Kuninori Morimoto | d55c9a9 | 2011-11-10 18:46:45 -0800 | [diff] [blame] | 1 | /* |
| 2 | * bonito board support |
| 3 | * |
| 4 | * Copyright (C) 2011 Renesas Solutions Corp. |
| 5 | * Copyright (C) 2011 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | #include <linux/kernel.h> |
Kuninori Morimoto | e609b7c | 2011-11-10 18:47:07 -0800 | [diff] [blame] | 23 | #include <linux/i2c.h> |
Kuninori Morimoto | d55c9a9 | 2011-11-10 18:46:45 -0800 | [diff] [blame] | 24 | #include <linux/init.h> |
| 25 | #include <linux/interrupt.h> |
| 26 | #include <linux/irq.h> |
| 27 | #include <linux/platform_device.h> |
| 28 | #include <linux/gpio.h> |
| 29 | #include <mach/common.h> |
| 30 | #include <asm/mach-types.h> |
| 31 | #include <asm/mach/arch.h> |
| 32 | #include <asm/mach/map.h> |
| 33 | #include <asm/mach/time.h> |
| 34 | #include <asm/hardware/cache-l2x0.h> |
| 35 | #include <mach/r8a7740.h> |
Kuninori Morimoto | 665ccfa | 2011-11-10 18:47:16 -0800 | [diff] [blame^] | 36 | #include <video/sh_mobile_lcdc.h> |
Kuninori Morimoto | d55c9a9 | 2011-11-10 18:46:45 -0800 | [diff] [blame] | 37 | |
| 38 | /* |
| 39 | * CS Address device note |
| 40 | *---------------------------------------------------------------- |
| 41 | * 0 0x0000_0000 NOR Flash (64MB) SW12 : bit3 = OFF |
| 42 | * 2 0x0800_0000 ExtNOR (64MB) SW12 : bit3 = OFF |
| 43 | * 4 - |
| 44 | * 5A - |
| 45 | * 5B 0x1600_0000 SRAM (8MB) |
| 46 | * 6 0x1800_0000 FPGA (64K) |
| 47 | * 0x1801_0000 Ether (4KB) |
| 48 | * 0x1801_1000 USB (4KB) |
| 49 | */ |
| 50 | |
| 51 | /* |
| 52 | * SW12 |
| 53 | * |
| 54 | * bit1 bit2 bit3 |
| 55 | *---------------------------------------------------------------------------- |
| 56 | * ON NOR WriteProtect NAND WriteProtect CS0 ExtNOR / CS2 NOR |
| 57 | * OFF NOR Not WriteProtect NAND Not WriteProtect CS0 NOR / CS2 ExtNOR |
| 58 | */ |
| 59 | |
| 60 | /* |
Kuninori Morimoto | b6b37e2 | 2011-11-10 18:46:56 -0800 | [diff] [blame] | 61 | * SCIFA5 (CN42) |
| 62 | * |
| 63 | * S38.3 = ON |
| 64 | * S39.6 = ON |
| 65 | * S43.1 = ON |
| 66 | */ |
| 67 | |
| 68 | /* |
Kuninori Morimoto | 665ccfa | 2011-11-10 18:47:16 -0800 | [diff] [blame^] | 69 | * LCDC0 (CN3/CN4/CN7) |
| 70 | * |
| 71 | * S38.1 = OFF |
| 72 | * S38.2 = OFF |
| 73 | */ |
| 74 | |
| 75 | /* |
Kuninori Morimoto | d55c9a9 | 2011-11-10 18:46:45 -0800 | [diff] [blame] | 76 | * FPGA |
| 77 | */ |
Kuninori Morimoto | b6b37e2 | 2011-11-10 18:46:56 -0800 | [diff] [blame] | 78 | #define BUSSWMR1 0x0070 |
| 79 | #define BUSSWMR2 0x0072 |
| 80 | #define BUSSWMR3 0x0074 |
| 81 | #define BUSSWMR4 0x0076 |
| 82 | |
Kuninori Morimoto | 665ccfa | 2011-11-10 18:47:16 -0800 | [diff] [blame^] | 83 | #define LCDCR 0x10B4 |
Kuninori Morimoto | d55c9a9 | 2011-11-10 18:46:45 -0800 | [diff] [blame] | 84 | #define A1MDSR 0x10E0 |
| 85 | #define BVERR 0x1100 |
| 86 | static u16 bonito_fpga_read(u32 offset) |
| 87 | { |
| 88 | return __raw_readw(0xf0003000 + offset); |
| 89 | } |
| 90 | |
| 91 | static void bonito_fpga_write(u32 offset, u16 val) |
| 92 | { |
| 93 | __raw_writew(val, 0xf0003000 + offset); |
| 94 | } |
| 95 | |
| 96 | /* |
Kuninori Morimoto | e609b7c | 2011-11-10 18:47:07 -0800 | [diff] [blame] | 97 | * PMIC settings |
| 98 | * |
| 99 | * FIXME |
| 100 | * |
| 101 | * bonito board needs some settings by pmic which use i2c access. |
| 102 | * pmic settings use device_initcall() here for use it. |
| 103 | */ |
| 104 | static __u8 *pmic_settings = NULL; |
| 105 | static __u8 pmic_do_2A[] = { |
| 106 | 0x1C, 0x09, |
| 107 | 0x1A, 0x80, |
| 108 | 0xff, 0xff, |
| 109 | }; |
| 110 | |
| 111 | static int __init pmic_init(void) |
| 112 | { |
| 113 | struct i2c_adapter *a = i2c_get_adapter(0); |
| 114 | struct i2c_msg msg; |
| 115 | __u8 buf[2]; |
| 116 | int i, ret; |
| 117 | |
| 118 | if (!pmic_settings) |
| 119 | return 0; |
| 120 | if (!a) |
| 121 | return 0; |
| 122 | |
| 123 | msg.addr = 0x46; |
| 124 | msg.buf = buf; |
| 125 | msg.len = 2; |
| 126 | msg.flags = 0; |
| 127 | |
| 128 | for (i = 0; ; i += 2) { |
| 129 | buf[0] = pmic_settings[i + 0]; |
| 130 | buf[1] = pmic_settings[i + 1]; |
| 131 | |
| 132 | if ((0xff == buf[0]) && (0xff == buf[1])) |
| 133 | break; |
| 134 | |
| 135 | ret = i2c_transfer(a, &msg, 1); |
| 136 | if (ret < 0) { |
| 137 | pr_err("i2c transfer fail\n"); |
| 138 | break; |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | return 0; |
| 143 | } |
| 144 | device_initcall(pmic_init); |
| 145 | |
| 146 | /* |
Kuninori Morimoto | 665ccfa | 2011-11-10 18:47:16 -0800 | [diff] [blame^] | 147 | * LCDC0 |
| 148 | */ |
| 149 | static const struct fb_videomode lcdc0_mode = { |
| 150 | .name = "WVGA Panel", |
| 151 | .xres = 800, |
| 152 | .yres = 480, |
| 153 | .left_margin = 88, |
| 154 | .right_margin = 40, |
| 155 | .hsync_len = 128, |
| 156 | .upper_margin = 20, |
| 157 | .lower_margin = 5, |
| 158 | .vsync_len = 5, |
| 159 | .sync = 0, |
| 160 | }; |
| 161 | |
| 162 | static struct sh_mobile_lcdc_info lcdc0_info = { |
| 163 | .clock_source = LCDC_CLK_BUS, |
| 164 | .ch[0] = { |
| 165 | .chan = LCDC_CHAN_MAINLCD, |
| 166 | .bpp = 16, |
| 167 | .interface_type = RGB24, |
| 168 | .clock_divider = 5, |
| 169 | .flags = 0, |
| 170 | .lcd_cfg = &lcdc0_mode, |
| 171 | .num_cfg = 1, |
| 172 | .lcd_size_cfg = { |
| 173 | .width = 152, |
| 174 | .height = 91, |
| 175 | }, |
| 176 | }, |
| 177 | }; |
| 178 | |
| 179 | static struct resource lcdc0_resources[] = { |
| 180 | [0] = { |
| 181 | .name = "LCDC0", |
| 182 | .start = 0xfe940000, |
| 183 | .end = 0xfe943fff, |
| 184 | .flags = IORESOURCE_MEM, |
| 185 | }, |
| 186 | [1] = { |
| 187 | .start = intcs_evt2irq(0x0580), |
| 188 | .flags = IORESOURCE_IRQ, |
| 189 | }, |
| 190 | }; |
| 191 | |
| 192 | static struct platform_device lcdc0_device = { |
| 193 | .name = "sh_mobile_lcdc_fb", |
| 194 | .id = 0, |
| 195 | .resource = lcdc0_resources, |
| 196 | .num_resources = ARRAY_SIZE(lcdc0_resources), |
| 197 | .dev = { |
| 198 | .platform_data = &lcdc0_info, |
| 199 | .coherent_dma_mask = ~0, |
| 200 | }, |
| 201 | }; |
| 202 | |
| 203 | /* |
Kuninori Morimoto | b6b37e2 | 2011-11-10 18:46:56 -0800 | [diff] [blame] | 204 | * core board devices |
Kuninori Morimoto | d55c9a9 | 2011-11-10 18:46:45 -0800 | [diff] [blame] | 205 | */ |
Kuninori Morimoto | b6b37e2 | 2011-11-10 18:46:56 -0800 | [diff] [blame] | 206 | static struct platform_device *bonito_core_devices[] __initdata = { |
| 207 | }; |
| 208 | |
| 209 | /* |
| 210 | * base board devices |
| 211 | */ |
| 212 | static struct platform_device *bonito_base_devices[] __initdata = { |
Kuninori Morimoto | 665ccfa | 2011-11-10 18:47:16 -0800 | [diff] [blame^] | 213 | &lcdc0_device, |
Kuninori Morimoto | d55c9a9 | 2011-11-10 18:46:45 -0800 | [diff] [blame] | 214 | }; |
| 215 | |
| 216 | /* |
| 217 | * map I/O |
| 218 | */ |
| 219 | static struct map_desc bonito_io_desc[] __initdata = { |
| 220 | /* |
| 221 | * for CPGA/INTC/PFC |
| 222 | * 0xe6000000-0xefffffff -> 0xe6000000-0xefffffff |
| 223 | */ |
| 224 | { |
| 225 | .virtual = 0xe6000000, |
| 226 | .pfn = __phys_to_pfn(0xe6000000), |
| 227 | .length = 160 << 20, |
| 228 | .type = MT_DEVICE_NONSHARED |
| 229 | }, |
| 230 | #ifdef CONFIG_CACHE_L2X0 |
| 231 | /* |
| 232 | * for l2x0_init() |
| 233 | * 0xf0100000-0xf0101000 -> 0xf0002000-0xf0003000 |
| 234 | */ |
| 235 | { |
| 236 | .virtual = 0xf0002000, |
| 237 | .pfn = __phys_to_pfn(0xf0100000), |
| 238 | .length = PAGE_SIZE, |
| 239 | .type = MT_DEVICE_NONSHARED |
| 240 | }, |
| 241 | #endif |
| 242 | /* |
| 243 | * for FPGA (0x1800000-0x19ffffff) |
| 244 | * 0x18000000-0x18002000 -> 0xf0003000-0xf0005000 |
| 245 | */ |
| 246 | { |
| 247 | .virtual = 0xf0003000, |
| 248 | .pfn = __phys_to_pfn(0x18000000), |
| 249 | .length = PAGE_SIZE * 2, |
| 250 | .type = MT_DEVICE_NONSHARED |
| 251 | } |
| 252 | }; |
| 253 | |
| 254 | static void __init bonito_map_io(void) |
| 255 | { |
| 256 | iotable_init(bonito_io_desc, ARRAY_SIZE(bonito_io_desc)); |
| 257 | |
| 258 | /* setup early devices and console here as well */ |
| 259 | r8a7740_add_early_devices(); |
| 260 | shmobile_setup_console(); |
| 261 | } |
| 262 | |
| 263 | /* |
| 264 | * board init |
| 265 | */ |
Kuninori Morimoto | b6b37e2 | 2011-11-10 18:46:56 -0800 | [diff] [blame] | 266 | #define BIT_ON(sw, bit) (sw & (1 << bit)) |
| 267 | #define BIT_OFF(sw, bit) (!(sw & (1 << bit))) |
| 268 | |
Kuninori Morimoto | 665ccfa | 2011-11-10 18:47:16 -0800 | [diff] [blame^] | 269 | #define VCCQ1CR 0xE6058140 |
| 270 | #define VCCQ1LCDCR 0xE6058186 |
| 271 | |
Kuninori Morimoto | d55c9a9 | 2011-11-10 18:46:45 -0800 | [diff] [blame] | 272 | static void __init bonito_init(void) |
| 273 | { |
| 274 | u16 val; |
| 275 | |
| 276 | r8a7740_pinmux_init(); |
| 277 | |
Kuninori Morimoto | e609b7c | 2011-11-10 18:47:07 -0800 | [diff] [blame] | 278 | pmic_settings = pmic_do_2A; |
| 279 | |
Kuninori Morimoto | b6b37e2 | 2011-11-10 18:46:56 -0800 | [diff] [blame] | 280 | /* |
| 281 | * core board settings |
| 282 | */ |
Kuninori Morimoto | d55c9a9 | 2011-11-10 18:46:45 -0800 | [diff] [blame] | 283 | |
| 284 | #ifdef CONFIG_CACHE_L2X0 |
| 285 | /* Early BRESP enable, Shared attribute override enable, 32K*8way */ |
| 286 | l2x0_init(__io(0xf0002000), 0x40440000, 0x82000fff); |
| 287 | #endif |
| 288 | |
| 289 | r8a7740_add_standard_devices(); |
Kuninori Morimoto | b6b37e2 | 2011-11-10 18:46:56 -0800 | [diff] [blame] | 290 | |
| 291 | platform_add_devices(bonito_core_devices, |
| 292 | ARRAY_SIZE(bonito_core_devices)); |
| 293 | |
| 294 | /* |
| 295 | * base board settings |
| 296 | */ |
| 297 | gpio_request(GPIO_PORT176, NULL); |
| 298 | gpio_direction_input(GPIO_PORT176); |
| 299 | if (!gpio_get_value(GPIO_PORT176)) { |
| 300 | u16 bsw2; |
| 301 | u16 bsw3; |
| 302 | u16 bsw4; |
| 303 | |
| 304 | /* |
| 305 | * FPGA |
| 306 | */ |
| 307 | gpio_request(GPIO_FN_CS5B, NULL); |
| 308 | gpio_request(GPIO_FN_CS6A, NULL); |
| 309 | gpio_request(GPIO_FN_CS5A_PORT105, NULL); |
| 310 | gpio_request(GPIO_FN_IRQ10, NULL); |
| 311 | |
| 312 | val = bonito_fpga_read(BVERR); |
| 313 | pr_info("bonito version: cpu %02x, base %02x\n", |
| 314 | ((val >> 8) & 0xFF), |
| 315 | ((val >> 0) & 0xFF)); |
| 316 | |
| 317 | bsw2 = bonito_fpga_read(BUSSWMR2); |
| 318 | bsw3 = bonito_fpga_read(BUSSWMR3); |
| 319 | bsw4 = bonito_fpga_read(BUSSWMR4); |
| 320 | |
| 321 | /* |
| 322 | * SCIFA5 (CN42) |
| 323 | */ |
| 324 | if (BIT_OFF(bsw2, 1) && /* S38.3 = ON */ |
| 325 | BIT_OFF(bsw3, 9) && /* S39.6 = ON */ |
| 326 | BIT_OFF(bsw4, 4)) { /* S43.1 = ON */ |
| 327 | gpio_request(GPIO_FN_SCIFA5_TXD_PORT91, NULL); |
| 328 | gpio_request(GPIO_FN_SCIFA5_RXD_PORT92, NULL); |
| 329 | } |
| 330 | |
Kuninori Morimoto | 665ccfa | 2011-11-10 18:47:16 -0800 | [diff] [blame^] | 331 | /* |
| 332 | * LCDC0 (CN3) |
| 333 | */ |
| 334 | if (BIT_ON(bsw2, 3) && /* S38.1 = OFF */ |
| 335 | BIT_ON(bsw2, 2)) { /* S38.2 = OFF */ |
| 336 | gpio_request(GPIO_FN_LCDC0_SELECT, NULL); |
| 337 | gpio_request(GPIO_FN_LCD0_D0, NULL); |
| 338 | gpio_request(GPIO_FN_LCD0_D1, NULL); |
| 339 | gpio_request(GPIO_FN_LCD0_D2, NULL); |
| 340 | gpio_request(GPIO_FN_LCD0_D3, NULL); |
| 341 | gpio_request(GPIO_FN_LCD0_D4, NULL); |
| 342 | gpio_request(GPIO_FN_LCD0_D5, NULL); |
| 343 | gpio_request(GPIO_FN_LCD0_D6, NULL); |
| 344 | gpio_request(GPIO_FN_LCD0_D7, NULL); |
| 345 | gpio_request(GPIO_FN_LCD0_D8, NULL); |
| 346 | gpio_request(GPIO_FN_LCD0_D9, NULL); |
| 347 | gpio_request(GPIO_FN_LCD0_D10, NULL); |
| 348 | gpio_request(GPIO_FN_LCD0_D11, NULL); |
| 349 | gpio_request(GPIO_FN_LCD0_D12, NULL); |
| 350 | gpio_request(GPIO_FN_LCD0_D13, NULL); |
| 351 | gpio_request(GPIO_FN_LCD0_D14, NULL); |
| 352 | gpio_request(GPIO_FN_LCD0_D15, NULL); |
| 353 | gpio_request(GPIO_FN_LCD0_D16, NULL); |
| 354 | gpio_request(GPIO_FN_LCD0_D17, NULL); |
| 355 | gpio_request(GPIO_FN_LCD0_D18_PORT163, NULL); |
| 356 | gpio_request(GPIO_FN_LCD0_D19_PORT162, NULL); |
| 357 | gpio_request(GPIO_FN_LCD0_D20_PORT161, NULL); |
| 358 | gpio_request(GPIO_FN_LCD0_D21_PORT158, NULL); |
| 359 | gpio_request(GPIO_FN_LCD0_D22_PORT160, NULL); |
| 360 | gpio_request(GPIO_FN_LCD0_D23_PORT159, NULL); |
| 361 | gpio_request(GPIO_FN_LCD0_DCK, NULL); |
| 362 | gpio_request(GPIO_FN_LCD0_VSYN, NULL); |
| 363 | gpio_request(GPIO_FN_LCD0_HSYN, NULL); |
| 364 | gpio_request(GPIO_FN_LCD0_DISP, NULL); |
| 365 | gpio_request(GPIO_FN_LCD0_LCLK_PORT165, NULL); |
| 366 | |
| 367 | gpio_request(GPIO_PORT61, NULL); /* LCDDON */ |
| 368 | gpio_direction_output(GPIO_PORT61, 1); |
| 369 | |
| 370 | /* backlight on */ |
| 371 | bonito_fpga_write(LCDCR, 1); |
| 372 | |
| 373 | /* drivability Max */ |
| 374 | __raw_writew(0x00FF , VCCQ1LCDCR); |
| 375 | __raw_writew(0xFFFF , VCCQ1CR); |
| 376 | } |
| 377 | |
Kuninori Morimoto | b6b37e2 | 2011-11-10 18:46:56 -0800 | [diff] [blame] | 378 | platform_add_devices(bonito_base_devices, |
| 379 | ARRAY_SIZE(bonito_base_devices)); |
| 380 | } |
Kuninori Morimoto | d55c9a9 | 2011-11-10 18:46:45 -0800 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | static void __init bonito_timer_init(void) |
| 384 | { |
| 385 | u16 val; |
| 386 | u8 md_ck = 0; |
| 387 | |
| 388 | /* read MD_CK value */ |
| 389 | val = bonito_fpga_read(A1MDSR); |
| 390 | if (val & (1 << 10)) |
| 391 | md_ck |= MD_CK2; |
| 392 | if (val & (1 << 9)) |
| 393 | md_ck |= MD_CK1; |
| 394 | if (val & (1 << 8)) |
| 395 | md_ck |= MD_CK0; |
| 396 | |
| 397 | r8a7740_clock_init(md_ck); |
| 398 | shmobile_timer.init(); |
| 399 | } |
| 400 | |
| 401 | struct sys_timer bonito_timer = { |
| 402 | .init = bonito_timer_init, |
| 403 | }; |
| 404 | |
| 405 | MACHINE_START(BONITO, "bonito") |
| 406 | .map_io = bonito_map_io, |
| 407 | .init_irq = r8a7740_init_irq, |
| 408 | .handle_irq = shmobile_handle_irq_intc, |
| 409 | .init_machine = bonito_init, |
| 410 | .timer = &bonito_timer, |
| 411 | MACHINE_END |