Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 106877
b: refs/heads/master
c: 284b018
h: refs/heads/master
i:
  106875: ab8e27d
v: v3
  • Loading branch information
Grant Likely committed Jul 26, 2008
1 parent 501a869 commit b121a4d
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: dc87c98e8f635a718f1abb2c3e15fc77c0001651
refs/heads/master: 284b01897340974000bcc84de87a4e1becc8a83d
6 changes: 6 additions & 0 deletions trunk/drivers/of/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ config OF_I2C
depends on PPC_OF && I2C
help
OpenFirmware I2C accessors

config OF_SPI
def_tristate SPI
depends on OF && PPC_OF && SPI
help
OpenFirmware SPI accessors
1 change: 1 addition & 0 deletions trunk/drivers/of/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ obj-y = base.o
obj-$(CONFIG_OF_DEVICE) += device.o platform.o
obj-$(CONFIG_OF_GPIO) += gpio.o
obj-$(CONFIG_OF_I2C) += of_i2c.o
obj-$(CONFIG_OF_SPI) += of_spi.o
93 changes: 93 additions & 0 deletions trunk/drivers/of/of_spi.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* SPI OF support routines
* Copyright (C) 2008 Secret Lab Technologies Ltd.
*
* Support routines for deriving SPI device attachments from the device
* tree.
*/

#include <linux/of.h>
#include <linux/device.h>
#include <linux/spi/spi.h>
#include <linux/of_spi.h>

/**
* of_register_spi_devices - Register child devices onto the SPI bus
* @master: Pointer to spi_master device
* @np: parent node of SPI device nodes
*
* Registers an spi_device for each child node of 'np' which has a 'reg'
* property.
*/
void of_register_spi_devices(struct spi_master *master, struct device_node *np)
{
struct spi_device *spi;
struct device_node *nc;
const u32 *prop;
int rc;
int len;

for_each_child_of_node(np, nc) {
/* Alloc an spi_device */
spi = spi_alloc_device(master);
if (!spi) {
dev_err(&master->dev, "spi_device alloc error for %s\n",
nc->full_name);
spi_dev_put(spi);
continue;
}

/* Select device driver */
if (of_modalias_node(nc, spi->modalias,
sizeof(spi->modalias)) < 0) {
dev_err(&master->dev, "cannot find modalias for %s\n",
nc->full_name);
spi_dev_put(spi);
continue;
}

/* Device address */
prop = of_get_property(nc, "reg", &len);
if (!prop || len < sizeof(*prop)) {
dev_err(&master->dev, "%s has no 'reg' property\n",
nc->full_name);
spi_dev_put(spi);
continue;
}
spi->chip_select = *prop;

/* Mode (clock phase/polarity/etc.) */
if (of_find_property(nc, "spi-cpha", NULL))
spi->mode |= SPI_CPHA;
if (of_find_property(nc, "spi-cpol", NULL))
spi->mode |= SPI_CPOL;

/* Device speed */
prop = of_get_property(nc, "spi-max-frequency", &len);
if (!prop || len < sizeof(*prop)) {
dev_err(&master->dev, "%s has no 'spi-max-frequency' property\n",
nc->full_name);
spi_dev_put(spi);
continue;
}
spi->max_speed_hz = *prop;

/* IRQ */
spi->irq = irq_of_parse_and_map(nc, 0);

/* Store a pointer to the node in the device structure */
of_node_get(nc);
spi->dev.archdata.of_node = nc;

/* Register the new device */
request_module(spi->modalias);
rc = spi_add_device(spi);
if (rc) {
dev_err(&master->dev, "spi_device register error %s\n",
nc->full_name);
spi_dev_put(spi);
}

}
}
EXPORT_SYMBOL(of_register_spi_devices);
18 changes: 18 additions & 0 deletions trunk/include/linux/of_spi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* OpenFirmware SPI support routines
* Copyright (C) 2008 Secret Lab Technologies Ltd.
*
* Support routines for deriving SPI device attachments from the device
* tree.
*/

#ifndef __LINUX_OF_SPI_H
#define __LINUX_OF_SPI_H

#include <linux/of.h>
#include <linux/spi/spi.h>

extern void of_register_spi_devices(struct spi_master *master,
struct device_node *np);

#endif /* __LINUX_OF_SPI */

0 comments on commit b121a4d

Please sign in to comment.