diff options
author | Daniel Mack <daniel@caiaq.de> | 2009-03-31 18:24:32 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-04-01 11:59:22 -0400 |
commit | a38da2ed74f628c1f3e907c772be21a66eccab9c (patch) | |
tree | e89697d25518dcca9861d6f65933fc3327cd5933 /drivers | |
parent | ab337a632783c251a3c3852aec0ead8a0281cbdd (diff) |
lis3: solve dependency between core and ACPI
This solves the dependency between lis3lv02d.[ch] and ACPI specific
methods. It introduces a ->bus_priv pointer to the device struct which is
casted to 'struct acpi_device' in the ACIP layer. Changed hp_accel.c
accordingly.
Signed-off-by: Daniel Mack <daniel@caiaq.de>
Acked-by: Pavel Machek <pavel@ucw.cz>
Acked-by: Eric Piel <eric.piel@tremplin-utc.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/hwmon/hp_accel.c | 99 | ||||
-rw-r--r-- | drivers/hwmon/lis3lv02d.c | 86 | ||||
-rw-r--r-- | drivers/hwmon/lis3lv02d.h | 20 |
3 files changed, 105 insertions, 100 deletions
diff --git a/drivers/hwmon/hp_accel.c b/drivers/hwmon/hp_accel.c index de26b1c3a96c..55d3dc565be6 100644 --- a/drivers/hwmon/hp_accel.c +++ b/drivers/hwmon/hp_accel.c | |||
@@ -85,25 +85,31 @@ MODULE_DEVICE_TABLE(acpi, lis3lv02d_device_ids); | |||
85 | 85 | ||
86 | /** | 86 | /** |
87 | * lis3lv02d_acpi_init - ACPI _INI method: initialize the device. | 87 | * lis3lv02d_acpi_init - ACPI _INI method: initialize the device. |
88 | * @handle: the handle of the device | 88 | * @lis3: pointer to the device struct |
89 | * | 89 | * |
90 | * Returns AE_OK on success. | 90 | * Returns 0 on success. |
91 | */ | 91 | */ |
92 | acpi_status lis3lv02d_acpi_init(acpi_handle handle) | 92 | int lis3lv02d_acpi_init(struct lis3lv02d *lis3) |
93 | { | 93 | { |
94 | return acpi_evaluate_object(handle, METHOD_NAME__INI, NULL, NULL); | 94 | struct acpi_device *dev = lis3->bus_priv; |
95 | if (acpi_evaluate_object(dev->handle, METHOD_NAME__INI, | ||
96 | NULL, NULL) != AE_OK) | ||
97 | return -EINVAL; | ||
98 | |||
99 | return 0; | ||
95 | } | 100 | } |
96 | 101 | ||
97 | /** | 102 | /** |
98 | * lis3lv02d_acpi_read - ACPI ALRD method: read a register | 103 | * lis3lv02d_acpi_read - ACPI ALRD method: read a register |
99 | * @handle: the handle of the device | 104 | * @lis3: pointer to the device struct |
100 | * @reg: the register to read | 105 | * @reg: the register to read |
101 | * @ret: result of the operation | 106 | * @ret: result of the operation |
102 | * | 107 | * |
103 | * Returns AE_OK on success. | 108 | * Returns 0 on success. |
104 | */ | 109 | */ |
105 | acpi_status lis3lv02d_acpi_read(acpi_handle handle, int reg, u8 *ret) | 110 | int lis3lv02d_acpi_read(struct lis3lv02d *lis3, int reg, u8 *ret) |
106 | { | 111 | { |
112 | struct acpi_device *dev = lis3->bus_priv; | ||
107 | union acpi_object arg0 = { ACPI_TYPE_INTEGER }; | 113 | union acpi_object arg0 = { ACPI_TYPE_INTEGER }; |
108 | struct acpi_object_list args = { 1, &arg0 }; | 114 | struct acpi_object_list args = { 1, &arg0 }; |
109 | unsigned long long lret; | 115 | unsigned long long lret; |
@@ -111,21 +117,22 @@ acpi_status lis3lv02d_acpi_read(acpi_handle handle, int reg, u8 *ret) | |||
111 | 117 | ||
112 | arg0.integer.value = reg; | 118 | arg0.integer.value = reg; |
113 | 119 | ||
114 | status = acpi_evaluate_integer(handle, "ALRD", &args, &lret); | 120 | status = acpi_evaluate_integer(dev->handle, "ALRD", &args, &lret); |
115 | *ret = lret; | 121 | *ret = lret; |
116 | return status; | 122 | return (status != AE_OK) ? -EINVAL : 0; |
117 | } | 123 | } |
118 | 124 | ||
119 | /** | 125 | /** |
120 | * lis3lv02d_acpi_write - ACPI ALWR method: write to a register | 126 | * lis3lv02d_acpi_write - ACPI ALWR method: write to a register |
121 | * @handle: the handle of the device | 127 | * @lis3: pointer to the device struct |
122 | * @reg: the register to write to | 128 | * @reg: the register to write to |
123 | * @val: the value to write | 129 | * @val: the value to write |
124 | * | 130 | * |
125 | * Returns AE_OK on success. | 131 | * Returns 0 on success. |
126 | */ | 132 | */ |
127 | acpi_status lis3lv02d_acpi_write(acpi_handle handle, int reg, u8 val) | 133 | int lis3lv02d_acpi_write(struct lis3lv02d *lis3, int reg, u8 val) |
128 | { | 134 | { |
135 | struct acpi_device *dev = lis3->bus_priv; | ||
129 | unsigned long long ret; /* Not used when writting */ | 136 | unsigned long long ret; /* Not used when writting */ |
130 | union acpi_object in_obj[2]; | 137 | union acpi_object in_obj[2]; |
131 | struct acpi_object_list args = { 2, in_obj }; | 138 | struct acpi_object_list args = { 2, in_obj }; |
@@ -135,7 +142,10 @@ acpi_status lis3lv02d_acpi_write(acpi_handle handle, int reg, u8 val) | |||
135 | in_obj[1].type = ACPI_TYPE_INTEGER; | 142 | in_obj[1].type = ACPI_TYPE_INTEGER; |
136 | in_obj[1].integer.value = val; | 143 | in_obj[1].integer.value = val; |
137 | 144 | ||
138 | return acpi_evaluate_integer(handle, "ALWR", &args, &ret); | 145 | if (acpi_evaluate_integer(dev->handle, "ALWR", &args, &ret) != AE_OK) |
146 | return -EINVAL; | ||
147 | |||
148 | return 0; | ||
139 | } | 149 | } |
140 | 150 | ||
141 | static int lis3lv02d_dmi_matched(const struct dmi_system_id *dmi) | 151 | static int lis3lv02d_dmi_matched(const struct dmi_system_id *dmi) |
@@ -217,7 +227,7 @@ static struct dmi_system_id lis3lv02d_dmi_ids[] = { | |||
217 | 227 | ||
218 | static void hpled_set(struct delayed_led_classdev *led_cdev, enum led_brightness value) | 228 | static void hpled_set(struct delayed_led_classdev *led_cdev, enum led_brightness value) |
219 | { | 229 | { |
220 | acpi_handle handle = lis3_dev.device->handle; | 230 | struct acpi_device *dev = lis3_dev.bus_priv; |
221 | unsigned long long ret; /* Not used when writing */ | 231 | unsigned long long ret; /* Not used when writing */ |
222 | union acpi_object in_obj[1]; | 232 | union acpi_object in_obj[1]; |
223 | struct acpi_object_list args = { 1, in_obj }; | 233 | struct acpi_object_list args = { 1, in_obj }; |
@@ -225,7 +235,7 @@ static void hpled_set(struct delayed_led_classdev *led_cdev, enum led_brightness | |||
225 | in_obj[0].type = ACPI_TYPE_INTEGER; | 235 | in_obj[0].type = ACPI_TYPE_INTEGER; |
226 | in_obj[0].integer.value = !!value; | 236 | in_obj[0].integer.value = !!value; |
227 | 237 | ||
228 | acpi_evaluate_integer(handle, "ALED", &args, &ret); | 238 | acpi_evaluate_integer(dev->handle, "ALED", &args, &ret); |
229 | } | 239 | } |
230 | 240 | ||
231 | static struct delayed_led_classdev hpled_led = { | 241 | static struct delayed_led_classdev hpled_led = { |
@@ -262,23 +272,6 @@ static void lis3lv02d_enum_resources(struct acpi_device *device) | |||
262 | printk(KERN_DEBUG DRIVER_NAME ": Error getting resources\n"); | 272 | printk(KERN_DEBUG DRIVER_NAME ": Error getting resources\n"); |
263 | } | 273 | } |
264 | 274 | ||
265 | static s16 lis3lv02d_read_16(acpi_handle handle, int reg) | ||
266 | { | ||
267 | u8 lo, hi; | ||
268 | |||
269 | lis3_dev.read(handle, reg - 1, &lo); | ||
270 | lis3_dev.read(handle, reg, &hi); | ||
271 | /* In "12 bit right justified" mode, bit 6, bit 7, bit 8 = bit 5 */ | ||
272 | return (s16)((hi << 8) | lo); | ||
273 | } | ||
274 | |||
275 | static s16 lis3lv02d_read_8(acpi_handle handle, int reg) | ||
276 | { | ||
277 | s8 lo; | ||
278 | lis3_dev.read(handle, reg, &lo); | ||
279 | return lo; | ||
280 | } | ||
281 | |||
282 | static int lis3lv02d_add(struct acpi_device *device) | 275 | static int lis3lv02d_add(struct acpi_device *device) |
283 | { | 276 | { |
284 | int ret; | 277 | int ret; |
@@ -286,7 +279,7 @@ static int lis3lv02d_add(struct acpi_device *device) | |||
286 | if (!device) | 279 | if (!device) |
287 | return -EINVAL; | 280 | return -EINVAL; |
288 | 281 | ||
289 | lis3_dev.device = device; | 282 | lis3_dev.bus_priv = device; |
290 | lis3_dev.init = lis3lv02d_acpi_init; | 283 | lis3_dev.init = lis3lv02d_acpi_init; |
291 | lis3_dev.read = lis3lv02d_acpi_read; | 284 | lis3_dev.read = lis3lv02d_acpi_read; |
292 | lis3_dev.write = lis3lv02d_acpi_write; | 285 | lis3_dev.write = lis3lv02d_acpi_write; |
@@ -294,23 +287,8 @@ static int lis3lv02d_add(struct acpi_device *device) | |||
294 | strcpy(acpi_device_class(device), ACPI_MDPS_CLASS); | 287 | strcpy(acpi_device_class(device), ACPI_MDPS_CLASS); |
295 | device->driver_data = &lis3_dev; | 288 | device->driver_data = &lis3_dev; |
296 | 289 | ||
297 | lis3lv02d_acpi_read(device->handle, WHO_AM_I, &lis3_dev.whoami); | 290 | /* obtain IRQ number of our device from ACPI */ |
298 | switch (lis3_dev.whoami) { | 291 | lis3lv02d_enum_resources(device); |
299 | case LIS_DOUBLE_ID: | ||
300 | printk(KERN_INFO DRIVER_NAME ": 2-byte sensor found\n"); | ||
301 | lis3_dev.read_data = lis3lv02d_read_16; | ||
302 | lis3_dev.mdps_max_val = 2048; | ||
303 | break; | ||
304 | case LIS_SINGLE_ID: | ||
305 | printk(KERN_INFO DRIVER_NAME ": 1-byte sensor found\n"); | ||
306 | lis3_dev.read_data = lis3lv02d_read_8; | ||
307 | lis3_dev.mdps_max_val = 128; | ||
308 | break; | ||
309 | default: | ||
310 | printk(KERN_ERR DRIVER_NAME | ||
311 | ": unknown sensor type 0x%X\n", lis3_dev.whoami); | ||
312 | return -EINVAL; | ||
313 | } | ||
314 | 292 | ||
315 | /* If possible use a "standard" axes order */ | 293 | /* If possible use a "standard" axes order */ |
316 | if (dmi_check_system(lis3lv02d_dmi_ids) == 0) { | 294 | if (dmi_check_system(lis3lv02d_dmi_ids) == 0) { |
@@ -319,18 +297,17 @@ static int lis3lv02d_add(struct acpi_device *device) | |||
319 | lis3_dev.ac = lis3lv02d_axis_normal; | 297 | lis3_dev.ac = lis3lv02d_axis_normal; |
320 | } | 298 | } |
321 | 299 | ||
322 | INIT_WORK(&hpled_led.work, delayed_set_status_worker); | 300 | /* call the core layer do its init */ |
323 | ret = led_classdev_register(NULL, &hpled_led.led_classdev); | 301 | ret = lis3lv02d_init_device(&lis3_dev); |
324 | if (ret) | 302 | if (ret) |
325 | return ret; | 303 | return ret; |
326 | 304 | ||
327 | /* obtain IRQ number of our device from ACPI */ | 305 | INIT_WORK(&hpled_led.work, delayed_set_status_worker); |
328 | lis3lv02d_enum_resources(lis3_dev.device); | 306 | ret = led_classdev_register(NULL, &hpled_led.led_classdev); |
329 | |||
330 | ret = lis3lv02d_init_device(&lis3_dev); | ||
331 | if (ret) { | 307 | if (ret) { |
308 | lis3lv02d_joystick_disable(); | ||
309 | lis3lv02d_poweroff(&lis3_dev); | ||
332 | flush_work(&hpled_led.work); | 310 | flush_work(&hpled_led.work); |
333 | led_classdev_unregister(&hpled_led.led_classdev); | ||
334 | return ret; | 311 | return ret; |
335 | } | 312 | } |
336 | 313 | ||
@@ -343,7 +320,7 @@ static int lis3lv02d_remove(struct acpi_device *device, int type) | |||
343 | return -EINVAL; | 320 | return -EINVAL; |
344 | 321 | ||
345 | lis3lv02d_joystick_disable(); | 322 | lis3lv02d_joystick_disable(); |
346 | lis3lv02d_poweroff(device->handle); | 323 | lis3lv02d_poweroff(&lis3_dev); |
347 | 324 | ||
348 | flush_work(&hpled_led.work); | 325 | flush_work(&hpled_led.work); |
349 | led_classdev_unregister(&hpled_led.led_classdev); | 326 | led_classdev_unregister(&hpled_led.led_classdev); |
@@ -356,7 +333,7 @@ static int lis3lv02d_remove(struct acpi_device *device, int type) | |||
356 | static int lis3lv02d_suspend(struct acpi_device *device, pm_message_t state) | 333 | static int lis3lv02d_suspend(struct acpi_device *device, pm_message_t state) |
357 | { | 334 | { |
358 | /* make sure the device is off when we suspend */ | 335 | /* make sure the device is off when we suspend */ |
359 | lis3lv02d_poweroff(device->handle); | 336 | lis3lv02d_poweroff(&lis3_dev); |
360 | return 0; | 337 | return 0; |
361 | } | 338 | } |
362 | 339 | ||
@@ -365,9 +342,9 @@ static int lis3lv02d_resume(struct acpi_device *device) | |||
365 | /* put back the device in the right state (ACPI might turn it on) */ | 342 | /* put back the device in the right state (ACPI might turn it on) */ |
366 | mutex_lock(&lis3_dev.lock); | 343 | mutex_lock(&lis3_dev.lock); |
367 | if (lis3_dev.usage > 0) | 344 | if (lis3_dev.usage > 0) |
368 | lis3lv02d_poweron(device->handle); | 345 | lis3lv02d_poweron(&lis3_dev); |
369 | else | 346 | else |
370 | lis3lv02d_poweroff(device->handle); | 347 | lis3lv02d_poweroff(&lis3_dev); |
371 | mutex_unlock(&lis3_dev.lock); | 348 | mutex_unlock(&lis3_dev.lock); |
372 | return 0; | 349 | return 0; |
373 | } | 350 | } |
diff --git a/drivers/hwmon/lis3lv02d.c b/drivers/hwmon/lis3lv02d.c index eeae7c9600e4..778eb7795983 100644 --- a/drivers/hwmon/lis3lv02d.c +++ b/drivers/hwmon/lis3lv02d.c | |||
@@ -36,7 +36,6 @@ | |||
36 | #include <linux/freezer.h> | 36 | #include <linux/freezer.h> |
37 | #include <linux/uaccess.h> | 37 | #include <linux/uaccess.h> |
38 | #include <linux/miscdevice.h> | 38 | #include <linux/miscdevice.h> |
39 | #include <acpi/acpi_drivers.h> | ||
40 | #include <asm/atomic.h> | 39 | #include <asm/atomic.h> |
41 | #include "lis3lv02d.h" | 40 | #include "lis3lv02d.h" |
42 | 41 | ||
@@ -53,18 +52,27 @@ | |||
53 | * joystick. | 52 | * joystick. |
54 | */ | 53 | */ |
55 | 54 | ||
56 | struct acpi_lis3lv02d lis3_dev = { | 55 | struct lis3lv02d lis3_dev = { |
57 | .misc_wait = __WAIT_QUEUE_HEAD_INITIALIZER(lis3_dev.misc_wait), | 56 | .misc_wait = __WAIT_QUEUE_HEAD_INITIALIZER(lis3_dev.misc_wait), |
58 | }; | 57 | }; |
59 | 58 | ||
60 | EXPORT_SYMBOL_GPL(lis3_dev); | 59 | EXPORT_SYMBOL_GPL(lis3_dev); |
61 | 60 | ||
62 | static s16 lis3lv02d_read_16(acpi_handle handle, int reg) | 61 | static s16 lis3lv02d_read_8(struct lis3lv02d *lis3, int reg) |
62 | { | ||
63 | s8 lo; | ||
64 | if (lis3->read(lis3, reg, &lo) < 0) | ||
65 | return 0; | ||
66 | |||
67 | return lo; | ||
68 | } | ||
69 | |||
70 | static s16 lis3lv02d_read_16(struct lis3lv02d *lis3, int reg) | ||
63 | { | 71 | { |
64 | u8 lo, hi; | 72 | u8 lo, hi; |
65 | 73 | ||
66 | lis3_dev.read(handle, reg, &lo); | 74 | lis3->read(lis3, reg - 1, &lo); |
67 | lis3_dev.read(handle, reg + 1, &hi); | 75 | lis3->read(lis3, reg, &hi); |
68 | /* In "12 bit right justified" mode, bit 6, bit 7, bit 8 = bit 5 */ | 76 | /* In "12 bit right justified" mode, bit 6, bit 7, bit 8 = bit 5 */ |
69 | return (s16)((hi << 8) | lo); | 77 | return (s16)((hi << 8) | lo); |
70 | } | 78 | } |
@@ -86,36 +94,36 @@ static inline int lis3lv02d_get_axis(s8 axis, int hw_values[3]) | |||
86 | 94 | ||
87 | /** | 95 | /** |
88 | * lis3lv02d_get_xyz - Get X, Y and Z axis values from the accelerometer | 96 | * lis3lv02d_get_xyz - Get X, Y and Z axis values from the accelerometer |
89 | * @handle: the handle to the device | 97 | * @lis3: pointer to the device struct |
90 | * @x: where to store the X axis value | 98 | * @x: where to store the X axis value |
91 | * @y: where to store the Y axis value | 99 | * @y: where to store the Y axis value |
92 | * @z: where to store the Z axis value | 100 | * @z: where to store the Z axis value |
93 | * | 101 | * |
94 | * Note that 40Hz input device can eat up about 10% CPU at 800MHZ | 102 | * Note that 40Hz input device can eat up about 10% CPU at 800MHZ |
95 | */ | 103 | */ |
96 | static void lis3lv02d_get_xyz(acpi_handle handle, int *x, int *y, int *z) | 104 | static void lis3lv02d_get_xyz(struct lis3lv02d *lis3, int *x, int *y, int *z) |
97 | { | 105 | { |
98 | int position[3]; | 106 | int position[3]; |
99 | 107 | ||
100 | position[0] = lis3_dev.read_data(handle, OUTX); | 108 | position[0] = lis3_dev.read_data(lis3, OUTX); |
101 | position[1] = lis3_dev.read_data(handle, OUTY); | 109 | position[1] = lis3_dev.read_data(lis3, OUTY); |
102 | position[2] = lis3_dev.read_data(handle, OUTZ); | 110 | position[2] = lis3_dev.read_data(lis3, OUTZ); |
103 | 111 | ||
104 | *x = lis3lv02d_get_axis(lis3_dev.ac.x, position); | 112 | *x = lis3lv02d_get_axis(lis3_dev.ac.x, position); |
105 | *y = lis3lv02d_get_axis(lis3_dev.ac.y, position); | 113 | *y = lis3lv02d_get_axis(lis3_dev.ac.y, position); |
106 | *z = lis3lv02d_get_axis(lis3_dev.ac.z, position); | 114 | *z = lis3lv02d_get_axis(lis3_dev.ac.z, position); |
107 | } | 115 | } |
108 | 116 | ||
109 | void lis3lv02d_poweroff(acpi_handle handle) | 117 | void lis3lv02d_poweroff(struct lis3lv02d *lis3) |
110 | { | 118 | { |
111 | lis3_dev.is_on = 0; | 119 | lis3_dev.is_on = 0; |
112 | } | 120 | } |
113 | EXPORT_SYMBOL_GPL(lis3lv02d_poweroff); | 121 | EXPORT_SYMBOL_GPL(lis3lv02d_poweroff); |
114 | 122 | ||
115 | void lis3lv02d_poweron(acpi_handle handle) | 123 | void lis3lv02d_poweron(struct lis3lv02d *lis3) |
116 | { | 124 | { |
117 | lis3_dev.is_on = 1; | 125 | lis3_dev.is_on = 1; |
118 | lis3_dev.init(handle); | 126 | lis3_dev.init(lis3); |
119 | } | 127 | } |
120 | EXPORT_SYMBOL_GPL(lis3lv02d_poweron); | 128 | EXPORT_SYMBOL_GPL(lis3lv02d_poweron); |
121 | 129 | ||
@@ -124,13 +132,13 @@ EXPORT_SYMBOL_GPL(lis3lv02d_poweron); | |||
124 | * device will always be on until a call to lis3lv02d_decrease_use(). Not to be | 132 | * device will always be on until a call to lis3lv02d_decrease_use(). Not to be |
125 | * used from interrupt context. | 133 | * used from interrupt context. |
126 | */ | 134 | */ |
127 | static void lis3lv02d_increase_use(struct acpi_lis3lv02d *dev) | 135 | static void lis3lv02d_increase_use(struct lis3lv02d *dev) |
128 | { | 136 | { |
129 | mutex_lock(&dev->lock); | 137 | mutex_lock(&dev->lock); |
130 | dev->usage++; | 138 | dev->usage++; |
131 | if (dev->usage == 1) { | 139 | if (dev->usage == 1) { |
132 | if (!dev->is_on) | 140 | if (!dev->is_on) |
133 | lis3lv02d_poweron(dev->device->handle); | 141 | lis3lv02d_poweron(dev); |
134 | } | 142 | } |
135 | mutex_unlock(&dev->lock); | 143 | mutex_unlock(&dev->lock); |
136 | } | 144 | } |
@@ -139,12 +147,12 @@ static void lis3lv02d_increase_use(struct acpi_lis3lv02d *dev) | |||
139 | * To be called whenever a usage of the device is stopped. | 147 | * To be called whenever a usage of the device is stopped. |
140 | * It will make sure to turn off the device when there is not usage. | 148 | * It will make sure to turn off the device when there is not usage. |
141 | */ | 149 | */ |
142 | static void lis3lv02d_decrease_use(struct acpi_lis3lv02d *dev) | 150 | static void lis3lv02d_decrease_use(struct lis3lv02d *dev) |
143 | { | 151 | { |
144 | mutex_lock(&dev->lock); | 152 | mutex_lock(&dev->lock); |
145 | dev->usage--; | 153 | dev->usage--; |
146 | if (dev->usage == 0) | 154 | if (dev->usage == 0) |
147 | lis3lv02d_poweroff(dev->device->handle); | 155 | lis3lv02d_poweroff(dev); |
148 | mutex_unlock(&dev->lock); | 156 | mutex_unlock(&dev->lock); |
149 | } | 157 | } |
150 | 158 | ||
@@ -291,7 +299,7 @@ static int lis3lv02d_joystick_kthread(void *data) | |||
291 | int x, y, z; | 299 | int x, y, z; |
292 | 300 | ||
293 | while (!kthread_should_stop()) { | 301 | while (!kthread_should_stop()) { |
294 | lis3lv02d_get_xyz(lis3_dev.device->handle, &x, &y, &z); | 302 | lis3lv02d_get_xyz(&lis3_dev, &x, &y, &z); |
295 | input_report_abs(lis3_dev.idev, ABS_X, x - lis3_dev.xcalib); | 303 | input_report_abs(lis3_dev.idev, ABS_X, x - lis3_dev.xcalib); |
296 | input_report_abs(lis3_dev.idev, ABS_Y, y - lis3_dev.ycalib); | 304 | input_report_abs(lis3_dev.idev, ABS_Y, y - lis3_dev.ycalib); |
297 | input_report_abs(lis3_dev.idev, ABS_Z, z - lis3_dev.zcalib); | 305 | input_report_abs(lis3_dev.idev, ABS_Z, z - lis3_dev.zcalib); |
@@ -325,7 +333,8 @@ static void lis3lv02d_joystick_close(struct input_dev *input) | |||
325 | 333 | ||
326 | static inline void lis3lv02d_calibrate_joystick(void) | 334 | static inline void lis3lv02d_calibrate_joystick(void) |
327 | { | 335 | { |
328 | lis3lv02d_get_xyz(lis3_dev.device->handle, &lis3_dev.xcalib, &lis3_dev.ycalib, &lis3_dev.zcalib); | 336 | lis3lv02d_get_xyz(&lis3_dev, |
337 | &lis3_dev.xcalib, &lis3_dev.ycalib, &lis3_dev.zcalib); | ||
329 | } | 338 | } |
330 | 339 | ||
331 | int lis3lv02d_joystick_enable(void) | 340 | int lis3lv02d_joystick_enable(void) |
@@ -382,7 +391,7 @@ static ssize_t lis3lv02d_position_show(struct device *dev, | |||
382 | int x, y, z; | 391 | int x, y, z; |
383 | 392 | ||
384 | lis3lv02d_increase_use(&lis3_dev); | 393 | lis3lv02d_increase_use(&lis3_dev); |
385 | lis3lv02d_get_xyz(lis3_dev.device->handle, &x, &y, &z); | 394 | lis3lv02d_get_xyz(&lis3_dev, &x, &y, &z); |
386 | lis3lv02d_decrease_use(&lis3_dev); | 395 | lis3lv02d_decrease_use(&lis3_dev); |
387 | return sprintf(buf, "(%d,%d,%d)\n", x, y, z); | 396 | return sprintf(buf, "(%d,%d,%d)\n", x, y, z); |
388 | } | 397 | } |
@@ -412,7 +421,7 @@ static ssize_t lis3lv02d_rate_show(struct device *dev, | |||
412 | int val; | 421 | int val; |
413 | 422 | ||
414 | lis3lv02d_increase_use(&lis3_dev); | 423 | lis3lv02d_increase_use(&lis3_dev); |
415 | lis3_dev.read(lis3_dev.device->handle, CTRL_REG1, &ctrl); | 424 | lis3_dev.read(&lis3_dev, CTRL_REG1, &ctrl); |
416 | lis3lv02d_decrease_use(&lis3_dev); | 425 | lis3lv02d_decrease_use(&lis3_dev); |
417 | val = (ctrl & (CTRL1_DF0 | CTRL1_DF1)) >> 4; | 426 | val = (ctrl & (CTRL1_DF0 | CTRL1_DF1)) >> 4; |
418 | return sprintf(buf, "%d\n", lis3lv02dl_df_val[val]); | 427 | return sprintf(buf, "%d\n", lis3lv02dl_df_val[val]); |
@@ -435,7 +444,7 @@ static struct attribute_group lis3lv02d_attribute_group = { | |||
435 | }; | 444 | }; |
436 | 445 | ||
437 | 446 | ||
438 | static int lis3lv02d_add_fs(struct acpi_device *device) | 447 | static int lis3lv02d_add_fs(struct lis3lv02d *lis3) |
439 | { | 448 | { |
440 | lis3_dev.pdev = platform_device_register_simple(DRIVER_NAME, -1, NULL, 0); | 449 | lis3_dev.pdev = platform_device_register_simple(DRIVER_NAME, -1, NULL, 0); |
441 | if (IS_ERR(lis3_dev.pdev)) | 450 | if (IS_ERR(lis3_dev.pdev)) |
@@ -456,10 +465,29 @@ EXPORT_SYMBOL_GPL(lis3lv02d_remove_fs); | |||
456 | * Initialise the accelerometer and the various subsystems. | 465 | * Initialise the accelerometer and the various subsystems. |
457 | * Should be rather independant of the bus system. | 466 | * Should be rather independant of the bus system. |
458 | */ | 467 | */ |
459 | int lis3lv02d_init_device(struct acpi_lis3lv02d *dev) | 468 | int lis3lv02d_init_device(struct lis3lv02d *dev) |
460 | { | 469 | { |
470 | dev->whoami = lis3lv02d_read_8(dev, WHO_AM_I); | ||
471 | |||
472 | switch (dev->whoami) { | ||
473 | case LIS_DOUBLE_ID: | ||
474 | printk(KERN_INFO DRIVER_NAME ": 2-byte sensor found\n"); | ||
475 | dev->read_data = lis3lv02d_read_16; | ||
476 | dev->mdps_max_val = 2048; | ||
477 | break; | ||
478 | case LIS_SINGLE_ID: | ||
479 | printk(KERN_INFO DRIVER_NAME ": 1-byte sensor found\n"); | ||
480 | dev->read_data = lis3lv02d_read_8; | ||
481 | dev->mdps_max_val = 128; | ||
482 | break; | ||
483 | default: | ||
484 | printk(KERN_ERR DRIVER_NAME | ||
485 | ": unknown sensor type 0x%X\n", lis3_dev.whoami); | ||
486 | return -EINVAL; | ||
487 | } | ||
488 | |||
461 | mutex_init(&dev->lock); | 489 | mutex_init(&dev->lock); |
462 | lis3lv02d_add_fs(dev->device); | 490 | lis3lv02d_add_fs(dev); |
463 | lis3lv02d_increase_use(dev); | 491 | lis3lv02d_increase_use(dev); |
464 | 492 | ||
465 | if (lis3lv02d_joystick_enable()) | 493 | if (lis3lv02d_joystick_enable()) |
@@ -467,10 +495,10 @@ int lis3lv02d_init_device(struct acpi_lis3lv02d *dev) | |||
467 | 495 | ||
468 | printk("lis3_init_device: irq %d\n", dev->irq); | 496 | printk("lis3_init_device: irq %d\n", dev->irq); |
469 | 497 | ||
470 | /* if we did not get an IRQ from ACPI - we have nothing more to do */ | 498 | /* bail if we did not get an IRQ from the bus layer */ |
471 | if (!dev->irq) { | 499 | if (!dev->irq) { |
472 | printk(KERN_ERR DRIVER_NAME | 500 | printk(KERN_ERR DRIVER_NAME |
473 | ": No IRQ in ACPI. Disabling /dev/freefall\n"); | 501 | ": No IRQ. Disabling /dev/freefall\n"); |
474 | goto out; | 502 | goto out; |
475 | } | 503 | } |
476 | 504 | ||
diff --git a/drivers/hwmon/lis3lv02d.h b/drivers/hwmon/lis3lv02d.h index 017fb2b754d5..745ec96806d4 100644 --- a/drivers/hwmon/lis3lv02d.h +++ b/drivers/hwmon/lis3lv02d.h | |||
@@ -159,14 +159,14 @@ struct axis_conversion { | |||
159 | s8 z; | 159 | s8 z; |
160 | }; | 160 | }; |
161 | 161 | ||
162 | struct acpi_lis3lv02d { | 162 | struct lis3lv02d { |
163 | struct acpi_device *device; /* The ACPI device */ | 163 | void *bus_priv; /* used by the bus layer only */ |
164 | acpi_status (*init) (acpi_handle handle); | 164 | int (*init) (struct lis3lv02d *lis3); |
165 | acpi_status (*write) (acpi_handle handle, int reg, u8 val); | 165 | int (*write) (struct lis3lv02d *lis3, int reg, u8 val); |
166 | acpi_status (*read) (acpi_handle handle, int reg, u8 *ret); | 166 | int (*read) (struct lis3lv02d *lis3, int reg, u8 *ret); |
167 | 167 | ||
168 | u8 whoami; /* 3Ah: 2-byte registries, 3Bh: 1-byte registries */ | 168 | u8 whoami; /* 3Ah: 2-byte registries, 3Bh: 1-byte registries */ |
169 | s16 (*read_data) (acpi_handle handle, int reg); | 169 | s16 (*read_data) (struct lis3lv02d *lis3, int reg); |
170 | int mdps_max_val; | 170 | int mdps_max_val; |
171 | 171 | ||
172 | struct input_dev *idev; /* input device */ | 172 | struct input_dev *idev; /* input device */ |
@@ -187,11 +187,11 @@ struct acpi_lis3lv02d { | |||
187 | unsigned long misc_opened; /* bit0: whether the device is open */ | 187 | unsigned long misc_opened; /* bit0: whether the device is open */ |
188 | }; | 188 | }; |
189 | 189 | ||
190 | int lis3lv02d_init_device(struct acpi_lis3lv02d *dev); | 190 | int lis3lv02d_init_device(struct lis3lv02d *lis3); |
191 | int lis3lv02d_joystick_enable(void); | 191 | int lis3lv02d_joystick_enable(void); |
192 | void lis3lv02d_joystick_disable(void); | 192 | void lis3lv02d_joystick_disable(void); |
193 | void lis3lv02d_poweroff(acpi_handle handle); | 193 | void lis3lv02d_poweroff(struct lis3lv02d *lis3); |
194 | void lis3lv02d_poweron(acpi_handle handle); | 194 | void lis3lv02d_poweron(struct lis3lv02d *lis3); |
195 | int lis3lv02d_remove_fs(void); | 195 | int lis3lv02d_remove_fs(void); |
196 | 196 | ||
197 | extern struct acpi_lis3lv02d lis3_dev; | 197 | extern struct lis3lv02d lis3_dev; |