0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
0012
0013 #include <linux/kernel.h>
0014 #include <linux/module.h>
0015 #include <linux/slab.h>
0016 #include <linux/init.h>
0017 #include <linux/types.h>
0018 #include <linux/acpi.h>
0019 #include <linux/platform_device.h>
0020
0021 #define GUID "C364AC71-36DB-495A-8494-B439D472A505"
0022
0023 #define TC1100_INSTANCE_WIRELESS 1
0024 #define TC1100_INSTANCE_JOGDIAL 2
0025
0026 MODULE_AUTHOR("Jamey Hicks, Carlos Corbacho");
0027 MODULE_DESCRIPTION("HP Compaq TC1100 Tablet WMI Extras");
0028 MODULE_LICENSE("GPL");
0029 MODULE_ALIAS("wmi:C364AC71-36DB-495A-8494-B439D472A505");
0030
0031 static struct platform_device *tc1100_device;
0032
0033 struct tc1100_data {
0034 u32 wireless;
0035 u32 jogdial;
0036 };
0037
0038 #ifdef CONFIG_PM
0039 static struct tc1100_data suspend_data;
0040 #endif
0041
0042
0043
0044
0045
0046 static int get_state(u32 *out, u8 instance)
0047 {
0048 u32 tmp;
0049 acpi_status status;
0050 struct acpi_buffer result = { ACPI_ALLOCATE_BUFFER, NULL };
0051 union acpi_object *obj;
0052
0053 if (!out)
0054 return -EINVAL;
0055
0056 if (instance > 2)
0057 return -ENODEV;
0058
0059 status = wmi_query_block(GUID, instance, &result);
0060 if (ACPI_FAILURE(status))
0061 return -ENODEV;
0062
0063 obj = (union acpi_object *) result.pointer;
0064 if (obj && obj->type == ACPI_TYPE_INTEGER) {
0065 tmp = obj->integer.value;
0066 } else {
0067 tmp = 0;
0068 }
0069
0070 if (result.length > 0)
0071 kfree(result.pointer);
0072
0073 switch (instance) {
0074 case TC1100_INSTANCE_WIRELESS:
0075 *out = (tmp == 3) ? 1 : 0;
0076 return 0;
0077 case TC1100_INSTANCE_JOGDIAL:
0078 *out = (tmp == 1) ? 0 : 1;
0079 return 0;
0080 default:
0081 return -ENODEV;
0082 }
0083 }
0084
0085 static int set_state(u32 *in, u8 instance)
0086 {
0087 u32 value;
0088 acpi_status status;
0089 struct acpi_buffer input;
0090
0091 if (!in)
0092 return -EINVAL;
0093
0094 if (instance > 2)
0095 return -ENODEV;
0096
0097 switch (instance) {
0098 case TC1100_INSTANCE_WIRELESS:
0099 value = (*in) ? 1 : 2;
0100 break;
0101 case TC1100_INSTANCE_JOGDIAL:
0102 value = (*in) ? 0 : 1;
0103 break;
0104 default:
0105 return -ENODEV;
0106 }
0107
0108 input.length = sizeof(u32);
0109 input.pointer = &value;
0110
0111 status = wmi_set_block(GUID, instance, &input);
0112 if (ACPI_FAILURE(status))
0113 return -ENODEV;
0114
0115 return 0;
0116 }
0117
0118
0119
0120
0121
0122
0123
0124
0125 #define show_set_bool(value, instance) \
0126 static ssize_t \
0127 show_bool_##value(struct device *dev, struct device_attribute *attr, \
0128 char *buf) \
0129 { \
0130 u32 result; \
0131 acpi_status status = get_state(&result, instance); \
0132 if (ACPI_SUCCESS(status)) \
0133 return sprintf(buf, "%d\n", result); \
0134 return sprintf(buf, "Read error\n"); \
0135 } \
0136 \
0137 static ssize_t \
0138 set_bool_##value(struct device *dev, struct device_attribute *attr, \
0139 const char *buf, size_t count) \
0140 { \
0141 u32 tmp = simple_strtoul(buf, NULL, 10); \
0142 acpi_status status = set_state(&tmp, instance); \
0143 if (ACPI_FAILURE(status)) \
0144 return -EINVAL; \
0145 return count; \
0146 } \
0147 static DEVICE_ATTR(value, S_IRUGO | S_IWUSR, \
0148 show_bool_##value, set_bool_##value);
0149
0150 show_set_bool(wireless, TC1100_INSTANCE_WIRELESS);
0151 show_set_bool(jogdial, TC1100_INSTANCE_JOGDIAL);
0152
0153 static struct attribute *tc1100_attributes[] = {
0154 &dev_attr_wireless.attr,
0155 &dev_attr_jogdial.attr,
0156 NULL
0157 };
0158
0159 static const struct attribute_group tc1100_attribute_group = {
0160 .attrs = tc1100_attributes,
0161 };
0162
0163
0164
0165
0166
0167 static int __init tc1100_probe(struct platform_device *device)
0168 {
0169 return sysfs_create_group(&device->dev.kobj, &tc1100_attribute_group);
0170 }
0171
0172
0173 static int tc1100_remove(struct platform_device *device)
0174 {
0175 sysfs_remove_group(&device->dev.kobj, &tc1100_attribute_group);
0176
0177 return 0;
0178 }
0179
0180 #ifdef CONFIG_PM
0181 static int tc1100_suspend(struct device *dev)
0182 {
0183 int ret;
0184
0185 ret = get_state(&suspend_data.wireless, TC1100_INSTANCE_WIRELESS);
0186 if (ret)
0187 return ret;
0188
0189 ret = get_state(&suspend_data.jogdial, TC1100_INSTANCE_JOGDIAL);
0190 if (ret)
0191 return ret;
0192
0193 return 0;
0194 }
0195
0196 static int tc1100_resume(struct device *dev)
0197 {
0198 int ret;
0199
0200 ret = set_state(&suspend_data.wireless, TC1100_INSTANCE_WIRELESS);
0201 if (ret)
0202 return ret;
0203
0204 ret = set_state(&suspend_data.jogdial, TC1100_INSTANCE_JOGDIAL);
0205 if (ret)
0206 return ret;
0207
0208 return 0;
0209 }
0210
0211 static const struct dev_pm_ops tc1100_pm_ops = {
0212 .suspend = tc1100_suspend,
0213 .resume = tc1100_resume,
0214 .freeze = tc1100_suspend,
0215 .restore = tc1100_resume,
0216 };
0217 #endif
0218
0219 static struct platform_driver tc1100_driver = {
0220 .driver = {
0221 .name = "tc1100-wmi",
0222 #ifdef CONFIG_PM
0223 .pm = &tc1100_pm_ops,
0224 #endif
0225 },
0226 .remove = tc1100_remove,
0227 };
0228
0229 static int __init tc1100_init(void)
0230 {
0231 int error;
0232
0233 if (!wmi_has_guid(GUID))
0234 return -ENODEV;
0235
0236 tc1100_device = platform_device_alloc("tc1100-wmi", -1);
0237 if (!tc1100_device)
0238 return -ENOMEM;
0239
0240 error = platform_device_add(tc1100_device);
0241 if (error)
0242 goto err_device_put;
0243
0244 error = platform_driver_probe(&tc1100_driver, tc1100_probe);
0245 if (error)
0246 goto err_device_del;
0247
0248 pr_info("HP Compaq TC1100 Tablet WMI Extras loaded\n");
0249 return 0;
0250
0251 err_device_del:
0252 platform_device_del(tc1100_device);
0253 err_device_put:
0254 platform_device_put(tc1100_device);
0255 return error;
0256 }
0257
0258 static void __exit tc1100_exit(void)
0259 {
0260 platform_device_unregister(tc1100_device);
0261 platform_driver_unregister(&tc1100_driver);
0262 }
0263
0264 module_init(tc1100_init);
0265 module_exit(tc1100_exit);