hwmon: (pmbus) Drop unnecessary error messages in probe error path

Drop error messages due to implementation errors and due to memory allocation
errors.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
hwmon: (pmbus) Fix 'Macros with multiple statements' checkpatch error

Fix:
ERROR: Macros with multiple statements should be enclosed in a do - while loop

by unwinding the problematic macros.

As a side effect, this patch reduces code size on x86_64 by 160 bytes and bss
size by 64 bytes.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
hwmon: (pmbus) Use dev variable to represent client->dev

This simplifies the code and makes it a bit smaller.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
hwmon: (pmbus) Simplify memory allocation for labels and booleans

Since memory is now allocated with dev_ functions, we no longer need to keep
track of allocated memory. Memory allocation for booleans and labels can
therefore be simplified substantially by allocating it only as needed.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
hwmon: (pmbus) Improve boolean handling

Boolean handling depends on storing the sensor data index in sensor_device_attr
as part of the index variable. This limits the number of sensor attributes to
256, and means the sensor sequence number actually has to be maintained to be
able to access sensor data from boolean functions.

Rework the code to store sensor pointers in the pmbus_boolean data structure
directly. With this approach, the number of supportable sensors is now
unlimited.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
hwmon: (pmbus) Simplify memory allocation for sensor attributes

Since memory is now allocated with dev_ functions, we no longer need to keep
track of allocated memory. Sensor memory allocation can therefore be
simplified significantly.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
hwmon: (pmbus) Use krealloc to allocate attribute memory

So far, attribute memory was allocated by pre-calculating the maximum possible
amount of attributes. Not only does this waste memory, it is also risky because
the calculation might be wrong. It also requires a lot of defines to specify
the maximum number of attributes per class.

Allocate attribute memory using krealloc() instead. That means we have to use
kfree(), since devm_krealloc() does not exist, but that is still less costly
and less risky than trying to predict the number of attributes at the beginning.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
hwmon: (pmbus) Add support for additional voltage sensor

Some PMBus chips support monitoring an additional non-standard voltage. While
this voltage can in many cases be supported by simulating an additional sensor
page, this does not work in all cases. Specifically, it is problematic if the
data format is linear and the voltage is reported in LINEAR11 format. Since
output voltages use LINEAR16, and the exponent for LINEAR16 data is chip-wide
and fixed, this can result in overflows.

To solve this problem, add support for an additional virtual input voltage,
call it 'vmon', and treat this voltage as input voltage (which, when the chip
supports linear data format, uses LINEAR11).

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
hwmon: (pmbus) Add function to clear sensor cache

For PMBus chips, modifying one limit register may affect other limits.
Since limits are all cached in the PMBus core driver, related changes
are not reflected in reported limits.

Introduce function to clear the attribute cache. After calling this function,
the core pmbus driver re-reads all cached values.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
hwmon: (pmbus/zl6100) Add support for VMON/VDRV

Some of the ZL6100 compatible chips support monitoring a separate voltage pin,
VMON (ZL2004) or VDRV (ZL91xx). Report it as in2 / vmon.

The chips support implicit warning limits for VMON/VDRV, as percentage of the
respective critical voltage. Support by reading/writing the critical voltages
and calculating the associated warning voltages.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
hwmon: (pmbus) Add support for word status register

Not all PMBus devices support the byte status register at 0x78.
Try to use the word status register at 0x79 instead if that is the case.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
hwmon: (pmbus/max34440) Add support for MAX34460 and MAX34461

MAX34460 is a PMBus 12-Channel Voltage Monitor & Sequencer.
MAX34461 is a PMBus 16-Channel Voltage Monitor & Sequencer.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
hwmon: (pmbus) Clean up for code size reduction

Rearranged some data structures, and merged some common functions.
Overall code and data size reduction by more than 900 bytes.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>