diff options
Diffstat (limited to 'drivers/spi/spi-orion.c')
-rw-r--r-- | drivers/spi/spi-orion.c | 80 |
1 files changed, 11 insertions, 69 deletions
diff --git a/drivers/spi/spi-orion.c b/drivers/spi/spi-orion.c index 7f2121fe2622..d018a4aac3a1 100644 --- a/drivers/spi/spi-orion.c +++ b/drivers/spi/spi-orion.c | |||
@@ -9,7 +9,6 @@ | |||
9 | * published by the Free Software Foundation. | 9 | * published by the Free Software Foundation. |
10 | */ | 10 | */ |
11 | 11 | ||
12 | #include <linux/init.h> | ||
13 | #include <linux/interrupt.h> | 12 | #include <linux/interrupt.h> |
14 | #include <linux/delay.h> | 13 | #include <linux/delay.h> |
15 | #include <linux/platform_device.h> | 14 | #include <linux/platform_device.h> |
@@ -43,8 +42,6 @@ | |||
43 | struct orion_spi { | 42 | struct orion_spi { |
44 | struct spi_master *master; | 43 | struct spi_master *master; |
45 | void __iomem *base; | 44 | void __iomem *base; |
46 | unsigned int max_speed; | ||
47 | unsigned int min_speed; | ||
48 | struct clk *clk; | 45 | struct clk *clk; |
49 | }; | 46 | }; |
50 | 47 | ||
@@ -75,23 +72,6 @@ orion_spi_clrbits(struct orion_spi *orion_spi, u32 reg, u32 mask) | |||
75 | writel(val, reg_addr); | 72 | writel(val, reg_addr); |
76 | } | 73 | } |
77 | 74 | ||
78 | static int orion_spi_set_transfer_size(struct orion_spi *orion_spi, int size) | ||
79 | { | ||
80 | if (size == 16) { | ||
81 | orion_spi_setbits(orion_spi, ORION_SPI_IF_CONFIG_REG, | ||
82 | ORION_SPI_IF_8_16_BIT_MODE); | ||
83 | } else if (size == 8) { | ||
84 | orion_spi_clrbits(orion_spi, ORION_SPI_IF_CONFIG_REG, | ||
85 | ORION_SPI_IF_8_16_BIT_MODE); | ||
86 | } else { | ||
87 | pr_debug("Bad bits per word value %d (only 8 or 16 are allowed).\n", | ||
88 | size); | ||
89 | return -EINVAL; | ||
90 | } | ||
91 | |||
92 | return 0; | ||
93 | } | ||
94 | |||
95 | static int orion_spi_baudrate_set(struct spi_device *spi, unsigned int speed) | 75 | static int orion_spi_baudrate_set(struct spi_device *spi, unsigned int speed) |
96 | { | 76 | { |
97 | u32 tclk_hz; | 77 | u32 tclk_hz; |
@@ -170,7 +150,14 @@ orion_spi_setup_transfer(struct spi_device *spi, struct spi_transfer *t) | |||
170 | if (rc) | 150 | if (rc) |
171 | return rc; | 151 | return rc; |
172 | 152 | ||
173 | return orion_spi_set_transfer_size(orion_spi, bits_per_word); | 153 | if (bits_per_word == 16) |
154 | orion_spi_setbits(orion_spi, ORION_SPI_IF_CONFIG_REG, | ||
155 | ORION_SPI_IF_8_16_BIT_MODE); | ||
156 | else | ||
157 | orion_spi_clrbits(orion_spi, ORION_SPI_IF_CONFIG_REG, | ||
158 | ORION_SPI_IF_8_16_BIT_MODE); | ||
159 | |||
160 | return 0; | ||
174 | } | 161 | } |
175 | 162 | ||
176 | static void orion_spi_set_cs(struct orion_spi *orion_spi, int enable) | 163 | static void orion_spi_set_cs(struct orion_spi *orion_spi, int enable) |
@@ -260,11 +247,9 @@ orion_spi_write_read_16bit(struct spi_device *spi, | |||
260 | static unsigned int | 247 | static unsigned int |
261 | orion_spi_write_read(struct spi_device *spi, struct spi_transfer *xfer) | 248 | orion_spi_write_read(struct spi_device *spi, struct spi_transfer *xfer) |
262 | { | 249 | { |
263 | struct orion_spi *orion_spi; | ||
264 | unsigned int count; | 250 | unsigned int count; |
265 | int word_len; | 251 | int word_len; |
266 | 252 | ||
267 | orion_spi = spi_master_get_devdata(spi->master); | ||
268 | word_len = spi->bits_per_word; | 253 | word_len = spi->bits_per_word; |
269 | count = xfer->len; | 254 | count = xfer->len; |
270 | 255 | ||
@@ -310,27 +295,6 @@ static int orion_spi_transfer_one_message(struct spi_master *master, | |||
310 | goto msg_done; | 295 | goto msg_done; |
311 | 296 | ||
312 | list_for_each_entry(t, &m->transfers, transfer_list) { | 297 | list_for_each_entry(t, &m->transfers, transfer_list) { |
313 | /* make sure buffer length is even when working in 16 | ||
314 | * bit mode*/ | ||
315 | if ((t->bits_per_word == 16) && (t->len & 1)) { | ||
316 | dev_err(&spi->dev, | ||
317 | "message rejected : " | ||
318 | "odd data length %d while in 16 bit mode\n", | ||
319 | t->len); | ||
320 | status = -EIO; | ||
321 | goto msg_done; | ||
322 | } | ||
323 | |||
324 | if (t->speed_hz && t->speed_hz < orion_spi->min_speed) { | ||
325 | dev_err(&spi->dev, | ||
326 | "message rejected : " | ||
327 | "device min speed (%d Hz) exceeds " | ||
328 | "required transfer speed (%d Hz)\n", | ||
329 | orion_spi->min_speed, t->speed_hz); | ||
330 | status = -EIO; | ||
331 | goto msg_done; | ||
332 | } | ||
333 | |||
334 | if (par_override || t->speed_hz || t->bits_per_word) { | 298 | if (par_override || t->speed_hz || t->bits_per_word) { |
335 | par_override = 1; | 299 | par_override = 1; |
336 | status = orion_spi_setup_transfer(spi, t); | 300 | status = orion_spi_setup_transfer(spi, t); |
@@ -375,28 +339,6 @@ static int orion_spi_reset(struct orion_spi *orion_spi) | |||
375 | return 0; | 339 | return 0; |
376 | } | 340 | } |
377 | 341 | ||
378 | static int orion_spi_setup(struct spi_device *spi) | ||
379 | { | ||
380 | struct orion_spi *orion_spi; | ||
381 | |||
382 | orion_spi = spi_master_get_devdata(spi->master); | ||
383 | |||
384 | if ((spi->max_speed_hz == 0) | ||
385 | || (spi->max_speed_hz > orion_spi->max_speed)) | ||
386 | spi->max_speed_hz = orion_spi->max_speed; | ||
387 | |||
388 | if (spi->max_speed_hz < orion_spi->min_speed) { | ||
389 | dev_err(&spi->dev, "setup: requested speed too low %d Hz\n", | ||
390 | spi->max_speed_hz); | ||
391 | return -EINVAL; | ||
392 | } | ||
393 | |||
394 | /* | ||
395 | * baudrate & width will be set orion_spi_setup_transfer | ||
396 | */ | ||
397 | return 0; | ||
398 | } | ||
399 | |||
400 | static int orion_spi_probe(struct platform_device *pdev) | 342 | static int orion_spi_probe(struct platform_device *pdev) |
401 | { | 343 | { |
402 | struct spi_master *master; | 344 | struct spi_master *master; |
@@ -425,9 +367,9 @@ static int orion_spi_probe(struct platform_device *pdev) | |||
425 | /* we support only mode 0, and no options */ | 367 | /* we support only mode 0, and no options */ |
426 | master->mode_bits = SPI_CPHA | SPI_CPOL; | 368 | master->mode_bits = SPI_CPHA | SPI_CPOL; |
427 | 369 | ||
428 | master->setup = orion_spi_setup; | ||
429 | master->transfer_one_message = orion_spi_transfer_one_message; | 370 | master->transfer_one_message = orion_spi_transfer_one_message; |
430 | master->num_chipselect = ORION_NUM_CHIPSELECTS; | 371 | master->num_chipselect = ORION_NUM_CHIPSELECTS; |
372 | master->bits_per_word_mask = SPI_BPW_MASK(8) | SPI_BPW_MASK(16); | ||
431 | 373 | ||
432 | platform_set_drvdata(pdev, master); | 374 | platform_set_drvdata(pdev, master); |
433 | 375 | ||
@@ -443,8 +385,8 @@ static int orion_spi_probe(struct platform_device *pdev) | |||
443 | clk_prepare(spi->clk); | 385 | clk_prepare(spi->clk); |
444 | clk_enable(spi->clk); | 386 | clk_enable(spi->clk); |
445 | tclk_hz = clk_get_rate(spi->clk); | 387 | tclk_hz = clk_get_rate(spi->clk); |
446 | spi->max_speed = DIV_ROUND_UP(tclk_hz, 4); | 388 | master->max_speed_hz = DIV_ROUND_UP(tclk_hz, 4); |
447 | spi->min_speed = DIV_ROUND_UP(tclk_hz, 30); | 389 | master->min_speed_hz = DIV_ROUND_UP(tclk_hz, 30); |
448 | 390 | ||
449 | r = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 391 | r = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
450 | spi->base = devm_ioremap_resource(&pdev->dev, r); | 392 | spi->base = devm_ioremap_resource(&pdev->dev, r); |