87bc46e145be44e68cda7a51e530731d239986a1
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 #if defined(SANSA_C200V2)
39 * workaround DBOP noise issue cause it's really annoying if your
40 * buttons don't work in the debug menu...
42 static short int input_value_tmp
[2];
43 int dbop_denoise_reject
= 0;
44 int dbop_denoise_accept
= 0;
47 /* read the DBOP data pins */
48 #if defined(SANSA_C200V2)
49 unsigned short dbop_read_input_once(void);
51 unsigned short dbop_read_input(void)
57 input_value_tmp
[i
] = dbop_read_input_once();
60 if (input_value_tmp
[0] == input_value_tmp
[1]) {
61 dbop_denoise_accept
++;
64 dbop_denoise_reject
++;
67 if (dbop_denoise_accept
+ dbop_denoise_reject
> 1000) {
68 dbop_denoise_accept
/= 2;
69 dbop_denoise_reject
/= 2;
72 return dbop_input_value
;
75 unsigned short dbop_read_input_once(void)
77 unsigned short dbop_read_input(void)
80 unsigned int dbop_ctrl_old
= DBOP_CTRL
;
81 unsigned int dbop_timpol23_old
= DBOP_TIMPOL_23
;
83 /* make sure that the DBOP FIFO is empty */
84 while ((DBOP_STAT
& (1<<10)) == 0);
87 while (delay
--) asm volatile ("nop\n");
89 /* write DBOP_DOUT to pre-charge DBOP data lines with a defined level */
90 DBOP_TIMPOL_23
= 0xe007e007; /* no strobe towards lcd */
91 DBOP_CTRL
= (1 << 19) | /* tri-state output */
92 (1 << 16) | /* enw=1 (enable write) */
93 (1 << 12); /* ow=1 (16-bit data width) */
94 DBOP_DOUT
= DBOP_PRECHARGE
;
95 while ((DBOP_STAT
& (1<<10)) == 0);
97 #if defined(SANSA_FUZE) || defined(SANSA_E200V2)
99 while (delay
--) asm volatile ("nop\n");
102 /* perform a DBOP read */
103 DBOP_CTRL
= (1 << 19) | /* tri-state output */
104 (1 << 15) | /* strd=1 (start read) */
105 (1 << 12) | /* ow=1 (16-bit data width) */
106 (31 << 0); /* rs_t=31 (read DBOP at end of cycle) */
107 while ((DBOP_STAT
& (1<<16)) == 0);
108 dbop_input_value
= DBOP_DIN
;
110 /* restore previous values */
111 DBOP_TIMPOL_23
= dbop_timpol23_old
;
112 DBOP_CTRL
= dbop_ctrl_old
;
114 return dbop_input_value
;
117 /* for the debug menu */
118 unsigned short dbop_debug(void)
120 return dbop_input_value
;
125 static inline void dbop_set_mode(int mode
)
128 unsigned long ctrl
= DBOP_CTRL
;
129 int curr_mode
= (DBOP_CTRL
>> 13) & 0x3; // bits 14:13
131 if (mode
== 32 && curr_mode
!= 1<<1)
132 DBOP_CTRL
= (ctrl
& ~(1<<13)) | (1<<14); // 2 serial half words
133 else if (mode
== 16 && curr_mode
!= 1<<0)
134 DBOP_CTRL
= (ctrl
& ~(1<<14)) | (1<<13); // 2 serial bytes
136 if (mode
== 32 && curr_mode
== 0)
137 DBOP_CTRL
= ctrl
| (1<<13|1<<14); /* 2 serial half words */
138 else if (mode
== 16 && curr_mode
== (1<<1|1<<0))
139 DBOP_CTRL
= ctrl
& ~(1<<14|1<<13); /* 1 serial half word */
143 while(delay
--) asm volatile("nop");
146 void dbop_write_data(const int16_t* p_bytes
, int count
)
150 if ((intptr_t)p_bytes
& 0x3 || count
== 1)
151 { /* need to do a single 16bit write beforehand if the address is
152 * not word aligned or count is 1, switch to 16bit mode if needed */
154 DBOP_DOUT16
= *p_bytes
++;
158 /* from here, 32bit transfers are save
159 * set it to transfer 4*(outputwidth) units at a time,
160 * if bit 12 is set it only does 2 halfwords though (we never set it)
161 * switch to 32bit output if needed */
163 data
= (int32_t*)p_bytes
;
166 DBOP_DOUT32
= *data
++;
169 /* Wait if push fifo is full */
170 while ((DBOP_STAT
& (1<<6)) != 0);
172 /* While push fifo is not empty */
173 while ((DBOP_STAT
& (1<<10)) == 0);
175 /* due to the 32bit alignment requirement or uneven count,
176 * we possibly need to do a 16bit transfer at the end also */
178 dbop_write_data((int16_t*)data
, 1);