Bartlomiej Zolnierkiewicz | ebdab07 | 2009-01-02 16:12:48 +0100 | [diff] [blame] | 1 | #include <linux/kernel.h> |
| 2 | #include <linux/ide.h> |
| 3 | |
| 4 | char *ide_media_string(ide_drive_t *drive) |
| 5 | { |
| 6 | switch (drive->media) { |
| 7 | case ide_disk: |
| 8 | return "disk"; |
| 9 | case ide_cdrom: |
| 10 | return "cdrom"; |
| 11 | case ide_tape: |
| 12 | return "tape"; |
| 13 | case ide_floppy: |
| 14 | return "floppy"; |
| 15 | case ide_optical: |
| 16 | return "optical"; |
| 17 | default: |
| 18 | return "UNKNOWN"; |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | static ssize_t media_show(struct device *dev, struct device_attribute *attr, |
| 23 | char *buf) |
| 24 | { |
| 25 | ide_drive_t *drive = to_ide_device(dev); |
| 26 | return sprintf(buf, "%s\n", ide_media_string(drive)); |
| 27 | } |
Greg Kroah-Hartman | fb3fed7 | 2013-10-07 18:27:35 -0700 | [diff] [blame] | 28 | static DEVICE_ATTR_RO(media); |
Bartlomiej Zolnierkiewicz | ebdab07 | 2009-01-02 16:12:48 +0100 | [diff] [blame] | 29 | |
| 30 | static ssize_t drivename_show(struct device *dev, struct device_attribute *attr, |
| 31 | char *buf) |
| 32 | { |
| 33 | ide_drive_t *drive = to_ide_device(dev); |
| 34 | return sprintf(buf, "%s\n", drive->name); |
| 35 | } |
Greg Kroah-Hartman | fb3fed7 | 2013-10-07 18:27:35 -0700 | [diff] [blame] | 36 | static DEVICE_ATTR_RO(drivename); |
Bartlomiej Zolnierkiewicz | ebdab07 | 2009-01-02 16:12:48 +0100 | [diff] [blame] | 37 | |
| 38 | static ssize_t modalias_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, "ide:m-%s\n", ide_media_string(drive)); |
| 43 | } |
Greg Kroah-Hartman | fb3fed7 | 2013-10-07 18:27:35 -0700 | [diff] [blame] | 44 | static DEVICE_ATTR_RO(modalias); |
Bartlomiej Zolnierkiewicz | ebdab07 | 2009-01-02 16:12:48 +0100 | [diff] [blame] | 45 | |
| 46 | static ssize_t model_show(struct device *dev, struct device_attribute *attr, |
| 47 | char *buf) |
| 48 | { |
| 49 | ide_drive_t *drive = to_ide_device(dev); |
| 50 | return sprintf(buf, "%s\n", (char *)&drive->id[ATA_ID_PROD]); |
| 51 | } |
Greg Kroah-Hartman | fb3fed7 | 2013-10-07 18:27:35 -0700 | [diff] [blame] | 52 | static DEVICE_ATTR_RO(model); |
Bartlomiej Zolnierkiewicz | ebdab07 | 2009-01-02 16:12:48 +0100 | [diff] [blame] | 53 | |
| 54 | static ssize_t firmware_show(struct device *dev, struct device_attribute *attr, |
| 55 | char *buf) |
| 56 | { |
| 57 | ide_drive_t *drive = to_ide_device(dev); |
| 58 | return sprintf(buf, "%s\n", (char *)&drive->id[ATA_ID_FW_REV]); |
| 59 | } |
Greg Kroah-Hartman | fb3fed7 | 2013-10-07 18:27:35 -0700 | [diff] [blame] | 60 | static DEVICE_ATTR_RO(firmware); |
Bartlomiej Zolnierkiewicz | ebdab07 | 2009-01-02 16:12:48 +0100 | [diff] [blame] | 61 | |
| 62 | static ssize_t serial_show(struct device *dev, struct device_attribute *attr, |
| 63 | char *buf) |
| 64 | { |
| 65 | ide_drive_t *drive = to_ide_device(dev); |
| 66 | return sprintf(buf, "%s\n", (char *)&drive->id[ATA_ID_SERNO]); |
| 67 | } |
Greg Kroah-Hartman | fb3fed7 | 2013-10-07 18:27:35 -0700 | [diff] [blame] | 68 | static DEVICE_ATTR(serial, 0400, serial_show, NULL); |
Bartlomiej Zolnierkiewicz | ebdab07 | 2009-01-02 16:12:48 +0100 | [diff] [blame] | 69 | |
Greg Kroah-Hartman | fb3fed7 | 2013-10-07 18:27:35 -0700 | [diff] [blame] | 70 | static DEVICE_ATTR(unload_heads, 0644, ide_park_show, ide_park_store); |
| 71 | |
| 72 | static struct attribute *ide_attrs[] = { |
| 73 | &dev_attr_media.attr, |
| 74 | &dev_attr_drivename.attr, |
| 75 | &dev_attr_modalias.attr, |
| 76 | &dev_attr_model.attr, |
| 77 | &dev_attr_firmware.attr, |
| 78 | &dev_attr_serial.attr, |
| 79 | &dev_attr_unload_heads.attr, |
| 80 | NULL, |
| 81 | }; |
| 82 | |
| 83 | static const struct attribute_group ide_attr_group = { |
| 84 | .attrs = ide_attrs, |
| 85 | }; |
| 86 | |
| 87 | const struct attribute_group *ide_dev_groups[] = { |
| 88 | &ide_attr_group, |
| 89 | NULL, |
Bartlomiej Zolnierkiewicz | ebdab07 | 2009-01-02 16:12:48 +0100 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | static ssize_t store_delete_devices(struct device *portdev, |
| 93 | struct device_attribute *attr, |
| 94 | const char *buf, size_t n) |
| 95 | { |
| 96 | ide_hwif_t *hwif = dev_get_drvdata(portdev); |
| 97 | |
| 98 | if (strncmp(buf, "1", n)) |
| 99 | return -EINVAL; |
| 100 | |
| 101 | ide_port_unregister_devices(hwif); |
| 102 | |
| 103 | return n; |
| 104 | }; |
| 105 | |
| 106 | static DEVICE_ATTR(delete_devices, S_IWUSR, NULL, store_delete_devices); |
| 107 | |
| 108 | static ssize_t store_scan(struct device *portdev, |
| 109 | struct device_attribute *attr, |
| 110 | const char *buf, size_t n) |
| 111 | { |
| 112 | ide_hwif_t *hwif = dev_get_drvdata(portdev); |
| 113 | |
| 114 | if (strncmp(buf, "1", n)) |
| 115 | return -EINVAL; |
| 116 | |
| 117 | ide_port_unregister_devices(hwif); |
| 118 | ide_port_scan(hwif); |
| 119 | |
| 120 | return n; |
| 121 | }; |
| 122 | |
| 123 | static DEVICE_ATTR(scan, S_IWUSR, NULL, store_scan); |
| 124 | |
| 125 | static struct device_attribute *ide_port_attrs[] = { |
| 126 | &dev_attr_delete_devices, |
| 127 | &dev_attr_scan, |
| 128 | NULL |
| 129 | }; |
| 130 | |
| 131 | int ide_sysfs_register_port(ide_hwif_t *hwif) |
| 132 | { |
| 133 | int i, uninitialized_var(rc); |
| 134 | |
| 135 | for (i = 0; ide_port_attrs[i]; i++) { |
| 136 | rc = device_create_file(hwif->portdev, ide_port_attrs[i]); |
| 137 | if (rc) |
| 138 | break; |
| 139 | } |
| 140 | |
| 141 | return rc; |
| 142 | } |