Path: blob/master/arch/sh/boards/board-magicpanelr2.c
10817 views
/*1* linux/arch/sh/boards/magicpanel/setup.c2*3* Copyright (C) 2007 Markus Brunner, Mark Jonas4*5* Magic Panel Release 2 board setup6*7* This file is subject to the terms and conditions of the GNU General Public8* License. See the file "COPYING" in the main directory of this archive9* for more details.10*/11#include <linux/init.h>12#include <linux/irq.h>13#include <linux/platform_device.h>14#include <linux/delay.h>15#include <linux/gpio.h>16#include <linux/smsc911x.h>17#include <linux/mtd/mtd.h>18#include <linux/mtd/partitions.h>19#include <linux/mtd/physmap.h>20#include <linux/mtd/map.h>21#include <mach/magicpanelr2.h>22#include <asm/heartbeat.h>23#include <cpu/sh7720.h>2425#define LAN9115_READY (__raw_readl(0xA8000084UL) & 0x00000001UL)2627/* Prefer cmdline over RedBoot */28static const char *probes[] = { "cmdlinepart", "RedBoot", NULL };2930/* Wait until reset finished. Timeout is 100ms. */31static int __init ethernet_reset_finished(void)32{33int i;3435if (LAN9115_READY)36return 1;3738for (i = 0; i < 10; ++i) {39mdelay(10);40if (LAN9115_READY)41return 1;42}4344return 0;45}4647static void __init reset_ethernet(void)48{49/* PMDR: LAN_RESET=on */50CLRBITS_OUTB(0x10, PORT_PMDR);5152udelay(200);5354/* PMDR: LAN_RESET=off */55SETBITS_OUTB(0x10, PORT_PMDR);56}5758static void __init setup_chip_select(void)59{60/* CS2: LAN (0x08000000 - 0x0bffffff) */61/* no idle cycles, normal space, 8 bit data bus */62__raw_writel(0x36db0400, CS2BCR);63/* (SW:1.5 WR:3 HW:1.5), ext. wait */64__raw_writel(0x000003c0, CS2WCR);6566/* CS4: CAN1 (0xb0000000 - 0xb3ffffff) */67/* no idle cycles, normal space, 8 bit data bus */68__raw_writel(0x00000200, CS4BCR);69/* (SW:1.5 WR:3 HW:1.5), ext. wait */70__raw_writel(0x00100981, CS4WCR);7172/* CS5a: CAN2 (0xb4000000 - 0xb5ffffff) */73/* no idle cycles, normal space, 8 bit data bus */74__raw_writel(0x00000200, CS5ABCR);75/* (SW:1.5 WR:3 HW:1.5), ext. wait */76__raw_writel(0x00100981, CS5AWCR);7778/* CS5b: CAN3 (0xb6000000 - 0xb7ffffff) */79/* no idle cycles, normal space, 8 bit data bus */80__raw_writel(0x00000200, CS5BBCR);81/* (SW:1.5 WR:3 HW:1.5), ext. wait */82__raw_writel(0x00100981, CS5BWCR);8384/* CS6a: Rotary (0xb8000000 - 0xb9ffffff) */85/* no idle cycles, normal space, 8 bit data bus */86__raw_writel(0x00000200, CS6ABCR);87/* (SW:1.5 WR:3 HW:1.5), no ext. wait */88__raw_writel(0x001009C1, CS6AWCR);89}9091static void __init setup_port_multiplexing(void)92{93/* A7 GPO(LED8); A6 GPO(LED7); A5 GPO(LED6); A4 GPO(LED5);94* A3 GPO(LED4); A2 GPO(LED3); A1 GPO(LED2); A0 GPO(LED1);95*/96__raw_writew(0x5555, PORT_PACR); /* 01 01 01 01 01 01 01 01 */9798/* B7 GPO(RST4); B6 GPO(RST3); B5 GPO(RST2); B4 GPO(RST1);99* B3 GPO(PB3); B2 GPO(PB2); B1 GPO(PB1); B0 GPO(PB0);100*/101__raw_writew(0x5555, PORT_PBCR); /* 01 01 01 01 01 01 01 01 */102103/* C7 GPO(PC7); C6 GPO(PC6); C5 GPO(PC5); C4 GPO(PC4);104* C3 LCD_DATA3; C2 LCD_DATA2; C1 LCD_DATA1; C0 LCD_DATA0;105*/106__raw_writew(0x5500, PORT_PCCR); /* 01 01 01 01 00 00 00 00 */107108/* D7 GPO(PD7); D6 GPO(PD6); D5 GPO(PD5); D4 GPO(PD4);109* D3 GPO(PD3); D2 GPO(PD2); D1 GPO(PD1); D0 GPO(PD0);110*/111__raw_writew(0x5555, PORT_PDCR); /* 01 01 01 01 01 01 01 01 */112113/* E7 (x); E6 GPI(nu); E5 GPI(nu); E4 LCD_M_DISP;114* E3 LCD_CL1; E2 LCD_CL2; E1 LCD_DON; E0 LCD_FLM;115*/116__raw_writew(0x3C00, PORT_PECR); /* 00 11 11 00 00 00 00 00 */117118/* F7 (x); F6 DA1(VLCD); F5 DA0(nc); F4 AN3;119* F3 AN2(MID_AD); F2 AN1(EARTH_AD); F1 AN0(TEMP); F0 GPI+(nc);120*/121__raw_writew(0x0002, PORT_PFCR); /* 00 00 00 00 00 00 00 10 */122123/* G7 (x); G6 IRQ5(TOUCH_BUSY); G5 IRQ4(TOUCH_IRQ); G4 GPI(KEY2);124* G3 GPI(KEY1); G2 GPO(LED11); G1 GPO(LED10); G0 GPO(LED9);125*/126__raw_writew(0x03D5, PORT_PGCR); /* 00 00 00 11 11 01 01 01 */127128/* H7 (x); H6 /RAS(BRAS); H5 /CAS(BCAS); H4 CKE(BCKE);129* H3 GPO(EARTH_OFF); H2 GPO(EARTH_TEST); H1 USB2_PWR; H0 USB1_PWR;130*/131__raw_writew(0x0050, PORT_PHCR); /* 00 00 00 00 01 01 00 00 */132133/* J7 (x); J6 AUDCK; J5 ASEBRKAK; J4 AUDATA3;134* J3 AUDATA2; J2 AUDATA1; J1 AUDATA0; J0 AUDSYNC;135*/136__raw_writew(0x0000, PORT_PJCR); /* 00 00 00 00 00 00 00 00 */137138/* K7 (x); K6 (x); K5 (x); K4 (x);139* K3 PINT7(/PWR2); K2 PINT6(/PWR1); K1 PINT5(nu); K0 PINT4(FLASH_READY)140*/141__raw_writew(0x00FF, PORT_PKCR); /* 00 00 00 00 11 11 11 11 */142143/* L7 TRST; L6 TMS; L5 TDO; L4 TDI;144* L3 TCK; L2 (x); L1 (x); L0 (x);145*/146__raw_writew(0x0000, PORT_PLCR); /* 00 00 00 00 00 00 00 00 */147148/* M7 GPO(CURRENT_SINK); M6 GPO(PWR_SWITCH); M5 GPO(LAN_SPEED);149* M4 GPO(LAN_RESET); M3 GPO(BUZZER); M2 GPO(LCD_BL);150* M1 CS5B(CAN3_CS); M0 GPI+(nc);151*/152__raw_writew(0x5552, PORT_PMCR); /* 01 01 01 01 01 01 00 10 */153154/* CURRENT_SINK=off, PWR_SWITCH=off, LAN_SPEED=100MBit,155* LAN_RESET=off, BUZZER=off, LCD_BL=off156*/157#if CONFIG_SH_MAGIC_PANEL_R2_VERSION == 2158__raw_writeb(0x30, PORT_PMDR);159#elif CONFIG_SH_MAGIC_PANEL_R2_VERSION == 3160__raw_writeb(0xF0, PORT_PMDR);161#else162#error Unknown revision of PLATFORM_MP_R2163#endif164165/* P7 (x); P6 (x); P5 (x);166* P4 GPO(nu); P3 IRQ3(LAN_IRQ); P2 IRQ2(CAN3_IRQ);167* P1 IRQ1(CAN2_IRQ); P0 IRQ0(CAN1_IRQ)168*/169__raw_writew(0x0100, PORT_PPCR); /* 00 00 00 01 00 00 00 00 */170__raw_writeb(0x10, PORT_PPDR);171172/* R7 A25; R6 A24; R5 A23; R4 A22;173* R3 A21; R2 A20; R1 A19; R0 A0;174*/175gpio_request(GPIO_FN_A25, NULL);176gpio_request(GPIO_FN_A24, NULL);177gpio_request(GPIO_FN_A23, NULL);178gpio_request(GPIO_FN_A22, NULL);179gpio_request(GPIO_FN_A21, NULL);180gpio_request(GPIO_FN_A20, NULL);181gpio_request(GPIO_FN_A19, NULL);182gpio_request(GPIO_FN_A0, NULL);183184/* S7 (x); S6 (x); S5 (x); S4 GPO(EEPROM_CS2);185* S3 GPO(EEPROM_CS1); S2 SIOF0_TXD; S1 SIOF0_RXD; S0 SIOF0_SCK;186*/187__raw_writew(0x0140, PORT_PSCR); /* 00 00 00 01 01 00 00 00 */188189/* T7 (x); T6 (x); T5 (x); T4 COM1_CTS;190* T3 COM1_RTS; T2 COM1_TXD; T1 COM1_RXD; T0 GPO(WDOG)191*/192__raw_writew(0x0001, PORT_PTCR); /* 00 00 00 00 00 00 00 01 */193194/* U7 (x); U6 (x); U5 (x); U4 GPI+(/AC_FAULT);195* U3 GPO(TOUCH_CS); U2 TOUCH_TXD; U1 TOUCH_RXD; U0 TOUCH_SCK;196*/197__raw_writew(0x0240, PORT_PUCR); /* 00 00 00 10 01 00 00 00 */198199/* V7 (x); V6 (x); V5 (x); V4 GPO(MID2);200* V3 GPO(MID1); V2 CARD_TxD; V1 CARD_RxD; V0 GPI+(/BAT_FAULT);201*/202__raw_writew(0x0142, PORT_PVCR); /* 00 00 00 01 01 00 00 10 */203}204205static void __init mpr2_setup(char **cmdline_p)206{207/* set Pin Select Register A:208* /PCC_CD1, /PCC_CD2, PCC_BVD1, PCC_BVD2,209* /IOIS16, IRQ4, IRQ5, USB1d_SUSPEND210*/211__raw_writew(0xAABC, PORT_PSELA);212/* set Pin Select Register B:213* /SCIF0_RTS, /SCIF0_CTS, LCD_VCPWC,214* LCD_VEPWC, IIC_SDA, IIC_SCL, Reserved215*/216__raw_writew(0x3C00, PORT_PSELB);217/* set Pin Select Register C:218* SIOF1_SCK, SIOF1_RxD, SCIF1_RxD, SCIF1_TxD, Reserved219*/220__raw_writew(0x0000, PORT_PSELC);221/* set Pin Select Register D: Reserved, SIOF1_TxD, Reserved, SIOF1_MCLK,222* Reserved, SIOF1_SYNC, Reserved, SCIF1_SCK, Reserved223*/224__raw_writew(0x0000, PORT_PSELD);225/* set USB TxRx Control: Reserved, DRV, Reserved, USB_TRANS, USB_SEL */226__raw_writew(0x0101, PORT_UTRCTL);227/* set USB Clock Control: USSCS, USSTB, Reserved (HighByte always A5) */228__raw_writew(0xA5C0, PORT_UCLKCR_W);229230setup_chip_select();231232setup_port_multiplexing();233234reset_ethernet();235236printk(KERN_INFO "Magic Panel Release 2 A.%i\n",237CONFIG_SH_MAGIC_PANEL_R2_VERSION);238239if (ethernet_reset_finished() == 0)240printk(KERN_WARNING "Ethernet not ready\n");241}242243static struct resource smsc911x_resources[] = {244[0] = {245.start = 0xa8000000,246.end = 0xabffffff,247.flags = IORESOURCE_MEM,248},249[1] = {250.start = 35,251.end = 35,252.flags = IORESOURCE_IRQ,253},254};255256static struct smsc911x_platform_config smsc911x_config = {257.phy_interface = PHY_INTERFACE_MODE_MII,258.irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,259.irq_type = SMSC911X_IRQ_TYPE_OPEN_DRAIN,260.flags = SMSC911X_USE_32BIT,261};262263static struct platform_device smsc911x_device = {264.name = "smsc911x",265.id = -1,266.num_resources = ARRAY_SIZE(smsc911x_resources),267.resource = smsc911x_resources,268.dev = {269.platform_data = &smsc911x_config,270},271};272273static struct resource heartbeat_resources[] = {274[0] = {275.start = PA_LED,276.end = PA_LED,277.flags = IORESOURCE_MEM,278},279};280281static struct heartbeat_data heartbeat_data = {282.flags = HEARTBEAT_INVERTED,283};284285static struct platform_device heartbeat_device = {286.name = "heartbeat",287.id = -1,288.dev = {289.platform_data = &heartbeat_data,290},291.num_resources = ARRAY_SIZE(heartbeat_resources),292.resource = heartbeat_resources,293};294295static struct mtd_partition *parsed_partitions;296297static struct mtd_partition mpr2_partitions[] = {298/* Reserved for bootloader, read-only */299{300.name = "Bootloader",301.offset = 0x00000000UL,302.size = MPR2_MTD_BOOTLOADER_SIZE,303.mask_flags = MTD_WRITEABLE,304},305/* Reserved for kernel image */306{307.name = "Kernel",308.offset = MTDPART_OFS_NXTBLK,309.size = MPR2_MTD_KERNEL_SIZE,310},311/* Rest is used for Flash FS */312{313.name = "Flash_FS",314.offset = MTDPART_OFS_NXTBLK,315.size = MTDPART_SIZ_FULL,316}317};318319static struct physmap_flash_data flash_data = {320.width = 2,321};322323static struct resource flash_resource = {324.start = 0x00000000,325.end = 0x2000000UL,326.flags = IORESOURCE_MEM,327};328329static struct platform_device flash_device = {330.name = "physmap-flash",331.id = -1,332.resource = &flash_resource,333.num_resources = 1,334.dev = {335.platform_data = &flash_data,336},337};338339static struct mtd_info *flash_mtd;340341static struct map_info mpr2_flash_map = {342.name = "Magic Panel R2 Flash",343.size = 0x2000000UL,344.bankwidth = 2,345};346347static void __init set_mtd_partitions(void)348{349int nr_parts = 0;350351simple_map_init(&mpr2_flash_map);352flash_mtd = do_map_probe("cfi_probe", &mpr2_flash_map);353nr_parts = parse_mtd_partitions(flash_mtd, probes,354&parsed_partitions, 0);355/* If there is no partition table, used the hard coded table */356if (nr_parts <= 0) {357flash_data.parts = mpr2_partitions;358flash_data.nr_parts = ARRAY_SIZE(mpr2_partitions);359} else {360flash_data.nr_parts = nr_parts;361flash_data.parts = parsed_partitions;362}363}364365/*366* Add all resources to the platform_device367*/368369static struct platform_device *mpr2_devices[] __initdata = {370&heartbeat_device,371&smsc911x_device,372&flash_device,373};374375376static int __init mpr2_devices_setup(void)377{378set_mtd_partitions();379return platform_add_devices(mpr2_devices, ARRAY_SIZE(mpr2_devices));380}381device_initcall(mpr2_devices_setup);382383/*384* Initialize IRQ setting385*/386static void __init init_mpr2_IRQ(void)387{388plat_irq_setup_pins(IRQ_MODE_IRQ); /* install handlers for IRQ0-5 */389390irq_set_irq_type(32, IRQ_TYPE_LEVEL_LOW); /* IRQ0 CAN1 */391irq_set_irq_type(33, IRQ_TYPE_LEVEL_LOW); /* IRQ1 CAN2 */392irq_set_irq_type(34, IRQ_TYPE_LEVEL_LOW); /* IRQ2 CAN3 */393irq_set_irq_type(35, IRQ_TYPE_LEVEL_LOW); /* IRQ3 SMSC9115 */394irq_set_irq_type(36, IRQ_TYPE_EDGE_RISING); /* IRQ4 touchscreen */395irq_set_irq_type(37, IRQ_TYPE_EDGE_FALLING); /* IRQ5 touchscreen */396397intc_set_priority(32, 13); /* IRQ0 CAN1 */398intc_set_priority(33, 13); /* IRQ0 CAN2 */399intc_set_priority(34, 13); /* IRQ0 CAN3 */400intc_set_priority(35, 6); /* IRQ3 SMSC9115 */401}402403/*404* The Machine Vector405*/406407static struct sh_machine_vector mv_mpr2 __initmv = {408.mv_name = "mpr2",409.mv_setup = mpr2_setup,410.mv_init_irq = init_mpr2_IRQ,411};412413414