coding-styleraspberry-piembedded-linuxhardware-port

first kernel space driver in -- linux


I was able to control GPIO using mmap system call to control LED operation directly from the user space. Now I want to implement driver in kernel space.

I am trying to write my first kernel space device driver for 16*2 line of LCD in Linux for ARM controller RPi. Now i need to access the GPIO for this purpose.

In AVR i use to access the Port like this.

#define PORTA  *(volatile unsigned char*)0x30

I was reading LLD it tells to use inb() & outb() function to access the i/o port.
http://www.makelinux.net/ldd3/chp-9-sect-2

1> Can we not use #define address of port to access the GPIO ?

2> What is the advantages to use use inb() & outb() functions for controlling the GPIO ?

Please suggest.


Solution

  • 1) the use of defines simplifies your task often. You could, of course, not use define for your port and use this construction literally everywhere you need to access the port. But then you will have to replace the 0x30 everywhere with another address if you change the design of your device, for example, if you decide to connect your LED to port B. Also, it will make your code less readable. Alternatively you could declare a function that will access your port. If such a simple function is declared inline (if your compiler supports inlines) then there is no difference in performance.

    2) the advantage of using inb() and outb() is portability of your program. If this is not an issue, then it is fine to access your port directly.