Loading...
1/*
2 * intel_oaktrail.c - Intel OakTrail Platform support.
3 *
4 * Copyright (C) 2010-2011 Intel Corporation
5 * Author: Yin Kangkai (kangkai.yin@intel.com)
6 *
7 * based on Compal driver, Copyright (C) 2008 Cezary Jackiewicz
8 * <cezary.jackiewicz (at) gmail.com>, based on MSI driver
9 * Copyright (C) 2006 Lennart Poettering <mzxreary (at) 0pointer (dot) de>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 * 02110-1301, USA.
25 *
26 * This driver does below things:
27 * 1. registers itself in the Linux backlight control in
28 * /sys/class/backlight/intel_oaktrail/
29 *
30 * 2. registers in the rfkill subsystem here: /sys/class/rfkill/rfkillX/
31 * for these components: wifi, bluetooth, wwan (3g), gps
32 *
33 * This driver might work on other products based on Oaktrail. If you
34 * want to try it you can pass force=1 as argument to the module which
35 * will force it to load even when the DMI data doesn't identify the
36 * product as compatible.
37 */
38
39#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
40
41#include <linux/module.h>
42#include <linux/kernel.h>
43#include <linux/init.h>
44#include <linux/acpi.h>
45#include <linux/fb.h>
46#include <linux/mutex.h>
47#include <linux/err.h>
48#include <linux/i2c.h>
49#include <linux/backlight.h>
50#include <linux/platform_device.h>
51#include <linux/dmi.h>
52#include <linux/rfkill.h>
53#include <acpi/acpi_bus.h>
54#include <acpi/acpi_drivers.h>
55
56
57#define DRIVER_NAME "intel_oaktrail"
58#define DRIVER_VERSION "0.4ac1"
59
60/*
61 * This is the devices status address in EC space, and the control bits
62 * definition:
63 *
64 * (1 << 0): Camera enable/disable, RW.
65 * (1 << 1): Bluetooth enable/disable, RW.
66 * (1 << 2): GPS enable/disable, RW.
67 * (1 << 3): WiFi enable/disable, RW.
68 * (1 << 4): WWAN (3G) enable/disalbe, RW.
69 * (1 << 5): Touchscreen enable/disable, Read Only.
70 */
71#define OT_EC_DEVICE_STATE_ADDRESS 0xD6
72
73#define OT_EC_CAMERA_MASK (1 << 0)
74#define OT_EC_BT_MASK (1 << 1)
75#define OT_EC_GPS_MASK (1 << 2)
76#define OT_EC_WIFI_MASK (1 << 3)
77#define OT_EC_WWAN_MASK (1 << 4)
78#define OT_EC_TS_MASK (1 << 5)
79
80/*
81 * This is the address in EC space and commands used to control LCD backlight:
82 *
83 * Two steps needed to change the LCD backlight:
84 * 1. write the backlight percentage into OT_EC_BL_BRIGHTNESS_ADDRESS;
85 * 2. write OT_EC_BL_CONTROL_ON_DATA into OT_EC_BL_CONTROL_ADDRESS.
86 *
87 * To read the LCD back light, just read out the value from
88 * OT_EC_BL_BRIGHTNESS_ADDRESS.
89 *
90 * LCD backlight brightness range: 0 - 100 (OT_EC_BL_BRIGHTNESS_MAX)
91 */
92#define OT_EC_BL_BRIGHTNESS_ADDRESS 0x44
93#define OT_EC_BL_BRIGHTNESS_MAX 100
94#define OT_EC_BL_CONTROL_ADDRESS 0x3A
95#define OT_EC_BL_CONTROL_ON_DATA 0x1A
96
97
98static int force;
99module_param(force, bool, 0);
100MODULE_PARM_DESC(force, "Force driver load, ignore DMI data");
101
102static struct platform_device *oaktrail_device;
103static struct backlight_device *oaktrail_bl_device;
104static struct rfkill *bt_rfkill;
105static struct rfkill *gps_rfkill;
106static struct rfkill *wifi_rfkill;
107static struct rfkill *wwan_rfkill;
108
109
110/* rfkill */
111static int oaktrail_rfkill_set(void *data, bool blocked)
112{
113 u8 value;
114 u8 result;
115 unsigned long radio = (unsigned long) data;
116
117 ec_read(OT_EC_DEVICE_STATE_ADDRESS, &result);
118
119 if (!blocked)
120 value = (u8) (result | radio);
121 else
122 value = (u8) (result & ~radio);
123
124 ec_write(OT_EC_DEVICE_STATE_ADDRESS, value);
125
126 return 0;
127}
128
129static const struct rfkill_ops oaktrail_rfkill_ops = {
130 .set_block = oaktrail_rfkill_set,
131};
132
133static struct rfkill *oaktrail_rfkill_new(char *name, enum rfkill_type type,
134 unsigned long mask)
135{
136 struct rfkill *rfkill_dev;
137 u8 value;
138 int err;
139
140 rfkill_dev = rfkill_alloc(name, &oaktrail_device->dev, type,
141 &oaktrail_rfkill_ops, (void *)mask);
142 if (!rfkill_dev)
143 return ERR_PTR(-ENOMEM);
144
145 ec_read(OT_EC_DEVICE_STATE_ADDRESS, &value);
146 rfkill_init_sw_state(rfkill_dev, (value & mask) != 1);
147
148 err = rfkill_register(rfkill_dev);
149 if (err) {
150 rfkill_destroy(rfkill_dev);
151 return ERR_PTR(err);
152 }
153
154 return rfkill_dev;
155}
156
157static inline void __oaktrail_rfkill_cleanup(struct rfkill *rf)
158{
159 if (rf) {
160 rfkill_unregister(rf);
161 rfkill_destroy(rf);
162 }
163}
164
165static void oaktrail_rfkill_cleanup(void)
166{
167 __oaktrail_rfkill_cleanup(wifi_rfkill);
168 __oaktrail_rfkill_cleanup(bt_rfkill);
169 __oaktrail_rfkill_cleanup(gps_rfkill);
170 __oaktrail_rfkill_cleanup(wwan_rfkill);
171}
172
173static int oaktrail_rfkill_init(void)
174{
175 int ret;
176
177 wifi_rfkill = oaktrail_rfkill_new("oaktrail-wifi",
178 RFKILL_TYPE_WLAN,
179 OT_EC_WIFI_MASK);
180 if (IS_ERR(wifi_rfkill)) {
181 ret = PTR_ERR(wifi_rfkill);
182 wifi_rfkill = NULL;
183 goto cleanup;
184 }
185
186 bt_rfkill = oaktrail_rfkill_new("oaktrail-bluetooth",
187 RFKILL_TYPE_BLUETOOTH,
188 OT_EC_BT_MASK);
189 if (IS_ERR(bt_rfkill)) {
190 ret = PTR_ERR(bt_rfkill);
191 bt_rfkill = NULL;
192 goto cleanup;
193 }
194
195 gps_rfkill = oaktrail_rfkill_new("oaktrail-gps",
196 RFKILL_TYPE_GPS,
197 OT_EC_GPS_MASK);
198 if (IS_ERR(gps_rfkill)) {
199 ret = PTR_ERR(gps_rfkill);
200 gps_rfkill = NULL;
201 goto cleanup;
202 }
203
204 wwan_rfkill = oaktrail_rfkill_new("oaktrail-wwan",
205 RFKILL_TYPE_WWAN,
206 OT_EC_WWAN_MASK);
207 if (IS_ERR(wwan_rfkill)) {
208 ret = PTR_ERR(wwan_rfkill);
209 wwan_rfkill = NULL;
210 goto cleanup;
211 }
212
213 return 0;
214
215cleanup:
216 oaktrail_rfkill_cleanup();
217 return ret;
218}
219
220
221/* backlight */
222static int get_backlight_brightness(struct backlight_device *b)
223{
224 u8 value;
225 ec_read(OT_EC_BL_BRIGHTNESS_ADDRESS, &value);
226
227 return value;
228}
229
230static int set_backlight_brightness(struct backlight_device *b)
231{
232 u8 percent = (u8) b->props.brightness;
233 if (percent < 0 || percent > OT_EC_BL_BRIGHTNESS_MAX)
234 return -EINVAL;
235
236 ec_write(OT_EC_BL_BRIGHTNESS_ADDRESS, percent);
237 ec_write(OT_EC_BL_CONTROL_ADDRESS, OT_EC_BL_CONTROL_ON_DATA);
238
239 return 0;
240}
241
242static const struct backlight_ops oaktrail_bl_ops = {
243 .get_brightness = get_backlight_brightness,
244 .update_status = set_backlight_brightness,
245};
246
247static int oaktrail_backlight_init(void)
248{
249 struct backlight_device *bd;
250 struct backlight_properties props;
251
252 memset(&props, 0, sizeof(struct backlight_properties));
253 props.type = BACKLIGHT_PLATFORM;
254 props.max_brightness = OT_EC_BL_BRIGHTNESS_MAX;
255 bd = backlight_device_register(DRIVER_NAME,
256 &oaktrail_device->dev, NULL,
257 &oaktrail_bl_ops,
258 &props);
259
260 if (IS_ERR(bd)) {
261 oaktrail_bl_device = NULL;
262 pr_warning("Unable to register backlight device\n");
263 return PTR_ERR(bd);
264 }
265
266 oaktrail_bl_device = bd;
267
268 bd->props.brightness = get_backlight_brightness(bd);
269 bd->props.power = FB_BLANK_UNBLANK;
270 backlight_update_status(bd);
271
272 return 0;
273}
274
275static void oaktrail_backlight_exit(void)
276{
277 if (oaktrail_bl_device)
278 backlight_device_unregister(oaktrail_bl_device);
279}
280
281static int __devinit oaktrail_probe(struct platform_device *pdev)
282{
283 return 0;
284}
285
286static int __devexit oaktrail_remove(struct platform_device *pdev)
287{
288 return 0;
289}
290
291static struct platform_driver oaktrail_driver = {
292 .driver = {
293 .name = DRIVER_NAME,
294 .owner = THIS_MODULE,
295 },
296 .probe = oaktrail_probe,
297 .remove = __devexit_p(oaktrail_remove)
298};
299
300static int dmi_check_cb(const struct dmi_system_id *id)
301{
302 pr_info("Identified model '%s'\n", id->ident);
303 return 0;
304}
305
306static struct dmi_system_id __initdata oaktrail_dmi_table[] = {
307 {
308 .ident = "OakTrail platform",
309 .matches = {
310 DMI_MATCH(DMI_PRODUCT_NAME, "OakTrail platform"),
311 },
312 .callback = dmi_check_cb
313 },
314 { }
315};
316
317static int __init oaktrail_init(void)
318{
319 int ret;
320
321 if (acpi_disabled) {
322 pr_err("ACPI needs to be enabled for this driver to work!\n");
323 return -ENODEV;
324 }
325
326 if (!force && !dmi_check_system(oaktrail_dmi_table)) {
327 pr_err("Platform not recognized (You could try the module's force-parameter)");
328 return -ENODEV;
329 }
330
331 ret = platform_driver_register(&oaktrail_driver);
332 if (ret) {
333 pr_warning("Unable to register platform driver\n");
334 goto err_driver_reg;
335 }
336
337 oaktrail_device = platform_device_alloc(DRIVER_NAME, -1);
338 if (!oaktrail_device) {
339 pr_warning("Unable to allocate platform device\n");
340 ret = -ENOMEM;
341 goto err_device_alloc;
342 }
343
344 ret = platform_device_add(oaktrail_device);
345 if (ret) {
346 pr_warning("Unable to add platform device\n");
347 goto err_device_add;
348 }
349
350 if (!acpi_video_backlight_support()) {
351 ret = oaktrail_backlight_init();
352 if (ret)
353 goto err_backlight;
354
355 } else
356 pr_info("Backlight controlled by ACPI video driver\n");
357
358 ret = oaktrail_rfkill_init();
359 if (ret) {
360 pr_warning("Setup rfkill failed\n");
361 goto err_rfkill;
362 }
363
364 pr_info("Driver "DRIVER_VERSION" successfully loaded\n");
365 return 0;
366
367err_rfkill:
368 oaktrail_backlight_exit();
369err_backlight:
370 platform_device_del(oaktrail_device);
371err_device_add:
372 platform_device_put(oaktrail_device);
373err_device_alloc:
374 platform_driver_unregister(&oaktrail_driver);
375err_driver_reg:
376
377 return ret;
378}
379
380static void __exit oaktrail_cleanup(void)
381{
382 oaktrail_backlight_exit();
383 oaktrail_rfkill_cleanup();
384 platform_device_unregister(oaktrail_device);
385 platform_driver_unregister(&oaktrail_driver);
386
387 pr_info("Driver unloaded\n");
388}
389
390module_init(oaktrail_init);
391module_exit(oaktrail_cleanup);
392
393MODULE_AUTHOR("Yin Kangkai (kangkai.yin@intel.com)");
394MODULE_DESCRIPTION("Intel Oaktrail Platform ACPI Extras");
395MODULE_VERSION(DRIVER_VERSION);
396MODULE_LICENSE("GPL");
397MODULE_ALIAS("dmi:*:svnIntelCorporation:pnOakTrailplatform:*");
1/*
2 * intel_oaktrail.c - Intel OakTrail Platform support.
3 *
4 * Copyright (C) 2010-2011 Intel Corporation
5 * Author: Yin Kangkai (kangkai.yin@intel.com)
6 *
7 * based on Compal driver, Copyright (C) 2008 Cezary Jackiewicz
8 * <cezary.jackiewicz (at) gmail.com>, based on MSI driver
9 * Copyright (C) 2006 Lennart Poettering <mzxreary (at) 0pointer (dot) de>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 * 02110-1301, USA.
25 *
26 * This driver does below things:
27 * 1. registers itself in the Linux backlight control in
28 * /sys/class/backlight/intel_oaktrail/
29 *
30 * 2. registers in the rfkill subsystem here: /sys/class/rfkill/rfkillX/
31 * for these components: wifi, bluetooth, wwan (3g), gps
32 *
33 * This driver might work on other products based on Oaktrail. If you
34 * want to try it you can pass force=1 as argument to the module which
35 * will force it to load even when the DMI data doesn't identify the
36 * product as compatible.
37 */
38
39#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
40
41#include <linux/module.h>
42#include <linux/kernel.h>
43#include <linux/init.h>
44#include <linux/acpi.h>
45#include <linux/fb.h>
46#include <linux/mutex.h>
47#include <linux/err.h>
48#include <linux/i2c.h>
49#include <linux/backlight.h>
50#include <linux/platform_device.h>
51#include <linux/dmi.h>
52#include <linux/rfkill.h>
53
54#define DRIVER_NAME "intel_oaktrail"
55#define DRIVER_VERSION "0.4ac1"
56
57/*
58 * This is the devices status address in EC space, and the control bits
59 * definition:
60 *
61 * (1 << 0): Camera enable/disable, RW.
62 * (1 << 1): Bluetooth enable/disable, RW.
63 * (1 << 2): GPS enable/disable, RW.
64 * (1 << 3): WiFi enable/disable, RW.
65 * (1 << 4): WWAN (3G) enable/disalbe, RW.
66 * (1 << 5): Touchscreen enable/disable, Read Only.
67 */
68#define OT_EC_DEVICE_STATE_ADDRESS 0xD6
69
70#define OT_EC_CAMERA_MASK (1 << 0)
71#define OT_EC_BT_MASK (1 << 1)
72#define OT_EC_GPS_MASK (1 << 2)
73#define OT_EC_WIFI_MASK (1 << 3)
74#define OT_EC_WWAN_MASK (1 << 4)
75#define OT_EC_TS_MASK (1 << 5)
76
77/*
78 * This is the address in EC space and commands used to control LCD backlight:
79 *
80 * Two steps needed to change the LCD backlight:
81 * 1. write the backlight percentage into OT_EC_BL_BRIGHTNESS_ADDRESS;
82 * 2. write OT_EC_BL_CONTROL_ON_DATA into OT_EC_BL_CONTROL_ADDRESS.
83 *
84 * To read the LCD back light, just read out the value from
85 * OT_EC_BL_BRIGHTNESS_ADDRESS.
86 *
87 * LCD backlight brightness range: 0 - 100 (OT_EC_BL_BRIGHTNESS_MAX)
88 */
89#define OT_EC_BL_BRIGHTNESS_ADDRESS 0x44
90#define OT_EC_BL_BRIGHTNESS_MAX 100
91#define OT_EC_BL_CONTROL_ADDRESS 0x3A
92#define OT_EC_BL_CONTROL_ON_DATA 0x1A
93
94
95static bool force;
96module_param(force, bool, 0);
97MODULE_PARM_DESC(force, "Force driver load, ignore DMI data");
98
99static struct platform_device *oaktrail_device;
100static struct backlight_device *oaktrail_bl_device;
101static struct rfkill *bt_rfkill;
102static struct rfkill *gps_rfkill;
103static struct rfkill *wifi_rfkill;
104static struct rfkill *wwan_rfkill;
105
106
107/* rfkill */
108static int oaktrail_rfkill_set(void *data, bool blocked)
109{
110 u8 value;
111 u8 result;
112 unsigned long radio = (unsigned long) data;
113
114 ec_read(OT_EC_DEVICE_STATE_ADDRESS, &result);
115
116 if (!blocked)
117 value = (u8) (result | radio);
118 else
119 value = (u8) (result & ~radio);
120
121 ec_write(OT_EC_DEVICE_STATE_ADDRESS, value);
122
123 return 0;
124}
125
126static const struct rfkill_ops oaktrail_rfkill_ops = {
127 .set_block = oaktrail_rfkill_set,
128};
129
130static struct rfkill *oaktrail_rfkill_new(char *name, enum rfkill_type type,
131 unsigned long mask)
132{
133 struct rfkill *rfkill_dev;
134 u8 value;
135 int err;
136
137 rfkill_dev = rfkill_alloc(name, &oaktrail_device->dev, type,
138 &oaktrail_rfkill_ops, (void *)mask);
139 if (!rfkill_dev)
140 return ERR_PTR(-ENOMEM);
141
142 ec_read(OT_EC_DEVICE_STATE_ADDRESS, &value);
143 rfkill_init_sw_state(rfkill_dev, (value & mask) != 1);
144
145 err = rfkill_register(rfkill_dev);
146 if (err) {
147 rfkill_destroy(rfkill_dev);
148 return ERR_PTR(err);
149 }
150
151 return rfkill_dev;
152}
153
154static inline void __oaktrail_rfkill_cleanup(struct rfkill *rf)
155{
156 if (rf) {
157 rfkill_unregister(rf);
158 rfkill_destroy(rf);
159 }
160}
161
162static void oaktrail_rfkill_cleanup(void)
163{
164 __oaktrail_rfkill_cleanup(wifi_rfkill);
165 __oaktrail_rfkill_cleanup(bt_rfkill);
166 __oaktrail_rfkill_cleanup(gps_rfkill);
167 __oaktrail_rfkill_cleanup(wwan_rfkill);
168}
169
170static int oaktrail_rfkill_init(void)
171{
172 int ret;
173
174 wifi_rfkill = oaktrail_rfkill_new("oaktrail-wifi",
175 RFKILL_TYPE_WLAN,
176 OT_EC_WIFI_MASK);
177 if (IS_ERR(wifi_rfkill)) {
178 ret = PTR_ERR(wifi_rfkill);
179 wifi_rfkill = NULL;
180 goto cleanup;
181 }
182
183 bt_rfkill = oaktrail_rfkill_new("oaktrail-bluetooth",
184 RFKILL_TYPE_BLUETOOTH,
185 OT_EC_BT_MASK);
186 if (IS_ERR(bt_rfkill)) {
187 ret = PTR_ERR(bt_rfkill);
188 bt_rfkill = NULL;
189 goto cleanup;
190 }
191
192 gps_rfkill = oaktrail_rfkill_new("oaktrail-gps",
193 RFKILL_TYPE_GPS,
194 OT_EC_GPS_MASK);
195 if (IS_ERR(gps_rfkill)) {
196 ret = PTR_ERR(gps_rfkill);
197 gps_rfkill = NULL;
198 goto cleanup;
199 }
200
201 wwan_rfkill = oaktrail_rfkill_new("oaktrail-wwan",
202 RFKILL_TYPE_WWAN,
203 OT_EC_WWAN_MASK);
204 if (IS_ERR(wwan_rfkill)) {
205 ret = PTR_ERR(wwan_rfkill);
206 wwan_rfkill = NULL;
207 goto cleanup;
208 }
209
210 return 0;
211
212cleanup:
213 oaktrail_rfkill_cleanup();
214 return ret;
215}
216
217
218/* backlight */
219static int get_backlight_brightness(struct backlight_device *b)
220{
221 u8 value;
222 ec_read(OT_EC_BL_BRIGHTNESS_ADDRESS, &value);
223
224 return value;
225}
226
227static int set_backlight_brightness(struct backlight_device *b)
228{
229 u8 percent = (u8) b->props.brightness;
230 if (percent < 0 || percent > OT_EC_BL_BRIGHTNESS_MAX)
231 return -EINVAL;
232
233 ec_write(OT_EC_BL_BRIGHTNESS_ADDRESS, percent);
234 ec_write(OT_EC_BL_CONTROL_ADDRESS, OT_EC_BL_CONTROL_ON_DATA);
235
236 return 0;
237}
238
239static const struct backlight_ops oaktrail_bl_ops = {
240 .get_brightness = get_backlight_brightness,
241 .update_status = set_backlight_brightness,
242};
243
244static int oaktrail_backlight_init(void)
245{
246 struct backlight_device *bd;
247 struct backlight_properties props;
248
249 memset(&props, 0, sizeof(struct backlight_properties));
250 props.type = BACKLIGHT_PLATFORM;
251 props.max_brightness = OT_EC_BL_BRIGHTNESS_MAX;
252 bd = backlight_device_register(DRIVER_NAME,
253 &oaktrail_device->dev, NULL,
254 &oaktrail_bl_ops,
255 &props);
256
257 if (IS_ERR(bd)) {
258 oaktrail_bl_device = NULL;
259 pr_warning("Unable to register backlight device\n");
260 return PTR_ERR(bd);
261 }
262
263 oaktrail_bl_device = bd;
264
265 bd->props.brightness = get_backlight_brightness(bd);
266 bd->props.power = FB_BLANK_UNBLANK;
267 backlight_update_status(bd);
268
269 return 0;
270}
271
272static void oaktrail_backlight_exit(void)
273{
274 if (oaktrail_bl_device)
275 backlight_device_unregister(oaktrail_bl_device);
276}
277
278static int oaktrail_probe(struct platform_device *pdev)
279{
280 return 0;
281}
282
283static int oaktrail_remove(struct platform_device *pdev)
284{
285 return 0;
286}
287
288static struct platform_driver oaktrail_driver = {
289 .driver = {
290 .name = DRIVER_NAME,
291 .owner = THIS_MODULE,
292 },
293 .probe = oaktrail_probe,
294 .remove = oaktrail_remove,
295};
296
297static int dmi_check_cb(const struct dmi_system_id *id)
298{
299 pr_info("Identified model '%s'\n", id->ident);
300 return 0;
301}
302
303static struct dmi_system_id __initdata oaktrail_dmi_table[] = {
304 {
305 .ident = "OakTrail platform",
306 .matches = {
307 DMI_MATCH(DMI_PRODUCT_NAME, "OakTrail platform"),
308 },
309 .callback = dmi_check_cb
310 },
311 { }
312};
313MODULE_DEVICE_TABLE(dmi, oaktrail_dmi_table);
314
315static int __init oaktrail_init(void)
316{
317 int ret;
318
319 if (acpi_disabled) {
320 pr_err("ACPI needs to be enabled for this driver to work!\n");
321 return -ENODEV;
322 }
323
324 if (!force && !dmi_check_system(oaktrail_dmi_table)) {
325 pr_err("Platform not recognized (You could try the module's force-parameter)");
326 return -ENODEV;
327 }
328
329 ret = platform_driver_register(&oaktrail_driver);
330 if (ret) {
331 pr_warning("Unable to register platform driver\n");
332 goto err_driver_reg;
333 }
334
335 oaktrail_device = platform_device_alloc(DRIVER_NAME, -1);
336 if (!oaktrail_device) {
337 pr_warning("Unable to allocate platform device\n");
338 ret = -ENOMEM;
339 goto err_device_alloc;
340 }
341
342 ret = platform_device_add(oaktrail_device);
343 if (ret) {
344 pr_warning("Unable to add platform device\n");
345 goto err_device_add;
346 }
347
348 if (!acpi_video_backlight_support()) {
349 ret = oaktrail_backlight_init();
350 if (ret)
351 goto err_backlight;
352
353 } else
354 pr_info("Backlight controlled by ACPI video driver\n");
355
356 ret = oaktrail_rfkill_init();
357 if (ret) {
358 pr_warning("Setup rfkill failed\n");
359 goto err_rfkill;
360 }
361
362 pr_info("Driver "DRIVER_VERSION" successfully loaded\n");
363 return 0;
364
365err_rfkill:
366 oaktrail_backlight_exit();
367err_backlight:
368 platform_device_del(oaktrail_device);
369err_device_add:
370 platform_device_put(oaktrail_device);
371err_device_alloc:
372 platform_driver_unregister(&oaktrail_driver);
373err_driver_reg:
374
375 return ret;
376}
377
378static void __exit oaktrail_cleanup(void)
379{
380 oaktrail_backlight_exit();
381 oaktrail_rfkill_cleanup();
382 platform_device_unregister(oaktrail_device);
383 platform_driver_unregister(&oaktrail_driver);
384
385 pr_info("Driver unloaded\n");
386}
387
388module_init(oaktrail_init);
389module_exit(oaktrail_cleanup);
390
391MODULE_AUTHOR("Yin Kangkai (kangkai.yin@intel.com)");
392MODULE_DESCRIPTION("Intel Oaktrail Platform ACPI Extras");
393MODULE_VERSION(DRIVER_VERSION);
394MODULE_LICENSE("GPL");