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

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

Pull pwm changes from Thierry Reding:
"The patches for this release cycle include various enhancements
(device tree support, better compile coverage, ...) for existing
drivers. There is a new driver for Atmel SoCs.

Various drivers as well as the sysfs support received minor fixes and
cleanups"

* tag 'pwm/for-3.14-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/thierry.reding/linux-pwm:
pwm: tiecap: Remove duplicate put_sync call
pwm: tiehrpwm: use dev_err() instead of pr_err()
pwm: pxa: remove unnecessary space before tabs
pwm: ep93xx: split module author names
pwm: use seq_puts() instead of seq_printf()
pwm: atmel-pwm: Do not unprepare clock after successful registration
of: Add Atmel PWM controller device tree binding
pwm: atmel-pwm: Add Atmel PWM controller driver
backlight: pwm_bl: Remove error message upon devm_kzalloc() failure
pwm: pca9685: depends on I2C rather than REGMAP_I2C
pwm: renesas-tpu: Enable driver compilation with COMPILE_TEST
pwm: jz4740: Use devm_clk_get()
pwm: jz4740: Pass device to clk_get()
pwm: sysfs: Convert to use ATTRIBUTE_GROUPS macro
pwm: pxa: Add device tree support

+537 -39
+33
Documentation/devicetree/bindings/pwm/atmel-pwm.txt
··· 1 + Atmel PWM controller 2 + 3 + Required properties: 4 + - compatible: should be one of: 5 + - "atmel,at91sam9rl-pwm" 6 + - "atmel,sama5d3-pwm" 7 + - reg: physical base address and length of the controller's registers 8 + - #pwm-cells: Should be 3. See pwm.txt in this directory for a 9 + description of the cells format. 10 + 11 + Example: 12 + 13 + pwm0: pwm@f8034000 { 14 + compatible = "atmel,at91sam9rl-pwm"; 15 + reg = <0xf8034000 0x400>; 16 + #pwm-cells = <3>; 17 + }; 18 + 19 + pwmleds { 20 + compatible = "pwm-leds"; 21 + 22 + d1 { 23 + label = "d1"; 24 + pwms = <&pwm0 3 5000 0> 25 + max-brightness = <255>; 26 + }; 27 + 28 + d2 { 29 + label = "d2"; 30 + pwms = <&pwm0 1 5000 1> 31 + max-brightness = <255>; 32 + }; 33 + };
+30
Documentation/devicetree/bindings/pwm/pxa-pwm.txt
··· 1 + Marvell PWM controller 2 + 3 + Required properties: 4 + - compatible: should be one or more of: 5 + - "marvell,pxa250-pwm" 6 + - "marvell,pxa270-pwm" 7 + - "marvell,pxa168-pwm" 8 + - "marvell,pxa910-pwm" 9 + - reg: Physical base address and length of the registers used by the PWM channel 10 + Note that one device instance must be created for each PWM that is used, so the 11 + length covers only the register window for one PWM output, not that of the 12 + entire PWM controller. Currently length is 0x10 for all supported devices. 13 + - #pwm-cells: Should be 1. This cell is used to specify the period in 14 + nanoseconds. 15 + 16 + Example PWM device node: 17 + 18 + pwm0: pwm@40b00000 { 19 + compatible = "marvell,pxa250-pwm"; 20 + reg = <0x40b00000 0x10>; 21 + #pwm-cells = <1>; 22 + }; 23 + 24 + Example PWM client node: 25 + 26 + backlight { 27 + compatible = "pwm-backlight"; 28 + pwms = <&pwm0 5000000>; 29 + ... 30 + }
+12 -2
drivers/pwm/Kconfig
··· 41 41 To compile this driver as a module, choose M here: the module 42 42 will be called pwm-ab8500. 43 43 44 + config PWM_ATMEL 45 + tristate "Atmel PWM support" 46 + depends on ARCH_AT91 47 + help 48 + Generic PWM framework driver for Atmel SoC. 49 + 50 + To compile this driver as a module, choose M here: the module 51 + will be called pwm-atmel. 52 + 44 53 config PWM_ATMEL_TCB 45 54 tristate "Atmel TC Block PWM support" 46 55 depends on ATMEL_TCLIB && OF ··· 131 122 132 123 config PWM_PCA9685 133 124 tristate "NXP PCA9685 PWM driver" 134 - depends on OF && REGMAP_I2C 125 + depends on OF && I2C 126 + select REGMAP_I2C 135 127 help 136 128 Generic PWM framework driver for NXP PCA9685 LED controller. 137 129 ··· 159 149 160 150 config PWM_RENESAS_TPU 161 151 tristate "Renesas TPU PWM support" 162 - depends on ARCH_SHMOBILE 152 + depends on ARCH_SHMOBILE || COMPILE_TEST 163 153 help 164 154 This driver exposes the Timer Pulse Unit (TPU) PWM controller found 165 155 in Renesas chips through the PWM API.
+1
drivers/pwm/Makefile
··· 1 1 obj-$(CONFIG_PWM) += core.o 2 2 obj-$(CONFIG_PWM_SYSFS) += sysfs.o 3 3 obj-$(CONFIG_PWM_AB8500) += pwm-ab8500.o 4 + obj-$(CONFIG_PWM_ATMEL) += pwm-atmel.o 4 5 obj-$(CONFIG_PWM_ATMEL_TCB) += pwm-atmel-tcb.o 5 6 obj-$(CONFIG_PWM_BFIN) += pwm-bfin.o 6 7 obj-$(CONFIG_PWM_EP93XX) += pwm-ep93xx.o
+3 -3
drivers/pwm/core.c
··· 808 808 seq_printf(s, " pwm-%-3d (%-20.20s):", i, pwm->label); 809 809 810 810 if (test_bit(PWMF_REQUESTED, &pwm->flags)) 811 - seq_printf(s, " requested"); 811 + seq_puts(s, " requested"); 812 812 813 813 if (test_bit(PWMF_ENABLED, &pwm->flags)) 814 - seq_printf(s, " enabled"); 814 + seq_puts(s, " enabled"); 815 815 816 - seq_printf(s, "\n"); 816 + seq_puts(s, "\n"); 817 817 } 818 818 } 819 819
+395
drivers/pwm/pwm-atmel.c
··· 1 + /* 2 + * Driver for Atmel Pulse Width Modulation Controller 3 + * 4 + * Copyright (C) 2013 Atmel Corporation 5 + * Bo Shen <voice.shen@atmel.com> 6 + * 7 + * Licensed under GPLv2. 8 + */ 9 + 10 + #include <linux/clk.h> 11 + #include <linux/err.h> 12 + #include <linux/io.h> 13 + #include <linux/module.h> 14 + #include <linux/of.h> 15 + #include <linux/of_device.h> 16 + #include <linux/platform_device.h> 17 + #include <linux/pwm.h> 18 + #include <linux/slab.h> 19 + 20 + /* The following is global registers for PWM controller */ 21 + #define PWM_ENA 0x04 22 + #define PWM_DIS 0x08 23 + #define PWM_SR 0x0C 24 + /* Bit field in SR */ 25 + #define PWM_SR_ALL_CH_ON 0x0F 26 + 27 + /* The following register is PWM channel related registers */ 28 + #define PWM_CH_REG_OFFSET 0x200 29 + #define PWM_CH_REG_SIZE 0x20 30 + 31 + #define PWM_CMR 0x0 32 + /* Bit field in CMR */ 33 + #define PWM_CMR_CPOL (1 << 9) 34 + #define PWM_CMR_UPD_CDTY (1 << 10) 35 + 36 + /* The following registers for PWM v1 */ 37 + #define PWMV1_CDTY 0x04 38 + #define PWMV1_CPRD 0x08 39 + #define PWMV1_CUPD 0x10 40 + 41 + /* The following registers for PWM v2 */ 42 + #define PWMV2_CDTY 0x04 43 + #define PWMV2_CDTYUPD 0x08 44 + #define PWMV2_CPRD 0x0C 45 + #define PWMV2_CPRDUPD 0x10 46 + 47 + /* 48 + * Max value for duty and period 49 + * 50 + * Although the duty and period register is 32 bit, 51 + * however only the LSB 16 bits are significant. 52 + */ 53 + #define PWM_MAX_DTY 0xFFFF 54 + #define PWM_MAX_PRD 0xFFFF 55 + #define PRD_MAX_PRES 10 56 + 57 + struct atmel_pwm_chip { 58 + struct pwm_chip chip; 59 + struct clk *clk; 60 + void __iomem *base; 61 + 62 + void (*config)(struct pwm_chip *chip, struct pwm_device *pwm, 63 + unsigned long dty, unsigned long prd); 64 + }; 65 + 66 + static inline struct atmel_pwm_chip *to_atmel_pwm_chip(struct pwm_chip *chip) 67 + { 68 + return container_of(chip, struct atmel_pwm_chip, chip); 69 + } 70 + 71 + static inline u32 atmel_pwm_readl(struct atmel_pwm_chip *chip, 72 + unsigned long offset) 73 + { 74 + return readl_relaxed(chip->base + offset); 75 + } 76 + 77 + static inline void atmel_pwm_writel(struct atmel_pwm_chip *chip, 78 + unsigned long offset, unsigned long val) 79 + { 80 + writel_relaxed(val, chip->base + offset); 81 + } 82 + 83 + static inline u32 atmel_pwm_ch_readl(struct atmel_pwm_chip *chip, 84 + unsigned int ch, unsigned long offset) 85 + { 86 + unsigned long base = PWM_CH_REG_OFFSET + ch * PWM_CH_REG_SIZE; 87 + 88 + return readl_relaxed(chip->base + base + offset); 89 + } 90 + 91 + static inline void atmel_pwm_ch_writel(struct atmel_pwm_chip *chip, 92 + unsigned int ch, unsigned long offset, 93 + unsigned long val) 94 + { 95 + unsigned long base = PWM_CH_REG_OFFSET + ch * PWM_CH_REG_SIZE; 96 + 97 + writel_relaxed(val, chip->base + base + offset); 98 + } 99 + 100 + static int atmel_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, 101 + int duty_ns, int period_ns) 102 + { 103 + struct atmel_pwm_chip *atmel_pwm = to_atmel_pwm_chip(chip); 104 + unsigned long clk_rate, prd, dty; 105 + unsigned long long div; 106 + unsigned int pres = 0; 107 + int ret; 108 + 109 + if (test_bit(PWMF_ENABLED, &pwm->flags) && (period_ns != pwm->period)) { 110 + dev_err(chip->dev, "cannot change PWM period while enabled\n"); 111 + return -EBUSY; 112 + } 113 + 114 + clk_rate = clk_get_rate(atmel_pwm->clk); 115 + div = clk_rate; 116 + 117 + /* Calculate the period cycles */ 118 + while (div > PWM_MAX_PRD) { 119 + div = clk_rate / (1 << pres); 120 + div = div * period_ns; 121 + /* 1/Hz = 100000000 ns */ 122 + do_div(div, 1000000000); 123 + 124 + if (pres++ > PRD_MAX_PRES) { 125 + dev_err(chip->dev, "pres exceeds the maximum value\n"); 126 + return -EINVAL; 127 + } 128 + } 129 + 130 + /* Calculate the duty cycles */ 131 + prd = div; 132 + div *= duty_ns; 133 + do_div(div, period_ns); 134 + dty = div; 135 + 136 + ret = clk_enable(atmel_pwm->clk); 137 + if (ret) { 138 + dev_err(chip->dev, "failed to enable PWM clock\n"); 139 + return ret; 140 + } 141 + 142 + atmel_pwm_ch_writel(atmel_pwm, pwm->hwpwm, PWM_CMR, pres); 143 + atmel_pwm->config(chip, pwm, dty, prd); 144 + 145 + clk_disable(atmel_pwm->clk); 146 + return ret; 147 + } 148 + 149 + static void atmel_pwm_config_v1(struct pwm_chip *chip, struct pwm_device *pwm, 150 + unsigned long dty, unsigned long prd) 151 + { 152 + struct atmel_pwm_chip *atmel_pwm = to_atmel_pwm_chip(chip); 153 + unsigned int val; 154 + 155 + if (test_bit(PWMF_ENABLED, &pwm->flags)) { 156 + /* 157 + * If the PWM channel is enabled, using the update register, 158 + * it needs to set bit 10 of CMR to 0 159 + */ 160 + atmel_pwm_ch_writel(atmel_pwm, pwm->hwpwm, PWMV1_CUPD, dty); 161 + 162 + val = atmel_pwm_ch_readl(atmel_pwm, pwm->hwpwm, PWM_CMR); 163 + val &= ~PWM_CMR_UPD_CDTY; 164 + atmel_pwm_ch_writel(atmel_pwm, pwm->hwpwm, PWM_CMR, val); 165 + } else { 166 + /* 167 + * If the PWM channel is disabled, write value to duty and 168 + * period registers directly. 169 + */ 170 + atmel_pwm_ch_writel(atmel_pwm, pwm->hwpwm, PWMV1_CDTY, dty); 171 + atmel_pwm_ch_writel(atmel_pwm, pwm->hwpwm, PWMV1_CPRD, prd); 172 + } 173 + } 174 + 175 + static void atmel_pwm_config_v2(struct pwm_chip *chip, struct pwm_device *pwm, 176 + unsigned long dty, unsigned long prd) 177 + { 178 + struct atmel_pwm_chip *atmel_pwm = to_atmel_pwm_chip(chip); 179 + 180 + if (test_bit(PWMF_ENABLED, &pwm->flags)) { 181 + /* 182 + * If the PWM channel is enabled, using the duty update register 183 + * to update the value. 184 + */ 185 + atmel_pwm_ch_writel(atmel_pwm, pwm->hwpwm, PWMV2_CDTYUPD, dty); 186 + } else { 187 + /* 188 + * If the PWM channel is disabled, write value to duty and 189 + * period registers directly. 190 + */ 191 + atmel_pwm_ch_writel(atmel_pwm, pwm->hwpwm, PWMV2_CDTY, dty); 192 + atmel_pwm_ch_writel(atmel_pwm, pwm->hwpwm, PWMV2_CPRD, prd); 193 + } 194 + } 195 + 196 + static int atmel_pwm_set_polarity(struct pwm_chip *chip, struct pwm_device *pwm, 197 + enum pwm_polarity polarity) 198 + { 199 + struct atmel_pwm_chip *atmel_pwm = to_atmel_pwm_chip(chip); 200 + u32 val; 201 + int ret; 202 + 203 + val = atmel_pwm_ch_readl(atmel_pwm, pwm->hwpwm, PWM_CMR); 204 + 205 + if (polarity == PWM_POLARITY_NORMAL) 206 + val &= ~PWM_CMR_CPOL; 207 + else 208 + val |= PWM_CMR_CPOL; 209 + 210 + ret = clk_enable(atmel_pwm->clk); 211 + if (ret) { 212 + dev_err(chip->dev, "failed to enable PWM clock\n"); 213 + return ret; 214 + } 215 + 216 + atmel_pwm_ch_writel(atmel_pwm, pwm->hwpwm, PWM_CMR, val); 217 + 218 + clk_disable(atmel_pwm->clk); 219 + 220 + return 0; 221 + } 222 + 223 + static int atmel_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm) 224 + { 225 + struct atmel_pwm_chip *atmel_pwm = to_atmel_pwm_chip(chip); 226 + int ret; 227 + 228 + ret = clk_enable(atmel_pwm->clk); 229 + if (ret) { 230 + dev_err(chip->dev, "failed to enable PWM clock\n"); 231 + return ret; 232 + } 233 + 234 + atmel_pwm_writel(atmel_pwm, PWM_ENA, 1 << pwm->hwpwm); 235 + 236 + return 0; 237 + } 238 + 239 + static void atmel_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm) 240 + { 241 + struct atmel_pwm_chip *atmel_pwm = to_atmel_pwm_chip(chip); 242 + 243 + atmel_pwm_writel(atmel_pwm, PWM_DIS, 1 << pwm->hwpwm); 244 + 245 + clk_disable(atmel_pwm->clk); 246 + } 247 + 248 + static const struct pwm_ops atmel_pwm_ops = { 249 + .config = atmel_pwm_config, 250 + .set_polarity = atmel_pwm_set_polarity, 251 + .enable = atmel_pwm_enable, 252 + .disable = atmel_pwm_disable, 253 + .owner = THIS_MODULE, 254 + }; 255 + 256 + struct atmel_pwm_data { 257 + void (*config)(struct pwm_chip *chip, struct pwm_device *pwm, 258 + unsigned long dty, unsigned long prd); 259 + }; 260 + 261 + static const struct atmel_pwm_data atmel_pwm_data_v1 = { 262 + .config = atmel_pwm_config_v1, 263 + }; 264 + 265 + static const struct atmel_pwm_data atmel_pwm_data_v2 = { 266 + .config = atmel_pwm_config_v2, 267 + }; 268 + 269 + static const struct platform_device_id atmel_pwm_devtypes[] = { 270 + { 271 + .name = "at91sam9rl-pwm", 272 + .driver_data = (kernel_ulong_t)&atmel_pwm_data_v1, 273 + }, { 274 + .name = "sama5d3-pwm", 275 + .driver_data = (kernel_ulong_t)&atmel_pwm_data_v2, 276 + }, { 277 + /* sentinel */ 278 + }, 279 + }; 280 + MODULE_DEVICE_TABLE(platform, atmel_pwm_devtypes); 281 + 282 + static const struct of_device_id atmel_pwm_dt_ids[] = { 283 + { 284 + .compatible = "atmel,at91sam9rl-pwm", 285 + .data = &atmel_pwm_data_v1, 286 + }, { 287 + .compatible = "atmel,sama5d3-pwm", 288 + .data = &atmel_pwm_data_v2, 289 + }, { 290 + /* sentinel */ 291 + }, 292 + }; 293 + MODULE_DEVICE_TABLE(of, atmel_pwm_dt_ids); 294 + 295 + static inline const struct atmel_pwm_data * 296 + atmel_pwm_get_driver_data(struct platform_device *pdev) 297 + { 298 + if (pdev->dev.of_node) { 299 + const struct of_device_id *match; 300 + 301 + match = of_match_device(atmel_pwm_dt_ids, &pdev->dev); 302 + if (!match) 303 + return NULL; 304 + 305 + return match->data; 306 + } else { 307 + const struct platform_device_id *id; 308 + 309 + id = platform_get_device_id(pdev); 310 + 311 + return (struct atmel_pwm_data *)id->driver_data; 312 + } 313 + } 314 + 315 + static int atmel_pwm_probe(struct platform_device *pdev) 316 + { 317 + const struct atmel_pwm_data *data; 318 + struct atmel_pwm_chip *atmel_pwm; 319 + struct resource *res; 320 + int ret; 321 + 322 + data = atmel_pwm_get_driver_data(pdev); 323 + if (!data) 324 + return -ENODEV; 325 + 326 + atmel_pwm = devm_kzalloc(&pdev->dev, sizeof(*atmel_pwm), GFP_KERNEL); 327 + if (!atmel_pwm) 328 + return -ENOMEM; 329 + 330 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 331 + atmel_pwm->base = devm_ioremap_resource(&pdev->dev, res); 332 + if (IS_ERR(atmel_pwm->base)) 333 + return PTR_ERR(atmel_pwm->base); 334 + 335 + atmel_pwm->clk = devm_clk_get(&pdev->dev, NULL); 336 + if (IS_ERR(atmel_pwm->clk)) 337 + return PTR_ERR(atmel_pwm->clk); 338 + 339 + ret = clk_prepare(atmel_pwm->clk); 340 + if (ret) { 341 + dev_err(&pdev->dev, "failed to prepare PWM clock\n"); 342 + return ret; 343 + } 344 + 345 + atmel_pwm->chip.dev = &pdev->dev; 346 + atmel_pwm->chip.ops = &atmel_pwm_ops; 347 + 348 + if (pdev->dev.of_node) { 349 + atmel_pwm->chip.of_xlate = of_pwm_xlate_with_flags; 350 + atmel_pwm->chip.of_pwm_n_cells = 3; 351 + } 352 + 353 + atmel_pwm->chip.base = -1; 354 + atmel_pwm->chip.npwm = 4; 355 + atmel_pwm->config = data->config; 356 + 357 + ret = pwmchip_add(&atmel_pwm->chip); 358 + if (ret < 0) { 359 + dev_err(&pdev->dev, "failed to add PWM chip %d\n", ret); 360 + goto unprepare_clk; 361 + } 362 + 363 + platform_set_drvdata(pdev, atmel_pwm); 364 + 365 + return ret; 366 + 367 + unprepare_clk: 368 + clk_unprepare(atmel_pwm->clk); 369 + return ret; 370 + } 371 + 372 + static int atmel_pwm_remove(struct platform_device *pdev) 373 + { 374 + struct atmel_pwm_chip *atmel_pwm = platform_get_drvdata(pdev); 375 + 376 + clk_unprepare(atmel_pwm->clk); 377 + 378 + return pwmchip_remove(&atmel_pwm->chip); 379 + } 380 + 381 + static struct platform_driver atmel_pwm_driver = { 382 + .driver = { 383 + .name = "atmel-pwm", 384 + .of_match_table = of_match_ptr(atmel_pwm_dt_ids), 385 + }, 386 + .id_table = atmel_pwm_devtypes, 387 + .probe = atmel_pwm_probe, 388 + .remove = atmel_pwm_remove, 389 + }; 390 + module_platform_driver(atmel_pwm_driver); 391 + 392 + MODULE_ALIAS("platform:atmel-pwm"); 393 + MODULE_AUTHOR("Bo Shen <voice.shen@atmel.com>"); 394 + MODULE_DESCRIPTION("Atmel PWM driver"); 395 + MODULE_LICENSE("GPL v2");
+2 -2
drivers/pwm/pwm-ep93xx.c
··· 224 224 module_platform_driver(ep93xx_pwm_driver); 225 225 226 226 MODULE_DESCRIPTION("Cirrus Logic EP93xx PWM driver"); 227 - MODULE_AUTHOR("Matthieu Crapet <mcrapet@gmail.com>, " 228 - "H Hartley Sweeten <hsweeten@visionengravers.com>"); 227 + MODULE_AUTHOR("Matthieu Crapet <mcrapet@gmail.com>"); 228 + MODULE_AUTHOR("H Hartley Sweeten <hsweeten@visionengravers.com>"); 229 229 MODULE_ALIAS("platform:ep93xx-pwm"); 230 230 MODULE_LICENSE("GPL");
+3 -17
drivers/pwm/pwm-jz4740.c
··· 165 165 static int jz4740_pwm_probe(struct platform_device *pdev) 166 166 { 167 167 struct jz4740_pwm_chip *jz4740; 168 - int ret; 169 168 170 169 jz4740 = devm_kzalloc(&pdev->dev, sizeof(*jz4740), GFP_KERNEL); 171 170 if (!jz4740) 172 171 return -ENOMEM; 173 172 174 - jz4740->clk = clk_get(NULL, "ext"); 173 + jz4740->clk = devm_clk_get(&pdev->dev, "ext"); 175 174 if (IS_ERR(jz4740->clk)) 176 175 return PTR_ERR(jz4740->clk); 177 176 ··· 179 180 jz4740->chip.npwm = NUM_PWM; 180 181 jz4740->chip.base = -1; 181 182 182 - ret = pwmchip_add(&jz4740->chip); 183 - if (ret < 0) { 184 - clk_put(jz4740->clk); 185 - return ret; 186 - } 187 - 188 183 platform_set_drvdata(pdev, jz4740); 189 184 190 - return 0; 185 + return pwmchip_add(&jz4740->chip); 191 186 } 192 187 193 188 static int jz4740_pwm_remove(struct platform_device *pdev) 194 189 { 195 190 struct jz4740_pwm_chip *jz4740 = platform_get_drvdata(pdev); 196 - int ret; 197 191 198 - ret = pwmchip_remove(&jz4740->chip); 199 - if (ret < 0) 200 - return ret; 201 - 202 - clk_put(jz4740->clk); 203 - 204 - return 0; 192 + return pwmchip_remove(&jz4740->chip); 205 193 } 206 194 207 195 static struct platform_driver jz4740_pwm_driver = {
+54 -1
drivers/pwm/pwm-pxa.c
··· 8 8 * published by the Free Software Foundation. 9 9 * 10 10 * 2008-02-13 initial version 11 - * eric miao <eric.miao@marvell.com> 11 + * eric miao <eric.miao@marvell.com> 12 12 */ 13 13 14 14 #include <linux/module.h> ··· 19 19 #include <linux/clk.h> 20 20 #include <linux/io.h> 21 21 #include <linux/pwm.h> 22 + #include <linux/of_device.h> 22 23 23 24 #include <asm/div64.h> 24 25 ··· 125 124 .owner = THIS_MODULE, 126 125 }; 127 126 127 + #ifdef CONFIG_OF 128 + /* 129 + * Device tree users must create one device instance for each pwm channel. 130 + * Hence we dispense with the HAS_SECONDARY_PWM and "tell" the original driver 131 + * code that this is a single channel pxa25x-pwm. Currently all devices are 132 + * supported identically. 133 + */ 134 + static struct of_device_id pwm_of_match[] = { 135 + { .compatible = "marvell,pxa250-pwm", .data = &pwm_id_table[0]}, 136 + { .compatible = "marvell,pxa270-pwm", .data = &pwm_id_table[0]}, 137 + { .compatible = "marvell,pxa168-pwm", .data = &pwm_id_table[0]}, 138 + { .compatible = "marvell,pxa910-pwm", .data = &pwm_id_table[0]}, 139 + { } 140 + }; 141 + MODULE_DEVICE_TABLE(of, pwm_of_match); 142 + #else 143 + #define pwm_of_match NULL 144 + #endif 145 + 146 + static const struct platform_device_id *pxa_pwm_get_id_dt(struct device *dev) 147 + { 148 + const struct of_device_id *id = of_match_device(pwm_of_match, dev); 149 + 150 + return id ? id->data : NULL; 151 + } 152 + 153 + static struct pwm_device * 154 + pxa_pwm_of_xlate(struct pwm_chip *pc, const struct of_phandle_args *args) 155 + { 156 + struct pwm_device *pwm; 157 + 158 + pwm = pwm_request_from_chip(pc, 0, NULL); 159 + if (IS_ERR(pwm)) 160 + return pwm; 161 + 162 + pwm_set_period(pwm, args->args[0]); 163 + 164 + return pwm; 165 + } 166 + 128 167 static int pwm_probe(struct platform_device *pdev) 129 168 { 130 169 const struct platform_device_id *id = platform_get_device_id(pdev); 131 170 struct pxa_pwm_chip *pwm; 132 171 struct resource *r; 133 172 int ret = 0; 173 + 174 + if (IS_ENABLED(CONFIG_OF) && id == NULL) 175 + id = pxa_pwm_get_id_dt(&pdev->dev); 176 + 177 + if (id == NULL) 178 + return -EINVAL; 134 179 135 180 pwm = devm_kzalloc(&pdev->dev, sizeof(*pwm), GFP_KERNEL); 136 181 if (pwm == NULL) { ··· 192 145 pwm->chip.ops = &pxa_pwm_ops; 193 146 pwm->chip.base = -1; 194 147 pwm->chip.npwm = (id->driver_data & HAS_SECONDARY_PWM) ? 2 : 1; 148 + 149 + if (IS_ENABLED(CONFIG_OF)) { 150 + pwm->chip.of_xlate = pxa_pwm_of_xlate; 151 + pwm->chip.of_pwm_n_cells = 1; 152 + } 195 153 196 154 r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 197 155 pwm->mmio_base = devm_ioremap_resource(&pdev->dev, r); ··· 228 176 .driver = { 229 177 .name = "pxa25x-pwm", 230 178 .owner = THIS_MODULE, 179 + .of_match_table = pwm_of_match, 231 180 }, 232 181 .probe = pwm_probe, 233 182 .remove = pwm_remove,
-1
drivers/pwm/pwm-tiecap.c
··· 279 279 pwmss_submodule_state_change(pdev->dev.parent, PWMSS_ECAPCLK_STOP_REQ); 280 280 pm_runtime_put_sync(&pdev->dev); 281 281 282 - pm_runtime_put_sync(&pdev->dev); 283 282 pm_runtime_disable(&pdev->dev); 284 283 return pwmchip_remove(&pc->chip); 285 284 }
+2 -2
drivers/pwm/pwm-tiehrpwm.c
··· 360 360 /* Enable TBCLK before enabling PWM device */ 361 361 ret = clk_enable(pc->tbclk); 362 362 if (ret) { 363 - pr_err("Failed to enable TBCLK for %s\n", 364 - dev_name(pc->chip.dev)); 363 + dev_err(chip->dev, "Failed to enable TBCLK for %s\n", 364 + dev_name(pc->chip.dev)); 365 365 return ret; 366 366 } 367 367
+2 -10
drivers/pwm/sysfs.c
··· 169 169 &dev_attr_polarity.attr, 170 170 NULL 171 171 }; 172 - 173 - static const struct attribute_group pwm_attr_group = { 174 - .attrs = pwm_attrs, 175 - }; 176 - 177 - static const struct attribute_group *pwm_attr_groups[] = { 178 - &pwm_attr_group, 179 - NULL, 180 - }; 172 + ATTRIBUTE_GROUPS(pwm); 181 173 182 174 static void pwm_export_release(struct device *child) 183 175 { ··· 197 205 export->child.release = pwm_export_release; 198 206 export->child.parent = parent; 199 207 export->child.devt = MKDEV(0, 0); 200 - export->child.groups = pwm_attr_groups; 208 + export->child.groups = pwm_groups; 201 209 dev_set_name(&export->child, "pwm%u", pwm->hwpwm); 202 210 203 211 ret = device_register(&export->child);
-1
drivers/video/backlight/pwm_bl.c
··· 241 241 242 242 pb = devm_kzalloc(&pdev->dev, sizeof(*pb), GFP_KERNEL); 243 243 if (!pb) { 244 - dev_err(&pdev->dev, "no memory for state\n"); 245 244 ret = -ENOMEM; 246 245 goto err_alloc; 247 246 }