blob: 19f812c1c7ffe8ef053417987f91d4867afa2f60 [file] [log] [blame]
Jens Arnolde48cc2a2004-05-10 11:38:24 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2004 by Jens Arnold
Nicolas Pennequin357ffb32008-05-05 10:32:46 +000011 * Based on the work of Alan Korr and Jörg Hohensohn
Jens Arnolde48cc2a2004-05-10 11:38:24 +000012 *
Daniel Stenberg2acc0ac2008-06-28 18:10:04 +000013 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
Jens Arnolde48cc2a2004-05-10 11:38:24 +000017 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 ****************************************************************************/
22
23#include "config.h"
Linus Nielsen Feltzing5cf33172004-10-26 06:53:34 +000024#include "cpu.h"
Jens Arnolde48cc2a2004-05-10 11:38:24 +000025
26#define LCDR (PBDR_ADDR+1)
27
Jens Arnolde48cc2a2004-05-10 11:38:24 +000028#define LCD_DS 1 /* PB0 = 1 --- 0001 --- LCD-DS */
29#define LCD_CS 2 /* PB1 = 1 --- 0010 --- /LCD-CS */
30#define LCD_SD 4 /* PB2 = 1 --- 0100 --- LCD-SD */
31#define LCD_SC 8 /* PB3 = 1 --- 1000 --- LCD-SC */
Jens Arnolde48cc2a2004-05-10 11:38:24 +000032
33/*
34 * About /CS,DS,SC,SD
35 * ------------------
36 *
37 * LCD on JBP and JBR uses a SPI protocol to receive orders (SDA and SCK lines)
38 *
39 * - /CS -> Chip Selection line :
40 * 0 : LCD chipset is activated.
41 * - DS -> Data Selection line, latched at the rising edge
42 * of the 8th serial clock (*) :
43 * 0 : instruction register,
Michael Sevakise89a3942006-11-08 16:13:04 +000044 * 1 : data register;
Jens Arnolde48cc2a2004-05-10 11:38:24 +000045 * - SC -> Serial Clock line (SDA).
46 * - SD -> Serial Data line (SCK), latched at the rising edge
Michael Sevakise89a3942006-11-08 16:13:04 +000047 * of each serial clock (*).
Jens Arnolde48cc2a2004-05-10 11:38:24 +000048 *
49 * _ _
50 * /CS \ /
51 * \______________________________________________________/
Michael Sevakise89a3942006-11-08 16:13:04 +000052 * _____ ____ ____ ____ ____ ____ ____ ____ ____ _____
Jens Arnolde48cc2a2004-05-10 11:38:24 +000053 * SD \/ D7 \/ D6 \/ D5 \/ D4 \/ D3 \/ D2 \/ D1 \/ D0 \/
54 * _____/\____/\____/\____/\____/\____/\____/\____/\____/\_____
55 *
Michael Sevakise89a3942006-11-08 16:13:04 +000056 * _____ _ _ _ _ _ _ _ ________
Jens Arnolde48cc2a2004-05-10 11:38:24 +000057 * SC \ * \ * \ * \ * \ * \ * \ * \ *
58 * \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/
Michael Sevakise89a3942006-11-08 16:13:04 +000059 * _ _________________________________________________________
60 * DS \/
Jens Arnolde48cc2a2004-05-10 11:38:24 +000061 * _/\_________________________________________________________
62 *
63 */
64
65 .section .icode,"ax",@progbits
66
67 .align 2
68 .global _lcd_write_command
69 .type _lcd_write_command,@function
70
71/* Write a command byte to the lcd controller
72 *
73 * Arguments:
Jens Arnoldcb1c9e42007-03-18 17:58:49 +000074 * r4 - command byte (int)
Jens Arnolde48cc2a2004-05-10 11:38:24 +000075 *
76 * Register usage:
77 * r0 - scratch
Jens Arnoldcb1c9e42007-03-18 17:58:49 +000078 * r1 - command byte (copied)
Jens Arnoldad70a9b2006-11-09 07:31:31 +000079 * r2 - precalculated port value (CS, DS and SC low, SD high)
Jens Arnolde48cc2a2004-05-10 11:38:24 +000080 * r3 - lcd port address
81 * r5 - 1 (byte count for reuse of the loop in _lcd_write_data)
82 */
83
84_lcd_write_command:
Jens Arnoldcb1c9e42007-03-18 17:58:49 +000085 mov.l .lcdr, r3 /* put lcd data port address in r3 */
86 mov r4, r1 /* copy data byte to r1 */
Jens Arnoldb30ca8c2008-01-14 18:47:00 +000087 mov #0, r5 /* fake end address - stop after first iteration */
Michael Sevakise89a3942006-11-08 16:13:04 +000088
Jens Arnolde48cc2a2004-05-10 11:38:24 +000089 /* This code will fail if an interrupt changes the contents of PBDRL.
90 * If so, we must disable the interrupt here. */
91
Jens Arnoldcb1c9e42007-03-18 17:58:49 +000092 mov.b @r3, r0 /* r0 = PBDRL */
93 or #(LCD_SD), r0 /* r0 |= LCD_SD */
Jens Arnolde48cc2a2004-05-10 11:38:24 +000094 and #(~(LCD_CS|LCD_DS|LCD_SC)),r0 /* r0 &= ~(LCD_CS|LCD_DS|LCD_SC) */
Michael Sevakise89a3942006-11-08 16:13:04 +000095
Jens Arnolde48cc2a2004-05-10 11:38:24 +000096 bra .single_transfer /* jump into the transfer loop */
Jens Arnoldcb1c9e42007-03-18 17:58:49 +000097 mov r0, r2
98
99
100 .align 2
101 .global _lcd_write_command_e
102 .type _lcd_write_command_e,@function
103
104/* Write a command byte and a data byte to the lcd controller
105 *
106 * Arguments:
107 * r4 - command byte
108 * r5 - data byte
109 *
110 * Register usage:
111 * r0 - scratch
112 * r1 - command/data byte (copied)
113 * r2 - precalculated port value (CS, DS and SC low, SD high)
114 * r3 - lcd port address
Jens Arnoldb30ca8c2008-01-14 18:47:00 +0000115 * r5 - fake end address
Jens Arnoldcb1c9e42007-03-18 17:58:49 +0000116 * r6 - data byte (saved)
117 * r7 - saved pr
118 */
119
120_lcd_write_command_e:
121 mov.l .lcdr, r3 /* put lcd data port address in r3 */
122 mov r4, r1 /* copy data byte to r1 */
123 mov r5, r6
Jens Arnoldb30ca8c2008-01-14 18:47:00 +0000124 mov #0, r5 /* fake end address - stop after first iteration */
Jens Arnoldcb1c9e42007-03-18 17:58:49 +0000125
126 /* This code will fail if an interrupt changes the contents of PBDRL.
127 * If so, we must disable the interrupt here. */
128
129 mov.b @r3, r0 /* r0 = PBDRL */
130 or #(LCD_SD), r0 /* r0 |= LCD_SD */
131 and #(~(LCD_CS|LCD_DS|LCD_SC)),r0 /* r0 &= ~(LCD_CS|LCD_DS|LCD_SC) */
132
133 sts pr, r7
134 bsr .single_transfer /* jump into the transfer loop */
135 mov r0, r2
136
137 lds r7, pr
138 mov r6, r1
Jens Arnoldcb1c9e42007-03-18 17:58:49 +0000139 or #(LCD_DS|LCD_SD), r0 /* r0 |= LCD_DS|LCD_SD */
140 and #(~(LCD_CS|LCD_SC)), r0 /* r0 &= ~(LCD_CS|LCD_SC) */
141 bra .single_transfer /* jump into the transfer loop */
142 mov r0, r2
Jens Arnolde48cc2a2004-05-10 11:38:24 +0000143
144
145 .align 2
146 .global _lcd_write_data
147 .type _lcd_write_data,@function
148
149
150/* A high performance function to write data to the display,
151 * one or multiple bytes.
152 *
153 * Arguments:
154 * r4 - data address
155 * r5 - byte count
156 *
157 * Register usage:
158 * r0 - scratch
159 * r1 - current data byte
Jens Arnoldb30ca8c2008-01-14 18:47:00 +0000160 * r2 - precalculated port value (CS and SC low, DS and SD high)
Jens Arnolde48cc2a2004-05-10 11:38:24 +0000161 * r3 - lcd port address
Jens Arnoldb30ca8c2008-01-14 18:47:00 +0000162 * r4 - current address
163 * r5 - end address
Jens Arnolde48cc2a2004-05-10 11:38:24 +0000164 */
165
166_lcd_write_data:
Jens Arnoldcb1c9e42007-03-18 17:58:49 +0000167 mov.l .lcdr, r3 /* put lcd data port address in r3 */
Jens Arnoldb30ca8c2008-01-14 18:47:00 +0000168 add r4, r5 /* end address */
Jens Arnolde48cc2a2004-05-10 11:38:24 +0000169
170 /* This code will fail if an interrupt changes the contents of PBDRL.
171 * If so, we must disable the interrupt here. If disabling interrupts
Nicolas Pennequin357ffb32008-05-05 10:32:46 +0000172 * for a long time (~9200 clks = ~830 µs for transferring 112 bytes on
Jens Arnolde48cc2a2004-05-10 11:38:24 +0000173 * recorders)is undesirable, the loop has to be rewritten to
174 * disable/precalculate/transfer/enable for each iteration. However,
175 * this would significantly decrease performance. */
176
Jens Arnoldcb1c9e42007-03-18 17:58:49 +0000177 mov.b @r3, r0 /* r0 = PBDRL */
178 or #(LCD_DS|LCD_SD), r0 /* r0 |= LCD_DS|LCD_SD */
179 and #(~(LCD_CS|LCD_SC)), r0 /* r0 &= ~(LCD_CS|LCD_SC) */
180 mov r0, r2
Jens Arnolde48cc2a2004-05-10 11:38:24 +0000181
182 .align 2
183.multi_transfer:
Jens Arnoldcb1c9e42007-03-18 17:58:49 +0000184 mov.b @r4+, r1 /* load data byte from memory */
Jens Arnolde48cc2a2004-05-10 11:38:24 +0000185
Michael Sevakise89a3942006-11-08 16:13:04 +0000186.single_transfer:
Jens Arnolde48cc2a2004-05-10 11:38:24 +0000187 shll16 r1 /* shift data to most significant byte */
188 shll8 r1
189
190 shll r1 /* shift the msb into carry */
Jens Arnoldcb1c9e42007-03-18 17:58:49 +0000191 mov r2, r0 /* copy precalculated port value */
Jens Arnolde48cc2a2004-05-10 11:38:24 +0000192 bt 1f /* data bit = 1? */
Jens Arnoldcb1c9e42007-03-18 17:58:49 +0000193 and #(~LCD_SD), r0 /* no: r0 &= ~LCD_SD */
Jens Arnoldb30ca8c2008-01-14 18:47:00 +00001941:
Jens Arnolde48cc2a2004-05-10 11:38:24 +0000195 shll r1 /* next shift here for alignment */
Jens Arnoldcb1c9e42007-03-18 17:58:49 +0000196 mov.b r0, @r3 /* set data to port */
197 or #(LCD_SC), r0 /* rise SC (independent of SD level) */
198 mov.b r0, @r3 /* set to port */
Michael Sevakise89a3942006-11-08 16:13:04 +0000199
Jens Arnoldcb1c9e42007-03-18 17:58:49 +0000200 mov r2, r0
Jens Arnolde48cc2a2004-05-10 11:38:24 +0000201 bt 1f
Jens Arnoldcb1c9e42007-03-18 17:58:49 +0000202 and #(~LCD_SD), r0
Jens Arnoldb30ca8c2008-01-14 18:47:00 +00002031:
Jens Arnoldcb1c9e42007-03-18 17:58:49 +0000204 mov.b r0, @r3
205 or #(LCD_SC), r0
206 mov.b r0, @r3
Jens Arnolde48cc2a2004-05-10 11:38:24 +0000207
Michael Sevakise89a3942006-11-08 16:13:04 +0000208 shll r1
Jens Arnoldcb1c9e42007-03-18 17:58:49 +0000209 mov r2, r0
Michael Sevakise89a3942006-11-08 16:13:04 +0000210 bt 1f
Jens Arnoldcb1c9e42007-03-18 17:58:49 +0000211 and #(~LCD_SD), r0
Jens Arnoldb30ca8c2008-01-14 18:47:00 +00002121:
Michael Sevakise89a3942006-11-08 16:13:04 +0000213 shll r1
Jens Arnoldcb1c9e42007-03-18 17:58:49 +0000214 mov.b r0, @r3
215 or #(LCD_SC), r0
216 mov.b r0, @r3
Michael Sevakise89a3942006-11-08 16:13:04 +0000217
Jens Arnoldcb1c9e42007-03-18 17:58:49 +0000218 mov r2, r0
Michael Sevakise89a3942006-11-08 16:13:04 +0000219 bt 1f
Jens Arnoldcb1c9e42007-03-18 17:58:49 +0000220 and #(~LCD_SD), r0
Jens Arnoldb30ca8c2008-01-14 18:47:00 +00002211:
Jens Arnoldcb1c9e42007-03-18 17:58:49 +0000222 mov.b r0, @r3
223 or #(LCD_SC), r0
224 mov.b r0, @r3
Michael Sevakise89a3942006-11-08 16:13:04 +0000225
226 shll r1
Jens Arnoldcb1c9e42007-03-18 17:58:49 +0000227 mov r2, r0
Michael Sevakise89a3942006-11-08 16:13:04 +0000228 bt 1f
Jens Arnoldcb1c9e42007-03-18 17:58:49 +0000229 and #(~LCD_SD), r0
Jens Arnoldb30ca8c2008-01-14 18:47:00 +00002301:
Michael Sevakise89a3942006-11-08 16:13:04 +0000231 shll r1
Jens Arnoldcb1c9e42007-03-18 17:58:49 +0000232 mov.b r0, @r3
233 or #(LCD_SC), r0
234 mov.b r0, @r3
Michael Sevakise89a3942006-11-08 16:13:04 +0000235
Jens Arnoldcb1c9e42007-03-18 17:58:49 +0000236 mov r2, r0
Michael Sevakise89a3942006-11-08 16:13:04 +0000237 bt 1f
Jens Arnoldcb1c9e42007-03-18 17:58:49 +0000238 and #(~LCD_SD), r0
Jens Arnoldb30ca8c2008-01-14 18:47:00 +00002391:
Jens Arnoldcb1c9e42007-03-18 17:58:49 +0000240 mov.b r0, @r3
241 or #(LCD_SC), r0
242 mov.b r0, @r3
Michael Sevakise89a3942006-11-08 16:13:04 +0000243
244 shll r1
Jens Arnoldcb1c9e42007-03-18 17:58:49 +0000245 mov r2, r0
Michael Sevakise89a3942006-11-08 16:13:04 +0000246 bt 1f
Jens Arnoldcb1c9e42007-03-18 17:58:49 +0000247 and #(~LCD_SD), r0
Jens Arnoldb30ca8c2008-01-14 18:47:00 +00002481:
Michael Sevakise89a3942006-11-08 16:13:04 +0000249 shll r1
Jens Arnoldcb1c9e42007-03-18 17:58:49 +0000250 mov.b r0, @r3
251 or #(LCD_SC), r0
252 mov.b r0, @r3
Michael Sevakise89a3942006-11-08 16:13:04 +0000253
Jens Arnoldcb1c9e42007-03-18 17:58:49 +0000254 mov r2, r0
Michael Sevakise89a3942006-11-08 16:13:04 +0000255 bt 1f
Jens Arnoldcb1c9e42007-03-18 17:58:49 +0000256 and #(~LCD_SD), r0
Jens Arnoldb30ca8c2008-01-14 18:47:00 +00002571:
Jens Arnoldcb1c9e42007-03-18 17:58:49 +0000258 mov.b r0, @r3
259 or #(LCD_SC), r0
260 mov.b r0, @r3
Jens Arnolde48cc2a2004-05-10 11:38:24 +0000261
Jens Arnoldb30ca8c2008-01-14 18:47:00 +0000262 cmp/hi r4, r5 /* some blocks left? */
263 bt .multi_transfer
Jens Arnolde48cc2a2004-05-10 11:38:24 +0000264
265 or #(LCD_CS|LCD_DS|LCD_SD|LCD_SC),r0 /* restore port */
Michael Sevakise89a3942006-11-08 16:13:04 +0000266 rts
Jens Arnoldcb1c9e42007-03-18 17:58:49 +0000267 mov.b r0, @r3
Jens Arnolde48cc2a2004-05-10 11:38:24 +0000268
269 /* This is the place to reenable the interrupts, if we have disabled
270 * them. See above. */
271
272 .align 2
273.lcdr:
274 .long LCDR