summaryrefslogtreecommitdiff
path: root/drivers/mxc/dam/dam_v1.c
blob: b6c9a6f068e5db0dfd6ee84617c9dd00cc5a205f (plain)
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
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
/*
 * Copyright 2004-2010 Freescale Semiconductor, Inc. All Rights Reserved.
 */

/*
 * The code contained herein is licensed under the GNU General Public
 * License. You may obtain a copy of the GNU General Public License
 * Version 2 or later at the following locations:
 *
 * http://www.opensource.org/licenses/gpl-license.html
 * http://www.gnu.org/copyleft/gpl.html
 */

/*!
 * @file dam_v1.c
 * @brief This is the brief documentation for this dam_v1.c file.
 *
 * This file contains the implementation of the DAM driver main services
 *
 * @ingroup DAM
 */

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/device.h>
#include <linux/slab.h>
#include <linux/fs.h>
#include <linux/io.h>
#include <asm/uaccess.h>
#include "dam.h"

/*!
 * This include to define bool type, false and true definitions.
 */
#include <mach/hardware.h>

#define DAM_VIRT_BASE_ADDR	IO_ADDRESS(AUDMUX_BASE_ADDR)

#define ModifyRegister32(a, b, c)	do {\
	__raw_writel(((__raw_readl(c)) & (~(a))) | (b), (c));\
} while (0)

#ifndef _reg_DAM_HPCR1
#define    _reg_DAM_HPCR1   (*((volatile unsigned long *) \
		(DAM_VIRT_BASE_ADDR + 0x00)))
#endif

#ifndef _reg_DAM_HPCR2
#define    _reg_DAM_HPCR2   (*((volatile unsigned long *) \
		(DAM_VIRT_BASE_ADDR + 0x04)))
#endif

#ifndef _reg_DAM_HPCR3
#define    _reg_DAM_HPCR3   (*((volatile unsigned long *) \
		(DAM_VIRT_BASE_ADDR + 0x08)))
#endif

#ifndef _reg_DAM_PPCR1
#define    _reg_DAM_PPCR1   (*((volatile unsigned long *) \
		(DAM_VIRT_BASE_ADDR + 0x10)))
#endif

#ifndef _reg_DAM_PPCR2
#define    _reg_DAM_PPCR2  (*((volatile unsigned long *) \
		(DAM_VIRT_BASE_ADDR + 0x14)))
#endif

#ifndef _reg_DAM_PPCR3
#define    _reg_DAM_PPCR3   (*((volatile unsigned long *) \
		(DAM_VIRT_BASE_ADDR + 0x1c)))
#endif

#ifndef _reg_DAM_HPCR
#define    _reg_DAM_HPCR(a)   ((volatile unsigned long *) \
		(DAM_VIRT_BASE_ADDR + (a)*4))
#endif

#ifndef _reg_DAM_PPCR
#define    _reg_DAM_PPCR(a)   ((volatile unsigned long *) \
		(DAM_VIRT_BASE_ADDR + 0x0c + (0x04 << (a-3))))
#endif

/*!
 * HPCR/PPCR Registers bit shift definitions
 */
#define dam_transmit_frame_sync_direction_shift  31
#define dam_transmit_clock_direction_shift       30
#define dam_transmit_frame_sync_select_shift     26
#define dam_transmit_clock_select_shift          26
#define dam_receive_frame_sync_direction_shift   25
#define dam_receive_clock_direction_shift        24
#define dam_receive_clock_select_shift           20
#define dam_receive_frame_sync_select_shift      20

#define dam_receive_data_select_shift            13
#define dam_synchronous_mode_shift               12

#define dam_transmit_receive_switch_shift        10

#define dam_mode_shift                            8
#define dam_internal_network_mode_shift           0

/*!
 * HPCR/PPCR Register bit masq definitions
 */
/*#define dam_selection_mask              0xF*/
#define dam_fs_selection_mask             0xF
#define dam_clk_selection_mask            0xF
#define dam_dat_selection_mask		        0x7
/*#define dam_mode_masq                   0x03*/
#define dam_internal_network_mode_mask    0xFF

