* [PATCH v1 0/4] Add max6639 regulator and devicetree support
2022-01-03 16:33 [PATCH v1 0/4] Add max6639 regulator and devicetree support Marcello Sylvester Bauer
@ 2022-01-03 16:33 ` Marcello Sylvester Bauer
2022-01-03 16:33 ` [PATCH v1 1/4] hwmon: (max6639) Update Datasheet URL Marcello Sylvester Bauer
` (3 subsequent siblings)
4 siblings, 0 replies; 12+ messages in thread
From: Marcello Sylvester Bauer @ 2022-01-03 16:33 UTC (permalink / raw)
To: linux-hwmon
Cc: Marcello Sylvester Bauer, Patrick Rudolph, Jean Delvare,
Guenter Roeck, linux-kernel
Hi,
these patches add devicetree support for the Maxim MAX6639.
In addition, it includes optional regulator support for the fan-supply and
updates the URL to the datasheet.
Marcello Sylvester Bauer (4):
hwmon: (max6639) Update Datasheet URL
hwmon: (max6639) Add regulator support
dt-bindings: hwmon: Add binding for max6639
hwmon: (max6639) Add devicetree support
.../bindings/hwmon/maxim,max6639.yaml | 71 ++++++++++
Documentation/hwmon/max6639.rst | 2 +-
drivers/hwmon/max6639.c | 122 ++++++++++++++++--
3 files changed, 186 insertions(+), 9 deletions(-)
create mode 100644 Documentation/devicetree/bindings/hwmon/maxim,max6639.yaml
--
2.33.1
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v1 1/4] hwmon: (max6639) Update Datasheet URL
2022-01-03 16:33 ` [PATCH v1 1/4] hwmon: (max6639) Update Datasheet URL Marcello Sylvester Bauer
@ 2022-01-03 16:33 ` Marcello Sylvester Bauer
0 siblings, 0 replies; 12+ messages in thread
From: Marcello Sylvester Bauer @ 2022-01-03 16:33 UTC (permalink / raw)
To: linux-hwmon
Cc: Marcello Sylvester Bauer, Patrick Rudolph, Jean Delvare,
Guenter Roeck, Jonathan Corbet, linux-doc, linux-kernel
The old Datasheet does not exist anymore.
Signed-off-by: Marcello Sylvester Bauer <sylv@sylv.io>
---
Documentation/hwmon/max6639.rst | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Documentation/hwmon/max6639.rst b/Documentation/hwmon/max6639.rst
index 3da54225f83c..c85d285a3489 100644
--- a/Documentation/hwmon/max6639.rst
+++ b/Documentation/hwmon/max6639.rst
@@ -9,7 +9,7 @@ Supported chips:
Addresses scanned: I2C 0x2c, 0x2e, 0x2f
- Datasheet: http://pdfserv.maxim-ic.com/en/ds/MAX6639.pdf
+ Datasheet: https://datasheets.maximintegrated.com/en/ds/MAX6639-MAX6639F.pdf
Authors:
- He Changqing <hechangqing@semptian.com>
--
2.33.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v1 2/4] hwmon: (max6639) Add regulator support
2022-01-03 16:33 ` [PATCH v1 2/4] hwmon: (max6639) Add regulator support Marcello Sylvester Bauer
@ 2022-01-03 16:33 ` Marcello Sylvester Bauer
0 siblings, 0 replies; 12+ messages in thread
From: Marcello Sylvester Bauer @ 2022-01-03 16:33 UTC (permalink / raw)
To: linux-hwmon
Cc: Marcello Sylvester Bauer, Patrick Rudolph, Jean Delvare,
Guenter Roeck, Liam Girdwood, Mark Brown, linux-kernel
Add regulator support for boards where the fan-supply have to be
powered up before it can be used.
Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
Signed-off-by: Marcello Sylvester Bauer <sylv@sylv.io>
---
drivers/hwmon/max6639.c | 75 ++++++++++++++++++++++++++++++++++++-----
1 file changed, 67 insertions(+), 8 deletions(-)
diff --git a/drivers/hwmon/max6639.c b/drivers/hwmon/max6639.c
index ccc0f047bd44..d733c35b5bcf 100644
--- a/drivers/hwmon/max6639.c
+++ b/drivers/hwmon/max6639.c
@@ -87,6 +87,9 @@ struct max6639_data {
/* Register values initialized only once */
u8 ppr; /* Pulses per rotation 0..3 for 1..4 ppr */
u8 rpm_range; /* Index in above rpm_ranges table */
+
+ /* Optional regulator for FAN supply */
+ struct regulator *reg;
};
static struct max6639_data *max6639_update_device(struct device *dev)
@@ -296,6 +299,17 @@ static ssize_t pwm_store(struct device *dev,
return res;
val = clamp_val(val, 0, 255);
+ if (data->reg) {
+ res = 0;
+ if (val == 0)
+ res = regulator_disable(data->reg);
+ else
+ res = regulator_enable(data->reg);
+ if (res) {
+ dev_err(dev, "Failed to operate fan supply: %d\n", res);
+ return res;
+ }
+ }
mutex_lock(&data->update_lock);
data->pwm[attr->index] = (u8)(val * 120 / 255);
@@ -516,6 +530,11 @@ static int max6639_detect(struct i2c_client *client,
return 0;
}
+static void max6639_regulator_disable(void *data)
+{
+ regulator_disable(data);
+}
+
static int max6639_probe(struct i2c_client *client)
{
struct device *dev = &client->dev;
@@ -528,6 +547,30 @@ static int max6639_probe(struct i2c_client *client)
return -ENOMEM;
data->client = client;
+
+ data->reg = devm_regulator_get_optional(dev, "fan");
+ if (IS_ERR(data->reg)) {
+ if (PTR_ERR(data->reg) != -ENODEV) {
+ err = (int)PTR_ERR(data->reg);
+ dev_warn(dev, "Failed looking up fan supply: %d\n", err);
+ return err;
+ }
+ data->reg = NULL;
+ } else {
+ /* Spin up fans */
+ err = regulator_enable(data->reg);
+ if (err) {
+ dev_err(dev, "Failed to enable fan supply: %d\n", err);
+ return err;
+ }
+ err = devm_add_action_or_reset(dev, max6639_regulator_disable,
+ data->reg);
+ if (err) {
+ dev_err(dev, "Failed to register action: %d\n", err);
+ return err;
+ }
+ }
+
mutex_init(&data->update_lock);
/* Initialize the max6639 chip */
@@ -545,23 +588,39 @@ static int max6639_probe(struct i2c_client *client)
static int max6639_suspend(struct device *dev)
{
struct i2c_client *client = to_i2c_client(dev);
- int data = i2c_smbus_read_byte_data(client, MAX6639_REG_GCONFIG);
- if (data < 0)
- return data;
+ struct max6639_data *data = dev_get_drvdata(dev);
+ int ret = i2c_smbus_read_byte_data(client, MAX6639_REG_GCONFIG);
+
+ if (ret < 0)
+ return ret;
+
+ if (data->reg)
+ regulator_disable(data->reg);
return i2c_smbus_write_byte_data(client,
- MAX6639_REG_GCONFIG, data | MAX6639_GCONFIG_STANDBY);
+ MAX6639_REG_GCONFIG, ret | MAX6639_GCONFIG_STANDBY);
}
static int max6639_resume(struct device *dev)
{
struct i2c_client *client = to_i2c_client(dev);
- int data = i2c_smbus_read_byte_data(client, MAX6639_REG_GCONFIG);
- if (data < 0)
- return data;
+ struct max6639_data *data = dev_get_drvdata(dev);
+ int ret;
+
+ if (data->reg) {
+ ret = regulator_enable(data->reg);
+ if (ret) {
+ dev_err(dev, "Failed to enable fan supply: %d\n", ret);
+ return ret;
+ }
+ }
+
+ ret = i2c_smbus_read_byte_data(client, MAX6639_REG_GCONFIG);
+ if (ret < 0)
+ return ret;
return i2c_smbus_write_byte_data(client,
- MAX6639_REG_GCONFIG, data & ~MAX6639_GCONFIG_STANDBY);
+ MAX6639_REG_GCONFIG, ret & ~MAX6639_GCONFIG_STANDBY);
}
#endif /* CONFIG_PM_SLEEP */
--
2.33.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v1 3/4] dt-bindings: hwmon: Add binding for max6639
2022-01-03 16:33 ` [PATCH v1 3/4] dt-bindings: hwmon: Add binding for max6639 Marcello Sylvester Bauer
@ 2022-01-03 16:33 ` Marcello Sylvester Bauer
2022-01-10 1:22 ` Guenter Roeck
1 sibling, 0 replies; 12+ messages in thread
From: Marcello Sylvester Bauer @ 2022-01-03 16:33 UTC (permalink / raw)
To: linux-hwmon
Cc: Marcello Sylvester Bauer, Patrick Rudolph, Jean Delvare,
Guenter Roeck, Rob Herring, Roland Stigge, devicetree,
linux-kernel
Add Devicetree binding documentation for Maxim MAX6639 temperature
monitor with PWM fan-speed controller.
The devicetree documentation for the SD3078 device tree.
Signed-off-by: Marcello Sylvester Bauer <sylv@sylv.io>
---
.../bindings/hwmon/maxim,max6639.yaml | 71 +++++++++++++++++++
1 file changed, 71 insertions(+)
create mode 100644 Documentation/devicetree/bindings/hwmon/maxim,max6639.yaml
diff --git a/Documentation/devicetree/bindings/hwmon/maxim,max6639.yaml b/Documentation/devicetree/bindings/hwmon/maxim,max6639.yaml
new file mode 100644
index 000000000000..136ed37b6aac
--- /dev/null
+++ b/Documentation/devicetree/bindings/hwmon/maxim,max6639.yaml
@@ -0,0 +1,71 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+
+$id: http://devicetree.org/schemas/hwmon/maxim,max6639.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Maxim max6639
+
+maintainers:
+ - Roland Stigge <stigge@antcom.de>
+
+description: |
+ The MAX6639 is a 2-channel temperature monitor with dual, automatic, PWM
+ fan-speed controller. It monitors its own temperature and one external
+ diode-connected transistor or the temperatures of two external diode-connected
+ transistors, typically available in CPUs, FPGAs, or GPUs.
+
+ Datasheets:
+ https://datasheets.maximintegrated.com/en/ds/MAX6639-MAX6639F.pdf
+
+properties:
+ compatible:
+ enum:
+ - maxim,max6639
+
+ reg:
+ maxItems: 1
+
+ polarity:
+ $ref: /schemas/types.yaml#/definitions/uint32
+ enum: [0, 1]
+ description:
+ PWM output is low at 100% duty cycle when this bit is set to zero. PWM
+ output is high at 100% duty cycle when this bit is set to 1.
+ Fans PWM polarity is set to high (1) by default.
+
+ pulses-per-revolution:
+ $ref: /schemas/types.yaml#/definitions/uint32
+ enum: [1, 2, 3, 4]
+ description:
+ Value specifying the number of pulses per revolution of the controlled
+ FAN.
+
+ rpm-range:
+ $ref: /schemas/types.yaml#/definitions/uint32
+ enum: [2000, 4000, 8000, 16000]
+ description:
+ Scales the tachometer counter by setting the maximum (full-scale) value
+ of the RPM range.
+
+required:
+ - compatible
+ - reg
+
+additionalProperties: false
+
+examples:
+ - |
+ i2c {
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ max6639@10 {
+ compatible = "maxim,max6639";
+ reg = <0x10>;
+ polarity = <1>;
+ pulses-per-revolution = <2>;
+ rpm-range = <4000>;
+ };
+ };
--
2.33.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v1 4/4] hwmon: (max6639) Add devicetree support
2022-01-03 16:33 ` [PATCH v1 4/4] hwmon: (max6639) Add devicetree support Marcello Sylvester Bauer
@ 2022-01-03 16:33 ` Marcello Sylvester Bauer
0 siblings, 0 replies; 12+ messages in thread
From: Marcello Sylvester Bauer @ 2022-01-03 16:33 UTC (permalink / raw)
To: linux-hwmon
Cc: Marcello Sylvester Bauer, Patrick Rudolph, Jean Delvare,
Guenter Roeck, linux-kernel
Allow the driver to work with device tree support.
Signed-off-by: Marcello Sylvester Bauer <sylv@sylv.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
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v1 0/4] Add max6639 regulator and devicetree support
@ 2022-01-03 16:33 Marcello Sylvester Bauer
2022-01-03 16:33 ` Marcello Sylvester Bauer
` (4 more replies)
0 siblings, 5 replies; 12+ messages in thread
From: Marcello Sylvester Bauer @ 2022-01-03 16:33 UTC (permalink / raw)
To: linux-hwmon
Cc: Marcello Sylvester Bauer, Patrick Rudolph, Jean Delvare,
Guenter Roeck, linux-kernel
Hi,
these patches add devicetree support for the Maxim MAX6639.
In addition, it includes optional regulator support for the fan-supply and
updates the URL to the datasheet.
Marcello Sylvester Bauer (4):
hwmon: (max6639) Update Datasheet URL
hwmon: (max6639) Add regulator support
dt-bindings: hwmon: Add binding for max6639
hwmon: (max6639) Add devicetree support
.../bindings/hwmon/maxim,max6639.yaml | 71 ++++++++++
Documentation/hwmon/max6639.rst | 2 +-
drivers/hwmon/max6639.c | 122 ++++++++++++++++--
3 files changed, 186 insertions(+), 9 deletions(-)
create mode 100644 Documentation/devicetree/bindings/hwmon/maxim,max6639.yaml
--
2.33.1
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v1 1/4] hwmon: (max6639) Update Datasheet URL
2022-01-03 16:33 [PATCH v1 0/4] Add max6639 regulator and devicetree support Marcello Sylvester Bauer
2022-01-03 16:33 ` Marcello Sylvester Bauer
@ 2022-01-03 16:33 ` Marcello Sylvester Bauer
2022-01-03 16:33 ` Marcello Sylvester Bauer
2022-01-03 16:33 ` [PATCH v1 2/4] hwmon: (max6639) Add regulator support Marcello Sylvester Bauer
` (2 subsequent siblings)
4 siblings, 1 reply; 12+ messages in thread
From: Marcello Sylvester Bauer @ 2022-01-03 16:33 UTC (permalink / raw)
To: linux-hwmon
Cc: Marcello Sylvester Bauer, Patrick Rudolph, Jean Delvare,
Guenter Roeck, Jonathan Corbet, linux-doc, linux-kernel
The old Datasheet does not exist anymore.
Signed-off-by: Marcello Sylvester Bauer <sylv@sylv.io>
---
Documentation/hwmon/max6639.rst | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Documentation/hwmon/max6639.rst b/Documentation/hwmon/max6639.rst
index 3da54225f83c..c85d285a3489 100644
--- a/Documentation/hwmon/max6639.rst
+++ b/Documentation/hwmon/max6639.rst
@@ -9,7 +9,7 @@ Supported chips:
Addresses scanned: I2C 0x2c, 0x2e, 0x2f
- Datasheet: http://pdfserv.maxim-ic.com/en/ds/MAX6639.pdf
+ Datasheet: https://datasheets.maximintegrated.com/en/ds/MAX6639-MAX6639F.pdf
Authors:
- He Changqing <hechangqing@semptian.com>
--
2.33.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v1 2/4] hwmon: (max6639) Add regulator support
2022-01-03 16:33 [PATCH v1 0/4] Add max6639 regulator and devicetree support Marcello Sylvester Bauer
2022-01-03 16:33 ` Marcello Sylvester Bauer
2022-01-03 16:33 ` [PATCH v1 1/4] hwmon: (max6639) Update Datasheet URL Marcello Sylvester Bauer
@ 2022-01-03 16:33 ` Marcello Sylvester Bauer
2022-01-03 16:33 ` Marcello Sylvester Bauer
2022-01-03 16:33 ` [PATCH v1 3/4] dt-bindings: hwmon: Add binding for max6639 Marcello Sylvester Bauer
2022-01-03 16:33 ` [PATCH v1 4/4] hwmon: (max6639) Add devicetree support Marcello Sylvester Bauer
4 siblings, 1 reply; 12+ messages in thread
From: Marcello Sylvester Bauer @ 2022-01-03 16:33 UTC (permalink / raw)
To: linux-hwmon
Cc: Marcello Sylvester Bauer, Patrick Rudolph, Jean Delvare,
Guenter Roeck, Liam Girdwood, Mark Brown, linux-kernel
Add regulator support for boards where the fan-supply have to be
powered up before it can be used.
Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
Signed-off-by: Marcello Sylvester Bauer <sylv@sylv.io>
---
drivers/hwmon/max6639.c | 75 ++++++++++++++++++++++++++++++++++++-----
1 file changed, 67 insertions(+), 8 deletions(-)
diff --git a/drivers/hwmon/max6639.c b/drivers/hwmon/max6639.c
index ccc0f047bd44..d733c35b5bcf 100644
--- a/drivers/hwmon/max6639.c
+++ b/drivers/hwmon/max6639.c
@@ -87,6 +87,9 @@ struct max6639_data {
/* Register values initialized only once */
u8 ppr; /* Pulses per rotation 0..3 for 1..4 ppr */
u8 rpm_range; /* Index in above rpm_ranges table */
+
+ /* Optional regulator for FAN supply */
+ struct regulator *reg;
};
static struct max6639_data *max6639_update_device(struct device *dev)
@@ -296,6 +299,17 @@ static ssize_t pwm_store(struct device *dev,
return res;
val = clamp_val(val, 0, 255);
+ if (data->reg) {
+ res = 0;
+ if (val == 0)
+ res = regulator_disable(data->reg);
+ else
+ res = regulator_enable(data->reg);
+ if (res) {
+ dev_err(dev, "Failed to operate fan supply: %d\n", res);
+ return res;
+ }
+ }
mutex_lock(&data->update_lock);
data->pwm[attr->index] = (u8)(val * 120 / 255);
@@ -516,6 +530,11 @@ static int max6639_detect(struct i2c_client *client,
return 0;
}
+static void max6639_regulator_disable(void *data)
+{
+ regulator_disable(data);
+}
+
static int max6639_probe(struct i2c_client *client)
{
struct device *dev = &client->dev;
@@ -528,6 +547,30 @@ static int max6639_probe(struct i2c_client *client)
return -ENOMEM;
data->client = client;
+
+ data->reg = devm_regulator_get_optional(dev, "fan");
+ if (IS_ERR(data->reg)) {
+ if (PTR_ERR(data->reg) != -ENODEV) {
+ err = (int)PTR_ERR(data->reg);
+ dev_warn(dev, "Failed looking up fan supply: %d\n", err);
+ return err;
+ }
+ data->reg = NULL;
+ } else {
+ /* Spin up fans */
+ err = regulator_enable(data->reg);
+ if (err) {
+ dev_err(dev, "Failed to enable fan supply: %d\n", err);
+ return err;
+ }
+ err = devm_add_action_or_reset(dev, max6639_regulator_disable,
+ data->reg);
+ if (err) {
+ dev_err(dev, "Failed to register action: %d\n", err);
+ return err;
+ }
+ }
+
mutex_init(&data->update_lock);
/* Initialize the max6639 chip */
@@ -545,23 +588,39 @@ static int max6639_probe(struct i2c_client *client)
static int max6639_suspend(struct device *dev)
{
struct i2c_client *client = to_i2c_client(dev);
- int data = i2c_smbus_read_byte_data(client, MAX6639_REG_GCONFIG);
- if (data < 0)
- return data;
+ struct max6639_data *data = dev_get_drvdata(dev);
+ int ret = i2c_smbus_read_byte_data(client, MAX6639_REG_GCONFIG);
+
+ if (ret < 0)
+ return ret;
+
+ if (data->reg)
+ regulator_disable(data->reg);
return i2c_smbus_write_byte_data(client,
- MAX6639_REG_GCONFIG, data | MAX6639_GCONFIG_STANDBY);
+ MAX6639_REG_GCONFIG, ret | MAX6639_GCONFIG_STANDBY);
}
static int max6639_resume(struct device *dev)
{
struct i2c_client *client = to_i2c_client(dev);
- int data = i2c_smbus_read_byte_data(client, MAX6639_REG_GCONFIG);
- if (data < 0)
- return data;
+ struct max6639_data *data = dev_get_drvdata(dev);
+ int ret;
+
+ if (data->reg) {
+ ret = regulator_enable(data->reg);
+ if (ret) {
+ dev_err(dev, "Failed to enable fan supply: %d\n", ret);
+ return ret;
+ }
+ }
+
+ ret = i2c_smbus_read_byte_data(client, MAX6639_REG_GCONFIG);
+ if (ret < 0)
+ return ret;
return i2c_smbus_write_byte_data(client,
- MAX6639_REG_GCONFIG, data & ~MAX6639_GCONFIG_STANDBY);
+ MAX6639_REG_GCONFIG, ret & ~MAX6639_GCONFIG_STANDBY);
}
#endif /* CONFIG_PM_SLEEP */
--
2.33.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v1 3/4] dt-bindings: hwmon: Add binding for max6639
2022-01-03 16:33 [PATCH v1 0/4] Add max6639 regulator and devicetree support Marcello Sylvester Bauer
` (2 preceding siblings ...)
2022-01-03 16:33 ` [PATCH v1 2/4] hwmon: (max6639) Add regulator support Marcello Sylvester Bauer
@ 2022-01-03 16:33 ` Marcello Sylvester Bauer
2022-01-03 16:33 ` Marcello Sylvester Bauer
2022-01-10 1:22 ` Guenter Roeck
2022-01-03 16:33 ` [PATCH v1 4/4] hwmon: (max6639) Add devicetree support Marcello Sylvester Bauer
4 siblings, 2 replies; 12+ messages in thread
From: Marcello Sylvester Bauer @ 2022-01-03 16:33 UTC (permalink / raw)
To: linux-hwmon
Cc: Marcello Sylvester Bauer, Patrick Rudolph, Jean Delvare,
Guenter Roeck, Rob Herring, Roland Stigge, devicetree,
linux-kernel
Add Devicetree binding documentation for Maxim MAX6639 temperature
monitor with PWM fan-speed controller.
The devicetree documentation for the SD3078 device tree.
Signed-off-by: Marcello Sylvester Bauer <sylv@sylv.io>
---
.../bindings/hwmon/maxim,max6639.yaml | 71 +++++++++++++++++++
1 file changed, 71 insertions(+)
create mode 100644 Documentation/devicetree/bindings/hwmon/maxim,max6639.yaml
diff --git a/Documentation/devicetree/bindings/hwmon/maxim,max6639.yaml b/Documentation/devicetree/bindings/hwmon/maxim,max6639.yaml
new file mode 100644
index 000000000000..136ed37b6aac
--- /dev/null
+++ b/Documentation/devicetree/bindings/hwmon/maxim,max6639.yaml
@@ -0,0 +1,71 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+
+$id: http://devicetree.org/schemas/hwmon/maxim,max6639.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Maxim max6639
+
+maintainers:
+ - Roland Stigge <stigge@antcom.de>
+
+description: |
+ The MAX6639 is a 2-channel temperature monitor with dual, automatic, PWM
+ fan-speed controller. It monitors its own temperature and one external
+ diode-connected transistor or the temperatures of two external diode-connected
+ transistors, typically available in CPUs, FPGAs, or GPUs.
+
+ Datasheets:
+ https://datasheets.maximintegrated.com/en/ds/MAX6639-MAX6639F.pdf
+
+properties:
+ compatible:
+ enum:
+ - maxim,max6639
+
+ reg:
+ maxItems: 1
+
+ polarity:
+ $ref: /schemas/types.yaml#/definitions/uint32
+ enum: [0, 1]
+ description:
+ PWM output is low at 100% duty cycle when this bit is set to zero. PWM
+ output is high at 100% duty cycle when this bit is set to 1.
+ Fans PWM polarity is set to high (1) by default.
+
+ pulses-per-revolution:
+ $ref: /schemas/types.yaml#/definitions/uint32
+ enum: [1, 2, 3, 4]
+ description:
+ Value specifying the number of pulses per revolution of the controlled
+ FAN.
+
+ rpm-range:
+ $ref: /schemas/types.yaml#/definitions/uint32
+ enum: [2000, 4000, 8000, 16000]
+ description:
+ Scales the tachometer counter by setting the maximum (full-scale) value
+ of the RPM range.
+
+required:
+ - compatible
+ - reg
+
+additionalProperties: false
+
+examples:
+ - |
+ i2c {
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ max6639@10 {
+ compatible = "maxim,max6639";
+ reg = <0x10>;
+ polarity = <1>;
+ pulses-per-revolution = <2>;
+ rpm-range = <4000>;
+ };
+ };
--
2.33.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v1 4/4] hwmon: (max6639) Add devicetree support
2022-01-03 16:33 [PATCH v1 0/4] Add max6639 regulator and devicetree support Marcello Sylvester Bauer
` (3 preceding siblings ...)
2022-01-03 16:33 ` [PATCH v1 3/4] dt-bindings: hwmon: Add binding for max6639 Marcello Sylvester Bauer
@ 2022-01-03 16:33 ` Marcello Sylvester Bauer
2022-01-03 16:33 ` Marcello Sylvester Bauer
4 siblings, 1 reply; 12+ messages in thread
From: Marcello Sylvester Bauer @ 2022-01-03 16:33 UTC (permalink / raw)
To: linux-hwmon
Cc: Marcello Sylvester Bauer, Patrick Rudolph, Jean Delvare,
Guenter Roeck, linux-kernel
Allow the driver to work with device tree support.
Signed-off-by: Marcello Sylvester Bauer <sylv@sylv.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
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH v1 3/4] dt-bindings: hwmon: Add binding for max6639
2022-01-03 16:33 ` [PATCH v1 3/4] dt-bindings: hwmon: Add binding for max6639 Marcello Sylvester Bauer
2022-01-03 16:33 ` Marcello Sylvester Bauer
@ 2022-01-10 1:22 ` Guenter Roeck
2022-01-13 10:39 ` sylv
1 sibling, 1 reply; 12+ messages in thread
From: Guenter Roeck @ 2022-01-10 1:22 UTC (permalink / raw)
To: Marcello Sylvester Bauer
Cc: linux-hwmon, Patrick Rudolph, Jean Delvare, Rob Herring,
Roland Stigge, devicetree, linux-kernel
On Mon, Jan 03, 2022 at 05:33:48PM +0100, Marcello Sylvester Bauer wrote:
> Add Devicetree binding documentation for Maxim MAX6639 temperature
> monitor with PWM fan-speed controller.
>
> The devicetree documentation for the SD3078 device tree.
>
> Signed-off-by: Marcello Sylvester Bauer <sylv@sylv.io>
> ---
> .../bindings/hwmon/maxim,max6639.yaml | 71 +++++++++++++++++++
> 1 file changed, 71 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/hwmon/maxim,max6639.yaml
>
> diff --git a/Documentation/devicetree/bindings/hwmon/maxim,max6639.yaml b/Documentation/devicetree/bindings/hwmon/maxim,max6639.yaml
> new file mode 100644
> index 000000000000..136ed37b6aac
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/hwmon/maxim,max6639.yaml
> @@ -0,0 +1,71 @@
> +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
> +%YAML 1.2
> +---
> +
> +$id: http://devicetree.org/schemas/hwmon/maxim,max6639.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: Maxim max6639
> +
> +maintainers:
> + - Roland Stigge <stigge@antcom.de>
> +
> +description: |
> + The MAX6639 is a 2-channel temperature monitor with dual, automatic, PWM
> + fan-speed controller. It monitors its own temperature and one external
> + diode-connected transistor or the temperatures of two external diode-connected
> + transistors, typically available in CPUs, FPGAs, or GPUs.
> +
> + Datasheets:
> + https://datasheets.maximintegrated.com/en/ds/MAX6639-MAX6639F.pdf
> +
> +properties:
> + compatible:
> + enum:
> + - maxim,max6639
> +
> + reg:
> + maxItems: 1
> +
> + polarity:
> + $ref: /schemas/types.yaml#/definitions/uint32
> + enum: [0, 1]
> + description:
> + PWM output is low at 100% duty cycle when this bit is set to zero. PWM
> + output is high at 100% duty cycle when this bit is set to 1.
> + Fans PWM polarity is set to high (1) by default.
Should probably be pwm-polarity.
> +
> + pulses-per-revolution:
> + $ref: /schemas/types.yaml#/definitions/uint32
> + enum: [1, 2, 3, 4]
> + description:
> + Value specifying the number of pulses per revolution of the controlled
> + FAN.
Is there a fan in the world with pulses-per-revolution == 3 ?
Valid values should probably be 1, 2, 4.
> +
> + rpm-range:
> + $ref: /schemas/types.yaml#/definitions/uint32
> + enum: [2000, 4000, 8000, 16000]
> + description:
> + Scales the tachometer counter by setting the maximum (full-scale) value
> + of the RPM range.
The above need to be per channel in devicetree data.
On higher level, max6639_platform_data should be removed entirely.
It isn't used by any in-kernel driver, and all its parameters are
per device and not per channel as they should be.
Guenter
> +
> +required:
> + - compatible
> + - reg
> +
> +additionalProperties: false
> +
> +examples:
> + - |
> + i2c {
> + #address-cells = <1>;
> + #size-cells = <0>;
> +
> + max6639@10 {
> + compatible = "maxim,max6639";
> + reg = <0x10>;
> + polarity = <1>;
> + pulses-per-revolution = <2>;
> + rpm-range = <4000>;
> + };
> + };
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v1 3/4] dt-bindings: hwmon: Add binding for max6639
2022-01-10 1:22 ` Guenter Roeck
@ 2022-01-13 10:39 ` sylv
0 siblings, 0 replies; 12+ messages in thread
From: sylv @ 2022-01-13 10:39 UTC (permalink / raw)
To: Guenter Roeck
Cc: linux-hwmon, Patrick Rudolph, Jean Delvare, Rob Herring,
Roland Stigge, devicetree, linux-kernel
Hi Guenter,
Thanks for your review.
On Sun, 2022-01-09 at 17:22 -0800, Guenter Roeck wrote:
> On Mon, Jan 03, 2022 at 05:33:48PM +0100, Marcello Sylvester Bauer wrote:
> > Add Devicetree binding documentation for Maxim MAX6639 temperature
> > monitor with PWM fan-speed controller.
> >
> > The devicetree documentation for the SD3078 device tree.
> >
> > Signed-off-by: Marcello Sylvester Bauer <sylv@sylv.io>
> > ---
> > .../bindings/hwmon/maxim,max6639.yaml | 71 +++++++++++++++++++
> > 1 file changed, 71 insertions(+)
> > create mode 100644 Documentation/devicetree/bindings/hwmon/maxim,max6639.yaml
> >
> > diff --git a/Documentation/devicetree/bindings/hwmon/maxim,max6639.yaml b/Documentation/devicetree/bindings/hwmon/maxim,max6639.yaml
> > new file mode 100644
> > index 000000000000..136ed37b6aac
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/hwmon/maxim,max6639.yaml
> > @@ -0,0 +1,71 @@
> > +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
> > +%YAML 1.2
> > +---
> > +
> > +$id: http://devicetree.org/schemas/hwmon/maxim,max6639.yaml#
> > +$schema: http://devicetree.org/meta-schemas/core.yaml#
> > +
> > +title: Maxim max6639
> > +
> > +maintainers:
> > + - Roland Stigge <stigge@antcom.de>
> > +
> > +description: |
> > + The MAX6639 is a 2-channel temperature monitor with dual, automatic, PWM
> > + fan-speed controller. It monitors its own temperature and one external
> > + diode-connected transistor or the temperatures of two external diode-connected
> > + transistors, typically available in CPUs, FPGAs, or GPUs.
> > +
> > + Datasheets:
> > + https://datasheets.maximintegrated.com/en/ds/MAX6639-MAX6639F.pdf
> > +
> > +properties:
> > + compatible:
> > + enum:
> > + - maxim,max6639
> > +
> > + reg:
> > + maxItems: 1
> > +
> > + polarity:
> > + $ref: /schemas/types.yaml#/definitions/uint32
> > + enum: [0, 1]
> > + description:
> > + PWM output is low at 100% duty cycle when this bit is set to zero. PWM
> > + output is high at 100% duty cycle when this bit is set to 1.
> > + Fans PWM polarity is set to high (1) by default.
>
> Should probably be pwm-polarity.
>
indeed.
> > +
> > + pulses-per-revolution:
> > + $ref: /schemas/types.yaml#/definitions/uint32
> > + enum: [1, 2, 3, 4]
> > + description:
> > + Value specifying the number of pulses per revolution of the controlled
> > + FAN.
>
> Is there a fan in the world with pulses-per-revolution == 3 ?
> Valid values should probably be 1, 2, 4.
>
No sure but regarding the data sheet, it is a valid value for ppr:
https://datasheets.maximintegrated.com/en/ds/MAX6639-MAX6639F.pdf
Page 16, Table 10
In my view we should keep it, since the IC does allow this values to be
set accordingly.
> > +
> > + rpm-range:
> > + $ref: /schemas/types.yaml#/definitions/uint32
> > + enum: [2000, 4000, 8000, 16000]
> > + description:
> > + Scales the tachometer counter by setting the maximum (full-scale) value
> > + of the RPM range.
>
> The above need to be per channel in devicetree data.
>
> On higher level, max6639_platform_data should be removed entirely.
> It isn't used by any in-kernel driver, and all its parameters are
> per device and not per channel as they should be.
Sounds great. In this way we could get rid of get_pdata_from_dt_node
and make it easier to add additional proprieties in future.
I'll adapt v2 to implement this change.
Marcello
>
> Guenter
>
> > +
> > +required:
> > + - compatible
> > + - reg
> > +
> > +additionalProperties: false
> > +
> > +examples:
> > + - |
> > + i2c {
> > + #address-cells = <1>;
> > + #size-cells = <0>;
> > +
> > + max6639@10 {
> > + compatible = "maxim,max6639";
> > + reg = <0x10>;
> > + polarity = <1>;
> > + pulses-per-revolution = <2>;
> > + rpm-range = <4000>;
> > + };
> > + };
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2022-01-13 10:40 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-03 16:33 [PATCH v1 0/4] Add max6639 regulator and devicetree support Marcello Sylvester Bauer
2022-01-03 16:33 ` Marcello Sylvester Bauer
2022-01-03 16:33 ` [PATCH v1 1/4] hwmon: (max6639) Update Datasheet URL Marcello Sylvester Bauer
2022-01-03 16:33 ` Marcello Sylvester Bauer
2022-01-03 16:33 ` [PATCH v1 2/4] hwmon: (max6639) Add regulator support Marcello Sylvester Bauer
2022-01-03 16:33 ` Marcello Sylvester Bauer
2022-01-03 16:33 ` [PATCH v1 3/4] dt-bindings: hwmon: Add binding for max6639 Marcello Sylvester Bauer
2022-01-03 16:33 ` Marcello Sylvester Bauer
2022-01-10 1:22 ` Guenter Roeck
2022-01-13 10:39 ` sylv
2022-01-03 16:33 ` [PATCH v1 4/4] hwmon: (max6639) Add devicetree support Marcello Sylvester Bauer
2022-01-03 16:33 ` Marcello Sylvester Bauer
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).