Skip to content

Commit ebdab07

Browse files
committed
ide: move sysfs support to ide-sysfs.c
While at it: - media_string() -> ide_media_string() There should be no functional changes caused by this patch. Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
1 parent 24630dc commit ebdab07

5 files changed

Lines changed: 132 additions & 123 deletions

File tree

‎drivers/ide/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
EXTRA_CFLAGS += -Idrivers/ide
66

77
ide-core-y += ide.o ide-ioctls.o ide-io.o ide-iops.o ide-lib.o ide-probe.o \
8-
ide-taskfile.o ide-pm.o ide-park.o ide-pio-blacklist.o
8+
ide-taskfile.o ide-pm.o ide-park.o ide-pio-blacklist.o ide-sysfs.o
99

1010
# core IDE code
1111
ide-core-$(CONFIG_IDE_TIMINGS) += ide-timings.o

‎drivers/ide/ide-probe.c‎

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,58 +1420,6 @@ static void ide_port_cable_detect(ide_hwif_t *hwif)
14201420
}
14211421
}
14221422

1423-
static ssize_t store_delete_devices(struct device *portdev,
1424-
struct device_attribute *attr,
1425-
const char *buf, size_t n)
1426-
{
1427-
ide_hwif_t *hwif = dev_get_drvdata(portdev);
1428-
1429-
if (strncmp(buf, "1", n))
1430-
return -EINVAL;
1431-
1432-
ide_port_unregister_devices(hwif);
1433-
1434-
return n;
1435-
};
1436-
1437-
static DEVICE_ATTR(delete_devices, S_IWUSR, NULL, store_delete_devices);
1438-
1439-
static ssize_t store_scan(struct device *portdev,
1440-
struct device_attribute *attr,
1441-
const char *buf, size_t n)
1442-
{
1443-
ide_hwif_t *hwif = dev_get_drvdata(portdev);
1444-
1445-
if (strncmp(buf, "1", n))
1446-
return -EINVAL;
1447-
1448-
ide_port_unregister_devices(hwif);
1449-
ide_port_scan(hwif);
1450-
1451-
return n;
1452-
};
1453-
1454-
static DEVICE_ATTR(scan, S_IWUSR, NULL, store_scan);
1455-
1456-
static struct device_attribute *ide_port_attrs[] = {
1457-
&dev_attr_delete_devices,
1458-
&dev_attr_scan,
1459-
NULL
1460-
};
1461-
1462-
static int ide_sysfs_register_port(ide_hwif_t *hwif)
1463-
{
1464-
int i, uninitialized_var(rc);
1465-
1466-
for (i = 0; ide_port_attrs[i]; i++) {
1467-
rc = device_create_file(hwif->portdev, ide_port_attrs[i]);
1468-
if (rc)
1469-
break;
1470-
}
1471-
1472-
return rc;
1473-
}
1474-
14751423
static unsigned int ide_indexes;
14761424

