ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / parisc / eisa_eeprom.c
1 /* 
2  *    EISA "eeprom" support routines
3  *
4  *    Copyright (C) 2001 Thomas Bogendoerfer <tsbogend at parisc-linux.org>
5  *
6  *
7  *    This program is free software; you can redistribute it and/or modify
8  *    it under the terms of the GNU General Public License as published by
9  *    the Free Software Foundation; either version 2 of the License, or
10  *    (at your option) any later version.
11  *
12  *    This program is distributed in the hope that it will be useful,
13  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *    GNU General Public License for more details.
16  *
17  *    You should have received a copy of the GNU General Public License
18  *    along with this program; if not, write to the Free Software
19  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #include <linux/config.h>
23 #include <linux/module.h>
24 #include <linux/init.h>
25 #include <linux/kernel.h>
26 #include <linux/miscdevice.h>
27 #include <linux/slab.h>
28 #include <linux/fs.h>
29 #include <asm/io.h>
30 #include <asm/uaccess.h>
31 #include <asm/eisa_eeprom.h>
32
33 #define         EISA_EEPROM_MINOR 241
34
35 static unsigned long eeprom_addr;
36
37 static loff_t eisa_eeprom_llseek(struct file *file, loff_t offset, int origin )
38 {
39         switch (origin) {
40           case 0:
41                 /* nothing to do */
42                 break;
43           case 1:
44                 offset += file->f_pos;
45                 break;
46           case 2:
47                 offset += HPEE_MAX_LENGTH;
48                 break;
49         }
50         return (offset >= 0 && offset < HPEE_MAX_LENGTH) ? (file->f_pos = offset) : -EINVAL;
51 }
52
53 static ssize_t eisa_eeprom_read(struct file * file,
54                               char *buf, size_t count, loff_t *ppos )
55 {
56         unsigned char *tmp;
57         ssize_t ret;
58         int i;
59         
60         if (*ppos >= HPEE_MAX_LENGTH)
61                 return 0;
62         
63         count = *ppos + count < HPEE_MAX_LENGTH ? count : HPEE_MAX_LENGTH - *ppos;
64         tmp = kmalloc(count, GFP_KERNEL);
65         if (tmp) {
66                 for (i = 0; i < count; i++)
67                         tmp[i] = gsc_readb(eeprom_addr+(*ppos)++);
68
69                 if (copy_to_user (buf, tmp, count))
70                         ret = -EFAULT;
71                 else
72                         ret = count;
73                 kfree (tmp);
74         } else
75                 ret = -ENOMEM;
76         
77         return ret;
78 }
79
80 static int eisa_eeprom_ioctl(struct inode *inode, struct file *file, 
81                            unsigned int cmd,
82                            unsigned long arg)
83 {
84         return -ENOTTY;
85 }
86
87 static int eisa_eeprom_open(struct inode *inode, struct file *file)
88 {
89         if (file->f_mode & 2 || eeprom_addr == 0)
90                 return -EINVAL;
91    
92         return 0;
93 }
94
95 static int eisa_eeprom_release(struct inode *inode, struct file *file)
96 {
97         return 0;
98 }
99
100 /*
101  *      The various file operations we support.
102  */
103 static struct file_operations eisa_eeprom_fops = {
104         .owner =        THIS_MODULE,
105         .llseek =       eisa_eeprom_llseek,
106         .read =         eisa_eeprom_read,
107         .ioctl =        eisa_eeprom_ioctl,
108         .open =         eisa_eeprom_open,
109         .release =      eisa_eeprom_release,
110 };
111
112 static struct miscdevice eisa_eeprom_dev=
113 {
114         EISA_EEPROM_MINOR,
115         "eisa eeprom",
116         &eisa_eeprom_fops
117 };
118
119 int __init eisa_eeprom_init(unsigned long addr)
120 {
121         int retval;
122
123         /* XXX why return success when we haven't done anything? */
124         if (!addr)
125                 return 0;
126
127         eeprom_addr = addr;
128
129         retval = misc_register(&eisa_eeprom_dev);
130         if (retval < 0) {
131                 printk(KERN_ERR "EISA EEPROM: cannot register misc device.\n");
132                 return retval;
133         }
134
135         printk(KERN_INFO "EISA EEPROM at 0x%lx\n", eeprom_addr);
136         return 0;
137 }
138
139 MODULE_LICENSE("GPL");