1. 程式人生 > >at91sam9260ek的板級、irq初始化-小試牛刀

at91sam9260ek的板級、irq初始化-小試牛刀

話不多說,先上程式碼。

//code path:arch/arm/mach-at91/board-sam9260ek.c
MACHINE_START(AT91SAM9260EK, "Atmel AT91SAM9260-EK")
	/* Maintainer: Atmel */
	.phys_io	= AT91_BASE_SYS,
	.io_pg_offst	= (AT91_VA_BASE_SYS >> 18) & 0xfffc,
	.boot_params	= AT91_SDRAM_BASE + 0x100,
	.timer		= &at91sam926x_timer,
	.map_io		= ek_map_io,//初始化時鐘和7個usart
	.init_irq	= ek_init_irq,<span style="white-space:pre">	</span>//macro for interrput definition 各個中斷號的優先順序定義
	.init_machine	= ek_board_init, //including USB PCI NAND Serial.etc initialization.各個外設初始化
MACHINE_END

該結構體的定義,在arch.h定義

#define MACHINE_START(_type,_name)			\
static const struct machine_desc __mach_desc_##_type	\
 __used							\
 __attribute__((__section__(".arch.info.init"))) = {	\
	.nr		= MACH_TYPE_##_type,		\
	.name		= _name,

#define MACHINE_END				\
};

首先,分析板級初始化的具體步驟:
//platform device register
static void __init ek_board_init(void)
{
	/* Serial */
	at91_add_device_serial(); //9260平臺串列埠裝置初始化註冊platform device register,還有裝置驅動註冊driver register,具體在atmel_serial.c
	/* USB Host */
	at91_add_device_usbh(&ek_usbh_data);//
	/* USB Device */
	at91_add_device_udc(&ek_udc_data);//
	/* SPI */
	//at91_add_device_spi(ek_spi_devices, ARRAY_SIZE(ek_spi_devices));
	/* NAND */
	ek_add_device_nand();//nand初始化,定義nand的分割槽狀態,位寬,以及定義nand驅動連線的建立時間、維持時間等,設定nand的匯流排片選地址範圍資訊
	/* Ethernet */
	at91_add_device_eth(&ek_macb_data);//乙太網驅動,設定各個外設管腳功能,具體見下
	/* MMC */
	//at91_add_device_mmc(0, &ek_mmc_data);
	/* I2C */
	//at91_add_device_i2c(NULL, 0);
	/* Compact Flash */
	//at91_add_device_cf(&ek_cf_data);
	/* SSC (to AT73C213) */
	//at73c213_set_clk(&at73c213_data);
	//at91_add_device_ssc(AT91SAM9260_ID_SSC, ATMEL_SSC_TX);
	/* LEDs */
	//at91_gpio_leds(ek_leds, ARRAY_SIZE(ek_leds));
	/* Push Buttons */
	//ek_add_device_buttons();
	/* shutdown controller, wakeup button (5 msec low) */
	at91_sys_write(AT91_SHDW_MR, 0);//給shutdown模式暫存器寫0,shutdown主要是用在待機喚醒等需求
}
//Ethernet的初始化
void __init at91_add_device_eth(struct at91_eth_data *data)
{
	if (!data)
		return;

	if (data->phy_irq_pin) {
		at91_set_gpio_input(data->phy_irq_pin, 0);
		at91_set_deglitch(data->phy_irq_pin, 1);
	}

	/* Pins used for MII and RMII */
	at91_set_A_periph(AT91_PIN_PA19, 0);	/* ETXCK_EREFCK */
	at91_set_A_periph(AT91_PIN_PA17, 0);	/* ERXDV */
	at91_set_A_periph(AT91_PIN_PA14, 0);	/* ERX0 */
	at91_set_A_periph(AT91_PIN_PA15, 0);	/* ERX1 */
	at91_set_A_periph(AT91_PIN_PA18, 0);	/* ERXER */
	at91_set_A_periph(AT91_PIN_PA16, 0);	/* ETXEN */
	at91_set_A_periph(AT91_PIN_PA12, 0);	/* ETX0 */
	at91_set_A_periph(AT91_PIN_PA13, 0);	/* ETX1 */
	at91_set_A_periph(AT91_PIN_PA21, 0);	/* EMDIO */
	at91_set_A_periph(AT91_PIN_PA20, 0);	/* EMDC */

	if (!data->is_rmii) {
		at91_set_B_periph(AT91_PIN_PA28, 0);	/* ECRS */
		at91_set_B_periph(AT91_PIN_PA29, 0);	/* ECOL */
		at91_set_B_periph(AT91_PIN_PA25, 0);	/* ERX2 */
		at91_set_B_periph(AT91_PIN_PA26, 0);	/* ERX3 */
		at91_set_B_periph(AT91_PIN_PA27, 0);	/* ERXCK */
		at91_set_B_periph(AT91_PIN_PA23, 0);	/* ETX2 */
		at91_set_B_periph(AT91_PIN_PA24, 0);	/* ETX3 */
		at91_set_B_periph(AT91_PIN_PA22, 0);	/* ETXER */
	}

	eth_data = *data;
	platform_device_register(&at91sam9260_eth_device); //設備註冊最後都會呼叫此函式
}