summaryrefslogtreecommitdiff
path: root/firmware/target/arm/tcc780x/cowond2/power-cowond2.c
diff options
context:
space:
mode:
authorMichael Giacomelli <giac2000@hotmail.com>2011-11-15 20:37:47 +0000
committerMichael Giacomelli <giac2000@hotmail.com>2011-11-15 20:37:47 +0000
commit3ba0e05ab5b731e09478ed089ff954ad3580be63 (patch)
tree53a6de6fc66e031060ae4a75479c20e8840b37cf /firmware/target/arm/tcc780x/cowond2/power-cowond2.c
parent9e07ef2b0adb8fca7e5a9e516397e533653f8836 (diff)
downloadrockbox-3ba0e05ab5b731e09478ed089ff954ad3580be63.tar.gz
rockbox-3ba0e05ab5b731e09478ed089ff954ad3580be63.zip
Commit FS#12352 by Stanislav Chizhik. Add support for the PCF50635. Enables detection of USB power sources.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30992 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/target/arm/tcc780x/cowond2/power-cowond2.c')
-rw-r--r--firmware/target/arm/tcc780x/cowond2/power-cowond2.c34
1 files changed, 32 insertions, 2 deletions
diff --git a/firmware/target/arm/tcc780x/cowond2/power-cowond2.c b/firmware/target/arm/tcc780x/cowond2/power-cowond2.c
index 7e8f066c58..02e0282ead 100644
--- a/firmware/target/arm/tcc780x/cowond2/power-cowond2.c
+++ b/firmware/target/arm/tcc780x/cowond2/power-cowond2.c
@@ -51,6 +51,10 @@ void power_init(void)
51 pmu = PCF50635; 51 pmu = PCF50635;
52 52
53 pcf50635_init(); 53 pcf50635_init();
54
55 /* Clear pending interrupts from pcf50635 */
56 unsigned char data[5]; /* 0 = INT1, 1 = INT2, 2 = INT3, ... 4 = INT5 */
57 pcf50635_read_multiple(PCF5063X_REG_INT1, data, 5);
54 } 58 }
55 else 59 else
56 { 60 {
@@ -64,11 +68,11 @@ void power_init(void)
64 /* Clear pending interrupts */ 68 /* Clear pending interrupts */
65 unsigned char data[3]; /* 0 = INT1, 1 = INT2, 2 = INT3 */ 69 unsigned char data[3]; /* 0 = INT1, 1 = INT2, 2 = INT3 */
66 pcf50606_read_multiple(0x02, data, 3); 70 pcf50606_read_multiple(0x02, data, 3);
71 }
67 72
68#ifndef BOOTLOADER 73#ifndef BOOTLOADER
69 IEN |= EXT3_IRQ_MASK; /* Unmask EXT3 */ 74 IEN |= EXT3_IRQ_MASK; /* Unmask EXT3 */
70#endif 75#endif
71 }
72} 76}
73 77
74void power_off(void) 78void power_off(void)
@@ -85,6 +89,8 @@ void power_off(void)
85#ifndef BOOTLOADER 89#ifndef BOOTLOADER
86void EXT3(void) 90void EXT3(void)
87{ 91{
92 if (get_pmu_type() == PCF50606)
93 {
88 unsigned char data[3]; /* 0 = INT1, 1 = INT2, 2 = INT3 */ 94 unsigned char data[3]; /* 0 = INT1, 1 = INT2, 2 = INT3 */
89 95
90 /* Clear pending interrupts from pcf50606 */ 96 /* Clear pending interrupts from pcf50606 */
@@ -104,6 +110,21 @@ void EXT3(void)
104 /* Touchscreen event, do something about it */ 110 /* Touchscreen event, do something about it */
105 touchscreen_handle_device_irq(); 111 touchscreen_handle_device_irq();
106 } 112 }
113 }
114 else
115 {
116 unsigned char data[5]; /* 0 = INT1, 1 = INT2, 2 = INT3, ... 4 = INT5 */
117
118 /* Clear pending interrupts from pcf50635 */
119 pcf50635_read_multiple(PCF5063X_REG_INT1, data, 5);
120
121 if (data[2] & PCF5063X_INT3_ONKEY1S)
122 {
123
124 if (!charger_inserted())
125 sys_poweroff();
126 }
127 }
107} 128}
108#endif 129#endif
109 130
@@ -126,7 +147,16 @@ unsigned int power_input_status(void)
126 } 147 }
127 else 148 else
128 { 149 {
129 /* TODO: use adapter/usb connection state from PCF50635 driver */ 150 /* pcf50635 power input status can be obtained from MBCS1 register */
151
152 int mbcs1 = pcf50635_read(PCF5063X_REG_MBCS1);
153 /* Check AC adapter presence*/
154 if (mbcs1 & PCF5063X_MBCS1_ADAPTPRES)
155 return POWER_INPUT_MAIN_CHARGER;
156
157 /* Check USB presence */
158 if (mbcs1 & PCF5063X_MBCS1_USBPRES)
159 return POWER_INPUT_USB_CHARGER;
130 } 160 }
131 161
132 return POWER_INPUT_NONE; 162 return POWER_INPUT_NONE;