GNU Linux-libre 4.19.304-gnu1
[releases.git] / drivers / staging / most / dim2 / sysfs.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * sysfs.c - MediaLB sysfs information
4  *
5  * Copyright (C) 2015, Microchip Technology Germany II GmbH & Co. KG
6  */
7
8 /* Author: Andrey Shvetsov <andrey.shvetsov@k2l.de> */
9
10 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
11
12 #include <linux/kernel.h>
13 #include "sysfs.h"
14 #include <linux/device.h>
15
16 static ssize_t state_show(struct device *dev, struct device_attribute *attr,
17                           char *buf)
18 {
19         bool state = dim2_sysfs_get_state_cb();
20
21         return sprintf(buf, "%s\n", state ? "locked" : "");
22 }
23
24 static DEVICE_ATTR_RO(state);
25
26 static struct attribute *dev_attrs[] = {
27         &dev_attr_state.attr,
28         NULL,
29 };
30
31 static struct attribute_group dev_attr_group = {
32         .attrs = dev_attrs,
33 };
34
35 static const struct attribute_group *dev_attr_groups[] = {
36         &dev_attr_group,
37         NULL,
38 };
39
40 int dim2_sysfs_probe(struct device *dev)
41 {
42         dev->groups = dev_attr_groups;
43         return device_register(dev);
44 }
45
46 void dim2_sysfs_destroy(struct device *dev)
47 {
48         device_unregister(dev);
49 }