All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andy.shevchenko@gmail.com>
To: Saravanan Sekar <sravanhome@gmail.com>
Cc: Lee Jones <lee.jones@linaro.org>,
	Rob Herring <robh+dt@kernel.org>,
	Jonathan Cameron <jic23@kernel.org>,
	Hartmut Knaack <knaack.h@gmx.de>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Peter Meerwald <pmeerw@pmeerw.net>,
	Sebastian Reichel <sre@kernel.org>,
	devicetree <devicetree@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	linux-iio <linux-iio@vger.kernel.org>,
	Linux PM <linux-pm@vger.kernel.org>
Subject: Re: [PATCH v4 4/5] power: supply: Add support for mps mp2629 battery charger
Date: Mon, 23 Mar 2020 01:26:00 +0200	[thread overview]
Message-ID: <CAHp75Vf0iAV1g5GV8XoewNEMnGee=_Wkgz=8Y_ym8UPdsb6eFQ@mail.gmail.com> (raw)
In-Reply-To: <20200322224626.13160-5-sravanhome@gmail.com>

On Mon, Mar 23, 2020 at 12:47 AM Saravanan Sekar <sravanhome@gmail.com> wrote:
>
> The mp2629 provides switching-mode battery charge management for
> single-cell Li-ion or Li-polymer battery. Driver supports the
> access/control input source and battery charging parameters.

...

> +#include <linux/module.h>
> +#include <linux/platform_device.h>

> +#include <linux/of_device.h>

Do you need this one?

> +#include <linux/interrupt.h>
> +#include <linux/iio/consumer.h>
> +#include <linux/iio/types.h>
> +#include <linux/power_supply.h>
> +#include <linux/workqueue.h>
> +#include <linux/regmap.h>

Perhaps put them in order?

> +#include <linux/mfd/core.h>

How this is being used?

> +#include <linux/mfd/mp2629.h>

...

> +#define MP2629_MASK_INPUT_TYPE         0xe0
> +#define MP2629_MASK_CHARGE_TYPE                0x18
> +#define MP2629_MASK_CHARGE_CTRL                0x30
> +#define MP2629_MASK_WDOG_CTRL          0x30
> +#define MP2629_MASK_IMPEDANCE          0xf0

GENMASK()?

...

> +       struct regmap_field *regmap_fields[TERM_CURRENT + 1];

Hmm... Why not to have a definition to cover + 1?

...

> +static int mp2629_get_prop(struct mp2629_charger *charger,
> +                          enum mp2629_field fld,
> +                          union power_supply_propval *val)
> +{
> +       int ret;
> +       unsigned int rval;
> +

> +       ret = regmap_field_read(charger->regmap_fields[fld], &rval);
> +       if (!ret)
> +               val->intval = (rval * props[fld].step) + props[fld].min;
> +
> +       return ret;

Why not to use standard pattern, i.e.

  if (ret)
    return ret;
  ...
  return 0;

?

> +}

...

> +static int mp2629_charger_battery_set_prop(struct power_supply *psy,
> +                                       enum power_supply_property psp,
> +                                       const union power_supply_propval *val)
> +{
> +       struct mp2629_charger *charger = dev_get_drvdata(psy->dev.parent);

> +       int ret;

You may replace it with in-place return statements.

> +
> +       switch (psp) {
> +       case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT:
> +               ret = mp2629_set_prop(charger, TERM_CURRENT, val);
> +               break;
> +
> +       case POWER_SUPPLY_PROP_PRECHARGE_CURRENT:
> +               ret = mp2629_set_prop(charger, PRECHARGE, val);
> +               break;
> +
> +       case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE:
> +               ret = mp2629_set_prop(charger, CHARGE_VLIM, val);
> +               break;
> +
> +       case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT:
> +               ret = mp2629_set_prop(charger, CHARGE_ILIM, val);
> +               break;
> +
> +       default:
> +               return -EINVAL;
> +       }

> +
> +       return ret;

...and drop this completely.

> +}

...

> +       case POWER_SUPPLY_PROP_ONLINE:
> +               ret = regmap_read(charger->regmap, MP2629_REG_STATUS, &rval);
> +               if (!ret)
> +                       val->intval = !!(rval & MP2629_MASK_INPUT_TYPE);
> +               break;

Traditional pattern?

...

> +static int mp2629_charger_usb_set_prop(struct power_supply *psy,
> +                               enum power_supply_property psp,
> +                               const union power_supply_propval *val)
> +{
> +       struct mp2629_charger *charger = dev_get_drvdata(psy->dev.parent);

> +       int ret;

No need to have it.

> +       switch (psp) {
> +       case POWER_SUPPLY_PROP_INPUT_VOLTAGE_LIMIT:
> +               ret = mp2629_set_prop(charger, INPUT_VLIM, val);
> +               break;
> +
> +       case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
> +               ret = mp2629_set_prop(charger, INPUT_ILIM, val);
> +               break;
> +
> +       default:
> +               return -EINVAL;
> +       }
> +
> +       return ret;
> +}

...

> +       return (psp == POWER_SUPPLY_PROP_PRECHARGE_CURRENT ||
> +               psp == POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT ||
> +               psp == POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT ||
> +               psp == POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE);

