mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
To: Bhavin Sharma <bhavin.sharma@siliconsignals.io>, sre@kernel.org
Cc: Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Hardevsinh Palaniya <hardevsinh.palaniya@siliconsignals.io>,
	linux-pm@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/2] power: supply: Add STC3117 fuel gauge unit driver
Date: Sat, 6 Jan 2024 17:52:09 +0100	[thread overview]
Message-ID: <6f7e65e8-ae83-4f92-b931-a56328d6ad87@linaro.org> (raw)
In-Reply-To: <20240106133546.936261-1-bhavin.sharma@siliconsignals.io>

On 06/01/2024 14:35, Bhavin Sharma wrote:
> Adding support for stc3117 fuel gauge driver with
> minimal functionality to read voltage level currently
> 
> Signed-off-by: Bhavin Sharma <bhavin.sharma@siliconsignals.io>
> ---
>  drivers/power/supply/Kconfig              |   7 ++
>  drivers/power/supply/Makefile             |   1 +
>  drivers/power/supply/stc3117_fuel_gauge.c | 136 ++++++++++++++++++++++
>  3 files changed, 144 insertions(+)
>  create mode 100644 drivers/power/supply/stc3117_fuel_gauge.c
> 
> diff --git a/drivers/power/supply/Kconfig b/drivers/power/supply/Kconfig
> index f21cb0581..02df55b0d 100644
> --- a/drivers/power/supply/Kconfig
> +++ b/drivers/power/supply/Kconfig
> @@ -875,6 +875,13 @@ config FUEL_GAUGE_SC27XX
>  	  Say Y here to enable support for fuel gauge with SC27XX
>  	  PMIC chips.
>  
> +config FUEL_GAUGE_STC3117
> +	tristate "STMicroelectronics STC3117 fuel gauge driver"
> +	depends on I2C
> +	help
> +	  Say Y here to enable support for fuel gauge with STC3117
> +	  PMIC chips.
> +
>  config CHARGER_UCS1002
>  	tristate "Microchip UCS1002 USB Port Power Controller"
>  	depends on I2C
> diff --git a/drivers/power/supply/Makefile b/drivers/power/supply/Makefile
> index 58b567278..f8ed3e5a8 100644
> --- a/drivers/power/supply/Makefile
> +++ b/drivers/power/supply/Makefile
> @@ -104,6 +104,7 @@ obj-$(CONFIG_CHARGER_CROS_USBPD)	+= cros_usbpd-charger.o
>  obj-$(CONFIG_CHARGER_CROS_PCHG)	+= cros_peripheral_charger.o
>  obj-$(CONFIG_CHARGER_SC2731)	+= sc2731_charger.o
>  obj-$(CONFIG_FUEL_GAUGE_SC27XX)	+= sc27xx_fuel_gauge.o
> +obj-$(CONFIG_FUEL_GAUGE_STC3117)	+= stc3117_fuel_gauge.o
>  obj-$(CONFIG_CHARGER_UCS1002)	+= ucs1002_power.o
>  obj-$(CONFIG_CHARGER_BD99954)	+= bd99954-charger.o
>  obj-$(CONFIG_CHARGER_WILCO)	+= wilco-charger.o
> diff --git a/drivers/power/supply/stc3117_fuel_gauge.c b/drivers/power/supply/stc3117_fuel_gauge.c
> new file mode 100644
> index 000000000..bf87bc1b9
> --- /dev/null
> +++ b/drivers/power/supply/stc3117_fuel_gauge.c
> @@ -0,0 +1,136 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * stc3117_fuel_gauge.c - STMicroelectronics STC3117 Fuel Gauge Driver
> + *
> + * Copyright (c) 2024 Silicon Signals Pvt Ltd.
> + * Author:      Bhavin Sharma <bhavin.sharma@siliconsignals.io>
> + *              Hardevsinh Palaniya <hardevsinh.palaniya@siliconsignals.com>
> + */
> +
> +

Just one blank line

> +#include <linux/i2c.h>
> +#include <linux/i2c-dev.h>
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/uaccess.h>
> +#include <linux/power_supply.h>
> +
> +#define VOLTAGE_REG_ADDR	0x08
> +#define VOLTAGE_REG_ADDR_SIZE	1		//in bytes
> +#define VOLTAGE_DATA_SIZE	2		//in bytes
> +#define LSB_VALUE		2200		//in micro-volts

LSB of what? This is very poor naming.


Missing spaces after //

> +
> +

One blank line

> +static int stc3117_probe(struct i2c_client *client);
> +static void stc3117_dev_remove(struct i2c_client *client);
> +
> +static int stc3117_get_property(struct power_supply *psy,
> +	enum power_supply_property psp, union power_supply_propval *val);
> +static int stc3117_get_batt_volt(const struct i2c_client *client);

Drop all these.

> +
> +const struct i2c_client *tmp_client;

Drop

> +struct power_supply *stc_sply;

Drop

