| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580 | 
							- /*
 
-  * TI DaVinci DM646X EVM board
 
-  *
 
-  * Derived from: arch/arm/mach-davinci/board-evm.c
 
-  * Copyright (C) 2006 Texas Instruments.
 
-  *
 
-  * (C) 2007-2008, MontaVista Software, Inc.
 
-  *
 
-  * This file is licensed under the terms of the GNU General Public License
 
-  * version 2. This program is licensed "as is" without any warranty of any
 
-  * kind, whether express or implied.
 
-  *
 
-  */
 
- /**************************************************************************
 
-  * Included Files
 
-  **************************************************************************/
 
- #include <linux/kernel.h>
 
- #include <linux/init.h>
 
- #include <linux/leds.h>
 
- #include <linux/gpio.h>
 
- #include <linux/platform_device.h>
 
- #include <linux/i2c.h>
 
- #include <linux/i2c/at24.h>
 
- #include <linux/i2c/pcf857x.h>
 
- #include <media/tvp514x.h>
 
- #include <media/adv7343.h>
 
- #include <linux/mtd/mtd.h>
 
- #include <linux/mtd/nand.h>
 
- #include <linux/mtd/partitions.h>
 
- #include <linux/clk.h>
 
- #include <linux/export.h>
 
- #include <asm/mach-types.h>
 
- #include <asm/mach/arch.h>
 
- #include <mach/common.h>
 
- #include <mach/serial.h>
 
- #include <linux/platform_data/i2c-davinci.h>
 
- #include <linux/platform_data/mtd-davinci.h>
 
- #include <mach/clock.h>
 
- #include <mach/cdce949.h>
 
- #include <linux/platform_data/mtd-davinci-aemif.h>
 
- #include "davinci.h"
 
- #include "clock.h"
 
- #define NAND_BLOCK_SIZE		SZ_128K
 
- /* Note: We are setting first partition as 'bootloader' constituting UBL, U-Boot
 
-  * and U-Boot environment this avoids dependency on any particular combination
 
-  * of UBL, U-Boot or flashing tools etc.
 
-  */
 
- static struct mtd_partition davinci_nand_partitions[] = {
 
- 	{
 
- 		/* UBL, U-Boot with environment */
 
- 		.name		= "bootloader",
 
- 		.offset		= MTDPART_OFS_APPEND,
 
- 		.size		= 16 * NAND_BLOCK_SIZE,
 
- 		.mask_flags	= MTD_WRITEABLE,	/* force read-only */
 
- 	}, {
 
- 		.name		= "kernel",
 
- 		.offset		= MTDPART_OFS_APPEND,
 
- 		.size		= SZ_4M,
 
- 		.mask_flags	= 0,
 
- 	}, {
 
- 		.name		= "filesystem",
 
- 		.offset		= MTDPART_OFS_APPEND,
 
- 		.size		= MTDPART_SIZ_FULL,
 
- 		.mask_flags	= 0,
 
- 	}
 
- };
 
- static struct davinci_aemif_timing dm6467tevm_nandflash_timing = {
 
- 	.wsetup		= 29,
 
- 	.wstrobe	= 24,
 
- 	.whold		= 14,
 
- 	.rsetup		= 19,
 
- 	.rstrobe	= 33,
 
- 	.rhold		= 0,
 
- 	.ta		= 29,
 
- };
 
- static struct davinci_nand_pdata davinci_nand_data = {
 
- 	.mask_cle 		= 0x80000,
 
- 	.mask_ale 		= 0x40000,
 
- 	.parts			= davinci_nand_partitions,
 
- 	.nr_parts		= ARRAY_SIZE(davinci_nand_partitions),
 
- 	.ecc_mode		= NAND_ECC_HW,
 
- 	.options		= 0,
 
- };
 
- static struct resource davinci_nand_resources[] = {
 
- 	{
 
- 		.start		= DM646X_ASYNC_EMIF_CS2_SPACE_BASE,
 
- 		.end		= DM646X_ASYNC_EMIF_CS2_SPACE_BASE + SZ_32M - 1,
 
- 		.flags		= IORESOURCE_MEM,
 
- 	}, {
 
- 		.start		= DM646X_ASYNC_EMIF_CONTROL_BASE,
 
- 		.end		= DM646X_ASYNC_EMIF_CONTROL_BASE + SZ_4K - 1,
 
- 		.flags		= IORESOURCE_MEM,
 
- 	},
 
- };
 
- static struct platform_device davinci_nand_device = {
 
- 	.name			= "davinci_nand",
 
- 	.id			= 0,
 
- 	.num_resources		= ARRAY_SIZE(davinci_nand_resources),
 
- 	.resource		= davinci_nand_resources,
 
- 	.dev			= {
 
- 		.platform_data	= &davinci_nand_data,
 
- 	},
 
- };
 
