diff options
author | Frank Schaefer <fschaefer.oss@googlemail.com> | 2017-04-16 14:41:52 -0300 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@s-opensource.com> | 2017-04-17 17:29:51 -0300 |
commit | 4d58443696a8e2a4bcae3fc6d32b0bee71ad9fa1 (patch) | |
tree | 6681476d6b0059959209face2f786e29bb6b84b7 /drivers | |
parent | e7080d4471d805d921a9ea21b32f911a91e248cb (diff) | |
download | linux-stable-4d58443696a8e2a4bcae3fc6d32b0bee71ad9fa1.tar.gz linux-stable-4d58443696a8e2a4bcae3fc6d32b0bee71ad9fa1.tar.bz2 linux-stable-4d58443696a8e2a4bcae3fc6d32b0bee71ad9fa1.zip |
[media] em28xx: simplify ID-reading from Micron sensors
Use i2c_smbus_read_word_data() instead of i2c_master_send() and
i2c_master_recv() for reading the ID of Micorn sensors.
i2c_smbus_read_word_data() assumes that byes are in little-endian,
so, it uses:
data->word = msgbuf1[0] | (msgbuf1[1] << 8);
However, Micron datasheet describes the ID as if they were read
in big-endian. So, we need to change the byte order in order to
match the ID number as described on their datasheets.
Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/media/usb/em28xx/em28xx-camera.c | 28 |
1 files changed, 4 insertions, 24 deletions
diff --git a/drivers/media/usb/em28xx/em28xx-camera.c b/drivers/media/usb/em28xx/em28xx-camera.c index 2f59237ee399..f401e5aa1373 100644 --- a/drivers/media/usb/em28xx/em28xx-camera.c +++ b/drivers/media/usb/em28xx/em28xx-camera.c @@ -98,8 +98,6 @@ static int em28xx_probe_sensor_micron(struct em28xx *dev) { int ret, i; char *name; - u8 reg; - __be16 id_be; u16 id; struct i2c_client *client = &dev->i2c_client[dev->def_i2c_bus]; @@ -107,10 +105,8 @@ static int em28xx_probe_sensor_micron(struct em28xx *dev) dev->em28xx_sensor = EM28XX_NOSENSOR; for (i = 0; micron_sensor_addrs[i] != I2C_CLIENT_END; i++) { client->addr = micron_sensor_addrs[i]; - /* NOTE: i2c_smbus_read_word_data() doesn't work with BE data */ /* Read chip ID from register 0x00 */ - reg = 0x00; - ret = i2c_master_send(client, ®, 1); + ret = i2c_smbus_read_word_data(client, 0x00); /* assumes LE */ if (ret < 0) { if (ret != -ENXIO) dev_err(&dev->intf->dev, @@ -118,24 +114,9 @@ static int em28xx_probe_sensor_micron(struct em28xx *dev) client->addr << 1, ret); continue; } - ret = i2c_master_recv(client, (u8 *)&id_be, 2); - if (ret < 0) { - dev_err(&dev->intf->dev, - "couldn't read from i2c device 0x%02x: error %i\n", - client->addr << 1, ret); - continue; - } - id = be16_to_cpu(id_be); + id = swab16(ret); /* LE -> BE */ /* Read chip ID from register 0xff */ - reg = 0xff; - ret = i2c_master_send(client, ®, 1); - if (ret < 0) { - dev_err(&dev->intf->dev, - "couldn't read from i2c device 0x%02x: error %i\n", - client->addr << 1, ret); - continue; - } - ret = i2c_master_recv(client, (u8 *)&id_be, 2); + ret = i2c_smbus_read_word_data(client, 0xff); if (ret < 0) { dev_err(&dev->intf->dev, "couldn't read from i2c device 0x%02x: error %i\n", @@ -143,10 +124,9 @@ static int em28xx_probe_sensor_micron(struct em28xx *dev) continue; } /* Validate chip ID to be sure we have a Micron device */ - if (id != be16_to_cpu(id_be)) + if (id != swab16(ret)) continue; /* Check chip ID */ - id = be16_to_cpu(id_be); switch (id) { case 0x1222: name = "MT9V012"; /* MI370 */ /* 640x480 */ |