ast_drv.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  1. /*
  2. * Copyright 2012 Red Hat Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the
  6. * "Software"), to deal in the Software without restriction, including
  7. * without limitation the rights to use, copy, modify, merge, publish,
  8. * distribute, sub license, and/or sell copies of the Software, and to
  9. * permit persons to whom the Software is furnished to do so, subject to
  10. * the following conditions:
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  15. * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
  16. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  17. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  18. * USE OR OTHER DEALINGS IN THE SOFTWARE.
  19. *
  20. * The above copyright notice and this permission notice (including the
  21. * next paragraph) shall be included in all copies or substantial portions
  22. * of the Software.
  23. *
  24. */
  25. /*
  26. * Authors: Dave Airlie <airlied@redhat.com>
  27. */
  28. #ifndef __AST_DRV_H__
  29. #define __AST_DRV_H__
  30. #include <linux/io.h>
  31. #include <linux/types.h>
  32. #include <drm/drm_connector.h>
  33. #include <drm/drm_crtc.h>
  34. #include <drm/drm_encoder.h>
  35. #include <drm/drm_mode.h>
  36. #include <drm/drm_framebuffer.h>
  37. #include "ast_reg.h"
  38. #define DRIVER_AUTHOR "Dave Airlie"
  39. #define DRIVER_NAME "ast"
  40. #define DRIVER_DESC "AST"
  41. #define DRIVER_DATE "20120228"
  42. #define DRIVER_MAJOR 0
  43. #define DRIVER_MINOR 1
  44. #define DRIVER_PATCHLEVEL 0
  45. #define PCI_CHIP_AST2000 0x2000
  46. #define PCI_CHIP_AST2100 0x2010
  47. #define __AST_CHIP(__gen, __index) ((__gen) << 16 | (__index))
  48. enum ast_chip {
  49. /* 1st gen */
  50. AST1000 = __AST_CHIP(1, 0), // unused
  51. AST2000 = __AST_CHIP(1, 1),
  52. /* 2nd gen */
  53. AST1100 = __AST_CHIP(2, 0),
  54. AST2100 = __AST_CHIP(2, 1),
  55. AST2050 = __AST_CHIP(2, 2), // unused
  56. /* 3rd gen */
  57. AST2200 = __AST_CHIP(3, 0),
  58. AST2150 = __AST_CHIP(3, 1),
  59. /* 4th gen */
  60. AST2300 = __AST_CHIP(4, 0),
  61. AST1300 = __AST_CHIP(4, 1),
  62. AST1050 = __AST_CHIP(4, 2), // unused
  63. /* 5th gen */
  64. AST2400 = __AST_CHIP(5, 0),
  65. AST1400 = __AST_CHIP(5, 1),
  66. AST1250 = __AST_CHIP(5, 2), // unused
  67. /* 6th gen */
  68. AST2500 = __AST_CHIP(6, 0),
  69. AST2510 = __AST_CHIP(6, 1),
  70. AST2520 = __AST_CHIP(6, 2), // unused
  71. /* 7th gen */
  72. AST2600 = __AST_CHIP(7, 0),
  73. AST2620 = __AST_CHIP(7, 1), // unused
  74. };
  75. #define __AST_CHIP_GEN(__chip) (((unsigned long)(__chip)) >> 16)
  76. enum ast_tx_chip {
  77. AST_TX_NONE,
  78. AST_TX_SIL164,
  79. AST_TX_DP501,
  80. AST_TX_ASTDP,
  81. };
  82. #define AST_TX_NONE_BIT BIT(AST_TX_NONE)
  83. #define AST_TX_SIL164_BIT BIT(AST_TX_SIL164)
  84. #define AST_TX_DP501_BIT BIT(AST_TX_DP501)
  85. #define AST_TX_ASTDP_BIT BIT(AST_TX_ASTDP)
  86. enum ast_config_mode {
  87. ast_use_p2a,
  88. ast_use_dt,
  89. ast_use_defaults
  90. };
  91. #define AST_DRAM_512Mx16 0
  92. #define AST_DRAM_1Gx16 1
  93. #define AST_DRAM_512Mx32 2
  94. #define AST_DRAM_1Gx32 3
  95. #define AST_DRAM_2Gx16 6
  96. #define AST_DRAM_4Gx16 7
  97. #define AST_DRAM_8Gx16 8
  98. /*
  99. * Hardware cursor
  100. */
  101. #define AST_MAX_HWC_WIDTH 64
  102. #define AST_MAX_HWC_HEIGHT 64
  103. #define AST_HWC_SIZE (AST_MAX_HWC_WIDTH * AST_MAX_HWC_HEIGHT * 2)
  104. #define AST_HWC_SIGNATURE_SIZE 32
  105. /* define for signature structure */
  106. #define AST_HWC_SIGNATURE_CHECKSUM 0x00
  107. #define AST_HWC_SIGNATURE_SizeX 0x04
  108. #define AST_HWC_SIGNATURE_SizeY 0x08
  109. #define AST_HWC_SIGNATURE_X 0x0C
  110. #define AST_HWC_SIGNATURE_Y 0x10
  111. #define AST_HWC_SIGNATURE_HOTSPOTX 0x14
  112. #define AST_HWC_SIGNATURE_HOTSPOTY 0x18
  113. /*
  114. * Planes
  115. */
  116. struct ast_plane {
  117. struct drm_plane base;
  118. void __iomem *vaddr;
  119. u64 offset;
  120. unsigned long size;
  121. };
  122. static inline struct ast_plane *to_ast_plane(struct drm_plane *plane)
  123. {
  124. return container_of(plane, struct ast_plane, base);
  125. }
  126. /*
  127. * Connector
  128. */
  129. struct ast_connector {
  130. struct drm_connector base;
  131. enum drm_connector_status physical_status;
  132. };
  133. static inline struct ast_connector *
  134. to_ast_connector(struct drm_connector *connector)
  135. {
  136. return container_of(connector, struct ast_connector, base);
  137. }
  138. /*
  139. * Device
  140. */
  141. struct ast_device {
  142. struct drm_device base;
  143. void __iomem *regs;
  144. void __iomem *ioregs;
  145. void __iomem *dp501_fw_buf;
  146. enum ast_config_mode config_mode;
  147. enum ast_chip chip;
  148. uint32_t dram_bus_width;
  149. uint32_t dram_type;
  150. uint32_t mclk;
  151. void __iomem *vram;
  152. unsigned long vram_base;
  153. unsigned long vram_size;
  154. unsigned long vram_fb_available;
  155. struct mutex modeset_lock; /* Protects access to modeset I/O registers in ioregs */
  156. struct ast_plane primary_plane;
  157. struct ast_plane cursor_plane;
  158. struct drm_crtc crtc;
  159. struct {
  160. struct {
  161. struct drm_encoder encoder;
  162. struct ast_connector connector;
  163. } vga;
  164. struct {
  165. struct drm_encoder encoder;
  166. struct ast_connector connector;
  167. } sil164;
  168. struct {
  169. struct drm_encoder encoder;
  170. struct ast_connector connector;
  171. } dp501;
  172. struct {
  173. struct drm_encoder encoder;
  174. struct ast_connector connector;
  175. } astdp;
  176. } output;
  177. bool support_wide_screen;
  178. unsigned long tx_chip_types; /* bitfield of enum ast_chip_type */
  179. u8 *dp501_fw_addr;
  180. const struct firmware *dp501_fw; /* dp501 fw */
  181. };
  182. static inline struct ast_device *to_ast_device(struct drm_device *dev)
  183. {
  184. return container_of(dev, struct ast_device, base);
  185. }
  186. struct drm_device *ast_device_create(struct pci_dev *pdev,
  187. const struct drm_driver *drv,
  188. enum ast_chip chip,
  189. enum ast_config_mode config_mode,
  190. void __iomem *regs,
  191. void __iomem *ioregs,
  192. bool need_post);
  193. static inline unsigned long __ast_gen(struct ast_device *ast)
  194. {
  195. return __AST_CHIP_GEN(ast->chip);
  196. }
  197. #define AST_GEN(__ast) __ast_gen(__ast)
  198. static inline bool __ast_gen_is_eq(struct ast_device *ast, unsigned long gen)
  199. {
  200. return __ast_gen(ast) == gen;
  201. }
  202. #define IS_AST_GEN1(__ast) __ast_gen_is_eq(__ast, 1)
  203. #define IS_AST_GEN2(__ast) __ast_gen_is_eq(__ast, 2)
  204. #define IS_AST_GEN3(__ast) __ast_gen_is_eq(__ast, 3)
  205. #define IS_AST_GEN4(__ast) __ast_gen_is_eq(__ast, 4)
  206. #define IS_AST_GEN5(__ast) __ast_gen_is_eq(__ast, 5)
  207. #define IS_AST_GEN6(__ast) __ast_gen_is_eq(__ast, 6)
  208. #define IS_AST_GEN7(__ast) __ast_gen_is_eq(__ast, 7)
  209. static inline u8 __ast_read8(const void __iomem *addr, u32 reg)
  210. {
  211. return ioread8(addr + reg);
  212. }
  213. static inline u32 __ast_read32(const void __iomem *addr, u32 reg)
  214. {
  215. return ioread32(addr + reg);
  216. }
  217. static inline void __ast_write8(void __iomem *addr, u32 reg, u8 val)
  218. {
  219. iowrite8(val, addr + reg);
  220. }
  221. static inline void __ast_write32(void __iomem *addr, u32 reg, u32 val)
  222. {
  223. iowrite32(val, addr + reg);
  224. }
  225. static inline u8 __ast_read8_i(void __iomem *addr, u32 reg, u8 index)
  226. {
  227. __ast_write8(addr, reg, index);
  228. return __ast_read8(addr, reg + 1);
  229. }
  230. static inline u8 __ast_read8_i_masked(void __iomem *addr, u32 reg, u8 index, u8 read_mask)
  231. {
  232. u8 val = __ast_read8_i(addr, reg, index);
  233. return val & read_mask;
  234. }
  235. static inline void __ast_write8_i(void __iomem *addr, u32 reg, u8 index, u8 val)
  236. {
  237. __ast_write8(addr, reg, index);
  238. __ast_write8(addr, reg + 1, val);
  239. }
  240. static inline void __ast_write8_i_masked(void __iomem *addr, u32 reg, u8 index, u8 read_mask,
  241. u8 val)
  242. {
  243. u8 tmp = __ast_read8_i_masked(addr, reg, index, read_mask);
  244. tmp |= val;
  245. __ast_write8_i(addr, reg, index, tmp);
  246. }
  247. static inline u32 ast_read32(struct ast_device *ast, u32 reg)
  248. {
  249. return __ast_read32(ast->regs, reg);
  250. }
  251. static inline void ast_write32(struct ast_device *ast, u32 reg, u32 val)
  252. {
  253. __ast_write32(ast->regs, reg, val);
  254. }
  255. static inline u8 ast_io_read8(struct ast_device *ast, u32 reg)
  256. {
  257. return __ast_read8(ast->ioregs, reg);
  258. }
  259. static inline void ast_io_write8(struct ast_device *ast, u32 reg, u8 val)
  260. {
  261. __ast_write8(ast->ioregs, reg, val);
  262. }
  263. static inline u8 ast_get_index_reg(struct ast_device *ast, u32 base, u8 index)
  264. {
  265. return __ast_read8_i(ast->ioregs, base, index);
  266. }
  267. static inline u8 ast_get_index_reg_mask(struct ast_device *ast, u32 base, u8 index,
  268. u8 preserve_mask)
  269. {
  270. return __ast_read8_i_masked(ast->ioregs, base, index, preserve_mask);
  271. }
  272. static inline void ast_set_index_reg(struct ast_device *ast, u32 base, u8 index, u8 val)
  273. {
  274. __ast_write8_i(ast->ioregs, base, index, val);
  275. }
  276. static inline void ast_set_index_reg_mask(struct ast_device *ast, u32 base, u8 index,
  277. u8 preserve_mask, u8 val)
  278. {
  279. __ast_write8_i_masked(ast->ioregs, base, index, preserve_mask, val);
  280. }
  281. #define AST_VIDMEM_SIZE_8M 0x00800000
  282. #define AST_VIDMEM_SIZE_16M 0x01000000
  283. #define AST_VIDMEM_SIZE_32M 0x02000000
  284. #define AST_VIDMEM_SIZE_64M 0x04000000
  285. #define AST_VIDMEM_SIZE_128M 0x08000000
  286. #define AST_VIDMEM_DEFAULT_SIZE AST_VIDMEM_SIZE_8M
  287. struct ast_vbios_stdtable {
  288. u8 misc;
  289. u8 seq[4];
  290. u8 crtc[25];
  291. u8 ar[20];
  292. u8 gr[9];
  293. };
  294. struct ast_vbios_enhtable {
  295. u32 ht;
  296. u32 hde;
  297. u32 hfp;
  298. u32 hsync;
  299. u32 vt;
  300. u32 vde;
  301. u32 vfp;
  302. u32 vsync;
  303. u32 dclk_index;
  304. u32 flags;
  305. u32 refresh_rate;
  306. u32 refresh_rate_index;
  307. u32 mode_id;
  308. };
  309. struct ast_vbios_dclk_info {
  310. u8 param1;
  311. u8 param2;
  312. u8 param3;
  313. };
  314. struct ast_vbios_mode_info {
  315. const struct ast_vbios_stdtable *std_table;
  316. const struct ast_vbios_enhtable *enh_table;
  317. };
  318. struct ast_crtc_state {
  319. struct drm_crtc_state base;
  320. /* Last known format of primary plane */
  321. const struct drm_format_info *format;
  322. struct ast_vbios_mode_info vbios_mode_info;
  323. };
  324. #define to_ast_crtc_state(state) container_of(state, struct ast_crtc_state, base)
  325. int ast_mode_config_init(struct ast_device *ast);
  326. #define AST_MM_ALIGN_SHIFT 4
  327. #define AST_MM_ALIGN_MASK ((1 << AST_MM_ALIGN_SHIFT) - 1)
  328. #define AST_DP501_FW_VERSION_MASK GENMASK(7, 4)
  329. #define AST_DP501_FW_VERSION_1 BIT(4)
  330. #define AST_DP501_PNP_CONNECTED BIT(1)
  331. #define AST_DP501_DEFAULT_DCLK 65
  332. #define AST_DP501_GBL_VERSION 0xf000
  333. #define AST_DP501_PNPMONITOR 0xf010
  334. #define AST_DP501_LINKRATE 0xf014
  335. #define AST_DP501_EDID_DATA 0xf020
  336. #define AST_DP_POWER_ON true
  337. #define AST_DP_POWER_OFF false
  338. /*
  339. * ASTDP resoultion table:
  340. * EX: ASTDP_A_B_C:
  341. * A: Resolution
  342. * B: Refresh Rate
  343. * C: Misc information, such as CVT, Reduce Blanked
  344. */
  345. #define ASTDP_640x480_60 0x00
  346. #define ASTDP_640x480_72 0x01
  347. #define ASTDP_640x480_75 0x02
  348. #define ASTDP_640x480_85 0x03
  349. #define ASTDP_800x600_56 0x04
  350. #define ASTDP_800x600_60 0x05
  351. #define ASTDP_800x600_72 0x06
  352. #define ASTDP_800x600_75 0x07
  353. #define ASTDP_800x600_85 0x08
  354. #define ASTDP_1024x768_60 0x09
  355. #define ASTDP_1024x768_70 0x0A
  356. #define ASTDP_1024x768_75 0x0B
  357. #define ASTDP_1024x768_85 0x0C
  358. #define ASTDP_1280x1024_60 0x0D
  359. #define ASTDP_1280x1024_75 0x0E
  360. #define ASTDP_1280x1024_85 0x0F
  361. #define ASTDP_1600x1200_60 0x10
  362. #define ASTDP_320x240_60 0x11
  363. #define ASTDP_400x300_60 0x12
  364. #define ASTDP_512x384_60 0x13
  365. #define ASTDP_1920x1200_60 0x14
  366. #define ASTDP_1920x1080_60 0x15
  367. #define ASTDP_1280x800_60 0x16
  368. #define ASTDP_1280x800_60_RB 0x17
  369. #define ASTDP_1440x900_60 0x18
  370. #define ASTDP_1440x900_60_RB 0x19
  371. #define ASTDP_1680x1050_60 0x1A
  372. #define ASTDP_1680x1050_60_RB 0x1B
  373. #define ASTDP_1600x900_60 0x1C
  374. #define ASTDP_1600x900_60_RB 0x1D
  375. #define ASTDP_1366x768_60 0x1E
  376. #define ASTDP_1152x864_75 0x1F
  377. int ast_mm_init(struct ast_device *ast);
  378. /* ast post */
  379. void ast_post_gpu(struct drm_device *dev);
  380. u32 ast_mindwm(struct ast_device *ast, u32 r);
  381. void ast_moutdwm(struct ast_device *ast, u32 r, u32 v);
  382. void ast_patch_ahb_2500(void __iomem *regs);
  383. int ast_vga_output_init(struct ast_device *ast);
  384. int ast_sil164_output_init(struct ast_device *ast);
  385. /* ast dp501 */
  386. bool ast_backup_fw(struct drm_device *dev, u8 *addr, u32 size);
  387. void ast_init_3rdtx(struct drm_device *dev);
  388. int ast_dp501_output_init(struct ast_device *ast);
  389. /* aspeed DP */
  390. int ast_dp_launch(struct ast_device *ast);
  391. int ast_astdp_output_init(struct ast_device *ast);
  392. #endif