lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <9b88a26c-088d-44a8-9226-8317a0bf63f1@kernel.org>
Date: Mon, 2 Dec 2024 11:28:07 +0100
From: Krzysztof Kozlowski <krzk@...nel.org>
To: Dzmitry Sankouski <dsankouski@...il.com>,
 Sebastian Reichel <sre@...nel.org>, Chanwoo Choi <cw00.choi@...sung.com>,
 Lee Jones <lee@...nel.org>, Rob Herring <robh@...nel.org>,
 Conor Dooley <conor+dt@...nel.org>,
 Dmitry Torokhov <dmitry.torokhov@...il.com>, Pavel Machek <pavel@....cz>,
 Hans de Goede <hdegoede@...hat.com>,
 Marek Szyprowski <m.szyprowski@...sung.com>,
 Sebastian Krzyszkowiak <sebastian.krzyszkowiak@...i.sm>,
 Purism Kernel Team <kernel@...i.sm>
Cc: linux-pm@...r.kernel.org, linux-kernel@...r.kernel.org,
 devicetree@...r.kernel.org, linux-input@...r.kernel.org,
 linux-leds@...r.kernel.org
Subject: Re: [PATCH v9 8/9] power: supply: max77705: Add charger driver for
 Maxim 77705

On 02/12/2024 10:48, Dzmitry Sankouski wrote:
> Add driver for Maxim 77705 switch-mode charger (part of max77705
> MFD driver) providing power supply class information to userspace.
> 
> The driver is configured through DTS (battery and system related
> settings).
> 
> Signed-off-by: Dzmitry Sankouski <dsankouski@...il.com>
> 


...

> +
> +static int max77705_charger_probe(struct platform_device *pdev)
> +{
> +	struct power_supply_config pscfg = {};
> +	struct i2c_client *i2c_chg;
> +	struct max77693_dev *max77705;
> +	struct max77705_charger_data *chg;
> +	struct device *dev, *parent;
> +	struct regmap_irq_chip_data *irq_data;
> +	int ret;
> +
> +	dev = &pdev->dev;
> +	parent = dev->parent;
> +	max77705 = dev_get_drvdata(parent);
> +
> +	chg = devm_kzalloc(dev, sizeof(*chg), GFP_KERNEL);
> +	if (!chg)
> +		return -ENOMEM;
> +
> +	platform_set_drvdata(pdev, chg);
> +
> +	i2c_chg = devm_i2c_new_dummy_device(dev, max77705->i2c->adapter, I2C_ADDR_CHG);
> +

Same problems as in other patchset. This really needs some work to look
closer to Linux coding style.


> +	if (IS_ERR(i2c_chg))
> +		return PTR_ERR(i2c_chg);
> +
> +	chg->regmap = devm_regmap_init_i2c(i2c_chg, &max77705_chg_regmap_config);
> +
> +	if (IS_ERR(chg->regmap))
> +		return PTR_ERR(chg->regmap);
> +
> +	chg->dev = dev;
> +
> +	ret = regmap_update_bits(chg->regmap,
> +				MAX77705_CHG_REG_INT_MASK,
> +				MAX77705_CHGIN_IM, 0);
> +
> +	if (ret)
> +		return ret;
> +
> +	pscfg.of_node = dev->of_node;
> +	pscfg.drv_data = chg;
> +
> +	chg->psy_chg = devm_power_supply_register(dev, &max77705_charger_psy_desc, &pscfg);
> +	if (IS_ERR(chg->psy_chg))
> +		return PTR_ERR(chg->psy_chg);
> +
> +	max77705_charger_irq_chip.irq_drv_data = chg;
> +	ret = devm_regmap_add_irq_chip(chg->dev, chg->regmap, max77705->irq,
> +					IRQF_ONESHOT | IRQF_SHARED, 0,
> +					&max77705_charger_irq_chip,
> +					&irq_data);
> +	if (ret) {
> +		dev_err(dev, "failed to add irq chip: %d\n", ret);
> +		return ret;
> +	}
> +
> +	chg->wqueue = create_singlethread_workqueue(dev_name(dev));
> +	if (IS_ERR(chg->wqueue)) {
> +		dev_err(dev, "failed to create workqueue\n");
> +		return PTR_ERR(chg->wqueue);
> +	}
> +	INIT_WORK(&chg->chgin_work, max77705_chgin_isr_work);
> +
> +	max77705_charger_initialize(chg);
> +
> +	return max77705_charger_enable(chg);
> +}
> +
> +static void max77705_charger_remove(struct platform_device *pdev)
> +{
> +	struct max77705_charger_data *chg = platform_get_drvdata(pdev);
> +
> +	max77705_charger_disable(chg);


Use devm for this. You use shared interrupt, so you are not suppose to
mix devm and non-devm, even if this is actually safe.

> +}
> +
> +static const struct of_device_id max77705_charger_of_match[] = {
> +	{ .compatible = "maxim,max77705-charger" },
> +	{ }
> +};
> +MODULE_DEVICE_TABLE(of, max77705_charger_of_match);
> +
> +static struct platform_driver max77705_charger_driver = {
> +	.driver = {
> +		.name = "max77705-charger",
> +		.of_match_table = max77705_charger_of_match,
> +	},
> +	.probe = max77705_charger_probe,
> +	.remove = max77705_charger_remove,
> +};
> +module_platform_driver(max77705_charger_driver);
> +
> +MODULE_AUTHOR("Dzmitry Sankouski <dsankouski@...il.com>");
> +MODULE_DESCRIPTION("Maxim MAX77705 charger driver");
> +MODULE_LICENSE("GPL");
> diff --git a/include/linux/power/max77705_charger.h b/include/linux/power/max77705_charger.h
> new file mode 100644
> index 000000000000..44ecd6b32cbe
> --- /dev/null
> +++ b/include/linux/power/max77705_charger.h
> @@ -0,0 +1,216 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/*
> + * Maxim MAX77705 definitions.
> + *
> + * Copyright (C) 2015 Samsung Electronics, Inc.
> + * Copyright (C) 2024 Dzmitry Sankouski <dsankouski@...il.com>
> + */


