Merge branch 'for-2.6.34' of git://linux-nfs.org/~bfields/linux
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / sh / drivers / dma / dma-sysfs.c
blob1ee631d3725eab14286bad5e303ac4c25a716653
1 /*
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
10 * for more details.
12 #include <linux/kernel.h>
13 #include <linux/init.h>
14 #include <linux/sysdev.h>
15 #include <linux/platform_device.h>
16 #include <linux/err.h>
17 #include <linux/string.h>
18 #include <asm/dma.h>
20 static struct sysdev_class dma_sysclass = {
21 .name = "dma",
24 static ssize_t dma_show_devices(struct sys_device *dev,
25 struct sysdev_attribute *attr, char *buf)
27 ssize_t len = 0;
28 int i;
30 for (i = 0; i < MAX_DMA_CHANNELS; i++) {
31 struct dma_info *info = get_dma_info(i);
32 struct dma_channel *channel = get_dma_channel(i);
34 if (unlikely(!info) || !channel)
35 continue;
37 len += sprintf(buf + len, "%2d: %14s %s\n",
38 channel->chan, info->name,
39 channel->dev_id);
42 return len;
45 static SYSDEV_ATTR(devices, S_IRUGO, dma_show_devices, NULL);
47 static int __init dma_sysclass_init(void)
49 int ret;
51 ret = sysdev_class_register(&dma_sysclass);
52 if (unlikely(ret))
53 return ret;
55 return sysfs_create_file(&dma_sysclass.kset.kobj, &attr_devices.attr);
57 postcore_initcall(dma_sysclass_init);
59 static ssize_t dma_show_dev_id(struct sys_device *dev,
60 struct sysdev_attribute *attr, char *buf)
62 struct dma_channel *channel = to_dma_channel(dev);
63 return sprintf(buf, "%s\n", channel->dev_id);
66 static ssize_t dma_store_dev_id(struct sys_device *dev,
67 struct sysdev_attribute *attr,
68 const char *buf, size_t count)
70 struct dma_channel *channel = to_dma_channel(dev);
71 strcpy(channel->dev_id, buf);
72 return count;
75 static SYSDEV_ATTR(dev_id, S_IRUGO | S_IWUSR, dma_show_dev_id, dma_store_dev_id);
77 static ssize_t dma_store_config(struct sys_device *dev,
78 struct sysdev_attribute *attr,
79 const char *buf, size_t count)
81 struct dma_channel *channel = to_dma_channel(dev);
82 unsigned long config;
84 config = simple_strtoul(buf, NULL, 0);
85 dma_configure_channel(channel->vchan, config);
87 return count;
90 static SYSDEV_ATTR(config, S_IWUSR, NULL, dma_store_config);
92 static ssize_t dma_show_mode(struct sys_device *dev,
93 struct sysdev_attribute *attr, char *buf)
95 struct dma_channel *channel = to_dma_channel(dev);
96 return sprintf(buf, "0x%08x\n", channel->mode);
99 static ssize_t dma_store_mode(struct sys_device *dev,
100 struct sysdev_attribute *attr,
101 const char *buf, size_t count)
103 struct dma_channel *channel = to_dma_channel(dev);
104 channel->mode = simple_strtoul(buf, NULL, 0);
105 return count;
108 static SYSDEV_ATTR(mode, S_IRUGO | S_IWUSR, dma_show_mode, dma_store_mode);
110 #define dma_ro_attr(field, fmt) \
111 static ssize_t dma_show_##field(struct sys_device *dev, \
112 struct sysdev_attribute *attr, char *buf)\
114 struct dma_channel *channel = to_dma_channel(dev); \
115 return sprintf(buf, fmt, channel->field); \
117 static SYSDEV_ATTR(field, S_IRUGO, dma_show_##field, NULL);
119 dma_ro_attr(count, "0x%08x\n");
120 dma_ro_attr(flags, "0x%08lx\n");
122 int dma_create_sysfs_files(struct dma_channel *chan, struct dma_info *info)
124 struct sys_device *dev = &chan->dev;
125 char name[16];
126 int ret;
128 dev->id = chan->vchan;
129 dev->cls = &dma_sysclass;
131 ret = sysdev_register(dev);
132 if (ret)
133 return ret;
135 ret |= sysdev_create_file(dev, &attr_dev_id);
136 ret |= sysdev_create_file(dev, &attr_count);
137 ret |= sysdev_create_file(dev, &attr_mode);
138 ret |= sysdev_create_file(dev, &attr_flags);
139 ret |= sysdev_create_file(dev, &attr_config);
141 if (unlikely(ret)) {
142 dev_err(&info->pdev->dev, "Failed creating attrs\n");
143 return ret;
146 snprintf(name, sizeof(name), "dma%d", chan->chan);
147 return sysfs_create_link(&info->pdev->dev.kobj, &dev->kobj, name);
150 void dma_remove_sysfs_files(struct dma_channel *chan, struct dma_info *info)
152 struct sys_device *dev = &chan->dev;
153 char name[16];
155 sysdev_remove_file(dev, &attr_dev_id);
156 sysdev_remove_file(dev, &attr_count);
157 sysdev_remove_file(dev, &attr_mode);
158 sysdev_remove_file(dev, &attr_flags);
159 sysdev_remove_file(dev, &attr_config);
161 snprintf(name, sizeof(name), "dma%d", chan->chan);
162 sysfs_remove_link(&info->pdev->dev.kobj, name);
164 sysdev_unregister(dev);