All pastes #950630 Raw Edit

Mine

public text v1 · immutable
·published 2008-03-20 18:49 UTC
rendered paste body
#include <linux/init.h>
#include <linux/module.h>
#include <asm/io.h>
#include <linux/proc_fs.h> 

MODULE_LICENSE("Dual BSD/GPL");


#define SIO_INDEX       0x2E
#define SIO_DATA        0x2F
#define CR30                    0x30
#define GPIO_BANK               0x2A 
#define DEF_BANK_REG    0x07

void openPort(void);
uint readValue(void);

static int __init readgpio_init(void)
{
        openPort();
//      printk(KERN_ALERT "%d \n", readValue() );
        if(create_proc_read_entry("gpio_input", 0, NULL, readgpio_proc, NULL) == 0)
        {
                printk(KERN_ERR "Unable to register \"gpio_input\" proc file\n");
                return -ENOMEM;
        }
	return 0;
}

static int readgpio_proc(char *buffer, char **start, off_t offset, int size, int *eof, void *data)
{
	return readValue();
}

static void __exit readgpio_exit(void) { printk(KERN_ALERT "Unloading GPIO driver"); }

void openPort(void)
{
   outb( 0x87, SIO_INDEX );
   outb( 0x87, SIO_INDEX );
   outb( GPIO_BANK, SIO_INDEX );    //select config reg 2
   outb( 0xFC, SIO_DATA  );	    //set to GPIO instead of game port
   outb( DEF_BANK_REG, SIO_INDEX ); //point to logical dev number register
   outb( DEF_BANK_REG, SIO_DATA  ); //select logical device number 7
   outb( CR30, SIO_INDEX );	    //open config reg CR30
   outb( 0x01, SIO_DATA  );	    //open the logical device
   outb( 0xF0, SIO_INDEX );	    //configuration register 0
   outb( 0xFF, SIO_DATA  );   	    //set to output
   outb( 0xF1, SIO_INDEX );			
}

uint readValue() { return inb( SIO_DATA ) ; }

module_init(readgpio_init);
module_exit(readgpio_exit);