Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'pwm/for-5.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/thierry.reding/linux-pwm

Pull pwm updates from Thierry Reding:
"This contains conversions of some more drivers to the atomic API as
well as the addition of new chip support for some existing drivers.

There are also various minor fixes and cleanups across the board, from
drivers to device tree bindings"

* tag 'pwm/for-5.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/thierry.reding/linux-pwm: (45 commits)
pwm: rcar: Simplify multiplication/shift logic
dt-bindings: pwm: renesas,tpu: Do not require pwm-cells twice
dt-bindings: pwm: tiehrpwm: Do not require pwm-cells twice
dt-bindings: pwm: tiecap: Do not require pwm-cells twice
dt-bindings: pwm: samsung: Do not require pwm-cells twice
dt-bindings: pwm: intel,keembay: Do not require pwm-cells twice
dt-bindings: pwm: brcm,bcm7038: Do not require pwm-cells twice
dt-bindings: pwm: toshiba,visconti: Include generic PWM schema
dt-bindings: pwm: renesas,pwm: Include generic PWM schema
dt-bindings: pwm: sifive: Include generic PWM schema
dt-bindings: pwm: rockchip: Include generic PWM schema
dt-bindings: pwm: mxs: Include generic PWM schema
dt-bindings: pwm: iqs620a: Include generic PWM schema
dt-bindings: pwm: intel,lgm: Include generic PWM schema
dt-bindings: pwm: imx: Include generic PWM schema
dt-bindings: pwm: allwinner,sun4i-a10: Include generic PWM schema
pwm: pwm-mediatek: Beautify error messages text
pwm: pwm-mediatek: Allocate clk_pwms with devm_kmalloc_array
pwm: pwm-mediatek: Simplify error handling with dev_err_probe()
pwm: brcmstb: Remove useless locking
...

