1 From 8e16207392cd715ea88f6780981a3d55ab005588 Mon Sep 17 00:00:00 2001
2 From: Andrey Shvetsov <andrey.shvetsov@k2l.de>
3 Date: Mon, 12 Feb 2018 12:23:37 +0100
4 Subject: [PATCH] staging: most: dim2: use device tree
6 Current dim2 driver expects the existence of a platform driver that
7 implements the platform specific initialization and delivery of the irq
10 This patch integrates the device tree activity and platform specific
13 Signed-off-by: Andrey Shvetsov <andrey.shvetsov@k2l.de>
15 hdm-dim2/dim2_hdm.c | 222 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------------
16 hdm-dim2/dim2_hdm.h | 28 ----------------------------
17 hdm-dim2/platform/dim2_arwen_mlb3.c | 165 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------
18 hdm-dim2/platform/dim2_arwen_mlb6.c | 169 -------------------------------------------------------------------------------------------------------------------------------------------------------------------------
19 hdm-dim2/platform/dim2_h2_dt.c | 227 -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
20 hdm-dim2/platform/dim2_mx6q.c | 192 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
21 hdm-dim2/platform/dim2_mx6q_dt.c | 224 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
22 7 files changed, 193 insertions(+), 1034 deletions(-)
23 delete mode 100644 hdm-dim2/dim2_hdm.h
24 delete mode 100644 hdm-dim2/platform/dim2_arwen_mlb3.c
25 delete mode 100644 hdm-dim2/platform/dim2_arwen_mlb6.c
26 delete mode 100644 hdm-dim2/platform/dim2_h2_dt.c
27 delete mode 100644 hdm-dim2/platform/dim2_mx6q.c
28 delete mode 100644 hdm-dim2/platform/dim2_mx6q_dt.c
30 diff --git a/hdm-dim2/dim2_hdm.c b/hdm-dim2/dim2_hdm.c
31 index e4629a5..2dba917 100644
32 --- a/hdm-dim2/dim2_hdm.c
33 +++ b/hdm-dim2/dim2_hdm.c
35 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
37 #include <linux/module.h>
38 +#include <linux/of_platform.h>
39 #include <linux/printk.h>
40 #include <linux/kernel.h>
41 #include <linux/init.h>
43 #include <linux/interrupt.h>
44 #include <linux/slab.h>
46 +#include <linux/clk.h>
47 #include <linux/dma-mapping.h>
48 #include <linux/sched.h>
49 #include <linux/kthread.h>
53 -#include "dim2_hdm.h"
54 #include "dim2_errors.h"
55 #include "dim2_sysfs.h"
57 @@ -93,6 +94,9 @@ struct dim2_hdm {
58 struct most_interface most_iface;
59 char name[16 + sizeof "dim2-"];
60 void __iomem *io_base;
63 + struct clk *clk_pll;
64 struct task_struct *netinfo_task;
65 wait_queue_head_t netinfo_waitq;
67 @@ -102,6 +106,12 @@ struct dim2_hdm {
68 struct medialb_bus bus;
69 void (*on_netinfo)(struct most_interface *,
70 unsigned char, unsigned char *);
71 + void (*disable_platform)(struct platform_device *);
74 +struct dim2_platform_data {
75 + int (*enable)(struct platform_device *);
76 + void (*disable)(struct platform_device *);
79 #define iface_to_hdm(iface) container_of(iface, struct dim2_hdm, most_iface)
80 @@ -686,6 +696,8 @@ static void dma_free(struct mbo *mbo, u32 size)
81 dma_free_coherent(NULL, size, mbo->virt_address, mbo->bus_address);
84 +static const struct of_device_id dim2_of_match[];
87 * dim2_probe - dim2 probe handler
88 * @pdev: platform device structure
89 @@ -695,7 +707,7 @@ static void dma_free(struct mbo *mbo, u32 size)
91 static int dim2_probe(struct platform_device *pdev)
93 - struct dim2_platform_data *pdata = pdev->dev.platform_data;
94 + const struct dim2_platform_data *pdata;
98 @@ -703,6 +715,8 @@ static int dim2_probe(struct platform_device *pdev)
102 + enum { MLB_INT_IDX, AHB0_INT_IDX };
104 dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
107 @@ -710,29 +724,30 @@ static int dim2_probe(struct platform_device *pdev)
110 platform_set_drvdata(pdev, dev);
112 + dev->clk_speed = CLK_4096FS;
114 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
115 dev->io_base = devm_ioremap_resource(&pdev->dev, res);
116 if (IS_ERR(dev->io_base))
117 return PTR_ERR(dev->io_base);
120 - dev_err(&pdev->dev, "missing platform data\n");
124 - ret = pdata->init ? pdata->init(pdata, dev->io_base) : 0;
125 + pdata = of_match_node(dim2_of_match, pdev->dev.of_node)->data;
126 + ret = pdata && pdata->enable ? pdata->enable(pdev) : 0;
130 + dev->disable_platform = pdata ? pdata->disable : 0;
132 dev_info(&pdev->dev, "sync: num of frames per sub-buffer: %u\n", fcnt);
133 - hal_ret = dim_startup(dev->io_base, pdata->clk_speed, fcnt);
134 + hal_ret = dim_startup(dev->io_base, dev->clk_speed, fcnt);
135 if (hal_ret != DIM_NO_ERROR) {
136 dev_err(&pdev->dev, "dim_startup failed: %d\n", hal_ret);
138 - goto err_bsp_destroy;
139 + goto err_disable_platform;
142 - irq = platform_get_irq(pdev, 0);
143 + irq = platform_get_irq(pdev, AHB0_INT_IDX);
145 dev_err(&pdev->dev, "failed to get ahb0_int irq: %d\n", irq);
147 @@ -746,7 +761,7 @@ static int dim2_probe(struct platform_device *pdev)
148 goto err_shutdown_dim;
151 - irq = platform_get_irq(pdev, 1);
152 + irq = platform_get_irq(pdev, MLB_INT_IDX);
154 dev_err(&pdev->dev, "failed to get mlb_int irq: %d\n", irq);
156 @@ -832,9 +847,9 @@ static int dim2_probe(struct platform_device *pdev)
157 kthread_stop(dev->netinfo_task);
161 - if (pdata && pdata->destroy)
162 - pdata->destroy(pdata);
163 +err_disable_platform:
164 + if (dev->disable_platform)
165 + dev->disable_platform(pdev);
169 @@ -848,7 +863,6 @@ static int dim2_probe(struct platform_device *pdev)
170 static int dim2_remove(struct platform_device *pdev)
172 struct dim2_hdm *dev = platform_get_drvdata(pdev);
173 - struct dim2_platform_data *pdata = pdev->dev.platform_data;
176 dim2_sysfs_destroy(&dev->bus);
177 @@ -859,37 +873,187 @@ static int dim2_remove(struct platform_device *pdev)
179 spin_unlock_irqrestore(&dim_lock, flags);
181 - if (pdata && pdata->destroy)
182 - pdata->destroy(pdata);
183 + if (dev->disable_platform)
184 + dev->disable_platform(pdev);
189 +/* platform specific functions [[ */
191 +static int fsl_mx6_enable(struct platform_device *pdev)
193 + struct dim2_hdm *dev = platform_get_drvdata(pdev);
196 + dev->clk = devm_clk_get(&pdev->dev, "mlb");
197 + if (IS_ERR_OR_NULL(dev->clk)) {
198 + dev_err(&pdev->dev, "unable to get mlb clock\n");
202 + ret = clk_prepare_enable(dev->clk);
204 + dev_err(&pdev->dev, "%s\n", "clk_prepare_enable failed");
208 + if (dev->clk_speed >= CLK_2048FS) {
210 + dev->clk_pll = devm_clk_get(&pdev->dev, "pll8_mlb");
211 + if (IS_ERR_OR_NULL(dev->clk_pll)) {
212 + dev_err(&pdev->dev, "unable to get mlb pll clock\n");
213 + clk_disable_unprepare(dev->clk);
217 + writel(0x888, dev->io_base + 0x38);
218 + clk_prepare_enable(dev->clk_pll);
224 +static void fsl_mx6_disable(struct platform_device *pdev)
226 + struct dim2_hdm *dev = platform_get_drvdata(pdev);
228 + if (dev->clk_speed >= CLK_2048FS)
229 + clk_disable_unprepare(dev->clk_pll);
231 + clk_disable_unprepare(dev->clk);
234 +static int rcar_h2_enable(struct platform_device *pdev)
236 + struct dim2_hdm *dev = platform_get_drvdata(pdev);
239 + dev->clk = devm_clk_get(&pdev->dev, NULL);
240 + if (IS_ERR(dev->clk)) {
241 + dev_err(&pdev->dev, "cannot get clock\n");
242 + return PTR_ERR(dev->clk);
245 + ret = clk_prepare_enable(dev->clk);
247 + dev_err(&pdev->dev, "%s\n", "clk_prepare_enable failed");
251 + if (dev->clk_speed >= CLK_2048FS) {
252 + /* enable MLP pll and LVDS drivers */
253 + writel(0x03, dev->io_base + 0x600);
255 + writel(0x888, dev->io_base + 0x38);
258 + writel(0x04, dev->io_base + 0x600);
263 - * break link to local platform_device_id struct
264 - * to prevent crash by unload platform device module
266 - pdev->id_entry = NULL;
268 + writel(0x03, dev->io_base + 0x500);
269 + writel(0x0002FF02, dev->io_base + 0x508);
274 -static const struct platform_device_id dim2_id[] = {
275 - { "medialb_dim2" },
276 - { }, /* Terminating entry */
277 +static void rcar_h2_disable(struct platform_device *pdev)
279 + struct dim2_hdm *dev = platform_get_drvdata(pdev);
281 + clk_disable_unprepare(dev->clk);
283 + /* disable PLLs and LVDS drivers */
284 + writel(0x0, dev->io_base + 0x600);
287 +static int rcar_m3_enable(struct platform_device *pdev)
289 + struct dim2_hdm *dev = platform_get_drvdata(pdev);
290 + u32 enable_512fs = dev->clk_speed == CLK_512FS;
293 + dev->clk = devm_clk_get(&pdev->dev, NULL);
294 + if (IS_ERR(dev->clk)) {
295 + dev_err(&pdev->dev, "cannot get clock\n");
296 + return PTR_ERR(dev->clk);
299 + ret = clk_prepare_enable(dev->clk);
301 + dev_err(&pdev->dev, "%s\n", "clk_prepare_enable failed");
306 + writel(0x04, dev->io_base + 0x600);
308 + writel(enable_512fs, dev->io_base + 0x604);
311 + writel(0x03, dev->io_base + 0x500);
312 + writel(0x0002FF02, dev->io_base + 0x508);
317 +static void rcar_m3_disable(struct platform_device *pdev)
319 + struct dim2_hdm *dev = platform_get_drvdata(pdev);
321 + clk_disable_unprepare(dev->clk);
323 + /* disable PLLs and LVDS drivers */
324 + writel(0x0, dev->io_base + 0x600);
327 +/* ]] platform specific functions */
329 +enum dim2_platforms { FSL_MX6, RCAR_H2, RCAR_M3 };
331 +static struct dim2_platform_data plat_data[] = {
332 + [FSL_MX6] = { .enable = fsl_mx6_enable, .disable = fsl_mx6_disable },
333 + [RCAR_H2] = { .enable = rcar_h2_enable, .disable = rcar_h2_disable },
334 + [RCAR_M3] = { .enable = rcar_m3_enable, .disable = rcar_m3_disable },
337 +static const struct of_device_id dim2_of_match[] = {
339 + .compatible = "fsl,imx6q-mlb150",
340 + .data = plat_data + FSL_MX6
343 + .compatible = "renesas,mlp",
344 + .data = plat_data + RCAR_H2
347 + .compatible = "rcar,medialb-dim2",
348 + .data = plat_data + RCAR_M3
351 + .compatible = "xlnx,axi4-os62420_3pin-1.00.a",
354 + .compatible = "xlnx,axi4-os62420_6pin-1.00.a",
359 -MODULE_DEVICE_TABLE(platform, dim2_id);
360 +MODULE_DEVICE_TABLE(of, dim2_of_match);
362 static struct platform_driver dim2_driver = {
364 .remove = dim2_remove,
365 - .id_table = dim2_id,
368 + .of_match_table = dim2_of_match,
372 module_platform_driver(dim2_driver);
374 -MODULE_AUTHOR("Jain Roy Ambi <JainRoy.Ambi@microchip.com>");
375 MODULE_AUTHOR("Andrey Shvetsov <andrey.shvetsov@k2l.de>");
376 MODULE_DESCRIPTION("MediaLB DIM2 Hardware Dependent Module");
377 MODULE_LICENSE("GPL");