Commit Graph

29 Commits

Author SHA1 Message Date
Stephen Kitt dd43193976 hwmon (pmbus) use simple i2c probe function
pmbus_do_probe doesn't use the id information provided in its second
argument, so this can be removed, which then allows using the
single-parameter i2c probe function ("probe_new") for probes.

This avoids scanning the identifier tables during probes.

Drivers which didn't use the id are converted as-is; drivers which did
are modified as follows:

* if the information in i2c_client is sufficient, that's used instead
  (client->name);
* configured v. probed comparisons are performed by comparing the
  configured name to the detected name, instead of the ids; this
  involves strcmp but is still cheaper than comparing all the device
  names when scanning the tables;
* anything else is handled by calling i2c_match_id() with the same
  level of error-handling (if any) as before.

Additionally, the mismatch message in the ltc2978 driver is adjusted
so that it no longer assumes that the driver_data is an index into
ltc2978_id.

Signed-off-by: Stephen Kitt <steve@sk2.org>
Acked-by: Wolfram Sang <wsa@kernel.org>
Link: https://lore.kernel.org/r/20200808210004.30880-1-steve@sk2.org
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2020-09-23 09:42:39 -07:00
Manikandan Elumalai a37881dead hwmon: (adm1275) Enable adm1278 ADM1278_TEMP1_EN
The adm1278 temp attribute need it for openbmc platform .
This feature not enabled by default, so PMON_CONFIG needs to enable it.

Signed-off-by: Manikandan Elumalai <manikandan.hcl.ers.epl@gmail.com>
Link: https://lore.kernel.org/r/20200622153727.GA9347@cnn
[groeck: Split long line]
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2020-07-19 16:25:21 -07:00
Chu Lin 6d1d41c075 hwmon: (adm1275) Make sure we are reading enough data for different chips
Issue:
When PEC is enabled, binding adm1272 to the adm1275 would
fail due to PEC error. See below:
adm1275: probe of xxxx failed with error -74

Diagnosis:
Per the datasheet of adm1272, adm1278, adm1293 and amd1294,
PMON_CONFIG (0xd4) is 16bits wide. On the other hand,
PMON_CONFIG (0xd4) for adm1275 is 8bits wide. The driver should not
assume everything is 8bits wide and read only 8bits from it.

Solution:
If it is adm1272, adm1278, adm1293 and adm1294, use i2c_read_word.
Else, use i2c_read_byte

Testing:
Binding adm1272 to the driver.
The change is only tested on adm1272.

Signed-off-by: Chu Lin <linchuyuan@google.com>
Link: https://lore.kernel.org/r/20200709040612.3977094-1-linchuyuan@google.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2020-07-09 07:02:35 -07:00
Guenter Roeck 43f33b6e59 hwmon: (pmbus) Add 'phase' parameter where needed for multi-phase support
In preparation for multi-phase support, add 'phase' parameter to read_word
and set_page functions. Actual multi-phase support will be added in
a subsequent patch.

Cc: Vadim Pasternak <vadimp@mellanox.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2020-03-08 20:35:47 -07:00
Guenter Roeck 7d45deb31b hwmon: (pmbus/adm1275) Fix power sampling support
Not every chip supported by this driver supports setting the number
of samples for power averaging. Also, the power monitoring register
is not always a 16-bit register, and the configuration bits used for
voltage sampling are different depending on the register width.
Some conditional code is needed to fix the problem.

On top of all that, the compiler complains about problems with
FIELD_GET and FIELD_PREP macros if the file is built with W=1.
Avoid using those macros to silence the warning.

Cc: Krzysztof Adamski <krzysztof.adamski@nokia.com>
Cc: Alexander Sverdlin <alexander.sverdlin@nokia.com>
Reviewed-by: Krzysztof Adamski <krzysztof.adamski@nokia.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2019-06-23 18:33:01 -07:00
Adamski, Krzysztof (Nokia - PL/Wroclaw) c83529c17e hwmon: (pmbus/adm1275) support PMBUS_VIRT_*_SAMPLES
The device supports setting the number of samples for averaging the
measurements. There are two separate settings - PWR_AVG for averaging
PIN and VI_AVG for averaging VIN/VAUX/IOUT, both being part of
PMON_CONFIG register. The values are stored as exponent of base 2 of the
actual number of samples that will be taken.

