hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/drivers/iio/accel/bma180.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * bma180.c - IIO driver for Bosch BMA180 triaxial acceleration sensor
34 *
....@@ -5,13 +6,11 @@
56 *
67 * Support for BMA250 (c) Peter Meerwald <pmeerw@pmeerw.net>
78 *
8
- * This file is subject to the terms and conditions of version 2 of
9
- * the GNU General Public License. See the file COPYING in the main
10
- * directory of this archive for more details.
11
- *
129 * SPI is not supported by driver
10
+ * BMA023/BMA150/SMB380: 7-bit I2C slave address 0x38
1311 * BMA180: 7-bit I2C slave address 0x40 or 0x41
1412 * BMA250: 7-bit I2C slave address 0x18 or 0x19
13
+ * BMA254: 7-bit I2C slave address 0x18 or 0x19
1514 */
1615
1716 #include <linux/module.h>
....@@ -21,6 +20,7 @@
2120 #include <linux/of_device.h>
2221 #include <linux/of.h>
2322 #include <linux/bitops.h>
23
+#include <linux/regulator/consumer.h>
2424 #include <linux/slab.h>
2525 #include <linux/string.h>
2626 #include <linux/iio/iio.h>
....@@ -34,19 +34,24 @@
3434 #define BMA180_IRQ_NAME "bma180_event"
3535
3636 enum chip_ids {
37
+ BMA023,
38
+ BMA150,
3739 BMA180,
3840 BMA250,
41
+ BMA254,
3942 };
4043
4144 struct bma180_data;
4245
4346 struct bma180_part_info {
47
+ u8 chip_id;
4448 const struct iio_chan_spec *channels;
4549 unsigned int num_channels;
4650 const int *scale_table;
4751 unsigned int num_scales;
4852 const int *bw_table;
4953 unsigned int num_bw;
54
+ int temp_offset;
5055
5156 u8 int_reset_reg, int_reset_mask;
5257 u8 sleep_reg, sleep_mask;
....@@ -54,13 +59,26 @@
5459 u8 scale_reg, scale_mask;
5560 u8 power_reg, power_mask, lowpower_val;
5661 u8 int_enable_reg, int_enable_mask;
57
- u8 softreset_reg;
62
+ u8 int_map_reg, int_enable_dataready_int1_mask;
63
+ u8 softreset_reg, softreset_val;
5864
5965 int (*chip_config)(struct bma180_data *data);
6066 void (*chip_disable)(struct bma180_data *data);
6167 };
6268
6369 /* Register set */
70
+#define BMA023_CTRL_REG0 0x0a
71
+#define BMA023_CTRL_REG1 0x0b
72
+#define BMA023_CTRL_REG2 0x14
73
+#define BMA023_CTRL_REG3 0x15
74
+
75
+#define BMA023_RANGE_MASK GENMASK(4, 3) /* Range of accel values */
76
+#define BMA023_BW_MASK GENMASK(2, 0) /* Accel bandwidth */
77
+#define BMA023_SLEEP BIT(0)
78
+#define BMA023_INT_RESET_MASK BIT(6)
79
+#define BMA023_NEW_DATA_INT BIT(5) /* Intr every new accel data is ready */
80
+#define BMA023_RESET_VAL BIT(1)
81
+
6482 #define BMA180_CHIP_ID 0x00 /* Need to distinguish BMA180 from other */
6583 #define BMA180_ACC_X_LSB 0x02 /* First of 6 registers of accel data */
6684 #define BMA180_TEMP 0x08
....@@ -91,7 +109,10 @@
91109 /* We have to write this value in reset register to do soft reset */
92110 #define BMA180_RESET_VAL 0xb6
93111
112
+#define BMA023_ID_REG_VAL 0x02
94113 #define BMA180_ID_REG_VAL 0x03
114
+#define BMA250_ID_REG_VAL 0x03
115
+#define BMA254_ID_REG_VAL 0xfa /* 250 decimal */
95116
96117 /* Chip power modes */
97118 #define BMA180_LOW_POWER 0x03
....@@ -113,10 +134,31 @@
113134 #define BMA250_INT1_DATA_MASK BIT(0)
114135 #define BMA250_INT_RESET_MASK BIT(7) /* Reset pending interrupts */
115136
137
+#define BMA254_RANGE_REG 0x0f
138
+#define BMA254_BW_REG 0x10
139
+#define BMA254_POWER_REG 0x11
140
+#define BMA254_RESET_REG 0x14
141
+#define BMA254_INT_ENABLE_REG 0x17
142
+#define BMA254_INT_MAP_REG 0x1a
143
+#define BMA254_INT_RESET_REG 0x21
144
+
145
+#define BMA254_RANGE_MASK GENMASK(3, 0) /* Range of accel values */
146
+#define BMA254_BW_MASK GENMASK(4, 0) /* Accel bandwidth */
147
+#define BMA254_BW_OFFSET 8
148
+#define BMA254_SUSPEND_MASK BIT(7) /* chip will sleep */
149
+#define BMA254_LOWPOWER_MASK BIT(6)
150
+#define BMA254_DATA_INTEN_MASK BIT(4)
151
+#define BMA254_INT2_DATA_MASK BIT(7)
152
+#define BMA254_INT1_DATA_MASK BIT(0)
153
+#define BMA254_INT_RESET_MASK BIT(7) /* Reset pending interrupts */
154
+
116155 struct bma180_data {
156
+ struct regulator *vdd_supply;
157
+ struct regulator *vddio_supply;
117158 struct i2c_client *client;
118159 struct iio_trigger *trig;
119160 const struct bma180_part_info *part_info;
161
+ struct iio_mount_matrix orientation;
120162 struct mutex mutex;
121163 bool sleep_state;
122164 int scale;
....@@ -136,11 +178,14 @@
136178 TEMP
137179 };
138180
181
+static int bma023_bw_table[] = { 25, 50, 100, 190, 375, 750, 1500 }; /* Hz */
182
+static int bma023_scale_table[] = { 2452, 4903, 9709, };
183
+
139184 static int bma180_bw_table[] = { 10, 20, 40, 75, 150, 300 }; /* Hz */
140185 static int bma180_scale_table[] = { 1275, 1863, 2452, 3727, 4903, 9709, 19417 };
141186
142
-static int bma250_bw_table[] = { 8, 16, 31, 63, 125, 250 }; /* Hz */
143
-static int bma250_scale_table[] = { 0, 0, 0, 38344, 0, 76590, 0, 0, 153180, 0,
187
+static int bma25x_bw_table[] = { 8, 16, 31, 63, 125, 250 }; /* Hz */
188
+static int bma25x_scale_table[] = { 0, 0, 0, 38344, 0, 76590, 0, 0, 153180, 0,
144189 0, 0, 306458 };
145190
146191 static int bma180_get_data_reg(struct bma180_data *data, enum bma180_chan chan)
....@@ -300,7 +345,8 @@
300345 static int bma180_soft_reset(struct bma180_data *data)
301346 {
302347 int ret = i2c_smbus_write_byte_data(data->client,
303
- data->part_info->softreset_reg, BMA180_RESET_VAL);
348
+ data->part_info->softreset_reg,
349
+ data->part_info->softreset_val);
304350
305351 if (ret)
306352 dev_err(&data->client->dev, "failed to reset the chip\n");
....@@ -315,8 +361,11 @@
315361
316362 if (ret < 0)
317363 return ret;
318
- if (ret != BMA180_ID_REG_VAL)
364
+ if (ret != data->part_info->chip_id) {
365
+ dev_err(&data->client->dev, "wrong chip ID %d expected %d\n",
366
+ ret, data->part_info->chip_id);
319367 return -ENODEV;
368
+ }
320369
321370 ret = bma180_soft_reset(data);
322371 if (ret)
....@@ -327,17 +376,37 @@
327376 */
328377 msleep(20);
329378
330
- ret = bma180_set_new_data_intr_state(data, false);
331
- if (ret)
332
- return ret;
379
+ return bma180_set_new_data_intr_state(data, false);
380
+}
333381
334
- return bma180_set_pmode(data, false);
382
+static int bma023_chip_config(struct bma180_data *data)
383
+{
384
+ int ret = bma180_chip_init(data);
385
+
386
+ if (ret)
387
+ goto err;
388
+
389
+ ret = bma180_set_bw(data, 50); /* 50 Hz */
390
+ if (ret)
391
+ goto err;
392
+ ret = bma180_set_scale(data, 2452); /* 2 G */
393
+ if (ret)
394
+ goto err;
395
+
396
+ return 0;
397
+
398
+err:
399
+ dev_err(&data->client->dev, "failed to config the chip\n");
400
+ return ret;
335401 }
336402
337403 static int bma180_chip_config(struct bma180_data *data)
338404 {
339405 int ret = bma180_chip_init(data);
340406
407
+ if (ret)
408
+ goto err;
409
+ ret = bma180_set_pmode(data, false);
341410 if (ret)
342411 goto err;
343412 ret = bma180_set_bits(data, BMA180_CTRL_REG0, BMA180_DIS_WAKE_UP, 1);
....@@ -363,10 +432,13 @@
363432 return ret;
364433 }
365434
366
-static int bma250_chip_config(struct bma180_data *data)
435
+static int bma25x_chip_config(struct bma180_data *data)
367436 {
368437 int ret = bma180_chip_init(data);
369438
439
+ if (ret)
440
+ goto err;
441
+ ret = bma180_set_pmode(data, false);
370442 if (ret)
371443 goto err;
372444 ret = bma180_set_bw(data, 16); /* 16 Hz */
....@@ -375,8 +447,12 @@
375447 ret = bma180_set_scale(data, 38344); /* 2 G */
376448 if (ret)
377449 goto err;
378
- ret = bma180_set_bits(data, BMA250_INT_MAP_REG,
379
- BMA250_INT1_DATA_MASK, 1);
450
+ /*
451
+ * This enables dataready interrupt on the INT1 pin
452
+ * FIXME: support using the INT2 pin
453
+ */
454
+ ret = bma180_set_bits(data, data->part_info->int_map_reg,
455
+ data->part_info->int_enable_dataready_int1_mask, 1);
380456 if (ret)
381457 goto err;
382458
....@@ -385,6 +461,17 @@
385461 err:
386462 dev_err(&data->client->dev, "failed to config the chip\n");
387463 return ret;
464
+}
465
+
466
+static void bma023_chip_disable(struct bma180_data *data)
467
+{
468
+ if (bma180_set_sleep_state(data, true))
469
+ goto err;
470
+
471
+ return;
472
+
473
+err:
474
+ dev_err(&data->client->dev, "failed to disable the chip\n");
388475 }
389476
390477 static void bma180_chip_disable(struct bma180_data *data)
....@@ -402,7 +489,7 @@
402489 dev_err(&data->client->dev, "failed to disable the chip\n");
403490 }
404491
405
-static void bma250_chip_disable(struct bma180_data *data)
492
+static void bma25x_chip_disable(struct bma180_data *data)
406493 {
407494 if (bma180_set_new_data_intr_state(data, false))
408495 goto err;
....@@ -486,8 +573,12 @@
486573 iio_device_release_direct_mode(indio_dev);
487574 if (ret < 0)
488575 return ret;
489
- *val = sign_extend32(ret >> chan->scan_type.shift,
490
- chan->scan_type.realbits - 1);
576
+ if (chan->scan_type.sign == 's') {
577
+ *val = sign_extend32(ret >> chan->scan_type.shift,
578
+ chan->scan_type.realbits - 1);
579
+ } else {
580
+ *val = ret;
581
+ }
491582 return IIO_VAL_INT;
492583 case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY:
493584 *val = data->bw;
....@@ -505,7 +596,7 @@
505596 return -EINVAL;
506597 }
507598 case IIO_CHAN_INFO_OFFSET:
508
- *val = 48; /* 0 LSB @ 24 degree C */
599
+ *val = data->part_info->temp_offset;
509600 return IIO_VAL_INT;
510601 default:
511602 return -EINVAL;
....@@ -567,6 +658,15 @@
567658 return ret;
568659 }
569660
661
+static const struct iio_mount_matrix *
662
+bma180_accel_get_mount_matrix(const struct iio_dev *indio_dev,
663
+ const struct iio_chan_spec *chan)
664
+{
665
+ struct bma180_data *data = iio_priv(indio_dev);
666
+
667
+ return &data->orientation;
668
+}
669
+
570670 static const struct iio_enum bma180_power_mode_enum = {
571671 .items = bma180_power_modes,
572672 .num_items = ARRAY_SIZE(bma180_power_modes),
....@@ -574,11 +674,46 @@
574674 .set = bma180_set_power_mode,
575675 };
576676
577
-static const struct iio_chan_spec_ext_info bma180_ext_info[] = {
578
- IIO_ENUM("power_mode", true, &bma180_power_mode_enum),
579
- IIO_ENUM_AVAILABLE("power_mode", &bma180_power_mode_enum),
580
- { },
677
+static const struct iio_chan_spec_ext_info bma023_ext_info[] = {
678
+ IIO_MOUNT_MATRIX(IIO_SHARED_BY_DIR, bma180_accel_get_mount_matrix),
679
+ { }
581680 };
681
+
682
+static const struct iio_chan_spec_ext_info bma180_ext_info[] = {
683
+ IIO_ENUM("power_mode", IIO_SHARED_BY_TYPE, &bma180_power_mode_enum),
684
+ IIO_ENUM_AVAILABLE("power_mode", &bma180_power_mode_enum),
685
+ IIO_MOUNT_MATRIX(IIO_SHARED_BY_DIR, bma180_accel_get_mount_matrix),
686
+ { }
687
+};
688
+
689
+#define BMA023_ACC_CHANNEL(_axis, _bits) { \
690
+ .type = IIO_ACCEL, \
691
+ .modified = 1, \
692
+ .channel2 = IIO_MOD_##_axis, \
693
+ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
694
+ .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \
695
+ BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), \
696
+ .scan_index = AXIS_##_axis, \
697
+ .scan_type = { \
698
+ .sign = 's', \
699
+ .realbits = _bits, \
700
+ .storagebits = 16, \
701
+ .shift = 16 - _bits, \
702
+ }, \
703
+ .ext_info = bma023_ext_info, \
704
+}
705
+
706
+#define BMA150_TEMP_CHANNEL { \
707
+ .type = IIO_TEMP, \
708
+ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
709
+ BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_OFFSET), \
710
+ .scan_index = TEMP, \
711
+ .scan_type = { \
712
+ .sign = 'u', \
713
+ .realbits = 8, \
714
+ .storagebits = 16, \
715
+ }, \
716
+}
582717
583718 #define BMA180_ACC_CHANNEL(_axis, _bits) { \
584719 .type = IIO_ACCEL, \
....@@ -609,6 +744,21 @@
609744 }, \
610745 }
611746
747
+static const struct iio_chan_spec bma023_channels[] = {
748
+ BMA023_ACC_CHANNEL(X, 10),
749
+ BMA023_ACC_CHANNEL(Y, 10),
750
+ BMA023_ACC_CHANNEL(Z, 10),
751
+ IIO_CHAN_SOFT_TIMESTAMP(4),
752
+};
753
+
754
+static const struct iio_chan_spec bma150_channels[] = {
755
+ BMA023_ACC_CHANNEL(X, 10),
756
+ BMA023_ACC_CHANNEL(Y, 10),
757
+ BMA023_ACC_CHANNEL(Z, 10),
758
+ BMA150_TEMP_CHANNEL,
759
+ IIO_CHAN_SOFT_TIMESTAMP(4),
760
+};
761
+
612762 static const struct iio_chan_spec bma180_channels[] = {
613763 BMA180_ACC_CHANNEL(X, 14),
614764 BMA180_ACC_CHANNEL(Y, 14),
....@@ -625,14 +775,81 @@
625775 IIO_CHAN_SOFT_TIMESTAMP(4),
626776 };
627777
778
+static const struct iio_chan_spec bma254_channels[] = {
779
+ BMA180_ACC_CHANNEL(X, 12),
780
+ BMA180_ACC_CHANNEL(Y, 12),
781
+ BMA180_ACC_CHANNEL(Z, 12),
782
+ BMA180_TEMP_CHANNEL,
783
+ IIO_CHAN_SOFT_TIMESTAMP(4),
784
+};
785
+
628786 static const struct bma180_part_info bma180_part_info[] = {
787
+ [BMA023] = {
788
+ .chip_id = BMA023_ID_REG_VAL,
789
+ .channels = bma023_channels,
790
+ .num_channels = ARRAY_SIZE(bma023_channels),
791
+ .scale_table = bma023_scale_table,
792
+ .num_scales = ARRAY_SIZE(bma023_scale_table),
793
+ .bw_table = bma023_bw_table,
794
+ .num_bw = ARRAY_SIZE(bma023_bw_table),
795
+ /* No temperature channel */
796
+ .temp_offset = 0,
797
+ .int_reset_reg = BMA023_CTRL_REG0,
798
+ .int_reset_mask = BMA023_INT_RESET_MASK,
799
+ .sleep_reg = BMA023_CTRL_REG0,
800
+ .sleep_mask = BMA023_SLEEP,
801
+ .bw_reg = BMA023_CTRL_REG2,
802
+ .bw_mask = BMA023_BW_MASK,
803
+ .scale_reg = BMA023_CTRL_REG2,
804
+ .scale_mask = BMA023_RANGE_MASK,
805
+ /* No power mode on bma023 */
806
+ .power_reg = 0,
807
+ .power_mask = 0,
808
+ .lowpower_val = 0,
809
+ .int_enable_reg = BMA023_CTRL_REG3,
810
+ .int_enable_mask = BMA023_NEW_DATA_INT,
811
+ .softreset_reg = BMA023_CTRL_REG0,
812
+ .softreset_val = BMA023_RESET_VAL,
813
+ .chip_config = bma023_chip_config,
814
+ .chip_disable = bma023_chip_disable,
815
+ },
816
+ [BMA150] = {
817
+ .chip_id = BMA023_ID_REG_VAL,
818
+ .channels = bma150_channels,
819
+ .num_channels = ARRAY_SIZE(bma150_channels),
820
+ .scale_table = bma023_scale_table,
821
+ .num_scales = ARRAY_SIZE(bma023_scale_table),
822
+ .bw_table = bma023_bw_table,
823
+ .num_bw = ARRAY_SIZE(bma023_bw_table),
824
+ .temp_offset = -60, /* 0 LSB @ -30 degree C */
825
+ .int_reset_reg = BMA023_CTRL_REG0,
826
+ .int_reset_mask = BMA023_INT_RESET_MASK,
827
+ .sleep_reg = BMA023_CTRL_REG0,
828
+ .sleep_mask = BMA023_SLEEP,
829
+ .bw_reg = BMA023_CTRL_REG2,
830
+ .bw_mask = BMA023_BW_MASK,
831
+ .scale_reg = BMA023_CTRL_REG2,
832
+ .scale_mask = BMA023_RANGE_MASK,
833
+ /* No power mode on bma150 */
834
+ .power_reg = 0,
835
+ .power_mask = 0,
836
+ .lowpower_val = 0,
837
+ .int_enable_reg = BMA023_CTRL_REG3,
838
+ .int_enable_mask = BMA023_NEW_DATA_INT,
839
+ .softreset_reg = BMA023_CTRL_REG0,
840
+ .softreset_val = BMA023_RESET_VAL,
841
+ .chip_config = bma023_chip_config,
842
+ .chip_disable = bma023_chip_disable,
843
+ },
629844 [BMA180] = {
845
+ .chip_id = BMA180_ID_REG_VAL,
630846 .channels = bma180_channels,
631847 .num_channels = ARRAY_SIZE(bma180_channels),
632848 .scale_table = bma180_scale_table,
633849 .num_scales = ARRAY_SIZE(bma180_scale_table),
634850 .bw_table = bma180_bw_table,
635851 .num_bw = ARRAY_SIZE(bma180_bw_table),
852
+ .temp_offset = 48, /* 0 LSB @ 24 degree C */
636853 .int_reset_reg = BMA180_CTRL_REG0,
637854 .int_reset_mask = BMA180_RESET_INT,
638855 .sleep_reg = BMA180_CTRL_REG0,
....@@ -647,16 +864,19 @@
647864 .int_enable_reg = BMA180_CTRL_REG3,
648865 .int_enable_mask = BMA180_NEW_DATA_INT,
649866 .softreset_reg = BMA180_RESET,
867
+ .softreset_val = BMA180_RESET_VAL,
650868 .chip_config = bma180_chip_config,
651869 .chip_disable = bma180_chip_disable,
652870 },
653871 [BMA250] = {
872
+ .chip_id = BMA250_ID_REG_VAL,
654873 .channels = bma250_channels,
655874 .num_channels = ARRAY_SIZE(bma250_channels),
656
- .scale_table = bma250_scale_table,
657
- .num_scales = ARRAY_SIZE(bma250_scale_table),
658
- .bw_table = bma250_bw_table,
659
- .num_bw = ARRAY_SIZE(bma250_bw_table),
875
+ .scale_table = bma25x_scale_table,
876
+ .num_scales = ARRAY_SIZE(bma25x_scale_table),
877
+ .bw_table = bma25x_bw_table,
878
+ .num_bw = ARRAY_SIZE(bma25x_bw_table),
879
+ .temp_offset = 48, /* 0 LSB @ 24 degree C */
660880 .int_reset_reg = BMA250_INT_RESET_REG,
661881 .int_reset_mask = BMA250_INT_RESET_MASK,
662882 .sleep_reg = BMA250_POWER_REG,
....@@ -671,9 +891,42 @@
671891 .lowpower_val = 1,
672892 .int_enable_reg = BMA250_INT_ENABLE_REG,
673893 .int_enable_mask = BMA250_DATA_INTEN_MASK,
894
+ .int_map_reg = BMA250_INT_MAP_REG,
895
+ .int_enable_dataready_int1_mask = BMA250_INT1_DATA_MASK,
674896 .softreset_reg = BMA250_RESET_REG,
675
- .chip_config = bma250_chip_config,
676
- .chip_disable = bma250_chip_disable,
897
+ .softreset_val = BMA180_RESET_VAL,
898
+ .chip_config = bma25x_chip_config,
899
+ .chip_disable = bma25x_chip_disable,
900
+ },
901
+ [BMA254] = {
902
+ .chip_id = BMA254_ID_REG_VAL,
903
+ .channels = bma254_channels,
904
+ .num_channels = ARRAY_SIZE(bma254_channels),
905
+ .scale_table = bma25x_scale_table,
906
+ .num_scales = ARRAY_SIZE(bma25x_scale_table),
907
+ .bw_table = bma25x_bw_table,
908
+ .num_bw = ARRAY_SIZE(bma25x_bw_table),
909
+ .temp_offset = 46, /* 0 LSB @ 23 degree C */
910
+ .int_reset_reg = BMA254_INT_RESET_REG,
911
+ .int_reset_mask = BMA254_INT_RESET_MASK,
912
+ .sleep_reg = BMA254_POWER_REG,
913
+ .sleep_mask = BMA254_SUSPEND_MASK,
914
+ .bw_reg = BMA254_BW_REG,
915
+ .bw_mask = BMA254_BW_MASK,
916
+ .bw_offset = BMA254_BW_OFFSET,
917
+ .scale_reg = BMA254_RANGE_REG,
918
+ .scale_mask = BMA254_RANGE_MASK,
919
+ .power_reg = BMA254_POWER_REG,
920
+ .power_mask = BMA254_LOWPOWER_MASK,
921
+ .lowpower_val = 1,
922
+ .int_enable_reg = BMA254_INT_ENABLE_REG,
923
+ .int_enable_mask = BMA254_DATA_INTEN_MASK,
924
+ .int_map_reg = BMA254_INT_MAP_REG,
925
+ .int_enable_dataready_int1_mask = BMA254_INT1_DATA_MASK,
926
+ .softreset_reg = BMA254_RESET_REG,
927
+ .softreset_val = BMA180_RESET_VAL,
928
+ .chip_config = bma25x_chip_config,
929
+ .chip_disable = bma25x_chip_disable,
677930 },
678931 };
679932
....@@ -731,12 +984,13 @@
731984 static int bma180_probe(struct i2c_client *client,
732985 const struct i2c_device_id *id)
733986 {
987
+ struct device *dev = &client->dev;
734988 struct bma180_data *data;
735989 struct iio_dev *indio_dev;
736990 enum chip_ids chip;
737991 int ret;
738992
739
- indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
993
+ indio_dev = devm_iio_device_alloc(dev, sizeof(*data));
740994 if (!indio_dev)
741995 return -ENOMEM;
742996
....@@ -744,17 +998,51 @@
744998 i2c_set_clientdata(client, indio_dev);
745999 data->client = client;
7461000 if (client->dev.of_node)
747
- chip = (enum chip_ids)of_device_get_match_data(&client->dev);
1001
+ chip = (enum chip_ids)of_device_get_match_data(dev);
7481002 else
7491003 chip = id->driver_data;
7501004 data->part_info = &bma180_part_info[chip];
1005
+
1006
+ ret = iio_read_mount_matrix(dev, "mount-matrix",
1007
+ &data->orientation);
1008
+ if (ret)
1009
+ return ret;
1010
+
1011
+ data->vdd_supply = devm_regulator_get(dev, "vdd");
1012
+ if (IS_ERR(data->vdd_supply))
1013
+ return dev_err_probe(dev, PTR_ERR(data->vdd_supply),
1014
+ "Failed to get vdd regulator\n");
1015
+
1016
+ data->vddio_supply = devm_regulator_get(dev, "vddio");
1017
+ if (IS_ERR(data->vddio_supply))
1018
+ return dev_err_probe(dev, PTR_ERR(data->vddio_supply),
1019
+ "Failed to get vddio regulator\n");
1020
+
1021
+ /* Typical voltage 2.4V these are min and max */
1022
+ ret = regulator_set_voltage(data->vdd_supply, 1620000, 3600000);
1023
+ if (ret)
1024
+ return ret;
1025
+ ret = regulator_set_voltage(data->vddio_supply, 1200000, 3600000);
1026
+ if (ret)
1027
+ return ret;
1028
+ ret = regulator_enable(data->vdd_supply);
1029
+ if (ret) {
1030
+ dev_err(dev, "Failed to enable vdd regulator: %d\n", ret);
1031
+ return ret;
1032
+ }
1033
+ ret = regulator_enable(data->vddio_supply);
1034
+ if (ret) {
1035
+ dev_err(dev, "Failed to enable vddio regulator: %d\n", ret);
1036
+ goto err_disable_vdd;
1037
+ }
1038
+ /* Wait to make sure we started up properly (3 ms at least) */
1039
+ usleep_range(3000, 5000);
7511040
7521041 ret = data->part_info->chip_config(data);
7531042 if (ret < 0)
7541043 goto err_chip_disable;
7551044
7561045 mutex_init(&data->mutex);
757
- indio_dev->dev.parent = &client->dev;
7581046 indio_dev->channels = data->part_info->channels;
7591047 indio_dev->num_channels = data->part_info->num_channels;
7601048 indio_dev->name = id->name;
....@@ -769,34 +1057,35 @@
7691057 goto err_chip_disable;
7701058 }
7711059
772
- ret = devm_request_irq(&client->dev, client->irq,
1060
+ ret = devm_request_irq(dev, client->irq,
7731061 iio_trigger_generic_data_rdy_poll, IRQF_TRIGGER_RISING,
7741062 "bma180_event", data->trig);
7751063 if (ret) {
776
- dev_err(&client->dev, "unable to request IRQ\n");
1064
+ dev_err(dev, "unable to request IRQ\n");
7771065 goto err_trigger_free;
7781066 }
7791067
780
- data->trig->dev.parent = &client->dev;
1068
+ data->trig->dev.parent = dev;
7811069 data->trig->ops = &bma180_trigger_ops;
7821070 iio_trigger_set_drvdata(data->trig, indio_dev);
783
- indio_dev->trig = iio_trigger_get(data->trig);
7841071
7851072 ret = iio_trigger_register(data->trig);
7861073 if (ret)
7871074 goto err_trigger_free;
1075
+
1076
+ indio_dev->trig = iio_trigger_get(data->trig);
7881077 }
7891078
7901079 ret = iio_triggered_buffer_setup(indio_dev, NULL,
7911080 bma180_trigger_handler, NULL);
7921081 if (ret < 0) {
793
- dev_err(&client->dev, "unable to setup iio triggered buffer\n");
1082
+ dev_err(dev, "unable to setup iio triggered buffer\n");
7941083 goto err_trigger_unregister;
7951084 }
7961085
7971086 ret = iio_device_register(indio_dev);
7981087 if (ret < 0) {
799
- dev_err(&client->dev, "unable to register iio device\n");
1088
+ dev_err(dev, "unable to register iio device\n");
8001089 goto err_buffer_cleanup;
8011090 }
8021091
....@@ -811,6 +1100,9 @@
8111100 iio_trigger_free(data->trig);
8121101 err_chip_disable:
8131102 data->part_info->chip_disable(data);
1103
+ regulator_disable(data->vddio_supply);
1104
+err_disable_vdd:
1105
+ regulator_disable(data->vdd_supply);
8141106
8151107 return ret;
8161108 }
....@@ -830,6 +1122,8 @@
8301122 mutex_lock(&data->mutex);
8311123 data->part_info->chip_disable(data);
8321124 mutex_unlock(&data->mutex);
1125
+ regulator_disable(data->vddio_supply);
1126
+ regulator_disable(data->vdd_supply);
8331127
8341128 return 0;
8351129 }
....@@ -868,8 +1162,12 @@
8681162 #endif
8691163
8701164 static const struct i2c_device_id bma180_ids[] = {
1165
+ { "bma023", BMA023 },
1166
+ { "bma150", BMA150 },
8711167 { "bma180", BMA180 },
8721168 { "bma250", BMA250 },
1169
+ { "bma254", BMA254 },
1170
+ { "smb380", BMA150 },
8731171 { }
8741172 };
8751173
....@@ -877,12 +1175,28 @@
8771175
8781176 static const struct of_device_id bma180_of_match[] = {
8791177 {
1178
+ .compatible = "bosch,bma023",
1179
+ .data = (void *)BMA023
1180
+ },
1181
+ {
1182
+ .compatible = "bosch,bma150",
1183
+ .data = (void *)BMA150
1184
+ },
1185
+ {
8801186 .compatible = "bosch,bma180",
8811187 .data = (void *)BMA180
8821188 },
8831189 {
8841190 .compatible = "bosch,bma250",
8851191 .data = (void *)BMA250
1192
+ },
1193
+ {
1194
+ .compatible = "bosch,bma254",
1195
+ .data = (void *)BMA254
1196
+ },
1197
+ {
1198
+ .compatible = "bosch,smb380",
1199
+ .data = (void *)BMA150
8861200 },
8871201 { }
8881202 };
....@@ -903,5 +1217,5 @@
9031217
9041218 MODULE_AUTHOR("Kravchenko Oleksandr <x0199363@ti.com>");
9051219 MODULE_AUTHOR("Texas Instruments, Inc.");
906
-MODULE_DESCRIPTION("Bosch BMA180/BMA250 triaxial acceleration sensor");
1220
+MODULE_DESCRIPTION("Bosch BMA023/BMA1x0/BMA25x triaxial acceleration sensor");
9071221 MODULE_LICENSE("GPL");