summaryrefslogtreecommitdiff
path: root/firmware/target/coldfire/iriver/h300
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/coldfire/iriver/h300')
-rw-r--r--firmware/target/coldfire/iriver/h300/button-h300.c19
-rw-r--r--firmware/target/coldfire/iriver/h300/pcf50606-h300.c61
2 files changed, 76 insertions, 4 deletions
diff --git a/firmware/target/coldfire/iriver/h300/button-h300.c b/firmware/target/coldfire/iriver/h300/button-h300.c
index 80210b6c19..bcd954df8a 100644
--- a/firmware/target/coldfire/iriver/h300/button-h300.c
+++ b/firmware/target/coldfire/iriver/h300/button-h300.c
@@ -27,9 +27,10 @@
27#include "backlight.h" 27#include "backlight.h"
28#include "adc.h" 28#include "adc.h"
29#include "system.h" 29#include "system.h"
30#ifdef HAVE_REMOTE_LCD
31#include "lcd-remote.h" 30#include "lcd-remote.h"
32#endif 31
32/* have buttons scan by default */
33static bool button_scan_on = true;
33 34
34void button_init_device(void) 35void button_init_device(void)
35{ 36{
@@ -41,13 +42,23 @@ void button_init_device(void)
41 GPIO1_FUNCTION |= 0x00100062; 42 GPIO1_FUNCTION |= 0x00100062;
42} 43}
43 44
45void button_enable_scan(bool enable)
46{
47 button_scan_on = enable;
48}
49
50bool button_scan_enabled(void)
51{
52 return button_scan_on;
53}
54
44bool button_hold(void) 55bool button_hold(void)
45{ 56{
46 return (GPIO1_READ & 0x00000002)?true:false; 57 return (GPIO1_READ & 0x00000002)?true:false;
47} 58}
48 59
49bool remote_button_hold_only(void) 60bool remote_button_hold_only(void)
50{ 61{
51 if(remote_type() == REMOTETYPE_H300_NONLCD) 62 if(remote_type() == REMOTETYPE_H300_NONLCD)
52 return adc_scan(ADC_REMOTE)<0x0d; /* hold should be 0x00 */ 63 return adc_scan(ADC_REMOTE)<0x0d; /* hold should be 0x00 */
53 else 64 else
@@ -88,7 +99,7 @@ int button_read_device(void)
88 backlight_hold_changed(hold_button); 99 backlight_hold_changed(hold_button);
89#endif 100#endif
90 101
91 if (!hold_button) 102 if (button_scan_on && !hold_button)
92 { 103 {
93 data = adc_scan(ADC_BUTTONS); 104 data = adc_scan(ADC_BUTTONS);
94 105
diff --git a/firmware/target/coldfire/iriver/h300/pcf50606-h300.c b/firmware/target/coldfire/iriver/h300/pcf50606-h300.c
index c990f5ddcb..3a67d541d3 100644
--- a/firmware/target/coldfire/iriver/h300/pcf50606-h300.c
+++ b/firmware/target/coldfire/iriver/h300/pcf50606-h300.c
@@ -20,6 +20,7 @@
20#include "system.h" 20#include "system.h"
21#include "kernel.h" 21#include "kernel.h"
22#include "pcf50606.h" 22#include "pcf50606.h"
23#include "button-target.h"
23 24
24/* These voltages were determined by measuring the output of the PCF50606 25/* These voltages were determined by measuring the output of the PCF50606
25 on a running H300, and verified by disassembling the original firmware */ 26 on a running H300, and verified by disassembling the original firmware */
@@ -37,10 +38,44 @@ static void set_voltages(void)
37 pcf50606_write_multiple(0x23, buf, 5); 38 pcf50606_write_multiple(0x23, buf, 5);
38} 39}
39 40
41static void init_pmu_interrupts(void)
42{
43 /* inital data is interrupt masks */
44 unsigned char data[3] =
45 {
46 ~0x00,
47 ~0x00,
48 ~0x06, /* unmask ACDREM, ACDINS */
49 };
50
51 /* make sure GPI6 interrupt is off before unmasking anything */
52 and_l(~0x0f000000, &INTPRI5); /* INT38 - Priority 0 (Off) */
53
54 /* unmask the PMU interrupts we want to service */
55 pcf50606_write_multiple(0x05, data, 3);
56 /* clear INT1-3 as these are left set after standby */
57 pcf50606_read_multiple(0x02, data, 3);
58
59 /* Set to read pcf50606 INT but keep GPI6 off until init completes */
60 and_l(~0x00000040, &GPIO_ENABLE);
61 or_l(0x00000040, &GPIO_FUNCTION);
62 or_l(0x00004000, &GPIO_INT_EN); /* GPI6 H-L */
63}
64
65static inline void enable_pmu_interrupts(void)
66{
67 /* clear pending GPI6 interrupts first or it may miss the first
68 H-L transition */
69 or_l(0x00004000, &GPIO_INT_CLEAR);
70 or_l(0x03000000, &INTPRI5); /* INT38 - Priority 3 */
71}
72
40void pcf50606_init(void) 73void pcf50606_init(void)
41{ 74{
42 pcf50606_i2c_init(); 75 pcf50606_i2c_init();
43 76
77 /* initialize pmu interrupts but don't service them yet */
78 init_pmu_interrupts();
44 set_voltages(); 79 set_voltages();
45 80
46 pcf50606_write(0x08, 0x60); /* Wake on USB and charger insertion */ 81 pcf50606_write(0x08, 0x60); /* Wake on USB and charger insertion */
@@ -49,4 +84,30 @@ void pcf50606_init(void)
49 84
50 pcf50606_write(0x35, 0x13); /* Backlight PWM = 512Hz 50/50 */ 85 pcf50606_write(0x35, 0x13); /* Backlight PWM = 512Hz 50/50 */
51 pcf50606_write(0x3a, 0x3b); /* PWM output on GPOOD1 */ 86 pcf50606_write(0x3a, 0x3b); /* PWM output on GPOOD1 */
87
88 pcf50606_write(0x33, 0x8c); /* Accessory detect: ACDAPE=1, THRSHLD=2.20V */
89
90 enable_pmu_interrupts(); /* allow GPI6 interrupts from PMU now */
91}
92
93/* PMU interrupt */
94void GPI6(void) __attribute__ ((interrupt_handler));
95void GPI6(void)
96{
97 unsigned char data[3]; /* 0 = INT1, 1 = INT2, 2 = INT3 */
98
99 /* Clear pending GPI6 interrupts */
100 or_l(0x00004000, &GPIO_INT_CLEAR);
101
102 /* clear pending interrupts from pcf50606 */
103 pcf50606_read_multiple(0x02, data, 3);
104
105 if (data[2] & 0x06)
106 {
107 /* ACDINS/ACDREM */
108 /* Check if the button driver should actually scan main buttons or not
109 - bias towards "yes" out of paranoia. */
110 button_enable_scan((data[2] & 0x02) != 0 ||
111 (pcf50606_read(0x33) & 0x01) != 0);
112 }
52} 113}