steve-m has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/osmocom-bb/+/15149


Change subject: fw/abb/twl3025: Add function to query PWON state
......................................................................

fw/abb/twl3025: Add function to query PWON state

This allows us to detect power button presses on the Pirelli
DP-L10 and the Huawei GTM900-B module. Polling will only be
activated once the power button has been pressed and we received
the interrupt. The goal is to reduce the required amount of
TWL3025 register accesses to a minimum.

Change-Id: I31be61c8089173aed616abd1ede6c4cf5c9b6770
---
M src/target/firmware/abb/twl3025.c
M src/target/firmware/include/abb/twl3025.h
2 files changed, 30 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/49/15149/1

diff --git a/src/target/firmware/abb/twl3025.c 
b/src/target/firmware/abb/twl3025.c
index e4fcf4f..ad2b01f 100644
--- a/src/target/firmware/abb/twl3025.c
+++ b/src/target/firmware/abb/twl3025.c
@@ -60,8 +60,15 @@
        ABB_RAMP_VAL( 0,  0),
 };

+typedef enum pwon_state {
+       PWON_IDLE,
+       PWON_DETECTED,
+       PWON_REPORTED,
+} pwon_state_t;
+
 struct twl3025 {
        uint8_t page;
+       pwon_state_t pwon;
 };
 static struct twl3025 twl3025_state;

@@ -106,6 +113,8 @@
        case IRQ_EXTERNAL: // charger in/out, pwrbtn, adc done
                src = twl3025_reg_read(ITSTATREG);
 //             printd("itstatreg 0x%02x\n", src);
+               if ((src & 0x04) && twl3025_state.pwon == PWON_IDLE)
+                       twl3025_state.pwon = PWON_DETECTED;
                if (src & 0x08)
                        handle_charger();
                if (src & 0x20)
@@ -127,6 +136,7 @@
        twl3025_clk13m(1);
        twl3025_reg_write(AFCCTLADD, 0x01);     /* AFCCK(1:0) must not be zero! 
*/
        twl3025_unit_enable(TWL3025_UNIT_AFC, 1);
+       twl3025_state.pwon = PWON_IDLE;

        irq_register_handler(IRQ_EXTERNAL, &twl3025_irq);
        irq_config(IRQ_EXTERNAL, 0, 0, 0);
@@ -185,6 +195,24 @@
        delay_ms(1);
 }

+int twl3025_get_pwon(void)
+{
+       switch (twl3025_state.pwon) {
+       case PWON_DETECTED:
+               twl3025_state.pwon = PWON_REPORTED;
+               break;
+       case PWON_REPORTED:
+               if (twl3025_reg_read(VRPCSTS) & 0x10)
+                       twl3025_state.pwon = PWON_IDLE;
+               break;
+       case PWON_IDLE:
+       default:
+               break;
+       }
+
+       return (twl3025_state.pwon != PWON_IDLE);
+}
+
 void twl3025_power_off(void)
 {
        unsigned long flags;
diff --git a/src/target/firmware/include/abb/twl3025.h 
b/src/target/firmware/include/abb/twl3025.h
index 3640644..938a425 100755
--- a/src/target/firmware/include/abb/twl3025.h
+++ b/src/target/firmware/include/abb/twl3025.h
@@ -144,6 +144,8 @@
 void twl3025_reg_write(uint8_t reg, uint16_t data);
 uint16_t twl3025_reg_read(uint8_t reg);

+int twl3025_get_pwon(void);
+
 void twl3025_power_off(void);
 
 void twl3025_clk13m(int enable);

--
To view, visit https://gerrit.osmocom.org/c/osmocom-bb/+/15149
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-Change-Id: I31be61c8089173aed616abd1ede6c4cf5c9b6770
Gerrit-Change-Number: 15149
Gerrit-PatchSet: 1
Gerrit-Owner: steve-m <[email protected]>
Gerrit-MessageType: newchange

Reply via email to