/*!
 * HPCR/PPCR Register reset value definitions
 */
#define dam_hpcr_default_value 0x00001000
#define dam_ppcr_default_value 0x00001000

#define DAM_NAME   "dam"
static struct class *mxc_dam_class;

EXPORT_SYMBOL(dam_select_mode);
EXPORT_SYMBOL(dam_select_RxClk_direction);
EXPORT_SYMBOL(dam_select_RxClk_source);
EXPORT_SYMBOL(dam_select_RxD_source);
EXPORT_SYMBOL(dam_select_RxFS_direction);
EXPORT_SYMBOL(dam_select_RxFS_source);
EXPORT_SYMBOL(dam_select_TxClk_direction);
EXPORT_SYMBOL(dam_select_TxClk_source);
EXPORT_SYMBOL(dam_select_TxFS_direction);
EXPORT_SYMBOL(dam_select_TxFS_source);
EXPORT_SYMBOL(dam_set_internal_network_mode_mask);
EXPORT_SYMBOL(dam_set_synchronous);
EXPORT_SYMBOL(dam_switch_Tx_Rx);
EXPORT_SYMBOL(dam_reset_register);

/*!
 * DAM major
 */
#ifdef TEST_DAM
static int major_dam;

typedef struct _mxc_cfg {
	int reg;
	int val;
} mxc_cfg;

#endif

/*!
 * This function selects the operation mode of the port.
 *
 * @param        port              the DAM port to configure
 * @param        the_mode          the operation mode of the port
 *
 * @return       This function returns the result of the operation
 *               (0 if successful, -1 otherwise).
 */
int dam_select_mode(dam_port port, dam_mode the_mode)
{
	int result;
	result = 0;

	if (port >= 3)
		the_mode = normal_mode;
	ModifyRegister32(1 << dam_mode_shift,
			 the_mode << dam_mode_shift, _reg_DAM_HPCR(port));

	return result;
}

/*!
 * This function controls Receive clock signal direction for the port.
 *
 * @param        port              the DAM port to configure
 * @param        direction         the Rx clock signal direction
 */
void dam_select_RxClk_direction(dam_port port, signal_direction direction)
{
	if (port < 3) {
		ModifyRegister32(1 << dam_receive_clock_direction_shift,
				 direction << dam_receive_clock_direction_shift,
				 _reg_DAM_HPCR(port));
	} else {
		ModifyRegister32(1 << dam_receive_clock_direction_shift,
				 direction << dam_receive_clock_direction_shift,
				 _reg_DAM_PPCR(port));
	}
	return;
}

/*!
 * This function controls Receive clock signal source for the port.
 *
 * @param        p_config          the DAM port to configure
 * @param        from_RxClk        the signal comes from RxClk or TxClk of
 *                                 the source port
 * @param        p_source          the source port
 */
void dam_select_RxClk_source(dam_port p_config,
			     bool from_RxClk, dam_port p_source)
{
	if (p_config < 3) {
		ModifyRegister32(dam_clk_selection_mask <<
				 dam_receive_clock_select_shift,
				 ((from_RxClk << 3) | p_source) <<
				 dam_receive_clock_select_shift,
				 _reg_DAM_HPCR(p_config));
	} else {
		ModifyRegister32(dam_clk_selection_mask <<
				 dam_receive_clock_select_shift,
				 ((from_RxClk << 3) | p_source) <<
				 dam_receive_clock_select_shift,
				 _reg_DAM_PPCR(p_config));
	}
	return;
}

/*!
 * This function selects the source port for the RxD data.
 *
 * @param        p_config          the DAM port to configure
 * @param        p_source          the source port
 */
void dam_select_RxD_source(dam_port p_config, dam_port p_source)
{
	if (p_config < 3) {
		ModifyRegister32(dam_dat_selection_mask <<
				 dam_receive_data_select_shift,
				 p_source << dam_receive_data_select_shift,
				 _reg_DAM_HPCR(p_config));
	} else {
		ModifyRegister32(dam_dat_selection_mask <<
				 dam_receive_data_select_shift,
				 p_source << dam_receive_data_select_shift,
				 _reg_DAM_PPCR(p_config));
	}
	return;
}

