Skip to content

Commit 46eec87

Browse files
author
Uwe Kleine-König
committed
staging: greybus: pwm: Change prototype of helpers to prepare further changes
This prepares the driver for further changes that will make it harder to determine the pwm_chip from a given gb_pwm_chip. To just not have to do that, rework gb_pwm_activate_operation(), gb_pwm_deactivate_operation(), gb_pwm_config_operation(), gb_pwm_set_polarity_operation(), gb_pwm_enable_operation() and gb_pwm_disable_operation() to take a pwm_chip. Also use the pwm_chip as driver data instead of the gb_pwm_chip. Reviewed-by: Greg Kroah-Hartman <[email protected]> Link: https://lore.kernel.org/r/ef9b346d5bab508d4ded81cf115bf244938d04f1.1707900770.git.u.kleine-koenig@pengutronix.de Signed-off-by: Uwe Kleine-König <[email protected]>
1 parent 4b2b7b1 commit 46eec87

File tree

1 file changed

+29
-31
lines changed
  • drivers/staging/greybus

1 file changed

+29
-31
lines changed

drivers/staging/greybus/pwm.c

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ static int gb_pwm_count_operation(struct gb_pwm_chip *pwmc)
3939
return 0;
4040
}
4141

42-
static int gb_pwm_activate_operation(struct gb_pwm_chip *pwmc,
43-
u8 which)
42+
static int gb_pwm_activate_operation(struct pwm_chip *chip, u8 which)
4443
{
44+
struct gb_pwm_chip *pwmc = pwm_chip_to_gb_pwm_chip(chip);
4545
struct gb_pwm_activate_request request;
4646
struct gbphy_device *gbphy_dev;
4747
int ret;
@@ -51,7 +51,7 @@ static int gb_pwm_activate_operation(struct gb_pwm_chip *pwmc,
5151

5252
request.which = which;
5353

54-
gbphy_dev = to_gbphy_dev(pwmc->chip.dev);
54+
gbphy_dev = to_gbphy_dev(chip->dev);
5555
ret = gbphy_runtime_get_sync(gbphy_dev);
5656
if (ret)
5757
return ret;
@@ -64,9 +64,9 @@ static int gb_pwm_activate_operation(struct gb_pwm_chip *pwmc,
6464
return ret;
6565
}
6666

67-
static int gb_pwm_deactivate_operation(struct gb_pwm_chip *pwmc,
68-
u8 which)
67+
static int gb_pwm_deactivate_operation(struct pwm_chip *chip, u8 which)
6968
{
69+
struct gb_pwm_chip *pwmc = pwm_chip_to_gb_pwm_chip(chip);
7070
struct gb_pwm_deactivate_request request;
7171
struct gbphy_device *gbphy_dev;
7272
int ret;
@@ -76,7 +76,7 @@ static int gb_pwm_deactivate_operation(struct gb_pwm_chip *pwmc,
7676

7777
request.which = which;
7878

79-
gbphy_dev = to_gbphy_dev(pwmc->chip.dev);
79+
gbphy_dev = to_gbphy_dev(chip->dev);
8080
ret = gbphy_runtime_get_sync(gbphy_dev);
8181
if (ret)
8282
return ret;
@@ -89,9 +89,10 @@ static int gb_pwm_deactivate_operation(struct gb_pwm_chip *pwmc,
8989
return ret;
9090
}
9191

92-
static int gb_pwm_config_operation(struct gb_pwm_chip *pwmc,
92+
static int gb_pwm_config_operation(struct pwm_chip *chip,
9393
u8 which, u32 duty, u32 period)
9494
{
95+
struct gb_pwm_chip *pwmc = pwm_chip_to_gb_pwm_chip(chip);
9596
struct gb_pwm_config_request request;
9697
struct gbphy_device *gbphy_dev;
9798
int ret;
@@ -103,7 +104,7 @@ static int gb_pwm_config_operation(struct gb_pwm_chip *pwmc,
103104
request.duty = cpu_to_le32(duty);
104105
request.period = cpu_to_le32(period);
105106

106-
gbphy_dev = to_gbphy_dev(pwmc->chip.dev);
107+
gbphy_dev = to_gbphy_dev(chip->dev);
107108
ret = gbphy_runtime_get_sync(gbphy_dev);
108109
if (ret)
109110
return ret;
@@ -116,9 +117,10 @@ static int gb_pwm_config_operation(struct gb_pwm_chip *pwmc,
116117
return ret;
117118
}
118119

119-
static int gb_pwm_set_polarity_operation(struct gb_pwm_chip *pwmc,
120+
static int gb_pwm_set_polarity_operation(struct pwm_chip *chip,
120121
u8 which, u8 polarity)
121122
{
123+
struct gb_pwm_chip *pwmc = pwm_chip_to_gb_pwm_chip(chip);
122124
struct gb_pwm_polarity_request request;
123125
struct gbphy_device *gbphy_dev;
124126
int ret;
@@ -129,7 +131,7 @@ static int gb_pwm_set_polarity_operation(struct gb_pwm_chip *pwmc,
129131
request.which = which;
130132
request.polarity = polarity;
131133

132-
gbphy_dev = to_gbphy_dev(pwmc->chip.dev);
134+
gbphy_dev = to_gbphy_dev(chip->dev);
133135
ret = gbphy_runtime_get_sync(gbphy_dev);
134136
if (ret)
135137
return ret;
@@ -142,9 +144,9 @@ static int gb_pwm_set_polarity_operation(struct gb_pwm_chip *pwmc,
142144
return ret;
143145
}
144146

145-
static int gb_pwm_enable_operation(struct gb_pwm_chip *pwmc,
146-
u8 which)
147+
static int gb_pwm_enable_operation(struct pwm_chip *chip, u8 which)
147148
{
149+
struct gb_pwm_chip *pwmc = pwm_chip_to_gb_pwm_chip(chip);
148150
struct gb_pwm_enable_request request;
149151
struct gbphy_device *gbphy_dev;
150152
int ret;
@@ -154,7 +156,7 @@ static int gb_pwm_enable_operation(struct gb_pwm_chip *pwmc,
154156

155157
request.which = which;
156158

157-
gbphy_dev = to_gbphy_dev(pwmc->chip.dev);
159+
gbphy_dev = to_gbphy_dev(chip->dev);
158160
ret = gbphy_runtime_get_sync(gbphy_dev);
159161
if (ret)
160162
return ret;
@@ -167,9 +169,9 @@ static int gb_pwm_enable_operation(struct gb_pwm_chip *pwmc,
167169
return ret;
168170
}
169171

170-
static int gb_pwm_disable_operation(struct gb_pwm_chip *pwmc,
171-
u8 which)
172+
static int gb_pwm_disable_operation(struct pwm_chip *chip, u8 which)
172173
{
174+
struct gb_pwm_chip *pwmc = pwm_chip_to_gb_pwm_chip(chip);
173175
struct gb_pwm_disable_request request;
174176
struct gbphy_device *gbphy_dev;
175177
int ret;
@@ -182,27 +184,23 @@ static int gb_pwm_disable_operation(struct gb_pwm_chip *pwmc,
182184
ret = gb_operation_sync(pwmc->connection, GB_PWM_TYPE_DISABLE,
183185
&request, sizeof(request), NULL, 0);
184186

185-
gbphy_dev = to_gbphy_dev(pwmc->chip.dev);
187+
gbphy_dev = to_gbphy_dev(chip->dev);
186188
gbphy_runtime_put_autosuspend(gbphy_dev);
187189

188190
return ret;
189191
}
190192

191193
static int gb_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm)
192194
{
193-
struct gb_pwm_chip *pwmc = pwm_chip_to_gb_pwm_chip(chip);
194-
195-
return gb_pwm_activate_operation(pwmc, pwm->hwpwm);
195+
return gb_pwm_activate_operation(chip, pwm->hwpwm);
196196
};
197197

198198
static void gb_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)
199199
{
200-
struct gb_pwm_chip *pwmc = pwm_chip_to_gb_pwm_chip(chip);
201-
202200
if (pwm_is_enabled(pwm))
203201
dev_warn(chip->dev, "freeing PWM device without disabling\n");
204202

205-
gb_pwm_deactivate_operation(pwmc, pwm->hwpwm);
203+
gb_pwm_deactivate_operation(chip, pwm->hwpwm);
206204
}
207205

208206
static int gb_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
@@ -212,22 +210,21 @@ static int gb_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
212210
bool enabled = pwm->state.enabled;
213211
u64 period = state->period;
214212
u64 duty_cycle = state->duty_cycle;
215-
struct gb_pwm_chip *pwmc = pwm_chip_to_gb_pwm_chip(chip);
216213

217214
/* Set polarity */
218215
if (state->polarity != pwm->state.polarity) {
219216
if (enabled) {
220-
gb_pwm_disable_operation(pwmc, pwm->hwpwm);
217+
gb_pwm_disable_operation(chip, pwm->hwpwm);
221218
enabled = false;
222219
}
223-
err = gb_pwm_set_polarity_operation(pwmc, pwm->hwpwm, state->polarity);
220+
err = gb_pwm_set_polarity_operation(chip, pwm->hwpwm, state->polarity);
224221
if (err)
225222
return err;
226223
}
227224

228225
if (!state->enabled) {
229226
if (enabled)
230-
gb_pwm_disable_operation(pwmc, pwm->hwpwm);
227+
gb_pwm_disable_operation(chip, pwm->hwpwm);
231228
return 0;
232229
}
233230

@@ -243,13 +240,13 @@ static int gb_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
243240
if (duty_cycle > period)
244241
duty_cycle = period;
245242

246-
err = gb_pwm_config_operation(pwmc, pwm->hwpwm, duty_cycle, period);
243+
err = gb_pwm_config_operation(chip, pwm->hwpwm, duty_cycle, period);
247244
if (err)
248245
return err;
249246

250247
/* enable/disable */
251248
if (!enabled)
252-
return gb_pwm_enable_operation(pwmc, pwm->hwpwm);
249+
return gb_pwm_enable_operation(chip, pwm->hwpwm);
253250

254251
return 0;
255252
}
@@ -282,7 +279,7 @@ static int gb_pwm_probe(struct gbphy_device *gbphy_dev,
282279

283280
pwmc->connection = connection;
284281
gb_connection_set_data(connection, pwmc);
285-
gb_gbphy_set_data(gbphy_dev, pwmc);
282+
gb_gbphy_set_data(gbphy_dev, chip);
286283

287284
ret = gb_connection_enable(connection);
288285
if (ret)
@@ -320,15 +317,16 @@ static int gb_pwm_probe(struct gbphy_device *gbphy_dev,
320317

321318
static void gb_pwm_remove(struct gbphy_device *gbphy_dev)
322319
{
323-
struct gb_pwm_chip *pwmc = gb_gbphy_get_data(gbphy_dev);
320+
struct pwm_chip *chip = gb_gbphy_get_data(gbphy_dev);
321+
struct gb_pwm_chip *pwmc = pwm_chip_to_gb_pwm_chip(chip);
324322
struct gb_connection *connection = pwmc->connection;
325323
int ret;
326324

327325
ret = gbphy_runtime_get_sync(gbphy_dev);
328326
if (ret)
329327
gbphy_runtime_get_noresume(gbphy_dev);
330328

331-
pwmchip_remove(&pwmc->chip);
329+
pwmchip_remove(chip);
332330
gb_connection_disable(connection);
333331
gb_connection_destroy(connection);
334332
kfree(pwmc);

0 commit comments

Comments
 (0)