PM / sleep: Asynchronous threads for suspend_noirq
[linux/fpc-iii.git] / drivers / ide / ide-sysfs.c
blob84a6a9e08d64d450ef2828e72d75da8949cf5052
1 #include <linux/kernel.h>
2 #include <linux/ide.h>
4 char *ide_media_string(ide_drive_t *drive)
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";
22 static ssize_t media_show(struct device *dev, struct device_attribute *attr,
23 char *buf)
25 ide_drive_t *drive = to_ide_device(dev);
26 return sprintf(buf, "%s\n", ide_media_string(drive));
28 static DEVICE_ATTR_RO(media);
30 static ssize_t drivename_show(struct device *dev, struct device_attribute *attr,
31 char *buf)
33 ide_drive_t *drive = to_ide_device(dev);
34 return sprintf(buf, "%s\n", drive->name);
36 static DEVICE_ATTR_RO(drivename);
38 static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
39 char *buf)
41 ide_drive_t *drive = to_ide_device(dev);
42 return sprintf(buf, "ide:m-%s\n", ide_media_string(drive));
44 static DEVICE_ATTR_RO(modalias);
46 static ssize_t model_show(struct device *dev, struct device_attribute *attr,
47 char *buf)
49 ide_drive_t *drive = to_ide_device(dev);
50 return sprintf(buf, "%s\n", (char *)&drive->id[ATA_ID_PROD]);
52 static DEVICE_ATTR_RO(model);
54 static ssize_t firmware_show(struct device *dev, struct device_attribute *attr,
55 char *buf)
57 ide_drive_t *drive = to_ide_device(dev);
58 return sprintf(buf, "%s\n", (char *)&drive->id[ATA_ID_FW_REV]);
60 static DEVICE_ATTR_RO(firmware);
62 static ssize_t serial_show(struct device *dev, struct device_attribute *attr,
63 char *buf)
65 ide_drive_t *drive = to_ide_device(dev);
66 return sprintf(buf, "%s\n", (char *)&drive->id[ATA_ID_SERNO]);
68 static DEVICE_ATTR(serial, 0400, serial_show, NULL);
70 static DEVICE_ATTR(unload_heads, 0644, ide_park_show, ide_park_store);
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,
83 static const struct attribute_group ide_attr_group = {
84 .attrs = ide_attrs,
87 const struct attribute_group *ide_dev_groups[] = {
88 &ide_attr_group,
89 NULL,
92 static ssize_t store_delete_devices(struct device *portdev,
93 struct device_attribute *attr,
94 const char *buf, size_t n)
96 ide_hwif_t *hwif = dev_get_drvdata(portdev);
98 if (strncmp(buf, "1", n))
99 return -EINVAL;
101 ide_port_unregister_devices(hwif);
103 return n;
106 static DEVICE_ATTR(delete_devices, S_IWUSR, NULL, store_delete_devices);
108 static ssize_t store_scan(struct device *portdev,
109 struct device_attribute *attr,
110 const char *buf, size_t n)
112 ide_hwif_t *hwif = dev_get_drvdata(portdev);
114 if (strncmp(buf, "1", n))
115 return -EINVAL;
117 ide_port_unregister_devices(hwif);
118 ide_port_scan(hwif);
120 return n;
123 static DEVICE_ATTR(scan, S_IWUSR, NULL, store_scan);
125 static struct device_attribute *ide_port_attrs[] = {
126 &dev_attr_delete_devices,
127 &dev_attr_scan,
128 NULL
131 int ide_sysfs_register_port(ide_hwif_t *hwif)
133 int i, uninitialized_var(rc);
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;
141 return rc;