Skip to content

Commit 702c0b0

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/xilinx: Fix compile error spi/davinci: Fix clock prescale factor computation spi: move bitbang txrx utility functions to private header spi/mpc5121: Add SPI master driver for MPC5121 PSC powerpc/mpc5121: move PSC FIFO memory init to platform code spi/ep93xx: implemented driver for Cirrus EP93xx SPI controller Documentation/spi/* compile warning fix spi/omap2_mcspi: Check params before dereference or use spi/omap2_mcspi: add turbo mode support spi/omap2_mcspi: change default DMA_MIN_BYTES value to 160 spi/pl022: fix stop queue procedure spi/pl022: add support for the PL023 derivate spi/pl022: fix up differences between ARM and ST versions spi/spi_mpc8xxx: Do not use map_tx_dma to unmap rx_dma spi/spi_mpc8xxx: Fix QE mode Litte Endian spi/spi_mpc8xxx: fix potential memory corruption.
2 parents c19eb8f + bf6a67e commit 702c0b0

File tree

23 files changed

+2262
-319
lines changed

23 files changed

+2262
-319
lines changed

Documentation/spi/ep93xx_spi

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
Cirrus EP93xx SPI controller driver HOWTO
2+
=========================================
3+
4+
ep93xx_spi driver brings SPI master support for EP93xx SPI controller. Chip
5+
selects are implemented with GPIO lines.
6+
7+
NOTE: If possible, don't use SFRMOUT (SFRM1) signal as a chip select. It will
8+
not work correctly (it cannot be controlled by software). Use GPIO lines
9+
instead.
10+
11+
Sample configuration
12+
====================
13+
14+
Typically driver configuration is done in platform board files (the files under
15+
arch/arm/mach-ep93xx/*.c). In this example we configure MMC over SPI through
16+
this driver on TS-7260 board. You can adapt the code to suit your needs.
17+
18+
This example uses EGPIO9 as SD/MMC card chip select (this is wired in DIO1
19+
header on the board).
20+
21+
You need to select CONFIG_MMC_SPI to use mmc_spi driver.
22+
23+
arch/arm/mach-ep93xx/ts72xx.c:
24+
25+
...
26+
#include <linux/gpio.h>
27+
#include <linux/spi/spi.h>
28+
29+
#include <mach/ep93xx_spi.h>
30+
31+
/* this is our GPIO line used for chip select */
32+
#define MMC_CHIP_SELECT_GPIO EP93XX_GPIO_LINE_EGPIO9
33+
34+
static int ts72xx_mmc_spi_setup(struct spi_device *spi)
35+
{
36+
int err;
37+
38+
err = gpio_request(MMC_CHIP_SELECT_GPIO, spi->modalias);
39+
if (err)
40+
return err;
41+
42+
gpio_direction_output(MMC_CHIP_SELECT_GPIO, 1);
43+
44+
return 0;
45+
}
46+
47+
static void ts72xx_mmc_spi_cleanup(struct spi_device *spi)
48+
{
49+
gpio_set_value(MMC_CHIP_SELECT_GPIO, 1);
50+
gpio_direction_input(MMC_CHIP_SELECT_GPIO);
51+
gpio_free(MMC_CHIP_SELECT_GPIO);
52+
}
53+
54+
static void ts72xx_mmc_spi_cs_control(struct spi_device *spi, int value)
55+
{
56+
gpio_set_value(MMC_CHIP_SELECT_GPIO, value);
57+
}
58+
59+
static struct ep93xx_spi_chip_ops ts72xx_mmc_spi_ops = {
60+
.setup = ts72xx_mmc_spi_setup,
61+
.cleanup = ts72xx_mmc_spi_cleanup,
62+
.cs_control = ts72xx_mmc_spi_cs_control,
63+
};
64+
65+
static struct spi_board_info ts72xx_spi_devices[] __initdata = {
66+
{
67+
.modalias = "mmc_spi",
68+
.controller_data = &ts72xx_mmc_spi_ops,
69+
/*
70+
* We use 10 MHz even though the maximum is 7.4 MHz. The driver
71+
* will limit it automatically to max. frequency.
72+
*/
73+
.max_speed_hz = 10 * 1000 * 1000,
74+
.bus_num = 0,
75+
.chip_select = 0,
76+
.mode = SPI_MODE_0,
77+
},
78+
};
79+
80+
static struct ep93xx_spi_info ts72xx_spi_info = {
81+
.num_chipselect = ARRAY_SIZE(ts72xx_spi_devices),
82+
};
83+
84+
static void __init ts72xx_init_machine(void)
85+
{
86+
...
87+
ep93xx_register_spi(&ts72xx_spi_info, ts72xx_spi_devices,
88+
ARRAY_SIZE(ts72xx_spi_devices));
89+
}
90+
91+
Thanks to
92+
=========
93+
Martin Guy, H. Hartley Sweeten and others who helped me during development of
94+
the driver. Simplemachines.it donated me a Sim.One board which I used testing
95+
the driver on EP9307.

