blob: 84a6a9e08d64d450ef2828e72d75da8949cf5052 [file] [log] [blame]
Bartlomiej Zolnierkiewiczebdab072009-01-02 16:12:48 +01001#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}
Greg Kroah-Hartmanfb3fed72013-10-07 18:27:35 -070028static DEVICE_ATTR_RO(media);
Bartlomiej Zolnierkiewiczebdab072009-01-02 16:12:48 +010029
30static 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-Hartmanfb3fed72013-10-07 18:27:35 -070036static DEVICE_ATTR_RO(drivename);
Bartlomiej Zolnierkiewiczebdab072009-01-02 16:12:48 +010037
38static 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-Hartmanfb3fed72013-10-07 18:27:35 -070044static DEVICE_ATTR_RO(modalias);
Bartlomiej Zolnierkiewiczebdab072009-01-02 16:12:48 +010045
46static 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-Hartmanfb3fed72013-10-07 18:27:35 -070052static DEVICE_ATTR_RO(model);
Bartlomiej Zolnierkiewiczebdab072009-01-02 16:12:48 +010053
54static 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-Hartmanfb3fed72013-10-07 18:27:35 -070060static DEVICE_ATTR_RO(firmware);
Bartlomiej Zolnierkiewiczebdab072009-01-02 16:12:48 +010061
62static 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-Hartmanfb3fed72013-10-07 18:27:35 -070068static DEVICE_ATTR(serial, 0400, serial_show, NULL);
Bartlomiej Zolnierkiewiczebdab072009-01-02 16:12:48 +010069
Greg Kroah-Hartmanfb3fed72013-10-07 18:27:35 -070070static DEVICE_ATTR(unload_heads, 0644, ide_park_show, ide_park_store);
71
72static 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
83static const struct attribute_group ide_attr_group = {
84 .attrs = ide_attrs,
85};
86
87const struct attribute_group *ide_dev_groups[] = {
88 &ide_attr_group,
89 NULL,
Bartlomiej Zolnierkiewiczebdab072009-01-02 16:12:48 +010090};
91
92static 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
106static DEVICE_ATTR(delete_devices, S_IWUSR, NULL, store_delete_devices);
107
108static 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
123static DEVICE_ATTR(scan, S_IWUSR, NULL, store_scan);
124
125static struct device_attribute *ide_port_attrs[] = {
126 &dev_attr_delete_devices,
127 &dev_attr_scan,
128 NULL
129};
130
131int 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}