/* Add the following to arch/arm/mach-at91/at91sam9260_devices.c */

/* --------------------------------------------------------------------
 *  Timer/Counter blocks
 * -------------------------------------------------------------------- */
#if defined(CONFIG_AT91SAM9260_PWM) || defined(CONFIG_AT91SAM9260_PWM_MODULE)
static struct resource pwm_resources[6][2] = {
	[0] = {
		[0] = {
			.start	= AT91SAM9260_BASE_TC(0),
			.end	= AT91SAM9260_BASE_TC(0) + 0x40 - 1,
			.flags	= IORESOURCE_MEM,
		},
		[1] = {
			.start	= AT91SAM9260_ID_TC0,
			.end	= AT91SAM9260_ID_TC0,
			.flags	= IORESOURCE_IRQ,
		},
	},
	[1] = {		
		[0] = {
			.start	= AT91SAM9260_BASE_TC(1),
			.end	= AT91SAM9260_BASE_TC(1) + 0x40 - 1,
			.flags	= IORESOURCE_MEM,
		},
		[1] = {
			.start	= AT91SAM9260_ID_TC1,
			.end	= AT91SAM9260_ID_TC1,
			.flags	= IORESOURCE_IRQ,
		},
	},
	[2] = {
		[0] = {
			.start	= AT91SAM9260_BASE_TC(2),
			.end	= AT91SAM9260_BASE_TC(2) + 0x40 - 1,
			.flags	= IORESOURCE_MEM,
		},
		[1] = {
			.start	= AT91SAM9260_ID_TC2,
			.end	= AT91SAM9260_ID_TC2,
			.flags	= IORESOURCE_IRQ,
		},
	},
	[3] = {
		[0] = {
			.start	= AT91SAM9260_BASE_TC(3),
			.end	= AT91SAM9260_BASE_TC(3) + 0x40 - 1,
			.flags	= IORESOURCE_MEM,
		},
		[1] = {
			.start	= AT91SAM9260_ID_TC3,
			.end	= AT91SAM9260_ID_TC3,
			.flags	= IORESOURCE_IRQ,
		},
	},
	[4] = {
		[0] = {
			.start	= AT91SAM9260_BASE_TC(4),
			.end	= AT91SAM9260_BASE_TC(4) + 0x40 - 1,
			.flags	= IORESOURCE_MEM,
		},
		[1] = {
			.start	= AT91SAM9260_ID_TC4,
			.end	= AT91SAM9260_ID_TC4,
			.flags	= IORESOURCE_IRQ,
		},
	},
	[5] = {
		[0] = {
			.start	= AT91SAM9260_BASE_TC(5),
			.end	= AT91SAM9260_BASE_TC(5) + 0x40 - 1,
			.flags	= IORESOURCE_MEM,
		},
		[1] = {
			.start	= AT91SAM9260_ID_TC5,
			.end	= AT91SAM9260_ID_TC5,
			.flags	= IORESOURCE_IRQ,
		},
	},
};

static struct platform_device at91sam9260_pwm_devices[] = {
	{
		.name		= "at91_pwm",
		.id		= 0,
		.resource	= pwm_resources[0],
		.num_resources	= ARRAY_SIZE(pwm_resources[0]),
	},
	{
		.name		= "at91_pwm",
		.id		= 1,
		.resource	= pwm_resources[1],
		.num_resources	= ARRAY_SIZE(pwm_resources[1]),
	},
	{
		.name		= "at91_pwm",
		.id		= 2,
		.resource	= pwm_resources[2],
		.num_resources	= ARRAY_SIZE(pwm_resources[2]),
	},
	{
		.name		= "at91_pwm",
		.id		= 3,
		.resource	= pwm_resources[3],
		.num_resources	= ARRAY_SIZE(pwm_resources[3]),
	},
	{
		.name		= "at91_pwm",
		.id		= 4,
		.resource	= pwm_resources[4],
		.num_resources	= ARRAY_SIZE(pwm_resources[4]),
	},
	{
		.name		= "at91_pwm",
		.id		= 5,
		.resource	= pwm_resources[5],
		.num_resources	= ARRAY_SIZE(pwm_resources[5]),
	},

};

void __init at91_add_device_pwm(struct at91_pwm_data *data, int nr_pwms)
{
	int i;

	for (i = 0; i < nr_pwms; i++, data++) {
		char pwm_clk[8], parent_clk[8];
		struct at91_pwm_data *pwm = data;

		snprintf(pwm_clk, sizeof(pwm_clk), "tc%d_clk", pwm->channel);
		snprintf(parent_clk, sizeof(parent_clk), "t%d_clk",
			 pwm->channel % 3);

		at91_clock_associate(
			pwm_clk, &at91sam9260_pwm_devices[pwm->channel].dev,
			parent_clk);
		
		at91sam9260_pwm_devices[pwm->channel].dev.platform_data = pwm;
		platform_device_register(&at91sam9260_pwm_devices[pwm->channel]);
	}
}

#else 
/* FIXME */
void __init at91_add_device_pwm(struct at91_pwm_data *data, int nr_pwms)
{

}
#endif
