blob: 2740b40aad9b318bbaf289357c197b6294323bf8 [file] [log] [blame]
Cezary Jackiewicz54115522008-06-09 16:22:22 -07001/*-*-linux-c-*-*/
2
3/*
4 Copyright (C) 2008 Cezary Jackiewicz <cezary.jackiewicz (at) gmail.com>
5
6 based on MSI driver
7
8 Copyright (C) 2006 Lennart Poettering <mzxreary (at) 0pointer (dot) de>
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 02110-1301, USA.
24 */
25
26/*
27 * comapl-laptop.c - Compal laptop support.
28 *
Mario Limonciello493e9142009-08-25 10:30:13 -050029 * The driver registers itself with the rfkill subsystem and
30 * the Linux backlight control subsystem.
Cezary Jackiewicz54115522008-06-09 16:22:22 -070031 *
32 * This driver might work on other laptops produced by Compal. If you
33 * want to try it you can pass force=1 as argument to the module which
34 * will force it to load even when the DMI data doesn't identify the
Cezary Jackiewicz87dc5e32008-06-12 22:08:59 +020035 * laptop as FL9x.
Cezary Jackiewicz54115522008-06-09 16:22:22 -070036 */
37
38#include <linux/module.h>
39#include <linux/kernel.h>
40#include <linux/init.h>
41#include <linux/acpi.h>
42#include <linux/dmi.h>
43#include <linux/backlight.h>
44#include <linux/platform_device.h>
Mario Limonciello493e9142009-08-25 10:30:13 -050045#include <linux/rfkill.h>
Cezary Jackiewicz54115522008-06-09 16:22:22 -070046
Cezary Jackiewicz87dc5e32008-06-12 22:08:59 +020047#define COMPAL_DRIVER_VERSION "0.2.6"
Cezary Jackiewicz54115522008-06-09 16:22:22 -070048
49#define COMPAL_LCD_LEVEL_MAX 8
50
51#define COMPAL_EC_COMMAND_WIRELESS 0xBB
52#define COMPAL_EC_COMMAND_LCD_LEVEL 0xB9
53
54#define KILLSWITCH_MASK 0x10
55#define WLAN_MASK 0x01
56#define BT_MASK 0x02
57
Mario Limonciello493e9142009-08-25 10:30:13 -050058static struct rfkill *wifi_rfkill;
59static struct rfkill *bt_rfkill;
60static struct platform_device *compal_device;
61
Cezary Jackiewicz54115522008-06-09 16:22:22 -070062static int force;
63module_param(force, bool, 0);
64MODULE_PARM_DESC(force, "Force driver load, ignore DMI data");
65
66/* Hardware access */
67
68static int set_lcd_level(int level)
69{
70 if (level < 0 || level >= COMPAL_LCD_LEVEL_MAX)
71 return -EINVAL;
72
73 ec_write(COMPAL_EC_COMMAND_LCD_LEVEL, level);
74
75 return 0;
76}
77
78static int get_lcd_level(void)
79{
80 u8 result;
81
82 ec_read(COMPAL_EC_COMMAND_LCD_LEVEL, &result);
83
84 return (int) result;
85}
86
Mario Limonciello493e9142009-08-25 10:30:13 -050087static int compal_rfkill_set(void *data, bool blocked)
Cezary Jackiewicz54115522008-06-09 16:22:22 -070088{
Mario Limonciello493e9142009-08-25 10:30:13 -050089 unsigned long radio = (unsigned long) data;
Cezary Jackiewicz54115522008-06-09 16:22:22 -070090 u8 result, value;
91
92 ec_read(COMPAL_EC_COMMAND_WIRELESS, &result);
93
Mario Limonciello493e9142009-08-25 10:30:13 -050094 if (!blocked)
95 value = (u8) (result | radio);
96 else
97 value = (u8) (result & ~radio);
98 ec_write(COMPAL_EC_COMMAND_WIRELESS, value);
Cezary Jackiewicz54115522008-06-09 16:22:22 -070099
100 return 0;
101}
102
Mario Limonciello493e9142009-08-25 10:30:13 -0500103static void compal_rfkill_poll(struct rfkill *rfkill, void *data)
Cezary Jackiewicz54115522008-06-09 16:22:22 -0700104{
105 u8 result;
Mario Limonciello493e9142009-08-25 10:30:13 -0500106 bool hw_blocked;
Cezary Jackiewicz54115522008-06-09 16:22:22 -0700107
108 ec_read(COMPAL_EC_COMMAND_WIRELESS, &result);
109
Mario Limonciello493e9142009-08-25 10:30:13 -0500110 hw_blocked = !(result & KILLSWITCH_MASK);
111 rfkill_set_hw_state(rfkill, hw_blocked);
112}
Cezary Jackiewicz54115522008-06-09 16:22:22 -0700113
Mario Limonciello493e9142009-08-25 10:30:13 -0500114static const struct rfkill_ops compal_rfkill_ops = {
115 .poll = compal_rfkill_poll,
116 .set_block = compal_rfkill_set,
117};
118
119static int setup_rfkill(void)
120{
121 int ret;
122
123 wifi_rfkill = rfkill_alloc("compal-wifi", &compal_device->dev,
124 RFKILL_TYPE_WLAN, &compal_rfkill_ops,
125 (void *) WLAN_MASK);
126 if (!wifi_rfkill)
127 return -ENOMEM;
128
129 ret = rfkill_register(wifi_rfkill);
130 if (ret)
131 goto err_wifi;
132
133 bt_rfkill = rfkill_alloc("compal-bluetooth", &compal_device->dev,
134 RFKILL_TYPE_BLUETOOTH, &compal_rfkill_ops,
135 (void *) BT_MASK);
136 if (!bt_rfkill) {
137 ret = -ENOMEM;
138 goto err_allocate_bt;
Cezary Jackiewicz54115522008-06-09 16:22:22 -0700139 }
Mario Limonciello493e9142009-08-25 10:30:13 -0500140 ret = rfkill_register(bt_rfkill);
141 if (ret)
142 goto err_register_bt;
Cezary Jackiewicz54115522008-06-09 16:22:22 -0700143
144 return 0;
Mario Limonciello493e9142009-08-25 10:30:13 -0500145
146err_register_bt:
147 rfkill_destroy(bt_rfkill);
148
149err_allocate_bt:
150 rfkill_unregister(wifi_rfkill);
151
152err_wifi:
153 rfkill_destroy(wifi_rfkill);
154
155 return ret;
Cezary Jackiewicz54115522008-06-09 16:22:22 -0700156}
157
158/* Backlight device stuff */
159
160static int bl_get_brightness(struct backlight_device *b)
161{
162 return get_lcd_level();
163}
164
165
166static int bl_update_status(struct backlight_device *b)
167{
168 return set_lcd_level(b->props.brightness);
169}
170
171static struct backlight_ops compalbl_ops = {
172 .get_brightness = bl_get_brightness,
173 .update_status = bl_update_status,
174};
175
176static struct backlight_device *compalbl_device;
177
Cezary Jackiewicz54115522008-06-09 16:22:22 -0700178
179static struct platform_driver compal_driver = {
180 .driver = {
181 .name = "compal-laptop",
182 .owner = THIS_MODULE,
183 }
184};
185
Cezary Jackiewicz54115522008-06-09 16:22:22 -0700186/* Initialization */
187
188static int dmi_check_cb(const struct dmi_system_id *id)
189{
190 printk(KERN_INFO "compal-laptop: Identified laptop model '%s'.\n",
191 id->ident);
192
193 return 0;
194}
195
196static struct dmi_system_id __initdata compal_dmi_table[] = {
197 {
198 .ident = "FL90/IFL90",
199 .matches = {
200 DMI_MATCH(DMI_BOARD_NAME, "IFL90"),
201 DMI_MATCH(DMI_BOARD_VERSION, "IFT00"),
202 },
203 .callback = dmi_check_cb
204 },
205 {
206 .ident = "FL90/IFL90",
207 .matches = {
208 DMI_MATCH(DMI_BOARD_NAME, "IFL90"),
209 DMI_MATCH(DMI_BOARD_VERSION, "REFERENCE"),
210 },
211 .callback = dmi_check_cb
212 },
213 {
214 .ident = "FL91/IFL91",
215 .matches = {
216 DMI_MATCH(DMI_BOARD_NAME, "IFL91"),
217 DMI_MATCH(DMI_BOARD_VERSION, "IFT00"),
218 },
219 .callback = dmi_check_cb
220 },
221 {
222 .ident = "FL92/JFL92",
223 .matches = {
224 DMI_MATCH(DMI_BOARD_NAME, "JFL92"),
225 DMI_MATCH(DMI_BOARD_VERSION, "IFT00"),
226 },
227 .callback = dmi_check_cb
228 },
229 {
230 .ident = "FT00/IFT00",
231 .matches = {
232 DMI_MATCH(DMI_BOARD_NAME, "IFT00"),
233 DMI_MATCH(DMI_BOARD_VERSION, "IFT00"),
234 },
235 .callback = dmi_check_cb
236 },
Mario Limonciello34325b92009-08-24 16:00:47 -0500237 {
238 .ident = "Dell Mini 9",
239 .matches = {
240 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
241 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 910"),
242 },
243 .callback = dmi_check_cb
244 },
245 {
246 .ident = "Dell Mini 10",
247 .matches = {
248 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
249 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1010"),
250 },
251 .callback = dmi_check_cb
252 },
253 {
254 .ident = "Dell Mini 10v",
255 .matches = {
256 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
257 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1011"),
258 },
259 .callback = dmi_check_cb
260 },
261 {
262 .ident = "Dell Inspiron 11z",
263 .matches = {
264 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
265 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1110"),
266 },
267 .callback = dmi_check_cb
268 },
269 {
270 .ident = "Dell Mini 12",
271 .matches = {
272 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
273 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1210"),
274 },
275 .callback = dmi_check_cb
276 },
277
Cezary Jackiewicz54115522008-06-09 16:22:22 -0700278 { }
279};
280
281static int __init compal_init(void)
282{
283 int ret;
284
285 if (acpi_disabled)
286 return -ENODEV;
287
288 if (!force && !dmi_check_system(compal_dmi_table))
289 return -ENODEV;
290
291 /* Register backlight stuff */
292
Thomas Renninger29454f12008-08-01 17:37:58 +0200293 if (!acpi_video_backlight_support()) {
294 compalbl_device = backlight_device_register("compal-laptop", NULL, NULL,
295 &compalbl_ops);
296 if (IS_ERR(compalbl_device))
297 return PTR_ERR(compalbl_device);
Cezary Jackiewicz54115522008-06-09 16:22:22 -0700298
Thomas Renninger29454f12008-08-01 17:37:58 +0200299 compalbl_device->props.max_brightness = COMPAL_LCD_LEVEL_MAX-1;
300 }
Cezary Jackiewicz54115522008-06-09 16:22:22 -0700301
302 ret = platform_driver_register(&compal_driver);
303 if (ret)
304 goto fail_backlight;
305
306 /* Register platform stuff */
307
308 compal_device = platform_device_alloc("compal-laptop", -1);
309 if (!compal_device) {
310 ret = -ENOMEM;
311 goto fail_platform_driver;
312 }
313
314 ret = platform_device_add(compal_device);
315 if (ret)
Mario Limonciello493e9142009-08-25 10:30:13 -0500316 goto fail_platform_device;
Cezary Jackiewicz54115522008-06-09 16:22:22 -0700317
Mario Limonciello493e9142009-08-25 10:30:13 -0500318 ret = setup_rfkill();
Cezary Jackiewicz54115522008-06-09 16:22:22 -0700319 if (ret)
Mario Limonciello493e9142009-08-25 10:30:13 -0500320 goto fail_rfkill;
Cezary Jackiewicz54115522008-06-09 16:22:22 -0700321
322 printk(KERN_INFO "compal-laptop: driver "COMPAL_DRIVER_VERSION
323 " successfully loaded.\n");
324
325 return 0;
326
Mario Limonciello493e9142009-08-25 10:30:13 -0500327fail_rfkill:
Cezary Jackiewicz54115522008-06-09 16:22:22 -0700328 platform_device_del(compal_device);
329
Mario Limonciello493e9142009-08-25 10:30:13 -0500330fail_platform_device:
Cezary Jackiewicz54115522008-06-09 16:22:22 -0700331
332 platform_device_put(compal_device);
333
334fail_platform_driver:
335
336 platform_driver_unregister(&compal_driver);
337
338fail_backlight:
339
340 backlight_device_unregister(compalbl_device);
341
342 return ret;
343}
344
345static void __exit compal_cleanup(void)
346{
347
Cezary Jackiewicz54115522008-06-09 16:22:22 -0700348 platform_device_unregister(compal_device);
349 platform_driver_unregister(&compal_driver);
350 backlight_device_unregister(compalbl_device);
Mario Limonciello493e9142009-08-25 10:30:13 -0500351 rfkill_unregister(wifi_rfkill);
352 rfkill_destroy(wifi_rfkill);
353 rfkill_unregister(bt_rfkill);
354 rfkill_destroy(bt_rfkill);
Cezary Jackiewicz54115522008-06-09 16:22:22 -0700355
356 printk(KERN_INFO "compal-laptop: driver unloaded.\n");
357}
358
359module_init(compal_init);
360module_exit(compal_cleanup);
361
362MODULE_AUTHOR("Cezary Jackiewicz");
363MODULE_DESCRIPTION("Compal Laptop Support");
364MODULE_VERSION(COMPAL_DRIVER_VERSION);
365MODULE_LICENSE("GPL");
366
367MODULE_ALIAS("dmi:*:rnIFL90:rvrIFT00:*");
368MODULE_ALIAS("dmi:*:rnIFL90:rvrREFERENCE:*");
369MODULE_ALIAS("dmi:*:rnIFL91:rvrIFT00:*");
370MODULE_ALIAS("dmi:*:rnJFL92:rvrIFT00:*");
371MODULE_ALIAS("dmi:*:rnIFT00:rvrIFT00:*");
Mario Limonciello34325b92009-08-24 16:00:47 -0500372MODULE_ALIAS("dmi:*:svnDellInc.:pnInspiron910:*");
373MODULE_ALIAS("dmi:*:svnDellInc.:pnInspiron1010:*");
374MODULE_ALIAS("dmi:*:svnDellInc.:pnInspiron1011:*");
375MODULE_ALIAS("dmi:*:svnDellInc.:pnInspiron1110:*");
376MODULE_ALIAS("dmi:*:svnDellInc.:pnInspiron1210:*");