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

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

Pull pwm updates from Thierry Reding:
"This contains a few fixes and a bunch of cleanups, a lot of which is
in preparation for Uwe's character device support that may be ready in
time for the next merge window"

* tag 'pwm/for-6.7-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/thierry.reding/linux-pwm: (37 commits)
pwm: samsung: Document new member .channel in struct samsung_pwm_chip
pwm: bcm2835: Add support for suspend/resume
pwm: brcmstb: Checked clk_prepare_enable() return value
pwm: brcmstb: Utilize appropriate clock APIs in suspend/resume
pwm: pxa: Explicitly include correct DT includes
pwm: cros-ec: Simplify using devm_pwmchip_add() and dev_err_probe()
pwm: samsung: Consistently use the same name for driver data
pwm: vt8500: Simplify using devm functions
pwm: sprd: Simplify using devm_pwmchip_add() and dev_err_probe()
pwm: sprd: Provide a helper to cast a chip to driver data
pwm: spear: Simplify using devm functions
pwm: mtk-disp: Simplify using devm_pwmchip_add()
pwm: imx-tpm: Simplify using devm functions
pwm: brcmstb: Simplify using devm functions
pwm: bcm2835: Simplify using devm functions
pwm: bcm-iproc: Simplify using devm functions
pwm: Adapt sysfs API documentation to reality
pwm: dwc: add PWM bit unset in get_state call
pwm: dwc: make timer clock configurable
pwm: dwc: split pci out of core driver
...

