psb_irq.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  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(int irq, void *arg)
  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|_PSB_IRQ_ASLE))
  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. rmb();
  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[0].enabled)
  236. dev_priv->vdc_irq_mask |= _PSB_VSYNC_PIPEA_FLAG;
  237. if (dev->vblank[1].enabled)
  238. dev_priv->vdc_irq_mask |= _PSB_VSYNC_PIPEB_FLAG;
  239. /* FIXME: Handle Medfield irq mask
  240. if (dev->vblank[1].enabled)
  241. dev_priv->vdc_irq_mask |= _MDFLD_PIPEB_EVENT_FLAG;
  242. if (dev->vblank[2].enabled)
  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[0].enabled)
  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[1].enabled)
  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[2].enabled)
  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[0].enabled)
  288. psb_disable_pipestat(dev_priv, 0, PIPE_VBLANK_INTERRUPT_ENABLE);
  289. if (dev->vblank[1].enabled)
  290. psb_disable_pipestat(dev_priv, 1, PIPE_VBLANK_INTERRUPT_ENABLE);
  291. if (dev->vblank[2].enabled)
  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. /*
  372. * It is used to enable VBLANK interrupt
  373. */
  374. int psb_enable_vblank(struct drm_device *dev, int pipe)
  375. {
  376. struct drm_psb_private *dev_priv = dev->dev_private;
  377. unsigned long irqflags;
  378. uint32_t reg_val = 0;
  379. uint32_t pipeconf_reg = mid_pipeconf(pipe);
  380. /* Medfield is different - we should perhaps extract out vblank
  381. and blacklight etc ops */
  382. if (IS_MFLD(dev))
  383. return mdfld_enable_te(dev, pipe);
  384. if (gma_power_begin(dev, false)) {
  385. reg_val = REG_READ(pipeconf_reg);
  386. gma_power_end(dev);
  387. }
  388. if (!(reg_val & PIPEACONF_ENABLE))
  389. return -EINVAL;
  390. spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags);
  391. if (pipe == 0)
  392. dev_priv->vdc_irq_mask |= _PSB_VSYNC_PIPEA_FLAG;
  393. else if (pipe == 1)
  394. dev_priv->vdc_irq_mask |= _PSB_VSYNC_PIPEB_FLAG;
  395. PSB_WVDC32(~dev_priv->vdc_irq_mask, PSB_INT_MASK_R);
  396. PSB_WVDC32(dev_priv->vdc_irq_mask, PSB_INT_ENABLE_R);
  397. psb_enable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_ENABLE);
  398. spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags);
  399. return 0;
  400. }
  401. /*
  402. * It is used to disable VBLANK interrupt
  403. */
  404. void psb_disable_vblank(struct drm_device *dev, int pipe)
  405. {
  406. struct drm_psb_private *dev_priv = dev->dev_private;
  407. unsigned long irqflags;
  408. if (IS_MFLD(dev))
  409. mdfld_disable_te(dev, pipe);
  410. spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags);
  411. if (pipe == 0)
  412. dev_priv->vdc_irq_mask &= ~_PSB_VSYNC_PIPEA_FLAG;
  413. else if (pipe == 1)
  414. dev_priv->vdc_irq_mask &= ~_PSB_VSYNC_PIPEB_FLAG;
  415. PSB_WVDC32(~dev_priv->vdc_irq_mask, PSB_INT_MASK_R);
  416. PSB_WVDC32(dev_priv->vdc_irq_mask, PSB_INT_ENABLE_R);
  417. psb_disable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_ENABLE);
  418. spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags);
  419. }
  420. /*
  421. * It is used to enable TE interrupt
  422. */
  423. int mdfld_enable_te(struct drm_device *dev, int pipe)
  424. {
  425. struct drm_psb_private *dev_priv =
  426. (struct drm_psb_private *) dev->dev_private;
  427. unsigned long irqflags;
  428. uint32_t reg_val = 0;
  429. uint32_t pipeconf_reg = mid_pipeconf(pipe);
  430. if (gma_power_begin(dev, false)) {
  431. reg_val = REG_READ(pipeconf_reg);
  432. gma_power_end(dev);
  433. }
  434. if (!(reg_val & PIPEACONF_ENABLE))
  435. return -EINVAL;
  436. spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags);
  437. mid_enable_pipe_event(dev_priv, pipe);
  438. psb_enable_pipestat(dev_priv, pipe, PIPE_TE_ENABLE);
  439. spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags);
  440. return 0;
  441. }
  442. /*
  443. * It is used to disable TE interrupt
  444. */
  445. void mdfld_disable_te(struct drm_device *dev, int pipe)
  446. {
  447. struct drm_psb_private *dev_priv =
  448. (struct drm_psb_private *) dev->dev_private;
  449. unsigned long irqflags;
  450. if (!dev_priv->dsr_enable)
  451. return;
  452. spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags);
  453. mid_disable_pipe_event(dev_priv, pipe);
  454. psb_disable_pipestat(dev_priv, pipe, PIPE_TE_ENABLE);
  455. spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags);
  456. }
  457. /* Called from drm generic code, passed a 'crtc', which
  458. * we use as a pipe index
  459. */
  460. u32 psb_get_vblank_counter(struct drm_device *dev, int pipe)
  461. {
  462. uint32_t high_frame = PIPEAFRAMEHIGH;
  463. uint32_t low_frame = PIPEAFRAMEPIXEL;
  464. uint32_t pipeconf_reg = PIPEACONF;
  465. uint32_t reg_val = 0;
  466. uint32_t high1 = 0, high2 = 0, low = 0, count = 0;
  467. switch (pipe) {
  468. case 0:
  469. break;
  470. case 1:
  471. high_frame = PIPEBFRAMEHIGH;
  472. low_frame = PIPEBFRAMEPIXEL;
  473. pipeconf_reg = PIPEBCONF;
  474. break;
  475. case 2:
  476. high_frame = PIPECFRAMEHIGH;
  477. low_frame = PIPECFRAMEPIXEL;
  478. pipeconf_reg = PIPECCONF;
  479. break;
  480. default:
  481. dev_err(dev->dev, "%s, invalid pipe.\n", __func__);
  482. return 0;
  483. }
  484. if (!gma_power_begin(dev, false))
  485. return 0;
  486. reg_val = REG_READ(pipeconf_reg);
  487. if (!(reg_val & PIPEACONF_ENABLE)) {
  488. dev_err(dev->dev, "trying to get vblank count for disabled pipe %d\n",
  489. pipe);
  490. goto psb_get_vblank_counter_exit;
  491. }
  492. /*
  493. * High & low register fields aren't synchronized, so make sure
  494. * we get a low value that's stable across two reads of the high
  495. * register.
  496. */
  497. do {
  498. high1 = ((REG_READ(high_frame) & PIPE_FRAME_HIGH_MASK) >>
  499. PIPE_FRAME_HIGH_SHIFT);
  500. low = ((REG_READ(low_frame) & PIPE_FRAME_LOW_MASK) >>
  501. PIPE_FRAME_LOW_SHIFT);
  502. high2 = ((REG_READ(high_frame) & PIPE_FRAME_HIGH_MASK) >>
  503. PIPE_FRAME_HIGH_SHIFT);
  504. } while (high1 != high2);
  505. count = (high1 << 8) | low;
  506. psb_get_vblank_counter_exit:
  507. gma_power_end(dev);
  508. return count;
  509. }