Blame view

arch/arm/mach-at91/leds.c 3.6 KB
cc2832a13   Andrew Victor   [ARM] 3393/2: AT9...
1
2
3
4
5
6
7
8
9
10
  /*
   * 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.
  */
2f8163baa   Russell King   ARM: gpio: conver...
11
  #include <linux/gpio.h>
cc2832a13   Andrew Victor   [ARM] 3393/2: AT9...
12
13
14
  #include <linux/kernel.h>
  #include <linux/module.h>
  #include <linux/init.h>
a7307bf22   Andrew Victor   [ARM] 5259/2: [AT...
15
  #include <linux/platform_device.h>
cc2832a13   Andrew Victor   [ARM] 3393/2: AT9...
16

a09e64fbc   Russell King   [ARM] Move includ...
17
  #include <mach/board.h>
cc2832a13   Andrew Victor   [ARM] 3393/2: AT9...
18

a04ff1af9   Andrew Victor   [ARM] 4758/1: [AT...
19
20
21
  /* ------------------------------------------------------------------------- */
  
  #if defined(CONFIG_NEW_LEDS)
a04ff1af9   Andrew Victor   [ARM] 4758/1: [AT...
22
23
24
25
26
  /*
   * New cross-platform LED support.
   */
  
  static struct gpio_led_platform_data led_data;
791ccf2e4   Andrew Victor   [ARM] 5267/1: [AT...
27
  static struct platform_device at91_gpio_leds_device = {
a04ff1af9   Andrew Victor   [ARM] 4758/1: [AT...
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
  	.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[i].gpio, leds[i].active_low);
  
  	led_data.leds = leds;
  	led_data.num_leds = nr;
791ccf2e4   Andrew Victor   [ARM] 5267/1: [AT...
45
  	platform_device_register(&at91_gpio_leds_device);
a04ff1af9   Andrew Victor   [ARM] 4758/1: [AT...
46
47
48
49
50
51
52
53
  }
  
  #else
  void __init at91_gpio_leds(struct gpio_led *leds, int nr) {}
  #endif
  
  
  /* ------------------------------------------------------------------------- */
a7307bf22   Andrew Victor   [ARM] 5259/2: [AT...
54
55
56
57
58
59
60
  #if defined (CONFIG_LEDS_ATMEL_PWM)
  
  /*
   * PWM Leds
   */
  
  static struct gpio_led_platform_data pwm_led_data;
791ccf2e4   Andrew Victor   [ARM] 5267/1: [AT...
61
  static struct platform_device at91_pwm_leds_device = {
a7307bf22   Andrew Victor   [ARM] 5259/2: [AT...
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
  	.name			= "leds-atmel-pwm",
  	.id			= -1,
  	.dev.platform_data	= &pwm_led_data,
  };
  
  void __init at91_pwm_leds(struct gpio_led *leds, int nr)
  {
  	int i;
  	u32 pwm_mask = 0;
  
  	if (!nr)
  		return;
  
  	for (i = 0; i < nr; i++)
  		pwm_mask |= (1 << leds[i].gpio);
  
  	pwm_led_data.leds = leds;
  	pwm_led_data.num_leds = nr;
  
  	at91_add_device_pwm(pwm_mask);
791ccf2e4   Andrew Victor   [ARM] 5267/1: [AT...
82
  	platform_device_register(&at91_pwm_leds_device);
a7307bf22   Andrew Victor   [ARM] 5259/2: [AT...
83
84
85
86
87
88
89
  }
  #else
  void __init at91_pwm_leds(struct gpio_led *leds, int nr){}
  #endif
  
  
  /* ------------------------------------------------------------------------- */
a04ff1af9   Andrew Victor   [ARM] 4758/1: [AT...
90
91
92
93
94
95
96
97
98
99
100
  #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;
cc2832a13   Andrew Victor   [ARM] 3393/2: AT9...
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
  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;
cc2832a13   Andrew Victor   [ARM] 3393/2: AT9...
167
168
169
170
171
172
173
  	leds_event = at91_leds_event;
  
  	leds_event(led_start);
  	return 0;
  }
  
  __initcall(leds_init);
a04ff1af9   Andrew Victor   [ARM] 4758/1: [AT...
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
  
  
  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