How to write Platform Devices and Drivers with FPGA via GPMC

Post on 20-Aug-2015

4.783 views 11 download

Transcript of How to write Platform Devices and Drivers with FPGA via GPMC

How to write Platform Devices and Drivers with FPGA via GPMC

Bo-Yi Wu

2011.06.15

http://blog.wu-boy.com

What’s GPMC

• 全名 General-Purpose Memory Controller• the device unified memory controller (UMC)

dedicated to interfacing external memory devices.– NAND Flash– NOR Flash– FPGA (*)

• 如果要更深入研究,請參考 TI 線上 Documentation

寫 GPMC Drive 跟 FPGA 溝通前

必須先瞭解什麼是 Platform Devices 和 Platform Drivers

撰寫 Driver Model 事先預備 Porting Drivers to New Driver Model

• Driver Binding• Bus Types• Device Classes• Basic Device Structure• Managed Device Resource• Device Drivers• Device Interfaces• Platform Devices and Drivers

Platform 架構• 參考 <linux/platform_device.h> 來瞭解 dri

ver model 如何跟 platform bus 溝通• 用在 system-on-chip processors 或者是一

些 "legacy" PC interconnects

Platform devices

• 請指定一個名稱用來 Driver Binding ,以及定義該 Devices 需要用到的 addresses 和 IRQs.

struct platform_device {const char *name;u32 id;struct device dev;u32 num_resources;struct resource *resource;

};

Platform drivers

• Platform drivers 走 Driver Model 標準規範,提供 probe 及 remove method ,它們提供 power 管理及關閉提醒等標準

struct platform_driver {int (*probe)(struct platform_device *);int (*remove)(struct platform_device *);void (*shutdown)(struct platform_device *);int (*suspend)(struct platform_device *, pm_message_t state);int (*suspend_late)(struct platform_device *, pm_message_t state);int (*resume_early)(struct platform_device *);int (*resume)(struct platform_device *);struct device_driver driver;

};

• Probe 用來偵測特定 Hardware 是否存在,及使用該裝置資源 (clocks 和 device platform_data)

• 透過底下函式來註冊 Driver– int platform_driver_register(struct platform_driv

er *drv);

• 過去 Legacy Driver 並不會完全遵守標準 driver model ,這些 driver 會去註冊自己的 platform device ,而不是讓系統來完成註冊

裝置初始化• 在大多數的 Platform 設備都必須先註冊 P

latform Device– 定義 platform_data, resource, 共有多少個 re

source 等等– platform_device_register– platform_add_devices

Device Naming 和 Driver Binding

• platform_device.dev.bus_id 是一個 device id 分為兩個 component:– platform_device.name 用來跟 Driver match– platform_device.id 裝置編號順序 ( 例如假設有

支援多個 NAND 或 NOR Flash) ,如果設定為 -1 表示為獨一無二的裝置

Driver binding

• 在 Driver Core 裡面透過 probe 自動匹對– 利用 Device Name and ID 去 match

• name/id: gpmc_bus.1 或 gpmc_bus

board-omap3evm

GPMC Device Init

Match Driver name

GPMC Driver Init

GPMC Address IRQ

GPMC Clock andChip Select Define

GPMC support functions

• gpmc_cs_read_reg

• gpmc_cs_write_reg

• Please referrer arch/arm/mach-omap2/gpmc.c

GPMC Address Mapping

• Supported Devices– .GPMC_CONFIG1_i[11:10]

• Access Size Adaptation and Device Width– .GPMC_CONFIG1_i[13:12]

Timing Setting

上面兩張設定如果設定正確,就可以正確看到波形,如果設定錯誤,

請準備接收 Kernel Panic

結論• Platform Device 和 Platform Driver 區別?• GPMC Config_[1-7] 設定方式及規範• 實際參考 NAND Driver 程式