Commit be020f0d authored by Guenter Roeck's avatar Guenter Roeck Committed by Enric Balletbo i Serra

pwm: cros-ec: Simplify EC error handling

With enhanced error reporting from cros_ec_cmd_xfer_status() in place,
we can fully use it and no longer rely on EC error codes.
Acked-by: default avatarUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Reviewed-by: default avatarBrian Norris <briannorris@chromium.org>
Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
Signed-off-by: default avatarEnric Balletbo i Serra <enric.balletbo@collabora.com>
parent 0d080459
...@@ -81,8 +81,7 @@ static int cros_ec_pwm_set_duty(struct cros_ec_device *ec, u8 index, u16 duty) ...@@ -81,8 +81,7 @@ static int cros_ec_pwm_set_duty(struct cros_ec_device *ec, u8 index, u16 duty)
return cros_ec_cmd_xfer_status(ec, msg); return cros_ec_cmd_xfer_status(ec, msg);
} }
static int __cros_ec_pwm_get_duty(struct cros_ec_device *ec, u8 index, static int cros_ec_pwm_get_duty(struct cros_ec_device *ec, u8 index)
u32 *result)
{ {
struct { struct {
struct cros_ec_command msg; struct cros_ec_command msg;
...@@ -107,19 +106,12 @@ static int __cros_ec_pwm_get_duty(struct cros_ec_device *ec, u8 index, ...@@ -107,19 +106,12 @@ static int __cros_ec_pwm_get_duty(struct cros_ec_device *ec, u8 index,
params->index = index; params->index = index;
ret = cros_ec_cmd_xfer_status(ec, msg); ret = cros_ec_cmd_xfer_status(ec, msg);
if (result)
*result = msg->result;
if (ret < 0) if (ret < 0)
return ret; return ret;
return resp->duty; return resp->duty;
} }
static int cros_ec_pwm_get_duty(struct cros_ec_device *ec, u8 index)
{
return __cros_ec_pwm_get_duty(ec, index, NULL);
}
static int cros_ec_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, static int cros_ec_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
const struct pwm_state *state) const struct pwm_state *state)
{ {
...@@ -215,28 +207,18 @@ static int cros_ec_num_pwms(struct cros_ec_device *ec) ...@@ -215,28 +207,18 @@ static int cros_ec_num_pwms(struct cros_ec_device *ec)
/* The index field is only 8 bits */ /* The index field is only 8 bits */
for (i = 0; i <= U8_MAX; i++) { for (i = 0; i <= U8_MAX; i++) {
u32 result = 0; ret = cros_ec_pwm_get_duty(ec, i);
ret = __cros_ec_pwm_get_duty(ec, i, &result);
/* /*
* We look for SUCCESS, INVALID_COMMAND, or INVALID_PARAM * We look for SUCCESS, INVALID_COMMAND, or INVALID_PARAM
* responses; everything else is treated as an error. * responses; everything else is treated as an error.
* The EC error codes either map to -EOPNOTSUPP / -EINVAL, * The EC error codes map to -EOPNOTSUPP and -EINVAL,
* or -EPROTO is returned and the EC error is in the result * so check for those.
* field. Check for both.
*/ */
switch (ret) { switch (ret) {
case -EOPNOTSUPP: /* invalid command */ case -EOPNOTSUPP: /* invalid command */
return -ENODEV; return -ENODEV;
case -EINVAL: /* invalid parameter */ case -EINVAL: /* invalid parameter */
return i; return i;
case -EPROTO:
/* Old or new error return code: Handle both */
if (result == EC_RES_INVALID_COMMAND)
return -ENODEV;
else if (result == EC_RES_INVALID_PARAM)
return i;
return -EPROTO;
default: default:
if (ret < 0) if (ret < 0)
return ret; return ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment