Add max6639 regulator and devicetree support
Subsystems (3)
cover Add max6639 regulator and devicetree support
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
Signature · 1 line
2.33.1
PATCH 1/4 hwmon: (max6639) Update Datasheet URL
The old Datasheet does not exist anymore.
--- Documentation/hwmon/max6639.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Documentation/hwmon/max6639.rst +1 -1
@@ -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 <[email protected]>
Signature · 1 line
2.33.1
PATCH 2/4 hwmon: (max6639) Add regulator support
In reply to Marcello Sylvester BauerAdd regulator support for boards where the fan-supply have to be powered up before it can be used.
--- drivers/hwmon/max6639.c | 75 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 67 insertions(+), 8 deletions(-)
drivers/hwmon/max6639.c +67 -8
@@ -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 */
Signature · 1 line
2.33.1
PATCH 3/4 dt-bindings: hwmon: Add binding for max6639
In reply to Marcello Sylvester BauerAdd Devicetree binding documentation for Maxim MAX6639 temperature monitor with PWM fan-speed controller.
The devicetree documentation for the SD3078 device tree.
--- .../bindings/hwmon/maxim,max6639.yaml | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 Documentation/devicetree/bindings/hwmon/maxim,max6639.yaml
Documentation/devicetree/bindings/hwmon/maxim,max6639.yaml new file +71 -0
@@ -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 <[email protected]> + +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>; + }; + };
Signature · 1 line
2.33.1
Guenter Roeck
maintainerRe: [PATCH v1 3/4] dt-bindings: hwmon: Add binding for max6639
Quoted 43 lines · Marcello Sylvester Bauer
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 <[email protected]>--- .../bindings/hwmon/maxim,max6639.yaml | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 Documentation/devicetree/bindings/hwmon/maxim,max6639.yamlDocumentation/devicetree/bindings/hwmon/maxim,max6639.yaml new file +26
-0@@ -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 <[email protected]> + +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 +
Documentation/devicetree/bindings/hwmon/maxim,max6639.yaml line 36
Quoted 10 lines
Documentation/devicetree/bindings/hwmon/maxim,max6639.yaml new file +10
-0+ 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.
Documentation/devicetree/bindings/hwmon/maxim,max6639.yaml line 43
Quoted 7 lines
Documentation/devicetree/bindings/hwmon/maxim,max6639.yaml new file +7
-0+ + 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.
Documentation/devicetree/bindings/hwmon/maxim,max6639.yaml line 50
Quoted 7 lines
Documentation/devicetree/bindings/hwmon/maxim,max6639.yaml new file +7
-0+ + 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
Quoted 21 lines
Documentation/devicetree/bindings/hwmon/maxim,max6639.yaml new file +21
-0+ +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>; + }; + };
Re: [PATCH v1 3/4] dt-bindings: hwmon: Add binding for max6639
Hi Guenter,
Thanks for your review.
Quoted 48 lines · Guenter Roeck
Quoted 47 lines · Marcello Sylvester Bauer
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 <[email protected]>--- .../bindings/hwmon/maxim,max6639.yaml | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 Documentation/devicetree/bindings/hwmon/maxim,max6639.yamlDocumentation/devicetree/bindings/hwmon/maxim,max6639.yaml new file +30
-0@@ -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 <[email protected]> + +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:
Quoted 9 lines
Documentation/devicetree/bindings/hwmon/maxim,max6639.yaml line 36
Quoted 6 lines
Documentation/devicetree/bindings/hwmon/maxim,max6639.yaml new file +6
-0+ $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.
Quoted 11 lines
Documentation/devicetree/bindings/hwmon/maxim,max6639.yaml line 43
Quoted 7 lines
Documentation/devicetree/bindings/hwmon/maxim,max6639.yaml new file +7
-0+ + 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.
Quoted 8 lines
Documentation/devicetree/bindings/hwmon/maxim,max6639.yaml line 50
Quoted 7 lines
Documentation/devicetree/bindings/hwmon/maxim,max6639.yaml new file +7
-0+ + 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.
Quoted 5 lines
The above need to be per channel in devicetree data.
On higher level,
max6639_platform_datashould 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
Quoted 24 lines
Guenter
Quoted 21 lines
Documentation/devicetree/bindings/hwmon/maxim,max6639.yaml new file +21
-0+ +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>; + }; + };
PATCH 4/4 hwmon: (max6639) Add devicetree support
In reply to Marcello Sylvester BauerAllow the driver to work with device tree support.
--- drivers/hwmon/max6639.c | 47 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+)
drivers/hwmon/max6639.c +47 -0
@@ -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,
Signature · 1 line
2.33.1