av7110_hw.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _AV7110_HW_H_
  3. #define _AV7110_HW_H_
  4. #include "av7110.h"
  5. /* DEBI transfer mode defs */
  6. #define DEBINOSWAP 0x000e0000
  7. #define DEBISWAB 0x001e0000
  8. #define DEBISWAP 0x002e0000
  9. #define ARM_WAIT_FREE (HZ)
  10. #define ARM_WAIT_SHAKE (HZ/5)
  11. #define ARM_WAIT_OSD (HZ)
  12. enum av7110_bootstate
  13. {
  14. BOOTSTATE_BUFFER_EMPTY = 0,
  15. BOOTSTATE_BUFFER_FULL = 1,
  16. BOOTSTATE_AV7110_BOOT_COMPLETE = 2
  17. };
  18. enum av7110_type_rec_play_format
  19. { RP_None,
  20. AudioPES,
  21. AudioMp2,
  22. AudioPCM,
  23. VideoPES,
  24. AV_PES
  25. };
  26. enum av7110_osd_palette_type
  27. {
  28. NoPalet = 0, /* No palette */
  29. Pal1Bit = 2, /* 2 colors for 1 Bit Palette */
  30. Pal2Bit = 4, /* 4 colors for 2 bit palette */
  31. Pal4Bit = 16, /* 16 colors for 4 bit palette */
  32. Pal8Bit = 256 /* 256 colors for 16 bit palette */
  33. };
  34. /* switch defines */
  35. #define SB_GPIO 3
  36. #define SB_OFF SAA7146_GPIO_OUTLO /* SlowBlank off (TV-Mode) */
  37. #define SB_ON SAA7146_GPIO_INPUT /* SlowBlank on (AV-Mode) */
  38. #define SB_WIDE SAA7146_GPIO_OUTHI /* SlowBlank 6V (16/9-Mode) (not implemented) */
  39. #define FB_GPIO 1
  40. #define FB_OFF SAA7146_GPIO_LO /* FastBlank off (CVBS-Mode) */
  41. #define FB_ON SAA7146_GPIO_OUTHI /* FastBlank on (RGB-Mode) */
  42. #define FB_LOOP SAA7146_GPIO_INPUT /* FastBlank loop-through (PC graphics ???) */
  43. enum av7110_video_output_mode
  44. {
  45. NO_OUT = 0, /* disable analog output */
  46. CVBS_RGB_OUT = 1,
  47. CVBS_YC_OUT = 2,
  48. YC_OUT = 3
  49. };
  50. /* firmware internal msg q status: */
  51. #define GPMQFull 0x0001 /* Main Message Queue Full */
  52. #define GPMQOver 0x0002 /* Main Message Queue Overflow */
  53. #define HPQFull 0x0004 /* High Priority Msg Queue Full */
  54. #define HPQOver 0x0008
  55. #define OSDQFull 0x0010 /* OSD Queue Full */
  56. #define OSDQOver 0x0020
  57. #define GPMQBusy 0x0040 /* Queue not empty, FW >= 261d */
  58. #define HPQBusy 0x0080
  59. #define OSDQBusy 0x0100
  60. /* hw section filter flags */
  61. #define SECTION_EIT 0x01
  62. #define SECTION_SINGLE 0x00
  63. #define SECTION_CYCLE 0x02
  64. #define SECTION_CONTINUOS 0x04
  65. #define SECTION_MODE 0x06
  66. #define SECTION_IPMPE 0x0C /* size up to 4k */
  67. #define SECTION_HIGH_SPEED 0x1C /* larger buffer */
  68. #define DATA_PIPING_FLAG 0x20 /* for Data Piping Filter */
  69. #define PBUFSIZE_NONE 0x0000
  70. #define PBUFSIZE_1P 0x0100
  71. #define PBUFSIZE_2P 0x0200
  72. #define PBUFSIZE_1K 0x0300
  73. #define PBUFSIZE_2K 0x0400
  74. #define PBUFSIZE_4K 0x0500
  75. #define PBUFSIZE_8K 0x0600
  76. #define PBUFSIZE_16K 0x0700
  77. #define PBUFSIZE_32K 0x0800
  78. /* firmware command codes */
  79. enum av7110_osd_command {
  80. WCreate,
  81. WDestroy,
  82. WMoveD,
  83. WMoveA,
  84. WHide,
  85. WTop,
  86. DBox,
  87. DLine,
  88. DText,
  89. Set_Font,
  90. SetColor,
  91. SetBlend,
  92. SetWBlend,
  93. SetCBlend,
  94. SetNonBlend,
  95. LoadBmp,
  96. BlitBmp,
  97. ReleaseBmp,
  98. SetWTrans,
  99. SetWNoTrans,
  100. Set_Palette
  101. };
  102. enum av7110_pid_command {
  103. MultiPID,
  104. VideoPID,
  105. AudioPID,
  106. InitFilt,
  107. FiltError,
  108. NewVersion,
  109. CacheError,
  110. AddPIDFilter,
  111. DelPIDFilter,
  112. Scan,
  113. SetDescr,
  114. SetIR,
  115. FlushTSQueue
  116. };
  117. enum av7110_mpeg_command {
  118. SelAudChannels
  119. };
  120. enum av7110_audio_command {
  121. AudioDAC,
  122. CabADAC,
  123. ON22K,
  124. OFF22K,
  125. MainSwitch,
  126. ADSwitch,
  127. SendDiSEqC,
  128. SetRegister,
  129. SpdifSwitch
  130. };
  131. enum av7110_request_command {
  132. AudioState,
  133. AudioBuffState,
  134. VideoState1,
  135. VideoState2,
  136. VideoState3,
  137. CrashCounter,
  138. ReqVersion,
  139. ReqVCXO,
  140. ReqRegister,
  141. ReqSecFilterError,
  142. ReqSTC
  143. };
  144. enum av7110_encoder_command {
  145. SetVidMode,
  146. SetTestMode,
  147. LoadVidCode,
  148. SetMonitorType,
  149. SetPanScanType,
  150. SetFreezeMode,
  151. SetWSSConfig
  152. };
  153. enum av7110_rec_play_state {
  154. __Record,
  155. __Stop,
  156. __Play,
  157. __Pause,
  158. __Slow,
  159. __FF_IP,
  160. __Scan_I,
  161. __Continue
  162. };
  163. enum av7110_fw_cmd_misc {
  164. AV7110_FW_VIDEO_ZOOM = 1,
  165. AV7110_FW_VIDEO_COMMAND,
  166. AV7110_FW_AUDIO_COMMAND
  167. };
  168. enum av7110_command_type {
  169. COMTYPE_NOCOM,
  170. COMTYPE_PIDFILTER,
  171. COMTYPE_MPEGDECODER,
  172. COMTYPE_OSD,
  173. COMTYPE_BMP,
  174. COMTYPE_ENCODER,
  175. COMTYPE_AUDIODAC,
  176. COMTYPE_REQUEST,
  177. COMTYPE_SYSTEM,
  178. COMTYPE_REC_PLAY,
  179. COMTYPE_COMMON_IF,
  180. COMTYPE_PID_FILTER,
  181. COMTYPE_PES,
  182. COMTYPE_TS,
  183. COMTYPE_VIDEO,
  184. COMTYPE_AUDIO,
  185. COMTYPE_CI_LL,
  186. COMTYPE_MISC = 0x80
  187. };
  188. #define VID_NONE_PREF 0x00 /* No aspect ration processing preferred */
  189. #define VID_PAN_SCAN_PREF 0x01 /* Pan and Scan Display preferred */
  190. #define VID_VERT_COMP_PREF 0x02 /* Vertical compression display preferred */
  191. #define VID_VC_AND_PS_PREF 0x03 /* PanScan and vertical Compression if allowed */
  192. #define VID_CENTRE_CUT_PREF 0x05 /* PanScan with zero vector */
  193. /* MPEG video decoder commands */
  194. #define AV_VIDEO_CMD_STOP 0x000e
  195. #define AV_VIDEO_CMD_PLAY 0x000d
  196. #define AV_VIDEO_CMD_FREEZE 0x0102
  197. #define AV_VIDEO_CMD_FFWD 0x0016
  198. #define AV_VIDEO_CMD_SLOW 0x0022
  199. /* MPEG audio decoder commands */
  200. #define AUDIO_CMD_MUTE 0x0001
  201. #define AUDIO_CMD_UNMUTE 0x0002
  202. #define AUDIO_CMD_PCM16 0x0010
  203. #define AUDIO_CMD_STEREO 0x0080
  204. #define AUDIO_CMD_MONO_L 0x0100
  205. #define AUDIO_CMD_MONO_R 0x0200
  206. #define AUDIO_CMD_SYNC_OFF 0x000e
  207. #define AUDIO_CMD_SYNC_ON 0x000f
  208. /* firmware data interface codes */
  209. #define DATA_NONE 0x00
  210. #define DATA_FSECTION 0x01
  211. #define DATA_IPMPE 0x02
  212. #define DATA_MPEG_RECORD 0x03
  213. #define DATA_DEBUG_MESSAGE 0x04
  214. #define DATA_COMMON_INTERFACE 0x05
  215. #define DATA_MPEG_PLAY 0x06
  216. #define DATA_BMP_LOAD 0x07
  217. #define DATA_IRCOMMAND 0x08
  218. #define DATA_PIPING 0x09
  219. #define DATA_STREAMING 0x0a
  220. #define DATA_CI_GET 0x0b
  221. #define DATA_CI_PUT 0x0c
  222. #define DATA_MPEG_VIDEO_EVENT 0x0d
  223. #define DATA_PES_RECORD 0x10
  224. #define DATA_PES_PLAY 0x11
  225. #define DATA_TS_RECORD 0x12
  226. #define DATA_TS_PLAY 0x13
  227. /* ancient CI command codes, only two are actually still used
  228. * by the link level CI firmware */
  229. #define CI_CMD_ERROR 0x00
  230. #define CI_CMD_ACK 0x01
  231. #define CI_CMD_SYSTEM_READY 0x02
  232. #define CI_CMD_KEYPRESS 0x03
  233. #define CI_CMD_ON_TUNED 0x04
  234. #define CI_CMD_ON_SWITCH_PROGRAM 0x05
  235. #define CI_CMD_SECTION_ARRIVED 0x06
  236. #define CI_CMD_SECTION_TIMEOUT 0x07
  237. #define CI_CMD_TIME 0x08
  238. #define CI_CMD_ENTER_MENU 0x09
  239. #define CI_CMD_FAST_PSI 0x0a
  240. #define CI_CMD_GET_SLOT_INFO 0x0b
  241. #define CI_MSG_NONE 0x00
  242. #define CI_MSG_CI_INFO 0x01
  243. #define CI_MSG_MENU 0x02
  244. #define CI_MSG_LIST 0x03
  245. #define CI_MSG_TEXT 0x04
  246. #define CI_MSG_REQUEST_INPUT 0x05
  247. #define CI_MSG_INPUT_COMPLETE 0x06
  248. #define CI_MSG_LIST_MORE 0x07
  249. #define CI_MSG_MENU_MORE 0x08
  250. #define CI_MSG_CLOSE_MMI_IMM 0x09
  251. #define CI_MSG_SECTION_REQUEST 0x0a
  252. #define CI_MSG_CLOSE_FILTER 0x0b
  253. #define CI_PSI_COMPLETE 0x0c
  254. #define CI_MODULE_READY 0x0d
  255. #define CI_SWITCH_PRG_REPLY 0x0e
  256. #define CI_MSG_TEXT_MORE 0x0f
  257. #define CI_MSG_CA_PMT 0xe0
  258. #define CI_MSG_ERROR 0xf0
  259. /* base address of the dual ported RAM which serves as communication
  260. * area between PCI bus and av7110,
  261. * as seen by the DEBI bus of the saa7146 */
  262. #define DPRAM_BASE 0x4000
  263. /* boot protocol area */
  264. #define AV7110_BOOT_STATE (DPRAM_BASE + 0x3F8)
  265. #define AV7110_BOOT_SIZE (DPRAM_BASE + 0x3FA)
  266. #define AV7110_BOOT_BASE (DPRAM_BASE + 0x3FC)
  267. #define AV7110_BOOT_BLOCK (DPRAM_BASE + 0x400)
  268. #define AV7110_BOOT_MAX_SIZE 0xc00
  269. /* firmware command protocol area */
  270. #define IRQ_STATE (DPRAM_BASE + 0x0F4)
  271. #define IRQ_STATE_EXT (DPRAM_BASE + 0x0F6)
  272. #define MSGSTATE (DPRAM_BASE + 0x0F8)
  273. #define COMMAND (DPRAM_BASE + 0x0FC)
  274. #define COM_BUFF (DPRAM_BASE + 0x100)
  275. #define COM_BUFF_SIZE 0x20
  276. /* various data buffers */
  277. #define BUFF1_BASE (DPRAM_BASE + 0x120)
  278. #define BUFF1_SIZE 0xE0
  279. #define DATA_BUFF0_BASE (DPRAM_BASE + 0x200)
  280. #define DATA_BUFF0_SIZE 0x0800
  281. #define DATA_BUFF1_BASE (DATA_BUFF0_BASE+DATA_BUFF0_SIZE)
  282. #define DATA_BUFF1_SIZE 0x0800
  283. #define DATA_BUFF2_BASE (DATA_BUFF1_BASE+DATA_BUFF1_SIZE)
  284. #define DATA_BUFF2_SIZE 0x0800
  285. #define DATA_BUFF3_BASE (DATA_BUFF2_BASE+DATA_BUFF2_SIZE)
  286. #define DATA_BUFF3_SIZE 0x0400
  287. #define Reserved (DPRAM_BASE + 0x1E00)
  288. #define Reserved_SIZE 0x1C0
  289. /* firmware status area */
  290. #define STATUS_BASE (DPRAM_BASE + 0x1FC0)
  291. #define STATUS_LOOPS (STATUS_BASE + 0x08)
  292. #define STATUS_MPEG_WIDTH (STATUS_BASE + 0x0C)
  293. /* ((aspect_ratio & 0xf) << 12) | (height & 0xfff) */
  294. #define STATUS_MPEG_HEIGHT_AR (STATUS_BASE + 0x0E)
  295. /* firmware data protocol area */
  296. #define RX_TYPE (DPRAM_BASE + 0x1FE8)
  297. #define RX_LEN (DPRAM_BASE + 0x1FEA)
  298. #define TX_TYPE (DPRAM_BASE + 0x1FEC)
  299. #define TX_LEN (DPRAM_BASE + 0x1FEE)
  300. #define RX_BUFF (DPRAM_BASE + 0x1FF4)
  301. #define TX_BUFF (DPRAM_BASE + 0x1FF6)
  302. #define HANDSHAKE_REG (DPRAM_BASE + 0x1FF8)
  303. #define COM_IF_LOCK (DPRAM_BASE + 0x1FFA)
  304. #define IRQ_RX (DPRAM_BASE + 0x1FFC)
  305. #define IRQ_TX (DPRAM_BASE + 0x1FFE)
  306. /* used by boot protocol to load firmware into av7110 DRAM */
  307. #define DRAM_START_CODE 0x2e000404
  308. #define DRAM_MAX_CODE_SIZE 0x00100000
  309. /* saa7146 gpio lines */
  310. #define RESET_LINE 2
  311. #define DEBI_DONE_LINE 1
  312. #define ARM_IRQ_LINE 0
  313. extern int av7110_bootarm(struct av7110 *av7110);
  314. extern int av7110_firmversion(struct av7110 *av7110);
  315. #define FW_CI_LL_SUPPORT(arm_app) ((arm_app) & 0x80000000)
  316. #define FW_4M_SDRAM(arm_app) ((arm_app) & 0x40000000)
  317. #define FW_VERSION(arm_app) ((arm_app) & 0x0000FFFF)
  318. extern int av7110_wait_msgstate(struct av7110 *av7110, u16 flags);
  319. extern int av7110_fw_cmd(struct av7110 *av7110, int type, int com, int num, ...);
  320. extern int av7110_fw_request(struct av7110 *av7110, u16 *request_buf,
  321. int request_buf_len, u16 *reply_buf, int reply_buf_len);
  322. /* DEBI (saa7146 data extension bus interface) access */
  323. extern int av7110_debiwrite(struct av7110 *av7110, u32 config,
  324. int addr, u32 val, unsigned int count);
  325. extern u32 av7110_debiread(struct av7110 *av7110, u32 config,
  326. int addr, unsigned int count);
  327. /* DEBI during interrupt */
  328. /* single word writes */
  329. static inline void iwdebi(struct av7110 *av7110, u32 config, int addr, u32 val, unsigned int count)
  330. {
  331. av7110_debiwrite(av7110, config, addr, val, count);
  332. }
  333. /* buffer writes */
  334. static inline void mwdebi(struct av7110 *av7110, u32 config, int addr,
  335. const u8 *val, int count)
  336. {
  337. memcpy(av7110->debi_virt, val, count);
  338. av7110_debiwrite(av7110, config, addr, 0, count);
  339. }
  340. static inline u32 irdebi(struct av7110 *av7110, u32 config, int addr, u32 val, unsigned int count)
  341. {
  342. u32 res;
  343. res=av7110_debiread(av7110, config, addr, count);
  344. if (count<=4)
  345. memcpy(av7110->debi_virt, (char *) &res, count);
  346. return res;
  347. }
  348. /* DEBI outside interrupts, only for count <= 4! */
  349. static inline void wdebi(struct av7110 *av7110, u32 config, int addr, u32 val, unsigned int count)
  350. {
  351. unsigned long flags;
  352. spin_lock_irqsave(&av7110->debilock, flags);
  353. av7110_debiwrite(av7110, config, addr, val, count);
  354. spin_unlock_irqrestore(&av7110->debilock, flags);
  355. }
  356. static inline u32 rdebi(struct av7110 *av7110, u32 config, int addr, u32 val, unsigned int count)
  357. {
  358. unsigned long flags;
  359. u32 res;
  360. spin_lock_irqsave(&av7110->debilock, flags);
  361. res=av7110_debiread(av7110, config, addr, count);
  362. spin_unlock_irqrestore(&av7110->debilock, flags);
  363. return res;
  364. }
  365. /* handle mailbox registers of the dual ported RAM */
  366. static inline void ARM_ResetMailBox(struct av7110 *av7110)
  367. {
  368. unsigned long flags;
  369. spin_lock_irqsave(&av7110->debilock, flags);
  370. av7110_debiread(av7110, DEBINOSWAP, IRQ_RX, 2);
  371. av7110_debiwrite(av7110, DEBINOSWAP, IRQ_RX, 0, 2);
  372. spin_unlock_irqrestore(&av7110->debilock, flags);
  373. }
  374. static inline void ARM_ClearMailBox(struct av7110 *av7110)
  375. {
  376. iwdebi(av7110, DEBINOSWAP, IRQ_RX, 0, 2);
  377. }
  378. static inline void ARM_ClearIrq(struct av7110 *av7110)
  379. {
  380. irdebi(av7110, DEBINOSWAP, IRQ_RX, 0, 2);
  381. }
  382. /****************************************************************************
  383. * Firmware commands
  384. ****************************************************************************/
  385. static inline int SendDAC(struct av7110 *av7110, u8 addr, u8 data)
  386. {
  387. return av7110_fw_cmd(av7110, COMTYPE_AUDIODAC, AudioDAC, 2, addr, data);
  388. }
  389. static inline int av7710_set_video_mode(struct av7110 *av7110, int mode)
  390. {
  391. return av7110_fw_cmd(av7110, COMTYPE_ENCODER, SetVidMode, 1, mode);
  392. }
  393. static inline int vidcom(struct av7110 *av7110, u32 com, u32 arg)
  394. {
  395. return av7110_fw_cmd(av7110, COMTYPE_MISC, AV7110_FW_VIDEO_COMMAND, 4,
  396. (com>>16), (com&0xffff),
  397. (arg>>16), (arg&0xffff));
  398. }
  399. static inline int audcom(struct av7110 *av7110, u32 com)
  400. {
  401. return av7110_fw_cmd(av7110, COMTYPE_MISC, AV7110_FW_AUDIO_COMMAND, 2,
  402. (com>>16), (com&0xffff));
  403. }
  404. static inline int Set22K(struct av7110 *av7110, int state)
  405. {
  406. return av7110_fw_cmd(av7110, COMTYPE_AUDIODAC, (state ? ON22K : OFF22K), 0);
  407. }
  408. extern int av7110_diseqc_send(struct av7110 *av7110, int len, u8 *msg, unsigned long burst);
  409. #ifdef CONFIG_DVB_AV7110_OSD
  410. extern int av7110_osd_cmd(struct av7110 *av7110, osd_cmd_t *dc);
  411. extern int av7110_osd_capability(struct av7110 *av7110, osd_cap_t *cap);
  412. #endif /* CONFIG_DVB_AV7110_OSD */
  413. #endif /* _AV7110_HW_H_ */