Kevin Hilman | e38d92f | 2009-04-29 17:44:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * TI DaVinci DM646X EVM board |
| 3 | * |
| 4 | * Derived from: arch/arm/mach-davinci/board-evm.c |
| 5 | * Copyright (C) 2006 Texas Instruments. |
| 6 | * |
| 7 | * (C) 2007-2008, MontaVista Software, Inc. |
| 8 | * |
| 9 | * This file is licensed under the terms of the GNU General Public License |
| 10 | * version 2. This program is licensed "as is" without any warranty of any |
| 11 | * kind, whether express or implied. |
| 12 | * |
| 13 | */ |
| 14 | |
| 15 | /************************************************************************** |
| 16 | * Included Files |
| 17 | **************************************************************************/ |
| 18 | |
| 19 | #include <linux/kernel.h> |
| 20 | #include <linux/module.h> |
| 21 | #include <linux/init.h> |
| 22 | #include <linux/fs.h> |
| 23 | #include <linux/major.h> |
| 24 | #include <linux/root_dev.h> |
| 25 | #include <linux/dma-mapping.h> |
| 26 | #include <linux/serial.h> |
| 27 | #include <linux/serial_8250.h> |
| 28 | #include <linux/leds.h> |
| 29 | #include <linux/gpio.h> |
| 30 | #include <linux/io.h> |
| 31 | #include <linux/platform_device.h> |
| 32 | #include <linux/i2c.h> |
| 33 | #include <linux/i2c/at24.h> |
| 34 | #include <linux/i2c/pcf857x.h> |
| 35 | #include <linux/etherdevice.h> |
| 36 | |
| 37 | #include <asm/setup.h> |
| 38 | #include <asm/mach-types.h> |
| 39 | #include <asm/mach/arch.h> |
| 40 | #include <asm/mach/map.h> |
| 41 | #include <asm/mach/flash.h> |
| 42 | |
| 43 | #include <mach/dm646x.h> |
| 44 | #include <mach/common.h> |
| 45 | #include <mach/psc.h> |
| 46 | #include <mach/serial.h> |
| 47 | #include <mach/i2c.h> |
Kevin Hilman | ac7b75b | 2009-05-07 06:19:40 -0700 | [diff] [blame] | 48 | #include <mach/mmc.h> |
| 49 | #include <mach/emac.h> |
| 50 | |
Hemant Pedanekar | 548197b | 2009-07-17 23:30:36 +0530 | [diff] [blame^] | 51 | #if defined(CONFIG_BLK_DEV_PALMCHIP_BK3710) || \ |
| 52 | defined(CONFIG_BLK_DEV_PALMCHIP_BK3710_MODULE) |
| 53 | #define HAS_ATA 1 |
| 54 | #else |
| 55 | #define HAS_ATA 0 |
| 56 | #endif |
| 57 | |
| 58 | /* CPLD Register 0 bits to control ATA */ |
| 59 | #define DM646X_EVM_ATA_RST BIT(0) |
| 60 | #define DM646X_EVM_ATA_PWD BIT(1) |
| 61 | |
Kevin Hilman | ac7b75b | 2009-05-07 06:19:40 -0700 | [diff] [blame] | 62 | #define DM646X_EVM_PHY_MASK (0x2) |
| 63 | #define DM646X_EVM_MDIO_FREQUENCY (2200000) /* PHY bus frequency */ |
| 64 | |
Kevin Hilman | e38d92f | 2009-04-29 17:44:58 -0700 | [diff] [blame] | 65 | static struct davinci_uart_config uart_config __initdata = { |
| 66 | .enabled_uarts = (1 << 0), |
| 67 | }; |
| 68 | |
Hemant Pedanekar | 548197b | 2009-07-17 23:30:36 +0530 | [diff] [blame^] | 69 | /* CPLD Register 0 Client: used for I/O Control */ |
| 70 | static int cpld_reg0_probe(struct i2c_client *client, |
| 71 | const struct i2c_device_id *id) |
| 72 | { |
| 73 | if (HAS_ATA) { |
| 74 | u8 data; |
| 75 | struct i2c_msg msg[2] = { |
| 76 | { |
| 77 | .addr = client->addr, |
| 78 | .flags = I2C_M_RD, |
| 79 | .len = 1, |
| 80 | .buf = &data, |
| 81 | }, |
| 82 | { |
| 83 | .addr = client->addr, |
| 84 | .flags = 0, |
| 85 | .len = 1, |
| 86 | .buf = &data, |
| 87 | }, |
| 88 | }; |
| 89 | |
| 90 | /* Clear ATA_RSTn and ATA_PWD bits to enable ATA operation. */ |
| 91 | i2c_transfer(client->adapter, msg, 1); |
| 92 | data &= ~(DM646X_EVM_ATA_RST | DM646X_EVM_ATA_PWD); |
| 93 | i2c_transfer(client->adapter, msg + 1, 1); |
| 94 | } |
| 95 | |
| 96 | return 0; |
| 97 | } |
| 98 | |
| 99 | static const struct i2c_device_id cpld_reg_ids[] = { |
| 100 | { "cpld_reg0", 0, }, |
| 101 | { }, |
| 102 | }; |
| 103 | |
| 104 | static struct i2c_driver dm6467evm_cpld_driver = { |
| 105 | .driver.name = "cpld_reg0", |
| 106 | .id_table = cpld_reg_ids, |
| 107 | .probe = cpld_reg0_probe, |
| 108 | }; |
| 109 | |
Kevin Hilman | e38d92f | 2009-04-29 17:44:58 -0700 | [diff] [blame] | 110 | /* LEDS */ |
| 111 | |
| 112 | static struct gpio_led evm_leds[] = { |
| 113 | { .name = "DS1", .active_low = 1, }, |
| 114 | { .name = "DS2", .active_low = 1, }, |
| 115 | { .name = "DS3", .active_low = 1, }, |
| 116 | { .name = "DS4", .active_low = 1, }, |
| 117 | }; |
| 118 | |
| 119 | static __initconst struct gpio_led_platform_data evm_led_data = { |
| 120 | .num_leds = ARRAY_SIZE(evm_leds), |
| 121 | .leds = evm_leds, |
| 122 | }; |
| 123 | |
| 124 | static struct platform_device *evm_led_dev; |
| 125 | |
| 126 | static int evm_led_setup(struct i2c_client *client, int gpio, |
| 127 | unsigned int ngpio, void *c) |
| 128 | { |
| 129 | struct gpio_led *leds = evm_leds; |
| 130 | int status; |
| 131 | |
| 132 | while (ngpio--) { |
| 133 | leds->gpio = gpio++; |
| 134 | leds++; |
| 135 | }; |
| 136 | |
| 137 | evm_led_dev = platform_device_alloc("leds-gpio", 0); |
| 138 | platform_device_add_data(evm_led_dev, &evm_led_data, |
| 139 | sizeof(evm_led_data)); |
| 140 | |
| 141 | evm_led_dev->dev.parent = &client->dev; |
| 142 | status = platform_device_add(evm_led_dev); |
| 143 | if (status < 0) { |
| 144 | platform_device_put(evm_led_dev); |
| 145 | evm_led_dev = NULL; |
| 146 | } |
| 147 | return status; |
| 148 | } |
| 149 | |
| 150 | static int evm_led_teardown(struct i2c_client *client, int gpio, |
| 151 | unsigned ngpio, void *c) |
| 152 | { |
| 153 | if (evm_led_dev) { |
| 154 | platform_device_unregister(evm_led_dev); |
| 155 | evm_led_dev = NULL; |
| 156 | } |
| 157 | return 0; |
| 158 | } |
| 159 | |
| 160 | static int evm_sw_gpio[4] = { -EINVAL, -EINVAL, -EINVAL, -EINVAL }; |
| 161 | |
| 162 | static int evm_sw_setup(struct i2c_client *client, int gpio, |
| 163 | unsigned ngpio, void *c) |
| 164 | { |
| 165 | int status; |
| 166 | int i; |
| 167 | char label[10]; |
| 168 | |
| 169 | for (i = 0; i < 4; ++i) { |
| 170 | snprintf(label, 10, "user_sw%d", i); |
| 171 | status = gpio_request(gpio, label); |
| 172 | if (status) |
| 173 | goto out_free; |
| 174 | evm_sw_gpio[i] = gpio++; |
| 175 | |
| 176 | status = gpio_direction_input(evm_sw_gpio[i]); |
| 177 | if (status) { |
| 178 | gpio_free(evm_sw_gpio[i]); |
| 179 | evm_sw_gpio[i] = -EINVAL; |
| 180 | goto out_free; |
| 181 | } |
| 182 | |
| 183 | status = gpio_export(evm_sw_gpio[i], 0); |
| 184 | if (status) { |
| 185 | gpio_free(evm_sw_gpio[i]); |
| 186 | evm_sw_gpio[i] = -EINVAL; |
| 187 | goto out_free; |
| 188 | } |
| 189 | } |
| 190 | return status; |
| 191 | out_free: |
| 192 | for (i = 0; i < 4; ++i) { |
| 193 | if (evm_sw_gpio[i] != -EINVAL) { |
| 194 | gpio_free(evm_sw_gpio[i]); |
| 195 | evm_sw_gpio[i] = -EINVAL; |
| 196 | } |
| 197 | } |
| 198 | return status; |
| 199 | } |
| 200 | |
| 201 | static int evm_sw_teardown(struct i2c_client *client, int gpio, |
| 202 | unsigned ngpio, void *c) |
| 203 | { |
| 204 | int i; |
| 205 | |
| 206 | for (i = 0; i < 4; ++i) { |
| 207 | if (evm_sw_gpio[i] != -EINVAL) { |
| 208 | gpio_unexport(evm_sw_gpio[i]); |
| 209 | gpio_free(evm_sw_gpio[i]); |
| 210 | evm_sw_gpio[i] = -EINVAL; |
| 211 | } |
| 212 | } |
| 213 | return 0; |
| 214 | } |
| 215 | |
| 216 | static int evm_pcf_setup(struct i2c_client *client, int gpio, |
| 217 | unsigned int ngpio, void *c) |
| 218 | { |
| 219 | int status; |
| 220 | |
| 221 | if (ngpio < 8) |
| 222 | return -EINVAL; |
| 223 | |
| 224 | status = evm_sw_setup(client, gpio, 4, c); |
| 225 | if (status) |
| 226 | return status; |
| 227 | |
| 228 | return evm_led_setup(client, gpio+4, 4, c); |
| 229 | } |
| 230 | |
| 231 | static int evm_pcf_teardown(struct i2c_client *client, int gpio, |
| 232 | unsigned int ngpio, void *c) |
| 233 | { |
| 234 | BUG_ON(ngpio < 8); |
| 235 | |
| 236 | evm_sw_teardown(client, gpio, 4, c); |
| 237 | evm_led_teardown(client, gpio+4, 4, c); |
| 238 | |
| 239 | return 0; |
| 240 | } |
| 241 | |
| 242 | static struct pcf857x_platform_data pcf_data = { |
| 243 | .gpio_base = DAVINCI_N_GPIO+1, |
| 244 | .setup = evm_pcf_setup, |
| 245 | .teardown = evm_pcf_teardown, |
| 246 | }; |
| 247 | |
| 248 | /* Most of this EEPROM is unused, but U-Boot uses some data: |
| 249 | * - 0x7f00, 6 bytes Ethernet Address |
| 250 | * - ... newer boards may have more |
| 251 | */ |
Kevin Hilman | e38d92f | 2009-04-29 17:44:58 -0700 | [diff] [blame] | 252 | |
| 253 | static struct at24_platform_data eeprom_info = { |
| 254 | .byte_len = (256*1024) / 8, |
| 255 | .page_size = 64, |
| 256 | .flags = AT24_FLAG_ADDR16, |
Mark A. Greer | b14dc0f | 2009-04-15 12:41:27 -0700 | [diff] [blame] | 257 | .setup = davinci_get_mac_addr, |
| 258 | .context = (void *)0x7f00, |
Kevin Hilman | e38d92f | 2009-04-29 17:44:58 -0700 | [diff] [blame] | 259 | }; |
| 260 | |
Chaithrika U S | 25acf55 | 2009-06-05 06:28:08 -0400 | [diff] [blame] | 261 | static u8 dm646x_iis_serializer_direction[] = { |
| 262 | TX_MODE, RX_MODE, INACTIVE_MODE, INACTIVE_MODE, |
| 263 | }; |
| 264 | |
| 265 | static u8 dm646x_dit_serializer_direction[] = { |
| 266 | TX_MODE, |
| 267 | }; |
| 268 | |
| 269 | static struct snd_platform_data dm646x_evm_snd_data[] = { |
| 270 | { |
| 271 | .clk_name = "mcasp0", |
| 272 | .tx_dma_offset = 0x400, |
| 273 | .rx_dma_offset = 0x400, |
| 274 | .op_mode = DAVINCI_MCASP_IIS_MODE, |
| 275 | .num_serializer = ARRAY_SIZE(dm646x_iis_serializer_direction), |
| 276 | .tdm_slots = 2, |
| 277 | .serial_dir = dm646x_iis_serializer_direction, |
| 278 | .eventq_no = EVENTQ_0, |
| 279 | }, |
| 280 | { |
| 281 | .clk_name = "mcasp1", |
| 282 | .tx_dma_offset = 0x400, |
| 283 | .rx_dma_offset = 0, |
| 284 | .op_mode = DAVINCI_MCASP_DIT_MODE, |
| 285 | .num_serializer = ARRAY_SIZE(dm646x_dit_serializer_direction), |
| 286 | .tdm_slots = 32, |
| 287 | .serial_dir = dm646x_dit_serializer_direction, |
| 288 | .eventq_no = EVENTQ_0, |
| 289 | }, |
| 290 | }; |
| 291 | |
Kevin Hilman | e38d92f | 2009-04-29 17:44:58 -0700 | [diff] [blame] | 292 | static struct i2c_board_info __initdata i2c_info[] = { |
| 293 | { |
| 294 | I2C_BOARD_INFO("24c256", 0x50), |
| 295 | .platform_data = &eeprom_info, |
| 296 | }, |
| 297 | { |
| 298 | I2C_BOARD_INFO("pcf8574a", 0x38), |
| 299 | .platform_data = &pcf_data, |
| 300 | }, |
Hemant Pedanekar | 548197b | 2009-07-17 23:30:36 +0530 | [diff] [blame^] | 301 | { |
| 302 | I2C_BOARD_INFO("cpld_reg0", 0x3a), |
| 303 | }, |
Kevin Hilman | e38d92f | 2009-04-29 17:44:58 -0700 | [diff] [blame] | 304 | }; |
| 305 | |
| 306 | static struct davinci_i2c_platform_data i2c_pdata = { |
| 307 | .bus_freq = 100 /* kHz */, |
| 308 | .bus_delay = 0 /* usec */, |
| 309 | }; |
| 310 | |
| 311 | static void __init evm_init_i2c(void) |
| 312 | { |
| 313 | davinci_init_i2c(&i2c_pdata); |
Hemant Pedanekar | 548197b | 2009-07-17 23:30:36 +0530 | [diff] [blame^] | 314 | i2c_add_driver(&dm6467evm_cpld_driver); |
Kevin Hilman | e38d92f | 2009-04-29 17:44:58 -0700 | [diff] [blame] | 315 | i2c_register_board_info(1, i2c_info, ARRAY_SIZE(i2c_info)); |
| 316 | } |
| 317 | |
| 318 | static void __init davinci_map_io(void) |
| 319 | { |
Kevin Hilman | e38d92f | 2009-04-29 17:44:58 -0700 | [diff] [blame] | 320 | dm646x_init(); |
| 321 | } |
| 322 | |
| 323 | static __init void evm_init(void) |
| 324 | { |
Mark A. Greer | 972412b | 2009-04-15 12:40:56 -0700 | [diff] [blame] | 325 | struct davinci_soc_info *soc_info = &davinci_soc_info; |
| 326 | |
Kevin Hilman | e38d92f | 2009-04-29 17:44:58 -0700 | [diff] [blame] | 327 | evm_init_i2c(); |
| 328 | davinci_serial_init(&uart_config); |
Chaithrika U S | 25acf55 | 2009-06-05 06:28:08 -0400 | [diff] [blame] | 329 | dm646x_init_mcasp0(&dm646x_evm_snd_data[0]); |
| 330 | dm646x_init_mcasp1(&dm646x_evm_snd_data[1]); |
Mark A. Greer | 972412b | 2009-04-15 12:40:56 -0700 | [diff] [blame] | 331 | |
Hemant Pedanekar | 548197b | 2009-07-17 23:30:36 +0530 | [diff] [blame^] | 332 | if (HAS_ATA) |
| 333 | dm646x_init_ide(); |
| 334 | |
Mark A. Greer | 972412b | 2009-04-15 12:40:56 -0700 | [diff] [blame] | 335 | soc_info->emac_pdata->phy_mask = DM646X_EVM_PHY_MASK; |
| 336 | soc_info->emac_pdata->mdio_max_freq = DM646X_EVM_MDIO_FREQUENCY; |
Kevin Hilman | e38d92f | 2009-04-29 17:44:58 -0700 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | static __init void davinci_dm646x_evm_irq_init(void) |
| 340 | { |
| 341 | davinci_irq_init(); |
| 342 | } |
| 343 | |
| 344 | MACHINE_START(DAVINCI_DM6467_EVM, "DaVinci DM646x EVM") |
| 345 | .phys_io = IO_PHYS, |
| 346 | .io_pg_offst = (__IO_ADDRESS(IO_PHYS) >> 18) & 0xfffc, |
| 347 | .boot_params = (0x80000100), |
| 348 | .map_io = davinci_map_io, |
| 349 | .init_irq = davinci_dm646x_evm_irq_init, |
| 350 | .timer = &davinci_timer, |
| 351 | .init_machine = evm_init, |
| 352 | MACHINE_END |
| 353 | |