Linux Audio

Check our new training course

Loading...
v3.5.6
   1/*
   2 *  Copyright (C) 2007 Atmel Corporation
   3 *
   4 * This file is subject to the terms and conditions of the GNU General Public
   5 * License.  See the file COPYING in the main directory of this archive for
   6 * more details.
   7 */
   8
   9#include <asm/mach/arch.h>
  10#include <asm/mach/map.h>
  11
  12#include <linux/dma-mapping.h>
  13#include <linux/gpio.h>
  14#include <linux/platform_device.h>
  15#include <linux/i2c-gpio.h>
  16
  17#include <linux/fb.h>
  18#include <video/atmel_lcdc.h>
  19
  20#include <mach/board.h>
 
  21#include <mach/at91sam9rl.h>
  22#include <mach/at91sam9rl_matrix.h>
  23#include <mach/at91_matrix.h>
  24#include <mach/at91sam9_smc.h>
  25#include <mach/at_hdmac.h>
  26
  27#include "generic.h"
  28
  29
  30/* --------------------------------------------------------------------
  31 *  HDMAC - AHB DMA Controller
  32 * -------------------------------------------------------------------- */
  33
  34#if defined(CONFIG_AT_HDMAC) || defined(CONFIG_AT_HDMAC_MODULE)
  35static u64 hdmac_dmamask = DMA_BIT_MASK(32);
  36
 
 
 
 
  37static struct resource hdmac_resources[] = {
  38	[0] = {
  39		.start	= AT91SAM9RL_BASE_DMA,
  40		.end	= AT91SAM9RL_BASE_DMA + SZ_512 - 1,
  41		.flags	= IORESOURCE_MEM,
  42	},
  43	[2] = {
  44		.start	= AT91SAM9RL_ID_DMA,
  45		.end	= AT91SAM9RL_ID_DMA,
  46		.flags	= IORESOURCE_IRQ,
  47	},
  48};
  49
  50static struct platform_device at_hdmac_device = {
  51	.name		= "at91sam9rl_dma",
  52	.id		= -1,
  53	.dev		= {
  54				.dma_mask		= &hdmac_dmamask,
  55				.coherent_dma_mask	= DMA_BIT_MASK(32),
 
  56	},
  57	.resource	= hdmac_resources,
  58	.num_resources	= ARRAY_SIZE(hdmac_resources),
  59};
  60
  61void __init at91_add_device_hdmac(void)
  62{
 
  63	platform_device_register(&at_hdmac_device);
  64}
  65#else
  66void __init at91_add_device_hdmac(void) {}
  67#endif
  68
  69/* --------------------------------------------------------------------
  70 *  USB HS Device (Gadget)
  71 * -------------------------------------------------------------------- */
  72
  73#if defined(CONFIG_USB_ATMEL_USBA) || defined(CONFIG_USB_ATMEL_USBA_MODULE)
  74
  75static struct resource usba_udc_resources[] = {
  76	[0] = {
  77		.start	= AT91SAM9RL_UDPHS_FIFO,
  78		.end	= AT91SAM9RL_UDPHS_FIFO + SZ_512K - 1,
  79		.flags	= IORESOURCE_MEM,
  80	},
  81	[1] = {
  82		.start	= AT91SAM9RL_BASE_UDPHS,
  83		.end	= AT91SAM9RL_BASE_UDPHS + SZ_1K - 1,
  84		.flags	= IORESOURCE_MEM,
  85	},
  86	[2] = {
  87		.start	= AT91SAM9RL_ID_UDPHS,
  88		.end	= AT91SAM9RL_ID_UDPHS,
  89		.flags	= IORESOURCE_IRQ,
  90	},
  91};
  92
  93#define EP(nam, idx, maxpkt, maxbk, dma, isoc)			\
  94	[idx] = {						\
  95		.name		= nam,				\
  96		.index		= idx,				\
  97		.fifo_size	= maxpkt,			\
  98		.nr_banks	= maxbk,			\
  99		.can_dma	= dma,				\
 100		.can_isoc	= isoc,				\
 101	}
 102
 103static struct usba_ep_data usba_udc_ep[] __initdata = {
 104	EP("ep0", 0, 64, 1, 0, 0),
 105	EP("ep1", 1, 1024, 2, 1, 1),
 106	EP("ep2", 2, 1024, 2, 1, 1),
 107	EP("ep3", 3, 1024, 3, 1, 0),
 108	EP("ep4", 4, 1024, 3, 1, 0),
 109	EP("ep5", 5, 1024, 3, 1, 1),
 110	EP("ep6", 6, 1024, 3, 1, 1),
 111};
 112
 113#undef EP
 114
 115/*
 116 * pdata doesn't have room for any endpoints, so we need to
 117 * append room for the ones we need right after it.
 118 */
 119static struct {
 120	struct usba_platform_data pdata;
 121	struct usba_ep_data ep[7];
 122} usba_udc_data;
 123
 124static struct platform_device at91_usba_udc_device = {
 125	.name		= "atmel_usba_udc",
 126	.id		= -1,
 127	.dev		= {
 128				.platform_data	= &usba_udc_data.pdata,
 129	},
 130	.resource	= usba_udc_resources,
 131	.num_resources	= ARRAY_SIZE(usba_udc_resources),
 132};
 133
 134void __init at91_add_device_usba(struct usba_platform_data *data)
 135{
 136	/*
 137	 * Invalid pins are 0 on AT91, but the usba driver is shared
 138	 * with AVR32, which use negative values instead. Once/if
 139	 * gpio_is_valid() is ported to AT91, revisit this code.
 140	 */
 141	usba_udc_data.pdata.vbus_pin = -EINVAL;
 142	usba_udc_data.pdata.num_ep = ARRAY_SIZE(usba_udc_ep);
 143	memcpy(usba_udc_data.ep, usba_udc_ep, sizeof(usba_udc_ep));
 144
 145	if (data && gpio_is_valid(data->vbus_pin)) {
 146		at91_set_gpio_input(data->vbus_pin, 0);
 147		at91_set_deglitch(data->vbus_pin, 1);
 148		usba_udc_data.pdata.vbus_pin = data->vbus_pin;
 149	}
 150
 151	/* Pullup pin is handled internally by USB device peripheral */
 152
 153	platform_device_register(&at91_usba_udc_device);
 154}
 155#else
 156void __init at91_add_device_usba(struct usba_platform_data *data) {}
 157#endif
 158
 159
 160/* --------------------------------------------------------------------
 161 *  MMC / SD
 162 * -------------------------------------------------------------------- */
 163
 164#if defined(CONFIG_MMC_AT91) || defined(CONFIG_MMC_AT91_MODULE)
 165static u64 mmc_dmamask = DMA_BIT_MASK(32);
 166static struct at91_mmc_data mmc_data;
 167
 168static struct resource mmc_resources[] = {
 169	[0] = {
 170		.start	= AT91SAM9RL_BASE_MCI,
 171		.end	= AT91SAM9RL_BASE_MCI + SZ_16K - 1,
 172		.flags	= IORESOURCE_MEM,
 173	},
 174	[1] = {
 175		.start	= AT91SAM9RL_ID_MCI,
 176		.end	= AT91SAM9RL_ID_MCI,
 177		.flags	= IORESOURCE_IRQ,
 178	},
 179};
 180
 181static struct platform_device at91sam9rl_mmc_device = {
 182	.name		= "at91_mci",
 183	.id		= -1,
 184	.dev		= {
 185				.dma_mask		= &mmc_dmamask,
 186				.coherent_dma_mask	= DMA_BIT_MASK(32),
 187				.platform_data		= &mmc_data,
 188	},
 189	.resource	= mmc_resources,
 190	.num_resources	= ARRAY_SIZE(mmc_resources),
 191};
 192
 193void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data)
 194{
 195	if (!data)
 196		return;
 197
 198	/* input/irq */
 199	if (gpio_is_valid(data->det_pin)) {
 200		at91_set_gpio_input(data->det_pin, 1);
 201		at91_set_deglitch(data->det_pin, 1);
 202	}
 203	if (gpio_is_valid(data->wp_pin))
 204		at91_set_gpio_input(data->wp_pin, 1);
 205	if (gpio_is_valid(data->vcc_pin))
 206		at91_set_gpio_output(data->vcc_pin, 0);
 207
 208	/* CLK */
 209	at91_set_A_periph(AT91_PIN_PA2, 0);
 210
 211	/* CMD */
 212	at91_set_A_periph(AT91_PIN_PA1, 1);
 213
 214	/* DAT0, maybe DAT1..DAT3 */
 215	at91_set_A_periph(AT91_PIN_PA0, 1);
 216	if (data->wire4) {
 217		at91_set_A_periph(AT91_PIN_PA3, 1);
 218		at91_set_A_periph(AT91_PIN_PA4, 1);
 219		at91_set_A_periph(AT91_PIN_PA5, 1);
 220	}
 221
 222	mmc_data = *data;
 223	platform_device_register(&at91sam9rl_mmc_device);
 224}
 225#else
 226void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data) {}
 227#endif
 228
 229
 230/* --------------------------------------------------------------------
 231 *  NAND / SmartMedia
 232 * -------------------------------------------------------------------- */
 233
 234#if defined(CONFIG_MTD_NAND_ATMEL) || defined(CONFIG_MTD_NAND_ATMEL_MODULE)
 235static struct atmel_nand_data nand_data;
 236
 237#define NAND_BASE	AT91_CHIPSELECT_3
 238
 239static struct resource nand_resources[] = {
 240	[0] = {
 241		.start	= NAND_BASE,
 242		.end	= NAND_BASE + SZ_256M - 1,
 243		.flags	= IORESOURCE_MEM,
 244	},
 245	[1] = {
 246		.start	= AT91SAM9RL_BASE_ECC,
 247		.end	= AT91SAM9RL_BASE_ECC + SZ_512 - 1,
 248		.flags	= IORESOURCE_MEM,
 249	}
 250};
 251
 252static struct platform_device atmel_nand_device = {
 253	.name		= "atmel_nand",
 254	.id		= -1,
 255	.dev		= {
 256				.platform_data	= &nand_data,
 257	},
 258	.resource	= nand_resources,
 259	.num_resources	= ARRAY_SIZE(nand_resources),
 260};
 261
 262void __init at91_add_device_nand(struct atmel_nand_data *data)
 263{
 264	unsigned long csa;
 265
 266	if (!data)
 267		return;
 268
 269	csa = at91_matrix_read(AT91_MATRIX_EBICSA);
 270	at91_matrix_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_CS3A_SMC_SMARTMEDIA);
 271
 272	/* enable pin */
 273	if (gpio_is_valid(data->enable_pin))
 274		at91_set_gpio_output(data->enable_pin, 1);
 275
 276	/* ready/busy pin */
 277	if (gpio_is_valid(data->rdy_pin))
 278		at91_set_gpio_input(data->rdy_pin, 1);
 279
 280	/* card detect pin */
 281	if (gpio_is_valid(data->det_pin))
 282		at91_set_gpio_input(data->det_pin, 1);
 283
 284	at91_set_A_periph(AT91_PIN_PB4, 0);		/* NANDOE */
 285	at91_set_A_periph(AT91_PIN_PB5, 0);		/* NANDWE */
 286
 287	nand_data = *data;
 288	platform_device_register(&atmel_nand_device);
 289}
 290
 291#else
 292void __init at91_add_device_nand(struct atmel_nand_data *data) {}
 293#endif
 294
 295
 296/* --------------------------------------------------------------------
 297 *  TWI (i2c)
 298 * -------------------------------------------------------------------- */
 299
 300/*
 301 * Prefer the GPIO code since the TWI controller isn't robust
 302 * (gets overruns and underruns under load) and can only issue
 303 * repeated STARTs in one scenario (the driver doesn't yet handle them).
 304 */
 305#if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
 306
 307static struct i2c_gpio_platform_data pdata = {
 308	.sda_pin		= AT91_PIN_PA23,
 309	.sda_is_open_drain	= 1,
 310	.scl_pin		= AT91_PIN_PA24,
 311	.scl_is_open_drain	= 1,
 312	.udelay			= 2,		/* ~100 kHz */
 313};
 314
 315static struct platform_device at91sam9rl_twi_device = {
 316	.name			= "i2c-gpio",
 317	.id			= -1,
 318	.dev.platform_data	= &pdata,
 319};
 320
 321void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
 322{
 323	at91_set_GPIO_periph(AT91_PIN_PA23, 1);		/* TWD (SDA) */
 324	at91_set_multi_drive(AT91_PIN_PA23, 1);
 325
 326	at91_set_GPIO_periph(AT91_PIN_PA24, 1);		/* TWCK (SCL) */
 327	at91_set_multi_drive(AT91_PIN_PA24, 1);
 328
 329	i2c_register_board_info(0, devices, nr_devices);
 330	platform_device_register(&at91sam9rl_twi_device);
 331}
 332
 333#elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
 334
 335static struct resource twi_resources[] = {
 336	[0] = {
 337		.start	= AT91SAM9RL_BASE_TWI0,
 338		.end	= AT91SAM9RL_BASE_TWI0 + SZ_16K - 1,
 339		.flags	= IORESOURCE_MEM,
 340	},
 341	[1] = {
 342		.start	= AT91SAM9RL_ID_TWI0,
 343		.end	= AT91SAM9RL_ID_TWI0,
 344		.flags	= IORESOURCE_IRQ,
 345	},
 346};
 347
 348static struct platform_device at91sam9rl_twi_device = {
 349	.name		= "at91_i2c",
 350	.id		= -1,
 351	.resource	= twi_resources,
 352	.num_resources	= ARRAY_SIZE(twi_resources),
 353};
 354
 355void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
 356{
 357	/* pins used for TWI interface */
 358	at91_set_A_periph(AT91_PIN_PA23, 0);		/* TWD */
 359	at91_set_multi_drive(AT91_PIN_PA23, 1);
 360
 361	at91_set_A_periph(AT91_PIN_PA24, 0);		/* TWCK */
 362	at91_set_multi_drive(AT91_PIN_PA24, 1);
 363
 364	i2c_register_board_info(0, devices, nr_devices);
 365	platform_device_register(&at91sam9rl_twi_device);
 366}
 367#else
 368void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices) {}
 369#endif
 370
 371
 372/* --------------------------------------------------------------------
 373 *  SPI
 374 * -------------------------------------------------------------------- */
 375
 376#if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
 377static u64 spi_dmamask = DMA_BIT_MASK(32);
 378
 379static struct resource spi_resources[] = {
 380	[0] = {
 381		.start	= AT91SAM9RL_BASE_SPI,
 382		.end	= AT91SAM9RL_BASE_SPI + SZ_16K - 1,
 383		.flags	= IORESOURCE_MEM,
 384	},
 385	[1] = {
 386		.start	= AT91SAM9RL_ID_SPI,
 387		.end	= AT91SAM9RL_ID_SPI,
 388		.flags	= IORESOURCE_IRQ,
 389	},
 390};
 391
 392static struct platform_device at91sam9rl_spi_device = {
 393	.name		= "atmel_spi",
 394	.id		= 0,
 395	.dev		= {
 396				.dma_mask		= &spi_dmamask,
 397				.coherent_dma_mask	= DMA_BIT_MASK(32),
 398	},
 399	.resource	= spi_resources,
 400	.num_resources	= ARRAY_SIZE(spi_resources),
 401};
 402
 403static const unsigned spi_standard_cs[4] = { AT91_PIN_PA28, AT91_PIN_PB7, AT91_PIN_PD8, AT91_PIN_PD9 };
 404
 405
 406void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
 407{
 408	int i;
 409	unsigned long cs_pin;
 410
 411	at91_set_A_periph(AT91_PIN_PA25, 0);	/* MISO */
 412	at91_set_A_periph(AT91_PIN_PA26, 0);	/* MOSI */
 413	at91_set_A_periph(AT91_PIN_PA27, 0);	/* SPCK */
 414
 415	/* Enable SPI chip-selects */
 416	for (i = 0; i < nr_devices; i++) {
 417		if (devices[i].controller_data)
 418			cs_pin = (unsigned long) devices[i].controller_data;
 419		else
 420			cs_pin = spi_standard_cs[devices[i].chip_select];
 421
 422		if (!gpio_is_valid(cs_pin))
 423			continue;
 424
 425		/* enable chip-select pin */
 426		at91_set_gpio_output(cs_pin, 1);
 427
 428		/* pass chip-select pin to driver */
 429		devices[i].controller_data = (void *) cs_pin;
 430	}
 431
 432	spi_register_board_info(devices, nr_devices);
 433	platform_device_register(&at91sam9rl_spi_device);
 434}
 435#else
 436void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
 437#endif
 438
 439
 440/* --------------------------------------------------------------------
 441 *  AC97
 442 * -------------------------------------------------------------------- */
 443
 444#if defined(CONFIG_SND_ATMEL_AC97C) || defined(CONFIG_SND_ATMEL_AC97C_MODULE)
 445static u64 ac97_dmamask = DMA_BIT_MASK(32);
 446static struct ac97c_platform_data ac97_data;
 447
 448static struct resource ac97_resources[] = {
 449	[0] = {
 450		.start	= AT91SAM9RL_BASE_AC97C,
 451		.end	= AT91SAM9RL_BASE_AC97C + SZ_16K - 1,
 452		.flags	= IORESOURCE_MEM,
 453	},
 454	[1] = {
 455		.start	= AT91SAM9RL_ID_AC97C,
 456		.end	= AT91SAM9RL_ID_AC97C,
 457		.flags	= IORESOURCE_IRQ,
 458	},
 459};
 460
 461static struct platform_device at91sam9rl_ac97_device = {
 462	.name		= "atmel_ac97c",
 463	.id		= 0,
 464	.dev		= {
 465				.dma_mask		= &ac97_dmamask,
 466				.coherent_dma_mask	= DMA_BIT_MASK(32),
 467				.platform_data		= &ac97_data,
 468	},
 469	.resource	= ac97_resources,
 470	.num_resources	= ARRAY_SIZE(ac97_resources),
 471};
 472
 473void __init at91_add_device_ac97(struct ac97c_platform_data *data)
 474{
 475	if (!data)
 476		return;
 477
 478	at91_set_A_periph(AT91_PIN_PD1, 0);	/* AC97FS */
 479	at91_set_A_periph(AT91_PIN_PD2, 0);	/* AC97CK */
 480	at91_set_A_periph(AT91_PIN_PD3, 0);	/* AC97TX */
 481	at91_set_A_periph(AT91_PIN_PD4, 0);	/* AC97RX */
 482
 483	/* reset */
 484	if (gpio_is_valid(data->reset_pin))
 485		at91_set_gpio_output(data->reset_pin, 0);
 486
 487	ac97_data = *data;
 488	platform_device_register(&at91sam9rl_ac97_device);
 489}
 490#else
 491void __init at91_add_device_ac97(struct ac97c_platform_data *data) {}
 492#endif
 493
 494
 495/* --------------------------------------------------------------------
 496 *  LCD Controller
 497 * -------------------------------------------------------------------- */
 498
 499#if defined(CONFIG_FB_ATMEL) || defined(CONFIG_FB_ATMEL_MODULE)
 500static u64 lcdc_dmamask = DMA_BIT_MASK(32);
 501static struct atmel_lcdfb_info lcdc_data;
 502
 503static struct resource lcdc_resources[] = {
 504	[0] = {
 505		.start	= AT91SAM9RL_LCDC_BASE,
 506		.end	= AT91SAM9RL_LCDC_BASE + SZ_4K - 1,
 507		.flags	= IORESOURCE_MEM,
 508	},
 509	[1] = {
 510		.start	= AT91SAM9RL_ID_LCDC,
 511		.end	= AT91SAM9RL_ID_LCDC,
 512		.flags	= IORESOURCE_IRQ,
 513	},
 514};
 515
 516static struct platform_device at91_lcdc_device = {
 517	.name		= "atmel_lcdfb",
 518	.id		= 0,
 519	.dev		= {
 520				.dma_mask		= &lcdc_dmamask,
 521				.coherent_dma_mask	= DMA_BIT_MASK(32),
 522				.platform_data		= &lcdc_data,
 523	},
 524	.resource	= lcdc_resources,
 525	.num_resources	= ARRAY_SIZE(lcdc_resources),
 526};
 527
 528void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data)
 529{
 530	if (!data) {
 531		return;
 532	}
 533
 534	at91_set_B_periph(AT91_PIN_PC1, 0);	/* LCDPWR */
 535	at91_set_A_periph(AT91_PIN_PC5, 0);	/* LCDHSYNC */
 536	at91_set_A_periph(AT91_PIN_PC6, 0);	/* LCDDOTCK */
 537	at91_set_A_periph(AT91_PIN_PC7, 0);	/* LCDDEN */
 538	at91_set_A_periph(AT91_PIN_PC3, 0);	/* LCDCC */
 539	at91_set_B_periph(AT91_PIN_PC9, 0);	/* LCDD3 */
 540	at91_set_B_periph(AT91_PIN_PC10, 0);	/* LCDD4 */
 541	at91_set_B_periph(AT91_PIN_PC11, 0);	/* LCDD5 */
 542	at91_set_B_periph(AT91_PIN_PC12, 0);	/* LCDD6 */
 543	at91_set_B_periph(AT91_PIN_PC13, 0);	/* LCDD7 */
 544	at91_set_B_periph(AT91_PIN_PC15, 0);	/* LCDD11 */
 545	at91_set_B_periph(AT91_PIN_PC16, 0);	/* LCDD12 */
 546	at91_set_B_periph(AT91_PIN_PC17, 0);	/* LCDD13 */
 547	at91_set_B_periph(AT91_PIN_PC18, 0);	/* LCDD14 */
 548	at91_set_B_periph(AT91_PIN_PC19, 0);	/* LCDD15 */
 549	at91_set_B_periph(AT91_PIN_PC20, 0);	/* LCDD18 */
 550	at91_set_B_periph(AT91_PIN_PC21, 0);	/* LCDD19 */
 551	at91_set_B_periph(AT91_PIN_PC22, 0);	/* LCDD20 */
 552	at91_set_B_periph(AT91_PIN_PC23, 0);	/* LCDD21 */
 553	at91_set_B_periph(AT91_PIN_PC24, 0);	/* LCDD22 */
 554	at91_set_B_periph(AT91_PIN_PC25, 0);	/* LCDD23 */
 555
 556	lcdc_data = *data;
 557	platform_device_register(&at91_lcdc_device);
 558}
 559#else
 560void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data) {}
 561#endif
 562
 563
 564/* --------------------------------------------------------------------
 565 *  Timer/Counter block
 566 * -------------------------------------------------------------------- */
 567
 568#ifdef CONFIG_ATMEL_TCLIB
 569
 570static struct resource tcb_resources[] = {
 571	[0] = {
 572		.start	= AT91SAM9RL_BASE_TCB0,
 573		.end	= AT91SAM9RL_BASE_TCB0 + SZ_16K - 1,
 574		.flags	= IORESOURCE_MEM,
 575	},
 576	[1] = {
 577		.start	= AT91SAM9RL_ID_TC0,
 578		.end	= AT91SAM9RL_ID_TC0,
 579		.flags	= IORESOURCE_IRQ,
 580	},
 581	[2] = {
 582		.start	= AT91SAM9RL_ID_TC1,
 583		.end	= AT91SAM9RL_ID_TC1,
 584		.flags	= IORESOURCE_IRQ,
 585	},
 586	[3] = {
 587		.start	= AT91SAM9RL_ID_TC2,
 588		.end	= AT91SAM9RL_ID_TC2,
 589		.flags	= IORESOURCE_IRQ,
 590	},
 591};
 592
 593static struct platform_device at91sam9rl_tcb_device = {
 594	.name		= "atmel_tcb",
 595	.id		= 0,
 596	.resource	= tcb_resources,
 597	.num_resources	= ARRAY_SIZE(tcb_resources),
 598};
 599
 600static void __init at91_add_device_tc(void)
 601{
 602	platform_device_register(&at91sam9rl_tcb_device);
 603}
 604#else
 605static void __init at91_add_device_tc(void) { }
 606#endif
 607
 608
 609/* --------------------------------------------------------------------
 610 *  Touchscreen
 611 * -------------------------------------------------------------------- */
 612
 613#if defined(CONFIG_TOUCHSCREEN_ATMEL_TSADCC) || defined(CONFIG_TOUCHSCREEN_ATMEL_TSADCC_MODULE)
 614static u64 tsadcc_dmamask = DMA_BIT_MASK(32);
 615static struct at91_tsadcc_data tsadcc_data;
 616
 617static struct resource tsadcc_resources[] = {
 618	[0] = {
 619		.start	= AT91SAM9RL_BASE_TSC,
 620		.end	= AT91SAM9RL_BASE_TSC + SZ_16K - 1,
 621		.flags	= IORESOURCE_MEM,
 622	},
 623	[1] = {
 624		.start	= AT91SAM9RL_ID_TSC,
 625		.end	= AT91SAM9RL_ID_TSC,
 626		.flags	= IORESOURCE_IRQ,
 627	}
 628};
 629
 630static struct platform_device at91sam9rl_tsadcc_device = {
 631	.name		= "atmel_tsadcc",
 632	.id		= -1,
 633	.dev		= {
 634				.dma_mask		= &tsadcc_dmamask,
 635				.coherent_dma_mask	= DMA_BIT_MASK(32),
 636				.platform_data		= &tsadcc_data,
 637	},
 638	.resource	= tsadcc_resources,
 639	.num_resources	= ARRAY_SIZE(tsadcc_resources),
 640};
 641
 642void __init at91_add_device_tsadcc(struct at91_tsadcc_data *data)
 643{
 644	if (!data)
 645		return;
 646
 647	at91_set_A_periph(AT91_PIN_PA17, 0);	/* AD0_XR */
 648	at91_set_A_periph(AT91_PIN_PA18, 0);	/* AD1_XL */
 649	at91_set_A_periph(AT91_PIN_PA19, 0);	/* AD2_YT */
 650	at91_set_A_periph(AT91_PIN_PA20, 0);	/* AD3_TB */
 651
 652	tsadcc_data = *data;
 653	platform_device_register(&at91sam9rl_tsadcc_device);
 654}
 655#else
 656void __init at91_add_device_tsadcc(struct at91_tsadcc_data *data) {}
 657#endif
 658
 659
 660/* --------------------------------------------------------------------
 661 *  RTC
 662 * -------------------------------------------------------------------- */
 663
 664#if defined(CONFIG_RTC_DRV_AT91RM9200) || defined(CONFIG_RTC_DRV_AT91RM9200_MODULE)
 665static struct platform_device at91sam9rl_rtc_device = {
 666	.name		= "at91_rtc",
 667	.id		= -1,
 668	.num_resources	= 0,
 669};
 670
 671static void __init at91_add_device_rtc(void)
 672{
 673	platform_device_register(&at91sam9rl_rtc_device);
 674}
 675#else
 676static void __init at91_add_device_rtc(void) {}
 677#endif
 678
 679
 680/* --------------------------------------------------------------------
 681 *  RTT
 682 * -------------------------------------------------------------------- */
 683
 684static struct resource rtt_resources[] = {
 685	{
 686		.start	= AT91SAM9RL_BASE_RTT,
 687		.end	= AT91SAM9RL_BASE_RTT + SZ_16 - 1,
 688		.flags	= IORESOURCE_MEM,
 689	}, {
 690		.flags	= IORESOURCE_MEM,
 691	}
 692};
 693
 694static struct platform_device at91sam9rl_rtt_device = {
 695	.name		= "at91_rtt",
 696	.id		= 0,
 697	.resource	= rtt_resources,
 
 698};
 699
 700#if IS_ENABLED(CONFIG_RTC_DRV_AT91SAM9)
 701static void __init at91_add_device_rtt_rtc(void)
 702{
 703	at91sam9rl_rtt_device.name = "rtc-at91sam9";
 704	/*
 705	 * The second resource is needed:
 706	 * GPBR will serve as the storage for RTC time offset
 707	 */
 708	at91sam9rl_rtt_device.num_resources = 2;
 709	rtt_resources[1].start = AT91SAM9RL_BASE_GPBR +
 710				 4 * CONFIG_RTC_DRV_AT91SAM9_GPBR;
 711	rtt_resources[1].end = rtt_resources[1].start + 3;
 712}
 713#else
 714static void __init at91_add_device_rtt_rtc(void)
 715{
 716	/* Only one resource is needed: RTT not used as RTC */
 717	at91sam9rl_rtt_device.num_resources = 1;
 718}
 719#endif
 720
 721static void __init at91_add_device_rtt(void)
 722{
 723	at91_add_device_rtt_rtc();
 724	platform_device_register(&at91sam9rl_rtt_device);
 725}
 726
 727
 728/* --------------------------------------------------------------------
 729 *  Watchdog
 730 * -------------------------------------------------------------------- */
 731
 732#if defined(CONFIG_AT91SAM9X_WATCHDOG) || defined(CONFIG_AT91SAM9X_WATCHDOG_MODULE)
 733static struct resource wdt_resources[] = {
 734	{
 735		.start	= AT91SAM9RL_BASE_WDT,
 736		.end	= AT91SAM9RL_BASE_WDT + SZ_16 - 1,
 737		.flags	= IORESOURCE_MEM,
 738	}
 739};
 740
 741static struct platform_device at91sam9rl_wdt_device = {
 742	.name		= "at91_wdt",
 743	.id		= -1,
 744	.resource	= wdt_resources,
 745	.num_resources	= ARRAY_SIZE(wdt_resources),
 746};
 747
 748static void __init at91_add_device_watchdog(void)
 749{
 750	platform_device_register(&at91sam9rl_wdt_device);
 751}
 752#else
 753static void __init at91_add_device_watchdog(void) {}
 754#endif
 755
 756
 757/* --------------------------------------------------------------------
 758 *  PWM
 759 * --------------------------------------------------------------------*/
 760
 761#if defined(CONFIG_ATMEL_PWM)
 762static u32 pwm_mask;
 763
 764static struct resource pwm_resources[] = {
 765	[0] = {
 766		.start	= AT91SAM9RL_BASE_PWMC,
 767		.end	= AT91SAM9RL_BASE_PWMC + SZ_16K - 1,
 768		.flags	= IORESOURCE_MEM,
 769	},
 770	[1] = {
 771		.start	= AT91SAM9RL_ID_PWMC,
 772		.end	= AT91SAM9RL_ID_PWMC,
 773		.flags	= IORESOURCE_IRQ,
 774	},
 775};
 776
 777static struct platform_device at91sam9rl_pwm0_device = {
 778	.name	= "atmel_pwm",
 779	.id	= -1,
 780	.dev	= {
 781		.platform_data		= &pwm_mask,
 782	},
 783	.resource	= pwm_resources,
 784	.num_resources	= ARRAY_SIZE(pwm_resources),
 785};
 786
 787void __init at91_add_device_pwm(u32 mask)
 788{
 789	if (mask & (1 << AT91_PWM0))
 790		at91_set_B_periph(AT91_PIN_PB8, 1);	/* enable PWM0 */
 791
 792	if (mask & (1 << AT91_PWM1))
 793		at91_set_B_periph(AT91_PIN_PB9, 1);	/* enable PWM1 */
 794
 795	if (mask & (1 << AT91_PWM2))
 796		at91_set_B_periph(AT91_PIN_PD5, 1);	/* enable PWM2 */
 797
 798	if (mask & (1 << AT91_PWM3))
 799		at91_set_B_periph(AT91_PIN_PD8, 1);	/* enable PWM3 */
 800
 801	pwm_mask = mask;
 802
 803	platform_device_register(&at91sam9rl_pwm0_device);
 804}
 805#else
 806void __init at91_add_device_pwm(u32 mask) {}
 807#endif
 808
 809
 810/* --------------------------------------------------------------------
 811 *  SSC -- Synchronous Serial Controller
 812 * -------------------------------------------------------------------- */
 813
 814#if defined(CONFIG_ATMEL_SSC) || defined(CONFIG_ATMEL_SSC_MODULE)
 815static u64 ssc0_dmamask = DMA_BIT_MASK(32);
 816
 817static struct resource ssc0_resources[] = {
 818	[0] = {
 819		.start	= AT91SAM9RL_BASE_SSC0,
 820		.end	= AT91SAM9RL_BASE_SSC0 + SZ_16K - 1,
 821		.flags	= IORESOURCE_MEM,
 822	},
 823	[1] = {
 824		.start	= AT91SAM9RL_ID_SSC0,
 825		.end	= AT91SAM9RL_ID_SSC0,
 826		.flags	= IORESOURCE_IRQ,
 827	},
 828};
 829
 830static struct platform_device at91sam9rl_ssc0_device = {
 831	.name	= "ssc",
 832	.id	= 0,
 833	.dev	= {
 834		.dma_mask		= &ssc0_dmamask,
 835		.coherent_dma_mask	= DMA_BIT_MASK(32),
 836	},
 837	.resource	= ssc0_resources,
 838	.num_resources	= ARRAY_SIZE(ssc0_resources),
 839};
 840
 841static inline void configure_ssc0_pins(unsigned pins)
 842{
 843	if (pins & ATMEL_SSC_TF)
 844		at91_set_A_periph(AT91_PIN_PC0, 1);
 845	if (pins & ATMEL_SSC_TK)
 846		at91_set_A_periph(AT91_PIN_PC1, 1);
 847	if (pins & ATMEL_SSC_TD)
 848		at91_set_A_periph(AT91_PIN_PA15, 1);
 849	if (pins & ATMEL_SSC_RD)
 850		at91_set_A_periph(AT91_PIN_PA16, 1);
 851	if (pins & ATMEL_SSC_RK)
 852		at91_set_B_periph(AT91_PIN_PA10, 1);
 853	if (pins & ATMEL_SSC_RF)
 854		at91_set_B_periph(AT91_PIN_PA22, 1);
 855}
 856
 857static u64 ssc1_dmamask = DMA_BIT_MASK(32);
 858
 859static struct resource ssc1_resources[] = {
 860	[0] = {
 861		.start	= AT91SAM9RL_BASE_SSC1,
 862		.end	= AT91SAM9RL_BASE_SSC1 + SZ_16K - 1,
 863		.flags	= IORESOURCE_MEM,
 864	},
 865	[1] = {
 866		.start	= AT91SAM9RL_ID_SSC1,
 867		.end	= AT91SAM9RL_ID_SSC1,
 868		.flags	= IORESOURCE_IRQ,
 869	},
 870};
 871
 872static struct platform_device at91sam9rl_ssc1_device = {
 873	.name	= "ssc",
 874	.id	= 1,
 875	.dev	= {
 876		.dma_mask		= &ssc1_dmamask,
 877		.coherent_dma_mask	= DMA_BIT_MASK(32),
 878	},
 879	.resource	= ssc1_resources,
 880	.num_resources	= ARRAY_SIZE(ssc1_resources),
 881};
 882
 883static inline void configure_ssc1_pins(unsigned pins)
 884{
 885	if (pins & ATMEL_SSC_TF)
 886		at91_set_B_periph(AT91_PIN_PA29, 1);
 887	if (pins & ATMEL_SSC_TK)
 888		at91_set_B_periph(AT91_PIN_PA30, 1);
 889	if (pins & ATMEL_SSC_TD)
 890		at91_set_B_periph(AT91_PIN_PA13, 1);
 891	if (pins & ATMEL_SSC_RD)
 892		at91_set_B_periph(AT91_PIN_PA14, 1);
 893	if (pins & ATMEL_SSC_RK)
 894		at91_set_B_periph(AT91_PIN_PA9, 1);
 895	if (pins & ATMEL_SSC_RF)
 896		at91_set_B_periph(AT91_PIN_PA8, 1);
 897}
 898
 899/*
 900 * SSC controllers are accessed through library code, instead of any
 901 * kind of all-singing/all-dancing driver.  For example one could be
 902 * used by a particular I2S audio codec's driver, while another one
 903 * on the same system might be used by a custom data capture driver.
 904 */
 905void __init at91_add_device_ssc(unsigned id, unsigned pins)
 906{
 907	struct platform_device *pdev;
 908
 909	/*
 910	 * NOTE: caller is responsible for passing information matching
 911	 * "pins" to whatever will be using each particular controller.
 912	 */
 913	switch (id) {
 914	case AT91SAM9RL_ID_SSC0:
 915		pdev = &at91sam9rl_ssc0_device;
 916		configure_ssc0_pins(pins);
 917		break;
 918	case AT91SAM9RL_ID_SSC1:
 919		pdev = &at91sam9rl_ssc1_device;
 920		configure_ssc1_pins(pins);
 921		break;
 922	default:
 923		return;
 924	}
 925
 926	platform_device_register(pdev);
 927}
 928
 929#else
 930void __init at91_add_device_ssc(unsigned id, unsigned pins) {}
 931#endif
 932
 933
 934/* --------------------------------------------------------------------
 935 *  UART
 936 * -------------------------------------------------------------------- */
 937
 938#if defined(CONFIG_SERIAL_ATMEL)
 939static struct resource dbgu_resources[] = {
 940	[0] = {
 941		.start	= AT91SAM9RL_BASE_DBGU,
 942		.end	= AT91SAM9RL_BASE_DBGU + SZ_512 - 1,
 943		.flags	= IORESOURCE_MEM,
 944	},
 945	[1] = {
 946		.start	= AT91_ID_SYS,
 947		.end	= AT91_ID_SYS,
 948		.flags	= IORESOURCE_IRQ,
 949	},
 950};
 951
 952static struct atmel_uart_data dbgu_data = {
 953	.use_dma_tx	= 0,
 954	.use_dma_rx	= 0,		/* DBGU not capable of receive DMA */
 
 955};
 956
 957static u64 dbgu_dmamask = DMA_BIT_MASK(32);
 958
 959static struct platform_device at91sam9rl_dbgu_device = {
 960	.name		= "atmel_usart",
 961	.id		= 0,
 962	.dev		= {
 963				.dma_mask		= &dbgu_dmamask,
 964				.coherent_dma_mask	= DMA_BIT_MASK(32),
 965				.platform_data		= &dbgu_data,
 966	},
 967	.resource	= dbgu_resources,
 968	.num_resources	= ARRAY_SIZE(dbgu_resources),
 969};
 970
 971static inline void configure_dbgu_pins(void)
 972{
 973	at91_set_A_periph(AT91_PIN_PA21, 0);		/* DRXD */
 974	at91_set_A_periph(AT91_PIN_PA22, 1);		/* DTXD */
 975}
 976
 977static struct resource uart0_resources[] = {
 978	[0] = {
 979		.start	= AT91SAM9RL_BASE_US0,
 980		.end	= AT91SAM9RL_BASE_US0 + SZ_16K - 1,
 981		.flags	= IORESOURCE_MEM,
 982	},
 983	[1] = {
 984		.start	= AT91SAM9RL_ID_US0,
 985		.end	= AT91SAM9RL_ID_US0,
 986		.flags	= IORESOURCE_IRQ,
 987	},
 988};
 989
 990static struct atmel_uart_data uart0_data = {
 991	.use_dma_tx	= 1,
 992	.use_dma_rx	= 1,
 993};
 994
 995static u64 uart0_dmamask = DMA_BIT_MASK(32);
 996
 997static struct platform_device at91sam9rl_uart0_device = {
 998	.name		= "atmel_usart",
 999	.id		= 1,
1000	.dev		= {
1001				.dma_mask		= &uart0_dmamask,
1002				.coherent_dma_mask	= DMA_BIT_MASK(32),
1003				.platform_data		= &uart0_data,
1004	},
1005	.resource	= uart0_resources,
1006	.num_resources	= ARRAY_SIZE(uart0_resources),
1007};
1008
1009static inline void configure_usart0_pins(unsigned pins)
1010{
1011	at91_set_A_periph(AT91_PIN_PA6, 1);		/* TXD0 */
1012	at91_set_A_periph(AT91_PIN_PA7, 0);		/* RXD0 */
1013
1014	if (pins & ATMEL_UART_RTS)
1015		at91_set_A_periph(AT91_PIN_PA9, 0);	/* RTS0 */
1016	if (pins & ATMEL_UART_CTS)
1017		at91_set_A_periph(AT91_PIN_PA10, 0);	/* CTS0 */
1018	if (pins & ATMEL_UART_DSR)
1019		at91_set_A_periph(AT91_PIN_PD14, 0);	/* DSR0 */
1020	if (pins & ATMEL_UART_DTR)
1021		at91_set_A_periph(AT91_PIN_PD15, 0);	/* DTR0 */
1022	if (pins & ATMEL_UART_DCD)
1023		at91_set_A_periph(AT91_PIN_PD16, 0);	/* DCD0 */
1024	if (pins & ATMEL_UART_RI)
1025		at91_set_A_periph(AT91_PIN_PD17, 0);	/* RI0 */
1026}
1027
1028static struct resource uart1_resources[] = {
1029	[0] = {
1030		.start	= AT91SAM9RL_BASE_US1,
1031		.end	= AT91SAM9RL_BASE_US1 + SZ_16K - 1,
1032		.flags	= IORESOURCE_MEM,
1033	},
1034	[1] = {
1035		.start	= AT91SAM9RL_ID_US1,
1036		.end	= AT91SAM9RL_ID_US1,
1037		.flags	= IORESOURCE_IRQ,
1038	},
1039};
1040
1041static struct atmel_uart_data uart1_data = {
1042	.use_dma_tx	= 1,
1043	.use_dma_rx	= 1,
1044};
1045
1046static u64 uart1_dmamask = DMA_BIT_MASK(32);
1047
1048static struct platform_device at91sam9rl_uart1_device = {
1049	.name		= "atmel_usart",
1050	.id		= 2,
1051	.dev		= {
1052				.dma_mask		= &uart1_dmamask,
1053				.coherent_dma_mask	= DMA_BIT_MASK(32),
1054				.platform_data		= &uart1_data,
1055	},
1056	.resource	= uart1_resources,
1057	.num_resources	= ARRAY_SIZE(uart1_resources),
1058};
1059
1060static inline void configure_usart1_pins(unsigned pins)
1061{
1062	at91_set_A_periph(AT91_PIN_PA11, 1);		/* TXD1 */
1063	at91_set_A_periph(AT91_PIN_PA12, 0);		/* RXD1 */
1064
1065	if (pins & ATMEL_UART_RTS)
1066		at91_set_B_periph(AT91_PIN_PA18, 0);	/* RTS1 */
1067	if (pins & ATMEL_UART_CTS)
1068		at91_set_B_periph(AT91_PIN_PA19, 0);	/* CTS1 */
1069}
1070
1071static struct resource uart2_resources[] = {
1072	[0] = {
1073		.start	= AT91SAM9RL_BASE_US2,
1074		.end	= AT91SAM9RL_BASE_US2 + SZ_16K - 1,
1075		.flags	= IORESOURCE_MEM,
1076	},
1077	[1] = {
1078		.start	= AT91SAM9RL_ID_US2,
1079		.end	= AT91SAM9RL_ID_US2,
1080		.flags	= IORESOURCE_IRQ,
1081	},
1082};
1083
1084static struct atmel_uart_data uart2_data = {
1085	.use_dma_tx	= 1,
1086	.use_dma_rx	= 1,
1087};
1088
1089static u64 uart2_dmamask = DMA_BIT_MASK(32);
1090
1091static struct platform_device at91sam9rl_uart2_device = {
1092	.name		= "atmel_usart",
1093	.id		= 3,
1094	.dev		= {
1095				.dma_mask		= &uart2_dmamask,
1096				.coherent_dma_mask	= DMA_BIT_MASK(32),
1097				.platform_data		= &uart2_data,
1098	},
1099	.resource	= uart2_resources,
1100	.num_resources	= ARRAY_SIZE(uart2_resources),
1101};
1102
1103static inline void configure_usart2_pins(unsigned pins)
1104{
1105	at91_set_A_periph(AT91_PIN_PA13, 1);		/* TXD2 */
1106	at91_set_A_periph(AT91_PIN_PA14, 0);		/* RXD2 */
1107
1108	if (pins & ATMEL_UART_RTS)
1109		at91_set_A_periph(AT91_PIN_PA29, 0);	/* RTS2 */
1110	if (pins & ATMEL_UART_CTS)
1111		at91_set_A_periph(AT91_PIN_PA30, 0);	/* CTS2 */
1112}
1113
1114static struct resource uart3_resources[] = {
1115	[0] = {
1116		.start	= AT91SAM9RL_BASE_US3,
1117		.end	= AT91SAM9RL_BASE_US3 + SZ_16K - 1,
1118		.flags	= IORESOURCE_MEM,
1119	},
1120	[1] = {
1121		.start	= AT91SAM9RL_ID_US3,
1122		.end	= AT91SAM9RL_ID_US3,
1123		.flags	= IORESOURCE_IRQ,
1124	},
1125};
1126
1127static struct atmel_uart_data uart3_data = {
1128	.use_dma_tx	= 1,
1129	.use_dma_rx	= 1,
1130};
1131
1132static u64 uart3_dmamask = DMA_BIT_MASK(32);
1133
1134static struct platform_device at91sam9rl_uart3_device = {
1135	.name		= "atmel_usart",
1136	.id		= 4,
1137	.dev		= {
1138				.dma_mask		= &uart3_dmamask,
1139				.coherent_dma_mask	= DMA_BIT_MASK(32),
1140				.platform_data		= &uart3_data,
1141	},
1142	.resource	= uart3_resources,
1143	.num_resources	= ARRAY_SIZE(uart3_resources),
1144};
1145
1146static inline void configure_usart3_pins(unsigned pins)
1147{
1148	at91_set_A_periph(AT91_PIN_PB0, 1);		/* TXD3 */
1149	at91_set_A_periph(AT91_PIN_PB1, 0);		/* RXD3 */
1150
1151	if (pins & ATMEL_UART_RTS)
1152		at91_set_B_periph(AT91_PIN_PD4, 0);	/* RTS3 */
1153	if (pins & ATMEL_UART_CTS)
1154		at91_set_B_periph(AT91_PIN_PD3, 0);	/* CTS3 */
1155}
1156
1157static struct platform_device *__initdata at91_uarts[ATMEL_MAX_UART];	/* the UARTs to use */
 
