1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2009 by Bertrik Sikken
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
25 #include "dbop-as3525.h"
27 #if defined(SANSA_FUZE) || defined(SANSA_FUZEV2)
28 #define DBOP_PRECHARGE 0x80FF
29 #elif defined(SANSA_E200V2) || defined(SANSA_C200V2)
30 #define DBOP_PRECHARGE 0xF0FF
33 #if CONFIG_CPU == AS3525
34 /* doesn't work with the new ams sansas so far and is not needed */
35 static short int dbop_input_value
= 0;
37 /* read the DBOP data pins */
38 unsigned short dbop_read_input(void)
40 unsigned int dbop_ctrl_old
= DBOP_CTRL
;
41 unsigned int dbop_timpol23_old
= DBOP_TIMPOL_23
;
43 /* make sure that the DBOP FIFO is empty */
44 while ((DBOP_STAT
& (1<<10)) == 0);
47 while (delay
--) asm volatile ("nop\n");
49 /* write DBOP_DOUT to pre-charge DBOP data lines with a defined level */
50 DBOP_TIMPOL_23
= 0xe007e007; /* no strobe towards lcd */
51 DBOP_CTRL
= (1 << 19) | /* tri-state output */
52 (1 << 16) | /* enw=1 (enable write) */
53 (1 << 12); /* ow=1 (16-bit data width) */
54 DBOP_DOUT
= DBOP_PRECHARGE
;
55 #if defined(SANSA_C200V2)
56 /* two additional writes to precharge longer get rid of the read noise */
57 DBOP_DOUT
= DBOP_PRECHARGE
;
58 DBOP_DOUT
= DBOP_PRECHARGE
;
60 while ((DBOP_STAT
& (1<<10)) == 0);
62 #if defined(SANSA_FUZE) || defined(SANSA_E200V2)
64 while (delay
--) asm volatile ("nop\n");
67 /* perform a DBOP read */
68 DBOP_CTRL
= (1 << 19) | /* tri-state output */
69 (1 << 15) | /* strd=1 (start read) */
70 (1 << 12) | /* ow=1 (16-bit data width) */
71 (31 << 0); /* rs_t=31 (read DBOP at end of cycle) */
72 while ((DBOP_STAT
& (1<<16)) == 0);
73 dbop_input_value
= DBOP_DIN
;
75 /* restore previous values */
76 DBOP_TIMPOL_23
= dbop_timpol23_old
;
77 DBOP_CTRL
= dbop_ctrl_old
;
79 return dbop_input_value
;
82 /* for the debug menu */
83 unsigned short dbop_debug(void)
85 return dbop_input_value
;
90 static inline void dbop_set_mode(int mode
)
93 unsigned long ctrl
= DBOP_CTRL
;
94 int curr_mode
= (DBOP_CTRL
>> 13) & 0x3; // bits 14:13
96 if (mode
== 32 && curr_mode
!= 1<<1)
97 DBOP_CTRL
= (ctrl
& ~(1<<13)) | (1<<14); // 2 serial half words
98 else if (mode
== 16 && curr_mode
!= 1<<0)
99 DBOP_CTRL
= (ctrl
& ~(1<<14)) | (1<<13); // 2 serial bytes
101 if (mode
== 32 && curr_mode
== 0)
102 DBOP_CTRL
= ctrl
| (1<<13|1<<14); /* 2 serial half words */
103 else if (mode
== 16 && curr_mode
== (1<<1|1<<0))
104 DBOP_CTRL
= ctrl
& ~(1<<14|1<<13); /* 1 serial half word */
108 while(delay
--) asm volatile("nop");
111 void dbop_write_data(const int16_t* p_bytes
, int count
)
115 if ((intptr_t)p_bytes
& 0x3 || count
== 1)
116 { /* need to do a single 16bit write beforehand if the address is
117 * not word aligned or count is 1, switch to 16bit mode if needed */
119 DBOP_DOUT16
= *p_bytes
++;
123 /* from here, 32bit transfers are save
124 * set it to transfer 4*(outputwidth) units at a time,
125 * if bit 12 is set it only does 2 halfwords though (we never set it)
126 * switch to 32bit output if needed */
128 data
= (int32_t*)p_bytes
;
131 DBOP_DOUT32
= *data
++;
134 /* Wait if push fifo is full */
135 while ((DBOP_STAT
& (1<<6)) != 0);
137 /* While push fifo is not empty */
138 while ((DBOP_STAT
& (1<<10)) == 0);
140 /* due to the 32bit alignment requirement or uneven count,
141 * we possibly need to do a 16bit transfer at the end also */
143 dbop_write_data((int16_t*)data
, 1);