summaryrefslogtreecommitdiff
path: root/include/write_protect.h
blob: 8e0911197484a74f8505dbf1212871e3c591d866 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* Copyright 2022 The ChromiumOS Authors
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef __CROS_EC_WRITE_PROTECT_H
#define __CROS_EC_WRITE_PROTECT_H

#ifdef CONFIG_ZEPHYR
#include "zephyr_write_protect.h"
#else
#include "gpio.h"

static inline bool write_protect_is_asserted(void)
{
#ifdef CONFIG_WP_ALWAYS
	return true;
#elif defined(CONFIG_WP_ACTIVE_HIGH)
	return gpio_get_level(GPIO_WP);
#else
	return !gpio_get_level(GPIO_WP_L);
#endif
}

static inline int write_protect_enable_interrupt(void)
{
#ifdef CONFIG_WP_ACTIVE_HIGH
	return gpio_enable_interrupt(GPIO_WP);
#else
	return gpio_enable_interrupt(GPIO_WP_L);
#endif
}

#ifdef TEST_BUILD
/**
 * Set the WP state.
 *
 * @param value		Logical level of the WP pin
 */
static inline void write_protect_set(int value)
{
#ifdef CONFIG_WP_ACTIVE_HIGH
	gpio_set_level(GPIO_WP, value);
#else
	gpio_set_level(GPIO_WP_L, !value);
#endif /* CONFIG_WP_ACTIVE_HIGH */
}
#endif /* TEST_BUILD */

#endif /* !CONFIG_ZEPHYR */
#endif /* __CROS_EC_WRITE_PROTECT_H */