Skip to content

Commit 90ae83f

Browse files
committed
Merge branch 'next-spi' of git://git.secretlab.ca/git/linux-2.6
* 'next-spi' of git://git.secretlab.ca/git/linux-2.6: spi/pl022: fix erroneous platform data in U300 spi: fixed odd static string conventions in core code spi/bfin_spi: only request GPIO on first load spi/bfin_spi: handle error/status changes after data interrupts spi: enable spi_board_info to be registered after spi_master
2 parents 47c5ba5 + 65289d6 commit 90ae83f

File tree

4 files changed

+73
-52
lines changed

4 files changed

+73
-52
lines changed

arch/arm/mach-u300/spi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static struct spi_board_info u300_spi_devices[] = {
6767
.bus_num = 0, /* Only one bus on this chip */
6868
.chip_select = 0,
6969
/* Means SPI_CS_HIGH, change if e.g low CS */
70-
.mode = SPI_MODE_1 | SPI_LSB_FIRST | SPI_LOOP,
70+
.mode = SPI_MODE_1 | SPI_LOOP,
7171
},
7272
#endif
7373
};

drivers/spi/spi.c

Lines changed: 52 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@
2929
#include <linux/spi/spi.h>
3030
#include <linux/of_spi.h>
3131

32-
33-
/* SPI bustype and spi_master class are registered after board init code
34-
* provides the SPI device tables, ensuring that both are present by the
35-
* time controller driver registration causes spi_devices to "enumerate".
36-
*/
3732
static void spidev_release(struct device *dev)
3833
{
3934
struct spi_device *spi = to_spi_device(dev);
@@ -202,11 +197,16 @@ EXPORT_SYMBOL_GPL(spi_register_driver);
202197

203198
struct boardinfo {
204199
struct list_head list;
205-
unsigned n_board_info;
206-
struct spi_board_info board_info[0];
200+
struct spi_board_info board_info;
207201
};
208202

209203
static LIST_HEAD(board_list);
204+
static LIST_HEAD(spi_master_list);
205+
206+
/*
207+
* Used to protect add/del opertion for board_info list and
208+
* spi_master list, and their matching process
209+
*/
210210
static DEFINE_MUTEX(board_lock);
211211

212212
/**
@@ -300,16 +300,16 @@ int spi_add_device(struct spi_device *spi)
300300
*/
301301
status = spi_setup(spi);
302302
if (status < 0) {
303-
dev_err(dev, "can't %s %s, status %d\n",
304-
"setup", dev_name(&spi->dev), status);
303+
dev_err(dev, "can't setup %s, status %d\n",
304+
dev_name(&spi->dev), status);
305305
goto done;
306306
}
307307

308308
/* Device may be bound to an active driver when this returns */
309309
status = device_add(&spi->dev);
310310
if (status < 0)
311-
dev_err(dev, "can't %s %s, status %d\n",
312-
"add", dev_name(&spi->dev), status);
311+
dev_err(dev, "can't add %s, status %d\n",
312+
dev_name(&spi->dev), status);
313313
else
314314
dev_dbg(dev, "registered child %s\n", dev_name(&spi->dev));
315315

@@ -371,6 +371,20 @@ struct spi_device *spi_new_device(struct spi_master *master,
371371
}
372372
EXPORT_SYMBOL_GPL(spi_new_device);
373373

374+
static void spi_match_master_to_boardinfo(struct spi_master *master,
375+
struct spi_board_info *bi)
376+
{
377+
struct spi_device *dev;
378+
379+
if (master->bus_num != bi->bus_num)
380+
return;
381+
382+
dev = spi_new_device(master, bi);
383+
if (!dev)
384+
dev_err(master->dev.parent, "can't create new device for %s\n",
385+
bi->modalias);
386+
}
387+
374388
/**
375389
* spi_register_board_info - register SPI devices for a given board
376390
* @info: array of chip descriptors
@@ -393,43 +407,25 @@ EXPORT_SYMBOL_GPL(spi_new_device);
393407
int __init
394408
spi_register_board_info(struct spi_board_info const *info, unsigned n)
395409
{
396-
struct boardinfo *bi;
410+
struct boardinfo *bi;
411+
int i;
397412

398-
bi = kmalloc(sizeof(*bi) + n * sizeof *info, GFP_KERNEL);
413+
bi = kzalloc(n * sizeof(*bi), GFP_KERNEL);
399414
if (!bi)
400415
return -ENOMEM;
401-
bi->n_board_info = n;
402-
memcpy(bi->board_info, info, n * sizeof *info);
403416

404-
mutex_lock(&board_lock);
405-
list_add_tail(&bi->list, &board_list);
406-
mutex_unlock(&board_lock);
407-
return 0;
408-
}
417+
for (i = 0; i < n; i++, bi++, info++) {
418+
struct spi_master *master;
409419

410-
/* FIXME someone should add support for a __setup("spi", ...) that
411-
* creates board info from kernel command lines
412-
*/
413-
414-
static void scan_boardinfo(struct spi_master *master)
415-
{
416-
struct boardinfo *bi;
417-
418-
mutex_lock(&board_lock);
419-
list_for_each_entry(bi, &board_list, list) {
420-
struct spi_board_info *chip = bi->board_info;
421-
unsigned n;
422-
423-
for (n = bi->n_board_info; n > 0; n--, chip++) {
424-
if (chip->bus_num != master->bus_num)
425-
continue;
426-
/* NOTE: this relies on spi_new_device to
427-
* issue diagnostics when given bogus inputs
428-
*/
429-
(void) spi_new_device(master, chip);
430-
}
420+
memcpy(&bi->board_info, info, sizeof(*info));
421+
mutex_lock(&board_lock);
422+
list_add_tail(&bi->list, &board_list);
423+
list_for_each_entry(master, &spi_master_list, list)
424+
spi_match_master_to_boardinfo(master, &bi->board_info);
425+
mutex_unlock(&board_lock);
431426
}
432-
mutex_unlock(&board_lock);
427+
428+
return 0;
433429
}
434430

435431
/*-------------------------------------------------------------------------*/
@@ -512,6 +508,7 @@ int spi_register_master(struct spi_master *master)
512508
{
513509
static atomic_t dyn_bus_id = ATOMIC_INIT((1<<15) - 1);
514510
struct device *dev = master->dev.parent;
511+
struct boardinfo *bi;
515512
int status = -ENODEV;
516513
int dynamic = 0;
517514

@@ -547,8 +544,12 @@ int spi_register_master(struct spi_master *master)
547544
dev_dbg(dev, "registered master %s%s\n", dev_name(&master->dev),
548545
dynamic ? " (dynamic)" : "");
549546

550-
/* populate children from any spi device tables */
551-
scan_boardinfo(master);
547+
mutex_lock(&board_lock);
548+
list_add_tail(&master->list, &spi_master_list);
549+
list_for_each_entry(bi, &board_list, list)
550+
spi_match_master_to_boardinfo(master, &bi->board_info);
551+
mutex_unlock(&board_lock);
552+
552553
status = 0;
553554

554555
/* Register devices from the device tree */
@@ -579,7 +580,12 @@ void spi_unregister_master(struct spi_master *master)
579580
{
580581
int dummy;
581582

582-
dummy = device_for_each_child(&master->dev, NULL, __unregister);
583+
mutex_lock(&board_lock);
584+
list_del(&master->list);
585+
mutex_unlock(&board_lock);
586+
587+
dummy = device_for_each_child(master->dev.parent, &master->dev,
588+
__unregister);
583589
device_unregister(&master->dev);
584590
}
585591
EXPORT_SYMBOL_GPL(spi_unregister_master);
@@ -652,7 +658,7 @@ int spi_setup(struct spi_device *spi)
652658
*/
653659
bad_bits = spi->mode & ~spi->master->mode_bits;
654660
if (bad_bits) {
655-
dev_dbg(&spi->dev, "setup: unsupported mode bits %x\n",
661+
dev_err(&spi->dev, "setup: unsupported mode bits %x\n",
656662
bad_bits);
657663
return -EINVAL;
658664
}

drivers/spi/spi_bfin5xx.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,15 @@ static irqreturn_t bfin_spi_dma_irq_handler(int irq, void *dev_id)
504504
"in dma_irq_handler dmastat:0x%x spistat:0x%x\n",
505505
dmastat, spistat);
506506

507+
if (drv_data->rx != NULL) {
508+
u16 cr = read_CTRL(drv_data);
509+
/* discard old RX data and clear RXS */
510+
bfin_spi_dummy_read(drv_data);
511+
write_CTRL(drv_data, cr & ~BIT_CTL_ENABLE); /* Disable SPI */
512+
write_CTRL(drv_data, cr & ~BIT_CTL_TIMOD); /* Restore State */
513+
write_STAT(drv_data, BIT_STAT_CLR); /* Clear Status */
514+
}
515+
507516
clear_dma_irqstat(drv_data->dma_channel);
508517

509518
/*
@@ -1099,12 +1108,15 @@ static int bfin_spi_setup(struct spi_device *spi)
10991108
}
11001109

11011110
if (chip->chip_select_num >= MAX_CTRL_CS) {
1102-
ret = gpio_request(chip->cs_gpio, spi->modalias);
1103-
if (ret) {
1104-
dev_err(&spi->dev, "gpio_request() error\n");
1105-
goto pin_error;
1111+
/* Only request on first setup */
1112+
if (spi_get_ctldata(spi) == NULL) {
1113+
ret = gpio_request(chip->cs_gpio, spi->modalias);
1114+
if (ret) {
1115+
dev_err(&spi->dev, "gpio_request() error\n");
1116+
goto pin_error;
1117+
}
1118+
gpio_direction_output(chip->cs_gpio, 1);
11061119
}
1107-
gpio_direction_output(chip->cs_gpio, 1);
11081120
}
11091121

11101122
dev_dbg(&spi->dev, "setup spi chip %s, width is %d, dma is %d\n",

include/linux/spi/spi.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv)
204204
/**
205205
* struct spi_master - interface to SPI master controller
206206
* @dev: device interface to this driver
207+
* @list: link with the global spi_master list
207208
* @bus_num: board-specific (and often SOC-specific) identifier for a
208209
* given SPI controller.
209210
* @num_chipselect: chipselects are used to distinguish individual
@@ -238,6 +239,8 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv)
238239
struct spi_master {
239240
struct device dev;
240241

242+
struct list_head list;
243+
241244
/* other than negative (== assign one dynamically), bus_num is fully
242245
* board-specific. usually that simplifies to being SOC-specific.
243246
* example: one SOC has three SPI controllers, numbered 0..2,

0 commit comments

Comments
 (0)