Linux Sound subsystem development
 help / color / mirror / Atom feed
* creating a software driver
@ 2002-11-16  6:21 Chris Ison
  2002-11-16  9:29 ` Neale Banks
  2002-11-16 10:42 ` Guenther Sohler
  0 siblings, 2 replies; 3+ messages in thread
From: Chris Ison @ 2002-11-16  6:21 UTC (permalink / raw)
  To: linux-sound

does anyone know where I can get docs for creating a kernel level
software only driver for linux. The only docs anf howto's I can find
just have a simple hello world example.

A pointer to some software only module source in the linux kernel would
be acceptable, but so far have only found pci hardware drivers.

The aim is to create a gpl's software midi driver so I can use/create
midi editors/players and such.


Thank you in advance.

Chris Ison

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: creating a software driver
  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
  1 sibling, 0 replies; 3+ messages in thread
From: Neale Banks @ 2002-11-16  9:29 UTC (permalink / raw)
  To: linux-sound

Hi Chris,

On Sat, 16 Nov 2002, Chris Ison wrote:

> does anyone know where I can get docs for creating a kernel level
> software only driver for linux. The only docs anf howto's I can find
> just have a simple hello world example.

Have you looked in the O'Reilly book "Writing Linux Device Drivers"?

> A pointer to some software only module source in the linux kernel would
> be acceptable, but so far have only found pci hardware drivers.
> 
> The aim is to create a gpl's software midi driver so I can use/create
> midi editors/players and such.

Ah, maybe the alsa virmidi driver would be a helpful start?

BTW, timidity is supposed to be able to operate as an "ALSA Client" -
which looked hopeful for my Toshi with ALi5451 (has synth, but no Linux
support :-( ) but I couldn't get this to work.  What do your plans include
that wouldn't be done by getting timidity working as an ALSA client?

Regards,
Neale.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: creating a software driver
  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
  1 sibling, 0 replies; 3+ messages in thread
From: Guenther Sohler @ 2002-11-16 10:42 UTC (permalink / raw)
  To: linux-sound

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



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2002-11-16 10:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox