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