Merge remote-tracking branch 'moduleh/module.h-split'
[linux-2.6/next.git] / arch / arm / mach-u300 / spi.c
blob7b597e2b19e2aa724d238f04a8b6b503e0ea67aa
1 /*
2 * arch/arm/mach-u300/spi.c
4 * Copyright (C) 2009 ST-Ericsson AB
5 * License terms: GNU General Public License (GPL) version 2
7 * Author: Linus Walleij <linus.walleij@stericsson.com>
8 */
9 #include <linux/device.h>
10 #include <linux/amba/bus.h>
11 #include <linux/spi/spi.h>
12 #include <linux/amba/pl022.h>
13 #include <linux/err.h>
14 #include <mach/coh901318.h>
15 #include <mach/dma_channels.h>
17 #include "padmux.h"
20 * The following is for the actual devices on the SSP/SPI bus
22 #ifdef CONFIG_MACH_U300_SPIDUMMY
23 static void select_dummy_chip(u32 chipselect)
25 pr_debug("CORE: %s called with CS=0x%x (%s)\n",
26 __func__,
27 chipselect,
28 chipselect ? "unselect chip" : "select chip");
30 * Here you would write the chip select value to the GPIO pins if
31 * this was a real chip (but this is a loopback dummy).
35 struct pl022_config_chip dummy_chip_info = {
36 /* available POLLING_TRANSFER, INTERRUPT_TRANSFER, DMA_TRANSFER */
37 .com_mode = DMA_TRANSFER,
38 .iface = SSP_INTERFACE_MOTOROLA_SPI,
39 /* We can only act as master but SSP_SLAVE is possible in theory */
40 .hierarchy = SSP_MASTER,
41 /* 0 = drive TX even as slave, 1 = do not drive TX as slave */
42 .slave_tx_disable = 0,
43 .rx_lev_trig = SSP_RX_4_OR_MORE_ELEM,
44 .tx_lev_trig = SSP_TX_4_OR_MORE_EMPTY_LOC,
45 .ctrl_len = SSP_BITS_12,
46 .wait_state = SSP_MWIRE_WAIT_ZERO,
47 .duplex = SSP_MICROWIRE_CHANNEL_FULL_DUPLEX,
49 * This is where you insert a call to a function to enable CS
50 * (usually GPIO) for a certain chip.
52 .cs_control = select_dummy_chip,
54 #endif
56 static struct spi_board_info u300_spi_devices[] = {
57 #ifdef CONFIG_MACH_U300_SPIDUMMY
59 /* A dummy chip used for loopback tests */
60 .modalias = "spi-dummy",
61 /* Really dummy, pass in additional chip config here */
62 .platform_data = NULL,
63 /* This defines how the controller shall handle the device */
64 .controller_data = &dummy_chip_info,
65 /* .irq - no external IRQ routed from this device */
66 .max_speed_hz = 1000000,
67 .bus_num = 0, /* Only one bus on this chip */
68 .chip_select = 0,
69 /* Means SPI_CS_HIGH, change if e.g low CS */
70 .mode = SPI_MODE_1 | SPI_LOOP,
72 #endif
75 static struct pl022_ssp_controller ssp_platform_data = {
76 /* If you have several SPI buses this varies, we have only bus 0 */
77 .bus_id = 0,
79 * On the APP CPU GPIO 4, 5 and 6 are connected as generic
80 * chip selects for SPI. (Same on U330, U335 and U365.)
81 * TODO: make sure the GPIO driver can select these properly
82 * and do padmuxing accordingly too.
84 .num_chipselect = 3,
85 #ifdef CONFIG_COH901318
86 .enable_dma = 1,
87 .dma_filter = coh901318_filter_id,
88 .dma_rx_param = (void *) U300_DMA_SPI_RX,
89 .dma_tx_param = (void *) U300_DMA_SPI_TX,
90 #else
91 .enable_dma = 0,
92 #endif
96 void __init u300_spi_init(struct amba_device *adev)
98 struct pmx *pmx;
100 adev->dev.platform_data = &ssp_platform_data;
102 * Setup padmuxing for SPI. Since this must always be
103 * compiled into the kernel, pmx is never released.
105 pmx = pmx_get(&adev->dev, U300_APP_PMX_SPI_SETTING);
107 if (IS_ERR(pmx))
108 dev_warn(&adev->dev, "Could not get padmux handle\n");
109 else {
110 int ret;
112 ret = pmx_activate(&adev->dev, pmx);
113 if (IS_ERR_VALUE(ret))
114 dev_warn(&adev->dev, "Could not activate padmuxing\n");
119 void __init u300_spi_register_board_devices(void)
121 /* Register any SPI devices */
122 spi_register_board_info(u300_spi_devices, ARRAY_SIZE(u300_spi_devices));