Archive for December, 2011

Linux 的 I2C 总线驱动模型

Thursday, December 29th, 2011

Linux 的I2C 总线驱动架构
Bus Driver vs. Device Driver
Linux 中I2C 驱动分为两个部分,总线(BUS)和设备(DEVICE)。我把他们分别比喻为铁路和列车,相当的贴切啊!
1. 总线驱动

总线驱动是为系统中每个I2C 总线增加相应的读写方法,也包括I2C总线控制器的初始化等,但是总线驱动只提供读写函数,本身不会进行任何的通讯,因为它并不知道设备是否真正存在。这样设计也是为了减小SOC芯片驱动和外围设备驱动的耦合性。

1.2. 设备驱动

设备驱动则是与挂在I2C 总线上的具体的设备通讯的驱动。通过I2C总线驱动提供的函数,不同SOC的I2C总线控制器的差异对设备驱动透明。

在系统开机时,首先装载的是I2C总线驱动。一个总线驱动用于支持一条特定的I2C总线的读写。一个总线驱动通常需要两个模块,一个struct i2c_adapter 和一个struct i2c_algorithm 来描述。
via

Compiling directly into a kernel vs. modules

Saturday, December 10th, 2011

You have two options for adding functionality to the kernel: building functions into the kernel (making a monolithic kernel) or adding them as modules.

Monolithic kernels:

Building a function into the kernel directly ensures that that function will be available at all times. The downside is that it makes your kernel bigger, increasing boot time, and ultimately using that much more memory to hold the kernel. If you are compiling a kernel to fit on a floppy so that you can boot Linux off a rescue floppy, space will become an issue.

Modules:

Building a function as a module allows that function to be loaded into memory as needed and unloaded when it is no longer needed. This helps keep your kernel small. It is very useful if, say, you are swapping hardware in and out of your system frequently. You could compile support for a variety of, say, sound cards as modules, and your Linux system will theoretically only load the driver that is appropriate for the hardware setup at the time.

Another benefit of building functions as modules is that parameters can be passed to the modules which can be useful in debugging your system if problems occur.

There are some considerations to be made when deciding if a kernel function should be modularized. A small performance penalty is paid as it takes a little time to get the module loaded and unloaded. There are some functions that are needed at boot time and these cannot be compiled as modules — they need to be present in the kernel so your system can be loaded. For example, ext2/ext3/reiserfs file system support needs to be built into the kernel so that your partitions can be read, as you need to be able to read the filesystem to load modules. In my case, if I have PCMCIA support built into the kernel, then metworking works. If PCMCIA support is modularized, networking fails to start, probably because the PCMCIA support needs to be available very early in the boot process to set up networking.
via Gentoo Forums