- #if defined(CONFIG_BLK_DEV_PALMCHIP_BK3710) || \
 
-     defined(CONFIG_BLK_DEV_PALMCHIP_BK3710_MODULE)
 
- #define HAS_ATA 1
 
- #else
 
- #define HAS_ATA 0
 
- #endif
 
- /* CPLD Register 0 bits to control ATA */
 
- #define DM646X_EVM_ATA_RST		BIT(0)
 
- #define DM646X_EVM_ATA_PWD		BIT(1)
 
- /* CPLD Register 0 Client: used for I/O Control */
 
- static int cpld_reg0_probe(struct i2c_client *client,
 
- 			   const struct i2c_device_id *id)
 
- {
 
- 	if (HAS_ATA) {
 
- 		u8 data;
 
- 		struct i2c_msg msg[2] = {
 
- 			{
 
- 				.addr = client->addr,
 
- 				.flags = I2C_M_RD,
 
- 				.len = 1,
 
- 				.buf = &data,
 
- 			},
 
- 			{
 
- 				.addr = client->addr,
 
- 				.flags = 0,
 
- 				.len = 1,
 
- 				.buf = &data,
 
- 			},
 
- 		};
 
- 		/* Clear ATA_RSTn and ATA_PWD bits to enable ATA operation. */
 
- 		i2c_transfer(client->adapter, msg, 1);
 
- 		data &= ~(DM646X_EVM_ATA_RST | DM646X_EVM_ATA_PWD);
 
- 		i2c_transfer(client->adapter, msg + 1, 1);
 
- 	}
 
- 	return 0;
 
- }
 
- static const struct i2c_device_id cpld_reg_ids[] = {
 
- 	{ "cpld_reg0", 0, },
 
- 	{ },
 
- };
 
- static struct i2c_driver dm6467evm_cpld_driver = {
 
- 	.driver.name	= "cpld_reg0",
 
- 	.id_table	= cpld_reg_ids,
 
- 	.probe		= cpld_reg0_probe,
 
- };
 
- /* LEDS */
 
- static struct gpio_led evm_leds[] = {
 
- 	{ .name = "DS1", .active_low = 1, },
 
- 	{ .name = "DS2", .active_low = 1, },
 
- 	{ .name = "DS3", .active_low = 1, },
 
- 	{ .name = "DS4", .active_low = 1, },
 
- };
 
- static const struct gpio_led_platform_data evm_led_data = {
 
- 	.num_leds = ARRAY_SIZE(evm_leds),
 
- 	.leds     = evm_leds,
 
- };
 
- static struct platform_device *evm_led_dev;
 
- static int evm_led_setup(struct i2c_client *client, int gpio,
 
- 			unsigned int ngpio, void *c)
 
- {
 
- 	struct gpio_led *leds = evm_leds;
 
- 	int status;
 
- 	while (ngpio--) {
 
- 		leds->gpio = gpio++;
 
- 		leds++;
 
- 	}
 
- 	evm_led_dev = platform_device_alloc("leds-gpio", 0);
 
- 	platform_device_add_data(evm_led_dev, &evm_led_data,
 
- 				sizeof(evm_led_data));
 
- 	evm_led_dev->dev.parent = &client->dev;
 
- 	status = platform_device_add(evm_led_dev);
 
- 	if (status < 0) {
 
- 		platform_device_put(evm_led_dev);
 
- 		evm_led_dev = NULL;
 
- 	}
 
- 	return status;
 
- }
 
- static int evm_led_teardown(struct i2c_client *client, int gpio,
 
- 				unsigned ngpio, void *c)
 
- {
 
- 	if (evm_led_dev) {
 
- 		platform_device_unregister(evm_led_dev);
 
- 		evm_led_dev = NULL;
 
- 	}
 
- 	return 0;
 
- }
 
- static int evm_sw_gpio[4] = { -EINVAL, -EINVAL, -EINVAL, -EINVAL };
 
- static int evm_sw_setup(struct i2c_client *client, int gpio,
 
- 			unsigned ngpio, void *c)
 
