Steve Sakoman | eba2645 | 2008-10-09 17:51:43 +0300 | [diff] [blame^] | 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 | |
| 30 | #include <linux/mtd/mtd.h> |
| 31 | #include <linux/mtd/nand.h> |
| 32 | #include <linux/mtd/partitions.h> |
| 33 | |
| 34 | #include <asm/mach-types.h> |
| 35 | #include <asm/mach/arch.h> |
| 36 | #include <asm/mach/flash.h> |
| 37 | #include <asm/mach/map.h> |
| 38 | |
| 39 | #include <mach/board-overo.h> |
| 40 | #include <mach/board.h> |
| 41 | #include <mach/common.h> |
| 42 | #include <mach/gpio.h> |
| 43 | #include <mach/gpmc.h> |
| 44 | #include <mach/hardware.h> |
| 45 | #include <mach/nand.h> |
| 46 | |
| 47 | #define NAND_BLOCK_SIZE SZ_128K |
| 48 | #define GPMC_CS0_BASE 0x60 |
| 49 | #define GPMC_CS_SIZE 0x30 |
| 50 | |
| 51 | static struct mtd_partition overo_nand_partitions[] = { |
| 52 | { |
| 53 | .name = "xloader", |
| 54 | .offset = 0, /* Offset = 0x00000 */ |
| 55 | .size = 4 * NAND_BLOCK_SIZE, |
| 56 | .mask_flags = MTD_WRITEABLE |
| 57 | }, |
| 58 | { |
| 59 | .name = "uboot", |
| 60 | .offset = MTDPART_OFS_APPEND, /* Offset = 0x80000 */ |
| 61 | .size = 14 * NAND_BLOCK_SIZE, |
| 62 | }, |
| 63 | { |
| 64 | .name = "uboot environment", |
| 65 | .offset = MTDPART_OFS_APPEND, /* Offset = 0x240000 */ |
| 66 | .size = 2 * NAND_BLOCK_SIZE, |
| 67 | }, |
| 68 | { |
| 69 | .name = "linux", |
| 70 | .offset = MTDPART_OFS_APPEND, /* Offset = 0x280000 */ |
| 71 | .size = 32 * NAND_BLOCK_SIZE, |
| 72 | }, |
| 73 | { |
| 74 | .name = "rootfs", |
| 75 | .offset = MTDPART_OFS_APPEND, /* Offset = 0x680000 */ |
| 76 | .size = MTDPART_SIZ_FULL, |
| 77 | }, |
| 78 | }; |
| 79 | |
| 80 | static struct omap_nand_platform_data overo_nand_data = { |
| 81 | .parts = overo_nand_partitions, |
| 82 | .nr_parts = ARRAY_SIZE(overo_nand_partitions), |
| 83 | .dma_channel = -1, /* disable DMA in OMAP NAND driver */ |
| 84 | }; |
| 85 | |
| 86 | static struct resource overo_nand_resource = { |
| 87 | .flags = IORESOURCE_MEM, |
| 88 | }; |
| 89 | |
| 90 | static struct platform_device overo_nand_device = { |
| 91 | .name = "omap2-nand", |
| 92 | .id = -1, |
| 93 | .dev = { |
| 94 | .platform_data = &overo_nand_data, |
| 95 | }, |
| 96 | .num_resources = 1, |
| 97 | .resource = &overo_nand_resource, |
| 98 | }; |
| 99 | |
| 100 | |
| 101 | static void __init overo_flash_init(void) |
| 102 | { |
| 103 | u8 cs = 0; |
| 104 | u8 nandcs = GPMC_CS_NUM + 1; |
| 105 | |
| 106 | u32 gpmc_base_add = OMAP34XX_GPMC_VIRT; |
| 107 | |
| 108 | /* find out the chip-select on which NAND exists */ |
| 109 | while (cs < GPMC_CS_NUM) { |
| 110 | u32 ret = 0; |
| 111 | ret = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG1); |
| 112 | |
| 113 | if ((ret & 0xC00) == 0x800) { |
| 114 | printk(KERN_INFO "Found NAND on CS%d\n", cs); |
| 115 | if (nandcs > GPMC_CS_NUM) |
| 116 | nandcs = cs; |
| 117 | } |
| 118 | cs++; |
| 119 | } |
| 120 | |
| 121 | if (nandcs > GPMC_CS_NUM) { |
| 122 | printk(KERN_INFO "NAND: Unable to find configuration " |
| 123 | "in GPMC\n "); |
| 124 | return; |
| 125 | } |
| 126 | |
| 127 | if (nandcs < GPMC_CS_NUM) { |
| 128 | overo_nand_data.cs = nandcs; |
| 129 | overo_nand_data.gpmc_cs_baseaddr = (void *) |
| 130 | (gpmc_base_add + GPMC_CS0_BASE + nandcs * GPMC_CS_SIZE); |
| 131 | overo_nand_data.gpmc_baseaddr = (void *) (gpmc_base_add); |
| 132 | |
| 133 | printk(KERN_INFO "Registering NAND on CS%d\n", nandcs); |
| 134 | if (platform_device_register(&overo_nand_device) < 0) |
| 135 | printk(KERN_ERR "Unable to register NAND device\n"); |
| 136 | } |
| 137 | } |
| 138 | static struct omap_uart_config overo_uart_config __initdata = { |
| 139 | .enabled_uarts = ((1 << 0) | (1 << 1) | (1 << 2)), |
| 140 | }; |
| 141 | |
| 142 | static int __init overo_i2c_init(void) |
| 143 | { |
| 144 | /* i2c2 pins are used for gpio */ |
| 145 | omap_register_i2c_bus(3, 400, NULL, 0); |
| 146 | return 0; |
| 147 | } |
| 148 | |
| 149 | static void __init overo_init_irq(void) |
| 150 | { |
| 151 | omap2_init_common_hw(); |
| 152 | omap_init_irq(); |
| 153 | omap_gpio_init(); |
| 154 | } |
| 155 | |
| 156 | static struct platform_device overo_lcd_device = { |
| 157 | .name = "overo_lcd", |
| 158 | .id = -1, |
| 159 | }; |
| 160 | |
| 161 | static struct omap_lcd_config overo_lcd_config __initdata = { |
| 162 | .ctrl_name = "internal", |
| 163 | }; |
| 164 | |
| 165 | static struct omap_board_config_kernel overo_config[] __initdata = { |
| 166 | { OMAP_TAG_UART, &overo_uart_config }, |
| 167 | { OMAP_TAG_LCD, &overo_lcd_config }, |
| 168 | }; |
| 169 | |
| 170 | static struct platform_device *overo_devices[] __initdata = { |
| 171 | &overo_lcd_device, |
| 172 | }; |
| 173 | |
| 174 | static void __init overo_init(void) |
| 175 | { |
| 176 | overo_i2c_init(); |
| 177 | platform_add_devices(overo_devices, ARRAY_SIZE(overo_devices)); |
| 178 | omap_board_config = overo_config; |
| 179 | omap_board_config_size = ARRAY_SIZE(overo_config); |
| 180 | omap_serial_init(); |
| 181 | overo_flash_init(); |
| 182 | |
| 183 | if ((gpio_request(OVERO_GPIO_W2W_NRESET, |
| 184 | "OVERO_GPIO_W2W_NRESET") == 0) && |
| 185 | (gpio_direction_output(OVERO_GPIO_W2W_NRESET, 1) == 0)) { |
| 186 | gpio_export(OVERO_GPIO_W2W_NRESET, 0); |
| 187 | gpio_set_value(OVERO_GPIO_W2W_NRESET, 0); |
| 188 | udelay(10); |
| 189 | gpio_set_value(OVERO_GPIO_W2W_NRESET, 1); |
| 190 | } else { |
| 191 | printk(KERN_ERR "could not obtain gpio for " |
| 192 | "OVERO_GPIO_W2W_NRESET\n"); |
| 193 | } |
| 194 | |
| 195 | if ((gpio_request(OVERO_GPIO_BT_XGATE, "OVERO_GPIO_BT_XGATE") == 0) && |
| 196 | (gpio_direction_output(OVERO_GPIO_BT_XGATE, 0) == 0)) |
| 197 | gpio_export(OVERO_GPIO_BT_XGATE, 0); |
| 198 | else |
| 199 | printk(KERN_ERR "could not obtain gpio for OVERO_GPIO_BT_XGATE\n"); |
| 200 | |
| 201 | if ((gpio_request(OVERO_GPIO_BT_NRESET, "OVERO_GPIO_BT_NRESET") == 0) && |
| 202 | (gpio_direction_output(OVERO_GPIO_BT_NRESET, 1) == 0)) { |
| 203 | gpio_export(OVERO_GPIO_BT_NRESET, 0); |
| 204 | gpio_set_value(OVERO_GPIO_BT_NRESET, 0); |
| 205 | mdelay(6); |
| 206 | gpio_set_value(OVERO_GPIO_BT_NRESET, 1); |
| 207 | } else { |
| 208 | printk(KERN_ERR "could not obtain gpio for " |
| 209 | "OVERO_GPIO_BT_NRESET\n"); |
| 210 | } |
| 211 | |
| 212 | if ((gpio_request(OVERO_GPIO_USBH_CPEN, "OVERO_GPIO_USBH_CPEN") == 0) && |
| 213 | (gpio_direction_output(OVERO_GPIO_USBH_CPEN, 1) == 0)) |
| 214 | gpio_export(OVERO_GPIO_USBH_CPEN, 0); |
| 215 | else |
| 216 | printk(KERN_ERR "could not obtain gpio for " |
| 217 | "OVERO_GPIO_USBH_CPEN\n"); |
| 218 | |
| 219 | if ((gpio_request(OVERO_GPIO_USBH_NRESET, |
| 220 | "OVERO_GPIO_USBH_NRESET") == 0) && |
| 221 | (gpio_direction_output(OVERO_GPIO_USBH_NRESET, 1) == 0)) |
| 222 | gpio_export(OVERO_GPIO_USBH_NRESET, 0); |
| 223 | else |
| 224 | printk(KERN_ERR "could not obtain gpio for " |
| 225 | "OVERO_GPIO_USBH_NRESET\n"); |
| 226 | } |
| 227 | |
| 228 | static void __init overo_map_io(void) |
| 229 | { |
| 230 | omap2_set_globals_343x(); |
| 231 | omap2_map_common_io(); |
| 232 | } |
| 233 | |
| 234 | MACHINE_START(OVERO, "Gumstix Overo") |
| 235 | .phys_io = 0x48000000, |
| 236 | .io_pg_offst = ((0xd8000000) >> 18) & 0xfffc, |
| 237 | .boot_params = 0x80000100, |
| 238 | .map_io = overo_map_io, |
| 239 | .init_irq = overo_init_irq, |
| 240 | .init_machine = overo_init, |
| 241 | .timer = &omap_timer, |
| 242 | MACHINE_END |