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