aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorBen Dooks <ben@trinity.fluff.org>2006-05-20 18:00:17 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2006-05-21 15:59:19 -0400
commit1fc7547d4bfe5c8c8c79e196b955b6fbaa21bfd2 (patch)
tree1a08d571dbbd64a4585f2e486aa87ad1005a37f7 /drivers
parent1b81d6637d27a0e6a0506ecef65493b50d859cfc (diff)
[PATCH] S3C24XX: GPIO based SPI driver
SPI driver for SPI by GPIO on the Samsung S3C24XX series of SoC processors. Signed-off-by: Ben Dooks <ben-linux@fluff.org> Cc: Greg KH <greg@kroah.com> Cc: David Brownell <david-b@pacbell.net> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/spi/Kconfig8
-rw-r--r--drivers/spi/Makefile1
-rw-r--r--drivers/spi/spi_butterfly.c1
-rw-r--r--drivers/spi/spi_s3c24xx_gpio.c188
4 files changed, 198 insertions, 0 deletions
diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
index 3867c6ef24f3..c60dacfaadd2 100644
--- a/drivers/spi/Kconfig
+++ b/drivers/spi/Kconfig
@@ -95,6 +95,14 @@ config SPI_PXA2XX
95 The driver can be configured to use any SSP port and additional 95 The driver can be configured to use any SSP port and additional
96 documentation can be found a Documentation/spi/pxa2xx. 96 documentation can be found a Documentation/spi/pxa2xx.
97 97
98config SPI_S3C24XX_GPIO
99 tristate "Samsung S3C24XX series SPI by GPIO"
100 depends on SPI_MASTER && ARCH_S3C2410 && SPI_BITBANG && EXPERIMENTAL
101 help
102 SPI driver for Samsung S3C24XX series ARM SoCs using
103 GPIO lines to provide the SPI bus. This can be used where
104 the inbuilt hardware cannot provide the transfer mode, or
105 where the board is using non hardware connected pins.
98# 106#
99# Add new SPI master controllers in alphabetical order above this line 107# Add new SPI master controllers in alphabetical order above this line
100# 108#
diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile
index 5a410caa03c7..4dc82c93bfe6 100644
--- a/drivers/spi/Makefile
+++ b/drivers/spi/Makefile
@@ -15,6 +15,7 @@ obj-$(CONFIG_SPI_BITBANG) += spi_bitbang.o
15obj-$(CONFIG_SPI_BUTTERFLY) += spi_butterfly.o 15obj-$(CONFIG_SPI_BUTTERFLY) += spi_butterfly.o
16obj-$(CONFIG_SPI_PXA2XX) += pxa2xx_spi.o 16obj-$(CONFIG_SPI_PXA2XX) += pxa2xx_spi.o
17obj-$(CONFIG_SPI_MPC83xx) += spi_mpc83xx.o 17obj-$(CONFIG_SPI_MPC83xx) += spi_mpc83xx.o
18obj-$(CONFIG_SPI_S3C24XX_GPIO) += spi_s3c24xx_gpio.o
18# ... add above this line ... 19# ... add above this line ...
19 20
20# SPI protocol drivers (device/link on bus) 21# SPI protocol drivers (device/link on bus)
diff --git a/drivers/spi/spi_butterfly.c b/drivers/spi/spi_butterfly.c
index ff9e5faa4dc9..a006a1ee27ac 100644
--- a/drivers/spi/spi_butterfly.c
+++ b/drivers/spi/spi_butterfly.c
@@ -321,6 +321,7 @@ static void butterfly_attach(struct parport *p)
321 * (firmware resets at45, acts as spi slave) or neither (we ignore 321 * (firmware resets at45, acts as spi slave) or neither (we ignore
322 * both, AVR uses AT45). Here we expect firmware for the first option. 322 * both, AVR uses AT45). Here we expect firmware for the first option.
323 */ 323 */
324
324 pp->info[0].max_speed_hz = 15 * 1000 * 1000; 325 pp->info[0].max_speed_hz = 15 * 1000 * 1000;
325 strcpy(pp->info[0].modalias, "mtd_dataflash"); 326 strcpy(pp->info[0].modalias, "mtd_dataflash");
326 pp->info[0].platform_data = &flash; 327 pp->info[0].platform_data = &flash;
diff --git a/drivers/spi/spi_s3c24xx_gpio.c b/drivers/spi/spi_s3c24xx_gpio.c
new file mode 100644
index 000000000000..aacdceb8f44b
--- /dev/null
+++ b/drivers/spi/spi_s3c24xx_gpio.c
@@ -0,0 +1,188 @@
1/* linux/drivers/spi/spi_s3c24xx_gpio.c
2 *
3 * Copyright (c) 2006 Ben Dooks
4 * Copyright (c) 2006 Simtec Electronics
5 *
6 * S3C24XX GPIO based SPI driver
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12*/
13
14#include <linux/config.h>
15#include <linux/kernel.h>
16#include <linux/init.h>
17#include <linux/delay.h>
18#include <linux/spinlock.h>
19#include <linux/platform_device.h>
20
21#include <linux/spi/spi.h>
22#include <linux/spi/spi_bitbang.h>
23
24#include <asm/arch/regs-gpio.h>
25#include <asm/arch/spi-gpio.h>
26#include <asm/arch/hardware.h>
27
28struct s3c2410_spigpio {
29 struct spi_bitbang bitbang;
30
31 struct s3c2410_spigpio_info *info;
32 struct platform_device *dev;
33};
34
35static inline struct s3c2410_spigpio *spidev_to_sg(struct spi_device *spi)
36{
37 return spi->controller_data;
38}
39
40static inline void setsck(struct spi_device *dev, int on)
41{
42 struct s3c2410_spigpio *sg = spidev_to_sg(dev);
43 s3c2410_gpio_setpin(sg->info->pin_clk, on ? 1 : 0);
44}
45
46static inline void setmosi(struct spi_device *dev, int on)
47{
48 struct s3c2410_spigpio *sg = spidev_to_sg(dev);
49 s3c2410_gpio_setpin(sg->info->pin_mosi, on ? 1 : 0);
50}
51
52static inline u32 getmiso(struct spi_device *dev)
53{
54 struct s3c2410_spigpio *sg = spidev_to_sg(dev);
55 return s3c2410_gpio_getpin(sg->info->pin_miso) ? 1 : 0;
56}
57
58#define spidelay(x) ndelay(x)
59
60#define EXPAND_BITBANG_TXRX
61#include <linux/spi/spi_bitbang.h>
62
63
64static u32 s3c2410_spigpio_txrx_mode0(struct spi_device *spi,
65 unsigned nsecs, u32 word, u8 bits)
66{
67 return bitbang_txrx_be_cpha0(spi, nsecs, 0, word, bits);
68}
69
70static u32 s3c2410_spigpio_txrx_mode1(struct spi_device *spi,
71 unsigned nsecs, u32 word, u8 bits)
72{
73 return bitbang_txrx_be_cpha1(spi, nsecs, 0, word, bits);
74}
75
76static void s3c2410_spigpio_chipselect(struct spi_device *dev, int value)
77{
78 struct s3c2410_spigpio *sg = spidev_to_sg(dev);
79
80 if (sg->info && sg->info->chip_select)
81 (sg->info->chip_select)(sg->info, value);
82}
83
84static int s3c2410_spigpio_probe(struct platform_device *dev)
85{
86 struct spi_master *master;
87 struct s3c2410_spigpio *sp;
88 int ret;
89 int i;
90
91 master = spi_alloc_master(&dev->dev, sizeof(struct s3c2410_spigpio));
92 if (master == NULL) {
93 dev_err(&dev->dev, "failed to allocate spi master\n");
94 ret = -ENOMEM;
95 goto err;
96 }
97
98 sp = spi_master_get_devdata(master);
99
100 platform_set_drvdata(dev, sp);
101
102 /* copy in the plkatform data */
103 sp->info = dev->dev.platform_data;
104
105 /* setup spi bitbang adaptor */
106 sp->bitbang.master = spi_master_get(master);
107 sp->bitbang.chipselect = s3c2410_spigpio_chipselect;
108
109 sp->bitbang.txrx_word[SPI_MODE_0] = s3c2410_spigpio_txrx_mode0;
110 sp->bitbang.txrx_word[SPI_MODE_1] = s3c2410_spigpio_txrx_mode1;
111
112 /* set state of spi pins */
113 s3c2410_gpio_setpin(sp->info->pin_clk, 0);
114 s3c2410_gpio_setpin(sp->info->pin_mosi, 0);
115
116 s3c2410_gpio_cfgpin(sp->info->pin_clk, S3C2410_GPIO_OUTPUT);
117 s3c2410_gpio_cfgpin(sp->info->pin_mosi, S3C2410_GPIO_OUTPUT);
118 s3c2410_gpio_cfgpin(sp->info->pin_miso, S3C2410_GPIO_INPUT);
119
120 ret = spi_bitbang_start(&sp->bitbang);
121 if (ret)
122 goto err_no_bitbang;
123
124 /* register the chips to go with the board */
125
126 for (i = 0; i < sp->info->board_size; i++) {
127 dev_info(&dev->dev, "registering %p: %s\n",
128 &sp->info->board_info[i],
129 sp->info->board_info[i].modalias);
130
131 sp->info->board_info[i].controller_data = sp;
132 spi_new_device(master, sp->info->board_info + i);
133 }
134
135 return 0;
136
137 err_no_bitbang:
138 spi_master_put(sp->bitbang.master);
139 err:
140 return ret;
141
142}
143
144static int s3c2410_spigpio_remove(struct platform_device *dev)
145{
146 struct s3c2410_spigpio *sp = platform_get_drvdata(dev);
147
148 spi_bitbang_stop(&sp->bitbang);
149 spi_master_put(sp->bitbang.master);
150
151 return 0;
152}
153
154/* all gpio should be held over suspend/resume, so we should
155 * not need to deal with this
156*/
157
158#define s3c2410_spigpio_suspend NULL
159#define s3c2410_spigpio_resume NULL
160
161
162static struct platform_driver s3c2410_spigpio_drv = {
163 .probe = s3c2410_spigpio_probe,
164 .remove = s3c2410_spigpio_remove,
165 .suspend = s3c2410_spigpio_suspend,
166 .resume = s3c2410_spigpio_resume,
167 .driver = {
168 .name = "s3c24xx-spi-gpio",
169 .owner = THIS_MODULE,
170 },
171};
172
173static int __init s3c2410_spigpio_init(void)
174{
175 return platform_driver_register(&s3c2410_spigpio_drv);
176}
177
178static void __exit s3c2410_spigpio_exit(void)
179{
180 platform_driver_unregister(&s3c2410_spigpio_drv);
181}
182
183module_init(s3c2410_spigpio_init);
184module_exit(s3c2410_spigpio_exit);
185
186MODULE_DESCRIPTION("S3C24XX SPI Driver");
187MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
188MODULE_LICENSE("GPL");