imx6q can驅動理解

2021-06-29 15:06:17 字數 3687 閱讀 8780

//理解imx536的can驅動還是從probe開始吧,2.6版本核心can驅動是歸屬於網路驅動

//所以我得先去把網路驅動幾個重要結構體先找出來吧。前進吧!年輕人。

static

struct

platform_driver flexcan_driver = ,  

.probe = flexcan_probe,  

.remove = flexcan_remove,  

.suspend = flexcan_suspend,  

.resume = flexcan_resume,  

};  

下面看probe

[cpp]view plain

copy

static

intflexcan_probe(

struct

platform_device *pdev)  

return

0;  

}  

probe中主要是呼叫了flexcan_device_alloc,繼續看flexcan_device_alloc

[cpp]view plain

copy

struct

net_device *flexcan_device_alloc(

struct

platform_device *pdev,  

void

(*setup) (

struct

net_device *dev))  

//flexcan指向net尾端,即私有資料結構體起始位址

flexcan = netdev_priv(net);  

memset(flexcan, 0, sizeof

(*flexcan));  

//互斥鎖初始化

mutex_init(&flexcan->mutex);  

//初始化核心定時器

init_timer(&flexcan->timer);  

flexcan->dev = pdev;  

//註冊中斷,對映虛擬記憶體

if(flexcan_device_attach(flexcan))   

//把板級配置檔案中設定的struct flexcan_platform_data中的值,傳遞給flexcan

flexcan_device_default(flexcan);  

//根據can的波特率去算br_presdiv,br_propseg,br_pseg1,br_pseg2這些變數的值

//因為flexcan->bitrate值未確定,所以在我的板上,這個函式不起效果

flexcan_set_bitrate(flexcan, flexcan->bitrate);  

//重新計算波特率,儲存在flexcan

flexcan_update_bitrate(flexcan);  

//array_size作用是取陣列元素個數

num = array_size(flexcan_dev_attr);  

//device_create_file,新增屬性檔案,我的理解最終會設定檔案系統sys目錄下一些裝置屬性檔案

//這些裝置檔案是在呼叫device_create時生成的。device_create這個函式什麼時候呼叫的呢,這個就需要udev

//udev是什麼?udev是裝置管理器,能自動生成裝置節點。

//在dm9000驅動裡不知道為什麼沒看到這個函式?

for(i = 0; i < num; i++)   

}  //上面操作的反向操作

if(i != num)   

//儲存net為裝置私有資料

dev_set_drvdata(&pdev->dev, net);  

return

net;  

}  

flexcan_device_alloc中最重要的幾個函式flexcan_device_attach,flexcan_device_default,flexcan_set_bitratef,lexcan_update_bitrate

下面看看這個函式的**,看它們都幹了什麼?

[cpp]view plain

copy

static

void

flexcan_set_bitrate(

struct

flexcan_device *flexcan, 

intbitrate)  

}  if(!found)   

}  }  

}  if

(found)  else

}  [cpp]view plain

copy

static

void

flexcan_update_bitrate(

struct

flexcan_device *flexcan)  

}  if(!rate)  

return

;  //計算can傳輸速率

//其中br_presdiv,br_propseg,br_pseg1,br_pseg2,這些引數都是在板級配置檔案中設定的

//所以可以實現由使用者自己配置can波特率

div = (flexcan->br_presdiv + 1);  

div *=  

(flexcan->br_propseg + flexcan->br_pseg1 + flexcan->br_pseg2 + 4);  

flexcan->bitrate = (rate + div - 1) / div;  

}  

[cpp]view plain

copy

static

intflexcan_device_attach(

struct

flexcan_device *flexcan)  

ret = -einval;  

if(plat_data)   

if(plat_data->io_reg)   

}  flexcan->clk = clk_get(&(flexcan->dev)->dev, "can_clk"

);  

//如果板級配置檔案中root_clk_id被配置了,can時鐘源變成了root_clk_id

if(plat_data->root_clk_id)   

flexcan->hwmb = (struct

can_hw_mb *)(flexcan->io_base + can_mb_base);  

flexcan->rx_mask = (unsigned int

*)(flexcan->io_base + can_rxmask_base);  

return

0;  

//以後得多學學核心糾錯處理了

plat_err:  

if(flexcan->core_reg)   

no_irq_err:  

if(flexcan->io_base)  

iounmap(flexcan->io_base);  

return

ret;  

}  

imx6q 驅動開發

一 leds驅動 vim imx6q arm2.dts 根節點中新增 leds led5 led6 測試leds cd sys bus platform devices leds leds led5 echo 1 brightness echo 0 brightness 二 lcd驅動 檢視解析度 ...

(imx6)LED驅動筆記

include include include include include include include include include include include define led major 200 主裝置號 define led name led 裝置名字 define ledo...

imx6ul之LCD驅動移植

首先貼上一位大佬的部落格,對lcd有很詳細的描述 在uboot和kernel中,都存在這樣乙個結構體fb videomode 描述lcd的各項引數,結構體 如下 struct fb videomode 其中 display timings 中的 mode name 如果不寫會預設使用native m...