tc6393xb.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. /*
  2. * Toshiba TC6393XB I/O Controller.
  3. * Found in Sharp Zaurus SL-6000 (tosa) or some
  4. * Toshiba e-Series PDAs.
  5. *
  6. * Most features are currently unsupported!!!
  7. *
  8. * This code is licensed under the GNU GPL v2.
  9. *
  10. * Contributions after 2012-01-13 are licensed under the terms of the
  11. * GNU GPL, version 2 or (at your option) any later version.
  12. */
  13. #include "hw.h"
  14. #include "devices.h"
  15. #include "flash.h"
  16. #include "ui/console.h"
  17. #include "ui/pixel_ops.h"
  18. #include "sysemu/blockdev.h"
  19. #define IRQ_TC6393_NAND 0
  20. #define IRQ_TC6393_MMC 1
  21. #define IRQ_TC6393_OHCI 2
  22. #define IRQ_TC6393_SERIAL 3
  23. #define IRQ_TC6393_FB 4
  24. #define TC6393XB_NR_IRQS 8
  25. #define TC6393XB_GPIOS 16
  26. #define SCR_REVID 0x08 /* b Revision ID */
  27. #define SCR_ISR 0x50 /* b Interrupt Status */
  28. #define SCR_IMR 0x52 /* b Interrupt Mask */
  29. #define SCR_IRR 0x54 /* b Interrupt Routing */
  30. #define SCR_GPER 0x60 /* w GP Enable */
  31. #define SCR_GPI_SR(i) (0x64 + (i)) /* b3 GPI Status */
  32. #define SCR_GPI_IMR(i) (0x68 + (i)) /* b3 GPI INT Mask */
  33. #define SCR_GPI_EDER(i) (0x6c + (i)) /* b3 GPI Edge Detect Enable */
  34. #define SCR_GPI_LIR(i) (0x70 + (i)) /* b3 GPI Level Invert */
  35. #define SCR_GPO_DSR(i) (0x78 + (i)) /* b3 GPO Data Set */
  36. #define SCR_GPO_DOECR(i) (0x7c + (i)) /* b3 GPO Data OE Control */
  37. #define SCR_GP_IARCR(i) (0x80 + (i)) /* b3 GP Internal Active Register Control */
  38. #define SCR_GP_IARLCR(i) (0x84 + (i)) /* b3 GP INTERNAL Active Register Level Control */
  39. #define SCR_GPI_BCR(i) (0x88 + (i)) /* b3 GPI Buffer Control */
  40. #define SCR_GPA_IARCR 0x8c /* w GPa Internal Active Register Control */
  41. #define SCR_GPA_IARLCR 0x90 /* w GPa Internal Active Register Level Control */
  42. #define SCR_GPA_BCR 0x94 /* w GPa Buffer Control */
  43. #define SCR_CCR 0x98 /* w Clock Control */
  44. #define SCR_PLL2CR 0x9a /* w PLL2 Control */
  45. #define SCR_PLL1CR 0x9c /* l PLL1 Control */
  46. #define SCR_DIARCR 0xa0 /* b Device Internal Active Register Control */
  47. #define SCR_DBOCR 0xa1 /* b Device Buffer Off Control */
  48. #define SCR_FER 0xe0 /* b Function Enable */
  49. #define SCR_MCR 0xe4 /* w Mode Control */
  50. #define SCR_CONFIG 0xfc /* b Configuration Control */
  51. #define SCR_DEBUG 0xff /* b Debug */
  52. #define NAND_CFG_COMMAND 0x04 /* w Command */
  53. #define NAND_CFG_BASE 0x10 /* l Control Base Address */
  54. #define NAND_CFG_INTP 0x3d /* b Interrupt Pin */
  55. #define NAND_CFG_INTE 0x48 /* b Int Enable */
  56. #define NAND_CFG_EC 0x4a /* b Event Control */
  57. #define NAND_CFG_ICC 0x4c /* b Internal Clock Control */
  58. #define NAND_CFG_ECCC 0x5b /* b ECC Control */
  59. #define NAND_CFG_NFTC 0x60 /* b NAND Flash Transaction Control */
  60. #define NAND_CFG_NFM 0x61 /* b NAND Flash Monitor */
  61. #define NAND_CFG_NFPSC 0x62 /* b NAND Flash Power Supply Control */
  62. #define NAND_CFG_NFDC 0x63 /* b NAND Flash Detect Control */
  63. #define NAND_DATA 0x00 /* l Data */
  64. #define NAND_MODE 0x04 /* b Mode */
  65. #define NAND_STATUS 0x05 /* b Status */
  66. #define NAND_ISR 0x06 /* b Interrupt Status */
  67. #define NAND_IMR 0x07 /* b Interrupt Mask */
  68. #define NAND_MODE_WP 0x80
  69. #define NAND_MODE_CE 0x10
  70. #define NAND_MODE_ALE 0x02
  71. #define NAND_MODE_CLE 0x01
  72. #define NAND_MODE_ECC_MASK 0x60
  73. #define NAND_MODE_ECC_EN 0x20
  74. #define NAND_MODE_ECC_READ 0x40
  75. #define NAND_MODE_ECC_RST 0x60
  76. struct TC6393xbState {
  77. MemoryRegion iomem;
  78. qemu_irq irq;
  79. qemu_irq *sub_irqs;
  80. struct {
  81. uint8_t ISR;
  82. uint8_t IMR;
  83. uint8_t IRR;
  84. uint16_t GPER;
  85. uint8_t GPI_SR[3];
  86. uint8_t GPI_IMR[3];
  87. uint8_t GPI_EDER[3];
  88. uint8_t GPI_LIR[3];
  89. uint8_t GP_IARCR[3];
  90. uint8_t GP_IARLCR[3];
  91. uint8_t GPI_BCR[3];
  92. uint16_t GPA_IARCR;
  93. uint16_t GPA_IARLCR;
  94. uint16_t CCR;
  95. uint16_t PLL2CR;
  96. uint32_t PLL1CR;
  97. uint8_t DIARCR;
  98. uint8_t DBOCR;
  99. uint8_t FER;
  100. uint16_t MCR;
  101. uint8_t CONFIG;
  102. uint8_t DEBUG;
  103. } scr;
  104. uint32_t gpio_dir;
  105. uint32_t gpio_level;
  106. uint32_t prev_level;
  107. qemu_irq handler[TC6393XB_GPIOS];
  108. qemu_irq *gpio_in;
  109. struct {
  110. uint8_t mode;
  111. uint8_t isr;
  112. uint8_t imr;
  113. } nand;
  114. int nand_enable;
  115. uint32_t nand_phys;
  116. DeviceState *flash;
  117. ECCState ecc;
  118. DisplayState *ds;
  119. MemoryRegion vram;
  120. uint16_t *vram_ptr;
  121. uint32_t scr_width, scr_height; /* in pixels */
  122. qemu_irq l3v;
  123. unsigned blank : 1,
  124. blanked : 1;
  125. };
  126. qemu_irq *tc6393xb_gpio_in_get(TC6393xbState *s)
  127. {
  128. return s->gpio_in;
  129. }
  130. static void tc6393xb_gpio_set(void *opaque, int line, int level)
  131. {
  132. // TC6393xbState *s = opaque;
  133. if (line > TC6393XB_GPIOS) {
  134. printf("%s: No GPIO pin %i\n", __FUNCTION__, line);
  135. return;
  136. }
  137. // FIXME: how does the chip reflect the GPIO input level change?
  138. }
  139. void tc6393xb_gpio_out_set(TC6393xbState *s, int line,
  140. qemu_irq handler)
  141. {
  142. if (line >= TC6393XB_GPIOS) {
  143. fprintf(stderr, "TC6393xb: no GPIO pin %d\n", line);
  144. return;
  145. }
  146. s->handler[line] = handler;
  147. }
  148. static void tc6393xb_gpio_handler_update(TC6393xbState *s)
  149. {
  150. uint32_t level, diff;
  151. int bit;
  152. level = s->gpio_level & s->gpio_dir;
  153. for (diff = s->prev_level ^ level; diff; diff ^= 1 << bit) {
  154. bit = ffs(diff) - 1;
  155. qemu_set_irq(s->handler[bit], (level >> bit) & 1);
  156. }
  157. s->prev_level = level;
  158. }
  159. qemu_irq tc6393xb_l3v_get(TC6393xbState *s)
  160. {
  161. return s->l3v;
  162. }
  163. static void tc6393xb_l3v(void *opaque, int line, int level)
  164. {
  165. TC6393xbState *s = opaque;
  166. s->blank = !level;
  167. fprintf(stderr, "L3V: %d\n", level);
  168. }
  169. static void tc6393xb_sub_irq(void *opaque, int line, int level) {
  170. TC6393xbState *s = opaque;
  171. uint8_t isr = s->scr.ISR;
  172. if (level)
  173. isr |= 1 << line;
  174. else
  175. isr &= ~(1 << line);
  176. s->scr.ISR = isr;
  177. qemu_set_irq(s->irq, isr & s->scr.IMR);
  178. }
  179. #define SCR_REG_B(N) \
  180. case SCR_ ##N: return s->scr.N
  181. #define SCR_REG_W(N) \
  182. case SCR_ ##N: return s->scr.N; \
  183. case SCR_ ##N + 1: return s->scr.N >> 8;
  184. #define SCR_REG_L(N) \
  185. case SCR_ ##N: return s->scr.N; \
  186. case SCR_ ##N + 1: return s->scr.N >> 8; \
  187. case SCR_ ##N + 2: return s->scr.N >> 16; \
  188. case SCR_ ##N + 3: return s->scr.N >> 24;
  189. #define SCR_REG_A(N) \
  190. case SCR_ ##N(0): return s->scr.N[0]; \
  191. case SCR_ ##N(1): return s->scr.N[1]; \
  192. case SCR_ ##N(2): return s->scr.N[2]
  193. static uint32_t tc6393xb_scr_readb(TC6393xbState *s, hwaddr addr)
  194. {
  195. switch (addr) {
  196. case SCR_REVID:
  197. return 3;
  198. case SCR_REVID+1:
  199. return 0;
  200. SCR_REG_B(ISR);
  201. SCR_REG_B(IMR);
  202. SCR_REG_B(IRR);
  203. SCR_REG_W(GPER);
  204. SCR_REG_A(GPI_SR);
  205. SCR_REG_A(GPI_IMR);
  206. SCR_REG_A(GPI_EDER);
  207. SCR_REG_A(GPI_LIR);
  208. case SCR_GPO_DSR(0):
  209. case SCR_GPO_DSR(1):
  210. case SCR_GPO_DSR(2):
  211. return (s->gpio_level >> ((addr - SCR_GPO_DSR(0)) * 8)) & 0xff;
  212. case SCR_GPO_DOECR(0):
  213. case SCR_GPO_DOECR(1):
  214. case SCR_GPO_DOECR(2):
  215. return (s->gpio_dir >> ((addr - SCR_GPO_DOECR(0)) * 8)) & 0xff;
  216. SCR_REG_A(GP_IARCR);
  217. SCR_REG_A(GP_IARLCR);
  218. SCR_REG_A(GPI_BCR);
  219. SCR_REG_W(GPA_IARCR);
  220. SCR_REG_W(GPA_IARLCR);
  221. SCR_REG_W(CCR);
  222. SCR_REG_W(PLL2CR);
  223. SCR_REG_L(PLL1CR);
  224. SCR_REG_B(DIARCR);
  225. SCR_REG_B(DBOCR);
  226. SCR_REG_B(FER);
  227. SCR_REG_W(MCR);
  228. SCR_REG_B(CONFIG);
  229. SCR_REG_B(DEBUG);
  230. }
  231. fprintf(stderr, "tc6393xb_scr: unhandled read at %08x\n", (uint32_t) addr);
  232. return 0;
  233. }
  234. #undef SCR_REG_B
  235. #undef SCR_REG_W
  236. #undef SCR_REG_L
  237. #undef SCR_REG_A
  238. #define SCR_REG_B(N) \
  239. case SCR_ ##N: s->scr.N = value; return;
  240. #define SCR_REG_W(N) \
  241. case SCR_ ##N: s->scr.N = (s->scr.N & ~0xff) | (value & 0xff); return; \
  242. case SCR_ ##N + 1: s->scr.N = (s->scr.N & 0xff) | (value << 8); return
  243. #define SCR_REG_L(N) \
  244. case SCR_ ##N: s->scr.N = (s->scr.N & ~0xff) | (value & 0xff); return; \
  245. case SCR_ ##N + 1: s->scr.N = (s->scr.N & ~(0xff << 8)) | (value & (0xff << 8)); return; \
  246. case SCR_ ##N + 2: s->scr.N = (s->scr.N & ~(0xff << 16)) | (value & (0xff << 16)); return; \
  247. case SCR_ ##N + 3: s->scr.N = (s->scr.N & ~(0xff << 24)) | (value & (0xff << 24)); return;
  248. #define SCR_REG_A(N) \
  249. case SCR_ ##N(0): s->scr.N[0] = value; return; \
  250. case SCR_ ##N(1): s->scr.N[1] = value; return; \
  251. case SCR_ ##N(2): s->scr.N[2] = value; return
  252. static void tc6393xb_scr_writeb(TC6393xbState *s, hwaddr addr, uint32_t value)
  253. {
  254. switch (addr) {
  255. SCR_REG_B(ISR);
  256. SCR_REG_B(IMR);
  257. SCR_REG_B(IRR);
  258. SCR_REG_W(GPER);
  259. SCR_REG_A(GPI_SR);
  260. SCR_REG_A(GPI_IMR);
  261. SCR_REG_A(GPI_EDER);
  262. SCR_REG_A(GPI_LIR);
  263. case SCR_GPO_DSR(0):
  264. case SCR_GPO_DSR(1):
  265. case SCR_GPO_DSR(2):
  266. s->gpio_level = (s->gpio_level & ~(0xff << ((addr - SCR_GPO_DSR(0))*8))) | ((value & 0xff) << ((addr - SCR_GPO_DSR(0))*8));
  267. tc6393xb_gpio_handler_update(s);
  268. return;
  269. case SCR_GPO_DOECR(0):
  270. case SCR_GPO_DOECR(1):
  271. case SCR_GPO_DOECR(2):
  272. s->gpio_dir = (s->gpio_dir & ~(0xff << ((addr - SCR_GPO_DOECR(0))*8))) | ((value & 0xff) << ((addr - SCR_GPO_DOECR(0))*8));
  273. tc6393xb_gpio_handler_update(s);
  274. return;
  275. SCR_REG_A(GP_IARCR);
  276. SCR_REG_A(GP_IARLCR);
  277. SCR_REG_A(GPI_BCR);
  278. SCR_REG_W(GPA_IARCR);
  279. SCR_REG_W(GPA_IARLCR);
  280. SCR_REG_W(CCR);
  281. SCR_REG_W(PLL2CR);
  282. SCR_REG_L(PLL1CR);
  283. SCR_REG_B(DIARCR);
  284. SCR_REG_B(DBOCR);
  285. SCR_REG_B(FER);
  286. SCR_REG_W(MCR);
  287. SCR_REG_B(CONFIG);
  288. SCR_REG_B(DEBUG);
  289. }
  290. fprintf(stderr, "tc6393xb_scr: unhandled write at %08x: %02x\n",
  291. (uint32_t) addr, value & 0xff);
  292. }
  293. #undef SCR_REG_B
  294. #undef SCR_REG_W
  295. #undef SCR_REG_L
  296. #undef SCR_REG_A
  297. static void tc6393xb_nand_irq(TC6393xbState *s) {
  298. qemu_set_irq(s->sub_irqs[IRQ_TC6393_NAND],
  299. (s->nand.imr & 0x80) && (s->nand.imr & s->nand.isr));
  300. }
  301. static uint32_t tc6393xb_nand_cfg_readb(TC6393xbState *s, hwaddr addr) {
  302. switch (addr) {
  303. case NAND_CFG_COMMAND:
  304. return s->nand_enable ? 2 : 0;
  305. case NAND_CFG_BASE:
  306. case NAND_CFG_BASE + 1:
  307. case NAND_CFG_BASE + 2:
  308. case NAND_CFG_BASE + 3:
  309. return s->nand_phys >> (addr - NAND_CFG_BASE);
  310. }
  311. fprintf(stderr, "tc6393xb_nand_cfg: unhandled read at %08x\n", (uint32_t) addr);
  312. return 0;
  313. }
  314. static void tc6393xb_nand_cfg_writeb(TC6393xbState *s, hwaddr addr, uint32_t value) {
  315. switch (addr) {
  316. case NAND_CFG_COMMAND:
  317. s->nand_enable = (value & 0x2);
  318. return;
  319. case NAND_CFG_BASE:
  320. case NAND_CFG_BASE + 1:
  321. case NAND_CFG_BASE + 2:
  322. case NAND_CFG_BASE + 3:
  323. s->nand_phys &= ~(0xff << ((addr - NAND_CFG_BASE) * 8));
  324. s->nand_phys |= (value & 0xff) << ((addr - NAND_CFG_BASE) * 8);
  325. return;
  326. }
  327. fprintf(stderr, "tc6393xb_nand_cfg: unhandled write at %08x: %02x\n",
  328. (uint32_t) addr, value & 0xff);
  329. }
  330. static uint32_t tc6393xb_nand_readb(TC6393xbState *s, hwaddr addr) {
  331. switch (addr) {
  332. case NAND_DATA + 0:
  333. case NAND_DATA + 1:
  334. case NAND_DATA + 2:
  335. case NAND_DATA + 3:
  336. return nand_getio(s->flash);
  337. case NAND_MODE:
  338. return s->nand.mode;
  339. case NAND_STATUS:
  340. return 0x14;
  341. case NAND_ISR:
  342. return s->nand.isr;
  343. case NAND_IMR:
  344. return s->nand.imr;
  345. }
  346. fprintf(stderr, "tc6393xb_nand: unhandled read at %08x\n", (uint32_t) addr);
  347. return 0;
  348. }
  349. static void tc6393xb_nand_writeb(TC6393xbState *s, hwaddr addr, uint32_t value) {
  350. // fprintf(stderr, "tc6393xb_nand: write at %08x: %02x\n",
  351. // (uint32_t) addr, value & 0xff);
  352. switch (addr) {
  353. case NAND_DATA + 0:
  354. case NAND_DATA + 1:
  355. case NAND_DATA + 2:
  356. case NAND_DATA + 3:
  357. nand_setio(s->flash, value);
  358. s->nand.isr |= 1;
  359. tc6393xb_nand_irq(s);
  360. return;
  361. case NAND_MODE:
  362. s->nand.mode = value;
  363. nand_setpins(s->flash,
  364. value & NAND_MODE_CLE,
  365. value & NAND_MODE_ALE,
  366. !(value & NAND_MODE_CE),
  367. value & NAND_MODE_WP,
  368. 0); // FIXME: gnd
  369. switch (value & NAND_MODE_ECC_MASK) {
  370. case NAND_MODE_ECC_RST:
  371. ecc_reset(&s->ecc);
  372. break;
  373. case NAND_MODE_ECC_READ:
  374. // FIXME
  375. break;
  376. case NAND_MODE_ECC_EN:
  377. ecc_reset(&s->ecc);
  378. }
  379. return;
  380. case NAND_ISR:
  381. s->nand.isr = value;
  382. tc6393xb_nand_irq(s);
  383. return;
  384. case NAND_IMR:
  385. s->nand.imr = value;
  386. tc6393xb_nand_irq(s);
  387. return;
  388. }
  389. fprintf(stderr, "tc6393xb_nand: unhandled write at %08x: %02x\n",
  390. (uint32_t) addr, value & 0xff);
  391. }
  392. #define BITS 8
  393. #include "tc6393xb_template.h"
  394. #define BITS 15
  395. #include "tc6393xb_template.h"
  396. #define BITS 16
  397. #include "tc6393xb_template.h"
  398. #define BITS 24
  399. #include "tc6393xb_template.h"
  400. #define BITS 32
  401. #include "tc6393xb_template.h"
  402. static void tc6393xb_draw_graphic(TC6393xbState *s, int full_update)
  403. {
  404. switch (ds_get_bits_per_pixel(s->ds)) {
  405. case 8:
  406. tc6393xb_draw_graphic8(s);
  407. break;
  408. case 15:
  409. tc6393xb_draw_graphic15(s);
  410. break;
  411. case 16:
  412. tc6393xb_draw_graphic16(s);
  413. break;
  414. case 24:
  415. tc6393xb_draw_graphic24(s);
  416. break;
  417. case 32:
  418. tc6393xb_draw_graphic32(s);
  419. break;
  420. default:
  421. printf("tc6393xb: unknown depth %d\n", ds_get_bits_per_pixel(s->ds));
  422. return;
  423. }
  424. dpy_gfx_update(s->ds, 0, 0, s->scr_width, s->scr_height);
  425. }
  426. static void tc6393xb_draw_blank(TC6393xbState *s, int full_update)
  427. {
  428. int i, w;
  429. uint8_t *d;
  430. if (!full_update)
  431. return;
  432. w = s->scr_width * ((ds_get_bits_per_pixel(s->ds) + 7) >> 3);
  433. d = ds_get_data(s->ds);
  434. for(i = 0; i < s->scr_height; i++) {
  435. memset(d, 0, w);
  436. d += ds_get_linesize(s->ds);
  437. }
  438. dpy_gfx_update(s->ds, 0, 0, s->scr_width, s->scr_height);
  439. }
  440. static void tc6393xb_update_display(void *opaque)
  441. {
  442. TC6393xbState *s = opaque;
  443. int full_update;
  444. if (s->scr_width == 0 || s->scr_height == 0)
  445. return;
  446. full_update = 0;
  447. if (s->blanked != s->blank) {
  448. s->blanked = s->blank;
  449. full_update = 1;
  450. }
  451. if (s->scr_width != ds_get_width(s->ds) || s->scr_height != ds_get_height(s->ds)) {
  452. qemu_console_resize(s->ds, s->scr_width, s->scr_height);
  453. full_update = 1;
  454. }
  455. if (s->blanked)
  456. tc6393xb_draw_blank(s, full_update);
  457. else
  458. tc6393xb_draw_graphic(s, full_update);
  459. }
  460. static uint64_t tc6393xb_readb(void *opaque, hwaddr addr,
  461. unsigned size)
  462. {
  463. TC6393xbState *s = opaque;
  464. switch (addr >> 8) {
  465. case 0:
  466. return tc6393xb_scr_readb(s, addr & 0xff);
  467. case 1:
  468. return tc6393xb_nand_cfg_readb(s, addr & 0xff);
  469. };
  470. if ((addr &~0xff) == s->nand_phys && s->nand_enable) {
  471. // return tc6393xb_nand_readb(s, addr & 0xff);
  472. uint8_t d = tc6393xb_nand_readb(s, addr & 0xff);
  473. // fprintf(stderr, "tc6393xb_nand: read at %08x: %02hhx\n", (uint32_t) addr, d);
  474. return d;
  475. }
  476. // fprintf(stderr, "tc6393xb: unhandled read at %08x\n", (uint32_t) addr);
  477. return 0;
  478. }
  479. static void tc6393xb_writeb(void *opaque, hwaddr addr,
  480. uint64_t value, unsigned size) {
  481. TC6393xbState *s = opaque;
  482. switch (addr >> 8) {
  483. case 0:
  484. tc6393xb_scr_writeb(s, addr & 0xff, value);
  485. return;
  486. case 1:
  487. tc6393xb_nand_cfg_writeb(s, addr & 0xff, value);
  488. return;
  489. };
  490. if ((addr &~0xff) == s->nand_phys && s->nand_enable)
  491. tc6393xb_nand_writeb(s, addr & 0xff, value);
  492. else
  493. fprintf(stderr, "tc6393xb: unhandled write at %08x: %02x\n",
  494. (uint32_t) addr, (int)value & 0xff);
  495. }
  496. TC6393xbState *tc6393xb_init(MemoryRegion *sysmem, uint32_t base, qemu_irq irq)
  497. {
  498. TC6393xbState *s;
  499. DriveInfo *nand;
  500. static const MemoryRegionOps tc6393xb_ops = {
  501. .read = tc6393xb_readb,
  502. .write = tc6393xb_writeb,
  503. .endianness = DEVICE_NATIVE_ENDIAN,
  504. .impl = {
  505. .min_access_size = 1,
  506. .max_access_size = 1,
  507. },
  508. };
  509. s = (TC6393xbState *) g_malloc0(sizeof(TC6393xbState));
  510. s->irq = irq;
  511. s->gpio_in = qemu_allocate_irqs(tc6393xb_gpio_set, s, TC6393XB_GPIOS);
  512. s->l3v = *qemu_allocate_irqs(tc6393xb_l3v, s, 1);
  513. s->blanked = 1;
  514. s->sub_irqs = qemu_allocate_irqs(tc6393xb_sub_irq, s, TC6393XB_NR_IRQS);
  515. nand = drive_get(IF_MTD, 0, 0);
  516. s->flash = nand_init(nand ? nand->bdrv : NULL, NAND_MFR_TOSHIBA, 0x76);
  517. memory_region_init_io(&s->iomem, &tc6393xb_ops, s, "tc6393xb", 0x10000);
  518. memory_region_add_subregion(sysmem, base, &s->iomem);
  519. memory_region_init_ram(&s->vram, "tc6393xb.vram", 0x100000);
  520. vmstate_register_ram_global(&s->vram);
  521. s->vram_ptr = memory_region_get_ram_ptr(&s->vram);
  522. memory_region_add_subregion(sysmem, base + 0x100000, &s->vram);
  523. s->scr_width = 480;
  524. s->scr_height = 640;
  525. s->ds = graphic_console_init(tc6393xb_update_display,
  526. NULL, /* invalidate */
  527. NULL, /* screen_dump */
  528. NULL, /* text_update */
  529. s);
  530. return s;
  531. }