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