1 From f7cccb2e66f0187f69a432536f227b32a458f94b 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/806] MISC: bcm2835: smi: use clock manager and fix reload
7 Use clock manager instead of self-made clockmanager.
9 Also fix some error paths that showd up during development
10 (especially missing release of dma resources on rmmod)
12 Signed-off-by: Martin Sperl <kernel@martin.sperl.org>
14 drivers/misc/bcm2835_smi.c | 86 +++++++++++++-------------------------
15 1 file changed, 28 insertions(+), 58 deletions(-)
17 --- a/drivers/misc/bcm2835_smi.c
18 +++ b/drivers/misc/bcm2835_smi.c
20 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 +#include <linux/clk.h>
24 #include <linux/kernel.h>
25 #include <linux/module.h>
28 struct bcm2835_smi_instance {
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;
35 struct dma_chan *dma_chan;
36 @@ -72,8 +73,7 @@ struct bcm2835_smi_instance {
38 struct scatterlist buffer_sgl;
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 {
48 /****************************************************************************
50 -* SMI clock manager setup
52 -***************************************************************************/
54 -static inline void write_smi_cm_reg(struct bcm2835_smi_instance *inst,
55 - u32 val, unsigned reg)
57 - writel(CM_PWD | val, inst->cm_smi_regs_ptr + reg);
60 -static inline u32 read_smi_cm_reg(struct bcm2835_smi_instance *inst,
63 - return readl(inst->cm_smi_regs_ptr + reg);
66 -static void smi_setup_clock(struct bcm2835_smi_instance *inst)
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)
74 - write_smi_cm_reg(inst, (inst->clock_divisor << CM_SMI_DIV_DIVI_OFFS),
76 - write_smi_cm_reg(inst, (inst->clock_source << CM_SMI_CTL_SRC_OFFS),
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);
84 -/****************************************************************************
86 * SMI peripheral setup
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;
95 + /* We require device tree support */
98 /* Allocate buffers and instance data */
100 inst = devm_kzalloc(dev, sizeof(struct bcm2835_smi_instance),
107 spin_lock_init(&inst->transaction_lock);
109 - /* We require device tree support */
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);
129 + addr = of_get_address(node, 0, NULL, NULL);
130 + inst->smi_regs_busaddr = be32_to_cpu(addr);
132 err = bcm2835_smi_dma_setup(inst);
137 - /* Finally, do peripheral setup */
138 + /* request clock */
139 + inst->clk = devm_clk_get(dev, NULL);
142 + clk_prepare_enable(inst->clk);
144 - smi_setup_clock(inst);
145 + /* Finally, do peripheral setup */
146 smi_setup_regs(inst);
148 platform_set_drvdata(pdev, inst);
149 @@ -937,6 +899,9 @@ static int bcm2835_smi_probe(struct plat
150 dev_info(inst->dev, "initialised");
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;
163 + dmaengine_terminate_all(inst->dma_chan);
164 + dma_release_channel(inst->dma_chan);
166 + clk_disable_unprepare(inst->clk);
168 dev_info(dev, "SMI device removed - OK");