]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
Merge remote-tracking branch 'pwm/for-next'
authorStephen Rothwell <sfr@canb.auug.org.au>
Wed, 21 May 2014 06:04:36 +0000 (16:04 +1000)
committerStephen Rothwell <sfr@canb.auug.org.au>
Wed, 21 May 2014 06:04:36 +0000 (16:04 +1000)
19 files changed:
Documentation/devicetree/bindings/pwm/bcm-kona-pwm.txt [new file with mode: 0644]
Documentation/pwm.txt
arch/arm/plat-samsung/dev-backlight.c
drivers/pwm/Kconfig
drivers/pwm/Makefile
drivers/pwm/pwm-ab8500.c
drivers/pwm/pwm-bcm-kona.c [new file with mode: 0644]
drivers/pwm/pwm-imx.c
drivers/pwm/pwm-lpss.c
drivers/pwm/pwm-pxa.c
drivers/pwm/pwm-renesas-tpu.c
drivers/pwm/pwm-spear.c
drivers/pwm/pwm-tegra.c
drivers/pwm/pwm-tiecap.c
drivers/pwm/pwm-tiehrpwm.c
drivers/pwm/pwm-twl.c
drivers/pwm/pwm-vt8500.c
drivers/video/backlight/pwm_bl.c
include/linux/pwm_backlight.h

diff --git a/Documentation/devicetree/bindings/pwm/bcm-kona-pwm.txt b/Documentation/devicetree/bindings/pwm/bcm-kona-pwm.txt
new file mode 100644 (file)
index 0000000..8eae9fe
--- /dev/null
@@ -0,0 +1,21 @@
+Broadcom Kona PWM controller device tree bindings
+
+This controller has 6 channels.
+
+Required Properties :
+- compatible: should contain "brcm,kona-pwm"
+- reg: physical base address and length of the controller's registers
+- clocks: phandle + clock specifier pair for the external clock
+- #pwm-cells: Should be 3. See pwm.txt in this directory for a
+  description of the cells format.
+
+Refer to clocks/clock-bindings.txt for generic clock consumer properties.
+
+Example:
+
+pwm: pwm@3e01a000 {
+       compatible = "brcm,bcm11351-pwm", "brcm,kona-pwm";
+       reg = <0x3e01a000 0xc4>;
+       clocks = <&pwm_clk>;
+       #pwm-cells = <3>;
+};
index 93cb979749860f323bb797ce2adc2923d629e1ed..0527f615b115cb38ff5bb314dd01f1e7709493f3 100644 (file)
@@ -97,6 +97,13 @@ pwm_chip as argument which provides a description of the PWM chip, the
 number of PWM devices provided by the chip and the chip-specific
 implementation of the supported PWM operations to the framework.
 
+When implementing polarity support in a PWM driver, make sure to respect the
+signal conventions in the PWM framework. By definition, normal polarity
+characterizes a signal starts high for the duration of the duty cycle and
+goes low for the remainder of the period. Conversely, a signal with inversed
+polarity starts low for the duration of the duty cycle and goes high for the
+remainder of the period.
+
 Locking
 -------
 
