Add basic support for the phyCARD-L aka PCA-A-102.

Signed-off-by: Juergen Kilb <J.Kilb@phytec.de>

---
Index: linux-2.6.33.7/arch/arm/mach-omap2/board-pca102.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ linux-2.6.33.7/arch/arm/mach-omap2/board-pca102.c	2010-11-09 18:39:11.390868537 +0100
@@ -0,0 +1,401 @@
+/*
+ * linux/arch/arm/mach-omap2/board-pca102.c
+ *
+ * Copyright (C) 2010 Phytec Messtechnik GmbH
+ *
+ * Modified from mach-omap2/board-evm.c
+ *
+ * Initial code: Syed Mohammed Khasim
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/delay.h>
+#include <linux/err.h>
+#include <linux/clk.h>
+#include <linux/io.h>
+#include <linux/gpio.h>
+#include <linux/input.h>
+#include <linux/leds.h>
+#include <linux/interrupt.h>
+
+#include <linux/mtd/mtd.h>
+#include <linux/mtd/partitions.h>
+#include <linux/mtd/nand.h>
+
+#include <linux/spi/spi.h>
+#include <linux/spi/ads7846.h>
+#include <linux/i2c/twl.h>
+#include <linux/usb/otg.h>
+#include <linux/smsc911x.h>
+
+#include <linux/regulator/machine.h>
+
+#include <mach/hardware.h>
+#include <asm/mach-types.h>
+#include <asm/mach/arch.h>
+#include <asm/mach/map.h>
+#include <asm/mach/flash.h>
+
+#include <plat/board.h>
+#include <plat/usb.h>
+#include <plat/common.h>
+#include <plat/mcspi.h>
+#include <plat/gpmc.h>
+#include <plat/nand.h>
+#include <plat/timer-gp.h>
+
+#include "mux.h"
+#include "sdram-micron-mt46h32m32lf-6.h"
+
+#undef PCA102_PCB_1334_1
+#define	PCA102_PCB_1334_2
+
+#ifdef PCA102_PCB_1334_1
+#define OMAP3_PCA102_TS_GPIO		175
+#define OMAP3_PCA102_EHCI_VBUS		22
+#define OMAP3_PCA102_EHCI_SELECT	25
+#endif
+
+#ifdef PCA102_PCB_1334_2
+#define OMAP3_PCA102_TS_GPIO		175
+#define OMAP3_PCA102_EHCI_VBUS		22
+#define OMAP3_PCA102_EHCI_OC		25
+#define OMAP3_PCA102_EHCI_nRST		65
+#endif
+
+#define OMAP3_PCA102_OTG_SELECT		24
+
+#define OMAP3_PCA102_ETHR_START		0x2c000000
+#define OMAP3_PCA102_ETHR_SIZE		1024
+#define OMAP3_PCA102_ETHR_ID_REV	0x50
+#define OMAP3_PCA102_ETHR_GPIO_IRQ	177
+#define OMAP3_PCA102_SMSC911X_CS	5
+
+#define GPMC_CS0_BASE  0x60
+#define GPMC_CS_SIZE   0x30
+
+#include <linux/dma-mapping.h>
+#include <plat/omap-ac97.h>
+
+static struct omap_ac97_data   omap3beagle_ac97_data = {
+       .reset_gpio     = 156,
+       .mcbsp          = 1,
+};
+
+static uint64_t                mcbsp_dmamask  = ~(uint32_t)0;
+static struct platform_device omap3beagle_ac97_device = {
+	.name	= "omap-ac97",
+	.id	= -1,
+	.dev	= {
+		/* TODO: that's the wrong place... :( this should be set for
+		* the McBSP device */
+		.coherent_dma_mask	= DMA_BIT_MASK(32),
+		.dma_mask		= &mcbsp_dmamask,
+		.platform_data		= &omap3beagle_ac97_data,
+	}
+};
+
+static struct omap_nand_platform_data omap3_pca102_nand_data = {
+	.options	= NAND_BUSWIDTH_16,
+	.dma_channel	= -1,	/* disable DMA in OMAP NAND driver */
+	.nand_setup	= NULL,
+	.dev_ready	= NULL,
+};
+
+static struct resource omap3_pca102_nand_resource = {
+	.flags		= IORESOURCE_MEM,
+};
+
+static struct platform_device omap3_pca102_nand_device = {
+	.name	= "omap2-nand",
+	.id	= -1,
+	.dev	= {
+		.platform_data  = &omap3_pca102_nand_data,
+		},
+	.num_resources	= 1,
+	.resource	= &omap3_pca102_nand_resource,
+};
+
+#if defined(CONFIG_SMSC911X) || defined(CONFIG_SMSC911X_MODULE)
+static struct resource omap3_pca102_smsc911x_resources[] = {
+	[0] =	{
+		.start	= OMAP3_PCA102_ETHR_START,
+		.end	= (OMAP3_PCA102_ETHR_START +
+				OMAP3_PCA102_ETHR_SIZE - 1),
+		.flags	= IORESOURCE_MEM,
+	},
+	[1] =	{
+		.start	= OMAP_GPIO_IRQ(OMAP3_PCA102_ETHR_GPIO_IRQ),
+		.end	= OMAP_GPIO_IRQ(OMAP3_PCA102_ETHR_GPIO_IRQ),
+		.flags	= (IORESOURCE_IRQ | IRQF_TRIGGER_LOW),
+	},
+};
+
+static struct smsc911x_platform_config smsc911x_config = {
+	.phy_interface  = PHY_INTERFACE_MODE_MII,
+	.irq_polarity   = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
+	.irq_type       = SMSC911X_IRQ_TYPE_PUSH_PULL,
+	.flags          = (SMSC911X_USE_32BIT | SMSC911X_SAVE_MAC_ADDRESS),
+};
+
+static struct platform_device omap3_pca102_smsc911x_device = {
+	.name		= "smsc911x",
+	.id		= -1,
+	.num_resources	= ARRAY_SIZE(omap3_pca102_smsc911x_resources),
+	.resource	= &omap3_pca102_smsc911x_resources[0],
+	.dev		= {
+		.platform_data = &smsc911x_config,
+	},
+};
+
+static inline void __init omap3_pca102_init_smsc911x(void)
+{
+	int eth_cs;
+	struct clk *l3ck;
+	unsigned int rate;
+
+	eth_cs = OMAP3_PCA102_SMSC911X_CS;
+
+	l3ck = clk_get(NULL, "l3_ck");
+	if (IS_ERR(l3ck))
+		rate = 100000000;
+	else
+		rate = clk_get_rate(l3ck);
+
+	omap_mux_init_gpio(OMAP3_PCA102_ETHR_GPIO_IRQ, OMAP_PIN_INPUT);
+
+	if (gpio_request(OMAP3_PCA102_ETHR_GPIO_IRQ, "SMSC911x irq") < 0) {
+		printk(KERN_ERR "Failed to request GPIO%d for smsc911x IRQ\n",
+			OMAP3_PCA102_ETHR_GPIO_IRQ);
+		return;
+	}
+
+	gpio_direction_input(OMAP3_PCA102_ETHR_GPIO_IRQ);
+	platform_device_register(&omap3_pca102_smsc911x_device);
+}
+
+#else
+static inline void __init omap3_pca102_init_smsc911x(void) { return; }
+#endif
+
+static struct regulator_consumer_supply omap3_pca102_vmmc1_supply = {
+	.supply			= "vmmc",
+};
+
+/* VMMC1 for MMC1 pins CMD, CLK, DAT0..DAT3 (20 mA, plus card == max 220 mA) */
+static struct regulator_init_data omap3_pca102_vmmc1 = {
+	.constraints = {
+		.min_uV			= 1850000,
+		.max_uV			= 3150000,
+		.valid_modes_mask	= REGULATOR_MODE_NORMAL
+					| REGULATOR_MODE_STANDBY,
+		.valid_ops_mask		= REGULATOR_CHANGE_VOLTAGE
+					| REGULATOR_CHANGE_MODE
+					| REGULATOR_CHANGE_STATUS,
+	},
+	.num_consumer_supplies	= 1,
+	.consumer_supplies	= &omap3_pca102_vmmc1_supply,
+};
+
+static int __init omap3_pca102_i2c_init(void)
+{
+	/*
+	 * REVISIT: These entries can be set in omap3evm_twl_data
+	 * after a merge with MFD tree
+	 */
+	/* PMIC */
+	omap_register_i2c_bus(1, 400, NULL, 0);
+	/* EEPROM */
+	omap_register_i2c_bus(2, 400, NULL, 0);
+	/* Baseboard */
+	omap_register_i2c_bus(3, 400, NULL, 0);
+	return 0;
+}
+
+static struct platform_device omap3_pca102_lcd_device = {
+	.name		= "omap3_pca102_lcd",
+	.id		= -1,
+};
+
+static struct omap_lcd_config omap3_pca102_lcd_config __initdata = {
+	.ctrl_name	= "internal",
+};
+
+static struct omap_board_config_kernel omap3_pca102_config[] __initdata = {
+	{ OMAP_TAG_LCD,		&omap3_pca102_lcd_config },
+};
+
+static void __init omap3_pca102_init_irq(void)
+{
+	omap_board_config = omap3_pca102_config;
+	omap_board_config_size = ARRAY_SIZE(omap3_pca102_config);
+	omap2_init_common_hw(mt46h32m32lf6_sdrc_params, NULL);
+	omap_init_irq();
+	omap_gpio_init();
+}
+
+static struct platform_device *omap3_pca102_devices[] __initdata = {
+	&omap3_pca102_lcd_device,
+};
+
+static void __init omap3_pca102_flash_init(void)
+{
+	u8 cs = 0;
+	u8 nandcs = GPMC_CS_NUM + 1;
+
+	u32 gpmc_base_add = OMAP34XX_GPMC_VIRT;
+
+	/* find out the chip-select on which NAND exists */
+	while (cs < GPMC_CS_NUM) {
+		u32 ret = 0;
+		ret = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG1);
+
+		if ((ret & 0xC00) == 0x800) {
+			printk(KERN_INFO "Found NAND on CS%d\n", cs);
+			if (nandcs > GPMC_CS_NUM)
+				nandcs = cs;
+		}
+		cs++;
+	}
+
+	if (nandcs > GPMC_CS_NUM) {
+		printk(KERN_INFO "NAND: Unable to find configuration "
+				"in GPMC\n ");
+		return;
+	}
+
+	if (nandcs < GPMC_CS_NUM) {
+		omap3_pca102_nand_data.cs = nandcs;
+		omap3_pca102_nand_data.gpmc_cs_baseaddr = (void *)
+			(gpmc_base_add + GPMC_CS0_BASE
+			+ nandcs * GPMC_CS_SIZE);
+		omap3_pca102_nand_data.gpmc_baseaddr = (void *) (gpmc_base_add);
+
+		printk(KERN_INFO "Registering NAND on CS%d\n", nandcs);
+		if (platform_device_register(&omap3_pca102_nand_device) < 0)
+			printk(KERN_ERR "Unable to register NAND device\n");
+	}
+}
+
+static struct ehci_hcd_omap_platform_data ehci_pdata __initconst = {
+	.port_mode[0] = EHCI_HCD_OMAP_MODE_PHY,
+	.port_mode[1] = EHCI_HCD_OMAP_MODE_UNKNOWN,
+	.port_mode[2] = EHCI_HCD_OMAP_MODE_UNKNOWN,
+
+	/* PHY reset GPIO will be runtime programmed based on EVM version */
+#ifdef PCA102_PCB_1334_1
+	.phy_reset  = false,
+	.reset_gpio_port[0]  = -EINVAL,
+#else
+	.phy_reset  = true,
+	.reset_gpio_port[0]  = OMAP3_PCA102_EHCI_nRST,
+#endif
+	.reset_gpio_port[1]  = -EINVAL,
+	.reset_gpio_port[2]  = -EINVAL
+};
+
+#ifdef CONFIG_OMAP_MUX
+static struct omap_board_mux board_mux[] __initdata = {
+	/* mUSB */
+	OMAP3_MUX(HSUSB0_CLK, OMAP_MUX_MODE0 | OMAP_PIN_INPUT),
+	OMAP3_MUX(HSUSB0_STP, OMAP_MUX_MODE0 | OMAP_PIN_OUTPUT),
+	OMAP3_MUX(HSUSB0_DIR, OMAP_MUX_MODE0 | OMAP_PIN_INPUT),
+	OMAP3_MUX(HSUSB0_NXT, OMAP_MUX_MODE0 | OMAP_PIN_INPUT),
+	OMAP3_MUX(HSUSB0_DATA0, OMAP_MUX_MODE0 | OMAP_PIN_INPUT),
+	OMAP3_MUX(HSUSB0_DATA1, OMAP_MUX_MODE0 | OMAP_PIN_INPUT),
+	OMAP3_MUX(HSUSB0_DATA2, OMAP_MUX_MODE0 | OMAP_PIN_INPUT),
+	OMAP3_MUX(HSUSB0_DATA3, OMAP_MUX_MODE0 | OMAP_PIN_INPUT),
+	OMAP3_MUX(HSUSB0_DATA4, OMAP_MUX_MODE0 | OMAP_PIN_INPUT),
+	OMAP3_MUX(HSUSB0_DATA5, OMAP_MUX_MODE0 | OMAP_PIN_INPUT),
+	OMAP3_MUX(HSUSB0_DATA6, OMAP_MUX_MODE0 | OMAP_PIN_INPUT),
+	OMAP3_MUX(HSUSB0_DATA7, OMAP_MUX_MODE0 | OMAP_PIN_INPUT),
+
+{ .reg_offset = OMAP_MUX_TERMINATOR },
+};
+#else
+#define board_mux	NULL
+#endif
+
+static void __init omap3_pca102_init(void)
+{
+	omap3_mux_init(board_mux, OMAP_PACKAGE_CBB);
+
+	omap3_pca102_i2c_init();
+
+	platform_add_devices(omap3_pca102_devices,
+				ARRAY_SIZE(omap3_pca102_devices));
+
+	omap_serial_init_port(2); /* we only have used UART3 */
+#ifdef CONFIG_NOP_USB_XCEIV
+	/* OMAP3EVM uses ISP1504 phy and so register nop transceiver */
+	usb_nop_xceiv_register();
+#endif
+
+#ifdef PCA102_PCB_1334_1
+	omap_mux_init_gpio(OMAP3_PCA102_EHCI_SELECT, OMAP_PIN_OUTPUT);
+	if ((gpio_request(OMAP3_PCA102_EHCI_SELECT, "nUSBH_CS") == 0) &&
+	    (gpio_direction_output(OMAP3_PCA102_EHCI_SELECT, 1) == 0)) {
+		printk(KERN_INFO "succeded to nUSBH_CS\n");
+		gpio_set_value(OMAP3_PCA102_EHCI_SELECT, 0);
+	} else {
+		printk(KERN_ERR "could not obtain gpio for nUSBH_CS\n");
+	}
+#else
+	omap_mux_init_gpio(OMAP3_PCA102_EHCI_nRST, OMAP_PIN_OUTPUT);
+#endif
+	omap_mux_init_gpio(OMAP3_PCA102_OTG_SELECT, OMAP_PIN_OUTPUT);
+	if ((gpio_request(OMAP3_PCA102_OTG_SELECT, "nUSBOTG_CS") == 0) &&
+	    (gpio_direction_output(OMAP3_PCA102_OTG_SELECT, 1) == 0)) {
+		printk(KERN_INFO "succeded to nUSBOTG_CS\n");
+		gpio_set_value(OMAP3_PCA102_OTG_SELECT, 0);
+	} else {
+		printk(KERN_ERR "could not obtain gpio for nUSBOTG_CS\n");
+	}
+
+	usb_musb_init();
+	usb_ehci_init(&ehci_pdata);
+	omap3_pca102_flash_init();
+	omap3_pca102_init_smsc911x();
+
+	omap_mux_init_gpio(omap3beagle_ac97_data.reset_gpio, OMAP_PIN_OUTPUT);
+
+	omap_mux_init_signal("mcbsp2_dx.mcbsp2_dx",	OMAP_PIN_OUTPUT);
+	omap_mux_init_signal("mcbsp2_clkx.mcbsp2_clkx",	OMAP_PIN_INPUT);
+	omap_mux_init_signal("mcbsp2_fsx.mcbsp2_fsx",	OMAP_PIN_OUTPUT);
+	omap_mux_init_signal("mcbsp2_dr.mcbsp2_dr",	OMAP_PIN_INPUT);
+	platform_device_register(&omap3beagle_ac97_device);
+
+	omap_mux_init_gpio(26, OMAP_PIN_OUTPUT);
+	if ((gpio_request(26, "DISP_PWRDOWN") == 0) &&
+	    (gpio_direction_output(26, 1) == 0)) {
+		printk(KERN_INFO "succeded to map GPIO26\n");
+		gpio_export(26, 0);
+		gpio_set_value(26, 0);
+		gpio_set_value(26, 1);
+	} else {
+		printk(KERN_ERR "could not obtain gpio for \n");
+	}
+}
+
+static void __init omap3_pca102_map_io(void)
+{
+	omap2_set_globals_343x();
+	omap2_map_common_io();
+}
+
+MACHINE_START(PCA102, "phyCRAD-L OMAP35xx")
+	/* Maintainer: Jürgen Kilb - Phytec Messtechnik GmbH */
+	.phys_io	= 0x48000000,
+	.io_pg_offst	= ((0xfa000000) >> 18) & 0xfffc,
+	.boot_params	= 0x80000100,
+	.map_io		= omap3_pca102_map_io,
+	.init_irq	= omap3_pca102_init_irq,
+	.init_machine	= omap3_pca102_init,
+	.timer		= &omap_timer,
+MACHINE_END
Index: linux-2.6.33.7/arch/arm/mach-omap2/Kconfig
===================================================================
--- linux-2.6.33.7.orig/arch/arm/mach-omap2/Kconfig	2010-08-02 19:27:18.000000000 +0200
+++ linux-2.6.33.7/arch/arm/mach-omap2/Kconfig	2010-11-05 10:10:09.740936882 +0100
@@ -102,6 +102,12 @@
 	depends on ARCH_OMAP3 && ARCH_OMAP34XX
 	select OMAP_PACKAGE_CBB
 
