2 * Fujitsu Lifebook Application Panel button drive
4 * Copyright (C) 2007 Stephen Hemminger <shemminger@linux-foundation.org>
5 * Copyright (C) 2001-2003 Jochen Eisinger <jochen@penguin-breeder.org>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published by
9 * the Free Software Foundation.
11 * Many Fujitsu Lifebook laptops have a small panel of buttons that are
12 * accessible via the i2c/smbus interface. This driver polls those
13 * buttons and generates input events.
15 * For more details see:
16 * http://apanel.sourceforge.net/tech.php
19 #include <linux/kernel.h>
20 #include <linux/module.h>
21 #include <linux/ioport.h>
23 #include <linux/input-polldev.h>
24 #include <linux/i2c.h>
25 #include <linux/leds.h>
27 #define APANEL_NAME "Fujitsu Application Panel"
28 #define APANEL "apanel"
30 /* How often we poll keys - msecs */
31 #define POLL_INTERVAL_DEFAULT 1000
33 /* Magic constants in BIOS that tell about buttons */
36 APANEL_DEV_APPBTN = 1,
51 /* Result of BIOS snooping/probing -- what features are supported */
52 static enum apanel_chip device_chip[APANEL_DEV_MAX];
54 #define MAX_PANEL_KEYS 12
57 struct input_polled_dev *ipdev;
58 struct i2c_client *client;
59 unsigned short keymap[MAX_PANEL_KEYS];
61 struct led_classdev mail_led;
65 static int apanel_probe(struct i2c_client *, const struct i2c_device_id *);
67 static void report_key(struct input_dev *input, unsigned keycode)
69 pr_debug(APANEL ": report key %#x\n", keycode);
70 input_report_key(input, keycode, 1);
73 input_report_key(input, keycode, 0);
77 /* Poll for key changes
79 * Read Application keys via SMI
80 * A (0x4), B (0x8), Internet (0x2), Email (0x1).
83 * Forward (0x100), Rewind (0x200), Stop (0x400), Pause (0x800)
85 static void apanel_poll(struct input_polled_dev *ipdev)
87 struct apanel *ap = ipdev->private;
88 struct input_dev *idev = ipdev->input;
89 u8 cmd = device_chip[APANEL_DEV_APPBTN] == CHIP_OZ992C ? 0 : 8;
93 data = i2c_smbus_read_word_data(ap->client, cmd);
95 return; /* ignore errors (due to ACPI??) */
97 /* write back to clear latch */
98 i2c_smbus_write_word_data(ap->client, cmd, 0);
103 dev_dbg(&idev->dev, APANEL ": data %#x\n", data);
104 for (i = 0; i < idev->keycodemax; i++)
105 if ((1u << i) & data)
106 report_key(idev, ap->keymap[i]);
109 static int mail_led_set(struct led_classdev *led,
110 enum led_brightness value)
112 struct apanel *ap = container_of(led, struct apanel, mail_led);
113 u16 led_bits = value != LED_OFF ? 0x8000 : 0x0000;
115 return i2c_smbus_write_word_data(ap->client, 0x10, led_bits);
118 static int apanel_remove(struct i2c_client *client)
120 struct apanel *ap = i2c_get_clientdata(client);
122 if (device_chip[APANEL_DEV_LED] != CHIP_NONE)
123 led_classdev_unregister(&ap->mail_led);
125 input_unregister_polled_device(ap->ipdev);
126 input_free_polled_device(ap->ipdev);
131 static void apanel_shutdown(struct i2c_client *client)
133 apanel_remove(client);
136 static const struct i2c_device_id apanel_id[] = {
137 { "fujitsu_apanel", 0 },
140 MODULE_DEVICE_TABLE(i2c, apanel_id);
142 static struct i2c_driver apanel_driver = {
146 .probe = &apanel_probe,
147 .remove = &apanel_remove,
148 .shutdown = &apanel_shutdown,
149 .id_table = apanel_id,
152 static struct apanel apanel = {
162 [11] = KEY_PLAYPAUSE,
167 .brightness_set_blocking = mail_led_set,
171 /* NB: Only one panel on the i2c. */
172 static int apanel_probe(struct i2c_client *client,
173 const struct i2c_device_id *id)
176 struct input_polled_dev *ipdev;
177 struct input_dev *idev;
178 u8 cmd = device_chip[APANEL_DEV_APPBTN] == CHIP_OZ992C ? 0 : 8;
179 int i, err = -ENOMEM;
183 ipdev = input_allocate_polled_device();
190 i2c_set_clientdata(client, ap);
192 err = i2c_smbus_write_word_data(client, cmd, 0);
194 dev_warn(&client->dev, APANEL ": smbus write error %d\n",
199 ipdev->poll = apanel_poll;
200 ipdev->poll_interval = POLL_INTERVAL_DEFAULT;
204 idev->name = APANEL_NAME " buttons";
205 idev->phys = "apanel/input0";
206 idev->id.bustype = BUS_HOST;
207 idev->dev.parent = &client->dev;
209 set_bit(EV_KEY, idev->evbit);
211 idev->keycode = ap->keymap;
212 idev->keycodesize = sizeof(ap->keymap[0]);
213 idev->keycodemax = (device_chip[APANEL_DEV_CDBTN] != CHIP_NONE) ? 12 : 4;
215 for (i = 0; i < idev->keycodemax; i++)
217 set_bit(ap->keymap[i], idev->keybit);
219 err = input_register_polled_device(ipdev);
223 if (device_chip[APANEL_DEV_LED] != CHIP_NONE) {
224 err = led_classdev_register(&client->dev, &ap->mail_led);
231 input_unregister_polled_device(ipdev);
233 input_free_polled_device(ipdev);
238 /* Scan the system ROM for the signature "FJKEYINF" */
239 static __init const void __iomem *bios_signature(const void __iomem *bios)
242 const unsigned char signature[] = "FJKEYINF";
244 for (offset = 0; offset < 0x10000; offset += 0x10) {
245 if (check_signature(bios + offset, signature,
246 sizeof(signature)-1))
247 return bios + offset;
249 pr_notice(APANEL ": Fujitsu BIOS signature '%s' not found...\n",
254 static int __init apanel_init(void)
257 const void __iomem *p;
259 unsigned char i2c_addr;
262 bios = ioremap(0xF0000, 0x10000); /* Can't fail */
264 p = bios_signature(bios);
270 /* just use the first address */
272 i2c_addr = readb(p + 3) >> 1;
274 for ( ; (devno = readb(p)) & 0x7f; p += 4) {
275 unsigned char method, slave, chip;
277 method = readb(p + 1);
279 slave = readb(p + 3) >> 1;
281 if (slave != i2c_addr) {
282 pr_notice(APANEL ": only one SMBus slave "
283 "address supported, skipping device...\n");
287 /* translate alternative device numbers */
290 devno = APANEL_DEV_APPBTN;
293 devno = APANEL_DEV_LED;
297 if (devno >= APANEL_DEV_MAX)
298 pr_notice(APANEL ": unknown device %u found\n", devno);
299 else if (device_chip[devno] != CHIP_NONE)
300 pr_warn(APANEL ": duplicate entry for devno %u\n",
303 else if (method != 1 && method != 2 && method != 4) {
304 pr_notice(APANEL ": unknown method %u for devno %u\n",
307 device_chip[devno] = (enum apanel_chip) chip;
314 pr_info(APANEL ": no input devices reported by BIOS\n");
318 return i2c_add_driver(&apanel_driver);
320 module_init(apanel_init);
322 static void __exit apanel_cleanup(void)
324 i2c_del_driver(&apanel_driver);
326 module_exit(apanel_cleanup);
328 MODULE_AUTHOR("Stephen Hemminger <shemminger@linux-foundation.org>");
329 MODULE_DESCRIPTION(APANEL_NAME " driver");
330 MODULE_LICENSE("GPL");
332 MODULE_ALIAS("dmi:*:svnFUJITSU:pnLifeBook*:pvr*:rvnFUJITSU:*");
333 MODULE_ALIAS("dmi:*:svnFUJITSU:pnLifebook*:pvr*:rvnFUJITSU:*");