2012-04-07 08:30:23 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
*
|
2013-02-23 15:59:49 +00:00
|
|
|
* Module wrapper for SI4709 FM Radio Chip, using /dev/si470x (si4709.ko)
|
|
|
|
* Samsung YP-R0 & Samsung YP-R1
|
2012-04-07 08:30:23 +00:00
|
|
|
*
|
|
|
|
* 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"
|
2012-09-27 09:56:03 +00:00
|
|
|
#include "kernel.h"
|
2012-04-07 08:30:23 +00:00
|
|
|
|
2013-02-23 15:59:49 +00:00
|
|
|
#include "radio-ypr.h"
|
2012-09-27 09:56:03 +00:00
|
|
|
#include "si4700.h"
|
|
|
|
#include "power.h"
|
2012-04-07 08:30:23 +00:00
|
|
|
|
|
|
|
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);
|
2012-09-27 09:56:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HAVE_RDS_CAP
|
|
|
|
|
|
|
|
/* Register we are going to poll */
|
|
|
|
#define STATUSRSSI 0xA
|
|
|
|
#define STATUSRSSI_RDSR (0x1 << 15)
|
|
|
|
|
|
|
|
/* Low-level RDS Support */
|
|
|
|
static struct event_queue rds_queue;
|
|
|
|
static uint32_t rds_stack[DEFAULT_STACK_SIZE / sizeof(uint32_t)];
|
|
|
|
|
|
|
|
enum {
|
|
|
|
Q_POWERUP,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void NORETURN_ATTR rds_thread(void)
|
|
|
|
{
|
|
|
|
/* start up frozen */
|
|
|
|
int timeout = TIMEOUT_BLOCK;
|
|
|
|
struct queue_event ev;
|
2017-04-20 03:20:00 +00:00
|
|
|
bool rds_rdy = false;
|
2012-09-27 09:56:03 +00:00
|
|
|
|
|
|
|
while (true) {
|
|
|
|
queue_wait_w_tmo(&rds_queue, &ev, timeout);
|
|
|
|
switch (ev.id) {
|
|
|
|
case Q_POWERUP:
|
|
|
|
/* power up: timeout after 1 tick, else block indefinitely */
|
|
|
|
timeout = ev.data ? 1 : TIMEOUT_BLOCK;
|
|
|
|
break;
|
2017-04-20 03:20:00 +00:00
|
|
|
case SYS_TIMEOUT:;
|
2012-09-27 09:56:03 +00:00
|
|
|
/* Captures RDS data and processes it */
|
2017-04-20 03:20:00 +00:00
|
|
|
bool rdsr = si4709_read_reg(STATUSRSSI) & STATUSRSSI_RDSR;
|
|
|
|
if (rdsr != rds_rdy) {
|
|
|
|
rds_rdy = rdsr;
|
|
|
|
if (rdsr) {
|
|
|
|
si4700_rds_process();
|
|
|
|
}
|
2012-09-27 09:56:03 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* true after full radio power up, and false before powering down */
|
|
|
|
void si4700_rds_powerup(bool on)
|
|
|
|
{
|
|
|
|
queue_post(&rds_queue, Q_POWERUP, on);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* One-time RDS init at startup */
|
|
|
|
void si4700_rds_init(void)
|
|
|
|
{
|
|
|
|
queue_init(&rds_queue, false);
|
|
|
|
create_thread(rds_thread, rds_stack, sizeof(rds_stack), 0, "rds"
|
|
|
|
IF_PRIO(, PRIORITY_PLAYBACK) IF_COP(, CPU));
|
|
|
|
}
|
|
|
|
#endif /* HAVE_RDS_CAP */
|