jpeg_hw.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  1. /*
  2. * Copyright (c) 2020 Actions Technology Co., Ltd
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #ifndef ZEPHYR_DRIVERS_JPEG_HW_H_
  7. #define ZEPHYR_DRIVERS_JPEG_HW_H_
  8. #include <zephyr.h>
  9. #include <device.h>
  10. #include <string.h>
  11. #include <board_cfg.h>
  12. #define JPEG_INRAM1 0x2ff17C00
  13. #define JPEG_INRAM0 0x2ff17E00
  14. #define JPEG_VLCTABLE_RAM 0x2ff17A00
  15. #define JPEG_IQTABLE_RAM 0x2ff17800
  16. #define JPEG_VLCTABLE_SIZE (384/4)
  17. #define JPEG_IQTABLE_SIZE (192/4)
  18. #define SDMAIP_SDMA3HFIP 19
  19. #define SDMAIP_SDMA2HFIP 18
  20. #define SDMAIP_SDMA1HFIP 17
  21. #define SDMAIP_SDMA0HFIP 16
  22. #define SDMAIP_SDMA3TCIP 3
  23. #define SDMAIP_SDMA2TCIP 2
  24. #define SDMAIP_SDMA1TCIP 1
  25. #define SDMAIP_SDMA0TCIP 0
  26. #define SDMAIE_SDMA3HFIE 19
  27. #define SDMAIE_SDMA2HFIE 18
  28. #define SDMAIE_SDMA1HFIE 17
  29. #define SDMAIE_SDMA0HFIE 16
  30. #define SDMAIE_SDMA3TCIE 3
  31. #define SDMAIE_SDMA2TCIE 2
  32. #define SDMAIE_SDMA1TCIE 1
  33. #define SDMAIE_SDMA0TCIE 0
  34. #define SDMADEBUG_DEBUGSEL_e 5
  35. #define SDMADEBUG_DEBUGSEL_SHIFT 0
  36. #define SDMADEBUG_DEBUGSEL_MASK (0x3F<<0)
  37. #define SDMA0CTL_STRME 24
  38. #define SDMA0CTL_RELOAD 18
  39. #define SDMA0CTL_DSTSL_e 13
  40. #define SDMA0CTL_DSTSL_SHIFT 8
  41. #define SDMA0CTL_DSTSL_MASK (0x3F<<8)
  42. #define SDMA0CTL_YSAM 6
  43. #define SDMA0CTL_SRCSL_e 5
  44. #define SDMA0CTL_SRCSL_SHIFT 0
  45. #define SDMA0CTL_SRCSL_MASK (0x3F<<0)
  46. #define SDMA0START_DMASTART 0
  47. #define SDMA0SADDR_DMASADDR_e 31
  48. #define SDMA0SADDR_DMASADDR_SHIFT 0
  49. #define SDMA0SADDR_DMASADDR_MASK (0xFFFFFFFF<<0)
  50. #define SDMA0BC_DMABYTECOUNTER_e 19
  51. #define SDMA0BC_DMABYTECOUNTER_SHIFT 0
  52. #define SDMA0BC_DMABYTECOUNTER_MASK (0xFFFFF<<0)
  53. #define SDMA0RC_DMAREMAINCOUNTER_e 19
  54. #define SDMA0RC_DMAREMAINCOUNTER_SHIFT 0
  55. #define SDMA0RC_DMAREMAINCOUNTER_MASK (0xFFFFF<<0)
  56. #define SDMA1CTL_STRME 24
  57. #define SDMA1CTL_JPEG_OUT_FORMAT 20
  58. #define SDMA1CTL_YDAM 14
  59. #define SDMA1CTL_DSTSL 8
  60. #define SDMA1CTL_YSAM 6
  61. #define SDMA1CTL_SRCSL 0
  62. #define SDMA1START_DMASTART 0
  63. #define SDMA1SADDR_DMASADDR_e 31
  64. #define SDMA1SADDR_DMASADDR_SHIFT 0
  65. #define SDMA1SADDR_DMASADDR_MASK (0xFFFFFFFF<<0)
  66. #define SDMA1DADDR_DMADADDR_e 31
  67. #define SDMA1DADDR_DMADADDR_SHIFT 0
  68. #define SDMA1DADDR_DMADADDR_MASK (0xFFFFFFFF<<0)
  69. #define SDMA1BC_DMABYTECOUNTER_e 19
  70. #define SDMA1BC_DMABYTECOUNTER_SHIFT 0
  71. #define SDMA1BC_DMABYTECOUNTER_MASK (0xFFFFF<<0)
  72. #define SDMA1RC_DMAREMAINCOUNTER_e 19
  73. #define SDMA1RC_DMAREMAINCOUNTER_SHIFT 0
  74. #define SDMA1RC_DMAREMAINCOUNTER_MASK (0xFFFFF<<0)
  75. #define SDMA2CTL_STRME 24
  76. #define SDMA2CTL_JPEG_OUT_FORMAT 20
  77. #define SDMA2CTL_YDAM 14
  78. #define SDMA2CTL_DSTSL 8
  79. #define SDMA2CTL_YSAM 6
  80. #define SDMA2CTL_SRCSL 0
  81. #define SDMA2START_DMASTART 0
  82. #define SDMA2SADDR_DMASADDR_e 31
  83. #define SDMA2SADDR_DMASADDR_SHIFT 0
  84. #define SDMA2SADDR_DMASADDR_MASK (0xFFFFFFFF<<0)
  85. #define SDMA2DADDR_DMADADDR_e 31
  86. #define SDMA2DADDR_DMADADDR_SHIFT 0
  87. #define SDMA2DADDR_DMADADDR_MASK (0xFFFFFFFF<<0)
  88. #define SDMA2BC_DMABYTECOUNTER_e 19
  89. #define SDMA2BC_DMABYTECOUNTER_SHIFT 0
  90. #define SDMA2BC_DMABYTECOUNTER_MASK (0xFFFFF<<0)
  91. #define SDMA2RC_DMAREMAINCOUNTER_e 19
  92. #define SDMA2RC_DMAREMAINCOUNTER_SHIFT 0
  93. #define SDMA2RC_DMAREMAINCOUNTER_MASK (0xFFFFF<<0)
  94. #define SDMA3CTL_STRME 24
  95. #define SDMA3CTL_JPEG_OUT_FORMAT 20
  96. #define SDMA3CTL_YDAM 14
  97. #define SDMA3CTL_DSTSL 8
  98. #define SDMA3CTL_YSAM 6
  99. #define SDMA3CTL_SRCSL 0
  100. #define SDMA3START_DMASTART 0
  101. #define SDMA3SADDR_DMASADDR_e 31
  102. #define SDMA3SADDR_DMASADDR_SHIFT 0
  103. #define SDMA3SADDR_DMASADDR_MASK (0xFFFFFFFF<<0)
  104. #define SDMA3DADDR_DMADADDR_e 31
  105. #define SDMA3DADDR_DMADADDR_SHIFT 0
  106. #define SDMA3DADDR_DMADADDR_MASK (0xFFFFFFFF<<0)
  107. #define SDMA3BC_DMABYTECOUNTER_e 19
  108. #define SDMA3BC_DMABYTECOUNTER_SHIFT 0
  109. #define SDMA3BC_DMABYTECOUNTER_MASK (0xFFFFF<<0)
  110. #define SDMA3RC_DMAREMAINCOUNTER_e 19
  111. #define SDMA3RC_DMAREMAINCOUNTER_SHIFT 0
  112. #define SDMA3RC_DMAREMAINCOUNTER_MASK (0xFFFFF<<0)
  113. #define LINE_LENGTH0_LENGTH_e 15
  114. #define LINE_LENGTH0_LENGTH_SHIFT 0
  115. #define LINE_LENGTH0_LENGTH_MASK (0xFFFF<<0)
  116. #define LINE_COUNT0_COUNT_e 15
  117. #define LINE_COUNT0_COUNT_SHIFT 0
  118. #define LINE_COUNT0_COUNT_MASK (0xFFFF<<0)
  119. #define LINE_SRC_STRIDE0_STRIDE_e 15
  120. #define LINE_SRC_STRIDE0_STRIDE_SHIFT 0
  121. #define LINE_SRC_STRIDE0_STRIDE_MASK (0xFFFF<<0)
  122. #define LINE_REMAIN0_COUNTER_e 15
  123. #define LINE_REMAIN0_COUNTER_SHIFT 0
  124. #define LINE_REMAIN0_COUNTER_MASK (0xFFFF<<0)
  125. #define BYTE_REMAIN_IN_LINE0_COUNTER_e 15
  126. #define BYTE_REMAIN_IN_LINE0_COUNTER_SHIFT 0
  127. #define BYTE_REMAIN_IN_LINE0_COUNTER_MASK (0xFFFF<<0)
  128. #define LINE_LENGTH1_LENGTH_e 15
  129. #define LINE_LENGTH1_LENGTH_SHIFT 0
  130. #define LINE_LENGTH1_LENGTH_MASK (0xFFFF<<0)
  131. #define LINE_COUNT1_COUNT_e 15
  132. #define LINE_COUNT1_COUNT_SHIFT 0
  133. #define LINE_COUNT1_COUNT_MASK (0xFFFF<<0)
  134. #define LINE_SRC_STRIDE1_STRIDE_e 15
  135. #define LINE_SRC_STRIDE1_STRIDE_SHIFT 0
  136. #define LINE_SRC_STRIDE1_STRIDE_MASK (0xFFFF<<0)
  137. #define LINE_DST_STRIDE1_STRIDE_e 15
  138. #define LINE_DST_STRIDE1_STRIDE_SHIFT 0
  139. #define LINE_DST_STRIDE1_STRIDE_MASK (0xFFFF<<0)
  140. #define LINE_REMAIN1_COUNTER_e 15
  141. #define LINE_REMAIN1_COUNTER_SHIFT 0
  142. #define LINE_REMAIN1_COUNTER_MASK (0xFFFF<<0)
  143. #define BYTE_REMAIN_IN_LINE1_COUNTER_e 15
  144. #define BYTE_REMAIN_IN_LINE1_COUNTER_SHIFT 0
  145. #define BYTE_REMAIN_IN_LINE1_COUNTER_MASK (0xFFFF<<0)
  146. #define LINE_LENGTH2_LENGTH_e 15
  147. #define LINE_LENGTH2_LENGTH_SHIFT 0
  148. #define LINE_LENGTH2_LENGTH_MASK (0xFFFF<<0)
  149. #define LINE_COUNT2_COUNT_e 15
  150. #define LINE_COUNT2_COUNT_SHIFT 0
  151. #define LINE_COUNT2_COUNT_MASK (0xFFFF<<0)
  152. #define LINE_SRC_STRIDE2_STRIDE_e 15
  153. #define LINE_SRC_STRIDE2_STRIDE_SHIFT 0
  154. #define LINE_SRC_STRIDE2_STRIDE_MASK (0xFFFF<<0)
  155. #define LINE_DST_STRIDE2_STRIDE_e 15
  156. #define LINE_DST_STRIDE2_STRIDE_SHIFT 0
  157. #define LINE_DST_STRIDE2_STRIDE_MASK (0xFFFF<<0)
  158. #define LINE_REMAIN2_COUNTER_e 15
  159. #define LINE_REMAIN2_COUNTER_SHIFT 0
  160. #define LINE_REMAIN2_COUNTER_MASK (0xFFFF<<0)
  161. #define BYTE_REMAIN_IN_LINE2_COUNTER_e 15
  162. #define BYTE_REMAIN_IN_LINE2_COUNTER_SHIFT 0
  163. #define BYTE_REMAIN_IN_LINE2_COUNTER_MASK (0xFFFF<<0)
  164. #define LINE_LENGTH3_LENGTH_e 15
  165. #define LINE_LENGTH3_LENGTH_SHIFT 0
  166. #define LINE_LENGTH3_LENGTH_MASK (0xFFFF<<0)
  167. #define LINE_COUNT3_COUNT_e 15
  168. #define LINE_COUNT3_COUNT_SHIFT 0
  169. #define LINE_COUNT3_COUNT_MASK (0xFFFF<<0)
  170. #define LINE_SRC_STRIDE3_STRIDE_e 15
  171. #define LINE_SRC_STRIDE3_STRIDE_SHIFT 0
  172. #define LINE_SRC_STRIDE3_STRIDE_MASK (0xFFFF<<0)
  173. #define LINE_DST_STRIDE3_STRIDE_e 15
  174. #define LINE_DST_STRIDE3_STRIDE_SHIFT 0
  175. #define LINE_DST_STRIDE3_STRIDE_MASK (0xFFFF<<0)
  176. #define LINE_REMAIN3_COUNTER_e 15
  177. #define LINE_REMAIN3_COUNTER_SHIFT 0
  178. #define LINE_REMAIN3_COUNTER_MASK (0xFFFF<<0)
  179. #define BYTE_REMAIN_IN_LINE3_COUNTER_e 15
  180. #define BYTE_REMAIN_IN_LINE3_COUNTER_SHIFT 0
  181. #define BYTE_REMAIN_IN_LINE3_COUNTER_MASK (0xFFFF<<0)
  182. #define MAX_NUMBER_OF_COMPONENTS 3
  183. /**
  184. * @brief SDMA Channel Config Module (SDMA_CHAN_Type)
  185. */
  186. typedef struct { /*!< DMA Channel Config Structure */
  187. volatile uint32_t CTL; /*!< (@ 0x00000000) Control Register */
  188. volatile uint32_t START; /*!< (@ 0x00000004) Start Register */
  189. volatile uint32_t SADDR; /*!< (@ 0x00000008) Source Address 0 Register */
  190. const volatile uint32_t RESERVED_1;
  191. volatile uint32_t DADDR; /*!< (@ 0x00000010) Source Address 1 Register */
  192. const volatile uint32_t RESERVED_2;
  193. volatile uint32_t BC; /*!< (@ 0x00000018) Byte Counter Register */
  194. volatile uint32_t RC; /*!< (@ 0x0000001C) Remain Counter Register */
  195. const volatile uint32_t RESERVED_3[56];
  196. } SDMA_CHAN_Type; /*!< Size = 256 (0x100) */
  197. /**
  198. * @brief SDMA Line Config Module (SDMA_LINE_Type)
  199. */
  200. typedef struct { /*!< SDMA Line Config Structure */
  201. volatile uint32_t LENGTH; /*!< (@ 0x00000000) Line Length Register */
  202. volatile uint32_t COUNT; /*!< (@ 0x00000004) Line Count Register */
  203. volatile uint32_t SSTRIDE; /*!< (@ 0x00000008) Line Src Stride Register */
  204. volatile uint32_t DSTRIDE; /*!< (@ 0x0000000C) Line Dest Stride Register */
  205. volatile uint32_t REMAIN; /*!< (@ 0x00000010) Line Remain Register */
  206. volatile uint32_t BYTE_REMAIN_IN_LINE; /*!< (@ 0x00000014) Byte Remain in Transmitting Line Register */
  207. const volatile uint32_t RESERVED[2];
  208. } SDMA_LINE_Type; /*!< Size = 32 (0x20) */
  209. /**
  210. * @brief SDMA Module (SDMA)
  211. */
  212. typedef struct { /*!< SDMA Structure */
  213. volatile uint32_t IP; /*!< (@ 0x00000000) Interrupt Pending Register */
  214. volatile uint32_t IE; /*!< (@ 0x00000004) Interrupt Enable Register */
  215. const volatile uint32_t RESERVED_1[26];
  216. volatile uint32_t PRIORITY; /*!< (@ 0x00000070) Priority Control Register */
  217. const volatile uint32_t RESERVED_2[3];
  218. volatile uint32_t DEBUG; /*!< (@ 0x00000080) Debug Register */
  219. const volatile uint32_t RESERVED_3[7];
  220. volatile uint32_t COUPLE_CONFIG; /*!< (@ 0x000000A0) Debug Register */
  221. volatile uint32_t COUPLE_BUF_ADDR; /*!< (@ 0x000000A4) Debug Register */
  222. volatile uint32_t COUPLE_BUF_SIZE; /*!< (@ 0x000000A8) Debug Register */
  223. volatile uint32_t COUPLE_START; /*!< (@ 0x000000AC) Debug Register */
  224. volatile uint32_t COUPLE_WRITER_POINTER; /*!< (@ 0x000000B0) Debug Register */
  225. volatile uint32_t COUPLE_READ_POINTER; /*!< (@ 0x000000B4) Debug Register */
  226. const volatile uint32_t RESERVED_4[18];
  227. SDMA_CHAN_Type CHAN_CTL[5];
  228. const volatile uint32_t RESERVED_5[384];
  229. SDMA_LINE_Type LINE_CTL[5];
  230. const volatile uint32_t RESERVED_6[24];
  231. volatile uint32_t COLOR_FILL_DATA[3]; /*!< (@ 0x000000AC) Color Fill Data Register */
  232. } __attribute__((__packed__)) SDMA_Type; /*!< Size = 3340 (0xD0C) */
  233. /**
  234. * @brief JPEG_HW Module (JPEG_HW)
  235. */
  236. typedef struct { /*!< JPEG_HW Structure */
  237. volatile uint32_t JPEG_ENABLE; /*!< (@ 0x00000000) Decoder enable register */
  238. volatile uint32_t JPEG_INTERRUPT; /*!< (@ 0x00000004) Decoder interrupt DRQ register */
  239. volatile uint32_t JPEG_CONFIG; /*!< (@ 0x00000008) Decode configure register */
  240. volatile uint32_t JPEG_BITSTREAM; /*!< (@ 0x0000000C) Bitstream register */
  241. volatile uint32_t JPEG_DOWNSAMPLE; /*!< (@ 0x00000010) Downsample register */
  242. volatile uint32_t JPEG_STREAM_SIZE; /*!< (@ 0x00000014) Stream size register */
  243. volatile uint32_t JPEG_WINDOW_SIZE; /*!< (@ 0x00000018) Window_wh register */
  244. volatile uint32_t JPEG_OUTPUT; /*!< (@ 0x0000001C) Output height register */
  245. volatile uint32_t JPEG_WINDOW_START; /*!< (@ 0x00000020) Window start */
  246. volatile uint32_t JPEG_RESOLUTION; /*!< (@ 0x00000024) Decoder picture resolution register*/
  247. volatile uint32_t JPEG_HUFF_TABLE; /*!< (@ 0x00000028) Huffman table select register */
  248. volatile uint32_t JPEG_AC_VLC[7]; /*!< (@ 0x0000002C) Jpeg AC VLC code part */
  249. volatile uint32_t JPEG_DC_VLC[4]; /*!< (@ 0x00000048) Jpeg DC VLC code part */
  250. const volatile uint32_t RESERVED;
  251. volatile uint32_t JPEG_DEBUG; /*!< (@ 0x0000005C) Decoder debug register */
  252. } __attribute__((__packed__)) JPEG_HW_Type; /*!< Size = 3340 (0xD0C) */
  253. typedef enum { /* JPEG marker codes */
  254. YUV100 = 0,
  255. YUV111,
  256. YUV420,
  257. YUV211H,
  258. YUV211V,
  259. YUV422,
  260. YUV_OTHER,
  261. }jpeg_yue_mode_e;
  262. typedef struct
  263. {
  264. uint32_t Ls;
  265. uint32_t Ns;
  266. uint32_t Cs[MAX_NUMBER_OF_COMPONENTS]; /* Scan component selector */
  267. uint32_t Td[MAX_NUMBER_OF_COMPONENTS]; /* Selects table for DC */
  268. uint32_t Ta[MAX_NUMBER_OF_COMPONENTS]; /* Selects table for AC */
  269. uint32_t Ss;
  270. uint32_t Se;
  271. uint32_t Ah;
  272. uint32_t Al;
  273. uint32_t index;
  274. } ScanInfo;
  275. struct jpeg_info_t {
  276. uint8_t *stream_addr;
  277. uint32_t stream_offset;
  278. uint32_t stream_size;
  279. uint16_t image_w;
  280. uint16_t image_h;
  281. uint16_t window_x;
  282. uint16_t window_y;
  283. uint16_t window_w;
  284. uint16_t window_h;
  285. uint16_t output_stride;
  286. uint8_t output_format;
  287. uint8_t ds_mode;
  288. uint8_t *output_bmp;
  289. uint8_t DC_TAB0[16];
  290. uint8_t DC_TAB1[16];
  291. uint8_t AC_TAB0[16];
  292. uint8_t AC_TAB1[16];
  293. uint8_t *HDcTable[4];
  294. uint8_t *HAcTable[4];
  295. int32_t amountOfQTables;
  296. int32_t getQTablenum;
  297. jpeg_yue_mode_e yuv_mode;
  298. ScanInfo scan;
  299. uint8_t Date[20];
  300. };
  301. enum jpeg_hw_status {
  302. /* frame decode finised*/
  303. DECODE_FRAME_FINISHED = 0,
  304. /* block decoded finised */
  305. DECODE_BLOCK_FINISHED = 1,
  306. /* block decoded ERR */
  307. DECODE_DRROR = 2,
  308. };
  309. /**
  310. * @struct jpeg_hw_engine_capabilities
  311. * @brief Structure holding display engine capabilities
  312. *
  313. * @var uint8_t jpeg_hw_capabilities::num_overlays
  314. * Maximum number of overlays supported
  315. *
  316. * @var uint16_t jpeg_hw_capabilities::max_width
  317. * X Resolution at maximum
  318. *
  319. * @var uint16_t jpeg_hw_capabilities::max_height
  320. * Y Resolution at maximum
  321. *
  322. * @var uint8_t jpeg_hw_capabilities::support_blend_fg
  323. * Blending constant fg color supported
  324. *
  325. * @var uint8_t jpeg_hw_capabilities::support_blend_b
  326. * Blending constant bg color supported
  327. *
  328. * @var uint32_t jpeg_hw_capabilities::supported_input_pixel_formats
  329. * Bitwise or of input pixel formats supported by the display engine
  330. *
  331. * @var uint32_t jpeg_hw_capabilities::supported_output_pixel_formats
  332. * Bitwise or of output pixel formats supported by the display engine
  333. *
  334. * @var uint32_t jpeg_hw_capabilities::supported_rotate_pixel_formats
  335. * Bitwise or of rotation pixel formats supported by the display engine
  336. *
  337. */
  338. struct jpeg_hw_capabilities {
  339. uint32_t min_width : 10;
  340. uint32_t min_height : 10;
  341. uint32_t max_width : 10;
  342. uint32_t max_height : 10;
  343. };
  344. /**
  345. * @typedef jpeg_hw_engine_instance_callback_t
  346. * @brief Callback API executed when any display engine instance transfer complete or error
  347. *
  348. */
  349. typedef void (*jpeg_hw_instance_callback_t)(int err_code, void *user_data);
  350. /**
  351. * @typedef jpeg_hw_open_api
  352. * @brief Callback API to open jpeg hw
  353. * See jpeg_hw_open_api() for argument description
  354. */
  355. typedef int (*jpeg_hw_open_api)(const struct device *dev);
  356. /**
  357. * @typedef jpeg_hw_close_api
  358. * @brief Callback API to close jpeg hw
  359. * See jpeg_hw_close() for argument description
  360. */
  361. typedef int (*jpeg_hw_close_api)(const struct device *dev);
  362. /**
  363. * @typedef jpeg_hw_config_api
  364. * @brief Callback API to config jpeg hw
  365. * See jpeg_hw_config() for argument description
  366. */
  367. typedef int (*jpeg_hw_config_api)(const struct device *dev,
  368. struct jpeg_info_t *cfg_info);
  369. /**
  370. * @typedef jpeg_hw_config_api
  371. * @brief Callback API to config jpeg hw
  372. * See jpeg_hw_config() for argument description
  373. */
  374. typedef int (*jpeg_hw_decode_api)(const struct device *dev);
  375. /**
  376. * @typedef jpeg_hw_get_capabilities_api
  377. * @brief Callback API to get jpeg hw capabilities
  378. * See jpeg_hw_get_capabilities() for argument description
  379. */
  380. typedef void (*jpeg_hw_get_capabilities_api)(const struct device *dev,
  381. struct jpeg_hw_capabilities *capabilities);
  382. /**
  383. * @typedef jpeg_hw_register_callback_api
  384. * @brief Callback API to register instance callback
  385. * See jpeg_hw_register_callback() for argument description
  386. */
  387. typedef int (*jpeg_hw_register_callback_api)(const struct device *dev,
  388. jpeg_hw_instance_callback_t callback, void *user_data);
  389. /**
  390. * @typedef jpeg_hw_poll_api
  391. * @brief Callback API to poll complete of jpeg hw
  392. * See jpeg_hw_poll_api() for argument description
  393. */
  394. typedef int (*jpeg_hw_poll_api)(const struct device *dev,
  395. int timeout_ms);
  396. /**
  397. * @brief jpeg hw driver API
  398. * API which a jpeg hw driver should expose
  399. */
  400. struct jpeg_hw_driver_api {
  401. jpeg_hw_open_api open;
  402. jpeg_hw_close_api close;
  403. jpeg_hw_config_api config;
  404. jpeg_hw_get_capabilities_api get_capabilities;
  405. jpeg_hw_register_callback_api register_callback;
  406. jpeg_hw_decode_api decode;
  407. jpeg_hw_poll_api poll;
  408. };
  409. /**
  410. * @brief open jpeg hw
  411. *
  412. * @param dev Pointer to device structure
  413. *
  414. * @retval 0 on success else negative errno code.
  415. */
  416. static inline int jpeg_open(
  417. const struct device *dev)
  418. {
  419. struct jpeg_hw_driver_api *api =
  420. (struct jpeg_hw_driver_api *)dev->api;
  421. return api->open(dev);
  422. }
  423. /**
  424. * @brief config jpeg hw
  425. *
  426. * @param dev Pointer to device structure
  427. *
  428. * @retval 0 on success else negative errno code.
  429. */
  430. static inline int jpeg_config(
  431. const struct device *dev, struct jpeg_info_t *cfg_info)
  432. {
  433. struct jpeg_hw_driver_api *api =
  434. (struct jpeg_hw_driver_api *)dev->api;
  435. return api->config(dev, cfg_info);
  436. }
  437. /**
  438. * @brief jpeg hw start process
  439. *
  440. * @param dev Pointer to device structure
  441. *
  442. * @retval 0 on success else negative errno code.
  443. */
  444. static inline int jpeg_decode(
  445. const struct device *dev)
  446. {
  447. struct jpeg_hw_driver_api *api =
  448. (struct jpeg_hw_driver_api *)dev->api;
  449. return api->decode(dev);
  450. }
  451. /**
  452. * @brief jpeg hw start process
  453. *
  454. * @param dev Pointer to device structure
  455. *
  456. * @retval 0 on success else negative errno code.
  457. */
  458. static inline int jpeg_register_callback(
  459. const struct device *dev,
  460. jpeg_hw_instance_callback_t callback, void *user_data)
  461. {
  462. struct jpeg_hw_driver_api *api =
  463. (struct jpeg_hw_driver_api *)dev->api;
  464. return api->register_callback(dev, callback, user_data);
  465. }
  466. /**
  467. * @brief close jpeg hw
  468. *
  469. * @param dev Pointer to device structure
  470. *
  471. * @retval 0 on success else negative errno code.
  472. */
  473. static inline int jpeg_decode_wait_finished(
  474. const struct device *dev, int timeout)
  475. {
  476. struct jpeg_hw_driver_api *api =
  477. (struct jpeg_hw_driver_api *)dev->api;
  478. return api->poll(dev, timeout);
  479. }
  480. /**
  481. * @brief close jpeg hw
  482. *
  483. * @param dev Pointer to device structure
  484. *
  485. * @retval 0 on success else negative errno code.
  486. */
  487. static inline int jpeg_close(
  488. const struct device *dev)
  489. {
  490. struct jpeg_hw_driver_api *api =
  491. (struct jpeg_hw_driver_api *)dev->api;
  492. return api->close(dev);
  493. }
  494. #endif /* ZEPHYR_DRIVERS_JPEG_HW_H_ */