diff options
author | Thierry Reding <thierry.reding@gmail.com> | 2016-05-17 08:44:37 -0400 |
---|---|---|
committer | Thierry Reding <thierry.reding@gmail.com> | 2016-05-17 08:44:37 -0400 |
commit | 3f1f368e4ab5ac2692e3dfec66a9e6a0a2f6cea7 (patch) | |
tree | 67d84a279f38b1582fb0345a9d81cd474cfa7965 | |
parent | f55532a0c0b8bb6148f4e07853b876ef73bc69ca (diff) | |
parent | fbd45a12988e75a48d392feb8b0e5feb5d612513 (diff) |
Merge branch 'for-4.7/pwm-args' into for-4.7/pwm-atomic
-rw-r--r-- | drivers/pwm/core.c | 26 | ||||
-rw-r--r-- | drivers/pwm/pwm-clps711x.c | 2 | ||||
-rw-r--r-- | drivers/pwm/pwm-pxa.c | 2 | ||||
-rw-r--r-- | include/linux/pwm.h | 33 |
4 files changed, 55 insertions, 8 deletions
diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c index 7831bc6b51dd..22cf3959041c 100644 --- a/drivers/pwm/core.c +++ b/drivers/pwm/core.c | |||
@@ -146,12 +146,12 @@ of_pwm_xlate_with_flags(struct pwm_chip *pc, const struct of_phandle_args *args) | |||
146 | if (IS_ERR(pwm)) | 146 | if (IS_ERR(pwm)) |
147 | return pwm; | 147 | return pwm; |
148 | 148 | ||
149 | pwm_set_period(pwm, args->args[1]); | 149 | pwm->args.period = args->args[1]; |
150 | 150 | ||
151 | if (args->args[2] & PWM_POLARITY_INVERTED) | 151 | if (args->args[2] & PWM_POLARITY_INVERTED) |
152 | pwm_set_polarity(pwm, PWM_POLARITY_INVERSED); | 152 | pwm->args.polarity = PWM_POLARITY_INVERSED; |
153 | else | 153 | else |
154 | pwm_set_polarity(pwm, PWM_POLARITY_NORMAL); | 154 | pwm->args.polarity = PWM_POLARITY_NORMAL; |
155 | 155 | ||
156 | return pwm; | 156 | return pwm; |
157 | } | 157 | } |
@@ -172,7 +172,7 @@ of_pwm_simple_xlate(struct pwm_chip *pc, const struct of_phandle_args *args) | |||
172 | if (IS_ERR(pwm)) | 172 | if (IS_ERR(pwm)) |
173 | return pwm; | 173 | return pwm; |
174 | 174 | ||
175 | pwm_set_period(pwm, args->args[1]); | 175 | pwm->args.period = args->args[1]; |
176 | 176 | ||
177 | return pwm; | 177 | return pwm; |
178 | } | 178 | } |
@@ -620,6 +620,13 @@ struct pwm_device *of_pwm_get(struct device_node *np, const char *con_id) | |||
620 | 620 | ||
621 | pwm->label = con_id; | 621 | pwm->label = con_id; |
622 | 622 | ||
623 | /* | ||
624 | * FIXME: This should be removed once all PWM users properly make use | ||
625 | * of struct pwm_args to initialize the PWM device. As long as this is | ||
626 | * here, the PWM state and hardware state can get out of sync. | ||
627 | */ | ||
628 | pwm_apply_args(pwm); | ||
629 | |||
623 | put: | 630 | put: |
624 | of_node_put(args.np); | 631 | of_node_put(args.np); |
625 | 632 | ||
@@ -751,8 +758,15 @@ struct pwm_device *pwm_get(struct device *dev, const char *con_id) | |||
751 | if (IS_ERR(pwm)) | 758 | if (IS_ERR(pwm)) |
752 | goto out; | 759 | goto out; |
753 | 760 | ||
754 | pwm_set_period(pwm, chosen->period); | 761 | pwm->args.period = chosen->period; |
755 | pwm_set_polarity(pwm, chosen->polarity); | 762 | pwm->args.polarity = chosen->polarity; |
763 | |||
764 | /* | ||
765 | * FIXME: This should be removed once all PWM users properly make use | ||
766 | * of struct pwm_args to initialize the PWM device. As long as this is | ||
767 | * here, the PWM state and hardware state can get out of sync. | ||
768 | */ | ||
769 | pwm_apply_args(pwm); | ||
756 | 770 | ||
757 | out: | 771 | out: |
758 | mutex_unlock(&pwm_lookup_lock); | 772 | mutex_unlock(&pwm_lookup_lock); |
diff --git a/drivers/pwm/pwm-clps711x.c b/drivers/pwm/pwm-clps711x.c index a80c10803636..7d335422cfda 100644 --- a/drivers/pwm/pwm-clps711x.c +++ b/drivers/pwm/pwm-clps711x.c | |||
@@ -60,7 +60,7 @@ static int clps711x_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm) | |||
60 | return -EINVAL; | 60 | return -EINVAL; |
61 | 61 | ||
62 | /* Store constant period value */ | 62 | /* Store constant period value */ |
63 | pwm_set_period(pwm, DIV_ROUND_CLOSEST(NSEC_PER_SEC, freq)); | 63 | pwm->args.period = DIV_ROUND_CLOSEST(NSEC_PER_SEC, freq); |
64 | 64 | ||
65 | return 0; | 65 | return 0; |
66 | } | 66 | } |
diff --git a/drivers/pwm/pwm-pxa.c b/drivers/pwm/pwm-pxa.c index cb2f7024cf68..58b709f29130 100644 --- a/drivers/pwm/pwm-pxa.c +++ b/drivers/pwm/pwm-pxa.c | |||
@@ -160,7 +160,7 @@ pxa_pwm_of_xlate(struct pwm_chip *pc, const struct of_phandle_args *args) | |||
160 | if (IS_ERR(pwm)) | 160 | if (IS_ERR(pwm)) |
161 | return pwm; | 161 | return pwm; |
162 | 162 | ||
163 | pwm_set_period(pwm, args->args[0]); | 163 | pwm->args.period = args->args[0]; |
164 | 164 | ||
165 | return pwm; | 165 | return pwm; |
166 | } | 166 | } |
diff --git a/include/linux/pwm.h b/include/linux/pwm.h index cfc3ed46cad2..b78d27c42629 100644 --- a/include/linux/pwm.h +++ b/include/linux/pwm.h | |||
@@ -74,6 +74,24 @@ enum pwm_polarity { | |||
74 | PWM_POLARITY_INVERSED, | 74 | PWM_POLARITY_INVERSED, |
75 | }; | 75 | }; |
76 | 76 | ||
77 | /** | ||
78 | * struct pwm_args - board-dependent PWM arguments | ||
79 | * @period: reference period | ||
80 | * @polarity: reference polarity | ||
81 | * | ||
82 | * This structure describes board-dependent arguments attached to a PWM | ||
83 | * device. These arguments are usually retrieved from the PWM lookup table or | ||
84 | * device tree. | ||
85 | * | ||
86 | * Do not confuse this with the PWM state: PWM arguments represent the initial | ||
87 | * configuration that users want to use on this PWM device rather than the | ||
88 | * current PWM hardware state. | ||
89 | */ | ||
90 | struct pwm_args { | ||
91 | unsigned int period; | ||
92 | enum pwm_polarity polarity; | ||
93 | }; | ||
94 | |||
77 | enum { | 95 | enum { |
78 | PWMF_REQUESTED = 1 << 0, | 96 | PWMF_REQUESTED = 1 << 0, |
79 | PWMF_ENABLED = 1 << 1, | 97 | PWMF_ENABLED = 1 << 1, |
@@ -92,6 +110,7 @@ enum { | |||
92 | * @period: period of the PWM signal (in nanoseconds) | 110 | * @period: period of the PWM signal (in nanoseconds) |
93 | * @duty_cycle: duty cycle of the PWM signal (in nanoseconds) | 111 | * @duty_cycle: duty cycle of the PWM signal (in nanoseconds) |
94 | * @polarity: polarity of the PWM signal | 112 | * @polarity: polarity of the PWM signal |
113 | * @args: PWM arguments | ||
95 | */ | 114 | */ |
96 | struct pwm_device { | 115 | struct pwm_device { |
97 | const char *label; | 116 | const char *label; |
@@ -105,6 +124,8 @@ struct pwm_device { | |||
105 | unsigned int period; | 124 | unsigned int period; |
106 | unsigned int duty_cycle; | 125 | unsigned int duty_cycle; |
107 | enum pwm_polarity polarity; | 126 | enum pwm_polarity polarity; |
127 | |||
128 | struct pwm_args args; | ||
108 | }; | 129 | }; |
109 | 130 | ||
110 | static inline bool pwm_is_enabled(const struct pwm_device *pwm) | 131 | static inline bool pwm_is_enabled(const struct pwm_device *pwm) |
@@ -144,6 +165,18 @@ static inline enum pwm_polarity pwm_get_polarity(const struct pwm_device *pwm) | |||
144 | return pwm ? pwm->polarity : PWM_POLARITY_NORMAL; | 165 | return pwm ? pwm->polarity : PWM_POLARITY_NORMAL; |
145 | } | 166 | } |
146 | 167 | ||
168 | static inline void pwm_get_args(const struct pwm_device *pwm, | ||
169 | struct pwm_args *args) | ||
170 | { | ||
171 | *args = pwm->args; | ||
172 | } | ||
173 | |||
174 | static inline void pwm_apply_args(struct pwm_device *pwm) | ||
175 | { | ||
176 | pwm_set_period(pwm, pwm->args.period); | ||
177 | pwm_set_polarity(pwm, pwm->args.polarity); | ||
178 | } | ||
179 | |||
147 | /** | 180 | /** |
148 | * struct pwm_ops - PWM controller operations | 181 | * struct pwm_ops - PWM controller operations |
149 | * @request: optional hook for requesting a PWM | 182 | * @request: optional hook for requesting a PWM |