55b760ca40b5981c29c4a345d41b44d9f50d32de
[openwrt/staging/lynxis.git] /
1 From f468b36a6b998cf9848bfcc24370cf13b2730b93 Mon Sep 17 00:00:00 2001
2 From: Martin Sperl <kernel@martin.sperl.org>
3 Date: Tue, 26 Apr 2016 14:59:21 +0000
4 Subject: [PATCH 050/725] MISC: bcm2835: smi: use clock manager and fix reload
5 issues
6
7 Use clock manager instead of self-made clockmanager.
8
9 Also fix some error paths that showd up during development
10 (especially missing release of dma resources on rmmod)
11
12 Signed-off-by: Martin Sperl <kernel@martin.sperl.org>
13 ---
14 drivers/misc/bcm2835_smi.c | 86 +++++++++++++-------------------------
15 1 file changed, 28 insertions(+), 58 deletions(-)
16
17 --- a/drivers/misc/bcm2835_smi.c
18 +++ b/drivers/misc/bcm2835_smi.c
19 @@ -34,6 +34,7 @@
20 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
21 */
22
23 +#include <linux/clk.h>
24 #include <linux/kernel.h>
25 #include <linux/module.h>
26 #include <linux/of.h>
27 @@ -62,7 +63,7 @@
28 struct bcm2835_smi_instance {
29 struct device *dev;
30 struct smi_settings settings;
31 - __iomem void *smi_regs_ptr, *cm_smi_regs_ptr;
32 + __iomem void *smi_regs_ptr;
33 dma_addr_t smi_regs_busaddr;
34
35 struct dma_chan *dma_chan;
36 @@ -72,8 +73,7 @@ struct bcm2835_smi_instance {
37
38 struct scatterlist buffer_sgl;
39
40 - int clock_source;
41 - int clock_divisor;
42 + struct clk *clk;
43
44 /* Sometimes we are called into in an atomic context (e.g. by
45 JFFS2 + MTD) so we can't use a mutex */
46 @@ -82,42 +82,6 @@ struct bcm2835_smi_instance {
47
48 /****************************************************************************
49 *
50 -* SMI clock manager setup
51 -*
52 -***************************************************************************/
53 -
54 -static inline void write_smi_cm_reg(struct bcm2835_smi_instance *inst,
55 - u32 val, unsigned reg)
56 -{
57 - writel(CM_PWD | val, inst->cm_smi_regs_ptr + reg);
58 -}
59 -
60 -static inline u32 read_smi_cm_reg(struct bcm2835_smi_instance *inst,
61 - unsigned reg)
62 -{
63 - return readl(inst->cm_smi_regs_ptr + reg);
64 -}
65 -
66 -static void smi_setup_clock(struct bcm2835_smi_instance *inst)
67 -{
68 - dev_dbg(inst->dev, "Setting up clock...");
69 - /* Disable SMI clock and wait for it to stop. */
70 - write_smi_cm_reg(inst, 0, CM_SMI_CTL);
71 - while (read_smi_cm_reg(inst, CM_SMI_CTL) & CM_SMI_CTL_BUSY)
72 - ;
73 -
74 - write_smi_cm_reg(inst, (inst->clock_divisor << CM_SMI_DIV_DIVI_OFFS),
75 - CM_SMI_DIV);
76 - write_smi_cm_reg(inst, (inst->clock_source << CM_SMI_CTL_SRC_OFFS),
77 - CM_SMI_CTL);
78 -
79 - /* Enable the clock */
80 - write_smi_cm_reg(inst, (inst->clock_source << CM_SMI_CTL_SRC_OFFS) |
81 - CM_SMI_CTL_ENAB, CM_SMI_CTL);
82 -}
83 -
84 -/****************************************************************************
85 -*
86 * SMI peripheral setup
87 *
88 ***************************************************************************/
89 @@ -894,42 +858,40 @@ static int bcm2835_smi_probe(struct plat
90 struct device_node *node = dev->of_node;
91 struct resource *ioresource;
92 struct bcm2835_smi_instance *inst;
93 + const __be32 *addr;
94
95 + /* We require device tree support */
96 + if (!node)
97 + return -EINVAL;
98 /* Allocate buffers and instance data */
99 -
100 inst = devm_kzalloc(dev, sizeof(struct bcm2835_smi_instance),
101 GFP_KERNEL);
102 -
103 if (!inst)
104 return -ENOMEM;
105
106 inst->dev = dev;
107 spin_lock_init(&inst->transaction_lock);
108
109 - /* We require device tree support */
110 - if (!node)
111 - return -EINVAL;
112 -
113 ioresource = platform_get_resource(pdev, IORESOURCE_MEM, 0);
114 inst->smi_regs_ptr = devm_ioremap_resource(dev, ioresource);
115 - ioresource = platform_get_resource(pdev, IORESOURCE_MEM, 1);
116 - inst->cm_smi_regs_ptr = devm_ioremap_resource(dev, ioresource);
117 - inst->smi_regs_busaddr = be32_to_cpu(
118 - *of_get_address(node, 0, NULL, NULL));
119 - of_property_read_u32(node,
120 - "brcm,smi-clock-source",
121 - &inst->clock_source);
122 - of_property_read_u32(node,
123 - "brcm,smi-clock-divisor",
124 - &inst->clock_divisor);
125 + if (IS_ERR(inst->smi_regs_ptr)) {
126 + err = PTR_ERR(inst->smi_regs_ptr);
127 + goto err;
128 + }
129 + addr = of_get_address(node, 0, NULL, NULL);
130 + inst->smi_regs_busaddr = be32_to_cpu(addr);
131
132 err = bcm2835_smi_dma_setup(inst);
133 if (err)
134 - return err;
135 + goto err;
136
137 - /* Finally, do peripheral setup */
138 + /* request clock */
139 + inst->clk = devm_clk_get(dev, NULL);
140 + if (!inst->clk)
141 + goto err;
142 + clk_prepare_enable(inst->clk);
143
144 - smi_setup_clock(inst);
145 + /* Finally, do peripheral setup */
146 smi_setup_regs(inst);
147
148 platform_set_drvdata(pdev, inst);
149 @@ -937,6 +899,9 @@ static int bcm2835_smi_probe(struct plat
150 dev_info(inst->dev, "initialised");
151
152 return 0;
153 +err:
154 + kfree(inst);
155 + return err;
156 }
157
158 /****************************************************************************
159 @@ -950,6 +915,11 @@ static int bcm2835_smi_remove(struct pla
160 struct bcm2835_smi_instance *inst = platform_get_drvdata(pdev);
161 struct device *dev = inst->dev;
162
163 + dmaengine_terminate_all(inst->dma_chan);
164 + dma_release_channel(inst->dma_chan);
165 +
166 + clk_disable_unprepare(inst->clk);
167 +
168 dev_info(dev, "SMI device removed - OK");
169 return 0;
170 }