- {
 
- 	int status;
 
- 	int i;
 
- 	char label[10];
 
- 	for (i = 0; i < 4; ++i) {
 
- 		snprintf(label, 10, "user_sw%d", i);
 
- 		status = gpio_request(gpio, label);
 
- 		if (status)
 
- 			goto out_free;
 
- 		evm_sw_gpio[i] = gpio++;
 
- 		status = gpio_direction_input(evm_sw_gpio[i]);
 
- 		if (status) {
 
- 			gpio_free(evm_sw_gpio[i]);
 
- 			evm_sw_gpio[i] = -EINVAL;
 
- 			goto out_free;
 
- 		}
 
- 		status = gpio_export(evm_sw_gpio[i], 0);
 
- 		if (status) {
 
- 			gpio_free(evm_sw_gpio[i]);
 
- 			evm_sw_gpio[i] = -EINVAL;
 
- 			goto out_free;
 
- 		}
 
- 	}
 
- 	return status;
 
- out_free:
 
- 	for (i = 0; i < 4; ++i) {
 
- 		if (evm_sw_gpio[i] != -EINVAL) {
 
- 			gpio_free(evm_sw_gpio[i]);
 
- 			evm_sw_gpio[i] = -EINVAL;
 
- 		}
 
- 	}
 
- 	return status;
 
- }
 
- static int evm_sw_teardown(struct i2c_client *client, int gpio,
 
- 			unsigned ngpio, void *c)
 
- {
 
- 	int i;
 
- 	for (i = 0; i < 4; ++i) {
 
- 		if (evm_sw_gpio[i] != -EINVAL) {
 
- 			gpio_unexport(evm_sw_gpio[i]);
 
- 			gpio_free(evm_sw_gpio[i]);
 
- 			evm_sw_gpio[i] = -EINVAL;
 
- 		}
 
- 	}
 
- 	return 0;
 
- }
 
- static int evm_pcf_setup(struct i2c_client *client, int gpio,
 
- 			unsigned int ngpio, void *c)
 
- {
 
- 	int status;
 
- 	if (ngpio < 8)
 
- 		return -EINVAL;
 
- 	status = evm_sw_setup(client, gpio, 4, c);
 
- 	if (status)
 
- 		return status;
 
- 	return evm_led_setup(client, gpio+4, 4, c);
 
- }
 
- static int evm_pcf_teardown(struct i2c_client *client, int gpio,
 
- 			unsigned int ngpio, void *c)
 
- {
 
- 	BUG_ON(ngpio < 8);
 
- 	evm_sw_teardown(client, gpio, 4, c);
 
- 	evm_led_teardown(client, gpio+4, 4, c);
 
- 	return 0;
 
- }
 
- static struct pcf857x_platform_data pcf_data = {
 
- 	.gpio_base	= DAVINCI_N_GPIO+1,
 
- 	.setup		= evm_pcf_setup,
 
- 	.teardown	= evm_pcf_teardown,
 
- };
 
- /* Most of this EEPROM is unused, but U-Boot uses some data:
 
-  *  - 0x7f00, 6 bytes Ethernet Address
 
-  *  - ... newer boards may have more
 
-  */
 
- static struct at24_platform_data eeprom_info = {
 
- 	.byte_len       = (256*1024) / 8,
 
- 	.page_size      = 64,
 
- 	.flags          = AT24_FLAG_ADDR16,
 
- 	.setup          = davinci_get_mac_addr,
 
- 	.context	= (void *)0x7f00,
 
- };
 
- static u8 dm646x_iis_serializer_direction[] = {
 
-        TX_MODE, RX_MODE, INACTIVE_MODE, INACTIVE_MODE,
 
- };
 
- static u8 dm646x_dit_serializer_direction[] = {
 
-        TX_MODE,
 
- };
 
- static struct snd_platform_data dm646x_evm_snd_data[] = {
 
- 	{
 
- 		.tx_dma_offset  = 0x400,
 
- 		.rx_dma_offset  = 0x400,
 
- 		.op_mode        = DAVINCI_MCASP_IIS_MODE,
 
- 		.num_serializer = ARRAY_SIZE(dm646x_iis_serializer_direction),
 
- 		.tdm_slots      = 2,
 
- 		.serial_dir     = dm646x_iis_serializer_direction,
 
- 		.asp_chan_q     = EVENTQ_0,
 
- 	},
 
- 	{
 
- 		.tx_dma_offset  = 0x400,
 
- 		.rx_dma_offset  = 0,
 
- 		.op_mode        = DAVINCI_MCASP_DIT_MODE,
 
- 		.num_serializer = ARRAY_SIZE(dm646x_dit_serializer_direction),
 
- 		.tdm_slots      = 32,
 
- 		.serial_dir     = dm646x_dit_serializer_direction,
 
- 		.asp_chan_q     = EVENTQ_0,
 
- 	},
 
- };
 
- static struct i2c_client *cpld_client;
 
- static int cpld_video_probe(struct i2c_client *client,
 
- 			const struct i2c_device_id *id)
 
