Skip to content

Commit e209a02

Browse files
msperlpopcornmix
authored andcommitted
MISC: bcm2835: smi: use clock manager and fix reload issues
Use clock manager instead of self-made clockmanager. Also fix some error paths that showd up during development (especially missing release of dma resources on rmmod) Signed-off-by: Martin Sperl <kernel@martin.sperl.org>
1 parent 7a95d43 commit e209a02

1 file changed

Lines changed: 28 additions & 58 deletions

File tree

‎drivers/misc/bcm2835_smi.c‎

Lines changed: 28 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3535
*/
3636

37+
#include <linux/clk.h>
3738
#include <linux/kernel.h>
3839
#include <linux/module.h>
3940
#include <linux/of.h>
@@ -62,7 +63,7 @@
6263
struct bcm2835_smi_instance {
6364
struct device *dev;
6465
struct smi_settings settings;
65-
__iomem void *smi_regs_ptr, *cm_smi_regs_ptr;
66+
__iomem void *smi_regs_ptr;
6667
dma_addr_t smi_regs_busaddr;
6768

6869
struct dma_chan *dma_chan;
@@ -72,50 +73,13 @@ struct bcm2835_smi_instance {
7273

7374
struct scatterlist buffer_sgl;
7475

75-
int clock_source;
76-
int clock_divisor;
76+
struct clk *clk;
7777

7878
/* Sometimes we are called into in an atomic context (e.g. by
7979
JFFS2 + MTD) so we can't use a mutex */
8080
spinlock_t transaction_lock;
8181
};
8282

83-
/****************************************************************************
84-
*
85-
* SMI clock manager setup
86-
*
87-
***************************************************************************/
88-
89-
static inline void write_smi_cm_reg(struct bcm2835_smi_instance *inst,
90-
u32 val, unsigned reg)
91-
{
92-
writel(CM_PWD | val, inst->cm_smi_regs_ptr + reg);
93-
}
94-
95-
static inline u32 read_smi_cm_reg(struct bcm2835_smi_instance *inst,
96-
unsigned reg)
97-
{
98-
return readl(inst->cm_smi_regs_ptr + reg);
99-
}
100-
101-
static void smi_setup_clock(struct bcm2835_smi_instance *inst)
102-
{
103-
dev_dbg(inst->dev, "Setting up clock...");
104-
/* Disable SMI clock and wait for it to stop. */
105-
write_smi_cm_reg(inst, 0, CM_SMI_CTL);
106-
while (read_smi_cm_reg(inst, CM_SMI_CTL) & CM_SMI_CTL_BUSY)
107-
;
108-
109-
write_smi_cm_reg(inst, (inst->clock_divisor << CM_SMI_DIV_DIVI_OFFS),
110-
CM_SMI_DIV);
111-
write_smi_cm_reg(inst, (inst->clock_source << CM_SMI_CTL_SRC_OFFS),
112-
CM_SMI_CTL);
113-
114-
/* Enable the clock */
115-
write_smi_cm_reg(inst, (inst->clock_source << CM_SMI_CTL_SRC_OFFS) |
116-
CM_SMI_CTL_ENAB, CM_SMI_CTL);
117-
}
118-
11983
/****************************************************************************
12084
*
12185
* SMI peripheral setup
@@ -894,49 +858,50 @@ static int bcm2835_smi_probe(struct platform_device *pdev)
894858
struct device_node *node = dev->of_node;
895859
struct resource *ioresource;
896860
struct bcm2835_smi_instance *inst;
861+
const __be32 *addr;
897862

863+
/* We require device tree support */
864+
if (!node)
865+
return -EINVAL;
898866
/* Allocate buffers and instance data */
899-
900867
inst = devm_kzalloc(dev, sizeof(struct bcm2835_smi_instance),
901868
GFP_KERNEL);
902-
903869
if (!inst)
904870
return -ENOMEM;
905871

906872
inst->dev = dev;
907873
spin_lock_init(&inst->transaction_lock);
908874

909-
/* We require device tree support */
910-
if (!node)
911-
return -EINVAL;
912-
913875
ioresource = platform_get_resource(pdev, IORESOURCE_MEM, 0);
914876
inst->smi_regs_ptr = devm_ioremap_resource(dev, ioresource);
915-
ioresource = platform_get_resource(pdev, IORESOURCE_MEM, 1);
916-
inst->cm_smi_regs_ptr = devm_ioremap_resource(dev, ioresource);
917-
inst->smi_regs_busaddr = be32_to_cpu(
918-
*of_get_address(node, 0, NULL, NULL));
919-
of_property_read_u32(node,
920-
"brcm,smi-clock-source",
921-
&inst->clock_source);
922-
of_property_read_u32(node,
923-
"brcm,smi-clock-divisor",
924-
&inst->clock_divisor);
877+
if (IS_ERR(inst->smi_regs_ptr)) {
878+
err = PTR_ERR(inst->smi_regs_ptr);
879+
goto err;
880+
}
881+
addr = of_get_address(node, 0, NULL, NULL);
882+
inst->smi_regs_busaddr = be32_to_cpu(addr);
925883

926884
err = bcm2835_smi_dma_setup(inst);
927885
if (err)
928-
return err;
886+
goto err;
929887

930-
/* Finally, do peripheral setup */
888+
/* request clock */
889+
inst->clk = devm_clk_get(dev, NULL);
890+
if (!inst->clk)
891+
goto err;
892+
clk_prepare_enable(inst->clk);
931893

932-
smi_setup_clock(inst);
894+
/* Finally, do peripheral setup */
933895
smi_setup_regs(inst);
934896

935897
platform_set_drvdata(pdev, inst);
936898

937899
dev_info(inst->dev, "initialised");
938900

939901
return 0;
902+
err:
903+
kfree(inst);
904+
return err;
940905
}
941906

942907
/****************************************************************************
@@ -950,6 +915,11 @@ static int bcm2835_smi_remove(struct platform_device *pdev)
950915
struct bcm2835_smi_instance *inst = platform_get_drvdata(pdev);
951916
struct device *dev = inst->dev;
952917

918+
dmaengine_terminate_all(inst->dma_chan);
919+
dma_release_channel(inst->dma_chan);
920+
921+
clk_disable_unprepare(inst->clk);
922+
953923
dev_info(dev, "SMI device removed - OK");
954924
return 0;
955925
}

0 commit comments

Comments
 (0)