Luca Tettamanti | 2c03d07 | 2009-04-07 15:32:59 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007-2009 Luca Tettamanti <kronos.it@gmail.com> |
| 3 | * |
| 4 | * This file is released under the GPLv2 |
| 5 | * See COPYING in the top level directory of the kernel tree. |
| 6 | */ |
| 7 | |
Joe Perches | ac56149 | 2010-10-20 06:51:30 +0000 | [diff] [blame] | 8 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 9 | |
Luca Tettamanti | 7e5eab1 | 2010-01-10 20:52:33 +0100 | [diff] [blame] | 10 | #include <linux/debugfs.h> |
Luca Tettamanti | 2c03d07 | 2009-04-07 15:32:59 +0200 | [diff] [blame] | 11 | #include <linux/kernel.h> |
| 12 | #include <linux/hwmon.h> |
| 13 | #include <linux/list.h> |
| 14 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 15 | #include <linux/slab.h> |
Luca Tettamanti | 86ca33e | 2011-01-22 16:07:11 +0100 | [diff] [blame] | 16 | #include <linux/dmi.h> |
Luca Tettamanti | 2c03d07 | 2009-04-07 15:32:59 +0200 | [diff] [blame] | 17 | |
| 18 | #include <acpi/acpi.h> |
| 19 | #include <acpi/acpixf.h> |
| 20 | #include <acpi/acpi_drivers.h> |
| 21 | #include <acpi/acpi_bus.h> |
| 22 | |
| 23 | |
| 24 | #define ATK_HID "ATK0110" |
| 25 | |
Luca Tettamanti | 86ca33e | 2011-01-22 16:07:11 +0100 | [diff] [blame] | 26 | static bool new_if; |
| 27 | module_param(new_if, bool, 0); |
| 28 | MODULE_PARM_DESC(new_if, "Override detection heuristic and force the use of the new ATK0110 interface"); |
| 29 | |
| 30 | static const struct dmi_system_id __initconst atk_force_new_if[] = { |
| 31 | { |
| 32 | /* Old interface has broken MCH temp monitoring */ |
| 33 | .ident = "Asus Sabertooth X58", |
| 34 | .matches = { |
| 35 | DMI_MATCH(DMI_BOARD_NAME, "SABERTOOTH X58") |
| 36 | } |
| 37 | }, |
| 38 | { } |
| 39 | }; |
| 40 | |
Luca Tettamanti | 2c03d07 | 2009-04-07 15:32:59 +0200 | [diff] [blame] | 41 | /* Minimum time between readings, enforced in order to avoid |
| 42 | * hogging the CPU. |
| 43 | */ |
| 44 | #define CACHE_TIME HZ |
| 45 | |
| 46 | #define BOARD_ID "MBIF" |
| 47 | #define METHOD_ENUMERATE "GGRP" |
| 48 | #define METHOD_READ "GITM" |
| 49 | #define METHOD_WRITE "SITM" |
| 50 | #define METHOD_OLD_READ_TMP "RTMP" |
| 51 | #define METHOD_OLD_READ_VLT "RVLT" |
| 52 | #define METHOD_OLD_READ_FAN "RFAN" |
| 53 | #define METHOD_OLD_ENUM_TMP "TSIF" |
| 54 | #define METHOD_OLD_ENUM_VLT "VSIF" |
| 55 | #define METHOD_OLD_ENUM_FAN "FSIF" |
| 56 | |
| 57 | #define ATK_MUX_HWMON 0x00000006ULL |
Luca Tettamanti | 9e6eba6 | 2009-10-09 20:35:18 +0200 | [diff] [blame] | 58 | #define ATK_MUX_MGMT 0x00000011ULL |
Luca Tettamanti | 2c03d07 | 2009-04-07 15:32:59 +0200 | [diff] [blame] | 59 | |
| 60 | #define ATK_CLASS_MASK 0xff000000ULL |
| 61 | #define ATK_CLASS_FREQ_CTL 0x03000000ULL |
| 62 | #define ATK_CLASS_FAN_CTL 0x04000000ULL |
| 63 | #define ATK_CLASS_HWMON 0x06000000ULL |
Luca Tettamanti | 9e6eba6 | 2009-10-09 20:35:18 +0200 | [diff] [blame] | 64 | #define ATK_CLASS_MGMT 0x11000000ULL |
Luca Tettamanti | 2c03d07 | 2009-04-07 15:32:59 +0200 | [diff] [blame] | 65 | |
| 66 | #define ATK_TYPE_MASK 0x00ff0000ULL |
| 67 | #define HWMON_TYPE_VOLT 0x00020000ULL |
| 68 | #define HWMON_TYPE_TEMP 0x00030000ULL |
| 69 | #define HWMON_TYPE_FAN 0x00040000ULL |
| 70 | |
Luca Tettamanti | 9e6eba6 | 2009-10-09 20:35:18 +0200 | [diff] [blame] | 71 | #define ATK_ELEMENT_ID_MASK 0x0000ffffULL |
| 72 | |
| 73 | #define ATK_EC_ID 0x11060004ULL |
Luca Tettamanti | 2c03d07 | 2009-04-07 15:32:59 +0200 | [diff] [blame] | 74 | |
| 75 | enum atk_pack_member { |
| 76 | HWMON_PACK_FLAGS, |
| 77 | HWMON_PACK_NAME, |
| 78 | HWMON_PACK_LIMIT1, |
| 79 | HWMON_PACK_LIMIT2, |
| 80 | HWMON_PACK_ENABLE |
| 81 | }; |
| 82 | |
| 83 | /* New package format */ |
| 84 | #define _HWMON_NEW_PACK_SIZE 7 |
| 85 | #define _HWMON_NEW_PACK_FLAGS 0 |
| 86 | #define _HWMON_NEW_PACK_NAME 1 |
| 87 | #define _HWMON_NEW_PACK_UNK1 2 |
| 88 | #define _HWMON_NEW_PACK_UNK2 3 |
| 89 | #define _HWMON_NEW_PACK_LIMIT1 4 |
| 90 | #define _HWMON_NEW_PACK_LIMIT2 5 |
| 91 | #define _HWMON_NEW_PACK_ENABLE 6 |
| 92 | |
| 93 | /* Old package format */ |
| 94 | #define _HWMON_OLD_PACK_SIZE 5 |
| 95 | #define _HWMON_OLD_PACK_FLAGS 0 |
| 96 | #define _HWMON_OLD_PACK_NAME 1 |
| 97 | #define _HWMON_OLD_PACK_LIMIT1 2 |
| 98 | #define _HWMON_OLD_PACK_LIMIT2 3 |
| 99 | #define _HWMON_OLD_PACK_ENABLE 4 |
| 100 | |
| 101 | |
| 102 | struct atk_data { |
| 103 | struct device *hwmon_dev; |
| 104 | acpi_handle atk_handle; |
| 105 | struct acpi_device *acpi_dev; |
| 106 | |
| 107 | bool old_interface; |
| 108 | |
| 109 | /* old interface */ |
| 110 | acpi_handle rtmp_handle; |
| 111 | acpi_handle rvlt_handle; |
| 112 | acpi_handle rfan_handle; |
| 113 | /* new inteface */ |
| 114 | acpi_handle enumerate_handle; |
| 115 | acpi_handle read_handle; |
Luca Tettamanti | 9e6eba6 | 2009-10-09 20:35:18 +0200 | [diff] [blame] | 116 | acpi_handle write_handle; |
| 117 | |
| 118 | bool disable_ec; |
Luca Tettamanti | 2c03d07 | 2009-04-07 15:32:59 +0200 | [diff] [blame] | 119 | |
| 120 | int voltage_count; |
| 121 | int temperature_count; |
| 122 | int fan_count; |
| 123 | struct list_head sensor_list; |
Luca Tettamanti | 7e5eab1 | 2010-01-10 20:52:33 +0100 | [diff] [blame] | 124 | |
| 125 | struct { |
| 126 | struct dentry *root; |
| 127 | u32 id; |
| 128 | } debugfs; |
Luca Tettamanti | 2c03d07 | 2009-04-07 15:32:59 +0200 | [diff] [blame] | 129 | }; |
| 130 | |
| 131 | |
| 132 | typedef ssize_t (*sysfs_show_func)(struct device *dev, |
| 133 | struct device_attribute *attr, char *buf); |
| 134 | |
| 135 | static const struct acpi_device_id atk_ids[] = { |
| 136 | {ATK_HID, 0}, |
| 137 | {"", 0}, |
| 138 | }; |
| 139 | MODULE_DEVICE_TABLE(acpi, atk_ids); |
| 140 | |
| 141 | #define ATTR_NAME_SIZE 16 /* Worst case is "tempN_input" */ |
| 142 | |
| 143 | struct atk_sensor_data { |
| 144 | struct list_head list; |
| 145 | struct atk_data *data; |
| 146 | struct device_attribute label_attr; |
| 147 | struct device_attribute input_attr; |
| 148 | struct device_attribute limit1_attr; |
| 149 | struct device_attribute limit2_attr; |
| 150 | char label_attr_name[ATTR_NAME_SIZE]; |
| 151 | char input_attr_name[ATTR_NAME_SIZE]; |
| 152 | char limit1_attr_name[ATTR_NAME_SIZE]; |
| 153 | char limit2_attr_name[ATTR_NAME_SIZE]; |
| 154 | u64 id; |
| 155 | u64 type; |
| 156 | u64 limit1; |
| 157 | u64 limit2; |
| 158 | u64 cached_value; |
| 159 | unsigned long last_updated; /* in jiffies */ |
| 160 | bool is_valid; |
| 161 | char const *acpi_name; |
| 162 | }; |
| 163 | |
Luca Tettamanti | 18e25555 | 2009-10-09 20:35:18 +0200 | [diff] [blame] | 164 | /* Return buffer format: |
| 165 | * [0-3] "value" is valid flag |
| 166 | * [4-7] value |
| 167 | * [8- ] unknown stuff on newer mobos |
| 168 | */ |
| 169 | struct atk_acpi_ret_buffer { |
| 170 | u32 flags; |
| 171 | u32 value; |
| 172 | u8 data[]; |
| 173 | }; |
| 174 | |
| 175 | /* Input buffer used for GITM and SITM methods */ |
| 176 | struct atk_acpi_input_buf { |
| 177 | u32 id; |
| 178 | u32 param1; |
| 179 | u32 param2; |
Luca Tettamanti | 2c03d07 | 2009-04-07 15:32:59 +0200 | [diff] [blame] | 180 | }; |
| 181 | |
| 182 | static int atk_add(struct acpi_device *device); |
| 183 | static int atk_remove(struct acpi_device *device, int type); |
| 184 | static void atk_print_sensor(struct atk_data *data, union acpi_object *obj); |
| 185 | static int atk_read_value(struct atk_sensor_data *sensor, u64 *value); |
| 186 | static void atk_free_sensors(struct atk_data *data); |
| 187 | |
| 188 | static struct acpi_driver atk_driver = { |
| 189 | .name = ATK_HID, |
| 190 | .class = "hwmon", |
| 191 | .ids = atk_ids, |
| 192 | .ops = { |
| 193 | .add = atk_add, |
| 194 | .remove = atk_remove, |
| 195 | }, |
| 196 | }; |
| 197 | |
| 198 | #define input_to_atk_sensor(attr) \ |
| 199 | container_of(attr, struct atk_sensor_data, input_attr) |
| 200 | |
| 201 | #define label_to_atk_sensor(attr) \ |
| 202 | container_of(attr, struct atk_sensor_data, label_attr) |
| 203 | |
| 204 | #define limit1_to_atk_sensor(attr) \ |
| 205 | container_of(attr, struct atk_sensor_data, limit1_attr) |
| 206 | |
| 207 | #define limit2_to_atk_sensor(attr) \ |
| 208 | container_of(attr, struct atk_sensor_data, limit2_attr) |
| 209 | |
| 210 | static ssize_t atk_input_show(struct device *dev, |
| 211 | struct device_attribute *attr, char *buf) |
| 212 | { |
| 213 | struct atk_sensor_data *s = input_to_atk_sensor(attr); |
| 214 | u64 value; |
| 215 | int err; |
| 216 | |
| 217 | err = atk_read_value(s, &value); |
| 218 | if (err) |
| 219 | return err; |
| 220 | |
| 221 | if (s->type == HWMON_TYPE_TEMP) |
| 222 | /* ACPI returns decidegree */ |
| 223 | value *= 100; |
| 224 | |
| 225 | return sprintf(buf, "%llu\n", value); |
| 226 | } |
| 227 | |
| 228 | static ssize_t atk_label_show(struct device *dev, |
| 229 | struct device_attribute *attr, char *buf) |
| 230 | { |
| 231 | struct atk_sensor_data *s = label_to_atk_sensor(attr); |
| 232 | |
| 233 | return sprintf(buf, "%s\n", s->acpi_name); |
| 234 | } |
| 235 | |
| 236 | static ssize_t atk_limit1_show(struct device *dev, |
| 237 | struct device_attribute *attr, char *buf) |
| 238 | { |
| 239 | struct atk_sensor_data *s = limit1_to_atk_sensor(attr); |
| 240 | u64 value = s->limit1; |
| 241 | |
| 242 | if (s->type == HWMON_TYPE_TEMP) |
| 243 | value *= 100; |
| 244 | |
| 245 | return sprintf(buf, "%lld\n", value); |
| 246 | } |
| 247 | |
| 248 | static ssize_t atk_limit2_show(struct device *dev, |
| 249 | struct device_attribute *attr, char *buf) |
| 250 | { |
| 251 | struct atk_sensor_data *s = limit2_to_atk_sensor(attr); |
| 252 | u64 value = s->limit2; |
| 253 | |
| 254 | if (s->type == HWMON_TYPE_TEMP) |
| 255 | value *= 100; |
| 256 | |
| 257 | return sprintf(buf, "%lld\n", value); |
| 258 | } |
| 259 | |
| 260 | static ssize_t atk_name_show(struct device *dev, |
| 261 | struct device_attribute *attr, char *buf) |
| 262 | { |
| 263 | return sprintf(buf, "atk0110\n"); |
| 264 | } |
| 265 | static struct device_attribute atk_name_attr = |
| 266 | __ATTR(name, 0444, atk_name_show, NULL); |
| 267 | |
| 268 | static void atk_init_attribute(struct device_attribute *attr, char *name, |
| 269 | sysfs_show_func show) |
| 270 | { |
Guenter Roeck | 9a2d55b | 2011-05-24 12:19:05 -0700 | [diff] [blame] | 271 | sysfs_attr_init(&attr->attr); |
Luca Tettamanti | 2c03d07 | 2009-04-07 15:32:59 +0200 | [diff] [blame] | 272 | attr->attr.name = name; |
| 273 | attr->attr.mode = 0444; |
| 274 | attr->show = show; |
| 275 | attr->store = NULL; |
| 276 | } |
| 277 | |
| 278 | |
| 279 | static union acpi_object *atk_get_pack_member(struct atk_data *data, |
| 280 | union acpi_object *pack, |
| 281 | enum atk_pack_member m) |
| 282 | { |
| 283 | bool old_if = data->old_interface; |
| 284 | int offset; |
| 285 | |
| 286 | switch (m) { |
| 287 | case HWMON_PACK_FLAGS: |
| 288 | offset = old_if ? _HWMON_OLD_PACK_FLAGS : _HWMON_NEW_PACK_FLAGS; |
| 289 | break; |
| 290 | case HWMON_PACK_NAME: |
| 291 | offset = old_if ? _HWMON_OLD_PACK_NAME : _HWMON_NEW_PACK_NAME; |
| 292 | break; |
| 293 | case HWMON_PACK_LIMIT1: |
| 294 | offset = old_if ? _HWMON_OLD_PACK_LIMIT1 : |
| 295 | _HWMON_NEW_PACK_LIMIT1; |
| 296 | break; |
| 297 | case HWMON_PACK_LIMIT2: |
| 298 | offset = old_if ? _HWMON_OLD_PACK_LIMIT2 : |
| 299 | _HWMON_NEW_PACK_LIMIT2; |
| 300 | break; |
| 301 | case HWMON_PACK_ENABLE: |
| 302 | offset = old_if ? _HWMON_OLD_PACK_ENABLE : |
| 303 | _HWMON_NEW_PACK_ENABLE; |
| 304 | break; |
| 305 | default: |
| 306 | return NULL; |
| 307 | } |
| 308 | |
| 309 | return &pack->package.elements[offset]; |
| 310 | } |
| 311 | |
| 312 | |
| 313 | /* New package format is: |
| 314 | * - flag (int) |
| 315 | * class - used for de-muxing the request to the correct GITn |
| 316 | * type (volt, temp, fan) |
| 317 | * sensor id | |
| 318 | * sensor id - used for de-muxing the request _inside_ the GITn |
| 319 | * - name (str) |
| 320 | * - unknown (int) |
| 321 | * - unknown (int) |
| 322 | * - limit1 (int) |
| 323 | * - limit2 (int) |
| 324 | * - enable (int) |
| 325 | * |
| 326 | * The old package has the same format but it's missing the two unknown fields. |
| 327 | */ |
| 328 | static int validate_hwmon_pack(struct atk_data *data, union acpi_object *obj) |
| 329 | { |
| 330 | struct device *dev = &data->acpi_dev->dev; |
| 331 | union acpi_object *tmp; |
| 332 | bool old_if = data->old_interface; |
| 333 | int const expected_size = old_if ? _HWMON_OLD_PACK_SIZE : |
| 334 | _HWMON_NEW_PACK_SIZE; |
| 335 | |
| 336 | if (obj->type != ACPI_TYPE_PACKAGE) { |
| 337 | dev_warn(dev, "Invalid type: %d\n", obj->type); |
| 338 | return -EINVAL; |
| 339 | } |
| 340 | |
| 341 | if (obj->package.count != expected_size) { |
| 342 | dev_warn(dev, "Invalid package size: %d, expected: %d\n", |
| 343 | obj->package.count, expected_size); |
| 344 | return -EINVAL; |
| 345 | } |
| 346 | |
| 347 | tmp = atk_get_pack_member(data, obj, HWMON_PACK_FLAGS); |
| 348 | if (tmp->type != ACPI_TYPE_INTEGER) { |
| 349 | dev_warn(dev, "Invalid type (flag): %d\n", tmp->type); |
| 350 | return -EINVAL; |
| 351 | } |
| 352 | |
| 353 | tmp = atk_get_pack_member(data, obj, HWMON_PACK_NAME); |
| 354 | if (tmp->type != ACPI_TYPE_STRING) { |
| 355 | dev_warn(dev, "Invalid type (name): %d\n", tmp->type); |
| 356 | return -EINVAL; |
| 357 | } |
| 358 | |
| 359 | /* Don't check... we don't know what they're useful for anyway */ |
| 360 | #if 0 |
| 361 | tmp = &obj->package.elements[HWMON_PACK_UNK1]; |
| 362 | if (tmp->type != ACPI_TYPE_INTEGER) { |
| 363 | dev_warn(dev, "Invalid type (unk1): %d\n", tmp->type); |
| 364 | return -EINVAL; |
| 365 | } |
| 366 | |
| 367 | tmp = &obj->package.elements[HWMON_PACK_UNK2]; |
| 368 | if (tmp->type != ACPI_TYPE_INTEGER) { |
| 369 | dev_warn(dev, "Invalid type (unk2): %d\n", tmp->type); |
| 370 | return -EINVAL; |
| 371 | } |
| 372 | #endif |
| 373 | |
| 374 | tmp = atk_get_pack_member(data, obj, HWMON_PACK_LIMIT1); |
| 375 | if (tmp->type != ACPI_TYPE_INTEGER) { |
| 376 | dev_warn(dev, "Invalid type (limit1): %d\n", tmp->type); |
| 377 | return -EINVAL; |
| 378 | } |
| 379 | |
| 380 | tmp = atk_get_pack_member(data, obj, HWMON_PACK_LIMIT2); |
| 381 | if (tmp->type != ACPI_TYPE_INTEGER) { |
| 382 | dev_warn(dev, "Invalid type (limit2): %d\n", tmp->type); |
| 383 | return -EINVAL; |
| 384 | } |
| 385 | |
| 386 | tmp = atk_get_pack_member(data, obj, HWMON_PACK_ENABLE); |
| 387 | if (tmp->type != ACPI_TYPE_INTEGER) { |
| 388 | dev_warn(dev, "Invalid type (enable): %d\n", tmp->type); |
| 389 | return -EINVAL; |
| 390 | } |
| 391 | |
| 392 | atk_print_sensor(data, obj); |
| 393 | |
| 394 | return 0; |
| 395 | } |
| 396 | |
Luca Tettamanti | b900870 | 2009-05-08 20:27:28 +0200 | [diff] [blame] | 397 | #ifdef DEBUG |
Luca Tettamanti | 2c03d07 | 2009-04-07 15:32:59 +0200 | [diff] [blame] | 398 | static char const *atk_sensor_type(union acpi_object *flags) |
| 399 | { |
| 400 | u64 type = flags->integer.value & ATK_TYPE_MASK; |
| 401 | char const *what; |
| 402 | |
| 403 | switch (type) { |
| 404 | case HWMON_TYPE_VOLT: |
| 405 | what = "voltage"; |
| 406 | break; |
| 407 | case HWMON_TYPE_TEMP: |
| 408 | what = "temperature"; |
| 409 | break; |
| 410 | case HWMON_TYPE_FAN: |
| 411 | what = "fan"; |
| 412 | break; |
| 413 | default: |
| 414 | what = "unknown"; |
| 415 | break; |
| 416 | } |
| 417 | |
| 418 | return what; |
| 419 | } |
Luca Tettamanti | b900870 | 2009-05-08 20:27:28 +0200 | [diff] [blame] | 420 | #endif |
Luca Tettamanti | 2c03d07 | 2009-04-07 15:32:59 +0200 | [diff] [blame] | 421 | |
| 422 | static void atk_print_sensor(struct atk_data *data, union acpi_object *obj) |
| 423 | { |
| 424 | #ifdef DEBUG |
| 425 | struct device *dev = &data->acpi_dev->dev; |
| 426 | union acpi_object *flags; |
| 427 | union acpi_object *name; |
| 428 | union acpi_object *limit1; |
| 429 | union acpi_object *limit2; |
| 430 | union acpi_object *enable; |
| 431 | char const *what; |
| 432 | |
| 433 | flags = atk_get_pack_member(data, obj, HWMON_PACK_FLAGS); |
| 434 | name = atk_get_pack_member(data, obj, HWMON_PACK_NAME); |
| 435 | limit1 = atk_get_pack_member(data, obj, HWMON_PACK_LIMIT1); |
| 436 | limit2 = atk_get_pack_member(data, obj, HWMON_PACK_LIMIT2); |
| 437 | enable = atk_get_pack_member(data, obj, HWMON_PACK_ENABLE); |
| 438 | |
| 439 | what = atk_sensor_type(flags); |
| 440 | |
| 441 | dev_dbg(dev, "%s: %#llx %s [%llu-%llu] %s\n", what, |
| 442 | flags->integer.value, |
| 443 | name->string.pointer, |
| 444 | limit1->integer.value, limit2->integer.value, |
| 445 | enable->integer.value ? "enabled" : "disabled"); |
| 446 | #endif |
| 447 | } |
| 448 | |
| 449 | static int atk_read_value_old(struct atk_sensor_data *sensor, u64 *value) |
| 450 | { |
| 451 | struct atk_data *data = sensor->data; |
| 452 | struct device *dev = &data->acpi_dev->dev; |
| 453 | struct acpi_object_list params; |
| 454 | union acpi_object id; |
| 455 | acpi_status status; |
| 456 | acpi_handle method; |
| 457 | |
| 458 | switch (sensor->type) { |
| 459 | case HWMON_TYPE_VOLT: |
| 460 | method = data->rvlt_handle; |
| 461 | break; |
| 462 | case HWMON_TYPE_TEMP: |
| 463 | method = data->rtmp_handle; |
| 464 | break; |
| 465 | case HWMON_TYPE_FAN: |
| 466 | method = data->rfan_handle; |
| 467 | break; |
| 468 | default: |
| 469 | return -EINVAL; |
| 470 | } |
| 471 | |
| 472 | id.type = ACPI_TYPE_INTEGER; |
| 473 | id.integer.value = sensor->id; |
| 474 | |
| 475 | params.count = 1; |
| 476 | params.pointer = &id; |
| 477 | |
| 478 | status = acpi_evaluate_integer(method, NULL, ¶ms, value); |
| 479 | if (status != AE_OK) { |
| 480 | dev_warn(dev, "%s: ACPI exception: %s\n", __func__, |
| 481 | acpi_format_exception(status)); |
| 482 | return -EIO; |
| 483 | } |
| 484 | |
| 485 | return 0; |
| 486 | } |
| 487 | |
Luca Tettamanti | 18e25555 | 2009-10-09 20:35:18 +0200 | [diff] [blame] | 488 | static union acpi_object *atk_ggrp(struct atk_data *data, u16 mux) |
| 489 | { |
| 490 | struct device *dev = &data->acpi_dev->dev; |
| 491 | struct acpi_buffer buf; |
| 492 | acpi_status ret; |
| 493 | struct acpi_object_list params; |
| 494 | union acpi_object id; |
| 495 | union acpi_object *pack; |
| 496 | |
| 497 | id.type = ACPI_TYPE_INTEGER; |
| 498 | id.integer.value = mux; |
| 499 | params.count = 1; |
| 500 | params.pointer = &id; |
| 501 | |
| 502 | buf.length = ACPI_ALLOCATE_BUFFER; |
| 503 | ret = acpi_evaluate_object(data->enumerate_handle, NULL, ¶ms, &buf); |
| 504 | if (ret != AE_OK) { |
| 505 | dev_err(dev, "GGRP[%#x] ACPI exception: %s\n", mux, |
| 506 | acpi_format_exception(ret)); |
| 507 | return ERR_PTR(-EIO); |
| 508 | } |
| 509 | pack = buf.pointer; |
| 510 | if (pack->type != ACPI_TYPE_PACKAGE) { |
| 511 | /* Execution was successful, but the id was not found */ |
| 512 | ACPI_FREE(pack); |
| 513 | return ERR_PTR(-ENOENT); |
| 514 | } |
| 515 | |
| 516 | if (pack->package.count < 1) { |
| 517 | dev_err(dev, "GGRP[%#x] package is too small\n", mux); |
| 518 | ACPI_FREE(pack); |
| 519 | return ERR_PTR(-EIO); |
| 520 | } |
| 521 | return pack; |
| 522 | } |
| 523 | |
| 524 | static union acpi_object *atk_gitm(struct atk_data *data, u64 id) |
| 525 | { |
| 526 | struct device *dev = &data->acpi_dev->dev; |
| 527 | struct atk_acpi_input_buf buf; |
| 528 | union acpi_object tmp; |
| 529 | struct acpi_object_list params; |
| 530 | struct acpi_buffer ret; |
| 531 | union acpi_object *obj; |
| 532 | acpi_status status; |
| 533 | |
| 534 | buf.id = id; |
| 535 | buf.param1 = 0; |
| 536 | buf.param2 = 0; |
| 537 | |
| 538 | tmp.type = ACPI_TYPE_BUFFER; |
| 539 | tmp.buffer.pointer = (u8 *)&buf; |
| 540 | tmp.buffer.length = sizeof(buf); |
| 541 | |
| 542 | params.count = 1; |
| 543 | params.pointer = (void *)&tmp; |
| 544 | |
| 545 | ret.length = ACPI_ALLOCATE_BUFFER; |
| 546 | status = acpi_evaluate_object_typed(data->read_handle, NULL, ¶ms, |
| 547 | &ret, ACPI_TYPE_BUFFER); |
| 548 | if (status != AE_OK) { |
| 549 | dev_warn(dev, "GITM[%#llx] ACPI exception: %s\n", id, |
| 550 | acpi_format_exception(status)); |
| 551 | return ERR_PTR(-EIO); |
| 552 | } |
| 553 | obj = ret.pointer; |
| 554 | |
| 555 | /* Sanity check */ |
| 556 | if (obj->buffer.length < 8) { |
| 557 | dev_warn(dev, "Unexpected ASBF length: %u\n", |
| 558 | obj->buffer.length); |
| 559 | ACPI_FREE(obj); |
| 560 | return ERR_PTR(-EIO); |
| 561 | } |
| 562 | return obj; |
| 563 | } |
| 564 | |
Luca Tettamanti | 9e6eba6 | 2009-10-09 20:35:18 +0200 | [diff] [blame] | 565 | static union acpi_object *atk_sitm(struct atk_data *data, |
| 566 | struct atk_acpi_input_buf *buf) |
| 567 | { |
| 568 | struct device *dev = &data->acpi_dev->dev; |
| 569 | struct acpi_object_list params; |
| 570 | union acpi_object tmp; |
| 571 | struct acpi_buffer ret; |
| 572 | union acpi_object *obj; |
| 573 | acpi_status status; |
| 574 | |
| 575 | tmp.type = ACPI_TYPE_BUFFER; |
| 576 | tmp.buffer.pointer = (u8 *)buf; |
| 577 | tmp.buffer.length = sizeof(*buf); |
| 578 | |
| 579 | params.count = 1; |
| 580 | params.pointer = &tmp; |
| 581 | |
| 582 | ret.length = ACPI_ALLOCATE_BUFFER; |
| 583 | status = acpi_evaluate_object_typed(data->write_handle, NULL, ¶ms, |
| 584 | &ret, ACPI_TYPE_BUFFER); |
| 585 | if (status != AE_OK) { |
| 586 | dev_warn(dev, "SITM[%#x] ACPI exception: %s\n", buf->id, |
| 587 | acpi_format_exception(status)); |
| 588 | return ERR_PTR(-EIO); |
| 589 | } |
| 590 | obj = ret.pointer; |
| 591 | |
| 592 | /* Sanity check */ |
| 593 | if (obj->buffer.length < 8) { |
| 594 | dev_warn(dev, "Unexpected ASBF length: %u\n", |
| 595 | obj->buffer.length); |
| 596 | ACPI_FREE(obj); |
| 597 | return ERR_PTR(-EIO); |
| 598 | } |
| 599 | return obj; |
| 600 | } |
| 601 | |
Luca Tettamanti | 2c03d07 | 2009-04-07 15:32:59 +0200 | [diff] [blame] | 602 | static int atk_read_value_new(struct atk_sensor_data *sensor, u64 *value) |
| 603 | { |
| 604 | struct atk_data *data = sensor->data; |
| 605 | struct device *dev = &data->acpi_dev->dev; |
Luca Tettamanti | 18e25555 | 2009-10-09 20:35:18 +0200 | [diff] [blame] | 606 | union acpi_object *obj; |
| 607 | struct atk_acpi_ret_buffer *buf; |
| 608 | int err = 0; |
Luca Tettamanti | 2c03d07 | 2009-04-07 15:32:59 +0200 | [diff] [blame] | 609 | |
Luca Tettamanti | 18e25555 | 2009-10-09 20:35:18 +0200 | [diff] [blame] | 610 | obj = atk_gitm(data, sensor->id); |
| 611 | if (IS_ERR(obj)) |
| 612 | return PTR_ERR(obj); |
Luca Tettamanti | 2c03d07 | 2009-04-07 15:32:59 +0200 | [diff] [blame] | 613 | |
Luca Tettamanti | 18e25555 | 2009-10-09 20:35:18 +0200 | [diff] [blame] | 614 | buf = (struct atk_acpi_ret_buffer *)obj->buffer.pointer; |
| 615 | if (buf->flags == 0) { |
Luca Tettamanti | 2c03d07 | 2009-04-07 15:32:59 +0200 | [diff] [blame] | 616 | /* The reading is not valid, possible causes: |
| 617 | * - sensor failure |
| 618 | * - enumeration was FUBAR (and we didn't notice) |
| 619 | */ |
Luca Tettamanti | 18e25555 | 2009-10-09 20:35:18 +0200 | [diff] [blame] | 620 | dev_warn(dev, "Read failed, sensor = %#llx\n", sensor->id); |
| 621 | err = -EIO; |
| 622 | goto out; |
Luca Tettamanti | 2c03d07 | 2009-04-07 15:32:59 +0200 | [diff] [blame] | 623 | } |
| 624 | |
Luca Tettamanti | 18e25555 | 2009-10-09 20:35:18 +0200 | [diff] [blame] | 625 | *value = buf->value; |
| 626 | out: |
| 627 | ACPI_FREE(obj); |
| 628 | return err; |
Luca Tettamanti | 2c03d07 | 2009-04-07 15:32:59 +0200 | [diff] [blame] | 629 | } |
| 630 | |
| 631 | static int atk_read_value(struct atk_sensor_data *sensor, u64 *value) |
| 632 | { |
| 633 | int err; |
| 634 | |
| 635 | if (!sensor->is_valid || |
| 636 | time_after(jiffies, sensor->last_updated + CACHE_TIME)) { |
| 637 | if (sensor->data->old_interface) |
| 638 | err = atk_read_value_old(sensor, value); |
| 639 | else |
| 640 | err = atk_read_value_new(sensor, value); |
| 641 | |
| 642 | sensor->is_valid = true; |
| 643 | sensor->last_updated = jiffies; |
| 644 | sensor->cached_value = *value; |
| 645 | } else { |
| 646 | *value = sensor->cached_value; |
| 647 | err = 0; |
| 648 | } |
| 649 | |
| 650 | return err; |
| 651 | } |
| 652 | |
Luca Tettamanti | 7e5eab1 | 2010-01-10 20:52:33 +0100 | [diff] [blame] | 653 | #ifdef CONFIG_DEBUG_FS |
| 654 | static int atk_debugfs_gitm_get(void *p, u64 *val) |
| 655 | { |
| 656 | struct atk_data *data = p; |
| 657 | union acpi_object *ret; |
| 658 | struct atk_acpi_ret_buffer *buf; |
| 659 | int err = 0; |
| 660 | |
| 661 | if (!data->read_handle) |
| 662 | return -ENODEV; |
| 663 | |
| 664 | if (!data->debugfs.id) |
| 665 | return -EINVAL; |
| 666 | |
| 667 | ret = atk_gitm(data, data->debugfs.id); |
| 668 | if (IS_ERR(ret)) |
| 669 | return PTR_ERR(ret); |
| 670 | |
| 671 | buf = (struct atk_acpi_ret_buffer *)ret->buffer.pointer; |
| 672 | if (buf->flags) |
| 673 | *val = buf->value; |
| 674 | else |
| 675 | err = -EIO; |
| 676 | |
Luca Tettamanti | 0b8e77f | 2011-07-17 18:39:18 +0200 | [diff] [blame] | 677 | ACPI_FREE(ret); |
Luca Tettamanti | 7e5eab1 | 2010-01-10 20:52:33 +0100 | [diff] [blame] | 678 | return err; |
| 679 | } |
| 680 | |
| 681 | DEFINE_SIMPLE_ATTRIBUTE(atk_debugfs_gitm, |
| 682 | atk_debugfs_gitm_get, |
| 683 | NULL, |
| 684 | "0x%08llx\n") |
| 685 | |
| 686 | static int atk_acpi_print(char *buf, size_t sz, union acpi_object *obj) |
| 687 | { |
| 688 | int ret = 0; |
| 689 | |
| 690 | switch (obj->type) { |
| 691 | case ACPI_TYPE_INTEGER: |
| 692 | ret = snprintf(buf, sz, "0x%08llx\n", obj->integer.value); |
| 693 | break; |
| 694 | case ACPI_TYPE_STRING: |
| 695 | ret = snprintf(buf, sz, "%s\n", obj->string.pointer); |
| 696 | break; |
| 697 | } |
| 698 | |
| 699 | return ret; |
| 700 | } |
| 701 | |
| 702 | static void atk_pack_print(char *buf, size_t sz, union acpi_object *pack) |
| 703 | { |
| 704 | int ret; |
| 705 | int i; |
| 706 | |
| 707 | for (i = 0; i < pack->package.count; i++) { |
| 708 | union acpi_object *obj = &pack->package.elements[i]; |
| 709 | |
| 710 | ret = atk_acpi_print(buf, sz, obj); |
| 711 | if (ret >= sz) |
| 712 | break; |
| 713 | buf += ret; |
| 714 | sz -= ret; |
| 715 | } |
| 716 | } |
| 717 | |
| 718 | static int atk_debugfs_ggrp_open(struct inode *inode, struct file *file) |
| 719 | { |
| 720 | struct atk_data *data = inode->i_private; |
| 721 | char *buf = NULL; |
| 722 | union acpi_object *ret; |
| 723 | u8 cls; |
| 724 | int i; |
| 725 | |
| 726 | if (!data->enumerate_handle) |
| 727 | return -ENODEV; |
| 728 | if (!data->debugfs.id) |
| 729 | return -EINVAL; |
| 730 | |
| 731 | cls = (data->debugfs.id & 0xff000000) >> 24; |
| 732 | ret = atk_ggrp(data, cls); |
| 733 | if (IS_ERR(ret)) |
| 734 | return PTR_ERR(ret); |
| 735 | |
| 736 | for (i = 0; i < ret->package.count; i++) { |
| 737 | union acpi_object *pack = &ret->package.elements[i]; |
| 738 | union acpi_object *id; |
| 739 | |
| 740 | if (pack->type != ACPI_TYPE_PACKAGE) |
| 741 | continue; |
| 742 | if (!pack->package.count) |
| 743 | continue; |
| 744 | id = &pack->package.elements[0]; |
| 745 | if (id->integer.value == data->debugfs.id) { |
| 746 | /* Print the package */ |
| 747 | buf = kzalloc(512, GFP_KERNEL); |
| 748 | if (!buf) { |
| 749 | ACPI_FREE(ret); |
| 750 | return -ENOMEM; |
| 751 | } |
| 752 | atk_pack_print(buf, 512, pack); |
| 753 | break; |
| 754 | } |
| 755 | } |
| 756 | ACPI_FREE(ret); |
| 757 | |
| 758 | if (!buf) |
| 759 | return -EINVAL; |
| 760 | |
| 761 | file->private_data = buf; |
| 762 | |
| 763 | return nonseekable_open(inode, file); |
| 764 | } |
| 765 | |
| 766 | static ssize_t atk_debugfs_ggrp_read(struct file *file, char __user *buf, |
| 767 | size_t count, loff_t *pos) |
| 768 | { |
| 769 | char *str = file->private_data; |
| 770 | size_t len = strlen(str); |
| 771 | |
| 772 | return simple_read_from_buffer(buf, count, pos, str, len); |
| 773 | } |
| 774 | |
| 775 | static int atk_debugfs_ggrp_release(struct inode *inode, struct file *file) |
| 776 | { |
| 777 | kfree(file->private_data); |
| 778 | return 0; |
| 779 | } |
| 780 | |
| 781 | static const struct file_operations atk_debugfs_ggrp_fops = { |
| 782 | .read = atk_debugfs_ggrp_read, |
| 783 | .open = atk_debugfs_ggrp_open, |
| 784 | .release = atk_debugfs_ggrp_release, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 785 | .llseek = no_llseek, |
Luca Tettamanti | 7e5eab1 | 2010-01-10 20:52:33 +0100 | [diff] [blame] | 786 | }; |
| 787 | |
| 788 | static void atk_debugfs_init(struct atk_data *data) |
| 789 | { |
| 790 | struct dentry *d; |
| 791 | struct dentry *f; |
| 792 | |
| 793 | data->debugfs.id = 0; |
| 794 | |
| 795 | d = debugfs_create_dir("asus_atk0110", NULL); |
| 796 | if (!d || IS_ERR(d)) |
| 797 | return; |
| 798 | |
| 799 | f = debugfs_create_x32("id", S_IRUSR | S_IWUSR, d, &data->debugfs.id); |
| 800 | if (!f || IS_ERR(f)) |
| 801 | goto cleanup; |
| 802 | |
| 803 | f = debugfs_create_file("gitm", S_IRUSR, d, data, |
| 804 | &atk_debugfs_gitm); |
| 805 | if (!f || IS_ERR(f)) |
| 806 | goto cleanup; |
| 807 | |
| 808 | f = debugfs_create_file("ggrp", S_IRUSR, d, data, |
| 809 | &atk_debugfs_ggrp_fops); |
| 810 | if (!f || IS_ERR(f)) |
| 811 | goto cleanup; |
| 812 | |
| 813 | data->debugfs.root = d; |
| 814 | |
| 815 | return; |
| 816 | cleanup: |
| 817 | debugfs_remove_recursive(d); |
| 818 | } |
| 819 | |
| 820 | static void atk_debugfs_cleanup(struct atk_data *data) |
| 821 | { |
| 822 | debugfs_remove_recursive(data->debugfs.root); |
| 823 | } |
| 824 | |
| 825 | #else /* CONFIG_DEBUG_FS */ |
| 826 | |
| 827 | static void atk_debugfs_init(struct atk_data *data) |
| 828 | { |
| 829 | } |
| 830 | |
| 831 | static void atk_debugfs_cleanup(struct atk_data *data) |
| 832 | { |
| 833 | } |
| 834 | #endif |
| 835 | |
Luca Tettamanti | 2c03d07 | 2009-04-07 15:32:59 +0200 | [diff] [blame] | 836 | static int atk_add_sensor(struct atk_data *data, union acpi_object *obj) |
| 837 | { |
| 838 | struct device *dev = &data->acpi_dev->dev; |
| 839 | union acpi_object *flags; |
| 840 | union acpi_object *name; |
| 841 | union acpi_object *limit1; |
| 842 | union acpi_object *limit2; |
| 843 | union acpi_object *enable; |
| 844 | struct atk_sensor_data *sensor; |
| 845 | char const *base_name; |
| 846 | char const *limit1_name; |
| 847 | char const *limit2_name; |
| 848 | u64 type; |
| 849 | int err; |
| 850 | int *num; |
| 851 | int start; |
| 852 | |
| 853 | if (obj->type != ACPI_TYPE_PACKAGE) { |
| 854 | /* wft is this? */ |
| 855 | dev_warn(dev, "Unknown type for ACPI object: (%d)\n", |
| 856 | obj->type); |
| 857 | return -EINVAL; |
| 858 | } |
| 859 | |
| 860 | err = validate_hwmon_pack(data, obj); |
| 861 | if (err) |
| 862 | return err; |
| 863 | |
| 864 | /* Ok, we have a valid hwmon package */ |
| 865 | type = atk_get_pack_member(data, obj, HWMON_PACK_FLAGS)->integer.value |
| 866 | & ATK_TYPE_MASK; |
| 867 | |
| 868 | switch (type) { |
| 869 | case HWMON_TYPE_VOLT: |
| 870 | base_name = "in"; |
| 871 | limit1_name = "min"; |
| 872 | limit2_name = "max"; |
| 873 | num = &data->voltage_count; |
| 874 | start = 0; |
| 875 | break; |
| 876 | case HWMON_TYPE_TEMP: |
| 877 | base_name = "temp"; |
| 878 | limit1_name = "max"; |
| 879 | limit2_name = "crit"; |
| 880 | num = &data->temperature_count; |
| 881 | start = 1; |
| 882 | break; |
| 883 | case HWMON_TYPE_FAN: |
| 884 | base_name = "fan"; |
| 885 | limit1_name = "min"; |
| 886 | limit2_name = "max"; |
| 887 | num = &data->fan_count; |
| 888 | start = 1; |
| 889 | break; |
| 890 | default: |
| 891 | dev_warn(dev, "Unknown sensor type: %#llx\n", type); |
| 892 | return -EINVAL; |
| 893 | } |
| 894 | |
| 895 | enable = atk_get_pack_member(data, obj, HWMON_PACK_ENABLE); |
| 896 | if (!enable->integer.value) |
| 897 | /* sensor is disabled */ |
| 898 | return 0; |
| 899 | |
| 900 | flags = atk_get_pack_member(data, obj, HWMON_PACK_FLAGS); |
| 901 | name = atk_get_pack_member(data, obj, HWMON_PACK_NAME); |
| 902 | limit1 = atk_get_pack_member(data, obj, HWMON_PACK_LIMIT1); |
| 903 | limit2 = atk_get_pack_member(data, obj, HWMON_PACK_LIMIT2); |
| 904 | |
| 905 | sensor = kzalloc(sizeof(*sensor), GFP_KERNEL); |
| 906 | if (!sensor) |
| 907 | return -ENOMEM; |
| 908 | |
| 909 | sensor->acpi_name = kstrdup(name->string.pointer, GFP_KERNEL); |
| 910 | if (!sensor->acpi_name) { |
| 911 | err = -ENOMEM; |
| 912 | goto out; |
| 913 | } |
| 914 | |
| 915 | INIT_LIST_HEAD(&sensor->list); |
| 916 | sensor->type = type; |
| 917 | sensor->data = data; |
| 918 | sensor->id = flags->integer.value; |
| 919 | sensor->limit1 = limit1->integer.value; |
Luca Tettamanti | 8d28249 | 2009-07-28 16:31:39 +0200 | [diff] [blame] | 920 | if (data->old_interface) |
| 921 | sensor->limit2 = limit2->integer.value; |
| 922 | else |
| 923 | /* The upper limit is expressed as delta from lower limit */ |
| 924 | sensor->limit2 = sensor->limit1 + limit2->integer.value; |
Luca Tettamanti | 2c03d07 | 2009-04-07 15:32:59 +0200 | [diff] [blame] | 925 | |
| 926 | snprintf(sensor->input_attr_name, ATTR_NAME_SIZE, |
| 927 | "%s%d_input", base_name, start + *num); |
| 928 | atk_init_attribute(&sensor->input_attr, |
| 929 | sensor->input_attr_name, |
| 930 | atk_input_show); |
| 931 | |
| 932 | snprintf(sensor->label_attr_name, ATTR_NAME_SIZE, |
| 933 | "%s%d_label", base_name, start + *num); |
| 934 | atk_init_attribute(&sensor->label_attr, |
| 935 | sensor->label_attr_name, |
| 936 | atk_label_show); |
| 937 | |
| 938 | snprintf(sensor->limit1_attr_name, ATTR_NAME_SIZE, |
| 939 | "%s%d_%s", base_name, start + *num, limit1_name); |
| 940 | atk_init_attribute(&sensor->limit1_attr, |
| 941 | sensor->limit1_attr_name, |
| 942 | atk_limit1_show); |
| 943 | |
| 944 | snprintf(sensor->limit2_attr_name, ATTR_NAME_SIZE, |
| 945 | "%s%d_%s", base_name, start + *num, limit2_name); |
| 946 | atk_init_attribute(&sensor->limit2_attr, |
| 947 | sensor->limit2_attr_name, |
| 948 | atk_limit2_show); |
| 949 | |
| 950 | list_add(&sensor->list, &data->sensor_list); |
| 951 | (*num)++; |
| 952 | |
| 953 | return 1; |
| 954 | out: |
| 955 | kfree(sensor->acpi_name); |
| 956 | kfree(sensor); |
| 957 | return err; |
| 958 | } |
| 959 | |
| 960 | static int atk_enumerate_old_hwmon(struct atk_data *data) |
| 961 | { |
| 962 | struct device *dev = &data->acpi_dev->dev; |
| 963 | struct acpi_buffer buf; |
| 964 | union acpi_object *pack; |
| 965 | acpi_status status; |
| 966 | int i, ret; |
| 967 | int count = 0; |
| 968 | |
| 969 | /* Voltages */ |
| 970 | buf.length = ACPI_ALLOCATE_BUFFER; |
| 971 | status = acpi_evaluate_object_typed(data->atk_handle, |
| 972 | METHOD_OLD_ENUM_VLT, NULL, &buf, ACPI_TYPE_PACKAGE); |
| 973 | if (status != AE_OK) { |
| 974 | dev_warn(dev, METHOD_OLD_ENUM_VLT ": ACPI exception: %s\n", |
| 975 | acpi_format_exception(status)); |
| 976 | |
| 977 | return -ENODEV; |
| 978 | } |
| 979 | |
| 980 | pack = buf.pointer; |
| 981 | for (i = 1; i < pack->package.count; i++) { |
| 982 | union acpi_object *obj = &pack->package.elements[i]; |
| 983 | |
| 984 | ret = atk_add_sensor(data, obj); |
| 985 | if (ret > 0) |
| 986 | count++; |
| 987 | } |
| 988 | ACPI_FREE(buf.pointer); |
| 989 | |
| 990 | /* Temperatures */ |
| 991 | buf.length = ACPI_ALLOCATE_BUFFER; |
| 992 | status = acpi_evaluate_object_typed(data->atk_handle, |
| 993 | METHOD_OLD_ENUM_TMP, NULL, &buf, ACPI_TYPE_PACKAGE); |
| 994 | if (status != AE_OK) { |
| 995 | dev_warn(dev, METHOD_OLD_ENUM_TMP ": ACPI exception: %s\n", |
| 996 | acpi_format_exception(status)); |
| 997 | |
| 998 | ret = -ENODEV; |
| 999 | goto cleanup; |
| 1000 | } |
| 1001 | |
| 1002 | pack = buf.pointer; |
| 1003 | for (i = 1; i < pack->package.count; i++) { |
| 1004 | union acpi_object *obj = &pack->package.elements[i]; |
| 1005 | |
| 1006 | ret = atk_add_sensor(data, obj); |
| 1007 | if (ret > 0) |
| 1008 | count++; |
| 1009 | } |
| 1010 | ACPI_FREE(buf.pointer); |
| 1011 | |
| 1012 | /* Fans */ |
| 1013 | buf.length = ACPI_ALLOCATE_BUFFER; |
| 1014 | status = acpi_evaluate_object_typed(data->atk_handle, |
| 1015 | METHOD_OLD_ENUM_FAN, NULL, &buf, ACPI_TYPE_PACKAGE); |
| 1016 | if (status != AE_OK) { |
| 1017 | dev_warn(dev, METHOD_OLD_ENUM_FAN ": ACPI exception: %s\n", |
| 1018 | acpi_format_exception(status)); |
| 1019 | |
| 1020 | ret = -ENODEV; |
| 1021 | goto cleanup; |
| 1022 | } |
| 1023 | |
| 1024 | pack = buf.pointer; |
| 1025 | for (i = 1; i < pack->package.count; i++) { |
| 1026 | union acpi_object *obj = &pack->package.elements[i]; |
| 1027 | |
| 1028 | ret = atk_add_sensor(data, obj); |
| 1029 | if (ret > 0) |
| 1030 | count++; |
| 1031 | } |
| 1032 | ACPI_FREE(buf.pointer); |
| 1033 | |
| 1034 | return count; |
| 1035 | cleanup: |
| 1036 | atk_free_sensors(data); |
| 1037 | return ret; |
| 1038 | } |
| 1039 | |
Luca Tettamanti | 9e6eba6 | 2009-10-09 20:35:18 +0200 | [diff] [blame] | 1040 | static int atk_ec_present(struct atk_data *data) |
| 1041 | { |
| 1042 | struct device *dev = &data->acpi_dev->dev; |
| 1043 | union acpi_object *pack; |
| 1044 | union acpi_object *ec; |
| 1045 | int ret; |
| 1046 | int i; |
| 1047 | |
| 1048 | pack = atk_ggrp(data, ATK_MUX_MGMT); |
| 1049 | if (IS_ERR(pack)) { |
| 1050 | if (PTR_ERR(pack) == -ENOENT) { |
| 1051 | /* The MGMT class does not exists - that's ok */ |
| 1052 | dev_dbg(dev, "Class %#llx not found\n", ATK_MUX_MGMT); |
| 1053 | return 0; |
| 1054 | } |
| 1055 | return PTR_ERR(pack); |
| 1056 | } |
| 1057 | |
| 1058 | /* Search the EC */ |
| 1059 | ec = NULL; |
| 1060 | for (i = 0; i < pack->package.count; i++) { |
| 1061 | union acpi_object *obj = &pack->package.elements[i]; |
| 1062 | union acpi_object *id; |
| 1063 | |
| 1064 | if (obj->type != ACPI_TYPE_PACKAGE) |
| 1065 | continue; |
| 1066 | |
| 1067 | id = &obj->package.elements[0]; |
| 1068 | if (id->type != ACPI_TYPE_INTEGER) |
| 1069 | continue; |
| 1070 | |
| 1071 | if (id->integer.value == ATK_EC_ID) { |
| 1072 | ec = obj; |
| 1073 | break; |
| 1074 | } |
| 1075 | } |
| 1076 | |
| 1077 | ret = (ec != NULL); |
| 1078 | if (!ret) |
| 1079 | /* The system has no EC */ |
| 1080 | dev_dbg(dev, "EC not found\n"); |
| 1081 | |
| 1082 | ACPI_FREE(pack); |
| 1083 | return ret; |
| 1084 | } |
| 1085 | |
| 1086 | static int atk_ec_enabled(struct atk_data *data) |
| 1087 | { |
| 1088 | struct device *dev = &data->acpi_dev->dev; |
| 1089 | union acpi_object *obj; |
| 1090 | struct atk_acpi_ret_buffer *buf; |
| 1091 | int err; |
| 1092 | |
| 1093 | obj = atk_gitm(data, ATK_EC_ID); |
| 1094 | if (IS_ERR(obj)) { |
| 1095 | dev_err(dev, "Unable to query EC status\n"); |
| 1096 | return PTR_ERR(obj); |
| 1097 | } |
| 1098 | buf = (struct atk_acpi_ret_buffer *)obj->buffer.pointer; |
| 1099 | |
| 1100 | if (buf->flags == 0) { |
| 1101 | dev_err(dev, "Unable to query EC status\n"); |
| 1102 | err = -EIO; |
| 1103 | } else { |
| 1104 | err = (buf->value != 0); |
| 1105 | dev_dbg(dev, "EC is %sabled\n", |
| 1106 | err ? "en" : "dis"); |
| 1107 | } |
| 1108 | |
| 1109 | ACPI_FREE(obj); |
| 1110 | return err; |
| 1111 | } |
| 1112 | |
| 1113 | static int atk_ec_ctl(struct atk_data *data, int enable) |
| 1114 | { |
| 1115 | struct device *dev = &data->acpi_dev->dev; |
| 1116 | union acpi_object *obj; |
| 1117 | struct atk_acpi_input_buf sitm; |
| 1118 | struct atk_acpi_ret_buffer *ec_ret; |
| 1119 | int err = 0; |
| 1120 | |
| 1121 | sitm.id = ATK_EC_ID; |
| 1122 | sitm.param1 = enable; |
| 1123 | sitm.param2 = 0; |
| 1124 | |
| 1125 | obj = atk_sitm(data, &sitm); |
| 1126 | if (IS_ERR(obj)) { |
| 1127 | dev_err(dev, "Failed to %sable the EC\n", |
| 1128 | enable ? "en" : "dis"); |
| 1129 | return PTR_ERR(obj); |
| 1130 | } |
| 1131 | ec_ret = (struct atk_acpi_ret_buffer *)obj->buffer.pointer; |
| 1132 | if (ec_ret->flags == 0) { |
| 1133 | dev_err(dev, "Failed to %sable the EC\n", |
| 1134 | enable ? "en" : "dis"); |
| 1135 | err = -EIO; |
| 1136 | } else { |
| 1137 | dev_info(dev, "EC %sabled\n", |
| 1138 | enable ? "en" : "dis"); |
| 1139 | } |
| 1140 | |
| 1141 | ACPI_FREE(obj); |
| 1142 | return err; |
| 1143 | } |
| 1144 | |
Luca Tettamanti | 2c03d07 | 2009-04-07 15:32:59 +0200 | [diff] [blame] | 1145 | static int atk_enumerate_new_hwmon(struct atk_data *data) |
| 1146 | { |
| 1147 | struct device *dev = &data->acpi_dev->dev; |
Luca Tettamanti | 2c03d07 | 2009-04-07 15:32:59 +0200 | [diff] [blame] | 1148 | union acpi_object *pack; |
| 1149 | int err; |
| 1150 | int i; |
| 1151 | |
Luca Tettamanti | 9e6eba6 | 2009-10-09 20:35:18 +0200 | [diff] [blame] | 1152 | err = atk_ec_present(data); |
| 1153 | if (err < 0) |
| 1154 | return err; |
| 1155 | if (err) { |
| 1156 | err = atk_ec_enabled(data); |
| 1157 | if (err < 0) |
| 1158 | return err; |
| 1159 | /* If the EC was disabled we will disable it again on unload */ |
| 1160 | data->disable_ec = err; |
| 1161 | |
| 1162 | err = atk_ec_ctl(data, 1); |
| 1163 | if (err) { |
| 1164 | data->disable_ec = false; |
| 1165 | return err; |
| 1166 | } |
| 1167 | } |
| 1168 | |
Luca Tettamanti | 2c03d07 | 2009-04-07 15:32:59 +0200 | [diff] [blame] | 1169 | dev_dbg(dev, "Enumerating hwmon sensors\n"); |
| 1170 | |
Luca Tettamanti | 18e25555 | 2009-10-09 20:35:18 +0200 | [diff] [blame] | 1171 | pack = atk_ggrp(data, ATK_MUX_HWMON); |
| 1172 | if (IS_ERR(pack)) |
| 1173 | return PTR_ERR(pack); |
Luca Tettamanti | 2c03d07 | 2009-04-07 15:32:59 +0200 | [diff] [blame] | 1174 | |
| 1175 | for (i = 0; i < pack->package.count; i++) { |
| 1176 | union acpi_object *obj = &pack->package.elements[i]; |
| 1177 | |
| 1178 | atk_add_sensor(data, obj); |
| 1179 | } |
| 1180 | |
| 1181 | err = data->voltage_count + data->temperature_count + data->fan_count; |
| 1182 | |
Luca Tettamanti | 18e25555 | 2009-10-09 20:35:18 +0200 | [diff] [blame] | 1183 | ACPI_FREE(pack); |
Luca Tettamanti | 2c03d07 | 2009-04-07 15:32:59 +0200 | [diff] [blame] | 1184 | return err; |
| 1185 | } |
| 1186 | |
| 1187 | static int atk_create_files(struct atk_data *data) |
| 1188 | { |
| 1189 | struct atk_sensor_data *s; |
| 1190 | int err; |
| 1191 | |
| 1192 | list_for_each_entry(s, &data->sensor_list, list) { |
| 1193 | err = device_create_file(data->hwmon_dev, &s->input_attr); |
| 1194 | if (err) |
| 1195 | return err; |
| 1196 | err = device_create_file(data->hwmon_dev, &s->label_attr); |
| 1197 | if (err) |
| 1198 | return err; |
| 1199 | err = device_create_file(data->hwmon_dev, &s->limit1_attr); |
| 1200 | if (err) |
| 1201 | return err; |
| 1202 | err = device_create_file(data->hwmon_dev, &s->limit2_attr); |
| 1203 | if (err) |
| 1204 | return err; |
| 1205 | } |
| 1206 | |
| 1207 | err = device_create_file(data->hwmon_dev, &atk_name_attr); |
| 1208 | |
| 1209 | return err; |
| 1210 | } |
| 1211 | |
| 1212 | static void atk_remove_files(struct atk_data *data) |
| 1213 | { |
| 1214 | struct atk_sensor_data *s; |
| 1215 | |
| 1216 | list_for_each_entry(s, &data->sensor_list, list) { |
| 1217 | device_remove_file(data->hwmon_dev, &s->input_attr); |
| 1218 | device_remove_file(data->hwmon_dev, &s->label_attr); |
| 1219 | device_remove_file(data->hwmon_dev, &s->limit1_attr); |
| 1220 | device_remove_file(data->hwmon_dev, &s->limit2_attr); |
| 1221 | } |
| 1222 | device_remove_file(data->hwmon_dev, &atk_name_attr); |
| 1223 | } |
| 1224 | |
| 1225 | static void atk_free_sensors(struct atk_data *data) |
| 1226 | { |
| 1227 | struct list_head *head = &data->sensor_list; |
| 1228 | struct atk_sensor_data *s, *tmp; |
| 1229 | |
| 1230 | list_for_each_entry_safe(s, tmp, head, list) { |
| 1231 | kfree(s->acpi_name); |
| 1232 | kfree(s); |
| 1233 | } |
| 1234 | } |
| 1235 | |
| 1236 | static int atk_register_hwmon(struct atk_data *data) |
| 1237 | { |
| 1238 | struct device *dev = &data->acpi_dev->dev; |
| 1239 | int err; |
| 1240 | |
| 1241 | dev_dbg(dev, "registering hwmon device\n"); |
| 1242 | data->hwmon_dev = hwmon_device_register(dev); |
| 1243 | if (IS_ERR(data->hwmon_dev)) |
| 1244 | return PTR_ERR(data->hwmon_dev); |
| 1245 | |
| 1246 | dev_dbg(dev, "populating sysfs directory\n"); |
| 1247 | err = atk_create_files(data); |
| 1248 | if (err) |
| 1249 | goto remove; |
| 1250 | |
| 1251 | return 0; |
| 1252 | remove: |
| 1253 | /* Cleanup the registered files */ |
| 1254 | atk_remove_files(data); |
| 1255 | hwmon_device_unregister(data->hwmon_dev); |
| 1256 | return err; |
| 1257 | } |
| 1258 | |
Luca Tettamanti | 8ba406b | 2010-01-10 20:52:33 +0100 | [diff] [blame] | 1259 | static int atk_probe_if(struct atk_data *data) |
Luca Tettamanti | 2c03d07 | 2009-04-07 15:32:59 +0200 | [diff] [blame] | 1260 | { |
| 1261 | struct device *dev = &data->acpi_dev->dev; |
| 1262 | acpi_handle ret; |
| 1263 | acpi_status status; |
Luca Tettamanti | 8ba406b | 2010-01-10 20:52:33 +0100 | [diff] [blame] | 1264 | int err = 0; |
Luca Tettamanti | 2c03d07 | 2009-04-07 15:32:59 +0200 | [diff] [blame] | 1265 | |
| 1266 | /* RTMP: read temperature */ |
| 1267 | status = acpi_get_handle(data->atk_handle, METHOD_OLD_READ_TMP, &ret); |
Luca Tettamanti | 8ba406b | 2010-01-10 20:52:33 +0100 | [diff] [blame] | 1268 | if (ACPI_SUCCESS(status)) |
| 1269 | data->rtmp_handle = ret; |
| 1270 | else |
Luca Tettamanti | 2c03d07 | 2009-04-07 15:32:59 +0200 | [diff] [blame] | 1271 | dev_dbg(dev, "method " METHOD_OLD_READ_TMP " not found: %s\n", |
| 1272 | acpi_format_exception(status)); |
Luca Tettamanti | 2c03d07 | 2009-04-07 15:32:59 +0200 | [diff] [blame] | 1273 | |
| 1274 | /* RVLT: read voltage */ |
| 1275 | status = acpi_get_handle(data->atk_handle, METHOD_OLD_READ_VLT, &ret); |
Luca Tettamanti | 8ba406b | 2010-01-10 20:52:33 +0100 | [diff] [blame] | 1276 | if (ACPI_SUCCESS(status)) |
| 1277 | data->rvlt_handle = ret; |
| 1278 | else |
Luca Tettamanti | 2c03d07 | 2009-04-07 15:32:59 +0200 | [diff] [blame] | 1279 | dev_dbg(dev, "method " METHOD_OLD_READ_VLT " not found: %s\n", |
| 1280 | acpi_format_exception(status)); |
Luca Tettamanti | 2c03d07 | 2009-04-07 15:32:59 +0200 | [diff] [blame] | 1281 | |
| 1282 | /* RFAN: read fan status */ |
| 1283 | status = acpi_get_handle(data->atk_handle, METHOD_OLD_READ_FAN, &ret); |
Luca Tettamanti | 8ba406b | 2010-01-10 20:52:33 +0100 | [diff] [blame] | 1284 | if (ACPI_SUCCESS(status)) |
| 1285 | data->rfan_handle = ret; |
| 1286 | else |
Luca Tettamanti | 2c03d07 | 2009-04-07 15:32:59 +0200 | [diff] [blame] | 1287 | dev_dbg(dev, "method " METHOD_OLD_READ_FAN " not found: %s\n", |
| 1288 | acpi_format_exception(status)); |
Luca Tettamanti | 2c03d07 | 2009-04-07 15:32:59 +0200 | [diff] [blame] | 1289 | |
| 1290 | /* Enumeration */ |
| 1291 | status = acpi_get_handle(data->atk_handle, METHOD_ENUMERATE, &ret); |
Luca Tettamanti | 8ba406b | 2010-01-10 20:52:33 +0100 | [diff] [blame] | 1292 | if (ACPI_SUCCESS(status)) |
| 1293 | data->enumerate_handle = ret; |
| 1294 | else |
Luca Tettamanti | 2c03d07 | 2009-04-07 15:32:59 +0200 | [diff] [blame] | 1295 | dev_dbg(dev, "method " METHOD_ENUMERATE " not found: %s\n", |
| 1296 | acpi_format_exception(status)); |
Luca Tettamanti | 2c03d07 | 2009-04-07 15:32:59 +0200 | [diff] [blame] | 1297 | |
| 1298 | /* De-multiplexer (read) */ |
| 1299 | status = acpi_get_handle(data->atk_handle, METHOD_READ, &ret); |
Luca Tettamanti | 8ba406b | 2010-01-10 20:52:33 +0100 | [diff] [blame] | 1300 | if (ACPI_SUCCESS(status)) |
| 1301 | data->read_handle = ret; |
| 1302 | else |
Luca Tettamanti | 2c03d07 | 2009-04-07 15:32:59 +0200 | [diff] [blame] | 1303 | dev_dbg(dev, "method " METHOD_READ " not found: %s\n", |
| 1304 | acpi_format_exception(status)); |
Luca Tettamanti | 2c03d07 | 2009-04-07 15:32:59 +0200 | [diff] [blame] | 1305 | |
Luca Tettamanti | 9e6eba6 | 2009-10-09 20:35:18 +0200 | [diff] [blame] | 1306 | /* De-multiplexer (write) */ |
| 1307 | status = acpi_get_handle(data->atk_handle, METHOD_WRITE, &ret); |
Luca Tettamanti | 8ba406b | 2010-01-10 20:52:33 +0100 | [diff] [blame] | 1308 | if (ACPI_SUCCESS(status)) |
| 1309 | data->write_handle = ret; |
| 1310 | else |
| 1311 | dev_dbg(dev, "method " METHOD_WRITE " not found: %s\n", |
Luca Tettamanti | 9e6eba6 | 2009-10-09 20:35:18 +0200 | [diff] [blame] | 1312 | acpi_format_exception(status)); |
Luca Tettamanti | 9e6eba6 | 2009-10-09 20:35:18 +0200 | [diff] [blame] | 1313 | |
Luca Tettamanti | 8ba406b | 2010-01-10 20:52:33 +0100 | [diff] [blame] | 1314 | /* Check for hwmon methods: first check "old" style methods; note that |
| 1315 | * both may be present: in this case we stick to the old interface; |
| 1316 | * analysis of multiple DSDTs indicates that when both interfaces |
| 1317 | * are present the new one (GGRP/GITM) is not functional. |
| 1318 | */ |
Luca Tettamanti | 86ca33e | 2011-01-22 16:07:11 +0100 | [diff] [blame] | 1319 | if (new_if) |
| 1320 | dev_info(dev, "Overriding interface detection\n"); |
| 1321 | if (data->rtmp_handle && data->rvlt_handle && data->rfan_handle && !new_if) |
Luca Tettamanti | 8ba406b | 2010-01-10 20:52:33 +0100 | [diff] [blame] | 1322 | data->old_interface = true; |
| 1323 | else if (data->enumerate_handle && data->read_handle && |
| 1324 | data->write_handle) |
| 1325 | data->old_interface = false; |
| 1326 | else |
| 1327 | err = -ENODEV; |
| 1328 | |
| 1329 | return err; |
Luca Tettamanti | 2c03d07 | 2009-04-07 15:32:59 +0200 | [diff] [blame] | 1330 | } |
| 1331 | |
| 1332 | static int atk_add(struct acpi_device *device) |
| 1333 | { |
| 1334 | acpi_status ret; |
| 1335 | int err; |
| 1336 | struct acpi_buffer buf; |
| 1337 | union acpi_object *obj; |
| 1338 | struct atk_data *data; |
| 1339 | |
| 1340 | dev_dbg(&device->dev, "adding...\n"); |
| 1341 | |
| 1342 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 1343 | if (!data) |
| 1344 | return -ENOMEM; |
| 1345 | |
| 1346 | data->acpi_dev = device; |
| 1347 | data->atk_handle = device->handle; |
| 1348 | INIT_LIST_HEAD(&data->sensor_list); |
Luca Tettamanti | 9e6eba6 | 2009-10-09 20:35:18 +0200 | [diff] [blame] | 1349 | data->disable_ec = false; |
Luca Tettamanti | 2c03d07 | 2009-04-07 15:32:59 +0200 | [diff] [blame] | 1350 | |
| 1351 | buf.length = ACPI_ALLOCATE_BUFFER; |
| 1352 | ret = acpi_evaluate_object_typed(data->atk_handle, BOARD_ID, NULL, |
| 1353 | &buf, ACPI_TYPE_PACKAGE); |
| 1354 | if (ret != AE_OK) { |
| 1355 | dev_dbg(&device->dev, "atk: method MBIF not found\n"); |
Luca Tettamanti | 5542482 | 2010-01-25 15:00:49 +0100 | [diff] [blame] | 1356 | } else { |
| 1357 | obj = buf.pointer; |
| 1358 | if (obj->package.count >= 2) { |
| 1359 | union acpi_object *id = &obj->package.elements[1]; |
| 1360 | if (id->type == ACPI_TYPE_STRING) |
| 1361 | dev_dbg(&device->dev, "board ID = %s\n", |
| 1362 | id->string.pointer); |
| 1363 | } |
| 1364 | ACPI_FREE(buf.pointer); |
Luca Tettamanti | 2c03d07 | 2009-04-07 15:32:59 +0200 | [diff] [blame] | 1365 | } |
| 1366 | |
Luca Tettamanti | 8ba406b | 2010-01-10 20:52:33 +0100 | [diff] [blame] | 1367 | err = atk_probe_if(data); |
| 1368 | if (err) { |
| 1369 | dev_err(&device->dev, "No usable hwmon interface detected\n"); |
| 1370 | goto out; |
Luca Tettamanti | 2c03d07 | 2009-04-07 15:32:59 +0200 | [diff] [blame] | 1371 | } |
| 1372 | |
Luca Tettamanti | 8ba406b | 2010-01-10 20:52:33 +0100 | [diff] [blame] | 1373 | if (data->old_interface) { |
| 1374 | dev_dbg(&device->dev, "Using old hwmon interface\n"); |
Luca Tettamanti | 2c03d07 | 2009-04-07 15:32:59 +0200 | [diff] [blame] | 1375 | err = atk_enumerate_old_hwmon(data); |
Luca Tettamanti | 8ba406b | 2010-01-10 20:52:33 +0100 | [diff] [blame] | 1376 | } else { |
| 1377 | dev_dbg(&device->dev, "Using new hwmon interface\n"); |
Luca Tettamanti | 2c03d07 | 2009-04-07 15:32:59 +0200 | [diff] [blame] | 1378 | err = atk_enumerate_new_hwmon(data); |
Luca Tettamanti | 8ba406b | 2010-01-10 20:52:33 +0100 | [diff] [blame] | 1379 | } |
Luca Tettamanti | 2c03d07 | 2009-04-07 15:32:59 +0200 | [diff] [blame] | 1380 | if (err < 0) |
| 1381 | goto out; |
| 1382 | if (err == 0) { |
| 1383 | dev_info(&device->dev, |
| 1384 | "No usable sensor detected, bailing out\n"); |
| 1385 | err = -ENODEV; |
| 1386 | goto out; |
| 1387 | } |
| 1388 | |
| 1389 | err = atk_register_hwmon(data); |
| 1390 | if (err) |
| 1391 | goto cleanup; |
| 1392 | |
Luca Tettamanti | 7e5eab1 | 2010-01-10 20:52:33 +0100 | [diff] [blame] | 1393 | atk_debugfs_init(data); |
| 1394 | |
Luca Tettamanti | 2c03d07 | 2009-04-07 15:32:59 +0200 | [diff] [blame] | 1395 | device->driver_data = data; |
| 1396 | return 0; |
| 1397 | cleanup: |
| 1398 | atk_free_sensors(data); |
| 1399 | out: |
Luca Tettamanti | 9e6eba6 | 2009-10-09 20:35:18 +0200 | [diff] [blame] | 1400 | if (data->disable_ec) |
| 1401 | atk_ec_ctl(data, 0); |
Luca Tettamanti | 2c03d07 | 2009-04-07 15:32:59 +0200 | [diff] [blame] | 1402 | kfree(data); |
| 1403 | return err; |
| 1404 | } |
| 1405 | |
| 1406 | static int atk_remove(struct acpi_device *device, int type) |
| 1407 | { |
| 1408 | struct atk_data *data = device->driver_data; |
| 1409 | dev_dbg(&device->dev, "removing...\n"); |
| 1410 | |
| 1411 | device->driver_data = NULL; |
| 1412 | |
Luca Tettamanti | 7e5eab1 | 2010-01-10 20:52:33 +0100 | [diff] [blame] | 1413 | atk_debugfs_cleanup(data); |
| 1414 | |
Luca Tettamanti | 2c03d07 | 2009-04-07 15:32:59 +0200 | [diff] [blame] | 1415 | atk_remove_files(data); |
| 1416 | atk_free_sensors(data); |
| 1417 | hwmon_device_unregister(data->hwmon_dev); |
| 1418 | |
Luca Tettamanti | 9e6eba6 | 2009-10-09 20:35:18 +0200 | [diff] [blame] | 1419 | if (data->disable_ec) { |
| 1420 | if (atk_ec_ctl(data, 0)) |
| 1421 | dev_err(&device->dev, "Failed to disable EC\n"); |
| 1422 | } |
| 1423 | |
Luca Tettamanti | 2c03d07 | 2009-04-07 15:32:59 +0200 | [diff] [blame] | 1424 | kfree(data); |
| 1425 | |
| 1426 | return 0; |
| 1427 | } |
| 1428 | |
| 1429 | static int __init atk0110_init(void) |
| 1430 | { |
| 1431 | int ret; |
| 1432 | |
Jean Delvare | 70dd6be | 2010-05-27 19:58:37 +0200 | [diff] [blame] | 1433 | /* Make sure it's safe to access the device through ACPI */ |
| 1434 | if (!acpi_resources_are_enforced()) { |
Joe Perches | ac56149 | 2010-10-20 06:51:30 +0000 | [diff] [blame] | 1435 | pr_err("Resources not safely usable due to acpi_enforce_resources kernel parameter\n"); |
Jean Delvare | 70dd6be | 2010-05-27 19:58:37 +0200 | [diff] [blame] | 1436 | return -EBUSY; |
| 1437 | } |
| 1438 | |
Luca Tettamanti | 86ca33e | 2011-01-22 16:07:11 +0100 | [diff] [blame] | 1439 | if (dmi_check_system(atk_force_new_if)) |
| 1440 | new_if = true; |
| 1441 | |
Luca Tettamanti | 2c03d07 | 2009-04-07 15:32:59 +0200 | [diff] [blame] | 1442 | ret = acpi_bus_register_driver(&atk_driver); |
| 1443 | if (ret) |
Joe Perches | ac56149 | 2010-10-20 06:51:30 +0000 | [diff] [blame] | 1444 | pr_info("acpi_bus_register_driver failed: %d\n", ret); |
Luca Tettamanti | 2c03d07 | 2009-04-07 15:32:59 +0200 | [diff] [blame] | 1445 | |
| 1446 | return ret; |
| 1447 | } |
| 1448 | |
| 1449 | static void __exit atk0110_exit(void) |
| 1450 | { |
| 1451 | acpi_bus_unregister_driver(&atk_driver); |
| 1452 | } |
| 1453 | |
| 1454 | module_init(atk0110_init); |
| 1455 | module_exit(atk0110_exit); |
| 1456 | |
| 1457 | MODULE_LICENSE("GPL"); |