Commit 7256c2e7 authored by Uwe Kleine-König's avatar Uwe Kleine-König

pwm: cros-ec: Change prototype of helpers to prepare further changes

pwm_chip allocation and registration is about to change. For that the
number of PWM devices must be known earlier in cros_ec_pwm_probe(). So
make cros_ec_pwm_get_duty() and cros_ec_num_pwms() independent of
struct cros_ec_pwm_device which is only available later.
Reviewed-by: default avatarTzung-Bi Shih <tzungbi@kernel.org>
Link: https://lore.kernel.org/r/c0cfc75c1cba0f735555e0138387143ec101feb3.1707900770.git.u.kleine-koenig@pengutronix.deSigned-off-by: default avatarUwe Kleine-König <u.kleine-koenig@pengutronix.de>
parent b1a80d50
...@@ -93,9 +93,8 @@ static int cros_ec_pwm_set_duty(struct cros_ec_pwm_device *ec_pwm, u8 index, ...@@ -93,9 +93,8 @@ static int cros_ec_pwm_set_duty(struct cros_ec_pwm_device *ec_pwm, u8 index,
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_pwm_device *ec_pwm, u8 index) static int cros_ec_pwm_get_duty(struct cros_ec_device *ec, bool use_pwm_type, u8 index)
{ {
struct cros_ec_device *ec = ec_pwm->ec;
struct { struct {
struct cros_ec_command msg; struct cros_ec_command msg;
union { union {
...@@ -115,7 +114,7 @@ static int cros_ec_pwm_get_duty(struct cros_ec_pwm_device *ec_pwm, u8 index) ...@@ -115,7 +114,7 @@ static int cros_ec_pwm_get_duty(struct cros_ec_pwm_device *ec_pwm, u8 index)
msg->insize = sizeof(*resp); msg->insize = sizeof(*resp);
msg->outsize = sizeof(*params); msg->outsize = sizeof(*params);
if (ec_pwm->use_pwm_type) { if (use_pwm_type) {
ret = cros_ec_dt_type_to_pwm_type(index, &params->pwm_type); ret = cros_ec_dt_type_to_pwm_type(index, &params->pwm_type);
if (ret) { if (ret) {
dev_err(ec->dev, "Invalid PWM type index: %d\n", index); dev_err(ec->dev, "Invalid PWM type index: %d\n", index);
...@@ -171,7 +170,7 @@ static int cros_ec_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm, ...@@ -171,7 +170,7 @@ static int cros_ec_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
struct cros_ec_pwm *channel = &ec_pwm->channel[pwm->hwpwm]; struct cros_ec_pwm *channel = &ec_pwm->channel[pwm->hwpwm];
int ret; int ret;
ret = cros_ec_pwm_get_duty(ec_pwm, pwm->hwpwm); ret = cros_ec_pwm_get_duty(ec_pwm->ec, ec_pwm->use_pwm_type, pwm->hwpwm);
if (ret < 0) { if (ret < 0) {
dev_err(chip->dev, "error getting initial duty: %d\n", ret); dev_err(chip->dev, "error getting initial duty: %d\n", ret);
return ret; return ret;
...@@ -226,13 +225,17 @@ static const struct pwm_ops cros_ec_pwm_ops = { ...@@ -226,13 +225,17 @@ static const struct pwm_ops cros_ec_pwm_ops = {
* of PWMs it supports directly, so we have to read the pwm duty cycle for * of PWMs it supports directly, so we have to read the pwm duty cycle for
* subsequent channels until we get an error. * subsequent channels until we get an error.
*/ */
static int cros_ec_num_pwms(struct cros_ec_pwm_device *ec_pwm) static int cros_ec_num_pwms(struct cros_ec_device *ec)
{ {
int i, ret; int i, ret;
/* 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++) {
ret = cros_ec_pwm_get_duty(ec_pwm, i); /*
* Note that this function is only called when use_pwm_type is
* false. With use_pwm_type == true the number of PWMs is fixed.
*/
ret = cros_ec_pwm_get_duty(ec, false, i);
/* /*
* 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.
...@@ -283,7 +286,7 @@ static int cros_ec_pwm_probe(struct platform_device *pdev) ...@@ -283,7 +286,7 @@ static int cros_ec_pwm_probe(struct platform_device *pdev)
if (ec_pwm->use_pwm_type) { if (ec_pwm->use_pwm_type) {
chip->npwm = CROS_EC_PWM_DT_COUNT; chip->npwm = CROS_EC_PWM_DT_COUNT;
} else { } else {
ret = cros_ec_num_pwms(ec_pwm); ret = cros_ec_num_pwms(ec);
if (ret < 0) if (ret < 0)
return dev_err_probe(dev, ret, "Couldn't find PWMs\n"); return dev_err_probe(dev, ret, "Couldn't find PWMs\n");
chip->npwm = ret; chip->npwm = 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