Lines Matching +full:cros +full:- +full:ec
1 // SPDX-License-Identifier: GPL-2.0
3 * Expose a PWM controlled by the ChromeOS EC to the host processor.
16 #include <dt-bindings/mfd/cros_ec.h>
19 * struct cros_ec_pwm_device - Driver data for EC PWM
21 * @ec: Pointer to EC device
25 struct cros_ec_device *ec; member
44 return -EINVAL; in cros_ec_dt_type_to_pwm_type()
51 struct cros_ec_device *ec = ec_pwm->ec; in cros_ec_pwm_set_duty() local
62 msg->version = 0; in cros_ec_pwm_set_duty()
63 msg->command = EC_CMD_PWM_SET_DUTY; in cros_ec_pwm_set_duty()
64 msg->insize = 0; in cros_ec_pwm_set_duty()
65 msg->outsize = sizeof(*params); in cros_ec_pwm_set_duty()
67 params->duty = duty; in cros_ec_pwm_set_duty()
69 if (ec_pwm->use_pwm_type) { in cros_ec_pwm_set_duty()
70 ret = cros_ec_dt_type_to_pwm_type(index, ¶ms->pwm_type); in cros_ec_pwm_set_duty()
72 dev_err(ec->dev, "Invalid PWM type index: %d\n", index); in cros_ec_pwm_set_duty()
75 params->index = 0; in cros_ec_pwm_set_duty()
77 params->pwm_type = EC_PWM_TYPE_GENERIC; in cros_ec_pwm_set_duty()
78 params->index = index; in cros_ec_pwm_set_duty()
81 return cros_ec_cmd_xfer_status(ec, msg); in cros_ec_pwm_set_duty()
84 static int cros_ec_pwm_get_duty(struct cros_ec_device *ec, bool use_pwm_type, u8 index) in cros_ec_pwm_get_duty() argument
100 msg->version = 0; in cros_ec_pwm_get_duty()
101 msg->command = EC_CMD_PWM_GET_DUTY; in cros_ec_pwm_get_duty()
102 msg->insize = sizeof(*resp); in cros_ec_pwm_get_duty()
103 msg->outsize = sizeof(*params); in cros_ec_pwm_get_duty()
106 ret = cros_ec_dt_type_to_pwm_type(index, ¶ms->pwm_type); in cros_ec_pwm_get_duty()
108 dev_err(ec->dev, "Invalid PWM type index: %d\n", index); in cros_ec_pwm_get_duty()
111 params->index = 0; in cros_ec_pwm_get_duty()
113 params->pwm_type = EC_PWM_TYPE_GENERIC; in cros_ec_pwm_get_duty()
114 params->index = index; in cros_ec_pwm_get_duty()
117 ret = cros_ec_cmd_xfer_status(ec, msg); in cros_ec_pwm_get_duty()
121 return resp->duty; in cros_ec_pwm_get_duty()
131 /* The EC won't let us change the period */ in cros_ec_pwm_apply()
132 if (state->period != EC_PWM_MAX_DUTY) in cros_ec_pwm_apply()
133 return -EINVAL; in cros_ec_pwm_apply()
135 if (state->polarity != PWM_POLARITY_NORMAL) in cros_ec_pwm_apply()
136 return -EINVAL; in cros_ec_pwm_apply()
139 * EC doesn't separate the concept of duty cycle and enabled, but in cros_ec_pwm_apply()
142 duty_cycle = state->enabled ? state->duty_cycle : 0; in cros_ec_pwm_apply()
144 ret = cros_ec_pwm_set_duty(ec_pwm, pwm->hwpwm, duty_cycle); in cros_ec_pwm_apply()
157 ret = cros_ec_pwm_get_duty(ec_pwm->ec, ec_pwm->use_pwm_type, pwm->hwpwm); in cros_ec_pwm_get_state()
163 state->enabled = (ret > 0); in cros_ec_pwm_get_state()
164 state->duty_cycle = ret; in cros_ec_pwm_get_state()
165 state->period = EC_PWM_MAX_DUTY; in cros_ec_pwm_get_state()
166 state->polarity = PWM_POLARITY_NORMAL; in cros_ec_pwm_get_state()
177 * Determine the number of supported PWMs. The EC does not return the number
181 static int cros_ec_num_pwms(struct cros_ec_device *ec) in cros_ec_num_pwms() argument
191 ret = cros_ec_pwm_get_duty(ec, false, i); in cros_ec_num_pwms()
195 * The EC error codes map to -EOPNOTSUPP and -EINVAL, in cros_ec_num_pwms()
199 case -EOPNOTSUPP: /* invalid command */ in cros_ec_num_pwms()
200 return -ENODEV; in cros_ec_num_pwms()
201 case -EINVAL: /* invalid parameter */ in cros_ec_num_pwms()
215 struct cros_ec_device *ec = dev_get_drvdata(pdev->dev.parent); in cros_ec_pwm_probe() local
216 struct device *dev = &pdev->dev; in cros_ec_pwm_probe()
217 struct device_node *np = pdev->dev.of_node; in cros_ec_pwm_probe()
224 if (!ec) in cros_ec_pwm_probe()
225 return dev_err_probe(dev, -EINVAL, "no parent EC device\n"); in cros_ec_pwm_probe()
227 if (of_device_is_compatible(np, "google,cros-ec-pwm-type")) { in cros_ec_pwm_probe()
231 ret = cros_ec_num_pwms(ec); in cros_ec_pwm_probe()
242 ec_pwm->use_pwm_type = use_pwm_type; in cros_ec_pwm_probe()
243 ec_pwm->ec = ec; in cros_ec_pwm_probe()
246 chip->ops = &cros_ec_pwm_ops; in cros_ec_pwm_probe()
257 chip->pwms[i].args.period = EC_PWM_MAX_DUTY; in cros_ec_pwm_probe()
259 dev_dbg(dev, "Probed %u PWMs\n", chip->npwm); in cros_ec_pwm_probe()
270 { .compatible = "google,cros-ec-pwm" },
271 { .compatible = "google,cros-ec-pwm-type" },
280 .name = "cros-ec-pwm",
286 MODULE_ALIAS("platform:cros-ec-pwm");
287 MODULE_DESCRIPTION("ChromeOS EC PWM driver");