- {
 
- 	cpld_client = client;
 
- 	return 0;
 
- }
 
- static int cpld_video_remove(struct i2c_client *client)
 
- {
 
- 	cpld_client = NULL;
 
- 	return 0;
 
- }
 
- static const struct i2c_device_id cpld_video_id[] = {
 
- 	{ "cpld_video", 0 },
 
- 	{ }
 
- };
 
- static struct i2c_driver cpld_video_driver = {
 
- 	.driver = {
 
- 		.name	= "cpld_video",
 
- 	},
 
- 	.probe		= cpld_video_probe,
 
- 	.remove		= cpld_video_remove,
 
- 	.id_table	= cpld_video_id,
 
- };
 
- static void evm_init_cpld(void)
 
- {
 
- 	i2c_add_driver(&cpld_video_driver);
 
- }
 
- static struct i2c_board_info __initdata i2c_info[] =  {
 
- 	{
 
- 		I2C_BOARD_INFO("24c256", 0x50),
 
- 		.platform_data  = &eeprom_info,
 
- 	},
 
- 	{
 
- 		I2C_BOARD_INFO("pcf8574a", 0x38),
 
- 		.platform_data	= &pcf_data,
 
- 	},
 
- 	{
 
- 		I2C_BOARD_INFO("cpld_reg0", 0x3a),
 
- 	},
 
- 	{
 
- 		I2C_BOARD_INFO("tlv320aic33", 0x18),
 
- 	},
 
- 	{
 
- 		I2C_BOARD_INFO("cpld_video", 0x3b),
 
- 	},
 
- 	{
 
- 		I2C_BOARD_INFO("cdce949", 0x6c),
 
- 	},
 
- };
 
- static struct davinci_i2c_platform_data i2c_pdata = {
 
- 	.bus_freq       = 100 /* kHz */,
 
- 	.bus_delay      = 0 /* usec */,
 
- };
 
- #define VCH2CLK_MASK		(BIT_MASK(10) | BIT_MASK(9) | BIT_MASK(8))
 
- #define VCH2CLK_SYSCLK8		(BIT(9))
 
- #define VCH2CLK_AUXCLK		(BIT(9) | BIT(8))
 
- #define VCH3CLK_MASK		(BIT_MASK(14) | BIT_MASK(13) | BIT_MASK(12))
 
- #define VCH3CLK_SYSCLK8		(BIT(13))
 
- #define VCH3CLK_AUXCLK		(BIT(14) | BIT(13))
 
- #define VIDCH2CLK		(BIT(10))
 
- #define VIDCH3CLK		(BIT(11))
 
- #define VIDCH1CLK		(BIT(4))
 
- #define TVP7002_INPUT		(BIT(4))
 
- #define TVP5147_INPUT		(~BIT(4))
 
- #define VPIF_INPUT_ONE_CHANNEL	(BIT(5))
 
- #define VPIF_INPUT_TWO_CHANNEL	(~BIT(5))
 
- #define TVP5147_CH0		"tvp514x-0"
 
- #define TVP5147_CH1		"tvp514x-1"
 
- /* spin lock for updating above registers */
 
- static spinlock_t vpif_reg_lock;
 
- static int set_vpif_clock(int mux_mode, int hd)
 
- {
 
- 	unsigned long flags;
 
- 	unsigned int value;
 
- 	int val = 0;
 
- 	int err = 0;
 
- 	if (!cpld_client)
 
- 		return -ENXIO;
 
- 	/* disable the clock */
 
- 	spin_lock_irqsave(&vpif_reg_lock, flags);
 
- 	value = __raw_readl(DAVINCI_SYSMOD_VIRT(SYSMOD_VSCLKDIS));
 
- 	value |= (VIDCH3CLK | VIDCH2CLK);
 
- 	__raw_writel(value, DAVINCI_SYSMOD_VIRT(SYSMOD_VSCLKDIS));
 
- 	spin_unlock_irqrestore(&vpif_reg_lock, flags);
 
- 	val = i2c_smbus_read_byte(cpld_client);
 
- 	if (val < 0)
 
- 		return val;
 
- 	if (mux_mode == 1)
 
- 		val &= ~0x40;
 
- 	else
 
- 		val |= 0x40;
 
- 	err = i2c_smbus_write_byte(cpld_client, val);
 
- 	if (err)
 
- 		return err;
 
- 	value = __raw_readl(DAVINCI_SYSMOD_VIRT(SYSMOD_VIDCLKCTL));
 
- 	value &= ~(VCH2CLK_MASK);
 
- 	value &= ~(VCH3CLK_MASK);
 
- 	if (hd >= 1)
 
- 		value |= (VCH2CLK_SYSCLK8 | VCH3CLK_SYSCLK8);
 
- 	else
 
- 		value |= (VCH2CLK_AUXCLK | VCH3CLK_AUXCLK);
 
- 	__raw_writel(value, DAVINCI_SYSMOD_VIRT(SYSMOD_VIDCLKCTL));
 
- 	spin_lock_irqsave(&vpif_reg_lock, flags);
 
- 	value = __raw_readl(DAVINCI_SYSMOD_VIRT(SYSMOD_VSCLKDIS));
 
- 	/* enable the clock */
 
- 	value &= ~(VIDCH3CLK | VIDCH2CLK);
 
- 	__raw_writel(value, DAVINCI_SYSMOD_VIRT(SYSMOD_VSCLKDIS));
 
- 	spin_unlock_irqrestore(&vpif_reg_lock, flags);
 
- 	return 0;
 
- }
 
