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
This commit is contained in:
parent
a1de51d357
commit
da7cd7408a
|
@ -60,8 +60,15 @@ const uint16_t twl3025_default_ramp[16] = {
|
|||
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 @@ static void twl3025_irq(enum irq_nr nr)
|
|||
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 @@ void twl3025_init(void)
|
|||
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 @@ static void twl3025_wait_ibic_access(void)
|
|||
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;
|
||||
|
|
|
@ -144,6 +144,8 @@ void twl3025_init(void);
|
|||
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);
|
||||
|
|
Loading…
Reference in New Issue