Linus Walleij | c7c8c78 | 2009-08-14 10:59:05 +0100 | [diff] [blame] | 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> |
Linus Walleij | ec8f125 | 2010-08-13 11:31:59 +0200 | [diff] [blame] | 14 | #include <mach/coh901318.h> |
Linus Walleij | 8dcf470 | 2012-08-13 11:51:15 +0200 | [diff] [blame^] | 15 | #include "dma_channels.h" |
Linus Walleij | ec8f125 | 2010-08-13 11:31:59 +0200 | [diff] [blame] | 16 | |
Linus Walleij | c7c8c78 | 2009-08-14 10:59:05 +0100 | [diff] [blame] | 17 | /* |
| 18 | * The following is for the actual devices on the SSP/SPI bus |
| 19 | */ |
| 20 | #ifdef CONFIG_MACH_U300_SPIDUMMY |
| 21 | static void select_dummy_chip(u32 chipselect) |
| 22 | { |
| 23 | pr_debug("CORE: %s called with CS=0x%x (%s)\n", |
| 24 | __func__, |
| 25 | chipselect, |
| 26 | chipselect ? "unselect chip" : "select chip"); |
| 27 | /* |
| 28 | * Here you would write the chip select value to the GPIO pins if |
| 29 | * this was a real chip (but this is a loopback dummy). |
| 30 | */ |
| 31 | } |
| 32 | |
| 33 | struct pl022_config_chip dummy_chip_info = { |
Linus Walleij | ec8f125 | 2010-08-13 11:31:59 +0200 | [diff] [blame] | 34 | /* available POLLING_TRANSFER, INTERRUPT_TRANSFER, DMA_TRANSFER */ |
| 35 | .com_mode = DMA_TRANSFER, |
Linus Walleij | c7c8c78 | 2009-08-14 10:59:05 +0100 | [diff] [blame] | 36 | .iface = SSP_INTERFACE_MOTOROLA_SPI, |
| 37 | /* We can only act as master but SSP_SLAVE is possible in theory */ |
| 38 | .hierarchy = SSP_MASTER, |
| 39 | /* 0 = drive TX even as slave, 1 = do not drive TX as slave */ |
| 40 | .slave_tx_disable = 0, |
Linus Walleij | 32d55ff | 2011-06-16 09:28:28 +0200 | [diff] [blame] | 41 | .rx_lev_trig = SSP_RX_4_OR_MORE_ELEM, |
| 42 | .tx_lev_trig = SSP_TX_4_OR_MORE_EMPTY_LOC, |
Linus Walleij | c7c8c78 | 2009-08-14 10:59:05 +0100 | [diff] [blame] | 43 | .ctrl_len = SSP_BITS_12, |
| 44 | .wait_state = SSP_MWIRE_WAIT_ZERO, |
| 45 | .duplex = SSP_MICROWIRE_CHANNEL_FULL_DUPLEX, |
| 46 | /* |
| 47 | * This is where you insert a call to a function to enable CS |
| 48 | * (usually GPIO) for a certain chip. |
| 49 | */ |
| 50 | .cs_control = select_dummy_chip, |
| 51 | }; |
| 52 | #endif |
| 53 | |
| 54 | static struct spi_board_info u300_spi_devices[] = { |
| 55 | #ifdef CONFIG_MACH_U300_SPIDUMMY |
| 56 | { |
| 57 | /* A dummy chip used for loopback tests */ |
| 58 | .modalias = "spi-dummy", |
| 59 | /* Really dummy, pass in additional chip config here */ |
| 60 | .platform_data = NULL, |
| 61 | /* This defines how the controller shall handle the device */ |
| 62 | .controller_data = &dummy_chip_info, |
| 63 | /* .irq - no external IRQ routed from this device */ |
| 64 | .max_speed_hz = 1000000, |
| 65 | .bus_num = 0, /* Only one bus on this chip */ |
| 66 | .chip_select = 0, |
| 67 | /* Means SPI_CS_HIGH, change if e.g low CS */ |
Linus Walleij | 65289d6 | 2010-10-21 21:05:25 +0200 | [diff] [blame] | 68 | .mode = SPI_MODE_1 | SPI_LOOP, |
Linus Walleij | c7c8c78 | 2009-08-14 10:59:05 +0100 | [diff] [blame] | 69 | }, |
| 70 | #endif |
| 71 | }; |
| 72 | |
| 73 | static struct pl022_ssp_controller ssp_platform_data = { |
| 74 | /* If you have several SPI buses this varies, we have only bus 0 */ |
| 75 | .bus_id = 0, |
Linus Walleij | c7c8c78 | 2009-08-14 10:59:05 +0100 | [diff] [blame] | 76 | /* |
| 77 | * On the APP CPU GPIO 4, 5 and 6 are connected as generic |
| 78 | * chip selects for SPI. (Same on U330, U335 and U365.) |
| 79 | * TODO: make sure the GPIO driver can select these properly |
| 80 | * and do padmuxing accordingly too. |
| 81 | */ |
| 82 | .num_chipselect = 3, |
Linus Walleij | ec8f125 | 2010-08-13 11:31:59 +0200 | [diff] [blame] | 83 | #ifdef CONFIG_COH901318 |
| 84 | .enable_dma = 1, |
| 85 | .dma_filter = coh901318_filter_id, |
| 86 | .dma_rx_param = (void *) U300_DMA_SPI_RX, |
| 87 | .dma_tx_param = (void *) U300_DMA_SPI_TX, |
| 88 | #else |
| 89 | .enable_dma = 0, |
| 90 | #endif |
Linus Walleij | c7c8c78 | 2009-08-14 10:59:05 +0100 | [diff] [blame] | 91 | }; |
| 92 | |
| 93 | |
| 94 | void __init u300_spi_init(struct amba_device *adev) |
| 95 | { |
Linus Walleij | c7c8c78 | 2009-08-14 10:59:05 +0100 | [diff] [blame] | 96 | adev->dev.platform_data = &ssp_platform_data; |
Linus Walleij | c7c8c78 | 2009-08-14 10:59:05 +0100 | [diff] [blame] | 97 | } |
Linus Walleij | ec8f125 | 2010-08-13 11:31:59 +0200 | [diff] [blame] | 98 | |
Linus Walleij | c7c8c78 | 2009-08-14 10:59:05 +0100 | [diff] [blame] | 99 | void __init u300_spi_register_board_devices(void) |
| 100 | { |
| 101 | /* Register any SPI devices */ |
| 102 | spi_register_board_info(u300_spi_devices, ARRAY_SIZE(u300_spi_devices)); |
| 103 | } |