@@ -25,6 +25,7 @@ struct soc_info {
};
struct jz4740_pwm_chip {
+ struct device *parent;
struct regmap *map;
struct clk *clk[];
};
@@ -37,10 +38,11 @@ static inline struct jz4740_pwm_chip *to_jz4740(struct pwm_chip *chip)
static bool jz4740_pwm_can_use_chn(struct pwm_chip *chip,
unsigned int channel)
{
+ struct jz4740_pwm_chip *jz = to_jz4740(chip);
/* Enable all TCU channels for PWM use by default except channels 0/1 */
u32 pwm_channels_mask = GENMASK(chip->npwm - 1, 2);
- device_property_read_u32(chip->dev->parent,
+ device_property_read_u32(jz->parent->parent,
"ingenic,pwm-channels-mask",
&pwm_channels_mask);
@@ -59,9 +61,9 @@ static int jz4740_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm)
snprintf(name, sizeof(name), "timer%u", pwm->hwpwm);
- clk = clk_get(chip->dev, name);
+ clk = clk_get(jz->parent, name);
if (IS_ERR(clk))
- return dev_err_probe(chip->dev, PTR_ERR(clk),
+ return dev_err_probe(jz->parent, PTR_ERR(clk),
"Failed to get clock\n");
err = clk_prepare_enable(clk);
@@ -148,7 +150,7 @@ static int jz4740_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
*/
rate = clk_round_rate(clk, tmp);
if (rate < 0) {
- dev_err(chip->dev, "Unable to round rate: %ld", rate);
+ dev_err(jz->parent, "Unable to round rate: %ld", rate);
return rate;
}
@@ -169,7 +171,7 @@ static int jz4740_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
err = clk_set_rate(clk, rate);
if (err) {
- dev_err(chip->dev, "Unable to set rate: %d", err);
+ dev_err(jz->parent, "Unable to set rate: %d", err);
return err;
}
@@ -235,6 +237,8 @@ static int jz4740_pwm_probe(struct platform_device *pdev)
return PTR_ERR(chip);
jz = to_jz4740(chip);
+ jz->parent = &pdev->dev;
+
jz->map = device_node_to_regmap(dev->parent->of_node);
if (IS_ERR(jz->map)) {
dev_err(dev, "regmap not found: %ld\n", PTR_ERR(jz->map));
@@ -290,7 +290,7 @@ struct pwm_ops {
* @pwms: array of PWM devices allocated by the framework
*/
struct pwm_chip {
- struct device *dev;
+ struct device dev;
const struct pwm_ops *ops;
struct module *owner;
int id;
struct pwm_chip::dev is about to change. To not have to touch this driver in the same commit as struct pwm_chip::dev, store a pointer to the parent device in driver data. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> --- drivers/pwm/pwm-jz4740.c | 14 +++++++++----- include/linux/pwm.h | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-)