aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-ks8695/leds.c
blob: 4bd707547293189bcae0ce588ad30f2b05bf1d20 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
 * LED driver for KS8695-based boards.
 *
 * Copyright (C) Andrew Victor
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */
#include <linux/gpio.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>

#include <asm/leds.h>
#include <mach/devices.h>


static inline void ks8695_led_on(unsigned int led)
{
	gpio_set_value(led, 0);
}

static inline void ks8695_led_off(unsigned int led)
{
	gpio_set_value(led, 1);
}

static inline void ks8695_led_toggle(unsigned int led)
{
	unsigned long is_off = gpio_get_value(led);
	if (is_off)
		ks8695_led_on(led);
	else
		ks8695_led_off(led);
}


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

	local_irq_save(flags);

	switch(evt) {
	case led_start:		/* System startup */
		ks8695_led_on(ks8695_leds_cpu);
		break;

	case led_stop:		/* System stop / suspend */
		ks8695_led_off(ks8695_leds_cpu);
		break;

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

#ifdef CONFIG_LEDS_CPU
	case led_idle_start:	/* Entering idle state */
		ks8695_led_off(ks8695_leds_cpu);
		break;

	case led_idle_end:	/* Exit idle state */
		ks8695_led_on(ks8695_leds_cpu);
		break;
#endif

	default:
		break;
	}

	local_irq_restore(flags);
}


static int __init leds_init(void)
{
	if ((ks8695_leds_timer == -1) || (ks8695_leds_cpu == -1))
		return -ENODEV;

	leds_event = ks8695_leds_event;

	leds_event(led_start);
	return 0;
}

__initcall(leds_init);