index be4ad0b21c082abf990d00bec2f14d665672e78d..2157c5b539e6c9ad88baab1b41985b27f525042d 100644 (file)
@@ -124,8 +124,6 @@ void __init samsung_bl_set(struct samsung_bl_gpio_info *gpio_info,
                samsung_bl_data->pwm_period_ns = bl_data->pwm_period_ns;
        if (bl_data->enable_gpio >= 0)
                samsung_bl_data->enable_gpio = bl_data->enable_gpio;
-       if (bl_data->enable_gpio_flags)
-               samsung_bl_data->enable_gpio_flags = bl_data->enable_gpio_flags;
        if (bl_data->init)
                samsung_bl_data->init = bl_data->init;
        if (bl_data->notify)
index 5b34ff29ea38042c84b19424ba3bc1826fab24a2..4ad7b89a4cb44c4ee200b79036750fcce267e674 100644 (file)
@@ -62,6 +62,15 @@ config PWM_ATMEL_TCB
          To compile this driver as a module, choose M here: the module
          will be called pwm-atmel-tcb.
 
+config PWM_BCM_KONA
+       tristate "Kona PWM support"
+       depends on ARCH_BCM_MOBILE
+       help
+         Generic PWM framework driver for Broadcom Kona PWM block.
+
+         To compile this driver as a module, choose M here: the module
+         will be called pwm-bcm-kona.
+
 config PWM_BFIN
        tristate "Blackfin PWM support"
        depends on BFIN_GPTIMERS
index e57d2c38a79403902d4855295cfbf7c469510b7f..5c86a19d5d39c052adda3fecf3f05b69f7e17bc7 100644 (file)
@@ -3,6 +3,7 @@ obj-$(CONFIG_PWM_SYSFS)         += sysfs.o
 obj-$(CONFIG_PWM_AB8500)       += pwm-ab8500.o
 obj-$(CONFIG_PWM_ATMEL)                += pwm-atmel.o
 obj-$(CONFIG_PWM_ATMEL_TCB)    += pwm-atmel-tcb.o
+obj-$(CONFIG_PWM_BCM_KONA)     += pwm-bcm-kona.o
 obj-$(CONFIG_PWM_BFIN)         += pwm-bfin.o
 obj-$(CONFIG_PWM_CLPS711X)     += pwm-clps711x.o
 obj-$(CONFIG_PWM_EP93XX)       += pwm-ep93xx.o
index 1d07a6f9937541f46de1afc07962974498f69cdc..9d53e8ef90d00c24cb2ccffced9fbdc05f994f13 100644 (file)
@@ -101,10 +101,8 @@ static int ab8500_pwm_probe(struct platform_device *pdev)
         * device which is required for ab8500 read and write
         */
        ab8500 = devm_kzalloc(&pdev->dev, sizeof(*ab8500), GFP_KERNEL);
-       if (ab8500 == NULL) {
-               dev_err(&pdev->dev, "failed to allocate memory\n");
+       if (ab8500 == NULL)
                return -ENOMEM;
-       }
 
        ab8500->chip.dev = &pdev->dev;
        ab8500->chip.ops = &ab8500_pwm_ops;
diff --git a/drivers/pwm/pwm-bcm-kona.c b/drivers/pwm/pwm-bcm-kona.c
new file mode 100644 (file)
index 0000000..02bc048
--- /dev/null
@@ -0,0 +1,318 @@
+/*
+ * Copyright (C) 2014 Broadcom Corporation
+ *
+ * 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.
+ *
+ * This program is distributed "as is" WITHOUT ANY WARRANTY of any
+ * kind, whether express or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/ioport.h>
+#include <linux/math64.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/pwm.h>
+#include <linux/slab.h>
+#include <linux/types.h>
+
+/*
+ * The Kona PWM has some unusual characteristics.  Here are the main points.
+ *
+ * 1) There is no disable bit and the hardware docs advise programming a zero
+ *    duty to achieve output equivalent to that of a normal disable operation.
+ *
+ * 2) Changes to prescale, duty, period, and polarity do not take effect until
+ *    a subsequent rising edge of the trigger bit.
+ *
+ * 3) If the smooth bit and trigger bit are both low, the output is a constant
+ *    high signal.  Otherwise, the earlier waveform continues to be output.
+ *
+ * 4) If the smooth bit is set on the rising edge of the trigger bit, output
+ *    will transition to the new settings on a period boundary (which could be
+ *    seconds away).  If the smooth bit is clear, new settings will be applied
+ *    as soon as possible (the hardware always has a 400ns delay).
+ *
+ * 5) When the external clock that feeds the PWM is disabled, output is pegged
+ *    high or low depending on its state at that exact instant.
+ */
+
+#define PWM_CONTROL_OFFSET                     (0x00000000)
+#define PWM_CONTROL_SMOOTH_SHIFT(chan)         (24 + (chan))
+#define PWM_CONTROL_TYPE_SHIFT(chan)           (16 + (chan))
+#define PWM_CONTROL_POLARITY_SHIFT(chan)       (8 + (chan))
+#define PWM_CONTROL_TRIGGER_SHIFT(chan)                (chan)
+
+#define PRESCALE_OFFSET                                (0x00000004)
+#define PRESCALE_SHIFT(chan)                   ((chan) << 2)
+#define PRESCALE_MASK(chan)                    (0x7 << PRESCALE_SHIFT(chan))
+#define PRESCALE_MIN                           (0x00000000)
+#define PRESCALE_MAX                           (0x00000007)
+
+#define PERIOD_COUNT_OFFSET(chan)              (0x00000008 + ((chan) << 3))
+#define PERIOD_COUNT_MIN                       (0x00000002)
+#define PERIOD_COUNT_MAX                       (0x00ffffff)
+
+#define DUTY_CYCLE_HIGH_OFFSET(chan)           (0x0000000c + ((chan) << 3))
+#define DUTY_CYCLE_HIGH_MIN                    (0x00000000)
+#define DUTY_CYCLE_HIGH_MAX                    (0x00ffffff)
+
+struct kona_pwmc {
+       struct pwm_chip chip;
+       void __iomem *base;
+       struct clk *clk;
+};
+
+static inline struct kona_pwmc *to_kona_pwmc(struct pwm_chip *_chip)
+{
+       return container_of(_chip, struct kona_pwmc, chip);
+}
+
+static void kona_pwmc_apply_settings(struct kona_pwmc *kp, unsigned int chan)
+{
+       unsigned int value = readl(kp->base + PWM_CONTROL_OFFSET);
+
+       /* Clear trigger bit but set smooth bit to maintain old output */
+       value |= 1 << PWM_CONTROL_SMOOTH_SHIFT(chan);
+       value &= ~(1 << PWM_CONTROL_TRIGGER_SHIFT(chan));
+       writel(value, kp->base + PWM_CONTROL_OFFSET);
+
+       /* Set trigger bit and clear smooth bit to apply new settings */
+       value &= ~(1 << PWM_CONTROL_SMOOTH_SHIFT(chan));
+       value |= 1 << PWM_CONTROL_TRIGGER_SHIFT(chan);
+       writel(value, kp->base + PWM_CONTROL_OFFSET);
+}
+
+static int kona_pwmc_config(struct pwm_chip *chip, struct pwm_device *pwm,
+                           int duty_ns, int period_ns)
+{
+       struct kona_pwmc *kp = to_kona_pwmc(chip);
+       u64 val, div, rate;
+       unsigned long prescale = PRESCALE_MIN, pc, dc;
+       unsigned int value, chan = pwm->hwpwm;
+
+       /*
+        * Find period count, duty count and prescale to suit duty_ns and
+        * period_ns. This is done according to formulas described below:
+        *
+        * period_ns = 10^9 * (PRESCALE + 1) * PC / PWM_CLK_RATE
+        * duty_ns = 10^9 * (PRESCALE + 1) * DC / PWM_CLK_RATE
+        *
+        * PC = (PWM_CLK_RATE * period_ns) / (10^9 * (PRESCALE + 1))
+        * DC = (PWM_CLK_RATE * duty_ns) / (10^9 * (PRESCALE + 1))
+        */
+
+       rate = clk_get_rate(kp->clk);
+
+       while (1) {
+               div = 1000000000;
+               div *= 1 + prescale;
+               val = rate * period_ns;
+               pc = div64_u64(val, div);
+               val = rate * duty_ns;
+               dc = div64_u64(val, div);
+
+               /* If duty_ns or period_ns are not achievable then return */
+               if (pc < PERIOD_COUNT_MIN || dc < DUTY_CYCLE_HIGH_MIN)
+                       return -EINVAL;
+
+               /* If pc and dc are in bounds, the calculation is done */
+               if (pc <= PERIOD_COUNT_MAX && dc <= DUTY_CYCLE_HIGH_MAX)
+                       break;
+
+               /* Otherwise, increase prescale and recalculate pc and dc */
+               if (++prescale > PRESCALE_MAX)
+                       return -EINVAL;
+       }
+
+       /* If the PWM channel is enabled, write the settings to the HW */
+       if (test_bit(PWMF_ENABLED, &pwm->flags)) {
+               value = readl(kp->base + PRESCALE_OFFSET);
+               value &= ~PRESCALE_MASK(chan);
+               value |= prescale << PRESCALE_SHIFT(chan);
+               writel(value, kp->base + PRESCALE_OFFSET);
+
+               writel(pc, kp->base + PERIOD_COUNT_OFFSET(chan));
+
+               writel(dc, kp->base + DUTY_CYCLE_HIGH_OFFSET(chan));
+
+               kona_pwmc_apply_settings(kp, chan);
+       }
+
+       return 0;
+}
+
+static int kona_pwmc_set_polarity(struct pwm_chip *chip, struct pwm_device *pwm,
+                                 enum pwm_polarity polarity)
+{
+       struct kona_pwmc *kp = to_kona_pwmc(chip);
+       unsigned int chan = pwm->hwpwm;
+       unsigned int value;
+       int ret;
+
+       ret = clk_prepare_enable(kp->clk);
+       if (ret < 0) {
+               dev_err(chip->dev, "failed to enable clock: %d\n", ret);
+               return ret;
+       }
+
+       value = readl(kp->base + PWM_CONTROL_OFFSET);
+
+       if (polarity == PWM_POLARITY_NORMAL)
+               value |= 1 << PWM_CONTROL_POLARITY_SHIFT(chan);
+       else
+               value &= ~(1 << PWM_CONTROL_POLARITY_SHIFT(chan));
+
+       writel(value, kp->base + PWM_CONTROL_OFFSET);
+
+       kona_pwmc_apply_settings(kp, chan);
+
+       /* Wait for waveform to settle before gating off the clock */
+       ndelay(400);
+
+       clk_disable_unprepare(kp->clk);
+
+       return 0;
+}
+
+static int kona_pwmc_enable(struct pwm_chip *chip, struct pwm_device *pwm)
+{
+       struct kona_pwmc *kp = to_kona_pwmc(chip);
+       int ret;
+
+       ret = clk_prepare_enable(kp->clk);
+       if (ret < 0) {
+               dev_err(chip->dev, "failed to enable clock: %d\n", ret);
+               return ret;
+       }
+
+       ret = kona_pwmc_config(chip, pwm, pwm->duty_cycle, pwm->period);
+       if (ret < 0) {
+               clk_disable_unprepare(kp->clk);
+               return ret;
+       }
+
+       return 0;
+}
+
+static void kona_pwmc_disable(struct pwm_chip *chip, struct pwm_device *pwm)
+{
+       struct kona_pwmc *kp = to_kona_pwmc(chip);
+       unsigned int chan = pwm->hwpwm;
+
+       /* Simulate a disable by configuring for zero duty */
+       writel(0, kp->base + DUTY_CYCLE_HIGH_OFFSET(chan));
+       kona_pwmc_apply_settings(kp, chan);
+
+       /* Wait for waveform to settle before gating off the clock */
+       ndelay(400);
+
+       clk_disable_unprepare(kp->clk);
+}
+
+static const struct pwm_ops kona_pwm_ops = {
+       .config = kona_pwmc_config,
+       .set_polarity = kona_pwmc_set_polarity,
+       .enable = kona_pwmc_enable,
+       .disable = kona_pwmc_disable,
+       .owner = THIS_MODULE,
+};
+
+static int kona_pwmc_probe(struct platform_device *pdev)
+{
+       struct kona_pwmc *kp;
+       struct resource *res;
+       unsigned int chan;
+       unsigned int value = 0;
+       int ret = 0;
+
+       kp = devm_kzalloc(&pdev->dev, sizeof(*kp), GFP_KERNEL);
+       if (kp == NULL)
+               return -ENOMEM;
+
+       platform_set_drvdata(pdev, kp);
+
+       kp->chip.dev = &pdev->dev;
+       kp->chip.ops = &kona_pwm_ops;
+       kp->chip.base = -1;
+       kp->chip.npwm = 6;
+       kp->chip.of_xlate = of_pwm_xlate_with_flags;
+       kp->chip.of_pwm_n_cells = 3;
+       kp->chip.can_sleep = true;
+
+       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       kp->base = devm_ioremap_resource(&pdev->dev, res);
+       if (IS_ERR(kp->base))
+               return PTR_ERR(kp->base);
+
+       kp->clk = devm_clk_get(&pdev->dev, NULL);
+       if (IS_ERR(kp->clk)) {
+               dev_err(&pdev->dev, "failed to get clock: %ld\n",
+                       PTR_ERR(kp->clk));
+               return PTR_ERR(kp->clk);
+       }
+
+       ret = clk_prepare_enable(kp->clk);
+       if (ret < 0) {
+               dev_err(&pdev->dev, "failed to enable clock: %d\n", ret);
+               return ret;
+       }
+
+       /* Set smooth mode, push/pull, and normal polarity for all channels */
+       for (chan = 0; chan < kp->chip.npwm; chan++) {
+               value |= (1 << PWM_CONTROL_SMOOTH_SHIFT(chan));
+               value |= (1 << PWM_CONTROL_TYPE_SHIFT(chan));
+               value |= (1 << PWM_CONTROL_POLARITY_SHIFT(chan));
+       }
+
+       writel(value, kp->base + PWM_CONTROL_OFFSET);
+
+       clk_disable_unprepare(kp->clk);
+
+       ret = pwmchip_add(&kp->chip);
+       if (ret < 0)
+               dev_err(&pdev->dev, "failed to add PWM chip: %d\n", ret);
+
+       return ret;
+}
+
+static int kona_pwmc_remove(struct platform_device *pdev)
+{
+       struct kona_pwmc *kp = platform_get_drvdata(pdev);
+       unsigned int chan;
+
+       for (chan = 0; chan < kp->chip.npwm; chan++)
+               if (test_bit(PWMF_ENABLED, &kp->chip.pwms[chan].flags))
+                       clk_disable_unprepare(kp->clk);
+
+       return pwmchip_remove(&kp->chip);
+}
+
+static const struct of_device_id bcm_kona_pwmc_dt[] = {
+       { .compatible = "brcm,kona-pwm" },
+       { },
+};
+MODULE_DEVICE_TABLE(of, bcm_kona_pwmc_dt);
+
+static struct platform_driver kona_pwmc_driver = {
+       .driver = {
+               .name = "bcm-kona-pwm",
+               .of_match_table = bcm_kona_pwmc_dt,
+       },
+       .probe = kona_pwmc_probe,
+       .remove = kona_pwmc_remove,
+};
+module_platform_driver(kona_pwmc_driver);
+
+MODULE_AUTHOR("Broadcom Corporation <bcm-kernel-feedback-list@broadcom.com>");
+MODULE_AUTHOR("Tim Kryger <tkryger@broadcom.com>");
+MODULE_DESCRIPTION("Broadcom Kona PWM driver");
+MODULE_LICENSE("GPL v2");
index cc477334487494fe014ba8993feb8c674fadad3f..d797c7b84c3feb4b23bd2c2d21651902eda6784f 100644 (file)
@@ -241,10 +241,8 @@ static int imx_pwm_probe(struct platform_device *pdev)
                return -ENODEV;
 
        imx = devm_kzalloc(&pdev->dev, sizeof(*imx), GFP_KERNEL);
-       if (imx == NULL) {
-               dev_err(&pdev->dev, "failed to allocate memory\n");
+       if (imx == NULL)
                return -ENOMEM;
-       }
 
        imx->clk_per = devm_clk_get(&pdev->dev, "per");
        if (IS_ERR(imx->clk_per)) {
index 449e372050a0ed3953cf6b21aa4f905ea5ee7a7d..44ce6c6103ae4088abbb9382f6f69ac5ae4ff412 100644 (file)
@@ -6,6 +6,7 @@
  * Author: Chew Kean Ho <kean.ho.chew@intel.com>
  * Author: Chang Rebecca Swee Fun <rebecca.swee.fun.chang@intel.com>
  * Author: Chew Chiau Ee <chiau.ee.chew@intel.com>
+ * Author: Alan Cox <alan@linux.intel.com>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
@@ -19,6 +20,9 @@
 #include <linux/module.h>
 #include <linux/pwm.h>
 #include <linux/platform_device.h>
+#include <linux/pci.h>
+
+static int pci_drv, plat_drv;  /* So we know which drivers registered */
 
 #define PWM                            0x00000000
 #define PWM_ENABLE                     BIT(31)
@@ -34,6 +38,16 @@ struct pwm_lpss_chip {
        struct pwm_chip chip;
        void __iomem *regs;
        struct clk *clk;
+       unsigned long clk_rate;
+};
+
+struct pwm_lpss_boardinfo {
+       unsigned long clk_rate;
+};
+
+/* BayTrail */
+static const struct pwm_lpss_boardinfo byt_info = {
+       25000000
 };
 
 static inline struct pwm_lpss_chip *to_lpwm(struct pwm_chip *chip)
@@ -55,7 +69,7 @@ static int pwm_lpss_config(struct pwm_chip *chip, struct pwm_device *pwm,
        /* The equation is: base_unit = ((freq / c) * 65536) + correction */
        base_unit = freq * 65536;
 
-       c = clk_get_rate(lpwm->clk);
+       c = lpwm->clk_rate;
        if (!c)
                return -EINVAL;
 
@@ -113,52 +127,48 @@ static const struct pwm_ops pwm_lpss_ops = {
        .owner = THIS_MODULE,
 };
 
-static const struct acpi_device_id pwm_lpss_acpi_match[] = {
-       { "80860F09", 0 },
-       { },
-};
-MODULE_DEVICE_TABLE(acpi, pwm_lpss_acpi_match);
-
-static int pwm_lpss_probe(struct platform_device *pdev)
+static struct pwm_lpss_chip *pwm_lpss_probe(struct device *dev,
+                                           struct resource *r,
+                                           const struct pwm_lpss_boardinfo *info)
 {
        struct pwm_lpss_chip *lpwm;
-       struct resource *r;
        int ret;
 
-       lpwm = devm_kzalloc(&pdev->dev, sizeof(*lpwm), GFP_KERNEL);
+       lpwm = devm_kzalloc(dev, sizeof(*lpwm), GFP_KERNEL);
        if (!lpwm)
-               return -ENOMEM;
-
-       r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+               return ERR_PTR(-ENOMEM);
 
-       lpwm->regs = devm_ioremap_resource(&pdev->dev, r);
+       lpwm->regs = devm_ioremap_resource(dev, r);
        if (IS_ERR(lpwm->regs))
-               return PTR_ERR(lpwm->regs);
-
-       lpwm->clk = devm_clk_get(&pdev->dev, NULL);
-       if (IS_ERR(lpwm->clk)) {
-               dev_err(&pdev->dev, "failed to get PWM clock\n");
-               return PTR_ERR(lpwm->clk);
+               return ERR_CAST(lpwm->regs);
+
+       if (info) {
+               lpwm->clk_rate = info->clk_rate;
+       } else {
+               lpwm->clk = devm_clk_get(dev, NULL);
+               if (IS_ERR(lpwm->clk)) {
+                       dev_err(dev, "failed to get PWM clock\n");
+                       return ERR_CAST(lpwm->clk);
+               }
+               lpwm->clk_rate = clk_get_rate(lpwm->clk);
        }
 
-       lpwm->chip.dev = &pdev->dev;
+       lpwm->chip.dev = dev;
        lpwm->chip.ops = &pwm_lpss_ops;
        lpwm->chip.base = -1;
        lpwm->chip.npwm = 1;
 
        ret = pwmchip_add(&lpwm->chip);
        if (ret) {
-               dev_err(&pdev->dev, "failed to add PWM chip: %d\n", ret);
-               return ret;
+               dev_err(dev, "failed to add PWM chip: %d\n", ret);
+               return ERR_PTR(ret);
        }
 
-       platform_set_drvdata(pdev, lpwm);
-       return 0;
+       return lpwm;
 }
 
-static int pwm_lpss_remove(struct platform_device *pdev)
+static int pwm_lpss_remove(struct pwm_lpss_chip *lpwm)
 {
-       struct pwm_lpss_chip *lpwm = platform_get_drvdata(pdev);
        u32 ctrl;
 
        ctrl = readl(lpwm->regs + PWM);
@@ -167,15 +177,104 @@ static int pwm_lpss_remove(struct platform_device *pdev)
        return pwmchip_remove(&lpwm->chip);
 }
 
-static struct platform_driver pwm_lpss_driver = {
+static int pwm_lpss_probe_pci(struct pci_dev *pdev,
+                             const struct pci_device_id *id)
+{
+       const struct pwm_lpss_boardinfo *info;
+       struct pwm_lpss_chip *lpwm;
+       int err;
+
+       err = pci_enable_device(pdev);
+       if (err < 0)
+               return err;
+
+       info = (struct pwm_lpss_boardinfo *)id->driver_data;
+       lpwm = pwm_lpss_probe(&pdev->dev, &pdev->resource[0], info);
+       if (IS_ERR(lpwm))
+               return PTR_ERR(lpwm);
+
+       pci_set_drvdata(pdev, lpwm);
+       return 0;
+}
+
+static void pwm_lpss_remove_pci(struct pci_dev *pdev)
+{
+       struct pwm_lpss_chip *lpwm = pci_get_drvdata(pdev);
+
+       pwm_lpss_remove(lpwm);
+       pci_disable_device(pdev);
+}
+
+static struct pci_device_id pwm_lpss_pci_ids[] = {
+       { PCI_VDEVICE(INTEL, 0x0f08), (unsigned long)&byt_info},
+       { PCI_VDEVICE(INTEL, 0x0f09), (unsigned long)&byt_info},
+       { },
+};
+MODULE_DEVICE_TABLE(pci, pwm_lpss_pci_ids);
+
+static struct pci_driver pwm_lpss_driver_pci = {
+       .name = "pwm-lpss",
+       .id_table = pwm_lpss_pci_ids,
+       .probe = pwm_lpss_probe_pci,
+       .remove = pwm_lpss_remove_pci,
+};
+
+static int pwm_lpss_probe_platform(struct platform_device *pdev)
+{
+       struct pwm_lpss_chip *lpwm;
+       struct resource *r;
+
+       r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+
+       lpwm = pwm_lpss_probe(&pdev->dev, r, NULL);
+       if (IS_ERR(lpwm))
+               return PTR_ERR(lpwm);
+
+       platform_set_drvdata(pdev, lpwm);
+       return 0;
+}
+
+static int pwm_lpss_remove_platform(struct platform_device *pdev)
+{
+       struct pwm_lpss_chip *lpwm = platform_get_drvdata(pdev);
+
+       return pwm_lpss_remove(lpwm);
+}
+
+static const struct acpi_device_id pwm_lpss_acpi_match[] = {
+       { "80860F09", 0 },
+       { },
+};
+MODULE_DEVICE_TABLE(acpi, pwm_lpss_acpi_match);
+
+static struct platform_driver pwm_lpss_driver_platform = {
        .driver = {
                .name = "pwm-lpss",
                .acpi_match_table = pwm_lpss_acpi_match,
        },
-       .probe = pwm_lpss_probe,
-       .remove = pwm_lpss_remove,
+       .probe = pwm_lpss_probe_platform,
+       .remove = pwm_lpss_remove_platform,
 };
-module_platform_driver(pwm_lpss_driver);
+
+static int __init pwm_init(void)
+{
+       pci_drv = pci_register_driver(&pwm_lpss_driver_pci);
+       plat_drv = platform_driver_register(&pwm_lpss_driver_platform);
+       if (pci_drv && plat_drv)
+               return pci_drv;
+
+       return 0;
+}
+module_init(pwm_init);
+
+static void __exit pwm_exit(void)
+{
+       if (!pci_drv)
+               pci_unregister_driver(&pwm_lpss_driver_pci);
+       if (!plat_drv)
+               platform_driver_unregister(&pwm_lpss_driver_platform);
+}
+module_exit(pwm_exit);
 
 MODULE_DESCRIPTION("PWM driver for Intel LPSS");
 MODULE_AUTHOR("Mika Westerberg <mika.westerberg@linux.intel.com>");
index cd356d8702441169773d030494a4c41c42dc7702..0b312ec420b6920b34cf3cb236a0f20c16c3f502 100644 (file)
@@ -179,10 +179,8 @@ static int pwm_probe(struct platform_device *pdev)
                return -EINVAL;
 
        pwm = devm_kzalloc(&pdev->dev, sizeof(*pwm), GFP_KERNEL);
-       if (pwm == NULL) {
-               dev_err(&pdev->dev, "failed to allocate memory\n");
+       if (pwm == NULL)
                return -ENOMEM;
-       }
 
        pwm->clk = devm_clk_get(&pdev->dev, NULL);
        if (IS_ERR(pwm->clk))
index aff6ba9b49e7b4b3bac9d566af39f01c6136b6bb..cc13ff4cfab06001c71eb3f31efc077356a8010c 100644 (file)
@@ -405,10 +405,8 @@ static int tpu_probe(struct platform_device *pdev)
        int ret;
 
        tpu = devm_kzalloc(&pdev->dev, sizeof(*tpu), GFP_KERNEL);
-       if (tpu == NULL) {
-               dev_err(&pdev->dev, "failed to allocate driver data\n");
+       if (tpu == NULL)
                return -ENOMEM;
-       }
 
        spin_lock_init(&tpu->lock);
        tpu->pdev = pdev;
index cb2d4f0f97114b30cfa04cf29daf13dccf8cc3a7..6fd93e6a4122b0a6e021b60cf8ca792e5054d889 100644 (file)
@@ -179,10 +179,8 @@ static int spear_pwm_probe(struct platform_device *pdev)
        u32 val;
 
        pc = devm_kzalloc(&pdev->dev, sizeof(*pc), GFP_KERNEL);
-       if (!pc) {
-               dev_err(&pdev->dev, "failed to allocate memory\n");
+       if (!pc)
                return -ENOMEM;
-       }
 
        r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
        pc->mmio_base = devm_ioremap_resource(&pdev->dev, r);
@@ -222,7 +220,7 @@ static int spear_pwm_probe(struct platform_device *pdev)
        }
 
        ret = pwmchip_add(&pc->chip);
-       if (!ret) {
+       if (ret < 0) {
                clk_unprepare(pc->clk);
                dev_err(&pdev->dev, "pwmchip_add() failed: %d\n", ret);
        }
index 74298c561c4e57f303f675a13987f6b70ecb5dc4..61d86b9498caa8bb381dbe274e1c0c6e65ee755b 100644 (file)
@@ -173,10 +173,8 @@ static int tegra_pwm_probe(struct platform_device *pdev)
        int ret;
 
        pwm = devm_kzalloc(&pdev->dev, sizeof(*pwm), GFP_KERNEL);
-       if (!pwm) {
-               dev_err(&pdev->dev, "failed to allocate memory\n");
+       if (!pwm)
                return -ENOMEM;
-       }
 
        pwm->dev = &pdev->dev;
 
index 032092c7a6ae3d23705ca79d6d1e175b2a524768..74efbe7f20c3ab084939421dcafa40b108baee95 100644 (file)
@@ -209,10 +209,8 @@ static int ecap_pwm_probe(struct platform_device *pdev)
        u16 status;
 
        pc = devm_kzalloc(&pdev->dev, sizeof(*pc), GFP_KERNEL);
-       if (!pc) {
-               dev_err(&pdev->dev, "failed to allocate memory\n");
+       if (!pc)
                return -ENOMEM;
-       }
 
        clk = devm_clk_get(&pdev->dev, "fck");
        if (IS_ERR(clk)) {
index aee4471424d14a98da494f877909ae5e9f804990..3a31c08cc6c854f0420c292c36e5a36096fc6f0f 100644 (file)
@@ -440,10 +440,8 @@ static int ehrpwm_pwm_probe(struct platform_device *pdev)
        u16 status;
 
        pc = devm_kzalloc(&pdev->dev, sizeof(*pc), GFP_KERNEL);
-       if (!pc) {
-               dev_err(&pdev->dev, "failed to allocate memory\n");
+       if (!pc)
                return -ENOMEM;
-       }
 
        clk = devm_clk_get(&pdev->dev, "fck");
        if (IS_ERR(clk)) {
index b99a50e626a64f82ca98783cc373bd2bc4c82e01..04f76725d59158e1da8fa6968b470edfc0670d36 100644 (file)
@@ -263,14 +263,6 @@ static void twl6030_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
        val |= TWL6030_PWM_TOGGLE(pwm->hwpwm, TWL6030_PWMXR);
        val &= ~TWL6030_PWM_TOGGLE(pwm->hwpwm, TWL6030_PWMXS | TWL6030_PWMXEN);
 
-       ret = twl_i2c_write_u8(TWL6030_MODULE_ID1, val, TWL6030_TOGGLE3_REG);
-       if (ret < 0) {
-               dev_err(chip->dev, "%s: Failed to read TOGGLE3\n", pwm->label);
-               goto out;
-       }
-
-       val |= TWL6030_PWM_TOGGLE(pwm->hwpwm, TWL6030_PWMXS | TWL6030_PWMXEN);
-
        ret = twl_i2c_write_u8(TWL6030_MODULE_ID1, val, TWL6030_TOGGLE3_REG);
        if (ret < 0) {
                dev_err(chip->dev, "%s: Failed to disable PWM\n", pwm->label);
index 323125abf3f4ddae2d6f2c48abe956c8b497b40e..652e6b5b859b92d6cdd2585506e9e24a7528f35b 100644 (file)
@@ -211,10 +211,8 @@ static int vt8500_pwm_probe(struct platform_device *pdev)
        }
 
        chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL);
-       if (chip == NULL) {
-               dev_err(&pdev->dev, "failed to allocate memory\n");
+       if (chip == NULL)
                return -ENOMEM;
-       }
 
        chip->chip.dev = &pdev->dev;
        chip->chip.ops = &vt8500_pwm_ops;
index b75201ff46f6d1bc133a5cae571b90082d11347d..cc49347bbcc0766019fd077f776b2dd19f8d6d49 100644 (file)
@@ -10,8 +10,8 @@
  * published by the Free Software Foundation.
  */
 
+#include <linux/gpio/consumer.h>
 #include <linux/gpio.h>
-#include <linux/of_gpio.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/init.h>
@@ -32,8 +32,7 @@ struct pwm_bl_data {
        unsigned int            *levels;
        bool                    enabled;
        struct regulator        *power_supply;
-       int                     enable_gpio;
-       unsigned long           enable_gpio_flags;
+       struct gpio_desc        *enable_gpio;
        unsigned int            scale;
        int                     (*notify)(struct device *,
                                          int brightness);
@@ -54,12 +53,8 @@ static void pwm_backlight_power_on(struct pwm_bl_data *pb, int brightness)
        if (err < 0)
                dev_err(pb->dev, "failed to enable power supply\n");
 
-       if (gpio_is_valid(pb->enable_gpio)) {
-               if (pb->enable_gpio_flags & PWM_BACKLIGHT_GPIO_ACTIVE_LOW)
-                       gpio_set_value(pb->enable_gpio, 0);
-               else
-                       gpio_set_value(pb->enable_gpio, 1);
-       }
+       if (pb->enable_gpio)
+               gpiod_set_value(pb->enable_gpio, 1);
 
        pwm_enable(pb->pwm);
        pb->enabled = true;
@@ -73,12 +68,8 @@ static void pwm_backlight_power_off(struct pwm_bl_data *pb)
        pwm_config(pb->pwm, 0, pb->period);
        pwm_disable(pb->pwm);
 
-       if (gpio_is_valid(pb->enable_gpio)) {
-               if (pb->enable_gpio_flags & PWM_BACKLIGHT_GPIO_ACTIVE_LOW)
-                       gpio_set_value(pb->enable_gpio, 1);
-               else
-                       gpio_set_value(pb->enable_gpio, 0);
-       }
+       if (pb->enable_gpio)
+               gpiod_set_value(pb->enable_gpio, 0);
 
        regulator_disable(pb->power_supply);
        pb->enabled = false;
@@ -148,7 +139,6 @@ static int pwm_backlight_parse_dt(struct device *dev,
                                  struct platform_pwm_backlight_data *data)
 {
        struct device_node *node = dev->of_node;
-       enum of_gpio_flags flags;
        struct property *prop;
        int length;
        u32 value;
@@ -189,14 +179,6 @@ static int pwm_backlight_parse_dt(struct device *dev,
                data->max_brightness--;
        }
 
-       data->enable_gpio = of_get_named_gpio_flags(node, "enable-gpios", 0,
-                                                   &flags);
-       if (data->enable_gpio == -EPROBE_DEFER)
-               return -EPROBE_DEFER;
-
-       if (gpio_is_valid(data->enable_gpio) && (flags & OF_GPIO_ACTIVE_LOW))
-               data->enable_gpio_flags |= PWM_BACKLIGHT_GPIO_ACTIVE_LOW;
-
        return 0;
 }
 
@@ -256,8 +238,6 @@ static int pwm_backlight_probe(struct platform_device *pdev)
        } else
                pb->scale = data->max_brightness;
 
-       pb->enable_gpio = data->enable_gpio;
-       pb->enable_gpio_flags = data->enable_gpio_flags;
        pb->notify = data->notify;
        pb->notify_after = data->notify_after;
        pb->check_fb = data->check_fb;
@@ -265,26 +245,38 @@ static int pwm_backlight_probe(struct platform_device *pdev)
        pb->dev = &pdev->dev;
        pb->enabled = false;
 
-       if (gpio_is_valid(pb->enable_gpio)) {
-               unsigned long flags;
-
-               if (pb->enable_gpio_flags & PWM_BACKLIGHT_GPIO_ACTIVE_LOW)
-                       flags = GPIOF_OUT_INIT_HIGH;
+       pb->enable_gpio = devm_gpiod_get(&pdev->dev, "enable");
+       if (IS_ERR(pb->enable_gpio)) {
+               ret = PTR_ERR(pb->enable_gpio);
+               if (ret == -ENOENT)
+                       pb->enable_gpio = NULL;
                else
-                       flags = GPIOF_OUT_INIT_LOW;
+                       goto err_alloc;
+       }
 
-               ret = gpio_request_one(pb->enable_gpio, flags, "enable");
+       /*
+        * Compatibility fallback for drivers still using the integer GPIO
+        * platform data. Must go away soon.
+        */
+       if (!pb->enable_gpio && gpio_is_valid(data->enable_gpio)) {
+               ret = devm_gpio_request_one(&pdev->dev, data->enable_gpio,
+                                           GPIOF_OUT_INIT_HIGH, "enable");
                if (ret < 0) {
                        dev_err(&pdev->dev, "failed to request GPIO#%d: %d\n",
-                               pb->enable_gpio, ret);
+                               data->enable_gpio, ret);
                        goto err_alloc;
                }
+
+               pb->enable_gpio = gpio_to_desc(data->enable_gpio);
        }
 
+       if (pb->enable_gpio)
+               gpiod_direction_output(pb->enable_gpio, 1);
+
        pb->power_supply = devm_regulator_get(&pdev->dev, "power");
        if (IS_ERR(pb->power_supply)) {
                ret = PTR_ERR(pb->power_supply);
-               goto err_gpio;
+               goto err_alloc;
        }
 
        pb->pwm = devm_pwm_get(&pdev->dev, NULL);
@@ -295,7 +287,7 @@ static int pwm_backlight_probe(struct platform_device *pdev)
                if (IS_ERR(pb->pwm)) {
                        dev_err(&pdev->dev, "unable to request legacy PWM\n");
                        ret = PTR_ERR(pb->pwm);
-                       goto err_gpio;
+                       goto err_alloc;
                }
        }
 
@@ -320,7 +312,7 @@ static int pwm_backlight_probe(struct platform_device *pdev)
        if (IS_ERR(bl)) {
                dev_err(&pdev->dev, "failed to register backlight\n");
                ret = PTR_ERR(bl);
-               goto err_gpio;
+               goto err_alloc;
        }
 
        if (data->dft_brightness > data->max_brightness) {
@@ -336,9 +328,6 @@ static int pwm_backlight_probe(struct platform_device *pdev)
        platform_set_drvdata(pdev, bl);
        return 0;
 
-err_gpio:
-       if (gpio_is_valid(pb->enable_gpio))
-               gpio_free(pb->enable_gpio);
 err_alloc:
        if (data->exit)
                data->exit(&pdev->dev);
@@ -359,6 +348,14 @@ static int pwm_backlight_remove(struct platform_device *pdev)
        return 0;
 }
 
+static void pwm_backlight_shutdown(struct platform_device *pdev)
+{
+       struct backlight_device *bl = platform_get_drvdata(pdev);
+       struct pwm_bl_data *pb = bl_get_data(bl);
+
+       pwm_backlight_power_off(pb);
+}
+
 #ifdef CONFIG_PM_SLEEP
 static int pwm_backlight_suspend(struct device *dev)
 {
@@ -404,6 +401,7 @@ static struct platform_driver pwm_backlight_driver = {
        },
        .probe          = pwm_backlight_probe,
        .remove         = pwm_backlight_remove,
+       .shutdown       = pwm_backlight_shutdown,
 };
 
 module_platform_driver(pwm_backlight_driver);
index 2de2e275b2cbd1390ec6693d8f436b05352da16a..efdd9227a49c9c9e77e7b74fff7e891df27935b7 100644 (file)
@@ -6,9 +6,6 @@
 
 #include <linux/backlight.h>
 
-/* TODO: convert to gpiod_*() API once it has been merged */
-#define PWM_BACKLIGHT_GPIO_ACTIVE_LOW  (1 << 0)
-
 struct platform_pwm_backlight_data {
        int pwm_id;
        unsigned int max_brightness;
@@ -16,8 +13,8 @@ struct platform_pwm_backlight_data {
        unsigned int lth_brightness;
        unsigned int pwm_period_ns;
        unsigned int *levels;
+       /* TODO remove once all users are switched to gpiod_* API */
        int enable_gpio;
-       unsigned long enable_gpio_flags;
        int (*init)(struct device *dev);
        int (*notify)(struct device *dev, int brightness);
        void (*notify_after)(struct device *dev, int brightness);