All pastes #27165 Raw Edit

Mine

public c v1 · immutable
#27165 ·published 2005-10-31 19:47 UTC
rendered paste body
/* * PC Engines WRAP(.1C/.1D/.1E/.2B/.2B) Keyboard LED Emulation * Copyright (c) 2005 Shane Spencer <shane@bogomip.com> *//* * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 as published by * the Free Software Foundation. */#include <linux/kernel.h>#include <linux/slab.h>#include <linux/input.h>#include <linux/module.h>#include <linux/init.h>#include <linux/scx200_gpio.h>#define NAME "scx200_wrapled"#define DRIVER_DESC "PC Engines WRAP(.1C/.1D/.1E/.2B/.2B) Keyboard LED Emulation"MODULE_AUTHOR("Shane Spencer <shane@bogomip.com>");MODULE_DESCRIPTION(DRIVER_DESC);MODULE_LICENSE("GPL");static struct input_dev dev;static int open;static int scx200_wrapled_open(struct input_dev *dev){   open++;   return 0;}static void scx200_wrapled_close(struct input_dev *dev){   open--;}/* * Event callback from the input module (the magic). */static int scx200_wrapled_event(struct input_dev *dev, unsigned int type, unsigned int code, int value){   switch (type) {    case EV_LED:      scx200_gpio_set(2, !test_bit(LED_NUML,   dev->led));      scx200_gpio_set(3, !test_bit(LED_CAPSL,   dev->led));      scx200_gpio_set(18, !test_bit(LED_SCROLLL,   dev->led));      return 0;   }   return -1;}static int __init scx200_wrapled_init(void){   if (!scx200_gpio_present())     {        printk(KERN_ERR NAME ": no SCx200 gpio pins available\n");        return -ENODEV;     }   if(scx200_gpio_configure(2, ~0, 0) == 0x00000001 &&      scx200_gpio_configure(3, ~0, 0) == 0x00000001 &&      scx200_gpio_configure(18, ~0, 0) == 0x00000001)     {        printk(KERN_ERR NAME ": SCx200 WRAP LED GPIO Found\n");     }   else     {        printk(KERN_ERR NAME ": SCx200 WRAP LED GPIO Not Found\n");        return -ENODEV;     }   dev.evbit[0] = BIT(EV_KEY) | BIT(EV_LED);   dev.ledbit[0] = BIT(LED_CAPSL) | BIT(LED_NUML) | BIT(LED_SCROLLL);   init_input_dev(&dev);   set_bit(0, dev.keybit);   set_bit(56, dev.keybit);   set_bit(69, dev.keybit);   set_bit(70, dev.keybit);   clear_bit(0, dev.keybit);   dev.private = NULL;   dev.open = scx200_wrapled_open;   dev.close = scx200_wrapled_close;   dev.event = scx200_wrapled_event;   dev.name = "scx200_wrapled";   dev.id.bustype = BUS_HOST;   dev.id.vendor = 0x0001;   dev.id.product = 0x0001;   dev.id.version = 0x0100;   input_register_device(&dev);   printk(KERN_INFO "input: led: %s initialized\n", dev.name);   return 0;}static void __exit scx200_wrapled_exit(void){   input_unregister_device(&dev);   printk(KERN_INFO "input: led: %s deinitialized\n", dev.name);}module_init(scx200_wrapled_init);module_exit(scx200_wrapled_exit);