Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * arch/sh/drivers/dma/dma-sysfs.c |
| 3 | * |
| 4 | * sysfs interface for SH DMA API |
| 5 | * |
Paul Mundt | 4dfc119 | 2006-11-24 14:43:09 +0900 | [diff] [blame] | 6 | * Copyright (C) 2004 - 2006 Paul Mundt |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
| 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 Mundt | 0d83177 | 2006-01-16 22:14:09 -0800 | [diff] [blame] | 15 | #include <linux/platform_device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <linux/module.h> |
Paul Mundt | 0d83177 | 2006-01-16 22:14:09 -0800 | [diff] [blame] | 17 | #include <linux/err.h> |
Tim Schmielau | 4e57b68 | 2005-10-30 15:03:48 -0800 | [diff] [blame] | 18 | #include <linux/string.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <asm/dma.h> |
| 20 | |
| 21 | static struct sysdev_class dma_sysclass = { |
| 22 | set_kset_name("dma"), |
| 23 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | EXPORT_SYMBOL(dma_sysclass); |
| 25 | |
| 26 | static ssize_t dma_show_devices(struct sys_device *dev, char *buf) |
| 27 | { |
| 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 Mundt | 4dfc119 | 2006-11-24 14:43:09 +0900 | [diff] [blame] | 33 | struct dma_channel *channel = get_dma_channel(i); |
| 34 | |
| 35 | if (unlikely(!info) || !channel) |
| 36 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
| 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 | |
| 46 | static SYSDEV_ATTR(devices, S_IRUGO, dma_show_devices, NULL); |
| 47 | |
| 48 | static int __init dma_sysclass_init(void) |
| 49 | { |
| 50 | int ret; |
| 51 | |
| 52 | ret = sysdev_class_register(&dma_sysclass); |
Paul Mundt | 711fa80 | 2006-10-03 13:14:04 +0900 | [diff] [blame] | 53 | if (unlikely(ret)) |
| 54 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
Paul Mundt | 711fa80 | 2006-10-03 13:14:04 +0900 | [diff] [blame] | 56 | return sysfs_create_file(&dma_sysclass.kset.kobj, &attr_devices.attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | postcore_initcall(dma_sysclass_init); |
| 59 | |
| 60 | static ssize_t dma_show_dev_id(struct sys_device *dev, char *buf) |
| 61 | { |
| 62 | struct dma_channel *channel = to_dma_channel(dev); |
| 63 | return sprintf(buf, "%s\n", channel->dev_id); |
| 64 | } |
| 65 | |
| 66 | static ssize_t dma_store_dev_id(struct sys_device *dev, |
| 67 | const char *buf, size_t count) |
| 68 | { |
| 69 | struct dma_channel *channel = to_dma_channel(dev); |
| 70 | strcpy(channel->dev_id, buf); |
| 71 | return count; |
| 72 | } |
| 73 | |
| 74 | static SYSDEV_ATTR(dev_id, S_IRUGO | S_IWUSR, dma_show_dev_id, dma_store_dev_id); |
| 75 | |
| 76 | static ssize_t dma_store_config(struct sys_device *dev, |
| 77 | const char *buf, size_t count) |
| 78 | { |
| 79 | struct dma_channel *channel = to_dma_channel(dev); |
| 80 | unsigned long config; |
| 81 | |
| 82 | config = simple_strtoul(buf, NULL, 0); |
Paul Mundt | 0d83177 | 2006-01-16 22:14:09 -0800 | [diff] [blame] | 83 | dma_configure_channel(channel->vchan, config); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | |
| 85 | return count; |
| 86 | } |
| 87 | |
| 88 | static SYSDEV_ATTR(config, S_IWUSR, NULL, dma_store_config); |
| 89 | |
| 90 | static ssize_t dma_show_mode(struct sys_device *dev, char *buf) |
| 91 | { |
| 92 | struct dma_channel *channel = to_dma_channel(dev); |
| 93 | return sprintf(buf, "0x%08x\n", channel->mode); |
| 94 | } |
| 95 | |
| 96 | static ssize_t dma_store_mode(struct sys_device *dev, |
| 97 | const char *buf, size_t count) |
| 98 | { |
| 99 | struct dma_channel *channel = to_dma_channel(dev); |
| 100 | channel->mode = simple_strtoul(buf, NULL, 0); |
| 101 | return count; |
| 102 | } |
| 103 | |
| 104 | static SYSDEV_ATTR(mode, S_IRUGO | S_IWUSR, dma_show_mode, dma_store_mode); |
| 105 | |
| 106 | #define dma_ro_attr(field, fmt) \ |
| 107 | static ssize_t dma_show_##field(struct sys_device *dev, char *buf) \ |
| 108 | { \ |
| 109 | struct dma_channel *channel = to_dma_channel(dev); \ |
| 110 | return sprintf(buf, fmt, channel->field); \ |
| 111 | } \ |
| 112 | static SYSDEV_ATTR(field, S_IRUGO, dma_show_##field, NULL); |
| 113 | |
| 114 | dma_ro_attr(count, "0x%08x\n"); |
| 115 | dma_ro_attr(flags, "0x%08lx\n"); |
| 116 | |
Paul Mundt | 0d83177 | 2006-01-16 22:14:09 -0800 | [diff] [blame] | 117 | int dma_create_sysfs_files(struct dma_channel *chan, struct dma_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | { |
| 119 | struct sys_device *dev = &chan->dev; |
Paul Mundt | 0d83177 | 2006-01-16 22:14:09 -0800 | [diff] [blame] | 120 | char name[16]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | int ret; |
| 122 | |
Paul Mundt | 0d83177 | 2006-01-16 22:14:09 -0800 | [diff] [blame] | 123 | dev->id = chan->vchan; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | dev->cls = &dma_sysclass; |
| 125 | |
| 126 | ret = sysdev_register(dev); |
| 127 | if (ret) |
| 128 | return ret; |
| 129 | |
Paul Mundt | 4dfc119 | 2006-11-24 14:43:09 +0900 | [diff] [blame] | 130 | ret |= sysdev_create_file(dev, &attr_dev_id); |
| 131 | ret |= sysdev_create_file(dev, &attr_count); |
| 132 | ret |= sysdev_create_file(dev, &attr_mode); |
| 133 | ret |= sysdev_create_file(dev, &attr_flags); |
| 134 | ret |= sysdev_create_file(dev, &attr_config); |
| 135 | |
| 136 | if (unlikely(ret)) { |
| 137 | dev_err(&info->pdev->dev, "Failed creating attrs\n"); |
| 138 | return ret; |
| 139 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | |
Paul Mundt | 0d83177 | 2006-01-16 22:14:09 -0800 | [diff] [blame] | 141 | snprintf(name, sizeof(name), "dma%d", chan->chan); |
| 142 | return sysfs_create_link(&info->pdev->dev.kobj, &dev->kobj, name); |
| 143 | } |
| 144 | |
| 145 | void dma_remove_sysfs_files(struct dma_channel *chan, struct dma_info *info) |
| 146 | { |
| 147 | struct sys_device *dev = &chan->dev; |
| 148 | char name[16]; |
| 149 | |
| 150 | sysdev_remove_file(dev, &attr_dev_id); |
| 151 | sysdev_remove_file(dev, &attr_count); |
| 152 | sysdev_remove_file(dev, &attr_mode); |
| 153 | sysdev_remove_file(dev, &attr_flags); |
| 154 | sysdev_remove_file(dev, &attr_config); |
| 155 | |
| 156 | snprintf(name, sizeof(name), "dma%d", chan->chan); |
| 157 | sysfs_remove_link(&info->pdev->dev.kobj, name); |
| 158 | |
| 159 | sysdev_unregister(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | } |