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/module.h> 23 #include <linux/init.h> 24 #include <linux/kernel.h> 25 #include <linux/miscdevice.h> 26 #include <linux/slab.h> 27 #include <linux/fs.h> 28 #include <asm/io.h> 29 #include <asm/uaccess.h> 30 #include <asm/eisa_eeprom.h> 31 32 #define EISA_EEPROM_MINOR 241 33 34 static loff_t eisa_eeprom_llseek(struct file *file, loff_t offset, int origin ) 35 { 36 switch (origin) { 37 case 0: 38 /* nothing to do */ 39 break; 40 case 1: 41 offset += file->f_pos; 42 break; 43 case 2: 44 offset += HPEE_MAX_LENGTH; 45 break; 46 } 47 return (offset >= 0 && offset < HPEE_MAX_LENGTH) ? (file->f_pos = offset) : -EINVAL; 48 } 49 50 static ssize_t eisa_eeprom_read(struct file * file, 51 char __user *buf, size_t count, loff_t *ppos ) 52 { 53 unsigned char *tmp; 54 ssize_t ret; 55 int i; 56 57 if (*ppos < 0 || *ppos >= HPEE_MAX_LENGTH) 58 return 0; 59 60 count = *ppos + count < HPEE_MAX_LENGTH ? count : HPEE_MAX_LENGTH - *ppos; 61 tmp = kmalloc(count, GFP_KERNEL); 62 if (tmp) { 63 for (i = 0; i < count; i++) 64 tmp[i] = readb(eisa_eeprom_addr+(*ppos)++); 65 66 if (copy_to_user (buf, tmp, count)) 67 ret = -EFAULT; 68 else 69 ret = count; 70 kfree (tmp); 71 } else 72 ret = -ENOMEM; 73 74 return ret; 75 } 76 77 static int eisa_eeprom_open(struct inode *inode, struct file *file) 78 { 79 if (file->f_mode & FMODE_WRITE) 80 return -EINVAL; 81 82 return 0; 83 } 84 85 static int eisa_eeprom_release(struct inode *inode, struct file *file) 86 { 87 return 0; 88 } 89 90 /* 91 * The various file operations we support. 92 */ 93 static const struct file_operations eisa_eeprom_fops = { 94 .owner = THIS_MODULE, 95 .llseek = eisa_eeprom_llseek, 96 .read = eisa_eeprom_read, 97 .open = eisa_eeprom_open, 98 .release = eisa_eeprom_release, 99 }; 100 101 static struct miscdevice eisa_eeprom_dev = { 102 EISA_EEPROM_MINOR, 103 "eisa_eeprom", 104 &eisa_eeprom_fops 105 }; 106 107 static int __init eisa_eeprom_init(void) 108 { 109 int retval; 110 111 if (!eisa_eeprom_addr) 112 return -ENODEV; 113 114 retval = misc_register(&eisa_eeprom_dev); 115 if (retval < 0) { 116 printk(KERN_ERR "EISA EEPROM: cannot register misc device.\n"); 117 return retval; 118 } 119 120 printk(KERN_INFO "EISA EEPROM at 0x%p\n", eisa_eeprom_addr); 121 return 0; 122 } 123 124 MODULE_LICENSE("GPL"); 125 126 module_init(eisa_eeprom_init); 127