Skip to contentSkip to conversation

staging: iio: hmc5843: Set iio name dynamically based on i2c name

PATCH Superseded [email protected] 2 participants 3 messages Aug 12, 2015

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: iio: hmc5843: Set iio name dynamically based on i2c name

From: Yong Li <[email protected]>

Load the driver using the below command:
echo hmc5983 0x1e > /sys/bus/i2c/devices/i2c-?/new_device

In sysfs, the iio name is hmc5843, however the i2c name is hmc5983, they are inconsistent.

With this patch, the iio name will be the same as the i2c device name

---
 drivers/staging/iio/magnetometer/hmc5843_i2c.c | 1 +
 1 file changed, 1 insertion(+)
drivers/staging/iio/magnetometer/hmc5843_i2c.c +1 -0
index ff08667..3b03644 100644
@@ -59,6 +59,7 @@ static const struct regmap_config hmc5843_i2c_regmap_config = {
 static int hmc5843_i2c_probe(struct i2c_client *cli,
 			     const struct i2c_device_id *id)
 {
+	cli->dev.driver->name = id->name;
 	return hmc5843_common_probe(&cli->dev,
 			devm_regmap_init_i2c(cli, &hmc5843_i2c_regmap_config),
 			id->driver_data);
Signature · 1 line
2.1.0
#1 lore raw
Quoted 20 lines · On 08/12/2015 10:20 AM, [email protected] wrote:

From: Yong Li <[email protected]>

Load the driver using the below command:
echo hmc5983 0x1e > /sys/bus/i2c/devices/i2c-?/new_device

In sysfs, the iio name is hmc5843, however the i2c name is hmc5983, they are inconsistent.

With this patch, the iio name will be the same as the i2c device name

---
 drivers/staging/iio/magnetometer/hmc5843_i2c.c | 1 +
 1 file changed, 1 insertion(+)
drivers/staging/iio/magnetometer/hmc5843_i2c.c +0 -0
index ff08667..3b03644 100644

drivers/staging/iio/magnetometer/hmc5843_i2c.c static const struct regmap_config hmc5843_i2c_regmap_config = { · line 62

Quoted 4 lines
drivers/staging/iio/magnetometer/hmc5843_i2c.c +1 -0
@@ -59,6 +59,7 @@ static const struct regmap_config hmc5843_i2c_regmap_config = {
 static int hmc5843_i2c_probe(struct i2c_client *cli,
 			     const struct i2c_device_id *id)
 {
+	cli->dev.driver->name = id->name;

You are overwriting a the name of the driver, which is a struct that is shared between all instances of the device which specific data from one device. That is most certainly not correct.

Update hmc5843_common_probe() and add a parameter that takes the name for the device and then pass the id->name when the function is called.

Quoted 4 lines
drivers/staging/iio/magnetometer/hmc5843_i2c.c +0 -0
 	return hmc5843_common_probe(&cli->dev,
 			devm_regmap_init_i2c(cli, &hmc5843_i2c_regmap_config),
 			id->driver_data);
author
#2 lore raw

dGhhbmtzIGZvciB5b3VyIGNvbW1lbnRzLiBsZXQgbWUgc3VibWl0IGFub3RoZXIgb25lDQoNCrei 19TO0rXEIGlQaG9uZQ0KDQo+INTaIDIwMTXE6jjUwjEyyNWjrDE2OjI4o6xMYXJzLVBldGVyIENs YXVzZW4gPGxhcnNAbWV0YWZvby5kZT4g0LS1wKO6DQo+IA0KPj4gT24gMDgvMTIvMjAxNSAxMDoy MCBBTSwgc2RsaXlvbmdAZ21haWwuY29tIHdyb3RlOg0KPj4gRnJvbTogWW9uZyBMaSA8c2RsaXlv bmdAZ21haWwuY29tPg0KPj4gDQo+PiBMb2FkIHRoZSBkcml2ZXIgdXNpbmcgdGhlIGJlbG93IGNv bW1hbmQ6DQo+PiBlY2hvIGhtYzU5ODMgMHgxZSA+IC9zeXMvYnVzL2kyYy9kZXZpY2VzL2kyYy0/ L25ld19kZXZpY2UNCj4+IA0KPj4gSW4gc3lzZnMsIHRoZSBpaW8gbmFtZSBpcyBobWM1ODQzLCBo b3dldmVyIHRoZSBpMmMgbmFtZSBpcyBobWM1OTgzLA0KPj4gdGhleSBhcmUgaW5jb25zaXN0ZW50 Lg0KPj4gDQo+PiBXaXRoIHRoaXMgcGF0Y2gsIHRoZSBpaW8gbmFtZSB3aWxsIGJlIHRoZSBzYW1l IGFzIHRoZSBpMmMgZGV2aWNlIG5hbWUNCj4+IA0KPj4gU2lnbmVkLW9mZi1ieTogWW9uZyBMaSA8 c2RsaXlvbmdAZ21haWwuY29tPg0KPj4gLS0tDQo+Pi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