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