+config MACH_PCA102
+	bool "OMAP 3530 phyCARD-L Phytec-Messtechnik GmbH"
+	depends on ARCH_OMAP3 && ARCH_OMAP34XX
+        select OMAP_PACKAGE_CBB
+	select OMAP_MUX
+
 config MACH_NOKIA_N800
        bool
 
Index: linux-2.6.33.7/arch/arm/mach-omap2/Makefile
===================================================================
--- linux-2.6.33.7.orig/arch/arm/mach-omap2/Makefile	2010-08-02 19:27:18.000000000 +0200
+++ linux-2.6.33.7/arch/arm/mach-omap2/Makefile	2010-11-09 18:38:46.001173990 +0100
@@ -111,6 +111,8 @@
 
 obj-$(CONFIG_MACH_OMAP3517EVM)     += board-am3517evm.o
 
+obj-$(CONFIG_MACH_PCA102)		+= board-pca102.o
+
 # Platform specific device init code
 obj-y					+= usb-musb.o
 obj-$(CONFIG_MACH_OMAP2_TUSB6010)	+= usb-tusb6010.o
Index: linux-2.6.33.7/arch/arm/tools/mach-types
===================================================================
--- linux-2.6.33.7.orig/arch/arm/tools/mach-types	2010-08-02 19:27:18.000000000 +0200
+++ linux-2.6.33.7/arch/arm/tools/mach-types	2010-11-05 10:10:09.750931142 +0100
@@ -2678,3 +2678,5 @@
 mioa702			MACH_MIOA702		MIOA702			2691
 hpmin			MACH_HPMIN		HPMIN			2692
 ak880xak		MACH_AK880XAK		AK880XAK		2693
+pca102			MACH_PCA102		PCA102			2843
+
Index: linux-2.6.33.7/sound/soc/omap/omap-ac97-beagle.c
===================================================================
--- linux-2.6.33.7.orig/sound/soc/omap/omap-ac97-beagle.c	2010-11-05 10:10:09.560936074 +0100
+++ linux-2.6.33.7/sound/soc/omap/omap-ac97-beagle.c	2010-11-05 10:10:09.750931142 +0100
@@ -67,7 +67,7 @@
 {
 	int			rc;
 
-	snd_soc_beagle_dai.cpu_dai = omap_ac97_get_dai(0);
+	snd_soc_beagle_dai.cpu_dai = omap_ac97_get_dai(1);
 	if (!snd_soc_beagle_dai.cpu_dai)
 		return -ENOENT;
 