1158
1159void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins)
1160{
1161	struct platform_device *pdev;
1162	struct atmel_uart_data *pdata;
1163
1164	switch (id) {
1165		case 0:		/* DBGU */
1166			pdev = &at91sam9rl_dbgu_device;
1167			configure_dbgu_pins();
1168			break;
1169		case AT91SAM9RL_ID_US0:
1170			pdev = &at91sam9rl_uart0_device;
1171			configure_usart0_pins(pins);
1172			break;
1173		case AT91SAM9RL_ID_US1:
1174			pdev = &at91sam9rl_uart1_device;
1175			configure_usart1_pins(pins);
1176			break;
1177		case AT91SAM9RL_ID_US2:
1178			pdev = &at91sam9rl_uart2_device;
1179			configure_usart2_pins(pins);
1180			break;
1181		case AT91SAM9RL_ID_US3:
1182			pdev = &at91sam9rl_uart3_device;
1183			configure_usart3_pins(pins);
1184			break;
1185		default:
1186			return;
1187	}
1188	pdata = pdev->dev.platform_data;
1189	pdata->num = portnr;		/* update to mapped ID */
1190
1191	if (portnr < ATMEL_MAX_UART)
1192		at91_uarts[portnr] = pdev;
1193}
1194
 
 
 
 
 
 
 
 
1195void __init at91_add_device_serial(void)
1196{
1197	int i;
1198
1199	for (i = 0; i < ATMEL_MAX_UART; i++) {
1200		if (at91_uarts[i])
1201			platform_device_register(at91_uarts[i]);
1202	}
 
 
 
1203}
1204#else
1205void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) {}
 
