summaryrefslogtreecommitdiff
path: root/firmware/target/arm/imx31/gigabeat-s
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2008-05-10 18:00:11 +0000
committerMichael Sevakis <jethead71@rockbox.org>2008-05-10 18:00:11 +0000
commit80278e45aa79cee66596c257c5d3870765233e00 (patch)
tree3a974d996f2bcf7f176175c904cf22edf9132ac9 /firmware/target/arm/imx31/gigabeat-s
parent6e812b1d2e7941ee1f3e7abdbc2a2eba601f17e3 (diff)
downloadrockbox-80278e45aa79cee66596c257c5d3870765233e00.tar.gz
rockbox-80278e45aa79cee66596c257c5d3870765233e00.zip
Bring Gigabeat S bootloader one step close to a release version.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@17442 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/target/arm/imx31/gigabeat-s')
-rw-r--r--firmware/target/arm/imx31/gigabeat-s/ata-target.h4
-rw-r--r--firmware/target/arm/imx31/gigabeat-s/backlight-imx31.c4
-rw-r--r--firmware/target/arm/imx31/gigabeat-s/backlight-target.h8
-rw-r--r--firmware/target/arm/imx31/gigabeat-s/button-imx31.c38
-rw-r--r--firmware/target/arm/imx31/gigabeat-s/button-target.h7
-rw-r--r--firmware/target/arm/imx31/gigabeat-s/mc13783-imx31.c48
-rw-r--r--firmware/target/arm/imx31/gigabeat-s/system-imx31.c1
-rw-r--r--firmware/target/arm/imx31/gigabeat-s/usb-target.h4
8 files changed, 102 insertions, 12 deletions
diff --git a/firmware/target/arm/imx31/gigabeat-s/ata-target.h b/firmware/target/arm/imx31/gigabeat-s/ata-target.h
index 6428e9f41f..8f8083dc8d 100644
--- a/firmware/target/arm/imx31/gigabeat-s/ata-target.h
+++ b/firmware/target/arm/imx31/gigabeat-s/ata-target.h
@@ -19,6 +19,10 @@
19#ifndef ATA_TARGET_H 19#ifndef ATA_TARGET_H
20#define ATA_TARGET_H 20#define ATA_TARGET_H
21 21
22#ifdef BOOTLOADER
23#define ATA_DRIVER_CLOSE
24#endif
25
22/* Plain C read & write loops */ 26/* Plain C read & write loops */
23#define PREFER_C_READING 27#define PREFER_C_READING
24#define PREFER_C_WRITING 28#define PREFER_C_WRITING
diff --git a/firmware/target/arm/imx31/gigabeat-s/backlight-imx31.c b/firmware/target/arm/imx31/gigabeat-s/backlight-imx31.c
index 4df9be843c..b35e3c1ad0 100644
--- a/firmware/target/arm/imx31/gigabeat-s/backlight-imx31.c
+++ b/firmware/target/arm/imx31/gigabeat-s/backlight-imx31.c
@@ -22,6 +22,7 @@
22#include "mc13783.h" 22#include "mc13783.h"
23#include "backlight-target.h" 23#include "backlight-target.h"
24 24
25#ifdef HAVE_BACKLIGHT_BRIGHTNESS
25/* Table that uses combinations of current level and pwm fraction to get 26/* Table that uses combinations of current level and pwm fraction to get
26 * as many uniquely-visible brightness levels as possible. The lowest current 27 * as many uniquely-visible brightness levels as possible. The lowest current
27 * level for any average current is used even though many combinations give 28 * level for any average current is used even though many combinations give
@@ -60,6 +61,7 @@ static const struct
60 { 3, 12 }, /* 9 12 7.2 */ 61 { 3, 12 }, /* 9 12 7.2 */
61 /* Anything higher is just too much */ 62 /* Anything higher is just too much */
62}; 63};
64#endif /* HAVE_BACKLIGHT_BRIGHTNESS */
63 65
64bool _backlight_init(void) 66bool _backlight_init(void)
65{ 67{
@@ -85,6 +87,7 @@ void _backlight_off(void)
85 mc13783_clear(MC13783_LED_CONTROL0, MC13783_LEDEN); 87 mc13783_clear(MC13783_LED_CONTROL0, MC13783_LEDEN);
86} 88}
87 89
90#ifdef HAVE_BACKLIGHT_BRIGHTNESS
88/* Assumes that the backlight has been initialized */ 91/* Assumes that the backlight has been initialized */
89void _backlight_set_brightness(int brightness) 92void _backlight_set_brightness(int brightness)
90{ 93{
@@ -106,3 +109,4 @@ void _backlight_set_brightness(int brightness)
106 109
107 mc13783_write(MC13783_LED_CONTROL2, data); 110 mc13783_write(MC13783_LED_CONTROL2, data);
108} 111}
112#endif /* HAVE_BACKLIGHT_BRIGHTNESS */
diff --git a/firmware/target/arm/imx31/gigabeat-s/backlight-target.h b/firmware/target/arm/imx31/gigabeat-s/backlight-target.h
index 7c4b2fa0fd..145df0d930 100644
--- a/firmware/target/arm/imx31/gigabeat-s/backlight-target.h
+++ b/firmware/target/arm/imx31/gigabeat-s/backlight-target.h
@@ -19,11 +19,15 @@
19#ifndef BACKLIGHT_TARGET_H 19#ifndef BACKLIGHT_TARGET_H
20#define BACKLIGHT_TARGET_H 20#define BACKLIGHT_TARGET_H
21 21
22#ifdef BOOTLOADER
23#define BACKLIGHT_DRIVER_CLOSE
24/* Force the whole driver to be built */
25#define BACKLIGHT_FULL_INIT
26#endif
27
22bool _backlight_init(void); 28bool _backlight_init(void);
23void _backlight_on(void); 29void _backlight_on(void);
24void _backlight_off(void); 30void _backlight_off(void);
25void _backlight_set_brightness(int brightness); 31void _backlight_set_brightness(int brightness);
26 32
27/* true: backlight fades off - false: backlight fades on */
28void __backlight_dim(bool dim);
29#endif 33#endif
diff --git a/firmware/target/arm/imx31/gigabeat-s/button-imx31.c b/firmware/target/arm/imx31/gigabeat-s/button-imx31.c
index e80166bca7..746883d010 100644
--- a/firmware/target/arm/imx31/gigabeat-s/button-imx31.c
+++ b/firmware/target/arm/imx31/gigabeat-s/button-imx31.c
@@ -29,11 +29,16 @@
29 29
30/* Most code in here is taken from the Linux BSP provided by Freescale 30/* Most code in here is taken from the Linux BSP provided by Freescale
31 * Copyright 2004-2006 Freescale Semiconductor, Inc. All Rights Reserved. */ 31 * Copyright 2004-2006 Freescale Semiconductor, Inc. All Rights Reserved. */
32 32#ifdef HAVE_HEADPHONE_DETECTION
33static bool headphones_detect = false; 33static bool headphones_detect = false;
34#endif
34static uint32_t int_btn = BUTTON_NONE; 35static uint32_t int_btn = BUTTON_NONE;
35static bool hold_button = false; 36static bool hold_button = false;
37#ifdef BOOTLOADER
38static bool initialized = false;
39#else
36static bool hold_button_old = false; 40static bool hold_button_old = false;
41#endif
37#define _button_hold() (GPIO3_DR & 0x10) 42#define _button_hold() (GPIO3_DR & 0x10)
38 43
39static __attribute__((interrupt("IRQ"))) void KPP_HANDLER(void) 44static __attribute__((interrupt("IRQ"))) void KPP_HANDLER(void)
@@ -116,6 +121,14 @@ static __attribute__((interrupt("IRQ"))) void KPP_HANDLER(void)
116 121
117void button_init_device(void) 122void button_init_device(void)
118{ 123{
124#ifdef BOOTLOADER
125 /* Can be called more than once in the bootloader */
126 if (initialized)
127 return;
128
129 initialized = true;
130#endif
131
119 /* Enable keypad clock */ 132 /* Enable keypad clock */
120 imx31_clkctl_module_clock_gating(CG_KPP, CGM_ON_ALL); 133 imx31_clkctl_module_clock_gating(CG_KPP, CGM_ON_ALL);
121 134
@@ -136,15 +149,26 @@ void button_init_device(void)
136 KPP_KDDR = (KPP_KDDR | (0x7 << 8)) & ~0x1f; 149 KPP_KDDR = (KPP_KDDR | (0x7 << 8)) & ~0x1f;
137 150
138 /* 5. Clear the KPKD Status Flag and Synchronizer chain. 151 /* 5. Clear the KPKD Status Flag and Synchronizer chain.
139 * 6. Set the KDIE control bit, and set the KRIE control 152 * 6. Set the KDIE control bit bit. */
140 * bit (to force immediate scan). */ 153 KPP_KPSR = KPP_KPSR_KDIE | KPP_KPSR_KRSS | KPP_KPSR_KDSC | KPP_KPSR_KPKD;
141 KPP_KPSR = KPP_KPSR_KRIE | KPP_KPSR_KDIE | KPP_KPSR_KRSS |
142 KPP_KPSR_KDSC | KPP_KPSR_KPKR | KPP_KPSR_KPKD;
143 154
144 /* KPP IRQ at priority 3 */ 155 /* KPP IRQ at priority 3 */
145 avic_enable_int(KPP, IRQ, 3, KPP_HANDLER); 156 avic_enable_int(KPP, IRQ, 3, KPP_HANDLER);
146} 157}
147 158
159#ifdef BUTTON_DRIVER_CLOSE
160void button_close_device(void)
161{
162 int oldlevel = disable_irq_save();
163
164 avic_disable_int(KPP);
165 KPP_KPSR &= ~(KPP_KPSR_KRIE | KPP_KPSR_KDIE);
166 int_btn = BUTTON_NONE;
167
168 restore_irq(oldlevel);
169}
170#endif /* BUTTON_DRIVER_CLOSE */
171
148bool button_hold(void) 172bool button_hold(void)
149{ 173{
150 return _button_hold(); 174 return _button_hold();
@@ -155,12 +179,14 @@ int button_read_device(void)
155 /* Simple poll of GPIO status */ 179 /* Simple poll of GPIO status */
156 hold_button = _button_hold(); 180 hold_button = _button_hold();
157 181
182#ifndef BOOTLOADER
158 /* Backlight hold handling */ 183 /* Backlight hold handling */
159 if (hold_button != hold_button_old) 184 if (hold_button != hold_button_old)
160 { 185 {
161 hold_button_old = hold_button; 186 hold_button_old = hold_button;
162 backlight_hold_changed(hold_button); 187 backlight_hold_changed(hold_button);
163 } 188 }
189#endif
164 190
165 /* Enable the keypad interrupt to cause it to fire if a key is down. 191 /* Enable the keypad interrupt to cause it to fire if a key is down.
166 * KPP_HANDLER will clear and disable it after the scan. If no key 192 * KPP_HANDLER will clear and disable it after the scan. If no key
@@ -190,6 +216,7 @@ void button_power_set_state(bool pressed)
190 restore_irq(oldlevel); 216 restore_irq(oldlevel);
191} 217}
192 218
219#ifdef HAVE_HEADPHONE_DETECTION
193/* This is called from the mc13783 interrupt thread */ 220/* This is called from the mc13783 interrupt thread */
194void set_headphones_inserted(bool inserted) 221void set_headphones_inserted(bool inserted)
195{ 222{
@@ -203,3 +230,4 @@ bool headphones_inserted(void)
203{ 230{
204 return headphones_detect; 231 return headphones_detect;
205} 232}
233#endif /* HAVE_HEADPHONE_DETECTION */
diff --git a/firmware/target/arm/imx31/gigabeat-s/button-target.h b/firmware/target/arm/imx31/gigabeat-s/button-target.h
index e2f68162f7..61d33f8e70 100644
--- a/firmware/target/arm/imx31/gigabeat-s/button-target.h
+++ b/firmware/target/arm/imx31/gigabeat-s/button-target.h
@@ -24,8 +24,13 @@
24 24
25#define HAS_BUTTON_HOLD 25#define HAS_BUTTON_HOLD
26 26
27#ifdef BOOTLOADER
28#define BUTTON_DRIVER_CLOSE
29#endif
30
27bool button_hold(void); 31bool button_hold(void);
28void button_init_device(void); 32void button_init_device(void);
33void button_close_device(void);
29int button_read_device(void); 34int button_read_device(void);
30void button_power_set_state(bool pressed); 35void button_power_set_state(bool pressed);
31void set_headphones_inserted(bool inserted); 36void set_headphones_inserted(bool inserted);
@@ -48,6 +53,8 @@ bool headphones_inserted(void);
48#define BUTTON_NEXT (1 << 11) 53#define BUTTON_NEXT (1 << 11)
49#define BUTTON_POWER (1 << 12) /* Read from PMIC */ 54#define BUTTON_POWER (1 << 12) /* Read from PMIC */
50 55
56#define BUTTON_MAIN (0x1fff)
57
51#define BUTTON_REMOTE 0 58#define BUTTON_REMOTE 0
52 59
53#define POWEROFF_BUTTON BUTTON_POWER 60#define POWEROFF_BUTTON BUTTON_POWER
diff --git a/firmware/target/arm/imx31/gigabeat-s/mc13783-imx31.c b/firmware/target/arm/imx31/gigabeat-s/mc13783-imx31.c
index 3af4b48b66..ddf8d1360f 100644
--- a/firmware/target/arm/imx31/gigabeat-s/mc13783-imx31.c
+++ b/firmware/target/arm/imx31/gigabeat-s/mc13783-imx31.c
@@ -29,6 +29,10 @@
29#include "adc-target.h" 29#include "adc-target.h"
30#include "usb-target.h" 30#include "usb-target.h"
31 31
32#ifdef BOOTLOADER
33#define PMIC_DRIVER_CLOSE
34#endif
35
32/* This is all based on communicating with the MC13783 PMU which is on 36/* This is all based on communicating with the MC13783 PMU which is on
33 * CSPI2 with the chip select at 0. The LCD controller resides on 37 * CSPI2 with the chip select at 0. The LCD controller resides on
34 * CSPI3 cs1, but we have no idea how to communicate to it */ 38 * CSPI3 cs1, but we have no idea how to communicate to it */
@@ -48,10 +52,14 @@ static struct spi_node mc13783_spi =
48static int mc13783_thread_stack[DEFAULT_STACK_SIZE/sizeof(int)]; 52static int mc13783_thread_stack[DEFAULT_STACK_SIZE/sizeof(int)];
49static const char *mc13783_thread_name = "pmic"; 53static const char *mc13783_thread_name = "pmic";
50static struct wakeup mc13783_wake; 54static struct wakeup mc13783_wake;
55#ifdef PMIC_DRIVER_CLOSE
56static bool pmic_close = false;
57static struct thread_entry *mc13783_thread_p = NULL;
58#endif
51 59
52/* The next two functions are rather target-specific but they'll just be left 60/* The next two functions are rather target-specific but they'll just be left
53 * here for the moment */ 61 * here for the moment */
54static __attribute__((noreturn)) void mc13783_interrupt_thread(void) 62static void mc13783_interrupt_thread(void)
55{ 63{
56 const unsigned char status_regs[2] = 64 const unsigned char status_regs[2] =
57 { 65 {
@@ -76,7 +84,9 @@ static __attribute__((noreturn)) void mc13783_interrupt_thread(void)
76 84
77 value = mc13783_read(MC13783_INTERRUPT_SENSE1); 85 value = mc13783_read(MC13783_INTERRUPT_SENSE1);
78 button_power_set_state((value & MC13783_ONOFD1) == 0); 86 button_power_set_state((value & MC13783_ONOFD1) == 0);
87#ifdef HAVE_HEADPHONE_DETECTION
79 set_headphones_inserted((value & MC13783_ONOFD2) == 0); 88 set_headphones_inserted((value & MC13783_ONOFD2) == 0);
89#endif
80 90
81 pending[0] = pending[1] = 0xffffff; 91 pending[0] = pending[1] = 0xffffff;
82 mc13783_write_regset(status_regs, pending, 2); 92 mc13783_write_regset(status_regs, pending, 2);
@@ -90,6 +100,14 @@ static __attribute__((noreturn)) void mc13783_interrupt_thread(void)
90 { 100 {
91 wakeup_wait(&mc13783_wake, TIMEOUT_BLOCK); 101 wakeup_wait(&mc13783_wake, TIMEOUT_BLOCK);
92 102
103#ifdef PMIC_DRIVER_CLOSE
104 if (pmic_close)
105 {
106 gpio_disable_event(MC13783_GPIO_NUM, MC13783_EVENT_ID);
107 return;
108 }
109#endif
110
93 mc13783_read_regset(status_regs, pending, 2); 111 mc13783_read_regset(status_regs, pending, 2);
94 mc13783_write_regset(status_regs, pending, 2); 112 mc13783_write_regset(status_regs, pending, 2);
95 113
@@ -130,9 +148,10 @@ static __attribute__((noreturn)) void mc13783_interrupt_thread(void)
130 148
131 if (pending[1] & MC13783_ONOFD1) 149 if (pending[1] & MC13783_ONOFD1)
132 button_power_set_state((value & MC13783_ONOFD1) == 0); 150 button_power_set_state((value & MC13783_ONOFD1) == 0);
133 151#ifdef HAVE_HEADPHONE_DETECTION
134 if (pending[1] & MC13783_ONOFD2) 152 if (pending[1] & MC13783_ONOFD2)
135 set_headphones_inserted((value & MC13783_ONOFD2) == 0); 153 set_headphones_inserted((value & MC13783_ONOFD2) == 0);
154#endif
136 } 155 }
137 } 156 }
138 } 157 }
@@ -161,10 +180,29 @@ void mc13783_init(void)
161 180
162 MC13783_GPIO_ISR = (1ul << MC13783_GPIO_LINE); 181 MC13783_GPIO_ISR = (1ul << MC13783_GPIO_LINE);
163 182
164 create_thread(mc13783_interrupt_thread, mc13783_thread_stack, 183#ifdef PMIC_DRIVER_CLOSE
165 sizeof(mc13783_thread_stack), 0, mc13783_thread_name 184 mc13783_thread_p =
166 IF_PRIO(, PRIORITY_REALTIME) IF_COP(, CPU)); 185#endif
186 create_thread(mc13783_interrupt_thread,
187 mc13783_thread_stack, sizeof(mc13783_thread_stack), 0,
188 mc13783_thread_name IF_PRIO(, PRIORITY_REALTIME) IF_COP(, CPU));
189}
190
191#ifdef PMIC_DRIVER_CLOSE
192void mc13783_close(void)
193{
194 struct thread_entry *thread = mc13783_thread_p;
195
196 if (thread == NULL)
197 return;
198
199 mc13783_thread_p = NULL;
200
201 pmic_close = true;
202 wakeup_signal(&mc13783_wake);
203 thread_wait(thread);
167} 204}
205#endif
168 206
169uint32_t mc13783_set(unsigned address, uint32_t bits) 207uint32_t mc13783_set(unsigned address, uint32_t bits)
170{ 208{
diff --git a/firmware/target/arm/imx31/gigabeat-s/system-imx31.c b/firmware/target/arm/imx31/gigabeat-s/system-imx31.c
index 3ec46bae67..1c3abc64fc 100644
--- a/firmware/target/arm/imx31/gigabeat-s/system-imx31.c
+++ b/firmware/target/arm/imx31/gigabeat-s/system-imx31.c
@@ -117,6 +117,7 @@ void system_prepare_fw_start(void)
117{ 117{
118 disable_interrupt(IRQ_FIQ_STATUS); 118 disable_interrupt(IRQ_FIQ_STATUS);
119 avic_disable_int(ALL); 119 avic_disable_int(ALL);
120 mc13783_close();
120 tick_stop(); 121 tick_stop();
121} 122}
122#endif 123#endif
diff --git a/firmware/target/arm/imx31/gigabeat-s/usb-target.h b/firmware/target/arm/imx31/gigabeat-s/usb-target.h
index 8c9dcfc65f..7ecd9a7d49 100644
--- a/firmware/target/arm/imx31/gigabeat-s/usb-target.h
+++ b/firmware/target/arm/imx31/gigabeat-s/usb-target.h
@@ -19,6 +19,10 @@
19#ifndef USB_TARGET_H 19#ifndef USB_TARGET_H
20#define USB_TARGET_H 20#define USB_TARGET_H
21 21
22#ifdef BOOTLOADER
23#define USB_DRIVER_CLOSE
24#endif
25
22void usb_set_status(bool plugged); 26void usb_set_status(bool plugged);
23bool usb_init_device(void); 27bool usb_init_device(void);
24int usb_detect(void); 28int usb_detect(void);