Skip to content

Commit 913fd40

Browse files
Jakko3jic23
authored andcommitted
iio: magnetometer: yas530: Add IIO scaling to "chip_info"
Add IIO scaling to the "chip_info" structure to ease the handling to different YAS variants. Signed-off-by: Jakob Hauser <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Reviewed-by: Linus Walleij <[email protected]> Link: https://lore.kernel.org/r/a12f892633bbee13a8856c231dc793ebbc5d3a03.1660337264.git.jahau@rocketmail.com Signed-off-by: Jonathan Cameron <[email protected]>
1 parent dd9bd44 commit 913fd40

File tree

1 file changed

+7
-21
lines changed

1 file changed

+7
-21
lines changed

drivers/iio/magnetometer/yamaha-yas530.c

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,15 @@ struct yas5xx;
130130
* @version_names: version letters or namings
131131
* @volatile_reg: device-specific volatile registers
132132
* @volatile_reg_qty: quantity of device-specific volatile registers
133+
* @scaling_val2: scaling value for IIO_CHAN_INFO_SCALE
133134
*/
134135
struct yas5xx_chip_info {
135136
unsigned int devid;
136137
char *product_name;
137138
char *version_names[2];
138139
const int *volatile_reg;
139140
int volatile_reg_qty;
141+
u32 scaling_val2;
140142
};
141143

142144
/**
@@ -504,27 +506,8 @@ static int yas5xx_read_raw(struct iio_dev *indio_dev,
504506
}
505507
return IIO_VAL_INT;
506508
case IIO_CHAN_INFO_SCALE:
507-
switch (ci->devid) {
508-
case YAS530_DEVICE_ID:
509-
/*
510-
* Raw values of YAS530 are in picotesla. Divide by
511-
* 100000000 (10^8) to get Gauss.
512-
*/
513-
*val = 1;
514-
*val2 = 100000000;
515-
break;
516-
case YAS532_DEVICE_ID:
517-
/*
518-
* Raw values of YAS532 are in nanotesla. Divide by
519-
* 100000 (10^5) to get Gauss.
520-
*/
521-
*val = 1;
522-
*val2 = 100000;
523-
break;
524-
default:
525-
dev_err(yas5xx->dev, "unknown device type\n");
526-
return -EINVAL;
527-
}
509+
*val = 1;
510+
*val2 = ci->scaling_val2;
528511
return IIO_VAL_FRACTIONAL;
529512
default:
530513
/* Unknown request */
@@ -951,20 +934,23 @@ static const struct yas5xx_chip_info yas5xx_chip_info_tbl[] = {
951934
.version_names = { "A", "B" },
952935
.volatile_reg = yas530_volatile_reg,
953936
.volatile_reg_qty = ARRAY_SIZE(yas530_volatile_reg),
937+
.scaling_val2 = 100000000, /* picotesla to Gauss */
954938
},
955939
[yas532] = {
956940
.devid = YAS532_DEVICE_ID,
957941
.product_name = "YAS532 MS-3R",
958942
.version_names = { "AB", "AC" },
959943
.volatile_reg = yas530_volatile_reg,
960944
.volatile_reg_qty = ARRAY_SIZE(yas530_volatile_reg),
945+
.scaling_val2 = 100000, /* nanotesla to Gauss */
961946
},
962947
[yas533] = {
963948
.devid = YAS532_DEVICE_ID,
964949
.product_name = "YAS533 MS-3F",
965950
.version_names = { "AB", "AC" },
966951
.volatile_reg = yas530_volatile_reg,
967952
.volatile_reg_qty = ARRAY_SIZE(yas530_volatile_reg),
953+
.scaling_val2 = 100000, /* nanotesla to Gauss */
968954
},
969955
};
970956

0 commit comments

Comments
 (0)