nseries.c 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422
  1. /*
  2. * Nokia N-series internet tablets.
  3. *
  4. * Copyright (C) 2007 Nokia Corporation
  5. * Written by Andrzej Zaborowski <andrew@openedhand.com>
  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 or
  10. * (at your option) version 3 of the License.
  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 along
  18. * with this program; if not, write to the Free Software Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  20. */
  21. #include "qemu-common.h"
  22. #include "sysemu.h"
  23. #include "omap.h"
  24. #include "arm-misc.h"
  25. #include "irq.h"
  26. #include "console.h"
  27. #include "boards.h"
  28. #include "i2c.h"
  29. #include "devices.h"
  30. #include "flash.h"
  31. #include "hw.h"
  32. #include "bt.h"
  33. /* Nokia N8x0 support */
  34. struct n800_s {
  35. struct omap_mpu_state_s *cpu;
  36. struct rfbi_chip_s blizzard;
  37. struct {
  38. void *opaque;
  39. uint32_t (*txrx)(void *opaque, uint32_t value, int len);
  40. struct uwire_slave_s *chip;
  41. } ts;
  42. i2c_bus *i2c;
  43. int keymap[0x80];
  44. i2c_slave *kbd;
  45. struct tusb_s *usb;
  46. void *retu;
  47. void *tahvo;
  48. void *nand;
  49. };
  50. /* GPIO pins */
  51. #define N8X0_TUSB_ENABLE_GPIO 0
  52. #define N800_MMC2_WP_GPIO 8
  53. #define N800_UNKNOWN_GPIO0 9 /* out */
  54. #define N810_MMC2_VIOSD_GPIO 9
  55. #define N810_HEADSET_AMP_GPIO 10
  56. #define N800_CAM_TURN_GPIO 12
  57. #define N810_GPS_RESET_GPIO 12
  58. #define N800_BLIZZARD_POWERDOWN_GPIO 15
  59. #define N800_MMC1_WP_GPIO 23
  60. #define N810_MMC2_VSD_GPIO 23
  61. #define N8X0_ONENAND_GPIO 26
  62. #define N810_BLIZZARD_RESET_GPIO 30
  63. #define N800_UNKNOWN_GPIO2 53 /* out */
  64. #define N8X0_TUSB_INT_GPIO 58
  65. #define N8X0_BT_WKUP_GPIO 61
  66. #define N8X0_STI_GPIO 62
  67. #define N8X0_CBUS_SEL_GPIO 64
  68. #define N8X0_CBUS_DAT_GPIO 65
  69. #define N8X0_CBUS_CLK_GPIO 66
  70. #define N8X0_WLAN_IRQ_GPIO 87
  71. #define N8X0_BT_RESET_GPIO 92
  72. #define N8X0_TEA5761_CS_GPIO 93
  73. #define N800_UNKNOWN_GPIO 94
  74. #define N810_TSC_RESET_GPIO 94
  75. #define N800_CAM_ACT_GPIO 95
  76. #define N810_GPS_WAKEUP_GPIO 95
  77. #define N8X0_MMC_CS_GPIO 96
  78. #define N8X0_WLAN_PWR_GPIO 97
  79. #define N8X0_BT_HOST_WKUP_GPIO 98
  80. #define N810_SPEAKER_AMP_GPIO 101
  81. #define N810_KB_LOCK_GPIO 102
  82. #define N800_TSC_TS_GPIO 103
  83. #define N810_TSC_TS_GPIO 106
  84. #define N8X0_HEADPHONE_GPIO 107
  85. #define N8X0_RETU_GPIO 108
  86. #define N800_TSC_KP_IRQ_GPIO 109
  87. #define N810_KEYBOARD_GPIO 109
  88. #define N800_BAT_COVER_GPIO 110
  89. #define N810_SLIDE_GPIO 110
  90. #define N8X0_TAHVO_GPIO 111
  91. #define N800_UNKNOWN_GPIO4 112 /* out */
  92. #define N810_SLEEPX_LED_GPIO 112
  93. #define N800_TSC_RESET_GPIO 118 /* ? */
  94. #define N810_AIC33_RESET_GPIO 118
  95. #define N800_TSC_UNKNOWN_GPIO 119 /* out */
  96. #define N8X0_TMP105_GPIO 125
  97. /* Config */
  98. #define BT_UART 0
  99. #define XLDR_LL_UART 1
  100. /* Addresses on the I2C bus 0 */
  101. #define N810_TLV320AIC33_ADDR 0x18 /* Audio CODEC */
  102. #define N8X0_TCM825x_ADDR 0x29 /* Camera */
  103. #define N810_LP5521_ADDR 0x32 /* LEDs */
  104. #define N810_TSL2563_ADDR 0x3d /* Light sensor */
  105. #define N810_LM8323_ADDR 0x45 /* Keyboard */
  106. /* Addresses on the I2C bus 1 */
  107. #define N8X0_TMP105_ADDR 0x48 /* Temperature sensor */
  108. #define N8X0_MENELAUS_ADDR 0x72 /* Power management */
  109. /* Chipselects on GPMC NOR interface */
  110. #define N8X0_ONENAND_CS 0
  111. #define N8X0_USB_ASYNC_CS 1
  112. #define N8X0_USB_SYNC_CS 4
  113. #define N8X0_BD_ADDR 0x00, 0x1a, 0x89, 0x9e, 0x3e, 0x81
  114. static void n800_mmc_cs_cb(void *opaque, int line, int level)
  115. {
  116. /* TODO: this seems to actually be connected to the menelaus, to
  117. * which also both MMC slots connect. */
  118. omap_mmc_enable((struct omap_mmc_s *) opaque, !level);
  119. printf("%s: MMC slot %i active\n", __FUNCTION__, level + 1);
  120. }
  121. static void n8x0_gpio_setup(struct n800_s *s)
  122. {
  123. qemu_irq *mmc_cs = qemu_allocate_irqs(n800_mmc_cs_cb, s->cpu->mmc, 1);
  124. omap2_gpio_out_set(s->cpu->gpif, N8X0_MMC_CS_GPIO, mmc_cs[0]);
  125. qemu_irq_lower(omap2_gpio_in_get(s->cpu->gpif, N800_BAT_COVER_GPIO)[0]);
  126. }
  127. #define MAEMO_CAL_HEADER(...) \
  128. 'C', 'o', 'n', 'F', 0x02, 0x00, 0x04, 0x00, \
  129. __VA_ARGS__, \
  130. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  131. static const uint8_t n8x0_cal_wlan_mac[] = {
  132. MAEMO_CAL_HEADER('w', 'l', 'a', 'n', '-', 'm', 'a', 'c')
  133. 0x1c, 0x00, 0x00, 0x00, 0x47, 0xd6, 0x69, 0xb3,
  134. 0x30, 0x08, 0xa0, 0x83, 0x00, 0x00, 0x00, 0x00,
  135. 0x00, 0x00, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x00,
  136. 0x89, 0x00, 0x00, 0x00, 0x9e, 0x00, 0x00, 0x00,
  137. 0x5d, 0x00, 0x00, 0x00, 0xc1, 0x00, 0x00, 0x00,
  138. };
  139. static const uint8_t n8x0_cal_bt_id[] = {
  140. MAEMO_CAL_HEADER('b', 't', '-', 'i', 'd', 0, 0, 0)
  141. 0x0a, 0x00, 0x00, 0x00, 0xa3, 0x4b, 0xf6, 0x96,
  142. 0xa8, 0xeb, 0xb2, 0x41, 0x00, 0x00, 0x00, 0x00,
  143. N8X0_BD_ADDR,
  144. };
  145. static void n8x0_nand_setup(struct n800_s *s)
  146. {
  147. char *otp_region;
  148. /* Either ec40xx or ec48xx are OK for the ID */
  149. omap_gpmc_attach(s->cpu->gpmc, N8X0_ONENAND_CS, 0, onenand_base_update,
  150. onenand_base_unmap,
  151. (s->nand = onenand_init(0xec4800, 1,
  152. omap2_gpio_in_get(s->cpu->gpif,
  153. N8X0_ONENAND_GPIO)[0])));
  154. otp_region = onenand_raw_otp(s->nand);
  155. memcpy(otp_region + 0x000, n8x0_cal_wlan_mac, sizeof(n8x0_cal_wlan_mac));
  156. memcpy(otp_region + 0x800, n8x0_cal_bt_id, sizeof(n8x0_cal_bt_id));
  157. /* XXX: in theory should also update the OOB for both pages */
  158. }
  159. static void n8x0_i2c_setup(struct n800_s *s)
  160. {
  161. qemu_irq tmp_irq = omap2_gpio_in_get(s->cpu->gpif, N8X0_TMP105_GPIO)[0];
  162. /* Attach the CPU on one end of our I2C bus. */
  163. s->i2c = omap_i2c_bus(s->cpu->i2c[0]);
  164. /* Attach a menelaus PM chip */
  165. i2c_set_slave_address(
  166. twl92230_init(s->i2c,
  167. s->cpu->irq[0][OMAP_INT_24XX_SYS_NIRQ]),
  168. N8X0_MENELAUS_ADDR);
  169. /* Attach a TMP105 PM chip (A0 wired to ground) */
  170. i2c_set_slave_address(tmp105_init(s->i2c, tmp_irq), N8X0_TMP105_ADDR);
  171. }
  172. /* Touchscreen and keypad controller */
  173. static struct mouse_transform_info_s n800_pointercal = {
  174. .x = 800,
  175. .y = 480,
  176. .a = { 14560, -68, -3455208, -39, -9621, 35152972, 65536 },
  177. };
  178. static struct mouse_transform_info_s n810_pointercal = {
  179. .x = 800,
  180. .y = 480,
  181. .a = { 15041, 148, -4731056, 171, -10238, 35933380, 65536 },
  182. };
  183. #define RETU_KEYCODE 61 /* F3 */
  184. static void n800_key_event(void *opaque, int keycode)
  185. {
  186. struct n800_s *s = (struct n800_s *) opaque;
  187. int code = s->keymap[keycode & 0x7f];
  188. if (code == -1) {
  189. if ((keycode & 0x7f) == RETU_KEYCODE)
  190. retu_key_event(s->retu, !(keycode & 0x80));
  191. return;
  192. }
  193. tsc210x_key_event(s->ts.chip, code, !(keycode & 0x80));
  194. }
  195. static const int n800_keys[16] = {
  196. -1,
  197. 72, /* Up */
  198. 63, /* Home (F5) */
  199. -1,
  200. 75, /* Left */
  201. 28, /* Enter */
  202. 77, /* Right */
  203. -1,
  204. 1, /* Cycle (ESC) */
  205. 80, /* Down */
  206. 62, /* Menu (F4) */
  207. -1,
  208. 66, /* Zoom- (F8) */
  209. 64, /* FullScreen (F6) */
  210. 65, /* Zoom+ (F7) */
  211. -1,
  212. };
  213. static void n800_tsc_kbd_setup(struct n800_s *s)
  214. {
  215. int i;
  216. /* XXX: are the three pins inverted inside the chip between the
  217. * tsc and the cpu (N4111)? */
  218. qemu_irq penirq = 0; /* NC */
  219. qemu_irq kbirq = omap2_gpio_in_get(s->cpu->gpif, N800_TSC_KP_IRQ_GPIO)[0];
  220. qemu_irq dav = omap2_gpio_in_get(s->cpu->gpif, N800_TSC_TS_GPIO)[0];
  221. s->ts.chip = tsc2301_init(penirq, kbirq, dav, 0);
  222. s->ts.opaque = s->ts.chip->opaque;
  223. s->ts.txrx = tsc210x_txrx;
  224. for (i = 0; i < 0x80; i ++)
  225. s->keymap[i] = -1;
  226. for (i = 0; i < 0x10; i ++)
  227. if (n800_keys[i] >= 0)
  228. s->keymap[n800_keys[i]] = i;
  229. qemu_add_kbd_event_handler(n800_key_event, s);
  230. tsc210x_set_transform(s->ts.chip, &n800_pointercal);
  231. }
  232. static void n810_tsc_setup(struct n800_s *s)
  233. {
  234. qemu_irq pintdav = omap2_gpio_in_get(s->cpu->gpif, N810_TSC_TS_GPIO)[0];
  235. s->ts.opaque = tsc2005_init(pintdav);
  236. s->ts.txrx = tsc2005_txrx;
  237. tsc2005_set_transform(s->ts.opaque, &n810_pointercal);
  238. }
  239. /* N810 Keyboard controller */
  240. static void n810_key_event(void *opaque, int keycode)
  241. {
  242. struct n800_s *s = (struct n800_s *) opaque;
  243. int code = s->keymap[keycode & 0x7f];
  244. if (code == -1) {
  245. if ((keycode & 0x7f) == RETU_KEYCODE)
  246. retu_key_event(s->retu, !(keycode & 0x80));
  247. return;
  248. }
  249. lm832x_key_event(s->kbd, code, !(keycode & 0x80));
  250. }
  251. #define M 0
  252. static int n810_keys[0x80] = {
  253. [0x01] = 16, /* Q */
  254. [0x02] = 37, /* K */
  255. [0x03] = 24, /* O */
  256. [0x04] = 25, /* P */
  257. [0x05] = 14, /* Backspace */
  258. [0x06] = 30, /* A */
  259. [0x07] = 31, /* S */
  260. [0x08] = 32, /* D */
  261. [0x09] = 33, /* F */
  262. [0x0a] = 34, /* G */
  263. [0x0b] = 35, /* H */
  264. [0x0c] = 36, /* J */
  265. [0x11] = 17, /* W */
  266. [0x12] = 62, /* Menu (F4) */
  267. [0x13] = 38, /* L */
  268. [0x14] = 40, /* ' (Apostrophe) */
  269. [0x16] = 44, /* Z */
  270. [0x17] = 45, /* X */
  271. [0x18] = 46, /* C */
  272. [0x19] = 47, /* V */
  273. [0x1a] = 48, /* B */
  274. [0x1b] = 49, /* N */
  275. [0x1c] = 42, /* Shift (Left shift) */
  276. [0x1f] = 65, /* Zoom+ (F7) */
  277. [0x21] = 18, /* E */
  278. [0x22] = 39, /* ; (Semicolon) */
  279. [0x23] = 12, /* - (Minus) */
  280. [0x24] = 13, /* = (Equal) */
  281. [0x2b] = 56, /* Fn (Left Alt) */
  282. [0x2c] = 50, /* M */
  283. [0x2f] = 66, /* Zoom- (F8) */
  284. [0x31] = 19, /* R */
  285. [0x32] = 29 | M, /* Right Ctrl */
  286. [0x34] = 57, /* Space */
  287. [0x35] = 51, /* , (Comma) */
  288. [0x37] = 72 | M, /* Up */
  289. [0x3c] = 82 | M, /* Compose (Insert) */
  290. [0x3f] = 64, /* FullScreen (F6) */
  291. [0x41] = 20, /* T */
  292. [0x44] = 52, /* . (Dot) */
  293. [0x46] = 77 | M, /* Right */
  294. [0x4f] = 63, /* Home (F5) */
  295. [0x51] = 21, /* Y */
  296. [0x53] = 80 | M, /* Down */
  297. [0x55] = 28, /* Enter */
  298. [0x5f] = 1, /* Cycle (ESC) */
  299. [0x61] = 22, /* U */
  300. [0x64] = 75 | M, /* Left */
  301. [0x71] = 23, /* I */
  302. #if 0
  303. [0x75] = 28 | M, /* KP Enter (KP Enter) */
  304. #else
  305. [0x75] = 15, /* KP Enter (Tab) */
  306. #endif
  307. };
  308. #undef M
  309. static void n810_kbd_setup(struct n800_s *s)
  310. {
  311. qemu_irq kbd_irq = omap2_gpio_in_get(s->cpu->gpif, N810_KEYBOARD_GPIO)[0];
  312. int i;
  313. for (i = 0; i < 0x80; i ++)
  314. s->keymap[i] = -1;
  315. for (i = 0; i < 0x80; i ++)
  316. if (n810_keys[i] > 0)
  317. s->keymap[n810_keys[i]] = i;
  318. qemu_add_kbd_event_handler(n810_key_event, s);
  319. /* Attach the LM8322 keyboard to the I2C bus,
  320. * should happen in n8x0_i2c_setup and s->kbd be initialised here. */
  321. s->kbd = lm8323_init(s->i2c, kbd_irq);
  322. i2c_set_slave_address(s->kbd, N810_LM8323_ADDR);
  323. }
  324. /* LCD MIPI DBI-C controller (URAL) */
  325. struct mipid_s {
  326. int resp[4];
  327. int param[4];
  328. int p;
  329. int pm;
  330. int cmd;
  331. int sleep;
  332. int booster;
  333. int te;
  334. int selfcheck;
  335. int partial;
  336. int normal;
  337. int vscr;
  338. int invert;
  339. int onoff;
  340. int gamma;
  341. uint32_t id;
  342. };
  343. static void mipid_reset(struct mipid_s *s)
  344. {
  345. if (!s->sleep)
  346. fprintf(stderr, "%s: Display off\n", __FUNCTION__);
  347. s->pm = 0;
  348. s->cmd = 0;
  349. s->sleep = 1;
  350. s->booster = 0;
  351. s->selfcheck =
  352. (1 << 7) | /* Register loading OK. */
  353. (1 << 5) | /* The chip is attached. */
  354. (1 << 4); /* Display glass still in one piece. */
  355. s->te = 0;
  356. s->partial = 0;
  357. s->normal = 1;
  358. s->vscr = 0;
  359. s->invert = 0;
  360. s->onoff = 1;
  361. s->gamma = 0;
  362. }
  363. static uint32_t mipid_txrx(void *opaque, uint32_t cmd, int len)
  364. {
  365. struct mipid_s *s = (struct mipid_s *) opaque;
  366. uint8_t ret;
  367. if (len > 9)
  368. cpu_abort(cpu_single_env, "%s: FIXME: bad SPI word width %i\n",
  369. __FUNCTION__, len);
  370. if (s->p >= ARRAY_SIZE(s->resp))
  371. ret = 0;
  372. else
  373. ret = s->resp[s->p ++];
  374. if (s->pm --> 0)
  375. s->param[s->pm] = cmd;
  376. else
  377. s->cmd = cmd;
  378. switch (s->cmd) {
  379. case 0x00: /* NOP */
  380. break;
  381. case 0x01: /* SWRESET */
  382. mipid_reset(s);
  383. break;
  384. case 0x02: /* BSTROFF */
  385. s->booster = 0;
  386. break;
  387. case 0x03: /* BSTRON */
  388. s->booster = 1;
  389. break;
  390. case 0x04: /* RDDID */
  391. s->p = 0;
  392. s->resp[0] = (s->id >> 16) & 0xff;
  393. s->resp[1] = (s->id >> 8) & 0xff;
  394. s->resp[2] = (s->id >> 0) & 0xff;
  395. break;
  396. case 0x06: /* RD_RED */
  397. case 0x07: /* RD_GREEN */
  398. /* XXX the bootloader sometimes issues RD_BLUE meaning RDDID so
  399. * for the bootloader one needs to change this. */
  400. case 0x08: /* RD_BLUE */
  401. s->p = 0;
  402. /* TODO: return first pixel components */
  403. s->resp[0] = 0x01;
  404. break;
  405. case 0x09: /* RDDST */
  406. s->p = 0;
  407. s->resp[0] = s->booster << 7;
  408. s->resp[1] = (5 << 4) | (s->partial << 2) |
  409. (s->sleep << 1) | s->normal;
  410. s->resp[2] = (s->vscr << 7) | (s->invert << 5) |
  411. (s->onoff << 2) | (s->te << 1) | (s->gamma >> 2);
  412. s->resp[3] = s->gamma << 6;
  413. break;
  414. case 0x0a: /* RDDPM */
  415. s->p = 0;
  416. s->resp[0] = (s->onoff << 2) | (s->normal << 3) | (s->sleep << 4) |
  417. (s->partial << 5) | (s->sleep << 6) | (s->booster << 7);
  418. break;
  419. case 0x0b: /* RDDMADCTR */
  420. s->p = 0;
  421. s->resp[0] = 0;
  422. break;
  423. case 0x0c: /* RDDCOLMOD */
  424. s->p = 0;
  425. s->resp[0] = 5; /* 65K colours */
  426. break;
  427. case 0x0d: /* RDDIM */
  428. s->p = 0;
  429. s->resp[0] = (s->invert << 5) | (s->vscr << 7) | s->gamma;
  430. break;
  431. case 0x0e: /* RDDSM */
  432. s->p = 0;
  433. s->resp[0] = s->te << 7;
  434. break;
  435. case 0x0f: /* RDDSDR */
  436. s->p = 0;
  437. s->resp[0] = s->selfcheck;
  438. break;
  439. case 0x10: /* SLPIN */
  440. s->sleep = 1;
  441. break;
  442. case 0x11: /* SLPOUT */
  443. s->sleep = 0;
  444. s->selfcheck ^= 1 << 6; /* POFF self-diagnosis Ok */
  445. break;
  446. case 0x12: /* PTLON */
  447. s->partial = 1;
  448. s->normal = 0;
  449. s->vscr = 0;
  450. break;
  451. case 0x13: /* NORON */
  452. s->partial = 0;
  453. s->normal = 1;
  454. s->vscr = 0;
  455. break;
  456. case 0x20: /* INVOFF */
  457. s->invert = 0;
  458. break;
  459. case 0x21: /* INVON */
  460. s->invert = 1;
  461. break;
  462. case 0x22: /* APOFF */
  463. case 0x23: /* APON */
  464. goto bad_cmd;
  465. case 0x25: /* WRCNTR */
  466. if (s->pm < 0)
  467. s->pm = 1;
  468. goto bad_cmd;
  469. case 0x26: /* GAMSET */
  470. if (!s->pm)
  471. s->gamma = ffs(s->param[0] & 0xf) - 1;
  472. else if (s->pm < 0)
  473. s->pm = 1;
  474. break;
  475. case 0x28: /* DISPOFF */
  476. s->onoff = 0;
  477. fprintf(stderr, "%s: Display off\n", __FUNCTION__);
  478. break;
  479. case 0x29: /* DISPON */
  480. s->onoff = 1;
  481. fprintf(stderr, "%s: Display on\n", __FUNCTION__);
  482. break;
  483. case 0x2a: /* CASET */
  484. case 0x2b: /* RASET */
  485. case 0x2c: /* RAMWR */
  486. case 0x2d: /* RGBSET */
  487. case 0x2e: /* RAMRD */
  488. case 0x30: /* PTLAR */
  489. case 0x33: /* SCRLAR */
  490. goto bad_cmd;
  491. case 0x34: /* TEOFF */
  492. s->te = 0;
  493. break;
  494. case 0x35: /* TEON */
  495. if (!s->pm)
  496. s->te = 1;
  497. else if (s->pm < 0)
  498. s->pm = 1;
  499. break;
  500. case 0x36: /* MADCTR */
  501. goto bad_cmd;
  502. case 0x37: /* VSCSAD */
  503. s->partial = 0;
  504. s->normal = 0;
  505. s->vscr = 1;
  506. break;
  507. case 0x38: /* IDMOFF */
  508. case 0x39: /* IDMON */
  509. case 0x3a: /* COLMOD */
  510. goto bad_cmd;
  511. case 0xb0: /* CLKINT / DISCTL */
  512. case 0xb1: /* CLKEXT */
  513. if (s->pm < 0)
  514. s->pm = 2;
  515. break;
  516. case 0xb4: /* FRMSEL */
  517. break;
  518. case 0xb5: /* FRM8SEL */
  519. case 0xb6: /* TMPRNG / INIESC */
  520. case 0xb7: /* TMPHIS / NOP2 */
  521. case 0xb8: /* TMPREAD / MADCTL */
  522. case 0xba: /* DISTCTR */
  523. case 0xbb: /* EPVOL */
  524. goto bad_cmd;
  525. case 0xbd: /* Unknown */
  526. s->p = 0;
  527. s->resp[0] = 0;
  528. s->resp[1] = 1;
  529. break;
  530. case 0xc2: /* IFMOD */
  531. if (s->pm < 0)
  532. s->pm = 2;
  533. break;
  534. case 0xc6: /* PWRCTL */
  535. case 0xc7: /* PPWRCTL */
  536. case 0xd0: /* EPWROUT */
  537. case 0xd1: /* EPWRIN */
  538. case 0xd4: /* RDEV */
  539. case 0xd5: /* RDRR */
  540. goto bad_cmd;
  541. case 0xda: /* RDID1 */
  542. s->p = 0;
  543. s->resp[0] = (s->id >> 16) & 0xff;
  544. break;
  545. case 0xdb: /* RDID2 */
  546. s->p = 0;
  547. s->resp[0] = (s->id >> 8) & 0xff;
  548. break;
  549. case 0xdc: /* RDID3 */
  550. s->p = 0;
  551. s->resp[0] = (s->id >> 0) & 0xff;
  552. break;
  553. default:
  554. bad_cmd:
  555. fprintf(stderr, "%s: unknown command %02x\n", __FUNCTION__, s->cmd);
  556. break;
  557. }
  558. return ret;
  559. }
  560. static void *mipid_init(void)
  561. {
  562. struct mipid_s *s = (struct mipid_s *) qemu_mallocz(sizeof(*s));
  563. s->id = 0x838f03;
  564. mipid_reset(s);
  565. return s;
  566. }
  567. static void n8x0_spi_setup(struct n800_s *s)
  568. {
  569. void *tsc = s->ts.opaque;
  570. void *mipid = mipid_init();
  571. omap_mcspi_attach(s->cpu->mcspi[0], s->ts.txrx, tsc, 0);
  572. omap_mcspi_attach(s->cpu->mcspi[0], mipid_txrx, mipid, 1);
  573. }
  574. /* This task is normally performed by the bootloader. If we're loading
  575. * a kernel directly, we need to enable the Blizzard ourselves. */
  576. static void n800_dss_init(struct rfbi_chip_s *chip)
  577. {
  578. uint8_t *fb_blank;
  579. chip->write(chip->opaque, 0, 0x2a); /* LCD Width register */
  580. chip->write(chip->opaque, 1, 0x64);
  581. chip->write(chip->opaque, 0, 0x2c); /* LCD HNDP register */
  582. chip->write(chip->opaque, 1, 0x1e);
  583. chip->write(chip->opaque, 0, 0x2e); /* LCD Height 0 register */
  584. chip->write(chip->opaque, 1, 0xe0);
  585. chip->write(chip->opaque, 0, 0x30); /* LCD Height 1 register */
  586. chip->write(chip->opaque, 1, 0x01);
  587. chip->write(chip->opaque, 0, 0x32); /* LCD VNDP register */
  588. chip->write(chip->opaque, 1, 0x06);
  589. chip->write(chip->opaque, 0, 0x68); /* Display Mode register */
  590. chip->write(chip->opaque, 1, 1); /* Enable bit */
  591. chip->write(chip->opaque, 0, 0x6c);
  592. chip->write(chip->opaque, 1, 0x00); /* Input X Start Position */
  593. chip->write(chip->opaque, 1, 0x00); /* Input X Start Position */
  594. chip->write(chip->opaque, 1, 0x00); /* Input Y Start Position */
  595. chip->write(chip->opaque, 1, 0x00); /* Input Y Start Position */
  596. chip->write(chip->opaque, 1, 0x1f); /* Input X End Position */
  597. chip->write(chip->opaque, 1, 0x03); /* Input X End Position */
  598. chip->write(chip->opaque, 1, 0xdf); /* Input Y End Position */
  599. chip->write(chip->opaque, 1, 0x01); /* Input Y End Position */
  600. chip->write(chip->opaque, 1, 0x00); /* Output X Start Position */
  601. chip->write(chip->opaque, 1, 0x00); /* Output X Start Position */
  602. chip->write(chip->opaque, 1, 0x00); /* Output Y Start Position */
  603. chip->write(chip->opaque, 1, 0x00); /* Output Y Start Position */
  604. chip->write(chip->opaque, 1, 0x1f); /* Output X End Position */
  605. chip->write(chip->opaque, 1, 0x03); /* Output X End Position */
  606. chip->write(chip->opaque, 1, 0xdf); /* Output Y End Position */
  607. chip->write(chip->opaque, 1, 0x01); /* Output Y End Position */
  608. chip->write(chip->opaque, 1, 0x01); /* Input Data Format */
  609. chip->write(chip->opaque, 1, 0x01); /* Data Source Select */
  610. fb_blank = memset(qemu_malloc(800 * 480 * 2), 0xff, 800 * 480 * 2);
  611. /* Display Memory Data Port */
  612. chip->block(chip->opaque, 1, fb_blank, 800 * 480 * 2, 800);
  613. free(fb_blank);
  614. }
  615. static void n8x0_dss_setup(struct n800_s *s)
  616. {
  617. s->blizzard.opaque = s1d13745_init(0);
  618. s->blizzard.block = s1d13745_write_block;
  619. s->blizzard.write = s1d13745_write;
  620. s->blizzard.read = s1d13745_read;
  621. omap_rfbi_attach(s->cpu->dss, 0, &s->blizzard);
  622. }
  623. static void n8x0_cbus_setup(struct n800_s *s)
  624. {
  625. qemu_irq dat_out = omap2_gpio_in_get(s->cpu->gpif, N8X0_CBUS_DAT_GPIO)[0];
  626. qemu_irq retu_irq = omap2_gpio_in_get(s->cpu->gpif, N8X0_RETU_GPIO)[0];
  627. qemu_irq tahvo_irq = omap2_gpio_in_get(s->cpu->gpif, N8X0_TAHVO_GPIO)[0];
  628. struct cbus_s *cbus = cbus_init(dat_out);
  629. omap2_gpio_out_set(s->cpu->gpif, N8X0_CBUS_CLK_GPIO, cbus->clk);
  630. omap2_gpio_out_set(s->cpu->gpif, N8X0_CBUS_DAT_GPIO, cbus->dat);
  631. omap2_gpio_out_set(s->cpu->gpif, N8X0_CBUS_SEL_GPIO, cbus->sel);
  632. cbus_attach(cbus, s->retu = retu_init(retu_irq, 1));
  633. cbus_attach(cbus, s->tahvo = tahvo_init(tahvo_irq, 1));
  634. }
  635. static void n8x0_uart_setup(struct n800_s *s)
  636. {
  637. CharDriverState *radio = uart_hci_init(
  638. omap2_gpio_in_get(s->cpu->gpif,
  639. N8X0_BT_HOST_WKUP_GPIO)[0]);
  640. omap2_gpio_out_set(s->cpu->gpif, N8X0_BT_RESET_GPIO,
  641. csrhci_pins_get(radio)[csrhci_pin_reset]);
  642. omap2_gpio_out_set(s->cpu->gpif, N8X0_BT_WKUP_GPIO,
  643. csrhci_pins_get(radio)[csrhci_pin_wakeup]);
  644. omap_uart_attach(s->cpu->uart[BT_UART], radio);
  645. }
  646. static void n8x0_usb_power_cb(void *opaque, int line, int level)
  647. {
  648. struct n800_s *s = opaque;
  649. tusb6010_power(s->usb, level);
  650. }
  651. static void n8x0_usb_setup(struct n800_s *s)
  652. {
  653. qemu_irq tusb_irq = omap2_gpio_in_get(s->cpu->gpif, N8X0_TUSB_INT_GPIO)[0];
  654. qemu_irq tusb_pwr = qemu_allocate_irqs(n8x0_usb_power_cb, s, 1)[0];
  655. struct tusb_s *tusb = tusb6010_init(tusb_irq);
  656. /* Using the NOR interface */
  657. omap_gpmc_attach(s->cpu->gpmc, N8X0_USB_ASYNC_CS,
  658. tusb6010_async_io(tusb), 0, 0, tusb);
  659. omap_gpmc_attach(s->cpu->gpmc, N8X0_USB_SYNC_CS,
  660. tusb6010_sync_io(tusb), 0, 0, tusb);
  661. s->usb = tusb;
  662. omap2_gpio_out_set(s->cpu->gpif, N8X0_TUSB_ENABLE_GPIO, tusb_pwr);
  663. }
  664. /* Setup done before the main bootloader starts by some early setup code
  665. * - used when we want to run the main bootloader in emulation. This
  666. * isn't documented. */
  667. static uint32_t n800_pinout[104] = {
  668. 0x080f00d8, 0x00d40808, 0x03080808, 0x080800d0,
  669. 0x00dc0808, 0x0b0f0f00, 0x080800b4, 0x00c00808,
  670. 0x08080808, 0x180800c4, 0x00b80000, 0x08080808,
  671. 0x080800bc, 0x00cc0808, 0x08081818, 0x18180128,
  672. 0x01241800, 0x18181818, 0x000000f0, 0x01300000,
  673. 0x00001b0b, 0x1b0f0138, 0x00e0181b, 0x1b031b0b,
  674. 0x180f0078, 0x00740018, 0x0f0f0f1a, 0x00000080,
  675. 0x007c0000, 0x00000000, 0x00000088, 0x00840000,
  676. 0x00000000, 0x00000094, 0x00980300, 0x0f180003,
  677. 0x0000008c, 0x00900f0f, 0x0f0f1b00, 0x0f00009c,
  678. 0x01140000, 0x1b1b0f18, 0x0818013c, 0x01400008,
  679. 0x00001818, 0x000b0110, 0x010c1800, 0x0b030b0f,
  680. 0x181800f4, 0x00f81818, 0x00000018, 0x000000fc,
  681. 0x00401808, 0x00000000, 0x0f1b0030, 0x003c0008,
  682. 0x00000000, 0x00000038, 0x00340000, 0x00000000,
  683. 0x1a080070, 0x00641a1a, 0x08080808, 0x08080060,
  684. 0x005c0808, 0x08080808, 0x08080058, 0x00540808,
  685. 0x08080808, 0x0808006c, 0x00680808, 0x08080808,
  686. 0x000000a8, 0x00b00000, 0x08080808, 0x000000a0,
  687. 0x00a40000, 0x00000000, 0x08ff0050, 0x004c0808,
  688. 0xffffffff, 0xffff0048, 0x0044ffff, 0xffffffff,
  689. 0x000000ac, 0x01040800, 0x08080b0f, 0x18180100,
  690. 0x01081818, 0x0b0b1808, 0x1a0300e4, 0x012c0b1a,
  691. 0x02020018, 0x0b000134, 0x011c0800, 0x0b1b1b00,
  692. 0x0f0000c8, 0x00ec181b, 0x000f0f02, 0x00180118,
  693. 0x01200000, 0x0f0b1b1b, 0x0f0200e8, 0x0000020b,
  694. };
  695. static void n800_setup_nolo_tags(void *sram_base)
  696. {
  697. int i;
  698. uint32_t *p = sram_base + 0x8000;
  699. uint32_t *v = sram_base + 0xa000;
  700. memset(p, 0, 0x3000);
  701. strcpy((void *) (p + 0), "QEMU N800");
  702. strcpy((void *) (p + 8), "F5");
  703. stl_raw(p + 10, 0x04f70000);
  704. strcpy((void *) (p + 9), "RX-34");
  705. /* RAM size in MB? */
  706. stl_raw(p + 12, 0x80);
  707. /* Pointer to the list of tags */
  708. stl_raw(p + 13, OMAP2_SRAM_BASE + 0x9000);
  709. /* The NOLO tags start here */
  710. p = sram_base + 0x9000;
  711. #define ADD_TAG(tag, len) \
  712. stw_raw((uint16_t *) p + 0, tag); \
  713. stw_raw((uint16_t *) p + 1, len); p ++; \
  714. stl_raw(p ++, OMAP2_SRAM_BASE | (((void *) v - sram_base) & 0xffff));
  715. /* OMAP STI console? Pin out settings? */
  716. ADD_TAG(0x6e01, 414);
  717. for (i = 0; i < ARRAY_SIZE(n800_pinout); i ++)
  718. stl_raw(v ++, n800_pinout[i]);
  719. /* Kernel memsize? */
  720. ADD_TAG(0x6e05, 1);
  721. stl_raw(v ++, 2);
  722. /* NOLO serial console */
  723. ADD_TAG(0x6e02, 4);
  724. stl_raw(v ++, XLDR_LL_UART); /* UART number (1 - 3) */
  725. #if 0
  726. /* CBUS settings (Retu/AVilma) */
  727. ADD_TAG(0x6e03, 6);
  728. stw_raw((uint16_t *) v + 0, 65); /* CBUS GPIO0 */
  729. stw_raw((uint16_t *) v + 1, 66); /* CBUS GPIO1 */
  730. stw_raw((uint16_t *) v + 2, 64); /* CBUS GPIO2 */
  731. v += 2;
  732. #endif
  733. /* Nokia ASIC BB5 (Retu/Tahvo) */
  734. ADD_TAG(0x6e0a, 4);
  735. stw_raw((uint16_t *) v + 0, 111); /* "Retu" interrupt GPIO */
  736. stw_raw((uint16_t *) v + 1, 108); /* "Tahvo" interrupt GPIO */
  737. v ++;
  738. /* LCD console? */
  739. ADD_TAG(0x6e04, 4);
  740. stw_raw((uint16_t *) v + 0, 30); /* ??? */
  741. stw_raw((uint16_t *) v + 1, 24); /* ??? */
  742. v ++;
  743. #if 0
  744. /* LCD settings */
  745. ADD_TAG(0x6e06, 2);
  746. stw_raw((uint16_t *) (v ++), 15); /* ??? */
  747. #endif
  748. /* I^2C (Menelaus) */
  749. ADD_TAG(0x6e07, 4);
  750. stl_raw(v ++, 0x00720000); /* ??? */
  751. /* Unknown */
  752. ADD_TAG(0x6e0b, 6);
  753. stw_raw((uint16_t *) v + 0, 94); /* ??? */
  754. stw_raw((uint16_t *) v + 1, 23); /* ??? */
  755. stw_raw((uint16_t *) v + 2, 0); /* ??? */
  756. v += 2;
  757. /* OMAP gpio switch info */
  758. ADD_TAG(0x6e0c, 80);
  759. strcpy((void *) v, "bat_cover"); v += 3;
  760. stw_raw((uint16_t *) v + 0, 110); /* GPIO num ??? */
  761. stw_raw((uint16_t *) v + 1, 1); /* GPIO num ??? */
  762. v += 2;
  763. strcpy((void *) v, "cam_act"); v += 3;
  764. stw_raw((uint16_t *) v + 0, 95); /* GPIO num ??? */
  765. stw_raw((uint16_t *) v + 1, 32); /* GPIO num ??? */
  766. v += 2;
  767. strcpy((void *) v, "cam_turn"); v += 3;
  768. stw_raw((uint16_t *) v + 0, 12); /* GPIO num ??? */
  769. stw_raw((uint16_t *) v + 1, 33); /* GPIO num ??? */
  770. v += 2;
  771. strcpy((void *) v, "headphone"); v += 3;
  772. stw_raw((uint16_t *) v + 0, 107); /* GPIO num ??? */
  773. stw_raw((uint16_t *) v + 1, 17); /* GPIO num ??? */
  774. v += 2;
  775. /* Bluetooth */
  776. ADD_TAG(0x6e0e, 12);
  777. stl_raw(v ++, 0x5c623d01); /* ??? */
  778. stl_raw(v ++, 0x00000201); /* ??? */
  779. stl_raw(v ++, 0x00000000); /* ??? */
  780. /* CX3110x WLAN settings */
  781. ADD_TAG(0x6e0f, 8);
  782. stl_raw(v ++, 0x00610025); /* ??? */
  783. stl_raw(v ++, 0xffff0057); /* ??? */
  784. /* MMC host settings */
  785. ADD_TAG(0x6e10, 12);
  786. stl_raw(v ++, 0xffff000f); /* ??? */
  787. stl_raw(v ++, 0xffffffff); /* ??? */
  788. stl_raw(v ++, 0x00000060); /* ??? */
  789. /* OneNAND chip select */
  790. ADD_TAG(0x6e11, 10);
  791. stl_raw(v ++, 0x00000401); /* ??? */
  792. stl_raw(v ++, 0x0002003a); /* ??? */
  793. stl_raw(v ++, 0x00000002); /* ??? */
  794. /* TEA5761 sensor settings */
  795. ADD_TAG(0x6e12, 2);
  796. stl_raw(v ++, 93); /* GPIO num ??? */
  797. #if 0
  798. /* Unknown tag */
  799. ADD_TAG(6e09, 0);
  800. /* Kernel UART / console */
  801. ADD_TAG(6e12, 0);
  802. #endif
  803. /* End of the list */
  804. stl_raw(p ++, 0x00000000);
  805. stl_raw(p ++, 0x00000000);
  806. }
  807. /* This task is normally performed by the bootloader. If we're loading
  808. * a kernel directly, we need to set up GPMC mappings ourselves. */
  809. static void n800_gpmc_init(struct n800_s *s)
  810. {
  811. uint32_t config7 =
  812. (0xf << 8) | /* MASKADDRESS */
  813. (1 << 6) | /* CSVALID */
  814. (4 << 0); /* BASEADDRESS */
  815. cpu_physical_memory_write(0x6800a078, /* GPMC_CONFIG7_0 */
  816. (void *) &config7, sizeof(config7));
  817. }
  818. /* Setup sequence done by the bootloader */
  819. static void n8x0_boot_init(void *opaque)
  820. {
  821. struct n800_s *s = (struct n800_s *) opaque;
  822. uint32_t buf;
  823. /* PRCM setup */
  824. #define omap_writel(addr, val) \
  825. buf = (val); \
  826. cpu_physical_memory_write(addr, (void *) &buf, sizeof(buf))
  827. omap_writel(0x48008060, 0x41); /* PRCM_CLKSRC_CTRL */
  828. omap_writel(0x48008070, 1); /* PRCM_CLKOUT_CTRL */
  829. omap_writel(0x48008078, 0); /* PRCM_CLKEMUL_CTRL */
  830. omap_writel(0x48008090, 0); /* PRCM_VOLTSETUP */
  831. omap_writel(0x48008094, 0); /* PRCM_CLKSSETUP */
  832. omap_writel(0x48008098, 0); /* PRCM_POLCTRL */
  833. omap_writel(0x48008140, 2); /* CM_CLKSEL_MPU */
  834. omap_writel(0x48008148, 0); /* CM_CLKSTCTRL_MPU */
  835. omap_writel(0x48008158, 1); /* RM_RSTST_MPU */
  836. omap_writel(0x480081c8, 0x15); /* PM_WKDEP_MPU */
  837. omap_writel(0x480081d4, 0x1d4); /* PM_EVGENCTRL_MPU */
  838. omap_writel(0x480081d8, 0); /* PM_EVEGENONTIM_MPU */
  839. omap_writel(0x480081dc, 0); /* PM_EVEGENOFFTIM_MPU */
  840. omap_writel(0x480081e0, 0xc); /* PM_PWSTCTRL_MPU */
  841. omap_writel(0x48008200, 0x047e7ff7); /* CM_FCLKEN1_CORE */
  842. omap_writel(0x48008204, 0x00000004); /* CM_FCLKEN2_CORE */
  843. omap_writel(0x48008210, 0x047e7ff1); /* CM_ICLKEN1_CORE */
  844. omap_writel(0x48008214, 0x00000004); /* CM_ICLKEN2_CORE */
  845. omap_writel(0x4800821c, 0x00000000); /* CM_ICLKEN4_CORE */
  846. omap_writel(0x48008230, 0); /* CM_AUTOIDLE1_CORE */
  847. omap_writel(0x48008234, 0); /* CM_AUTOIDLE2_CORE */
  848. omap_writel(0x48008238, 7); /* CM_AUTOIDLE3_CORE */
  849. omap_writel(0x4800823c, 0); /* CM_AUTOIDLE4_CORE */
  850. omap_writel(0x48008240, 0x04360626); /* CM_CLKSEL1_CORE */
  851. omap_writel(0x48008244, 0x00000014); /* CM_CLKSEL2_CORE */
  852. omap_writel(0x48008248, 0); /* CM_CLKSTCTRL_CORE */
  853. omap_writel(0x48008300, 0x00000000); /* CM_FCLKEN_GFX */
  854. omap_writel(0x48008310, 0x00000000); /* CM_ICLKEN_GFX */
  855. omap_writel(0x48008340, 0x00000001); /* CM_CLKSEL_GFX */
  856. omap_writel(0x48008400, 0x00000004); /* CM_FCLKEN_WKUP */
  857. omap_writel(0x48008410, 0x00000004); /* CM_ICLKEN_WKUP */
  858. omap_writel(0x48008440, 0x00000000); /* CM_CLKSEL_WKUP */
  859. omap_writel(0x48008500, 0x000000cf); /* CM_CLKEN_PLL */
  860. omap_writel(0x48008530, 0x0000000c); /* CM_AUTOIDLE_PLL */
  861. omap_writel(0x48008540, /* CM_CLKSEL1_PLL */
  862. (0x78 << 12) | (6 << 8));
  863. omap_writel(0x48008544, 2); /* CM_CLKSEL2_PLL */
  864. /* GPMC setup */
  865. n800_gpmc_init(s);
  866. /* Video setup */
  867. n800_dss_init(&s->blizzard);
  868. /* CPU setup */
  869. s->cpu->env->regs[15] = s->cpu->env->boot_info->loader_start;
  870. s->cpu->env->GE = 0x5;
  871. /* If the machine has a slided keyboard, open it */
  872. if (s->kbd)
  873. qemu_irq_raise(omap2_gpio_in_get(s->cpu->gpif, N810_SLIDE_GPIO)[0]);
  874. }
  875. #define OMAP_TAG_NOKIA_BT 0x4e01
  876. #define OMAP_TAG_WLAN_CX3110X 0x4e02
  877. #define OMAP_TAG_CBUS 0x4e03
  878. #define OMAP_TAG_EM_ASIC_BB5 0x4e04
  879. static struct omap_gpiosw_info_s {
  880. const char *name;
  881. int line;
  882. int type;
  883. } n800_gpiosw_info[] = {
  884. {
  885. "bat_cover", N800_BAT_COVER_GPIO,
  886. OMAP_GPIOSW_TYPE_COVER | OMAP_GPIOSW_INVERTED,
  887. }, {
  888. "cam_act", N800_CAM_ACT_GPIO,
  889. OMAP_GPIOSW_TYPE_ACTIVITY,
  890. }, {
  891. "cam_turn", N800_CAM_TURN_GPIO,
  892. OMAP_GPIOSW_TYPE_ACTIVITY | OMAP_GPIOSW_INVERTED,
  893. }, {
  894. "headphone", N8X0_HEADPHONE_GPIO,
  895. OMAP_GPIOSW_TYPE_CONNECTION | OMAP_GPIOSW_INVERTED,
  896. },
  897. { 0 }
  898. }, n810_gpiosw_info[] = {
  899. {
  900. "gps_reset", N810_GPS_RESET_GPIO,
  901. OMAP_GPIOSW_TYPE_ACTIVITY | OMAP_GPIOSW_OUTPUT,
  902. }, {
  903. "gps_wakeup", N810_GPS_WAKEUP_GPIO,
  904. OMAP_GPIOSW_TYPE_ACTIVITY | OMAP_GPIOSW_OUTPUT,
  905. }, {
  906. "headphone", N8X0_HEADPHONE_GPIO,
  907. OMAP_GPIOSW_TYPE_CONNECTION | OMAP_GPIOSW_INVERTED,
  908. }, {
  909. "kb_lock", N810_KB_LOCK_GPIO,
  910. OMAP_GPIOSW_TYPE_COVER | OMAP_GPIOSW_INVERTED,
  911. }, {
  912. "sleepx_led", N810_SLEEPX_LED_GPIO,
  913. OMAP_GPIOSW_TYPE_ACTIVITY | OMAP_GPIOSW_INVERTED | OMAP_GPIOSW_OUTPUT,
  914. }, {
  915. "slide", N810_SLIDE_GPIO,
  916. OMAP_GPIOSW_TYPE_COVER | OMAP_GPIOSW_INVERTED,
  917. },
  918. { 0 }
  919. };
  920. static struct omap_partition_info_s {
  921. uint32_t offset;
  922. uint32_t size;
  923. int mask;
  924. const char *name;
  925. } n800_part_info[] = {
  926. { 0x00000000, 0x00020000, 0x3, "bootloader" },
  927. { 0x00020000, 0x00060000, 0x0, "config" },
  928. { 0x00080000, 0x00200000, 0x0, "kernel" },
  929. { 0x00280000, 0x00200000, 0x3, "initfs" },
  930. { 0x00480000, 0x0fb80000, 0x3, "rootfs" },
  931. { 0, 0, 0, 0 }
  932. }, n810_part_info[] = {
  933. { 0x00000000, 0x00020000, 0x3, "bootloader" },
  934. { 0x00020000, 0x00060000, 0x0, "config" },
  935. { 0x00080000, 0x00220000, 0x0, "kernel" },
  936. { 0x002a0000, 0x00400000, 0x0, "initfs" },
  937. { 0x006a0000, 0x0f960000, 0x0, "rootfs" },
  938. { 0, 0, 0, 0 }
  939. };
  940. static bdaddr_t n8x0_bd_addr = {{ N8X0_BD_ADDR }};
  941. static int n8x0_atag_setup(void *p, int model)
  942. {
  943. uint8_t *b;
  944. uint16_t *w;
  945. uint32_t *l;
  946. struct omap_gpiosw_info_s *gpiosw;
  947. struct omap_partition_info_s *partition;
  948. const char *tag;
  949. w = p;
  950. stw_raw(w ++, OMAP_TAG_UART); /* u16 tag */
  951. stw_raw(w ++, 4); /* u16 len */
  952. stw_raw(w ++, (1 << 2) | (1 << 1) | (1 << 0)); /* uint enabled_uarts */
  953. w ++;
  954. #if 0
  955. stw_raw(w ++, OMAP_TAG_SERIAL_CONSOLE); /* u16 tag */
  956. stw_raw(w ++, 4); /* u16 len */
  957. stw_raw(w ++, XLDR_LL_UART + 1); /* u8 console_uart */
  958. stw_raw(w ++, 115200); /* u32 console_speed */
  959. #endif
  960. stw_raw(w ++, OMAP_TAG_LCD); /* u16 tag */
  961. stw_raw(w ++, 36); /* u16 len */
  962. strcpy((void *) w, "QEMU LCD panel"); /* char panel_name[16] */
  963. w += 8;
  964. strcpy((void *) w, "blizzard"); /* char ctrl_name[16] */
  965. w += 8;
  966. stw_raw(w ++, N810_BLIZZARD_RESET_GPIO); /* TODO: n800 s16 nreset_gpio */
  967. stw_raw(w ++, 24); /* u8 data_lines */
  968. stw_raw(w ++, OMAP_TAG_CBUS); /* u16 tag */
  969. stw_raw(w ++, 8); /* u16 len */
  970. stw_raw(w ++, N8X0_CBUS_CLK_GPIO); /* s16 clk_gpio */
  971. stw_raw(w ++, N8X0_CBUS_DAT_GPIO); /* s16 dat_gpio */
  972. stw_raw(w ++, N8X0_CBUS_SEL_GPIO); /* s16 sel_gpio */
  973. w ++;
  974. stw_raw(w ++, OMAP_TAG_EM_ASIC_BB5); /* u16 tag */
  975. stw_raw(w ++, 4); /* u16 len */
  976. stw_raw(w ++, N8X0_RETU_GPIO); /* s16 retu_irq_gpio */
  977. stw_raw(w ++, N8X0_TAHVO_GPIO); /* s16 tahvo_irq_gpio */
  978. gpiosw = (model == 810) ? n810_gpiosw_info : n800_gpiosw_info;
  979. for (; gpiosw->name; gpiosw ++) {
  980. stw_raw(w ++, OMAP_TAG_GPIO_SWITCH); /* u16 tag */
  981. stw_raw(w ++, 20); /* u16 len */
  982. strcpy((void *) w, gpiosw->name); /* char name[12] */
  983. w += 6;
  984. stw_raw(w ++, gpiosw->line); /* u16 gpio */
  985. stw_raw(w ++, gpiosw->type);
  986. stw_raw(w ++, 0);
  987. stw_raw(w ++, 0);
  988. }
  989. stw_raw(w ++, OMAP_TAG_NOKIA_BT); /* u16 tag */
  990. stw_raw(w ++, 12); /* u16 len */
  991. b = (void *) w;
  992. stb_raw(b ++, 0x01); /* u8 chip_type (CSR) */
  993. stb_raw(b ++, N8X0_BT_WKUP_GPIO); /* u8 bt_wakeup_gpio */
  994. stb_raw(b ++, N8X0_BT_HOST_WKUP_GPIO); /* u8 host_wakeup_gpio */
  995. stb_raw(b ++, N8X0_BT_RESET_GPIO); /* u8 reset_gpio */
  996. stb_raw(b ++, BT_UART + 1); /* u8 bt_uart */
  997. memcpy(b, &n8x0_bd_addr, 6); /* u8 bd_addr[6] */
  998. b += 6;
  999. stb_raw(b ++, 0x02); /* u8 bt_sysclk (38.4) */
  1000. w = (void *) b;
  1001. stw_raw(w ++, OMAP_TAG_WLAN_CX3110X); /* u16 tag */
  1002. stw_raw(w ++, 8); /* u16 len */
  1003. stw_raw(w ++, 0x25); /* u8 chip_type */
  1004. stw_raw(w ++, N8X0_WLAN_PWR_GPIO); /* s16 power_gpio */
  1005. stw_raw(w ++, N8X0_WLAN_IRQ_GPIO); /* s16 irq_gpio */
  1006. stw_raw(w ++, -1); /* s16 spi_cs_gpio */
  1007. stw_raw(w ++, OMAP_TAG_MMC); /* u16 tag */
  1008. stw_raw(w ++, 16); /* u16 len */
  1009. if (model == 810) {
  1010. stw_raw(w ++, 0x23f); /* unsigned flags */
  1011. stw_raw(w ++, -1); /* s16 power_pin */
  1012. stw_raw(w ++, -1); /* s16 switch_pin */
  1013. stw_raw(w ++, -1); /* s16 wp_pin */
  1014. stw_raw(w ++, 0x240); /* unsigned flags */
  1015. stw_raw(w ++, 0xc000); /* s16 power_pin */
  1016. stw_raw(w ++, 0x0248); /* s16 switch_pin */
  1017. stw_raw(w ++, 0xc000); /* s16 wp_pin */
  1018. } else {
  1019. stw_raw(w ++, 0xf); /* unsigned flags */
  1020. stw_raw(w ++, -1); /* s16 power_pin */
  1021. stw_raw(w ++, -1); /* s16 switch_pin */
  1022. stw_raw(w ++, -1); /* s16 wp_pin */
  1023. stw_raw(w ++, 0); /* unsigned flags */
  1024. stw_raw(w ++, 0); /* s16 power_pin */
  1025. stw_raw(w ++, 0); /* s16 switch_pin */
  1026. stw_raw(w ++, 0); /* s16 wp_pin */
  1027. }
  1028. stw_raw(w ++, OMAP_TAG_TEA5761); /* u16 tag */
  1029. stw_raw(w ++, 4); /* u16 len */
  1030. stw_raw(w ++, N8X0_TEA5761_CS_GPIO); /* u16 enable_gpio */
  1031. w ++;
  1032. partition = (model == 810) ? n810_part_info : n800_part_info;
  1033. for (; partition->name; partition ++) {
  1034. stw_raw(w ++, OMAP_TAG_PARTITION); /* u16 tag */
  1035. stw_raw(w ++, 28); /* u16 len */
  1036. strcpy((void *) w, partition->name); /* char name[16] */
  1037. l = (void *) (w + 8);
  1038. stl_raw(l ++, partition->size); /* unsigned int size */
  1039. stl_raw(l ++, partition->offset); /* unsigned int offset */
  1040. stl_raw(l ++, partition->mask); /* unsigned int mask_flags */
  1041. w = (void *) l;
  1042. }
  1043. stw_raw(w ++, OMAP_TAG_BOOT_REASON); /* u16 tag */
  1044. stw_raw(w ++, 12); /* u16 len */
  1045. #if 0
  1046. strcpy((void *) w, "por"); /* char reason_str[12] */
  1047. strcpy((void *) w, "charger"); /* char reason_str[12] */
  1048. strcpy((void *) w, "32wd_to"); /* char reason_str[12] */
  1049. strcpy((void *) w, "sw_rst"); /* char reason_str[12] */
  1050. strcpy((void *) w, "mbus"); /* char reason_str[12] */
  1051. strcpy((void *) w, "unknown"); /* char reason_str[12] */
  1052. strcpy((void *) w, "swdg_to"); /* char reason_str[12] */
  1053. strcpy((void *) w, "sec_vio"); /* char reason_str[12] */
  1054. strcpy((void *) w, "pwr_key"); /* char reason_str[12] */
  1055. strcpy((void *) w, "rtc_alarm"); /* char reason_str[12] */
  1056. #else
  1057. strcpy((void *) w, "pwr_key"); /* char reason_str[12] */
  1058. #endif
  1059. w += 6;
  1060. tag = (model == 810) ? "RX-44" : "RX-34";
  1061. stw_raw(w ++, OMAP_TAG_VERSION_STR); /* u16 tag */
  1062. stw_raw(w ++, 24); /* u16 len */
  1063. strcpy((void *) w, "product"); /* char component[12] */
  1064. w += 6;
  1065. strcpy((void *) w, tag); /* char version[12] */
  1066. w += 6;
  1067. stw_raw(w ++, OMAP_TAG_VERSION_STR); /* u16 tag */
  1068. stw_raw(w ++, 24); /* u16 len */
  1069. strcpy((void *) w, "hw-build"); /* char component[12] */
  1070. w += 6;
  1071. strcpy((void *) w, "QEMU " QEMU_VERSION); /* char version[12] */
  1072. w += 6;
  1073. tag = (model == 810) ? "1.1.10-qemu" : "1.1.6-qemu";
  1074. stw_raw(w ++, OMAP_TAG_VERSION_STR); /* u16 tag */
  1075. stw_raw(w ++, 24); /* u16 len */
  1076. strcpy((void *) w, "nolo"); /* char component[12] */
  1077. w += 6;
  1078. strcpy((void *) w, tag); /* char version[12] */
  1079. w += 6;
  1080. return (void *) w - p;
  1081. }
  1082. static int n800_atag_setup(struct arm_boot_info *info, void *p)
  1083. {
  1084. return n8x0_atag_setup(p, 800);
  1085. }
  1086. static int n810_atag_setup(struct arm_boot_info *info, void *p)
  1087. {
  1088. return n8x0_atag_setup(p, 810);
  1089. }
  1090. static void n8x0_init(ram_addr_t ram_size, const char *boot_device,
  1091. const char *kernel_filename,
  1092. const char *kernel_cmdline, const char *initrd_filename,
  1093. const char *cpu_model, struct arm_boot_info *binfo, int model)
  1094. {
  1095. struct n800_s *s = (struct n800_s *) qemu_mallocz(sizeof(*s));
  1096. int sdram_size = binfo->ram_size;
  1097. int onenandram_size = 0x00010000;
  1098. DisplayState *ds;
  1099. if (ram_size < sdram_size + onenandram_size + OMAP242X_SRAM_SIZE) {
  1100. fprintf(stderr, "This architecture uses %i bytes of memory\n",
  1101. sdram_size + onenandram_size + OMAP242X_SRAM_SIZE);
  1102. exit(1);
  1103. }
  1104. s->cpu = omap2420_mpu_init(sdram_size, cpu_model);
  1105. /* Setup peripherals
  1106. *
  1107. * Believed external peripherals layout in the N810:
  1108. * (spi bus 1)
  1109. * tsc2005
  1110. * lcd_mipid
  1111. * (spi bus 2)
  1112. * Conexant cx3110x (WLAN)
  1113. * optional: pc2400m (WiMAX)
  1114. * (i2c bus 0)
  1115. * TLV320AIC33 (audio codec)
  1116. * TCM825x (camera by Toshiba)
  1117. * lp5521 (clever LEDs)
  1118. * tsl2563 (light sensor, hwmon, model 7, rev. 0)
  1119. * lm8323 (keypad, manf 00, rev 04)
  1120. * (i2c bus 1)
  1121. * tmp105 (temperature sensor, hwmon)
  1122. * menelaus (pm)
  1123. * (somewhere on i2c - maybe N800-only)
  1124. * tea5761 (FM tuner)
  1125. * (serial 0)
  1126. * GPS
  1127. * (some serial port)
  1128. * csr41814 (Bluetooth)
  1129. */
  1130. n8x0_gpio_setup(s);
  1131. n8x0_nand_setup(s);
  1132. n8x0_i2c_setup(s);
  1133. if (model == 800)
  1134. n800_tsc_kbd_setup(s);
  1135. else if (model == 810) {
  1136. n810_tsc_setup(s);
  1137. n810_kbd_setup(s);
  1138. }
  1139. n8x0_spi_setup(s);
  1140. n8x0_dss_setup(s);
  1141. n8x0_cbus_setup(s);
  1142. n8x0_uart_setup(s);
  1143. if (usb_enabled)
  1144. n8x0_usb_setup(s);
  1145. /* Setup initial (reset) machine state */
  1146. /* Start at the OneNAND bootloader. */
  1147. s->cpu->env->regs[15] = 0;
  1148. if (kernel_filename) {
  1149. /* Or at the linux loader. */
  1150. binfo->kernel_filename = kernel_filename;
  1151. binfo->kernel_cmdline = kernel_cmdline;
  1152. binfo->initrd_filename = initrd_filename;
  1153. arm_load_kernel(s->cpu->env, binfo);
  1154. qemu_register_reset(n8x0_boot_init, s);
  1155. n8x0_boot_init(s);
  1156. }
  1157. if (option_rom[0] && (boot_device[0] == 'n' || !kernel_filename)) {
  1158. /* No, wait, better start at the ROM. */
  1159. s->cpu->env->regs[15] = OMAP2_Q2_BASE + 0x400000;
  1160. /* This is intended for loading the `secondary.bin' program from
  1161. * Nokia images (the NOLO bootloader). The entry point seems
  1162. * to be at OMAP2_Q2_BASE + 0x400000.
  1163. *
  1164. * The `2nd.bin' files contain some kind of earlier boot code and
  1165. * for them the entry point needs to be set to OMAP2_SRAM_BASE.
  1166. *
  1167. * The code above is for loading the `zImage' file from Nokia
  1168. * images. */
  1169. printf("%i bytes of image loaded\n", load_image(option_rom[0],
  1170. phys_ram_base + 0x400000));
  1171. n800_setup_nolo_tags(phys_ram_base + sdram_size);
  1172. }
  1173. /* FIXME: We shouldn't really be doing this here. The LCD controller
  1174. will set the size once configured, so this just sets an initial
  1175. size until the guest activates the display. */
  1176. ds = get_displaystate();
  1177. ds->surface = qemu_resize_displaysurface(ds->surface, 800, 480, 32, 4 * 800);
  1178. dpy_resize(ds);
  1179. }
  1180. static struct arm_boot_info n800_binfo = {
  1181. .loader_start = OMAP2_Q2_BASE,
  1182. /* Actually two chips of 0x4000000 bytes each */
  1183. .ram_size = 0x08000000,
  1184. .board_id = 0x4f7,
  1185. .atag_board = n800_atag_setup,
  1186. };
  1187. static struct arm_boot_info n810_binfo = {
  1188. .loader_start = OMAP2_Q2_BASE,
  1189. /* Actually two chips of 0x4000000 bytes each */
  1190. .ram_size = 0x08000000,
  1191. /* 0x60c and 0x6bf (WiMAX Edition) have been assigned but are not
  1192. * used by some older versions of the bootloader and 5555 is used
  1193. * instead (including versions that shipped with many devices). */
  1194. .board_id = 0x60c,
  1195. .atag_board = n810_atag_setup,
  1196. };
  1197. static void n800_init(ram_addr_t ram_size, int vga_ram_size,
  1198. const char *boot_device,
  1199. const char *kernel_filename, const char *kernel_cmdline,
  1200. const char *initrd_filename, const char *cpu_model)
  1201. {
  1202. return n8x0_init(ram_size, boot_device,
  1203. kernel_filename, kernel_cmdline, initrd_filename,
  1204. cpu_model, &n800_binfo, 800);
  1205. }
  1206. static void n810_init(ram_addr_t ram_size, int vga_ram_size,
  1207. const char *boot_device,
  1208. const char *kernel_filename, const char *kernel_cmdline,
  1209. const char *initrd_filename, const char *cpu_model)
  1210. {
  1211. return n8x0_init(ram_size, boot_device,
  1212. kernel_filename, kernel_cmdline, initrd_filename,
  1213. cpu_model, &n810_binfo, 810);
  1214. }
  1215. QEMUMachine n800_machine = {
  1216. .name = "n800",
  1217. .desc = "Nokia N800 tablet aka. RX-34 (OMAP2420)",
  1218. .init = n800_init,
  1219. .ram_require = (0x08000000 + 0x00010000 + OMAP242X_SRAM_SIZE) |
  1220. RAMSIZE_FIXED,
  1221. };
  1222. QEMUMachine n810_machine = {
  1223. .name = "n810",
  1224. .desc = "Nokia N810 tablet aka. RX-44 (OMAP2420)",
  1225. .init = n810_init,
  1226. .ram_require = (0x08000000 + 0x00010000 + OMAP242X_SRAM_SIZE) |
  1227. RAMSIZE_FIXED,
  1228. };