Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

S5L8702: Abstract LCD driver

This driver decouples the LCD interface from the target-specific LCD parameters. It makes it possible to reuse most of the ipod6g driver code on ipodnano3g and ipodnano4g.

No difference in the produced binaries for ipodnano2g (normal and bootloader).

Tested on ipod6g (normal and bootloader).

This is a part of the large iPod Nano 3G and iPod Nano 4G support patch.

Change-Id: I7ce198ed3d5a8b58759951e2d67788cbf9781dc8

authored by

Vencislav Atanasov and committed by
Solomon Peachy
843157e2 63d8aa00

+917 -470
+46 -29
firmware/SOURCES
··· 737 737 #endif /* BOOTLOADER */ 738 738 #endif /* CONFIG_CPU == AS3525 */ 739 739 740 + #if CONFIG_CPU == S5L8702 || CONFIG_CPU == S5L8720 741 + target/arm/ipod/button-clickwheel.c 742 + target/arm/s5l8702/kernel-s5l8702.c 743 + target/arm/s5l8702/system-s5l8702.c 744 + target/arm/s5l8702/timer-s5l8702.c 745 + target/arm/s5l8702/gpio-s5l8702.c 746 + target/arm/s5l8702/pl080.c 747 + target/arm/s5l8702/dma-s5l8702.c 748 + target/arm/s5l8702/clocking-s5l8702.c 749 + #if 0 // TODO 750 + target/arm/s5l8702/postmortemstub.S 751 + #endif 752 + #ifndef BOOTLOADER 753 + target/arm/s5l8702/pcm-s5l8702.c 754 + target/arm/s5l8702/debug-s5l8702.c 755 + #endif 756 + #if !defined(BOOTLOADER) || defined(HAVE_BOOTLOADER_USB_MODE) 757 + target/arm/s5l8702/usb-s5l8702.c 758 + #endif 759 + #ifdef HAVE_SERIAL 760 + target/arm/uc87xx.c 761 + target/arm/s5l8702/uart-s5l8702.c 762 + #endif 763 + target/arm/s5l8702/crypto-s5l8702.c 764 + #if CONFIG_CPU == S5L8702 765 + target/arm/s5l8702/spi-s5l8702.c 766 + target/arm/s5l8702/norboot-s5l8702.c 767 + #elif CONFIG_CPU == S5L8720 768 + /* target/arm/s5l8702/nandboot-s5l8702.c */ 769 + #endif 770 + #endif /* S5L8702 || S5L8720 */ 771 + 740 772 #if defined(CPU_PP) 741 773 target/arm/pp/i2s-pp.c 742 774 target/arm/pp/kernel-pp.c ··· 788 820 target/arm/imx31/crt0.S 789 821 #elif CONFIG_CPU==S5L8700 || CONFIG_CPU==S5L8701 790 822 target/arm/s5l8700/crt0.S 791 - #elif CONFIG_CPU==S5L8702 823 + #elif CONFIG_CPU==S5L8702 || CONFIG_CPU==S5L8720 792 824 target/arm/s5l8702/crt0.S 793 825 #elif CONFIG_CPU==IMX233 794 826 target/arm/imx233/crt0.S ··· 850 882 target/arm/rk27xx/ihifi2/lcd-ihifi770c.c 851 883 #elif CONFIG_LCD == LCD_IHIFI800 852 884 target/arm/rk27xx/ihifi2/lcd-ihifi800.c 885 + #elif CONFIG_LCD == LCD_IPOD6GNANO3G4G 886 + target/arm/s5l8702/lcd-s5l8702.c 887 + target/arm/s5l8702/lcd-asm-s5l8702.S 853 888 #endif 854 889 855 890 /* USB Stack */ ··· 1538 1573 #ifdef IPOD_NANO2G 1539 1574 target/arm/ipod/button-clickwheel.c 1540 1575 target/arm/s5l8700/postmortemstub.S 1576 + target/arm/s5l8700/usb-s5l8701.c 1541 1577 target/arm/s5l8700/ipodnano2g/backlight-nano2g.c 1542 1578 target/arm/s5l8700/ipodnano2g/lcd-nano2g.c 1543 1579 target/arm/s5l8700/ipodnano2g/lcd-asm-nano2g.S ··· 1546 1582 target/arm/s5l8700/ipodnano2g/ftl-nano2g.c 1547 1583 target/arm/s5l8700/ipodnano2g/nand-nano2g.c 1548 1584 target/arm/s5l8700/ipodnano2g/pmu-nano2g.c 1585 + #if (CONFIG_RTC == RTC_NANO2G) 1549 1586 target/arm/s5l8700/ipodnano2g/rtc-nano2g.c 1550 - target/arm/s5l8700/usb-s5l8701.c 1587 + #endif 1551 1588 #ifdef HAVE_SERIAL 1552 1589 target/arm/uc87xx.c 1553 1590 target/arm/s5l8700/uart-s5l8701.c ··· 1557 1594 target/arm/s5l8700/ipodnano2g/audio-nano2g.c 1558 1595 target/arm/s5l8700/ipodnano2g/piezo-nano2g.c 1559 1596 #endif 1560 - #endif 1597 + #endif /* IPOD_NANO2G */ 1561 1598 1562 1599 #ifdef IPOD_6G 1563 - target/arm/ipod/button-clickwheel.c 1564 - target/arm/s5l8702/ipod6g/storage_ata-6g.c 1565 - target/arm/s5l8702/ipod6g/backlight-6g.c 1566 - target/arm/s5l8702/ipod6g/powermgmt-6g.c 1567 - target/arm/s5l8702/ipod6g/power-6g.c 1568 - target/arm/s5l8702/kernel-s5l8702.c 1569 - target/arm/s5l8702/system-s5l8702.c 1570 - target/arm/s5l8702/timer-s5l8702.c 1571 - target/arm/s5l8702/gpio-s5l8702.c 1572 - target/arm/s5l8702/pl080.c 1573 - target/arm/s5l8702/dma-s5l8702.c 1574 - target/arm/s5l8702/clocking-s5l8702.c 1575 1600 target/arm/s5l8702/ipod6g/lcd-6g.c 1576 - target/arm/s5l8702/ipod6g/lcd-asm-6g.S 1601 + target/arm/s5l8702/ipod6g/backlight-6g.c 1577 1602 target/arm/s5l8702/ipod6g/piezo-6g.c 1578 - target/arm/s5l8702/spi-s5l8702.c 1579 - target/arm/s5l8702/crypto-s5l8702.c 1580 - target/arm/s5l8702/norboot-s5l8702.c 1581 - #if 0 //TODO 1582 - target/arm/s5l8702/postmortemstub.S 1583 - #endif 1584 1603 target/arm/s5l8702/ipod6g/pmu-6g.c 1604 + target/arm/s5l8702/ipod6g/adc-6g.c 1605 + target/arm/s5l8702/ipod6g/powermgmt-6g.c 1606 + target/arm/s5l8702/ipod6g/power-6g.c 1607 + target/arm/s5l8702/ipod6g/storage_ata-6g.c 1608 + #if (CONFIG_RTC == RTC_NANO2G) 1585 1609 target/arm/s5l8702/ipod6g/rtc-6g.c 1586 - target/arm/s5l8702/ipod6g/adc-6g.c 1587 - #if !defined(BOOTLOADER) || defined(HAVE_BOOTLOADER_USB_MODE) 1588 - target/arm/s5l8702/usb-s5l8702.c 1589 1610 #endif 1590 1611 #ifdef HAVE_SERIAL 1591 - target/arm/uc87xx.c 1592 - target/arm/s5l8702/uart-s5l8702.c 1593 1612 target/arm/s5l8702/ipod6g/serial-6g.c 1594 1613 #endif 1595 1614 #ifndef BOOTLOADER 1596 - target/arm/s5l8702/debug-s5l8702.c 1597 - target/arm/s5l8702/pcm-s5l8702.c 1598 1615 target/arm/s5l8702/ipod6g/audio-6g.c 1599 1616 target/arm/s5l8702/ipod6g/cscodec-6g.c 1600 1617 #endif /* BOOTLOADER */
+7 -2
firmware/target/arm/s5l8702/ipod6g/backlight-6g.c
··· 43 43 if (!lcd_active()) 44 44 { 45 45 lcd_awake(); 46 - lcd_update(); 47 - sleep(HZ/20); 48 46 } 49 47 #endif 50 48 pmu_write(0x29, 1); ··· 67 65 68 66 return true; 69 67 } 68 + 69 + /* Kill the backlight, instantly. */ 70 + void backlight_hw_kill(void) 71 + { 72 + pmu_write(0x2b, 0); /* T_dimstep = 0 */ 73 + backlight_hw_off(); 74 + }
+2
firmware/target/arm/s5l8702/ipod6g/backlight-target.h
··· 26 26 void backlight_hw_off(void); 27 27 void backlight_hw_brightness(int brightness); 28 28 29 + void backlight_hw_kill(void); 30 + 29 31 #endif
+122 -439
firmware/target/arm/s5l8702/ipod6g/lcd-6g.c
··· 18 18 * KIND, either express or implied. 19 19 * 20 20 ****************************************************************************/ 21 - #include "config.h" 22 - 23 - #include "hwcompat.h" 24 - #include "kernel.h" 25 - #include "lcd.h" 26 - #include "system.h" 27 - #include "cpu.h" 28 - #include "pmu-target.h" 29 - #include "power.h" 30 - #include "string.h" 31 - #include "dma-s5l8702.h" 32 - 33 - 34 - #define R_HORIZ_GRAM_ADDR_SET 0x200 35 - #define R_VERT_GRAM_ADDR_SET 0x201 36 - #define R_WRITE_DATA_TO_GRAM 0x202 37 - #define R_HORIZ_ADDR_START_POS 0x210 38 - #define R_HORIZ_ADDR_END_POS 0x211 39 - #define R_VERT_ADDR_START_POS 0x212 40 - #define R_VERT_ADDR_END_POS 0x213 41 - 21 + #include <stdlib.h> 22 + #include <stdint.h> 42 23 43 - /* LCD type 1 register defines */ 44 - 45 - #define R_COLUMN_ADDR_SET 0x2a 46 - #define R_ROW_ADDR_SET 0x2b 47 - #define R_MEMORY_WRITE 0x2c 24 + #include "config.h" 48 25 26 + #include "s5l87xx.h" 27 + #include "lcd-s5l8702.h" 49 28 50 - /** globals **/ 51 29 52 - int lcd_type; /* also needed in debug-s5l8702.c */ 53 - static struct mutex lcd_mutex; 54 - static uint16_t lcd_dblbuf[LCD_HEIGHT][LCD_WIDTH] CACHEALIGN_ATTR; 55 - static bool lcd_ispowered; 56 - 57 - #define CMD 0 /* send command with N data */ 58 - #define MREG 1 /* write multiple registers */ 59 - #define SLEEP 2 60 - #define END 0xff 61 - 62 - #define CMD16(len) (CMD | ((len) << 8)) 63 - #define MREG16(len) (MREG | ((len) << 8)) 64 - #define SLEEP16(t) (SLEEP | ((t) << 8)) 65 - 30 + #if defined(HAVE_LCD_SLEEP) || defined(HAVE_LCD_SHUTDOWN) 66 31 /* powersave sequences */ 67 32 68 - static const unsigned char lcd_sleep_seq_01[] = 33 + static const uint8_t lcd_sleep_seq_01[] = 69 34 { 70 - CMD, 0x28, 0, /* Display Off */ 71 - SLEEP, 5, /* 50 ms */ 72 - CMD, 0x10, 0, /* Sleep In Mode */ 73 - SLEEP, 5, /* 50 ms */ 35 + CMD, 0x28, 0, /* Display Off */ 36 + SLEEP, 5, /* 50 ms */ 37 + CMD, 0x10, 0, /* Sleep In */ 38 + SLEEP, 5, /* 50 ms */ 74 39 END 75 40 }; 76 41 77 - static const unsigned short lcd_enter_deepstby_seq_23[] = 42 + static const uint16_t lcd_deepstandby_seq_23[] = 78 43 { 79 44 /* Display Off */ 80 45 MREG16(1), 0x007, 0x0172, ··· 84 49 MREG16(1), 0x030, 0x0000, 85 50 MREG16(1), 0x100, 0x0780, 86 51 MREG16(1), 0x007, 0x0000, 52 + 53 + /* power supply off */ 87 54 MREG16(1), 0x101, 0x0260, 88 55 MREG16(1), 0x102, 0x00a9, 89 56 SLEEP16(3), ··· 94 61 SLEEP16(5), 95 62 END 96 63 }; 64 + #endif /* HAVE_LCD_SLEEP || HAVE_LCD_SHUTDOWN */ 97 65 98 - /* init sequences */ 66 + #ifdef HAVE_LCD_SLEEP 67 + /* awake sequences */ 99 68 100 - #ifdef HAVE_LCD_SLEEP 101 - static const unsigned char lcd_awake_seq_01[] = 69 + static const uint8_t lcd_awake_seq_01[] = 102 70 { 103 - CMD, 0x11, 0, /* Sleep Out Mode */ 104 - SLEEP, 6, /* 60 ms */ 105 - CMD, 0x29, 0, /* Display On */ 71 + CMD, 0x11, 0, /* Sleep Out */ 72 + SLEEP, 6, /* 60 ms */ 73 + CMD, 0x29, 0, /* Display On */ 106 74 END 107 75 }; 108 76 #endif 77 + 78 + // XXX: ili9340 DS: pag.168 B7H -> Entry Mode Set, DSTB -> enter this mode and tell how to exit 109 79 110 80 #if defined(HAVE_LCD_SLEEP) || defined(BOOTLOADER) 111 - static const unsigned short lcd_init_seq_23[] = 81 + /* init sequences */ 82 + 83 + static const uint16_t lcd_init_seq_23[] = 112 84 { 85 + #ifdef HAVE_LCD_SLEEP 86 + /* release from deep standby mode (ili9320 DS s12.3) */ 87 + CMD16, 0x000, /* NOP */ 88 + DELAY16(20), /* 1024 usecs */ 89 + CMD16, 0x000, 90 + DELAY16(20), 91 + CMD16, 0x000, 92 + DELAY16(20), 93 + CMD16, 0x000, 94 + DELAY16(20), 95 + CMD16, 0x000, 96 + DELAY16(20), 97 + CMD16, 0x000, 98 + DELAY16(20), 99 + #endif 100 + 113 101 /* Display settings */ 114 102 MREG16(1), 0x008, 0x0808, 115 103 MREG16(7), 0x010, 0x0013, 0x0300, 0x0101, 0x0a03, 0x0a0e, 0x0a19, 0x2402, ··· 124 112 MREG16(14), 0x320, 0x0206, 0x0102, 0x0404, 0x0303, 0x0300, 0x0407, 0x1c1f, 125 113 0x0206, 0x0102, 0x0404, 0x0303, 0x0300, 0x0407, 0x1c1f, 126 114 127 - /* GRAM and Base Imagen settings (ili9326ds) */ 115 + /* GRAM and Base Imagen settings (ili9326 DS) */ 128 116 MREG16(2), 0x400, 0x001d, 0x0001, 129 117 MREG16(1), 0x205, 0x0060, 130 118 ··· 149 137 MREG16(1), 0x007, 0x0173, 150 138 END 151 139 }; 152 - #endif /* HAVE_LCD_SLEEP || BOOTLOADER */ 153 140 154 141 #ifdef BOOTLOADER 155 - static const unsigned char lcd_init_seq_0[] = 142 + static const uint8_t lcd_init_seq_0[] = 156 143 { 157 - CMD, 0x11, 0, /* Sleep Out Mode */ 158 - SLEEP, 0x03, /* 30 ms */ 159 - CMD, 0x35, 1, 0x00, /* TEON (TBC) */ 160 - CMD, 0x3a, 1, 0x06, /* COLMOD (TBC) */ 161 - CMD, 0x36, 1, 0x00, /* MADCTR (TBC) */ 162 - CMD, 0x13, 0, /* NORON: Normal Mode On (Partial 163 - Mode Off, Scroll Mode Off) */ 144 + CMD, 0x11, 0, /* Sleep Out */ 145 + SLEEP, 3, /* 30 ms */ 146 + CMD, 0x35, 1, 0x00, /* Tearing Effect Line On */ 147 + CMD, 0x3a, 1, 0x06, /* Pixel Format Set */ 148 + CMD, 0x36, 1, 0x00, /* Memory Access Control */ 149 + 150 + CMD, 0x13, 0, /* Normal Mode On */ 164 151 CMD, 0x29, 0, /* Display On */ 165 152 END 166 153 }; 167 154 168 - static const unsigned char lcd_init_seq_1[] = 155 + static const uint8_t lcd_init_seq_1[] = 169 156 { 170 157 CMD, 0xb0, 21, 0x3a, 0x3a, 0x80, 0x80, 0x0a, 0x0a, 0x0a, 0x0a, 171 158 0x0a, 0x0a, 0x0a, 0x0a, 0x3c, 0x30, 0x0f, 0x00, ··· 177 164 0x14, 0x09, 0x15, 0x57, 0x27, 0x04, 0x05, 178 165 CMD, 0xd2, 1, 0x01, 179 166 180 - /* Gamma settings (TBC) */ 167 + /* Gamma settings */ 181 168 CMD, 0xe0, 13, 0x00, 0x00, 0x00, 0x05, 0x0b, 0x12, 0x16, 0x1f, 182 169 0x25, 0x22, 0x24, 0x29, 0x1c, 183 170 CMD, 0xe1, 13, 0x08, 0x01, 0x01, 0x06, 0x0b, 0x11, 0x15, 0x1f, ··· 191 178 CMD, 0xe5, 13, 0x07, 0x01, 0x01, 0x05, 0x09, 0x0f, 0x13, 0x1e, 192 179 0x26, 0x25, 0x28, 0x2e, 0x1e, 193 180 194 - CMD, 0x3a, 1, 0x06, /* COLMOD (TBC) */ 195 - CMD, 0xc2, 1, 0x00, /* Power Control 3 (TBC) */ 196 - CMD, 0x35, 1, 0x00, /* TEON (TBC) */ 197 - CMD, 0x11, 0, /* Sleep Out Mode */ 198 - SLEEP, 0x06, /* 60 ms */ 199 - CMD, 0x13, 0, /* NORON: Normal Mode On (Partial 200 - Mode Off, Scroll Mode Off) */ 181 + CMD, 0x3a, 1, 0x06, /* Pixel Format Set */ 182 + CMD, 0xc2, 1, 0x00, /* Power Control */ 183 + CMD, 0x35, 1, 0x00, /* Tearing Effect Line On */ 184 + 185 + CMD, 0x11, 0, /* Sleep Out */ 186 + SLEEP, 6, /* 60 ms */ 187 + CMD, 0x13, 0, /* Normal Mode On */ 201 188 CMD, 0x29, 0, /* Display On */ 202 189 END 203 190 }; 204 - #endif 191 + #endif /* BOOTLOADER */ 192 + #endif /* HAVE_LCD_SLEEP || BOOTLOADER */ 205 193 206 - /* DMA configuration */ 207 194 208 - /* one single transfer at once, needed LLIs: 209 - * screen_size / (DMAC_LLI_MAX_COUNT << swidth) = 210 - * (320*240*2) / (4095*2) = 19 211 - */ 212 - #define LCD_DMA_TSKBUF_SZ 1 /* N tasks, MUST be pow2 */ 213 - #define LCD_DMA_LLIBUF_SZ 32 /* N LLIs, MUST be pow2 */ 195 + static struct lcd_info_rec lcd_info_list[] = 196 + { 197 + [0] = { 198 + .lcd_type = 0, 199 + .mpuiface = LCD_MPUIFACE_PAR18, 200 + .cmdset = LCD_CMDSET_8BIT, 201 + #if defined(HAVE_LCD_SLEEP) || defined(HAVE_LCD_SHUTDOWN) 202 + .seq_sleep = (void*) lcd_sleep_seq_01, 203 + #endif 204 + #ifdef HAVE_LCD_SLEEP 205 + .seq_awake = (void*) lcd_awake_seq_01, 206 + #endif 207 + #ifdef BOOTLOADER 208 + .seq_init = (void*) lcd_init_seq_0, 209 + #endif 210 + }, 214 211 215 - static struct dmac_tsk lcd_dma_tskbuf[LCD_DMA_TSKBUF_SZ]; 216 - static struct dmac_lli volatile \ 217 - lcd_dma_llibuf[LCD_DMA_LLIBUF_SZ] CACHEALIGN_ATTR; 218 - 219 - static struct dmac_ch lcd_dma_ch = { 220 - .dmac = &s5l8702_dmac0, 221 - .prio = DMAC_CH_PRIO(4), 222 - .cb_fn = NULL, 223 - 224 - .tskbuf = lcd_dma_tskbuf, 225 - .tskbuf_mask = LCD_DMA_TSKBUF_SZ - 1, 226 - .queue_mode = QUEUE_NORMAL, 212 + [1] = { 213 + .lcd_type = 1, 214 + .mpuiface = LCD_MPUIFACE_PAR18, 215 + .cmdset = LCD_CMDSET_8BIT, 216 + #if defined(HAVE_LCD_SLEEP) || defined(HAVE_LCD_SHUTDOWN) 217 + .seq_sleep = (void*) lcd_sleep_seq_01, 218 + #endif 219 + #ifdef HAVE_LCD_SLEEP 220 + .seq_awake = (void*) lcd_awake_seq_01, 221 + #endif 222 + #ifdef BOOTLOADER 223 + .seq_init = (void*) lcd_init_seq_1, 224 + #endif 225 + }, 227 226 228 - .llibuf = lcd_dma_llibuf, 229 - .llibuf_mask = LCD_DMA_LLIBUF_SZ - 1, 230 - .llibuf_bus = DMAC_MASTER_AHB1, 231 - }; 227 + [2] = { 228 + .lcd_type = 2, 229 + .mpuiface = LCD_MPUIFACE_PAR18, 230 + .cmdset = LCD_CMDSET_16BIT, 231 + #if defined(HAVE_LCD_SLEEP) || defined(HAVE_LCD_SHUTDOWN) 232 + .seq_sleep = (void*) lcd_deepstandby_seq_23, 233 + #endif 234 + #ifdef HAVE_LCD_SLEEP 235 + .seq_awake = (void*) lcd_init_seq_23, 236 + #endif 237 + #ifdef BOOTLOADER 238 + .seq_init = (void*) lcd_init_seq_23, 239 + #endif 240 + }, 232 241 233 - static struct dmac_ch_cfg lcd_dma_ch_cfg = { 234 - .srcperi = S5L8702_DMAC0_PERI_MEM, 235 - .dstperi = S5L8702_DMAC0_PERI_LCD_WR, 236 - .sbsize = DMACCxCONTROL_BSIZE_1, 237 - .dbsize = DMACCxCONTROL_BSIZE_1, 238 - .swidth = DMACCxCONTROL_WIDTH_16, 239 - .dwidth = DMACCxCONTROL_WIDTH_16, 240 - .sbus = DMAC_MASTER_AHB1, 241 - .dbus = DMAC_MASTER_AHB1, 242 - .sinc = DMACCxCONTROL_INC_ENABLE, 243 - .dinc = DMACCxCONTROL_INC_DISABLE, 244 - .prot = DMAC_PROT_CACH | DMAC_PROT_BUFF | DMAC_PROT_PRIV, 245 - .lli_xfer_max_count = DMAC_LLI_MAX_COUNT, 242 + [3] = { 243 + .lcd_type = 3, 244 + .mpuiface = LCD_MPUIFACE_PAR18, 245 + .cmdset = LCD_CMDSET_16BIT, 246 + #if defined(HAVE_LCD_SLEEP) || defined(HAVE_LCD_SHUTDOWN) 247 + .seq_sleep = (void*) lcd_deepstandby_seq_23, 248 + #endif 249 + #ifdef HAVE_LCD_SLEEP 250 + .seq_awake = (void*) lcd_init_seq_23, 251 + #endif 252 + #ifdef BOOTLOADER 253 + .seq_init = (void*) lcd_init_seq_23, 254 + #endif 255 + }, 246 256 }; 247 257 248 - static inline void s5l_lcd_write_reg(int cmd, unsigned int data) 249 - { 250 - while (LCD_STATUS & 0x10); 251 - LCD_WCMD = cmd; 252 - 253 - while (LCD_STATUS & 0x10); 254 - /* 16-bit/1-transfer data format (ili9320ds s7.2.2) */ 255 - LCD_WDATA = (data & 0x78ff) | 256 - ((data & 0x0300) << 1) | ((data & 0x0400) << 5); 257 - } 258 - 259 - static inline void s5l_lcd_write_cmd(unsigned short cmd) 260 - { 261 - while (LCD_STATUS & 0x10); 262 - LCD_WCMD = cmd; 263 - } 264 - 265 - static inline void s5l_lcd_write_data(unsigned short data) 266 - { 267 - while (LCD_STATUS & 0x10); 268 - LCD_WDATA = data; 269 - } 270 - 271 - static void lcd_run_seq8(const unsigned char *seq) 258 + struct lcd_info_rec* lcd_target_get_info(void) 272 259 { 273 - int n; 274 - 275 - while (1) switch (*seq++) 276 - { 277 - case CMD: 278 - s5l_lcd_write_cmd(*seq++); 279 - n = *seq++; 280 - while (n--) 281 - s5l_lcd_write_data(*seq++); 282 - break; 283 - case SLEEP: 284 - sleep(*seq++); 285 - break; 286 - case END: 287 - default: 288 - /* bye */ 289 - return; 290 - } 291 - } 292 - 293 - static void lcd_run_seq16(const unsigned short *seq) 294 - { 295 - int action, param; 296 - unsigned short reg; 297 - 298 - while (1) 299 - { 300 - action = *seq & 0xff; 301 - param = *seq++ >> 8; 302 - 303 - switch (action) 304 - { 305 - case MREG: 306 - reg = *seq++; 307 - while (param--) 308 - s5l_lcd_write_reg(reg++, *seq++); 309 - break; 310 - case SLEEP: 311 - sleep(param); 312 - break; 313 - case END: 314 - default: 315 - /* bye */ 316 - return; 317 - } 318 - } 319 - } 320 - 321 - /*** hardware configuration ***/ 322 - 323 - int lcd_default_contrast(void) 324 - { 325 - return 0x1f; 326 - } 327 - 328 - void lcd_set_contrast(int val) 329 - { 330 - (void)val; 331 - } 332 - 333 - void lcd_set_invert_display(bool yesno) 334 - { 335 - (void)yesno; 336 - } 337 - 338 - void lcd_set_flip(bool yesno) 339 - { 340 - (void)yesno; 341 - } 342 - 343 - bool lcd_active(void) 344 - { 345 - return lcd_ispowered; 346 - } 347 - 348 - void lcd_powersave(void) 349 - { 350 - mutex_lock(&lcd_mutex); 351 - 352 - if (lcd_type & 2) 353 - lcd_run_seq16(lcd_enter_deepstby_seq_23); 354 - else 355 - lcd_run_seq8(lcd_sleep_seq_01); 356 - 357 - /* mask lcd controller clock gate */ 358 - PWRCON(0) |= (1 << CLOCKGATE_LCD); 359 - 360 - lcd_ispowered = false; 361 - 362 - mutex_unlock(&lcd_mutex); 363 - } 364 - 365 - void lcd_shutdown(void) 366 - { 367 - pmu_write(0x2b, 0); /* Kill the backlight, instantly. */ 368 - pmu_write(0x29, 0); 369 - 370 - lcd_powersave(); 371 - } 372 - 373 - #ifdef HAVE_LCD_SLEEP 374 - void lcd_sleep(void) 375 - { 376 - lcd_powersave(); 377 - } 378 - 379 - void lcd_awake(void) 380 - { 381 - mutex_lock(&lcd_mutex); 382 - 383 - /* unmask lcd controller clock gate */ 384 - PWRCON(0) &= ~(1 << CLOCKGATE_LCD); 385 - 386 - if (lcd_type & 2) { 387 - /* release from deep standby mode (ili9320ds s12.3) */ 388 - for (int i = 0; i < 6; i++) { 389 - s5l_lcd_write_cmd(0x000); 390 - udelay(1000); 391 - } 392 - 393 - lcd_run_seq16(lcd_init_seq_23); 394 - } 395 - else 396 - lcd_run_seq8(lcd_awake_seq_01); 397 - 398 - lcd_ispowered = true; 399 - 400 - mutex_unlock(&lcd_mutex); 401 - 402 - send_event(LCD_EVENT_ACTIVATION, NULL); 403 - } 404 - #endif 405 - 406 - /* LCD init */ 407 - void lcd_init_device(void) 408 - { 409 - mutex_init(&lcd_mutex); 410 - 411 - /* unmask lcd controller clock gate */ 412 - PWRCON(0) &= ~(1 << CLOCKGATE_LCD); 413 - 414 - /* Detect lcd type */ 415 - lcd_type = (PDAT6 & 0x30) >> 4; 416 - 417 - while (!(LCD_STATUS & 0x2)); 418 - LCD_CON = 0x80100db0; 419 - LCD_PHTIME = 0x33; 420 - 421 - /* Configure DMA channel */ 422 - dmac_ch_init(&lcd_dma_ch, &lcd_dma_ch_cfg); 423 - 424 - #ifdef BOOTLOADER 425 - switch (lcd_type) { 426 - case 0: lcd_run_seq8(lcd_init_seq_0); break; 427 - case 1: lcd_run_seq8(lcd_init_seq_1); break; 428 - default: lcd_run_seq16(lcd_init_seq_23); break; 429 - } 430 - #endif 431 - 432 - lcd_ispowered = true; 433 - } 434 - 435 - /*** Update functions ***/ 436 - 437 - static inline void lcd_write_pixel(fb_data pixel) 438 - { 439 - mutex_lock(&lcd_mutex); 440 - LCD_WDATA = pixel; 441 - mutex_unlock(&lcd_mutex); 442 - } 443 - 444 - /* Update the display. 445 - This must be called after all other LCD functions that change the display. */ 446 - void lcd_update(void) ICODE_ATTR; 447 - void lcd_update(void) 448 - { 449 - lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT); 450 - } 451 - 452 - /* Line write helper function. */ 453 - extern void lcd_write_line(const fb_data *addr, 454 - int pixelcount, 455 - const unsigned int lcd_base_addr); 456 - 457 - static void displaylcd_setup(int x, int y, int width, int height) ICODE_ATTR; 458 - static void displaylcd_setup(int x, int y, int width, int height) 459 - { 460 - /* TODO: ISR()->panicf()->lcd_update() blocks forever */ 461 - mutex_lock(&lcd_mutex); 462 - while (dmac_ch_running(&lcd_dma_ch)) 463 - yield(); 464 - 465 - int xe = (x + width) - 1; /* max horiz */ 466 - int ye = (y + height) - 1; /* max vert */ 467 - 468 - if (lcd_type & 2) { 469 - s5l_lcd_write_reg(R_HORIZ_ADDR_START_POS, x); 470 - s5l_lcd_write_reg(R_HORIZ_ADDR_END_POS, xe); 471 - s5l_lcd_write_reg(R_VERT_ADDR_START_POS, y); 472 - s5l_lcd_write_reg(R_VERT_ADDR_END_POS, ye); 473 - 474 - s5l_lcd_write_reg(R_HORIZ_GRAM_ADDR_SET, x); 475 - s5l_lcd_write_reg(R_VERT_GRAM_ADDR_SET, y); 476 - 477 - s5l_lcd_write_cmd(R_WRITE_DATA_TO_GRAM); 478 - } else { 479 - s5l_lcd_write_cmd(R_COLUMN_ADDR_SET); 480 - s5l_lcd_write_data(x >> 8); 481 - s5l_lcd_write_data(x & 0xff); 482 - s5l_lcd_write_data(xe >> 8); 483 - s5l_lcd_write_data(xe & 0xff); 484 - 485 - s5l_lcd_write_cmd(R_ROW_ADDR_SET); 486 - s5l_lcd_write_data(y >> 8); 487 - s5l_lcd_write_data(y & 0xff); 488 - s5l_lcd_write_data(ye >> 8); 489 - s5l_lcd_write_data(ye & 0xff); 490 - 491 - s5l_lcd_write_cmd(R_MEMORY_WRITE); 492 - } 493 - } 494 - 495 - static void displaylcd_dma(int pixels) ICODE_ATTR; 496 - static void displaylcd_dma(int pixels) 497 - { 498 - commit_dcache(); 499 - dmac_ch_queue(&lcd_dma_ch, lcd_dblbuf, 500 - (void*)S5L8702_DADDR_PERI_LCD_WR, pixels*2, NULL); 501 - mutex_unlock(&lcd_mutex); 502 - } 503 - 504 - /* Update a fraction of the display. */ 505 - void lcd_update_rect(int, int, int, int) ICODE_ATTR; 506 - void lcd_update_rect(int x, int y, int width, int height) 507 - { 508 - int pixels = width * height; 509 - fb_data* p = FBADDR(x,y); 510 - uint16_t* out = lcd_dblbuf[0]; 511 - 512 - #ifdef HAVE_LCD_SLEEP 513 - if (!lcd_active()) return; 514 - #endif 515 - 516 - displaylcd_setup(x, y, width, height); 517 - 518 - /* Copy display bitmap to hardware */ 519 - if (LCD_WIDTH == width) { 520 - /* Write all lines at once */ 521 - memcpy(out, p, pixels * 2); 522 - } else { 523 - do { 524 - /* Write a single line */ 525 - memcpy(out, p, width * 2); 526 - p += LCD_WIDTH; 527 - out += width; 528 - } while (--height); 529 - } 530 - 531 - displaylcd_dma(pixels); 532 - } 533 - 534 - /* Line write helper function for lcd_yuv_blit. Writes two lines of yuv420. */ 535 - extern void lcd_write_yuv420_lines(unsigned char const * const src[3], 536 - uint16_t* outbuf, 537 - int width, 538 - int stride); 539 - 540 - /* Blit a YUV bitmap directly to the LCD */ 541 - void lcd_blit_yuv(unsigned char * const src[3], 542 - int src_x, int src_y, int stride, 543 - int x, int y, int width, int height) ICODE_ATTR; 544 - void lcd_blit_yuv(unsigned char * const src[3], 545 - int src_x, int src_y, int stride, 546 - int x, int y, int width, int height) 547 - { 548 - unsigned int z; 549 - unsigned char const * yuv_src[3]; 550 - 551 - #ifdef HAVE_LCD_SLEEP 552 - if (!lcd_active()) return; 553 - #endif 554 - 555 - width = (width + 1) & ~1; /* ensure width is even */ 556 - 557 - int pixels = width * height; 558 - uint16_t* out = lcd_dblbuf[0]; 559 - 560 - z = stride * src_y; 561 - yuv_src[0] = src[0] + z + src_x; 562 - yuv_src[1] = src[1] + (z >> 2) + (src_x >> 1); 563 - yuv_src[2] = src[2] + (yuv_src[1] - src[1]); 564 - 565 - displaylcd_setup(x, y, width, height); 566 - 567 - height >>= 1; 568 - 569 - do { 570 - lcd_write_yuv420_lines(yuv_src, out, width, stride); 571 - yuv_src[0] += stride << 1; 572 - yuv_src[1] += stride >> 1; /* Skip down one chroma line */ 573 - yuv_src[2] += stride >> 1; 574 - out += width << 1; 575 - } while (--height); 576 - 577 - displaylcd_dma(pixels); 260 + return &lcd_info_list[(PDAT6 & 0x30) >> 4]; 578 261 }
firmware/target/arm/s5l8702/ipod6g/lcd-asm-6g.S firmware/target/arm/s5l8702/lcd-asm-s5l8702.S
+35
firmware/target/arm/s5l8702/ipod6g/lcd-target.h
··· 1 + /*************************************************************************** 2 + * __________ __ ___. 3 + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 + * \/ \/ \/ \/ \/ 8 + * $Id: lcd-nano2g.c 28868 2010-12-21 06:59:17Z Buschel $ 9 + * 10 + * Copyright (C) 2009 by Dave Chapman 11 + * 12 + * This program is free software; you can redistribute it and/or 13 + * modify it under the terms of the GNU General Public License 14 + * as published by the Free Software Foundation; either version 2 15 + * of the License, or (at your option) any later version. 16 + * 17 + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 18 + * KIND, either express or implied. 19 + * 20 + ****************************************************************************/ 21 + #ifndef __LCD_TARGET_H__ 22 + #define __LCD_TARGET_H__ 23 + 24 + // #include "config.h" 25 + 26 + /* define this to add support for LCDs with 16-bit command set */ 27 + #define S5L_LCD_WITH_CMDSET16 28 + 29 + /* define this to include support for LCD read ID command */ 30 + // #define S5L_LCD_WITH_READID 31 + 32 + // struct lcd_info_rec* lcd_target_get_info(void); 33 + 34 + 35 + #endif /* __LCD_TARGET_H__ */
+615
firmware/target/arm/s5l8702/lcd-s5l8702.c
··· 1 + /*************************************************************************** 2 + * __________ __ ___. 3 + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 + * \/ \/ \/ \/ \/ 8 + * $Id: lcd-nano2g.c 28868 2010-12-21 06:59:17Z Buschel $ 9 + * 10 + * Copyright (C) 2009 by Dave Chapman 11 + * 12 + * This program is free software; you can redistribute it and/or 13 + * modify it under the terms of the GNU General Public License 14 + * as published by the Free Software Foundation; either version 2 15 + * of the License, or (at your option) any later version. 16 + * 17 + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 18 + * KIND, either express or implied. 19 + * 20 + ****************************************************************************/ 21 + #include <stdint.h> 22 + #include <stdbool.h> 23 + #include <string.h> 24 + 25 + #include "config.h" 26 + 27 + #include "kernel.h" 28 + #include "system.h" 29 + #include "cpu.h" 30 + #include "lcd.h" 31 + #ifdef IPOD_6G 32 + #include "pmu-target.h" 33 + #endif 34 + #include "backlight-target.h" 35 + 36 + #include "s5l87xx.h" 37 + #include "clocking-s5l8702.h" 38 + #include "dma-s5l8702.h" 39 + #include "lcd-s5l8702.h" 40 + #include "lcd-target.h" 41 + 42 + 43 + // TODO TODO TODO: HAVE_LCD_ENABLE 44 + 45 + /* Switch command/frame mode: 46 + * 47 + * XXX: WIP, TBC 48 + * 49 + * Configures MPU interface and pixel mode. 50 + * 51 + * Frame mode: 52 + * 6g: 53 + * 16-bit 8080-series parallel MPU interface 54 + * pixel mode: RBG565/1-transfer 55 + * APB[15:0] -> D[17:10,8:1] 56 + * nano3g: 57 + * 9-bit 8080-series parallel PMU interface (TBC) 58 + * pixel mode: RGB565/2-transfers (TBC) 59 + * APB[15:0] -> D[8:1] + D[8:1] (TBC) 60 + * 61 + * Command mode: 62 + * LCD HW that uses 8-bit command set (6g, nano3g): 63 + * 8-bit 8080-series parallel MPU interface 64 + * APB[7:0] -> D[8:1] 65 + * LCD HW that uses 16-bit command set (6g): 66 + * 18-bit 8080-series parallel MPU interface (TBC) 67 + * APB[15:0] -> D[17:10,8:1] 68 + * 69 + * See ILI9320, ILI9326, ILI9340 DS. 70 + */ 71 + /* XXX: see ili9340, pg.27 for MCU interface selection, 72 + * bit31 could be the one that selects interface D[7:0] or D[8:1] for 8-bit), Type-I uses D[7:0] and Type-II uses D[17:10] (ILI9340) 73 + * 9-bit D[8:0] D[17:9] 74 + * 16-bit D[15:0] D[17:10],D[8:1] 75 + * 18-bit D[17:0] D[17:0] 76 + * bit24 could be the one that selects interface D[8:1] or D[17:10] 77 + * MCU_interface Mode Pins Write Read 78 + * #define LCD_MODE_8 0x80000c20 8080 MCU 8-bit bus iface D[8:1] APB[7:0] -> D[8:1] D[8:1] -> LCD_DBUFF[8:1] 79 + * #define LCD_MODE_9 0x81100db8 9-bit 80 + * #define LCD_MODE_16 0x80100db0 16-bit D[17:10,8:1] APB[15:0] -> D[17:10,8:1] 81 + * #define LCD_MODE_18 0x80000da8 18-bit D[17:0] APB[17:0] -> D[17:0] (TBC) 82 + * 83 + * #define LCD_MODE_8 0x80000c20 // LCD_MODE_P8T1 // paralled 8-bit, 1 transfer, TBC: DB[17:10] or DB[8:1] ??? 84 + * #define LCD_MODE_9 0x81100db8 // LCD_MODE_P9T2 // TBC: DB[8:1] or DB[17:10] ???, 2-transfers or 1.5-transfers, RGB565 or RBG666 ??? 85 + * #define LCD_MODE_16 0x80100db0 // LCD_MODE_P16T1 // TBC: DB[17:10,8:1] 86 + * #define LCD_MODE_18 0x80000da8 // LCD_MODE_P18T1 // TBC: DB[17:10,8:1] 87 + */ 88 + 89 + #define LCD_MODE_P8 0x80000c20 // LCD_MODE_P8T1 // paralled 8-bit, 1 transfer, TBC: DB[17:10] or DB[8:1] ??? 90 + #define LCD_MODE_P8b 0x80100c20 // TODO: see if it influences, so far we are using it in nano3g with 0x80000c20 and it seems to be working fine 91 + // It may be a "pixel format" setting for 8 bit, which would only affect DATA and not CMD ??? 92 + #define LCD_MODE_P9 0x81100db8 // LCD_MODE_P9T2 // TBC: DB[8:1] or DB[17:10] ???, 2-transfers or 1.5-transfers, RGB565 or RBG666 ??? 93 + #define LCD_MODE_P16 0x80100db0 // LCD_MODE_P16T1 // TBC: DB[17:10,8:1] 94 + #define LCD_MODE_P18 0x80000da8 // LCD_MODE_P18T1 // TBC: DB[17:10,8:1] 95 + 96 + #define LCD_MODE_S8 0x41000c20 // nano4g 97 + #define LCD_MODE_S9 0x41100db8 // nano4g 98 + 99 + 100 + 101 + #ifdef S5L_LCD_WITH_CMDSET16 102 + /* LCD type 16-bit register defines */ 103 + #define R_HORIZ_GRAM_ADDR_SET 0x200 104 + #define R_VERT_GRAM_ADDR_SET 0x201 105 + #define R_WRITE_DATA_TO_GRAM 0x202 106 + #define R_HORIZ_ADDR_START_POS 0x210 107 + #define R_HORIZ_ADDR_END_POS 0x211 108 + #define R_VERT_ADDR_START_POS 0x212 109 + #define R_VERT_ADDR_END_POS 0x213 110 + #endif 111 + 112 + /* LCD type 8-bit register defines */ 113 + #define R_COLUMN_ADDR_SET 0x2a 114 + #define R_ROW_ADDR_SET 0x2b 115 + #define R_MEMORY_WRITE 0x2c 116 + 117 + 118 + /** globals **/ 119 + 120 + int lcd_type; /* also needed in debug-s5l8702.c */ 121 + static struct mutex lcd_mutex; 122 + static uint16_t lcd_dblbuf[LCD_HEIGHT][LCD_WIDTH] CACHEALIGN_ATTR; 123 + static bool lcd_ispowered; 124 + 125 + /* TODO: there is no info about these specific drivers, 126 + some useful info on similar HW such as ILI9320, ILI9326, ILI9340 and */ 127 + 128 + static struct lcd_info_rec *lcd_info; 129 + static void (*lcd_run_seq)(void*); 130 + 131 + /* LCD_CONFIG values for command/frame modes */ 132 + static uint32_t lcd_cmd_mode IDATA_ATTR; 133 + static uint32_t lcd_frame_mode IDATA_ATTR; 134 + 135 + 136 + // TODO 137 + /* Each target must define a list containing all supported LCD types */ 138 + // extern struct lcd_info_rec lcd_info_list[]; 139 + // static struct lcd_info_rec lcd_info_list[]; 140 + 141 + 142 + /* DMA configuration */ 143 + 144 + /* One single transfer at once, needed LLIs: 145 + * screen_size / (DMAC_LLI_MAX_COUNT << swidth) = 146 + * (320*240*2) / (4095*2) = 19 147 + */ 148 + #define LCD_DMA_TSKBUF_SZ 1 /* N tasks, MUST be pow2 */ 149 + #define LCD_DMA_LLIBUF_SZ 32 /* N LLIs, MUST be pow2 */ 150 + 151 + static struct dmac_tsk lcd_dma_tskbuf[LCD_DMA_TSKBUF_SZ]; 152 + static struct dmac_lli volatile \ 153 + lcd_dma_llibuf[LCD_DMA_LLIBUF_SZ] CACHEALIGN_ATTR; 154 + 155 + static struct dmac_ch lcd_dma_ch = 156 + { 157 + .dmac = &s5l8702_dmac0, 158 + .prio = DMAC_CH_PRIO(4), 159 + .cb_fn = NULL, 160 + 161 + .tskbuf = lcd_dma_tskbuf, 162 + .tskbuf_mask = LCD_DMA_TSKBUF_SZ - 1, 163 + .queue_mode = QUEUE_NORMAL, 164 + 165 + .llibuf = lcd_dma_llibuf, 166 + .llibuf_mask = LCD_DMA_LLIBUF_SZ - 1, 167 + .llibuf_bus = DMAC_MASTER_AHB1, 168 + }; 169 + 170 + static struct dmac_ch_cfg lcd_dma_ch_cfg = 171 + { 172 + .srcperi = S5L8702_DMAC0_PERI_MEM, 173 + .dstperi = S5L8702_DMAC0_PERI_LCD_WR, 174 + .sbsize = DMACCxCONTROL_BSIZE_1, 175 + .dbsize = DMACCxCONTROL_BSIZE_1, 176 + .swidth = DMACCxCONTROL_WIDTH_16, 177 + .dwidth = DMACCxCONTROL_WIDTH_16, 178 + .sbus = DMAC_MASTER_AHB1, 179 + .dbus = DMAC_MASTER_AHB1, 180 + .sinc = DMACCxCONTROL_INC_ENABLE, 181 + .dinc = DMACCxCONTROL_INC_DISABLE, 182 + .prot = DMAC_PROT_CACH | DMAC_PROT_BUFF | DMAC_PROT_PRIV, 183 + .lli_xfer_max_count = DMAC_LLI_MAX_COUNT, 184 + }; 185 + 186 + 187 + /*** clocks ***/ 188 + 189 + // TODO: In mks5lboot --mkraw put a command to specify the address of the binary, 190 + // for example --address 0x6000, it must be greater than 0x310 which would be the default address, 191 + // pass this address (0x310..128Kb) in the dfu_options flag 192 + 193 + // TODO: to lcd-target.c 194 + static void lcd_target_enable_clocks(bool enable) 195 + { 196 + clockgate_enable(CLOCKGATE_LCD, enable); 197 + #ifdef IPOD_NANO4G 198 + clockgate_enable(CLOCKGATE_LCD_2, enable); 199 + #endif 200 + } 201 + 202 + 203 + /*** LCD controller - low level functions ***/ 204 + 205 + static void s5l_lcd_write_config(uint32_t config) ICODE_ATTR; 206 + static void s5l_lcd_write_config(uint32_t config) 207 + { 208 + while (!(LCD_STATUS & 0x2)); 209 + udelay(1); 210 + LCD_CON = config; 211 + } 212 + 213 + static void s5l_lcd_write_cmd(uint16_t cmd) ICODE_ATTR; 214 + static void s5l_lcd_write_cmd(uint16_t cmd) 215 + { 216 + while (LCD_STATUS & 0x10); 217 + LCD_WCMD = cmd; 218 + } 219 + 220 + static void s5l_lcd_write_data(uint16_t data) ICODE_ATTR; 221 + static void s5l_lcd_write_data(uint16_t data) 222 + { 223 + while (LCD_STATUS & 0x10); 224 + LCD_WDATA = data; 225 + } 226 + 227 + static void s5l_lcd_send_cmd8(uint8_t cmd, int len, uint8_t *data) ICODE_ATTR; 228 + static void s5l_lcd_send_cmd8(uint8_t cmd, int len, uint8_t *data) 229 + { 230 + s5l_lcd_write_cmd(cmd); 231 + while (len--) 232 + s5l_lcd_write_data(*data++); 233 + } 234 + 235 + #ifdef S5L_LCD_WITH_READID 236 + static void s5l_lcd_recv_cmd8(uint8_t cmd, int len, uint8_t *buf) 237 + { 238 + s5l_lcd_write_cmd(cmd); 239 + while (len--) { 240 + while (!(LCD_STATUS & 0x2)); 241 + LCD_RDATA = 0; 242 + while (!(LCD_STATUS & 1)); 243 + *buf++ = LCD_DBUFF >> 1; 244 + } 245 + } 246 + #endif 247 + 248 + #define s5l_lcd_set_command_mode() s5l_lcd_write_config(lcd_cmd_mode) 249 + #define s5l_lcd_set_frame_mode() s5l_lcd_write_config(lcd_frame_mode) 250 + 251 + static void s5l_lcd_run_seq8(void *seq8) 252 + { 253 + uint8_t *seq = seq8; 254 + 255 + while (1) switch (*seq++) 256 + { 257 + case CMD: 258 + { 259 + uint8_t cmd = *seq++; 260 + int len = *seq++; 261 + s5l_lcd_send_cmd8(cmd, len, seq); 262 + seq += len; 263 + break; 264 + } 265 + case SLEEP: 266 + sleep(*seq++); 267 + break; 268 + case END: 269 + default: 270 + /* bye */ 271 + return; 272 + } 273 + } 274 + 275 + #ifdef S5L_LCD_WITH_CMDSET16 276 + static void s5l_lcd_write_reg(uint16_t cmd, uint16_t data) ICODE_ATTR; 277 + static void s5l_lcd_write_reg(uint16_t cmd, uint16_t data) 278 + { 279 + s5l_lcd_write_cmd(cmd); 280 + s5l_lcd_write_data(data); 281 + } 282 + 283 + static void s5l_lcd_run_seq16(void *seq16) 284 + { 285 + uint16_t *seq = seq16; 286 + int action, param; 287 + uint16_t reg; 288 + 289 + while (1) 290 + { 291 + action = *seq & 0xff; 292 + param = *seq++ >> 8; 293 + 294 + switch (action) 295 + { 296 + case CMD: 297 + s5l_lcd_write_cmd(*seq++); 298 + break; 299 + case MREG: 300 + reg = *seq++; 301 + while (param--) 302 + s5l_lcd_write_reg(reg++, *seq++); 303 + break; 304 + case SLEEP: 305 + sleep(param); 306 + break; 307 + case DELAY: 308 + udelay(param<<6); 309 + break; 310 + case END: 311 + default: 312 + /* bye */ 313 + return; 314 + } 315 + } 316 + } 317 + #endif /* S5L_LCD_WITH_CMDSET16 */ 318 + 319 + 320 + /*** Update functions ***/ 321 + 322 + /* Update the display. 323 + This must be called after all other LCD functions that change the display. */ 324 + void lcd_update(void) ICODE_ATTR; 325 + void lcd_update(void) 326 + { 327 + lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT); 328 + } 329 + 330 + static void displaylcd_setup(int x, int y, int width, int height) ICODE_ATTR; 331 + static void displaylcd_setup(int x, int y, int width, int height) 332 + { 333 + int xe = (x + width) - 1; /* max horiz */ 334 + int ye = (y + height) - 1; /* max vert */ 335 + 336 + s5l_lcd_set_command_mode(); 337 + 338 + #ifdef S5L_LCD_WITH_CMDSET16 339 + if (lcd_info->cmdset == LCD_CMDSET_16BIT) 340 + { 341 + s5l_lcd_write_reg(R_HORIZ_ADDR_START_POS, x); 342 + s5l_lcd_write_reg(R_HORIZ_ADDR_END_POS, xe); 343 + s5l_lcd_write_reg(R_VERT_ADDR_START_POS, y); 344 + s5l_lcd_write_reg(R_VERT_ADDR_END_POS, ye); 345 + 346 + s5l_lcd_write_reg(R_HORIZ_GRAM_ADDR_SET, x); 347 + s5l_lcd_write_reg(R_VERT_GRAM_ADDR_SET, y); 348 + 349 + s5l_lcd_write_cmd(R_WRITE_DATA_TO_GRAM); 350 + } 351 + else 352 + #endif 353 + { 354 + uint8_t col[] = { x >> 8, x & 0xff, xe >> 8, xe & 0xff }; 355 + uint8_t row[] = { y >> 8, y & 0xff, ye >> 8, ye & 0xff }; 356 + s5l_lcd_send_cmd8(R_COLUMN_ADDR_SET, 4, col); 357 + s5l_lcd_send_cmd8(R_ROW_ADDR_SET, 4, row); 358 + 359 + s5l_lcd_write_cmd(R_MEMORY_WRITE); 360 + } 361 + } 362 + 363 + static void displaylcd_dma(int pixels) ICODE_ATTR; 364 + static void displaylcd_dma(int pixels) 365 + { 366 + s5l_lcd_set_frame_mode(); 367 + commit_dcache(); 368 + dmac_ch_queue(&lcd_dma_ch, lcd_dblbuf, 369 + (void*)S5L8702_DADDR_PERI_LCD_WR, pixels*2, NULL); 370 + } 371 + 372 + // TODO: wait if there is a DMA transfer in progress 373 + static void displaylcd_wait_dma(void) ICODE_ATTR; 374 + static void displaylcd_wait_dma(void) 375 + { 376 + while (dmac_ch_running(&lcd_dma_ch)) 377 + yield(); 378 + } 379 + 380 + /* Update a fraction of the display. */ 381 + void lcd_update_rect(int, int, int, int) ICODE_ATTR; 382 + void lcd_update_rect(int x, int y, int width, int height) 383 + { 384 + int pixels = width * height; 385 + fb_data* p = FBADDR(x,y); 386 + uint16_t* out = lcd_dblbuf[0]; 387 + 388 + /* FIXME: ISR()->panicf()->lcd_update() blocks forever */ 389 + mutex_lock(&lcd_mutex); 390 + if (lcd_ispowered) 391 + { 392 + // XXX: We contemplate the case where the LCD has entered SLEEP, 393 + // the s5l_lcd_set_command_mode() writes LCD_CONFIG 394 + // XXX: It is also possible that if the LCD clockgate has been disabled, 395 + // the LCD_CONFIG = xxx may still be blocked by the while(status == ok), 396 + // since it does not check the same status bit as when writing command/data 397 + 398 + displaylcd_wait_dma(); 399 + 400 + displaylcd_setup(x, y, width, height); 401 + 402 + /* Copy display bitmap to hardware */ 403 + if (LCD_WIDTH == width) { 404 + /* Write all lines at once */ 405 + memcpy(out, p, pixels * 2); 406 + } else { 407 + do { 408 + /* Write a single line */ 409 + memcpy(out, p, width * 2); 410 + p += LCD_WIDTH; 411 + out += width; 412 + } while (--height); 413 + } 414 + 415 + displaylcd_dma(pixels); 416 + } 417 + mutex_unlock(&lcd_mutex); 418 + } 419 + 420 + /* Line write helper function for lcd_yuv_blit. Writes two lines of yuv420. */ 421 + extern void lcd_write_yuv420_lines(unsigned char const * const src[3], 422 + uint16_t* outbuf, 423 + int width, 424 + int stride); 425 + 426 + /* Blit a YUV bitmap directly to the LCD */ 427 + void lcd_blit_yuv(unsigned char * const src[3], 428 + int src_x, int src_y, int stride, 429 + int x, int y, int width, int height) ICODE_ATTR; 430 + void lcd_blit_yuv(unsigned char * const src[3], 431 + int src_x, int src_y, int stride, 432 + int x, int y, int width, int height) 433 + { 434 + unsigned int z; 435 + unsigned char const * yuv_src[3]; 436 + 437 + width = (width + 1) & ~1; /* ensure width is even */ 438 + 439 + int pixels = width * height; 440 + uint16_t* out = lcd_dblbuf[0]; 441 + 442 + z = stride * src_y; 443 + yuv_src[0] = src[0] + z + src_x; 444 + yuv_src[1] = src[1] + (z >> 2) + (src_x >> 1); 445 + yuv_src[2] = src[2] + (yuv_src[1] - src[1]); 446 + 447 + /* TODO: ISR()->panicf()->lcd_update() blocks forever */ 448 + mutex_lock(&lcd_mutex); 449 + if (lcd_ispowered) 450 + { 451 + displaylcd_wait_dma(); 452 + 453 + displaylcd_setup(x, y, width, height); 454 + 455 + height >>= 1; 456 + 457 + do { 458 + lcd_write_yuv420_lines(yuv_src, out, width, stride); 459 + yuv_src[0] += stride << 1; 460 + yuv_src[1] += stride >> 1; /* Skip down one chroma line */ 461 + yuv_src[2] += stride >> 1; 462 + out += width << 1; 463 + } while (--height); 464 + 465 + displaylcd_dma(pixels); 466 + } 467 + mutex_unlock(&lcd_mutex); 468 + } 469 + 470 + 471 + /*** hardware configuration ***/ 472 + 473 + int lcd_default_contrast(void) 474 + { 475 + return 0x1f; 476 + } 477 + 478 + void lcd_set_contrast(int val) 479 + { 480 + (void)val; 481 + } 482 + 483 + void lcd_set_invert_display(bool yesno) 484 + { 485 + (void)yesno; 486 + } 487 + 488 + void lcd_set_flip(bool yesno) 489 + { 490 + (void)yesno; 491 + } 492 + 493 + #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP) 494 + bool lcd_active(void) 495 + { 496 + return lcd_ispowered; 497 + } 498 + #endif 499 + 500 + #if defined(HAVE_LCD_SHUTDOWN) || defined(HAVE_LCD_SLEEP) 501 + static void lcd_powersave(void) 502 + { 503 + mutex_lock(&lcd_mutex); 504 + 505 + displaylcd_wait_dma(); 506 + // XXX: Do not change modes while data is being sent 507 + s5l_lcd_set_command_mode(); 508 + lcd_run_seq(lcd_info->seq_sleep); 509 + 510 + lcd_target_enable_clocks(false); 511 + 512 + lcd_ispowered = false; 513 + 514 + mutex_unlock(&lcd_mutex); 515 + } 516 + #endif /* HAVE_LCD_SHUTDOWN || HAVE_LCD_SLEEP */ 517 + 518 + #ifdef HAVE_LCD_SHUTDOWN 519 + void lcd_shutdown(void) 520 + { 521 + backlight_hw_kill(); /* Kill the backlight, instantly. */ 522 + lcd_powersave(); 523 + } 524 + #endif 525 + 526 + #ifdef HAVE_LCD_SLEEP 527 + void lcd_sleep(void) 528 + { 529 + lcd_powersave(); 530 + } 531 + 532 + void lcd_awake(void) 533 + { 534 + mutex_lock(&lcd_mutex); 535 + 536 + lcd_target_enable_clocks(true); 537 + // XXX: Do not change modes while data is being sent 538 + s5l_lcd_set_command_mode(); 539 + lcd_run_seq(lcd_info->seq_awake); 540 + lcd_ispowered = true; // XXX: we have to put the lcd_ispowered before the lcd_update() 541 + 542 + lcd_update(); // XXX: update the display and wait for the update to finish before returning, 543 + 544 + displaylcd_wait_dma(); // we should really do sleep_out + lcd_update + display_on, 545 + // we can put a command in the sequence to do it 546 + 547 + mutex_unlock(&lcd_mutex); 548 + send_event(LCD_EVENT_ACTIVATION, NULL); 549 + } 550 + #endif 551 + 552 + #ifdef S5L_LCD_WITH_READID 553 + // TODO: protect it with mutex and while(dma) if you want to call it from other places (e.g. DEBUG) 554 + void lcd_read_display_id(int mpuiface, uint8_t *lcd_id) 555 + { 556 + s5l_lcd_write_config( 557 + (mpuiface == LCD_MPUIFACE_SERIAL) ? LCD_MODE_S8 : LCD_MODE_P8); 558 + s5l_lcd_recv_cmd8(4, 4, lcd_id); 559 + } 560 + #endif 561 + 562 + /* LCD init */ 563 + void lcd_init_device(void) 564 + { 565 + mutex_init(&lcd_mutex); 566 + 567 + lcd_target_enable_clocks(true); 568 + #if defined(IPOD_6G) || defined(IPOD_NANO3G) 569 + LCD_PHTIME = 0x33; 570 + #elif defined(IPOD_NANO4G) 571 + cg16_config(&CG16_LCD, true, CG16_SEL_PLL0, 16, 1, 0x0); 572 + s5l_lcd_write_config(LCD_MODE_S9); 573 + cg16_config(&CG16_LCD, false, CG16_SEL_PLL0, 16, 1, 0x0); 574 + LCD_PHTIME = 0x11; 575 + #endif 576 + 577 + lcd_info = lcd_target_get_info(); 578 + lcd_type = lcd_info->lcd_type; 579 + 580 + /* select mode to send commands */ 581 + #ifdef S5L_LCD_WITH_CMDSET16 582 + if (lcd_info->cmdset == LCD_CMDSET_16BIT) 583 + { 584 + lcd_cmd_mode = LCD_MODE_P18; 585 + lcd_run_seq = s5l_lcd_run_seq16; 586 + } 587 + else /* LCD_CMDSET_8BIT */ 588 + #endif 589 + { 590 + if (lcd_info->mpuiface == LCD_MPUIFACE_SERIAL) 591 + lcd_cmd_mode = LCD_MODE_S8; 592 + else 593 + lcd_cmd_mode = LCD_MODE_P8; 594 + lcd_run_seq = s5l_lcd_run_seq8; 595 + } 596 + 597 + /* select mode to send RGB565 data */ 598 + if (lcd_info->mpuiface == LCD_MPUIFACE_PAR9) 599 + lcd_frame_mode = LCD_MODE_P9; 600 + else if (lcd_info->mpuiface == LCD_MPUIFACE_PAR18) 601 + lcd_frame_mode = LCD_MODE_P16; 602 + else /* LCD_MPUIFACE_SERIAL */ 603 + lcd_frame_mode = LCD_MODE_S9; 604 + 605 + s5l_lcd_set_command_mode(); 606 + 607 + /* Configure DMA channel */ // TODO: this right after mutex_init() 608 + dmac_ch_init(&lcd_dma_ch, &lcd_dma_ch_cfg); 609 + 610 + #ifdef BOOTLOADER 611 + lcd_run_seq(lcd_info->seq_init); 612 + #endif 613 + 614 + lcd_ispowered = true; 615 + }
+90
firmware/target/arm/s5l8702/lcd-s5l8702.h
··· 1 + /*************************************************************************** 2 + * __________ __ ___. 3 + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 + * \/ \/ \/ \/ \/ 8 + * $Id: 9 + * 10 + * Copyright © 2009 Michael Sparmann 11 + * 12 + * This program is free software; you can redistribute it and/or 13 + * modify it under the terms of the GNU General Public License 14 + * as published by the Free Software Foundation; either version 2 15 + * of the License, or (at your option) any later version. 16 + * 17 + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 18 + * KIND, either express or implied. 19 + * 20 + ****************************************************************************/ 21 + #ifndef __LCD_S5L8702_H__ 22 + #define __LCD_S5L8702_H__ 23 + 24 + #include <stdint.h> 25 + 26 + #include "config.h" 27 + #include "lcd-target.h" 28 + 29 + 30 + /* sequence actions */ 31 + enum { 32 + CMD = 0, /* send command with N data */ 33 + SLEEP, /* unit: RB tick */ // TODO: the unit in ms. but using HZ 34 + #ifdef S5L_LCD_WITH_CMDSET16 35 + MREG, /* write multiple registers */ 36 + DELAY, /* unit: 64 us. */ 37 + #endif 38 + END = 0xff 39 + }; 40 + 41 + #ifdef S5L_LCD_WITH_CMDSET16 42 + /* pack 16-bit sequence actions */ 43 + #define CMD16 (CMD) /* send command with no data */ // TODO: why not use MREG16(0) ??? 44 + #define MREG16(len) (MREG | ((len) << 8)) 45 + #define SLEEP16(t) (SLEEP | ((t) << 8)) 46 + #define DELAY16(t) (DELAY | ((t) << 8)) 47 + 48 + /* Supported command sets */ 49 + enum { 50 + LCD_CMDSET_8BIT = 0, /* 8-bit command set similar to TODO */ 51 + LCD_CMDSET_16BIT, /* 16-bit command set similar to TODO */ 52 + }; 53 + #endif 54 + 55 + /* Supported MPU interfaces */ 56 + enum { 57 + LCD_MPUIFACE_PAR9 = 0, /* 8080-series 9-bit parallel */ 58 + LCD_MPUIFACE_PAR18, /* 8080-series 18-bit parallel */ 59 + LCD_MPUIFACE_SERIAL, /* 3-pin SPI (TBC) */ 60 + }; 61 + 62 + 63 + // TODO: typedef struct {} lcd_info_t; 64 + struct lcd_info_rec { 65 + uint8_t lcd_type; 66 + uint8_t mpuiface; /* LCD_MPUIFACE_ */ 67 + #ifdef S5L_LCD_WITH_CMDSET16 68 + uint8_t cmdset; /* LCD_CMDSET_ */ 69 + #endif 70 + /* sequences */ 71 + #if defined(HAVE_LCD_SLEEP) || defined(HAVE_LCD_SHUTDOWN) 72 + void *seq_sleep; 73 + #endif 74 + #ifdef HAVE_LCD_SLEEP 75 + void *seq_awake; 76 + #endif 77 + #ifdef BOOTLOADER 78 + void *seq_init; 79 + #endif 80 + }; 81 + 82 + void lcd_awake(void); 83 + 84 + #ifdef S5L_LCD_WITH_READID 85 + void lcd_read_display_id(int mupiface, uint8_t *lcd_id); 86 + #endif 87 + 88 + extern struct lcd_info_rec* lcd_target_get_info(void); 89 + 90 + #endif /* __LCD_S5L8702_H__ */