2 * intel_oaktrail.c - Intel OakTrail Platform support.
4 * Copyright (C) 2010-2011 Intel Corporation
5 * Author: Yin Kangkai (kangkai.yin@intel.com)
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>
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.
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.
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
26 * This driver does below things:
27 * 1. registers itself in the Linux backlight control in
28 * /sys/class/backlight/intel_oaktrail/
30 * 2. registers in the rfkill subsystem here: /sys/class/rfkill/rfkillX/
31 * for these components: wifi, bluetooth, wwan (3g), gps
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.
39 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
41 #include <linux/module.h>
42 #include <linux/kernel.h>
43 #include <linux/init.h>
44 #include <linux/acpi.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/video.h>
55 #define DRIVER_NAME "intel_oaktrail"
56 #define DRIVER_VERSION "0.4ac1"
59 * This is the devices status address in EC space, and the control bits
62 * (1 << 0): Camera enable/disable, RW.
63 * (1 << 1): Bluetooth enable/disable, RW.
64 * (1 << 2): GPS enable/disable, RW.
65 * (1 << 3): WiFi enable/disable, RW.
66 * (1 << 4): WWAN (3G) enable/disable, RW.
67 * (1 << 5): Touchscreen enable/disable, Read Only.
69 #define OT_EC_DEVICE_STATE_ADDRESS 0xD6
71 #define OT_EC_CAMERA_MASK (1 << 0)
72 #define OT_EC_BT_MASK (1 << 1)
73 #define OT_EC_GPS_MASK (1 << 2)
74 #define OT_EC_WIFI_MASK (1 << 3)
75 #define OT_EC_WWAN_MASK (1 << 4)
76 #define OT_EC_TS_MASK (1 << 5)
79 * This is the address in EC space and commands used to control LCD backlight:
81 * Two steps needed to change the LCD backlight:
82 * 1. write the backlight percentage into OT_EC_BL_BRIGHTNESS_ADDRESS;
83 * 2. write OT_EC_BL_CONTROL_ON_DATA into OT_EC_BL_CONTROL_ADDRESS.
85 * To read the LCD back light, just read out the value from
86 * OT_EC_BL_BRIGHTNESS_ADDRESS.
88 * LCD backlight brightness range: 0 - 100 (OT_EC_BL_BRIGHTNESS_MAX)
90 #define OT_EC_BL_BRIGHTNESS_ADDRESS 0x44
91 #define OT_EC_BL_BRIGHTNESS_MAX 100
92 #define OT_EC_BL_CONTROL_ADDRESS 0x3A
93 #define OT_EC_BL_CONTROL_ON_DATA 0x1A
97 module_param(force
, bool, 0);
98 MODULE_PARM_DESC(force
, "Force driver load, ignore DMI data");
100 static struct platform_device
*oaktrail_device
;
101 static struct backlight_device
*oaktrail_bl_device
;
102 static struct rfkill
*bt_rfkill
;
103 static struct rfkill
*gps_rfkill
;
104 static struct rfkill
*wifi_rfkill
;
105 static struct rfkill
*wwan_rfkill
;
109 static int oaktrail_rfkill_set(void *data
, bool blocked
)
113 unsigned long radio
= (unsigned long) data
;
115 ec_read(OT_EC_DEVICE_STATE_ADDRESS
, &result
);
118 value
= (u8
) (result
| radio
);
120 value
= (u8
) (result
& ~radio
);
122 ec_write(OT_EC_DEVICE_STATE_ADDRESS
, value
);
127 static const struct rfkill_ops oaktrail_rfkill_ops
= {
128 .set_block
= oaktrail_rfkill_set
,
131 static struct rfkill
*oaktrail_rfkill_new(char *name
, enum rfkill_type type
,
134 struct rfkill
*rfkill_dev
;
138 rfkill_dev
= rfkill_alloc(name
, &oaktrail_device
->dev
, type
,
139 &oaktrail_rfkill_ops
, (void *)mask
);
141 return ERR_PTR(-ENOMEM
);
143 ec_read(OT_EC_DEVICE_STATE_ADDRESS
, &value
);
144 rfkill_init_sw_state(rfkill_dev
, (value
& mask
) != 1);
146 err
= rfkill_register(rfkill_dev
);
148 rfkill_destroy(rfkill_dev
);
155 static inline void __oaktrail_rfkill_cleanup(struct rfkill
*rf
)
158 rfkill_unregister(rf
);
163 static void oaktrail_rfkill_cleanup(void)
165 __oaktrail_rfkill_cleanup(wifi_rfkill
);
166 __oaktrail_rfkill_cleanup(bt_rfkill
);
167 __oaktrail_rfkill_cleanup(gps_rfkill
);
168 __oaktrail_rfkill_cleanup(wwan_rfkill
);
171 static int oaktrail_rfkill_init(void)
175 wifi_rfkill
= oaktrail_rfkill_new("oaktrail-wifi",
178 if (IS_ERR(wifi_rfkill
)) {
179 ret
= PTR_ERR(wifi_rfkill
);
184 bt_rfkill
= oaktrail_rfkill_new("oaktrail-bluetooth",
185 RFKILL_TYPE_BLUETOOTH
,
187 if (IS_ERR(bt_rfkill
)) {
188 ret
= PTR_ERR(bt_rfkill
);
193 gps_rfkill
= oaktrail_rfkill_new("oaktrail-gps",
196 if (IS_ERR(gps_rfkill
)) {
197 ret
= PTR_ERR(gps_rfkill
);
202 wwan_rfkill
= oaktrail_rfkill_new("oaktrail-wwan",
205 if (IS_ERR(wwan_rfkill
)) {
206 ret
= PTR_ERR(wwan_rfkill
);
214 oaktrail_rfkill_cleanup();
220 static int get_backlight_brightness(struct backlight_device
*b
)
223 ec_read(OT_EC_BL_BRIGHTNESS_ADDRESS
, &value
);
228 static int set_backlight_brightness(struct backlight_device
*b
)
230 u8 percent
= (u8
) b
->props
.brightness
;
231 if (percent
< 0 || percent
> OT_EC_BL_BRIGHTNESS_MAX
)
234 ec_write(OT_EC_BL_BRIGHTNESS_ADDRESS
, percent
);
235 ec_write(OT_EC_BL_CONTROL_ADDRESS
, OT_EC_BL_CONTROL_ON_DATA
);
240 static const struct backlight_ops oaktrail_bl_ops
= {
241 .get_brightness
= get_backlight_brightness
,
242 .update_status
= set_backlight_brightness
,
245 static int oaktrail_backlight_init(void)
247 struct backlight_device
*bd
;
248 struct backlight_properties props
;
250 memset(&props
, 0, sizeof(struct backlight_properties
));
251 props
.type
= BACKLIGHT_PLATFORM
;
252 props
.max_brightness
= OT_EC_BL_BRIGHTNESS_MAX
;
253 bd
= backlight_device_register(DRIVER_NAME
,
254 &oaktrail_device
->dev
, NULL
,
259 oaktrail_bl_device
= NULL
;
260 pr_warning("Unable to register backlight device\n");
264 oaktrail_bl_device
= bd
;
266 bd
->props
.brightness
= get_backlight_brightness(bd
);
267 bd
->props
.power
= FB_BLANK_UNBLANK
;
268 backlight_update_status(bd
);
273 static void oaktrail_backlight_exit(void)
275 backlight_device_unregister(oaktrail_bl_device
);
278 static int oaktrail_probe(struct platform_device
*pdev
)
283 static int oaktrail_remove(struct platform_device
*pdev
)
288 static struct platform_driver oaktrail_driver
= {
292 .probe
= oaktrail_probe
,
293 .remove
= oaktrail_remove
,
296 static int dmi_check_cb(const struct dmi_system_id
*id
)
298 pr_info("Identified model '%s'\n", id
->ident
);
302 static struct dmi_system_id __initdata oaktrail_dmi_table
[] = {
304 .ident
= "OakTrail platform",
306 DMI_MATCH(DMI_PRODUCT_NAME
, "OakTrail platform"),
308 .callback
= dmi_check_cb
312 MODULE_DEVICE_TABLE(dmi
, oaktrail_dmi_table
);
314 static int __init
oaktrail_init(void)
319 pr_err("ACPI needs to be enabled for this driver to work!\n");
323 if (!force
&& !dmi_check_system(oaktrail_dmi_table
)) {
324 pr_err("Platform not recognized (You could try the module's force-parameter)");
328 ret
= platform_driver_register(&oaktrail_driver
);
330 pr_warning("Unable to register platform driver\n");
334 oaktrail_device
= platform_device_alloc(DRIVER_NAME
, -1);
335 if (!oaktrail_device
) {
336 pr_warning("Unable to allocate platform device\n");
338 goto err_device_alloc
;
341 ret
= platform_device_add(oaktrail_device
);
343 pr_warning("Unable to add platform device\n");
347 if (acpi_video_get_backlight_type() == acpi_backlight_vendor
) {
348 ret
= oaktrail_backlight_init();
353 ret
= oaktrail_rfkill_init();
355 pr_warning("Setup rfkill failed\n");
359 pr_info("Driver "DRIVER_VERSION
" successfully loaded\n");
363 oaktrail_backlight_exit();
365 platform_device_del(oaktrail_device
);
367 platform_device_put(oaktrail_device
);
369 platform_driver_unregister(&oaktrail_driver
);
375 static void __exit
oaktrail_cleanup(void)
377 oaktrail_backlight_exit();
378 oaktrail_rfkill_cleanup();
379 platform_device_unregister(oaktrail_device
);
380 platform_driver_unregister(&oaktrail_driver
);
382 pr_info("Driver unloaded\n");
385 module_init(oaktrail_init
);
386 module_exit(oaktrail_cleanup
);
388 MODULE_AUTHOR("Yin Kangkai (kangkai.yin@intel.com)");
389 MODULE_DESCRIPTION("Intel Oaktrail Platform ACPI Extras");
390 MODULE_VERSION(DRIVER_VERSION
);
391 MODULE_LICENSE("GPL");