diff options
Diffstat (limited to 'firmware/target/hosted/ypr0')
-rw-r--r-- | firmware/target/hosted/ypr0/audio-ypr0.c | 69 | ||||
-rw-r--r-- | firmware/target/hosted/ypr0/powermgmt-ypr0.c | 29 | ||||
-rw-r--r-- | firmware/target/hosted/ypr0/radio-ypr0.c | 66 | ||||
-rw-r--r-- | firmware/target/hosted/ypr0/radio-ypr0.h | 36 | ||||
-rw-r--r-- | firmware/target/hosted/ypr0/si4709.h | 82 |
5 files changed, 280 insertions, 2 deletions
diff --git a/firmware/target/hosted/ypr0/audio-ypr0.c b/firmware/target/hosted/ypr0/audio-ypr0.c new file mode 100644 index 0000000000..dfd63ef5cd --- /dev/null +++ b/firmware/target/hosted/ypr0/audio-ypr0.c | |||
@@ -0,0 +1,69 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2009 by Bertrik Sikken | ||
11 | * | ||
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. | ||
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 "config.h" | ||
22 | #include "system.h" | ||
23 | #include "cpu.h" | ||
24 | #include "audio.h" | ||
25 | #include "audiohw.h" | ||
26 | #include "sound.h" | ||
27 | |||
28 | int audio_channels = 2; | ||
29 | int audio_output_source = AUDIO_SRC_PLAYBACK; | ||
30 | |||
31 | void audio_set_output_source(int source) | ||
32 | { | ||
33 | if ((unsigned)source >= AUDIO_NUM_SOURCES) | ||
34 | source = AUDIO_SRC_PLAYBACK; | ||
35 | |||
36 | audio_output_source = source; | ||
37 | } /* audio_set_output_source */ | ||
38 | |||
39 | void audio_input_mux(int source, unsigned flags) | ||
40 | { | ||
41 | static int last_source = AUDIO_SRC_PLAYBACK; | ||
42 | |||
43 | (void)flags; | ||
44 | |||
45 | switch (source) | ||
46 | { | ||
47 | default: /* playback - no recording */ | ||
48 | source = AUDIO_SRC_PLAYBACK; | ||
49 | case AUDIO_SRC_PLAYBACK: | ||
50 | audio_channels = 2; | ||
51 | if (source != last_source) | ||
52 | { | ||
53 | audiohw_set_monitor(false); | ||
54 | |||
55 | } | ||
56 | break; | ||
57 | |||
58 | case AUDIO_SRC_FMRADIO: /* recording and playback */ | ||
59 | audio_channels = 2; | ||
60 | if (source == last_source) | ||
61 | break; | ||
62 | |||
63 | audiohw_set_monitor(true); | ||
64 | break; | ||
65 | } /* end switch */ | ||
66 | |||
67 | last_source = source; | ||
68 | } /* audio_input_mux */ | ||
69 | |||
diff --git a/firmware/target/hosted/ypr0/powermgmt-ypr0.c b/firmware/target/hosted/ypr0/powermgmt-ypr0.c index 45ff2ae737..347e5fa146 100644 --- a/firmware/target/hosted/ypr0/powermgmt-ypr0.c +++ b/firmware/target/hosted/ypr0/powermgmt-ypr0.c | |||
@@ -24,6 +24,7 @@ | |||
24 | #include "file.h" | 24 | #include "file.h" |
25 | #include "adc.h" | 25 | #include "adc.h" |
26 | #include "sc900776.h" | 26 | #include "sc900776.h" |
27 | #include "radio-ypr0.h" | ||
27 | 28 | ||
28 | const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] = | 29 | const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] = |
29 | { | 30 | { |
@@ -37,7 +38,6 @@ const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] = | |||
37 | }; | 38 | }; |
38 | 39 | ||
39 | /* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */ | 40 | /* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */ |
40 | /* FIXME: This is guessed. Make proper curve using battery_bench */ | ||
41 | const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] = | 41 | const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] = |
42 | { | 42 | { |
43 | { 3450, 3502, 3550, 3587, 3623, 3669, 3742, 3836, 3926, 4026, 4200 } | 43 | { 3450, 3502, 3550, 3587, 3623, 3669, 3742, 3836, 3926, 4026, 4200 } |
@@ -45,7 +45,6 @@ const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] = | |||
45 | 45 | ||
46 | #if CONFIG_CHARGING | 46 | #if CONFIG_CHARGING |
47 | /* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */ | 47 | /* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */ |
48 | /* FIXME: This is guessed. Make proper curve using battery_bench */ | ||
49 | const unsigned short const percent_to_volt_charge[11] = | 48 | const unsigned short const percent_to_volt_charge[11] = |
50 | { | 49 | { |
51 | 3450, 3670, 3721, 3751, 3782, 3821, 3876, 3941, 4034, 4125, 4200 | 50 | 3450, 3670, 3721, 3751, 3782, 3821, 3876, 3941, 4034, 4125, 4200 |
@@ -81,3 +80,29 @@ bool charging_state(void) | |||
81 | /* dont indicate for > ~95% */ | 80 | /* dont indicate for > ~95% */ |
82 | return ret && (_battery_voltage() <= charged_thres); | 81 | return ret && (_battery_voltage() <= charged_thres); |
83 | } | 82 | } |
83 | |||
84 | #if CONFIG_TUNER | ||
85 | static bool tuner_on = false; | ||
86 | |||
87 | bool tuner_power(bool status) | ||
88 | { | ||
89 | if (status != tuner_on) | ||
90 | { | ||
91 | tuner_on = status; | ||
92 | status = !status; | ||
93 | if (tuner_on) { | ||
94 | radiodev_open(); | ||
95 | } | ||
96 | else { | ||
97 | radiodev_close(); | ||
98 | } | ||
99 | } | ||
100 | |||
101 | return status; | ||
102 | } | ||
103 | |||
104 | bool tuner_powered(void) | ||
105 | { | ||
106 | return tuner_on; | ||
107 | } | ||
108 | #endif /* #if CONFIG_TUNER */ \ No newline at end of file | ||
diff --git a/firmware/target/hosted/ypr0/radio-ypr0.c b/firmware/target/hosted/ypr0/radio-ypr0.c new file mode 100644 index 0000000000..c3597bd18c --- /dev/null +++ b/firmware/target/hosted/ypr0/radio-ypr0.c | |||
@@ -0,0 +1,66 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * Module wrapper for SI4709 FM Radio Chip, using /dev/si470x (si4709.ko) of Samsung YP-R0 | ||
10 | * | ||
11 | * Copyright (c) 2012 Lorenzo Miori | ||
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 | |||
23 | #include <unistd.h> | ||
24 | #include <fcntl.h> | ||
25 | #include <sys/ioctl.h> | ||
26 | #include "stdint.h" | ||
27 | #include "string.h" | ||
28 | |||
29 | #include "radio-ypr0.h" | ||
30 | |||
31 | static int radio_dev = -1; | ||
32 | |||
33 | void radiodev_open(void) { | ||
34 | radio_dev = open("/dev/si470x", O_RDWR); | ||
35 | } | ||
36 | |||
37 | void radiodev_close(void) { | ||
38 | close(radio_dev); | ||
39 | } | ||
40 | |||
41 | /* High-level registers access */ | ||
42 | void si4709_write_reg(int addr, uint16_t value) { | ||
43 | sSi4709_t r = { .addr = addr, .value = value }; | ||
44 | ioctl(radio_dev, IOCTL_SI4709_WRITE_BYTE, &r); | ||
45 | } | ||
46 | |||
47 | uint16_t si4709_read_reg(int addr) { | ||
48 | sSi4709_t r = { .addr = addr, .value = 0 }; | ||
49 | ioctl(radio_dev, IOCTL_SI4709_READ_BYTE, &r); | ||
50 | return r.value; | ||
51 | } | ||
52 | |||
53 | /* Low-level i2c channel access */ | ||
54 | int fmradio_i2c_write(unsigned char address, unsigned char* buf, int count) | ||
55 | { | ||
56 | (void)address; | ||
57 | sSi4709_i2c_t r = { .size = count, .buf = buf }; | ||
58 | return ioctl(radio_dev, IOCTL_SI4709_I2C_WRITE, &r); | ||
59 | } | ||
60 | |||
61 | int fmradio_i2c_read(unsigned char address, unsigned char* buf, int count) | ||
62 | { | ||
63 | (void)address; | ||
64 | sSi4709_i2c_t r = { .size = count, .buf = buf }; | ||
65 | return ioctl(radio_dev, IOCTL_SI4709_I2C_READ, &r); | ||
66 | } \ No newline at end of file | ||
diff --git a/firmware/target/hosted/ypr0/radio-ypr0.h b/firmware/target/hosted/ypr0/radio-ypr0.h new file mode 100644 index 0000000000..13bcb6dc72 --- /dev/null +++ b/firmware/target/hosted/ypr0/radio-ypr0.h | |||
@@ -0,0 +1,36 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * Module wrapper for SI4709 FM Radio Chip, using /dev/si470x (si4709.ko) of Samsung YP-R0 | ||
10 | * | ||
11 | * Copyright (c) 2012 Lorenzo Miori | ||
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 | |||
23 | #ifndef __RADIO_YPR0_H__ | ||
24 | #define __RADIO_YPR0_H__ | ||
25 | |||
26 | #include "si4709.h" | ||
27 | #include "stdint.h" | ||
28 | #include "rds.h" | ||
29 | #include "si4700.h" | ||
30 | |||
31 | void radiodev_open(void); | ||
32 | void radiodev_close(void); | ||
33 | void si4709_write_reg(int addr, uint16_t value); | ||
34 | uint16_t si4709_read_reg(int addr); | ||
35 | |||
36 | #endif /*__RADIO-YPR0_H__*/ \ No newline at end of file | ||
diff --git a/firmware/target/hosted/ypr0/si4709.h b/firmware/target/hosted/ypr0/si4709.h new file mode 100644 index 0000000000..c27472e856 --- /dev/null +++ b/firmware/target/hosted/ypr0/si4709.h | |||
@@ -0,0 +1,82 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * Module header for SI4709 FM Radio Chip, using /dev/si470x (si4709.ko) of Samsung YP-R0 | ||
10 | * | ||
11 | * Copyright (c) 2012 Lorenzo Miori | ||
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 | |||
23 | #ifndef __SI4709_H__ | ||
24 | #define __SI4709_H__ | ||
25 | |||
26 | #include "stdint.h" | ||
27 | |||
28 | /* 7bits I2C address */ | ||
29 | #define SI4709_I2C_SLAVE_ADDR 0x10 | ||
30 | |||
31 | #define SI4702_DEVICEID 0x00 | ||
32 | #define SI4702_CHIPID 0x01 | ||
33 | #define SI4702_POWERCFG 0x02 | ||
34 | #define SI4702_CHANNEL 0x03 | ||
35 | #define SI4702_SYSCONFIG1 0x04 | ||
36 | #define SI4702_SYSCONFIG2 0x05 | ||
37 | #define SI4702_SYSCONFIG3 0x06 | ||
38 | #define SI4702_TEST1 0x07 | ||
39 | #define SI4702_TEST2 0x08 | ||
40 | #define SI4702_B00TCONFIG 0x09 | ||
41 | #define SI4702_STATUSRSSI 0x0A | ||
42 | #define SI4702_READCHAN 0x0B | ||
43 | #define SI4709_REG_NUM 0x10 | ||
44 | #define SI4702_REG_BYTE (SI4709_REG_NUM * 2) | ||
45 | #define SI4702_DEVICE_ID 0x1242 | ||
46 | #define SI4702_RW_REG_NUM (SI4702_STATUSRSSI - SI4702_POWERCFG) | ||
47 | #define SI4702_RW_OFFSET \ | ||
48 | (SI4709_REG_NUM - SI4702_STATUSRSSI + SI4702_POWERCFG) | ||
49 | #define BYTE_TO_WORD(hi, lo) (((hi) << 8) & 0xFF00) | ((lo) & 0x00FF) | ||
50 | |||
51 | typedef struct { | ||
52 | int addr; | ||
53 | uint16_t value; | ||
54 | }__attribute__((packed)) sSi4709_t; | ||
55 | |||
56 | typedef struct { | ||
57 | int size; | ||
58 | unsigned char *buf; | ||
59 | }__attribute__((packed)) sSi4709_i2c_t; | ||
60 | |||
61 | typedef enum | ||
62 | { | ||
63 | IOCTL_SI4709_INIT = 0, | ||
64 | IOCTL_SI4709_CLOSE, | ||
65 | IOCTL_SI4709_WRITE_BYTE, | ||
66 | IOCTL_SI4709_READ_BYTE, | ||
67 | IOCTL_SI4709_I2C_WRITE, | ||
68 | IOCTL_SI4709_I2C_READ, | ||
69 | |||
70 | E_IOCTL_SI4709_MAX | ||
71 | } eSi4709_ioctl_t; | ||
72 | |||
73 | #define DRV_IOCTL_SI4709_MAGIC 'S' | ||
74 | |||
75 | #define IOCTL_SI4709_INIT _IO(DRV_IOCTL_SI4709_MAGIC, IOCTL_SI4709_INIT) | ||
76 | #define IOCTL_SI4709_CLOSE _IO(DRV_IOCTL_SI4709_MAGIC, IOCTL_SI4709_CLOSE) | ||
77 | #define IOCTL_SI4709_WRITE_BYTE _IOW(DRV_IOCTL_SI4709_MAGIC, IOCTL_SI4709_WRITE_BYTE, sSi4709_t) | ||
78 | #define IOCTL_SI4709_READ_BYTE _IOR(DRV_IOCTL_SI4709_MAGIC, IOCTL_SI4709_READ_BYTE, sSi4709_t) | ||
79 | #define IOCTL_SI4709_I2C_WRITE _IOW(DRV_IOCTL_SI4709_MAGIC, IOCTL_SI4709_I2C_WRITE, sSi4709_i2c_t) | ||
80 | #define IOCTL_SI4709_I2C_READ _IOR(DRV_IOCTL_SI4709_MAGIC, IOCTL_SI4709_I2C_READ, sSi4709_i2c_t) | ||
81 | |||
82 | #endif /* __SI4709_H__ */ \ No newline at end of file | ||