~ubuntu-branches/ubuntu/maverick/u-boot-omap3/maverick

« back to all changes in this revision

Viewing changes to cpu/arm920t/ep93xx/led.c

  • Committer: Bazaar Package Importer
  • Author(s): Oliver Grawert
  • Date: 2010-03-22 15:06:23 UTC
  • Revision ID: james.westby@ubuntu.com-20100322150623-i21g8rgiyl5dohag
Tags: upstream-2010.3git20100315
ImportĀ upstreamĀ versionĀ 2010.3git20100315

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2010, 2009 Matthias Kaehlcke <matthias@kaehlcke.net>
 
3
 *
 
4
 * See file CREDITS for list of people who contributed to this
 
5
 * project.
 
6
 *
 
7
 * This program is free software; you can redistribute it and/or
 
8
 * modify it under the terms of the GNU General Public License as
 
9
 * published by the Free Software Foundation; either version 2 of
 
10
 * the License, or (at your option) any later version.
 
11
 *
 
12
 * This program is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
15
 * GNU General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU General Public License
 
18
 * along with this program; if not, write to the Free Software
 
19
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 
20
 * MA 02111-1307 USA
 
21
 */
 
22
 
 
23
#include <asm/io.h>
 
24
#include <asm/arch/ep93xx.h>
 
25
#include <config.h>
 
26
#include <status_led.h>
 
27
 
 
28
static uint8_t saved_state[2] = {STATUS_LED_OFF, STATUS_LED_OFF};
 
29
static uint32_t gpio_pin[2] = {1 << STATUS_LED_GREEN,
 
30
                               1 << STATUS_LED_RED};
 
31
 
 
32
inline void switch_LED_on(uint8_t led)
 
33
{
 
34
        register struct gpio_regs *gpio = (struct gpio_regs *)GPIO_BASE;
 
35
 
 
36
        writel(readl(&gpio->pedr) | gpio_pin[led], &gpio->pedr);
 
37
        saved_state[led] = STATUS_LED_ON;
 
38
}
 
39
 
 
40
inline void switch_LED_off(uint8_t led)
 
41
{
 
42
        register struct gpio_regs *gpio = (struct gpio_regs *)GPIO_BASE;
 
43
 
 
44
        writel(readl(&gpio->pedr) & ~gpio_pin[led], &gpio->pedr);
 
45
        saved_state[led] = STATUS_LED_OFF;
 
46
}
 
47
 
 
48
void red_LED_on(void)
 
49
{
 
50
        switch_LED_on(STATUS_LED_RED);
 
51
}
 
52
 
 
53
void red_LED_off(void)
 
54
{
 
55
        switch_LED_off(STATUS_LED_RED);
 
56
}
 
57
 
 
58
void green_LED_on(void)
 
59
{
 
60
        switch_LED_on(STATUS_LED_GREEN);
 
61
}
 
62
 
 
63
void green_LED_off(void)
 
64
{
 
65
        switch_LED_off(STATUS_LED_GREEN);
 
66
}
 
67
 
 
68
void __led_init(led_id_t mask, int state)
 
69
{
 
70
        __led_set(mask, state);
 
71
}
 
72
 
 
73
void __led_toggle(led_id_t mask)
 
74
{
 
75
        if (STATUS_LED_RED == mask) {
 
76
                if (STATUS_LED_ON == saved_state[STATUS_LED_RED])
 
77
                        red_LED_off();
 
78
                else
 
79
                        red_LED_on();
 
80
        } else if (STATUS_LED_GREEN == mask) {
 
81
                if (STATUS_LED_ON == saved_state[STATUS_LED_GREEN])
 
82
                        green_LED_off();
 
83
                else
 
84
                        green_LED_on();
 
85
        }
 
86
}
 
87
 
 
88
void __led_set(led_id_t mask, int state)
 
89
{
 
90
        if (STATUS_LED_RED == mask) {
 
91
                if (STATUS_LED_ON == state)
 
92
                        red_LED_on();
 
93
                else
 
94
                        red_LED_off();
 
95
        } else if (STATUS_LED_GREEN == mask) {
 
96
                if (STATUS_LED_ON == state)
 
97
                        green_LED_on();
 
98
                else
 
99
                        green_LED_off();
 
100
        }
 
101
}