59c6ae6712ef646dc52bfc8337403104366c7a6a
[AGL/meta-agl-demo.git] / recipes-kernel / most / files / 0006-dim2-fix-startup-sequence.patch
1 From 63bcd9b421ae7927948bffec9566db47f40ea290 Mon Sep 17 00:00:00 2001
2 From: Andrey Shvetsov <andrey.shvetsov@k2l.de>
3 Date: Tue, 30 Jan 2018 17:34:09 +0100
4 Subject: [PATCH] staging: most: dim2: fix startup sequence
5
6 Platform specific initializations (pdata->init) must be done before DIM2
7 IP module startup (dim_startup).
8
9 Signed-off-by: Andrey Shvetsov <andrey.shvetsov@k2l.de>
10 ---
11  hdm-dim2/dim2_hdm.c | 90 +++++++++++++++++++++++++++++++++++++++---------------------------------------------------
12  1 file changed, 39 insertions(+), 51 deletions(-)
13
14 diff --git a/hdm-dim2/dim2_hdm.c b/hdm-dim2/dim2_hdm.c
15 index 893b8e4..e4629a5 100644
16 --- a/hdm-dim2/dim2_hdm.c
17 +++ b/hdm-dim2/dim2_hdm.c
18 @@ -155,38 +155,6 @@ void dimcb_on_error(u8 error_id, const char *error_message)
19  }
20
21  /**
22 - * startup_dim - initialize the dim2 interface
23 - * @pdev: platform device
24 - */
25 -static int startup_dim(struct platform_device *pdev)
26 -{
27 -       struct dim2_hdm *dev = platform_get_drvdata(pdev);
28 -       struct dim2_platform_data *pdata = pdev->dev.platform_data;
29 -       u8 hal_ret;
30 -       int ret;
31 -
32 -       if (!pdata) {
33 -               pr_err("missing platform data\n");
34 -               return -EINVAL;
35 -       }
36 -
37 -       ret = pdata->init ? pdata->init(pdata, dev->io_base) : 0;
38 -       if (ret)
39 -               return ret;
40 -
41 -       pr_info("sync: num of frames per sub-buffer: %u\n", fcnt);
42 -       hal_ret = dim_startup(dev->io_base, pdata->clk_speed, fcnt);
43 -       if (hal_ret != DIM_NO_ERROR) {
44 -               pr_err("dim_startup failed: %d\n", hal_ret);
45 -               if (pdata && pdata->destroy)
46 -                       pdata->destroy(pdata);
47 -               return -ENODEV;
48 -       }
49 -
50 -       return 0;
51 -}
52 -
53 -/**
54   * try_start_dim_transfer - try to transfer a buffer on a channel
55   * @hdm_ch: channel specific data
56   *
57 @@ -727,10 +695,12 @@ static void dma_free(struct mbo *mbo, u32 size)
58   */
59  static int dim2_probe(struct platform_device *pdev)
60  {
61 +       struct dim2_platform_data *pdata = pdev->dev.platform_data;
62         struct dim2_hdm *dev;
63         struct resource *res;
64         int ret, i;
65         struct kobject *kobj;
66 +       u8 hal_ret;
67         int irq;
68
69         dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
70 @@ -745,38 +715,59 @@ static int dim2_probe(struct platform_device *pdev)
71         if (IS_ERR(dev->io_base))
72                 return PTR_ERR(dev->io_base);
73
74 +       if (!pdata) {
75 +               dev_err(&pdev->dev, "missing platform data\n");
76 +               return -EINVAL;
77 +       }
78 +
79 +       ret = pdata->init ? pdata->init(pdata, dev->io_base) : 0;
80 +       if (ret)
81 +               return ret;
82 +
83 +       dev_info(&pdev->dev, "sync: num of frames per sub-buffer: %u\n", fcnt);
84 +       hal_ret = dim_startup(dev->io_base, pdata->clk_speed, fcnt);
85 +       if (hal_ret != DIM_NO_ERROR) {
86 +               dev_err(&pdev->dev, "dim_startup failed: %d\n", hal_ret);
87 +               ret = -ENODEV;
88 +               goto err_bsp_destroy;
89 +       }
90 +
91         irq = platform_get_irq(pdev, 0);
92         if (irq < 0) {
93                 dev_err(&pdev->dev, "failed to get ahb0_int irq: %d\n", irq);
94 -               return irq;
95 +               ret = irq;
96 +               goto err_shutdown_dim;
97         }
98
99         ret = devm_request_irq(&pdev->dev, irq, dim2_ahb_isr, 0,
100                                "dim2_ahb0_int", dev);
101         if (ret) {
102                 dev_err(&pdev->dev, "failed to request ahb0_int irq %d\n", irq);
103 -               return ret;
104 +               goto err_shutdown_dim;
105         }
106
107         irq = platform_get_irq(pdev, 1);
108         if (irq < 0) {
109                 dev_err(&pdev->dev, "failed to get mlb_int irq: %d\n", irq);
110 -               return irq;
111 +               ret = irq;
112 +               goto err_shutdown_dim;
113         }
114
115         ret = devm_request_irq(&pdev->dev, irq, dim2_mlb_isr, 0,
116                                "dim2_mlb_int", dev);
117         if (ret) {
118                 dev_err(&pdev->dev, "failed to request mlb_int irq %d\n", irq);
119 -               return ret;
120 +               goto err_shutdown_dim;
121         }
122
123         init_waitqueue_head(&dev->netinfo_waitq);
124         dev->deliver_netinfo = 0;
125 -       dev->netinfo_task = kthread_run(&deliver_netinfo_thread, (void *)dev,
126 +       dev->netinfo_task = kthread_run(&deliver_netinfo_thread, dev,
127                                         "dim2_netinfo");
128 -       if (IS_ERR(dev->netinfo_task))
129 -               return PTR_ERR(dev->netinfo_task);
130 +       if (IS_ERR(dev->netinfo_task)) {
131 +               ret = PTR_ERR(dev->netinfo_task);
132 +               goto err_shutdown_dim;
133 +       }
134
135         for (i = 0; i < DMA_CHANNELS; i++) {
136                 struct most_channel_capability *cap = dev->capabilities + i;
137 @@ -833,20 +824,17 @@ static int dim2_probe(struct platform_device *pdev)
138         if (ret)
139                 goto err_unreg_iface;
140
141 -       ret = startup_dim(pdev);
142 -       if (ret) {
143 -               dev_err(&pdev->dev, "failed to initialize DIM2\n");
144 -               goto err_destroy_bus;
145 -       }
146 -
147         return 0;
148
149 -err_destroy_bus:
150 -       dim2_sysfs_destroy(&dev->bus);
151  err_unreg_iface:
152         most_deregister_interface(&dev->most_iface);
153  err_stop_thread:
154         kthread_stop(dev->netinfo_task);
155 +err_shutdown_dim:
156 +       dim_shutdown();
157 +err_bsp_destroy:
158 +       if (pdata && pdata->destroy)
159 +               pdata->destroy(pdata);
160
161         return ret;
162  }
163 @@ -863,6 +851,10 @@ static int dim2_remove(struct platform_device *pdev)
164         struct dim2_platform_data *pdata = pdev->dev.platform_data;
165         unsigned long flags;
166
167 +       dim2_sysfs_destroy(&dev->bus);
168 +       most_deregister_interface(&dev->most_iface);
169 +       kthread_stop(dev->netinfo_task);
170 +
171         spin_lock_irqsave(&dim_lock, flags);
172         dim_shutdown();
173         spin_unlock_irqrestore(&dim_lock, flags);
174 @@ -870,10 +862,6 @@ static int dim2_remove(struct platform_device *pdev)
175         if (pdata && pdata->destroy)
176                 pdata->destroy(pdata);
177
178 -       dim2_sysfs_destroy(&dev->bus);
179 -       most_deregister_interface(&dev->most_iface);
180 -       kthread_stop(dev->netinfo_task);
181 -
182         /*
183          * break link to local platform_device_id struct
184          * to prevent crash by unload platform device module
185 --
186 libgit2 0.26.0