blob: 70d992c540aeb7b6cc599596d407b7403253b62d [file] [log] [blame]
Kuninori Morimotod55c9a92011-11-10 18:46:45 -08001/*
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 Morimotoe609b7c2011-11-10 18:47:07 -080023#include <linux/i2c.h>
Kuninori Morimotod55c9a92011-11-10 18:46:45 -080024#include <linux/init.h>
25#include <linux/interrupt.h>
26#include <linux/irq.h>
Laurent Pinchart1e47ff22013-01-03 12:54:28 +010027#include <linux/pinctrl/machine.h>
Kuninori Morimotod55c9a92011-11-10 18:46:45 -080028#include <linux/platform_device.h>
29#include <linux/gpio.h>
Guennadi Liakhovetskid3ed18e2012-06-27 00:32:27 +020030#include <linux/regulator/fixed.h>
31#include <linux/regulator/machine.h>
Kuninori Morimoto6bf28052011-11-10 18:47:26 -080032#include <linux/smsc911x.h>
Phil Edworthy63d71122012-02-29 13:46:24 +000033#include <linux/videodev2.h>
Kuninori Morimotod55c9a92011-11-10 18:46:45 -080034#include <mach/common.h>
35#include <asm/mach-types.h>
36#include <asm/mach/arch.h>
37#include <asm/mach/map.h>
38#include <asm/mach/time.h>
39#include <asm/hardware/cache-l2x0.h>
40#include <mach/r8a7740.h>
Rob Herring250a2722012-01-03 16:57:33 -060041#include <mach/irqs.h>
Kuninori Morimoto665ccfa2011-11-10 18:47:16 -080042#include <video/sh_mobile_lcdc.h>
Kuninori Morimotod55c9a92011-11-10 18:46:45 -080043
44/*
45 * CS Address device note
46 *----------------------------------------------------------------
47 * 0 0x0000_0000 NOR Flash (64MB) SW12 : bit3 = OFF
48 * 2 0x0800_0000 ExtNOR (64MB) SW12 : bit3 = OFF
49 * 4 -
50 * 5A -
51 * 5B 0x1600_0000 SRAM (8MB)
52 * 6 0x1800_0000 FPGA (64K)
53 * 0x1801_0000 Ether (4KB)
54 * 0x1801_1000 USB (4KB)
55 */
56
57/*
58 * SW12
59 *
60 * bit1 bit2 bit3
61 *----------------------------------------------------------------------------
62 * ON NOR WriteProtect NAND WriteProtect CS0 ExtNOR / CS2 NOR
63 * OFF NOR Not WriteProtect NAND Not WriteProtect CS0 NOR / CS2 ExtNOR
64 */
65
66/*
Kuninori Morimotob6b37e22011-11-10 18:46:56 -080067 * SCIFA5 (CN42)
68 *
69 * S38.3 = ON
70 * S39.6 = ON
71 * S43.1 = ON
72 */
73
74/*
Kuninori Morimoto665ccfa2011-11-10 18:47:16 -080075 * LCDC0 (CN3/CN4/CN7)
76 *
77 * S38.1 = OFF
78 * S38.2 = OFF
79 */
80
Guennadi Liakhovetskid3ed18e2012-06-27 00:32:27 +020081/* Dummy supplies, where voltage doesn't matter */
82static struct regulator_consumer_supply dummy_supplies[] = {
83 REGULATOR_SUPPLY("vddvario", "smsc911x"),
84 REGULATOR_SUPPLY("vdd33a", "smsc911x"),
85};
86
Kuninori Morimoto665ccfa2011-11-10 18:47:16 -080087/*
Kuninori Morimotod55c9a92011-11-10 18:46:45 -080088 * FPGA
89 */
Kuninori Morimoto6bf28052011-11-10 18:47:26 -080090#define IRQSR0 0x0020
91#define IRQSR1 0x0022
92#define IRQMR0 0x0030
93#define IRQMR1 0x0032
Kuninori Morimotob6b37e22011-11-10 18:46:56 -080094#define BUSSWMR1 0x0070
95#define BUSSWMR2 0x0072
96#define BUSSWMR3 0x0074
97#define BUSSWMR4 0x0076
98
Kuninori Morimoto665ccfa2011-11-10 18:47:16 -080099#define LCDCR 0x10B4
Kuninori Morimoto6bf28052011-11-10 18:47:26 -0800100#define DEVRSTCR1 0x10D0
101#define DEVRSTCR2 0x10D2
Kuninori Morimotod55c9a92011-11-10 18:46:45 -0800102#define A1MDSR 0x10E0
103#define BVERR 0x1100
Kuninori Morimoto6bf28052011-11-10 18:47:26 -0800104
105/* FPGA IRQ */
106#define FPGA_IRQ_BASE (512)
107#define FPGA_IRQ0 (FPGA_IRQ_BASE)
108#define FPGA_IRQ1 (FPGA_IRQ_BASE + 16)
Kuninori Morimoto8900df72011-11-10 18:47:36 -0800109#define FPGA_ETH_IRQ (FPGA_IRQ0 + 15)
Kuninori Morimotod55c9a92011-11-10 18:46:45 -0800110static u16 bonito_fpga_read(u32 offset)
111{
Arnd Bergmann0a4b04d2012-09-14 20:08:08 +0000112 return __raw_readw(IOMEM(0xf0003000) + offset);
Kuninori Morimotod55c9a92011-11-10 18:46:45 -0800113}
114
115static void bonito_fpga_write(u32 offset, u16 val)
116{
Arnd Bergmann0a4b04d2012-09-14 20:08:08 +0000117 __raw_writew(val, IOMEM(0xf0003000) + offset);
Kuninori Morimotod55c9a92011-11-10 18:46:45 -0800118}
119
Kuninori Morimoto6bf28052011-11-10 18:47:26 -0800120static void bonito_fpga_irq_disable(struct irq_data *data)
121{
122 unsigned int irq = data->irq;
123 u32 addr = (irq < 1016) ? IRQMR0 : IRQMR1;
124 int shift = irq % 16;
125
126 bonito_fpga_write(addr, bonito_fpga_read(addr) | (1 << shift));
127}
128
129static void bonito_fpga_irq_enable(struct irq_data *data)
130{
131 unsigned int irq = data->irq;
132 u32 addr = (irq < 1016) ? IRQMR0 : IRQMR1;
133 int shift = irq % 16;
134
135 bonito_fpga_write(addr, bonito_fpga_read(addr) & ~(1 << shift));
136}
137
138static struct irq_chip bonito_fpga_irq_chip __read_mostly = {
139 .name = "bonito FPGA",
140 .irq_mask = bonito_fpga_irq_disable,
141 .irq_unmask = bonito_fpga_irq_enable,
142};
143
144static void bonito_fpga_irq_demux(unsigned int irq, struct irq_desc *desc)
145{
146 u32 val = bonito_fpga_read(IRQSR1) << 16 |
147 bonito_fpga_read(IRQSR0);
148 u32 mask = bonito_fpga_read(IRQMR1) << 16 |
149 bonito_fpga_read(IRQMR0);
150
151 int i;
152
153 val &= ~mask;
154
155 for (i = 0; i < 32; i++) {
156 if (!(val & (1 << i)))
157 continue;
158
159 generic_handle_irq(FPGA_IRQ_BASE + i);
160 }
161}
162
163static void bonito_fpga_init(void)
164{
165 int i;
166
167 bonito_fpga_write(IRQMR0, 0xffff); /* mask all */
168 bonito_fpga_write(IRQMR1, 0xffff); /* mask all */
169
170 /* Device reset */
171 bonito_fpga_write(DEVRSTCR1,
172 (1 << 2)); /* Eth */
173
174 /* FPGA irq require special handling */
175 for (i = FPGA_IRQ_BASE; i < FPGA_IRQ_BASE + 32; i++) {
176 irq_set_chip_and_handler_name(i, &bonito_fpga_irq_chip,
177 handle_level_irq, "level");
178 set_irq_flags(i, IRQF_VALID); /* yuck */
179 }
180
181 irq_set_chained_handler(evt2irq(0x0340), bonito_fpga_irq_demux);
182 irq_set_irq_type(evt2irq(0x0340), IRQ_TYPE_LEVEL_LOW);
183}
184
Kuninori Morimotod55c9a92011-11-10 18:46:45 -0800185/*
Kuninori Morimotoe609b7c2011-11-10 18:47:07 -0800186* PMIC settings
187*
188* FIXME
189*
190* bonito board needs some settings by pmic which use i2c access.
191* pmic settings use device_initcall() here for use it.
192*/
193static __u8 *pmic_settings = NULL;
194static __u8 pmic_do_2A[] = {
195 0x1C, 0x09,
196 0x1A, 0x80,
197 0xff, 0xff,
198};
199
200static int __init pmic_init(void)
201{
202 struct i2c_adapter *a = i2c_get_adapter(0);
203 struct i2c_msg msg;
204 __u8 buf[2];
205 int i, ret;
206
207 if (!pmic_settings)
208 return 0;
209 if (!a)
210 return 0;
211
212 msg.addr = 0x46;
213 msg.buf = buf;
214 msg.len = 2;
215 msg.flags = 0;
216
217 for (i = 0; ; i += 2) {
218 buf[0] = pmic_settings[i + 0];
219 buf[1] = pmic_settings[i + 1];
220
221 if ((0xff == buf[0]) && (0xff == buf[1]))
222 break;
223
224 ret = i2c_transfer(a, &msg, 1);
225 if (ret < 0) {
226 pr_err("i2c transfer fail\n");
227 break;
228 }
229 }
230
231 return 0;
232}
233device_initcall(pmic_init);
234
235/*
Kuninori Morimoto665ccfa2011-11-10 18:47:16 -0800236 * LCDC0
237 */
238static const struct fb_videomode lcdc0_mode = {
239 .name = "WVGA Panel",
240 .xres = 800,
241 .yres = 480,
242 .left_margin = 88,
243 .right_margin = 40,
244 .hsync_len = 128,
245 .upper_margin = 20,
246 .lower_margin = 5,
247 .vsync_len = 5,
248 .sync = 0,
249};
250
251static struct sh_mobile_lcdc_info lcdc0_info = {
252 .clock_source = LCDC_CLK_BUS,
253 .ch[0] = {
254 .chan = LCDC_CHAN_MAINLCD,
Phil Edworthy63d71122012-02-29 13:46:24 +0000255 .fourcc = V4L2_PIX_FMT_RGB565,
Kuninori Morimoto665ccfa2011-11-10 18:47:16 -0800256 .interface_type = RGB24,
257 .clock_divider = 5,
258 .flags = 0,
Laurent Pinchart93ff2592011-11-29 14:33:41 +0100259 .lcd_modes = &lcdc0_mode,
260 .num_modes = 1,
Laurent Pinchartafaad832011-09-11 22:59:04 +0200261 .panel_cfg = {
Kuninori Morimoto665ccfa2011-11-10 18:47:16 -0800262 .width = 152,
263 .height = 91,
264 },
265 },
266};
267
268static struct resource lcdc0_resources[] = {
269 [0] = {
270 .name = "LCDC0",
271 .start = 0xfe940000,
272 .end = 0xfe943fff,
273 .flags = IORESOURCE_MEM,
274 },
275 [1] = {
276 .start = intcs_evt2irq(0x0580),
277 .flags = IORESOURCE_IRQ,
278 },
279};
280
281static struct platform_device lcdc0_device = {
282 .name = "sh_mobile_lcdc_fb",
283 .id = 0,
284 .resource = lcdc0_resources,
285 .num_resources = ARRAY_SIZE(lcdc0_resources),
286 .dev = {
287 .platform_data = &lcdc0_info,
288 .coherent_dma_mask = ~0,
289 },
290};
291
Laurent Pinchart1e47ff22013-01-03 12:54:28 +0100292static const struct pinctrl_map lcdc0_pinctrl_map[] = {
293 /* LCD0 */
294 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_lcdc_fb.0", "pfc-r8a7740",
295 "lcd0_data24_1", "lcd0"),
296 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_lcdc_fb.0", "pfc-r8a7740",
297 "lcd0_lclk_1", "lcd0"),
298 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_lcdc_fb.0", "pfc-r8a7740",
299 "lcd0_sync", "lcd0"),
300};
301
Kuninori Morimoto665ccfa2011-11-10 18:47:16 -0800302/*
Kuninori Morimoto8900df72011-11-10 18:47:36 -0800303 * SMSC 9221
304 */
305static struct resource smsc_resources[] = {
306 [0] = {
307 .start = 0x18010000,
308 .end = 0x18011000 - 1,
309 .flags = IORESOURCE_MEM,
310 },
311 [1] = {
312 .start = FPGA_ETH_IRQ,
313 .flags = IORESOURCE_IRQ,
314 },
315};
316
317static struct smsc911x_platform_config smsc_platdata = {
318 .flags = SMSC911X_USE_16BIT,
319 .phy_interface = PHY_INTERFACE_MODE_MII,
320 .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
321 .irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL,
322};
323
324static struct platform_device smsc_device = {
325 .name = "smsc911x",
326 .dev = {
327 .platform_data = &smsc_platdata,
328 },
329 .resource = smsc_resources,
330 .num_resources = ARRAY_SIZE(smsc_resources),
331};
332
333/*
Kuninori Morimotob6b37e22011-11-10 18:46:56 -0800334 * core board devices
Kuninori Morimotod55c9a92011-11-10 18:46:45 -0800335 */
Kuninori Morimotob6b37e22011-11-10 18:46:56 -0800336static struct platform_device *bonito_core_devices[] __initdata = {
337};
338
339/*
340 * base board devices
341 */
342static struct platform_device *bonito_base_devices[] __initdata = {
Kuninori Morimoto665ccfa2011-11-10 18:47:16 -0800343 &lcdc0_device,
Kuninori Morimoto8900df72011-11-10 18:47:36 -0800344 &smsc_device,
Kuninori Morimotod55c9a92011-11-10 18:46:45 -0800345};
346
347/*
348 * map I/O
349 */
350static struct map_desc bonito_io_desc[] __initdata = {
Kuninori Morimotod55c9a92011-11-10 18:46:45 -0800351 /*
352 * for FPGA (0x1800000-0x19ffffff)
353 * 0x18000000-0x18002000 -> 0xf0003000-0xf0005000
354 */
355 {
356 .virtual = 0xf0003000,
357 .pfn = __phys_to_pfn(0x18000000),
358 .length = PAGE_SIZE * 2,
359 .type = MT_DEVICE_NONSHARED
360 }
361};
362
363static void __init bonito_map_io(void)
364{
Magnus Dammd3ab7222012-02-29 21:37:35 +0900365 r8a7740_map_io();
Kuninori Morimotod55c9a92011-11-10 18:46:45 -0800366 iotable_init(bonito_io_desc, ARRAY_SIZE(bonito_io_desc));
Kuninori Morimotod55c9a92011-11-10 18:46:45 -0800367}
368
369/*
370 * board init
371 */
Kuninori Morimotob6b37e22011-11-10 18:46:56 -0800372#define BIT_ON(sw, bit) (sw & (1 << bit))
373#define BIT_OFF(sw, bit) (!(sw & (1 << bit)))
374
Arnd Bergmann0a4b04d2012-09-14 20:08:08 +0000375#define VCCQ1CR IOMEM(0xE6058140)
376#define VCCQ1LCDCR IOMEM(0xE6058186)
Kuninori Morimoto665ccfa2011-11-10 18:47:16 -0800377
Kuninori Morimotod55c9a92011-11-10 18:46:45 -0800378static void __init bonito_init(void)
379{
380 u16 val;
381
Guennadi Liakhovetskid3ed18e2012-06-27 00:32:27 +0200382 regulator_register_fixed(0, dummy_supplies, ARRAY_SIZE(dummy_supplies));
383
Kuninori Morimotod55c9a92011-11-10 18:46:45 -0800384 r8a7740_pinmux_init();
Kuninori Morimoto6bf28052011-11-10 18:47:26 -0800385 bonito_fpga_init();
Kuninori Morimotod55c9a92011-11-10 18:46:45 -0800386
Kuninori Morimotoe609b7c2011-11-10 18:47:07 -0800387 pmic_settings = pmic_do_2A;
388
Kuninori Morimotob6b37e22011-11-10 18:46:56 -0800389 /*
390 * core board settings
391 */
Kuninori Morimotod55c9a92011-11-10 18:46:45 -0800392
393#ifdef CONFIG_CACHE_L2X0
394 /* Early BRESP enable, Shared attribute override enable, 32K*8way */
Rob Herringa2a47ca2012-03-09 17:16:40 -0600395 l2x0_init(IOMEM(0xf0002000), 0x40440000, 0x82000fff);
Kuninori Morimotod55c9a92011-11-10 18:46:45 -0800396#endif
397
398 r8a7740_add_standard_devices();
Kuninori Morimotob6b37e22011-11-10 18:46:56 -0800399
400 platform_add_devices(bonito_core_devices,
401 ARRAY_SIZE(bonito_core_devices));
402
403 /*
404 * base board settings
405 */
Laurent Pinchart8c2a1412013-02-16 07:38:50 +0100406 gpio_request_one(176, GPIOF_IN, NULL);
407 if (!gpio_get_value(176)) {
Kuninori Morimotob6b37e22011-11-10 18:46:56 -0800408 u16 bsw2;
409 u16 bsw3;
410 u16 bsw4;
411
412 /*
413 * FPGA
414 */
415 gpio_request(GPIO_FN_CS5B, NULL);
416 gpio_request(GPIO_FN_CS6A, NULL);
417 gpio_request(GPIO_FN_CS5A_PORT105, NULL);
418 gpio_request(GPIO_FN_IRQ10, NULL);
419
420 val = bonito_fpga_read(BVERR);
421 pr_info("bonito version: cpu %02x, base %02x\n",
422 ((val >> 8) & 0xFF),
423 ((val >> 0) & 0xFF));
424
425 bsw2 = bonito_fpga_read(BUSSWMR2);
426 bsw3 = bonito_fpga_read(BUSSWMR3);
427 bsw4 = bonito_fpga_read(BUSSWMR4);
428
429 /*
430 * SCIFA5 (CN42)
431 */
432 if (BIT_OFF(bsw2, 1) && /* S38.3 = ON */
433 BIT_OFF(bsw3, 9) && /* S39.6 = ON */
434 BIT_OFF(bsw4, 4)) { /* S43.1 = ON */
435 gpio_request(GPIO_FN_SCIFA5_TXD_PORT91, NULL);
436 gpio_request(GPIO_FN_SCIFA5_RXD_PORT92, NULL);
437 }
438
Kuninori Morimoto665ccfa2011-11-10 18:47:16 -0800439 /*
440 * LCDC0 (CN3)
441 */
442 if (BIT_ON(bsw2, 3) && /* S38.1 = OFF */
443 BIT_ON(bsw2, 2)) { /* S38.2 = OFF */
Laurent Pinchart1e47ff22013-01-03 12:54:28 +0100444 pinctrl_register_mappings(lcdc0_pinctrl_map,
445 ARRAY_SIZE(lcdc0_pinctrl_map));
446 gpio_request(GPIO_FN_LCDC0_SELECT, NULL);
Kuninori Morimoto665ccfa2011-11-10 18:47:16 -0800447
Laurent Pinchart8c2a1412013-02-16 07:38:50 +0100448 gpio_request_one(61, GPIOF_OUT_INIT_HIGH,
Laurent Pinchart89aaf5c2013-01-24 13:16:32 +0100449 NULL); /* LCDDON */
Kuninori Morimoto665ccfa2011-11-10 18:47:16 -0800450
451 /* backlight on */
452 bonito_fpga_write(LCDCR, 1);
453
454 /* drivability Max */
455 __raw_writew(0x00FF , VCCQ1LCDCR);
456 __raw_writew(0xFFFF , VCCQ1CR);
457 }
458
Kuninori Morimotob6b37e22011-11-10 18:46:56 -0800459 platform_add_devices(bonito_base_devices,
460 ARRAY_SIZE(bonito_base_devices));
461 }
Kuninori Morimotod55c9a92011-11-10 18:46:45 -0800462}
463
Magnus Damm23e5bc02012-03-06 17:36:53 +0900464static void __init bonito_earlytimer_init(void)
Kuninori Morimotod55c9a92011-11-10 18:46:45 -0800465{
466 u16 val;
467 u8 md_ck = 0;
468
469 /* read MD_CK value */
470 val = bonito_fpga_read(A1MDSR);
471 if (val & (1 << 10))
472 md_ck |= MD_CK2;
473 if (val & (1 << 9))
474 md_ck |= MD_CK1;
475 if (val & (1 << 8))
476 md_ck |= MD_CK0;
477
478 r8a7740_clock_init(md_ck);
Magnus Damm23e5bc02012-03-06 17:36:53 +0900479 shmobile_earlytimer_init();
Kuninori Morimotod55c9a92011-11-10 18:46:45 -0800480}
481
Kuninori Morimoto8823e2b2012-04-08 22:29:12 -0700482static void __init bonito_add_early_devices(void)
Magnus Damm23e5bc02012-03-06 17:36:53 +0900483{
484 r8a7740_add_early_devices();
Magnus Damm23e5bc02012-03-06 17:36:53 +0900485}
Kuninori Morimotod55c9a92011-11-10 18:46:45 -0800486
487MACHINE_START(BONITO, "bonito")
488 .map_io = bonito_map_io,
Magnus Damm23e5bc02012-03-06 17:36:53 +0900489 .init_early = bonito_add_early_devices,
Kuninori Morimotod55c9a92011-11-10 18:46:45 -0800490 .init_irq = r8a7740_init_irq,
491 .handle_irq = shmobile_handle_irq_intc,
492 .init_machine = bonito_init,
Shawn Guo21cc1b72012-04-26 21:58:41 +0800493 .init_late = shmobile_init_late,
Stephen Warren6bb27d72012-11-08 12:40:59 -0700494 .init_time = bonito_earlytimer_init,
Kuninori Morimotod55c9a92011-11-10 18:46:45 -0800495MACHINE_END