Magnus Damm | e7d1651 | 2009-07-22 16:20:54 +0000 | [diff] [blame] | 1 | /* |
| 2 | * KFR2R09 board support code |
| 3 | * |
| 4 | * Copyright (C) 2009 Magnus Damm |
| 5 | * |
| 6 | * This file is subject to the terms and conditions of the GNU General Public |
| 7 | * License. See the file "COPYING" in the main directory of this archive |
| 8 | * for more details. |
| 9 | */ |
| 10 | #include <linux/init.h> |
| 11 | #include <linux/platform_device.h> |
| 12 | #include <linux/interrupt.h> |
Magnus Damm | a366aa64 | 2009-07-22 16:22:28 +0000 | [diff] [blame] | 13 | #include <linux/mtd/physmap.h> |
Magnus Damm | 33893d7 | 2009-08-06 14:58:43 +0000 | [diff] [blame] | 14 | #include <linux/mtd/onenand.h> |
Magnus Damm | e7d1651 | 2009-07-22 16:20:54 +0000 | [diff] [blame] | 15 | #include <linux/delay.h> |
| 16 | #include <linux/clk.h> |
| 17 | #include <linux/gpio.h> |
Magnus Damm | 39a6bf1 | 2009-07-22 16:23:45 +0000 | [diff] [blame] | 18 | #include <linux/input.h> |
Magnus Damm | 5a1c4cb | 2009-08-19 14:39:15 +0000 | [diff] [blame] | 19 | #include <linux/i2c.h> |
| 20 | #include <linux/usb/r8a66597.h> |
Magnus Damm | 9f26e65 | 2009-08-06 14:51:30 +0000 | [diff] [blame] | 21 | #include <video/sh_mobile_lcdc.h> |
Magnus Damm | e7d1651 | 2009-07-22 16:20:54 +0000 | [diff] [blame] | 22 | #include <asm/clock.h> |
| 23 | #include <asm/machvec.h> |
| 24 | #include <asm/io.h> |
Magnus Damm | 39a6bf1 | 2009-07-22 16:23:45 +0000 | [diff] [blame] | 25 | #include <asm/sh_keysc.h> |
Magnus Damm | e7d1651 | 2009-07-22 16:20:54 +0000 | [diff] [blame] | 26 | #include <cpu/sh7724.h> |
Magnus Damm | 9f26e65 | 2009-08-06 14:51:30 +0000 | [diff] [blame] | 27 | #include <mach/kfr2r09.h> |
Magnus Damm | e7d1651 | 2009-07-22 16:20:54 +0000 | [diff] [blame] | 28 | |
Magnus Damm | a366aa64 | 2009-07-22 16:22:28 +0000 | [diff] [blame] | 29 | static struct mtd_partition kfr2r09_nor_flash_partitions[] = |
| 30 | { |
| 31 | { |
| 32 | .name = "boot", |
| 33 | .offset = 0, |
| 34 | .size = (4 * 1024 * 1024), |
| 35 | .mask_flags = MTD_WRITEABLE, /* Read-only */ |
| 36 | }, |
| 37 | { |
| 38 | .name = "other", |
| 39 | .offset = MTDPART_OFS_APPEND, |
| 40 | .size = MTDPART_SIZ_FULL, |
| 41 | }, |
| 42 | }; |
| 43 | |
| 44 | static struct physmap_flash_data kfr2r09_nor_flash_data = { |
| 45 | .width = 2, |
| 46 | .parts = kfr2r09_nor_flash_partitions, |
| 47 | .nr_parts = ARRAY_SIZE(kfr2r09_nor_flash_partitions), |
| 48 | }; |
| 49 | |
| 50 | static struct resource kfr2r09_nor_flash_resources[] = { |
| 51 | [0] = { |
| 52 | .name = "NOR Flash", |
| 53 | .start = 0x00000000, |
| 54 | .end = 0x03ffffff, |
| 55 | .flags = IORESOURCE_MEM, |
| 56 | } |
| 57 | }; |
| 58 | |
| 59 | static struct platform_device kfr2r09_nor_flash_device = { |
| 60 | .name = "physmap-flash", |
| 61 | .resource = kfr2r09_nor_flash_resources, |
| 62 | .num_resources = ARRAY_SIZE(kfr2r09_nor_flash_resources), |
| 63 | .dev = { |
| 64 | .platform_data = &kfr2r09_nor_flash_data, |
| 65 | }, |
| 66 | }; |
| 67 | |
Magnus Damm | 33893d7 | 2009-08-06 14:58:43 +0000 | [diff] [blame] | 68 | static struct resource kfr2r09_nand_flash_resources[] = { |
| 69 | [0] = { |
| 70 | .name = "NAND Flash", |
| 71 | .start = 0x10000000, |
| 72 | .end = 0x1001ffff, |
| 73 | .flags = IORESOURCE_MEM, |
| 74 | } |
| 75 | }; |
| 76 | |
| 77 | static struct platform_device kfr2r09_nand_flash_device = { |
| 78 | .name = "onenand-flash", |
| 79 | .resource = kfr2r09_nand_flash_resources, |
| 80 | .num_resources = ARRAY_SIZE(kfr2r09_nand_flash_resources), |
| 81 | }; |
| 82 | |
Magnus Damm | 39a6bf1 | 2009-07-22 16:23:45 +0000 | [diff] [blame] | 83 | static struct sh_keysc_info kfr2r09_sh_keysc_info = { |
| 84 | .mode = SH_KEYSC_MODE_1, /* KEYOUT0->4, KEYIN0->4 */ |
| 85 | .scan_timing = 3, |
| 86 | .delay = 10, |
| 87 | .keycodes = { |
| 88 | KEY_PHONE, KEY_CLEAR, KEY_MAIL, KEY_WWW, KEY_ENTER, |
| 89 | KEY_1, KEY_2, KEY_3, 0, KEY_UP, |
| 90 | KEY_4, KEY_5, KEY_6, 0, KEY_LEFT, |
| 91 | KEY_7, KEY_8, KEY_9, KEY_PROG1, KEY_RIGHT, |
| 92 | KEY_S, KEY_0, KEY_P, KEY_PROG2, KEY_DOWN, |
| 93 | 0, 0, 0, 0, 0 |
| 94 | }, |
| 95 | }; |
| 96 | |
| 97 | static struct resource kfr2r09_sh_keysc_resources[] = { |
| 98 | [0] = { |
| 99 | .name = "KEYSC", |
| 100 | .start = 0x044b0000, |
| 101 | .end = 0x044b000f, |
| 102 | .flags = IORESOURCE_MEM, |
| 103 | }, |
| 104 | [1] = { |
| 105 | .start = 79, |
| 106 | .flags = IORESOURCE_IRQ, |
| 107 | }, |
| 108 | }; |
| 109 | |
| 110 | static struct platform_device kfr2r09_sh_keysc_device = { |
| 111 | .name = "sh_keysc", |
| 112 | .id = 0, /* "keysc0" clock */ |
| 113 | .num_resources = ARRAY_SIZE(kfr2r09_sh_keysc_resources), |
| 114 | .resource = kfr2r09_sh_keysc_resources, |
| 115 | .dev = { |
| 116 | .platform_data = &kfr2r09_sh_keysc_info, |
| 117 | }, |
Magnus Damm | 442c375 | 2009-07-31 07:48:21 +0000 | [diff] [blame] | 118 | .archdata = { |
| 119 | .hwblk_id = HWBLK_KEYSC, |
| 120 | }, |
Magnus Damm | 39a6bf1 | 2009-07-22 16:23:45 +0000 | [diff] [blame] | 121 | }; |
| 122 | |
Magnus Damm | 9f26e65 | 2009-08-06 14:51:30 +0000 | [diff] [blame] | 123 | static struct sh_mobile_lcdc_info kfr2r09_sh_lcdc_info = { |
| 124 | .clock_source = LCDC_CLK_BUS, |
| 125 | .ch[0] = { |
| 126 | .chan = LCDC_CHAN_MAINLCD, |
| 127 | .bpp = 16, |
| 128 | .interface_type = SYS18, |
| 129 | .clock_divider = 6, |
| 130 | .flags = LCDC_FLAGS_DWPOL, |
| 131 | .lcd_cfg = { |
| 132 | .name = "TX07D34VM0AAA", |
| 133 | .xres = 240, |
| 134 | .yres = 400, |
| 135 | .left_margin = 0, |
| 136 | .right_margin = 16, |
| 137 | .hsync_len = 8, |
| 138 | .upper_margin = 0, |
| 139 | .lower_margin = 1, |
| 140 | .vsync_len = 1, |
| 141 | .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, |
| 142 | }, |
| 143 | .lcd_size_cfg = { |
| 144 | .width = 35, |
| 145 | .height = 58, |
| 146 | }, |
| 147 | .board_cfg = { |
| 148 | .setup_sys = kfr2r09_lcd_setup, |
| 149 | .display_on = kfr2r09_lcd_on, |
| 150 | .display_off = kfr2r09_lcd_off, |
| 151 | }, |
| 152 | .sys_bus_cfg = { |
| 153 | .ldmt2r = 0x07010904, |
| 154 | .ldmt3r = 0x14012914, |
| 155 | /* set 1s delay to encourage fsync() */ |
| 156 | .deferred_io_msec = 1000, |
| 157 | }, |
| 158 | } |
| 159 | }; |
| 160 | |
| 161 | static struct resource kfr2r09_sh_lcdc_resources[] = { |
| 162 | [0] = { |
| 163 | .name = "LCDC", |
| 164 | .start = 0xfe940000, /* P4-only space */ |
Phil Edworthy | a6f15ad | 2009-09-15 12:00:30 +0000 | [diff] [blame] | 165 | .end = 0xfe942fff, |
Magnus Damm | 9f26e65 | 2009-08-06 14:51:30 +0000 | [diff] [blame] | 166 | .flags = IORESOURCE_MEM, |
| 167 | }, |
| 168 | [1] = { |
| 169 | .start = 106, |
| 170 | .flags = IORESOURCE_IRQ, |
| 171 | }, |
| 172 | }; |
| 173 | |
| 174 | static struct platform_device kfr2r09_sh_lcdc_device = { |
| 175 | .name = "sh_mobile_lcdc_fb", |
| 176 | .num_resources = ARRAY_SIZE(kfr2r09_sh_lcdc_resources), |
| 177 | .resource = kfr2r09_sh_lcdc_resources, |
| 178 | .dev = { |
| 179 | .platform_data = &kfr2r09_sh_lcdc_info, |
| 180 | }, |
Magnus Damm | 963e04c | 2009-08-15 03:02:08 +0000 | [diff] [blame] | 181 | .archdata = { |
| 182 | .hwblk_id = HWBLK_LCDC, |
| 183 | }, |
Magnus Damm | 9f26e65 | 2009-08-06 14:51:30 +0000 | [diff] [blame] | 184 | }; |
| 185 | |
Magnus Damm | 5a1c4cb | 2009-08-19 14:39:15 +0000 | [diff] [blame] | 186 | static struct r8a66597_platdata kfr2r09_usb0_gadget_data = { |
| 187 | .on_chip = 1, |
| 188 | }; |
| 189 | |
| 190 | static struct resource kfr2r09_usb0_gadget_resources[] = { |
| 191 | [0] = { |
| 192 | .start = 0x04d80000, |
| 193 | .end = 0x04d80123, |
| 194 | .flags = IORESOURCE_MEM, |
| 195 | }, |
| 196 | [1] = { |
| 197 | .start = 65, |
| 198 | .end = 65, |
| 199 | .flags = IORESOURCE_IRQ | IRQF_TRIGGER_LOW, |
| 200 | }, |
| 201 | }; |
| 202 | |
| 203 | static struct platform_device kfr2r09_usb0_gadget_device = { |
| 204 | .name = "r8a66597_udc", |
| 205 | .id = 0, |
| 206 | .dev = { |
| 207 | .dma_mask = NULL, /* not use dma */ |
| 208 | .coherent_dma_mask = 0xffffffff, |
| 209 | .platform_data = &kfr2r09_usb0_gadget_data, |
| 210 | }, |
| 211 | .num_resources = ARRAY_SIZE(kfr2r09_usb0_gadget_resources), |
| 212 | .resource = kfr2r09_usb0_gadget_resources, |
| 213 | }; |
| 214 | |
Magnus Damm | a366aa64 | 2009-07-22 16:22:28 +0000 | [diff] [blame] | 215 | static struct platform_device *kfr2r09_devices[] __initdata = { |
| 216 | &kfr2r09_nor_flash_device, |
Magnus Damm | 33893d7 | 2009-08-06 14:58:43 +0000 | [diff] [blame] | 217 | &kfr2r09_nand_flash_device, |
Magnus Damm | 39a6bf1 | 2009-07-22 16:23:45 +0000 | [diff] [blame] | 218 | &kfr2r09_sh_keysc_device, |
Magnus Damm | 9f26e65 | 2009-08-06 14:51:30 +0000 | [diff] [blame] | 219 | &kfr2r09_sh_lcdc_device, |
Magnus Damm | a366aa64 | 2009-07-22 16:22:28 +0000 | [diff] [blame] | 220 | }; |
| 221 | |
| 222 | #define BSC_CS0BCR 0xfec10004 |
| 223 | #define BSC_CS0WCR 0xfec10024 |
Magnus Damm | 33893d7 | 2009-08-06 14:58:43 +0000 | [diff] [blame] | 224 | #define BSC_CS4BCR 0xfec10010 |
| 225 | #define BSC_CS4WCR 0xfec10030 |
Magnus Damm | 5a1c4cb | 2009-08-19 14:39:15 +0000 | [diff] [blame] | 226 | #define PORT_MSELCRB 0xa4050182 |
| 227 | |
Magnus Damm | 045a4b7 | 2009-08-20 13:57:36 +0000 | [diff] [blame] | 228 | #ifdef CONFIG_I2C |
Magnus Damm | 5a1c4cb | 2009-08-19 14:39:15 +0000 | [diff] [blame] | 229 | static int kfr2r09_usb0_gadget_i2c_setup(void) |
| 230 | { |
| 231 | struct i2c_adapter *a; |
| 232 | struct i2c_msg msg; |
| 233 | unsigned char buf[2]; |
| 234 | int ret; |
| 235 | |
| 236 | a = i2c_get_adapter(0); |
| 237 | if (!a) |
| 238 | return -ENODEV; |
| 239 | |
| 240 | /* set bit 1 (the second bit) of chip at 0x09, register 0x13 */ |
| 241 | buf[0] = 0x13; |
| 242 | msg.addr = 0x09; |
| 243 | msg.buf = buf; |
| 244 | msg.len = 1; |
| 245 | msg.flags = 0; |
| 246 | ret = i2c_transfer(a, &msg, 1); |
| 247 | if (ret != 1) |
| 248 | return -ENODEV; |
| 249 | |
| 250 | buf[0] = 0; |
| 251 | msg.addr = 0x09; |
| 252 | msg.buf = buf; |
| 253 | msg.len = 1; |
| 254 | msg.flags = I2C_M_RD; |
| 255 | ret = i2c_transfer(a, &msg, 1); |
| 256 | if (ret != 1) |
| 257 | return -ENODEV; |
| 258 | |
| 259 | buf[1] = buf[0] | (1 << 1); |
| 260 | buf[0] = 0x13; |
| 261 | msg.addr = 0x09; |
| 262 | msg.buf = buf; |
| 263 | msg.len = 2; |
| 264 | msg.flags = 0; |
| 265 | ret = i2c_transfer(a, &msg, 1); |
| 266 | if (ret != 1) |
| 267 | return -ENODEV; |
| 268 | |
| 269 | return 0; |
| 270 | } |
Magnus Damm | 045a4b7 | 2009-08-20 13:57:36 +0000 | [diff] [blame] | 271 | #else |
| 272 | static int kfr2r09_usb0_gadget_i2c_setup(void) |
| 273 | { |
| 274 | return -ENODEV; |
| 275 | } |
| 276 | #endif |
Magnus Damm | 5a1c4cb | 2009-08-19 14:39:15 +0000 | [diff] [blame] | 277 | |
| 278 | static int kfr2r09_usb0_gadget_setup(void) |
| 279 | { |
| 280 | int plugged_in; |
| 281 | |
| 282 | gpio_request(GPIO_PTN4, NULL); /* USB_DET */ |
| 283 | gpio_direction_input(GPIO_PTN4); |
| 284 | plugged_in = gpio_get_value(GPIO_PTN4); |
| 285 | if (!plugged_in) |
| 286 | return -ENODEV; /* no cable plugged in */ |
| 287 | |
| 288 | if (kfr2r09_usb0_gadget_i2c_setup() != 0) |
| 289 | return -ENODEV; /* unable to configure using i2c */ |
| 290 | |
| 291 | ctrl_outw((ctrl_inw(PORT_MSELCRB) & ~0xc000) | 0x8000, PORT_MSELCRB); |
| 292 | gpio_request(GPIO_FN_PDSTATUS, NULL); /* R-standby disables USB clock */ |
| 293 | gpio_request(GPIO_PTV6, NULL); /* USBCLK_ON */ |
| 294 | gpio_direction_output(GPIO_PTV6, 1); /* USBCLK_ON = H */ |
| 295 | msleep(20); /* wait 20ms to let the clock settle */ |
| 296 | clk_enable(clk_get(NULL, "usb0")); |
| 297 | ctrl_outw(0x0600, 0xa40501d4); |
| 298 | |
| 299 | return 0; |
| 300 | } |
Magnus Damm | a366aa64 | 2009-07-22 16:22:28 +0000 | [diff] [blame] | 301 | |
Magnus Damm | e7d1651 | 2009-07-22 16:20:54 +0000 | [diff] [blame] | 302 | static int __init kfr2r09_devices_setup(void) |
| 303 | { |
| 304 | /* enable SCIF1 serial port for YC401 console support */ |
| 305 | gpio_request(GPIO_FN_SCIF1_RXD, NULL); |
| 306 | gpio_request(GPIO_FN_SCIF1_TXD, NULL); |
| 307 | |
Magnus Damm | a366aa64 | 2009-07-22 16:22:28 +0000 | [diff] [blame] | 308 | /* setup NOR flash at CS0 */ |
| 309 | ctrl_outl(0x36db0400, BSC_CS0BCR); |
| 310 | ctrl_outl(0x00000500, BSC_CS0WCR); |
| 311 | |
Magnus Damm | 33893d7 | 2009-08-06 14:58:43 +0000 | [diff] [blame] | 312 | /* setup NAND flash at CS4 */ |
| 313 | ctrl_outl(0x36db0400, BSC_CS4BCR); |
| 314 | ctrl_outl(0x00000500, BSC_CS4WCR); |
| 315 | |
Magnus Damm | 39a6bf1 | 2009-07-22 16:23:45 +0000 | [diff] [blame] | 316 | /* setup KEYSC pins */ |
| 317 | gpio_request(GPIO_FN_KEYOUT0, NULL); |
| 318 | gpio_request(GPIO_FN_KEYOUT1, NULL); |
| 319 | gpio_request(GPIO_FN_KEYOUT2, NULL); |
| 320 | gpio_request(GPIO_FN_KEYOUT3, NULL); |
| 321 | gpio_request(GPIO_FN_KEYOUT4_IN6, NULL); |
| 322 | gpio_request(GPIO_FN_KEYIN0, NULL); |
| 323 | gpio_request(GPIO_FN_KEYIN1, NULL); |
| 324 | gpio_request(GPIO_FN_KEYIN2, NULL); |
| 325 | gpio_request(GPIO_FN_KEYIN3, NULL); |
| 326 | gpio_request(GPIO_FN_KEYIN4, NULL); |
| 327 | gpio_request(GPIO_FN_KEYOUT5_IN5, NULL); |
| 328 | |
Magnus Damm | 9f26e65 | 2009-08-06 14:51:30 +0000 | [diff] [blame] | 329 | /* setup LCDC pins for SYS panel */ |
| 330 | gpio_request(GPIO_FN_LCDD17, NULL); |
| 331 | gpio_request(GPIO_FN_LCDD16, NULL); |
| 332 | gpio_request(GPIO_FN_LCDD15, NULL); |
| 333 | gpio_request(GPIO_FN_LCDD14, NULL); |
| 334 | gpio_request(GPIO_FN_LCDD13, NULL); |
| 335 | gpio_request(GPIO_FN_LCDD12, NULL); |
| 336 | gpio_request(GPIO_FN_LCDD11, NULL); |
| 337 | gpio_request(GPIO_FN_LCDD10, NULL); |
| 338 | gpio_request(GPIO_FN_LCDD9, NULL); |
| 339 | gpio_request(GPIO_FN_LCDD8, NULL); |
| 340 | gpio_request(GPIO_FN_LCDD7, NULL); |
| 341 | gpio_request(GPIO_FN_LCDD6, NULL); |
| 342 | gpio_request(GPIO_FN_LCDD5, NULL); |
| 343 | gpio_request(GPIO_FN_LCDD4, NULL); |
| 344 | gpio_request(GPIO_FN_LCDD3, NULL); |
| 345 | gpio_request(GPIO_FN_LCDD2, NULL); |
| 346 | gpio_request(GPIO_FN_LCDD1, NULL); |
| 347 | gpio_request(GPIO_FN_LCDD0, NULL); |
| 348 | gpio_request(GPIO_FN_LCDRS, NULL); /* LCD_RS */ |
| 349 | gpio_request(GPIO_FN_LCDCS, NULL); /* LCD_CS/ */ |
| 350 | gpio_request(GPIO_FN_LCDRD, NULL); /* LCD_RD/ */ |
| 351 | gpio_request(GPIO_FN_LCDWR, NULL); /* LCD_WR/ */ |
| 352 | gpio_request(GPIO_FN_LCDVSYN, NULL); /* LCD_VSYNC */ |
| 353 | gpio_request(GPIO_PTE4, NULL); /* LCD_RST/ */ |
| 354 | gpio_direction_output(GPIO_PTE4, 1); |
| 355 | gpio_request(GPIO_PTF4, NULL); /* PROTECT/ */ |
| 356 | gpio_direction_output(GPIO_PTF4, 1); |
| 357 | gpio_request(GPIO_PTU0, NULL); /* LEDSTDBY/ */ |
| 358 | gpio_direction_output(GPIO_PTU0, 1); |
| 359 | |
Magnus Damm | 5a1c4cb | 2009-08-19 14:39:15 +0000 | [diff] [blame] | 360 | /* setup USB function */ |
| 361 | if (kfr2r09_usb0_gadget_setup() == 0) |
| 362 | platform_device_register(&kfr2r09_usb0_gadget_device); |
| 363 | |
Magnus Damm | a366aa64 | 2009-07-22 16:22:28 +0000 | [diff] [blame] | 364 | return platform_add_devices(kfr2r09_devices, |
| 365 | ARRAY_SIZE(kfr2r09_devices)); |
Magnus Damm | e7d1651 | 2009-07-22 16:20:54 +0000 | [diff] [blame] | 366 | } |
| 367 | device_initcall(kfr2r09_devices_setup); |
| 368 | |
| 369 | /* Return the board specific boot mode pin configuration */ |
| 370 | static int kfr2r09_mode_pins(void) |
| 371 | { |
| 372 | /* MD0=1, MD1=1, MD2=0: Clock Mode 3 |
| 373 | * MD3=0: 16-bit Area0 Bus Width |
| 374 | * MD5=1: Little Endian |
| 375 | * MD8=1: Test Mode Disabled |
| 376 | */ |
| 377 | return MODE_PIN0 | MODE_PIN1 | MODE_PIN5 | MODE_PIN8; |
| 378 | } |
| 379 | |
| 380 | /* |
| 381 | * The Machine Vector |
| 382 | */ |
| 383 | static struct sh_machine_vector mv_kfr2r09 __initmv = { |
| 384 | .mv_name = "kfr2r09", |
| 385 | .mv_mode_pins = kfr2r09_mode_pins, |
| 386 | }; |