aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/spi
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/spi')
-rw-r--r--drivers/spi/Kconfig15
-rw-r--r--drivers/spi/Makefile3
-rw-r--r--drivers/spi/spi-altera.c4
-rw-r--r--drivers/spi/spi-au1550.c2
-rw-r--r--drivers/spi/spi-bfin-sport.c2
-rw-r--r--drivers/spi/spi-gpio.c131
-rw-r--r--drivers/spi/spi-imx.c8
-rw-r--r--drivers/spi/spi-mpc512x-psc.c3
-rw-r--r--drivers/spi/spi-mpc52xx-psc.c3
-rw-r--r--drivers/spi/spi-mpc52xx.c9
-rw-r--r--drivers/spi/spi-mxs.c674
-rw-r--r--drivers/spi/spi-oc-tiny.c2
-rw-r--r--drivers/spi/spi-omap2-mcspi.c323
-rw-r--r--drivers/spi/spi-orion.c209
-rw-r--r--drivers/spi/spi-pl022.c251
-rw-r--r--drivers/spi/spi-ppc4xx.c4
-rw-r--r--drivers/spi/spi-s3c24xx.c1
-rw-r--r--drivers/spi/spi-s3c64xx.c18
-rw-r--r--drivers/spi/spi-sc18is602.c364
-rw-r--r--drivers/spi/spi-sh-hspi.c5
-rw-r--r--drivers/spi/spi-stmp.c6
-rw-r--r--drivers/spi/spi-tegra.c647
-rw-r--r--drivers/spi/spi-tle62x0.c13
-rw-r--r--drivers/spi/spi-topcliff-pch.c4
24 files changed, 1651 insertions, 1050 deletions
diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
index 2d198a01a410..ecc31a1f73fc 100644
--- a/drivers/spi/Kconfig
+++ b/drivers/spi/Kconfig
@@ -325,6 +325,12 @@ config SPI_S3C64XX
325 help 325 help
326 SPI driver for Samsung S3C64XX and newer SoCs. 326 SPI driver for Samsung S3C64XX and newer SoCs.
327 327
328config SPI_SC18IS602
329 tristate "NXP SC18IS602/602B/603 I2C to SPI bridge"
330 depends on I2C
331 help
332 SPI driver for NXP SC18IS602/602B/603 I2C to SPI bridge.
333
328config SPI_SH_MSIOF 334config SPI_SH_MSIOF
329 tristate "SuperH MSIOF SPI controller" 335 tristate "SuperH MSIOF SPI controller"
330 depends on SUPERH && HAVE_CLK 336 depends on SUPERH && HAVE_CLK
@@ -364,11 +370,12 @@ config SPI_STMP3XXX
364 help 370 help
365 SPI driver for Freescale STMP37xx/378x SoC SSP interface 371 SPI driver for Freescale STMP37xx/378x SoC SSP interface
366 372
367config SPI_TEGRA 373config SPI_MXS
368 tristate "Nvidia Tegra SPI controller" 374 tristate "Freescale MXS SPI controller"
369 depends on ARCH_TEGRA && TEGRA20_APB_DMA 375 depends on ARCH_MXS
376 select STMP_DEVICE
370 help 377 help
371 SPI driver for NVidia Tegra SoCs 378 SPI driver for Freescale MXS devices.
372 379
373config SPI_TI_SSP 380config SPI_TI_SSP
374 tristate "TI Sequencer Serial Port - SPI Support" 381 tristate "TI Sequencer Serial Port - SPI Support"
diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile
index 3920dcf4c740..22fd3a7251bc 100644
--- a/drivers/spi/Makefile
+++ b/drivers/spi/Makefile
@@ -36,6 +36,7 @@ obj-$(CONFIG_SPI_LM70_LLP) += spi-lm70llp.o
36obj-$(CONFIG_SPI_MPC512x_PSC) += spi-mpc512x-psc.o 36obj-$(CONFIG_SPI_MPC512x_PSC) += spi-mpc512x-psc.o
37obj-$(CONFIG_SPI_MPC52xx_PSC) += spi-mpc52xx-psc.o 37obj-$(CONFIG_SPI_MPC52xx_PSC) += spi-mpc52xx-psc.o
38obj-$(CONFIG_SPI_MPC52xx) += spi-mpc52xx.o 38obj-$(CONFIG_SPI_MPC52xx) += spi-mpc52xx.o
39obj-$(CONFIG_SPI_MXS) += spi-mxs.o
39obj-$(CONFIG_SPI_NUC900) += spi-nuc900.o 40obj-$(CONFIG_SPI_NUC900) += spi-nuc900.o
40obj-$(CONFIG_SPI_OC_TINY) += spi-oc-tiny.o 41obj-$(CONFIG_SPI_OC_TINY) += spi-oc-tiny.o
41obj-$(CONFIG_SPI_OMAP_UWIRE) += spi-omap-uwire.o 42obj-$(CONFIG_SPI_OMAP_UWIRE) += spi-omap-uwire.o
@@ -51,13 +52,13 @@ obj-$(CONFIG_SPI_S3C24XX) += spi-s3c24xx-hw.o
51spi-s3c24xx-hw-y := spi-s3c24xx.o 52spi-s3c24xx-hw-y := spi-s3c24xx.o
52spi-s3c24xx-hw-$(CONFIG_SPI_S3C24XX_FIQ) += spi-s3c24xx-fiq.o 53spi-s3c24xx-hw-$(CONFIG_SPI_S3C24XX_FIQ) += spi-s3c24xx-fiq.o
53obj-$(CONFIG_SPI_S3C64XX) += spi-s3c64xx.o 54obj-$(CONFIG_SPI_S3C64XX) += spi-s3c64xx.o
55obj-$(CONFIG_SPI_SC18IS602) += spi-sc18is602.o
54obj-$(CONFIG_SPI_SH) += spi-sh.o 56obj-$(CONFIG_SPI_SH) += spi-sh.o
55obj-$(CONFIG_SPI_SH_HSPI) += spi-sh-hspi.o 57obj-$(CONFIG_SPI_SH_HSPI) += spi-sh-hspi.o
56obj-$(CONFIG_SPI_SH_MSIOF) += spi-sh-msiof.o 58obj-$(CONFIG_SPI_SH_MSIOF) += spi-sh-msiof.o
57obj-$(CONFIG_SPI_SH_SCI) += spi-sh-sci.o 59obj-$(CONFIG_SPI_SH_SCI) += spi-sh-sci.o
58obj-$(CONFIG_SPI_SIRF) += spi-sirf.o 60obj-$(CONFIG_SPI_SIRF) += spi-sirf.o
59obj-$(CONFIG_SPI_STMP3XXX) += spi-stmp.o 61obj-$(CONFIG_SPI_STMP3XXX) += spi-stmp.o
60obj-$(CONFIG_SPI_TEGRA) += spi-tegra.o
61obj-$(CONFIG_SPI_TI_SSP) += spi-ti-ssp.o 62obj-$(CONFIG_SPI_TI_SSP) += spi-ti-ssp.o
62obj-$(CONFIG_SPI_TLE62X0) += spi-tle62x0.o 63obj-$(CONFIG_SPI_TLE62X0) += spi-tle62x0.o
63obj-$(CONFIG_SPI_TOPCLIFF_PCH) += spi-topcliff-pch.o 64obj-$(CONFIG_SPI_TOPCLIFF_PCH) += spi-topcliff-pch.o
diff --git a/drivers/spi/spi-altera.c b/drivers/spi/spi-altera.c
index c00d00e96ee4..f1fec2a19d10 100644
--- a/drivers/spi/spi-altera.c
+++ b/drivers/spi/spi-altera.c
@@ -307,8 +307,6 @@ static const struct of_device_id altera_spi_match[] = {
307 {}, 307 {},
308}; 308};
309MODULE_DEVICE_TABLE(of, altera_spi_match); 309MODULE_DEVICE_TABLE(of, altera_spi_match);
310#else /* CONFIG_OF */
311#define altera_spi_match NULL
312#endif /* CONFIG_OF */ 310#endif /* CONFIG_OF */
313 311
314static struct platform_driver altera_spi_driver = { 312static struct platform_driver altera_spi_driver = {
@@ -318,7 +316,7 @@ static struct platform_driver altera_spi_driver = {
318 .name = DRV_NAME, 316 .name = DRV_NAME,
319 .owner = THIS_MODULE, 317 .owner = THIS_MODULE,
320 .pm = NULL, 318 .pm = NULL,
321 .of_match_table = altera_spi_match, 319 .of_match_table = of_match_ptr(altera_spi_match),
322 }, 320 },
323}; 321};
324module_platform_driver(altera_spi_driver); 322module_platform_driver(altera_spi_driver);
diff --git a/drivers/spi/spi-au1550.c b/drivers/spi/spi-au1550.c
index 5784c8799616..4de66d1cfe51 100644
--- a/drivers/spi/spi-au1550.c
+++ b/drivers/spi/spi-au1550.c
@@ -475,7 +475,7 @@ static irqreturn_t au1550_spi_dma_irq_callback(struct au1550_spi *hw)
475 /* 475 /*
476 * due to an spi error we consider transfer as done, 476 * due to an spi error we consider transfer as done,
477 * so mask all events until before next transfer start 477 * so mask all events until before next transfer start
478 * and stop the possibly running dma immediatelly 478 * and stop the possibly running dma immediately
479 */ 479 */
480 au1550_spi_mask_ack_all(hw); 480 au1550_spi_mask_ack_all(hw);
481 au1xxx_dbdma_stop(hw->dma_rx_ch); 481 au1xxx_dbdma_stop(hw->dma_rx_ch);
diff --git a/drivers/spi/spi-bfin-sport.c b/drivers/spi/spi-bfin-sport.c
index 1fe51198a622..6555ecd07302 100644
--- a/drivers/spi/spi-bfin-sport.c
+++ b/drivers/spi/spi-bfin-sport.c
@@ -467,7 +467,7 @@ bfin_sport_spi_pump_transfers(unsigned long data)
467 dev_dbg(drv_data->dev, "IO write error!\n"); 467 dev_dbg(drv_data->dev, "IO write error!\n");
468 drv_data->state = ERROR_STATE; 468 drv_data->state = ERROR_STATE;
469 } else { 469 } else {
470 /* Update total byte transfered */ 470 /* Update total byte transferred */
471 message->actual_length += transfer->len; 471 message->actual_length += transfer->len;
472 /* Move to next transfer of this msg */ 472 /* Move to next transfer of this msg */
473 drv_data->state = bfin_sport_spi_next_transfer(drv_data); 473 drv_data->state = bfin_sport_spi_next_transfer(drv_data);
diff --git a/drivers/spi/spi-gpio.c b/drivers/spi/spi-gpio.c
index 0b56cfc71fab..a2b50c516b31 100644
--- a/drivers/spi/spi-gpio.c
+++ b/drivers/spi/spi-gpio.c
@@ -22,6 +22,8 @@
22#include <linux/init.h> 22#include <linux/init.h>
23#include <linux/platform_device.h> 23#include <linux/platform_device.h>
24#include <linux/gpio.h> 24#include <linux/gpio.h>
25#include <linux/of_device.h>
26#include <linux/of_gpio.h>
25 27
26#include <linux/spi/spi.h> 28#include <linux/spi/spi.h>
27#include <linux/spi/spi_bitbang.h> 29#include <linux/spi/spi_bitbang.h>
@@ -46,6 +48,7 @@ struct spi_gpio {
46 struct spi_bitbang bitbang; 48 struct spi_bitbang bitbang;
47 struct spi_gpio_platform_data pdata; 49 struct spi_gpio_platform_data pdata;
48 struct platform_device *pdev; 50 struct platform_device *pdev;
51 int cs_gpios[0];
49}; 52};
50 53
51/*----------------------------------------------------------------------*/ 54/*----------------------------------------------------------------------*/
@@ -89,15 +92,21 @@ struct spi_gpio {
89 92
90/*----------------------------------------------------------------------*/ 93/*----------------------------------------------------------------------*/
91 94
92static inline const struct spi_gpio_platform_data * __pure 95static inline struct spi_gpio * __pure
93spi_to_pdata(const struct spi_device *spi) 96spi_to_spi_gpio(const struct spi_device *spi)
94{ 97{
95 const struct spi_bitbang *bang; 98 const struct spi_bitbang *bang;
96 const struct spi_gpio *spi_gpio; 99 struct spi_gpio *spi_gpio;
97 100
98 bang = spi_master_get_devdata(spi->master); 101 bang = spi_master_get_devdata(spi->master);
99 spi_gpio = container_of(bang, struct spi_gpio, bitbang); 102 spi_gpio = container_of(bang, struct spi_gpio, bitbang);
100 return &spi_gpio->pdata; 103 return spi_gpio;
104}
105
106static inline struct spi_gpio_platform_data * __pure
107spi_to_pdata(const struct spi_device *spi)
108{
109 return &spi_to_spi_gpio(spi)->pdata;
101} 110}
102 111
103/* this is #defined to avoid unused-variable warnings when inlining */ 112/* this is #defined to avoid unused-variable warnings when inlining */
@@ -210,7 +219,8 @@ static u32 spi_gpio_spec_txrx_word_mode3(struct spi_device *spi,
210 219
211static void spi_gpio_chipselect(struct spi_device *spi, int is_active) 220static void spi_gpio_chipselect(struct spi_device *spi, int is_active)
212{ 221{
213 unsigned long cs = (unsigned long) spi->controller_data; 222 struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi);
223 unsigned int cs = spi_gpio->cs_gpios[spi->chip_select];
214 224
215 /* set initial clock polarity */ 225 /* set initial clock polarity */
216 if (is_active) 226 if (is_active)
@@ -224,12 +234,27 @@ static void spi_gpio_chipselect(struct spi_device *spi, int is_active)
224 234
225static int spi_gpio_setup(struct spi_device *spi) 235static int spi_gpio_setup(struct spi_device *spi)
226{ 236{
227 unsigned long cs = (unsigned long) spi->controller_data; 237 unsigned int cs;
228 int status = 0; 238 int status = 0;
239 struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi);
240 struct device_node *np = spi->master->dev.of_node;
229 241
230 if (spi->bits_per_word > 32) 242 if (spi->bits_per_word > 32)
231 return -EINVAL; 243 return -EINVAL;
232 244
245 if (np) {
246 /*
247 * In DT environments, the CS GPIOs have already been
248 * initialized from the "cs-gpios" property of the node.
249 */
250 cs = spi_gpio->cs_gpios[spi->chip_select];
251 } else {
252 /*
253 * ... otherwise, take it from spi->controller_data
254 */
255 cs = (unsigned int) spi->controller_data;
256 }
257
233 if (!spi->controller_state) { 258 if (!spi->controller_state) {
234 if (cs != SPI_GPIO_NO_CHIPSELECT) { 259 if (cs != SPI_GPIO_NO_CHIPSELECT) {
235 status = gpio_request(cs, dev_name(&spi->dev)); 260 status = gpio_request(cs, dev_name(&spi->dev));
@@ -239,8 +264,12 @@ static int spi_gpio_setup(struct spi_device *spi)
239 !(spi->mode & SPI_CS_HIGH)); 264 !(spi->mode & SPI_CS_HIGH));
240 } 265 }
241 } 266 }
242 if (!status) 267 if (!status) {
243 status = spi_bitbang_setup(spi); 268 status = spi_bitbang_setup(spi);
269 /* in case it was initialized from static board data */
270 spi_gpio->cs_gpios[spi->chip_select] = cs;
271 }
272
244 if (status) { 273 if (status) {
245 if (!spi->controller_state && cs != SPI_GPIO_NO_CHIPSELECT) 274 if (!spi->controller_state && cs != SPI_GPIO_NO_CHIPSELECT)
246 gpio_free(cs); 275 gpio_free(cs);
@@ -250,7 +279,8 @@ static int spi_gpio_setup(struct spi_device *spi)
250 279
251static void spi_gpio_cleanup(struct spi_device *spi) 280static void spi_gpio_cleanup(struct spi_device *spi)
252{ 281{
253 unsigned long cs = (unsigned long) spi->controller_data; 282 struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi);
283 unsigned int cs = spi_gpio->cs_gpios[spi->chip_select];
254 284
255 if (cs != SPI_GPIO_NO_CHIPSELECT) 285 if (cs != SPI_GPIO_NO_CHIPSELECT)
256 gpio_free(cs); 286 gpio_free(cs);
@@ -313,6 +343,55 @@ done:
313 return value; 343 return value;
314} 344}
315 345
346#ifdef CONFIG_OF
347static struct of_device_id spi_gpio_dt_ids[] = {
348 { .compatible = "spi-gpio" },
349 {}
350};
351MODULE_DEVICE_TABLE(of, spi_gpio_dt_ids);
352
353static int spi_gpio_probe_dt(struct platform_device *pdev)
354{
355 int ret;
356 u32 tmp;
357 struct spi_gpio_platform_data *pdata;
358 struct device_node *np = pdev->dev.of_node;
359 const struct of_device_id *of_id =
360 of_match_device(spi_gpio_dt_ids, &pdev->dev);
361
362 if (!of_id)
363 return 0;
364
365 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
366 if (!pdata)
367 return -ENOMEM;
368
369 pdata->sck = of_get_named_gpio(np, "gpio-sck", 0);
370 pdata->miso = of_get_named_gpio(np, "gpio-miso", 0);
371 pdata->mosi = of_get_named_gpio(np, "gpio-mosi", 0);
372
373 ret = of_property_read_u32(np, "num-chipselects", &tmp);
374 if (ret < 0) {
375 dev_err(&pdev->dev, "num-chipselects property not found\n");
376 goto error_free;
377 }
378
379 pdata->num_chipselect = tmp;
380 pdev->dev.platform_data = pdata;
381
382 return 1;
383
384error_free:
385 devm_kfree(&pdev->dev, pdata);
386 return ret;
387}
388#else
389static inline int spi_gpio_probe_dt(struct platform_device *pdev)
390{
391 return 0;
392}
393#endif
394
316static int __devinit spi_gpio_probe(struct platform_device *pdev) 395static int __devinit spi_gpio_probe(struct platform_device *pdev)
317{ 396{
318 int status; 397 int status;
@@ -320,6 +399,13 @@ static int __devinit spi_gpio_probe(struct platform_device *pdev)
320 struct spi_gpio *spi_gpio; 399 struct spi_gpio *spi_gpio;
321 struct spi_gpio_platform_data *pdata; 400 struct spi_gpio_platform_data *pdata;
322 u16 master_flags = 0; 401 u16 master_flags = 0;
402 bool use_of = 0;
403
404 status = spi_gpio_probe_dt(pdev);
405 if (status < 0)
406 return status;
407 if (status > 0)
408 use_of = 1;
323 409
324 pdata = pdev->dev.platform_data; 410 pdata = pdev->dev.platform_data;
325#ifdef GENERIC_BITBANG 411#ifdef GENERIC_BITBANG
@@ -331,7 +417,8 @@ static int __devinit spi_gpio_probe(struct platform_device *pdev)
331 if (status < 0) 417 if (status < 0)
332 return status; 418 return status;
333 419
334 master = spi_alloc_master(&pdev->dev, sizeof *spi_gpio); 420 master = spi_alloc_master(&pdev->dev, sizeof(*spi_gpio) +
421 (sizeof(int) * SPI_N_CHIPSEL));
335 if (!master) { 422 if (!master) {
336 status = -ENOMEM; 423 status = -ENOMEM;
337 goto gpio_free; 424 goto gpio_free;
@@ -348,6 +435,23 @@ static int __devinit spi_gpio_probe(struct platform_device *pdev)
348 master->num_chipselect = SPI_N_CHIPSEL; 435 master->num_chipselect = SPI_N_CHIPSEL;
349 master->setup = spi_gpio_setup; 436 master->setup = spi_gpio_setup;
350 master->cleanup = spi_gpio_cleanup; 437 master->cleanup = spi_gpio_cleanup;
438#ifdef CONFIG_OF
439 master->dev.of_node = pdev->dev.of_node;
440
441 if (use_of) {
442 int i;
443 struct device_node *np = pdev->dev.of_node;
444
445 /*
446 * In DT environments, take the CS GPIO from the "cs-gpios"
447 * property of the node.
448 */
449
450 for (i = 0; i < SPI_N_CHIPSEL; i++)
451 spi_gpio->cs_gpios[i] =
452 of_get_named_gpio(np, "cs-gpios", i);
453 }
454#endif
351 455
352 spi_gpio->bitbang.master = spi_master_get(master); 456 spi_gpio->bitbang.master = spi_master_get(master);
353 spi_gpio->bitbang.chipselect = spi_gpio_chipselect; 457 spi_gpio->bitbang.chipselect = spi_gpio_chipselect;
@@ -408,8 +512,11 @@ static int __devexit spi_gpio_remove(struct platform_device *pdev)
408MODULE_ALIAS("platform:" DRIVER_NAME); 512MODULE_ALIAS("platform:" DRIVER_NAME);
409 513
410static struct platform_driver spi_gpio_driver = { 514static struct platform_driver spi_gpio_driver = {
411 .driver.name = DRIVER_NAME, 515 .driver = {
412 .driver.owner = THIS_MODULE, 516 .name = DRIVER_NAME,
517 .owner = THIS_MODULE,
518 .of_match_table = of_match_ptr(spi_gpio_dt_ids),
519 },
413 .probe = spi_gpio_probe, 520 .probe = spi_gpio_probe,
414 .remove = __devexit_p(spi_gpio_remove), 521 .remove = __devexit_p(spi_gpio_remove),
415}; 522};
diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c
index 63e7fc9801cd..c9a0d8467de6 100644
--- a/drivers/spi/spi-imx.c
+++ b/drivers/spi/spi-imx.c
@@ -97,7 +97,7 @@ struct spi_imx_data {
97 const void *tx_buf; 97 const void *tx_buf;
98 unsigned int txfifo; /* number of words pushed in tx FIFO */ 98 unsigned int txfifo; /* number of words pushed in tx FIFO */
99 99
100 struct spi_imx_devtype_data *devtype_data; 100 const struct spi_imx_devtype_data *devtype_data;
101 int chipselect[0]; 101 int chipselect[0];
102}; 102};
103 103
@@ -197,6 +197,7 @@ static unsigned int spi_imx_clkdiv_2(unsigned int fin,
197#define MX51_ECSPI_CONFIG_SCLKPOL(cs) (1 << ((cs) + 4)) 197#define MX51_ECSPI_CONFIG_SCLKPOL(cs) (1 << ((cs) + 4))
198#define MX51_ECSPI_CONFIG_SBBCTRL(cs) (1 << ((cs) + 8)) 198#define MX51_ECSPI_CONFIG_SBBCTRL(cs) (1 << ((cs) + 8))
199#define MX51_ECSPI_CONFIG_SSBPOL(cs) (1 << ((cs) + 12)) 199#define MX51_ECSPI_CONFIG_SSBPOL(cs) (1 << ((cs) + 12))
200#define MX51_ECSPI_CONFIG_SCLKCTL(cs) (1 << ((cs) + 20))
200 201
201#define MX51_ECSPI_INT 0x10 202#define MX51_ECSPI_INT 0x10
202#define MX51_ECSPI_INT_TEEN (1 << 0) 203#define MX51_ECSPI_INT_TEEN (1 << 0)
@@ -287,9 +288,10 @@ static int __maybe_unused mx51_ecspi_config(struct spi_imx_data *spi_imx,
287 if (config->mode & SPI_CPHA) 288 if (config->mode & SPI_CPHA)
288 cfg |= MX51_ECSPI_CONFIG_SCLKPHA(config->cs); 289 cfg |= MX51_ECSPI_CONFIG_SCLKPHA(config->cs);
289 290
290 if (config->mode & SPI_CPOL) 291 if (config->mode & SPI_CPOL) {
291 cfg |= MX51_ECSPI_CONFIG_SCLKPOL(config->cs); 292 cfg |= MX51_ECSPI_CONFIG_SCLKPOL(config->cs);
292 293 cfg |= MX51_ECSPI_CONFIG_SCLKCTL(config->cs);
294 }
293 if (config->mode & SPI_CS_HIGH) 295 if (config->mode & SPI_CS_HIGH)
294 cfg |= MX51_ECSPI_CONFIG_SSBPOL(config->cs); 296 cfg |= MX51_ECSPI_CONFIG_SSBPOL(config->cs);
295 297
diff --git a/drivers/spi/spi-mpc512x-psc.c b/drivers/spi/spi-mpc512x-psc.c
index 4c63f772780a..0a1e39e94d06 100644
--- a/drivers/spi/spi-mpc512x-psc.c
+++ b/drivers/spi/spi-mpc512x-psc.c
@@ -494,7 +494,7 @@ free_master:
494 494
495static int __devexit mpc512x_psc_spi_do_remove(struct device *dev) 495static int __devexit mpc512x_psc_spi_do_remove(struct device *dev)
496{ 496{
497 struct spi_master *master = dev_get_drvdata(dev); 497 struct spi_master *master = spi_master_get(dev_get_drvdata(dev));
498 struct mpc512x_psc_spi *mps = spi_master_get_devdata(master); 498 struct mpc512x_psc_spi *mps = spi_master_get_devdata(master);
499 499
500 flush_workqueue(mps->workqueue); 500 flush_workqueue(mps->workqueue);
@@ -503,6 +503,7 @@ static int __devexit mpc512x_psc_spi_do_remove(struct device *dev)
503 free_irq(mps->irq, mps); 503 free_irq(mps->irq, mps);
504 if (mps->psc) 504 if (mps->psc)
505 iounmap(mps->psc); 505 iounmap(mps->psc);
506 spi_master_put(master);
506 507
507 return 0; 508 return 0;
508} 509}
diff --git a/drivers/spi/spi-mpc52xx-psc.c b/drivers/spi/spi-mpc52xx-psc.c
index 66047156d90d..bd47d262d53f 100644
--- a/drivers/spi/spi-mpc52xx-psc.c
+++ b/drivers/spi/spi-mpc52xx-psc.c
@@ -481,7 +481,7 @@ static int __devinit mpc52xx_psc_spi_of_probe(struct platform_device *op)
481 481
482static int __devexit mpc52xx_psc_spi_of_remove(struct platform_device *op) 482static int __devexit mpc52xx_psc_spi_of_remove(struct platform_device *op)
483{ 483{
484 struct spi_master *master = dev_get_drvdata(&op->dev); 484 struct spi_master *master = spi_master_get(dev_get_drvdata(&op->dev));
485 struct mpc52xx_psc_spi *mps = spi_master_get_devdata(master); 485 struct mpc52xx_psc_spi *mps = spi_master_get_devdata(master);
486 486
487 flush_workqueue(mps->workqueue); 487 flush_workqueue(mps->workqueue);
@@ -490,6 +490,7 @@ static int __devexit mpc52xx_psc_spi_of_remove(struct platform_device *op)
490 free_irq(mps->irq, mps); 490 free_irq(mps->irq, mps);
491 if (mps->psc) 491 if (mps->psc)
492 iounmap(mps->psc); 492 iounmap(mps->psc);
493 spi_master_put(master);
493 494
494 return 0; 495 return 0;
495} 496}
diff --git a/drivers/spi/spi-mpc52xx.c b/drivers/spi/spi-mpc52xx.c
index cb3a3830b0a5..045410650212 100644
--- a/drivers/spi/spi-mpc52xx.c
+++ b/drivers/spi/spi-mpc52xx.c
@@ -454,7 +454,7 @@ static int __devinit mpc52xx_spi_probe(struct platform_device *op)
454 GFP_KERNEL); 454 GFP_KERNEL);
455 if (!ms->gpio_cs) { 455 if (!ms->gpio_cs) {
456 rc = -ENOMEM; 456 rc = -ENOMEM;
457 goto err_alloc; 457 goto err_alloc_gpio;
458 } 458 }
459 459
460 for (i = 0; i < ms->gpio_cs_count; i++) { 460 for (i = 0; i < ms->gpio_cs_count; i++) {
@@ -514,12 +514,13 @@ static int __devinit mpc52xx_spi_probe(struct platform_device *op)
514 514
515 err_register: 515 err_register:
516 dev_err(&ms->master->dev, "initialization failed\n"); 516 dev_err(&ms->master->dev, "initialization failed\n");
517 spi_master_put(master);
518 err_gpio: 517 err_gpio:
519 while (i-- > 0) 518 while (i-- > 0)
520 gpio_free(ms->gpio_cs[i]); 519 gpio_free(ms->gpio_cs[i]);
521 520
522 kfree(ms->gpio_cs); 521 kfree(ms->gpio_cs);
522 err_alloc_gpio:
523 spi_master_put(master);
523 err_alloc: 524 err_alloc:
524 err_init: 525 err_init:
525 iounmap(regs); 526 iounmap(regs);
@@ -528,7 +529,7 @@ static int __devinit mpc52xx_spi_probe(struct platform_device *op)
528 529
529static int __devexit mpc52xx_spi_remove(struct platform_device *op) 530static int __devexit mpc52xx_spi_remove(struct platform_device *op)
530{ 531{
531 struct spi_master *master = dev_get_drvdata(&op->dev); 532 struct spi_master *master = spi_master_get(dev_get_drvdata(&op->dev));
532 struct mpc52xx_spi *ms = spi_master_get_devdata(master); 533 struct mpc52xx_spi *ms = spi_master_get_devdata(master);
533 int i; 534 int i;
534 535
@@ -540,8 +541,8 @@ static int __devexit mpc52xx_spi_remove(struct platform_device *op)
540 541
541 kfree(ms->gpio_cs); 542 kfree(ms->gpio_cs);
542 spi_unregister_master(master); 543 spi_unregister_master(master);
543 spi_master_put(master);
544 iounmap(ms->regs); 544 iounmap(ms->regs);
545 spi_master_put(master);
545 546
546 return 0; 547 return 0;
547} 548}
diff --git a/drivers/spi/spi-mxs.c b/drivers/spi/spi-mxs.c
new file mode 100644
index 000000000000..edf1360ab09e
--- /dev/null
+++ b/drivers/spi/spi-mxs.c
@@ -0,0 +1,674 @@
1/*
2 * Freescale MXS SPI master driver
3 *
4 * Copyright 2012 DENX Software Engineering, GmbH.
5 * Copyright 2012 Freescale Semiconductor, Inc.
6 * Copyright 2008 Embedded Alley Solutions, Inc All Rights Reserved.
7 *
8 * Rework and transition to new API by:
9 * Marek Vasut <marex@denx.de>
10 *
11 * Based on previous attempt by:
12 * Fabio Estevam <fabio.estevam@freescale.com>
13 *
14 * Based on code from U-Boot bootloader by:
15 * Marek Vasut <marex@denx.de>
16 *
17 * Based on spi-stmp.c, which is:
18 * Author: Dmitry Pervushin <dimka@embeddedalley.com>
19 *
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 2 of the License, or
23 * (at your option) any later version.
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 */
30
31#include <linux/kernel.h>
32#include <linux/init.h>
33#include <linux/ioport.h>
34#include <linux/of.h>
35#include <linux/of_device.h>
36#include <linux/of_gpio.h>
37#include <linux/platform_device.h>
38#include <linux/delay.h>
39#include <linux/interrupt.h>
40#include <linux/dma-mapping.h>
41#include <linux/dmaengine.h>
42#include <linux/highmem.h>
43#include <linux/clk.h>
44#include <linux/err.h>
45#include <linux/completion.h>
46#include <linux/gpio.h>
47#include <linux/regulator/consumer.h>
48#include <linux/module.h>
49#include <linux/pinctrl/consumer.h>
50#include <linux/stmp_device.h>
51#include <linux/spi/spi.h>
52#include <linux/spi/mxs-spi.h>
53
54#define DRIVER_NAME "mxs-spi"
55
56/* Use 10S timeout for very long transfers, it should suffice. */
57#define SSP_TIMEOUT 10000
58
59#define SG_MAXLEN 0xff00
60
61struct mxs_spi {
62 struct mxs_ssp ssp;
63 struct completion c;
64};
65
66static int mxs_spi_setup_transfer(struct spi_device *dev,
67 struct spi_transfer *t)
68{
69 struct mxs_spi *spi = spi_master_get_devdata(dev->master);
70 struct mxs_ssp *ssp = &spi->ssp;
71 uint8_t bits_per_word;
72 uint32_t hz = 0;
73
74 bits_per_word = dev->bits_per_word;
75 if (t && t->bits_per_word)
76 bits_per_word = t->bits_per_word;
77
78 if (bits_per_word != 8) {
79 dev_err(&dev->dev, "%s, unsupported bits_per_word=%d\n",
80 __func__, bits_per_word);
81 return -EINVAL;
82 }
83
84 hz = dev->max_speed_hz;
85 if (t && t->speed_hz)
86 hz = min(hz, t->speed_hz);
87 if (hz == 0) {
88 dev_err(&dev->dev, "Cannot continue with zero clock\n");
89 return -EINVAL;
90 }
91
92 mxs_ssp_set_clk_rate(ssp, hz);
93
94 writel(BF_SSP_CTRL1_SSP_MODE(BV_SSP_CTRL1_SSP_MODE__SPI) |
95 BF_SSP_CTRL1_WORD_LENGTH
96 (BV_SSP_CTRL1_WORD_LENGTH__EIGHT_BITS) |
97 ((dev->mode & SPI_CPOL) ? BM_SSP_CTRL1_POLARITY : 0) |
98 ((dev->mode & SPI_CPHA) ? BM_SSP_CTRL1_PHASE : 0),
99 ssp->base + HW_SSP_CTRL1(ssp));
100
101 writel(0x0, ssp->base + HW_SSP_CMD0);
102 writel(0x0, ssp->base + HW_SSP_CMD1);
103
104 return 0;
105}
106
107static int mxs_spi_setup(struct spi_device *dev)
108{
109 int err = 0;
110
111 if (!dev->bits_per_word)
112 dev->bits_per_word = 8;
113
114 if (dev->mode & ~(SPI_CPOL | SPI_CPHA))
115 return -EINVAL;
116
117 err = mxs_spi_setup_transfer(dev, NULL);
118 if (err) {
119 dev_err(&dev->dev,
120 "Failed to setup transfer, error = %d\n", err);
121 }
122
123 return err;
124}
125
126static uint32_t mxs_spi_cs_to_reg(unsigned cs)
127{
128 uint32_t select = 0;
129
130 /*
131 * i.MX28 Datasheet: 17.10.1: HW_SSP_CTRL0
132 *
133 * The bits BM_SSP_CTRL0_WAIT_FOR_CMD and BM_SSP_CTRL0_WAIT_FOR_IRQ
134 * in HW_SSP_CTRL0 register do have multiple usage, please refer to
135 * the datasheet for further details. In SPI mode, they are used to
136 * toggle the chip-select lines (nCS pins).
137 */
138 if (cs & 1)
139 select |= BM_SSP_CTRL0_WAIT_FOR_CMD;
140 if (cs & 2)
141 select |= BM_SSP_CTRL0_WAIT_FOR_IRQ;
142
143 return select;
144}
145
146static void mxs_spi_set_cs(struct mxs_spi *spi, unsigned cs)
147{
148 const uint32_t mask =
149 BM_SSP_CTRL0_WAIT_FOR_CMD | BM_SSP_CTRL0_WAIT_FOR_IRQ;
150 uint32_t select;
151 struct mxs_ssp *ssp = &spi->ssp;
152
153 writel(mask, ssp->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_CLR);
154 select = mxs_spi_cs_to_reg(cs);
155 writel(select, ssp->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_SET);
156}
157
158static inline void mxs_spi_enable(struct mxs_spi *spi)
159{
160 struct mxs_ssp *ssp = &spi->ssp;
161
162 writel(BM_SSP_CTRL0_LOCK_CS,
163 ssp->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_SET);
164 writel(BM_SSP_CTRL0_IGNORE_CRC,
165 ssp->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_CLR);
166}
167
168static inline void mxs_spi_disable(struct mxs_spi *spi)
169{
170 struct mxs_ssp *ssp = &spi->ssp;
171
172 writel(BM_SSP_CTRL0_LOCK_CS,
173 ssp->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_CLR);
174 writel(BM_SSP_CTRL0_IGNORE_CRC,
175 ssp->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_SET);
176}
177
178static int mxs_ssp_wait(struct mxs_spi *spi, int offset, int mask, bool set)
179{
180 const unsigned long timeout = jiffies + msecs_to_jiffies(SSP_TIMEOUT);
181 struct mxs_ssp *ssp = &spi->ssp;
182 uint32_t reg;
183
184 do {
185 reg = readl_relaxed(ssp->base + offset);
186
187 if (!set)
188 reg = ~reg;
189
190 reg &= mask;
191
192 if (reg == mask)
193 return 0;
194 } while (time_before(jiffies, timeout));
195
196 return -ETIMEDOUT;
197}
198
199static void mxs_ssp_dma_irq_callback(void *param)
200{
201 struct mxs_spi *spi = param;
202 complete(&spi->c);
203}
204
205static irqreturn_t mxs_ssp_irq_handler(int irq, void *dev_id)
206{
207 struct mxs_ssp *ssp = dev_id;
208 dev_err(ssp->dev, "%s[%i] CTRL1=%08x STATUS=%08x\n",
209 __func__, __LINE__,
210 readl(ssp->base + HW_SSP_CTRL1(ssp)),
211 readl(ssp->base + HW_SSP_STATUS(ssp)));
212 return IRQ_HANDLED;
213}
214
215static int mxs_spi_txrx_dma(struct mxs_spi *spi, int cs,
216 unsigned char *buf, int len,
217 int *first, int *last, int write)
218{
219 struct mxs_ssp *ssp = &spi->ssp;
220 struct dma_async_tx_descriptor *desc = NULL;
221 const bool vmalloced_buf = is_vmalloc_addr(buf);
222 const int desc_len = vmalloced_buf ? PAGE_SIZE : SG_MAXLEN;
223 const int sgs = DIV_ROUND_UP(len, desc_len);
224 int sg_count;
225 int min, ret;
226 uint32_t ctrl0;
227 struct page *vm_page;
228 void *sg_buf;
229 struct {
230 uint32_t pio[4];
231 struct scatterlist sg;
232 } *dma_xfer;
233
234 if (!len)
235 return -EINVAL;
236
237 dma_xfer = kzalloc(sizeof(*dma_xfer) * sgs, GFP_KERNEL);
238 if (!dma_xfer)
239 return -ENOMEM;
240
241 INIT_COMPLETION(spi->c);
242
243 ctrl0 = readl(ssp->base + HW_SSP_CTRL0);
244 ctrl0 |= BM_SSP_CTRL0_DATA_XFER | mxs_spi_cs_to_reg(cs);
245
246 if (*first)
247 ctrl0 |= BM_SSP_CTRL0_LOCK_CS;
248 if (!write)
249 ctrl0 |= BM_SSP_CTRL0_READ;
250
251 /* Queue the DMA data transfer. */
252 for (sg_count = 0; sg_count < sgs; sg_count++) {
253 min = min(len, desc_len);
254
255 /* Prepare the transfer descriptor. */
256 if ((sg_count + 1 == sgs) && *last)
257 ctrl0 |= BM_SSP_CTRL0_IGNORE_CRC;
258
259 if (ssp->devid == IMX23_SSP)
260 ctrl0 |= min;
261
262 dma_xfer[sg_count].pio[0] = ctrl0;
263 dma_xfer[sg_count].pio[3] = min;
264
265 if (vmalloced_buf) {
266 vm_page = vmalloc_to_page(buf);
267 if (!vm_page) {
268 ret = -ENOMEM;
269 goto err_vmalloc;
270 }
271 sg_buf = page_address(vm_page) +
272 ((size_t)buf & ~PAGE_MASK);
273 } else {
274 sg_buf = buf;
275 }
276
277 sg_init_one(&dma_xfer[sg_count].sg, sg_buf, min);
278 ret = dma_map_sg(ssp->dev, &dma_xfer[sg_count].sg, 1,
279 write ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
280
281 len -= min;
282 buf += min;
283
284 /* Queue the PIO register write transfer. */
285 desc = dmaengine_prep_slave_sg(ssp->dmach,
286 (struct scatterlist *)dma_xfer[sg_count].pio,
287 (ssp->devid == IMX23_SSP) ? 1 : 4,
288 DMA_TRANS_NONE,
289 sg_count ? DMA_PREP_INTERRUPT : 0);
290 if (!desc) {
291 dev_err(ssp->dev,
292 "Failed to get PIO reg. write descriptor.\n");
293 ret = -EINVAL;
294 goto err_mapped;
295 }
296
297 desc = dmaengine_prep_slave_sg(ssp->dmach,
298 &dma_xfer[sg_count].sg, 1,
299 write ? DMA_MEM_TO_DEV : DMA_DEV_TO_MEM,
300 DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
301
302 if (!desc) {
303 dev_err(ssp->dev,
304 "Failed to get DMA data write descriptor.\n");
305 ret = -EINVAL;
306 goto err_mapped;
307 }
308 }
309
310 /*
311 * The last descriptor must have this callback,
312 * to finish the DMA transaction.
313 */
314 desc->callback = mxs_ssp_dma_irq_callback;
315 desc->callback_param = spi;
316
317 /* Start the transfer. */
318 dmaengine_submit(desc);
319 dma_async_issue_pending(ssp->dmach);
320
321 ret = wait_for_completion_timeout(&spi->c,
322 msecs_to_jiffies(SSP_TIMEOUT));
323 if (!ret) {
324 dev_err(ssp->dev, "DMA transfer timeout\n");
325 ret = -ETIMEDOUT;
326 goto err_vmalloc;
327 }
328
329 ret = 0;
330
331err_vmalloc:
332 while (--sg_count >= 0) {
333err_mapped:
334 dma_unmap_sg(ssp->dev, &dma_xfer[sg_count].sg, 1,
335 write ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
336 }
337
338 kfree(dma_xfer);
339
340 return ret;
341}
342
343static int mxs_spi_txrx_pio(struct mxs_spi *spi, int cs,
344 unsigned char *buf, int len,
345 int *first, int *last, int write)
346{
347 struct mxs_ssp *ssp = &spi->ssp;
348
349 if (*first)
350 mxs_spi_enable(spi);
351
352 mxs_spi_set_cs(spi, cs);
353
354 while (len--) {
355 if (*last && len == 0)
356 mxs_spi_disable(spi);
357
358 if (ssp->devid == IMX23_SSP) {
359 writel(BM_SSP_CTRL0_XFER_COUNT,
360 ssp->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_CLR);
361 writel(1,
362 ssp->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_SET);
363 } else {
364 writel(1, ssp->base + HW_SSP_XFER_SIZE);
365 }
366
367 if (write)
368 writel(BM_SSP_CTRL0_READ,
369 ssp->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_CLR);
370 else
371 writel(BM_SSP_CTRL0_READ,
372 ssp->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_SET);
373
374 writel(BM_SSP_CTRL0_RUN,
375 ssp->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_SET);
376
377 if (mxs_ssp_wait(spi, HW_SSP_CTRL0, BM_SSP_CTRL0_RUN, 1))
378 return -ETIMEDOUT;
379
380 if (write)
381 writel(*buf, ssp->base + HW_SSP_DATA(ssp));
382
383 writel(BM_SSP_CTRL0_DATA_XFER,
384 ssp->base + HW_SSP_CTRL0 + STMP_OFFSET_REG_SET);
385
386 if (!write) {
387 if (mxs_ssp_wait(spi, HW_SSP_STATUS(ssp),
388 BM_SSP_STATUS_FIFO_EMPTY, 0))
389 return -ETIMEDOUT;
390
391 *buf = (readl(ssp->base + HW_SSP_DATA(ssp)) & 0xff);
392 }
393
394 if (mxs_ssp_wait(spi, HW_SSP_CTRL0, BM_SSP_CTRL0_RUN, 0))
395 return -ETIMEDOUT;
396
397 buf++;
398 }
399
400 if (len <= 0)
401 return 0;
402
403 return -ETIMEDOUT;
404}
405
406static int mxs_spi_transfer_one(struct spi_master *master,
407 struct spi_message *m)
408{
409 struct mxs_spi *spi = spi_master_get_devdata(master);
410 struct mxs_ssp *ssp = &spi->ssp;
411 int first, last;
412 struct spi_transfer *t, *tmp_t;
413 int status = 0;
414 int cs;
415
416 first = last = 0;
417
418 cs = m->spi->chip_select;
419
420 list_for_each_entry_safe(t, tmp_t, &m->transfers, transfer_list) {
421
422 status = mxs_spi_setup_transfer(m->spi, t);
423 if (status)
424 break;
425
426 if (&t->transfer_list == m->transfers.next)
427 first = 1;
428 if (&t->transfer_list == m->transfers.prev)
429 last = 1;
430 if ((t->rx_buf && t->tx_buf) || (t->rx_dma && t->tx_dma)) {
431 dev_err(ssp->dev,
432 "Cannot send and receive simultaneously\n");
433 status = -EINVAL;
434 break;
435 }
436
437 /*
438 * Small blocks can be transfered via PIO.
439 * Measured by empiric means:
440 *
441 * dd if=/dev/mtdblock0 of=/dev/null bs=1024k count=1
442 *
443 * DMA only: 2.164808 seconds, 473.0KB/s
444 * Combined: 1.676276 seconds, 610.9KB/s
445 */
446 if (t->len < 32) {
447 writel(BM_SSP_CTRL1_DMA_ENABLE,
448 ssp->base + HW_SSP_CTRL1(ssp) +
449 STMP_OFFSET_REG_CLR);
450
451 if (t->tx_buf)
452 status = mxs_spi_txrx_pio(spi, cs,
453 (void *)t->tx_buf,
454 t->len, &first, &last, 1);
455 if (t->rx_buf)
456 status = mxs_spi_txrx_pio(spi, cs,
457 t->rx_buf, t->len,
458 &first, &last, 0);
459 } else {
460 writel(BM_SSP_CTRL1_DMA_ENABLE,
461 ssp->base + HW_SSP_CTRL1(ssp) +
462 STMP_OFFSET_REG_SET);
463
464 if (t->tx_buf)
465 status = mxs_spi_txrx_dma(spi, cs,
466 (void *)t->tx_buf, t->len,
467 &first, &last, 1);
468 if (t->rx_buf)
469 status = mxs_spi_txrx_dma(spi, cs,
470 t->rx_buf, t->len,
471 &first, &last, 0);
472 }
473
474 if (status) {
475 stmp_reset_block(ssp->base);
476 break;
477 }
478
479 m->actual_length += t->len;
480 first = last = 0;
481 }
482
483 m->status = 0;
484 spi_finalize_current_message(master);
485
486 return status;
487}
488
489static bool mxs_ssp_dma_filter(struct dma_chan *chan, void *param)
490{
491 struct mxs_ssp *ssp = param;
492
493 if (!mxs_dma_is_apbh(chan))
494 return false;
495
496 if (chan->chan_id != ssp->dma_channel)
497 return false;
498
499 chan->private = &ssp->dma_data;
500
501 return true;
502}
503
504static const struct of_device_id mxs_spi_dt_ids[] = {
505 { .compatible = "fsl,imx23-spi", .data = (void *) IMX23_SSP, },
506 { .compatible = "fsl,imx28-spi", .data = (void *) IMX28_SSP, },
507 { /* sentinel */ }
508};
509MODULE_DEVICE_TABLE(of, mxs_spi_dt_ids);
510
511static int __devinit mxs_spi_probe(struct platform_device *pdev)
512{
513 const struct of_device_id *of_id =
514 of_match_device(mxs_spi_dt_ids, &pdev->dev);
515 struct device_node *np = pdev->dev.of_node;
516 struct spi_master *master;
517 struct mxs_spi *spi;
518 struct mxs_ssp *ssp;
519 struct resource *iores, *dmares;
520 struct pinctrl *pinctrl;
521 struct clk *clk;
522 void __iomem *base;
523 int devid, dma_channel, clk_freq;
524 int ret = 0, irq_err, irq_dma;
525 dma_cap_mask_t mask;
526
527 /*
528 * Default clock speed for the SPI core. 160MHz seems to
529 * work reasonably well with most SPI flashes, so use this
530 * as a default. Override with "clock-frequency" DT prop.
531 */
532 const int clk_freq_default = 160000000;
533
534 iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
535 irq_err = platform_get_irq(pdev, 0);
536 irq_dma = platform_get_irq(pdev, 1);
537 if (!iores || irq_err < 0 || irq_dma < 0)
538 return -EINVAL;
539
540 base = devm_request_and_ioremap(&pdev->dev, iores);
541 if (!base)
542 return -EADDRNOTAVAIL;
543
544 pinctrl = devm_pinctrl_get_select_default(&pdev->dev);
545 if (IS_ERR(pinctrl))
546 return PTR_ERR(pinctrl);
547
548 clk = devm_clk_get(&pdev->dev, NULL);
549 if (IS_ERR(clk))
550 return PTR_ERR(clk);
551
552 if (np) {
553 devid = (enum mxs_ssp_id) of_id->data;
554 /*
555 * TODO: This is a temporary solution and should be changed
556 * to use generic DMA binding later when the helpers get in.
557 */
558 ret = of_property_read_u32(np, "fsl,ssp-dma-channel",
559 &dma_channel);
560 if (ret) {
561 dev_err(&pdev->dev,
562 "Failed to get DMA channel\n");
563 return -EINVAL;
564 }
565
566 ret = of_property_read_u32(np, "clock-frequency",
567 &clk_freq);
568 if (ret)
569 clk_freq = clk_freq_default;
570 } else {
571 dmares = platform_get_resource(pdev, IORESOURCE_DMA, 0);
572 if (!dmares)
573 return -EINVAL;
574 devid = pdev->id_entry->driver_data;
575 dma_channel = dmares->start;
576 clk_freq = clk_freq_default;
577 }
578
579 master = spi_alloc_master(&pdev->dev, sizeof(*spi));
580 if (!master)
581 return -ENOMEM;
582
583 master->transfer_one_message = mxs_spi_transfer_one;
584 master->setup = mxs_spi_setup;
585 master->mode_bits = SPI_CPOL | SPI_CPHA;
586 master->num_chipselect = 3;
587 master->dev.of_node = np;
588 master->flags = SPI_MASTER_HALF_DUPLEX;
589
590 spi = spi_master_get_devdata(master);
591 ssp = &spi->ssp;
592 ssp->dev = &pdev->dev;
593 ssp->clk = clk;
594 ssp->base = base;
595 ssp->devid = devid;
596 ssp->dma_channel = dma_channel;
597
598 init_completion(&spi->c);
599
600 ret = devm_request_irq(&pdev->dev, irq_err, mxs_ssp_irq_handler, 0,
601 DRIVER_NAME, ssp);
602 if (ret)
603 goto out_master_free;
604
605 dma_cap_zero(mask);
606 dma_cap_set(DMA_SLAVE, mask);
607 ssp->dma_data.chan_irq = irq_dma;
608 ssp->dmach = dma_request_channel(mask, mxs_ssp_dma_filter, ssp);
609 if (!ssp->dmach) {
610 dev_err(ssp->dev, "Failed to request DMA\n");
611 goto out_master_free;
612 }
613
614 clk_prepare_enable(ssp->clk);
615 clk_set_rate(ssp->clk, clk_freq);
616 ssp->clk_rate = clk_get_rate(ssp->clk) / 1000;
617
618 stmp_reset_block(ssp->base);
619
620 platform_set_drvdata(pdev, master);
621
622 ret = spi_register_master(master);
623 if (ret) {
624 dev_err(&pdev->dev, "Cannot register SPI master, %d\n", ret);
625 goto out_free_dma;
626 }
627
628 return 0;
629
630out_free_dma:
631 dma_release_channel(ssp->dmach);
632 clk_disable_unprepare(ssp->clk);
633out_master_free:
634 spi_master_put(master);
635 return ret;
636}
637
638static int __devexit mxs_spi_remove(struct platform_device *pdev)
639{
640 struct spi_master *master;
641 struct mxs_spi *spi;
642 struct mxs_ssp *ssp;
643
644 master = spi_master_get(platform_get_drvdata(pdev));
645 spi = spi_master_get_devdata(master);
646 ssp = &spi->ssp;
647
648 spi_unregister_master(master);
649
650 dma_release_channel(ssp->dmach);
651
652 clk_disable_unprepare(ssp->clk);
653
654 spi_master_put(master);
655
656 return 0;
657}
658
659static struct platform_driver mxs_spi_driver = {
660 .probe = mxs_spi_probe,
661 .remove = __devexit_p(mxs_spi_remove),
662 .driver = {
663 .name = DRIVER_NAME,
664 .owner = THIS_MODULE,
665 .of_match_table = mxs_spi_dt_ids,
666 },
667};
668
669module_platform_driver(mxs_spi_driver);
670
671MODULE_AUTHOR("Marek Vasut <marex@denx.de>");
672MODULE_DESCRIPTION("MXS SPI master driver");
673MODULE_LICENSE("GPL");
674MODULE_ALIAS("platform:mxs-spi");
diff --git a/drivers/spi/spi-oc-tiny.c b/drivers/spi/spi-oc-tiny.c
index 698018fd992b..9d9071b730be 100644
--- a/drivers/spi/spi-oc-tiny.c
+++ b/drivers/spi/spi-oc-tiny.c
@@ -129,7 +129,7 @@ static int tiny_spi_txrx_bufs(struct spi_device *spi, struct spi_transfer *t)
129 unsigned int i; 129 unsigned int i;
130 130
131 if (hw->irq >= 0) { 131 if (hw->irq >= 0) {
132 /* use intrrupt driven data transfer */ 132 /* use interrupt driven data transfer */
133 hw->len = t->len; 133 hw->len = t->len;
134 hw->txp = t->tx_buf; 134 hw->txp = t->tx_buf;
135 hw->rxp = t->rx_buf; 135 hw->rxp = t->rx_buf;
diff --git a/drivers/spi/spi-omap2-mcspi.c b/drivers/spi/spi-omap2-mcspi.c
index d3d62f1e894c..3542fdc664b1 100644
--- a/drivers/spi/spi-omap2-mcspi.c
+++ b/drivers/spi/spi-omap2-mcspi.c
@@ -38,6 +38,8 @@
38#include <linux/pm_runtime.h> 38#include <linux/pm_runtime.h>
39#include <linux/of.h> 39#include <linux/of.h>
40#include <linux/of_device.h> 40#include <linux/of_device.h>
41#include <linux/pinctrl/consumer.h>
42#include <linux/err.h>
41 43
42#include <linux/spi/spi.h> 44#include <linux/spi/spi.h>
43 45
@@ -139,13 +141,6 @@ struct omap2_mcspi_cs {
139 u32 chconf0; 141 u32 chconf0;
140}; 142};
141 143
142#define MOD_REG_BIT(val, mask, set) do { \
143 if (set) \
144 val |= mask; \
145 else \
146 val &= ~mask; \
147} while (0)
148
149static inline void mcspi_write_reg(struct spi_master *master, 144static inline void mcspi_write_reg(struct spi_master *master,
150 int idx, u32 val) 145 int idx, u32 val)
151{ 146{
@@ -204,7 +199,11 @@ static void omap2_mcspi_set_dma_req(const struct spi_device *spi,
204 else 199 else
205 rw = OMAP2_MCSPI_CHCONF_DMAW; 200 rw = OMAP2_MCSPI_CHCONF_DMAW;
206 201
207 MOD_REG_BIT(l, rw, enable); 202 if (enable)
203 l |= rw;
204 else
205 l &= ~rw;
206
208 mcspi_write_chconf0(spi, l); 207 mcspi_write_chconf0(spi, l);
209} 208}
210 209
@@ -223,7 +222,11 @@ static void omap2_mcspi_force_cs(struct spi_device *spi, int cs_active)
223 u32 l; 222 u32 l;
224 223
225 l = mcspi_cached_chconf0(spi); 224 l = mcspi_cached_chconf0(spi);
226 MOD_REG_BIT(l, OMAP2_MCSPI_CHCONF_FORCE, cs_active); 225 if (cs_active)
226 l |= OMAP2_MCSPI_CHCONF_FORCE;
227 else
228 l &= ~OMAP2_MCSPI_CHCONF_FORCE;
229
227 mcspi_write_chconf0(spi, l); 230 mcspi_write_chconf0(spi, l);
228} 231}
229 232
@@ -238,9 +241,8 @@ static void omap2_mcspi_set_master_mode(struct spi_master *master)
238 * to single-channel master mode 241 * to single-channel master mode
239 */ 242 */
240 l = mcspi_read_reg(master, OMAP2_MCSPI_MODULCTRL); 243 l = mcspi_read_reg(master, OMAP2_MCSPI_MODULCTRL);
241 MOD_REG_BIT(l, OMAP2_MCSPI_MODULCTRL_STEST, 0); 244 l &= ~(OMAP2_MCSPI_MODULCTRL_STEST | OMAP2_MCSPI_MODULCTRL_MS);
242 MOD_REG_BIT(l, OMAP2_MCSPI_MODULCTRL_MS, 0); 245 l |= OMAP2_MCSPI_MODULCTRL_SINGLE;
243 MOD_REG_BIT(l, OMAP2_MCSPI_MODULCTRL_SINGLE, 1);
244 mcspi_write_reg(master, OMAP2_MCSPI_MODULCTRL, l); 246 mcspi_write_reg(master, OMAP2_MCSPI_MODULCTRL, l);
245 247
246 ctx->modulctrl = l; 248 ctx->modulctrl = l;
@@ -259,16 +261,6 @@ static void omap2_mcspi_restore_ctx(struct omap2_mcspi *mcspi)
259 list_for_each_entry(cs, &ctx->cs, node) 261 list_for_each_entry(cs, &ctx->cs, node)
260 __raw_writel(cs->chconf0, cs->base + OMAP2_MCSPI_CHCONF0); 262 __raw_writel(cs->chconf0, cs->base + OMAP2_MCSPI_CHCONF0);
261} 263}
262static void omap2_mcspi_disable_clocks(struct omap2_mcspi *mcspi)
263{
264 pm_runtime_mark_last_busy(mcspi->dev);
265 pm_runtime_put_autosuspend(mcspi->dev);
266}
267
268static int omap2_mcspi_enable_clocks(struct omap2_mcspi *mcspi)
269{
270 return pm_runtime_get_sync(mcspi->dev);
271}
272 264
273static int omap2_prepare_transfer(struct spi_master *master) 265static int omap2_prepare_transfer(struct spi_master *master)
274{ 266{
@@ -324,49 +316,27 @@ static void omap2_mcspi_tx_callback(void *data)
324 omap2_mcspi_set_dma_req(spi, 0, 0); 316 omap2_mcspi_set_dma_req(spi, 0, 0);
325} 317}
326 318
327static unsigned 319static void omap2_mcspi_tx_dma(struct spi_device *spi,
328omap2_mcspi_txrx_dma(struct spi_device *spi, struct spi_transfer *xfer) 320 struct spi_transfer *xfer,
321 struct dma_slave_config cfg)
329{ 322{
330 struct omap2_mcspi *mcspi; 323 struct omap2_mcspi *mcspi;
331 struct omap2_mcspi_cs *cs = spi->controller_state;
332 struct omap2_mcspi_dma *mcspi_dma; 324 struct omap2_mcspi_dma *mcspi_dma;
333 unsigned int count; 325 unsigned int count;
334 int word_len, element_count;
335 int elements = 0;
336 u32 l;
337 u8 * rx; 326 u8 * rx;
338 const u8 * tx; 327 const u8 * tx;
339 void __iomem *chstat_reg; 328 void __iomem *chstat_reg;
340 struct dma_slave_config cfg; 329 struct omap2_mcspi_cs *cs = spi->controller_state;
341 enum dma_slave_buswidth width;
342 unsigned es;
343 330
344 mcspi = spi_master_get_devdata(spi->master); 331 mcspi = spi_master_get_devdata(spi->master);
345 mcspi_dma = &mcspi->dma_channels[spi->chip_select]; 332 mcspi_dma = &mcspi->dma_channels[spi->chip_select];
346 l = mcspi_cached_chconf0(spi); 333 count = xfer->len;
347 334
335 rx = xfer->rx_buf;
336 tx = xfer->tx_buf;
348 chstat_reg = cs->base + OMAP2_MCSPI_CHSTAT0; 337 chstat_reg = cs->base + OMAP2_MCSPI_CHSTAT0;
349 338
350 if (cs->word_len <= 8) { 339 if (mcspi_dma->dma_tx) {
351 width = DMA_SLAVE_BUSWIDTH_1_BYTE;
352 es = 1;
353 } else if (cs->word_len <= 16) {
354 width = DMA_SLAVE_BUSWIDTH_2_BYTES;
355 es = 2;
356 } else {
357 width = DMA_SLAVE_BUSWIDTH_4_BYTES;
358 es = 4;
359 }
360
361 memset(&cfg, 0, sizeof(cfg));
362 cfg.src_addr = cs->phys + OMAP2_MCSPI_RX0;
363 cfg.dst_addr = cs->phys + OMAP2_MCSPI_TX0;
364 cfg.src_addr_width = width;
365 cfg.dst_addr_width = width;
366 cfg.src_maxburst = 1;
367 cfg.dst_maxburst = 1;
368
369 if (xfer->tx_buf && mcspi_dma->dma_tx) {
370 struct dma_async_tx_descriptor *tx; 340 struct dma_async_tx_descriptor *tx;
371 struct scatterlist sg; 341 struct scatterlist sg;
372 342
@@ -377,7 +347,7 @@ omap2_mcspi_txrx_dma(struct spi_device *spi, struct spi_transfer *xfer)
377 sg_dma_len(&sg) = xfer->len; 347 sg_dma_len(&sg) = xfer->len;
378 348
379 tx = dmaengine_prep_slave_sg(mcspi_dma->dma_tx, &sg, 1, 349 tx = dmaengine_prep_slave_sg(mcspi_dma->dma_tx, &sg, 1,
380 DMA_MEM_TO_DEV, DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 350 DMA_MEM_TO_DEV, DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
381 if (tx) { 351 if (tx) {
382 tx->callback = omap2_mcspi_tx_callback; 352 tx->callback = omap2_mcspi_tx_callback;
383 tx->callback_param = spi; 353 tx->callback_param = spi;
@@ -386,8 +356,50 @@ omap2_mcspi_txrx_dma(struct spi_device *spi, struct spi_transfer *xfer)
386 /* FIXME: fall back to PIO? */ 356 /* FIXME: fall back to PIO? */
387 } 357 }
388 } 358 }
359 dma_async_issue_pending(mcspi_dma->dma_tx);
360 omap2_mcspi_set_dma_req(spi, 0, 1);
361
362 wait_for_completion(&mcspi_dma->dma_tx_completion);
363 dma_unmap_single(mcspi->dev, xfer->tx_dma, count,
364 DMA_TO_DEVICE);
365
366 /* for TX_ONLY mode, be sure all words have shifted out */
367 if (rx == NULL) {
368 if (mcspi_wait_for_reg_bit(chstat_reg,
369 OMAP2_MCSPI_CHSTAT_TXS) < 0)
370 dev_err(&spi->dev, "TXS timed out\n");
371 else if (mcspi_wait_for_reg_bit(chstat_reg,
372 OMAP2_MCSPI_CHSTAT_EOT) < 0)
373 dev_err(&spi->dev, "EOT timed out\n");
374 }
375}
376
377static unsigned
378omap2_mcspi_rx_dma(struct spi_device *spi, struct spi_transfer *xfer,
379 struct dma_slave_config cfg,
380 unsigned es)
381{
382 struct omap2_mcspi *mcspi;
383 struct omap2_mcspi_dma *mcspi_dma;
384 unsigned int count;
385 u32 l;
386 int elements = 0;
387 int word_len, element_count;
388 struct omap2_mcspi_cs *cs = spi->controller_state;
389 mcspi = spi_master_get_devdata(spi->master);
390 mcspi_dma = &mcspi->dma_channels[spi->chip_select];
391 count = xfer->len;
392 word_len = cs->word_len;
393 l = mcspi_cached_chconf0(spi);
389 394
390 if (xfer->rx_buf && mcspi_dma->dma_rx) { 395 if (word_len <= 8)
396 element_count = count;
397 else if (word_len <= 16)
398 element_count = count >> 1;
399 else /* word_len <= 32 */
400 element_count = count >> 2;
401
402 if (mcspi_dma->dma_rx) {
391 struct dma_async_tx_descriptor *tx; 403 struct dma_async_tx_descriptor *tx;
392 struct scatterlist sg; 404 struct scatterlist sg;
393 size_t len = xfer->len - es; 405 size_t len = xfer->len - es;
@@ -402,108 +414,120 @@ omap2_mcspi_txrx_dma(struct spi_device *spi, struct spi_transfer *xfer)
402 sg_dma_len(&sg) = len; 414 sg_dma_len(&sg) = len;
403 415
404 tx = dmaengine_prep_slave_sg(mcspi_dma->dma_rx, &sg, 1, 416 tx = dmaengine_prep_slave_sg(mcspi_dma->dma_rx, &sg, 1,
405 DMA_DEV_TO_MEM, DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 417 DMA_DEV_TO_MEM, DMA_PREP_INTERRUPT |
418 DMA_CTRL_ACK);
406 if (tx) { 419 if (tx) {
407 tx->callback = omap2_mcspi_rx_callback; 420 tx->callback = omap2_mcspi_rx_callback;
408 tx->callback_param = spi; 421 tx->callback_param = spi;
409 dmaengine_submit(tx); 422 dmaengine_submit(tx);
410 } else { 423 } else {
411 /* FIXME: fall back to PIO? */ 424 /* FIXME: fall back to PIO? */
412 }
413 }
414
415 count = xfer->len;
416 word_len = cs->word_len;
417
418 rx = xfer->rx_buf;
419 tx = xfer->tx_buf;
420
421 if (word_len <= 8) {
422 element_count = count;
423 } else if (word_len <= 16) {
424 element_count = count >> 1;
425 } else /* word_len <= 32 */ {
426 element_count = count >> 2;
427 }
428
429 if (tx != NULL) {
430 dma_async_issue_pending(mcspi_dma->dma_tx);
431 omap2_mcspi_set_dma_req(spi, 0, 1);
432 }
433
434 if (rx != NULL) {
435 dma_async_issue_pending(mcspi_dma->dma_rx);
436 omap2_mcspi_set_dma_req(spi, 1, 1);
437 }
438
439 if (tx != NULL) {
440 wait_for_completion(&mcspi_dma->dma_tx_completion);
441 dma_unmap_single(mcspi->dev, xfer->tx_dma, count,
442 DMA_TO_DEVICE);
443
444 /* for TX_ONLY mode, be sure all words have shifted out */
445 if (rx == NULL) {
446 if (mcspi_wait_for_reg_bit(chstat_reg,
447 OMAP2_MCSPI_CHSTAT_TXS) < 0)
448 dev_err(&spi->dev, "TXS timed out\n");
449 else if (mcspi_wait_for_reg_bit(chstat_reg,
450 OMAP2_MCSPI_CHSTAT_EOT) < 0)
451 dev_err(&spi->dev, "EOT timed out\n");
452 } 425 }
453 } 426 }
454 427
455 if (rx != NULL) { 428 dma_async_issue_pending(mcspi_dma->dma_rx);
456 wait_for_completion(&mcspi_dma->dma_rx_completion); 429 omap2_mcspi_set_dma_req(spi, 1, 1);
457 dma_unmap_single(mcspi->dev, xfer->rx_dma, count,
458 DMA_FROM_DEVICE);
459 omap2_mcspi_set_enable(spi, 0);
460 430
461 elements = element_count - 1; 431 wait_for_completion(&mcspi_dma->dma_rx_completion);
432 dma_unmap_single(mcspi->dev, xfer->rx_dma, count,
433 DMA_FROM_DEVICE);
434 omap2_mcspi_set_enable(spi, 0);
462 435
463 if (l & OMAP2_MCSPI_CHCONF_TURBO) { 436 elements = element_count - 1;
464 elements--;
465 437
466 if (likely(mcspi_read_cs_reg(spi, OMAP2_MCSPI_CHSTAT0) 438 if (l & OMAP2_MCSPI_CHCONF_TURBO) {
467 & OMAP2_MCSPI_CHSTAT_RXS)) { 439 elements--;
468 u32 w;
469
470 w = mcspi_read_cs_reg(spi, OMAP2_MCSPI_RX0);
471 if (word_len <= 8)
472 ((u8 *)xfer->rx_buf)[elements++] = w;
473 else if (word_len <= 16)
474 ((u16 *)xfer->rx_buf)[elements++] = w;
475 else /* word_len <= 32 */
476 ((u32 *)xfer->rx_buf)[elements++] = w;
477 } else {
478 dev_err(&spi->dev,
479 "DMA RX penultimate word empty");
480 count -= (word_len <= 8) ? 2 :
481 (word_len <= 16) ? 4 :
482 /* word_len <= 32 */ 8;
483 omap2_mcspi_set_enable(spi, 1);
484 return count;
485 }
486 }
487 440
488 if (likely(mcspi_read_cs_reg(spi, OMAP2_MCSPI_CHSTAT0) 441 if (likely(mcspi_read_cs_reg(spi, OMAP2_MCSPI_CHSTAT0)
489 & OMAP2_MCSPI_CHSTAT_RXS)) { 442 & OMAP2_MCSPI_CHSTAT_RXS)) {
490 u32 w; 443 u32 w;
491 444
492 w = mcspi_read_cs_reg(spi, OMAP2_MCSPI_RX0); 445 w = mcspi_read_cs_reg(spi, OMAP2_MCSPI_RX0);
493 if (word_len <= 8) 446 if (word_len <= 8)
494 ((u8 *)xfer->rx_buf)[elements] = w; 447 ((u8 *)xfer->rx_buf)[elements++] = w;
495 else if (word_len <= 16) 448 else if (word_len <= 16)
496 ((u16 *)xfer->rx_buf)[elements] = w; 449 ((u16 *)xfer->rx_buf)[elements++] = w;
497 else /* word_len <= 32 */ 450 else /* word_len <= 32 */
498 ((u32 *)xfer->rx_buf)[elements] = w; 451 ((u32 *)xfer->rx_buf)[elements++] = w;
499 } else { 452 } else {
500 dev_err(&spi->dev, "DMA RX last word empty"); 453 dev_err(&spi->dev, "DMA RX penultimate word empty");
501 count -= (word_len <= 8) ? 1 : 454 count -= (word_len <= 8) ? 2 :
502 (word_len <= 16) ? 2 : 455 (word_len <= 16) ? 4 :
503 /* word_len <= 32 */ 4; 456 /* word_len <= 32 */ 8;
457 omap2_mcspi_set_enable(spi, 1);
458 return count;
504 } 459 }
505 omap2_mcspi_set_enable(spi, 1);
506 } 460 }
461 if (likely(mcspi_read_cs_reg(spi, OMAP2_MCSPI_CHSTAT0)
462 & OMAP2_MCSPI_CHSTAT_RXS)) {
463 u32 w;
464
465 w = mcspi_read_cs_reg(spi, OMAP2_MCSPI_RX0);
466 if (word_len <= 8)
467 ((u8 *)xfer->rx_buf)[elements] = w;
468 else if (word_len <= 16)
469 ((u16 *)xfer->rx_buf)[elements] = w;
470 else /* word_len <= 32 */
471 ((u32 *)xfer->rx_buf)[elements] = w;
472 } else {
473 dev_err(&spi->dev, "DMA RX last word empty");
474 count -= (word_len <= 8) ? 1 :
475 (word_len <= 16) ? 2 :
476 /* word_len <= 32 */ 4;
477 }
478 omap2_mcspi_set_enable(spi, 1);
479 return count;
480}
481
482static unsigned
483omap2_mcspi_txrx_dma(struct spi_device *spi, struct spi_transfer *xfer)
484{
485 struct omap2_mcspi *mcspi;
486 struct omap2_mcspi_cs *cs = spi->controller_state;
487 struct omap2_mcspi_dma *mcspi_dma;
488 unsigned int count;
489 u32 l;
490 u8 *rx;
491 const u8 *tx;
492 struct dma_slave_config cfg;
493 enum dma_slave_buswidth width;
494 unsigned es;
495
496 mcspi = spi_master_get_devdata(spi->master);
497 mcspi_dma = &mcspi->dma_channels[spi->chip_select];
498 l = mcspi_cached_chconf0(spi);
499
500
501 if (cs->word_len <= 8) {
502 width = DMA_SLAVE_BUSWIDTH_1_BYTE;
503 es = 1;
504 } else if (cs->word_len <= 16) {
505 width = DMA_SLAVE_BUSWIDTH_2_BYTES;
506 es = 2;
507 } else {
508 width = DMA_SLAVE_BUSWIDTH_4_BYTES;
509 es = 4;
510 }
511
512 memset(&cfg, 0, sizeof(cfg));
513 cfg.src_addr = cs->phys + OMAP2_MCSPI_RX0;
514 cfg.dst_addr = cs->phys + OMAP2_MCSPI_TX0;
515 cfg.src_addr_width = width;
516 cfg.dst_addr_width = width;
517 cfg.src_maxburst = 1;
518 cfg.dst_maxburst = 1;
519
520 rx = xfer->rx_buf;
521 tx = xfer->tx_buf;
522
523 count = xfer->len;
524
525 if (tx != NULL)
526 omap2_mcspi_tx_dma(spi, xfer, cfg);
527
528 if (rx != NULL)
529 return omap2_mcspi_rx_dma(spi, xfer, cfg, es);
530
507 return count; 531 return count;
508} 532}
509 533
@@ -847,12 +871,13 @@ static int omap2_mcspi_setup(struct spi_device *spi)
847 return ret; 871 return ret;
848 } 872 }
849 873
850 ret = omap2_mcspi_enable_clocks(mcspi); 874 ret = pm_runtime_get_sync(mcspi->dev);
851 if (ret < 0) 875 if (ret < 0)
852 return ret; 876 return ret;
853 877
854 ret = omap2_mcspi_setup_transfer(spi, NULL); 878 ret = omap2_mcspi_setup_transfer(spi, NULL);
855 omap2_mcspi_disable_clocks(mcspi); 879 pm_runtime_mark_last_busy(mcspi->dev);
880 pm_runtime_put_autosuspend(mcspi->dev);
856 881
857 return ret; 882 return ret;
858} 883}
@@ -1066,7 +1091,7 @@ static int __devinit omap2_mcspi_master_setup(struct omap2_mcspi *mcspi)
1066 struct omap2_mcspi_regs *ctx = &mcspi->ctx; 1091 struct omap2_mcspi_regs *ctx = &mcspi->ctx;
1067 int ret = 0; 1092 int ret = 0;
1068 1093
1069 ret = omap2_mcspi_enable_clocks(mcspi); 1094 ret = pm_runtime_get_sync(mcspi->dev);
1070 if (ret < 0) 1095 if (ret < 0)
1071 return ret; 1096 return ret;
1072 1097
@@ -1075,7 +1100,8 @@ static int __devinit omap2_mcspi_master_setup(struct omap2_mcspi *mcspi)
1075 ctx->wakeupenable = OMAP2_MCSPI_WAKEUPENABLE_WKEN; 1100 ctx->wakeupenable = OMAP2_MCSPI_WAKEUPENABLE_WKEN;
1076 1101
1077 omap2_mcspi_set_master_mode(master); 1102 omap2_mcspi_set_master_mode(master);
1078 omap2_mcspi_disable_clocks(mcspi); 1103 pm_runtime_mark_last_busy(mcspi->dev);
1104 pm_runtime_put_autosuspend(mcspi->dev);
1079 return 0; 1105 return 0;
1080} 1106}
1081 1107
@@ -1115,7 +1141,7 @@ MODULE_DEVICE_TABLE(of, omap_mcspi_of_match);
1115static int __devinit omap2_mcspi_probe(struct platform_device *pdev) 1141static int __devinit omap2_mcspi_probe(struct platform_device *pdev)
1116{ 1142{
1117 struct spi_master *master; 1143 struct spi_master *master;
1118 struct omap2_mcspi_platform_config *pdata; 1144 const struct omap2_mcspi_platform_config *pdata;
1119 struct omap2_mcspi *mcspi; 1145 struct omap2_mcspi *mcspi;
1120 struct resource *r; 1146 struct resource *r;
1121 int status = 0, i; 1147 int status = 0, i;
@@ -1123,6 +1149,7 @@ static int __devinit omap2_mcspi_probe(struct platform_device *pdev)
1123 static int bus_num = 1; 1149 static int bus_num = 1;
1124 struct device_node *node = pdev->dev.of_node; 1150 struct device_node *node = pdev->dev.of_node;
1125 const struct of_device_id *match; 1151 const struct of_device_id *match;
1152 struct pinctrl *pinctrl;
1126 1153
1127 master = spi_alloc_master(&pdev->dev, sizeof *mcspi); 1154 master = spi_alloc_master(&pdev->dev, sizeof *mcspi);
1128 if (master == NULL) { 1155 if (master == NULL) {
@@ -1218,6 +1245,11 @@ static int __devinit omap2_mcspi_probe(struct platform_device *pdev)
1218 if (status < 0) 1245 if (status < 0)
1219 goto dma_chnl_free; 1246 goto dma_chnl_free;
1220 1247
1248 pinctrl = devm_pinctrl_get_select_default(&pdev->dev);
1249 if (IS_ERR(pinctrl))
1250 dev_warn(&pdev->dev,
1251 "pins are not configured from the driver\n");
1252
1221 pm_runtime_use_autosuspend(&pdev->dev); 1253 pm_runtime_use_autosuspend(&pdev->dev);
1222 pm_runtime_set_autosuspend_delay(&pdev->dev, SPI_AUTOSUSPEND_TIMEOUT); 1254 pm_runtime_set_autosuspend_delay(&pdev->dev, SPI_AUTOSUSPEND_TIMEOUT);
1223 pm_runtime_enable(&pdev->dev); 1255 pm_runtime_enable(&pdev->dev);
@@ -1237,7 +1269,6 @@ dma_chnl_free:
1237 kfree(mcspi->dma_channels); 1269 kfree(mcspi->dma_channels);
1238free_master: 1270free_master:
1239 spi_master_put(master); 1271 spi_master_put(master);
1240 platform_set_drvdata(pdev, NULL);
1241 return status; 1272 return status;
1242} 1273}
1243 1274
@@ -1251,12 +1282,11 @@ static int __devexit omap2_mcspi_remove(struct platform_device *pdev)
1251 mcspi = spi_master_get_devdata(master); 1282 mcspi = spi_master_get_devdata(master);
1252 dma_channels = mcspi->dma_channels; 1283 dma_channels = mcspi->dma_channels;
1253 1284
1254 omap2_mcspi_disable_clocks(mcspi); 1285 pm_runtime_put_sync(mcspi->dev);
1255 pm_runtime_disable(&pdev->dev); 1286 pm_runtime_disable(&pdev->dev);
1256 1287
1257 spi_unregister_master(master); 1288 spi_unregister_master(master);
1258 kfree(dma_channels); 1289 kfree(dma_channels);
1259 platform_set_drvdata(pdev, NULL);
1260 1290
1261 return 0; 1291 return 0;
1262} 1292}
@@ -1277,20 +1307,21 @@ static int omap2_mcspi_resume(struct device *dev)
1277 struct omap2_mcspi_regs *ctx = &mcspi->ctx; 1307 struct omap2_mcspi_regs *ctx = &mcspi->ctx;
1278 struct omap2_mcspi_cs *cs; 1308 struct omap2_mcspi_cs *cs;
1279 1309
1280 omap2_mcspi_enable_clocks(mcspi); 1310 pm_runtime_get_sync(mcspi->dev);
1281 list_for_each_entry(cs, &ctx->cs, node) { 1311 list_for_each_entry(cs, &ctx->cs, node) {
1282 if ((cs->chconf0 & OMAP2_MCSPI_CHCONF_FORCE) == 0) { 1312 if ((cs->chconf0 & OMAP2_MCSPI_CHCONF_FORCE) == 0) {
1283 /* 1313 /*
1284 * We need to toggle CS state for OMAP take this 1314 * We need to toggle CS state for OMAP take this
1285 * change in account. 1315 * change in account.
1286 */ 1316 */
1287 MOD_REG_BIT(cs->chconf0, OMAP2_MCSPI_CHCONF_FORCE, 1); 1317 cs->chconf0 |= OMAP2_MCSPI_CHCONF_FORCE;
1288 __raw_writel(cs->chconf0, cs->base + OMAP2_MCSPI_CHCONF0); 1318 __raw_writel(cs->chconf0, cs->base + OMAP2_MCSPI_CHCONF0);
1289 MOD_REG_BIT(cs->chconf0, OMAP2_MCSPI_CHCONF_FORCE, 0); 1319 cs->chconf0 &= ~OMAP2_MCSPI_CHCONF_FORCE;
1290 __raw_writel(cs->chconf0, cs->base + OMAP2_MCSPI_CHCONF0); 1320 __raw_writel(cs->chconf0, cs->base + OMAP2_MCSPI_CHCONF0);
1291 } 1321 }
1292 } 1322 }
1293 omap2_mcspi_disable_clocks(mcspi); 1323 pm_runtime_mark_last_busy(mcspi->dev);
1324 pm_runtime_put_autosuspend(mcspi->dev);
1294 return 0; 1325 return 0;
1295} 1326}
1296#else 1327#else
diff --git a/drivers/spi/spi-orion.c b/drivers/spi/spi-orion.c
index 9b0caddce503..b17c09cf0a05 100644
--- a/drivers/spi/spi-orion.c
+++ b/drivers/spi/spi-orion.c
@@ -36,12 +36,6 @@
36#define ORION_SPI_CLK_PRESCALE_MASK 0x1F 36#define ORION_SPI_CLK_PRESCALE_MASK 0x1F
37 37
38struct orion_spi { 38struct orion_spi {
39 struct work_struct work;
40
41 /* Lock access to transfer list. */
42 spinlock_t lock;
43
44 struct list_head msg_queue;
45 struct spi_master *master; 39 struct spi_master *master;
46 void __iomem *base; 40 void __iomem *base;
47 unsigned int max_speed; 41 unsigned int max_speed;
@@ -49,8 +43,6 @@ struct orion_spi {
49 struct clk *clk; 43 struct clk *clk;
50}; 44};
51 45
52static struct workqueue_struct *orion_spi_wq;
53
54static inline void __iomem *spi_reg(struct orion_spi *orion_spi, u32 reg) 46static inline void __iomem *spi_reg(struct orion_spi *orion_spi, u32 reg)
55{ 47{
56 return orion_spi->base + reg; 48 return orion_spi->base + reg;
@@ -277,73 +269,78 @@ out:
277} 269}
278 270
279 271
280static void orion_spi_work(struct work_struct *work) 272static int orion_spi_transfer_one_message(struct spi_master *master,
273 struct spi_message *m)
281{ 274{
282 struct orion_spi *orion_spi = 275 struct orion_spi *orion_spi = spi_master_get_devdata(master);
283 container_of(work, struct orion_spi, work); 276 struct spi_device *spi = m->spi;
284 277 struct spi_transfer *t = NULL;
285 spin_lock_irq(&orion_spi->lock); 278 int par_override = 0;
286 while (!list_empty(&orion_spi->msg_queue)) { 279 int status = 0;
287 struct spi_message *m; 280 int cs_active = 0;
288 struct spi_device *spi;
289 struct spi_transfer *t = NULL;
290 int par_override = 0;
291 int status = 0;
292 int cs_active = 0;
293
294 m = container_of(orion_spi->msg_queue.next, struct spi_message,
295 queue);
296 281
297 list_del_init(&m->queue); 282 /* Load defaults */
298 spin_unlock_irq(&orion_spi->lock); 283 status = orion_spi_setup_transfer(spi, NULL);
299 284
300 spi = m->spi; 285 if (status < 0)
286 goto msg_done;
301 287
302 /* Load defaults */ 288 list_for_each_entry(t, &m->transfers, transfer_list) {
303 status = orion_spi_setup_transfer(spi, NULL); 289 /* make sure buffer length is even when working in 16
290 * bit mode*/
291 if ((t->bits_per_word == 16) && (t->len & 1)) {
292 dev_err(&spi->dev,
293 "message rejected : "
294 "odd data length %d while in 16 bit mode\n",
295 t->len);
296 status = -EIO;
297 goto msg_done;
298 }
304 299
305 if (status < 0) 300 if (t->speed_hz && t->speed_hz < orion_spi->min_speed) {
301 dev_err(&spi->dev,
302 "message rejected : "
303 "device min speed (%d Hz) exceeds "
304 "required transfer speed (%d Hz)\n",
305 orion_spi->min_speed, t->speed_hz);
306 status = -EIO;
306 goto msg_done; 307 goto msg_done;
308 }
307 309
308 list_for_each_entry(t, &m->transfers, transfer_list) { 310 if (par_override || t->speed_hz || t->bits_per_word) {
309 if (par_override || t->speed_hz || t->bits_per_word) { 311 par_override = 1;
310 par_override = 1; 312 status = orion_spi_setup_transfer(spi, t);
311 status = orion_spi_setup_transfer(spi, t); 313 if (status < 0)
312 if (status < 0) 314 break;
313 break; 315 if (!t->speed_hz && !t->bits_per_word)
314 if (!t->speed_hz && !t->bits_per_word) 316 par_override = 0;
315 par_override = 0;
316 }
317
318 if (!cs_active) {
319 orion_spi_set_cs(orion_spi, 1);
320 cs_active = 1;
321 }
322
323 if (t->len)
324 m->actual_length +=
325 orion_spi_write_read(spi, t);
326
327 if (t->delay_usecs)
328 udelay(t->delay_usecs);
329
330 if (t->cs_change) {
331 orion_spi_set_cs(orion_spi, 0);
332 cs_active = 0;
333 }
334 } 317 }
335 318
336msg_done: 319 if (!cs_active) {
337 if (cs_active) 320 orion_spi_set_cs(orion_spi, 1);
338 orion_spi_set_cs(orion_spi, 0); 321 cs_active = 1;
322 }
339 323
340 m->status = status; 324 if (t->len)
341 m->complete(m->context); 325 m->actual_length += orion_spi_write_read(spi, t);
342 326
343 spin_lock_irq(&orion_spi->lock); 327 if (t->delay_usecs)
328 udelay(t->delay_usecs);
329
330 if (t->cs_change) {
331 orion_spi_set_cs(orion_spi, 0);
332 cs_active = 0;
333 }
344 } 334 }
345 335
346 spin_unlock_irq(&orion_spi->lock); 336msg_done:
337 if (cs_active)
338 orion_spi_set_cs(orion_spi, 0);
339
340 m->status = status;
341 spi_finalize_current_message(master);
342
343 return 0;
347} 344}
348 345
349static int __init orion_spi_reset(struct orion_spi *orion_spi) 346static int __init orion_spi_reset(struct orion_spi *orion_spi)
@@ -376,75 +373,6 @@ static int orion_spi_setup(struct spi_device *spi)
376 return 0; 373 return 0;
377} 374}
378 375
379static int orion_spi_transfer(struct spi_device *spi, struct spi_message *m)
380{
381 struct orion_spi *orion_spi;
382 struct spi_transfer *t = NULL;
383 unsigned long flags;
384
385 m->actual_length = 0;
386 m->status = 0;
387
388 /* reject invalid messages and transfers */
389 if (list_empty(&m->transfers) || !m->complete)
390 return -EINVAL;
391
392 orion_spi = spi_master_get_devdata(spi->master);
393
394 list_for_each_entry(t, &m->transfers, transfer_list) {
395 unsigned int bits_per_word = spi->bits_per_word;
396
397 if (t->tx_buf == NULL && t->rx_buf == NULL && t->len) {
398 dev_err(&spi->dev,
399 "message rejected : "
400 "invalid transfer data buffers\n");
401 goto msg_rejected;
402 }
403
404 if (t->bits_per_word)
405 bits_per_word = t->bits_per_word;
406
407 if ((bits_per_word != 8) && (bits_per_word != 16)) {
408 dev_err(&spi->dev,
409 "message rejected : "
410 "invalid transfer bits_per_word (%d bits)\n",
411 bits_per_word);
412 goto msg_rejected;
413 }
414 /*make sure buffer length is even when working in 16 bit mode*/
415 if ((t->bits_per_word == 16) && (t->len & 1)) {
416 dev_err(&spi->dev,
417 "message rejected : "
418 "odd data length (%d) while in 16 bit mode\n",
419 t->len);
420 goto msg_rejected;
421 }
422
423 if (t->speed_hz && t->speed_hz < orion_spi->min_speed) {
424 dev_err(&spi->dev,
425 "message rejected : "
426 "device min speed (%d Hz) exceeds "
427 "required transfer speed (%d Hz)\n",
428 orion_spi->min_speed, t->speed_hz);
429 goto msg_rejected;
430 }
431 }
432
433
434 spin_lock_irqsave(&orion_spi->lock, flags);
435 list_add_tail(&m->queue, &orion_spi->msg_queue);
436 queue_work(orion_spi_wq, &orion_spi->work);
437 spin_unlock_irqrestore(&orion_spi->lock, flags);
438
439 return 0;
440msg_rejected:
441 /* Message rejected and not queued */
442 m->status = -EINVAL;
443 if (m->complete)
444 m->complete(m->context);
445 return -EINVAL;
446}
447
448static int __init orion_spi_probe(struct platform_device *pdev) 376static int __init orion_spi_probe(struct platform_device *pdev)
449{ 377{
450 struct spi_master *master; 378 struct spi_master *master;
@@ -474,7 +402,7 @@ static int __init orion_spi_probe(struct platform_device *pdev)
474 master->mode_bits = 0; 402 master->mode_bits = 0;
475 403
476 master->setup = orion_spi_setup; 404 master->setup = orion_spi_setup;
477 master->transfer = orion_spi_transfer; 405 master->transfer_one_message = orion_spi_transfer_one_message;
478 master->num_chipselect = ORION_NUM_CHIPSELECTS; 406 master->num_chipselect = ORION_NUM_CHIPSELECTS;
479 407
480 dev_set_drvdata(&pdev->dev, master); 408 dev_set_drvdata(&pdev->dev, master);
@@ -507,11 +435,6 @@ static int __init orion_spi_probe(struct platform_device *pdev)
507 } 435 }
508 spi->base = ioremap(r->start, SZ_1K); 436 spi->base = ioremap(r->start, SZ_1K);
509 437
510 INIT_WORK(&spi->work, orion_spi_work);
511
512 spin_lock_init(&spi->lock);
513 INIT_LIST_HEAD(&spi->msg_queue);
514
515 if (orion_spi_reset(spi) < 0) 438 if (orion_spi_reset(spi) < 0)
516 goto out_rel_mem; 439 goto out_rel_mem;
517 440
@@ -536,14 +459,12 @@ out:
536static int __exit orion_spi_remove(struct platform_device *pdev) 459static int __exit orion_spi_remove(struct platform_device *pdev)
537{ 460{
538 struct spi_master *master; 461 struct spi_master *master;
539 struct orion_spi *spi;
540 struct resource *r; 462 struct resource *r;
463 struct orion_spi *spi;
541 464
542 master = dev_get_drvdata(&pdev->dev); 465 master = dev_get_drvdata(&pdev->dev);
543 spi = spi_master_get_devdata(master); 466 spi = spi_master_get_devdata(master);
544 467
545 cancel_work_sync(&spi->work);
546
547 clk_disable_unprepare(spi->clk); 468 clk_disable_unprepare(spi->clk);
548 clk_put(spi->clk); 469 clk_put(spi->clk);
549 470
@@ -574,21 +495,13 @@ static struct platform_driver orion_spi_driver = {
574 495
575static int __init orion_spi_init(void) 496static int __init orion_spi_init(void)
576{ 497{
577 orion_spi_wq = create_singlethread_workqueue(
578 orion_spi_driver.driver.name);
579 if (orion_spi_wq == NULL)
580 return -ENOMEM;
581
582 return platform_driver_probe(&orion_spi_driver, orion_spi_probe); 498 return platform_driver_probe(&orion_spi_driver, orion_spi_probe);
583} 499}
584module_init(orion_spi_init); 500module_init(orion_spi_init);
585 501
586static void __exit orion_spi_exit(void) 502static void __exit orion_spi_exit(void)
587{ 503{
588 flush_workqueue(orion_spi_wq);
589 platform_driver_unregister(&orion_spi_driver); 504 platform_driver_unregister(&orion_spi_driver);
590
591 destroy_workqueue(orion_spi_wq);
592} 505}
593module_exit(orion_spi_exit); 506module_exit(orion_spi_exit);
594 507
diff --git a/drivers/spi/spi-pl022.c b/drivers/spi/spi-pl022.c
index 6abbe23c39b4..919464102d33 100644
--- a/drivers/spi/spi-pl022.c
+++ b/drivers/spi/spi-pl022.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * A driver for the ARM PL022 PrimeCell SSP/SPI bus master. 2 * A driver for the ARM PL022 PrimeCell SSP/SPI bus master.
3 * 3 *
4 * Copyright (C) 2008-2009 ST-Ericsson AB 4 * Copyright (C) 2008-2012 ST-Ericsson AB
5 * Copyright (C) 2006 STMicroelectronics Pvt. Ltd. 5 * Copyright (C) 2006 STMicroelectronics Pvt. Ltd.
6 * 6 *
7 * Author: Linus Walleij <linus.walleij@stericsson.com> 7 * Author: Linus Walleij <linus.walleij@stericsson.com>
@@ -40,6 +40,9 @@
40#include <linux/dma-mapping.h> 40#include <linux/dma-mapping.h>
41#include <linux/scatterlist.h> 41#include <linux/scatterlist.h>
42#include <linux/pm_runtime.h> 42#include <linux/pm_runtime.h>
43#include <linux/gpio.h>
44#include <linux/of_gpio.h>
45#include <linux/pinctrl/consumer.h>
43 46
44/* 47/*
45 * This macro is used to define some register default values. 48 * This macro is used to define some register default values.
@@ -356,6 +359,8 @@ struct vendor_data {
356 * @sgt_rx: scattertable for the RX transfer 359 * @sgt_rx: scattertable for the RX transfer
357 * @sgt_tx: scattertable for the TX transfer 360 * @sgt_tx: scattertable for the TX transfer
358 * @dummypage: a dummy page used for driving data on the bus with DMA 361 * @dummypage: a dummy page used for driving data on the bus with DMA
362 * @cur_cs: current chip select (gpio)
363 * @chipselects: list of chipselects (gpios)
359 */ 364 */
360struct pl022 { 365struct pl022 {
361 struct amba_device *adev; 366 struct amba_device *adev;
@@ -363,6 +368,10 @@ struct pl022 {
363 resource_size_t phybase; 368 resource_size_t phybase;
364 void __iomem *virtbase; 369 void __iomem *virtbase;
365 struct clk *clk; 370 struct clk *clk;
371 /* Two optional pin states - default & sleep */
372 struct pinctrl *pinctrl;
373 struct pinctrl_state *pins_default;
374 struct pinctrl_state *pins_sleep;
366 struct spi_master *master; 375 struct spi_master *master;
367 struct pl022_ssp_controller *master_info; 376 struct pl022_ssp_controller *master_info;
368 /* Message per-transfer pump */ 377 /* Message per-transfer pump */
@@ -389,6 +398,8 @@ struct pl022 {
389 char *dummypage; 398 char *dummypage;
390 bool dma_running; 399 bool dma_running;
391#endif 400#endif
401 int cur_cs;
402 int *chipselects;
392}; 403};
393 404
394/** 405/**
@@ -433,6 +444,14 @@ static void null_cs_control(u32 command)
433 pr_debug("pl022: dummy chip select control, CS=0x%x\n", command); 444 pr_debug("pl022: dummy chip select control, CS=0x%x\n", command);
434} 445}
435 446
447static void pl022_cs_control(struct pl022 *pl022, u32 command)
448{
449 if (gpio_is_valid(pl022->cur_cs))
450 gpio_set_value(pl022->cur_cs, command);
451 else
452 pl022->cur_chip->cs_control(command);
453}
454
436/** 455/**
437 * giveback - current spi_message is over, schedule next message and call 456 * giveback - current spi_message is over, schedule next message and call
438 * callback of this message. Assumes that caller already 457 * callback of this message. Assumes that caller already
@@ -479,7 +498,7 @@ static void giveback(struct pl022 *pl022)
479 if (next_msg && next_msg->spi != pl022->cur_msg->spi) 498 if (next_msg && next_msg->spi != pl022->cur_msg->spi)
480 next_msg = NULL; 499 next_msg = NULL;
481 if (!next_msg || pl022->cur_msg->state == STATE_ERROR) 500 if (!next_msg || pl022->cur_msg->state == STATE_ERROR)
482 pl022->cur_chip->cs_control(SSP_CHIP_DESELECT); 501 pl022_cs_control(pl022, SSP_CHIP_DESELECT);
483 else 502 else
484 pl022->next_msg_cs_active = true; 503 pl022->next_msg_cs_active = true;
485 504
@@ -818,8 +837,7 @@ static void dma_callback(void *data)
818 /* Update total bytes transferred */ 837 /* Update total bytes transferred */
819 msg->actual_length += pl022->cur_transfer->len; 838 msg->actual_length += pl022->cur_transfer->len;
820 if (pl022->cur_transfer->cs_change) 839 if (pl022->cur_transfer->cs_change)
821 pl022->cur_chip-> 840 pl022_cs_control(pl022, SSP_CHIP_DESELECT);
822 cs_control(SSP_CHIP_DESELECT);
823 841
824 /* Move to next transfer */ 842 /* Move to next transfer */
825 msg->state = next_transfer(pl022); 843 msg->state = next_transfer(pl022);
@@ -1252,8 +1270,7 @@ static irqreturn_t pl022_interrupt_handler(int irq, void *dev_id)
1252 /* Update total bytes transferred */ 1270 /* Update total bytes transferred */
1253 msg->actual_length += pl022->cur_transfer->len; 1271 msg->actual_length += pl022->cur_transfer->len;
1254 if (pl022->cur_transfer->cs_change) 1272 if (pl022->cur_transfer->cs_change)
1255 pl022->cur_chip-> 1273 pl022_cs_control(pl022, SSP_CHIP_DESELECT);
1256 cs_control(SSP_CHIP_DESELECT);
1257 /* Move to next transfer */ 1274 /* Move to next transfer */
1258 msg->state = next_transfer(pl022); 1275 msg->state = next_transfer(pl022);
1259 tasklet_schedule(&pl022->pump_transfers); 1276 tasklet_schedule(&pl022->pump_transfers);
@@ -1338,7 +1355,7 @@ static void pump_transfers(unsigned long data)
1338 1355
1339 /* Reselect chip select only if cs_change was requested */ 1356 /* Reselect chip select only if cs_change was requested */
1340 if (previous->cs_change) 1357 if (previous->cs_change)
1341 pl022->cur_chip->cs_control(SSP_CHIP_SELECT); 1358 pl022_cs_control(pl022, SSP_CHIP_SELECT);
1342 } else { 1359 } else {
1343 /* STATE_START */ 1360 /* STATE_START */
1344 message->state = STATE_RUNNING; 1361 message->state = STATE_RUNNING;
@@ -1377,7 +1394,7 @@ static void do_interrupt_dma_transfer(struct pl022 *pl022)
1377 1394
1378 /* Enable target chip, if not already active */ 1395 /* Enable target chip, if not already active */
1379 if (!pl022->next_msg_cs_active) 1396 if (!pl022->next_msg_cs_active)
1380 pl022->cur_chip->cs_control(SSP_CHIP_SELECT); 1397 pl022_cs_control(pl022, SSP_CHIP_SELECT);
1381 1398
1382 if (set_up_next_transfer(pl022, pl022->cur_transfer)) { 1399 if (set_up_next_transfer(pl022, pl022->cur_transfer)) {
1383 /* Error path */ 1400 /* Error path */
@@ -1429,12 +1446,12 @@ static void do_polling_transfer(struct pl022 *pl022)
1429 if (previous->delay_usecs) 1446 if (previous->delay_usecs)
1430 udelay(previous->delay_usecs); 1447 udelay(previous->delay_usecs);
1431 if (previous->cs_change) 1448 if (previous->cs_change)
1432 pl022->cur_chip->cs_control(SSP_CHIP_SELECT); 1449 pl022_cs_control(pl022, SSP_CHIP_SELECT);
1433 } else { 1450 } else {
1434 /* STATE_START */ 1451 /* STATE_START */
1435 message->state = STATE_RUNNING; 1452 message->state = STATE_RUNNING;
1436 if (!pl022->next_msg_cs_active) 1453 if (!pl022->next_msg_cs_active)
1437 pl022->cur_chip->cs_control(SSP_CHIP_SELECT); 1454 pl022_cs_control(pl022, SSP_CHIP_SELECT);
1438 } 1455 }
1439 1456
1440 /* Configuration Changing Per Transfer */ 1457 /* Configuration Changing Per Transfer */
@@ -1466,7 +1483,7 @@ static void do_polling_transfer(struct pl022 *pl022)
1466 /* Update total byte transferred */ 1483 /* Update total byte transferred */
1467 message->actual_length += pl022->cur_transfer->len; 1484 message->actual_length += pl022->cur_transfer->len;
1468 if (pl022->cur_transfer->cs_change) 1485 if (pl022->cur_transfer->cs_change)
1469 pl022->cur_chip->cs_control(SSP_CHIP_DESELECT); 1486 pl022_cs_control(pl022, SSP_CHIP_DESELECT);
1470 /* Move to next transfer */ 1487 /* Move to next transfer */
1471 message->state = next_transfer(pl022); 1488 message->state = next_transfer(pl022);
1472 } 1489 }
@@ -1495,6 +1512,7 @@ static int pl022_transfer_one_message(struct spi_master *master,
1495 1512
1496 /* Setup the SPI using the per chip configuration */ 1513 /* Setup the SPI using the per chip configuration */
1497 pl022->cur_chip = spi_get_ctldata(msg->spi); 1514 pl022->cur_chip = spi_get_ctldata(msg->spi);
1515 pl022->cur_cs = pl022->chipselects[msg->spi->chip_select];
1498 1516
1499 restore_state(pl022); 1517 restore_state(pl022);
1500 flush(pl022); 1518 flush(pl022);
@@ -1766,12 +1784,14 @@ static const struct pl022_config_chip pl022_default_chip_info = {
1766static int pl022_setup(struct spi_device *spi) 1784static int pl022_setup(struct spi_device *spi)
1767{ 1785{
1768 struct pl022_config_chip const *chip_info; 1786 struct pl022_config_chip const *chip_info;
1787 struct pl022_config_chip chip_info_dt;
1769 struct chip_data *chip; 1788 struct chip_data *chip;
1770 struct ssp_clock_params clk_freq = { .cpsdvsr = 0, .scr = 0}; 1789 struct ssp_clock_params clk_freq = { .cpsdvsr = 0, .scr = 0};
1771 int status = 0; 1790 int status = 0;
1772 struct pl022 *pl022 = spi_master_get_devdata(spi->master); 1791 struct pl022 *pl022 = spi_master_get_devdata(spi->master);
1773 unsigned int bits = spi->bits_per_word; 1792 unsigned int bits = spi->bits_per_word;
1774 u32 tmp; 1793 u32 tmp;
1794 struct device_node *np = spi->dev.of_node;
1775 1795
1776 if (!spi->max_speed_hz) 1796 if (!spi->max_speed_hz)
1777 return -EINVAL; 1797 return -EINVAL;
@@ -1794,10 +1814,32 @@ static int pl022_setup(struct spi_device *spi)
1794 chip_info = spi->controller_data; 1814 chip_info = spi->controller_data;
1795 1815
1796 if (chip_info == NULL) { 1816 if (chip_info == NULL) {
1797 chip_info = &pl022_default_chip_info; 1817 if (np) {
1798 /* spi_board_info.controller_data not is supplied */ 1818 chip_info_dt = pl022_default_chip_info;
1799 dev_dbg(&spi->dev, 1819
1800 "using default controller_data settings\n"); 1820 chip_info_dt.hierarchy = SSP_MASTER;
1821 of_property_read_u32(np, "pl022,interface",
1822 &chip_info_dt.iface);
1823 of_property_read_u32(np, "pl022,com-mode",
1824 &chip_info_dt.com_mode);
1825 of_property_read_u32(np, "pl022,rx-level-trig",
1826 &chip_info_dt.rx_lev_trig);
1827 of_property_read_u32(np, "pl022,tx-level-trig",
1828 &chip_info_dt.tx_lev_trig);
1829 of_property_read_u32(np, "pl022,ctrl-len",
1830 &chip_info_dt.ctrl_len);
1831 of_property_read_u32(np, "pl022,wait-state",
1832 &chip_info_dt.wait_state);
1833 of_property_read_u32(np, "pl022,duplex",
1834 &chip_info_dt.duplex);
1835
1836 chip_info = &chip_info_dt;
1837 } else {
1838 chip_info = &pl022_default_chip_info;
1839 /* spi_board_info.controller_data not is supplied */
1840 dev_dbg(&spi->dev,
1841 "using default controller_data settings\n");
1842 }
1801 } else 1843 } else
1802 dev_dbg(&spi->dev, 1844 dev_dbg(&spi->dev,
1803 "using user supplied controller_data settings\n"); 1845 "using user supplied controller_data settings\n");
@@ -1840,8 +1882,9 @@ static int pl022_setup(struct spi_device *spi)
1840 chip->xfer_type = chip_info->com_mode; 1882 chip->xfer_type = chip_info->com_mode;
1841 if (!chip_info->cs_control) { 1883 if (!chip_info->cs_control) {
1842 chip->cs_control = null_cs_control; 1884 chip->cs_control = null_cs_control;
1843 dev_warn(&spi->dev, 1885 if (!gpio_is_valid(pl022->chipselects[spi->chip_select]))
1844 "chip select function is NULL for this chip\n"); 1886 dev_warn(&spi->dev,
1887 "invalid chip select\n");
1845 } else 1888 } else
1846 chip->cs_control = chip_info->cs_control; 1889 chip->cs_control = chip_info->cs_control;
1847 1890
@@ -1986,6 +2029,34 @@ static void pl022_cleanup(struct spi_device *spi)
1986 kfree(chip); 2029 kfree(chip);
1987} 2030}
1988 2031
2032static struct pl022_ssp_controller *
2033pl022_platform_data_dt_get(struct device *dev)
2034{
2035 struct device_node *np = dev->of_node;
2036 struct pl022_ssp_controller *pd;
2037 u32 tmp;
2038
2039 if (!np) {
2040 dev_err(dev, "no dt node defined\n");
2041 return NULL;
2042 }
2043
2044 pd = devm_kzalloc(dev, sizeof(struct pl022_ssp_controller), GFP_KERNEL);
2045 if (!pd) {
2046 dev_err(dev, "cannot allocate platform data memory\n");
2047 return NULL;
2048 }
2049
2050 pd->bus_id = -1;
2051 of_property_read_u32(np, "num-cs", &tmp);
2052 pd->num_chipselect = tmp;
2053 of_property_read_u32(np, "pl022,autosuspend-delay",
2054 &pd->autosuspend_delay);
2055 pd->rt = of_property_read_bool(np, "pl022,rt");
2056
2057 return pd;
2058}
2059
1989static int __devinit 2060static int __devinit
1990pl022_probe(struct amba_device *adev, const struct amba_id *id) 2061pl022_probe(struct amba_device *adev, const struct amba_id *id)
1991{ 2062{
@@ -1993,22 +2064,31 @@ pl022_probe(struct amba_device *adev, const struct amba_id *id)
1993 struct pl022_ssp_controller *platform_info = adev->dev.platform_data; 2064 struct pl022_ssp_controller *platform_info = adev->dev.platform_data;
1994 struct spi_master *master; 2065 struct spi_master *master;
1995 struct pl022 *pl022 = NULL; /*Data for this driver */ 2066 struct pl022 *pl022 = NULL; /*Data for this driver */
1996 int status = 0; 2067 struct device_node *np = adev->dev.of_node;
2068 int status = 0, i, num_cs;
1997 2069
1998 dev_info(&adev->dev, 2070 dev_info(&adev->dev,
1999 "ARM PL022 driver, device ID: 0x%08x\n", adev->periphid); 2071 "ARM PL022 driver, device ID: 0x%08x\n", adev->periphid);
2000 if (platform_info == NULL) { 2072 if (!platform_info && IS_ENABLED(CONFIG_OF))
2001 dev_err(&adev->dev, "probe - no platform data supplied\n"); 2073 platform_info = pl022_platform_data_dt_get(dev);
2002 status = -ENODEV; 2074
2003 goto err_no_pdata; 2075 if (!platform_info) {
2076 dev_err(dev, "probe: no platform data defined\n");
2077 return -ENODEV;
2078 }
2079
2080 if (platform_info->num_chipselect) {
2081 num_cs = platform_info->num_chipselect;
2082 } else {
2083 dev_err(dev, "probe: no chip select defined\n");
2084 return -ENODEV;
2004 } 2085 }
2005 2086
2006 /* Allocate master with space for data */ 2087 /* Allocate master with space for data */
2007 master = spi_alloc_master(dev, sizeof(struct pl022)); 2088 master = spi_alloc_master(dev, sizeof(struct pl022));
2008 if (master == NULL) { 2089 if (master == NULL) {
2009 dev_err(&adev->dev, "probe - cannot alloc SPI master\n"); 2090 dev_err(&adev->dev, "probe - cannot alloc SPI master\n");
2010 status = -ENOMEM; 2091 return -ENOMEM;
2011 goto err_no_master;
2012 } 2092 }
2013 2093
2014 pl022 = spi_master_get_devdata(master); 2094 pl022 = spi_master_get_devdata(master);
@@ -2016,19 +2096,71 @@ pl022_probe(struct amba_device *adev, const struct amba_id *id)
2016 pl022->master_info = platform_info; 2096 pl022->master_info = platform_info;
2017 pl022->adev = adev; 2097 pl022->adev = adev;
2018 pl022->vendor = id->data; 2098 pl022->vendor = id->data;
2099 pl022->chipselects = devm_kzalloc(dev, num_cs * sizeof(int),
2100 GFP_KERNEL);
2101
2102 pl022->pinctrl = devm_pinctrl_get(dev);
2103 if (IS_ERR(pl022->pinctrl)) {
2104 status = PTR_ERR(pl022->pinctrl);
2105 goto err_no_pinctrl;
2106 }
2107
2108 pl022->pins_default = pinctrl_lookup_state(pl022->pinctrl,
2109 PINCTRL_STATE_DEFAULT);
2110 /* enable pins to be muxed in and configured */
2111 if (!IS_ERR(pl022->pins_default)) {
2112 status = pinctrl_select_state(pl022->pinctrl,
2113 pl022->pins_default);
2114 if (status)
2115 dev_err(dev, "could not set default pins\n");
2116 } else
2117 dev_err(dev, "could not get default pinstate\n");
2118
2119 pl022->pins_sleep = pinctrl_lookup_state(pl022->pinctrl,
2120 PINCTRL_STATE_SLEEP);
2121 if (IS_ERR(pl022->pins_sleep))
2122 dev_dbg(dev, "could not get sleep pinstate\n");
2019 2123
2020 /* 2124 /*
2021 * Bus Number Which has been Assigned to this SSP controller 2125 * Bus Number Which has been Assigned to this SSP controller
2022 * on this board 2126 * on this board
2023 */ 2127 */
2024 master->bus_num = platform_info->bus_id; 2128 master->bus_num = platform_info->bus_id;
2025 master->num_chipselect = platform_info->num_chipselect; 2129 master->num_chipselect = num_cs;
2026 master->cleanup = pl022_cleanup; 2130 master->cleanup = pl022_cleanup;
2027 master->setup = pl022_setup; 2131 master->setup = pl022_setup;
2028 master->prepare_transfer_hardware = pl022_prepare_transfer_hardware; 2132 master->prepare_transfer_hardware = pl022_prepare_transfer_hardware;
2029 master->transfer_one_message = pl022_transfer_one_message; 2133 master->transfer_one_message = pl022_transfer_one_message;
2030 master->unprepare_transfer_hardware = pl022_unprepare_transfer_hardware; 2134 master->unprepare_transfer_hardware = pl022_unprepare_transfer_hardware;
2031 master->rt = platform_info->rt; 2135 master->rt = platform_info->rt;
2136 master->dev.of_node = dev->of_node;
2137
2138 if (platform_info->num_chipselect && platform_info->chipselects) {
2139 for (i = 0; i < num_cs; i++)
2140 pl022->chipselects[i] = platform_info->chipselects[i];
2141 } else if (IS_ENABLED(CONFIG_OF)) {
2142 for (i = 0; i < num_cs; i++) {
2143 int cs_gpio = of_get_named_gpio(np, "cs-gpios", i);
2144
2145 if (cs_gpio == -EPROBE_DEFER) {
2146 status = -EPROBE_DEFER;
2147 goto err_no_gpio;
2148 }
2149
2150 pl022->chipselects[i] = cs_gpio;
2151
2152 if (gpio_is_valid(cs_gpio)) {
2153 if (devm_gpio_request(dev, cs_gpio, "ssp-pl022"))
2154 dev_err(&adev->dev,
2155 "could not request %d gpio\n",
2156 cs_gpio);
2157 else if (gpio_direction_output(cs_gpio, 1))
2158 dev_err(&adev->dev,
2159 "could set gpio %d as output\n",
2160 cs_gpio);
2161 }
2162 }
2163 }
2032 2164
2033 /* 2165 /*
2034 * Supports mode 0-3, loopback, and active low CS. Transfers are 2166 * Supports mode 0-3, loopback, and active low CS. Transfers are
@@ -2045,7 +2177,8 @@ pl022_probe(struct amba_device *adev, const struct amba_id *id)
2045 goto err_no_ioregion; 2177 goto err_no_ioregion;
2046 2178
2047 pl022->phybase = adev->res.start; 2179 pl022->phybase = adev->res.start;
2048 pl022->virtbase = ioremap(adev->res.start, resource_size(&adev->res)); 2180 pl022->virtbase = devm_ioremap(dev, adev->res.start,
2181 resource_size(&adev->res));
2049 if (pl022->virtbase == NULL) { 2182 if (pl022->virtbase == NULL) {
2050 status = -ENOMEM; 2183 status = -ENOMEM;
2051 goto err_no_ioremap; 2184 goto err_no_ioremap;
@@ -2055,7 +2188,7 @@ pl022_probe(struct amba_device *adev, const struct amba_id *id)
2055 2188
2056 pm_runtime_resume(dev); 2189 pm_runtime_resume(dev);
2057 2190
2058 pl022->clk = clk_get(&adev->dev, NULL); 2191 pl022->clk = devm_clk_get(&adev->dev, NULL);
2059 if (IS_ERR(pl022->clk)) { 2192 if (IS_ERR(pl022->clk)) {
2060 status = PTR_ERR(pl022->clk); 2193 status = PTR_ERR(pl022->clk);
2061 dev_err(&adev->dev, "could not retrieve SSP/SPI bus clock\n"); 2194 dev_err(&adev->dev, "could not retrieve SSP/SPI bus clock\n");
@@ -2083,8 +2216,8 @@ pl022_probe(struct amba_device *adev, const struct amba_id *id)
2083 SSP_CR1(pl022->virtbase)); 2216 SSP_CR1(pl022->virtbase));
2084 load_ssp_default_config(pl022); 2217 load_ssp_default_config(pl022);
2085 2218
2086 status = request_irq(adev->irq[0], pl022_interrupt_handler, 0, "pl022", 2219 status = devm_request_irq(dev, adev->irq[0], pl022_interrupt_handler,
2087 pl022); 2220 0, "pl022", pl022);
2088 if (status < 0) { 2221 if (status < 0) {
2089 dev_err(&adev->dev, "probe - cannot get IRQ (%d)\n", status); 2222 dev_err(&adev->dev, "probe - cannot get IRQ (%d)\n", status);
2090 goto err_no_irq; 2223 goto err_no_irq;
@@ -2124,22 +2257,18 @@ pl022_probe(struct amba_device *adev, const struct amba_id *id)
2124 err_spi_register: 2257 err_spi_register:
2125 if (platform_info->enable_dma) 2258 if (platform_info->enable_dma)
2126 pl022_dma_remove(pl022); 2259 pl022_dma_remove(pl022);
2127
2128 free_irq(adev->irq[0], pl022);
2129 err_no_irq: 2260 err_no_irq:
2130 clk_disable(pl022->clk); 2261 clk_disable(pl022->clk);
2131 err_no_clk_en: 2262 err_no_clk_en:
2132 clk_unprepare(pl022->clk); 2263 clk_unprepare(pl022->clk);
2133 err_clk_prep: 2264 err_clk_prep:
2134 clk_put(pl022->clk);
2135 err_no_clk: 2265 err_no_clk:
2136 iounmap(pl022->virtbase);
2137 err_no_ioremap: 2266 err_no_ioremap:
2138 amba_release_regions(adev); 2267 amba_release_regions(adev);
2139 err_no_ioregion: 2268 err_no_ioregion:
2269 err_no_gpio:
2270 err_no_pinctrl:
2140 spi_master_put(master); 2271 spi_master_put(master);
2141 err_no_master:
2142 err_no_pdata:
2143 return status; 2272 return status;
2144} 2273}
2145 2274
@@ -2161,20 +2290,55 @@ pl022_remove(struct amba_device *adev)
2161 if (pl022->master_info->enable_dma) 2290 if (pl022->master_info->enable_dma)
2162 pl022_dma_remove(pl022); 2291 pl022_dma_remove(pl022);
2163 2292
2164 free_irq(adev->irq[0], pl022);
2165 clk_disable(pl022->clk); 2293 clk_disable(pl022->clk);
2166 clk_unprepare(pl022->clk); 2294 clk_unprepare(pl022->clk);
2167 clk_put(pl022->clk);
2168 pm_runtime_disable(&adev->dev); 2295 pm_runtime_disable(&adev->dev);
2169 iounmap(pl022->virtbase);
2170 amba_release_regions(adev); 2296 amba_release_regions(adev);
2171 tasklet_disable(&pl022->pump_transfers); 2297 tasklet_disable(&pl022->pump_transfers);
2172 spi_unregister_master(pl022->master); 2298 spi_unregister_master(pl022->master);
2173 spi_master_put(pl022->master);
2174 amba_set_drvdata(adev, NULL); 2299 amba_set_drvdata(adev, NULL);
2175 return 0; 2300 return 0;
2176} 2301}
2177 2302
2303#if defined(CONFIG_SUSPEND) || defined(CONFIG_PM_RUNTIME)
2304/*
2305 * These two functions are used from both suspend/resume and
2306 * the runtime counterparts to handle external resources like
2307 * clocks, pins and regulators when going to sleep.
2308 */
2309static void pl022_suspend_resources(struct pl022 *pl022)
2310{
2311 int ret;
2312
2313 clk_disable(pl022->clk);
2314
2315 /* Optionally let pins go into sleep states */
2316 if (!IS_ERR(pl022->pins_sleep)) {
2317 ret = pinctrl_select_state(pl022->pinctrl,
2318 pl022->pins_sleep);
2319 if (ret)
2320 dev_err(&pl022->adev->dev,
2321 "could not set pins to sleep state\n");
2322 }
2323}
2324
2325static void pl022_resume_resources(struct pl022 *pl022)
2326{
2327 int ret;
2328
2329 /* Optionaly enable pins to be muxed in and configured */
2330 if (!IS_ERR(pl022->pins_default)) {
2331 ret = pinctrl_select_state(pl022->pinctrl,
2332 pl022->pins_default);
2333 if (ret)
2334 dev_err(&pl022->adev->dev,
2335 "could not set default pins\n");
2336 }
2337
2338 clk_enable(pl022->clk);
2339}
2340#endif
2341
2178#ifdef CONFIG_SUSPEND 2342#ifdef CONFIG_SUSPEND
2179static int pl022_suspend(struct device *dev) 2343static int pl022_suspend(struct device *dev)
2180{ 2344{
@@ -2186,6 +2350,7 @@ static int pl022_suspend(struct device *dev)
2186 dev_warn(dev, "cannot suspend master\n"); 2350 dev_warn(dev, "cannot suspend master\n");
2187 return ret; 2351 return ret;
2188 } 2352 }
2353 pl022_suspend_resources(pl022);
2189 2354
2190 dev_dbg(dev, "suspended\n"); 2355 dev_dbg(dev, "suspended\n");
2191 return 0; 2356 return 0;
@@ -2196,6 +2361,8 @@ static int pl022_resume(struct device *dev)
2196 struct pl022 *pl022 = dev_get_drvdata(dev); 2361 struct pl022 *pl022 = dev_get_drvdata(dev);
2197 int ret; 2362 int ret;
2198 2363
2364 pl022_resume_resources(pl022);
2365
2199 /* Start the queue running */ 2366 /* Start the queue running */
2200 ret = spi_master_resume(pl022->master); 2367 ret = spi_master_resume(pl022->master);
2201 if (ret) 2368 if (ret)
@@ -2212,8 +2379,7 @@ static int pl022_runtime_suspend(struct device *dev)
2212{ 2379{
2213 struct pl022 *pl022 = dev_get_drvdata(dev); 2380 struct pl022 *pl022 = dev_get_drvdata(dev);
2214 2381
2215 clk_disable(pl022->clk); 2382 pl022_suspend_resources(pl022);
2216
2217 return 0; 2383 return 0;
2218} 2384}
2219 2385
@@ -2221,8 +2387,7 @@ static int pl022_runtime_resume(struct device *dev)
2221{ 2387{
2222 struct pl022 *pl022 = dev_get_drvdata(dev); 2388 struct pl022 *pl022 = dev_get_drvdata(dev);
2223 2389
2224 clk_enable(pl022->clk); 2390 pl022_resume_resources(pl022);
2225
2226 return 0; 2391 return 0;
2227} 2392}
2228#endif 2393#endif
diff --git a/drivers/spi/spi-ppc4xx.c b/drivers/spi/spi-ppc4xx.c
index 75ac9d48ef46..7a85f22b6474 100644
--- a/drivers/spi/spi-ppc4xx.c
+++ b/drivers/spi/spi-ppc4xx.c
@@ -101,7 +101,7 @@ struct spi_ppc4xx_regs {
101 u8 dummy; 101 u8 dummy;
102 /* 102 /*
103 * Clock divisor modulus register 103 * Clock divisor modulus register
104 * This uses the follwing formula: 104 * This uses the following formula:
105 * SCPClkOut = OPBCLK/(4(CDM + 1)) 105 * SCPClkOut = OPBCLK/(4(CDM + 1))
106 * or 106 * or
107 * CDM = (OPBCLK/4*SCPClkOut) - 1 107 * CDM = (OPBCLK/4*SCPClkOut) - 1
@@ -201,7 +201,7 @@ static int spi_ppc4xx_setupxfer(struct spi_device *spi, struct spi_transfer *t)
201 return -EINVAL; 201 return -EINVAL;
202 } 202 }
203 203
204 /* Write new configration */ 204 /* Write new configuration */
205 out_8(&hw->regs->mode, cs->mode); 205 out_8(&hw->regs->mode, cs->mode);
206 206
207 /* Set the clock */ 207 /* Set the clock */
diff --git a/drivers/spi/spi-s3c24xx.c b/drivers/spi/spi-s3c24xx.c
index 8ee7d790ce49..a2a080b7f42b 100644
--- a/drivers/spi/spi-s3c24xx.c
+++ b/drivers/spi/spi-s3c24xx.c
@@ -611,6 +611,7 @@ static int __devinit s3c24xx_spi_probe(struct platform_device *pdev)
611 if (!pdata->set_cs) { 611 if (!pdata->set_cs) {
612 if (pdata->pin_cs < 0) { 612 if (pdata->pin_cs < 0) {
613 dev_err(&pdev->dev, "No chipselect pin\n"); 613 dev_err(&pdev->dev, "No chipselect pin\n");
614 err = -EINVAL;
614 goto err_register; 615 goto err_register;
615 } 616 }
616 617
diff --git a/drivers/spi/spi-s3c64xx.c b/drivers/spi/spi-s3c64xx.c
index 0e2a02228d5e..1a81c90a4a71 100644
--- a/drivers/spi/spi-s3c64xx.c
+++ b/drivers/spi/spi-s3c64xx.c
@@ -835,9 +835,7 @@ static struct s3c64xx_spi_csinfo *s3c64xx_get_slave_ctrldata(
835 return ERR_PTR(-EINVAL); 835 return ERR_PTR(-EINVAL);
836 } 836 }
837 837
838 for_each_child_of_node(slave_np, data_np) 838 data_np = of_get_child_by_name(slave_np, "controller-data");
839 if (!strcmp(data_np->name, "controller-data"))
840 break;
841 if (!data_np) { 839 if (!data_np) {
842 dev_err(&spi->dev, "child node 'controller-data' not found\n"); 840 dev_err(&spi->dev, "child node 'controller-data' not found\n");
843 return ERR_PTR(-EINVAL); 841 return ERR_PTR(-EINVAL);
@@ -847,6 +845,7 @@ static struct s3c64xx_spi_csinfo *s3c64xx_get_slave_ctrldata(
847 if (!cs) { 845 if (!cs) {
848 dev_err(&spi->dev, "could not allocate memory for controller" 846 dev_err(&spi->dev, "could not allocate memory for controller"
849 " data\n"); 847 " data\n");
848 of_node_put(data_np);
850 return ERR_PTR(-ENOMEM); 849 return ERR_PTR(-ENOMEM);
851 } 850 }
852 851
@@ -855,11 +854,13 @@ static struct s3c64xx_spi_csinfo *s3c64xx_get_slave_ctrldata(
855 dev_err(&spi->dev, "chip select gpio is not specified or " 854 dev_err(&spi->dev, "chip select gpio is not specified or "
856 "invalid\n"); 855 "invalid\n");
857 kfree(cs); 856 kfree(cs);
857 of_node_put(data_np);
858 return ERR_PTR(-EINVAL); 858 return ERR_PTR(-EINVAL);
859 } 859 }
860 860
861 of_property_read_u32(data_np, "samsung,spi-feedback-delay", &fb_delay); 861 of_property_read_u32(data_np, "samsung,spi-feedback-delay", &fb_delay);
862 cs->fb_delay = fb_delay; 862 cs->fb_delay = fb_delay;
863 of_node_put(data_np);
863 return cs; 864 return cs;
864} 865}
865 866
@@ -976,7 +977,8 @@ err_msgq:
976 spi_set_ctldata(spi, NULL); 977 spi_set_ctldata(spi, NULL);
977 978
978err_gpio_req: 979err_gpio_req:
979 kfree(cs); 980 if (spi->dev.of_node)
981 kfree(cs);
980 982
981 return err; 983 return err;
982} 984}
@@ -1409,7 +1411,7 @@ static int s3c64xx_spi_remove(struct platform_device *pdev)
1409#ifdef CONFIG_PM 1411#ifdef CONFIG_PM
1410static int s3c64xx_spi_suspend(struct device *dev) 1412static int s3c64xx_spi_suspend(struct device *dev)
1411{ 1413{
1412 struct spi_master *master = spi_master_get(dev_get_drvdata(dev)); 1414 struct spi_master *master = dev_get_drvdata(dev);
1413 struct s3c64xx_spi_driver_data *sdd = spi_master_get_devdata(master); 1415 struct s3c64xx_spi_driver_data *sdd = spi_master_get_devdata(master);
1414 1416
1415 spi_master_suspend(master); 1417 spi_master_suspend(master);
@@ -1428,7 +1430,7 @@ static int s3c64xx_spi_suspend(struct device *dev)
1428 1430
1429static int s3c64xx_spi_resume(struct device *dev) 1431static int s3c64xx_spi_resume(struct device *dev)
1430{ 1432{
1431 struct spi_master *master = spi_master_get(dev_get_drvdata(dev)); 1433 struct spi_master *master = dev_get_drvdata(dev);
1432 struct s3c64xx_spi_driver_data *sdd = spi_master_get_devdata(master); 1434 struct s3c64xx_spi_driver_data *sdd = spi_master_get_devdata(master);
1433 struct s3c64xx_spi_info *sci = sdd->cntrlr_info; 1435 struct s3c64xx_spi_info *sci = sdd->cntrlr_info;
1434 1436
@@ -1452,7 +1454,7 @@ static int s3c64xx_spi_resume(struct device *dev)
1452#ifdef CONFIG_PM_RUNTIME 1454#ifdef CONFIG_PM_RUNTIME
1453static int s3c64xx_spi_runtime_suspend(struct device *dev) 1455static int s3c64xx_spi_runtime_suspend(struct device *dev)
1454{ 1456{
1455 struct spi_master *master = spi_master_get(dev_get_drvdata(dev)); 1457 struct spi_master *master = dev_get_drvdata(dev);
1456 struct s3c64xx_spi_driver_data *sdd = spi_master_get_devdata(master); 1458 struct s3c64xx_spi_driver_data *sdd = spi_master_get_devdata(master);
1457 1459
1458 clk_disable(sdd->clk); 1460 clk_disable(sdd->clk);
@@ -1463,7 +1465,7 @@ static int s3c64xx_spi_runtime_suspend(struct device *dev)
1463 1465
1464static int s3c64xx_spi_runtime_resume(struct device *dev) 1466static int s3c64xx_spi_runtime_resume(struct device *dev)
1465{ 1467{
1466 struct spi_master *master = spi_master_get(dev_get_drvdata(dev)); 1468 struct spi_master *master = dev_get_drvdata(dev);
1467 struct s3c64xx_spi_driver_data *sdd = spi_master_get_devdata(master); 1469 struct s3c64xx_spi_driver_data *sdd = spi_master_get_devdata(master);
1468 1470
1469 clk_enable(sdd->src_clk); 1471 clk_enable(sdd->src_clk);
diff --git a/drivers/spi/spi-sc18is602.c b/drivers/spi/spi-sc18is602.c
new file mode 100644
index 000000000000..9eda21d739c6
--- /dev/null
+++ b/drivers/spi/spi-sc18is602.c
@@ -0,0 +1,364 @@
1/*
2 * NXP SC18IS602/603 SPI driver
3 *
4 * Copyright (C) Guenter Roeck <linux@roeck-us.net>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#include <linux/kernel.h>
22#include <linux/err.h>
23#include <linux/module.h>
24#include <linux/spi/spi.h>
25#include <linux/i2c.h>
26#include <linux/delay.h>
27#include <linux/pm_runtime.h>
28#include <linux/of.h>
29#include <linux/platform_data/sc18is602.h>
30
31enum chips { sc18is602, sc18is602b, sc18is603 };
32
33#define SC18IS602_BUFSIZ 200
34#define SC18IS602_CLOCK 7372000
35
36#define SC18IS602_MODE_CPHA BIT(2)
37#define SC18IS602_MODE_CPOL BIT(3)
38#define SC18IS602_MODE_LSB_FIRST BIT(5)
39#define SC18IS602_MODE_CLOCK_DIV_4 0x0
40#define SC18IS602_MODE_CLOCK_DIV_16 0x1
41#define SC18IS602_MODE_CLOCK_DIV_64 0x2
42#define SC18IS602_MODE_CLOCK_DIV_128 0x3
43
44struct sc18is602 {
45 struct spi_master *master;
46 struct device *dev;
47 u8 ctrl;
48 u32 freq;
49 u32 speed;
50
51 /* I2C data */
52 struct i2c_client *client;
53 enum chips id;
54 u8 buffer[SC18IS602_BUFSIZ + 1];
55 int tlen; /* Data queued for tx in buffer */
56 int rindex; /* Receive data index in buffer */
57};
58
59static int sc18is602_wait_ready(struct sc18is602 *hw, int len)
60{
61 int i, err;
62 int usecs = 1000000 * len / hw->speed + 1;
63 u8 dummy[1];
64
65 for (i = 0; i < 10; i++) {
66 err = i2c_master_recv(hw->client, dummy, 1);
67 if (err >= 0)
68 return 0;
69 usleep_range(usecs, usecs * 2);
70 }
71 return -ETIMEDOUT;
72}
73
74static int sc18is602_txrx(struct sc18is602 *hw, struct spi_message *msg,
75 struct spi_transfer *t, bool do_transfer)
76{
77 unsigned int len = t->len;
78 int ret;
79
80 if (hw->tlen == 0) {
81 /* First byte (I2C command) is chip select */
82 hw->buffer[0] = 1 << msg->spi->chip_select;
83 hw->tlen = 1;
84 hw->rindex = 0;
85 }
86 /*
87 * We can not immediately send data to the chip, since each I2C message
88 * resembles a full SPI message (from CS active to CS inactive).
89 * Enqueue messages up to the first read or until do_transfer is true.
90 */
91 if (t->tx_buf) {
92 memcpy(&hw->buffer[hw->tlen], t->tx_buf, len);
93 hw->tlen += len;
94 if (t->rx_buf)
95 do_transfer = true;
96 else
97 hw->rindex = hw->tlen - 1;
98 } else if (t->rx_buf) {
99 /*
100 * For receive-only transfers we still need to perform a dummy
101 * write to receive data from the SPI chip.
102 * Read data starts at the end of transmit data (minus 1 to
103 * account for CS).
104 */
105 hw->rindex = hw->tlen - 1;
106 memset(&hw->buffer[hw->tlen], 0, len);
107 hw->tlen += len;
108 do_transfer = true;
109 }
110
111 if (do_transfer && hw->tlen > 1) {
112 ret = sc18is602_wait_ready(hw, SC18IS602_BUFSIZ);
113 if (ret < 0)
114 return ret;
115 ret = i2c_master_send(hw->client, hw->buffer, hw->tlen);
116 if (ret < 0)
117 return ret;
118 if (ret != hw->tlen)
119 return -EIO;
120
121 if (t->rx_buf) {
122 int rlen = hw->rindex + len;
123
124 ret = sc18is602_wait_ready(hw, hw->tlen);
125 if (ret < 0)
126 return ret;
127 ret = i2c_master_recv(hw->client, hw->buffer, rlen);
128 if (ret < 0)
129 return ret;
130 if (ret != rlen)
131 return -EIO;
132 memcpy(t->rx_buf, &hw->buffer[hw->rindex], len);
133 }
134 hw->tlen = 0;
135 }
136 return len;
137}
138
139static int sc18is602_setup_transfer(struct sc18is602 *hw, u32 hz, u8 mode)
140{
141 u8 ctrl = 0;
142 int ret;
143
144 if (mode & SPI_CPHA)
145 ctrl |= SC18IS602_MODE_CPHA;
146 if (mode & SPI_CPOL)
147 ctrl |= SC18IS602_MODE_CPOL;
148 if (mode & SPI_LSB_FIRST)
149 ctrl |= SC18IS602_MODE_LSB_FIRST;
150
151 /* Find the closest clock speed */
152 if (hz >= hw->freq / 4) {
153 ctrl |= SC18IS602_MODE_CLOCK_DIV_4;
154 hw->speed = hw->freq / 4;
155 } else if (hz >= hw->freq / 16) {
156 ctrl |= SC18IS602_MODE_CLOCK_DIV_16;
157 hw->speed = hw->freq / 16;
158 } else if (hz >= hw->freq / 64) {
159 ctrl |= SC18IS602_MODE_CLOCK_DIV_64;
160 hw->speed = hw->freq / 64;
161 } else {
162 ctrl |= SC18IS602_MODE_CLOCK_DIV_128;
163 hw->speed = hw->freq / 128;
164 }
165
166 /*
167 * Don't do anything if the control value did not change. The initial
168 * value of 0xff for hw->ctrl ensures that the correct mode will be set
169 * with the first call to this function.
170 */
171 if (ctrl == hw->ctrl)
172 return 0;
173
174 ret = i2c_smbus_write_byte_data(hw->client, 0xf0, ctrl);
175 if (ret < 0)
176 return ret;
177
178 hw->ctrl = ctrl;
179
180 return 0;
181}
182
183static int sc18is602_check_transfer(struct spi_device *spi,
184 struct spi_transfer *t, int tlen)
185{
186 int bpw;
187 uint32_t hz;
188
189 if (t && t->len + tlen > SC18IS602_BUFSIZ)
190 return -EINVAL;
191
192 bpw = spi->bits_per_word;
193 if (t && t->bits_per_word)
194 bpw = t->bits_per_word;
195 if (bpw != 8)
196 return -EINVAL;
197
198 hz = spi->max_speed_hz;
199 if (t && t->speed_hz)
200 hz = t->speed_hz;
201 if (hz == 0)
202 return -EINVAL;
203
204 return 0;
205}
206
207static int sc18is602_transfer_one(struct spi_master *master,
208 struct spi_message *m)
209{
210 struct sc18is602 *hw = spi_master_get_devdata(master);
211 struct spi_device *spi = m->spi;
212 struct spi_transfer *t;
213 int status = 0;
214
215 /* SC18IS602 does not support CS2 */
216 if (hw->id == sc18is602 && spi->chip_select == 2) {
217 status = -ENXIO;
218 goto error;
219 }
220
221 hw->tlen = 0;
222 list_for_each_entry(t, &m->transfers, transfer_list) {
223 u32 hz = t->speed_hz ? : spi->max_speed_hz;
224 bool do_transfer;
225
226 status = sc18is602_check_transfer(spi, t, hw->tlen);
227 if (status < 0)
228 break;
229
230 status = sc18is602_setup_transfer(hw, hz, spi->mode);
231 if (status < 0)
232 break;
233
234 do_transfer = t->cs_change || list_is_last(&t->transfer_list,
235 &m->transfers);
236
237 if (t->len) {
238 status = sc18is602_txrx(hw, m, t, do_transfer);
239 if (status < 0)
240 break;
241 m->actual_length += status;
242 }
243 status = 0;
244
245 if (t->delay_usecs)
246 udelay(t->delay_usecs);
247 }
248error:
249 m->status = status;
250 spi_finalize_current_message(master);
251
252 return status;
253}
254
255static int sc18is602_setup(struct spi_device *spi)
256{
257 if (!spi->bits_per_word)
258 spi->bits_per_word = 8;
259
260 if (spi->mode & ~(SPI_CPHA | SPI_CPOL | SPI_LSB_FIRST))
261 return -EINVAL;
262
263 return sc18is602_check_transfer(spi, NULL, 0);
264}
265
266static int sc18is602_probe(struct i2c_client *client,
267 const struct i2c_device_id *id)
268{
269 struct device *dev = &client->dev;
270 struct device_node *np = dev->of_node;
271 struct sc18is602_platform_data *pdata = dev_get_platdata(dev);
272 struct sc18is602 *hw;
273 struct spi_master *master;
274 int error;
275
276 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C |
277 I2C_FUNC_SMBUS_WRITE_BYTE_DATA))
278 return -EINVAL;
279
280 master = spi_alloc_master(dev, sizeof(struct sc18is602));
281 if (!master)
282 return -ENOMEM;
283
284 hw = spi_master_get_devdata(master);
285 i2c_set_clientdata(client, hw);
286
287 hw->master = master;
288 hw->client = client;
289 hw->dev = dev;
290 hw->ctrl = 0xff;
291
292 hw->id = id->driver_data;
293
294 switch (hw->id) {
295 case sc18is602:
296 case sc18is602b:
297 master->num_chipselect = 4;
298 hw->freq = SC18IS602_CLOCK;
299 break;
300 case sc18is603:
301 master->num_chipselect = 2;
302 if (pdata) {
303 hw->freq = pdata->clock_frequency;
304 } else {
305 const __be32 *val;
306 int len;
307
308 val = of_get_property(np, "clock-frequency", &len);
309 if (val && len >= sizeof(__be32))
310 hw->freq = be32_to_cpup(val);
311 }
312 if (!hw->freq)
313 hw->freq = SC18IS602_CLOCK;
314 break;
315 }
316 master->bus_num = client->adapter->nr;
317 master->mode_bits = SPI_CPHA | SPI_CPOL | SPI_LSB_FIRST;
318 master->setup = sc18is602_setup;
319 master->transfer_one_message = sc18is602_transfer_one;
320 master->dev.of_node = np;
321
322 error = spi_register_master(master);
323 if (error)
324 goto error_reg;
325
326 return 0;
327
328error_reg:
329 spi_master_put(master);
330 return error;
331}
332
333static int sc18is602_remove(struct i2c_client *client)
334{
335 struct sc18is602 *hw = i2c_get_clientdata(client);
336 struct spi_master *master = hw->master;
337
338 spi_unregister_master(master);
339
340 return 0;
341}
342
343static const struct i2c_device_id sc18is602_id[] = {
344 { "sc18is602", sc18is602 },
345 { "sc18is602b", sc18is602b },
346 { "sc18is603", sc18is603 },
347 { }
348};
349MODULE_DEVICE_TABLE(i2c, sc18is602_id);
350
351static struct i2c_driver sc18is602_driver = {
352 .driver = {
353 .name = "sc18is602",
354 },
355 .probe = sc18is602_probe,
356 .remove = sc18is602_remove,
357 .id_table = sc18is602_id,
358};
359
360module_i2c_driver(sc18is602_driver);
361
362MODULE_DESCRIPTION("SC18IC602/603 SPI Master Driver");
363MODULE_AUTHOR("Guenter Roeck");
364MODULE_LICENSE("GPL");
diff --git a/drivers/spi/spi-sh-hspi.c b/drivers/spi/spi-sh-hspi.c
index 934138c7b3d3..796c077ef439 100644
--- a/drivers/spi/spi-sh-hspi.c
+++ b/drivers/spi/spi-sh-hspi.c
@@ -283,7 +283,7 @@ static int __devinit hspi_probe(struct platform_device *pdev)
283 ret = spi_register_master(master); 283 ret = spi_register_master(master);
284 if (ret < 0) { 284 if (ret < 0) {
285 dev_err(&pdev->dev, "spi_register_master error.\n"); 285 dev_err(&pdev->dev, "spi_register_master error.\n");
286 goto error2; 286 goto error1;
287 } 287 }
288 288
289 pm_runtime_enable(&pdev->dev); 289 pm_runtime_enable(&pdev->dev);
@@ -292,8 +292,6 @@ static int __devinit hspi_probe(struct platform_device *pdev)
292 292
293 return 0; 293 return 0;
294 294
295 error2:
296 devm_iounmap(hspi->dev, hspi->addr);
297 error1: 295 error1:
298 clk_put(clk); 296 clk_put(clk);
299 error0: 297 error0:
@@ -310,7 +308,6 @@ static int __devexit hspi_remove(struct platform_device *pdev)
310 308
311 clk_put(hspi->clk); 309 clk_put(hspi->clk);
312 spi_unregister_master(hspi->master); 310 spi_unregister_master(hspi->master);
313 devm_iounmap(hspi->dev, hspi->addr);
314 311
315 return 0; 312 return 0;
316} 313}
diff --git a/drivers/spi/spi-stmp.c b/drivers/spi/spi-stmp.c
index 58e385285323..911e904b3c84 100644
--- a/drivers/spi/spi-stmp.c
+++ b/drivers/spi/spi-stmp.c
@@ -594,9 +594,7 @@ static int __devexit stmp_spi_remove(struct platform_device *dev)
594 struct stmp_spi *ss; 594 struct stmp_spi *ss;
595 struct spi_master *master; 595 struct spi_master *master;
596 596
597 master = platform_get_drvdata(dev); 597 master = spi_master_get(platform_get_drvdata(dev));
598 if (master == NULL)
599 goto out0;
600 ss = spi_master_get_devdata(master); 598 ss = spi_master_get_devdata(master);
601 599
602 spi_unregister_master(master); 600 spi_unregister_master(master);
@@ -609,8 +607,6 @@ static int __devexit stmp_spi_remove(struct platform_device *dev)
609 destroy_workqueue(ss->workqueue); 607 destroy_workqueue(ss->workqueue);
610 iounmap(ss->regs); 608 iounmap(ss->regs);
611 spi_master_put(master); 609 spi_master_put(master);
612 platform_set_drvdata(dev, NULL);
613out0:
614 return 0; 610 return 0;
615} 611}
616 612
diff --git a/drivers/spi/spi-tegra.c b/drivers/spi/spi-tegra.c
deleted file mode 100644
index 488d9b6e9cbe..000000000000
--- a/drivers/spi/spi-tegra.c
+++ /dev/null
@@ -1,647 +0,0 @@
1/*
2 * Driver for Nvidia TEGRA spi controller.
3 *
4 * Copyright (C) 2010 Google, Inc.
5 *
6 * Author:
7 * Erik Gilling <konkers@android.com>
8 *
9 * This software is licensed under the terms of the GNU General Public
10 * License version 2, as published by the Free Software Foundation, and
11 * may be copied, distributed, and modified under those terms.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 */
19
20#include <linux/kernel.h>
21#include <linux/module.h>
22#include <linux/init.h>
23#include <linux/err.h>
24#include <linux/platform_device.h>
25#include <linux/io.h>
26#include <linux/dma-mapping.h>
27#include <linux/dmapool.h>
28#include <linux/clk.h>
29#include <linux/interrupt.h>
30#include <linux/delay.h>
31
32#include <linux/spi/spi.h>
33#include <linux/dmaengine.h>
34
35#include <mach/dma.h>
36
37#define SLINK_COMMAND 0x000
38#define SLINK_BIT_LENGTH(x) (((x) & 0x1f) << 0)
39#define SLINK_WORD_SIZE(x) (((x) & 0x1f) << 5)
40#define SLINK_BOTH_EN (1 << 10)
41#define SLINK_CS_SW (1 << 11)
42#define SLINK_CS_VALUE (1 << 12)
43#define SLINK_CS_POLARITY (1 << 13)
44#define SLINK_IDLE_SDA_DRIVE_LOW (0 << 16)
45#define SLINK_IDLE_SDA_DRIVE_HIGH (1 << 16)
46#define SLINK_IDLE_SDA_PULL_LOW (2 << 16)
47#define SLINK_IDLE_SDA_PULL_HIGH (3 << 16)
48#define SLINK_IDLE_SDA_MASK (3 << 16)
49#define SLINK_CS_POLARITY1 (1 << 20)
50#define SLINK_CK_SDA (1 << 21)
51#define SLINK_CS_POLARITY2 (1 << 22)
52#define SLINK_CS_POLARITY3 (1 << 23)
53#define SLINK_IDLE_SCLK_DRIVE_LOW (0 << 24)
54#define SLINK_IDLE_SCLK_DRIVE_HIGH (1 << 24)
55#define SLINK_IDLE_SCLK_PULL_LOW (2 << 24)
56#define SLINK_IDLE_SCLK_PULL_HIGH (3 << 24)
57#define SLINK_IDLE_SCLK_MASK (3 << 24)
58#define SLINK_M_S (1 << 28)
59#define SLINK_WAIT (1 << 29)
60#define SLINK_GO (1 << 30)
61#define SLINK_ENB (1 << 31)
62
63#define SLINK_COMMAND2 0x004
64#define SLINK_LSBFE (1 << 0)
65#define SLINK_SSOE (1 << 1)
66#define SLINK_SPIE (1 << 4)
67#define SLINK_BIDIROE (1 << 6)
68#define SLINK_MODFEN (1 << 7)
69#define SLINK_INT_SIZE(x) (((x) & 0x1f) << 8)
70#define SLINK_CS_ACTIVE_BETWEEN (1 << 17)
71#define SLINK_SS_EN_CS(x) (((x) & 0x3) << 18)
72#define SLINK_SS_SETUP(x) (((x) & 0x3) << 20)
73#define SLINK_FIFO_REFILLS_0 (0 << 22)
74#define SLINK_FIFO_REFILLS_1 (1 << 22)
75#define SLINK_FIFO_REFILLS_2 (2 << 22)
76#define SLINK_FIFO_REFILLS_3 (3 << 22)
77#define SLINK_FIFO_REFILLS_MASK (3 << 22)
78#define SLINK_WAIT_PACK_INT(x) (((x) & 0x7) << 26)
79#define SLINK_SPC0 (1 << 29)
80#define SLINK_TXEN (1 << 30)
81#define SLINK_RXEN (1 << 31)
82
83#define SLINK_STATUS 0x008
84#define SLINK_COUNT(val) (((val) >> 0) & 0x1f)
85#define SLINK_WORD(val) (((val) >> 5) & 0x1f)
86#define SLINK_BLK_CNT(val) (((val) >> 0) & 0xffff)
87#define SLINK_MODF (1 << 16)
88#define SLINK_RX_UNF (1 << 18)
89#define SLINK_TX_OVF (1 << 19)
90#define SLINK_TX_FULL (1 << 20)
91#define SLINK_TX_EMPTY (1 << 21)
92#define SLINK_RX_FULL (1 << 22)
93#define SLINK_RX_EMPTY (1 << 23)
94#define SLINK_TX_UNF (1 << 24)
95#define SLINK_RX_OVF (1 << 25)
96#define SLINK_TX_FLUSH (1 << 26)
97#define SLINK_RX_FLUSH (1 << 27)
98#define SLINK_SCLK (1 << 28)
99#define SLINK_ERR (1 << 29)
100#define SLINK_RDY (1 << 30)
101#define SLINK_BSY (1 << 31)
102
103#define SLINK_MAS_DATA 0x010
104#define SLINK_SLAVE_DATA 0x014
105
106#define SLINK_DMA_CTL 0x018
107#define SLINK_DMA_BLOCK_SIZE(x) (((x) & 0xffff) << 0)
108#define SLINK_TX_TRIG_1 (0 << 16)
109#define SLINK_TX_TRIG_4 (1 << 16)
110#define SLINK_TX_TRIG_8 (2 << 16)
111#define SLINK_TX_TRIG_16 (3 << 16)
112#define SLINK_TX_TRIG_MASK (3 << 16)
113#define SLINK_RX_TRIG_1 (0 << 18)
114#define SLINK_RX_TRIG_4 (1 << 18)
115#define SLINK_RX_TRIG_8 (2 << 18)
116#define SLINK_RX_TRIG_16 (3 << 18)
117#define SLINK_RX_TRIG_MASK (3 << 18)
118#define SLINK_PACKED (1 << 20)
119#define SLINK_PACK_SIZE_4 (0 << 21)
120#define SLINK_PACK_SIZE_8 (1 << 21)
121#define SLINK_PACK_SIZE_16 (2 << 21)
122#define SLINK_PACK_SIZE_32 (3 << 21)
123#define SLINK_PACK_SIZE_MASK (3 << 21)
124#define SLINK_IE_TXC (1 << 26)
125#define SLINK_IE_RXC (1 << 27)
126#define SLINK_DMA_EN (1 << 31)
127
128#define SLINK_STATUS2 0x01c
129#define SLINK_TX_FIFO_EMPTY_COUNT(val) (((val) & 0x3f) >> 0)
130#define SLINK_RX_FIFO_FULL_COUNT(val) (((val) & 0x3f) >> 16)
131
132#define SLINK_TX_FIFO 0x100
133#define SLINK_RX_FIFO 0x180
134
135static const unsigned long spi_tegra_req_sels[] = {
136 TEGRA_DMA_REQ_SEL_SL2B1,
137 TEGRA_DMA_REQ_SEL_SL2B2,
138 TEGRA_DMA_REQ_SEL_SL2B3,
139 TEGRA_DMA_REQ_SEL_SL2B4,
140};
141
142#define BB_LEN 32
143
144struct spi_tegra_data {
145 struct spi_master *master;
146 struct platform_device *pdev;
147 spinlock_t lock;
148
149 struct clk *clk;
150 void __iomem *base;
151 unsigned long phys;
152
153 u32 cur_speed;
154
155 struct list_head queue;
156 struct spi_transfer *cur;
157 unsigned cur_pos;
158 unsigned cur_len;
159 unsigned cur_bytes_per_word;
160
161 /* The tegra spi controller has a bug which causes the first word
162 * in PIO transactions to be garbage. Since packed DMA transactions
163 * require transfers to be 4 byte aligned we need a bounce buffer
164 * for the generic case.
165 */
166 int dma_req_len;
167 struct dma_chan *rx_dma;
168 struct dma_slave_config sconfig;
169 struct dma_async_tx_descriptor *rx_dma_desc;
170 dma_cookie_t rx_cookie;
171 u32 *rx_bb;
172 dma_addr_t rx_bb_phys;
173};
174
175static void tegra_spi_rx_dma_complete(void *args);
176static inline unsigned long spi_tegra_readl(struct spi_tegra_data *tspi,
177 unsigned long reg)
178{
179 return readl(tspi->base + reg);
180}
181
182static inline void spi_tegra_writel(struct spi_tegra_data *tspi,
183 unsigned long val,
184 unsigned long reg)
185{
186 writel(val, tspi->base + reg);
187}
188
189static void spi_tegra_go(struct spi_tegra_data *tspi)
190{
191 unsigned long val;
192
193 wmb();
194
195 val = spi_tegra_readl(tspi, SLINK_DMA_CTL);
196 val &= ~SLINK_DMA_BLOCK_SIZE(~0) & ~SLINK_DMA_EN;
197 val |= SLINK_DMA_BLOCK_SIZE(tspi->dma_req_len / 4 - 1);
198 spi_tegra_writel(tspi, val, SLINK_DMA_CTL);
199 tspi->rx_dma_desc = dmaengine_prep_slave_single(tspi->rx_dma,
200 tspi->rx_bb_phys, tspi->dma_req_len,
201 DMA_DEV_TO_MEM, DMA_PREP_INTERRUPT);
202 if (!tspi->rx_dma_desc) {
203 dev_err(&tspi->pdev->dev, "dmaengine slave prep failed\n");
204 return;
205 }
206 tspi->rx_dma_desc->callback = tegra_spi_rx_dma_complete;
207 tspi->rx_dma_desc->callback_param = tspi;
208 tspi->rx_cookie = dmaengine_submit(tspi->rx_dma_desc);
209 dma_async_issue_pending(tspi->rx_dma);
210
211 val |= SLINK_DMA_EN;
212 spi_tegra_writel(tspi, val, SLINK_DMA_CTL);
213}
214
215static unsigned spi_tegra_fill_tx_fifo(struct spi_tegra_data *tspi,
216 struct spi_transfer *t)
217{
218 unsigned len = min(t->len - tspi->cur_pos, BB_LEN *
219 tspi->cur_bytes_per_word);
220 u8 *tx_buf = (u8 *)t->tx_buf + tspi->cur_pos;
221 int i, j;
222 unsigned long val;
223
224 val = spi_tegra_readl(tspi, SLINK_COMMAND);
225 val &= ~SLINK_WORD_SIZE(~0);
226 val |= SLINK_WORD_SIZE(len / tspi->cur_bytes_per_word - 1);
227 spi_tegra_writel(tspi, val, SLINK_COMMAND);
228
229 for (i = 0; i < len; i += tspi->cur_bytes_per_word) {
230 val = 0;
231 for (j = 0; j < tspi->cur_bytes_per_word; j++)
232 val |= tx_buf[i + j] << j * 8;
233
234 spi_tegra_writel(tspi, val, SLINK_TX_FIFO);
235 }
236
237 tspi->dma_req_len = len / tspi->cur_bytes_per_word * 4;
238
239 return len;
240}
241
242static unsigned spi_tegra_drain_rx_fifo(struct spi_tegra_data *tspi,
243 struct spi_transfer *t)
244{
245 unsigned len = tspi->cur_len;
246 u8 *rx_buf = (u8 *)t->rx_buf + tspi->cur_pos;
247 int i, j;
248 unsigned long val;
249
250 for (i = 0; i < len; i += tspi->cur_bytes_per_word) {
251 val = tspi->rx_bb[i / tspi->cur_bytes_per_word];
252 for (j = 0; j < tspi->cur_bytes_per_word; j++)
253 rx_buf[i + j] = (val >> (j * 8)) & 0xff;
254 }
255
256 return len;
257}
258
259static void spi_tegra_start_transfer(struct spi_device *spi,
260 struct spi_transfer *t)
261{
262 struct spi_tegra_data *tspi = spi_master_get_devdata(spi->master);
263 u32 speed;
264 u8 bits_per_word;
265 unsigned long val;
266
267 speed = t->speed_hz ? t->speed_hz : spi->max_speed_hz;
268 bits_per_word = t->bits_per_word ? t->bits_per_word :
269 spi->bits_per_word;
270
271 tspi->cur_bytes_per_word = (bits_per_word - 1) / 8 + 1;
272
273 if (speed != tspi->cur_speed)
274 clk_set_rate(tspi->clk, speed);
275
276 if (tspi->cur_speed == 0)
277 clk_prepare_enable(tspi->clk);
278
279 tspi->cur_speed = speed;
280
281 val = spi_tegra_readl(tspi, SLINK_COMMAND2);
282 val &= ~SLINK_SS_EN_CS(~0) | SLINK_RXEN | SLINK_TXEN;
283 if (t->rx_buf)
284 val |= SLINK_RXEN;
285 if (t->tx_buf)
286 val |= SLINK_TXEN;
287 val |= SLINK_SS_EN_CS(spi->chip_select);
288 val |= SLINK_SPIE;
289 spi_tegra_writel(tspi, val, SLINK_COMMAND2);
290
291 val = spi_tegra_readl(tspi, SLINK_COMMAND);
292 val &= ~SLINK_BIT_LENGTH(~0);
293 val |= SLINK_BIT_LENGTH(bits_per_word - 1);
294
295 /* FIXME: should probably control CS manually so that we can be sure
296 * it does not go low between transfer and to support delay_usecs
297 * correctly.
298 */
299 val &= ~SLINK_IDLE_SCLK_MASK & ~SLINK_CK_SDA & ~SLINK_CS_SW;
300
301 if (spi->mode & SPI_CPHA)
302 val |= SLINK_CK_SDA;
303
304 if (spi->mode & SPI_CPOL)
305 val |= SLINK_IDLE_SCLK_DRIVE_HIGH;
306 else
307 val |= SLINK_IDLE_SCLK_DRIVE_LOW;
308
309 val |= SLINK_M_S;
310
311 spi_tegra_writel(tspi, val, SLINK_COMMAND);
312
313 spi_tegra_writel(tspi, SLINK_RX_FLUSH | SLINK_TX_FLUSH, SLINK_STATUS);
314
315 tspi->cur = t;
316 tspi->cur_pos = 0;
317 tspi->cur_len = spi_tegra_fill_tx_fifo(tspi, t);
318
319 spi_tegra_go(tspi);
320}
321
322static void spi_tegra_start_message(struct spi_device *spi,
323 struct spi_message *m)
324{
325 struct spi_transfer *t;
326
327 m->actual_length = 0;
328 m->status = 0;
329
330 t = list_first_entry(&m->transfers, struct spi_transfer, transfer_list);
331 spi_tegra_start_transfer(spi, t);
332}
333
334static void handle_spi_rx_dma_complete(struct spi_tegra_data *tspi)
335{
336 unsigned long flags;
337 struct spi_message *m;
338 struct spi_device *spi;
339 int timeout = 0;
340 unsigned long val;
341
342 /* the SPI controller may come back with both the BSY and RDY bits
343 * set. In this case we need to wait for the BSY bit to clear so
344 * that we are sure the DMA is finished. 1000 reads was empirically
345 * determined to be long enough.
346 */
347 while (timeout++ < 1000) {
348 if (!(spi_tegra_readl(tspi, SLINK_STATUS) & SLINK_BSY))
349 break;
350 }
351
352 spin_lock_irqsave(&tspi->lock, flags);
353
354 val = spi_tegra_readl(tspi, SLINK_STATUS);
355 val |= SLINK_RDY;
356 spi_tegra_writel(tspi, val, SLINK_STATUS);
357
358 m = list_first_entry(&tspi->queue, struct spi_message, queue);
359
360 if (timeout >= 1000)
361 m->status = -EIO;
362
363 spi = m->state;
364
365 tspi->cur_pos += spi_tegra_drain_rx_fifo(tspi, tspi->cur);
366 m->actual_length += tspi->cur_pos;
367
368 if (tspi->cur_pos < tspi->cur->len) {
369 tspi->cur_len = spi_tegra_fill_tx_fifo(tspi, tspi->cur);
370 spi_tegra_go(tspi);
371 } else if (!list_is_last(&tspi->cur->transfer_list,
372 &m->transfers)) {
373 tspi->cur = list_first_entry(&tspi->cur->transfer_list,
374 struct spi_transfer,
375 transfer_list);
376 spi_tegra_start_transfer(spi, tspi->cur);
377 } else {
378 list_del(&m->queue);
379
380 m->complete(m->context);
381
382 if (!list_empty(&tspi->queue)) {
383 m = list_first_entry(&tspi->queue, struct spi_message,
384 queue);
385 spi = m->state;
386 spi_tegra_start_message(spi, m);
387 } else {
388 clk_disable_unprepare(tspi->clk);
389 tspi->cur_speed = 0;
390 }
391 }
392
393 spin_unlock_irqrestore(&tspi->lock, flags);
394}
395
396static void tegra_spi_rx_dma_complete(void *args)
397{
398 struct spi_tegra_data *tspi = args;
399 handle_spi_rx_dma_complete(tspi);
400}
401
402static int spi_tegra_setup(struct spi_device *spi)
403{
404 struct spi_tegra_data *tspi = spi_master_get_devdata(spi->master);
405 unsigned long cs_bit;
406 unsigned long val;
407 unsigned long flags;
408
409 dev_dbg(&spi->dev, "setup %d bpw, %scpol, %scpha, %dHz\n",
410 spi->bits_per_word,
411 spi->mode & SPI_CPOL ? "" : "~",
412 spi->mode & SPI_CPHA ? "" : "~",
413 spi->max_speed_hz);
414
415
416 switch (spi->chip_select) {
417 case 0:
418 cs_bit = SLINK_CS_POLARITY;
419 break;
420
421 case 1:
422 cs_bit = SLINK_CS_POLARITY1;
423 break;
424
425 case 2:
426 cs_bit = SLINK_CS_POLARITY2;
427 break;
428
429 case 4:
430 cs_bit = SLINK_CS_POLARITY3;
431 break;
432
433 default:
434 return -EINVAL;
435 }
436
437 spin_lock_irqsave(&tspi->lock, flags);
438
439 val = spi_tegra_readl(tspi, SLINK_COMMAND);
440 if (spi->mode & SPI_CS_HIGH)
441 val |= cs_bit;
442 else
443 val &= ~cs_bit;
444 spi_tegra_writel(tspi, val, SLINK_COMMAND);
445
446 spin_unlock_irqrestore(&tspi->lock, flags);
447
448 return 0;
449}
450
451static int spi_tegra_transfer(struct spi_device *spi, struct spi_message *m)
452{
453 struct spi_tegra_data *tspi = spi_master_get_devdata(spi->master);
454 struct spi_transfer *t;
455 unsigned long flags;
456 int was_empty;
457
458 if (list_empty(&m->transfers) || !m->complete)
459 return -EINVAL;
460
461 list_for_each_entry(t, &m->transfers, transfer_list) {
462 if (t->bits_per_word < 0 || t->bits_per_word > 32)
463 return -EINVAL;
464
465 if (t->len == 0)
466 return -EINVAL;
467
468 if (!t->rx_buf && !t->tx_buf)
469 return -EINVAL;
470 }
471
472 m->state = spi;
473
474 spin_lock_irqsave(&tspi->lock, flags);
475 was_empty = list_empty(&tspi->queue);
476 list_add_tail(&m->queue, &tspi->queue);
477
478 if (was_empty)
479 spi_tegra_start_message(spi, m);
480
481 spin_unlock_irqrestore(&tspi->lock, flags);
482
483 return 0;
484}
485
486static int __devinit spi_tegra_probe(struct platform_device *pdev)
487{
488 struct spi_master *master;
489 struct spi_tegra_data *tspi;
490 struct resource *r;
491 int ret;
492 dma_cap_mask_t mask;
493
494 master = spi_alloc_master(&pdev->dev, sizeof *tspi);
495 if (master == NULL) {
496 dev_err(&pdev->dev, "master allocation failed\n");
497 return -ENOMEM;
498 }
499
500 /* the spi->mode bits understood by this driver: */
501 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
502
503 master->bus_num = pdev->id;
504
505 master->setup = spi_tegra_setup;
506 master->transfer = spi_tegra_transfer;
507 master->num_chipselect = 4;
508
509 dev_set_drvdata(&pdev->dev, master);
510 tspi = spi_master_get_devdata(master);
511 tspi->master = master;
512 tspi->pdev = pdev;
513 spin_lock_init(&tspi->lock);
514
515 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
516 if (r == NULL) {
517 ret = -ENODEV;
518 goto err0;
519 }
520
521 if (!request_mem_region(r->start, resource_size(r),
522 dev_name(&pdev->dev))) {
523 ret = -EBUSY;
524 goto err0;
525 }
526
527 tspi->phys = r->start;
528 tspi->base = ioremap(r->start, resource_size(r));
529 if (!tspi->base) {
530 dev_err(&pdev->dev, "can't ioremap iomem\n");
531 ret = -ENOMEM;
532 goto err1;
533 }
534
535 tspi->clk = clk_get(&pdev->dev, NULL);
536 if (IS_ERR(tspi->clk)) {
537 dev_err(&pdev->dev, "can not get clock\n");
538 ret = PTR_ERR(tspi->clk);
539 goto err2;
540 }
541
542 INIT_LIST_HEAD(&tspi->queue);
543
544 dma_cap_zero(mask);
545 dma_cap_set(DMA_SLAVE, mask);
546 tspi->rx_dma = dma_request_channel(mask, NULL, NULL);
547 if (!tspi->rx_dma) {
548 dev_err(&pdev->dev, "can not allocate rx dma channel\n");
549 ret = -ENODEV;
550 goto err3;
551 }
552
553 tspi->rx_bb = dma_alloc_coherent(&pdev->dev, sizeof(u32) * BB_LEN,
554 &tspi->rx_bb_phys, GFP_KERNEL);
555 if (!tspi->rx_bb) {
556 dev_err(&pdev->dev, "can not allocate rx bounce buffer\n");
557 ret = -ENOMEM;
558 goto err4;
559 }
560
561 /* Dmaengine Dma slave config */
562 tspi->sconfig.src_addr = tspi->phys + SLINK_RX_FIFO;
563 tspi->sconfig.dst_addr = tspi->phys + SLINK_RX_FIFO;
564 tspi->sconfig.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
565 tspi->sconfig.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
566 tspi->sconfig.slave_id = spi_tegra_req_sels[pdev->id];
567 tspi->sconfig.src_maxburst = 1;
568 tspi->sconfig.dst_maxburst = 1;
569 ret = dmaengine_device_control(tspi->rx_dma,
570 DMA_SLAVE_CONFIG, (unsigned long) &tspi->sconfig);
571 if (ret < 0) {
572 dev_err(&pdev->dev, "can not do slave configure for dma %d\n",
573 ret);
574 goto err4;
575 }
576
577 master->dev.of_node = pdev->dev.of_node;
578 ret = spi_register_master(master);
579
580 if (ret < 0)
581 goto err5;
582
583 return ret;
584
585err5:
586 dma_free_coherent(&pdev->dev, sizeof(u32) * BB_LEN,
587 tspi->rx_bb, tspi->rx_bb_phys);
588err4:
589 dma_release_channel(tspi->rx_dma);
590err3:
591 clk_put(tspi->clk);
592err2:
593 iounmap(tspi->base);
594err1:
595 release_mem_region(r->start, resource_size(r));
596err0:
597 spi_master_put(master);
598 return ret;
599}
600
601static int __devexit spi_tegra_remove(struct platform_device *pdev)
602{
603 struct spi_master *master;
604 struct spi_tegra_data *tspi;
605 struct resource *r;
606
607 master = dev_get_drvdata(&pdev->dev);
608 tspi = spi_master_get_devdata(master);
609
610 spi_unregister_master(master);
611 dma_release_channel(tspi->rx_dma);
612 dma_free_coherent(&pdev->dev, sizeof(u32) * BB_LEN,
613 tspi->rx_bb, tspi->rx_bb_phys);
614
615 clk_put(tspi->clk);
616 iounmap(tspi->base);
617
618 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
619 release_mem_region(r->start, resource_size(r));
620
621 return 0;
622}
623
624MODULE_ALIAS("platform:spi_tegra");
625
626#ifdef CONFIG_OF
627static struct of_device_id spi_tegra_of_match_table[] __devinitdata = {
628 { .compatible = "nvidia,tegra20-spi", },
629 {}
630};
631MODULE_DEVICE_TABLE(of, spi_tegra_of_match_table);
632#else /* CONFIG_OF */
633#define spi_tegra_of_match_table NULL
634#endif /* CONFIG_OF */
635
636static struct platform_driver spi_tegra_driver = {
637 .driver = {
638 .name = "spi_tegra",
639 .owner = THIS_MODULE,
640 .of_match_table = spi_tegra_of_match_table,
641 },
642 .probe = spi_tegra_probe,
643 .remove = __devexit_p(spi_tegra_remove),
644};
645module_platform_driver(spi_tegra_driver);
646
647MODULE_LICENSE("GPL");
diff --git a/drivers/spi/spi-tle62x0.c b/drivers/spi/spi-tle62x0.c
index 0ce5c12aab55..24421024deaf 100644
--- a/drivers/spi/spi-tle62x0.c
+++ b/drivers/spi/spi-tle62x0.c
@@ -316,18 +316,7 @@ static struct spi_driver tle62x0_driver = {
316 .remove = __devexit_p(tle62x0_remove), 316 .remove = __devexit_p(tle62x0_remove),
317}; 317};
318 318
319static __init int tle62x0_init(void) 319module_spi_driver(tle62x0_driver);
320{
321 return spi_register_driver(&tle62x0_driver);
322}
323
324static __exit void tle62x0_exit(void)
325{
326 spi_unregister_driver(&tle62x0_driver);
327}
328
329module_init(tle62x0_init);
330module_exit(tle62x0_exit);
331 320
332MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>"); 321MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
333MODULE_DESCRIPTION("TLE62x0 SPI driver"); 322MODULE_DESCRIPTION("TLE62x0 SPI driver");
diff --git a/drivers/spi/spi-topcliff-pch.c b/drivers/spi/spi-topcliff-pch.c
index cd56dcf46320..135f7406f4bf 100644
--- a/drivers/spi/spi-topcliff-pch.c
+++ b/drivers/spi/spi-topcliff-pch.c
@@ -505,7 +505,7 @@ static int pch_spi_transfer(struct spi_device *pspi, struct spi_message *pmsg)
505 } 505 }
506 506
507 if (unlikely(pspi->max_speed_hz == 0)) { 507 if (unlikely(pspi->max_speed_hz == 0)) {
508 dev_err(&pspi->dev, "%s pch_spi_tranfer maxspeed=%d\n", 508 dev_err(&pspi->dev, "%s pch_spi_transfer maxspeed=%d\n",
509 __func__, pspi->max_speed_hz); 509 __func__, pspi->max_speed_hz);
510 retval = -EINVAL; 510 retval = -EINVAL;
511 goto err_out; 511 goto err_out;
@@ -1536,8 +1536,6 @@ static int __devexit pch_spi_pd_remove(struct platform_device *plat_dev)
1536 1536
1537 pci_iounmap(board_dat->pdev, data->io_remap_addr); 1537 pci_iounmap(board_dat->pdev, data->io_remap_addr);
1538 spi_unregister_master(data->master); 1538 spi_unregister_master(data->master);
1539 spi_master_put(data->master);
1540 platform_set_drvdata(plat_dev, NULL);
1541 1539
1542 return 0; 1540 return 0;
1543} 1541}