![海思3559A pwm驅(qū)動(dòng)編寫(xiě)記錄_第1頁(yè)](http://file4.renrendoc.com/view/fd3ed827b40cd88bd0e842db7d082ae2/fd3ed827b40cd88bd0e842db7d082ae21.gif)
![海思3559A pwm驅(qū)動(dòng)編寫(xiě)記錄_第2頁(yè)](http://file4.renrendoc.com/view/fd3ed827b40cd88bd0e842db7d082ae2/fd3ed827b40cd88bd0e842db7d082ae22.gif)
![海思3559A pwm驅(qū)動(dòng)編寫(xiě)記錄_第3頁(yè)](http://file4.renrendoc.com/view/fd3ed827b40cd88bd0e842db7d082ae2/fd3ed827b40cd88bd0e842db7d082ae23.gif)
![海思3559A pwm驅(qū)動(dòng)編寫(xiě)記錄_第4頁(yè)](http://file4.renrendoc.com/view/fd3ed827b40cd88bd0e842db7d082ae2/fd3ed827b40cd88bd0e842db7d082ae24.gif)
![海思3559A pwm驅(qū)動(dòng)編寫(xiě)記錄_第5頁(yè)](http://file4.renrendoc.com/view/fd3ed827b40cd88bd0e842db7d082ae2/fd3ed827b40cd88bd0e842db7d082ae25.gif)
版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、由于hisi3559a的內(nèi)核中未包含pwm驅(qū)動(dòng),故需自己編寫(xiě)。.修改Kconfig文件翻開(kāi)XXX/drivers/pwm文件夾(XXX代表內(nèi)核路徑)中的Kconfig文件 增加如下 內(nèi)容config PWM.HISItristate hisi3559a PWM support by zd zjhhelpGeneric PWM framework driver for hisi3559a by zd zjh.這樣在menuconfig中將增加對(duì)應(yīng)的選項(xiàng).修改 makefile翻開(kāi)XXX/drivers/pwm文件夾(XXX代表內(nèi)核路徑)中的Makefile文件增加如下內(nèi)容obj-$(CONFIG
2、_PWM_HISI)+ 二 pwm-hisi.o即根據(jù)menuconfig中是否選擇PWM_HISI來(lái)決定是否編譯我們將要添加的驅(qū)動(dòng)程 序。.編寫(xiě)pwm驅(qū)動(dòng)在XXX/drivers/pwm文件夾中新增pwm-hisi.c文件編寫(xiě)內(nèi)容為:/*Driver for hisi3559a Pulse Width Modulation Controller*Copyright (C) 2021 zjh *Licensed under GPLv2./#include #include compatible = hisilicon,hi-pwm;reg = ;clocks = ;#pwm-cells = ;
3、clock-names = apb_pclk;status =disabled;):pwm2: pwm0 xl80900E0 compatible = hisilicon,hi-pwm;reg = ;clocks = ;#pwm-cells = ;clock-names = apb_pclk;status = disabled;);可以看到,上面的clocks項(xiàng)和時(shí)鐘驅(qū)動(dòng)中修改的內(nèi)容是相關(guān)聯(lián)的。6.應(yīng)用層使用例如(Qt)#include#include#include#include#includeQDebug#includeint exportPwm(unsigned int pwm)(in
4、t fd = -1;std:string sPath;if (pwm 3)(sPath = /sys/class/pwm/pwmchip + std:to_string(pwm) + /export;fd = open(sPath.c_str(), O_WRONLY);if (fd 0) TOC o 1-5 h z (printf(open export failedn);return -1;write(fd, 0,2);close(fd);return 0;elsereturn -1;int configPwm(unsigned int pwm, unsigned int period, u
5、nsigned int duty_cycle)(int fd = 0, len_p = 0, len_d = 0;char buf_p32;char buf_d32;std:string sPath;Ien_p = snprintf(buf_p, sizeof(buf_p), %d, period);Ien_d = snprintf(buf_d, sizeof(buf_d), %d, duty_cycle);if (pwm 3)(sPath = 7sys/class/pwm/pwmchip + std:to_string(pwm) + /pwmO/period;fd = open(sPath.
6、c_str(), O_WRONLY);if (fd 0)(printf(open period failedn);return -1;write(fd,buf_p, len_p);close(fd);sPath=7sys/class/pwm/pwmchip+ std:to_string(pwm) +7pwm0/duty_cycle;fd =open(sPath.c_str(),O_WRONLY); TOC o 1-5 h z if (fd0)printf(open duty_cycle failedn);return -1;write(fd, buf_d, len_d);close(fd);r
7、eturn 0;elsereturn -1;int enablePwm(unsigned int pwm)(int fd = 0;std:string sPath;if (pwm 3)sPath = /sys/class/pwm/pwmchip + std:to_string(pwm) + /pwmO/enable;fd = open(sPath.c_str(),O_WRONLY);if (fd 0)(printf(open enable failedn);return -1;write(fd, 1, 2);close(fd);return 0;elsereturn -1;int disabl
8、ePwm(unsigned int pwm)int fd = 0;std:string sPath;if (pwm 3)(sPath = /sys/class/pwm/pwmchip + std:to_string(pwm) + /pwmO/enable;fd = open(sPath.c_str(),O.WRONLY);if (fd 0)(printf(open enable failedn);return -1;write(fd, 0, 2);close(fd);return 0;)elsereturn -1;void setDefalutLumia(void)(int i = expor
9、tPwm(O);if (i != 0)qDebug() pwm export failed!;configPwm(0, 750, 375);enablePwm(O);void initFanPWM(void)int i = exportPwm(l);if (i != 0)qDebug() pwml export failed!;i = exportPwm(2);if (i != 0)qDebug() #includeinux/io.h#includeinux/module.h#includeinux/of.h#includeinux/of device.h#include#include#in
10、cludeinux/platform_device.h inux/pwm.h inux/slab.h#include#includeinux/spinlock.h inux/time.h/寄存器偏移量#include#include0 x00 0 x04 0 x08 OxOC 0 x10 0 x14 0 x18 BIT(O) BIT(l) BIT(2)#define PWM_CFG0#define PWM_CFG10 x00 0 x04 0 x08 OxOC 0 x10 0 x14 0 x18 BIT(O) BIT(l) BIT(2)#define PWM_CFG2#define PWM_CT
11、RL#define PWM_STATEO#define PWM_STATE1#define PWM_STATE2#define PWM_EN#define PWMJNV#define PWM_KEEP struct hisi_pwm_data /bool has_prescaler_bypass;/bool has_rdy;unsigned int npwm;);struct hisi_pwm_chip struct pwm_chip chip;struct elk *clk;void _iomem *base;spinlock_t ctrljock;const struct hisi_pwm
12、_data *data;);static inline struct hisi_pwm_chip *to_hisi_pwm_chip(struct pwm_chip *chip) (return container_of(chip, struct hisi_pwm_chip, chip);)/讀寄存器static inline u32 hisi_pwm_readl(struct hisi_pwm_chip *chip, unsigned long offset)( return readl(chip-base + offset);)/寫(xiě)寄存器static inline void hisi_pw
13、m_writel(struct hisi_pwm_chip *chip, u32 val, unsigned long offset)( writel(val, chip-base + offset);/配置pwmstatic int hisi_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, int duty_ns, int period_ns)(struct hisi_pwm_chip *hisi_pwm 二 to_hisi_pwm_chip(chip); u32 val = 0;u64 clk_rate = 0; int
14、err;clk_rate = clk_get_rate(hisi_pwm-clk); printk(KERN_CRIT pwm elk rate: %lldn, clk_rate);err = clk_prepare_enable(hisi_pwm-clk); if (err) dev_err(chip-dev, failed to enable PWM clockn); return err;spin_lock(&hisLpwm-ctrl_lock);/val = hisi_pwm_readl(hisi_pwm, PWM_CTRL);/val &二 OxFFFE;/hisi_pwm_writ
15、el(hisi_pwm, val, PWM_CTRL);/val = hisi_pwm_readl(hisi_pwm, PWM_CTRL);/val &二 OxFFFB; /hisLpwm_writel(hisLpwm, val, PWM_CTRL);Ado ( val = hisLpwm_readl(hisi_pwm, PWM_STATE2); printk(KERN_CRIT wait for pwm idle.An);)while(0 x400 = (val & 0 x400);*/if (duty_ns = 1)(hisi_pwm_writel(hisLpwm, duty_ns, PW
16、M_CFG1);printk(KERN_CRIT duty reg have be written.An);)if (period_ns = 2)(hisi_pwm_writel(hisLpwm, period_ns, PWM_CFG0);printk(KERN_CRIT period reg have be written.An);)/hisi_pwm_writel(hisi_pwm, Oxa, PWM_CFG2);printk(KERN_CRIT num reg have be written.An);/val = hisi_pwm_readl(hisi_pwm, PWM_CTRL);/v
17、al &二 OxFFFE;/hisi_pwm_writel(hisi_pwm, val, PWM_CTRL);val = hisi_pwm_readl(hisi_pwm, PWM_CTRL);val |= 0 x05;hisi_pwm_writel(hisi_pwm, val, PWM_CTRL);spin_unlock(&hisi_pwm-ctrl_lock);clk_disable_unprepare(hisLpwm-clk);return 0;)static int hisi_pwm_set_polarity(struct pwm_chip *chip, struct pwm_devic
18、e *pwm, enum pwm_polarity polarity)(struct hisi_pwm_chip *hisi_pwm = to_hisi_pwm_chip(chip);u32 val;int ret;ret = clk_prepare_enable(hisi_pwm-clk);if (ret) dev_err(chip-dev, failed to enable PWM clockn);return ret;spin_lock(&hisi_pwm-ctrl_lock);val = hisLpwm_readl(hisLpwm, PWM_CTRL);if (polarity !=
19、PWM_POLARITY_NORMAL)val |= 0 x02;elseval &二 OxFFFD;hisLpwm_writel(hisi_pwm, val, PWM_CTRL);spin_unlock(&hisi_pwm-ctrlock);clk_disable_unprepare(hisi_pwm-clk);return 0;)static int hisi_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)(struct hisi_pwm_chip *hisi_pwm = to_hisi_pwm_chip(chip);u3
20、2 val;int ret;ret = clk_prepare_enable(hisi_pwm-clk);if (ret) dev_err(chip-dev, failed to enable PWM clockn); return ret;spin_lock(&hisLpwm-ctrl_lock);val = hisi_pwm_readl(hisi_pwm, PWM_CTRL);val |= 0 x05;hisi_pwm_writel(hisi_pwm, val, PWM_CTRL);spin_unlock(&hisi_pwm-ctrl_lock);return 0;)static void
21、 hisi_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)struct hisi_pwm_chip *hisi_pwm = to_hisi_pwm_chip(chip);u32 val;spinjock(&hisi_pwm-ctrl_lock);val = hisi_pwm_readl(hisi_pwm, PWM_CTRL);val &二 OxFFFE;hisLpwm_writel(hisi_pwm, val, PWM_CTRL);spin_unlock(&hisi_pwm-ctrl_lock);clk_disable_un
22、prepare(hisi_pwm-clk); )static const struct pwm_ops hisi_pwm_ops = .config = hisi_pwm_config, ,set_polarity = hisi_pwm_set_polarity, .enable = hisi_pwm_enable, .disable = hisi_pwm_disable, .owner = THIS_MODULE,);static const struct hisi_pwm_data hisi_pwm_data_l = /.has_prescaler_bypass = true, /.has
23、_rdy = true, ,npwm = 1,);static const struct of_device_id hisi_pwm_of_match = patible = hisilicon,hi-pwm, .data = &hisi_pwm_data_l, ();MODULE_DEVICE_TABLE(of, hisi_pwm_of_match);static int hisi_pwm_probe(struct platform_device *pdev) (struct hisi_pwm_chip *pwm;struct resource *res;int ret;const stru
24、ct of_device_id *match;match = of_match_device(hisLpwm_of_match, &pdev-dev);pwm = devm_kzalloc(&pdev-dev, sizeof(*pwm), GFP_KERNEL); if (!pwm)return -ENOMEM;res = platform_get_resource(pdev, IORESOURCE_MEM, 0); pwm-base = devm_ioremap_resource(&pdev-dev, res);if (IS_ERR(pwm-base)return PTR_ERR(pwm-b
25、ase);pwm-clk = devm_clk_get(&pdev-dev, NULL);if (IS_ERR(pwm-clk)return PTR_ERR(pwm-clk);pwm-data = match-data;pwm-chip.dev = &pdev-dev;pwm-chip.ops = &hisi_pwm_ops;pwm-chip.base = -1;pwm-chip.npwm = pwm-data-npwm;pwm-chip.can_sleep = true;/pwm-chip.of_xlate = of_pwm_xlate_with_flags;/pwm-chip.of_pwm
26、_n_cells = 3;spin_lock_init(&pwm-ctrl_lock);ret = pwmchip_add(&pwm-chip);if (ret dev, failed to add PWM chip: %dn, ret); return ret;platform_set_drvdata(pdev, pwm);return 0;/clk_error:/ pwmchip_remove(&pwm-chip);/ return ret;)static int hisi_pwm_remove(struct platform_device *pdev)(struct hisi_pwm_c
27、hip *pwm = p I a tf o r m_g et_d rvd a ta (p d e v);return pwmchip_remove(&pwm-chip);static struct platform_driver hisi_pwm_driver = .driver = .name = hisi-pwm,.of_match_table = hisi_pwm_of_match,).,probe = hisi_pwm_probe,.remove = hisi_pwm_remove,);module_platform_driver(hisLpwm_driver);/ 宏展開(kāi)為驅(qū)動(dòng)入口M
28、ODULE_ALIAS(platform:hisi-pwm);MODULE_AUTHOR(zjh );MODULE_DESCRIPTION(zd hisi3559a PWM driver);MODULE_LICENSE(GPL v2);4.時(shí)鐘驅(qū)動(dòng)修改在hi3559avl00-clock.h最后增加如下定義/ add by zjh/ add by zjh/ add by zjh/ add by zjh/ add by zjh/ add by zjh/ add by zjh/ add by zjh/ add by zjh/ add by zjh/ add by zjh/ add by zjh/
29、add by zjh/ add by zjh/ add by zjh/ add by zjh#define HI3559AV100_SHUB_PWM2_CLK#define HI3559AV100_SHUB_PWM3_CLK#define HI3559AV100_SHUB_PWM6_CLK#define HI3559AV100_SHUB_PWM7_CLK修改clk-hi3559avl00.c文件內(nèi)容add by zjh為修改內(nèi)容/* shub div elk */struct clk_div_table shub_spi_clk_table = 0, 8,1, 4,2, 2;struct cl
30、k_div_table shub_spi4_clk_table = 0, 8,1, 4,2, 2,3, 1;struct clk_div_table shub_uart_div_clk_tableQ = 1, 8,2, 4;struct clk_div_table shub_pwm_clk_table = 0, 64,1, 8,2, 4,3, 2,4, l;/add by zjh struct hisi_divider_clock hi3559avl00_shub_div_clks _initdata = HI3559AV100_SHUB_SPI_SOURCE_CLK, clk_spi_clk
31、, shub_clk, 0, 0 x20, 24, 2, CLK_DIVIDER_ALLOW_ZERO, shub_spi_clk_table, HI3559AV100 SHUB UART DIV CLK, elk uart div elk, shub elk, 0, Oxlc, 28, 2, CLK DIVIDER ALLOW ZERO, shub uart div elk table, HI3559AV100_SHUB_PWM_SOURCE_CLK, clk_pwm_clk, shub_clk, 0, 0 x18, 8, 3, CLK_DIVIDER_ALLOW_ZERO, shub_pw
32、m_clk_table,/ add by zjh );/* shub gate elk */static struct hisi_gate_clock hi3559avl00_shub_gate_clks _initdata = HI3559AV100_SHUB_SPI0_CLK , clk_shub_spiO, clk_spLclk,0, 0 x20, 1, 0, HI3559AV100_SHUB_SPIl_CLK , clk_shub_spil, clk-SpLcIk,0, 0 x20, 5, 0, HI3559AV100_SHUB_SPI2_CLK , clk_shub_spi2, clk_spLclk,0, 0 x20, 9, 0,shu b_u a rt_so u rce_clk, shub_uart_source_clk, shu b_u a rt_source_clk, shu b_u a rt_so u rce_clk, shub_uart_sour
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 山地自行車(chē)生產(chǎn)建設(shè)項(xiàng)目可行性研究報(bào)告
- 2025年正話梅項(xiàng)目投資可行性研究分析報(bào)告
- 2020-2025年中國(guó)提花織物行業(yè)市場(chǎng)運(yùn)營(yíng)現(xiàn)狀及行業(yè)發(fā)展趨勢(shì)報(bào)告
- 間氟苯腈行業(yè)行業(yè)發(fā)展趨勢(shì)及投資戰(zhàn)略研究分析報(bào)告
- 2025年股權(quán)轉(zhuǎn)讓可行性分析報(bào)告
- 仿絲女旗袍行業(yè)市場(chǎng)發(fā)展及發(fā)展趨勢(shì)與投資戰(zhàn)略研究報(bào)告
- 2025-2030年中國(guó)鑄板機(jī)行業(yè)深度研究分析報(bào)告
- 2024-2025年中國(guó)金融系統(tǒng)安防行業(yè)發(fā)展趨勢(shì)預(yù)測(cè)及投資戰(zhàn)略咨詢報(bào)告
- 羅紋平腳褲行業(yè)行業(yè)發(fā)展趨勢(shì)及投資戰(zhàn)略研究分析報(bào)告
- 2025年建筑模板脫模涂料行業(yè)深度研究分析報(bào)告
- 信訪工作課件
- 安全生產(chǎn)的科技創(chuàng)新與成果轉(zhuǎn)化應(yīng)用
- 過(guò)氧乙酸消毒濃度及方法
- 王洪圖黃帝內(nèi)經(jīng)80課時(shí)講稿
- 英語(yǔ)課堂游戲PPT-英語(yǔ)游戲4個(gè)PPT-(切西瓜-打地鼠-開(kāi)火車(chē)-植物大戰(zhàn)僵尸)
- 大學(xué)物理光學(xué)總結(jié)-大學(xué)物理光學(xué)知識(shí)點(diǎn)總結(jié)課件
- 關(guān)于領(lǐng)導(dǎo)干部報(bào)告?zhèn)€人有關(guān)事項(xiàng)的規(guī)定全文
- 個(gè)人借條電子版模板
- 物業(yè)公司特色服務(wù)、日常增值服務(wù)項(xiàng)目供參考
- 創(chuàng)新創(chuàng)業(yè)實(shí)務(wù)PPT全套完整教學(xué)課件
- 工業(yè)企業(yè)電源快速切換裝置設(shè)計(jì)配置導(dǎo)則
評(píng)論
0/150
提交評(píng)論