Gigabeat S: Add ATA/IDE power management. Fix parameter order of regmod32 as it was...
[kugel-rb.git] / firmware / target / arm / imx31 / gigabeat-s / wmcodec-imx31.c
bloba88571ee14aa77f9445124e0f2f0ab78dc85aa1d
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Gigabeat S specific code for the WM8978 codec
12 * Copyright (C) 2008 Michael Sevakis
14 * All files in this archive are subject to the GNU General Public License.
15 * See the file COPYING in the source tree root for full license agreement.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
21 #include "config.h"
22 #include "system.h"
23 #include "kernel.h"
24 #include "sound.h"
25 #include "i2c-imx31.h"
27 /* NOTE: Some port-specific bits will have to be moved away (node and GPIO
28 * writes) for cleanest implementation. */
30 static struct i2c_node wm8978_i2c_node =
32 .num = I2C1_NUM,
33 .ifdr = I2C_IFDR_DIV192, /* 66MHz/.4MHz = 165, closest = 192 = 343750Hz */
34 /* Just hard-code for now - scaling may require
35 * updating */
36 .addr = WMC_I2C_ADDR,
39 void audiohw_init(void)
41 /* USB PLL = 338.688MHz, /30 = 11.2896MHz = 256Fs */
42 imx31_regmod32(&CLKCTL_PDR1,
43 PDR1_SSI1_PODFw(64-1) | PDR1_SSI2_PODFw(5-1),
44 PDR1_SSI1_PODF | PDR1_SSI2_PODF);
45 imx31_regmod32(&CLKCTL_PDR1,
46 PDR1_SSI1_PRE_PODFw(4-1) | PDR1_SSI2_PRE_PODFw(1-1),
47 PDR1_SSI1_PRE_PODF | PDR1_SSI2_PRE_PODF);
48 i2c_enable_node(&wm8978_i2c_node, true);
50 audiohw_preinit();
52 GPIO3_DR |= (1 << 21); /* Turn on analogue LDO */
55 void audiohw_enable_headphone_jack(bool enable)
57 if (enable)
59 GPIO3_DR |= (1 << 22); /* Turn on headphone jack output */
61 else
63 GPIO3_DR &= ~(1 << 22); /* Turn off headphone jack output */
67 void wmcodec_write(int reg, int data)
69 unsigned char d[2];
70 /* |aaaaaaad|dddddddd| */
71 d[0] = (reg << 1) | ((data & 0x100) >> 8);
72 d[1] = data;
73 i2c_write(&wm8978_i2c_node, d, 2);