1 #include <linux/kernel.h>
2 #include <linux/ide.h>
3
ide_media_string(ide_drive_t * drive)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
media_show(struct device * dev,struct device_attribute * attr,char * buf)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 }
28 static DEVICE_ATTR_RO(media);
29
drivename_show(struct device * dev,struct device_attribute * attr,char * buf)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 }
36 static DEVICE_ATTR_RO(drivename);
37
modalias_show(struct device * dev,struct device_attribute * attr,char * buf)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 }
44 static DEVICE_ATTR_RO(modalias);
45
model_show(struct device * dev,struct device_attribute * attr,char * buf)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 }
52 static DEVICE_ATTR_RO(model);
53
firmware_show(struct device * dev,struct device_attribute * attr,char * buf)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 }
60 static DEVICE_ATTR_RO(firmware);
61
serial_show(struct device * dev,struct device_attribute * attr,char * buf)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 }
68 static DEVICE_ATTR(serial, 0400, serial_show, NULL);
69
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,
90 };
91
store_delete_devices(struct device * portdev,struct device_attribute * attr,const char * buf,size_t n)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
store_scan(struct device * portdev,struct device_attribute * attr,const char * buf,size_t n)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
ide_sysfs_register_port(ide_hwif_t * hwif)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 }
143