| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * arch/sh/drivers/dma/dma-sysfs.c | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * sysfs interface for SH DMA API | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2006-11-24 14:43:09 +09:00
										 |  |  |  * Copyright (C) 2004 - 2006  Paul Mundt | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  |  * | 
					
						
							|  |  |  |  * 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>
 | 
					
						
							| 
									
										
										
										
											2011-07-31 17:40:26 -04:00
										 |  |  | #include <linux/stat.h>
 | 
					
						
							| 
									
										
										
										
											2011-12-21 15:09:52 -08:00
										 |  |  | #include <linux/device.h>
 | 
					
						
							| 
									
										
										
										
											2006-01-16 22:14:09 -08:00
										 |  |  | #include <linux/platform_device.h>
 | 
					
						
							|  |  |  | #include <linux/err.h>
 | 
					
						
							| 
									
										
										
										
											2005-10-30 15:03:48 -08:00
										 |  |  | #include <linux/string.h>
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | #include <asm/dma.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-21 15:09:52 -08:00
										 |  |  | static struct bus_type dma_subsys = { | 
					
						
							| 
									
										
										
										
											2007-12-20 02:09:39 +01:00
										 |  |  | 	.name = "dma", | 
					
						
							| 
									
										
										
										
											2011-12-21 15:09:52 -08:00
										 |  |  | 	.dev_name = "dma", | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-21 15:09:52 -08:00
										 |  |  | static ssize_t dma_show_devices(struct device *dev, | 
					
						
							|  |  |  | 				struct device_attribute *attr, char *buf) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	ssize_t len = 0; | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-19 18:50:09 +09:00
										 |  |  | 	for (i = 0; i < 16; i++) { | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		struct dma_info *info = get_dma_info(i); | 
					
						
							| 
									
										
										
										
											2006-11-24 14:43:09 +09:00
										 |  |  | 		struct dma_channel *channel = get_dma_channel(i); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (unlikely(!info) || !channel) | 
					
						
							|  |  |  | 			continue; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		len += sprintf(buf + len, "%2d: %14s    %s\n", | 
					
						
							|  |  |  | 			       channel->chan, info->name, | 
					
						
							|  |  |  | 			       channel->dev_id); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return len; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-21 15:09:52 -08:00
										 |  |  | static DEVICE_ATTR(devices, S_IRUGO, dma_show_devices, NULL); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-21 15:09:52 -08:00
										 |  |  | static int __init dma_subsys_init(void) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	int ret; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-21 15:09:52 -08:00
										 |  |  | 	ret = subsys_system_register(&dma_subsys, NULL); | 
					
						
							| 
									
										
										
										
											2006-10-03 13:14:04 +09:00
										 |  |  | 	if (unlikely(ret)) | 
					
						
							|  |  |  | 		return ret; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-30 19:36:03 +09:00
										 |  |  | 	return device_create_file(dma_subsys.dev_root, &dev_attr_devices); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2011-12-21 15:09:52 -08:00
										 |  |  | postcore_initcall(dma_subsys_init); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-21 15:09:52 -08:00
										 |  |  | static ssize_t dma_show_dev_id(struct device *dev, | 
					
						
							|  |  |  | 				struct device_attribute *attr, char *buf) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct dma_channel *channel = to_dma_channel(dev); | 
					
						
							|  |  |  | 	return sprintf(buf, "%s\n", channel->dev_id); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-21 15:09:52 -08:00
										 |  |  | static ssize_t dma_store_dev_id(struct device *dev, | 
					
						
							|  |  |  | 				struct device_attribute *attr, | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 				const char *buf, size_t count) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct dma_channel *channel = to_dma_channel(dev); | 
					
						
							|  |  |  | 	strcpy(channel->dev_id, buf); | 
					
						
							|  |  |  | 	return count; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-21 15:09:52 -08:00
										 |  |  | static DEVICE_ATTR(dev_id, S_IRUGO | S_IWUSR, dma_show_dev_id, dma_store_dev_id); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-21 15:09:52 -08:00
										 |  |  | static ssize_t dma_store_config(struct device *dev, | 
					
						
							|  |  |  | 				struct device_attribute *attr, | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 				const char *buf, size_t count) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct dma_channel *channel = to_dma_channel(dev); | 
					
						
							|  |  |  | 	unsigned long config; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	config = simple_strtoul(buf, NULL, 0); | 
					
						
							| 
									
										
										
										
											2006-01-16 22:14:09 -08:00
										 |  |  | 	dma_configure_channel(channel->vchan, config); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return count; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-21 15:09:52 -08:00
										 |  |  | static DEVICE_ATTR(config, S_IWUSR, NULL, dma_store_config); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-21 15:09:52 -08:00
										 |  |  | static ssize_t dma_show_mode(struct device *dev, | 
					
						
							|  |  |  | 				struct device_attribute *attr, char *buf) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct dma_channel *channel = to_dma_channel(dev); | 
					
						
							|  |  |  | 	return sprintf(buf, "0x%08x\n", channel->mode); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-21 15:09:52 -08:00
										 |  |  | static ssize_t dma_store_mode(struct device *dev, | 
					
						
							|  |  |  | 			      struct device_attribute *attr, | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			      const char *buf, size_t count) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct dma_channel *channel = to_dma_channel(dev); | 
					
						
							|  |  |  | 	channel->mode = simple_strtoul(buf, NULL, 0); | 
					
						
							|  |  |  | 	return count; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-21 15:09:52 -08:00
										 |  |  | static DEVICE_ATTR(mode, S_IRUGO | S_IWUSR, dma_show_mode, dma_store_mode); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define dma_ro_attr(field, fmt)						\
 | 
					
						
							| 
									
										
										
										
											2011-12-21 15:09:52 -08:00
										 |  |  | static ssize_t dma_show_##field(struct device *dev,		\ | 
					
						
							|  |  |  | 				struct device_attribute *attr, char *buf)\ | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | {									\ | 
					
						
							|  |  |  | 	struct dma_channel *channel = to_dma_channel(dev);		\ | 
					
						
							|  |  |  | 	return sprintf(buf, fmt, channel->field);			\ | 
					
						
							|  |  |  | }									\ | 
					
						
							| 
									
										
										
										
											2011-12-21 15:09:52 -08:00
										 |  |  | static DEVICE_ATTR(field, S_IRUGO, dma_show_##field, NULL); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | dma_ro_attr(count, "0x%08x\n"); | 
					
						
							|  |  |  | dma_ro_attr(flags, "0x%08lx\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-16 22:14:09 -08:00
										 |  |  | int dma_create_sysfs_files(struct dma_channel *chan, struct dma_info *info) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-21 15:09:52 -08:00
										 |  |  | 	struct device *dev = &chan->dev; | 
					
						
							| 
									
										
										
										
											2006-01-16 22:14:09 -08:00
										 |  |  | 	char name[16]; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	int ret; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-16 22:14:09 -08:00
										 |  |  | 	dev->id  = chan->vchan; | 
					
						
							| 
									
										
										
										
											2011-12-21 15:09:52 -08:00
										 |  |  | 	dev->bus = &dma_subsys; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-21 15:09:52 -08:00
										 |  |  | 	ret = device_register(dev); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	if (ret) | 
					
						
							|  |  |  | 		return ret; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-21 15:09:52 -08:00
										 |  |  | 	ret |= device_create_file(dev, &dev_attr_dev_id); | 
					
						
							|  |  |  | 	ret |= device_create_file(dev, &dev_attr_count); | 
					
						
							|  |  |  | 	ret |= device_create_file(dev, &dev_attr_mode); | 
					
						
							|  |  |  | 	ret |= device_create_file(dev, &dev_attr_flags); | 
					
						
							|  |  |  | 	ret |= device_create_file(dev, &dev_attr_config); | 
					
						
							| 
									
										
										
										
											2006-11-24 14:43:09 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (unlikely(ret)) { | 
					
						
							|  |  |  | 		dev_err(&info->pdev->dev, "Failed creating attrs\n"); | 
					
						
							|  |  |  | 		return ret; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-16 22:14:09 -08:00
										 |  |  | 	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) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-21 15:09:52 -08:00
										 |  |  | 	struct device *dev = &chan->dev; | 
					
						
							| 
									
										
										
										
											2006-01-16 22:14:09 -08:00
										 |  |  | 	char name[16]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-21 15:09:52 -08:00
										 |  |  | 	device_remove_file(dev, &dev_attr_dev_id); | 
					
						
							|  |  |  | 	device_remove_file(dev, &dev_attr_count); | 
					
						
							|  |  |  | 	device_remove_file(dev, &dev_attr_mode); | 
					
						
							|  |  |  | 	device_remove_file(dev, &dev_attr_flags); | 
					
						
							|  |  |  | 	device_remove_file(dev, &dev_attr_config); | 
					
						
							| 
									
										
										
										
											2006-01-16 22:14:09 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	snprintf(name, sizeof(name), "dma%d", chan->chan); | 
					
						
							|  |  |  | 	sysfs_remove_link(&info->pdev->dev.kobj, name); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-21 15:09:52 -08:00
										 |  |  | 	device_unregister(dev); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | } |