dma-sysfs.c 4.2 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5
/*
 * arch/sh/drivers/dma/dma-sysfs.c
 *
 * sysfs interface for SH DMA API
 *
P
Paul Mundt 已提交
6
 * Copyright (C) 2004 - 2006  Paul Mundt
L
Linus Torvalds 已提交
7 8 9 10 11 12 13 14
 *
 * This file is subject to the terms and conditions of the GNU General Public
 * License.  See the file "COPYING" in the main directory of this archive
 * for more details.
 */
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/sysdev.h>
P
Paul Mundt 已提交
15 16
#include <linux/platform_device.h>
#include <linux/err.h>
T
Tim Schmielau 已提交
17
#include <linux/string.h>
L
Linus Torvalds 已提交
18 19 20
#include <asm/dma.h>

static struct sysdev_class dma_sysclass = {
21
	.name = "dma",
L
Linus Torvalds 已提交
22 23
};

24 25
static ssize_t dma_show_devices(struct sys_device *dev,
				struct sysdev_attribute *attr, char *buf)
L
Linus Torvalds 已提交
26 27 28 29 30 31
{
	ssize_t len = 0;
	int i;

	for (i = 0; i < MAX_DMA_CHANNELS; i++) {
		struct dma_info *info = get_dma_info(i);
P
Paul Mundt 已提交
32 33 34 35
		struct dma_channel *channel = get_dma_channel(i);

		if (unlikely(!info) || !channel)
			continue;
L
Linus Torvalds 已提交
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51

		len += sprintf(buf + len, "%2d: %14s    %s\n",
			       channel->chan, info->name,
			       channel->dev_id);
	}

	return len;
}

static SYSDEV_ATTR(devices, S_IRUGO, dma_show_devices, NULL);

static int __init dma_sysclass_init(void)
{
	int ret;

	ret = sysdev_class_register(&dma_sysclass);
P
Paul Mundt 已提交
52 53
	if (unlikely(ret))
		return ret;
L
Linus Torvalds 已提交
54

P
Paul Mundt 已提交
55
	return sysfs_create_file(&dma_sysclass.kset.kobj, &attr_devices.attr);
L
Linus Torvalds 已提交
56 57 58
}
postcore_initcall(dma_sysclass_init);

59 60
static ssize_t dma_show_dev_id(struct sys_device *dev,
				struct sysdev_attribute *attr, char *buf)
L
Linus Torvalds 已提交
61 62 63 64 65 66
{
	struct dma_channel *channel = to_dma_channel(dev);
	return sprintf(buf, "%s\n", channel->dev_id);
}

static ssize_t dma_store_dev_id(struct sys_device *dev,
67
				struct sysdev_attribute *attr,
L
Linus Torvalds 已提交
68 69 70 71 72 73 74 75 76 77
				const char *buf, size_t count)
{
	struct dma_channel *channel = to_dma_channel(dev);
	strcpy(channel->dev_id, buf);
	return count;
}

static SYSDEV_ATTR(dev_id, S_IRUGO | S_IWUSR, dma_show_dev_id, dma_store_dev_id);

static ssize_t dma_store_config(struct sys_device *dev,
78
				struct sysdev_attribute *attr,
L
Linus Torvalds 已提交
79 80 81 82 83 84
				const char *buf, size_t count)
{
	struct dma_channel *channel = to_dma_channel(dev);
	unsigned long config;

	config = simple_strtoul(buf, NULL, 0);
P
Paul Mundt 已提交
85
	dma_configure_channel(channel->vchan, config);
L
Linus Torvalds 已提交
86 87 88 89 90 91

	return count;
}

static SYSDEV_ATTR(config, S_IWUSR, NULL, dma_store_config);

92 93
static ssize_t dma_show_mode(struct sys_device *dev,
				struct sysdev_attribute *attr, char *buf)
L
Linus Torvalds 已提交
94 95 96 97 98 99
{
	struct dma_channel *channel = to_dma_channel(dev);
	return sprintf(buf, "0x%08x\n", channel->mode);
}

static ssize_t dma_store_mode(struct sys_device *dev,
100
			      struct sysdev_attribute *attr,
L
Linus Torvalds 已提交
101 102 103 104 105 106 107 108 109 110
			      const char *buf, size_t count)
{
	struct dma_channel *channel = to_dma_channel(dev);
	channel->mode = simple_strtoul(buf, NULL, 0);
	return count;
}

static SYSDEV_ATTR(mode, S_IRUGO | S_IWUSR, dma_show_mode, dma_store_mode);

#define dma_ro_attr(field, fmt)						\
111 112
static ssize_t dma_show_##field(struct sys_device *dev, 		\
				struct sysdev_attribute *attr, char *buf)\
L
Linus Torvalds 已提交
113 114 115 116 117 118 119 120 121
{									\
	struct dma_channel *channel = to_dma_channel(dev);		\
	return sprintf(buf, fmt, channel->field);			\
}									\
static SYSDEV_ATTR(field, S_IRUGO, dma_show_##field, NULL);

dma_ro_attr(count, "0x%08x\n");
dma_ro_attr(flags, "0x%08lx\n");

P
Paul Mundt 已提交
122
int dma_create_sysfs_files(struct dma_channel *chan, struct dma_info *info)
L
Linus Torvalds 已提交
123 124
{
	struct sys_device *dev = &chan->dev;
P
Paul Mundt 已提交
125
	char name[16];
L
Linus Torvalds 已提交
126 127
	int ret;

P
Paul Mundt 已提交
128
	dev->id  = chan->vchan;
L
Linus Torvalds 已提交
129 130 131 132 133 134
	dev->cls = &dma_sysclass;

	ret = sysdev_register(dev);
	if (ret)
		return ret;

P
Paul Mundt 已提交
135 136 137 138 139 140 141 142 143 144
	ret |= sysdev_create_file(dev, &attr_dev_id);
	ret |= sysdev_create_file(dev, &attr_count);
	ret |= sysdev_create_file(dev, &attr_mode);
	ret |= sysdev_create_file(dev, &attr_flags);
	ret |= sysdev_create_file(dev, &attr_config);

	if (unlikely(ret)) {
		dev_err(&info->pdev->dev, "Failed creating attrs\n");
		return ret;
	}
L
Linus Torvalds 已提交
145

P
Paul Mundt 已提交
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
	snprintf(name, sizeof(name), "dma%d", chan->chan);
	return sysfs_create_link(&info->pdev->dev.kobj, &dev->kobj, name);
}

void dma_remove_sysfs_files(struct dma_channel *chan, struct dma_info *info)
{
	struct sys_device *dev = &chan->dev;
	char name[16];

	sysdev_remove_file(dev, &attr_dev_id);
	sysdev_remove_file(dev, &attr_count);
	sysdev_remove_file(dev, &attr_mode);
	sysdev_remove_file(dev, &attr_flags);
	sysdev_remove_file(dev, &attr_config);

	snprintf(name, sizeof(name), "dma%d", chan->chan);
	sysfs_remove_link(&info->pdev->dev.kobj, name);

	sysdev_unregister(dev);
L
Linus Torvalds 已提交
165
}