Add VIM4 MCU/FAN support
Subsystems (6)
v5 cover Add VIM4 MCU/FAN support
The Khadas VIM4 board features a different MCU variant compared to previous VIM boards.
While it shares the same I2C-based communication model, it differs in some ways:
- A distinct register map with its own volatile/writeable register set
- A fan control with 0–100 levels instead of the 0–3 levels previously
- A fan power supply gated through a regulator
This series adds support for this new variant by:
1. Refactoring the khadas-mcu MFD driver to use per-variant data structures (regmap config, cells, fan platform data), and adding the khadas,vim4-mcu compatible string.
2. Extending the fan thermal driver to retrieve the fan register and maximum level from platform_data,
and to optionally manage a power regulator for the fan supply.
3. Adding the corresponding DTS node for the VIM4, wiring the MCU to the I2C AO_A bus and exposing it as a thermal cooling device.
---
Changes in v5:
- PATCH 5: Replace devm_regulator_get_optional() with devm_regulator_get()
to simplify error handling and remove NULL checks, also
ordering as reverse christmas according to Neil's feedback.
- Link to v4: https://lore.kernel.org/r/[email protected]
Changes in v4:
- PATCH 1: limit fan-supply property by compatible according to Conor's feedback.
- Link to v3: https://lore.kernel.org/r/[email protected]
Changes in v3:
- PATCH 1: adding comment on vim4 compatible saying it is not discoverable,
thanks to Rob's and Neil's feedback.
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- PATCH 5: Add regulator_disable on suspend thanks to Neil's feedback.
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Ronald Claveau (8):
dt-bindings: mfd: khadas: Add new compatible for Khadas VIM4 MCU
dt-bindings: i2c: amlogic: Add compatible for T7 SOC
mfd: khadas-mcu: Add per-variant configuration infrastructure and VIM4 support
mfd: khadas-mcu: Add support for VIM4 MCU variant
thermal: khadas-mcu-fan: Add fan config from platform data Add regulator support
arm64: dts: amlogic: t7: Add i2c pinctrl node
arm64: dts: amlogic: t7: Add i2c controller node
arm64: dts: amlogic: t7: khadas-vim4: Add i2c MCU fan node
.../bindings/i2c/amlogic,meson6-i2c.yaml | 13 ++- .../devicetree/bindings/mfd/khadas,mcu.yaml | 18 ++++ .../dts/amlogic/amlogic-t7-a311d2-khadas-vim4.dts | 13 +++ arch/arm64/boot/dts/amlogic/amlogic-t7.dtsi | 20 ++++ drivers/mfd/khadas-mcu.c | 106 ++++++++++++++++++--- drivers/thermal/khadas_mcu_fan.c | 37 +++++-- include/linux/mfd/khadas-mcu.h | 39 +++++++- 7 files changed, 222 insertions(+), 24 deletions(-)
---
base-commit: f7b64ed948718290209074a50bb0df17e5944873
change-id: 20260402-add-mcu-fan-khadas-vim4-ac1cbe553c9b
prerequisite-message-id: <[email protected]>
prerequisite-patch-id: f03a086b4137158412b2d47b3de793b858de8dde
prerequisite-patch-id: 123970c9b29c2090440f2fd71c85d3c6fd8e36de
prerequisite-patch-id: 3e2e56b0926ba327b520f935df4ced5089bbe503
prerequisite-patch-id: 65a5d76ffdbc9b3aab3385bb65cb027004c30e7e
prerequisite-patch-id: 237269801826dd3ad7fb16eb4d7d6d4eab504278
prerequisite-patch-id: 57e9b08a968aedf543d3d0d56cf1ca4db20b2a16
prerequisite-change-id: 20260326-add-bcm43752-compatible-e264a4f7973a:v2
prerequisite-patch-id: cd98b74fa56af72af2553f391c400981d83cd4f4
prerequisite-patch-id: b730f5e42be1d89d193e63a0265495cdbf2c7d7b
prerequisite-change-id: 20260330-fix-invalid-property-bbe54d933f71:v2
prerequisite-patch-id: 8d675e7a239985c762843515b241f0a2f45f9c92
prerequisite-change-id: 20260331-fix-aml-t7-null-reset-2b608ebf9da4:v1
prerequisite-patch-id: 5b5de77af11747ce964404fb827d2ee2bff47ea5
prerequisite-patch-id: 1e37fc75fed1e533adee0f3e7e6ead1f8ff3c55c
prerequisite-patch-id: 65a5d76ffdbc9b3aab3385bb65cb027004c30e7e
prerequisite-patch-id: 2daf583fb5e7449a02bd217d8aca330171b598aa
prerequisite-patch-id: 237269801826dd3ad7fb16eb4d7d6d4eab504278
prerequisite-patch-id: d1ddf9b7710e91f8062de83bd7ba55afb2c4c112
prerequisite-patch-id: 57e9b08a968aedf543d3d0d56cf1ca4db20b2a16
prerequisite-patch-id: cd98b74fa56af72af2553f391c400981d83cd4f4
prerequisite-patch-id: b730f5e42be1d89d193e63a0265495cdbf2c7d7b
prerequisite-patch-id: 9debd88fa60febed9cd7208f86603b4c2d270520
prerequisite-patch-id: 314ef9ff0c4d1d15dab1dea9d92aa065f1eac3e9
Best regards,
Signature · 1 line
Ronald Claveau <[email protected]>
PATCH v5 1/8 dt-bindings: mfd: khadas: Add new compatible for Khadas VIM4 MCU
The Khadas VIM4 MCU register is slightly different from previous boards' MCU.
This board also features a switchable power source for its fan.
--- Documentation/devicetree/bindings/mfd/khadas,mcu.yaml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
Documentation/devicetree/bindings/mfd/khadas,mcu.yaml +18 -0
@@ -18,6 +18,7 @@ properties: compatible: enum: - khadas,mcu # MCU revision is discoverable + - khadas,vim4-mcu # Different MCU variant, not discoverable "#cooling-cells": # Only needed for boards having FAN control feature const: 2
@@ -25,10 +26,27 @@ properties: reg: maxItems: 1 + fan-supply: + description: Phandle to the regulator that powers the fan. + $ref: /schemas/types.yaml#/definitions/phandle + required: - compatible - reg +allOf: + - if: + properties: + compatible: + contains: + const: khadas,vim4-mcu + then: + required: + - fan-supply + else: + properties: + fan-supply: false + additionalProperties: false examples:
Signature · 1 line
2.49.0
PATCH v5 2/8 dt-bindings: i2c: amlogic: Add compatible for T7 SOC
In reply to Ronald ClaveauAdd the T7 SOC compatible which fallback to AXG compatible.
--- .../devicetree/bindings/i2c/amlogic,meson6-i2c.yaml | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
Documentation/devicetree/bindings/i2c/amlogic,meson6-i2c.yaml +9 -4
@@ -16,10 +16,15 @@ allOf: properties: compatible: - enum: - - amlogic,meson6-i2c # Meson6, Meson8 and compatible SoCs - - amlogic,meson-gxbb-i2c # GXBB and compatible SoCs - - amlogic,meson-axg-i2c # AXG and compatible SoCs + oneOf: + - items: + - enum: + - amlogic,t7-i2c + - const: amlogic,meson-axg-i2c + - enum: + - amlogic,meson6-i2c # Meson6, Meson8 and compatible SoCs + - amlogic,meson-gxbb-i2c # GXBB and compatible SoCs + - amlogic,meson-axg-i2c # AXG and compatible SoCs reg: maxItems: 1
Signature · 1 line
2.49.0
Wolfram Sang
AppliedRe: [PATCH v5 2/8] dt-bindings: i2c: amlogic: Add compatible for T7 SOC
Quoted 6 lines · On Fri, Apr 24, 2026 at 04:17:33PM +0200, Ronald Claveau via B4 Relay wrote:
From: Ronald Claveau <[email protected]>
Add the T7 SOC compatible which fallback to AXG compatible.
Signed-off-by Ronald Claveau <[email protected]>
Applied to for-current, thanks!
PATCH v5 3/8 mfd: khadas-mcu: Add per-variant configuration infrastructure and VIM4 support
In reply to Ronald ClaveauIntroduce a per-variant configuration structure (khadas_mcu_data) holding the regmap config and MFD cells,
selected at probe time via the of_device_id match data. This makes adding other variants straightforward.
Also introduce khadas_mcu_fan_pdata to pass fan register address and maximum level to the fan sub-driver, removing the hardcoded constants.
--- include/linux/mfd/khadas-mcu.h | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-)
include/linux/mfd/khadas-mcu.h +37 -2
@@ -70,6 +70,13 @@#define KHADAS_MCU_WOL_INIT_START_REG 0x87/* WO */ #define KHADAS_MCU_CMD_FAN_STATUS_CTRL_REG 0x88/* WO */ +/* VIM4 specific registers */ +#define KHADAS_MCU_VIM4_REST_CONF_REG 0x2c/* WO - reset EEPROM */ +#define KHADAS_MCU_VIM4_LED_ON_RAM_REG 0x89/* WO - LED volatile */ +#define KHADAS_MCU_VIM4_FAN_CTRL_REG 0x8a/* WO */ +#define KHADAS_MCU_VIM4_WDT_EN_REG 0x8b/* WO */ +#define KHADAS_MCU_VIM4_SYS_RST_REG 0x91/* WO */ +enum {KHADAS_BOARD_VIM1 =0x1 ,KHADAS_BOARD_VIM2 ,
@@ -82,10 +89,38 @@ enum {* struct khadas_mcu - Khadas MCU structure * @device: device reference used for logs * @regmap: register map +* @data: pointer to variant-specific config */ struct khadas_mcu { -struct device *dev; -struct regmap *regmap; +struct device *dev; +struct regmap *regmap; +const struct khadas_mcu_data *data; +}; + +/** +* struct khadas_mcu_data - per-variant configuration +* @regmap_config: regmap configuration +* @cells: MFD sub-devices +* @ncells: number of sub-devices +* @fan_cells: MFD fan sub-devices +* @nfan_cells: number of fan sub-devices +*/ +struct khadas_mcu_data { +const struct regmap_config *regmap_config; +const struct mfd_cell *cells; +int ncells; +const struct mfd_cell *fan_cells; +int nfan_cells; +}; + +/** +* struct khadas_mcu_fan_pdata - fan sub-driver configuration +* @fan_reg: register address to write the fan level +* @max_level: maximum fan level +*/ +struct khadas_mcu_fan_pdata { +unsigned int fan_reg; +unsigned int max_level; };#endif /* MFD_KHADAS_MCU_H */
Signature · 1 line
2.49.0
PATCH v5 4/8 mfd: khadas-mcu: Add support for VIM4 MCU variant
In reply to Ronald ClaveauRefactor probe() to use per-variant khadas_mcu_data instead of hardcoded globals.
Add dedicated regmap configuration and device data for the VIM4 MCU, with its own volatile/writeable registers.
Add the fan control register
(0–100 levels vs 0–3 for previous supported boards).
Add a new compatible string "khadas,vim4-mcu".
--- drivers/mfd/khadas-mcu.c | 106 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 95 insertions(+), 11 deletions(-)
drivers/mfd/khadas-mcu.c +95 -11
@@ -75,15 +75,91 @@ static const struct regmap_config khadas_mcu_regmap_config = { .cache_type = REGCACHE_MAPLE, }; +static const struct khadas_mcu_fan_pdata khadas_mcu_fan_pdata = { + .fan_reg =KHADAS_MCU_CMD_FAN_STATUS_CTRL_REG , + .max_level =3 , +}; +static struct mfd_cell khadas_mcu_fan_cells[] = {/* VIM1/2 Rev13+ and VIM3 only */ - { .name ="khadas-mcu-fan-ctrl" , }, + { + .name ="khadas-mcu-fan-ctrl" , + .platform_data = &khadas_mcu_fan_pdata, + .pdata_size =sizeof (khadas_mcu_fan_pdata), + }, };static struct mfd_cell khadas_mcu_cells[] = { { .name ="khadas-mcu-user-mem" , }, }; +static const struct khadas_mcu_data khadas_mcu_data = { + .regmap_config = &khadas_mcu_regmap_config, + .cells = khadas_mcu_cells, + .ncells =ARRAY_SIZE (khadas_mcu_cells), + .fan_cells = khadas_mcu_fan_cells, + .nfan_cells =ARRAY_SIZE (khadas_mcu_fan_cells), +}; + +static bool khadas_mcu_vim4_reg_volatile (struct device *dev,unsigned int reg) +{ +switch (reg) { +case KHADAS_MCU_PWR_OFF_CMD_REG : +case KHADAS_MCU_VIM4_REST_CONF_REG : +case KHADAS_MCU_WOL_INIT_START_REG : +case KHADAS_MCU_VIM4_LED_ON_RAM_REG : +case KHADAS_MCU_VIM4_FAN_CTRL_REG : +case KHADAS_MCU_VIM4_WDT_EN_REG : +case KHADAS_MCU_VIM4_SYS_RST_REG : +return true; +default : +return false; + } +} + +static bool khadas_mcu_vim4_reg_writeable (struct device *dev,unsigned int reg) +{ +switch (reg) { +case KHADAS_MCU_VERSION_0_REG : +case KHADAS_MCU_VERSION_1_REG : +case KHADAS_MCU_SHUTDOWN_NORMAL_STATUS_REG : +return false; +default : +return true; + } +} + +static const struct regmap_config khadas_mcu_vim4_regmap_config = { + .reg_bits =8 , + .reg_stride =1 , + .val_bits =8 , + .max_register =KHADAS_MCU_VIM4_SYS_RST_REG , + .volatile_reg = khadas_mcu_vim4_reg_volatile, + .writeable_reg = khadas_mcu_vim4_reg_writeable, + .cache_type =REGCACHE_MAPLE , +}; + +static const struct khadas_mcu_fan_pdata khadas_vim4_fan_pdata = { + .fan_reg =KHADAS_MCU_VIM4_FAN_CTRL_REG , + .max_level =0x64 , +}; + +static const struct mfd_cell khadas_mcu_vim4_cells[] = { + { + .name ="khadas-mcu-fan-ctrl" , + .platform_data = &khadas_vim4_fan_pdata, + .pdata_size =sizeof (khadas_vim4_fan_pdata), + }, +}; + +static const struct khadas_mcu_data khadas_vim4_mcu_data = { + .regmap_config = &khadas_mcu_vim4_regmap_config, + .cells =NULL , + .ncells =0 , + .fan_cells = khadas_mcu_vim4_cells, + .nfan_cells =ARRAY_SIZE (khadas_mcu_vim4_cells), +}; +static int khadas_mcu_probe (struct i2c_client *client) {struct device *dev = &client->dev;
@@ -94,28 +170,35 @@ static int khadas_mcu_probe(struct i2c_client *client)if (!ddata)return -ENOMEM ; + ddata->data =i2c_get_match_data (client); +if (!ddata->data) +return -EINVAL ; +i2c_set_clientdata (client, ddata); ddata->dev = dev; - ddata->regmap =devm_regmap_init_i2c (client, &khadas_mcu_regmap_config); + ddata->regmap =devm_regmap_init_i2c (client, + ddata->data->regmap_config);if (IS_ERR (ddata->regmap)) { ret =PTR_ERR (ddata->regmap);dev_err (dev,"Failed to allocate register map: %d\n" , ret);return ret; } - ret =devm_mfd_add_devices (dev,PLATFORM_DEVID_NONE , - khadas_mcu_cells, -ARRAY_SIZE (khadas_mcu_cells), -NULL ,0 ,NULL ); -if (ret) -return ret; +if (ddata->data->cells && ddata->data->ncells) { + ret =devm_mfd_add_devices (dev,PLATFORM_DEVID_NONE , + ddata->data->cells, + ddata->data->ncells, +NULL ,0 ,NULL ); +if (ret) +return ret; + }if (of_property_present (dev->of_node,"#cooling-cells" ))return devm_mfd_add_devices (dev,PLATFORM_DEVID_NONE , - khadas_mcu_fan_cells, -ARRAY_SIZE (khadas_mcu_fan_cells), + ddata->data->fan_cells, + ddata->data->nfan_cells,NULL ,0 ,NULL );return 0 ;
@@ -123,7 +206,8 @@ static int khadas_mcu_probe(struct i2c_client *client)#ifdef CONFIG_OF static const struct of_device_id khadas_mcu_of_match[] = { - { .compatible ="khadas,mcu" , }, + { .compatible ="khadas,mcu" , .data = &khadas_mcu_data }, + { .compatible ="khadas,vim4-mcu" , .data = &khadas_vim4_mcu_data }, {}, };MODULE_DEVICE_TABLE (of, khadas_mcu_of_match);
Signature · 1 line
2.49.0
Lee Jones
maintainerRe: [PATCH v5 4/8] mfd: khadas-mcu: Add support for VIM4 MCU variant
Quoted 24 lines · On Fri, 24 Apr 2026, Ronald Claveau via B4 Relay wrote:
From: Ronald Claveau <[email protected]>
Refactor
probe()to use per-variantkhadas_mcu_datainstead of hardcoded globals.Add dedicated regmap configuration and device data for the VIM4 MCU, with its own volatile/writeable registers.
Add the fan control register
(0–100 levels vs 0–3 for previous supported boards).Add a new compatible string "khadas,vim4-mcu".
Reviewed-by Neil Armstrong <[email protected]>Signed-off-by Ronald Claveau <[email protected]>--- drivers/mfd/khadas-mcu.c | 106 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 95 insertions(+), 11 deletions(-)drivers/mfd/khadas-mcu.c +0
-0
drivers/mfd/khadas-mcu.c static const struct regmap_config khadas_mcu_regmap_config = { · line 81
Quoted 7 lines
drivers/mfd/khadas-mcu.c +4
-0@@ -75,15 +75,91 @@ static const struct regmap_config khadas_mcu_regmap_config = { .cache_type = REGCACHE_MAPLE, }; +static const struct khadas_mcu_fan_pdata khadas_mcu_fan_pdata = { + .fan_reg =KHADAS_MCU_CMD_FAN_STATUS_CTRL_REG , + .max_level =3 , +};
What is 3?
drivers/mfd/khadas-mcu.c static const struct regmap_config khadas_mcu_regmap_config = { · line 90
Quoted 10 lines
drivers/mfd/khadas-mcu.c +6
-1+static struct mfd_cell khadas_mcu_fan_cells[] = {/* VIM1/2 Rev13+ and VIM3 only */ - { .name ="khadas-mcu-fan-ctrl" , }, + { + .name ="khadas-mcu-fan-ctrl" , + .platform_data = &khadas_mcu_fan_pdata, + .pdata_size =sizeof (khadas_mcu_fan_pdata), + }, };
Worth making this const at one point.
drivers/mfd/khadas-mcu.c static const struct regmap_config khadas_mcu_regmap_config = { · line 102
Quoted 12 lines
drivers/mfd/khadas-mcu.c +7
-0static struct mfd_cell khadas_mcu_cells[] = { { .name ="khadas-mcu-user-mem" , }, }; +static const struct khadas_mcu_data khadas_mcu_data = { + .regmap_config = &khadas_mcu_regmap_config, + .cells = khadas_mcu_cells, + .ncells =ARRAY_SIZE (khadas_mcu_cells), + .fan_cells = khadas_mcu_fan_cells, + .nfan_cells =ARRAY_SIZE (khadas_mcu_fan_cells), +};
This is a red flag!
Quoted 63 lines
drivers/mfd/khadas-mcu.c +59
-0+static bool khadas_mcu_vim4_reg_volatile (struct device *dev,unsigned int reg) +{ +switch (reg) { +case KHADAS_MCU_PWR_OFF_CMD_REG : +case KHADAS_MCU_VIM4_REST_CONF_REG : +case KHADAS_MCU_WOL_INIT_START_REG : +case KHADAS_MCU_VIM4_LED_ON_RAM_REG : +case KHADAS_MCU_VIM4_FAN_CTRL_REG : +case KHADAS_MCU_VIM4_WDT_EN_REG : +case KHADAS_MCU_VIM4_SYS_RST_REG : +return true; +default : +return false; + } +} + +static bool khadas_mcu_vim4_reg_writeable (struct device *dev,unsigned int reg) +{ +switch (reg) { +case KHADAS_MCU_VERSION_0_REG : +case KHADAS_MCU_VERSION_1_REG : +case KHADAS_MCU_SHUTDOWN_NORMAL_STATUS_REG : +return false; +default : +return true; + } +} + +static const struct regmap_config khadas_mcu_vim4_regmap_config = { + .reg_bits =8 , + .reg_stride =1 , + .val_bits =8 , + .max_register =KHADAS_MCU_VIM4_SYS_RST_REG , + .volatile_reg = khadas_mcu_vim4_reg_volatile, + .writeable_reg = khadas_mcu_vim4_reg_writeable, + .cache_type =REGCACHE_MAPLE , +}; + +static const struct khadas_mcu_fan_pdata khadas_vim4_fan_pdata = { + .fan_reg =KHADAS_MCU_VIM4_FAN_CTRL_REG , + .max_level =0x64 , +}; + +static const struct mfd_cell khadas_mcu_vim4_cells[] = { + { + .name ="khadas-mcu-fan-ctrl" , + .platform_data = &khadas_vim4_fan_pdata, + .pdata_size =sizeof (khadas_vim4_fan_pdata), + }, +}; + +static const struct khadas_mcu_data khadas_vim4_mcu_data = { + .regmap_config = &khadas_mcu_vim4_regmap_config, + .cells =NULL , + .ncells =0 , + .fan_cells = khadas_mcu_vim4_cells, + .nfan_cells =ARRAY_SIZE (khadas_mcu_vim4_cells), +}; +static int khadas_mcu_probe (struct i2c_client *client) {struct device *dev = &client->dev;
drivers/mfd/khadas-mcu.c static int khadas_mcu_probe(struct i2c_client *client) · line 175
Quoted 6 lines
drivers/mfd/khadas-mcu.c +3
-0@@ -94,28 +170,35 @@ static int khadas_mcu_probe(struct i2c_client *client)if (!ddata)return -ENOMEM ; + ddata->data =i2c_get_match_data (client); +if (!ddata->data) +return -EINVAL ;
Shouldn't this be -ENODEV?
drivers/mfd/khadas-mcu.c static int khadas_mcu_probe(struct i2c_client *client) · line 182
Quoted 7 lines
drivers/mfd/khadas-mcu.c +2
-1i2c_set_clientdata (client, ddata); ddata->dev = dev; - ddata->regmap =devm_regmap_init_i2c (client, &khadas_mcu_regmap_config); + ddata->regmap =devm_regmap_init_i2c (client, + ddata->data->regmap_config);
Use up to 100-chars to prevent this kind of wrapping.
drivers/mfd/khadas-mcu.c static int khadas_mcu_probe(struct i2c_client *client) · line 187
Quoted 5 lines
drivers/mfd/khadas-mcu.c +0
-0if (IS_ERR (ddata->regmap)) { ret =PTR_ERR (ddata->regmap);dev_err (dev,"Failed to allocate register map: %d\n" , ret);return ret; }
Maybe convert this to dev_err_probe() at one point.
Quoted 25 lines
drivers/mfd/khadas-mcu.c +10
-8- ret =devm_mfd_add_devices (dev,PLATFORM_DEVID_NONE , - khadas_mcu_cells, -ARRAY_SIZE (khadas_mcu_cells), -NULL ,0 ,NULL ); -if (ret) -return ret; +if (ddata->data->cells && ddata->data->ncells) { + ret =devm_mfd_add_devices (dev,PLATFORM_DEVID_NONE , + ddata->data->cells, + ddata->data->ncells, +NULL ,0 ,NULL ); +if (ret) +return ret; + }if (of_property_present (dev->of_node,"#cooling-cells" ))return devm_mfd_add_devices (dev,PLATFORM_DEVID_NONE , - khadas_mcu_fan_cells, -ARRAY_SIZE (khadas_mcu_fan_cells), + ddata->data->fan_cells, + ddata->data->nfan_cells,NULL ,0 ,NULL );return 0 ;
drivers/mfd/khadas-mcu.c static int khadas_mcu_probe(struct i2c_client *client) · line 210
Quoted 6 lines
drivers/mfd/khadas-mcu.c +2
-1@@ -123,7 +206,8 @@ static int khadas_mcu_probe(struct i2c_client *client)#ifdef CONFIG_OF static const struct of_device_id khadas_mcu_of_match[] = { - { .compatible = "khadas,mcu", }, + { .compatible ="khadas,mcu" , .data = &khadas_mcu_data }, + { .compatible = "khadas,vim4-mcu", .data = &khadas_vim4_mcu_data },
We don't allow data from one registration API (MFD) to be shoved through another (DT). Pass a value to match on instead, then use a switch() statement or similar to populate or register the devices.
Quoted 8 lines
drivers/mfd/khadas-mcu.c +0
-0{}, };MODULE_DEVICE_TABLE (of, khadas_mcu_of_match);Signature · 2 lines
-- 2.49.0
Re: [PATCH v5 4/8] mfd: khadas-mcu: Add support for VIM4 MCU variant
Thanks for your review Lee.
Quoted 29 lines · Lee Jones
Quoted 27 lines · On Fri, 24 Apr 2026, Ronald Claveau via B4 Relay wrote:
From: Ronald Claveau <[email protected]>
Refactor
probe()to use per-variantkhadas_mcu_datainstead of hardcoded globals.Add dedicated regmap configuration and device data for the VIM4 MCU, with its own volatile/writeable registers.
Add the fan control register
(0–100 levels vs 0–3 for previous supported boards).Add a new compatible string "khadas,vim4-mcu".
Reviewed-by Neil Armstrong <[email protected]>Signed-off-by Ronald Claveau <[email protected]>--- drivers/mfd/khadas-mcu.c | 106 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 95 insertions(+), 11 deletions(-)drivers/mfd/khadas-mcu.c +0
-0@@ -75,15 +75,91 @@ static const struct regmap_config khadas_mcu_regmap_config = { .cache_type = REGCACHE_MAPLE, };
Quoted 7 lines
drivers/mfd/khadas-mcu.c static const struct regmap_config khadas_mcu_regmap_config = { · line 81
Quoted 4 lines
drivers/mfd/khadas-mcu.c +4
-0+static const struct khadas_mcu_fan_pdata khadas_mcu_fan_pdata = { + .fan_reg =KHADAS_MCU_CMD_FAN_STATUS_CTRL_REG , + .max_level =3 , +};What is 3?
This is the max fan speed level as defined in the MCU register. I will add it as a comment.
/* Fan speed: 0 = off, 1 = low, 2 = medium, 3 = high */
Quoted 4 lines
Quoted 4 lines
drivers/mfd/khadas-mcu.c +1
-1+static struct mfd_cell khadas_mcu_fan_cells[] = {/* VIM1/2 Rev13+ and VIM3 only */ - { .name ="khadas-mcu-fan-ctrl" , },
Quoted 9 lines
drivers/mfd/khadas-mcu.c static const struct regmap_config khadas_mcu_regmap_config = { · line 90
Quoted 6 lines
drivers/mfd/khadas-mcu.c +5
-0+ { + .name = "khadas-mcu-fan-ctrl", + .platform_data = &khadas_mcu_fan_pdata, + .pdata_size = sizeof(khadas_mcu_fan_pdata), + }, };Worth making this const at one point.
Yes I will.
Quoted 5 lines
drivers/mfd/khadas-mcu.c static const struct regmap_config khadas_mcu_regmap_config = { · line 95
Quoted 5 lines
drivers/mfd/khadas-mcu.c +0
-0static struct mfd_cell khadas_mcu_cells[] = { { .name ="khadas-mcu-user-mem" , }, };
I will for that one too.
Quoted 76 lines
drivers/mfd/khadas-mcu.c static const struct regmap_config khadas_mcu_regmap_config = { · line 102
Quoted 7 lines
drivers/mfd/khadas-mcu.c +7
-0+static const struct khadas_mcu_data khadas_mcu_data = { + .regmap_config = &khadas_mcu_regmap_config, + .cells = khadas_mcu_cells, + .ncells =ARRAY_SIZE (khadas_mcu_cells), + .fan_cells = khadas_mcu_fan_cells, + .nfan_cells =ARRAY_SIZE (khadas_mcu_fan_cells), +};This is a red flag!
Quoted 66 lines
drivers/mfd/khadas-mcu.c +59
-0+static bool khadas_mcu_vim4_reg_volatile (struct device *dev,unsigned int reg) +{ +switch (reg) { +case KHADAS_MCU_PWR_OFF_CMD_REG : +case KHADAS_MCU_VIM4_REST_CONF_REG : +case KHADAS_MCU_WOL_INIT_START_REG : +case KHADAS_MCU_VIM4_LED_ON_RAM_REG : +case KHADAS_MCU_VIM4_FAN_CTRL_REG : +case KHADAS_MCU_VIM4_WDT_EN_REG : +case KHADAS_MCU_VIM4_SYS_RST_REG : +return true; +default : +return false; + } +} + +static bool khadas_mcu_vim4_reg_writeable (struct device *dev,unsigned int reg) +{ +switch (reg) { +case KHADAS_MCU_VERSION_0_REG : +case KHADAS_MCU_VERSION_1_REG : +case KHADAS_MCU_SHUTDOWN_NORMAL_STATUS_REG : +return false; +default : +return true; + } +} + +static const struct regmap_config khadas_mcu_vim4_regmap_config = { + .reg_bits =8 , + .reg_stride =1 , + .val_bits =8 , + .max_register =KHADAS_MCU_VIM4_SYS_RST_REG , + .volatile_reg = khadas_mcu_vim4_reg_volatile, + .writeable_reg = khadas_mcu_vim4_reg_writeable, + .cache_type =REGCACHE_MAPLE , +}; + +static const struct khadas_mcu_fan_pdata khadas_vim4_fan_pdata = { + .fan_reg =KHADAS_MCU_VIM4_FAN_CTRL_REG , + .max_level =0x64 , +}; + +static const struct mfd_cell khadas_mcu_vim4_cells[] = { + { + .name ="khadas-mcu-fan-ctrl" , + .platform_data = &khadas_vim4_fan_pdata, + .pdata_size =sizeof (khadas_vim4_fan_pdata), + }, +}; + +static const struct khadas_mcu_data khadas_vim4_mcu_data = { + .regmap_config = &khadas_mcu_vim4_regmap_config, + .cells =NULL , + .ncells =0 , + .fan_cells = khadas_mcu_vim4_cells, + .nfan_cells =ARRAY_SIZE (khadas_mcu_vim4_cells), +}; +static int khadas_mcu_probe (struct i2c_client *client) {struct device *dev = &client->dev;@@ -94,28 +170,35 @@ static int khadas_mcu_probe(struct i2c_client *client)if (!ddata)return -ENOMEM ;
Quoted 6 lines
drivers/mfd/khadas-mcu.c static int khadas_mcu_probe(struct i2c_client *client) · line 175
Quoted 3 lines
drivers/mfd/khadas-mcu.c +3
-0+ ddata->data =i2c_get_match_data (client); +if (!ddata->data) +return -EINVAL ;Shouldn't this be
-ENODEV?
I will change to -ENODEV for the switch default.
Quoted 10 lines
drivers/mfd/khadas-mcu.c static int khadas_mcu_probe(struct i2c_client *client) · line 182
Quoted 7 lines
drivers/mfd/khadas-mcu.c +2
-1i2c_set_clientdata (client, ddata); ddata->dev = dev; - ddata->regmap =devm_regmap_init_i2c (client, &khadas_mcu_regmap_config); + ddata->regmap =devm_regmap_init_i2c (client, + ddata->data->regmap_config);Use up to 100-chars to prevent this kind of wrapping.
Ok will do, is it a general rule or depends on maintainer ?
Quoted 8 lines
drivers/mfd/khadas-mcu.c static int khadas_mcu_probe(struct i2c_client *client) · line 187
Quoted 5 lines
drivers/mfd/khadas-mcu.c +0
-0if (IS_ERR (ddata->regmap)) { ret =PTR_ERR (ddata->regmap);dev_err (dev,"Failed to allocate register map: %d\n" , ret);return ret; }Maybe convert this to
dev_err_probe()at one point.
Ok I change that.
Quoted 26 lines
Quoted 26 lines
drivers/mfd/khadas-mcu.c +10
-8- ret =devm_mfd_add_devices (dev,PLATFORM_DEVID_NONE , - khadas_mcu_cells, -ARRAY_SIZE (khadas_mcu_cells), -NULL ,0 ,NULL ); -if (ret) -return ret; +if (ddata->data->cells && ddata->data->ncells) { + ret =devm_mfd_add_devices (dev,PLATFORM_DEVID_NONE , + ddata->data->cells, + ddata->data->ncells, +NULL ,0 ,NULL ); +if (ret) +return ret; + }if (of_property_present (dev->of_node,"#cooling-cells" ))return devm_mfd_add_devices (dev,PLATFORM_DEVID_NONE , - khadas_mcu_fan_cells, -ARRAY_SIZE (khadas_mcu_fan_cells), + ddata->data->fan_cells, + ddata->data->nfan_cells,NULL ,0 ,NULL );return 0 ;@@ -123,7 +206,8 @@ static int khadas_mcu_probe(struct i2c_client *client)
Quoted 10 lines
drivers/mfd/khadas-mcu.c static int khadas_mcu_probe(struct i2c_client *client) · line 210
Quoted 5 lines
drivers/mfd/khadas-mcu.c +2
-1#ifdef CONFIG_OF static const struct of_device_id khadas_mcu_of_match[] = { - { .compatible = "khadas,mcu", }, + { .compatible ="khadas,mcu" , .data = &khadas_mcu_data }, + { .compatible = "khadas,vim4-mcu", .data = &khadas_vim4_mcu_data },We don't allow data from one registration API (MFD) to be shoved through another (DT). Pass a value to match on instead, then use a
switch()statement or similar to populate or register the devices.
Thanks I'm on it.
Quoted 8 lines
Quoted 8 lines
drivers/mfd/khadas-mcu.c +0
-0{}, };MODULE_DEVICE_TABLE (of, khadas_mcu_of_match);Signature · 2 lines
-- 2.49.0
Signature · 2 lines
Best regards, Ronald
PATCH v5 5/8 thermal: khadas-mcu-fan: Add fan config from platform data Add regulator support
In reply to Ronald ClaveauReplace the hardcoded MAX_LEVEL constant and fan register with values read from platform_data (fan_reg, max_level), as new MCUs need different values.
Optionally acquire and enable a "fan" regulator supply at probe time and on resume,
so boards that gate fan power through a regulator are handled.
--- drivers/thermal/khadas_mcu_fan.c | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-)
drivers/thermal/khadas_mcu_fan.c +30 -7
@@ -13,13 +13,15 @@#include <linux/regmap.h> #include <linux/sysfs.h> #include <linux/thermal.h> - -#define MAX_LEVEL 3 +#include <linux/regulator/consumer.h> struct khadas_mcu_fan_ctx {struct khadas_mcu *mcu; +unsigned int fan_reg;unsigned int level; +unsigned int max_level;struct thermal_cooling_device *cdev; +struct regulator *power; }; static int khadas_mcu_fan_set_level(struct khadas_mcu_fan_ctx *ctx,
@@ -27,8 +29,7 @@ static int khadas_mcu_fan_set_level(struct khadas_mcu_fan_ctx *ctx, {int ret; - ret =regmap_write (ctx->mcu->regmap,KHADAS_MCU_CMD_FAN_STATUS_CTRL_REG , - level); + ret =regmap_write (ctx->mcu->regmap, ctx->fan_reg, level);if (ret)return ret;
@@ -40,7 +41,9 @@ static int khadas_mcu_fan_set_level(struct khadas_mcu_fan_ctx *ctx,static int khadas_mcu_fan_get_max_state (struct thermal_cooling_device *cdev,unsigned long *state) { - *state =MAX_LEVEL ; +struct khadas_mcu_fan_ctx *ctx = cdev->devdata; + + *state = ctx->max_level;return 0 ; }
@@ -61,7 +64,7 @@ khadas_mcu_fan_set_cur_state(struct thermal_cooling_device *cdev, {struct khadas_mcu_fan_ctx *ctx = cdev->devdata; -if (state >MAX_LEVEL ) +if (state > ctx->max_level)return -EINVAL ;if (state == ctx->level)
@@ -78,6 +81,7 @@ static const struct thermal_cooling_device_ops khadas_mcu_fan_cooling_ops = {static int khadas_mcu_fan_probe (struct platform_device *pdev) { +const struct khadas_mcu_fan_pdata *pdata =dev_get_platdata (&pdev->dev);struct khadas_mcu *mcu =dev_get_drvdata (pdev->dev.parent);struct thermal_cooling_device *cdev;struct device *dev = &pdev->dev;
@@ -87,7 +91,21 @@ static int khadas_mcu_fan_probe(struct platform_device *pdev) ctx =devm_kzalloc (dev,sizeof (*ctx),GFP_KERNEL );if (!ctx)return -ENOMEM ; + ctx->mcu = mcu; + ctx->fan_reg = pdata->fan_reg; + ctx->max_level = pdata->max_level; + + ctx->power =devm_regulator_get (dev->parent,"fan" ); +if (IS_ERR (ctx->power)) +return PTR_ERR (ctx->power); + + ret =regulator_enable (ctx->power); +if (ret) { +dev_err (dev,"Failed to enable fan power supply: %d\n" , ret); +return ret; + } +platform_set_drvdata (pdev, ctx); cdev = devm_thermal_of_cooling_device_register(dev->parent,
@@ -124,12 +142,17 @@ static int khadas_mcu_fan_suspend(struct device *dev) ctx->level = level_save; -return 0 ; +return regulator_disable (ctx->power); }static int khadas_mcu_fan_resume (struct device *dev) {struct khadas_mcu_fan_ctx *ctx =dev_get_drvdata (dev); +int ret; + + ret =regulator_enable (ctx->power); +if (ret) +return ret;return khadas_mcu_fan_set_level (ctx, ctx->level); }
Signature · 1 line
2.49.0
Re: [PATCH v5 5/8] thermal: khadas-mcu-fan: Add fan config from platform data Add regulator support
Quoted 107 lines · On 4/24/26 16:17, Ronald Claveau via B4 Relay wrote:
From: Ronald Claveau <[email protected]>
Replace the hardcoded
MAX_LEVELconstant and fan register with values read fromplatform_data(fan_reg,max_level), as new MCUs need different values.Optionally acquire and enable a "fan" regulator supply at probe time and on resume,
so boards that gate fan power through a regulator are handled.Signed-off-by Ronald Claveau <[email protected]>--- drivers/thermal/khadas_mcu_fan.c | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-)drivers/thermal/khadas_mcu_fan.c +25
-7@@ -13,13 +13,15 @@#include <linux/regmap.h> #include <linux/sysfs.h> #include <linux/thermal.h> - -#define MAX_LEVEL 3 +#include <linux/regulator/consumer.h> struct khadas_mcu_fan_ctx {struct khadas_mcu *mcu; +unsigned int fan_reg;unsigned int level; +unsigned int max_level;struct thermal_cooling_device *cdev; +struct regulator *power; }; static int khadas_mcu_fan_set_level(struct khadas_mcu_fan_ctx *ctx,@@ -27,8 +29,7 @@ static int khadas_mcu_fan_set_level(struct khadas_mcu_fan_ctx *ctx, {int ret; - ret =regmap_write (ctx->mcu->regmap,KHADAS_MCU_CMD_FAN_STATUS_CTRL_REG , - level); + ret =regmap_write (ctx->mcu->regmap, ctx->fan_reg, level);if (ret)return ret;@@ -40,7 +41,9 @@ static int khadas_mcu_fan_set_level(struct khadas_mcu_fan_ctx *ctx,static int khadas_mcu_fan_get_max_state (struct thermal_cooling_device *cdev,unsigned long *state) { - *state =MAX_LEVEL ; +struct khadas_mcu_fan_ctx *ctx = cdev->devdata; + + *state = ctx->max_level;return 0 ; }@@ -61,7 +64,7 @@ khadas_mcu_fan_set_cur_state(struct thermal_cooling_device *cdev, {struct khadas_mcu_fan_ctx *ctx = cdev->devdata; -if (state >MAX_LEVEL ) +if (state > ctx->max_level)return -EINVAL ;if (state == ctx->level)@@ -78,6 +81,7 @@ static const struct thermal_cooling_device_ops khadas_mcu_fan_cooling_ops = {static int khadas_mcu_fan_probe (struct platform_device *pdev) { +const struct khadas_mcu_fan_pdata *pdata =dev_get_platdata (&pdev->dev);struct khadas_mcu *mcu =dev_get_drvdata (pdev->dev.parent);struct thermal_cooling_device *cdev;struct device *dev = &pdev->dev;@@ -87,7 +91,21 @@ static int khadas_mcu_fan_probe(struct platform_device *pdev) ctx =devm_kzalloc (dev,sizeof (*ctx),GFP_KERNEL );if (!ctx)return -ENOMEM ; + ctx->mcu = mcu; + ctx->fan_reg = pdata->fan_reg; + ctx->max_level = pdata->max_level; + + ctx->power =devm_regulator_get (dev->parent,"fan" ); +if (IS_ERR (ctx->power)) +return PTR_ERR (ctx->power); + + ret =regulator_enable (ctx->power); +if (ret) { +dev_err (dev,"Failed to enable fan power supply: %d\n" , ret); +return ret; + } +platform_set_drvdata (pdev, ctx); cdev = devm_thermal_of_cooling_device_register(dev->parent,@@ -124,12 +142,17 @@ static int khadas_mcu_fan_suspend(struct device *dev) ctx->level = level_save; -return 0 ; +return regulator_disable (ctx->power); }static int khadas_mcu_fan_resume (struct device *dev)
drivers/thermal/khadas_mcu_fan.c static int khadas_mcu_fan_suspend(struct device *dev) · line 158
Quoted 10 lines
drivers/thermal/khadas_mcu_fan.c +5
-0{struct khadas_mcu_fan_ctx *ctx =dev_get_drvdata (dev); +int ret; + + ret =regulator_enable (ctx->power); +if (ret) +return ret;return khadas_mcu_fan_set_level (ctx, ctx->level); }
PATCH v5 6/8 arm64: dts: amlogic: t7: Add i2c pinctrl node
In reply to Ronald ClaveauAdd the T7 pinctrl used by the Khadas VIM4 for MCU communication.
--- arch/arm64/boot/dts/amlogic/amlogic-t7.dtsi | 10 ++++++++++ 1 file changed, 10 insertions(+)
arch/arm64/boot/dts/amlogic/amlogic-t7.dtsi +10 -0
@@ -376,6 +376,16 @@ mux { }; }; + i2c0_ao_d_pins: i2c0-ao-d { + mux { + groups = "i2c0_ao_sck_d", + "i2c0_ao_sda_d"; + function = "i2c0_ao"; + bias-disable; + drive-strength-microamp = <3000>; + }; + }; + pwm_a_pins: pwm-a { mux { groups = "pwm_a";
Signature · 1 line
2.49.0
PATCH v5 7/8 arm64: dts: amlogic: t7: Add i2c controller node
In reply to Ronald ClaveauAdd the T7 i2c controller node used by the Khadas VIM4 for MCU communication.
Use amlogic,meson-axg-i2c as fallback compatible.
--- arch/arm64/boot/dts/amlogic/amlogic-t7.dtsi | 10 ++++++++++ 1 file changed, 10 insertions(+)
arch/arm64/boot/dts/amlogic/amlogic-t7.dtsi +10 -0
@@ -711,6 +711,16 @@ pwm_ao_cd: pwm@60000 { status = "disabled"; }; + i2c_m_ao_a: i2c@76000 { + compatible = "amlogic,t7-i2c", "amlogic,meson-axg-i2c"; + reg = <0x0 0x76000 0x0 0x48>; + #address-cells = <1>; + #size-cells = <0>; + interrupts = <GIC_SPI 330 IRQ_TYPE_EDGE_RISING>; + clocks = <&clkc_periphs CLKID_SYS_I2C_AO_A>; + status = "disabled"; + }; + sd_emmc_a: mmc@88000 { compatible = "amlogic,t7-mmc", "amlogic,meson-axg-mmc"; reg = <0x0 0x88000 0x0 0x800>;
Signature · 1 line
2.49.0
PATCH v5 8/8 arm64: dts: amlogic: t7: khadas-vim4: Add i2c MCU fan node
In reply to Ronald ClaveauEnable and configure i2c MCU node to get fan working on Khadas VIM4.
--- .../boot/dts/amlogic/amlogic-t7-a311d2-khadas-vim4.dts | 13 +++++++++++++ 1 file changed, 13 insertions(+)
arch/arm64/boot/dts/amlogic/amlogic-t7-a311d2-khadas-vim4.dts +13 -0
@@ -157,6 +157,19 @@ wifi32k: wifi32k { }; }; +&i2c_m_ao_a { + status = "okay"; + pinctrl-0 = <&i2c0_ao_d_pins>; + pinctrl-names = "default"; + + khadas_mcu: system-controller@18 { + compatible = "khadas,vim4-mcu"; + reg = <0x18>; + fan-supply = <&vcc5v>; + #cooling-cells = <2>; + }; +}; + &pwm_ab { status = "okay"; pinctrl-0 = <&pwm_a_pins>;
Signature · 1 line
2.49.0