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/interrupt.h>
13 #include <linux/platform_device.h>
14 #include <linux/slab.h>
15 #include <linux/spi/dw_spi.h>
16 #include <linux/spi/spi.h>
18 #define DRIVER_NAME "dw_spi_mmio"
25 static int __devinit
dw_spi_mmio_probe(struct platform_device
*pdev
)
27 struct dw_spi_mmio
*dwsmmio
;
29 struct resource
*mem
, *ioarea
;
32 dwsmmio
= kzalloc(sizeof(struct dw_spi_mmio
), GFP_KERNEL
);
40 /* Get basic io resource and map it */
41 mem
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
43 dev_err(&pdev
->dev
, "no mem resource?\n");
48 ioarea
= request_mem_region(mem
->start
, resource_size(mem
),
51 dev_err(&pdev
->dev
, "SPI region already claimed\n");
56 dws
->regs
= ioremap_nocache(mem
->start
, resource_size(mem
));
58 dev_err(&pdev
->dev
, "SPI region already mapped\n");
63 dws
->irq
= platform_get_irq(pdev
, 0);
65 dev_err(&pdev
->dev
, "no irq resource?\n");
66 ret
= dws
->irq
; /* -ENXIO */
70 dwsmmio
->clk
= clk_get(&pdev
->dev
, NULL
);
75 clk_enable(dwsmmio
->clk
);
77 dws
->parent_dev
= &pdev
->dev
;
80 dws
->max_freq
= clk_get_rate(dwsmmio
->clk
);
82 ret
= dw_spi_add_host(dws
);
86 platform_set_drvdata(pdev
, dwsmmio
);
90 clk_disable(dwsmmio
->clk
);
91 clk_put(dwsmmio
->clk
);
94 free_irq(dws
->irq
, dws
);
98 release_mem_region(mem
->start
, resource_size(mem
));
105 static int __devexit
dw_spi_mmio_remove(struct platform_device
*pdev
)
107 struct dw_spi_mmio
*dwsmmio
= platform_get_drvdata(pdev
);
108 struct resource
*mem
;
110 platform_set_drvdata(pdev
, NULL
);
112 clk_disable(dwsmmio
->clk
);
113 clk_put(dwsmmio
->clk
);
116 free_irq(dwsmmio
->dws
.irq
, &dwsmmio
->dws
);
117 dw_spi_remove_host(&dwsmmio
->dws
);
118 iounmap(dwsmmio
->dws
.regs
);
121 mem
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
122 release_mem_region(mem
->start
, resource_size(mem
));
126 static struct platform_driver dw_spi_mmio_driver
= {
127 .remove
= __devexit_p(dw_spi_mmio_remove
),
130 .owner
= THIS_MODULE
,
134 static int __init
dw_spi_mmio_init(void)
136 return platform_driver_probe(&dw_spi_mmio_driver
, dw_spi_mmio_probe
);
138 module_init(dw_spi_mmio_init
);
140 static void __exit
dw_spi_mmio_exit(void)
142 platform_driver_unregister(&dw_spi_mmio_driver
);
144 module_exit(dw_spi_mmio_exit
);
146 MODULE_AUTHOR("Jean-Hugues Deschenes <jean-hugues.deschenes@octasic.com>");
147 MODULE_DESCRIPTION("Memory-mapped I/O interface driver for DW SPI Core");
148 MODULE_LICENSE("GPL v2");