Created
November 26, 2010 11:54
-
-
Save scottellis/716613 to your computer and use it in GitHub Desktop.
add_spike_device_to_bus
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static int __init add_spike_device_to_bus(void) | |
{ | |
struct spi_master *spi_master; | |
struct spi_device *spi_device; | |
struct device *pdev; | |
char buff[64]; | |
int status = 0; | |
spi_master = spi_busnum_to_master(SPI_BUS); | |
if (!spi_master) { | |
printk(KERN_ALERT "spi_busnum_to_master(%d) returned NULL\n", | |
SPI_BUS); | |
printk(KERN_ALERT "Missing modprobe omap2_mcspi?\n"); | |
return -1; | |
} | |
spi_device = spi_alloc_device(spi_master); | |
if (!spi_device) { | |
put_device(&spi_master->dev); | |
printk(KERN_ALERT "spi_alloc_device() failed\n"); | |
return -1; | |
} | |
/* specify a chip select line */ | |
spi_device->chip_select = SPI_BUS_CS1; | |
/* Check whether this SPI bus.cs is already claimed */ | |
snprintf(buff, sizeof(buff), "%s.%u", | |
dev_name(&spi_device->master->dev), | |
spi_device->chip_select); | |
pdev = bus_find_device_by_name(spi_device->dev.bus, NULL, buff); | |
if (pdev) { | |
/* We are not going to use this spi_device, so free it */ | |
spi_dev_put(spi_device); | |
/* | |
* There is already a device configured for this bus.cs combination. | |
* It's okay if it's us. This happens if we previously loaded then | |
* unloaded our driver. | |
* If it is not us, we complain and fail. | |
*/ | |
if (pdev->driver && pdev->driver->name && | |
strcmp(this_driver_name, pdev->driver->name)) { | |
printk(KERN_ALERT | |
"Driver [%s] already registered for %s\n", | |
pdev->driver->name, buff); | |
status = -1; | |
} | |
} else { | |
spi_device->max_speed_hz = SPI_BUS_SPEED; | |
spi_device->mode = SPI_MODE_0; | |
spi_device->bits_per_word = 8; | |
spi_device->irq = -1; | |
spi_device->controller_state = NULL; | |
spi_device->controller_data = NULL; | |
strlcpy(spi_device->modalias, this_driver_name, SPI_NAME_SIZE); | |
status = spi_add_device(spi_device); | |
if (status < 0) { | |
spi_dev_put(spi_device); | |
printk(KERN_ALERT "spi_add_device() failed: %d\n", | |
status); | |
} | |
} | |
put_device(&spi_master->dev); | |
return status; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment