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> |
Paul Gortmaker | 0c43871 | 2011-07-31 17:40:26 -0400 | [diff] [blame] | 14 | #include <linux/stat.h> |
Kay Sievers | dc6876a | 2011-12-21 15:09:52 -0800 | [diff] [blame] | 15 | #include <linux/device.h> |
Paul Mundt | 0d83177 | 2006-01-16 22:14:09 -0800 | [diff] [blame] | 16 | #include <linux/platform_device.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 | |
Kay Sievers | dc6876a | 2011-12-21 15:09:52 -0800 | [diff] [blame] | 21 | static struct bus_type dma_subsys = { |
Kay Sievers | af5ca3f | 2007-12-20 02:09:39 +0100 | [diff] [blame] | 22 | .name = "dma", |
Kay Sievers | dc6876a | 2011-12-21 15:09:52 -0800 | [diff] [blame] | 23 | .dev_name = "dma", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
Kay Sievers | dc6876a | 2011-12-21 15:09:52 -0800 | [diff] [blame] | 26 | static ssize_t dma_show_devices(struct device *dev, |
| 27 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | { |
| 29 | ssize_t len = 0; |
| 30 | int i; |
| 31 | |
Paul Mundt | e24cca1 | 2012-05-19 18:50:09 +0900 | [diff] [blame] | 32 | for (i = 0; i < 16; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | struct dma_info *info = get_dma_info(i); |
Paul Mundt | 4dfc119 | 2006-11-24 14:43:09 +0900 | [diff] [blame] | 34 | struct dma_channel *channel = get_dma_channel(i); |
| 35 | |
| 36 | if (unlikely(!info) || !channel) |
| 37 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
| 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 | |
Kay Sievers | dc6876a | 2011-12-21 15:09:52 -0800 | [diff] [blame] | 47 | static DEVICE_ATTR(devices, S_IRUGO, dma_show_devices, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
Kay Sievers | dc6876a | 2011-12-21 15:09:52 -0800 | [diff] [blame] | 49 | static int __init dma_subsys_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | { |
| 51 | int ret; |
| 52 | |
Kay Sievers | dc6876a | 2011-12-21 15:09:52 -0800 | [diff] [blame] | 53 | ret = subsys_system_register(&dma_subsys, NULL); |
Paul Mundt | 711fa80 | 2006-10-03 13:14:04 +0900 | [diff] [blame] | 54 | if (unlikely(ret)) |
| 55 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
Paul Mundt | 87c34ed | 2012-03-30 19:36:03 +0900 | [diff] [blame] | 57 | return device_create_file(dma_subsys.dev_root, &dev_attr_devices); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | } |
Kay Sievers | dc6876a | 2011-12-21 15:09:52 -0800 | [diff] [blame] | 59 | postcore_initcall(dma_subsys_init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | |
Kay Sievers | dc6876a | 2011-12-21 15:09:52 -0800 | [diff] [blame] | 61 | static ssize_t dma_show_dev_id(struct device *dev, |
| 62 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | { |
| 64 | struct dma_channel *channel = to_dma_channel(dev); |
| 65 | return sprintf(buf, "%s\n", channel->dev_id); |
| 66 | } |
| 67 | |
Kay Sievers | dc6876a | 2011-12-21 15:09:52 -0800 | [diff] [blame] | 68 | static ssize_t dma_store_dev_id(struct device *dev, |
| 69 | struct device_attribute *attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | 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 | |
Kay Sievers | dc6876a | 2011-12-21 15:09:52 -0800 | [diff] [blame] | 77 | static DEVICE_ATTR(dev_id, S_IRUGO | S_IWUSR, dma_show_dev_id, dma_store_dev_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | |
Kay Sievers | dc6876a | 2011-12-21 15:09:52 -0800 | [diff] [blame] | 79 | static ssize_t dma_store_config(struct device *dev, |
| 80 | struct device_attribute *attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | 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 Mundt | 0d83177 | 2006-01-16 22:14:09 -0800 | [diff] [blame] | 87 | dma_configure_channel(channel->vchan, config); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
| 89 | return count; |
| 90 | } |
| 91 | |
Kay Sievers | dc6876a | 2011-12-21 15:09:52 -0800 | [diff] [blame] | 92 | static DEVICE_ATTR(config, S_IWUSR, NULL, dma_store_config); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
Kay Sievers | dc6876a | 2011-12-21 15:09:52 -0800 | [diff] [blame] | 94 | static ssize_t dma_show_mode(struct device *dev, |
| 95 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | { |
| 97 | struct dma_channel *channel = to_dma_channel(dev); |
| 98 | return sprintf(buf, "0x%08x\n", channel->mode); |
| 99 | } |
| 100 | |
Kay Sievers | dc6876a | 2011-12-21 15:09:52 -0800 | [diff] [blame] | 101 | static ssize_t dma_store_mode(struct device *dev, |
| 102 | struct device_attribute *attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | 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 | |
Kay Sievers | dc6876a | 2011-12-21 15:09:52 -0800 | [diff] [blame] | 110 | static DEVICE_ATTR(mode, S_IRUGO | S_IWUSR, dma_show_mode, dma_store_mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | |
| 112 | #define dma_ro_attr(field, fmt) \ |
Kay Sievers | dc6876a | 2011-12-21 15:09:52 -0800 | [diff] [blame] | 113 | static ssize_t dma_show_##field(struct device *dev, \ |
| 114 | struct device_attribute *attr, char *buf)\ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | { \ |
| 116 | struct dma_channel *channel = to_dma_channel(dev); \ |
| 117 | return sprintf(buf, fmt, channel->field); \ |
| 118 | } \ |
Kay Sievers | dc6876a | 2011-12-21 15:09:52 -0800 | [diff] [blame] | 119 | static DEVICE_ATTR(field, S_IRUGO, dma_show_##field, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | |
| 121 | dma_ro_attr(count, "0x%08x\n"); |
| 122 | dma_ro_attr(flags, "0x%08lx\n"); |
| 123 | |
Paul Mundt | 0d83177 | 2006-01-16 22:14:09 -0800 | [diff] [blame] | 124 | 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] | 125 | { |
Kay Sievers | dc6876a | 2011-12-21 15:09:52 -0800 | [diff] [blame] | 126 | struct device *dev = &chan->dev; |
Paul Mundt | 0d83177 | 2006-01-16 22:14:09 -0800 | [diff] [blame] | 127 | char name[16]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | int ret; |
| 129 | |
Paul Mundt | 0d83177 | 2006-01-16 22:14:09 -0800 | [diff] [blame] | 130 | dev->id = chan->vchan; |
Kay Sievers | dc6876a | 2011-12-21 15:09:52 -0800 | [diff] [blame] | 131 | dev->bus = &dma_subsys; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | |
Kay Sievers | dc6876a | 2011-12-21 15:09:52 -0800 | [diff] [blame] | 133 | ret = device_register(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | if (ret) |
| 135 | return ret; |
| 136 | |
Kay Sievers | dc6876a | 2011-12-21 15:09:52 -0800 | [diff] [blame] | 137 | ret |= device_create_file(dev, &dev_attr_dev_id); |
| 138 | ret |= device_create_file(dev, &dev_attr_count); |
| 139 | ret |= device_create_file(dev, &dev_attr_mode); |
| 140 | ret |= device_create_file(dev, &dev_attr_flags); |
| 141 | ret |= device_create_file(dev, &dev_attr_config); |
Paul Mundt | 4dfc119 | 2006-11-24 14:43:09 +0900 | [diff] [blame] | 142 | |
| 143 | if (unlikely(ret)) { |
| 144 | dev_err(&info->pdev->dev, "Failed creating attrs\n"); |
| 145 | return ret; |
| 146 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | |
Paul Mundt | 0d83177 | 2006-01-16 22:14:09 -0800 | [diff] [blame] | 148 | snprintf(name, sizeof(name), "dma%d", chan->chan); |
| 149 | return sysfs_create_link(&info->pdev->dev.kobj, &dev->kobj, name); |
| 150 | } |
| 151 | |
| 152 | void dma_remove_sysfs_files(struct dma_channel *chan, struct dma_info *info) |
| 153 | { |
Kay Sievers | dc6876a | 2011-12-21 15:09:52 -0800 | [diff] [blame] | 154 | struct device *dev = &chan->dev; |
Paul Mundt | 0d83177 | 2006-01-16 22:14:09 -0800 | [diff] [blame] | 155 | char name[16]; |
| 156 | |
Kay Sievers | dc6876a | 2011-12-21 15:09:52 -0800 | [diff] [blame] | 157 | device_remove_file(dev, &dev_attr_dev_id); |
| 158 | device_remove_file(dev, &dev_attr_count); |
| 159 | device_remove_file(dev, &dev_attr_mode); |
| 160 | device_remove_file(dev, &dev_attr_flags); |
| 161 | device_remove_file(dev, &dev_attr_config); |
Paul Mundt | 0d83177 | 2006-01-16 22:14:09 -0800 | [diff] [blame] | 162 | |
| 163 | snprintf(name, sizeof(name), "dma%d", chan->chan); |
| 164 | sysfs_remove_link(&info->pdev->dev.kobj, name); |
| 165 | |
Kay Sievers | dc6876a | 2011-12-21 15:09:52 -0800 | [diff] [blame] | 166 | device_unregister(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | } |