diff options
Diffstat (limited to 'firmware/target/arm/imx31/gigabeat-s')
6 files changed, 57 insertions, 47 deletions
diff --git a/firmware/target/arm/imx31/gigabeat-s/adc-gigabeat-s.c b/firmware/target/arm/imx31/gigabeat-s/adc-gigabeat-s.c index eb30919077..b46fc2f63f 100644 --- a/firmware/target/arm/imx31/gigabeat-s/adc-gigabeat-s.c +++ b/firmware/target/arm/imx31/gigabeat-s/adc-gigabeat-s.c | |||
@@ -110,7 +110,7 @@ bool adc_enable_channel(int channel, bool enable) | |||
110 | != MC13783_DATA_ERROR; | 110 | != MC13783_DATA_ERROR; |
111 | } | 111 | } |
112 | 112 | ||
113 | /* Called by mc13783 interrupt thread when conversion is complete */ | 113 | /* ADC conversion complete event - called from PMIC ISR */ |
114 | void adc_done(void) | 114 | void adc_done(void) |
115 | { | 115 | { |
116 | semaphore_release(&adc_done_signal); | 116 | semaphore_release(&adc_done_signal); |
@@ -132,5 +132,5 @@ void adc_init(void) | |||
132 | 132 | ||
133 | /* Enable ADCDONE event */ | 133 | /* Enable ADCDONE event */ |
134 | mc13783_write(MC13783_INTERRUPT_STATUS0, MC13783_ADCDONEI); | 134 | mc13783_write(MC13783_INTERRUPT_STATUS0, MC13783_ADCDONEI); |
135 | mc13783_enable_event(MC13783_ADCDONE_EVENT); | 135 | mc13783_enable_event(MC13783_ADCDONE_EVENT, true); |
136 | } | 136 | } |
diff --git a/firmware/target/arm/imx31/gigabeat-s/button-gigabeat-s.c b/firmware/target/arm/imx31/gigabeat-s/button-gigabeat-s.c index 90db00dcc3..11d1d5a0b4 100644 --- a/firmware/target/arm/imx31/gigabeat-s/button-gigabeat-s.c +++ b/firmware/target/arm/imx31/gigabeat-s/button-gigabeat-s.c | |||
@@ -35,7 +35,7 @@ | |||
35 | static bool initialized = false; | 35 | static bool initialized = false; |
36 | #endif | 36 | #endif |
37 | 37 | ||
38 | static int ext_btn = BUTTON_NONE; /* Buttons not on KPP */ | 38 | static unsigned long ext_btn = BUTTON_NONE; /* Buttons not on KPP */ |
39 | static bool hold_button = false; | 39 | static bool hold_button = false; |
40 | #ifndef BOOTLOADER | 40 | #ifndef BOOTLOADER |
41 | static bool hold_button_old = false; | 41 | static bool hold_button_old = false; |
@@ -150,24 +150,16 @@ int button_read_device(void) | |||
150 | #endif | 150 | #endif |
151 | } | 151 | } |
152 | 152 | ||
153 | /* This is called from the mc13783 interrupt thread */ | 153 | /* Helper to update the power button status */ |
154 | void button_power_event(void) | 154 | static void power_button_update(bool pressed) |
155 | { | 155 | { |
156 | bool pressed = | 156 | bitmod32(&ext_btn, pressed ? BUTTON_POWER : 0, BUTTON_POWER); |
157 | (mc13783_read(MC13783_INTERRUPT_SENSE1) & MC13783_ONOFD1S) == 0; | 157 | } |
158 | |||
159 | int oldlevel = disable_irq_save(); | ||
160 | |||
161 | if (pressed) | ||
162 | { | ||
163 | ext_btn |= BUTTON_POWER; | ||
164 | } | ||
165 | else | ||
166 | { | ||
167 | ext_btn &= ~BUTTON_POWER; | ||
168 | } | ||
169 | 158 | ||
170 | restore_irq(oldlevel); | 159 | /* Power button event - called from PMIC ISR */ |
160 | void button_power_event(void) | ||
161 | { | ||
162 | power_button_update(!mc13783_event_sense(MC13783_ONOFD1_EVENT)); | ||
171 | } | 163 | } |
172 | 164 | ||
173 | void button_init_device(void) | 165 | void button_init_device(void) |
@@ -203,8 +195,9 @@ void button_init_device(void) | |||
203 | * 6. Set the KDIE control bit bit. */ | 195 | * 6. Set the KDIE control bit bit. */ |
204 | KPP_KPSR = KPP_KPSR_KRSS | KPP_KPSR_KDSC | KPP_KPSR_KPKD; | 196 | KPP_KPSR = KPP_KPSR_KRSS | KPP_KPSR_KDSC | KPP_KPSR_KPKD; |
205 | 197 | ||
206 | button_power_event(); | 198 | power_button_update(!(mc13783_read(MC13783_INTERRUPT_SENSE1) |
207 | mc13783_enable_event(MC13783_ONOFD1_EVENT); | 199 | & MC13783_ONOFD1S)); |
200 | mc13783_enable_event(MC13783_ONOFD1_EVENT, true); | ||
208 | 201 | ||
209 | #ifdef HAVE_HEADPHONE_DETECTION | 202 | #ifdef HAVE_HEADPHONE_DETECTION |
210 | headphone_init(); | 203 | headphone_init(); |
@@ -220,7 +213,7 @@ void button_close_device(void) | |||
220 | /* Assumes HP detection is not available */ | 213 | /* Assumes HP detection is not available */ |
221 | initialized = false; | 214 | initialized = false; |
222 | 215 | ||
223 | mc13783_disable_event(MC13783_ONOFD1_EVENT); | 216 | mc13783_enable_event(MC13783_ONOFD1_EVENT, true); |
224 | ext_btn = BUTTON_NONE; | 217 | ext_btn = BUTTON_NONE; |
225 | } | 218 | } |
226 | #endif /* BUTTON_DRIVER_CLOSE */ | 219 | #endif /* BUTTON_DRIVER_CLOSE */ |
diff --git a/firmware/target/arm/imx31/gigabeat-s/headphone-gigabeat-s.c b/firmware/target/arm/imx31/gigabeat-s/headphone-gigabeat-s.c index 6e76615308..4e1792d467 100644 --- a/firmware/target/arm/imx31/gigabeat-s/headphone-gigabeat-s.c +++ b/firmware/target/arm/imx31/gigabeat-s/headphone-gigabeat-s.c | |||
@@ -171,7 +171,7 @@ static void headphone_thread(void) | |||
171 | } | 171 | } |
172 | } | 172 | } |
173 | 173 | ||
174 | /* This is called from the mc13783 interrupt thread */ | 174 | /* HP plugged/unplugged event - called from PMIC ISR */ |
175 | void headphone_detect_event(void) | 175 | void headphone_detect_event(void) |
176 | { | 176 | { |
177 | /* Trigger the thread immediately. */ | 177 | /* Trigger the thread immediately. */ |
@@ -197,5 +197,5 @@ void INIT_ATTR headphone_init(void) | |||
197 | 197 | ||
198 | /* Initially poll and then enable PMIC event */ | 198 | /* Initially poll and then enable PMIC event */ |
199 | headphone_detect_event(); | 199 | headphone_detect_event(); |
200 | mc13783_enable_event(MC13783_ONOFD2_EVENT); | 200 | mc13783_enable_event(MC13783_ONOFD2_EVENT, true); |
201 | } | 201 | } |
diff --git a/firmware/target/arm/imx31/gigabeat-s/mc13783-gigabeat-s.c b/firmware/target/arm/imx31/gigabeat-s/mc13783-gigabeat-s.c index 12009fae06..6ae8c23c48 100644 --- a/firmware/target/arm/imx31/gigabeat-s/mc13783-gigabeat-s.c +++ b/firmware/target/arm/imx31/gigabeat-s/mc13783-gigabeat-s.c | |||
@@ -55,28 +55,33 @@ const struct mc13783_event mc13783_events[MC13783_NUM_EVENTS] = | |||
55 | { | 55 | { |
56 | [MC13783_ADCDONE_EVENT] = /* ADC conversion complete */ | 56 | [MC13783_ADCDONE_EVENT] = /* ADC conversion complete */ |
57 | { | 57 | { |
58 | .int_id = MC13783_INT_ID_ADCDONE, | 58 | .int_id = MC13783_INT_ID_ADCDONE, |
59 | .sense = 0, | ||
59 | .callback = adc_done, | 60 | .callback = adc_done, |
60 | }, | 61 | }, |
61 | [MC13783_ONOFD1_EVENT] = /* Power button */ | 62 | [MC13783_ONOFD1_EVENT] = /* Power button */ |
62 | { | 63 | { |
63 | .int_id = MC13783_INT_ID_ONOFD1, | 64 | .int_id = MC13783_INT_ID_ONOFD1, |
65 | .sense = MC13783_ONOFD1S, | ||
64 | .callback = button_power_event, | 66 | .callback = button_power_event, |
65 | }, | 67 | }, |
66 | [MC13783_SE1_EVENT] = /* Main charger detection */ | 68 | [MC13783_SE1_EVENT] = /* Main charger detection */ |
67 | { | 69 | { |
68 | .int_id = MC13783_INT_ID_SE1, | 70 | .int_id = MC13783_INT_ID_SE1, |
71 | .sense = MC13783_SE1S, | ||
69 | .callback = charger_main_detect_event, | 72 | .callback = charger_main_detect_event, |
70 | }, | 73 | }, |
71 | [MC13783_USB_EVENT] = /* USB insertion/USB charger detection */ | 74 | [MC13783_USB_EVENT] = /* USB insertion/USB charger detection */ |
72 | { | 75 | { |
73 | .int_id = MC13783_INT_ID_USB, | 76 | .int_id = MC13783_INT_ID_USB, |
77 | .sense = MC13783_USB4V4S, | ||
74 | .callback = usb_connect_event, | 78 | .callback = usb_connect_event, |
75 | }, | 79 | }, |
76 | #ifdef HAVE_HEADPHONE_DETECTION | 80 | #ifdef HAVE_HEADPHONE_DETECTION |
77 | [MC13783_ONOFD2_EVENT] = /* Headphone jack */ | 81 | [MC13783_ONOFD2_EVENT] = /* Headphone jack */ |
78 | { | 82 | { |
79 | .int_id = MC13783_INT_ID_ONOFD2, | 83 | .int_id = MC13783_INT_ID_ONOFD2, |
84 | .sense = 0, | ||
80 | .callback = headphone_detect_event, | 85 | .callback = headphone_detect_event, |
81 | }, | 86 | }, |
82 | #endif | 87 | #endif |
diff --git a/firmware/target/arm/imx31/gigabeat-s/power-gigabeat-s.c b/firmware/target/arm/imx31/gigabeat-s/power-gigabeat-s.c index 11276a6c3a..5b255a0e27 100644 --- a/firmware/target/arm/imx31/gigabeat-s/power-gigabeat-s.c +++ b/firmware/target/arm/imx31/gigabeat-s/power-gigabeat-s.c | |||
@@ -33,7 +33,7 @@ | |||
33 | #include "fmradio_i2c.h" | 33 | #include "fmradio_i2c.h" |
34 | #endif | 34 | #endif |
35 | 35 | ||
36 | static unsigned int power_status = POWER_INPUT_NONE; | 36 | static unsigned long power_status = POWER_INPUT_NONE; |
37 | 37 | ||
38 | /* Detect which power sources are present. */ | 38 | /* Detect which power sources are present. */ |
39 | unsigned int power_input_status(void) | 39 | unsigned int power_input_status(void) |
@@ -58,24 +58,28 @@ void usb_charging_maxcurrent_change(int maxcurrent) | |||
58 | /* Nothing to do */ | 58 | /* Nothing to do */ |
59 | } | 59 | } |
60 | 60 | ||
61 | /* Detect changes in presence of the AC adaptor. */ | 61 | /* Helper to update the charger status */ |
62 | static void update_main_charger(bool present) | ||
63 | { | ||
64 | bitmod32(&power_status, present ? POWER_INPUT_MAIN_CHARGER : 0, | ||
65 | POWER_INPUT_MAIN_CHARGER); | ||
66 | } | ||
67 | |||
68 | /* Detect changes in presence of the AC adaptor. Called from PMIC ISR. */ | ||
62 | void charger_main_detect_event(void) | 69 | void charger_main_detect_event(void) |
63 | { | 70 | { |
64 | if (mc13783_read(MC13783_INTERRUPT_SENSE0) & MC13783_SE1S) | 71 | update_main_charger(mc13783_event_sense(MC13783_INT_ID_SE1) |
65 | power_status |= POWER_INPUT_MAIN_CHARGER; | 72 | & MC13783_SE1S); |
66 | else | ||
67 | power_status &= ~POWER_INPUT_MAIN_CHARGER; | ||
68 | } | 73 | } |
69 | 74 | ||
70 | /* Detect changes in USB bus power. Called from usb connect event handler. */ | 75 | /* Detect changes in USB bus power. Called from usb connect event ISR. */ |
71 | void charger_usb_detect_event(int status) | 76 | void charger_usb_detect_event(int status) |
72 | { | 77 | { |
73 | /* USB plugged does not imply charging is possible or even | 78 | /* USB plugged does not imply charging is possible or even |
74 | * powering the device to maintain the battery. */ | 79 | * powering the device to maintain the battery. */ |
75 | if (status == USB_INSERTED) | 80 | bitmod32(&power_status, |
76 | power_status |= POWER_INPUT_USB_CHARGER; | 81 | status == USB_INSERTED ? POWER_INPUT_USB_CHARGER : 0, |
77 | else | 82 | POWER_INPUT_USB_CHARGER); |
78 | power_status &= ~POWER_INPUT_USB_CHARGER; | ||
79 | } | 83 | } |
80 | 84 | ||
81 | /* charging_state is implemented in powermgmt-imx31.c */ | 85 | /* charging_state is implemented in powermgmt-imx31.c */ |
@@ -152,8 +156,9 @@ void power_init(void) | |||
152 | #endif | 156 | #endif |
153 | 157 | ||
154 | /* Poll initial state */ | 158 | /* Poll initial state */ |
155 | charger_main_detect_event(); | 159 | update_main_charger(mc13783_read(MC13783_INTERRUPT_SENSE0) |
160 | & MC13783_SE1S); | ||
156 | 161 | ||
157 | /* Enable detect event */ | 162 | /* Enable detect event */ |
158 | mc13783_enable_event(MC13783_SE1_EVENT); | 163 | mc13783_enable_event(MC13783_SE1_EVENT, true); |
159 | } | 164 | } |
diff --git a/firmware/target/arm/imx31/gigabeat-s/usb-gigabeat-s.c b/firmware/target/arm/imx31/gigabeat-s/usb-gigabeat-s.c index b157544016..1584ffb574 100644 --- a/firmware/target/arm/imx31/gigabeat-s/usb-gigabeat-s.c +++ b/firmware/target/arm/imx31/gigabeat-s/usb-gigabeat-s.c | |||
@@ -59,16 +59,23 @@ bool usb_plugged(void) | |||
59 | return mc13783_read(MC13783_INTERRUPT_SENSE0) & MC13783_USB4V4S; | 59 | return mc13783_read(MC13783_INTERRUPT_SENSE0) & MC13783_USB4V4S; |
60 | } | 60 | } |
61 | 61 | ||
62 | void usb_connect_event(void) | 62 | /* Helper to update the USB cable status */ |
63 | static void update_usb_status(bool sense) | ||
63 | { | 64 | { |
64 | /* Read the immediate state of the cable from the PMIC */ | 65 | int status = sense ? USB_INSERTED : USB_EXTRACTED; |
65 | int status = usb_plugged() ? USB_INSERTED : USB_EXTRACTED; | ||
66 | usb_status = status; | 66 | usb_status = status; |
67 | /* Notify power that USB charging is potentially available */ | 67 | /* Notify power that USB charging is potentially available */ |
68 | charger_usb_detect_event(status); | 68 | charger_usb_detect_event(status); |
69 | usb_status_event(status); | 69 | usb_status_event(status); |
70 | } | 70 | } |
71 | 71 | ||
72 | /* Detect presence of USB bus - called from PMIC ISR */ | ||
73 | void usb_connect_event(void) | ||
74 | { | ||
75 | /* Read the associated sense value */ | ||
76 | update_usb_status(mc13783_event_sense(MC13783_USB_EVENT)); | ||
77 | } | ||
78 | |||
72 | int usb_detect(void) | 79 | int usb_detect(void) |
73 | { | 80 | { |
74 | return usb_status; | 81 | return usb_status; |
@@ -80,10 +87,10 @@ void usb_init_device(void) | |||
80 | usb_drv_startup(); | 87 | usb_drv_startup(); |
81 | 88 | ||
82 | /* Initially poll */ | 89 | /* Initially poll */ |
83 | usb_connect_event(); | 90 | update_usb_status(usb_plugged()); |
84 | 91 | ||
85 | /* Enable PMIC event */ | 92 | /* Enable PMIC event */ |
86 | mc13783_enable_event(MC13783_USB_EVENT); | 93 | mc13783_enable_event(MC13783_USB_EVENT, true); |
87 | } | 94 | } |
88 | 95 | ||
89 | void usb_enable(bool on) | 96 | void usb_enable(bool on) |