Loading...
1/*
2 * Support for rfkill on some Fujitsu-Siemens Amilo laptops.
3 * Copyright 2011 Ben Hutchings.
4 *
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.
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
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>
23
24/*
25 * These values were obtained from disassembling and debugging the
26 * PM.exe program installed in the Fujitsu-Siemens AMILO A1655G
27 */
28#define A1655_WIFI_COMMAND 0x10C5
29#define A1655_WIFI_ON 0x25
30#define A1655_WIFI_OFF 0x45
31
32static int amilo_a1655_rfkill_set_block(void *data, bool blocked)
33{
34 u8 param = blocked ? A1655_WIFI_OFF : A1655_WIFI_ON;
35 int rc;
36
37 i8042_lock_chip();
38 rc = i8042_command(¶m, A1655_WIFI_COMMAND);
39 i8042_unlock_chip();
40 return rc;
41}
42
43static const struct rfkill_ops amilo_a1655_rfkill_ops = {
44 .set_block = amilo_a1655_rfkill_set_block
45};
46
47/*
48 * These values were obtained from disassembling the PM.exe program
49 * installed in the Fujitsu-Siemens AMILO M 7440
50 */
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
57
58static int amilo_m7440_rfkill_set_block(void *data, bool blocked)
59{
60 u8 val1 = blocked ? M7440_RADIO_OFF1 : M7440_RADIO_ON1;
61 u8 val2 = blocked ? M7440_RADIO_OFF2 : M7440_RADIO_ON2;
62
63 outb(val1, M7440_PORT1);
64 outb(val2, M7440_PORT2);
65
66 /* Check whether the state has changed correctly */
67 if (inb(M7440_PORT1) != val1 || inb(M7440_PORT2) != val2)
68 return -EIO;
69
70 return 0;
71}
72
73static const struct rfkill_ops amilo_m7440_rfkill_ops = {
74 .set_block = amilo_m7440_rfkill_set_block
75};
76
77static const struct dmi_system_id amilo_rfkill_id_table[] = {
78 {
79 .matches = {
80 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
81 DMI_MATCH(DMI_BOARD_NAME, "AMILO A1655"),
82 },
83 .driver_data = (void *)&amilo_a1655_rfkill_ops
84 },
85 {
86 .matches = {
87 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
88 DMI_MATCH(DMI_BOARD_NAME, "AMILO L1310"),
89 },
90 .driver_data = (void *)&amilo_a1655_rfkill_ops
91 },
92 {
93 .matches = {
94 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
95 DMI_MATCH(DMI_BOARD_NAME, "AMILO M7440"),
96 },
97 .driver_data = (void *)&amilo_m7440_rfkill_ops
98 },
99 {}
100};
101
102static struct platform_device *amilo_rfkill_pdev;
103static struct rfkill *amilo_rfkill_dev;
104
105static int amilo_rfkill_probe(struct platform_device *device)
106{
107 int rc;
108 const struct dmi_system_id *system_id =
109 dmi_first_match(amilo_rfkill_id_table);
110
111 if (!system_id)
112 return -ENXIO;
113
114 amilo_rfkill_dev = rfkill_alloc(KBUILD_MODNAME, &device->dev,
115 RFKILL_TYPE_WLAN,
116 system_id->driver_data, NULL);
117 if (!amilo_rfkill_dev)
118 return -ENOMEM;
119
120 rc = rfkill_register(amilo_rfkill_dev);
121 if (rc)
122 goto fail;
123
124 return 0;
125
126fail:
127 rfkill_destroy(amilo_rfkill_dev);
128 return rc;
129}
130
131static int amilo_rfkill_remove(struct platform_device *device)
132{
133 rfkill_unregister(amilo_rfkill_dev);
134 rfkill_destroy(amilo_rfkill_dev);
135 return 0;
136}
137
138static struct platform_driver amilo_rfkill_driver = {
139 .driver = {
140 .name = KBUILD_MODNAME,
141 },
142 .probe = amilo_rfkill_probe,
143 .remove = amilo_rfkill_remove,
144};
145
146static int __init amilo_rfkill_init(void)
147{
148 int rc;
149
150 if (dmi_first_match(amilo_rfkill_id_table) == NULL)
151 return -ENODEV;
152
153 rc = platform_driver_register(&amilo_rfkill_driver);
154 if (rc)
155 return rc;
156
157 amilo_rfkill_pdev = platform_device_register_simple(KBUILD_MODNAME, -1,
158 NULL, 0);
159 if (IS_ERR(amilo_rfkill_pdev)) {
160 rc = PTR_ERR(amilo_rfkill_pdev);
161 goto fail;
162 }
163
164 return 0;
165
166fail:
167 platform_driver_unregister(&amilo_rfkill_driver);
168 return rc;
169}
170
171static void __exit amilo_rfkill_exit(void)
172{
173 platform_device_unregister(amilo_rfkill_pdev);
174 platform_driver_unregister(&amilo_rfkill_driver);
175}
176
177MODULE_AUTHOR("Ben Hutchings <ben@decadent.org.uk>");
178MODULE_LICENSE("GPL");
179MODULE_DEVICE_TABLE(dmi, amilo_rfkill_id_table);
180
181module_init(amilo_rfkill_init);
182module_exit(amilo_rfkill_exit);
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Support for rfkill on some Fujitsu-Siemens Amilo laptops.
4 * Copyright 2011 Ben Hutchings.
5 *
6 * Based in part on the fsam7440 driver, which is:
7 * Copyright 2005 Alejandro Vidal Mata & Javier Vidal Mata.
8 * and on the fsaa1655g driver, which is:
9 * Copyright 2006 Martin Večeřa.
10 */
11
12#include <linux/module.h>
13#include <linux/dmi.h>
14#include <linux/i8042.h>
15#include <linux/io.h>
16#include <linux/moduleparam.h>
17#include <linux/platform_device.h>
18#include <linux/rfkill.h>
19
20/*
21 * These values were obtained from disassembling and debugging the
22 * PM.exe program installed in the Fujitsu-Siemens AMILO A1655G
23 */
24#define A1655_WIFI_COMMAND 0x10C5
25#define A1655_WIFI_ON 0x25
26#define A1655_WIFI_OFF 0x45
27
28static int amilo_a1655_rfkill_set_block(void *data, bool blocked)
29{
30 u8 param = blocked ? A1655_WIFI_OFF : A1655_WIFI_ON;
31 int rc;
32
33 i8042_lock_chip();
34 rc = i8042_command(¶m, A1655_WIFI_COMMAND);
35 i8042_unlock_chip();
36 return rc;
37}
38
39static const struct rfkill_ops amilo_a1655_rfkill_ops = {
40 .set_block = amilo_a1655_rfkill_set_block
41};
42
43/*
44 * These values were obtained from disassembling the PM.exe program
45 * installed in the Fujitsu-Siemens AMILO M 7440
46 */
47#define M7440_PORT1 0x118f
48#define M7440_PORT2 0x118e
49#define M7440_RADIO_ON1 0x12
50#define M7440_RADIO_ON2 0x80
51#define M7440_RADIO_OFF1 0x10
52#define M7440_RADIO_OFF2 0x00
53
54static int amilo_m7440_rfkill_set_block(void *data, bool blocked)
55{
56 u8 val1 = blocked ? M7440_RADIO_OFF1 : M7440_RADIO_ON1;
57 u8 val2 = blocked ? M7440_RADIO_OFF2 : M7440_RADIO_ON2;
58
59 outb(val1, M7440_PORT1);
60 outb(val2, M7440_PORT2);
61
62 /* Check whether the state has changed correctly */
63 if (inb(M7440_PORT1) != val1 || inb(M7440_PORT2) != val2)
64 return -EIO;
65
66 return 0;
67}
68
69static const struct rfkill_ops amilo_m7440_rfkill_ops = {
70 .set_block = amilo_m7440_rfkill_set_block
71};
72
73static const struct dmi_system_id amilo_rfkill_id_table[] = {
74 {
75 .matches = {
76 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
77 DMI_MATCH(DMI_BOARD_NAME, "AMILO A1655"),
78 },
79 .driver_data = (void *)&amilo_a1655_rfkill_ops
80 },
81 {
82 .matches = {
83 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
84 DMI_MATCH(DMI_BOARD_NAME, "AMILO L1310"),
85 },
86 .driver_data = (void *)&amilo_a1655_rfkill_ops
87 },
88 {
89 .matches = {
90 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
91 DMI_MATCH(DMI_BOARD_NAME, "AMILO M7440"),
92 },
93 .driver_data = (void *)&amilo_m7440_rfkill_ops
94 },
95 {}
96};
97
98static struct platform_device *amilo_rfkill_pdev;
99static struct rfkill *amilo_rfkill_dev;
100
101static int amilo_rfkill_probe(struct platform_device *device)
102{
103 int rc;
104 const struct dmi_system_id *system_id =
105 dmi_first_match(amilo_rfkill_id_table);
106
107 if (!system_id)
108 return -ENXIO;
109
110 amilo_rfkill_dev = rfkill_alloc(KBUILD_MODNAME, &device->dev,
111 RFKILL_TYPE_WLAN,
112 system_id->driver_data, NULL);
113 if (!amilo_rfkill_dev)
114 return -ENOMEM;
115
116 rc = rfkill_register(amilo_rfkill_dev);
117 if (rc)
118 goto fail;
119
120 return 0;
121
122fail:
123 rfkill_destroy(amilo_rfkill_dev);
124 return rc;
125}
126
127static int amilo_rfkill_remove(struct platform_device *device)
128{
129 rfkill_unregister(amilo_rfkill_dev);
130 rfkill_destroy(amilo_rfkill_dev);
131 return 0;
132}
133
134static struct platform_driver amilo_rfkill_driver = {
135 .driver = {
136 .name = KBUILD_MODNAME,
137 },
138 .probe = amilo_rfkill_probe,
139 .remove = amilo_rfkill_remove,
140};
141
142static int __init amilo_rfkill_init(void)
143{
144 int rc;
145
146 if (dmi_first_match(amilo_rfkill_id_table) == NULL)
147 return -ENODEV;
148
149 rc = platform_driver_register(&amilo_rfkill_driver);
150 if (rc)
151 return rc;
152
153 amilo_rfkill_pdev = platform_device_register_simple(KBUILD_MODNAME,
154 PLATFORM_DEVID_NONE,
155 NULL, 0);
156 if (IS_ERR(amilo_rfkill_pdev)) {
157 rc = PTR_ERR(amilo_rfkill_pdev);
158 goto fail;
159 }
160
161 return 0;
162
163fail:
164 platform_driver_unregister(&amilo_rfkill_driver);
165 return rc;
166}
167
168static void __exit amilo_rfkill_exit(void)
169{
170 platform_device_unregister(amilo_rfkill_pdev);
171 platform_driver_unregister(&amilo_rfkill_driver);
172}
173
174MODULE_AUTHOR("Ben Hutchings <ben@decadent.org.uk>");
175MODULE_LICENSE("GPL");
176MODULE_DEVICE_TABLE(dmi, amilo_rfkill_id_table);
177
178module_init(amilo_rfkill_init);
179module_exit(amilo_rfkill_exit);