^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * NetWinder Button Driver-
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) Alex Holden <alex@linuxhacker.org> 1998, 1999.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/sched/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/time.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/miscdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <asm/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <asm/mach-types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define __NWBUTTON_C /* Tell the header file who we are */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include "nwbutton.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) static void button_sequence_finished(struct timer_list *unused);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) static int button_press_count; /* The count of button presses */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) /* Times for the end of a sequence */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) static DEFINE_TIMER(button_timer, button_sequence_finished);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) static DECLARE_WAIT_QUEUE_HEAD(button_wait_queue); /* Used for blocking read */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) static char button_output_buffer[32]; /* Stores data to write out of device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) static int bcount; /* The number of bytes in the buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) static int bdelay = BUTTON_DELAY; /* The delay, in jiffies */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) static struct button_callback button_callback_list[32]; /* The callback list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) static int callback_count; /* The number of callbacks registered */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) static int reboot_count = NUM_PRESSES_REBOOT; /* Number of presses to reboot */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * This function is called by other drivers to register a callback function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * to be called when a particular number of button presses occurs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * The callback list is a static array of 32 entries (I somehow doubt many
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * people are ever going to want to register more than 32 different actions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * to be performed by the kernel on different numbers of button presses ;).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * However, if an attempt to register a 33rd entry (perhaps a stuck loop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * somewhere registering the same entry over and over?) it will fail to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * do so and return -ENOMEM. If an attempt is made to register a null pointer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * it will fail to do so and return -EINVAL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * Because callbacks can be unregistered at random the list can become
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * fragmented, so we need to search through the list until we find the first
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * free entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * FIXME: Has anyone spotted any locking functions int his code recently ??
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) int button_add_callback (void (*callback) (void), int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) int lp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) if (callback_count == 32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) if (!callback) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) callback_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) for (; (button_callback_list [lp].callback); lp++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) button_callback_list [lp].callback = callback;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) button_callback_list [lp].count = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) * This function is called by other drivers to deregister a callback function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) * If you attempt to unregister a callback which does not exist, it will fail
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * with -EINVAL. If there is more than one entry with the same address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * because it searches the list from end to beginning, it will unregister the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * last one to be registered first (FILO- First In Last Out).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * Note that this is not necessarily true if the entries are not submitted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * at the same time, because another driver could have unregistered a callback
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) * between the submissions creating a gap earlier in the list, which would
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) * be filled first at submission time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) int button_del_callback (void (*callback) (void))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) int lp = 31;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) if (!callback) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) while (lp >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) if ((button_callback_list [lp].callback) == callback) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) button_callback_list [lp].callback = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) button_callback_list [lp].count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) callback_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) lp--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) * This function is called by button_sequence_finished to search through the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) * list of callback functions, and call any of them whose count argument
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) * matches the current count of button presses. It starts at the beginning
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) * of the list and works up to the end. It will refuse to follow a null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) * pointer (which should never happen anyway).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) static void button_consume_callbacks (int bpcount)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) int lp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) for (; lp <= 31; lp++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) if ((button_callback_list [lp].count) == bpcount) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) if (button_callback_list [lp].callback) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) button_callback_list[lp].callback();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) * This function is called when the button_timer times out.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) * ie. When you don't press the button for bdelay jiffies, this is taken to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) * mean you have ended the sequence of key presses, and this function is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) * called to wind things up (write the press_count out to /dev/button, call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) * any matching registered function callbacks, initiate reboot, etc.).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) static void button_sequence_finished(struct timer_list *unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) if (IS_ENABLED(CONFIG_NWBUTTON_REBOOT) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) button_press_count == reboot_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) kill_cad_pid(SIGINT, 1); /* Ask init to reboot us */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) button_consume_callbacks (button_press_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) bcount = sprintf (button_output_buffer, "%d\n", button_press_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) button_press_count = 0; /* Reset the button press counter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) wake_up_interruptible (&button_wait_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) * This handler is called when the orange button is pressed (GPIO 10 of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) * SuperIO chip, which maps to logical IRQ 26). If the press_count is 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) * this is the first press, so it starts a timer and increments the counter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) * If it is higher than 0, it deletes the old timer, starts a new one, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) * increments the counter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) static irqreturn_t button_handler (int irq, void *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) button_press_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) mod_timer(&button_timer, jiffies + bdelay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) * This function is called when a user space program attempts to read
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) * /dev/nwbutton. It puts the device to sleep on the wait queue until
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) * button_sequence_finished writes some data to the buffer and flushes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) * the queue, at which point it writes the data out to the device and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) * returns the number of characters it has written. This function is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) * reentrant, so that many processes can be attempting to read from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) * device at any one time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) static int button_read (struct file *filp, char __user *buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) DEFINE_WAIT(wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) prepare_to_wait(&button_wait_queue, &wait, TASK_INTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) schedule();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) finish_wait(&button_wait_queue, &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) return (copy_to_user (buffer, &button_output_buffer, bcount))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) ? -EFAULT : bcount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) * This structure is the file operations structure, which specifies what
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) * callbacks functions the kernel should call when a user mode process
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) * attempts to perform these operations on the device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) static const struct file_operations button_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) .read = button_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) .llseek = noop_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) * This structure is the misc device structure, which specifies the minor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) * device number (158 in this case), the name of the device (for /proc/misc),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) * and the address of the above file operations structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) static struct miscdevice button_misc_device = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) BUTTON_MINOR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) "nwbutton",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) &button_fops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) * This function is called to initialise the driver, either from misc.c at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) * bootup if the driver is compiled into the kernel, or from init_module
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) * below at module insert time. It attempts to register the device node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) * and the IRQ and fails with a warning message if either fails, though
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) * neither ever should because the device number and IRQ are unique to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) * this driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) static int __init nwbutton_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) if (!machine_is_netwinder())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) printk (KERN_INFO "NetWinder Button Driver Version %s (C) Alex Holden "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) "<alex@linuxhacker.org> 1998.\n", VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) if (misc_register (&button_misc_device)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) printk (KERN_WARNING "nwbutton: Couldn't register device 10, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) "%d.\n", BUTTON_MINOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) if (request_irq (IRQ_NETWINDER_BUTTON, button_handler, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) "nwbutton", NULL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) printk (KERN_WARNING "nwbutton: IRQ %d is not free.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) IRQ_NETWINDER_BUTTON);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) misc_deregister (&button_misc_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) static void __exit nwbutton_exit (void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) free_irq (IRQ_NETWINDER_BUTTON, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) misc_deregister (&button_misc_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) MODULE_AUTHOR("Alex Holden");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) module_init(nwbutton_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) module_exit(nwbutton_exit);