Thomas Gleixner | 1a59d1b8 | 2019-05-27 08:55:05 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * EISA "eeprom" support routines |
| 4 | * |
| 5 | * Copyright (C) 2001 Thomas Bogendoerfer <tsbogend at parisc-linux.org> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <linux/module.h> |
| 9 | #include <linux/init.h> |
| 10 | #include <linux/kernel.h> |
| 11 | #include <linux/miscdevice.h> |
| 12 | #include <linux/slab.h> |
| 13 | #include <linux/fs.h> |
| 14 | #include <asm/io.h> |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 15 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <asm/eisa_eeprom.h> |
| 17 | |
| 18 | #define EISA_EEPROM_MINOR 241 |
| 19 | |
Al Viro | 7479779 | 2013-06-17 15:27:47 +0400 | [diff] [blame] | 20 | static loff_t eisa_eeprom_llseek(struct file *file, loff_t offset, int origin) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | { |
Al Viro | 7479779 | 2013-06-17 15:27:47 +0400 | [diff] [blame] | 22 | return fixed_size_llseek(file, offset, origin, HPEE_MAX_LENGTH); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | static ssize_t eisa_eeprom_read(struct file * file, |
Alexey Dobriyan | 45dbe91 | 2006-01-10 20:47:51 -0500 | [diff] [blame] | 26 | char __user *buf, size_t count, loff_t *ppos ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | { |
| 28 | unsigned char *tmp; |
| 29 | ssize_t ret; |
| 30 | int i; |
| 31 | |
Michael Buesch | 6b4dbcd | 2009-07-20 22:58:44 +0000 | [diff] [blame] | 32 | if (*ppos < 0 || *ppos >= HPEE_MAX_LENGTH) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | return 0; |
| 34 | |
| 35 | count = *ppos + count < HPEE_MAX_LENGTH ? count : HPEE_MAX_LENGTH - *ppos; |
| 36 | tmp = kmalloc(count, GFP_KERNEL); |
| 37 | if (tmp) { |
| 38 | for (i = 0; i < count; i++) |
| 39 | tmp[i] = readb(eisa_eeprom_addr+(*ppos)++); |
| 40 | |
| 41 | if (copy_to_user (buf, tmp, count)) |
| 42 | ret = -EFAULT; |
| 43 | else |
| 44 | ret = count; |
| 45 | kfree (tmp); |
| 46 | } else |
| 47 | ret = -ENOMEM; |
| 48 | |
| 49 | return ret; |
| 50 | } |
| 51 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | static int eisa_eeprom_open(struct inode *inode, struct file *file) |
| 53 | { |
Al Viro | aeb5d72 | 2008-09-02 15:28:45 -0400 | [diff] [blame] | 54 | if (file->f_mode & FMODE_WRITE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | return -EINVAL; |
| 56 | |
| 57 | return 0; |
| 58 | } |
| 59 | |
| 60 | static int eisa_eeprom_release(struct inode *inode, struct file *file) |
| 61 | { |
| 62 | return 0; |
| 63 | } |
| 64 | |
| 65 | /* |
| 66 | * The various file operations we support. |
| 67 | */ |
Arjan van de Ven | d54b1fd | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 68 | static const struct file_operations eisa_eeprom_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | .owner = THIS_MODULE, |
| 70 | .llseek = eisa_eeprom_llseek, |
| 71 | .read = eisa_eeprom_read, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | .open = eisa_eeprom_open, |
| 73 | .release = eisa_eeprom_release, |
| 74 | }; |
| 75 | |
| 76 | static struct miscdevice eisa_eeprom_dev = { |
| 77 | EISA_EEPROM_MINOR, |
| 78 | "eisa_eeprom", |
| 79 | &eisa_eeprom_fops |
| 80 | }; |
| 81 | |
| 82 | static int __init eisa_eeprom_init(void) |
| 83 | { |
| 84 | int retval; |
| 85 | |
| 86 | if (!eisa_eeprom_addr) |
| 87 | return -ENODEV; |
| 88 | |
| 89 | retval = misc_register(&eisa_eeprom_dev); |
| 90 | if (retval < 0) { |
| 91 | printk(KERN_ERR "EISA EEPROM: cannot register misc device.\n"); |
| 92 | return retval; |
| 93 | } |
| 94 | |
Helge Deller | 28df2f8 | 2018-01-02 20:47:01 +0100 | [diff] [blame] | 95 | printk(KERN_INFO "EISA EEPROM at 0x%px\n", eisa_eeprom_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | return 0; |
| 97 | } |
| 98 | |
| 99 | MODULE_LICENSE("GPL"); |
| 100 | |
| 101 | module_init(eisa_eeprom_init); |