psb_irq.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  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_IRQ_ASLE)
  173. psb_intel_opregion_asle_intr(dev);
  174. if (vdc_stat & _PSB_VSYNC_PIPEA_FLAG)
  175. mid_pipe_event_handler(dev, 0);
  176. if (vdc_stat & _PSB_VSYNC_PIPEB_FLAG)
  177. mid_pipe_event_handler(dev, 1);
  178. }
  179. irqreturn_t psb_irq_handler(DRM_IRQ_ARGS)
  180. {
  181. struct drm_device *dev = arg;
  182. struct drm_psb_private *dev_priv = dev->dev_private;
  183. uint32_t vdc_stat, dsp_int = 0, sgx_int = 0, hotplug_int = 0;
  184. int handled = 0;
  185. spin_lock(&dev_priv->irqmask_lock);
  186. vdc_stat = PSB_RVDC32(PSB_INT_IDENTITY_R);
  187. if (vdc_stat & _PSB_PIPE_EVENT_FLAG)
  188. dsp_int = 1;
  189. /* FIXME: Handle Medfield
  190. if (vdc_stat & _MDFLD_DISP_ALL_IRQ_FLAG)
  191. dsp_int = 1;
  192. */
  193. if (vdc_stat & _PSB_IRQ_SGX_FLAG)
  194. sgx_int = 1;
  195. if (vdc_stat & _PSB_IRQ_DISP_HOTSYNC)
  196. hotplug_int = 1;
  197. vdc_stat &= dev_priv->vdc_irq_mask;
  198. spin_unlock(&dev_priv->irqmask_lock);
  199. if (dsp_int && gma_power_is_on(dev)) {
  200. psb_vdc_interrupt(dev, vdc_stat);
  201. handled = 1;
  202. }
  203. if (sgx_int) {
  204. /* Not expected - we have it masked, shut it up */
  205. u32 s, s2;
  206. s = PSB_RSGX32(PSB_CR_EVENT_STATUS);
  207. s2 = PSB_RSGX32(PSB_CR_EVENT_STATUS2);
  208. PSB_WSGX32(s, PSB_CR_EVENT_HOST_CLEAR);
  209. PSB_WSGX32(s2, PSB_CR_EVENT_HOST_CLEAR2);
  210. /* if s & _PSB_CE_TWOD_COMPLETE we have 2D done but
  211. we may as well poll even if we add that ! */
  212. handled = 1;
  213. }
  214. /* Note: this bit has other meanings on some devices, so we will
  215. need to address that later if it ever matters */
  216. if (hotplug_int && dev_priv->ops->hotplug) {
  217. handled = dev_priv->ops->hotplug(dev);
  218. REG_WRITE(PORT_HOTPLUG_STAT, REG_READ(PORT_HOTPLUG_STAT));
  219. }
  220. PSB_WVDC32(vdc_stat, PSB_INT_IDENTITY_R);
  221. (void) PSB_RVDC32(PSB_INT_IDENTITY_R);
  222. DRM_READMEMORYBARRIER();
  223. if (!handled)
  224. return IRQ_NONE;
  225. return IRQ_HANDLED;
  226. }
  227. void psb_irq_preinstall(struct drm_device *dev)
  228. {
  229. struct drm_psb_private *dev_priv =
  230. (struct drm_psb_private *) dev->dev_private;
  231. unsigned long irqflags;
  232. spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags);
  233. if (gma_power_is_on(dev))
  234. PSB_WVDC32(0xFFFFFFFF, PSB_HWSTAM);
  235. if (dev->vblank_enabled[0])
  236. dev_priv->vdc_irq_mask |= _PSB_VSYNC_PIPEA_FLAG;
  237. if (dev->vblank_enabled[1])
  238. dev_priv->vdc_irq_mask |= _PSB_VSYNC_PIPEB_FLAG;
  239. /* FIXME: Handle Medfield irq mask
  240. if (dev->vblank_enabled[1])
  241. dev_priv->vdc_irq_mask |= _MDFLD_PIPEB_EVENT_FLAG;
  242. if (dev->vblank_enabled[2])
  243. dev_priv->vdc_irq_mask |= _MDFLD_PIPEC_EVENT_FLAG;
  244. */
  245. /* Revisit this area - want per device masks ? */
  246. if (dev_priv->ops->hotplug)
  247. dev_priv->vdc_irq_mask |= _PSB_IRQ_DISP_HOTSYNC;
  248. dev_priv->vdc_irq_mask |= _PSB_IRQ_ASLE;
  249. /* This register is safe even if display island is off */
  250. PSB_WVDC32(~dev_priv->vdc_irq_mask, PSB_INT_MASK_R);
  251. spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags);
  252. }
  253. int psb_irq_postinstall(struct drm_device *dev)
  254. {
  255. struct drm_psb_private *dev_priv =
  256. (struct drm_psb_private *) dev->dev_private;
  257. unsigned long irqflags;
  258. spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags);
  259. /* This register is safe even if display island is off */
  260. PSB_WVDC32(dev_priv->vdc_irq_mask, PSB_INT_ENABLE_R);
  261. PSB_WVDC32(0xFFFFFFFF, PSB_HWSTAM);
  262. if (dev->vblank_enabled[0])
  263. psb_enable_pipestat(dev_priv, 0, PIPE_VBLANK_INTERRUPT_ENABLE);
  264. else
  265. psb_disable_pipestat(dev_priv, 0, PIPE_VBLANK_INTERRUPT_ENABLE);
  266. if (dev->vblank_enabled[1])
  267. psb_enable_pipestat(dev_priv, 1, PIPE_VBLANK_INTERRUPT_ENABLE);
  268. else
  269. psb_disable_pipestat(dev_priv, 1, PIPE_VBLANK_INTERRUPT_ENABLE);
  270. if (dev->vblank_enabled[2])
  271. psb_enable_pipestat(dev_priv, 2, PIPE_VBLANK_INTERRUPT_ENABLE);
  272. else
  273. psb_disable_pipestat(dev_priv, 2, PIPE_VBLANK_INTERRUPT_ENABLE);
  274. if (dev_priv->ops->hotplug_enable)
  275. dev_priv->ops->hotplug_enable(dev, true);
  276. spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags);
  277. return 0;
  278. }
  279. void psb_irq_uninstall(struct drm_device *dev)
  280. {
  281. struct drm_psb_private *dev_priv = dev->dev_private;
  282. unsigned long irqflags;
  283. spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags);
  284. if (dev_priv->ops->hotplug_enable)
  285. dev_priv->ops->hotplug_enable(dev, false);
  286. PSB_WVDC32(0xFFFFFFFF, PSB_HWSTAM);
  287. if (dev->vblank_enabled[0])
  288. psb_disable_pipestat(dev_priv, 0, PIPE_VBLANK_INTERRUPT_ENABLE);
  289. if (dev->vblank_enabled[1])
  290. psb_disable_pipestat(dev_priv, 1, PIPE_VBLANK_INTERRUPT_ENABLE);
  291. if (dev->vblank_enabled[2])
  292. psb_disable_pipestat(dev_priv, 2, PIPE_VBLANK_INTERRUPT_ENABLE);
  293. dev_priv->vdc_irq_mask &= _PSB_IRQ_SGX_FLAG |
  294. _PSB_IRQ_MSVDX_FLAG |
  295. _LNC_IRQ_TOPAZ_FLAG;
  296. /* These two registers are safe even if display island is off */
  297. PSB_WVDC32(~dev_priv->vdc_irq_mask, PSB_INT_MASK_R);
  298. PSB_WVDC32(dev_priv->vdc_irq_mask, PSB_INT_ENABLE_R);
  299. wmb();
  300. /* This register is safe even if display island is off */
  301. PSB_WVDC32(PSB_RVDC32(PSB_INT_IDENTITY_R), PSB_INT_IDENTITY_R);
  302. spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags);
  303. }
  304. void psb_irq_turn_on_dpst(struct drm_device *dev)
  305. {
  306. struct drm_psb_private *dev_priv =
  307. (struct drm_psb_private *) dev->dev_private;
  308. u32 hist_reg;
  309. u32 pwm_reg;
  310. if (gma_power_begin(dev, false)) {
  311. PSB_WVDC32(1 << 31, HISTOGRAM_LOGIC_CONTROL);
  312. hist_reg = PSB_RVDC32(HISTOGRAM_LOGIC_CONTROL);
  313. PSB_WVDC32(1 << 31, HISTOGRAM_INT_CONTROL);
  314. hist_reg = PSB_RVDC32(HISTOGRAM_INT_CONTROL);
  315. PSB_WVDC32(0x80010100, PWM_CONTROL_LOGIC);
  316. pwm_reg = PSB_RVDC32(PWM_CONTROL_LOGIC);
  317. PSB_WVDC32(pwm_reg | PWM_PHASEIN_ENABLE
  318. | PWM_PHASEIN_INT_ENABLE,
  319. PWM_CONTROL_LOGIC);
  320. pwm_reg = PSB_RVDC32(PWM_CONTROL_LOGIC);
  321. psb_enable_pipestat(dev_priv, 0, PIPE_DPST_EVENT_ENABLE);
  322. hist_reg = PSB_RVDC32(HISTOGRAM_INT_CONTROL);
  323. PSB_WVDC32(hist_reg | HISTOGRAM_INT_CTRL_CLEAR,
  324. HISTOGRAM_INT_CONTROL);
  325. pwm_reg = PSB_RVDC32(PWM_CONTROL_LOGIC);
  326. PSB_WVDC32(pwm_reg | 0x80010100 | PWM_PHASEIN_ENABLE,
  327. PWM_CONTROL_LOGIC);
  328. gma_power_end(dev);
  329. }
  330. }
  331. int psb_irq_enable_dpst(struct drm_device *dev)
  332. {
  333. struct drm_psb_private *dev_priv =
  334. (struct drm_psb_private *) dev->dev_private;
  335. unsigned long irqflags;
  336. spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags);
  337. /* enable DPST */
  338. mid_enable_pipe_event(dev_priv, 0);
  339. psb_irq_turn_on_dpst(dev);
  340. spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags);
  341. return 0;
  342. }
  343. void psb_irq_turn_off_dpst(struct drm_device *dev)
  344. {
  345. struct drm_psb_private *dev_priv =
  346. (struct drm_psb_private *) dev->dev_private;
  347. u32 hist_reg;
  348. u32 pwm_reg;
  349. if (gma_power_begin(dev, false)) {
  350. PSB_WVDC32(0x00000000, HISTOGRAM_INT_CONTROL);
  351. hist_reg = PSB_RVDC32(HISTOGRAM_INT_CONTROL);
  352. psb_disable_pipestat(dev_priv, 0, PIPE_DPST_EVENT_ENABLE);
  353. pwm_reg = PSB_RVDC32(PWM_CONTROL_LOGIC);
  354. PSB_WVDC32(pwm_reg & ~PWM_PHASEIN_INT_ENABLE,
  355. PWM_CONTROL_LOGIC);
  356. pwm_reg = PSB_RVDC32(PWM_CONTROL_LOGIC);
  357. gma_power_end(dev);
  358. }
  359. }
  360. int psb_irq_disable_dpst(struct drm_device *dev)
  361. {
  362. struct drm_psb_private *dev_priv =
  363. (struct drm_psb_private *) dev->dev_private;
  364. unsigned long irqflags;
  365. spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags);
  366. mid_disable_pipe_event(dev_priv, 0);
  367. psb_irq_turn_off_dpst(dev);
  368. spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags);
  369. return 0;
  370. }
  371. #ifdef PSB_FIXME
  372. static int psb_vblank_do_wait(struct drm_device *dev,
  373. unsigned int *sequence, atomic_t *counter)
  374. {
  375. unsigned int cur_vblank;
  376. int ret = 0;
  377. DRM_WAIT_ON(ret, dev->vbl_queue, 3 * DRM_HZ,
  378. (((cur_vblank = atomic_read(counter))
  379. - *sequence) <= (1 << 23)));
  380. *sequence = cur_vblank;
  381. return ret;
  382. }
  383. #endif
  384. /*
  385. * It is used to enable VBLANK interrupt
  386. */
  387. int psb_enable_vblank(struct drm_device *dev, int pipe)
  388. {
  389. struct drm_psb_private *dev_priv = dev->dev_private;
  390. unsigned long irqflags;
  391. uint32_t reg_val = 0;
  392. uint32_t pipeconf_reg = mid_pipeconf(pipe);
  393. /* Medfield is different - we should perhaps extract out vblank
  394. and blacklight etc ops */
  395. if (IS_MFLD(dev))
  396. return mdfld_enable_te(dev, pipe);
  397. if (gma_power_begin(dev, false)) {
  398. reg_val = REG_READ(pipeconf_reg);
  399. gma_power_end(dev);
  400. }
  401. if (!(reg_val & PIPEACONF_ENABLE))
  402. return -EINVAL;
  403. spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags);
  404. if (pipe == 0)
  405. dev_priv->vdc_irq_mask |= _PSB_VSYNC_PIPEA_FLAG;
  406. else if (pipe == 1)
  407. dev_priv->vdc_irq_mask |= _PSB_VSYNC_PIPEB_FLAG;
  408. PSB_WVDC32(~dev_priv->vdc_irq_mask, PSB_INT_MASK_R);
  409. PSB_WVDC32(dev_priv->vdc_irq_mask, PSB_INT_ENABLE_R);
  410. psb_enable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_ENABLE);
  411. spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags);
  412. return 0;
  413. }
  414. /*
  415. * It is used to disable VBLANK interrupt
  416. */
  417. void psb_disable_vblank(struct drm_device *dev, int pipe)
  418. {
  419. struct drm_psb_private *dev_priv = dev->dev_private;
  420. unsigned long irqflags;
  421. if (IS_MFLD(dev))
  422. mdfld_disable_te(dev, pipe);
  423. spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags);
  424. if (pipe == 0)
  425. dev_priv->vdc_irq_mask &= ~_PSB_VSYNC_PIPEA_FLAG;
  426. else if (pipe == 1)
  427. dev_priv->vdc_irq_mask &= ~_PSB_VSYNC_PIPEB_FLAG;
  428. PSB_WVDC32(~dev_priv->vdc_irq_mask, PSB_INT_MASK_R);
  429. PSB_WVDC32(dev_priv->vdc_irq_mask, PSB_INT_ENABLE_R);
  430. psb_disable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_ENABLE);
  431. spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags);
  432. }
  433. /*
  434. * It is used to enable TE interrupt
  435. */
  436. int mdfld_enable_te(struct drm_device *dev, int pipe)
  437. {
  438. struct drm_psb_private *dev_priv =
  439. (struct drm_psb_private *) dev->dev_private;
  440. unsigned long irqflags;
  441. uint32_t reg_val = 0;
  442. uint32_t pipeconf_reg = mid_pipeconf(pipe);
  443. if (gma_power_begin(dev, false)) {
  444. reg_val = REG_READ(pipeconf_reg);
  445. gma_power_end(dev);
  446. }
  447. if (!(reg_val & PIPEACONF_ENABLE))
  448. return -EINVAL;
  449. spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags);
  450. mid_enable_pipe_event(dev_priv, pipe);
  451. psb_enable_pipestat(dev_priv, pipe, PIPE_TE_ENABLE);
  452. spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags);
  453. return 0;
  454. }
  455. /*
  456. * It is used to disable TE interrupt
  457. */
  458. void mdfld_disable_te(struct drm_device *dev, int pipe)
  459. {
  460. struct drm_psb_private *dev_priv =
  461. (struct drm_psb_private *) dev->dev_private;
  462. unsigned long irqflags;
  463. if (!dev_priv->dsr_enable)
  464. return;
  465. spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags);
  466. mid_disable_pipe_event(dev_priv, pipe);
  467. psb_disable_pipestat(dev_priv, pipe, PIPE_TE_ENABLE);
  468. spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags);
  469. }
  470. /* Called from drm generic code, passed a 'crtc', which
  471. * we use as a pipe index
  472. */
  473. u32 psb_get_vblank_counter(struct drm_device *dev, int pipe)
  474. {
  475. uint32_t high_frame = PIPEAFRAMEHIGH;
  476. uint32_t low_frame = PIPEAFRAMEPIXEL;
  477. uint32_t pipeconf_reg = PIPEACONF;
  478. uint32_t reg_val = 0;
  479. uint32_t high1 = 0, high2 = 0, low = 0, count = 0;
  480. switch (pipe) {
  481. case 0:
  482. break;
  483. case 1:
  484. high_frame = PIPEBFRAMEHIGH;
  485. low_frame = PIPEBFRAMEPIXEL;
  486. pipeconf_reg = PIPEBCONF;
  487. break;
  488. case 2:
  489. high_frame = PIPECFRAMEHIGH;
  490. low_frame = PIPECFRAMEPIXEL;
  491. pipeconf_reg = PIPECCONF;
  492. break;
  493. default:
  494. dev_err(dev->dev, "%s, invalid pipe.\n", __func__);
  495. return 0;
  496. }
  497. if (!gma_power_begin(dev, false))
  498. return 0;
  499. reg_val = REG_READ(pipeconf_reg);
  500. if (!(reg_val & PIPEACONF_ENABLE)) {
  501. dev_err(dev->dev, "trying to get vblank count for disabled pipe %d\n",
  502. pipe);
  503. goto psb_get_vblank_counter_exit;
  504. }
  505. /*
  506. * High & low register fields aren't synchronized, so make sure
  507. * we get a low value that's stable across two reads of the high
  508. * register.
  509. */
  510. do {
  511. high1 = ((REG_READ(high_frame) & PIPE_FRAME_HIGH_MASK) >>
  512. PIPE_FRAME_HIGH_SHIFT);
  513. low = ((REG_READ(low_frame) & PIPE_FRAME_LOW_MASK) >>
  514. PIPE_FRAME_LOW_SHIFT);
  515. high2 = ((REG_READ(high_frame) & PIPE_FRAME_HIGH_MASK) >>
  516. PIPE_FRAME_HIGH_SHIFT);
  517. } while (high1 != high2);
  518. count = (high1 << 8) | low;
  519. psb_get_vblank_counter_exit:
  520. gma_power_end(dev);
  521. return count;
  522. }