blob: 5d37ac15f2fbf5d9eb762e44436d400c1ec208bc [file] [log] [blame]
Tom Rix83ae6982009-05-31 12:44:39 +02001/*
2 * Copyright (c) 2009 Wind River Systems, Inc.
3 * Tom Rix <Tom.Rix@windriver.com>
4 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Tom Rix83ae6982009-05-31 12:44:39 +02006 */
7#include <common.h>
8#include <status_led.h>
9#include <asm/arch/cpu.h>
10#include <asm/io.h>
11#include <asm/arch/sys_proto.h>
Sanjeev Premi84c3b632011-09-08 10:51:01 -040012#include <asm/gpio.h>
Tom Rix83ae6982009-05-31 12:44:39 +020013
14static unsigned int saved_state[2] = {STATUS_LED_OFF, STATUS_LED_OFF};
15
16/*
17 * GPIO LEDs
18 * 173 red
19 * 154 blue
20 * 61 blue2
21 */
22#define ZOOM2_LED_RED 173
23#define ZOOM2_LED_BLUE 154
24#define ZOOM2_LED_BLUE2 61
25
Jason Kridner2d3be7c2011-09-04 14:40:16 -040026void red_led_off(void)
Tom Rix83ae6982009-05-31 12:44:39 +020027{
28 /* red */
Sanjeev Premi84c3b632011-09-08 10:51:01 -040029 if (!gpio_request(ZOOM2_LED_RED, "")) {
30 gpio_direction_output(ZOOM2_LED_RED, 0);
31 gpio_set_value(ZOOM2_LED_RED, 0);
Tom Rix83ae6982009-05-31 12:44:39 +020032 }
33 saved_state[STATUS_LED_RED] = STATUS_LED_OFF;
34}
35
Jason Kridner2d3be7c2011-09-04 14:40:16 -040036void blue_led_off(void)
Tom Rix83ae6982009-05-31 12:44:39 +020037{
38 /* blue */
Sanjeev Premi84c3b632011-09-08 10:51:01 -040039 if (!gpio_request(ZOOM2_LED_BLUE, "")) {
40 gpio_direction_output(ZOOM2_LED_BLUE, 0);
41 gpio_set_value(ZOOM2_LED_BLUE, 0);
Tom Rix83ae6982009-05-31 12:44:39 +020042 }
43
44 /* blue 2 */
Sanjeev Premi84c3b632011-09-08 10:51:01 -040045 if (!gpio_request(ZOOM2_LED_BLUE2, "")) {
46 gpio_direction_output(ZOOM2_LED_BLUE2, 0);
47 gpio_set_value(ZOOM2_LED_BLUE2, 0);
Tom Rix83ae6982009-05-31 12:44:39 +020048 }
49 saved_state[STATUS_LED_BLUE] = STATUS_LED_OFF;
50}
51
Jason Kridner2d3be7c2011-09-04 14:40:16 -040052void red_led_on(void)
Tom Rix83ae6982009-05-31 12:44:39 +020053{
Jason Kridner2d3be7c2011-09-04 14:40:16 -040054 blue_led_off();
Tom Rix83ae6982009-05-31 12:44:39 +020055
56 /* red */
Sanjeev Premi84c3b632011-09-08 10:51:01 -040057 if (!gpio_request(ZOOM2_LED_RED, "")) {
58 gpio_direction_output(ZOOM2_LED_RED, 0);
59 gpio_set_value(ZOOM2_LED_RED, 1);
Tom Rix83ae6982009-05-31 12:44:39 +020060 }
61 saved_state[STATUS_LED_RED] = STATUS_LED_ON;
62}
63
Jason Kridner2d3be7c2011-09-04 14:40:16 -040064void blue_led_on(void)
Tom Rix83ae6982009-05-31 12:44:39 +020065{
Jason Kridner2d3be7c2011-09-04 14:40:16 -040066 red_led_off();
Tom Rix83ae6982009-05-31 12:44:39 +020067
68 /* blue */
Sanjeev Premi84c3b632011-09-08 10:51:01 -040069 if (!gpio_request(ZOOM2_LED_BLUE, "")) {
70 gpio_direction_output(ZOOM2_LED_BLUE, 0);
71 gpio_set_value(ZOOM2_LED_BLUE, 1);
Tom Rix83ae6982009-05-31 12:44:39 +020072 }
73
74 /* blue 2 */
Sanjeev Premi84c3b632011-09-08 10:51:01 -040075 if (!gpio_request(ZOOM2_LED_BLUE2, "")) {
76 gpio_direction_output(ZOOM2_LED_BLUE2, 0);
77 gpio_set_value(ZOOM2_LED_BLUE2, 1);
Tom Rix83ae6982009-05-31 12:44:39 +020078 }
79
80 saved_state[STATUS_LED_BLUE] = STATUS_LED_ON;
81}
82
83void __led_init (led_id_t mask, int state)
84{
85 __led_set (mask, state);
86}
87
88void __led_toggle (led_id_t mask)
89{
90 if (STATUS_LED_BLUE == mask) {
91 if (STATUS_LED_ON == saved_state[STATUS_LED_BLUE])
Jason Kridner2d3be7c2011-09-04 14:40:16 -040092 blue_led_off();
Tom Rix83ae6982009-05-31 12:44:39 +020093 else
Jason Kridner2d3be7c2011-09-04 14:40:16 -040094 blue_led_on();
Tom Rix83ae6982009-05-31 12:44:39 +020095 } else if (STATUS_LED_RED == mask) {
96 if (STATUS_LED_ON == saved_state[STATUS_LED_RED])
Jason Kridner2d3be7c2011-09-04 14:40:16 -040097 red_led_off();
Tom Rix83ae6982009-05-31 12:44:39 +020098 else
Jason Kridner2d3be7c2011-09-04 14:40:16 -040099 red_led_on();
Tom Rix83ae6982009-05-31 12:44:39 +0200100 }
101}
102
103void __led_set (led_id_t mask, int state)
104{
105 if (STATUS_LED_BLUE == mask) {
106 if (STATUS_LED_ON == state)
Jason Kridner2d3be7c2011-09-04 14:40:16 -0400107 blue_led_on();
Tom Rix83ae6982009-05-31 12:44:39 +0200108 else
Jason Kridner2d3be7c2011-09-04 14:40:16 -0400109 blue_led_off();
Tom Rix83ae6982009-05-31 12:44:39 +0200110 } else if (STATUS_LED_RED == mask) {
111 if (STATUS_LED_ON == state)
Jason Kridner2d3be7c2011-09-04 14:40:16 -0400112 red_led_on();
Tom Rix83ae6982009-05-31 12:44:39 +0200113 else
Jason Kridner2d3be7c2011-09-04 14:40:16 -0400114 red_led_off();
Tom Rix83ae6982009-05-31 12:44:39 +0200115 }
116}