Jan 2025 - Hello, my SoM is Toradex imx8m mini and I have added the following codes in function board_init(void) which is in board/toradex/verdin-imx8mm/verdin-imx8mm.c and I can enable the pwm successfully. But pwm is enabled within nearly one second after pressing the power button, we want it to be faster.
Then we try to move these codes in function board_init_f() which is in board/toradex/verdin-imx8mm/spl.c where the pwm can be loaded faster, but when building the u-boot, it says:
debian/build/verdin-imx8mm/spl/../board/toradex/verdin-imx8mm/spl.c:142: undefined reference to `pwm_set_config'
/usr/lib/gcc-cross/aarch64-linux-gnu/12/../../../../aarch64-linux-gnu/bin/ld: /tmp/ccl4iKdI.ltrans0.ltrans.o:debian/build/verdin-imx8mm/spl/../board/toradex/verdin-imx8mm/spl.c:148: undefined reference to `pwm_set_enable'
So, maybe need to use other function to enable pwm here?
I have enable these configs in configs/verdin-imx8mm_defconfig
+CONFIG_CMD_PWM=y
+CONFIG_PWM=y
+CONFIG_DM_PWM=y
+CONFIG_PWM_IMX=y
The following is my patch.
board/toradex/verdin-imx8mm/spl.c | 50 +++++++++++++++++++++++++++++++++++++++
1 file changed, 50 insertions(+)
diff --git a/board/toradex/verdin-imx8mm/spl.c b/board/toradex/verdin-imx8mm/spl.c
index 210665b…17de2b5 100644
— a/board/toradex/verdin-imx8mm/spl.c
+++ b/board/toradex/verdin-imx8mm/spl.c
@@ -26,11 +26,24 @@
#include <power/pca9450.h>
#include <power/pmic.h>
#include <spl.h>
+#include <dm.h>
+#include <pwm.h>
DECLARE_GLOBAL_DATA_PTR;
#define I2C_PMIC_BUS_ID 1
+#define IOMUXC_BASE_ADDR 0x30330000
+
+#define IOMUXC_SW_MUX_CTL_PAD_GPIO1_IO01 0x3033002c
+#define IOMUXC_SW_PAD_CTL_PAD_GPIO1_IO01 0x30330294
+
+#define IOMUXC_SW_MUX_CTL_PAD_SAI3_MCLK 0x303301e4
+#define IOMUXC_SW_PAD_CTL_PAD_SAI3_MCLK 0x3033044c
+
+#define MUX_MODE_ALT1 0x1
+#define PAD_CTL_DSE2 0x6
+
int spl_board_boot_device(enum boot_device boot_dev_spl)
{
switch (boot_dev_spl) {
@@ -103,6 +116,41 @@ int power_init_board(void)
return 0;
}
+void setup_iomux_pwm1(void)
+{
- // config ALT1(PWM function)
- writel(MUX_MODE_ALT1, IOMUXC_SW_MUX_CTL_PAD_GPIO1_IO01);
- // set PAD control, such as drive strength…
- writel(PAD_CTL_DSE2, IOMUXC_SW_PAD_CTL_PAD_GPIO1_IO01);
+}
+void enable_status_light(void)
+{
- struct udevice *pwm_dev1;
- int ret;
- // config IO MUX red-pwm1, green-pwm4
- setup_iomux_pwm1();
- // get pwm device
- ret = uclass_get_device(UCLASS_PWM, 0, &pwm_dev1);
- if (ret) {
-
printf("Failed to get PWM1 device: %d\n", ret);
- }
- // config PWM1:period 1ms,duty cycle 25(0-255)
- ret = pwm_set_config(pwm_dev1, 0, 1000000, 98039);
- if (ret) {
-
printf("Failed to configure PWM1: %d\n", ret);
- }
- // enable PWM
- ret = pwm_set_enable(pwm_dev1, 0, true);
- if (ret) {
-
printf("Failed to enable PWM1: %d\n", ret);
- }
+}
void board_init_f(ulong dummy)
{
struct udevice *dev;
@@ -137,6 +185,8 @@ void board_init_f(ulong dummy)
power_init_board();
- enable_status_light();
- /* DDR initialization */
spl_dram_init();