Lines Matching +full:6 +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) */
120 #define YAS537_MAG_AVERAGE_32_MASK GENMASK(6, 4)
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
250 * 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 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()
326 val = FIELD_GET(GENMASK(14, 6), val); in yas530_measure()
330 *y2 = yas530_extract_axis(&data[6]); in yas530_measure()
336 * 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 in yas530_measure()
344 *y2 = yas532_extract_axis(&data[6]); 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()
378 mutex_lock(&yas5xx->lock); in yas537_measure()
381 ret = regmap_write(yas5xx->map, YAS537_MEASURE, YAS5XX_MEASURE_START | in yas537_measure()
387 ret = regmap_read_poll_timeout(yas5xx->map, YAS5XX_MEASURE_DATA + 2, busy, in yas537_measure()
391 dev_err(yas5xx->dev, "timeout waiting for measurement\n"); in yas537_measure()
395 ret = regmap_bulk_read(yas5xx->map, YAS5XX_MEASURE_DATA, in yas537_measure()
400 mutex_unlock(&yas5xx->lock); in yas537_measure()
405 xy1y2[2] = get_unaligned_be16(&data[6]); in yas537_measure()
408 if (yas5xx->version == YAS537_VERSION_1) { in yas537_measure()
410 s[i] = xy1y2[i] - half_range; in yas537_measure()
411 h[0] = (c->k * (128 * s[0] + c->a2 * s[1] + c->a3 * s[2])) / half_range; in yas537_measure()
412 h[1] = (c->k * (c->a4 * s[0] + c->a5 * s[1] + c->a6 * s[2])) / half_range; in yas537_measure()
413 h[2] = (c->k * (c->a7 * s[0] + c->a8 * s[1] + c->a9 * s[2])) / half_range; in yas537_measure()
415 h[i] = clamp(h[i], -half_range, half_range - 1); in yas537_measure()
427 mutex_unlock(&yas5xx->lock); in yas537_measure()
432 static s32 yas530_linearize(struct yas5xx *yas5xx, u16 val, int axis) in yas530_linearize() argument
434 const struct yas5xx_chip_info *ci = yas5xx->chip_info; in yas530_linearize()
435 struct yas5xx_calibration *c = &yas5xx->calibration; in yas530_linearize()
444 switch (ci->devid) { in yas530_linearize()
446 if (yas5xx->version == YAS530_VERSION_A) in yas530_linearize()
452 if (yas5xx->version == YAS532_VERSION_AB) in yas530_linearize()
456 coef = yas532ac_coef[axis]; in yas530_linearize()
459 dev_err(yas5xx->dev, "unknown device type\n"); in yas530_linearize()
465 * x' = x - (3721 + 50 * f) + (xoffset - r) * c in yas530_linearize()
467 * Where f and r are calibration values, c is a per-device in yas530_linearize()
468 * and sometimes per-axis coefficient. in yas530_linearize()
470 return val - (3721 + 50 * c->f[axis]) + in yas530_linearize()
471 (yas5xx->hard_offsets[axis] - c->r[axis]) * coef; in yas530_linearize()
476 const struct yas5xx_chip_info *ci = yas5xx->chip_info; in yas5xx_calc_temperature()
482 t_ref = ci->t_ref; in yas5xx_calc_temperature()
483 min_temp_x10 = ci->min_temp_x10; in yas5xx_calc_temperature()
486 to = (min_temp_x10 + ((ref_temp_x10 - min_temp_x10) * t / t_ref)) * 100; in yas5xx_calc_temperature()
491 * yas530_get_measure() - Measure a sample of all axis and process
494 * @xo: X axis out
495 * @yo: Y axis out
496 * @zo: Z axis out
503 const struct yas5xx_chip_info *ci = yas5xx->chip_info; in yas530_get_measure()
504 struct yas5xx_calibration *c = &yas5xx->calibration; in yas530_get_measure()
525 t_ref = ci->t_ref; in yas530_get_measure()
526 if (ci->devid == YAS532_DEVICE_ID && in yas530_get_measure()
527 yas5xx->version == YAS532_VERSION_AC) { in yas530_get_measure()
528 t_comp = t - t_ref; in yas530_get_measure()
537 * x' = x - ----------- in yas530_get_measure()
540 sx = sx - (c->Cx * t_comp) / 100; in yas530_get_measure()
541 sy1 = sy1 - (c->Cy1 * t_comp) / 100; in yas530_get_measure()
542 sy2 = sy2 - (c->Cy2 * t_comp) / 100; in yas530_get_measure()
548 sy = sy1 - sy2; in yas530_get_measure()
549 sz = -sy1 - sy2; in yas530_get_measure()
558 * x' = k * --------------------------- in yas530_get_measure()
562 * y' = k * --------------------------- in yas530_get_measure()
566 * z' = k * --------------------------- in yas530_get_measure()
569 *xo = c->k * ((100 * sx + c->a2 * sy + c->a3 * sz) / 10); in yas530_get_measure()
570 *yo = c->k * ((c->a4 * sx + c->a5 * sy + c->a6 * sz) / 10); in yas530_get_measure()
571 *zo = c->k * ((c->a7 * sx + c->a8 * sy + c->a9 * sz) / 10); in yas530_get_measure()
577 * yas537_get_measure() - Measure a sample of all axis and process
580 * @xo: X axis out
581 * @yo: Y axis out
582 * @zo: Z axis out
604 *xo = (x - BIT(13)) * 300; in yas537_get_measure()
605 *yo = (y1 - y2) * 1732 / 10; in yas537_get_measure()
606 *zo = (-y1 - y2 + BIT(14)) * 300; in yas537_get_measure()
617 const struct yas5xx_chip_info *ci = yas5xx->chip_info; in yas5xx_read_raw()
624 pm_runtime_get_sync(yas5xx->dev); in yas5xx_read_raw()
625 ret = ci->get_measure(yas5xx, &t, &x, &y, &z); in yas5xx_read_raw()
626 pm_runtime_mark_last_busy(yas5xx->dev); in yas5xx_read_raw()
627 pm_runtime_put_autosuspend(yas5xx->dev); in yas5xx_read_raw()
630 switch (chan->address) { in yas5xx_read_raw()
644 dev_err(yas5xx->dev, "unknown channel\n"); in yas5xx_read_raw()
645 return -EINVAL; in yas5xx_read_raw()
650 *val2 = ci->scaling_val2; in yas5xx_read_raw()
654 return -EINVAL; in yas5xx_read_raw()
661 const struct yas5xx_chip_info *ci = yas5xx->chip_info; in yas5xx_fill_buffer()
665 pm_runtime_get_sync(yas5xx->dev); in yas5xx_fill_buffer()
666 ret = ci->get_measure(yas5xx, &t, &x, &y, &z); in yas5xx_fill_buffer()
667 pm_runtime_mark_last_busy(yas5xx->dev); in yas5xx_fill_buffer()
668 pm_runtime_put_autosuspend(yas5xx->dev); in yas5xx_fill_buffer()
670 dev_err(yas5xx->dev, "error refilling buffer\n"); in yas5xx_fill_buffer()
673 yas5xx->scan.channels[0] = t; in yas5xx_fill_buffer()
674 yas5xx->scan.channels[1] = x; in yas5xx_fill_buffer()
675 yas5xx->scan.channels[2] = y; in yas5xx_fill_buffer()
676 yas5xx->scan.channels[3] = z; in yas5xx_fill_buffer()
677 iio_push_to_buffers_with_timestamp(indio_dev, &yas5xx->scan, in yas5xx_fill_buffer()
684 struct iio_dev *indio_dev = pf->indio_dev; in yas5xx_handle_trigger()
687 iio_trigger_notify_done(indio_dev->trig); in yas5xx_handle_trigger()
699 return &yas5xx->orientation; in yas5xx_get_mount_matrix()
707 #define YAS5XX_AXIS_CHANNEL(axis, index) \ argument
711 .channel2 = IIO_MOD_##axis, \
754 const struct yas5xx_chip_info *ci = yas5xx->chip_info; in yas5xx_volatile_reg()
765 reg_qty = ci->volatile_reg_qty; in yas5xx_volatile_reg()
767 if (reg == ci->volatile_reg[i]) in yas5xx_volatile_reg()
783 * yas530_extract_calibration() - extracts the a2-a9 and k calibration
794 * Bitfield layout for the axis calibration data, for factor in yas530_extract_calibration()
797 * n 7 6 5 4 3 2 1 0 in yas530_extract_calibration()
800 * 2 [ 5 5 5 5 5 5 6 6 ] bits 47 .. 40 in yas530_extract_calibration()
801 * 3 [ 6 6 6 6 7 7 7 7 ] bits 39 .. 32 in yas530_extract_calibration()
804 * 6 [ 9 k k k k k c c ] bits 15 .. 8 in yas530_extract_calibration()
807 c->a2 = FIELD_GET(GENMASK_ULL(63, 58), val) - 32; in yas530_extract_calibration()
808 c->a3 = FIELD_GET(GENMASK_ULL(57, 54), val) - 8; in yas530_extract_calibration()
809 c->a4 = FIELD_GET(GENMASK_ULL(53, 48), val) - 32; in yas530_extract_calibration()
810 c->a5 = FIELD_GET(GENMASK_ULL(47, 42), val) + 38; in yas530_extract_calibration()
811 c->a6 = FIELD_GET(GENMASK_ULL(41, 36), val) - 32; in yas530_extract_calibration()
812 c->a7 = FIELD_GET(GENMASK_ULL(35, 29), val) - 64; in yas530_extract_calibration()
813 c->a8 = FIELD_GET(GENMASK_ULL(28, 23), val) - 32; in yas530_extract_calibration()
814 c->a9 = FIELD_GET(GENMASK_ULL(22, 15), val); in yas530_extract_calibration()
815 c->k = FIELD_GET(GENMASK_ULL(14, 10), val) + 10; in yas530_extract_calibration()
816 c->dck = FIELD_GET(GENMASK_ULL(9, 7), val); in yas530_extract_calibration()
821 struct yas5xx_calibration *c = &yas5xx->calibration; in yas530_get_calibration_data()
827 ret = regmap_bulk_read(yas5xx->map, YAS530_CAL, data, sizeof(data)); in yas530_get_calibration_data()
832 ret = regmap_bulk_read(yas5xx->map, YAS530_CAL, data, sizeof(data)); in yas530_get_calibration_data()
835 dev_dbg(yas5xx->dev, "calibration data: %16ph\n", data); in yas530_get_calibration_data()
841 yas5xx->version = data[15] & GENMASK(1, 0); in yas530_get_calibration_data()
844 c->Cx = data[0] * 6 - 768; in yas530_get_calibration_data()
845 c->Cy1 = data[1] * 6 - 768; in yas530_get_calibration_data()
846 c->Cy2 = data[2] * 6 - 768; in yas530_get_calibration_data()
852 * The r factors are 6 bit values where bit 5 is the sign in yas530_get_calibration_data()
854 * n 7 6 5 4 3 2 1 0 in yas530_get_calibration_data()
861 c->f[0] = FIELD_GET(GENMASK(22, 21), val); in yas530_get_calibration_data()
862 c->f[1] = FIELD_GET(GENMASK(14, 13), val); in yas530_get_calibration_data()
863 c->f[2] = FIELD_GET(GENMASK(6, 5), val); in yas530_get_calibration_data()
864 c->r[0] = sign_extend32(FIELD_GET(GENMASK(28, 23), val), 5); in yas530_get_calibration_data()
865 c->r[1] = sign_extend32(FIELD_GET(GENMASK(20, 15), val), 5); in yas530_get_calibration_data()
866 c->r[2] = sign_extend32(FIELD_GET(GENMASK(12, 7), val), 5); in yas530_get_calibration_data()
873 struct yas5xx_calibration *c = &yas5xx->calibration; in yas532_get_calibration_data()
879 ret = regmap_bulk_read(yas5xx->map, YAS530_CAL, data, sizeof(data)); in yas532_get_calibration_data()
883 ret = regmap_bulk_read(yas5xx->map, YAS530_CAL, data, sizeof(data)); in yas532_get_calibration_data()
886 dev_dbg(yas5xx->dev, "calibration data: %14ph\n", data); in yas532_get_calibration_data()
890 dev_warn(yas5xx->dev, "calibration is blank!\n"); in yas532_get_calibration_data()
896 yas5xx->version = data[13] & BIT(0); in yas532_get_calibration_data()
899 c->Cx = data[0] * 10 - 1280; in yas532_get_calibration_data()
900 c->Cy1 = data[1] * 10 - 1280; in yas532_get_calibration_data()
901 c->Cy2 = data[2] * 10 - 1280; in yas532_get_calibration_data()
907 * The r factors are 6 bit values where bit 5 is the sign in yas532_get_calibration_data()
909 * n 7 6 5 4 3 2 1 0 in yas532_get_calibration_data()
916 c->f[0] = FIELD_GET(GENMASK(24, 23), val); in yas532_get_calibration_data()
917 c->f[1] = FIELD_GET(GENMASK(16, 15), val); in yas532_get_calibration_data()
918 c->f[2] = FIELD_GET(GENMASK(8, 7), val); in yas532_get_calibration_data()
919 c->r[0] = sign_extend32(FIELD_GET(GENMASK(30, 25), val), 5); in yas532_get_calibration_data()
920 c->r[1] = sign_extend32(FIELD_GET(GENMASK(22, 17), val), 5); in yas532_get_calibration_data()
921 c->r[2] = sign_extend32(FIELD_GET(GENMASK(14, 7), val), 5); in yas532_get_calibration_data()
928 struct yas5xx_calibration *c = &yas5xx->calibration; in yas537_get_calibration_data()
934 ret = regmap_write(yas5xx->map, YAS537_SRST, BIT(1)); in yas537_get_calibration_data()
939 ret = regmap_bulk_read(yas5xx->map, YAS537_CAL, data, sizeof(data)); in yas537_get_calibration_data()
942 dev_dbg(yas5xx->dev, "calibration data: %17ph\n", data); in yas537_get_calibration_data()
946 dev_warn(yas5xx->dev, "calibration is blank!\n"); in yas537_get_calibration_data()
952 yas5xx->version = FIELD_GET(GENMASK(7, 6), data[16]); in yas537_get_calibration_data()
955 switch (yas5xx->version) { in yas537_get_calibration_data()
966 * data[6] 0x99 in yas537_get_calibration_data()
981 ret = regmap_write(yas5xx->map, YAS537_MTC + i, in yas537_get_calibration_data()
987 ret = regmap_write(yas5xx->map, YAS537_OFFSET_X + i, in yas537_get_calibration_data()
991 yas5xx->hard_offsets[i] = data[i + 12]; in yas537_get_calibration_data()
994 ret = regmap_write(yas5xx->map, YAS537_HCK + i, in yas537_get_calibration_data()
1021 ret = regmap_write(yas5xx->map, YAS537_MTC + i, in yas537_get_calibration_data()
1027 ret = regmap_write(yas5xx->map, YAS537_OFFSET_X + i, in yas537_get_calibration_data()
1031 yas5xx->hard_offsets[i] = data[i + 12]; in yas537_get_calibration_data()
1036 * data[3] n 7 6 5 4 3 2 1 0 in yas537_get_calibration_data()
1039 * data[15] n 7 6 5 4 3 2 1 0 in yas537_get_calibration_data()
1042 * data[15] n 7 6 5 4 3 2 1 0 in yas537_get_calibration_data()
1045 * data[16] n 7 6 5 4 3 2 1 0 in yas537_get_calibration_data()
1048 ret = regmap_write(yas5xx->map, YAS537_MTC + 3, in yas537_get_calibration_data()
1054 ret = regmap_write(yas5xx->map, YAS537_HCK, in yas537_get_calibration_data()
1059 ret = regmap_write(yas5xx->map, YAS537_LCK, in yas537_get_calibration_data()
1064 ret = regmap_write(yas5xx->map, YAS537_OC, in yas537_get_calibration_data()
1069 * For data extraction, build some blocks. Four 32-bit blocks in yas537_get_calibration_data()
1072 * n 7 6 5 4 3 2 1 0 in yas537_get_calibration_data()
1078 * n 7 6 5 4 3 2 1 0 in yas537_get_calibration_data()
1082 * data[6] 3 [ a4 ] bits 7 .. 0 in yas537_get_calibration_data()
1084 * n 7 6 5 4 3 2 1 0 in yas537_get_calibration_data()
1085 * data[6] 0 [ a5 a5 a5 a5 a5 a5 a5 ] bits 31 .. 24 in yas537_get_calibration_data()
1090 * n 7 6 5 4 3 2 1 0 in yas537_get_calibration_data()
1098 val3 = get_unaligned_be32(&data[6]); in yas537_get_calibration_data()
1101 c->Cx = FIELD_GET(GENMASK(31, 23), val1) - 256; in yas537_get_calibration_data()
1102 c->Cy1 = FIELD_GET(GENMASK(22, 14), val1) - 256; in yas537_get_calibration_data()
1103 c->Cy2 = FIELD_GET(GENMASK(13, 5), val1) - 256; in yas537_get_calibration_data()
1104 c->a2 = FIELD_GET(GENMASK(28, 22), val2) - 64; in yas537_get_calibration_data()
1105 c->a3 = FIELD_GET(GENMASK(21, 15), val2) - 64; in yas537_get_calibration_data()
1106 c->a4 = FIELD_GET(GENMASK(14, 7), val2) - 128; in yas537_get_calibration_data()
1107 c->a5 = FIELD_GET(GENMASK(30, 22), val3) - 112; in yas537_get_calibration_data()
1108 c->a6 = FIELD_GET(GENMASK(21, 15), val3) - 64; in yas537_get_calibration_data()
1109 c->a7 = FIELD_GET(GENMASK(14, 7), val3) - 128; in yas537_get_calibration_data()
1110 c->a8 = FIELD_GET(GENMASK(30, 24), val4) - 64; in yas537_get_calibration_data()
1111 c->a9 = FIELD_GET(GENMASK(23, 15), val4) - 112; in yas537_get_calibration_data()
1112 c->k = FIELD_GET(GENMASK(14, 8), val4); in yas537_get_calibration_data()
1115 dev_err(yas5xx->dev, "unknown version of YAS537\n"); in yas537_get_calibration_data()
1116 return -EINVAL; in yas537_get_calibration_data()
1125 struct yas5xx_calibration *c = &yas5xx->calibration; in yas530_dump_calibration()
1127 dev_dbg(yas5xx->dev, "f[] = [%d, %d, %d]\n", in yas530_dump_calibration()
1128 c->f[0], c->f[1], c->f[2]); in yas530_dump_calibration()
1129 dev_dbg(yas5xx->dev, "r[] = [%d, %d, %d]\n", in yas530_dump_calibration()
1130 c->r[0], c->r[1], c->r[2]); in yas530_dump_calibration()
1131 dev_dbg(yas5xx->dev, "Cx = %d\n", c->Cx); in yas530_dump_calibration()
1132 dev_dbg(yas5xx->dev, "Cy1 = %d\n", c->Cy1); in yas530_dump_calibration()
1133 dev_dbg(yas5xx->dev, "Cy2 = %d\n", c->Cy2); in yas530_dump_calibration()
1134 dev_dbg(yas5xx->dev, "a2 = %d\n", c->a2); in yas530_dump_calibration()
1135 dev_dbg(yas5xx->dev, "a3 = %d\n", c->a3); in yas530_dump_calibration()
1136 dev_dbg(yas5xx->dev, "a4 = %d\n", c->a4); in yas530_dump_calibration()
1137 dev_dbg(yas5xx->dev, "a5 = %d\n", c->a5); in yas530_dump_calibration()
1138 dev_dbg(yas5xx->dev, "a6 = %d\n", c->a6); in yas530_dump_calibration()
1139 dev_dbg(yas5xx->dev, "a7 = %d\n", c->a7); in yas530_dump_calibration()
1140 dev_dbg(yas5xx->dev, "a8 = %d\n", c->a8); in yas530_dump_calibration()
1141 dev_dbg(yas5xx->dev, "a9 = %d\n", c->a9); in yas530_dump_calibration()
1142 dev_dbg(yas5xx->dev, "k = %d\n", c->k); in yas530_dump_calibration()
1143 dev_dbg(yas5xx->dev, "dck = %d\n", c->dck); in yas530_dump_calibration()
1148 struct yas5xx_calibration *c = &yas5xx->calibration; in yas537_dump_calibration()
1150 if (yas5xx->version == YAS537_VERSION_1) { in yas537_dump_calibration()
1151 dev_dbg(yas5xx->dev, "Cx = %d\n", c->Cx); in yas537_dump_calibration()
1152 dev_dbg(yas5xx->dev, "Cy1 = %d\n", c->Cy1); in yas537_dump_calibration()
1153 dev_dbg(yas5xx->dev, "Cy2 = %d\n", c->Cy2); in yas537_dump_calibration()
1154 dev_dbg(yas5xx->dev, "a2 = %d\n", c->a2); in yas537_dump_calibration()
1155 dev_dbg(yas5xx->dev, "a3 = %d\n", c->a3); in yas537_dump_calibration()
1156 dev_dbg(yas5xx->dev, "a4 = %d\n", c->a4); in yas537_dump_calibration()
1157 dev_dbg(yas5xx->dev, "a5 = %d\n", c->a5); in yas537_dump_calibration()
1158 dev_dbg(yas5xx->dev, "a6 = %d\n", c->a6); in yas537_dump_calibration()
1159 dev_dbg(yas5xx->dev, "a7 = %d\n", c->a7); in yas537_dump_calibration()
1160 dev_dbg(yas5xx->dev, "a8 = %d\n", c->a8); in yas537_dump_calibration()
1161 dev_dbg(yas5xx->dev, "a9 = %d\n", c->a9); in yas537_dump_calibration()
1162 dev_dbg(yas5xx->dev, "k = %d\n", c->k); in yas537_dump_calibration()
1171 ret = regmap_write(yas5xx->map, YAS530_OFFSET_X, ox); in yas530_set_offsets()
1174 ret = regmap_write(yas5xx->map, YAS530_OFFSET_Y1, oy1); in yas530_set_offsets()
1177 return regmap_write(yas5xx->map, YAS530_OFFSET_Y2, oy2); in yas530_set_offsets()
1186 return old - BIT(bit); in yas530_adjust_offset()
1193 const struct yas5xx_chip_info *ci = yas5xx->chip_info; in yas530_measure_offsets()
1201 ret = regmap_write(yas5xx->map, YAS530_ACTUATE_INIT_COIL, 0); in yas530_measure_offsets()
1206 switch (ci->devid) { in yas530_measure_offsets()
1214 dev_err(yas5xx->dev, "unknown device type\n"); in yas530_measure_offsets()
1215 return -EINVAL; in yas530_measure_offsets()
1219 * We set offsets in the interval +-31 by iterating in yas530_measure_offsets()
1220 * +-16, +-8, +-4, +-2, +-1 adjusting the offsets each in yas530_measure_offsets()
1225 * as the values for [x, y1, y2]. The value is +/-31 in yas530_measure_offsets()
1234 for (i = 4; i >= 0; i--) { in yas530_measure_offsets()
1242 dev_dbg(yas5xx->dev, "measurement %d: x=%d, y1=%d, y2=%d\n", in yas530_measure_offsets()
1243 5-i, x, y1, y2); in yas530_measure_offsets()
1251 yas5xx->hard_offsets[0] = ox; in yas530_measure_offsets()
1252 yas5xx->hard_offsets[1] = oy1; in yas530_measure_offsets()
1253 yas5xx->hard_offsets[2] = oy2; in yas530_measure_offsets()
1258 dev_info(yas5xx->dev, "discovered hard offsets: x=%d, y1=%d, y2=%d\n", in yas530_measure_offsets()
1270 ret = regmap_write(yas5xx->map, YAS530_TEST1, 0); in yas530_power_on()
1273 ret = regmap_write(yas5xx->map, YAS530_TEST2, 0); in yas530_power_on()
1278 val = FIELD_PREP(YAS5XX_CONFIG_CCK_MASK, yas5xx->calibration.dck); in yas530_power_on()
1279 ret = regmap_write(yas5xx->map, YAS530_CONFIG, val); in yas530_power_on()
1283 /* Measure interval 0 (back-to-back?) */ in yas530_power_on()
1284 return regmap_write(yas5xx->map, YAS530_MEASURE_INTERVAL, 0); in yas530_power_on()
1295 ret = regmap_bulk_write(yas5xx->map, YAS537_ADCCAL, &buf, sizeof(buf)); in yas537_power_on()
1298 ret = regmap_write(yas5xx->map, YAS537_TRM, GENMASK(7, 0)); in yas537_power_on()
1304 - YAS537_MEASURE_TIME_WORST_US) / 4100; in yas537_power_on()
1305 ret = regmap_write(yas5xx->map, YAS537_MEASURE_INTERVAL, intrvl); in yas537_power_on()
1310 ret = regmap_write(yas5xx->map, YAS537_AVR, YAS537_MAG_AVERAGE_32_MASK); in yas537_power_on()
1315 ret = regmap_write(yas5xx->map, YAS537_CONFIG, BIT(3)); in yas537_power_on()
1328 .product_name = "YAS530 MS-3E",
1334 .min_temp_x10 = -620, /* 1/10:s degrees Celsius */
1343 .product_name = "YAS532 MS-3R",
1349 .min_temp_x10 = -500, /* 1/10:s degrees Celsius */
1358 .product_name = "YAS533 MS-3F",
1364 .min_temp_x10 = -500, /* 1/10:s degrees Celsius */
1373 .product_name = "YAS537 MS-3T",
1379 .min_temp_x10 = -3860, /* 1/10:s degrees Celsius */
1392 struct device *dev = &i2c->dev; in yas5xx_probe()
1400 return -ENOMEM; in yas5xx_probe()
1404 yas5xx->dev = dev; in yas5xx_probe()
1405 mutex_init(&yas5xx->lock); in yas5xx_probe()
1407 ret = iio_read_mount_matrix(dev, &yas5xx->orientation); in yas5xx_probe()
1411 yas5xx->regs[0].supply = "vdd"; in yas5xx_probe()
1412 yas5xx->regs[1].supply = "iovdd"; in yas5xx_probe()
1413 ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(yas5xx->regs), in yas5xx_probe()
1414 yas5xx->regs); in yas5xx_probe()
1418 ret = regulator_bulk_enable(ARRAY_SIZE(yas5xx->regs), yas5xx->regs); in yas5xx_probe()
1426 yas5xx->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW); in yas5xx_probe()
1427 if (IS_ERR(yas5xx->reset)) { in yas5xx_probe()
1428 ret = dev_err_probe(dev, PTR_ERR(yas5xx->reset), "failed to get reset line\n"); in yas5xx_probe()
1432 yas5xx->map = devm_regmap_init_i2c(i2c, &yas5xx_regmap_config); in yas5xx_probe()
1433 if (IS_ERR(yas5xx->map)) { in yas5xx_probe()
1434 ret = dev_err_probe(dev, PTR_ERR(yas5xx->map), "failed to allocate register map\n"); in yas5xx_probe()
1440 ci = (const struct yas5xx_chip_info *)id->driver_data; in yas5xx_probe()
1441 yas5xx->chip_info = ci; in yas5xx_probe()
1443 ret = regmap_read(yas5xx->map, YAS5XX_DEVICE_ID, &id_check); in yas5xx_probe()
1447 if (id_check != ci->devid) { in yas5xx_probe()
1448 ret = dev_err_probe(dev, -ENODEV, in yas5xx_probe()
1450 id_check, id->name); in yas5xx_probe()
1454 ret = ci->get_calibration_data(yas5xx); in yas5xx_probe()
1458 dev_info(dev, "detected %s %s\n", ci->product_name, in yas5xx_probe()
1459 ci->version_names[yas5xx->version]); in yas5xx_probe()
1461 ci->dump_calibration(yas5xx); in yas5xx_probe()
1463 ret = ci->power_on(yas5xx); in yas5xx_probe()
1467 if (ci->measure_offsets) { in yas5xx_probe()
1468 ret = ci->measure_offsets(yas5xx); in yas5xx_probe()
1473 indio_dev->info = &yas5xx_info; in yas5xx_probe()
1474 indio_dev->available_scan_masks = yas5xx_scan_masks; in yas5xx_probe()
1475 indio_dev->modes = INDIO_DIRECT_MODE; in yas5xx_probe()
1476 indio_dev->name = id->name; in yas5xx_probe()
1477 indio_dev->channels = yas5xx_channels; in yas5xx_probe()
1478 indio_dev->num_channels = ARRAY_SIZE(yas5xx_channels); in yas5xx_probe()
1508 gpiod_set_value_cansleep(yas5xx->reset, 1); in yas5xx_probe()
1510 regulator_bulk_disable(ARRAY_SIZE(yas5xx->regs), yas5xx->regs); in yas5xx_probe()
1519 struct device *dev = &i2c->dev; in yas5xx_remove()
1531 gpiod_set_value_cansleep(yas5xx->reset, 1); in yas5xx_remove()
1532 regulator_bulk_disable(ARRAY_SIZE(yas5xx->regs), yas5xx->regs); in yas5xx_remove()
1540 gpiod_set_value_cansleep(yas5xx->reset, 1); in yas5xx_runtime_suspend()
1541 regulator_bulk_disable(ARRAY_SIZE(yas5xx->regs), yas5xx->regs); in yas5xx_runtime_suspend()
1550 const struct yas5xx_chip_info *ci = yas5xx->chip_info; in yas5xx_runtime_resume()
1553 ret = regulator_bulk_enable(ARRAY_SIZE(yas5xx->regs), yas5xx->regs); in yas5xx_runtime_resume()
1565 gpiod_set_value_cansleep(yas5xx->reset, 0); in yas5xx_runtime_resume()
1567 ret = ci->power_on(yas5xx); in yas5xx_runtime_resume()
1576 gpiod_set_value_cansleep(yas5xx->reset, 1); in yas5xx_runtime_resume()
1577 regulator_bulk_disable(ARRAY_SIZE(yas5xx->regs), yas5xx->regs); in yas5xx_runtime_resume()
1615 MODULE_DESCRIPTION("Yamaha YAS53x 3-axis magnetometer driver");