1 From 7008284716403237f6bc7d7590b3ed073555bd56 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 34/34] 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-ap136.c | 6 ++
10 arch/mips/ath79/mach-ap81.c | 6 ++
11 arch/mips/ath79/mach-db120.c | 6 ++
12 arch/mips/ath79/mach-pb44.c | 6 ++
13 arch/mips/ath79/mach-ubnt-xm.c | 6 ++
14 .../include/asm/mach-ath79/ath79_spi_platform.h | 8 ++-
15 drivers/spi/spi-ath79.c | 67 +++++++++++++-------
16 8 files changed, 88 insertions(+), 23 deletions(-)
18 --- a/arch/mips/ath79/mach-ap121.c
19 +++ b/arch/mips/ath79/mach-ap121.c
20 @@ -58,12 +58,18 @@ static struct gpio_keys_button ap121_gpi
24 +static struct ath79_spi_controller_data ap121_spi0_data = {
25 + .cs_type = ATH79_SPI_CS_TYPE_INTERNAL,
29 static struct spi_board_info ap121_spi_info[] = {
33 .max_speed_hz = 25000000,
34 .modalias = "mx25l1606e",
35 + .controller_data = &ap121_spi0_data,
39 --- a/arch/mips/ath79/mach-ap136.c
40 +++ b/arch/mips/ath79/mach-ap136.c
41 @@ -98,12 +98,18 @@ static struct gpio_keys_button ap136_gpi
45 +static struct ath79_spi_controller_data ap136_spi0_data = {
46 + .cs_type = ATH79_SPI_CS_TYPE_INTERNAL,
50 static struct spi_board_info ap136_spi_info[] = {
54 .max_speed_hz = 25000000,
55 .modalias = "mx25l6405d",
56 + .controller_data = &ap136_spi0_data,
60 --- a/arch/mips/ath79/mach-db120.c
61 +++ b/arch/mips/ath79/mach-db120.c
62 @@ -76,12 +76,18 @@ static struct gpio_keys_button db120_gpi
66 +static struct ath79_spi_controller_data db120_spi0_data = {
67 + .cs_type = ATH79_SPI_CS_TYPE_INTERNAL,
71 static struct spi_board_info db120_spi_info[] = {
75 .max_speed_hz = 25000000,
76 .modalias = "s25sl064a",
77 + .controller_data = &db120_spi0_data,
81 --- a/arch/mips/ath79/mach-pb44.c
82 +++ b/arch/mips/ath79/mach-pb44.c
83 @@ -87,12 +87,18 @@ static struct gpio_keys_button pb44_gpio
87 +static struct ath79_spi_controller_data pb44_spi0_data = {
88 + .cs_type = ATH79_SPI_CS_TYPE_INTERNAL,
92 static struct spi_board_info pb44_spi_info[] = {
96 .max_speed_hz = 25000000,
98 + .controller_data = &pb44_spi0_data,
102 --- a/arch/mips/ath79/mach-ubnt-xm.c
103 +++ b/arch/mips/ath79/mach-ubnt-xm.c
104 @@ -65,12 +65,18 @@ static struct gpio_keys_button ubnt_xm_g
108 +static struct ath79_spi_controller_data ubnt_xm_spi0_data = {
109 + .cs_type = ATH79_SPI_CS_TYPE_INTERNAL,
113 static struct spi_board_info ubnt_xm_spi_info[] = {
117 .max_speed_hz = 25000000,
118 .modalias = "mx25l6405d",
119 + .controller_data = &ubnt_xm_spi0_data,
123 --- a/arch/mips/include/asm/mach-ath79/ath79_spi_platform.h
124 +++ b/arch/mips/include/asm/mach-ath79/ath79_spi_platform.h
125 @@ -16,8 +16,14 @@ struct ath79_spi_platform_data {
126 unsigned num_chipselect;
129 +enum ath79_spi_cs_type {
130 + ATH79_SPI_CS_TYPE_INTERNAL,
131 + ATH79_SPI_CS_TYPE_GPIO,
134 struct ath79_spi_controller_data {
136 + enum ath79_spi_cs_type cs_type;
140 #endif /* _ATH79_SPI_PLATFORM_H */
141 --- a/drivers/spi/spi-ath79.c
142 +++ b/drivers/spi/spi-ath79.c
144 #define ATH79_SPI_RRW_DELAY_FACTOR 12000
145 #define MHZ (1000 * 1000)
147 +#define ATH79_SPI_CS_LINE_MAX 2
150 struct spi_bitbang bitbang;
152 @@ -67,6 +69,7 @@ static void ath79_spi_chipselect(struct
154 struct ath79_spi *sp = ath79_spidev_to_sp(spi);
155 int cs_high = (spi->mode & SPI_CS_HIGH) ? is_active : !is_active;
156 + struct ath79_spi_controller_data *cdata = spi->controller_data;
159 /* set initial clock polarity */
160 @@ -78,20 +81,24 @@ static void ath79_spi_chipselect(struct
161 ath79_spi_wr(sp, AR71XX_SPI_REG_IOC, sp->ioc_base);
164 - if (spi->chip_select) {
165 - struct ath79_spi_controller_data *cdata = spi->controller_data;
167 - /* SPI is normally active-low */
168 - gpio_set_value(cdata->gpio, cs_high);
170 + switch (cdata->cs_type) {
171 + case ATH79_SPI_CS_TYPE_INTERNAL:
173 - sp->ioc_base |= AR71XX_SPI_IOC_CS0;
174 + sp->ioc_base |= AR71XX_SPI_IOC_CS(cdata->cs_line);
176 - sp->ioc_base &= ~AR71XX_SPI_IOC_CS0;
177 + sp->ioc_base &= ~AR71XX_SPI_IOC_CS(cdata->cs_line);
179 ath79_spi_wr(sp, AR71XX_SPI_REG_IOC, sp->ioc_base);
183 + case ATH79_SPI_CS_TYPE_GPIO:
184 + /* SPI is normally active-low */
185 + if (gpio_cansleep(cdata->cs_line))
186 + gpio_set_value_cansleep(cdata->cs_line, cs_high);
188 + gpio_set_value(cdata->cs_line, cs_high);
193 static void ath79_spi_enable(struct ath79_spi *sp)
194 @@ -118,24 +125,30 @@ static void ath79_spi_disable(struct ath
195 static int ath79_spi_setup_cs(struct spi_device *spi)
197 struct ath79_spi_controller_data *cdata;
198 + unsigned long flags;
201 cdata = spi->controller_data;
202 - if (spi->chip_select && !cdata)
207 - if (spi->chip_select) {
208 - unsigned long flags;
209 + switch (cdata->cs_type) {
210 + case ATH79_SPI_CS_TYPE_INTERNAL:
211 + if (cdata->cs_line > ATH79_SPI_CS_LINE_MAX)
215 + case ATH79_SPI_CS_TYPE_GPIO:
216 flags = GPIOF_DIR_OUT;
217 if (spi->mode & SPI_CS_HIGH)
218 flags |= GPIOF_INIT_LOW;
220 flags |= GPIOF_INIT_HIGH;
222 - status = gpio_request_one(cdata->gpio, flags,
223 + status = gpio_request_one(cdata->cs_line, flags,
224 dev_name(&spi->dev));
229 @@ -143,9 +156,19 @@ static int ath79_spi_setup_cs(struct spi
231 static void ath79_spi_cleanup_cs(struct spi_device *spi)
233 - if (spi->chip_select) {
234 - struct ath79_spi_controller_data *cdata = spi->controller_data;
235 - gpio_free(cdata->gpio);
236 + struct ath79_spi_controller_data *cdata;
238 + cdata = spi->controller_data;
242 + switch (cdata->cs_type) {
243 + case ATH79_SPI_CS_TYPE_INTERNAL:
244 + /* nothing to do */
246 + case ATH79_SPI_CS_TYPE_GPIO:
247 + gpio_free(cdata->cs_line);
252 @@ -210,6 +233,10 @@ static int ath79_spi_probe(struct platfo
256 + pdata = pdev->dev.platform_data;
260 master = spi_alloc_master(&pdev->dev, sizeof(*sp));
261 if (master == NULL) {
262 dev_err(&pdev->dev, "failed to allocate spi master\n");
263 @@ -219,15 +246,11 @@ static int ath79_spi_probe(struct platfo
264 sp = spi_master_get_devdata(master);
265 platform_set_drvdata(pdev, sp);
267 - pdata = dev_get_platdata(&pdev->dev);
269 master->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 32);
270 master->setup = ath79_spi_setup;
271 master->cleanup = ath79_spi_cleanup;
273 - master->bus_num = pdata->bus_num;
274 - master->num_chipselect = pdata->num_chipselect;
276 + master->bus_num = pdata->bus_num;
277 + master->num_chipselect = pdata->num_chipselect;
279 sp->bitbang.master = master;
280 sp->bitbang.chipselect = ath79_spi_chipselect;