tc6393xb.c 18 KB

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