Signed-off-by: Krzysztof Adamski <krzysztof.adamski@nokia.com>
Reviewed-by: Alexander Sverdlin <alexander.sverdlin@nokia.com>
[groeck: Dropped unused variables]
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2019-06-23 18:33:01 -07:00
Thomas Gleixner c942fddf87 treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 157
Based on 3 normalized pattern(s):

  this program is free software you can redistribute it and or modify
  it under the terms of the gnu general public license as published by
  the free software foundation either version 2 of the license or at
  your option any later version this program is distributed in the
  hope that it will be useful but without any warranty without even
  the implied warranty of merchantability or fitness for a particular
  purpose see the gnu general public license for more details

  this program is free software you can redistribute it and or modify
  it under the terms of the gnu general public license as published by
  the free software foundation either version 2 of the license or at
  your option any later version [author] [kishon] [vijay] [abraham]
  [i] [kishon]@[ti] [com] this program is distributed in the hope that
  it will be useful but without any warranty without even the implied
  warranty of merchantability or fitness for a particular purpose see
  the gnu general public license for more details

  this program is free software you can redistribute it and or modify
  it under the terms of the gnu general public license as published by
  the free software foundation either version 2 of the license or at
  your option any later version [author] [graeme] [gregory]
  [gg]@[slimlogic] [co] [uk] [author] [kishon] [vijay] [abraham] [i]
  [kishon]@[ti] [com] [based] [on] [twl6030]_[usb] [c] [author] [hema]
  [hk] [hemahk]@[ti] [com] this program is distributed in the hope
  that it will be useful but without any warranty without even the
  implied warranty of merchantability or fitness for a particular
  purpose see the gnu general public license for more details

extracted by the scancode license scanner the SPDX license identifier

  GPL-2.0-or-later

has been chosen to replace the boilerplate/reference in 1105 file(s).

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Allison Randal <allison@lohutok.net>
Reviewed-by: Richard Fontana <rfontana@redhat.com>
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Cc: linux-spdx@vger.kernel.org
Link: https://lkml.kernel.org/r/20190527070033.202006027@linutronix.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-05-30 11:26:37 -07:00
Kun Yi 6e5c06ad94 hwmon: (adm1275) Allow setting shunt reg value
The ADM series of hotswap controllers support extending
the current measurement range by using a sensing resistor
value other than the typical 1 mOhm. For example, using a 0.5 mOhm
sensing resistor doubles the maximal current can be measured.

Current driver assumes a shunt resistor value of 1 mOhm in calculation,
meaning for other resistor values, hwmon will report scaled
current/power measurements. This patch parses device tree parameter
"shunt-resistor-micro-ohms", if there is one.

Signed-off-by: Kun Yi <kunyi@google.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-12-02 16:25:28 -08:00
Guenter Roeck 4ff0ce227a hwmon: (pmbus/adm1275) Add support for ADM1272
The chip is quite similar to other chips in the series,
but as usual it comes with its own quirks.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-03-22 09:32:17 -07:00
Guenter Roeck ecb29abd4c hwmon: (pmbus/adm1275) Accept negative page register values
A negative page register value means that no page needs to be
selected. This is used by status register read operations and needs
to be accepted. The failure to do so so results in missed status
and limit registers.

Fixes: da8e48ab48 ("hwmon: (pmbus) Always call _pmbus_read_byte in core driver")
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-03-10 18:59:56 -08:00
Shikhar Dogra 6faecba0b3 driver: (adm1275) set the m,b and R coefficients correctly for power
Seems like coefficient values for m, b and R under power have been
put in the wrong order. Rearranging them properly to get correct
values of coefficients for power.

For specs, please refer to table 7 (page 35) on
http://www.analog.com/media/en/technical-documentation/data-sheets/ADM1075.pdf

