Get a good start on cleaning up powermgmt.c
[kugel-rb.git] / firmware / drivers / fmradio.c
blobf231d47b89dcab458fa245b0a46ad540cb4bca08
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 by Linus Nielsen Feltzing
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
19 #include "lcd.h"
20 #include "sh7034.h"
21 #include "kernel.h"
22 #include "thread.h"
23 #include "debug.h"
24 #include "system.h"
25 #include "fmradio.h"
27 #if CONFIG_TUNER
29 /* Signals:
30 DI (Data In) - PB0 (doubles as data pin for the LCD)
31 CL (Clock) - PB1 (doubles as clock for the LCD)
32 CE (Chip Enable) - PB3 (also chip select for the LCD, but active low)
33 DO (Data Out) - PB4
36 /* cute little functions */
37 #define CE_LO and_b(~0x08, PBDRL_ADDR)
38 #define CE_HI or_b(0x08, PBDRL_ADDR)
39 #define CL_LO and_b(~0x02, PBDRL_ADDR)
40 #define CL_HI or_b(0x02, PBDRL_ADDR)
41 #define DO (PBDR & 0x10)
42 #define DI_LO and_b(~0x01, PBDRL_ADDR)
43 #define DI_HI or_b(0x01, PBDRL_ADDR)
45 #define START or_b((0x08 | 0x02), PBDRL_ADDR)
47 /* delay loop */
48 #define DELAY do { int _x; for(_x=0;_x<10;_x++);} while (0)
51 int fmradio_read(int addr)
53 int i;
54 int data = 0;
56 START;
58 /* First address bit */
59 CL_LO;
60 if(addr & 2)
61 DI_HI;
62 else
63 DI_LO;
64 DELAY;
65 CL_HI;
66 DELAY;
68 /* Second address bit */
69 CL_LO;
70 if(addr & 1)
71 DI_HI;
72 else
73 DI_LO;
74 DELAY;
75 CL_HI;
76 DELAY;
78 for(i = 0; i < 21;i++)
80 CL_LO;
81 DELAY;
82 data <<= 1;
83 data |= (DO)?1:0;
84 CL_HI;
85 DELAY;
88 CE_LO;
90 return data;
93 void fmradio_set(int addr, int data)
95 int i;
97 /* Include the address in the data */
98 data |= addr << 21;
100 START;
102 for(i = 0; i < 23;i++)
104 CL_LO;
105 DELAY;
106 if(data & (1 << 22))
107 DI_HI;
108 else
109 DI_LO;
111 data <<= 1;
112 CL_HI;
113 DELAY;
116 CE_LO;
119 #endif