summaryrefslogtreecommitdiff
path: root/firmware/target/arm/as3525/ascodec-target.h
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/as3525/ascodec-target.h')
-rw-r--r--firmware/target/arm/as3525/ascodec-target.h66
1 files changed, 45 insertions, 21 deletions
diff --git a/firmware/target/arm/as3525/ascodec-target.h b/firmware/target/arm/as3525/ascodec-target.h
index 37947541c2..8ce9a428d3 100644
--- a/firmware/target/arm/as3525/ascodec-target.h
+++ b/firmware/target/arm/as3525/ascodec-target.h
@@ -52,7 +52,7 @@
52/* 52/*
53 * How many bytes we using in struct ascodec_request for the data buffer. 53 * How many bytes we using in struct ascodec_request for the data buffer.
54 * 4 fits the alignment best right now. 54 * 4 fits the alignment best right now.
55 * We don't actually use more than 2 at the moment (in adc_read). 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! 56 * Upper limit would be 255 since DACNT is 8 bits!
57 */ 57 */
58#define ASCODEC_REQ_MAXLEN 4 58#define ASCODEC_REQ_MAXLEN 4
@@ -74,19 +74,6 @@ void ascodec_init(void);
74 74
75int ascodec_write(unsigned int index, unsigned int value); 75int ascodec_write(unsigned int index, unsigned int value);
76 76
77#if CONFIG_CPU == AS3525v2
78static inline void ascodec_write_pmu(unsigned int index, unsigned int subreg,
79 unsigned int value)
80{
81 /* we disable interrupts to make sure no operation happen on the i2c bus
82 * between selecting the sub register and writing to it */
83 int oldstatus = disable_irq_save();
84 ascodec_write(AS3543_PMU_ENABLE, 8|subreg);
85 ascodec_write(index, value);
86 restore_irq(oldstatus);
87}
88#endif
89
90int ascodec_read(unsigned int index); 77int ascodec_read(unsigned int index);
91 78
92int ascodec_readbytes(unsigned int index, unsigned int len, unsigned char *data); 79int ascodec_readbytes(unsigned int index, unsigned int len, unsigned char *data);
@@ -119,18 +106,55 @@ void ascodec_lock(void);
119 106
120void ascodec_unlock(void); 107void ascodec_unlock(void);
121 108
122#if CONFIG_CPU == AS3525
123void ascodec_wait_adc_finished(void); 109void ascodec_wait_adc_finished(void);
124#else 110
125static inline void ascodec_wait_adc_finished(void) 111static inline void ascodec_monitor_endofch(void) {} /* already enabled */
112
113bool ascodec_endofch(void);
114
115bool ascodec_chg_status(void);
116
117#if CONFIG_CPU == AS3525v2
118static inline void ascodec_write_pmu(unsigned int index, unsigned int subreg,
119 unsigned int value)
120{
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);
127}
128
129static inline int ascodec_read_pmu(unsigned int index, unsigned int subreg)
126{ 130{
127 /* FIXME: Doesn't work yet on AS3525v2 */ 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, 8|subreg);
135 int ret = ascodec_read(index);
136 restore_irq(oldstatus);
137 return ret;
128} 138}
129#endif 139#endif /* CONFIG_CPU == AS3525v2 */
130 140
131void ascodec_enable_endofch_irq(void); 141static inline void ascodec_write_charger(int value)
142{
143#if CONFIG_CPU == AS3525
144 ascodec_write(AS3514_CHARGER, value);
145#else
146 ascodec_write_pmu(AS3543_CHARGER, 1, value);
147#endif
148}
132 149
133void ascodec_disable_endofch_irq(void); 150static inline int ascodec_read_charger(void)
151{
152#if CONFIG_CPU == AS3525
153 return ascodec_read(AS3514_CHARGER);
154#else
155 return ascodec_read_pmu(AS3543_CHARGER, 1);
156#endif
157}
134 158
135#endif /* !SIMULATOR */ 159#endif /* !SIMULATOR */
136 160