summaryrefslogtreecommitdiff
path: root/zephyr/shim/include/zephyr_write_protect.h
blob: 3af2fb3576e53e3192919adfeb2d78ab898e40c0 (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
/* Copyright 2022 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef __CROS_EC_ZEPHYR_WRITE_PROTECT_H
#define __CROS_EC_ZEPHYR_WRITE_PROTECT_H

#include "gpio/gpio_int.h"
#include "gpio_signal.h"
#include <zephyr/drivers/gpio.h>

/**
 * Check the WP state. The function depends on the alias 'gpio_wp'. It is used
 * to replace the enum-name.
 *
 * @return true if the WP is active, false otherwise.
 */
static inline int write_protect_is_asserted(void)
{
#ifdef CONFIG_WP_ALWAYS
	return true;
#else
	return gpio_pin_get_dt(GPIO_DT_FROM_ALIAS(gpio_wp));
#endif
}

/**
 * Enable interrupt for WP pin. The interrupt itself has to be defined in a node
 * with compatible = "cros-ec,gpio-interrupts" and pointed by the alias int_wp.
 *
 * @return 0 if success
 */
static inline int write_protect_enable_interrupt(void)
{
#if DT_NODE_EXISTS(DT_ALIAS(int_wp))
	return gpio_enable_dt_interrupt(GPIO_INT_FROM_NODE(DT_ALIAS(int_wp)));
#else
	return -1;
#endif
}

#endif /* __CROS_EC_ZEPHYR_WRITE_PROTECT_H */