Merge tag 'gpio-for-v3.11-3' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw...
[linux-2.6.git] / drivers / platform / x86 / amilo-rfkill.c
blob6296f078b7bc78eb57e89314e869f10c93a90eef
1 /*
2 * Support for rfkill on some Fujitsu-Siemens Amilo laptops.
3 * Copyright 2011 Ben Hutchings.
5 * Based in part on the fsam7440 driver, which is:
6 * Copyright 2005 Alejandro Vidal Mata & Javier Vidal Mata.
7 * and on the fsaa1655g driver, which is:
8 * Copyright 2006 Martin Večeřa.
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.
16 #include <linux/module.h>
17 #include <linux/dmi.h>
18 #include <linux/i8042.h>
19 #include <linux/io.h>
20 #include <linux/moduleparam.h>
21 #include <linux/platform_device.h>
22 #include <linux/rfkill.h>
25 * These values were obtained from disassembling and debugging the
26 * PM.exe program installed in the Fujitsu-Siemens AMILO A1655G
28 #define A1655_WIFI_COMMAND 0x10C5
29 #define A1655_WIFI_ON 0x25
30 #define A1655_WIFI_OFF 0x45
32 static int amilo_a1655_rfkill_set_block(void *data, bool blocked)
34 u8 param = blocked ? A1655_WIFI_OFF : A1655_WIFI_ON;
35 int rc;
37 i8042_lock_chip();
38 rc = i8042_command(&param, A1655_WIFI_COMMAND);
39 i8042_unlock_chip();
40 return rc;
43 static const struct rfkill_ops amilo_a1655_rfkill_ops = {
44 .set_block = amilo_a1655_rfkill_set_block
48 * These values were obtained from disassembling the PM.exe program
49 * installed in the Fujitsu-Siemens AMILO M 7440
51 #define M7440_PORT1 0x118f
52 #define M7440_PORT2 0x118e
53 #define M7440_RADIO_ON1 0x12
54 #define M7440_RADIO_ON2 0x80
55 #define M7440_RADIO_OFF1 0x10
56 #define M7440_RADIO_OFF2 0x00
58 static int amilo_m7440_rfkill_set_block(void *data, bool blocked)
60 u8 val1 = blocked ? M7440_RADIO_OFF1 : M7440_RADIO_ON1;
61 u8 val2 = blocked ? M7440_RADIO_OFF2 : M7440_RADIO_ON2;
63 outb(val1, M7440_PORT1);
64 outb(val2, M7440_PORT2);
66 /* Check whether the state has changed correctly */
67 if (inb(M7440_PORT1) != val1 || inb(M7440_PORT2) != val2)
68 return -EIO;
70 return 0;
73 static const struct rfkill_ops amilo_m7440_rfkill_ops = {
74 .set_block = amilo_m7440_rfkill_set_block
77 static const struct dmi_system_id amilo_rfkill_id_table[] = {
79 .matches = {
80 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
81 DMI_MATCH(DMI_BOARD_NAME, "AMILO A1655"),
83 .driver_data = (void *)&amilo_a1655_rfkill_ops
86 .matches = {
87 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
88 DMI_MATCH(DMI_BOARD_NAME, "AMILO M7440"),
90 .driver_data = (void *)&amilo_m7440_rfkill_ops
95 static struct platform_device *amilo_rfkill_pdev;
96 static struct rfkill *amilo_rfkill_dev;
98 static int amilo_rfkill_probe(struct platform_device *device)
100 int rc;
101 const struct dmi_system_id *system_id =
102 dmi_first_match(amilo_rfkill_id_table);
104 if (!system_id)
105 return -ENXIO;
107 amilo_rfkill_dev = rfkill_alloc(KBUILD_MODNAME, &device->dev,
108 RFKILL_TYPE_WLAN,
109 system_id->driver_data, NULL);
110 if (!amilo_rfkill_dev)
111 return -ENOMEM;
113 rc = rfkill_register(amilo_rfkill_dev);
114 if (rc)
115 goto fail;
117 return 0;
119 fail:
120 rfkill_destroy(amilo_rfkill_dev);
121 return rc;
124 static int amilo_rfkill_remove(struct platform_device *device)
126 rfkill_unregister(amilo_rfkill_dev);
127 rfkill_destroy(amilo_rfkill_dev);
128 return 0;
131 static struct platform_driver amilo_rfkill_driver = {
132 .driver = {
133 .name = KBUILD_MODNAME,
134 .owner = THIS_MODULE,
136 .probe = amilo_rfkill_probe,
137 .remove = amilo_rfkill_remove,
140 static int __init amilo_rfkill_init(void)
142 int rc;
144 if (dmi_first_match(amilo_rfkill_id_table) == NULL)
145 return -ENODEV;
147 rc = platform_driver_register(&amilo_rfkill_driver);
148 if (rc)
149 return rc;
151 amilo_rfkill_pdev = platform_device_register_simple(KBUILD_MODNAME, -1,
152 NULL, 0);
153 if (IS_ERR(amilo_rfkill_pdev)) {
154 rc = PTR_ERR(amilo_rfkill_pdev);
155 goto fail;
158 return 0;
160 fail:
161 platform_driver_unregister(&amilo_rfkill_driver);
162 return rc;
165 static void __exit amilo_rfkill_exit(void)
167 platform_device_unregister(amilo_rfkill_pdev);
168 platform_driver_unregister(&amilo_rfkill_driver);
171 MODULE_AUTHOR("Ben Hutchings <ben@decadent.org.uk>");
172 MODULE_LICENSE("GPL");
173 MODULE_DEVICE_TABLE(dmi, amilo_rfkill_id_table);
175 module_init(amilo_rfkill_init);
176 module_exit(amilo_rfkill_exit);