psb_irq.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. /**************************************************************************
  2. * Copyright (c) 2007, Intel Corporation.
  3. * All Rights Reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  17. *
  18. * Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
  19. * develop this driver.
  20. *
  21. **************************************************************************/
  22. /*
  23. */
  24. #include <drm/drmP.h>
  25. #include "psb_drv.h"
  26. #include "psb_reg.h"
  27. #include "psb_intel_reg.h"
  28. #include "power.h"
  29. #include "psb_irq.h"
  30. #include "mdfld_output.h"
  31. /*
  32. * inline functions
  33. */
  34. static inline u32
  35. psb_pipestat(int pipe)
  36. {
  37. if (pipe == 0)
  38. return PIPEASTAT;
  39. if (pipe == 1)
  40. return PIPEBSTAT;
  41. if (pipe == 2)
  42. return PIPECSTAT;
  43. BUG();
  44. }
  45. static inline u32
  46. mid_pipe_event(int pipe)
  47. {
  48. if (pipe == 0)
  49. return _PSB_PIPEA_EVENT_FLAG;
  50. if (pipe == 1)
  51. return _MDFLD_PIPEB_EVENT_FLAG;
  52. if (pipe == 2)
  53. return _MDFLD_PIPEC_EVENT_FLAG;
  54. BUG();
  55. }
  56. static inline u32
  57. mid_pipe_vsync(int pipe)
  58. {
  59. if (pipe == 0)
  60. return _PSB_VSYNC_PIPEA_FLAG;
  61. if (pipe == 1)
  62. return _PSB_VSYNC_PIPEB_FLAG;
  63. if (pipe == 2)
  64. return _MDFLD_PIPEC_VBLANK_FLAG;
  65. BUG();
  66. }
  67. static inline u32
  68. mid_pipeconf(int pipe)
  69. {
  70. if (pipe == 0)
  71. return PIPEACONF;
  72. if (pipe == 1)
  73. return PIPEBCONF;
  74. if (pipe == 2)
  75. return PIPECCONF;
  76. BUG();
  77. }
  78. void
  79. psb_enable_pipestat(struct drm_psb_private *dev_priv, int pipe, u32 mask)
  80. {
  81. if ((dev_priv->pipestat[pipe] & mask) != mask) {
  82. u32 reg = psb_pipestat(pipe);
  83. dev_priv->pipestat[pipe] |= mask;
  84. /* Enable the interrupt, clear any pending status */
  85. if (gma_power_begin(dev_priv->dev, false)) {
  86. u32 writeVal = PSB_RVDC32(reg);
  87. writeVal |= (mask | (mask >> 16));
  88. PSB_WVDC32(writeVal, reg);
  89. (void) PSB_RVDC32(reg);
  90. gma_power_end(dev_priv->dev);
  91. }
  92. }
  93. }
  94. void
  95. psb_disable_pipestat(struct drm_psb_private *dev_priv, int pipe, u32 mask)
  96. {
  97. if ((dev_priv->pipestat[pipe] & mask) != 0) {
  98. u32 reg = psb_pipestat(pipe);
  99. dev_priv->pipestat[pipe] &= ~mask;
  100. if (gma_power_begin(dev_priv->dev, false)) {
  101. u32 writeVal = PSB_RVDC32(reg);
  102. writeVal &= ~mask;
  103. PSB_WVDC32(writeVal, reg);
  104. (void) PSB_RVDC32(reg);
  105. gma_power_end(dev_priv->dev);
  106. }
  107. }
  108. }
  109. static void mid_enable_pipe_event(struct drm_psb_private *dev_priv, int pipe)
  110. {
  111. if (gma_power_begin(dev_priv->dev, false)) {
  112. u32 pipe_event = mid_pipe_event(pipe);
  113. dev_priv->vdc_irq_mask |= pipe_event;
  114. PSB_WVDC32(~dev_priv->vdc_irq_mask, PSB_INT_MASK_R);
  115. PSB_WVDC32(dev_priv->vdc_irq_mask, PSB_INT_ENABLE_R);
  116. gma_power_end(dev_priv->dev);
  117. }
  118. }
  119. static void mid_disable_pipe_event(struct drm_psb_private *dev_priv, int pipe)
  120. {
  121. if (dev_priv->pipestat[pipe] == 0) {
  122. if (gma_power_begin(dev_priv->dev, false)) {
  123. u32 pipe_event = mid_pipe_event(pipe);
  124. dev_priv->vdc_irq_mask &= ~pipe_event;
  125. PSB_WVDC32(~dev_priv->vdc_irq_mask, PSB_INT_MASK_R);
  126. PSB_WVDC32(dev_priv->vdc_irq_mask, PSB_INT_ENABLE_R);
  127. gma_power_end(dev_priv->dev);
  128. }
  129. }
  130. }
  131. /**
  132. * Display controller interrupt handler for pipe event.
  133. *
  134. */
  135. static void mid_pipe_event_handler(struct drm_device *dev, int pipe)
  136. {
  137. struct drm_psb_private *dev_priv =
  138. (struct drm_psb_private *) dev->dev_private;
  139. uint32_t pipe_stat_val = 0;
  140. uint32_t pipe_stat_reg = psb_pipestat(pipe);
  141. uint32_t pipe_enable = dev_priv->pipestat[pipe];
  142. uint32_t pipe_status = dev_priv->pipestat[pipe] >> 16;
  143. uint32_t pipe_clear;
  144. uint32_t i = 0;
  145. spin_lock(&dev_priv->irqmask_lock);
  146. pipe_stat_val = PSB_RVDC32(pipe_stat_reg);
  147. pipe_stat_val &= pipe_enable | pipe_status;
  148. pipe_stat_val &= pipe_stat_val >> 16;
  149. spin_unlock(&dev_priv->irqmask_lock);
  150. /* Clear the 2nd level interrupt status bits
  151. * Sometimes the bits are very sticky so we repeat until they unstick */
  152. for (i = 0; i < 0xffff; i++) {
  153. PSB_WVDC32(PSB_RVDC32(pipe_stat_reg), pipe_stat_reg);
  154. pipe_clear = PSB_RVDC32(pipe_stat_reg) & pipe_status;
  155. if (pipe_clear == 0)
  156. break;
  157. }
  158. if (pipe_clear)
  159. dev_err(dev->dev,
  160. "%s, can't clear status bits for pipe %d, its value = 0x%x.\n",
  161. __func__, pipe, PSB_RVDC32(pipe_stat_reg));
  162. if (pipe_stat_val & PIPE_VBLANK_STATUS)
  163. drm_handle_vblank(dev, pipe);
  164. if (pipe_stat_val & PIPE_TE_STATUS)
  165. drm_handle_vblank(dev, pipe);
  166. }
  167. /*
  168. * Display controller interrupt handler.
  169. */
  170. static void psb_vdc_interrupt(struct drm_device *dev, uint32_t vdc_stat)
  171. {
  172. if (vdc_stat & _PSB_VSYNC_PIPEA_FLAG)
  173. mid_pipe_event_handler(dev, 0);
  174. if (vdc_stat & _PSB_VSYNC_PIPEB_FLAG)
  175. mid_pipe_event_handler(dev, 1);
  176. }
  177. irqreturn_t psb_irq_handler(DRM_IRQ_ARGS)
  178. {
  179. struct drm_device *dev = (struct drm_device *) arg;
  180. struct drm_psb_private *dev_priv =
  181. (struct drm_psb_private *) dev->dev_private;
  182. uint32_t vdc_stat, dsp_int = 0, sgx_int = 0;
  183. int handled = 0;
  184. spin_lock(&dev_priv->irqmask_lock);
  185. vdc_stat = PSB_RVDC32(PSB_INT_IDENTITY_R);
  186. if (vdc_stat & _PSB_PIPE_EVENT_FLAG)
  187. dsp_int = 1;
  188. /* FIXME: Handle Medfield
  189. if (vdc_stat & _MDFLD_DISP_ALL_IRQ_FLAG)
  190. dsp_int = 1;
  191. */
  192. if (vdc_stat & _PSB_IRQ_SGX_FLAG)
  193. sgx_int = 1;
  194. vdc_stat &= dev_priv->vdc_irq_mask;
  195. spin_unlock(&dev_priv->irqmask_lock);
  196. if (dsp_int && gma_power_is_on(dev)) {
  197. psb_vdc_interrupt(dev, vdc_stat);
  198. handled = 1;
  199. }
  200. if (sgx_int) {
  201. /* Not expected - we have it masked, shut it up */
  202. u32 s, s2;
  203. s = PSB_RSGX32(PSB_CR_EVENT_STATUS);
  204. s2 = PSB_RSGX32(PSB_CR_EVENT_STATUS2);
  205. PSB_WSGX32(s, PSB_CR_EVENT_HOST_CLEAR);
  206. PSB_WSGX32(s2, PSB_CR_EVENT_HOST_CLEAR2);
  207. /* if s & _PSB_CE_TWOD_COMPLETE we have 2D done but
  208. we may as well poll even if we add that ! */
  209. handled = 1;
  210. }
  211. PSB_WVDC32(vdc_stat, PSB_INT_IDENTITY_R);
  212. (void) PSB_RVDC32(PSB_INT_IDENTITY_R);
  213. DRM_READMEMORYBARRIER();
  214. if (!handled)
  215. return IRQ_NONE;
  216. return IRQ_HANDLED;
  217. }
  218. void psb_irq_preinstall(struct drm_device *dev)
  219. {
  220. struct drm_psb_private *dev_priv =
  221. (struct drm_psb_private *) dev->dev_private;
  222. unsigned long irqflags;
  223. spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags);
  224. if (gma_power_is_on(dev))
  225. PSB_WVDC32(0xFFFFFFFF, PSB_HWSTAM);
  226. if (dev->vblank_enabled[0])
  227. dev_priv->vdc_irq_mask |= _PSB_VSYNC_PIPEA_FLAG;
  228. if (dev->vblank_enabled[1])
  229. dev_priv->vdc_irq_mask |= _PSB_VSYNC_PIPEB_FLAG;
  230. /* FIXME: Handle Medfield irq mask
  231. if (dev->vblank_enabled[1])
  232. dev_priv->vdc_irq_mask |= _MDFLD_PIPEB_EVENT_FLAG;
  233. if (dev->vblank_enabled[2])
  234. dev_priv->vdc_irq_mask |= _MDFLD_PIPEC_EVENT_FLAG;
  235. */
  236. /* This register is safe even if display island is off */
  237. PSB_WVDC32(~dev_priv->vdc_irq_mask, PSB_INT_MASK_R);
  238. spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags);
  239. }
  240. int psb_irq_postinstall(struct drm_device *dev)
  241. {
  242. struct drm_psb_private *dev_priv =
  243. (struct drm_psb_private *) dev->dev_private;
  244. unsigned long irqflags;
  245. spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags);
  246. /* This register is safe even if display island is off */
  247. PSB_WVDC32(dev_priv->vdc_irq_mask, PSB_INT_ENABLE_R);
  248. PSB_WVDC32(0xFFFFFFFF, PSB_HWSTAM);
  249. if (dev->vblank_enabled[0])
  250. psb_enable_pipestat(dev_priv, 0, PIPE_VBLANK_INTERRUPT_ENABLE);
  251. else
  252. psb_disable_pipestat(dev_priv, 0, PIPE_VBLANK_INTERRUPT_ENABLE);
  253. if (dev->vblank_enabled[1])
  254. psb_enable_pipestat(dev_priv, 1, PIPE_VBLANK_INTERRUPT_ENABLE);
  255. else
  256. psb_disable_pipestat(dev_priv, 1, PIPE_VBLANK_INTERRUPT_ENABLE);
  257. if (dev->vblank_enabled[2])
  258. psb_enable_pipestat(dev_priv, 2, PIPE_VBLANK_INTERRUPT_ENABLE);
  259. else
  260. psb_disable_pipestat(dev_priv, 2, PIPE_VBLANK_INTERRUPT_ENABLE);
  261. spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags);
  262. return 0;
  263. }
  264. void psb_irq_uninstall(struct drm_device *dev)
  265. {
  266. struct drm_psb_private *dev_priv =
  267. (struct drm_psb_private *) dev->dev_private;
  268. unsigned long irqflags;
  269. spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags);
  270. PSB_WVDC32(0xFFFFFFFF, PSB_HWSTAM);
  271. if (dev->vblank_enabled[0])
  272. psb_disable_pipestat(dev_priv, 0, PIPE_VBLANK_INTERRUPT_ENABLE);
  273. if (dev->vblank_enabled[1])
  274. psb_disable_pipestat(dev_priv, 1, PIPE_VBLANK_INTERRUPT_ENABLE);
  275. if (dev->vblank_enabled[2])
  276. psb_disable_pipestat(dev_priv, 2, PIPE_VBLANK_INTERRUPT_ENABLE);
  277. dev_priv->vdc_irq_mask &= _PSB_IRQ_SGX_FLAG |
  278. _PSB_IRQ_MSVDX_FLAG |
  279. _LNC_IRQ_TOPAZ_FLAG;
  280. /* These two registers are safe even if display island is off */
  281. PSB_WVDC32(~dev_priv->vdc_irq_mask, PSB_INT_MASK_R);
  282. PSB_WVDC32(dev_priv->vdc_irq_mask, PSB_INT_ENABLE_R);
  283. wmb();
  284. /* This register is safe even if display island is off */
  285. PSB_WVDC32(PSB_RVDC32(PSB_INT_IDENTITY_R), PSB_INT_IDENTITY_R);
  286. spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags);
  287. }
  288. void psb_irq_turn_on_dpst(struct drm_device *dev)
  289. {
  290. struct drm_psb_private *dev_priv =
  291. (struct drm_psb_private *) dev->dev_private;
  292. u32 hist_reg;
  293. u32 pwm_reg;
  294. if (gma_power_begin(dev, false)) {
  295. PSB_WVDC32(1 << 31, HISTOGRAM_LOGIC_CONTROL);
  296. hist_reg = PSB_RVDC32(HISTOGRAM_LOGIC_CONTROL);
  297. PSB_WVDC32(1 << 31, HISTOGRAM_INT_CONTROL);
  298. hist_reg = PSB_RVDC32(HISTOGRAM_INT_CONTROL);
  299. PSB_WVDC32(0x80010100, PWM_CONTROL_LOGIC);
  300. pwm_reg = PSB_RVDC32(PWM_CONTROL_LOGIC);
  301. PSB_WVDC32(pwm_reg | PWM_PHASEIN_ENABLE
  302. | PWM_PHASEIN_INT_ENABLE,
  303. PWM_CONTROL_LOGIC);
  304. pwm_reg = PSB_RVDC32(PWM_CONTROL_LOGIC);
  305. psb_enable_pipestat(dev_priv, 0, PIPE_DPST_EVENT_ENABLE);
  306. hist_reg = PSB_RVDC32(HISTOGRAM_INT_CONTROL);
  307. PSB_WVDC32(hist_reg | HISTOGRAM_INT_CTRL_CLEAR,
  308. HISTOGRAM_INT_CONTROL);
  309. pwm_reg = PSB_RVDC32(PWM_CONTROL_LOGIC);
  310. PSB_WVDC32(pwm_reg | 0x80010100 | PWM_PHASEIN_ENABLE,
  311. PWM_CONTROL_LOGIC);
  312. gma_power_end(dev);
  313. }
  314. }
  315. int psb_irq_enable_dpst(struct drm_device *dev)
  316. {
  317. struct drm_psb_private *dev_priv =
  318. (struct drm_psb_private *) dev->dev_private;
  319. unsigned long irqflags;
  320. spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags);
  321. /* enable DPST */
  322. mid_enable_pipe_event(dev_priv, 0);
  323. psb_irq_turn_on_dpst(dev);
  324. spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags);
  325. return 0;
  326. }
  327. void psb_irq_turn_off_dpst(struct drm_device *dev)
  328. {
  329. struct drm_psb_private *dev_priv =
  330. (struct drm_psb_private *) dev->dev_private;
  331. u32 hist_reg;
  332. u32 pwm_reg;
  333. if (gma_power_begin(dev, false)) {
  334. PSB_WVDC32(0x00000000, HISTOGRAM_INT_CONTROL);
  335. hist_reg = PSB_RVDC32(HISTOGRAM_INT_CONTROL);
  336. psb_disable_pipestat(dev_priv, 0, PIPE_DPST_EVENT_ENABLE);
  337. pwm_reg = PSB_RVDC32(PWM_CONTROL_LOGIC);
  338. PSB_WVDC32(pwm_reg & !(PWM_PHASEIN_INT_ENABLE),
  339. PWM_CONTROL_LOGIC);
  340. pwm_reg = PSB_RVDC32(PWM_CONTROL_LOGIC);
  341. gma_power_end(dev);
  342. }
  343. }
  344. int psb_irq_disable_dpst(struct drm_device *dev)
  345. {
  346. struct drm_psb_private *dev_priv =
  347. (struct drm_psb_private *) dev->dev_private;
  348. unsigned long irqflags;
  349. spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags);
  350. mid_disable_pipe_event(dev_priv, 0);
  351. psb_irq_turn_off_dpst(dev);
  352. spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags);
  353. return 0;
  354. }
  355. #ifdef PSB_FIXME
  356. static int psb_vblank_do_wait(struct drm_device *dev,
  357. unsigned int *sequence, atomic_t *counter)
  358. {
  359. unsigned int cur_vblank;
  360. int ret = 0;
  361. DRM_WAIT_ON(ret, dev->vbl_queue, 3 * DRM_HZ,
  362. (((cur_vblank = atomic_read(counter))
  363. - *sequence) <= (1 << 23)));
  364. *sequence = cur_vblank;
  365. return ret;
  366. }
  367. #endif
  368. /*
  369. * It is used to enable VBLANK interrupt
  370. */
  371. int psb_enable_vblank(struct drm_device *dev, int pipe)
  372. {
  373. struct drm_psb_private *dev_priv = dev->dev_private;
  374. unsigned long irqflags;
  375. uint32_t reg_val = 0;
  376. uint32_t pipeconf_reg = mid_pipeconf(pipe);
  377. /* Medfield is different - we should perhaps extract out vblank
  378. and blacklight etc ops */
  379. if (IS_MFLD(dev))
  380. return mdfld_enable_te(dev, pipe);
  381. if (gma_power_begin(dev, false)) {
  382. reg_val = REG_READ(pipeconf_reg);
  383. gma_power_end(dev);
  384. }
  385. if (!(reg_val & PIPEACONF_ENABLE))
  386. return -EINVAL;
  387. spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags);
  388. if (pipe == 0)
  389. dev_priv->vdc_irq_mask |= _PSB_VSYNC_PIPEA_FLAG;
  390. else if (pipe == 1)
  391. dev_priv->vdc_irq_mask |= _PSB_VSYNC_PIPEB_FLAG;
  392. PSB_WVDC32(~dev_priv->vdc_irq_mask, PSB_INT_MASK_R);
  393. PSB_WVDC32(dev_priv->vdc_irq_mask, PSB_INT_ENABLE_R);
  394. psb_enable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_ENABLE);
  395. spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags);
  396. return 0;
  397. }
  398. /*
  399. * It is used to disable VBLANK interrupt
  400. */
  401. void psb_disable_vblank(struct drm_device *dev, int pipe)
  402. {
  403. struct drm_psb_private *dev_priv = dev->dev_private;
  404. unsigned long irqflags;
  405. if (IS_MFLD(dev))
  406. mdfld_disable_te(dev, pipe);
  407. spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags);
  408. if (pipe == 0)
  409. dev_priv->vdc_irq_mask &= ~_PSB_VSYNC_PIPEA_FLAG;
  410. else if (pipe == 1)
  411. dev_priv->vdc_irq_mask &= ~_PSB_VSYNC_PIPEB_FLAG;
  412. PSB_WVDC32(~dev_priv->vdc_irq_mask, PSB_INT_MASK_R);
  413. PSB_WVDC32(dev_priv->vdc_irq_mask, PSB_INT_ENABLE_R);
  414. psb_disable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_ENABLE);
  415. spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags);
  416. }
  417. /*
  418. * It is used to enable TE interrupt
  419. */
  420. int mdfld_enable_te(struct drm_device *dev, int pipe)
  421. {
  422. struct drm_psb_private *dev_priv =
  423. (struct drm_psb_private *) dev->dev_private;
  424. unsigned long irqflags;
  425. uint32_t reg_val = 0;
  426. uint32_t pipeconf_reg = mid_pipeconf(pipe);
  427. if (gma_power_begin(dev, false)) {
  428. reg_val = REG_READ(pipeconf_reg);
  429. gma_power_end(dev);
  430. }
  431. if (!(reg_val & PIPEACONF_ENABLE))
  432. return -EINVAL;
  433. spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags);
  434. mid_enable_pipe_event(dev_priv, pipe);
  435. psb_enable_pipestat(dev_priv, pipe, PIPE_TE_ENABLE);
  436. spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags);
  437. return 0;
  438. }
  439. /*
  440. * It is used to disable TE interrupt
  441. */
  442. void mdfld_disable_te(struct drm_device *dev, int pipe)
  443. {
  444. struct drm_psb_private *dev_priv =
  445. (struct drm_psb_private *) dev->dev_private;
  446. unsigned long irqflags;
  447. if (!dev_priv->dsr_enable)
  448. return;
  449. spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags);
  450. mid_disable_pipe_event(dev_priv, pipe);
  451. psb_disable_pipestat(dev_priv, pipe, PIPE_TE_ENABLE);
  452. spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags);
  453. }
  454. /* Called from drm generic code, passed a 'crtc', which
  455. * we use as a pipe index
  456. */
  457. u32 psb_get_vblank_counter(struct drm_device *dev, int pipe)
  458. {
  459. uint32_t high_frame = PIPEAFRAMEHIGH;
  460. uint32_t low_frame = PIPEAFRAMEPIXEL;
  461. uint32_t pipeconf_reg = PIPEACONF;
  462. uint32_t reg_val = 0;
  463. uint32_t high1 = 0, high2 = 0, low = 0, count = 0;
  464. switch (pipe) {
  465. case 0:
  466. break;
  467. case 1:
  468. high_frame = PIPEBFRAMEHIGH;
  469. low_frame = PIPEBFRAMEPIXEL;
  470. pipeconf_reg = PIPEBCONF;
  471. break;
  472. case 2:
  473. high_frame = PIPECFRAMEHIGH;
  474. low_frame = PIPECFRAMEPIXEL;
  475. pipeconf_reg = PIPECCONF;
  476. break;
  477. default:
  478. dev_err(dev->dev, "%s, invalid pipe.\n", __func__);
  479. return 0;
  480. }
  481. if (!gma_power_begin(dev, false))
  482. return 0;
  483. reg_val = REG_READ(pipeconf_reg);
  484. if (!(reg_val & PIPEACONF_ENABLE)) {
  485. dev_err(dev->dev, "trying to get vblank count for disabled pipe %d\n",
  486. pipe);
  487. goto psb_get_vblank_counter_exit;
  488. }
  489. /*
  490. * High & low register fields aren't synchronized, so make sure
  491. * we get a low value that's stable across two reads of the high
  492. * register.
  493. */
  494. do {
  495. high1 = ((REG_READ(high_frame) & PIPE_FRAME_HIGH_MASK) >>
  496. PIPE_FRAME_HIGH_SHIFT);
  497. low = ((REG_READ(low_frame) & PIPE_FRAME_LOW_MASK) >>
  498. PIPE_FRAME_LOW_SHIFT);
  499. high2 = ((REG_READ(high_frame) & PIPE_FRAME_HIGH_MASK) >>
  500. PIPE_FRAME_HIGH_SHIFT);
  501. } while (high1 != high2);
  502. count = (high1 << 8) | low;
  503. psb_get_vblank_counter_exit:
  504. gma_power_end(dev);
  505. return count;
  506. }