Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * KFR2R09 board support code |
| 4 | * |
| 5 | * Copyright (C) 2009 Magnus Damm |
| 6 | */ |
| 7 | |
| 8 | #include <asm/clock.h> |
| 9 | #include <asm/io.h> |
| 10 | #include <asm/machvec.h> |
| 11 | #include <asm/suspend.h> |
| 12 | |
| 13 | #include <cpu/sh7724.h> |
| 14 | |
| 15 | #include <linux/clkdev.h> |
| 16 | #include <linux/delay.h> |
| 17 | #include <linux/dma-mapping.h> |
| 18 | #include <linux/gpio.h> |
| 19 | #include <linux/gpio/machine.h> |
| 20 | #include <linux/i2c.h> |
| 21 | #include <linux/init.h> |
| 22 | #include <linux/input.h> |
| 23 | #include <linux/input/sh_keysc.h> |
| 24 | #include <linux/interrupt.h> |
| 25 | #include <linux/memblock.h> |
| 26 | #include <linux/mfd/tmio.h> |
| 27 | #include <linux/mmc/host.h> |
| 28 | #include <linux/mtd/onenand.h> |
| 29 | #include <linux/mtd/physmap.h> |
| 30 | #include <linux/platform_data/lv5207lp.h> |
| 31 | #include <linux/platform_device.h> |
| 32 | #include <linux/regulator/fixed.h> |
| 33 | #include <linux/regulator/machine.h> |
| 34 | #include <linux/sh_intc.h> |
| 35 | #include <linux/usb/r8a66597.h> |
| 36 | #include <linux/videodev2.h> |
| 37 | |
| 38 | #include <mach/kfr2r09.h> |
| 39 | |
| 40 | #include <media/drv-intf/renesas-ceu.h> |
| 41 | #include <media/i2c/rj54n1cb0c.h> |
| 42 | |
| 43 | #include <video/sh_mobile_lcdc.h> |
| 44 | |
| 45 | #define CEU_BUFFER_MEMORY_SIZE (4 << 20) |
| 46 | static phys_addr_t ceu_dma_membase; |
| 47 | |
| 48 | /* set VIO_CKO clock to 25MHz */ |
| 49 | #define CEU_MCLK_FREQ 25000000 |
| 50 | #define DRVCRB 0xA405018C |
| 51 | |
| 52 | static struct mtd_partition kfr2r09_nor_flash_partitions[] = |
| 53 | { |
| 54 | { |
| 55 | .name = "boot", |
| 56 | .offset = 0, |
| 57 | .size = (4 * 1024 * 1024), |
| 58 | .mask_flags = MTD_WRITEABLE, /* Read-only */ |
| 59 | }, |
| 60 | { |
| 61 | .name = "other", |
| 62 | .offset = MTDPART_OFS_APPEND, |
| 63 | .size = MTDPART_SIZ_FULL, |
| 64 | }, |
| 65 | }; |
| 66 | |
| 67 | static struct physmap_flash_data kfr2r09_nor_flash_data = { |
| 68 | .width = 2, |
| 69 | .parts = kfr2r09_nor_flash_partitions, |
| 70 | .nr_parts = ARRAY_SIZE(kfr2r09_nor_flash_partitions), |
| 71 | }; |
| 72 | |
| 73 | static struct resource kfr2r09_nor_flash_resources[] = { |
| 74 | [0] = { |
| 75 | .name = "NOR Flash", |
| 76 | .start = 0x00000000, |
| 77 | .end = 0x03ffffff, |
| 78 | .flags = IORESOURCE_MEM, |
| 79 | } |
| 80 | }; |
| 81 | |
| 82 | static struct platform_device kfr2r09_nor_flash_device = { |
| 83 | .name = "physmap-flash", |
| 84 | .resource = kfr2r09_nor_flash_resources, |
| 85 | .num_resources = ARRAY_SIZE(kfr2r09_nor_flash_resources), |
| 86 | .dev = { |
| 87 | .platform_data = &kfr2r09_nor_flash_data, |
| 88 | }, |
| 89 | }; |
| 90 | |
| 91 | static struct resource kfr2r09_nand_flash_resources[] = { |
| 92 | [0] = { |
| 93 | .name = "NAND Flash", |
| 94 | .start = 0x10000000, |
| 95 | .end = 0x1001ffff, |
| 96 | .flags = IORESOURCE_MEM, |
| 97 | } |
| 98 | }; |
| 99 | |
| 100 | static struct platform_device kfr2r09_nand_flash_device = { |
| 101 | .name = "onenand-flash", |
| 102 | .resource = kfr2r09_nand_flash_resources, |
| 103 | .num_resources = ARRAY_SIZE(kfr2r09_nand_flash_resources), |
| 104 | }; |
| 105 | |
| 106 | static struct sh_keysc_info kfr2r09_sh_keysc_info = { |
| 107 | .mode = SH_KEYSC_MODE_1, /* KEYOUT0->4, KEYIN0->4 */ |
| 108 | .scan_timing = 3, |
| 109 | .delay = 10, |
| 110 | .keycodes = { |
| 111 | KEY_PHONE, KEY_CLEAR, KEY_MAIL, KEY_WWW, KEY_ENTER, |
| 112 | KEY_1, KEY_2, KEY_3, 0, KEY_UP, |
| 113 | KEY_4, KEY_5, KEY_6, 0, KEY_LEFT, |
| 114 | KEY_7, KEY_8, KEY_9, KEY_PROG1, KEY_RIGHT, |
| 115 | KEY_S, KEY_0, KEY_P, KEY_PROG2, KEY_DOWN, |
| 116 | 0, 0, 0, 0, 0 |
| 117 | }, |
| 118 | }; |
| 119 | |
| 120 | static struct resource kfr2r09_sh_keysc_resources[] = { |
| 121 | [0] = { |
| 122 | .name = "KEYSC", |
| 123 | .start = 0x044b0000, |
| 124 | .end = 0x044b000f, |
| 125 | .flags = IORESOURCE_MEM, |
| 126 | }, |
| 127 | [1] = { |
| 128 | .start = evt2irq(0xbe0), |
| 129 | .flags = IORESOURCE_IRQ, |
| 130 | }, |
| 131 | }; |
| 132 | |
| 133 | static struct platform_device kfr2r09_sh_keysc_device = { |
| 134 | .name = "sh_keysc", |
| 135 | .id = 0, /* "keysc0" clock */ |
| 136 | .num_resources = ARRAY_SIZE(kfr2r09_sh_keysc_resources), |
| 137 | .resource = kfr2r09_sh_keysc_resources, |
| 138 | .dev = { |
| 139 | .platform_data = &kfr2r09_sh_keysc_info, |
| 140 | }, |
| 141 | }; |
| 142 | |
| 143 | static const struct fb_videomode kfr2r09_lcdc_modes[] = { |
| 144 | { |
| 145 | .name = "TX07D34VM0AAA", |
| 146 | .xres = 240, |
| 147 | .yres = 400, |
| 148 | .left_margin = 0, |
| 149 | .right_margin = 16, |
| 150 | .hsync_len = 8, |
| 151 | .upper_margin = 0, |
| 152 | .lower_margin = 1, |
| 153 | .vsync_len = 1, |
| 154 | .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, |
| 155 | }, |
| 156 | }; |
| 157 | |
| 158 | static struct sh_mobile_lcdc_info kfr2r09_sh_lcdc_info = { |
| 159 | .clock_source = LCDC_CLK_BUS, |
| 160 | .ch[0] = { |
| 161 | .chan = LCDC_CHAN_MAINLCD, |
| 162 | .fourcc = V4L2_PIX_FMT_RGB565, |
| 163 | .interface_type = SYS18, |
| 164 | .clock_divider = 6, |
| 165 | .flags = LCDC_FLAGS_DWPOL, |
| 166 | .lcd_modes = kfr2r09_lcdc_modes, |
| 167 | .num_modes = ARRAY_SIZE(kfr2r09_lcdc_modes), |
| 168 | .panel_cfg = { |
| 169 | .width = 35, |
| 170 | .height = 58, |
| 171 | .setup_sys = kfr2r09_lcd_setup, |
| 172 | .start_transfer = kfr2r09_lcd_start, |
| 173 | }, |
| 174 | .sys_bus_cfg = { |
| 175 | .ldmt2r = 0x07010904, |
| 176 | .ldmt3r = 0x14012914, |
| 177 | /* set 1s delay to encourage fsync() */ |
| 178 | .deferred_io_msec = 1000, |
| 179 | }, |
| 180 | } |
| 181 | }; |
| 182 | |
| 183 | static struct resource kfr2r09_sh_lcdc_resources[] = { |
| 184 | [0] = { |
| 185 | .name = "LCDC", |
| 186 | .start = 0xfe940000, /* P4-only space */ |
| 187 | .end = 0xfe942fff, |
| 188 | .flags = IORESOURCE_MEM, |
| 189 | }, |
| 190 | [1] = { |
| 191 | .start = evt2irq(0xf40), |
| 192 | .flags = IORESOURCE_IRQ, |
| 193 | }, |
| 194 | }; |
| 195 | |
| 196 | static struct platform_device kfr2r09_sh_lcdc_device = { |
| 197 | .name = "sh_mobile_lcdc_fb", |
| 198 | .num_resources = ARRAY_SIZE(kfr2r09_sh_lcdc_resources), |
| 199 | .resource = kfr2r09_sh_lcdc_resources, |
| 200 | .dev = { |
| 201 | .platform_data = &kfr2r09_sh_lcdc_info, |
| 202 | }, |
| 203 | }; |
| 204 | |
| 205 | static struct lv5207lp_platform_data kfr2r09_backlight_data = { |
| 206 | .fbdev = &kfr2r09_sh_lcdc_device.dev, |
| 207 | .def_value = 13, |
| 208 | .max_value = 13, |
| 209 | }; |
| 210 | |
| 211 | static struct i2c_board_info kfr2r09_backlight_board_info = { |
| 212 | I2C_BOARD_INFO("lv5207lp", 0x75), |
| 213 | .platform_data = &kfr2r09_backlight_data, |
| 214 | }; |
| 215 | |
| 216 | static struct r8a66597_platdata kfr2r09_usb0_gadget_data = { |
| 217 | .on_chip = 1, |
| 218 | }; |
| 219 | |
| 220 | static struct resource kfr2r09_usb0_gadget_resources[] = { |
| 221 | [0] = { |
| 222 | .start = 0x04d80000, |
| 223 | .end = 0x04d80123, |
| 224 | .flags = IORESOURCE_MEM, |
| 225 | }, |
| 226 | [1] = { |
| 227 | .start = evt2irq(0xa20), |
| 228 | .end = evt2irq(0xa20), |
| 229 | .flags = IORESOURCE_IRQ | IRQF_TRIGGER_LOW, |
| 230 | }, |
| 231 | }; |
| 232 | |
| 233 | static struct platform_device kfr2r09_usb0_gadget_device = { |
| 234 | .name = "r8a66597_udc", |
| 235 | .id = 0, |
| 236 | .dev = { |
| 237 | .dma_mask = NULL, /* not use dma */ |
| 238 | .coherent_dma_mask = 0xffffffff, |
| 239 | .platform_data = &kfr2r09_usb0_gadget_data, |
| 240 | }, |
| 241 | .num_resources = ARRAY_SIZE(kfr2r09_usb0_gadget_resources), |
| 242 | .resource = kfr2r09_usb0_gadget_resources, |
| 243 | }; |
| 244 | |
| 245 | static struct ceu_platform_data ceu_pdata = { |
| 246 | .num_subdevs = 1, |
| 247 | .subdevs = { |
| 248 | { /* [0] = rj54n1cb0c */ |
| 249 | .flags = 0, |
| 250 | .bus_width = 8, |
| 251 | .bus_shift = 0, |
| 252 | .i2c_adapter_id = 1, |
| 253 | .i2c_address = 0x50, |
| 254 | }, |
| 255 | }, |
| 256 | }; |
| 257 | |
| 258 | static struct resource kfr2r09_ceu_resources[] = { |
| 259 | [0] = { |
| 260 | .name = "CEU", |
| 261 | .start = 0xfe910000, |
| 262 | .end = 0xfe91009f, |
| 263 | .flags = IORESOURCE_MEM, |
| 264 | }, |
| 265 | [1] = { |
| 266 | .start = evt2irq(0x880), |
| 267 | .end = evt2irq(0x880), |
| 268 | .flags = IORESOURCE_IRQ, |
| 269 | }, |
| 270 | }; |
| 271 | |
| 272 | static struct platform_device kfr2r09_ceu_device = { |
| 273 | .name = "renesas-ceu", |
| 274 | .id = 0, /* "ceu0" clock */ |
| 275 | .num_resources = ARRAY_SIZE(kfr2r09_ceu_resources), |
| 276 | .resource = kfr2r09_ceu_resources, |
| 277 | .dev = { |
| 278 | .platform_data = &ceu_pdata, |
| 279 | }, |
| 280 | }; |
| 281 | |
| 282 | static struct rj54n1_pdata rj54n1_priv = { |
| 283 | .mclk_freq = CEU_MCLK_FREQ, |
| 284 | .ioctl_high = false, |
| 285 | }; |
| 286 | |
| 287 | static struct i2c_board_info kfr2r09_i2c_camera = { |
| 288 | I2C_BOARD_INFO("rj54n1cb0c", 0x50), |
| 289 | .platform_data = &rj54n1_priv, |
| 290 | }; |
| 291 | |
| 292 | static struct gpiod_lookup_table rj54n1_gpios = { |
| 293 | .dev_id = "1-0050", |
| 294 | .table = { |
| 295 | GPIO_LOOKUP("sh7724_pfc", GPIO_PTB4, "poweron", |
| 296 | GPIO_ACTIVE_HIGH), |
| 297 | GPIO_LOOKUP("sh7724_pfc", GPIO_PTB7, "enable", |
| 298 | GPIO_ACTIVE_HIGH), |
| 299 | }, |
| 300 | }; |
| 301 | |
| 302 | /* Fixed 3.3V regulator to be used by SDHI0 */ |
| 303 | static struct regulator_consumer_supply fixed3v3_power_consumers[] = |
| 304 | { |
| 305 | REGULATOR_SUPPLY("vmmc", "sh_mobile_sdhi.0"), |
| 306 | REGULATOR_SUPPLY("vqmmc", "sh_mobile_sdhi.0"), |
| 307 | }; |
| 308 | |
| 309 | static struct resource kfr2r09_sh_sdhi0_resources[] = { |
| 310 | [0] = { |
| 311 | .name = "SDHI0", |
| 312 | .start = 0x04ce0000, |
| 313 | .end = 0x04ce00ff, |
| 314 | .flags = IORESOURCE_MEM, |
| 315 | }, |
| 316 | [1] = { |
| 317 | .start = evt2irq(0xe80), |
| 318 | .flags = IORESOURCE_IRQ, |
| 319 | }, |
| 320 | }; |
| 321 | |
| 322 | static struct tmio_mmc_data sh7724_sdhi0_data = { |
| 323 | .chan_priv_tx = (void *)SHDMA_SLAVE_SDHI0_TX, |
| 324 | .chan_priv_rx = (void *)SHDMA_SLAVE_SDHI0_RX, |
| 325 | .capabilities = MMC_CAP_SDIO_IRQ, |
| 326 | .capabilities2 = MMC_CAP2_NO_WRITE_PROTECT, |
| 327 | }; |
| 328 | |
| 329 | static struct platform_device kfr2r09_sh_sdhi0_device = { |
| 330 | .name = "sh_mobile_sdhi", |
| 331 | .num_resources = ARRAY_SIZE(kfr2r09_sh_sdhi0_resources), |
| 332 | .resource = kfr2r09_sh_sdhi0_resources, |
| 333 | .dev = { |
| 334 | .platform_data = &sh7724_sdhi0_data, |
| 335 | }, |
| 336 | }; |
| 337 | |
| 338 | static struct platform_device *kfr2r09_devices[] __initdata = { |
| 339 | &kfr2r09_nor_flash_device, |
| 340 | &kfr2r09_nand_flash_device, |
| 341 | &kfr2r09_sh_keysc_device, |
| 342 | &kfr2r09_sh_lcdc_device, |
| 343 | &kfr2r09_sh_sdhi0_device, |
| 344 | }; |
| 345 | |
| 346 | #define BSC_CS0BCR 0xfec10004 |
| 347 | #define BSC_CS0WCR 0xfec10024 |
| 348 | #define BSC_CS4BCR 0xfec10010 |
| 349 | #define BSC_CS4WCR 0xfec10030 |
| 350 | #define PORT_MSELCRB 0xa4050182 |
| 351 | |
| 352 | #ifdef CONFIG_I2C |
| 353 | static int kfr2r09_usb0_gadget_i2c_setup(void) |
| 354 | { |
| 355 | struct i2c_adapter *a; |
| 356 | struct i2c_msg msg; |
| 357 | unsigned char buf[2]; |
| 358 | int ret; |
| 359 | |
| 360 | a = i2c_get_adapter(0); |
| 361 | if (!a) |
| 362 | return -ENODEV; |
| 363 | |
| 364 | /* set bit 1 (the second bit) of chip at 0x09, register 0x13 */ |
| 365 | buf[0] = 0x13; |
| 366 | msg.addr = 0x09; |
| 367 | msg.buf = buf; |
| 368 | msg.len = 1; |
| 369 | msg.flags = 0; |
| 370 | ret = i2c_transfer(a, &msg, 1); |
| 371 | if (ret != 1) |
| 372 | return -ENODEV; |
| 373 | |
| 374 | buf[0] = 0; |
| 375 | msg.addr = 0x09; |
| 376 | msg.buf = buf; |
| 377 | msg.len = 1; |
| 378 | msg.flags = I2C_M_RD; |
| 379 | ret = i2c_transfer(a, &msg, 1); |
| 380 | if (ret != 1) |
| 381 | return -ENODEV; |
| 382 | |
| 383 | buf[1] = buf[0] | (1 << 1); |
| 384 | buf[0] = 0x13; |
| 385 | msg.addr = 0x09; |
| 386 | msg.buf = buf; |
| 387 | msg.len = 2; |
| 388 | msg.flags = 0; |
| 389 | ret = i2c_transfer(a, &msg, 1); |
| 390 | if (ret != 1) |
| 391 | return -ENODEV; |
| 392 | |
| 393 | return 0; |
| 394 | } |
| 395 | |
| 396 | static int kfr2r09_serial_i2c_setup(void) |
| 397 | { |
| 398 | struct i2c_adapter *a; |
| 399 | struct i2c_msg msg; |
| 400 | unsigned char buf[2]; |
| 401 | int ret; |
| 402 | |
| 403 | a = i2c_get_adapter(0); |
| 404 | if (!a) |
| 405 | return -ENODEV; |
| 406 | |
| 407 | /* set bit 6 (the 7th bit) of chip at 0x09, register 0x13 */ |
| 408 | buf[0] = 0x13; |
| 409 | msg.addr = 0x09; |
| 410 | msg.buf = buf; |
| 411 | msg.len = 1; |
| 412 | msg.flags = 0; |
| 413 | ret = i2c_transfer(a, &msg, 1); |
| 414 | if (ret != 1) |
| 415 | return -ENODEV; |
| 416 | |
| 417 | buf[0] = 0; |
| 418 | msg.addr = 0x09; |
| 419 | msg.buf = buf; |
| 420 | msg.len = 1; |
| 421 | msg.flags = I2C_M_RD; |
| 422 | ret = i2c_transfer(a, &msg, 1); |
| 423 | if (ret != 1) |
| 424 | return -ENODEV; |
| 425 | |
| 426 | buf[1] = buf[0] | (1 << 6); |
| 427 | buf[0] = 0x13; |
| 428 | msg.addr = 0x09; |
| 429 | msg.buf = buf; |
| 430 | msg.len = 2; |
| 431 | msg.flags = 0; |
| 432 | ret = i2c_transfer(a, &msg, 1); |
| 433 | if (ret != 1) |
| 434 | return -ENODEV; |
| 435 | |
| 436 | return 0; |
| 437 | } |
| 438 | #else |
| 439 | static int kfr2r09_usb0_gadget_i2c_setup(void) |
| 440 | { |
| 441 | return -ENODEV; |
| 442 | } |
| 443 | |
| 444 | static int kfr2r09_serial_i2c_setup(void) |
| 445 | { |
| 446 | return -ENODEV; |
| 447 | } |
| 448 | #endif |
| 449 | |
| 450 | static int kfr2r09_usb0_gadget_setup(void) |
| 451 | { |
| 452 | int plugged_in; |
| 453 | |
| 454 | gpio_request(GPIO_PTN4, NULL); /* USB_DET */ |
| 455 | gpio_direction_input(GPIO_PTN4); |
| 456 | plugged_in = gpio_get_value(GPIO_PTN4); |
| 457 | if (!plugged_in) |
| 458 | return -ENODEV; /* no cable plugged in */ |
| 459 | |
| 460 | if (kfr2r09_usb0_gadget_i2c_setup() != 0) |
| 461 | return -ENODEV; /* unable to configure using i2c */ |
| 462 | |
| 463 | __raw_writew((__raw_readw(PORT_MSELCRB) & ~0xc000) | 0x8000, PORT_MSELCRB); |
| 464 | gpio_request(GPIO_FN_PDSTATUS, NULL); /* R-standby disables USB clock */ |
| 465 | gpio_request(GPIO_PTV6, NULL); /* USBCLK_ON */ |
| 466 | gpio_direction_output(GPIO_PTV6, 1); /* USBCLK_ON = H */ |
| 467 | msleep(20); /* wait 20ms to let the clock settle */ |
| 468 | clk_enable(clk_get(NULL, "usb0")); |
| 469 | __raw_writew(0x0600, 0xa40501d4); |
| 470 | |
| 471 | return 0; |
| 472 | } |
| 473 | |
| 474 | extern char kfr2r09_sdram_enter_start; |
| 475 | extern char kfr2r09_sdram_enter_end; |
| 476 | extern char kfr2r09_sdram_leave_start; |
| 477 | extern char kfr2r09_sdram_leave_end; |
| 478 | |
| 479 | static int __init kfr2r09_devices_setup(void) |
| 480 | { |
| 481 | static struct clk *camera_clk; |
| 482 | |
| 483 | /* register board specific self-refresh code */ |
| 484 | sh_mobile_register_self_refresh(SUSP_SH_STANDBY | SUSP_SH_SF | |
| 485 | SUSP_SH_RSTANDBY, |
| 486 | &kfr2r09_sdram_enter_start, |
| 487 | &kfr2r09_sdram_enter_end, |
| 488 | &kfr2r09_sdram_leave_start, |
| 489 | &kfr2r09_sdram_leave_end); |
| 490 | |
| 491 | regulator_register_always_on(0, "fixed-3.3V", fixed3v3_power_consumers, |
| 492 | ARRAY_SIZE(fixed3v3_power_consumers), 3300000); |
| 493 | |
| 494 | /* enable SCIF1 serial port for YC401 console support */ |
| 495 | gpio_request(GPIO_FN_SCIF1_RXD, NULL); |
| 496 | gpio_request(GPIO_FN_SCIF1_TXD, NULL); |
| 497 | kfr2r09_serial_i2c_setup(); /* ECONTMSK(bit6=L10ONEN) set 1 */ |
| 498 | gpio_request(GPIO_PTG3, NULL); /* HPON_ON */ |
| 499 | gpio_direction_output(GPIO_PTG3, 1); /* HPON_ON = H */ |
| 500 | |
| 501 | /* setup NOR flash at CS0 */ |
| 502 | __raw_writel(0x36db0400, BSC_CS0BCR); |
| 503 | __raw_writel(0x00000500, BSC_CS0WCR); |
| 504 | |
| 505 | /* setup NAND flash at CS4 */ |
| 506 | __raw_writel(0x36db0400, BSC_CS4BCR); |
| 507 | __raw_writel(0x00000500, BSC_CS4WCR); |
| 508 | |
| 509 | /* setup KEYSC pins */ |
| 510 | gpio_request(GPIO_FN_KEYOUT0, NULL); |
| 511 | gpio_request(GPIO_FN_KEYOUT1, NULL); |
| 512 | gpio_request(GPIO_FN_KEYOUT2, NULL); |
| 513 | gpio_request(GPIO_FN_KEYOUT3, NULL); |
| 514 | gpio_request(GPIO_FN_KEYOUT4_IN6, NULL); |
| 515 | gpio_request(GPIO_FN_KEYIN0, NULL); |
| 516 | gpio_request(GPIO_FN_KEYIN1, NULL); |
| 517 | gpio_request(GPIO_FN_KEYIN2, NULL); |
| 518 | gpio_request(GPIO_FN_KEYIN3, NULL); |
| 519 | gpio_request(GPIO_FN_KEYIN4, NULL); |
| 520 | gpio_request(GPIO_FN_KEYOUT5_IN5, NULL); |
| 521 | |
| 522 | /* setup LCDC pins for SYS panel */ |
| 523 | gpio_request(GPIO_FN_LCDD17, NULL); |
| 524 | gpio_request(GPIO_FN_LCDD16, NULL); |
| 525 | gpio_request(GPIO_FN_LCDD15, NULL); |
| 526 | gpio_request(GPIO_FN_LCDD14, NULL); |
| 527 | gpio_request(GPIO_FN_LCDD13, NULL); |
| 528 | gpio_request(GPIO_FN_LCDD12, NULL); |
| 529 | gpio_request(GPIO_FN_LCDD11, NULL); |
| 530 | gpio_request(GPIO_FN_LCDD10, NULL); |
| 531 | gpio_request(GPIO_FN_LCDD9, NULL); |
| 532 | gpio_request(GPIO_FN_LCDD8, NULL); |
| 533 | gpio_request(GPIO_FN_LCDD7, NULL); |
| 534 | gpio_request(GPIO_FN_LCDD6, NULL); |
| 535 | gpio_request(GPIO_FN_LCDD5, NULL); |
| 536 | gpio_request(GPIO_FN_LCDD4, NULL); |
| 537 | gpio_request(GPIO_FN_LCDD3, NULL); |
| 538 | gpio_request(GPIO_FN_LCDD2, NULL); |
| 539 | gpio_request(GPIO_FN_LCDD1, NULL); |
| 540 | gpio_request(GPIO_FN_LCDD0, NULL); |
| 541 | gpio_request(GPIO_FN_LCDRS, NULL); /* LCD_RS */ |
| 542 | gpio_request(GPIO_FN_LCDCS, NULL); /* LCD_CS/ */ |
| 543 | gpio_request(GPIO_FN_LCDRD, NULL); /* LCD_RD/ */ |
| 544 | gpio_request(GPIO_FN_LCDWR, NULL); /* LCD_WR/ */ |
| 545 | gpio_request(GPIO_FN_LCDVSYN, NULL); /* LCD_VSYNC */ |
| 546 | gpio_request(GPIO_PTE4, NULL); /* LCD_RST/ */ |
| 547 | gpio_direction_output(GPIO_PTE4, 1); |
| 548 | gpio_request(GPIO_PTF4, NULL); /* PROTECT/ */ |
| 549 | gpio_direction_output(GPIO_PTF4, 1); |
| 550 | gpio_request(GPIO_PTU0, NULL); /* LEDSTDBY/ */ |
| 551 | gpio_direction_output(GPIO_PTU0, 1); |
| 552 | |
| 553 | /* setup USB function */ |
| 554 | if (kfr2r09_usb0_gadget_setup() == 0) |
| 555 | platform_device_register(&kfr2r09_usb0_gadget_device); |
| 556 | |
| 557 | /* CEU */ |
| 558 | gpio_request(GPIO_FN_VIO_CKO, NULL); |
| 559 | gpio_request(GPIO_FN_VIO0_CLK, NULL); |
| 560 | gpio_request(GPIO_FN_VIO0_VD, NULL); |
| 561 | gpio_request(GPIO_FN_VIO0_HD, NULL); |
| 562 | gpio_request(GPIO_FN_VIO0_FLD, NULL); |
| 563 | gpio_request(GPIO_FN_VIO0_D7, NULL); |
| 564 | gpio_request(GPIO_FN_VIO0_D6, NULL); |
| 565 | gpio_request(GPIO_FN_VIO0_D5, NULL); |
| 566 | gpio_request(GPIO_FN_VIO0_D4, NULL); |
| 567 | gpio_request(GPIO_FN_VIO0_D3, NULL); |
| 568 | gpio_request(GPIO_FN_VIO0_D2, NULL); |
| 569 | gpio_request(GPIO_FN_VIO0_D1, NULL); |
| 570 | gpio_request(GPIO_FN_VIO0_D0, NULL); |
| 571 | |
| 572 | /* SDHI0 connected to yc304 */ |
| 573 | gpio_request(GPIO_FN_SDHI0CD, NULL); |
| 574 | gpio_request(GPIO_FN_SDHI0D3, NULL); |
| 575 | gpio_request(GPIO_FN_SDHI0D2, NULL); |
| 576 | gpio_request(GPIO_FN_SDHI0D1, NULL); |
| 577 | gpio_request(GPIO_FN_SDHI0D0, NULL); |
| 578 | gpio_request(GPIO_FN_SDHI0CMD, NULL); |
| 579 | gpio_request(GPIO_FN_SDHI0CLK, NULL); |
| 580 | |
| 581 | i2c_register_board_info(0, &kfr2r09_backlight_board_info, 1); |
| 582 | |
| 583 | /* Set camera clock frequency and register and alias for rj54n1. */ |
| 584 | camera_clk = clk_get(NULL, "video_clk"); |
| 585 | if (!IS_ERR(camera_clk)) { |
| 586 | clk_set_rate(camera_clk, |
| 587 | clk_round_rate(camera_clk, CEU_MCLK_FREQ)); |
| 588 | clk_put(camera_clk); |
| 589 | } |
| 590 | clk_add_alias(NULL, "1-0050", "video_clk", NULL); |
| 591 | |
| 592 | /* set DRVCRB |
| 593 | * |
| 594 | * use 1.8 V for VccQ_VIO |
| 595 | * use 2.85V for VccQ_SR |
| 596 | */ |
| 597 | __raw_writew((__raw_readw(DRVCRB) & ~0x0003) | 0x0001, DRVCRB); |
| 598 | |
| 599 | gpiod_add_lookup_table(&rj54n1_gpios); |
| 600 | |
| 601 | i2c_register_board_info(1, &kfr2r09_i2c_camera, 1); |
| 602 | |
| 603 | /* Initialize CEU platform device separately to map memory first */ |
| 604 | device_initialize(&kfr2r09_ceu_device.dev); |
| 605 | arch_setup_pdev_archdata(&kfr2r09_ceu_device); |
| 606 | dma_declare_coherent_memory(&kfr2r09_ceu_device.dev, |
| 607 | ceu_dma_membase, ceu_dma_membase, |
| 608 | ceu_dma_membase + CEU_BUFFER_MEMORY_SIZE - 1, |
| 609 | DMA_MEMORY_EXCLUSIVE); |
| 610 | |
| 611 | platform_device_add(&kfr2r09_ceu_device); |
| 612 | |
| 613 | return platform_add_devices(kfr2r09_devices, |
| 614 | ARRAY_SIZE(kfr2r09_devices)); |
| 615 | } |
| 616 | device_initcall(kfr2r09_devices_setup); |
| 617 | |
| 618 | /* Return the board specific boot mode pin configuration */ |
| 619 | static int kfr2r09_mode_pins(void) |
| 620 | { |
| 621 | /* MD0=1, MD1=1, MD2=0: Clock Mode 3 |
| 622 | * MD3=0: 16-bit Area0 Bus Width |
| 623 | * MD5=1: Little Endian |
| 624 | * MD8=1: Test Mode Disabled |
| 625 | */ |
| 626 | return MODE_PIN0 | MODE_PIN1 | MODE_PIN5 | MODE_PIN8; |
| 627 | } |
| 628 | |
| 629 | /* Reserve a portion of memory for CEU buffers */ |
| 630 | static void __init kfr2r09_mv_mem_reserve(void) |
| 631 | { |
| 632 | phys_addr_t phys; |
| 633 | phys_addr_t size = CEU_BUFFER_MEMORY_SIZE; |
| 634 | |
| 635 | phys = memblock_alloc_base(size, PAGE_SIZE, MEMBLOCK_ALLOC_ANYWHERE); |
| 636 | memblock_free(phys, size); |
| 637 | memblock_remove(phys, size); |
| 638 | |
| 639 | ceu_dma_membase = phys; |
| 640 | } |
| 641 | |
| 642 | /* |
| 643 | * The Machine Vector |
| 644 | */ |
| 645 | static struct sh_machine_vector mv_kfr2r09 __initmv = { |
| 646 | .mv_name = "kfr2r09", |
| 647 | .mv_mode_pins = kfr2r09_mode_pins, |
| 648 | .mv_mem_reserve = kfr2r09_mv_mem_reserve, |
| 649 | }; |