2 * arch/sh/drivers/dma/dma-sysfs.c
4 * sysfs interface for SH DMA API
6 * Copyright (C) 2004 - 2006 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/platform_device.h>
16 #include <linux/module.h>
17 #include <linux/err.h>
18 #include <linux/string.h>
21 static struct sysdev_class dma_sysclass = {
24 EXPORT_SYMBOL(dma_sysclass);
26 static ssize_t dma_show_devices(struct sys_device *dev,
27 struct sysdev_attribute *attr, char *buf)
32 for (i = 0; i < MAX_DMA_CHANNELS; i++) {
33 struct dma_info *info = get_dma_info(i);
34 struct dma_channel *channel = get_dma_channel(i);
36 if (unlikely(!info) || !channel)
39 len += sprintf(buf + len, "%2d: %14s %s\n",
40 channel->chan, info->name,
47 static SYSDEV_ATTR(devices, S_IRUGO, dma_show_devices, NULL);
49 static int __init dma_sysclass_init(void)
53 ret = sysdev_class_register(&dma_sysclass);
57 return sysfs_create_file(&dma_sysclass.kset.kobj, &attr_devices.attr);
59 postcore_initcall(dma_sysclass_init);
61 static ssize_t dma_show_dev_id(struct sys_device *dev,
62 struct sysdev_attribute *attr, char *buf)
64 struct dma_channel *channel = to_dma_channel(dev);
65 return sprintf(buf, "%s\n", channel->dev_id);
68 static ssize_t dma_store_dev_id(struct sys_device *dev,
69 struct sysdev_attribute *attr,
70 const char *buf, size_t count)
72 struct dma_channel *channel = to_dma_channel(dev);
73 strcpy(channel->dev_id, buf);
77 static SYSDEV_ATTR(dev_id, S_IRUGO | S_IWUSR, dma_show_dev_id, dma_store_dev_id);
79 static ssize_t dma_store_config(struct sys_device *dev,
80 struct sysdev_attribute *attr,
81 const char *buf, size_t count)
83 struct dma_channel *channel = to_dma_channel(dev);
86 config = simple_strtoul(buf, NULL, 0);
87 dma_configure_channel(channel->vchan, config);
92 static SYSDEV_ATTR(config, S_IWUSR, NULL, dma_store_config);
94 static ssize_t dma_show_mode(struct sys_device *dev,
95 struct sysdev_attribute *attr, char *buf)
97 struct dma_channel *channel = to_dma_channel(dev);
98 return sprintf(buf, "0x%08x\n", channel->mode);
101 static ssize_t dma_store_mode(struct sys_device *dev,
102 struct sysdev_attribute *attr,
103 const char *buf, size_t count)
105 struct dma_channel *channel = to_dma_channel(dev);
106 channel->mode = simple_strtoul(buf, NULL, 0);
110 static SYSDEV_ATTR(mode, S_IRUGO | S_IWUSR, dma_show_mode, dma_store_mode);
112 #define dma_ro_attr(field, fmt) \
113 static ssize_t dma_show_##field(struct sys_device *dev, \
114 struct sysdev_attribute *attr, char *buf)\
116 struct dma_channel *channel = to_dma_channel(dev); \
117 return sprintf(buf, fmt, channel->field); \
119 static SYSDEV_ATTR(field, S_IRUGO, dma_show_##field, NULL);
121 dma_ro_attr(count, "0x%08x\n");
122 dma_ro_attr(flags, "0x%08lx\n");
124 int dma_create_sysfs_files(struct dma_channel *chan, struct dma_info *info)
126 struct sys_device *dev = &chan->dev;
130 dev->id = chan->vchan;
131 dev->cls = &dma_sysclass;
133 ret = sysdev_register(dev);
137 ret |= sysdev_create_file(dev, &attr_dev_id);
138 ret |= sysdev_create_file(dev, &attr_count);
139 ret |= sysdev_create_file(dev, &attr_mode);
140 ret |= sysdev_create_file(dev, &attr_flags);
141 ret |= sysdev_create_file(dev, &attr_config);
144 dev_err(&info->pdev->dev, "Failed creating attrs\n");
148 snprintf(name, sizeof(name), "dma%d", chan->chan);
149 return sysfs_create_link(&info->pdev->dev.kobj, &dev->kobj, name);
152 void dma_remove_sysfs_files(struct dma_channel *chan, struct dma_info *info)
154 struct sys_device *dev = &chan->dev;
157 sysdev_remove_file(dev, &attr_dev_id);
158 sysdev_remove_file(dev, &attr_count);
159 sysdev_remove_file(dev, &attr_mode);
160 sysdev_remove_file(dev, &attr_flags);
161 sysdev_remove_file(dev, &attr_config);
163 snprintf(name, sizeof(name), "dma%d", chan->chan);
164 sysfs_remove_link(&info->pdev->dev.kobj, name);
166 sysdev_unregister(dev);