IMX LED Driver TP

From ArmadeusWiki
Jump to navigationJump to search

Page under construction... Informations on this page are not guaranteed !!

Proposal

The goal of this tutorial is to build from scratch a simple led driver wire on GPIO of the iMX. This document will describes step by step how to implement a such driver

Howto Load/unload modules : "hwmon" module

Loading a module is quite simple once it is compiled and is present in the rootfs of the apf board. All the compiled driver modules are in the "/lib/modules/<kernel version>/kernel" in the apf rootfs. To list all the loadable modules by the kernel in the board type :

 # find /lib/modules/`uname -r`/kernel -name "*.ko"
/lib/modules/2.6.27.13/kernel/sound/arm/snd-imx-alsa-tsc2102.ko
/lib/modules/2.6.27.13/kernel/sound/arm/snd-mx2.ko
/lib/modules/2.6.27.13/kernel/sound/core/snd-page-alloc.ko
/lib/modules/2.6.27.13/kernel/sound/core/snd-timer.ko
/lib/modules/2.6.27.13/kernel/sound/core/snd.ko
/lib/modules/2.6.27.13/kernel/sound/core/snd-pcm.ko
/lib/modules/2.6.27.13/kernel/sound/soundcore.ko
/lib/modules/2.6.27.13/kernel/drivers/spi/tsc2102.ko
/lib/modules/2.6.27.13/kernel/drivers/scsi/scsi_wait_scan.ko
/lib/modules/2.6.27.13/kernel/drivers/hwmon/hwmon.ko
/lib/modules/2.6.27.13/kernel/drivers/input/touchscreen/tsc2102_ts.ko
/lib/modules/2.6.27.13/kernel/drivers/video/backlight/lcd.ko
/lib/modules/2.6.27.13/kernel/drivers/video/backlight/backlight.ko
/lib/modules/2.6.27.13/kernel/drivers/armadeus/max1027/max1027.ko
/lib/modules/2.6.27.13/kernel/drivers/armadeus/backlight/imx_bl.ko

For example, I will load "/lib/modules/2.6.27.13/kernel/drivers/hwmon/hwmon.ko" module :

 # modprobe hwmon
 #

To list all mod loaded :

 # lsmod
Module                  Size  Used by    Not tainted
hwmon                   2356  0 

To unload it just type :

 # rmmod hwmon
 #

TBC

Howto Build a simple char module and load/unload it : the "Hello World" module

The "Hello World" module code is quite simple have only load and unload fonction.

Create required folder and files

Create a hello folder in <armadeus_directory>/target/linux/modules/. On the host computer type :

cd <armadeus_directory>/target/linux/modules/
mkdir hello

Hello.c source file

#include <linux/module.h> /* Default module librairies TBC */
#include <linux/kernel.h>

/* Print "Hello, world\n" with KERN_ALERT level (stdio TBC) */
static int hello_init(void){
      printk(KERN_ALERT "Hello, world\n");
      return 0;
}

/* Print "Goodbye, cruel world\n" with KERN_ALERT level (stdio TBC) */
static void hello_exit(void){
      printk(KERN_ALERT "Goodbye, cruel world\n");
}

module_init(hello_init); /* Set hello_init function as the module init one (called when module load) */
module_exit(hello_exit); /* Set hello_exit function as the module exit one (called when module unload) */

MODULE_LICENSE("GPL"); /* Set the license module */

Makefile file

# Part executed when called from kernel build system:
ifneq ($(KERNELRELEASE),)

obj-$(CONFIG_ARMADEUS_LED_XAV_DRIVER)	+= hello.o

#hello-objs	:= hello.o

# Part executed when called from standard make in this directory:
# (preferably use Makefile in parent directory)
else

ARMADEUS_BASE_DIR=../../../..
include $(ARMADEUS_BASE_DIR)/Makefile.in

KDIR    := $(ARMADEUS_LINUX_DIR)
PWD	:= $(shell pwd)

# Armadeus custom drivers common targets:
include ../Makefile.in

endif

TBC

Howto Provide read/write commands to the user though /dev/hello : "Hello World Read Write" module

Howto Build a register use module : "iMX LED" module