Root/qiboot/src/cpu/s3c2410/gta01.c

1/*
2 * (C) Copyright 2007 OpenMoko, Inc.
3 * Author: Andy Green <andy@openmoko.com>
4 *
5 * Configuation settings for the OPENMOKO Neo GTA02 Linux GSM phone
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 * MA 02111-1307 USA
21 *
22 */
23
24#include <qi.h>
25#include <neo_gta01.h>
26#include <serial-s3c24xx.h>
27#include <ports-s3c24xx.h>
28#include <s3c24xx-mci.h>
29#include <i2c-bitbang-s3c24xx.h>
30#include <pcf50606.h>
31
32#define GTA01_DEBUG_UART 0
33#define PCF50606_I2C_ADS 0x08
34
35
36struct pcf50606_init {
37        u8 index;
38        u8 value;
39};
40
41/* initial register set for PCF50606 in Neo1973 devices */
42const struct pcf50606_init pcf50606_initial_regs[] = {
43    { PCF50606_REG_OOCS, 0x00 },
44    { PCF50606_REG_INT1M, 0x00 },
45    { PCF50606_REG_INT2M, 0x00 },
46    { PCF50606_REG_INT3M, PCF50606_INT3_TSCPRES },
47    { PCF50606_REG_OOCC1, PCF50606_OOCC1_RTCWAK | PCF50606_OOCC1_CHGWAK |
48                  PCF50606_OOCC1_EXTONWAK_HIGH },
49    { PCF50606_REG_OOCC2, PCF50606_OOCC2_ONKEYDB_14ms | PCF50606_OOCC2_EXTONDB_14ms },
50    { PCF50606_REG_PSSC, 0x00 },
51    { PCF50606_REG_PWROKM, 0x00 },
52    { PCF50606_REG_DCDC1, 0x18 }, /* GL_1V5: off */
53    { PCF50606_REG_DCDC2, 0x00 },
54    { PCF50606_REG_DCDC3, 0x00 },
55    { PCF50606_REG_DCDC4, 0x30 }, /* 1.25A */
56
57    { PCF50606_REG_DCDEC1, 0xe8 }, /* IO_3V3: on */
58    { PCF50606_REG_DCDEC2, 0x00 },
59
60    { PCF50606_REG_DCUDC1, 0xc4 }, /* CORE_1V8: 2.1V if PWREN2 = HIGH */
61    { PCF50606_REG_DCUDC2, 0x30 }, /* 1.25A current limit */
62
63    { PCF50606_REG_IOREGC, 0xf8 }, /* CODEC_3V3: on */
64    { PCF50606_REG_D1REGC1, 0x16 }, /* BT_3V15: off */
65
66    { PCF50606_REG_D2REGC1, 0x10 }, /* GL_2V5: off */
67
68    { PCF50606_REG_D3REGC1, 0xec }, /* STBY_1V8: 2.1V */
69
70    { PCF50606_REG_LPREGC1, 0xf8 }, /* LCM_3V3: on */
71    { PCF50606_REG_LPREGC2, 0x00 },
72
73    { PCF50606_REG_MBCC1, 0x01 }, /* CHGAPE */
74    { PCF50606_REG_MBCC2, 0x00 }, /* unlimited charging */
75    { PCF50606_REG_MBCC3, 0x1a }, /* 0.2*Ifast, 4.20V */
76    { PCF50606_REG_BBCC, 0x1f }, /* 400uA */
77    { PCF50606_REG_ADCC1, 0x00 },
78    { PCF50606_REG_ADCC2, 0x00 },
79    { PCF50606_REG_ACDC1, 0x86 }, /* ACD thresh 1.6V, enabled */
80    { PCF50606_REG_BVMC, PCF50606_BVMC_THRSHLD_3V3 },
81    { PCF50606_REG_PWMC1, 0x00 },
82    { PCF50606_REG_LEDC1, 0x00 },
83    { PCF50606_REG_LEDC2, 0x00 },
84    { PCF50606_REG_GPOC1, 0x00 },
85    { PCF50606_REG_GPOC2, 0x00 },
86    { PCF50606_REG_GPOC3, 0x00 },
87    { PCF50606_REG_GPOC4, 0x00 },
88    { PCF50606_REG_GPOC5, 0x00 },
89};
90
91
92static const struct board_variant board_variants[] = {
93    [0] = {
94        .name = "Bv4",
95        .machine_revision = 0x240,
96    }
97};
98
99
100void port_init_gta01(void)
101{
102    int n;
103    unsigned int * MPLLCON = (unsigned int *)0x4c000004;
104
105    rGPACON = 0x005E0FFF;
106    rGPADAT = 0x00010000; /* nNAND_WP set high */
107
108    rGPBCON = 0x00045455;
109    rGPBUP = 0x000007FF;
110    rGPBDAT = 0x00000004; /* SD-card pwr off */
111
112    rGPCCON = 0xAAAA12A9;
113    rGPCUP = 0x0000FFFF;
114
115    rGPDCON = 0xAAAAAAAA;
116    rGPDUP = 0x0000FFFF;
117
118    rGPECON = 0xAAAAAAAA;
119    rGPEUP = 0x0000FFFF;
120
121    rGPFCON = 0x0000aa99;
122    rGPFUP = 0x000000FF;
123    rGPFDAT = 0x00000004;
124
125    rGPGCON = 0xFF14F0F8;
126    rGPGUP = 0x0000AFEF;
127
128    rGPHCON = 0x0000FAAA;
129    rGPHUP = 0x000007FF;
130
131
132    /* Load PMU with safe values */
133
134    for (n = 0; n < ARRAY_SIZE(pcf50606_initial_regs); n++)
135        i2c_write_sync(&bb_s3c24xx, PCF50606_I2C_ADS,
136                pcf50606_initial_regs[n].index,
137                pcf50606_initial_regs[n].value);
138
139    /* Give a short vibrate notification */
140    rGPBDAT |= (1 << 3);
141    udelay(1000000);
142    rGPBDAT &= ~(1 << 3);
143
144
145    /* change CPU to 266MHz 1:2:4 */
146    *MPLLCON = ((0x7d << 12) + (0x1 << 4) + 0x1);
147    /* Delay after update of PLL: Page 7-19, seven nops */
148    asm __volatile__ (
149        "nop\n"
150        "nop\n"
151        "nop\n"
152        "nop\n"
153        "nop\n"
154        "nop\n"
155        "nop\n"
156    );
157
158    
159    /* set debug UART working at 115kbps */
160    serial_init_115200_s3c24xx(GTA01_DEBUG_UART, 66 /* 66.5MHz PCLK */);
161}
162
163
164int sd_card_init_gta01(void)
165{
166    int retval = -1;
167
168    /* Check if AUX is held. Then skip SD-card kernels!
169     * FIXME: This would be nicer to do with an API.
170     */
171    if (!(rGPFDAT & (1 << 6))) {
172        return -1;
173    }
174
175    /* if SD card inserted, power it up and initialize*/
176    if (!(rGPFDAT & (1 << 5)))
177    {
178        rGPBDAT &= ~(1 << 2);
179        retval = s3c24xx_mmc_init(1);
180    }
181    return retval;
182}
183
184int sd_card_block_read_gta01(unsigned char * buf, unsigned long start512,
185                int blocks512)
186{
187    return s3c24xx_mmc_bread(0, start512, blocks512, buf);
188}
189
190int is_this_board_gta01(void)
191{
192    /* FIXME: How to check for GTA01 ? */
193        return 1;
194}
195
196const struct board_variant const * get_board_variant_gta01(void)
197{
198    return &board_variants[0];
199}
200
201static __attribute__ (( section (".steppingstone") )) void putc_gta01(char c)
202{
203    serial_putc_s3c24xx(GTA01_DEBUG_UART, c);
204}
205
206static void close_gta01(void)
207{
208    /* set I2C GPIO back to peripheral unit */
209    (bb_s3c24xx.close)();
210}
211
212/* Here we will care only about AUX button as polling for PWR button
213 * through i2c slows down the boot */
214
215static u8 get_ui_keys_gta01(void)
216{
217    u8 keys;
218    u8 ret = 0;
219    static u8 old_keys = 0; /* previous state for debounce */
220    static u8 older_keys = 0; /* previous debounced output for edge detect */
221
222    /* GPF6 is AUX on GTA01, map to UI_ACTION_SKIPKERNEL, down = 0 */
223    keys = ! (rGPFDAT & (1 << 6));
224
225    /* edge action */
226    if ((old_keys & 1) && !(older_keys & 1))
227        ret |= UI_ACTION_SKIPKERNEL;
228
229    older_keys = old_keys;
230    old_keys = keys;
231
232    return ret;
233}
234
235static u8 get_ui_debug_gta01(void)
236{
237    /* PWR button state can be seen in OOCS b0, down = 0, map to UI_ACTION_ADD_DEBUG */
238    return !(i2c_read_sync(&bb_s3c24xx, PCF50606_I2C_ADS, PCF50606_REG_OOCS) & 1);
239}
240
241/*
242 * API for bootloader on this machine
243 */
244
245const struct board_api board_api_gta01 = {
246    .name = "Neo1973 GTA01",
247    .linux_machine_id = 1182,
248    .linux_mem_start = 0x30000000,
249    .linux_mem_size = (128 * 1024 * 1024),
250    .linux_tag_placement = 0x30000000 + 0x100,
251    .get_board_variant = get_board_variant_gta01,
252    .is_this_board = is_this_board_gta01,
253    .port_init = port_init_gta01,
254    .putc = putc_gta01,
255    .close = close_gta01,
256    .get_ui_keys = get_ui_keys_gta01,
257    .get_ui_debug = get_ui_debug_gta01,
258
259    .commandline_board = "mtdparts="
260                "neo1973-nand:"
261                 "0x00040000(qi),"
262                 "0x00004000(u-boot_env),"
263                 "0x00200000(kernel),"
264                 "0x000a0000(splash),"
265                 "0x03d1c000(rootfs) "
266                   "loglevel=4 "
267                   "console=tty0 "
268                   "console=ttySAC0,115200 "
269                   "init=/sbin/init "
270                   "ro ",
271    .commandline_board_debug = " loglevel=8 ",
272    .noboot = "boot/noboot-GTA01",
273    .append = "boot/append-GTA01",
274    /* these are the ways we could boot GTA01 in order to try */
275    .kernel_source = {
276        [0] = {
277            .name = "SD Card EXT2 Kernel p1",
278            .block_init = sd_card_init_gta01,
279            .block_read = sd_card_block_read_gta01,
280            .partition_index = 1,
281            .filesystem = FS_EXT2,
282            .filepath = "boot/uImage-GTA01.bin",
283            .commandline_append = "root=/dev/mmcblk0p1 rootdelay=1 ",
284        },
285        [1] = {
286            .name = "SD Card EXT2 Kernel p2",
287            .block_init = sd_card_init_gta01,
288            .block_read = sd_card_block_read_gta01,
289            .partition_index = 2,
290            .filesystem = FS_EXT2,
291            .filepath = "boot/uImage-GTA01.bin",
292            .commandline_append = "root=/dev/mmcblk0p2 rootdelay=1 ",
293        },
294        [2] = {
295            .name = "SD Card EXT2 Kernel p3",
296            .block_init = sd_card_init_gta01,
297            .block_read = sd_card_block_read_gta01,
298            .partition_index = 3,
299            .filesystem = FS_EXT2,
300            .filepath = "boot/uImage-GTA01.bin",
301            .commandline_append = "root=/dev/mmcblk0p3 rootdelay=1 ",
302        },
303        [3] = {
304            .name = "NAND Kernel",
305            .block_read = nand_read_ll,
306            .offset_blocks512_if_no_partition = 0x44000 / 512,
307            .filesystem = FS_RAW,
308            .commandline_append = "rootfstype=jffs2 "
309                       "root=/dev/mtdblock4 ",
310        },
311    },
312};
313

Archive Download this file



interactive