hdpu_nexus.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. },
  53. };
  54. static int hdpu_slot_id_open(struct inode *inode, struct file *file)
  55. {
  56. return single_open(file, hdpu_slot_id_read, NULL);
  57. }
  58. static int hdpu_slot_id_read(struct seq_file *seq, void *offset)
  59. {
  60. seq_printf(seq, "%d\n", slot_id);
  61. return 0;
  62. }
  63. static int hdpu_chassis_id_open(struct inode *inode, struct file *file)
  64. {
  65. return single_open(file, hdpu_chassis_id_read, NULL);
  66. }
  67. static int hdpu_chassis_id_read(struct seq_file *seq, void *offset)
  68. {
  69. seq_printf(seq, "%d\n", chassis_id);
  70. return 0;
  71. }
  72. static int hdpu_nexus_probe(struct platform_device *pdev)
  73. {
  74. struct resource *res;
  75. int *nexus_id_addr;
  76. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  77. if (!res) {
  78. printk(KERN_ERR "sky_nexus: "
  79. "Invalid memory resource.\n");
  80. return -EINVAL;
  81. }
  82. nexus_id_addr = ioremap(res->start,
  83. (unsigned long)(res->end - res->start));
  84. if (nexus_id_addr) {
  85. slot_id = (*nexus_id_addr >> 8) & 0x1f;
  86. chassis_id = *nexus_id_addr & 0xff;
  87. iounmap(nexus_id_addr);
  88. } else {
  89. printk(KERN_ERR "sky_nexus: Could not map slot id\n");
  90. }
  91. hdpu_slot_id = create_proc_entry("sky_slot_id", 0666, &proc_root);
  92. if (!hdpu_slot_id) {
  93. printk(KERN_WARNING "sky_nexus: "
  94. "Unable to create proc dir entry: sky_slot_id\n");
  95. } else {
  96. hdpu_slot_id->proc_fops = &proc_slot_id;
  97. hdpu_slot_id->owner = THIS_MODULE;
  98. }
  99. hdpu_chassis_id = create_proc_entry("sky_chassis_id", 0666, &proc_root);
  100. if (!hdpu_chassis_id) {
  101. printk(KERN_WARNING "sky_nexus: "
  102. "Unable to create proc dir entry: sky_chassis_id\n");
  103. } else {
  104. hdpu_chassis_id->proc_fops = &proc_chassis_id;
  105. hdpu_chassis_id->owner = THIS_MODULE;
  106. }
  107. return 0;
  108. }
  109. static int hdpu_nexus_remove(struct platform_device *pdev)
  110. {
  111. slot_id = -1;
  112. chassis_id = -1;
  113. remove_proc_entry("sky_slot_id", &proc_root);
  114. remove_proc_entry("sky_chassis_id", &proc_root);
  115. hdpu_slot_id = 0;
  116. hdpu_chassis_id = 0;
  117. return 0;
  118. }
  119. static int __init nexus_init(void)
  120. {
  121. return platform_driver_register(&hdpu_nexus_driver);
  122. }
  123. static void __exit nexus_exit(void)
  124. {
  125. platform_driver_unregister(&hdpu_nexus_driver);
  126. }
  127. module_init(nexus_init);
  128. module_exit(nexus_exit);
  129. MODULE_AUTHOR("Brian Waite");
  130. MODULE_LICENSE("GPL");