ast_mode.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161
  1. /*
  2. * Copyright 2012 Red Hat Inc.
  3. * Parts based on xf86-video-ast
  4. * Copyright (c) 2005 ASPEED Technology Inc.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the
  8. * "Software"), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish,
  10. * distribute, sub license, and/or sell copies of the Software, and to
  11. * permit persons to whom the Software is furnished to do so, subject to
  12. * the following conditions:
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
  18. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  19. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  20. * USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. * The above copyright notice and this permission notice (including the
  23. * next paragraph) shall be included in all copies or substantial portions
  24. * of the Software.
  25. *
  26. */
  27. /*
  28. * Authors: Dave Airlie <airlied@redhat.com>
  29. */
  30. #include <linux/export.h>
  31. #include "drmP.h"
  32. #include "drm_crtc.h"
  33. #include "drm_crtc_helper.h"
  34. #include "ast_drv.h"
  35. #include "ast_tables.h"
  36. static struct ast_i2c_chan *ast_i2c_create(struct drm_device *dev);
  37. static void ast_i2c_destroy(struct ast_i2c_chan *i2c);
  38. static int ast_cursor_set(struct drm_crtc *crtc,
  39. struct drm_file *file_priv,
  40. uint32_t handle,
  41. uint32_t width,
  42. uint32_t height);
  43. static int ast_cursor_move(struct drm_crtc *crtc,
  44. int x, int y);
  45. static inline void ast_load_palette_index(struct ast_private *ast,
  46. u8 index, u8 red, u8 green,
  47. u8 blue)
  48. {
  49. ast_io_write8(ast, AST_IO_DAC_INDEX_WRITE, index);
  50. ast_io_read8(ast, AST_IO_SEQ_PORT);
  51. ast_io_write8(ast, AST_IO_DAC_DATA, red);
  52. ast_io_read8(ast, AST_IO_SEQ_PORT);
  53. ast_io_write8(ast, AST_IO_DAC_DATA, green);
  54. ast_io_read8(ast, AST_IO_SEQ_PORT);
  55. ast_io_write8(ast, AST_IO_DAC_DATA, blue);
  56. ast_io_read8(ast, AST_IO_SEQ_PORT);
  57. }
  58. static void ast_crtc_load_lut(struct drm_crtc *crtc)
  59. {
  60. struct ast_private *ast = crtc->dev->dev_private;
  61. struct ast_crtc *ast_crtc = to_ast_crtc(crtc);
  62. int i;
  63. if (!crtc->enabled)
  64. return;
  65. for (i = 0; i < 256; i++)
  66. ast_load_palette_index(ast, i, ast_crtc->lut_r[i],
  67. ast_crtc->lut_g[i], ast_crtc->lut_b[i]);
  68. }
  69. static bool ast_get_vbios_mode_info(struct drm_crtc *crtc, struct drm_display_mode *mode,
  70. struct drm_display_mode *adjusted_mode,
  71. struct ast_vbios_mode_info *vbios_mode)
  72. {
  73. struct ast_private *ast = crtc->dev->dev_private;
  74. u32 refresh_rate_index = 0, mode_id, color_index, refresh_rate;
  75. u32 hborder, vborder;
  76. switch (crtc->fb->bits_per_pixel) {
  77. case 8:
  78. vbios_mode->std_table = &vbios_stdtable[VGAModeIndex];
  79. color_index = VGAModeIndex - 1;
  80. break;
  81. case 16:
  82. vbios_mode->std_table = &vbios_stdtable[HiCModeIndex];
  83. color_index = HiCModeIndex;
  84. break;
  85. case 24:
  86. case 32:
  87. vbios_mode->std_table = &vbios_stdtable[TrueCModeIndex];
  88. color_index = TrueCModeIndex;
  89. break;
  90. default:
  91. return false;
  92. }
  93. switch (crtc->mode.crtc_hdisplay) {
  94. case 640:
  95. vbios_mode->enh_table = &res_640x480[refresh_rate_index];
  96. break;
  97. case 800:
  98. vbios_mode->enh_table = &res_800x600[refresh_rate_index];
  99. break;
  100. case 1024:
  101. vbios_mode->enh_table = &res_1024x768[refresh_rate_index];
  102. break;
  103. case 1280:
  104. if (crtc->mode.crtc_vdisplay == 800)
  105. vbios_mode->enh_table = &res_1280x800[refresh_rate_index];
  106. else
  107. vbios_mode->enh_table = &res_1280x1024[refresh_rate_index];
  108. break;
  109. case 1440:
  110. vbios_mode->enh_table = &res_1440x900[refresh_rate_index];
  111. break;
  112. case 1600:
  113. vbios_mode->enh_table = &res_1600x1200[refresh_rate_index];
  114. break;
  115. case 1680:
  116. vbios_mode->enh_table = &res_1680x1050[refresh_rate_index];
  117. break;
  118. case 1920:
  119. if (crtc->mode.crtc_vdisplay == 1080)
  120. vbios_mode->enh_table = &res_1920x1080[refresh_rate_index];
  121. else
  122. vbios_mode->enh_table = &res_1920x1200[refresh_rate_index];
  123. break;
  124. default:
  125. return false;
  126. }
  127. refresh_rate = drm_mode_vrefresh(mode);
  128. while (vbios_mode->enh_table->refresh_rate < refresh_rate) {
  129. vbios_mode->enh_table++;
  130. if ((vbios_mode->enh_table->refresh_rate > refresh_rate) ||
  131. (vbios_mode->enh_table->refresh_rate == 0xff)) {
  132. vbios_mode->enh_table--;
  133. break;
  134. }
  135. }
  136. hborder = (vbios_mode->enh_table->flags & HBorder) ? 8 : 0;
  137. vborder = (vbios_mode->enh_table->flags & VBorder) ? 8 : 0;
  138. adjusted_mode->crtc_htotal = vbios_mode->enh_table->ht;
  139. adjusted_mode->crtc_hblank_start = vbios_mode->enh_table->hde + hborder;
  140. adjusted_mode->crtc_hblank_end = vbios_mode->enh_table->ht - hborder;
  141. adjusted_mode->crtc_hsync_start = vbios_mode->enh_table->hde + hborder +
  142. vbios_mode->enh_table->hfp;
  143. adjusted_mode->crtc_hsync_end = (vbios_mode->enh_table->hde + hborder +
  144. vbios_mode->enh_table->hfp +
  145. vbios_mode->enh_table->hsync);
  146. adjusted_mode->crtc_vtotal = vbios_mode->enh_table->vt;
  147. adjusted_mode->crtc_vblank_start = vbios_mode->enh_table->vde + vborder;
  148. adjusted_mode->crtc_vblank_end = vbios_mode->enh_table->vt - vborder;
  149. adjusted_mode->crtc_vsync_start = vbios_mode->enh_table->vde + vborder +
  150. vbios_mode->enh_table->vfp;
  151. adjusted_mode->crtc_vsync_end = (vbios_mode->enh_table->vde + vborder +
  152. vbios_mode->enh_table->vfp +
  153. vbios_mode->enh_table->vsync);
  154. refresh_rate_index = vbios_mode->enh_table->refresh_rate_index;
  155. mode_id = vbios_mode->enh_table->mode_id;
  156. if (ast->chip == AST1180) {
  157. /* TODO 1180 */
  158. } else {
  159. ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x8c, (u8)((color_index & 0xf) << 4));
  160. ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x8d, refresh_rate_index & 0xff);
  161. ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x8e, mode_id & 0xff);
  162. ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x91, 0xa8);
  163. ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x92, crtc->fb->bits_per_pixel);
  164. ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x93, adjusted_mode->clock / 1000);
  165. ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x94, adjusted_mode->crtc_hdisplay);
  166. ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x95, adjusted_mode->crtc_hdisplay >> 8);
  167. ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x96, adjusted_mode->crtc_vdisplay);
  168. ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x97, adjusted_mode->crtc_vdisplay >> 8);
  169. }
  170. return true;
  171. }
  172. static void ast_set_std_reg(struct drm_crtc *crtc, struct drm_display_mode *mode,
  173. struct ast_vbios_mode_info *vbios_mode)
  174. {
  175. struct ast_private *ast = crtc->dev->dev_private;
  176. struct ast_vbios_stdtable *stdtable;
  177. u32 i;
  178. u8 jreg;
  179. stdtable = vbios_mode->std_table;
  180. jreg = stdtable->misc;
  181. ast_io_write8(ast, AST_IO_MISC_PORT_WRITE, jreg);
  182. /* Set SEQ */
  183. ast_set_index_reg(ast, AST_IO_SEQ_PORT, 0x00, 0x03);
  184. for (i = 0; i < 4; i++) {
  185. jreg = stdtable->seq[i];
  186. if (!i)
  187. jreg |= 0x20;
  188. ast_set_index_reg(ast, AST_IO_SEQ_PORT, (i + 1) , jreg);
  189. }
  190. /* Set CRTC */
  191. ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0x11, 0x7f, 0x00);
  192. for (i = 0; i < 25; i++)
  193. ast_set_index_reg(ast, AST_IO_CRTC_PORT, i, stdtable->crtc[i]);
  194. /* set AR */
  195. jreg = ast_io_read8(ast, AST_IO_INPUT_STATUS1_READ);
  196. for (i = 0; i < 20; i++) {
  197. jreg = stdtable->ar[i];
  198. ast_io_write8(ast, AST_IO_AR_PORT_WRITE, (u8)i);
  199. ast_io_write8(ast, AST_IO_AR_PORT_WRITE, jreg);
  200. }
  201. ast_io_write8(ast, AST_IO_AR_PORT_WRITE, 0x14);
  202. ast_io_write8(ast, AST_IO_AR_PORT_WRITE, 0x00);
  203. jreg = ast_io_read8(ast, AST_IO_INPUT_STATUS1_READ);
  204. ast_io_write8(ast, AST_IO_AR_PORT_WRITE, 0x20);
  205. /* Set GR */
  206. for (i = 0; i < 9; i++)
  207. ast_set_index_reg(ast, AST_IO_GR_PORT, i, stdtable->gr[i]);
  208. }
  209. static void ast_set_crtc_reg(struct drm_crtc *crtc, struct drm_display_mode *mode,
  210. struct ast_vbios_mode_info *vbios_mode)
  211. {
  212. struct ast_private *ast = crtc->dev->dev_private;
  213. u8 jreg05 = 0, jreg07 = 0, jreg09 = 0, jregAC = 0, jregAD = 0, jregAE = 0;
  214. u16 temp;
  215. ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0x11, 0x7f, 0x00);
  216. temp = (mode->crtc_htotal >> 3) - 5;
  217. if (temp & 0x100)
  218. jregAC |= 0x01; /* HT D[8] */
  219. ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0x00, 0x00, temp);
  220. temp = (mode->crtc_hdisplay >> 3) - 1;
  221. if (temp & 0x100)
  222. jregAC |= 0x04; /* HDE D[8] */
  223. ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0x01, 0x00, temp);
  224. temp = (mode->crtc_hblank_start >> 3) - 1;
  225. if (temp & 0x100)
  226. jregAC |= 0x10; /* HBS D[8] */
  227. ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0x02, 0x00, temp);
  228. temp = ((mode->crtc_hblank_end >> 3) - 1) & 0x7f;
  229. if (temp & 0x20)
  230. jreg05 |= 0x80; /* HBE D[5] */
  231. if (temp & 0x40)
  232. jregAD |= 0x01; /* HBE D[5] */
  233. ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0x03, 0xE0, (temp & 0x1f));
  234. temp = (mode->crtc_hsync_start >> 3) - 1;
  235. if (temp & 0x100)
  236. jregAC |= 0x40; /* HRS D[5] */
  237. ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0x04, 0x00, temp);
  238. temp = ((mode->crtc_hsync_end >> 3) - 1) & 0x3f;
  239. if (temp & 0x20)
  240. jregAD |= 0x04; /* HRE D[5] */
  241. ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0x05, 0x60, (u8)((temp & 0x1f) | jreg05));
  242. ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xAC, 0x00, jregAC);
  243. ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xAD, 0x00, jregAD);
  244. /* vert timings */
  245. temp = (mode->crtc_vtotal) - 2;
  246. if (temp & 0x100)
  247. jreg07 |= 0x01;
  248. if (temp & 0x200)
  249. jreg07 |= 0x20;
  250. if (temp & 0x400)
  251. jregAE |= 0x01;
  252. ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0x06, 0x00, temp);
  253. temp = (mode->crtc_vsync_start) - 1;
  254. if (temp & 0x100)
  255. jreg07 |= 0x04;
  256. if (temp & 0x200)
  257. jreg07 |= 0x80;
  258. if (temp & 0x400)
  259. jregAE |= 0x08;
  260. ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0x10, 0x00, temp);
  261. temp = (mode->crtc_vsync_end - 1) & 0x3f;
  262. if (temp & 0x10)
  263. jregAE |= 0x20;
  264. if (temp & 0x20)
  265. jregAE |= 0x40;
  266. ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0x11, 0x70, temp & 0xf);
  267. temp = mode->crtc_vdisplay - 1;
  268. if (temp & 0x100)
  269. jreg07 |= 0x02;
  270. if (temp & 0x200)
  271. jreg07 |= 0x40;
  272. if (temp & 0x400)
  273. jregAE |= 0x02;
  274. ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0x12, 0x00, temp);
  275. temp = mode->crtc_vblank_start - 1;
  276. if (temp & 0x100)
  277. jreg07 |= 0x08;
  278. if (temp & 0x200)
  279. jreg09 |= 0x20;
  280. if (temp & 0x400)
  281. jregAE |= 0x04;
  282. ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0x15, 0x00, temp);
  283. temp = mode->crtc_vblank_end - 1;
  284. if (temp & 0x100)
  285. jregAE |= 0x10;
  286. ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0x16, 0x00, temp);
  287. ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0x07, 0x00, jreg07);
  288. ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0x09, 0xdf, jreg09);
  289. ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xAE, 0x00, (jregAE | 0x80));
  290. ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0x11, 0x7f, 0x80);
  291. }
  292. static void ast_set_offset_reg(struct drm_crtc *crtc)
  293. {
  294. struct ast_private *ast = crtc->dev->dev_private;
  295. u16 offset;
  296. offset = crtc->fb->pitches[0] >> 3;
  297. ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x13, (offset & 0xff));
  298. ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0xb0, (offset >> 8) & 0x3f);
  299. }
  300. static void ast_set_dclk_reg(struct drm_device *dev, struct drm_display_mode *mode,
  301. struct ast_vbios_mode_info *vbios_mode)
  302. {
  303. struct ast_private *ast = dev->dev_private;
  304. struct ast_vbios_dclk_info *clk_info;
  305. clk_info = &dclk_table[vbios_mode->enh_table->dclk_index];
  306. ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xc0, 0x00, clk_info->param1);
  307. ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xc1, 0x00, clk_info->param2);
  308. ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xbb, 0x0f,
  309. (clk_info->param3 & 0x80) | ((clk_info->param3 & 0x3) << 4));
  310. }
  311. static void ast_set_ext_reg(struct drm_crtc *crtc, struct drm_display_mode *mode,
  312. struct ast_vbios_mode_info *vbios_mode)
  313. {
  314. struct ast_private *ast = crtc->dev->dev_private;
  315. u8 jregA0 = 0, jregA3 = 0, jregA8 = 0;
  316. switch (crtc->fb->bits_per_pixel) {
  317. case 8:
  318. jregA0 = 0x70;
  319. jregA3 = 0x01;
  320. jregA8 = 0x00;
  321. break;
  322. case 15:
  323. case 16:
  324. jregA0 = 0x70;
  325. jregA3 = 0x04;
  326. jregA8 = 0x02;
  327. break;
  328. case 32:
  329. jregA0 = 0x70;
  330. jregA3 = 0x08;
  331. jregA8 = 0x02;
  332. break;
  333. }
  334. ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xa0, 0x8f, jregA0);
  335. ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xa3, 0xf0, jregA3);
  336. ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xa8, 0xfd, jregA8);
  337. /* Set Threshold */
  338. if (ast->chip == AST2300) {
  339. ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0xa7, 0x78);
  340. ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0xa6, 0x60);
  341. } else if (ast->chip == AST2100 ||
  342. ast->chip == AST1100 ||
  343. ast->chip == AST2200 ||
  344. ast->chip == AST2150) {
  345. ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0xa7, 0x3f);
  346. ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0xa6, 0x2f);
  347. } else {
  348. ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0xa7, 0x2f);
  349. ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0xa6, 0x1f);
  350. }
  351. }
  352. void ast_set_sync_reg(struct drm_device *dev, struct drm_display_mode *mode,
  353. struct ast_vbios_mode_info *vbios_mode)
  354. {
  355. struct ast_private *ast = dev->dev_private;
  356. u8 jreg;
  357. jreg = ast_io_read8(ast, AST_IO_MISC_PORT_READ);
  358. jreg |= (vbios_mode->enh_table->flags & SyncNN);
  359. ast_io_write8(ast, AST_IO_MISC_PORT_WRITE, jreg);
  360. }
  361. bool ast_set_dac_reg(struct drm_crtc *crtc, struct drm_display_mode *mode,
  362. struct ast_vbios_mode_info *vbios_mode)
  363. {
  364. switch (crtc->fb->bits_per_pixel) {
  365. case 8:
  366. break;
  367. default:
  368. return false;
  369. }
  370. return true;
  371. }
  372. void ast_set_start_address_crt1(struct drm_crtc *crtc, unsigned offset)
  373. {
  374. struct ast_private *ast = crtc->dev->dev_private;
  375. u32 addr;
  376. addr = offset >> 2;
  377. ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x0d, (u8)(addr & 0xff));
  378. ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0x0c, (u8)((addr >> 8) & 0xff));
  379. ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0xaf, (u8)((addr >> 16) & 0xff));
  380. }
  381. static void ast_crtc_dpms(struct drm_crtc *crtc, int mode)
  382. {
  383. struct ast_private *ast = crtc->dev->dev_private;
  384. if (ast->chip == AST1180)
  385. return;
  386. switch (mode) {
  387. case DRM_MODE_DPMS_ON:
  388. case DRM_MODE_DPMS_STANDBY:
  389. case DRM_MODE_DPMS_SUSPEND:
  390. ast_set_index_reg_mask(ast, AST_IO_SEQ_PORT, 0x1, 0xdf, 0);
  391. ast_crtc_load_lut(crtc);
  392. break;
  393. case DRM_MODE_DPMS_OFF:
  394. ast_set_index_reg_mask(ast, AST_IO_SEQ_PORT, 0x1, 0xdf, 0x20);
  395. break;
  396. }
  397. }
  398. static bool ast_crtc_mode_fixup(struct drm_crtc *crtc,
  399. const struct drm_display_mode *mode,
  400. struct drm_display_mode *adjusted_mode)
  401. {
  402. return true;
  403. }
  404. /* ast is different - we will force move buffers out of VRAM */
  405. static int ast_crtc_do_set_base(struct drm_crtc *crtc,
  406. struct drm_framebuffer *fb,
  407. int x, int y, int atomic)
  408. {
  409. struct ast_private *ast = crtc->dev->dev_private;
  410. struct drm_gem_object *obj;
  411. struct ast_framebuffer *ast_fb;
  412. struct ast_bo *bo;
  413. int ret;
  414. u64 gpu_addr;
  415. /* push the previous fb to system ram */
  416. if (!atomic && fb) {
  417. ast_fb = to_ast_framebuffer(fb);
  418. obj = ast_fb->obj;
  419. bo = gem_to_ast_bo(obj);
  420. ret = ast_bo_reserve(bo, false);
  421. if (ret)
  422. return ret;
  423. ast_bo_push_sysram(bo);
  424. ast_bo_unreserve(bo);
  425. }
  426. ast_fb = to_ast_framebuffer(crtc->fb);
  427. obj = ast_fb->obj;
  428. bo = gem_to_ast_bo(obj);
  429. ret = ast_bo_reserve(bo, false);
  430. if (ret)
  431. return ret;
  432. ret = ast_bo_pin(bo, TTM_PL_FLAG_VRAM, &gpu_addr);
  433. if (ret) {
  434. ast_bo_unreserve(bo);
  435. return ret;
  436. }
  437. if (&ast->fbdev->afb == ast_fb) {
  438. /* if pushing console in kmap it */
  439. ret = ttm_bo_kmap(&bo->bo, 0, bo->bo.num_pages, &bo->kmap);
  440. if (ret)
  441. DRM_ERROR("failed to kmap fbcon\n");
  442. }
  443. ast_bo_unreserve(bo);
  444. ast_set_start_address_crt1(crtc, (u32)gpu_addr);
  445. return 0;
  446. }
  447. static int ast_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y,
  448. struct drm_framebuffer *old_fb)
  449. {
  450. return ast_crtc_do_set_base(crtc, old_fb, x, y, 0);
  451. }
  452. static int ast_crtc_mode_set(struct drm_crtc *crtc,
  453. struct drm_display_mode *mode,
  454. struct drm_display_mode *adjusted_mode,
  455. int x, int y,
  456. struct drm_framebuffer *old_fb)
  457. {
  458. struct drm_device *dev = crtc->dev;
  459. struct ast_private *ast = crtc->dev->dev_private;
  460. struct ast_vbios_mode_info vbios_mode;
  461. bool ret;
  462. if (ast->chip == AST1180) {
  463. DRM_ERROR("AST 1180 modesetting not supported\n");
  464. return -EINVAL;
  465. }
  466. ret = ast_get_vbios_mode_info(crtc, mode, adjusted_mode, &vbios_mode);
  467. if (ret == false)
  468. return -EINVAL;
  469. ast_open_key(ast);
  470. ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xa1, 0xff, 0x04);
  471. ast_set_std_reg(crtc, adjusted_mode, &vbios_mode);
  472. ast_set_crtc_reg(crtc, adjusted_mode, &vbios_mode);
  473. ast_set_offset_reg(crtc);
  474. ast_set_dclk_reg(dev, adjusted_mode, &vbios_mode);
  475. ast_set_ext_reg(crtc, adjusted_mode, &vbios_mode);
  476. ast_set_sync_reg(dev, adjusted_mode, &vbios_mode);
  477. ast_set_dac_reg(crtc, adjusted_mode, &vbios_mode);
  478. ast_crtc_mode_set_base(crtc, x, y, old_fb);
  479. return 0;
  480. }
  481. static void ast_crtc_disable(struct drm_crtc *crtc)
  482. {
  483. }
  484. static void ast_crtc_prepare(struct drm_crtc *crtc)
  485. {
  486. }
  487. static void ast_crtc_commit(struct drm_crtc *crtc)
  488. {
  489. struct ast_private *ast = crtc->dev->dev_private;
  490. ast_set_index_reg_mask(ast, AST_IO_SEQ_PORT, 0x1, 0xdf, 0);
  491. }
  492. static const struct drm_crtc_helper_funcs ast_crtc_helper_funcs = {
  493. .dpms = ast_crtc_dpms,
  494. .mode_fixup = ast_crtc_mode_fixup,
  495. .mode_set = ast_crtc_mode_set,
  496. .mode_set_base = ast_crtc_mode_set_base,
  497. .disable = ast_crtc_disable,
  498. .load_lut = ast_crtc_load_lut,
  499. .disable = ast_crtc_disable,
  500. .prepare = ast_crtc_prepare,
  501. .commit = ast_crtc_commit,
  502. };
  503. static void ast_crtc_reset(struct drm_crtc *crtc)
  504. {
  505. }
  506. static void ast_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
  507. u16 *blue, uint32_t start, uint32_t size)
  508. {
  509. struct ast_crtc *ast_crtc = to_ast_crtc(crtc);
  510. int end = (start + size > 256) ? 256 : start + size, i;
  511. /* userspace palettes are always correct as is */
  512. for (i = start; i < end; i++) {
  513. ast_crtc->lut_r[i] = red[i] >> 8;
  514. ast_crtc->lut_g[i] = green[i] >> 8;
  515. ast_crtc->lut_b[i] = blue[i] >> 8;
  516. }
  517. ast_crtc_load_lut(crtc);
  518. }
  519. static void ast_crtc_destroy(struct drm_crtc *crtc)
  520. {
  521. drm_crtc_cleanup(crtc);
  522. kfree(crtc);
  523. }
  524. static const struct drm_crtc_funcs ast_crtc_funcs = {
  525. .cursor_set = ast_cursor_set,
  526. .cursor_move = ast_cursor_move,
  527. .reset = ast_crtc_reset,
  528. .set_config = drm_crtc_helper_set_config,
  529. .gamma_set = ast_crtc_gamma_set,
  530. .destroy = ast_crtc_destroy,
  531. };
  532. int ast_crtc_init(struct drm_device *dev)
  533. {
  534. struct ast_crtc *crtc;
  535. int i;
  536. crtc = kzalloc(sizeof(struct ast_crtc), GFP_KERNEL);
  537. if (!crtc)
  538. return -ENOMEM;
  539. drm_crtc_init(dev, &crtc->base, &ast_crtc_funcs);
  540. drm_mode_crtc_set_gamma_size(&crtc->base, 256);
  541. drm_crtc_helper_add(&crtc->base, &ast_crtc_helper_funcs);
  542. for (i = 0; i < 256; i++) {
  543. crtc->lut_r[i] = i;
  544. crtc->lut_g[i] = i;
  545. crtc->lut_b[i] = i;
  546. }
  547. return 0;
  548. }
  549. static void ast_encoder_destroy(struct drm_encoder *encoder)
  550. {
  551. drm_encoder_cleanup(encoder);
  552. kfree(encoder);
  553. }
  554. static struct drm_encoder *ast_best_single_encoder(struct drm_connector *connector)
  555. {
  556. int enc_id = connector->encoder_ids[0];
  557. struct drm_mode_object *obj;
  558. struct drm_encoder *encoder;
  559. /* pick the encoder ids */
  560. if (enc_id) {
  561. obj = drm_mode_object_find(connector->dev, enc_id, DRM_MODE_OBJECT_ENCODER);
  562. if (!obj)
  563. return NULL;
  564. encoder = obj_to_encoder(obj);
  565. return encoder;
  566. }
  567. return NULL;
  568. }
  569. static const struct drm_encoder_funcs ast_enc_funcs = {
  570. .destroy = ast_encoder_destroy,
  571. };
  572. static void ast_encoder_dpms(struct drm_encoder *encoder, int mode)
  573. {
  574. }
  575. static bool ast_mode_fixup(struct drm_encoder *encoder,
  576. const struct drm_display_mode *mode,
  577. struct drm_display_mode *adjusted_mode)
  578. {
  579. return true;
  580. }
  581. static void ast_encoder_mode_set(struct drm_encoder *encoder,
  582. struct drm_display_mode *mode,
  583. struct drm_display_mode *adjusted_mode)
  584. {
  585. }
  586. static void ast_encoder_prepare(struct drm_encoder *encoder)
  587. {
  588. }
  589. static void ast_encoder_commit(struct drm_encoder *encoder)
  590. {
  591. }
  592. static const struct drm_encoder_helper_funcs ast_enc_helper_funcs = {
  593. .dpms = ast_encoder_dpms,
  594. .mode_fixup = ast_mode_fixup,
  595. .prepare = ast_encoder_prepare,
  596. .commit = ast_encoder_commit,
  597. .mode_set = ast_encoder_mode_set,
  598. };
  599. int ast_encoder_init(struct drm_device *dev)
  600. {
  601. struct ast_encoder *ast_encoder;
  602. ast_encoder = kzalloc(sizeof(struct ast_encoder), GFP_KERNEL);
  603. if (!ast_encoder)
  604. return -ENOMEM;
  605. drm_encoder_init(dev, &ast_encoder->base, &ast_enc_funcs,
  606. DRM_MODE_ENCODER_DAC);
  607. drm_encoder_helper_add(&ast_encoder->base, &ast_enc_helper_funcs);
  608. ast_encoder->base.possible_crtcs = 1;
  609. return 0;
  610. }
  611. static int ast_get_modes(struct drm_connector *connector)
  612. {
  613. struct ast_connector *ast_connector = to_ast_connector(connector);
  614. struct edid *edid;
  615. int ret;
  616. edid = drm_get_edid(connector, &ast_connector->i2c->adapter);
  617. if (edid) {
  618. drm_mode_connector_update_edid_property(&ast_connector->base, edid);
  619. ret = drm_add_edid_modes(connector, edid);
  620. kfree(edid);
  621. return ret;
  622. } else
  623. drm_mode_connector_update_edid_property(&ast_connector->base, NULL);
  624. return 0;
  625. }
  626. static int ast_mode_valid(struct drm_connector *connector,
  627. struct drm_display_mode *mode)
  628. {
  629. return MODE_OK;
  630. }
  631. static void ast_connector_destroy(struct drm_connector *connector)
  632. {
  633. struct ast_connector *ast_connector = to_ast_connector(connector);
  634. ast_i2c_destroy(ast_connector->i2c);
  635. drm_sysfs_connector_remove(connector);
  636. drm_connector_cleanup(connector);
  637. kfree(connector);
  638. }
  639. static enum drm_connector_status
  640. ast_connector_detect(struct drm_connector *connector, bool force)
  641. {
  642. return connector_status_connected;
  643. }
  644. static const struct drm_connector_helper_funcs ast_connector_helper_funcs = {
  645. .mode_valid = ast_mode_valid,
  646. .get_modes = ast_get_modes,
  647. .best_encoder = ast_best_single_encoder,
  648. };
  649. static const struct drm_connector_funcs ast_connector_funcs = {
  650. .dpms = drm_helper_connector_dpms,
  651. .detect = ast_connector_detect,
  652. .fill_modes = drm_helper_probe_single_connector_modes,
  653. .destroy = ast_connector_destroy,
  654. };
  655. int ast_connector_init(struct drm_device *dev)
  656. {
  657. struct ast_connector *ast_connector;
  658. struct drm_connector *connector;
  659. struct drm_encoder *encoder;
  660. ast_connector = kzalloc(sizeof(struct ast_connector), GFP_KERNEL);
  661. if (!ast_connector)
  662. return -ENOMEM;
  663. connector = &ast_connector->base;
  664. drm_connector_init(dev, connector, &ast_connector_funcs, DRM_MODE_CONNECTOR_VGA);
  665. drm_connector_helper_add(connector, &ast_connector_helper_funcs);
  666. connector->interlace_allowed = 0;
  667. connector->doublescan_allowed = 0;
  668. drm_sysfs_connector_add(connector);
  669. connector->polled = DRM_CONNECTOR_POLL_CONNECT;
  670. encoder = list_first_entry(&dev->mode_config.encoder_list, struct drm_encoder, head);
  671. drm_mode_connector_attach_encoder(connector, encoder);
  672. ast_connector->i2c = ast_i2c_create(dev);
  673. if (!ast_connector->i2c)
  674. DRM_ERROR("failed to add ddc bus for connector\n");
  675. return 0;
  676. }
  677. /* allocate cursor cache and pin at start of VRAM */
  678. int ast_cursor_init(struct drm_device *dev)
  679. {
  680. struct ast_private *ast = dev->dev_private;
  681. int size;
  682. int ret;
  683. struct drm_gem_object *obj;
  684. struct ast_bo *bo;
  685. uint64_t gpu_addr;
  686. size = (AST_HWC_SIZE + AST_HWC_SIGNATURE_SIZE) * AST_DEFAULT_HWC_NUM;
  687. ret = ast_gem_create(dev, size, true, &obj);
  688. if (ret)
  689. return ret;
  690. bo = gem_to_ast_bo(obj);
  691. ret = ast_bo_reserve(bo, false);
  692. if (unlikely(ret != 0))
  693. goto fail;
  694. ret = ast_bo_pin(bo, TTM_PL_FLAG_VRAM, &gpu_addr);
  695. ast_bo_unreserve(bo);
  696. if (ret)
  697. goto fail;
  698. /* kmap the object */
  699. ret = ttm_bo_kmap(&bo->bo, 0, bo->bo.num_pages, &ast->cache_kmap);
  700. if (ret)
  701. goto fail;
  702. ast->cursor_cache = obj;
  703. ast->cursor_cache_gpu_addr = gpu_addr;
  704. DRM_ERROR("pinned cursor cache at %llx\n", ast->cursor_cache_gpu_addr);
  705. return 0;
  706. fail:
  707. return ret;
  708. }
  709. void ast_cursor_fini(struct drm_device *dev)
  710. {
  711. struct ast_private *ast = dev->dev_private;
  712. ttm_bo_kunmap(&ast->cache_kmap);
  713. drm_gem_object_unreference_unlocked(ast->cursor_cache);
  714. }
  715. int ast_mode_init(struct drm_device *dev)
  716. {
  717. ast_cursor_init(dev);
  718. ast_crtc_init(dev);
  719. ast_encoder_init(dev);
  720. ast_connector_init(dev);
  721. return 0;
  722. }
  723. void ast_mode_fini(struct drm_device *dev)
  724. {
  725. ast_cursor_fini(dev);
  726. }
  727. static int get_clock(void *i2c_priv)
  728. {
  729. struct ast_i2c_chan *i2c = i2c_priv;
  730. struct ast_private *ast = i2c->dev->dev_private;
  731. uint32_t val;
  732. val = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0x10) >> 4;
  733. return val & 1 ? 1 : 0;
  734. }
  735. static int get_data(void *i2c_priv)
  736. {
  737. struct ast_i2c_chan *i2c = i2c_priv;
  738. struct ast_private *ast = i2c->dev->dev_private;
  739. uint32_t val;
  740. val = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0x20) >> 5;
  741. return val & 1 ? 1 : 0;
  742. }
  743. static void set_clock(void *i2c_priv, int clock)
  744. {
  745. struct ast_i2c_chan *i2c = i2c_priv;
  746. struct ast_private *ast = i2c->dev->dev_private;
  747. int i;
  748. u8 ujcrb7, jtemp;
  749. for (i = 0; i < 0x10000; i++) {
  750. ujcrb7 = ((clock & 0x01) ? 0 : 1);
  751. ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0xfe, ujcrb7);
  752. jtemp = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0x01);
  753. if (ujcrb7 == jtemp)
  754. break;
  755. }
  756. }
  757. static void set_data(void *i2c_priv, int data)
  758. {
  759. struct ast_i2c_chan *i2c = i2c_priv;
  760. struct ast_private *ast = i2c->dev->dev_private;
  761. int i;
  762. u8 ujcrb7, jtemp;
  763. for (i = 0; i < 0x10000; i++) {
  764. ujcrb7 = ((data & 0x01) ? 0 : 1) << 2;
  765. ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0xfb, ujcrb7);
  766. jtemp = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0x04);
  767. if (ujcrb7 == jtemp)
  768. break;
  769. }
  770. }
  771. static struct ast_i2c_chan *ast_i2c_create(struct drm_device *dev)
  772. {
  773. struct ast_i2c_chan *i2c;
  774. int ret;
  775. i2c = kzalloc(sizeof(struct ast_i2c_chan), GFP_KERNEL);
  776. if (!i2c)
  777. return NULL;
  778. i2c->adapter.owner = THIS_MODULE;
  779. i2c->adapter.class = I2C_CLASS_DDC;
  780. i2c->adapter.dev.parent = &dev->pdev->dev;
  781. i2c->dev = dev;
  782. i2c_set_adapdata(&i2c->adapter, i2c);
  783. snprintf(i2c->adapter.name, sizeof(i2c->adapter.name),
  784. "AST i2c bit bus");
  785. i2c->adapter.algo_data = &i2c->bit;
  786. i2c->bit.udelay = 20;
  787. i2c->bit.timeout = 2;
  788. i2c->bit.data = i2c;
  789. i2c->bit.setsda = set_data;
  790. i2c->bit.setscl = set_clock;
  791. i2c->bit.getsda = get_data;
  792. i2c->bit.getscl = get_clock;
  793. ret = i2c_bit_add_bus(&i2c->adapter);
  794. if (ret) {
  795. DRM_ERROR("Failed to register bit i2c\n");
  796. goto out_free;
  797. }
  798. return i2c;
  799. out_free:
  800. kfree(i2c);
  801. return NULL;
  802. }
  803. static void ast_i2c_destroy(struct ast_i2c_chan *i2c)
  804. {
  805. if (!i2c)
  806. return;
  807. i2c_del_adapter(&i2c->adapter);
  808. kfree(i2c);
  809. }
  810. void ast_show_cursor(struct drm_crtc *crtc)
  811. {
  812. struct ast_private *ast = crtc->dev->dev_private;
  813. u8 jreg;
  814. jreg = 0x2;
  815. /* enable ARGB cursor */
  816. jreg |= 1;
  817. ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xcb, 0xfc, jreg);
  818. }
  819. void ast_hide_cursor(struct drm_crtc *crtc)
  820. {
  821. struct ast_private *ast = crtc->dev->dev_private;
  822. ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xcb, 0xfc, 0x00);
  823. }
  824. static u32 copy_cursor_image(u8 *src, u8 *dst, int width, int height)
  825. {
  826. union {
  827. u32 ul;
  828. u8 b[4];
  829. } srcdata32[2], data32;
  830. union {
  831. u16 us;
  832. u8 b[2];
  833. } data16;
  834. u32 csum = 0;
  835. s32 alpha_dst_delta, last_alpha_dst_delta;
  836. u8 *srcxor, *dstxor;
  837. int i, j;
  838. u32 per_pixel_copy, two_pixel_copy;
  839. alpha_dst_delta = AST_MAX_HWC_WIDTH << 1;
  840. last_alpha_dst_delta = alpha_dst_delta - (width << 1);
  841. srcxor = src;
  842. dstxor = (u8 *)dst + last_alpha_dst_delta + (AST_MAX_HWC_HEIGHT - height) * alpha_dst_delta;
  843. per_pixel_copy = width & 1;
  844. two_pixel_copy = width >> 1;
  845. for (j = 0; j < height; j++) {
  846. for (i = 0; i < two_pixel_copy; i++) {
  847. srcdata32[0].ul = *((u32 *)srcxor) & 0xf0f0f0f0;
  848. srcdata32[1].ul = *((u32 *)(srcxor + 4)) & 0xf0f0f0f0;
  849. data32.b[0] = srcdata32[0].b[1] | (srcdata32[0].b[0] >> 4);
  850. data32.b[1] = srcdata32[0].b[3] | (srcdata32[0].b[2] >> 4);
  851. data32.b[2] = srcdata32[0].b[1] | (srcdata32[1].b[0] >> 4);
  852. data32.b[3] = srcdata32[0].b[3] | (srcdata32[1].b[2] >> 4);
  853. writel(data32.ul, dstxor);
  854. csum += data32.ul;
  855. dstxor += 4;
  856. srcxor += 8;
  857. }
  858. for (i = 0; i < per_pixel_copy; i++) {
  859. srcdata32[0].ul = *((u32 *)srcxor) & 0xf0f0f0f0;
  860. data16.b[0] = srcdata32[0].b[1] | (srcdata32[0].b[0] >> 4);
  861. data16.b[1] = srcdata32[0].b[3] | (srcdata32[0].b[2] >> 4);
  862. writew(data16.us, dstxor);
  863. csum += (u32)data16.us;
  864. dstxor += 2;
  865. srcxor += 4;
  866. }
  867. dstxor += last_alpha_dst_delta;
  868. }
  869. return csum;
  870. }
  871. static int ast_cursor_set(struct drm_crtc *crtc,
  872. struct drm_file *file_priv,
  873. uint32_t handle,
  874. uint32_t width,
  875. uint32_t height)
  876. {
  877. struct ast_private *ast = crtc->dev->dev_private;
  878. struct ast_crtc *ast_crtc = to_ast_crtc(crtc);
  879. struct drm_gem_object *obj;
  880. struct ast_bo *bo;
  881. uint64_t gpu_addr;
  882. u32 csum;
  883. int ret;
  884. struct ttm_bo_kmap_obj uobj_map;
  885. u8 *src, *dst;
  886. bool src_isiomem, dst_isiomem;
  887. if (!handle) {
  888. ast_hide_cursor(crtc);
  889. return 0;
  890. }
  891. if (width > AST_MAX_HWC_WIDTH || height > AST_MAX_HWC_HEIGHT)
  892. return -EINVAL;
  893. obj = drm_gem_object_lookup(crtc->dev, file_priv, handle);
  894. if (!obj) {
  895. DRM_ERROR("Cannot find cursor object %x for crtc\n", handle);
  896. return -ENOENT;
  897. }
  898. bo = gem_to_ast_bo(obj);
  899. ret = ast_bo_reserve(bo, false);
  900. if (ret)
  901. goto fail;
  902. ret = ttm_bo_kmap(&bo->bo, 0, bo->bo.num_pages, &uobj_map);
  903. src = ttm_kmap_obj_virtual(&uobj_map, &src_isiomem);
  904. dst = ttm_kmap_obj_virtual(&ast->cache_kmap, &dst_isiomem);
  905. if (src_isiomem == true)
  906. DRM_ERROR("src cursor bo should be in main memory\n");
  907. if (dst_isiomem == false)
  908. DRM_ERROR("dst bo should be in VRAM\n");
  909. dst += (AST_HWC_SIZE + AST_HWC_SIGNATURE_SIZE)*ast->next_cursor;
  910. /* do data transfer to cursor cache */
  911. csum = copy_cursor_image(src, dst, width, height);
  912. /* write checksum + signature */
  913. ttm_bo_kunmap(&uobj_map);
  914. ast_bo_unreserve(bo);
  915. {
  916. u8 *dst = (u8 *)ast->cache_kmap.virtual + (AST_HWC_SIZE + AST_HWC_SIGNATURE_SIZE)*ast->next_cursor + AST_HWC_SIZE;
  917. writel(csum, dst);
  918. writel(width, dst + AST_HWC_SIGNATURE_SizeX);
  919. writel(height, dst + AST_HWC_SIGNATURE_SizeY);
  920. writel(0, dst + AST_HWC_SIGNATURE_HOTSPOTX);
  921. writel(0, dst + AST_HWC_SIGNATURE_HOTSPOTY);
  922. /* set pattern offset */
  923. gpu_addr = ast->cursor_cache_gpu_addr;
  924. gpu_addr += (AST_HWC_SIZE + AST_HWC_SIGNATURE_SIZE)*ast->next_cursor;
  925. gpu_addr >>= 3;
  926. ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0xc8, gpu_addr & 0xff);
  927. ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0xc9, (gpu_addr >> 8) & 0xff);
  928. ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0xca, (gpu_addr >> 16) & 0xff);
  929. }
  930. ast_crtc->cursor_width = width;
  931. ast_crtc->cursor_height = height;
  932. ast_crtc->offset_x = AST_MAX_HWC_WIDTH - width;
  933. ast_crtc->offset_y = AST_MAX_HWC_WIDTH - height;
  934. ast->next_cursor = (ast->next_cursor + 1) % AST_DEFAULT_HWC_NUM;
  935. ast_show_cursor(crtc);
  936. drm_gem_object_unreference_unlocked(obj);
  937. return 0;
  938. fail:
  939. drm_gem_object_unreference_unlocked(obj);
  940. return ret;
  941. }
  942. static int ast_cursor_move(struct drm_crtc *crtc,
  943. int x, int y)
  944. {
  945. struct ast_crtc *ast_crtc = to_ast_crtc(crtc);
  946. struct ast_private *ast = crtc->dev->dev_private;
  947. int x_offset, y_offset;
  948. u8 *sig;
  949. sig = (u8 *)ast->cache_kmap.virtual + (AST_HWC_SIZE + AST_HWC_SIGNATURE_SIZE)*ast->next_cursor + AST_HWC_SIZE;
  950. writel(x, sig + AST_HWC_SIGNATURE_X);
  951. writel(y, sig + AST_HWC_SIGNATURE_Y);
  952. x_offset = ast_crtc->offset_x;
  953. y_offset = ast_crtc->offset_y;
  954. if (x < 0) {
  955. x_offset = (-x) + ast_crtc->offset_x;
  956. x = 0;
  957. }
  958. if (y < 0) {
  959. y_offset = (-y) + ast_crtc->offset_y;
  960. y = 0;
  961. }
  962. ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0xc2, x_offset);
  963. ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0xc3, y_offset);
  964. ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0xc4, (x & 0xff));
  965. ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0xc5, ((x >> 8) & 0x0f));
  966. ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0xc6, (y & 0xff));
  967. ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0xc7, ((y >> 8) & 0x07));
  968. /* dummy write to fire HWC */
  969. ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xCB, 0xFF, 0x00);
  970. return 0;
  971. }