2010年10月21日 星期四

寫驅動程式的工作流程

常聽別人說寫驅動程式很簡單,但自己卻偶而才有這種感覺,因此整理至今為止,
在寫驅動程式可能需要注意,檢查的部份,若有新的心得再繼續更新修正與補充。

standard operating procedure(sop), work flow to write a device driver:

hardware
1. power on? reset timing sequence. study device spec, platform cpu/soc spec.
2. bus interface: host and device part, study bus spec
3. clock for device or device interface bus, study bus spec
4. power pin voltage in device datasheet spec?, study device spec

use multimeter(三用電表) to check voltage, current or resistance
use oscilloscope (示波器) to study and check clock timing, signal sequence and timing,
use Logic Analyzer(邏輯分析儀) to study and check bus protocol

software

5. board initial code:
struct machine_desc in arch/arm/include/asm/mach/arch.h
for example:
arch/arm/mach-s3c64xx/mach-smdk6410.c
search for MACHINE_START()
.init_irq for irq initialization
.map_io for memory mapped address space
.init_machine for board initial startup code and some early driver power on

6. gpio setting or multi-function pin, study soc spec, device spec

gpio_request() to reserve our gpio pins to prevent other drivers' disturbance

memory mapped i/o chip select timing setting, study device read/write timing
and SoC memory mapped timing sequence, memory mapped address space
assignment (resource in platform device)

use iotable_init() to define .virtual, .pfn, .length, .type in struct map_desc
irq(interrupt pin) from gpio pin (use gpiolib and resource in platform device)

use gpio_to_irq(), set_irq_handler(), enable platform interrupt vectors
assign platform_driver name to corresponding platform_device

use platform_add_devices() to add platform device drivers

7. device power/reset sequence, study device spec

8. device initial command, study device spec, sample driver reference

9. device register read/write verify, device register interace
(memory mapped i/o chip select setting, bus procotol spec, device init
command)

10. device setting command, study device spec

11. device driver export device node in /dev, information in /sys, /proc

12. make device nodes in /dev, by driver or mknod
check device file major/minor number in ~linux/Documentation/devices.txt

13. library cross compile, setting matched to /dev path?
export CC=/path/to/cross/tools; ./configure --build=x86-linux,
--host=arm-linux

14. application cross compile, set correct link path to library(prefix)
export CC=/path/to/cross/tools; ./configure --build=x86-linux,
--host=arm-linux --with_lib=/path/to/cross/compiled/lib

inspired by jserv: 分享是最好的記憶

希望人人都會寫驅動程式,只要有硬體設備,Linux 都可以支援。

沒有留言:

張貼留言