eisa_eeprom.c 3.1 KB

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