summaryrefslogtreecommitdiff
path: root/zephyr/drivers/cros_cbi/cros_cbi_ssfc.c
blob: 624b0ddc5fc7bea0016097c2f1883e52e5433384 (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
52
53
54
55
56
57
/* 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.
 */

#include <drivers/cros_cbi.h>
#include <logging/log.h>

#include "cros_board_info.h"
#include "cros_cbi_ssfc.h"
#include "cros_cbi_common.h"

#define DT_DRV_COMPAT named_cbi_ssfc_value

LOG_MODULE_REGISTER(cros_cbi_ssfc, LOG_LEVEL_ERR);

void cros_cbi_ssfc_init(const struct device *dev)
{
	struct cros_cbi_data *data = (struct cros_cbi_data *)(dev->data);

	if (cbi_get_ssfc(&data->cached_ssfc.raw_value) != EC_SUCCESS) {
		DT_INST_FOREACH_STATUS_OKAY_VARGS(CBI_SSFC_INIT_DEFAULT, data)
	}

	LOG_INF("Read CBI SSFC : 0x%08X\n", data->cached_ssfc.raw_value);
}

static int cros_cbi_ssfc_get_parent_field_value(union cbi_ssfc cached_ssfc,
						enum cbi_ssfc_value_id value_id,
						uint32_t *value)
{
	switch (value_id) {
		DT_INST_FOREACH_STATUS_OKAY_VARGS(CBI_SSFC_PARENT_VALUE_CASE,
						  cached_ssfc, value)
	default:
		LOG_ERR("CBI SSFC parent field value not found: %d\n",
		        value_id);
		return -EINVAL;
	}
	return 0;
}

bool cros_cbi_ec_ssfc_check_match(const struct device *dev,
					 enum cbi_ssfc_value_id value_id)
{
	struct cros_cbi_data *data = (struct cros_cbi_data *)(dev->data);
	struct cros_cbi_config *cfg = (struct cros_cbi_config *)(dev->config);
	int rc;
	uint32_t value;

	rc = cros_cbi_ssfc_get_parent_field_value(data->cached_ssfc,
						  value_id, &value);
	if (rc) {
		return false;
	}
	return value == cfg->ssfc_values[value_id];
}