blob: 35332caef74d7a638c9a455419d434c5a3cb48b8 [file] [log] [blame]
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -08001/*
2 * Copyright (c) 2009, Google Inc.
3 * All rights reserved.
Ajay Dudani32edd472009-11-25 14:43:14 -08004 * Copyright (c) 2009, Code Aurora Forum. All rights reserved.
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -08005 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 * * Neither the name of Google, Inc. nor the names of its contributors
16 * may be used to endorse or promote products derived from this
17 * software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
29 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33#include <debug.h>
34#include <dev/keys.h>
35#include <dev/gpio_keypad.h>
36#include <lib/ptable.h>
37#include <dev/flash.h>
Chandan Uddaraju885e4db2009-12-03 22:45:26 -080038#include <smem.h>
39
40#define LINUX_MACHTYPE_SURF 1007016
41#define LINUX_MACHTYPE_FFA 1007017
42#define LINUX_MACHTYPE_FLUID 1007018
43
44//Enum values for 7x30 target platforms.
45enum platform
46{
47 HW_PLATFORM_UNKNOWN = 0,
48 HW_PLATFORM_SURF = 1,
49 HW_PLATFORM_FFA = 2,
50 HW_PLATFORM_FLUID = 3,
51 HW_PLATFORM_32BITS = 0x7FFFFFFF
52};
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -080053
54static struct ptable flash_ptable;
55
56/* for these partitions, start will be offset by either what we get from
57 * smem, or from the above offset if smem is not useful. Also, we should
58 * probably have smem_ptable code populate our flash_ptable.
59 *
60 * When smem provides us with a full partition table, we can get rid of
61 * this altogether.
62 *
63 */
64static struct ptentry board_part_list[] = {
65 {
66 .start = 0,
67 .length = 40,
68 .name = "boot",
69 },
70 {
71 .start = 56,
Ajay Dudani232ce812009-12-02 00:14:11 -080072 .length = 304 /* 76MB */,
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -080073 .name = "system",
74 },
75 {
Ajay Dudani232ce812009-12-02 00:14:11 -080076 .start = 364,
77 .length = 304 /* 76MB */,
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -080078 .name = "cache",
79 },
80 {
Ajay Dudani232ce812009-12-02 00:14:11 -080081 .start = 672,
82 .length = 304 /* 76MB */,
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -080083 .name = "userdata",
84 },
85};
86static int num_parts = sizeof(board_part_list)/sizeof(struct ptentry);
87
88void smem_ptable_init(void);
89unsigned smem_get_apps_flash_start(void);
90
91void keypad_init(void);
92
93void target_init(void)
94{
95 unsigned offset;
96 struct flash_info *flash_info;
97 int i;
98
99 dprintf(INFO, "target_init()\n");
100
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -0800101 keys_init();
102 keypad_init();
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -0800103
104 ptable_init(&flash_ptable);
105 smem_ptable_init();
106
107 flash_init();
108 flash_info = flash_get_info();
109 ASSERT(flash_info);
110
111 offset = smem_get_apps_flash_start();
112 if (offset == 0xffffffff)
113 while(1);
114
115 for (i = 0; i < num_parts; i++) {
116 struct ptentry *ptn = &board_part_list[i];
117 unsigned len = ptn->length;
118
119 if ((len == 0) && (i == num_parts - 1))
120 len = flash_info->num_blocks - offset - ptn->start;
121 ptable_add(&flash_ptable, ptn->name, offset + ptn->start,
122 len, ptn->flags);
123 }
124
125 ptable_dump(&flash_ptable);
126 flash_set_ptable(&flash_ptable);
127}
Chandan Uddaraju885e4db2009-12-03 22:45:26 -0800128
129unsigned board_machtype(void)
130{
131 struct smem_board_info board_info;
132 unsigned int board_info_struct_len = sizeof(board_info);
133 enum platform platform_type = 0;
134 unsigned smem_status;
135
136 smem_status = smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION,
137 &board_info, board_info_struct_len );
138 if(smem_status)
139 {
140 dprintf(CRITICAL, "ERROR: unable to read shared memory for Hardware Platform\n");
141 }
142
143 if (board_info.format == 3)
144 {
145 platform_type = board_info.hw_platform;
146 switch (platform_type)
147 {
148 case HW_PLATFORM_SURF:
149 return LINUX_MACHTYPE_SURF;
150 case HW_PLATFORM_FFA:
151 return LINUX_MACHTYPE_FFA;
152 case HW_PLATFORM_FLUID:
153 return LINUX_MACHTYPE_FLUID;
154 default:
155 return LINUX_MACHTYPE_SURF;
156 }
157 }
158 return LINUX_MACHTYPE_SURF;
159}