tc6393xb.c 18 KB

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