aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/s3c24xx/patches-2.6.24/1303-fix-lid302dl-bitbang-all-the-way-baby.patch.patch
blob: 852faaeb42ecb0dc7196766155e4cd69ef4281ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
From 1c6f5a92c816db43128444606c26507ebe6e5a43 Mon Sep 17 00:00:00 2001
From: Andy Green <andy@openmoko.com>
Date: Mon, 13 Oct 2008 12:01:05 +0100
Subject: [PATCH] fix-lid302dl-bitbang-all-the-way-baby.patch

This large patch removes motion sensor from Linux SPI bitbang driver.
Previously, some access was done through Linux SPI protected
by a mutex, and the ISR access was done by platform bitbang code due
to inability of Linux SPI driver to work in the interrupt context.

Now all access is done by bitbang callbacks in mach_gta02.c and are
protected by single scheme of interrupt lockout for the duration --
I line-by-line'd the driver to confirm that best I could, adding
protection and taking more care on several /sys related paths.

Because this is no longer a Linux SPI bus driver, the path for various
/sys things have changed.  They can now be found down, eg,

/sys/devices/platform/lis302dl.1/sample_rate

lis302dl.1 is the top sensor and .2 the bottom.  The names of the input
susbsytem paths remain the same as before.

Signed-off-by: Andy Green <andy@openmoko.com>
---
 arch/arm/mach-s3c2440/mach-gta02.c |  233 +++++++++----------
 drivers/input/misc/lis302dl.c      |  437 ++++++++++++++++--------------------
 include/linux/lis302dl.h           |    9 +-
 3 files changed, 315 insertions(+), 364 deletions(-)