Fixes: 904b296f30 ("hwmon: (adm1275) Introduce configuration data structure for coeffcients")
Signed-off-by: Shikhar Dogra <shidogra@cisco.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2017-03-27 19:43:36 -07:00
Yi Li 2b3d0c1953 hwmon: (adm1275) Enable adm1278 VOUT sampling
The adm1278 can optionally monitor the VOUT pin. This functionality is
not enabled at reset, so PMON_CONFIG needs to be modified in order to
enable it.

Signed-off-by: Yi Li <adamliyi@msn.com>
Signed-off-by: Joel Stanley <joel@jms.id.au>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2016-12-02 13:28:07 -08:00
Guenter Roeck 709066acdd hwmon: (adm1275) Add support for ADM1278
ADM1278 is mostly compatible to other chips of the same series.
Besides the usual difference in coefficients, it supports
a temperature sensor, and it can measure both input and output
voltage at the same time.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2016-03-05 06:36:03 -08:00
Guenter Roeck 68a4038236 hwmon: (adm1275) Add support for ADM1293 and ADM1294
ADM1293 and ADM1294 are mostly compatible with other chips of the same
series, but have more configuration options. There are also some
differences in register details.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2015-08-09 13:44:27 -07:00
Guenter Roeck 9048539b7c hwmon: (adm1275) Introduce new feature flags
Introduce have_vout, have_vaux_status, have_pin_max, and have_uc_fault
to simplify adding support for new chips.

