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]
Date:   Mon,  3 Jan 2022 17:33:54 +0100
From:   Marcello Sylvester Bauer <sylv@...v.io>
To:     linux-hwmon@...r.kernel.org
Cc:     Marcello Sylvester Bauer <sylv@...v.io>,
        Patrick Rudolph <patrick.rudolph@...ements.com>,
        Jean Delvare <jdelvare@...e.com>,
        Guenter Roeck <linux@...ck-us.net>,
        linux-kernel@...r.kernel.org
Subject: [PATCH v1 4/4] hwmon: (max6639) Add devicetree support

Allow the driver to work with device tree support.

Signed-off-by: Marcello Sylvester Bauer <sylv@...v.io>
---
 drivers/hwmon/max6639.c | 47 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/drivers/hwmon/max6639.c b/drivers/hwmon/max6639.c
index d733c35b5bcf..f84ee4a05f80 100644
--- a/drivers/hwmon/max6639.c
+++ b/drivers/hwmon/max6639.c
@@ -412,6 +412,38 @@ static int rpm_range_to_reg(int range)
 	return 1; /* default: 4000 RPM */
 }
 
+static struct max6639_platform_data *get_pdata_from_dt_node(struct device *dev)
+{
+	struct max6639_platform_data *pdata;
+	u32 pol, ppr, rpm;
+	int ret;
+
+	pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
+	if (!pdata)
+		return ERR_PTR(-ENOMEM);
+
+	pdata->pwm_polarity = true;
+	ret = of_property_read_u32(dev->of_node, "polarity", &pol);
+	if (!ret && !pol)
+		pdata->pwm_polarity = false;
+
+	ret = of_property_read_u32(dev->of_node, "pulses-per-revolution", &ppr);
+	if (ret < 0)
+		dev_warn(dev, "No pulses-per-revolution property\n");
+	else
+		pdata->ppr = ppr;
+
+	ret = of_property_read_u32(dev->of_node, "rpm-range", &rpm);
+	if (ret < 0) {
+		dev_warn(dev, "no rpm-range property\n");
+		pdata->rpm_range = 4000;
+	} else {
+		pdata->rpm_range = rpm;
+	}
+
+	return pdata;
+}
+
 static int max6639_init_client(struct i2c_client *client,
 			       struct max6639_data *data)
 {
@@ -421,6 +453,12 @@ static int max6639_init_client(struct i2c_client *client,
 	int rpm_range = 1; /* default: 4000 RPM */
 	int err;
 
+	if (!max6639_info && client->dev.of_node) {
+		max6639_info = get_pdata_from_dt_node(&client->dev);
+		if (IS_ERR(max6639_info))
+			return PTR_ERR(max6639_info);
+	}
+
 	/* Reset chip to default values, see below for GCONFIG setup */
 	err = i2c_smbus_write_byte_data(client, MAX6639_REG_GCONFIG,
 				  MAX6639_GCONFIG_POR);
@@ -631,6 +669,14 @@ static const struct i2c_device_id max6639_id[] = {
 
 MODULE_DEVICE_TABLE(i2c, max6639_id);
 
+#ifdef CONFIG_OF
+static const struct of_device_id maxim_of_platform_match[] = {
+	{.compatible = "maxim,max6639"},
+	{},
+};
+MODULE_DEVICE_TABLE(of, maxim_of_platform_match);
+#endif
+
 static SIMPLE_DEV_PM_OPS(max6639_pm_ops, max6639_suspend, max6639_resume);
 
 static struct i2c_driver max6639_driver = {
@@ -638,6 +684,7 @@ static struct i2c_driver max6639_driver = {
 	.driver = {
 		   .name = "max6639",
 		   .pm = &max6639_pm_ops,
+		   .of_match_table = of_match_ptr(maxim_of_platform_match),
 		   },
 	.probe_new = max6639_probe,
 	.id_table = max6639_id,
-- 
2.33.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