freemyipod r280 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r279‎ | r280 | r281 >
Date:19:19, 23 November 2010
Author:theseven
Status:new
Tags:
Comment:
emBIOS: Use DMA for SPI on s5l8702
Modified paths:
  • /embios/trunk/target/ipodnano3g/s5l8702.h (modified) (history)
  • /embios/trunk/target/ipodnano3g/spi.c (modified) (history)
  • /embios/trunk/target/ipodnano4g/s5l8720.h (modified) (history)

Diff [purge]

Index: embios/trunk/target/ipodnano3g/s5l8702.h
@@ -319,6 +319,9 @@
320320 #define SPICLKGATE(i) ((i) == 2 ? 0x2f : \
321321 (i) == 1 ? 0x2b : \
322322 0x22)
 323+#define SPIDMA(i) ((i) == 2 ? 0xd : \
 324+ (i) == 1 ? 0xf : \
 325+ 0x5)
323326 #define SPICTRL(i) (*((uint32_t volatile*)(SPIBASE(i))))
324327 #define SPISETUP(i) (*((uint32_t volatile*)(SPIBASE(i) + 0x4)))
325328 #define SPISTATUS(i) (*((uint32_t volatile*)(SPIBASE(i) + 0x8)))
Index: embios/trunk/target/ipodnano3g/spi.c
@@ -29,6 +29,7 @@
3030
3131
3232 static struct mutex spimutex[3];
 33+static struct wakeup spiwakeup[3];
3334
3435
3536 void spi_prepare(int port)
@@ -63,12 +64,54 @@
6465 {
6566 uint8_t* buffer = (uint8_t*)buf;
6667 SPIRXLIMIT(port) = size;
67 - SPISETUP(port) |= 1;
68 - while (size--)
 68+ if (size < 0x100)
6969 {
70 - while (!(SPISTATUS(port) & 0x3e00)) yield();
71 - *buffer++ = SPIRXDATA(port);
 70+ SPISETUP(port) |= 1;
 71+ while (size--)
 72+ {
 73+ while (!(SPISTATUS(port) & 0x3e00)) yield();
 74+ *buffer++ = SPIRXDATA(port);
 75+ }
 76+ SPISETUP(port) &= ~1;
 77+ return;
7278 }
73 - SPISETUP(port) &= ~1;
 79+ SPISETUP(port) |= 0x41;
 80+ void* addr = (void*)((uint32_t)buf + size);
 81+ struct dma_lli* lli = (struct dma_lli*)(((uint32_t)addr - 0x10) & ~0xf);
 82+ struct dma_lli* nextlli = NULL;
 83+ while (addr > buf)
 84+ {
 85+ size = (uint32_t)addr - (uint32_t)buf;
 86+ if (size > 0xfff) size = 0xfff;
 87+ else lli = (struct dma_lli*)((int)&DMAC0CLLI(port + 5));
 88+ addr = (void*)((uint32_t)addr - size);
 89+ lli->srcaddr = (void*)((int)&SPIRXDATA(port));
 90+ lli->dstaddr = addr;
 91+ lli->nextlli = nextlli;
 92+ lli->control = 0x78000000 | size | (nextlli == NULL ? 0x80000000 : 0);
 93+ nextlli = lli;
 94+ lli = &lli[-1];
 95+ }
 96+ clean_dcache();
 97+ DMAC0CCONFIG(port + 5) = 0x9001 | (SPIDMA(port) << 1);
 98+ wakeup_wait(&spiwakeup[port], TIMEOUT_BLOCK);
 99+ SPISETUP(port) &= ~0x41;
74100 }
75101
 102+void INT_DMAC0C5()
 103+{
 104+ DMAC0INTTCCLR = 1 << 5;
 105+ wakeup_signal(&spiwakeup[0]);
 106+}
 107+
 108+void INT_DMAC0C6()
 109+{
 110+ DMAC0INTTCCLR = 1 << 6;
 111+ wakeup_signal(&spiwakeup[1]);
 112+}
 113+
 114+void INT_DMAC0C7()
 115+{
 116+ DMAC0INTTCCLR = 1 << 7;
 117+ wakeup_signal(&spiwakeup[2]);
 118+}
Index: embios/trunk/target/ipodnano4g/s5l8720.h
@@ -319,6 +319,9 @@
320320 #define SPICLKGATE(i) ((i) == 2 ? 0x2f : \
321321 (i) == 1 ? 0x2b : \
322322 0x22)
 323+#define SPIDMA(i) ((i) == 2 ? 0xd : \
 324+ (i) == 1 ? 0xf : \
 325+ 0x5)
323326 #define SPICTRL(i) (*((uint32_t volatile*)(SPIBASE(i))))
324327 #define SPISETUP(i) (*((uint32_t volatile*)(SPIBASE(i) + 0x4)))
325328 #define SPISTATUS(i) (*((uint32_t volatile*)(SPIBASE(i) + 0x8)))