Linux Sound subsystem development
 help / color / mirror / Atom feed
From: Guenther Sohler <guenther.sohler@newlogic.com>
To: linux-sound@vger.kernel.org
Subject: Re: creating a software driver
Date: Sat, 16 Nov 2002 10:42:39 +0000	[thread overview]
Message-ID: <marc-linux-sound-103744337230076@msgid-missing> (raw)
In-Reply-To: <marc-linux-sound-103742816723431@msgid-missing>

A very tiny template of such a character device driver is

#include <linux/module.h>

#define MY_MOD_MAJOR    253


static int my_mod_release (struct inode *inode, struct file *file);
static int my_mod_open (struct inode *inode, struct file *file);
static int my_mod_ioctl (struct inode *inode, struct file *file,
                         unsigned int cmd, unsigned long arg);



static struct file_operations my_mod_fops = {
  ioctl:my_mod_ioctl,
  open:my_mod_open,
  release:my_mod_release,
};


static struct parport *pp_use;
static unsigned char shadow[3];


static int
my_mod_release (struct inode *inode, struct file *file)
{
  MOD_DEC_USE_COUNT;
  return 0;
}

static int
my_mod_open (struct inode *inode, struct file *file)
{
  MOD_INC_USE_COUNT;
  return 0;
}


static int
my_mod_ioctl (struct inode *inode, struct file *file, unsigned int cmd,
              unsigned long arg)
{
  int byte, bit, val=0, i;
  printk("%d %d\n",cmd,arg);
  return 0;
//or   return -EINVAL;
}



int
init_module (void)
{
  register_chrdev (MY_MOD_MAJOR, "my_mod", &my_mod_fops);
  printk("Init\n");
  return 0;
}

void
cleanup_module (void)
{
  printk("Release\n");
  unregister_chrdev (MY_MOD_MAJOR, "my_mod");
}

I compile this with 

gcc -D__KERNEL__ -I/usr/src/linux/include -Wall -Wstrict-prototypes -O2
-fomit-frame-pointer -fno-strict-aliasing -pipe -fno-strength-reduce 
-m486 -malign-loops=2 -malign-jumps=2 -malign-functions=2 -DCPUX6 -DMODULE  
-c -o  parbit.o parbit.c

I dont know which options are really neccesary but for sure __KERNEL__ and
-MODULE

Dont forget to create a character device with mknod


Please tell me how it works for you


rds Guenther



      parent reply	other threads:[~2002-11-16 10:42 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-11-16  6:21 creating a software driver Chris Ison
2002-11-16  9:29 ` Neale Banks
2002-11-16 10:42 ` Guenther Sohler [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=marc-linux-sound-103744337230076@msgid-missing \
    --to=guenther.sohler@newlogic.com \
    --cc=linux-sound@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox