make oldconfig will rebuild these...
[linux-2.4.21-pre4.git] / drivers / gsc / eisa_eeprom.c
1 #include <linux/config.h>
2 #include <linux/module.h>
3 #include <linux/init.h>
4 #include <linux/kernel.h>
5 #include <linux/miscdevice.h>
6 #include <linux/slab.h>
7 #include <asm/gsc.h>
8 #include <asm/uaccess.h>
9 #include <asm/eisa_eeprom.h>
10
11 #define         EISA_EEPROM_MINOR 241
12
13 static unsigned long eeprom_addr;
14
15 static long long eisa_eeprom_llseek(struct file *file, loff_t offset, int origin )
16 {
17         switch (origin) {
18           case 0:
19                 /* nothing to do */
20                 break;
21           case 1:
22                 offset += file->f_pos;
23                 break;
24           case 2:
25                 offset += HPEE_MAX_LENGTH;
26                 break;
27         }
28         return (offset >= 0 && offset < HPEE_MAX_LENGTH) ? (file->f_pos = offset) : -EINVAL;
29 }
30
31 static ssize_t eisa_eeprom_read(struct file * file,
32                               char *buf, size_t count, loff_t *ppos )
33 {
34         unsigned char *tmp;
35         ssize_t ret;
36         int i;
37         
38         if (*ppos >= HPEE_MAX_LENGTH)
39                 return 0;
40         
41         count = *ppos + count < HPEE_MAX_LENGTH ? count : HPEE_MAX_LENGTH - *ppos;
42         tmp = kmalloc(count, GFP_KERNEL);
43         if (tmp) {
44                 for (i = 0; i < count; i++)
45                         tmp[i] = gsc_readb(eeprom_addr+(*ppos)++);
46
47                 if (copy_to_user (buf, tmp, count))
48                         ret = -EFAULT;
49                 else
50                         ret = count;
51                 kfree (tmp);
52         } else
53                 ret = -ENOMEM;
54         
55         return ret;
56 }
57
58 static int eisa_eeprom_ioctl(struct inode *inode, struct file *file, 
59                            unsigned int cmd,
60                            unsigned long arg)
61 {
62         return -ENOTTY;
63 }
64
65 static int eisa_eeprom_open(struct inode *inode, struct file *file)
66 {
67         if (file->f_mode & 2 || eeprom_addr == 0)
68                 return -EINVAL;
69    
70         return 0;
71 }
72
73 static int eisa_eeprom_release(struct inode *inode, struct file *file)
74 {
75         return 0;
76 }
77
78 /*
79  *      The various file operations we support.
80  */
81 static struct file_operations eisa_eeprom_fops = {
82         owner:          THIS_MODULE,
83         llseek:         eisa_eeprom_llseek,
84         read:           eisa_eeprom_read,
85         ioctl:          eisa_eeprom_ioctl,
86         open:           eisa_eeprom_open,
87         release:        eisa_eeprom_release,
88 };
89
90 static struct miscdevice eisa_eeprom_dev=
91 {
92         EISA_EEPROM_MINOR,
93         "eisa eeprom",
94         &eisa_eeprom_fops
95 };
96
97 int __init eisa_eeprom_init(unsigned long addr)
98 {
99         if (addr) {
100                 eeprom_addr = addr;
101                 misc_register(&eisa_eeprom_dev);
102                 printk(KERN_INFO "EISA EEPROM at 0x%lx\n", eeprom_addr);
103         }
104         return 0;
105 }
106
107 MODULE_LICENSE("GPL");