4 * Copyright (C) 2011 Renesas Solutions Corp.
5 * Copyright (C) 2011 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
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.
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.
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
22 #include <linux/kernel.h>
23 #include <linux/i2c.h>
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 <linux/smsc911x.h>
30 #include <linux/videodev2.h>
31 #include <mach/common.h>
32 #include <asm/mach-types.h>
33 #include <asm/mach/arch.h>
34 #include <asm/mach/map.h>
35 #include <asm/mach/time.h>
36 #include <asm/hardware/cache-l2x0.h>
37 #include <mach/r8a7740.h>
38 #include <mach/irqs.h>
39 #include <video/sh_mobile_lcdc.h>
42 * CS Address device note
43 *----------------------------------------------------------------
44 * 0 0x0000_0000 NOR Flash (64MB) SW12 : bit3 = OFF
45 * 2 0x0800_0000 ExtNOR (64MB) SW12 : bit3 = OFF
48 * 5B 0x1600_0000 SRAM (8MB)
49 * 6 0x1800_0000 FPGA (64K)
50 * 0x1801_0000 Ether (4KB)
51 * 0x1801_1000 USB (4KB)
58 *----------------------------------------------------------------------------
59 * ON NOR WriteProtect NAND WriteProtect CS0 ExtNOR / CS2 NOR
60 * OFF NOR Not WriteProtect NAND Not WriteProtect CS0 NOR / CS2 ExtNOR
85 #define BUSSWMR1 0x0070
86 #define BUSSWMR2 0x0072
87 #define BUSSWMR3 0x0074
88 #define BUSSWMR4 0x0076
91 #define DEVRSTCR1 0x10D0
92 #define DEVRSTCR2 0x10D2
97 #define FPGA_IRQ_BASE (512)
98 #define FPGA_IRQ0 (FPGA_IRQ_BASE)
99 #define FPGA_IRQ1 (FPGA_IRQ_BASE + 16)
100 #define FPGA_ETH_IRQ (FPGA_IRQ0 + 15)
101 static u16
bonito_fpga_read(u32 offset
)
103 return __raw_readw(0xf0003000 + offset
);
106 static void bonito_fpga_write(u32 offset
, u16 val
)
108 __raw_writew(val
, 0xf0003000 + offset
);
111 static void bonito_fpga_irq_disable(struct irq_data
*data
)
113 unsigned int irq
= data
->irq
;
114 u32 addr
= (irq
< 1016) ? IRQMR0
: IRQMR1
;
115 int shift
= irq
% 16;
117 bonito_fpga_write(addr
, bonito_fpga_read(addr
) | (1 << shift
));
120 static void bonito_fpga_irq_enable(struct irq_data
*data
)
122 unsigned int irq
= data
->irq
;
123 u32 addr
= (irq
< 1016) ? IRQMR0
: IRQMR1
;
124 int shift
= irq
% 16;
126 bonito_fpga_write(addr
, bonito_fpga_read(addr
) & ~(1 << shift
));
129 static struct irq_chip bonito_fpga_irq_chip __read_mostly
= {
130 .name
= "bonito FPGA",
131 .irq_mask
= bonito_fpga_irq_disable
,
132 .irq_unmask
= bonito_fpga_irq_enable
,
135 static void bonito_fpga_irq_demux(unsigned int irq
, struct irq_desc
*desc
)
137 u32 val
= bonito_fpga_read(IRQSR1
) << 16 |
138 bonito_fpga_read(IRQSR0
);
139 u32 mask
= bonito_fpga_read(IRQMR1
) << 16 |
140 bonito_fpga_read(IRQMR0
);
146 for (i
= 0; i
< 32; i
++) {
147 if (!(val
& (1 << i
)))
150 generic_handle_irq(FPGA_IRQ_BASE
+ i
);
154 static void bonito_fpga_init(void)
158 bonito_fpga_write(IRQMR0
, 0xffff); /* mask all */
159 bonito_fpga_write(IRQMR1
, 0xffff); /* mask all */
162 bonito_fpga_write(DEVRSTCR1
,
165 /* FPGA irq require special handling */
166 for (i
= FPGA_IRQ_BASE
; i
< FPGA_IRQ_BASE
+ 32; i
++) {
167 irq_set_chip_and_handler_name(i
, &bonito_fpga_irq_chip
,
168 handle_level_irq
, "level");
169 set_irq_flags(i
, IRQF_VALID
); /* yuck */
172 irq_set_chained_handler(evt2irq(0x0340), bonito_fpga_irq_demux
);
173 irq_set_irq_type(evt2irq(0x0340), IRQ_TYPE_LEVEL_LOW
);
181 * bonito board needs some settings by pmic which use i2c access.
182 * pmic settings use device_initcall() here for use it.
184 static __u8
*pmic_settings
= NULL
;
185 static __u8 pmic_do_2A
[] = {
191 static int __init
pmic_init(void)
193 struct i2c_adapter
*a
= i2c_get_adapter(0);
208 for (i
= 0; ; i
+= 2) {
209 buf
[0] = pmic_settings
[i
+ 0];
210 buf
[1] = pmic_settings
[i
+ 1];
212 if ((0xff == buf
[0]) && (0xff == buf
[1]))
215 ret
= i2c_transfer(a
, &msg
, 1);
217 pr_err("i2c transfer fail\n");
224 device_initcall(pmic_init
);
229 static const struct fb_videomode lcdc0_mode
= {
230 .name
= "WVGA Panel",
242 static struct sh_mobile_lcdc_info lcdc0_info
= {
243 .clock_source
= LCDC_CLK_BUS
,
245 .chan
= LCDC_CHAN_MAINLCD
,
246 .fourcc
= V4L2_PIX_FMT_RGB565
,
247 .interface_type
= RGB24
,
250 .lcd_modes
= &lcdc0_mode
,
259 static struct resource lcdc0_resources
[] = {
264 .flags
= IORESOURCE_MEM
,
267 .start
= intcs_evt2irq(0x0580),
268 .flags
= IORESOURCE_IRQ
,
272 static struct platform_device lcdc0_device
= {
273 .name
= "sh_mobile_lcdc_fb",
275 .resource
= lcdc0_resources
,
276 .num_resources
= ARRAY_SIZE(lcdc0_resources
),
278 .platform_data
= &lcdc0_info
,
279 .coherent_dma_mask
= ~0,
286 static struct resource smsc_resources
[] = {
289 .end
= 0x18011000 - 1,
290 .flags
= IORESOURCE_MEM
,
293 .start
= FPGA_ETH_IRQ
,
294 .flags
= IORESOURCE_IRQ
,
298 static struct smsc911x_platform_config smsc_platdata
= {
299 .flags
= SMSC911X_USE_16BIT
,
300 .phy_interface
= PHY_INTERFACE_MODE_MII
,
301 .irq_polarity
= SMSC911X_IRQ_POLARITY_ACTIVE_LOW
,
302 .irq_type
= SMSC911X_IRQ_TYPE_PUSH_PULL
,
305 static struct platform_device smsc_device
= {
308 .platform_data
= &smsc_platdata
,
310 .resource
= smsc_resources
,
311 .num_resources
= ARRAY_SIZE(smsc_resources
),
317 static struct platform_device
*bonito_core_devices
[] __initdata
= {
323 static struct platform_device
*bonito_base_devices
[] __initdata
= {
331 static struct map_desc bonito_io_desc
[] __initdata
= {
333 * for FPGA (0x1800000-0x19ffffff)
334 * 0x18000000-0x18002000 -> 0xf0003000-0xf0005000
337 .virtual = 0xf0003000,
338 .pfn
= __phys_to_pfn(0x18000000),
339 .length
= PAGE_SIZE
* 2,
340 .type
= MT_DEVICE_NONSHARED
344 static void __init
bonito_map_io(void)
347 iotable_init(bonito_io_desc
, ARRAY_SIZE(bonito_io_desc
));
353 #define BIT_ON(sw, bit) (sw & (1 << bit))
354 #define BIT_OFF(sw, bit) (!(sw & (1 << bit)))
356 #define VCCQ1CR 0xE6058140
357 #define VCCQ1LCDCR 0xE6058186
359 static void __init
bonito_init(void)
363 r8a7740_pinmux_init();
366 pmic_settings
= pmic_do_2A
;
369 * core board settings
372 #ifdef CONFIG_CACHE_L2X0
373 /* Early BRESP enable, Shared attribute override enable, 32K*8way */
374 l2x0_init(IOMEM(0xf0002000), 0x40440000, 0x82000fff);
377 r8a7740_add_standard_devices();
379 platform_add_devices(bonito_core_devices
,
380 ARRAY_SIZE(bonito_core_devices
));
383 * base board settings
385 gpio_request(GPIO_PORT176
, NULL
);
386 gpio_direction_input(GPIO_PORT176
);
387 if (!gpio_get_value(GPIO_PORT176
)) {
395 gpio_request(GPIO_FN_CS5B
, NULL
);
396 gpio_request(GPIO_FN_CS6A
, NULL
);
397 gpio_request(GPIO_FN_CS5A_PORT105
, NULL
);
398 gpio_request(GPIO_FN_IRQ10
, NULL
);
400 val
= bonito_fpga_read(BVERR
);
401 pr_info("bonito version: cpu %02x, base %02x\n",
403 ((val
>> 0) & 0xFF));
405 bsw2
= bonito_fpga_read(BUSSWMR2
);
406 bsw3
= bonito_fpga_read(BUSSWMR3
);
407 bsw4
= bonito_fpga_read(BUSSWMR4
);
412 if (BIT_OFF(bsw2
, 1) && /* S38.3 = ON */
413 BIT_OFF(bsw3
, 9) && /* S39.6 = ON */
414 BIT_OFF(bsw4
, 4)) { /* S43.1 = ON */
415 gpio_request(GPIO_FN_SCIFA5_TXD_PORT91
, NULL
);
416 gpio_request(GPIO_FN_SCIFA5_RXD_PORT92
, NULL
);
422 if (BIT_ON(bsw2
, 3) && /* S38.1 = OFF */
423 BIT_ON(bsw2
, 2)) { /* S38.2 = OFF */
424 gpio_request(GPIO_FN_LCDC0_SELECT
, NULL
);
425 gpio_request(GPIO_FN_LCD0_D0
, NULL
);
426 gpio_request(GPIO_FN_LCD0_D1
, NULL
);
427 gpio_request(GPIO_FN_LCD0_D2
, NULL
);
428 gpio_request(GPIO_FN_LCD0_D3
, NULL
);
429 gpio_request(GPIO_FN_LCD0_D4
, NULL
);
430 gpio_request(GPIO_FN_LCD0_D5
, NULL
);
431 gpio_request(GPIO_FN_LCD0_D6
, NULL
);
432 gpio_request(GPIO_FN_LCD0_D7
, NULL
);
433 gpio_request(GPIO_FN_LCD0_D8
, NULL
);
434 gpio_request(GPIO_FN_LCD0_D9
, NULL
);
435 gpio_request(GPIO_FN_LCD0_D10
, NULL
);
436 gpio_request(GPIO_FN_LCD0_D11
, NULL
);
437 gpio_request(GPIO_FN_LCD0_D12
, NULL
);
438 gpio_request(GPIO_FN_LCD0_D13
, NULL
);
439 gpio_request(GPIO_FN_LCD0_D14
, NULL
);
440 gpio_request(GPIO_FN_LCD0_D15
, NULL
);
441 gpio_request(GPIO_FN_LCD0_D16
, NULL
);
442 gpio_request(GPIO_FN_LCD0_D17
, NULL
);
443 gpio_request(GPIO_FN_LCD0_D18_PORT163
, NULL
);
444 gpio_request(GPIO_FN_LCD0_D19_PORT162
, NULL
);
445 gpio_request(GPIO_FN_LCD0_D20_PORT161
, NULL
);
446 gpio_request(GPIO_FN_LCD0_D21_PORT158
, NULL
);
447 gpio_request(GPIO_FN_LCD0_D22_PORT160
, NULL
);
448 gpio_request(GPIO_FN_LCD0_D23_PORT159
, NULL
);
449 gpio_request(GPIO_FN_LCD0_DCK
, NULL
);
450 gpio_request(GPIO_FN_LCD0_VSYN
, NULL
);
451 gpio_request(GPIO_FN_LCD0_HSYN
, NULL
);
452 gpio_request(GPIO_FN_LCD0_DISP
, NULL
);
453 gpio_request(GPIO_FN_LCD0_LCLK_PORT165
, NULL
);
455 gpio_request(GPIO_PORT61
, NULL
); /* LCDDON */
456 gpio_direction_output(GPIO_PORT61
, 1);
459 bonito_fpga_write(LCDCR
, 1);
461 /* drivability Max */
462 __raw_writew(0x00FF , VCCQ1LCDCR
);
463 __raw_writew(0xFFFF , VCCQ1CR
);
466 platform_add_devices(bonito_base_devices
,
467 ARRAY_SIZE(bonito_base_devices
));
471 static void __init
bonito_earlytimer_init(void)
476 /* read MD_CK value */
477 val
= bonito_fpga_read(A1MDSR
);
485 r8a7740_clock_init(md_ck
);
486 shmobile_earlytimer_init();
489 void __init
bonito_add_early_devices(void)
491 r8a7740_add_early_devices();
493 /* override timer setup with board-specific code */
494 shmobile_timer
.init
= bonito_earlytimer_init
;
497 MACHINE_START(BONITO
, "bonito")
498 .map_io
= bonito_map_io
,
499 .init_early
= bonito_add_early_devices
,
500 .init_irq
= r8a7740_init_irq
,
501 .handle_irq
= shmobile_handle_irq_intc
,
502 .init_machine
= bonito_init
,
503 .timer
= &shmobile_timer
,