summaryrefslogtreecommitdiff
path: root/firmware/target/arm/imx31
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/imx31')
-rw-r--r--firmware/target/arm/imx31/ata-imx31.c12
-rw-r--r--firmware/target/arm/imx31/gigabeat-s/adc-gigabeat-s.c8
-rw-r--r--firmware/target/arm/imx31/gigabeat-s/headphone-gigabeat-s.c8
-rw-r--r--firmware/target/arm/imx31/i2c-imx31.c8
-rw-r--r--firmware/target/arm/imx31/mc13783-imx31.c20
5 files changed, 29 insertions, 27 deletions
diff --git a/firmware/target/arm/imx31/ata-imx31.c b/firmware/target/arm/imx31/ata-imx31.c
index d539282e70..8a40c924ff 100644
--- a/firmware/target/arm/imx31/ata-imx31.c
+++ b/firmware/target/arm/imx31/ata-imx31.c
@@ -246,7 +246,7 @@ static const struct ata_udma_timings
246 246
247/** Threading **/ 247/** Threading **/
248/* Signal to tell thread when DMA is done */ 248/* Signal to tell thread when DMA is done */
249static struct wakeup ata_dma_wakeup; 249static struct semaphore ata_dma_complete;
250 250
251/** SDMA **/ 251/** SDMA **/
252/* Array of buffer descriptors for large transfers and alignnment */ 252/* Array of buffer descriptors for large transfers and alignnment */
@@ -445,7 +445,7 @@ static void ata_dma_callback(void)
445 ATA_INTERRUPT_CLEAR = ATA_INTERRUPT_PENDING; 445 ATA_INTERRUPT_CLEAR = ATA_INTERRUPT_PENDING;
446 446
447 ata_set_intrq(false); /* Return INTRQ to MCU */ 447 ata_set_intrq(false); /* Return INTRQ to MCU */
448 wakeup_signal(&ata_dma_wakeup); /* Signal waiting thread */ 448 semaphore_release(&ata_dma_complete); /* Signal waiting thread */
449} 449}
450 450
451bool ata_dma_setup(void *addr, unsigned long bytes, bool write) 451bool ata_dma_setup(void *addr, unsigned long bytes, bool write)
@@ -580,7 +580,8 @@ bool ata_dma_finish(void)
580 { 580 {
581 int oldirq; 581 int oldirq;
582 582
583 if (LIKELY(wakeup_wait(&ata_dma_wakeup, HZ/2) == OBJ_WAIT_SUCCEEDED)) 583 if (LIKELY(semaphore_wait(&ata_dma_complete, HZ/2)
584 == OBJ_WAIT_SUCCEEDED))
584 break; 585 break;
585 586
586 ata_keep_active(); 587 ata_keep_active();
@@ -594,7 +595,8 @@ bool ata_dma_finish(void)
594 sdma_channel_stop(channel); /* Stop DMA */ 595 sdma_channel_stop(channel); /* Stop DMA */
595 restore_irq(oldirq); 596 restore_irq(oldirq);
596 597
597 if (wakeup_wait(&ata_dma_wakeup, TIMEOUT_NOBLOCK) == OBJ_WAIT_SUCCEEDED) 598 if (semaphore_wait(&ata_dma_complete, TIMEOUT_NOBLOCK)
599 == OBJ_WAIT_SUCCEEDED)
598 break; /* DMA really did finish after timeout */ 600 break; /* DMA really did finish after timeout */
599 601
600 sdma_channel_reset(channel); /* Reset everything + clear error */ 602 sdma_channel_reset(channel); /* Reset everything + clear error */
@@ -716,7 +718,7 @@ void ata_device_init(void)
716 ata_dma_selected = ATA_DMA_PIO; 718 ata_dma_selected = ATA_DMA_PIO;
717 719
718 /* Called for first time at startup */ 720 /* Called for first time at startup */
719 wakeup_init(&ata_dma_wakeup); 721 semaphore_init(&ata_dma_complete, 1, 0);
720 722
721 if (!sdma_channel_init(ATA_DMA_CH_NUM_RD, &ata_cd_rd, ata_bda) || 723 if (!sdma_channel_init(ATA_DMA_CH_NUM_RD, &ata_cd_rd, ata_bda) ||
722 !sdma_channel_init(ATA_DMA_CH_NUM_WR, &ata_cd_wr, ata_bda)) 724 !sdma_channel_init(ATA_DMA_CH_NUM_WR, &ata_cd_wr, ata_bda))
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 f7bc0ed37c..eb30919077 100644
--- a/firmware/target/arm/imx31/gigabeat-s/adc-gigabeat-s.c
+++ b/firmware/target/arm/imx31/gigabeat-s/adc-gigabeat-s.c
@@ -35,7 +35,7 @@ static const unsigned char reg_array[4] =
35}; 35};
36 36
37static uint32_t channels[2][4]; 37static uint32_t channels[2][4];
38static struct wakeup adc_wake; 38static struct semaphore adc_done_signal;
39static struct mutex adc_mtx; 39static struct mutex adc_mtx;
40static long last_adc_read[2]; /* One for each input group */ 40static long last_adc_read[2]; /* One for each input group */
41 41
@@ -67,7 +67,7 @@ unsigned short adc_read(int channel)
67 mc13783_write(MC13783_ADC1, adc1); 67 mc13783_write(MC13783_ADC1, adc1);
68 68
69 /* Wait for done signal */ 69 /* Wait for done signal */
70 wakeup_wait(&adc_wake, TIMEOUT_BLOCK); 70 semaphore_wait(&adc_done_signal, TIMEOUT_BLOCK);
71 71
72 /* Read all 8 channels that are converted - two channels in each 72 /* Read all 8 channels that are converted - two channels in each
73 * word. */ 73 * word. */
@@ -113,12 +113,12 @@ bool adc_enable_channel(int channel, bool enable)
113/* Called by mc13783 interrupt thread when conversion is complete */ 113/* Called by mc13783 interrupt thread when conversion is complete */
114void adc_done(void) 114void adc_done(void)
115{ 115{
116 wakeup_signal(&adc_wake); 116 semaphore_release(&adc_done_signal);
117} 117}
118 118
119void adc_init(void) 119void adc_init(void)
120{ 120{
121 wakeup_init(&adc_wake); 121 semaphore_init(&adc_done_signal, 1, 0);
122 mutex_init(&adc_mtx); 122 mutex_init(&adc_mtx);
123 123
124 /* Init so first reads get data */ 124 /* Init so first reads get data */
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 0f8cb67a9d..6e76615308 100644
--- a/firmware/target/arm/imx31/gigabeat-s/headphone-gigabeat-s.c
+++ b/firmware/target/arm/imx31/gigabeat-s/headphone-gigabeat-s.c
@@ -29,7 +29,7 @@
29#include "adc.h" 29#include "adc.h"
30#include "button.h" 30#include "button.h"
31 31
32static struct wakeup headphone_wakeup; 32static struct semaphore headphone_wakeup;
33static unsigned int headphone_thread_id; 33static unsigned int headphone_thread_id;
34static int headphone_stack[200/sizeof(int)]; /* Not much stack needed */ 34static int headphone_stack[200/sizeof(int)]; /* Not much stack needed */
35static const char * const headphone_thread_name = "headphone"; 35static const char * const headphone_thread_name = "headphone";
@@ -115,7 +115,7 @@ static void headphone_thread(void)
115 115
116 while (1) 116 while (1)
117 { 117 {
118 int rc = wakeup_wait(&headphone_wakeup, headphone_wait_timeout); 118 int rc = semaphore_wait(&headphone_wakeup, headphone_wait_timeout);
119 unsigned int data = adc_read(ADC_HPREMOTE); 119 unsigned int data = adc_read(ADC_HPREMOTE);
120 120
121 if (rc == OBJ_WAIT_TIMEDOUT) 121 if (rc == OBJ_WAIT_TIMEDOUT)
@@ -175,7 +175,7 @@ static void headphone_thread(void)
175void headphone_detect_event(void) 175void headphone_detect_event(void)
176{ 176{
177 /* Trigger the thread immediately. */ 177 /* Trigger the thread immediately. */
178 wakeup_signal(&headphone_wakeup); 178 semaphore_release(&headphone_wakeup);
179} 179}
180 180
181/* Tell if anything is in the jack. */ 181/* Tell if anything is in the jack. */
@@ -187,7 +187,7 @@ bool headphones_inserted(void)
187void INIT_ATTR headphone_init(void) 187void INIT_ATTR headphone_init(void)
188{ 188{
189 /* A thread is required to monitor the remote ADC and jack state. */ 189 /* A thread is required to monitor the remote ADC and jack state. */
190 wakeup_init(&headphone_wakeup); 190 semaphore_init(&headphone_wakeup, 1, 0);
191 headphone_thread_id = create_thread(headphone_thread, 191 headphone_thread_id = create_thread(headphone_thread,
192 headphone_stack, 192 headphone_stack,
193 sizeof(headphone_stack), 193 sizeof(headphone_stack),
diff --git a/firmware/target/arm/imx31/i2c-imx31.c b/firmware/target/arm/imx31/i2c-imx31.c
index 4e810c588f..975f951fdc 100644
--- a/firmware/target/arm/imx31/i2c-imx31.c
+++ b/firmware/target/arm/imx31/i2c-imx31.c
@@ -48,7 +48,7 @@ static struct i2c_module_descriptor
48 volatile unsigned short * const base; /* Module base address */ 48 volatile unsigned short * const base; /* Module base address */
49 void (* const handler)(void); /* Module interrupt handler */ 49 void (* const handler)(void); /* Module interrupt handler */
50 struct mutex m; /* Node mutual-exclusion */ 50 struct mutex m; /* Node mutual-exclusion */
51 struct wakeup w; /* I2C done signal */ 51 struct semaphore complete; /* I2C completion signal */
52 unsigned char *addr_data; /* Additional addressing data */ 52 unsigned char *addr_data; /* Additional addressing data */
53 int addr_count; /* Addressing byte count */ 53 int addr_count; /* Addressing byte count */
54 unsigned char *data; /* TX/RX buffer (actual data) */ 54 unsigned char *data; /* TX/RX buffer (actual data) */
@@ -164,7 +164,7 @@ i2c_stop:
164 base[I2CR] &= ~(I2C_I2CR_MSTA | I2C_I2CR_IIEN); 164 base[I2CR] &= ~(I2C_I2CR_MSTA | I2C_I2CR_IIEN);
165i2c_done: 165i2c_done:
166 /* Signal thread we're done */ 166 /* Signal thread we're done */
167 wakeup_signal(&desc->w); 167 semaphore_release(&desc->complete);
168} 168}
169 169
170#if (I2C_MODULE_MASK & USE_I2C1_MODULE) 170#if (I2C_MODULE_MASK & USE_I2C1_MODULE)
@@ -221,7 +221,7 @@ static int i2c_transfer(struct i2c_node * const node,
221 base[I2DR] = desc->addr; 221 base[I2DR] = desc->addr;
222 222
223 /* Wait for transfer to complete */ 223 /* Wait for transfer to complete */
224 if (wakeup_wait(&desc->w, HZ) == OBJ_WAIT_SUCCEEDED) 224 if (semaphore_wait(&desc->complete, HZ) == OBJ_WAIT_SUCCEEDED)
225 { 225 {
226 count -= desc->data_count; 226 count -= desc->data_count;
227 } 227 }
@@ -294,7 +294,7 @@ void i2c_init(void)
294 struct i2c_module_descriptor *const desc = &i2c_descs[i]; 294 struct i2c_module_descriptor *const desc = &i2c_descs[i];
295 ccm_module_clock_gating(desc->cg, CGM_ON_RUN_WAIT); 295 ccm_module_clock_gating(desc->cg, CGM_ON_RUN_WAIT);
296 mutex_init(&desc->m); 296 mutex_init(&desc->m);
297 wakeup_init(&desc->w); 297 semaphore_init(&desc->complete, 1, 0);
298 desc->base[I2CR] = 0; 298 desc->base[I2CR] = 0;
299 ccm_module_clock_gating(desc->cg, CGM_OFF); 299 ccm_module_clock_gating(desc->cg, CGM_OFF);
300 } 300 }
diff --git a/firmware/target/arm/imx31/mc13783-imx31.c b/firmware/target/arm/imx31/mc13783-imx31.c
index d5d22e2c75..006b065ea5 100644
--- a/firmware/target/arm/imx31/mc13783-imx31.c
+++ b/firmware/target/arm/imx31/mc13783-imx31.c
@@ -32,11 +32,11 @@ extern struct spi_node mc13783_spi;
32/* PMIC event service data */ 32/* PMIC event service data */
33static int mc13783_thread_stack[DEFAULT_STACK_SIZE/sizeof(int)]; 33static int mc13783_thread_stack[DEFAULT_STACK_SIZE/sizeof(int)];
34static const char *mc13783_thread_name = "pmic"; 34static const char *mc13783_thread_name = "pmic";
35static struct wakeup mc13783_svc_wake; 35static struct semaphore mc13783_svc_wake;
36 36
37/* Synchronous thread communication objects */ 37/* Synchronous thread communication objects */
38static struct mutex mc13783_spi_mutex; 38static struct mutex mc13783_spi_mutex;
39static struct wakeup mc13783_spi_wake; 39static struct semaphore mc13783_spi_complete;
40 40
41/* Tracking for which interrupts are enabled */ 41/* Tracking for which interrupts are enabled */
42static uint32_t pmic_int_enabled[2] = 42static uint32_t pmic_int_enabled[2] =
@@ -69,13 +69,13 @@ static void mc13783_xfer_complete_cb(struct spi_transfer_desc *xfer)
69 if (xfer->count != 0) 69 if (xfer->count != 0)
70 return; 70 return;
71 71
72 wakeup_signal(&mc13783_spi_wake); 72 semaphore_release(&mc13783_spi_complete);
73} 73}
74 74
75static inline bool wait_for_transfer_complete(void) 75static inline bool wait_for_transfer_complete(void)
76{ 76{
77 return wakeup_wait(&mc13783_spi_wake, HZ*2) == OBJ_WAIT_SUCCEEDED && 77 return semaphore_wait(&mc13783_spi_complete, HZ*2)
78 mc13783_transfer.count == 0; 78 == OBJ_WAIT_SUCCEEDED && mc13783_transfer.count == 0;
79} 79}
80 80
81static void mc13783_interrupt_thread(void) 81static void mc13783_interrupt_thread(void)
@@ -89,7 +89,7 @@ static void mc13783_interrupt_thread(void)
89 { 89 {
90 const struct mc13783_event *event, *event_last; 90 const struct mc13783_event *event, *event_last;
91 91
92 wakeup_wait(&mc13783_svc_wake, TIMEOUT_BLOCK); 92 semaphore_wait(&mc13783_svc_wake, TIMEOUT_BLOCK);
93 93
94 if (mc13783_thread_id == 0) 94 if (mc13783_thread_id == 0)
95 break; 95 break;
@@ -140,16 +140,16 @@ void mc13783_event(void)
140 /* Mask the interrupt (unmasked when PMIC thread services it). */ 140 /* Mask the interrupt (unmasked when PMIC thread services it). */
141 bitclr32(&MC13783_GPIO_IMR, 1ul << MC13783_GPIO_LINE); 141 bitclr32(&MC13783_GPIO_IMR, 1ul << MC13783_GPIO_LINE);
142 MC13783_GPIO_ISR = (1ul << MC13783_GPIO_LINE); 142 MC13783_GPIO_ISR = (1ul << MC13783_GPIO_LINE);
143 wakeup_signal(&mc13783_svc_wake); 143 semaphore_release(&mc13783_svc_wake);
144} 144}
145 145
146void INIT_ATTR mc13783_init(void) 146void INIT_ATTR mc13783_init(void)
147{ 147{
148 /* Serial interface must have been initialized first! */ 148 /* Serial interface must have been initialized first! */
149 wakeup_init(&mc13783_svc_wake); 149 semaphore_init(&mc13783_svc_wake, 1, 0);
150 mutex_init(&mc13783_spi_mutex); 150 mutex_init(&mc13783_spi_mutex);
151 151
152 wakeup_init(&mc13783_spi_wake); 152 semaphore_init(&mc13783_spi_complete, 1, 0);
153 153
154 /* Enable the PMIC SPI module */ 154 /* Enable the PMIC SPI module */
155 spi_enable_module(&mc13783_spi); 155 spi_enable_module(&mc13783_spi);
@@ -175,7 +175,7 @@ void mc13783_close(void)
175 return; 175 return;
176 176
177 mc13783_thread_id = 0; 177 mc13783_thread_id = 0;
178 wakeup_signal(&mc13783_svc_wake); 178 semaphore_release(&mc13783_svc_wake);
179 thread_wait(thread_id); 179 thread_wait(thread_id);
180 spi_disable_module(&mc13783_spi); 180 spi_disable_module(&mc13783_spi);
181} 181}