Loading...
1// SPDX-License-Identifier: GPL-2.0
2#include <linux/kernel.h>
3#include <linux/ide.h>
4
5char *ide_media_string(ide_drive_t *drive)
6{
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";
20 }
21}
22
23static ssize_t media_show(struct device *dev, struct device_attribute *attr,
24 char *buf)
25{
26 ide_drive_t *drive = to_ide_device(dev);
27 return sprintf(buf, "%s\n", ide_media_string(drive));
28}
29static DEVICE_ATTR_RO(media);
30
31static ssize_t drivename_show(struct device *dev, struct device_attribute *attr,
32 char *buf)
33{
34 ide_drive_t *drive = to_ide_device(dev);
35 return sprintf(buf, "%s\n", drive->name);
36}
37static DEVICE_ATTR_RO(drivename);
38
39static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
40 char *buf)
41{
42 ide_drive_t *drive = to_ide_device(dev);
43 return sprintf(buf, "ide:m-%s\n", ide_media_string(drive));
44}
45static DEVICE_ATTR_RO(modalias);
46
47static ssize_t model_show(struct device *dev, struct device_attribute *attr,
48 char *buf)
49{
50 ide_drive_t *drive = to_ide_device(dev);
51 return sprintf(buf, "%s\n", (char *)&drive->id[ATA_ID_PROD]);
52}
53static DEVICE_ATTR_RO(model);
54
55static ssize_t firmware_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_FW_REV]);
60}
61static DEVICE_ATTR_RO(firmware);
62
63static ssize_t serial_show(struct device *dev, struct device_attribute *attr,
64 char *buf)
65{
66 ide_drive_t *drive = to_ide_device(dev);
67 return sprintf(buf, "%s\n", (char *)&drive->id[ATA_ID_SERNO]);
68}
69static DEVICE_ATTR(serial, 0400, serial_show, NULL);
70
71static DEVICE_ATTR(unload_heads, 0644, ide_park_show, ide_park_store);
72
73static 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,
82};
83
84static const struct attribute_group ide_attr_group = {
85 .attrs = ide_attrs,
86};
87
88const struct attribute_group *ide_dev_groups[] = {
89 &ide_attr_group,
90 NULL,
91};
92
93static ssize_t store_delete_devices(struct device *portdev,
94 struct device_attribute *attr,
95 const char *buf, size_t n)
96{
97 ide_hwif_t *hwif = dev_get_drvdata(portdev);
98
99 if (strncmp(buf, "1", n))
100 return -EINVAL;
101
102 ide_port_unregister_devices(hwif);
103
104 return n;
105};
106
107static DEVICE_ATTR(delete_devices, S_IWUSR, NULL, store_delete_devices);
108
109static ssize_t store_scan(struct device *portdev,
110 struct device_attribute *attr,
111 const char *buf, size_t n)
112{
113 ide_hwif_t *hwif = dev_get_drvdata(portdev);
114
115 if (strncmp(buf, "1", n))
116 return -EINVAL;
117
118 ide_port_unregister_devices(hwif);
119 ide_port_scan(hwif);
120
121 return n;
122};
123
124static DEVICE_ATTR(scan, S_IWUSR, NULL, store_scan);
125
126static struct device_attribute *ide_port_attrs[] = {
127 &dev_attr_delete_devices,
128 &dev_attr_scan,
129 NULL
130};
131
132int ide_sysfs_register_port(ide_hwif_t *hwif)
133{
134 int i, rc;
135
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;
140 }
141
142 return rc;
143}
1#include <linux/kernel.h>
2#include <linux/ide.h>
3
4char *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
22static 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}
28
29static ssize_t drivename_show(struct device *dev, struct device_attribute *attr,
30 char *buf)
31{
32 ide_drive_t *drive = to_ide_device(dev);
33 return sprintf(buf, "%s\n", drive->name);
34}
35
36static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
37 char *buf)
38{
39 ide_drive_t *drive = to_ide_device(dev);
40 return sprintf(buf, "ide:m-%s\n", ide_media_string(drive));
41}
42
43static ssize_t model_show(struct device *dev, struct device_attribute *attr,
44 char *buf)
45{
46 ide_drive_t *drive = to_ide_device(dev);
47 return sprintf(buf, "%s\n", (char *)&drive->id[ATA_ID_PROD]);
48}
49
50static ssize_t firmware_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_FW_REV]);
55}
56
57static ssize_t serial_show(struct device *dev, struct device_attribute *attr,
58 char *buf)
59{
60 ide_drive_t *drive = to_ide_device(dev);
61 return sprintf(buf, "%s\n", (char *)&drive->id[ATA_ID_SERNO]);
62}
63
64struct device_attribute ide_dev_attrs[] = {
65 __ATTR_RO(media),
66 __ATTR_RO(drivename),
67 __ATTR_RO(modalias),
68 __ATTR_RO(model),
69 __ATTR_RO(firmware),
70 __ATTR(serial, 0400, serial_show, NULL),
71 __ATTR(unload_heads, 0644, ide_park_show, ide_park_store),
72 __ATTR_NULL
73};
74
75static ssize_t store_delete_devices(struct device *portdev,
76 struct device_attribute *attr,
77 const char *buf, size_t n)
78{
79 ide_hwif_t *hwif = dev_get_drvdata(portdev);
80
81 if (strncmp(buf, "1", n))
82 return -EINVAL;
83
84 ide_port_unregister_devices(hwif);
85
86 return n;
87};
88
89static DEVICE_ATTR(delete_devices, S_IWUSR, NULL, store_delete_devices);
90
91static 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
97 if (strncmp(buf, "1", n))
98 return -EINVAL;
99
100 ide_port_unregister_devices(hwif);
101 ide_port_scan(hwif);
102
103 return n;
104};
105
106static DEVICE_ATTR(scan, S_IWUSR, NULL, store_scan);
107
108static struct device_attribute *ide_port_attrs[] = {
109 &dev_attr_delete_devices,
110 &dev_attr_scan,
111 NULL
112};
113
114int ide_sysfs_register_port(ide_hwif_t *hwif)
115{
116 int i, uninitialized_var(rc);
117
118 for (i = 0; ide_port_attrs[i]; i++) {
119 rc = device_create_file(hwif->portdev, ide_port_attrs[i]);
120 if (rc)
121 break;
122 }
123
124 return rc;
125}