2 * dim2_sysfs.c - MediaLB sysfs information
4 * Copyright (C) 2015, Microchip Technology Germany II GmbH & Co. KG
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
11 * This file is licensed under GPLv2.
14 /* Author: Andrey Shvetsov <andrey.shvetsov@k2l.de> */
16 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
18 #include <linux/kernel.h>
19 #include "dim2_sysfs.h"
22 struct attribute attr;
23 ssize_t (*show)(struct medialb_bus *bus, char *buf);
24 ssize_t (*store)(struct medialb_bus *bus, const char *buf,
28 static ssize_t state_show(struct medialb_bus *bus, char *buf)
30 bool state = dim2_sysfs_get_state_cb();
32 return sprintf(buf, "%s\n", state ? "locked" : "");
35 static struct bus_attr state_attr = __ATTR_RO(state);
37 static struct attribute *bus_default_attrs[] = {
42 static struct attribute_group bus_attr_group = {
43 .attrs = bus_default_attrs,
46 static void bus_kobj_release(struct kobject *kobj)
50 static ssize_t bus_kobj_attr_show(struct kobject *kobj, struct attribute *attr,
53 struct medialb_bus *bus =
54 container_of(kobj, struct medialb_bus, kobj_group);
55 struct bus_attr *xattr = container_of(attr, struct bus_attr, attr);
60 return xattr->show(bus, buf);
63 static ssize_t bus_kobj_attr_store(struct kobject *kobj, struct attribute *attr,
64 const char *buf, size_t count)
66 struct medialb_bus *bus =
67 container_of(kobj, struct medialb_bus, kobj_group);
68 struct bus_attr *xattr = container_of(attr, struct bus_attr, attr);
73 return xattr->store(bus, buf, count);
76 static struct sysfs_ops const bus_kobj_sysfs_ops = {
77 .show = bus_kobj_attr_show,
78 .store = bus_kobj_attr_store,
81 static struct kobj_type bus_ktype = {
82 .release = bus_kobj_release,
83 .sysfs_ops = &bus_kobj_sysfs_ops,
86 int dim2_sysfs_probe(struct medialb_bus *bus, struct kobject *parent_kobj)
90 kobject_init(&bus->kobj_group, &bus_ktype);
91 err = kobject_add(&bus->kobj_group, parent_kobj, "bus");
93 pr_err("kobject_add() failed: %d\n", err);
97 err = sysfs_create_group(&bus->kobj_group, &bus_attr_group);
99 pr_err("sysfs_create_group() failed: %d\n", err);
100 goto err_create_group;
106 kobject_put(&bus->kobj_group);
112 void dim2_sysfs_destroy(struct medialb_bus *bus)
114 kobject_put(&bus->kobj_group);