2010年10月21日 星期四



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

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


5. board initial code:
struct machine_desc in arch/arm/include/asm/mach/arch.h
for example:
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

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,

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 都可以支援。




免責聲明: 本文所載資料僅供參考,並不構成投資建議,