cros_ec: Add support for switches

On x86 platforms the EC provides a way to read 'switches', which are
on/off values determined by the EC.

Add a new driver method for this and implement it for LPC.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass
2021-01-16 14:52:28 -07:00
parent 2b4b653391
commit 3a6c994f38
7 changed files with 120 additions and 0 deletions

View File

@@ -1557,6 +1557,22 @@ int cros_ec_set_lid_shutdown_mask(struct udevice *dev, int enable)
return 0;
}
int cros_ec_get_switches(struct udevice *dev)
{
struct dm_cros_ec_ops *ops;
int ret;
ops = dm_cros_ec_get_ops(dev);
if (!ops->get_switches)
return -ENOSYS;
ret = ops->get_switches(dev);
if (ret < 0)
return log_msg_ret("get", ret);
return ret;
}
UCLASS_DRIVER(cros_ec) = {
.id = UCLASS_CROS_EC,
.name = "cros-ec",

View File

@@ -207,6 +207,12 @@ int cros_ec_lpc_init(struct cros_ec_dev *dev, const void *blob)
return 0;
}
/* Return the byte of EC switch states */
static int cros_ec_lpc_get_switches(struct udevice *dev)
{
return inb(EC_LPC_ADDR_MEMMAP + EC_MEMMAP_SWITCHES);
}
/*
* Test if LPC command args are supported.
*
@@ -239,6 +245,7 @@ static struct dm_cros_ec_ops cros_ec_ops = {
.packet = cros_ec_lpc_packet,
.command = cros_ec_lpc_command,
.check_version = cros_ec_lpc_check_version,
.get_switches = cros_ec_lpc_get_switches,
};
static const struct udevice_id cros_ec_ids[] = {

View File

@@ -75,6 +75,7 @@ struct ec_keymatrix_entry {
* @keyscan: Current keyscan information (bit set for each row/column pressed)
* @recovery_req: Keyboard recovery requested
* @test_flags: Flags that control behaviour for tests
* @switches: Current switches value (EC_SWITCH_)
*/
struct ec_state {
u8 vbnv_context[EC_VBNV_BLOCK_SIZE_V2];
@@ -541,6 +542,14 @@ void cros_ec_check_keyboard(struct udevice *dev)
}
}
/* Return the byte of EC switch states */
static int cros_ec_sandbox_get_switches(struct udevice *dev)
{
struct ec_state *ec = dev_get_priv(dev);
return ec->test_flags & CROSECT_LID_OPEN ? EC_SWITCH_LID_OPEN : 0;
}
void sandbox_cros_ec_set_test_flags(struct udevice *dev, uint flags)
{
struct ec_state *ec = dev_get_priv(dev);
@@ -603,6 +612,7 @@ int cros_ec_probe(struct udevice *dev)
struct dm_cros_ec_ops cros_ec_ops = {
.packet = cros_ec_sandbox_packet,
.get_switches = cros_ec_sandbox_get_switches,
};
static const struct udevice_id cros_ec_ids[] = {