iio: magnetometer: yamaha-yas530: Ad-hoc cleanups
cover iio: magnetometer: yamaha-yas530: Ad-hoc cleanups
Some small cleanups against yamaha-yas530 driver. I wanted to produce more but have had no time so far, hence just this mini-series.
Andy Shevchenko (3):
iio: magnetometer: yamaha-yas530: Get rid of
i2c_client_get_device_id()
iio: magnetometer: yamaha-yas530: Use devm_mutex_init() for mutex
initialization
iio: magnetometer: yamaha-yas530: replace usleep_range() with fsleep()
drivers/iio/magnetometer/yamaha-yas530.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)
Signature · 1 line
2.50.1
PATCH 1/3 iio: magnetometer: yamaha-yas530: Get rid of i2c_client_get_device_id()
Instead of relying on the name from ID table, which might be ambiguous in some cases, use explicit product label in the driver data. With that being done, get rid of i2c_client_get_device_id() call.
--- drivers/iio/magnetometer/yamaha-yas530.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/iio/magnetometer/yamaha-yas530.c +8 -3
@@ -168,6 +168,7 @@ struct yas5xx;/** * struct yas5xx_chip_info - device-specific data and function pointers * @devid: device ID number +* @product_label: product label used in Linux * @product_name: product name of the YAS variant * @version_names: version letters or namings * @volatile_reg: device-specific volatile registers
@@ -189,6 +190,7 @@ struct yas5xx;*/ struct yas5xx_chip_info {unsigned int devid; +const char *product_label;const char *product_name;const char *version_names[2 ];const int *volatile_reg;
@@ -1323,6 +1325,7 @@ static int yas537_power_on(struct yas5xx *yas5xx)static const struct yas5xx_chip_info yas5xx_chip_info_tbl[] = { [yas530] = { .devid =YAS530_DEVICE_ID , + .product_label ="yas530" , .product_name ="YAS530 MS-3E" , .version_names = {"A" ,"B" }, .volatile_reg = yas530_volatile_reg,
@@ -1338,6 +1341,7 @@ static const struct yas5xx_chip_info yas5xx_chip_info_tbl[] = { }, [yas532] = { .devid = YAS532_DEVICE_ID, + .product_label = "yas532", .product_name = "YAS532 MS-3R", .version_names = { "AB", "AC" }, .volatile_reg = yas530_volatile_reg,
@@ -1353,6 +1357,7 @@ static const struct yas5xx_chip_info yas5xx_chip_info_tbl[] = { }, [yas533] = { .devid = YAS532_DEVICE_ID, + .product_label = "yas533", .product_name = "YAS533 MS-3F", .version_names = { "AB", "AC" }, .volatile_reg = yas530_volatile_reg,
@@ -1368,6 +1373,7 @@ static const struct yas5xx_chip_info yas5xx_chip_info_tbl[] = { }, [yas537] = { .devid = YAS537_DEVICE_ID, + .product_label = "yas537", .product_name = "YAS537 MS-3T", .version_names = { "v0", "v1" }, /* version naming unknown */ .volatile_reg = yas537_volatile_reg,
@@ -1385,7 +1391,6 @@ static const struct yas5xx_chip_info yas5xx_chip_info_tbl[] = {static int yas5xx_probe (struct i2c_client *i2c) { -const struct i2c_device_id *id =i2c_client_get_device_id (i2c);struct iio_dev *indio_dev;struct device *dev = &i2c->dev;struct yas5xx *yas5xx;
@@ -1443,7 +1448,7 @@ static int yas5xx_probe(struct i2c_client *i2c)if (id_check != ci->devid) { ret =dev_err_probe (dev, -ENODEV ,"device ID %02x doesn't match %s\n" , - id_check, id->name); + id_check, ci->product_label); goto assert_reset; }
@@ -1469,7 +1474,7 @@ static int yas5xx_probe(struct i2c_client *i2c) indio_dev->info = &yas5xx_info; indio_dev->available_scan_masks = yas5xx_scan_masks; indio_dev->modes =INDIO_DIRECT_MODE ; - indio_dev->name = id->name; + indio_dev->name = ci->product_label; indio_dev->channels = yas5xx_channels; indio_dev->num_channels =ARRAY_SIZE (yas5xx_channels);
Signature · 1 line
2.50.1
PATCH 2/3 iio: magnetometer: yamaha-yas530: Use devm_mutex_init() for mutex initialization
In reply to Andy ShevchenkoUse devm_mutex_init() since it brings some benefits when CONFIG_DEBUG_MUTEXES is enabled.
--- drivers/iio/magnetometer/yamaha-yas530.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/iio/magnetometer/yamaha-yas530.c +4 -1
@@ -1405,7 +1405,10 @@ static int yas5xx_probe(struct i2c_client *i2c) yas5xx =iio_priv (indio_dev);i2c_set_clientdata (i2c, indio_dev); yas5xx->dev = dev; -mutex_init (&yas5xx->lock); + + ret =devm_mutex_init (dev, &yas5xx->lock); +if (ret) +return ret; ret =iio_read_mount_matrix (dev, &yas5xx->orientation);if (ret)
Signature · 1 line
2.50.1
PATCH 3/3 iio: magnetometer: yamaha-yas530: replace usleep_range() with fsleep()
In reply to Andy ShevchenkoReplace usleep_range() with fsleep() to allow the kernel to select the most appropriate delay mechanism based on duration. Using USEC_PER_MSEC makes the unit conversion explicit.
--- drivers/iio/magnetometer/yamaha-yas530.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/iio/magnetometer/yamaha-yas530.c +3 -3
@@ -1317,7 +1317,7 @@ static int yas537_power_on(struct yas5xx *yas5xx)return ret;/* Wait until the coil has ramped up */ -usleep_range (YAS537_MAG_RCOIL_TIME_US ,YAS537_MAG_RCOIL_TIME_US +100 ); +fsleep (YAS537_MAG_RCOIL_TIME_US );return 0 ; }
@@ -1426,7 +1426,7 @@ static int yas5xx_probe(struct i2c_client *i2c)return dev_err_probe (dev, ret,"cannot enable regulators\n" );/* See comment in runtime resume callback */ -usleep_range (31000 ,40000 ); +fsleep (31 *USEC_PER_MSEC );/* This will take the device out of reset if need be */ yas5xx->reset =devm_gpiod_get_optional (dev,"reset" ,GPIOD_OUT_LOW );
@@ -1565,7 +1565,7 @@ static int yas5xx_runtime_resume(struct device *dev)* for all voltages to settle. The YAS532 is 10ms then 4ms for the * I2C to come online. Let's keep it safe and put this at 31ms. */ -usleep_range (31000 ,40000 ); +fsleep (31 *USEC_PER_MSEC );gpiod_set_value_cansleep (yas5xx->reset,0 ); ret = ci->power_on (yas5xx);
Signature · 1 line
2.50.1
Quoted 2 lines · On Fri, 8 May 2026 08:08:32 +0200 Andy Shevchenko…
Some small cleanups against yamaha-yas530 driver. I wanted to produce more but have had no time so far, hence just this mini-series.
Applied.
Thanks,
J
Quoted 11 lines
Andy Shevchenko (3):
iio: magnetometer: yamaha-yas530: Get rid ofi2c_client_get_device_id()iio: magnetometer: yamaha-yas530: Use
devm_mutex_init()for mutex
initialization
iio: magnetometer: yamaha-yas530: replaceusleep_range()withfsleep()drivers/iio/magnetometer/yamaha-yas530.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)