summaryrefslogtreecommitdiffstats
path: root/target/linux/ifxmips/files/drivers/char/danube_led.c
blob: b0b8e82899dea5aa319ab3895c2d821330ba7d68 (plain)
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
93
94
95
96
97
98
99
100
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/*
 *   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.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
 *
 *   Copyright (C) 2006 infineon
 *   Copyright (C) 2007 John Crispin <blogic@openwrt.org> 
 *
 */

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/version.h>
#include <linux/types.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <asm/uaccess.h>
#include <asm/unistd.h>
#include <linux/errno.h>
#include <asm/ifxmips/ifxmips.h>
#include <asm/ifxmips/ifxmips_gpio.h>
#include <asm/ifxmips/ifxmips_pmu.h>

#define IFXMIPS_LED_CLK_EDGE				IFXMIPS_LED_FALLING
//#define IFXMIPS_LED_CLK_EDGE			IFXMIPS_LED_RISING

#define IFXMIPS_LED_SPEED				IFXMIPS_LED_8HZ

#define IFXMIPS_LED_GPIO_PORT	0

static int ifxmips_led_major;

void
ifxmips_led_set (unsigned int led)
{
	led &= 0xffffff;
	writel(readl(IFXMIPS_LED_CPU0) | led, IFXMIPS_LED_CPU0);
}
EXPORT_SYMBOL(ifxmips_led_set);

void
ifxmips_led_clear (unsigned int led)
{
	led = ~(led & 0xffffff);
	writel(readl(IFXMIPS_LED_CPU0) & led, IFXMIPS_LED_CPU0);
}
EXPORT_SYMBOL(ifxmips_led_clear);

void
ifxmips_led_blink_set (unsigned int led)
{
	led &= 0xffffff;
	writel(readl(IFXMIPS_LED_CON0) | led, IFXMIPS_LED_CON0);
}
EXPORT_SYMBOL(ifxmips_led_blink_set);

void
ifxmips_led_blink_clear (unsigned int led)
{
	led = ~(led & 0xffffff);
	writel(readl(IFXMIPS_LED_CON0) & led, IFXMIPS_LED_CON0);
}
EXPORT_SYMBOL(ifxmips_led_blink_clear);

void
ifxmips_led_setup_gpio (void)
{
	int i = 0;

	/* we need to setup pins SH,D,ST (4,5,6) */
	for (i = 4; i < 7; i++)
	{
		ifxmips_port_set_altsel0(IFXMIPS_LED_GPIO_PORT, i);
		ifxmips_port_clear_altsel1(IFXMIPS_LED_GPIO_PORT, i);
		ifxmips_port_set_dir_out(IFXMIPS_LED_GPIO_PORT, i);
		ifxmips_port_set_open_drain(IFXMIPS_LED_GPIO_PORT, i);
	}
}

static int
led_ioctl (struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
{
	int ret = -EINVAL;

	switch ( cmd )
	{
	}

	return ret;
}

static int
led_open (struct inode *inode, struct file *file)
{
	return 0;
}

static int
led_release (struct inode *inode, struct file *file)
{
	return 0;
}

static struct file_operations ifxmips_led_fops = {
	.owner = THIS_MODULE,
	.ioctl = led_ioctl,
	.open = led_open,
	.release = led_release
};


/*
Map for LED on reference board
	WLAN_READ     LED11   OUT1    15
	WARNING       LED12   OUT2    14
	FXS1_LINK     LED13   OUT3    13
	FXS2_LINK     LED14   OUT4    12
	FXO_ACT       LED15   OUT5    11
	USB_LINK      LED16   OUT6    10
	ADSL2_LINK    LED19   OUT7    9
	BT_LINK       LED17   OUT8    8
	SD_LINK       LED20   OUT9    7
	ADSL2_TRAFFIC LED31   OUT16   0
Map for hardware relay on reference board
	USB Power On          OUT11   5
	RELAY                 OUT12   4
*/


int __init
ifxmips_led_init (void)
{
	int ret = 0;

	ifxmips_led_setup_gpio();

	writel(0, IFXMIPS_LED_AR);
	writel(0, IFXMIPS_LED_CPU0);
	writel(0, IFXMIPS_LED_CPU1);
	writel(LED_CON0_SWU, IFXMIPS_LED_CON0);
	writel(0, IFXMIPS_LED_CON1);

	/* setup the clock edge that the shift register is triggered on */
	writel(readl(IFXMIPS_LED_CON0) & ~IFXMIPS_LED_EDGE_MASK, IFXMIPS_LED_CON0);
	writel(readl(IFXMIPS_LED_CON0) | IFXMIPS_LED_CLK_EDGE, IFXMIPS_LED_CON0);

	/* per default leds 15-0 are set */
	writel(IFXMIPS_LED_GROUP1 | IFXMIPS_LED_GROUP0, IFXMIPS_LED_CON1);

	/* leds are update periodically by the FPID */
	writel(readl(IFXMIPS_LED_CON1) & ~IFXMIPS_LED_UPD_MASK, IFXMIPS_LED_CON1);
	writel(readl(IFXMIPS_LED_CON1) | IFXMIPS_LED_UPD_SRC_FPI, IFXMIPS_LED_CON1);

	/* set led update speed */
	writel(readl(IFXMIPS_LED_CON1) & ~IFXMIPS_LED_MASK, IFXMIPS_LED_CON1);
	writel(readl(IFXMIPS_LED_CON1) | IFXMIPS_LED_SPEED, IFXMIPS_LED_CON1);

	/* adsl 0 and 1 leds are updated by the arc */
	writel(readl(IFXMIPS_LED_CON0) | IFXMIPS_LED_ADSL_SRC, IFXMIPS_LED_CON0);

	/* per default, the leds are turned on */
	ifxmips_pmu_enable(IFXMIPS_PMU_PWDCR_LED);

	ifxmips_led_major = register_chrdev(0, "ifxmips_led", &ifxmips_led_fops);

	if (!ifxmips_led_major)
	{
		printk("ifxmips_led: Error! Could not register device. %d\n", ifxmips_led_major);
		ret = -EINVAL;

		goto out;
	}

	printk(KERN_INFO "ifxmips_led : device registered on major %d\n", ifxmips_led_major);

out:
	return ret;
}

void __exit
ifxmips_led_exit (void)
{
	unregister_chrdev(ifxmips_led_major, "ifxmips_led");
}

module_init(ifxmips_led_init);
module_exit(ifxmips_led_exit);