* [PATCH v5 0/2] *mfd: Add support for Khadas Microcontroller
@ 2020-06-24 16:15 Neil Armstrong
2020-06-24 16:15 ` [PATCH v5 1/2] thermal: add support for the MCU controlled FAN on Khadas boards Neil Armstrong
2020-06-24 16:15 ` [PATCH v5 2/2] arm64: dts: meson-khadas-vim3: add Khadas MCU nodes Neil Armstrong
0 siblings, 2 replies; 6+ messages in thread
From: Neil Armstrong @ 2020-06-24 16:15 UTC (permalink / raw)
To: khilman, lee.jones
Cc: Neil Armstrong, linux-amlogic, linux-pm, linux-arm-kernel,
linux-kernel, rui.zhang, daniel.lezcano, amit.kucheria
The new Khadas VIM2, VIM3 and Edge boards embeds an on-board microcontroller
connected via I2C.
This Microcontroller is present on the Khadas VIM1, VIM2, VIM3 and Edge
boards.
It has multiple boot control features like password check, power-on
options, power-off control and system FAN control on recent boards.
Thie serie adds :
- the Thermal Cooling cell driver
- add support into the Khadas VIM3/VIM3L DT
Changes since v4 at [5]:
- Removed ctx checks in thermal driver
- Removed the useless khadas_mcu_fan_disable() helper in thermal driver
- Fixed a small indentation issue in thermal driver
Changes since v3 at [4]:
- Removed Applied patches 1, 2 & 4
- Added reviewed-by tags for patch 3 & 5
Changes since v2 at [3]:
- Removed NVMEM driver for separate submission
- fixed MFD driver, header and Kconfig
- fixed Thermal Kconfig
- fixed MAINTAINERS files and path
Changes since RFC v1 at [2]:
- moved hwmon driver to thermal-only
- moved the SM1 thermal nodes in a separate serie
- added the bindings review tag from rob
[1] http://lore.kernel.org/r/20200512093916.19676-1-narmstrong@baylibre.com
[2] http://lore.kernel.org/r/20200421080102.22796-1-narmstrong@baylibre.com
[3] http://lore.kernel.org/r/20200512132613.31507-1-narmstrong@baylibre.com
[4] http://lore.kernel.org/r/20200608091739.2368-1-narmstrong@baylibre.com
[5] http://lore.kernel.org/r/20200618133818.15857-1-narmstrong@baylibre.com
Neil Armstrong (2):
thermal: add support for the MCU controlled FAN on Khadas boards
arm64: dts: meson-khadas-vim3: add Khadas MCU nodes
.../boot/dts/amlogic/meson-khadas-vim3.dtsi | 23 +++
drivers/thermal/Kconfig | 11 ++
drivers/thermal/Makefile | 1 +
drivers/thermal/khadas_mcu_fan.c | 162 ++++++++++++++++++
4 files changed, 197 insertions(+)
create mode 100644 drivers/thermal/khadas_mcu_fan.c
--
2.22.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v5 1/2] thermal: add support for the MCU controlled FAN on Khadas boards
2020-06-24 16:15 [PATCH v5 0/2] *mfd: Add support for Khadas Microcontroller Neil Armstrong
@ 2020-06-24 16:15 ` Neil Armstrong
2020-06-24 16:18 ` Daniel Lezcano
2020-06-25 6:43 ` Lee Jones
2020-06-24 16:15 ` [PATCH v5 2/2] arm64: dts: meson-khadas-vim3: add Khadas MCU nodes Neil Armstrong
1 sibling, 2 replies; 6+ messages in thread
From: Neil Armstrong @ 2020-06-24 16:15 UTC (permalink / raw)
To: lee.jones
Cc: Neil Armstrong, khilman, linux-amlogic, linux-pm,
linux-arm-kernel, linux-kernel, rui.zhang, daniel.lezcano,
amit.kucheria, Amit Kucheria
The new Khadas VIM2 and VIM3 boards controls the cooling fan via the
on-board microcontroller.
This implements the FAN control as thermal devices and as cell of the Khadas
MCU MFD driver.
Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
Reviewed-by: Amit Kucheria <amit.kucheria@linaro.org>
---
Hi Daniel,
Is it ok Lee applies this patch via the MFD tree since it depends on
the linux/mfd/khadas-mcu.h header ?
Thanks,
Neil
drivers/thermal/Kconfig | 11 +++
drivers/thermal/Makefile | 1 +
drivers/thermal/khadas_mcu_fan.c | 162 +++++++++++++++++++++++++++++++
3 files changed, 174 insertions(+)
create mode 100644 drivers/thermal/khadas_mcu_fan.c
diff --git a/drivers/thermal/Kconfig b/drivers/thermal/Kconfig
index 3eb2348e5242..0125561488c9 100644
--- a/drivers/thermal/Kconfig
+++ b/drivers/thermal/Kconfig
@@ -500,4 +500,15 @@ config SPRD_THERMAL
help
Support for the Spreadtrum thermal sensor driver in the Linux thermal
framework.
+
+config KHADAS_MCU_FAN_THERMAL
+ tristate "Khadas MCU controller FAN cooling support"
+ depends on OF || COMPILE_TEST
+ depends on MFD_KHADAS_MCU
+ select MFD_CORE
+ select REGMAP
+ help
+ If you say yes here you get support for the FAN controlled
+ by the Microcontroller found on the Khadas VIM boards.
+
endif
diff --git a/drivers/thermal/Makefile b/drivers/thermal/Makefile
index 0c8b84a09b9a..4b6aabaa7e31 100644
--- a/drivers/thermal/Makefile
+++ b/drivers/thermal/Makefile
@@ -61,3 +61,4 @@ obj-$(CONFIG_ZX2967_THERMAL) += zx2967_thermal.o
obj-$(CONFIG_UNIPHIER_THERMAL) += uniphier_thermal.o
obj-$(CONFIG_AMLOGIC_THERMAL) += amlogic_thermal.o
obj-$(CONFIG_SPRD_THERMAL) += sprd_thermal.o
+obj-$(CONFIG_KHADAS_MCU_FAN_THERMAL) += khadas_mcu_fan.o
diff --git a/drivers/thermal/khadas_mcu_fan.c b/drivers/thermal/khadas_mcu_fan.c
new file mode 100644
index 000000000000..9eadd2d6413e
--- /dev/null
+++ b/drivers/thermal/khadas_mcu_fan.c
@@ -0,0 +1,162 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Khadas MCU Controlled FAN driver
+ *
+ * Copyright (C) 2020 BayLibre SAS
+ * Author(s): Neil Armstrong <narmstrong@baylibre.com>
+ */
+
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/mfd/khadas-mcu.h>
+#include <linux/regmap.h>
+#include <linux/sysfs.h>
+#include <linux/thermal.h>
+
+#define MAX_LEVEL 3
+
+struct khadas_mcu_fan_ctx {
+ struct khadas_mcu *mcu;
+ unsigned int level;
+ struct thermal_cooling_device *cdev;
+};
+
+static int khadas_mcu_fan_set_level(struct khadas_mcu_fan_ctx *ctx,
+ unsigned int level)
+{
+ int ret;
+
+ ret = regmap_write(ctx->mcu->regmap, KHADAS_MCU_CMD_FAN_STATUS_CTRL_REG,
+ level);
+ if (ret)
+ return ret;
+
+ ctx->level = level;
+
+ return 0;
+}
+
+static int khadas_mcu_fan_get_max_state(struct thermal_cooling_device *cdev,
+ unsigned long *state)
+{
+ *state = MAX_LEVEL;
+
+ return 0;
+}
+
+static int khadas_mcu_fan_get_cur_state(struct thermal_cooling_device *cdev,
+ unsigned long *state)
+{
+ struct khadas_mcu_fan_ctx *ctx = cdev->devdata;
+
+ *state = ctx->level;
+
+ return 0;
+}
+
+static int
+khadas_mcu_fan_set_cur_state(struct thermal_cooling_device *cdev,
+ unsigned long state)
+{
+ struct khadas_mcu_fan_ctx *ctx = cdev->devdata;
+
+ if (state > MAX_LEVEL)
+ return -EINVAL;
+
+ if (state == ctx->level)
+ return 0;
+
+ return khadas_mcu_fan_set_level(ctx, state);
+}
+
+static const struct thermal_cooling_device_ops khadas_mcu_fan_cooling_ops = {
+ .get_max_state = khadas_mcu_fan_get_max_state,
+ .get_cur_state = khadas_mcu_fan_get_cur_state,
+ .set_cur_state = khadas_mcu_fan_set_cur_state,
+};
+
+static int khadas_mcu_fan_probe(struct platform_device *pdev)
+{
+ struct khadas_mcu *mcu = dev_get_drvdata(pdev->dev.parent);
+ struct thermal_cooling_device *cdev;
+ struct device *dev = &pdev->dev;
+ struct khadas_mcu_fan_ctx *ctx;
+ int ret;
+
+ ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
+ if (!ctx)
+ return -ENOMEM;
+ ctx->mcu = mcu;
+ platform_set_drvdata(pdev, ctx);
+
+ cdev = devm_thermal_of_cooling_device_register(dev->parent,
+ dev->parent->of_node, "khadas-mcu-fan", ctx,
+ &khadas_mcu_fan_cooling_ops);
+ if (IS_ERR(cdev)) {
+ ret = PTR_ERR(cdev);
+ dev_err(dev, "Failed to register khadas-mcu-fan as cooling device: %d\n",
+ ret);
+ return ret;
+ }
+ ctx->cdev = cdev;
+ thermal_cdev_update(cdev);
+
+ return 0;
+}
+
+static void khadas_mcu_fan_shutdown(struct platform_device *pdev)
+{
+ struct khadas_mcu_fan_ctx *ctx = platform_get_drvdata(pdev);
+
+ khadas_mcu_fan_set_level(ctx, 0);
+}
+
+#ifdef CONFIG_PM_SLEEP
+static int khadas_mcu_fan_suspend(struct device *dev)
+{
+ struct khadas_mcu_fan_ctx *ctx = dev_get_drvdata(dev);
+ unsigned int level_save = ctx->level;
+ int ret;
+
+ ret = khadas_mcu_fan_set_level(ctx, 0);
+ if (ret)
+ return ret;
+
+ ctx->level = level_save;
+
+ return 0;
+}
+
+static int khadas_mcu_fan_resume(struct device *dev)
+{
+ struct khadas_mcu_fan_ctx *ctx = dev_get_drvdata(dev);
+
+ return khadas_mcu_fan_set_level(ctx, ctx->level);
+}
+#endif
+
+static SIMPLE_DEV_PM_OPS(khadas_mcu_fan_pm, khadas_mcu_fan_suspend,
+ khadas_mcu_fan_resume);
+
+static const struct platform_device_id khadas_mcu_fan_id_table[] = {
+ { .name = "khadas-mcu-fan-ctrl", },
+ {},
+};
+MODULE_DEVICE_TABLE(platform, khadas_mcu_fan_id_table);
+
+static struct platform_driver khadas_mcu_fan_driver = {
+ .probe = khadas_mcu_fan_probe,
+ .shutdown = khadas_mcu_fan_shutdown,
+ .driver = {
+ .name = "khadas-mcu-fan-ctrl",
+ .pm = &khadas_mcu_fan_pm,
+ },
+ .id_table = khadas_mcu_fan_id_table,
+};
+
+module_platform_driver(khadas_mcu_fan_driver);
+
+MODULE_AUTHOR("Neil Armstrong <narmstrong@baylibre.com>");
+MODULE_DESCRIPTION("Khadas MCU FAN driver");
+MODULE_LICENSE("GPL");
--
2.22.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v5 2/2] arm64: dts: meson-khadas-vim3: add Khadas MCU nodes
2020-06-24 16:15 [PATCH v5 0/2] *mfd: Add support for Khadas Microcontroller Neil Armstrong
2020-06-24 16:15 ` [PATCH v5 1/2] thermal: add support for the MCU controlled FAN on Khadas boards Neil Armstrong
@ 2020-06-24 16:15 ` Neil Armstrong
2020-07-02 7:49 ` Neil Armstrong
1 sibling, 1 reply; 6+ messages in thread
From: Neil Armstrong @ 2020-06-24 16:15 UTC (permalink / raw)
To: khilman
Cc: Neil Armstrong, lee.jones, linux-amlogic, linux-pm,
linux-arm-kernel, linux-kernel, rui.zhang, daniel.lezcano,
amit.kucheria, Amit Kucheria
Add the Khadas MCU node with active FAN thermal nodes for all the
Khadas VIM3 variants.
Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
Reviewed-by: Amit Kucheria <amit.kucheria@linaro.org>
---
Hi Kevin,
The bindings has been reviewed and merged by Lee,
could you apply this one via the amlogic tree ?
Thanks,
Neil
.../boot/dts/amlogic/meson-khadas-vim3.dtsi | 23 +++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/arch/arm64/boot/dts/amlogic/meson-khadas-vim3.dtsi b/arch/arm64/boot/dts/amlogic/meson-khadas-vim3.dtsi
index 1ef1e3672b96..27408c10a811 100644
--- a/arch/arm64/boot/dts/amlogic/meson-khadas-vim3.dtsi
+++ b/arch/arm64/boot/dts/amlogic/meson-khadas-vim3.dtsi
@@ -183,6 +183,23 @@
hdmi-phandle = <&hdmi_tx>;
};
+&cpu_thermal {
+ trips {
+ cpu_active: cpu-active {
+ temperature = <80000>; /* millicelsius */
+ hysteresis = <2000>; /* millicelsius */
+ type = "active";
+ };
+ };
+
+ cooling-maps {
+ map {
+ trip = <&cpu_active>;
+ cooling-device = <&khadas_mcu THERMAL_NO_LIMIT THERMAL_NO_LIMIT>;
+ };
+ };
+};
+
&ext_mdio {
external_phy: ethernet-phy@0 {
/* Realtek RTL8211F (0x001cc916) */
@@ -222,6 +239,12 @@
pinctrl-0 = <&i2c_ao_sck_pins>, <&i2c_ao_sda_pins>;
pinctrl-names = "default";
+ khadas_mcu: system-controller@18 {
+ compatible = "khadas,mcu";
+ reg = <0x18>;
+ #cooling-cells = <2>;
+ };
+
gpio_expander: gpio-controller@20 {
compatible = "ti,tca6408";
reg = <0x20>;
--
2.22.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v5 1/2] thermal: add support for the MCU controlled FAN on Khadas boards
2020-06-24 16:15 ` [PATCH v5 1/2] thermal: add support for the MCU controlled FAN on Khadas boards Neil Armstrong
@ 2020-06-24 16:18 ` Daniel Lezcano
2020-06-25 6:43 ` Lee Jones
1 sibling, 0 replies; 6+ messages in thread
From: Daniel Lezcano @ 2020-06-24 16:18 UTC (permalink / raw)
To: Neil Armstrong, lee.jones
Cc: khilman, linux-amlogic, linux-pm, linux-arm-kernel, linux-kernel,
rui.zhang, amit.kucheria, Amit Kucheria
On 24/06/2020 18:15, Neil Armstrong wrote:
> The new Khadas VIM2 and VIM3 boards controls the cooling fan via the
> on-board microcontroller.
>
> This implements the FAN control as thermal devices and as cell of the Khadas
> MCU MFD driver.
>
> Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
> Reviewed-by: Amit Kucheria <amit.kucheria@linaro.org>
> ---
> Hi Daniel,
>
> Is it ok Lee applies this patch via the MFD tree since it depends on
> the linux/mfd/khadas-mcu.h header ?
Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org>
[ ... ]
--
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs
Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v5 1/2] thermal: add support for the MCU controlled FAN on Khadas boards
2020-06-24 16:15 ` [PATCH v5 1/2] thermal: add support for the MCU controlled FAN on Khadas boards Neil Armstrong
2020-06-24 16:18 ` Daniel Lezcano
@ 2020-06-25 6:43 ` Lee Jones
1 sibling, 0 replies; 6+ messages in thread
From: Lee Jones @ 2020-06-25 6:43 UTC (permalink / raw)
To: Neil Armstrong
Cc: khilman, linux-amlogic, linux-pm, linux-arm-kernel, linux-kernel,
rui.zhang, daniel.lezcano, amit.kucheria, Amit Kucheria
On Wed, 24 Jun 2020, Neil Armstrong wrote:
> The new Khadas VIM2 and VIM3 boards controls the cooling fan via the
> on-board microcontroller.
>
> This implements the FAN control as thermal devices and as cell of the Khadas
> MCU MFD driver.
>
> Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
> Reviewed-by: Amit Kucheria <amit.kucheria@linaro.org>
> ---
> Hi Daniel,
>
> Is it ok Lee applies this patch via the MFD tree since it depends on
> the linux/mfd/khadas-mcu.h header ?
>
> Thanks,
> Neil
>
> drivers/thermal/Kconfig | 11 +++
> drivers/thermal/Makefile | 1 +
> drivers/thermal/khadas_mcu_fan.c | 162 +++++++++++++++++++++++++++++++
> 3 files changed, 174 insertions(+)
> create mode 100644 drivers/thermal/khadas_mcu_fan.c
Applied, thanks.
--
Lee Jones [李琼斯]
Senior Technical Lead - Developer Services
Linaro.org │ Open source software for Arm SoCs
Follow Linaro: Facebook | Twitter | Blog
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v5 2/2] arm64: dts: meson-khadas-vim3: add Khadas MCU nodes
2020-06-24 16:15 ` [PATCH v5 2/2] arm64: dts: meson-khadas-vim3: add Khadas MCU nodes Neil Armstrong
@ 2020-07-02 7:49 ` Neil Armstrong
0 siblings, 0 replies; 6+ messages in thread
From: Neil Armstrong @ 2020-07-02 7:49 UTC (permalink / raw)
To: khilman
Cc: lee.jones, linux-amlogic, linux-pm, linux-arm-kernel,
linux-kernel, rui.zhang, daniel.lezcano, amit.kucheria,
Amit Kucheria
Hi Kevin,
Can you apply this patch ? the rest of the serie has been pulled into Lee's tree.
Thanks,
Neil
On 24/06/2020 18:15, Neil Armstrong wrote:
> Add the Khadas MCU node with active FAN thermal nodes for all the
> Khadas VIM3 variants.
>
> Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
> Reviewed-by: Amit Kucheria <amit.kucheria@linaro.org>
> ---
> Hi Kevin,
>
> The bindings has been reviewed and merged by Lee,
> could you apply this one via the amlogic tree ?
>
> Thanks,
> Neil
>
> .../boot/dts/amlogic/meson-khadas-vim3.dtsi | 23 +++++++++++++++++++
> 1 file changed, 23 insertions(+)
>
> diff --git a/arch/arm64/boot/dts/amlogic/meson-khadas-vim3.dtsi b/arch/arm64/boot/dts/amlogic/meson-khadas-vim3.dtsi
> index 1ef1e3672b96..27408c10a811 100644
> --- a/arch/arm64/boot/dts/amlogic/meson-khadas-vim3.dtsi
> +++ b/arch/arm64/boot/dts/amlogic/meson-khadas-vim3.dtsi
> @@ -183,6 +183,23 @@
> hdmi-phandle = <&hdmi_tx>;
> };
>
> +&cpu_thermal {
> + trips {
> + cpu_active: cpu-active {
> + temperature = <80000>; /* millicelsius */
> + hysteresis = <2000>; /* millicelsius */
> + type = "active";
> + };
> + };
> +
> + cooling-maps {
> + map {
> + trip = <&cpu_active>;
> + cooling-device = <&khadas_mcu THERMAL_NO_LIMIT THERMAL_NO_LIMIT>;
> + };
> + };
> +};
> +
> &ext_mdio {
> external_phy: ethernet-phy@0 {
> /* Realtek RTL8211F (0x001cc916) */
> @@ -222,6 +239,12 @@
> pinctrl-0 = <&i2c_ao_sck_pins>, <&i2c_ao_sda_pins>;
> pinctrl-names = "default";
>
> + khadas_mcu: system-controller@18 {
> + compatible = "khadas,mcu";
> + reg = <0x18>;
> + #cooling-cells = <2>;
> + };
> +
> gpio_expander: gpio-controller@20 {
> compatible = "ti,tca6408";
> reg = <0x20>;
>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2020-07-02 7:49 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-24 16:15 [PATCH v5 0/2] *mfd: Add support for Khadas Microcontroller Neil Armstrong
2020-06-24 16:15 ` [PATCH v5 1/2] thermal: add support for the MCU controlled FAN on Khadas boards Neil Armstrong
2020-06-24 16:18 ` Daniel Lezcano
2020-06-25 6:43 ` Lee Jones
2020-06-24 16:15 ` [PATCH v5 2/2] arm64: dts: meson-khadas-vim3: add Khadas MCU nodes Neil Armstrong
2020-07-02 7:49 ` Neil Armstrong
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).