Also simplify error returns where appropriate to return immediately
on error.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2015-08-09 13:44:26 -07:00
Guenter Roeck 904b296f30 hwmon: (adm1275) Introduce configuration data structure for coeffcients
Each new chip supported by the driver has a new set of coefficients,
making hard-coding coefficients more and more cumbersome. Introduce
a datastructure and table to simplify configuration.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2015-08-09 13:44:26 -07:00
Guenter Roeck 99b416085c hwmon: (adm1275) Use BIT macro
Use BIT macro to simplify adding new bit masks.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2015-08-09 13:44:26 -07:00
Guenter Roeck 9271126966 hwmon: (adm1275) Add support for ADM1075
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2012-03-18 18:27:52 -07:00
Guenter Roeck dd285ad737 hwmon: (pmbus) Simplify remove functions
Since devm_kzalloc() is now used to allocate driver memory, the client
driver remove function has no purpose other than to call pmbus_do_remove().
This means we can get rid of it by redefining pmbus_do_remove() to use the
same prototype, and pointing to it directly.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2012-03-18 18:27:46 -07:00
Guenter Roeck 8b313ca7f1 hwmon: (pmbus) Convert pmbus drivers to use devm_kzalloc
Marginally less code and eliminate the possibility of memory leaks.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2012-03-18 18:27:45 -07:00
Axel Lin f0967eea80 hwmon: convert drivers/hwmon/* to use module_i2c_driver()
This patch converts the drivers in drivers/hwmon/* to use the
module_i2c_driver() macro which makes the code smaller and a bit simpler.

Signed-off-by: Axel Lin <axel.lin@gmail.com>
Cc: Corentin Labbe <corentin.labbe@geomatys.fr>
Cc: Dirk Eibach <eibach@gdsys.de>
Cc: "Mark M. Hoffman" <mhoffman@lightlink.com>
Cc: Steve Glendinning <steve.glendinning@smsc.com>
Cc: Riku Voipio <riku.voipio@iki.fi>
Cc: Guillaume Ligneul <guillaume.ligneul@gmail.com>
Cc: David George <david.george@ska.ac.za>
Cc: "Hans J. Koch" <hjk@hansjkoch.de>
Cc: Marc Hulsman <m.hulsman@tudelft.nl>
Cc: Rudolf Marek <r.marek@assembler.cz>
Signed-off-by: Guenter Roeck <guenter.roeck@ericsson.com>
2012-03-18 18:26:50 -07:00
Guenter Roeck 87102808d0 hwmon: (pmbus/adm1275) Validate device ID
Since manufacturer and device ID are known, read and validate it.

Signed-off-by: Guenter Roeck <guenter.roeck@ericsson.com>
[Dan Carpenter <dan.carpenter@oracle.com>: Fixed memory leak]
Reviewed-by: Robert Coulson <robert.coulson@ericsson.com>
2012-01-05 08:19:27 -08:00
Guenter Roeck da8e48ab48 hwmon: (pmbus) Always call _pmbus_read_byte in core driver
Always call _pmbus_read_byte() instead of pmbus_read_byte() in PMBus core
driver. With this change, device specific read functions can be implemented for
all registers.

Since the device specific read_byte function is now always called, we need to be
more careful with page validations. Only fail if the passed page number is larger
than 0, since -1 means "current page".

Signed-off-by: Guenter Roeck <guenter.roeck@ericsson.com>
Reviewed-by: Robert Coulson <robert.coulson@ericsson.com>
2011-10-24 11:09:40 -07:00
Guenter Roeck 5cf231a346 hwmon: (pmbus/adm1275) Add support for ADM1276
ADM1276 is mostly compatible to ADM1275, with added support for input power
measurement. Add support for it to the ADM1275 driver.

Signed-off-by: Guenter Roeck <guenter.roeck@ericsson.com>
Acked-by: Jean Delvare <khali@linux-fr.org>
2011-10-24 11:09:35 -07:00
Guenter Roeck c5e6763667 hwmon: (pmbus/adm1275) Add support for second current limit
ADM1275 supports a second current limit, which can be configured as either lower
or upper limit. Add support for it and report it as either lower or upper
critical current limit.

Also replace error return code EINVAL for unsupported pages with ENXIO as this
is more appropriate for the observed condition.

Signed-off-by: Guenter Roeck <guenter.roeck@ericsson.com>
Acked-by: Jean Delvare <khali@linux-fr.org>
2011-10-24 11:09:34 -07:00
Guenter Roeck 866cf12a0e hwmon: (pmbus) Don't return errors from driver remove functions
Driver remove functions have an error return value, but rarely return an error
in practice. If a driver does return an error from its remove function, the
driver won't be unloaded and is expected to stay alive.

pmbus_do_remove() is defined as returning an int, but always returns 0 (no
error). Calling code passes that return value on to high level driver
remove functions, but does not evaluate it and removes driver data even if
pmbus_do_remove() returned an error (which it in practice never does). Even if
this code could never cause a real problem, it is nevertheless conceptually
wrong.

To reduce confusion and simplify the code, change pmbus_do_remove() to be a void
function, and have PMBus client drivers always return zero in their driver
remove functions.

Reported-by: Jean Delvare <khali@linux-fr.org>
Signed-off-by: Guenter Roeck <guenter.roeck@ericsson.com>
Acked-by: Jean Delvare <khali@linux-fr.org>
2011-10-24 11:09:33 -07:00
Guenter Roeck c576e30cd0 hwmon: (adm1275) Add support for peak attributes
Add support for voltage and current peak (historic maximum) attributes.

Signed-off-by: Guenter Roeck <guenter.roeck@ericsson.com>
Reviewed-by: Robert Coulson <robert.coulson@ericsson.com>
2011-07-28 17:09:52 -07:00
Guenter Roeck 1061d8518f hwmon: (pmbus) Add support for VID output voltage mode
In VID mode, output voltages are measured and reported as VID values, and
have to be converted to voltages using VID conversion tables or functions.
Support is added for VR11 only at this time.

This patch enables support for PMBus devices supporting VID VR11 based output
voltage selection such as NCP4200 and NCP4208.

Signed-off-by: Guenter Roeck <guenter.roeck@ericsson.com>
Reviewed-by: Robert Coulson <robert.coulson@ericsson.com>
2011-07-28 15:31:11 -07:00
Guenter Roeck 9d2ecfb768 hwmon: (pmbus) Move PMBus drivers to drivers/hwmon/pmbus
Since the number of PMBus drivers is getting large, move them into
directory drivers/hwmon/pmbus to improve readability and scalability.

Signed-off-by: Guenter Roeck <guenter.roeck@ericsson.com>
Reviewed-by: Robert Coulson <robert.coulson@ericsson.com>
2011-07-28 11:47:53 -07:00