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

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

Pull pwm changes from Thierry Reding:
"The majority of these changes are cleanups and fixes across all
drivers. Redundant error messages are removed and more PWM
controllers set the .can_sleep flag to signal that they can't be used
in atomic context.

Support is added for the Broadcom Kona family of SoCs and the Intel
LPSS driver can now probe PCI devices in addition to ACPI devices.
Upon shutdown, the pwm-backlight driver will now power off the
backlight. It also uses the new descriptor-based GPIO API for more
concise GPIO handling.

A large chunk of these changes also converts platforms to use the
lookup mechanism rather than relying on the global number space to
reference PWM devices. This is largely in preparation for more
unification and cleanups in future patches. Eventually it will allow
the legacy PWM API to be removed"

* tag 'pwm/for-3.16-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/thierry.reding/linux-pwm: (38 commits)
pwm: fsl-ftm: set pwm_chip can_sleep flag
pwm: ab8500: Fix wrong value shift for disable/enable PWM
pwm: samsung: do not set manual update bit in pwm_samsung_config
pwm: lp3943: Set pwm_chip can_sleep flag
pwm: atmel: set pwm_chip can_sleep flag
pwm: mxs: set pwm_chip can_sleep flag
pwm: tiehrpwm: inline accessor functions
pwm: tiehrpwm: don't build PM related functions when not needed
pwm-backlight: retrieve configured PWM period
leds: leds-pwm: retrieve configured PWM period
ARM: pxa: hx4700: use PWM_LOOKUP to initialize struct pwm_lookup
ARM: shmobile: armadillo: use PWM_LOOKUP to initialize struct pwm_lookup
ARM: OMAP3: Beagle: use PWM_LOOKUP to initialize struct pwm_lookup
pwm: modify PWM_LOOKUP to initialize all struct pwm_lookup members
ARM: pxa: hx4700: initialize all the struct pwm_lookup members
ARM: OMAP3: Beagle: initialize all the struct pwm_lookup members
pwm: renesas-tpu: remove unused struct tpu_pwm_platform_data
ARM: shmobile: armadillo: initialize all struct pwm_lookup members
pwm: add period and polarity to struct pwm_lookup
pwm: twl: Really disable twl6030 PWMs
...

