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
52
53
54
55
56
57
|
/* 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.
*/
#include <zephyr/drivers/eeprom.h>
#include <zephyr/drivers/gpio.h>
#include "console.h"
#include "cros_board_info.h"
#include "write_protect.h"
#if DT_NODE_EXISTS(DT_NODELABEL(cbi_eeprom))
#define CBI_EEPROM_DEV DEVICE_DT_GET(DT_NODELABEL(cbi_eeprom))
#ifdef CONFIG_PLATFORM_EC_EEPROM_CBI_WP
#if !DT_NODE_EXISTS(DT_ALIAS(gpio_cbi_wp))
#error gpio_cbi_wp alias has to point to the CBI WP output pin.
#endif
void cbi_latch_eeprom_wp(void)
{
cprints(CC_SYSTEM, "CBI WP latched");
gpio_pin_set_dt(GPIO_DT_FROM_ALIAS(gpio_cbi_wp), 1);
}
#endif /* CONFIG_PLATFORM_EC_EEPROM_CBI_WP */
static int eeprom_load(uint8_t offset, uint8_t *data, int len)
{
return eeprom_read(CBI_EEPROM_DEV, offset, data, len);
}
static int eeprom_is_write_protected(void)
{
if (IS_ENABLED(CONFIG_PLATFORM_EC_BYPASS_CBI_EEPROM_WP_CHECK))
return 0;
return write_protect_is_asserted();
}
static int eeprom_store(uint8_t *cbi)
{
return eeprom_write(CBI_EEPROM_DEV, 0, cbi,
((struct cbi_header *)cbi)->total_size);
}
static const struct cbi_storage_driver eeprom_drv = {
.store = eeprom_store,
.load = eeprom_load,
.is_protected = eeprom_is_write_protected,
};
const struct cbi_storage_config_t cbi_config = {
.storage_type = CBI_STORAGE_TYPE_EEPROM,
.drv = &eeprom_drv,
};
#endif
|