方案一:利用 LED_PWM (1) PWM0 PWM1 分析 原始功能没有复用 LS1X_PWM0_BASE 0x1fe5c000 此处是物理地址0xbfefc0000 为核心虚地址空间的程序空间地址 使用的平台文件 pwm.c 中 这就需要在内核配置时,添加以下选项: 添加了HAVE_PWM后,就有了平台设备pwm_device的定义 ls1x_pwm_list (2)内核中选择Loongson 1Cboard的CPU 则在pwm.c中定义了外部的ls1x_pwm_list,分析驱动pwm.c 这个变量在平台文件中定义,分析ls1c300a_openloongson_v2.0_platform.c 下面看leds_pwm 在drivers/leds/ 下的makefile, leds_pwm的编译依赖于 CONFIG_LEDS_PWM. CONFIG_LEDS_PWM 在内核配置中的出现依赖于 HAVE_PWM配置项 其中, struct pwm_device 在文件 linux-3.0.82-openloongson\linux-3.0.82-openloongson\arch\mips\include\asm\mach-loongson\ls1x\ls1x_pwm.h #ifndef __ASM_ARCH_LS1X_PWM_H #define __ASM_ARCH_LS1X_PWM_H struct pwm_device { unsignedint id; unsignedint gpio; boolused; }; #endif /* __ASM_ARCH_LS1X_PWM_H */ (3)Linux内核配置选中pwm驱动 Machine selection ---> Systemtype(Loongson family of machines) ---> MacineType(Loongson 1C board) ---> [ ] loongson 1c v2 Enable PWM 在LED类中配置PWM Device Drivers ---> LED Support ---> <*>PWM driven LED Support 在平台文件ls1c300a_openloongson_v2.0_platform.c 中添加: #ifdef CONFIG_LEDS_PWM static struct led_pwm ls1x_pwm_leds[] = { { .name = "ls1x_pwm_led1", .pwm_id = 0, .max_brightness = 255, .pwm_period_ns = 7812500, }, { .name = "ls1x_pwm_led2", .pwm_id = 1, .max_brightness = 255, .pwm_period_ns = 7812500, }, }; static struct led_pwm_platform_data ls1x_pwm_data ={ .num_leds = ARRAY_SIZE(ls1x_pwm_leds), .leds = ls1x_pwm_leds, }; static struct platform_device ls1x_leds_pwm = { .name = "leds_pwm", .id =-1, .dev = { .platform_data= &ls1x_pwm_data, }, }; #endif //#ifdef CONFIG_LEDS_PWM 上一个平台文件中,函数static struct platform_device *ls1b_platform_devices[]__initdata 中添加: #ifdef CONFIG_LEDS_PWM &ls1x_leds_pwm, #endif 平台文件增加成功:leds_pwm 将PWM0 占比调到最大(高电平占100%) echo 255 > brightness 将PWM0 占比调到最小(低电平占100%) echo 0 > brightness
|