blob: 70a5d82eb2f8c8b6a10340e152e77357304ce162 [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 *
Paul Mundt0d831772006-01-16 22:14:09 -08006 * Copyright (C) 2004, 2005 Paul Mundt
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 *
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>
Paul Mundt0d831772006-01-16 22:14:09 -080015#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/module.h>
Paul Mundt0d831772006-01-16 22:14:09 -080017#include <linux/err.h>
Tim Schmielau4e57b682005-10-30 15:03:48 -080018#include <linux/string.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <asm/dma.h>
20
21static struct sysdev_class dma_sysclass = {
22 set_kset_name("dma"),
23};
24
25EXPORT_SYMBOL(dma_sysclass);
26
27static 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
44static SYSDEV_ATTR(devices, S_IRUGO, dma_show_devices, NULL);
45
46static int __init dma_sysclass_init(void)
47{
48 int ret;
49
50 ret = sysdev_class_register(&dma_sysclass);
51 if (ret == 0)
52 sysfs_create_file(&dma_sysclass.kset.kobj, &attr_devices.attr);
53
54 return ret;
55}
56
57postcore_initcall(dma_sysclass_init);
58
59static ssize_t dma_show_dev_id(struct sys_device *dev, char *buf)
60{
61 struct dma_channel *channel = to_dma_channel(dev);
62 return sprintf(buf, "%s\n", channel->dev_id);
63}
64
65static ssize_t dma_store_dev_id(struct sys_device *dev,
66 const char *buf, size_t count)
67{
68 struct dma_channel *channel = to_dma_channel(dev);
69 strcpy(channel->dev_id, buf);
70 return count;
71}
72
73static SYSDEV_ATTR(dev_id, S_IRUGO | S_IWUSR, dma_show_dev_id, dma_store_dev_id);
74
75static ssize_t dma_store_config(struct sys_device *dev,
76 const char *buf, size_t count)
77{
78 struct dma_channel *channel = to_dma_channel(dev);
79 unsigned long config;
80
81 config = simple_strtoul(buf, NULL, 0);
Paul Mundt0d831772006-01-16 22:14:09 -080082 dma_configure_channel(channel->vchan, config);
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
84 return count;
85}
86
87static SYSDEV_ATTR(config, S_IWUSR, NULL, dma_store_config);
88
89static ssize_t dma_show_mode(struct sys_device *dev, char *buf)
90{
91 struct dma_channel *channel = to_dma_channel(dev);
92 return sprintf(buf, "0x%08x\n", channel->mode);
93}
94
95static ssize_t dma_store_mode(struct sys_device *dev,
96 const char *buf, size_t count)
97{
98 struct dma_channel *channel = to_dma_channel(dev);
99 channel->mode = simple_strtoul(buf, NULL, 0);
100 return count;
101}
102
103static SYSDEV_ATTR(mode, S_IRUGO | S_IWUSR, dma_show_mode, dma_store_mode);
104
105#define dma_ro_attr(field, fmt) \
106static ssize_t dma_show_##field(struct sys_device *dev, char *buf) \
107{ \
108 struct dma_channel *channel = to_dma_channel(dev); \
109 return sprintf(buf, fmt, channel->field); \
110} \
111static SYSDEV_ATTR(field, S_IRUGO, dma_show_##field, NULL);
112
113dma_ro_attr(count, "0x%08x\n");
114dma_ro_attr(flags, "0x%08lx\n");
115
Paul Mundt0d831772006-01-16 22:14:09 -0800116int dma_create_sysfs_files(struct dma_channel *chan, struct dma_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117{
118 struct sys_device *dev = &chan->dev;
Paul Mundt0d831772006-01-16 22:14:09 -0800119 char name[16];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 int ret;
121
Paul Mundt0d831772006-01-16 22:14:09 -0800122 dev->id = chan->vchan;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 dev->cls = &dma_sysclass;
124
125 ret = sysdev_register(dev);
126 if (ret)
127 return ret;
128
129 sysdev_create_file(dev, &attr_dev_id);
130 sysdev_create_file(dev, &attr_count);
131 sysdev_create_file(dev, &attr_mode);
132 sysdev_create_file(dev, &attr_flags);
133 sysdev_create_file(dev, &attr_config);
134
Paul Mundt0d831772006-01-16 22:14:09 -0800135 snprintf(name, sizeof(name), "dma%d", chan->chan);
136 return sysfs_create_link(&info->pdev->dev.kobj, &dev->kobj, name);
137}
138
139void dma_remove_sysfs_files(struct dma_channel *chan, struct dma_info *info)
140{
141 struct sys_device *dev = &chan->dev;
142 char name[16];
143
144 sysdev_remove_file(dev, &attr_dev_id);
145 sysdev_remove_file(dev, &attr_count);
146 sysdev_remove_file(dev, &attr_mode);
147 sysdev_remove_file(dev, &attr_flags);
148 sysdev_remove_file(dev, &attr_config);
149
150 snprintf(name, sizeof(name), "dma%d", chan->chan);
151 sysfs_remove_link(&info->pdev->dev.kobj, name);
152
153 sysdev_unregister(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154}
155