Redundant parentheses.
Ditto for similar cases in the driver.

...

> +static ssize_t batt_impedance_compensation_show(struct device *dev,
> +                                          struct device_attribute *attr,
> +                                          char *buf)
> +{
> +       struct mp2629_charger *charger = dev_get_drvdata(dev->parent);
> +       unsigned int rval;
> +       int ret;
> +
> +       ret = regmap_read(charger->regmap, MP2629_REG_IMPEDANCE_COMP, &rval);

> +       if (ret < 0)

' < 0' is not needed.
Ditto for other cases.

> +               return ret;
> +
> +       rval = (rval >> 4) * 10;
> +

> +       return scnprintf(buf, PAGE_SIZE, "%d mohm\n", rval);

Simple sprintf().

> +}

...

> +static ssize_t batt_impedance_compensation_store(struct device *dev,
> +                                           struct device_attribute *attr,
> +                                           const char *buf,
> +                                           size_t count)
> +{
> +       struct mp2629_charger *charger = dev_get_drvdata(dev->parent);
> +       long val;
> +       int ret;
> +
> +       ret = kstrtol(buf, 10, &val);

> +       if (ret < 0)

No need to check for negative only.

> +               return ret;
> +
> +       if (val < 0 && val > 140)
> +               return -ERANGE;

And what the point then to use l instead of ul or even uint variant of
the conversion above?

> +       /* multiples of 10 mohm so round off */
> +       val = val / 10;
> +       ret = regmap_update_bits(charger->regmap, MP2629_REG_IMPEDANCE_COMP,
> +                                       MP2629_MASK_IMPEDANCE, val << 4);
> +       if (ret < 0)
> +               return ret;
> +
> +       return count;
> +}

...

> +static int mp2629_charger_probe(struct platform_device *pdev)
> +{
> +       struct device *dev = &pdev->dev;

> +       void **pdata = pdev->dev.platform_data;

Why void?
Why **?
Why not to use dev_get_platdata()?
Why do we need platform data at all?

> +       struct mp2629_charger *charger;
> +       struct power_supply_config psy_cfg = {0};
> +       int ret, i;

> +       charger->regmap = *pdata;

> +       regmap_update_bits(charger->regmap, MP2629_REG_INTERRUPT,
> +                               GENMASK(6, 5), (BIT(6) | BIT(5)));

Too many parentheses.

> +}

--
With Best Regards,
Andy Shevchenko

  reply	other threads:[~2020-03-22 23:26 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-22 22:46 [PATCH v4 0/5] Add battery charger driver support for MP2629 Saravanan Sekar
2020-03-22 22:46 ` [PATCH v4 1/5] dt-bindings: mfd: add document bindings for mp2629 Saravanan Sekar
2020-03-27  8:00   ` Lee Jones
2020-03-27 21:50     ` saravanan sekar
2020-03-30  6:46       ` Lee Jones
2020-04-07 16:29         ` saravanan sekar
2020-04-08 10:15           ` Lee Jones
2020-03-22 22:46 ` [PATCH v4 2/5] mfd: mp2629: Add support for mps battery charger Saravanan Sekar
2020-03-23  6:08   ` kbuild test robot
2020-03-23  9:15   ` kbuild test robot
2020-03-27  7:55   ` Lee Jones
2020-03-27  8:32     ` saravanan sekar
2020-03-27 10:22       ` Lee Jones
2020-03-27 10:56         ` saravanan sekar
2020-03-27 11:25           ` Lee Jones
2020-03-27 12:40             ` saravanan sekar
2020-03-27 12:56               ` Andy Shevchenko
2020-03-27 13:03                 ` saravanan sekar
2020-03-27 13:17                   ` Andy Shevchenko
2020-03-28 14:36         ` Jonathan Cameron
2020-03-22 22:46 ` [PATCH v4 3/5] iio: adc: mp2629: Add support for mp2629 ADC driver Saravanan Sekar
2020-03-22 23:32   ` Andy Shevchenko
2020-03-28 14:42     ` Jonathan Cameron
2020-03-28 18:50       ` Andy Shevchenko
2020-03-29 10:37       ` saravanan sekar
2020-03-29 11:09         ` Andy Shevchenko
2020-03-22 22:46 ` [PATCH v4 4/5] power: supply: Add support for mps mp2629 battery charger Saravanan Sekar
2020-03-22 23:26   ` Andy Shevchenko [this message]
2020-03-23 12:29     ` saravanan sekar
2020-03-23  4:11   ` kbuild test robot
2020-03-23  7:21   ` kbuild test robot
2020-03-23  7:30   ` kbuild test robot
2020-03-22 22:46 ` [PATCH v4 5/5] MAINTAINERS: Add entry for mp2629 Battery Charger driver Saravanan Sekar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAHp75Vf0iAV1g5GV8XoewNEMnGee=_Wkgz=8Y_ym8UPdsb6eFQ@mail.gmail.com' \
    --to=andy.shevchenko@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=jic23@kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=lee.jones@linaro.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=pmeerw@pmeerw.net \
    --cc=robh+dt@kernel.org \
    --cc=sravanhome@gmail.com \
    --cc=sre@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.