ide-sysfs.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 DEVICE_ATTR_RO(media);
  27. static ssize_t drivename_show(struct device *dev, struct device_attribute *attr,
  28. char *buf)
  29. {
  30. ide_drive_t *drive = to_ide_device(dev);
  31. return sprintf(buf, "%s\n", drive->name);
  32. }
  33. static DEVICE_ATTR_RO(drivename);
  34. static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
  35. char *buf)
  36. {
  37. ide_drive_t *drive = to_ide_device(dev);
  38. return sprintf(buf, "ide:m-%s\n", ide_media_string(drive));
  39. }
  40. static DEVICE_ATTR_RO(modalias);
  41. static ssize_t model_show(struct device *dev, struct device_attribute *attr,
  42. char *buf)
  43. {
  44. ide_drive_t *drive = to_ide_device(dev);
  45. return sprintf(buf, "%s\n", (char *)&drive->id[ATA_ID_PROD]);
  46. }
  47. static DEVICE_ATTR_RO(model);
  48. static ssize_t firmware_show(struct device *dev, struct device_attribute *attr,
  49. char *buf)
  50. {
  51. ide_drive_t *drive = to_ide_device(dev);
  52. return sprintf(buf, "%s\n", (char *)&drive->id[ATA_ID_FW_REV]);
  53. }
  54. static DEVICE_ATTR_RO(firmware);
  55. static ssize_t serial_show(struct device *dev, struct device_attribute *attr,
  56. char *buf)
  57. {
  58. ide_drive_t *drive = to_ide_device(dev);
  59. return sprintf(buf, "%s\n", (char *)&drive->id[ATA_ID_SERNO]);
  60. }
  61. static DEVICE_ATTR(serial, 0400, serial_show, NULL);
  62. static DEVICE_ATTR(unload_heads, 0644, ide_park_show, ide_park_store);
  63. static struct attribute *ide_attrs[] = {
  64. &dev_attr_media.attr,
  65. &dev_attr_drivename.attr,
  66. &dev_attr_modalias.attr,
  67. &dev_attr_model.attr,
  68. &dev_attr_firmware.attr,
  69. &dev_attr_serial.attr,
  70. &dev_attr_unload_heads.attr,
  71. NULL,
  72. };
  73. static const struct attribute_group ide_attr_group = {
  74. .attrs = ide_attrs,
  75. };
  76. const struct attribute_group *ide_dev_groups[] = {
  77. &ide_attr_group,
  78. NULL,
  79. };
  80. static ssize_t store_delete_devices(struct device *portdev,
  81. struct device_attribute *attr,
  82. const char *buf, size_t n)
  83. {
  84. ide_hwif_t *hwif = dev_get_drvdata(portdev);
  85. if (strncmp(buf, "1", n))
  86. return -EINVAL;
  87. ide_port_unregister_devices(hwif);
  88. return n;
  89. };
  90. static DEVICE_ATTR(delete_devices, S_IWUSR, NULL, store_delete_devices);
  91. static ssize_t store_scan(struct device *portdev,
  92. struct device_attribute *attr,
  93. const char *buf, size_t n)
  94. {
  95. ide_hwif_t *hwif = dev_get_drvdata(portdev);
  96. if (strncmp(buf, "1", n))
  97. return -EINVAL;
  98. ide_port_unregister_devices(hwif);
  99. ide_port_scan(hwif);
  100. return n;
  101. };
  102. static DEVICE_ATTR(scan, S_IWUSR, NULL, store_scan);
  103. static struct device_attribute *ide_port_attrs[] = {
  104. &dev_attr_delete_devices,
  105. &dev_attr_scan,
  106. NULL
  107. };
  108. int ide_sysfs_register_port(ide_hwif_t *hwif)
  109. {
  110. int i, uninitialized_var(rc);
  111. for (i = 0; ide_port_attrs[i]; i++) {
  112. rc = device_create_file(hwif->portdev, ide_port_attrs[i]);
  113. if (rc)
  114. break;
  115. }
  116. return rc;
  117. }