hwmon: (adc128d818) Preserve operation mode
authorAlexander Koch <mail@alexanderkoch.net>
Fri, 6 Jan 2017 10:38:17 +0000 (11:38 +0100)
committerGuenter Roeck <linux@roeck-us.net>
Tue, 10 Jan 2017 17:15:00 +0000 (09:15 -0800)
Preserve chip operation mode if no mode is specified via devicetree. This
enables operation when chip configuration is done by BIOS/ROMMON.

Signed-off-by: Alexander Koch <mail@alexanderkoch.net>
Acked-by: Michael Hornung <mhornung.linux@gmail.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/adc128d818.c

index 0502af963f731e1347ae90c1b437a46699fceef7..bbe3a5c5b3f51f338661f60f0f6c76390f4489e8 100644 (file)
@@ -491,7 +491,7 @@ static int adc128_probe(struct i2c_client *client,
                data->vref = 2560;      /* 2.56V, in mV */
        }
 
-       /* Operation mode is optional and defaults to mode 0 */
+       /* Operation mode is optional. If unspecified, keep current mode */
        if (of_property_read_u8(dev->of_node, "ti,mode", &data->mode) == 0) {
                if (data->mode > 3) {
                        dev_err(dev, "invalid operation mode %d\n",
@@ -500,7 +500,10 @@ static int adc128_probe(struct i2c_client *client,
                        goto error;
                }
        } else {
-               data->mode = 0;
+               err = i2c_smbus_read_byte_data(client, ADC128_REG_CONFIG_ADV);
+               if (err < 0)
+                       goto error;
+               data->mode = (err >> 1) & ADC128_REG_MASK;
        }
 
        data->client = client;