ide-sysfs.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #include <linux/kernel.h>
  2. #include <linux/ide.h>
  3. char *ide_media_string(ide_drive_t *drive)
  4. {
  5. switch (drive->media) {
  6. case ide_disk:
  7. return "disk";
  8. case ide_cdrom:
  9. return "cdrom";
  10. case ide_tape:
  11. return "tape";
  12. case ide_floppy:
  13. return "floppy";
  14. case ide_optical:
  15. return "optical";
  16. default:
  17. return "UNKNOWN";
  18. }
  19. }
  20. static ssize_t media_show(struct device *dev, struct device_attribute *attr,
  21. char *buf)
  22. {
  23. ide_drive_t *drive = to_ide_device(dev);
  24. return sprintf(buf, "%s\n", ide_media_string(drive));
  25. }
  26. static ssize_t drivename_show(struct device *dev, struct device_attribute *attr,
  27. char *buf)
  28. {
  29. ide_drive_t *drive = to_ide_device(dev);
  30. return sprintf(buf, "%s\n", drive->name);
  31. }
  32. static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
  33. char *buf)
  34. {
  35. ide_drive_t *drive = to_ide_device(dev);
  36. return sprintf(buf, "ide:m-%s\n", ide_media_string(drive));
  37. }
  38. static ssize_t model_show(struct device *dev, struct device_attribute *attr,
  39. char *buf)
  40. {
  41. ide_drive_t *drive = to_ide_device(dev);
  42. return sprintf(buf, "%s\n", (char *)&drive->id[ATA_ID_PROD]);
  43. }
  44. static ssize_t firmware_show(struct device *dev, struct device_attribute *attr,
  45. char *buf)
  46. {
  47. ide_drive_t *drive = to_ide_device(dev);
  48. return sprintf(buf, "%s\n", (char *)&drive->id[ATA_ID_FW_REV]);
  49. }
  50. static ssize_t serial_show(struct device *dev, struct device_attribute *attr,
  51. char *buf)
  52. {
  53. ide_drive_t *drive = to_ide_device(dev);
  54. return sprintf(buf, "%s\n", (char *)&drive->id[ATA_ID_SERNO]);
  55. }
  56. struct device_attribute ide_dev_attrs[] = {
  57. __ATTR_RO(media),
  58. __ATTR_RO(drivename),
  59. __ATTR_RO(modalias),
  60. __ATTR_RO(model),
  61. __ATTR_RO(firmware),
  62. __ATTR(serial, 0400, serial_show, NULL),
  63. __ATTR(unload_heads, 0644, ide_park_show, ide_park_store),
  64. __ATTR_NULL
  65. };
  66. static ssize_t store_delete_devices(struct device *portdev,
  67. struct device_attribute *attr,
  68. const char *buf, size_t n)
  69. {
  70. ide_hwif_t *hwif = dev_get_drvdata(portdev);
  71. if (strncmp(buf, "1", n))
  72. return -EINVAL;
  73. ide_port_unregister_devices(hwif);
  74. return n;
  75. };
  76. static DEVICE_ATTR(delete_devices, S_IWUSR, NULL, store_delete_devices);
  77. static ssize_t store_scan(struct device *portdev,
  78. struct device_attribute *attr,
  79. const char *buf, size_t n)
  80. {
  81. ide_hwif_t *hwif = dev_get_drvdata(portdev);
  82. if (strncmp(buf, "1", n))
  83. return -EINVAL;
  84. ide_port_unregister_devices(hwif);
  85. ide_port_scan(hwif);
  86. return n;
  87. };
  88. static DEVICE_ATTR(scan, S_IWUSR, NULL, store_scan);
  89. static struct device_attribute *ide_port_attrs[] = {
  90. &dev_attr_delete_devices,
  91. &dev_attr_scan,
  92. NULL
  93. };
  94. int ide_sysfs_register_port(ide_hwif_t *hwif)
  95. {
  96. int i, uninitialized_var(rc);
  97. for (i = 0; ide_port_attrs[i]; i++) {
  98. rc = device_create_file(hwif->portdev, ide_port_attrs[i]);
  99. if (rc)
  100. break;
  101. }
  102. return rc;
  103. }