eisa_eeprom.c 3.1 KB

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