summaryrefslogtreecommitdiff
path: root/firmware/target/arm/s5l8702/ipod6g
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/s5l8702/ipod6g')
-rw-r--r--firmware/target/arm/s5l8702/ipod6g/adc-ipod6g.c39
-rw-r--r--firmware/target/arm/s5l8702/ipod6g/adc-target.h33
-rw-r--r--firmware/target/arm/s5l8702/ipod6g/ata-ipod6g.c197
-rw-r--r--firmware/target/arm/s5l8702/ipod6g/ata-target.h47
-rw-r--r--firmware/target/arm/s5l8702/ipod6g/audio-ipod6g.c65
-rw-r--r--firmware/target/arm/s5l8702/ipod6g/backlight-ipod6g.c67
-rw-r--r--firmware/target/arm/s5l8702/ipod6g/backlight-target.h29
-rw-r--r--firmware/target/arm/s5l8702/ipod6g/button-target.h78
-rw-r--r--firmware/target/arm/s5l8702/ipod6g/cscodec-ipod6g.c64
-rw-r--r--firmware/target/arm/s5l8702/ipod6g/lcd-asm-ipod6g.S295
-rw-r--r--firmware/target/arm/s5l8702/ipod6g/lcd-ipod6g.c286
-rw-r--r--firmware/target/arm/s5l8702/ipod6g/pmu-ipod6g.c143
-rw-r--r--firmware/target/arm/s5l8702/ipod6g/pmu-target.h46
-rw-r--r--firmware/target/arm/s5l8702/ipod6g/power-ipod6g.c75
-rw-r--r--firmware/target/arm/s5l8702/ipod6g/powermgmt-ipod6g.c88
-rw-r--r--firmware/target/arm/s5l8702/ipod6g/rtc-ipod6g.c72
16 files changed, 1624 insertions, 0 deletions
diff --git a/firmware/target/arm/s5l8702/ipod6g/adc-ipod6g.c b/firmware/target/arm/s5l8702/ipod6g/adc-ipod6g.c
new file mode 100644
index 0000000000..201af5ee00
--- /dev/null
+++ b/firmware/target/arm/s5l8702/ipod6g/adc-ipod6g.c
@@ -0,0 +1,39 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: adc-s5l8700.c 21775 2009-07-11 14:12:02Z bertrik $
9 *
10 * Copyright (C) 2009 by Bertrik Sikken
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
22#include "config.h"
23
24#include "inttypes.h"
25#include "s5l8702.h"
26#include "adc.h"
27#include "adc-target.h"
28#include "pmu-target.h"
29#include "kernel.h"
30
31unsigned short adc_read(int channel)
32{
33 return pmu_read_adc(channel);
34}
35
36void adc_init(void)
37{
38}
39
diff --git a/firmware/target/arm/s5l8702/ipod6g/adc-target.h b/firmware/target/arm/s5l8702/ipod6g/adc-target.h
new file mode 100644
index 0000000000..d4dce3d31f
--- /dev/null
+++ b/firmware/target/arm/s5l8702/ipod6g/adc-target.h
@@ -0,0 +1,33 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: adc-target.h 21734 2009-07-09 20:17:47Z bertrik $
9 *
10 * Copyright (C) 2006 by Barry Wardell
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 _ADC_TARGET_H_
22#define _ADC_TARGET_H_
23
24#define NUM_ADC_CHANNELS 4
25
26#define ADC_UNKNOWN_0 0
27#define ADC_UNKNOWN_1 1
28#define ADC_BATTERY 2
29#define ADC_UNKNOWN_3 3
30
31#define ADC_UNREG_POWER ADC_BATTERY /* For compatibility */
32
33#endif
diff --git a/firmware/target/arm/s5l8702/ipod6g/ata-ipod6g.c b/firmware/target/arm/s5l8702/ipod6g/ata-ipod6g.c
new file mode 100644
index 0000000000..f1577ee857
--- /dev/null
+++ b/firmware/target/arm/s5l8702/ipod6g/ata-ipod6g.c
@@ -0,0 +1,197 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: ata-meg-fx.c 27935 2010-08-28 23:12:11Z funman $
9 *
10 * Copyright (C) 2011 by 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#include "config.h"
22#include "cpu.h"
23#include "kernel.h"
24#include "thread.h"
25#include "system.h"
26#include "power.h"
27#include "panic.h"
28#include "pmu-target.h"
29#include "ata.h"
30#include "ata-target.h"
31#include "s5l8702.h"
32
33
34static struct wakeup ata_wakeup;
35
36#ifdef HAVE_ATA_DMA
37static uint32_t ata_dma_flags;
38#endif
39
40
41void ata_reset(void)
42{
43 ATA_SWRST = 1;
44 sleep(HZ / 100);
45 ATA_SWRST = 0;
46 sleep(HZ / 10);
47}
48
49void ata_enable(bool on)
50{
51 if (on)
52 {
53 PWRCON(0) &= ~(1 << 5);
54 ATA_CFG = 0x41;
55 sleep(HZ / 100);
56 ATA_CFG = 0x40;
57 sleep(HZ / 20);
58 ata_reset();
59 ATA_CCONTROL = 1;
60 sleep(HZ / 5);
61 ATA_PIO_TIME = 0x191f7;
62 *ATA_HCYL = 0;
63 while (!(ATA_PIO_READY & 2)) yield();
64 }
65 else
66 {
67 ATA_CCONTROL = 0;
68 while (!(ATA_CCONTROL & 2)) yield();
69 PWRCON(1) |= 1 << 5;
70 }
71}
72
73bool ata_is_coldstart(void)
74{
75 return false;
76}
77
78void ata_device_init(void)
79{
80 VIC0INTENABLE = 1 << IRQ_ATA;
81}
82
83uint16_t ata_read_cbr(uint32_t volatile* reg)
84{
85 while (!(ATA_PIO_READY & 2));
86 volatile uint32_t __attribute__((unused)) dummy = *reg;
87 while (!(ATA_PIO_READY & 1));
88 return ATA_PIO_RDATA;
89}
90
91void ata_write_cbr(uint32_t volatile* reg, uint16_t data)
92{
93 while (!(ATA_PIO_READY & 2));
94 *reg = data;
95}
96
97void ata_set_pio_timings(int mode)
98{
99 if (mode >= 4) ATA_PIO_TIME = 0x7083;
100 if (mode >= 3) ATA_PIO_TIME = 0x2072;
101 else ATA_PIO_TIME = 0x11f3;
102}
103
104#ifdef HAVE_ATA_DMA
105static void ata_set_mdma_timings(unsigned int mode)
106{
107 if (mode >= 2) ATA_MDMA_TIME = 0x5072;
108 if (mode >= 1) ATA_MDMA_TIME = 0x7083;
109 else ATA_MDMA_TIME = 0x1c175;
110}
111
112static void ata_set_udma_timings(unsigned int mode)
113{
114 if (mode >= 4) ATA_UDMA_TIME = 0x2010a52;
115 if (mode >= 3) ATA_UDMA_TIME = 0x2020a52;
116 if (mode >= 2) ATA_UDMA_TIME = 0x3030a52;
117 if (mode >= 1) ATA_UDMA_TIME = 0x3050a52;
118 else ATA_UDMA_TIME = 0x5071152;
119}
120
121void ata_dma_set_mode(unsigned char mode)
122{
123 unsigned int modeidx = mode & 0x07;
124 unsigned int dmamode = mode & 0xf8;
125
126 if (dmamode == 0x40 && modeidx <= ATA_MAX_UDMA)
127 {
128 /* Using Ultra DMA */
129 ata_set_udma_timings(dmamode);
130 ata_dma_flags = 0x60c;
131 }
132 else if (dmamode == 0x20 && modeidx <= ATA_MAX_MWDMA)
133 {
134 /* Using Multiword DMA */
135 ata_set_mdma_timings(dmamode);
136 ata_dma_flags = 0x408;
137 }
138 else
139 {
140 /* Don't understand this - force PIO. */
141 ata_dma_flags = 0;
142 }
143}
144
145bool ata_dma_setup(void *addr, unsigned long bytes, bool write)
146{
147 if ((((int)addr) & 0xf) || (((int)bytes) & 0xf) || !ata_dma_flags)
148 return false;
149
150 if (write) clean_dcache();
151 else invalidate_dcache();
152 ATA_CCOMMAND = 2;
153
154 if (write)
155 {
156 ATA_SBUF_START = addr;
157 ATA_SBUF_SIZE = bytes;
158 ATA_CFG |= 0x10;
159 }
160 else
161 {
162 ATA_TBUF_START = addr;
163 ATA_TBUF_SIZE = bytes;
164 ATA_CFG &= ~0x10;
165 }
166 ATA_XFR_NUM = bytes - 1;
167
168 return true;
169}
170
171bool ata_dma_finish(void)
172{
173 ATA_CFG |= ata_dma_flags;
174 ATA_CFG &= ~0x180;
175 wakeup_wait(&ata_wakeup, TIMEOUT_NOBLOCK);
176 ATA_IRQ = 0x1f;
177 ATA_IRQ_MASK = 1;
178 ATA_CCOMMAND = 1;
179 if (wakeup_wait(&ata_wakeup, HZ / 2) != OBJ_WAIT_SUCCEEDED)
180 {
181 ATA_CCOMMAND = 2;
182 ATA_CFG &= ~0x100c;
183 return false;
184 }
185 ATA_CCOMMAND = 2;
186 ATA_CFG &= ~0x100c;
187 return true;
188}
189#endif /* HAVE_ATA_DMA */
190
191void INT_ATA(void)
192{
193 uint32_t ata_irq = ATA_IRQ;
194 ATA_IRQ = ata_irq;
195 if (ata_irq & ATA_IRQ_MASK) wakeup_signal(&ata_wakeup);
196 ATA_IRQ_MASK = 0;
197}
diff --git a/firmware/target/arm/s5l8702/ipod6g/ata-target.h b/firmware/target/arm/s5l8702/ipod6g/ata-target.h
new file mode 100644
index 0000000000..e2e7bd298c
--- /dev/null
+++ b/firmware/target/arm/s5l8702/ipod6g/ata-target.h
@@ -0,0 +1,47 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: ata-target.h 25525 2010-04-07 20:01:21Z torne $
9 *
10 * Copyright (C) 2011 by 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 ATA_TARGET_H
22#define ATA_TARGET_H
23
24#include "inttypes.h"
25#include "s5l8702.h"
26
27#ifdef BOOTLOADER
28#define ATA_DRIVER_CLOSE
29#endif
30
31#define ATA_SWAP_IDENTIFY(word) (swap16(word))
32
33void ata_reset(void);
34void ata_device_init(void);
35bool ata_is_coldstart(void);
36uint16_t ata_read_cbr(uint32_t volatile* reg);
37void ata_write_cbr(uint32_t volatile* reg, uint16_t data);
38
39#define ATA_OUT8(reg, data) ata_write_cbr(reg, data)
40#define ATA_OUT16(reg, data) ata_write_cbr(reg, data)
41#define ATA_IN8(reg) ata_read_cbr(reg)
42#define ATA_IN16(reg) ata_read_cbr(reg)
43
44#define ATA_SET_DEVICE_FEATURES
45void ata_set_pio_timings(int mode);
46
47#endif
diff --git a/firmware/target/arm/s5l8702/ipod6g/audio-ipod6g.c b/firmware/target/arm/s5l8702/ipod6g/audio-ipod6g.c
new file mode 100644
index 0000000000..6ede3d0c30
--- /dev/null
+++ b/firmware/target/arm/s5l8702/ipod6g/audio-ipod6g.c
@@ -0,0 +1,65 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: audio-nano2g.c 23095 2009-10-11 09:17:12Z dave $
9 *
10 * Copyright (C) 2006 by Michael Sevakis
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 "system.h"
22#include "cpu.h"
23#include "audio.h"
24#include "sound.h"
25
26#if INPUT_SRC_CAPS != 0
27void audio_set_output_source(int source)
28{
29 if ((unsigned)source >= AUDIO_NUM_SOURCES)
30 source = AUDIO_SRC_PLAYBACK;
31} /* audio_set_output_source */
32
33void audio_input_mux(int source, unsigned flags)
34{
35 (void)flags;
36 /* Prevent pops from unneeded switching */
37 static int last_source = AUDIO_SRC_PLAYBACK;
38
39 switch (source)
40 {
41 default: /* playback - no recording */
42 source = AUDIO_SRC_PLAYBACK;
43 case AUDIO_SRC_PLAYBACK:
44#ifdef HAVE_RECORDING
45 if (source != last_source)
46 {
47 audiohw_set_monitor(false);
48 audiohw_disable_recording();
49 }
50#endif
51 break;
52#ifdef HAVE_LINE_REC
53 case AUDIO_SRC_LINEIN: /* recording only */
54 if (source != last_source)
55 {
56 audiohw_set_monitor(false);
57 audiohw_enable_recording(false); /* source line */
58 }
59 break;
60#endif
61 } /* end switch */
62
63 last_source = source;
64} /* audio_input_mux */
65#endif /* INPUT_SRC_CAPS != 0 */
diff --git a/firmware/target/arm/s5l8702/ipod6g/backlight-ipod6g.c b/firmware/target/arm/s5l8702/ipod6g/backlight-ipod6g.c
new file mode 100644
index 0000000000..dc21d161de
--- /dev/null
+++ b/firmware/target/arm/s5l8702/ipod6g/backlight-ipod6g.c
@@ -0,0 +1,67 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: backlight-nano2g.c 28601 2010-11-14 20:39:18Z theseven $
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 <stdbool.h>
22
23#include "config.h"
24#include "kernel.h"
25#include "backlight.h"
26#include "backlight-target.h"
27#include "pmu-target.h"
28
29#ifdef HAVE_LCD_SLEEP
30bool lcd_active(void);
31void lcd_awake(void);
32void lcd_update(void);
33#endif
34
35void _backlight_set_brightness(int brightness)
36{
37 pmu_write(0x28, brightness);
38}
39
40void _backlight_on(void)
41{
42#ifdef HAVE_LCD_SLEEP
43 if (!lcd_active())
44 {
45 lcd_awake();
46 lcd_update();
47 sleep(HZ/8);
48 }
49#endif
50 pmu_write(0x29, 1);
51}
52
53void _backlight_off(void)
54{
55 pmu_write(0x29, 0);
56}
57
58bool _backlight_init(void)
59{
60 pmu_write(0x2a, 6);
61 pmu_write(0x28, 0x20);
62 pmu_write(0x2b, 20);
63
64 _backlight_on();
65
66 return true;
67}
diff --git a/firmware/target/arm/s5l8702/ipod6g/backlight-target.h b/firmware/target/arm/s5l8702/ipod6g/backlight-target.h
new file mode 100644
index 0000000000..05a8addfea
--- /dev/null
+++ b/firmware/target/arm/s5l8702/ipod6g/backlight-target.h
@@ -0,0 +1,29 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: backlight-target.h 21478 2009-06-23 18:11:03Z bertrik $
9 *
10 * Copyright (C) 2008 by Marcoen Hirschberg
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 BACKLIGHT_TARGET_H
22#define BACKLIGHT_TARGET_H
23
24bool _backlight_init(void);
25void _backlight_on(void);
26void _backlight_off(void);
27void _backlight_set_brightness(int brightness);
28
29#endif
diff --git a/firmware/target/arm/s5l8702/ipod6g/button-target.h b/firmware/target/arm/s5l8702/ipod6g/button-target.h
new file mode 100644
index 0000000000..0bd89d1d2a
--- /dev/null
+++ b/firmware/target/arm/s5l8702/ipod6g/button-target.h
@@ -0,0 +1,78 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: button-target.h 21828 2009-07-12 22:16:51Z dave $
9 *
10 * Copyright (C) 2006 by Barry Wardell
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 _BUTTON_TARGET_H_
22#define _BUTTON_TARGET_H_
23
24#include <stdbool.h>
25#include "config.h"
26
27#define HAS_BUTTON_HOLD
28
29bool button_hold(void);
30void button_init_device(void);
31int button_read_device(void);
32
33void ipod_mini_button_int(void);
34void ipod_3g_button_int(void);
35void ipod_4g_button_int(void);
36
37/* iPod specific button codes */
38
39#define BUTTON_SELECT 0x00000001
40#define BUTTON_MENU 0x00000002
41
42#define BUTTON_LEFT 0x00000004
43#define BUTTON_RIGHT 0x00000008
44#define BUTTON_SCROLL_FWD 0x00000010
45#define BUTTON_SCROLL_BACK 0x00000020
46
47#define BUTTON_PLAY 0x00000040
48
49#define BUTTON_MAIN (BUTTON_SELECT|BUTTON_MENU\
50 |BUTTON_LEFT|BUTTON_RIGHT|BUTTON_SCROLL_FWD\
51 |BUTTON_SCROLL_BACK|BUTTON_PLAY)
52
53 /* Remote control's buttons */
54#ifdef IPOD_ACCESSORY_PROTOCOL
55#define BUTTON_RC_PLAY 0x00100000
56#define BUTTON_RC_STOP 0x00080000
57
58#define BUTTON_RC_LEFT 0x00040000
59#define BUTTON_RC_RIGHT 0x00020000
60#define BUTTON_RC_VOL_UP 0x00010000
61#define BUTTON_RC_VOL_DOWN 0x00008000
62
63#define BUTTON_REMOTE (BUTTON_RC_PLAY|BUTTON_RC_STOP\
64 |BUTTON_RC_LEFT|BUTTON_RC_RIGHT\
65 |BUTTON_RC_VOL_UP|BUTTON_RC_VOL_DOWN)
66#else
67#define BUTTON_REMOTE 0
68#endif
69
70/* This is for later
71#define BUTTON_SCROLL_TOUCH 0x00000200
72*/
73
74
75#define POWEROFF_BUTTON BUTTON_PLAY
76#define POWEROFF_COUNT 40
77
78#endif /* _BUTTON_TARGET_H_ */
diff --git a/firmware/target/arm/s5l8702/ipod6g/cscodec-ipod6g.c b/firmware/target/arm/s5l8702/ipod6g/cscodec-ipod6g.c
new file mode 100644
index 0000000000..460b254730
--- /dev/null
+++ b/firmware/target/arm/s5l8702/ipod6g/cscodec-ipod6g.c
@@ -0,0 +1,64 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: wmcodec-s5l8700.c 22025 2009-07-25 00:49:13Z dave $
9 *
10 * S5L8702-specific code for Cirrus codecs
11 *
12 * Copyright (c) 2010 Michael Sparmann
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
18 *
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
21 *
22 ****************************************************************************/
23
24#include "system.h"
25#include "audiohw.h"
26#include "i2c-s5l8702.h"
27#include "s5l8702.h"
28#include "cscodec.h"
29
30void audiohw_init(void)
31{
32#ifdef HAVE_CS42L55
33 audiohw_preinit();
34#endif
35}
36
37unsigned char cscodec_read(int reg)
38{
39 unsigned char data;
40 i2c_read(0, 0x94, reg, 1, &data);
41 return data;
42}
43
44void cscodec_write(int reg, unsigned char data)
45{
46 i2c_write(0, 0x94, reg, 1, &data);
47}
48
49void cscodec_power(bool state)
50{
51 (void)state; //TODO: Figure out which LDO this is
52}
53
54void cscodec_reset(bool state)
55{
56 if (state) PDAT(3) &= ~8;
57 else PDAT(3) |= 8;
58}
59
60void cscodec_clock(bool state)
61{
62 if (state) CLKCON0C &= ~0xffff;
63 else CLKCON0C |= 0x8000;
64}
diff --git a/firmware/target/arm/s5l8702/ipod6g/lcd-asm-ipod6g.S b/firmware/target/arm/s5l8702/ipod6g/lcd-asm-ipod6g.S
new file mode 100644
index 0000000000..2b170f329b
--- /dev/null
+++ b/firmware/target/arm/s5l8702/ipod6g/lcd-asm-ipod6g.S
@@ -0,0 +1,295 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: lcd-as-video.S 26756 2010-06-11 04:41:36Z funman $
9 *
10 * Copyright (C) 2010 by Andree Buschmann
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
22/****************************************************************************
23 * #define FORCE_FIFO_WAIT
24 *
25 * This is not needed in YUV blitting when the LCD IF is fast enough. In this
26 * case YUV-to-RGB conversion per pixel needs longer than the transfer of a
27 * pixel via the LCD IF. For iPod nano 2G this is true if the LCD IF is
28 * configured to use LCD_PHTIME = 0x00 (see lcd-nano2g.c).
29 ****************************************************************************/
30
31#include "config.h"
32
33 .section .icode, "ax", %progbits
34
35/****************************************************************************
36 * void lcd_write_line(const fb_data *addr,
37 * int pixelcount,
38 * const unsigned int lcd_base_addr);
39 *
40 * Writes pixelcount pixels from src-pointer (lcd_framebuffer) to LCD dataport.
41 */
42 .align 2
43 .global lcd_write_line
44 .type lcd_write_line, %function
45 /* r0 = addr, must be aligned */
46 /* r1 = pixel count, must be even */
47lcd_write_line: /* r2 = LCD_BASE */
48 stmfd sp!, {r4-r6, lr} /* save non-scratch registers */
49 add r12, r2, #0x40 /* LCD_WDATA = LCD data port */
50
51.loop:
52 ldmia r0!, {r3, r5} /* read 2 pixel (=8 byte) */
53
54 /* wait for FIFO half full */
55.fifo_wait:
56 ldr lr, [r2, #0x1C] /* while (LCD_STATUS & 0x08); */
57 tst lr, #0x8
58 bgt .fifo_wait
59
60 mov r4, r3, asr #16 /* r3 = 1st pixel, r4 = 2nd pixel */
61 mov r6, r5, asr #16 /* r5 = 3rd pixel, r6 = 4th pixel */
62 stmia r12, {r3-r6} /* write pixels (lowest 16 bit used) */
63
64 subs r1, r1, #4
65 bgt .loop
66
67 ldmpc regs=r4-r6
68
69/****************************************************************************
70 * extern void lcd_write_yuv420_lines(unsigned char const * const src[3],
71 * const unsigned LCD_BASE,
72 * int width,
73 * int stride);
74 *
75 * Conversion from Motion JPEG and MPEG Y'PbPr to RGB is:
76 * |R| |1.164 0.000 1.596| |Y' - 16|
77 * |G| = |1.164 -0.391 -0.813| |Pb - 128|
78 * |B| |1.164 2.018 0.000| |Pr - 128|
79 *
80 * Scaled, normalized, rounded and tweaked to yield RGB 565:
81 * |R| |74 0 101| |Y' - 16| >> 9
82 * |G| = |74 -24 -51| |Cb - 128| >> 8
83 * |B| |74 128 0| |Cr - 128| >> 9
84 *
85 * Converts two lines from YUV to RGB565 and writes to LCD at once. First loop
86 * loads Cb/Cr, calculates the chroma offset and saves them to buffer. Within
87 * the second loop these chroma offset are reloaded from buffer. Within each
88 * loop two pixels are calculated and written to LCD.
89 */
90 .align 2
91 .global lcd_write_yuv420_lines
92 .type lcd_write_yuv420_lines, %function
93lcd_write_yuv420_lines:
94 /* r0 = src = yuv_src */
95 /* r1 = dst = LCD_BASE */
96 /* r2 = width */
97 /* r3 = stride */
98 stmfd sp!, { r4-r10, lr } /* save non-scratch */
99 ldmia r0, { r9, r10, r12 } /* r9 = yuv_src[0] = Y'_p */
100 /* r10 = yuv_src[1] = Cb_p */
101 /* r12 = yuv_src[2] = Cr_p */
102 add r3, r9, r3 /* r3 = &ysrc[stride] */
103 add r4, r2, r2, asr #1 /* chroma buffer lenght = width/2 *3 */
104 mov r4, r4, asl #2 /* use words for str/ldm possibility */
105 add r4, r4, #19 /* plus room for 4 additional words, */
106 bic r4, r4, #3 /* rounded up to multiples of 4 byte */
107 sub sp, sp, r4 /* and allocate on stack */
108 stmia sp, {r1-r4} /* LCD_BASE, width, &ysrc[stride], stack_alloc */
109
110 mov r7, r2 /* r7 = loop count */
111 add r8, sp, #16 /* chroma buffer */
112 add lr, r1, #0x40 /* LCD data port = LCD_BASE + 0x40 */
113
114 /* 1st loop start */
11510: /* loop start */
116
117 ldrb r0, [r10], #1 /* r0 = *usrc++ = *Cb_p++ */
118 ldrb r1, [r12], #1 /* r1 = *vsrc++ = *Cr_p++ */
119
120 sub r0, r0, #128 /* r0 = Cb-128 */
121 sub r1, r1, #128 /* r1 = Cr-128 */
122
123 add r2, r1, r1, asl #1 /* r2 = Cr*51 + Cb*24 */
124 add r2, r2, r2, asl #4
125 add r2, r2, r0, asl #3
126 add r2, r2, r0, asl #4
127
128 add r4, r1, r1, asl #2 /* r1 = Cr*101 */
129 add r4, r4, r1, asl #5
130 add r1, r4, r1, asl #6
131
132 add r1, r1, #256 /* r1 = rv = (r1 + 256) >> 9 */
133 mov r1, r1, asr #9
134 rsb r2, r2, #128 /* r2 = guv = (-r2 + 128) >> 8 */
135 mov r2, r2, asr #8
136 add r0, r0, #2 /* r0 = bu = (Cb*128 + 256) >> 9 */
137 mov r0, r0, asr #2
138 stmia r8!, {r0-r2} /* store r0, r1 and r2 to chroma buffer */
139
140 /* 1st loop, first pixel */
141 ldrb r5, [r9], #1 /* r5 = *ysrc++ = *Y'_p++ */
142 sub r5, r5, #16 /* r5 = (Y'-16) * 74 */
143 add r3, r5, r5, asl #2
144 add r5, r3, r5, asl #5
145
146 add r6, r1, r5, asr #8 /* r6 = r = (Y >> 9) + rv */
147 add r3, r2, r5, asr #7 /* r3 = g = (Y >> 8) + guv */
148 add r4, r0, r5, asr #8 /* r4 = b = (Y >> 9) + bu */
149
150 orr r5, r6, r4 /* check if clamping is needed... */
151 orr r5, r5, r3, asr #1 /* ...at all */
152 cmp r5, #31
153 bls 15f /* -> no clamp */
154 cmp r6, #31 /* clamp r */
155 mvnhi r6, r6, asr #31
156 andhi r6, r6, #31
157 cmp r3, #63 /* clamp g */
158 mvnhi r3, r3, asr #31
159 andhi r3, r3, #63
160 cmp r4, #31 /* clamp b */
161 mvnhi r4, r4, asr #31
162 andhi r4, r4, #31
16315: /* no clamp */
164
165 /* calculate pixel_1 and save to r4 for later pixel packing */
166 orr r4, r4, r3, lsl #5 /* pixel_1 = r<<11 | g<<5 | b */
167 orr r4, r4, r6, lsl #11 /* r4 = pixel_1 */
168
169 /* 1st loop, second pixel */
170 ldrb r5, [r9], #1 /* r5 = *ysrc++ = *Y'_p++ */
171 sub r5, r5, #16 /* r5 = (Y'-16) * 74 */
172 add r3, r5, r5, asl #2
173 add r5, r3, r5, asl #5
174
175 add r6, r1, r5, asr #8 /* r6 = r = (Y >> 9) + rv */
176 add r3, r2, r5, asr #7 /* r3 = g = (Y >> 8) + guv */
177 add r5, r0, r5, asr #8 /* r5 = b = (Y >> 9) + bu */
178
179 orr r0, r6, r5 /* check if clamping is needed... */
180 orr r0, r0, r3, asr #1 /* ...at all */
181 cmp r0, #31
182 bls 15f /* -> no clamp */
183 cmp r6, #31 /* clamp r */
184 mvnhi r6, r6, asr #31
185 andhi r6, r6, #31
186 cmp r3, #63 /* clamp g */
187 mvnhi r3, r3, asr #31
188 andhi r3, r3, #63
189 cmp r5, #31 /* clamp b */
190 mvnhi r5, r5, asr #31
191 andhi r5, r5, #31
19215: /* no clamp */
193
194 /* calculate pixel_2 and pack with pixel_1 before writing */
195 orr r5, r5, r3, lsl #5 /* pixel_2 = r<<11 | g<<5 | b */
196 orr r5, r5, r6, lsl #11 /* r5 = pixel_2 */
197#ifdef FORCE_FIFO_WAIT
198 /* wait for FIFO half full */
199.fifo_wait1:
200 ldr r3, [lr, #-0x24] /* while (LCD_STATUS & 0x08); */
201 tst r3, #0x8
202 bgt .fifo_wait1
203#endif
204 stmia lr, {r4,r5} /* write pixel_1 and pixel_2 */
205
206 subs r7, r7, #2 /* check for loop end */
207 bgt 10b /* back to beginning */
208 /* 1st loop end */
209
210 /* Reload several registers for pointer rewinding for next loop */
211 add r8, sp, #16 /* chroma buffer */
212 ldmia sp, { r1, r7, r9} /* r1 = LCD_BASE */
213 /* r7 = loop count */
214 /* r9 = &ysrc[stride] */
215
216 /* 2nd loop start */
21720: /* loop start */
218 /* restore r0 (bu), r1 (rv) and r2 (guv) from chroma buffer */
219 ldmia r8!, {r0-r2}
220
221 /* 2nd loop, first pixel */
222 ldrb r5, [r9], #1 /* r5 = *ysrc++ = *Y'_p++ */
223 sub r5, r5, #16 /* r5 = (Y'-16) * 74 */
224 add r3, r5, r5, asl #2
225 add r5, r3, r5, asl #5
226
227 add r6, r1, r5, asr #8 /* r6 = r = (Y >> 9) + rv */
228 add r3, r2, r5, asr #7 /* r3 = g = (Y >> 8) + guv */
229 add r4, r0, r5, asr #8 /* r4 = b = (Y >> 9) + bu */
230
231 orr r5, r6, r4 /* check if clamping is needed... */
232 orr r5, r5, r3, asr #1 /* ...at all */
233 cmp r5, #31
234 bls 15f /* -> no clamp */
235 cmp r6, #31 /* clamp r */
236 mvnhi r6, r6, asr #31
237 andhi r6, r6, #31
238 cmp r3, #63 /* clamp g */
239 mvnhi r3, r3, asr #31
240 andhi r3, r3, #63
241 cmp r4, #31 /* clamp b */
242 mvnhi r4, r4, asr #31
243 andhi r4, r4, #31
24415: /* no clamp */
245 /* calculate pixel_1 and save to r4 for later pixel packing */
246 orr r4, r4, r3, lsl #5 /* pixel_1 = r<<11 | g<<5 | b */
247 orr r4, r4, r6, lsl #11 /* r4 = pixel_1 */
248
249 /* 2nd loop, second pixel */
250 ldrb r5, [r9], #1 /* r5 = *ysrc++ = *Y'_p++ */
251 sub r5, r5, #16 /* r5 = (Y'-16) * 74 */
252 add r3, r5, r5, asl #2
253 add r5, r3, r5, asl #5
254
255 add r6, r1, r5, asr #8 /* r6 = r = (Y >> 9) + rv */
256 add r3, r2, r5, asr #7 /* r3 = g = (Y >> 8) + guv */
257 add r5, r0, r5, asr #8 /* r5 = b = (Y >> 9) + bu */
258
259 orr r0, r6, r5 /* check if clamping is needed... */
260 orr r0, r0, r3, asr #1 /* ...at all */
261 cmp r0, #31
262 bls 15f /* -> no clamp */
263 cmp r6, #31 /* clamp r */
264 mvnhi r6, r6, asr #31
265 andhi r6, r6, #31
266 cmp r3, #63 /* clamp g */
267 mvnhi r3, r3, asr #31
268 andhi r3, r3, #63
269 cmp r5, #31 /* clamp b */
270 mvnhi r5, r5, asr #31
271 andhi r5, r5, #31
27215: /* no clamp */
273
274 /* calculate pixel_2 and pack with pixel_1 before writing */
275 orr r5, r5, r3, lsl #5 /* pixel_2 = r<<11 | g<<5 | b */
276 orr r5, r5, r6, lsl #11 /* r5 = pixel_2 */
277#ifdef FORCE_FIFO_WAIT
278 /* wait for FIFO half full */
279.fifo_wait2:
280 ldr r3, [lr, #-0x24] /* while (LCD_STATUS & 0x08); */
281 tst r3, #0x8
282 bgt .fifo_wait2
283#endif
284 stmia lr, {r4,r5} /* write pixel_1 and pixel_2 */
285
286 subs r7, r7, #2 /* check for loop end */
287 bgt 20b /* back to beginning */
288 /* 2nd loop end */
289
290 ldr r3, [sp, #12]
291 add sp, sp, r3 /* deallocate buffer */
292 ldmpc regs=r4-r10 /* restore registers */
293
294 .ltorg
295 .size lcd_write_yuv420_lines, .-lcd_write_yuv420_lines
diff --git a/firmware/target/arm/s5l8702/ipod6g/lcd-ipod6g.c b/firmware/target/arm/s5l8702/ipod6g/lcd-ipod6g.c
new file mode 100644
index 0000000000..1de6a8e62f
--- /dev/null
+++ b/firmware/target/arm/s5l8702/ipod6g/lcd-ipod6g.c
@@ -0,0 +1,286 @@
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 "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
31
32#define R_HORIZ_GRAM_ADDR_SET 0x200
33#define R_VERT_GRAM_ADDR_SET 0x201
34#define R_WRITE_DATA_TO_GRAM 0x202
35#define R_HORIZ_ADDR_START_POS 0x210
36#define R_HORIZ_ADDR_END_POS 0x211
37#define R_VERT_ADDR_START_POS 0x212
38#define R_VERT_ADDR_END_POS 0x213
39
40
41/* LCD type 1 register defines */
42
43#define R_COLUMN_ADDR_SET 0x2a
44#define R_ROW_ADDR_SET 0x2b
45#define R_MEMORY_WRITE 0x2c
46
47
48/** globals **/
49
50int lcd_type; /* also needed in debug-s5l8702.c */
51
52
53static inline void s5l_lcd_write_cmd_data(int cmd, int data)
54{
55 while (LCD_STATUS & 0x10);
56 LCD_WCMD = cmd;
57
58 while (LCD_STATUS & 0x10);
59 LCD_WDATA = data;
60}
61
62static inline void s5l_lcd_write_cmd(unsigned short cmd)
63{
64 while (LCD_STATUS & 0x10);
65 LCD_WCMD = cmd;
66}
67
68static inline void s5l_lcd_write_data(unsigned short data)
69{
70 while (LCD_STATUS & 0x10);
71 LCD_WDATA = data;
72}
73
74/*** hardware configuration ***/
75
76int lcd_default_contrast(void)
77{
78 return 0x1f;
79}
80
81void lcd_set_contrast(int val)
82{
83 (void)val;
84}
85
86void lcd_set_invert_display(bool yesno)
87{
88 (void)yesno;
89}
90
91void lcd_set_flip(bool yesno)
92{
93 (void)yesno;
94}
95
96bool lcd_active(void)
97{
98 return true;
99}
100
101void lcd_shutdown(void)
102{
103 pmu_write(0x2b, 0); /* Kill the backlight, instantly. */
104 pmu_write(0x29, 0);
105
106 if (lcd_type == 3)
107 {
108 s5l_lcd_write_cmd_data(0x7, 0x172);
109 s5l_lcd_write_cmd_data(0x30, 0x3ff);
110 sleep(HZ / 10);
111 s5l_lcd_write_cmd_data(0x7, 0x120);
112 s5l_lcd_write_cmd_data(0x30, 0x0);
113 s5l_lcd_write_cmd_data(0x100, 0x780);
114 s5l_lcd_write_cmd_data(0x7, 0x0);
115 s5l_lcd_write_cmd_data(0x101, 0x260);
116 s5l_lcd_write_cmd_data(0x102, 0xa9);
117 sleep(HZ / 30);
118 s5l_lcd_write_cmd_data(0x100, 0x700);
119 s5l_lcd_write_cmd_data(0x100, 0x704);
120 }
121 else if (lcd_type == 1)
122 {
123 s5l_lcd_write_cmd(0x28);
124 s5l_lcd_write_cmd(0x10);
125 sleep(HZ / 10);
126 }
127 else
128 {
129 s5l_lcd_write_cmd(0x28);
130 sleep(HZ / 20);
131 s5l_lcd_write_cmd(0x10);
132 sleep(HZ / 20);
133 }
134}
135
136void lcd_sleep(void)
137{
138 lcd_shutdown();
139}
140
141/* LCD init */
142void lcd_init_device(void)
143{
144 /* Detect lcd type */
145 lcd_type = (PDAT6 & 0x30) >> 4;
146}
147
148/*** Update functions ***/
149
150static inline void lcd_write_pixel(fb_data pixel)
151{
152 LCD_WDATA = pixel;
153}
154
155/* Update the display.
156 This must be called after all other LCD functions that change the display. */
157void lcd_update(void) ICODE_ATTR;
158void lcd_update(void)
159{
160 lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT);
161}
162
163/* Line write helper function. */
164extern void lcd_write_line(const fb_data *addr,
165 int pixelcount,
166 const unsigned int lcd_base_addr);
167
168/* Update a fraction of the display. */
169void lcd_update_rect(int, int, int, int) ICODE_ATTR;
170void lcd_update_rect(int x, int y, int width, int height)
171{
172 int y0, x0, y1, x1;
173 fb_data* p;
174
175 /* Both x and width need to be preprocessed due to asm optimizations */
176 x = x & ~1; /* ensure x is even */
177 width = (width + 3) & ~3; /* ensure width is a multiple of 4 */
178
179 x0 = x; /* start horiz */
180 y0 = y; /* start vert */
181 x1 = (x + width) - 1; /* max horiz */
182 y1 = (y + height) - 1; /* max vert */
183
184 if (lcd_type & 2) {
185 s5l_lcd_write_cmd_data(R_HORIZ_ADDR_START_POS, x0);
186 s5l_lcd_write_cmd_data(R_HORIZ_ADDR_END_POS, x1);
187 s5l_lcd_write_cmd_data(R_VERT_ADDR_START_POS, y0);
188 s5l_lcd_write_cmd_data(R_VERT_ADDR_END_POS, y1);
189
190 s5l_lcd_write_cmd_data(R_HORIZ_GRAM_ADDR_SET, (x1 << 8) | x0);
191 s5l_lcd_write_cmd_data(R_VERT_GRAM_ADDR_SET, (y1 << 8) | y0);
192
193 s5l_lcd_write_cmd(R_WRITE_DATA_TO_GRAM);
194 } else {
195 s5l_lcd_write_cmd(R_COLUMN_ADDR_SET);
196 s5l_lcd_write_data(x0 >> 8);
197 s5l_lcd_write_data(x0 & 0xff);
198 s5l_lcd_write_data(x1 >> 8);
199 s5l_lcd_write_data(x1 & 0xff);
200
201 s5l_lcd_write_cmd(R_ROW_ADDR_SET);
202 s5l_lcd_write_data(y0 >> 8);
203 s5l_lcd_write_data(y0 & 0xff);
204 s5l_lcd_write_data(y1 >> 8);
205 s5l_lcd_write_data(y1 & 0xff);
206
207 s5l_lcd_write_cmd(R_MEMORY_WRITE);
208 }
209 for (y = y0; y <= y1; y++)
210 for (x = x0; x <= x1; x++)
211 s5l_lcd_write_data(lcd_framebuffer[y][x]);
212 return;
213
214 /* Copy display bitmap to hardware */
215 p = &lcd_framebuffer[y0][x0];
216 if (LCD_WIDTH == width) {
217 /* Write all lines at once */
218 lcd_write_line(p, height*LCD_WIDTH, LCD_BASE);
219 } else {
220 y1 = height;
221 do {
222 /* Write a single line */
223 lcd_write_line(p, width, LCD_BASE);
224 p += LCD_WIDTH;
225 } while (--y1 > 0 );
226 }
227}
228
229/* Line write helper function for lcd_yuv_blit. Writes two lines of yuv420. */
230extern void lcd_write_yuv420_lines(unsigned char const * const src[3],
231 const unsigned int lcd_baseadress,
232 int width,
233 int stride);
234
235/* Blit a YUV bitmap directly to the LCD */
236void lcd_blit_yuv(unsigned char * const src[3],
237 int src_x, int src_y, int stride,
238 int x, int y, int width, int height)
239{
240 unsigned int z, y0, x0, y1, x1;;
241 unsigned char const * yuv_src[3];
242
243 width = (width + 1) & ~1; /* ensure width is even */
244
245 x0 = x; /* start horiz */
246 y0 = y; /* start vert */
247 x1 = (x + width) - 1; /* max horiz */
248 y1 = (y + height) - 1; /* max vert */
249
250 if (lcd_type & 2) {
251 s5l_lcd_write_cmd_data(R_HORIZ_ADDR_START_POS, x0);
252 s5l_lcd_write_cmd_data(R_HORIZ_ADDR_END_POS, x1);
253 s5l_lcd_write_cmd_data(R_VERT_ADDR_START_POS, y0);
254 s5l_lcd_write_cmd_data(R_VERT_ADDR_END_POS, y1);
255
256 s5l_lcd_write_cmd_data(R_HORIZ_GRAM_ADDR_SET, (x1 << 8) | x0);
257 s5l_lcd_write_cmd_data(R_VERT_GRAM_ADDR_SET, (y1 << 8) | y0);
258
259 s5l_lcd_write_cmd(0);
260 s5l_lcd_write_cmd(R_WRITE_DATA_TO_GRAM);
261 } else {
262 s5l_lcd_write_cmd(R_COLUMN_ADDR_SET);
263 s5l_lcd_write_data(x0); /* Start column */
264 s5l_lcd_write_data(x1); /* End column */
265
266 s5l_lcd_write_cmd(R_ROW_ADDR_SET);
267 s5l_lcd_write_data(y0); /* Start row */
268 s5l_lcd_write_data(y1); /* End row */
269
270 s5l_lcd_write_cmd(R_MEMORY_WRITE);
271 }
272
273 z = stride * src_y;
274 yuv_src[0] = src[0] + z + src_x;
275 yuv_src[1] = src[1] + (z >> 2) + (src_x >> 1);
276 yuv_src[2] = src[2] + (yuv_src[1] - src[1]);
277
278 height >>= 1;
279
280 do {
281 lcd_write_yuv420_lines(yuv_src, LCD_BASE, width, stride);
282 yuv_src[0] += stride << 1;
283 yuv_src[1] += stride >> 1; /* Skip down one chroma line */
284 yuv_src[2] += stride >> 1;
285 } while (--height > 0);
286}
diff --git a/firmware/target/arm/s5l8702/ipod6g/pmu-ipod6g.c b/firmware/target/arm/s5l8702/ipod6g/pmu-ipod6g.c
new file mode 100644
index 0000000000..73d8f98083
--- /dev/null
+++ b/firmware/target/arm/s5l8702/ipod6g/pmu-ipod6g.c
@@ -0,0 +1,143 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: pmu-nano2g.c 27752 2010-08-08 10:49:32Z bertrik $
9 *
10 * Copyright © 2008 Rafaël Carré
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
22#include "config.h"
23#include "kernel.h"
24#include "i2c-s5l8702.h"
25#include "pmu-target.h"
26
27static struct mutex pmu_adc_mutex;
28
29int pmu_read_multiple(int address, int count, unsigned char* buffer)
30{
31 return i2c_read(0, 0xe6, address, count, buffer);
32}
33
34int pmu_write_multiple(int address, int count, unsigned char* buffer)
35{
36 return i2c_write(0, 0xe6, address, count, buffer);
37}
38
39unsigned char pmu_read(int address)
40{
41 unsigned char tmp;
42
43 pmu_read_multiple(address, 1, &tmp);
44
45 return tmp;
46}
47
48int pmu_write(int address, unsigned char val)
49{
50 return pmu_write_multiple(address, 1, &val);
51}
52
53void pmu_init(void)
54{
55 mutex_init(&pmu_adc_mutex);
56}
57
58int pmu_read_adc(unsigned int adc)
59{
60 int data = 0;
61 mutex_lock(&pmu_adc_mutex);
62 pmu_write(0x54, 5 | (adc << 4));
63 while ((data & 0x80) == 0)
64 {
65 yield();
66 data = pmu_read(0x57);
67 }
68 int value = (pmu_read(0x55) << 2) | (data & 3);
69 mutex_unlock(&pmu_adc_mutex);
70 return value;
71}
72
73/* millivolts */
74int pmu_read_battery_voltage(void)
75{
76 return pmu_read_adc(0) * 6;
77}
78
79/* milliamps */
80int pmu_read_battery_current(void)
81{
82// return pmu_read_adc(2);
83 return 0;
84}
85
86void pmu_ldo_on_in_standby(unsigned int ldo, int onoff)
87{
88 if (ldo < 4)
89 {
90 unsigned char newval = pmu_read(0x3B) & ~(1 << (2 * ldo));
91 if (onoff) newval |= 1 << (2 * ldo);
92 pmu_write(0x3B, newval);
93 }
94 else if (ldo < 8)
95 {
96 unsigned char newval = pmu_read(0x3C) & ~(1 << (2 * (ldo - 4)));
97 if (onoff) newval |= 1 << (2 * (ldo - 4));
98 pmu_write(0x3C, newval);
99 }
100}
101
102void pmu_ldo_set_voltage(unsigned int ldo, unsigned char voltage)
103{
104 if (ldo > 6) return;
105 pmu_write(0x2d + (ldo << 1), voltage);
106}
107
108void pmu_hdd_power(bool on)
109{
110 pmu_write(0x1b, on ? 1 : 0);
111}
112
113void pmu_ldo_power_on(unsigned int ldo)
114{
115 if (ldo > 6) return;
116 pmu_write(0x2e + (ldo << 1), 1);
117}
118
119void pmu_ldo_power_off(unsigned int ldo)
120{
121 if (ldo > 6) return;
122 pmu_write(0x2e + (ldo << 1), 0);
123}
124
125void pmu_set_wake_condition(unsigned char condition)
126{
127 pmu_write(0xd, condition);
128}
129
130void pmu_enter_standby(void)
131{
132 pmu_write(0xc, 1);
133}
134
135void pmu_read_rtc(unsigned char* buffer)
136{
137 pmu_read_multiple(0x59, 7, buffer);
138}
139
140void pmu_write_rtc(unsigned char* buffer)
141{
142 pmu_write_multiple(0x59, 7, buffer);
143}
diff --git a/firmware/target/arm/s5l8702/ipod6g/pmu-target.h b/firmware/target/arm/s5l8702/ipod6g/pmu-target.h
new file mode 100644
index 0000000000..a8c7851d97
--- /dev/null
+++ b/firmware/target/arm/s5l8702/ipod6g/pmu-target.h
@@ -0,0 +1,46 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: pmu-target.h 24721 2010-02-17 15:54:48Z theseven $
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
22#ifndef __PMU_TARGET_H__
23#define __PMU_TARGET_H__
24
25#include <stdbool.h>
26#include "config.h"
27
28unsigned char pmu_read(int address);
29int pmu_write(int address, unsigned char val);
30int pmu_read_multiple(int address, int count, unsigned char* buffer);
31int pmu_write_multiple(int address, int count, unsigned char* buffer);
32int pmu_read_adc(unsigned int adc);
33int pmu_read_battery_voltage(void);
34int pmu_read_battery_current(void);
35void pmu_init(void);
36void pmu_ldo_on_in_standby(unsigned int ldo, int onoff);
37void pmu_ldo_set_voltage(unsigned int ldo, unsigned char voltage);
38void pmu_ldo_power_on(unsigned int ldo);
39void pmu_ldo_power_off(unsigned int ldo);
40void pmu_set_wake_condition(unsigned char condition);
41void pmu_enter_standby(void);
42void pmu_read_rtc(unsigned char* buffer);
43void pmu_write_rtc(unsigned char* buffer);
44void pmu_hdd_power(bool on);
45
46#endif
diff --git a/firmware/target/arm/s5l8702/ipod6g/power-ipod6g.c b/firmware/target/arm/s5l8702/ipod6g/power-ipod6g.c
new file mode 100644
index 0000000000..973e26968f
--- /dev/null
+++ b/firmware/target/arm/s5l8702/ipod6g/power-ipod6g.c
@@ -0,0 +1,75 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: power-nano2g.c 28190 2010-10-01 18:09:10Z Buschel $
9 *
10 * Copyright © 2009 Bertrik Sikken
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 <stdbool.h>
22#include "config.h"
23#include "inttypes.h"
24#include "s5l8702.h"
25#include "power.h"
26#include "panic.h"
27#include "pmu-target.h"
28#include "usb_core.h" /* for usb_charging_maxcurrent_change */
29
30static int idepowered;
31
32void power_off(void)
33{
34 pmu_set_wake_condition(0x42); /* USB inserted or EXTON1 */
35 pmu_enter_standby();
36
37 while(1);
38}
39
40void power_init(void)
41{
42 idepowered = false;
43}
44
45void ide_power_enable(bool on)
46{
47 idepowered = on;
48 pmu_hdd_power(on);
49}
50
51bool ide_powered()
52{
53 return idepowered;
54}
55
56#if CONFIG_CHARGING
57
58#ifdef HAVE_USB_CHARGING_ENABLE
59void usb_charging_maxcurrent_change(int maxcurrent)
60{
61 bool on = (maxcurrent >= 500);
62 GPIOCMD = 0xb060e | (on ? 1 : 0);
63}
64#endif
65
66unsigned int power_input_status(void)
67{
68 return (PDAT(12) & 8) ? POWER_INPUT_NONE : POWER_INPUT_MAIN_CHARGER;
69}
70
71bool charging_state(void)
72{
73 return false; //TODO: Figure out
74}
75#endif /* CONFIG_CHARGING */
diff --git a/firmware/target/arm/s5l8702/ipod6g/powermgmt-ipod6g.c b/firmware/target/arm/s5l8702/ipod6g/powermgmt-ipod6g.c
new file mode 100644
index 0000000000..3bd3791eeb
--- /dev/null
+++ b/firmware/target/arm/s5l8702/ipod6g/powermgmt-ipod6g.c
@@ -0,0 +1,88 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: powermgmt-nano2g.c 28159 2010-09-24 22:42:06Z Buschel $
9 *
10 * Copyright © 2008 Rafaël Carré
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
22#include "config.h"
23#include "powermgmt.h"
24#include "pmu-target.h"
25#include "power.h"
26#include "audiohw.h"
27
28const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] =
29{
30 3600
31};
32
33const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] =
34{
35 3350
36};
37
38/* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */
39const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] =
40{
41 { 3550, 3783, 3830, 3882, 3911, 3949, 3996, 4067, 4148, 4228, 4310 }
42};
43
44#if CONFIG_CHARGING
45/* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */
46const unsigned short percent_to_volt_charge[11] =
47{
48 3550, 3783, 3830, 3882, 3911, 3949, 3996, 4067, 4148, 4228, 4310
49};
50#endif /* CONFIG_CHARGING */
51
52/* ADC should read 0x3ff=6.00V */
53#define BATTERY_SCALE_FACTOR 6000
54/* full-scale ADC readout (2^10) in millivolt */
55
56
57/* Returns battery voltage from ADC [millivolts] */
58unsigned int battery_adc_voltage(void)
59{
60 int compensation = (10 * (pmu_read_battery_current() - 7)) / 12;
61 if (charging_state()) return pmu_read_battery_voltage() - compensation;
62 return pmu_read_battery_voltage() + compensation;
63}
64
65
66#ifdef HAVE_ACCESSORY_SUPPLY
67void accessory_supply_set(bool enable)
68{
69 if (enable)
70 {
71 /* Accessory voltage supply on */
72//TODO: pmu_ldo_power_on(6);
73 }
74 else
75 {
76 /* Accessory voltage supply off */
77//TODO: pmu_ldo_power_off(6);
78 }
79}
80#endif
81
82#ifdef HAVE_LINEOUT_POWEROFF
83void lineout_set(bool enable)
84{
85 /* Call audio hardware driver implementation */
86 audiohw_enable_lineout(enable);
87}
88#endif
diff --git a/firmware/target/arm/s5l8702/ipod6g/rtc-ipod6g.c b/firmware/target/arm/s5l8702/ipod6g/rtc-ipod6g.c
new file mode 100644
index 0000000000..76ef8ecb00
--- /dev/null
+++ b/firmware/target/arm/s5l8702/ipod6g/rtc-ipod6g.c
@@ -0,0 +1,72 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: rtc-nano2g.c 23114 2009-10-11 18:20:56Z theseven $
9 *
10 * Copyright (C) 2002 by Linus Nielsen Feltzing, Uwe Freese, Laurent Baum
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 "config.h"
22#include "rtc.h"
23#include "kernel.h"
24#include "system.h"
25#include "pmu-target.h"
26
27void rtc_init(void)
28{
29}
30
31int rtc_read_datetime(struct tm *tm)
32{
33 unsigned int i;
34 unsigned char buf[7];
35
36 pmu_read_rtc(buf);
37
38 for (i = 0; i < sizeof(buf); i++)
39 buf[i] = BCD2DEC(buf[i]);
40
41 tm->tm_sec = buf[0];
42 tm->tm_min = buf[1];
43 tm->tm_hour = buf[2];
44 tm->tm_wday = buf[3];
45 tm->tm_mday = buf[4];
46 tm->tm_mon = buf[5] - 1;
47 tm->tm_year = buf[6] + 100;
48
49 return 0;
50}
51
52int rtc_write_datetime(const struct tm *tm)
53{
54 unsigned int i;
55 unsigned char buf[7];
56
57 buf[0] = tm->tm_sec;
58 buf[1] = tm->tm_min;
59 buf[2] = tm->tm_hour;
60 buf[3] = tm->tm_wday;
61 buf[4] = tm->tm_mday;
62 buf[5] = tm->tm_mon + 1;
63 buf[6] = tm->tm_year - 100;
64
65 for (i = 0; i < sizeof(buf); i++)
66 buf[i] = DEC2BCD(buf[i]);
67
68 pmu_write_rtc(buf);
69
70 return 0;
71}
72