14771425
/**

‎drivers/ide/ide-sysfs.c‎

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
#include <linux/kernel.h>
2+
#include <linux/ide.h>
3+
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+
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+
29+
static 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+
36+
static 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+
43+
static 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+
50+
static 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+
57+
static 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+
64+
struct 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+
75+
static 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+
89+
static DEVICE_ATTR(delete_devices, S_IWUSR, NULL, store_delete_devices);
90+
91+
static 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+
106+
static DEVICE_ATTR(scan, S_IWUSR, NULL, store_scan);
107+
108+
static struct device_attribute *ide_port_attrs[] = {
109+
&dev_attr_delete_devices,
110+
&dev_attr_scan,
111+
NULL
112+
};
113+
114+
int 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+
}

‎drivers/ide/ide.c‎

Lines changed: 2 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -440,81 +440,13 @@ static int ide_bus_match(struct device *dev, struct device_driver *drv)
440440
return 1;
441441
}
442442

443-
static char *media_string(ide_drive_t *drive)
444-
{
445-
switch (drive->media) {
446-
case ide_disk:
447-
return "disk";
448-
case ide_cdrom:
449-
return "cdrom";
450-
case ide_tape:
451-
return "tape";
452-
case ide_floppy:
453-
return "floppy";
454-
case ide_optical:
455-
return "optical";
456-
default:
457-
return "UNKNOWN";
458-
}
459-
}
460-
461-
static ssize_t media_show(struct device *dev, struct device_attribute *attr, char *buf)
462-
{
463-
ide_drive_t *drive = to_ide_device(dev);
464-
return sprintf(buf, "%s\n", media_string(drive));
465-
}
466-
467-
static ssize_t drivename_show(struct device *dev, struct device_attribute *attr, char *buf)
468-
{
469-
ide_drive_t *drive = to_ide_device(dev);
470-
return sprintf(buf, "%s\n", drive->name);
471-
}
472-
473-
static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, char *buf)
474-
{
475-
ide_drive_t *drive = to_ide_device(dev);
476-
return sprintf(buf, "ide:m-%s\n", media_string(drive));
477-
}
478-
479-
static ssize_t model_show(struct device *dev, struct device_attribute *attr,
480-
char *buf)
481-
{
482-
ide_drive_t *drive = to_ide_device(dev);
483-
return sprintf(buf, "%s\n", (char *)&drive->id[ATA_ID_PROD]);
484-
}
485-
486-
static ssize_t firmware_show(struct device *dev, struct device_attribute *attr,
487-
char *buf)
488-
{
489-
ide_drive_t *drive = to_ide_device(dev);
490-
return sprintf(buf, "%s\n", (char *)&drive->id[ATA_ID_FW_REV]);
491-
}
492-
493-
static ssize_t serial_show(struct device *dev, struct device_attribute *attr,
494-
char *buf)
495-
{
496-
ide_drive_t *drive = to_ide_device(dev);
497-
return sprintf(buf, "%s\n", (char *)&drive->id[ATA_ID_SERNO]);
498-
}
499-
500-
static struct device_attribute ide_dev_attrs[] = {
501-
__ATTR_RO(media),
502-
__ATTR_RO(drivename),
503-
__ATTR_RO(modalias),
504-
__ATTR_RO(model),
505-
__ATTR_RO(firmware),
506-
__ATTR(serial, 0400, serial_show, NULL),
507-
__ATTR(unload_heads, 0644, ide_park_show, ide_park_store),
508-
__ATTR_NULL
509-
};
510-
511443
static int ide_uevent(struct device *dev, struct kobj_uevent_env *env)
512444
{
513445
ide_drive_t *drive = to_ide_device(dev);
514446

515-
add_uevent_var(env, "MEDIA=%s", media_string(drive));
447+
add_uevent_var(env, "MEDIA=%s", ide_media_string(drive));
516448
add_uevent_var(env, "DRIVENAME=%s", drive->name);
517-
add_uevent_var(env, "MODALIAS=ide:m-%s", media_string(drive));
449+
add_uevent_var(env, "MODALIAS=ide:m-%s", ide_media_string(drive));
518450
return 0;
519451
}
520452

‎include/linux/ide.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,6 +1533,7 @@ void ide_unregister_region(struct gendisk *);
15331533
void ide_undecoded_slave(ide_drive_t *);
15341534

15351535
void ide_port_apply_params(ide_hwif_t *);
1536+
int ide_sysfs_register_port(ide_hwif_t *);
15361537

15371538
struct ide_host *ide_host_alloc(const struct ide_port_info *, hw_regs_t **);
15381539
void ide_host_free(struct ide_host *);
@@ -1627,6 +1628,9 @@ extern struct mutex ide_cfg_mtx;
16271628

16281629
#define local_irq_set(flags) do { local_save_flags((flags)); local_irq_enable_in_hardirq(); } while (0)
16291630

1631+
char *ide_media_string(ide_drive_t *);
1632+
1633+
extern struct device_attribute ide_dev_attrs[];
16301634
extern struct bus_type ide_bus_type;
16311635
extern struct class *ide_port_class;
16321636

0 commit comments

Comments
 (0)