-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathleds-it87-moxa-ngs.c
192 lines (163 loc) · 6.07 KB
/
leds-it87-moxa-ngs.c
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
// SPDX-License-Identifier: GPL-2.0-only
/*
* leds-it87.c - LED control with GPIOs for IT87XX Super I/O chips
* Copyright (C) 2020 Moxa, Inc.
* Remus Wu <[email protected]>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope 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.
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include "leds-it87-moxa-ngs.h"
#include <linux/dmi.h>
#include <linux/errno.h>
#include <linux/leds.h>
#include <linux/module.h>
#include <linux/platform_device.h>
/************************************************
* Database
************************************************/
#define IT87XX_GPIO_LED(_board_color_function, _gpio, _active_low, \
_default_state) \
{ \
.name = _board_color_function, \
.gpio = _gpio, \
.active_low = _active_low, \
.default_state = _default_state, \
}
#define IT87XX_GPIO_LED_TRIGGER(_board_color_function, _gpio, _active_low, \
_default_trigger) \
{ \
.name = _board_color_function, \
.gpio = _gpio, \
.active_low = _active_low, \
.default_state = LEDS_GPIO_DEFSTATE_OFF, \
.default_trigger = _default_trigger, \
}
/* V Series */
static struct gpio_led it87xx_leds_moxa_v_2201[] = {
IT87XX_GPIO_LED("V2201:GREEN:PRG1", 298, 1, LEDS_GPIO_DEFSTATE_OFF),
IT87XX_GPIO_LED("V2201:GREEN:PRG2", 299, 1, LEDS_GPIO_DEFSTATE_OFF),
IT87XX_GPIO_LED("V2201:RED:PRG3", 303, 1, LEDS_GPIO_DEFSTATE_OFF),
};
/* DA Series */
static struct gpio_led it87xx_leds_moxa_da_820c[] = {
IT87XX_GPIO_LED("DA820C:GREEN:PRG1", 496, 1, LEDS_GPIO_DEFSTATE_OFF),
IT87XX_GPIO_LED("DA820C:GREEN:PRG2", 497, 1, LEDS_GPIO_DEFSTATE_OFF),
IT87XX_GPIO_LED("DA820C:GREEN:PRG3", 498, 1, LEDS_GPIO_DEFSTATE_OFF),
IT87XX_GPIO_LED("DA820C:GREEN:PRG4", 499, 1, LEDS_GPIO_DEFSTATE_OFF),
IT87XX_GPIO_LED("DA820C:GREEN:PRG5", 500, 1, LEDS_GPIO_DEFSTATE_OFF),
IT87XX_GPIO_LED("DA820C:GREEN:PRG6", 501, 1, LEDS_GPIO_DEFSTATE_OFF),
IT87XX_GPIO_LED("DA820C:GREEN:PRG7", 502, 1, LEDS_GPIO_DEFSTATE_OFF),
IT87XX_GPIO_LED("DA820C:GREEN:PRG8", 503, 1, LEDS_GPIO_DEFSTATE_OFF),
};
static struct gpio_led it87xx_leds_moxa_da_682c[] = {
IT87XX_GPIO_LED("DA682C:GREEN:PRG1", 496, 1, LEDS_GPIO_DEFSTATE_OFF),
IT87XX_GPIO_LED("DA682C:GREEN:PRG2", 497, 1, LEDS_GPIO_DEFSTATE_OFF),
IT87XX_GPIO_LED("DA682C:GREEN:PRG3", 498, 1, LEDS_GPIO_DEFSTATE_OFF),
IT87XX_GPIO_LED("DA682C:GREEN:PRG4", 499, 1, LEDS_GPIO_DEFSTATE_OFF),
IT87XX_GPIO_LED("DA682C:GREEN:PRG5", 500, 1, LEDS_GPIO_DEFSTATE_OFF),
IT87XX_GPIO_LED("DA682C:GREEN:PRG6", 501, 1, LEDS_GPIO_DEFSTATE_OFF),
IT87XX_GPIO_LED("DA682C:GREEN:PRG7", 502, 1, LEDS_GPIO_DEFSTATE_OFF),
IT87XX_GPIO_LED("DA682C:GREEN:PRG8", 503, 1, LEDS_GPIO_DEFSTATE_OFF),
};
static struct gpio_led it87xx_leds_moxa_da_681c[] = {
IT87XX_GPIO_LED("DA681C:GREEN:PRG1", 496, 1, LEDS_GPIO_DEFSTATE_OFF),
IT87XX_GPIO_LED("DA681C:GREEN:PRG2", 497, 1, LEDS_GPIO_DEFSTATE_OFF),
IT87XX_GPIO_LED("DA681C:GREEN:PRG3", 498, 1, LEDS_GPIO_DEFSTATE_OFF),
IT87XX_GPIO_LED("DA681C:GREEN:PRG4", 499, 1, LEDS_GPIO_DEFSTATE_OFF),
IT87XX_GPIO_LED("DA681C:GREEN:PRG5", 500, 1, LEDS_GPIO_DEFSTATE_OFF),
IT87XX_GPIO_LED("DA681C:GREEN:PRG6", 501, 1, LEDS_GPIO_DEFSTATE_OFF),
IT87XX_GPIO_LED("DA681C:GREEN:PRG7", 502, 1, LEDS_GPIO_DEFSTATE_OFF),
IT87XX_GPIO_LED("DA681C:GREEN:PRG8", 503, 1, LEDS_GPIO_DEFSTATE_OFF),
};
/************************************************
* Initial
************************************************/
static struct gpio_led_platform_data it87xx_leds_pdata;
static void it87xx_leds_device_pdata_release(struct device *dev)
{
/* Needed to silence this message:
* Device 'xxx' does not have a release() function, it is broken and
* must be fixed
*/
}
static struct platform_device it87xx_leds_dev = {
.name = "leds-gpio",
.id = -1,
.dev = {
.release = it87xx_leds_device_pdata_release,
.platform_data = &it87xx_leds_pdata,
}
};
static struct platform_device *it87xx_leds_devs[] = {
&it87xx_leds_dev,
};
#define it87xx_set_pdata(dev_leds) \
do { \
it87xx_leds_pdata.leds = dev_leds; \
it87xx_leds_pdata.num_leds = ARRAY_SIZE(dev_leds); \
} while (0)
static __init const struct it87xx_board_type *it87xx_board_find(void)
{
const struct it87xx_board_type_list *device;
const char *model;
model = dmi_get_system_info(DMI_BOARD_NAME);
pr_debug("model = %s\n", model);
for (device = it87xx_board_type_list_models; device->model_name;
device++) {
pr_debug("device->model_name = %s\n", device->model_name);
if (!strcmp(model, device->model_name)) {
pr_info("Found board: %s\n", device->model_name);
return &device->board;
}
}
return it87xx_board_unknown;
}
static int __init it87xx_leds_init(void)
{
int ret;
const struct it87xx_board_type *device;
ret = request_module(IT87XX_GPIO_DRIVER);
if (ret)
return ret;
device = it87xx_board_find();
if (device->board == IT87XX_BOARD_UNKNOWN)
return -ENODEV;
switch (device->board) {
case IT87XX_BOARD_MOXA_V_2201:
it87xx_set_pdata(it87xx_leds_moxa_v_2201);
break;
case IT87XX_BOARD_MOXA_DA_820C:
it87xx_set_pdata(it87xx_leds_moxa_da_820c);
break;
case IT87XX_BOARD_MOXA_DA_682C:
it87xx_set_pdata(it87xx_leds_moxa_da_682c);
break;
case IT87XX_BOARD_MOXA_DA_681C:
it87xx_set_pdata(it87xx_leds_moxa_da_681c);
break;
default:
return -ENODEV;
}
return platform_add_devices(it87xx_leds_devs,
ARRAY_SIZE(it87xx_leds_devs));
}
static void __exit it87xx_leds_exit(void)
{
int i;
for (i = 0; i < ARRAY_SIZE(it87xx_leds_devs); i++)
platform_device_unregister(it87xx_leds_devs[i]);
}
module_init(it87xx_leds_init);
module_exit(it87xx_leds_exit);
MODULE_AUTHOR("Remus Wu <[email protected]>");
MODULE_DESCRIPTION("LED driver for GPIO IT87xx Super I/O chips");
MODULE_LICENSE("GPL");
MODULE_ALIAS("platform:leds-it87-moxa-ngs");