- static struct vpif_subdev_info dm646x_vpif_subdev[] = {
 
- 	{
 
- 		.name	= "adv7343",
 
- 		.board_info = {
 
- 			I2C_BOARD_INFO("adv7343", 0x2a),
 
- 		},
 
- 	},
 
- 	{
 
- 		.name	= "ths7303",
 
- 		.board_info = {
 
- 			I2C_BOARD_INFO("ths7303", 0x2c),
 
- 		},
 
- 	},
 
- };
 
- static const struct vpif_output dm6467_ch0_outputs[] = {
 
- 	{
 
- 		.output = {
 
- 			.index = 0,
 
- 			.name = "Composite",
 
- 			.type = V4L2_OUTPUT_TYPE_ANALOG,
 
- 			.capabilities = V4L2_OUT_CAP_STD,
 
- 			.std = V4L2_STD_ALL,
 
- 		},
 
- 		.subdev_name = "adv7343",
 
- 		.output_route = ADV7343_COMPOSITE_ID,
 
- 	},
 
- 	{
 
- 		.output = {
 
- 			.index = 1,
 
- 			.name = "Component",
 
- 			.type = V4L2_OUTPUT_TYPE_ANALOG,
 
- 			.capabilities = V4L2_OUT_CAP_CUSTOM_TIMINGS,
 
- 		},
 
- 		.subdev_name = "adv7343",
 
- 		.output_route = ADV7343_COMPONENT_ID,
 
- 	},
 
- 	{
 
- 		.output = {
 
- 			.index = 2,
 
- 			.name = "S-Video",
 
- 			.type = V4L2_OUTPUT_TYPE_ANALOG,
 
- 			.capabilities = V4L2_OUT_CAP_STD,
 
- 			.std = V4L2_STD_ALL,
 
- 		},
 
- 		.subdev_name = "adv7343",
 
- 		.output_route = ADV7343_SVIDEO_ID,
 
- 	},
 
- };
 
- static struct vpif_display_config dm646x_vpif_display_config = {
 
- 	.set_clock	= set_vpif_clock,
 
- 	.subdevinfo	= dm646x_vpif_subdev,
 
- 	.subdev_count	= ARRAY_SIZE(dm646x_vpif_subdev),
 
- 	.chan_config[0] = {
 
- 		.outputs = dm6467_ch0_outputs,
 
- 		.output_count = ARRAY_SIZE(dm6467_ch0_outputs),
 
- 	},
 
- 	.card_name	= "DM646x EVM",
 
- };
 
- /**
 
-  * setup_vpif_input_path()
 
-  * @channel: channel id (0 - CH0, 1 - CH1)
 
-  * @sub_dev_name: ptr sub device name
 
-  *
 
-  * This will set vpif input to capture data from tvp514x or
 
-  * tvp7002.
 
-  */
 
- static int setup_vpif_input_path(int channel, const char *sub_dev_name)
 
- {
 
- 	int err = 0;
 
- 	int val;
 
- 	/* for channel 1, we don't do anything */
 
- 	if (channel != 0)
 
- 		return 0;
 
- 	if (!cpld_client)
 
- 		return -ENXIO;
 
- 	val = i2c_smbus_read_byte(cpld_client);
 
- 	if (val < 0)
 
- 		return val;
 
- 	if (!strcmp(sub_dev_name, TVP5147_CH0) ||
 
- 	    !strcmp(sub_dev_name, TVP5147_CH1))
 
- 		val &= TVP5147_INPUT;
 
- 	else
 
- 		val |= TVP7002_INPUT;
 
- 	err = i2c_smbus_write_byte(cpld_client, val);
 
- 	if (err)
 
- 		return err;
 
- 	return 0;
 
- }
 
 
  |