特别详细好懂的一篇文章:s3c2440 -linux-LED驱动

2019-07-12 15:52发布

嵌入式Linux之我行,主要讲述和总结了本人在学习嵌入式linux中的每个步骤。一为总结经验,二希望能给想入门嵌入式Linux的朋友提供方便。如有错误之处,谢请指正。 ·共享资源,欢迎转载:http://hbhuanggang.cublog.cn 一、开发环境 ·  机:VMWare--Fedora 9 ·开发板:Mini2440--64MB Nand ·编译器:arm-linux-gcc-4.3.2 二、实现步骤 1. 硬件原理图分析。由原理图得知LED电路是共阳极的,并分别由2440GPB5GPB6GPB7GPB8口控制的 2. 去掉内核已有的LED驱动设置,因为IO口与mini2440开发板的不一致,根本就不能控制板上的LED #gedit arch/arm/plat-s3c24xx/common-smdk.c    //注释掉以下内容   /* LED devices */
/*
static struct s3c24xx_led_platdata smdk_pdata_led4 = {
    .gpio        = S3C2410_GPF4,
    .flags        = S3C24XX_LEDF_ACTLOW | S3C24XX_LEDF_TRISTATE,
    .name        = "led4",
    .def_trigger    = "timer",
};

static struct s3c24xx_led_platdata smdk_pdata_led5 = {
    .gpio        = S3C2410_GPF5,
    .flags        = S3C24XX_LEDF_ACTLOW | S3C24XX_LEDF_TRISTATE,
    .name        = "led5",
    .def_trigger    = "nand-disk",
};

static struct s3c24xx_led_platdata smdk_pdata_led6 = {
    .gpio        = S3C2410_GPF6,
    .flags        = S3C24XX_LEDF_ACTLOW | S3C24XX_LEDF_TRISTATE,
    .name        = "led6",
};

static struct s3c24xx_led_platdata smdk_pdata_led7 = {
    .gpio        = S3C2410_GPF7,
    .flags        = S3C24XX_LEDF_ACTLOW | S3C24XX_LEDF_TRISTATE,
    .name        = "led7",
};

static struct platform_device smdk_led4 = {
    .name        = "s3c24xx_led",
    .id        = 0,
    .dev        = {
        .platform_data = &smdk_pdata_led4,
    },
};

static struct platform_device smdk_led5 = {
    .name        = "s3c24xx_led",
    .id        = 1,
    .dev        = {
        .platform_data = &smdk_pdata_led5,
    },
};

static struct platform_device smdk_led6 = {
    .name        = "s3c24xx_led",
    .id        = 2,
    .dev        = {
        .platform_data = &smdk_pdata_led6,
    },
};

static struct platform_device smdk_led7 = {
    .name        = "s3c24xx_led",
    .id        = 3,
    .dev        = {
        .platform_data = &smdk_pdata_led7,
    },
};*/   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;

    s3c_device_nand.dev.platform_data = &smdk_nand_info;

    platform_add_devices(smdk_devs, ARRAY_SIZE(smdk_devs));

    s3c_pm_init();
}
3.
编写适合mini2440开发板的LED驱动,代码如下,文件名称:my2440_leds.c /*
 ==============================================
 Name            : my2440_leds.c
 Author          : Huang Gang
 Date            : 05/11/2009
 Copyright       : GPL
 Description     : my2440 leds driver
 ==============================================
 */

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/fs.h>
#include <linux/errno.h>
#include <mach/hardware.h>
#include <mach/regs-gpio.h>

#define DEVICE_NAME