Commit c69fb76e8f53b36b81fd7c8a1ed251aaf6bb0386
Committed by
David S. Miller
1 parent
005066122b
Exists in
master
and in
4 other branches
atm/adummy: add syfs DEVICE_ATTR to change signal
Signed-off-by: Karl Hiramoto <karl@hiramoto.org> Signed-off-by: David S. Miller <davem@davemloft.net>
Showing 1 changed file with 39 additions and 0 deletions Side-by-side Diff
drivers/atm/adummy.c
... | ... | @@ -40,6 +40,42 @@ |
40 | 40 | |
41 | 41 | static LIST_HEAD(adummy_devs); |
42 | 42 | |
43 | +static ssize_t __set_signal(struct device *dev, | |
44 | + struct device_attribute *attr, | |
45 | + const char *buf, size_t len) | |
46 | +{ | |
47 | + struct atm_dev *atm_dev = container_of(dev, struct atm_dev, class_dev); | |
48 | + int signal; | |
49 | + | |
50 | + if (sscanf(buf, "%d", &signal) == 1) { | |
51 | + | |
52 | + if (signal < ATM_PHY_SIG_LOST || signal > ATM_PHY_SIG_FOUND) | |
53 | + signal = ATM_PHY_SIG_UNKNOWN; | |
54 | + | |
55 | + atm_dev_signal_change(atm_dev, signal); | |
56 | + return 1; | |
57 | + } | |
58 | + return -EINVAL; | |
59 | +} | |
60 | + | |
61 | +static ssize_t __show_signal(struct device *dev, | |
62 | + struct device_attribute *attr, char *buf) | |
63 | +{ | |
64 | + struct atm_dev *atm_dev = container_of(dev, struct atm_dev, class_dev); | |
65 | + return sprintf(buf, "%d\n", atm_dev->signal); | |
66 | +} | |
67 | +static DEVICE_ATTR(signal, 0644, __show_signal, __set_signal); | |
68 | + | |
69 | +static struct attribute *adummy_attrs[] = { | |
70 | + &dev_attr_signal.attr, | |
71 | + NULL | |
72 | +}; | |
73 | + | |
74 | +static struct attribute_group adummy_group_attrs = { | |
75 | + .name = NULL, /* We want them in dev's root folder */ | |
76 | + .attrs = adummy_attrs | |
77 | +}; | |
78 | + | |
43 | 79 | static int __init |
44 | 80 | adummy_start(struct atm_dev *dev) |
45 | 81 | { |
... | ... | @@ -127,6 +163,9 @@ |
127 | 163 | |
128 | 164 | adummy_dev->atm_dev = atm_dev; |
129 | 165 | atm_dev->dev_data = adummy_dev; |
166 | + | |
167 | + if (sysfs_create_group(&atm_dev->class_dev.kobj, &adummy_group_attrs)) | |
168 | + dev_err(&atm_dev->class_dev, "Could not register attrs for adummy\n"); | |
130 | 169 | |
131 | 170 | if (adummy_start(atm_dev)) { |
132 | 171 | printk(KERN_ERR DEV_LABEL ": adummy_start() failed\n"); |