Lines Matching +full:3 +full:- +full:axis

1 // SPDX-License-Identifier: GPL-2.0-only
7 * YAS530 MS-3E (2011 Samsung Galaxy S Advance)
8 * YAS532 MS-3R (2011 Samsung Galaxy S4)
9 * YAS533 MS-3F (Vivo 1633, 1707, V3, Y21L)
11 * YAS535 MS-6C
12 * YAS536 MS-3W
13 * YAS537 MS-3T (2015 Samsung Galaxy S6, Note 5, Galaxy S7)
14 * YAS539 MS-3S (2018 Samsung Galaxy A7 SM-A750FN)
57 #define YAS530_OFFSET_X 0x85 /* [-31 .. 31] */
58 #define YAS530_OFFSET_Y1 0x86 /* [-31 .. 31] */
59 #define YAS530_OFFSET_Y2 0x87 /* [-31 .. 31] */
97 #define YAS530_DEVICE_ID 0x01 /* YAS530 (MS-3E) */
98 #define YAS530_VERSION_A 0 /* YAS530 (MS-3E A) */
99 #define YAS530_VERSION_B 1 /* YAS530B (MS-3E B) */
103 #define YAS530_DATA_CENTER BIT(YAS530_DATA_BITS - 1)
104 #define YAS530_DATA_OVERFLOW (BIT(YAS530_DATA_BITS) - 1)
106 #define YAS532_DEVICE_ID 0x02 /* YAS532/YAS533 (MS-3R/F) */
107 #define YAS532_VERSION_AB 0 /* YAS532/533 AB (MS-3R/F AB) */
108 #define YAS532_VERSION_AC 1 /* YAS532/533 AC (MS-3R/F AC) */
114 #define YAS532_DATA_CENTER BIT(YAS532_DATA_BITS - 1)
115 #define YAS532_DATA_OVERFLOW (BIT(YAS532_DATA_BITS) - 1)
117 #define YAS537_DEVICE_ID 0x07 /* YAS537 (MS-3T) */
130 #define YAS537_LCK_MASK_GET GENMASK(3, 0)
154 s32 r[3];
155 u32 f[3];
169 * struct yas5xx_chip_info - device-specific data and function pointers
173 * @volatile_reg: device-specific volatile registers
174 * @volatile_reg_qty: quantity of device-specific volatile registers
182 * @power_on: function pointer to power-on procedure
207 * struct yas5xx - state container for the YAS5xx driver
209 * @chip_info: device-specific data and function pointers
212 * @hard_offsets: offsets for each axis measured with initcoil actuated
213 * @orientation: mounting matrix, flipped axis etc
219 * so that measurements get serialized in a first-come-first serve manner
227 s8 hard_offsets[3];
250 * 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 in yas530_extract_axis()
254 val = FIELD_GET(GENMASK(14, 3), val); in yas530_extract_axis()
265 * 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 in yas532_extract_axis()
274 * yas530_measure() - Make a measure from the hardware
277 * @x: the raw x axis measurement
278 * @y1: the y1 axis measurement
279 * @y2: the y2 axis measurement
286 const struct yas5xx_chip_info *ci = yas5xx->chip_info; in yas530_measure()
292 mutex_lock(&yas5xx->lock); in yas530_measure()
293 ret = regmap_write(yas5xx->map, YAS530_MEASURE, YAS5XX_MEASURE_START); in yas530_measure()
302 ret = regmap_read_poll_timeout(yas5xx->map, YAS5XX_MEASURE_DATA, busy, in yas530_measure()
306 dev_err(yas5xx->dev, "timeout waiting for measurement\n"); in yas530_measure()
310 ret = regmap_bulk_read(yas5xx->map, YAS5XX_MEASURE_DATA, in yas530_measure()
315 mutex_unlock(&yas5xx->lock); in yas530_measure()
317 switch (ci->devid) { in yas530_measure()
322 * 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 in yas530_measure()
336 * 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 in yas530_measure()
347 dev_err(yas5xx->dev, "unknown data format\n"); in yas530_measure()
348 ret = -EINVAL; in yas530_measure()
355 mutex_unlock(&yas5xx->lock); in yas530_measure()
360 * yas537_measure() - Make a measure from the hardware
363 * @x: the raw x axis measurement
364 * @y1: the y1 axis measurement
365 * @y2: the y2 axis measurement
370 struct yas5xx_calibration *c = &yas5xx->calibration; in yas537_measure()
373 u16 xy1y2[3]; in yas537_measure()
374 s32 h[3], s[3]; in yas537_measure()
377 mutex_lock(&yas5xx->lock); in yas537_measure()
380 ret = regmap_write(yas5xx->map, YAS537_MEASURE, YAS5XX_MEASURE_START | in yas537_measure()
386 ret = regmap_read_poll_timeout(yas5xx->map, YAS5XX_MEASURE_DATA + 2, busy, in yas537_measure()
390 dev_err(yas5xx->dev, "timeout waiting for measurement\n"); in yas537_measure()
394 ret = regmap_bulk_read(yas5xx->map, YAS5XX_MEASURE_DATA, in yas537_measure()
399 mutex_unlock(&yas5xx->lock); in yas537_measure()
407 if (yas5xx->version == YAS537_VERSION_1) { in yas537_measure()
408 for (i = 0; i < 3; i++) in yas537_measure()
409 s[i] = xy1y2[i] - BIT(13); in yas537_measure()
410 h[0] = (c->k * (128 * s[0] + c->a2 * s[1] + c->a3 * s[2])) / BIT(13); in yas537_measure()
411 h[1] = (c->k * (c->a4 * s[0] + c->a5 * s[1] + c->a6 * s[2])) / BIT(13); in yas537_measure()
412 h[2] = (c->k * (c->a7 * s[0] + c->a8 * s[1] + c->a9 * s[2])) / BIT(13); in yas537_measure()
413 for (i = 0; i < 3; i++) { in yas537_measure()
414 clamp_val(h[i], -BIT(13), BIT(13) - 1); in yas537_measure()
426 mutex_unlock(&yas5xx->lock); in yas537_measure()
431 static s32 yas530_linearize(struct yas5xx *yas5xx, u16 val, int axis) in yas530_linearize() argument
433 const struct yas5xx_chip_info *ci = yas5xx->chip_info; in yas530_linearize()
434 struct yas5xx_calibration *c = &yas5xx->calibration; in yas530_linearize()
443 switch (ci->devid) { in yas530_linearize()
445 if (yas5xx->version == YAS530_VERSION_A) in yas530_linearize()
451 if (yas5xx->version == YAS532_VERSION_AB) in yas530_linearize()
455 coef = yas532ac_coef[axis]; in yas530_linearize()
458 dev_err(yas5xx->dev, "unknown device type\n"); in yas530_linearize()
464 * x' = x - (3721 + 50 * f) + (xoffset - r) * c in yas530_linearize()
466 * Where f and r are calibration values, c is a per-device in yas530_linearize()
467 * and sometimes per-axis coefficient. in yas530_linearize()
469 return val - (3721 + 50 * c->f[axis]) + in yas530_linearize()
470 (yas5xx->hard_offsets[axis] - c->r[axis]) * coef; in yas530_linearize()
475 const struct yas5xx_chip_info *ci = yas5xx->chip_info; in yas5xx_calc_temperature()
481 t_ref = ci->t_ref; in yas5xx_calc_temperature()
482 min_temp_x10 = ci->min_temp_x10; in yas5xx_calc_temperature()
485 to = (min_temp_x10 + ((ref_temp_x10 - min_temp_x10) * t / t_ref)) * 100; in yas5xx_calc_temperature()
490 * yas530_get_measure() - Measure a sample of all axis and process
493 * @xo: X axis out
494 * @yo: Y axis out
495 * @zo: Z axis out
502 const struct yas5xx_chip_info *ci = yas5xx->chip_info; in yas530_get_measure()
503 struct yas5xx_calibration *c = &yas5xx->calibration; in yas530_get_measure()
524 t_ref = ci->t_ref; in yas530_get_measure()
525 if (ci->devid == YAS532_DEVICE_ID && in yas530_get_measure()
526 yas5xx->version == YAS532_VERSION_AC) { in yas530_get_measure()
527 t_comp = t - t_ref; in yas530_get_measure()
536 * x' = x - ----------- in yas530_get_measure()
539 sx = sx - (c->Cx * t_comp) / 100; in yas530_get_measure()
540 sy1 = sy1 - (c->Cy1 * t_comp) / 100; in yas530_get_measure()
541 sy2 = sy2 - (c->Cy2 * t_comp) / 100; in yas530_get_measure()
547 sy = sy1 - sy2; in yas530_get_measure()
548 sz = -sy1 - sy2; in yas530_get_measure()
557 * x' = k * --------------------------- in yas530_get_measure()
561 * y' = k * --------------------------- in yas530_get_measure()
565 * z' = k * --------------------------- in yas530_get_measure()
568 *xo = c->k * ((100 * sx + c->a2 * sy + c->a3 * sz) / 10); in yas530_get_measure()
569 *yo = c->k * ((c->a4 * sx + c->a5 * sy + c->a6 * sz) / 10); in yas530_get_measure()
570 *zo = c->k * ((c->a7 * sx + c->a8 * sy + c->a9 * sz) / 10); in yas530_get_measure()
576 * yas537_get_measure() - Measure a sample of all axis and process
579 * @xo: X axis out
580 * @yo: Y axis out
581 * @zo: Z axis out
603 *xo = (x - BIT(13)) * 300; in yas537_get_measure()
604 *yo = (y1 - y2) * 1732 / 10; in yas537_get_measure()
605 *zo = (-y1 - y2 + BIT(14)) * 300; in yas537_get_measure()
616 const struct yas5xx_chip_info *ci = yas5xx->chip_info; in yas5xx_read_raw()
623 pm_runtime_get_sync(yas5xx->dev); in yas5xx_read_raw()
624 ret = ci->get_measure(yas5xx, &t, &x, &y, &z); in yas5xx_read_raw()
625 pm_runtime_mark_last_busy(yas5xx->dev); in yas5xx_read_raw()
626 pm_runtime_put_autosuspend(yas5xx->dev); in yas5xx_read_raw()
629 switch (chan->address) { in yas5xx_read_raw()
639 case 3: in yas5xx_read_raw()
643 dev_err(yas5xx->dev, "unknown channel\n"); in yas5xx_read_raw()
644 return -EINVAL; in yas5xx_read_raw()
649 *val2 = ci->scaling_val2; in yas5xx_read_raw()
653 return -EINVAL; in yas5xx_read_raw()
660 const struct yas5xx_chip_info *ci = yas5xx->chip_info; in yas5xx_fill_buffer()
664 pm_runtime_get_sync(yas5xx->dev); in yas5xx_fill_buffer()
665 ret = ci->get_measure(yas5xx, &t, &x, &y, &z); in yas5xx_fill_buffer()
666 pm_runtime_mark_last_busy(yas5xx->dev); in yas5xx_fill_buffer()
667 pm_runtime_put_autosuspend(yas5xx->dev); in yas5xx_fill_buffer()
669 dev_err(yas5xx->dev, "error refilling buffer\n"); in yas5xx_fill_buffer()
672 yas5xx->scan.channels[0] = t; in yas5xx_fill_buffer()
673 yas5xx->scan.channels[1] = x; in yas5xx_fill_buffer()
674 yas5xx->scan.channels[2] = y; in yas5xx_fill_buffer()
675 yas5xx->scan.channels[3] = z; in yas5xx_fill_buffer()
676 iio_push_to_buffers_with_timestamp(indio_dev, &yas5xx->scan, in yas5xx_fill_buffer()
683 struct iio_dev *indio_dev = pf->indio_dev; in yas5xx_handle_trigger()
686 iio_trigger_notify_done(indio_dev->trig); in yas5xx_handle_trigger()
698 return &yas5xx->orientation; in yas5xx_get_mount_matrix()
706 #define YAS5XX_AXIS_CHANNEL(axis, index) \ argument
710 .channel2 = IIO_MOD_##axis, \
739 YAS5XX_AXIS_CHANNEL(Z, 3),
743 static const unsigned long yas5xx_scan_masks[] = { GENMASK(3, 0), 0 };
753 const struct yas5xx_chip_info *ci = yas5xx->chip_info; in yas5xx_volatile_reg()
764 reg_qty = ci->volatile_reg_qty; in yas5xx_volatile_reg()
766 if (reg == ci->volatile_reg[i]) in yas5xx_volatile_reg()
782 * yas530_extract_calibration() - extracts the a2-a9 and k calibration
793 * Bitfield layout for the axis calibration data, for factor in yas530_extract_calibration()
796 * n 7 6 5 4 3 2 1 0 in yas530_extract_calibration()
797 * 0 [ 2 2 2 2 2 2 3 3 ] bits 63 .. 56 in yas530_extract_calibration()
798 * 1 [ 3 3 4 4 4 4 4 4 ] bits 55 .. 48 in yas530_extract_calibration()
800 * 3 [ 6 6 6 6 7 7 7 7 ] bits 39 .. 32 in yas530_extract_calibration()
806 c->a2 = FIELD_GET(GENMASK_ULL(63, 58), val) - 32; in yas530_extract_calibration()
807 c->a3 = FIELD_GET(GENMASK_ULL(57, 54), val) - 8; in yas530_extract_calibration()
808 c->a4 = FIELD_GET(GENMASK_ULL(53, 48), val) - 32; in yas530_extract_calibration()
809 c->a5 = FIELD_GET(GENMASK_ULL(47, 42), val) + 38; in yas530_extract_calibration()
810 c->a6 = FIELD_GET(GENMASK_ULL(41, 36), val) - 32; in yas530_extract_calibration()
811 c->a7 = FIELD_GET(GENMASK_ULL(35, 29), val) - 64; in yas530_extract_calibration()
812 c->a8 = FIELD_GET(GENMASK_ULL(28, 23), val) - 32; in yas530_extract_calibration()
813 c->a9 = FIELD_GET(GENMASK_ULL(22, 15), val); in yas530_extract_calibration()
814 c->k = FIELD_GET(GENMASK_ULL(14, 10), val) + 10; in yas530_extract_calibration()
815 c->dck = FIELD_GET(GENMASK_ULL(9, 7), val); in yas530_extract_calibration()
820 struct yas5xx_calibration *c = &yas5xx->calibration; in yas530_get_calibration_data()
826 ret = regmap_bulk_read(yas5xx->map, YAS530_CAL, data, sizeof(data)); in yas530_get_calibration_data()
831 ret = regmap_bulk_read(yas5xx->map, YAS530_CAL, data, sizeof(data)); in yas530_get_calibration_data()
834 dev_dbg(yas5xx->dev, "calibration data: %16ph\n", data); in yas530_get_calibration_data()
840 yas5xx->version = data[15] & GENMASK(1, 0); in yas530_get_calibration_data()
843 c->Cx = data[0] * 6 - 768; in yas530_get_calibration_data()
844 c->Cy1 = data[1] * 6 - 768; in yas530_get_calibration_data()
845 c->Cy2 = data[2] * 6 - 768; in yas530_get_calibration_data()
846 yas530_extract_calibration(&data[3], c); in yas530_get_calibration_data()
853 * n 7 6 5 4 3 2 1 0 in yas530_get_calibration_data()
857 * 3 [ r2 f2 f2 xx xx xx xx xx ] bits 7 .. 0 in yas530_get_calibration_data()
860 c->f[0] = FIELD_GET(GENMASK(22, 21), val); in yas530_get_calibration_data()
861 c->f[1] = FIELD_GET(GENMASK(14, 13), val); in yas530_get_calibration_data()
862 c->f[2] = FIELD_GET(GENMASK(6, 5), val); in yas530_get_calibration_data()
863 c->r[0] = sign_extend32(FIELD_GET(GENMASK(28, 23), val), 5); in yas530_get_calibration_data()
864 c->r[1] = sign_extend32(FIELD_GET(GENMASK(20, 15), val), 5); in yas530_get_calibration_data()
865 c->r[2] = sign_extend32(FIELD_GET(GENMASK(12, 7), val), 5); in yas530_get_calibration_data()
872 struct yas5xx_calibration *c = &yas5xx->calibration; in yas532_get_calibration_data()
878 ret = regmap_bulk_read(yas5xx->map, YAS530_CAL, data, sizeof(data)); in yas532_get_calibration_data()
882 ret = regmap_bulk_read(yas5xx->map, YAS530_CAL, data, sizeof(data)); in yas532_get_calibration_data()
885 dev_dbg(yas5xx->dev, "calibration data: %14ph\n", data); in yas532_get_calibration_data()
889 dev_warn(yas5xx->dev, "calibration is blank!\n"); in yas532_get_calibration_data()
895 yas5xx->version = data[13] & BIT(0); in yas532_get_calibration_data()
898 c->Cx = data[0] * 10 - 1280; in yas532_get_calibration_data()
899 c->Cy1 = data[1] * 10 - 1280; in yas532_get_calibration_data()
900 c->Cy2 = data[2] * 10 - 1280; in yas532_get_calibration_data()
901 yas530_extract_calibration(&data[3], c); in yas532_get_calibration_data()
908 * n 7 6 5 4 3 2 1 0 in yas532_get_calibration_data()
912 * 3 [ f2 xx xx xx xx xx xx xx ] bits 7 .. 0 in yas532_get_calibration_data()
915 c->f[0] = FIELD_GET(GENMASK(24, 23), val); in yas532_get_calibration_data()
916 c->f[1] = FIELD_GET(GENMASK(16, 15), val); in yas532_get_calibration_data()
917 c->f[2] = FIELD_GET(GENMASK(8, 7), val); in yas532_get_calibration_data()
918 c->r[0] = sign_extend32(FIELD_GET(GENMASK(30, 25), val), 5); in yas532_get_calibration_data()
919 c->r[1] = sign_extend32(FIELD_GET(GENMASK(22, 17), val), 5); in yas532_get_calibration_data()
920 c->r[2] = sign_extend32(FIELD_GET(GENMASK(14, 7), val), 5); in yas532_get_calibration_data()
927 struct yas5xx_calibration *c = &yas5xx->calibration; in yas537_get_calibration_data()
933 ret = regmap_write(yas5xx->map, YAS537_SRST, BIT(1)); in yas537_get_calibration_data()
938 ret = regmap_bulk_read(yas5xx->map, YAS537_CAL, data, sizeof(data)); in yas537_get_calibration_data()
941 dev_dbg(yas5xx->dev, "calibration data: %17ph\n", data); in yas537_get_calibration_data()
945 dev_warn(yas5xx->dev, "calibration is blank!\n"); in yas537_get_calibration_data()
951 yas5xx->version = FIELD_GET(GENMASK(7, 6), data[16]); in yas537_get_calibration_data()
954 switch (yas5xx->version) { in yas537_get_calibration_data()
962 * data[3] 0x96 in yas537_get_calibration_data()
980 ret = regmap_write(yas5xx->map, YAS537_MTC + i, in yas537_get_calibration_data()
985 for (i = 0; i < 3; i++) { in yas537_get_calibration_data()
986 ret = regmap_write(yas5xx->map, YAS537_OFFSET_X + i, in yas537_get_calibration_data()
990 yas5xx->hard_offsets[i] = data[i + 12]; in yas537_get_calibration_data()
993 ret = regmap_write(yas5xx->map, YAS537_HCK + i, in yas537_get_calibration_data()
1009 * data[3] YAS537_MTC+3 (partially) 0x96 in yas537_get_calibration_data()
1019 for (i = 0; i < 3; i++) { in yas537_get_calibration_data()
1020 ret = regmap_write(yas5xx->map, YAS537_MTC + i, in yas537_get_calibration_data()
1025 for (i = 0; i < 3; i++) { in yas537_get_calibration_data()
1026 ret = regmap_write(yas5xx->map, YAS537_OFFSET_X + i, in yas537_get_calibration_data()
1030 yas5xx->hard_offsets[i] = data[i + 12]; in yas537_get_calibration_data()
1035 * data[3] n 7 6 5 4 3 2 1 0 in yas537_get_calibration_data()
1036 * YAS537_MTC+3 x x x 1 0 0 0 0 in yas537_get_calibration_data()
1038 * data[15] n 7 6 5 4 3 2 1 0 in yas537_get_calibration_data()
1041 * data[15] n 7 6 5 4 3 2 1 0 in yas537_get_calibration_data()
1044 * data[16] n 7 6 5 4 3 2 1 0 in yas537_get_calibration_data()
1047 ret = regmap_write(yas5xx->map, YAS537_MTC + 3, in yas537_get_calibration_data()
1049 FIELD_GET(YAS537_MTC3_MASK_GET, data[3])) | in yas537_get_calibration_data()
1053 ret = regmap_write(yas5xx->map, YAS537_HCK, in yas537_get_calibration_data()
1058 ret = regmap_write(yas5xx->map, YAS537_LCK, in yas537_get_calibration_data()
1063 ret = regmap_write(yas5xx->map, YAS537_OC, in yas537_get_calibration_data()
1068 * For data extraction, build some blocks. Four 32-bit blocks in yas537_get_calibration_data()
1071 * n 7 6 5 4 3 2 1 0 in yas537_get_calibration_data()
1075 * data[3] 3 [ C2 C2 C2 ] bits 7 .. 0 in yas537_get_calibration_data()
1077 * n 7 6 5 4 3 2 1 0 in yas537_get_calibration_data()
1078 * data[3] 0 [ a2 a2 a2 a2 a2 ] bits 31 .. 24 in yas537_get_calibration_data()
1081 * data[6] 3 [ a4 ] bits 7 .. 0 in yas537_get_calibration_data()
1083 * n 7 6 5 4 3 2 1 0 in yas537_get_calibration_data()
1087 * data[9] 3 [ a7 ] bits 7 .. 0 in yas537_get_calibration_data()
1089 * n 7 6 5 4 3 2 1 0 in yas537_get_calibration_data()
1093 * data[12] 3 [ ] bits 7 .. 0 in yas537_get_calibration_data()
1096 val2 = get_unaligned_be32(&data[3]); in yas537_get_calibration_data()
1100 c->Cx = FIELD_GET(GENMASK(31, 23), val1) - 256; in yas537_get_calibration_data()
1101 c->Cy1 = FIELD_GET(GENMASK(22, 14), val1) - 256; in yas537_get_calibration_data()
1102 c->Cy2 = FIELD_GET(GENMASK(13, 5), val1) - 256; in yas537_get_calibration_data()
1103 c->a2 = FIELD_GET(GENMASK(28, 22), val2) - 64; in yas537_get_calibration_data()
1104 c->a3 = FIELD_GET(GENMASK(21, 15), val2) - 64; in yas537_get_calibration_data()
1105 c->a4 = FIELD_GET(GENMASK(14, 7), val2) - 128; in yas537_get_calibration_data()
1106 c->a5 = FIELD_GET(GENMASK(30, 22), val3) - 112; in yas537_get_calibration_data()
1107 c->a6 = FIELD_GET(GENMASK(21, 15), val3) - 64; in yas537_get_calibration_data()
1108 c->a7 = FIELD_GET(GENMASK(14, 7), val3) - 128; in yas537_get_calibration_data()
1109 c->a8 = FIELD_GET(GENMASK(30, 24), val4) - 64; in yas537_get_calibration_data()
1110 c->a9 = FIELD_GET(GENMASK(23, 15), val4) - 112; in yas537_get_calibration_data()
1111 c->k = FIELD_GET(GENMASK(14, 8), val4); in yas537_get_calibration_data()
1114 dev_err(yas5xx->dev, "unknown version of YAS537\n"); in yas537_get_calibration_data()
1115 return -EINVAL; in yas537_get_calibration_data()
1124 struct yas5xx_calibration *c = &yas5xx->calibration; in yas530_dump_calibration()
1126 dev_dbg(yas5xx->dev, "f[] = [%d, %d, %d]\n", in yas530_dump_calibration()
1127 c->f[0], c->f[1], c->f[2]); in yas530_dump_calibration()
1128 dev_dbg(yas5xx->dev, "r[] = [%d, %d, %d]\n", in yas530_dump_calibration()
1129 c->r[0], c->r[1], c->r[2]); in yas530_dump_calibration()
1130 dev_dbg(yas5xx->dev, "Cx = %d\n", c->Cx); in yas530_dump_calibration()
1131 dev_dbg(yas5xx->dev, "Cy1 = %d\n", c->Cy1); in yas530_dump_calibration()
1132 dev_dbg(yas5xx->dev, "Cy2 = %d\n", c->Cy2); in yas530_dump_calibration()
1133 dev_dbg(yas5xx->dev, "a2 = %d\n", c->a2); in yas530_dump_calibration()
1134 dev_dbg(yas5xx->dev, "a3 = %d\n", c->a3); in yas530_dump_calibration()
1135 dev_dbg(yas5xx->dev, "a4 = %d\n", c->a4); in yas530_dump_calibration()
1136 dev_dbg(yas5xx->dev, "a5 = %d\n", c->a5); in yas530_dump_calibration()
1137 dev_dbg(yas5xx->dev, "a6 = %d\n", c->a6); in yas530_dump_calibration()
1138 dev_dbg(yas5xx->dev, "a7 = %d\n", c->a7); in yas530_dump_calibration()
1139 dev_dbg(yas5xx->dev, "a8 = %d\n", c->a8); in yas530_dump_calibration()
1140 dev_dbg(yas5xx->dev, "a9 = %d\n", c->a9); in yas530_dump_calibration()
1141 dev_dbg(yas5xx->dev, "k = %d\n", c->k); in yas530_dump_calibration()
1142 dev_dbg(yas5xx->dev, "dck = %d\n", c->dck); in yas530_dump_calibration()
1147 struct yas5xx_calibration *c = &yas5xx->calibration; in yas537_dump_calibration()
1149 if (yas5xx->version == YAS537_VERSION_1) { in yas537_dump_calibration()
1150 dev_dbg(yas5xx->dev, "Cx = %d\n", c->Cx); in yas537_dump_calibration()
1151 dev_dbg(yas5xx->dev, "Cy1 = %d\n", c->Cy1); in yas537_dump_calibration()
1152 dev_dbg(yas5xx->dev, "Cy2 = %d\n", c->Cy2); in yas537_dump_calibration()
1153 dev_dbg(yas5xx->dev, "a2 = %d\n", c->a2); in yas537_dump_calibration()
1154 dev_dbg(yas5xx->dev, "a3 = %d\n", c->a3); in yas537_dump_calibration()
1155 dev_dbg(yas5xx->dev, "a4 = %d\n", c->a4); in yas537_dump_calibration()
1156 dev_dbg(yas5xx->dev, "a5 = %d\n", c->a5); in yas537_dump_calibration()
1157 dev_dbg(yas5xx->dev, "a6 = %d\n", c->a6); in yas537_dump_calibration()
1158 dev_dbg(yas5xx->dev, "a7 = %d\n", c->a7); in yas537_dump_calibration()
1159 dev_dbg(yas5xx->dev, "a8 = %d\n", c->a8); in yas537_dump_calibration()
1160 dev_dbg(yas5xx->dev, "a9 = %d\n", c->a9); in yas537_dump_calibration()
1161 dev_dbg(yas5xx->dev, "k = %d\n", c->k); in yas537_dump_calibration()
1170 ret = regmap_write(yas5xx->map, YAS530_OFFSET_X, ox); in yas530_set_offsets()
1173 ret = regmap_write(yas5xx->map, YAS530_OFFSET_Y1, oy1); in yas530_set_offsets()
1176 return regmap_write(yas5xx->map, YAS530_OFFSET_Y2, oy2); in yas530_set_offsets()
1185 return old - BIT(bit); in yas530_adjust_offset()
1192 const struct yas5xx_chip_info *ci = yas5xx->chip_info; in yas530_measure_offsets()
1200 ret = regmap_write(yas5xx->map, YAS530_ACTUATE_INIT_COIL, 0); in yas530_measure_offsets()
1205 switch (ci->devid) { in yas530_measure_offsets()
1213 dev_err(yas5xx->dev, "unknown device type\n"); in yas530_measure_offsets()
1214 return -EINVAL; in yas530_measure_offsets()
1218 * We set offsets in the interval +-31 by iterating in yas530_measure_offsets()
1219 * +-16, +-8, +-4, +-2, +-1 adjusting the offsets each in yas530_measure_offsets()
1224 * as the values for [x, y1, y2]. The value is +/-31 in yas530_measure_offsets()
1233 for (i = 4; i >= 0; i--) { in yas530_measure_offsets()
1241 dev_dbg(yas5xx->dev, "measurement %d: x=%d, y1=%d, y2=%d\n", in yas530_measure_offsets()
1242 5-i, x, y1, y2); in yas530_measure_offsets()
1250 yas5xx->hard_offsets[0] = ox; in yas530_measure_offsets()
1251 yas5xx->hard_offsets[1] = oy1; in yas530_measure_offsets()
1252 yas5xx->hard_offsets[2] = oy2; in yas530_measure_offsets()
1257 dev_info(yas5xx->dev, "discovered hard offsets: x=%d, y1=%d, y2=%d\n", in yas530_measure_offsets()
1269 ret = regmap_write(yas5xx->map, YAS530_TEST1, 0); in yas530_power_on()
1272 ret = regmap_write(yas5xx->map, YAS530_TEST2, 0); in yas530_power_on()
1277 val = FIELD_PREP(YAS5XX_CONFIG_CCK_MASK, yas5xx->calibration.dck); in yas530_power_on()
1278 ret = regmap_write(yas5xx->map, YAS530_CONFIG, val); in yas530_power_on()
1282 /* Measure interval 0 (back-to-back?) */ in yas530_power_on()
1283 return regmap_write(yas5xx->map, YAS530_MEASURE_INTERVAL, 0); in yas530_power_on()
1293 buf = cpu_to_be16(GENMASK(9, 3)); in yas537_power_on()
1294 ret = regmap_bulk_write(yas5xx->map, YAS537_ADCCAL, &buf, sizeof(buf)); in yas537_power_on()
1297 ret = regmap_write(yas5xx->map, YAS537_TRM, GENMASK(7, 0)); in yas537_power_on()
1303 - YAS537_MEASURE_TIME_WORST_US) / 4100; in yas537_power_on()
1304 ret = regmap_write(yas5xx->map, YAS537_MEASURE_INTERVAL, intrvl); in yas537_power_on()
1309 ret = regmap_write(yas5xx->map, YAS537_AVR, YAS537_MAG_AVERAGE_32_MASK); in yas537_power_on()
1314 ret = regmap_write(yas5xx->map, YAS537_CONFIG, BIT(3)); in yas537_power_on()
1327 .product_name = "YAS530 MS-3E",
1333 .min_temp_x10 = -620, /* 1/10:s degrees Celsius */
1342 .product_name = "YAS532 MS-3R",
1348 .min_temp_x10 = -500, /* 1/10:s degrees Celsius */
1357 .product_name = "YAS533 MS-3F",
1363 .min_temp_x10 = -500, /* 1/10:s degrees Celsius */
1372 .product_name = "YAS537 MS-3T",
1378 .min_temp_x10 = -3860, /* 1/10:s degrees Celsius */
1391 struct device *dev = &i2c->dev; in yas5xx_probe()
1399 return -ENOMEM; in yas5xx_probe()
1403 yas5xx->dev = dev; in yas5xx_probe()
1404 mutex_init(&yas5xx->lock); in yas5xx_probe()
1406 ret = iio_read_mount_matrix(dev, &yas5xx->orientation); in yas5xx_probe()
1410 yas5xx->regs[0].supply = "vdd"; in yas5xx_probe()
1411 yas5xx->regs[1].supply = "iovdd"; in yas5xx_probe()
1412 ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(yas5xx->regs), in yas5xx_probe()
1413 yas5xx->regs); in yas5xx_probe()
1417 ret = regulator_bulk_enable(ARRAY_SIZE(yas5xx->regs), yas5xx->regs); in yas5xx_probe()
1425 yas5xx->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW); in yas5xx_probe()
1426 if (IS_ERR(yas5xx->reset)) { in yas5xx_probe()
1427 ret = dev_err_probe(dev, PTR_ERR(yas5xx->reset), "failed to get reset line\n"); in yas5xx_probe()
1431 yas5xx->map = devm_regmap_init_i2c(i2c, &yas5xx_regmap_config); in yas5xx_probe()
1432 if (IS_ERR(yas5xx->map)) { in yas5xx_probe()
1433 ret = dev_err_probe(dev, PTR_ERR(yas5xx->map), "failed to allocate register map\n"); in yas5xx_probe()
1438 yas5xx->chip_info = ci; in yas5xx_probe()
1440 ret = regmap_read(yas5xx->map, YAS5XX_DEVICE_ID, &id_check); in yas5xx_probe()
1444 if (id_check != ci->devid) { in yas5xx_probe()
1445 ret = dev_err_probe(dev, -ENODEV, in yas5xx_probe()
1447 id_check, id->name); in yas5xx_probe()
1451 ret = ci->get_calibration_data(yas5xx); in yas5xx_probe()
1455 dev_info(dev, "detected %s %s\n", ci->product_name, in yas5xx_probe()
1456 ci->version_names[yas5xx->version]); in yas5xx_probe()
1458 ci->dump_calibration(yas5xx); in yas5xx_probe()
1460 ret = ci->power_on(yas5xx); in yas5xx_probe()
1464 if (ci->measure_offsets) { in yas5xx_probe()
1465 ret = ci->measure_offsets(yas5xx); in yas5xx_probe()
1470 indio_dev->info = &yas5xx_info; in yas5xx_probe()
1471 indio_dev->available_scan_masks = yas5xx_scan_masks; in yas5xx_probe()
1472 indio_dev->modes = INDIO_DIRECT_MODE; in yas5xx_probe()
1473 indio_dev->name = id->name; in yas5xx_probe()
1474 indio_dev->channels = yas5xx_channels; in yas5xx_probe()
1475 indio_dev->num_channels = ARRAY_SIZE(yas5xx_channels); in yas5xx_probe()
1505 gpiod_set_value_cansleep(yas5xx->reset, 1); in yas5xx_probe()
1507 regulator_bulk_disable(ARRAY_SIZE(yas5xx->regs), yas5xx->regs); in yas5xx_probe()
1516 struct device *dev = &i2c->dev; in yas5xx_remove()
1528 gpiod_set_value_cansleep(yas5xx->reset, 1); in yas5xx_remove()
1529 regulator_bulk_disable(ARRAY_SIZE(yas5xx->regs), yas5xx->regs); in yas5xx_remove()
1537 gpiod_set_value_cansleep(yas5xx->reset, 1); in yas5xx_runtime_suspend()
1538 regulator_bulk_disable(ARRAY_SIZE(yas5xx->regs), yas5xx->regs); in yas5xx_runtime_suspend()
1547 const struct yas5xx_chip_info *ci = yas5xx->chip_info; in yas5xx_runtime_resume()
1550 ret = regulator_bulk_enable(ARRAY_SIZE(yas5xx->regs), yas5xx->regs); in yas5xx_runtime_resume()
1562 gpiod_set_value_cansleep(yas5xx->reset, 0); in yas5xx_runtime_resume()
1564 ret = ci->power_on(yas5xx); in yas5xx_runtime_resume()
1573 gpiod_set_value_cansleep(yas5xx->reset, 1); in yas5xx_runtime_resume()
1574 regulator_bulk_disable(ARRAY_SIZE(yas5xx->regs), yas5xx->regs); in yas5xx_runtime_resume()
1612 MODULE_DESCRIPTION("Yamaha YAS53x 3-axis magnetometer driver");