summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNils Wallménius <nils@rockbox.org>2008-04-13 10:04:21 +0000
committerNils Wallménius <nils@rockbox.org>2008-04-13 10:04:21 +0000
commit8c5d552ebdadd00a3f1610110afb6eb4fa77071a (patch)
tree0af146dd372ea8110e89fe474ad9e419af762533
parentd715f79ed6f8aa113c529b8a1ac5d8d82b69670f (diff)
downloadrockbox-8c5d552ebdadd00a3f1610110afb6eb4fa77071a.tar.gz
rockbox-8c5d552ebdadd00a3f1610110afb6eb4fa77071a.zip
Charger detection for Gigabeat S
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@17093 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/export/mc13783.h3
-rw-r--r--firmware/target/arm/imx31/gigabeat-s/mc13783-imx31.c16
-rw-r--r--firmware/target/arm/imx31/gigabeat-s/power-imx31.c10
-rw-r--r--firmware/target/arm/imx31/gigabeat-s/power-imx31.h21
4 files changed, 47 insertions, 3 deletions
diff --git a/firmware/export/mc13783.h b/firmware/export/mc13783.h
index 264c0bac4f..a489f4c8b9 100644
--- a/firmware/export/mc13783.h
+++ b/firmware/export/mc13783.h
@@ -88,6 +88,9 @@ enum mc13783_regs_enum
88 MC13783_NUM_REGS, 88 MC13783_NUM_REGS,
89}; 89};
90 90
91/* INTERRUPT_STATUS0, INTERRUPT_MASK0, INTERRUPT_SENSE0 */
92#define MC13783_CHGDET (1 << 6)
93
91/* INTERRUPT_STATUS1, INTERRUPT_MASK1, INTERRUPT_SENSE1 */ 94/* INTERRUPT_STATUS1, INTERRUPT_MASK1, INTERRUPT_SENSE1 */
92#define MC13783_HSL (1 << 0) 95#define MC13783_HSL (1 << 0)
93#define MC13783_ON1B (1 << 3) 96#define MC13783_ON1B (1 << 3)
diff --git a/firmware/target/arm/imx31/gigabeat-s/mc13783-imx31.c b/firmware/target/arm/imx31/gigabeat-s/mc13783-imx31.c
index a04cd7f893..fdb214a33d 100644
--- a/firmware/target/arm/imx31/gigabeat-s/mc13783-imx31.c
+++ b/firmware/target/arm/imx31/gigabeat-s/mc13783-imx31.c
@@ -24,6 +24,7 @@
24#include "debug.h" 24#include "debug.h"
25#include "kernel.h" 25#include "kernel.h"
26 26
27#include "power-imx31.h"
27#include "button-target.h" 28#include "button-target.h"
28 29
29/* This is all based on communicating with the MC13783 PMU which is on 30/* This is all based on communicating with the MC13783 PMU which is on
@@ -64,11 +65,15 @@ static __attribute__((noreturn)) void mc13783_interrupt_thread(void)
64 gpio_enable_event(MC13783_GPIO_NUM, MC13783_EVENT_ID); 65 gpio_enable_event(MC13783_GPIO_NUM, MC13783_EVENT_ID);
65 66
66 /* Check initial states */ 67 /* Check initial states */
68 value = mc13783_read(MC13783_INTERRUPT_SENSE0);
69 set_charger_inserted(value & MC13783_CHGDET);
70
67 value = mc13783_read(MC13783_INTERRUPT_SENSE1); 71 value = mc13783_read(MC13783_INTERRUPT_SENSE1);
68 button_power_set_state((value & MC13783_ON1B) == 0); 72 button_power_set_state((value & MC13783_ON1B) == 0);
69 set_headphones_inserted((value & MC13783_ON2B) == 0); 73 set_headphones_inserted((value & MC13783_ON2B) == 0);
70 74
71 /* Enable desired PMIC interrupts */ 75 /* Enable desired PMIC interrupts */
76 mc13783_clear(MC13783_INTERRUPT_MASK0, MC13783_CHGDET);
72 mc13783_clear(MC13783_INTERRUPT_MASK1, MC13783_ON1B | MC13783_ON2B); 77 mc13783_clear(MC13783_INTERRUPT_MASK1, MC13783_ON1B | MC13783_ON2B);
73 78
74 while (1) 79 while (1)
@@ -78,12 +83,19 @@ static __attribute__((noreturn)) void mc13783_interrupt_thread(void)
78 mc13783_read_regset(status_regs, pending, 2); 83 mc13783_read_regset(status_regs, pending, 2);
79 mc13783_write_regset(status_regs, pending, 2); 84 mc13783_write_regset(status_regs, pending, 2);
80 85
81#if 0 86
82 if (pending[0]) 87 if (pending[0])
83 { 88 {
84 /* Handle ...PENDING0 */ 89 /* Handle ...PENDING0 */
90 if (pending[0] & MC13783_CHGDET)
91 {
92 value = mc13783_read(MC13783_INTERRUPT_SENSE0);
93
94 if (pending[0] & MC13783_CHGDET)
95 set_charger_inserted(value & MC13783_CHGDET);
96 }
85 } 97 }
86#endif 98
87 99
88 if (pending[1]) 100 if (pending[1])
89 { 101 {
diff --git a/firmware/target/arm/imx31/gigabeat-s/power-imx31.c b/firmware/target/arm/imx31/gigabeat-s/power-imx31.c
index f57c55a70b..e51318d16f 100644
--- a/firmware/target/arm/imx31/gigabeat-s/power-imx31.c
+++ b/firmware/target/arm/imx31/gigabeat-s/power-imx31.c
@@ -26,13 +26,21 @@
26 26
27#ifndef SIMULATOR 27#ifndef SIMULATOR
28 28
29static bool charger_detect = false;
30
29void power_init(void) 31void power_init(void)
30{ 32{
31} 33}
32 34
35/* This is called from the mc13783 interrupt thread */
36void set_charger_inserted(bool inserted)
37{
38 charger_detect = inserted;
39}
40
33bool charger_inserted(void) 41bool charger_inserted(void)
34{ 42{
35 return false; 43 return charger_detect;
36} 44}
37 45
38/* Returns true if the unit is charging the batteries. */ 46/* Returns true if the unit is charging the batteries. */
diff --git a/firmware/target/arm/imx31/gigabeat-s/power-imx31.h b/firmware/target/arm/imx31/gigabeat-s/power-imx31.h
new file mode 100644
index 0000000000..f2f6ef8a73
--- /dev/null
+++ b/firmware/target/arm/imx31/gigabeat-s/power-imx31.h
@@ -0,0 +1,21 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id:$
9 *
10 * Copyright (C) 2008 by Nils Wallménius
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20void set_charger_inserted(bool inserted);
21