blob: 1ee631d3725eab14286bad5e303ac4c25a716653 [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>
Paul Mundt0d831772006-01-16 22:14:09 -080016#include <linux/err.h>
Tim Schmielau4e57b682005-10-30 15:03:48 -080017#include <linux/string.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <asm/dma.h>
19
20static struct sysdev_class dma_sysclass = {
Kay Sieversaf5ca3f2007-12-20 02:09:39 +010021 .name = "dma",
Linus Torvalds1da177e2005-04-16 15:20:36 -070022};
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
Andi Kleen4a0b2b42008-07-01 18:48:41 +020024static ssize_t dma_show_devices(struct sys_device *dev,
25 struct sysdev_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070026{
27 ssize_t len = 0;
28 int i;
29
30 for (i = 0; i < MAX_DMA_CHANNELS; i++) {
31 struct dma_info *info = get_dma_info(i);
Paul Mundt4dfc1192006-11-24 14:43:09 +090032 struct dma_channel *channel = get_dma_channel(i);
33
34 if (unlikely(!info) || !channel)
35 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37 len += sprintf(buf + len, "%2d: %14s %s\n",
38 channel->chan, info->name,
39 channel->dev_id);
40 }
41
42 return len;
43}
44
45static SYSDEV_ATTR(devices, S_IRUGO, dma_show_devices, NULL);
46
47static int __init dma_sysclass_init(void)
48{
49 int ret;
50
51 ret = sysdev_class_register(&dma_sysclass);
Paul Mundt711fa802006-10-03 13:14:04 +090052 if (unlikely(ret))
53 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
Paul Mundt711fa802006-10-03 13:14:04 +090055 return sysfs_create_file(&dma_sysclass.kset.kobj, &attr_devices.attr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070056}
Linus Torvalds1da177e2005-04-16 15:20:36 -070057postcore_initcall(dma_sysclass_init);
58
Andi Kleen4a0b2b42008-07-01 18:48:41 +020059static ssize_t dma_show_dev_id(struct sys_device *dev,
60 struct sysdev_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070061{
62 struct dma_channel *channel = to_dma_channel(dev);
63 return sprintf(buf, "%s\n", channel->dev_id);
64}
65
66static ssize_t dma_store_dev_id(struct sys_device *dev,
Andi Kleen4a0b2b42008-07-01 18:48:41 +020067 struct sysdev_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 const char *buf, size_t count)
69{
70 struct dma_channel *channel = to_dma_channel(dev);
71 strcpy(channel->dev_id, buf);
72 return count;
73}
74
75static SYSDEV_ATTR(dev_id, S_IRUGO | S_IWUSR, dma_show_dev_id, dma_store_dev_id);
76
77static ssize_t dma_store_config(struct sys_device *dev,
Andi Kleen4a0b2b42008-07-01 18:48:41 +020078 struct sysdev_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 const char *buf, size_t count)
80{
81 struct dma_channel *channel = to_dma_channel(dev);
82 unsigned long config;
83
84 config = simple_strtoul(buf, NULL, 0);
Paul Mundt0d831772006-01-16 22:14:09 -080085 dma_configure_channel(channel->vchan, config);
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
87 return count;
88}
89
90static SYSDEV_ATTR(config, S_IWUSR, NULL, dma_store_config);
91
Andi Kleen4a0b2b42008-07-01 18:48:41 +020092static ssize_t dma_show_mode(struct sys_device *dev,
93 struct sysdev_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070094{
95 struct dma_channel *channel = to_dma_channel(dev);
96 return sprintf(buf, "0x%08x\n", channel->mode);
97}
98
99static ssize_t dma_store_mode(struct sys_device *dev,
Andi Kleen4a0b2b42008-07-01 18:48:41 +0200100 struct sysdev_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 const char *buf, size_t count)
102{
103 struct dma_channel *channel = to_dma_channel(dev);
104 channel->mode = simple_strtoul(buf, NULL, 0);
105 return count;
106}
107
108static SYSDEV_ATTR(mode, S_IRUGO | S_IWUSR, dma_show_mode, dma_store_mode);
109
110#define dma_ro_attr(field, fmt) \
Andi Kleen4a0b2b42008-07-01 18:48:41 +0200111static ssize_t dma_show_##field(struct sys_device *dev, \
112 struct sysdev_attribute *attr, char *buf)\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113{ \
114 struct dma_channel *channel = to_dma_channel(dev); \
115 return sprintf(buf, fmt, channel->field); \
116} \
117static SYSDEV_ATTR(field, S_IRUGO, dma_show_##field, NULL);
118
119dma_ro_attr(count, "0x%08x\n");
120dma_ro_attr(flags, "0x%08lx\n");
121
Paul Mundt0d831772006-01-16 22:14:09 -0800122int dma_create_sysfs_files(struct dma_channel *chan, struct dma_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123{
124 struct sys_device *dev = &chan->dev;
Paul Mundt0d831772006-01-16 22:14:09 -0800125 char name[16];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 int ret;
127
Paul Mundt0d831772006-01-16 22:14:09 -0800128 dev->id = chan->vchan;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 dev->cls = &dma_sysclass;
130
131 ret = sysdev_register(dev);
132 if (ret)
133 return ret;
134
Paul Mundt4dfc1192006-11-24 14:43:09 +0900135 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);
140
141 if (unlikely(ret)) {
142 dev_err(&info->pdev->dev, "Failed creating attrs\n");
143 return ret;
144 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
Paul Mundt0d831772006-01-16 22:14:09 -0800146 snprintf(name, sizeof(name), "dma%d", chan->chan);
147 return sysfs_create_link(&info->pdev->dev.kobj, &dev->kobj, name);
148}
149
150void dma_remove_sysfs_files(struct dma_channel *chan, struct dma_info *info)
151{
152 struct sys_device *dev = &chan->dev;
153 char name[16];
154
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);
160
161 snprintf(name, sizeof(name), "dma%d", chan->chan);
162 sysfs_remove_link(&info->pdev->dev.kobj, name);
163
164 sysdev_unregister(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165}