...

> +
> +/* MAX77705_CHG_REG_CNFG_10 */
> +#define MAX77705_CHG_WCIN_LIM		GENMASK(5, 0)
> +
> +/* MAX77705_CHG_REG_CNFG_11 */
> +#define MAX77705_VBYPSET_SHIFT		0
> +#define MAX77705_VBYPSET_MASK		GENMASK(6, 0)
> +
> +/* MAX77705_CHG_REG_CNFG_12 */
> +#define MAX77705_CHGINSEL_SHIFT		5
> +#define MAX77705_CHGINSEL_MASK		BIT(MAX77705_CHGINSEL_SHIFT)
> +#define MAX77705_WCINSEL_SHIFT		6
> +#define MAX77705_WCINSEL_MASK		BIT(MAX77705_WCINSEL_SHIFT)
> +#define MAX77705_VCHGIN_REG_MASK	GENMASK(4, 3)
> +#define MAX77705_WCIN_REG_MASK		GENMASK(2, 1)
> +#define MAX77705_REG_DISKIP_SHIFT	0
> +#define MAX77705_REG_DISKIP_MASK	BIT(MAX77705_REG_DISKIP_SHIFT)
> +/* REG=4.5V, UVLO=4.7V */
> +#define MAX77705_VCHGIN_4_5		0
> +/* REG=4.5V, UVLO=4.7V */
> +#define MAX77705_WCIN_4_5		0
> +#define MAX77705_DISABLE_SKIP		1
> +#define MAX77705_AUTO_SKIP		0
> +
> +/* mA */
> +#define MAX77705_CURRENT_STEP		25
> +#define MAX77705_CURRENT_WCIN_MAX	1600
> +#define MAX77705_CURRENT_CHGIN_MAX	3200
> +
> +/* Convert current in mA to corresponding CNFG09 value */
> +inline u8 max77705_convert_ma_to_chgin_ilim_value(unsigned int cur)
> +{
> +	if (cur < MAX77705_CURRENT_STEP)
> +		return 0;
> +	if (cur < MAX77705_CURRENT_CHGIN_MAX)
> +		return (cur / MAX77705_CURRENT_STEP) - 1;
> +	else
> +		return (MAX77705_CURRENT_CHGIN_MAX / MAX77705_CURRENT_STEP) - 1;
> +}


Drop all inlines from header. You are not suppose to have such driver
functions inlined all over the users.


Best regards,
Krzysztof

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