Commit be122abe authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'spi-for-linus' of git://git.secretlab.ca/git/linux-2.6

Pull SPI changes from Grant Likely:
 "Bug fixes and new features for SPI device drivers.  Also move device
  tree support code out of drivers/of and into drivers/spi/spi.c where
  it makes more sense."

* tag 'spi-for-linus' of git://git.secretlab.ca/git/linux-2.6:
  spi: By default setup spi_masters with 1 chipselect and dynamics bus number
  SPI: PRIMA2: use the newest APIs of PINCTRL to fix compiling errors
  spi/spi-fsl-spi: reference correct pdata in fsl_spi_cs_control
  spi: refactor spi-coldfire-qspi to use SPI queue framework.
  spi/omap2-mcspi: convert to the pump message infrastructure
  spi/rspi: add dmaengine support
  spi/topcliff: use correct __devexit_p annotation
  spi: Dont call prepare/unprepare transfer if not populated
  spi/ep93xx: clean probe/remove routines
  spi/devicetree: Move devicetree support code into spi directory
  spi: use module_pci_driver
  spi/omap2-mcspi: Trivial optimisation
  spi: omap2-mcspi: add support for pm_runtime autosuspend
  spi/omap: Remove bus_num usage for instance index
  OMAP : SPI : use devm_* functions
  spi: omap2-mcspi: convert to module_platform_driver
  spi: omap2-mcspi: make it behave as a module
