hdpu_nexus.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * Sky Nexus Register Driver
  3. *
  4. * Copyright (C) 2002 Brian Waite
  5. *
  6. * This driver allows reading the Nexus register
  7. * It exports the /proc/sky_chassis_id and also
  8. * /proc/sky_slot_id pseudo-file for status information.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License
  12. * as published by the Free Software Foundation; either version
  13. * 2 of the License, or (at your option) any later version.
  14. *
  15. */
  16. #include <linux/module.h>
  17. #include <linux/kernel.h>
  18. #include <linux/proc_fs.h>
  19. #include <linux/hdpu_features.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/seq_file.h>
  22. #include <asm/io.h>
  23. static int hdpu_nexus_probe(struct platform_device *pdev);
  24. static int hdpu_nexus_remove(struct platform_device *pdev);
  25. static int hdpu_slot_id_open(struct inode *inode, struct file *file);
  26. static int hdpu_slot_id_read(struct seq_file *seq, void *offset);
  27. static int hdpu_chassis_id_open(struct inode *inode, struct file *file);
  28. static int hdpu_chassis_id_read(struct seq_file *seq, void *offset);
  29. static struct proc_dir_entry *hdpu_slot_id;
  30. static struct proc_dir_entry *hdpu_chassis_id;
  31. static int slot_id = -1;
  32. static int chassis_id = -1;
  33. static const struct file_operations proc_slot_id = {
  34. .open = hdpu_slot_id_open,
  35. .read = seq_read,
  36. .llseek = seq_lseek,
  37. .release = single_release,
  38. .owner = THIS_MODULE,
  39. };
  40. static const struct file_operations proc_chassis_id = {
  41. .open = hdpu_chassis_id_open,
  42. .read = seq_read,
  43. .llseek = seq_lseek,
  44. .release = single_release,
  45. .owner = THIS_MODULE,
  46. };
  47. static struct platform_driver hdpu_nexus_driver = {
  48. .probe = hdpu_nexus_probe,
  49. .remove = hdpu_nexus_remove,
  50. .driver = {
  51. .name = HDPU_NEXUS_NAME,
  52. .owner = THIS_MODULE,
  53. },
  54. };
  55. static int hdpu_slot_id_open(struct inode *inode, struct file *file)
  56. {
  57. return single_open(file, hdpu_slot_id_read, NULL);
  58. }
  59. static int hdpu_slot_id_read(struct seq_file *seq, void *offset)
  60. {
  61. seq_printf(seq, "%d\n", slot_id);
  62. return 0;
  63. }
  64. static int hdpu_chassis_id_open(struct inode *inode, struct file *file)
  65. {
  66. return single_open(file, hdpu_chassis_id_read, NULL);
  67. }
  68. static int hdpu_chassis_id_read(struct seq_file *seq, void *offset)
  69. {
  70. seq_printf(seq, "%d\n", chassis_id);
  71. return 0;
  72. }
  73. static int hdpu_nexus_probe(struct platform_device *pdev)
  74. {
  75. struct resource *res;
  76. int *nexus_id_addr;
  77. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  78. if (!res) {
  79. printk(KERN_ERR "sky_nexus: "
  80. "Invalid memory resource.\n");
  81. return -EINVAL;
  82. }
  83. nexus_id_addr = ioremap(res->start,
  84. (unsigned long)(res->end - res->start));
  85. if (nexus_id_addr) {
  86. slot_id = (*nexus_id_addr >> 8) & 0x1f;
  87. chassis_id = *nexus_id_addr & 0xff;
  88. iounmap(nexus_id_addr);
  89. } else {
  90. printk(KERN_ERR "sky_nexus: Could not map slot id\n");
  91. }
  92. hdpu_slot_id = proc_create("sky_slot_id", 0666, NULL, &proc_slot_id);
  93. if (!hdpu_slot_id) {
  94. printk(KERN_WARNING "sky_nexus: "
  95. "Unable to create proc dir entry: sky_slot_id\n");
  96. }
  97. hdpu_chassis_id = proc_create("sky_chassis_id", 0666, NULL,
  98. &proc_chassis_id);
  99. if (!hdpu_chassis_id)
  100. printk(KERN_WARNING "sky_nexus: "
  101. "Unable to create proc dir entry: sky_chassis_id\n");
  102. }
  103. return 0;
  104. }
  105. static int hdpu_nexus_remove(struct platform_device *pdev)
  106. {
  107. slot_id = -1;
  108. chassis_id = -1;
  109. remove_proc_entry("sky_slot_id", NULL);
  110. remove_proc_entry("sky_chassis_id", NULL);
  111. hdpu_slot_id = 0;
  112. hdpu_chassis_id = 0;
  113. return 0;
  114. }
  115. static int __init nexus_init(void)
  116. {
  117. return platform_driver_register(&hdpu_nexus_driver);
  118. }
  119. static void __exit nexus_exit(void)
  120. {
  121. platform_driver_unregister(&hdpu_nexus_driver);
  122. }
  123. module_init(nexus_init);
  124. module_exit(nexus_exit);
  125. MODULE_AUTHOR("Brian Waite");
  126. MODULE_LICENSE("GPL");
  127. MODULE_ALIAS("platform:" HDPU_NEXUS_NAME);