1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
|
diff -uNr dm355_codecs_1_13_000/dm355mm/module/dm350mmap.c dm355_codecs_1_13_000.new/dm355mm/module/dm350mmap.c
--- dm355_codecs_1_13_000/dm355mm/module/dm350mmap.c 2009-05-20 11:22:57.000000000 -0500
+++ dm355_codecs_1_13_000.new/dm355mm/module/dm350mmap.c 2009-06-09 10:43:25.000000000 -0500
@@ -7,7 +7,7 @@
* Use of this software is controlled by the terms and conditions found in the
* license agreement under which this software has been supplied or provided.
* ============================================================================
- */
+ */
#include <linux/module.h>
#include <linux/init.h>
#include <linux/moduleparam.h>
@@ -20,274 +20,283 @@
#include <linux/proc_fs.h>
#include <linux/kernel.h>
#include <linux/device.h>
-
+#include <linux/clk.h>
+
#include <asm/page.h>
#include <asm/uaccess.h>
#include <asm/pgtable.h>
#include <asm/io.h>
-#include<asm/system.h>
-#include<asm-arm/memory.h>
+#include <asm/system.h>
+#include <asm/memory.h>
+
#include <asm/irq.h>
-
+
+#include <linux/version.h>
#include <linux/completion.h>
-#include <asm/arch/edma.h>
-
+#include <mach/edma.h>
+
#define ASQINT_ENABLE
- typedef struct _edma_params
-{
- unsigned long src;
- unsigned long dst;
- unsigned int srcmode;
- unsigned int srcfifowidth;
- int srcbidx;
- int srccidx;
- unsigned int dstmode;
- unsigned int dstfifowidth;
- int dstbidx;
- int dstcidx;
- int acnt;
- int bcnt;
- int ccnt;
- int bcntrld;
- int syncmode;
- } edma_params;
+typedef struct _edma_params {
+ unsigned long src;
+ unsigned long dst;
+ unsigned int srcmode;
+ unsigned int srcfifowidth;
+ int srcbidx;
+ int srccidx;
+ unsigned int dstmode;
+ unsigned int dstfifowidth;
+ int dstbidx;
+ int dstcidx;
+ int acnt;
+ int bcnt;
+ int ccnt;
+ int bcntrld;
+ int syncmode;
+} edma_params;
#define DM350MMAP_IOCMEMCPY 0x7
#define DM350MMAP_IOCWAIT 0x8
#define DM350MMAP_IOCCLEAR_PENDING 0x9
-
+
#ifdef __DEBUG
-#define __D(fmt, args...) printk(KERN_DEBUG "DM350MMAP Debug: " fmt, ## args)
+# define __D(fmt, args...) printk(KERN_DEBUG "DM350MMAP Debug: " fmt, ## args)
#else /* */
-#define __D(fmt, args...)
+# define __D(fmt, args...)
#endif /* */
-
+
#define __E(fmt, args...) printk(KERN_ERR "DM350MMAP Error: " fmt, ## args)
-
+
#define MAXTYPE(T) ((T) (((T)1 << ((sizeof(T) * 8) - 1) ^ ((T) -1))))
-
+
static int major = 0;
#if (USE_UDEV==1)
static struct class *dm350mmap_class;
-
#endif // USE_UDEV
-static DECLARE_MUTEX_LOCKED (dm350mmap_reply_mutex);
-int master_ch;
-struct completion edmacompletion;
-
-/* Forward declaration of system calls */
-static int ioctl (struct inode *inode, struct file *filp, unsigned int cmd,
- unsigned long args);
-static int mmap (struct file *filp, struct vm_area_struct *vma);
-static int open (struct inode *inode, struct file *filp);
-static int release (struct inode *inode, struct file *filp);
+
+static DECLARE_MUTEX(dm350mmap_reply_mutex);
+static struct completion edmacompletion;
+
+/* Forward declaration of system calls */
+static int ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
+ unsigned long args);
+static int mmap(struct file *filp, struct vm_area_struct *vma);
+static int open(struct inode *inode, struct file *filp);
+static int release(struct inode *inode, struct file *filp);
static struct file_operations dm350mmap_fxns = { ioctl: ioctl, mmap: mmap, open: open, release:release
-
};
-static irqreturn_t irq_handler (int irq, void *dev_id, struct pt_regs *regs)
+/* Structure to hold mjcp clock info */
+static struct clk *mjcp = NULL;
+
+//static irqreturn_t irq_handler (int irq, void *dev_id, struct pt_regs *regs)
+static irqreturn_t irq_handler(int irq, void *dev_id)
{
-
- /* Release the mutex, suggesting sequencer processing complete */
- up (&dm350mmap_reply_mutex);
- return IRQ_HANDLED;
+ /* Release the mutex, suggesting sequencer processing complete */
+ up(&dm350mmap_reply_mutex);
+ return IRQ_HANDLED;
}
-static void memcpy_dma_irq_handler (int lch, u16 ch_status, void *data)
+static void memcpy_dma_irq_handler(unsigned lch, u16 ch_status, void *data)
{
- complete_all (&edmacompletion);
-}
+ complete_all(&edmacompletion);
+}
-static int mmap (struct file *filp, struct vm_area_struct *vma)
+static int mmap(struct file *filp, struct vm_area_struct *vma)
{
- __D ("mmap: vma->vm_start = %#lx\n", vma->vm_start);
- __D ("mmap: vma->vm_pgoff = %#lx\n", vma->vm_pgoff);
- __D ("mmap: vma->vm_end = %#lx\n", vma->vm_end);
- __D ("mmap: size = %#lx\n", vma->vm_end - vma->vm_start);
- vma->vm_page_prot = pgprot_noncached (vma->vm_page_prot);
- if (remap_pfn_range (vma, vma->vm_start,
-
-#ifdef LINUX_2_6_18
- (vma->vm_pgoff >> PAGE_SHIFT),
+ __D("mmap: vma->vm_start = %#lx\n", vma->vm_start);
+ __D("mmap: vma->vm_pgoff = %#lx\n", vma->vm_pgoff);
+ __D("mmap: vma->vm_end = %#lx\n", vma->vm_end);
+ __D("mmap: size = %#lx\n", vma->vm_end - vma->vm_start);
+ vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
+ if (remap_pfn_range(vma, vma->vm_start,
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
+ (vma->vm_pgoff >> PAGE_SHIFT),
#else /* */
- vma->vm_pgoff,
+ vma->vm_pgoff,
#endif /* */
-
- vma->vm_end - vma->vm_start, vma->vm_page_prot))
- {
- __E ("mmap: failed remap_pfn_range\n");
- return -EAGAIN;
+ vma->vm_end - vma->vm_start, vma->vm_page_prot)) {
+ __E("mmap: failed remap_pfn_range\n");
+ return -EAGAIN;
}
- return 0;
+ return 0;
}
-static int ioctl (struct inode *inode, struct file *filp, unsigned int cmd,
- unsigned long args)
+static int ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
+ unsigned long args)
{
- unsigned int __user *argp = (unsigned int __user *) args;
- edma_params edmaparams;
- int err = 0, tcc = EDMA_TCC_ANY;
- struct paramentry_descriptor paramentry;
- switch (cmd)
- {
-
- /*
- * Tries to clear any previously unaccounted interrupt.
- */
- case DM350MMAP_IOCCLEAR_PENDING:
-
- {
- int retval;
- __D ("Clear Pending Call received.\n");
- init_MUTEX_LOCKED(&dm350mmap_reply_mutex);
- return 0;
- }
- break;
-
- /*
- * Blocks till the sequencer completion interrupt arrives.
- */
- case DM350MMAP_IOCWAIT:
-
- {
- int retval;
- __D ("WAIT Call received.\n");
- retval = down_interruptible (&dm350mmap_reply_mutex);
- return retval;
- }
- break;
- case DM350MMAP_IOCMEMCPY:
- __D ("MEMCPY ioctl received.\n");
- if (copy_from_user (&edmaparams, argp, sizeof (edmaparams)))
- {
- return -EFAULT;
- }
- err =
- davinci_request_dma (EDMA_DMA_CHANNEL_ANY, "EDMA memcpy",
- memcpy_dma_irq_handler, NULL, &master_ch, &tcc,
- EVENTQ_1);
-
- /* Handle Failure condition here */
- if (err < 0)
- {
- __E ("Error in requesting Master channel %d = 0x%x\n", master_ch,
- err);
- return err;
- }
- davinci_stop_dma (master_ch);
- init_completion (&edmacompletion);
- davinci_set_dma_src_params (master_ch,
- (unsigned long) edmaparams.src,
- edmaparams.srcmode,
- edmaparams.srcfifowidth);
- davinci_set_dma_dest_params (master_ch,
- (unsigned long) edmaparams.dst,
- edmaparams.dstmode,
- edmaparams.dstfifowidth);
- davinci_set_dma_src_index (master_ch, edmaparams.srcbidx,
- edmaparams.srccidx);
- davinci_set_dma_dest_index (master_ch, edmaparams.dstbidx,
- edmaparams.dstcidx);
- davinci_set_dma_transfer_params (master_ch, edmaparams.acnt,
- edmaparams.bcnt, edmaparams.ccnt,
- edmaparams.bcntrld,
- edmaparams.syncmode);
- davinci_get_dma_params (master_ch, ¶mentry);
-
- /*printk("%x : %x : %x : %x : %x : %x : %x\n", paramentry.opt,
- paramentry.a_b_cnt, paramentry.src_dst_bidx,
- paramentry.src_dst_cidx, paramentry.ccnt, paramentry.src,
- paramentry.dst); */
- davinci_set_dma_params (master_ch, ¶mentry);
- davinci_start_dma (master_ch);
- wait_for_completion (&edmacompletion);
-
- //printk("Dma completed... \n");
- davinci_stop_dma (master_ch);
- davinci_free_dma (master_ch);
- break;
- default:
- __E ("Unknown ioctl received = %d.\n", cmd);
- return -EINVAL;
+ unsigned int __user *argp = (unsigned int __user *) args;
+ edma_params edmaparams;
+ int edma_channel;
+ int retval = 0;
+ struct edmacc_param p_ram;
+
+ switch (cmd) {
+
+ /*
+ * Tries to clear any previously unaccounted interrupt.
+ */
+ case DM350MMAP_IOCCLEAR_PENDING:
+ __D("Clear Pending Call received.\n");
+ init_MUTEX_LOCKED(&dm350mmap_reply_mutex);
+ break;
+
+ /*
+ * Blocks till the sequencer completion interrupt arrives.
+ */
+ case DM350MMAP_IOCWAIT:
+ __D("WAIT Call received.\n");
+ retval = down_interruptible(&dm350mmap_reply_mutex);
+ break;
+
+ case DM350MMAP_IOCMEMCPY:
+ __D("MEMCPY ioctl received.\n");
+ if (copy_from_user(&edmaparams, argp, sizeof(edmaparams))) {
+ retval = -EFAULT;
+ break;
+ }
+
+ edma_channel =
+ edma_alloc_channel(EDMA_CHANNEL_ANY, &memcpy_dma_irq_handler,
+ NULL, EVENTQ_1);
+
+ /* Handle Failure condition here */
+ if (edma_channel < 0) {
+ __E("Error in requesting Master channel = 0x%x\n",
+ edma_channel);
+ retval = edma_channel;
+ break;
+ }
+
+ edma_stop(edma_channel);
+
+ init_completion(&edmacompletion);
+
+ edma_set_src(edma_channel,
+ (dma_addr_t) edmaparams.src,
+ edmaparams.srcmode, edmaparams.srcfifowidth);
+
+ edma_set_dest(edma_channel,
+ (dma_addr_t) edmaparams.dst,
+ edmaparams.dstmode, edmaparams.dstfifowidth);
+
+ edma_set_src_index(edma_channel, edmaparams.srcbidx,
+ edmaparams.srccidx);
+ edma_set_dest_index(edma_channel, edmaparams.dstbidx,
+ edmaparams.dstcidx);
+
+ edma_set_transfer_params(edma_channel,
+ edmaparams.acnt,
+ edmaparams.bcnt,
+ edmaparams.ccnt,
+ edmaparams.bcntrld, edmaparams.syncmode);
+
+ edma_read_slot(edma_channel, &p_ram);
+ p_ram.opt |= TCINTEN | EDMA_TCC(edma_channel);
+ edma_write_slot(edma_channel, &p_ram);
+
+ edma_start(edma_channel);
+ wait_for_completion(&edmacompletion);
+ edma_stop(edma_channel);
+ edma_free_channel(edma_channel);
+ break;
+
+ default:
+ __E("Unknown ioctl received = %d.\n", cmd);
+ retval = -EINVAL;
+ break;
}
- return 0;
+
+ return retval;
}
-static int open (struct inode *inode, struct file *filp)
+static int open(struct inode *inode, struct file *filp)
{
- __D ("open: called.\n");
- return 0;
+ __D("open: called.\n");
+ return 0;
}
-static int release (struct inode *inode, struct file *filp)
+static int release(struct inode *inode, struct file *filp)
{
- __D ("close: called.");
- return 0;
+ __D("close: called.");
+ return 0;
}
-int __init dm350mmap_init (void)
+int __init dm350mmap_init(void)
{
- __D ("** DM350MMAP kernel module built: " __DATE__ " " __TIME__ "\n");
- major = register_chrdev (0, "dm350mmap", &dm350mmap_fxns);
- if (major < 0)
- {
- __E ("Failed to allocate major number.\n");
- return -ENODEV;
+ /* In the GIT kernel unused clocks are disabled. To run codec we need to
+ * enable mjcp clock.
+ */
+ mjcp = clk_get(NULL, "mjcp");
+ if (IS_ERR(mjcp))
+ printk(KERN_WARNING "unable to get MJCP clock\n");
+ else
+ clk_enable(mjcp);
+
+ __D("** DM350MMAP kernel module built: " __DATE__ " " __TIME__ "\n");
+ major = register_chrdev(0, "dm350mmap", &dm350mmap_fxns);
+ if (major < 0) {
+ __E("Failed to allocate major number.\n");
+ return -ENODEV;
}
- __D ("Allocated major number: %d\n", major);
-
+ __D("Allocated major number: %d\n", major);
+
#if (USE_UDEV==1)
- dm350mmap_class = class_create (THIS_MODULE, "dm350mmap");
- if (IS_ERR (dm350mmap_class))
- {
- __E ("Error creating dm350mmap device class.\n");
- return -EIO;
+ dm350mmap_class = class_create(THIS_MODULE, "dm350mmap");
+ if (IS_ERR(dm350mmap_class)) {
+ __E("Error creating dm350mmap device class.\n");
+ return -EIO;
}
- class_device_create (dm350mmap_class, NULL, MKDEV (major, 0), NULL,
- "dm350mmap");
-
+ class_device_create(dm350mmap_class, NULL, MKDEV(major, 0), NULL,
+ "dm350mmap");
+
#endif // USE_UDEV
- __D ("Successfully initialized module\n");
-
+ __D("Successfully initialized module\n");
+
#ifdef ASQINT_ENABLE
- if (request_irq (IRQ_ASQINT, irq_handler, 0, "seq_arm_interrupt", NULL))
- {
- __D ("Could not install ISR\n");
+ if (request_irq(IRQ_ASQINT, irq_handler, 0, "seq_arm_interrupt", NULL)) {
+ __D("Could not install ISR\n");
}
-
+
#endif /* */
+ init_MUTEX_LOCKED(&dm350mmap_reply_mutex);
return 0;
}
-void __exit dm350mmap_exit (void)
+void __exit dm350mmap_exit(void)
{
- __D ("In dm350mmap_exit()\n");
-
+ /* if mjcp clock is enabled then free it */
+ if (mjcp) {
+ clk_disable(mjcp);
+ clk_put(mjcp);
+ }
+
+ __D("In dm350mmap_exit()\n");
+
#if (USE_UDEV==1)
- class_device_destroy (dm350mmap_class, MKDEV (major, 0));
- class_destroy (dm350mmap_class);
-
+ class_device_destroy(dm350mmap_class, MKDEV(major, 0));
+ class_destroy(dm350mmap_class);
+
#endif // USE_UDEV
- __D ("Unregistering character device dm350mmap\n");
- unregister_chrdev (major, "dm350mmap");
-
+ __D("Unregistering character device dm350mmap\n");
+ unregister_chrdev(major, "dm350mmap");
+
#ifdef ASQINT_ENABLE
- free_irq (IRQ_ASQINT, NULL);
-
+ free_irq(IRQ_ASQINT, NULL);
+
#endif /* */
- __D ("dm350mmap unregistered\n");
-}
+ __D("dm350mmap unregistered\n");
+}
-module_init (dm350mmap_init);
+module_init(dm350mmap_init);
-module_exit (dm350mmap_exit);
-MODULE_LICENSE ("GPL");
-MODULE_AUTHOR ("Texas Instruments");
-MODULE_DESCRIPTION ("DM350 mmap export to userland");
+module_exit(dm350mmap_exit);
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Texas Instruments");
+MODULE_DESCRIPTION("DM350 mmap export to userland");
|