Skip to contentSkip to conversation

creating a software driver

DISCUSSION Chris Ison 3 participants 3 messages Nov 16, 2002 Sound

lore
Share & tools
lore

Chris Ison

author
#0 lore raw

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

#1 lore raw

Hi Chris,

Quoted 3 lines · Chris Ison

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"?

Quoted 5 lines

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.

#2 lore raw
In reply to Chris Ison

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