+578 -178
+21
Documentation/devicetree/bindings/pwm/bcm-kona-pwm.txt
··· 1 + Broadcom Kona PWM controller device tree bindings 2 + 3 + This controller has 6 channels. 4 + 5 + Required Properties : 6 + - compatible: should contain "brcm,kona-pwm" 7 + - reg: physical base address and length of the controller's registers 8 + - clocks: phandle + clock specifier pair for the external clock 9 + - #pwm-cells: Should be 3. See pwm.txt in this directory for a 10 + description of the cells format. 11 + 12 + Refer to clocks/clock-bindings.txt for generic clock consumer properties. 13 + 14 + Example: 15 + 16 + pwm: pwm@3e01a000 { 17 + compatible = "brcm,bcm11351-pwm", "brcm,kona-pwm"; 18 + reg = <0x3e01a000 0xc4>; 19 + clocks = <&pwm_clk>; 20 + #pwm-cells = <3>; 21 + };
+9 -1
Documentation/pwm.txt
··· 19 19 consumers to providers, as given in the following example: 20 20 21 21 static struct pwm_lookup board_pwm_lookup[] = { 22 - PWM_LOOKUP("tegra-pwm", 0, "pwm-backlight", NULL), 22 + PWM_LOOKUP("tegra-pwm", 0, "pwm-backlight", NULL, 23 + 50000, PWM_POLARITY_NORMAL), 23 24 }; 24 25 25 26 static void __init board_init(void) ··· 97 96 pwm_chip as argument which provides a description of the PWM chip, the 98 97 number of PWM devices provided by the chip and the chip-specific 99 98 implementation of the supported PWM operations to the framework. 99 + 100 + When implementing polarity support in a PWM driver, make sure to respect the 101 + signal conventions in the PWM framework. By definition, normal polarity 102 + characterizes a signal starts high for the duration of the duty cycle and 103 + goes low for the remainder of the period. Conversely, a signal with inversed 104 + polarity starts low for the duration of the duty cycle and goes high for the 105 + remainder of the period. 100 106 101 107 Locking 102 108 -------
+2 -1
arch/arm/mach-omap2/board-omap3beagle.c
··· 60 60 61 61 static struct pwm_lookup pwm_lookup[] = { 62 62 /* LEDB -> PMU_STAT */ 63 - PWM_LOOKUP("twl-pwmled", 1, "leds_pwm", "beagleboard::pmu_stat"), 63 + PWM_LOOKUP("twl-pwmled", 1, "leds_pwm", "beagleboard::pmu_stat", 64 + 7812500, PWM_POLARITY_NORMAL), 64 65 }; 65 66 66 67 static struct led_pwm pwm_leds[] = {
+2 -1
arch/arm/mach-pxa/hx4700.c
··· 574 574 }; 575 575 576 576 static struct pwm_lookup hx4700_pwm_lookup[] = { 577 - PWM_LOOKUP("pxa27x-pwm.1", 0, "pwm-backlight", NULL), 577 + PWM_LOOKUP("pxa27x-pwm.1", 0, "pwm-backlight", NULL, 578 + 30923, PWM_POLARITY_NORMAL), 578 579 }; 579 580 580 581 /*
+3 -11
arch/arm/mach-shmobile/board-armadillo800eva.c
··· 31 31 #include <linux/gpio_keys.h> 32 32 #include <linux/regulator/driver.h> 33 33 #include <linux/pinctrl/machine.h> 34 - #include <linux/platform_data/pwm-renesas-tpu.h> 34 + #include <linux/pwm.h> 35 35 #include <linux/pwm_backlight.h> 36 36 #include <linux/regulator/fixed.h> 37 37 #include <linux/regulator/gpio-regulator.h> ··· 399 399 }, 400 400 }; 401 401 402 - static struct tpu_pwm_platform_data pwm_device_data = { 403 - .channels[2] = { 404 - .polarity = PWM_POLARITY_INVERSED, 405 - } 406 - }; 407 - 408 402 static struct platform_device pwm_device = { 409 403 .name = "renesas-tpu-pwm", 410 404 .id = -1, 411 - .dev = { 412 - .platform_data = &pwm_device_data, 413 - }, 414 405 .num_resources = ARRAY_SIZE(pwm_resources), 415 406 .resource = pwm_resources, 416 407 }; 417 408 418 409 static struct pwm_lookup pwm_lookup[] = { 419 - PWM_LOOKUP("renesas-tpu-pwm", 2, "pwm-backlight.0", NULL), 410 + PWM_LOOKUP("renesas-tpu-pwm", 2, "pwm-backlight.0", NULL, 411 + 33333, PWM_POLARITY_INVERSED), 420 412 }; 421 413 422 414 /* LCDC and backlight */
-2
arch/arm/plat-samsung/dev-backlight.c
··· 124 124 samsung_bl_data->pwm_period_ns = bl_data->pwm_period_ns; 125 125 if (bl_data->enable_gpio >= 0) 126 126 samsung_bl_data->enable_gpio = bl_data->enable_gpio; 127 - if (bl_data->enable_gpio_flags) 128 - samsung_bl_data->enable_gpio_flags = bl_data->enable_gpio_flags; 129 127 if (bl_data->init) 130 128 samsung_bl_data->init = bl_data->init; 131 129 if (bl_data->notify)
+4 -1
drivers/leds/leds-pwm.c
··· 181 181 led_dat->cdev.name = cur_led->name; 182 182 led_dat->cdev.default_trigger = cur_led->default_trigger; 183 183 led_dat->active_low = cur_led->active_low; 184 - led_dat->period = cur_led->pwm_period_ns; 185 184 led_dat->cdev.brightness_set = led_pwm_set; 186 185 led_dat->cdev.brightness = LED_OFF; 187 186 led_dat->cdev.max_brightness = cur_led->max_brightness; ··· 189 190 led_dat->can_sleep = pwm_can_sleep(led_dat->pwm); 190 191 if (led_dat->can_sleep) 191 192 INIT_WORK(&led_dat->work, led_pwm_work); 193 + 194 + led_dat->period = pwm_get_period(led_dat->pwm); 195 + if (!led_dat->period && (cur_led->pwm_period_ns > 0)) 196 + led_dat->period = cur_led->pwm_period_ns; 192 197 193 198 ret = led_classdev_register(&pdev->dev, &led_dat->cdev); 194 199 if (ret < 0)
+9
drivers/pwm/Kconfig
··· 62 62 To compile this driver as a module, choose M here: the module 63 63 will be called pwm-atmel-tcb. 64 64 65 + config PWM_BCM_KONA 66 + tristate "Kona PWM support" 67 + depends on ARCH_BCM_MOBILE 68 + help 69 + Generic PWM framework driver for Broadcom Kona PWM block. 70 + 71 + To compile this driver as a module, choose M here: the module 72 + will be called pwm-bcm-kona. 73 + 65 74 config PWM_BFIN 66 75 tristate "Blackfin PWM support" 67 76 depends on BFIN_GPTIMERS
+1
drivers/pwm/Makefile
··· 3 3 obj-$(CONFIG_PWM_AB8500) += pwm-ab8500.o 4 4 obj-$(CONFIG_PWM_ATMEL) += pwm-atmel.o 5 5 obj-$(CONFIG_PWM_ATMEL_TCB) += pwm-atmel-tcb.o 6 + obj-$(CONFIG_PWM_BCM_KONA) += pwm-bcm-kona.o 6 7 obj-$(CONFIG_PWM_BFIN) += pwm-bfin.o 7 8 obj-$(CONFIG_PWM_CLPS711X) += pwm-clps711x.o 8 9 obj-$(CONFIG_PWM_EP93XX) += pwm-ep93xx.o
+7 -1
drivers/pwm/core.c
··· 661 661 } 662 662 } 663 663 664 + mutex_unlock(&pwm_lookup_lock); 665 + 664 666 if (chip) 665 667 pwm = pwm_request_from_chip(chip, index, con_id ?: dev_id); 668 + if (IS_ERR(pwm)) 669 + return pwm; 666 670 667 - mutex_unlock(&pwm_lookup_lock); 671 + pwm_set_period(pwm, p->period); 672 + pwm_set_polarity(pwm, p->polarity); 673 + 668 674 669 675 return pwm; 670 676 }
+3 -10
drivers/pwm/pwm-ab8500.c
··· 20 20 #define AB8500_PWM_OUT_CTRL2_REG 0x61 21 21 #define AB8500_PWM_OUT_CTRL7_REG 0x66 22 22 23 - /* backlight driver constants */ 24 - #define ENABLE_PWM 1 25 - #define DISABLE_PWM 0 26 - 27 23 struct ab8500_pwm_chip { 28 24 struct pwm_chip chip; 29 25 }; ··· 60 64 61 65 ret = abx500_mask_and_set_register_interruptible(chip->dev, 62 66 AB8500_MISC, AB8500_PWM_OUT_CTRL7_REG, 63 - 1 << (chip->base - 1), ENABLE_PWM); 67 + 1 << (chip->base - 1), 1 << (chip->base - 1)); 64 68 if (ret < 0) 65 69 dev_err(chip->dev, "%s: Failed to enable PWM, Error %d\n", 66 70 pwm->label, ret); ··· 73 77 74 78 ret = abx500_mask_and_set_register_interruptible(chip->dev, 75 79 AB8500_MISC, AB8500_PWM_OUT_CTRL7_REG, 76 - 1 << (chip->base - 1), DISABLE_PWM); 80 + 1 << (chip->base - 1), 0); 77 81 if (ret < 0) 78 82 dev_err(chip->dev, "%s: Failed to disable PWM, Error %d\n", 79 83 pwm->label, ret); 80 - return; 81 84 } 82 85 83 86 static const struct pwm_ops ab8500_pwm_ops = { ··· 96 101 * device which is required for ab8500 read and write 97 102 */ 98 103 ab8500 = devm_kzalloc(&pdev->dev, sizeof(*ab8500), GFP_KERNEL); 99 - if (ab8500 == NULL) { 100 - dev_err(&pdev->dev, "failed to allocate memory\n"); 104 + if (ab8500 == NULL) 101 105 return -ENOMEM; 102 - } 103 106 104 107 ab8500->chip.dev = &pdev->dev; 105 108 ab8500->chip.ops = &ab8500_pwm_ops;
+1
drivers/pwm/pwm-atmel.c
··· 357 357 358 358 atmel_pwm->chip.base = -1; 359 359 atmel_pwm->chip.npwm = 4; 360 + atmel_pwm->chip.can_sleep = true; 360 361 atmel_pwm->config = data->config; 361 362 362 363 ret = pwmchip_add(&atmel_pwm->chip);
+318
drivers/pwm/pwm-bcm-kona.c
··· 1 + /* 2 + * Copyright (C) 2014 Broadcom Corporation 3 + * 4 + * This program is free software; you can redistribute it and/or 5 + * modify it under the terms of the GNU General Public License as 6 + * published by the Free Software Foundation version 2. 7 + * 8 + * This program is distributed "as is" WITHOUT ANY WARRANTY of any 9 + * kind, whether express or implied; without even the implied warranty 10 + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 + * GNU General Public License for more details. 12 + */ 13 + 14 + #include <linux/clk.h> 15 + #include <linux/delay.h> 16 + #include <linux/err.h> 17 + #include <linux/io.h> 18 + #include <linux/ioport.h> 19 + #include <linux/math64.h> 20 + #include <linux/module.h> 21 + #include <linux/of.h> 22 + #include <linux/platform_device.h> 23 + #include <linux/pwm.h> 24 + #include <linux/slab.h> 25 + #include <linux/types.h> 26 + 27 + /* 28 + * The Kona PWM has some unusual characteristics. Here are the main points. 29 + * 30 + * 1) There is no disable bit and the hardware docs advise programming a zero 31 + * duty to achieve output equivalent to that of a normal disable operation. 32 + * 33 + * 2) Changes to prescale, duty, period, and polarity do not take effect until 34 + * a subsequent rising edge of the trigger bit. 35 + * 36 + * 3) If the smooth bit and trigger bit are both low, the output is a constant 37 + * high signal. Otherwise, the earlier waveform continues to be output. 38 + * 39 + * 4) If the smooth bit is set on the rising edge of the trigger bit, output 40 + * will transition to the new settings on a period boundary (which could be 41 + * seconds away). If the smooth bit is clear, new settings will be applied 42 + * as soon as possible (the hardware always has a 400ns delay). 43 + * 44 + * 5) When the external clock that feeds the PWM is disabled, output is pegged 45 + * high or low depending on its state at that exact instant. 46 + */ 47 + 48 + #define PWM_CONTROL_OFFSET (0x00000000) 49 + #define PWM_CONTROL_SMOOTH_SHIFT(chan) (24 + (chan)) 50 + #define PWM_CONTROL_TYPE_SHIFT(chan) (16 + (chan)) 51 + #define PWM_CONTROL_POLARITY_SHIFT(chan) (8 + (chan)) 52 + #define PWM_CONTROL_TRIGGER_SHIFT(chan) (chan) 53 + 54 + #define PRESCALE_OFFSET (0x00000004) 55 + #define PRESCALE_SHIFT(chan) ((chan) << 2) 56 + #define PRESCALE_MASK(chan) (0x7 << PRESCALE_SHIFT(chan)) 57 + #define PRESCALE_MIN (0x00000000) 58 + #define PRESCALE_MAX (0x00000007) 59 + 60 + #define PERIOD_COUNT_OFFSET(chan) (0x00000008 + ((chan) << 3)) 61 + #define PERIOD_COUNT_MIN (0x00000002) 62 + #define PERIOD_COUNT_MAX (0x00ffffff) 63 + 64 + #define DUTY_CYCLE_HIGH_OFFSET(chan) (0x0000000c + ((chan) << 3)) 65 + #define DUTY_CYCLE_HIGH_MIN (0x00000000) 66 + #define DUTY_CYCLE_HIGH_MAX (0x00ffffff) 67 + 68 + struct kona_pwmc { 69 + struct pwm_chip chip; 70 + void __iomem *base; 71 + struct clk *clk; 72 + }; 73 + 74 + static inline struct kona_pwmc *to_kona_pwmc(struct pwm_chip *_chip) 75 + { 76 + return container_of(_chip, struct kona_pwmc, chip); 77 + } 78 + 79 + static void kona_pwmc_apply_settings(struct kona_pwmc *kp, unsigned int chan) 80 + { 81 + unsigned int value = readl(kp->base + PWM_CONTROL_OFFSET); 82 + 83 + /* Clear trigger bit but set smooth bit to maintain old output */ 84 + value |= 1 << PWM_CONTROL_SMOOTH_SHIFT(chan); 85 + value &= ~(1 << PWM_CONTROL_TRIGGER_SHIFT(chan)); 86 + writel(value, kp->base + PWM_CONTROL_OFFSET); 87 + 88 + /* Set trigger bit and clear smooth bit to apply new settings */ 89 + value &= ~(1 << PWM_CONTROL_SMOOTH_SHIFT(chan)); 90 + value |= 1 << PWM_CONTROL_TRIGGER_SHIFT(chan); 91 + writel(value, kp->base + PWM_CONTROL_OFFSET); 92 + } 93 + 94 + static int kona_pwmc_config(struct pwm_chip *chip, struct pwm_device *pwm, 95 + int duty_ns, int period_ns) 96 + { 97 + struct kona_pwmc *kp = to_kona_pwmc(chip); 98 + u64 val, div, rate; 99 + unsigned long prescale = PRESCALE_MIN, pc, dc; 100 + unsigned int value, chan = pwm->hwpwm; 101 + 102 + /* 103 + * Find period count, duty count and prescale to suit duty_ns and 104 + * period_ns. This is done according to formulas described below: 105 + * 106 + * period_ns = 10^9 * (PRESCALE + 1) * PC / PWM_CLK_RATE 107 + * duty_ns = 10^9 * (PRESCALE + 1) * DC / PWM_CLK_RATE 108 + * 109 + * PC = (PWM_CLK_RATE * period_ns) / (10^9 * (PRESCALE + 1)) 110 + * DC = (PWM_CLK_RATE * duty_ns) / (10^9 * (PRESCALE + 1)) 111 + */ 112 + 113 + rate = clk_get_rate(kp->clk); 114 + 115 + while (1) { 116 + div = 1000000000; 117 + div *= 1 + prescale; 118 + val = rate * period_ns; 119 + pc = div64_u64(val, div); 120 + val = rate * duty_ns; 121 + dc = div64_u64(val, div); 122 + 123 + /* If duty_ns or period_ns are not achievable then return */ 124 + if (pc < PERIOD_COUNT_MIN || dc < DUTY_CYCLE_HIGH_MIN) 125 + return -EINVAL; 126 + 127 + /* If pc and dc are in bounds, the calculation is done */ 128 + if (pc <= PERIOD_COUNT_MAX && dc <= DUTY_CYCLE_HIGH_MAX) 129 + break; 130 + 131 + /* Otherwise, increase prescale and recalculate pc and dc */ 132 + if (++prescale > PRESCALE_MAX) 133 + return -EINVAL; 134 + } 135 + 136 + /* If the PWM channel is enabled, write the settings to the HW */ 137 + if (test_bit(PWMF_ENABLED, &pwm->flags)) { 138 + value = readl(kp->base + PRESCALE_OFFSET); 139 + value &= ~PRESCALE_MASK(chan); 140 + value |= prescale << PRESCALE_SHIFT(chan); 141 + writel(value, kp->base + PRESCALE_OFFSET); 142 + 143 + writel(pc, kp->base + PERIOD_COUNT_OFFSET(chan)); 144 + 145 + writel(dc, kp->base + DUTY_CYCLE_HIGH_OFFSET(chan)); 146 + 147 + kona_pwmc_apply_settings(kp, chan); 148 + } 149 + 150 + return 0; 151 + } 152 + 153 + static int kona_pwmc_set_polarity(struct pwm_chip *chip, struct pwm_device *pwm, 154 + enum pwm_polarity polarity) 155 + { 156 + struct kona_pwmc *kp = to_kona_pwmc(chip); 157 + unsigned int chan = pwm->hwpwm; 158 + unsigned int value; 159 + int ret; 160 + 161 + ret = clk_prepare_enable(kp->clk); 162 + if (ret < 0) { 163 + dev_err(chip->dev, "failed to enable clock: %d\n", ret); 164 + return ret; 165 + } 166 + 167 + value = readl(kp->base + PWM_CONTROL_OFFSET); 168 + 169 + if (polarity == PWM_POLARITY_NORMAL) 170 + value |= 1 << PWM_CONTROL_POLARITY_SHIFT(chan); 171 + else 172 + value &= ~(1 << PWM_CONTROL_POLARITY_SHIFT(chan)); 173 + 174 + writel(value, kp->base + PWM_CONTROL_OFFSET); 175 + 176 + kona_pwmc_apply_settings(kp, chan); 177 + 178 + /* Wait for waveform to settle before gating off the clock */ 179 + ndelay(400); 180 + 181 + clk_disable_unprepare(kp->clk); 182 + 183 + return 0; 184 + } 185 + 186 + static int kona_pwmc_enable(struct pwm_chip *chip, struct pwm_device *pwm) 187 + { 188 + struct kona_pwmc *kp = to_kona_pwmc(chip); 189 + int ret; 190 + 191 + ret = clk_prepare_enable(kp->clk); 192 + if (ret < 0) { 193 + dev_err(chip->dev, "failed to enable clock: %d\n", ret); 194 + return ret; 195 + } 196 + 197 + ret = kona_pwmc_config(chip, pwm, pwm->duty_cycle, pwm->period); 198 + if (ret < 0) { 199 + clk_disable_unprepare(kp->clk); 200 + return ret; 201 + } 202 + 203 + return 0; 204 + } 205 + 206 + static void kona_pwmc_disable(struct pwm_chip *chip, struct pwm_device *pwm) 207 + { 208 + struct kona_pwmc *kp = to_kona_pwmc(chip); 209 + unsigned int chan = pwm->hwpwm; 210 + 211 + /* Simulate a disable by configuring for zero duty */ 212 + writel(0, kp->base + DUTY_CYCLE_HIGH_OFFSET(chan)); 213 + kona_pwmc_apply_settings(kp, chan); 214 + 215 + /* Wait for waveform to settle before gating off the clock */ 216 + ndelay(400); 217 + 218 + clk_disable_unprepare(kp->clk); 219 + } 220 + 221 + static const struct pwm_ops kona_pwm_ops = { 222 + .config = kona_pwmc_config, 223 + .set_polarity = kona_pwmc_set_polarity, 224 + .enable = kona_pwmc_enable, 225 + .disable = kona_pwmc_disable, 226 + .owner = THIS_MODULE, 227 + }; 228 + 229 + static int kona_pwmc_probe(struct platform_device *pdev) 230 + { 231 + struct kona_pwmc *kp; 232 + struct resource *res; 233 + unsigned int chan; 234 + unsigned int value = 0; 235 + int ret = 0; 236 + 237 + kp = devm_kzalloc(&pdev->dev, sizeof(*kp), GFP_KERNEL); 238 + if (kp == NULL) 239 + return -ENOMEM; 240 + 241 + platform_set_drvdata(pdev, kp); 242 + 243 + kp->chip.dev = &pdev->dev; 244 + kp->chip.ops = &kona_pwm_ops; 245 + kp->chip.base = -1; 246 + kp->chip.npwm = 6; 247 + kp->chip.of_xlate = of_pwm_xlate_with_flags; 248 + kp->chip.of_pwm_n_cells = 3; 249 + kp->chip.can_sleep = true; 250 + 251 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 252 + kp->base = devm_ioremap_resource(&pdev->dev, res); 253 + if (IS_ERR(kp->base)) 254 + return PTR_ERR(kp->base); 255 + 256 + kp->clk = devm_clk_get(&pdev->dev, NULL); 257 + if (IS_ERR(kp->clk)) { 258 + dev_err(&pdev->dev, "failed to get clock: %ld\n", 259 + PTR_ERR(kp->clk)); 260 + return PTR_ERR(kp->clk); 261 + } 262 + 263 + ret = clk_prepare_enable(kp->clk); 264 + if (ret < 0) { 265 + dev_err(&pdev->dev, "failed to enable clock: %d\n", ret); 266 + return ret; 267 + } 268 + 269 + /* Set smooth mode, push/pull, and normal polarity for all channels */ 270 + for (chan = 0; chan < kp->chip.npwm; chan++) { 271 + value |= (1 << PWM_CONTROL_SMOOTH_SHIFT(chan)); 272 + value |= (1 << PWM_CONTROL_TYPE_SHIFT(chan)); 273 + value |= (1 << PWM_CONTROL_POLARITY_SHIFT(chan)); 274 + } 275 + 276 + writel(value, kp->base + PWM_CONTROL_OFFSET); 277 + 278 + clk_disable_unprepare(kp->clk); 279 + 280 + ret = pwmchip_add(&kp->chip); 281 + if (ret < 0) 282 + dev_err(&pdev->dev, "failed to add PWM chip: %d\n", ret); 283 + 284 + return ret; 285 + } 286 + 287 + static int kona_pwmc_remove(struct platform_device *pdev) 288 + { 289 + struct kona_pwmc *kp = platform_get_drvdata(pdev); 290 + unsigned int chan; 291 + 292 + for (chan = 0; chan < kp->chip.npwm; chan++) 293 + if (test_bit(PWMF_ENABLED, &kp->chip.pwms[chan].flags)) 294 + clk_disable_unprepare(kp->clk); 295 + 296 + return pwmchip_remove(&kp->chip); 297 + } 298 + 299 + static const struct of_device_id bcm_kona_pwmc_dt[] = { 300 + { .compatible = "brcm,kona-pwm" }, 301 + { }, 302 + }; 303 + MODULE_DEVICE_TABLE(of, bcm_kona_pwmc_dt); 304 + 305 + static struct platform_driver kona_pwmc_driver = { 306 + .driver = { 307 + .name = "bcm-kona-pwm", 308 + .of_match_table = bcm_kona_pwmc_dt, 309 + }, 310 + .probe = kona_pwmc_probe, 311 + .remove = kona_pwmc_remove, 312 + }; 313 + module_platform_driver(kona_pwmc_driver); 314 + 315 + MODULE_AUTHOR("Broadcom Corporation <bcm-kernel-feedback-list@broadcom.com>"); 316 + MODULE_AUTHOR("Tim Kryger <tkryger@broadcom.com>"); 317 + MODULE_DESCRIPTION("Broadcom Kona PWM driver"); 318 + MODULE_LICENSE("GPL v2");
+1
drivers/pwm/pwm-fsl-ftm.c
··· 454 454 fpc->chip.of_pwm_n_cells = 3; 455 455 fpc->chip.base = -1; 456 456 fpc->chip.npwm = 8; 457 + fpc->chip.can_sleep = true; 457 458 458 459 ret = pwmchip_add(&fpc->chip); 459 460 if (ret < 0) {
+1 -3
drivers/pwm/pwm-imx.c
··· 241 241 return -ENODEV; 242 242 243 243 imx = devm_kzalloc(&pdev->dev, sizeof(*imx), GFP_KERNEL); 244 - if (imx == NULL) { 245 - dev_err(&pdev->dev, "failed to allocate memory\n"); 244 + if (imx == NULL) 246 245 return -ENOMEM; 247 - } 248 246 249 247 imx->clk_per = devm_clk_get(&pdev->dev, "per"); 250 248 if (IS_ERR(imx->clk_per)) {
+1
drivers/pwm/pwm-lp3943.c
··· 278 278 lp3943_pwm->chip.dev = &pdev->dev; 279 279 lp3943_pwm->chip.ops = &lp3943_pwm_ops; 280 280 lp3943_pwm->chip.npwm = LP3943_NUM_PWMS; 281 + lp3943_pwm->chip.can_sleep = true; 281 282 282 283 platform_set_drvdata(pdev, lp3943_pwm); 283 284
+129 -30
drivers/pwm/pwm-lpss.c
··· 6 6 * Author: Chew Kean Ho <kean.ho.chew@intel.com> 7 7 * Author: Chang Rebecca Swee Fun <rebecca.swee.fun.chang@intel.com> 8 8 * Author: Chew Chiau Ee <chiau.ee.chew@intel.com> 9 + * Author: Alan Cox <alan@linux.intel.com> 9 10 * 10 11 * This program is free software; you can redistribute it and/or modify 11 12 * it under the terms of the GNU General Public License version 2 as ··· 20 19 #include <linux/module.h> 21 20 #include <linux/pwm.h> 22 21 #include <linux/platform_device.h> 22 + #include <linux/pci.h> 23 + 24 + static int pci_drv, plat_drv; /* So we know which drivers registered */ 23 25 24 26 #define PWM 0x00000000 25 27 #define PWM_ENABLE BIT(31) ··· 38 34 struct pwm_chip chip; 39 35 void __iomem *regs; 40 36 struct clk *clk; 37 + unsigned long clk_rate; 38 + }; 39 + 40 + struct pwm_lpss_boardinfo { 41 + unsigned long clk_rate; 42 + }; 43 + 44 + /* BayTrail */ 45 + static const struct pwm_lpss_boardinfo byt_info = { 46 + 25000000 41 47 }; 42 48 43 49 static inline struct pwm_lpss_chip *to_lpwm(struct pwm_chip *chip) ··· 69 55 /* The equation is: base_unit = ((freq / c) * 65536) + correction */ 70 56 base_unit = freq * 65536; 71 57 72 - c = clk_get_rate(lpwm->clk); 58 + c = lpwm->clk_rate; 73 59 if (!c) 74 60 return -EINVAL; 75 61 ··· 127 113 .owner = THIS_MODULE, 128 114 }; 129 115 130 - static const struct acpi_device_id pwm_lpss_acpi_match[] = { 131 - { "80860F09", 0 }, 132 - { }, 133 - }; 134 - MODULE_DEVICE_TABLE(acpi, pwm_lpss_acpi_match); 135 - 136 - static int pwm_lpss_probe(struct platform_device *pdev) 116 + static struct pwm_lpss_chip *pwm_lpss_probe(struct device *dev, 117 + struct resource *r, 118 + const struct pwm_lpss_boardinfo *info) 137 119 { 138 120 struct pwm_lpss_chip *lpwm; 139 - struct resource *r; 140 121 int ret; 141 122 142 - lpwm = devm_kzalloc(&pdev->dev, sizeof(*lpwm), GFP_KERNEL); 123 + lpwm = devm_kzalloc(dev, sizeof(*lpwm), GFP_KERNEL); 143 124 if (!lpwm) 144 - return -ENOMEM; 125 + return ERR_PTR(-ENOMEM); 145 126 146 - r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 147 - 148 - lpwm->regs = devm_ioremap_resource(&pdev->dev, r); 127 + lpwm->regs = devm_ioremap_resource(dev, r); 149 128 if (IS_ERR(lpwm->regs)) 150 - return PTR_ERR(lpwm->regs); 129 + return ERR_CAST(lpwm->regs); 151 130 152 - lpwm->clk = devm_clk_get(&pdev->dev, NULL); 153 - if (IS_ERR(lpwm->clk)) { 154 - dev_err(&pdev->dev, "failed to get PWM clock\n"); 155 - return PTR_ERR(lpwm->clk); 131 + if (info) { 132 + lpwm->clk_rate = info->clk_rate; 133 + } else { 134 + lpwm->clk = devm_clk_get(dev, NULL); 135 + if (IS_ERR(lpwm->clk)) { 136 + dev_err(dev, "failed to get PWM clock\n"); 137 + return ERR_CAST(lpwm->clk); 138 + } 139 + lpwm->clk_rate = clk_get_rate(lpwm->clk); 156 140 } 157 141 158 - lpwm->chip.dev = &pdev->dev; 142 + lpwm->chip.dev = dev; 159 143 lpwm->chip.ops = &pwm_lpss_ops; 160 144 lpwm->chip.base = -1; 161 145 lpwm->chip.npwm = 1; 162 146 163 147 ret = pwmchip_add(&lpwm->chip); 164 148 if (ret) { 165 - dev_err(&pdev->dev, "failed to add PWM chip: %d\n", ret); 166 - return ret; 149 + dev_err(dev, "failed to add PWM chip: %d\n", ret); 150 + return ERR_PTR(ret); 167 151 } 168 152 169 - platform_set_drvdata(pdev, lpwm); 170 - return 0; 153 + return lpwm; 171 154 } 172 155 173 - static int pwm_lpss_remove(struct platform_device *pdev) 156 + static int pwm_lpss_remove(struct pwm_lpss_chip *lpwm) 174 157 { 175 - struct pwm_lpss_chip *lpwm = platform_get_drvdata(pdev); 176 158 u32 ctrl; 177 159 178 160 ctrl = readl(lpwm->regs + PWM); ··· 177 167 return pwmchip_remove(&lpwm->chip); 178 168 } 179 169 180 - static struct platform_driver pwm_lpss_driver = { 170 + static int pwm_lpss_probe_pci(struct pci_dev *pdev, 171 + const struct pci_device_id *id) 172 + { 173 + const struct pwm_lpss_boardinfo *info; 174 + struct pwm_lpss_chip *lpwm; 175 + int err; 176 + 177 + err = pci_enable_device(pdev); 178 + if (err < 0) 179 + return err; 180 + 181 + info = (struct pwm_lpss_boardinfo *)id->driver_data; 182 + lpwm = pwm_lpss_probe(&pdev->dev, &pdev->resource[0], info); 183 + if (IS_ERR(lpwm)) 184 + return PTR_ERR(lpwm); 185 + 186 + pci_set_drvdata(pdev, lpwm); 187 + return 0; 188 + } 189 + 190 + static void pwm_lpss_remove_pci(struct pci_dev *pdev) 191 + { 192 + struct pwm_lpss_chip *lpwm = pci_get_drvdata(pdev); 193 + 194 + pwm_lpss_remove(lpwm); 195 + pci_disable_device(pdev); 196 + } 197 + 198 + static struct pci_device_id pwm_lpss_pci_ids[] = { 199 + { PCI_VDEVICE(INTEL, 0x0f08), (unsigned long)&byt_info}, 200 + { PCI_VDEVICE(INTEL, 0x0f09), (unsigned long)&byt_info}, 201 + { }, 202 + }; 203 + MODULE_DEVICE_TABLE(pci, pwm_lpss_pci_ids); 204 + 205 + static struct pci_driver pwm_lpss_driver_pci = { 206 + .name = "pwm-lpss", 207 + .id_table = pwm_lpss_pci_ids, 208 + .probe = pwm_lpss_probe_pci, 209 + .remove = pwm_lpss_remove_pci, 210 + }; 211 + 212 + static int pwm_lpss_probe_platform(struct platform_device *pdev) 213 + { 214 + struct pwm_lpss_chip *lpwm; 215 + struct resource *r; 216 + 217 + r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 218 + 219 + lpwm = pwm_lpss_probe(&pdev->dev, r, NULL); 220 + if (IS_ERR(lpwm)) 221 + return PTR_ERR(lpwm); 222 + 223 + platform_set_drvdata(pdev, lpwm); 224 + return 0; 225 + } 226 + 227 + static int pwm_lpss_remove_platform(struct platform_device *pdev) 228 + { 229 + struct pwm_lpss_chip *lpwm = platform_get_drvdata(pdev); 230 + 231 + return pwm_lpss_remove(lpwm); 232 + } 233 + 234 + static const struct acpi_device_id pwm_lpss_acpi_match[] = { 235 + { "80860F09", 0 }, 236 + { }, 237 + }; 238 + MODULE_DEVICE_TABLE(acpi, pwm_lpss_acpi_match); 239 + 240 + static struct platform_driver pwm_lpss_driver_platform = { 181 241 .driver = { 182 242 .name = "pwm-lpss", 183 243 .acpi_match_table = pwm_lpss_acpi_match, 184 244 }, 185 - .probe = pwm_lpss_probe, 186 - .remove = pwm_lpss_remove, 245 + .probe = pwm_lpss_probe_platform, 246 + .remove = pwm_lpss_remove_platform, 187 247 }; 188 - module_platform_driver(pwm_lpss_driver); 248 + 249 + static int __init pwm_init(void) 250 + { 251 + pci_drv = pci_register_driver(&pwm_lpss_driver_pci); 252 + plat_drv = platform_driver_register(&pwm_lpss_driver_platform); 253 + if (pci_drv && plat_drv) 254 + return pci_drv; 255 + 256 + return 0; 257 + } 258 + module_init(pwm_init); 259 + 260 + static void __exit pwm_exit(void) 261 + { 262 + if (!pci_drv) 263 + pci_unregister_driver(&pwm_lpss_driver_pci); 264 + if (!plat_drv) 265 + platform_driver_unregister(&pwm_lpss_driver_platform); 266 + } 267 + module_exit(pwm_exit); 189 268 190 269 MODULE_DESCRIPTION("PWM driver for Intel LPSS"); 191 270 MODULE_AUTHOR("Mika Westerberg <mika.westerberg@linux.intel.com>");
+1
drivers/pwm/pwm-mxs.c
··· 147 147 mxs->chip.dev = &pdev->dev; 148 148 mxs->chip.ops = &mxs_pwm_ops; 149 149 mxs->chip.base = -1; 150 + mxs->chip.can_sleep = true; 150 151 ret = of_property_read_u32(np, "fsl,pwm-number", &mxs->chip.npwm); 151 152 if (ret < 0) { 152 153 dev_err(&pdev->dev, "failed to get pwm number: %d\n", ret);
+1 -3
drivers/pwm/pwm-pxa.c
··· 179 179 return -EINVAL; 180 180 181 181 pwm = devm_kzalloc(&pdev->dev, sizeof(*pwm), GFP_KERNEL); 182 - if (pwm == NULL) { 183 - dev_err(&pdev->dev, "failed to allocate memory\n"); 182 + if (pwm == NULL) 184 183 return -ENOMEM; 185 - } 186 184 187 185 pwm->clk = devm_clk_get(&pdev->dev, NULL); 188 186 if (IS_ERR(pwm->clk))
+4 -19
drivers/pwm/pwm-renesas-tpu.c
··· 21 21 #include <linux/module.h> 22 22 #include <linux/mutex.h> 23 23 #include <linux/of.h> 24 - #include <linux/platform_data/pwm-renesas-tpu.h> 25 24 #include <linux/platform_device.h> 26 25 #include <linux/pm_runtime.h> 27 26 #include <linux/pwm.h> 28 27 #include <linux/slab.h> 29 28 #include <linux/spinlock.h> 29 + 30 + #define TPU_CHANNEL_MAX 4 30 31 31 32 #define TPU_TSTR 0x00 /* Timer start register (shared) */ 32 33 ··· 88 87 89 88 struct tpu_device { 90 89 struct platform_device *pdev; 91 - enum pwm_polarity polarities[TPU_CHANNEL_MAX]; 92 90 struct pwm_chip chip; 93 91 spinlock_t lock; 94 92 ··· 229 229 230 230 pwm->tpu = tpu; 231 231 pwm->channel = _pwm->hwpwm; 232 - pwm->polarity = tpu->polarities[pwm->channel]; 232 + pwm->polarity = PWM_POLARITY_NORMAL; 233 233 pwm->prescaler = 0; 234 234 pwm->period = 0; 235 235 pwm->duty = 0; ··· 388 388 * Probe and remove 389 389 */ 390 390 391 - static void tpu_parse_pdata(struct tpu_device *tpu) 392 - { 393 - struct tpu_pwm_platform_data *pdata = tpu->pdev->dev.platform_data; 394 - unsigned int i; 395 - 396 - for (i = 0; i < ARRAY_SIZE(tpu->polarities); ++i) 397 - tpu->polarities[i] = pdata ? pdata->channels[i].polarity 398 - : PWM_POLARITY_NORMAL; 399 - } 400 - 401 391 static int tpu_probe(struct platform_device *pdev) 402 392 { 403 393 struct tpu_device *tpu; ··· 395 405 int ret; 396 406 397 407 tpu = devm_kzalloc(&pdev->dev, sizeof(*tpu), GFP_KERNEL); 398 - if (tpu == NULL) { 399 - dev_err(&pdev->dev, "failed to allocate driver data\n"); 408 + if (tpu == NULL) 400 409 return -ENOMEM; 401 - } 402 410 403 411 spin_lock_init(&tpu->lock); 404 412 tpu->pdev = pdev; 405 - 406 - /* Initialize device configuration from platform data. */ 407 - tpu_parse_pdata(tpu); 408 413 409 414 /* Map memory, get clock and pin control. */ 410 415 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-3
drivers/pwm/pwm-samsung.c
··· 335 335 writel(tcnt, our_chip->base + REG_TCNTB(pwm->hwpwm)); 336 336 writel(tcmp, our_chip->base + REG_TCMPB(pwm->hwpwm)); 337 337 338 - if (test_bit(PWMF_ENABLED, &pwm->flags)) 339 - pwm_samsung_enable(chip, pwm); 340 - 341 338 chan->period_ns = period_ns; 342 339 chan->tin_ns = tin_ns; 343 340 chan->duty_ns = duty_ns;
+2 -4
drivers/pwm/pwm-spear.c
··· 179 179 u32 val; 180 180 181 181 pc = devm_kzalloc(&pdev->dev, sizeof(*pc), GFP_KERNEL); 182 - if (!pc) { 183 - dev_err(&pdev->dev, "failed to allocate memory\n"); 182 + if (!pc) 184 183 return -ENOMEM; 185 - } 186 184 187 185 r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 188 186 pc->mmio_base = devm_ioremap_resource(&pdev->dev, r); ··· 220 222 } 221 223 222 224 ret = pwmchip_add(&pc->chip); 223 - if (!ret) { 225 + if (ret < 0) { 224 226 clk_unprepare(pc->clk); 225 227 dev_err(&pdev->dev, "pwmchip_add() failed: %d\n", ret); 226 228 }
+1 -3
drivers/pwm/pwm-tegra.c
··· 173 173 int ret; 174 174 175 175 pwm = devm_kzalloc(&pdev->dev, sizeof(*pwm), GFP_KERNEL); 176 - if (!pwm) { 177 - dev_err(&pdev->dev, "failed to allocate memory\n"); 176 + if (!pwm) 178 177 return -ENOMEM; 179 - } 180 178 181 179 pwm->dev = &pdev->dev; 182 180
+1 -3
drivers/pwm/pwm-tiecap.c
··· 209 209 u16 status; 210 210 211 211 pc = devm_kzalloc(&pdev->dev, sizeof(*pc), GFP_KERNEL); 212 - if (!pc) { 213 - dev_err(&pdev->dev, "failed to allocate memory\n"); 212 + if (!pc) 214 213 return -ENOMEM; 215 - } 216 214 217 215 clk = devm_clk_get(&pdev->dev, "fck"); 218 216 if (IS_ERR(clk)) {
+4 -6
drivers/pwm/pwm-tiehrpwm.c
··· 138 138 return container_of(chip, struct ehrpwm_pwm_chip, chip); 139 139 } 140 140 141 - static u16 ehrpwm_read(void __iomem *base, int offset) 141 + static inline u16 ehrpwm_read(void __iomem *base, int offset) 142 142 { 143 143 return readw(base + offset); 144 144 } 145 145 146 - static void ehrpwm_write(void __iomem *base, int offset, unsigned int val) 146 + static inline void ehrpwm_write(void __iomem *base, int offset, unsigned int val) 147 147 { 148 148 writew(val & 0xFFFF, base + offset); 149 149 } ··· 440 440 u16 status; 441 441 442 442 pc = devm_kzalloc(&pdev->dev, sizeof(*pc), GFP_KERNEL); 443 - if (!pc) { 444 - dev_err(&pdev->dev, "failed to allocate memory\n"); 443 + if (!pc) 445 444 return -ENOMEM; 446 - } 447 445 448 446 clk = devm_clk_get(&pdev->dev, "fck"); 449 447 if (IS_ERR(clk)) { ··· 529 531 return pwmchip_remove(&pc->chip); 530 532 } 531 533 534 + #ifdef CONFIG_PM_SLEEP 532 535 static void ehrpwm_pwm_save_context(struct ehrpwm_pwm_chip *pc) 533 536 { 534 537 pm_runtime_get_sync(pc->chip.dev); ··· 556 557 ehrpwm_write(pc->mmio_base, TBCTL, pc->ctx.tbctl); 557 558 } 558 559 559 - #ifdef CONFIG_PM_SLEEP 560 560 static int ehrpwm_pwm_suspend(struct device *dev) 561 561 { 562 562 struct ehrpwm_pwm_chip *pc = dev_get_drvdata(dev);
-8
drivers/pwm/pwm-twl.c
··· 265 265 266 266 ret = twl_i2c_write_u8(TWL6030_MODULE_ID1, val, TWL6030_TOGGLE3_REG); 267 267 if (ret < 0) { 268 - dev_err(chip->dev, "%s: Failed to read TOGGLE3\n", pwm->label); 269 - goto out; 270 - } 271 - 272 - val |= TWL6030_PWM_TOGGLE(pwm->hwpwm, TWL6030_PWMXS | TWL6030_PWMXEN); 273 - 274 - ret = twl_i2c_write_u8(TWL6030_MODULE_ID1, val, TWL6030_TOGGLE3_REG); 275 - if (ret < 0) { 276 268 dev_err(chip->dev, "%s: Failed to disable PWM\n", pwm->label); 277 269 goto out; 278 270 }
+1 -3
drivers/pwm/pwm-vt8500.c
··· 211 211 } 212 212 213 213 chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL); 214 - if (chip == NULL) { 215 - dev_err(&pdev->dev, "failed to allocate memory\n"); 214 + if (chip == NULL) 216 215 return -ENOMEM; 217 - } 218 216 219 217 chip->chip.dev = &pdev->dev; 220 218 chip->chip.ops = &vt8500_pwm_ops;
+45 -44
drivers/video/backlight/pwm_bl.c
··· 10 10 * published by the Free Software Foundation. 11 11 */ 12 12 13 + #include <linux/gpio/consumer.h> 13 14 #include <linux/gpio.h> 14 - #include <linux/of_gpio.h> 15 15 #include <linux/module.h> 16 16 #include <linux/kernel.h> 17 17 #include <linux/init.h> ··· 32 32 unsigned int *levels; 33 33 bool enabled; 34 34 struct regulator *power_supply; 35 - int enable_gpio; 36 - unsigned long enable_gpio_flags; 35 + struct gpio_desc *enable_gpio; 37 36 unsigned int scale; 38 37 int (*notify)(struct device *, 39 38 int brightness); ··· 53 54 if (err < 0) 54 55 dev_err(pb->dev, "failed to enable power supply\n"); 55 56 56 - if (gpio_is_valid(pb->enable_gpio)) { 57 - if (pb->enable_gpio_flags & PWM_BACKLIGHT_GPIO_ACTIVE_LOW) 58 - gpio_set_value(pb->enable_gpio, 0); 59 - else 60 - gpio_set_value(pb->enable_gpio, 1); 61 - } 57 + if (pb->enable_gpio) 58 + gpiod_set_value(pb->enable_gpio, 1); 62 59 63 60 pwm_enable(pb->pwm); 64 61 pb->enabled = true; ··· 68 73 pwm_config(pb->pwm, 0, pb->period); 69 74 pwm_disable(pb->pwm); 70 75 71 - if (gpio_is_valid(pb->enable_gpio)) { 72 - if (pb->enable_gpio_flags & PWM_BACKLIGHT_GPIO_ACTIVE_LOW) 73 - gpio_set_value(pb->enable_gpio, 1); 74 - else 75 - gpio_set_value(pb->enable_gpio, 0); 76 - } 76 + if (pb->enable_gpio) 77 + gpiod_set_value(pb->enable_gpio, 0); 77 78 78 79 regulator_disable(pb->power_supply); 79 80 pb->enabled = false; ··· 139 148 struct platform_pwm_backlight_data *data) 140 149 { 141 150 struct device_node *node = dev->of_node; 142 - enum of_gpio_flags flags; 143 151 struct property *prop; 144 152 int length; 145 153 u32 value; ··· 178 188 data->dft_brightness = value; 179 189 data->max_brightness--; 180 190 } 181 - 182 - data->enable_gpio = of_get_named_gpio_flags(node, "enable-gpios", 0, 183 - &flags); 184 - if (data->enable_gpio == -EPROBE_DEFER) 185 - return -EPROBE_DEFER; 186 - 187 - if (gpio_is_valid(data->enable_gpio) && (flags & OF_GPIO_ACTIVE_LOW)) 188 - data->enable_gpio_flags |= PWM_BACKLIGHT_GPIO_ACTIVE_LOW; 189 191 190 192 return 0; 191 193 } ··· 238 256 } else 239 257 pb->scale = data->max_brightness; 240 258 241 - pb->enable_gpio = data->enable_gpio; 242 - pb->enable_gpio_flags = data->enable_gpio_flags; 243 259 pb->notify = data->notify; 244 260 pb->notify_after = data->notify_after; 245 261 pb->check_fb = data->check_fb; ··· 245 265 pb->dev = &pdev->dev; 246 266 pb->enabled = false; 247 267 248 - if (gpio_is_valid(pb->enable_gpio)) { 249 - unsigned long flags; 250 - 251 - if (pb->enable_gpio_flags & PWM_BACKLIGHT_GPIO_ACTIVE_LOW) 252 - flags = GPIOF_OUT_INIT_HIGH; 268 + pb->enable_gpio = devm_gpiod_get(&pdev->dev, "enable"); 269 + if (IS_ERR(pb->enable_gpio)) { 270 + ret = PTR_ERR(pb->enable_gpio); 271 + if (ret == -ENOENT) 272 + pb->enable_gpio = NULL; 253 273 else 254 - flags = GPIOF_OUT_INIT_LOW; 274 + goto err_alloc; 275 + } 255 276 256 - ret = gpio_request_one(pb->enable_gpio, flags, "enable"); 277 + /* 278 + * Compatibility fallback for drivers still using the integer GPIO 279 + * platform data. Must go away soon. 280 + */ 281 + if (!pb->enable_gpio && gpio_is_valid(data->enable_gpio)) { 282 + ret = devm_gpio_request_one(&pdev->dev, data->enable_gpio, 283 + GPIOF_OUT_INIT_HIGH, "enable"); 257 284 if (ret < 0) { 258 285 dev_err(&pdev->dev, "failed to request GPIO#%d: %d\n", 259 - pb->enable_gpio, ret); 286 + data->enable_gpio, ret); 260 287 goto err_alloc; 261 288 } 289 + 290 + pb->enable_gpio = gpio_to_desc(data->enable_gpio); 262 291 } 292 + 293 + if (pb->enable_gpio) 294 + gpiod_direction_output(pb->enable_gpio, 1); 263 295 264 296 pb->power_supply = devm_regulator_get(&pdev->dev, "power"); 265 297 if (IS_ERR(pb->power_supply)) { 266 298 ret = PTR_ERR(pb->power_supply); 267 - goto err_gpio; 299 + goto err_alloc; 268 300 } 269 301 270 302 pb->pwm = devm_pwm_get(&pdev->dev, NULL); ··· 287 295 if (IS_ERR(pb->pwm)) { 288 296 dev_err(&pdev->dev, "unable to request legacy PWM\n"); 289 297 ret = PTR_ERR(pb->pwm); 290 - goto err_gpio; 298 + goto err_alloc; 291 299 } 292 300 } 293 301 ··· 296 304 /* 297 305 * The DT case will set the pwm_period_ns field to 0 and store the 298 306 * period, parsed from the DT, in the PWM device. For the non-DT case, 299 - * set the period from platform data. 307 + * set the period from platform data if it has not already been set 308 + * via the PWM lookup table. 300 309 */ 301 - if (data->pwm_period_ns > 0) 302 - pwm_set_period(pb->pwm, data->pwm_period_ns); 303 - 304 310 pb->period = pwm_get_period(pb->pwm); 311 + if (!pb->period && (data->pwm_period_ns > 0)) { 312 + pb->period = data->pwm_period_ns; 313 + pwm_set_period(pb->pwm, data->pwm_period_ns); 314 + } 315 + 305 316 pb->lth_brightness = data->lth_brightness * (pb->period / pb->scale); 306 317 307 318 memset(&props, 0, sizeof(struct backlight_properties)); ··· 315 320 if (IS_ERR(bl)) { 316 321 dev_err(&pdev->dev, "failed to register backlight\n"); 317 322 ret = PTR_ERR(bl); 318 - goto err_gpio; 323 + goto err_alloc; 319 324 } 320 325 321 326 if (data->dft_brightness > data->max_brightness) { ··· 331 336 platform_set_drvdata(pdev, bl); 332 337 return 0; 333 338 334 - err_gpio: 335 - if (gpio_is_valid(pb->enable_gpio)) 336 - gpio_free(pb->enable_gpio); 337 339 err_alloc: 338 340 if (data->exit) 339 341 data->exit(&pdev->dev); ··· 349 357 pb->exit(&pdev->dev); 350 358 351 359 return 0; 360 + } 361 + 362 + static void pwm_backlight_shutdown(struct platform_device *pdev) 363 + { 364 + struct backlight_device *bl = platform_get_drvdata(pdev); 365 + struct pwm_bl_data *pb = bl_get_data(bl); 366 + 367 + pwm_backlight_power_off(pb); 352 368 } 353 369 354 370 #ifdef CONFIG_PM_SLEEP ··· 404 404 }, 405 405 .probe = pwm_backlight_probe, 406 406 .remove = pwm_backlight_remove, 407 + .shutdown = pwm_backlight_shutdown, 407 408 }; 408 409 409 410 module_platform_driver(pwm_backlight_driver);
-16
include/linux/platform_data/pwm-renesas-tpu.h
··· 1 - #ifndef __PWM_RENESAS_TPU_H__ 2 - #define __PWM_RENESAS_TPU_H__ 3 - 4 - #include <linux/pwm.h> 5 - 6 - #define TPU_CHANNEL_MAX 4 7 - 8 - struct tpu_pwm_channel_data { 9 - enum pwm_polarity polarity; 10 - }; 11 - 12 - struct tpu_pwm_platform_data { 13 - struct tpu_pwm_channel_data channels[TPU_CHANNEL_MAX]; 14 - }; 15 - 16 - #endif /* __PWM_RENESAS_TPU_H__ */
+5 -1
include/linux/pwm.h
··· 274 274 unsigned int index; 275 275 const char *dev_id; 276 276 const char *con_id; 277 + unsigned int period; 278 + enum pwm_polarity polarity; 277 279 }; 278 280 279 - #define PWM_LOOKUP(_provider, _index, _dev_id, _con_id) \ 281 + #define PWM_LOOKUP(_provider, _index, _dev_id, _con_id, _period, _polarity) \ 280 282 { \ 281 283 .provider = _provider, \ 282 284 .index = _index, \ 283 285 .dev_id = _dev_id, \ 284 286 .con_id = _con_id, \ 287 + .period = _period, \ 288 + .polarity = _polarity \ 285 289 } 286 290 287 291 #if IS_ENABLED(CONFIG_PWM)
+1 -4
include/linux/pwm_backlight.h
··· 6 6 7 7 #include <linux/backlight.h> 8 8 9 - /* TODO: convert to gpiod_*() API once it has been merged */ 10 - #define PWM_BACKLIGHT_GPIO_ACTIVE_LOW (1 << 0) 11 - 12 9 struct platform_pwm_backlight_data { 13 10 int pwm_id; 14 11 unsigned int max_brightness; ··· 13 16 unsigned int lth_brightness; 14 17 unsigned int pwm_period_ns; 15 18 unsigned int *levels; 19 + /* TODO remove once all users are switched to gpiod_* API */ 16 20 int enable_gpio; 17 - unsigned long enable_gpio_flags; 18 21 int (*init)(struct device *dev); 19 22 int (*notify)(struct device *dev, int brightness); 20 23 void (*notify_after)(struct device *dev, int brightness);