/*!
 * This function controls Receive Frame Sync signal direction for the port.
 *
 * @param        port              the DAM port to configure
 * @param        direction         the Rx Frame Sync signal direction
 */
void dam_select_RxFS_direction(dam_port port, signal_direction direction)
{
	if (port < 3) {
		ModifyRegister32(1 << dam_receive_frame_sync_direction_shift,
				 direction <<
				 dam_receive_frame_sync_direction_shift,
				 _reg_DAM_HPCR(port));
	} else {
		ModifyRegister32(1 << dam_receive_frame_sync_direction_shift,
				 direction <<
				 dam_receive_frame_sync_direction_shift,
				 _reg_DAM_PPCR(port));
	}
	return;
}

/*!
 * This function controls Receive Frame Sync signal source for the port.
 *
 * @param        p_config          the DAM port to configure
 * @param        from_RxFS         the signal comes from RxFS or TxFS of
 *                                 the source port
 * @param        p_source          the source port
 */
void dam_select_RxFS_source(dam_port p_config,
			    bool from_RxFS, dam_port p_source)
{
	if (p_config < 3) {
		ModifyRegister32(dam_fs_selection_mask <<
				 dam_receive_frame_sync_select_shift,
				 ((from_RxFS << 3) | p_source) <<
				 dam_receive_frame_sync_select_shift,
				 _reg_DAM_HPCR(p_config));
	} else {
		ModifyRegister32(dam_fs_selection_mask <<
				 dam_receive_frame_sync_select_shift,
				 ((from_RxFS << 3) | p_source) <<
				 dam_receive_frame_sync_select_shift,
				 _reg_DAM_PPCR(p_config));
	}
	return;
}

/*!
 * This function controls Transmit clock signal direction for the port.
 *
 * @param        port              the DAM port to configure
 * @param        direction         the Tx clock signal direction
 */
void dam_select_TxClk_direction(dam_port port, signal_direction direction)
{
	if (port < 3) {
		ModifyRegister32(1 << dam_transmit_clock_direction_shift,
				 direction <<
				 dam_transmit_clock_direction_shift,
				 _reg_DAM_HPCR(port));
	} else {
		ModifyRegister32(1 << dam_transmit_clock_direction_shift,
				 direction <<
				 dam_transmit_clock_direction_shift,
				 _reg_DAM_PPCR(port));
	}
	return;
}

/*!
 * This function controls Transmit clock signal source for the port.
 *
 * @param        p_config          the DAM port to configure
 * @param        from_RxClk        the signal comes from RxClk or TxClk of
 *                                 the source port
 * @param        p_source          the source port
 */
void dam_select_TxClk_source(dam_port p_config,
			     bool from_RxClk, dam_port p_source)
{
	if (p_config < 3) {
		ModifyRegister32(dam_clk_selection_mask <<
				 dam_transmit_clock_select_shift,
				 ((from_RxClk << 3) | p_source) <<
				 dam_transmit_clock_select_shift,
				 _reg_DAM_HPCR(p_config));
	} else {
		ModifyRegister32(dam_clk_selection_mask <<
				 dam_transmit_clock_select_shift,
				 ((from_RxClk << 3) | p_source) <<
				 dam_transmit_clock_select_shift,
				 _reg_DAM_PPCR(p_config));
	}
	return;
}

/*!
 * This function controls Transmit Frame Sync signal direction for the port.
 *
 * @param        port              the DAM port to configure
 * @param        direction         the Tx Frame Sync signal direction
 */
void dam_select_TxFS_direction(dam_port port, signal_direction direction)
{
	if (port < 3) {
		ModifyRegister32(1 << dam_transmit_frame_sync_direction_shift,
				 direction <<
				 dam_transmit_frame_sync_direction_shift,
				 _reg_DAM_HPCR(port));
	} else {
		ModifyRegister32(1 << dam_transmit_frame_sync_direction_shift,
				 direction <<
				 dam_transmit_frame_sync_direction_shift,
				 _reg_DAM_HPCR(port));
	}
	return;
}