parents b343c8be 1e8a52e1
...@@ -67,12 +67,6 @@ config OF_NET ...@@ -67,12 +67,6 @@ config OF_NET
depends on NETDEVICES depends on NETDEVICES
def_bool y def_bool y
config OF_SPI
def_tristate SPI
depends on SPI && !SPARC
help
OpenFirmware SPI accessors
config OF_MDIO config OF_MDIO
def_tristate PHYLIB def_tristate PHYLIB
depends on PHYLIB depends on PHYLIB
......
...@@ -7,7 +7,6 @@ obj-$(CONFIG_OF_DEVICE) += device.o platform.o ...@@ -7,7 +7,6 @@ obj-$(CONFIG_OF_DEVICE) += device.o platform.o
obj-$(CONFIG_OF_GPIO) += gpio.o obj-$(CONFIG_OF_GPIO) += gpio.o
obj-$(CONFIG_OF_I2C) += of_i2c.o obj-$(CONFIG_OF_I2C) += of_i2c.o
obj-$(CONFIG_OF_NET) += of_net.o obj-$(CONFIG_OF_NET) += of_net.o
obj-$(CONFIG_OF_SPI) += of_spi.o
obj-$(CONFIG_OF_SELFTEST) += selftest.o obj-$(CONFIG_OF_SELFTEST) += selftest.o
obj-$(CONFIG_OF_MDIO) += of_mdio.o obj-$(CONFIG_OF_MDIO) += of_mdio.o
obj-$(CONFIG_OF_PCI) += of_pci.o obj-$(CONFIG_OF_PCI) += of_pci.o
......
/*
* SPI OF support routines
* Copyright (C) 2008 Secret Lab Technologies Ltd.
*
* Support routines for deriving SPI device attachments from the device
* tree.
*/
#include <linux/module.h>
#include <linux/of.h>
#include <linux/device.h>
#include <linux/spi/spi.h>
#include <linux/of_irq.h>
#include <linux/of_spi.h>
/**
* of_register_spi_devices - Register child devices onto the SPI bus
* @master: Pointer to spi_master device
*
* Registers an spi_device for each child node of master node which has a 'reg'
* property.
*/
void of_register_spi_devices(struct spi_master *master)
{
struct spi_device *spi;
struct device_node *nc;
const __be32 *prop;
int rc;
int len;
if (!master->dev.of_node)
return;
for_each_child_of_node(master->dev.of_node, 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 = be32_to_cpup(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;
if (of_find_property(nc, "spi-cs-high", NULL))
spi->mode |= SPI_CS_HIGH;
/* 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 = be32_to_cpup(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.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);
...@@ -216,9 +216,6 @@ static __devinit int ath79_spi_probe(struct platform_device *pdev) ...@@ -216,9 +216,6 @@ static __devinit int ath79_spi_probe(struct platform_device *pdev)
if (pdata) { if (pdata) {
master->bus_num = pdata->bus_num; master->bus_num = pdata->bus_num;
master->num_chipselect = pdata->num_chipselect; master->num_chipselect = pdata->num_chipselect;
} else {
master->bus_num = -1;
master->num_chipselect = 1;
} }
sp->bitbang.master = spi_master_get(master); sp->bitbang.master = spi_master_get(master);
......
...@@ -25,12 +25,12 @@ ...@@ -25,12 +25,12 @@
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/sched.h> #include <linux/sched.h>
#include <linux/workqueue.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/io.h> #include <linux/io.h>
#include <linux/clk.h> #include <linux/clk.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/spi/spi.h> #include <linux/spi/spi.h>
#include <linux/pm_runtime.h>
#include <asm/coldfire.h> #include <asm/coldfire.h>
#include <asm/mcfsim.h> #include <asm/mcfsim.h>
...@@ -78,10 +78,7 @@ struct mcfqspi { ...@@ -78,10 +78,7 @@ struct mcfqspi {
wait_queue_head_t waitq; wait_queue_head_t waitq;
struct work_struct work; struct device *dev;
struct workqueue_struct *workq;
spinlock_t lock;
struct list_head msgq;
}; };
static void mcfqspi_wr_qmr(struct mcfqspi *mcfqspi, u16 val) static void mcfqspi_wr_qmr(struct mcfqspi *mcfqspi, u16 val)
...@@ -303,120 +300,80 @@ static void mcfqspi_transfer_msg16(struct mcfqspi *mcfqspi, unsigned count, ...@@ -303,120 +300,80 @@ static void mcfqspi_transfer_msg16(struct mcfqspi *mcfqspi, unsigned count,
} }
} }
static void mcfqspi_work(struct work_struct *work) static int mcfqspi_transfer_one_message(struct spi_master *master,
struct spi_message *msg)
{ {
struct mcfqspi *mcfqspi = container_of(work, struct mcfqspi, work); struct mcfqspi *mcfqspi = spi_master_get_devdata(master);
unsigned long flags; struct spi_device *spi = msg->spi;
struct spi_transfer *t;
spin_lock_irqsave(&mcfqspi->lock, flags); int status = 0;
while (!list_empty(&mcfqspi->msgq)) {
struct spi_message *msg; list_for_each_entry(t, &msg->transfers, transfer_list) {
struct spi_device *spi; bool cs_high = spi->mode & SPI_CS_HIGH;
struct spi_transfer *xfer; u16 qmr = MCFQSPI_QMR_MSTR;
int status = 0;
if (t->bits_per_word)
msg = container_of(mcfqspi->msgq.next, struct spi_message, qmr |= t->bits_per_word << 10;
queue); else
qmr |= spi->bits_per_word << 10;
list_del_init(&msg->queue); if (spi->mode & SPI_CPHA)
spin_unlock_irqrestore(&mcfqspi->lock, flags); qmr |= MCFQSPI_QMR_CPHA;
if (spi->mode & SPI_CPOL)
spi = msg->spi; qmr |= MCFQSPI_QMR_CPOL;
if (t->speed_hz)
list_for_each_entry(xfer, &msg->transfers, transfer_list) { qmr |= mcfqspi_qmr_baud(t->speed_hz);
bool cs_high = spi->mode & SPI_CS_HIGH; else
u16 qmr = MCFQSPI_QMR_MSTR; qmr |= mcfqspi_qmr_baud(spi->max_speed_hz);
mcfqspi_wr_qmr(mcfqspi, qmr);
if (xfer->bits_per_word)
qmr |= xfer->bits_per_word << 10; mcfqspi_cs_select(mcfqspi, spi->chip_select, cs_high);
else
qmr |= spi->bits_per_word << 10; mcfqspi_wr_qir(mcfqspi, MCFQSPI_QIR_SPIFE);
if (spi->mode & SPI_CPHA) if ((t->bits_per_word ? t->bits_per_word :
qmr |= MCFQSPI_QMR_CPHA; spi->bits_per_word) == 8)
if (spi->mode & SPI_CPOL) mcfqspi_transfer_msg8(mcfqspi, t->len, t->tx_buf,
qmr |= MCFQSPI_QMR_CPOL; t->rx_buf);
if (xfer->speed_hz) else
qmr |= mcfqspi_qmr_baud(xfer->speed_hz); mcfqspi_transfer_msg16(mcfqspi, t->len / 2, t->tx_buf,
else t->rx_buf);
qmr |= mcfqspi_qmr_baud(spi->max_speed_hz); mcfqspi_wr_qir(mcfqspi, 0);
mcfqspi_wr_qmr(mcfqspi, qmr);
if (t->delay_usecs)
mcfqspi_cs_select(mcfqspi, spi->chip_select, cs_high); udelay(t->delay_usecs);
if (t->cs_change) {
mcfqspi_wr_qir(mcfqspi, MCFQSPI_QIR_SPIFE); if (!list_is_last(&t->transfer_list, &msg->transfers))
if ((xfer->bits_per_word ? xfer->bits_per_word : mcfqspi_cs_deselect(mcfqspi, spi->chip_select,
spi->bits_per_word) == 8) cs_high);
mcfqspi_transfer_msg8(mcfqspi, xfer->len, } else {
xfer->tx_buf, if (list_is_last(&t->transfer_list, &msg->transfers))
xfer->rx_buf); mcfqspi_cs_deselect(mcfqspi, spi->chip_select,
else cs_high);
mcfqspi_transfer_msg16(mcfqspi, xfer->len / 2,
xfer->tx_buf,
xfer->rx_buf);
mcfqspi_wr_qir(mcfqspi, 0);
if (xfer->delay_usecs)
udelay(xfer->delay_usecs);
if (xfer->cs_change) {
if (!list_is_last(&xfer->transfer_list,
&msg->transfers))
mcfqspi_cs_deselect(mcfqspi,
spi->chip_select,
cs_high);
} else {
if (list_is_last(&xfer->transfer_list,
&msg->transfers))
mcfqspi_cs_deselect(mcfqspi,
spi->chip_select,
cs_high);
}
msg->actual_length += xfer->len;
} }
msg->status = status; msg->actual_length += t->len;
msg->complete(msg->context);
spin_lock_irqsave(&mcfqspi->lock, flags);
} }
spin_unlock_irqrestore(&mcfqspi->lock, flags); msg->status = status;
spi_finalize_current_message(master);
return status;
} }
static int mcfqspi_transfer(struct spi_device *spi, struct spi_message *msg) static int mcfqspi_prepare_transfer_hw(struct spi_master *master)
{ {
struct mcfqspi *mcfqspi; struct mcfqspi *mcfqspi = spi_master_get_devdata(master);
struct spi_transfer *xfer;
unsigned long flags;
mcfqspi = spi_master_get_devdata(spi->master);
list_for_each_entry(xfer, &msg->transfers, transfer_list) {
if (xfer->bits_per_word && ((xfer->bits_per_word < 8)
|| (xfer->bits_per_word > 16))) {
dev_dbg(&spi->dev,
"%d bits per word is not supported\n",
xfer->bits_per_word);
goto fail;
}
if (xfer->speed_hz) {
u32 real_speed = MCFQSPI_BUSCLK /
mcfqspi_qmr_baud(xfer->speed_hz);
if (real_speed != xfer->speed_hz)
dev_dbg(&spi->dev,
"using speed %d instead of %d\n",
real_speed, xfer->speed_hz);
}
}
msg->status = -EINPROGRESS;
msg->actual_length = 0;
spin_lock_irqsave(&mcfqspi->lock, flags); pm_runtime_get_sync(mcfqspi->dev);
list_add_tail(&msg->queue, &mcfqspi->msgq);
queue_work(mcfqspi->workq, &mcfqspi->work); return 0;
spin_unlock_irqrestore(&mcfqspi->lock, flags); }
static int mcfqspi_unprepare_transfer_hw(struct spi_master *master)
{
struct mcfqspi *mcfqspi = spi_master_get_devdata(master);
pm_runtime_put_sync(mcfqspi->dev);
return 0; return 0;
fail:
msg->status = -EINVAL;
return -EINVAL;
} }
static int mcfqspi_setup(struct spi_device *spi) static int mcfqspi_setup(struct spi_device *spi)
...@@ -502,21 +459,10 @@ static int __devinit mcfqspi_probe(struct platform_device *pdev) ...@@ -502,21 +459,10 @@ static int __devinit mcfqspi_probe(struct platform_device *pdev)
} }
clk_enable(mcfqspi->clk); clk_enable(mcfqspi->clk);
mcfqspi->workq = create_singlethread_workqueue(dev_name(master->dev.parent));
if (!mcfqspi->workq) {
dev_dbg(&pdev->dev, "create_workqueue failed\n");
status = -ENOMEM;
goto fail4;
}
INIT_WORK(&mcfqspi->work, mcfqspi_work);
spin_lock_init(&mcfqspi->lock);
INIT_LIST_HEAD(&mcfqspi->msgq);
init_waitqueue_head(&mcfqspi->waitq);
pdata = pdev->dev.platform_data; pdata = pdev->dev.platform_data;
if (!pdata) { if (!pdata) {
dev_dbg(&pdev->dev, "platform data is missing\n"); dev_dbg(&pdev->dev, "platform data is missing\n");
goto fail5; goto fail4;
} }
master->bus_num = pdata->bus_num; master->bus_num = pdata->bus_num;
master->num_chipselect = pdata->num_chipselect; master->num_chipselect = pdata->num_chipselect;
...@@ -525,28 +471,33 @@ static int __devinit mcfqspi_probe(struct platform_device *pdev) ...@@ -525,28 +471,33 @@ static int __devinit mcfqspi_probe(struct platform_device *pdev)
status = mcfqspi_cs_setup(mcfqspi); status = mcfqspi_cs_setup(mcfqspi);
if (status) { if (status) {
dev_dbg(&pdev->dev, "error initializing cs_control\n"); dev_dbg(&pdev->dev, "error initializing cs_control\n");
goto fail5; goto fail4;
} }
init_waitqueue_head(&mcfqspi->waitq);
mcfqspi->dev = &pdev->dev;
master->mode_bits = SPI_CS_HIGH | SPI_CPOL | SPI_CPHA; master->mode_bits = SPI_CS_HIGH | SPI_CPOL | SPI_CPHA;
master->setup = mcfqspi_setup; master->setup = mcfqspi_setup;
master->transfer = mcfqspi_transfer; master->transfer_one_message = mcfqspi_transfer_one_message;
master->prepare_transfer_hardware = mcfqspi_prepare_transfer_hw;
master->unprepare_transfer_hardware = mcfqspi_unprepare_transfer_hw;
platform_set_drvdata(pdev, master); platform_set_drvdata(pdev, master);
status = spi_register_master(master); status = spi_register_master(master);
if (status) { if (status) {
dev_dbg(&pdev->dev, "spi_register_master failed\n"); dev_dbg(&pdev->dev, "spi_register_master failed\n");
goto fail6; goto fail5;
} }
pm_runtime_enable(mcfqspi->dev);
dev_info(&pdev->dev, "Coldfire QSPI bus driver\n"); dev_info(&pdev->dev, "Coldfire QSPI bus driver\n");
return 0; return 0;
fail6:
mcfqspi_cs_teardown(mcfqspi);
fail5: fail5:
destroy_workqueue(mcfqspi->workq); mcfqspi_cs_teardown(mcfqspi);
fail4: fail4:
clk_disable(mcfqspi->clk); clk_disable(mcfqspi->clk);
clk_put(mcfqspi->clk); clk_put(mcfqspi->clk);
...@@ -570,12 +521,12 @@ static int __devexit mcfqspi_remove(struct platform_device *pdev) ...@@ -570,12 +521,12 @@ static int __devexit mcfqspi_remove(struct platform_device *pdev)
struct mcfqspi *mcfqspi = spi_master_get_devdata(master); struct mcfqspi *mcfqspi = spi_master_get_devdata(master);
struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0); struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
pm_runtime_disable(mcfqspi->dev);
/* disable the hardware (set the baud rate to 0) */ /* disable the hardware (set the baud rate to 0) */
mcfqspi_wr_qmr(mcfqspi, MCFQSPI_QMR_MSTR); mcfqspi_wr_qmr(mcfqspi, MCFQSPI_QMR_MSTR);
platform_set_drvdata(pdev, NULL); platform_set_drvdata(pdev, NULL);
mcfqspi_cs_teardown(mcfqspi); mcfqspi_cs_teardown(mcfqspi);
destroy_workqueue(mcfqspi->workq);
clk_disable(mcfqspi->clk); clk_disable(mcfqspi->clk);
clk_put(mcfqspi->clk); clk_put(mcfqspi->clk);
free_irq(mcfqspi->irq, mcfqspi); free_irq(mcfqspi->irq, mcfqspi);
...@@ -587,11 +538,13 @@ static int __devexit mcfqspi_remove(struct platform_device *pdev) ...@@ -587,11 +538,13 @@ static int __devexit mcfqspi_remove(struct platform_device *pdev)
return 0; return 0;
} }
#ifdef CONFIG_PM #ifdef CONFIG_PM_SLEEP
static int mcfqspi_suspend(struct device *dev) static int mcfqspi_suspend(struct device *dev)
{ {
struct mcfqspi *mcfqspi = platform_get_drvdata(to_platform_device(dev)); struct spi_master *master = spi_master_get(dev_get_drvdata(dev));
struct mcfqspi *mcfqspi = spi_master_get_devdata(master);
spi_master_suspend(master);
clk_disable(mcfqspi->clk); clk_disable(mcfqspi->clk);
...@@ -600,27 +553,47 @@ static int mcfqspi_suspend(struct device *dev) ...@@ -600,27 +553,47 @@ static int mcfqspi_suspend(struct device *dev)
static int mcfqspi_resume(struct device *dev) static int mcfqspi_resume(struct device *dev)
{ {
struct mcfqspi *mcfqspi = platform_get_drvdata(to_platform_device(dev)); struct spi_master *master = spi_master_get(dev_get_drvdata(dev));
struct mcfqspi *mcfqspi = spi_master_get_devdata(master);
spi_master_resume(master);
clk_enable(mcfqspi->clk); clk_enable(mcfqspi->clk);
return 0; return 0;
} }
#endif
static struct dev_pm_ops mcfqspi_dev_pm_ops = { #ifdef CONFIG_PM_RUNTIME
.suspend = mcfqspi_suspend, static int mcfqspi_runtime_suspend(struct device *dev)
.resume = mcfqspi_resume, {
}; struct mcfqspi *mcfqspi = platform_get_drvdata(to_platform_device(dev));
#define MCFQSPI_DEV_PM_OPS (&mcfqspi_dev_pm_ops) clk_disable(mcfqspi->clk);
#else
#define MCFQSPI_DEV_PM_OPS NULL return 0;
}
static int mcfqspi_runtime_resume(struct device *dev)
{
struct mcfqspi *mcfqspi = platform_get_drvdata(to_platform_device(dev));
clk_enable(mcfqspi->clk);
return 0;
}
#endif #endif
static const struct dev_pm_ops mcfqspi_pm = {
SET_SYSTEM_SLEEP_PM_OPS(mcfqspi_suspend, mcfqspi_resume)
SET_RUNTIME_PM_OPS(mcfqspi_runtime_suspend, mcfqspi_runtime_resume,
NULL)
};
static struct platform_driver mcfqspi_driver = { static struct platform_driver mcfqspi_driver = {
.driver.name = DRIVER_NAME, .driver.name = DRIVER_NAME,
.driver.owner = THIS_MODULE, .driver.owner = THIS_MODULE,
.driver.pm = MCFQSPI_DEV_PM_OPS, .driver.pm = &mcfqspi_pm,
.probe = mcfqspi_probe, .probe = mcfqspi_probe,
.remove = __devexit_p(mcfqspi_remove), .remove = __devexit_p(mcfqspi_remove),
}; };
......
...@@ -164,18 +164,7 @@ static struct pci_driver dw_spi_driver = { ...@@ -164,18 +164,7 @@ static struct pci_driver dw_spi_driver = {
.resume = spi_resume, .resume = spi_resume,
}; };
static int __init mrst_spi_init(void) module_pci_driver(dw_spi_driver);
{
return pci_register_driver(&dw_spi_driver);
}
static void __exit mrst_spi_exit(void)
{
pci_unregister_driver(&dw_spi_driver);
}
module_init(mrst_spi_init);
module_exit(mrst_spi_exit);
MODULE_AUTHOR("Feng Tang <feng.tang@intel.com>"); MODULE_AUTHOR("Feng Tang <feng.tang@intel.com>");
MODULE_DESCRIPTION("PCI interface driver for DW SPI Core"); MODULE_DESCRIPTION("PCI interface driver for DW SPI Core");
......
...@@ -76,7 +76,6 @@ ...@@ -76,7 +76,6 @@
* @clk: clock for the controller * @clk: clock for the controller
* @regs_base: pointer to ioremap()'d registers * @regs_base: pointer to ioremap()'d registers
* @sspdr_phys: physical address of the SSPDR register * @sspdr_phys: physical address of the SSPDR register
* @irq: IRQ number used by the driver
* @min_rate: minimum clock rate (in Hz) supported by the controller * @min_rate: minimum clock rate (in Hz) supported by the controller
* @max_rate: maximum clock rate (in Hz) supported by the controller * @max_rate: maximum clock rate (in Hz) supported by the controller
* @running: is the queue running * @running: is the queue running
...@@ -114,7 +113,6 @@ struct ep93xx_spi { ...@@ -114,7 +113,6 @@ struct ep93xx_spi {
struct clk *clk; struct clk *clk;
void __iomem *regs_base; void __iomem *regs_base;
unsigned long sspdr_phys; unsigned long sspdr_phys;
int irq;
unsigned long min_rate; unsigned long min_rate;
unsigned long max_rate; unsigned long max_rate;
bool running; bool running;
...@@ -1031,6 +1029,7 @@ static int __devinit ep93xx_spi_probe(struct platform_device *pdev) ...@@ -1031,6 +1029,7 @@ static int __devinit ep93xx_spi_probe(struct platform_device *pdev)
struct ep93xx_spi_info *info; struct ep93xx_spi_info *info;
struct ep93xx_spi *espi; struct ep93xx_spi *espi;
struct resource *res; struct resource *res;
int irq;
int error; int error;
info = pdev->dev.platform_data; info = pdev->dev.platform_data;
...@@ -1070,8 +1069,8 @@ static int __devinit ep93xx_spi_probe(struct platform_device *pdev) ...@@ -1070,8 +1069,8 @@ static int __devinit ep93xx_spi_probe(struct platform_device *pdev)
espi->min_rate = clk_get_rate(espi->clk) / (254 * 256); espi->min_rate = clk_get_rate(espi->clk) / (254 * 256);
espi->pdev = pdev; espi->pdev = pdev;
espi->irq = platform_get_irq(pdev, 0); irq = platform_get_irq(pdev, 0);
if (espi->irq < 0) { if (irq < 0) {
error = -EBUSY; error = -EBUSY;
dev_err(&pdev->dev, "failed to get irq resources\n"); dev_err(&pdev->dev, "failed to get irq resources\n");
goto fail_put_clock; goto fail_put_clock;
...@@ -1084,26 +1083,20 @@ static int __devinit ep93xx_spi_probe(struct platform_device *pdev) ...@@ -1084,26 +1083,20 @@ static int __devinit ep93xx_spi_probe(struct platform_device *pdev)
goto fail_put_clock; goto fail_put_clock;
} }
res = request_mem_region(res->start, resource_size(res), pdev->name);
if (!res) {
dev_err(&pdev->dev, "unable to request iomem resources\n");
error = -EBUSY;
goto fail_put_clock;
}
espi->sspdr_phys = res->start + SSPDR; espi->sspdr_phys = res->start + SSPDR;
espi->regs_base = ioremap(res->start, resource_size(res));
espi->regs_base = devm_request_and_ioremap(&pdev->dev, res);
if (!espi->regs_base) { if (!espi->regs_base) {
dev_err(&pdev->dev, "failed to map resources\n"); dev_err(&pdev->dev, "failed to map resources\n");
error = -ENODEV; error = -ENODEV;
goto fail_free_mem; goto fail_put_clock;
} }
error = request_irq(espi->irq, ep93xx_spi_interrupt, 0, error = devm_request_irq(&pdev->dev, irq, ep93xx_spi_interrupt,
"ep93xx-spi", espi); 0, "ep93xx-spi", espi);
if (error) { if (error) {
dev_err(&pdev->dev, "failed to request irq\n"); dev_err(&pdev->dev, "failed to request irq\n");
goto fail_unmap_regs; goto fail_put_clock;
} }
if (info->use_dma && ep93xx_spi_setup_dma(espi)) if (info->use_dma && ep93xx_spi_setup_dma(espi))
...@@ -1128,7 +1121,7 @@ static int __devinit ep93xx_spi_probe(struct platform_device *pdev) ...@@ -1128,7 +1121,7 @@ static int __devinit ep93xx_spi_probe(struct platform_device *pdev)
} }
dev_info(&pdev->dev, "EP93xx SPI Controller at 0x%08lx irq %d\n", dev_info(&pdev->dev, "EP93xx SPI Controller at 0x%08lx irq %d\n",
(unsigned long)res->start, espi->irq); (unsigned long)res->start, irq);
return 0; return 0;
...@@ -1136,11 +1129,6 @@ static int __devinit ep93xx_spi_probe(struct platform_device *pdev) ...@@ -1136,11 +1129,6 @@ static int __devinit ep93xx_spi_probe(struct platform_device *pdev)
destroy_workqueue(espi->wq); destroy_workqueue(espi->wq);
fail_free_dma: fail_free_dma:
ep93xx_spi_release_dma(espi); ep93xx_spi_release_dma(espi);
free_irq(espi->irq, espi);
fail_unmap_regs:
iounmap(espi->regs_base);
fail_free_mem:
release_mem_region(res->start, resource_size(res));
fail_put_clock: fail_put_clock:
clk_put(espi->clk); clk_put(espi->clk);
fail_release_master: fail_release_master:
...@@ -1154,7 +1142,6 @@ static int __devexit ep93xx_spi_remove(struct platform_device *pdev) ...@@ -1154,7 +1142,6 @@ static int __devexit ep93xx_spi_remove(struct platform_device *pdev)
{ {
struct spi_master *master = platform_get_drvdata(pdev); struct spi_master *master = platform_get_drvdata(pdev);
struct ep93xx_spi *espi = spi_master_get_devdata(master); struct ep93xx_spi *espi = spi_master_get_devdata(master);
struct resource *res;
spin_lock_irq(&espi->lock); spin_lock_irq(&espi->lock);
espi->running = false; espi->running = false;
...@@ -1180,10 +1167,6 @@ static int __devexit ep93xx_spi_remove(struct platform_device *pdev) ...@@ -1180,10 +1167,6 @@ static int __devexit ep93xx_spi_remove(struct platform_device *pdev)
spin_unlock_irq(&espi->lock); spin_unlock_irq(&espi->lock);
ep93xx_spi_release_dma(espi); ep93xx_spi_release_dma(espi);
free_irq(espi->irq, espi);
iounmap(espi->regs_base);
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
release_mem_region(res->start, resource_size(res));
clk_put(espi->clk); clk_put(espi->clk);
platform_set_drvdata(pdev, NULL); platform_set_drvdata(pdev, NULL);
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
#include <linux/mm.h> #include <linux/mm.h>
#include <linux/of.h> #include <linux/of.h>
#include <linux/of_platform.h> #include <linux/of_platform.h>
#include <linux/of_spi.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/err.h> #include <linux/err.h>
#include <sysdev/fsl_soc.h> #include <sysdev/fsl_soc.h>
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
#include <linux/dma-mapping.h> #include <linux/dma-mapping.h>
#include <linux/mm.h> #include <linux/mm.h>
#include <linux/of_platform.h> #include <linux/of_platform.h>
#include <linux/of_spi.h> #include <linux/spi/spi.h>
#include <sysdev/fsl_soc.h> #include <sysdev/fsl_soc.h>
#include "spi-fsl-lib.h" #include "spi-fsl-lib.h"
......
...@@ -933,7 +933,7 @@ static struct spi_master * __devinit fsl_spi_probe(struct device *dev, ...@@ -933,7 +933,7 @@ static struct spi_master * __devinit fsl_spi_probe(struct device *dev,
static void fsl_spi_cs_control(struct spi_device *spi, bool on) static void fsl_spi_cs_control(struct spi_device *spi, bool on)
{ {
struct device *dev = spi->dev.parent; struct device *dev = spi->dev.parent->parent;
struct mpc8xxx_spi_probe_info *pinfo = to_of_pinfo(dev->platform_data); struct mpc8xxx_spi_probe_info *pinfo = to_of_pinfo(dev->platform_data);
u16 cs = spi->chip_select; u16 cs = spi->chip_select;
int gpio = pinfo->gpios[cs]; int gpio = pinfo->gpios[cs];
......
...@@ -219,9 +219,6 @@ static void spi_lm70llp_attach(struct parport *p) ...@@ -219,9 +219,6 @@ static void spi_lm70llp_attach(struct parport *p)
} }
pp = spi_master_get_devdata(master); pp = spi_master_get_devdata(master);
master->bus_num = -1; /* dynamic alloc of a bus number */
master->num_chipselect = 1;
/* /*
* SPI and bitbang hookup. * SPI and bitbang hookup.
*/ */
......
...@@ -433,7 +433,6 @@ static int __devinit mpc52xx_spi_probe(struct platform_device *op) ...@@ -433,7 +433,6 @@ static int __devinit mpc52xx_spi_probe(struct platform_device *op)
goto err_alloc; goto err_alloc;
} }
master->bus_num = -1;
master->setup = mpc52xx_spi_setup; master->setup = mpc52xx_spi_setup;
master->transfer = mpc52xx_spi_transfer; master->transfer = mpc52xx_spi_transfer;
master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LSB_FIRST; master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LSB_FIRST;
...@@ -479,8 +478,6 @@ static int __devinit mpc52xx_spi_probe(struct platform_device *op) ...@@ -479,8 +478,6 @@ static int __devinit mpc52xx_spi_probe(struct platform_device *op)
gpio_direction_output(gpio_cs, 1); gpio_direction_output(gpio_cs, 1);
ms->gpio_cs[i] = gpio_cs; ms->gpio_cs[i] = gpio_cs;
} }
} else {
master->num_chipselect = 1;
} }
spin_lock_init(&ms->lock); spin_lock_init(&ms->lock);
......
This diff is collapsed.
...@@ -30,7 +30,6 @@ ...@@ -30,7 +30,6 @@
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/wait.h> #include <linux/wait.h>
#include <linux/of_platform.h> #include <linux/of_platform.h>
#include <linux/of_spi.h>
#include <linux/of_gpio.h> #include <linux/of_gpio.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/delay.h> #include <linux/delay.h>
...@@ -467,9 +466,6 @@ static int __init spi_ppc4xx_of_probe(struct platform_device *op) ...@@ -467,9 +466,6 @@ static int __init spi_ppc4xx_of_probe(struct platform_device *op)
bbp->master->setup = spi_ppc4xx_setup; bbp->master->setup = spi_ppc4xx_setup;
bbp->master->cleanup = spi_ppc4xx_cleanup; bbp->master->cleanup = spi_ppc4xx_cleanup;
/* Allocate bus num dynamically. */
bbp->master->bus_num = -1;
/* the spi->mode bits understood by this driver: */ /* the spi->mode bits understood by this driver: */
bbp->master->mode_bits = bbp->master->mode_bits =
SPI_CPHA | SPI_CPOL | SPI_CS_HIGH | SPI_LSB_FIRST; SPI_CPHA | SPI_CPOL | SPI_CS_HIGH | SPI_LSB_FIRST;
......
...@@ -164,17 +164,7 @@ static struct pci_driver ce4100_spi_driver = { ...@@ -164,17 +164,7 @@ static struct pci_driver ce4100_spi_driver = {
.remove = __devexit_p(ce4100_spi_remove), .remove = __devexit_p(ce4100_spi_remove),
}; };
static int __init ce4100_spi_init(void) module_pci_driver(ce4100_spi_driver);
{
return pci_register_driver(&ce4100_spi_driver);
}
module_init(ce4100_spi_init);
static void __exit ce4100_spi_exit(void)
{
pci_unregister_driver(&ce4100_spi_driver);
}
module_exit(ce4100_spi_exit);
MODULE_DESCRIPTION("CE4100 PCI-SPI glue code for PXA's driver"); MODULE_DESCRIPTION("CE4100 PCI-SPI glue code for PXA's driver");
MODULE_LICENSE("GPL v2"); MODULE_LICENSE("GPL v2");
......
...@@ -31,7 +31,11 @@ ...@@ -31,7 +31,11 @@
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/io.h> #include <linux/io.h>
#include <linux/clk.h> #include <linux/clk.h>
#include <linux/dmaengine.h>
#include <linux/dma-mapping.h>
#include <linux/sh_dma.h>
#include <linux/spi/spi.h> #include <linux/spi/spi.h>
#include <linux/spi/rspi.h>
#define RSPI_SPCR 0x00 #define RSPI_SPCR 0x00
#define RSPI_SSLP 0x01 #define RSPI_SSLP 0x01
...@@ -141,6 +145,16 @@ struct rspi_data { ...@@ -141,6 +145,16 @@ struct rspi_data {
spinlock_t lock; spinlock_t lock;
struct clk *clk; struct clk *clk;
unsigned char spsr; unsigned char spsr;
/* for dmaengine */
struct sh_dmae_slave dma_tx;
struct sh_dmae_slave dma_rx;
struct dma_chan *chan_tx;
struct dma_chan *chan_rx;
int irq;
unsigned dma_width_16bit:1;
unsigned dma_callbacked:1;
}; };
static void rspi_write8(struct rspi_data *rspi, u8 data, u16 offset) static void rspi_write8(struct rspi_data *rspi, u8 data, u16 offset)
...@@ -265,11 +279,125 @@ static int rspi_send_pio(struct rspi_data *rspi, struct spi_message *mesg, ...@@ -265,11 +279,125 @@ static int rspi_send_pio(struct rspi_data *rspi, struct spi_message *mesg,
return 0; return 0;
} }
static int rspi_receive_pio(struct rspi_data *rspi, struct spi_message *mesg, static void rspi_dma_complete(void *arg)
struct spi_transfer *t) {
struct rspi_data *rspi = arg;
rspi->dma_callbacked = 1;
wake_up_interruptible(&rspi->wait);
}
static int rspi_dma_map_sg(struct scatterlist *sg, void *buf, unsigned len,
struct dma_chan *chan,
enum dma_transfer_direction dir)
{
sg_init_table(sg, 1);
sg_set_buf(sg, buf, len);
sg_dma_len(sg) = len;
return dma_map_sg(chan->device->dev, sg, 1, dir);
}
static void rspi_dma_unmap_sg(struct scatterlist *sg, struct dma_chan *chan,
enum dma_transfer_direction dir)
{
dma_unmap_sg(chan->device->dev, sg, 1, dir);
}
static void rspi_memory_to_8bit(void *buf, const void *data, unsigned len)
{
u16 *dst = buf;
const u8 *src = data;
while (len) {
*dst++ = (u16)(*src++);
len--;
}
}
static void rspi_memory_from_8bit(void *buf, const void *data, unsigned len)
{
u8 *dst = buf;
const u16 *src = data;
while (len) {
*dst++ = (u8)*src++;
len--;
}
}
static int rspi_send_dma(struct rspi_data *rspi, struct spi_transfer *t)
{
struct scatterlist sg;
void *buf = NULL;
struct dma_async_tx_descriptor *desc;
unsigned len;
int ret = 0;
if (rspi->dma_width_16bit) {
/*
* If DMAC bus width is 16-bit, the driver allocates a dummy
* buffer. And, the driver converts original data into the
* DMAC data as the following format:
* original data: 1st byte, 2nd byte ...
* DMAC data: 1st byte, dummy, 2nd byte, dummy ...
*/
len = t->len * 2;
buf = kmalloc(len, GFP_KERNEL);
if (!buf)
return -ENOMEM;
rspi_memory_to_8bit(buf, t->tx_buf, t->len);
} else {
len = t->len;
buf = (void *)t->tx_buf;
}
if (!rspi_dma_map_sg(&sg, buf, len, rspi->chan_tx, DMA_TO_DEVICE)) {
ret = -EFAULT;
goto end_nomap;
}
desc = dmaengine_prep_slave_sg(rspi->chan_tx, &sg, 1, DMA_TO_DEVICE,
DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
if (!desc) {
ret = -EIO;
goto end;
}
/*
* DMAC needs SPTIE, but if SPTIE is set, this IRQ routine will be
* called. So, this driver disables the IRQ while DMA transfer.
*/
disable_irq(rspi->irq);
rspi_write8(rspi, rspi_read8(rspi, RSPI_SPCR) | SPCR_TXMD, RSPI_SPCR);
rspi_enable_irq(rspi, SPCR_SPTIE);
rspi->dma_callbacked = 0;
desc->callback = rspi_dma_complete;
desc->callback_param = rspi;
dmaengine_submit(desc);
dma_async_issue_pending(rspi->chan_tx);
ret = wait_event_interruptible_timeout(rspi->wait,
rspi->dma_callbacked, HZ);
if (ret > 0 && rspi->dma_callbacked)
ret = 0;
else if (!ret)
ret = -ETIMEDOUT;
rspi_disable_irq(rspi, SPCR_SPTIE);
enable_irq(rspi->irq);
end:
rspi_dma_unmap_sg(&sg, rspi->chan_tx, DMA_TO_DEVICE);
end_nomap:
if (rspi->dma_width_16bit)
kfree(buf);
return ret;
}
static void rspi_receive_init(struct rspi_data *rspi)
{ {
int remain = t->len;
u8 *data;
unsigned char spsr; unsigned char spsr;
spsr = rspi_read8(rspi, RSPI_SPSR); spsr = rspi_read8(rspi, RSPI_SPSR);
...@@ -278,6 +406,15 @@ static int rspi_receive_pio(struct rspi_data *rspi, struct spi_message *mesg, ...@@ -278,6 +406,15 @@ static int rspi_receive_pio(struct rspi_data *rspi, struct spi_message *mesg,
if (spsr & SPSR_OVRF) if (spsr & SPSR_OVRF)
rspi_write8(rspi, rspi_read8(rspi, RSPI_SPSR) & ~SPSR_OVRF, rspi_write8(rspi, rspi_read8(rspi, RSPI_SPSR) & ~SPSR_OVRF,
RSPI_SPCR); RSPI_SPCR);
}
static int rspi_receive_pio(struct rspi_data *rspi, struct spi_message *mesg,
struct spi_transfer *t)
{
int remain = t->len;
u8 *data;
rspi_receive_init(rspi);
data = (u8 *)t->rx_buf; data = (u8 *)t->rx_buf;
while (remain > 0) { while (remain > 0) {
...@@ -307,6 +444,120 @@ static int rspi_receive_pio(struct rspi_data *rspi, struct spi_message *mesg, ...@@ -307,6 +444,120 @@ static int rspi_receive_pio(struct rspi_data *rspi, struct spi_message *mesg,
return 0; return 0;
} }
static int rspi_receive_dma(struct rspi_data *rspi, struct spi_transfer *t)
{
struct scatterlist sg, sg_dummy;
void *dummy = NULL, *rx_buf = NULL;
struct dma_async_tx_descriptor *desc, *desc_dummy;
unsigned len;
int ret = 0;
if (rspi->dma_width_16bit) {
/*
* If DMAC bus width is 16-bit, the driver allocates a dummy
* buffer. And, finally the driver converts the DMAC data into
* actual data as the following format:
* DMAC data: 1st byte, dummy, 2nd byte, dummy ...
* actual data: 1st byte, 2nd byte ...
*/
len = t->len * 2;
rx_buf = kmalloc(len, GFP_KERNEL);
if (!rx_buf)
return -ENOMEM;
} else {
len = t->len;
rx_buf = t->rx_buf;
}
/* prepare dummy transfer to generate SPI clocks */
dummy = kzalloc(len, GFP_KERNEL);
if (!dummy) {
ret = -ENOMEM;
goto end_nomap;
}
if (!rspi_dma_map_sg(&sg_dummy, dummy, len, rspi->chan_tx,
DMA_TO_DEVICE)) {
ret = -EFAULT;
goto end_nomap;
}
desc_dummy = dmaengine_prep_slave_sg(rspi->chan_tx, &sg_dummy, 1,
DMA_TO_DEVICE, DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
if (!desc_dummy) {
ret = -EIO;
goto end_dummy_mapped;
}
/* prepare receive transfer */
if (!rspi_dma_map_sg(&sg, rx_buf, len, rspi->chan_rx,
DMA_FROM_DEVICE)) {
ret = -EFAULT;
goto end_dummy_mapped;
}
desc = dmaengine_prep_slave_sg(rspi->chan_rx, &sg, 1, DMA_FROM_DEVICE,
DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
if (!desc) {
ret = -EIO;
goto end;
}
rspi_receive_init(rspi);
/*
* DMAC needs SPTIE, but if SPTIE is set, this IRQ routine will be
* called. So, this driver disables the IRQ while DMA transfer.
*/
disable_irq(rspi->irq);
rspi_write8(rspi, rspi_read8(rspi, RSPI_SPCR) & ~SPCR_TXMD, RSPI_SPCR);
rspi_enable_irq(rspi, SPCR_SPTIE | SPCR_SPRIE);
rspi->dma_callbacked = 0;
desc->callback = rspi_dma_complete;
desc->callback_param = rspi;
dmaengine_submit(desc);
dma_async_issue_pending(rspi->chan_rx);
desc_dummy->callback = NULL; /* No callback */
dmaengine_submit(desc_dummy);
dma_async_issue_pending(rspi->chan_tx);
ret = wait_event_interruptible_timeout(rspi->wait,
rspi->dma_callbacked, HZ);
if (ret > 0 && rspi->dma_callbacked)
ret = 0;
else if (!ret)
ret = -ETIMEDOUT;
rspi_disable_irq(rspi, SPCR_SPTIE | SPCR_SPRIE);
enable_irq(rspi->irq);
end:
rspi_dma_unmap_sg(&sg, rspi->chan_rx, DMA_FROM_DEVICE);
end_dummy_mapped:
rspi_dma_unmap_sg(&sg_dummy, rspi->chan_tx, DMA_TO_DEVICE);
end_nomap:
if (rspi->dma_width_16bit) {
if (!ret)
rspi_memory_from_8bit(t->rx_buf, rx_buf, t->len);
kfree(rx_buf);
}
kfree(dummy);
return ret;
}
static int rspi_is_dma(struct rspi_data *rspi, struct spi_transfer *t)
{
if (t->tx_buf && rspi->chan_tx)
return 1;
/* If the module receives data by DMAC, it also needs TX DMAC */
if (t->rx_buf && rspi->chan_tx && rspi->chan_rx)
return 1;
return 0;
}
static void rspi_work(struct work_struct *work) static void rspi_work(struct work_struct *work)
{ {
struct rspi_data *rspi = container_of(work, struct rspi_data, ws); struct rspi_data *rspi = container_of(work, struct rspi_data, ws);
...@@ -325,12 +576,18 @@ static void rspi_work(struct work_struct *work) ...@@ -325,12 +576,18 @@ static void rspi_work(struct work_struct *work)
list_for_each_entry(t, &mesg->transfers, transfer_list) { list_for_each_entry(t, &mesg->transfers, transfer_list) {
if (t->tx_buf) { if (t->tx_buf) {
ret = rspi_send_pio(rspi, mesg, t); if (rspi_is_dma(rspi, t))
ret = rspi_send_dma(rspi, t);
else
ret = rspi_send_pio(rspi, mesg, t);
if (ret < 0) if (ret < 0)
goto error; goto error;
} }
if (t->rx_buf) { if (t->rx_buf) {
ret = rspi_receive_pio(rspi, mesg, t); if (rspi_is_dma(rspi, t))
ret = rspi_receive_dma(rspi, t);
else
ret = rspi_receive_pio(rspi, mesg, t);
if (ret < 0) if (ret < 0)
goto error; goto error;
} }
...@@ -406,11 +663,58 @@ static irqreturn_t rspi_irq(int irq, void *_sr) ...@@ -406,11 +663,58 @@ static irqreturn_t rspi_irq(int irq, void *_sr)
return ret; return ret;
} }
static bool rspi_filter(struct dma_chan *chan, void *filter_param)
{
chan->private = filter_param;
return true;
}
static void __devinit rspi_request_dma(struct rspi_data *rspi,
struct platform_device *pdev)
{
struct rspi_plat_data *rspi_pd = pdev->dev.platform_data;
dma_cap_mask_t mask;
if (!rspi_pd)
return;
rspi->dma_width_16bit = rspi_pd->dma_width_16bit;
/* If the module receives data by DMAC, it also needs TX DMAC */
if (rspi_pd->dma_rx_id && rspi_pd->dma_tx_id) {
dma_cap_zero(mask);
dma_cap_set(DMA_SLAVE, mask);
rspi->dma_rx.slave_id = rspi_pd->dma_rx_id;
rspi->chan_rx = dma_request_channel(mask, rspi_filter,
&rspi->dma_rx);
if (rspi->chan_rx)
dev_info(&pdev->dev, "Use DMA when rx.\n");
}
if (rspi_pd->dma_tx_id) {
dma_cap_zero(mask);
dma_cap_set(DMA_SLAVE, mask);
rspi->dma_tx.slave_id = rspi_pd->dma_tx_id;
rspi->chan_tx = dma_request_channel(mask, rspi_filter,
&rspi->dma_tx);
if (rspi->chan_tx)
dev_info(&pdev->dev, "Use DMA when tx\n");
}
}
static void __devexit rspi_release_dma(struct rspi_data *rspi)
{
if (rspi->chan_tx)
dma_release_channel(rspi->chan_tx);
if (rspi->chan_rx)
dma_release_channel(rspi->chan_rx);
}
static int __devexit rspi_remove(struct platform_device *pdev) static int __devexit rspi_remove(struct platform_device *pdev)
{ {
struct rspi_data *rspi = dev_get_drvdata(&pdev->dev); struct rspi_data *rspi = dev_get_drvdata(&pdev->dev);
spi_unregister_master(rspi->master); spi_unregister_master(rspi->master);
rspi_release_dma(rspi);
free_irq(platform_get_irq(pdev, 0), rspi); free_irq(platform_get_irq(pdev, 0), rspi);
clk_put(rspi->clk); clk_put(rspi->clk);
iounmap(rspi->addr); iounmap(rspi->addr);
...@@ -483,6 +787,9 @@ static int __devinit rspi_probe(struct platform_device *pdev) ...@@ -483,6 +787,9 @@ static int __devinit rspi_probe(struct platform_device *pdev)
goto error3; goto error3;
} }
rspi->irq = irq;
rspi_request_dma(rspi, pdev);
ret = spi_register_master(master); ret = spi_register_master(master);
if (ret < 0) { if (ret < 0) {
dev_err(&pdev->dev, "spi_register_master error.\n"); dev_err(&pdev->dev, "spi_register_master error.\n");
...@@ -494,6 +801,7 @@ static int __devinit rspi_probe(struct platform_device *pdev) ...@@ -494,6 +801,7 @@ static int __devinit rspi_probe(struct platform_device *pdev)
return 0; return 0;
error4: error4:
rspi_release_dma(rspi);
free_irq(irq, rspi); free_irq(irq, rspi);
error3: error3:
clk_put(rspi->clk); clk_put(rspi->clk);
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
#include <linux/of_gpio.h> #include <linux/of_gpio.h>
#include <linux/spi/spi.h> #include <linux/spi/spi.h>
#include <linux/spi/spi_bitbang.h> #include <linux/spi/spi_bitbang.h>
#include <linux/pinctrl/pinmux.h> #include <linux/pinctrl/consumer.h>
#define DRIVER_NAME "sirfsoc_spi" #define DRIVER_NAME "sirfsoc_spi"
...@@ -127,7 +127,7 @@ struct sirfsoc_spi { ...@@ -127,7 +127,7 @@ struct sirfsoc_spi {
void __iomem *base; void __iomem *base;
u32 ctrl_freq; /* SPI controller clock speed */ u32 ctrl_freq; /* SPI controller clock speed */
struct clk *clk; struct clk *clk;
struct pinmux *pmx; struct pinctrl *p;
/* rx & tx bufs from the spi_transfer */ /* rx & tx bufs from the spi_transfer */
const void *tx; const void *tx;
...@@ -560,17 +560,15 @@ static int __devinit spi_sirfsoc_probe(struct platform_device *pdev) ...@@ -560,17 +560,15 @@ static int __devinit spi_sirfsoc_probe(struct platform_device *pdev)
master->bus_num = pdev->id; master->bus_num = pdev->id;
sspi->bitbang.master->dev.of_node = pdev->dev.of_node; sspi->bitbang.master->dev.of_node = pdev->dev.of_node;
sspi->pmx = pinmux_get(&pdev->dev, NULL); sspi->p = pinctrl_get_select_default(&pdev->dev);
ret = IS_ERR(sspi->pmx); ret = IS_ERR(sspi->p);
if (ret) if (ret)
goto free_master; goto free_master;
pinmux_enable(sspi->pmx);
sspi->clk = clk_get(&pdev->dev, NULL); sspi->clk = clk_get(&pdev->dev, NULL);
if (IS_ERR(sspi->clk)) { if (IS_ERR(sspi->clk)) {
ret = -EINVAL; ret = -EINVAL;
goto free_pmx; goto free_pin;
} }
clk_enable(sspi->clk); clk_enable(sspi->clk);
sspi->ctrl_freq = clk_get_rate(sspi->clk); sspi->ctrl_freq = clk_get_rate(sspi->clk);
...@@ -598,9 +596,8 @@ static int __devinit spi_sirfsoc_probe(struct platform_device *pdev) ...@@ -598,9 +596,8 @@ static int __devinit spi_sirfsoc_probe(struct platform_device *pdev)
free_clk: free_clk:
clk_disable(sspi->clk); clk_disable(sspi->clk);
clk_put(sspi->clk); clk_put(sspi->clk);
free_pmx: free_pin:
pinmux_disable(sspi->pmx); pinctrl_put(sspi->p);
pinmux_put(sspi->pmx);
free_master: free_master:
spi_master_put(master); spi_master_put(master);
err_cs: err_cs:
...@@ -623,8 +620,7 @@ static int __devexit spi_sirfsoc_remove(struct platform_device *pdev) ...@@ -623,8 +620,7 @@ static int __devexit spi_sirfsoc_remove(struct platform_device *pdev)
} }
clk_disable(sspi->clk); clk_disable(sspi->clk);
clk_put(sspi->clk); clk_put(sspi->clk);
pinmux_disable(sspi->pmx); pinctrl_put(sspi->p);
pinmux_put(sspi->pmx);
spi_master_put(master); spi_master_put(master);
return 0; return 0;
} }
......
...@@ -1438,7 +1438,6 @@ static int __devinit pch_spi_pd_probe(struct platform_device *plat_dev) ...@@ -1438,7 +1438,6 @@ static int __devinit pch_spi_pd_probe(struct platform_device *plat_dev)
plat_dev->id, data->io_remap_addr); plat_dev->id, data->io_remap_addr);
/* initialize members of SPI master */ /* initialize members of SPI master */
master->bus_num = -1;
master->num_chipselect = PCH_MAX_CS; master->num_chipselect = PCH_MAX_CS;
master->setup = pch_spi_setup; master->setup = pch_spi_setup;
master->transfer = pch_spi_transfer; master->transfer = pch_spi_transfer;
...@@ -1779,7 +1778,7 @@ static struct pci_driver pch_spi_pcidev_driver = { ...@@ -1779,7 +1778,7 @@ static struct pci_driver pch_spi_pcidev_driver = {
.name = "pch_spi", .name = "pch_spi",
.id_table = pch_spi_pcidev_id, .id_table = pch_spi_pcidev_id,
.probe = pch_spi_probe, .probe = pch_spi_probe,
.remove = pch_spi_remove, .remove = __devexit_p(pch_spi_remove),
.suspend = pch_spi_suspend, .suspend = pch_spi_suspend,
.resume = pch_spi_resume, .resume = pch_spi_resume,
}; };
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* SPI init/core code * SPI init/core code
* *
* Copyright (C) 2005 David Brownell * Copyright (C) 2005 David Brownell
* Copyright (C) 2008 Secret Lab Technologies Ltd.
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -19,15 +20,16 @@ ...@@ -19,15 +20,16 @@
*/ */
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/kmod.h>
#include <linux/device.h> #include <linux/device.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/cache.h> #include <linux/cache.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/of_device.h> #include <linux/of_device.h>
#include <linux/of_irq.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/mod_devicetable.h> #include <linux/mod_devicetable.h>
#include <linux/spi/spi.h> #include <linux/spi/spi.h>
#include <linux/of_spi.h>
#include <linux/pm_runtime.h> #include <linux/pm_runtime.h>
#include <linux/export.h> #include <linux/export.h>
#include <linux/sched.h> #include <linux/sched.h>
...@@ -530,7 +532,7 @@ static void spi_pump_messages(struct kthread_work *work) ...@@ -530,7 +532,7 @@ static void spi_pump_messages(struct kthread_work *work)
/* Lock queue and check for queue work */ /* Lock queue and check for queue work */
spin_lock_irqsave(&master->queue_lock, flags); spin_lock_irqsave(&master->queue_lock, flags);
if (list_empty(&master->queue) || !master->running) { if (list_empty(&master->queue) || !master->running) {
if (master->busy) { if (master->busy && master->unprepare_transfer_hardware) {
ret = master->unprepare_transfer_hardware(master); ret = master->unprepare_transfer_hardware(master);
if (ret) { if (ret) {
spin_unlock_irqrestore(&master->queue_lock, flags); spin_unlock_irqrestore(&master->queue_lock, flags);
...@@ -560,7 +562,7 @@ static void spi_pump_messages(struct kthread_work *work) ...@@ -560,7 +562,7 @@ static void spi_pump_messages(struct kthread_work *work)
master->busy = true; master->busy = true;
spin_unlock_irqrestore(&master->queue_lock, flags); spin_unlock_irqrestore(&master->queue_lock, flags);
if (!was_busy) { if (!was_busy && master->prepare_transfer_hardware) {
ret = master->prepare_transfer_hardware(master); ret = master->prepare_transfer_hardware(master);
if (ret) { if (ret) {
dev_err(&master->dev, dev_err(&master->dev,
...@@ -798,6 +800,94 @@ static int spi_master_initialize_queue(struct spi_master *master) ...@@ -798,6 +800,94 @@ static int spi_master_initialize_queue(struct spi_master *master)
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
#if defined(CONFIG_OF) && !defined(CONFIG_SPARC)
/**
* of_register_spi_devices() - Register child devices onto the SPI bus
* @master: Pointer to spi_master device
*
* Registers an spi_device for each child node of master node which has a 'reg'
* property.
*/
static void of_register_spi_devices(struct spi_master *master)
{
struct spi_device *spi;
struct device_node *nc;
const __be32 *prop;
int rc;
int len;
if (!master->dev.of_node)
return;
for_each_child_of_node(master->dev.of_node, 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 = be32_to_cpup(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;
if (of_find_property(nc, "spi-cs-high", NULL))
spi->mode |= SPI_CS_HIGH;
/* 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 = be32_to_cpup(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.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);
}
}
}
#else
static void of_register_spi_devices(struct spi_master *master) { }
#endif
static void spi_master_release(struct device *dev) static void spi_master_release(struct device *dev)
{ {
struct spi_master *master; struct spi_master *master;
...@@ -846,6 +936,8 @@ struct spi_master *spi_alloc_master(struct device *dev, unsigned size) ...@@ -846,6 +936,8 @@ struct spi_master *spi_alloc_master(struct device *dev, unsigned size)
return NULL; return NULL;
device_initialize(&master->dev); device_initialize(&master->dev);
master->bus_num = -1;
master->num_chipselect = 1;
master->dev.class = &spi_master_class; master->dev.class = &spi_master_class;
master->dev.parent = get_device(dev); master->dev.parent = get_device(dev);
spi_master_set_devdata(master, &master[1]); spi_master_set_devdata(master, &master[1]);
......
/*
* 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/spi/spi.h>
#if defined(CONFIG_OF_SPI) || defined(CONFIG_OF_SPI_MODULE)
extern void of_register_spi_devices(struct spi_master *master);
#else
static inline void of_register_spi_devices(struct spi_master *master)
{
return;
}
#endif /* CONFIG_OF_SPI */
#endif /* __LINUX_OF_SPI */
/*
* Renesas SPI driver
*
* Copyright (C) 2012 Renesas Solutions Corp.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifndef __LINUX_SPI_RENESAS_SPI_H__
#define __LINUX_SPI_RENESAS_SPI_H__
struct rspi_plat_data {
unsigned int dma_tx_id;
unsigned int dma_rx_id;
unsigned dma_width_16bit:1; /* DMAC read/write width = 16-bit */
};
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment