This source file includes following definitions.
- apu1_led_brightness_set
- apu_led_config
- apu_led_probe
- apu_led_init
- apu_led_exit
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 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
35
36 #include <linux/dmi.h>
37 #include <linux/err.h>
38 #include <linux/init.h>
39 #include <linux/io.h>
40 #include <linux/kernel.h>
41 #include <linux/leds.h>
42 #include <linux/module.h>
43 #include <linux/platform_device.h>
44
45 #define APU1_FCH_ACPI_MMIO_BASE 0xFED80000
46 #define APU1_FCH_GPIO_BASE (APU1_FCH_ACPI_MMIO_BASE + 0x01BD)
47 #define APU1_LEDON 0x08
48 #define APU1_LEDOFF 0xC8
49 #define APU1_NUM_GPIO 3
50 #define APU1_IOSIZE sizeof(u8)
51
52
53 struct apu_param {
54 void __iomem *addr;
55 };
56
57
58 struct apu_led_priv {
59 struct led_classdev cdev;
60 struct apu_param param;
61 };
62 #define cdev_to_priv(c) container_of(c, struct apu_led_priv, cdev)
63
64
65 struct apu_led_profile {
66 const char *name;
67 enum led_brightness brightness;
68 unsigned long offset;
69 };
70
71 struct apu_led_pdata {
72 struct platform_device *pdev;
73 struct apu_led_priv *pled;
74 spinlock_t lock;
75 };
76
77 static struct apu_led_pdata *apu_led;
78
79 static const struct apu_led_profile apu1_led_profile[] = {
80 { "apu:green:1", LED_ON, APU1_FCH_GPIO_BASE + 0 * APU1_IOSIZE },
81 { "apu:green:2", LED_OFF, APU1_FCH_GPIO_BASE + 1 * APU1_IOSIZE },
82 { "apu:green:3", LED_OFF, APU1_FCH_GPIO_BASE + 2 * APU1_IOSIZE },
83 };
84
85 static const struct dmi_system_id apu_led_dmi_table[] __initconst = {
86 {
87 .ident = "apu",
88 .matches = {
89 DMI_MATCH(DMI_SYS_VENDOR, "PC Engines"),
90 DMI_MATCH(DMI_PRODUCT_NAME, "APU")
91 }
92 },
93 {}
94 };
95 MODULE_DEVICE_TABLE(dmi, apu_led_dmi_table);
96
97 static void apu1_led_brightness_set(struct led_classdev *led, enum led_brightness value)
98 {
99 struct apu_led_priv *pled = cdev_to_priv(led);
100
101 spin_lock(&apu_led->lock);
102 iowrite8(value ? APU1_LEDON : APU1_LEDOFF, pled->param.addr);
103 spin_unlock(&apu_led->lock);
104 }
105
106 static int apu_led_config(struct device *dev, struct apu_led_pdata *apuld)
107 {
108 int i;
109 int err;
110
111 apu_led->pled = devm_kcalloc(dev,
112 ARRAY_SIZE(apu1_led_profile), sizeof(struct apu_led_priv),
113 GFP_KERNEL);
114
115 if (!apu_led->pled)
116 return -ENOMEM;
117
118 for (i = 0; i < ARRAY_SIZE(apu1_led_profile); i++) {
119 struct apu_led_priv *pled = &apu_led->pled[i];
120 struct led_classdev *led_cdev = &pled->cdev;
121
122 led_cdev->name = apu1_led_profile[i].name;
123 led_cdev->brightness = apu1_led_profile[i].brightness;
124 led_cdev->max_brightness = 1;
125 led_cdev->flags = LED_CORE_SUSPENDRESUME;
126 led_cdev->brightness_set = apu1_led_brightness_set;
127
128 pled->param.addr = devm_ioremap(dev,
129 apu1_led_profile[i].offset, APU1_IOSIZE);
130 if (!pled->param.addr) {
131 err = -ENOMEM;
132 goto error;
133 }
134
135 err = led_classdev_register(dev, led_cdev);
136 if (err)
137 goto error;
138
139 apu1_led_brightness_set(led_cdev, apu1_led_profile[i].brightness);
140 }
141
142 return 0;
143
144 error:
145 while (i-- > 0)
146 led_classdev_unregister(&apu_led->pled[i].cdev);
147
148 return err;
149 }
150
151 static int __init apu_led_probe(struct platform_device *pdev)
152 {
153 apu_led = devm_kzalloc(&pdev->dev, sizeof(*apu_led), GFP_KERNEL);
154
155 if (!apu_led)
156 return -ENOMEM;
157
158 apu_led->pdev = pdev;
159
160 spin_lock_init(&apu_led->lock);
161 return apu_led_config(&pdev->dev, apu_led);
162 }
163
164 static struct platform_driver apu_led_driver = {
165 .driver = {
166 .name = KBUILD_MODNAME,
167 },
168 };
169
170 static int __init apu_led_init(void)
171 {
172 struct platform_device *pdev;
173 int err;
174
175 if (!(dmi_match(DMI_SYS_VENDOR, "PC Engines") &&
176 dmi_match(DMI_PRODUCT_NAME, "APU"))) {
177 pr_err("No PC Engines APUv1 board detected. For APUv2,3 support, enable CONFIG_PCENGINES_APU2\n");
178 return -ENODEV;
179 }
180
181 pdev = platform_device_register_simple(KBUILD_MODNAME, -1, NULL, 0);
182 if (IS_ERR(pdev)) {
183 pr_err("Device allocation failed\n");
184 return PTR_ERR(pdev);
185 }
186
187 err = platform_driver_probe(&apu_led_driver, apu_led_probe);
188 if (err) {
189 pr_err("Probe platform driver failed\n");
190 platform_device_unregister(pdev);
191 }
192
193 return err;
194 }
195
196 static void __exit apu_led_exit(void)
197 {
198 int i;
199
200 for (i = 0; i < ARRAY_SIZE(apu1_led_profile); i++)
201 led_classdev_unregister(&apu_led->pled[i].cdev);
202
203 platform_device_unregister(apu_led->pdev);
204 platform_driver_unregister(&apu_led_driver);
205 }
206
207 module_init(apu_led_init);
208 module_exit(apu_led_exit);
209
210 MODULE_AUTHOR("Alan Mizrahi");
211 MODULE_DESCRIPTION("PC Engines APU1 front LED driver");
212 MODULE_LICENSE("GPL v2");
213 MODULE_ALIAS("platform:leds_apu");