0001
0002
0003
0004
0005
0006
0007
0008 #include <linux/module.h>
0009 #include <linux/init.h>
0010 #include <linux/kernel.h>
0011 #include <linux/miscdevice.h>
0012 #include <linux/slab.h>
0013 #include <linux/fs.h>
0014 #include <asm/io.h>
0015 #include <linux/uaccess.h>
0016 #include <asm/eisa_eeprom.h>
0017
0018 #define EISA_EEPROM_MINOR 241
0019
0020 static loff_t eisa_eeprom_llseek(struct file *file, loff_t offset, int origin)
0021 {
0022 return fixed_size_llseek(file, offset, origin, HPEE_MAX_LENGTH);
0023 }
0024
0025 static ssize_t eisa_eeprom_read(struct file * file,
0026 char __user *buf, size_t count, loff_t *ppos )
0027 {
0028 unsigned char *tmp;
0029 ssize_t ret;
0030 int i;
0031
0032 if (*ppos < 0 || *ppos >= HPEE_MAX_LENGTH)
0033 return 0;
0034
0035 count = *ppos + count < HPEE_MAX_LENGTH ? count : HPEE_MAX_LENGTH - *ppos;
0036 tmp = kmalloc(count, GFP_KERNEL);
0037 if (tmp) {
0038 for (i = 0; i < count; i++)
0039 tmp[i] = readb(eisa_eeprom_addr+(*ppos)++);
0040
0041 if (copy_to_user (buf, tmp, count))
0042 ret = -EFAULT;
0043 else
0044 ret = count;
0045 kfree (tmp);
0046 } else
0047 ret = -ENOMEM;
0048
0049 return ret;
0050 }
0051
0052 static int eisa_eeprom_open(struct inode *inode, struct file *file)
0053 {
0054 if (file->f_mode & FMODE_WRITE)
0055 return -EINVAL;
0056
0057 return 0;
0058 }
0059
0060 static int eisa_eeprom_release(struct inode *inode, struct file *file)
0061 {
0062 return 0;
0063 }
0064
0065
0066
0067
0068 static const struct file_operations eisa_eeprom_fops = {
0069 .owner = THIS_MODULE,
0070 .llseek = eisa_eeprom_llseek,
0071 .read = eisa_eeprom_read,
0072 .open = eisa_eeprom_open,
0073 .release = eisa_eeprom_release,
0074 };
0075
0076 static struct miscdevice eisa_eeprom_dev = {
0077 EISA_EEPROM_MINOR,
0078 "eisa_eeprom",
0079 &eisa_eeprom_fops
0080 };
0081
0082 static int __init eisa_eeprom_init(void)
0083 {
0084 int retval;
0085
0086 if (!eisa_eeprom_addr)
0087 return -ENODEV;
0088
0089 retval = misc_register(&eisa_eeprom_dev);
0090 if (retval < 0) {
0091 printk(KERN_ERR "EISA EEPROM: cannot register misc device.\n");
0092 return retval;
0093 }
0094
0095 printk(KERN_INFO "EISA EEPROM at 0x%px\n", eisa_eeprom_addr);
0096 return 0;
0097 }
0098
0099 MODULE_LICENSE("GPL");
0100
0101 module_init(eisa_eeprom_init);