Merge branch 'locking-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[firefly-linux-kernel-4.4.55.git] / drivers / pwm / pwm-renesas-tpu.c
index 2600892782c13eded21d810077485150521da55e..3b71b42e89d505cf5120f87d173f7e78f05e6550 100644 (file)
 #include <linux/ioport.h>
 #include <linux/module.h>
 #include <linux/mutex.h>
-#include <linux/platform_data/pwm-renesas-tpu.h>
+#include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/pm_runtime.h>
 #include <linux/pwm.h>
 #include <linux/slab.h>
 #include <linux/spinlock.h>
 
+#define TPU_CHANNEL_MAX                4
+
 #define TPU_TSTR               0x00    /* Timer start register (shared) */
 
 #define TPU_TCRn               0x00    /* Timer control register */
@@ -86,7 +88,6 @@ struct tpu_pwm_device {
 
 struct tpu_device {
        struct platform_device *pdev;
-       struct tpu_pwm_platform_data *pdata;
        struct pwm_chip chip;
        spinlock_t lock;
 
@@ -228,8 +229,7 @@ static int tpu_pwm_request(struct pwm_chip *chip, struct pwm_device *_pwm)
 
        pwm->tpu = tpu;
        pwm->channel = _pwm->hwpwm;
-       pwm->polarity = tpu->pdata ? tpu->pdata->channels[pwm->channel].polarity
-                     : PWM_POLARITY_NORMAL;
+       pwm->polarity = PWM_POLARITY_NORMAL;
        pwm->prescaler = 0;
        pwm->period = 0;
        pwm->duty = 0;
@@ -395,20 +395,14 @@ 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;
-       }
 
-       tpu->pdata = pdev->dev.platform_data;
+       spin_lock_init(&tpu->lock);
+       tpu->pdev = pdev;
 
        /* Map memory, get clock and pin control. */
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-       if (!res) {
-               dev_err(&pdev->dev, "failed to get I/O memory\n");
-               return -ENXIO;
-       }
-
        tpu->base = devm_ioremap_resource(&pdev->dev, res);
        if (IS_ERR(tpu->base))
                return PTR_ERR(tpu->base);
@@ -422,11 +416,10 @@ static int tpu_probe(struct platform_device *pdev)
        /* Initialize and register the device. */
        platform_set_drvdata(pdev, tpu);
 
-       spin_lock_init(&tpu->lock);
-       tpu->pdev = pdev;
-
        tpu->chip.dev = &pdev->dev;
        tpu->chip.ops = &tpu_pwm_ops;
+       tpu->chip.of_xlate = of_pwm_xlate_with_flags;
+       tpu->chip.of_pwm_n_cells = 3;
        tpu->chip.base = -1;
        tpu->chip.npwm = TPU_CHANNEL_MAX;
 
@@ -457,12 +450,26 @@ static int tpu_remove(struct platform_device *pdev)
        return 0;
 }
 
+#ifdef CONFIG_OF
+static const struct of_device_id tpu_of_table[] = {
+       { .compatible = "renesas,tpu-r8a73a4", },
+       { .compatible = "renesas,tpu-r8a7740", },
+       { .compatible = "renesas,tpu-r8a7790", },
+       { .compatible = "renesas,tpu-sh7372", },
+       { .compatible = "renesas,tpu", },
+       { },
+};
+
+MODULE_DEVICE_TABLE(of, tpu_of_table);
+#endif
+
 static struct platform_driver tpu_driver = {
        .probe          = tpu_probe,
        .remove         = tpu_remove,
        .driver         = {
                .name   = "renesas-tpu-pwm",
                .owner  = THIS_MODULE,
+               .of_match_table = of_match_ptr(tpu_of_table),
        }
 };