2 * HP Compaq TC1100 Tablet WMI Extras Driver
4 * Copyright (C) 2007 Carlos Corbacho <carlos@strangeworlds.co.uk>
5 * Copyright (C) 2004 Jamey Hicks <jamey.hicks@hp.com>
6 * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
7 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
9 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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 (at
14 * 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 along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
28 #include <linux/kernel.h>
29 #include <linux/module.h>
30 #include <linux/slab.h>
31 #include <linux/init.h>
32 #include <linux/types.h>
33 #include <acpi/acpi.h>
34 #include <acpi/acpi_bus.h>
35 #include <acpi/acpi_drivers.h>
36 #include <linux/platform_device.h>
38 #define GUID "C364AC71-36DB-495A-8494-B439D472A505"
40 #define TC1100_INSTANCE_WIRELESS 1
41 #define TC1100_INSTANCE_JOGDIAL 2
43 #define TC1100_LOGPREFIX "tc1100-wmi: "
44 #define TC1100_INFO KERN_INFO TC1100_LOGPREFIX
46 MODULE_AUTHOR("Jamey Hicks, Carlos Corbacho");
47 MODULE_DESCRIPTION("HP Compaq TC1100 Tablet WMI Extras");
48 MODULE_LICENSE("GPL");
49 MODULE_ALIAS("wmi:C364AC71-36DB-495A-8494-B439D472A505");
51 static struct platform_device
*tc1100_device
;
58 static struct tc1100_data suspend_data
;
60 /* --------------------------------------------------------------------------
62 -------------------------------------------------------------------------- */
64 static int get_state(u32
*out
, u8 instance
)
68 struct acpi_buffer result
= { ACPI_ALLOCATE_BUFFER
, NULL
};
69 union acpi_object
*obj
;
77 status
= wmi_query_block(GUID
, instance
, &result
);
78 if (ACPI_FAILURE(status
))
81 obj
= (union acpi_object
*) result
.pointer
;
82 if (obj
&& obj
->type
== ACPI_TYPE_INTEGER
) {
83 tmp
= obj
->integer
.value
;
88 if (result
.length
> 0 && result
.pointer
)
89 kfree(result
.pointer
);
92 case TC1100_INSTANCE_WIRELESS
:
93 *out
= (tmp
== 3) ? 1 : 0;
95 case TC1100_INSTANCE_JOGDIAL
:
96 *out
= (tmp
== 1) ? 0 : 1;
103 static int set_state(u32
*in
, u8 instance
)
107 struct acpi_buffer input
;
116 case TC1100_INSTANCE_WIRELESS
:
117 value
= (*in
) ? 1 : 2;
119 case TC1100_INSTANCE_JOGDIAL
:
120 value
= (*in
) ? 0 : 1;
126 input
.length
= sizeof(u32
);
127 input
.pointer
= &value
;
129 status
= wmi_set_block(GUID
, instance
, &input
);
130 if (ACPI_FAILURE(status
))
136 /* --------------------------------------------------------------------------
138 -------------------------------------------------------------------------- */
141 * Read/ write bool sysfs macro
143 #define show_set_bool(value, instance) \
145 show_bool_##value(struct device *dev, struct device_attribute *attr, \
149 acpi_status status = get_state(&result, instance); \
150 if (ACPI_SUCCESS(status)) \
151 return sprintf(buf, "%d\n", result); \
152 return sprintf(buf, "Read error\n"); \
156 set_bool_##value(struct device *dev, struct device_attribute *attr, \
157 const char *buf, size_t count) \
159 u32 tmp = simple_strtoul(buf, NULL, 10); \
160 acpi_status status = set_state(&tmp, instance); \
161 if (ACPI_FAILURE(status)) \
165 static DEVICE_ATTR(value, S_IWUGO | S_IRUGO | S_IWUSR, \
166 show_bool_##value, set_bool_##value);
168 show_set_bool(wireless
, TC1100_INSTANCE_WIRELESS
);
169 show_set_bool(jogdial
, TC1100_INSTANCE_JOGDIAL
);
171 static struct attribute
*tc1100_attributes
[] = {
172 &dev_attr_wireless
.attr
,
173 &dev_attr_jogdial
.attr
,
177 static struct attribute_group tc1100_attribute_group
= {
178 .attrs
= tc1100_attributes
,
181 /* --------------------------------------------------------------------------
183 -------------------------------------------------------------------------- */
185 static int __init
tc1100_probe(struct platform_device
*device
)
187 return sysfs_create_group(&device
->dev
.kobj
, &tc1100_attribute_group
);
191 static int __devexit
tc1100_remove(struct platform_device
*device
)
193 sysfs_remove_group(&device
->dev
.kobj
, &tc1100_attribute_group
);
199 static int tc1100_suspend(struct device
*dev
)
203 ret
= get_state(&suspend_data
.wireless
, TC1100_INSTANCE_WIRELESS
);
207 ret
= get_state(&suspend_data
.jogdial
, TC1100_INSTANCE_JOGDIAL
);
214 static int tc1100_resume(struct device
*dev
)
218 ret
= set_state(&suspend_data
.wireless
, TC1100_INSTANCE_WIRELESS
);
222 ret
= set_state(&suspend_data
.jogdial
, TC1100_INSTANCE_JOGDIAL
);
229 static const struct dev_pm_ops tc1100_pm_ops
= {
230 .suspend
= tc1100_suspend
,
231 .resume
= tc1100_resume
,
232 .freeze
= tc1100_suspend
,
233 .restore
= tc1100_resume
,
237 static struct platform_driver tc1100_driver
= {
239 .name
= "tc1100-wmi",
240 .owner
= THIS_MODULE
,
242 .pm
= &tc1100_pm_ops
,
245 .remove
= __devexit_p(tc1100_remove
),
248 static int __init
tc1100_init(void)
252 if (!wmi_has_guid(GUID
))
255 tc1100_device
= platform_device_alloc("tc1100-wmi", -1);
259 error
= platform_device_add(tc1100_device
);
263 error
= platform_driver_probe(&tc1100_driver
, tc1100_probe
);
267 printk(TC1100_INFO
"HP Compaq TC1100 Tablet WMI Extras loaded\n");
271 platform_device_del(tc1100_device
);
273 platform_device_put(tc1100_device
);
277 static void __exit
tc1100_exit(void)
279 platform_device_unregister(tc1100_device
);
280 platform_driver_unregister(&tc1100_driver
);
283 module_init(tc1100_init
);
284 module_exit(tc1100_exit
);