]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/commitdiff
hwmon: (pmbus_core) Simplify sign extensions
authorGuenter Roeck <guenter.roeck@ericsson.com>
Wed, 28 Sep 2011 18:36:20 +0000 (11:36 -0700)
committerGuenter Roeck <guenter.roeck@ericsson.com>
Mon, 24 Oct 2011 18:09:44 +0000 (11:09 -0700)
Shift operations can be used for sign extensions. Use it.

Signed-off-by: Guenter Roeck <guenter.roeck@ericsson.com>
Reviewed-by: Robert Coulson <robert.coulson@ericsson.com>
drivers/hwmon/pmbus/pmbus_core.c

index 814ebb198346c3e1f00bbaa759745db5d5480bae..00460d8d84239e57c880238469df0f2965c9b976 100644 (file)
@@ -445,13 +445,8 @@ static long pmbus_reg2data_linear(struct pmbus_data *data,
                exponent = data->exponent;
                mantissa = (u16) sensor->data;
        } else {                                /* LINEAR11 */
-               exponent = (sensor->data >> 11) & 0x001f;
-               mantissa = sensor->data & 0x07ff;
-
-               if (exponent > 0x0f)
-                       exponent |= 0xffe0;     /* sign extend exponent */
-               if (mantissa > 0x03ff)
-                       mantissa |= 0xfffff800; /* sign extend mantissa */
+               exponent = ((s16)sensor->data) >> 11;
+               mantissa = ((s16)((sensor->data & 0x7ff) << 5)) >> 5;
        }
 
        val = mantissa;
@@ -1628,7 +1623,7 @@ static void pmbus_find_attributes(struct i2c_client *client,
 static int pmbus_identify_common(struct i2c_client *client,
                                 struct pmbus_data *data)
 {
-       int vout_mode = -1, exponent;
+       int vout_mode = -1;
 
        if (pmbus_check_byte_register(client, 0, PMBUS_VOUT_MODE))
                vout_mode = _pmbus_read_byte_data(client, 0, PMBUS_VOUT_MODE);
@@ -1642,11 +1637,7 @@ static int pmbus_identify_common(struct i2c_client *client,
                        if (data->info->format[PSC_VOLTAGE_OUT] != linear)
                                return -ENODEV;
 
-                       exponent = vout_mode & 0x1f;
-                       /* and sign-extend it */
-                       if (exponent & 0x10)
-                               exponent |= ~0x1f;
-                       data->exponent = exponent;
+                       data->exponent = ((s8)(vout_mode << 3)) >> 3;
                        break;
                case 1: /* VID mode         */
                        if (data->info->format[PSC_VOLTAGE_OUT] != vid)