mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-27 19:29:37 +00:00
![Linus Torvalds](/assets/img/avatar_default.png)
A new driver has been added for the SPEAr platform and the TWL4030/6030 driver has been replaced by two drivers that control the regular PWMs and the PWM driven LEDs provided by the chips. The vt8500, tiecap, tiehrpwm, i.MX, LPC32xx and Samsung drivers have all been improved and the device tree bindings now support the PWM signal polarity. -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (GNU/Linux) iQIcBAABAgAGBQJQ0XF+AAoJEN0jrNd/PrOhk5IP/RxjjfVM8z7i0xc6ykNRyv/3 y8jRh1miwPXeamLdW07vF2NILBtDBmZ8TUbfAMt1esf25UST79Rgol/ia+QlBb3q w/pCDVGwlOW+2qUd34Nlb+CyKXRROIbPcFy29RZn+Z29qdkWn4LVS0nZ0UJPSPel 80P6qxkrFGG8eKsYKB7InA0g4Ds0neWRJAoYsVp5jzyOPFpUILPdaptX+iSEk1v3 VvkIx8eTDPZO9aqn8qL6bcE0g0AneF+dJ4qzLiswlsPMxsFIoVysw6n2JuEyy+FD x0Ml86Zl4SiNzZa4Pwa1250MwFT3cvnjWbAdLb2CGJVMV/uGU6nuyfXV0Aa1XtjQ C0k8LNshgiID8/m1/H3+/aUy9Cx/hj1KM4jchrwkCphlBiAEEryKjTPJXDwfjuBI s5NP4rUwfNVSQT66RaNVZ7atOKyeVu+hwAKO0h6PHOsD1GwhsT+b51/YmWXmb2E5 OgLLOOHVFORfxCrsXRhWcHydMzfplOtfZ4smr4WG0hKUVn2Zp1DK1zDE2rCBB4X1 ZMas4OO9uDRY9IDXZUZUtXcDPDppI6Zx3YeE1/MWzmjWqzyEYFf5OXBbakPr40Rq lKEwYPNf5yiqIURfFZiGDk61mrwA0Vi3i8vYfTFq1zyX9u8KbXeY8g7AhcyC1qsM YhfCmJZ0njopu8oENMgn =m+7I -----END PGP SIGNATURE----- Merge tag 'for-3.8-rc1' of git://gitorious.org/linux-pwm/linux-pwm Pull pwm changes from Thierry Reding: "A new driver has been added for the SPEAr platform and the TWL4030/6030 driver has been replaced by two drivers that control the regular PWMs and the PWM driven LEDs provided by the chips. The vt8500, tiecap, tiehrpwm, i.MX, LPC32xx and Samsung drivers have all been improved and the device tree bindings now support the PWM signal polarity." Fix up trivial conflicts due to __devinit/exit removal. * tag 'for-3.8-rc1' of git://gitorious.org/linux-pwm/linux-pwm: (21 commits) pwm: samsung: add missing s3c->pwm_id assignment pwm: lpc32xx: Set the chip base for dynamic allocation pwm: lpc32xx: Properly disable the clock on device removal pwm: lpc32xx: Fix the PWM polarity pwm: i.MX: eliminate build warning pwm: Export of_pwm_xlate_with_flags() pwm: Remove pwm-twl6030 driver pwm: New driver to support PWM driven LEDs on TWL4030/6030 series of PMICs pwm: New driver to support PWMs on TWL4030/6030 series of PMICs pwm: pwm-tiehrpwm: pinctrl support pwm: tiehrpwm: Add device-tree binding pwm: pwm-tiehrpwm: Adding TBCLK gating support. pwm: pwm-tiecap: pinctrl support pwm: tiecap: Add device-tree binding pwm: Add TI PWM subsystem driver pwm: Device tree support for PWM polarity pwm: vt8500: Ensure PWM clock is enabled during pwm_config pwm: vt8500: Fix build error pwm: spear: Staticize spear_pwm_config() pwm: Add SPEAr PWM chip driver support ...
167 lines
4 KiB
C
167 lines
4 KiB
C
/*
|
|
* Copyright 2012 Alexandre Pereira da Silva <aletes.xgr@gmail.com>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; version 2.
|
|
*
|
|
*/
|
|
|
|
#include <linux/clk.h>
|
|
#include <linux/err.h>
|
|
#include <linux/io.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/module.h>
|
|
#include <linux/of.h>
|
|
#include <linux/of_address.h>
|
|
#include <linux/platform_device.h>
|
|
#include <linux/pwm.h>
|
|
#include <linux/slab.h>
|
|
|
|
struct lpc32xx_pwm_chip {
|
|
struct pwm_chip chip;
|
|
struct clk *clk;
|
|
void __iomem *base;
|
|
};
|
|
|
|
#define PWM_ENABLE (1 << 31)
|
|
#define PWM_RELOADV(x) (((x) & 0xFF) << 8)
|
|
#define PWM_DUTY(x) ((x) & 0xFF)
|
|
|
|
#define to_lpc32xx_pwm_chip(_chip) \
|
|
container_of(_chip, struct lpc32xx_pwm_chip, chip)
|
|
|
|
static int lpc32xx_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
|
|
int duty_ns, int period_ns)
|
|
{
|
|
struct lpc32xx_pwm_chip *lpc32xx = to_lpc32xx_pwm_chip(chip);
|
|
unsigned long long c;
|
|
int period_cycles, duty_cycles;
|
|
|
|
c = clk_get_rate(lpc32xx->clk) / 256;
|
|
c = c * period_ns;
|
|
do_div(c, NSEC_PER_SEC);
|
|
|
|
/* Handle high and low extremes */
|
|
if (c == 0)
|
|
c = 1;
|
|
if (c > 255)
|
|
c = 0; /* 0 set division by 256 */
|
|
period_cycles = c;
|
|
|
|
/* The duty-cycle value is as follows:
|
|
*
|
|
* DUTY-CYCLE HIGH LEVEL
|
|
* 1 99.9%
|
|
* 25 90.0%
|
|
* 128 50.0%
|
|
* 220 10.0%
|
|
* 255 0.1%
|
|
* 0 0.0%
|
|
*
|
|
* In other words, the register value is duty-cycle % 256 with
|
|
* duty-cycle in the range 1-256.
|
|
*/
|
|
c = 256 * duty_ns;
|
|
do_div(c, period_ns);
|
|
if (c > 255)
|
|
c = 255;
|
|
duty_cycles = 256 - c;
|
|
|
|
writel(PWM_ENABLE | PWM_RELOADV(period_cycles) | PWM_DUTY(duty_cycles),
|
|
lpc32xx->base + (pwm->hwpwm << 2));
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int lpc32xx_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
|
|
{
|
|
struct lpc32xx_pwm_chip *lpc32xx = to_lpc32xx_pwm_chip(chip);
|
|
|
|
return clk_enable(lpc32xx->clk);
|
|
}
|
|
|
|
static void lpc32xx_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
|
|
{
|
|
struct lpc32xx_pwm_chip *lpc32xx = to_lpc32xx_pwm_chip(chip);
|
|
|
|
writel(0, lpc32xx->base + (pwm->hwpwm << 2));
|
|
clk_disable(lpc32xx->clk);
|
|
}
|
|
|
|
static const struct pwm_ops lpc32xx_pwm_ops = {
|
|
.config = lpc32xx_pwm_config,
|
|
.enable = lpc32xx_pwm_enable,
|
|
.disable = lpc32xx_pwm_disable,
|
|
.owner = THIS_MODULE,
|
|
};
|
|
|
|
static int lpc32xx_pwm_probe(struct platform_device *pdev)
|
|
{
|
|
struct lpc32xx_pwm_chip *lpc32xx;
|
|
struct resource *res;
|
|
int ret;
|
|
|
|
lpc32xx = devm_kzalloc(&pdev->dev, sizeof(*lpc32xx), GFP_KERNEL);
|
|
if (!lpc32xx)
|
|
return -ENOMEM;
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
if (!res)
|
|
return -EINVAL;
|
|
|
|
lpc32xx->base = devm_request_and_ioremap(&pdev->dev, res);
|
|
if (!lpc32xx->base)
|
|
return -EADDRNOTAVAIL;
|
|
|
|
lpc32xx->clk = devm_clk_get(&pdev->dev, NULL);
|
|
if (IS_ERR(lpc32xx->clk))
|
|
return PTR_ERR(lpc32xx->clk);
|
|
|
|
lpc32xx->chip.dev = &pdev->dev;
|
|
lpc32xx->chip.ops = &lpc32xx_pwm_ops;
|
|
lpc32xx->chip.npwm = 2;
|
|
lpc32xx->chip.base = -1;
|
|
|
|
ret = pwmchip_add(&lpc32xx->chip);
|
|
if (ret < 0) {
|
|
dev_err(&pdev->dev, "failed to add PWM chip, error %d\n", ret);
|
|
return ret;
|
|
}
|
|
|
|
platform_set_drvdata(pdev, lpc32xx);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int lpc32xx_pwm_remove(struct platform_device *pdev)
|
|
{
|
|
struct lpc32xx_pwm_chip *lpc32xx = platform_get_drvdata(pdev);
|
|
unsigned int i;
|
|
|
|
for (i = 0; i < lpc32xx->chip.npwm; i++)
|
|
pwm_disable(&lpc32xx->chip.pwms[i]);
|
|
|
|
return pwmchip_remove(&lpc32xx->chip);
|
|
}
|
|
|
|
static struct of_device_id lpc32xx_pwm_dt_ids[] = {
|
|
{ .compatible = "nxp,lpc3220-pwm", },
|
|
{ /* sentinel */ }
|
|
};
|
|
MODULE_DEVICE_TABLE(of, lpc32xx_pwm_dt_ids);
|
|
|
|
static struct platform_driver lpc32xx_pwm_driver = {
|
|
.driver = {
|
|
.name = "lpc32xx-pwm",
|
|
.of_match_table = of_match_ptr(lpc32xx_pwm_dt_ids),
|
|
},
|
|
.probe = lpc32xx_pwm_probe,
|
|
.remove = lpc32xx_pwm_remove,
|
|
};
|
|
module_platform_driver(lpc32xx_pwm_driver);
|
|
|
|
MODULE_ALIAS("platform:lpc32xx-pwm");
|
|
MODULE_AUTHOR("Alexandre Pereira da Silva <aletes.xgr@gmail.com>");
|
|
MODULE_DESCRIPTION("LPC32XX PWM Driver");
|
|
MODULE_LICENSE("GPL v2");
|