s3c2410 linux板級檔案裝置的初始化過程
阿新 • • 發佈:2019-02-09
/*linux板級裝置的初始化過程
start_kernel() -> setup_arch(&command_line) -> mdesc = setup_machine(machine_arch_type) -> list = lookup_machine_type(nr) -> return struct machine_desc.
核心在啟動的時候就是最先執行start_kernel() , 然後她就會呼叫體系結構相關的setup_arch(&command_line), 如arm體系結構的在arch/arm/kernel/setup.c中,
進一步, 她就要初始化板級相關的裝置, 但在此之前, 她必須找到這塊目標板的描述結構, 所以她就先通過lookup_machine_type(nr)來查詢這個結構,
傳入的引數是又uboot傳過來的, 儲存在r2中. 如假設她傳入的是'SMDK2410' 的nr, lookup_machine_type(nr) 就會找到如下的machine_desc.
這個結構在一個專門描述sddk2410的檔案中--arch/arm/mach-s3c2410/mach-smdk2410.c
*/
MACHINE_START(SMDK2410, "SMDK2410") /* @TODO: request a new identifier and switch
* to SMDK2410 */
/* Maintainer: Jonas Dietsche */
.phys_io = S3C2410_PA_UART,
.io_pg_offst = (((u32)S3C24XX_VA_UART) >> 18) & 0xfffc,
.boot_params = S3C2410_SDRAM_PA + 0x100,
//重要的板級初始化函式
.map_io = smdk2410_map_io,
.init_irq = s3c24xx_init_irq,
.init_machine = smdk2410_init,
.timer = &s3c24xx_timer,
MACHINE_END
/*
MACHINE_START的第一個引數是用來構造機器的型別的, 如這裡的SMDK2410 ,
又下面的定義
.nr = MACH_TYPE_##_type
有 nr = MACH_TYPE_SMDK2410
而 MACH_TYPE_SMDK2410這些機器型別則在/include/asm-arm/mach-types.h中定義:
#define MACH_TYPE_SMDK2410 193
完整的結構描述如下:
*/
struct machine_desc {
/*
* Note! The first four elements are used
* by assembler code in head-armv.S
*/
unsigned int nr; /* architecture number */
unsigned int phys_io; /* start of physical io */
unsigned int io_pg_offst; /* byte offset for io
* page tabe entry */
const char *name; /* architecture name */
unsigned long boot_params; /* tagged list */
unsigned int video_start; /* start of video RAM */
unsigned int video_end; /* end of video RAM */
unsigned int reserve_lp0 :1; /* never has lp0 */
unsigned int reserve_lp1 :1; /* never has lp1 */
unsigned int reserve_lp2 :1; /* never has lp2 */
unsigned int soft_reboot :1; /* soft reboot */
void (*fixup)(struct machine_desc *,
struct tag *, char **,
struct meminfo *);
void (*map_io)(void);/* IO mapping function */
void (*init_irq)(void);
struct sys_timer *timer; /* system tick timer */
void (*init_machine)(void);
};
/*
* Set of macros to define architecture features. This is built into
* a table by the linker.
*/
#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 \
};
/*
在arch/arm/mach-s3c2410/mach-smdk2410.c 定義了以下兩個函式實現:
*/
static struct map_desc smdk2410_iodesc[] __initdata = {
/* nothing here yet */
};
static struct platform_device *smdk2410_devices[] __initdata = {
&s3c_device_usb,
&s3c_device_lcd,
&s3c_device_wdt,
&s3c_device_i2c,
&s3c_device_iis,
};
static void __init smdk2410_map_io(void)
{
//主要是做外圍裝置的實體地址到虛擬地址的對映
s3c24xx_init_io(smdk2410_iodesc, ARRAY_SIZE(smdk2410_iodesc));
//頻率的初始化
s3c24xx_init_clocks(0);
//串列埠的初始化
s3c24xx_init_uarts(smdk2410_uartcfgs, ARRAY_SIZE(smdk2410_uartcfgs));
}
static void __init smdk2410_init(void)
{
//註冊smdk2410特有的裝置
platform_add_devices(smdk2410_devices, ARRAY_SIZE(smdk2410_devices));
//smdk系列的初始化, 我們知道smdk有2410, 2412, 2440等等, 所以這裡她又抽象出了一些共有的相同的部分, 都使用下面的函式做初始化工作.
smdk_machine_init();
}
/* devices we initialise */
static struct platform_device __initdata *smdk_devs[] = {
&s3c_device_nand,
&smdk_led4,
&smdk_led5,
&smdk_led6,
&smdk_led7,
};
void __init smdk_machine_init(void)
{
/* Configure the LEDs (even if we have no LED support)*/
s3c2410_gpio_cfgpin(S3C2410_GPF4, S3C2410_GPF4_OUTP);
s3c2410_gpio_cfgpin(S3C2410_GPF5, S3C2410_GPF5_OUTP);
s3c2410_gpio_cfgpin(S3C2410_GPF6, S3C2410_GPF6_OUTP);
s3c2410_gpio_cfgpin(S3C2410_GPF7, S3C2410_GPF7_OUTP);
s3c2410_gpio_setpin(S3C2410_GPF4, 1);
s3c2410_gpio_setpin(S3C2410_GPF5, 1);
s3c2410_gpio_setpin(S3C2410_GPF6, 1);
s3c2410_gpio_setpin(S3C2410_GPF7, 1);
if (machine_is_smdk2443())
smdk_nand_info.twrph0 = 50;
//注意這一行, 註冊了nand flash的分割槽資訊
s3c_device_nand.dev.platform_data = &smdk_nand_info;
//再一次註冊裝置, 但這一次是smdk共有的. 如nand flash等等
platform_add_devices(smdk_devs, ARRAY_SIZE(smdk_devs));
//電源管理的初始化
s3c2410_pm_init();
}
start_kernel() -> setup_arch(&command_line) -> mdesc = setup_machine(machine_arch_type) -> list = lookup_machine_type(nr) -> return struct machine_desc.
核心在啟動的時候就是最先執行start_kernel() , 然後她就會呼叫體系結構相關的setup_arch(&command_line), 如arm體系結構的在arch/arm/kernel/setup.c中,
進一步, 她就要初始化板級相關的裝置, 但在此之前, 她必須找到這塊目標板的描述結構, 所以她就先通過lookup_machine_type(nr)來查詢這個結構,
傳入的引數是又uboot傳過來的, 儲存在r2中. 如假設她傳入的是'SMDK2410' 的nr, lookup_machine_type(nr) 就會找到如下的machine_desc.
這個結構在一個專門描述sddk2410的檔案中--arch/arm/mach-s3c2410/mach-smdk2410.c
*/
MACHINE_START(SMDK2410, "SMDK2410") /* @TODO: request a new identifier and switch
* to SMDK2410 */
/* Maintainer: Jonas Dietsche */
.phys_io = S3C2410_PA_UART,
.io_pg_offst = (((u32)S3C24XX_VA_UART) >> 18) & 0xfffc,
.boot_params = S3C2410_SDRAM_PA + 0x100,
//重要的板級初始化函式
.map_io = smdk2410_map_io,
.init_irq = s3c24xx_init_irq,
.init_machine = smdk2410_init,
.timer = &s3c24xx_timer,
MACHINE_END
/*
MACHINE_START的第一個引數是用來構造機器的型別的, 如這裡的SMDK2410 ,
又下面的定義
.nr = MACH_TYPE_##_type
有 nr = MACH_TYPE_SMDK2410
而 MACH_TYPE_SMDK2410這些機器型別則在/include/asm-arm/mach-types.h中定義:
#define MACH_TYPE_SMDK2410 193
完整的結構描述如下:
*/
struct machine_desc {
/*
* Note! The first four elements are used
* by assembler code in head-armv.S
*/
unsigned int nr; /* architecture number */
unsigned int phys_io; /* start of physical io */
unsigned int io_pg_offst; /* byte offset for io
* page tabe entry */
const char *name; /* architecture name */
unsigned long boot_params; /* tagged list */
unsigned int video_start; /* start of video RAM */
unsigned int video_end; /* end of video RAM */
unsigned int reserve_lp0 :1; /* never has lp0 */
unsigned int reserve_lp1 :1; /* never has lp1 */
unsigned int reserve_lp2 :1; /* never has lp2 */
unsigned int soft_reboot :1; /* soft reboot */
void (*fixup)(struct machine_desc *,
struct tag *, char **,
struct meminfo *);
void (*map_io)(void);/* IO mapping function */
void (*init_irq)(void);
struct sys_timer *timer; /* system tick timer */
void (*init_machine)(void);
};
/*
* Set of macros to define architecture features. This is built into
* a table by the linker.
*/
#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 \
};
/*
在arch/arm/mach-s3c2410/mach-smdk2410.c 定義了以下兩個函式實現:
*/
static struct map_desc smdk2410_iodesc[] __initdata = {
/* nothing here yet */
};
static struct platform_device *smdk2410_devices[] __initdata = {
&s3c_device_usb,
&s3c_device_lcd,
&s3c_device_wdt,
&s3c_device_i2c,
&s3c_device_iis,
};
static void __init smdk2410_map_io(void)
{
//主要是做外圍裝置的實體地址到虛擬地址的對映
s3c24xx_init_io(smdk2410_iodesc, ARRAY_SIZE(smdk2410_iodesc));
//頻率的初始化
s3c24xx_init_clocks(0);
//串列埠的初始化
s3c24xx_init_uarts(smdk2410_uartcfgs, ARRAY_SIZE(smdk2410_uartcfgs));
}
static void __init smdk2410_init(void)
{
//註冊smdk2410特有的裝置
platform_add_devices(smdk2410_devices, ARRAY_SIZE(smdk2410_devices));
//smdk系列的初始化, 我們知道smdk有2410, 2412, 2440等等, 所以這裡她又抽象出了一些共有的相同的部分, 都使用下面的函式做初始化工作.
smdk_machine_init();
}
/* devices we initialise */
static struct platform_device __initdata *smdk_devs[] = {
&s3c_device_nand,
&smdk_led4,
&smdk_led5,
&smdk_led6,
&smdk_led7,
};
void __init smdk_machine_init(void)
{
/* Configure the LEDs (even if we have no LED support)*/
s3c2410_gpio_cfgpin(S3C2410_GPF4, S3C2410_GPF4_OUTP);
s3c2410_gpio_cfgpin(S3C2410_GPF5, S3C2410_GPF5_OUTP);
s3c2410_gpio_cfgpin(S3C2410_GPF6, S3C2410_GPF6_OUTP);
s3c2410_gpio_cfgpin(S3C2410_GPF7, S3C2410_GPF7_OUTP);
s3c2410_gpio_setpin(S3C2410_GPF4, 1);
s3c2410_gpio_setpin(S3C2410_GPF5, 1);
s3c2410_gpio_setpin(S3C2410_GPF6, 1);
s3c2410_gpio_setpin(S3C2410_GPF7, 1);
if (machine_is_smdk2443())
smdk_nand_info.twrph0 = 50;
//注意這一行, 註冊了nand flash的分割槽資訊
s3c_device_nand.dev.platform_data = &smdk_nand_info;
//再一次註冊裝置, 但這一次是smdk共有的. 如nand flash等等
platform_add_devices(smdk_devs, ARRAY_SIZE(smdk_devs));
//電源管理的初始化
s3c2410_pm_init();
}