/*!
 * This function controls Transmit Frame Sync signal source for the port.
 *
 * @param        p_config          the DAM port to configure
 * @param        from_RxFS         the signal comes from RxFS or TxFS of
 *                                 the source port
 * @param        p_source          the source port
 */
void dam_select_TxFS_source(dam_port p_config,
			    bool from_RxFS, dam_port p_source)
{
	if (p_config < 3) {
		ModifyRegister32(dam_fs_selection_mask <<
				 dam_transmit_frame_sync_select_shift,
				 ((from_RxFS << 3) | p_source) <<
				 dam_transmit_frame_sync_select_shift,
				 _reg_DAM_HPCR(p_config));
	} else {
		ModifyRegister32(dam_fs_selection_mask <<
				 dam_transmit_frame_sync_select_shift,
				 ((from_RxFS << 3) | p_source) <<
				 dam_transmit_frame_sync_select_shift,
				 _reg_DAM_PPCR(p_config));
	}
	return;
}

/*!
 * This function sets a bit mask that selects the port from which of the RxD
 * signals are to be ANDed together for internal network mode.
 * Bit 6 represents RxD from Port7 and bit0 represents RxD from Port1.
 * 1 excludes RxDn from ANDing. 0 includes RxDn for ANDing.
 *
 * @param        port              the DAM port to configure
 * @param        bit_mask          the bit mask
 *
 * @return       This function returns the result of the operation
 *               (0 if successful, -1 otherwise).
 */
int dam_set_internal_network_mode_mask(dam_port port, unsigned char bit_mask)
{
	int result;
	result = 0;

	ModifyRegister32(dam_internal_network_mode_mask <<
			 dam_internal_network_mode_shift,
			 bit_mask << dam_internal_network_mode_shift,
			 _reg_DAM_HPCR(port));
	return result;
}

/*!
 * This function controls whether or not the port is in synchronous mode.
 * When the synchronous mode is selected, the receive and the transmit sections
 * use common clock and frame sync signals.
 * When the synchronous mode is not selected, separate clock and frame sync
 * signals are used for the transmit and the receive sections.
 * The defaut value is the synchronous mode selected.
 *
 * @param        port              the DAM port to configure
 * @param        synchronous       the state to assign
 */
void dam_set_synchronous(dam_port port, bool synchronous)
{
	if (port < 3) {
		ModifyRegister32(1 << dam_synchronous_mode_shift,
				 synchronous << dam_synchronous_mode_shift,
				 _reg_DAM_HPCR(port));
	} else {
		ModifyRegister32(1 << dam_synchronous_mode_shift,
				 synchronous << dam_synchronous_mode_shift,
				 _reg_DAM_PPCR(port));
	}
	return;
}

/*!
 * This function swaps the transmit and receive signals from (Da-TxD, Db-RxD)
 * to (Da-RxD, Db-TxD).
 * This default signal configuration is Da-TxD, Db-RxD.
 *
 * @param        port              the DAM port to configure
 * @param        value             the switch state
 */
void dam_switch_Tx_Rx(dam_port port, bool value)
{
	if (port < 3) {
		ModifyRegister32(1 << dam_transmit_receive_switch_shift,
				 value << dam_transmit_receive_switch_shift,
				 _reg_DAM_HPCR(port));
	} else {
		ModifyRegister32(1 << dam_transmit_receive_switch_shift,
				 value << dam_transmit_receive_switch_shift,
				 _reg_DAM_PPCR(port));
	}
	return;
}

/*!
 * This function resets the two registers of the selected port.
 *
 * @param        port              the DAM port to reset
 */
void dam_reset_register(dam_port port)
{
	if (port < 3) {
		ModifyRegister32(0xFFFFFFFF, dam_hpcr_default_value,
				 _reg_DAM_HPCR(port));
	} else {
		ModifyRegister32(0xFFFFFFFF, dam_ppcr_default_value,
				 _reg_DAM_PPCR(port));
	}
	return;
}

