Linus Nielsen Feltzing | 331c7d9 | 2003-05-03 02:40:09 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2002 by Linus Nielsen Feltzing |
| 11 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame^] | 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. |
Linus Nielsen Feltzing | 331c7d9 | 2003-05-03 02:40:09 +0000 | [diff] [blame] | 16 | * |
| 17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 18 | * KIND, either express or implied. |
| 19 | * |
| 20 | ****************************************************************************/ |
| 21 | #include "lcd.h" |
| 22 | #include "sh7034.h" |
| 23 | #include "kernel.h" |
| 24 | #include "thread.h" |
| 25 | #include "debug.h" |
Jörg Hohensohn | 75bab49 | 2003-11-06 01:34:50 +0000 | [diff] [blame] | 26 | #include "system.h" |
Bertrik Sikken | a5d3029 | 2008-04-28 10:22:05 +0000 | [diff] [blame] | 27 | #include "fmradio.h" |
Linus Nielsen Feltzing | 331c7d9 | 2003-05-03 02:40:09 +0000 | [diff] [blame] | 28 | |
Jens Arnold | c652218 | 2007-02-18 08:46:12 +0000 | [diff] [blame] | 29 | #if CONFIG_TUNER |
Linus Nielsen Feltzing | 331c7d9 | 2003-05-03 02:40:09 +0000 | [diff] [blame] | 30 | |
| 31 | /* Signals: |
| 32 | DI (Data In) - PB0 (doubles as data pin for the LCD) |
| 33 | CL (Clock) - PB1 (doubles as clock for the LCD) |
| 34 | CE (Chip Enable) - PB3 (also chip select for the LCD, but active low) |
| 35 | DO (Data Out) - PB4 |
| 36 | */ |
| 37 | |
Linus Nielsen Feltzing | 331c7d9 | 2003-05-03 02:40:09 +0000 | [diff] [blame] | 38 | /* cute little functions */ |
Linus Nielsen Feltzing | bef7ab0 | 2003-11-07 12:15:24 +0000 | [diff] [blame] | 39 | #define CE_LO and_b(~0x08, PBDRL_ADDR) |
| 40 | #define CE_HI or_b(0x08, PBDRL_ADDR) |
| 41 | #define CL_LO and_b(~0x02, PBDRL_ADDR) |
| 42 | #define CL_HI or_b(0x02, PBDRL_ADDR) |
| 43 | #define DO (PBDR & 0x10) |
| 44 | #define DI_LO and_b(~0x01, PBDRL_ADDR) |
| 45 | #define DI_HI or_b(0x01, PBDRL_ADDR) |
Linus Nielsen Feltzing | 331c7d9 | 2003-05-03 02:40:09 +0000 | [diff] [blame] | 46 | |
Linus Nielsen Feltzing | bef7ab0 | 2003-11-07 12:15:24 +0000 | [diff] [blame] | 47 | #define START or_b((0x08 | 0x02), PBDRL_ADDR) |
Linus Nielsen Feltzing | 331c7d9 | 2003-05-03 02:40:09 +0000 | [diff] [blame] | 48 | |
| 49 | /* delay loop */ |
| 50 | #define DELAY do { int _x; for(_x=0;_x<10;_x++);} while (0) |
| 51 | |
Linus Nielsen Feltzing | 331c7d9 | 2003-05-03 02:40:09 +0000 | [diff] [blame] | 52 | |
| 53 | int fmradio_read(int addr) |
| 54 | { |
| 55 | int i; |
| 56 | int data = 0; |
| 57 | |
| 58 | START; |
| 59 | |
| 60 | /* First address bit */ |
| 61 | CL_LO; |
| 62 | if(addr & 2) |
| 63 | DI_HI; |
| 64 | else |
| 65 | DI_LO; |
| 66 | DELAY; |
| 67 | CL_HI; |
| 68 | DELAY; |
| 69 | |
| 70 | /* Second address bit */ |
| 71 | CL_LO; |
| 72 | if(addr & 1) |
| 73 | DI_HI; |
| 74 | else |
| 75 | DI_LO; |
| 76 | DELAY; |
| 77 | CL_HI; |
| 78 | DELAY; |
| 79 | |
| 80 | for(i = 0; i < 21;i++) |
| 81 | { |
| 82 | CL_LO; |
| 83 | DELAY; |
| 84 | data <<= 1; |
| 85 | data |= (DO)?1:0; |
| 86 | CL_HI; |
| 87 | DELAY; |
| 88 | } |
| 89 | |
| 90 | CE_LO; |
| 91 | |
| 92 | return data; |
| 93 | } |
| 94 | |
| 95 | void fmradio_set(int addr, int data) |
| 96 | { |
| 97 | int i; |
| 98 | |
| 99 | /* Include the address in the data */ |
| 100 | data |= addr << 21; |
| 101 | |
| 102 | START; |
| 103 | |
| 104 | for(i = 0; i < 23;i++) |
| 105 | { |
| 106 | CL_LO; |
| 107 | DELAY; |
| 108 | if(data & (1 << 22)) |
| 109 | DI_HI; |
| 110 | else |
| 111 | DI_LO; |
| 112 | |
| 113 | data <<= 1; |
| 114 | CL_HI; |
| 115 | DELAY; |
| 116 | } |
| 117 | |
| 118 | CE_LO; |
| 119 | } |
| 120 | |
Linus Nielsen Feltzing | 331c7d9 | 2003-05-03 02:40:09 +0000 | [diff] [blame] | 121 | #endif |