blob: 75f87f125dac9c7e954fc03537f5542dbb0c1640 [file] [log] [blame]
Nicolas Boichat6f2fad72007-05-08 00:24:52 -07001/*
2 * drivers/hwmon/applesmc.c - driver for Apple's SMC (accelerometer, temperature
3 * sensors, fan control, keyboard backlight control) used in Intel-based Apple
4 * computers.
5 *
6 * Copyright (C) 2007 Nicolas Boichat <nicolas@boichat.ch>
Henrik Rydberg41e71f92010-11-09 15:15:11 +00007 * Copyright (C) 2010 Henrik Rydberg <rydberg@euromail.se>
Nicolas Boichat6f2fad72007-05-08 00:24:52 -07008 *
9 * Based on hdaps.c driver:
10 * Copyright (C) 2005 Robert Love <rml@novell.com>
Jesper Juhlaa8521e2012-06-20 21:18:48 +020011 * Copyright (C) 2005 Jesper Juhl <jj@chaosbits.net>
Nicolas Boichat6f2fad72007-05-08 00:24:52 -070012 *
13 * Fan control based on smcFanControl:
14 * Copyright (C) 2006 Hendrik Holtmann <holtmann@mac.com>
15 *
16 * This program is free software; you can redistribute it and/or modify it
17 * under the terms of the GNU General Public License v2 as published by the
18 * Free Software Foundation.
19 *
20 * This program is distributed in the hope that it will be useful, but WITHOUT
21 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
22 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
23 * more details.
24 *
25 * You should have received a copy of the GNU General Public License along with
26 * this program; if not, write to the Free Software Foundation, Inc.,
27 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
28 */
29
Joe Perches1ee7c712010-11-09 15:15:03 +000030#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
31
Nicolas Boichat6f2fad72007-05-08 00:24:52 -070032#include <linux/delay.h>
33#include <linux/platform_device.h>
Dmitry Torokhovd5cf2b92007-09-26 00:01:35 -040034#include <linux/input-polldev.h>
Nicolas Boichat6f2fad72007-05-08 00:24:52 -070035#include <linux/kernel.h>
Henrik Rydberg58745832010-11-10 10:58:03 +000036#include <linux/slab.h>
Nicolas Boichat6f2fad72007-05-08 00:24:52 -070037#include <linux/module.h>
38#include <linux/timer.h>
39#include <linux/dmi.h>
40#include <linux/mutex.h>
41#include <linux/hwmon-sysfs.h>
H Hartley Sweeten6055fae2009-09-15 17:18:13 +020042#include <linux/io.h>
Nicolas Boichat6f2fad72007-05-08 00:24:52 -070043#include <linux/leds.h>
44#include <linux/hwmon.h>
45#include <linux/workqueue.h>
46
47/* data port used by Apple SMC */
48#define APPLESMC_DATA_PORT 0x300
49/* command/status port used by Apple SMC */
50#define APPLESMC_CMD_PORT 0x304
51
52#define APPLESMC_NR_PORTS 32 /* 0x300-0x31f */
53
54#define APPLESMC_MAX_DATA_LENGTH 32
55
Henrik Rydberg58745832010-11-10 10:58:03 +000056/* wait up to 32 ms for a status change. */
Henrik Rydberga332bf92012-07-09 12:10:26 +020057#define APPLESMC_MIN_WAIT 0x0010
Henrik Rydberg8c9398d2008-10-18 20:27:43 -070058#define APPLESMC_MAX_WAIT 0x8000
59
Nicolas Boichat6f2fad72007-05-08 00:24:52 -070060#define APPLESMC_STATUS_MASK 0x0f
61#define APPLESMC_READ_CMD 0x10
62#define APPLESMC_WRITE_CMD 0x11
63#define APPLESMC_GET_KEY_BY_INDEX_CMD 0x12
64#define APPLESMC_GET_KEY_TYPE_CMD 0x13
65
66#define KEY_COUNT_KEY "#KEY" /* r-o ui32 */
67
Henrik Rydberg8bd1a122008-10-18 20:27:39 -070068#define LIGHT_SENSOR_LEFT_KEY "ALV0" /* r-o {alv (6-10 bytes) */
69#define LIGHT_SENSOR_RIGHT_KEY "ALV1" /* r-o {alv (6-10 bytes) */
Dmitry Torokhovd5cf2b92007-09-26 00:01:35 -040070#define BACKLIGHT_KEY "LKSB" /* w-o {lkb (2 bytes) */
Nicolas Boichat6f2fad72007-05-08 00:24:52 -070071
Dmitry Torokhovd5cf2b92007-09-26 00:01:35 -040072#define CLAMSHELL_KEY "MSLD" /* r-o ui8 (unused) */
Nicolas Boichat6f2fad72007-05-08 00:24:52 -070073
74#define MOTION_SENSOR_X_KEY "MO_X" /* r-o sp78 (2 bytes) */
75#define MOTION_SENSOR_Y_KEY "MO_Y" /* r-o sp78 (2 bytes) */
76#define MOTION_SENSOR_Z_KEY "MO_Z" /* r-o sp78 (2 bytes) */
77#define MOTION_SENSOR_KEY "MOCN" /* r/w ui16 */
78
79#define FANS_COUNT "FNum" /* r-o ui8 */
80#define FANS_MANUAL "FS! " /* r-w ui16 */
Henrik Rydberg3eba2bf2010-11-09 15:15:08 +000081#define FAN_ID_FMT "F%dID" /* r-o char[16] */
Nicolas Boichat6f2fad72007-05-08 00:24:52 -070082
Henrik Rydbergb6e51222012-07-16 09:18:10 +020083#define TEMP_SENSOR_TYPE "sp78"
84
Nicolas Boichat6f2fad72007-05-08 00:24:52 -070085/* List of keys used to read/write fan speeds */
Henrik Rydberg3eba2bf2010-11-09 15:15:08 +000086static const char *const fan_speed_fmt[] = {
87 "F%dAc", /* actual speed */
88 "F%dMn", /* minimum speed (rw) */
89 "F%dMx", /* maximum speed */
90 "F%dSf", /* safe speed - not all models */
91 "F%dTg", /* target speed (manual: rw) */
Nicolas Boichat6f2fad72007-05-08 00:24:52 -070092};
93
94#define INIT_TIMEOUT_MSECS 5000 /* wait up to 5s for device init ... */
95#define INIT_WAIT_MSECS 50 /* ... in 50ms increments */
96
Dmitry Torokhovd5cf2b92007-09-26 00:01:35 -040097#define APPLESMC_POLL_INTERVAL 50 /* msecs */
Nicolas Boichat6f2fad72007-05-08 00:24:52 -070098#define APPLESMC_INPUT_FUZZ 4 /* input event threshold */
99#define APPLESMC_INPUT_FLAT 4
100
Henrik Rydberg3eba2bf2010-11-09 15:15:08 +0000101#define to_index(attr) (to_sensor_dev_attr(attr)->index & 0xffff)
102#define to_option(attr) (to_sensor_dev_attr(attr)->index >> 16)
Henrik Rydberg9792dad2010-11-10 10:58:04 +0000103
Henrik Rydberg9792dad2010-11-10 10:58:04 +0000104/* Dynamic device node attributes */
105struct applesmc_dev_attr {
106 struct sensor_device_attribute sda; /* hwmon attributes */
107 char name[32]; /* room for node file name */
108};
109
110/* Dynamic device node group */
111struct applesmc_node_group {
112 char *format; /* format string */
113 void *show; /* show function */
114 void *store; /* store function */
Henrik Rydberg3eba2bf2010-11-09 15:15:08 +0000115 int option; /* function argument */
Henrik Rydberg9792dad2010-11-10 10:58:04 +0000116 struct applesmc_dev_attr *nodes; /* dynamic node array */
117};
118
Henrik Rydberg58745832010-11-10 10:58:03 +0000119/* AppleSMC entry - cached register information */
120struct applesmc_entry {
121 char key[5]; /* four-letter key code */
122 u8 valid; /* set when entry is successfully read once */
123 u8 len; /* bounded by APPLESMC_MAX_DATA_LENGTH */
124 char type[5]; /* four-letter type code */
125 u8 flags; /* 0x10: func; 0x40: write; 0x80: read */
126};
127
128/* Register lookup and registers common to all SMCs */
129static struct applesmc_registers {
130 struct mutex mutex; /* register read/write mutex */
131 unsigned int key_count; /* number of SMC registers */
Henrik Rydberg3eba2bf2010-11-09 15:15:08 +0000132 unsigned int fan_count; /* number of fans */
Henrik Rydberg9792dad2010-11-10 10:58:04 +0000133 unsigned int temp_count; /* number of temperature registers */
134 unsigned int temp_begin; /* temperature lower index bound */
135 unsigned int temp_end; /* temperature upper index bound */
Henrik Rydberg40ef06f2010-11-10 10:58:05 +0000136 int num_light_sensors; /* number of light sensors */
137 bool has_accelerometer; /* has motion sensor */
138 bool has_key_backlight; /* has keyboard backlight */
Henrik Rydberg58745832010-11-10 10:58:03 +0000139 bool init_complete; /* true when fully initialized */
140 struct applesmc_entry *cache; /* cached key entries */
141} smcreg = {
142 .mutex = __MUTEX_INITIALIZER(smcreg.mutex),
143};
144
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700145static const int debug;
146static struct platform_device *pdev;
147static s16 rest_x;
148static s16 rest_y;
Henrik Rydberga976f152009-09-21 17:04:50 -0700149static u8 backlight_state[2];
150
Tony Jones1beeffe2007-08-20 13:46:20 -0700151static struct device *hwmon_dev;
Dmitry Torokhovd5cf2b92007-09-26 00:01:35 -0400152static struct input_polled_dev *applesmc_idev;
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700153
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700154/*
155 * Last index written to key_at_index sysfs file, and value to use for all other
156 * key_at_index_* sysfs files.
157 */
158static unsigned int key_at_index;
159
160static struct workqueue_struct *applesmc_led_wq;
161
162/*
Henrik Rydberg8c9398d2008-10-18 20:27:43 -0700163 * __wait_status - Wait up to 32ms for the status port to get a certain value
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700164 * (masked with 0x0f), returning zero if the value is obtained. Callers must
165 * hold applesmc_lock.
166 */
167static int __wait_status(u8 val)
168{
Henrik Rydberg8c9398d2008-10-18 20:27:43 -0700169 int us;
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700170
171 val = val & APPLESMC_STATUS_MASK;
172
Henrik Rydberg8c9398d2008-10-18 20:27:43 -0700173 for (us = APPLESMC_MIN_WAIT; us < APPLESMC_MAX_WAIT; us <<= 1) {
174 udelay(us);
Guenter Roeck2bfe8142010-11-10 10:42:21 -0800175 if ((inb(APPLESMC_CMD_PORT) & APPLESMC_STATUS_MASK) == val)
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700176 return 0;
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700177 }
178
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700179 return -EIO;
180}
181
182/*
Henrik Rydberg84d2d7f2008-10-18 20:27:38 -0700183 * special treatment of command port - on newer macbooks, it seems necessary
184 * to resend the command byte before polling the status again. Callers must
185 * hold applesmc_lock.
186 */
187static int send_command(u8 cmd)
188{
Henrik Rydberg8c9398d2008-10-18 20:27:43 -0700189 int us;
190 for (us = APPLESMC_MIN_WAIT; us < APPLESMC_MAX_WAIT; us <<= 1) {
Henrik Rydberg84d2d7f2008-10-18 20:27:38 -0700191 outb(cmd, APPLESMC_CMD_PORT);
Henrik Rydberg8c9398d2008-10-18 20:27:43 -0700192 udelay(us);
Henrik Rydberg84d2d7f2008-10-18 20:27:38 -0700193 if ((inb(APPLESMC_CMD_PORT) & APPLESMC_STATUS_MASK) == 0x0c)
194 return 0;
Henrik Rydberg84d2d7f2008-10-18 20:27:38 -0700195 }
Henrik Rydberg84d2d7f2008-10-18 20:27:38 -0700196 return -EIO;
197}
198
Henrik Rydberg58745832010-11-10 10:58:03 +0000199static int send_argument(const char *key)
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700200{
201 int i;
202
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700203 for (i = 0; i < 4; i++) {
204 outb(key[i], APPLESMC_DATA_PORT);
205 if (__wait_status(0x04))
206 return -EIO;
207 }
Henrik Rydberg58745832010-11-10 10:58:03 +0000208 return 0;
209}
210
211static int read_smc(u8 cmd, const char *key, u8 *buffer, u8 len)
212{
213 int i;
214
215 if (send_command(cmd) || send_argument(key)) {
Henrik Rydbergac852ed2012-06-07 04:54:29 -0400216 pr_warn("%.4s: read arg fail\n", key);
Henrik Rydberg58745832010-11-10 10:58:03 +0000217 return -EIO;
218 }
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700219
220 outb(len, APPLESMC_DATA_PORT);
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700221
222 for (i = 0; i < len; i++) {
Henrik Rydberg58745832010-11-10 10:58:03 +0000223 if (__wait_status(0x05)) {
Henrik Rydbergac852ed2012-06-07 04:54:29 -0400224 pr_warn("%.4s: read data fail\n", key);
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700225 return -EIO;
Henrik Rydberg58745832010-11-10 10:58:03 +0000226 }
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700227 buffer[i] = inb(APPLESMC_DATA_PORT);
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700228 }
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700229
230 return 0;
231}
232
Henrik Rydberg58745832010-11-10 10:58:03 +0000233static int write_smc(u8 cmd, const char *key, const u8 *buffer, u8 len)
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700234{
235 int i;
236
Henrik Rydberg58745832010-11-10 10:58:03 +0000237 if (send_command(cmd) || send_argument(key)) {
238 pr_warn("%s: write arg fail\n", key);
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700239 return -EIO;
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700240 }
241
242 outb(len, APPLESMC_DATA_PORT);
243
244 for (i = 0; i < len; i++) {
Henrik Rydberg58745832010-11-10 10:58:03 +0000245 if (__wait_status(0x04)) {
246 pr_warn("%s: write data fail\n", key);
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700247 return -EIO;
Henrik Rydberg58745832010-11-10 10:58:03 +0000248 }
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700249 outb(buffer[i], APPLESMC_DATA_PORT);
250 }
251
252 return 0;
253}
254
Henrik Rydberg58745832010-11-10 10:58:03 +0000255static int read_register_count(unsigned int *count)
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700256{
Henrik Rydberg58745832010-11-10 10:58:03 +0000257 __be32 be;
258 int ret;
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700259
Henrik Rydberg58745832010-11-10 10:58:03 +0000260 ret = read_smc(APPLESMC_READ_CMD, KEY_COUNT_KEY, (u8 *)&be, 4);
261 if (ret)
262 return ret;
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700263
Henrik Rydberg58745832010-11-10 10:58:03 +0000264 *count = be32_to_cpu(be);
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700265 return 0;
266}
267
268/*
Henrik Rydberg58745832010-11-10 10:58:03 +0000269 * Serialized I/O
270 *
271 * Returns zero on success or a negative error on failure.
272 * All functions below are concurrency safe - callers should NOT hold lock.
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700273 */
Henrik Rydberg58745832010-11-10 10:58:03 +0000274
275static int applesmc_read_entry(const struct applesmc_entry *entry,
276 u8 *buf, u8 len)
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700277{
Henrik Rydberg58745832010-11-10 10:58:03 +0000278 int ret;
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700279
Henrik Rydberg58745832010-11-10 10:58:03 +0000280 if (entry->len != len)
281 return -EINVAL;
282 mutex_lock(&smcreg.mutex);
283 ret = read_smc(APPLESMC_READ_CMD, entry->key, buf, len);
284 mutex_unlock(&smcreg.mutex);
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700285
Henrik Rydberg58745832010-11-10 10:58:03 +0000286 return ret;
287}
288
289static int applesmc_write_entry(const struct applesmc_entry *entry,
290 const u8 *buf, u8 len)
291{
292 int ret;
293
294 if (entry->len != len)
295 return -EINVAL;
296 mutex_lock(&smcreg.mutex);
297 ret = write_smc(APPLESMC_WRITE_CMD, entry->key, buf, len);
298 mutex_unlock(&smcreg.mutex);
299 return ret;
300}
301
302static const struct applesmc_entry *applesmc_get_entry_by_index(int index)
303{
304 struct applesmc_entry *cache = &smcreg.cache[index];
305 u8 key[4], info[6];
306 __be32 be;
307 int ret = 0;
308
309 if (cache->valid)
310 return cache;
311
312 mutex_lock(&smcreg.mutex);
313
314 if (cache->valid)
315 goto out;
316 be = cpu_to_be32(index);
317 ret = read_smc(APPLESMC_GET_KEY_BY_INDEX_CMD, (u8 *)&be, key, 4);
318 if (ret)
319 goto out;
320 ret = read_smc(APPLESMC_GET_KEY_TYPE_CMD, key, info, 6);
321 if (ret)
322 goto out;
323
324 memcpy(cache->key, key, 4);
325 cache->len = info[0];
326 memcpy(cache->type, &info[1], 4);
327 cache->flags = info[5];
328 cache->valid = 1;
329
330out:
331 mutex_unlock(&smcreg.mutex);
332 if (ret)
333 return ERR_PTR(ret);
334 return cache;
335}
336
337static int applesmc_get_lower_bound(unsigned int *lo, const char *key)
338{
339 int begin = 0, end = smcreg.key_count;
340 const struct applesmc_entry *entry;
341
342 while (begin != end) {
343 int middle = begin + (end - begin) / 2;
344 entry = applesmc_get_entry_by_index(middle);
Henrik Rydberg0fc86ec2012-01-26 06:08:41 -0500345 if (IS_ERR(entry)) {
346 *lo = 0;
Henrik Rydberg58745832010-11-10 10:58:03 +0000347 return PTR_ERR(entry);
Henrik Rydberg0fc86ec2012-01-26 06:08:41 -0500348 }
Henrik Rydberg58745832010-11-10 10:58:03 +0000349 if (strcmp(entry->key, key) < 0)
350 begin = middle + 1;
351 else
352 end = middle;
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700353 }
354
Henrik Rydberg58745832010-11-10 10:58:03 +0000355 *lo = begin;
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700356 return 0;
357}
358
Henrik Rydberg58745832010-11-10 10:58:03 +0000359static int applesmc_get_upper_bound(unsigned int *hi, const char *key)
360{
361 int begin = 0, end = smcreg.key_count;
362 const struct applesmc_entry *entry;
363
364 while (begin != end) {
365 int middle = begin + (end - begin) / 2;
366 entry = applesmc_get_entry_by_index(middle);
Henrik Rydberg0fc86ec2012-01-26 06:08:41 -0500367 if (IS_ERR(entry)) {
368 *hi = smcreg.key_count;
Henrik Rydberg58745832010-11-10 10:58:03 +0000369 return PTR_ERR(entry);
Henrik Rydberg0fc86ec2012-01-26 06:08:41 -0500370 }
Henrik Rydberg58745832010-11-10 10:58:03 +0000371 if (strcmp(key, entry->key) < 0)
372 end = middle;
373 else
374 begin = middle + 1;
375 }
376
377 *hi = begin;
378 return 0;
379}
380
381static const struct applesmc_entry *applesmc_get_entry_by_key(const char *key)
382{
383 int begin, end;
384 int ret;
385
386 ret = applesmc_get_lower_bound(&begin, key);
387 if (ret)
388 return ERR_PTR(ret);
389 ret = applesmc_get_upper_bound(&end, key);
390 if (ret)
391 return ERR_PTR(ret);
392 if (end - begin != 1)
393 return ERR_PTR(-EINVAL);
394
395 return applesmc_get_entry_by_index(begin);
396}
397
398static int applesmc_read_key(const char *key, u8 *buffer, u8 len)
399{
400 const struct applesmc_entry *entry;
401
402 entry = applesmc_get_entry_by_key(key);
403 if (IS_ERR(entry))
404 return PTR_ERR(entry);
405
406 return applesmc_read_entry(entry, buffer, len);
407}
408
409static int applesmc_write_key(const char *key, const u8 *buffer, u8 len)
410{
411 const struct applesmc_entry *entry;
412
413 entry = applesmc_get_entry_by_key(key);
414 if (IS_ERR(entry))
415 return PTR_ERR(entry);
416
417 return applesmc_write_entry(entry, buffer, len);
418}
419
Henrik Rydberg40ef06f2010-11-10 10:58:05 +0000420static int applesmc_has_key(const char *key, bool *value)
421{
422 const struct applesmc_entry *entry;
423
424 entry = applesmc_get_entry_by_key(key);
425 if (IS_ERR(entry) && PTR_ERR(entry) != -EINVAL)
426 return PTR_ERR(entry);
427
428 *value = !IS_ERR(entry);
429 return 0;
430}
431
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700432/*
Henrik Rydbergedf48f32012-06-20 18:00:06 +0200433 * applesmc_read_s16 - Read 16-bit signed big endian register
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700434 */
Henrik Rydbergedf48f32012-06-20 18:00:06 +0200435static int applesmc_read_s16(const char *key, s16 *value)
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700436{
437 u8 buffer[2];
438 int ret;
439
Henrik Rydbergedf48f32012-06-20 18:00:06 +0200440 ret = applesmc_read_key(key, buffer, 2);
441 if (ret)
442 return ret;
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700443
444 *value = ((s16)buffer[0] << 8) | buffer[1];
Henrik Rydbergedf48f32012-06-20 18:00:06 +0200445 return 0;
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700446}
447
448/*
Henrik Rydberg2344cd02010-11-09 15:15:02 +0000449 * applesmc_device_init - initialize the accelerometer. Can sleep.
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700450 */
Henrik Rydberg2344cd02010-11-09 15:15:02 +0000451static void applesmc_device_init(void)
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700452{
Henrik Rydberg2344cd02010-11-09 15:15:02 +0000453 int total;
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700454 u8 buffer[2];
455
Henrik Rydberg40ef06f2010-11-10 10:58:05 +0000456 if (!smcreg.has_accelerometer)
Henrik Rydberg2344cd02010-11-09 15:15:02 +0000457 return;
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700458
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700459 for (total = INIT_TIMEOUT_MSECS; total > 0; total -= INIT_WAIT_MSECS) {
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700460 if (!applesmc_read_key(MOTION_SENSOR_KEY, buffer, 2) &&
Henrik Rydberg2344cd02010-11-09 15:15:02 +0000461 (buffer[0] != 0x00 || buffer[1] != 0x00))
Henrik Rydberg58745832010-11-10 10:58:03 +0000462 return;
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700463 buffer[0] = 0xe0;
464 buffer[1] = 0x00;
465 applesmc_write_key(MOTION_SENSOR_KEY, buffer, 2);
466 msleep(INIT_WAIT_MSECS);
467 }
468
Joe Perches1ee7c712010-11-09 15:15:03 +0000469 pr_warn("failed to init the device\n");
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700470}
471
472/*
Henrik Rydberg58745832010-11-10 10:58:03 +0000473 * applesmc_init_smcreg_try - Try to initialize register cache. Idempotent.
474 */
475static int applesmc_init_smcreg_try(void)
476{
477 struct applesmc_registers *s = &smcreg;
Henrik Rydberg40ef06f2010-11-10 10:58:05 +0000478 bool left_light_sensor, right_light_sensor;
Henrik Rydberg3eba2bf2010-11-09 15:15:08 +0000479 u8 tmp[1];
Henrik Rydberg58745832010-11-10 10:58:03 +0000480 int ret;
481
482 if (s->init_complete)
483 return 0;
484
485 ret = read_register_count(&s->key_count);
486 if (ret)
487 return ret;
488
489 if (!s->cache)
490 s->cache = kcalloc(s->key_count, sizeof(*s->cache), GFP_KERNEL);
491 if (!s->cache)
492 return -ENOMEM;
493
Henrik Rydberg3eba2bf2010-11-09 15:15:08 +0000494 ret = applesmc_read_key(FANS_COUNT, tmp, 1);
495 if (ret)
496 return ret;
497 s->fan_count = tmp[0];
498
Henrik Rydberg9792dad2010-11-10 10:58:04 +0000499 ret = applesmc_get_lower_bound(&s->temp_begin, "T");
500 if (ret)
501 return ret;
502 ret = applesmc_get_lower_bound(&s->temp_end, "U");
503 if (ret)
504 return ret;
505 s->temp_count = s->temp_end - s->temp_begin;
506
Henrik Rydberg40ef06f2010-11-10 10:58:05 +0000507 ret = applesmc_has_key(LIGHT_SENSOR_LEFT_KEY, &left_light_sensor);
508 if (ret)
509 return ret;
510 ret = applesmc_has_key(LIGHT_SENSOR_RIGHT_KEY, &right_light_sensor);
511 if (ret)
512 return ret;
513 ret = applesmc_has_key(MOTION_SENSOR_KEY, &s->has_accelerometer);
514 if (ret)
515 return ret;
516 ret = applesmc_has_key(BACKLIGHT_KEY, &s->has_key_backlight);
517 if (ret)
518 return ret;
519
520 s->num_light_sensors = left_light_sensor + right_light_sensor;
Henrik Rydberg58745832010-11-10 10:58:03 +0000521 s->init_complete = true;
522
Henrik Rydberg3eba2bf2010-11-09 15:15:08 +0000523 pr_info("key=%d fan=%d temp=%d acc=%d lux=%d kbd=%d\n",
524 s->key_count, s->fan_count, s->temp_count,
Henrik Rydberg40ef06f2010-11-10 10:58:05 +0000525 s->has_accelerometer,
526 s->num_light_sensors,
527 s->has_key_backlight);
Henrik Rydberg58745832010-11-10 10:58:03 +0000528
529 return 0;
530}
531
532/*
533 * applesmc_init_smcreg - Initialize register cache.
534 *
535 * Retries until initialization is successful, or the operation times out.
536 *
537 */
538static int applesmc_init_smcreg(void)
539{
540 int ms, ret;
541
542 for (ms = 0; ms < INIT_TIMEOUT_MSECS; ms += INIT_WAIT_MSECS) {
543 ret = applesmc_init_smcreg_try();
544 if (!ret) {
545 if (ms)
546 pr_info("init_smcreg() took %d ms\n", ms);
547 return 0;
548 }
549 msleep(INIT_WAIT_MSECS);
550 }
551
552 kfree(smcreg.cache);
553 smcreg.cache = NULL;
554
555 return ret;
556}
557
558static void applesmc_destroy_smcreg(void)
559{
560 kfree(smcreg.cache);
561 smcreg.cache = NULL;
562 smcreg.init_complete = false;
563}
564
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700565/* Device model stuff */
566static int applesmc_probe(struct platform_device *dev)
567{
Henrik Rydberg58745832010-11-10 10:58:03 +0000568 int ret;
569
570 ret = applesmc_init_smcreg();
571 if (ret)
572 return ret;
573
Henrik Rydberg2344cd02010-11-09 15:15:02 +0000574 applesmc_device_init();
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700575
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700576 return 0;
577}
578
Henrik Rydberga976f152009-09-21 17:04:50 -0700579/* Synchronize device with memorized backlight state */
580static int applesmc_pm_resume(struct device *dev)
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700581{
Henrik Rydberg40ef06f2010-11-10 10:58:05 +0000582 if (smcreg.has_key_backlight)
Henrik Rydberga976f152009-09-21 17:04:50 -0700583 applesmc_write_key(BACKLIGHT_KEY, backlight_state, 2);
Henrik Rydberga976f152009-09-21 17:04:50 -0700584 return 0;
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700585}
586
Henrik Rydberga976f152009-09-21 17:04:50 -0700587/* Reinitialize device on resume from hibernation */
588static int applesmc_pm_restore(struct device *dev)
589{
Henrik Rydberg2344cd02010-11-09 15:15:02 +0000590 applesmc_device_init();
Henrik Rydberga976f152009-09-21 17:04:50 -0700591 return applesmc_pm_resume(dev);
592}
593
Alexey Dobriyan47145212009-12-14 18:00:08 -0800594static const struct dev_pm_ops applesmc_pm_ops = {
Henrik Rydberga976f152009-09-21 17:04:50 -0700595 .resume = applesmc_pm_resume,
596 .restore = applesmc_pm_restore,
597};
598
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700599static struct platform_driver applesmc_driver = {
600 .probe = applesmc_probe,
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700601 .driver = {
602 .name = "applesmc",
603 .owner = THIS_MODULE,
Henrik Rydberga976f152009-09-21 17:04:50 -0700604 .pm = &applesmc_pm_ops,
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700605 },
606};
607
608/*
609 * applesmc_calibrate - Set our "resting" values. Callers must
610 * hold applesmc_lock.
611 */
612static void applesmc_calibrate(void)
613{
Henrik Rydbergedf48f32012-06-20 18:00:06 +0200614 applesmc_read_s16(MOTION_SENSOR_X_KEY, &rest_x);
615 applesmc_read_s16(MOTION_SENSOR_Y_KEY, &rest_y);
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700616 rest_x = -rest_x;
617}
618
Dmitry Torokhovd5cf2b92007-09-26 00:01:35 -0400619static void applesmc_idev_poll(struct input_polled_dev *dev)
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700620{
Dmitry Torokhovd5cf2b92007-09-26 00:01:35 -0400621 struct input_dev *idev = dev->input;
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700622 s16 x, y;
623
Henrik Rydbergedf48f32012-06-20 18:00:06 +0200624 if (applesmc_read_s16(MOTION_SENSOR_X_KEY, &x))
Henrik Rydberg58745832010-11-10 10:58:03 +0000625 return;
Henrik Rydbergedf48f32012-06-20 18:00:06 +0200626 if (applesmc_read_s16(MOTION_SENSOR_Y_KEY, &y))
Henrik Rydberg58745832010-11-10 10:58:03 +0000627 return;
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700628
629 x = -x;
Dmitry Torokhovd5cf2b92007-09-26 00:01:35 -0400630 input_report_abs(idev, ABS_X, x - rest_x);
631 input_report_abs(idev, ABS_Y, y - rest_y);
632 input_sync(idev);
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700633}
634
635/* Sysfs Files */
636
Nicolas Boichatfa744192007-05-23 13:58:13 -0700637static ssize_t applesmc_name_show(struct device *dev,
638 struct device_attribute *attr, char *buf)
639{
640 return snprintf(buf, PAGE_SIZE, "applesmc\n");
641}
642
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700643static ssize_t applesmc_position_show(struct device *dev,
644 struct device_attribute *attr, char *buf)
645{
646 int ret;
647 s16 x, y, z;
648
Henrik Rydbergedf48f32012-06-20 18:00:06 +0200649 ret = applesmc_read_s16(MOTION_SENSOR_X_KEY, &x);
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700650 if (ret)
651 goto out;
Henrik Rydbergedf48f32012-06-20 18:00:06 +0200652 ret = applesmc_read_s16(MOTION_SENSOR_Y_KEY, &y);
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700653 if (ret)
654 goto out;
Henrik Rydbergedf48f32012-06-20 18:00:06 +0200655 ret = applesmc_read_s16(MOTION_SENSOR_Z_KEY, &z);
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700656 if (ret)
657 goto out;
658
659out:
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700660 if (ret)
661 return ret;
662 else
663 return snprintf(buf, PAGE_SIZE, "(%d,%d,%d)\n", x, y, z);
664}
665
666static ssize_t applesmc_light_show(struct device *dev,
667 struct device_attribute *attr, char *sysfsbuf)
668{
Henrik Rydberg58745832010-11-10 10:58:03 +0000669 const struct applesmc_entry *entry;
Henrik Rydberg8bd1a122008-10-18 20:27:39 -0700670 static int data_length;
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700671 int ret;
672 u8 left = 0, right = 0;
Henrik Rydberg58745832010-11-10 10:58:03 +0000673 u8 buffer[10];
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700674
Henrik Rydberg8bd1a122008-10-18 20:27:39 -0700675 if (!data_length) {
Henrik Rydberg58745832010-11-10 10:58:03 +0000676 entry = applesmc_get_entry_by_key(LIGHT_SENSOR_LEFT_KEY);
677 if (IS_ERR(entry))
678 return PTR_ERR(entry);
679 if (entry->len > 10)
680 return -ENXIO;
681 data_length = entry->len;
Joe Perches1ee7c712010-11-09 15:15:03 +0000682 pr_info("light sensor data length set to %d\n", data_length);
Henrik Rydberg8bd1a122008-10-18 20:27:39 -0700683 }
684
685 ret = applesmc_read_key(LIGHT_SENSOR_LEFT_KEY, buffer, data_length);
Alex Murrayc3d63622009-01-15 13:51:08 -0800686 /* newer macbooks report a single 10-bit bigendian value */
687 if (data_length == 10) {
688 left = be16_to_cpu(*(__be16 *)(buffer + 6)) >> 2;
689 goto out;
690 }
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700691 left = buffer[2];
692 if (ret)
693 goto out;
Henrik Rydberg8bd1a122008-10-18 20:27:39 -0700694 ret = applesmc_read_key(LIGHT_SENSOR_RIGHT_KEY, buffer, data_length);
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700695 right = buffer[2];
696
697out:
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700698 if (ret)
699 return ret;
700 else
701 return snprintf(sysfsbuf, PAGE_SIZE, "(%d,%d)\n", left, right);
702}
703
Alex Murrayfa5575c2010-05-27 19:58:54 +0200704/* Displays sensor key as label */
705static ssize_t applesmc_show_sensor_label(struct device *dev,
706 struct device_attribute *devattr, char *sysfsbuf)
707{
Henrik Rydberg9792dad2010-11-10 10:58:04 +0000708 int index = smcreg.temp_begin + to_index(devattr);
709 const struct applesmc_entry *entry;
Alex Murrayfa5575c2010-05-27 19:58:54 +0200710
Henrik Rydberg9792dad2010-11-10 10:58:04 +0000711 entry = applesmc_get_entry_by_index(index);
712 if (IS_ERR(entry))
713 return PTR_ERR(entry);
714
715 return snprintf(sysfsbuf, PAGE_SIZE, "%s\n", entry->key);
Alex Murrayfa5575c2010-05-27 19:58:54 +0200716}
717
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700718/* Displays degree Celsius * 1000 */
719static ssize_t applesmc_show_temperature(struct device *dev,
720 struct device_attribute *devattr, char *sysfsbuf)
721{
Henrik Rydberg9792dad2010-11-10 10:58:04 +0000722 int index = smcreg.temp_begin + to_index(devattr);
723 const struct applesmc_entry *entry;
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700724 int ret;
Henrik Rydbergb6e51222012-07-16 09:18:10 +0200725 s16 value;
726 int temp;
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700727
Henrik Rydberg9792dad2010-11-10 10:58:04 +0000728 entry = applesmc_get_entry_by_index(index);
729 if (IS_ERR(entry))
730 return PTR_ERR(entry);
Henrik Rydbergb6e51222012-07-16 09:18:10 +0200731 if (strcmp(entry->type, TEMP_SENSOR_TYPE))
Henrik Rydbergdcdea262010-11-09 15:15:06 +0000732 return -EINVAL;
Henrik Rydberg9792dad2010-11-10 10:58:04 +0000733
Henrik Rydbergb6e51222012-07-16 09:18:10 +0200734 ret = applesmc_read_s16(entry->key, &value);
Henrik Rydberg9792dad2010-11-10 10:58:04 +0000735 if (ret)
736 return ret;
737
Henrik Rydbergb6e51222012-07-16 09:18:10 +0200738 temp = 250 * (value >> 6);
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700739
Henrik Rydbergb6e51222012-07-16 09:18:10 +0200740 return snprintf(sysfsbuf, PAGE_SIZE, "%d\n", temp);
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700741}
742
743static ssize_t applesmc_show_fan_speed(struct device *dev,
744 struct device_attribute *attr, char *sysfsbuf)
745{
746 int ret;
747 unsigned int speed = 0;
748 char newkey[5];
749 u8 buffer[2];
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700750
Henrik Rydberg3eba2bf2010-11-09 15:15:08 +0000751 sprintf(newkey, fan_speed_fmt[to_option(attr)], to_index(attr));
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700752
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700753 ret = applesmc_read_key(newkey, buffer, 2);
754 speed = ((buffer[0] << 8 | buffer[1]) >> 2);
755
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700756 if (ret)
757 return ret;
758 else
759 return snprintf(sysfsbuf, PAGE_SIZE, "%u\n", speed);
760}
761
762static ssize_t applesmc_store_fan_speed(struct device *dev,
763 struct device_attribute *attr,
764 const char *sysfsbuf, size_t count)
765{
766 int ret;
Guenter Roeck2bfe8142010-11-10 10:42:21 -0800767 unsigned long speed;
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700768 char newkey[5];
769 u8 buffer[2];
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700770
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100771 if (kstrtoul(sysfsbuf, 10, &speed) < 0 || speed >= 0x4000)
Guenter Roeck2bfe8142010-11-10 10:42:21 -0800772 return -EINVAL; /* Bigger than a 14-bit value */
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700773
Henrik Rydberg3eba2bf2010-11-09 15:15:08 +0000774 sprintf(newkey, fan_speed_fmt[to_option(attr)], to_index(attr));
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700775
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700776 buffer[0] = (speed >> 6) & 0xff;
777 buffer[1] = (speed << 2) & 0xff;
778 ret = applesmc_write_key(newkey, buffer, 2);
779
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700780 if (ret)
781 return ret;
782 else
783 return count;
784}
785
786static ssize_t applesmc_show_fan_manual(struct device *dev,
Henrik Rydberg3eba2bf2010-11-09 15:15:08 +0000787 struct device_attribute *attr, char *sysfsbuf)
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700788{
789 int ret;
790 u16 manual = 0;
791 u8 buffer[2];
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700792
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700793 ret = applesmc_read_key(FANS_MANUAL, buffer, 2);
Henrik Rydberg3eba2bf2010-11-09 15:15:08 +0000794 manual = ((buffer[0] << 8 | buffer[1]) >> to_index(attr)) & 0x01;
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700795
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700796 if (ret)
797 return ret;
798 else
799 return snprintf(sysfsbuf, PAGE_SIZE, "%d\n", manual);
800}
801
802static ssize_t applesmc_store_fan_manual(struct device *dev,
Henrik Rydberg3eba2bf2010-11-09 15:15:08 +0000803 struct device_attribute *attr,
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700804 const char *sysfsbuf, size_t count)
805{
806 int ret;
807 u8 buffer[2];
Guenter Roeck2bfe8142010-11-10 10:42:21 -0800808 unsigned long input;
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700809 u16 val;
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700810
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100811 if (kstrtoul(sysfsbuf, 10, &input) < 0)
Guenter Roeck2bfe8142010-11-10 10:42:21 -0800812 return -EINVAL;
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700813
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700814 ret = applesmc_read_key(FANS_MANUAL, buffer, 2);
815 val = (buffer[0] << 8 | buffer[1]);
816 if (ret)
817 goto out;
818
819 if (input)
Henrik Rydberg3eba2bf2010-11-09 15:15:08 +0000820 val = val | (0x01 << to_index(attr));
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700821 else
Henrik Rydberg3eba2bf2010-11-09 15:15:08 +0000822 val = val & ~(0x01 << to_index(attr));
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700823
824 buffer[0] = (val >> 8) & 0xFF;
825 buffer[1] = val & 0xFF;
826
827 ret = applesmc_write_key(FANS_MANUAL, buffer, 2);
828
829out:
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700830 if (ret)
831 return ret;
832 else
833 return count;
834}
835
836static ssize_t applesmc_show_fan_position(struct device *dev,
837 struct device_attribute *attr, char *sysfsbuf)
838{
839 int ret;
840 char newkey[5];
841 u8 buffer[17];
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700842
Henrik Rydberg3eba2bf2010-11-09 15:15:08 +0000843 sprintf(newkey, FAN_ID_FMT, to_index(attr));
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700844
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700845 ret = applesmc_read_key(newkey, buffer, 16);
846 buffer[16] = 0;
847
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700848 if (ret)
849 return ret;
850 else
851 return snprintf(sysfsbuf, PAGE_SIZE, "%s\n", buffer+4);
852}
853
854static ssize_t applesmc_calibrate_show(struct device *dev,
855 struct device_attribute *attr, char *sysfsbuf)
856{
857 return snprintf(sysfsbuf, PAGE_SIZE, "(%d,%d)\n", rest_x, rest_y);
858}
859
860static ssize_t applesmc_calibrate_store(struct device *dev,
861 struct device_attribute *attr, const char *sysfsbuf, size_t count)
862{
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700863 applesmc_calibrate();
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700864
865 return count;
866}
867
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700868static void applesmc_backlight_set(struct work_struct *work)
869{
Henrik Rydberga976f152009-09-21 17:04:50 -0700870 applesmc_write_key(BACKLIGHT_KEY, backlight_state, 2);
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700871}
872static DECLARE_WORK(backlight_work, &applesmc_backlight_set);
873
874static void applesmc_brightness_set(struct led_classdev *led_cdev,
875 enum led_brightness value)
876{
877 int ret;
878
Henrik Rydberga976f152009-09-21 17:04:50 -0700879 backlight_state[0] = value;
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700880 ret = queue_work(applesmc_led_wq, &backlight_work);
881
882 if (debug && (!ret))
883 printk(KERN_DEBUG "applesmc: work was already on the queue.\n");
884}
885
886static ssize_t applesmc_key_count_show(struct device *dev,
887 struct device_attribute *attr, char *sysfsbuf)
888{
889 int ret;
890 u8 buffer[4];
891 u32 count;
892
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700893 ret = applesmc_read_key(KEY_COUNT_KEY, buffer, 4);
894 count = ((u32)buffer[0]<<24) + ((u32)buffer[1]<<16) +
895 ((u32)buffer[2]<<8) + buffer[3];
896
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700897 if (ret)
898 return ret;
899 else
900 return snprintf(sysfsbuf, PAGE_SIZE, "%d\n", count);
901}
902
903static ssize_t applesmc_key_at_index_read_show(struct device *dev,
904 struct device_attribute *attr, char *sysfsbuf)
905{
Henrik Rydberg58745832010-11-10 10:58:03 +0000906 const struct applesmc_entry *entry;
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700907 int ret;
908
Henrik Rydberg58745832010-11-10 10:58:03 +0000909 entry = applesmc_get_entry_by_index(key_at_index);
910 if (IS_ERR(entry))
911 return PTR_ERR(entry);
912 ret = applesmc_read_entry(entry, sysfsbuf, entry->len);
913 if (ret)
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700914 return ret;
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700915
Henrik Rydberg58745832010-11-10 10:58:03 +0000916 return entry->len;
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700917}
918
919static ssize_t applesmc_key_at_index_data_length_show(struct device *dev,
920 struct device_attribute *attr, char *sysfsbuf)
921{
Henrik Rydberg58745832010-11-10 10:58:03 +0000922 const struct applesmc_entry *entry;
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700923
Henrik Rydberg58745832010-11-10 10:58:03 +0000924 entry = applesmc_get_entry_by_index(key_at_index);
925 if (IS_ERR(entry))
926 return PTR_ERR(entry);
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700927
Henrik Rydberg58745832010-11-10 10:58:03 +0000928 return snprintf(sysfsbuf, PAGE_SIZE, "%d\n", entry->len);
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700929}
930
931static ssize_t applesmc_key_at_index_type_show(struct device *dev,
932 struct device_attribute *attr, char *sysfsbuf)
933{
Henrik Rydberg58745832010-11-10 10:58:03 +0000934 const struct applesmc_entry *entry;
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700935
Henrik Rydberg58745832010-11-10 10:58:03 +0000936 entry = applesmc_get_entry_by_index(key_at_index);
937 if (IS_ERR(entry))
938 return PTR_ERR(entry);
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700939
Henrik Rydberg58745832010-11-10 10:58:03 +0000940 return snprintf(sysfsbuf, PAGE_SIZE, "%s\n", entry->type);
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700941}
942
943static ssize_t applesmc_key_at_index_name_show(struct device *dev,
944 struct device_attribute *attr, char *sysfsbuf)
945{
Henrik Rydberg58745832010-11-10 10:58:03 +0000946 const struct applesmc_entry *entry;
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700947
Henrik Rydberg58745832010-11-10 10:58:03 +0000948 entry = applesmc_get_entry_by_index(key_at_index);
949 if (IS_ERR(entry))
950 return PTR_ERR(entry);
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700951
Henrik Rydberg58745832010-11-10 10:58:03 +0000952 return snprintf(sysfsbuf, PAGE_SIZE, "%s\n", entry->key);
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700953}
954
955static ssize_t applesmc_key_at_index_show(struct device *dev,
956 struct device_attribute *attr, char *sysfsbuf)
957{
958 return snprintf(sysfsbuf, PAGE_SIZE, "%d\n", key_at_index);
959}
960
961static ssize_t applesmc_key_at_index_store(struct device *dev,
962 struct device_attribute *attr, const char *sysfsbuf, size_t count)
963{
Henrik Rydberg58745832010-11-10 10:58:03 +0000964 unsigned long newkey;
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700965
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100966 if (kstrtoul(sysfsbuf, 10, &newkey) < 0
Henrik Rydberg58745832010-11-10 10:58:03 +0000967 || newkey >= smcreg.key_count)
968 return -EINVAL;
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700969
Henrik Rydberg58745832010-11-10 10:58:03 +0000970 key_at_index = newkey;
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700971 return count;
972}
973
974static struct led_classdev applesmc_backlight = {
Richard Purdie6c152be2007-10-31 15:00:07 +0100975 .name = "smc::kbd_backlight",
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700976 .default_trigger = "nand-disk",
977 .brightness_set = applesmc_brightness_set,
978};
979
Henrik Rydberg0b0b5df2010-11-09 15:15:09 +0000980static struct applesmc_node_group info_group[] = {
981 { "name", applesmc_name_show },
982 { "key_count", applesmc_key_count_show },
983 { "key_at_index", applesmc_key_at_index_show, applesmc_key_at_index_store },
984 { "key_at_index_name", applesmc_key_at_index_name_show },
985 { "key_at_index_type", applesmc_key_at_index_type_show },
986 { "key_at_index_data_length", applesmc_key_at_index_data_length_show },
987 { "key_at_index_data", applesmc_key_at_index_read_show },
988 { }
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700989};
990
Henrik Rydberg0b0b5df2010-11-09 15:15:09 +0000991static struct applesmc_node_group accelerometer_group[] = {
992 { "position", applesmc_position_show },
993 { "calibrate", applesmc_calibrate_show, applesmc_calibrate_store },
994 { }
Nicolas Boichat6f2fad72007-05-08 00:24:52 -0700995};
996
Henrik Rydberg0b0b5df2010-11-09 15:15:09 +0000997static struct applesmc_node_group light_sensor_group[] = {
998 { "light", applesmc_light_show },
999 { }
1000};
Nicolas Boichat6f2fad72007-05-08 00:24:52 -07001001
Henrik Rydberg3eba2bf2010-11-09 15:15:08 +00001002static struct applesmc_node_group fan_group[] = {
1003 { "fan%d_label", applesmc_show_fan_position },
1004 { "fan%d_input", applesmc_show_fan_speed, NULL, 0 },
1005 { "fan%d_min", applesmc_show_fan_speed, applesmc_store_fan_speed, 1 },
1006 { "fan%d_max", applesmc_show_fan_speed, NULL, 2 },
1007 { "fan%d_safe", applesmc_show_fan_speed, NULL, 3 },
1008 { "fan%d_output", applesmc_show_fan_speed, applesmc_store_fan_speed, 4 },
1009 { "fan%d_manual", applesmc_show_fan_manual, applesmc_store_fan_manual },
1010 { }
Nicolas Boichat6f2fad72007-05-08 00:24:52 -07001011};
1012
Henrik Rydberg9792dad2010-11-10 10:58:04 +00001013static struct applesmc_node_group temp_group[] = {
1014 { "temp%d_label", applesmc_show_sensor_label },
1015 { "temp%d_input", applesmc_show_temperature },
1016 { }
Alex Murrayfa5575c2010-05-27 19:58:54 +02001017};
1018
Nicolas Boichat6f2fad72007-05-08 00:24:52 -07001019/* Module stuff */
1020
1021/*
Henrik Rydberg9792dad2010-11-10 10:58:04 +00001022 * applesmc_destroy_nodes - remove files and free associated memory
1023 */
1024static void applesmc_destroy_nodes(struct applesmc_node_group *groups)
1025{
1026 struct applesmc_node_group *grp;
1027 struct applesmc_dev_attr *node;
1028
1029 for (grp = groups; grp->nodes; grp++) {
1030 for (node = grp->nodes; node->sda.dev_attr.attr.name; node++)
1031 sysfs_remove_file(&pdev->dev.kobj,
1032 &node->sda.dev_attr.attr);
1033 kfree(grp->nodes);
1034 grp->nodes = NULL;
1035 }
1036}
1037
1038/*
1039 * applesmc_create_nodes - create a two-dimensional group of sysfs files
1040 */
1041static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
1042{
1043 struct applesmc_node_group *grp;
1044 struct applesmc_dev_attr *node;
1045 struct attribute *attr;
1046 int ret, i;
1047
1048 for (grp = groups; grp->format; grp++) {
1049 grp->nodes = kcalloc(num + 1, sizeof(*node), GFP_KERNEL);
1050 if (!grp->nodes) {
1051 ret = -ENOMEM;
1052 goto out;
1053 }
1054 for (i = 0; i < num; i++) {
1055 node = &grp->nodes[i];
1056 sprintf(node->name, grp->format, i + 1);
Henrik Rydberg3eba2bf2010-11-09 15:15:08 +00001057 node->sda.index = (grp->option << 16) | (i & 0xffff);
Henrik Rydberg9792dad2010-11-10 10:58:04 +00001058 node->sda.dev_attr.show = grp->show;
1059 node->sda.dev_attr.store = grp->store;
1060 attr = &node->sda.dev_attr.attr;
Henrik Rydberg9d1f8a402011-01-22 20:55:39 +01001061 sysfs_attr_init(attr);
Henrik Rydberg9792dad2010-11-10 10:58:04 +00001062 attr->name = node->name;
1063 attr->mode = S_IRUGO | (grp->store ? S_IWUSR : 0);
1064 ret = sysfs_create_file(&pdev->dev.kobj, attr);
1065 if (ret) {
1066 attr->name = NULL;
1067 goto out;
1068 }
1069 }
1070 }
1071
1072 return 0;
1073out:
1074 applesmc_destroy_nodes(groups);
1075 return ret;
1076}
1077
Nicolas Boichat6f2fad72007-05-08 00:24:52 -07001078/* Create accelerometer ressources */
1079static int applesmc_create_accelerometer(void)
1080{
Dmitry Torokhovd5cf2b92007-09-26 00:01:35 -04001081 struct input_dev *idev;
Nicolas Boichat6f2fad72007-05-08 00:24:52 -07001082 int ret;
1083
Henrik Rydberg0b0b5df2010-11-09 15:15:09 +00001084 if (!smcreg.has_accelerometer)
1085 return 0;
1086
1087 ret = applesmc_create_nodes(accelerometer_group, 1);
Nicolas Boichat6f2fad72007-05-08 00:24:52 -07001088 if (ret)
1089 goto out;
1090
Dmitry Torokhovd5cf2b92007-09-26 00:01:35 -04001091 applesmc_idev = input_allocate_polled_device();
Nicolas Boichat6f2fad72007-05-08 00:24:52 -07001092 if (!applesmc_idev) {
1093 ret = -ENOMEM;
1094 goto out_sysfs;
1095 }
1096
Dmitry Torokhovd5cf2b92007-09-26 00:01:35 -04001097 applesmc_idev->poll = applesmc_idev_poll;
1098 applesmc_idev->poll_interval = APPLESMC_POLL_INTERVAL;
1099
Nicolas Boichat6f2fad72007-05-08 00:24:52 -07001100 /* initial calibrate for the input device */
1101 applesmc_calibrate();
1102
Dmitry Torokhovd5cf2b92007-09-26 00:01:35 -04001103 /* initialize the input device */
1104 idev = applesmc_idev->input;
1105 idev->name = "applesmc";
1106 idev->id.bustype = BUS_HOST;
1107 idev->dev.parent = &pdev->dev;
Jiri Slaby7b19ada2007-10-18 23:40:32 -07001108 idev->evbit[0] = BIT_MASK(EV_ABS);
Dmitry Torokhovd5cf2b92007-09-26 00:01:35 -04001109 input_set_abs_params(idev, ABS_X,
Nicolas Boichat6f2fad72007-05-08 00:24:52 -07001110 -256, 256, APPLESMC_INPUT_FUZZ, APPLESMC_INPUT_FLAT);
Dmitry Torokhovd5cf2b92007-09-26 00:01:35 -04001111 input_set_abs_params(idev, ABS_Y,
Nicolas Boichat6f2fad72007-05-08 00:24:52 -07001112 -256, 256, APPLESMC_INPUT_FUZZ, APPLESMC_INPUT_FLAT);
1113
Dmitry Torokhovd5cf2b92007-09-26 00:01:35 -04001114 ret = input_register_polled_device(applesmc_idev);
Nicolas Boichat6f2fad72007-05-08 00:24:52 -07001115 if (ret)
1116 goto out_idev;
1117
Nicolas Boichat6f2fad72007-05-08 00:24:52 -07001118 return 0;
1119
1120out_idev:
Dmitry Torokhovd5cf2b92007-09-26 00:01:35 -04001121 input_free_polled_device(applesmc_idev);
Nicolas Boichat6f2fad72007-05-08 00:24:52 -07001122
1123out_sysfs:
Henrik Rydberg0b0b5df2010-11-09 15:15:09 +00001124 applesmc_destroy_nodes(accelerometer_group);
Nicolas Boichat6f2fad72007-05-08 00:24:52 -07001125
1126out:
Joe Perches1ee7c712010-11-09 15:15:03 +00001127 pr_warn("driver init failed (ret=%d)!\n", ret);
Nicolas Boichat6f2fad72007-05-08 00:24:52 -07001128 return ret;
1129}
1130
1131/* Release all ressources used by the accelerometer */
1132static void applesmc_release_accelerometer(void)
1133{
Henrik Rydberg0b0b5df2010-11-09 15:15:09 +00001134 if (!smcreg.has_accelerometer)
1135 return;
Dmitry Torokhovd5cf2b92007-09-26 00:01:35 -04001136 input_unregister_polled_device(applesmc_idev);
1137 input_free_polled_device(applesmc_idev);
Henrik Rydberg0b0b5df2010-11-09 15:15:09 +00001138 applesmc_destroy_nodes(accelerometer_group);
Nicolas Boichat6f2fad72007-05-08 00:24:52 -07001139}
Henrik Rydberg0b0b5df2010-11-09 15:15:09 +00001140
1141static int applesmc_create_light_sensor(void)
1142{
1143 if (!smcreg.num_light_sensors)
1144 return 0;
1145 return applesmc_create_nodes(light_sensor_group, 1);
1146}
1147
1148static void applesmc_release_light_sensor(void)
1149{
1150 if (!smcreg.num_light_sensors)
1151 return;
1152 applesmc_destroy_nodes(light_sensor_group);
1153}
1154
1155static int applesmc_create_key_backlight(void)
1156{
1157 if (!smcreg.has_key_backlight)
1158 return 0;
1159 applesmc_led_wq = create_singlethread_workqueue("applesmc-led");
1160 if (!applesmc_led_wq)
1161 return -ENOMEM;
1162 return led_classdev_register(&pdev->dev, &applesmc_backlight);
1163}
1164
1165static void applesmc_release_key_backlight(void)
1166{
1167 if (!smcreg.has_key_backlight)
1168 return;
1169 led_classdev_unregister(&applesmc_backlight);
1170 destroy_workqueue(applesmc_led_wq);
1171}
1172
Henrik Rydberg40ef06f2010-11-10 10:58:05 +00001173static int applesmc_dmi_match(const struct dmi_system_id *id)
1174{
1175 return 1;
1176}
Nicolas Boichat6f2fad72007-05-08 00:24:52 -07001177
Guenter Roeck85ebfd32012-01-19 11:02:15 -08001178/*
1179 * Note that DMI_MATCH(...,"MacBook") will match "MacBookPro1,1".
1180 * So we need to put "Apple MacBook Pro" before "Apple MacBook".
1181 */
Nicolas Boichat6f2fad72007-05-08 00:24:52 -07001182static __initdata struct dmi_system_id applesmc_whitelist[] = {
Henrik Rydbergf5274c92008-10-18 20:27:40 -07001183 { applesmc_dmi_match, "Apple MacBook Air", {
1184 DMI_MATCH(DMI_BOARD_VENDOR, "Apple"),
1185 DMI_MATCH(DMI_PRODUCT_NAME, "MacBookAir") },
Henrik Rydberg40ef06f2010-11-10 10:58:05 +00001186 },
Nicolas Boichat6f2fad72007-05-08 00:24:52 -07001187 { applesmc_dmi_match, "Apple MacBook Pro", {
Guenter Roeck2bfe8142010-11-10 10:42:21 -08001188 DMI_MATCH(DMI_BOARD_VENDOR, "Apple"),
1189 DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro") },
Henrik Rydberg40ef06f2010-11-10 10:58:05 +00001190 },
Riki Oktariantocd19ba12008-02-04 23:41:58 -08001191 { applesmc_dmi_match, "Apple MacBook", {
Guenter Roeck2bfe8142010-11-10 10:42:21 -08001192 DMI_MATCH(DMI_BOARD_VENDOR, "Apple"),
1193 DMI_MATCH(DMI_PRODUCT_NAME, "MacBook") },
Henrik Rydberg40ef06f2010-11-10 10:58:05 +00001194 },
Nicolas Boichat6f2fad72007-05-08 00:24:52 -07001195 { applesmc_dmi_match, "Apple Macmini", {
Guenter Roeck2bfe8142010-11-10 10:42:21 -08001196 DMI_MATCH(DMI_BOARD_VENDOR, "Apple"),
1197 DMI_MATCH(DMI_PRODUCT_NAME, "Macmini") },
Henrik Rydberg40ef06f2010-11-10 10:58:05 +00001198 },
Henrik Rydberg45a3a362008-11-19 15:36:42 -08001199 { applesmc_dmi_match, "Apple MacPro", {
1200 DMI_MATCH(DMI_BOARD_VENDOR, "Apple"),
1201 DMI_MATCH(DMI_PRODUCT_NAME, "MacPro") },
Henrik Rydberg40ef06f2010-11-10 10:58:05 +00001202 },
Roberto De Ioris9f86f282008-08-15 00:40:30 -07001203 { applesmc_dmi_match, "Apple iMac", {
Guenter Roeck2bfe8142010-11-10 10:42:21 -08001204 DMI_MATCH(DMI_BOARD_VENDOR, "Apple"),
1205 DMI_MATCH(DMI_PRODUCT_NAME, "iMac") },
Henrik Rydberg40ef06f2010-11-10 10:58:05 +00001206 },
Nicolas Boichat6f2fad72007-05-08 00:24:52 -07001207 { .ident = NULL }
1208};
1209
1210static int __init applesmc_init(void)
1211{
1212 int ret;
Nicolas Boichat6f2fad72007-05-08 00:24:52 -07001213
Nicolas Boichat6f2fad72007-05-08 00:24:52 -07001214 if (!dmi_check_system(applesmc_whitelist)) {
Joe Perches1ee7c712010-11-09 15:15:03 +00001215 pr_warn("supported laptop not found!\n");
Nicolas Boichat6f2fad72007-05-08 00:24:52 -07001216 ret = -ENODEV;
1217 goto out;
1218 }
1219
1220 if (!request_region(APPLESMC_DATA_PORT, APPLESMC_NR_PORTS,
1221 "applesmc")) {
1222 ret = -ENXIO;
1223 goto out;
1224 }
1225
1226 ret = platform_driver_register(&applesmc_driver);
1227 if (ret)
1228 goto out_region;
1229
Jean Delvareddfbf2a2007-05-08 20:27:04 -07001230 pdev = platform_device_register_simple("applesmc", APPLESMC_DATA_PORT,
1231 NULL, 0);
Nicolas Boichat6f2fad72007-05-08 00:24:52 -07001232 if (IS_ERR(pdev)) {
1233 ret = PTR_ERR(pdev);
1234 goto out_driver;
1235 }
1236
Henrik Rydberg58745832010-11-10 10:58:03 +00001237 /* create register cache */
1238 ret = applesmc_init_smcreg();
Nicolas Boichat6996abf2007-05-27 22:17:43 +02001239 if (ret)
1240 goto out_device;
Nicolas Boichatfa744192007-05-23 13:58:13 -07001241
Henrik Rydberg0b0b5df2010-11-09 15:15:09 +00001242 ret = applesmc_create_nodes(info_group, 1);
Henrik Rydberg58745832010-11-10 10:58:03 +00001243 if (ret)
1244 goto out_smcreg;
1245
Henrik Rydberg3eba2bf2010-11-09 15:15:08 +00001246 ret = applesmc_create_nodes(fan_group, smcreg.fan_count);
1247 if (ret)
1248 goto out_info;
Nicolas Boichat6f2fad72007-05-08 00:24:52 -07001249
Henrik Rydberg9792dad2010-11-10 10:58:04 +00001250 ret = applesmc_create_nodes(temp_group, smcreg.temp_count);
1251 if (ret)
1252 goto out_fans;
Nicolas Boichat6f2fad72007-05-08 00:24:52 -07001253
Henrik Rydberg0b0b5df2010-11-09 15:15:09 +00001254 ret = applesmc_create_accelerometer();
1255 if (ret)
1256 goto out_temperature;
Nicolas Boichat6f2fad72007-05-08 00:24:52 -07001257
Henrik Rydberg0b0b5df2010-11-09 15:15:09 +00001258 ret = applesmc_create_light_sensor();
1259 if (ret)
1260 goto out_accelerometer;
Nicolas Boichat6f2fad72007-05-08 00:24:52 -07001261
Henrik Rydberg0b0b5df2010-11-09 15:15:09 +00001262 ret = applesmc_create_key_backlight();
1263 if (ret)
1264 goto out_light_sysfs;
Nicolas Boichat6f2fad72007-05-08 00:24:52 -07001265
Tony Jones1beeffe2007-08-20 13:46:20 -07001266 hwmon_dev = hwmon_device_register(&pdev->dev);
1267 if (IS_ERR(hwmon_dev)) {
1268 ret = PTR_ERR(hwmon_dev);
Nicolas Boichat6f2fad72007-05-08 00:24:52 -07001269 goto out_light_ledclass;
1270 }
1271
Nicolas Boichat6f2fad72007-05-08 00:24:52 -07001272 return 0;
1273
1274out_light_ledclass:
Henrik Rydberg0b0b5df2010-11-09 15:15:09 +00001275 applesmc_release_key_backlight();
Nicolas Boichat6f2fad72007-05-08 00:24:52 -07001276out_light_sysfs:
Henrik Rydberg0b0b5df2010-11-09 15:15:09 +00001277 applesmc_release_light_sensor();
Nicolas Boichat6f2fad72007-05-08 00:24:52 -07001278out_accelerometer:
Henrik Rydberg0b0b5df2010-11-09 15:15:09 +00001279 applesmc_release_accelerometer();
Nicolas Boichat6f2fad72007-05-08 00:24:52 -07001280out_temperature:
Henrik Rydberg9792dad2010-11-10 10:58:04 +00001281 applesmc_destroy_nodes(temp_group);
Henrik Rydberg0559a532010-05-11 09:17:47 +02001282out_fans:
Henrik Rydberg3eba2bf2010-11-09 15:15:08 +00001283 applesmc_destroy_nodes(fan_group);
1284out_info:
Henrik Rydberg0b0b5df2010-11-09 15:15:09 +00001285 applesmc_destroy_nodes(info_group);
Henrik Rydberg58745832010-11-10 10:58:03 +00001286out_smcreg:
1287 applesmc_destroy_smcreg();
Nicolas Boichat6f2fad72007-05-08 00:24:52 -07001288out_device:
1289 platform_device_unregister(pdev);
1290out_driver:
1291 platform_driver_unregister(&applesmc_driver);
1292out_region:
1293 release_region(APPLESMC_DATA_PORT, APPLESMC_NR_PORTS);
1294out:
Joe Perches1ee7c712010-11-09 15:15:03 +00001295 pr_warn("driver init failed (ret=%d)!\n", ret);
Nicolas Boichat6f2fad72007-05-08 00:24:52 -07001296 return ret;
1297}
1298
1299static void __exit applesmc_exit(void)
1300{
Tony Jones1beeffe2007-08-20 13:46:20 -07001301 hwmon_device_unregister(hwmon_dev);
Henrik Rydberg0b0b5df2010-11-09 15:15:09 +00001302 applesmc_release_key_backlight();
1303 applesmc_release_light_sensor();
1304 applesmc_release_accelerometer();
Henrik Rydberg9792dad2010-11-10 10:58:04 +00001305 applesmc_destroy_nodes(temp_group);
Henrik Rydberg3eba2bf2010-11-09 15:15:08 +00001306 applesmc_destroy_nodes(fan_group);
Henrik Rydberg0b0b5df2010-11-09 15:15:09 +00001307 applesmc_destroy_nodes(info_group);
Henrik Rydberg58745832010-11-10 10:58:03 +00001308 applesmc_destroy_smcreg();
Nicolas Boichat6f2fad72007-05-08 00:24:52 -07001309 platform_device_unregister(pdev);
1310 platform_driver_unregister(&applesmc_driver);
1311 release_region(APPLESMC_DATA_PORT, APPLESMC_NR_PORTS);
Nicolas Boichat6f2fad72007-05-08 00:24:52 -07001312}
1313
1314module_init(applesmc_init);
1315module_exit(applesmc_exit);
1316
1317MODULE_AUTHOR("Nicolas Boichat");
1318MODULE_DESCRIPTION("Apple SMC");
1319MODULE_LICENSE("GPL v2");
Henrik Rydbergdc924ef2008-12-01 13:13:49 -08001320MODULE_DEVICE_TABLE(dmi, applesmc_whitelist);