imx8mm pwm in uboot not work

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

imx8mm pwm in uboot not work

Jump to solution
2,733 Views
sclu
Contributor I

My lcd backlight need pwm control, so I config pwm4, backlight in dts:

lvds_backlight: lvds_backlight {
compatible = "pwm-backlight";
pwms = <&pwm4 0 100000 0>;
status = "okay";
enable-gpios = <&gpio4 26 GPIO_ACTIVE_HIGH>;

brightness-levels = < 0 1 2 3 4 5 6 7 8 9
.......
};

&pwm4 {
#pwm-cells = <3>;
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_pwm4>;
status = "okay";
};

I also open the driver: pwm-imx.c pwm-backlight.c in Config file

But it got stuck in the driver:

int pwm_config_internal(struct pwm_regs *pwm, unsigned long period_cycles,
unsigned long duty_cycles, unsigned long prescale)
{
u32 cr;
 
    printf("%s %d, &pwm->ir=0x%x\n", __func__, __LINE__, &pwm->ir);
writel(0, &pwm->ir);
    printf("%s %d\n", __func__, __LINE__);
cr = PWMCR_PRESCALER(prescale) |
PWMCR_DOZEEN | PWMCR_WAITEN |
PWMCR_DBGEN | PWMCR_CLKSRC_IPG_HIGH;
 
    printf("%s %d\n", __func__, __LINE__);
writel(cr, &pwm->cr);
    printf("%s %d\n", __func__, __LINE__);
/* set duty cycles */
writel(duty_cycles, &pwm->sar);
    printf("%s %d\n", __func__, __LINE__);
/* set period cycles */
writel(period_cycles, &pwm->pr);
    printf("%s %d\n", __func__, __LINE__);
return 0;
}
 
The log show the "&pwm->ir"  address is correct: 0x30690008, But it's stuck here :
writel(0, &pwm->ir);
It seems that the address 0x30690008 cannot be directly accessed
 
I have also tried using ioremap function to obtain addresses, But there is a compilation error prompt
I have also tried to disable the PWM4 configuration in DTS, and used:
  pwm_init(3, 0, 0);
  pwm_config(3, 5, 10);
  pwm_enable(3);
But we also encountered the same problem
 
Can someone help me please ?
 
 
 
 

 

 

0 Kudos
Reply
1 Solution
2,653 Views
Dhruvit
NXP TechSupport
NXP TechSupport

Hi @sclu,

I hope you are doing well.

system hang-up is caused due to clock not being enabled for the PWM module.

PWM support for i.MX8M Processors is not available in the uboot version before v2022.04.

PWM  DM support & register support is added using the below commits in v2023.04.

arch: mach-imx: imx8m: add pwm_regs struct in imx-regs

arch: mach-imx: imx8m: add pwm ctrl registers fields defines

One can refer to the below-mentioned link to add pwm support in imx8m.

https://cuteparrot.pixnet.net/blog/post/229123814-%5Bnxp%5D%5Bimx8mm%5Dhow-to-enable-pwm1-on-uboot

Thanks & Regards,
Dhruvit Vasavada

View solution in original post

0 Kudos
Reply
4 Replies
2,719 Views
Dhruvit
NXP TechSupport
NXP TechSupport

Hi @sclu,

I hope you are doing well.
 
Please confirm if you were able to read/write the memory from the Uboot command or not.
 
Kindly refer to the below files for the device tree configuration for PWM in the U-boot.
 
Kindly share the whole device tree file and the log you are getting in case of failure to further debug the issue.
 
Thanks & Regards,
Dhruvit Vasavada

0 Kudos
Reply
2,685 Views
sclu
Contributor I

Thank you for your reply, My driver is attached.

I use the md.l command, and the system hang up:

sclu_1-1692599762439.png

 

 

0 Kudos
Reply
2,654 Views
Dhruvit
NXP TechSupport
NXP TechSupport

Hi @sclu,

I hope you are doing well.

system hang-up is caused due to clock not being enabled for the PWM module.

PWM support for i.MX8M Processors is not available in the uboot version before v2022.04.

PWM  DM support & register support is added using the below commits in v2023.04.

arch: mach-imx: imx8m: add pwm_regs struct in imx-regs

arch: mach-imx: imx8m: add pwm ctrl registers fields defines

One can refer to the below-mentioned link to add pwm support in imx8m.

https://cuteparrot.pixnet.net/blog/post/229123814-%5Bnxp%5D%5Bimx8mm%5Dhow-to-enable-pwm1-on-uboot

Thanks & Regards,
Dhruvit Vasavada

0 Kudos
Reply
2,639 Views
sclu
Contributor I
Your answer perfectly solved all my problems,I add:
clock_enable(CCGR_PWM4,0);
clock_set_target_val(PWM4_CLK_ROOT, CLK_ROOT_ON |
CLK_ROOT_SOURCE_SEL(0)| CLK_ROOT_POST_DIV(CLK_ROOT_POST_DIV1));
clock_enable(CCGR_PWM4, 1);
Use my code and it will work!
0 Kudos
Reply