LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer
User Name
Password
Linux - Embedded & Single-board computer This forum is for the discussion of Linux on both embedded devices and single-board computers (such as the Raspberry Pi, BeagleBoard and PandaBoard). Discussions involving Arduino, plug computers and other micro-controller like devices are also welcome.

Notices


Reply
  Search this Thread
Old 10-20-2011, 10:01 PM   #1
icemetal
LQ Newbie
 
Registered: Oct 2011
Posts: 8

Rep: Reputation: Disabled
Post Understanding Linux driver


I will like to understand how this driver works , can anyone put comments or send me to a site that would explain most of this commands

Code:
#include <linux/miscdevice.h>
#include <linux/delay.h>
#include <asm/irq.h>
#include <mach/regs-gpio.h>
#include <mach/hardware.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/mm.h>
#include <linux/fs.h>
#include <linux/types.h>
#include <linux/delay.h>
#include <linux/moduleparam.h>
#include <linux/slab.h>
#include <linux/errno.h>
#include <linux/ioctl.h>
#include <linux/cdev.h>
#include <linux/string.h>
#include <linux/list.h>
#include <linux/pci.h>
#include <linux/gpio.h>
#include <asm/uaccess.h>
#include <asm/atomic.h>
#include <asm/unistd.h>


#define DEVICE_NAME "leds"

static unsigned long led_table [] = {
  S3C2410_GPB(5),
  S3C2410_GPB(6),
  S3C2410_GPB(7),
  S3C2410_GPB(8),
};

static unsigned int led_cfg_table [] = {
  S3C2410_GPIO_OUTPUT,
  S3C2410_GPIO_OUTPUT,
  S3C2410_GPIO_OUTPUT,
  S3C2410_GPIO_OUTPUT,
};

static int sbc2440_leds_ioctl(
  struct inode *inode, 
  struct file *file, 
  unsigned int cmd, 
  unsigned long arg)
{
  switch(cmd) {
  case 0:
  case 1:
    if (arg > 4) {
      return -EINVAL;
    }
    s3c2410_gpio_setpin(led_table[arg], !cmd);
    return 0;
  default:
    return -EINVAL;
  }
}

static struct file_operations dev_fops = {
  .owner  =  THIS_MODULE,
  .ioctl  =  sbc2440_leds_ioctl,
};

static struct miscdevice misc = {
  .minor = MISC_DYNAMIC_MINOR,
  .name = DEVICE_NAME,
  .fops = &dev_fops,
};

static int __init dev_init(void)
{
  int ret;

  int i;
  
  for (i = 0; i < 4; i++) {
    s3c2410_gpio_cfgpin(led_table[i], led_cfg_table[i]);
    s3c2410_gpio_setpin(led_table[i], 0);
  }

  ret = misc_register(&misc);

  printk (DEVICE_NAME"\tinitialized\n");

  return ret;
}

static void __exit dev_exit(void)
{
  misc_deregister(&misc);
}

module_init(dev_init);
module_exit(dev_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("FriendlyARM Inc.");
 
Old 10-21-2011, 01:00 AM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,398
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
See Linux Device Drivers, 3rd Edition.

--- rod
 
Old 10-21-2011, 01:09 AM   #3
icemetal
LQ Newbie
 
Registered: Oct 2011
Posts: 8

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by theNbomr View Post
I did and it does not talk about GPIO
 
Old 10-21-2011, 05:58 AM   #4
venkatganesh
LQ Newbie
 
Registered: Sep 2011
Posts: 11

Rep: Reputation: Disabled
i am beginner for fedro15 and how to install rtlinux and use modules
 
Old 10-21-2011, 09:06 AM   #5
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,398
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
GPIO is generally very platform-specific. It should be documented by your hardware vendor.

--- rod.
 
Old 10-21-2011, 09:49 AM   #6
icemetal
LQ Newbie
 
Registered: Oct 2011
Posts: 8

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by theNbomr View Post
GPIO is generally very platform-specific. It should be documented by your hardware vendor.

--- rod.
no is not, you can activate the GPIO in the kernel and use command like:

echo "1" > gpio32/value
echo "0" > gpio32/value

to turn on and off an led on the GPIO line.
 
Old 11-17-2011, 07:26 PM   #7
formiaczek
LQ Newbie
 
Registered: Nov 2011
Posts: 8

Rep: Reputation: 0
Quote:
Originally Posted by icemetal View Post
no is not, you can activate the GPIO in the kernel and use command like:

echo "1" > gpio32/value
echo "0" > gpio32/value

to turn on and off an led on the GPIO line.
In fact - it is platform specific (although GPIO is very similar, like a standard in most HW implementations, only specific / small details would differ) but this is why you have drivers.

Above code seems to be a driver to interact with LEDs connected to some of SoC gpio pins.
Code:
static int sbc2440_leds_ioctl(
  struct inode *inode, 
  struct file *file, 
  unsigned int cmd, 
  unsigned long arg)
is the implementation of a code that turns on or of (depending on cmd being true or false) an LED indexed by 'arg'.

Code:
static int __init dev_init(void)
is used to turn them of on a module load (init) and to set up a configuration*.
(configuration of GPIO pins that these LEDs are connected to - GPIOs can be configured to be either input (if used e.g. for switches / buttons etc) or as OUTPUT (if used to control something, e.g. an LED).

Last edited by formiaczek; 11-17-2011 at 07:36 PM. Reason: forgot to put the description
 
Old 11-17-2011, 07:48 PM   #8
icemetal
LQ Newbie
 
Registered: Oct 2011
Posts: 8

Original Poster
Rep: Reputation: Disabled
I figure how that driver works, but that driver is very limited to that chip, so I enable the standard gpio libraries in linux, so my c code would work in any ARM32 processor that has linux in it(with the gpio in the kernel enable), I found this couple of pages very useful, but thanks formiaczek for taking the time to explain that part of the code.

http://blog.makezine.com/archive/200...gle-board.html

http://www.avrfreaks.net/wiki/index....ion:Linux/GPIO

Last edited by icemetal; 11-17-2011 at 07:59 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Help understanding driver management in Slackware as compared to Windows. Laxman_prodigy Slackware 11 08-15-2011 10:05 PM
Need an understanding on Bluetooth driver gtirtha Linux - Software 2 03-10-2011 06:50 AM
Need help understanding how a device driver interacts with user space programs AustinMarton Linux - General 1 11-21-2008 05:29 AM
understanding how to compile driver pjremy Linux - Newbie 4 11-29-2007 11:37 PM
understanding linux jordyberg Linux - Newbie 5 11-22-2007 07:21 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer

All times are GMT -5. The time now is 04:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration