2 * arch/sh/drivers/dma/dma-sysfs.c
4 * sysfs interface for SH DMA API
6 * Copyright (C) 2004 Paul Mundt
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file "COPYING" in the main directory of this archive
12 #include <linux/kernel.h>
13 #include <linux/init.h>
14 #include <linux/sysdev.h>
15 #include <linux/module.h>
16 #include <linux/string.h>
19 static struct sysdev_class dma_sysclass = {
23 EXPORT_SYMBOL(dma_sysclass);
25 static ssize_t dma_show_devices(struct sys_device *dev, char *buf)
30 for (i = 0; i < MAX_DMA_CHANNELS; i++) {
31 struct dma_info *info = get_dma_info(i);
32 struct dma_channel *channel = &info->channels[i];
34 len += sprintf(buf + len, "%2d: %14s %s\n",
35 channel->chan, info->name,
42 static SYSDEV_ATTR(devices, S_IRUGO, dma_show_devices, NULL);
44 static int __init dma_sysclass_init(void)
48 ret = sysdev_class_register(&dma_sysclass);
50 sysfs_create_file(&dma_sysclass.kset.kobj, &attr_devices.attr);
55 postcore_initcall(dma_sysclass_init);
57 static ssize_t dma_show_dev_id(struct sys_device *dev, char *buf)
59 struct dma_channel *channel = to_dma_channel(dev);
60 return sprintf(buf, "%s\n", channel->dev_id);
63 static ssize_t dma_store_dev_id(struct sys_device *dev,
64 const char *buf, size_t count)
66 struct dma_channel *channel = to_dma_channel(dev);
67 strcpy(channel->dev_id, buf);
71 static SYSDEV_ATTR(dev_id, S_IRUGO | S_IWUSR, dma_show_dev_id, dma_store_dev_id);
73 static ssize_t dma_store_config(struct sys_device *dev,
74 const char *buf, size_t count)
76 struct dma_channel *channel = to_dma_channel(dev);
79 config = simple_strtoul(buf, NULL, 0);
80 dma_configure_channel(channel->chan, config);
85 static SYSDEV_ATTR(config, S_IWUSR, NULL, dma_store_config);
87 static ssize_t dma_show_mode(struct sys_device *dev, char *buf)
89 struct dma_channel *channel = to_dma_channel(dev);
90 return sprintf(buf, "0x%08x\n", channel->mode);
93 static ssize_t dma_store_mode(struct sys_device *dev,
94 const char *buf, size_t count)
96 struct dma_channel *channel = to_dma_channel(dev);
97 channel->mode = simple_strtoul(buf, NULL, 0);
101 static SYSDEV_ATTR(mode, S_IRUGO | S_IWUSR, dma_show_mode, dma_store_mode);
103 #define dma_ro_attr(field, fmt) \
104 static ssize_t dma_show_##field(struct sys_device *dev, char *buf) \
106 struct dma_channel *channel = to_dma_channel(dev); \
107 return sprintf(buf, fmt, channel->field); \
109 static SYSDEV_ATTR(field, S_IRUGO, dma_show_##field, NULL);
111 dma_ro_attr(count, "0x%08x\n");
112 dma_ro_attr(flags, "0x%08lx\n");
114 int __init dma_create_sysfs_files(struct dma_channel *chan)
116 struct sys_device *dev = &chan->dev;
119 dev->id = chan->chan;
120 dev->cls = &dma_sysclass;
122 ret = sysdev_register(dev);
126 sysdev_create_file(dev, &attr_dev_id);
127 sysdev_create_file(dev, &attr_count);
128 sysdev_create_file(dev, &attr_mode);
129 sysdev_create_file(dev, &attr_flags);
130 sysdev_create_file(dev, &attr_config);