Documentation/spi/spidev_fdx.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ static void do_msg(int fd, int len)
5858
len = sizeof buf;
5959

6060
buf[0] = 0xaa;
61-
xfer[0].tx_buf = (__u64) buf;
61+
xfer[0].tx_buf = (unsigned long)buf;
6262
xfer[0].len = 1;
6363

64-
xfer[1].rx_buf = (__u64) buf;
64+
xfer[1].rx_buf = (unsigned long) buf;
6565
xfer[1].len = len;
6666

6767
status = ioctl(fd, SPI_IOC_MESSAGE(2), xfer);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#ifndef __ASM_MACH_EP93XX_SPI_H
2+
#define __ASM_MACH_EP93XX_SPI_H
3+
4+
struct spi_device;
5+
6+
/**
7+
* struct ep93xx_spi_info - EP93xx specific SPI descriptor
8+
* @num_chipselect: number of chip selects on this board, must be
9+
* at least one
10+
*/
11+
struct ep93xx_spi_info {
12+
int num_chipselect;
13+
};
14+
15+
/**
16+
* struct ep93xx_spi_chip_ops - operation callbacks for SPI slave device
17+
* @setup: setup the chip select mechanism
18+
* @cleanup: cleanup the chip select mechanism
19+
* @cs_control: control the device chip select
20+
*/
21+
struct ep93xx_spi_chip_ops {
22+
int (*setup)(struct spi_device *spi);
23+
void (*cleanup)(struct spi_device *spi);
24+
void (*cs_control)(struct spi_device *spi, int value);
25+
};
26+
27+
#endif /* __ASM_MACH_EP93XX_SPI_H */

arch/powerpc/include/asm/mpc52xx_psc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ struct mpc52xx_psc_fifo {
248248
u16 tflwfptr; /* PSC + 0x9e */
249249
};
250250

251+
#define MPC512x_PSC_FIFO_EOF 0x100
251252
#define MPC512x_PSC_FIFO_RESET_SLICE 0x80
252253
#define MPC512x_PSC_FIFO_ENABLE_SLICE 0x01
253254
#define MPC512x_PSC_FIFO_ENABLE_DMA 0x04

arch/powerpc/platforms/512x/mpc512x_shared.c

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <asm/prom.h>
2323
#include <asm/time.h>
2424
#include <asm/mpc5121.h>
25+
#include <asm/mpc52xx_psc.h>
2526

2627
#include "mpc512x.h"
2728

@@ -95,9 +96,86 @@ void __init mpc512x_declare_of_platform_devices(void)
9596
}
9697
}
9798

