免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12
最近访问板块 发新帖
楼主: xiaoyao183
打印 上一主题 下一主题

GPIO驱动疑问 [复制链接]

论坛徽章:
0
11 [报告]
发表于 2008-08-25 19:19 |只看该作者
/*
* LED driver for Atmel AT91-based boards.
*
*  Copyright (C) SAN People (Pty) Ltd
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*/

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>

#include <asm/mach-types.h>
#include <asm/arch/board.h>
#include <asm/arch/gpio.h>


/* ------------------------------------------------------------------------- */

#if defined(CONFIG_NEW_LEDS)

#include <linux/platform_device.h>

/*
* New cross-platform LED support.
*/

static struct gpio_led_platform_data led_data;

static struct platform_device at91_leds = {
        .name                        = "leds-gpio",
        .id                        = -1,
        .dev.platform_data        = &led_data,
};

void __init at91_gpio_leds(struct gpio_led *leds, int nr)
{
        int i;

        if (!nr)
                return;

        for (i = 0; i < nr; i++)
                at91_set_gpio_output(leds.gpio, leds.active_low);

        led_data.leds = leds;
        led_data.num_leds = nr;
        platform_device_register(&at91_leds);
}

#else
void __init at91_gpio_leds(struct gpio_led *leds, int nr) {}
#endif


/* ------------------------------------------------------------------------- */

#if defined(CONFIG_LEDS)

#include <asm/leds.h>

/*
* Old ARM-specific LED framework; not fully functional when generic time is
* in use.
*/

static u8 at91_leds_cpu;
static u8 at91_leds_timer;


static inline void at91_led_on(unsigned int led)
{
        at91_set_gpio_value(led, 0);
}

static inline void at91_led_off(unsigned int led)
{
        at91_set_gpio_value(led, 1);
}

static inline void at91_led_toggle(unsigned int led)
{
        unsigned long is_off = at91_get_gpio_value(led);
        if (is_off)
                at91_led_on(led);
        else
                at91_led_off(led);
}


/*
* Handle LED events.
*/
static void at91_leds_event(led_event_t evt)
{
        unsigned long flags;

        local_irq_save(flags);

        switch(evt) {
        case led_start:                /* System startup */
                at91_led_on(at91_leds_cpu);
                break;

        case led_stop:                /* System stop / suspend */
                at91_led_off(at91_leds_cpu);
                break;

#ifdef CONFIG_LEDS_TIMER
        case led_timer:                /* Every 50 timer ticks */
                at91_led_toggle(at91_leds_timer);
                break;
#endif

#ifdef CONFIG_LEDS_CPU
        case led_idle_start:        /* Entering idle state */
                at91_led_off(at91_leds_cpu);
                break;

        case led_idle_end:        /* Exit idle state */
                at91_led_on(at91_leds_cpu);
                break;
#endif

        default:
                break;
        }

        local_irq_restore(flags);
}


static int __init leds_init(void)
{
        if (!at91_leds_timer || !at91_leds_cpu)
                return -ENODEV;

        leds_event = at91_leds_event;

        leds_event(led_start);
        return 0;
}

__initcall(leds_init);


void __init at91_init_leds(u8 cpu_led, u8 timer_led)
{
        /* Enable GPIO to access the LEDs */
        at91_set_gpio_output(cpu_led, 1);
        at91_set_gpio_output(timer_led, 1);

        at91_leds_cpu        = cpu_led;
        at91_leds_timer        = timer_led;
}

#else
void __init at91_init_leds(u8 cpu_led, u8 timer_led) {}
#endif

论坛徽章:
8
2015年辞旧岁徽章
日期:2015-03-03 16:54:15午马
日期:2015-02-04 12:00:07羊年新春福章
日期:2015-02-04 11:57:56双子座
日期:2014-12-02 11:44:59金牛座
日期:2014-10-08 16:47:08狮子座
日期:2014-08-29 13:37:46巳蛇
日期:2014-08-26 17:32:29NBA常规赛纪念章
日期:2015-05-04 22:32:03
12 [报告]
发表于 2008-09-01 11:29 |只看该作者
这就是个GPIO的驱动,LZ的问题没有体现出来啊???

论坛徽章:
0
13 [报告]
发表于 2008-10-18 08:07 |只看该作者

回复 #1 xiaoyao183 的帖子

LZ,我看了内核是没找到gpio提供给应用程序接口.自己改写了一个关于GPIO驱动,提供应用程序操作接口.Atmel9260 + linux-2.6.25.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP