1/* 2 * board-overo.c (Gumstix Overo) 3 * 4 * Initial code: Steve Sakoman <steve@sakoman.com> 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 8 * version 2 as published by the Free Software Foundation. 9 * 10 * This program is distributed in the hope that it will be useful, but 11 * WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 18 * 02110-1301 USA 19 * 20 */ 21 22#include <linux/clk.h> 23#include <linux/delay.h> 24#include <linux/err.h> 25#include <linux/init.h> 26#include <linux/io.h> 27#include <linux/kernel.h> 28#include <linux/platform_device.h> 29#include <linux/i2c/twl.h> 30#include <linux/regulator/machine.h> 31 32#include <linux/mtd/mtd.h> 33#include <linux/mtd/nand.h> 34#include <linux/mtd/partitions.h> 35 36#include <asm/mach-types.h> 37#include <asm/mach/arch.h> 38#include <asm/mach/flash.h> 39#include <asm/mach/map.h> 40 41#include <plat/board.h> 42#include <plat/common.h> 43#include <mach/gpio.h> 44#include <plat/gpmc.h> 45#include <mach/hardware.h> 46#include <plat/nand.h> 47#include <plat/usb.h> 48 49#include "mux.h" 50#include "sdram-micron-mt46h32m32lf-6.h" 51#include "hsmmc.h" 52 53#define OVERO_GPIO_BT_XGATE 15 54#define OVERO_GPIO_W2W_NRESET 16 55#define OVERO_GPIO_PENDOWN 114 56#define OVERO_GPIO_BT_NRESET 164 57#define OVERO_GPIO_USBH_CPEN 168 58#define OVERO_GPIO_USBH_NRESET 183 59 60#define NAND_BLOCK_SIZE SZ_128K 61 62#define OVERO_SMSC911X_CS 5 63#define OVERO_SMSC911X_GPIO 176 64#define OVERO_SMSC911X2_CS 4 65#define OVERO_SMSC911X2_GPIO 65 66 67#if defined(CONFIG_TOUCHSCREEN_ADS7846) || defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE) 68 69#include <plat/mcspi.h> 70#include <linux/spi/spi.h> 71#include <linux/spi/ads7846.h> 72 73static struct omap2_mcspi_device_config ads7846_mcspi_config = { 74 .turbo_mode = 0, 75 .single_channel = 1, /* 0: slave, 1: master */ 76}; 77 78static int ads7846_get_pendown_state(void) 79{ 80 return !gpio_get_value(OVERO_GPIO_PENDOWN); 81} 82 83static struct ads7846_platform_data ads7846_config = { 84 .x_max = 0x0fff, 85 .y_max = 0x0fff, 86 .x_plate_ohms = 180, 87 .pressure_max = 255, 88 .debounce_max = 10, 89 .debounce_tol = 3, 90 .debounce_rep = 1, 91 .get_pendown_state = ads7846_get_pendown_state, 92 .keep_vref_on = 1, 93}; 94 95static struct spi_board_info overo_spi_board_info[] __initdata = { 96 { 97 .modalias = "ads7846", 98 .bus_num = 1, 99 .chip_select = 0, 100 .max_speed_hz = 1500000, 101 .controller_data = &ads7846_mcspi_config, 102 .irq = OMAP_GPIO_IRQ(OVERO_GPIO_PENDOWN), 103 .platform_data = &ads7846_config, 104 } 105}; 106 107static void __init overo_ads7846_init(void) 108{ 109 if ((gpio_request(OVERO_GPIO_PENDOWN, "ADS7846_PENDOWN") == 0) && 110 (gpio_direction_input(OVERO_GPIO_PENDOWN) == 0)) { 111 gpio_export(OVERO_GPIO_PENDOWN, 0); 112 } else { 113 printk(KERN_ERR "could not obtain gpio for ADS7846_PENDOWN\n"); 114 return; 115 } 116 117 spi_register_board_info(overo_spi_board_info, 118 ARRAY_SIZE(overo_spi_board_info)); 119} 120 121#else 122static inline void __init overo_ads7846_init(void) { return; } 123#endif 124 125#if defined(CONFIG_SMSC911X) || defined(CONFIG_SMSC911X_MODULE) 126 127#include <linux/smsc911x.h> 128 129static struct resource overo_smsc911x_resources[] = { 130 { 131 .name = "smsc911x-memory", 132 .flags = IORESOURCE_MEM, 133 }, 134 { 135 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL, 136 }, 137}; 138 139static struct resource overo_smsc911x2_resources[] = { 140 { 141 .name = "smsc911x2-memory", 142 .flags = IORESOURCE_MEM, 143 }, 144 { 145 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL, 146 }, 147}; 148 149static struct smsc911x_platform_config overo_smsc911x_config = { 150 .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW, 151 .irq_type = SMSC911X_IRQ_TYPE_OPEN_DRAIN, 152 .flags = SMSC911X_USE_32BIT , 153 .phy_interface = PHY_INTERFACE_MODE_MII, 154}; 155 156static struct platform_device overo_smsc911x_device = { 157 .name = "smsc911x", 158 .id = 0, 159 .num_resources = ARRAY_SIZE(overo_smsc911x_resources), 160 .resource = overo_smsc911x_resources, 161 .dev = { 162 .platform_data = &overo_smsc911x_config, 163 }, 164}; 165 166static struct platform_device overo_smsc911x2_device = { 167 .name = "smsc911x", 168 .id = 1, 169 .num_resources = ARRAY_SIZE(overo_smsc911x2_resources), 170 .resource = overo_smsc911x2_resources, 171 .dev = { 172 .platform_data = &overo_smsc911x_config, 173 }, 174}; 175 176static struct platform_device *smsc911x_devices[] = { 177 &overo_smsc911x_device, 178 &overo_smsc911x2_device, 179}; 180 181static inline void __init overo_init_smsc911x(void) 182{ 183 unsigned long cs_mem_base, cs_mem_base2; 184 185 /* set up first smsc911x chip */ 186 187 if (gpmc_cs_request(OVERO_SMSC911X_CS, SZ_16M, &cs_mem_base) < 0) { 188 printk(KERN_ERR "Failed request for GPMC mem for smsc911x\n"); 189 return; 190 } 191 192 overo_smsc911x_resources[0].start = cs_mem_base + 0x0; 193 overo_smsc911x_resources[0].end = cs_mem_base + 0xff; 194 195 if ((gpio_request(OVERO_SMSC911X_GPIO, "SMSC911X IRQ") == 0) && 196 (gpio_direction_input(OVERO_SMSC911X_GPIO) == 0)) { 197 gpio_export(OVERO_SMSC911X_GPIO, 0); 198 } else { 199 printk(KERN_ERR "could not obtain gpio for SMSC911X IRQ\n"); 200 return; 201 } 202 203 overo_smsc911x_resources[1].start = OMAP_GPIO_IRQ(OVERO_SMSC911X_GPIO); 204 overo_smsc911x_resources[1].end = 0; 205 206 /* set up second smsc911x chip */ 207 208 if (gpmc_cs_request(OVERO_SMSC911X2_CS, SZ_16M, &cs_mem_base2) < 0) { 209 printk(KERN_ERR "Failed request for GPMC mem for smsc911x2\n"); 210 return; 211 } 212 213 overo_smsc911x2_resources[0].start = cs_mem_base2 + 0x0; 214 overo_smsc911x2_resources[0].end = cs_mem_base2 + 0xff; 215 216 if ((gpio_request(OVERO_SMSC911X2_GPIO, "SMSC911X2 IRQ") == 0) && 217 (gpio_direction_input(OVERO_SMSC911X2_GPIO) == 0)) { 218 gpio_export(OVERO_SMSC911X2_GPIO, 0); 219 } else { 220 printk(KERN_ERR "could not obtain gpio for SMSC911X2 IRQ\n"); 221 return; 222 } 223 224 overo_smsc911x2_resources[1].start = OMAP_GPIO_IRQ(OVERO_SMSC911X2_GPIO); 225 overo_smsc911x2_resources[1].end = 0; 226 227 platform_add_devices(smsc911x_devices, ARRAY_SIZE(smsc911x_devices)); 228} 229 230#else 231static inline void __init overo_init_smsc911x(void) { return; } 232#endif 233 234static struct mtd_partition overo_nand_partitions[] = { 235 { 236 .name = "xloader", 237 .offset = 0, /* Offset = 0x00000 */ 238 .size = 4 * NAND_BLOCK_SIZE, 239 .mask_flags = MTD_WRITEABLE 240 }, 241 { 242 .name = "uboot", 243 .offset = MTDPART_OFS_APPEND, /* Offset = 0x80000 */ 244 .size = 14 * NAND_BLOCK_SIZE, 245 }, 246 { 247 .name = "uboot environment", 248 .offset = MTDPART_OFS_APPEND, /* Offset = 0x240000 */ 249 .size = 2 * NAND_BLOCK_SIZE, 250 }, 251 { 252 .name = "linux", 253 .offset = MTDPART_OFS_APPEND, /* Offset = 0x280000 */ 254 .size = 32 * NAND_BLOCK_SIZE, 255 }, 256 { 257 .name = "rootfs", 258 .offset = MTDPART_OFS_APPEND, /* Offset = 0x680000 */ 259 .size = MTDPART_SIZ_FULL, 260 }, 261}; 262 263static struct omap_nand_platform_data overo_nand_data = { 264 .parts = overo_nand_partitions, 265 .nr_parts = ARRAY_SIZE(overo_nand_partitions), 266 .dma_channel = -1, /* disable DMA in OMAP NAND driver */ 267}; 268 269static void __init overo_flash_init(void) 270{ 271 u8 cs = 0; 272 u8 nandcs = GPMC_CS_NUM + 1; 273 274 /* find out the chip-select on which NAND exists */ 275 while (cs < GPMC_CS_NUM) { 276 u32 ret = 0; 277 ret = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG1); 278 279 if ((ret & 0xC00) == 0x800) { 280 printk(KERN_INFO "Found NAND on CS%d\n", cs); 281 if (nandcs > GPMC_CS_NUM) 282 nandcs = cs; 283 } 284 cs++; 285 } 286 287 if (nandcs > GPMC_CS_NUM) { 288 printk(KERN_INFO "NAND: Unable to find configuration " 289 "in GPMC\n "); 290 return; 291 } 292 293 if (nandcs < GPMC_CS_NUM) { 294 overo_nand_data.cs = nandcs; 295 296 printk(KERN_INFO "Registering NAND on CS%d\n", nandcs); 297 if (gpmc_nand_init(&overo_nand_data) < 0) 298 printk(KERN_ERR "Unable to register NAND device\n"); 299 } 300} 301 302static struct omap2_hsmmc_info mmc[] = { 303 { 304 .mmc = 1, 305 .wires = 4, 306 .gpio_cd = -EINVAL, 307 .gpio_wp = -EINVAL, 308 }, 309 { 310 .mmc = 2, 311 .wires = 4, 312 .gpio_cd = -EINVAL, 313 .gpio_wp = -EINVAL, 314 .transceiver = true, 315 .ocr_mask = 0x00100000, /* 3.3V */ 316 }, 317 {} /* Terminator */ 318}; 319 320static struct regulator_consumer_supply overo_vmmc1_supply = { 321 .supply = "vmmc", 322}; 323 324static int overo_twl_gpio_setup(struct device *dev, 325 unsigned gpio, unsigned ngpio) 326{ 327 omap2_hsmmc_init(mmc); 328 329 overo_vmmc1_supply.dev = mmc[0].dev; 330 331 return 0; 332} 333 334static struct twl4030_gpio_platform_data overo_gpio_data = { 335 .gpio_base = OMAP_MAX_GPIO_LINES, 336 .irq_base = TWL4030_GPIO_IRQ_BASE, 337 .irq_end = TWL4030_GPIO_IRQ_END, 338 .setup = overo_twl_gpio_setup, 339}; 340 341static struct twl4030_usb_data overo_usb_data = { 342 .usb_mode = T2_USB_MODE_ULPI, 343}; 344 345static struct regulator_init_data overo_vmmc1 = { 346 .constraints = { 347 .min_uV = 1850000, 348 .max_uV = 3150000, 349 .valid_modes_mask = REGULATOR_MODE_NORMAL 350 | REGULATOR_MODE_STANDBY, 351 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE 352 | REGULATOR_CHANGE_MODE 353 | REGULATOR_CHANGE_STATUS, 354 }, 355 .num_consumer_supplies = 1, 356 .consumer_supplies = &overo_vmmc1_supply, 357}; 358 359static struct twl4030_codec_audio_data overo_audio_data = { 360 .audio_mclk = 26000000, 361}; 362 363static struct twl4030_codec_data overo_codec_data = { 364 .audio_mclk = 26000000, 365 .audio = &overo_audio_data, 366}; 367 368/* mmc2 (WLAN) and Bluetooth don't use twl4030 regulators */ 369 370static struct twl4030_platform_data overo_twldata = { 371 .irq_base = TWL4030_IRQ_BASE, 372 .irq_end = TWL4030_IRQ_END, 373 .gpio = &overo_gpio_data, 374 .usb = &overo_usb_data, 375 .codec = &overo_codec_data, 376 .vmmc1 = &overo_vmmc1, 377}; 378 379static struct i2c_board_info __initdata overo_i2c_boardinfo[] = { 380 { 381 I2C_BOARD_INFO("tps65950", 0x48), 382 .flags = I2C_CLIENT_WAKE, 383 .irq = INT_34XX_SYS_NIRQ, 384 .platform_data = &overo_twldata, 385 }, 386}; 387 388static int __init overo_i2c_init(void) 389{ 390 omap_register_i2c_bus(1, 2600, overo_i2c_boardinfo, 391 ARRAY_SIZE(overo_i2c_boardinfo)); 392 /* i2c2 pins are used for gpio */ 393 omap_register_i2c_bus(3, 400, NULL, 0); 394 return 0; 395} 396 397static struct platform_device overo_lcd_device = { 398 .name = "overo_lcd", 399 .id = -1, 400}; 401 402static struct omap_lcd_config overo_lcd_config __initdata = { 403 .ctrl_name = "internal", 404}; 405 406static struct omap_board_config_kernel overo_config[] __initdata = { 407 { OMAP_TAG_LCD, &overo_lcd_config }, 408}; 409 410static void __init overo_init_irq(void) 411{ 412 omap_board_config = overo_config; 413 omap_board_config_size = ARRAY_SIZE(overo_config); 414 omap2_init_common_hw(mt46h32m32lf6_sdrc_params, 415 mt46h32m32lf6_sdrc_params); 416 omap_init_irq(); 417 omap_gpio_init(); 418} 419 420static struct platform_device *overo_devices[] __initdata = { 421 &overo_lcd_device, 422}; 423 424static const struct ehci_hcd_omap_platform_data ehci_pdata __initconst = { 425 .port_mode[0] = EHCI_HCD_OMAP_MODE_UNKNOWN, 426 .port_mode[1] = EHCI_HCD_OMAP_MODE_PHY, 427 .port_mode[2] = EHCI_HCD_OMAP_MODE_UNKNOWN, 428 429 .phy_reset = true, 430 .reset_gpio_port[0] = -EINVAL, 431 .reset_gpio_port[1] = OVERO_GPIO_USBH_NRESET, 432 .reset_gpio_port[2] = -EINVAL 433}; 434 435#ifdef CONFIG_OMAP_MUX 436static struct omap_board_mux board_mux[] __initdata = { 437 { .reg_offset = OMAP_MUX_TERMINATOR }, 438}; 439#else 440#define board_mux NULL 441#endif 442 443static struct omap_musb_board_data musb_board_data = { 444 .interface_type = MUSB_INTERFACE_ULPI, 445 .mode = MUSB_OTG, 446 .power = 100, 447}; 448 449static void __init overo_init(void) 450{ 451 omap3_mux_init(board_mux, OMAP_PACKAGE_CBB); 452 overo_i2c_init(); 453 platform_add_devices(overo_devices, ARRAY_SIZE(overo_devices)); 454 omap_serial_init(); 455 overo_flash_init(); 456 usb_musb_init(&musb_board_data); 457 usb_ehci_init(&ehci_pdata); 458 overo_ads7846_init(); 459 overo_init_smsc911x(); 460 461 /* Ensure SDRC pins are mux'd for self-refresh */ 462 omap_mux_init_signal("sdrc_cke0", OMAP_PIN_OUTPUT); 463 omap_mux_init_signal("sdrc_cke1", OMAP_PIN_OUTPUT); 464 465 if ((gpio_request(OVERO_GPIO_W2W_NRESET, 466 "OVERO_GPIO_W2W_NRESET") == 0) && 467 (gpio_direction_output(OVERO_GPIO_W2W_NRESET, 1) == 0)) { 468 gpio_export(OVERO_GPIO_W2W_NRESET, 0); 469 gpio_set_value(OVERO_GPIO_W2W_NRESET, 0); 470 udelay(10); 471 gpio_set_value(OVERO_GPIO_W2W_NRESET, 1); 472 } else { 473 printk(KERN_ERR "could not obtain gpio for " 474 "OVERO_GPIO_W2W_NRESET\n"); 475 } 476 477 if ((gpio_request(OVERO_GPIO_BT_XGATE, "OVERO_GPIO_BT_XGATE") == 0) && 478 (gpio_direction_output(OVERO_GPIO_BT_XGATE, 0) == 0)) 479 gpio_export(OVERO_GPIO_BT_XGATE, 0); 480 else 481 printk(KERN_ERR "could not obtain gpio for OVERO_GPIO_BT_XGATE\n"); 482 483 if ((gpio_request(OVERO_GPIO_BT_NRESET, "OVERO_GPIO_BT_NRESET") == 0) && 484 (gpio_direction_output(OVERO_GPIO_BT_NRESET, 1) == 0)) { 485 gpio_export(OVERO_GPIO_BT_NRESET, 0); 486 gpio_set_value(OVERO_GPIO_BT_NRESET, 0); 487 mdelay(6); 488 gpio_set_value(OVERO_GPIO_BT_NRESET, 1); 489 } else { 490 printk(KERN_ERR "could not obtain gpio for " 491 "OVERO_GPIO_BT_NRESET\n"); 492 } 493 494 if ((gpio_request(OVERO_GPIO_USBH_CPEN, "OVERO_GPIO_USBH_CPEN") == 0) && 495 (gpio_direction_output(OVERO_GPIO_USBH_CPEN, 1) == 0)) 496 gpio_export(OVERO_GPIO_USBH_CPEN, 0); 497 else 498 printk(KERN_ERR "could not obtain gpio for " 499 "OVERO_GPIO_USBH_CPEN\n"); 500} 501 502MACHINE_START(OVERO, "Gumstix Overo") 503 .phys_io = 0x48000000, 504 .io_pg_offst = ((0xfa000000) >> 18) & 0xfffc, 505 .boot_params = 0x80000100, 506 .map_io = omap3_map_io, 507 .reserve = omap_reserve, 508 .init_irq = overo_init_irq, 509 .init_machine = overo_init, 510 .timer = &omap_timer, 511MACHINE_END 512