dv-bfin_ppi.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /* Blackfin Parallel Port Interface (PPI) model
  2. For "old style" PPIs on BF53x/etc... parts.
  3. Copyright (C) 2010-2015 Free Software Foundation, Inc.
  4. Contributed by Analog Devices, Inc.
  5. This file is part of simulators.
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 3 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  16. #include "config.h"
  17. #include "sim-main.h"
  18. #include "devices.h"
  19. #include "dv-bfin_ppi.h"
  20. #include "gui.h"
  21. /* XXX: TX is merely a stub. */
  22. struct bfin_ppi
  23. {
  24. /* This top portion matches common dv_bfin struct. */
  25. bu32 base;
  26. struct hw *dma_master;
  27. bool acked;
  28. struct hw_event *handler;
  29. char saved_byte;
  30. int saved_count;
  31. /* GUI state. */
  32. void *gui_state;
  33. int color;
  34. /* Order after here is important -- matches hardware MMR layout. */
  35. bu16 BFIN_MMR_16(control);
  36. bu16 BFIN_MMR_16(status);
  37. bu16 BFIN_MMR_16(count);
  38. bu16 BFIN_MMR_16(delay);
  39. bu16 BFIN_MMR_16(frame);
  40. };
  41. #define mmr_base() offsetof(struct bfin_ppi, control)
  42. #define mmr_offset(mmr) (offsetof(struct bfin_ppi, mmr) - mmr_base())
  43. static const char * const mmr_names[] =
  44. {
  45. "PPI_CONTROL", "PPI_STATUS", "PPI_COUNT", "PPI_DELAY", "PPI_FRAME",
  46. };
  47. #define mmr_name(off) mmr_names[(off) / 4]
  48. static void
  49. bfin_ppi_gui_setup (struct bfin_ppi *ppi)
  50. {
  51. int bpp;
  52. /* If we are in RX mode, nothing to do. */
  53. if (!(ppi->control & PORT_DIR))
  54. return;
  55. bpp = bfin_gui_color_depth (ppi->color);
  56. ppi->gui_state = bfin_gui_setup (ppi->gui_state,
  57. ppi->control & PORT_EN,
  58. (ppi->count + 1) / (bpp / 8),
  59. ppi->frame,
  60. ppi->color);
  61. }
  62. static unsigned
  63. bfin_ppi_io_write_buffer (struct hw *me, const void *source, int space,
  64. address_word addr, unsigned nr_bytes)
  65. {
  66. struct bfin_ppi *ppi = hw_data (me);
  67. bu32 mmr_off;
  68. bu32 value;
  69. bu16 *valuep;
  70. value = dv_load_2 (source);
  71. mmr_off = addr - ppi->base;
  72. valuep = (void *)((unsigned long)ppi + mmr_base() + mmr_off);
  73. HW_TRACE_WRITE ();
  74. dv_bfin_mmr_require_16 (me, addr, nr_bytes, true);
  75. switch (mmr_off)
  76. {
  77. case mmr_offset(control):
  78. *valuep = value;
  79. bfin_ppi_gui_setup (ppi);
  80. break;
  81. case mmr_offset(count):
  82. case mmr_offset(delay):
  83. case mmr_offset(frame):
  84. *valuep = value;
  85. break;
  86. case mmr_offset(status):
  87. dv_w1c_2 (valuep, value, ~(1 << 10));
  88. break;
  89. default:
  90. dv_bfin_mmr_invalid (me, addr, nr_bytes, true);
  91. break;
  92. }
  93. return nr_bytes;
  94. }
  95. static unsigned
  96. bfin_ppi_io_read_buffer (struct hw *me, void *dest, int space,
  97. address_word addr, unsigned nr_bytes)
  98. {
  99. struct bfin_ppi *ppi = hw_data (me);
  100. bu32 mmr_off;
  101. bu16 *valuep;
  102. mmr_off = addr - ppi->base;
  103. valuep = (void *)((unsigned long)ppi + mmr_base() + mmr_off);
  104. HW_TRACE_READ ();
  105. dv_bfin_mmr_require_16 (me, addr, nr_bytes, false);
  106. switch (mmr_off)
  107. {
  108. case mmr_offset(control):
  109. case mmr_offset(count):
  110. case mmr_offset(delay):
  111. case mmr_offset(frame):
  112. case mmr_offset(status):
  113. dv_store_2 (dest, *valuep);
  114. break;
  115. default:
  116. dv_bfin_mmr_invalid (me, addr, nr_bytes, false);
  117. break;
  118. }
  119. return nr_bytes;
  120. }
  121. static unsigned
  122. bfin_ppi_dma_read_buffer (struct hw *me, void *dest, int space,
  123. unsigned_word addr, unsigned nr_bytes)
  124. {
  125. HW_TRACE_DMA_READ ();
  126. return 0;
  127. }
  128. static unsigned
  129. bfin_ppi_dma_write_buffer (struct hw *me, const void *source,
  130. int space, unsigned_word addr,
  131. unsigned nr_bytes,
  132. int violate_read_only_section)
  133. {
  134. struct bfin_ppi *ppi = hw_data (me);
  135. HW_TRACE_DMA_WRITE ();
  136. return bfin_gui_update (ppi->gui_state, source, nr_bytes);
  137. }
  138. static const struct hw_port_descriptor bfin_ppi_ports[] =
  139. {
  140. { "stat", 0, 0, output_port, },
  141. { NULL, 0, 0, 0, },
  142. };
  143. static void
  144. attach_bfin_ppi_regs (struct hw *me, struct bfin_ppi *ppi)
  145. {
  146. address_word attach_address;
  147. int attach_space;
  148. unsigned attach_size;
  149. reg_property_spec reg;
  150. if (hw_find_property (me, "reg") == NULL)
  151. hw_abort (me, "Missing \"reg\" property");
  152. if (!hw_find_reg_array_property (me, "reg", 0, &reg))
  153. hw_abort (me, "\"reg\" property must contain three addr/size entries");
  154. hw_unit_address_to_attach_address (hw_parent (me),
  155. &reg.address,
  156. &attach_space, &attach_address, me);
  157. hw_unit_size_to_attach_size (hw_parent (me), &reg.size, &attach_size, me);
  158. if (attach_size != BFIN_MMR_PPI_SIZE)
  159. hw_abort (me, "\"reg\" size must be %#x", BFIN_MMR_PPI_SIZE);
  160. hw_attach_address (hw_parent (me),
  161. 0, attach_space, attach_address, attach_size, me);
  162. ppi->base = attach_address;
  163. }
  164. static void
  165. bfin_ppi_finish (struct hw *me)
  166. {
  167. struct bfin_ppi *ppi;
  168. const char *color;
  169. ppi = HW_ZALLOC (me, struct bfin_ppi);
  170. set_hw_data (me, ppi);
  171. set_hw_io_read_buffer (me, bfin_ppi_io_read_buffer);
  172. set_hw_io_write_buffer (me, bfin_ppi_io_write_buffer);
  173. set_hw_dma_read_buffer (me, bfin_ppi_dma_read_buffer);
  174. set_hw_dma_write_buffer (me, bfin_ppi_dma_write_buffer);
  175. set_hw_ports (me, bfin_ppi_ports);
  176. attach_bfin_ppi_regs (me, ppi);
  177. /* Initialize the PPI. */
  178. if (hw_find_property (me, "color"))
  179. color = hw_find_string_property (me, "color");
  180. else
  181. color = NULL;
  182. ppi->color = bfin_gui_color (color);
  183. }
  184. const struct hw_descriptor dv_bfin_ppi_descriptor[] =
  185. {
  186. {"bfin_ppi", bfin_ppi_finish,},
  187. {NULL, NULL},
  188. };