1 // SPDX-License-Identifier: GPL-2.0
3 * arch/sh/drivers/dma/dma-sysfs.c
5 * sysfs interface for SH DMA API
7 * Copyright (C) 2004 - 2006 Paul Mundt
9 #include <linux/kernel.h>
10 #include <linux/init.h>
11 #include <linux/stat.h>
12 #include <linux/device.h>
13 #include <linux/platform_device.h>
14 #include <linux/err.h>
15 #include <linux/string.h>
18 static const struct bus_type dma_subsys
= {
23 static ssize_t
dma_show_devices(struct device
*dev
,
24 struct device_attribute
*attr
, char *buf
)
29 for (i
= 0; i
< 16; i
++) {
30 struct dma_info
*info
= get_dma_info(i
);
31 struct dma_channel
*channel
= get_dma_channel(i
);
33 if (unlikely(!info
) || !channel
)
36 len
+= sprintf(buf
+ len
, "%2d: %14s %s\n",
37 channel
->chan
, info
->name
,
44 static DEVICE_ATTR(devices
, S_IRUGO
, dma_show_devices
, NULL
);
46 static int __init
dma_subsys_init(void)
48 struct device
*dev_root
;
51 ret
= subsys_system_register(&dma_subsys
, NULL
);
55 dev_root
= bus_get_dev_root(&dma_subsys
);
57 ret
= device_create_file(dev_root
, &dev_attr_devices
);
62 postcore_initcall(dma_subsys_init
);
64 static ssize_t
dma_show_dev_id(struct device
*dev
,
65 struct device_attribute
*attr
, char *buf
)
67 struct dma_channel
*channel
= to_dma_channel(dev
);
68 return sprintf(buf
, "%s\n", channel
->dev_id
);
71 static ssize_t
dma_store_dev_id(struct device
*dev
,
72 struct device_attribute
*attr
,
73 const char *buf
, size_t count
)
75 struct dma_channel
*channel
= to_dma_channel(dev
);
76 strcpy(channel
->dev_id
, buf
);
80 static DEVICE_ATTR(dev_id
, S_IRUGO
| S_IWUSR
, dma_show_dev_id
, dma_store_dev_id
);
82 static ssize_t
dma_store_config(struct device
*dev
,
83 struct device_attribute
*attr
,
84 const char *buf
, size_t count
)
86 struct dma_channel
*channel
= to_dma_channel(dev
);
89 config
= simple_strtoul(buf
, NULL
, 0);
90 dma_configure_channel(channel
->vchan
, config
);
95 static DEVICE_ATTR(config
, S_IWUSR
, NULL
, dma_store_config
);
97 static ssize_t
dma_show_mode(struct device
*dev
,
98 struct device_attribute
*attr
, char *buf
)
100 struct dma_channel
*channel
= to_dma_channel(dev
);
101 return sprintf(buf
, "0x%08x\n", channel
->mode
);
104 static ssize_t
dma_store_mode(struct device
*dev
,
105 struct device_attribute
*attr
,
106 const char *buf
, size_t count
)
108 struct dma_channel
*channel
= to_dma_channel(dev
);
109 channel
->mode
= simple_strtoul(buf
, NULL
, 0);
113 static DEVICE_ATTR(mode
, S_IRUGO
| S_IWUSR
, dma_show_mode
, dma_store_mode
);
115 #define dma_ro_attr(field, fmt) \
116 static ssize_t dma_show_##field(struct device *dev, \
117 struct device_attribute *attr, char *buf)\
119 struct dma_channel *channel = to_dma_channel(dev); \
120 return sprintf(buf, fmt, channel->field); \
122 static DEVICE_ATTR(field, S_IRUGO, dma_show_##field, NULL);
124 dma_ro_attr(count
, "0x%08x\n");
125 dma_ro_attr(flags
, "0x%08lx\n");
127 int dma_create_sysfs_files(struct dma_channel
*chan
, struct dma_info
*info
)
129 struct device
*dev
= &chan
->dev
;
133 dev
->id
= chan
->vchan
;
134 dev
->bus
= &dma_subsys
;
136 ret
= device_register(dev
);
140 ret
|= device_create_file(dev
, &dev_attr_dev_id
);
141 ret
|= device_create_file(dev
, &dev_attr_count
);
142 ret
|= device_create_file(dev
, &dev_attr_mode
);
143 ret
|= device_create_file(dev
, &dev_attr_flags
);
144 ret
|= device_create_file(dev
, &dev_attr_config
);
147 dev_err(&info
->pdev
->dev
, "Failed creating attrs\n");
151 snprintf(name
, sizeof(name
), "dma%d", chan
->chan
);
152 return sysfs_create_link(&info
->pdev
->dev
.kobj
, &dev
->kobj
, name
);
155 void dma_remove_sysfs_files(struct dma_channel
*chan
, struct dma_info
*info
)
157 struct device
*dev
= &chan
->dev
;
160 device_remove_file(dev
, &dev_attr_dev_id
);
161 device_remove_file(dev
, &dev_attr_count
);
162 device_remove_file(dev
, &dev_attr_mode
);
163 device_remove_file(dev
, &dev_attr_flags
);
164 device_remove_file(dev
, &dev_attr_config
);
166 snprintf(name
, sizeof(name
), "dma%d", chan
->chan
);
167 sysfs_remove_link(&info
->pdev
->dev
.kobj
, name
);
169 device_unregister(dev
);