diff options
Diffstat (limited to 'arch/arm/mach-u300/spi.c')
-rw-r--r-- | arch/arm/mach-u300/spi.c | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/arch/arm/mach-u300/spi.c b/arch/arm/mach-u300/spi.c new file mode 100644 index 000000000000..f0e887bea30e --- /dev/null +++ b/arch/arm/mach-u300/spi.c | |||
@@ -0,0 +1,124 @@ | |||
1 | /* | ||
2 | * arch/arm/mach-u300/spi.c | ||
3 | * | ||
4 | * Copyright (C) 2009 ST-Ericsson AB | ||
5 | * License terms: GNU General Public License (GPL) version 2 | ||
6 | * | ||
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 "padmux.h" | ||
15 | |||
16 | /* | ||
17 | * The following is for the actual devices on the SSP/SPI bus | ||
18 | */ | ||
19 | #ifdef CONFIG_MACH_U300_SPIDUMMY | ||
20 | static void select_dummy_chip(u32 chipselect) | ||
21 | { | ||
22 | pr_debug("CORE: %s called with CS=0x%x (%s)\n", | ||
23 | __func__, | ||
24 | chipselect, | ||
25 | chipselect ? "unselect chip" : "select chip"); | ||
26 | /* | ||
27 | * Here you would write the chip select value to the GPIO pins if | ||
28 | * this was a real chip (but this is a loopback dummy). | ||
29 | */ | ||
30 | } | ||
31 | |||
32 | struct pl022_config_chip dummy_chip_info = { | ||
33 | /* Nominally this is LOOPBACK_DISABLED, but this is our dummy chip! */ | ||
34 | .lbm = LOOPBACK_ENABLED, | ||
35 | /* | ||
36 | * available POLLING_TRANSFER and INTERRUPT_TRANSFER, | ||
37 | * DMA_TRANSFER does not work | ||
38 | */ | ||
39 | .com_mode = INTERRUPT_TRANSFER, | ||
40 | .iface = SSP_INTERFACE_MOTOROLA_SPI, | ||
41 | /* We can only act as master but SSP_SLAVE is possible in theory */ | ||
42 | .hierarchy = SSP_MASTER, | ||
43 | /* 0 = drive TX even as slave, 1 = do not drive TX as slave */ | ||
44 | .slave_tx_disable = 0, | ||
45 | /* LSB first */ | ||
46 | .endian_tx = SSP_TX_LSB, | ||
47 | .endian_rx = SSP_RX_LSB, | ||
48 | .data_size = SSP_DATA_BITS_8, /* used to be 12 in some default */ | ||
49 | .rx_lev_trig = SSP_RX_1_OR_MORE_ELEM, | ||
50 | .tx_lev_trig = SSP_TX_1_OR_MORE_EMPTY_LOC, | ||
51 | .clk_phase = SSP_CLK_SECOND_EDGE, | ||
52 | .clk_pol = SSP_CLK_POL_IDLE_LOW, | ||
53 | .ctrl_len = SSP_BITS_12, | ||
54 | .wait_state = SSP_MWIRE_WAIT_ZERO, | ||
55 | .duplex = SSP_MICROWIRE_CHANNEL_FULL_DUPLEX, | ||
56 | /* | ||
57 | * This is where you insert a call to a function to enable CS | ||
58 | * (usually GPIO) for a certain chip. | ||
59 | */ | ||
60 | .cs_control = select_dummy_chip, | ||
61 | }; | ||
62 | #endif | ||
63 | |||
64 | static struct spi_board_info u300_spi_devices[] = { | ||
65 | #ifdef CONFIG_MACH_U300_SPIDUMMY | ||
66 | { | ||
67 | /* A dummy chip used for loopback tests */ | ||
68 | .modalias = "spi-dummy", | ||
69 | /* Really dummy, pass in additional chip config here */ | ||
70 | .platform_data = NULL, | ||
71 | /* This defines how the controller shall handle the device */ | ||
72 | .controller_data = &dummy_chip_info, | ||
73 | /* .irq - no external IRQ routed from this device */ | ||
74 | .max_speed_hz = 1000000, | ||
75 | .bus_num = 0, /* Only one bus on this chip */ | ||
76 | .chip_select = 0, | ||
77 | /* Means SPI_CS_HIGH, change if e.g low CS */ | ||
78 | .mode = 0, | ||
79 | }, | ||
80 | #endif | ||
81 | }; | ||
82 | |||
83 | static struct pl022_ssp_controller ssp_platform_data = { | ||
84 | /* If you have several SPI buses this varies, we have only bus 0 */ | ||
85 | .bus_id = 0, | ||
86 | /* Set this to 1 when we think we got DMA working */ | ||
87 | .enable_dma = 0, | ||
88 | /* | ||
89 | * On the APP CPU GPIO 4, 5 and 6 are connected as generic | ||
90 | * chip selects for SPI. (Same on U330, U335 and U365.) | ||
91 | * TODO: make sure the GPIO driver can select these properly | ||
92 | * and do padmuxing accordingly too. | ||
93 | */ | ||
94 | .num_chipselect = 3, | ||
95 | }; | ||
96 | |||
97 | |||
98 | void __init u300_spi_init(struct amba_device *adev) | ||
99 | { | ||
100 | struct pmx *pmx; | ||
101 | |||
102 | adev->dev.platform_data = &ssp_platform_data; | ||
103 | /* | ||
104 | * Setup padmuxing for SPI. Since this must always be | ||
105 | * compiled into the kernel, pmx is never released. | ||
106 | */ | ||
107 | pmx = pmx_get(&adev->dev, U300_APP_PMX_SPI_SETTING); | ||
108 | |||
109 | if (IS_ERR(pmx)) | ||
110 | dev_warn(&adev->dev, "Could not get padmux handle\n"); | ||
111 | else { | ||
112 | int ret; | ||
113 | |||
114 | ret = pmx_activate(&adev->dev, pmx); | ||
115 | if (IS_ERR_VALUE(ret)) | ||
116 | dev_warn(&adev->dev, "Could not activate padmuxing\n"); | ||
117 | } | ||
118 | |||
119 | } | ||
120 | void __init u300_spi_register_board_devices(void) | ||
121 | { | ||
122 | /* Register any SPI devices */ | ||
123 | spi_register_board_info(u300_spi_devices, ARRAY_SIZE(u300_spi_devices)); | ||
124 | } | ||