<div dir="ltr">Thanks. I changed the documentation piece and submitted v2.</div><br><div class="gmail_quote"><div dir="ltr">On Fri, Sep 28, 2018 at 11:30 AM Guenter Roeck <<a href="mailto:linux@roeck-us.net">linux@roeck-us.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Fri, Sep 28, 2018 at 10:45:00AM -0700, Kun Yi wrote:<br>
> The ADM series of hotswap controllers support extending<br>
> the current measurement range by using a sensing resistor<br>
> value other than the typical 1 mOhm. For example, using a 0.5 mOhm<br>
> sensing resistor doubles the maximal current can be measured.<br>
> <br>
> Current driver assumes a shunt resistor value of 1 mOhm in calculation,<br>
> meaning for other resistor values, hwmon will report scaled<br>
> current/power measurements. This patch adds a device tree parameter so<br>
> that individual boards can configure its shunt resistor value.<br>
> <br>
Please copy DT maintainers for all DT changes.<br>
<br>
> Signed-off-by: Kun Yi <<a href="mailto:kunyi@google.com" target="_blank">kunyi@google.com</a>><br>
> ---<br>
>  .../devicetree/bindings/hwmon/adm1275.txt     | 19 +++++++++++++++++++<br>
>  Documentation/hwmon/adm1275                   |  3 +++<br>
>  drivers/hwmon/pmbus/adm1275.c                 | 15 +++++++++++++--<br>
>  3 files changed, 35 insertions(+), 2 deletions(-)<br>
>  create mode 100644 Documentation/devicetree/bindings/hwmon/adm1275.txt<br>
> <br>
> diff --git a/Documentation/devicetree/bindings/hwmon/adm1275.txt b/Documentation/devicetree/bindings/hwmon/adm1275.txt<br>
> new file mode 100644<br>
> index 000000000000..a182fa195ed1<br>
> --- /dev/null<br>
> +++ b/Documentation/devicetree/bindings/hwmon/adm1275.txt<br>
> @@ -0,0 +1,19 @@<br>
> +adm1275 properties<br>
> +<br>
> +Required properties:<br>
> +- compatible: Must be one of the supported compatible strings in<br>
> +  Documentation/hwmon/adm1275<br>
<br>
It would be more appropriate to list those here as devicetree properties.<br>
The information in Documentation/hwmon/adm1275 does not include the "adi,"<br>
prefix.<br>
<br>
Thanks,<br>
Guenter<br>
<br>
> +- reg: I2C address<br>
> +<br>
> +Optional properties:<br>
> +<br>
> +- shunt-resistor-micro-ohms<br>
> +     Shunt resistor value in micro-Ohm<br>
> +<br>
> +Example:<br>
> +<br>
> +adm1272@10 {<br>
> +     compatible = "adi,adm1272";<br>
> +     reg = <0x10>;<br>
> +     shunt-resistor-micro-ohms = <500>;<br>
> +};<br>
> diff --git a/Documentation/hwmon/adm1275 b/Documentation/hwmon/adm1275<br>
> index 39033538eb03..5e277b0d91ce 100644<br>
> --- a/Documentation/hwmon/adm1275<br>
> +++ b/Documentation/hwmon/adm1275<br>
> @@ -58,6 +58,9 @@ The ADM1075, unlike many other PMBus devices, does not support internal voltage<br>
>  or current scaling. Reported voltages, currents, and power are raw measurements,<br>
>  and will typically have to be scaled.<br>
>  <br>
> +The shunt value in micro-ohms can be set via device tree at compile-time. Please<br>
> +refer to the Documentation/devicetree/bindings/hwmon/adm1275.txt for bindings<br>
> +if the device tree is used.<br>
>  <br>
>  Platform data support<br>
>  ---------------------<br>
> diff --git a/drivers/hwmon/pmbus/adm1275.c b/drivers/hwmon/pmbus/adm1275.c<br>
> index 13600fa79e7f..f569372c9204 100644<br>
> --- a/drivers/hwmon/pmbus/adm1275.c<br>
> +++ b/drivers/hwmon/pmbus/adm1275.c<br>
> @@ -373,6 +373,7 @@ static int adm1275_probe(struct i2c_client *client,<br>
>       const struct coefficients *coefficients;<br>
>       int vindex = -1, voindex = -1, cindex = -1, pindex = -1;<br>
>       int tindex = -1;<br>
> +     u32 shunt;<br>
>  <br>
>       if (!i2c_check_functionality(client->adapter,<br>
>                                    I2C_FUNC_SMBUS_READ_BYTE_DATA<br>
> @@ -421,6 +422,13 @@ static int adm1275_probe(struct i2c_client *client,<br>
>       if (!data)<br>
>               return -ENOMEM;<br>
>  <br>
> +     if (of_property_read_u32(client->dev.of_node,<br>
> +                              "shunt-resistor-micro-ohms", &shunt))<br>
> +             shunt = 1000; /* 1 mOhm if not set via DT */<br>
> +<br>
> +     if (shunt == 0)<br>
> +             return -EINVAL;<br>
> +<br>
>       data->id = mid->driver_data;<br>
>  <br>
>       info = &data->info;<br>
> @@ -654,12 +662,15 @@ static int adm1275_probe(struct i2c_client *client,<br>
>               info->R[PSC_VOLTAGE_OUT] = coefficients[voindex].R;<br>
>       }<br>
>       if (cindex >= 0) {<br>
> -             info->m[PSC_CURRENT_OUT] = coefficients[cindex].m;<br>
> +             /* Scale current with sense resistor value */<br>
> +             info->m[PSC_CURRENT_OUT] =<br>
> +                     coefficients[cindex].m * shunt / 1000;<br>
>               info->b[PSC_CURRENT_OUT] = coefficients[cindex].b;<br>
>               info->R[PSC_CURRENT_OUT] = coefficients[cindex].R;<br>
>       }<br>
>       if (pindex >= 0) {<br>
> -             info->m[PSC_POWER] = coefficients[pindex].m;<br>
> +             info->m[PSC_POWER] =<br>
> +                     coefficients[pindex].m * shunt / 1000;<br>
>               info->b[PSC_POWER] = coefficients[pindex].b;<br>
>               info->R[PSC_POWER] = coefficients[pindex].R;<br>
>       }<br>
> -- <br>
> 2.19.0.605.g01d371f741-goog<br>
> <br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">Regards,<div>Kun</div></div></div>