eisa_eeprom.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * EISA "eeprom" support routines
  4. *
  5. * Copyright (C) 2001 Thomas Bogendoerfer <tsbogend at parisc-linux.org>
  6. */
  7. #include <linux/module.h>
  8. #include <linux/init.h>
  9. #include <linux/kernel.h>
  10. #include <linux/miscdevice.h>
  11. #include <linux/slab.h>
  12. #include <linux/fs.h>
  13. #include <asm/io.h>
  14. #include <linux/uaccess.h>
  15. #include <asm/eisa_eeprom.h>
  16. #define EISA_EEPROM_MINOR 241
  17. static loff_t eisa_eeprom_llseek(struct file *file, loff_t offset, int origin)
  18. {
  19. return fixed_size_llseek(file, offset, origin, HPEE_MAX_LENGTH);
  20. }
  21. static ssize_t eisa_eeprom_read(struct file * file,
  22. char __user *buf, size_t count, loff_t *ppos )
  23. {
  24. unsigned char *tmp;
  25. ssize_t ret;
  26. int i;
  27. if (*ppos < 0 || *ppos >= HPEE_MAX_LENGTH)
  28. return 0;
  29. count = *ppos + count < HPEE_MAX_LENGTH ? count : HPEE_MAX_LENGTH - *ppos;
  30. tmp = kmalloc(count, GFP_KERNEL);
  31. if (tmp) {
  32. for (i = 0; i < count; i++)
  33. tmp[i] = readb(eisa_eeprom_addr+(*ppos)++);
  34. if (copy_to_user (buf, tmp, count))
  35. ret = -EFAULT;
  36. else
  37. ret = count;
  38. kfree (tmp);
  39. } else
  40. ret = -ENOMEM;
  41. return ret;
  42. }
  43. static int eisa_eeprom_open(struct inode *inode, struct file *file)
  44. {
  45. if (file->f_mode & FMODE_WRITE)
  46. return -EINVAL;
  47. return 0;
  48. }
  49. static int eisa_eeprom_release(struct inode *inode, struct file *file)
  50. {
  51. return 0;
  52. }
  53. /*
  54. * The various file operations we support.
  55. */
  56. static const struct file_operations eisa_eeprom_fops = {
  57. .owner = THIS_MODULE,
  58. .llseek = eisa_eeprom_llseek,
  59. .read = eisa_eeprom_read,
  60. .open = eisa_eeprom_open,
  61. .release = eisa_eeprom_release,
  62. };
  63. static struct miscdevice eisa_eeprom_dev = {
  64. EISA_EEPROM_MINOR,
  65. "eisa_eeprom",
  66. &eisa_eeprom_fops
  67. };
  68. static int __init eisa_eeprom_init(void)
  69. {
  70. int retval;
  71. if (!eisa_eeprom_addr)
  72. return -ENODEV;
  73. retval = misc_register(&eisa_eeprom_dev);
  74. if (retval < 0) {
  75. printk(KERN_ERR "EISA EEPROM: cannot register misc device.\n");
  76. return retval;
  77. }
  78. printk(KERN_INFO "EISA EEPROM at 0x%px\n", eisa_eeprom_addr);
  79. return 0;
  80. }
  81. MODULE_LICENSE("GPL");
  82. module_init(eisa_eeprom_init);