spi.c (2841a5fc375e9c573d10b82db30fa8a4cc25301c) | spi.c (b158935f70b9c156903338053216dd0adf7ce31c) |
---|---|
1/* 2 * SPI init/core code 3 * 4 * Copyright (C) 2005 David Brownell 5 * Copyright (C) 2008 Secret Lab Technologies Ltd. 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by --- 512 unchanged lines hidden (view full) --- 521 mutex_unlock(&board_lock); 522 } 523 524 return 0; 525} 526 527/*-------------------------------------------------------------------------*/ 528 | 1/* 2 * SPI init/core code 3 * 4 * Copyright (C) 2005 David Brownell 5 * Copyright (C) 2008 Secret Lab Technologies Ltd. 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by --- 512 unchanged lines hidden (view full) --- 521 mutex_unlock(&board_lock); 522 } 523 524 return 0; 525} 526 527/*-------------------------------------------------------------------------*/ 528 |
529static void spi_set_cs(struct spi_device *spi, bool enable) 530{ 531 if (spi->mode & SPI_CS_HIGH) 532 enable = !enable; 533 534 if (spi->cs_gpio >= 0) 535 gpio_set_value(spi->cs_gpio, !enable); 536 else if (spi->master->set_cs) 537 spi->master->set_cs(spi, !enable); 538} 539 540/* 541 * spi_transfer_one_message - Default implementation of transfer_one_message() 542 * 543 * This is a standard implementation of transfer_one_message() for 544 * drivers which impelment a transfer_one() operation. It provides 545 * standard handling of delays and chip select management. 546 */ 547static int spi_transfer_one_message(struct spi_master *master, 548 struct spi_message *msg) 549{ 550 struct spi_transfer *xfer; 551 bool cur_cs = true; 552 bool keep_cs = false; 553 int ret = 0; 554 555 spi_set_cs(msg->spi, true); 556 557 list_for_each_entry(xfer, &msg->transfers, transfer_list) { 558 trace_spi_transfer_start(msg, xfer); 559 560 INIT_COMPLETION(master->xfer_completion); 561 562 ret = master->transfer_one(master, msg->spi, xfer); 563 if (ret < 0) { 564 dev_err(&msg->spi->dev, 565 "SPI transfer failed: %d\n", ret); 566 goto out; 567 } 568 569 if (ret > 0) 570 wait_for_completion(&master->xfer_completion); 571 572 trace_spi_transfer_stop(msg, xfer); 573 574 if (msg->status != -EINPROGRESS) 575 goto out; 576 577 if (xfer->delay_usecs) 578 udelay(xfer->delay_usecs); 579 580 if (xfer->cs_change) { 581 if (list_is_last(&xfer->transfer_list, 582 &msg->transfers)) { 583 keep_cs = true; 584 } else { 585 cur_cs = !cur_cs; 586 spi_set_cs(msg->spi, cur_cs); 587 } 588 } 589 590 msg->actual_length += xfer->len; 591 } 592 593out: 594 if (ret != 0 || !keep_cs) 595 spi_set_cs(msg->spi, false); 596 597 if (msg->status == -EINPROGRESS) 598 msg->status = ret; 599 600 spi_finalize_current_message(master); 601 602 return ret; 603} 604 |
|
529/** | 605/** |
606 * spi_finalize_current_transfer - report completion of a transfer 607 * 608 * Called by SPI drivers using the core transfer_one_message() 609 * implementation to notify it that the current interrupt driven 610 * transfer has finised and the next one may be scheduled. 611 */ 612void spi_finalize_current_transfer(struct spi_master *master) 613{ 614 complete(&master->xfer_completion); 615} 616EXPORT_SYMBOL_GPL(spi_finalize_current_transfer); 617 618/** |
|
530 * spi_pump_messages - kthread work function which processes spi message queue 531 * @work: pointer to kthread work struct contained in the master struct 532 * 533 * This function checks if there is any spi message in the queue that 534 * needs processing and if so call out to the driver to initialize hardware 535 * and transfer each message. 536 * 537 */ --- 293 unchanged lines hidden (view full) --- 831} 832 833static int spi_master_initialize_queue(struct spi_master *master) 834{ 835 int ret; 836 837 master->queued = true; 838 master->transfer = spi_queued_transfer; | 619 * spi_pump_messages - kthread work function which processes spi message queue 620 * @work: pointer to kthread work struct contained in the master struct 621 * 622 * This function checks if there is any spi message in the queue that 623 * needs processing and if so call out to the driver to initialize hardware 624 * and transfer each message. 625 * 626 */ --- 293 unchanged lines hidden (view full) --- 920} 921 922static int spi_master_initialize_queue(struct spi_master *master) 923{ 924 int ret; 925 926 master->queued = true; 927 master->transfer = spi_queued_transfer; |
928 if (!master->transfer_one_message) 929 master->transfer_one_message = spi_transfer_one_message; |
|
839 840 /* Initialize and start queue */ 841 ret = spi_init_queue(master); 842 if (ret) { 843 dev_err(&master->dev, "problem initializing queue\n"); 844 goto err_init_queue; 845 } 846 ret = spi_start_queue(master); --- 390 unchanged lines hidden (view full) --- 1237 */ 1238 master->bus_num = atomic_dec_return(&dyn_bus_id); 1239 dynamic = 1; 1240 } 1241 1242 spin_lock_init(&master->bus_lock_spinlock); 1243 mutex_init(&master->bus_lock_mutex); 1244 master->bus_lock_flag = 0; | 930 931 /* Initialize and start queue */ 932 ret = spi_init_queue(master); 933 if (ret) { 934 dev_err(&master->dev, "problem initializing queue\n"); 935 goto err_init_queue; 936 } 937 ret = spi_start_queue(master); --- 390 unchanged lines hidden (view full) --- 1328 */ 1329 master->bus_num = atomic_dec_return(&dyn_bus_id); 1330 dynamic = 1; 1331 } 1332 1333 spin_lock_init(&master->bus_lock_spinlock); 1334 mutex_init(&master->bus_lock_mutex); 1335 master->bus_lock_flag = 0; |
1336 init_completion(&master->xfer_completion); |
|
1245 1246 /* register the device, then userspace will see it. 1247 * registration fails if the bus ID is in use. 1248 */ 1249 dev_set_name(&master->dev, "spi%u", master->bus_num); 1250 status = device_add(&master->dev); 1251 if (status < 0) 1252 goto done; --- 664 unchanged lines hidden --- | 1337 1338 /* register the device, then userspace will see it. 1339 * registration fails if the bus ID is in use. 1340 */ 1341 dev_set_name(&master->dev, "spi%u", master->bus_num); 1342 status = device_add(&master->dev); 1343 if (status < 0) 1344 goto done; --- 664 unchanged lines hidden --- |