Cyril Chemparathy | 57a58a2 | 2010-05-18 12:51:21 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Texas Instruments TNETV107X EVM Board Support |
| 3 | * |
| 4 | * Copyright (C) 2010 Texas Instruments |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License as |
| 8 | * published by the Free Software Foundation version 2. |
| 9 | * |
| 10 | * This program is distributed "as is" WITHOUT ANY WARRANTY of any |
| 11 | * kind, whether express or implied; without even the implied warranty |
| 12 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | */ |
| 15 | #include <linux/kernel.h> |
| 16 | #include <linux/init.h> |
| 17 | #include <linux/console.h> |
| 18 | #include <linux/dma-mapping.h> |
| 19 | #include <linux/interrupt.h> |
| 20 | #include <linux/gpio.h> |
| 21 | #include <linux/delay.h> |
| 22 | #include <linux/platform_device.h> |
| 23 | #include <linux/ratelimit.h> |
| 24 | #include <linux/mtd/mtd.h> |
| 25 | #include <linux/mtd/partitions.h> |
Cyril Chemparathy | a1b4440 | 2010-09-20 12:26:42 -0400 | [diff] [blame] | 26 | #include <linux/input.h> |
| 27 | #include <linux/input/matrix_keypad.h> |
Cyril Chemparathy | f6e5306 | 2011-01-18 19:21:41 +0000 | [diff] [blame] | 28 | #include <linux/spi/spi.h> |
Cyril Chemparathy | a1b4440 | 2010-09-20 12:26:42 -0400 | [diff] [blame] | 29 | |
Cyril Chemparathy | 57a58a2 | 2010-05-18 12:51:21 -0400 | [diff] [blame] | 30 | #include <asm/mach/arch.h> |
| 31 | #include <asm/mach-types.h> |
| 32 | |
| 33 | #include <mach/irqs.h> |
| 34 | #include <mach/edma.h> |
| 35 | #include <mach/mux.h> |
| 36 | #include <mach/cp_intc.h> |
| 37 | #include <mach/tnetv107x.h> |
| 38 | |
| 39 | #define EVM_MMC_WP_GPIO 21 |
| 40 | #define EVM_MMC_CD_GPIO 24 |
Cyril Chemparathy | f6e5306 | 2011-01-18 19:21:41 +0000 | [diff] [blame] | 41 | #define EVM_SPI_CS_GPIO 54 |
Cyril Chemparathy | 57a58a2 | 2010-05-18 12:51:21 -0400 | [diff] [blame] | 42 | |
| 43 | static int initialize_gpio(int gpio, char *desc) |
| 44 | { |
| 45 | int ret; |
| 46 | |
| 47 | ret = gpio_request(gpio, desc); |
| 48 | if (ret < 0) { |
| 49 | pr_err_ratelimited("cannot open %s gpio\n", desc); |
| 50 | return -ENOSYS; |
| 51 | } |
| 52 | gpio_direction_input(gpio); |
| 53 | return gpio; |
| 54 | } |
| 55 | |
| 56 | static int mmc_get_cd(int index) |
| 57 | { |
| 58 | static int gpio; |
| 59 | |
| 60 | if (!gpio) |
| 61 | gpio = initialize_gpio(EVM_MMC_CD_GPIO, "mmc card detect"); |
| 62 | |
| 63 | if (gpio < 0) |
| 64 | return gpio; |
| 65 | |
| 66 | return gpio_get_value(gpio) ? 0 : 1; |
| 67 | } |
| 68 | |
| 69 | static int mmc_get_ro(int index) |
| 70 | { |
| 71 | static int gpio; |
| 72 | |
| 73 | if (!gpio) |
| 74 | gpio = initialize_gpio(EVM_MMC_WP_GPIO, "mmc write protect"); |
| 75 | |
| 76 | if (gpio < 0) |
| 77 | return gpio; |
| 78 | |
| 79 | return gpio_get_value(gpio) ? 1 : 0; |
| 80 | } |
| 81 | |
| 82 | static struct davinci_mmc_config mmc_config = { |
| 83 | .get_cd = mmc_get_cd, |
| 84 | .get_ro = mmc_get_ro, |
| 85 | .wires = 4, |
| 86 | .max_freq = 50000000, |
| 87 | .caps = MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED, |
| 88 | .version = MMC_CTLR_VERSION_1, |
| 89 | }; |
| 90 | |
| 91 | static const short sdio1_pins[] __initdata = { |
| 92 | TNETV107X_SDIO1_CLK_1, TNETV107X_SDIO1_CMD_1, |
| 93 | TNETV107X_SDIO1_DATA0_1, TNETV107X_SDIO1_DATA1_1, |
| 94 | TNETV107X_SDIO1_DATA2_1, TNETV107X_SDIO1_DATA3_1, |
| 95 | TNETV107X_GPIO21, TNETV107X_GPIO24, |
| 96 | -1 |
| 97 | }; |
| 98 | |
| 99 | static const short uart1_pins[] __initdata = { |
| 100 | TNETV107X_UART1_RD, TNETV107X_UART1_TD, |
| 101 | -1 |
| 102 | }; |
| 103 | |
Cyril Chemparathy | 08e0e1d | 2011-01-18 19:21:40 +0000 | [diff] [blame] | 104 | static const short ssp_pins[] __initdata = { |
| 105 | TNETV107X_SSP0_0, TNETV107X_SSP0_1, TNETV107X_SSP0_2, |
| 106 | TNETV107X_SSP1_0, TNETV107X_SSP1_1, TNETV107X_SSP1_2, |
| 107 | TNETV107X_SSP1_3, -1 |
| 108 | }; |
| 109 | |
Cyril Chemparathy | 57a58a2 | 2010-05-18 12:51:21 -0400 | [diff] [blame] | 110 | static struct mtd_partition nand_partitions[] = { |
| 111 | /* bootloader (U-Boot, etc) in first 12 sectors */ |
| 112 | { |
| 113 | .name = "bootloader", |
| 114 | .offset = 0, |
| 115 | .size = (12*SZ_128K), |
| 116 | .mask_flags = MTD_WRITEABLE, /* force read-only */ |
| 117 | }, |
| 118 | /* bootloader params in the next sector */ |
| 119 | { |
| 120 | .name = "params", |
| 121 | .offset = MTDPART_OFS_NXTBLK, |
| 122 | .size = SZ_128K, |
| 123 | .mask_flags = MTD_WRITEABLE, /* force read-only */ |
| 124 | }, |
| 125 | /* kernel */ |
| 126 | { |
| 127 | .name = "kernel", |
| 128 | .offset = MTDPART_OFS_NXTBLK, |
| 129 | .size = SZ_4M, |
| 130 | .mask_flags = 0, |
| 131 | }, |
| 132 | /* file system */ |
| 133 | { |
| 134 | .name = "filesystem", |
| 135 | .offset = MTDPART_OFS_NXTBLK, |
| 136 | .size = MTDPART_SIZ_FULL, |
| 137 | .mask_flags = 0, |
| 138 | } |
| 139 | }; |
| 140 | |
| 141 | static struct davinci_nand_pdata nand_config = { |
| 142 | .mask_cle = 0x4000, |
| 143 | .mask_ale = 0x2000, |
| 144 | .parts = nand_partitions, |
| 145 | .nr_parts = ARRAY_SIZE(nand_partitions), |
| 146 | .ecc_mode = NAND_ECC_HW, |
| 147 | .options = NAND_USE_FLASH_BBT, |
| 148 | .ecc_bits = 1, |
| 149 | }; |
| 150 | |
| 151 | static struct davinci_uart_config serial_config __initconst = { |
| 152 | .enabled_uarts = BIT(1), |
| 153 | }; |
| 154 | |
Cyril Chemparathy | a1b4440 | 2010-09-20 12:26:42 -0400 | [diff] [blame] | 155 | static const uint32_t keymap[] = { |
| 156 | KEY(0, 0, KEY_NUMERIC_1), |
| 157 | KEY(0, 1, KEY_NUMERIC_2), |
| 158 | KEY(0, 2, KEY_NUMERIC_3), |
| 159 | KEY(0, 3, KEY_FN_F1), |
| 160 | KEY(0, 4, KEY_MENU), |
| 161 | |
| 162 | KEY(1, 0, KEY_NUMERIC_4), |
| 163 | KEY(1, 1, KEY_NUMERIC_5), |
| 164 | KEY(1, 2, KEY_NUMERIC_6), |
| 165 | KEY(1, 3, KEY_UP), |
| 166 | KEY(1, 4, KEY_FN_F2), |
| 167 | |
| 168 | KEY(2, 0, KEY_NUMERIC_7), |
| 169 | KEY(2, 1, KEY_NUMERIC_8), |
| 170 | KEY(2, 2, KEY_NUMERIC_9), |
| 171 | KEY(2, 3, KEY_LEFT), |
| 172 | KEY(2, 4, KEY_ENTER), |
| 173 | |
| 174 | KEY(3, 0, KEY_NUMERIC_STAR), |
| 175 | KEY(3, 1, KEY_NUMERIC_0), |
| 176 | KEY(3, 2, KEY_NUMERIC_POUND), |
| 177 | KEY(3, 3, KEY_DOWN), |
| 178 | KEY(3, 4, KEY_RIGHT), |
| 179 | |
| 180 | KEY(4, 0, KEY_FN_F3), |
| 181 | KEY(4, 1, KEY_FN_F4), |
| 182 | KEY(4, 2, KEY_MUTE), |
| 183 | KEY(4, 3, KEY_HOME), |
| 184 | KEY(4, 4, KEY_BACK), |
| 185 | |
| 186 | KEY(5, 0, KEY_VOLUMEDOWN), |
| 187 | KEY(5, 1, KEY_VOLUMEUP), |
| 188 | KEY(5, 2, KEY_F1), |
| 189 | KEY(5, 3, KEY_F2), |
| 190 | KEY(5, 4, KEY_F3), |
| 191 | }; |
| 192 | |
| 193 | static const struct matrix_keymap_data keymap_data = { |
| 194 | .keymap = keymap, |
| 195 | .keymap_size = ARRAY_SIZE(keymap), |
| 196 | }; |
| 197 | |
| 198 | static struct matrix_keypad_platform_data keypad_config = { |
| 199 | .keymap_data = &keymap_data, |
| 200 | .num_row_gpios = 6, |
| 201 | .num_col_gpios = 5, |
| 202 | .debounce_ms = 0, /* minimum */ |
| 203 | .active_low = 0, /* pull up realization */ |
| 204 | .no_autorepeat = 0, |
| 205 | }; |
| 206 | |
Cyril Chemparathy | f6e5306 | 2011-01-18 19:21:41 +0000 | [diff] [blame] | 207 | static void spi_select_device(int cs) |
| 208 | { |
| 209 | static int gpio; |
| 210 | |
| 211 | if (!gpio) { |
| 212 | int ret; |
| 213 | ret = gpio_request(EVM_SPI_CS_GPIO, "spi chipsel"); |
| 214 | if (ret < 0) { |
| 215 | pr_err("cannot open spi chipsel gpio\n"); |
| 216 | gpio = -ENOSYS; |
| 217 | return; |
| 218 | } else { |
| 219 | gpio = EVM_SPI_CS_GPIO; |
| 220 | gpio_direction_output(gpio, 0); |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | if (gpio < 0) |
| 225 | return; |
| 226 | |
| 227 | return gpio_set_value(gpio, cs ? 1 : 0); |
| 228 | } |
| 229 | |
| 230 | static struct ti_ssp_spi_data spi_master_data = { |
| 231 | .num_cs = 2, |
| 232 | .select = spi_select_device, |
| 233 | .iosel = SSP_PIN_SEL(0, SSP_CLOCK) | SSP_PIN_SEL(1, SSP_DATA) | |
| 234 | SSP_PIN_SEL(2, SSP_CHIPSEL) | SSP_PIN_SEL(3, SSP_IN) | |
| 235 | SSP_INPUT_SEL(3), |
| 236 | }; |
| 237 | |
Cyril Chemparathy | 08e0e1d | 2011-01-18 19:21:40 +0000 | [diff] [blame] | 238 | static struct ti_ssp_data ssp_config = { |
| 239 | .out_clock = 250 * 1000, |
| 240 | .dev_data = { |
Cyril Chemparathy | f6e5306 | 2011-01-18 19:21:41 +0000 | [diff] [blame] | 241 | [1] = { |
| 242 | .dev_name = "ti-ssp-spi", |
| 243 | .pdata = &spi_master_data, |
| 244 | .pdata_size = sizeof(spi_master_data), |
| 245 | }, |
Cyril Chemparathy | 08e0e1d | 2011-01-18 19:21:40 +0000 | [diff] [blame] | 246 | }, |
| 247 | }; |
| 248 | |
Cyril Chemparathy | 57a58a2 | 2010-05-18 12:51:21 -0400 | [diff] [blame] | 249 | static struct tnetv107x_device_info evm_device_info __initconst = { |
| 250 | .serial_config = &serial_config, |
| 251 | .mmc_config[1] = &mmc_config, /* controller 1 */ |
| 252 | .nand_config[0] = &nand_config, /* chip select 0 */ |
Cyril Chemparathy | a1b4440 | 2010-09-20 12:26:42 -0400 | [diff] [blame] | 253 | .keypad_config = &keypad_config, |
Cyril Chemparathy | 08e0e1d | 2011-01-18 19:21:40 +0000 | [diff] [blame] | 254 | .ssp_config = &ssp_config, |
Cyril Chemparathy | 57a58a2 | 2010-05-18 12:51:21 -0400 | [diff] [blame] | 255 | }; |
| 256 | |
Cyril Chemparathy | f6e5306 | 2011-01-18 19:21:41 +0000 | [diff] [blame] | 257 | static struct spi_board_info spi_info[] __initconst = { |
| 258 | }; |
| 259 | |
Cyril Chemparathy | 57a58a2 | 2010-05-18 12:51:21 -0400 | [diff] [blame] | 260 | static __init void tnetv107x_evm_board_init(void) |
| 261 | { |
| 262 | davinci_cfg_reg_list(sdio1_pins); |
| 263 | davinci_cfg_reg_list(uart1_pins); |
Cyril Chemparathy | 08e0e1d | 2011-01-18 19:21:40 +0000 | [diff] [blame] | 264 | davinci_cfg_reg_list(ssp_pins); |
Cyril Chemparathy | 57a58a2 | 2010-05-18 12:51:21 -0400 | [diff] [blame] | 265 | |
| 266 | tnetv107x_devices_init(&evm_device_info); |
Cyril Chemparathy | f6e5306 | 2011-01-18 19:21:41 +0000 | [diff] [blame] | 267 | |
| 268 | spi_register_board_info(spi_info, ARRAY_SIZE(spi_info)); |
Cyril Chemparathy | 57a58a2 | 2010-05-18 12:51:21 -0400 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | #ifdef CONFIG_SERIAL_8250_CONSOLE |
| 272 | static int __init tnetv107x_evm_console_init(void) |
| 273 | { |
| 274 | return add_preferred_console("ttyS", 0, "115200"); |
| 275 | } |
| 276 | console_initcall(tnetv107x_evm_console_init); |
| 277 | #endif |
| 278 | |
| 279 | MACHINE_START(TNETV107X, "TNETV107X EVM") |
Cyril Chemparathy | 57a58a2 | 2010-05-18 12:51:21 -0400 | [diff] [blame] | 280 | .boot_params = (TNETV107X_DDR_BASE + 0x100), |
| 281 | .map_io = tnetv107x_init, |
| 282 | .init_irq = cp_intc_init, |
| 283 | .timer = &davinci_timer, |
| 284 | .init_machine = tnetv107x_evm_board_init, |
| 285 | MACHINE_END |