summaryrefslogtreecommitdiff
path: root/firmware/tuner_philips.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/tuner_philips.c')
-rw-r--r--firmware/tuner_philips.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/firmware/tuner_philips.c b/firmware/tuner_philips.c
index 50559af23e..e63d063bfd 100644
--- a/firmware/tuner_philips.c
+++ b/firmware/tuner_philips.c
@@ -19,10 +19,12 @@
19 ****************************************************************************/ 19 ****************************************************************************/
20 20
21#include <stdbool.h> 21#include <stdbool.h>
22#include <string.h>
22#include "tuner.h" /* tuner abstraction interface */ 23#include "tuner.h" /* tuner abstraction interface */
23#include "fmradio_i2c.h" /* physical interface driver */ 24#include "fmradio_i2c.h" /* physical interface driver */
24 25
25/* FIXME: this is just a dummy */ 26#define I2C_ADR 0xC0
27static unsigned char write_bytes[5];
26 28
27/* tuner abstraction layer: set something to the tuner */ 29/* tuner abstraction layer: set something to the tuner */
28void philips_set(int setting, int value) 30void philips_set(int setting, int value)
@@ -31,12 +33,22 @@ void philips_set(int setting, int value)
31 switch(setting) 33 switch(setting)
32 { 34 {
33 case RADIO_INIT: 35 case RADIO_INIT:
36 memset(write_bytes, 0, sizeof(write_bytes));
34 break; 37 break;
35 38
36 case RADIO_FREQUENCY: 39 case RADIO_FREQUENCY:
40 {
41 int n;
42 n = (4 * (value - 225000)) / 50000;
43 write_bytes[0] = (write_bytes[0] & 0xC0) | (n >> 8);
44 write_bytes[1] = n & 0xFF;
45 fmradio_i2c_write(I2C_ADR, write_bytes, sizeof(write_bytes));
46 }
37 break; 47 break;
38 48
39 case RADIO_MUTE: 49 case RADIO_MUTE:
50 write_bytes[0] = (write_bytes[0] & 0x7F) | (value ? 0x80 : 0);
51 fmradio_i2c_write(I2C_ADR, write_bytes, sizeof(write_bytes));
40 break; 52 break;
41 53
42 case RADIO_IF_MEASUREMENT: 54 case RADIO_IF_MEASUREMENT:
@@ -46,6 +58,8 @@ void philips_set(int setting, int value)
46 break; 58 break;
47 59
48 case RADIO_FORCE_MONO: 60 case RADIO_FORCE_MONO:
61 write_bytes[2] = (write_bytes[2] & 0xF7) | (value ? 0x08 : 0);
62 fmradio_i2c_write(I2C_ADR, write_bytes, sizeof(write_bytes));
49 break; 63 break;
50 } 64 }
51} 65}
@@ -53,17 +67,24 @@ void philips_set(int setting, int value)
53/* tuner abstraction layer: read something from the tuner */ 67/* tuner abstraction layer: read something from the tuner */
54int philips_get(int setting) 68int philips_get(int setting)
55{ 69{
70 unsigned char read_bytes[5];
56 int val = -1; 71 int val = -1;
72
73 fmradio_i2c_read(I2C_ADR, read_bytes, sizeof(read_bytes));
74
57 switch(setting) 75 switch(setting)
58 { 76 {
59 case RADIO_PRESENT: 77 case RADIO_PRESENT:
60 val = 0; /* false */ 78 val = 1; /* true */
61 break; 79 break;
62 80
63 case RADIO_IF_MEASURED: 81 case RADIO_IF_MEASURED:
82 val = read_bytes[2] & 0x7F;
83 val = 1070 + (val-55)/2;
64 break; 84 break;
65 85
66 case RADIO_STEREO: 86 case RADIO_STEREO:
87 val = read_bytes[2] >> 7;
67 break; 88 break;
68 } 89 }
69 return val; 90 return val;