1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Driver for AS3514 audio codec
12 * Copyright (c) 2007 Daniel Ankers
13 * Copyright (c) 2007 Christian Gmeiner
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
23 ****************************************************************************/
25 #ifndef _ASCODEC_TARGET_H
26 #define _ASCODEC_TARGET_H
31 #include "kernel.h" /* for struct wakeup */
32 #include "clock-target.h" /* for AS3525_I2C_PRESCALER */
33 #include "system-arm.h"
35 /* Charge Pump and Power management Settings */
36 #define AS314_CP_DCDC3_SETTING \
37 ((0<<7) | /* CP_SW Auto-Switch Margin 0=200/300 1=150/255 */ \
38 (0<<6) | /* CP_on 0=Normal op 1=Chg Pump Always On */ \
39 (0<<5) | /* LREG_CPnot Always write 0 */ \
40 (0<<3) | /* DCDC3p BVDD setting 3.6/3.2/3.1/3.0 */ \
41 (1<<2) | /* LREG_off 1=Auto mode switching 0=Length Reg only*/\
42 (0<<0) ) /* CVDDp Core Voltage Setting 1.2/1.15/1.10/1.05*/
49 #define ASCODEC_REQ_READ 0
50 #define ASCODEC_REQ_WRITE 1
53 * How many bytes we using in struct ascodec_request for the data buffer.
54 * 4 fits the alignment best right now.
55 * We don't actually use more than 3 at the moment (when reading interrupts)
56 * Upper limit would be 255 since DACNT is 8 bits!
58 #define ASCODEC_REQ_MAXLEN 4
60 typedef void (ascodec_cb_fn
)(unsigned const char *data
, unsigned cnt
);
62 struct ascodec_request
{
67 unsigned char data
[ASCODEC_REQ_MAXLEN
];
69 ascodec_cb_fn
*callback
;
70 struct ascodec_request
*next
;
73 void ascodec_init(void) INIT_ATTR
;
75 int ascodec_write(unsigned int index
, unsigned int value
);
77 int ascodec_read(unsigned int index
);
79 int ascodec_readbytes(unsigned int index
, unsigned int len
, unsigned char *data
);
82 * The request struct passed in must be allocated statically.
83 * If you call ascodec_async_write from different places, each
84 * call needs it's own request struct.
85 * This comment is duplicated in .c and .h for your convenience.
87 void ascodec_async_write(unsigned index
, unsigned int value
, struct ascodec_request
*req
);
90 * The request struct passed in must be allocated statically.
91 * If you call ascodec_async_read from different places, each
92 * call needs it's own request struct.
93 * If len is bigger than ASCODEC_REQ_MAXLEN it will be
94 * set to ASCODEC_REQ_MAXLEN.
95 * This comment is duplicated in .c and .h for your convenience.
97 void ascodec_async_read(unsigned index
, unsigned int len
,
98 struct ascodec_request
*req
, ascodec_cb_fn
*cb
);
100 void ascodec_req_init(struct ascodec_request
*req
, int type
,
101 unsigned int index
, unsigned int cnt
);
103 void ascodec_submit(struct ascodec_request
*req
);
105 void ascodec_lock(void);
107 void ascodec_unlock(void);
109 void ascodec_wait_adc_finished(void);
111 static inline void ascodec_monitor_endofch(void) {} /* already enabled */
113 bool ascodec_endofch(void);
115 bool ascodec_chg_status(void);
117 #if CONFIG_CPU == AS3525v2
118 static inline void ascodec_write_pmu(unsigned int index
, unsigned int subreg
,
121 /* we disable interrupts to make sure no operation happen on the i2c bus
122 * between selecting the sub register and writing to it */
123 int oldstatus
= disable_irq_save();
124 ascodec_write(AS3543_PMU_ENABLE
, 8|subreg
);
125 ascodec_write(index
, value
);
126 restore_irq(oldstatus
);
129 static inline int ascodec_read_pmu(unsigned int index
, unsigned int subreg
)
131 /* we disable interrupts to make sure no operation happen on the i2c bus
132 * between selecting the sub register and reading it */
133 int oldstatus
= disable_irq_save();
134 ascodec_write(AS3543_PMU_ENABLE
, subreg
);
135 int ret
= ascodec_read(index
);
136 restore_irq(oldstatus
);
139 #endif /* CONFIG_CPU == AS3525v2 */
141 static inline void ascodec_write_charger(int value
)
143 #if CONFIG_CPU == AS3525
144 ascodec_write(AS3514_CHARGER
, value
);
146 ascodec_write_pmu(AS3543_CHARGER
, 1, value
);
150 static inline int ascodec_read_charger(void)
152 #if CONFIG_CPU == AS3525
153 return ascodec_read(AS3514_CHARGER
);
155 return ascodec_read_pmu(AS3543_CHARGER
, 1);
159 #endif /* !SIMULATOR */
161 #endif /* !_ASCODEC_TARGET_H */