+484 -393
+4
Documentation/devicetree/bindings/mfd/google,cros-ec.yaml
··· 85 85 86 86 ec-pwm: 87 87 $ref: "/schemas/pwm/google,cros-ec-pwm.yaml#" 88 + deprecated: true 89 + 90 + pwm: 91 + $ref: "/schemas/pwm/google,cros-ec-pwm.yaml#" 88 92 89 93 keyboard-controller: 90 94 $ref: "/schemas/input/google,cros-ec-keyb.yaml#"
+24 -21
Documentation/devicetree/bindings/pwm/allwinner,sun4i-a10-pwm.yaml
··· 52 52 resets: 53 53 maxItems: 1 54 54 55 - if: 56 - properties: 57 - compatible: 58 - contains: 59 - const: allwinner,sun50i-h6-pwm 60 55 61 - then: 62 - properties: 63 - clocks: 64 - maxItems: 2 56 + allOf: 57 + - $ref: pwm.yaml# 65 58 66 - clock-names: 67 - items: 68 - - const: mod 69 - - const: bus 59 + - if: 60 + properties: 61 + compatible: 62 + contains: 63 + const: allwinner,sun50i-h6-pwm 70 64 71 - required: 72 - - clock-names 73 - - resets 65 + then: 66 + properties: 67 + clocks: 68 + maxItems: 2 74 69 75 - else: 76 - properties: 77 - clocks: 78 - maxItems: 1 70 + clock-names: 71 + items: 72 + - const: mod 73 + - const: bus 74 + 75 + required: 76 + - clock-names 77 + - resets 78 + 79 + else: 80 + properties: 81 + clocks: 82 + maxItems: 1 79 83 80 84 required: 81 - - "#pwm-cells" 82 85 - compatible 83 86 - reg 84 87 - clocks
-1
Documentation/devicetree/bindings/pwm/brcm,bcm7038-pwm.yaml
··· 28 28 required: 29 29 - compatible 30 30 - reg 31 - - "#pwm-cells" 32 31 - clocks 33 32 34 33 additionalProperties: false
+4 -1
Documentation/devicetree/bindings/pwm/google,cros-ec-pwm.yaml
··· 16 16 An EC PWM node should be only found as a sub-node of the EC node (see 17 17 Documentation/devicetree/bindings/mfd/google,cros-ec.yaml). 18 18 19 + allOf: 20 + - $ref: pwm.yaml# 21 + 19 22 properties: 20 23 compatible: 21 24 const: google,cros-ec-pwm ··· 42 39 compatible = "google,cros-ec-spi"; 43 40 reg = <0>; 44 41 45 - cros_ec_pwm: ec-pwm { 42 + cros_ec_pwm: pwm { 46 43 compatible = "google,cros-ec-pwm"; 47 44 #pwm-cells = <1>; 48 45 };
+3 -1
Documentation/devicetree/bindings/pwm/imx-pwm.yaml
··· 9 9 maintainers: 10 10 - Philipp Zabel <p.zabel@pengutronix.de> 11 11 12 + allOf: 13 + - $ref: pwm.yaml# 14 + 12 15 properties: 13 16 "#pwm-cells": 14 17 description: | ··· 62 59 maxItems: 1 63 60 64 61 required: 65 - - "#pwm-cells" 66 62 - compatible 67 63 - reg 68 64 - clocks
+3 -1
Documentation/devicetree/bindings/pwm/imx-tpm-pwm.yaml
··· 13 13 The TPM counter and period counter are shared between multiple 14 14 channels, so all channels should use same period setting. 15 15 16 + allOf: 17 + - $ref: pwm.yaml# 18 + 16 19 properties: 17 20 "#pwm-cells": 18 21 const: 3 ··· 37 34 maxItems: 1 38 35 39 36 required: 40 - - "#pwm-cells" 41 37 - compatible 42 38 - reg 43 39 - clocks
-1
Documentation/devicetree/bindings/pwm/intel,keembay-pwm.yaml
··· 31 31 - compatible 32 32 - reg 33 33 - clocks 34 - - '#pwm-cells' 35 34 36 35 additionalProperties: false 37 36
+3
Documentation/devicetree/bindings/pwm/intel,lgm-pwm.yaml
··· 9 9 maintainers: 10 10 - Rahul Tanwar <rtanwar@maxlinear.com> 11 11 12 + allOf: 13 + - $ref: pwm.yaml# 14 + 12 15 properties: 13 16 compatible: 14 17 const: intel,lgm-pwm
+3 -1
Documentation/devicetree/bindings/pwm/iqs620a-pwm.yaml
··· 15 15 Documentation/devicetree/bindings/mfd/iqs62x.yaml for further details as 16 16 well as an example. 17 17 18 + allOf: 19 + - $ref: pwm.yaml# 20 + 18 21 properties: 19 22 compatible: 20 23 enum: ··· 28 25 29 26 required: 30 27 - compatible 31 - - "#pwm-cells" 32 28 33 29 additionalProperties: false 34 30
+3 -1
Documentation/devicetree/bindings/pwm/mxs-pwm.yaml
··· 10 10 - Shawn Guo <shawnguo@kernel.org> 11 11 - Anson Huang <anson.huang@nxp.com> 12 12 13 + allOf: 14 + - $ref: pwm.yaml# 15 + 13 16 properties: 14 17 compatible: 15 18 enum: ··· 31 28 required: 32 29 - compatible 33 30 - reg 34 - - "#pwm-cells" 35 31 - fsl,pwm-number 36 32 37 33 additionalProperties: false
+1
Documentation/devicetree/bindings/pwm/pwm-mtk-disp.txt
··· 6 6 - "mediatek,mt6595-disp-pwm": found on mt6595 SoC. 7 7 - "mediatek,mt8167-disp-pwm", "mediatek,mt8173-disp-pwm": found on mt8167 SoC. 8 8 - "mediatek,mt8173-disp-pwm": found on mt8173 SoC. 9 + - "mediatek,mt8183-disp-pwm": found on mt8183 SoC.$ 9 10 - reg: physical base address and length of the controller's registers. 10 11 - #pwm-cells: must be 2. See pwm.yaml in this directory for a description of 11 12 the cell format.
+32 -30
Documentation/devicetree/bindings/pwm/pwm-rockchip.yaml
··· 51 51 required: 52 52 - compatible 53 53 - reg 54 - - "#pwm-cells" 55 54 56 - if: 57 - properties: 58 - compatible: 59 - contains: 60 - enum: 61 - - rockchip,rk3328-pwm 62 - - rockchip,rv1108-pwm 55 + allOf: 56 + - $ref: pwm.yaml# 63 57 64 - then: 65 - properties: 66 - clocks: 67 - items: 68 - - description: Used to derive the functional clock for the device. 69 - - description: Used as the APB bus clock. 58 + - if: 59 + properties: 60 + compatible: 61 + contains: 62 + enum: 63 + - rockchip,rk3328-pwm 64 + - rockchip,rv1108-pwm 70 65 71 - clock-names: 72 - items: 73 - - const: pwm 74 - - const: pclk 66 + then: 67 + properties: 68 + clocks: 69 + items: 70 + - description: Used to derive the functional clock for the device. 71 + - description: Used as the APB bus clock. 75 72 76 - required: 77 - - clocks 78 - - clock-names 73 + clock-names: 74 + items: 75 + - const: pwm 76 + - const: pclk 79 77 80 - else: 81 - properties: 82 - clocks: 83 - maxItems: 1 84 - description: 85 - Used both to derive the functional clock 86 - for the device and as the bus clock. 78 + required: 79 + - clocks 80 + - clock-names 87 81 88 - required: 89 - - clocks 82 + else: 83 + properties: 84 + clocks: 85 + maxItems: 1 86 + description: 87 + Used both to derive the functional clock 88 + for the device and as the bus clock. 89 + 90 + required: 91 + - clocks 90 92 91 93 additionalProperties: false 92 94
-1
Documentation/devicetree/bindings/pwm/pwm-samsung.yaml
··· 86 86 - clocks 87 87 - clock-names 88 88 - compatible 89 - - "#pwm-cells" 90 89 - reg 91 90 92 91 additionalProperties: false
+3 -1
Documentation/devicetree/bindings/pwm/pwm-sifive.yaml
··· 21 21 22 22 https://github.com/sifive/sifive-blocks/tree/master/src/main/scala/devices/pwm 23 23 24 + allOf: 25 + - $ref: pwm.yaml# 26 + 24 27 properties: 25 28 compatible: 26 29 items: ··· 57 54 - compatible 58 55 - reg 59 56 - clocks 60 - - "#pwm-cells" 61 57 - interrupts 62 58 63 59 additionalProperties: false
-1
Documentation/devicetree/bindings/pwm/pwm-tiecap.yaml
··· 47 47 required: 48 48 - compatible 49 49 - reg 50 - - "#pwm-cells" 51 50 - clocks 52 51 - clock-names 53 52
-1
Documentation/devicetree/bindings/pwm/pwm-tiehrpwm.yaml
··· 48 48 required: 49 49 - compatible 50 50 - reg 51 - - "#pwm-cells" 52 51 - clocks 53 52 - clock-names 54 53
+14 -12
Documentation/devicetree/bindings/pwm/renesas,pwm-rcar.yaml
··· 59 59 required: 60 60 - compatible 61 61 - reg 62 - - '#pwm-cells' 63 62 - clocks 64 63 - power-domains 65 64 66 - if: 67 - not: 68 - properties: 69 - compatible: 70 - contains: 71 - enum: 72 - - renesas,pwm-r8a7778 73 - - renesas,pwm-r8a7779 74 - then: 75 - required: 76 - - resets 65 + allOf: 66 + - $ref: pwm.yaml# 67 + 68 + - if: 69 + not: 70 + properties: 71 + compatible: 72 + contains: 73 + enum: 74 + - renesas,pwm-r8a7778 75 + - renesas,pwm-r8a7779 76 + then: 77 + required: 78 + - resets 77 79 78 80 additionalProperties: false 79 81
-1
Documentation/devicetree/bindings/pwm/renesas,tpu-pwm.yaml
··· 68 68 required: 69 69 - compatible 70 70 - reg 71 - - '#pwm-cells' 72 71 - clocks 73 72 - power-domains 74 73
+3 -1
Documentation/devicetree/bindings/pwm/toshiba,pwm-visconti.yaml
··· 9 9 maintainers: 10 10 - Nobuhiro Iwamatsu <nobuhiro1.iwamatsu@toshiba.co.jp> 11 11 12 + allOf: 13 + - $ref: pwm.yaml# 14 + 12 15 properties: 13 16 compatible: 14 17 items: ··· 26 23 required: 27 24 - compatible 28 25 - reg 29 - - '#pwm-cells' 30 26 31 27 additionalProperties: false 32 28
+1
Documentation/devicetree/bindings/timer/ingenic,tcu.yaml
··· 152 152 - enum: 153 153 - ingenic,jz4740-pwm 154 154 - ingenic,jz4725b-pwm 155 + - ingenic,x1000-pwm 155 156 - items: 156 157 - enum: 157 158 - ingenic,jz4760-pwm
+1 -1
drivers/pwm/pwm-atmel.c
··· 271 271 bool disable_clk) 272 272 { 273 273 struct atmel_pwm_chip *atmel_pwm = to_atmel_pwm_chip(chip); 274 - unsigned long timeout = jiffies + 2 * HZ; 274 + unsigned long timeout; 275 275 276 276 atmel_pwm_wait_nonpending(atmel_pwm, pwm->hwpwm); 277 277
+58 -32
drivers/pwm/pwm-bcm-kona.c
··· 109 109 } 110 110 111 111 static int kona_pwmc_config(struct pwm_chip *chip, struct pwm_device *pwm, 112 - int duty_ns, int period_ns) 112 + u64 duty_ns, u64 period_ns) 113 113 { 114 114 struct kona_pwmc *kp = to_kona_pwmc(chip); 115 - u64 val, div, rate; 115 + u64 div, rate; 116 116 unsigned long prescale = PRESCALE_MIN, pc, dc; 117 117 unsigned int value, chan = pwm->hwpwm; 118 118 ··· 132 132 while (1) { 133 133 div = 1000000000; 134 134 div *= 1 + prescale; 135 - val = rate * period_ns; 136 - pc = div64_u64(val, div); 137 - val = rate * duty_ns; 138 - dc = div64_u64(val, div); 135 + pc = mul_u64_u64_div_u64(rate, period_ns, div); 136 + dc = mul_u64_u64_div_u64(rate, duty_ns, div); 139 137 140 138 /* If duty_ns or period_ns are not achievable then return */ 141 139 if (pc < PERIOD_COUNT_MIN) ··· 148 150 return -EINVAL; 149 151 } 150 152 151 - /* 152 - * Don't apply settings if disabled. The period and duty cycle are 153 - * always calculated above to ensure the new values are 154 - * validated immediately instead of on enable. 155 - */ 156 - if (pwm_is_enabled(pwm)) { 157 - kona_pwmc_prepare_for_settings(kp, chan); 153 + kona_pwmc_prepare_for_settings(kp, chan); 158 154 159 - value = readl(kp->base + PRESCALE_OFFSET); 160 - value &= ~PRESCALE_MASK(chan); 161 - value |= prescale << PRESCALE_SHIFT(chan); 162 - writel(value, kp->base + PRESCALE_OFFSET); 155 + value = readl(kp->base + PRESCALE_OFFSET); 156 + value &= ~PRESCALE_MASK(chan); 157 + value |= prescale << PRESCALE_SHIFT(chan); 158 + writel(value, kp->base + PRESCALE_OFFSET); 163 159 164 - writel(pc, kp->base + PERIOD_COUNT_OFFSET(chan)); 160 + writel(pc, kp->base + PERIOD_COUNT_OFFSET(chan)); 165 161 166 - writel(dc, kp->base + DUTY_CYCLE_HIGH_OFFSET(chan)); 162 + writel(dc, kp->base + DUTY_CYCLE_HIGH_OFFSET(chan)); 167 163 168 - kona_pwmc_apply_settings(kp, chan); 169 - } 164 + kona_pwmc_apply_settings(kp, chan); 170 165 171 166 return 0; 172 167 } ··· 207 216 return ret; 208 217 } 209 218 210 - ret = kona_pwmc_config(chip, pwm, pwm_get_duty_cycle(pwm), 211 - pwm_get_period(pwm)); 212 - if (ret < 0) { 213 - clk_disable_unprepare(kp->clk); 214 - return ret; 215 - } 216 - 217 219 return 0; 218 220 } 219 221 ··· 232 248 clk_disable_unprepare(kp->clk); 233 249 } 234 250 251 + static int kona_pwmc_apply(struct pwm_chip *chip, struct pwm_device *pwm, 252 + const struct pwm_state *state) 253 + { 254 + int err; 255 + struct kona_pwmc *kp = to_kona_pwmc(chip); 256 + bool enabled = pwm->state.enabled; 257 + 258 + if (state->polarity != pwm->state.polarity) { 259 + if (enabled) { 260 + kona_pwmc_disable(chip, pwm); 261 + enabled = false; 262 + } 263 + 264 + err = kona_pwmc_set_polarity(chip, pwm, state->polarity); 265 + if (err) 266 + return err; 267 + 268 + pwm->state.polarity = state->polarity; 269 + } 270 + 271 + if (!state->enabled) { 272 + if (enabled) 273 + kona_pwmc_disable(chip, pwm); 274 + return 0; 275 + } else if (!enabled) { 276 + /* 277 + * This is a bit special here, usually the PWM should only be 278 + * enabled when duty and period are setup. But before this 279 + * driver was converted to .apply it was done the other way 280 + * around and so this behaviour was kept even though this might 281 + * result in a glitch. This might be improvable by someone with 282 + * hardware and/or documentation. 283 + */ 284 + err = kona_pwmc_enable(chip, pwm); 285 + if (err) 286 + return err; 287 + } 288 + 289 + err = kona_pwmc_config(pwm->chip, pwm, state->duty_cycle, state->period); 290 + if (err && !pwm->state.enabled) 291 + clk_disable_unprepare(kp->clk); 292 + 293 + return err; 294 + } 295 + 235 296 static const struct pwm_ops kona_pwm_ops = { 236 - .config = kona_pwmc_config, 237 - .set_polarity = kona_pwmc_set_polarity, 238 - .enable = kona_pwmc_enable, 239 - .disable = kona_pwmc_disable, 297 + .apply = kona_pwmc_apply, 240 298 .owner = THIS_MODULE, 241 299 }; 242 300
+25 -29
drivers/pwm/pwm-brcmstb.c
··· 53 53 54 54 struct brcmstb_pwm { 55 55 void __iomem *base; 56 - spinlock_t lock; 57 56 struct clk *clk; 58 57 struct pwm_chip chip; 59 58 }; ··· 94 95 * "on" time, so this translates directly into our HW programming here. 95 96 */ 96 97 static int brcmstb_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, 97 - int duty_ns, int period_ns) 98 + u64 duty_ns, u64 period_ns) 98 99 { 99 100 struct brcmstb_pwm *p = to_brcmstb_pwm(chip); 100 101 unsigned long pc, dc, cword = CONST_VAR_F_MAX; ··· 113 114 } 114 115 115 116 while (1) { 116 - u64 rate, tmp; 117 + u64 rate; 117 118 118 119 /* 119 120 * Calculate the base rate from base frequency and current 120 121 * cword 121 122 */ 122 123 rate = (u64)clk_get_rate(p->clk) * (u64)cword; 123 - do_div(rate, 1 << CWORD_BIT_SIZE); 124 + rate >>= CWORD_BIT_SIZE; 124 125 125 - tmp = period_ns * rate; 126 - do_div(tmp, NSEC_PER_SEC); 127 - pc = tmp; 128 - 129 - tmp = (duty_ns + 1) * rate; 130 - do_div(tmp, NSEC_PER_SEC); 131 - dc = tmp; 126 + pc = mul_u64_u64_div_u64(period_ns, rate, NSEC_PER_SEC); 127 + dc = mul_u64_u64_div_u64(duty_ns + 1, rate, NSEC_PER_SEC); 132 128 133 129 /* 134 130 * We can be called with separate duty and period updates, ··· 158 164 * generator output a base frequency for the constant frequency 159 165 * generator to derive from. 160 166 */ 161 - spin_lock(&p->lock); 162 167 brcmstb_pwm_writel(p, cword >> 8, PWM_CWORD_MSB(channel)); 163 168 brcmstb_pwm_writel(p, cword & 0xff, PWM_CWORD_LSB(channel)); 164 169 ··· 169 176 /* Configure on and period value */ 170 177 brcmstb_pwm_writel(p, pc, PWM_PERIOD(channel)); 171 178 brcmstb_pwm_writel(p, dc, PWM_ON(channel)); 172 - spin_unlock(&p->lock); 173 179 174 180 return 0; 175 181 } ··· 179 187 unsigned int shift = channel * CTRL_CHAN_OFFS; 180 188 u32 value; 181 189 182 - spin_lock(&p->lock); 183 190 value = brcmstb_pwm_readl(p, PWM_CTRL); 184 191 185 192 if (enable) { ··· 190 199 } 191 200 192 201 brcmstb_pwm_writel(p, value, PWM_CTRL); 193 - spin_unlock(&p->lock); 194 202 } 195 203 196 - static int brcmstb_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm) 204 + static int brcmstb_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, 205 + const struct pwm_state *state) 197 206 { 198 207 struct brcmstb_pwm *p = to_brcmstb_pwm(chip); 208 + int err; 199 209 200 - brcmstb_pwm_enable_set(p, pwm->hwpwm, true); 210 + if (state->polarity != PWM_POLARITY_NORMAL) 211 + return -EINVAL; 212 + 213 + if (!state->enabled) { 214 + if (pwm->state.enabled) 215 + brcmstb_pwm_enable_set(p, pwm->hwpwm, false); 216 + 217 + return 0; 218 + } 219 + 220 + err = brcmstb_pwm_config(chip, pwm, state->duty_cycle, state->period); 221 + if (err) 222 + return err; 223 + 224 + if (!pwm->state.enabled) 225 + brcmstb_pwm_enable_set(p, pwm->hwpwm, true); 201 226 202 227 return 0; 203 228 } 204 229 205 - static void brcmstb_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm) 206 - { 207 - struct brcmstb_pwm *p = to_brcmstb_pwm(chip); 208 - 209 - brcmstb_pwm_enable_set(p, pwm->hwpwm, false); 210 - } 211 - 212 230 static const struct pwm_ops brcmstb_pwm_ops = { 213 - .config = brcmstb_pwm_config, 214 - .enable = brcmstb_pwm_enable, 215 - .disable = brcmstb_pwm_disable, 231 + .apply = brcmstb_pwm_apply, 216 232 .owner = THIS_MODULE, 217 233 }; 218 234 ··· 237 239 p = devm_kzalloc(&pdev->dev, sizeof(*p), GFP_KERNEL); 238 240 if (!p) 239 241 return -ENOMEM; 240 - 241 - spin_lock_init(&p->lock); 242 242 243 243 p->clk = devm_clk_get(&pdev->dev, NULL); 244 244 if (IS_ERR(p->clk)) {
+70 -71
drivers/pwm/pwm-img.c
··· 77 77 return container_of(chip, struct img_pwm_chip, chip); 78 78 } 79 79 80 - static inline void img_pwm_writel(struct img_pwm_chip *chip, 80 + static inline void img_pwm_writel(struct img_pwm_chip *imgchip, 81 81 u32 reg, u32 val) 82 82 { 83 - writel(val, chip->base + reg); 83 + writel(val, imgchip->base + reg); 84 84 } 85 85 86 - static inline u32 img_pwm_readl(struct img_pwm_chip *chip, 87 - u32 reg) 86 + static inline u32 img_pwm_readl(struct img_pwm_chip *imgchip, u32 reg) 88 87 { 89 - return readl(chip->base + reg); 88 + return readl(imgchip->base + reg); 90 89 } 91 90 92 91 static int img_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, ··· 93 94 { 94 95 u32 val, div, duty, timebase; 95 96 unsigned long mul, output_clk_hz, input_clk_hz; 96 - struct img_pwm_chip *pwm_chip = to_img_pwm_chip(chip); 97 - unsigned int max_timebase = pwm_chip->data->max_timebase; 97 + struct img_pwm_chip *imgchip = to_img_pwm_chip(chip); 98 + unsigned int max_timebase = imgchip->data->max_timebase; 98 99 int ret; 99 100 100 - if (period_ns < pwm_chip->min_period_ns || 101 - period_ns > pwm_chip->max_period_ns) { 101 + if (period_ns < imgchip->min_period_ns || 102 + period_ns > imgchip->max_period_ns) { 102 103 dev_err(chip->dev, "configured period not in range\n"); 103 104 return -ERANGE; 104 105 } 105 106 106 - input_clk_hz = clk_get_rate(pwm_chip->pwm_clk); 107 + input_clk_hz = clk_get_rate(imgchip->pwm_clk); 107 108 output_clk_hz = DIV_ROUND_UP(NSEC_PER_SEC, period_ns); 108 109 109 110 mul = DIV_ROUND_UP(input_clk_hz, output_clk_hz); ··· 131 132 if (ret < 0) 132 133 return ret; 133 134 134 - val = img_pwm_readl(pwm_chip, PWM_CTRL_CFG); 135 + val = img_pwm_readl(imgchip, PWM_CTRL_CFG); 135 136 val &= ~(PWM_CTRL_CFG_DIV_MASK << PWM_CTRL_CFG_DIV_SHIFT(pwm->hwpwm)); 136 137 val |= (div & PWM_CTRL_CFG_DIV_MASK) << 137 138 PWM_CTRL_CFG_DIV_SHIFT(pwm->hwpwm); 138 - img_pwm_writel(pwm_chip, PWM_CTRL_CFG, val); 139 + img_pwm_writel(imgchip, PWM_CTRL_CFG, val); 139 140 140 141 val = (duty << PWM_CH_CFG_DUTY_SHIFT) | 141 142 (timebase << PWM_CH_CFG_TMBASE_SHIFT); 142 - img_pwm_writel(pwm_chip, PWM_CH_CFG(pwm->hwpwm), val); 143 + img_pwm_writel(imgchip, PWM_CH_CFG(pwm->hwpwm), val); 143 144 144 145 pm_runtime_mark_last_busy(chip->dev); 145 146 pm_runtime_put_autosuspend(chip->dev); ··· 150 151 static int img_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm) 151 152 { 152 153 u32 val; 153 - struct img_pwm_chip *pwm_chip = to_img_pwm_chip(chip); 154 + struct img_pwm_chip *imgchip = to_img_pwm_chip(chip); 154 155 int ret; 155 156 156 157 ret = pm_runtime_resume_and_get(chip->dev); 157 158 if (ret < 0) 158 159 return ret; 159 160 160 - val = img_pwm_readl(pwm_chip, PWM_CTRL_CFG); 161 + val = img_pwm_readl(imgchip, PWM_CTRL_CFG); 161 162 val |= BIT(pwm->hwpwm); 162 - img_pwm_writel(pwm_chip, PWM_CTRL_CFG, val); 163 + img_pwm_writel(imgchip, PWM_CTRL_CFG, val); 163 164 164 - regmap_update_bits(pwm_chip->periph_regs, PERIP_PWM_PDM_CONTROL, 165 + regmap_update_bits(imgchip->periph_regs, PERIP_PWM_PDM_CONTROL, 165 166 PERIP_PWM_PDM_CONTROL_CH_MASK << 166 167 PERIP_PWM_PDM_CONTROL_CH_SHIFT(pwm->hwpwm), 0); 167 168 ··· 171 172 static void img_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm) 172 173 { 173 174 u32 val; 174 - struct img_pwm_chip *pwm_chip = to_img_pwm_chip(chip); 175 + struct img_pwm_chip *imgchip = to_img_pwm_chip(chip); 175 176 176 - val = img_pwm_readl(pwm_chip, PWM_CTRL_CFG); 177 + val = img_pwm_readl(imgchip, PWM_CTRL_CFG); 177 178 val &= ~BIT(pwm->hwpwm); 178 - img_pwm_writel(pwm_chip, PWM_CTRL_CFG, val); 179 + img_pwm_writel(imgchip, PWM_CTRL_CFG, val); 179 180 180 181 pm_runtime_mark_last_busy(chip->dev); 181 182 pm_runtime_put_autosuspend(chip->dev); ··· 226 227 227 228 static int img_pwm_runtime_suspend(struct device *dev) 228 229 { 229 - struct img_pwm_chip *pwm_chip = dev_get_drvdata(dev); 230 + struct img_pwm_chip *imgchip = dev_get_drvdata(dev); 230 231 231 - clk_disable_unprepare(pwm_chip->pwm_clk); 232 - clk_disable_unprepare(pwm_chip->sys_clk); 232 + clk_disable_unprepare(imgchip->pwm_clk); 233 + clk_disable_unprepare(imgchip->sys_clk); 233 234 234 235 return 0; 235 236 } 236 237 237 238 static int img_pwm_runtime_resume(struct device *dev) 238 239 { 239 - struct img_pwm_chip *pwm_chip = dev_get_drvdata(dev); 240 + struct img_pwm_chip *imgchip = dev_get_drvdata(dev); 240 241 int ret; 241 242 242 - ret = clk_prepare_enable(pwm_chip->sys_clk); 243 + ret = clk_prepare_enable(imgchip->sys_clk); 243 244 if (ret < 0) { 244 245 dev_err(dev, "could not prepare or enable sys clock\n"); 245 246 return ret; 246 247 } 247 248 248 - ret = clk_prepare_enable(pwm_chip->pwm_clk); 249 + ret = clk_prepare_enable(imgchip->pwm_clk); 249 250 if (ret < 0) { 250 251 dev_err(dev, "could not prepare or enable pwm clock\n"); 251 - clk_disable_unprepare(pwm_chip->sys_clk); 252 + clk_disable_unprepare(imgchip->sys_clk); 252 253 return ret; 253 254 } 254 255 ··· 260 261 int ret; 261 262 u64 val; 262 263 unsigned long clk_rate; 263 - struct img_pwm_chip *pwm; 264 + struct img_pwm_chip *imgchip; 264 265 const struct of_device_id *of_dev_id; 265 266 266 - pwm = devm_kzalloc(&pdev->dev, sizeof(*pwm), GFP_KERNEL); 267 - if (!pwm) 267 + imgchip = devm_kzalloc(&pdev->dev, sizeof(*imgchip), GFP_KERNEL); 268 + if (!imgchip) 268 269 return -ENOMEM; 269 270 270 - pwm->dev = &pdev->dev; 271 + imgchip->dev = &pdev->dev; 271 272 272 - pwm->base = devm_platform_ioremap_resource(pdev, 0); 273 - if (IS_ERR(pwm->base)) 274 - return PTR_ERR(pwm->base); 273 + imgchip->base = devm_platform_ioremap_resource(pdev, 0); 274 + if (IS_ERR(imgchip->base)) 275 + return PTR_ERR(imgchip->base); 275 276 276 277 of_dev_id = of_match_device(img_pwm_of_match, &pdev->dev); 277 278 if (!of_dev_id) 278 279 return -ENODEV; 279 - pwm->data = of_dev_id->data; 280 + imgchip->data = of_dev_id->data; 280 281 281 - pwm->periph_regs = syscon_regmap_lookup_by_phandle(pdev->dev.of_node, 282 - "img,cr-periph"); 283 - if (IS_ERR(pwm->periph_regs)) 284 - return PTR_ERR(pwm->periph_regs); 282 + imgchip->periph_regs = syscon_regmap_lookup_by_phandle(pdev->dev.of_node, 283 + "img,cr-periph"); 284 + if (IS_ERR(imgchip->periph_regs)) 285 + return PTR_ERR(imgchip->periph_regs); 285 286 286 - pwm->sys_clk = devm_clk_get(&pdev->dev, "sys"); 287 - if (IS_ERR(pwm->sys_clk)) { 287 + imgchip->sys_clk = devm_clk_get(&pdev->dev, "sys"); 288 + if (IS_ERR(imgchip->sys_clk)) { 288 289 dev_err(&pdev->dev, "failed to get system clock\n"); 289 - return PTR_ERR(pwm->sys_clk); 290 + return PTR_ERR(imgchip->sys_clk); 290 291 } 291 292 292 - pwm->pwm_clk = devm_clk_get(&pdev->dev, "pwm"); 293 - if (IS_ERR(pwm->pwm_clk)) { 294 - dev_err(&pdev->dev, "failed to get pwm clock\n"); 295 - return PTR_ERR(pwm->pwm_clk); 293 + imgchip->pwm_clk = devm_clk_get(&pdev->dev, "imgchip"); 294 + if (IS_ERR(imgchip->pwm_clk)) { 295 + dev_err(&pdev->dev, "failed to get imgchip clock\n"); 296 + return PTR_ERR(imgchip->pwm_clk); 296 297 } 297 298 298 - platform_set_drvdata(pdev, pwm); 299 + platform_set_drvdata(pdev, imgchip); 299 300 300 301 pm_runtime_set_autosuspend_delay(&pdev->dev, IMG_PWM_PM_TIMEOUT); 301 302 pm_runtime_use_autosuspend(&pdev->dev); ··· 306 307 goto err_pm_disable; 307 308 } 308 309 309 - clk_rate = clk_get_rate(pwm->pwm_clk); 310 + clk_rate = clk_get_rate(imgchip->pwm_clk); 310 311 if (!clk_rate) { 311 - dev_err(&pdev->dev, "pwm clock has no frequency\n"); 312 + dev_err(&pdev->dev, "imgchip clock has no frequency\n"); 312 313 ret = -EINVAL; 313 314 goto err_suspend; 314 315 } 315 316 316 317 /* The maximum input clock divider is 512 */ 317 - val = (u64)NSEC_PER_SEC * 512 * pwm->data->max_timebase; 318 + val = (u64)NSEC_PER_SEC * 512 * imgchip->data->max_timebase; 318 319 do_div(val, clk_rate); 319 - pwm->max_period_ns = val; 320 + imgchip->max_period_ns = val; 320 321 321 322 val = (u64)NSEC_PER_SEC * MIN_TMBASE_STEPS; 322 323 do_div(val, clk_rate); 323 - pwm->min_period_ns = val; 324 + imgchip->min_period_ns = val; 324 325 325 - pwm->chip.dev = &pdev->dev; 326 - pwm->chip.ops = &img_pwm_ops; 327 - pwm->chip.npwm = IMG_PWM_NPWM; 326 + imgchip->chip.dev = &pdev->dev; 327 + imgchip->chip.ops = &img_pwm_ops; 328 + imgchip->chip.npwm = IMG_PWM_NPWM; 328 329 329 - ret = pwmchip_add(&pwm->chip); 330 + ret = pwmchip_add(&imgchip->chip); 330 331 if (ret < 0) { 331 332 dev_err(&pdev->dev, "pwmchip_add failed: %d\n", ret); 332 333 goto err_suspend; ··· 345 346 346 347 static int img_pwm_remove(struct platform_device *pdev) 347 348 { 348 - struct img_pwm_chip *pwm_chip = platform_get_drvdata(pdev); 349 + struct img_pwm_chip *imgchip = platform_get_drvdata(pdev); 349 350 350 351 pm_runtime_disable(&pdev->dev); 351 352 if (!pm_runtime_status_suspended(&pdev->dev)) 352 353 img_pwm_runtime_suspend(&pdev->dev); 353 354 354 - pwmchip_remove(&pwm_chip->chip); 355 + pwmchip_remove(&imgchip->chip); 355 356 356 357 return 0; 357 358 } ··· 359 360 #ifdef CONFIG_PM_SLEEP 360 361 static int img_pwm_suspend(struct device *dev) 361 362 { 362 - struct img_pwm_chip *pwm_chip = dev_get_drvdata(dev); 363 + struct img_pwm_chip *imgchip = dev_get_drvdata(dev); 363 364 int i, ret; 364 365 365 366 if (pm_runtime_status_suspended(dev)) { ··· 368 369 return ret; 369 370 } 370 371 371 - for (i = 0; i < pwm_chip->chip.npwm; i++) 372 - pwm_chip->suspend_ch_cfg[i] = img_pwm_readl(pwm_chip, 373 - PWM_CH_CFG(i)); 372 + for (i = 0; i < imgchip->chip.npwm; i++) 373 + imgchip->suspend_ch_cfg[i] = img_pwm_readl(imgchip, 374 + PWM_CH_CFG(i)); 374 375 375 - pwm_chip->suspend_ctrl_cfg = img_pwm_readl(pwm_chip, PWM_CTRL_CFG); 376 + imgchip->suspend_ctrl_cfg = img_pwm_readl(imgchip, PWM_CTRL_CFG); 376 377 377 378 img_pwm_runtime_suspend(dev); 378 379 ··· 381 382 382 383 static int img_pwm_resume(struct device *dev) 383 384 { 384 - struct img_pwm_chip *pwm_chip = dev_get_drvdata(dev); 385 + struct img_pwm_chip *imgchip = dev_get_drvdata(dev); 385 386 int ret; 386 387 int i; 387 388 ··· 389 390 if (ret) 390 391 return ret; 391 392 392 - for (i = 0; i < pwm_chip->chip.npwm; i++) 393 - img_pwm_writel(pwm_chip, PWM_CH_CFG(i), 394 - pwm_chip->suspend_ch_cfg[i]); 393 + for (i = 0; i < imgchip->chip.npwm; i++) 394 + img_pwm_writel(imgchip, PWM_CH_CFG(i), 395 + imgchip->suspend_ch_cfg[i]); 395 396 396 - img_pwm_writel(pwm_chip, PWM_CTRL_CFG, pwm_chip->suspend_ctrl_cfg); 397 + img_pwm_writel(imgchip, PWM_CTRL_CFG, imgchip->suspend_ctrl_cfg); 397 398 398 - for (i = 0; i < pwm_chip->chip.npwm; i++) 399 - if (pwm_chip->suspend_ctrl_cfg & BIT(i)) 400 - regmap_update_bits(pwm_chip->periph_regs, 399 + for (i = 0; i < imgchip->chip.npwm; i++) 400 + if (imgchip->suspend_ctrl_cfg & BIT(i)) 401 + regmap_update_bits(imgchip->periph_regs, 401 402 PERIP_PWM_PDM_CONTROL, 402 403 PERIP_PWM_PDM_CONTROL_CH_MASK << 403 404 PERIP_PWM_PDM_CONTROL_CH_SHIFT(i),
+28 -5
drivers/pwm/pwm-imx1.c
··· 61 61 } 62 62 63 63 static int pwm_imx1_config(struct pwm_chip *chip, 64 - struct pwm_device *pwm, int duty_ns, int period_ns) 64 + struct pwm_device *pwm, u64 duty_ns, u64 period_ns) 65 65 { 66 66 struct pwm_imx1_chip *imx = to_pwm_imx1_chip(chip); 67 67 u32 max, p; ··· 84 84 * (/2 .. /16). 85 85 */ 86 86 max = readl(imx->mmio_base + MX1_PWMP); 87 - p = max * duty_ns / period_ns; 87 + p = mul_u64_u64_div_u64(max, duty_ns, period_ns); 88 88 89 89 writel(max - p, imx->mmio_base + MX1_PWMS); 90 90 ··· 120 120 pwm_imx1_clk_disable_unprepare(chip); 121 121 } 122 122 123 + static int pwm_imx1_apply(struct pwm_chip *chip, struct pwm_device *pwm, 124 + const struct pwm_state *state) 125 + { 126 + int err; 127 + 128 + if (state->polarity != PWM_POLARITY_NORMAL) 129 + return -EINVAL; 130 + 131 + if (!state->enabled) { 132 + if (pwm->state.enabled) 133 + pwm_imx1_disable(chip, pwm); 134 + 135 + return 0; 136 + } 137 + 138 + err = pwm_imx1_config(chip, pwm, state->duty_cycle, state->period); 139 + if (err) 140 + return err; 141 + 142 + if (!pwm->state.enabled) 143 + return pwm_imx1_enable(chip, pwm); 144 + 145 + return 0; 146 + } 147 + 123 148 static const struct pwm_ops pwm_imx1_ops = { 124 - .enable = pwm_imx1_enable, 125 - .disable = pwm_imx1_disable, 126 - .config = pwm_imx1_config, 149 + .apply = pwm_imx1_apply, 127 150 .owner = THIS_MODULE, 128 151 }; 129 152
+5
drivers/pwm/pwm-jz4740.c
··· 256 256 .num_pwms = 6, 257 257 }; 258 258 259 + static const struct soc_info __maybe_unused x1000_soc_info = { 260 + .num_pwms = 5, 261 + }; 262 + 259 263 #ifdef CONFIG_OF 260 264 static const struct of_device_id jz4740_pwm_dt_ids[] = { 261 265 { .compatible = "ingenic,jz4740-pwm", .data = &jz4740_soc_info }, 262 266 { .compatible = "ingenic,jz4725b-pwm", .data = &jz4725b_soc_info }, 267 + { .compatible = "ingenic,x1000-pwm", .data = &x1000_soc_info }, 263 268 {}, 264 269 }; 265 270 MODULE_DEVICE_TABLE(of, jz4740_pwm_dt_ids);
+18 -33
drivers/pwm/pwm-lpc18xx-sct.c
··· 76 76 #define LPC18XX_PWM_EVENT_PERIOD 0 77 77 #define LPC18XX_PWM_EVENT_MAX 16 78 78 79 + #define LPC18XX_NUM_PWMS 16 80 + 79 81 /* SCT conflict resolution */ 80 82 enum lpc18xx_pwm_res_action { 81 83 LPC18XX_PWM_RES_NONE, ··· 103 101 unsigned long event_map; 104 102 struct mutex res_lock; 105 103 struct mutex period_lock; 104 + struct lpc18xx_pwm_data channeldata[LPC18XX_NUM_PWMS]; 106 105 }; 107 106 108 107 static inline struct lpc18xx_pwm_chip * ··· 166 163 struct pwm_device *pwm, int duty_ns) 167 164 { 168 165 struct lpc18xx_pwm_chip *lpc18xx_pwm = to_lpc18xx_pwm_chip(chip); 169 - struct lpc18xx_pwm_data *lpc18xx_data = pwm_get_chip_data(pwm); 166 + struct lpc18xx_pwm_data *lpc18xx_data = &lpc18xx_pwm->channeldata[pwm->hwpwm]; 170 167 u64 val; 171 168 172 169 val = (u64)duty_ns * lpc18xx_pwm->clk_rate; ··· 236 233 static int lpc18xx_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm) 237 234 { 238 235 struct lpc18xx_pwm_chip *lpc18xx_pwm = to_lpc18xx_pwm_chip(chip); 239 - struct lpc18xx_pwm_data *lpc18xx_data = pwm_get_chip_data(pwm); 236 + struct lpc18xx_pwm_data *lpc18xx_data = &lpc18xx_pwm->channeldata[pwm->hwpwm]; 240 237 enum lpc18xx_pwm_res_action res_action; 241 238 unsigned int set_event, clear_event; 242 239 ··· 271 268 static void lpc18xx_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm) 272 269 { 273 270 struct lpc18xx_pwm_chip *lpc18xx_pwm = to_lpc18xx_pwm_chip(chip); 274 - struct lpc18xx_pwm_data *lpc18xx_data = pwm_get_chip_data(pwm); 271 + struct lpc18xx_pwm_data *lpc18xx_data = &lpc18xx_pwm->channeldata[pwm->hwpwm]; 275 272 276 273 lpc18xx_pwm_writel(lpc18xx_pwm, 277 274 LPC18XX_PWM_EVCTRL(lpc18xx_data->duty_event), 0); ··· 282 279 static int lpc18xx_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm) 283 280 { 284 281 struct lpc18xx_pwm_chip *lpc18xx_pwm = to_lpc18xx_pwm_chip(chip); 285 - struct lpc18xx_pwm_data *lpc18xx_data = pwm_get_chip_data(pwm); 282 + struct lpc18xx_pwm_data *lpc18xx_data = &lpc18xx_pwm->channeldata[pwm->hwpwm]; 286 283 unsigned long event; 287 284 288 285 event = find_first_zero_bit(&lpc18xx_pwm->event_map, ··· 303 300 static void lpc18xx_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm) 304 301 { 305 302 struct lpc18xx_pwm_chip *lpc18xx_pwm = to_lpc18xx_pwm_chip(chip); 306 - struct lpc18xx_pwm_data *lpc18xx_data = pwm_get_chip_data(pwm); 303 + struct lpc18xx_pwm_data *lpc18xx_data = &lpc18xx_pwm->channeldata[pwm->hwpwm]; 307 304 308 305 clear_bit(lpc18xx_data->duty_event, &lpc18xx_pwm->event_map); 309 306 } ··· 327 324 static int lpc18xx_pwm_probe(struct platform_device *pdev) 328 325 { 329 326 struct lpc18xx_pwm_chip *lpc18xx_pwm; 330 - struct pwm_device *pwm; 331 - int ret, i; 327 + int ret; 332 328 u64 val; 333 329 334 330 lpc18xx_pwm = devm_kzalloc(&pdev->dev, sizeof(*lpc18xx_pwm), ··· 372 370 373 371 lpc18xx_pwm->chip.dev = &pdev->dev; 374 372 lpc18xx_pwm->chip.ops = &lpc18xx_pwm_ops; 375 - lpc18xx_pwm->chip.npwm = 16; 373 + lpc18xx_pwm->chip.npwm = LPC18XX_NUM_PWMS; 376 374 377 375 /* SCT counter must be in unify (32 bit) mode */ 378 376 lpc18xx_pwm_writel(lpc18xx_pwm, LPC18XX_PWM_CONFIG, ··· 397 395 lpc18xx_pwm_writel(lpc18xx_pwm, LPC18XX_PWM_LIMIT, 398 396 BIT(lpc18xx_pwm->period_event)); 399 397 400 - ret = pwmchip_add(&lpc18xx_pwm->chip); 401 - if (ret < 0) { 402 - dev_err(&pdev->dev, "pwmchip_add failed: %d\n", ret); 403 - goto disable_pwmclk; 404 - } 405 - 406 - for (i = 0; i < lpc18xx_pwm->chip.npwm; i++) { 407 - struct lpc18xx_pwm_data *data; 408 - 409 - pwm = &lpc18xx_pwm->chip.pwms[i]; 410 - 411 - data = devm_kzalloc(lpc18xx_pwm->dev, sizeof(*data), 412 - GFP_KERNEL); 413 - if (!data) { 414 - ret = -ENOMEM; 415 - goto remove_pwmchip; 416 - } 417 - 418 - pwm_set_chip_data(pwm, data); 419 - } 420 - 421 - platform_set_drvdata(pdev, lpc18xx_pwm); 422 - 423 398 val = lpc18xx_pwm_readl(lpc18xx_pwm, LPC18XX_PWM_CTRL); 424 399 val &= ~LPC18XX_PWM_BIDIR; 425 400 val &= ~LPC18XX_PWM_CTRL_HALT; ··· 404 425 val |= LPC18XX_PWM_PRE(0); 405 426 lpc18xx_pwm_writel(lpc18xx_pwm, LPC18XX_PWM_CTRL, val); 406 427 428 + ret = pwmchip_add(&lpc18xx_pwm->chip); 429 + if (ret < 0) { 430 + dev_err(&pdev->dev, "pwmchip_add failed: %d\n", ret); 431 + goto disable_pwmclk; 432 + } 433 + 434 + platform_set_drvdata(pdev, lpc18xx_pwm); 435 + 407 436 return 0; 408 437 409 - remove_pwmchip: 410 - pwmchip_remove(&lpc18xx_pwm->chip); 411 438 disable_pwmclk: 412 439 clk_disable_unprepare(lpc18xx_pwm->pwm_clk); 413 440 return ret;
+13 -21
drivers/pwm/pwm-mediatek.c
··· 146 146 147 147 if (clkdiv > PWM_CLK_DIV_MAX) { 148 148 pwm_mediatek_clk_disable(chip, pwm); 149 - dev_err(chip->dev, "period %d not supported\n", period_ns); 149 + dev_err(chip->dev, "period of %d ns not supported\n", period_ns); 150 150 return -EINVAL; 151 151 } 152 152 ··· 221 221 if (IS_ERR(pc->regs)) 222 222 return PTR_ERR(pc->regs); 223 223 224 - pc->clk_pwms = devm_kcalloc(&pdev->dev, pc->soc->num_pwms, 224 + pc->clk_pwms = devm_kmalloc_array(&pdev->dev, pc->soc->num_pwms, 225 225 sizeof(*pc->clk_pwms), GFP_KERNEL); 226 226 if (!pc->clk_pwms) 227 227 return -ENOMEM; 228 228 229 229 pc->clk_top = devm_clk_get(&pdev->dev, "top"); 230 - if (IS_ERR(pc->clk_top)) { 231 - dev_err(&pdev->dev, "clock: top fail: %ld\n", 232 - PTR_ERR(pc->clk_top)); 233 - return PTR_ERR(pc->clk_top); 234 - } 230 + if (IS_ERR(pc->clk_top)) 231 + return dev_err_probe(&pdev->dev, PTR_ERR(pc->clk_top), 232 + "Failed to get top clock\n"); 235 233 236 234 pc->clk_main = devm_clk_get(&pdev->dev, "main"); 237 - if (IS_ERR(pc->clk_main)) { 238 - dev_err(&pdev->dev, "clock: main fail: %ld\n", 239 - PTR_ERR(pc->clk_main)); 240 - return PTR_ERR(pc->clk_main); 241 - } 235 + if (IS_ERR(pc->clk_main)) 236 + return dev_err_probe(&pdev->dev, PTR_ERR(pc->clk_main), 237 + "Failed to get main clock\n"); 242 238 243 239 for (i = 0; i < pc->soc->num_pwms; i++) { 244 240 char name[8]; ··· 242 246 snprintf(name, sizeof(name), "pwm%d", i + 1); 243 247 244 248 pc->clk_pwms[i] = devm_clk_get(&pdev->dev, name); 245 - if (IS_ERR(pc->clk_pwms[i])) { 246 - dev_err(&pdev->dev, "clock: %s fail: %ld\n", 247 - name, PTR_ERR(pc->clk_pwms[i])); 248 - return PTR_ERR(pc->clk_pwms[i]); 249 - } 249 + if (IS_ERR(pc->clk_pwms[i])) 250 + return dev_err_probe(&pdev->dev, PTR_ERR(pc->clk_pwms[i]), 251 + "Failed to get %s clock\n", name); 250 252 } 251 253 252 254 pc->chip.dev = &pdev->dev; ··· 252 258 pc->chip.npwm = pc->soc->num_pwms; 253 259 254 260 ret = devm_pwmchip_add(&pdev->dev, &pc->chip); 255 - if (ret < 0) { 256 - dev_err(&pdev->dev, "pwmchip_add() failed: %d\n", ret); 257 - return ret; 258 - } 261 + if (ret < 0) 262 + return dev_err_probe(&pdev->dev, ret, "pwmchip_add() failed\n"); 259 263 260 264 return 0; 261 265 }
+8 -17
drivers/pwm/pwm-meson.c
··· 120 120 static int meson_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm) 121 121 { 122 122 struct meson_pwm *meson = to_meson_pwm(chip); 123 - struct meson_pwm_channel *channel; 123 + struct meson_pwm_channel *channel = &meson->channels[pwm->hwpwm]; 124 124 struct device *dev = chip->dev; 125 125 int err; 126 - 127 - channel = pwm_get_chip_data(pwm); 128 - if (channel) 129 - return 0; 130 - 131 - channel = &meson->channels[pwm->hwpwm]; 132 126 133 127 if (channel->clk_parent) { 134 128 err = clk_set_parent(channel->clk, channel->clk_parent); ··· 141 147 return err; 142 148 } 143 149 144 - return pwm_set_chip_data(pwm, channel); 150 + return 0; 145 151 } 146 152 147 153 static void meson_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm) 148 154 { 149 - struct meson_pwm_channel *channel = pwm_get_chip_data(pwm); 155 + struct meson_pwm *meson = to_meson_pwm(chip); 156 + struct meson_pwm_channel *channel = &meson->channels[pwm->hwpwm]; 150 157 151 - if (channel) 152 - clk_disable_unprepare(channel->clk); 158 + clk_disable_unprepare(channel->clk); 153 159 } 154 160 155 161 static int meson_pwm_calc(struct meson_pwm *meson, struct pwm_device *pwm, 156 162 const struct pwm_state *state) 157 163 { 158 - struct meson_pwm_channel *channel = pwm_get_chip_data(pwm); 164 + struct meson_pwm_channel *channel = &meson->channels[pwm->hwpwm]; 159 165 unsigned int duty, period, pre_div, cnt, duty_cnt; 160 166 unsigned long fin_freq; 161 167 ··· 218 224 219 225 static void meson_pwm_enable(struct meson_pwm *meson, struct pwm_device *pwm) 220 226 { 221 - struct meson_pwm_channel *channel = pwm_get_chip_data(pwm); 227 + struct meson_pwm_channel *channel = &meson->channels[pwm->hwpwm]; 222 228 struct meson_pwm_channel_data *channel_data; 223 229 unsigned long flags; 224 230 u32 value; ··· 261 267 static int meson_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, 262 268 const struct pwm_state *state) 263 269 { 264 - struct meson_pwm_channel *channel = pwm_get_chip_data(pwm); 265 270 struct meson_pwm *meson = to_meson_pwm(chip); 271 + struct meson_pwm_channel *channel = &meson->channels[pwm->hwpwm]; 266 272 int err = 0; 267 - 268 - if (!state) 269 - return -EINVAL; 270 273 271 274 if (!state->enabled) { 272 275 if (state->polarity == PWM_POLARITY_INVERSED) {
+2 -2
drivers/pwm/pwm-pca9685.c
··· 560 560 pca9685_write_reg(pca, PCA9685_MODE1, reg); 561 561 562 562 /* Reset OFF/ON registers to POR default */ 563 - pca9685_write_reg(pca, PCA9685_ALL_LED_OFF_L, LED_FULL); 563 + pca9685_write_reg(pca, PCA9685_ALL_LED_OFF_L, 0); 564 564 pca9685_write_reg(pca, PCA9685_ALL_LED_OFF_H, LED_FULL); 565 565 pca9685_write_reg(pca, PCA9685_ALL_LED_ON_L, 0); 566 - pca9685_write_reg(pca, PCA9685_ALL_LED_ON_H, 0); 566 + pca9685_write_reg(pca, PCA9685_ALL_LED_ON_H, LED_FULL); 567 567 568 568 pca->chip.ops = &pca9685_pwm_ops; 569 569 /* Add an extra channel for ALL_LED */
+28 -5
drivers/pwm/pwm-pxa.c
··· 58 58 * duty_ns = 10^9 * (PRESCALE + 1) * DC / PWM_CLK_RATE 59 59 */ 60 60 static int pxa_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, 61 - int duty_ns, int period_ns) 61 + u64 duty_ns, u64 period_ns) 62 62 { 63 63 struct pxa_pwm_chip *pc = to_pxa_pwm_chip(chip); 64 64 unsigned long long c; ··· 84 84 if (duty_ns == period_ns) 85 85 dc = PWMDCR_FD; 86 86 else 87 - dc = (pv + 1) * duty_ns / period_ns; 87 + dc = mul_u64_u64_div_u64(pv + 1, duty_ns, period_ns); 88 88 89 89 /* NOTE: the clock to PWM has to be enabled first 90 90 * before writing to the registers ··· 115 115 clk_disable_unprepare(pc->clk); 116 116 } 117 117 118 + static int pxa_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, 119 + const struct pwm_state *state) 120 + { 121 + int err; 122 + 123 + if (state->polarity != PWM_POLARITY_NORMAL) 124 + return -EINVAL; 125 + 126 + if (!state->enabled) { 127 + if (pwm->state.enabled) 128 + pxa_pwm_disable(chip, pwm); 129 + 130 + return 0; 131 + } 132 + 133 + err = pxa_pwm_config(chip, pwm, state->duty_cycle, state->period); 134 + if (err) 135 + return err; 136 + 137 + if (!pwm->state.enabled) 138 + return pxa_pwm_enable(chip, pwm); 139 + 140 + return 0; 141 + } 142 + 118 143 static const struct pwm_ops pxa_pwm_ops = { 119 - .config = pxa_pwm_config, 120 - .enable = pxa_pwm_enable, 121 - .disable = pxa_pwm_disable, 144 + .apply = pxa_pwm_apply, 122 145 .owner = THIS_MODULE, 123 146 }; 124 147
-1
drivers/pwm/pwm-raspberrypi-poe.c
··· 163 163 rpipwm->firmware = firmware; 164 164 rpipwm->chip.dev = dev; 165 165 rpipwm->chip.ops = &raspberrypi_pwm_ops; 166 - rpipwm->chip.base = -1; 167 166 rpipwm->chip.npwm = RASPBERRYPI_FIRMWARE_PWM_NUM; 168 167 169 168 ret = raspberrypi_pwm_get_property(rpipwm->firmware, RPI_PWM_CUR_DUTY_REG,
+1 -1
drivers/pwm/pwm-rcar.c
··· 110 110 unsigned long clk_rate = clk_get_rate(rp->clk); 111 111 u32 cyc, ph; 112 112 113 - one_cycle = (unsigned long long)NSEC_PER_SEC * 100ULL * (1 << div); 113 + one_cycle = NSEC_PER_SEC * 100ULL << div; 114 114 do_div(one_cycle, clk_rate); 115 115 116 116 tmp = period_ns * 100ULL;
+8 -10
drivers/pwm/pwm-stmpe.c
··· 269 269 static int __init stmpe_pwm_probe(struct platform_device *pdev) 270 270 { 271 271 struct stmpe *stmpe = dev_get_drvdata(pdev->dev.parent); 272 - struct stmpe_pwm *pwm; 272 + struct stmpe_pwm *stmpe_pwm; 273 273 int ret; 274 274 275 - pwm = devm_kzalloc(&pdev->dev, sizeof(*pwm), GFP_KERNEL); 276 - if (!pwm) 275 + stmpe_pwm = devm_kzalloc(&pdev->dev, sizeof(*stmpe_pwm), GFP_KERNEL); 276 + if (!stmpe_pwm) 277 277 return -ENOMEM; 278 278 279 - pwm->stmpe = stmpe; 280 - pwm->chip.dev = &pdev->dev; 279 + stmpe_pwm->stmpe = stmpe; 280 + stmpe_pwm->chip.dev = &pdev->dev; 281 281 282 282 if (stmpe->partnum == STMPE2401 || stmpe->partnum == STMPE2403) { 283 - pwm->chip.ops = &stmpe_24xx_pwm_ops; 284 - pwm->chip.npwm = 3; 283 + stmpe_pwm->chip.ops = &stmpe_24xx_pwm_ops; 284 + stmpe_pwm->chip.npwm = 3; 285 285 } else { 286 286 if (stmpe->partnum == STMPE1601) 287 287 dev_err(&pdev->dev, "STMPE1601 not yet supported\n"); ··· 295 295 if (ret) 296 296 return ret; 297 297 298 - ret = pwmchip_add(&pwm->chip); 298 + ret = pwmchip_add(&stmpe_pwm->chip); 299 299 if (ret) { 300 300 stmpe_disable(stmpe, STMPE_BLOCK_PWM); 301 301 return ret; 302 302 } 303 - 304 - platform_set_drvdata(pdev, pwm); 305 303 306 304 return 0; 307 305 }
+35 -35
drivers/pwm/pwm-sun4i.c
··· 390 390 391 391 static int sun4i_pwm_probe(struct platform_device *pdev) 392 392 { 393 - struct sun4i_pwm_chip *pwm; 393 + struct sun4i_pwm_chip *sun4ichip; 394 394 int ret; 395 395 396 - pwm = devm_kzalloc(&pdev->dev, sizeof(*pwm), GFP_KERNEL); 397 - if (!pwm) 396 + sun4ichip = devm_kzalloc(&pdev->dev, sizeof(*sun4ichip), GFP_KERNEL); 397 + if (!sun4ichip) 398 398 return -ENOMEM; 399 399 400 - pwm->data = of_device_get_match_data(&pdev->dev); 401 - if (!pwm->data) 400 + sun4ichip->data = of_device_get_match_data(&pdev->dev); 401 + if (!sun4ichip->data) 402 402 return -ENODEV; 403 403 404 - pwm->base = devm_platform_ioremap_resource(pdev, 0); 405 - if (IS_ERR(pwm->base)) 406 - return PTR_ERR(pwm->base); 404 + sun4ichip->base = devm_platform_ioremap_resource(pdev, 0); 405 + if (IS_ERR(sun4ichip->base)) 406 + return PTR_ERR(sun4ichip->base); 407 407 408 408 /* 409 409 * All hardware variants need a source clock that is divided and ··· 416 416 * unnamed one of the PWM device) and if this is not found we fall 417 417 * back to the first clock of the PWM. 418 418 */ 419 - pwm->clk = devm_clk_get_optional(&pdev->dev, "mod"); 420 - if (IS_ERR(pwm->clk)) 421 - return dev_err_probe(&pdev->dev, PTR_ERR(pwm->clk), 419 + sun4ichip->clk = devm_clk_get_optional(&pdev->dev, "mod"); 420 + if (IS_ERR(sun4ichip->clk)) 421 + return dev_err_probe(&pdev->dev, PTR_ERR(sun4ichip->clk), 422 422 "get mod clock failed\n"); 423 423 424 - if (!pwm->clk) { 425 - pwm->clk = devm_clk_get(&pdev->dev, NULL); 426 - if (IS_ERR(pwm->clk)) 427 - return dev_err_probe(&pdev->dev, PTR_ERR(pwm->clk), 424 + if (!sun4ichip->clk) { 425 + sun4ichip->clk = devm_clk_get(&pdev->dev, NULL); 426 + if (IS_ERR(sun4ichip->clk)) 427 + return dev_err_probe(&pdev->dev, PTR_ERR(sun4ichip->clk), 428 428 "get unnamed clock failed\n"); 429 429 } 430 430 431 - pwm->bus_clk = devm_clk_get_optional(&pdev->dev, "bus"); 432 - if (IS_ERR(pwm->bus_clk)) 433 - return dev_err_probe(&pdev->dev, PTR_ERR(pwm->bus_clk), 431 + sun4ichip->bus_clk = devm_clk_get_optional(&pdev->dev, "bus"); 432 + if (IS_ERR(sun4ichip->bus_clk)) 433 + return dev_err_probe(&pdev->dev, PTR_ERR(sun4ichip->bus_clk), 434 434 "get bus clock failed\n"); 435 435 436 - pwm->rst = devm_reset_control_get_optional_shared(&pdev->dev, NULL); 437 - if (IS_ERR(pwm->rst)) 438 - return dev_err_probe(&pdev->dev, PTR_ERR(pwm->rst), 436 + sun4ichip->rst = devm_reset_control_get_optional_shared(&pdev->dev, NULL); 437 + if (IS_ERR(sun4ichip->rst)) 438 + return dev_err_probe(&pdev->dev, PTR_ERR(sun4ichip->rst), 439 439 "get reset failed\n"); 440 440 441 441 /* Deassert reset */ 442 - ret = reset_control_deassert(pwm->rst); 442 + ret = reset_control_deassert(sun4ichip->rst); 443 443 if (ret) { 444 444 dev_err(&pdev->dev, "cannot deassert reset control: %pe\n", 445 445 ERR_PTR(ret)); ··· 450 450 * We're keeping the bus clock on for the sake of simplicity. 451 451 * Actually it only needs to be on for hardware register accesses. 452 452 */ 453 - ret = clk_prepare_enable(pwm->bus_clk); 453 + ret = clk_prepare_enable(sun4ichip->bus_clk); 454 454 if (ret) { 455 455 dev_err(&pdev->dev, "cannot prepare and enable bus_clk %pe\n", 456 456 ERR_PTR(ret)); 457 457 goto err_bus; 458 458 } 459 459 460 - pwm->chip.dev = &pdev->dev; 461 - pwm->chip.ops = &sun4i_pwm_ops; 462 - pwm->chip.npwm = pwm->data->npwm; 460 + sun4ichip->chip.dev = &pdev->dev; 461 + sun4ichip->chip.ops = &sun4i_pwm_ops; 462 + sun4ichip->chip.npwm = sun4ichip->data->npwm; 463 463 464 - spin_lock_init(&pwm->ctrl_lock); 464 + spin_lock_init(&sun4ichip->ctrl_lock); 465 465 466 - ret = pwmchip_add(&pwm->chip); 466 + ret = pwmchip_add(&sun4ichip->chip); 467 467 if (ret < 0) { 468 468 dev_err(&pdev->dev, "failed to add PWM chip: %d\n", ret); 469 469 goto err_pwm_add; 470 470 } 471 471 472 - platform_set_drvdata(pdev, pwm); 472 + platform_set_drvdata(pdev, sun4ichip); 473 473 474 474 return 0; 475 475 476 476 err_pwm_add: 477 - clk_disable_unprepare(pwm->bus_clk); 477 + clk_disable_unprepare(sun4ichip->bus_clk); 478 478 err_bus: 479 - reset_control_assert(pwm->rst); 479 + reset_control_assert(sun4ichip->rst); 480 480 481 481 return ret; 482 482 } 483 483 484 484 static int sun4i_pwm_remove(struct platform_device *pdev) 485 485 { 486 - struct sun4i_pwm_chip *pwm = platform_get_drvdata(pdev); 486 + struct sun4i_pwm_chip *sun4ichip = platform_get_drvdata(pdev); 487 487 488 - pwmchip_remove(&pwm->chip); 488 + pwmchip_remove(&sun4ichip->chip); 489 489 490 - clk_disable_unprepare(pwm->bus_clk); 491 - reset_control_assert(pwm->rst); 490 + clk_disable_unprepare(sun4ichip->bus_clk); 491 + reset_control_assert(sun4ichip->rst); 492 492 493 493 return 0; 494 494 }
+29 -30
drivers/pwm/pwm-tegra.c
··· 85 85 return container_of(chip, struct tegra_pwm_chip, chip); 86 86 } 87 87 88 - static inline u32 pwm_readl(struct tegra_pwm_chip *chip, unsigned int num) 88 + static inline u32 pwm_readl(struct tegra_pwm_chip *pc, unsigned int offset) 89 89 { 90 - return readl(chip->regs + (num << 4)); 90 + return readl(pc->regs + (offset << 4)); 91 91 } 92 92 93 - static inline void pwm_writel(struct tegra_pwm_chip *chip, unsigned int num, 94 - unsigned long val) 93 + static inline void pwm_writel(struct tegra_pwm_chip *pc, unsigned int offset, u32 value) 95 94 { 96 - writel(val, chip->regs + (num << 4)); 95 + writel(value, pc->regs + (offset << 4)); 97 96 } 98 97 99 98 static int tegra_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, ··· 239 240 240 241 static int tegra_pwm_probe(struct platform_device *pdev) 241 242 { 242 - struct tegra_pwm_chip *pwm; 243 + struct tegra_pwm_chip *pc; 243 244 int ret; 244 245 245 - pwm = devm_kzalloc(&pdev->dev, sizeof(*pwm), GFP_KERNEL); 246 - if (!pwm) 246 + pc = devm_kzalloc(&pdev->dev, sizeof(*pc), GFP_KERNEL); 247 + if (!pc) 247 248 return -ENOMEM; 248 249 249 - pwm->soc = of_device_get_match_data(&pdev->dev); 250 - pwm->dev = &pdev->dev; 250 + pc->soc = of_device_get_match_data(&pdev->dev); 251 + pc->dev = &pdev->dev; 251 252 252 - pwm->regs = devm_platform_ioremap_resource(pdev, 0); 253 - if (IS_ERR(pwm->regs)) 254 - return PTR_ERR(pwm->regs); 253 + pc->regs = devm_platform_ioremap_resource(pdev, 0); 254 + if (IS_ERR(pc->regs)) 255 + return PTR_ERR(pc->regs); 255 256 256 - platform_set_drvdata(pdev, pwm); 257 + platform_set_drvdata(pdev, pc); 257 258 258 - pwm->clk = devm_clk_get(&pdev->dev, NULL); 259 - if (IS_ERR(pwm->clk)) 260 - return PTR_ERR(pwm->clk); 259 + pc->clk = devm_clk_get(&pdev->dev, NULL); 260 + if (IS_ERR(pc->clk)) 261 + return PTR_ERR(pc->clk); 261 262 262 263 ret = devm_tegra_core_dev_init_opp_table_common(&pdev->dev); 263 264 if (ret) ··· 269 270 return ret; 270 271 271 272 /* Set maximum frequency of the IP */ 272 - ret = dev_pm_opp_set_rate(pwm->dev, pwm->soc->max_frequency); 273 + ret = dev_pm_opp_set_rate(pc->dev, pc->soc->max_frequency); 273 274 if (ret < 0) { 274 275 dev_err(&pdev->dev, "Failed to set max frequency: %d\n", ret); 275 276 goto put_pm; ··· 280 281 * clock register resolutions. Get the configured frequency 281 282 * so that PWM period can be calculated more accurately. 282 283 */ 283 - pwm->clk_rate = clk_get_rate(pwm->clk); 284 + pc->clk_rate = clk_get_rate(pc->clk); 284 285 285 286 /* Set minimum limit of PWM period for the IP */ 286 - pwm->min_period_ns = 287 - (NSEC_PER_SEC / (pwm->soc->max_frequency >> PWM_DUTY_WIDTH)) + 1; 287 + pc->min_period_ns = 288 + (NSEC_PER_SEC / (pc->soc->max_frequency >> PWM_DUTY_WIDTH)) + 1; 288 289 289 - pwm->rst = devm_reset_control_get_exclusive(&pdev->dev, "pwm"); 290 - if (IS_ERR(pwm->rst)) { 291 - ret = PTR_ERR(pwm->rst); 290 + pc->rst = devm_reset_control_get_exclusive(&pdev->dev, "pwm"); 291 + if (IS_ERR(pc->rst)) { 292 + ret = PTR_ERR(pc->rst); 292 293 dev_err(&pdev->dev, "Reset control is not found: %d\n", ret); 293 294 goto put_pm; 294 295 } 295 296 296 - reset_control_deassert(pwm->rst); 297 + reset_control_deassert(pc->rst); 297 298 298 - pwm->chip.dev = &pdev->dev; 299 - pwm->chip.ops = &tegra_pwm_ops; 300 - pwm->chip.npwm = pwm->soc->num_channels; 299 + pc->chip.dev = &pdev->dev; 300 + pc->chip.ops = &tegra_pwm_ops; 301 + pc->chip.npwm = pc->soc->num_channels; 301 302 302 - ret = pwmchip_add(&pwm->chip); 303 + ret = pwmchip_add(&pc->chip); 303 304 if (ret < 0) { 304 305 dev_err(&pdev->dev, "pwmchip_add() failed: %d\n", ret); 305 - reset_control_assert(pwm->rst); 306 + reset_control_assert(pc->rst); 306 307 goto put_pm; 307 308 } 308 309
+35 -5
drivers/pwm/pwm-tiehrpwm.c
··· 216 216 * duty_ns = 10^9 * (ps_divval * duty_cycles) / PWM_CLK_RATE 217 217 */ 218 218 static int ehrpwm_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, 219 - int duty_ns, int period_ns) 219 + u64 duty_ns, u64 period_ns) 220 220 { 221 221 struct ehrpwm_pwm_chip *pc = to_ehrpwm_pwm_chip(chip); 222 222 u32 period_cycles, duty_cycles; ··· 401 401 pc->period_cycles[pwm->hwpwm] = 0; 402 402 } 403 403 404 + static int ehrpwm_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, 405 + const struct pwm_state *state) 406 + { 407 + int err; 408 + bool enabled = pwm->state.enabled; 409 + 410 + if (state->polarity != pwm->state.polarity) { 411 + if (enabled) { 412 + ehrpwm_pwm_disable(chip, pwm); 413 + enabled = false; 414 + } 415 + 416 + err = ehrpwm_pwm_set_polarity(chip, pwm, state->polarity); 417 + if (err) 418 + return err; 419 + } 420 + 421 + if (!state->enabled) { 422 + if (enabled) 423 + ehrpwm_pwm_disable(chip, pwm); 424 + return 0; 425 + } 426 + 427 + err = ehrpwm_pwm_config(chip, pwm, state->duty_cycle, state->period); 428 + if (err) 429 + return err; 430 + 431 + if (!enabled) 432 + err = ehrpwm_pwm_enable(chip, pwm); 433 + 434 + return err; 435 + } 436 + 404 437 static const struct pwm_ops ehrpwm_pwm_ops = { 405 438 .free = ehrpwm_pwm_free, 406 - .config = ehrpwm_pwm_config, 407 - .set_polarity = ehrpwm_pwm_set_polarity, 408 - .enable = ehrpwm_pwm_enable, 409 - .disable = ehrpwm_pwm_disable, 439 + .apply = ehrpwm_pwm_apply, 410 440 .owner = THIS_MODULE, 411 441 }; 412 442
+19 -19
drivers/pwm/pwm-vt8500.c
··· 235 235 236 236 static int vt8500_pwm_probe(struct platform_device *pdev) 237 237 { 238 - struct vt8500_chip *chip; 238 + struct vt8500_chip *vt8500; 239 239 struct device_node *np = pdev->dev.of_node; 240 240 int ret; 241 241 ··· 244 244 return -EINVAL; 245 245 } 246 246 247 - chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL); 248 - if (chip == NULL) 247 + vt8500 = devm_kzalloc(&pdev->dev, sizeof(*vt8500), GFP_KERNEL); 248 + if (vt8500 == NULL) 249 249 return -ENOMEM; 250 250 251 - chip->chip.dev = &pdev->dev; 252 - chip->chip.ops = &vt8500_pwm_ops; 253 - chip->chip.npwm = VT8500_NR_PWMS; 251 + vt8500->chip.dev = &pdev->dev; 252 + vt8500->chip.ops = &vt8500_pwm_ops; 253 + vt8500->chip.npwm = VT8500_NR_PWMS; 254 254 255 - chip->clk = devm_clk_get(&pdev->dev, NULL); 256 - if (IS_ERR(chip->clk)) { 255 + vt8500->clk = devm_clk_get(&pdev->dev, NULL); 256 + if (IS_ERR(vt8500->clk)) { 257 257 dev_err(&pdev->dev, "clock source not specified\n"); 258 - return PTR_ERR(chip->clk); 258 + return PTR_ERR(vt8500->clk); 259 259 } 260 260 261 - chip->base = devm_platform_ioremap_resource(pdev, 0); 262 - if (IS_ERR(chip->base)) 263 - return PTR_ERR(chip->base); 261 + vt8500->base = devm_platform_ioremap_resource(pdev, 0); 262 + if (IS_ERR(vt8500->base)) 263 + return PTR_ERR(vt8500->base); 264 264 265 - ret = clk_prepare(chip->clk); 265 + ret = clk_prepare(vt8500->clk); 266 266 if (ret < 0) { 267 267 dev_err(&pdev->dev, "failed to prepare clock\n"); 268 268 return ret; 269 269 } 270 270 271 - ret = pwmchip_add(&chip->chip); 271 + ret = pwmchip_add(&vt8500->chip); 272 272 if (ret < 0) { 273 273 dev_err(&pdev->dev, "failed to add PWM chip\n"); 274 - clk_unprepare(chip->clk); 274 + clk_unprepare(vt8500->clk); 275 275 return ret; 276 276 } 277 277 278 - platform_set_drvdata(pdev, chip); 278 + platform_set_drvdata(pdev, vt8500); 279 279 return ret; 280 280 } 281 281 282 282 static int vt8500_pwm_remove(struct platform_device *pdev) 283 283 { 284 - struct vt8500_chip *chip = platform_get_drvdata(pdev); 284 + struct vt8500_chip *vt8500 = platform_get_drvdata(pdev); 285 285 286 - pwmchip_remove(&chip->chip); 286 + pwmchip_remove(&vt8500->chip); 287 287 288 - clk_unprepare(chip->clk); 288 + clk_unprepare(vt8500->clk); 289 289 290 290 return 0; 291 291 }