udisks: services: change default.target to multi-user.target
[AGL/meta-agl-demo.git] / recipes-kernel / most / files / 0007-dim2-use-device-tree.patch
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
5
6 Current dim2 driver expects the existence of a platform driver that
7 implements the platform specific initialization and delivery of the irq
8 numbers.
9
10 This patch integrates the device tree activity and platform specific
11 code into the driver.
12
13 Signed-off-by: Andrey Shvetsov <andrey.shvetsov@k2l.de>
14 ---
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
29
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
34 @@ -14,6 +14,7 @@
35  #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
36
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>
42 @@ -21,13 +22,13 @@
43  #include <linux/interrupt.h>
44  #include <linux/slab.h>
45  #include <linux/io.h>
46 +#include <linux/clk.h>
47  #include <linux/dma-mapping.h>
48  #include <linux/sched.h>
49  #include <linux/kthread.h>
50
51  #include <mostcore.h>
52  #include "dim2_hal.h"
53 -#include "dim2_hdm.h"
54  #include "dim2_errors.h"
55  #include "dim2_sysfs.h"
56
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;
61 +       u8 clk_speed;
62 +       struct clk *clk;
63 +       struct clk *clk_pll;
64         struct task_struct *netinfo_task;
65         wait_queue_head_t netinfo_waitq;
66         int deliver_netinfo;
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 *);
72 +};
73 +
74 +struct dim2_platform_data {
75 +       int (*enable)(struct platform_device *);
76 +       void (*disable)(struct platform_device *);
77  };
78
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);
82  }
83
84 +static const struct of_device_id dim2_of_match[];
85 +
86  /*
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)
90   */
91  static int dim2_probe(struct platform_device *pdev)
92  {
93 -       struct dim2_platform_data *pdata = pdev->dev.platform_data;
94 +       const struct dim2_platform_data *pdata;
95         struct dim2_hdm *dev;
96         struct resource *res;
97         int ret, i;
98 @@ -703,6 +715,8 @@ static int dim2_probe(struct platform_device *pdev)
99         u8 hal_ret;
100         int irq;
101
102 +       enum { MLB_INT_IDX, AHB0_INT_IDX };
103 +
104         dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
105         if (!dev)
106                 return -ENOMEM;
107 @@ -710,29 +724,30 @@ static int dim2_probe(struct platform_device *pdev)
108         dev->atx_idx = -1;
109
110         platform_set_drvdata(pdev, dev);
111 +
112 +       dev->clk_speed = CLK_4096FS;
113 +
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);
118
119 -       if (!pdata) {
120 -               dev_err(&pdev->dev, "missing platform data\n");
121 -               return -EINVAL;
122 -       }
123 -
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;
127         if (ret)
128                 return ret;
129
130 +       dev->disable_platform = pdata ? pdata->disable : 0;
131 +
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);
137                 ret = -ENODEV;
138 -               goto err_bsp_destroy;
139 +               goto err_disable_platform;
140         }
141
142 -       irq = platform_get_irq(pdev, 0);
143 +       irq = platform_get_irq(pdev, AHB0_INT_IDX);
144         if (irq < 0) {
145                 dev_err(&pdev->dev, "failed to get ahb0_int irq: %d\n", irq);
146                 ret = irq;
147 @@ -746,7 +761,7 @@ static int dim2_probe(struct platform_device *pdev)
148                 goto err_shutdown_dim;
149         }
150
151 -       irq = platform_get_irq(pdev, 1);
152 +       irq = platform_get_irq(pdev, MLB_INT_IDX);
153         if (irq < 0) {
154                 dev_err(&pdev->dev, "failed to get mlb_int irq: %d\n", irq);
155                 ret = irq;
156 @@ -832,9 +847,9 @@ static int dim2_probe(struct platform_device *pdev)
157         kthread_stop(dev->netinfo_task);
158  err_shutdown_dim:
159         dim_shutdown();
160 -err_bsp_destroy:
161 -       if (pdata && pdata->destroy)
162 -               pdata->destroy(pdata);
163 +err_disable_platform:
164 +       if (dev->disable_platform)
165 +               dev->disable_platform(pdev);
166
167         return ret;
168  }
169 @@ -848,7 +863,6 @@ static int dim2_probe(struct platform_device *pdev)
170  static int dim2_remove(struct platform_device *pdev)
171  {
172         struct dim2_hdm *dev = platform_get_drvdata(pdev);
173 -       struct dim2_platform_data *pdata = pdev->dev.platform_data;
174         unsigned long flags;
175
176         dim2_sysfs_destroy(&dev->bus);
177 @@ -859,37 +873,187 @@ static int dim2_remove(struct platform_device *pdev)
178         dim_shutdown();
179         spin_unlock_irqrestore(&dim_lock, flags);
180
181 -       if (pdata && pdata->destroy)
182 -               pdata->destroy(pdata);
183 +       if (dev->disable_platform)
184 +               dev->disable_platform(pdev);
185 +
186 +       return 0;
187 +}
188 +
189 +/* platform specific functions [[ */
190 +
191 +static int fsl_mx6_enable(struct platform_device *pdev)
192 +{
193 +       struct dim2_hdm *dev = platform_get_drvdata(pdev);
194 +       int ret;
195 +
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");
199 +               return -EFAULT;
200 +       }
201 +
202 +       ret = clk_prepare_enable(dev->clk);
203 +       if (ret) {
204 +               dev_err(&pdev->dev, "%s\n", "clk_prepare_enable failed");
205 +               return ret;
206 +       }
207 +
208 +       if (dev->clk_speed >= CLK_2048FS) {
209 +               /* enable pll */
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);
214 +                       return -EFAULT;
215 +               }
216 +
217 +               writel(0x888, dev->io_base + 0x38);
218 +               clk_prepare_enable(dev->clk_pll);
219 +       }
220 +
221 +       return 0;
222 +}
223 +
224 +static void fsl_mx6_disable(struct platform_device *pdev)
225 +{
226 +       struct dim2_hdm *dev = platform_get_drvdata(pdev);
227 +
228 +       if (dev->clk_speed >= CLK_2048FS)
229 +               clk_disable_unprepare(dev->clk_pll);
230 +
231 +       clk_disable_unprepare(dev->clk);
232 +}
233 +
234 +static int rcar_h2_enable(struct platform_device *pdev)
235 +{
236 +       struct dim2_hdm *dev = platform_get_drvdata(pdev);
237 +       int ret;
238 +
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);
243 +       }
244 +
245 +       ret = clk_prepare_enable(dev->clk);
246 +       if (ret) {
247 +               dev_err(&pdev->dev, "%s\n", "clk_prepare_enable failed");
248 +               return ret;
249 +       }
250 +
251 +       if (dev->clk_speed >= CLK_2048FS) {
252 +               /* enable MLP pll and LVDS drivers */
253 +               writel(0x03, dev->io_base + 0x600);
254 +               /* set bias */
255 +               writel(0x888, dev->io_base + 0x38);
256 +       } else {
257 +               /* PLL */
258 +               writel(0x04, dev->io_base + 0x600);
259 +       }
260 +
261
262 -       /*
263 -        * break link to local platform_device_id struct
264 -        * to prevent crash by unload platform device module
265 -        */
266 -       pdev->id_entry = NULL;
267 +       /* BBCR = 0b11 */
268 +       writel(0x03, dev->io_base + 0x500);
269 +       writel(0x0002FF02, dev->io_base + 0x508);
270
271         return 0;
272  }
273
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)
278 +{
279 +       struct dim2_hdm *dev = platform_get_drvdata(pdev);
280 +
281 +       clk_disable_unprepare(dev->clk);
282 +
283 +       /* disable PLLs and LVDS drivers */
284 +       writel(0x0, dev->io_base + 0x600);
285 +}
286 +
287 +static int rcar_m3_enable(struct platform_device *pdev)
288 +{
289 +       struct dim2_hdm *dev = platform_get_drvdata(pdev);
290 +       u32 enable_512fs = dev->clk_speed == CLK_512FS;
291 +       int ret;
292 +
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);
297 +       }
298 +
299 +       ret = clk_prepare_enable(dev->clk);
300 +       if (ret) {
301 +               dev_err(&pdev->dev, "%s\n", "clk_prepare_enable failed");
302 +               return ret;
303 +       }
304 +
305 +       /* PLL */
306 +       writel(0x04, dev->io_base + 0x600);
307 +
308 +       writel(enable_512fs, dev->io_base + 0x604);
309 +
310 +       /* BBCR = 0b11 */
311 +       writel(0x03, dev->io_base + 0x500);
312 +       writel(0x0002FF02, dev->io_base + 0x508);
313 +
314 +       return 0;
315 +}
316 +
317 +static void rcar_m3_disable(struct platform_device *pdev)
318 +{
319 +       struct dim2_hdm *dev = platform_get_drvdata(pdev);
320 +
321 +       clk_disable_unprepare(dev->clk);
322 +
323 +       /* disable PLLs and LVDS drivers */
324 +       writel(0x0, dev->io_base + 0x600);
325 +}
326 +
327 +/* ]] platform specific functions */
328 +
329 +enum dim2_platforms { FSL_MX6, RCAR_H2, RCAR_M3 };
330 +
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 },
335 +};
336 +
337 +static const struct of_device_id dim2_of_match[] = {
338 +       {
339 +               .compatible = "fsl,imx6q-mlb150",
340 +               .data = plat_data + FSL_MX6
341 +       },
342 +       {
343 +               .compatible = "renesas,mlp",
344 +               .data = plat_data + RCAR_H2
345 +       },
346 +       {
347 +               .compatible = "rcar,medialb-dim2",
348 +               .data = plat_data + RCAR_M3
349 +       },
350 +       {
351 +               .compatible = "xlnx,axi4-os62420_3pin-1.00.a",
352 +       },
353 +       {
354 +               .compatible = "xlnx,axi4-os62420_6pin-1.00.a",
355 +       },
356 +       {},
357  };
358
359 -MODULE_DEVICE_TABLE(platform, dim2_id);
360 +MODULE_DEVICE_TABLE(of, dim2_of_match);
361
362  static struct platform_driver dim2_driver = {
363         .probe = dim2_probe,
364         .remove = dim2_remove,
365 -       .id_table = dim2_id,
366         .driver = {
367                 .name = "hdm_dim2",
368 +               .of_match_table = dim2_of_match,
369         },
370  };
371
372  module_platform_driver(dim2_driver);
373
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");
378 libgit2 0.26.0