summaryrefslogtreecommitdiff
path: root/drivers/misc/cros_ec_sandbox.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/misc/cros_ec_sandbox.c')
-rw-r--r--drivers/misc/cros_ec_sandbox.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/drivers/misc/cros_ec_sandbox.c b/drivers/misc/cros_ec_sandbox.c
index bc01df0904..db5e3b0f51 100644
--- a/drivers/misc/cros_ec_sandbox.c
+++ b/drivers/misc/cros_ec_sandbox.c
@@ -64,6 +64,7 @@ struct ec_keymatrix_entry {
enum {
VSTORE_SLOT_COUNT = 4,
+ PWM_CHANNEL_COUNT = 4,
};
struct vstore_slot {
@@ -71,6 +72,10 @@ struct vstore_slot {
u8 data[EC_VSTORE_SLOT_SIZE];
};
+struct ec_pwm_channel {
+ uint duty; /* not ns, EC_PWM_MAX_DUTY = 100% */
+};
+
/**
* struct ec_state - Information about the EC state
*
@@ -85,6 +90,7 @@ struct vstore_slot {
* @recovery_req: Keyboard recovery requested
* @test_flags: Flags that control behaviour for tests
* @slot_locked: Locked vstore slots (mask)
+ * @pwm: Information per PWM channel
*/
struct ec_state {
u8 vbnv_context[EC_VBNV_BLOCK_SIZE_V2];
@@ -98,6 +104,7 @@ struct ec_state {
bool recovery_req;
uint test_flags;
struct vstore_slot slot[VSTORE_SLOT_COUNT];
+ struct ec_pwm_channel pwm[PWM_CHANNEL_COUNT];
} s_state, *g_state;
/**
@@ -554,6 +561,33 @@ static int process_cmd(struct ec_state *ec,
len = sizeof(*resp);
break;
}
+ case EC_CMD_PWM_GET_DUTY: {
+ const struct ec_params_pwm_get_duty *req = req_data;
+ struct ec_response_pwm_get_duty *resp = resp_data;
+ struct ec_pwm_channel *pwm;
+
+ if (req->pwm_type != EC_PWM_TYPE_GENERIC)
+ return -EINVAL;
+ if (req->index >= PWM_CHANNEL_COUNT)
+ return -EINVAL;
+ pwm = &ec->pwm[req->index];
+ resp->duty = pwm->duty;
+ len = sizeof(*resp);
+ break;
+ }
+ case EC_CMD_PWM_SET_DUTY: {
+ const struct ec_params_pwm_set_duty *req = req_data;
+ struct ec_pwm_channel *pwm;
+
+ if (req->pwm_type != EC_PWM_TYPE_GENERIC)
+ return -EINVAL;
+ if (req->index >= PWM_CHANNEL_COUNT)
+ return -EINVAL;
+ pwm = &ec->pwm[req->index];
+ pwm->duty = req->duty;
+ len = 0;
+ break;
+ }
default:
printf(" ** Unknown EC command %#02x\n", req_hdr->command);
return -1;
@@ -619,6 +653,19 @@ void sandbox_cros_ec_set_test_flags(struct udevice *dev, uint flags)
ec->test_flags = flags;
}
+int sandbox_cros_ec_get_pwm_duty(struct udevice *dev, uint index, uint *duty)
+{
+ struct ec_state *ec = dev_get_priv(dev);
+ struct ec_pwm_channel *pwm;
+
+ if (index >= PWM_CHANNEL_COUNT)
+ return -ENOSPC;
+ pwm = &ec->pwm[index];
+ *duty = pwm->duty;
+
+ return 0;
+}
+
int cros_ec_probe(struct udevice *dev)
{
struct ec_state *ec = dev_get_priv(dev);