initial commit with v2.6.9
[linux-2.6.9-moxart.git] / drivers / parisc / eisa_eeprom.c
blobd16724dbe890c37ed4eb49311dc68b2fd490e700
1 /*
2 * EISA "eeprom" support routines
4 * Copyright (C) 2001 Thomas Bogendoerfer <tsbogend at parisc-linux.org>
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.
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.
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
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>
33 #define EISA_EEPROM_MINOR 241
35 static unsigned long eeprom_addr;
37 static loff_t eisa_eeprom_llseek(struct file *file, loff_t offset, int origin )
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;
50 return (offset >= 0 && offset < HPEE_MAX_LENGTH) ? (file->f_pos = offset) : -EINVAL;
53 static ssize_t eisa_eeprom_read(struct file * file,
54 char *buf, size_t count, loff_t *ppos )
56 unsigned char *tmp;
57 ssize_t ret;
58 int i;
60 if (*ppos >= HPEE_MAX_LENGTH)
61 return 0;
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)++);
69 if (copy_to_user (buf, tmp, count))
70 ret = -EFAULT;
71 else
72 ret = count;
73 kfree (tmp);
74 } else
75 ret = -ENOMEM;
77 return ret;
80 static int eisa_eeprom_ioctl(struct inode *inode, struct file *file,
81 unsigned int cmd,
82 unsigned long arg)
84 return -ENOTTY;
87 static int eisa_eeprom_open(struct inode *inode, struct file *file)
89 if (file->f_mode & 2 || eeprom_addr == 0)
90 return -EINVAL;
92 return 0;
95 static int eisa_eeprom_release(struct inode *inode, struct file *file)
97 return 0;
101 * The various file operations we support.
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,
112 static struct miscdevice eisa_eeprom_dev=
114 EISA_EEPROM_MINOR,
115 "eisa eeprom",
116 &eisa_eeprom_fops
119 int __init eisa_eeprom_init(unsigned long addr)
121 int retval;
123 /* XXX why return success when we haven't done anything? */
124 if (!addr)
125 return 0;
127 eeprom_addr = addr;
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;
135 printk(KERN_INFO "EISA EEPROM at 0x%lx\n", eeprom_addr);
136 return 0;
139 MODULE_LICENSE("GPL");