#ifdef TEST_DAM

/*!
 * This function implements IOCTL controls on a DAM device.
 *
 * @param        inode       pointer on the node
 * @param        file        pointer on the file
 * @param        cmd         the command
 * @param        arg         the parameter :\n
 * DAM_CONFIG_SSI1:\n
 * data from port 1 to port 4, clock and FS from port 1 (SSI1)\n
 * DAM_CONFIG_SSI2:\n
 * data from port 2 to port 5, clock and FS from port 2 (SSI2)\n
 * DAM_CONFIG_SSI_NETWORK_MODE:\n
 * network mode for mix digital with data from port 1 to port4,\n
 * data from port 2 to port 4, clock and FS from port 1 (SSI1)
 *
 * @return       This function returns 0 if successful.
 */
static int dam_ioctl(struct inode *inode,
		     struct file *file, unsigned int cmd, unsigned long arg)
{
	return 0;
}

/*!
 * This function implements the open method on a DAM device.
 *
 * @param        inode       pointer on the node
 * @param        file        pointer on the file
 *
 * @return       This function returns 0.
 */
static int dam_open(struct inode *inode, struct file *file)
{
	/* DBG_PRINTK("ssi : dam_open()\n"); */
	return 0;
}

/*!
 * This function implements the release method on a DAM device.
 *
 * @param        inode       pointer on the node
 * @param        file        pointer on the file
 *
 * @return       This function returns 0.
 */
static int dam_free(struct inode *inode, struct file *file)
{
	/* DBG_PRINTK("ssi : dam_free()\n"); */
	return 0;
}

/*!
 * This structure defines file operations for a DAM device.
 */
static struct file_operations dam_fops = {

	/*!
	 * the owner
	 */
	.owner = THIS_MODULE,

	/*!
	 * the ioctl operation
	 */
	.ioctl = dam_ioctl,

	/*!
	 * the open operation
	 */
	.open = dam_open,

	/*!
	 * the release operation
	 */
	.release = dam_free,
};

#endif

/*!
 * This function implements the init function of the DAM device.
 * This function is called when the module is loaded.
 *
 * @return       This function returns 0.
 */
static int __init dam_init(void)
{
#ifdef TEST_DAM
	struct device *temp_class;
	printk(KERN_DEBUG "dam : dam_init(void) \n");

	major_dam = register_chrdev(0, DAM_NAME, &dam_fops);
	if (major_dam < 0) {
		printk(KERN_WARNING "Unable to get a major for dam");
		return major_dam;
	}

	mxc_dam_class = class_create(THIS_MODULE, DAM_NAME);
	if (IS_ERR(mxc_dam_class)) {
		goto err_out;
	}

	temp_class = device_create(mxc_dam_class, NULL,
				   MKDEV(major_dam, 0), NULL, DAM_NAME);
	if (IS_ERR(temp_class)) {
		goto err_out;
	}
#endif
	return 0;

      err_out:
	printk(KERN_ERR "Error creating dam class device.\n");
	device_destroy(mxc_dam_class, MKDEV(major_dam, 0));
	class_destroy(mxc_dam_class);
	unregister_chrdev(major_dam, DAM_NAME);
	return -1;
}

/*!
 * This function implements the exit function of the SPI device.
 * This function is called when the module is unloaded.
 *
 */
static void __exit dam_exit(void)
{
#ifdef TEST_DAM
	device_destroy(mxc_dam_class, MKDEV(major_dam, 0));
	class_destroy(mxc_dam_class);
	unregister_chrdev(major_dam, DAM_NAME);
	printk(KERN_DEBUG "dam : successfully unloaded\n");
#endif
}

module_init(dam_init);
module_exit(dam_exit);

MODULE_DESCRIPTION("DAM char device driver");
MODULE_AUTHOR("Freescale Semiconductor, Inc.");
MODULE_LICENSE("GPL");