diff options
author | Guenter Roeck <guenter.roeck@ericsson.com> | 2011-09-28 14:36:20 -0400 |
---|---|---|
committer | Guenter Roeck <guenter.roeck@ericsson.com> | 2011-10-24 14:09:44 -0400 |
commit | 1af1f5313cfea85a185c7bbb5258f7856fc8fea7 (patch) | |
tree | acc73abb589337fec213c175a077edd8b743a994 /drivers/hwmon/pmbus | |
parent | bc365a7f3c0d5b5b2a642e6646098b306b6faa4d (diff) |
hwmon: (pmbus_core) Simplify sign extensions
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>
Diffstat (limited to 'drivers/hwmon/pmbus')
-rw-r--r-- | drivers/hwmon/pmbus/pmbus_core.c | 17 |
1 files changed, 4 insertions, 13 deletions
diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c index 814ebb198346..00460d8d8423 100644 --- a/drivers/hwmon/pmbus/pmbus_core.c +++ b/drivers/hwmon/pmbus/pmbus_core.c | |||
@@ -445,13 +445,8 @@ static long pmbus_reg2data_linear(struct pmbus_data *data, | |||
445 | exponent = data->exponent; | 445 | exponent = data->exponent; |
446 | mantissa = (u16) sensor->data; | 446 | mantissa = (u16) sensor->data; |
447 | } else { /* LINEAR11 */ | 447 | } else { /* LINEAR11 */ |
448 | exponent = (sensor->data >> 11) & 0x001f; | 448 | exponent = ((s16)sensor->data) >> 11; |
449 | mantissa = sensor->data & 0x07ff; | 449 | mantissa = ((s16)((sensor->data & 0x7ff) << 5)) >> 5; |
450 | |||
451 | if (exponent > 0x0f) | ||
452 | exponent |= 0xffe0; /* sign extend exponent */ | ||
453 | if (mantissa > 0x03ff) | ||
454 | mantissa |= 0xfffff800; /* sign extend mantissa */ | ||
455 | } | 450 | } |
456 | 451 | ||
457 | val = mantissa; | 452 | val = mantissa; |
@@ -1628,7 +1623,7 @@ static void pmbus_find_attributes(struct i2c_client *client, | |||
1628 | static int pmbus_identify_common(struct i2c_client *client, | 1623 | static int pmbus_identify_common(struct i2c_client *client, |
1629 | struct pmbus_data *data) | 1624 | struct pmbus_data *data) |
1630 | { | 1625 | { |
1631 | int vout_mode = -1, exponent; | 1626 | int vout_mode = -1; |
1632 | 1627 | ||
1633 | if (pmbus_check_byte_register(client, 0, PMBUS_VOUT_MODE)) | 1628 | if (pmbus_check_byte_register(client, 0, PMBUS_VOUT_MODE)) |
1634 | vout_mode = _pmbus_read_byte_data(client, 0, PMBUS_VOUT_MODE); | 1629 | vout_mode = _pmbus_read_byte_data(client, 0, PMBUS_VOUT_MODE); |
@@ -1642,11 +1637,7 @@ static int pmbus_identify_common(struct i2c_client *client, | |||
1642 | if (data->info->format[PSC_VOLTAGE_OUT] != linear) | 1637 | if (data->info->format[PSC_VOLTAGE_OUT] != linear) |
1643 | return -ENODEV; | 1638 | return -ENODEV; |
1644 | 1639 | ||
1645 | exponent = vout_mode & 0x1f; | 1640 | data->exponent = ((s8)(vout_mode << 3)) >> 3; |
1646 | /* and sign-extend it */ | ||
1647 | if (exponent & 0x10) | ||
1648 | exponent |= ~0x1f; | ||
1649 | data->exponent = exponent; | ||
1650 | break; | 1641 | break; |
1651 | case 1: /* VID mode */ | 1642 | case 1: /* VID mode */ |
1652 | if (data->info->format[PSC_VOLTAGE_OUT] != vid) | 1643 | if (data->info->format[PSC_VOLTAGE_OUT] != vid) |