eisa_eeprom.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. static loff_t eisa_eeprom_llseek(struct file *file, loff_t offset, int origin)
  17. {
  18. return fixed_size_llseek(file, offset, origin, HPEE_MAX_LENGTH);
  19. }
  20. static ssize_t eisa_eeprom_read(struct file * file,
  21. char __user *buf, size_t count, loff_t *ppos )
  22. {
  23. unsigned char *tmp;
  24. ssize_t ret;
  25. int i;
  26. if (*ppos < 0 || *ppos >= HPEE_MAX_LENGTH)
  27. return 0;
  28. count = *ppos + count < HPEE_MAX_LENGTH ? count : HPEE_MAX_LENGTH - *ppos;
  29. tmp = kmalloc(count, GFP_KERNEL);
  30. if (tmp) {
  31. for (i = 0; i < count; i++)
  32. tmp[i] = readb(eisa_eeprom_addr+(*ppos)++);
  33. if (copy_to_user (buf, tmp, count))
  34. ret = -EFAULT;
  35. else
  36. ret = count;
  37. kfree (tmp);
  38. } else
  39. ret = -ENOMEM;
  40. return ret;
  41. }
  42. static int eisa_eeprom_open(struct inode *inode, struct file *file)
  43. {
  44. if (file->f_mode & FMODE_WRITE)
  45. return -EINVAL;
  46. return 0;
  47. }
  48. static int eisa_eeprom_release(struct inode *inode, struct file *file)
  49. {
  50. return 0;
  51. }
  52. /*
  53. * The various file operations we support.
  54. */
  55. static const struct file_operations eisa_eeprom_fops = {
  56. .owner = THIS_MODULE,
  57. .llseek = eisa_eeprom_llseek,
  58. .read = eisa_eeprom_read,
  59. .open = eisa_eeprom_open,
  60. .release = eisa_eeprom_release,
  61. };
  62. static struct miscdevice eisa_eeprom_dev = {
  63. EISA_EEPROM_MINOR,
  64. "eisa_eeprom",
  65. &eisa_eeprom_fops
  66. };
  67. static int __init eisa_eeprom_init(void)
  68. {
  69. int retval;
  70. if (!eisa_eeprom_addr)
  71. return -ENODEV;
  72. retval = misc_register(&eisa_eeprom_dev);
  73. if (retval < 0) {
  74. printk(KERN_ERR "EISA EEPROM: cannot register misc device.\n");
  75. return retval;
  76. }
  77. printk(KERN_INFO "EISA EEPROM at 0x%px\n", eisa_eeprom_addr);
  78. return 0;
  79. }
  80. MODULE_LICENSE("GPL");
  81. module_init(eisa_eeprom_init);