sh: build fixes for defconfigs.
[linux-2.6.git] / arch / sh / drivers / dma / dma-sysfs.c
1 /*
2  * arch/sh/drivers/dma/dma-sysfs.c
3  *
4  * sysfs interface for SH DMA API
5  *
6  * Copyright (C) 2004, 2005  Paul Mundt
7  *
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.
11  */
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>
19 #include <asm/dma.h>
20
21 static struct sysdev_class dma_sysclass = {
22         set_kset_name("dma"),
23 };
24
25 EXPORT_SYMBOL(dma_sysclass);
26
27 static ssize_t dma_show_devices(struct sys_device *dev, char *buf)
28 {
29         ssize_t len = 0;
30         int i;
31
32         for (i = 0; i < MAX_DMA_CHANNELS; i++) {
33                 struct dma_info *info = get_dma_info(i);
34                 struct dma_channel *channel = &info->channels[i];
35
36                 len += sprintf(buf + len, "%2d: %14s    %s\n",
37                                channel->chan, info->name,
38                                channel->dev_id);
39         }
40
41         return len;
42 }
43
44 static SYSDEV_ATTR(devices, S_IRUGO, dma_show_devices, NULL);
45
46 static int __init dma_sysclass_init(void)
47 {
48         int ret;
49
50         ret = sysdev_class_register(&dma_sysclass);
51         if (unlikely(ret))
52                 return ret;
53
54         return sysfs_create_file(&dma_sysclass.kset.kobj, &attr_devices.attr);
55 }
56 postcore_initcall(dma_sysclass_init);
57
58 static ssize_t dma_show_dev_id(struct sys_device *dev, char *buf)
59 {
60         struct dma_channel *channel = to_dma_channel(dev);
61         return sprintf(buf, "%s\n", channel->dev_id);
62 }
63
64 static ssize_t dma_store_dev_id(struct sys_device *dev,
65                                 const char *buf, size_t count)
66 {
67         struct dma_channel *channel = to_dma_channel(dev);
68         strcpy(channel->dev_id, buf);
69         return count;
70 }
71
72 static SYSDEV_ATTR(dev_id, S_IRUGO | S_IWUSR, dma_show_dev_id, dma_store_dev_id);
73
74 static ssize_t dma_store_config(struct sys_device *dev,
75                                 const char *buf, size_t count)
76 {
77         struct dma_channel *channel = to_dma_channel(dev);
78         unsigned long config;
79
80         config = simple_strtoul(buf, NULL, 0);
81         dma_configure_channel(channel->vchan, config);
82
83         return count;
84 }
85
86 static SYSDEV_ATTR(config, S_IWUSR, NULL, dma_store_config);
87
88 static ssize_t dma_show_mode(struct sys_device *dev, char *buf)
89 {
90         struct dma_channel *channel = to_dma_channel(dev);
91         return sprintf(buf, "0x%08x\n", channel->mode);
92 }
93
94 static ssize_t dma_store_mode(struct sys_device *dev,
95                               const char *buf, size_t count)
96 {
97         struct dma_channel *channel = to_dma_channel(dev);
98         channel->mode = simple_strtoul(buf, NULL, 0);
99         return count;
100 }
101
102 static SYSDEV_ATTR(mode, S_IRUGO | S_IWUSR, dma_show_mode, dma_store_mode);
103
104 #define dma_ro_attr(field, fmt)                                         \
105 static ssize_t dma_show_##field(struct sys_device *dev, char *buf)      \
106 {                                                                       \
107         struct dma_channel *channel = to_dma_channel(dev);              \
108         return sprintf(buf, fmt, channel->field);                       \
109 }                                                                       \
110 static SYSDEV_ATTR(field, S_IRUGO, dma_show_##field, NULL);
111
112 dma_ro_attr(count, "0x%08x\n");
113 dma_ro_attr(flags, "0x%08lx\n");
114
115 int dma_create_sysfs_files(struct dma_channel *chan, struct dma_info *info)
116 {
117         struct sys_device *dev = &chan->dev;
118         char name[16];
119         int ret;
120
121         dev->id  = chan->vchan;
122         dev->cls = &dma_sysclass;
123
124         ret = sysdev_register(dev);
125         if (ret)
126                 return ret;
127
128         sysdev_create_file(dev, &attr_dev_id);
129         sysdev_create_file(dev, &attr_count);
130         sysdev_create_file(dev, &attr_mode);
131         sysdev_create_file(dev, &attr_flags);
132         sysdev_create_file(dev, &attr_config);
133
134         snprintf(name, sizeof(name), "dma%d", chan->chan);
135         return sysfs_create_link(&info->pdev->dev.kobj, &dev->kobj, name);
136 }
137
138 void dma_remove_sysfs_files(struct dma_channel *chan, struct dma_info *info)
139 {
140         struct sys_device *dev = &chan->dev;
141         char name[16];
142
143         sysdev_remove_file(dev, &attr_dev_id);
144         sysdev_remove_file(dev, &attr_count);
145         sysdev_remove_file(dev, &attr_mode);
146         sysdev_remove_file(dev, &attr_flags);
147         sysdev_remove_file(dev, &attr_config);
148
149         snprintf(name, sizeof(name), "dma%d", chan->chan);
150         sysfs_remove_link(&info->pdev->dev.kobj, name);
151
152         sysdev_unregister(dev);
153 }