Skip to content

Commit 22f032c

Browse files
ukleinekUwe Kleine-König
authored andcommitted
pwm: axi-pwmgen: Create a dedicated function for getting driver data from a chip
Compared to direct calls to pwmchip_get_drvdata() a dedicated function has two upsides: A better name and the right type. So the code becomes easier to read and the new function is harder to use wrongly. Another side effect (which is the secret motivation for this patch, but shhh) is that the driver becomes a bit easier to backport to kernel versions that don't have devm_pwmchip_alloc() yet. Signed-off-by: Uwe Kleine-König <[email protected]> Reviewed-by: Trevor Gamblin <[email protected]> Link: https://lore.kernel.org/r/[email protected] [ukleinek: added an * to the new function's prototype to make the compiler happy] Signed-off-by: Uwe Kleine-König <[email protected]>
1 parent 51f8137 commit 22f032c

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

drivers/pwm/pwm-axi-pwmgen.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,15 @@ static const struct regmap_config axi_pwmgen_regmap_config = {
5353
.max_register = 0xFC,
5454
};
5555

56+
static struct axi_pwmgen_ddata *axi_pwmgen_ddata_from_chip(struct pwm_chip *chip)
57+
{
58+
return pwmchip_get_drvdata(chip);
59+
}
60+
5661
static int axi_pwmgen_apply(struct pwm_chip *chip, struct pwm_device *pwm,
5762
const struct pwm_state *state)
5863
{
59-
struct axi_pwmgen_ddata *ddata = pwmchip_get_drvdata(chip);
64+
struct axi_pwmgen_ddata *ddata = axi_pwmgen_ddata_from_chip(chip);
6065
unsigned int ch = pwm->hwpwm;
6166
struct regmap *regmap = ddata->regmap;
6267
u64 period_cnt, duty_cnt;
@@ -100,7 +105,7 @@ static int axi_pwmgen_apply(struct pwm_chip *chip, struct pwm_device *pwm,
100105
static int axi_pwmgen_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
101106
struct pwm_state *state)
102107
{
103-
struct axi_pwmgen_ddata *ddata = pwmchip_get_drvdata(chip);
108+
struct axi_pwmgen_ddata *ddata = axi_pwmgen_ddata_from_chip(chip);
104109
struct regmap *regmap = ddata->regmap;
105110
unsigned int ch = pwm->hwpwm;
106111
u32 cnt;

0 commit comments

Comments
 (0)