+537 -776
+11 -2
Documentation/devicetree/bindings/pwm/mxs-pwm.yaml
··· 15 15 16 16 properties: 17 17 compatible: 18 - enum: 19 - - fsl,imx23-pwm 18 + oneOf: 19 + - const: fsl,imx23-pwm 20 + - items: 21 + - enum: 22 + - fsl,imx28-pwm 23 + - const: fsl,imx23-pwm 20 24 21 25 reg: 26 + maxItems: 1 27 + 28 + clocks: 22 29 maxItems: 1 23 30 24 31 "#pwm-cells": ··· 38 31 required: 39 32 - compatible 40 33 - reg 34 + - clocks 41 35 - fsl,pwm-number 42 36 43 37 additionalProperties: false ··· 48 40 pwm@80064000 { 49 41 compatible = "fsl,imx23-pwm"; 50 42 reg = <0x80064000 0x2000>; 43 + clocks = <&clks 30>; 51 44 #pwm-cells = <3>; 52 45 fsl,pwm-number = <8>; 53 46 };
-1
drivers/gpio/gpio-mvebu.c
··· 757 757 .free = mvebu_pwm_free, 758 758 .get_state = mvebu_pwm_get_state, 759 759 .apply = mvebu_pwm_apply, 760 - .owner = THIS_MODULE, 761 760 }; 762 761 763 762 static void __maybe_unused mvebu_pwm_suspend(struct mvebu_gpio_chip *mvchip)
-1
drivers/gpu/drm/bridge/ti-sn65dsi86.c
··· 1580 1580 .free = ti_sn_pwm_free, 1581 1581 .apply = ti_sn_pwm_apply, 1582 1582 .get_state = ti_sn_pwm_get_state, 1583 - .owner = THIS_MODULE, 1584 1583 }; 1585 1584 1586 1585 static int ti_sn_pwm_probe(struct auxiliary_device *adev,
-1
drivers/leds/rgb/leds-qcom-lpg.c
··· 1085 1085 .request = lpg_pwm_request, 1086 1086 .apply = lpg_pwm_apply, 1087 1087 .get_state = lpg_pwm_get_state, 1088 - .owner = THIS_MODULE, 1089 1088 }; 1090 1089 1091 1090 static int lpg_add_pwm(struct lpg *lpg)
+15 -5
drivers/pwm/Kconfig
··· 173 173 will be called pwm-clps711x. 174 174 175 175 config PWM_CRC 176 - bool "Intel Crystalcove (CRC) PWM support" 177 - depends on X86 && INTEL_SOC_PMIC 176 + tristate "Intel Crystalcove (CRC) PWM support" 177 + depends on INTEL_SOC_PMIC 178 178 help 179 179 Generic PWM framework driver for Crystalcove (CRC) PMIC based PWM 180 180 control. ··· 186 186 PWM driver for exposing a PWM attached to the ChromeOS Embedded 187 187 Controller. 188 188 189 + config PWM_DWC_CORE 190 + tristate 191 + depends on HAS_IOMEM 192 + help 193 + PWM driver for Synopsys DWC PWM Controller. 194 + 195 + To compile this driver as a module, build the dependecies as 196 + modules, this will be called pwm-dwc-core. 197 + 189 198 config PWM_DWC 190 - tristate "DesignWare PWM Controller" 191 - depends on PCI 199 + tristate "DesignWare PWM Controller (PCI bus)" 200 + depends on HAS_IOMEM && PCI 201 + select PWM_DWC_CORE 192 202 help 193 203 PWM driver for Synopsys DWC PWM Controller attached to a PCI bus. 194 204 ··· 417 407 418 408 config PWM_MICROCHIP_CORE 419 409 tristate "Microchip corePWM PWM support" 420 - depends on SOC_MICROCHIP_POLARFIRE || COMPILE_TEST 410 + depends on ARCH_MICROCHIP_POLARFIRE || COMPILE_TEST 421 411 depends on HAS_IOMEM && OF 422 412 help 423 413 PWM driver for Microchip FPGA soft IP core.
+1
drivers/pwm/Makefile
··· 15 15 obj-$(CONFIG_PWM_CLPS711X) += pwm-clps711x.o 16 16 obj-$(CONFIG_PWM_CRC) += pwm-crc.o 17 17 obj-$(CONFIG_PWM_CROS_EC) += pwm-cros-ec.o 18 + obj-$(CONFIG_PWM_DWC_CORE) += pwm-dwc-core.o 18 19 obj-$(CONFIG_PWM_DWC) += pwm-dwc.o 19 20 obj-$(CONFIG_PWM_EP93XX) += pwm-ep93xx.o 20 21 obj-$(CONFIG_PWM_FSL_FTM) += pwm-fsl-ftm.o
+14 -41
drivers/pwm/core.c
··· 89 89 if (test_bit(PWMF_REQUESTED, &pwm->flags)) 90 90 return -EBUSY; 91 91 92 - if (!try_module_get(pwm->chip->ops->owner)) 92 + if (!try_module_get(pwm->chip->owner)) 93 93 return -ENODEV; 94 94 95 95 if (pwm->chip->ops->request) { 96 96 err = pwm->chip->ops->request(pwm->chip, pwm); 97 97 if (err) { 98 - module_put(pwm->chip->ops->owner); 98 + module_put(pwm->chip->owner); 99 99 return err; 100 100 } 101 101 } ··· 208 208 of_node_put(chip->dev->of_node); 209 209 } 210 210 211 - /** 212 - * pwm_set_chip_data() - set private chip data for a PWM 213 - * @pwm: PWM device 214 - * @data: pointer to chip-specific data 215 - * 216 - * Returns: 0 on success or a negative error code on failure. 217 - */ 218 - int pwm_set_chip_data(struct pwm_device *pwm, void *data) 219 - { 220 - if (!pwm) 221 - return -EINVAL; 222 - 223 - pwm->chip_data = data; 224 - 225 - return 0; 226 - } 227 - EXPORT_SYMBOL_GPL(pwm_set_chip_data); 228 - 229 - /** 230 - * pwm_get_chip_data() - get private chip data for a PWM 231 - * @pwm: PWM device 232 - * 233 - * Returns: A pointer to the chip-private data for the PWM device. 234 - */ 235 - void *pwm_get_chip_data(struct pwm_device *pwm) 236 - { 237 - return pwm ? pwm->chip_data : NULL; 238 - } 239 - EXPORT_SYMBOL_GPL(pwm_get_chip_data); 240 - 241 211 static bool pwm_ops_check(const struct pwm_chip *chip) 242 212 { 243 213 const struct pwm_ops *ops = chip->ops; ··· 223 253 } 224 254 225 255 /** 226 - * pwmchip_add() - register a new PWM chip 256 + * __pwmchip_add() - register a new PWM chip 227 257 * @chip: the PWM chip to add 258 + * @owner: reference to the module providing the chip. 228 259 * 229 - * Register a new PWM chip. 260 + * Register a new PWM chip. @owner is supposed to be THIS_MODULE, use the 261 + * pwmchip_add wrapper to do this right. 230 262 * 231 263 * Returns: 0 on success or a negative error code on failure. 232 264 */ 233 - int pwmchip_add(struct pwm_chip *chip) 265 + int __pwmchip_add(struct pwm_chip *chip, struct module *owner) 234 266 { 235 267 struct pwm_device *pwm; 236 268 unsigned int i; ··· 243 271 244 272 if (!pwm_ops_check(chip)) 245 273 return -EINVAL; 274 + 275 + chip->owner = owner; 246 276 247 277 chip->pwms = kcalloc(chip->npwm, sizeof(*pwm), GFP_KERNEL); 248 278 if (!chip->pwms) ··· 280 306 281 307 return 0; 282 308 } 283 - EXPORT_SYMBOL_GPL(pwmchip_add); 309 + EXPORT_SYMBOL_GPL(__pwmchip_add); 284 310 285 311 /** 286 312 * pwmchip_remove() - remove a PWM chip ··· 312 338 pwmchip_remove(chip); 313 339 } 314 340 315 - int devm_pwmchip_add(struct device *dev, struct pwm_chip *chip) 341 + int __devm_pwmchip_add(struct device *dev, struct pwm_chip *chip, struct module *owner) 316 342 { 317 343 int ret; 318 344 319 - ret = pwmchip_add(chip); 345 + ret = __pwmchip_add(chip, owner); 320 346 if (ret) 321 347 return ret; 322 348 323 349 return devm_add_action_or_reset(dev, devm_pwmchip_remove, chip); 324 350 } 325 - EXPORT_SYMBOL_GPL(devm_pwmchip_add); 351 + EXPORT_SYMBOL_GPL(__devm_pwmchip_add); 326 352 327 353 /** 328 354 * pwm_request_from_chip() - request a PWM device relative to a PWM chip ··· 950 976 if (pwm->chip->ops->free) 951 977 pwm->chip->ops->free(pwm->chip, pwm); 952 978 953 - pwm_set_chip_data(pwm, NULL); 954 979 pwm->label = NULL; 955 980 956 - module_put(pwm->chip->ops->owner); 981 + module_put(pwm->chip->owner); 957 982 out: 958 983 mutex_unlock(&pwm_lock); 959 984 }
-1
drivers/pwm/pwm-ab8500.c
··· 181 181 static const struct pwm_ops ab8500_pwm_ops = { 182 182 .apply = ab8500_pwm_apply, 183 183 .get_state = ab8500_pwm_get_state, 184 - .owner = THIS_MODULE, 185 184 }; 186 185 187 186 static int ab8500_pwm_probe(struct platform_device *pdev)
-1
drivers/pwm/pwm-apple.c
··· 99 99 static const struct pwm_ops apple_pwm_ops = { 100 100 .apply = apple_pwm_apply, 101 101 .get_state = apple_pwm_get_state, 102 - .owner = THIS_MODULE, 103 102 }; 104 103 105 104 static int apple_pwm_probe(struct platform_device *pdev)
-1
drivers/pwm/pwm-atmel-hlcdc.c
··· 170 170 171 171 static const struct pwm_ops atmel_hlcdc_pwm_ops = { 172 172 .apply = atmel_hlcdc_pwm_apply, 173 - .owner = THIS_MODULE, 174 173 }; 175 174 176 175 static const struct atmel_hlcdc_pwm_errata atmel_hlcdc_pwm_at91sam9x5_errata = {
-1
drivers/pwm/pwm-atmel-tcb.c
··· 364 364 .request = atmel_tcb_pwm_request, 365 365 .free = atmel_tcb_pwm_free, 366 366 .apply = atmel_tcb_pwm_apply, 367 - .owner = THIS_MODULE, 368 367 }; 369 368 370 369 static struct atmel_tcb_config tcb_rm9200_config = {
+1 -2
drivers/pwm/pwm-atmel.c
··· 402 402 static const struct pwm_ops atmel_pwm_ops = { 403 403 .apply = atmel_pwm_apply, 404 404 .get_state = atmel_pwm_get_state, 405 - .owner = THIS_MODULE, 406 405 }; 407 406 408 407 static const struct atmel_pwm_data atmel_sam9rl_pwm_data = { ··· 546 547 static struct platform_driver atmel_pwm_driver = { 547 548 .driver = { 548 549 .name = "atmel-pwm", 549 - .of_match_table = of_match_ptr(atmel_pwm_dt_ids), 550 + .of_match_table = atmel_pwm_dt_ids, 550 551 }, 551 552 .probe = atmel_pwm_probe, 552 553 };
+9 -29
drivers/pwm/pwm-bcm-iproc.c
··· 183 183 static const struct pwm_ops iproc_pwm_ops = { 184 184 .apply = iproc_pwmc_apply, 185 185 .get_state = iproc_pwmc_get_state, 186 - .owner = THIS_MODULE, 187 186 }; 188 187 189 188 static int iproc_pwmc_probe(struct platform_device *pdev) ··· 206 207 if (IS_ERR(ip->base)) 207 208 return PTR_ERR(ip->base); 208 209 209 - ip->clk = devm_clk_get(&pdev->dev, NULL); 210 - if (IS_ERR(ip->clk)) { 211 - dev_err(&pdev->dev, "failed to get clock: %ld\n", 212 - PTR_ERR(ip->clk)); 213 - return PTR_ERR(ip->clk); 214 - } 215 - 216 - ret = clk_prepare_enable(ip->clk); 217 - if (ret < 0) { 218 - dev_err(&pdev->dev, "failed to enable clock: %d\n", ret); 219 - return ret; 220 - } 210 + ip->clk = devm_clk_get_enabled(&pdev->dev, NULL); 211 + if (IS_ERR(ip->clk)) 212 + return dev_err_probe(&pdev->dev, PTR_ERR(ip->clk), 213 + "failed to get clock\n"); 221 214 222 215 /* Set full drive and normal polarity for all channels */ 223 216 value = readl(ip->base + IPROC_PWM_CTRL_OFFSET); ··· 221 230 222 231 writel(value, ip->base + IPROC_PWM_CTRL_OFFSET); 223 232 224 - ret = pwmchip_add(&ip->chip); 225 - if (ret < 0) { 226 - dev_err(&pdev->dev, "failed to add PWM chip: %d\n", ret); 227 - clk_disable_unprepare(ip->clk); 228 - } 233 + ret = devm_pwmchip_add(&pdev->dev, &ip->chip); 234 + if (ret < 0) 235 + return dev_err_probe(&pdev->dev, ret, 236 + "failed to add PWM chip\n"); 229 237 230 - return ret; 231 - } 232 - 233 - static void iproc_pwmc_remove(struct platform_device *pdev) 234 - { 235 - struct iproc_pwmc *ip = platform_get_drvdata(pdev); 236 - 237 - pwmchip_remove(&ip->chip); 238 - 239 - clk_disable_unprepare(ip->clk); 238 + return 0; 240 239 } 241 240 242 241 static const struct of_device_id bcm_iproc_pwmc_dt[] = { ··· 241 260 .of_match_table = bcm_iproc_pwmc_dt, 242 261 }, 243 262 .probe = iproc_pwmc_probe, 244 - .remove_new = iproc_pwmc_remove, 245 263 }; 246 264 module_platform_driver(iproc_pwmc_driver); 247 265
-1
drivers/pwm/pwm-bcm-kona.c
··· 269 269 270 270 static const struct pwm_ops kona_pwm_ops = { 271 271 .apply = kona_pwmc_apply, 272 - .owner = THIS_MODULE, 273 272 }; 274 273 275 274 static int kona_pwmc_probe(struct platform_device *pdev)
+19 -19
drivers/pwm/pwm-bcm2835.c
··· 129 129 .request = bcm2835_pwm_request, 130 130 .free = bcm2835_pwm_free, 131 131 .apply = bcm2835_pwm_apply, 132 - .owner = THIS_MODULE, 133 132 }; 134 133 135 134 static int bcm2835_pwm_probe(struct platform_device *pdev) ··· 146 147 if (IS_ERR(pc->base)) 147 148 return PTR_ERR(pc->base); 148 149 149 - pc->clk = devm_clk_get(&pdev->dev, NULL); 150 + pc->clk = devm_clk_get_enabled(&pdev->dev, NULL); 150 151 if (IS_ERR(pc->clk)) 151 152 return dev_err_probe(&pdev->dev, PTR_ERR(pc->clk), 152 153 "clock not found\n"); 153 - 154 - ret = clk_prepare_enable(pc->clk); 155 - if (ret) 156 - return ret; 157 154 158 155 pc->chip.dev = &pdev->dev; 159 156 pc->chip.ops = &bcm2835_pwm_ops; 160 157 pc->chip.npwm = 2; 161 158 162 - platform_set_drvdata(pdev, pc); 163 - 164 - ret = pwmchip_add(&pc->chip); 159 + ret = devm_pwmchip_add(&pdev->dev, &pc->chip); 165 160 if (ret < 0) 166 - goto add_fail; 161 + return dev_err_probe(&pdev->dev, ret, 162 + "failed to add pwmchip\n"); 167 163 168 164 return 0; 169 - 170 - add_fail: 171 - clk_disable_unprepare(pc->clk); 172 - return ret; 173 165 } 174 166 175 - static void bcm2835_pwm_remove(struct platform_device *pdev) 167 + static int bcm2835_pwm_suspend(struct device *dev) 176 168 { 177 - struct bcm2835_pwm *pc = platform_get_drvdata(pdev); 178 - 179 - pwmchip_remove(&pc->chip); 169 + struct bcm2835_pwm *pc = dev_get_drvdata(dev); 180 170 181 171 clk_disable_unprepare(pc->clk); 172 + 173 + return 0; 182 174 } 175 + 176 + static int bcm2835_pwm_resume(struct device *dev) 177 + { 178 + struct bcm2835_pwm *pc = dev_get_drvdata(dev); 179 + 180 + return clk_prepare_enable(pc->clk); 181 + } 182 + 183 + static DEFINE_SIMPLE_DEV_PM_OPS(bcm2835_pwm_pm_ops, bcm2835_pwm_suspend, 184 + bcm2835_pwm_resume); 183 185 184 186 static const struct of_device_id bcm2835_pwm_of_match[] = { 185 187 { .compatible = "brcm,bcm2835-pwm", }, ··· 192 192 .driver = { 193 193 .name = "bcm2835-pwm", 194 194 .of_match_table = bcm2835_pwm_of_match, 195 + .pm = pm_ptr(&bcm2835_pwm_pm_ops), 195 196 }, 196 197 .probe = bcm2835_pwm_probe, 197 - .remove_new = bcm2835_pwm_remove, 198 198 }; 199 199 module_platform_driver(bcm2835_pwm_driver); 200 200
+10 -53
drivers/pwm/pwm-berlin.c
··· 39 39 #define BERLIN_PWM_TCNT 0xc 40 40 #define BERLIN_PWM_MAX_TCNT 65535 41 41 42 + #define BERLIN_PWM_NUMPWMS 4 43 + 42 44 struct berlin_pwm_channel { 43 45 u32 enable; 44 46 u32 ctrl; ··· 52 50 struct pwm_chip chip; 53 51 struct clk *clk; 54 52 void __iomem *base; 53 + struct berlin_pwm_channel channel[BERLIN_PWM_NUMPWMS]; 55 54 }; 56 55 57 56 static inline struct berlin_pwm_chip *to_berlin_pwm_chip(struct pwm_chip *chip) ··· 71 68 unsigned long offset) 72 69 { 73 70 writel_relaxed(value, bpc->base + channel * 0x10 + offset); 74 - } 75 - 76 - static int berlin_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm) 77 - { 78 - struct berlin_pwm_channel *channel; 79 - 80 - channel = kzalloc(sizeof(*channel), GFP_KERNEL); 81 - if (!channel) 82 - return -ENOMEM; 83 - 84 - return pwm_set_chip_data(pwm, channel); 85 - } 86 - 87 - static void berlin_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm) 88 - { 89 - struct berlin_pwm_channel *channel = pwm_get_chip_data(pwm); 90 - 91 - kfree(channel); 92 71 } 93 72 94 73 static int berlin_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, ··· 187 202 } 188 203 189 204 static const struct pwm_ops berlin_pwm_ops = { 190 - .request = berlin_pwm_request, 191 - .free = berlin_pwm_free, 192 205 .apply = berlin_pwm_apply, 193 - .owner = THIS_MODULE, 194 206 }; 195 207 196 208 static const struct of_device_id berlin_pwm_match[] = { ··· 209 227 if (IS_ERR(bpc->base)) 210 228 return PTR_ERR(bpc->base); 211 229 212 - bpc->clk = devm_clk_get(&pdev->dev, NULL); 230 + bpc->clk = devm_clk_get_enabled(&pdev->dev, NULL); 213 231 if (IS_ERR(bpc->clk)) 214 232 return PTR_ERR(bpc->clk); 215 233 216 - ret = clk_prepare_enable(bpc->clk); 217 - if (ret) 218 - return ret; 219 - 220 234 bpc->chip.dev = &pdev->dev; 221 235 bpc->chip.ops = &berlin_pwm_ops; 222 - bpc->chip.npwm = 4; 236 + bpc->chip.npwm = BERLIN_PWM_NUMPWMS; 223 237 224 - ret = pwmchip_add(&bpc->chip); 225 - if (ret < 0) { 226 - dev_err(&pdev->dev, "failed to add PWM chip: %d\n", ret); 227 - clk_disable_unprepare(bpc->clk); 228 - return ret; 229 - } 238 + ret = devm_pwmchip_add(&pdev->dev, &bpc->chip); 239 + if (ret < 0) 240 + return dev_err_probe(&pdev->dev, ret, "failed to add PWM chip\n"); 230 241 231 242 platform_set_drvdata(pdev, bpc); 232 243 233 244 return 0; 234 - } 235 - 236 - static void berlin_pwm_remove(struct platform_device *pdev) 237 - { 238 - struct berlin_pwm_chip *bpc = platform_get_drvdata(pdev); 239 - 240 - pwmchip_remove(&bpc->chip); 241 - 242 - clk_disable_unprepare(bpc->clk); 243 245 } 244 246 245 247 #ifdef CONFIG_PM_SLEEP ··· 233 267 unsigned int i; 234 268 235 269 for (i = 0; i < bpc->chip.npwm; i++) { 236 - struct berlin_pwm_channel *channel; 237 - 238 - channel = pwm_get_chip_data(&bpc->chip.pwms[i]); 239 - if (!channel) 240 - continue; 270 + struct berlin_pwm_channel *channel = &bpc->channel[i]; 241 271 242 272 channel->enable = berlin_pwm_readl(bpc, i, BERLIN_PWM_ENABLE); 243 273 channel->ctrl = berlin_pwm_readl(bpc, i, BERLIN_PWM_CONTROL); ··· 257 295 return ret; 258 296 259 297 for (i = 0; i < bpc->chip.npwm; i++) { 260 - struct berlin_pwm_channel *channel; 261 - 262 - channel = pwm_get_chip_data(&bpc->chip.pwms[i]); 263 - if (!channel) 264 - continue; 298 + struct berlin_pwm_channel *channel = &bpc->channel[i]; 265 299 266 300 berlin_pwm_writel(bpc, i, channel->ctrl, BERLIN_PWM_CONTROL); 267 301 berlin_pwm_writel(bpc, i, channel->duty, BERLIN_PWM_DUTY); ··· 274 316 275 317 static struct platform_driver berlin_pwm_driver = { 276 318 .probe = berlin_pwm_probe, 277 - .remove_new = berlin_pwm_remove, 278 319 .driver = { 279 320 .name = "berlin-pwm", 280 321 .of_match_table = berlin_pwm_match,
+11 -38
drivers/pwm/pwm-brcmstb.c
··· 220 220 221 221 static const struct pwm_ops brcmstb_pwm_ops = { 222 222 .apply = brcmstb_pwm_apply, 223 - .owner = THIS_MODULE, 224 223 }; 225 224 226 225 static const struct of_device_id brcmstb_pwm_of_match[] = { ··· 237 238 if (!p) 238 239 return -ENOMEM; 239 240 240 - p->clk = devm_clk_get(&pdev->dev, NULL); 241 - if (IS_ERR(p->clk)) { 242 - dev_err(&pdev->dev, "failed to obtain clock\n"); 243 - return PTR_ERR(p->clk); 244 - } 245 - 246 - ret = clk_prepare_enable(p->clk); 247 - if (ret < 0) { 248 - dev_err(&pdev->dev, "failed to enable clock: %d\n", ret); 249 - return ret; 250 - } 241 + p->clk = devm_clk_get_enabled(&pdev->dev, NULL); 242 + if (IS_ERR(p->clk)) 243 + return dev_err_probe(&pdev->dev, PTR_ERR(p->clk), 244 + "failed to obtain clock\n"); 251 245 252 246 platform_set_drvdata(pdev, p); 253 247 ··· 249 257 p->chip.npwm = 2; 250 258 251 259 p->base = devm_platform_ioremap_resource(pdev, 0); 252 - if (IS_ERR(p->base)) { 253 - ret = PTR_ERR(p->base); 254 - goto out_clk; 255 - } 260 + if (IS_ERR(p->base)) 261 + return PTR_ERR(p->base); 256 262 257 - ret = pwmchip_add(&p->chip); 258 - if (ret) { 259 - dev_err(&pdev->dev, "failed to add PWM chip: %d\n", ret); 260 - goto out_clk; 261 - } 263 + ret = devm_pwmchip_add(&pdev->dev, &p->chip); 264 + if (ret) 265 + return dev_err_probe(&pdev->dev, ret, "failed to add PWM chip\n"); 262 266 263 267 return 0; 264 - 265 - out_clk: 266 - clk_disable_unprepare(p->clk); 267 - return ret; 268 - } 269 - 270 - static void brcmstb_pwm_remove(struct platform_device *pdev) 271 - { 272 - struct brcmstb_pwm *p = platform_get_drvdata(pdev); 273 - 274 - pwmchip_remove(&p->chip); 275 - clk_disable_unprepare(p->clk); 276 268 } 277 269 278 270 #ifdef CONFIG_PM_SLEEP ··· 264 288 { 265 289 struct brcmstb_pwm *p = dev_get_drvdata(dev); 266 290 267 - clk_disable(p->clk); 291 + clk_disable_unprepare(p->clk); 268 292 269 293 return 0; 270 294 } ··· 273 297 { 274 298 struct brcmstb_pwm *p = dev_get_drvdata(dev); 275 299 276 - clk_enable(p->clk); 277 - 278 - return 0; 300 + return clk_prepare_enable(p->clk); 279 301 } 280 302 #endif 281 303 ··· 282 308 283 309 static struct platform_driver brcmstb_pwm_driver = { 284 310 .probe = brcmstb_pwm_probe, 285 - .remove_new = brcmstb_pwm_remove, 286 311 .driver = { 287 312 .name = "pwm-brcmstb", 288 313 .of_match_table = brcmstb_pwm_of_match,
-1
drivers/pwm/pwm-clk.c
··· 77 77 78 78 static const struct pwm_ops pwm_clk_ops = { 79 79 .apply = pwm_clk_apply, 80 - .owner = THIS_MODULE, 81 80 }; 82 81 83 82 static int pwm_clk_probe(struct platform_device *pdev)
-1
drivers/pwm/pwm-clps711x.c
··· 72 72 static const struct pwm_ops clps711x_pwm_ops = { 73 73 .request = clps711x_pwm_request, 74 74 .apply = clps711x_pwm_apply, 75 - .owner = THIS_MODULE, 76 75 }; 77 76 78 77 static struct pwm_device *clps711x_pwm_xlate(struct pwm_chip *chip,
+4 -1
drivers/pwm/pwm-crc.c
··· 184 184 .name = "crystal_cove_pwm", 185 185 }, 186 186 }; 187 + module_platform_driver(crystalcove_pwm_driver); 187 188 188 - builtin_platform_driver(crystalcove_pwm_driver); 189 + MODULE_ALIAS("platform:crystal_cove_pwm"); 190 + MODULE_DESCRIPTION("Intel Crystalcove (CRC) PWM support"); 191 + MODULE_LICENSE("GPL");
+17 -50
drivers/pwm/pwm-cros-ec.c
··· 22 22 * @ec: Pointer to EC device 23 23 * @chip: PWM controller chip 24 24 * @use_pwm_type: Use PWM types instead of generic channels 25 + * @channel: array with per-channel data 25 26 */ 26 27 struct cros_ec_pwm_device { 27 28 struct device *dev; 28 29 struct cros_ec_device *ec; 29 30 struct pwm_chip chip; 30 31 bool use_pwm_type; 32 + struct cros_ec_pwm *channel; 31 33 }; 32 34 33 35 /** ··· 43 41 static inline struct cros_ec_pwm_device *pwm_to_cros_ec_pwm(struct pwm_chip *chip) 44 42 { 45 43 return container_of(chip, struct cros_ec_pwm_device, chip); 46 - } 47 - 48 - static int cros_ec_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm) 49 - { 50 - struct cros_ec_pwm *channel; 51 - 52 - channel = kzalloc(sizeof(*channel), GFP_KERNEL); 53 - if (!channel) 54 - return -ENOMEM; 55 - 56 - pwm_set_chip_data(pwm, channel); 57 - 58 - return 0; 59 - } 60 - 61 - static void cros_ec_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm) 62 - { 63 - struct cros_ec_pwm *channel = pwm_get_chip_data(pwm); 64 - 65 - kfree(channel); 66 44 } 67 45 68 46 static int cros_ec_dt_type_to_pwm_type(u8 dt_index, u8 *pwm_type) ··· 140 158 const struct pwm_state *state) 141 159 { 142 160 struct cros_ec_pwm_device *ec_pwm = pwm_to_cros_ec_pwm(chip); 143 - struct cros_ec_pwm *channel = pwm_get_chip_data(pwm); 161 + struct cros_ec_pwm *channel = &ec_pwm->channel[pwm->hwpwm]; 144 162 u16 duty_cycle; 145 163 int ret; 146 164 ··· 170 188 struct pwm_state *state) 171 189 { 172 190 struct cros_ec_pwm_device *ec_pwm = pwm_to_cros_ec_pwm(chip); 173 - struct cros_ec_pwm *channel = pwm_get_chip_data(pwm); 191 + struct cros_ec_pwm *channel = &ec_pwm->channel[pwm->hwpwm]; 174 192 int ret; 175 193 176 194 ret = cros_ec_pwm_get_duty(ec_pwm, pwm->hwpwm); ··· 219 237 } 220 238 221 239 static const struct pwm_ops cros_ec_pwm_ops = { 222 - .request = cros_ec_pwm_request, 223 - .free = cros_ec_pwm_free, 224 240 .get_state = cros_ec_pwm_get_state, 225 241 .apply = cros_ec_pwm_apply, 226 - .owner = THIS_MODULE, 227 242 }; 228 243 229 244 /* ··· 265 286 struct pwm_chip *chip; 266 287 int ret; 267 288 268 - if (!ec) { 269 - dev_err(dev, "no parent EC device\n"); 270 - return -EINVAL; 271 - } 289 + if (!ec) 290 + return dev_err_probe(dev, -EINVAL, "no parent EC device\n"); 272 291 273 292 ec_pwm = devm_kzalloc(dev, sizeof(*ec_pwm), GFP_KERNEL); 274 293 if (!ec_pwm) ··· 287 310 chip->npwm = CROS_EC_PWM_DT_COUNT; 288 311 } else { 289 312 ret = cros_ec_num_pwms(ec_pwm); 290 - if (ret < 0) { 291 - dev_err(dev, "Couldn't find PWMs: %d\n", ret); 292 - return ret; 293 - } 313 + if (ret < 0) 314 + return dev_err_probe(dev, ret, "Couldn't find PWMs\n"); 294 315 chip->npwm = ret; 295 316 } 296 317 318 + ec_pwm->channel = devm_kcalloc(dev, chip->npwm, sizeof(*ec_pwm->channel), 319 + GFP_KERNEL); 320 + if (!ec_pwm->channel) 321 + return -ENOMEM; 322 + 297 323 dev_dbg(dev, "Probed %u PWMs\n", chip->npwm); 298 324 299 - ret = pwmchip_add(chip); 300 - if (ret < 0) { 301 - dev_err(dev, "cannot register PWM: %d\n", ret); 302 - return ret; 303 - } 325 + ret = devm_pwmchip_add(dev, chip); 326 + if (ret < 0) 327 + return dev_err_probe(dev, ret, "cannot register PWM\n"); 304 328 305 - platform_set_drvdata(pdev, ec_pwm); 306 - 307 - return ret; 308 - } 309 - 310 - static void cros_ec_pwm_remove(struct platform_device *dev) 311 - { 312 - struct cros_ec_pwm_device *ec_pwm = platform_get_drvdata(dev); 313 - struct pwm_chip *chip = &ec_pwm->chip; 314 - 315 - pwmchip_remove(chip); 329 + return 0; 316 330 } 317 331 318 332 #ifdef CONFIG_OF ··· 317 349 318 350 static struct platform_driver cros_ec_pwm_driver = { 319 351 .probe = cros_ec_pwm_probe, 320 - .remove_new = cros_ec_pwm_remove, 321 352 .driver = { 322 353 .name = "cros-ec-pwm", 323 354 .of_match_table = of_match_ptr(cros_ec_pwm_of_match),
+184
drivers/pwm/pwm-dwc-core.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * DesignWare PWM Controller driver core 4 + * 5 + * Copyright (C) 2018-2020 Intel Corporation 6 + * 7 + * Author: Felipe Balbi (Intel) 8 + * Author: Jarkko Nikula <jarkko.nikula@linux.intel.com> 9 + * Author: Raymond Tan <raymond.tan@intel.com> 10 + */ 11 + 12 + #define DEFAULT_SYMBOL_NAMESPACE dwc_pwm 13 + 14 + #include <linux/bitops.h> 15 + #include <linux/export.h> 16 + #include <linux/kernel.h> 17 + #include <linux/module.h> 18 + #include <linux/pci.h> 19 + #include <linux/pm_runtime.h> 20 + #include <linux/pwm.h> 21 + 22 + #include "pwm-dwc.h" 23 + 24 + static void __dwc_pwm_set_enable(struct dwc_pwm *dwc, int pwm, int enabled) 25 + { 26 + u32 reg; 27 + 28 + reg = dwc_pwm_readl(dwc, DWC_TIM_CTRL(pwm)); 29 + 30 + if (enabled) 31 + reg |= DWC_TIM_CTRL_EN; 32 + else 33 + reg &= ~DWC_TIM_CTRL_EN; 34 + 35 + dwc_pwm_writel(dwc, reg, DWC_TIM_CTRL(pwm)); 36 + } 37 + 38 + static int __dwc_pwm_configure_timer(struct dwc_pwm *dwc, 39 + struct pwm_device *pwm, 40 + const struct pwm_state *state) 41 + { 42 + u64 tmp; 43 + u32 ctrl; 44 + u32 high; 45 + u32 low; 46 + 47 + /* 48 + * Calculate width of low and high period in terms of input clock 49 + * periods and check are the result within HW limits between 1 and 50 + * 2^32 periods. 51 + */ 52 + tmp = DIV_ROUND_CLOSEST_ULL(state->duty_cycle, dwc->clk_ns); 53 + if (tmp < 1 || tmp > (1ULL << 32)) 54 + return -ERANGE; 55 + low = tmp - 1; 56 + 57 + tmp = DIV_ROUND_CLOSEST_ULL(state->period - state->duty_cycle, 58 + dwc->clk_ns); 59 + if (tmp < 1 || tmp > (1ULL << 32)) 60 + return -ERANGE; 61 + high = tmp - 1; 62 + 63 + /* 64 + * Specification says timer usage flow is to disable timer, then 65 + * program it followed by enable. It also says Load Count is loaded 66 + * into timer after it is enabled - either after a disable or 67 + * a reset. Based on measurements it happens also without disable 68 + * whenever Load Count is updated. But follow the specification. 69 + */ 70 + __dwc_pwm_set_enable(dwc, pwm->hwpwm, false); 71 + 72 + /* 73 + * Write Load Count and Load Count 2 registers. Former defines the 74 + * width of low period and latter the width of high period in terms 75 + * multiple of input clock periods: 76 + * Width = ((Count + 1) * input clock period). 77 + */ 78 + dwc_pwm_writel(dwc, low, DWC_TIM_LD_CNT(pwm->hwpwm)); 79 + dwc_pwm_writel(dwc, high, DWC_TIM_LD_CNT2(pwm->hwpwm)); 80 + 81 + /* 82 + * Set user-defined mode, timer reloads from Load Count registers 83 + * when it counts down to 0. 84 + * Set PWM mode, it makes output to toggle and width of low and high 85 + * periods are set by Load Count registers. 86 + */ 87 + ctrl = DWC_TIM_CTRL_MODE_USER | DWC_TIM_CTRL_PWM; 88 + dwc_pwm_writel(dwc, ctrl, DWC_TIM_CTRL(pwm->hwpwm)); 89 + 90 + /* 91 + * Enable timer. Output starts from low period. 92 + */ 93 + __dwc_pwm_set_enable(dwc, pwm->hwpwm, state->enabled); 94 + 95 + return 0; 96 + } 97 + 98 + static int dwc_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, 99 + const struct pwm_state *state) 100 + { 101 + struct dwc_pwm *dwc = to_dwc_pwm(chip); 102 + 103 + if (state->polarity != PWM_POLARITY_INVERSED) 104 + return -EINVAL; 105 + 106 + if (state->enabled) { 107 + if (!pwm->state.enabled) 108 + pm_runtime_get_sync(chip->dev); 109 + return __dwc_pwm_configure_timer(dwc, pwm, state); 110 + } else { 111 + if (pwm->state.enabled) { 112 + __dwc_pwm_set_enable(dwc, pwm->hwpwm, false); 113 + pm_runtime_put_sync(chip->dev); 114 + } 115 + } 116 + 117 + return 0; 118 + } 119 + 120 + static int dwc_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm, 121 + struct pwm_state *state) 122 + { 123 + struct dwc_pwm *dwc = to_dwc_pwm(chip); 124 + u64 duty, period; 125 + u32 ctrl, ld, ld2; 126 + 127 + pm_runtime_get_sync(chip->dev); 128 + 129 + ctrl = dwc_pwm_readl(dwc, DWC_TIM_CTRL(pwm->hwpwm)); 130 + ld = dwc_pwm_readl(dwc, DWC_TIM_LD_CNT(pwm->hwpwm)); 131 + ld2 = dwc_pwm_readl(dwc, DWC_TIM_LD_CNT2(pwm->hwpwm)); 132 + 133 + state->enabled = !!(ctrl & DWC_TIM_CTRL_EN); 134 + 135 + /* 136 + * If we're not in PWM, technically the output is a 50-50 137 + * based on the timer load-count only. 138 + */ 139 + if (ctrl & DWC_TIM_CTRL_PWM) { 140 + duty = (ld + 1) * dwc->clk_ns; 141 + period = (ld2 + 1) * dwc->clk_ns; 142 + period += duty; 143 + } else { 144 + duty = (ld + 1) * dwc->clk_ns; 145 + period = duty * 2; 146 + } 147 + 148 + state->polarity = PWM_POLARITY_INVERSED; 149 + state->period = period; 150 + state->duty_cycle = duty; 151 + 152 + pm_runtime_put_sync(chip->dev); 153 + 154 + return 0; 155 + } 156 + 157 + static const struct pwm_ops dwc_pwm_ops = { 158 + .apply = dwc_pwm_apply, 159 + .get_state = dwc_pwm_get_state, 160 + }; 161 + 162 + struct dwc_pwm *dwc_pwm_alloc(struct device *dev) 163 + { 164 + struct dwc_pwm *dwc; 165 + 166 + dwc = devm_kzalloc(dev, sizeof(*dwc), GFP_KERNEL); 167 + if (!dwc) 168 + return NULL; 169 + 170 + dwc->clk_ns = 10; 171 + dwc->chip.dev = dev; 172 + dwc->chip.ops = &dwc_pwm_ops; 173 + dwc->chip.npwm = DWC_TIMERS_TOTAL; 174 + 175 + dev_set_drvdata(dev, dwc); 176 + return dwc; 177 + } 178 + EXPORT_SYMBOL_GPL(dwc_pwm_alloc); 179 + 180 + MODULE_AUTHOR("Felipe Balbi (Intel)"); 181 + MODULE_AUTHOR("Jarkko Nikula <jarkko.nikula@linux.intel.com>"); 182 + MODULE_AUTHOR("Raymond Tan <raymond.tan@intel.com>"); 183 + MODULE_DESCRIPTION("DesignWare PWM Controller"); 184 + MODULE_LICENSE("GPL");
+4 -193
drivers/pwm/pwm-dwc.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 /* 3 - * DesignWare PWM Controller driver 3 + * DesignWare PWM Controller driver (PCI part) 4 4 * 5 5 * Copyright (C) 2018-2020 Intel Corporation 6 6 * ··· 13 13 * periods are one or more input clock periods long. 14 14 */ 15 15 16 + #define DEFAULT_MOUDLE_NAMESPACE dwc_pwm 17 + 16 18 #include <linux/bitops.h> 17 19 #include <linux/export.h> 18 20 #include <linux/kernel.h> ··· 23 21 #include <linux/pm_runtime.h> 24 22 #include <linux/pwm.h> 25 23 26 - #define DWC_TIM_LD_CNT(n) ((n) * 0x14) 27 - #define DWC_TIM_LD_CNT2(n) (((n) * 4) + 0xb0) 28 - #define DWC_TIM_CUR_VAL(n) (((n) * 0x14) + 0x04) 29 - #define DWC_TIM_CTRL(n) (((n) * 0x14) + 0x08) 30 - #define DWC_TIM_EOI(n) (((n) * 0x14) + 0x0c) 31 - #define DWC_TIM_INT_STS(n) (((n) * 0x14) + 0x10) 32 - 33 - #define DWC_TIMERS_INT_STS 0xa0 34 - #define DWC_TIMERS_EOI 0xa4 35 - #define DWC_TIMERS_RAW_INT_STS 0xa8 36 - #define DWC_TIMERS_COMP_VERSION 0xac 37 - 38 - #define DWC_TIMERS_TOTAL 8 39 - #define DWC_CLK_PERIOD_NS 10 40 - 41 - /* Timer Control Register */ 42 - #define DWC_TIM_CTRL_EN BIT(0) 43 - #define DWC_TIM_CTRL_MODE BIT(1) 44 - #define DWC_TIM_CTRL_MODE_FREE (0 << 1) 45 - #define DWC_TIM_CTRL_MODE_USER (1 << 1) 46 - #define DWC_TIM_CTRL_INT_MASK BIT(2) 47 - #define DWC_TIM_CTRL_PWM BIT(3) 48 - 49 - struct dwc_pwm_ctx { 50 - u32 cnt; 51 - u32 cnt2; 52 - u32 ctrl; 53 - }; 54 - 55 - struct dwc_pwm { 56 - struct pwm_chip chip; 57 - void __iomem *base; 58 - struct dwc_pwm_ctx ctx[DWC_TIMERS_TOTAL]; 59 - }; 60 - #define to_dwc_pwm(p) (container_of((p), struct dwc_pwm, chip)) 61 - 62 - static inline u32 dwc_pwm_readl(struct dwc_pwm *dwc, u32 offset) 63 - { 64 - return readl(dwc->base + offset); 65 - } 66 - 67 - static inline void dwc_pwm_writel(struct dwc_pwm *dwc, u32 value, u32 offset) 68 - { 69 - writel(value, dwc->base + offset); 70 - } 71 - 72 - static void __dwc_pwm_set_enable(struct dwc_pwm *dwc, int pwm, int enabled) 73 - { 74 - u32 reg; 75 - 76 - reg = dwc_pwm_readl(dwc, DWC_TIM_CTRL(pwm)); 77 - 78 - if (enabled) 79 - reg |= DWC_TIM_CTRL_EN; 80 - else 81 - reg &= ~DWC_TIM_CTRL_EN; 82 - 83 - dwc_pwm_writel(dwc, reg, DWC_TIM_CTRL(pwm)); 84 - } 85 - 86 - static int __dwc_pwm_configure_timer(struct dwc_pwm *dwc, 87 - struct pwm_device *pwm, 88 - const struct pwm_state *state) 89 - { 90 - u64 tmp; 91 - u32 ctrl; 92 - u32 high; 93 - u32 low; 94 - 95 - /* 96 - * Calculate width of low and high period in terms of input clock 97 - * periods and check are the result within HW limits between 1 and 98 - * 2^32 periods. 99 - */ 100 - tmp = DIV_ROUND_CLOSEST_ULL(state->duty_cycle, DWC_CLK_PERIOD_NS); 101 - if (tmp < 1 || tmp > (1ULL << 32)) 102 - return -ERANGE; 103 - low = tmp - 1; 104 - 105 - tmp = DIV_ROUND_CLOSEST_ULL(state->period - state->duty_cycle, 106 - DWC_CLK_PERIOD_NS); 107 - if (tmp < 1 || tmp > (1ULL << 32)) 108 - return -ERANGE; 109 - high = tmp - 1; 110 - 111 - /* 112 - * Specification says timer usage flow is to disable timer, then 113 - * program it followed by enable. It also says Load Count is loaded 114 - * into timer after it is enabled - either after a disable or 115 - * a reset. Based on measurements it happens also without disable 116 - * whenever Load Count is updated. But follow the specification. 117 - */ 118 - __dwc_pwm_set_enable(dwc, pwm->hwpwm, false); 119 - 120 - /* 121 - * Write Load Count and Load Count 2 registers. Former defines the 122 - * width of low period and latter the width of high period in terms 123 - * multiple of input clock periods: 124 - * Width = ((Count + 1) * input clock period). 125 - */ 126 - dwc_pwm_writel(dwc, low, DWC_TIM_LD_CNT(pwm->hwpwm)); 127 - dwc_pwm_writel(dwc, high, DWC_TIM_LD_CNT2(pwm->hwpwm)); 128 - 129 - /* 130 - * Set user-defined mode, timer reloads from Load Count registers 131 - * when it counts down to 0. 132 - * Set PWM mode, it makes output to toggle and width of low and high 133 - * periods are set by Load Count registers. 134 - */ 135 - ctrl = DWC_TIM_CTRL_MODE_USER | DWC_TIM_CTRL_PWM; 136 - dwc_pwm_writel(dwc, ctrl, DWC_TIM_CTRL(pwm->hwpwm)); 137 - 138 - /* 139 - * Enable timer. Output starts from low period. 140 - */ 141 - __dwc_pwm_set_enable(dwc, pwm->hwpwm, state->enabled); 142 - 143 - return 0; 144 - } 145 - 146 - static int dwc_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, 147 - const struct pwm_state *state) 148 - { 149 - struct dwc_pwm *dwc = to_dwc_pwm(chip); 150 - 151 - if (state->polarity != PWM_POLARITY_INVERSED) 152 - return -EINVAL; 153 - 154 - if (state->enabled) { 155 - if (!pwm->state.enabled) 156 - pm_runtime_get_sync(chip->dev); 157 - return __dwc_pwm_configure_timer(dwc, pwm, state); 158 - } else { 159 - if (pwm->state.enabled) { 160 - __dwc_pwm_set_enable(dwc, pwm->hwpwm, false); 161 - pm_runtime_put_sync(chip->dev); 162 - } 163 - } 164 - 165 - return 0; 166 - } 167 - 168 - static int dwc_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm, 169 - struct pwm_state *state) 170 - { 171 - struct dwc_pwm *dwc = to_dwc_pwm(chip); 172 - u64 duty, period; 173 - 174 - pm_runtime_get_sync(chip->dev); 175 - 176 - state->enabled = !!(dwc_pwm_readl(dwc, 177 - DWC_TIM_CTRL(pwm->hwpwm)) & DWC_TIM_CTRL_EN); 178 - 179 - duty = dwc_pwm_readl(dwc, DWC_TIM_LD_CNT(pwm->hwpwm)); 180 - duty += 1; 181 - duty *= DWC_CLK_PERIOD_NS; 182 - state->duty_cycle = duty; 183 - 184 - period = dwc_pwm_readl(dwc, DWC_TIM_LD_CNT2(pwm->hwpwm)); 185 - period += 1; 186 - period *= DWC_CLK_PERIOD_NS; 187 - period += duty; 188 - state->period = period; 189 - 190 - state->polarity = PWM_POLARITY_INVERSED; 191 - 192 - pm_runtime_put_sync(chip->dev); 193 - 194 - return 0; 195 - } 196 - 197 - static const struct pwm_ops dwc_pwm_ops = { 198 - .apply = dwc_pwm_apply, 199 - .get_state = dwc_pwm_get_state, 200 - .owner = THIS_MODULE, 201 - }; 202 - 203 - static struct dwc_pwm *dwc_pwm_alloc(struct device *dev) 204 - { 205 - struct dwc_pwm *dwc; 206 - 207 - dwc = devm_kzalloc(dev, sizeof(*dwc), GFP_KERNEL); 208 - if (!dwc) 209 - return NULL; 210 - 211 - dwc->chip.dev = dev; 212 - dwc->chip.ops = &dwc_pwm_ops; 213 - dwc->chip.npwm = DWC_TIMERS_TOTAL; 214 - 215 - dev_set_drvdata(dev, dwc); 216 - return dwc; 217 - } 24 + #include "pwm-dwc.h" 218 25 219 26 static int dwc_pwm_probe(struct pci_dev *pci, const struct pci_device_id *id) 220 27 {
+60
drivers/pwm/pwm-dwc.h
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * DesignWare PWM Controller driver 4 + * 5 + * Copyright (C) 2018-2020 Intel Corporation 6 + * 7 + * Author: Felipe Balbi (Intel) 8 + * Author: Jarkko Nikula <jarkko.nikula@linux.intel.com> 9 + * Author: Raymond Tan <raymond.tan@intel.com> 10 + */ 11 + 12 + MODULE_IMPORT_NS(dwc_pwm); 13 + 14 + #define DWC_TIM_LD_CNT(n) ((n) * 0x14) 15 + #define DWC_TIM_LD_CNT2(n) (((n) * 4) + 0xb0) 16 + #define DWC_TIM_CUR_VAL(n) (((n) * 0x14) + 0x04) 17 + #define DWC_TIM_CTRL(n) (((n) * 0x14) + 0x08) 18 + #define DWC_TIM_EOI(n) (((n) * 0x14) + 0x0c) 19 + #define DWC_TIM_INT_STS(n) (((n) * 0x14) + 0x10) 20 + 21 + #define DWC_TIMERS_INT_STS 0xa0 22 + #define DWC_TIMERS_EOI 0xa4 23 + #define DWC_TIMERS_RAW_INT_STS 0xa8 24 + #define DWC_TIMERS_COMP_VERSION 0xac 25 + 26 + #define DWC_TIMERS_TOTAL 8 27 + 28 + /* Timer Control Register */ 29 + #define DWC_TIM_CTRL_EN BIT(0) 30 + #define DWC_TIM_CTRL_MODE BIT(1) 31 + #define DWC_TIM_CTRL_MODE_FREE (0 << 1) 32 + #define DWC_TIM_CTRL_MODE_USER (1 << 1) 33 + #define DWC_TIM_CTRL_INT_MASK BIT(2) 34 + #define DWC_TIM_CTRL_PWM BIT(3) 35 + 36 + struct dwc_pwm_ctx { 37 + u32 cnt; 38 + u32 cnt2; 39 + u32 ctrl; 40 + }; 41 + 42 + struct dwc_pwm { 43 + struct pwm_chip chip; 44 + void __iomem *base; 45 + unsigned int clk_ns; 46 + struct dwc_pwm_ctx ctx[DWC_TIMERS_TOTAL]; 47 + }; 48 + #define to_dwc_pwm(p) (container_of((p), struct dwc_pwm, chip)) 49 + 50 + static inline u32 dwc_pwm_readl(struct dwc_pwm *dwc, u32 offset) 51 + { 52 + return readl(dwc->base + offset); 53 + } 54 + 55 + static inline void dwc_pwm_writel(struct dwc_pwm *dwc, u32 value, u32 offset) 56 + { 57 + writel(value, dwc->base + offset); 58 + } 59 + 60 + extern struct dwc_pwm *dwc_pwm_alloc(struct device *dev);
-1
drivers/pwm/pwm-ep93xx.c
··· 159 159 .request = ep93xx_pwm_request, 160 160 .free = ep93xx_pwm_free, 161 161 .apply = ep93xx_pwm_apply, 162 - .owner = THIS_MODULE, 163 162 }; 164 163 165 164 static int ep93xx_pwm_probe(struct platform_device *pdev)
-1
drivers/pwm/pwm-fsl-ftm.c
··· 350 350 .request = fsl_pwm_request, 351 351 .free = fsl_pwm_free, 352 352 .apply = fsl_pwm_apply, 353 - .owner = THIS_MODULE, 354 353 }; 355 354 356 355 static int fsl_pwm_init(struct fsl_pwm_chip *fpc)
-1
drivers/pwm/pwm-hibvt.c
··· 185 185 .get_state = hibvt_pwm_get_state, 186 186 .apply = hibvt_pwm_apply, 187 187 188 - .owner = THIS_MODULE, 189 188 }; 190 189 191 190 static int hibvt_pwm_probe(struct platform_device *pdev)
-1
drivers/pwm/pwm-img.c
··· 208 208 209 209 static const struct pwm_ops img_pwm_ops = { 210 210 .apply = img_pwm_apply, 211 - .owner = THIS_MODULE, 212 211 }; 213 212 214 213 static const struct img_pwm_soc_data pistachio_pwm = {
+5 -25
drivers/pwm/pwm-imx-tpm.c
··· 332 332 .free = pwm_imx_tpm_free, 333 333 .get_state = pwm_imx_tpm_get_state, 334 334 .apply = pwm_imx_tpm_apply, 335 - .owner = THIS_MODULE, 336 335 }; 337 336 338 337 static int pwm_imx_tpm_probe(struct platform_device *pdev) ··· 350 351 if (IS_ERR(tpm->base)) 351 352 return PTR_ERR(tpm->base); 352 353 353 - tpm->clk = devm_clk_get(&pdev->dev, NULL); 354 + tpm->clk = devm_clk_get_enabled(&pdev->dev, NULL); 354 355 if (IS_ERR(tpm->clk)) 355 356 return dev_err_probe(&pdev->dev, PTR_ERR(tpm->clk), 356 357 "failed to get PWM clock\n"); 357 - 358 - ret = clk_prepare_enable(tpm->clk); 359 - if (ret) { 360 - dev_err(&pdev->dev, 361 - "failed to prepare or enable clock: %d\n", ret); 362 - return ret; 363 - } 364 358 365 359 tpm->chip.dev = &pdev->dev; 366 360 tpm->chip.ops = &imx_tpm_pwm_ops; ··· 364 372 365 373 mutex_init(&tpm->lock); 366 374 367 - ret = pwmchip_add(&tpm->chip); 368 - if (ret) { 369 - dev_err(&pdev->dev, "failed to add PWM chip: %d\n", ret); 370 - clk_disable_unprepare(tpm->clk); 371 - } 375 + ret = devm_pwmchip_add(&pdev->dev, &tpm->chip); 376 + if (ret) 377 + return dev_err_probe(&pdev->dev, ret, "failed to add PWM chip\n"); 372 378 373 - return ret; 374 - } 375 - 376 - static void pwm_imx_tpm_remove(struct platform_device *pdev) 377 - { 378 - struct imx_tpm_pwm_chip *tpm = platform_get_drvdata(pdev); 379 - 380 - pwmchip_remove(&tpm->chip); 381 - 382 - clk_disable_unprepare(tpm->clk); 379 + return 0; 383 380 } 384 381 385 382 static int __maybe_unused pwm_imx_tpm_suspend(struct device *dev) ··· 418 437 .pm = &imx_tpm_pwm_pm, 419 438 }, 420 439 .probe = pwm_imx_tpm_probe, 421 - .remove_new = pwm_imx_tpm_remove, 422 440 }; 423 441 module_platform_driver(imx_tpm_pwm_driver); 424 442
-1
drivers/pwm/pwm-imx1.c
··· 146 146 147 147 static const struct pwm_ops pwm_imx1_ops = { 148 148 .apply = pwm_imx1_apply, 149 - .owner = THIS_MODULE, 150 149 }; 151 150 152 151 static const struct of_device_id pwm_imx1_dt_ids[] = {
-1
drivers/pwm/pwm-imx27.c
··· 296 296 static const struct pwm_ops pwm_imx27_ops = { 297 297 .apply = pwm_imx27_apply, 298 298 .get_state = pwm_imx27_get_state, 299 - .owner = THIS_MODULE, 300 299 }; 301 300 302 301 static const struct of_device_id pwm_imx27_dt_ids[] = {
-1
drivers/pwm/pwm-intel-lgm.c
··· 107 107 static const struct pwm_ops lgm_pwm_ops = { 108 108 .get_state = lgm_pwm_get_state, 109 109 .apply = lgm_pwm_apply, 110 - .owner = THIS_MODULE, 111 110 }; 112 111 113 112 static void lgm_pwm_init(struct lgm_pwm_chip *pc)
-1
drivers/pwm/pwm-iqs620a.c
··· 166 166 static const struct pwm_ops iqs620_pwm_ops = { 167 167 .apply = iqs620_pwm_apply, 168 168 .get_state = iqs620_pwm_get_state, 169 - .owner = THIS_MODULE, 170 169 }; 171 170 172 171 static void iqs620_pwm_notifier_unregister(void *context)
+24 -22
drivers/pwm/pwm-jz4740.c
··· 27 27 struct jz4740_pwm_chip { 28 28 struct pwm_chip chip; 29 29 struct regmap *map; 30 + struct clk *clk[]; 30 31 }; 31 32 32 33 static inline struct jz4740_pwm_chip *to_jz4740(struct pwm_chip *chip) ··· 71 70 return err; 72 71 } 73 72 74 - pwm_set_chip_data(pwm, clk); 73 + jz->clk[pwm->hwpwm] = clk; 75 74 76 75 return 0; 77 76 } 78 77 79 78 static void jz4740_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm) 80 79 { 81 - struct clk *clk = pwm_get_chip_data(pwm); 80 + struct jz4740_pwm_chip *jz = to_jz4740(chip); 81 + struct clk *clk = jz->clk[pwm->hwpwm]; 82 82 83 83 clk_disable_unprepare(clk); 84 84 clk_put(clk); ··· 123 121 static int jz4740_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, 124 122 const struct pwm_state *state) 125 123 { 126 - struct jz4740_pwm_chip *jz4740 = to_jz4740(pwm->chip); 124 + struct jz4740_pwm_chip *jz = to_jz4740(pwm->chip); 127 125 unsigned long long tmp = 0xffffull * NSEC_PER_SEC; 128 - struct clk *clk = pwm_get_chip_data(pwm); 126 + struct clk *clk = jz->clk[pwm->hwpwm]; 129 127 unsigned long period, duty; 130 128 long rate; 131 129 int err; ··· 175 173 } 176 174 177 175 /* Reset counter to 0 */ 178 - regmap_write(jz4740->map, TCU_REG_TCNTc(pwm->hwpwm), 0); 176 + regmap_write(jz->map, TCU_REG_TCNTc(pwm->hwpwm), 0); 179 177 180 178 /* Set duty */ 181 - regmap_write(jz4740->map, TCU_REG_TDHRc(pwm->hwpwm), duty); 179 + regmap_write(jz->map, TCU_REG_TDHRc(pwm->hwpwm), duty); 182 180 183 181 /* Set period */ 184 - regmap_write(jz4740->map, TCU_REG_TDFRc(pwm->hwpwm), period); 182 + regmap_write(jz->map, TCU_REG_TDFRc(pwm->hwpwm), period); 185 183 186 184 /* Set abrupt shutdown */ 187 - regmap_set_bits(jz4740->map, TCU_REG_TCSRc(pwm->hwpwm), 185 + regmap_set_bits(jz->map, TCU_REG_TCSRc(pwm->hwpwm), 188 186 TCU_TCSR_PWM_SD); 189 187 190 188 /* ··· 201 199 * state instead of its inactive state. 202 200 */ 203 201 if ((state->polarity == PWM_POLARITY_NORMAL) ^ state->enabled) 204 - regmap_update_bits(jz4740->map, TCU_REG_TCSRc(pwm->hwpwm), 202 + regmap_update_bits(jz->map, TCU_REG_TCSRc(pwm->hwpwm), 205 203 TCU_TCSR_PWM_INITL_HIGH, 0); 206 204 else 207 - regmap_update_bits(jz4740->map, TCU_REG_TCSRc(pwm->hwpwm), 205 + regmap_update_bits(jz->map, TCU_REG_TCSRc(pwm->hwpwm), 208 206 TCU_TCSR_PWM_INITL_HIGH, 209 207 TCU_TCSR_PWM_INITL_HIGH); 210 208 ··· 218 216 .request = jz4740_pwm_request, 219 217 .free = jz4740_pwm_free, 220 218 .apply = jz4740_pwm_apply, 221 - .owner = THIS_MODULE, 222 219 }; 223 220 224 221 static int jz4740_pwm_probe(struct platform_device *pdev) 225 222 { 226 223 struct device *dev = &pdev->dev; 227 - struct jz4740_pwm_chip *jz4740; 224 + struct jz4740_pwm_chip *jz; 228 225 const struct soc_info *info; 229 226 230 227 info = device_get_match_data(dev); 231 228 if (!info) 232 229 return -EINVAL; 233 230 234 - jz4740 = devm_kzalloc(dev, sizeof(*jz4740), GFP_KERNEL); 235 - if (!jz4740) 231 + jz = devm_kzalloc(dev, struct_size(jz, clk, info->num_pwms), 232 + GFP_KERNEL); 233 + if (!jz) 236 234 return -ENOMEM; 237 235 238 - jz4740->map = device_node_to_regmap(dev->parent->of_node); 239 - if (IS_ERR(jz4740->map)) { 240 - dev_err(dev, "regmap not found: %ld\n", PTR_ERR(jz4740->map)); 241 - return PTR_ERR(jz4740->map); 236 + jz->map = device_node_to_regmap(dev->parent->of_node); 237 + if (IS_ERR(jz->map)) { 238 + dev_err(dev, "regmap not found: %ld\n", PTR_ERR(jz->map)); 239 + return PTR_ERR(jz->map); 242 240 } 243 241 244 - jz4740->chip.dev = dev; 245 - jz4740->chip.ops = &jz4740_pwm_ops; 246 - jz4740->chip.npwm = info->num_pwms; 242 + jz->chip.dev = dev; 243 + jz->chip.ops = &jz4740_pwm_ops; 244 + jz->chip.npwm = info->num_pwms; 247 245 248 - return devm_pwmchip_add(dev, &jz4740->chip); 246 + return devm_pwmchip_add(dev, &jz->chip); 249 247 } 250 248 251 249 static const struct soc_info jz4740_soc_info = {
-1
drivers/pwm/pwm-keembay.c
··· 178 178 } 179 179 180 180 static const struct pwm_ops keembay_pwm_ops = { 181 - .owner = THIS_MODULE, 182 181 .apply = keembay_pwm_apply, 183 182 .get_state = keembay_pwm_get_state, 184 183 };
+7 -15
drivers/pwm/pwm-lp3943.c
··· 23 23 struct pwm_chip chip; 24 24 struct lp3943 *lp3943; 25 25 struct lp3943_platform_data *pdata; 26 + struct lp3943_pwm_map pwm_map[LP3943_NUM_PWMS]; 26 27 }; 27 28 28 29 static inline struct lp3943_pwm *to_lp3943_pwm(struct pwm_chip *chip) ··· 36 35 { 37 36 struct lp3943_platform_data *pdata = lp3943_pwm->pdata; 38 37 struct lp3943 *lp3943 = lp3943_pwm->lp3943; 39 - struct lp3943_pwm_map *pwm_map; 38 + struct lp3943_pwm_map *pwm_map = &lp3943_pwm->pwm_map[hwpwm]; 40 39 int i, offset; 41 - 42 - pwm_map = kzalloc(sizeof(*pwm_map), GFP_KERNEL); 43 - if (!pwm_map) 44 - return ERR_PTR(-ENOMEM); 45 40 46 41 pwm_map->output = pdata->pwms[hwpwm]->output; 47 42 pwm_map->num_outputs = pdata->pwms[hwpwm]->num_outputs; ··· 46 49 offset = pwm_map->output[i]; 47 50 48 51 /* Return an error if the pin is already assigned */ 49 - if (test_and_set_bit(offset, &lp3943->pin_used)) { 50 - kfree(pwm_map); 52 + if (test_and_set_bit(offset, &lp3943->pin_used)) 51 53 return ERR_PTR(-EBUSY); 52 - } 53 54 } 54 55 55 56 return pwm_map; ··· 62 67 if (IS_ERR(pwm_map)) 63 68 return PTR_ERR(pwm_map); 64 69 65 - return pwm_set_chip_data(pwm, pwm_map); 70 + return 0; 66 71 } 67 72 68 73 static void lp3943_pwm_free_map(struct lp3943_pwm *lp3943_pwm, ··· 75 80 offset = pwm_map->output[i]; 76 81 clear_bit(offset, &lp3943->pin_used); 77 82 } 78 - 79 - kfree(pwm_map); 80 83 } 81 84 82 85 static void lp3943_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm) 83 86 { 84 87 struct lp3943_pwm *lp3943_pwm = to_lp3943_pwm(chip); 85 - struct lp3943_pwm_map *pwm_map = pwm_get_chip_data(pwm); 88 + struct lp3943_pwm_map *pwm_map = &lp3943_pwm->pwm_map[pwm->hwpwm]; 86 89 87 90 lp3943_pwm_free_map(lp3943_pwm, pwm_map); 88 91 } ··· 152 159 static int lp3943_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm) 153 160 { 154 161 struct lp3943_pwm *lp3943_pwm = to_lp3943_pwm(chip); 155 - struct lp3943_pwm_map *pwm_map = pwm_get_chip_data(pwm); 162 + struct lp3943_pwm_map *pwm_map = &lp3943_pwm->pwm_map[pwm->hwpwm]; 156 163 u8 val; 157 164 158 165 if (pwm->hwpwm == 0) ··· 171 178 static void lp3943_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm) 172 179 { 173 180 struct lp3943_pwm *lp3943_pwm = to_lp3943_pwm(chip); 174 - struct lp3943_pwm_map *pwm_map = pwm_get_chip_data(pwm); 181 + struct lp3943_pwm_map *pwm_map = &lp3943_pwm->pwm_map[pwm->hwpwm]; 175 182 176 183 /* 177 184 * LP3943 outputs are open-drain, so the pin should be configured ··· 209 216 .request = lp3943_pwm_request, 210 217 .free = lp3943_pwm_free, 211 218 .apply = lp3943_pwm_apply, 212 - .owner = THIS_MODULE, 213 219 }; 214 220 215 221 static int lp3943_pwm_parse_dt(struct device *dev,
-1
drivers/pwm/pwm-lpc18xx-sct.c
··· 341 341 .apply = lpc18xx_pwm_apply, 342 342 .request = lpc18xx_pwm_request, 343 343 .free = lpc18xx_pwm_free, 344 - .owner = THIS_MODULE, 345 344 }; 346 345 347 346 static const struct of_device_id lpc18xx_pwm_of_match[] = {
-1
drivers/pwm/pwm-lpc32xx.c
··· 115 115 116 116 static const struct pwm_ops lpc32xx_pwm_ops = { 117 117 .apply = lpc32xx_pwm_apply, 118 - .owner = THIS_MODULE, 119 118 }; 120 119 121 120 static int lpc32xx_pwm_probe(struct platform_device *pdev)
-1
drivers/pwm/pwm-lpss.c
··· 243 243 static const struct pwm_ops pwm_lpss_ops = { 244 244 .apply = pwm_lpss_apply, 245 245 .get_state = pwm_lpss_get_state, 246 - .owner = THIS_MODULE, 247 246 }; 248 247 249 248 struct pwm_lpss_chip *devm_pwm_lpss_probe(struct device *dev, void __iomem *base,
-1
drivers/pwm/pwm-mediatek.c
··· 229 229 230 230 static const struct pwm_ops pwm_mediatek_ops = { 231 231 .apply = pwm_mediatek_apply, 232 - .owner = THIS_MODULE, 233 232 }; 234 233 235 234 static int pwm_mediatek_probe(struct platform_device *pdev)
-1
drivers/pwm/pwm-meson.c
··· 335 335 .free = meson_pwm_free, 336 336 .apply = meson_pwm_apply, 337 337 .get_state = meson_pwm_get_state, 338 - .owner = THIS_MODULE, 339 338 }; 340 339 341 340 static const char * const pwm_meson8b_parent_names[] = {
-1
drivers/pwm/pwm-microchip-core.c
··· 435 435 static const struct pwm_ops mchp_core_pwm_ops = { 436 436 .apply = mchp_core_pwm_apply, 437 437 .get_state = mchp_core_pwm_get_state, 438 - .owner = THIS_MODULE, 439 438 }; 440 439 441 440 static const struct of_device_id mchp_core_of_match[] = {
+7 -18
drivers/pwm/pwm-mtk-disp.c
··· 227 227 static const struct pwm_ops mtk_disp_pwm_ops = { 228 228 .apply = mtk_disp_pwm_apply, 229 229 .get_state = mtk_disp_pwm_get_state, 230 - .owner = THIS_MODULE, 231 230 }; 232 231 233 232 static int mtk_disp_pwm_probe(struct platform_device *pdev) ··· 246 247 247 248 mdp->clk_main = devm_clk_get(&pdev->dev, "main"); 248 249 if (IS_ERR(mdp->clk_main)) 249 - return PTR_ERR(mdp->clk_main); 250 + return dev_err_probe(&pdev->dev, PTR_ERR(mdp->clk_main), 251 + "Failed to get main clock\n"); 250 252 251 253 mdp->clk_mm = devm_clk_get(&pdev->dev, "mm"); 252 254 if (IS_ERR(mdp->clk_mm)) 253 - return PTR_ERR(mdp->clk_mm); 255 + return dev_err_probe(&pdev->dev, PTR_ERR(mdp->clk_mm), 256 + "Failed to get mm clock\n"); 254 257 255 258 mdp->chip.dev = &pdev->dev; 256 259 mdp->chip.ops = &mtk_disp_pwm_ops; 257 260 mdp->chip.npwm = 1; 258 261 259 - ret = pwmchip_add(&mdp->chip); 260 - if (ret < 0) { 261 - dev_err(&pdev->dev, "pwmchip_add() failed: %pe\n", ERR_PTR(ret)); 262 - return ret; 263 - } 264 - 265 - platform_set_drvdata(pdev, mdp); 262 + ret = devm_pwmchip_add(&pdev->dev, &mdp->chip); 263 + if (ret < 0) 264 + return dev_err_probe(&pdev->dev, ret, "pwmchip_add() failed\n"); 266 265 267 266 return 0; 268 - } 269 - 270 - static void mtk_disp_pwm_remove(struct platform_device *pdev) 271 - { 272 - struct mtk_disp_pwm *mdp = platform_get_drvdata(pdev); 273 - 274 - pwmchip_remove(&mdp->chip); 275 267 } 276 268 277 269 static const struct mtk_pwm_data mt2701_pwm_data = { ··· 310 320 .of_match_table = mtk_disp_pwm_of_match, 311 321 }, 312 322 .probe = mtk_disp_pwm_probe, 313 - .remove_new = mtk_disp_pwm_remove, 314 323 }; 315 324 module_platform_driver(mtk_disp_pwm_driver); 316 325
-1
drivers/pwm/pwm-mxs.c
··· 115 115 116 116 static const struct pwm_ops mxs_pwm_ops = { 117 117 .apply = mxs_pwm_apply, 118 - .owner = THIS_MODULE, 119 118 }; 120 119 121 120 static int mxs_pwm_probe(struct platform_device *pdev)
-1
drivers/pwm/pwm-ntxec.c
··· 126 126 } 127 127 128 128 static const struct pwm_ops ntxec_pwm_ops = { 129 - .owner = THIS_MODULE, 130 129 .apply = ntxec_pwm_apply, 131 130 /* 132 131 * No .get_state callback, because the current state cannot be read
+1 -2
drivers/pwm/pwm-omap-dmtimer.c
··· 311 311 312 312 static const struct pwm_ops pwm_omap_dmtimer_ops = { 313 313 .apply = pwm_omap_dmtimer_apply, 314 - .owner = THIS_MODULE, 315 314 }; 316 315 317 316 static int pwm_omap_dmtimer_probe(struct platform_device *pdev) ··· 465 466 static struct platform_driver pwm_omap_dmtimer_driver = { 466 467 .driver = { 467 468 .name = "omap-dmtimer-pwm", 468 - .of_match_table = of_match_ptr(pwm_omap_dmtimer_of_match), 469 + .of_match_table = pwm_omap_dmtimer_of_match, 469 470 }, 470 471 .probe = pwm_omap_dmtimer_probe, 471 472 .remove_new = pwm_omap_dmtimer_remove,
-1
drivers/pwm/pwm-pca9685.c
··· 505 505 .get_state = pca9685_pwm_get_state, 506 506 .request = pca9685_pwm_request, 507 507 .free = pca9685_pwm_free, 508 - .owner = THIS_MODULE, 509 508 }; 510 509 511 510 static const struct regmap_config pca9685_regmap_i2c_config = {
+1 -2
drivers/pwm/pwm-pxa.c
··· 24 24 #include <linux/clk.h> 25 25 #include <linux/io.h> 26 26 #include <linux/pwm.h> 27 - #include <linux/of_device.h> 27 + #include <linux/of.h> 28 28 29 29 #include <asm/div64.h> 30 30 ··· 135 135 136 136 static const struct pwm_ops pxa_pwm_ops = { 137 137 .apply = pxa_pwm_apply, 138 - .owner = THIS_MODULE, 139 138 }; 140 139 141 140 #ifdef CONFIG_OF
-1
drivers/pwm/pwm-raspberrypi-poe.c
··· 135 135 static const struct pwm_ops raspberrypi_pwm_ops = { 136 136 .get_state = raspberrypi_pwm_get_state, 137 137 .apply = raspberrypi_pwm_apply, 138 - .owner = THIS_MODULE, 139 138 }; 140 139 141 140 static int raspberrypi_pwm_probe(struct platform_device *pdev)
-1
drivers/pwm/pwm-rcar.c
··· 198 198 .request = rcar_pwm_request, 199 199 .free = rcar_pwm_free, 200 200 .apply = rcar_pwm_apply, 201 - .owner = THIS_MODULE, 202 201 }; 203 202 204 203 static int rcar_pwm_probe(struct platform_device *pdev)
+11 -12
drivers/pwm/pwm-renesas-tpu.c
··· 85 85 86 86 void __iomem *base; 87 87 struct clk *clk; 88 + struct tpu_pwm_device tpd[TPU_CHANNEL_MAX]; 88 89 }; 89 90 90 91 #define to_tpu_device(c) container_of(c, struct tpu_device, chip) ··· 216 215 if (pwm->hwpwm >= TPU_CHANNEL_MAX) 217 216 return -EINVAL; 218 217 219 - tpd = kzalloc(sizeof(*tpd), GFP_KERNEL); 220 - if (tpd == NULL) 221 - return -ENOMEM; 218 + tpd = &tpu->tpd[pwm->hwpwm]; 222 219 223 220 tpd->tpu = tpu; 224 221 tpd->channel = pwm->hwpwm; ··· 227 228 228 229 tpd->timer_on = false; 229 230 230 - pwm_set_chip_data(pwm, tpd); 231 - 232 231 return 0; 233 232 } 234 233 235 234 static void tpu_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm) 236 235 { 237 - struct tpu_pwm_device *tpd = pwm_get_chip_data(pwm); 236 + struct tpu_device *tpu = to_tpu_device(chip); 237 + struct tpu_pwm_device *tpd = &tpu->tpd[pwm->hwpwm]; 238 238 239 239 tpu_pwm_timer_stop(tpd); 240 - kfree(tpd); 241 240 } 242 241 243 242 static int tpu_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, 244 243 u64 duty_ns, u64 period_ns, bool enabled) 245 244 { 246 - struct tpu_pwm_device *tpd = pwm_get_chip_data(pwm); 247 245 struct tpu_device *tpu = to_tpu_device(chip); 246 + struct tpu_pwm_device *tpd = &tpu->tpd[pwm->hwpwm]; 248 247 unsigned int prescaler; 249 248 bool duty_only = false; 250 249 u32 clk_rate; ··· 350 353 static int tpu_pwm_set_polarity(struct pwm_chip *chip, struct pwm_device *pwm, 351 354 enum pwm_polarity polarity) 352 355 { 353 - struct tpu_pwm_device *tpd = pwm_get_chip_data(pwm); 356 + struct tpu_device *tpu = to_tpu_device(chip); 357 + struct tpu_pwm_device *tpd = &tpu->tpd[pwm->hwpwm]; 354 358 355 359 tpd->polarity = polarity; 356 360 ··· 360 362 361 363 static int tpu_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm) 362 364 { 363 - struct tpu_pwm_device *tpd = pwm_get_chip_data(pwm); 365 + struct tpu_device *tpu = to_tpu_device(chip); 366 + struct tpu_pwm_device *tpd = &tpu->tpd[pwm->hwpwm]; 364 367 int ret; 365 368 366 369 ret = tpu_pwm_timer_start(tpd); ··· 383 384 384 385 static void tpu_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm) 385 386 { 386 - struct tpu_pwm_device *tpd = pwm_get_chip_data(pwm); 387 + struct tpu_device *tpu = to_tpu_device(chip); 388 + struct tpu_pwm_device *tpd = &tpu->tpd[pwm->hwpwm]; 387 389 388 390 /* The timer must be running to modify the pin output configuration. */ 389 391 tpu_pwm_timer_start(tpd); ··· 431 431 .request = tpu_pwm_request, 432 432 .free = tpu_pwm_free, 433 433 .apply = tpu_pwm_apply, 434 - .owner = THIS_MODULE, 435 434 }; 436 435 437 436 /* -----------------------------------------------------------------------------
-1
drivers/pwm/pwm-rockchip.c
··· 228 228 static const struct pwm_ops rockchip_pwm_ops = { 229 229 .get_state = rockchip_pwm_get_state, 230 230 .apply = rockchip_pwm_apply, 231 - .owner = THIS_MODULE, 232 231 }; 233 232 234 233 static const struct rockchip_pwm_data pwm_data_v1 = {
-1
drivers/pwm/pwm-rz-mtu3.c
··· 438 438 .free = rz_mtu3_pwm_free, 439 439 .get_state = rz_mtu3_pwm_get_state, 440 440 .apply = rz_mtu3_pwm_apply, 441 - .owner = THIS_MODULE, 442 441 }; 443 442 444 443 static int rz_mtu3_pwm_pm_runtime_suspend(struct device *dev)
+71 -81
drivers/pwm/pwm-samsung.c
··· 77 77 * @base_clk: base clock used to drive the timers 78 78 * @tclk0: external clock 0 (can be ERR_PTR if not present) 79 79 * @tclk1: external clock 1 (can be ERR_PTR if not present) 80 + * @channel: per channel driver data 80 81 */ 81 82 struct samsung_pwm_chip { 82 83 struct pwm_chip chip; ··· 89 88 struct clk *base_clk; 90 89 struct clk *tclk0; 91 90 struct clk *tclk1; 91 + struct samsung_pwm_channel channel[SAMSUNG_PWM_NUM]; 92 92 }; 93 93 94 94 #ifndef CONFIG_CLKSRC_SAMSUNG_PWM ··· 119 117 return (channel == 0) ? 0 : (channel + 1); 120 118 } 121 119 122 - static void __pwm_samsung_manual_update(struct samsung_pwm_chip *chip, 120 + static void __pwm_samsung_manual_update(struct samsung_pwm_chip *our_chip, 123 121 struct pwm_device *pwm) 124 122 { 125 123 unsigned int tcon_chan = to_tcon_channel(pwm->hwpwm); 126 124 u32 tcon; 127 125 128 - tcon = readl(chip->base + REG_TCON); 126 + tcon = readl(our_chip->base + REG_TCON); 129 127 tcon |= TCON_MANUALUPDATE(tcon_chan); 130 - writel(tcon, chip->base + REG_TCON); 128 + writel(tcon, our_chip->base + REG_TCON); 131 129 132 130 tcon &= ~TCON_MANUALUPDATE(tcon_chan); 133 - writel(tcon, chip->base + REG_TCON); 131 + writel(tcon, our_chip->base + REG_TCON); 134 132 } 135 133 136 - static void pwm_samsung_set_divisor(struct samsung_pwm_chip *pwm, 134 + static void pwm_samsung_set_divisor(struct samsung_pwm_chip *our_chip, 137 135 unsigned int channel, u8 divisor) 138 136 { 139 137 u8 shift = TCFG1_SHIFT(channel); ··· 141 139 u32 reg; 142 140 u8 bits; 143 141 144 - bits = (fls(divisor) - 1) - pwm->variant.div_base; 142 + bits = (fls(divisor) - 1) - our_chip->variant.div_base; 145 143 146 144 spin_lock_irqsave(&samsung_pwm_lock, flags); 147 145 148 - reg = readl(pwm->base + REG_TCFG1); 146 + reg = readl(our_chip->base + REG_TCFG1); 149 147 reg &= ~(TCFG1_MUX_MASK << shift); 150 148 reg |= bits << shift; 151 - writel(reg, pwm->base + REG_TCFG1); 149 + writel(reg, our_chip->base + REG_TCFG1); 152 150 153 151 spin_unlock_irqrestore(&samsung_pwm_lock, flags); 154 152 } 155 153 156 - static int pwm_samsung_is_tdiv(struct samsung_pwm_chip *chip, unsigned int chan) 154 + static int pwm_samsung_is_tdiv(struct samsung_pwm_chip *our_chip, unsigned int chan) 157 155 { 158 - struct samsung_pwm_variant *variant = &chip->variant; 156 + struct samsung_pwm_variant *variant = &our_chip->variant; 159 157 u32 reg; 160 158 161 - reg = readl(chip->base + REG_TCFG1); 159 + reg = readl(our_chip->base + REG_TCFG1); 162 160 reg >>= TCFG1_SHIFT(chan); 163 161 reg &= TCFG1_MUX_MASK; 164 162 165 163 return (BIT(reg) & variant->tclk_mask) == 0; 166 164 } 167 165 168 - static unsigned long pwm_samsung_get_tin_rate(struct samsung_pwm_chip *chip, 166 + static unsigned long pwm_samsung_get_tin_rate(struct samsung_pwm_chip *our_chip, 169 167 unsigned int chan) 170 168 { 171 169 unsigned long rate; 172 170 u32 reg; 173 171 174 - rate = clk_get_rate(chip->base_clk); 172 + rate = clk_get_rate(our_chip->base_clk); 175 173 176 - reg = readl(chip->base + REG_TCFG0); 174 + reg = readl(our_chip->base + REG_TCFG0); 177 175 if (chan >= 2) 178 176 reg >>= TCFG0_PRESCALER1_SHIFT; 179 177 reg &= TCFG0_PRESCALER_MASK; ··· 181 179 return rate / (reg + 1); 182 180 } 183 181 184 - static unsigned long pwm_samsung_calc_tin(struct samsung_pwm_chip *chip, 182 + static unsigned long pwm_samsung_calc_tin(struct samsung_pwm_chip *our_chip, 185 183 unsigned int chan, unsigned long freq) 186 184 { 187 - struct samsung_pwm_variant *variant = &chip->variant; 185 + struct samsung_pwm_variant *variant = &our_chip->variant; 188 186 unsigned long rate; 189 187 struct clk *clk; 190 188 u8 div; 191 189 192 - if (!pwm_samsung_is_tdiv(chip, chan)) { 193 - clk = (chan < 2) ? chip->tclk0 : chip->tclk1; 190 + if (!pwm_samsung_is_tdiv(our_chip, chan)) { 191 + clk = (chan < 2) ? our_chip->tclk0 : our_chip->tclk1; 194 192 if (!IS_ERR(clk)) { 195 193 rate = clk_get_rate(clk); 196 194 if (rate) 197 195 return rate; 198 196 } 199 197 200 - dev_warn(chip->chip.dev, 198 + dev_warn(our_chip->chip.dev, 201 199 "tclk of PWM %d is inoperational, using tdiv\n", chan); 202 200 } 203 201 204 - rate = pwm_samsung_get_tin_rate(chip, chan); 205 - dev_dbg(chip->chip.dev, "tin parent at %lu\n", rate); 202 + rate = pwm_samsung_get_tin_rate(our_chip, chan); 203 + dev_dbg(our_chip->chip.dev, "tin parent at %lu\n", rate); 206 204 207 205 /* 208 206 * Compare minimum PWM frequency that can be achieved with possible ··· 222 220 div = variant->div_base; 223 221 } 224 222 225 - pwm_samsung_set_divisor(chip, chan, BIT(div)); 223 + pwm_samsung_set_divisor(our_chip, chan, BIT(div)); 226 224 227 225 return rate >> div; 228 226 } ··· 230 228 static int pwm_samsung_request(struct pwm_chip *chip, struct pwm_device *pwm) 231 229 { 232 230 struct samsung_pwm_chip *our_chip = to_samsung_pwm_chip(chip); 233 - struct samsung_pwm_channel *our_chan; 234 231 235 232 if (!(our_chip->variant.output_mask & BIT(pwm->hwpwm))) { 236 233 dev_warn(chip->dev, ··· 238 237 return -EINVAL; 239 238 } 240 239 241 - our_chan = kzalloc(sizeof(*our_chan), GFP_KERNEL); 242 - if (!our_chan) 243 - return -ENOMEM; 244 - 245 - pwm_set_chip_data(pwm, our_chan); 240 + memset(&our_chip->channel[pwm->hwpwm], 0, sizeof(our_chip->channel[pwm->hwpwm])); 246 241 247 242 return 0; 248 - } 249 - 250 - static void pwm_samsung_free(struct pwm_chip *chip, struct pwm_device *pwm) 251 - { 252 - kfree(pwm_get_chip_data(pwm)); 253 243 } 254 244 255 245 static int pwm_samsung_enable(struct pwm_chip *chip, struct pwm_device *pwm) ··· 294 302 spin_unlock_irqrestore(&samsung_pwm_lock, flags); 295 303 } 296 304 297 - static void pwm_samsung_manual_update(struct samsung_pwm_chip *chip, 305 + static void pwm_samsung_manual_update(struct samsung_pwm_chip *our_chip, 298 306 struct pwm_device *pwm) 299 307 { 300 308 unsigned long flags; 301 309 302 310 spin_lock_irqsave(&samsung_pwm_lock, flags); 303 311 304 - __pwm_samsung_manual_update(chip, pwm); 312 + __pwm_samsung_manual_update(our_chip, pwm); 305 313 306 314 spin_unlock_irqrestore(&samsung_pwm_lock, flags); 307 315 } ··· 310 318 int duty_ns, int period_ns, bool force_period) 311 319 { 312 320 struct samsung_pwm_chip *our_chip = to_samsung_pwm_chip(chip); 313 - struct samsung_pwm_channel *chan = pwm_get_chip_data(pwm); 321 + struct samsung_pwm_channel *chan = &our_chip->channel[pwm->hwpwm]; 314 322 u32 tin_ns = chan->tin_ns, tcnt, tcmp, oldtcmp; 315 323 316 324 tcnt = readl(our_chip->base + REG_TCNTB(pwm->hwpwm)); ··· 385 393 return __pwm_samsung_config(chip, pwm, duty_ns, period_ns, false); 386 394 } 387 395 388 - static void pwm_samsung_set_invert(struct samsung_pwm_chip *chip, 396 + static void pwm_samsung_set_invert(struct samsung_pwm_chip *our_chip, 389 397 unsigned int channel, bool invert) 390 398 { 391 399 unsigned int tcon_chan = to_tcon_channel(channel); ··· 394 402 395 403 spin_lock_irqsave(&samsung_pwm_lock, flags); 396 404 397 - tcon = readl(chip->base + REG_TCON); 405 + tcon = readl(our_chip->base + REG_TCON); 398 406 399 407 if (invert) { 400 - chip->inverter_mask |= BIT(channel); 408 + our_chip->inverter_mask |= BIT(channel); 401 409 tcon |= TCON_INVERT(tcon_chan); 402 410 } else { 403 - chip->inverter_mask &= ~BIT(channel); 411 + our_chip->inverter_mask &= ~BIT(channel); 404 412 tcon &= ~TCON_INVERT(tcon_chan); 405 413 } 406 414 407 - writel(tcon, chip->base + REG_TCON); 415 + writel(tcon, our_chip->base + REG_TCON); 408 416 409 417 spin_unlock_irqrestore(&samsung_pwm_lock, flags); 410 418 } ··· 465 473 466 474 static const struct pwm_ops pwm_samsung_ops = { 467 475 .request = pwm_samsung_request, 468 - .free = pwm_samsung_free, 469 476 .apply = pwm_samsung_apply, 470 - .owner = THIS_MODULE, 471 477 }; 472 478 473 479 #ifdef CONFIG_OF ··· 507 517 }; 508 518 MODULE_DEVICE_TABLE(of, samsung_pwm_matches); 509 519 510 - static int pwm_samsung_parse_dt(struct samsung_pwm_chip *chip) 520 + static int pwm_samsung_parse_dt(struct samsung_pwm_chip *our_chip) 511 521 { 512 - struct device_node *np = chip->chip.dev->of_node; 522 + struct device_node *np = our_chip->chip.dev->of_node; 513 523 const struct of_device_id *match; 514 524 struct property *prop; 515 525 const __be32 *cur; ··· 519 529 if (!match) 520 530 return -ENODEV; 521 531 522 - memcpy(&chip->variant, match->data, sizeof(chip->variant)); 532 + memcpy(&our_chip->variant, match->data, sizeof(our_chip->variant)); 523 533 524 534 of_property_for_each_u32(np, "samsung,pwm-outputs", prop, cur, val) { 525 535 if (val >= SAMSUNG_PWM_NUM) { 526 - dev_err(chip->chip.dev, 536 + dev_err(our_chip->chip.dev, 527 537 "%s: invalid channel index in samsung,pwm-outputs property\n", 528 538 __func__); 529 539 continue; 530 540 } 531 - chip->variant.output_mask |= BIT(val); 541 + our_chip->variant.output_mask |= BIT(val); 532 542 } 533 543 534 544 return 0; 535 545 } 536 546 #else 537 - static int pwm_samsung_parse_dt(struct samsung_pwm_chip *chip) 547 + static int pwm_samsung_parse_dt(struct samsung_pwm_chip *our_chip) 538 548 { 539 549 return -ENODEV; 540 550 } ··· 543 553 static int pwm_samsung_probe(struct platform_device *pdev) 544 554 { 545 555 struct device *dev = &pdev->dev; 546 - struct samsung_pwm_chip *chip; 556 + struct samsung_pwm_chip *our_chip; 547 557 unsigned int chan; 548 558 int ret; 549 559 550 - chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL); 551 - if (chip == NULL) 560 + our_chip = devm_kzalloc(&pdev->dev, sizeof(*our_chip), GFP_KERNEL); 561 + if (our_chip == NULL) 552 562 return -ENOMEM; 553 563 554 - chip->chip.dev = &pdev->dev; 555 - chip->chip.ops = &pwm_samsung_ops; 556 - chip->chip.npwm = SAMSUNG_PWM_NUM; 557 - chip->inverter_mask = BIT(SAMSUNG_PWM_NUM) - 1; 564 + our_chip->chip.dev = &pdev->dev; 565 + our_chip->chip.ops = &pwm_samsung_ops; 566 + our_chip->chip.npwm = SAMSUNG_PWM_NUM; 567 + our_chip->inverter_mask = BIT(SAMSUNG_PWM_NUM) - 1; 558 568 559 569 if (IS_ENABLED(CONFIG_OF) && pdev->dev.of_node) { 560 - ret = pwm_samsung_parse_dt(chip); 570 + ret = pwm_samsung_parse_dt(our_chip); 561 571 if (ret) 562 572 return ret; 563 573 } else { ··· 566 576 return -EINVAL; 567 577 } 568 578 569 - memcpy(&chip->variant, pdev->dev.platform_data, 570 - sizeof(chip->variant)); 579 + memcpy(&our_chip->variant, pdev->dev.platform_data, 580 + sizeof(our_chip->variant)); 571 581 } 572 582 573 - chip->base = devm_platform_ioremap_resource(pdev, 0); 574 - if (IS_ERR(chip->base)) 575 - return PTR_ERR(chip->base); 583 + our_chip->base = devm_platform_ioremap_resource(pdev, 0); 584 + if (IS_ERR(our_chip->base)) 585 + return PTR_ERR(our_chip->base); 576 586 577 - chip->base_clk = devm_clk_get(&pdev->dev, "timers"); 578 - if (IS_ERR(chip->base_clk)) { 587 + our_chip->base_clk = devm_clk_get(&pdev->dev, "timers"); 588 + if (IS_ERR(our_chip->base_clk)) { 579 589 dev_err(dev, "failed to get timer base clk\n"); 580 - return PTR_ERR(chip->base_clk); 590 + return PTR_ERR(our_chip->base_clk); 581 591 } 582 592 583 - ret = clk_prepare_enable(chip->base_clk); 593 + ret = clk_prepare_enable(our_chip->base_clk); 584 594 if (ret < 0) { 585 595 dev_err(dev, "failed to enable base clock\n"); 586 596 return ret; 587 597 } 588 598 589 599 for (chan = 0; chan < SAMSUNG_PWM_NUM; ++chan) 590 - if (chip->variant.output_mask & BIT(chan)) 591 - pwm_samsung_set_invert(chip, chan, true); 600 + if (our_chip->variant.output_mask & BIT(chan)) 601 + pwm_samsung_set_invert(our_chip, chan, true); 592 602 593 603 /* Following clocks are optional. */ 594 - chip->tclk0 = devm_clk_get(&pdev->dev, "pwm-tclk0"); 595 - chip->tclk1 = devm_clk_get(&pdev->dev, "pwm-tclk1"); 604 + our_chip->tclk0 = devm_clk_get(&pdev->dev, "pwm-tclk0"); 605 + our_chip->tclk1 = devm_clk_get(&pdev->dev, "pwm-tclk1"); 596 606 597 - platform_set_drvdata(pdev, chip); 607 + platform_set_drvdata(pdev, our_chip); 598 608 599 - ret = pwmchip_add(&chip->chip); 609 + ret = pwmchip_add(&our_chip->chip); 600 610 if (ret < 0) { 601 611 dev_err(dev, "failed to register PWM chip\n"); 602 - clk_disable_unprepare(chip->base_clk); 612 + clk_disable_unprepare(our_chip->base_clk); 603 613 return ret; 604 614 } 605 615 606 616 dev_dbg(dev, "base_clk at %lu, tclk0 at %lu, tclk1 at %lu\n", 607 - clk_get_rate(chip->base_clk), 608 - !IS_ERR(chip->tclk0) ? clk_get_rate(chip->tclk0) : 0, 609 - !IS_ERR(chip->tclk1) ? clk_get_rate(chip->tclk1) : 0); 617 + clk_get_rate(our_chip->base_clk), 618 + !IS_ERR(our_chip->tclk0) ? clk_get_rate(our_chip->tclk0) : 0, 619 + !IS_ERR(our_chip->tclk1) ? clk_get_rate(our_chip->tclk1) : 0); 610 620 611 621 return 0; 612 622 } 613 623 614 624 static void pwm_samsung_remove(struct platform_device *pdev) 615 625 { 616 - struct samsung_pwm_chip *chip = platform_get_drvdata(pdev); 626 + struct samsung_pwm_chip *our_chip = platform_get_drvdata(pdev); 617 627 618 - pwmchip_remove(&chip->chip); 628 + pwmchip_remove(&our_chip->chip); 619 629 620 - clk_disable_unprepare(chip->base_clk); 630 + clk_disable_unprepare(our_chip->base_clk); 621 631 } 622 632 623 633 #ifdef CONFIG_PM_SLEEP ··· 629 639 630 640 for (i = 0; i < SAMSUNG_PWM_NUM; i++) { 631 641 struct pwm_device *pwm = &chip->pwms[i]; 632 - struct samsung_pwm_channel *chan = pwm_get_chip_data(pwm); 642 + struct samsung_pwm_channel *chan = &our_chip->channel[i]; 633 643 634 - if (!chan) 644 + if (!(pwm->flags & PWMF_REQUESTED)) 635 645 continue; 636 646 637 647 if (our_chip->variant.output_mask & BIT(i))
-1
drivers/pwm/pwm-sifive.c
··· 203 203 .free = pwm_sifive_free, 204 204 .get_state = pwm_sifive_get_state, 205 205 .apply = pwm_sifive_apply, 206 - .owner = THIS_MODULE, 207 206 }; 208 207 209 208 static int pwm_sifive_clock_notifier(struct notifier_block *nb,
-1
drivers/pwm/pwm-sl28cpld.c
··· 200 200 static const struct pwm_ops sl28cpld_pwm_ops = { 201 201 .apply = sl28cpld_pwm_apply, 202 202 .get_state = sl28cpld_pwm_get_state, 203 - .owner = THIS_MODULE, 204 203 }; 205 204 206 205 static int sl28cpld_pwm_probe(struct platform_device *pdev)
+11 -30
drivers/pwm/pwm-spear.c
··· 189 189 190 190 static const struct pwm_ops spear_pwm_ops = { 191 191 .apply = spear_pwm_apply, 192 - .owner = THIS_MODULE, 193 192 }; 194 193 195 194 static int spear_pwm_probe(struct platform_device *pdev) ··· 206 207 if (IS_ERR(pc->mmio_base)) 207 208 return PTR_ERR(pc->mmio_base); 208 209 209 - pc->clk = devm_clk_get(&pdev->dev, NULL); 210 + pc->clk = devm_clk_get_prepared(&pdev->dev, NULL); 210 211 if (IS_ERR(pc->clk)) 211 - return PTR_ERR(pc->clk); 212 - 213 - platform_set_drvdata(pdev, pc); 212 + return dev_err_probe(&pdev->dev, PTR_ERR(pc->clk), 213 + "Failed to get clock\n"); 214 214 215 215 pc->chip.dev = &pdev->dev; 216 216 pc->chip.ops = &spear_pwm_ops; 217 217 pc->chip.npwm = NUM_PWM; 218 218 219 - ret = clk_prepare(pc->clk); 220 - if (ret) 221 - return ret; 222 - 223 219 if (of_device_is_compatible(np, "st,spear1340-pwm")) { 224 220 ret = clk_enable(pc->clk); 225 - if (ret) { 226 - clk_unprepare(pc->clk); 227 - return ret; 228 - } 221 + if (ret) 222 + return dev_err_probe(&pdev->dev, ret, 223 + "Failed to enable clk\n"); 224 + 229 225 /* 230 226 * Following enables PWM chip, channels would still be 231 227 * enabled individually through their control register ··· 232 238 clk_disable(pc->clk); 233 239 } 234 240 235 - ret = pwmchip_add(&pc->chip); 236 - if (ret < 0) { 237 - clk_unprepare(pc->clk); 238 - dev_err(&pdev->dev, "pwmchip_add() failed: %d\n", ret); 239 - } 241 + ret = devm_pwmchip_add(&pdev->dev, &pc->chip); 242 + if (ret < 0) 243 + return dev_err_probe(&pdev->dev, ret, "pwmchip_add() failed\n"); 240 244 241 - return ret; 242 - } 243 - 244 - static void spear_pwm_remove(struct platform_device *pdev) 245 - { 246 - struct spear_pwm_chip *pc = platform_get_drvdata(pdev); 247 - 248 - pwmchip_remove(&pc->chip); 249 - 250 - /* clk was prepared in probe, hence unprepare it here */ 251 - clk_unprepare(pc->clk); 245 + return 0; 252 246 } 253 247 254 248 static const struct of_device_id spear_pwm_of_match[] = { ··· 253 271 .of_match_table = spear_pwm_of_match, 254 272 }, 255 273 .probe = spear_pwm_probe, 256 - .remove_new = spear_pwm_remove, 257 274 }; 258 275 259 276 module_platform_driver(spear_pwm_driver);
+10 -19
drivers/pwm/pwm-sprd.c
··· 40 40 struct sprd_pwm_chn chn[SPRD_PWM_CHN_NUM]; 41 41 }; 42 42 43 + static inline struct sprd_pwm_chip* sprd_pwm_from_chip(struct pwm_chip *chip) 44 + { 45 + return container_of(chip, struct sprd_pwm_chip, chip); 46 + } 47 + 43 48 /* 44 49 * The list of clocks required by PWM channels, and each channel has 2 clocks: 45 50 * enable clock and pwm clock. ··· 74 69 static int sprd_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm, 75 70 struct pwm_state *state) 76 71 { 77 - struct sprd_pwm_chip *spc = 78 - container_of(chip, struct sprd_pwm_chip, chip); 72 + struct sprd_pwm_chip *spc = sprd_pwm_from_chip(chip); 79 73 struct sprd_pwm_chn *chn = &spc->chn[pwm->hwpwm]; 80 74 u32 val, duty, prescale; 81 75 u64 tmp; ··· 166 162 static int sprd_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, 167 163 const struct pwm_state *state) 168 164 { 169 - struct sprd_pwm_chip *spc = 170 - container_of(chip, struct sprd_pwm_chip, chip); 165 + struct sprd_pwm_chip *spc = sprd_pwm_from_chip(chip); 171 166 struct sprd_pwm_chn *chn = &spc->chn[pwm->hwpwm]; 172 167 struct pwm_state *cstate = &pwm->state; 173 168 int ret; ··· 213 210 static const struct pwm_ops sprd_pwm_ops = { 214 211 .apply = sprd_pwm_apply, 215 212 .get_state = sprd_pwm_get_state, 216 - .owner = THIS_MODULE, 217 213 }; 218 214 219 215 static int sprd_pwm_clk_init(struct sprd_pwm_chip *spc) ··· 242 240 chn->clk_rate = clk_get_rate(clk_pwm); 243 241 } 244 242 245 - if (!i) { 246 - dev_err(spc->dev, "no available PWM channels\n"); 247 - return -ENODEV; 248 - } 243 + if (!i) 244 + return dev_err_probe(spc->dev, -ENODEV, "no available PWM channels\n"); 249 245 250 246 spc->num_pwms = i; 251 247 ··· 264 264 return PTR_ERR(spc->base); 265 265 266 266 spc->dev = &pdev->dev; 267 - platform_set_drvdata(pdev, spc); 268 267 269 268 ret = sprd_pwm_clk_init(spc); 270 269 if (ret) ··· 273 274 spc->chip.ops = &sprd_pwm_ops; 274 275 spc->chip.npwm = spc->num_pwms; 275 276 276 - ret = pwmchip_add(&spc->chip); 277 + ret = devm_pwmchip_add(&pdev->dev, &spc->chip); 277 278 if (ret) 278 279 dev_err(&pdev->dev, "failed to add PWM chip\n"); 279 280 280 281 return ret; 281 - } 282 - 283 - static void sprd_pwm_remove(struct platform_device *pdev) 284 - { 285 - struct sprd_pwm_chip *spc = platform_get_drvdata(pdev); 286 - 287 - pwmchip_remove(&spc->chip); 288 282 } 289 283 290 284 static const struct of_device_id sprd_pwm_of_match[] = { ··· 292 300 .of_match_table = sprd_pwm_of_match, 293 301 }, 294 302 .probe = sprd_pwm_probe, 295 - .remove_new = sprd_pwm_remove, 296 303 }; 297 304 298 305 module_platform_driver(sprd_pwm_driver);
+14 -16
drivers/pwm/pwm-sti.c
··· 79 79 unsigned int cpt_num_devs; 80 80 unsigned int max_pwm_cnt; 81 81 unsigned int max_prescale; 82 + struct sti_cpt_ddata *ddata; 82 83 }; 83 84 84 85 struct sti_pwm_chip { ··· 315 314 { 316 315 struct sti_pwm_chip *pc = to_sti_pwmchip(chip); 317 316 struct sti_pwm_compat_data *cdata = pc->cdata; 318 - struct sti_cpt_ddata *ddata = pwm_get_chip_data(pwm); 317 + struct sti_cpt_ddata *ddata = &cdata->ddata[pwm->hwpwm]; 319 318 struct device *dev = pc->dev; 320 319 unsigned int effective_ticks; 321 320 unsigned long long high, low; ··· 421 420 .capture = sti_pwm_capture, 422 421 .apply = sti_pwm_apply, 423 422 .free = sti_pwm_free, 424 - .owner = THIS_MODULE, 425 423 }; 426 424 427 425 static irqreturn_t sti_pwm_interrupt(int irq, void *data) ··· 440 440 while (cpt_int_stat) { 441 441 devicenum = ffs(cpt_int_stat) - 1; 442 442 443 - ddata = pwm_get_chip_data(&pc->chip.pwms[devicenum]); 443 + ddata = &pc->cdata->ddata[devicenum]; 444 444 445 445 /* 446 446 * Capture input: ··· 638 638 dev_err(dev, "failed to prepare clock\n"); 639 639 return ret; 640 640 } 641 + 642 + cdata->ddata = devm_kzalloc(dev, cdata->cpt_num_devs * sizeof(*cdata->ddata), GFP_KERNEL); 643 + if (!cdata->ddata) 644 + return -ENOMEM; 641 645 } 642 646 643 647 pc->chip.dev = dev; 644 648 pc->chip.ops = &sti_pwm_ops; 645 649 pc->chip.npwm = pc->cdata->pwm_num_devs; 646 650 651 + for (i = 0; i < cdata->cpt_num_devs; i++) { 652 + struct sti_cpt_ddata *ddata = &cdata->ddata[i]; 653 + 654 + init_waitqueue_head(&ddata->wait); 655 + mutex_init(&ddata->lock); 656 + } 657 + 647 658 ret = pwmchip_add(&pc->chip); 648 659 if (ret < 0) { 649 660 clk_unprepare(pc->pwm_clk); 650 661 clk_unprepare(pc->cpt_clk); 651 662 return ret; 652 - } 653 - 654 - for (i = 0; i < cdata->cpt_num_devs; i++) { 655 - struct sti_cpt_ddata *ddata; 656 - 657 - ddata = devm_kzalloc(dev, sizeof(*ddata), GFP_KERNEL); 658 - if (!ddata) 659 - return -ENOMEM; 660 - 661 - init_waitqueue_head(&ddata->wait); 662 - mutex_init(&ddata->lock); 663 - 664 - pwm_set_chip_data(&pc->chip.pwms[i], ddata); 665 663 } 666 664 667 665 platform_set_drvdata(pdev, pc);
-1
drivers/pwm/pwm-stm32-lp.c
··· 189 189 } 190 190 191 191 static const struct pwm_ops stm32_pwm_lp_ops = { 192 - .owner = THIS_MODULE, 193 192 .apply = stm32_pwm_lp_apply, 194 193 .get_state = stm32_pwm_lp_get_state, 195 194 };
-1
drivers/pwm/pwm-stm32.c
··· 487 487 } 488 488 489 489 static const struct pwm_ops stm32pwm_ops = { 490 - .owner = THIS_MODULE, 491 490 .apply = stm32_pwm_apply_locked, 492 491 .capture = IS_ENABLED(CONFIG_DMA_ENGINE) ? stm32_pwm_capture : NULL, 493 492 };
-1
drivers/pwm/pwm-stmpe.c
··· 287 287 288 288 static const struct pwm_ops stmpe_24xx_pwm_ops = { 289 289 .apply = stmpe_24xx_pwm_apply, 290 - .owner = THIS_MODULE, 291 290 }; 292 291 293 292 static int __init stmpe_pwm_probe(struct platform_device *pdev)
-1
drivers/pwm/pwm-sun4i.c
··· 325 325 static const struct pwm_ops sun4i_pwm_ops = { 326 326 .apply = sun4i_pwm_apply, 327 327 .get_state = sun4i_pwm_get_state, 328 - .owner = THIS_MODULE, 329 328 }; 330 329 331 330 static const struct sun4i_pwm_data sun4i_pwm_dual_nobypass = {
-1
drivers/pwm/pwm-sunplus.c
··· 163 163 static const struct pwm_ops sunplus_pwm_ops = { 164 164 .apply = sunplus_pwm_apply, 165 165 .get_state = sunplus_pwm_get_state, 166 - .owner = THIS_MODULE, 167 166 }; 168 167 169 168 static void sunplus_pwm_clk_release(void *data)
-1
drivers/pwm/pwm-tegra.c
··· 268 268 269 269 static const struct pwm_ops tegra_pwm_ops = { 270 270 .apply = tegra_pwm_apply, 271 - .owner = THIS_MODULE, 272 271 }; 273 272 274 273 static int tegra_pwm_probe(struct platform_device *pdev)
-1
drivers/pwm/pwm-tiecap.c
··· 205 205 206 206 static const struct pwm_ops ecap_pwm_ops = { 207 207 .apply = ecap_pwm_apply, 208 - .owner = THIS_MODULE, 209 208 }; 210 209 211 210 static const struct of_device_id ecap_of_match[] = {
-1
drivers/pwm/pwm-tiehrpwm.c
··· 437 437 static const struct pwm_ops ehrpwm_pwm_ops = { 438 438 .free = ehrpwm_pwm_free, 439 439 .apply = ehrpwm_pwm_apply, 440 - .owner = THIS_MODULE, 441 440 }; 442 441 443 442 static const struct of_device_id ehrpwm_of_match[] = {
-2
drivers/pwm/pwm-twl-led.c
··· 189 189 190 190 static const struct pwm_ops twl4030_pwmled_ops = { 191 191 .apply = twl4030_pwmled_apply, 192 - .owner = THIS_MODULE, 193 192 }; 194 193 195 194 static int twl6030_pwmled_config(struct pwm_chip *chip, struct pwm_device *pwm, ··· 341 342 .apply = twl6030_pwmled_apply, 342 343 .request = twl6030_pwmled_request, 343 344 .free = twl6030_pwmled_free, 344 - .owner = THIS_MODULE, 345 345 }; 346 346 347 347 static int twl_pwmled_probe(struct platform_device *pdev)
-2
drivers/pwm/pwm-twl.c
··· 333 333 .apply = twl4030_pwm_apply, 334 334 .request = twl4030_pwm_request, 335 335 .free = twl4030_pwm_free, 336 - .owner = THIS_MODULE, 337 336 }; 338 337 339 338 static const struct pwm_ops twl6030_pwm_ops = { 340 339 .apply = twl6030_pwm_apply, 341 - .owner = THIS_MODULE, 342 340 }; 343 341 344 342 static int twl_pwm_probe(struct platform_device *pdev)
-1
drivers/pwm/pwm-visconti.c
··· 129 129 static const struct pwm_ops visconti_pwm_ops = { 130 130 .apply = visconti_pwm_apply, 131 131 .get_state = visconti_pwm_get_state, 132 - .owner = THIS_MODULE, 133 132 }; 134 133 135 134 static int visconti_pwm_probe(struct platform_device *pdev)
+9 -34
drivers/pwm/pwm-vt8500.c
··· 221 221 222 222 static const struct pwm_ops vt8500_pwm_ops = { 223 223 .apply = vt8500_pwm_apply, 224 - .owner = THIS_MODULE, 225 224 }; 226 225 227 226 static const struct of_device_id vt8500_pwm_dt_ids[] = { ··· 235 236 struct device_node *np = pdev->dev.of_node; 236 237 int ret; 237 238 238 - if (!np) { 239 - dev_err(&pdev->dev, "invalid devicetree node\n"); 240 - return -EINVAL; 241 - } 239 + if (!np) 240 + return dev_err_probe(&pdev->dev, -EINVAL, "invalid devicetree node\n"); 242 241 243 242 vt8500 = devm_kzalloc(&pdev->dev, sizeof(*vt8500), GFP_KERNEL); 244 243 if (vt8500 == NULL) ··· 246 249 vt8500->chip.ops = &vt8500_pwm_ops; 247 250 vt8500->chip.npwm = VT8500_NR_PWMS; 248 251 249 - vt8500->clk = devm_clk_get(&pdev->dev, NULL); 250 - if (IS_ERR(vt8500->clk)) { 251 - dev_err(&pdev->dev, "clock source not specified\n"); 252 - return PTR_ERR(vt8500->clk); 253 - } 252 + vt8500->clk = devm_clk_get_prepared(&pdev->dev, NULL); 253 + if (IS_ERR(vt8500->clk)) 254 + return dev_err_probe(&pdev->dev, PTR_ERR(vt8500->clk), "clock source not specified\n"); 254 255 255 256 vt8500->base = devm_platform_ioremap_resource(pdev, 0); 256 257 if (IS_ERR(vt8500->base)) 257 258 return PTR_ERR(vt8500->base); 258 259 259 - ret = clk_prepare(vt8500->clk); 260 - if (ret < 0) { 261 - dev_err(&pdev->dev, "failed to prepare clock\n"); 262 - return ret; 263 - } 260 + ret = devm_pwmchip_add(&pdev->dev, &vt8500->chip); 261 + if (ret < 0) 262 + return dev_err_probe(&pdev->dev, ret, "failed to add PWM chip\n"); 264 263 265 - ret = pwmchip_add(&vt8500->chip); 266 - if (ret < 0) { 267 - dev_err(&pdev->dev, "failed to add PWM chip\n"); 268 - clk_unprepare(vt8500->clk); 269 - return ret; 270 - } 271 - 272 - platform_set_drvdata(pdev, vt8500); 273 - return ret; 274 - } 275 - 276 - static void vt8500_pwm_remove(struct platform_device *pdev) 277 - { 278 - struct vt8500_chip *vt8500 = platform_get_drvdata(pdev); 279 - 280 - pwmchip_remove(&vt8500->chip); 281 - 282 - clk_unprepare(vt8500->clk); 264 + return 0; 283 265 } 284 266 285 267 static struct platform_driver vt8500_pwm_driver = { 286 268 .probe = vt8500_pwm_probe, 287 - .remove_new = vt8500_pwm_remove, 288 269 .driver = { 289 270 .name = "vt8500-pwm", 290 271 .of_match_table = vt8500_pwm_dt_ids,
-1
drivers/pwm/pwm-xilinx.c
··· 198 198 static const struct pwm_ops xilinx_pwm_ops = { 199 199 .apply = xilinx_pwm_apply, 200 200 .get_state = xilinx_pwm_get_state, 201 - .owner = THIS_MODULE, 202 201 }; 203 202 204 203 static const struct regmap_config xilinx_pwm_regmap_config = {
-1
drivers/staging/greybus/pwm.c
··· 258 258 .request = gb_pwm_request, 259 259 .free = gb_pwm_free, 260 260 .apply = gb_pwm_apply, 261 - .owner = THIS_MODULE, 262 261 }; 263 262 264 263 static int gb_pwm_probe(struct gbphy_device *gbphy_dev,
+6 -18
include/linux/pwm.h
··· 71 71 * @hwpwm: per-chip relative index of the PWM device 72 72 * @pwm: global index of the PWM device 73 73 * @chip: PWM chip providing this PWM device 74 - * @chip_data: chip-private data associated with the PWM device 75 74 * @args: PWM arguments 76 75 * @state: last applied state 77 76 * @last: last implemented state (for PWM_DEBUG) ··· 81 82 unsigned int hwpwm; 82 83 unsigned int pwm; 83 84 struct pwm_chip *chip; 84 - void *chip_data; 85 85 86 86 struct pwm_args args; 87 87 struct pwm_state state; ··· 265 267 * @get_state: get the current PWM state. This function is only 266 268 * called once per PWM device when the PWM chip is 267 269 * registered. 268 - * @owner: helps prevent removal of modules exporting active PWMs 269 270 */ 270 271 struct pwm_ops { 271 272 int (*request)(struct pwm_chip *chip, struct pwm_device *pwm); ··· 275 278 const struct pwm_state *state); 276 279 int (*get_state)(struct pwm_chip *chip, struct pwm_device *pwm, 277 280 struct pwm_state *state); 278 - struct module *owner; 279 281 }; 280 282 281 283 /** 282 284 * struct pwm_chip - abstract a PWM controller 283 285 * @dev: device providing the PWMs 284 286 * @ops: callbacks for this PWM controller 287 + * @owner: module providing this chip 285 288 * @base: number of first PWM controlled by this chip 286 289 * @npwm: number of PWMs controlled by this chip 287 290 * @of_xlate: request a PWM device given a device tree PWM specifier ··· 292 295 struct pwm_chip { 293 296 struct device *dev; 294 297 const struct pwm_ops *ops; 298 + struct module *owner; 295 299 int base; 296 300 unsigned int npwm; 297 301 ··· 381 383 /* PWM provider APIs */ 382 384 int pwm_capture(struct pwm_device *pwm, struct pwm_capture *result, 383 385 unsigned long timeout); 384 - int pwm_set_chip_data(struct pwm_device *pwm, void *data); 385 - void *pwm_get_chip_data(struct pwm_device *pwm); 386 386 387 - int pwmchip_add(struct pwm_chip *chip); 387 + int __pwmchip_add(struct pwm_chip *chip, struct module *owner); 388 + #define pwmchip_add(chip) __pwmchip_add(chip, THIS_MODULE) 388 389 void pwmchip_remove(struct pwm_chip *chip); 389 390 390 - int devm_pwmchip_add(struct device *dev, struct pwm_chip *chip); 391 + int __devm_pwmchip_add(struct device *dev, struct pwm_chip *chip, struct module *owner); 392 + #define devm_pwmchip_add(dev, chip) __devm_pwmchip_add(dev, chip, THIS_MODULE) 391 393 392 394 struct pwm_device *pwm_request_from_chip(struct pwm_chip *chip, 393 395 unsigned int index, ··· 441 443 unsigned long timeout) 442 444 { 443 445 return -EINVAL; 444 - } 445 - 446 - static inline int pwm_set_chip_data(struct pwm_device *pwm, void *data) 447 - { 448 - return -EINVAL; 449 - } 450 - 451 - static inline void *pwm_get_chip_data(struct pwm_device *pwm) 452 - { 453 - return NULL; 454 446 } 455 447 456 448 static inline int pwmchip_add(struct pwm_chip *chip)