> +
> +static const struct of_device_id stc3117_of_match[] = {

This goes next to driver structure.

> +	{ .compatible = "st,stc3117-fgu" },
> +	{},
> +};
> +

No blank line

> +MODULE_DEVICE_TABLE(of, stc3117_of_match);
> +
> +static const struct i2c_device_id stc3117_id[] = {

The same.

> +	{"stc3117", 0},
> +	{},
> +};
> +
> +

No blank lines

> +MODULE_DEVICE_TABLE(i2c, stc3117_id);
> +
> +struct i2c_driver stc3117_i2c_driver = {

Where did you place it? Open existing drivers and see how it is done.

> +	.driver = {
> +		.name = "stc3117_i2c_driver",
> +		.owner = THIS_MODULE,

Drop, ok, this is some ancient vendor driver which you just send
upstream. Sorry, no. You must clean it from all that ancient cruft.

You must run smatch, sparse and coccinelle/coccicheck.

> +		.of_match_table = of_match_ptr(stc3117_of_match),

Drop of_match_ptr

> +	},
> +	.probe = stc3117_probe,
> +	.id_table = stc3117_id,
> +	.remove = stc3117_dev_remove,
> +};
> +
> +
> +static enum power_supply_property stc3117_battery_props[] = {
> +	POWER_SUPPLY_PROP_VOLTAGE_NOW,
> +};
> +
> +static const struct power_supply_desc stc3117_battery_desc = {
> +	.name = "stc3117-battery",
> +	.type = POWER_SUPPLY_TYPE_BATTERY,
> +	.get_property = stc3117_get_property,
> +	.properties = stc3117_battery_props,
> +	.num_properties = ARRAY_SIZE(stc3117_battery_props),
> +};
> +
> +static int stc3117_get_property(struct power_supply *psy,
> +	enum power_supply_property psp, union power_supply_propval *val)
> +{
> +	switch (psp) {
> +	case POWER_SUPPLY_PROP_VOLTAGE_NOW:
> +		val->intval = stc3117_get_batt_volt(tmp_client);
> +	break;
> +	default:
> +		return -EINVAL;
> +	}
> +	return 0;
> +}
> +
> +

What's with this double blank lines?

> +static int stc3117_get_batt_volt(const struct i2c_client *stc_client)
> +{
> +	int ret, volt = 0;
> +	char i2c_tx = VOLTAGE_REG_ADDR, i2c_rx[2] = {0};
> +
> +	ret = i2c_master_send(stc_client, &i2c_tx, VOLTAGE_REG_ADDR_SIZE);
> +	if (ret > 0) {
> +
> +		ret = i2c_master_recv(stc_client, i2c_rx, VOLTAGE_DATA_SIZE);
> +		if (ret > 0) {
> +
> +			volt = (i2c_rx[1] << 8) + i2c_rx[0];
> +			volt *= LSB_VALUE;
> +
> +			return volt;
> +		}
> +	}
> +
> +	return ret;
> +}
> +
> +static int stc3117_probe(struct i2c_client *client)
> +{
> +	struct power_supply_config psy_cfg = {};
> +	struct device *dev;
> +
> +	dev = &client->dev;
> +
> +	psy_cfg.of_node = dev->of_node;
> +
> +	tmp_client = client;
> +
> +	stc_sply = power_supply_register(dev, &stc3117_battery_desc, &psy_cfg);

devm

> +	if (IS_ERR(stc_sply))
> +		pr_err("failed to register battery\n");

dev_err

> +
> +	return 0;
> +}
> +
> +static void stc3117_dev_remove(struct i2c_client *client)
> +{
> +	power_supply_unregister(stc_sply);
> +}
> +
> +module_i2c_driver(stc3117_i2c_driver);
> +
> +MODULE_LICENSE("GPL");
> +MODULE_AUTHOR("Bhavin Sharma <bhavin.sharma@siliconsignals.io>");
> +MODULE_AUTHOR("Hardevsinh Palaniya <hardevsinh.palaniya@siliconsignals.io>");
> +MODULE_DESCRIPTION("STC3117 Fuel Gauge Driver");

Best regards,
Krzysztof


  parent reply	other threads:[~2024-01-06 16:52 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-06 13:35 Bhavin Sharma
2024-01-06 13:35 ` [PATCH v2 2/2] dt-bindings: power: supply: stc3117: Convert to DT schema format Bhavin Sharma
2024-01-06 14:36   ` Rob Herring
2024-01-06 16:48   ` Krzysztof Kozlowski
2024-01-06 16:52 ` Krzysztof Kozlowski [this message]
2024-01-06 16:53 ` [PATCH v2 1/2] power: supply: Add STC3117 fuel gauge unit driver Krzysztof Kozlowski
2024-01-07 22:11 ` kernel test robot
2024-01-11 15:30 ` kernel test robot

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=6f7e65e8-ae83-4f92-b931-a56328d6ad87@linaro.org \
    --to=krzysztof.kozlowski@linaro.org \
    --cc=bhavin.sharma@siliconsignals.io \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=hardevsinh.palaniya@siliconsignals.io \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®