/*
|
/*
|
* linux/arch/arm/drivers/char/mouse.c
|
* linux/arch/arm/drivers/char/mouse.c
|
*
|
*
|
* Generic misc open routine by Johan Myreen
|
* Generic misc open routine by Johan Myreen
|
*
|
*
|
* Based on code from Linus
|
* Based on code from Linus
|
*
|
*
|
* Teemu Rantanen's Microsoft Busmouse support and Derrick Cole's
|
* Teemu Rantanen's Microsoft Busmouse support and Derrick Cole's
|
* changes incorporated into 0.97pl4
|
* changes incorporated into 0.97pl4
|
* by Peter Cervasio (pete%q106fm.uucp@wupost.wustl.edu) (08SEP92)
|
* by Peter Cervasio (pete%q106fm.uucp@wupost.wustl.edu) (08SEP92)
|
* See busmouse.c for particulars.
|
* See busmouse.c for particulars.
|
*
|
*
|
* Made things a lot mode modular - easy to compile in just one or two
|
* Made things a lot mode modular - easy to compile in just one or two
|
* of the misc drivers, as they are now completely independent. Linus.
|
* of the misc drivers, as they are now completely independent. Linus.
|
*
|
*
|
* Support for loadable modules. 8-Sep-95 Philip Blundell <pjb27@cam.ac.uk>
|
* Support for loadable modules. 8-Sep-95 Philip Blundell <pjb27@cam.ac.uk>
|
*
|
*
|
* Fixed a failing symbol register to free the device registration
|
* Fixed a failing symbol register to free the device registration
|
* Alan Cox <alan@lxorguk.ukuu.org.uk> 21-Jan-96
|
* Alan Cox <alan@lxorguk.ukuu.org.uk> 21-Jan-96
|
*
|
*
|
* Dynamic minors and /proc/mice by Alessandro Rubini. 26-Mar-96
|
* Dynamic minors and /proc/mice by Alessandro Rubini. 26-Mar-96
|
*
|
*
|
* Renamed to misc and miscdevice to be more accurate. Alan Cox 26-Mar-96
|
* Renamed to misc and miscdevice to be more accurate. Alan Cox 26-Mar-96
|
*
|
*
|
* Handling of mouse minor numbers for kerneld:
|
* Handling of mouse minor numbers for kerneld:
|
* Idea by Jacques Gelinas <jack@solucorp.qc.ca>,
|
* Idea by Jacques Gelinas <jack@solucorp.qc.ca>,
|
* adapted by Bjorn Ekwall <bj0rn@blox.se>
|
* adapted by Bjorn Ekwall <bj0rn@blox.se>
|
* corrected by Alan Cox <alan@lxorguk.ukuu.org.uk>
|
* corrected by Alan Cox <alan@lxorguk.ukuu.org.uk>
|
*/
|
*/
|
|
|
#include <linux/config.h>
|
#include <linux/config.h>
|
#include <linux/module.h>
|
#include <linux/module.h>
|
|
|
#include <linux/fs.h>
|
#include <linux/fs.h>
|
#include <linux/errno.h>
|
#include <linux/errno.h>
|
#include <linux/miscdevice.h>
|
#include <linux/miscdevice.h>
|
#include <linux/kernel.h>
|
#include <linux/kernel.h>
|
#include <linux/major.h>
|
#include <linux/major.h>
|
#include <linux/malloc.h>
|
#include <linux/malloc.h>
|
#include <linux/proc_fs.h>
|
#include <linux/proc_fs.h>
|
#include <linux/stat.h>
|
#include <linux/stat.h>
|
|
|
#include <linux/tty.h> /* needed by selection.h */
|
#include <linux/tty.h> /* needed by selection.h */
|
#include "vt_kern.h"
|
#include "vt_kern.h"
|
#include "selection.h" /* export its symbols */
|
#include "selection.h" /* export its symbols */
|
#ifdef CONFIG_KERNELD
|
#ifdef CONFIG_KERNELD
|
#include <linux/kerneld.h>
|
#include <linux/kerneld.h>
|
#endif
|
#endif
|
|
|
#include "mouse.h"
|
#include "mouse.h"
|
|
|
/*
|
/*
|
* Head entry for the doubly linked miscdevice list
|
* Head entry for the doubly linked miscdevice list
|
*/
|
*/
|
static struct miscdevice misc_list = { 0, "head", NULL, &misc_list, &misc_list };
|
static struct miscdevice misc_list = { 0, "head", NULL, &misc_list, &misc_list };
|
|
|
/*
|
/*
|
* Assigned numbers, used for dynamic minors
|
* Assigned numbers, used for dynamic minors
|
*/
|
*/
|
#define DYNAMIC_MINORS 64 /* like dynamic majors used to do */
|
#define DYNAMIC_MINORS 64 /* like dynamic majors used to do */
|
static unsigned char misc_minors[DYNAMIC_MINORS / 8];
|
static unsigned char misc_minors[DYNAMIC_MINORS / 8];
|
|
|
#ifndef MODULE
|
#ifndef MODULE
|
extern void watchdog_init(void);
|
extern void watchdog_init(void);
|
extern int arch_mouse_init(void);
|
extern int arch_mouse_init(void);
|
extern int con_get_info(int *mode, int *shift, int *col, int *row,
|
extern int con_get_info(int *mode, int *shift, int *col, int *row,
|
struct tty_struct **tty);
|
struct tty_struct **tty);
|
|
|
#ifdef CONFIG_PROC_FS
|
#ifdef CONFIG_PROC_FS
|
static int proc_misc_read(char *buf, char **start, off_t offset, int len, int unused)
|
static int proc_misc_read(char *buf, char **start, off_t offset, int len, int unused)
|
{
|
{
|
struct miscdevice *p;
|
struct miscdevice *p;
|
|
|
len=0;
|
len=0;
|
for (p = misc_list.next; p != &misc_list; p = p->next)
|
for (p = misc_list.next; p != &misc_list; p = p->next)
|
len += sprintf(buf+len, "%3i %s\n",p->minor, p->name ?: "");
|
len += sprintf(buf+len, "%3i %s\n",p->minor, p->name ?: "");
|
return len;
|
return len;
|
}
|
}
|
|
|
#endif /* PROC_FS */
|
#endif /* PROC_FS */
|
#endif /* !MODULE */
|
#endif /* !MODULE */
|
|
|
static int misc_open(struct inode * inode, struct file * file)
|
static int misc_open(struct inode * inode, struct file * file)
|
{
|
{
|
int minor = MINOR(inode->i_rdev);
|
int minor = MINOR(inode->i_rdev);
|
struct miscdevice *c = misc_list.next;
|
struct miscdevice *c = misc_list.next;
|
file->f_op = NULL;
|
file->f_op = NULL;
|
|
|
while ((c != &misc_list) && (c->minor != minor))
|
while ((c != &misc_list) && (c->minor != minor))
|
c = c->next;
|
c = c->next;
|
if (c == &misc_list) {
|
if (c == &misc_list) {
|
#ifdef CONFIG_KERNELD
|
#ifdef CONFIG_KERNELD
|
char modname[20];
|
char modname[20];
|
sprintf(modname, "char-major-%d-%d", MISC_MAJOR, minor);
|
sprintf(modname, "char-major-%d-%d", MISC_MAJOR, minor);
|
request_module(modname);
|
request_module(modname);
|
c = misc_list.next;
|
c = misc_list.next;
|
while ((c != &misc_list) && (c->minor != minor))
|
while ((c != &misc_list) && (c->minor != minor))
|
c = c->next;
|
c = c->next;
|
if (c == &misc_list)
|
if (c == &misc_list)
|
#endif
|
#endif
|
return -ENODEV;
|
return -ENODEV;
|
}
|
}
|
|
|
if ((file->f_op = c->fops))
|
if ((file->f_op = c->fops))
|
return file->f_op->open(inode,file);
|
return file->f_op->open(inode,file);
|
else
|
else
|
return -ENODEV;
|
return -ENODEV;
|
}
|
}
|
|
|
static struct file_operations misc_fops = {
|
static struct file_operations misc_fops = {
|
NULL, /* seek */
|
NULL, /* seek */
|
NULL, /* read */
|
NULL, /* read */
|
NULL, /* write */
|
NULL, /* write */
|
NULL, /* readdir */
|
NULL, /* readdir */
|
NULL, /* select */
|
NULL, /* select */
|
NULL, /* ioctl */
|
NULL, /* ioctl */
|
NULL, /* mmap */
|
NULL, /* mmap */
|
misc_open,
|
misc_open,
|
NULL /* release */
|
NULL /* release */
|
};
|
};
|
|
|
int misc_register(struct miscdevice * misc)
|
int misc_register(struct miscdevice * misc)
|
{
|
{
|
if (misc->next || misc->prev)
|
if (misc->next || misc->prev)
|
return -EBUSY;
|
return -EBUSY;
|
if (misc->minor == MISC_DYNAMIC_MINOR) {
|
if (misc->minor == MISC_DYNAMIC_MINOR) {
|
int i = DYNAMIC_MINORS;
|
int i = DYNAMIC_MINORS;
|
while (--i >= 0)
|
while (--i >= 0)
|
if ( (misc_minors[i>>3] & (1 << (i&7))) == 0)
|
if ( (misc_minors[i>>3] & (1 << (i&7))) == 0)
|
break;
|
break;
|
if (i<0) return -EBUSY;
|
if (i<0) return -EBUSY;
|
misc->minor = i;
|
misc->minor = i;
|
}
|
}
|
if (misc->minor < DYNAMIC_MINORS)
|
if (misc->minor < DYNAMIC_MINORS)
|
misc_minors[misc->minor >> 3] |= 1 << (misc->minor & 7);
|
misc_minors[misc->minor >> 3] |= 1 << (misc->minor & 7);
|
MOD_INC_USE_COUNT;
|
MOD_INC_USE_COUNT;
|
misc->next = &misc_list;
|
misc->next = &misc_list;
|
misc->prev = misc_list.prev;
|
misc->prev = misc_list.prev;
|
misc->prev->next = misc;
|
misc->prev->next = misc;
|
misc->next->prev = misc;
|
misc->next->prev = misc;
|
return 0;
|
return 0;
|
}
|
}
|
|
|
int misc_deregister(struct miscdevice * misc)
|
int misc_deregister(struct miscdevice * misc)
|
{
|
{
|
int i = misc->minor;
|
int i = misc->minor;
|
if (!misc->next || !misc->prev)
|
if (!misc->next || !misc->prev)
|
return -EINVAL;
|
return -EINVAL;
|
MOD_DEC_USE_COUNT;
|
MOD_DEC_USE_COUNT;
|
misc->prev->next = misc->next;
|
misc->prev->next = misc->next;
|
misc->next->prev = misc->prev;
|
misc->next->prev = misc->prev;
|
misc->next = NULL;
|
misc->next = NULL;
|
misc->prev = NULL;
|
misc->prev = NULL;
|
if (i < DYNAMIC_MINORS && i>0) {
|
if (i < DYNAMIC_MINORS && i>0) {
|
misc_minors[i>>3] &= ~(1 << (misc->minor & 7));
|
misc_minors[i>>3] &= ~(1 << (misc->minor & 7));
|
}
|
}
|
return 0;
|
return 0;
|
}
|
}
|
|
|
#ifdef MODULE
|
#ifdef MODULE
|
|
|
#define misc_init init_module
|
#define misc_init init_module
|
|
|
void cleanup_module(void)
|
void cleanup_module(void)
|
{
|
{
|
unregister_chrdev(MISC_MAJOR, "misc");
|
unregister_chrdev(MISC_MAJOR, "misc");
|
}
|
}
|
|
|
#endif
|
#endif
|
|
|
static struct symbol_table misc_syms = {
|
static struct symbol_table misc_syms = {
|
/* Should this be surrounded with "#ifdef CONFIG_MODULES" ? */
|
/* Should this be surrounded with "#ifdef CONFIG_MODULES" ? */
|
#include <linux/symtab_begin.h>
|
#include <linux/symtab_begin.h>
|
X(misc_register),
|
X(misc_register),
|
X(misc_deregister),
|
X(misc_deregister),
|
#ifndef MODULE
|
#ifndef MODULE
|
X(set_selection), /* used by the kmouse module, can only */
|
X(set_selection), /* used by the kmouse module, can only */
|
X(paste_selection), /* be exported if misc.c is in linked in */
|
X(paste_selection), /* be exported if misc.c is in linked in */
|
X(con_get_info),
|
X(con_get_info),
|
#endif
|
#endif
|
#include <linux/symtab_end.h>
|
#include <linux/symtab_end.h>
|
};
|
};
|
|
|
int misc_init(void)
|
int misc_init(void)
|
{
|
{
|
#ifndef MODULE
|
#ifndef MODULE
|
#ifdef CONFIG_PROC_FS
|
#ifdef CONFIG_PROC_FS
|
proc_register_dynamic(&proc_root, &(struct proc_dir_entry) {
|
proc_register_dynamic(&proc_root, &(struct proc_dir_entry) {
|
0, 4, "misc",
|
0, 4, "misc",
|
S_IFREG | S_IRUGO, 1, 0, 0,
|
S_IFREG | S_IRUGO, 1, 0, 0,
|
0, NULL /* ops -- default to array */,
|
0, NULL /* ops -- default to array */,
|
&proc_misc_read /* get_info */,
|
&proc_misc_read /* get_info */,
|
});
|
});
|
#endif /* PROC_FS */
|
#endif /* PROC_FS */
|
#ifdef CONFIG_MOUSE
|
#ifdef CONFIG_MOUSE
|
misc_mouse_init();
|
misc_mouse_init();
|
#endif
|
#endif
|
#ifdef CONFIG_SOFT_WATCHDOG
|
#ifdef CONFIG_SOFT_WATCHDOG
|
watchdog_init();
|
watchdog_init();
|
#endif
|
#endif
|
#endif /* !MODULE */
|
#endif /* !MODULE */
|
if (register_chrdev(MISC_MAJOR,"misc",&misc_fops)) {
|
if (register_chrdev(MISC_MAJOR,"misc",&misc_fops)) {
|
printk("unable to get major %d for misc devices\n",
|
printk("unable to get major %d for misc devices\n",
|
MISC_MAJOR);
|
MISC_MAJOR);
|
return -EIO;
|
return -EIO;
|
}
|
}
|
|
|
if(register_symtab(&misc_syms)!=0)
|
if(register_symtab(&misc_syms)!=0)
|
{
|
{
|
unregister_chrdev(MISC_MAJOR, "misc");
|
unregister_chrdev(MISC_MAJOR, "misc");
|
return -EIO;
|
return -EIO;
|
}
|
}
|
return 0;
|
return 0;
|
}
|
}
|
|
|