Message ID | 20200130203106.201894-14-pmalani@chromium.org |
---|---|
State | Changes Requested |
Headers | show |
Series | platform/chrome: Replace cros_ec_cmd_xfer_status | expand |
On 30/1/20 21:31, Prashant Malani wrote: > Convert one existing usage of cros_ec_cmd_xfer_status() to > cros_ec_send_cmd_msg(), which accomplishes the same thing but also does > the EC message struct setup,and is defined in platform/chrome and is > accessible by other modules. > > For the other usage, switch it to using cros_ec_cmd_xfer(), since the > calling functions rely on the result field of the struct cros_ec_command > struct that is used. > > Signed-off-by: Prashant Malani <pmalani@chromium.org> > --- > drivers/pwm/pwm-cros-ec.c | 27 +++++++++------------------ > 1 file changed, 9 insertions(+), 18 deletions(-) > > diff --git a/drivers/pwm/pwm-cros-ec.c b/drivers/pwm/pwm-cros-ec.c > index 89497448d21775..8bf610a6529e7e 100644 > --- a/drivers/pwm/pwm-cros-ec.c > +++ b/drivers/pwm/pwm-cros-ec.c > @@ -32,25 +32,14 @@ static inline struct cros_ec_pwm_device *pwm_to_cros_ec_pwm(struct pwm_chip *c) > > static int cros_ec_pwm_set_duty(struct cros_ec_device *ec, u8 index, u16 duty) > { > - struct { > - struct cros_ec_command msg; > - struct ec_params_pwm_set_duty params; > - } __packed buf; > - struct ec_params_pwm_set_duty *params = &buf.params; > - struct cros_ec_command *msg = &buf.msg; > - > - memset(&buf, 0, sizeof(buf)); > + struct ec_params_pwm_set_duty params = {0}; > > - msg->version = 0; > - msg->command = EC_CMD_PWM_SET_DUTY; > - msg->insize = 0; > - msg->outsize = sizeof(*params); > - > - params->duty = duty; > - params->pwm_type = EC_PWM_TYPE_GENERIC; > - params->index = index; > + params.duty = duty; > + params.pwm_type = EC_PWM_TYPE_GENERIC; > + params.index = index; > > - return cros_ec_cmd_xfer_status(ec, msg); > + return cros_ec_send_cmd_msg(ec, 0, EC_CMD_PWM_SET_DUTY, ¶ms, > + sizeof(params), NULL, 0); > } > > static int __cros_ec_pwm_get_duty(struct cros_ec_device *ec, u8 index, > @@ -78,11 +67,13 @@ static int __cros_ec_pwm_get_duty(struct cros_ec_device *ec, u8 index, > params->pwm_type = EC_PWM_TYPE_GENERIC; > params->index = index; > > - ret = cros_ec_cmd_xfer_status(ec, msg); > + ret = cros_ec_cmd_xfer(ec, msg); Why? There is a good reason we introduced the cros_ec_cmd_xfer_status. IMO the purpose of introduce the new wrapper only makes sense if we can cover _all_ the cases, so we can remove cros_ec_cmd_xfer_status and make cros_ec_cmd_xfer private to cros_ec_proto. Is not possible to use the new wrapper here? > if (result) > *result = msg->result; Hmm, I see, that's the problem ... This driver will need a bit of rework but I think could be possible to use the wrapper. > if (ret < 0) > return ret; > + else if (msg->result != EC_RES_SUCCESS) > + return -EPROTO; > > return resp->duty; > } >
On Mon, Feb 3, 2020 at 7:33 AM Enric Balletbo i Serra <enric.balletbo@collabora.com> wrote: > > > On 30/1/20 21:31, Prashant Malani wrote: > > Convert one existing usage of cros_ec_cmd_xfer_status() to > > cros_ec_send_cmd_msg(), which accomplishes the same thing but also does > > the EC message struct setup,and is defined in platform/chrome and is > > accessible by other modules. > > > > For the other usage, switch it to using cros_ec_cmd_xfer(), since the > > calling functions rely on the result field of the struct cros_ec_command > > struct that is used. > > > > Signed-off-by: Prashant Malani <pmalani@chromium.org> > > --- > > drivers/pwm/pwm-cros-ec.c | 27 +++++++++------------------ > > 1 file changed, 9 insertions(+), 18 deletions(-) > > > > diff --git a/drivers/pwm/pwm-cros-ec.c b/drivers/pwm/pwm-cros-ec.c > > index 89497448d21775..8bf610a6529e7e 100644 > > --- a/drivers/pwm/pwm-cros-ec.c > > +++ b/drivers/pwm/pwm-cros-ec.c > > @@ -32,25 +32,14 @@ static inline struct cros_ec_pwm_device *pwm_to_cros_ec_pwm(struct pwm_chip *c) > > > > static int cros_ec_pwm_set_duty(struct cros_ec_device *ec, u8 index, u16 duty) > > { > > - struct { > > - struct cros_ec_command msg; > > - struct ec_params_pwm_set_duty params; > > - } __packed buf; > > - struct ec_params_pwm_set_duty *params = &buf.params; > > - struct cros_ec_command *msg = &buf.msg; > > - > > - memset(&buf, 0, sizeof(buf)); > > + struct ec_params_pwm_set_duty params = {0}; > > > > - msg->version = 0; > > - msg->command = EC_CMD_PWM_SET_DUTY; > > - msg->insize = 0; > > - msg->outsize = sizeof(*params); > > - > > - params->duty = duty; > > - params->pwm_type = EC_PWM_TYPE_GENERIC; > > - params->index = index; > > + params.duty = duty; > > + params.pwm_type = EC_PWM_TYPE_GENERIC; > > + params.index = index; > > > > - return cros_ec_cmd_xfer_status(ec, msg); > > + return cros_ec_send_cmd_msg(ec, 0, EC_CMD_PWM_SET_DUTY, ¶ms, > > + sizeof(params), NULL, 0); > > } > > > > static int __cros_ec_pwm_get_duty(struct cros_ec_device *ec, u8 index, > > @@ -78,11 +67,13 @@ static int __cros_ec_pwm_get_duty(struct cros_ec_device *ec, u8 index, > > params->pwm_type = EC_PWM_TYPE_GENERIC; > > params->index = index; > > > > - ret = cros_ec_cmd_xfer_status(ec, msg); > > + ret = cros_ec_cmd_xfer(ec, msg); > > Why? There is a good reason we introduced the cros_ec_cmd_xfer_status. > > IMO the purpose of introduce the new wrapper only makes sense if we can cover > _all_ the cases, so we can remove cros_ec_cmd_xfer_status and make > cros_ec_cmd_xfer private to cros_ec_proto. > > Is not possible to use the new wrapper here? > > > if (result) > > *result = msg->result; > > Hmm, I see, that's the problem ... > > This driver will need a bit of rework but I think could be possible to use the > wrapper. Yeah, I looked around, and it seems to use msg->result. Perhaps we should work on reworking this driver before doing the large patch series? I would be happy to work on it, unless you feel there is someone else who'd be better suited. Kindly let me know. > > > if (ret < 0) > > return ret; > > + else if (msg->result != EC_RES_SUCCESS) > > + return -EPROTO; > > > > return resp->duty; > > } > >
Hi Enric, On Mon, Feb 3, 2020 at 10:26 AM Prashant Malani <pmalani@chromium.org> wrote: > > On Mon, Feb 3, 2020 at 7:33 AM Enric Balletbo i Serra > <enric.balletbo@collabora.com> wrote: > > > > > > On 30/1/20 21:31, Prashant Malani wrote: > > > Convert one existing usage of cros_ec_cmd_xfer_status() to > > > cros_ec_send_cmd_msg(), which accomplishes the same thing but also does > > > the EC message struct setup,and is defined in platform/chrome and is > > > accessible by other modules. > > > > > > For the other usage, switch it to using cros_ec_cmd_xfer(), since the > > > calling functions rely on the result field of the struct cros_ec_command > > > struct that is used. > > > > > > Signed-off-by: Prashant Malani <pmalani@chromium.org> > > > --- > > > drivers/pwm/pwm-cros-ec.c | 27 +++++++++------------------ > > > 1 file changed, 9 insertions(+), 18 deletions(-) > > > > > > diff --git a/drivers/pwm/pwm-cros-ec.c b/drivers/pwm/pwm-cros-ec.c > > > index 89497448d21775..8bf610a6529e7e 100644 > > > --- a/drivers/pwm/pwm-cros-ec.c > > > +++ b/drivers/pwm/pwm-cros-ec.c > > > @@ -32,25 +32,14 @@ static inline struct cros_ec_pwm_device *pwm_to_cros_ec_pwm(struct pwm_chip *c) > > > > > > static int cros_ec_pwm_set_duty(struct cros_ec_device *ec, u8 index, u16 duty) > > > { > > > - struct { > > > - struct cros_ec_command msg; > > > - struct ec_params_pwm_set_duty params; > > > - } __packed buf; > > > - struct ec_params_pwm_set_duty *params = &buf.params; > > > - struct cros_ec_command *msg = &buf.msg; > > > - > > > - memset(&buf, 0, sizeof(buf)); > > > + struct ec_params_pwm_set_duty params = {0}; > > > > > > - msg->version = 0; > > > - msg->command = EC_CMD_PWM_SET_DUTY; > > > - msg->insize = 0; > > > - msg->outsize = sizeof(*params); > > > - > > > - params->duty = duty; > > > - params->pwm_type = EC_PWM_TYPE_GENERIC; > > > - params->index = index; > > > + params.duty = duty; > > > + params.pwm_type = EC_PWM_TYPE_GENERIC; > > > + params.index = index; > > > > > > - return cros_ec_cmd_xfer_status(ec, msg); > > > + return cros_ec_send_cmd_msg(ec, 0, EC_CMD_PWM_SET_DUTY, ¶ms, > > > + sizeof(params), NULL, 0); > > > } > > > > > > static int __cros_ec_pwm_get_duty(struct cros_ec_device *ec, u8 index, > > > @@ -78,11 +67,13 @@ static int __cros_ec_pwm_get_duty(struct cros_ec_device *ec, u8 index, > > > params->pwm_type = EC_PWM_TYPE_GENERIC; > > > params->index = index; > > > > > > - ret = cros_ec_cmd_xfer_status(ec, msg); > > > + ret = cros_ec_cmd_xfer(ec, msg); > > > > Why? There is a good reason we introduced the cros_ec_cmd_xfer_status. > > > > IMO the purpose of introduce the new wrapper only makes sense if we can cover > > _all_ the cases, so we can remove cros_ec_cmd_xfer_status and make > > cros_ec_cmd_xfer private to cros_ec_proto. I'm hoping for that too, but as we saw below (and some in some other drivers), some callers of cros_ec_cmd_xfer() actually use the msg->result. Should we change the new wrapper to return the message via a pointer (if not NULL), so something like this ? : int cros_ec_send_cmd_msg(struct cros_ec_device *ec, unsigned int version, uint32_t command, void *outdata, unsigned int outsize, void *indata, unsigned int insize, uint32_t *result) ? > > > > Is not possible to use the new wrapper here? > > > > > if (result) > > > *result = msg->result; > > > > Hmm, I see, that's the problem ... > > > > This driver will need a bit of rework but I think could be possible to use the > > wrapper. > Yeah, I looked around, and it seems to use msg->result. > Perhaps we should work on reworking this driver before doing the large > patch series? I would be happy to work on it, unless you feel there is > someone else who'd be better suited. Kindly let me know. > > > > > if (ret < 0) > > > return ret; > > > + else if (msg->result != EC_RES_SUCCESS) > > > + return -EPROTO; > > > > > > return resp->duty; > > > } > > >
diff --git a/drivers/pwm/pwm-cros-ec.c b/drivers/pwm/pwm-cros-ec.c index 89497448d21775..8bf610a6529e7e 100644 --- a/drivers/pwm/pwm-cros-ec.c +++ b/drivers/pwm/pwm-cros-ec.c @@ -32,25 +32,14 @@ static inline struct cros_ec_pwm_device *pwm_to_cros_ec_pwm(struct pwm_chip *c) static int cros_ec_pwm_set_duty(struct cros_ec_device *ec, u8 index, u16 duty) { - struct { - struct cros_ec_command msg; - struct ec_params_pwm_set_duty params; - } __packed buf; - struct ec_params_pwm_set_duty *params = &buf.params; - struct cros_ec_command *msg = &buf.msg; - - memset(&buf, 0, sizeof(buf)); + struct ec_params_pwm_set_duty params = {0}; - msg->version = 0; - msg->command = EC_CMD_PWM_SET_DUTY; - msg->insize = 0; - msg->outsize = sizeof(*params); - - params->duty = duty; - params->pwm_type = EC_PWM_TYPE_GENERIC; - params->index = index; + params.duty = duty; + params.pwm_type = EC_PWM_TYPE_GENERIC; + params.index = index; - return cros_ec_cmd_xfer_status(ec, msg); + return cros_ec_send_cmd_msg(ec, 0, EC_CMD_PWM_SET_DUTY, ¶ms, + sizeof(params), NULL, 0); } static int __cros_ec_pwm_get_duty(struct cros_ec_device *ec, u8 index, @@ -78,11 +67,13 @@ static int __cros_ec_pwm_get_duty(struct cros_ec_device *ec, u8 index, params->pwm_type = EC_PWM_TYPE_GENERIC; params->index = index; - ret = cros_ec_cmd_xfer_status(ec, msg); + ret = cros_ec_cmd_xfer(ec, msg); if (result) *result = msg->result; if (ret < 0) return ret; + else if (msg->result != EC_RES_SUCCESS) + return -EPROTO; return resp->duty; }
Convert one existing usage of cros_ec_cmd_xfer_status() to cros_ec_send_cmd_msg(), which accomplishes the same thing but also does the EC message struct setup,and is defined in platform/chrome and is accessible by other modules. For the other usage, switch it to using cros_ec_cmd_xfer(), since the calling functions rely on the result field of the struct cros_ec_command struct that is used. Signed-off-by: Prashant Malani <pmalani@chromium.org> --- drivers/pwm/pwm-cros-ec.c | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-)