ast_mode.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160
  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. return ret;
  621. } else
  622. drm_mode_connector_update_edid_property(&ast_connector->base, NULL);
  623. return 0;
  624. }
  625. static int ast_mode_valid(struct drm_connector *connector,
  626. struct drm_display_mode *mode)
  627. {
  628. return MODE_OK;
  629. }
  630. static void ast_connector_destroy(struct drm_connector *connector)
  631. {
  632. struct ast_connector *ast_connector = to_ast_connector(connector);
  633. ast_i2c_destroy(ast_connector->i2c);
  634. drm_sysfs_connector_remove(connector);
  635. drm_connector_cleanup(connector);
  636. kfree(connector);
  637. }
  638. static enum drm_connector_status
  639. ast_connector_detect(struct drm_connector *connector, bool force)
  640. {
  641. return connector_status_connected;
  642. }
  643. static const struct drm_connector_helper_funcs ast_connector_helper_funcs = {
  644. .mode_valid = ast_mode_valid,
  645. .get_modes = ast_get_modes,
  646. .best_encoder = ast_best_single_encoder,
  647. };
  648. static const struct drm_connector_funcs ast_connector_funcs = {
  649. .dpms = drm_helper_connector_dpms,
  650. .detect = ast_connector_detect,
  651. .fill_modes = drm_helper_probe_single_connector_modes,
  652. .destroy = ast_connector_destroy,
  653. };
  654. int ast_connector_init(struct drm_device *dev)
  655. {
  656. struct ast_connector *ast_connector;
  657. struct drm_connector *connector;
  658. struct drm_encoder *encoder;
  659. ast_connector = kzalloc(sizeof(struct ast_connector), GFP_KERNEL);
  660. if (!ast_connector)
  661. return -ENOMEM;
  662. connector = &ast_connector->base;
  663. drm_connector_init(dev, connector, &ast_connector_funcs, DRM_MODE_CONNECTOR_VGA);
  664. drm_connector_helper_add(connector, &ast_connector_helper_funcs);
  665. connector->interlace_allowed = 0;
  666. connector->doublescan_allowed = 0;
  667. drm_sysfs_connector_add(connector);
  668. connector->polled = DRM_CONNECTOR_POLL_CONNECT;
  669. encoder = list_first_entry(&dev->mode_config.encoder_list, struct drm_encoder, head);
  670. drm_mode_connector_attach_encoder(connector, encoder);
  671. ast_connector->i2c = ast_i2c_create(dev);
  672. if (!ast_connector->i2c)
  673. DRM_ERROR("failed to add ddc bus for connector\n");
  674. return 0;
  675. }
  676. /* allocate cursor cache and pin at start of VRAM */
  677. int ast_cursor_init(struct drm_device *dev)
  678. {
  679. struct ast_private *ast = dev->dev_private;
  680. int size;
  681. int ret;
  682. struct drm_gem_object *obj;
  683. struct ast_bo *bo;
  684. uint64_t gpu_addr;
  685. size = (AST_HWC_SIZE + AST_HWC_SIGNATURE_SIZE) * AST_DEFAULT_HWC_NUM;
  686. ret = ast_gem_create(dev, size, true, &obj);
  687. if (ret)
  688. return ret;
  689. bo = gem_to_ast_bo(obj);
  690. ret = ast_bo_reserve(bo, false);
  691. if (unlikely(ret != 0))
  692. goto fail;
  693. ret = ast_bo_pin(bo, TTM_PL_FLAG_VRAM, &gpu_addr);
  694. ast_bo_unreserve(bo);
  695. if (ret)
  696. goto fail;
  697. /* kmap the object */
  698. ret = ttm_bo_kmap(&bo->bo, 0, bo->bo.num_pages, &ast->cache_kmap);
  699. if (ret)
  700. goto fail;
  701. ast->cursor_cache = obj;
  702. ast->cursor_cache_gpu_addr = gpu_addr;
  703. DRM_DEBUG_KMS("pinned cursor cache at %llx\n", ast->cursor_cache_gpu_addr);
  704. return 0;
  705. fail:
  706. return ret;
  707. }
  708. void ast_cursor_fini(struct drm_device *dev)
  709. {
  710. struct ast_private *ast = dev->dev_private;
  711. ttm_bo_kunmap(&ast->cache_kmap);
  712. drm_gem_object_unreference_unlocked(ast->cursor_cache);
  713. }
  714. int ast_mode_init(struct drm_device *dev)
  715. {
  716. ast_cursor_init(dev);
  717. ast_crtc_init(dev);
  718. ast_encoder_init(dev);
  719. ast_connector_init(dev);
  720. return 0;
  721. }
  722. void ast_mode_fini(struct drm_device *dev)
  723. {
  724. ast_cursor_fini(dev);
  725. }
  726. static int get_clock(void *i2c_priv)
  727. {
  728. struct ast_i2c_chan *i2c = i2c_priv;
  729. struct ast_private *ast = i2c->dev->dev_private;
  730. uint32_t val;
  731. val = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0x10) >> 4;
  732. return val & 1 ? 1 : 0;
  733. }
  734. static int get_data(void *i2c_priv)
  735. {
  736. struct ast_i2c_chan *i2c = i2c_priv;
  737. struct ast_private *ast = i2c->dev->dev_private;
  738. uint32_t val;
  739. val = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0x20) >> 5;
  740. return val & 1 ? 1 : 0;
  741. }
  742. static void set_clock(void *i2c_priv, int clock)
  743. {
  744. struct ast_i2c_chan *i2c = i2c_priv;
  745. struct ast_private *ast = i2c->dev->dev_private;
  746. int i;
  747. u8 ujcrb7, jtemp;
  748. for (i = 0; i < 0x10000; i++) {
  749. ujcrb7 = ((clock & 0x01) ? 0 : 1);
  750. ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0xfe, ujcrb7);
  751. jtemp = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0x01);
  752. if (ujcrb7 == jtemp)
  753. break;
  754. }
  755. }
  756. static void set_data(void *i2c_priv, int data)
  757. {
  758. struct ast_i2c_chan *i2c = i2c_priv;
  759. struct ast_private *ast = i2c->dev->dev_private;
  760. int i;
  761. u8 ujcrb7, jtemp;
  762. for (i = 0; i < 0x10000; i++) {
  763. ujcrb7 = ((data & 0x01) ? 0 : 1) << 2;
  764. ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0xfb, ujcrb7);
  765. jtemp = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0x04);
  766. if (ujcrb7 == jtemp)
  767. break;
  768. }
  769. }
  770. static struct ast_i2c_chan *ast_i2c_create(struct drm_device *dev)
  771. {
  772. struct ast_i2c_chan *i2c;
  773. int ret;
  774. i2c = kzalloc(sizeof(struct ast_i2c_chan), GFP_KERNEL);
  775. if (!i2c)
  776. return NULL;
  777. i2c->adapter.owner = THIS_MODULE;
  778. i2c->adapter.class = I2C_CLASS_DDC;
  779. i2c->adapter.dev.parent = &dev->pdev->dev;
  780. i2c->dev = dev;
  781. i2c_set_adapdata(&i2c->adapter, i2c);
  782. snprintf(i2c->adapter.name, sizeof(i2c->adapter.name),
  783. "AST i2c bit bus");
  784. i2c->adapter.algo_data = &i2c->bit;
  785. i2c->bit.udelay = 20;
  786. i2c->bit.timeout = 2;
  787. i2c->bit.data = i2c;
  788. i2c->bit.setsda = set_data;
  789. i2c->bit.setscl = set_clock;
  790. i2c->bit.getsda = get_data;
  791. i2c->bit.getscl = get_clock;
  792. ret = i2c_bit_add_bus(&i2c->adapter);
  793. if (ret) {
  794. DRM_ERROR("Failed to register bit i2c\n");
  795. goto out_free;
  796. }
  797. return i2c;
  798. out_free:
  799. kfree(i2c);
  800. return NULL;
  801. }
  802. static void ast_i2c_destroy(struct ast_i2c_chan *i2c)
  803. {
  804. if (!i2c)
  805. return;
  806. i2c_del_adapter(&i2c->adapter);
  807. kfree(i2c);
  808. }
  809. void ast_show_cursor(struct drm_crtc *crtc)
  810. {
  811. struct ast_private *ast = crtc->dev->dev_private;
  812. u8 jreg;
  813. jreg = 0x2;
  814. /* enable ARGB cursor */
  815. jreg |= 1;
  816. ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xcb, 0xfc, jreg);
  817. }
  818. void ast_hide_cursor(struct drm_crtc *crtc)
  819. {
  820. struct ast_private *ast = crtc->dev->dev_private;
  821. ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xcb, 0xfc, 0x00);
  822. }
  823. static u32 copy_cursor_image(u8 *src, u8 *dst, int width, int height)
  824. {
  825. union {
  826. u32 ul;
  827. u8 b[4];
  828. } srcdata32[2], data32;
  829. union {
  830. u16 us;
  831. u8 b[2];
  832. } data16;
  833. u32 csum = 0;
  834. s32 alpha_dst_delta, last_alpha_dst_delta;
  835. u8 *srcxor, *dstxor;
  836. int i, j;
  837. u32 per_pixel_copy, two_pixel_copy;
  838. alpha_dst_delta = AST_MAX_HWC_WIDTH << 1;
  839. last_alpha_dst_delta = alpha_dst_delta - (width << 1);
  840. srcxor = src;
  841. dstxor = (u8 *)dst + last_alpha_dst_delta + (AST_MAX_HWC_HEIGHT - height) * alpha_dst_delta;
  842. per_pixel_copy = width & 1;
  843. two_pixel_copy = width >> 1;
  844. for (j = 0; j < height; j++) {
  845. for (i = 0; i < two_pixel_copy; i++) {
  846. srcdata32[0].ul = *((u32 *)srcxor) & 0xf0f0f0f0;
  847. srcdata32[1].ul = *((u32 *)(srcxor + 4)) & 0xf0f0f0f0;
  848. data32.b[0] = srcdata32[0].b[1] | (srcdata32[0].b[0] >> 4);
  849. data32.b[1] = srcdata32[0].b[3] | (srcdata32[0].b[2] >> 4);
  850. data32.b[2] = srcdata32[0].b[1] | (srcdata32[1].b[0] >> 4);
  851. data32.b[3] = srcdata32[0].b[3] | (srcdata32[1].b[2] >> 4);
  852. writel(data32.ul, dstxor);
  853. csum += data32.ul;
  854. dstxor += 4;
  855. srcxor += 8;
  856. }
  857. for (i = 0; i < per_pixel_copy; i++) {
  858. srcdata32[0].ul = *((u32 *)srcxor) & 0xf0f0f0f0;
  859. data16.b[0] = srcdata32[0].b[1] | (srcdata32[0].b[0] >> 4);
  860. data16.b[1] = srcdata32[0].b[3] | (srcdata32[0].b[2] >> 4);
  861. writew(data16.us, dstxor);
  862. csum += (u32)data16.us;
  863. dstxor += 2;
  864. srcxor += 4;
  865. }
  866. dstxor += last_alpha_dst_delta;
  867. }
  868. return csum;
  869. }
  870. static int ast_cursor_set(struct drm_crtc *crtc,
  871. struct drm_file *file_priv,
  872. uint32_t handle,
  873. uint32_t width,
  874. uint32_t height)
  875. {
  876. struct ast_private *ast = crtc->dev->dev_private;
  877. struct ast_crtc *ast_crtc = to_ast_crtc(crtc);
  878. struct drm_gem_object *obj;
  879. struct ast_bo *bo;
  880. uint64_t gpu_addr;
  881. u32 csum;
  882. int ret;
  883. struct ttm_bo_kmap_obj uobj_map;
  884. u8 *src, *dst;
  885. bool src_isiomem, dst_isiomem;
  886. if (!handle) {
  887. ast_hide_cursor(crtc);
  888. return 0;
  889. }
  890. if (width > AST_MAX_HWC_WIDTH || height > AST_MAX_HWC_HEIGHT)
  891. return -EINVAL;
  892. obj = drm_gem_object_lookup(crtc->dev, file_priv, handle);
  893. if (!obj) {
  894. DRM_ERROR("Cannot find cursor object %x for crtc\n", handle);
  895. return -ENOENT;
  896. }
  897. bo = gem_to_ast_bo(obj);
  898. ret = ast_bo_reserve(bo, false);
  899. if (ret)
  900. goto fail;
  901. ret = ttm_bo_kmap(&bo->bo, 0, bo->bo.num_pages, &uobj_map);
  902. src = ttm_kmap_obj_virtual(&uobj_map, &src_isiomem);
  903. dst = ttm_kmap_obj_virtual(&ast->cache_kmap, &dst_isiomem);
  904. if (src_isiomem == true)
  905. DRM_ERROR("src cursor bo should be in main memory\n");
  906. if (dst_isiomem == false)
  907. DRM_ERROR("dst bo should be in VRAM\n");
  908. dst += (AST_HWC_SIZE + AST_HWC_SIGNATURE_SIZE)*ast->next_cursor;
  909. /* do data transfer to cursor cache */
  910. csum = copy_cursor_image(src, dst, width, height);
  911. /* write checksum + signature */
  912. ttm_bo_kunmap(&uobj_map);
  913. ast_bo_unreserve(bo);
  914. {
  915. u8 *dst = (u8 *)ast->cache_kmap.virtual + (AST_HWC_SIZE + AST_HWC_SIGNATURE_SIZE)*ast->next_cursor + AST_HWC_SIZE;
  916. writel(csum, dst);
  917. writel(width, dst + AST_HWC_SIGNATURE_SizeX);
  918. writel(height, dst + AST_HWC_SIGNATURE_SizeY);
  919. writel(0, dst + AST_HWC_SIGNATURE_HOTSPOTX);
  920. writel(0, dst + AST_HWC_SIGNATURE_HOTSPOTY);
  921. /* set pattern offset */
  922. gpu_addr = ast->cursor_cache_gpu_addr;
  923. gpu_addr += (AST_HWC_SIZE + AST_HWC_SIGNATURE_SIZE)*ast->next_cursor;
  924. gpu_addr >>= 3;
  925. ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0xc8, gpu_addr & 0xff);
  926. ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0xc9, (gpu_addr >> 8) & 0xff);
  927. ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0xca, (gpu_addr >> 16) & 0xff);
  928. }
  929. ast_crtc->cursor_width = width;
  930. ast_crtc->cursor_height = height;
  931. ast_crtc->offset_x = AST_MAX_HWC_WIDTH - width;
  932. ast_crtc->offset_y = AST_MAX_HWC_WIDTH - height;
  933. ast->next_cursor = (ast->next_cursor + 1) % AST_DEFAULT_HWC_NUM;
  934. ast_show_cursor(crtc);
  935. drm_gem_object_unreference_unlocked(obj);
  936. return 0;
  937. fail:
  938. drm_gem_object_unreference_unlocked(obj);
  939. return ret;
  940. }
  941. static int ast_cursor_move(struct drm_crtc *crtc,
  942. int x, int y)
  943. {
  944. struct ast_crtc *ast_crtc = to_ast_crtc(crtc);
  945. struct ast_private *ast = crtc->dev->dev_private;
  946. int x_offset, y_offset;
  947. u8 *sig;
  948. sig = (u8 *)ast->cache_kmap.virtual + (AST_HWC_SIZE + AST_HWC_SIGNATURE_SIZE)*ast->next_cursor + AST_HWC_SIZE;
  949. writel(x, sig + AST_HWC_SIGNATURE_X);
  950. writel(y, sig + AST_HWC_SIGNATURE_Y);
  951. x_offset = ast_crtc->offset_x;
  952. y_offset = ast_crtc->offset_y;
  953. if (x < 0) {
  954. x_offset = (-x) + ast_crtc->offset_x;
  955. x = 0;
  956. }
  957. if (y < 0) {
  958. y_offset = (-y) + ast_crtc->offset_y;
  959. y = 0;
  960. }
  961. ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0xc2, x_offset);
  962. ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0xc3, y_offset);
  963. ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0xc4, (x & 0xff));
  964. ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0xc5, ((x >> 8) & 0x0f));
  965. ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0xc6, (y & 0xff));
  966. ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0xc7, ((y >> 8) & 0x07));
  967. /* dummy write to fire HWC */
  968. ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xCB, 0xFF, 0x00);
  969. return 0;
  970. }