drm: Add adv7511 encoder driver
[platform/adaptation/renesas_rcar/renesas_kernel.git] / drivers / clocksource / sh_tmu.c
index 3eee5c8..0f665b8 100644 (file)
@@ -24,6 +24,7 @@
 #include <linux/ioport.h>
 #include <linux/irq.h>
 #include <linux/module.h>
+#include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/pm_domain.h>
 #include <linux/pm_runtime.h>
@@ -61,6 +62,8 @@ struct sh_tmu_device {
 
        enum sh_tmu_model model;
 
+       raw_spinlock_t lock; /* Protect the shared start/stop register */
+
        struct sh_tmu_channel *channels;
        unsigned int num_channels;
 
@@ -68,8 +71,6 @@ struct sh_tmu_device {
        bool has_clocksource;
 };
 
-static DEFINE_RAW_SPINLOCK(sh_tmu_lock);
-
 #define TSTR -1 /* shared register */
 #define TCOR  0 /* channel register */
 #define TCNT 1 /* channel register */
@@ -132,7 +133,7 @@ static void sh_tmu_start_stop_ch(struct sh_tmu_channel *ch, int start)
        unsigned long flags, value;
 
        /* start stop register shared by multiple timer channels */
-       raw_spin_lock_irqsave(&sh_tmu_lock, flags);
+       raw_spin_lock_irqsave(&ch->tmu->lock, flags);
        value = sh_tmu_read(ch, TSTR);
 
        if (start)
@@ -141,7 +142,7 @@ static void sh_tmu_start_stop_ch(struct sh_tmu_channel *ch, int start)
                value &= ~(1 << ch->index);
 
        sh_tmu_write(ch, TSTR, value);
-       raw_spin_unlock_irqrestore(&sh_tmu_lock, flags);
+       raw_spin_unlock_irqrestore(&ch->tmu->lock, flags);
 }
 
 static int __sh_tmu_enable(struct sh_tmu_channel *ch)
@@ -509,21 +510,48 @@ static int sh_tmu_map_memory(struct sh_tmu_device *tmu)
        return 0;
 }
 
+static int sh_tmu_parse_dt(struct sh_tmu_device *tmu)
+{
+       struct device_node *np = tmu->pdev->dev.of_node;
+
+       tmu->model = SH_TMU;
+       tmu->num_channels = 3;
+
+       of_property_read_u32(np, "#renesas,channels", &tmu->num_channels);
+
+       if (tmu->num_channels != 2 && tmu->num_channels != 3) {
+               dev_err(&tmu->pdev->dev, "invalid number of channels %u\n",
+                       tmu->num_channels);
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
 static int sh_tmu_setup(struct sh_tmu_device *tmu, struct platform_device *pdev)
 {
-       struct sh_timer_config *cfg = pdev->dev.platform_data;
-       const struct platform_device_id *id = pdev->id_entry;
        unsigned int i;
        int ret;
 
-       if (!cfg) {
+       tmu->pdev = pdev;
+
+       raw_spin_lock_init(&tmu->lock);
+
+       if (IS_ENABLED(CONFIG_OF) && pdev->dev.of_node) {
+               ret = sh_tmu_parse_dt(tmu);
+               if (ret < 0)
+                       return ret;
+       } else if (pdev->dev.platform_data) {
+               const struct platform_device_id *id = pdev->id_entry;
+               struct sh_timer_config *cfg = pdev->dev.platform_data;
+
+               tmu->model = id->driver_data;
+               tmu->num_channels = hweight8(cfg->channels_mask);
+       } else {
                dev_err(&tmu->pdev->dev, "missing platform data\n");
                return -ENXIO;
        }
 
-       tmu->pdev = pdev;
-       tmu->model = id->driver_data;
-
        /* Get hold of clock. */
        tmu->clk = clk_get(&tmu->pdev->dev, "fck");
        if (IS_ERR(tmu->clk)) {
@@ -543,8 +571,6 @@ static int sh_tmu_setup(struct sh_tmu_device *tmu, struct platform_device *pdev)
        }
 
        /* Allocate and setup the channels. */
-       tmu->num_channels = hweight8(cfg->channels_mask);
-
        tmu->channels = kzalloc(sizeof(*tmu->channels) * tmu->num_channels,
                                GFP_KERNEL);
        if (tmu->channels == NULL) {
@@ -626,11 +652,18 @@ static const struct platform_device_id sh_tmu_id_table[] = {
 };
 MODULE_DEVICE_TABLE(platform, sh_tmu_id_table);
 
+static const struct of_device_id sh_tmu_of_table[] __maybe_unused = {
+       { .compatible = "renesas,tmu" },
+       { }
+};
+MODULE_DEVICE_TABLE(of, sh_tmu_of_table);
+
 static struct platform_driver sh_tmu_device_driver = {
        .probe          = sh_tmu_probe,
        .remove         = sh_tmu_remove,
        .driver         = {
                .name   = "sh_tmu",
+               .of_match_table = of_match_ptr(sh_tmu_of_table),
        },
        .id_table       = sh_tmu_id_table,
 };