【msm8953】带clk的gpio口模拟pwm

1.选择带有clk功能的gpio33作为pwm模拟口:

【msm8953】带clk的gpio口模拟pwm_第1张图片

2.配置设备树

① 在msm8953-pinctrl.dtsi添加:

位置:kernel/msm-3.18/arch/arm64/boot/dts/qcom

   gpio_clk {
            gpio_clk_default: gpio_clk_default {
                 mux {
                          pins = "gpio33";
                          function = "gp0_clk_a";
                 };
                 config {
                          pins = "gpio33";
                          drive-strength = <8>;
                          bias-pull-up;
                };
            };
            gpio_clk_sleep: gpio_clk_sleep {
                 mux {
                          pins = "gpio33";
                          function = "gp0_clk_a";
                     };
                 config {
                          pins = "gpio33";
                          drive-strength = <2>;
                          bias-pull-down;
                 };
            };
        };

② 在msm8953-mtp.dtsi的soc中添加

位置:kernel/msm-3.18/arch/arm64/boot/dts/qcom

qcom,gpioclk {
       compatible = "qcom,gpio_clk";
       clocks = <&clock_gcc clk_gcc_camss_gp0_clk>;
       clock-names = "gpio_clk";
       pinctrl-names = "clk_default", "clk_sleep";
       pinctrl-0 = <&gpio_clk_default>;
       pinctrl-1 = <&gpio_clk_sleep>;
   };

3.配置时钟

位置:kernel/msm-3.18/drivers/clk/msm/clock-gcc-8953.c

在clk_freq_tbl时钟表的 ftb_camss_gp0_clk_src 结构体中添加时钟,

F(10000, xo, 16, 1, 120),

注:10000代表频率,xo代表时钟源,16为div, 120为占空比调节范围最大值

4.添加驱动

说明:平台上已经写好了gpioclk的驱动,并且不开源,只留下.o文件。包括上面3个步骤平台上已经写好了,直接用就可以。但是学习是一个过程,要理解这个是怎么来的。以后遇到没有写出来的就可以根据这个步骤完成了

位置:kernel/msm-3.18/drivers/gpioclk

① Makefile

obj-$(CONFIG_GPIO_CLK)	+= gpio_clk.o

ifeq ($(TARGET_BUILD_VARIANT),user)
$(obj)/gpio_clk.o: $(srctree)/$(obj)/gpio_clk.user FORCE
	cp $(srctree)/$(obj)/gpio_clk.user $(obj)/gpio_clk.o
else
$(obj)/gpio_clk.o: $(srctree)/$(obj)/gpio_clk FORCE
	cp $(srctree)/$(obj)/gpio_clk $(obj)/gpio_clk.o
endif

② Kconfig

config GPIO_CLK
    tristate "gpio clock  driver"
    default n
    help
      This is the main file for gpio clock.

      Say Y here if you have a gpio clock connected to your system.

      If unsure, say N.

      To compile this driver as a module, choose M here.

5.使gpioclk参与编译

①修改Makefile

位置:kernel/msm-3.18/drivers 添加:

obj-y   += gpioclk/

② 修改Kconfig

位置:kernel/msm-3.18/drivers 添加:

source "drivers/gpioclk/Kconfig"

③ 编译进内核

位置:kernel/msm-3.18/arch/arm64/configs/msmcortex_deconfig , 添加

CONFIG_GPIO_CLK=y

注:内核编译完后看选项是否被编译请看:out/target/product/msm8953_64/obj/kernel/msm-3.18/include/generated/autoconf.h

是否#define CONFIG_GPIO_CLK 1

6. 返回安卓根目录,编译内核

make bootimage -j8

注:驱动是否编译进内核看:/sys/module

7.烧写完后,进入/sys/devices/soc/soc:qcom,gpioclk,可以看到如下

8.使能pwm

echo 1 > gpio_clock_enable

就可以看到波形了:

注:占空比默认为60,其范围为(0~120)。频率10khz不变。需要设置时改变占空比就行了!

 

普通gpio口模拟pwm请参考:https://blog.csdn.net/qq_35141454/article/details/101428415

你可能感兴趣的:(【msm8953】带clk的gpio口模拟pwm)