Lines Matching refs:yas5xx

166 struct yas5xx;
199 int (*get_measure)(struct yas5xx *yas5xx, s32 *to, s32 *xo, s32 *yo, s32 *zo);
200 int (*get_calibration_data)(struct yas5xx *yas5xx);
201 void (*dump_calibration)(struct yas5xx *yas5xx);
202 int (*measure_offsets)(struct yas5xx *yas5xx);
203 int (*power_on)(struct yas5xx *yas5xx);
207 * struct yas5xx - state container for the YAS5xx driver
222 struct yas5xx {
275 * @yas5xx: The device state
284 static int yas530_measure(struct yas5xx *yas5xx, u16 *t, u16 *x, u16 *y1, u16 *y2)
286 const struct yas5xx_chip_info *ci = yas5xx->chip_info;
292 mutex_lock(&yas5xx->lock);
293 ret = regmap_write(yas5xx->map, YAS530_MEASURE, YAS5XX_MEASURE_START);
302 ret = regmap_read_poll_timeout(yas5xx->map, YAS5XX_MEASURE_DATA, busy,
306 dev_err(yas5xx->dev, "timeout waiting for measurement\n");
310 ret = regmap_bulk_read(yas5xx->map, YAS5XX_MEASURE_DATA,
315 mutex_unlock(&yas5xx->lock);
347 dev_err(yas5xx->dev, "unknown data format\n");
355 mutex_unlock(&yas5xx->lock);
361 * @yas5xx: The device state
368 static int yas537_measure(struct yas5xx *yas5xx, u16 *t, u16 *x, u16 *y1, u16 *y2)
370 struct yas5xx_calibration *c = &yas5xx->calibration;
377 mutex_lock(&yas5xx->lock);
380 ret = regmap_write(yas5xx->map, YAS537_MEASURE, YAS5XX_MEASURE_START |
386 ret = regmap_read_poll_timeout(yas5xx->map, YAS5XX_MEASURE_DATA + 2, busy,
390 dev_err(yas5xx->dev, "timeout waiting for measurement\n");
394 ret = regmap_bulk_read(yas5xx->map, YAS5XX_MEASURE_DATA,
399 mutex_unlock(&yas5xx->lock);
407 if (yas5xx->version == YAS537_VERSION_1) {
426 mutex_unlock(&yas5xx->lock);
431 static s32 yas530_linearize(struct yas5xx *yas5xx, u16 val, int axis)
433 const struct yas5xx_chip_info *ci = yas5xx->chip_info;
434 struct yas5xx_calibration *c = &yas5xx->calibration;
445 if (yas5xx->version == YAS530_VERSION_A)
451 if (yas5xx->version == YAS532_VERSION_AB)
458 dev_err(yas5xx->dev, "unknown device type\n");
470 (yas5xx->hard_offsets[axis] - c->r[axis]) * coef;
473 static s32 yas5xx_calc_temperature(struct yas5xx *yas5xx, u16 t)
475 const struct yas5xx_chip_info *ci = yas5xx->chip_info;
491 * @yas5xx: The device state
500 static int yas530_get_measure(struct yas5xx *yas5xx, s32 *to, s32 *xo, s32 *yo, s32 *zo)
502 const struct yas5xx_chip_info *ci = yas5xx->chip_info;
503 struct yas5xx_calibration *c = &yas5xx->calibration;
510 ret = yas530_measure(yas5xx, &t, &x, &y1, &y2);
515 sx = yas530_linearize(yas5xx, x, 0);
516 sy1 = yas530_linearize(yas5xx, y1, 1);
517 sy2 = yas530_linearize(yas5xx, y2, 2);
526 yas5xx->version == YAS532_VERSION_AC) {
551 *to = yas5xx_calc_temperature(yas5xx, t);
577 * @yas5xx: The device state
584 static int yas537_get_measure(struct yas5xx *yas5xx, s32 *to, s32 *xo, s32 *yo, s32 *zo)
590 ret = yas537_measure(yas5xx, &t, &x, &y1, &y2);
595 *to = yas5xx_calc_temperature(yas5xx, t);
615 struct yas5xx *yas5xx = iio_priv(indio_dev);
616 const struct yas5xx_chip_info *ci = yas5xx->chip_info;
623 pm_runtime_get_sync(yas5xx->dev);
624 ret = ci->get_measure(yas5xx, &t, &x, &y, &z);
625 pm_runtime_mark_last_busy(yas5xx->dev);
626 pm_runtime_put_autosuspend(yas5xx->dev);
643 dev_err(yas5xx->dev, "unknown channel\n");
659 struct yas5xx *yas5xx = iio_priv(indio_dev);
660 const struct yas5xx_chip_info *ci = yas5xx->chip_info;
664 pm_runtime_get_sync(yas5xx->dev);
665 ret = ci->get_measure(yas5xx, &t, &x, &y, &z);
666 pm_runtime_mark_last_busy(yas5xx->dev);
667 pm_runtime_put_autosuspend(yas5xx->dev);
669 dev_err(yas5xx->dev, "error refilling buffer\n");
672 yas5xx->scan.channels[0] = t;
673 yas5xx->scan.channels[1] = x;
674 yas5xx->scan.channels[2] = y;
675 yas5xx->scan.channels[3] = z;
676 iio_push_to_buffers_with_timestamp(indio_dev, &yas5xx->scan,
696 struct yas5xx *yas5xx = iio_priv(indio_dev);
698 return &yas5xx->orientation;
752 struct yas5xx *yas5xx = iio_priv(indio_dev);
753 const struct yas5xx_chip_info *ci = yas5xx->chip_info;
818 static int yas530_get_calibration_data(struct yas5xx *yas5xx)
820 struct yas5xx_calibration *c = &yas5xx->calibration;
826 ret = regmap_bulk_read(yas5xx->map, YAS530_CAL, data, sizeof(data));
831 ret = regmap_bulk_read(yas5xx->map, YAS530_CAL, data, sizeof(data));
834 dev_dbg(yas5xx->dev, "calibration data: %16ph\n", data);
840 yas5xx->version = data[15] & GENMASK(1, 0);
870 static int yas532_get_calibration_data(struct yas5xx *yas5xx)
872 struct yas5xx_calibration *c = &yas5xx->calibration;
878 ret = regmap_bulk_read(yas5xx->map, YAS530_CAL, data, sizeof(data));
882 ret = regmap_bulk_read(yas5xx->map, YAS530_CAL, data, sizeof(data));
885 dev_dbg(yas5xx->dev, "calibration data: %14ph\n", data);
889 dev_warn(yas5xx->dev, "calibration is blank!\n");
895 yas5xx->version = data[13] & BIT(0);
925 static int yas537_get_calibration_data(struct yas5xx *yas5xx)
927 struct yas5xx_calibration *c = &yas5xx->calibration;
933 ret = regmap_write(yas5xx->map, YAS537_SRST, BIT(1));
938 ret = regmap_bulk_read(yas5xx->map, YAS537_CAL, data, sizeof(data));
941 dev_dbg(yas5xx->dev, "calibration data: %17ph\n", data);
945 dev_warn(yas5xx->dev, "calibration is blank!\n");
951 yas5xx->version = FIELD_GET(GENMASK(7, 6), data[16]);
954 switch (yas5xx->version) {
980 ret = regmap_write(yas5xx->map, YAS537_MTC + i,
986 ret = regmap_write(yas5xx->map, YAS537_OFFSET_X + i,
990 yas5xx->hard_offsets[i] = data[i + 12];
993 ret = regmap_write(yas5xx->map, YAS537_HCK + i,
1020 ret = regmap_write(yas5xx->map, YAS537_MTC + i,
1026 ret = regmap_write(yas5xx->map, YAS537_OFFSET_X + i,
1030 yas5xx->hard_offsets[i] = data[i + 12];
1047 ret = regmap_write(yas5xx->map, YAS537_MTC + 3,
1053 ret = regmap_write(yas5xx->map, YAS537_HCK,
1058 ret = regmap_write(yas5xx->map, YAS537_LCK,
1063 ret = regmap_write(yas5xx->map, YAS537_OC,
1114 dev_err(yas5xx->dev, "unknown version of YAS537\n");
1122 static void yas530_dump_calibration(struct yas5xx *yas5xx)
1124 struct yas5xx_calibration *c = &yas5xx->calibration;
1126 dev_dbg(yas5xx->dev, "f[] = [%d, %d, %d]\n",
1128 dev_dbg(yas5xx->dev, "r[] = [%d, %d, %d]\n",
1130 dev_dbg(yas5xx->dev, "Cx = %d\n", c->Cx);
1131 dev_dbg(yas5xx->dev, "Cy1 = %d\n", c->Cy1);
1132 dev_dbg(yas5xx->dev, "Cy2 = %d\n", c->Cy2);
1133 dev_dbg(yas5xx->dev, "a2 = %d\n", c->a2);
1134 dev_dbg(yas5xx->dev, "a3 = %d\n", c->a3);
1135 dev_dbg(yas5xx->dev, "a4 = %d\n", c->a4);
1136 dev_dbg(yas5xx->dev, "a5 = %d\n", c->a5);
1137 dev_dbg(yas5xx->dev, "a6 = %d\n", c->a6);
1138 dev_dbg(yas5xx->dev, "a7 = %d\n", c->a7);
1139 dev_dbg(yas5xx->dev, "a8 = %d\n", c->a8);
1140 dev_dbg(yas5xx->dev, "a9 = %d\n", c->a9);
1141 dev_dbg(yas5xx->dev, "k = %d\n", c->k);
1142 dev_dbg(yas5xx->dev, "dck = %d\n", c->dck);
1145 static void yas537_dump_calibration(struct yas5xx *yas5xx)
1147 struct yas5xx_calibration *c = &yas5xx->calibration;
1149 if (yas5xx->version == YAS537_VERSION_1) {
1150 dev_dbg(yas5xx->dev, "Cx = %d\n", c->Cx);
1151 dev_dbg(yas5xx->dev, "Cy1 = %d\n", c->Cy1);
1152 dev_dbg(yas5xx->dev, "Cy2 = %d\n", c->Cy2);
1153 dev_dbg(yas5xx->dev, "a2 = %d\n", c->a2);
1154 dev_dbg(yas5xx->dev, "a3 = %d\n", c->a3);
1155 dev_dbg(yas5xx->dev, "a4 = %d\n", c->a4);
1156 dev_dbg(yas5xx->dev, "a5 = %d\n", c->a5);
1157 dev_dbg(yas5xx->dev, "a6 = %d\n", c->a6);
1158 dev_dbg(yas5xx->dev, "a7 = %d\n", c->a7);
1159 dev_dbg(yas5xx->dev, "a8 = %d\n", c->a8);
1160 dev_dbg(yas5xx->dev, "a9 = %d\n", c->a9);
1161 dev_dbg(yas5xx->dev, "k = %d\n", c->k);
1166 static int yas530_set_offsets(struct yas5xx *yas5xx, s8 ox, s8 oy1, s8 oy2)
1170 ret = regmap_write(yas5xx->map, YAS530_OFFSET_X, ox);
1173 ret = regmap_write(yas5xx->map, YAS530_OFFSET_Y1, oy1);
1176 return regmap_write(yas5xx->map, YAS530_OFFSET_Y2, oy2);
1190 static int yas530_measure_offsets(struct yas5xx *yas5xx)
1192 const struct yas5xx_chip_info *ci = yas5xx->chip_info;
1200 ret = regmap_write(yas5xx->map, YAS530_ACTUATE_INIT_COIL, 0);
1213 dev_err(yas5xx->dev, "unknown device type\n");
1234 ret = yas530_set_offsets(yas5xx, ox, oy1, oy2);
1238 ret = yas530_measure(yas5xx, &t, &x, &y1, &y2);
1241 dev_dbg(yas5xx->dev, "measurement %d: x=%d, y1=%d, y2=%d\n",
1250 yas5xx->hard_offsets[0] = ox;
1251 yas5xx->hard_offsets[1] = oy1;
1252 yas5xx->hard_offsets[2] = oy2;
1253 ret = yas530_set_offsets(yas5xx, ox, oy1, oy2);
1257 dev_info(yas5xx->dev, "discovered hard offsets: x=%d, y1=%d, y2=%d\n",
1263 static int yas530_power_on(struct yas5xx *yas5xx)
1269 ret = regmap_write(yas5xx->map, YAS530_TEST1, 0);
1272 ret = regmap_write(yas5xx->map, YAS530_TEST2, 0);
1277 val = FIELD_PREP(YAS5XX_CONFIG_CCK_MASK, yas5xx->calibration.dck);
1278 ret = regmap_write(yas5xx->map, YAS530_CONFIG, val);
1283 return regmap_write(yas5xx->map, YAS530_MEASURE_INTERVAL, 0);
1286 static int yas537_power_on(struct yas5xx *yas5xx)
1294 ret = regmap_bulk_write(yas5xx->map, YAS537_ADCCAL, &buf, sizeof(buf));
1297 ret = regmap_write(yas5xx->map, YAS537_TRM, GENMASK(7, 0));
1304 ret = regmap_write(yas5xx->map, YAS537_MEASURE_INTERVAL, intrvl);
1309 ret = regmap_write(yas5xx->map, YAS537_AVR, YAS537_MAG_AVERAGE_32_MASK);
1314 ret = regmap_write(yas5xx->map, YAS537_CONFIG, BIT(3));
1392 struct yas5xx *yas5xx;
1397 indio_dev = devm_iio_device_alloc(dev, sizeof(*yas5xx));
1401 yas5xx = iio_priv(indio_dev);
1403 yas5xx->dev = dev;
1404 mutex_init(&yas5xx->lock);
1406 ret = iio_read_mount_matrix(dev, &yas5xx->orientation);
1410 yas5xx->regs[0].supply = "vdd";
1411 yas5xx->regs[1].supply = "iovdd";
1412 ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(yas5xx->regs),
1413 yas5xx->regs);
1417 ret = regulator_bulk_enable(ARRAY_SIZE(yas5xx->regs), yas5xx->regs);
1425 yas5xx->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
1426 if (IS_ERR(yas5xx->reset)) {
1427 ret = dev_err_probe(dev, PTR_ERR(yas5xx->reset), "failed to get reset line\n");
1431 yas5xx->map = devm_regmap_init_i2c(i2c, &yas5xx_regmap_config);
1432 if (IS_ERR(yas5xx->map)) {
1433 ret = dev_err_probe(dev, PTR_ERR(yas5xx->map), "failed to allocate register map\n");
1438 yas5xx->chip_info = ci;
1440 ret = regmap_read(yas5xx->map, YAS5XX_DEVICE_ID, &id_check);
1451 ret = ci->get_calibration_data(yas5xx);
1456 ci->version_names[yas5xx->version]);
1458 ci->dump_calibration(yas5xx);
1460 ret = ci->power_on(yas5xx);
1465 ret = ci->measure_offsets(yas5xx);
1505 gpiod_set_value_cansleep(yas5xx->reset, 1);
1507 regulator_bulk_disable(ARRAY_SIZE(yas5xx->regs), yas5xx->regs);
1515 struct yas5xx *yas5xx = iio_priv(indio_dev);
1528 gpiod_set_value_cansleep(yas5xx->reset, 1);
1529 regulator_bulk_disable(ARRAY_SIZE(yas5xx->regs), yas5xx->regs);
1535 struct yas5xx *yas5xx = iio_priv(indio_dev);
1537 gpiod_set_value_cansleep(yas5xx->reset, 1);
1538 regulator_bulk_disable(ARRAY_SIZE(yas5xx->regs), yas5xx->regs);
1546 struct yas5xx *yas5xx = iio_priv(indio_dev);
1547 const struct yas5xx_chip_info *ci = yas5xx->chip_info;
1550 ret = regulator_bulk_enable(ARRAY_SIZE(yas5xx->regs), yas5xx->regs);
1562 gpiod_set_value_cansleep(yas5xx->reset, 0);
1564 ret = ci->power_on(yas5xx);
1573 gpiod_set_value_cansleep(yas5xx->reset, 1);
1574 regulator_bulk_disable(ARRAY_SIZE(yas5xx->regs), yas5xx->regs);
1602 .name = "yas5xx",