From 76150158c13ffe8a1228431e6ca4ecaa61aa8795 Mon Sep 17 00:00:00 2001 From: Oleg S Date: Thu, 4 Jan 2024 21:45:27 +0300 Subject: [PATCH] ipq806x: Add kmod-hwmon-emc2305 for devices with FAN controller Kernel driver patches have also been added. These patches should be taken from /target/linux/bcm27xx/patches-*/ Signed-off-by: Oleg S --- target/linux/ipq806x/modules.mk | 15 ++ ...n-add-microchip-emc2305.yaml-dt-bind.patch | 75 ++++++++ ...ixup-microchip-emc2305.yaml-bindings.patch | 40 +++++ ...xups-for-driver-submitted-to-mailing.patch | 163 ++++++++++++++++++ ...d-calls-to-initialise-of-cooling-map.patch | 54 ++++++ ...ange-OF-properties-pwm-min-pwm-max-t.patch | 69 ++++++++ 6 files changed, 416 insertions(+) create mode 100644 target/linux/ipq806x/patches-6.1/950-0412-dt-bindings-hwmon-add-microchip-emc2305.yaml-dt-bind.patch create mode 100644 target/linux/ipq806x/patches-6.1/950-0413-dtbindings-Fixup-microchip-emc2305.yaml-bindings.patch create mode 100644 target/linux/ipq806x/patches-6.1/950-0441-hwmon-emc2305-fixups-for-driver-submitted-to-mailing.patch create mode 100644 target/linux/ipq806x/patches-6.1/950-0687-hwmon-emc2305-Add-calls-to-initialise-of-cooling-map.patch create mode 100644 target/linux/ipq806x/patches-6.1/950-0695-hwmon-emc2305-Change-OF-properties-pwm-min-pwm-max-t.patch diff --git a/target/linux/ipq806x/modules.mk b/target/linux/ipq806x/modules.mk index a2b844d0f03cc3..f875d48a08e339 100644 --- a/target/linux/ipq806x/modules.mk +++ b/target/linux/ipq806x/modules.mk @@ -16,6 +16,21 @@ endef $(eval $(call KernelPackage,phy-qcom-ipq806x-usb)) +define KernelPackage/hwmon-emc2305 + TITLE:=Microchip EMC2301/2/3/5 fan controller + KCONFIG:=CONFIG_SENSORS_EMC2305 + FILES:=$(LINUX_DIR)/drivers/hwmon/emc2305.ko + AUTOLOAD:=$(call AutoProbe,emc2305) + $(call AddDepends/hwmon,+kmod-i2c-core +kmod-thermal +kmod-regmap-i2c) +endef + +define KernelPackage/hwmon-emc2305/description + Kernel module for Microchip EMC2301/EMC2302/EMC2303/EMC2305 fan controllers +endef + +$(eval $(call KernelPackage,hwmon-emc2305)) + + define KernelPackage/sound-soc-ipq8064-storm TITLE:=Qualcomm IPQ8064 SoC support for Google Storm DEPENDS:=@TARGET_ipq806x +kmod-sound-soc-core diff --git a/target/linux/ipq806x/patches-6.1/950-0412-dt-bindings-hwmon-add-microchip-emc2305.yaml-dt-bind.patch b/target/linux/ipq806x/patches-6.1/950-0412-dt-bindings-hwmon-add-microchip-emc2305.yaml-dt-bind.patch new file mode 100644 index 00000000000000..e6cfecfe250c98 --- /dev/null +++ b/target/linux/ipq806x/patches-6.1/950-0412-dt-bindings-hwmon-add-microchip-emc2305.yaml-dt-bind.patch @@ -0,0 +1,75 @@ +From 25478932f5d9e6f763cdf9a0ee2272e33510a76a Mon Sep 17 00:00:00 2001 +From: Michael Shych +Date: Sat, 30 Apr 2022 14:49:04 +0300 +Subject: [PATCH] dt-bindings: hwmon: add microchip,emc2305.yaml dt + binding description. + +Submitted to linux-hwmon mailing list at +https://patchwork.kernel.org/project/linux-hwmon/patch/20220430114905.53448-3-michaelsh@nvidia.com/ + +Add basic description of emc2305 driver device tree binding. + +Signed-off-by: Michael Shych +Reviewed-by: Vadim Pasternak +--- + .../bindings/hwmon/microchip,emc2305.yaml | 54 +++++++++++++++++++ + 1 file changed, 54 insertions(+) + create mode 100644 Documentation/devicetree/bindings/hwmon/microchip,emc2305.yaml + +--- /dev/null ++++ b/Documentation/devicetree/bindings/hwmon/microchip,emc2305.yaml +@@ -0,0 +1,54 @@ ++# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) ++%YAML 1.2 ++--- ++ ++$id: http://devicetree.org/schemas/hwmon/emc2305.yaml# ++$schema: http://devicetree.org/meta-schemas/core.yaml# ++ ++title: Microchip EMC2305 RPM-based PWM Fan Speed Controller ++ ++properties: ++ compatible: ++ enum: ++ - microcip,emc2305 ++ ++ emc2305,pwm-min: ++ description: ++ Min pwm of emc2305 ++ maxItems: 1 ++ emc2305,pwm-max: ++ description: ++ Max pwm of emc2305 ++ maxItems: 1 ++ emc2305,pwm-channel: ++ description: ++ Max number of pwm channels ++ maxItems: 1 ++ emcs205,max-state: ++ description: ++ maxItems: 1 ++ emc2305,cooling-levels: ++ description: ++ Quantity of cooling level state. ++ maxItems: 1 ++ ++required: ++ - compatible ++ ++optional: ++ - emc2305,min-pwm ++ - emc2305,max-pwm ++ - emc2305,pwm-channels ++ - emc2305,cooling-levels ++ ++additionalProperties: false ++ ++examples: ++ - | ++ fan { ++ emc2305,compatible = "microchip,emc2305"; ++ emc2305,pwm-min = <0>; ++ emc2305,pwm-max = <255>; ++ emc2305,pwm-channel = <5> ++ emc2305,cooling-levels = <10>; ++ }; diff --git a/target/linux/ipq806x/patches-6.1/950-0413-dtbindings-Fixup-microchip-emc2305.yaml-bindings.patch b/target/linux/ipq806x/patches-6.1/950-0413-dtbindings-Fixup-microchip-emc2305.yaml-bindings.patch new file mode 100644 index 00000000000000..93a913903ed085 --- /dev/null +++ b/target/linux/ipq806x/patches-6.1/950-0413-dtbindings-Fixup-microchip-emc2305.yaml-bindings.patch @@ -0,0 +1,40 @@ +From 2bc4fabde3e63ffb5484804a5f0d1ee950d77475 Mon Sep 17 00:00:00 2001 +From: Dave Stevenson +Date: Tue, 10 May 2022 14:03:30 +0100 +Subject: [PATCH] dtbindings: Fixup microchip,emc2305.yaml bindings + +The bindings submitted to mainline had some issues, so fix them up. + +Signed-off-by: Dave Stevenson +--- + .../devicetree/bindings/hwmon/microchip,emc2305.yaml | 8 ++++---- + 1 file changed, 4 insertions(+), 4 deletions(-) + +--- a/Documentation/devicetree/bindings/hwmon/microchip,emc2305.yaml ++++ b/Documentation/devicetree/bindings/hwmon/microchip,emc2305.yaml +@@ -5,13 +5,13 @@ + $id: http://devicetree.org/schemas/hwmon/emc2305.yaml# + $schema: http://devicetree.org/meta-schemas/core.yaml# + +-title: Microchip EMC2305 RPM-based PWM Fan Speed Controller ++title: Microchip EMC230[1|2|3|5] RPM-based PWM Fan Speed Controller + + properties: + compatible: + enum: +- - microcip,emc2305 +- ++ - microchip,emc2305 ++ - microchip,emc2301 + emc2305,pwm-min: + description: + Min pwm of emc2305 +@@ -46,7 +46,7 @@ additionalProperties: false + examples: + - | + fan { +- emc2305,compatible = "microchip,emc2305"; ++ compatible = "microchip,emc2305"; + emc2305,pwm-min = <0>; + emc2305,pwm-max = <255>; + emc2305,pwm-channel = <5> diff --git a/target/linux/ipq806x/patches-6.1/950-0441-hwmon-emc2305-fixups-for-driver-submitted-to-mailing.patch b/target/linux/ipq806x/patches-6.1/950-0441-hwmon-emc2305-fixups-for-driver-submitted-to-mailing.patch new file mode 100644 index 00000000000000..abb1eacef2403e --- /dev/null +++ b/target/linux/ipq806x/patches-6.1/950-0441-hwmon-emc2305-fixups-for-driver-submitted-to-mailing.patch @@ -0,0 +1,163 @@ +From c53aee9d78372213c34f5ebfb084b58be754a23c Mon Sep 17 00:00:00 2001 +From: Phil Elwell +Date: Thu, 5 May 2022 15:46:07 +0100 +Subject: [PATCH] hwmon: emc2305: fixups for driver submitted to + mailing lists + +The driver had a number of issues, checkpatch warnings/errors, +and other limitations, so fix these up to make it usable. + +Signed-off-by: Phil Elwell +Signed-off-by: Dave Stevenson +--- + drivers/hwmon/emc2305.c | 73 +++++++++++++++++++++++++++++++++++++++-- + 1 file changed, 71 insertions(+), 2 deletions(-) + +--- a/drivers/hwmon/emc2305.c ++++ b/drivers/hwmon/emc2305.c +@@ -15,12 +15,13 @@ + static const unsigned short + emc2305_normal_i2c[] = { 0x27, 0x2c, 0x2d, 0x2e, 0x2f, 0x4c, 0x4d, I2C_CLIENT_END }; + ++#define EMC2305_REG_FAN_STATUS 0x24 ++#define EMC2305_REG_FAN_STALL_STATUS 0x25 + #define EMC2305_REG_DRIVE_FAIL_STATUS 0x27 + #define EMC2305_REG_VENDOR 0xfe + #define EMC2305_FAN_MAX 0xff + #define EMC2305_FAN_MIN 0x00 + #define EMC2305_FAN_MAX_STATE 10 +-#define EMC2305_DEVICE 0x34 + #define EMC2305_VENDOR 0x5d + #define EMC2305_REG_PRODUCT_ID 0xfd + #define EMC2305_TACH_REGS_UNUSE_BITS 3 +@@ -39,6 +40,7 @@ emc2305_normal_i2c[] = { 0x27, 0x2c, 0x2 + #define EMC2305_RPM_FACTOR 3932160 + + #define EMC2305_REG_FAN_DRIVE(n) (0x30 + 0x10 * (n)) ++#define EMC2305_REG_FAN_CFG(n) (0x32 + 0x10 * (n)) + #define EMC2305_REG_FAN_MIN_DRIVE(n) (0x38 + 0x10 * (n)) + #define EMC2305_REG_FAN_TACH(n) (0x3e + 0x10 * (n)) + +@@ -58,6 +60,15 @@ static const struct i2c_device_id emc230 + }; + MODULE_DEVICE_TABLE(i2c, emc2305_ids); + ++static const struct of_device_id emc2305_dt_ids[] = { ++ { .compatible = "microchip,emc2305" }, ++ { .compatible = "microchip,emc2303" }, ++ { .compatible = "microchip,emc2302" }, ++ { .compatible = "microchip,emc2301" }, ++ { } ++}; ++MODULE_DEVICE_TABLE(of, emc2305_dt_ids); ++ + /** + * @cdev: cooling device; + * @curr_state: cooling current state; +@@ -101,6 +112,7 @@ struct emc2305_data { + u8 pwm_num; + bool pwm_separate; + u8 pwm_min[EMC2305_PWM_MAX]; ++ u8 pwm_max; + struct emc2305_cdev_data cdev_data[EMC2305_PWM_MAX]; + }; + +@@ -273,7 +285,7 @@ static int emc2305_set_pwm(struct device + struct i2c_client *client = data->client; + int ret; + +- if (val < data->pwm_min[channel] || val > EMC2305_FAN_MAX) ++ if (val < data->pwm_min[channel] || val > data->pwm_max) + return -EINVAL; + + ret = i2c_smbus_write_byte_data(client, EMC2305_REG_FAN_DRIVE(channel), val); +@@ -284,6 +296,49 @@ static int emc2305_set_pwm(struct device + return 0; + } + ++static int emc2305_get_tz_of(struct device *dev) ++{ ++ struct device_node *np = dev->of_node; ++ struct emc2305_data *data = dev_get_drvdata(dev); ++ int ret = 0; ++ u32 val; ++ int i; ++ ++ /* OF parameters are optional - overwrite default setting ++ * if some of them are provided. ++ */ ++ ++ ret = of_property_read_u32(np, "emc2305,cooling-levels", &val); ++ if (!ret) ++ data->max_state = (u8)val; ++ else if (ret != -EINVAL) ++ return ret; ++ ++ ret = of_property_read_u32(np, "emc2305,pwm-max", &val); ++ if (!ret) ++ data->pwm_max = (u8)val; ++ else if (ret != -EINVAL) ++ return ret; ++ ++ ret = of_property_read_u32(np, "emc2305,pwm-min", &val); ++ if (!ret) ++ for (i = 0; i < EMC2305_PWM_MAX; i++) ++ data->pwm_min[i] = (u8)val; ++ else if (ret != -EINVAL) ++ return ret; ++ ++ /* Not defined or 0 means one thermal zone over all cooling devices. ++ * Otherwise - separated thermal zones for each PWM channel. ++ */ ++ ret = of_property_read_u32(np, "emc2305,pwm-channel", &val); ++ if (!ret) ++ data->pwm_separate = (val != 0); ++ else if (ret != -EINVAL) ++ return ret; ++ ++ return 0; ++} ++ + static int emc2305_set_single_tz(struct device *dev, int idx) + { + struct emc2305_data *data = dev_get_drvdata(dev); +@@ -572,11 +627,18 @@ static int emc2305_probe(struct i2c_clie + data->pwm_separate = pdata->pwm_separate; + for (i = 0; i < EMC2305_PWM_MAX; i++) + data->pwm_min[i] = pdata->pwm_min[i]; ++ data->pwm_max = EMC2305_FAN_MAX; + } else { + data->max_state = EMC2305_FAN_MAX_STATE; + data->pwm_separate = false; + for (i = 0; i < EMC2305_PWM_MAX; i++) + data->pwm_min[i] = EMC2305_FAN_MIN; ++ data->pwm_max = EMC2305_FAN_MAX; ++ if (dev->of_node) { ++ ret = emc2305_get_tz_of(dev); ++ if (ret < 0) ++ return ret; ++ } + } + + data->hwmon_dev = devm_hwmon_device_register_with_info(dev, "emc2305", data, +@@ -597,6 +659,12 @@ static int emc2305_probe(struct i2c_clie + return ret; + } + ++ /* Acknowledge any existing faults. Stops the device responding on the ++ * SMBus alert address. ++ */ ++ i2c_smbus_read_byte_data(client, EMC2305_REG_FAN_STALL_STATUS); ++ i2c_smbus_read_byte_data(client, EMC2305_REG_FAN_STATUS); ++ + return 0; + } + +@@ -612,6 +680,7 @@ static struct i2c_driver emc2305_driver + .class = I2C_CLASS_HWMON, + .driver = { + .name = "emc2305", ++ .of_match_table = emc2305_dt_ids, + }, + .probe = emc2305_probe, + .remove = emc2305_remove, diff --git a/target/linux/ipq806x/patches-6.1/950-0687-hwmon-emc2305-Add-calls-to-initialise-of-cooling-map.patch b/target/linux/ipq806x/patches-6.1/950-0687-hwmon-emc2305-Add-calls-to-initialise-of-cooling-map.patch new file mode 100644 index 00000000000000..c08e0411784bde --- /dev/null +++ b/target/linux/ipq806x/patches-6.1/950-0687-hwmon-emc2305-Add-calls-to-initialise-of-cooling-map.patch @@ -0,0 +1,54 @@ +From 76f8210c9498983b492645ec2c90c5c547ae415b Mon Sep 17 00:00:00 2001 +From: Dave Stevenson +Date: Fri, 21 Apr 2023 14:49:38 +0100 +Subject: [PATCH] hwmon: emc2305: Add calls to initialise of cooling + maps + +Commit 46ef9d4ed26b ("hwmon: emc2305: fixups for driver submitted to +mailing lists") missed adding the call to thermal_of_cooling_device_register +required to configure any cooling maps for the device, hence stopping it +from actually ever changing speed. + +Signed-off-by: Dave Stevenson +--- + drivers/hwmon/emc2305.c | 22 ++++++++++++++++------ + 1 file changed, 16 insertions(+), 6 deletions(-) + +--- a/drivers/hwmon/emc2305.c ++++ b/drivers/hwmon/emc2305.c +@@ -348,9 +348,17 @@ static int emc2305_set_single_tz(struct + cdev_idx = (idx) ? idx - 1 : 0; + pwm = data->pwm_min[cdev_idx]; + +- data->cdev_data[cdev_idx].cdev = +- thermal_cooling_device_register(emc2305_fan_name[idx], data, +- &emc2305_cooling_ops); ++ if (dev->of_node) ++ data->cdev_data[cdev_idx].cdev = ++ devm_thermal_of_cooling_device_register(dev, dev->of_node, ++ emc2305_fan_name[idx], ++ data, ++ &emc2305_cooling_ops); ++ else ++ data->cdev_data[cdev_idx].cdev = ++ thermal_cooling_device_register(emc2305_fan_name[idx], ++ data, ++ &emc2305_cooling_ops); + + if (IS_ERR(data->cdev_data[cdev_idx].cdev)) { + dev_err(dev, "Failed to register cooling device %s\n", emc2305_fan_name[idx]); +@@ -403,9 +411,11 @@ static void emc2305_unset_tz(struct devi + int i; + + /* Unregister cooling device. */ +- for (i = 0; i < EMC2305_PWM_MAX; i++) +- if (data->cdev_data[i].cdev) +- thermal_cooling_device_unregister(data->cdev_data[i].cdev); ++ if (!dev->of_node) { ++ for (i = 0; i < EMC2305_PWM_MAX; i++) ++ if (data->cdev_data[i].cdev) ++ thermal_cooling_device_unregister(data->cdev_data[i].cdev); ++ } + } + + static umode_t diff --git a/target/linux/ipq806x/patches-6.1/950-0695-hwmon-emc2305-Change-OF-properties-pwm-min-pwm-max-t.patch b/target/linux/ipq806x/patches-6.1/950-0695-hwmon-emc2305-Change-OF-properties-pwm-min-pwm-max-t.patch new file mode 100644 index 00000000000000..6be34bf9b78725 --- /dev/null +++ b/target/linux/ipq806x/patches-6.1/950-0695-hwmon-emc2305-Change-OF-properties-pwm-min-pwm-max-t.patch @@ -0,0 +1,69 @@ +From ab304fd0099444dc7535c81abbbc0077cd878d7e Mon Sep 17 00:00:00 2001 +From: Dave Stevenson +Date: Fri, 21 Apr 2023 15:48:39 +0100 +Subject: [PATCH] hwmon: emc2305: Change OF properties pwm-min & + pwm-max to u8 + +There is no DT binding for emc2305 as mainline are still +discussing how to do a generic fan binding. +The 5.15 driver was reading the "emc2305," properties +"cooling-levels", "pwm-max", "pwm-min", and "pwm-channel" as u8. +The overlay was writing them as u16 (;) so it was working. + +The 6.1 driver was reading as u32, which failed as there is +insufficient data. + +As this is all downstream only, revert to u8 to match 5.15. + +Signed-off-by: Dave Stevenson +--- + drivers/hwmon/emc2305.c | 16 ++++++++-------- + 1 file changed, 8 insertions(+), 8 deletions(-) + +--- a/drivers/hwmon/emc2305.c ++++ b/drivers/hwmon/emc2305.c +@@ -301,36 +301,36 @@ static int emc2305_get_tz_of(struct devi + struct device_node *np = dev->of_node; + struct emc2305_data *data = dev_get_drvdata(dev); + int ret = 0; +- u32 val; ++ u8 val; + int i; + + /* OF parameters are optional - overwrite default setting + * if some of them are provided. + */ + +- ret = of_property_read_u32(np, "emc2305,cooling-levels", &val); ++ ret = of_property_read_u8(np, "emc2305,cooling-levels", &val); + if (!ret) +- data->max_state = (u8)val; ++ data->max_state = val; + else if (ret != -EINVAL) + return ret; + +- ret = of_property_read_u32(np, "emc2305,pwm-max", &val); ++ ret = of_property_read_u8(np, "emc2305,pwm-max", &val); + if (!ret) +- data->pwm_max = (u8)val; ++ data->pwm_max = val; + else if (ret != -EINVAL) + return ret; + +- ret = of_property_read_u32(np, "emc2305,pwm-min", &val); ++ ret = of_property_read_u8(np, "emc2305,pwm-min", &val); + if (!ret) + for (i = 0; i < EMC2305_PWM_MAX; i++) +- data->pwm_min[i] = (u8)val; ++ data->pwm_min[i] = val; + else if (ret != -EINVAL) + return ret; + + /* Not defined or 0 means one thermal zone over all cooling devices. + * Otherwise - separated thermal zones for each PWM channel. + */ +- ret = of_property_read_u32(np, "emc2305,pwm-channel", &val); ++ ret = of_property_read_u8(np, "emc2305,pwm-channel", &val); + if (!ret) + data->pwm_separate = (val != 0); + else if (ret != -EINVAL)