Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[cris-mirror.git] / drivers / ide / ide-sysfs.c
blobb9dfeb2e8bd6603c20dc9e02554adc0eff6ed72c
1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/kernel.h>
3 #include <linux/ide.h>
5 char *ide_media_string(ide_drive_t *drive)
7 switch (drive->media) {
8 case ide_disk:
9 return "disk";
10 case ide_cdrom:
11 return "cdrom";
12 case ide_tape:
13 return "tape";
14 case ide_floppy:
15 return "floppy";
16 case ide_optical:
17 return "optical";
18 default:
19 return "UNKNOWN";
23 static ssize_t media_show(struct device *dev, struct device_attribute *attr,
24 char *buf)
26 ide_drive_t *drive = to_ide_device(dev);
27 return sprintf(buf, "%s\n", ide_media_string(drive));
29 static DEVICE_ATTR_RO(media);
31 static ssize_t drivename_show(struct device *dev, struct device_attribute *attr,
32 char *buf)
34 ide_drive_t *drive = to_ide_device(dev);
35 return sprintf(buf, "%s\n", drive->name);
37 static DEVICE_ATTR_RO(drivename);
39 static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
40 char *buf)
42 ide_drive_t *drive = to_ide_device(dev);
43 return sprintf(buf, "ide:m-%s\n", ide_media_string(drive));
45 static DEVICE_ATTR_RO(modalias);
47 static ssize_t model_show(struct device *dev, struct device_attribute *attr,
48 char *buf)
50 ide_drive_t *drive = to_ide_device(dev);
51 return sprintf(buf, "%s\n", (char *)&drive->id[ATA_ID_PROD]);
53 static DEVICE_ATTR_RO(model);
55 static ssize_t firmware_show(struct device *dev, struct device_attribute *attr,
56 char *buf)
58 ide_drive_t *drive = to_ide_device(dev);
59 return sprintf(buf, "%s\n", (char *)&drive->id[ATA_ID_FW_REV]);
61 static DEVICE_ATTR_RO(firmware);
63 static ssize_t serial_show(struct device *dev, struct device_attribute *attr,
64 char *buf)
66 ide_drive_t *drive = to_ide_device(dev);
67 return sprintf(buf, "%s\n", (char *)&drive->id[ATA_ID_SERNO]);
69 static DEVICE_ATTR(serial, 0400, serial_show, NULL);
71 static DEVICE_ATTR(unload_heads, 0644, ide_park_show, ide_park_store);
73 static struct attribute *ide_attrs[] = {
74 &dev_attr_media.attr,
75 &dev_attr_drivename.attr,
76 &dev_attr_modalias.attr,
77 &dev_attr_model.attr,
78 &dev_attr_firmware.attr,
79 &dev_attr_serial.attr,
80 &dev_attr_unload_heads.attr,
81 NULL,
84 static const struct attribute_group ide_attr_group = {
85 .attrs = ide_attrs,
88 const struct attribute_group *ide_dev_groups[] = {
89 &ide_attr_group,
90 NULL,
93 static ssize_t store_delete_devices(struct device *portdev,
94 struct device_attribute *attr,
95 const char *buf, size_t n)
97 ide_hwif_t *hwif = dev_get_drvdata(portdev);
99 if (strncmp(buf, "1", n))
100 return -EINVAL;
102 ide_port_unregister_devices(hwif);
104 return n;
107 static DEVICE_ATTR(delete_devices, S_IWUSR, NULL, store_delete_devices);
109 static ssize_t store_scan(struct device *portdev,
110 struct device_attribute *attr,
111 const char *buf, size_t n)
113 ide_hwif_t *hwif = dev_get_drvdata(portdev);
115 if (strncmp(buf, "1", n))
116 return -EINVAL;
118 ide_port_unregister_devices(hwif);
119 ide_port_scan(hwif);
121 return n;
124 static DEVICE_ATTR(scan, S_IWUSR, NULL, store_scan);
126 static struct device_attribute *ide_port_attrs[] = {
127 &dev_attr_delete_devices,
128 &dev_attr_scan,
129 NULL
132 int ide_sysfs_register_port(ide_hwif_t *hwif)
134 int i, uninitialized_var(rc);
136 for (i = 0; ide_port_attrs[i]; i++) {
137 rc = device_create_file(hwif->portdev, ide_port_attrs[i]);
138 if (rc)
139 break;
142 return rc;