1206void __init at91_add_device_serial(void) {}
1207#endif
1208
1209
1210/* -------------------------------------------------------------------- */
1211
1212/*
1213 * These devices are always present and don't need any board-specific
1214 * setup.
1215 */
1216static int __init at91_add_standard_devices(void)
1217{
1218	at91_add_device_hdmac();
1219	at91_add_device_rtc();
1220	at91_add_device_rtt();
1221	at91_add_device_watchdog();
1222	at91_add_device_tc();
1223	return 0;
1224}
1225
1226arch_initcall(at91_add_standard_devices);
v3.1
   1/*
   2 *  Copyright (C) 2007 Atmel Corporation
   3 *
   4 * This file is subject to the terms and conditions of the GNU General Public
   5 * License.  See the file COPYING in the main directory of this archive for
   6 * more details.
   7 */
   8
   9#include <asm/mach/arch.h>
  10#include <asm/mach/map.h>
  11
  12#include <linux/dma-mapping.h>
 
  13#include <linux/platform_device.h>
  14#include <linux/i2c-gpio.h>
  15
  16#include <linux/fb.h>
  17#include <video/atmel_lcdc.h>
  18
  19#include <mach/board.h>
  20#include <mach/gpio.h>
  21#include <mach/at91sam9rl.h>
  22#include <mach/at91sam9rl_matrix.h>
 
  23#include <mach/at91sam9_smc.h>
  24#include <mach/at_hdmac.h>
  25
  26#include "generic.h"
  27
  28
  29/* --------------------------------------------------------------------
  30 *  HDMAC - AHB DMA Controller
  31 * -------------------------------------------------------------------- */
  32
  33#if defined(CONFIG_AT_HDMAC) || defined(CONFIG_AT_HDMAC_MODULE)
  34static u64 hdmac_dmamask = DMA_BIT_MASK(32);
  35
  36static struct at_dma_platform_data atdma_pdata = {
  37	.nr_channels	= 2,
  38};
  39
  40static struct resource hdmac_resources[] = {
  41	[0] = {
  42		.start	= AT91_BASE_SYS + AT91_DMA,
  43		.end	= AT91_BASE_SYS + AT91_DMA + SZ_512 - 1,
  44		.flags	= IORESOURCE_MEM,
  45	},
  46	[2] = {
  47		.start	= AT91SAM9RL_ID_DMA,
  48		.end	= AT91SAM9RL_ID_DMA,
  49		.flags	= IORESOURCE_IRQ,
  50	},
  51};
  52
  53static struct platform_device at_hdmac_device = {
  54	.name		= "at_hdmac",
  55	.id		= -1,
  56	.dev		= {
  57				.dma_mask		= &hdmac_dmamask,
  58				.coherent_dma_mask	= DMA_BIT_MASK(32),
  59				.platform_data		= &atdma_pdata,
  60	},
  61	.resource	= hdmac_resources,
  62	.num_resources	= ARRAY_SIZE(hdmac_resources),
  63};
  64
  65void __init at91_add_device_hdmac(void)
  66{
  67	dma_cap_set(DMA_MEMCPY, atdma_pdata.cap_mask);
  68	platform_device_register(&at_hdmac_device);
  69}
  70#else
  71void __init at91_add_device_hdmac(void) {}
  72#endif
  73
  74/* --------------------------------------------------------------------
  75 *  USB HS Device (Gadget)
  76 * -------------------------------------------------------------------- */
  77
  78#if defined(CONFIG_USB_GADGET_ATMEL_USBA) || defined(CONFIG_USB_GADGET_ATMEL_USBA_MODULE)
  79
  80static struct resource usba_udc_resources[] = {
  81	[0] = {
  82		.start	= AT91SAM9RL_UDPHS_FIFO,
  83		.end	= AT91SAM9RL_UDPHS_FIFO + SZ_512K - 1,
  84		.flags	= IORESOURCE_MEM,
  85	},
  86	[1] = {
  87		.start	= AT91SAM9RL_BASE_UDPHS,
  88		.end	= AT91SAM9RL_BASE_UDPHS + SZ_1K - 1,
  89		.flags	= IORESOURCE_MEM,
  90	},
  91	[2] = {
  92		.start	= AT91SAM9RL_ID_UDPHS,
  93		.end	= AT91SAM9RL_ID_UDPHS,
  94		.flags	= IORESOURCE_IRQ,
  95	},
  96};
  97
  98#define EP(nam, idx, maxpkt, maxbk, dma, isoc)			\
  99	[idx] = {						\
 100		.name		= nam,				\
 101		.index		= idx,				\
 102		.fifo_size	= maxpkt,			\
 103		.nr_banks	= maxbk,			\
 104		.can_dma	= dma,				\
 105		.can_isoc	= isoc,				\
 106	}
 107
 108static struct usba_ep_data usba_udc_ep[] __initdata = {
 109	EP("ep0", 0, 64, 1, 0, 0),
 110	EP("ep1", 1, 1024, 2, 1, 1),
 111	EP("ep2", 2, 1024, 2, 1, 1),
 112	EP("ep3", 3, 1024, 3, 1, 0),
 113	EP("ep4", 4, 1024, 3, 1, 0),
 114	EP("ep5", 5, 1024, 3, 1, 1),
 115	EP("ep6", 6, 1024, 3, 1, 1),
 116};
 117
 118#undef EP
 119
 120/*
 121 * pdata doesn't have room for any endpoints, so we need to
 122 * append room for the ones we need right after it.
 123 */
 124static struct {
 125	struct usba_platform_data pdata;
 126	struct usba_ep_data ep[7];
 127} usba_udc_data;
 128
 129static struct platform_device at91_usba_udc_device = {
 130	.name		= "atmel_usba_udc",
 131	.id		= -1,
 132	.dev		= {
 133				.platform_data	= &usba_udc_data.pdata,
 134	},
 135	.resource	= usba_udc_resources,
 136	.num_resources	= ARRAY_SIZE(usba_udc_resources),
 137};
 138
 139void __init at91_add_device_usba(struct usba_platform_data *data)
 140{
 141	/*
 142	 * Invalid pins are 0 on AT91, but the usba driver is shared
 143	 * with AVR32, which use negative values instead. Once/if
 144	 * gpio_is_valid() is ported to AT91, revisit this code.
 145	 */
 146	usba_udc_data.pdata.vbus_pin = -EINVAL;
 147	usba_udc_data.pdata.num_ep = ARRAY_SIZE(usba_udc_ep);
 148	memcpy(usba_udc_data.ep, usba_udc_ep, sizeof(usba_udc_ep));
 149
 150	if (data && data->vbus_pin > 0) {
 151		at91_set_gpio_input(data->vbus_pin, 0);
 152		at91_set_deglitch(data->vbus_pin, 1);
 153		usba_udc_data.pdata.vbus_pin = data->vbus_pin;
 154	}
 155
 156	/* Pullup pin is handled internally by USB device peripheral */
 157
 158	platform_device_register(&at91_usba_udc_device);
 159}
 160#else
 161void __init at91_add_device_usba(struct usba_platform_data *data) {}
 162#endif
 163
 164
 165/* --------------------------------------------------------------------
 166 *  MMC / SD
 167 * -------------------------------------------------------------------- */
 168
 169#if defined(CONFIG_MMC_AT91) || defined(CONFIG_MMC_AT91_MODULE)
 170static u64 mmc_dmamask = DMA_BIT_MASK(32);
 171static struct at91_mmc_data mmc_data;
 172
 173static struct resource mmc_resources[] = {
 174	[0] = {
 175		.start	= AT91SAM9RL_BASE_MCI,
 176		.end	= AT91SAM9RL_BASE_MCI + SZ_16K - 1,
 177		.flags	= IORESOURCE_MEM,
 178	},
 179	[1] = {
 180		.start	= AT91SAM9RL_ID_MCI,
 181		.end	= AT91SAM9RL_ID_MCI,
 182		.flags	= IORESOURCE_IRQ,
 183	},
 184};
 185
 186static struct platform_device at91sam9rl_mmc_device = {
 187	.name		= "at91_mci",
 188	.id		= -1,
 189	.dev		= {
 190				.dma_mask		= &mmc_dmamask,
 191				.coherent_dma_mask	= DMA_BIT_MASK(32),
 192				.platform_data		= &mmc_data,
 193	},
 194	.resource	= mmc_resources,
 195	.num_resources	= ARRAY_SIZE(mmc_resources),
 196};
 197
 198void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data)
 199{
 200	if (!data)
 201		return;
 202
 203	/* input/irq */
 204	if (data->det_pin) {
 205		at91_set_gpio_input(data->det_pin, 1);
 206		at91_set_deglitch(data->det_pin, 1);
 207	}
 208	if (data->wp_pin)
 209		at91_set_gpio_input(data->wp_pin, 1);
 210	if (data->vcc_pin)
 211		at91_set_gpio_output(data->vcc_pin, 0);
 212
 213	/* CLK */
 214	at91_set_A_periph(AT91_PIN_PA2, 0);
 215
 216	/* CMD */
 217	at91_set_A_periph(AT91_PIN_PA1, 1);
 218
 219	/* DAT0, maybe DAT1..DAT3 */
 220	at91_set_A_periph(AT91_PIN_PA0, 1);
 221	if (data->wire4) {
 222		at91_set_A_periph(AT91_PIN_PA3, 1);
 223		at91_set_A_periph(AT91_PIN_PA4, 1);
 224		at91_set_A_periph(AT91_PIN_PA5, 1);
 225	}
 226
 227	mmc_data = *data;
 228	platform_device_register(&at91sam9rl_mmc_device);
 229}
 230#else
 231void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data) {}
 232#endif
 233
 234
 235/* --------------------------------------------------------------------
 236 *  NAND / SmartMedia
 237 * -------------------------------------------------------------------- */
 238
 239#if defined(CONFIG_MTD_NAND_ATMEL) || defined(CONFIG_MTD_NAND_ATMEL_MODULE)
 240static struct atmel_nand_data nand_data;
 241
 242#define NAND_BASE	AT91_CHIPSELECT_3
 243
 244static struct resource nand_resources[] = {
 245	[0] = {
 246		.start	= NAND_BASE,
 247		.end	= NAND_BASE + SZ_256M - 1,
 248		.flags	= IORESOURCE_MEM,
 249	},
 250	[1] = {
 251		.start	= AT91_BASE_SYS + AT91_ECC,
 252		.end	= AT91_BASE_SYS + AT91_ECC + SZ_512 - 1,
 253		.flags	= IORESOURCE_MEM,
 254	}
 255};
 256
 257static struct platform_device atmel_nand_device = {
 258	.name		= "atmel_nand",
 259	.id		= -1,
 260	.dev		= {
 261				.platform_data	= &nand_data,
 262	},
 263	.resource	= nand_resources,
 264	.num_resources	= ARRAY_SIZE(nand_resources),
 265};
 266
 267void __init at91_add_device_nand(struct atmel_nand_data *data)
 268{
 269	unsigned long csa;
 270
 271	if (!data)
 272		return;
 273
 274	csa = at91_sys_read(AT91_MATRIX_EBICSA);
 275	at91_sys_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_CS3A_SMC_SMARTMEDIA);
 276
 277	/* enable pin */
 278	if (data->enable_pin)
 279		at91_set_gpio_output(data->enable_pin, 1);
 280
 281	/* ready/busy pin */
 282	if (data->rdy_pin)
 283		at91_set_gpio_input(data->rdy_pin, 1);
 284
 285	/* card detect pin */
 286	if (data->det_pin)
 287		at91_set_gpio_input(data->det_pin, 1);
 288
 289	at91_set_A_periph(AT91_PIN_PB4, 0);		/* NANDOE */
 290	at91_set_A_periph(AT91_PIN_PB5, 0);		/* NANDWE */
 291
 292	nand_data = *data;
 293	platform_device_register(&atmel_nand_device);
 294}
 295
 296#else
 297void __init at91_add_device_nand(struct atmel_nand_data *data) {}
 298#endif
 299
 300
 301/* --------------------------------------------------------------------
 302 *  TWI (i2c)
 303 * -------------------------------------------------------------------- */
 304
 305/*
 306 * Prefer the GPIO code since the TWI controller isn't robust
 307 * (gets overruns and underruns under load) and can only issue
 308 * repeated STARTs in one scenario (the driver doesn't yet handle them).
 309 */
 310#if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
 311
 312static struct i2c_gpio_platform_data pdata = {
 313	.sda_pin		= AT91_PIN_PA23,
 314	.sda_is_open_drain	= 1,
 315	.scl_pin		= AT91_PIN_PA24,
 316	.scl_is_open_drain	= 1,
 317	.udelay			= 2,		/* ~100 kHz */
 318};
 319
 320static struct platform_device at91sam9rl_twi_device = {
 321	.name			= "i2c-gpio",
 322	.id			= -1,
 323	.dev.platform_data	= &pdata,
 324};
 325
 326void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
 327{
 328	at91_set_GPIO_periph(AT91_PIN_PA23, 1);		/* TWD (SDA) */
 329	at91_set_multi_drive(AT91_PIN_PA23, 1);
 330
 331	at91_set_GPIO_periph(AT91_PIN_PA24, 1);		/* TWCK (SCL) */
 332	at91_set_multi_drive(AT91_PIN_PA24, 1);
 333
 334	i2c_register_board_info(0, devices, nr_devices);
 335	platform_device_register(&at91sam9rl_twi_device);
 336}
 337
 338#elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
 339
 340static struct resource twi_resources[] = {
 341	[0] = {
 342		.start	= AT91SAM9RL_BASE_TWI0,
 343		.end	= AT91SAM9RL_BASE_TWI0 + SZ_16K - 1,
 344		.flags	= IORESOURCE_MEM,
 345	},
 346	[1] = {
 347		.start	= AT91SAM9RL_ID_TWI0,
 348		.end	= AT91SAM9RL_ID_TWI0,
 349		.flags	= IORESOURCE_IRQ,
 350	},
 351};
 352
 353static struct platform_device at91sam9rl_twi_device = {
 354	.name		= "at91_i2c",
 355	.id		= -1,
 356	.resource	= twi_resources,
 357	.num_resources	= ARRAY_SIZE(twi_resources),
 358};
 359
 360void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
 361{
 362	/* pins used for TWI interface */
 363	at91_set_A_periph(AT91_PIN_PA23, 0);		/* TWD */
 364	at91_set_multi_drive(AT91_PIN_PA23, 1);
 365
 366	at91_set_A_periph(AT91_PIN_PA24, 0);		/* TWCK */
 367	at91_set_multi_drive(AT91_PIN_PA24, 1);
 368
 369	i2c_register_board_info(0, devices, nr_devices);
 370	platform_device_register(&at91sam9rl_twi_device);
 371}
 372#else
 373void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices) {}
 374#endif
 375
 376
 377/* --------------------------------------------------------------------
 378 *  SPI
 379 * -------------------------------------------------------------------- */
 380
 381#if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
 382static u64 spi_dmamask = DMA_BIT_MASK(32);
 383
 384static struct resource spi_resources[] = {
 385	[0] = {
 386		.start	= AT91SAM9RL_BASE_SPI,
 387		.end	= AT91SAM9RL_BASE_SPI + SZ_16K - 1,
 388		.flags	= IORESOURCE_MEM,
 389	},
 390	[1] = {
 391		.start	= AT91SAM9RL_ID_SPI,
 392		.end	= AT91SAM9RL_ID_SPI,
 393		.flags	= IORESOURCE_IRQ,
 394	},
 395};
 396
 397static struct platform_device at91sam9rl_spi_device = {
 398	.name		= "atmel_spi",
 399	.id		= 0,
 400	.dev		= {
 401				.dma_mask		= &spi_dmamask,
 402				.coherent_dma_mask	= DMA_BIT_MASK(32),
 403	},
 404	.resource	= spi_resources,
 405	.num_resources	= ARRAY_SIZE(spi_resources),
 406};
 407
 408static const unsigned spi_standard_cs[4] = { AT91_PIN_PA28, AT91_PIN_PB7, AT91_PIN_PD8, AT91_PIN_PD9 };
 409
 410
 411void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
 412{
 413	int i;
 414	unsigned long cs_pin;
 415
 416	at91_set_A_periph(AT91_PIN_PA25, 0);	/* MISO */
 417	at91_set_A_periph(AT91_PIN_PA26, 0);	/* MOSI */
 418	at91_set_A_periph(AT91_PIN_PA27, 0);	/* SPCK */
 419
 420	/* Enable SPI chip-selects */
 421	for (i = 0; i < nr_devices; i++) {
 422		if (devices[i].controller_data)
 423			cs_pin = (unsigned long) devices[i].controller_data;
 424		else
 425			cs_pin = spi_standard_cs[devices[i].chip_select];
 426
 
 
 
 427		/* enable chip-select pin */
 428		at91_set_gpio_output(cs_pin, 1);
 429
 430		/* pass chip-select pin to driver */
 431		devices[i].controller_data = (void *) cs_pin;
 432	}
 433
 434	spi_register_board_info(devices, nr_devices);
 435	platform_device_register(&at91sam9rl_spi_device);
 436}
 437#else
 438void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
 439#endif
 440
 441
 442/* --------------------------------------------------------------------
 443 *  AC97
 444 * -------------------------------------------------------------------- */
 445
 446#if defined(CONFIG_SND_ATMEL_AC97C) || defined(CONFIG_SND_ATMEL_AC97C_MODULE)
 447static u64 ac97_dmamask = DMA_BIT_MASK(32);
 448static struct ac97c_platform_data ac97_data;
 449
 450static struct resource ac97_resources[] = {
 451	[0] = {
 452		.start	= AT91SAM9RL_BASE_AC97C,
 453		.end	= AT91SAM9RL_BASE_AC97C + SZ_16K - 1,
 454		.flags	= IORESOURCE_MEM,
 455	},
 456	[1] = {
 457		.start	= AT91SAM9RL_ID_AC97C,
 458		.end	= AT91SAM9RL_ID_AC97C,
 459		.flags	= IORESOURCE_IRQ,
 460	},
 461};
 462
 463static struct platform_device at91sam9rl_ac97_device = {
 464	.name		= "atmel_ac97c",
 465	.id		= 0,
 466	.dev		= {
 467				.dma_mask		= &ac97_dmamask,
 468				.coherent_dma_mask	= DMA_BIT_MASK(32),
 469				.platform_data		= &ac97_data,
 470	},
 471	.resource	= ac97_resources,
 472	.num_resources	= ARRAY_SIZE(ac97_resources),
 473};
 474
 475void __init at91_add_device_ac97(struct ac97c_platform_data *data)
 476{
 477	if (!data)
 478		return;
 479
 480	at91_set_A_periph(AT91_PIN_PD1, 0);	/* AC97FS */
 481	at91_set_A_periph(AT91_PIN_PD2, 0);	/* AC97CK */
 482	at91_set_A_periph(AT91_PIN_PD3, 0);	/* AC97TX */
 483	at91_set_A_periph(AT91_PIN_PD4, 0);	/* AC97RX */
 484
 485	/* reset */
 486	if (data->reset_pin)
 487		at91_set_gpio_output(data->reset_pin, 0);
 488
 489	ac97_data = *data;
 490	platform_device_register(&at91sam9rl_ac97_device);
 491}
 492#else
 493void __init at91_add_device_ac97(struct ac97c_platform_data *data) {}
 494#endif
 495
 496
 497/* --------------------------------------------------------------------
 498 *  LCD Controller
 499 * -------------------------------------------------------------------- */
 500
 501#if defined(CONFIG_FB_ATMEL) || defined(CONFIG_FB_ATMEL_MODULE)
 502static u64 lcdc_dmamask = DMA_BIT_MASK(32);
 503static struct atmel_lcdfb_info lcdc_data;
 504
 505static struct resource lcdc_resources[] = {
 506	[0] = {
 507		.start	= AT91SAM9RL_LCDC_BASE,
 508		.end	= AT91SAM9RL_LCDC_BASE + SZ_4K - 1,
 509		.flags	= IORESOURCE_MEM,
 510	},
 511	[1] = {
 512		.start	= AT91SAM9RL_ID_LCDC,
 513		.end	= AT91SAM9RL_ID_LCDC,
 514		.flags	= IORESOURCE_IRQ,
 515	},
 516};
 517
 518static struct platform_device at91_lcdc_device = {
 519	.name		= "atmel_lcdfb",
 520	.id		= 0,
 521	.dev		= {
 522				.dma_mask		= &lcdc_dmamask,
 523				.coherent_dma_mask	= DMA_BIT_MASK(32),
 524				.platform_data		= &lcdc_data,
 525	},
 526	.resource	= lcdc_resources,
 527	.num_resources	= ARRAY_SIZE(lcdc_resources),
 528};
 529
 530void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data)
 531{
 532	if (!data) {
 533		return;
 534	}
 535
 536	at91_set_B_periph(AT91_PIN_PC1, 0);	/* LCDPWR */
 537	at91_set_A_periph(AT91_PIN_PC5, 0);	/* LCDHSYNC */
 538	at91_set_A_periph(AT91_PIN_PC6, 0);	/* LCDDOTCK */
 539	at91_set_A_periph(AT91_PIN_PC7, 0);	/* LCDDEN */
 540	at91_set_A_periph(AT91_PIN_PC3, 0);	/* LCDCC */
 541	at91_set_B_periph(AT91_PIN_PC9, 0);	/* LCDD3 */
 542	at91_set_B_periph(AT91_PIN_PC10, 0);	/* LCDD4 */
 543	at91_set_B_periph(AT91_PIN_PC11, 0);	/* LCDD5 */
 544	at91_set_B_periph(AT91_PIN_PC12, 0);	/* LCDD6 */
 545	at91_set_B_periph(AT91_PIN_PC13, 0);	/* LCDD7 */
 546	at91_set_B_periph(AT91_PIN_PC15, 0);	/* LCDD11 */
 547	at91_set_B_periph(AT91_PIN_PC16, 0);	/* LCDD12 */
 548	at91_set_B_periph(AT91_PIN_PC17, 0);	/* LCDD13 */
 549	at91_set_B_periph(AT91_PIN_PC18, 0);	/* LCDD14 */
 550	at91_set_B_periph(AT91_PIN_PC19, 0);	/* LCDD15 */
 551	at91_set_B_periph(AT91_PIN_PC20, 0);	/* LCDD18 */
 552	at91_set_B_periph(AT91_PIN_PC21, 0);	/* LCDD19 */
 553	at91_set_B_periph(AT91_PIN_PC22, 0);	/* LCDD20 */
 554	at91_set_B_periph(AT91_PIN_PC23, 0);	/* LCDD21 */
 555	at91_set_B_periph(AT91_PIN_PC24, 0);	/* LCDD22 */
 556	at91_set_B_periph(AT91_PIN_PC25, 0);	/* LCDD23 */
 557
 558	lcdc_data = *data;
 559	platform_device_register(&at91_lcdc_device);
 560}
 561#else
 562void __init at91_add_device_lcdc(struct atmel_lcdfb_info *data) {}
 563#endif
 564
 565
 566/* --------------------------------------------------------------------
 567 *  Timer/Counter block
 568 * -------------------------------------------------------------------- */
 569
 570#ifdef CONFIG_ATMEL_TCLIB
 571
 572static struct resource tcb_resources[] = {
 573	[0] = {
 574		.start	= AT91SAM9RL_BASE_TCB0,
 575		.end	= AT91SAM9RL_BASE_TCB0 + SZ_16K - 1,
 576		.flags	= IORESOURCE_MEM,
 577	},
 578	[1] = {
 579		.start	= AT91SAM9RL_ID_TC0,
 580		.end	= AT91SAM9RL_ID_TC0,
 581		.flags	= IORESOURCE_IRQ,
 582	},
 583	[2] = {
 584		.start	= AT91SAM9RL_ID_TC1,
 585		.end	= AT91SAM9RL_ID_TC1,
 586		.flags	= IORESOURCE_IRQ,
 587	},
 588	[3] = {
 589		.start	= AT91SAM9RL_ID_TC2,
 590		.end	= AT91SAM9RL_ID_TC2,
 591		.flags	= IORESOURCE_IRQ,
 592	},
 593};
 594
 595static struct platform_device at91sam9rl_tcb_device = {
 596	.name		= "atmel_tcb",
 597	.id		= 0,
 598	.resource	= tcb_resources,
 599	.num_resources	= ARRAY_SIZE(tcb_resources),
 600};
 601
 602static void __init at91_add_device_tc(void)
 603{
 604	platform_device_register(&at91sam9rl_tcb_device);
 605}
 606#else
 607static void __init at91_add_device_tc(void) { }
 608#endif
 609
 610
 611/* --------------------------------------------------------------------
 612 *  Touchscreen
 613 * -------------------------------------------------------------------- */
 614
 615#if defined(CONFIG_TOUCHSCREEN_ATMEL_TSADCC) || defined(CONFIG_TOUCHSCREEN_ATMEL_TSADCC_MODULE)
 616static u64 tsadcc_dmamask = DMA_BIT_MASK(32);
 617static struct at91_tsadcc_data tsadcc_data;
 618
 619static struct resource tsadcc_resources[] = {
 620	[0] = {
 621		.start	= AT91SAM9RL_BASE_TSC,
 622		.end	= AT91SAM9RL_BASE_TSC + SZ_16K - 1,
 623		.flags	= IORESOURCE_MEM,
 624	},
 625	[1] = {
 626		.start	= AT91SAM9RL_ID_TSC,
 627		.end	= AT91SAM9RL_ID_TSC,
 628		.flags	= IORESOURCE_IRQ,
 629	}
 630};
 631
 632static struct platform_device at91sam9rl_tsadcc_device = {
 633	.name		= "atmel_tsadcc",
 634	.id		= -1,
 635	.dev		= {
 636				.dma_mask		= &tsadcc_dmamask,
 637				.coherent_dma_mask	= DMA_BIT_MASK(32),
 638				.platform_data		= &tsadcc_data,
 639	},
 640	.resource	= tsadcc_resources,
 641	.num_resources	= ARRAY_SIZE(tsadcc_resources),
 642};
 643
 644void __init at91_add_device_tsadcc(struct at91_tsadcc_data *data)
 645{
 646	if (!data)
 647		return;
 648
 649	at91_set_A_periph(AT91_PIN_PA17, 0);	/* AD0_XR */
 650	at91_set_A_periph(AT91_PIN_PA18, 0);	/* AD1_XL */
 651	at91_set_A_periph(AT91_PIN_PA19, 0);	/* AD2_YT */
 652	at91_set_A_periph(AT91_PIN_PA20, 0);	/* AD3_TB */
 653
 654	tsadcc_data = *data;
 655	platform_device_register(&at91sam9rl_tsadcc_device);
 656}
 657#else
 658void __init at91_add_device_tsadcc(struct at91_tsadcc_data *data) {}
 659#endif
 660
 661
 662/* --------------------------------------------------------------------
 663 *  RTC
 664 * -------------------------------------------------------------------- */
 665
 666#if defined(CONFIG_RTC_DRV_AT91RM9200) || defined(CONFIG_RTC_DRV_AT91RM9200_MODULE)
 667static struct platform_device at91sam9rl_rtc_device = {
 668	.name		= "at91_rtc",
 669	.id		= -1,
 670	.num_resources	= 0,
 671};
 672
 673static void __init at91_add_device_rtc(void)
 674{
 675	platform_device_register(&at91sam9rl_rtc_device);
 676}
 677#else
 678static void __init at91_add_device_rtc(void) {}
 679#endif
 680
 681
 682/* --------------------------------------------------------------------
 683 *  RTT
 684 * -------------------------------------------------------------------- */
 685
 686static struct resource rtt_resources[] = {
 687	{
 688		.start	= AT91_BASE_SYS + AT91_RTT,
 689		.end	= AT91_BASE_SYS + AT91_RTT + SZ_16 - 1,
 
 
 690		.flags	= IORESOURCE_MEM,
 691	}
 692};
 693
 694static struct platform_device at91sam9rl_rtt_device = {
 695	.name		= "at91_rtt",
 696	.id		= 0,
 697	.resource	= rtt_resources,
 698	.num_resources	= ARRAY_SIZE(rtt_resources),
 699};
 700
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 701static void __init at91_add_device_rtt(void)
 702{
 
 703	platform_device_register(&at91sam9rl_rtt_device);
 704}
 705
 706
 707/* --------------------------------------------------------------------
 708 *  Watchdog
 709 * -------------------------------------------------------------------- */
 710
 711#if defined(CONFIG_AT91SAM9X_WATCHDOG) || defined(CONFIG_AT91SAM9X_WATCHDOG_MODULE)
 
 
 
 
 
 
 
 
 712static struct platform_device at91sam9rl_wdt_device = {
 713	.name		= "at91_wdt",
 714	.id		= -1,
 715	.num_resources	= 0,
 
 716};
 717
 718static void __init at91_add_device_watchdog(void)
 719{
 720	platform_device_register(&at91sam9rl_wdt_device);
 721}
 722#else
 723static void __init at91_add_device_watchdog(void) {}
 724#endif
 725
 726
 727/* --------------------------------------------------------------------
 728 *  PWM
 729 * --------------------------------------------------------------------*/
 730
 731#if defined(CONFIG_ATMEL_PWM)
 732static u32 pwm_mask;
 733
 734static struct resource pwm_resources[] = {
 735	[0] = {
 736		.start	= AT91SAM9RL_BASE_PWMC,
 737		.end	= AT91SAM9RL_BASE_PWMC + SZ_16K - 1,
 738		.flags	= IORESOURCE_MEM,
 739	},
 740	[1] = {
 741		.start	= AT91SAM9RL_ID_PWMC,
 742		.end	= AT91SAM9RL_ID_PWMC,
 743		.flags	= IORESOURCE_IRQ,
 744	},
 745};
 746
 747static struct platform_device at91sam9rl_pwm0_device = {
 748	.name	= "atmel_pwm",
 749	.id	= -1,
 750	.dev	= {
 751		.platform_data		= &pwm_mask,
 752	},
 753	.resource	= pwm_resources,
 754	.num_resources	= ARRAY_SIZE(pwm_resources),
 755};
 756
 757void __init at91_add_device_pwm(u32 mask)
 758{
 759	if (mask & (1 << AT91_PWM0))
 760		at91_set_B_periph(AT91_PIN_PB8, 1);	/* enable PWM0 */
 761
 762	if (mask & (1 << AT91_PWM1))
 763		at91_set_B_periph(AT91_PIN_PB9, 1);	/* enable PWM1 */
 764
 765	if (mask & (1 << AT91_PWM2))
 766		at91_set_B_periph(AT91_PIN_PD5, 1);	/* enable PWM2 */
 767
 768	if (mask & (1 << AT91_PWM3))
 769		at91_set_B_periph(AT91_PIN_PD8, 1);	/* enable PWM3 */
 770
 771	pwm_mask = mask;
 772
 773	platform_device_register(&at91sam9rl_pwm0_device);
 774}
 775#else
 776void __init at91_add_device_pwm(u32 mask) {}
 777#endif
 778
 779
 780/* --------------------------------------------------------------------
 781 *  SSC -- Synchronous Serial Controller
 782 * -------------------------------------------------------------------- */
 783
 784#if defined(CONFIG_ATMEL_SSC) || defined(CONFIG_ATMEL_SSC_MODULE)
 785static u64 ssc0_dmamask = DMA_BIT_MASK(32);
 786
 787static struct resource ssc0_resources[] = {
 788	[0] = {
 789		.start	= AT91SAM9RL_BASE_SSC0,
 790		.end	= AT91SAM9RL_BASE_SSC0 + SZ_16K - 1,
 791		.flags	= IORESOURCE_MEM,
 792	},
 793	[1] = {
 794		.start	= AT91SAM9RL_ID_SSC0,
 795		.end	= AT91SAM9RL_ID_SSC0,
 796		.flags	= IORESOURCE_IRQ,
 797	},
 798};
 799
 800static struct platform_device at91sam9rl_ssc0_device = {
 801	.name	= "ssc",
 802	.id	= 0,
 803	.dev	= {
 804		.dma_mask		= &ssc0_dmamask,
 805		.coherent_dma_mask	= DMA_BIT_MASK(32),
 806	},
 807	.resource	= ssc0_resources,
 808	.num_resources	= ARRAY_SIZE(ssc0_resources),
 809};
 810
 811static inline void configure_ssc0_pins(unsigned pins)
 812{
 813	if (pins & ATMEL_SSC_TF)
 814		at91_set_A_periph(AT91_PIN_PC0, 1);
 815	if (pins & ATMEL_SSC_TK)
 816		at91_set_A_periph(AT91_PIN_PC1, 1);
 817	if (pins & ATMEL_SSC_TD)
 818		at91_set_A_periph(AT91_PIN_PA15, 1);
 819	if (pins & ATMEL_SSC_RD)
 820		at91_set_A_periph(AT91_PIN_PA16, 1);
 821	if (pins & ATMEL_SSC_RK)
 822		at91_set_B_periph(AT91_PIN_PA10, 1);
 823	if (pins & ATMEL_SSC_RF)
 824		at91_set_B_periph(AT91_PIN_PA22, 1);
 825}
 826
 827static u64 ssc1_dmamask = DMA_BIT_MASK(32);
 828
 829static struct resource ssc1_resources[] = {
 830	[0] = {
 831		.start	= AT91SAM9RL_BASE_SSC1,
 832		.end	= AT91SAM9RL_BASE_SSC1 + SZ_16K - 1,
 833		.flags	= IORESOURCE_MEM,
 834	},
 835	[1] = {
 836		.start	= AT91SAM9RL_ID_SSC1,
 837		.end	= AT91SAM9RL_ID_SSC1,
 838		.flags	= IORESOURCE_IRQ,
 839	},
 840};
 841
 842static struct platform_device at91sam9rl_ssc1_device = {
 843	.name	= "ssc",
 844	.id	= 1,
 845	.dev	= {
 846		.dma_mask		= &ssc1_dmamask,
 847		.coherent_dma_mask	= DMA_BIT_MASK(32),
 848	},
 849	.resource	= ssc1_resources,
 850	.num_resources	= ARRAY_SIZE(ssc1_resources),
 851};
 852
 853static inline void configure_ssc1_pins(unsigned pins)
 854{
 855	if (pins & ATMEL_SSC_TF)
 856		at91_set_B_periph(AT91_PIN_PA29, 1);
 857	if (pins & ATMEL_SSC_TK)
 858		at91_set_B_periph(AT91_PIN_PA30, 1);
 859	if (pins & ATMEL_SSC_TD)
 860		at91_set_B_periph(AT91_PIN_PA13, 1);
 861	if (pins & ATMEL_SSC_RD)
 862		at91_set_B_periph(AT91_PIN_PA14, 1);
 863	if (pins & ATMEL_SSC_RK)
 864		at91_set_B_periph(AT91_PIN_PA9, 1);
 865	if (pins & ATMEL_SSC_RF)
 866		at91_set_B_periph(AT91_PIN_PA8, 1);
 867}
 868
 869/*
 870 * SSC controllers are accessed through library code, instead of any
 871 * kind of all-singing/all-dancing driver.  For example one could be
 872 * used by a particular I2S audio codec's driver, while another one
 873 * on the same system might be used by a custom data capture driver.
 874 */
 875void __init at91_add_device_ssc(unsigned id, unsigned pins)
 876{
 877	struct platform_device *pdev;
 878
 879	/*
 880	 * NOTE: caller is responsible for passing information matching
 881	 * "pins" to whatever will be using each particular controller.
 882	 */
 883	switch (id) {
 884	case AT91SAM9RL_ID_SSC0:
 885		pdev = &at91sam9rl_ssc0_device;
 886		configure_ssc0_pins(pins);
 887		break;
 888	case AT91SAM9RL_ID_SSC1:
 889		pdev = &at91sam9rl_ssc1_device;
 890		configure_ssc1_pins(pins);
 891		break;
 892	default:
 893		return;
 894	}
 895
 896	platform_device_register(pdev);
 897}
 898
 899#else
 900void __init at91_add_device_ssc(unsigned id, unsigned pins) {}
 901#endif
 902
 903
 904/* --------------------------------------------------------------------
 905 *  UART
 906 * -------------------------------------------------------------------- */
 907
 908#if defined(CONFIG_SERIAL_ATMEL)
 909static struct resource dbgu_resources[] = {
 910	[0] = {
 911		.start	= AT91_VA_BASE_SYS + AT91_DBGU,
 912		.end	= AT91_VA_BASE_SYS + AT91_DBGU + SZ_512 - 1,
 913		.flags	= IORESOURCE_MEM,
 914	},
 915	[1] = {
 916		.start	= AT91_ID_SYS,
 917		.end	= AT91_ID_SYS,
 918		.flags	= IORESOURCE_IRQ,
 919	},
 920};
 921
 922static struct atmel_uart_data dbgu_data = {
 923	.use_dma_tx	= 0,
 924	.use_dma_rx	= 0,		/* DBGU not capable of receive DMA */
 925	.regs		= (void __iomem *)(AT91_VA_BASE_SYS + AT91_DBGU),
 926};
 927
 928static u64 dbgu_dmamask = DMA_BIT_MASK(32);
 929
 930static struct platform_device at91sam9rl_dbgu_device = {
 931	.name		= "atmel_usart",
 932	.id		= 0,
 933	.dev		= {
 934				.dma_mask		= &dbgu_dmamask,
 935				.coherent_dma_mask	= DMA_BIT_MASK(32),
 936				.platform_data		= &dbgu_data,
 937	},
 938	.resource	= dbgu_resources,
 939	.num_resources	= ARRAY_SIZE(dbgu_resources),
 940};
 941
 942static inline void configure_dbgu_pins(void)
 943{
 944	at91_set_A_periph(AT91_PIN_PA21, 0);		/* DRXD */
 945	at91_set_A_periph(AT91_PIN_PA22, 1);		/* DTXD */
 946}
 947
 948static struct resource uart0_resources[] = {
 949	[0] = {
 950		.start	= AT91SAM9RL_BASE_US0,
 951		.end	= AT91SAM9RL_BASE_US0 + SZ_16K - 1,
 952		.flags	= IORESOURCE_MEM,
 953	},
 954	[1] = {
 955		.start	= AT91SAM9RL_ID_US0,
 956		.end	= AT91SAM9RL_ID_US0,
 957		.flags	= IORESOURCE_IRQ,
 958	},
 959};
 960
 961static struct atmel_uart_data uart0_data = {
 962	.use_dma_tx	= 1,
 963	.use_dma_rx	= 1,
 964};
 965
 966static u64 uart0_dmamask = DMA_BIT_MASK(32);
 967
 968static struct platform_device at91sam9rl_uart0_device = {
 969	.name		= "atmel_usart",
 970	.id		= 1,
 971	.dev		= {
 972				.dma_mask		= &uart0_dmamask,
 973				.coherent_dma_mask	= DMA_BIT_MASK(32),
 974				.platform_data		= &uart0_data,
 975	},
 976	.resource	= uart0_resources,
 977	.num_resources	= ARRAY_SIZE(uart0_resources),
 978};
 979
 980static inline void configure_usart0_pins(unsigned pins)
 981{
 982	at91_set_A_periph(AT91_PIN_PA6, 1);		/* TXD0 */
 983	at91_set_A_periph(AT91_PIN_PA7, 0);		/* RXD0 */
 984
 985	if (pins & ATMEL_UART_RTS)
 986		at91_set_A_periph(AT91_PIN_PA9, 0);	/* RTS0 */
 987	if (pins & ATMEL_UART_CTS)
 988		at91_set_A_periph(AT91_PIN_PA10, 0);	/* CTS0 */
 989	if (pins & ATMEL_UART_DSR)
 990		at91_set_A_periph(AT91_PIN_PD14, 0);	/* DSR0 */
 991	if (pins & ATMEL_UART_DTR)
 992		at91_set_A_periph(AT91_PIN_PD15, 0);	/* DTR0 */
 993	if (pins & ATMEL_UART_DCD)
 994		at91_set_A_periph(AT91_PIN_PD16, 0);	/* DCD0 */
 995	if (pins & ATMEL_UART_RI)
 996		at91_set_A_periph(AT91_PIN_PD17, 0);	/* RI0 */
 997}
 998
 999static struct resource uart1_resources[] = {
1000	[0] = {
1001		.start	= AT91SAM9RL_BASE_US1,
1002		.end	= AT91SAM9RL_BASE_US1 + SZ_16K - 1,
1003		.flags	= IORESOURCE_MEM,
1004	},
1005	[1] = {
1006		.start	= AT91SAM9RL_ID_US1,
1007		.end	= AT91SAM9RL_ID_US1,
1008		.flags	= IORESOURCE_IRQ,
1009	},
1010};
1011
1012static struct atmel_uart_data uart1_data = {
1013	.use_dma_tx	= 1,
1014	.use_dma_rx	= 1,
1015};
1016
1017static u64 uart1_dmamask = DMA_BIT_MASK(32);
1018
1019static struct platform_device at91sam9rl_uart1_device = {
1020	.name		= "atmel_usart",
1021	.id		= 2,
1022	.dev		= {
1023				.dma_mask		= &uart1_dmamask,
1024				.coherent_dma_mask	= DMA_BIT_MASK(32),
1025				.platform_data		= &uart1_data,
1026	},
1027	.resource	= uart1_resources,
1028	.num_resources	= ARRAY_SIZE(uart1_resources),
1029};
1030
1031static inline void configure_usart1_pins(unsigned pins)
1032{
1033	at91_set_A_periph(AT91_PIN_PA11, 1);		/* TXD1 */
1034	at91_set_A_periph(AT91_PIN_PA12, 0);		/* RXD1 */
1035
1036	if (pins & ATMEL_UART_RTS)
1037		at91_set_B_periph(AT91_PIN_PA18, 0);	/* RTS1 */
1038	if (pins & ATMEL_UART_CTS)
1039		at91_set_B_periph(AT91_PIN_PA19, 0);	/* CTS1 */
1040}
1041
1042static struct resource uart2_resources[] = {
1043	[0] = {
1044		.start	= AT91SAM9RL_BASE_US2,
1045		.end	= AT91SAM9RL_BASE_US2 + SZ_16K - 1,
1046		.flags	= IORESOURCE_MEM,
1047	},
1048	[1] = {
1049		.start	= AT91SAM9RL_ID_US2,
1050		.end	= AT91SAM9RL_ID_US2,
1051		.flags	= IORESOURCE_IRQ,
1052	},
1053};
1054
1055static struct atmel_uart_data uart2_data = {
1056	.use_dma_tx	= 1,
1057	.use_dma_rx	= 1,
1058};
1059
1060static u64 uart2_dmamask = DMA_BIT_MASK(32);
1061
1062static struct platform_device at91sam9rl_uart2_device = {
1063	.name		= "atmel_usart",
1064	.id		= 3,
1065	.dev		= {
1066				.dma_mask		= &uart2_dmamask,
1067				.coherent_dma_mask	= DMA_BIT_MASK(32),
1068				.platform_data		= &uart2_data,
1069	},
1070	.resource	= uart2_resources,
1071	.num_resources	= ARRAY_SIZE(uart2_resources),
1072};
1073
1074static inline void configure_usart2_pins(unsigned pins)
1075{
1076	at91_set_A_periph(AT91_PIN_PA13, 1);		/* TXD2 */
1077	at91_set_A_periph(AT91_PIN_PA14, 0);		/* RXD2 */
1078
1079	if (pins & ATMEL_UART_RTS)
1080		at91_set_A_periph(AT91_PIN_PA29, 0);	/* RTS2 */
1081	if (pins & ATMEL_UART_CTS)
1082		at91_set_A_periph(AT91_PIN_PA30, 0);	/* CTS2 */
1083}
1084
1085static struct resource uart3_resources[] = {
1086	[0] = {
1087		.start	= AT91SAM9RL_BASE_US3,
1088		.end	= AT91SAM9RL_BASE_US3 + SZ_16K - 1,
1089		.flags	= IORESOURCE_MEM,
1090	},
1091	[1] = {
1092		.start	= AT91SAM9RL_ID_US3,
1093		.end	= AT91SAM9RL_ID_US3,
1094		.flags	= IORESOURCE_IRQ,
1095	},
1096};
1097
1098static struct atmel_uart_data uart3_data = {
1099	.use_dma_tx	= 1,
1100	.use_dma_rx	= 1,
1101};
1102
1103static u64 uart3_dmamask = DMA_BIT_MASK(32);
1104
1105static struct platform_device at91sam9rl_uart3_device = {
1106	.name		= "atmel_usart",
1107	.id		= 4,
1108	.dev		= {
1109				.dma_mask		= &uart3_dmamask,
1110				.coherent_dma_mask	= DMA_BIT_MASK(32),
1111				.platform_data		= &uart3_data,
1112	},
1113	.resource	= uart3_resources,
1114	.num_resources	= ARRAY_SIZE(uart3_resources),
1115};
1116
1117static inline void configure_usart3_pins(unsigned pins)
1118{
1119	at91_set_A_periph(AT91_PIN_PB0, 1);		/* TXD3 */
1120	at91_set_A_periph(AT91_PIN_PB1, 0);		/* RXD3 */
1121
1122	if (pins & ATMEL_UART_RTS)
1123		at91_set_B_periph(AT91_PIN_PD4, 0);	/* RTS3 */
1124	if (pins & ATMEL_UART_CTS)
1125		at91_set_B_periph(AT91_PIN_PD3, 0);	/* CTS3 */
1126}
1127
1128static struct platform_device *__initdata at91_uarts[ATMEL_MAX_UART];	/* the UARTs to use */
1129struct platform_device *atmel_default_console_device;	/* the serial console device */
1130
1131void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins)
1132{
1133	struct platform_device *pdev;
1134	struct atmel_uart_data *pdata;
1135
1136	switch (id) {
1137		case 0:		/* DBGU */
1138			pdev = &at91sam9rl_dbgu_device;
1139			configure_dbgu_pins();
1140			break;
1141		case AT91SAM9RL_ID_US0:
1142			pdev = &at91sam9rl_uart0_device;
1143			configure_usart0_pins(pins);
1144			break;
1145		case AT91SAM9RL_ID_US1:
1146			pdev = &at91sam9rl_uart1_device;
1147			configure_usart1_pins(pins);
1148			break;
1149		case AT91SAM9RL_ID_US2:
1150			pdev = &at91sam9rl_uart2_device;
1151			configure_usart2_pins(pins);
1152			break;
1153		case AT91SAM9RL_ID_US3:
1154			pdev = &at91sam9rl_uart3_device;
1155			configure_usart3_pins(pins);
1156			break;
1157		default:
1158			return;
1159	}
1160	pdata = pdev->dev.platform_data;
1161	pdata->num = portnr;		/* update to mapped ID */
1162
1163	if (portnr < ATMEL_MAX_UART)
1164		at91_uarts[portnr] = pdev;
1165}
1166
1167void __init at91_set_serial_console(unsigned portnr)
1168{
1169	if (portnr < ATMEL_MAX_UART) {
1170		atmel_default_console_device = at91_uarts[portnr];
1171		at91sam9rl_set_console_clock(at91_uarts[portnr]->id);
1172	}
1173}
1174
1175void __init at91_add_device_serial(void)
1176{
1177	int i;
1178
1179	for (i = 0; i < ATMEL_MAX_UART; i++) {
1180		if (at91_uarts[i])
1181			platform_device_register(at91_uarts[i]);
1182	}
1183
1184	if (!atmel_default_console_device)
1185		printk(KERN_INFO "AT91: No default serial console defined.\n");
1186}
1187#else
1188void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) {}
1189void __init at91_set_serial_console(unsigned portnr) {}
1190void __init at91_add_device_serial(void) {}
1191#endif
1192
1193
1194/* -------------------------------------------------------------------- */
1195
1196/*
1197 * These devices are always present and don't need any board-specific
1198 * setup.
1199 */
1200static int __init at91_add_standard_devices(void)
1201{
1202	at91_add_device_hdmac();
1203	at91_add_device_rtc();
1204	at91_add_device_rtt();
1205	at91_add_device_watchdog();
1206	at91_add_device_tc();
1207	return 0;
1208}
1209
1210arch_initcall(at91_add_standard_devices);