diff options
Diffstat (limited to 'drivers/spi')
-rw-r--r-- | drivers/spi/Kconfig | 3 | ||||
-rw-r--r-- | drivers/spi/spi-dw-mmio.c | 2 | ||||
-rw-r--r-- | drivers/spi/spi-dw.c | 17 | ||||
-rw-r--r-- | drivers/spi/spi-efm32.c | 39 | ||||
-rw-r--r-- | drivers/spi/spi-ep93xx.c | 21 | ||||
-rw-r--r-- | drivers/spi/spi-fsl-dspi.c | 94 | ||||
-rw-r--r-- | drivers/spi/spi-fsl-espi.c | 5 | ||||
-rw-r--r-- | drivers/spi/spi-fsl-lib.c | 14 | ||||
-rw-r--r-- | drivers/spi/spi-fsl-spi.c | 30 | ||||
-rw-r--r-- | drivers/spi/spi-gpio.c | 2 | ||||
-rw-r--r-- | drivers/spi/spi-pl022.c | 5 | ||||
-rw-r--r-- | drivers/spi/spi-pxa2xx.c | 3 |
12 files changed, 111 insertions, 124 deletions
diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig index a79e89f63b71..eea4eb83f352 100644 --- a/drivers/spi/Kconfig +++ b/drivers/spi/Kconfig | |||
@@ -270,6 +270,7 @@ config SPI_FSL_SPI | |||
270 | config SPI_FSL_DSPI | 270 | config SPI_FSL_DSPI |
271 | tristate "Freescale DSPI controller" | 271 | tristate "Freescale DSPI controller" |
272 | select SPI_BITBANG | 272 | select SPI_BITBANG |
273 | select REGMAP_MMIO | ||
273 | depends on SOC_VF610 || COMPILE_TEST | 274 | depends on SOC_VF610 || COMPILE_TEST |
274 | help | 275 | help |
275 | This enables support for the Freescale DSPI controller in master | 276 | This enables support for the Freescale DSPI controller in master |
@@ -546,7 +547,7 @@ config SPI_DW_MID_DMA | |||
546 | 547 | ||
547 | config SPI_DW_MMIO | 548 | config SPI_DW_MMIO |
548 | tristate "Memory-mapped io interface driver for DW SPI core" | 549 | tristate "Memory-mapped io interface driver for DW SPI core" |
549 | depends on SPI_DESIGNWARE && HAVE_CLK | 550 | depends on SPI_DESIGNWARE |
550 | 551 | ||
551 | # | 552 | # |
552 | # There are lots of SPI device types, with sensors and memory | 553 | # There are lots of SPI device types, with sensors and memory |
diff --git a/drivers/spi/spi-dw-mmio.c b/drivers/spi/spi-dw-mmio.c index 9af56cdf1540..1492f5ee9aaa 100644 --- a/drivers/spi/spi-dw-mmio.c +++ b/drivers/spi/spi-dw-mmio.c | |||
@@ -66,7 +66,7 @@ static int dw_spi_mmio_probe(struct platform_device *pdev) | |||
66 | if (ret) | 66 | if (ret) |
67 | return ret; | 67 | return ret; |
68 | 68 | ||
69 | dws->bus_num = 0; | 69 | dws->bus_num = pdev->id; |
70 | dws->num_cs = 4; | 70 | dws->num_cs = 4; |
71 | dws->max_freq = clk_get_rate(dwsmmio->clk); | 71 | dws->max_freq = clk_get_rate(dwsmmio->clk); |
72 | 72 | ||
diff --git a/drivers/spi/spi-dw.c b/drivers/spi/spi-dw.c index bf98d63d92b3..712ac5629cd4 100644 --- a/drivers/spi/spi-dw.c +++ b/drivers/spi/spi-dw.c | |||
@@ -276,8 +276,7 @@ static void giveback(struct dw_spi *dws) | |||
276 | queue_work(dws->workqueue, &dws->pump_messages); | 276 | queue_work(dws->workqueue, &dws->pump_messages); |
277 | spin_unlock_irqrestore(&dws->lock, flags); | 277 | spin_unlock_irqrestore(&dws->lock, flags); |
278 | 278 | ||
279 | last_transfer = list_entry(msg->transfers.prev, | 279 | last_transfer = list_last_entry(&msg->transfers, struct spi_transfer, |
280 | struct spi_transfer, | ||
281 | transfer_list); | 280 | transfer_list); |
282 | 281 | ||
283 | if (!last_transfer->cs_change && dws->cs_control) | 282 | if (!last_transfer->cs_change && dws->cs_control) |
@@ -439,12 +438,6 @@ static void pump_transfers(unsigned long data) | |||
439 | 438 | ||
440 | if (transfer->speed_hz != speed) { | 439 | if (transfer->speed_hz != speed) { |
441 | speed = transfer->speed_hz; | 440 | speed = transfer->speed_hz; |
442 | if (speed > dws->max_freq) { | ||
443 | printk(KERN_ERR "MRST SPI0: unsupported" | ||
444 | "freq: %dHz\n", speed); | ||
445 | message->status = -EIO; | ||
446 | goto early_exit; | ||
447 | } | ||
448 | 441 | ||
449 | /* clk_div doesn't support odd number */ | 442 | /* clk_div doesn't support odd number */ |
450 | clk_div = dws->max_freq / speed; | 443 | clk_div = dws->max_freq / speed; |
@@ -671,12 +664,6 @@ static int dw_spi_setup(struct spi_device *spi) | |||
671 | return 0; | 664 | return 0; |
672 | } | 665 | } |
673 | 666 | ||
674 | static void dw_spi_cleanup(struct spi_device *spi) | ||
675 | { | ||
676 | struct chip_data *chip = spi_get_ctldata(spi); | ||
677 | kfree(chip); | ||
678 | } | ||
679 | |||
680 | static int init_queue(struct dw_spi *dws) | 667 | static int init_queue(struct dw_spi *dws) |
681 | { | 668 | { |
682 | INIT_LIST_HEAD(&dws->queue); | 669 | INIT_LIST_HEAD(&dws->queue); |
@@ -806,9 +793,9 @@ int dw_spi_add_host(struct device *dev, struct dw_spi *dws) | |||
806 | master->bits_per_word_mask = SPI_BPW_MASK(8) | SPI_BPW_MASK(16); | 793 | master->bits_per_word_mask = SPI_BPW_MASK(8) | SPI_BPW_MASK(16); |
807 | master->bus_num = dws->bus_num; | 794 | master->bus_num = dws->bus_num; |
808 | master->num_chipselect = dws->num_cs; | 795 | master->num_chipselect = dws->num_cs; |
809 | master->cleanup = dw_spi_cleanup; | ||
810 | master->setup = dw_spi_setup; | 796 | master->setup = dw_spi_setup; |
811 | master->transfer = dw_spi_transfer; | 797 | master->transfer = dw_spi_transfer; |
798 | master->max_speed_hz = dws->max_freq; | ||
812 | 799 | ||
813 | /* Basic HW init */ | 800 | /* Basic HW init */ |
814 | spi_hw_init(dws); | 801 | spi_hw_init(dws); |
diff --git a/drivers/spi/spi-efm32.c b/drivers/spi/spi-efm32.c index f53bbea385c0..be44a3eeb5e8 100644 --- a/drivers/spi/spi-efm32.c +++ b/drivers/spi/spi-efm32.c | |||
@@ -287,17 +287,17 @@ static u32 efm32_spi_get_configured_location(struct efm32_spi_ddata *ddata) | |||
287 | return (reg & REG_ROUTE_LOCATION__MASK) >> __ffs(REG_ROUTE_LOCATION__MASK); | 287 | return (reg & REG_ROUTE_LOCATION__MASK) >> __ffs(REG_ROUTE_LOCATION__MASK); |
288 | } | 288 | } |
289 | 289 | ||
290 | static int efm32_spi_probe_dt(struct platform_device *pdev, | 290 | static void efm32_spi_probe_dt(struct platform_device *pdev, |
291 | struct spi_master *master, struct efm32_spi_ddata *ddata) | 291 | struct spi_master *master, struct efm32_spi_ddata *ddata) |
292 | { | 292 | { |
293 | struct device_node *np = pdev->dev.of_node; | 293 | struct device_node *np = pdev->dev.of_node; |
294 | u32 location; | 294 | u32 location; |
295 | int ret; | 295 | int ret; |
296 | 296 | ||
297 | if (!np) | 297 | ret = of_property_read_u32(np, "efm32,location", &location); |
298 | return 1; | 298 | if (ret) |
299 | 299 | /* fall back to old and (wrongly) generic property "location" */ | |
300 | ret = of_property_read_u32(np, "location", &location); | 300 | ret = of_property_read_u32(np, "location", &location); |
301 | if (!ret) { | 301 | if (!ret) { |
302 | dev_dbg(&pdev->dev, "using location %u\n", location); | 302 | dev_dbg(&pdev->dev, "using location %u\n", location); |
303 | } else { | 303 | } else { |
@@ -308,7 +308,6 @@ static int efm32_spi_probe_dt(struct platform_device *pdev, | |||
308 | } | 308 | } |
309 | 309 | ||
310 | ddata->pdata.location = location; | 310 | ddata->pdata.location = location; |
311 | return 0; | ||
312 | } | 311 | } |
313 | 312 | ||
314 | static int efm32_spi_probe(struct platform_device *pdev) | 313 | static int efm32_spi_probe(struct platform_device *pdev) |
@@ -318,9 +317,14 @@ static int efm32_spi_probe(struct platform_device *pdev) | |||
318 | int ret; | 317 | int ret; |
319 | struct spi_master *master; | 318 | struct spi_master *master; |
320 | struct device_node *np = pdev->dev.of_node; | 319 | struct device_node *np = pdev->dev.of_node; |
321 | unsigned int num_cs, i; | 320 | int num_cs, i; |
321 | |||
322 | if (!np) | ||
323 | return -EINVAL; | ||
322 | 324 | ||
323 | num_cs = of_gpio_named_count(np, "cs-gpios"); | 325 | num_cs = of_gpio_named_count(np, "cs-gpios"); |
326 | if (num_cs < 0) | ||
327 | return num_cs; | ||
324 | 328 | ||
325 | master = spi_alloc_master(&pdev->dev, | 329 | master = spi_alloc_master(&pdev->dev, |
326 | sizeof(*ddata) + num_cs * sizeof(unsigned)); | 330 | sizeof(*ddata) + num_cs * sizeof(unsigned)); |
@@ -412,23 +416,7 @@ static int efm32_spi_probe(struct platform_device *pdev) | |||
412 | goto err; | 416 | goto err; |
413 | } | 417 | } |
414 | 418 | ||
415 | ret = efm32_spi_probe_dt(pdev, master, ddata); | 419 | efm32_spi_probe_dt(pdev, master, ddata); |
416 | if (ret > 0) { | ||
417 | /* not created by device tree */ | ||
418 | const struct efm32_spi_pdata *pdata = | ||
419 | dev_get_platdata(&pdev->dev); | ||
420 | |||
421 | if (pdata) | ||
422 | ddata->pdata = *pdata; | ||
423 | else | ||
424 | ddata->pdata.location = | ||
425 | efm32_spi_get_configured_location(ddata); | ||
426 | |||
427 | master->bus_num = pdev->id; | ||
428 | |||
429 | } else if (ret < 0) { | ||
430 | goto err_disable_clk; | ||
431 | } | ||
432 | 420 | ||
433 | efm32_spi_write32(ddata, 0, REG_IEN); | 421 | efm32_spi_write32(ddata, 0, REG_IEN); |
434 | efm32_spi_write32(ddata, REG_ROUTE_TXPEN | REG_ROUTE_RXPEN | | 422 | efm32_spi_write32(ddata, REG_ROUTE_TXPEN | REG_ROUTE_RXPEN | |
@@ -484,6 +472,9 @@ static int efm32_spi_remove(struct platform_device *pdev) | |||
484 | 472 | ||
485 | static const struct of_device_id efm32_spi_dt_ids[] = { | 473 | static const struct of_device_id efm32_spi_dt_ids[] = { |
486 | { | 474 | { |
475 | .compatible = "energymicro,efm32-spi", | ||
476 | }, { | ||
477 | /* doesn't follow the "vendor,device" scheme, don't use */ | ||
487 | .compatible = "efm32,spi", | 478 | .compatible = "efm32,spi", |
488 | }, { | 479 | }, { |
489 | /* sentinel */ | 480 | /* sentinel */ |
diff --git a/drivers/spi/spi-ep93xx.c b/drivers/spi/spi-ep93xx.c index 1bfaed6e4073..2f675d32df0e 100644 --- a/drivers/spi/spi-ep93xx.c +++ b/drivers/spi/spi-ep93xx.c | |||
@@ -73,8 +73,6 @@ | |||
73 | * @clk: clock for the controller | 73 | * @clk: clock for the controller |
74 | * @regs_base: pointer to ioremap()'d registers | 74 | * @regs_base: pointer to ioremap()'d registers |
75 | * @sspdr_phys: physical address of the SSPDR register | 75 | * @sspdr_phys: physical address of the SSPDR register |
76 | * @min_rate: minimum clock rate (in Hz) supported by the controller | ||
77 | * @max_rate: maximum clock rate (in Hz) supported by the controller | ||
78 | * @wait: wait here until given transfer is completed | 76 | * @wait: wait here until given transfer is completed |
79 | * @current_msg: message that is currently processed (or %NULL if none) | 77 | * @current_msg: message that is currently processed (or %NULL if none) |
80 | * @tx: current byte in transfer to transmit | 78 | * @tx: current byte in transfer to transmit |
@@ -95,8 +93,6 @@ struct ep93xx_spi { | |||
95 | struct clk *clk; | 93 | struct clk *clk; |
96 | void __iomem *regs_base; | 94 | void __iomem *regs_base; |
97 | unsigned long sspdr_phys; | 95 | unsigned long sspdr_phys; |
98 | unsigned long min_rate; | ||
99 | unsigned long max_rate; | ||
100 | struct completion wait; | 96 | struct completion wait; |
101 | struct spi_message *current_msg; | 97 | struct spi_message *current_msg; |
102 | size_t tx; | 98 | size_t tx; |
@@ -199,9 +195,9 @@ static void ep93xx_spi_disable_interrupts(const struct ep93xx_spi *espi) | |||
199 | * @div_scr: pointer to return the scr divider | 195 | * @div_scr: pointer to return the scr divider |
200 | */ | 196 | */ |
201 | static int ep93xx_spi_calc_divisors(const struct ep93xx_spi *espi, | 197 | static int ep93xx_spi_calc_divisors(const struct ep93xx_spi *espi, |
202 | unsigned long rate, | 198 | u32 rate, u8 *div_cpsr, u8 *div_scr) |
203 | u8 *div_cpsr, u8 *div_scr) | ||
204 | { | 199 | { |
200 | struct spi_master *master = platform_get_drvdata(espi->pdev); | ||
205 | unsigned long spi_clk_rate = clk_get_rate(espi->clk); | 201 | unsigned long spi_clk_rate = clk_get_rate(espi->clk); |
206 | int cpsr, scr; | 202 | int cpsr, scr; |
207 | 203 | ||
@@ -210,7 +206,7 @@ static int ep93xx_spi_calc_divisors(const struct ep93xx_spi *espi, | |||
210 | * controller. Note that minimum value is already checked in | 206 | * controller. Note that minimum value is already checked in |
211 | * ep93xx_spi_transfer_one_message(). | 207 | * ep93xx_spi_transfer_one_message(). |
212 | */ | 208 | */ |
213 | rate = clamp(rate, espi->min_rate, espi->max_rate); | 209 | rate = clamp(rate, master->min_speed_hz, master->max_speed_hz); |
214 | 210 | ||
215 | /* | 211 | /* |
216 | * Calculate divisors so that we can get speed according the | 212 | * Calculate divisors so that we can get speed according the |
@@ -735,13 +731,6 @@ static int ep93xx_spi_transfer_one_message(struct spi_master *master, | |||
735 | struct spi_message *msg) | 731 | struct spi_message *msg) |
736 | { | 732 | { |
737 | struct ep93xx_spi *espi = spi_master_get_devdata(master); | 733 | struct ep93xx_spi *espi = spi_master_get_devdata(master); |
738 | struct spi_transfer *t; | ||
739 | |||
740 | /* first validate each transfer */ | ||
741 | list_for_each_entry(t, &msg->transfers, transfer_list) { | ||
742 | if (t->speed_hz < espi->min_rate) | ||
743 | return -EINVAL; | ||
744 | } | ||
745 | 734 | ||
746 | msg->state = NULL; | 735 | msg->state = NULL; |
747 | msg->status = 0; | 736 | msg->status = 0; |
@@ -917,8 +906,8 @@ static int ep93xx_spi_probe(struct platform_device *pdev) | |||
917 | * Calculate maximum and minimum supported clock rates | 906 | * Calculate maximum and minimum supported clock rates |
918 | * for the controller. | 907 | * for the controller. |
919 | */ | 908 | */ |
920 | espi->max_rate = clk_get_rate(espi->clk) / 2; | 909 | master->max_speed_hz = clk_get_rate(espi->clk) / 2; |
921 | espi->min_rate = clk_get_rate(espi->clk) / (254 * 256); | 910 | master->min_speed_hz = clk_get_rate(espi->clk) / (254 * 256); |
922 | espi->pdev = pdev; | 911 | espi->pdev = pdev; |
923 | 912 | ||
924 | espi->sspdr_phys = res->start + SSPDR; | 913 | espi->sspdr_phys = res->start + SSPDR; |
diff --git a/drivers/spi/spi-fsl-dspi.c b/drivers/spi/spi-fsl-dspi.c index a25392065d9b..d565eeee3bd8 100644 --- a/drivers/spi/spi-fsl-dspi.c +++ b/drivers/spi/spi-fsl-dspi.c | |||
@@ -18,6 +18,7 @@ | |||
18 | #include <linux/interrupt.h> | 18 | #include <linux/interrupt.h> |
19 | #include <linux/errno.h> | 19 | #include <linux/errno.h> |
20 | #include <linux/platform_device.h> | 20 | #include <linux/platform_device.h> |
21 | #include <linux/regmap.h> | ||
21 | #include <linux/sched.h> | 22 | #include <linux/sched.h> |
22 | #include <linux/delay.h> | 23 | #include <linux/delay.h> |
23 | #include <linux/io.h> | 24 | #include <linux/io.h> |
@@ -108,11 +109,11 @@ struct fsl_dspi { | |||
108 | struct spi_bitbang bitbang; | 109 | struct spi_bitbang bitbang; |
109 | struct platform_device *pdev; | 110 | struct platform_device *pdev; |
110 | 111 | ||
111 | void __iomem *base; | 112 | struct regmap *regmap; |
112 | int irq; | 113 | int irq; |
113 | struct clk *clk; | 114 | struct clk *clk; |
114 | 115 | ||
115 | struct spi_transfer *cur_transfer; | 116 | struct spi_transfer *cur_transfer; |
116 | struct chip_data *cur_chip; | 117 | struct chip_data *cur_chip; |
117 | size_t len; | 118 | size_t len; |
118 | void *tx; | 119 | void *tx; |
@@ -123,24 +124,17 @@ struct fsl_dspi { | |||
123 | u8 cs; | 124 | u8 cs; |
124 | u16 void_write_data; | 125 | u16 void_write_data; |
125 | 126 | ||
126 | wait_queue_head_t waitq; | 127 | wait_queue_head_t waitq; |
127 | u32 waitflags; | 128 | u32 waitflags; |
128 | }; | 129 | }; |
129 | 130 | ||
130 | static inline int is_double_byte_mode(struct fsl_dspi *dspi) | 131 | static inline int is_double_byte_mode(struct fsl_dspi *dspi) |
131 | { | 132 | { |
132 | return ((readl(dspi->base + SPI_CTAR(dspi->cs)) & SPI_FRAME_BITS_MASK) | 133 | unsigned int val; |
133 | == SPI_FRAME_BITS(8)) ? 0 : 1; | ||
134 | } | ||
135 | 134 | ||
136 | static void set_bit_mode(struct fsl_dspi *dspi, unsigned char bits) | 135 | regmap_read(dspi->regmap, SPI_CTAR(dspi->cs), &val); |
137 | { | ||
138 | u32 temp; | ||
139 | 136 | ||
140 | temp = readl(dspi->base + SPI_CTAR(dspi->cs)); | 137 | return ((val & SPI_FRAME_BITS_MASK) == SPI_FRAME_BITS(8)) ? 0 : 1; |
141 | temp &= ~SPI_FRAME_BITS_MASK; | ||
142 | temp |= SPI_FRAME_BITS(bits); | ||
143 | writel(temp, dspi->base + SPI_CTAR(dspi->cs)); | ||
144 | } | 138 | } |
145 | 139 | ||
146 | static void hz_to_spi_baud(char *pbr, char *br, int speed_hz, | 140 | static void hz_to_spi_baud(char *pbr, char *br, int speed_hz, |
@@ -188,7 +182,8 @@ static int dspi_transfer_write(struct fsl_dspi *dspi) | |||
188 | */ | 182 | */ |
189 | if (tx_word && (dspi->len == 1)) { | 183 | if (tx_word && (dspi->len == 1)) { |
190 | dspi->dataflags |= TRAN_STATE_WORD_ODD_NUM; | 184 | dspi->dataflags |= TRAN_STATE_WORD_ODD_NUM; |
191 | set_bit_mode(dspi, 8); | 185 | regmap_update_bits(dspi->regmap, SPI_CTAR(dspi->cs), |
186 | SPI_FRAME_BITS_MASK, SPI_FRAME_BITS(8)); | ||
192 | tx_word = 0; | 187 | tx_word = 0; |
193 | } | 188 | } |
194 | 189 | ||
@@ -238,7 +233,8 @@ static int dspi_transfer_write(struct fsl_dspi *dspi) | |||
238 | dspi_pushr |= SPI_PUSHR_CTCNT; /* clear counter */ | 233 | dspi_pushr |= SPI_PUSHR_CTCNT; /* clear counter */ |
239 | } | 234 | } |
240 | 235 | ||
241 | writel(dspi_pushr, dspi->base + SPI_PUSHR); | 236 | regmap_write(dspi->regmap, SPI_PUSHR, dspi_pushr); |
237 | |||
242 | tx_count++; | 238 | tx_count++; |
243 | } | 239 | } |
244 | 240 | ||
@@ -253,17 +249,23 @@ static int dspi_transfer_read(struct fsl_dspi *dspi) | |||
253 | while ((dspi->rx < dspi->rx_end) | 249 | while ((dspi->rx < dspi->rx_end) |
254 | && (rx_count < DSPI_FIFO_SIZE)) { | 250 | && (rx_count < DSPI_FIFO_SIZE)) { |
255 | if (rx_word) { | 251 | if (rx_word) { |
252 | unsigned int val; | ||
253 | |||
256 | if ((dspi->rx_end - dspi->rx) == 1) | 254 | if ((dspi->rx_end - dspi->rx) == 1) |
257 | break; | 255 | break; |
258 | 256 | ||
259 | d = SPI_POPR_RXDATA(readl(dspi->base + SPI_POPR)); | 257 | regmap_read(dspi->regmap, SPI_POPR, &val); |
258 | d = SPI_POPR_RXDATA(val); | ||
260 | 259 | ||
261 | if (!(dspi->dataflags & TRAN_STATE_RX_VOID)) | 260 | if (!(dspi->dataflags & TRAN_STATE_RX_VOID)) |
262 | *(u16 *)dspi->rx = d; | 261 | *(u16 *)dspi->rx = d; |
263 | dspi->rx += 2; | 262 | dspi->rx += 2; |
264 | 263 | ||
265 | } else { | 264 | } else { |
266 | d = SPI_POPR_RXDATA(readl(dspi->base + SPI_POPR)); | 265 | unsigned int val; |
266 | |||
267 | regmap_read(dspi->regmap, SPI_POPR, &val); | ||
268 | d = SPI_POPR_RXDATA(val); | ||
267 | if (!(dspi->dataflags & TRAN_STATE_RX_VOID)) | 269 | if (!(dspi->dataflags & TRAN_STATE_RX_VOID)) |
268 | *(u8 *)dspi->rx = d; | 270 | *(u8 *)dspi->rx = d; |
269 | dspi->rx++; | 271 | dspi->rx++; |
@@ -295,13 +297,13 @@ static int dspi_txrx_transfer(struct spi_device *spi, struct spi_transfer *t) | |||
295 | if (!dspi->tx) | 297 | if (!dspi->tx) |
296 | dspi->dataflags |= TRAN_STATE_TX_VOID; | 298 | dspi->dataflags |= TRAN_STATE_TX_VOID; |
297 | 299 | ||
298 | writel(dspi->cur_chip->mcr_val, dspi->base + SPI_MCR); | 300 | regmap_write(dspi->regmap, SPI_MCR, dspi->cur_chip->mcr_val); |
299 | writel(dspi->cur_chip->ctar_val, dspi->base + SPI_CTAR(dspi->cs)); | 301 | regmap_write(dspi->regmap, SPI_CTAR(dspi->cs), dspi->cur_chip->ctar_val); |
300 | writel(SPI_RSER_EOQFE, dspi->base + SPI_RSER); | 302 | regmap_write(dspi->regmap, SPI_RSER, SPI_RSER_EOQFE); |
301 | 303 | ||
302 | if (t->speed_hz) | 304 | if (t->speed_hz) |
303 | writel(dspi->cur_chip->ctar_val, | 305 | regmap_write(dspi->regmap, SPI_CTAR(dspi->cs), |
304 | dspi->base + SPI_CTAR(dspi->cs)); | 306 | dspi->cur_chip->ctar_val); |
305 | 307 | ||
306 | dspi_transfer_write(dspi); | 308 | dspi_transfer_write(dspi); |
307 | 309 | ||
@@ -315,7 +317,9 @@ static int dspi_txrx_transfer(struct spi_device *spi, struct spi_transfer *t) | |||
315 | static void dspi_chipselect(struct spi_device *spi, int value) | 317 | static void dspi_chipselect(struct spi_device *spi, int value) |
316 | { | 318 | { |
317 | struct fsl_dspi *dspi = spi_master_get_devdata(spi->master); | 319 | struct fsl_dspi *dspi = spi_master_get_devdata(spi->master); |
318 | u32 pushr = readl(dspi->base + SPI_PUSHR); | 320 | unsigned int pushr; |
321 | |||
322 | regmap_read(dspi->regmap, SPI_PUSHR, &pushr); | ||
319 | 323 | ||
320 | switch (value) { | 324 | switch (value) { |
321 | case BITBANG_CS_ACTIVE: | 325 | case BITBANG_CS_ACTIVE: |
@@ -326,7 +330,7 @@ static void dspi_chipselect(struct spi_device *spi, int value) | |||
326 | break; | 330 | break; |
327 | } | 331 | } |
328 | 332 | ||
329 | writel(pushr, dspi->base + SPI_PUSHR); | 333 | regmap_write(dspi->regmap, SPI_PUSHR, pushr); |
330 | } | 334 | } |
331 | 335 | ||
332 | static int dspi_setup_transfer(struct spi_device *spi, struct spi_transfer *t) | 336 | static int dspi_setup_transfer(struct spi_device *spi, struct spi_transfer *t) |
@@ -338,7 +342,8 @@ static int dspi_setup_transfer(struct spi_device *spi, struct spi_transfer *t) | |||
338 | /* Only alloc on first setup */ | 342 | /* Only alloc on first setup */ |
339 | chip = spi_get_ctldata(spi); | 343 | chip = spi_get_ctldata(spi); |
340 | if (chip == NULL) { | 344 | if (chip == NULL) { |
341 | chip = kcalloc(1, sizeof(struct chip_data), GFP_KERNEL); | 345 | chip = devm_kzalloc(&spi->dev, sizeof(struct chip_data), |
346 | GFP_KERNEL); | ||
342 | if (!chip) | 347 | if (!chip) |
343 | return -ENOMEM; | 348 | return -ENOMEM; |
344 | } | 349 | } |
@@ -349,7 +354,6 @@ static int dspi_setup_transfer(struct spi_device *spi, struct spi_transfer *t) | |||
349 | fmsz = spi->bits_per_word - 1; | 354 | fmsz = spi->bits_per_word - 1; |
350 | } else { | 355 | } else { |
351 | pr_err("Invalid wordsize\n"); | 356 | pr_err("Invalid wordsize\n"); |
352 | kfree(chip); | ||
353 | return -ENODEV; | 357 | return -ENODEV; |
354 | } | 358 | } |
355 | 359 | ||
@@ -382,13 +386,15 @@ static irqreturn_t dspi_interrupt(int irq, void *dev_id) | |||
382 | { | 386 | { |
383 | struct fsl_dspi *dspi = (struct fsl_dspi *)dev_id; | 387 | struct fsl_dspi *dspi = (struct fsl_dspi *)dev_id; |
384 | 388 | ||
385 | writel(SPI_SR_EOQF, dspi->base + SPI_SR); | 389 | regmap_write(dspi->regmap, SPI_SR, SPI_SR_EOQF); |
386 | 390 | ||
387 | dspi_transfer_read(dspi); | 391 | dspi_transfer_read(dspi); |
388 | 392 | ||
389 | if (!dspi->len) { | 393 | if (!dspi->len) { |
390 | if (dspi->dataflags & TRAN_STATE_WORD_ODD_NUM) | 394 | if (dspi->dataflags & TRAN_STATE_WORD_ODD_NUM) |
391 | set_bit_mode(dspi, 16); | 395 | regmap_update_bits(dspi->regmap, SPI_CTAR(dspi->cs), |
396 | SPI_FRAME_BITS_MASK, SPI_FRAME_BITS(16)); | ||
397 | |||
392 | dspi->waitflags = 1; | 398 | dspi->waitflags = 1; |
393 | wake_up_interruptible(&dspi->waitq); | 399 | wake_up_interruptible(&dspi->waitq); |
394 | } else { | 400 | } else { |
@@ -430,8 +436,13 @@ static int dspi_resume(struct device *dev) | |||
430 | } | 436 | } |
431 | #endif /* CONFIG_PM_SLEEP */ | 437 | #endif /* CONFIG_PM_SLEEP */ |
432 | 438 | ||
433 | static const struct dev_pm_ops dspi_pm = { | 439 | static SIMPLE_DEV_PM_OPS(dspi_pm, dspi_suspend, dspi_resume); |
434 | SET_SYSTEM_SLEEP_PM_OPS(dspi_suspend, dspi_resume) | 440 | |
441 | static struct regmap_config dspi_regmap_config = { | ||
442 | .reg_bits = 32, | ||
443 | .val_bits = 32, | ||
444 | .reg_stride = 4, | ||
445 | .max_register = 0x88, | ||
435 | }; | 446 | }; |
436 | 447 | ||
437 | static int dspi_probe(struct platform_device *pdev) | 448 | static int dspi_probe(struct platform_device *pdev) |
@@ -440,6 +451,7 @@ static int dspi_probe(struct platform_device *pdev) | |||
440 | struct spi_master *master; | 451 | struct spi_master *master; |
441 | struct fsl_dspi *dspi; | 452 | struct fsl_dspi *dspi; |
442 | struct resource *res; | 453 | struct resource *res; |
454 | void __iomem *base; | ||
443 | int ret = 0, cs_num, bus_num; | 455 | int ret = 0, cs_num, bus_num; |
444 | 456 | ||
445 | master = spi_alloc_master(&pdev->dev, sizeof(struct fsl_dspi)); | 457 | master = spi_alloc_master(&pdev->dev, sizeof(struct fsl_dspi)); |
@@ -474,12 +486,24 @@ static int dspi_probe(struct platform_device *pdev) | |||
474 | master->bus_num = bus_num; | 486 | master->bus_num = bus_num; |
475 | 487 | ||
476 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 488 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
477 | dspi->base = devm_ioremap_resource(&pdev->dev, res); | 489 | base = devm_ioremap_resource(&pdev->dev, res); |
478 | if (IS_ERR(dspi->base)) { | 490 | if (IS_ERR(base)) { |
479 | ret = PTR_ERR(dspi->base); | 491 | ret = PTR_ERR(base); |
480 | goto out_master_put; | 492 | goto out_master_put; |
481 | } | 493 | } |
482 | 494 | ||
495 | dspi_regmap_config.lock_arg = dspi; | ||
496 | dspi_regmap_config.val_format_endian = | ||
497 | of_property_read_bool(np, "big-endian") | ||
498 | ? REGMAP_ENDIAN_BIG : REGMAP_ENDIAN_DEFAULT; | ||
499 | dspi->regmap = devm_regmap_init_mmio_clk(&pdev->dev, "dspi", base, | ||
500 | &dspi_regmap_config); | ||
501 | if (IS_ERR(dspi->regmap)) { | ||
502 | dev_err(&pdev->dev, "failed to init regmap: %ld\n", | ||
503 | PTR_ERR(dspi->regmap)); | ||
504 | return PTR_ERR(dspi->regmap); | ||
505 | } | ||
506 | |||
483 | dspi->irq = platform_get_irq(pdev, 0); | 507 | dspi->irq = platform_get_irq(pdev, 0); |
484 | if (dspi->irq < 0) { | 508 | if (dspi->irq < 0) { |
485 | dev_err(&pdev->dev, "can't get platform irq\n"); | 509 | dev_err(&pdev->dev, "can't get platform irq\n"); |
diff --git a/drivers/spi/spi-fsl-espi.c b/drivers/spi/spi-fsl-espi.c index 428dc7a6b62e..6fb2b75df821 100644 --- a/drivers/spi/spi-fsl-espi.c +++ b/drivers/spi/spi-fsl-espi.c | |||
@@ -219,13 +219,8 @@ static int fsl_espi_bufs(struct spi_device *spi, struct spi_transfer *t) | |||
219 | struct mpc8xxx_spi *mpc8xxx_spi = spi_master_get_devdata(spi->master); | 219 | struct mpc8xxx_spi *mpc8xxx_spi = spi_master_get_devdata(spi->master); |
220 | struct fsl_espi_reg *reg_base = mpc8xxx_spi->reg_base; | 220 | struct fsl_espi_reg *reg_base = mpc8xxx_spi->reg_base; |
221 | unsigned int len = t->len; | 221 | unsigned int len = t->len; |
222 | u8 bits_per_word; | ||
223 | int ret; | 222 | int ret; |
224 | 223 | ||
225 | bits_per_word = spi->bits_per_word; | ||
226 | if (t->bits_per_word) | ||
227 | bits_per_word = t->bits_per_word; | ||
228 | |||
229 | mpc8xxx_spi->len = t->len; | 224 | mpc8xxx_spi->len = t->len; |
230 | len = roundup(len, 4) / 4; | 225 | len = roundup(len, 4) / 4; |
231 | 226 | ||
diff --git a/drivers/spi/spi-fsl-lib.c b/drivers/spi/spi-fsl-lib.c index 0b75f26158ab..e5d45fca3551 100644 --- a/drivers/spi/spi-fsl-lib.c +++ b/drivers/spi/spi-fsl-lib.c | |||
@@ -200,7 +200,7 @@ int of_mpc8xxx_spi_probe(struct platform_device *ofdev) | |||
200 | const void *prop; | 200 | const void *prop; |
201 | int ret = -ENOMEM; | 201 | int ret = -ENOMEM; |
202 | 202 | ||
203 | pinfo = kzalloc(sizeof(*pinfo), GFP_KERNEL); | 203 | pinfo = devm_kzalloc(&ofdev->dev, sizeof(*pinfo), GFP_KERNEL); |
204 | if (!pinfo) | 204 | if (!pinfo) |
205 | return -ENOMEM; | 205 | return -ENOMEM; |
206 | 206 | ||
@@ -215,15 +215,13 @@ int of_mpc8xxx_spi_probe(struct platform_device *ofdev) | |||
215 | pdata->sysclk = get_brgfreq(); | 215 | pdata->sysclk = get_brgfreq(); |
216 | if (pdata->sysclk == -1) { | 216 | if (pdata->sysclk == -1) { |
217 | pdata->sysclk = fsl_get_sys_freq(); | 217 | pdata->sysclk = fsl_get_sys_freq(); |
218 | if (pdata->sysclk == -1) { | 218 | if (pdata->sysclk == -1) |
219 | ret = -ENODEV; | 219 | return -ENODEV; |
220 | goto err; | ||
221 | } | ||
222 | } | 220 | } |
223 | #else | 221 | #else |
224 | ret = of_property_read_u32(np, "clock-frequency", &pdata->sysclk); | 222 | ret = of_property_read_u32(np, "clock-frequency", &pdata->sysclk); |
225 | if (ret) | 223 | if (ret) |
226 | goto err; | 224 | return ret; |
227 | #endif | 225 | #endif |
228 | 226 | ||
229 | prop = of_get_property(np, "mode", NULL); | 227 | prop = of_get_property(np, "mode", NULL); |
@@ -237,8 +235,4 @@ int of_mpc8xxx_spi_probe(struct platform_device *ofdev) | |||
237 | pdata->flags = SPI_CPM_MODE | SPI_CPM1; | 235 | pdata->flags = SPI_CPM_MODE | SPI_CPM1; |
238 | 236 | ||
239 | return 0; | 237 | return 0; |
240 | |||
241 | err: | ||
242 | kfree(pinfo); | ||
243 | return ret; | ||
244 | } | 238 | } |
diff --git a/drivers/spi/spi-fsl-spi.c b/drivers/spi/spi-fsl-spi.c index 119f7af94537..f35488ed62a9 100644 --- a/drivers/spi/spi-fsl-spi.c +++ b/drivers/spi/spi-fsl-spi.c | |||
@@ -239,12 +239,6 @@ static int fsl_spi_setup_transfer(struct spi_device *spi, | |||
239 | if (!bits_per_word) | 239 | if (!bits_per_word) |
240 | bits_per_word = spi->bits_per_word; | 240 | bits_per_word = spi->bits_per_word; |
241 | 241 | ||
242 | /* Make sure its a bit width we support [4..16, 32] */ | ||
243 | if ((bits_per_word < 4) | ||
244 | || ((bits_per_word > 16) && (bits_per_word != 32)) | ||
245 | || (bits_per_word > mpc8xxx_spi->max_bits_per_word)) | ||
246 | return -EINVAL; | ||
247 | |||
248 | if (!hz) | 242 | if (!hz) |
249 | hz = spi->max_speed_hz; | 243 | hz = spi->max_speed_hz; |
250 | 244 | ||
@@ -362,18 +356,28 @@ static int fsl_spi_bufs(struct spi_device *spi, struct spi_transfer *t, | |||
362 | static void fsl_spi_do_one_msg(struct spi_message *m) | 356 | static void fsl_spi_do_one_msg(struct spi_message *m) |
363 | { | 357 | { |
364 | struct spi_device *spi = m->spi; | 358 | struct spi_device *spi = m->spi; |
365 | struct spi_transfer *t; | 359 | struct spi_transfer *t, *first; |
366 | unsigned int cs_change; | 360 | unsigned int cs_change; |
367 | const int nsecs = 50; | 361 | const int nsecs = 50; |
368 | int status; | 362 | int status; |
369 | 363 | ||
370 | cs_change = 1; | 364 | /* Don't allow changes if CS is active */ |
371 | status = 0; | 365 | first = list_first_entry(&m->transfers, struct spi_transfer, |
366 | transfer_list); | ||
372 | list_for_each_entry(t, &m->transfers, transfer_list) { | 367 | list_for_each_entry(t, &m->transfers, transfer_list) { |
373 | if (t->bits_per_word || t->speed_hz) { | 368 | if ((first->bits_per_word != t->bits_per_word) || |
374 | /* Don't allow changes if CS is active */ | 369 | (first->speed_hz != t->speed_hz)) { |
375 | status = -EINVAL; | 370 | status = -EINVAL; |
371 | dev_err(&spi->dev, | ||
372 | "bits_per_word/speed_hz should be same for the same SPI transfer\n"); | ||
373 | return; | ||
374 | } | ||
375 | } | ||
376 | 376 | ||
377 | cs_change = 1; | ||
378 | status = -EINVAL; | ||
379 | list_for_each_entry(t, &m->transfers, transfer_list) { | ||
380 | if (t->bits_per_word || t->speed_hz) { | ||
377 | if (cs_change) | 381 | if (cs_change) |
378 | status = fsl_spi_setup_transfer(spi, t); | 382 | status = fsl_spi_setup_transfer(spi, t); |
379 | if (status < 0) | 383 | if (status < 0) |
@@ -641,6 +645,10 @@ static struct spi_master * fsl_spi_probe(struct device *dev, | |||
641 | if (mpc8xxx_spi->type == TYPE_GRLIB) | 645 | if (mpc8xxx_spi->type == TYPE_GRLIB) |
642 | fsl_spi_grlib_probe(dev); | 646 | fsl_spi_grlib_probe(dev); |
643 | 647 | ||
648 | master->bits_per_word_mask = | ||
649 | (SPI_BPW_RANGE_MASK(4, 16) | SPI_BPW_MASK(32)) & | ||
650 | SPI_BPW_RANGE_MASK(1, mpc8xxx_spi->max_bits_per_word); | ||
651 | |||
644 | if (mpc8xxx_spi->flags & SPI_QE_CPU_MODE) | 652 | if (mpc8xxx_spi->flags & SPI_QE_CPU_MODE) |
645 | mpc8xxx_spi->set_shifts = fsl_spi_qe_cpu_set_shifts; | 653 | mpc8xxx_spi->set_shifts = fsl_spi_qe_cpu_set_shifts; |
646 | 654 | ||
diff --git a/drivers/spi/spi-gpio.c b/drivers/spi/spi-gpio.c index b189b958432b..e97baf2f475c 100644 --- a/drivers/spi/spi-gpio.c +++ b/drivers/spi/spi-gpio.c | |||
@@ -250,7 +250,7 @@ static int spi_gpio_setup(struct spi_device *spi) | |||
250 | /* | 250 | /* |
251 | * ... otherwise, take it from spi->controller_data | 251 | * ... otherwise, take it from spi->controller_data |
252 | */ | 252 | */ |
253 | cs = (unsigned int) spi->controller_data; | 253 | cs = (unsigned int)(uintptr_t) spi->controller_data; |
254 | } | 254 | } |
255 | 255 | ||
256 | if (!spi->controller_state) { | 256 | if (!spi->controller_state) { |
diff --git a/drivers/spi/spi-pl022.c b/drivers/spi/spi-pl022.c index 2789b452e711..3c5b90559bec 100644 --- a/drivers/spi/spi-pl022.c +++ b/drivers/spi/spi-pl022.c | |||
@@ -459,9 +459,8 @@ static void giveback(struct pl022 *pl022) | |||
459 | struct spi_transfer *last_transfer; | 459 | struct spi_transfer *last_transfer; |
460 | pl022->next_msg_cs_active = false; | 460 | pl022->next_msg_cs_active = false; |
461 | 461 | ||
462 | last_transfer = list_entry(pl022->cur_msg->transfers.prev, | 462 | last_transfer = list_last_entry(&pl022->cur_msg->transfers, |
463 | struct spi_transfer, | 463 | struct spi_transfer, transfer_list); |
464 | transfer_list); | ||
465 | 464 | ||
466 | /* Delay if requested before any change in chip select */ | 465 | /* Delay if requested before any change in chip select */ |
467 | if (last_transfer->delay_usecs) | 466 | if (last_transfer->delay_usecs) |
diff --git a/drivers/spi/spi-pxa2xx.c b/drivers/spi/spi-pxa2xx.c index c702fc536a77..41185d0557fa 100644 --- a/drivers/spi/spi-pxa2xx.c +++ b/drivers/spi/spi-pxa2xx.c | |||
@@ -362,8 +362,7 @@ static void giveback(struct driver_data *drv_data) | |||
362 | drv_data->cur_msg = NULL; | 362 | drv_data->cur_msg = NULL; |
363 | drv_data->cur_transfer = NULL; | 363 | drv_data->cur_transfer = NULL; |
364 | 364 | ||
365 | last_transfer = list_entry(msg->transfers.prev, | 365 | last_transfer = list_last_entry(&msg->transfers, struct spi_transfer, |
366 | struct spi_transfer, | ||
367 | transfer_list); | 366 | transfer_list); |
368 | 367 | ||
369 | /* Delay if requested before any change in chip select */ | 368 | /* Delay if requested before any change in chip select */ |