pwm: Provide an inline function to get the parent device of a given chip
[linux-2.6-microblaze.git] / drivers / pwm / core.c
index 1b4c3d0..830a697 100644 (file)
@@ -71,18 +71,18 @@ static void pwm_apply_debug(struct pwm_device *pwm,
 
        if (s2.polarity != state->polarity &&
            state->duty_cycle < state->period)
-               dev_warn(chip->dev, ".apply ignored .polarity\n");
+               dev_warn(pwmchip_parent(chip), ".apply ignored .polarity\n");
 
        if (state->enabled &&
            last->polarity == state->polarity &&
            last->period > s2.period &&
            last->period <= state->period)
-               dev_warn(chip->dev,
+               dev_warn(pwmchip_parent(chip),
                         ".apply didn't pick the best available period (requested: %llu, applied: %llu, possible: %llu)\n",
                         state->period, s2.period, last->period);
 
        if (state->enabled && state->period < s2.period)
-               dev_warn(chip->dev,
+               dev_warn(pwmchip_parent(chip),
                         ".apply is supposed to round down period (requested: %llu, applied: %llu)\n",
                         state->period, s2.period);
 
@@ -91,20 +91,20 @@ static void pwm_apply_debug(struct pwm_device *pwm,
            last->period == s2.period &&
            last->duty_cycle > s2.duty_cycle &&
            last->duty_cycle <= state->duty_cycle)
-               dev_warn(chip->dev,
+               dev_warn(pwmchip_parent(chip),
                         ".apply didn't pick the best available duty cycle (requested: %llu/%llu, applied: %llu/%llu, possible: %llu/%llu)\n",
                         state->duty_cycle, state->period,
                         s2.duty_cycle, s2.period,
                         last->duty_cycle, last->period);
 
        if (state->enabled && state->duty_cycle < s2.duty_cycle)
-               dev_warn(chip->dev,
+               dev_warn(pwmchip_parent(chip),
                         ".apply is supposed to round down duty_cycle (requested: %llu/%llu, applied: %llu/%llu)\n",
                         state->duty_cycle, state->period,
                         s2.duty_cycle, s2.period);
 
        if (!state->enabled && s2.enabled && s2.duty_cycle > 0)
-               dev_warn(chip->dev,
+               dev_warn(pwmchip_parent(chip),
                         "requested disabled, but yielded enabled with duty > 0\n");
 
        /* reapply the state that the driver reported being configured. */
@@ -112,7 +112,7 @@ static void pwm_apply_debug(struct pwm_device *pwm,
        trace_pwm_apply(pwm, &s1, err);
        if (err) {
                *last = s1;
-               dev_err(chip->dev, "failed to reapply current setting\n");
+               dev_err(pwmchip_parent(chip), "failed to reapply current setting\n");
                return;
        }
 
@@ -127,7 +127,7 @@ static void pwm_apply_debug(struct pwm_device *pwm,
            s1.polarity != last->polarity ||
            (s1.enabled && s1.period != last->period) ||
            (s1.enabled && s1.duty_cycle != last->duty_cycle)) {
-               dev_err(chip->dev,
+               dev_err(pwmchip_parent(chip),
                        ".apply is not idempotent (ena=%d pol=%d %llu/%llu) -> (ena=%d pol=%d %llu/%llu)\n",
                        s1.enabled, s1.polarity, s1.duty_cycle, s1.period,
                        last->enabled, last->polarity, last->duty_cycle,
@@ -318,7 +318,7 @@ static struct pwm_chip *pwmchip_find_by_name(const char *name)
        mutex_lock(&pwm_lock);
 
        idr_for_each_entry_ul(&pwm_chips, chip, tmp, id) {
-               const char *chip_name = dev_name(chip->dev);
+               const char *chip_name = dev_name(pwmchip_parent(chip));
 
                if (chip_name && strcmp(chip_name, name) == 0) {
                        mutex_unlock(&pwm_lock);
@@ -456,19 +456,19 @@ EXPORT_SYMBOL_GPL(of_pwm_single_xlate);
 
 static void of_pwmchip_add(struct pwm_chip *chip)
 {
-       if (!chip->dev || !chip->dev->of_node)
+       if (!pwmchip_parent(chip) || !pwmchip_parent(chip)->of_node)
                return;
 
        if (!chip->of_xlate)
                chip->of_xlate = of_pwm_xlate_with_flags;
 
-       of_node_get(chip->dev->of_node);
+       of_node_get(pwmchip_parent(chip)->of_node);
 }
 
 static void of_pwmchip_remove(struct pwm_chip *chip)
 {
-       if (chip->dev)
-               of_node_put(chip->dev->of_node);
+       if (pwmchip_parent(chip))
+               of_node_put(pwmchip_parent(chip)->of_node);
 }
 
 static bool pwm_ops_check(const struct pwm_chip *chip)
@@ -479,7 +479,7 @@ static bool pwm_ops_check(const struct pwm_chip *chip)
                return false;
 
        if (IS_ENABLED(CONFIG_PWM_DEBUG) && !ops->get_state)
-               dev_warn(chip->dev,
+               dev_warn(pwmchip_parent(chip),
                         "Please implement the .get_state() callback\n");
 
        return true;
@@ -500,7 +500,7 @@ int __pwmchip_add(struct pwm_chip *chip, struct module *owner)
        unsigned int i;
        int ret;
 
-       if (!chip || !chip->dev || !chip->ops || !chip->npwm)
+       if (!chip || !pwmchip_parent(chip) || !chip->ops || !chip->npwm)
                return -EINVAL;
 
        if (!pwm_ops_check(chip))
@@ -594,15 +594,15 @@ static struct device_link *pwm_device_link_add(struct device *dev,
                 * impact the PM sequence ordering: the PWM supplier may get
                 * suspended before the consumer.
                 */
-               dev_warn(pwm->chip->dev,
+               dev_warn(pwmchip_parent(pwm->chip),
                         "No consumer device specified to create a link to\n");
                return NULL;
        }
 
-       dl = device_link_add(dev, pwm->chip->dev, DL_FLAG_AUTOREMOVE_CONSUMER);
+       dl = device_link_add(dev, pwmchip_parent(pwm->chip), DL_FLAG_AUTOREMOVE_CONSUMER);
        if (!dl) {
                dev_err(dev, "failed to create device link to %s\n",
-                       dev_name(pwm->chip->dev));
+                       dev_name(pwmchip_parent(pwm->chip)));
                return ERR_PTR(-EINVAL);
        }
 
@@ -617,7 +617,7 @@ static struct pwm_chip *fwnode_to_pwmchip(struct fwnode_handle *fwnode)
        mutex_lock(&pwm_lock);
 
        idr_for_each_entry_ul(&pwm_chips, chip, tmp, id)
-               if (chip->dev && device_match_fwnode(chip->dev, fwnode)) {
+               if (pwmchip_parent(chip) && device_match_fwnode(pwmchip_parent(chip), fwnode)) {
                        mutex_unlock(&pwm_lock);
                        return chip;
                }
@@ -1085,8 +1085,8 @@ static int pwm_seq_show(struct seq_file *s, void *v)
 
        seq_printf(s, "%s%d: %s/%s, %d PWM device%s\n",
                   (char *)s->private, chip->id,
-                  chip->dev->bus ? chip->dev->bus->name : "no-bus",
-                  dev_name(chip->dev), chip->npwm,
+                  pwmchip_parent(chip)->bus ? pwmchip_parent(chip)->bus->name : "no-bus",
+                  dev_name(pwmchip_parent(chip)), chip->npwm,
                   (chip->npwm != 1) ? "s" : "");
 
        pwm_dbg_show(chip, s);