1 From 1c6f5a92c816db43128444606c26507ebe6e5a43 Mon Sep 17 00:00:00 2001
2 From: Andy Green <andy@openmoko.com>
3 Date: Mon, 13 Oct 2008 12:01:05 +0100
4 Subject: [PATCH] fix-lid302dl-bitbang-all-the-way-baby.patch
6 This large patch removes motion sensor from Linux SPI bitbang driver.
7 Previously, some access was done through Linux SPI protected
8 by a mutex, and the ISR access was done by platform bitbang code due
9 to inability of Linux SPI driver to work in the interrupt context.
11 Now all access is done by bitbang callbacks in mach_gta02.c and are
12 protected by single scheme of interrupt lockout for the duration --
13 I line-by-line'd the driver to confirm that best I could, adding
14 protection and taking more care on several /sys related paths.
16 Because this is no longer a Linux SPI bus driver, the path for various
17 /sys things have changed. They can now be found down, eg,
19 /sys/devices/platform/lis302dl.1/sample_rate
21 lis302dl.1 is the top sensor and .2 the bottom. The names of the input
22 susbsytem paths remain the same as before.
24 Signed-off-by: Andy Green <andy@openmoko.com>
26 arch/arm/mach-s3c2440/mach-gta02.c | 233 +++++++++----------
27 drivers/input/misc/lis302dl.c | 437 ++++++++++++++++--------------------
28 include/linux/lis302dl.h | 9 +-
29 3 files changed, 315 insertions(+), 364 deletions(-)
31 diff --git a/arch/arm/mach-s3c2440/mach-gta02.c b/arch/arm/mach-s3c2440/mach-gta02.c
32 index 467c417..b19632c 100644
33 --- a/arch/arm/mach-s3c2440/mach-gta02.c
34 +++ b/arch/arm/mach-s3c2440/mach-gta02.c
35 @@ -1052,20 +1052,21 @@ static struct platform_device gta02_vibrator_dev = {
36 /* #define DEBUG_SPEW_MS */
37 #define MG_PER_SAMPLE 18
39 -struct lis302dl_platform_data lis302_pdata[];
40 +struct lis302dl_platform_data lis302_pdata_top;
41 +struct lis302dl_platform_data lis302_pdata_bottom;
43 -void gta02_lis302dl_bitbang_read(struct lis302dl_info *lis)
45 + * generic SPI RX and TX bitbang
46 + * only call with interrupts off!
49 +static void __gta02_lis302dl_bitbang(struct lis302dl_info *lis, u8 *tx,
50 + int tx_bytes, u8 *rx, int rx_bytes)
52 struct lis302dl_platform_data *pdata = lis->pdata;
53 - u8 shifter = 0xc0 | LIS302DL_REG_OUT_X; /* read, autoincrement */
57 unsigned long other_cs;
58 - unsigned long flags;
63 - local_irq_save(flags);
66 * Huh.. "quirk"... CS on this device is not really "CS" like you can
67 @@ -1073,20 +1074,25 @@ void gta02_lis302dl_bitbang_read(struct lis302dl_info *lis)
68 * have 2 devices on one interface, the "disabled" device when we talk
69 * to an "enabled" device sees the clocks as I2C clocks, creating
72 * I2C sees MOSI going LOW while CLK HIGH as a START action, we must
73 * ensure this is never issued.
76 - if (&lis302_pdata[0] == pdata)
77 - other_cs = lis302_pdata[1].pin_chip_select;
78 + if (&lis302_pdata_top == pdata)
79 + other_cs = lis302_pdata_bottom.pin_chip_select;
81 - other_cs = lis302_pdata[0].pin_chip_select;
82 + other_cs = lis302_pdata_top.pin_chip_select;
84 s3c2410_gpio_setpin(other_cs, 1);
85 s3c2410_gpio_setpin(pdata->pin_chip_select, 1);
86 s3c2410_gpio_setpin(pdata->pin_clk, 1);
87 s3c2410_gpio_setpin(pdata->pin_chip_select, 0);
88 - for (n = 0; n < 8; n++) { /* write the r/w, inc and address */
90 + /* send the register index, r/w and autoinc bits */
91 + for (n = 0; n < (tx_bytes << 3); n++) {
93 + shifter = tx[n >> 3];
94 s3c2410_gpio_setpin(pdata->pin_clk, 0);
95 s3c2410_gpio_setpin(pdata->pin_mosi, (shifter >> 7) & 1);
96 s3c2410_gpio_setpin(pdata->pin_clk, 0);
97 @@ -1095,44 +1101,71 @@ void gta02_lis302dl_bitbang_read(struct lis302dl_info *lis)
101 - for (n = 0; n < 5; n++) { /* 5 consequetive registers */
102 - for (n1 = 0; n1 < 8; n1++) { /* 8 bits each */
103 - s3c2410_gpio_setpin(pdata->pin_clk, 0);
104 - s3c2410_gpio_setpin(pdata->pin_clk, 0);
106 - if (s3c2410_gpio_getpin(pdata->pin_miso))
108 - s3c2410_gpio_setpin(pdata->pin_clk, 1);
109 - s3c2410_gpio_setpin(pdata->pin_clk, 1);
113 -#ifdef DEBUG_SPEW_MS
116 - input_report_rel(lis->input_dev, REL_X, MG_PER_SAMPLE * (s8)shifter);
119 -#ifdef DEBUG_SPEW_MS
122 - input_report_rel(lis->input_dev, REL_Y, MG_PER_SAMPLE * (s8)shifter);
125 -#ifdef DEBUG_SPEW_MS
128 - input_report_rel(lis->input_dev, REL_Z, MG_PER_SAMPLE * (s8)shifter);
131 + for (n = 0; n < (rx_bytes << 3); n++) { /* 8 bits each */
132 + s3c2410_gpio_setpin(pdata->pin_clk, 0);
133 + s3c2410_gpio_setpin(pdata->pin_clk, 0);
135 + if (s3c2410_gpio_getpin(pdata->pin_miso))
138 + rx[n >> 3] = shifter;
139 + s3c2410_gpio_setpin(pdata->pin_clk, 1);
140 + s3c2410_gpio_setpin(pdata->pin_clk, 1);
142 s3c2410_gpio_setpin(pdata->pin_chip_select, 1);
143 s3c2410_gpio_setpin(other_cs, 1);
147 +static int gta02_lis302dl_bitbang_read_reg(struct lis302dl_info *lis, u8 reg)
149 + u8 data = 0xc0 | reg; /* read, autoincrement */
150 + unsigned long flags;
152 + local_irq_save(flags);
154 + __gta02_lis302dl_bitbang(lis, &data, 1, &data, 1);
156 + local_irq_restore(flags);
161 +static void gta02_lis302dl_bitbang_write_reg(struct lis302dl_info *lis, u8 reg,
164 + u8 data[2] = { 0x00 | reg, val }; /* write, no autoincrement */
165 + unsigned long flags;
167 + local_irq_save(flags);
169 + __gta02_lis302dl_bitbang(lis, &data[0], 2, NULL, 0);
171 local_irq_restore(flags);
176 +static void gta02_lis302dl_bitbang_sample(struct lis302dl_info *lis)
178 + u8 data = 0xc0 | LIS302DL_REG_OUT_X; /* read, autoincrement */
180 + unsigned long flags;
182 + local_irq_save(flags);
184 + __gta02_lis302dl_bitbang(lis, &data, 1, &read[0], 5);
186 + local_irq_restore(flags);
188 + input_report_rel(lis->input_dev, REL_X, MG_PER_SAMPLE * (s8)read[0]);
189 + input_report_rel(lis->input_dev, REL_Y, MG_PER_SAMPLE * (s8)read[2]);
190 + input_report_rel(lis->input_dev, REL_Z, MG_PER_SAMPLE * (s8)read[4]);
192 input_sync(lis->input_dev);
194 - printk("%s: %d %d %d\n", pdata->name, x, y, z);
195 + printk(KERN_INFO "%s: %d %d %d\n", pdata->name, read[0], read[2],
200 @@ -1159,103 +1192,58 @@ void gta02_lis302dl_suspend_io(struct lis302dl_info *lis, int resume)
201 s3c2410_gpio_setpin(pdata->pin_clk, 1);
202 /* misnomer: it is a pullDOWN in 2442 */
203 s3c2410_gpio_pullup(pdata->pin_miso, 0);
205 + s3c2410_gpio_cfgpin(pdata->pin_chip_select, S3C2410_GPIO_OUTPUT);
206 + s3c2410_gpio_cfgpin(pdata->pin_clk, S3C2410_GPIO_OUTPUT);
207 + s3c2410_gpio_cfgpin(pdata->pin_mosi, S3C2410_GPIO_OUTPUT);
208 + s3c2410_gpio_cfgpin(pdata->pin_miso, S3C2410_GPIO_INPUT);
212 -struct lis302dl_platform_data lis302_pdata[] = {
216 +struct lis302dl_platform_data lis302_pdata_top = {
217 .name = "lis302-1 (top)",
218 .pin_chip_select= S3C2410_GPD12,
219 .pin_clk = S3C2410_GPG7,
220 .pin_mosi = S3C2410_GPG6,
221 .pin_miso = S3C2410_GPG5,
222 + .interrupt = GTA02_IRQ_GSENSOR_1,
223 .open_drain = 1, /* altered at runtime by PCB rev */
224 - .lis302dl_bitbang_read = gta02_lis302dl_bitbang_read,
225 + .lis302dl_bitbang_read_sample = gta02_lis302dl_bitbang_sample,
226 + .lis302dl_bitbang_reg_read = gta02_lis302dl_bitbang_read_reg,
227 + .lis302dl_bitbang_reg_write = gta02_lis302dl_bitbang_write_reg,
228 .lis302dl_suspend_io = gta02_lis302dl_suspend_io,
232 +struct lis302dl_platform_data lis302_pdata_bottom = {
233 .name = "lis302-2 (bottom)",
234 .pin_chip_select= S3C2410_GPD13,
235 .pin_clk = S3C2410_GPG7,
236 .pin_mosi = S3C2410_GPG6,
237 .pin_miso = S3C2410_GPG5,
238 + .interrupt = GTA02_IRQ_GSENSOR_2,
239 .open_drain = 1, /* altered at runtime by PCB rev */
240 - .lis302dl_bitbang_read = gta02_lis302dl_bitbang_read,
241 + .lis302dl_bitbang_read_sample = gta02_lis302dl_bitbang_sample,
242 + .lis302dl_bitbang_reg_read = gta02_lis302dl_bitbang_read_reg,
243 + .lis302dl_bitbang_reg_write = gta02_lis302dl_bitbang_write_reg,
244 .lis302dl_suspend_io = gta02_lis302dl_suspend_io,
248 -static struct spi_board_info gta02_spi_acc_bdinfo[] = {
250 - .modalias = "lis302dl",
251 - .platform_data = &lis302_pdata[0],
252 - .irq = GTA02_IRQ_GSENSOR_1,
253 - .max_speed_hz = 10 * 1000 * 1000,
256 - .mode = SPI_MODE_3,
259 - .modalias = "lis302dl",
260 - .platform_data = &lis302_pdata[1],
261 - .irq = GTA02_IRQ_GSENSOR_2,
262 - .max_speed_hz = 10 * 1000 * 1000,
265 - .mode = SPI_MODE_3,
269 -static void spi_acc_cs(struct s3c2410_spigpio_info *spigpio_info,
272 - struct lis302dl_platform_data * plat_data =
273 - (struct lis302dl_platform_data *)spigpio_info->
274 - board_info->platform_data;
276 - case BITBANG_CS_ACTIVE:
277 - s3c2410_gpio_setpin(plat_data[csid].pin_chip_select, 0);
279 - case BITBANG_CS_INACTIVE:
280 - s3c2410_gpio_setpin(plat_data[csid].pin_chip_select, 1);
285 -static struct s3c2410_spigpio_info spi_gpio_cfg = {
286 - .pin_clk = S3C2410_GPG7,
287 - .pin_mosi = S3C2410_GPG6,
288 - .pin_miso = S3C2410_GPG5,
289 - .board_size = ARRAY_SIZE(gta02_spi_acc_bdinfo),
290 - .board_info = gta02_spi_acc_bdinfo,
291 - .chip_select = &spi_acc_cs,
292 - .num_chipselect = 2,
295 -static struct resource s3c_spi_acc_resource[] = {
297 - .start = S3C2410_GPG3,
298 - .end = S3C2410_GPG3,
301 - .start = S3C2410_GPG5,
302 - .end = S3C2410_GPG5,
305 - .start = S3C2410_GPG6,
306 - .end = S3C2410_GPG6,
309 - .start = S3C2410_GPG7,
310 - .end = S3C2410_GPG7,
311 +static struct platform_device s3c_device_spi_acc1 = {
312 + .name = "lis302dl",
315 + .platform_data = &lis302_pdata_top,
319 -static struct platform_device s3c_device_spi_acc = {
320 - .name = "spi_s3c24xx_gpio",
322 - .num_resources = ARRAY_SIZE(s3c_spi_acc_resource),
323 - .resource = s3c_spi_acc_resource,
324 +static struct platform_device s3c_device_spi_acc2 = {
325 + .name = "lis302dl",
328 - .platform_data = &spi_gpio_cfg,
329 + .platform_data = &lis302_pdata_bottom,
333 @@ -1573,8 +1561,8 @@ static void __init gta02_machine_init(void)
334 switch (system_rev) {
335 case GTA02v6_SYSTEM_REV:
336 /* we need push-pull interrupt from motion sensors */
337 - lis302_pdata[0].open_drain = 0;
338 - lis302_pdata[1].open_drain = 0;
339 + lis302_pdata_top.open_drain = 0;
340 + lis302_pdata_bottom.open_drain = 0;
344 @@ -1635,7 +1623,8 @@ static void __init gta02_machine_init(void)
345 mangle_glamo_res_by_system_rev();
346 platform_device_register(>a02_glamo_dev);
348 - platform_device_register(&s3c_device_spi_acc);
349 + platform_device_register(&s3c_device_spi_acc1);
350 + platform_device_register(&s3c_device_spi_acc2);
351 platform_device_register(>a02_button_dev);
352 platform_device_register(>a02_pm_gsm_dev);
353 platform_device_register(>a02_pm_usbhost_dev);
354 diff --git a/drivers/input/misc/lis302dl.c b/drivers/input/misc/lis302dl.c
355 index b01ca04..1d5781d 100644
356 --- a/drivers/input/misc/lis302dl.c
357 +++ b/drivers/input/misc/lis302dl.c
359 /* Linux kernel driver for the ST LIS302D 3-axis accelerometer
361 - * Copyright (C) 2007 by Openmoko, Inc.
362 + * Copyright (C) 2007-2008 by Openmoko, Inc.
363 * Author: Harald Welte <laforge@openmoko.org>
364 + * converted to private bitbang by:
365 + * Andy Green <andy@openmoko.com>
366 * All rights reserved.
368 * This program is free software; you can redistribute it and/or
371 #include <linux/lis302dl.h>
373 -/* lowlevel register access functions */
375 -#define READ_BIT 0x80
376 -#define READ_BIT_INC_ADS 0xc0
377 -#define ADDR_MASK 0x3f
379 -static u_int8_t __reg_read(struct lis302dl_info *lis, u_int8_t reg)
380 +static void __reg_set_bit_mask(struct lis302dl_info *lis, u8 reg, u8 mask,
386 - BUG_ON(reg & ~ADDR_MASK);
388 - cmd = reg | READ_BIT;
390 - rc = spi_w8r8(lis->spi_dev, cmd);
395 -static u_int8_t reg_read(struct lis302dl_info *lis, u_int8_t reg)
399 - mutex_lock(&lis->lock);
400 - ret = __reg_read(lis, reg);
401 - mutex_unlock(&lis->lock);
406 -static int __reg_write(struct lis302dl_info *lis, u_int8_t reg, u_int8_t val)
410 - BUG_ON(reg & ~ADDR_MASK);
415 - return spi_write(lis->spi_dev, buf, sizeof(buf));
418 -static int reg_write(struct lis302dl_info *lis, u_int8_t reg, u_int8_t val)
422 - mutex_lock(&lis->lock);
423 - ret = __reg_write(lis, reg, val);
424 - mutex_unlock(&lis->lock);
429 -static int reg_set_bit_mask(struct lis302dl_info *lis,
430 - u_int8_t reg, u_int8_t mask, u_int8_t val)
437 - mutex_lock(&lis->lock);
439 - tmp = __reg_read(lis, reg);
440 + tmp = (lis->pdata->lis302dl_bitbang_reg_read)(lis, reg);
443 - ret = __reg_write(lis, reg, tmp);
445 - mutex_unlock(&lis->lock);
448 + (lis->pdata->lis302dl_bitbang_reg_write)(lis, reg, tmp);
451 /* interrupt handling related */
452 @@ -124,17 +67,17 @@ enum lis302dl_intmode {
453 LIS302DL_INTMODE_CLICK = 0x07,
456 -static void lis302dl_int_mode(struct spi_device *spi, int int_pin,
457 +static void __lis302dl_int_mode(struct device *dev, int int_pin,
458 enum lis302dl_intmode mode)
460 - struct lis302dl_info *lis = dev_get_drvdata(&spi->dev);
461 + struct lis302dl_info *lis = dev_get_drvdata(dev);
465 - reg_set_bit_mask(lis, LIS302DL_REG_CTRL3, 0x07, mode);
466 + __reg_set_bit_mask(lis, LIS302DL_REG_CTRL3, 0x07, mode);
469 - reg_set_bit_mask(lis, LIS302DL_REG_CTRL3, 0x38, mode << 3);
470 + __reg_set_bit_mask(lis, LIS302DL_REG_CTRL3, 0x38, mode << 3);
474 @@ -165,7 +108,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *_lis)
476 struct lis302dl_info *lis = _lis;
478 - (lis->pdata->lis302dl_bitbang_read)(lis);
479 + (lis->pdata->lis302dl_bitbang_read_sample)(lis);
483 @@ -175,7 +118,13 @@ static ssize_t show_rate(struct device *dev, struct device_attribute *attr,
486 struct lis302dl_info *lis = dev_get_drvdata(dev);
487 - u_int8_t ctrl1 = reg_read(lis, LIS302DL_REG_CTRL1);
489 + unsigned long flags;
491 + local_irq_save(flags);
492 + ctrl1 = (lis->pdata->lis302dl_bitbang_reg_read)
493 + (lis, LIS302DL_REG_CTRL1);
494 + local_irq_restore(flags);
496 return sprintf(buf, "%d\n", ctrl1 & LIS302DL_CTRL1_DR ? 400 : 100);
498 @@ -184,12 +133,17 @@ static ssize_t set_rate(struct device *dev, struct device_attribute *attr,
499 const char *buf, size_t count)
501 struct lis302dl_info *lis = dev_get_drvdata(dev);
502 + unsigned long flags;
504 + local_irq_save(flags);
506 if (!strcmp(buf, "400\n"))
507 - reg_set_bit_mask(lis, LIS302DL_REG_CTRL1, LIS302DL_CTRL1_DR,
508 + __reg_set_bit_mask(lis, LIS302DL_REG_CTRL1, LIS302DL_CTRL1_DR,
511 - reg_set_bit_mask(lis, LIS302DL_REG_CTRL1, LIS302DL_CTRL1_DR, 0);
512 + __reg_set_bit_mask(lis, LIS302DL_REG_CTRL1, LIS302DL_CTRL1_DR,
514 + local_irq_restore(flags);
518 @@ -200,7 +154,13 @@ static ssize_t show_scale(struct device *dev, struct device_attribute *attr,
521 struct lis302dl_info *lis = dev_get_drvdata(dev);
522 - u_int8_t ctrl1 = reg_read(lis, LIS302DL_REG_CTRL1);
524 + unsigned long flags;
526 + local_irq_save(flags);
527 + ctrl1 = (lis->pdata->lis302dl_bitbang_reg_read)(lis,
528 + LIS302DL_REG_CTRL1);
529 + local_irq_restore(flags);
531 return sprintf(buf, "%s\n", ctrl1 & LIS302DL_CTRL1_FS ? "9.2" : "2.3");
533 @@ -209,12 +169,18 @@ static ssize_t set_scale(struct device *dev, struct device_attribute *attr,
534 const char *buf, size_t count)
536 struct lis302dl_info *lis = dev_get_drvdata(dev);
537 + unsigned long flags;
539 + local_irq_save(flags);
541 if (!strcmp(buf, "9.2\n"))
542 - reg_set_bit_mask(lis, LIS302DL_REG_CTRL1, LIS302DL_CTRL1_FS,
543 + __reg_set_bit_mask(lis, LIS302DL_REG_CTRL1, LIS302DL_CTRL1_FS,
546 - reg_set_bit_mask(lis, LIS302DL_REG_CTRL1, LIS302DL_CTRL1_FS, 0);
547 + __reg_set_bit_mask(lis, LIS302DL_REG_CTRL1, LIS302DL_CTRL1_FS,
550 + local_irq_restore(flags);
554 @@ -222,7 +188,7 @@ static ssize_t set_scale(struct device *dev, struct device_attribute *attr,
555 static DEVICE_ATTR(full_scale, S_IRUGO | S_IWUSR, show_scale, set_scale);
557 static ssize_t lis302dl_dump(struct device *dev, struct device_attribute *attr,
561 struct lis302dl_info *lis = dev_get_drvdata(dev);
563 @@ -233,7 +199,7 @@ static ssize_t lis302dl_dump(struct device *dev, struct device_attribute *attr,
564 local_irq_save(flags);
566 for (n = 0; n < sizeof(reg); n++)
567 - reg[n] = reg_read(lis, n);
568 + reg[n] = (lis->pdata->lis302dl_bitbang_reg_read)(lis, n);
570 local_irq_restore(flags);
572 @@ -248,9 +214,9 @@ static ssize_t lis302dl_dump(struct device *dev, struct device_attribute *attr,
574 static DEVICE_ATTR(dump, S_IRUGO, lis302dl_dump, NULL);
576 -static int freefall_ms_to_duration(struct lis302dl_info *lis, int ms)
577 +static int __freefall_ms_to_duration(struct lis302dl_info *lis, int ms)
579 - u_int8_t r = reg_read(lis, LIS302DL_REG_CTRL1);
580 + u8 r = (lis->pdata->lis302dl_bitbang_reg_read)(lis, LIS302DL_REG_CTRL1);
582 /* If we have 400 ms sampling rate, the stepping is 2.5 ms,
583 * on 100 ms the stepping is 10ms */
584 @@ -268,9 +234,9 @@ static int freefall_ms_to_duration(struct lis302dl_info *lis, int ms)
588 -static int freefall_duration_to_ms(struct lis302dl_info *lis, int duration)
589 +static int __freefall_duration_to_ms(struct lis302dl_info *lis, int duration)
591 - u_int8_t r = reg_read(lis, LIS302DL_REG_CTRL1);
592 + u8 r = (lis->pdata->lis302dl_bitbang_reg_read)(lis, LIS302DL_REG_CTRL1);
594 if (r & LIS302DL_CTRL1_DR)
595 return (duration * 25) / 10;
596 @@ -314,18 +280,18 @@ static ssize_t set_freefall_common(int which, struct device *dev,
597 /* Turn off the interrupt */
598 local_irq_save(flags);
599 if (lis->flags & LIS302DL_F_IRQ_WAKE)
600 - disable_irq_wake(lis->spi_dev->irq);
601 - lis302dl_int_mode(lis->spi_dev, which,
602 + disable_irq_wake(lis->pdata->interrupt);
603 + __lis302dl_int_mode(lis->dev, which,
604 LIS302DL_INTMODE_DATA_READY);
605 lis->flags &= ~(flag_mask | LIS302DL_F_IRQ_WAKE);
607 - reg_write(lis, r_cfg, 0);
608 - reg_write(lis, r_ths, 0);
609 - reg_write(lis, r_duration, 0);
610 + (lis->pdata->lis302dl_bitbang_reg_write)(lis, r_cfg, 0);
611 + (lis->pdata->lis302dl_bitbang_reg_write)(lis, r_ths, 0);
612 + (lis->pdata->lis302dl_bitbang_reg_write)(lis, r_duration, 0);
614 /* Power off unless the input subsystem is using the device */
615 if (!(lis->flags & LIS302DL_F_INPUT_OPEN))
616 - reg_set_bit_mask(lis, LIS302DL_REG_CTRL1,
617 + __reg_set_bit_mask(lis, LIS302DL_REG_CTRL1,
618 LIS302DL_CTRL1_PD, 0);
620 local_irq_restore(flags);
621 @@ -337,7 +303,10 @@ static ssize_t set_freefall_common(int which, struct device *dev,
625 - duration = freefall_ms_to_duration(lis, ms);
626 + local_irq_save(flags);
627 + duration = __freefall_ms_to_duration(lis, ms);
628 + local_irq_save(flags);
633 @@ -355,23 +324,25 @@ static ssize_t set_freefall_common(int which, struct device *dev,
635 /* Setup the configuration registers */
636 local_irq_save(flags);
637 - reg_write(lis, r_cfg, 0); /* First zero to get to a known state */
638 - reg_write(lis, r_cfg,
639 + /* First zero to get to a known state */
640 + (lis->pdata->lis302dl_bitbang_reg_write)(lis, r_cfg, 0);
641 + (lis->pdata->lis302dl_bitbang_reg_write)(lis, r_cfg,
642 (and_events ? LIS302DL_FFWUCFG_AOI : 0) |
643 x_lo | x_hi | y_lo | y_hi | z_lo | z_hi);
644 - reg_write(lis, r_ths, threshold & ~LIS302DL_FFWUTHS_DCRM);
645 - reg_write(lis, r_duration, duration);
646 + (lis->pdata->lis302dl_bitbang_reg_write)(lis, r_ths,
647 + threshold & ~LIS302DL_FFWUTHS_DCRM);
648 + (lis->pdata->lis302dl_bitbang_reg_write)(lis, r_duration, duration);
650 /* Route the interrupt for wakeup */
651 - lis302dl_int_mode(lis->spi_dev, which, intmode);
652 + __lis302dl_int_mode(lis->dev, which, intmode);
654 /* Power up the device and note that we want to wake up from
656 if (!(lis->flags & LIS302DL_F_IRQ_WAKE))
657 - enable_irq_wake(lis->spi_dev->irq);
658 + enable_irq_wake(lis->pdata->interrupt);
660 lis->flags |= flag_mask | LIS302DL_F_IRQ_WAKE;
661 - reg_set_bit_mask(lis, LIS302DL_REG_CTRL1, LIS302DL_CTRL1_PD,
662 + __reg_set_bit_mask(lis, LIS302DL_REG_CTRL1, LIS302DL_CTRL1_PD,
664 local_irq_restore(flags);
666 @@ -403,6 +374,8 @@ static ssize_t show_freefall_common(int which, struct device *dev,
667 int r_duration = LIS302DL_REG_FF_WU_DURATION_1;
668 int r_cfg = LIS302DL_REG_FF_WU_CFG_1;
669 int r_src = LIS302DL_REG_FF_WU_SRC_1;
670 + unsigned long flags;
673 /* Configure second freefall/wakeup pin */
675 @@ -411,11 +384,15 @@ static ssize_t show_freefall_common(int which, struct device *dev,
676 r_cfg = LIS302DL_REG_FF_WU_CFG_2;
677 r_src = LIS302DL_REG_FF_WU_SRC_2;
679 - config = reg_read(lis, r_cfg);
680 - threshold = reg_read(lis, r_ths);
681 - duration = reg_read(lis, r_duration);
682 - r4 = reg_read(lis, r_src);
683 - r5 = reg_read(lis, LIS302DL_REG_CTRL3);
685 + local_irq_save(flags);
686 + config = (lis->pdata->lis302dl_bitbang_reg_read)(lis, r_cfg);
687 + threshold = (lis->pdata->lis302dl_bitbang_reg_read)(lis, r_ths);
688 + duration = (lis->pdata->lis302dl_bitbang_reg_read)(lis, r_duration);
689 + r4 = (lis->pdata->lis302dl_bitbang_reg_read)(lis, r_src);
690 + r5 = (lis->pdata->lis302dl_bitbang_reg_read)(lis, LIS302DL_REG_CTRL3);
691 + ms = __freefall_duration_to_ms(lis, duration);
692 + local_irq_restore(flags);
694 /* All events off? */
695 if ((config & (LIS302DL_FFWUCFG_XLIE | LIS302DL_FFWUCFG_XHIE |
696 @@ -423,13 +400,14 @@ static ssize_t show_freefall_common(int which, struct device *dev,
697 LIS302DL_FFWUCFG_ZLIE | LIS302DL_FFWUCFG_ZHIE)) == 0)
698 return sprintf(buf, "off\n");
702 "%s events, %s interrupt, duration %d, threshold %d, "
703 "enabled: %s %s %s %s %s %s\n",
704 (config & LIS302DL_FFWUCFG_AOI) == 0 ? "or" : "and",
705 (config & LIS302DL_FFWUCFG_LIR) == 0 ?
706 "don't latch" : "latch",
707 - freefall_duration_to_ms(lis, duration), threshold,
709 (config & LIS302DL_FFWUCFG_XLIE) == 0 ? "---" : "xlo",
710 (config & LIS302DL_FFWUCFG_XHIE) == 0 ? "---" : "xhi",
711 (config & LIS302DL_FFWUCFG_YLIE) == 0 ? "---" : "ylo",
712 @@ -480,14 +458,15 @@ static int lis302dl_input_open(struct input_dev *inp)
714 local_irq_save(flags);
715 /* make sure we're powered up and generate data ready */
716 - reg_set_bit_mask(lis, LIS302DL_REG_CTRL1, ctrl1, ctrl1);
717 - local_irq_restore(flags);
718 + __reg_set_bit_mask(lis, LIS302DL_REG_CTRL1, ctrl1, ctrl1);
720 lis->flags |= LIS302DL_F_INPUT_OPEN;
722 /* kick it off -- since we are edge triggered, if we missed the edge
723 * permanent low interrupt is death for us */
724 - (lis->pdata->lis302dl_bitbang_read)(lis);
725 + (lis->pdata->lis302dl_bitbang_read_sample)(lis);
727 + local_irq_restore(flags);
731 @@ -504,13 +483,13 @@ static void lis302dl_input_close(struct input_dev *inp)
732 /* since the input core already serializes access and makes sure we
733 * only see close() for the close of the last user, we can safely
734 * disable the data ready events */
735 - reg_set_bit_mask(lis, LIS302DL_REG_CTRL1, ctrl1, 0x00);
736 + __reg_set_bit_mask(lis, LIS302DL_REG_CTRL1, ctrl1, 0x00);
737 lis->flags &= ~LIS302DL_F_INPUT_OPEN;
739 /* however, don't power down the whole device if still needed */
740 if (!(lis->flags & LIS302DL_F_WUP_FF ||
741 lis->flags & LIS302DL_F_WUP_CLICK)) {
742 - reg_set_bit_mask(lis, LIS302DL_REG_CTRL1, LIS302DL_CTRL1_PD,
743 + __reg_set_bit_mask(lis, LIS302DL_REG_CTRL1, LIS302DL_CTRL1_PD,
746 local_irq_restore(flags);
747 @@ -524,23 +503,23 @@ static int __lis302dl_reset_device(struct lis302dl_info *lis)
751 - reg_write(lis, LIS302DL_REG_CTRL2, LIS302DL_CTRL2_BOOT |
752 - LIS302DL_CTRL2_FDS);
753 + (lis->pdata->lis302dl_bitbang_reg_write)(lis, LIS302DL_REG_CTRL2,
754 + LIS302DL_CTRL2_BOOT | LIS302DL_CTRL2_FDS);
756 - while ((reg_read(lis, LIS302DL_REG_CTRL2) & LIS302DL_CTRL2_BOOT) &&
758 + while (((lis->pdata->lis302dl_bitbang_reg_read)(lis, LIS302DL_REG_CTRL2)
759 + & LIS302DL_CTRL2_BOOT) && (timeout--))
762 return !!(timeout < 0);
765 -static int __devinit lis302dl_probe(struct spi_device *spi)
766 +static int __devinit lis302dl_probe(struct platform_device *pdev)
769 struct lis302dl_info *lis;
772 - struct lis302dl_platform_data *pdata;
773 + struct lis302dl_platform_data *pdata = pdev->dev.platform_data;
775 lis = kzalloc(sizeof(*lis), GFP_KERNEL);
777 @@ -548,38 +527,34 @@ static int __devinit lis302dl_probe(struct spi_device *spi)
779 local_irq_save(flags);
781 - mutex_init(&lis->lock);
782 - lis->spi_dev = spi;
783 + lis->dev = &pdev->dev;
785 - spi_set_drvdata(spi, lis);
786 + dev_set_drvdata(lis->dev, lis);
788 - pdata = spi->dev.platform_data;
789 + lis->pdata = pdata;
791 - rc = spi_setup(spi);
793 - dev_err(&spi->dev, "error during spi_setup\n");
794 - dev_set_drvdata(&spi->dev, NULL);
795 - goto bail_free_lis;
797 + /* Configure our IO */
798 + (lis->pdata->lis302dl_suspend_io)(lis, 1);
800 - wai = reg_read(lis, LIS302DL_REG_WHO_AM_I);
801 + wai = (lis->pdata->lis302dl_bitbang_reg_read)(lis,
802 + LIS302DL_REG_WHO_AM_I);
803 if (wai != LIS302DL_WHO_AM_I_MAGIC) {
804 - dev_err(&spi->dev, "unknown who_am_i signature 0x%02x\n", wai);
805 - dev_set_drvdata(&spi->dev, NULL);
806 + dev_err(lis->dev, "unknown who_am_i signature 0x%02x\n", wai);
807 + dev_set_drvdata(lis->dev, NULL);
812 - rc = sysfs_create_group(&spi->dev.kobj, &lis302dl_attr_group);
813 + rc = sysfs_create_group(&lis->dev->kobj, &lis302dl_attr_group);
815 - dev_err(&spi->dev, "error creating sysfs group\n");
816 + dev_err(lis->dev, "error creating sysfs group\n");
820 /* initialize input layer details */
821 lis->input_dev = input_allocate_device();
822 if (!lis->input_dev) {
823 - dev_err(&spi->dev, "Unable to allocate input device\n");
824 + dev_err(lis->dev, "Unable to allocate input device\n");
828 @@ -601,57 +576,64 @@ static int __devinit lis302dl_probe(struct spi_device *spi)
830 rc = input_register_device(lis->input_dev);
832 - dev_err(&spi->dev, "error %d registering input device\n", rc);
833 + dev_err(lis->dev, "error %d registering input device\n", rc);
837 if (__lis302dl_reset_device(lis))
838 - dev_err(&spi->dev, "device BOOT reload failed\n");
839 + dev_err(lis->dev, "device BOOT reload failed\n");
841 /* force us powered */
842 - reg_write(lis, LIS302DL_REG_CTRL1, LIS302DL_CTRL1_PD |
843 - LIS302DL_CTRL1_Xen |
844 - LIS302DL_CTRL1_Yen |
845 - LIS302DL_CTRL1_Zen);
846 + (lis->pdata->lis302dl_bitbang_reg_write)(lis, LIS302DL_REG_CTRL1,
847 + LIS302DL_CTRL1_PD |
848 + LIS302DL_CTRL1_Xen |
849 + LIS302DL_CTRL1_Yen |
850 + LIS302DL_CTRL1_Zen);
853 - reg_write(lis, LIS302DL_REG_CTRL2, 0);
854 - reg_write(lis, LIS302DL_REG_CTRL3, LIS302DL_CTRL3_PP_OD |
855 - LIS302DL_CTRL3_IHL);
856 - reg_write(lis, LIS302DL_REG_FF_WU_THS_1, 0x0);
857 - reg_write(lis, LIS302DL_REG_FF_WU_DURATION_1, 0x00);
858 - reg_write(lis, LIS302DL_REG_FF_WU_CFG_1, 0x0);
859 + (lis->pdata->lis302dl_bitbang_reg_write)(lis, LIS302DL_REG_CTRL2, 0);
860 + (lis->pdata->lis302dl_bitbang_reg_write)(lis, LIS302DL_REG_CTRL3,
861 + LIS302DL_CTRL3_PP_OD | LIS302DL_CTRL3_IHL);
862 + (lis->pdata->lis302dl_bitbang_reg_write)(lis,
863 + LIS302DL_REG_FF_WU_THS_1, 0x0);
864 + (lis->pdata->lis302dl_bitbang_reg_write)(lis,
865 + LIS302DL_REG_FF_WU_DURATION_1, 0x00);
866 + (lis->pdata->lis302dl_bitbang_reg_write)(lis,
867 + LIS302DL_REG_FF_WU_CFG_1, 0x0);
869 /* start off in powered down mode; we power up when someone opens us */
870 - reg_write(lis, LIS302DL_REG_CTRL1, LIS302DL_CTRL1_Xen |
871 - LIS302DL_CTRL1_Yen |
872 - LIS302DL_CTRL1_Zen);
873 + (lis->pdata->lis302dl_bitbang_reg_write)(lis, LIS302DL_REG_CTRL1,
874 + LIS302DL_CTRL1_Xen |
875 + LIS302DL_CTRL1_Yen |
876 + LIS302DL_CTRL1_Zen);
878 if (pdata->open_drain)
879 /* switch interrupt to open collector, active-low */
880 - reg_write(lis, LIS302DL_REG_CTRL3, LIS302DL_CTRL3_PP_OD |
881 - LIS302DL_CTRL3_IHL);
882 + (lis->pdata->lis302dl_bitbang_reg_write)(lis,
883 + LIS302DL_REG_CTRL3, LIS302DL_CTRL3_PP_OD |
884 + LIS302DL_CTRL3_IHL);
886 /* push-pull, active-low */
887 - reg_write(lis, LIS302DL_REG_CTRL3, LIS302DL_CTRL3_IHL);
888 + (lis->pdata->lis302dl_bitbang_reg_write)(lis,
889 + LIS302DL_REG_CTRL3, LIS302DL_CTRL3_IHL);
891 - lis302dl_int_mode(spi, 1, LIS302DL_INTMODE_DATA_READY);
892 - lis302dl_int_mode(spi, 2, LIS302DL_INTMODE_DATA_READY);
893 + __lis302dl_int_mode(lis->dev, 1, LIS302DL_INTMODE_DATA_READY);
894 + __lis302dl_int_mode(lis->dev, 2, LIS302DL_INTMODE_DATA_READY);
896 - reg_read(lis, LIS302DL_REG_STATUS);
897 - reg_read(lis, LIS302DL_REG_FF_WU_SRC_1);
898 - reg_read(lis, LIS302DL_REG_FF_WU_SRC_2);
899 - reg_read(lis, LIS302DL_REG_CLICK_SRC);
900 + (lis->pdata->lis302dl_bitbang_reg_read)(lis, LIS302DL_REG_STATUS);
901 + (lis->pdata->lis302dl_bitbang_reg_read)(lis, LIS302DL_REG_FF_WU_SRC_1);
902 + (lis->pdata->lis302dl_bitbang_reg_read)(lis, LIS302DL_REG_FF_WU_SRC_2);
903 + (lis->pdata->lis302dl_bitbang_reg_read)(lis, LIS302DL_REG_CLICK_SRC);
905 - dev_info(&spi->dev, "Found %s\n", pdata->name);
906 + dev_info(lis->dev, "Found %s\n", pdata->name);
910 - rc = request_irq(lis->spi_dev->irq, lis302dl_interrupt,
911 + rc = request_irq(pdata->interrupt, lis302dl_interrupt,
912 IRQF_TRIGGER_FALLING, "lis302dl", lis);
914 - dev_err(&spi->dev, "error requesting IRQ %d\n",
915 - lis->spi_dev->irq);
916 + dev_err(lis->dev, "error requesting IRQ %d\n",
917 + lis->pdata->interrupt);
920 local_irq_restore(flags);
921 @@ -662,50 +644,71 @@ bail_inp_reg:
923 input_free_device(lis->input_dev);
925 - sysfs_remove_group(&spi->dev.kobj, &lis302dl_attr_group);
926 + sysfs_remove_group(&lis->dev->kobj, &lis302dl_attr_group);
929 local_irq_restore(flags);
933 -static int __devexit lis302dl_remove(struct spi_device *spi)
934 +static int __devexit lis302dl_remove(struct platform_device *pdev)
936 - struct lis302dl_info *lis = dev_get_drvdata(&spi->dev);
937 + struct lis302dl_info *lis = dev_get_drvdata(&pdev->dev);
940 /* Reset and power down the device */
941 local_irq_save(flags);
942 - reg_write(lis, LIS302DL_REG_CTRL3, 0x00);
943 - reg_write(lis, LIS302DL_REG_CTRL2, 0x00);
944 - reg_write(lis, LIS302DL_REG_CTRL1, 0x00);
945 + (lis->pdata->lis302dl_bitbang_reg_write)(lis, LIS302DL_REG_CTRL3, 0x00);
946 + (lis->pdata->lis302dl_bitbang_reg_write)(lis, LIS302DL_REG_CTRL2, 0x00);
947 + (lis->pdata->lis302dl_bitbang_reg_write)(lis, LIS302DL_REG_CTRL1, 0x00);
948 local_irq_restore(flags);
950 /* Cleanup resources */
951 - free_irq(lis->spi_dev->irq, lis);
952 - sysfs_remove_group(&spi->dev.kobj, &lis302dl_attr_group);
953 + free_irq(lis->pdata->interrupt, lis);
954 + sysfs_remove_group(&pdev->dev.kobj, &lis302dl_attr_group);
955 input_unregister_device(lis->input_dev);
957 input_free_device(lis->input_dev);
958 - dev_set_drvdata(&spi->dev, NULL);
959 + dev_set_drvdata(lis->dev, NULL);
966 -static int lis302dl_suspend(struct spi_device *spi, pm_message_t state)
968 +static u8 regs_to_save[] = {
969 + LIS302DL_REG_CTRL1,
970 + LIS302DL_REG_CTRL2,
971 + LIS302DL_REG_CTRL3,
972 + LIS302DL_REG_FF_WU_CFG_1,
973 + LIS302DL_REG_FF_WU_THS_1,
974 + LIS302DL_REG_FF_WU_DURATION_1,
975 + LIS302DL_REG_FF_WU_CFG_2,
976 + LIS302DL_REG_FF_WU_THS_2,
977 + LIS302DL_REG_FF_WU_DURATION_2,
978 + LIS302DL_REG_CLICK_CFG,
979 + LIS302DL_REG_CLICK_THSY_X,
980 + LIS302DL_REG_CLICK_THSZ,
981 + LIS302DL_REG_CLICK_TIME_LIMIT,
982 + LIS302DL_REG_CLICK_LATENCY,
983 + LIS302DL_REG_CLICK_WINDOW,
987 +static int lis302dl_suspend(struct platform_device *pdev, pm_message_t state)
989 - struct lis302dl_info *lis = dev_get_drvdata(&spi->dev);
990 + struct lis302dl_info *lis = dev_get_drvdata(&pdev->dev);
995 /* determine if we want to wake up from the accel. */
996 if (lis->flags & LIS302DL_F_WUP_FF ||
997 lis->flags & LIS302DL_F_WUP_CLICK)
1000 - disable_irq(lis->spi_dev->irq);
1001 + disable_irq(lis->pdata->interrupt);
1002 local_irq_save(flags);
1005 @@ -718,38 +721,15 @@ static int lis302dl_suspend(struct spi_device *spi, pm_message_t state)
1006 (lis->pdata->lis302dl_suspend_io)(lis, 1);
1008 /* save registers */
1009 - lis->regs[LIS302DL_REG_CTRL1] = reg_read(lis, LIS302DL_REG_CTRL1);
1010 - lis->regs[LIS302DL_REG_CTRL2] = reg_read(lis, LIS302DL_REG_CTRL2);
1011 - lis->regs[LIS302DL_REG_CTRL3] = reg_read(lis, LIS302DL_REG_CTRL3);
1012 - lis->regs[LIS302DL_REG_FF_WU_CFG_1] =
1013 - reg_read(lis, LIS302DL_REG_FF_WU_CFG_1);
1014 - lis->regs[LIS302DL_REG_FF_WU_THS_1] =
1015 - reg_read(lis, LIS302DL_REG_FF_WU_THS_1);
1016 - lis->regs[LIS302DL_REG_FF_WU_DURATION_1] =
1017 - reg_read(lis, LIS302DL_REG_FF_WU_DURATION_1);
1018 - lis->regs[LIS302DL_REG_FF_WU_CFG_2] =
1019 - reg_read(lis, LIS302DL_REG_FF_WU_CFG_2);
1020 - lis->regs[LIS302DL_REG_FF_WU_THS_2] =
1021 - reg_read(lis, LIS302DL_REG_FF_WU_THS_2);
1022 - lis->regs[LIS302DL_REG_FF_WU_DURATION_2] =
1023 - reg_read(lis, LIS302DL_REG_FF_WU_DURATION_2);
1024 - lis->regs[LIS302DL_REG_CLICK_CFG] =
1025 - reg_read(lis, LIS302DL_REG_CLICK_CFG);
1026 - lis->regs[LIS302DL_REG_CLICK_THSY_X] =
1027 - reg_read(lis, LIS302DL_REG_CLICK_THSY_X);
1028 - lis->regs[LIS302DL_REG_CLICK_THSZ] =
1029 - reg_read(lis, LIS302DL_REG_CLICK_THSZ);
1030 - lis->regs[LIS302DL_REG_CLICK_TIME_LIMIT] =
1031 - reg_read(lis, LIS302DL_REG_CLICK_TIME_LIMIT);
1032 - lis->regs[LIS302DL_REG_CLICK_LATENCY] =
1033 - reg_read(lis, LIS302DL_REG_CLICK_LATENCY);
1034 - lis->regs[LIS302DL_REG_CLICK_WINDOW] =
1035 - reg_read(lis, LIS302DL_REG_CLICK_WINDOW);
1036 + for (n = 0; n < ARRAY_SIZE(regs_to_save); n++)
1037 + lis->regs[regs_to_save[n]] =
1038 + (lis->pdata->lis302dl_bitbang_reg_read)(lis,
1042 - tmp = reg_read(lis, LIS302DL_REG_CTRL1);
1043 + tmp = (lis->pdata->lis302dl_bitbang_reg_read)(lis, LIS302DL_REG_CTRL1);
1044 tmp &= ~LIS302DL_CTRL1_PD;
1045 - reg_write(lis, LIS302DL_REG_CTRL1, tmp);
1046 + (lis->pdata->lis302dl_bitbang_reg_write)(lis, LIS302DL_REG_CTRL1, tmp);
1048 /* place our IO to the device in sleep-compatible states */
1049 (lis->pdata->lis302dl_suspend_io)(lis, 0);
1050 @@ -759,10 +739,11 @@ static int lis302dl_suspend(struct spi_device *spi, pm_message_t state)
1054 -static int lis302dl_resume(struct spi_device *spi)
1055 +static int lis302dl_resume(struct platform_device *pdev)
1057 - struct lis302dl_info *lis = dev_get_drvdata(&spi->dev);
1058 + struct lis302dl_info *lis = dev_get_drvdata(&pdev->dev);
1059 unsigned long flags;
1062 if (lis->flags & LIS302DL_F_WUP_FF ||
1063 lis->flags & LIS302DL_F_WUP_CLICK)
1064 @@ -774,50 +755,28 @@ static int lis302dl_resume(struct spi_device *spi)
1065 (lis->pdata->lis302dl_suspend_io)(lis, 1);
1067 /* resume from powerdown first! */
1068 - reg_write(lis, LIS302DL_REG_CTRL1, LIS302DL_CTRL1_PD |
1069 - LIS302DL_CTRL1_Xen |
1070 - LIS302DL_CTRL1_Yen |
1071 - LIS302DL_CTRL1_Zen);
1072 + (lis->pdata->lis302dl_bitbang_reg_write)(lis, LIS302DL_REG_CTRL1,
1073 + LIS302DL_CTRL1_PD |
1074 + LIS302DL_CTRL1_Xen |
1075 + LIS302DL_CTRL1_Yen |
1076 + LIS302DL_CTRL1_Zen);
1079 if (__lis302dl_reset_device(lis))
1080 - dev_err(&spi->dev, "device BOOT reload failed\n");
1081 + dev_err(&pdev->dev, "device BOOT reload failed\n");
1083 - /* restore registers after resume */
1084 - reg_write(lis, LIS302DL_REG_CTRL1, lis->regs[LIS302DL_REG_CTRL1] |
1085 - LIS302DL_CTRL1_PD |
1086 + lis->regs[LIS302DL_REG_CTRL1] |= LIS302DL_CTRL1_PD |
1087 LIS302DL_CTRL1_Xen |
1088 LIS302DL_CTRL1_Yen |
1089 - LIS302DL_CTRL1_Zen);
1090 - reg_write(lis, LIS302DL_REG_CTRL2, lis->regs[LIS302DL_REG_CTRL2]);
1091 - reg_write(lis, LIS302DL_REG_CTRL3, lis->regs[LIS302DL_REG_CTRL3]);
1092 - reg_write(lis, LIS302DL_REG_FF_WU_CFG_1,
1093 - lis->regs[LIS302DL_REG_FF_WU_CFG_1]);
1094 - reg_write(lis, LIS302DL_REG_FF_WU_THS_1,
1095 - lis->regs[LIS302DL_REG_FF_WU_THS_1]);
1096 - reg_write(lis, LIS302DL_REG_FF_WU_DURATION_1,
1097 - lis->regs[LIS302DL_REG_FF_WU_DURATION_1]);
1098 - reg_write(lis, LIS302DL_REG_FF_WU_CFG_2,
1099 - lis->regs[LIS302DL_REG_FF_WU_CFG_2]);
1100 - reg_write(lis, LIS302DL_REG_FF_WU_THS_2,
1101 - lis->regs[LIS302DL_REG_FF_WU_THS_2]);
1102 - reg_write(lis, LIS302DL_REG_FF_WU_DURATION_2,
1103 - lis->regs[LIS302DL_REG_FF_WU_DURATION_2]);
1104 - reg_write(lis, LIS302DL_REG_CLICK_CFG,
1105 - lis->regs[LIS302DL_REG_CLICK_CFG]);
1106 - reg_write(lis, LIS302DL_REG_CLICK_THSY_X,
1107 - lis->regs[LIS302DL_REG_CLICK_THSY_X]);
1108 - reg_write(lis, LIS302DL_REG_CLICK_THSZ,
1109 - lis->regs[LIS302DL_REG_CLICK_THSZ]);
1110 - reg_write(lis, LIS302DL_REG_CLICK_TIME_LIMIT,
1111 - lis->regs[LIS302DL_REG_CLICK_TIME_LIMIT]);
1112 - reg_write(lis, LIS302DL_REG_CLICK_LATENCY,
1113 - lis->regs[LIS302DL_REG_CLICK_LATENCY]);
1114 - reg_write(lis, LIS302DL_REG_CLICK_WINDOW,
1115 - lis->regs[LIS302DL_REG_CLICK_WINDOW]);
1116 + LIS302DL_CTRL1_Zen;
1118 + /* restore registers after resume */
1119 + for (n = 0; n < ARRAY_SIZE(regs_to_save); n++)
1120 + (lis->pdata->lis302dl_bitbang_reg_write)(lis,
1121 + regs_to_save[n], lis->regs[regs_to_save[n]]);
1123 local_irq_restore(flags);
1124 - enable_irq(lis->spi_dev->irq);
1125 + enable_irq(lis->pdata->interrupt);
1129 @@ -826,7 +785,7 @@ static int lis302dl_resume(struct spi_device *spi)
1130 #define lis302dl_resume NULL
1133 -static struct spi_driver lis302dl_driver = {
1134 +static struct platform_driver lis302dl_driver = {
1137 .owner = THIS_MODULE,
1138 @@ -838,14 +797,14 @@ static struct spi_driver lis302dl_driver = {
1139 .resume = lis302dl_resume,
1142 -static int __init lis302dl_init(void)
1143 +static int __devinit lis302dl_init(void)
1145 - return spi_register_driver(&lis302dl_driver);
1146 + return platform_driver_register(&lis302dl_driver);
1149 static void __exit lis302dl_exit(void)
1151 - spi_unregister_driver(&lis302dl_driver);
1152 + platform_driver_unregister(&lis302dl_driver);
1155 MODULE_AUTHOR("Harald Welte <laforge@openmoko.org>");
1156 diff --git a/include/linux/lis302dl.h b/include/linux/lis302dl.h
1157 index 7daa8b3..4578db4 100644
1158 --- a/include/linux/lis302dl.h
1159 +++ b/include/linux/lis302dl.h
1160 @@ -15,15 +15,18 @@ struct lis302dl_platform_data {
1161 unsigned long pin_mosi;
1162 unsigned long pin_miso;
1164 - void (*lis302dl_bitbang_read)(struct lis302dl_info *);
1166 + void (*lis302dl_bitbang_read_sample)(struct lis302dl_info *);
1167 void (*lis302dl_suspend_io)(struct lis302dl_info *, int resuming);
1168 + int (*lis302dl_bitbang_reg_read)(struct lis302dl_info *, u8 reg);
1169 + void (*lis302dl_bitbang_reg_write)(struct lis302dl_info *, u8 reg,
1173 struct lis302dl_info {
1174 struct lis302dl_platform_data *pdata;
1175 - struct spi_device *spi_dev;
1176 + struct device *dev;
1177 struct input_dev *input_dev;
1178 - struct mutex lock;
1180 u_int8_t regs[0x40];