summaryrefslogtreecommitdiffstats
path: root/firmware/drivers/lcd-ipodvideo.c
blob: 8c404c80e4b93dd04dbabd5e882cedc9985d49bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/***************************************************************************
 *             __________               __   ___.
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
 *                     \/            \/     \/    \/            \/
 * $Id$
 *
 * LCD driver for iPod Video
 * 
 * Based on code from the ipodlinux project - http://ipodlinux.org/
 * Adapted for Rockbox in December 2005
 *
 * Original file: linux/arch/armnommu/mach-ipod/fb.c
 *
 * Copyright (c) 2003-2005 Bernard Leach (leachbj@bouncycastle.org)
 *
 * All files in this archive are subject to the GNU General Public License.
 * See the file COPYING in the source tree root for full license agreement.
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
 *
 ****************************************************************************/
#include "config.h"
#include "cpu.h"
#include "lcd.h"
#include "kernel.h"
#include "system.h"

/*** hardware configuration ***/

void lcd_set_contrast(int val)
{
  /* TODO: Implement lcd_set_contrast() */
  (void)val;
}

void lcd_set_invert_display(bool yesno)
{
  /* TODO: Implement lcd_set_invert_display() */
  (void)yesno;
}

/* turn the display upside down (call lcd_update() afterwards) */
void lcd_set_flip(bool yesno)
{
  /* TODO: Implement lcd_set_flip() */
  (void)yesno;
}

/* Rolls up the lcd display by the specified amount of lines.
 * Lines that are rolled out over the top of the screen are
 * rolled in from the bottom again. This is a hardware 
 * remapping only and all operations on the lcd are affected.
 * -> 
 * @param int lines - The number of lines that are rolled. 
 *  The value must be 0 <= pixels < LCD_HEIGHT. */
void lcd_roll(int lines)
{
    /* TODO: Implement lcd_roll() */
    lines &= LCD_HEIGHT-1;
}

/* LCD init */
void lcd_init_device(void)
{  
    /* iPodLinux doesn't appear have any LCD init code for the Video */
}

/*** update functions ***/

/* Performance function that works with an external buffer
   note that by and bheight are in 4-pixel units! */
void lcd_blit(const fb_data* data, int x, int by, int width,
              int bheight, int stride)
{
    /* TODO: Implement lcd_blit() */
    (void)data;
    (void)x;
    (void)by;
    (void)width;
    (void)bheight;
    (void)stride;
}

static inline void lcd_bcm_write32(unsigned address, unsigned value)
{
    /* write out destination address as two 16bit values */
    outw(address, 0x30010000);
    outw((address >> 16), 0x30010000);

    /* wait for it to be write ready */
    while ((inw(0x30030000) & 0x2) == 0);

    /* write out the value low 16, high 16 */
    outw(value, 0x30000000);
    outw((value >> 16), 0x30000000);
}

static void lcd_bcm_setup_rect(unsigned cmd,
                               unsigned start_horiz, 
                               unsigned start_vert, 
                               unsigned max_horiz,
                               unsigned max_vert, 
                               unsigned count)
{
    lcd_bcm_write32(0x1F8, 0xFFFA0005);
    lcd_bcm_write32(0xE0000, cmd);
    lcd_bcm_write32(0xE0004, start_horiz);
    lcd_bcm_write32(0xE0008, start_vert);
    lcd_bcm_write32(0xE000C, max_horiz);
    lcd_bcm_write32(0xE0010, max_vert);
    lcd_bcm_write32(0xE0014, count);
    lcd_bcm_write32(0xE0018, count);
    lcd_bcm_write32(0xE001C, 0);
}

static unsigned lcd_bcm_read32(unsigned address) {
    while ((inw(0x30020000) & 1) == 0);

    /* write out destination address as two 16bit values */
    outw(address, 0x30020000);
    outw((address >> 16), 0x30020000);

    /* wait for it to be read ready */
    while ((inw(0x30030000) & 0x10) == 0);

    /* read the value */
    return inw(0x30000000) | inw(0x30000000) << 16;
}

static inline void lcd_bcm_finishup(void) {
    unsigned data; 

    outw(0x31, 0x30030000); 

    lcd_bcm_read32(0x1FC);

    do {
        /* This function takes about 14ms to execute - so we yield() */
        yield();
        data = lcd_bcm_read32(0x1F8);
    } while (data == 0xFFFA0005 || data == 0xFFFF);

    lcd_bcm_read32(0x1FC);
}

/* Update a fraction of the display. */
void lcd_update_rect(int x, int y, int width, int height) ICODE_ATTR;
void lcd_update_rect(int x, int y, int width, int height)
{
    int rect1,rect2,rect3,rect4;
    int newx,newwidth;
    int count;
    int c, r;
    unsigned short *src;

    /* Ensure x and width are both even - so we can read 32-bit aligned 
       data from lcd_framebuffer */
    newx=x&~1;
    newwidth=width&~1;
    if (newx+newwidth < x+width) { newwidth+=2; }
    x=newx; width=newwidth;

    /* calculate the drawing region */
    rect1 = x;                         /* start horiz */
    rect2 = y;                         /* start vert */
    rect3 = (x + width) - 1;           /* max horiz */
    rect4 = (y + height) - 1;          /* max vert */

    /* setup the drawing region */
    count=(width * height) << 1;
    lcd_bcm_setup_rect(0x34, rect1, rect2, rect3, rect4, count);

    src = (unsigned short*)&lcd_framebuffer[y][x];

    /* write out destination address as two 16bit values */
    outw((0xE0020 & 0xffff), 0x30010000);
    outw((0xE0020 >> 16), 0x30010000);

    /* wait for it to be write ready */
    while ((inw(0x30030000) & 0x2) == 0);

    for (r = 0; r < height; r++) {
        /* for each column */
        for (c = 0; c < width; c+=2) {
            /* write out two pixels */
            outw(*(src++), 0x30000000);
            outw(*(src++), 0x30000000);
        }
        src += (LCD_WIDTH - width);
    }

    lcd_bcm_finishup();
}

/* Update the display.
   This must be called after all other LCD functions that change the display. */
void lcd_update(void)
{
    lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT);
}