blob: 910698293d64790416d6af1e7085539e5d7bc0d0 [file] [log] [blame]
Linus Walleijc7c8c782009-08-14 10:59:05 +01001/*
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>
Linus Walleij9f575d92013-01-04 10:35:06 +010013#include <linux/platform_data/dma-coh901318.h>
Linus Walleijc7c8c782009-08-14 10:59:05 +010014#include <linux/err.h>
Linus Walleijec8f1252010-08-13 11:31:59 +020015
Linus Walleijc7c8c782009-08-14 10:59:05 +010016/*
17 * The following is for the actual devices on the SSP/SPI bus
18 */
19#ifdef CONFIG_MACH_U300_SPIDUMMY
20static 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
32struct pl022_config_chip dummy_chip_info = {
Linus Walleijec8f1252010-08-13 11:31:59 +020033 /* available POLLING_TRANSFER, INTERRUPT_TRANSFER, DMA_TRANSFER */
34 .com_mode = DMA_TRANSFER,
Linus Walleijc7c8c782009-08-14 10:59:05 +010035 .iface = SSP_INTERFACE_MOTOROLA_SPI,
36 /* We can only act as master but SSP_SLAVE is possible in theory */
37 .hierarchy = SSP_MASTER,
38 /* 0 = drive TX even as slave, 1 = do not drive TX as slave */
39 .slave_tx_disable = 0,
Linus Walleij32d55ff2011-06-16 09:28:28 +020040 .rx_lev_trig = SSP_RX_4_OR_MORE_ELEM,
41 .tx_lev_trig = SSP_TX_4_OR_MORE_EMPTY_LOC,
Linus Walleijc7c8c782009-08-14 10:59:05 +010042 .ctrl_len = SSP_BITS_12,
43 .wait_state = SSP_MWIRE_WAIT_ZERO,
44 .duplex = SSP_MICROWIRE_CHANNEL_FULL_DUPLEX,
45 /*
46 * This is where you insert a call to a function to enable CS
47 * (usually GPIO) for a certain chip.
48 */
49 .cs_control = select_dummy_chip,
50};
51#endif
52
53static struct spi_board_info u300_spi_devices[] = {
54#ifdef CONFIG_MACH_U300_SPIDUMMY
55 {
56 /* A dummy chip used for loopback tests */
57 .modalias = "spi-dummy",
58 /* Really dummy, pass in additional chip config here */
59 .platform_data = NULL,
60 /* This defines how the controller shall handle the device */
61 .controller_data = &dummy_chip_info,
62 /* .irq - no external IRQ routed from this device */
63 .max_speed_hz = 1000000,
64 .bus_num = 0, /* Only one bus on this chip */
65 .chip_select = 0,
66 /* Means SPI_CS_HIGH, change if e.g low CS */
Linus Walleij65289d62010-10-21 21:05:25 +020067 .mode = SPI_MODE_1 | SPI_LOOP,
Linus Walleijc7c8c782009-08-14 10:59:05 +010068 },
69#endif
70};
71
72static struct pl022_ssp_controller ssp_platform_data = {
73 /* If you have several SPI buses this varies, we have only bus 0 */
74 .bus_id = 0,
Linus Walleijc7c8c782009-08-14 10:59:05 +010075 /*
76 * On the APP CPU GPIO 4, 5 and 6 are connected as generic
77 * chip selects for SPI. (Same on U330, U335 and U365.)
78 * TODO: make sure the GPIO driver can select these properly
79 * and do padmuxing accordingly too.
80 */
81 .num_chipselect = 3,
Linus Walleijec8f1252010-08-13 11:31:59 +020082#ifdef CONFIG_COH901318
83 .enable_dma = 1,
84 .dma_filter = coh901318_filter_id,
85 .dma_rx_param = (void *) U300_DMA_SPI_RX,
86 .dma_tx_param = (void *) U300_DMA_SPI_TX,
87#else
88 .enable_dma = 0,
89#endif
Linus Walleijc7c8c782009-08-14 10:59:05 +010090};
91
92
93void __init u300_spi_init(struct amba_device *adev)
94{
Linus Walleijc7c8c782009-08-14 10:59:05 +010095 adev->dev.platform_data = &ssp_platform_data;
Linus Walleijc7c8c782009-08-14 10:59:05 +010096}
Linus Walleijec8f1252010-08-13 11:31:59 +020097
Linus Walleijc7c8c782009-08-14 10:59:05 +010098void __init u300_spi_register_board_devices(void)
99{
100 /* Register any SPI devices */
101 spi_register_board_info(u300_spi_devices, ARRAY_SIZE(u300_spi_devices));
102}