blob: 83cc704770d7488e489945655dcb3634285a9123 [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>
Paul Gortmaker0c438712011-07-31 17:40:26 -040014#include <linux/stat.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/sysdev.h>
Paul Mundt0d831772006-01-16 22:14:09 -080016#include <linux/platform_device.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 -070024
Andi Kleen4a0b2b42008-07-01 18:48:41 +020025static ssize_t dma_show_devices(struct sys_device *dev,
26 struct sysdev_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070027{
28 ssize_t len = 0;
29 int i;
30
31 for (i = 0; i < MAX_DMA_CHANNELS; i++) {
32 struct dma_info *info = get_dma_info(i);
Paul Mundt4dfc1192006-11-24 14:43:09 +090033 struct dma_channel *channel = get_dma_channel(i);
34
35 if (unlikely(!info) || !channel)
36 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
38 len += sprintf(buf + len, "%2d: %14s %s\n",
39 channel->chan, info->name,
40 channel->dev_id);
41 }
42
43 return len;
44}
45
46static SYSDEV_ATTR(devices, S_IRUGO, dma_show_devices, NULL);
47
48static int __init dma_sysclass_init(void)
49{
50 int ret;
51
52 ret = sysdev_class_register(&dma_sysclass);
Paul Mundt711fa802006-10-03 13:14:04 +090053 if (unlikely(ret))
54 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
Paul Mundt711fa802006-10-03 13:14:04 +090056 return sysfs_create_file(&dma_sysclass.kset.kobj, &attr_devices.attr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070057}
Linus Torvalds1da177e2005-04-16 15:20:36 -070058postcore_initcall(dma_sysclass_init);
59
Andi Kleen4a0b2b42008-07-01 18:48:41 +020060static ssize_t dma_show_dev_id(struct sys_device *dev,
61 struct sysdev_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070062{
63 struct dma_channel *channel = to_dma_channel(dev);
64 return sprintf(buf, "%s\n", channel->dev_id);
65}
66
67static ssize_t dma_store_dev_id(struct sys_device *dev,
Andi Kleen4a0b2b42008-07-01 18:48:41 +020068 struct sysdev_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 const char *buf, size_t count)
70{
71 struct dma_channel *channel = to_dma_channel(dev);
72 strcpy(channel->dev_id, buf);
73 return count;
74}
75
76static SYSDEV_ATTR(dev_id, S_IRUGO | S_IWUSR, dma_show_dev_id, dma_store_dev_id);
77
78static ssize_t dma_store_config(struct sys_device *dev,
Andi Kleen4a0b2b42008-07-01 18:48:41 +020079 struct sysdev_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 const char *buf, size_t count)
81{
82 struct dma_channel *channel = to_dma_channel(dev);
83 unsigned long config;
84
85 config = simple_strtoul(buf, NULL, 0);
Paul Mundt0d831772006-01-16 22:14:09 -080086 dma_configure_channel(channel->vchan, config);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
88 return count;
89}
90
91static SYSDEV_ATTR(config, S_IWUSR, NULL, dma_store_config);
92
Andi Kleen4a0b2b42008-07-01 18:48:41 +020093static ssize_t dma_show_mode(struct sys_device *dev,
94 struct sysdev_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070095{
96 struct dma_channel *channel = to_dma_channel(dev);
97 return sprintf(buf, "0x%08x\n", channel->mode);
98}
99
100static ssize_t dma_store_mode(struct sys_device *dev,
Andi Kleen4a0b2b42008-07-01 18:48:41 +0200101 struct sysdev_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 const char *buf, size_t count)
103{
104 struct dma_channel *channel = to_dma_channel(dev);
105 channel->mode = simple_strtoul(buf, NULL, 0);
106 return count;
107}
108
109static SYSDEV_ATTR(mode, S_IRUGO | S_IWUSR, dma_show_mode, dma_store_mode);
110
111#define dma_ro_attr(field, fmt) \
Andi Kleen4a0b2b42008-07-01 18:48:41 +0200112static ssize_t dma_show_##field(struct sys_device *dev, \
113 struct sysdev_attribute *attr, char *buf)\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114{ \
115 struct dma_channel *channel = to_dma_channel(dev); \
116 return sprintf(buf, fmt, channel->field); \
117} \
118static SYSDEV_ATTR(field, S_IRUGO, dma_show_##field, NULL);
119
120dma_ro_attr(count, "0x%08x\n");
121dma_ro_attr(flags, "0x%08lx\n");
122
Paul Mundt0d831772006-01-16 22:14:09 -0800123int dma_create_sysfs_files(struct dma_channel *chan, struct dma_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124{
125 struct sys_device *dev = &chan->dev;
Paul Mundt0d831772006-01-16 22:14:09 -0800126 char name[16];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 int ret;
128
Paul Mundt0d831772006-01-16 22:14:09 -0800129 dev->id = chan->vchan;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 dev->cls = &dma_sysclass;
131
132 ret = sysdev_register(dev);
133 if (ret)
134 return ret;
135
Paul Mundt4dfc1192006-11-24 14:43:09 +0900136 ret |= sysdev_create_file(dev, &attr_dev_id);
137 ret |= sysdev_create_file(dev, &attr_count);
138 ret |= sysdev_create_file(dev, &attr_mode);
139 ret |= sysdev_create_file(dev, &attr_flags);
140 ret |= sysdev_create_file(dev, &attr_config);
141
142 if (unlikely(ret)) {
143 dev_err(&info->pdev->dev, "Failed creating attrs\n");
144 return ret;
145 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146
Paul Mundt0d831772006-01-16 22:14:09 -0800147 snprintf(name, sizeof(name), "dma%d", chan->chan);
148 return sysfs_create_link(&info->pdev->dev.kobj, &dev->kobj, name);
149}
150
151void dma_remove_sysfs_files(struct dma_channel *chan, struct dma_info *info)
152{
153 struct sys_device *dev = &chan->dev;
154 char name[16];
155
156 sysdev_remove_file(dev, &attr_dev_id);
157 sysdev_remove_file(dev, &attr_count);
158 sysdev_remove_file(dev, &attr_mode);
159 sysdev_remove_file(dev, &attr_flags);
160 sysdev_remove_file(dev, &attr_config);
161
162 snprintf(name, sizeof(name), "dma%d", chan->chan);
163 sysfs_remove_link(&info->pdev->dev.kobj, name);
164
165 sysdev_unregister(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166}