diff options
Diffstat (limited to 'firmware/target/arm/samsung/fmradio-yh92x.c')
-rw-r--r-- | firmware/target/arm/samsung/fmradio-yh92x.c | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/firmware/target/arm/samsung/fmradio-yh92x.c b/firmware/target/arm/samsung/fmradio-yh92x.c new file mode 100644 index 0000000000..4637aca287 --- /dev/null +++ b/firmware/target/arm/samsung/fmradio-yh92x.c | |||
@@ -0,0 +1,120 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * Physical interface of the Philips TEA5767 in Samsung YH-92x | ||
10 | * | ||
11 | * Copyright (C) 2014 by Szymon Dziok | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or | ||
14 | * modify it under the terms of the GNU General Public License | ||
15 | * as published by the Free Software Foundation; either version 2 | ||
16 | * of the License, or (at your option) any later version. | ||
17 | * | ||
18 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
19 | * KIND, either express or implied. | ||
20 | * | ||
21 | ****************************************************************************/ | ||
22 | #include "config.h" | ||
23 | #include "system.h" | ||
24 | #include "cpu.h" | ||
25 | #include "fmradio_3wire.h" | ||
26 | |||
27 | #define CLOCK_EN GPIO_SET_BITWISE(GPIOL_ENABLE, 0x10) | ||
28 | #define CLOCK_OUT GPIO_SET_BITWISE(GPIOL_OUTPUT_EN, 0x10) | ||
29 | #define CLOCK_LO GPIO_CLEAR_BITWISE(GPIOL_OUTPUT_VAL, 0x10) | ||
30 | #define CLOCK_HI GPIO_SET_BITWISE(GPIOL_OUTPUT_VAL, 0x10) | ||
31 | |||
32 | #define DATA (GPIOL_INPUT_VAL & 0x08) | ||
33 | #define DATA_EN GPIO_SET_BITWISE(GPIOL_ENABLE, 0x08) | ||
34 | #define DATA_IN GPIO_CLEAR_BITWISE(GPIOL_OUTPUT_EN, 0x08) | ||
35 | #define DATA_OUT GPIO_SET_BITWISE(GPIOL_OUTPUT_EN, 0x08) | ||
36 | #define DATA_LO GPIO_CLEAR_BITWISE(GPIOL_OUTPUT_VAL, 0x08) | ||
37 | #define DATA_HI GPIO_SET_BITWISE(GPIOL_OUTPUT_VAL, 0x08) | ||
38 | |||
39 | #define READWRITE_EN GPIO_SET_BITWISE(GPIOL_ENABLE, 0x01) | ||
40 | #define READWRITE_OUT GPIO_SET_BITWISE(GPIOL_OUTPUT_EN, 0x01) | ||
41 | #define READWRITE_LO GPIO_CLEAR_BITWISE(GPIOL_OUTPUT_VAL, 0x01) | ||
42 | #define READWRITE_HI GPIO_SET_BITWISE(GPIOL_OUTPUT_VAL, 0x01) | ||
43 | |||
44 | #define DELAY1 udelay(1) | ||
45 | #define DELAY2 udelay(2) | ||
46 | |||
47 | void fmradio_3wire_init(void) | ||
48 | { | ||
49 | READWRITE_EN; | ||
50 | READWRITE_OUT; | ||
51 | |||
52 | DATA_EN; | ||
53 | DATA_IN; | ||
54 | |||
55 | CLOCK_EN; | ||
56 | CLOCK_HI; | ||
57 | CLOCK_OUT; | ||
58 | |||
59 | DELAY2; | ||
60 | } | ||
61 | |||
62 | int fmradio_3wire_write(const unsigned char* buf) | ||
63 | { | ||
64 | int i, j; | ||
65 | |||
66 | CLOCK_LO; | ||
67 | READWRITE_LO; | ||
68 | DELAY2; | ||
69 | READWRITE_HI; | ||
70 | DELAY1; | ||
71 | DATA_OUT; | ||
72 | |||
73 | /* 5 bytes to the tuner */ | ||
74 | for (j = 0; j < 5; j++) | ||
75 | { | ||
76 | for (i = 7; i >= 0; i--) | ||
77 | { | ||
78 | if ((buf[j] >> i) & 0x1) DATA_HI; | ||
79 | else DATA_LO; | ||
80 | DELAY1; | ||
81 | CLOCK_HI; | ||
82 | DELAY2; | ||
83 | CLOCK_LO; | ||
84 | DELAY1; | ||
85 | } | ||
86 | } | ||
87 | READWRITE_LO; | ||
88 | |||
89 | return j; | ||
90 | } | ||
91 | |||
92 | int fmradio_3wire_read(unsigned char* buf) | ||
93 | { | ||
94 | int i, j; | ||
95 | |||
96 | CLOCK_LO; | ||
97 | READWRITE_HI; | ||
98 | DELAY2; | ||
99 | READWRITE_LO; | ||
100 | DELAY2; | ||
101 | DATA_IN; | ||
102 | |||
103 | /* 5 bytes from the tuner */ | ||
104 | for (j = 0; j < 5; j++) | ||
105 | { | ||
106 | buf[j] = 0; | ||
107 | for (i = 7; i >= 0; i--) | ||
108 | { | ||
109 | buf[j] |= ((DATA >> 3) << i); | ||
110 | |||
111 | CLOCK_HI; | ||
112 | DELAY2; | ||
113 | CLOCK_LO; | ||
114 | DELAY2; | ||
115 | } | ||
116 | } | ||
117 | READWRITE_HI; | ||
118 | |||
119 | return j; | ||
120 | } | ||