From: Tzung-Bi Shih <tzungbi@kernel.org>
To: "Sung-Chi, Li" <lschyi@chromium.org>
Cc: Benson Leung <bleung@chromium.org>,
Guenter Roeck <groeck@chromium.org>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>, Lee Jones <lee@kernel.org>,
linux-kernel@vger.kernel.org, chrome-platform@lists.linux.dev,
devicetree@vger.kernel.org
Subject: Re: [PATCH 1/3] platform/chrome: cros_ec_charge_state: add new driver to control charge
Date: Wed, 20 Nov 2024 16:08:26 +0000 [thread overview]
Message-ID: <Zz4JeoY4R-n703bY@google.com> (raw)
In-Reply-To: <20241118-add_charger_state-v1-1-94997079f35a@chromium.org>
On Mon, Nov 18, 2024 at 05:33:46PM +0800, Sung-Chi, Li wrote:
> diff --git a/drivers/platform/chrome/cros_ec_charge_state.c b/drivers/platform/chrome/cros_ec_charge_state.c
[...]
> +#define DRV_NAME "cros-ec-charge-state"
> +#define CHARGE_TYPE_CHARGE "charge"
> +#define CHARGE_TYPE_INPUT "input"
I'm not a big fan of these kind of macros and would prefer to remove them.
> +static int
> +cros_ec_charge_state_get_current_limit(struct cros_ec_device *ec_dev,
> + enum charge_state_params charge_type,
> + uint32_t *limit)
> +{
[...]
> + *limit = cpu_to_le32(state.get_param.value);
> + return 0;
> +}
> +
> +static int
> +cros_ec_charge_state_set_current_limit(struct cros_ec_device *ec_dev,
> + enum charge_state_params charge_type,
> + uint32_t limit)
> +{
[...]
> + param.set_param.value = cpu_to_le32(limit);
Looks weird to me. Both getter and setter use cpu_to_le32()? Should one
of them be le32_to_cpu()?
> +static int
> +cros_ec_charge_state_get_cur_state(struct thermal_cooling_device *cdev,
> + unsigned long *state)
> +{
> + struct cros_ec_charge_state_data *data = cdev->devdata;
> + uint32_t limit;
> + int ret;
> +
> + ret = cros_ec_charge_state_get_current_limit(data->ec_dev,
> + data->charge_type, &limit);
> + if (ret) {
> + dev_err(data->dev, "failed to get current state: %d", ret);
If something went wrong, and cros_ec_charge_state_get_current_limit() keeps
returning errors, would it somehow flood the kernel logs?
> + return ret;
> + }
> +
> + *state = data->max_milliamp - limit;
Would it happen: data->max_milliamp - limit < data->min_milliamp == true?
> +static int
> +cros_ec_charge_state_register_charge_chip(struct device *dev,
> + struct device_node *node,
> + struct cros_ec_device *cros_ec)
> +{
[...]
> +
> + if (!strcmp(type_val, CHARGE_TYPE_CHARGE)) {
> + data->charge_type = CS_PARAM_CHG_CURRENT;
> + } else if (!strcmp(type_val, CHARGE_TYPE_INPUT)) {
> + data->charge_type = CS_PARAM_CHG_INPUT_CURRENT;
> + } else {
> + dev_err(dev, "unknown charge type: %s", type_val);
> + return -1;
How about -EINVAL?
> + }
> +
> + ret = of_property_read_u32(node, "min-milliamp", &data->min_milliamp);
> + if (ret) {
> + dev_err(dev, "failed to get min-milliamp data: %d", ret);
> + return ret;
> + }
> +
> + ret = of_property_read_u32(node, "max-milliamp", &data->max_milliamp);
> + if (ret) {
> + dev_err(dev, "failed to get max-milliamp data: %d", ret);
> + return ret;
> + }
Would it happen: min-milliamp > max-milliamp == true?
> +
> + data->ec_dev = cros_ec;
> + data->dev = dev;
> +
> + cdev = devm_thermal_of_cooling_device_register(
> + dev, node, node->name, data,
> + &cros_ec_charge_state_cooling_device_ops);
> + if (IS_ERR_VALUE(cdev)) {
Any reasons to not use IS_ERR()?
> +static int cros_ec_charge_state_probe(struct platform_device *pdev)
> +{
> + struct device *dev = &pdev->dev;
> + struct cros_ec_dev *ec_dev = dev_get_drvdata(dev->parent);
> + struct cros_ec_device *cros_ec = ec_dev->ec_dev;
> + struct device_node *child;
> +
> + for_each_available_child_of_node(cros_ec->dev->of_node, child) {
> + if (!of_device_is_compatible(child,
> + "google,cros-ec-charge-state"))
> + continue;
> + if (cros_ec_charge_state_register_charge_chip(dev, child,
> + cros_ec))
> + continue;
> + }
There should be a way to use the compatible string in struct mfd_cell for
matching the node. See also [1].
[1]: https://elixir.bootlin.com/linux/v6.12/source/drivers/mfd/mfd-core.c#L184
> +
> +static const struct platform_device_id cros_ec_charge_state_id[] = {
> + { DRV_NAME, 0 },
^
> +static struct platform_driver cros_ec_chargedev_driver = {
The whole file uses "cros_ec_charge_state_" as a prefix for all symbols. Any
reasons to not make this consistent?
next prev parent reply other threads:[~2024-11-20 16:08 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-18 9:33 [PATCH 0/3] Introduce new driver cros-ec-charge-state Sung-Chi, Li
2024-11-18 9:33 ` [PATCH 1/3] platform/chrome: cros_ec_charge_state: add new driver to control charge Sung-Chi, Li
2024-11-20 16:08 ` Tzung-Bi Shih [this message]
2024-11-21 13:05 ` kernel test robot
2024-11-21 13:47 ` Thomas Weißschuh
2024-11-21 14:00 ` Krzysztof Kozlowski
2024-11-21 14:11 ` Thomas Weißschuh
2024-11-22 1:53 ` Sung-Chi, Li
2024-11-18 9:33 ` [PATCH 2/3] dt-bindings: chrome: add new binding google,cros-ec-chrage-state Sung-Chi, Li
2024-11-18 10:22 ` Rob Herring (Arm)
2024-11-18 20:25 ` Rob Herring
2024-11-19 2:23 ` Sung-Chi, Li
2024-11-20 16:35 ` Krzysztof Kozlowski
2024-11-20 16:37 ` Krzysztof Kozlowski
2024-11-18 9:33 ` [PATCH 3/3] mfd: cros_ec: Add charge state control cell Sung-Chi, Li
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=Zz4JeoY4R-n703bY@google.com \
--to=tzungbi@kernel.org \
--cc=bleung@chromium.org \
--cc=chrome-platform@lists.linux.dev \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=groeck@chromium.org \
--cc=krzk+dt@kernel.org \
--cc=lee@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lschyi@chromium.org \
--cc=robh@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;
as well as URLs for NNTP newsgroup(s).