blob: 347ee11351ec6c4375c06a8bf3f970733f022181 [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 Mundt4dfc1192006-11-24 14:43:09 +09006 * Copyright (C) 2004 - 2006 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 = {
Kay Sieversaf5ca3f2007-12-20 02:09:39 +010022 .name = "dma",
Linus Torvalds1da177e2005-04-16 15:20:36 -070023};
Linus Torvalds1da177e2005-04-16 15:20:36 -070024EXPORT_SYMBOL(dma_sysclass);
25
Andi Kleen4a0b2b42008-07-01 18:48:41 +020026static ssize_t dma_show_devices(struct sys_device *dev,
27 struct sysdev_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070028{
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);
Paul Mundt4dfc1192006-11-24 14:43:09 +090034 struct dma_channel *channel = get_dma_channel(i);
35
36 if (unlikely(!info) || !channel)
37 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
39 len += sprintf(buf + len, "%2d: %14s %s\n",
40 channel->chan, info->name,
41 channel->dev_id);
42 }
43
44 return len;
45}
46
47static SYSDEV_ATTR(devices, S_IRUGO, dma_show_devices, NULL);
48
49static int __init dma_sysclass_init(void)
50{
51 int ret;
52
53 ret = sysdev_class_register(&dma_sysclass);
Paul Mundt711fa802006-10-03 13:14:04 +090054 if (unlikely(ret))
55 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Paul Mundt711fa802006-10-03 13:14:04 +090057 return sysfs_create_file(&dma_sysclass.kset.kobj, &attr_devices.attr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070058}
Linus Torvalds1da177e2005-04-16 15:20:36 -070059postcore_initcall(dma_sysclass_init);
60
Andi Kleen4a0b2b42008-07-01 18:48:41 +020061static ssize_t dma_show_dev_id(struct sys_device *dev,
62 struct sysdev_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070063{
64 struct dma_channel *channel = to_dma_channel(dev);
65 return sprintf(buf, "%s\n", channel->dev_id);
66}
67
68static ssize_t dma_store_dev_id(struct sys_device *dev,
Andi Kleen4a0b2b42008-07-01 18:48:41 +020069 struct sysdev_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 const char *buf, size_t count)
71{
72 struct dma_channel *channel = to_dma_channel(dev);
73 strcpy(channel->dev_id, buf);
74 return count;
75}
76
77static SYSDEV_ATTR(dev_id, S_IRUGO | S_IWUSR, dma_show_dev_id, dma_store_dev_id);
78
79static ssize_t dma_store_config(struct sys_device *dev,
Andi Kleen4a0b2b42008-07-01 18:48:41 +020080 struct sysdev_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 const char *buf, size_t count)
82{
83 struct dma_channel *channel = to_dma_channel(dev);
84 unsigned long config;
85
86 config = simple_strtoul(buf, NULL, 0);
Paul Mundt0d831772006-01-16 22:14:09 -080087 dma_configure_channel(channel->vchan, config);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
89 return count;
90}
91
92static SYSDEV_ATTR(config, S_IWUSR, NULL, dma_store_config);
93
Andi Kleen4a0b2b42008-07-01 18:48:41 +020094static ssize_t dma_show_mode(struct sys_device *dev,
95 struct sysdev_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070096{
97 struct dma_channel *channel = to_dma_channel(dev);
98 return sprintf(buf, "0x%08x\n", channel->mode);
99}
100
101static ssize_t dma_store_mode(struct sys_device *dev,
Andi Kleen4a0b2b42008-07-01 18:48:41 +0200102 struct sysdev_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 const char *buf, size_t count)
104{
105 struct dma_channel *channel = to_dma_channel(dev);
106 channel->mode = simple_strtoul(buf, NULL, 0);
107 return count;
108}
109
110static SYSDEV_ATTR(mode, S_IRUGO | S_IWUSR, dma_show_mode, dma_store_mode);
111
112#define dma_ro_attr(field, fmt) \
Andi Kleen4a0b2b42008-07-01 18:48:41 +0200113static ssize_t dma_show_##field(struct sys_device *dev, \
114 struct sysdev_attribute *attr, char *buf)\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115{ \
116 struct dma_channel *channel = to_dma_channel(dev); \
117 return sprintf(buf, fmt, channel->field); \
118} \
119static SYSDEV_ATTR(field, S_IRUGO, dma_show_##field, NULL);
120
121dma_ro_attr(count, "0x%08x\n");
122dma_ro_attr(flags, "0x%08lx\n");
123
Paul Mundt0d831772006-01-16 22:14:09 -0800124int dma_create_sysfs_files(struct dma_channel *chan, struct dma_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125{
126 struct sys_device *dev = &chan->dev;
Paul Mundt0d831772006-01-16 22:14:09 -0800127 char name[16];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 int ret;
129
Paul Mundt0d831772006-01-16 22:14:09 -0800130 dev->id = chan->vchan;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 dev->cls = &dma_sysclass;
132
133 ret = sysdev_register(dev);
134 if (ret)
135 return ret;
136
Paul Mundt4dfc1192006-11-24 14:43:09 +0900137 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);
142
143 if (unlikely(ret)) {
144 dev_err(&info->pdev->dev, "Failed creating attrs\n");
145 return ret;
146 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
Paul Mundt0d831772006-01-16 22:14:09 -0800148 snprintf(name, sizeof(name), "dma%d", chan->chan);
149 return sysfs_create_link(&info->pdev->dev.kobj, &dev->kobj, name);
150}
151
152void dma_remove_sysfs_files(struct dma_channel *chan, struct dma_info *info)
153{
154 struct sys_device *dev = &chan->dev;
155 char name[16];
156
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);
162
163 snprintf(name, sizeof(name), "dma%d", chan->chan);
164 sysfs_remove_link(&info->pdev->dev.kobj, name);
165
166 sysdev_unregister(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167}