summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
authorBertrik Sikken <bertrik@sikken.nl>2008-10-26 13:28:52 +0000
committerBertrik Sikken <bertrik@sikken.nl>2008-10-26 13:28:52 +0000
commit95726a5c239d37a453efa7fe4e2f7cfdb96f536b (patch)
tree35f2a66a2ea58ddb1fff97a51018c26cbeefbb51 /firmware
parent92683778f615a5ff079fec12ea256643c669194a (diff)
downloadrockbox-95726a5c239d37a453efa7fe4e2f7cfdb96f536b.tar.gz
rockbox-95726a5c239d37a453efa7fe4e2f7cfdb96f536b.zip
FS#9503 - Sansa v2 audio/PMU communication driver (for the AS3525 SoC)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@18886 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-rw-r--r--firmware/SOURCES3
-rw-r--r--firmware/target/arm/as3525/as3525-codec.c132
-rw-r--r--firmware/target/arm/as3525/as3525-codec.h27
3 files changed, 162 insertions, 0 deletions
diff --git a/firmware/SOURCES b/firmware/SOURCES
index 4407b0e8b9..7a93d058b4 100644
--- a/firmware/SOURCES
+++ b/firmware/SOURCES
@@ -1038,6 +1038,7 @@ target/arm/pcm-telechips.c
1038#ifndef SIMULATOR 1038#ifndef SIMULATOR
1039target/arm/as3525/sansa-clip/lcd-ssd1303.c 1039target/arm/as3525/sansa-clip/lcd-ssd1303.c
1040target/arm/as3525/sansa-clip/button-clip.c 1040target/arm/as3525/sansa-clip/button-clip.c
1041target/arm/as3525/as3525-codec.c
1041#endif /* !SIMULATOR */ 1042#endif /* !SIMULATOR */
1042#endif /* SANSA_CLIP */ 1043#endif /* SANSA_CLIP */
1043 1044
@@ -1045,6 +1046,7 @@ target/arm/as3525/sansa-clip/button-clip.c
1045#ifndef SIMULATOR 1046#ifndef SIMULATOR
1046target/arm/as3525/sansa-e200v2/lcd-e200v2.c 1047target/arm/as3525/sansa-e200v2/lcd-e200v2.c
1047target/arm/as3525/sansa-e200v2/button-e200v2.c 1048target/arm/as3525/sansa-e200v2/button-e200v2.c
1049target/arm/as3525/as3525-codec.c
1048#endif /* !SIMULATOR */ 1050#endif /* !SIMULATOR */
1049#endif /* SANSA_E200V2 */ 1051#endif /* SANSA_E200V2 */
1050 1052
@@ -1052,6 +1054,7 @@ target/arm/as3525/sansa-e200v2/button-e200v2.c
1052#ifndef SIMULATOR 1054#ifndef SIMULATOR
1053target/arm/lcd-ssd1815.c 1055target/arm/lcd-ssd1815.c
1054target/arm/as3525/sansa-m200v2/button-m200v2.c 1056target/arm/as3525/sansa-m200v2/button-m200v2.c
1057target/arm/as3525/as3525-codec.c
1055#endif /* !SIMULATOR */ 1058#endif /* !SIMULATOR */
1056#endif /* SANSA_M200V2 */ 1059#endif /* SANSA_M200V2 */
1057 1060
diff --git a/firmware/target/arm/as3525/as3525-codec.c b/firmware/target/arm/as3525/as3525-codec.c
new file mode 100644
index 0000000000..1de2f49e1a
--- /dev/null
+++ b/firmware/target/arm/as3525/as3525-codec.c
@@ -0,0 +1,132 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: $
9 *
10 * Copyright (C) 2008 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
22/*
23 Provides access to the codec/charger/rtc/adc part of the as3525.
24 This part is on address 0x46 of the internal i2c bus in the as3525.
25 Registers in the codec part seem to be nearly identical to the registers
26 in the AS3514 (used in the "v1" versions of the sansa c200 and e200).
27
28 I2C register description:
29 * I2C2_CNTRL needs to be set to 0x51 for transfers to work at all.
30 bit 1 indicates direction of transfer (0 = write, 1 = read)
31 * I2C2_SR (status register) indicates in bit 0 if a transfer is busy.
32 * I2C2_SLAD0 contains the i2c slave address to read from / write to.
33 * I2C2_CPSR0/1 is the divider from the peripheral clock to the i2c clock.
34 * I2C2_DACNT sets the number of bytes to transfer and actually starts it.
35
36 When a transfer is attempted to a non-existing i2c slave address,
37 interrupt bit 7 is raised and DACNT is not decremented after the transfer.
38 */
39
40#include "as3525-codec.h"
41#include "as3525.h"
42
43#define AUDIO_I2C_ADDR 0x46
44
45#define I2C2_DATA *((volatile unsigned int *)(I2C_AUDIO_BASE + 0x00))
46#define I2C2_SLAD0 *((volatile unsigned int *)(I2C_AUDIO_BASE + 0x04))
47#define I2C2_CNTRL *((volatile unsigned int *)(I2C_AUDIO_BASE + 0x0C))
48#define I2C2_DACNT *((volatile unsigned int *)(I2C_AUDIO_BASE + 0x10))
49#define I2C2_CPSR0 *((volatile unsigned int *)(I2C_AUDIO_BASE + 0x1C))
50#define I2C2_CPSR1 *((volatile unsigned int *)(I2C_AUDIO_BASE + 0x20))
51#define I2C2_IMR *((volatile unsigned int *)(I2C_AUDIO_BASE + 0x24))
52#define I2C2_RIS *((volatile unsigned int *)(I2C_AUDIO_BASE + 0x28))
53#define I2C2_MIS *((volatile unsigned int *)(I2C_AUDIO_BASE + 0x2C))
54#define I2C2_SR *((volatile unsigned int *)(I2C_AUDIO_BASE + 0x30))
55#define I2C2_INT_CLR *((volatile unsigned int *)(I2C_AUDIO_BASE + 0x40))
56#define I2C2_SADDR *((volatile unsigned int *)(I2C_AUDIO_BASE + 0x44))
57
58
59/* initialises the internal i2c bus and prepares for transfers to the codec */
60void as3525_codec_init(void)
61{
62 /* reset device */
63 CCU_SRC = CCU_SRC_I2C_AUDIO_EN;
64 CCU_SRL = CCU_SRL_MAGIC_NUMBER;
65 CCU_SRL = 0;
66
67 /* enable clock */
68 CGU_PERI |= CGU_I2C_AUDIO_MASTER_CLOCK_ENABLE;
69
70 /* prescaler for i2c clock */
71 I2C2_CPSR0 = 60; /* 24 MHz / 400 kHz */
72 I2C2_CPSR1 = 0; /* MSB */
73
74 /* set i2c slave address of codec part */
75 I2C2_SLAD0 = AUDIO_I2C_ADDR << 1;
76
77 I2C2_CNTRL = 0x51;
78}
79
80
81/* returns != 0 when busy */
82static int i2c_busy(void)
83{
84 return (I2C2_SR & 1);
85}
86
87
88/* returns 0 on success, <0 otherwise */
89int as3525_codec_write(int index, int value)
90{
91 if (index == 0x21) {
92 /* prevent setting of the LREG_CP_not bit */
93 value &= ~(1 << 5);
94 }
95
96 /* check if still busy */
97 if (i2c_busy()) {
98 return -1;
99 }
100
101 /* start transfer */
102 I2C2_SADDR = index;
103 I2C2_CNTRL &= ~(1 << 1);
104 I2C2_DATA = value;
105 I2C2_DACNT = 1;
106
107 /* wait for transfer*/
108 while (i2c_busy());
109
110 return 0;
111}
112
113
114/* returns value read on success, <0 otherwise */
115int as3525_codec_read(int index)
116{
117 /* check if still busy */
118 if (i2c_busy()) {
119 return -1;
120 }
121
122 /* start transfer */
123 I2C2_SADDR = index;
124 I2C2_CNTRL |= (1 << 1);
125 I2C2_DACNT = 1;
126
127 /* wait for transfer*/
128 while (i2c_busy());
129
130 return I2C2_DATA;
131}
132
diff --git a/firmware/target/arm/as3525/as3525-codec.h b/firmware/target/arm/as3525/as3525-codec.h
new file mode 100644
index 0000000000..9d694554c6
--- /dev/null
+++ b/firmware/target/arm/as3525/as3525-codec.h
@@ -0,0 +1,27 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: $
9 *
10 * Copyright (C) 2008 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
22void as3525_codec_init(void);
23
24int as3525_codec_write(int index, int value);
25int as3525_codec_read(int index);
26
27