1 From 16535fe56591ff85acd6776f53ff515799b037ba Mon Sep 17 00:00:00 2001
2 From: Gabor Juhos <juhosg@openwrt.org>
3 Date: Wed, 11 Jan 2012 22:25:11 +0100
4 Subject: [PATCH 47/47] spi/ath79: make chipselect logic more flexible
6 Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
8 arch/mips/ath79/mach-ap121.c | 6 ++
9 arch/mips/ath79/mach-ap81.c | 6 ++
10 arch/mips/ath79/mach-db120.c | 6 ++
11 arch/mips/ath79/mach-pb44.c | 6 ++
12 arch/mips/ath79/mach-ubnt-xm.c | 6 ++
13 .../include/asm/mach-ath79/ath79_spi_platform.h | 8 ++-
14 drivers/spi/spi-ath79.c | 70 +++++++++++++-------
15 7 files changed, 82 insertions(+), 26 deletions(-)
17 --- a/arch/mips/ath79/mach-ap121.c
18 +++ b/arch/mips/ath79/mach-ap121.c
19 @@ -58,12 +58,18 @@ static struct gpio_keys_button ap121_gpi
23 +static struct ath79_spi_controller_data ap121_spi0_data = {
24 + .cs_type = ATH79_SPI_CS_TYPE_INTERNAL,
28 static struct spi_board_info ap121_spi_info[] = {
32 .max_speed_hz = 25000000,
33 .modalias = "mx25l1606e",
34 + .controller_data = &ap121_spi0_data,
38 --- a/arch/mips/ath79/mach-ap81.c
39 +++ b/arch/mips/ath79/mach-ap81.c
40 @@ -67,12 +67,18 @@ static struct gpio_keys_button ap81_gpio
44 +static struct ath79_spi_controller_data ap81_spi0_data = {
45 + .cs_type = ATH79_SPI_CS_TYPE_INTERNAL,
49 static struct spi_board_info ap81_spi_info[] = {
53 .max_speed_hz = 25000000,
55 + .controller_data = &ap81_spi0_data,
59 --- a/arch/mips/ath79/mach-db120.c
60 +++ b/arch/mips/ath79/mach-db120.c
61 @@ -76,12 +76,18 @@ static struct gpio_keys_button db120_gpi
65 +static struct ath79_spi_controller_data db120_spi0_data = {
66 + .cs_type = ATH79_SPI_CS_TYPE_INTERNAL,
70 static struct spi_board_info db120_spi_info[] = {
74 .max_speed_hz = 25000000,
75 .modalias = "s25sl064a",
76 + .controller_data = &db120_spi0_data,
80 --- a/arch/mips/ath79/mach-pb44.c
81 +++ b/arch/mips/ath79/mach-pb44.c
82 @@ -87,12 +87,18 @@ static struct gpio_keys_button pb44_gpio
86 +static struct ath79_spi_controller_data pb44_spi0_data = {
87 + .cs_type = ATH79_SPI_CS_TYPE_INTERNAL,
91 static struct spi_board_info pb44_spi_info[] = {
95 .max_speed_hz = 25000000,
97 + .controller_data = &pb44_spi0_data,
101 --- a/arch/mips/ath79/mach-ubnt-xm.c
102 +++ b/arch/mips/ath79/mach-ubnt-xm.c
103 @@ -65,12 +65,18 @@ static struct gpio_keys_button ubnt_xm_g
107 +static struct ath79_spi_controller_data ubnt_xm_spi0_data = {
108 + .cs_type = ATH79_SPI_CS_TYPE_INTERNAL,
112 static struct spi_board_info ubnt_xm_spi_info[] = {
116 .max_speed_hz = 25000000,
117 .modalias = "mx25l6405d",
118 + .controller_data = &ubnt_xm_spi0_data,
122 --- a/arch/mips/include/asm/mach-ath79/ath79_spi_platform.h
123 +++ b/arch/mips/include/asm/mach-ath79/ath79_spi_platform.h
124 @@ -16,8 +16,14 @@ struct ath79_spi_platform_data {
125 unsigned num_chipselect;
128 +enum ath79_spi_cs_type {
129 + ATH79_SPI_CS_TYPE_INTERNAL,
130 + ATH79_SPI_CS_TYPE_GPIO,
133 struct ath79_spi_controller_data {
135 + enum ath79_spi_cs_type cs_type;
139 #endif /* _ATH79_SPI_PLATFORM_H */
140 --- a/drivers/spi/spi-ath79.c
141 +++ b/drivers/spi/spi-ath79.c
143 #define ATH79_SPI_RRW_DELAY_FACTOR 12000
144 #define MHZ (1000 * 1000)
146 +#define ATH79_SPI_CS_LINE_MAX 2
149 struct spi_bitbang bitbang;
151 @@ -69,6 +71,7 @@ static void ath79_spi_chipselect(struct
153 struct ath79_spi *sp = ath79_spidev_to_sp(spi);
154 int cs_high = (spi->mode & SPI_CS_HIGH) ? is_active : !is_active;
155 + struct ath79_spi_controller_data *cdata = spi->controller_data;
158 /* set initial clock polarity */
159 @@ -80,20 +83,21 @@ static void ath79_spi_chipselect(struct
160 ath79_spi_wr(sp, AR71XX_SPI_REG_IOC, sp->ioc_base);
163 - if (spi->chip_select) {
164 - struct ath79_spi_controller_data *cdata = spi->controller_data;
166 - /* SPI is normally active-low */
167 - gpio_set_value(cdata->gpio, cs_high);
169 + switch (cdata->cs_type) {
170 + case ATH79_SPI_CS_TYPE_INTERNAL:
172 - sp->ioc_base |= AR71XX_SPI_IOC_CS0;
173 + sp->ioc_base |= AR71XX_SPI_IOC_CS(cdata->cs_line);
175 - sp->ioc_base &= ~AR71XX_SPI_IOC_CS0;
176 + sp->ioc_base &= ~AR71XX_SPI_IOC_CS(cdata->cs_line);
178 ath79_spi_wr(sp, AR71XX_SPI_REG_IOC, sp->ioc_base);
182 + case ATH79_SPI_CS_TYPE_GPIO:
183 + /* SPI is normally active-low */
184 + gpio_set_value(cdata->cs_line, cs_high);
189 static void ath79_spi_enable(struct ath79_spi *sp)
190 @@ -120,24 +124,30 @@ static void ath79_spi_disable(struct ath
191 static int ath79_spi_setup_cs(struct spi_device *spi)
193 struct ath79_spi_controller_data *cdata;
194 + unsigned long flags;
197 cdata = spi->controller_data;
198 - if (spi->chip_select && !cdata)
203 - if (spi->chip_select) {
204 - unsigned long flags;
205 + switch (cdata->cs_type) {
206 + case ATH79_SPI_CS_TYPE_INTERNAL:
207 + if (cdata->cs_line > ATH79_SPI_CS_LINE_MAX)
211 + case ATH79_SPI_CS_TYPE_GPIO:
212 flags = GPIOF_DIR_OUT;
213 if (spi->mode & SPI_CS_HIGH)
214 flags |= GPIOF_INIT_HIGH;
216 flags |= GPIOF_INIT_LOW;
218 - status = gpio_request_one(cdata->gpio, flags,
219 + status = gpio_request_one(cdata->cs_line, flags,
220 dev_name(&spi->dev));
225 @@ -145,9 +155,19 @@ static int ath79_spi_setup_cs(struct spi
227 static void ath79_spi_cleanup_cs(struct spi_device *spi)
229 - if (spi->chip_select) {
230 - struct ath79_spi_controller_data *cdata = spi->controller_data;
231 - gpio_free(cdata->gpio);
232 + struct ath79_spi_controller_data *cdata;
234 + cdata = spi->controller_data;
238 + switch (cdata->cs_type) {
239 + case ATH79_SPI_CS_TYPE_INTERNAL:
240 + /* nothing to do */
242 + case ATH79_SPI_CS_TYPE_GPIO:
243 + gpio_free(cdata->cs_line);
248 @@ -155,6 +175,9 @@ static int ath79_spi_setup(struct spi_de
252 + if (spi->controller_data == NULL)
255 if (spi->bits_per_word > 32)
258 @@ -215,6 +238,10 @@ static __devinit int ath79_spi_probe(str
262 + pdata = pdev->dev.platform_data;
266 master = spi_alloc_master(&pdev->dev, sizeof(*sp));
267 if (master == NULL) {
268 dev_err(&pdev->dev, "failed to allocate spi master\n");
269 @@ -224,17 +251,10 @@ static __devinit int ath79_spi_probe(str
270 sp = spi_master_get_devdata(master);
271 platform_set_drvdata(pdev, sp);
273 - pdata = pdev->dev.platform_data;
275 master->setup = ath79_spi_setup;
276 master->cleanup = ath79_spi_cleanup;
278 - master->bus_num = pdata->bus_num;
279 - master->num_chipselect = pdata->num_chipselect;
281 - master->bus_num = -1;
282 - master->num_chipselect = 1;
284 + master->bus_num = pdata->bus_num;
285 + master->num_chipselect = pdata->num_chipselect;
287 sp->bitbang.master = spi_master_get(master);
288 sp->bitbang.chipselect = ath79_spi_chipselect;