Linux 驅動學習筆記

來源:互聯網
上載者:User

最近用mini2440學習linux驅動,做一下筆記


LED驅動:

static int __init dev_init(void)

在驅動的初始化函數中經常看到,__init 首碼,
這個在下面檔案中定義

file:/include/linux/init.h


/* These macros are used to mark some functions or<br /> * initialized data (doesn't apply to uninitialized data)<br /> * as `initialization' functions. The kernel can take this<br /> * as hint that the function is used only during the initialization<br /> * phase and free up used memory resources after<br /> *<br /> * Usage:<br /> * For functions:<br /> *<br /> * You should add __init immediately before the function name, like:<br /> *<br /> * static void __init initme(int x, int y)<br /> * {<br /> * extern int z; z = x * y;<br /> * }



主要是將這個函數放在init段section中,這樣可以在執行完成後,釋放記憶體。


關於s3c2410_gpio_cfgpin函數,只能瞭解到,設定某個GPIO的功能,但是怎麼實現的沒看明白,好像還用到虛擬位址了,最後也沒有發現是怎麼配置的GPCON寄存器的,

void s3c2410_gpio_cfgpin(unsigned int pin, unsigned int function)<br />{<br />void __iomem *base = S3C24XX_GPIO_BASE(pin);<br />unsigned long mask;<br />unsigned long con;<br />unsigned long flags;<br />if (pin < S3C2410_GPIO_BANKB) {<br />mask = 1 << S3C2410_GPIO_OFFSET(pin);<br />} else {<br />mask = 3 << S3C2410_GPIO_OFFSET(pin)*2;<br />}<br />switch (function) {<br />case S3C2410_GPIO_LEAVE:<br />mask = 0;<br />function = 0;<br />break;<br />case S3C2410_GPIO_INPUT:<br />case S3C2410_GPIO_OUTPUT:<br />case S3C2410_GPIO_SFN2:<br />case S3C2410_GPIO_SFN3:<br />if (pin < S3C2410_GPIO_BANKB) {<br />function -= 1;<br />function &= 1;<br />function <<= S3C2410_GPIO_OFFSET(pin);<br />} else {<br />function &= 3;<br />function <<= S3C2410_GPIO_OFFSET(pin)*2;<br />}<br />}<br />/* modify the specified register wwith IRQs off */<br />local_irq_save(flags);<br />con = __raw_readl(base + 0x00);<br />con &= ~mask;<br />con |= function;<br />__raw_writel(con, base + 0x00);<br />local_irq_restore(flags);<br />}<br />

而且,後面



有個地方講不通:

(這個地方應該是都不滿足
switch
的條件,所以,
function
不改變)

#define
S3C2410_GPIO_LEAVE  
(0xFFFFFFFF)

#define S3C2410_GPIO_INPUT  
(0xFFFFFFF0) 
/*
not available on A */

#define
S3C2410_GPIO_OUTPUT 
(0xFFFFFFF1)

#define
S3C2410_GPIO_IRQ    
(0xFFFFFFF2)  
/* not available for all */

#define
S3C2410_GPIO_SFN2   
(0xFFFFFFF2) 
/* bank A => addr/cs/nand */

#define
S3C2410_GPIO_SFN3   
(0xFFFFFFF3) 
/* not available on A */

 


#define
S3C2410_GPB5_OUTP   
(0x01 << 10)

所以,

s3c2410_gpio_cfgpin(S3C2410_GPB5, S3C2410_GPB5_OUTP);

switch (function)

根本對不上號?

 

s3c2410_gpio_cfgpin(S3C2410_GPB5, S3C2410_GPB5_OUTP);

s3c2410_gpio_cfgpin(37, S3C2410_GPB5_OUTP);

s3c2410_gpio_cfgpin(37,

 0x01 << 10


);

剩下的37怎麼變換出mask,怎麼得到GPCON的地址沒看懂?






這個在
/arch/arm/mach-s3c2410/include/mach/regs-gpio.h
中定義


#define
S3C2410_GPB5        
S3C2410_GPIONO(S3C2410_GPIO_BANKB, 5)


#define
S3C2410_GPB5_INP     (0x00 << 10)


#define
S3C2410_GPB5_OUTP    (0x01 << 10)


#define
S3C2410_GPB5_nXBACK  (0x02 << 10)


 



S3C2410_GPIONO

(S3C2410_GPIO_BANKB
,
5)


 


#define S3C2410_GPIONO

(bank,offset) ((bank) + (offset))


#define
S3C2410_GPIO_BANKA   (32*0)


#define S3C2410_GPIO_BANKB

  
(32*1)

 



可以看一下這篇文章:

http://www.linuxidc.com/Linux/2011-06/37322.htm




相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.