2010-01-06 11:48:49     Why I cannot find my driver file under /dev?

Document created by Aaronwu Employee on Aug 20, 2013
Version 1Show Document
  • View in full screen mode

2010-01-06 11:48:49     Why I cannot find my driver file under /dev?

Jianxi Fu (UNITED STATES)

Message: 84238   

 

Hi, All

 

Could someone do me a favor to check the procedure following?

 

Board: BF537-STAMP

Development Ver. 2009R1

 

Step 1. I wrote a driver stc_led.c used to control the LED on the board (please see at the bottom)

 

Step 2.   docs.blackfin.uclinux.org/doku.php?id=basic_driver_configure_and_build

              Put stc_led.c in linux-2.6.x/drivers/char

 

Step 3. Modify linux-2.6.x/drivers/char/Makefile, add

              obj-$(CONFIG_LED) += stc_led.o

 

Step 4. Modify linux-2.6.x/drivers/char/Kconfig, add

                config LED

                            tristate “Led driver”

                           default y

                            ---help---

 

Step 5 Modify vendors/AnalogDevices/BF537-STAMP/device_table.txt, add

/dev/led0 c 755  0  0  60  0  0  0 -

 

 

Than I use "make menuconfig" also choose Led driver

 

However, when I start the uImage, I cannot find led0 in the dev folder

 

Did I miss anything important?

 

 

 

--------------------------stc_led.c------------------------------

 

#include <linux/module.h>

#include <linux/init.h>

#include <linux/sched.h>

#include <linux/kernel.h>

#include <linux/fs.h>

#include <linux/errno.h> /* error codes */

#include <linux/types.h> /* size_t */

#include <linux/delay.h> /* mdelay() */

#include <asm/uaccess.h> /* copy_to_user() copy_from_usr */

#include <mach/cdefBF537.h>

 

#define LED_MAJOR 61

#define LED_DEVNAME "led"

 

static char * version = "ADSP led driver version 0.9(2008.01.22).\n";

 

void led_set(void)

{

bfin_write_PORTFIO_DIR(0x0FC0);

bfin_write_PORTFIO_SET(0x0FC0);

}

 

void led_clear(void)

{

bfin_write_PORTFIO_DIR(0x0FC0);

bfin_write_PORTFIO_CLEAR(0x0FC0);

}

 

static int led_open(struct inode *inode,struct file *file)

{

/* MOD_INC_USE_COUNT; */

 

return 0;

}

 

static int led_release(struct inode *inode,struct file *file)

{

/* MOD_DEC_USE_COUNT; */

 

return 0;

}

 

static ssize_t led_read(struct file *file,char *buf,size_t count,loff_t *offset)

{

return 0;

}

 

static ssize_t led_write(struct file *file,char *buf,size_t count,loff_t *offset)

{

u8 tmp;

int ret;

 

if(count>1)

  count = 1;

ret = copy_from_user(&tmp,buf,count) ? -EFAULT : count;

if(ret)

{

  if(!tmp)

  {

   led_clear();

  }

  else

  {

   led_set();

  }

}

 

return ret;

}

 

static struct file_operations led_ops =

{

owner: THIS_MODULE,

read: led_read,

write: led_write,

open: led_open,

release: led_release,

};

 

/*

* module init

*/

int __init led_init_module(void)

{

int res;

 

printk(KERN_INFO" %s",version);

 

res = register_chrdev(LED_MAJOR,LED_DEVNAME,&led_ops);

if(res<0)

{

  printk("stc_led.o:unable to get major %d for led device.\n",LED_MAJOR);

  return(res);

}

 

/* init led device */

led_set();

mdelay(100);

led_clear();

mdelay(100);

led_set();

 

return 0;

}

 

/*

* module cleanup

*/

void __exit led_cleanup(void)

{

//int res;

 

/*res = */unregister_chrdev(LED_MAJOR,LED_DEVNAME);

/*if(res<0)

{

  printk("stc_led.o:unable to release major %d for led devide.\n",LED_MAJOR);

}*/

}

 

module_init(led_init_module);

module_exit(led_cleanup);

 

MODULE_DESCRIPTION("ADSP led driver");

QuoteReplyEditDelete

 

 

2010-01-06 13:16:04     Re: Why I cannot find my driver file under /dev?

Mike Frysinger (UNITED STATES)

Message: 84239   

 

if you want the device to appear automatically, you have to create the class devices yourself.  otherwise, use `mknod` and make the device node yourself.

 

if you're writing this driver just to learn about the Blackfin processor, that is one thing ... but if you're trying to make a real driver, you shouldnt be accessing any of these MMRs yourself.  there is a GPIO framework that hides all of the PORT details, and it can even be driven completely from userspace via the GPIO SYSFS interface.

QuoteReplyEditDelete

 

 

2010-01-06 13:34:18     Re: Why I cannot find my driver file under /dev?

Jianxi Fu (UNITED STATES)

Message: 84240   

 

Dear Mike,

 

It works now, the LED can blinking~~

I will try to write a real driver in the future.

However, I learn slowly, step by step.

Anyway, thank you very much for your help~~

 

Best regards

 

Jianxi

Attachments

    Outcomes