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
6 Platform specific initializations (pdata->init) must be done before DIM2
7 IP module startup (dim_startup).
9 Signed-off-by: Andrey Shvetsov <andrey.shvetsov@k2l.de>
11 hdm-dim2/dim2_hdm.c | 90 +++++++++++++++++++++++++++++++++++++++---------------------------------------------------
12 1 file changed, 39 insertions(+), 51 deletions(-)
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)
22 - * startup_dim - initialize the dim2 interface
23 - * @pdev: platform device
25 -static int startup_dim(struct platform_device *pdev)
27 - struct dim2_hdm *dev = platform_get_drvdata(pdev);
28 - struct dim2_platform_data *pdata = pdev->dev.platform_data;
33 - pr_err("missing platform data\n");
37 - ret = pdata->init ? pdata->init(pdata, dev->io_base) : 0;
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);
54 * try_start_dim_transfer - try to transfer a buffer on a channel
55 * @hdm_ch: channel specific data
57 @@ -727,10 +695,12 @@ static void dma_free(struct mbo *mbo, u32 size)
59 static int dim2_probe(struct platform_device *pdev)
61 + struct dim2_platform_data *pdata = pdev->dev.platform_data;
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);
75 + dev_err(&pdev->dev, "missing platform data\n");
79 + ret = pdata->init ? pdata->init(pdata, dev->io_base) : 0;
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);
88 + goto err_bsp_destroy;
91 irq = platform_get_irq(pdev, 0);
93 dev_err(&pdev->dev, "failed to get ahb0_int irq: %d\n", irq);
96 + goto err_shutdown_dim;
99 ret = devm_request_irq(&pdev->dev, irq, dim2_ahb_isr, 0,
100 "dim2_ahb0_int", dev);
102 dev_err(&pdev->dev, "failed to request ahb0_int irq %d\n", irq);
104 + goto err_shutdown_dim;
107 irq = platform_get_irq(pdev, 1);
109 dev_err(&pdev->dev, "failed to get mlb_int irq: %d\n", irq);
112 + goto err_shutdown_dim;
115 ret = devm_request_irq(&pdev->dev, irq, dim2_mlb_isr, 0,
116 "dim2_mlb_int", dev);
118 dev_err(&pdev->dev, "failed to request mlb_int irq %d\n", irq);
120 + goto err_shutdown_dim;
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,
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;
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)
139 goto err_unreg_iface;
141 - ret = startup_dim(pdev);
143 - dev_err(&pdev->dev, "failed to initialize DIM2\n");
144 - goto err_destroy_bus;
150 - dim2_sysfs_destroy(&dev->bus);
152 most_deregister_interface(&dev->most_iface);
154 kthread_stop(dev->netinfo_task);
158 + if (pdata && pdata->destroy)
159 + pdata->destroy(pdata);
163 @@ -863,6 +851,10 @@ static int dim2_remove(struct platform_device *pdev)
164 struct dim2_platform_data *pdata = pdev->dev.platform_data;
167 + dim2_sysfs_destroy(&dev->bus);
168 + most_deregister_interface(&dev->most_iface);
169 + kthread_stop(dev->netinfo_task);
171 spin_lock_irqsave(&dim_lock, flags);
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);
178 - dim2_sysfs_destroy(&dev->bus);
179 - most_deregister_interface(&dev->most_iface);
180 - kthread_stop(dev->netinfo_task);
183 * break link to local platform_device_id struct
184 * to prevent crash by unload platform device module