summaryrefslogtreecommitdiff
path: root/firmware/target/hosted/samsungypr/ypr1/wmcodec-ypr1.c
diff options
context:
space:
mode:
authorLorenzo Miori <memoryS60@gmail.com>2013-09-10 22:48:34 +0200
committerThomas Martitz <kugel@rockbox.org>2014-02-05 09:56:21 +0100
commite876f4df6d240bd2e319b1e63be95a625f049a97 (patch)
treece2fe1b24650e3be7a6cd2d346d29090a5422a8c /firmware/target/hosted/samsungypr/ypr1/wmcodec-ypr1.c
parentb828b9d99bff2acc0e1f543f3176fd4b632cba68 (diff)
downloadrockbox-e876f4df6d240bd2e319b1e63be95a625f049a97.tar.gz
rockbox-e876f4df6d240bd2e319b1e63be95a625f049a97.zip
Samsung YP-R1 target port
This is the basic port to the new target Samsung YP-R1, which runs on a similar platform as YP-R0. Port is usable, although there are still some optimizations that have to be done. Change-Id: If83a8e386369e413581753780c159026d9e41f04
Diffstat (limited to 'firmware/target/hosted/samsungypr/ypr1/wmcodec-ypr1.c')
-rw-r--r--firmware/target/hosted/samsungypr/ypr1/wmcodec-ypr1.c90
1 files changed, 90 insertions, 0 deletions
diff --git a/firmware/target/hosted/samsungypr/ypr1/wmcodec-ypr1.c b/firmware/target/hosted/samsungypr/ypr1/wmcodec-ypr1.c
new file mode 100644
index 0000000000..f38c33ada1
--- /dev/null
+++ b/firmware/target/hosted/samsungypr/ypr1/wmcodec-ypr1.c
@@ -0,0 +1,90 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * I2C bus wrapper for WM1808 codec on SAMSUNG YP-R1
10 *
11 * Copyright (c) 2013 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 <stdio.h>
24#include <unistd.h>
25#include <fcntl.h>
26#include <sys/ioctl.h>
27
28#include "system.h"
29#include "audiohw.h"
30#include "wmcodec.h"
31#include "audio.h"
32#include "panic.h"
33#include "logf.h"
34
35
36#define I2C_SLAVE 0x0703
37
38/**
39 * YP-R1's kernel has ALSA implementation of the WM1808, but it
40 * unfortunately doesn't export any function to play with register.
41 * For that reason we control the I2C bus directly, letting RB driver to do the rest
42 * Assumption: no other ALSA applications are using the mixer!
43 */
44
45static int wmcodec_dev = -1;
46
47/* The ONLY tested freq for now is 44100, others are just stubs!! */
48const struct wmc_srctrl_entry wmc_srctrl_table[HW_NUM_FREQ] =
49{
50 /* TODO fix PLL frequencies also for the other available rates */
51 [HW_FREQ_44] = /* PLL = on */
52 {
53 .plln = 3 | (1 << 3),
54 .pllk1 = 0x18, /* 11289600 */
55 .pllk2 = 0x111,
56 .pllk3 = 0x139,
57 .mclkdiv = WMC_MCLKDIV_2,
58 .filter = WMC_SR_48KHZ,
59 },
60};
61
62void audiohw_init(void)
63{
64 /* First of all we need to open the device */
65 wmcodec_dev = open("/dev/i2c-1", O_RDWR);
66 if (wmcodec_dev < 0)
67 panicf("Failed to open /dev/i2c-1 device!\n");
68
69 /* Let's set the slave address and if no error we are ready!*/
70 int addr = 0x1a;
71 if (ioctl(wmcodec_dev, I2C_SLAVE, addr) < 0)
72 logf("Failed to set slave address!\n");
73}
74
75void wmcodec_write(int reg, int data)
76{
77 unsigned char data2[2];
78 /* |aaaaaaad|dddddddd| */
79 data2[0] = (reg << 0x1) | ((data >> 8) & 0x1);
80 data2[1] = data;
81
82 if (write(wmcodec_dev, data2, 2) < 0)
83 panicf("I2C device write error!\n");
84}
85
86void audiohw_enable_headphone_jack(bool enable)
87{
88 /* We don't use this facility: we have a separate GPIO for that */
89 (void)enable;
90}