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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
|
/* u-boot driver for the tpo TD028TTEC1 LCM
*
* Copyright (C) 2006-2007 by OpenMoko, Inc.
* Author: Harald Welte <laforge@openmoko.org>
* All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*/
/* modified by hns@goldelico.com
* now is just a SPI/GPIO driver to the serial interface of the TD028TTEC1
*** should all this code be moved to drivers/misc or drivers/video ?
*/
#include <common.h>
#include <asm/errno.h>
#include <asm/io.h>
#include <asm/arch/mux.h>
#include <asm/arch/sys_proto.h>
#include <asm/arch/gpio.h>
#include <asm/mach-types.h>
#include "TD028TTEC1.h"
#ifdef CONFIG_OMAP3_BEAGLE
#ifdef CONFIG_OMAP3_GTA04
#define GPIO_CS 19
#define GPIO_SCL 12
#define GPIO_DIN 18
#define GPIO_DOUT 20
#else /* Beagle Hybrid */
#define GPIO_CS 161
#define GPIO_SCL 162
#define GPIO_DIN 159
#define GPIO_DOUT 158
#endif
#define SPI_READ() (omap_get_gpio_datain(GPIO_DIN))
#define SPI_CS(bit) (omap_set_gpio_dataout(GPIO_CS, bit))
#define SPI_SDA(bit) (omap_set_gpio_dataout(GPIO_DOUT, bit))
#define SPI_SCL(bit) (omap_set_gpio_dataout(GPIO_SCL, bit))
#elif !defined(CONFIG_GTA02_REVISION) /* GTA01 */
#define GTA01_SCLK (1 << 7) /* GPG7 */
#define GTA01_MOSI (1 << 6) /* GPG6 */
#define GTA01_MISO (1 << 5) /* GPG5 */
#define GTA01_CS (1 << 3) /* GPG3 */
#define SPI_READ ((immr->GPGDAT & GTA01_MISO) != 0)
#define SPI_CS(bit) if (bit) gpio->GPGDAT |= GTA01_CS; \
else gpio->GPGDAT &= ~GTA01_CS
#define SPI_SDA(bit) if (bit) gpio->GPGDAT |= GTA01_MOSI; \
else gpio->GPGDAT &= ~GTA01_MOSI
#define SPI_SCL(bit) if (bit) gpio->GPGDAT |= GTA01_SCLK; \
else gpio->GPGDAT &= ~GTA01_SCLK
#else /* GTA02 */
extern void smedia3362_spi_cs(int);
extern void smedia3362_spi_sda(int);
extern void smedia3362_spi_scl(int);
extern void smedia3362_lcm_reset(int);
#define SPI_READ $not$implemented$
#define SPI_CS(b) smedia3362_spi_cs(b)
#define SPI_SDA(b) smedia3362_spi_sda(b)
#define SPI_SCL(b) smedia3362_spi_scl(b)
#endif
/* 150uS minimum clock cycle, we have two of this plus our other
* instructions */
#define SPI_DELAY() udelay(150)
static int jbt_spi_xfer(int wordnum, int bitlen, u_int16_t *dout)
{
#if !defined(_BEAGLE_)
S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO();
#endif
u_int16_t tmpdout = 0;
int i, j;
// DEBUGP("spi_xfer: dout %08X wordnum %u bitlen %d\n",
// *(uint *)dout, wordnum, bitlen);
SPI_CS(0);
for (i = 0; i < wordnum; i ++) {
tmpdout = dout[i];
for (j = 0; j < bitlen; j++) {
SPI_SCL(0);
if (tmpdout & (1 << (bitlen-1))) {
SPI_SDA(1);
// DEBUGPC("1");
// VERIFY(1);
} else {
SPI_SDA(0);
// DEBUGPC("0");
// VERIFY(0);
}
SPI_DELAY();
SPI_SCL(1);
SPI_DELAY();
tmpdout <<= 1;
}
// DEBUGPC(" ");
}
// DEBUGPC("\n");
SPI_CS(1);
return 0;
}
#define JBT_COMMAND 0x000
#define JBT_DATA 0x100
int jbt_reg_write_nodata(struct jbt_info *jbt, u_int8_t reg)
{
int rc;
jbt->tx_buf[0] = JBT_COMMAND | reg;
rc = jbt_spi_xfer(1, 9, jbt->tx_buf);
return rc;
}
int jbt_reg_write(struct jbt_info *jbt, u_int8_t reg, u_int8_t data)
{
int rc;
jbt->tx_buf[0] = JBT_COMMAND | reg;
jbt->tx_buf[1] = JBT_DATA | data;
rc = jbt_spi_xfer(2, 9, jbt->tx_buf);
return rc;
}
int jbt_reg_write16(struct jbt_info *jbt, u_int8_t reg, u_int16_t data)
{
int rc;
jbt->tx_buf[0] = JBT_COMMAND | reg;
jbt->tx_buf[1] = JBT_DATA | (data >> 8);
jbt->tx_buf[2] = JBT_DATA | (data & 0xff);
rc = jbt_spi_xfer(3, 9, jbt->tx_buf);
return rc;
}
int jbt_check(void)
{ // check if we have connectivity
#if defined(_BEAGLE_)
int err;
int i;
int failed=0;
int cnt0 = 0;
int cnt1 = 0;
#if 0
printf("jbt_reg_init()\n");
#endif
err = omap_request_gpio(GPIO_CS);
SPI_CS(1); // unselect
err |= omap_request_gpio(GPIO_SCL);
SPI_SCL(1); // default
err |= omap_request_gpio(GPIO_DOUT);
SPI_SDA(0);
err |= omap_request_gpio(GPIO_DIN);
if(err)
{
printf("jbt_reg_init() - could not get GPIOs\n");
return 1;
}
#if 1 // should have already been done by MUX settings!
omap_set_gpio_direction(GPIO_CS, 0); // output
omap_set_gpio_direction(GPIO_SCL, 0); // output
omap_set_gpio_direction(GPIO_DOUT, 0); // output
omap_set_gpio_direction(GPIO_DIN, 1); // input (for reading back)
#endif
// omap_free_gpio(GPIO_DIN);
// omap_free_gpio(GPIO_DOUT);
// omap_free_gpio(GPIO_CS);
// omap_free_gpio(GPIO_SCL);
for(i=0; i<16; i++)
{ // check for connection between GPIO158 -> GPIO159; since we have 10 kOhm pse. make sure that the PUP/PDN is disabled on DIN in the MUX config!
int bit=i&1;
SPI_SDA(bit); // write bit
SPI_DELAY();
#if 0
printf("bit: %d out: %d in: %d (%d)\n", bit, omap_get_gpio_datain(GPIO_DOUT), omap_get_gpio_datain(GPIO_DIN), SPI_READ());
#endif
if(SPI_READ() != bit) // did not read back
failed++;
if(SPI_READ())
cnt1++;
else
cnt0++;
}
if(failed > 0)
{
printf("DISPLAY: ");
if(cnt0 == 0)
printf("DIN (GPIO%d) stuck at 0\n", GPIO_DIN);
else if(cnt1 == 0)
printf("DIN (GPIO%d) stuck at 1\n", GPIO_DIN);
else
printf("DIN-DOUT (GPIO%d- (GPIO%d)) connetion broken\n", GPIO_DIN, GPIO_DOUT);
return 1;
}
#endif
return 0;
}
int jbt_reg_init(void)
{
if(jbt_check())
return 1; // some error
/* according to data sheet: wait 50ms (Tpos of LCM). However, 50ms
* seems unreliable with later LCM batches, increasing to 90ms */
udelay(90000);
printf("did jbt_reg_init()\n");
return 0;
}
|