summaryrefslogtreecommitdiff
path: root/firmware/target/arm/imx31/gigabeat-s
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/imx31/gigabeat-s')
-rw-r--r--firmware/target/arm/imx31/gigabeat-s/button-imx31.c8
-rw-r--r--firmware/target/arm/imx31/gigabeat-s/system-imx31.c31
-rw-r--r--firmware/target/arm/imx31/gigabeat-s/system-target.h17
3 files changed, 37 insertions, 19 deletions
diff --git a/firmware/target/arm/imx31/gigabeat-s/button-imx31.c b/firmware/target/arm/imx31/gigabeat-s/button-imx31.c
index 7c432450c2..587e66e0bc 100644
--- a/firmware/target/arm/imx31/gigabeat-s/button-imx31.c
+++ b/firmware/target/arm/imx31/gigabeat-s/button-imx31.c
@@ -68,8 +68,6 @@ static __attribute__((interrupt("IRQ"))) void KPP_HANDLER(void)
68 68
69 for (col = 0; col < 3; col++) /* Col */ 69 for (col = 0; col < 3; col++) /* Col */
70 { 70 {
71 int i;
72
73 /* 2. Write 1s to KPDR[10:8] setting column data to 1s */ 71 /* 2. Write 1s to KPDR[10:8] setting column data to 1s */
74 KPP_KPDR |= (0x7 << 8); 72 KPP_KPDR |= (0x7 << 8);
75 73
@@ -78,8 +76,7 @@ static __attribute__((interrupt("IRQ"))) void KPP_HANDLER(void)
78 KPP_KPCR &= ~(0x7 << 8); 76 KPP_KPCR &= ~(0x7 << 8);
79 77
80 /* Give the columns time to discharge */ 78 /* Give the columns time to discharge */
81 for (i = 0; i < 128; i++) /* TODO: find minimum safe delay */ 79 udelay(2);
82 asm volatile ("");
83 80
84 /* 4. Configure columns as open-drain */ 81 /* 4. Configure columns as open-drain */
85 KPP_KPCR |= (0x7 << 8); 82 KPP_KPCR |= (0x7 << 8);
@@ -94,8 +91,7 @@ static __attribute__((interrupt("IRQ"))) void KPP_HANDLER(void)
94 91
95 /* Delay added to avoid propagating the 0 from column to row 92 /* Delay added to avoid propagating the 0 from column to row
96 * when scanning. */ 93 * when scanning. */
97 for (i = 0; i < 128; i++) /* TODO: find minimum safe delay */ 94 udelay(2);
98 asm volatile ("");
99 95
100 /* Read row input */ 96 /* Read row input */
101 button |= (~KPP_KPDR & kms[col].mask) << kms[col].shift; 97 button |= (~KPP_KPDR & kms[col].mask) << kms[col].shift;
diff --git a/firmware/target/arm/imx31/gigabeat-s/system-imx31.c b/firmware/target/arm/imx31/gigabeat-s/system-imx31.c
index c339f4fe7c..7454806d07 100644
--- a/firmware/target/arm/imx31/gigabeat-s/system-imx31.c
+++ b/firmware/target/arm/imx31/gigabeat-s/system-imx31.c
@@ -32,6 +32,8 @@
32#include "clkctl-imx31.h" 32#include "clkctl-imx31.h"
33#include "mc13783.h" 33#include "mc13783.h"
34 34
35/** Watchdog timer routines **/
36
35/* Initialize the watchdog timer */ 37/* Initialize the watchdog timer */
36void watchdog_init(unsigned int half_seconds) 38void watchdog_init(unsigned int half_seconds)
37{ 39{
@@ -57,6 +59,33 @@ void watchdog_service(void)
57 WDOG_WSR = 0xaaaa; 59 WDOG_WSR = 0xaaaa;
58} 60}
59 61
62/** GPT timer routines - basis for udelay **/
63
64/* Start the general-purpose timer (1MHz) */
65void gpt_start(void)
66{
67 imx31_clkctl_module_clock_gating(CG_GPT, CGM_ON_RUN_WAIT);
68 unsigned int ipg_mhz = imx31_clkctl_get_ipg_clk() / 1000000;
69
70 GPTCR &= ~GPTCR_EN; /* Disable counter */
71 GPTCR |= GPTCR_SWR; /* Reset module */
72 while (GPTCR & GPTCR_SWR);
73 /* No output
74 * No capture
75 * Enable in run mode only (doesn't tick while in WFI)
76 * Freerun mode (count to 0xFFFFFFFF and roll-over to 0x00000000)
77 */
78 GPTCR = GPTCR_FRR | GPTCR_CLKSRC_IPG_CLK;
79 GPTPR = ipg_mhz - 1;
80 GPTCR |= GPTCR_EN;
81}
82
83/* Stop the general-purpose timer */
84void gpt_stop(void)
85{
86 GPTCR &= ~GPTCR_EN;
87}
88
60int system_memory_guard(int newmode) 89int system_memory_guard(int newmode)
61{ 90{
62 (void)newmode; 91 (void)newmode;
@@ -84,7 +113,6 @@ void system_init(void)
84 /* CGR0 */ 113 /* CGR0 */
85 CG_SD_MMC1, 114 CG_SD_MMC1,
86 CG_SD_MMC2, 115 CG_SD_MMC2,
87 CG_GPT,
88 CG_IIM, 116 CG_IIM,
89 CG_SDMA, 117 CG_SDMA,
90 CG_CSPI3, 118 CG_CSPI3,
@@ -140,6 +168,7 @@ void system_init(void)
140 imx31_clkctl_module_clock_gating(disable_clocks[i], CGM_OFF); 168 imx31_clkctl_module_clock_gating(disable_clocks[i], CGM_OFF);
141 169
142 avic_init(); 170 avic_init();
171 gpt_start();
143 gpio_init(); 172 gpio_init();
144} 173}
145 174
diff --git a/firmware/target/arm/imx31/gigabeat-s/system-target.h b/firmware/target/arm/imx31/gigabeat-s/system-target.h
index b99b31d1b4..c7797e43c9 100644
--- a/firmware/target/arm/imx31/gigabeat-s/system-target.h
+++ b/firmware/target/arm/imx31/gigabeat-s/system-target.h
@@ -31,25 +31,18 @@
31#define CPUFREQ_MAX CPU_FREQ 31#define CPUFREQ_MAX CPU_FREQ
32#endif 32#endif
33 33
34/* For USB driver - no accuracy assurance */
35static inline void udelay(unsigned int usecs) 34static inline void udelay(unsigned int usecs)
36{ 35{
37 unsigned int x; 36 unsigned stop = GPTCNT + usecs;
38 for (x = 0; x < 300*usecs; x++) 37 while (TIME_BEFORE(GPTCNT, stop));
39 asm volatile ("");
40} 38}
41 39
42#if 0
43static inline void udelay(unsigned int usecs)
44{
45 volatile signed int stop = EPITCNT1 - usecs;
46 while ((signed int)EPITCNT1 > stop);
47}
48#endif
49
50void watchdog_init(unsigned int half_seconds); 40void watchdog_init(unsigned int half_seconds);
51void watchdog_service(void); 41void watchdog_service(void);
52 42
43void gpt_start(void);
44void gpt_stop(void);
45
53/* Prepare for transition to firmware */ 46/* Prepare for transition to firmware */
54void system_prepare_fw_start(void); 47void system_prepare_fw_start(void);
55void tick_stop(void); 48void tick_stop(void);