IMX LED Driver TP: Difference between revisions

From ArmadeusWiki
No edit summary
 
(One intermediate revision by the same user not shown)
Line 4: Line 4:


== Howto Load/unload modules : "hwmon" module ==
== Howto Load/unload modules : "hwmon" module ==
Load module is quite simple once it is compile an in the rootfs of the apf board.
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". To find all the loadable modules by the kernel in the board type :
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 :
<pre class="apf">
<pre class="apf">
  # find /lib/modules/`uname -r`/kernel -name "*.ko"
  # find /lib/modules/`uname -r`/kernel -name "*.ko"
Line 29: Line 29:
  #
  #
</pre>
</pre>
To list all mod loaded :
<pre class="apf">
# lsmod
Module                  Size  Used by    Not tainted
hwmon                  2356  0
</pre>
To unload it just type :
To unload it just type :
<pre class="apf">
<pre class="apf">
Line 36: Line 43:
TBC
TBC


== Howto Build a simple module and load/unload it : the "Hello World" module ==
== 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 :
 
<pre class="host">
cd <armadeus_directory>/target/linux/modules/
mkdir hello
</pre>
==== Hello.c source file ====
<source lang="c">
#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 */
</source>
==== Makefile file ====
<source lang="text">
# 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
</source>
TBC
== Howto Provide read/write commands to the user though /dev/hello : "Hello World Read Write" module ==
== 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 ==
== Howto Build a register use module : "iMX LED" module ==

Latest revision as of 20:57, 30 March 2009

Page under construction... Construction.png 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