summaryrefslogtreecommitdiffstats
path: root/firmware/target/hosted/ypr0
diff options
context:
space:
mode:
authorLorenzo Miori <memorys60@gmail.com>2012-04-07 10:30:23 +0200
committerThomas Martitz <kugel@rockbox.org>2012-05-28 19:39:14 +0200
commit3cad5573b68917442564dc4f210fac056447c5cd (patch)
tree16e7f637a7bf9a22b00fde445a97f267b5467cc2 /firmware/target/hosted/ypr0
parent9c33f93c1c9bfd37f33f638eccceefa4c0d5b5e6 (diff)
downloadrockbox-3cad5573b68917442564dc4f210fac056447c5cd.tar.gz
rockbox-3cad5573b68917442564dc4f210fac056447c5cd.zip
ypr0: This patch adds radio support to Samsung YP-R0
Basically it uses the default SI4700 radio chip driver, the only thing that's different is the I2C access, written specifically to interact with my kernel module. Next things to add are: - RDS support! Change-Id: I0ed125641e00f93124d7a34f90dd508e7f1db5a4 Signed-off-by: Lorenzo Miori <memorys60@gmail.com>
Diffstat (limited to 'firmware/target/hosted/ypr0')
-rw-r--r--firmware/target/hosted/ypr0/audio-ypr0.c69
-rw-r--r--firmware/target/hosted/ypr0/powermgmt-ypr0.c29
-rw-r--r--firmware/target/hosted/ypr0/radio-ypr0.c66
-rw-r--r--firmware/target/hosted/ypr0/radio-ypr0.h36
-rw-r--r--firmware/target/hosted/ypr0/si4709.h82
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 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2009 by Bertrik Sikken
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+#include "config.h"
+#include "system.h"
+#include "cpu.h"
+#include "audio.h"
+#include "audiohw.h"
+#include "sound.h"
+
+int audio_channels = 2;
+int audio_output_source = AUDIO_SRC_PLAYBACK;
+
+void audio_set_output_source(int source)
+{
+ if ((unsigned)source >= AUDIO_NUM_SOURCES)
+ source = AUDIO_SRC_PLAYBACK;
+
+ audio_output_source = source;
+} /* audio_set_output_source */
+
+void audio_input_mux(int source, unsigned flags)
+{
+ static int last_source = AUDIO_SRC_PLAYBACK;
+
+ (void)flags;
+
+ switch (source)
+ {
+ default: /* playback - no recording */
+ source = AUDIO_SRC_PLAYBACK;
+ case AUDIO_SRC_PLAYBACK:
+ audio_channels = 2;
+ if (source != last_source)
+ {
+ audiohw_set_monitor(false);
+
+ }
+ break;
+
+ case AUDIO_SRC_FMRADIO: /* recording and playback */
+ audio_channels = 2;
+ if (source == last_source)
+ break;
+
+ audiohw_set_monitor(true);
+ break;
+ } /* end switch */
+
+ last_source = source;
+} /* audio_input_mux */
+
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 @@
#include "file.h"
#include "adc.h"
#include "sc900776.h"
+#include "radio-ypr0.h"
const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] =
{
@@ -37,7 +38,6 @@ const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] =
};
/* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */
-/* FIXME: This is guessed. Make proper curve using battery_bench */
const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] =
{
{ 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] =
#if CONFIG_CHARGING
/* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */
-/* FIXME: This is guessed. Make proper curve using battery_bench */
const unsigned short const percent_to_volt_charge[11] =
{
3450, 3670, 3721, 3751, 3782, 3821, 3876, 3941, 4034, 4125, 4200
@@ -81,3 +80,29 @@ bool charging_state(void)
/* dont indicate for > ~95% */
return ret && (_battery_voltage() <= charged_thres);
}
+
+#if CONFIG_TUNER
+static bool tuner_on = false;
+
+bool tuner_power(bool status)
+{
+ if (status != tuner_on)
+ {
+ tuner_on = status;
+ status = !status;
+ if (tuner_on) {
+ radiodev_open();
+ }
+ else {
+ radiodev_close();
+ }
+ }
+
+ return status;
+}
+
+bool tuner_powered(void)
+{
+ return tuner_on;
+}
+#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 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ *
+ * Module wrapper for SI4709 FM Radio Chip, using /dev/si470x (si4709.ko) of Samsung YP-R0
+ *
+ * Copyright (c) 2012 Lorenzo Miori
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include "stdint.h"
+#include "string.h"
+
+#include "radio-ypr0.h"
+
+static int radio_dev = -1;
+
+void radiodev_open(void) {
+ radio_dev = open("/dev/si470x", O_RDWR);
+}
+
+void radiodev_close(void) {
+ close(radio_dev);
+}
+
+/* High-level registers access */
+void si4709_write_reg(int addr, uint16_t value) {
+ sSi4709_t r = { .addr = addr, .value = value };
+ ioctl(radio_dev, IOCTL_SI4709_WRITE_BYTE, &r);
+}
+
+uint16_t si4709_read_reg(int addr) {
+ sSi4709_t r = { .addr = addr, .value = 0 };
+ ioctl(radio_dev, IOCTL_SI4709_READ_BYTE, &r);
+ return r.value;
+}
+
+/* Low-level i2c channel access */
+int fmradio_i2c_write(unsigned char address, unsigned char* buf, int count)
+{
+ (void)address;
+ sSi4709_i2c_t r = { .size = count, .buf = buf };
+ return ioctl(radio_dev, IOCTL_SI4709_I2C_WRITE, &r);
+}
+
+int fmradio_i2c_read(unsigned char address, unsigned char* buf, int count)
+{
+ (void)address;
+ sSi4709_i2c_t r = { .size = count, .buf = buf };
+ return ioctl(radio_dev, IOCTL_SI4709_I2C_READ, &r);
+} \ 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 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ *
+ * Module wrapper for SI4709 FM Radio Chip, using /dev/si470x (si4709.ko) of Samsung YP-R0
+ *
+ * Copyright (c) 2012 Lorenzo Miori
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#ifndef __RADIO_YPR0_H__
+#define __RADIO_YPR0_H__
+
+#include "si4709.h"
+#include "stdint.h"
+#include "rds.h"
+#include "si4700.h"
+
+void radiodev_open(void);
+void radiodev_close(void);
+void si4709_write_reg(int addr, uint16_t value);
+uint16_t si4709_read_reg(int addr);
+
+#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 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ *
+ * Module header for SI4709 FM Radio Chip, using /dev/si470x (si4709.ko) of Samsung YP-R0
+ *
+ * Copyright (c) 2012 Lorenzo Miori
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#ifndef __SI4709_H__
+#define __SI4709_H__
+
+#include "stdint.h"
+
+/* 7bits I2C address */
+#define SI4709_I2C_SLAVE_ADDR 0x10
+
+#define SI4702_DEVICEID 0x00
+#define SI4702_CHIPID 0x01
+#define SI4702_POWERCFG 0x02
+#define SI4702_CHANNEL 0x03
+#define SI4702_SYSCONFIG1 0x04
+#define SI4702_SYSCONFIG2 0x05
+#define SI4702_SYSCONFIG3 0x06
+#define SI4702_TEST1 0x07
+#define SI4702_TEST2 0x08
+#define SI4702_B00TCONFIG 0x09
+#define SI4702_STATUSRSSI 0x0A
+#define SI4702_READCHAN 0x0B
+#define SI4709_REG_NUM 0x10
+#define SI4702_REG_BYTE (SI4709_REG_NUM * 2)
+#define SI4702_DEVICE_ID 0x1242
+#define SI4702_RW_REG_NUM (SI4702_STATUSRSSI - SI4702_POWERCFG)
+#define SI4702_RW_OFFSET \
+ (SI4709_REG_NUM - SI4702_STATUSRSSI + SI4702_POWERCFG)
+#define BYTE_TO_WORD(hi, lo) (((hi) << 8) & 0xFF00) | ((lo) & 0x00FF)
+
+typedef struct {
+ int addr;
+ uint16_t value;
+}__attribute__((packed)) sSi4709_t;
+
+typedef struct {
+ int size;
+ unsigned char *buf;
+}__attribute__((packed)) sSi4709_i2c_t;
+
+typedef enum
+{
+ IOCTL_SI4709_INIT = 0,
+ IOCTL_SI4709_CLOSE,
+ IOCTL_SI4709_WRITE_BYTE,
+ IOCTL_SI4709_READ_BYTE,
+ IOCTL_SI4709_I2C_WRITE,
+ IOCTL_SI4709_I2C_READ,
+
+ E_IOCTL_SI4709_MAX
+} eSi4709_ioctl_t;
+
+#define DRV_IOCTL_SI4709_MAGIC 'S'
+
+#define IOCTL_SI4709_INIT _IO(DRV_IOCTL_SI4709_MAGIC, IOCTL_SI4709_INIT)
+#define IOCTL_SI4709_CLOSE _IO(DRV_IOCTL_SI4709_MAGIC, IOCTL_SI4709_CLOSE)
+#define IOCTL_SI4709_WRITE_BYTE _IOW(DRV_IOCTL_SI4709_MAGIC, IOCTL_SI4709_WRITE_BYTE, sSi4709_t)
+#define IOCTL_SI4709_READ_BYTE _IOR(DRV_IOCTL_SI4709_MAGIC, IOCTL_SI4709_READ_BYTE, sSi4709_t)
+#define IOCTL_SI4709_I2C_WRITE _IOW(DRV_IOCTL_SI4709_MAGIC, IOCTL_SI4709_I2C_WRITE, sSi4709_i2c_t)
+#define IOCTL_SI4709_I2C_READ _IOR(DRV_IOCTL_SI4709_MAGIC, IOCTL_SI4709_I2C_READ, sSi4709_i2c_t)
+
+#endif /* __SI4709_H__ */ \ No newline at end of file