2 * dw_spi_mmio.c - Memory-mapped interface driver for DW SPI Core
4 * Copyright (c) 2010, Octasic semiconductor.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
11 #include <linux/clk.h>
12 #include <linux/err.h>
13 #include <linux/interrupt.h>
14 #include <linux/platform_device.h>
15 #include <linux/slab.h>
16 #include <linux/spi/dw_spi.h>
17 #include <linux/spi/spi.h>
19 #define DRIVER_NAME "dw_spi_mmio"
26 static int __devinit
dw_spi_mmio_probe(struct platform_device
*pdev
)
28 struct dw_spi_mmio
*dwsmmio
;
30 struct resource
*mem
, *ioarea
;
33 dwsmmio
= kzalloc(sizeof(struct dw_spi_mmio
), GFP_KERNEL
);
41 /* Get basic io resource and map it */
42 mem
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
44 dev_err(&pdev
->dev
, "no mem resource?\n");
49 ioarea
= request_mem_region(mem
->start
, resource_size(mem
),
52 dev_err(&pdev
->dev
, "SPI region already claimed\n");
57 dws
->regs
= ioremap_nocache(mem
->start
, resource_size(mem
));
59 dev_err(&pdev
->dev
, "SPI region already mapped\n");
64 dws
->irq
= platform_get_irq(pdev
, 0);
66 dev_err(&pdev
->dev
, "no irq resource?\n");
67 ret
= dws
->irq
; /* -ENXIO */
71 dwsmmio
->clk
= clk_get(&pdev
->dev
, NULL
);
72 if (IS_ERR(dwsmmio
->clk
)) {
73 ret
= PTR_ERR(dwsmmio
->clk
);
76 clk_enable(dwsmmio
->clk
);
78 dws
->parent_dev
= &pdev
->dev
;
81 dws
->max_freq
= clk_get_rate(dwsmmio
->clk
);
83 ret
= dw_spi_add_host(dws
);
87 platform_set_drvdata(pdev
, dwsmmio
);
91 clk_disable(dwsmmio
->clk
);
92 clk_put(dwsmmio
->clk
);
95 free_irq(dws
->irq
, dws
);
99 release_mem_region(mem
->start
, resource_size(mem
));
106 static int __devexit
dw_spi_mmio_remove(struct platform_device
*pdev
)
108 struct dw_spi_mmio
*dwsmmio
= platform_get_drvdata(pdev
);
109 struct resource
*mem
;
111 platform_set_drvdata(pdev
, NULL
);
113 clk_disable(dwsmmio
->clk
);
114 clk_put(dwsmmio
->clk
);
117 free_irq(dwsmmio
->dws
.irq
, &dwsmmio
->dws
);
118 dw_spi_remove_host(&dwsmmio
->dws
);
119 iounmap(dwsmmio
->dws
.regs
);
122 mem
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
123 release_mem_region(mem
->start
, resource_size(mem
));
127 static struct platform_driver dw_spi_mmio_driver
= {
128 .remove
= __devexit_p(dw_spi_mmio_remove
),
131 .owner
= THIS_MODULE
,
135 static int __init
dw_spi_mmio_init(void)
137 return platform_driver_probe(&dw_spi_mmio_driver
, dw_spi_mmio_probe
);
139 module_init(dw_spi_mmio_init
);
141 static void __exit
dw_spi_mmio_exit(void)
143 platform_driver_unregister(&dw_spi_mmio_driver
);
145 module_exit(dw_spi_mmio_exit
);
147 MODULE_AUTHOR("Jean-Hugues Deschenes <jean-hugues.deschenes@octasic.com>");
148 MODULE_DESCRIPTION("Memory-mapped I/O interface driver for DW SPI Core");
149 MODULE_LICENSE("GPL v2");