99+
#define DEFAULT_FIFO_SIZE 16
100+
101+
static unsigned int __init get_fifo_size(struct device_node *np,
102+
char *prop_name)
103+
{
104+
const unsigned int *fp;
105+
106+
fp = of_get_property(np, prop_name, NULL);
107+
if (fp)
108+
return *fp;
109+
110+
pr_warning("no %s property in %s node, defaulting to %d\n",
111+
prop_name, np->full_name, DEFAULT_FIFO_SIZE);
112+
113+
return DEFAULT_FIFO_SIZE;
114+
}
115+
116+
#define FIFOC(_base) ((struct mpc512x_psc_fifo __iomem *) \
117+
((u32)(_base) + sizeof(struct mpc52xx_psc)))
118+
119+
/* Init PSC FIFO space for TX and RX slices */
120+
void __init mpc512x_psc_fifo_init(void)
121+
{
122+
struct device_node *np;
123+
void __iomem *psc;
124+
unsigned int tx_fifo_size;
125+
unsigned int rx_fifo_size;
126+
int fifobase = 0; /* current fifo address in 32 bit words */
127+
128+
for_each_compatible_node(np, NULL, "fsl,mpc5121-psc") {
129+
tx_fifo_size = get_fifo_size(np, "fsl,tx-fifo-size");
130+
rx_fifo_size = get_fifo_size(np, "fsl,rx-fifo-size");
131+
132+
/* size in register is in 4 byte units */
133+
tx_fifo_size /= 4;
134+
rx_fifo_size /= 4;
135+
if (!tx_fifo_size)
136+
tx_fifo_size = 1;
137+
if (!rx_fifo_size)
138+
rx_fifo_size = 1;
139+
140+
psc = of_iomap(np, 0);
141+
if (!psc) {
142+
pr_err("%s: Can't map %s device\n",
143+
__func__, np->full_name);
144+
continue;
145+
}
146+
147+
/* FIFO space is 4KiB, check if requested size is available */
148+
if ((fifobase + tx_fifo_size + rx_fifo_size) > 0x1000) {
149+
pr_err("%s: no fifo space available for %s\n",
150+
__func__, np->full_name);
151+
iounmap(psc);
152+
/*
153+
* chances are that another device requests less
154+
* fifo space, so we continue.
155+
*/
156+
continue;
157+
}
158+
159+
/* set tx and rx fifo size registers */
160+
out_be32(&FIFOC(psc)->txsz, (fifobase << 16) | tx_fifo_size);
161+
fifobase += tx_fifo_size;
162+
out_be32(&FIFOC(psc)->rxsz, (fifobase << 16) | rx_fifo_size);
163+
fifobase += rx_fifo_size;
164+
165+
/* reset and enable the slices */
166+
out_be32(&FIFOC(psc)->txcmd, 0x80);
167+
out_be32(&FIFOC(psc)->txcmd, 0x01);
168+
out_be32(&FIFOC(psc)->rxcmd, 0x80);
169+
out_be32(&FIFOC(psc)->rxcmd, 0x01);
170+
171+
iounmap(psc);
172+
}
173+
}
174+
98175
void __init mpc512x_init(void)
99176
{
100177
mpc512x_declare_of_platform_devices();
101178
mpc5121_clk_init();
102179
mpc512x_restart_init();
180+
mpc512x_psc_fifo_init();
103181
}

drivers/serial/mpc52xx_uart.c

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -397,34 +397,10 @@ static unsigned long mpc512x_getuartclk(void *p)
397397
return mpc5xxx_get_bus_frequency(p);
398398
}
399399

400-
#define DEFAULT_FIFO_SIZE 16
401-
402-
static unsigned int __init get_fifo_size(struct device_node *np,
403-
char *fifo_name)
404-
{
405-
const unsigned int *fp;
406-
407-
fp = of_get_property(np, fifo_name, NULL);
408-
if (fp)
409-
return *fp;
410-
411-
pr_warning("no %s property in %s node, defaulting to %d\n",
412-
fifo_name, np->full_name, DEFAULT_FIFO_SIZE);
413-
414-
return DEFAULT_FIFO_SIZE;
415-
}
416-
417-
#define FIFOC(_base) ((struct mpc512x_psc_fifo __iomem *) \
418-
((u32)(_base) + sizeof(struct mpc52xx_psc)))
419-
420400
/* Init PSC FIFO Controller */
421401
static int __init mpc512x_psc_fifoc_init(void)
422402
{
423403
struct device_node *np;
424-
void __iomem *psc;
425-
unsigned int tx_fifo_size;
426-
unsigned int rx_fifo_size;
427-
int fifobase = 0; /* current fifo address in 32 bit words */
428404

429405
np = of_find_compatible_node(NULL, NULL,
430406
"fsl,mpc5121-psc-fifo");
@@ -447,51 +423,6 @@ static int __init mpc512x_psc_fifoc_init(void)
447423
return -ENODEV;
448424
}
449425

