Classic/6G: hold switch detection using GPIO

Configures GPIO ports to detect holdswitch status instead of
polling the PMU via I2C, this fixes some random crashes

Change-Id: I407c9ca4c2c9203842f9e774b1c8d0455d59048c
Reviewed-on: http://gerrit.rockbox.org/194
Reviewed-by: Michael Giacomelli <giac2000@hotmail.com>
This commit is contained in:
Cástor Muñoz 2012-03-20 23:26:11 +01:00
parent 1d5a505019
commit 7ec426e497

View file

@ -39,7 +39,7 @@
#include "serial.h"
#include "power.h"
#include "powermgmt.h"
#if defined(IPOD_NANO2G) || defined(IPOD_6G)
#ifdef IPOD_NANO2G
#include "pmu-target.h"
#endif
@ -87,11 +87,6 @@ static int int_btn = BUTTON_NONE;
static struct semaphore button_init_wakeup;
#endif
#if CONFIG_CPU==S5L8702
static long holdswitch_last_read;
static bool holdswitch_last_value;
#endif
#ifdef CPU_PP
static void opto_i2c_init(void)
{
@ -367,7 +362,10 @@ static void s5l_clickwheel_init(void)
WHEEL04 |= 1;
PDAT10 &= ~2;
#elif CONFIG_CPU==S5L8702
//TODO: Implement
/* enable external (CY8C21x34) wheel controller */
GPIOCMD = 0xe040f;
/* TODO: enable and init internal (s5l8702) wheel controller */
#endif
}
@ -377,8 +375,9 @@ void button_init_device(void)
#if CONFIG_CPU==S5L8701
INTMSK |= (1<<26);
#elif CONFIG_CPU==S5L8702
holdswitch_last_read = USEC_TIMER;
holdswitch_last_value = (pmu_read(0x87) & 2) == 0;
/* configure GPIO E2 as pull-up input */
GPIOCMD = 0xe0200;
PUNB(14) |= (1 << 2);
#endif
s5l_clickwheel_init();
semaphore_wait(&button_init_wakeup, HZ / 10);
@ -393,15 +392,7 @@ bool button_hold(void)
else PCON15 = (PCON15 & ~0xffff0000) | 0x22220000;
return value;
#elif CONFIG_CPU==S5L8702
if (USEC_TIMER - holdswitch_last_read > 100000)
{
holdswitch_last_read = USEC_TIMER;
holdswitch_last_value = (pmu_read(0x87) & 2) == 0;
}
if (holdswitch_last_value)
PCON(14) = PCON(14) & ~0xffffff00;
else PCON(14) = (PCON(14) & ~0xffffff00) | 0x22222200;
return holdswitch_last_value;
return ((PDATE & (1 << 2)) == 0);
#endif
}
@ -411,7 +402,6 @@ bool headphones_inserted(void)
return ((PDAT14 & (1 << 5)) != 0);
#elif CONFIG_CPU==S5L8702
return ((PDATA & (1 << 6)) != 0);
return false;
#endif
}
#endif
@ -445,7 +435,10 @@ int button_read_device(void)
WHEEL10 = 0;
PWRCONEXT |= 1;
#elif CONFIG_CPU==S5L8702
//TODO: Implement
/* disable external (CY8C21x34) wheel controller */
GPIOCMD = 0xe040e;
/* TODO: disable internal (s5l8702) wheel controller */
#endif
}
else
@ -458,7 +451,7 @@ int button_read_device(void)
pmu_ldo_power_on(1); /* enable clickwheel power supply */
s5l_clickwheel_init();
#elif CONFIG_CPU==S5L8702
//TODO: Implement
s5l_clickwheel_init();
#endif
}
}