| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
 | 2 |  * arch/sh/drivers/dma/dma-api.c | 
 | 3 |  * | 
 | 4 |  * SuperH-specific DMA management API | 
 | 5 |  * | 
| Paul Mundt | 0d83177 | 2006-01-16 22:14:09 -0800 | [diff] [blame] | 6 |  * Copyright (C) 2003, 2004, 2005  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/init.h> | 
 | 13 | #include <linux/module.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/spinlock.h> | 
 | 15 | #include <linux/proc_fs.h> | 
 | 16 | #include <linux/list.h> | 
| Paul Mundt | 0d83177 | 2006-01-16 22:14:09 -0800 | [diff] [blame] | 17 | #include <linux/platform_device.h> | 
| Mark Glaisher | db9b99d | 2006-11-24 15:13:52 +0900 | [diff] [blame] | 18 | #include <linux/mm.h> | 
| Manuel Lauss | bdff33d | 2007-05-31 13:44:17 +0900 | [diff] [blame] | 19 | #include <linux/sched.h> | 
| Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 20 | #include <linux/slab.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <asm/dma.h> | 
 | 22 |  | 
 | 23 | DEFINE_SPINLOCK(dma_spin_lock); | 
 | 24 | static LIST_HEAD(registered_dmac_list); | 
 | 25 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | struct dma_info *get_dma_info(unsigned int chan) | 
 | 27 | { | 
| Paul Mundt | 0d83177 | 2006-01-16 22:14:09 -0800 | [diff] [blame] | 28 | 	struct dma_info *info; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 |  | 
 | 30 | 	/* | 
 | 31 | 	 * Look for each DMAC's range to determine who the owner of | 
 | 32 | 	 * the channel is. | 
 | 33 | 	 */ | 
| Paul Mundt | 0d83177 | 2006-01-16 22:14:09 -0800 | [diff] [blame] | 34 | 	list_for_each_entry(info, ®istered_dmac_list, list) { | 
| Adrian McMenamin | eb695db | 2007-07-24 13:30:55 +0900 | [diff] [blame] | 35 | 		if ((chan <  info->first_vchannel_nr) || | 
 | 36 | 		    (chan >= info->first_vchannel_nr + info->nr_channels)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | 			continue; | 
 | 38 |  | 
 | 39 | 		return info; | 
 | 40 | 	} | 
 | 41 |  | 
 | 42 | 	return NULL; | 
 | 43 | } | 
| Mark Glaisher | db9b99d | 2006-11-24 15:13:52 +0900 | [diff] [blame] | 44 | EXPORT_SYMBOL(get_dma_info); | 
 | 45 |  | 
 | 46 | struct dma_info *get_dma_info_by_name(const char *dmac_name) | 
 | 47 | { | 
 | 48 | 	struct dma_info *info; | 
 | 49 |  | 
 | 50 | 	list_for_each_entry(info, ®istered_dmac_list, list) { | 
 | 51 | 		if (dmac_name && (strcmp(dmac_name, info->name) != 0)) | 
 | 52 | 			continue; | 
 | 53 | 		else | 
 | 54 | 			return info; | 
 | 55 | 	} | 
 | 56 |  | 
 | 57 | 	return NULL; | 
 | 58 | } | 
 | 59 | EXPORT_SYMBOL(get_dma_info_by_name); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 |  | 
| Paul Mundt | 0d83177 | 2006-01-16 22:14:09 -0800 | [diff] [blame] | 61 | static unsigned int get_nr_channels(void) | 
 | 62 | { | 
 | 63 | 	struct dma_info *info; | 
 | 64 | 	unsigned int nr = 0; | 
 | 65 |  | 
 | 66 | 	if (unlikely(list_empty(®istered_dmac_list))) | 
 | 67 | 		return nr; | 
 | 68 |  | 
 | 69 | 	list_for_each_entry(info, ®istered_dmac_list, list) | 
 | 70 | 		nr += info->nr_channels; | 
 | 71 |  | 
 | 72 | 	return nr; | 
 | 73 | } | 
 | 74 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | struct dma_channel *get_dma_channel(unsigned int chan) | 
 | 76 | { | 
 | 77 | 	struct dma_info *info = get_dma_info(chan); | 
| Mark Glaisher | db9b99d | 2006-11-24 15:13:52 +0900 | [diff] [blame] | 78 | 	struct dma_channel *channel; | 
 | 79 | 	int i; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 |  | 
| Mark Glaisher | db9b99d | 2006-11-24 15:13:52 +0900 | [diff] [blame] | 81 | 	if (unlikely(!info)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | 		return ERR_PTR(-EINVAL); | 
 | 83 |  | 
| Mark Glaisher | db9b99d | 2006-11-24 15:13:52 +0900 | [diff] [blame] | 84 | 	for (i = 0; i < info->nr_channels; i++) { | 
 | 85 | 		channel = &info->channels[i]; | 
| Adrian McMenamin | eb695db | 2007-07-24 13:30:55 +0900 | [diff] [blame] | 86 | 		if (channel->vchan == chan) | 
| Mark Glaisher | db9b99d | 2006-11-24 15:13:52 +0900 | [diff] [blame] | 87 | 			return channel; | 
 | 88 | 	} | 
 | 89 |  | 
 | 90 | 	return NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | } | 
| Mark Glaisher | db9b99d | 2006-11-24 15:13:52 +0900 | [diff] [blame] | 92 | EXPORT_SYMBOL(get_dma_channel); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 |  | 
 | 94 | int get_dma_residue(unsigned int chan) | 
 | 95 | { | 
 | 96 | 	struct dma_info *info = get_dma_info(chan); | 
| Mark Glaisher | db9b99d | 2006-11-24 15:13:52 +0900 | [diff] [blame] | 97 | 	struct dma_channel *channel = get_dma_channel(chan); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 |  | 
 | 99 | 	if (info->ops->get_residue) | 
 | 100 | 		return info->ops->get_residue(channel); | 
 | 101 |  | 
 | 102 | 	return 0; | 
 | 103 | } | 
| Mark Glaisher | db9b99d | 2006-11-24 15:13:52 +0900 | [diff] [blame] | 104 | EXPORT_SYMBOL(get_dma_residue); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 |  | 
| Mark Glaisher | db9b99d | 2006-11-24 15:13:52 +0900 | [diff] [blame] | 106 | static int search_cap(const char **haystack, const char *needle) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | { | 
| Mark Glaisher | db9b99d | 2006-11-24 15:13:52 +0900 | [diff] [blame] | 108 | 	const char **p; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 |  | 
| Mark Glaisher | db9b99d | 2006-11-24 15:13:52 +0900 | [diff] [blame] | 110 | 	for (p = haystack; *p; p++) | 
 | 111 | 		if (strcmp(*p, needle) == 0) | 
 | 112 | 			return 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 |  | 
 | 114 | 	return 0; | 
 | 115 | } | 
 | 116 |  | 
| Mark Glaisher | db9b99d | 2006-11-24 15:13:52 +0900 | [diff] [blame] | 117 | /** | 
 | 118 |  * request_dma_bycap - Allocate a DMA channel based on its capabilities | 
 | 119 |  * @dmac: List of DMA controllers to search | 
| Simon Arlott | e868d61 | 2007-05-14 08:15:10 +0900 | [diff] [blame] | 120 |  * @caps: List of capabilities | 
| Mark Glaisher | db9b99d | 2006-11-24 15:13:52 +0900 | [diff] [blame] | 121 |  * | 
 | 122 |  * Search all channels of all DMA controllers to find a channel which | 
 | 123 |  * matches the requested capabilities. The result is the channel | 
 | 124 |  * number if a match is found, or %-ENODEV if no match is found. | 
 | 125 |  * | 
 | 126 |  * Note that not all DMA controllers export capabilities, in which | 
 | 127 |  * case they can never be allocated using this API, and so | 
 | 128 |  * request_dma() must be used specifying the channel number. | 
 | 129 |  */ | 
 | 130 | int request_dma_bycap(const char **dmac, const char **caps, const char *dev_id) | 
 | 131 | { | 
 | 132 | 	unsigned int found = 0; | 
 | 133 | 	struct dma_info *info; | 
 | 134 | 	const char **p; | 
 | 135 | 	int i; | 
 | 136 |  | 
 | 137 | 	BUG_ON(!dmac || !caps); | 
 | 138 |  | 
 | 139 | 	list_for_each_entry(info, ®istered_dmac_list, list) | 
 | 140 | 		if (strcmp(*dmac, info->name) == 0) { | 
 | 141 | 			found = 1; | 
 | 142 | 			break; | 
 | 143 | 		} | 
 | 144 |  | 
 | 145 | 	if (!found) | 
 | 146 | 		return -ENODEV; | 
 | 147 |  | 
 | 148 | 	for (i = 0; i < info->nr_channels; i++) { | 
 | 149 | 		struct dma_channel *channel = &info->channels[i]; | 
 | 150 |  | 
 | 151 | 		if (unlikely(!channel->caps)) | 
 | 152 | 			continue; | 
 | 153 |  | 
 | 154 | 		for (p = caps; *p; p++) { | 
 | 155 | 			if (!search_cap(channel->caps, *p)) | 
 | 156 | 				break; | 
 | 157 | 			if (request_dma(channel->chan, dev_id) == 0) | 
 | 158 | 				return channel->chan; | 
 | 159 | 		} | 
 | 160 | 	} | 
 | 161 |  | 
 | 162 | 	return -EINVAL; | 
 | 163 | } | 
 | 164 | EXPORT_SYMBOL(request_dma_bycap); | 
 | 165 |  | 
 | 166 | int dmac_search_free_channel(const char *dev_id) | 
 | 167 | { | 
 | 168 | 	struct dma_channel *channel = { 0 }; | 
 | 169 | 	struct dma_info *info = get_dma_info(0); | 
 | 170 | 	int i; | 
 | 171 |  | 
 | 172 | 	for (i = 0; i < info->nr_channels; i++) { | 
 | 173 | 		channel = &info->channels[i]; | 
 | 174 | 		if (unlikely(!channel)) | 
 | 175 | 			return -ENODEV; | 
 | 176 |  | 
 | 177 | 		if (atomic_read(&channel->busy) == 0) | 
 | 178 | 			break; | 
 | 179 | 	} | 
 | 180 |  | 
 | 181 | 	if (info->ops->request) { | 
 | 182 | 		int result = info->ops->request(channel); | 
 | 183 | 		if (result) | 
 | 184 | 			return result; | 
 | 185 |  | 
 | 186 | 		atomic_set(&channel->busy, 1); | 
 | 187 | 		return channel->chan; | 
 | 188 | 	} | 
 | 189 |  | 
 | 190 | 	return -ENOSYS; | 
 | 191 | } | 
 | 192 |  | 
 | 193 | int request_dma(unsigned int chan, const char *dev_id) | 
 | 194 | { | 
 | 195 | 	struct dma_channel *channel = { 0 }; | 
 | 196 | 	struct dma_info *info = get_dma_info(chan); | 
 | 197 | 	int result; | 
 | 198 |  | 
 | 199 | 	channel = get_dma_channel(chan); | 
 | 200 | 	if (atomic_xchg(&channel->busy, 1)) | 
 | 201 | 		return -EBUSY; | 
 | 202 |  | 
 | 203 | 	strlcpy(channel->dev_id, dev_id, sizeof(channel->dev_id)); | 
 | 204 |  | 
 | 205 | 	if (info->ops->request) { | 
 | 206 | 		result = info->ops->request(channel); | 
 | 207 | 		if (result) | 
 | 208 | 			atomic_set(&channel->busy, 0); | 
 | 209 |  | 
 | 210 | 		return result; | 
 | 211 | 	} | 
 | 212 |  | 
 | 213 | 	return 0; | 
 | 214 | } | 
 | 215 | EXPORT_SYMBOL(request_dma); | 
 | 216 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | void free_dma(unsigned int chan) | 
 | 218 | { | 
 | 219 | 	struct dma_info *info = get_dma_info(chan); | 
| Mark Glaisher | db9b99d | 2006-11-24 15:13:52 +0900 | [diff] [blame] | 220 | 	struct dma_channel *channel = get_dma_channel(chan); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 |  | 
 | 222 | 	if (info->ops->free) | 
 | 223 | 		info->ops->free(channel); | 
 | 224 |  | 
 | 225 | 	atomic_set(&channel->busy, 0); | 
 | 226 | } | 
| Mark Glaisher | db9b99d | 2006-11-24 15:13:52 +0900 | [diff] [blame] | 227 | EXPORT_SYMBOL(free_dma); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 |  | 
 | 229 | void dma_wait_for_completion(unsigned int chan) | 
 | 230 | { | 
 | 231 | 	struct dma_info *info = get_dma_info(chan); | 
| Mark Glaisher | db9b99d | 2006-11-24 15:13:52 +0900 | [diff] [blame] | 232 | 	struct dma_channel *channel = get_dma_channel(chan); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 |  | 
 | 234 | 	if (channel->flags & DMA_TEI_CAPABLE) { | 
 | 235 | 		wait_event(channel->wait_queue, | 
 | 236 | 			   (info->ops->get_residue(channel) == 0)); | 
 | 237 | 		return; | 
 | 238 | 	} | 
 | 239 |  | 
 | 240 | 	while (info->ops->get_residue(channel)) | 
 | 241 | 		cpu_relax(); | 
 | 242 | } | 
| Mark Glaisher | db9b99d | 2006-11-24 15:13:52 +0900 | [diff] [blame] | 243 | EXPORT_SYMBOL(dma_wait_for_completion); | 
 | 244 |  | 
 | 245 | int register_chan_caps(const char *dmac, struct dma_chan_caps *caps) | 
 | 246 | { | 
 | 247 | 	struct dma_info *info; | 
 | 248 | 	unsigned int found = 0; | 
 | 249 | 	int i; | 
 | 250 |  | 
 | 251 | 	list_for_each_entry(info, ®istered_dmac_list, list) | 
 | 252 | 		if (strcmp(dmac, info->name) == 0) { | 
 | 253 | 			found = 1; | 
 | 254 | 			break; | 
 | 255 | 		} | 
 | 256 |  | 
 | 257 | 	if (unlikely(!found)) | 
 | 258 | 		return -ENODEV; | 
 | 259 |  | 
 | 260 | 	for (i = 0; i < info->nr_channels; i++, caps++) { | 
 | 261 | 		struct dma_channel *channel; | 
 | 262 |  | 
 | 263 | 		if ((info->first_channel_nr + i) != caps->ch_num) | 
 | 264 | 			return -EINVAL; | 
 | 265 |  | 
 | 266 | 		channel = &info->channels[i]; | 
 | 267 | 		channel->caps = caps->caplist; | 
 | 268 | 	} | 
 | 269 |  | 
 | 270 | 	return 0; | 
 | 271 | } | 
 | 272 | EXPORT_SYMBOL(register_chan_caps); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 |  | 
 | 274 | void dma_configure_channel(unsigned int chan, unsigned long flags) | 
 | 275 | { | 
 | 276 | 	struct dma_info *info = get_dma_info(chan); | 
| Mark Glaisher | db9b99d | 2006-11-24 15:13:52 +0900 | [diff] [blame] | 277 | 	struct dma_channel *channel = get_dma_channel(chan); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 |  | 
 | 279 | 	if (info->ops->configure) | 
 | 280 | 		info->ops->configure(channel, flags); | 
 | 281 | } | 
| Mark Glaisher | db9b99d | 2006-11-24 15:13:52 +0900 | [diff] [blame] | 282 | EXPORT_SYMBOL(dma_configure_channel); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 |  | 
 | 284 | int dma_xfer(unsigned int chan, unsigned long from, | 
 | 285 | 	     unsigned long to, size_t size, unsigned int mode) | 
 | 286 | { | 
 | 287 | 	struct dma_info *info = get_dma_info(chan); | 
| Mark Glaisher | db9b99d | 2006-11-24 15:13:52 +0900 | [diff] [blame] | 288 | 	struct dma_channel *channel = get_dma_channel(chan); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 |  | 
 | 290 | 	channel->sar	= from; | 
 | 291 | 	channel->dar	= to; | 
 | 292 | 	channel->count	= size; | 
 | 293 | 	channel->mode	= mode; | 
 | 294 |  | 
 | 295 | 	return info->ops->xfer(channel); | 
 | 296 | } | 
| Mark Glaisher | db9b99d | 2006-11-24 15:13:52 +0900 | [diff] [blame] | 297 | EXPORT_SYMBOL(dma_xfer); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 |  | 
| Mark Glaisher | db9b99d | 2006-11-24 15:13:52 +0900 | [diff] [blame] | 299 | int dma_extend(unsigned int chan, unsigned long op, void *param) | 
 | 300 | { | 
 | 301 | 	struct dma_info *info = get_dma_info(chan); | 
 | 302 | 	struct dma_channel *channel = get_dma_channel(chan); | 
 | 303 |  | 
 | 304 | 	if (info->ops->extend) | 
 | 305 | 		return info->ops->extend(channel, op, param); | 
 | 306 |  | 
 | 307 | 	return -ENOSYS; | 
 | 308 | } | 
 | 309 | EXPORT_SYMBOL(dma_extend); | 
 | 310 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | static int dma_read_proc(char *buf, char **start, off_t off, | 
 | 312 | 			 int len, int *eof, void *data) | 
 | 313 | { | 
| Paul Mundt | 0d83177 | 2006-01-16 22:14:09 -0800 | [diff] [blame] | 314 | 	struct dma_info *info; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | 	char *p = buf; | 
 | 316 |  | 
 | 317 | 	if (list_empty(®istered_dmac_list)) | 
 | 318 | 		return 0; | 
 | 319 |  | 
 | 320 | 	/* | 
 | 321 | 	 * Iterate over each registered DMAC | 
 | 322 | 	 */ | 
| Paul Mundt | 0d83177 | 2006-01-16 22:14:09 -0800 | [diff] [blame] | 323 | 	list_for_each_entry(info, ®istered_dmac_list, list) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | 		int i; | 
 | 325 |  | 
 | 326 | 		/* | 
 | 327 | 		 * Iterate over each channel | 
 | 328 | 		 */ | 
 | 329 | 		for (i = 0; i < info->nr_channels; i++) { | 
 | 330 | 			struct dma_channel *channel = info->channels + i; | 
 | 331 |  | 
 | 332 | 			if (!(channel->flags & DMA_CONFIGURED)) | 
 | 333 | 				continue; | 
 | 334 |  | 
 | 335 | 			p += sprintf(p, "%2d: %14s    %s\n", i, | 
 | 336 | 				     info->name, channel->dev_id); | 
 | 337 | 		} | 
 | 338 | 	} | 
 | 339 |  | 
 | 340 | 	return p - buf; | 
 | 341 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 |  | 
| Paul Mundt | 0d83177 | 2006-01-16 22:14:09 -0800 | [diff] [blame] | 343 | int register_dmac(struct dma_info *info) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | { | 
| Paul Mundt | 0d83177 | 2006-01-16 22:14:09 -0800 | [diff] [blame] | 345 | 	unsigned int total_channels, i; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 |  | 
 | 347 | 	INIT_LIST_HEAD(&info->list); | 
 | 348 |  | 
 | 349 | 	printk(KERN_INFO "DMA: Registering %s handler (%d channel%s).\n", | 
| Mark Glaisher | db9b99d | 2006-11-24 15:13:52 +0900 | [diff] [blame] | 350 | 	       info->name, info->nr_channels, info->nr_channels > 1 ? "s" : ""); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 |  | 
 | 352 | 	BUG_ON((info->flags & DMAC_CHANNELS_CONFIGURED) && !info->channels); | 
 | 353 |  | 
| Stephen Rothwell | 222dc79 | 2008-02-02 23:03:47 +1100 | [diff] [blame] | 354 | 	info->pdev = platform_device_register_simple(info->name, -1, | 
| Paul Mundt | 0d83177 | 2006-01-16 22:14:09 -0800 | [diff] [blame] | 355 | 						     NULL, 0); | 
 | 356 | 	if (IS_ERR(info->pdev)) | 
 | 357 | 		return PTR_ERR(info->pdev); | 
 | 358 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | 	/* | 
 | 360 | 	 * Don't touch pre-configured channels | 
 | 361 | 	 */ | 
 | 362 | 	if (!(info->flags & DMAC_CHANNELS_CONFIGURED)) { | 
 | 363 | 		unsigned int size; | 
 | 364 |  | 
 | 365 | 		size = sizeof(struct dma_channel) * info->nr_channels; | 
 | 366 |  | 
| Mark Glaisher | db9b99d | 2006-11-24 15:13:52 +0900 | [diff] [blame] | 367 | 		info->channels = kzalloc(size, GFP_KERNEL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | 		if (!info->channels) | 
 | 369 | 			return -ENOMEM; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | 	} | 
 | 371 |  | 
| Paul Mundt | 0d83177 | 2006-01-16 22:14:09 -0800 | [diff] [blame] | 372 | 	total_channels = get_nr_channels(); | 
| Adrian McMenamin | eb695db | 2007-07-24 13:30:55 +0900 | [diff] [blame] | 373 | 	info->first_vchannel_nr = total_channels; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | 	for (i = 0; i < info->nr_channels; i++) { | 
| Mark Glaisher | db9b99d | 2006-11-24 15:13:52 +0900 | [diff] [blame] | 375 | 		struct dma_channel *chan = &info->channels[i]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 |  | 
| Mark Glaisher | db9b99d | 2006-11-24 15:13:52 +0900 | [diff] [blame] | 377 | 		atomic_set(&chan->busy, 0); | 
 | 378 |  | 
 | 379 | 		chan->chan  = info->first_channel_nr + i; | 
 | 380 | 		chan->vchan = info->first_channel_nr + i + total_channels; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 |  | 
 | 382 | 		memcpy(chan->dev_id, "Unused", 7); | 
 | 383 |  | 
 | 384 | 		if (info->flags & DMAC_CHANNELS_TEI_CAPABLE) | 
 | 385 | 			chan->flags |= DMA_TEI_CAPABLE; | 
 | 386 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | 		init_waitqueue_head(&chan->wait_queue); | 
| Paul Mundt | 0d83177 | 2006-01-16 22:14:09 -0800 | [diff] [blame] | 388 | 		dma_create_sysfs_files(chan, info); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | 	} | 
 | 390 |  | 
 | 391 | 	list_add(&info->list, ®istered_dmac_list); | 
 | 392 |  | 
 | 393 | 	return 0; | 
 | 394 | } | 
| Mark Glaisher | db9b99d | 2006-11-24 15:13:52 +0900 | [diff] [blame] | 395 | EXPORT_SYMBOL(register_dmac); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 |  | 
| Paul Mundt | 0d83177 | 2006-01-16 22:14:09 -0800 | [diff] [blame] | 397 | void unregister_dmac(struct dma_info *info) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | { | 
| Paul Mundt | 0d83177 | 2006-01-16 22:14:09 -0800 | [diff] [blame] | 399 | 	unsigned int i; | 
 | 400 |  | 
 | 401 | 	for (i = 0; i < info->nr_channels; i++) | 
 | 402 | 		dma_remove_sysfs_files(info->channels + i, info); | 
 | 403 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | 	if (!(info->flags & DMAC_CHANNELS_CONFIGURED)) | 
 | 405 | 		kfree(info->channels); | 
 | 406 |  | 
 | 407 | 	list_del(&info->list); | 
| Paul Mundt | 0d83177 | 2006-01-16 22:14:09 -0800 | [diff] [blame] | 408 | 	platform_device_unregister(info->pdev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | } | 
| Mark Glaisher | db9b99d | 2006-11-24 15:13:52 +0900 | [diff] [blame] | 410 | EXPORT_SYMBOL(unregister_dmac); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 |  | 
 | 412 | static int __init dma_api_init(void) | 
 | 413 | { | 
| Mark Glaisher | db9b99d | 2006-11-24 15:13:52 +0900 | [diff] [blame] | 414 | 	printk(KERN_NOTICE "DMA: Registering DMA API.\n"); | 
| Kulikov Vasiliy | 32dfab3 | 2010-07-28 16:39:26 +0000 | [diff] [blame] | 415 | 	return create_proc_read_entry("dma", 0, 0, dma_read_proc, 0) | 
 | 416 | 		    ? 0 : -ENOMEM; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | subsys_initcall(dma_api_init); | 
 | 419 |  | 
 | 420 | MODULE_AUTHOR("Paul Mundt <lethal@linux-sh.org>"); | 
 | 421 | MODULE_DESCRIPTION("DMA API for SuperH"); | 
 | 422 | MODULE_LICENSE("GPL"); |