summaryrefslogtreecommitdiffstats
path: root/drivers/spi
diff options
context:
space:
mode:
authorKen Wilson <ken.wilson@opengear.com>2015-01-11 22:13:59 -0500
committerMark Brown <broonie@kernel.org>2015-01-14 12:21:55 -0500
commit75872ebe96d3e78e86840f51dd4b7ca0abeacd6e (patch)
treecf90f40ca12ad6050a6861ce5183257809de17cd /drivers/spi
parent97bf6af1f928216fd6c5a66e8a57bfa95a659672 (diff)
spi: orion: Change spi-orion to use transfer_one() semantics for SPI transfers
This commit changes spi-orion to provide setup, set_cs, and transfer_one functions instead of transfer_one_message. This allows chip select support for both native and GPIO chip selects to be added. Signed-off-by: Ken Wilson <ken.wilson@opengear.com> Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'drivers/spi')
-rw-r--r--drivers/spi/spi-orion.c73
1 files changed, 23 insertions, 50 deletions
diff --git a/drivers/spi/spi-orion.c b/drivers/spi/spi-orion.c
index 3dec9e0b99b8..98f1a8491b27 100644
--- a/drivers/spi/spi-orion.c
+++ b/drivers/spi/spi-orion.c
@@ -215,9 +215,14 @@ orion_spi_setup_transfer(struct spi_device *spi, struct spi_transfer *t)
215 return 0; 215 return 0;
216} 216}
217 217
218static void orion_spi_set_cs(struct orion_spi *orion_spi, int enable) 218static void orion_spi_set_cs(struct spi_device *spi, bool enable)
219{ 219{
220 if (enable) 220 struct orion_spi *orion_spi;
221
222 orion_spi = spi_master_get_devdata(spi->master);
223
224 /* Chip select logic is inverted from spi_set_cs */
225 if (!enable)
221 orion_spi_setbits(orion_spi, ORION_SPI_IF_CTRL_REG, 0x1); 226 orion_spi_setbits(orion_spi, ORION_SPI_IF_CTRL_REG, 0x1);
222 else 227 else
223 orion_spi_clrbits(orion_spi, ORION_SPI_IF_CTRL_REG, 0x1); 228 orion_spi_clrbits(orion_spi, ORION_SPI_IF_CTRL_REG, 0x1);
@@ -332,64 +337,31 @@ out:
332 return xfer->len - count; 337 return xfer->len - count;
333} 338}
334 339
335static int orion_spi_transfer_one_message(struct spi_master *master, 340static int orion_spi_transfer_one(struct spi_master *master,
336 struct spi_message *m) 341 struct spi_device *spi,
342 struct spi_transfer *t)
337{ 343{
338 struct orion_spi *orion_spi = spi_master_get_devdata(master);
339 struct spi_device *spi = m->spi;
340 struct spi_transfer *t = NULL;
341 int par_override = 0;
342 int status = 0; 344 int status = 0;
343 int cs_active = 0;
344
345 /* Load defaults */
346 status = orion_spi_setup_transfer(spi, NULL);
347 345
346 status = orion_spi_setup_transfer(spi, t);
348 if (status < 0) 347 if (status < 0)
349 goto msg_done; 348 return status;
350
351 list_for_each_entry(t, &m->transfers, transfer_list) {
352 if (par_override || t->speed_hz || t->bits_per_word) {
353 par_override = 1;
354 status = orion_spi_setup_transfer(spi, t);
355 if (status < 0)
356 break;
357 if (!t->speed_hz && !t->bits_per_word)
358 par_override = 0;
359 }
360
361 if (!cs_active) {
362 orion_spi_set_cs(orion_spi, 1);
363 cs_active = 1;
364 }
365 349
366 if (t->len) 350 if (t->len)
367 m->actual_length += orion_spi_write_read(spi, t); 351 orion_spi_write_read(spi, t);
368 352
369 if (t->delay_usecs) 353 return status;
370 udelay(t->delay_usecs); 354}
371
372 if (t->cs_change) {
373 orion_spi_set_cs(orion_spi, 0);
374 cs_active = 0;
375 }
376 }
377
378msg_done:
379 if (cs_active)
380 orion_spi_set_cs(orion_spi, 0);
381
382 m->status = status;
383 spi_finalize_current_message(master);
384 355
385 return 0; 356static int orion_spi_setup(struct spi_device *spi)
357{
358 return orion_spi_setup_transfer(spi, NULL);
386} 359}
387 360
388static int orion_spi_reset(struct orion_spi *orion_spi) 361static int orion_spi_reset(struct orion_spi *orion_spi)
389{ 362{
390 /* Verify that the CS is deasserted */ 363 /* Verify that the CS is deasserted */
391 orion_spi_set_cs(orion_spi, 0); 364 orion_spi_clrbits(orion_spi, ORION_SPI_IF_CTRL_REG, 0x1);
392
393 return 0; 365 return 0;
394} 366}
395 367
@@ -442,9 +414,10 @@ static int orion_spi_probe(struct platform_device *pdev)
442 414
443 /* we support only mode 0, and no options */ 415 /* we support only mode 0, and no options */
444 master->mode_bits = SPI_CPHA | SPI_CPOL; 416 master->mode_bits = SPI_CPHA | SPI_CPOL;
445 417 master->set_cs = orion_spi_set_cs;
446 master->transfer_one_message = orion_spi_transfer_one_message; 418 master->transfer_one = orion_spi_transfer_one;
447 master->num_chipselect = ORION_NUM_CHIPSELECTS; 419 master->num_chipselect = ORION_NUM_CHIPSELECTS;
420 master->setup = orion_spi_setup;
448 master->bits_per_word_mask = SPI_BPW_MASK(8) | SPI_BPW_MASK(16); 421 master->bits_per_word_mask = SPI_BPW_MASK(8) | SPI_BPW_MASK(16);
449 master->auto_runtime_pm = true; 422 master->auto_runtime_pm = true;
450 423