diff --git a/arch/arm/mach-s3c2440/mach-gta02.c b/arch/arm/mach-s3c2440/mach-gta02.c
index 467c417..b19632c 100644
--- a/arch/arm/mach-s3c2440/mach-gta02.c
+++ b/arch/arm/mach-s3c2440/mach-gta02.c
@@ -1052,20 +1052,21 @@ static struct platform_device gta02_vibrator_dev = {
 /* #define DEBUG_SPEW_MS */
 #define MG_PER_SAMPLE 18
 
-struct lis302dl_platform_data lis302_pdata[];
+struct lis302dl_platform_data lis302_pdata_top;
+struct lis302dl_platform_data lis302_pdata_bottom;
 
-void gta02_lis302dl_bitbang_read(struct lis302dl_info *lis)
+/*
+ * generic SPI RX and TX bitbang
+ * only call with interrupts off!
+ */
+
+static void __gta02_lis302dl_bitbang(struct lis302dl_info *lis, u8 *tx,
+					     int tx_bytes, u8 *rx, int rx_bytes)
 {
 	struct lis302dl_platform_data *pdata = lis->pdata;
-	u8 shifter = 0xc0 | LIS302DL_REG_OUT_X; /* read, autoincrement */
-	int n, n1;
+	int n;
+	u8 shifter = 0;
 	unsigned long other_cs;
-	unsigned long flags;
-#ifdef DEBUG_SPEW_MS
-	s8 x, y, z;
-#endif
-
-	local_irq_save(flags);
 
 	/*
 	 * Huh.. "quirk"... CS on this device is not really "CS" like you can
@@ -1073,20 +1074,25 @@ void gta02_lis302dl_bitbang_read(struct lis302dl_info *lis)
 	 * have 2 devices on one interface, the "disabled" device when we talk
 	 * to an "enabled" device sees the clocks as I2C clocks, creating
 	 * havoc.
+	 *
 	 * I2C sees MOSI going LOW while CLK HIGH as a START action, we must
 	 * ensure this is never issued.
 	 */
 
-	if (&lis302_pdata[0] == pdata)
-		other_cs = lis302_pdata[1].pin_chip_select;
+	if (&lis302_pdata_top == pdata)
+		other_cs = lis302_pdata_bottom.pin_chip_select;
 	else
-		other_cs = lis302_pdata[0].pin_chip_select;
+		other_cs = lis302_pdata_top.pin_chip_select;
 
 	s3c2410_gpio_setpin(other_cs, 1);
 	s3c2410_gpio_setpin(pdata->pin_chip_select, 1);
 	s3c2410_gpio_setpin(pdata->pin_clk, 1);
 	s3c2410_gpio_setpin(pdata->pin_chip_select, 0);
-	for (n = 0; n < 8; n++) { /* write the r/w, inc and address */
+
+	/* send the register index, r/w and autoinc bits */
+	for (n = 0; n < (tx_bytes << 3); n++) {
+		if (!(n & 7))
+			shifter = tx[n >> 3];
 		s3c2410_gpio_setpin(pdata->pin_clk, 0);
 		s3c2410_gpio_setpin(pdata->pin_mosi, (shifter >> 7) & 1);
 		s3c2410_gpio_setpin(pdata->pin_clk, 0);
@@ -1095,44 +1101,71 @@ void gta02_lis302dl_bitbang_read(struct lis302dl_info *lis)
 		shifter <<= 1;
 	}
 
-	for (n = 0; n < 5; n++) { /* 5 consequetive registers */
-		for (n1 = 0; n1 < 8; n1++) { /* 8 bits each */
-			s3c2410_gpio_setpin(pdata->pin_clk, 0);
-			s3c2410_gpio_setpin(pdata->pin_clk, 0);
-			shifter <<= 1;
-			if (s3c2410_gpio_getpin(pdata->pin_miso))
-				shifter |= 1;
-			s3c2410_gpio_setpin(pdata->pin_clk, 1);
-			s3c2410_gpio_setpin(pdata->pin_clk, 1);
-		}
-		switch (n) {
-		case 0:
-#ifdef DEBUG_SPEW_MS
-			x = shifter;
-#endif
-			input_report_rel(lis->input_dev, REL_X, MG_PER_SAMPLE * (s8)shifter);
-			break;
-		case 2:
-#ifdef DEBUG_SPEW_MS
-			y = shifter;
-#endif
-			input_report_rel(lis->input_dev, REL_Y, MG_PER_SAMPLE * (s8)shifter);
-			break;
-		case 4:
-#ifdef DEBUG_SPEW_MS
-			z = shifter;
-#endif
-			input_report_rel(lis->input_dev, REL_Z, MG_PER_SAMPLE * (s8)shifter);
-			break;
-		}
+	for (n = 0; n < (rx_bytes << 3); n++) { /* 8 bits each */
+		s3c2410_gpio_setpin(pdata->pin_clk, 0);
+		s3c2410_gpio_setpin(pdata->pin_clk, 0);
+		shifter <<= 1;
+		if (s3c2410_gpio_getpin(pdata->pin_miso))
+			shifter |= 1;
+		if ((n & 7) == 7)
+			rx[n >> 3] = shifter;
+		s3c2410_gpio_setpin(pdata->pin_clk, 1);
+		s3c2410_gpio_setpin(pdata->pin_clk, 1);
 	}
 	s3c2410_gpio_setpin(pdata->pin_chip_select, 1);
 	s3c2410_gpio_setpin(other_cs, 1);
+}
+
+
+static int gta02_lis302dl_bitbang_read_reg(struct lis302dl_info *lis, u8 reg)
+{
+	u8 data = 0xc0 | reg; /* read, autoincrement */
+	unsigned long flags;
+
+	local_irq_save(flags);
+
+	__gta02_lis302dl_bitbang(lis, &data, 1, &data, 1);
+
+	local_irq_restore(flags);
+
+	return data;
+}
+
+static void gta02_lis302dl_bitbang_write_reg(struct lis302dl_info *lis, u8 reg,
+									 u8 val)
+{
+	u8 data[2] = { 0x00 | reg, val }; /* write, no autoincrement */
+	unsigned long flags;
+
+	local_irq_save(flags);
+
+	__gta02_lis302dl_bitbang(lis, &data[0], 2, NULL, 0);
+
 	local_irq_restore(flags);
 
+}
+
+
+static void gta02_lis302dl_bitbang_sample(struct lis302dl_info *lis)
+{
+	u8 data = 0xc0 | LIS302DL_REG_OUT_X; /* read, autoincrement */
+	u8 read[5];
+	unsigned long flags;
+
+	local_irq_save(flags);
+
+	__gta02_lis302dl_bitbang(lis, &data, 1, &read[0], 5);
+
+	local_irq_restore(flags);
+
+	input_report_rel(lis->input_dev, REL_X, MG_PER_SAMPLE * (s8)read[0]);
+	input_report_rel(lis->input_dev, REL_Y, MG_PER_SAMPLE * (s8)read[2]);
+	input_report_rel(lis->input_dev, REL_Z, MG_PER_SAMPLE * (s8)read[4]);
+
 	input_sync(lis->input_dev);
 #ifdef DEBUG_SPEW_MS
-	printk("%s: %d %d %d\n", pdata->name, x, y, z);
+	printk(KERN_INFO "%s: %d %d %d\n", pdata->name, read[0], read[2],
+								       read[4]);
 #endif
 }
 
@@ -1159,103 +1192,58 @@ void gta02_lis302dl_suspend_io(struct lis302dl_info *lis, int resume)
 	s3c2410_gpio_setpin(pdata->pin_clk, 1);
 	/* misnomer: it is a pullDOWN in 2442 */
 	s3c2410_gpio_pullup(pdata->pin_miso, 0);
+
+	s3c2410_gpio_cfgpin(pdata->pin_chip_select, S3C2410_GPIO_OUTPUT);
+	s3c2410_gpio_cfgpin(pdata->pin_clk, S3C2410_GPIO_OUTPUT);
+	s3c2410_gpio_cfgpin(pdata->pin_mosi, S3C2410_GPIO_OUTPUT);
+	s3c2410_gpio_cfgpin(pdata->pin_miso, S3C2410_GPIO_INPUT);
+
 }
 
-struct lis302dl_platform_data lis302_pdata[] = {
-	{
+
+
+struct lis302dl_platform_data lis302_pdata_top = {
 		.name		= "lis302-1 (top)",
 		.pin_chip_select= S3C2410_GPD12,
 		.pin_clk	= S3C2410_GPG7,
 		.pin_mosi	= S3C2410_GPG6,
 		.pin_miso	= S3C2410_GPG5,
+		.interrupt	= GTA02_IRQ_GSENSOR_1,
 		.open_drain	= 1, /* altered at runtime by PCB rev */
-		.lis302dl_bitbang_read = gta02_lis302dl_bitbang_read,
+		.lis302dl_bitbang_read_sample = gta02_lis302dl_bitbang_sample,
+		.lis302dl_bitbang_reg_read = gta02_lis302dl_bitbang_read_reg,
+		.lis302dl_bitbang_reg_write = gta02_lis302dl_bitbang_write_reg,
 		.lis302dl_suspend_io = gta02_lis302dl_suspend_io,
-	}, {
+};
+
+struct lis302dl_platform_data lis302_pdata_bottom = {
 		.name		= "lis302-2 (bottom)",
 		.pin_chip_select= S3C2410_GPD13,
 		.pin_clk	= S3C2410_GPG7,
 		.pin_mosi	= S3C2410_GPG6,
 		.pin_miso	= S3C2410_GPG5,
+		.interrupt	= GTA02_IRQ_GSENSOR_2,
 		.open_drain	= 1, /* altered at runtime by PCB rev */
-		.lis302dl_bitbang_read = gta02_lis302dl_bitbang_read,
+		.lis302dl_bitbang_read_sample = gta02_lis302dl_bitbang_sample,
+		.lis302dl_bitbang_reg_read = gta02_lis302dl_bitbang_read_reg,
+		.lis302dl_bitbang_reg_write = gta02_lis302dl_bitbang_write_reg,
 		.lis302dl_suspend_io = gta02_lis302dl_suspend_io,
-	},
 };
 
-static struct spi_board_info gta02_spi_acc_bdinfo[] = {
-	{
-		.modalias	= "lis302dl",
-		.platform_data	= &lis302_pdata[0],
-		.irq		= GTA02_IRQ_GSENSOR_1,
-		.max_speed_hz	= 10 * 1000 * 1000,
-		.bus_num	= 1,
-		.chip_select	= 0,
-		.mode		= SPI_MODE_3,
-	},
-	{
-		.modalias	= "lis302dl",
-		.platform_data	= &lis302_pdata[1],
-		.irq		= GTA02_IRQ_GSENSOR_2,
-		.max_speed_hz	= 10 * 1000 * 1000,
-		.bus_num	= 1,
-		.chip_select	= 1,
-		.mode		= SPI_MODE_3,
-	},
-};
-
-static void spi_acc_cs(struct s3c2410_spigpio_info *spigpio_info,
-		       int csid, int cs)
-{
-	struct lis302dl_platform_data * plat_data =
-				(struct lis302dl_platform_data *)spigpio_info->
-						     board_info->platform_data;
-	switch (cs) {
-	case BITBANG_CS_ACTIVE:
-		s3c2410_gpio_setpin(plat_data[csid].pin_chip_select, 0);
-		break;
-	case BITBANG_CS_INACTIVE:
-		s3c2410_gpio_setpin(plat_data[csid].pin_chip_select, 1);
-		break;
-	}
-}
 
-static struct s3c2410_spigpio_info spi_gpio_cfg = {
-	.pin_clk	= S3C2410_GPG7,
-	.pin_mosi	= S3C2410_GPG6,
-	.pin_miso	= S3C2410_GPG5,
-	.board_size	= ARRAY_SIZE(gta02_spi_acc_bdinfo),
-	.board_info	= gta02_spi_acc_bdinfo,
-	.chip_select	= &spi_acc_cs,
-	.num_chipselect = 2,
-};
-
-static struct resource s3c_spi_acc_resource[] = {
-	[0] = {
-		.start = S3C2410_GPG3,
-		.end   = S3C2410_GPG3,
-	},
-	[1] = {
-		.start = S3C2410_GPG5,
-		.end   = S3C2410_GPG5,
-	},
-	[2] = {
-		.start = S3C2410_GPG6,
-		.end   = S3C2410_GPG6,
-	},
-	[3] = {
-		.start = S3C2410_GPG7,
-		.end   = S3C2410_GPG7,
+static struct platform_device s3c_device_spi_acc1 = {
+	.name		  = "lis302dl",
+	.id		  = 1,
+	.dev = {
+		.platform_data = &lis302_pdata_top,
 	},
 };
 
-static struct platform_device s3c_device_spi_acc = {
-	.name		  = "spi_s3c24xx_gpio",
-	.id		  = 1,
-	.num_resources	  = ARRAY_SIZE(s3c_spi_acc_resource),
-	.resource	  = s3c_spi_acc_resource,
+static struct platform_device s3c_device_spi_acc2 = {
+	.name		  = "lis302dl",
+	.id		  = 2,
 	.dev = {
-		.platform_data = &spi_gpio_cfg,
+		.platform_data = &lis302_pdata_bottom,
 	},
 };
 
@@ -1573,8 +1561,8 @@ static void __init gta02_machine_init(void)
 	switch (system_rev) {
 	case GTA02v6_SYSTEM_REV:
 		/* we need push-pull interrupt from motion sensors */
-		lis302_pdata[0].open_drain = 0;
-		lis302_pdata[1].open_drain = 0;
+		lis302_pdata_top.open_drain = 0;
+		lis302_pdata_bottom.open_drain = 0;
 		break;
 	default:
 		break;
@@ -1635,7 +1623,8 @@ static void __init gta02_machine_init(void)
 	mangle_glamo_res_by_system_rev();
 	platform_device_register(&gta02_glamo_dev);
 
-	platform_device_register(&s3c_device_spi_acc);
+	platform_device_register(&s3c_device_spi_acc1);
+	platform_device_register(&s3c_device_spi_acc2);
 	platform_device_register(&gta02_button_dev);
 	platform_device_register(&gta02_pm_gsm_dev);
 	platform_device_register(&gta02_pm_usbhost_dev);
diff --git a/drivers/input/misc/lis302dl.c b/drivers/input/misc/lis302dl.c
index b01ca04..1d5781d 100644
--- a/drivers/input/misc/lis302dl.c
+++ b/drivers/input/misc/lis302dl.c
@@ -1,7 +1,9 @@
 /* Linux kernel driver for the ST LIS302D 3-axis accelerometer
  *
- * Copyright (C) 2007 by Openmoko, Inc.
+ * Copyright (C) 2007-2008 by Openmoko, Inc.
  * Author: Harald Welte <laforge@openmoko.org>
+ *         converted to private bitbang by:
+ *         Andy Green <andy@openmoko.com>
  * All rights reserved.
  *
  * This program is free software; you can redistribute it and/or
@@ -39,78 +41,19 @@
 
 #include <linux/lis302dl.h>
 
-/* lowlevel register access functions */
 
-#define READ_BIT		0x80
-#define READ_BIT_INC_ADS	0xc0
-#define	ADDR_MASK		0x3f
 
-static u_int8_t __reg_read(struct lis302dl_info *lis, u_int8_t reg)
+static void __reg_set_bit_mask(struct lis302dl_info *lis, u8 reg, u8 mask,
+									 u8 val)
 {
-	int rc;
-	u_int8_t cmd;
-
-	BUG_ON(reg & ~ADDR_MASK);
-
-	cmd = reg | READ_BIT;
-
-	rc = spi_w8r8(lis->spi_dev, cmd);
-
-	return rc;
-}
-
-static u_int8_t reg_read(struct lis302dl_info *lis, u_int8_t reg)
-{
-	u_int8_t ret;
-
-	mutex_lock(&lis->lock);
-	ret = __reg_read(lis, reg);
-	mutex_unlock(&lis->lock);
-
-	return ret;
-}
-
-static int __reg_write(struct lis302dl_info *lis, u_int8_t reg, u_int8_t val)
-{
-	u_int8_t buf[2];
-
-	BUG_ON(reg & ~ADDR_MASK);
-
-	buf[0] = reg;
-	buf[1] = val;
-
-	return spi_write(lis->spi_dev, buf, sizeof(buf));
-}
-
-static int reg_write(struct lis302dl_info *lis, u_int8_t reg, u_int8_t val)
-{
-	int ret;
-
-	mutex_lock(&lis->lock);
-	ret = __reg_write(lis, reg, val);
-	mutex_unlock(&lis->lock);
-
-	return ret;
-}
-
-static int reg_set_bit_mask(struct lis302dl_info *lis,
-			    u_int8_t reg, u_int8_t mask, u_int8_t val)
-{
-	int ret;
 	u_int8_t tmp;
 
 	val &= mask;
 
-	mutex_lock(&lis->lock);
-
-	tmp = __reg_read(lis, reg);
+	tmp = (lis->pdata->lis302dl_bitbang_reg_read)(lis, reg);
 	tmp &= ~mask;
 	tmp |= val;
-	ret = __reg_write(lis, reg, tmp);
-
-	mutex_unlock(&lis->lock);
-
-	return ret;
+	(lis->pdata->lis302dl_bitbang_reg_write)(lis, reg, tmp);
 }
 
 /* interrupt handling related */
@@ -124,17 +67,17 @@ enum lis302dl_intmode {
 	LIS302DL_INTMODE_CLICK		= 0x07,
 };
 
-static void lis302dl_int_mode(struct spi_device *spi, int int_pin,
+static void __lis302dl_int_mode(struct device *dev, int int_pin,
 			      enum lis302dl_intmode mode)
 {
-	struct lis302dl_info *lis = dev_get_drvdata(&spi->dev);
+	struct lis302dl_info *lis = dev_get_drvdata(dev);
 
 	switch (int_pin) {
 	case 1:
-		reg_set_bit_mask(lis, LIS302DL_REG_CTRL3, 0x07, mode);
+		__reg_set_bit_mask(lis, LIS302DL_REG_CTRL3, 0x07, mode);
 		break;
 	case 2:
-		reg_set_bit_mask(lis, LIS302DL_REG_CTRL3, 0x38, mode << 3);
+		__reg_set_bit_mask(lis, LIS302DL_REG_CTRL3, 0x38, mode << 3);
 		break;
 	default:
 		BUG();
@@ -165,7 +108,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *_lis)
 {
 	struct lis302dl_info *lis = _lis;
 
-	(lis->pdata->lis302dl_bitbang_read)(lis);
+	(lis->pdata->lis302dl_bitbang_read_sample)(lis);
 	return IRQ_HANDLED;
 }
 
@@ -175,7 +118,13 @@ static ssize_t show_rate(struct device *dev, struct device_attribute *attr,
 			 char *buf)
 {
 	struct lis302dl_info *lis = dev_get_drvdata(dev);
-	u_int8_t ctrl1 = reg_read(lis, LIS302DL_REG_CTRL1);
+	u8 ctrl1;
+	unsigned long flags;
+
+	local_irq_save(flags);
+	ctrl1 = (lis->pdata->lis302dl_bitbang_reg_read)
+						      (lis, LIS302DL_REG_CTRL1);
+	local_irq_restore(flags);
 
 	return sprintf(buf, "%d\n", ctrl1 & LIS302DL_CTRL1_DR ? 400 : 100);
 }
@@ -184,12 +133,17 @@ static ssize_t set_rate(struct device *dev, struct device_attribute *attr,
 			const char *buf, size_t count)
 {
 	struct lis302dl_info *lis = dev_get_drvdata(dev);
+	unsigned long flags;
+
+	local_irq_save(flags);
 
 	if (!strcmp(buf, "400\n"))
-		reg_set_bit_mask(lis, LIS302DL_REG_CTRL1, LIS302DL_CTRL1_DR,
+		__reg_set_bit_mask(lis, LIS302DL_REG_CTRL1, LIS302DL_CTRL1_DR,
 				 LIS302DL_CTRL1_DR);
 	else
-		reg_set_bit_mask(lis, LIS302DL_REG_CTRL1, LIS302DL_CTRL1_DR, 0);
+		__reg_set_bit_mask(lis, LIS302DL_REG_CTRL1, LIS302DL_CTRL1_DR,
+									     0);
+	local_irq_restore(flags);
 
 	return count;
 }
@@ -200,7 +154,13 @@ static ssize_t show_scale(struct device *dev, struct device_attribute *attr,
 			  char *buf)
 {
 	struct lis302dl_info *lis = dev_get_drvdata(dev);
-	u_int8_t ctrl1 = reg_read(lis, LIS302DL_REG_CTRL1);
+	u_int8_t ctrl1;
+	unsigned long flags;
+
+	local_irq_save(flags);
+	ctrl1 = (lis->pdata->lis302dl_bitbang_reg_read)(lis,
+							    LIS302DL_REG_CTRL1);
+	local_irq_restore(flags);
 
 	return sprintf(buf, "%s\n", ctrl1 & LIS302DL_CTRL1_FS ? "9.2" : "2.3");
 }
@@ -209,12 +169,18 @@ static ssize_t set_scale(struct device *dev, struct device_attribute *attr,
 			 const char *buf, size_t count)
 {
 	struct lis302dl_info *lis = dev_get_drvdata(dev);
+	unsigned long flags;
+
+	local_irq_save(flags);
 
 	if (!strcmp(buf, "9.2\n"))
-		reg_set_bit_mask(lis, LIS302DL_REG_CTRL1, LIS302DL_CTRL1_FS,
+		__reg_set_bit_mask(lis, LIS302DL_REG_CTRL1, LIS302DL_CTRL1_FS,
 				 LIS302DL_CTRL1_FS);
 	else
-		reg_set_bit_mask(lis, LIS302DL_REG_CTRL1, LIS302DL_CTRL1_FS, 0);
+		__reg_set_bit_mask(lis, LIS302DL_REG_CTRL1, LIS302DL_CTRL1_FS,
+									     0);
+
+	local_irq_restore(flags);
 
 	return count;
 }
@@ -222,7 +188,7 @@ static ssize_t set_scale(struct device *dev, struct device_attribute *attr,
 static DEVICE_ATTR(full_scale, S_IRUGO | S_IWUSR, show_scale, set_scale);
 
 static ssize_t lis302dl_dump(struct device *dev, struct device_attribute *attr,
-			  char *buf)
+								      char *buf)
 {
 	struct lis302dl_info *lis = dev_get_drvdata(dev);
 	int n = 0;
@@ -233,7 +199,7 @@ static ssize_t lis302dl_dump(struct device *dev, struct device_attribute *attr,
 	local_irq_save(flags);
 
 	for (n = 0; n < sizeof(reg); n++)
-		reg[n] = reg_read(lis, n);
+		reg[n] = (lis->pdata->lis302dl_bitbang_reg_read)(lis, n);
 
 	local_irq_restore(flags);
 
@@ -248,9 +214,9 @@ static ssize_t lis302dl_dump(struct device *dev, struct device_attribute *attr,
 }
 static DEVICE_ATTR(dump, S_IRUGO, lis302dl_dump, NULL);
 
-static int freefall_ms_to_duration(struct lis302dl_info *lis, int ms)
+static int __freefall_ms_to_duration(struct lis302dl_info *lis, int ms)
 {
-	u_int8_t r = reg_read(lis, LIS302DL_REG_CTRL1);
+	u8 r = (lis->pdata->lis302dl_bitbang_reg_read)(lis, LIS302DL_REG_CTRL1);
 
 	/* If we have 400 ms sampling rate, the stepping is 2.5 ms,
 	 * on 100 ms the stepping is 10ms */
@@ -268,9 +234,9 @@ static int freefall_ms_to_duration(struct lis302dl_info *lis, int ms)
 	return ms / 10;
 }
 
-static int freefall_duration_to_ms(struct lis302dl_info *lis, int duration)
+static int __freefall_duration_to_ms(struct lis302dl_info *lis, int duration)
 {
-	u_int8_t r = reg_read(lis, LIS302DL_REG_CTRL1);
+	u8 r = (lis->pdata->lis302dl_bitbang_reg_read)(lis, LIS302DL_REG_CTRL1);
 
 	if (r & LIS302DL_CTRL1_DR)
 		return (duration * 25) / 10;
@@ -314,18 +280,18 @@ static ssize_t set_freefall_common(int which, struct device *dev,
 		/* Turn off the interrupt */
 		local_irq_save(flags);
 		if (lis->flags & LIS302DL_F_IRQ_WAKE)
-			disable_irq_wake(lis->spi_dev->irq);
-		lis302dl_int_mode(lis->spi_dev, which,
+			disable_irq_wake(lis->pdata->interrupt);
+		__lis302dl_int_mode(lis->dev, which,
 						   LIS302DL_INTMODE_DATA_READY);
 		lis->flags &= ~(flag_mask | LIS302DL_F_IRQ_WAKE);
 
-		reg_write(lis, r_cfg, 0);
-		reg_write(lis, r_ths, 0);
-		reg_write(lis, r_duration, 0);
+		(lis->pdata->lis302dl_bitbang_reg_write)(lis, r_cfg, 0);
+		(lis->pdata->lis302dl_bitbang_reg_write)(lis, r_ths, 0);
+		(lis->pdata->lis302dl_bitbang_reg_write)(lis, r_duration, 0);
 
 		/* Power off unless the input subsystem is using the device */
 		if (!(lis->flags & LIS302DL_F_INPUT_OPEN))
-			reg_set_bit_mask(lis, LIS302DL_REG_CTRL1,
+			__reg_set_bit_mask(lis, LIS302DL_REG_CTRL1,
 							  LIS302DL_CTRL1_PD, 0);
 
 		local_irq_restore(flags);
@@ -337,7 +303,10 @@ static ssize_t set_freefall_common(int which, struct device *dev,
 							      &and_events) != 6)
 		return -EINVAL;
 
-	duration = freefall_ms_to_duration(lis, ms);
+	local_irq_save(flags);
+	duration = __freefall_ms_to_duration(lis, ms);
+	local_irq_save(flags);
+
 	if (duration < 0)
 		return -ERANGE;
 
@@ -355,23 +324,25 @@ static ssize_t set_freefall_common(int which, struct device *dev,
 
 	/* Setup the configuration registers */
 	local_irq_save(flags);
-	reg_write(lis, r_cfg, 0); /* First zero to get to a known state */
-	reg_write(lis, r_cfg,
+	/* First zero to get to a known state */
+	(lis->pdata->lis302dl_bitbang_reg_write)(lis, r_cfg, 0);
+	(lis->pdata->lis302dl_bitbang_reg_write)(lis, r_cfg,
 		(and_events ? LIS302DL_FFWUCFG_AOI : 0) |
 		x_lo | x_hi | y_lo | y_hi | z_lo | z_hi);
-	reg_write(lis, r_ths, threshold & ~LIS302DL_FFWUTHS_DCRM);
-	reg_write(lis, r_duration, duration);
+	(lis->pdata->lis302dl_bitbang_reg_write)(lis, r_ths,
+					    threshold & ~LIS302DL_FFWUTHS_DCRM);
+	(lis->pdata->lis302dl_bitbang_reg_write)(lis, r_duration, duration);
 
 	/* Route the interrupt for wakeup */
-	lis302dl_int_mode(lis->spi_dev, which, intmode);
+	__lis302dl_int_mode(lis->dev, which, intmode);
 
 	/* Power up the device and note that we want to wake up from
 	 * this interrupt */
 	if (!(lis->flags & LIS302DL_F_IRQ_WAKE))
-		enable_irq_wake(lis->spi_dev->irq);
+		enable_irq_wake(lis->pdata->interrupt);
 
 	lis->flags |= flag_mask | LIS302DL_F_IRQ_WAKE;
-	reg_set_bit_mask(lis, LIS302DL_REG_CTRL1, LIS302DL_CTRL1_PD,
+	__reg_set_bit_mask(lis, LIS302DL_REG_CTRL1, LIS302DL_CTRL1_PD,
 			LIS302DL_CTRL1_PD);
 	local_irq_restore(flags);
 
@@ -403,6 +374,8 @@ static ssize_t show_freefall_common(int which, struct device *dev,
 	int r_duration = LIS302DL_REG_FF_WU_DURATION_1;
 	int r_cfg = LIS302DL_REG_FF_WU_CFG_1;
 	int r_src = LIS302DL_REG_FF_WU_SRC_1;
+	unsigned long flags;
+	int ms;
 
 	/* Configure second freefall/wakeup pin */
 	if (which == 2) {
@@ -411,11 +384,15 @@ static ssize_t show_freefall_common(int which, struct device *dev,
 		r_cfg = LIS302DL_REG_FF_WU_CFG_2;
 		r_src = LIS302DL_REG_FF_WU_SRC_2;
 	}
-	config = reg_read(lis, r_cfg);
-	threshold = reg_read(lis, r_ths);
-	duration = reg_read(lis, r_duration);
-	r4 = reg_read(lis, r_src);
-	r5 = reg_read(lis, LIS302DL_REG_CTRL3);
+
+	local_irq_save(flags);
+	config = (lis->pdata->lis302dl_bitbang_reg_read)(lis, r_cfg);
+	threshold = (lis->pdata->lis302dl_bitbang_reg_read)(lis, r_ths);
+	duration = (lis->pdata->lis302dl_bitbang_reg_read)(lis, r_duration);
+	r4 = (lis->pdata->lis302dl_bitbang_reg_read)(lis, r_src);
+	r5 = (lis->pdata->lis302dl_bitbang_reg_read)(lis, LIS302DL_REG_CTRL3);
+	ms = __freefall_duration_to_ms(lis, duration);
+	local_irq_restore(flags);
 
 	/* All events off? */
 	if ((config & (LIS302DL_FFWUCFG_XLIE | LIS302DL_FFWUCFG_XHIE |
@@ -423,13 +400,14 @@ static ssize_t show_freefall_common(int which, struct device *dev,
 			LIS302DL_FFWUCFG_ZLIE | LIS302DL_FFWUCFG_ZHIE)) == 0)
 		return sprintf(buf, "off\n");
 
+
 	return sprintf(buf,
 			"%s events, %s interrupt, duration %d, threshold %d, "
 			"enabled: %s %s %s %s %s %s\n",
 			(config & LIS302DL_FFWUCFG_AOI) == 0 ? "or" : "and",
 			(config & LIS302DL_FFWUCFG_LIR) == 0 ?
 							"don't latch" : "latch",
-			freefall_duration_to_ms(lis, duration), threshold,
+			ms, threshold,
 			(config & LIS302DL_FFWUCFG_XLIE) == 0 ? "---" : "xlo",
 			(config & LIS302DL_FFWUCFG_XHIE) == 0 ? "---" : "xhi",
 			(config & LIS302DL_FFWUCFG_YLIE) == 0 ? "---" : "ylo",
@@ -480,14 +458,15 @@ static int lis302dl_input_open(struct input_dev *inp)
 
 	local_irq_save(flags);
 	/* make sure we're powered up and generate data ready */
-	reg_set_bit_mask(lis, LIS302DL_REG_CTRL1, ctrl1, ctrl1);
-	local_irq_restore(flags);
+	__reg_set_bit_mask(lis, LIS302DL_REG_CTRL1, ctrl1, ctrl1);
 
 	lis->flags |= LIS302DL_F_INPUT_OPEN;
 
 	/* kick it off -- since we are edge triggered, if we missed the edge
 	 * permanent low interrupt is death for us */
-	(lis->pdata->lis302dl_bitbang_read)(lis);
+	(lis->pdata->lis302dl_bitbang_read_sample)(lis);
+
+	local_irq_restore(flags);
 
 	return 0;
 }
@@ -504,13 +483,13 @@ static void lis302dl_input_close(struct input_dev *inp)
 	/* since the input core already serializes access and makes sure we
 	 * only see close() for the close of the last user, we can safely
 	 * disable the data ready events */
-	reg_set_bit_mask(lis, LIS302DL_REG_CTRL1, ctrl1, 0x00);
+	__reg_set_bit_mask(lis, LIS302DL_REG_CTRL1, ctrl1, 0x00);
 	lis->flags &= ~LIS302DL_F_INPUT_OPEN;
 
 	/* however, don't power down the whole device if still needed */
 	if (!(lis->flags & LIS302DL_F_WUP_FF ||
 	      lis->flags & LIS302DL_F_WUP_CLICK)) {
-		reg_set_bit_mask(lis, LIS302DL_REG_CTRL1, LIS302DL_CTRL1_PD,
+		__reg_set_bit_mask(lis, LIS302DL_REG_CTRL1, LIS302DL_CTRL1_PD,
 				 0x00);
 	}
 	local_irq_restore(flags);
@@ -524,23 +503,23 @@ static int __lis302dl_reset_device(struct lis302dl_info *lis)
 {
 	int timeout = 10;
 
-	reg_write(lis, LIS302DL_REG_CTRL2, LIS302DL_CTRL2_BOOT |
-							    LIS302DL_CTRL2_FDS);
+	(lis->pdata->lis302dl_bitbang_reg_write)(lis, LIS302DL_REG_CTRL2,
+				      LIS302DL_CTRL2_BOOT | LIS302DL_CTRL2_FDS);
 
-	while ((reg_read(lis, LIS302DL_REG_CTRL2) & LIS302DL_CTRL2_BOOT) &&
-								    (timeout--))
+	while (((lis->pdata->lis302dl_bitbang_reg_read)(lis, LIS302DL_REG_CTRL2)
+					  & LIS302DL_CTRL2_BOOT) && (timeout--))
 		mdelay(1);
 
 	return !!(timeout < 0);
 }
 
-static int __devinit lis302dl_probe(struct spi_device *spi)
+static int __devinit lis302dl_probe(struct platform_device *pdev)
 {
 	int rc;
 	struct lis302dl_info *lis;
 	u_int8_t wai;
 	unsigned long flags;
-	struct lis302dl_platform_data *pdata;
+	struct lis302dl_platform_data *pdata = pdev->dev.platform_data;
 
 	lis = kzalloc(sizeof(*lis), GFP_KERNEL);
 	if (!lis)
@@ -548,38 +527,34 @@ static int __devinit lis302dl_probe(struct spi_device *spi)
 
 	local_irq_save(flags);
 
-	mutex_init(&lis->lock);
-	lis->spi_dev = spi;
+	lis->dev = &pdev->dev;
 
-	spi_set_drvdata(spi, lis);
+	dev_set_drvdata(lis->dev, lis);
 
-	pdata = spi->dev.platform_data;
+	lis->pdata = pdata;
 
-	rc = spi_setup(spi);
-	if (rc < 0) {
-		dev_err(&spi->dev, "error during spi_setup\n");
-		dev_set_drvdata(&spi->dev, NULL);
-		goto bail_free_lis;
-	}
+	/* Configure our IO */
+	(lis->pdata->lis302dl_suspend_io)(lis, 1);
 
-	wai = reg_read(lis, LIS302DL_REG_WHO_AM_I);
+	wai = (lis->pdata->lis302dl_bitbang_reg_read)(lis,
+							 LIS302DL_REG_WHO_AM_I);
 	if (wai != LIS302DL_WHO_AM_I_MAGIC) {
-		dev_err(&spi->dev, "unknown who_am_i signature 0x%02x\n", wai);
-		dev_set_drvdata(&spi->dev, NULL);
+		dev_err(lis->dev, "unknown who_am_i signature 0x%02x\n", wai);
+		dev_set_drvdata(lis->dev, NULL);
 		rc = -ENODEV;
 		goto bail_free_lis;
 	}
 
-	rc = sysfs_create_group(&spi->dev.kobj, &lis302dl_attr_group);
+	rc = sysfs_create_group(&lis->dev->kobj, &lis302dl_attr_group);
 	if (rc) {
-		dev_err(&spi->dev, "error creating sysfs group\n");
+		dev_err(lis->dev, "error creating sysfs group\n");
 		goto bail_free_lis;
 	}
 
 	/* initialize input layer details */
 	lis->input_dev = input_allocate_device();
 	if (!lis->input_dev) {
-		dev_err(&spi->dev, "Unable to allocate input device\n");
+		dev_err(lis->dev, "Unable to allocate input device\n");
 		goto bail_sysfs;
 	}
 
@@ -601,57 +576,64 @@ static int __devinit lis302dl_probe(struct spi_device *spi)
 
 	rc = input_register_device(lis->input_dev);
 	if (rc) {
-		dev_err(&spi->dev, "error %d registering input device\n", rc);
+		dev_err(lis->dev, "error %d registering input device\n", rc);
 		goto bail_inp_dev;
 	}
 
 	if (__lis302dl_reset_device(lis))
-		dev_err(&spi->dev, "device BOOT reload failed\n");
+		dev_err(lis->dev, "device BOOT reload failed\n");
 
 	/* force us powered */
-	reg_write(lis, LIS302DL_REG_CTRL1, LIS302DL_CTRL1_PD |
-					   LIS302DL_CTRL1_Xen |
-					   LIS302DL_CTRL1_Yen |
-					   LIS302DL_CTRL1_Zen);
+	(lis->pdata->lis302dl_bitbang_reg_write)(lis, LIS302DL_REG_CTRL1,
+						      LIS302DL_CTRL1_PD |
+						      LIS302DL_CTRL1_Xen |
+						      LIS302DL_CTRL1_Yen |
+						      LIS302DL_CTRL1_Zen);
 	mdelay(1);
 
-	reg_write(lis, LIS302DL_REG_CTRL2, 0);
-	reg_write(lis, LIS302DL_REG_CTRL3, LIS302DL_CTRL3_PP_OD |
-							    LIS302DL_CTRL3_IHL);
-	reg_write(lis, LIS302DL_REG_FF_WU_THS_1, 0x0);
-	reg_write(lis, LIS302DL_REG_FF_WU_DURATION_1, 0x00);
-	reg_write(lis, LIS302DL_REG_FF_WU_CFG_1, 0x0);
+	(lis->pdata->lis302dl_bitbang_reg_write)(lis, LIS302DL_REG_CTRL2, 0);
+	(lis->pdata->lis302dl_bitbang_reg_write)(lis, LIS302DL_REG_CTRL3,
+				     LIS302DL_CTRL3_PP_OD | LIS302DL_CTRL3_IHL);
+	(lis->pdata->lis302dl_bitbang_reg_write)(lis,
+						 LIS302DL_REG_FF_WU_THS_1, 0x0);
+	(lis->pdata->lis302dl_bitbang_reg_write)(lis,
+					   LIS302DL_REG_FF_WU_DURATION_1, 0x00);
+	(lis->pdata->lis302dl_bitbang_reg_write)(lis,
+						 LIS302DL_REG_FF_WU_CFG_1, 0x0);
 
 	/* start off in powered down mode; we power up when someone opens us */
-	reg_write(lis, LIS302DL_REG_CTRL1, LIS302DL_CTRL1_Xen |
-					   LIS302DL_CTRL1_Yen |
-					   LIS302DL_CTRL1_Zen);
+	(lis->pdata->lis302dl_bitbang_reg_write)(lis, LIS302DL_REG_CTRL1,
+							LIS302DL_CTRL1_Xen |
+							LIS302DL_CTRL1_Yen |
+							LIS302DL_CTRL1_Zen);
 
 	if (pdata->open_drain)
 		/* switch interrupt to open collector, active-low */
-		reg_write(lis, LIS302DL_REG_CTRL3, LIS302DL_CTRL3_PP_OD |
-						   LIS302DL_CTRL3_IHL);
+		(lis->pdata->lis302dl_bitbang_reg_write)(lis,
+			LIS302DL_REG_CTRL3, LIS302DL_CTRL3_PP_OD |
+					    LIS302DL_CTRL3_IHL);
 	else
 		/* push-pull, active-low */
-		reg_write(lis, LIS302DL_REG_CTRL3, LIS302DL_CTRL3_IHL);
+		(lis->pdata->lis302dl_bitbang_reg_write)(lis,
+					LIS302DL_REG_CTRL3, LIS302DL_CTRL3_IHL);
 
-	lis302dl_int_mode(spi, 1, LIS302DL_INTMODE_DATA_READY);
-	lis302dl_int_mode(spi, 2, LIS302DL_INTMODE_DATA_READY);
+	__lis302dl_int_mode(lis->dev, 1, LIS302DL_INTMODE_DATA_READY);
+	__lis302dl_int_mode(lis->dev, 2, LIS302DL_INTMODE_DATA_READY);
 
-	reg_read(lis, LIS302DL_REG_STATUS);
-	reg_read(lis, LIS302DL_REG_FF_WU_SRC_1);
-	reg_read(lis, LIS302DL_REG_FF_WU_SRC_2);
-	reg_read(lis, LIS302DL_REG_CLICK_SRC);
+	(lis->pdata->lis302dl_bitbang_reg_read)(lis, LIS302DL_REG_STATUS);
+	(lis->pdata->lis302dl_bitbang_reg_read)(lis, LIS302DL_REG_FF_WU_SRC_1);
+	(lis->pdata->lis302dl_bitbang_reg_read)(lis, LIS302DL_REG_FF_WU_SRC_2);
+	(lis->pdata->lis302dl_bitbang_reg_read)(lis, LIS302DL_REG_CLICK_SRC);
 
-	dev_info(&spi->dev, "Found %s\n", pdata->name);
+	dev_info(lis->dev, "Found %s\n", pdata->name);
 
 	lis->pdata = pdata;
 
-	rc = request_irq(lis->spi_dev->irq, lis302dl_interrupt,
+	rc = request_irq(pdata->interrupt, lis302dl_interrupt,
 			 IRQF_TRIGGER_FALLING, "lis302dl", lis);
 	if (rc < 0) {
-		dev_err(&spi->dev, "error requesting IRQ %d\n",
-			lis->spi_dev->irq);
+		dev_err(lis->dev, "error requesting IRQ %d\n",
+			lis->pdata->interrupt);
 		goto bail_inp_reg;
 	}
 	local_irq_restore(flags);
@@ -662,50 +644,71 @@ bail_inp_reg:
 bail_inp_dev:
 	input_free_device(lis->input_dev);
 bail_sysfs:
-	sysfs_remove_group(&spi->dev.kobj, &lis302dl_attr_group);
+	sysfs_remove_group(&lis->dev->kobj, &lis302dl_attr_group);
 bail_free_lis:
 	kfree(lis);
 	local_irq_restore(flags);
 	return rc;
 }
 
-static int __devexit lis302dl_remove(struct spi_device *spi)
+static int __devexit lis302dl_remove(struct platform_device *pdev)
 {
-	struct lis302dl_info *lis = dev_get_drvdata(&spi->dev);
+	struct lis302dl_info *lis = dev_get_drvdata(&pdev->dev);
 	unsigned long flags;
 
 	/* Reset and power down the device */
 	local_irq_save(flags);
-	reg_write(lis, LIS302DL_REG_CTRL3, 0x00);
-	reg_write(lis, LIS302DL_REG_CTRL2, 0x00);
-	reg_write(lis, LIS302DL_REG_CTRL1, 0x00);
+	(lis->pdata->lis302dl_bitbang_reg_write)(lis, LIS302DL_REG_CTRL3, 0x00);
+	(lis->pdata->lis302dl_bitbang_reg_write)(lis, LIS302DL_REG_CTRL2, 0x00);
+	(lis->pdata->lis302dl_bitbang_reg_write)(lis, LIS302DL_REG_CTRL1, 0x00);
 	local_irq_restore(flags);
 
 	/* Cleanup resources */
-	free_irq(lis->spi_dev->irq, lis);
-	sysfs_remove_group(&spi->dev.kobj, &lis302dl_attr_group);
+	free_irq(lis->pdata->interrupt, lis);
+	sysfs_remove_group(&pdev->dev.kobj, &lis302dl_attr_group);
 	input_unregister_device(lis->input_dev);
 	if (lis->input_dev)
 		input_free_device(lis->input_dev);
-	dev_set_drvdata(&spi->dev, NULL);
+	dev_set_drvdata(lis->dev, NULL);
 	kfree(lis);
 
 	return 0;
 }
 
 #ifdef CONFIG_PM
-static int lis302dl_suspend(struct spi_device *spi, pm_message_t state)
+
+static u8 regs_to_save[] = {
+	LIS302DL_REG_CTRL1,
+	LIS302DL_REG_CTRL2,
+	LIS302DL_REG_CTRL3,
+	LIS302DL_REG_FF_WU_CFG_1,
+	LIS302DL_REG_FF_WU_THS_1,
+	LIS302DL_REG_FF_WU_DURATION_1,
+	LIS302DL_REG_FF_WU_CFG_2,
+	LIS302DL_REG_FF_WU_THS_2,
+	LIS302DL_REG_FF_WU_DURATION_2,
+	LIS302DL_REG_CLICK_CFG,
+	LIS302DL_REG_CLICK_THSY_X,
+	LIS302DL_REG_CLICK_THSZ,
+	LIS302DL_REG_CLICK_TIME_LIMIT,
+	LIS302DL_REG_CLICK_LATENCY,
+	LIS302DL_REG_CLICK_WINDOW,
+
+};
+
+static int lis302dl_suspend(struct platform_device *pdev, pm_message_t state)
 {
-	struct lis302dl_info *lis = dev_get_drvdata(&spi->dev);
+	struct lis302dl_info *lis = dev_get_drvdata(&pdev->dev);
 	unsigned long flags;
 	u_int8_t tmp;
+	int n;
 
 	/* determine if we want to wake up from the accel. */
 	if (lis->flags & LIS302DL_F_WUP_FF ||
 		lis->flags & LIS302DL_F_WUP_CLICK)
 		return 0;
 
-	disable_irq(lis->spi_dev->irq);
+	disable_irq(lis->pdata->interrupt);
 	local_irq_save(flags);
 
 	/*
@@ -718,38 +721,15 @@ static int lis302dl_suspend(struct spi_device *spi, pm_message_t state)
 	(lis->pdata->lis302dl_suspend_io)(lis, 1);
 
 	/* save registers */
-	lis->regs[LIS302DL_REG_CTRL1] = reg_read(lis, LIS302DL_REG_CTRL1);
-	lis->regs[LIS302DL_REG_CTRL2] = reg_read(lis, LIS302DL_REG_CTRL2);
-	lis->regs[LIS302DL_REG_CTRL3] = reg_read(lis, LIS302DL_REG_CTRL3);
-	lis->regs[LIS302DL_REG_FF_WU_CFG_1] =
-				reg_read(lis, LIS302DL_REG_FF_WU_CFG_1);
-	lis->regs[LIS302DL_REG_FF_WU_THS_1] =
-				reg_read(lis, LIS302DL_REG_FF_WU_THS_1);
-	lis->regs[LIS302DL_REG_FF_WU_DURATION_1] =
-				reg_read(lis, LIS302DL_REG_FF_WU_DURATION_1);
-	lis->regs[LIS302DL_REG_FF_WU_CFG_2] =
-				reg_read(lis, LIS302DL_REG_FF_WU_CFG_2);
-	lis->regs[LIS302DL_REG_FF_WU_THS_2] =
-				reg_read(lis, LIS302DL_REG_FF_WU_THS_2);
-	lis->regs[LIS302DL_REG_FF_WU_DURATION_2] =
-				reg_read(lis, LIS302DL_REG_FF_WU_DURATION_2);
-	lis->regs[LIS302DL_REG_CLICK_CFG] =
-				reg_read(lis, LIS302DL_REG_CLICK_CFG);
-	lis->regs[LIS302DL_REG_CLICK_THSY_X] =
-				reg_read(lis, LIS302DL_REG_CLICK_THSY_X);
-	lis->regs[LIS302DL_REG_CLICK_THSZ] =
-				reg_read(lis, LIS302DL_REG_CLICK_THSZ);
-	lis->regs[LIS302DL_REG_CLICK_TIME_LIMIT] =
-				reg_read(lis, LIS302DL_REG_CLICK_TIME_LIMIT);
-	lis->regs[LIS302DL_REG_CLICK_LATENCY] =
-				reg_read(lis, LIS302DL_REG_CLICK_LATENCY);
-	lis->regs[LIS302DL_REG_CLICK_WINDOW] =
-				reg_read(lis, LIS302DL_REG_CLICK_WINDOW);
+	for (n = 0; n < ARRAY_SIZE(regs_to_save); n++)
+		lis->regs[regs_to_save[n]] =
+			(lis->pdata->lis302dl_bitbang_reg_read)(lis,
+							       regs_to_save[n]);
 
 	/* power down */
-	tmp = reg_read(lis, LIS302DL_REG_CTRL1);
+	tmp = (lis->pdata->lis302dl_bitbang_reg_read)(lis, LIS302DL_REG_CTRL1);
 	tmp &= ~LIS302DL_CTRL1_PD;
-	reg_write(lis, LIS302DL_REG_CTRL1, tmp);
+	(lis->pdata->lis302dl_bitbang_reg_write)(lis, LIS302DL_REG_CTRL1, tmp);
 
 	/* place our IO to the device in sleep-compatible states */
 	(lis->pdata->lis302dl_suspend_io)(lis, 0);
@@ -759,10 +739,11 @@ static int lis302dl_suspend(struct spi_device *spi, pm_message_t state)
 	return 0;
 }
 
-static int lis302dl_resume(struct spi_device *spi)
+static int lis302dl_resume(struct platform_device *pdev)
 {
-	struct lis302dl_info *lis = dev_get_drvdata(&spi->dev);
+	struct lis302dl_info *lis = dev_get_drvdata(&pdev->dev);
 	unsigned long flags;
+	int n;
 
 	if (lis->flags & LIS302DL_F_WUP_FF ||
 		lis->flags & LIS302DL_F_WUP_CLICK)
@@ -774,50 +755,28 @@ static int lis302dl_resume(struct spi_device *spi)
 	(lis->pdata->lis302dl_suspend_io)(lis, 1);
 
 	/* resume from powerdown first! */
-	reg_write(lis, LIS302DL_REG_CTRL1, LIS302DL_CTRL1_PD |
-					   LIS302DL_CTRL1_Xen |
-					   LIS302DL_CTRL1_Yen |
-					   LIS302DL_CTRL1_Zen);
+	(lis->pdata->lis302dl_bitbang_reg_write)(lis, LIS302DL_REG_CTRL1,
+						      LIS302DL_CTRL1_PD |
+						      LIS302DL_CTRL1_Xen |
+						      LIS302DL_CTRL1_Yen |
+						      LIS302DL_CTRL1_Zen);
 	mdelay(1);
 
 	if (__lis302dl_reset_device(lis))
-		dev_err(&spi->dev, "device BOOT reload failed\n");
+		dev_err(&pdev->dev, "device BOOT reload failed\n");
 
-	/* restore registers after resume */
-	reg_write(lis, LIS302DL_REG_CTRL1, lis->regs[LIS302DL_REG_CTRL1] |
-						LIS302DL_CTRL1_PD |
+	lis->regs[LIS302DL_REG_CTRL1] |=	LIS302DL_CTRL1_PD |
 						LIS302DL_CTRL1_Xen |
 						LIS302DL_CTRL1_Yen |
-						LIS302DL_CTRL1_Zen);
-	reg_write(lis, LIS302DL_REG_CTRL2, lis->regs[LIS302DL_REG_CTRL2]);
-	reg_write(lis, LIS302DL_REG_CTRL3, lis->regs[LIS302DL_REG_CTRL3]);
-	reg_write(lis, LIS302DL_REG_FF_WU_CFG_1,
-		  lis->regs[LIS302DL_REG_FF_WU_CFG_1]);
-	reg_write(lis, LIS302DL_REG_FF_WU_THS_1,
-		  lis->regs[LIS302DL_REG_FF_WU_THS_1]);
-	reg_write(lis, LIS302DL_REG_FF_WU_DURATION_1,
-		  lis->regs[LIS302DL_REG_FF_WU_DURATION_1]);
-	reg_write(lis, LIS302DL_REG_FF_WU_CFG_2,
-		  lis->regs[LIS302DL_REG_FF_WU_CFG_2]);
-	reg_write(lis, LIS302DL_REG_FF_WU_THS_2,
-		  lis->regs[LIS302DL_REG_FF_WU_THS_2]);
-	reg_write(lis, LIS302DL_REG_FF_WU_DURATION_2,
-		  lis->regs[LIS302DL_REG_FF_WU_DURATION_2]);
-	reg_write(lis, LIS302DL_REG_CLICK_CFG,
-		  lis->regs[LIS302DL_REG_CLICK_CFG]);
-	reg_write(lis, LIS302DL_REG_CLICK_THSY_X,
-		  lis->regs[LIS302DL_REG_CLICK_THSY_X]);
-	reg_write(lis, LIS302DL_REG_CLICK_THSZ,
-		  lis->regs[LIS302DL_REG_CLICK_THSZ]);
-	reg_write(lis, LIS302DL_REG_CLICK_TIME_LIMIT,
-		  lis->regs[LIS302DL_REG_CLICK_TIME_LIMIT]);
-	reg_write(lis, LIS302DL_REG_CLICK_LATENCY,
-		  lis->regs[LIS302DL_REG_CLICK_LATENCY]);
-	reg_write(lis, LIS302DL_REG_CLICK_WINDOW,
-		  lis->regs[LIS302DL_REG_CLICK_WINDOW]);
+						LIS302DL_CTRL1_Zen;
+
+	/* restore registers after resume */
+	for (n = 0; n < ARRAY_SIZE(regs_to_save); n++)
+		(lis->pdata->lis302dl_bitbang_reg_write)(lis,
+				   regs_to_save[n], lis->regs[regs_to_save[n]]);
 
 	local_irq_restore(flags);
-	enable_irq(lis->spi_dev->irq);
+	enable_irq(lis->pdata->interrupt);
 
 	return 0;
 }
@@ -826,7 +785,7 @@ static int lis302dl_resume(struct spi_device *spi)
 #define lis302dl_resume		NULL
 #endif
 
-static struct spi_driver lis302dl_driver = {
+static struct platform_driver lis302dl_driver = {
 	.driver = {
 		.name	= "lis302dl",
 		.owner	= THIS_MODULE,
@@ -838,14 +797,14 @@ static struct spi_driver lis302dl_driver = {
 	.resume	 = lis302dl_resume,
 };
 
-static int __init lis302dl_init(void)
+static int __devinit lis302dl_init(void)
 {
-	return spi_register_driver(&lis302dl_driver);
+	return platform_driver_register(&lis302dl_driver);
 }
 
 static void __exit lis302dl_exit(void)
 {
-	spi_unregister_driver(&lis302dl_driver);
+	platform_driver_unregister(&lis302dl_driver);
 }
 
 MODULE_AUTHOR("Harald Welte <laforge@openmoko.org>");
diff --git a/include/linux/lis302dl.h b/include/linux/lis302dl.h
index 7daa8b3..4578db4 100644
--- a/include/linux/lis302dl.h
+++ b/include/linux/lis302dl.h
@@ -15,15 +15,18 @@ struct lis302dl_platform_data {
 	unsigned long pin_mosi;
 	unsigned long pin_miso;
 	int open_drain;
-	void (*lis302dl_bitbang_read)(struct lis302dl_info *);
+	int interrupt;
+	void (*lis302dl_bitbang_read_sample)(struct lis302dl_info *);
 	void (*lis302dl_suspend_io)(struct lis302dl_info *, int resuming);
+	int (*lis302dl_bitbang_reg_read)(struct lis302dl_info *, u8 reg);
+	void (*lis302dl_bitbang_reg_write)(struct lis302dl_info *, u8 reg,
+									u8 val);
 };
 
 struct lis302dl_info {
 	struct lis302dl_platform_data *pdata;
-	struct spi_device *spi_dev;
+	struct device *dev;
 	struct input_dev *input_dev;
-	struct mutex lock;
 	unsigned int flags;
 	u_int8_t regs[0x40];
 };
-- 
1.5.6.5