450-
for_each_compatible_node(np, NULL, "fsl,mpc5121-psc-uart") {
451-
tx_fifo_size = get_fifo_size(np, "fsl,tx-fifo-size");
452-
rx_fifo_size = get_fifo_size(np, "fsl,rx-fifo-size");
453-
454-
/* size in register is in 4 byte units */
455-
tx_fifo_size /= 4;
456-
rx_fifo_size /= 4;
457-
if (!tx_fifo_size)
458-
tx_fifo_size = 1;
459-
if (!rx_fifo_size)
460-
rx_fifo_size = 1;
461-
462-
psc = of_iomap(np, 0);
463-
if (!psc) {
464-
pr_err("%s: Can't map %s device\n",
465-
__func__, np->full_name);
466-
continue;
467-
}
468-
469-
/* FIFO space is 4KiB, check if requested size is available */
470-
if ((fifobase + tx_fifo_size + rx_fifo_size) > 0x1000) {
471-
pr_err("%s: no fifo space available for %s\n",
472-
__func__, np->full_name);
473-
iounmap(psc);
474-
/*
475-
* chances are that another device requests less
476-
* fifo space, so we continue.
477-
*/
478-
continue;
479-
}
480-
/* set tx and rx fifo size registers */
481-
out_be32(&FIFOC(psc)->txsz, (fifobase << 16) | tx_fifo_size);
482-
fifobase += tx_fifo_size;
483-
out_be32(&FIFOC(psc)->rxsz, (fifobase << 16) | rx_fifo_size);
484-
fifobase += rx_fifo_size;
485-
486-
/* reset and enable the slices */
487-
out_be32(&FIFOC(psc)->txcmd, 0x80);
488-
out_be32(&FIFOC(psc)->txcmd, 0x01);
489-
out_be32(&FIFOC(psc)->rxcmd, 0x80);
490-
out_be32(&FIFOC(psc)->rxcmd, 0x01);
491-
492-
iounmap(psc);
493-
}
494-
495426
return 0;
496427
}
497428

drivers/spi/Kconfig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,16 @@ config SPI_DAVINCI
117117
help
118118
SPI master controller for DaVinci and DA8xx SPI modules.
119119

120+
config SPI_EP93XX
121+
tristate "Cirrus Logic EP93xx SPI controller"
122+
depends on ARCH_EP93XX
123+
help
124+
This enables using the Cirrus EP93xx SPI controller in master
125+
mode.
126+
127+
To compile this driver as a module, choose M here. The module will be
128+
called ep93xx_spi.
129+
120130
config SPI_GPIO
121131
tristate "GPIO-based bitbanging SPI Master"
122132
depends on GENERIC_GPIO
@@ -165,6 +175,13 @@ config SPI_MPC52xx_PSC
165175
This enables using the Freescale MPC52xx Programmable Serial
166176
Controller in master SPI mode.
167177

178+
config SPI_MPC512x_PSC
179+
tristate "Freescale MPC512x PSC SPI controller"
180+
depends on SPI_MASTER && PPC_MPC512x
181+
help
182+
This enables using the Freescale MPC5121 Programmable Serial
183+
Controller in SPI master mode.
184+
168185
config SPI_MPC8xxx
169186
tristate "Freescale MPC8xxx SPI controller"
170187
depends on FSL_SOC

drivers/spi/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ obj-$(CONFIG_SPI_DAVINCI) += davinci_spi.o
2121
obj-$(CONFIG_SPI_DESIGNWARE) += dw_spi.o
2222
obj-$(CONFIG_SPI_DW_PCI) += dw_spi_pci.o
2323
obj-$(CONFIG_SPI_DW_MMIO) += dw_spi_mmio.o
24+
obj-$(CONFIG_SPI_EP93XX) += ep93xx_spi.o
2425
obj-$(CONFIG_SPI_GPIO) += spi_gpio.o
2526
obj-$(CONFIG_SPI_IMX) += spi_imx.o
2627
obj-$(CONFIG_SPI_LM70_LLP) += spi_lm70llp.o
@@ -30,6 +31,7 @@ obj-$(CONFIG_SPI_OMAP24XX) += omap2_mcspi.o
3031
obj-$(CONFIG_SPI_OMAP_100K) += omap_spi_100k.o
3132
obj-$(CONFIG_SPI_ORION) += orion_spi.o
3233
obj-$(CONFIG_SPI_PL022) += amba-pl022.o
34+
obj-$(CONFIG_SPI_MPC512x_PSC) += mpc512x_psc_spi.o
3335
obj-$(CONFIG_SPI_MPC52xx_PSC) += mpc52xx_psc_spi.o
3436
obj-$(CONFIG_SPI_MPC52xx) += mpc52xx_spi.o
3537
obj-$(CONFIG_SPI_MPC8xxx) += spi_mpc8xxx.o

0 commit comments

Comments
 (0)