PageRenderTime 37ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 0ms

/drivers/video/omap2/dss/dsi.c

https://bitbucket.org/wisechild/galaxy-nexus
C | 4892 lines | 3688 code | 975 blank | 229 comment | 517 complexity | 651627daad8025e184a206d72d55e37f MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0
  1. /*
  2. * linux/drivers/video/omap2/dss/dsi.c
  3. *
  4. * Copyright (C) 2009 Nokia Corporation
  5. * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License version 2 as published by
  9. * the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #define DSS_SUBSYS_NAME "DSI"
  20. #include <linux/kernel.h>
  21. #include <linux/io.h>
  22. #include <linux/clk.h>
  23. #include <linux/device.h>
  24. #include <linux/err.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/delay.h>
  27. #include <linux/mutex.h>
  28. #include <linux/semaphore.h>
  29. #include <linux/seq_file.h>
  30. #include <linux/platform_device.h>
  31. #include <linux/regulator/consumer.h>
  32. #include <linux/wait.h>
  33. #include <linux/workqueue.h>
  34. #include <linux/sched.h>
  35. #include <linux/slab.h>
  36. #include <linux/debugfs.h>
  37. #include <linux/pm_runtime.h>
  38. #include <video/omapdss.h>
  39. #include <plat/clock.h>
  40. #include "dss.h"
  41. #include "dss_features.h"
  42. /*#define VERBOSE_IRQ*/
  43. #define DSI_CATCH_MISSING_TE
  44. struct dsi_reg { u16 idx; };
  45. #define DSI_REG(idx) ((const struct dsi_reg) { idx })
  46. #define DSI_SZ_REGS SZ_1K
  47. /* DSI Protocol Engine */
  48. #define DSI_REVISION DSI_REG(0x0000)
  49. #define DSI_SYSCONFIG DSI_REG(0x0010)
  50. #define DSI_SYSSTATUS DSI_REG(0x0014)
  51. #define DSI_IRQSTATUS DSI_REG(0x0018)
  52. #define DSI_IRQENABLE DSI_REG(0x001C)
  53. #define DSI_CTRL DSI_REG(0x0040)
  54. #define DSI_GNQ DSI_REG(0x0044)
  55. #define DSI_COMPLEXIO_CFG1 DSI_REG(0x0048)
  56. #define DSI_COMPLEXIO_IRQ_STATUS DSI_REG(0x004C)
  57. #define DSI_COMPLEXIO_IRQ_ENABLE DSI_REG(0x0050)
  58. #define DSI_CLK_CTRL DSI_REG(0x0054)
  59. #define DSI_TIMING1 DSI_REG(0x0058)
  60. #define DSI_TIMING2 DSI_REG(0x005C)
  61. #define DSI_VM_TIMING1 DSI_REG(0x0060)
  62. #define DSI_VM_TIMING2 DSI_REG(0x0064)
  63. #define DSI_VM_TIMING3 DSI_REG(0x0068)
  64. #define DSI_CLK_TIMING DSI_REG(0x006C)
  65. #define DSI_TX_FIFO_VC_SIZE DSI_REG(0x0070)
  66. #define DSI_RX_FIFO_VC_SIZE DSI_REG(0x0074)
  67. #define DSI_COMPLEXIO_CFG2 DSI_REG(0x0078)
  68. #define DSI_RX_FIFO_VC_FULLNESS DSI_REG(0x007C)
  69. #define DSI_VM_TIMING4 DSI_REG(0x0080)
  70. #define DSI_TX_FIFO_VC_EMPTINESS DSI_REG(0x0084)
  71. #define DSI_VM_TIMING5 DSI_REG(0x0088)
  72. #define DSI_VM_TIMING6 DSI_REG(0x008C)
  73. #define DSI_VM_TIMING7 DSI_REG(0x0090)
  74. #define DSI_STOPCLK_TIMING DSI_REG(0x0094)
  75. #define DSI_VC_CTRL(n) DSI_REG(0x0100 + (n * 0x20))
  76. #define DSI_VC_TE(n) DSI_REG(0x0104 + (n * 0x20))
  77. #define DSI_VC_LONG_PACKET_HEADER(n) DSI_REG(0x0108 + (n * 0x20))
  78. #define DSI_VC_LONG_PACKET_PAYLOAD(n) DSI_REG(0x010C + (n * 0x20))
  79. #define DSI_VC_SHORT_PACKET_HEADER(n) DSI_REG(0x0110 + (n * 0x20))
  80. #define DSI_VC_IRQSTATUS(n) DSI_REG(0x0118 + (n * 0x20))
  81. #define DSI_VC_IRQENABLE(n) DSI_REG(0x011C + (n * 0x20))
  82. /* DSIPHY_SCP */
  83. #define DSI_DSIPHY_CFG0 DSI_REG(0x200 + 0x0000)
  84. #define DSI_DSIPHY_CFG1 DSI_REG(0x200 + 0x0004)
  85. #define DSI_DSIPHY_CFG2 DSI_REG(0x200 + 0x0008)
  86. #define DSI_DSIPHY_CFG5 DSI_REG(0x200 + 0x0014)
  87. #define DSI_DSIPHY_CFG10 DSI_REG(0x200 + 0x0028)
  88. /* DSI_PLL_CTRL_SCP */
  89. #define DSI_PLL_CONTROL DSI_REG(0x300 + 0x0000)
  90. #define DSI_PLL_STATUS DSI_REG(0x300 + 0x0004)
  91. #define DSI_PLL_GO DSI_REG(0x300 + 0x0008)
  92. #define DSI_PLL_CONFIGURATION1 DSI_REG(0x300 + 0x000C)
  93. #define DSI_PLL_CONFIGURATION2 DSI_REG(0x300 + 0x0010)
  94. #define REG_GET(dsidev, idx, start, end) \
  95. FLD_GET(dsi_read_reg(dsidev, idx), start, end)
  96. #define REG_FLD_MOD(dsidev, idx, val, start, end) \
  97. dsi_write_reg(dsidev, idx, FLD_MOD(dsi_read_reg(dsidev, idx), val, start, end))
  98. /* Global interrupts */
  99. #define DSI_IRQ_VC0 (1 << 0)
  100. #define DSI_IRQ_VC1 (1 << 1)
  101. #define DSI_IRQ_VC2 (1 << 2)
  102. #define DSI_IRQ_VC3 (1 << 3)
  103. #define DSI_IRQ_WAKEUP (1 << 4)
  104. #define DSI_IRQ_RESYNC (1 << 5)
  105. #define DSI_IRQ_PLL_LOCK (1 << 7)
  106. #define DSI_IRQ_PLL_UNLOCK (1 << 8)
  107. #define DSI_IRQ_PLL_RECALL (1 << 9)
  108. #define DSI_IRQ_COMPLEXIO_ERR (1 << 10)
  109. #define DSI_IRQ_HS_TX_TIMEOUT (1 << 14)
  110. #define DSI_IRQ_LP_RX_TIMEOUT (1 << 15)
  111. #define DSI_IRQ_TE_TRIGGER (1 << 16)
  112. #define DSI_IRQ_ACK_TRIGGER (1 << 17)
  113. #define DSI_IRQ_SYNC_LOST (1 << 18)
  114. #define DSI_IRQ_LDO_POWER_GOOD (1 << 19)
  115. #define DSI_IRQ_TA_TIMEOUT (1 << 20)
  116. #define DSI_IRQ_ERROR_MASK \
  117. (DSI_IRQ_HS_TX_TIMEOUT | DSI_IRQ_LP_RX_TIMEOUT | DSI_IRQ_SYNC_LOST | \
  118. DSI_IRQ_TA_TIMEOUT)
  119. #define DSI_IRQ_CHANNEL_MASK 0xf
  120. /* Virtual channel interrupts */
  121. #define DSI_VC_IRQ_CS (1 << 0)
  122. #define DSI_VC_IRQ_ECC_CORR (1 << 1)
  123. #define DSI_VC_IRQ_PACKET_SENT (1 << 2)
  124. #define DSI_VC_IRQ_FIFO_TX_OVF (1 << 3)
  125. #define DSI_VC_IRQ_FIFO_RX_OVF (1 << 4)
  126. #define DSI_VC_IRQ_BTA (1 << 5)
  127. #define DSI_VC_IRQ_ECC_NO_CORR (1 << 6)
  128. #define DSI_VC_IRQ_FIFO_TX_UDF (1 << 7)
  129. #define DSI_VC_IRQ_PP_BUSY_CHANGE (1 << 8)
  130. #define DSI_VC_IRQ_ERROR_MASK \
  131. (DSI_VC_IRQ_CS | DSI_VC_IRQ_ECC_CORR | DSI_VC_IRQ_FIFO_TX_OVF | \
  132. DSI_VC_IRQ_FIFO_RX_OVF | DSI_VC_IRQ_ECC_NO_CORR | \
  133. DSI_VC_IRQ_FIFO_TX_UDF)
  134. /* ComplexIO interrupts */
  135. #define DSI_CIO_IRQ_ERRSYNCESC1 (1 << 0)
  136. #define DSI_CIO_IRQ_ERRSYNCESC2 (1 << 1)
  137. #define DSI_CIO_IRQ_ERRSYNCESC3 (1 << 2)
  138. #define DSI_CIO_IRQ_ERRSYNCESC4 (1 << 3)
  139. #define DSI_CIO_IRQ_ERRSYNCESC5 (1 << 4)
  140. #define DSI_CIO_IRQ_ERRESC1 (1 << 5)
  141. #define DSI_CIO_IRQ_ERRESC2 (1 << 6)
  142. #define DSI_CIO_IRQ_ERRESC3 (1 << 7)
  143. #define DSI_CIO_IRQ_ERRESC4 (1 << 8)
  144. #define DSI_CIO_IRQ_ERRESC5 (1 << 9)
  145. #define DSI_CIO_IRQ_ERRCONTROL1 (1 << 10)
  146. #define DSI_CIO_IRQ_ERRCONTROL2 (1 << 11)
  147. #define DSI_CIO_IRQ_ERRCONTROL3 (1 << 12)
  148. #define DSI_CIO_IRQ_ERRCONTROL4 (1 << 13)
  149. #define DSI_CIO_IRQ_ERRCONTROL5 (1 << 14)
  150. #define DSI_CIO_IRQ_STATEULPS1 (1 << 15)
  151. #define DSI_CIO_IRQ_STATEULPS2 (1 << 16)
  152. #define DSI_CIO_IRQ_STATEULPS3 (1 << 17)
  153. #define DSI_CIO_IRQ_STATEULPS4 (1 << 18)
  154. #define DSI_CIO_IRQ_STATEULPS5 (1 << 19)
  155. #define DSI_CIO_IRQ_ERRCONTENTIONLP0_1 (1 << 20)
  156. #define DSI_CIO_IRQ_ERRCONTENTIONLP1_1 (1 << 21)
  157. #define DSI_CIO_IRQ_ERRCONTENTIONLP0_2 (1 << 22)
  158. #define DSI_CIO_IRQ_ERRCONTENTIONLP1_2 (1 << 23)
  159. #define DSI_CIO_IRQ_ERRCONTENTIONLP0_3 (1 << 24)
  160. #define DSI_CIO_IRQ_ERRCONTENTIONLP1_3 (1 << 25)
  161. #define DSI_CIO_IRQ_ERRCONTENTIONLP0_4 (1 << 26)
  162. #define DSI_CIO_IRQ_ERRCONTENTIONLP1_4 (1 << 27)
  163. #define DSI_CIO_IRQ_ERRCONTENTIONLP0_5 (1 << 28)
  164. #define DSI_CIO_IRQ_ERRCONTENTIONLP1_5 (1 << 29)
  165. #define DSI_CIO_IRQ_ULPSACTIVENOT_ALL0 (1 << 30)
  166. #define DSI_CIO_IRQ_ULPSACTIVENOT_ALL1 (1 << 31)
  167. #define DSI_CIO_IRQ_ERROR_MASK \
  168. (DSI_CIO_IRQ_ERRSYNCESC1 | DSI_CIO_IRQ_ERRSYNCESC2 | \
  169. DSI_CIO_IRQ_ERRSYNCESC3 | DSI_CIO_IRQ_ERRSYNCESC4 | \
  170. DSI_CIO_IRQ_ERRSYNCESC5 | \
  171. DSI_CIO_IRQ_ERRESC1 | DSI_CIO_IRQ_ERRESC2 | \
  172. DSI_CIO_IRQ_ERRESC3 | DSI_CIO_IRQ_ERRESC4 | \
  173. DSI_CIO_IRQ_ERRESC5 | \
  174. DSI_CIO_IRQ_ERRCONTROL1 | DSI_CIO_IRQ_ERRCONTROL2 | \
  175. DSI_CIO_IRQ_ERRCONTROL3 | DSI_CIO_IRQ_ERRCONTROL4 | \
  176. DSI_CIO_IRQ_ERRCONTROL5 | \
  177. DSI_CIO_IRQ_ERRCONTENTIONLP0_1 | DSI_CIO_IRQ_ERRCONTENTIONLP1_1 | \
  178. DSI_CIO_IRQ_ERRCONTENTIONLP0_2 | DSI_CIO_IRQ_ERRCONTENTIONLP1_2 | \
  179. DSI_CIO_IRQ_ERRCONTENTIONLP0_3 | DSI_CIO_IRQ_ERRCONTENTIONLP1_3 | \
  180. DSI_CIO_IRQ_ERRCONTENTIONLP0_4 | DSI_CIO_IRQ_ERRCONTENTIONLP1_4 | \
  181. DSI_CIO_IRQ_ERRCONTENTIONLP0_5 | DSI_CIO_IRQ_ERRCONTENTIONLP1_5)
  182. #define DSI_DT_DCS_SHORT_WRITE_0 0x05
  183. #define DSI_DT_DCS_SHORT_WRITE_1 0x15
  184. #define DSI_DT_DCS_READ 0x06
  185. #define DSI_DT_SET_MAX_RET_PKG_SIZE 0x37
  186. #define DSI_DT_NULL_PACKET 0x09
  187. #define DSI_DT_DCS_LONG_WRITE 0x39
  188. #define DSI_DT_RX_ACK_WITH_ERR 0x02
  189. #define DSI_DT_RX_LONG_READ 0x1a
  190. #define DSI_DT_RX_DCS_LONG_READ 0x1c
  191. #define DSI_DT_RX_SHORT_READ_1 0x21
  192. #define DSI_DT_RX_SHORT_READ_2 0x22
  193. typedef void (*omap_dsi_isr_t) (void *arg, u32 mask);
  194. #define DSI_MAX_NR_ISRS 2
  195. struct dsi_isr_data {
  196. omap_dsi_isr_t isr;
  197. void *arg;
  198. u32 mask;
  199. };
  200. enum fifo_size {
  201. DSI_FIFO_SIZE_0 = 0,
  202. DSI_FIFO_SIZE_32 = 1,
  203. DSI_FIFO_SIZE_64 = 2,
  204. DSI_FIFO_SIZE_96 = 3,
  205. DSI_FIFO_SIZE_128 = 4,
  206. };
  207. enum dsi_vc_mode {
  208. DSI_VC_MODE_L4 = 0,
  209. DSI_VC_MODE_VP,
  210. };
  211. enum dsi_lane {
  212. DSI_CLK_P = 1 << 0,
  213. DSI_CLK_N = 1 << 1,
  214. DSI_DATA1_P = 1 << 2,
  215. DSI_DATA1_N = 1 << 3,
  216. DSI_DATA2_P = 1 << 4,
  217. DSI_DATA2_N = 1 << 5,
  218. DSI_DATA3_P = 1 << 6,
  219. DSI_DATA3_N = 1 << 7,
  220. DSI_DATA4_P = 1 << 8,
  221. DSI_DATA4_N = 1 << 9,
  222. };
  223. struct dsi_update_region {
  224. u16 x, y, w, h;
  225. struct omap_dss_device *device;
  226. };
  227. struct dsi_irq_stats {
  228. unsigned long last_reset;
  229. unsigned irq_count;
  230. unsigned dsi_irqs[32];
  231. unsigned vc_irqs[4][32];
  232. unsigned cio_irqs[32];
  233. };
  234. struct dsi_isr_tables {
  235. struct dsi_isr_data isr_table[DSI_MAX_NR_ISRS];
  236. struct dsi_isr_data isr_table_vc[4][DSI_MAX_NR_ISRS];
  237. struct dsi_isr_data isr_table_cio[DSI_MAX_NR_ISRS];
  238. };
  239. struct dsi_data {
  240. struct platform_device *pdev;
  241. void __iomem *base;
  242. struct mutex runtime_lock;
  243. int runtime_count;
  244. int irq;
  245. struct clk *dss_clk;
  246. struct clk *sys_clk;
  247. void (*dsi_mux_pads)(bool enable);
  248. struct dsi_clock_info current_cinfo;
  249. bool vdds_dsi_enabled;
  250. struct regulator *vdds_dsi_reg;
  251. struct {
  252. enum dsi_vc_mode mode;
  253. struct omap_dss_device *dssdev;
  254. enum fifo_size fifo_size;
  255. int vc_id;
  256. } vc[4];
  257. struct mutex lock;
  258. struct semaphore bus_lock;
  259. unsigned pll_locked;
  260. spinlock_t irq_lock;
  261. struct dsi_isr_tables isr_tables;
  262. /* space for a copy used by the interrupt handler */
  263. struct dsi_isr_tables isr_tables_copy;
  264. int update_channel;
  265. struct dsi_update_region update_region;
  266. bool te_enabled;
  267. bool ulps_enabled;
  268. void (*framedone_callback)(int, void *);
  269. void *framedone_data;
  270. struct delayed_work framedone_timeout_work;
  271. #ifdef DSI_CATCH_MISSING_TE
  272. struct timer_list te_timer;
  273. #endif
  274. unsigned long cache_req_pck;
  275. unsigned long cache_clk_freq;
  276. struct dsi_clock_info cache_cinfo;
  277. u32 errors;
  278. spinlock_t errors_lock;
  279. #ifdef DEBUG
  280. ktime_t perf_setup_time;
  281. ktime_t perf_start_time;
  282. #endif
  283. int debug_read;
  284. int debug_write;
  285. #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
  286. spinlock_t irq_stats_lock;
  287. struct dsi_irq_stats irq_stats;
  288. #endif
  289. /* DSI PLL Parameter Ranges */
  290. unsigned long regm_max, regn_max;
  291. unsigned long regm_dispc_max, regm_dsi_max;
  292. unsigned long fint_min, fint_max;
  293. unsigned long lpdiv_max;
  294. int num_data_lanes;
  295. unsigned scp_clk_refcount;
  296. };
  297. struct dsi_packet_sent_handler_data {
  298. struct platform_device *dsidev;
  299. struct completion *completion;
  300. };
  301. static struct platform_device *dsi_pdev_map[MAX_NUM_DSI];
  302. #ifdef DEBUG
  303. static unsigned int dsi_perf;
  304. module_param_named(dsi_perf, dsi_perf, bool, 0644);
  305. #endif
  306. static inline struct dsi_data *dsi_get_dsidrv_data(struct platform_device *dsidev)
  307. {
  308. return dev_get_drvdata(&dsidev->dev);
  309. }
  310. static inline struct platform_device *dsi_get_dsidev_from_dssdev(struct omap_dss_device *dssdev)
  311. {
  312. return dsi_pdev_map[dssdev->phy.dsi.module];
  313. }
  314. struct platform_device *dsi_get_dsidev_from_id(int module)
  315. {
  316. return dsi_pdev_map[module];
  317. }
  318. static int dsi_get_dsidev_id(struct platform_device *dsidev)
  319. {
  320. /* TEMP: Pass 0 as the dsi module index till the time the dsi platform
  321. * device names aren't changed to the form "omapdss_dsi.0",
  322. * "omapdss_dsi.1" and so on */
  323. BUG_ON(dsidev->id != -1);
  324. return 0;
  325. }
  326. static inline void dsi_write_reg(struct platform_device *dsidev,
  327. const struct dsi_reg idx, u32 val)
  328. {
  329. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  330. __raw_writel(val, dsi->base + idx.idx);
  331. }
  332. static inline u32 dsi_read_reg(struct platform_device *dsidev,
  333. const struct dsi_reg idx)
  334. {
  335. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  336. return __raw_readl(dsi->base + idx.idx);
  337. }
  338. void dsi_bus_lock(struct omap_dss_device *dssdev)
  339. {
  340. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  341. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  342. down(&dsi->bus_lock);
  343. }
  344. EXPORT_SYMBOL(dsi_bus_lock);
  345. void dsi_bus_unlock(struct omap_dss_device *dssdev)
  346. {
  347. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  348. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  349. up(&dsi->bus_lock);
  350. }
  351. EXPORT_SYMBOL(dsi_bus_unlock);
  352. static bool dsi_bus_is_locked(struct platform_device *dsidev)
  353. {
  354. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  355. return dsi->bus_lock.count == 0;
  356. }
  357. static void dsi_completion_handler(void *data, u32 mask)
  358. {
  359. complete((struct completion *)data);
  360. }
  361. static inline int wait_for_bit_change(struct platform_device *dsidev,
  362. const struct dsi_reg idx, int bitnum, int value)
  363. {
  364. int t = 100000;
  365. while (REG_GET(dsidev, idx, bitnum, bitnum) != value) {
  366. if (--t == 0)
  367. return !value;
  368. }
  369. return value;
  370. }
  371. #ifdef DEBUG
  372. static void dsi_perf_mark_setup(struct platform_device *dsidev)
  373. {
  374. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  375. dsi->perf_setup_time = ktime_get();
  376. }
  377. static void dsi_perf_mark_start(struct platform_device *dsidev)
  378. {
  379. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  380. dsi->perf_start_time = ktime_get();
  381. }
  382. static void dsi_perf_show(struct platform_device *dsidev, const char *name)
  383. {
  384. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  385. ktime_t t, setup_time, trans_time;
  386. u32 total_bytes;
  387. u32 setup_us, trans_us, total_us;
  388. if (!dsi_perf)
  389. return;
  390. t = ktime_get();
  391. setup_time = ktime_sub(dsi->perf_start_time, dsi->perf_setup_time);
  392. setup_us = (u32)ktime_to_us(setup_time);
  393. if (setup_us == 0)
  394. setup_us = 1;
  395. trans_time = ktime_sub(t, dsi->perf_start_time);
  396. trans_us = (u32)ktime_to_us(trans_time);
  397. if (trans_us == 0)
  398. trans_us = 1;
  399. total_us = setup_us + trans_us;
  400. total_bytes = dsi->update_region.w *
  401. dsi->update_region.h *
  402. dsi->update_region.device->ctrl.pixel_size / 8;
  403. printk(KERN_INFO "DSI(%s): %u us + %u us = %u us (%uHz), "
  404. "%u bytes, %u kbytes/sec\n",
  405. name,
  406. setup_us,
  407. trans_us,
  408. total_us,
  409. 1000*1000 / total_us,
  410. total_bytes,
  411. total_bytes * 1000 / total_us);
  412. }
  413. #else
  414. static inline void dsi_perf_mark_setup(struct platform_device *dsidev)
  415. {
  416. }
  417. static inline void dsi_perf_mark_start(struct platform_device *dsidev)
  418. {
  419. }
  420. static inline void dsi_perf_show(struct platform_device *dsidev,
  421. const char *name)
  422. {
  423. }
  424. #endif
  425. static void print_irq_status(u32 status)
  426. {
  427. if (status == 0)
  428. return;
  429. #ifndef VERBOSE_IRQ
  430. if ((status & ~DSI_IRQ_CHANNEL_MASK) == 0)
  431. return;
  432. #endif
  433. printk(KERN_DEBUG "DSI IRQ: 0x%x: ", status);
  434. #define PIS(x) \
  435. if (status & DSI_IRQ_##x) \
  436. printk(#x " ");
  437. #ifdef VERBOSE_IRQ
  438. PIS(VC0);
  439. PIS(VC1);
  440. PIS(VC2);
  441. PIS(VC3);
  442. #endif
  443. PIS(WAKEUP);
  444. PIS(RESYNC);
  445. PIS(PLL_LOCK);
  446. PIS(PLL_UNLOCK);
  447. PIS(PLL_RECALL);
  448. PIS(COMPLEXIO_ERR);
  449. PIS(HS_TX_TIMEOUT);
  450. PIS(LP_RX_TIMEOUT);
  451. PIS(TE_TRIGGER);
  452. PIS(ACK_TRIGGER);
  453. PIS(SYNC_LOST);
  454. PIS(LDO_POWER_GOOD);
  455. PIS(TA_TIMEOUT);
  456. #undef PIS
  457. printk("\n");
  458. }
  459. static void print_irq_status_vc(int channel, u32 status)
  460. {
  461. if (status == 0)
  462. return;
  463. #ifndef VERBOSE_IRQ
  464. if ((status & ~DSI_VC_IRQ_PACKET_SENT) == 0)
  465. return;
  466. #endif
  467. printk(KERN_DEBUG "DSI VC(%d) IRQ 0x%x: ", channel, status);
  468. #define PIS(x) \
  469. if (status & DSI_VC_IRQ_##x) \
  470. printk(#x " ");
  471. PIS(CS);
  472. PIS(ECC_CORR);
  473. #ifdef VERBOSE_IRQ
  474. PIS(PACKET_SENT);
  475. #endif
  476. PIS(FIFO_TX_OVF);
  477. PIS(FIFO_RX_OVF);
  478. PIS(BTA);
  479. PIS(ECC_NO_CORR);
  480. PIS(FIFO_TX_UDF);
  481. PIS(PP_BUSY_CHANGE);
  482. #undef PIS
  483. printk("\n");
  484. }
  485. static void print_irq_status_cio(u32 status)
  486. {
  487. if (status == 0)
  488. return;
  489. printk(KERN_DEBUG "DSI CIO IRQ 0x%x: ", status);
  490. #define PIS(x) \
  491. if (status & DSI_CIO_IRQ_##x) \
  492. printk(#x " ");
  493. PIS(ERRSYNCESC1);
  494. PIS(ERRSYNCESC2);
  495. PIS(ERRSYNCESC3);
  496. PIS(ERRESC1);
  497. PIS(ERRESC2);
  498. PIS(ERRESC3);
  499. PIS(ERRCONTROL1);
  500. PIS(ERRCONTROL2);
  501. PIS(ERRCONTROL3);
  502. PIS(STATEULPS1);
  503. PIS(STATEULPS2);
  504. PIS(STATEULPS3);
  505. PIS(ERRCONTENTIONLP0_1);
  506. PIS(ERRCONTENTIONLP1_1);
  507. PIS(ERRCONTENTIONLP0_2);
  508. PIS(ERRCONTENTIONLP1_2);
  509. PIS(ERRCONTENTIONLP0_3);
  510. PIS(ERRCONTENTIONLP1_3);
  511. PIS(ULPSACTIVENOT_ALL0);
  512. PIS(ULPSACTIVENOT_ALL1);
  513. #undef PIS
  514. printk("\n");
  515. }
  516. #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
  517. static void dsi_collect_irq_stats(struct platform_device *dsidev, u32 irqstatus,
  518. u32 *vcstatus, u32 ciostatus)
  519. {
  520. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  521. int i;
  522. spin_lock(&dsi->irq_stats_lock);
  523. dsi->irq_stats.irq_count++;
  524. dss_collect_irq_stats(irqstatus, dsi->irq_stats.dsi_irqs);
  525. for (i = 0; i < 4; ++i)
  526. dss_collect_irq_stats(vcstatus[i], dsi->irq_stats.vc_irqs[i]);
  527. dss_collect_irq_stats(ciostatus, dsi->irq_stats.cio_irqs);
  528. spin_unlock(&dsi->irq_stats_lock);
  529. }
  530. #else
  531. #define dsi_collect_irq_stats(dsidev, irqstatus, vcstatus, ciostatus)
  532. #endif
  533. static int debug_irq;
  534. static void dsi_handle_irq_errors(struct platform_device *dsidev, u32 irqstatus,
  535. u32 *vcstatus, u32 ciostatus)
  536. {
  537. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  538. int i;
  539. if (irqstatus & DSI_IRQ_ERROR_MASK) {
  540. DSSERR("DSI error, irqstatus %x\n", irqstatus);
  541. print_irq_status(irqstatus);
  542. spin_lock(&dsi->errors_lock);
  543. dsi->errors |= irqstatus & DSI_IRQ_ERROR_MASK;
  544. spin_unlock(&dsi->errors_lock);
  545. } else if (debug_irq) {
  546. print_irq_status(irqstatus);
  547. }
  548. for (i = 0; i < 4; ++i) {
  549. if (vcstatus[i] & DSI_VC_IRQ_ERROR_MASK) {
  550. DSSERR("DSI VC(%d) error, vc irqstatus %x\n",
  551. i, vcstatus[i]);
  552. print_irq_status_vc(i, vcstatus[i]);
  553. } else if (debug_irq) {
  554. print_irq_status_vc(i, vcstatus[i]);
  555. }
  556. }
  557. if (ciostatus & DSI_CIO_IRQ_ERROR_MASK) {
  558. DSSERR("DSI CIO error, cio irqstatus %x\n", ciostatus);
  559. print_irq_status_cio(ciostatus);
  560. } else if (debug_irq) {
  561. print_irq_status_cio(ciostatus);
  562. }
  563. }
  564. static void dsi_call_isrs(struct dsi_isr_data *isr_array,
  565. unsigned isr_array_size, u32 irqstatus)
  566. {
  567. struct dsi_isr_data *isr_data;
  568. int i;
  569. for (i = 0; i < isr_array_size; i++) {
  570. isr_data = &isr_array[i];
  571. if (isr_data->isr && isr_data->mask & irqstatus)
  572. isr_data->isr(isr_data->arg, irqstatus);
  573. }
  574. }
  575. static void dsi_handle_isrs(struct dsi_isr_tables *isr_tables,
  576. u32 irqstatus, u32 *vcstatus, u32 ciostatus)
  577. {
  578. int i;
  579. dsi_call_isrs(isr_tables->isr_table,
  580. ARRAY_SIZE(isr_tables->isr_table),
  581. irqstatus);
  582. for (i = 0; i < 4; ++i) {
  583. if (vcstatus[i] == 0)
  584. continue;
  585. dsi_call_isrs(isr_tables->isr_table_vc[i],
  586. ARRAY_SIZE(isr_tables->isr_table_vc[i]),
  587. vcstatus[i]);
  588. }
  589. if (ciostatus != 0)
  590. dsi_call_isrs(isr_tables->isr_table_cio,
  591. ARRAY_SIZE(isr_tables->isr_table_cio),
  592. ciostatus);
  593. }
  594. static irqreturn_t omap_dsi_irq_handler(int irq, void *arg)
  595. {
  596. struct platform_device *dsidev;
  597. struct dsi_data *dsi;
  598. u32 irqstatus, vcstatus[4], ciostatus;
  599. int i;
  600. dsidev = (struct platform_device *) arg;
  601. dsi = dsi_get_dsidrv_data(dsidev);
  602. spin_lock(&dsi->irq_lock);
  603. irqstatus = dsi_read_reg(dsidev, DSI_IRQSTATUS);
  604. /* IRQ is not for us */
  605. if (!irqstatus) {
  606. spin_unlock(&dsi->irq_lock);
  607. return IRQ_NONE;
  608. }
  609. dsi_write_reg(dsidev, DSI_IRQSTATUS, irqstatus & ~DSI_IRQ_CHANNEL_MASK);
  610. /* flush posted write */
  611. dsi_read_reg(dsidev, DSI_IRQSTATUS);
  612. for (i = 0; i < 4; ++i) {
  613. if ((irqstatus & (1 << i)) == 0) {
  614. vcstatus[i] = 0;
  615. continue;
  616. }
  617. vcstatus[i] = dsi_read_reg(dsidev, DSI_VC_IRQSTATUS(i));
  618. dsi_write_reg(dsidev, DSI_VC_IRQSTATUS(i), vcstatus[i]);
  619. /* flush posted write */
  620. dsi_read_reg(dsidev, DSI_VC_IRQSTATUS(i));
  621. }
  622. if (irqstatus & DSI_IRQ_COMPLEXIO_ERR) {
  623. ciostatus = dsi_read_reg(dsidev, DSI_COMPLEXIO_IRQ_STATUS);
  624. dsi_write_reg(dsidev, DSI_COMPLEXIO_IRQ_STATUS, ciostatus);
  625. /* flush posted write */
  626. dsi_read_reg(dsidev, DSI_COMPLEXIO_IRQ_STATUS);
  627. } else {
  628. ciostatus = 0;
  629. }
  630. #ifdef DSI_CATCH_MISSING_TE
  631. if (irqstatus & DSI_IRQ_TE_TRIGGER)
  632. del_timer(&dsi->te_timer);
  633. #endif
  634. /* make a copy and unlock, so that isrs can unregister
  635. * themselves */
  636. memcpy(&dsi->isr_tables_copy, &dsi->isr_tables,
  637. sizeof(dsi->isr_tables));
  638. spin_unlock(&dsi->irq_lock);
  639. dsi_handle_isrs(&dsi->isr_tables_copy, irqstatus, vcstatus, ciostatus);
  640. dsi_handle_irq_errors(dsidev, irqstatus, vcstatus, ciostatus);
  641. dsi_collect_irq_stats(dsidev, irqstatus, vcstatus, ciostatus);
  642. return IRQ_HANDLED;
  643. }
  644. /* dsi->irq_lock has to be locked by the caller */
  645. static void _omap_dsi_configure_irqs(struct platform_device *dsidev,
  646. struct dsi_isr_data *isr_array,
  647. unsigned isr_array_size, u32 default_mask,
  648. const struct dsi_reg enable_reg,
  649. const struct dsi_reg status_reg)
  650. {
  651. struct dsi_isr_data *isr_data;
  652. u32 mask;
  653. u32 old_mask;
  654. int i;
  655. mask = default_mask;
  656. for (i = 0; i < isr_array_size; i++) {
  657. isr_data = &isr_array[i];
  658. if (isr_data->isr == NULL)
  659. continue;
  660. mask |= isr_data->mask;
  661. }
  662. old_mask = dsi_read_reg(dsidev, enable_reg);
  663. /* clear the irqstatus for newly enabled irqs */
  664. dsi_write_reg(dsidev, status_reg, (mask ^ old_mask) & mask);
  665. dsi_write_reg(dsidev, enable_reg, mask);
  666. /* flush posted writes */
  667. dsi_read_reg(dsidev, enable_reg);
  668. dsi_read_reg(dsidev, status_reg);
  669. }
  670. /* dsi->irq_lock has to be locked by the caller */
  671. static void _omap_dsi_set_irqs(struct platform_device *dsidev)
  672. {
  673. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  674. u32 mask = DSI_IRQ_ERROR_MASK;
  675. #ifdef DSI_CATCH_MISSING_TE
  676. mask |= DSI_IRQ_TE_TRIGGER;
  677. #endif
  678. _omap_dsi_configure_irqs(dsidev, dsi->isr_tables.isr_table,
  679. ARRAY_SIZE(dsi->isr_tables.isr_table), mask,
  680. DSI_IRQENABLE, DSI_IRQSTATUS);
  681. }
  682. /* dsi->irq_lock has to be locked by the caller */
  683. static void _omap_dsi_set_irqs_vc(struct platform_device *dsidev, int vc)
  684. {
  685. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  686. _omap_dsi_configure_irqs(dsidev, dsi->isr_tables.isr_table_vc[vc],
  687. ARRAY_SIZE(dsi->isr_tables.isr_table_vc[vc]),
  688. DSI_VC_IRQ_ERROR_MASK,
  689. DSI_VC_IRQENABLE(vc), DSI_VC_IRQSTATUS(vc));
  690. }
  691. /* dsi->irq_lock has to be locked by the caller */
  692. static void _omap_dsi_set_irqs_cio(struct platform_device *dsidev)
  693. {
  694. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  695. _omap_dsi_configure_irqs(dsidev, dsi->isr_tables.isr_table_cio,
  696. ARRAY_SIZE(dsi->isr_tables.isr_table_cio),
  697. DSI_CIO_IRQ_ERROR_MASK,
  698. DSI_COMPLEXIO_IRQ_ENABLE, DSI_COMPLEXIO_IRQ_STATUS);
  699. }
  700. static void _dsi_initialize_irq(struct platform_device *dsidev)
  701. {
  702. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  703. unsigned long flags;
  704. int vc;
  705. spin_lock_irqsave(&dsi->irq_lock, flags);
  706. memset(&dsi->isr_tables, 0, sizeof(dsi->isr_tables));
  707. _omap_dsi_set_irqs(dsidev);
  708. for (vc = 0; vc < 4; ++vc)
  709. _omap_dsi_set_irqs_vc(dsidev, vc);
  710. _omap_dsi_set_irqs_cio(dsidev);
  711. spin_unlock_irqrestore(&dsi->irq_lock, flags);
  712. }
  713. static int _dsi_register_isr(omap_dsi_isr_t isr, void *arg, u32 mask,
  714. struct dsi_isr_data *isr_array, unsigned isr_array_size)
  715. {
  716. struct dsi_isr_data *isr_data;
  717. int free_idx;
  718. int i;
  719. BUG_ON(isr == NULL);
  720. /* check for duplicate entry and find a free slot */
  721. free_idx = -1;
  722. for (i = 0; i < isr_array_size; i++) {
  723. isr_data = &isr_array[i];
  724. if (isr_data->isr == isr && isr_data->arg == arg &&
  725. isr_data->mask == mask) {
  726. return -EINVAL;
  727. }
  728. if (isr_data->isr == NULL && free_idx == -1)
  729. free_idx = i;
  730. }
  731. if (free_idx == -1)
  732. return -EBUSY;
  733. isr_data = &isr_array[free_idx];
  734. isr_data->isr = isr;
  735. isr_data->arg = arg;
  736. isr_data->mask = mask;
  737. return 0;
  738. }
  739. static int _dsi_unregister_isr(omap_dsi_isr_t isr, void *arg, u32 mask,
  740. struct dsi_isr_data *isr_array, unsigned isr_array_size)
  741. {
  742. struct dsi_isr_data *isr_data;
  743. int i;
  744. for (i = 0; i < isr_array_size; i++) {
  745. isr_data = &isr_array[i];
  746. if (isr_data->isr != isr || isr_data->arg != arg ||
  747. isr_data->mask != mask)
  748. continue;
  749. isr_data->isr = NULL;
  750. isr_data->arg = NULL;
  751. isr_data->mask = 0;
  752. return 0;
  753. }
  754. return -EINVAL;
  755. }
  756. static int dsi_register_isr(struct platform_device *dsidev, omap_dsi_isr_t isr,
  757. void *arg, u32 mask)
  758. {
  759. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  760. unsigned long flags;
  761. int r;
  762. spin_lock_irqsave(&dsi->irq_lock, flags);
  763. r = _dsi_register_isr(isr, arg, mask, dsi->isr_tables.isr_table,
  764. ARRAY_SIZE(dsi->isr_tables.isr_table));
  765. if (r == 0)
  766. _omap_dsi_set_irqs(dsidev);
  767. spin_unlock_irqrestore(&dsi->irq_lock, flags);
  768. return r;
  769. }
  770. static int dsi_unregister_isr(struct platform_device *dsidev,
  771. omap_dsi_isr_t isr, void *arg, u32 mask)
  772. {
  773. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  774. unsigned long flags;
  775. int r;
  776. spin_lock_irqsave(&dsi->irq_lock, flags);
  777. r = _dsi_unregister_isr(isr, arg, mask, dsi->isr_tables.isr_table,
  778. ARRAY_SIZE(dsi->isr_tables.isr_table));
  779. if (r == 0)
  780. _omap_dsi_set_irqs(dsidev);
  781. spin_unlock_irqrestore(&dsi->irq_lock, flags);
  782. return r;
  783. }
  784. static int dsi_register_isr_vc(struct platform_device *dsidev, int channel,
  785. omap_dsi_isr_t isr, void *arg, u32 mask)
  786. {
  787. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  788. unsigned long flags;
  789. int r;
  790. spin_lock_irqsave(&dsi->irq_lock, flags);
  791. r = _dsi_register_isr(isr, arg, mask,
  792. dsi->isr_tables.isr_table_vc[channel],
  793. ARRAY_SIZE(dsi->isr_tables.isr_table_vc[channel]));
  794. if (r == 0)
  795. _omap_dsi_set_irqs_vc(dsidev, channel);
  796. spin_unlock_irqrestore(&dsi->irq_lock, flags);
  797. return r;
  798. }
  799. static int dsi_unregister_isr_vc(struct platform_device *dsidev, int channel,
  800. omap_dsi_isr_t isr, void *arg, u32 mask)
  801. {
  802. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  803. unsigned long flags;
  804. int r;
  805. spin_lock_irqsave(&dsi->irq_lock, flags);
  806. r = _dsi_unregister_isr(isr, arg, mask,
  807. dsi->isr_tables.isr_table_vc[channel],
  808. ARRAY_SIZE(dsi->isr_tables.isr_table_vc[channel]));
  809. if (r == 0)
  810. _omap_dsi_set_irqs_vc(dsidev, channel);
  811. spin_unlock_irqrestore(&dsi->irq_lock, flags);
  812. return r;
  813. }
  814. static int dsi_register_isr_cio(struct platform_device *dsidev,
  815. omap_dsi_isr_t isr, void *arg, u32 mask)
  816. {
  817. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  818. unsigned long flags;
  819. int r;
  820. spin_lock_irqsave(&dsi->irq_lock, flags);
  821. r = _dsi_register_isr(isr, arg, mask, dsi->isr_tables.isr_table_cio,
  822. ARRAY_SIZE(dsi->isr_tables.isr_table_cio));
  823. if (r == 0)
  824. _omap_dsi_set_irqs_cio(dsidev);
  825. spin_unlock_irqrestore(&dsi->irq_lock, flags);
  826. return r;
  827. }
  828. static int dsi_unregister_isr_cio(struct platform_device *dsidev,
  829. omap_dsi_isr_t isr, void *arg, u32 mask)
  830. {
  831. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  832. unsigned long flags;
  833. int r;
  834. spin_lock_irqsave(&dsi->irq_lock, flags);
  835. r = _dsi_unregister_isr(isr, arg, mask, dsi->isr_tables.isr_table_cio,
  836. ARRAY_SIZE(dsi->isr_tables.isr_table_cio));
  837. if (r == 0)
  838. _omap_dsi_set_irqs_cio(dsidev);
  839. spin_unlock_irqrestore(&dsi->irq_lock, flags);
  840. return r;
  841. }
  842. static u32 dsi_get_errors(struct platform_device *dsidev)
  843. {
  844. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  845. unsigned long flags;
  846. u32 e;
  847. spin_lock_irqsave(&dsi->errors_lock, flags);
  848. e = dsi->errors;
  849. dsi->errors = 0;
  850. spin_unlock_irqrestore(&dsi->errors_lock, flags);
  851. return e;
  852. }
  853. int dsi_runtime_get(struct platform_device *dsidev)
  854. {
  855. int r;
  856. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  857. mutex_lock(&dsi->runtime_lock);
  858. if (dsi->runtime_count++ == 0) {
  859. DSSDBG("dsi_runtime_get\n");
  860. r = dss_runtime_get();
  861. if (r)
  862. goto err_get_dss;
  863. r = dispc_runtime_get();
  864. if (r)
  865. goto err_get_dispc;
  866. /* XXX dsi fclk can also come from DSI PLL */
  867. clk_enable(dsi->dss_clk);
  868. r = pm_runtime_get_sync(&dsi->pdev->dev);
  869. WARN_ON(r);
  870. if (r < 0)
  871. goto err_runtime_get;
  872. }
  873. mutex_unlock(&dsi->runtime_lock);
  874. return 0;
  875. err_runtime_get:
  876. clk_disable(dsi->dss_clk);
  877. dispc_runtime_put();
  878. err_get_dispc:
  879. dss_runtime_put();
  880. err_get_dss:
  881. mutex_unlock(&dsi->runtime_lock);
  882. return r;
  883. }
  884. void dsi_runtime_put(struct platform_device *dsidev)
  885. {
  886. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  887. mutex_lock(&dsi->runtime_lock);
  888. if (--dsi->runtime_count == 0) {
  889. int r;
  890. DSSDBG("dsi_runtime_put\n");
  891. r = pm_runtime_put_sync(&dsi->pdev->dev);
  892. WARN_ON(r);
  893. clk_disable(dsi->dss_clk);
  894. dispc_runtime_put();
  895. dss_runtime_put();
  896. }
  897. mutex_unlock(&dsi->runtime_lock);
  898. }
  899. /* source clock for DSI PLL. this could also be PCLKFREE */
  900. static inline void dsi_enable_pll_clock(struct platform_device *dsidev,
  901. bool enable)
  902. {
  903. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  904. if (enable)
  905. clk_enable(dsi->sys_clk);
  906. else
  907. clk_disable(dsi->sys_clk);
  908. if (enable && dsi->pll_locked) {
  909. if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 1, 1) != 1)
  910. DSSERR("cannot lock PLL when enabling clocks\n");
  911. }
  912. }
  913. #ifdef DEBUG
  914. static void _dsi_print_reset_status(struct platform_device *dsidev)
  915. {
  916. u32 l;
  917. int b0, b1, b2;
  918. if (!dss_debug)
  919. return;
  920. /* A dummy read using the SCP interface to any DSIPHY register is
  921. * required after DSIPHY reset to complete the reset of the DSI complex
  922. * I/O. */
  923. l = dsi_read_reg(dsidev, DSI_DSIPHY_CFG5);
  924. printk(KERN_DEBUG "DSI resets: ");
  925. l = dsi_read_reg(dsidev, DSI_PLL_STATUS);
  926. printk("PLL (%d) ", FLD_GET(l, 0, 0));
  927. l = dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG1);
  928. printk("CIO (%d) ", FLD_GET(l, 29, 29));
  929. if (dss_has_feature(FEAT_DSI_REVERSE_TXCLKESC)) {
  930. b0 = 28;
  931. b1 = 27;
  932. b2 = 26;
  933. } else {
  934. b0 = 24;
  935. b1 = 25;
  936. b2 = 26;
  937. }
  938. l = dsi_read_reg(dsidev, DSI_DSIPHY_CFG5);
  939. printk("PHY (%x%x%x, %d, %d, %d)\n",
  940. FLD_GET(l, b0, b0),
  941. FLD_GET(l, b1, b1),
  942. FLD_GET(l, b2, b2),
  943. FLD_GET(l, 29, 29),
  944. FLD_GET(l, 30, 30),
  945. FLD_GET(l, 31, 31));
  946. }
  947. #else
  948. #define _dsi_print_reset_status(x)
  949. #endif
  950. static inline int dsi_if_enable(struct platform_device *dsidev, bool enable)
  951. {
  952. DSSDBG("dsi_if_enable(%d)\n", enable);
  953. enable = enable ? 1 : 0;
  954. REG_FLD_MOD(dsidev, DSI_CTRL, enable, 0, 0); /* IF_EN */
  955. if (wait_for_bit_change(dsidev, DSI_CTRL, 0, enable) != enable) {
  956. DSSERR("Failed to set dsi_if_enable to %d\n", enable);
  957. return -EIO;
  958. }
  959. return 0;
  960. }
  961. unsigned long dsi_get_pll_hsdiv_dispc_rate(struct platform_device *dsidev)
  962. {
  963. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  964. return dsi->current_cinfo.dsi_pll_hsdiv_dispc_clk;
  965. }
  966. static unsigned long dsi_get_pll_hsdiv_dsi_rate(struct platform_device *dsidev)
  967. {
  968. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  969. return dsi->current_cinfo.dsi_pll_hsdiv_dsi_clk;
  970. }
  971. static unsigned long dsi_get_txbyteclkhs(struct platform_device *dsidev)
  972. {
  973. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  974. return dsi->current_cinfo.clkin4ddr / 16;
  975. }
  976. static unsigned long dsi_fclk_rate(struct platform_device *dsidev)
  977. {
  978. unsigned long r;
  979. int dsi_module = dsi_get_dsidev_id(dsidev);
  980. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  981. if (dss_get_dsi_clk_source(dsi_module) == OMAP_DSS_CLK_SRC_FCK) {
  982. /* DSI FCLK source is DSS_CLK_FCK */
  983. r = clk_get_rate(dsi->dss_clk);
  984. } else {
  985. /* DSI FCLK source is dsi_pll_hsdiv_dsi_clk */
  986. r = dsi_get_pll_hsdiv_dsi_rate(dsidev);
  987. }
  988. return r;
  989. }
  990. static int dsi_set_lp_clk_divisor(struct omap_dss_device *dssdev)
  991. {
  992. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  993. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  994. unsigned long dsi_fclk;
  995. unsigned lp_clk_div;
  996. unsigned long lp_clk;
  997. lp_clk_div = dssdev->clocks.dsi.lp_clk_div;
  998. if (lp_clk_div == 0 || lp_clk_div > dsi->lpdiv_max)
  999. return -EINVAL;
  1000. dsi_fclk = dsi_fclk_rate(dsidev);
  1001. lp_clk = dsi_fclk / 2 / lp_clk_div;
  1002. DSSDBG("LP_CLK_DIV %u, LP_CLK %lu\n", lp_clk_div, lp_clk);
  1003. dsi->current_cinfo.lp_clk = lp_clk;
  1004. dsi->current_cinfo.lp_clk_div = lp_clk_div;
  1005. /* LP_CLK_DIVISOR */
  1006. REG_FLD_MOD(dsidev, DSI_CLK_CTRL, lp_clk_div, 12, 0);
  1007. /* LP_RX_SYNCHRO_ENABLE */
  1008. REG_FLD_MOD(dsidev, DSI_CLK_CTRL, dsi_fclk > 30000000 ? 1 : 0, 21, 21);
  1009. return 0;
  1010. }
  1011. static void dsi_enable_scp_clk(struct platform_device *dsidev)
  1012. {
  1013. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1014. if (dsi->scp_clk_refcount++ == 0)
  1015. REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 1, 14, 14); /* CIO_CLK_ICG */
  1016. }
  1017. static void dsi_disable_scp_clk(struct platform_device *dsidev)
  1018. {
  1019. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1020. WARN_ON(dsi->scp_clk_refcount == 0);
  1021. if (--dsi->scp_clk_refcount == 0)
  1022. REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 0, 14, 14); /* CIO_CLK_ICG */
  1023. }
  1024. enum dsi_pll_power_state {
  1025. DSI_PLL_POWER_OFF = 0x0,
  1026. DSI_PLL_POWER_ON_HSCLK = 0x1,
  1027. DSI_PLL_POWER_ON_ALL = 0x2,
  1028. DSI_PLL_POWER_ON_DIV = 0x3,
  1029. };
  1030. static int dsi_pll_power(struct platform_device *dsidev,
  1031. enum dsi_pll_power_state state)
  1032. {
  1033. int t = 0;
  1034. /* DSI-PLL power command 0x3 is not working */
  1035. if (dss_has_feature(FEAT_DSI_PLL_PWR_BUG) &&
  1036. state == DSI_PLL_POWER_ON_DIV)
  1037. state = DSI_PLL_POWER_ON_ALL;
  1038. /* PLL_PWR_CMD */
  1039. REG_FLD_MOD(dsidev, DSI_CLK_CTRL, state, 31, 30);
  1040. /* PLL_PWR_STATUS */
  1041. while (FLD_GET(dsi_read_reg(dsidev, DSI_CLK_CTRL), 29, 28) != state) {
  1042. if (++t > 1000) {
  1043. DSSERR("Failed to set DSI PLL power mode to %d\n",
  1044. state);
  1045. return -ENODEV;
  1046. }
  1047. udelay(1);
  1048. }
  1049. return 0;
  1050. }
  1051. /* calculate clock rates using dividers in cinfo */
  1052. static int dsi_calc_clock_rates(struct omap_dss_device *dssdev,
  1053. struct dsi_clock_info *cinfo)
  1054. {
  1055. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  1056. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1057. if (cinfo->regn == 0 || cinfo->regn > dsi->regn_max)
  1058. return -EINVAL;
  1059. if (cinfo->regm == 0 || cinfo->regm > dsi->regm_max)
  1060. return -EINVAL;
  1061. if (cinfo->regm_dispc > dsi->regm_dispc_max)
  1062. return -EINVAL;
  1063. if (cinfo->regm_dsi > dsi->regm_dsi_max)
  1064. return -EINVAL;
  1065. if (cinfo->use_sys_clk) {
  1066. cinfo->clkin = clk_get_rate(dsi->sys_clk);
  1067. /* XXX it is unclear if highfreq should be used
  1068. * with DSS_SYS_CLK source also */
  1069. cinfo->highfreq = 0;
  1070. } else {
  1071. cinfo->clkin = dispc_pclk_rate(dssdev->manager->id);
  1072. if (cinfo->clkin < 32000000)
  1073. cinfo->highfreq = 0;
  1074. else
  1075. cinfo->highfreq = 1;
  1076. }
  1077. cinfo->fint = cinfo->clkin / (cinfo->regn * (cinfo->highfreq ? 2 : 1));
  1078. if (cinfo->fint > dsi->fint_max || cinfo->fint < dsi->fint_min)
  1079. return -EINVAL;
  1080. cinfo->clkin4ddr = 2 * cinfo->regm * cinfo->fint;
  1081. if (cinfo->clkin4ddr > 1800 * 1000 * 1000)
  1082. return -EINVAL;
  1083. if (cinfo->regm_dispc > 0)
  1084. cinfo->dsi_pll_hsdiv_dispc_clk =
  1085. cinfo->clkin4ddr / cinfo->regm_dispc;
  1086. else
  1087. cinfo->dsi_pll_hsdiv_dispc_clk = 0;
  1088. if (cinfo->regm_dsi > 0)
  1089. cinfo->dsi_pll_hsdiv_dsi_clk =
  1090. cinfo->clkin4ddr / cinfo->regm_dsi;
  1091. else
  1092. cinfo->dsi_pll_hsdiv_dsi_clk = 0;
  1093. return 0;
  1094. }
  1095. int dsi_pll_calc_clock_div_pck(struct platform_device *dsidev, bool is_tft,
  1096. unsigned long req_pck, struct dsi_clock_info *dsi_cinfo,
  1097. struct dispc_clock_info *dispc_cinfo)
  1098. {
  1099. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1100. struct dsi_clock_info cur, best;
  1101. struct dispc_clock_info best_dispc;
  1102. int min_fck_per_pck;
  1103. int match = 0;
  1104. unsigned long dss_sys_clk, max_dss_fck;
  1105. dss_sys_clk = clk_get_rate(dsi->sys_clk);
  1106. max_dss_fck = dss_feat_get_param_max(FEAT_PARAM_DSS_FCK);
  1107. if (req_pck == dsi->cache_req_pck &&
  1108. dsi->cache_cinfo.clkin == dss_sys_clk) {
  1109. DSSDBG("DSI clock info found from cache\n");
  1110. *dsi_cinfo = dsi->cache_cinfo;
  1111. dispc_find_clk_divs(is_tft, req_pck,
  1112. dsi_cinfo->dsi_pll_hsdiv_dispc_clk, dispc_cinfo);
  1113. return 0;
  1114. }
  1115. min_fck_per_pck = CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK;
  1116. if (min_fck_per_pck &&
  1117. req_pck * min_fck_per_pck > max_dss_fck) {
  1118. DSSERR("Requested pixel clock not possible with the current "
  1119. "OMAP2_DSS_MIN_FCK_PER_PCK setting. Turning "
  1120. "the constraint off.\n");
  1121. min_fck_per_pck = 0;
  1122. }
  1123. DSSDBG("dsi_pll_calc\n");
  1124. retry:
  1125. memset(&best, 0, sizeof(best));
  1126. memset(&best_dispc, 0, sizeof(best_dispc));
  1127. memset(&cur, 0, sizeof(cur));
  1128. cur.clkin = dss_sys_clk;
  1129. cur.use_sys_clk = 1;
  1130. cur.highfreq = 0;
  1131. /* no highfreq: 0.75MHz < Fint = clkin / regn < 2.1MHz */
  1132. /* highfreq: 0.75MHz < Fint = clkin / (2*regn) < 2.1MHz */
  1133. /* To reduce PLL lock time, keep Fint high (around 2 MHz) */
  1134. for (cur.regn = 1; cur.regn < dsi->regn_max; ++cur.regn) {
  1135. if (cur.highfreq == 0)
  1136. cur.fint = cur.clkin / cur.regn;
  1137. else
  1138. cur.fint = cur.clkin / (2 * cur.regn);
  1139. if (cur.fint > dsi->fint_max || cur.fint < dsi->fint_min)
  1140. continue;
  1141. /* DSIPHY(MHz) = (2 * regm / regn) * (clkin / (highfreq + 1)) */
  1142. for (cur.regm = 1; cur.regm < dsi->regm_max; ++cur.regm) {
  1143. unsigned long a, b;
  1144. a = 2 * cur.regm * (cur.clkin/1000);
  1145. b = cur.regn * (cur.highfreq + 1);
  1146. cur.clkin4ddr = a / b * 1000;
  1147. if (cur.clkin4ddr > 1800 * 1000 * 1000)
  1148. break;
  1149. /* dsi_pll_hsdiv_dispc_clk(MHz) =
  1150. * DSIPHY(MHz) / regm_dispc < 173MHz/186Mhz */
  1151. for (cur.regm_dispc = 1; cur.regm_dispc <
  1152. dsi->regm_dispc_max; ++cur.regm_dispc) {
  1153. struct dispc_clock_info cur_dispc;
  1154. cur.dsi_pll_hsdiv_dispc_clk =
  1155. cur.clkin4ddr / cur.regm_dispc;
  1156. /* this will narrow down the search a bit,
  1157. * but still give pixclocks below what was
  1158. * requested */
  1159. if (cur.dsi_pll_hsdiv_dispc_clk < req_pck)
  1160. break;
  1161. if (cur.dsi_pll_hsdiv_dispc_clk > max_dss_fck)
  1162. continue;
  1163. if (min_fck_per_pck &&
  1164. cur.dsi_pll_hsdiv_dispc_clk <
  1165. req_pck * min_fck_per_pck)
  1166. continue;
  1167. match = 1;
  1168. dispc_find_clk_divs(is_tft, req_pck,
  1169. cur.dsi_pll_hsdiv_dispc_clk,
  1170. &cur_dispc);
  1171. if (abs(cur_dispc.pck - req_pck) <
  1172. abs(best_dispc.pck - req_pck)) {
  1173. best = cur;
  1174. best_dispc = cur_dispc;
  1175. if (cur_dispc.pck == req_pck)
  1176. goto found;
  1177. }
  1178. }
  1179. }
  1180. }
  1181. found:
  1182. if (!match) {
  1183. if (min_fck_per_pck) {
  1184. DSSERR("Could not find suitable clock settings.\n"
  1185. "Turning FCK/PCK constraint off and"
  1186. "trying again.\n");
  1187. min_fck_per_pck = 0;
  1188. goto retry;
  1189. }
  1190. DSSERR("Could not find suitable clock settings.\n");
  1191. return -EINVAL;
  1192. }
  1193. /* dsi_pll_hsdiv_dsi_clk (regm_dsi) is not used */
  1194. best.regm_dsi = 0;
  1195. best.dsi_pll_hsdiv_dsi_clk = 0;
  1196. if (dsi_cinfo)
  1197. *dsi_cinfo = best;
  1198. if (dispc_cinfo)
  1199. *dispc_cinfo = best_dispc;
  1200. dsi->cache_req_pck = req_pck;
  1201. dsi->cache_clk_freq = 0;
  1202. dsi->cache_cinfo = best;
  1203. return 0;
  1204. }
  1205. int dsi_pll_set_clock_div(struct platform_device *dsidev,
  1206. struct dsi_clock_info *cinfo)
  1207. {
  1208. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1209. int r = 0;
  1210. u32 l;
  1211. int f = 0;
  1212. u8 regn_start, regn_end, regm_start, regm_end;
  1213. u8 regm_dispc_start, regm_dispc_end, regm_dsi_start, regm_dsi_end;
  1214. DSSDBGF();
  1215. dsi->current_cinfo.use_sys_clk = cinfo->use_sys_clk;
  1216. dsi->current_cinfo.highfreq = cinfo->highfreq;
  1217. dsi->current_cinfo.fint = cinfo->fint;
  1218. dsi->current_cinfo.clkin4ddr = cinfo->clkin4ddr;
  1219. dsi->current_cinfo.dsi_pll_hsdiv_dispc_clk =
  1220. cinfo->dsi_pll_hsdiv_dispc_clk;
  1221. dsi->current_cinfo.dsi_pll_hsdiv_dsi_clk =
  1222. cinfo->dsi_pll_hsdiv_dsi_clk;
  1223. dsi->current_cinfo.regn = cinfo->regn;
  1224. dsi->current_cinfo.regm = cinfo->regm;
  1225. dsi->current_cinfo.regm_dispc = cinfo->regm_dispc;
  1226. dsi->current_cinfo.regm_dsi = cinfo->regm_dsi;
  1227. DSSDBG("DSI Fint %ld\n", cinfo->fint);
  1228. DSSDBG("clkin (%s) rate %ld, highfreq %d\n",
  1229. cinfo->use_sys_clk ? "dss_sys_clk" : "pclkfree",
  1230. cinfo->clkin,
  1231. cinfo->highfreq);
  1232. /* DSIPHY == CLKIN4DDR */
  1233. DSSDBG("CLKIN4DDR = 2 * %d / %d * %lu / %d = %lu\n",
  1234. cinfo->regm,
  1235. cinfo->regn,
  1236. cinfo->clkin,
  1237. cinfo->highfreq + 1,
  1238. cinfo->clkin4ddr);
  1239. DSSDBG("Data rate on 1 DSI lane %ld Mbps\n",
  1240. cinfo->clkin4ddr / 1000 / 1000 / 2);
  1241. DSSDBG("Clock lane freq %ld Hz\n", cinfo->clkin4ddr / 4);
  1242. DSSDBG("regm_dispc = %d, %s (%s) = %lu\n", cinfo->regm_dispc,
  1243. dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC),
  1244. dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC),
  1245. cinfo->dsi_pll_hsdiv_dispc_clk);
  1246. DSSDBG("regm_dsi = %d, %s (%s) = %lu\n", cinfo->regm_dsi,
  1247. dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI),
  1248. dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI),
  1249. cinfo->dsi_pll_hsdiv_dsi_clk);
  1250. dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGN, &regn_start, &regn_end);
  1251. dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM, &regm_start, &regm_end);
  1252. dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM_DISPC, &regm_dispc_start,
  1253. &regm_dispc_end);
  1254. dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM_DSI, &regm_dsi_start,
  1255. &regm_dsi_end);
  1256. /* DSI_PLL_AUTOMODE = manual */
  1257. REG_FLD_MOD(dsidev, DSI_PLL_CONTROL, 0, 0, 0);
  1258. l = dsi_read_reg(dsidev, DSI_PLL_CONFIGURATION1);
  1259. l = FLD_MOD(l, 1, 0, 0); /* DSI_PLL_STOPMODE */
  1260. /* DSI_PLL_REGN */
  1261. l = FLD_MOD(l, cinfo->regn - 1, regn_start, regn_end);
  1262. /* DSI_PLL_REGM */
  1263. l = FLD_MOD(l, cinfo->regm, regm_start, regm_end);
  1264. /* DSI_CLOCK_DIV */
  1265. l = FLD_MOD(l, cinfo->regm_dispc > 0 ? cinfo->regm_dispc - 1 : 0,
  1266. regm_dispc_start, regm_dispc_end);
  1267. /* DSIPROTO_CLOCK_DIV */
  1268. l = FLD_MOD(l, cinfo->regm_dsi > 0 ? cinfo->regm_dsi - 1 : 0,
  1269. regm_dsi_start, regm_dsi_end);
  1270. dsi_write_reg(dsidev, DSI_PLL_CONFIGURATION1, l);
  1271. BUG_ON(cinfo->fint < dsi->fint_min || cinfo->fint > dsi->fint_max);
  1272. if (dss_has_feature(FEAT_DSI_PLL_FREQSEL)) {
  1273. f = cinfo->fint < 1000000 ? 0x3 :
  1274. cinfo->fint < 1250000 ? 0x4 :
  1275. cinfo->fint < 1500000 ? 0x5 :
  1276. cinfo->fint < 1750000 ? 0x6 :
  1277. 0x7;
  1278. }
  1279. l = dsi_read_reg(dsidev, DSI_PLL_CONFIGURATION2);
  1280. if (dss_has_feature(FEAT_DSI_PLL_FREQSEL))
  1281. l = FLD_MOD(l, f, 4, 1); /* DSI_PLL_FREQSEL */
  1282. l = FLD_MOD(l, cinfo->use_sys_clk ? 0 : 1,
  1283. 11, 11); /* DSI_PLL_CLKSEL */
  1284. l = FLD_MOD(l, cinfo->highfreq,
  1285. 12, 12); /* DSI_PLL_HIGHFREQ */
  1286. l = FLD_MOD(l, 1, 13, 13); /* DSI_PLL_REFEN */
  1287. l = FLD_MOD(l, 0, 14, 14); /* DSIPHY_CLKINEN */
  1288. l = FLD_MOD(l, 1, 20, 20); /* DSI_HSDIVBYPASS */
  1289. if (cpu_is_omap44xx())
  1290. l = FLD_MOD(l, 3, 22, 21); /* DSI_REF_SEL */
  1291. dsi_write_reg(dsidev, DSI_PLL_CONFIGURATION2, l);
  1292. REG_FLD_MOD(dsidev, DSI_PLL_GO, 1, 0, 0); /* DSI_PLL_GO */
  1293. if (wait_for_bit_change(dsidev, DSI_PLL_GO, 0, 0) != 0) {
  1294. DSSERR("dsi pll go bit not going down.\n");
  1295. r = -EIO;
  1296. goto err;
  1297. }
  1298. if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 1, 1) != 1) {
  1299. DSSERR("cannot lock PLL\n");
  1300. r = -EIO;
  1301. goto err;
  1302. }
  1303. dsi->pll_locked = 1;
  1304. l = dsi_read_reg(dsidev, DSI_PLL_CONFIGURATION2);
  1305. l = FLD_MOD(l, 0, 0, 0); /* DSI_PLL_IDLE */
  1306. l = FLD_MOD(l, 0, 5, 5); /* DSI_PLL_PLLLPMODE */
  1307. l = FLD_MOD(l, 0, 6, 6); /* DSI_PLL_LOWCURRSTBY */
  1308. l = FLD_MOD(l, 0, 7, 7); /* DSI_PLL_TIGHTPHASELOCK */
  1309. l = FLD_MOD(l, 0, 8, 8); /* DSI_PLL_DRIFTGUARDEN */
  1310. l = FLD_MOD(l, 0, 10, 9); /* DSI_PLL_LOCKSEL */
  1311. l = FLD_MOD(l, 1, 13, 13); /* DSI_PLL_REFEN */
  1312. l = FLD_MOD(l, 1, 14, 14); /* DSIPHY_CLKINEN */
  1313. l = FLD_MOD(l, 0, 15, 15); /* DSI_BYPASSEN */
  1314. l = FLD_MOD(l, 1, 16, 16); /* DSS_CLOCK_EN */
  1315. l = FLD_MOD(l, 0, 17, 17); /* DSS_CLOCK_PWDN */
  1316. l = FLD_MOD(l, 1, 18, 18); /* DSI_PROTO_CLOCK_EN */
  1317. l = FLD_MOD(l, 0, 19, 19); /* DSI_PROTO_CLOCK_PWDN */
  1318. l = FLD_MOD(l, 0, 20, 20); /* DSI_HSDIVBYPASS */
  1319. dsi_write_reg(dsidev, DSI_PLL_CONFIGURATION2, l);
  1320. DSSDBG("PLL config done\n");
  1321. err:
  1322. return r;
  1323. }
  1324. int dsi_pll_init(struct platform_device *dsidev, bool enable_hsclk,
  1325. bool enable_hsdiv)
  1326. {
  1327. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1328. int r = 0;
  1329. enum dsi_pll_power_state pwstate;
  1330. DSSDBG("PLL init\n");
  1331. if (dsi->vdds_dsi_reg == NULL) {
  1332. struct regulator *vdds_dsi;
  1333. vdds_dsi = regulator_get(&dsi->pdev->dev, "vdds_dsi");
  1334. if (IS_ERR(vdds_dsi)) {
  1335. DSSERR("can't get VDDS_DSI regulator\n");
  1336. return PTR_ERR(vdds_dsi);
  1337. }
  1338. dsi->vdds_dsi_reg = vdds_dsi;
  1339. }
  1340. dsi_enable_pll_clock(dsidev, 1);
  1341. /*
  1342. * Note: SCP CLK is not required on OMAP3, but it is required on OMAP4.
  1343. */
  1344. dsi_enable_scp_clk(dsidev);
  1345. if (!dsi->vdds_dsi_enabled) {
  1346. r = regulator_enable(dsi->vdds_dsi_reg);
  1347. if (r)
  1348. goto err0;
  1349. dsi->vdds_dsi_enabled = true;
  1350. }
  1351. /* XXX PLL does not come out of reset without this... */
  1352. dispc_pck_free_enable(1);
  1353. if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 0, 1) != 1) {
  1354. DSSERR("PLL not coming out of reset.\n");
  1355. r = -ENODEV;
  1356. dispc_pck_free_enable(0);
  1357. goto err1;
  1358. }
  1359. /* XXX ... but if left on, we get problems when planes do not
  1360. * fill the whole display. No idea about this */
  1361. dispc_pck_free_enable(0);
  1362. if (enable_hsclk && enable_hsdiv)
  1363. pwstate = DSI_PLL_POWER_ON_ALL;
  1364. else if (enable_hsclk)
  1365. pwstate = DSI_PLL_POWER_ON_HSCLK;
  1366. else if (enable_hsdiv)
  1367. pwstate = DSI_PLL_POWER_ON_DIV;
  1368. else
  1369. pwstate = DSI_PLL_POWER_OFF;
  1370. r = dsi_pll_power(dsidev, pwstate);
  1371. if (r)
  1372. goto err1;
  1373. DSSDBG("PLL init done\n");
  1374. return 0;
  1375. err1:
  1376. if (dsi->vdds_dsi_enabled) {
  1377. regulator_disable(dsi->vdds_dsi_reg);
  1378. dsi->vdds_dsi_enabled = false;
  1379. }
  1380. err0:
  1381. dsi_disable_scp_clk(dsidev);
  1382. dsi_enable_pll_clock(dsidev, 0);
  1383. return r;
  1384. }
  1385. void dsi_pll_uninit(struct platform_device *dsidev, bool disconnect_lanes)
  1386. {
  1387. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1388. dsi->pll_locked = 0;
  1389. dsi_pll_power(dsidev, DSI_PLL_POWER_OFF);
  1390. if (disconnect_lanes) {
  1391. WARN_ON(!dsi->vdds_dsi_enabled);
  1392. regulator_disable(dsi->vdds_dsi_reg);
  1393. dsi->vdds_dsi_enabled = false;
  1394. }
  1395. dsi_disable_scp_clk(dsidev);
  1396. dsi_enable_pll_clock(dsidev, 0);
  1397. DSSDBG("PLL uninit done\n");
  1398. }
  1399. static void dsi_dump_dsidev_clocks(struct platform_device *dsidev,
  1400. struct seq_file *s)
  1401. {
  1402. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1403. struct dsi_clock_info *cinfo = &dsi->current_cinfo;
  1404. enum omap_dss_clk_source dispc_clk_src, dsi_clk_src;
  1405. int dsi_module = dsi_get_dsidev_id(dsidev);
  1406. dispc_clk_src = dss_get_dispc_clk_source();
  1407. dsi_clk_src = dss_get_dsi_clk_source(dsi_module);
  1408. if (dsi_runtime_get(dsidev))
  1409. return;
  1410. seq_printf(s, "- DSI%d PLL -\n", dsi_module + 1);
  1411. seq_printf(s, "dsi pll source = %s\n",
  1412. cinfo->use_sys_clk ? "dss_sys_clk" : "pclkfree");
  1413. seq_printf(s, "Fint\t\t%-16luregn %u\n", cinfo->fint, cinfo->regn);
  1414. seq_printf(s, "CLKIN4DDR\t%-16luregm %u\n",
  1415. cinfo->clkin4ddr, cinfo->regm);
  1416. seq_printf(s, "%s (%s)\t%-16luregm_dispc %u\t(%s)\n",
  1417. dss_get_generic_clk_source_name(dispc_clk_src),
  1418. dss_feat_get_clk_source_name(dispc_clk_src),
  1419. cinfo->dsi_pll_hsdiv_dispc_clk,
  1420. cinfo->regm_dispc,
  1421. dispc_clk_src == OMAP_DSS_CLK_SRC_FCK ?
  1422. "off" : "on");
  1423. seq_printf(s, "%s (%s)\t%-16luregm_dsi %u\t(%s)\n",
  1424. dss_get_generic_clk_source_name(dsi_clk_src),
  1425. dss_feat_get_clk_source_name(dsi_clk_src),
  1426. cinfo->dsi_pll_hsdiv_dsi_clk,
  1427. cinfo->regm_dsi,
  1428. dsi_clk_src == OMAP_DSS_CLK_SRC_FCK ?
  1429. "off" : "on");
  1430. seq_printf(s, "- DSI%d -\n", dsi_module + 1);
  1431. seq_printf(s, "dsi fclk source = %s (%s)\n",
  1432. dss_get_generic_clk_source_name(dsi_clk_src),
  1433. dss_feat_get_clk_source_name(dsi_clk_src));
  1434. seq_printf(s, "DSI_FCLK\t%lu\n", dsi_fclk_rate(dsidev));
  1435. seq_printf(s, "DDR_CLK\t\t%lu\n",
  1436. cinfo->clkin4ddr / 4);
  1437. seq_printf(s, "TxByteClkHS\t%lu\n", dsi_get_txbyteclkhs(dsidev));
  1438. seq_printf(s, "LP_CLK\t\t%lu\n", cinfo->lp_clk);
  1439. dsi_runtime_put(dsidev);
  1440. }
  1441. void dsi_dump_clocks(struct seq_file *s)
  1442. {
  1443. struct platform_device *dsidev;
  1444. int i;
  1445. for (i = 0; i < MAX_NUM_DSI; i++) {
  1446. dsidev = dsi_get_dsidev_from_id(i);
  1447. if (dsidev)
  1448. dsi_dump_dsidev_clocks(dsidev, s);
  1449. }
  1450. }
  1451. #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
  1452. static void dsi_dump_dsidev_irqs(struct platform_device *dsidev,
  1453. struct seq_file *s)
  1454. {
  1455. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1456. unsigned long flags;
  1457. struct dsi_irq_stats stats;
  1458. int dsi_module = dsi_get_dsidev_id(dsidev);
  1459. spin_lock_irqsave(&dsi->irq_stats_lock, flags);
  1460. stats = dsi->irq_stats;
  1461. memset(&dsi->irq_stats, 0, sizeof(dsi->irq_stats));
  1462. dsi->irq_stats.last_reset = jiffies;
  1463. spin_unlock_irqrestore(&dsi->irq_stats_lock, flags);
  1464. seq_printf(s, "period %u ms\n",
  1465. jiffies_to_msecs(jiffies - stats.last_reset));
  1466. seq_printf(s, "irqs %d\n", stats.irq_count);
  1467. #define PIS(x) \
  1468. seq_printf(s, "%-20s %10d\n", #x, stats.dsi_irqs[ffs(DSI_IRQ_##x)-1]);
  1469. seq_printf(s, "-- DSI%d interrupts --\n", dsi_module + 1);
  1470. PIS(VC0);
  1471. PIS(VC1);
  1472. PIS(VC2);
  1473. PIS(VC3);
  1474. PIS(WAKEUP);
  1475. PIS(RESYNC);
  1476. PIS(PLL_LOCK);
  1477. PIS(PLL_UNLOCK);
  1478. PIS(PLL_RECALL);
  1479. PIS(COMPLEXIO_ERR);
  1480. PIS(HS_TX_TIMEOUT);
  1481. PIS(LP_RX_TIMEOUT);
  1482. PIS(TE_TRIGGER);
  1483. PIS(ACK_TRIGGER);
  1484. PIS(SYNC_LOST);
  1485. PIS(LDO_POWER_GOOD);
  1486. PIS(TA_TIMEOUT);
  1487. #undef PIS
  1488. #define PIS(x) \
  1489. seq_printf(s, "%-20s %10d %10d %10d %10d\n", #x, \
  1490. stats.vc_irqs[0][ffs(DSI_VC_IRQ_##x)-1], \
  1491. stats.vc_irqs[1][ffs(DSI_VC_IRQ_##x)-1], \
  1492. stats.vc_irqs[2][ffs(DSI_VC_IRQ_##x)-1], \
  1493. stats.vc_irqs[3][ffs(DSI_VC_IRQ_##x)-1]);
  1494. seq_printf(s, "-- VC interrupts --\n");
  1495. PIS(CS);
  1496. PIS(ECC_CORR);
  1497. PIS(PACKET_SENT);
  1498. PIS(FIFO_TX_OVF);
  1499. PIS(FIFO_RX_OVF);
  1500. PIS(BTA);
  1501. PIS(ECC_NO_CORR);
  1502. PIS(FIFO_TX_UDF);
  1503. PIS(PP_BUSY_CHANGE);
  1504. #undef PIS
  1505. #define PIS(x) \
  1506. seq_printf(s, "%-20s %10d\n", #x, \
  1507. stats.cio_irqs[ffs(DSI_CIO_IRQ_##x)-1]);
  1508. seq_printf(s, "-- CIO interrupts --\n");
  1509. PIS(ERRSYNCESC1);
  1510. PIS(ERRSYNCESC2);
  1511. PIS(ERRSYNCESC3);
  1512. PIS(ERRESC1);
  1513. PIS(ERRESC2);
  1514. PIS(ERRESC3);
  1515. PIS(ERRCONTROL1);
  1516. PIS(ERRCONTROL2);
  1517. PIS(ERRCONTROL3);
  1518. PIS(STATEULPS1);
  1519. PIS(STATEULPS2);
  1520. PIS(STATEULPS3);
  1521. PIS(ERRCONTENTIONLP0_1);
  1522. PIS(ERRCONTENTIONLP1_1);
  1523. PIS(ERRCONTENTIONLP0_2);
  1524. PIS(ERRCONTENTIONLP1_2);
  1525. PIS(ERRCONTENTIONLP0_3);
  1526. PIS(ERRCONTENTIONLP1_3);
  1527. PIS(ULPSACTIVENOT_ALL0);
  1528. PIS(ULPSACTIVENOT_ALL1);
  1529. #undef PIS
  1530. }
  1531. static void dsi1_dump_irqs(struct seq_file *s)
  1532. {
  1533. struct platform_device *dsidev = dsi_get_dsidev_from_id(0);
  1534. dsi_dump_dsidev_irqs(dsidev, s);
  1535. }
  1536. static void dsi2_dump_irqs(struct seq_file *s)
  1537. {
  1538. struct platform_device *dsidev = dsi_get_dsidev_from_id(1);
  1539. dsi_dump_dsidev_irqs(dsidev, s);
  1540. }
  1541. void dsi_create_debugfs_files_irq(struct dentry *debugfs_dir,
  1542. const struct file_operations *debug_fops)
  1543. {
  1544. struct platform_device *dsidev;
  1545. dsidev = dsi_get_dsidev_from_id(0);
  1546. if (dsidev)
  1547. debugfs_create_file("dsi1_irqs", S_IRUGO, debugfs_dir,
  1548. &dsi1_dump_irqs, debug_fops);
  1549. dsidev = dsi_get_dsidev_from_id(1);
  1550. if (dsidev)
  1551. debugfs_create_file("dsi2_irqs", S_IRUGO, debugfs_dir,
  1552. &dsi2_dump_irqs, debug_fops);
  1553. }
  1554. #endif
  1555. static void dsi_dump_dsidev_regs(struct platform_device *dsidev,
  1556. struct seq_file *s)
  1557. {
  1558. #define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, dsi_read_reg(dsidev, r))
  1559. if (dsi_runtime_get(dsidev))
  1560. return;
  1561. dsi_enable_scp_clk(dsidev);
  1562. DUMPREG(DSI_REVISION);
  1563. DUMPREG(DSI_SYSCONFIG);
  1564. DUMPREG(DSI_SYSSTATUS);
  1565. DUMPREG(DSI_IRQSTATUS);
  1566. DUMPREG(DSI_IRQENABLE);
  1567. DUMPREG(DSI_CTRL);
  1568. DUMPREG(DSI_COMPLEXIO_CFG1);
  1569. DUMPREG(DSI_COMPLEXIO_IRQ_STATUS);
  1570. DUMPREG(DSI_COMPLEXIO_IRQ_ENABLE);
  1571. DUMPREG(DSI_CLK_CTRL);
  1572. DUMPREG(DSI_TIMING1);
  1573. DUMPREG(DSI_TIMING2);
  1574. DUMPREG(DSI_VM_TIMING1);
  1575. DUMPREG(DSI_VM_TIMING2);
  1576. DUMPREG(DSI_VM_TIMING3);
  1577. DUMPREG(DSI_CLK_TIMING);
  1578. DUMPREG(DSI_TX_FIFO_VC_SIZE);
  1579. DUMPREG(DSI_RX_FIFO_VC_SIZE);
  1580. DUMPREG(DSI_COMPLEXIO_CFG2);
  1581. DUMPREG(DSI_RX_FIFO_VC_FULLNESS);
  1582. DUMPREG(DSI_VM_TIMING4);
  1583. DUMPREG(DSI_TX_FIFO_VC_EMPTINESS);
  1584. DUMPREG(DSI_VM_TIMING5);
  1585. DUMPREG(DSI_VM_TIMING6);
  1586. DUMPREG(DSI_VM_TIMING7);
  1587. DUMPREG(DSI_STOPCLK_TIMING);
  1588. DUMPREG(DSI_VC_CTRL(0));
  1589. DUMPREG(DSI_VC_TE(0));
  1590. DUMPREG(DSI_VC_LONG_PACKET_HEADER(0));
  1591. DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(0));
  1592. DUMPREG(DSI_VC_SHORT_PACKET_HEADER(0));
  1593. DUMPREG(DSI_VC_IRQSTATUS(0));
  1594. DUMPREG(DSI_VC_IRQENABLE(0));
  1595. DUMPREG(DSI_VC_CTRL(1));
  1596. DUMPREG(DSI_VC_TE(1));
  1597. DUMPREG(DSI_VC_LONG_PACKET_HEADER(1));
  1598. DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(1));
  1599. DUMPREG(DSI_VC_SHORT_PACKET_HEADER(1));
  1600. DUMPREG(DSI_VC_IRQSTATUS(1));
  1601. DUMPREG(DSI_VC_IRQENABLE(1));
  1602. DUMPREG(DSI_VC_CTRL(2));
  1603. DUMPREG(DSI_VC_TE(2));
  1604. DUMPREG(DSI_VC_LONG_PACKET_HEADER(2));
  1605. DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(2));
  1606. DUMPREG(DSI_VC_SHORT_PACKET_HEADER(2));
  1607. DUMPREG(DSI_VC_IRQSTATUS(2));
  1608. DUMPREG(DSI_VC_IRQENABLE(2));
  1609. DUMPREG(DSI_VC_CTRL(3));
  1610. DUMPREG(DSI_VC_TE(3));
  1611. DUMPREG(DSI_VC_LONG_PACKET_HEADER(3));
  1612. DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(3));
  1613. DUMPREG(DSI_VC_SHORT_PACKET_HEADER(3));
  1614. DUMPREG(DSI_VC_IRQSTATUS(3));
  1615. DUMPREG(DSI_VC_IRQENABLE(3));
  1616. DUMPREG(DSI_DSIPHY_CFG0);
  1617. DUMPREG(DSI_DSIPHY_CFG1);
  1618. DUMPREG(DSI_DSIPHY_CFG2);
  1619. DUMPREG(DSI_DSIPHY_CFG5);
  1620. DUMPREG(DSI_PLL_CONTROL);
  1621. DUMPREG(DSI_PLL_STATUS);
  1622. DUMPREG(DSI_PLL_GO);
  1623. DUMPREG(DSI_PLL_CONFIGURATION1);
  1624. DUMPREG(DSI_PLL_CONFIGURATION2);
  1625. dsi_disable_scp_clk(dsidev);
  1626. dsi_runtime_put(dsidev);
  1627. #undef DUMPREG
  1628. }
  1629. static void dsi1_dump_regs(struct seq_file *s)
  1630. {
  1631. struct platform_device *dsidev = dsi_get_dsidev_from_id(0);
  1632. dsi_dump_dsidev_regs(dsidev, s);
  1633. }
  1634. static void dsi2_dump_regs(struct seq_file *s)
  1635. {
  1636. struct platform_device *dsidev = dsi_get_dsidev_from_id(1);
  1637. dsi_dump_dsidev_regs(dsidev, s);
  1638. }
  1639. void dsi_create_debugfs_files_reg(struct dentry *debugfs_dir,
  1640. const struct file_operations *debug_fops)
  1641. {
  1642. struct platform_device *dsidev;
  1643. dsidev = dsi_get_dsidev_from_id(0);
  1644. if (dsidev)
  1645. debugfs_create_file("dsi1_regs", S_IRUGO, debugfs_dir,
  1646. &dsi1_dump_regs, debug_fops);
  1647. dsidev = dsi_get_dsidev_from_id(1);
  1648. if (dsidev)
  1649. debugfs_create_file("dsi2_regs", S_IRUGO, debugfs_dir,
  1650. &dsi2_dump_regs, debug_fops);
  1651. }
  1652. enum dsi_cio_power_state {
  1653. DSI_COMPLEXIO_POWER_OFF = 0x0,
  1654. DSI_COMPLEXIO_POWER_ON = 0x1,
  1655. DSI_COMPLEXIO_POWER_ULPS = 0x2,
  1656. };
  1657. static int dsi_cio_power(struct platform_device *dsidev,
  1658. enum dsi_cio_power_state state)
  1659. {
  1660. int t = 0;
  1661. /* PWR_CMD */
  1662. REG_FLD_MOD(dsidev, DSI_COMPLEXIO_CFG1, state, 28, 27);
  1663. if (cpu_is_omap44xx())
  1664. /*bit 30 has to be set to 1 to GO in omap4*/
  1665. REG_FLD_MOD(dsidev, DSI_COMPLEXIO_CFG1, 1, 30, 30);
  1666. /* PWR_STATUS */
  1667. while (FLD_GET(dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG1),
  1668. 26, 25) != state) {
  1669. if (++t > 1000) {
  1670. DSSERR("failed to set complexio power state to "
  1671. "%d\n", state);
  1672. return -ENODEV;
  1673. }
  1674. udelay(1);
  1675. }
  1676. return 0;
  1677. }
  1678. /* Number of data lanes present on DSI interface */
  1679. static inline int dsi_get_num_data_lanes(struct platform_device *dsidev)
  1680. {
  1681. /* DSI on OMAP3 doesn't have register DSI_GNQ, set number
  1682. * of data lanes as 2 by default */
  1683. if (dss_has_feature(FEAT_DSI_GNQ))
  1684. return REG_GET(dsidev, DSI_GNQ, 11, 9); /* NB_DATA_LANES */
  1685. else
  1686. return 2;
  1687. }
  1688. /* Number of data lanes used by the dss device */
  1689. static inline int dsi_get_num_data_lanes_dssdev(struct omap_dss_device *dssdev)
  1690. {
  1691. int num_data_lanes = 0;
  1692. if (dssdev->phy.dsi.data1_lane != 0)
  1693. num_data_lanes++;
  1694. if (dssdev->phy.dsi.data2_lane != 0)
  1695. num_data_lanes++;
  1696. if (dssdev->phy.dsi.data3_lane != 0)
  1697. num_data_lanes++;
  1698. if (dssdev->phy.dsi.data4_lane != 0)
  1699. num_data_lanes++;
  1700. return num_data_lanes;
  1701. }
  1702. static unsigned dsi_get_line_buf_size(struct platform_device *dsidev)
  1703. {
  1704. int val;
  1705. /* line buffer on OMAP3 is 1024 x 24bits */
  1706. /* XXX: for some reason using full buffer size causes
  1707. * considerable TX slowdown with update sizes that fill the
  1708. * whole buffer */
  1709. if (!dss_has_feature(FEAT_DSI_GNQ))
  1710. return 1023 * 3;
  1711. val = REG_GET(dsidev, DSI_GNQ, 14, 12); /* VP1_LINE_BUFFER_SIZE */
  1712. switch (val) {
  1713. case 1:
  1714. return 512 * 3; /* 512x24 bits */
  1715. case 2:
  1716. return 682 * 3; /* 682x24 bits */
  1717. case 3:
  1718. return 853 * 3; /* 853x24 bits */
  1719. case 4:
  1720. return 1024 * 3; /* 1024x24 bits */
  1721. case 5:
  1722. return 1194 * 3; /* 1194x24 bits */
  1723. case 6:
  1724. return 1365 * 3; /* 1365x24 bits */
  1725. default:
  1726. BUG();
  1727. }
  1728. }
  1729. static void dsi_set_lane_config(struct omap_dss_device *dssdev)
  1730. {
  1731. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  1732. u32 r;
  1733. int num_data_lanes_dssdev = dsi_get_num_data_lanes_dssdev(dssdev);
  1734. int clk_lane = dssdev->phy.dsi.clk_lane;
  1735. int data1_lane = dssdev->phy.dsi.data1_lane;
  1736. int data2_lane = dssdev->phy.dsi.data2_lane;
  1737. int clk_pol = dssdev->phy.dsi.clk_pol;
  1738. int data1_pol = dssdev->phy.dsi.data1_pol;
  1739. int data2_pol = dssdev->phy.dsi.data2_pol;
  1740. r = dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG1);
  1741. r = FLD_MOD(r, clk_lane, 2, 0);
  1742. r = FLD_MOD(r, clk_pol, 3, 3);
  1743. r = FLD_MOD(r, data1_lane, 6, 4);
  1744. r = FLD_MOD(r, data1_pol, 7, 7);
  1745. r = FLD_MOD(r, data2_lane, 10, 8);
  1746. r = FLD_MOD(r, data2_pol, 11, 11);
  1747. if (num_data_lanes_dssdev > 2) {
  1748. int data3_lane = dssdev->phy.dsi.data3_lane;
  1749. int data3_pol = dssdev->phy.dsi.data3_pol;
  1750. r = FLD_MOD(r, data3_lane, 14, 12);
  1751. r = FLD_MOD(r, data3_pol, 15, 15);
  1752. }
  1753. if (num_data_lanes_dssdev > 3) {
  1754. int data4_lane = dssdev->phy.dsi.data4_lane;
  1755. int data4_pol = dssdev->phy.dsi.data4_pol;
  1756. r = FLD_MOD(r, data4_lane, 18, 16);
  1757. r = FLD_MOD(r, data4_pol, 19, 19);
  1758. }
  1759. dsi_write_reg(dsidev, DSI_COMPLEXIO_CFG1, r);
  1760. /* The configuration of the DSI complex I/O (number of data lanes,
  1761. position, differential order) should not be changed while
  1762. DSS.DSI_CLK_CRTRL[20] LP_CLK_ENABLE bit is set to 1. In order for
  1763. the hardware to take into account a new configuration of the complex
  1764. I/O (done in DSS.DSI_COMPLEXIO_CFG1 register), it is recommended to
  1765. follow this sequence: First set the DSS.DSI_CTRL[0] IF_EN bit to 1,
  1766. then reset the DSS.DSI_CTRL[0] IF_EN to 0, then set
  1767. DSS.DSI_CLK_CTRL[20] LP_CLK_ENABLE to 1 and finally set again the
  1768. DSS.DSI_CTRL[0] IF_EN bit to 1. If the sequence is not followed, the
  1769. DSI complex I/O configuration is unknown. */
  1770. /*
  1771. REG_FLD_MOD(dsidev, DSI_CTRL, 1, 0, 0);
  1772. REG_FLD_MOD(dsidev, DSI_CTRL, 0, 0, 0);
  1773. REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 1, 20, 20);
  1774. REG_FLD_MOD(dsidev, DSI_CTRL, 1, 0, 0);
  1775. */
  1776. }
  1777. static inline unsigned ns2ddr(struct platform_device *dsidev, unsigned ns)
  1778. {
  1779. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1780. /* convert time in ns to ddr ticks, rounding up */
  1781. unsigned long ddr_clk = dsi->current_cinfo.clkin4ddr / 4;
  1782. return (ns * (ddr_clk / 1000 / 1000) + 999) / 1000;
  1783. }
  1784. static inline unsigned ddr2ns(struct platform_device *dsidev, unsigned ddr)
  1785. {
  1786. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1787. unsigned long ddr_clk = dsi->current_cinfo.clkin4ddr / 4;
  1788. return ddr * 1000 * 1000 / (ddr_clk / 1000);
  1789. }
  1790. static void dsi_cio_timings(struct platform_device *dsidev)
  1791. {
  1792. u32 r;
  1793. u32 ths_prepare, ths_prepare_ths_zero, ths_trail, ths_exit;
  1794. u32 tlpx_half, tclk_trail, tclk_zero;
  1795. u32 tclk_prepare;
  1796. /* calculate timings */
  1797. /* 1 * DDR_CLK = 2 * UI */
  1798. /* min 40ns + 4*UI max 85ns + 6*UI */
  1799. ths_prepare = ns2ddr(dsidev, 70) + 2;
  1800. /* min 145ns + 10*UI */
  1801. ths_prepare_ths_zero = ns2ddr(dsidev, 175) + 2;
  1802. /* min max(8*UI, 60ns+4*UI) */
  1803. ths_trail = ns2ddr(dsidev, 60) + 5;
  1804. /* min 100ns */
  1805. ths_exit = ns2ddr(dsidev, 145);
  1806. /* tlpx min 50n */
  1807. tlpx_half = ns2ddr(dsidev, 25);
  1808. /* min 60ns */
  1809. tclk_trail = ns2ddr(dsidev, 60) + 2;
  1810. /* min 38ns, max 95ns */
  1811. tclk_prepare = ns2ddr(dsidev, 65);
  1812. /* min tclk-prepare + tclk-zero = 300ns */
  1813. tclk_zero = ns2ddr(dsidev, 260);
  1814. DSSDBG("ths_prepare %u (%uns), ths_prepare_ths_zero %u (%uns)\n",
  1815. ths_prepare, ddr2ns(dsidev, ths_prepare),
  1816. ths_prepare_ths_zero, ddr2ns(dsidev, ths_prepare_ths_zero));
  1817. DSSDBG("ths_trail %u (%uns), ths_exit %u (%uns)\n",
  1818. ths_trail, ddr2ns(dsidev, ths_trail),
  1819. ths_exit, ddr2ns(dsidev, ths_exit));
  1820. DSSDBG("tlpx_half %u (%uns), tclk_trail %u (%uns), "
  1821. "tclk_zero %u (%uns)\n",
  1822. tlpx_half, ddr2ns(dsidev, tlpx_half),
  1823. tclk_trail, ddr2ns(dsidev, tclk_trail),
  1824. tclk_zero, ddr2ns(dsidev, tclk_zero));
  1825. DSSDBG("tclk_prepare %u (%uns)\n",
  1826. tclk_prepare, ddr2ns(dsidev, tclk_prepare));
  1827. /* program timings */
  1828. r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG0);
  1829. r = FLD_MOD(r, ths_prepare, 31, 24);
  1830. r = FLD_MOD(r, ths_prepare_ths_zero, 23, 16);
  1831. r = FLD_MOD(r, ths_trail, 15, 8);
  1832. r = FLD_MOD(r, ths_exit, 7, 0);
  1833. dsi_write_reg(dsidev, DSI_DSIPHY_CFG0, r);
  1834. r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG1);
  1835. r = FLD_MOD(r, tlpx_half, 22, 16);
  1836. r = FLD_MOD(r, tclk_trail, 15, 8);
  1837. r = FLD_MOD(r, tclk_zero, 7, 0);
  1838. dsi_write_reg(dsidev, DSI_DSIPHY_CFG1, r);
  1839. r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG2);
  1840. r = FLD_MOD(r, tclk_prepare, 7, 0);
  1841. dsi_write_reg(dsidev, DSI_DSIPHY_CFG2, r);
  1842. }
  1843. static void dsi_cio_enable_lane_override(struct omap_dss_device *dssdev,
  1844. enum dsi_lane lanes)
  1845. {
  1846. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  1847. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1848. int clk_lane = dssdev->phy.dsi.clk_lane;
  1849. int data1_lane = dssdev->phy.dsi.data1_lane;
  1850. int data2_lane = dssdev->phy.dsi.data2_lane;
  1851. int data3_lane = dssdev->phy.dsi.data3_lane;
  1852. int data4_lane = dssdev->phy.dsi.data4_lane;
  1853. int clk_pol = dssdev->phy.dsi.clk_pol;
  1854. int data1_pol = dssdev->phy.dsi.data1_pol;
  1855. int data2_pol = dssdev->phy.dsi.data2_pol;
  1856. int data3_pol = dssdev->phy.dsi.data3_pol;
  1857. int data4_pol = dssdev->phy.dsi.data4_pol;
  1858. u32 l = 0;
  1859. u8 lptxscp_start = dsi->num_data_lanes == 2 ? 22 : 26;
  1860. if (lanes & DSI_CLK_P)
  1861. l |= 1 << ((clk_lane - 1) * 2 + (clk_pol ? 0 : 1));
  1862. if (lanes & DSI_CLK_N)
  1863. l |= 1 << ((clk_lane - 1) * 2 + (clk_pol ? 1 : 0));
  1864. if (lanes & DSI_DATA1_P)
  1865. l |= 1 << ((data1_lane - 1) * 2 + (data1_pol ? 0 : 1));
  1866. if (lanes & DSI_DATA1_N)
  1867. l |= 1 << ((data1_lane - 1) * 2 + (data1_pol ? 1 : 0));
  1868. if (lanes & DSI_DATA2_P)
  1869. l |= 1 << ((data2_lane - 1) * 2 + (data2_pol ? 0 : 1));
  1870. if (lanes & DSI_DATA2_N)
  1871. l |= 1 << ((data2_lane - 1) * 2 + (data2_pol ? 1 : 0));
  1872. if (lanes & DSI_DATA3_P)
  1873. l |= 1 << ((data3_lane - 1) * 2 + (data3_pol ? 0 : 1));
  1874. if (lanes & DSI_DATA3_N)
  1875. l |= 1 << ((data3_lane - 1) * 2 + (data3_pol ? 1 : 0));
  1876. if (lanes & DSI_DATA4_P)
  1877. l |= 1 << ((data4_lane - 1) * 2 + (data4_pol ? 0 : 1));
  1878. if (lanes & DSI_DATA4_N)
  1879. l |= 1 << ((data4_lane - 1) * 2 + (data4_pol ? 1 : 0));
  1880. /*
  1881. * Bits in REGLPTXSCPDAT4TO0DXDY:
  1882. * 17: DY0 18: DX0
  1883. * 19: DY1 20: DX1
  1884. * 21: DY2 22: DX2
  1885. * 23: DY3 24: DX3
  1886. * 25: DY4 26: DX4
  1887. */
  1888. /* Set the lane override configuration */
  1889. /* REGLPTXSCPDAT4TO0DXDY */
  1890. REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, l, lptxscp_start, 17);
  1891. /* Enable lane override */
  1892. /* ENLPTXSCPDAT */
  1893. REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, 1, 27, 27);
  1894. }
  1895. static void dsi_cio_disable_lane_override(struct platform_device *dsidev)
  1896. {
  1897. /* Disable lane override */
  1898. REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, 0, 27, 27); /* ENLPTXSCPDAT */
  1899. /* Reset the lane override configuration */
  1900. /* REGLPTXSCPDAT4TO0DXDY */
  1901. REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, 0, 22, 17);
  1902. }
  1903. static int dsi_cio_wait_tx_clk_esc_reset(struct omap_dss_device *dssdev)
  1904. {
  1905. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  1906. int t;
  1907. int bits[3];
  1908. bool in_use[3];
  1909. if (dss_has_feature(FEAT_DSI_REVERSE_TXCLKESC)) {
  1910. bits[0] = 28;
  1911. bits[1] = 27;
  1912. bits[2] = 26;
  1913. } else {
  1914. bits[0] = 24;
  1915. bits[1] = 25;
  1916. bits[2] = 26;
  1917. }
  1918. in_use[0] = false;
  1919. in_use[1] = false;
  1920. in_use[2] = false;
  1921. if (dssdev->phy.dsi.clk_lane != 0)
  1922. in_use[dssdev->phy.dsi.clk_lane - 1] = true;
  1923. if (dssdev->phy.dsi.data1_lane != 0)
  1924. in_use[dssdev->phy.dsi.data1_lane - 1] = true;
  1925. if (dssdev->phy.dsi.data2_lane != 0)
  1926. in_use[dssdev->phy.dsi.data2_lane - 1] = true;
  1927. t = 100000;
  1928. while (true) {
  1929. u32 l;
  1930. int i;
  1931. int ok;
  1932. l = dsi_read_reg(dsidev, DSI_DSIPHY_CFG5);
  1933. ok = 0;
  1934. for (i = 0; i < 3; ++i) {
  1935. if (!in_use[i] || (l & (1 << bits[i])))
  1936. ok++;
  1937. }
  1938. if (ok == 3)
  1939. break;
  1940. if (--t == 0) {
  1941. for (i = 0; i < 3; ++i) {
  1942. if (!in_use[i] || (l & (1 << bits[i])))
  1943. continue;
  1944. DSSERR("CIO TXCLKESC%d domain not coming " \
  1945. "out of reset\n", i);
  1946. }
  1947. return -EIO;
  1948. }
  1949. }
  1950. return 0;
  1951. }
  1952. static int dsi_cio_init(struct omap_dss_device *dssdev)
  1953. {
  1954. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  1955. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1956. int r;
  1957. int num_data_lanes_dssdev = dsi_get_num_data_lanes_dssdev(dssdev);
  1958. u32 l;
  1959. DSSDBGF();
  1960. if (dsi->dsi_mux_pads)
  1961. dsi->dsi_mux_pads(true);
  1962. if (cpu_is_omap44xx()) {
  1963. /* DDR_CLK_ALWAYS_ON */
  1964. REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 0, 13, 13);
  1965. /* HS_AUTO_STOP_ENABLE */
  1966. REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 1, 18, 18);
  1967. }
  1968. dsi_enable_scp_clk(dsidev);
  1969. /* A dummy read using the SCP interface to any DSIPHY register is
  1970. * required after DSIPHY reset to complete the reset of the DSI complex
  1971. * I/O. */
  1972. dsi_read_reg(dsidev, DSI_DSIPHY_CFG5);
  1973. if (wait_for_bit_change(dsidev, DSI_DSIPHY_CFG5, 30, 1) != 1) {
  1974. DSSERR("CIO SCP Clock domain not coming out of reset.\n");
  1975. r = -EIO;
  1976. goto err_scp_clk_dom;
  1977. }
  1978. dsi_set_lane_config(dssdev);
  1979. /* set TX STOP MODE timer to maximum for this operation */
  1980. l = dsi_read_reg(dsidev, DSI_TIMING1);
  1981. l = FLD_MOD(l, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
  1982. l = FLD_MOD(l, 1, 14, 14); /* STOP_STATE_X16_IO */
  1983. l = FLD_MOD(l, 1, 13, 13); /* STOP_STATE_X4_IO */
  1984. l = FLD_MOD(l, 0x1fff, 12, 0); /* STOP_STATE_COUNTER_IO */
  1985. dsi_write_reg(dsidev, DSI_TIMING1, l);
  1986. if (dsi->ulps_enabled) {
  1987. u32 lane_mask = DSI_CLK_P | DSI_DATA1_P | DSI_DATA2_P;
  1988. DSSDBG("manual ulps exit\n");
  1989. /* ULPS is exited by Mark-1 state for 1ms, followed by
  1990. * stop state. DSS HW cannot do this via the normal
  1991. * ULPS exit sequence, as after reset the DSS HW thinks
  1992. * that we are not in ULPS mode, and refuses to send the
  1993. * sequence. So we need to send the ULPS exit sequence
  1994. * manually.
  1995. */
  1996. if (num_data_lanes_dssdev > 2)
  1997. lane_mask |= DSI_DATA3_P;
  1998. if (num_data_lanes_dssdev > 3)
  1999. lane_mask |= DSI_DATA4_P;
  2000. dsi_cio_enable_lane_override(dssdev, lane_mask);
  2001. }
  2002. r = dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_ON);
  2003. if (r)
  2004. goto err_cio_pwr;
  2005. if (wait_for_bit_change(dsidev, DSI_COMPLEXIO_CFG1, 29, 1) != 1) {
  2006. DSSERR("CIO PWR clock domain not coming out of reset.\n");
  2007. r = -ENODEV;
  2008. goto err_cio_pwr_dom;
  2009. }
  2010. dsi_if_enable(dsidev, true);
  2011. dsi_if_enable(dsidev, false);
  2012. REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 1, 20, 20); /* LP_CLK_ENABLE */
  2013. r = dsi_cio_wait_tx_clk_esc_reset(dssdev);
  2014. if (r)
  2015. goto err_tx_clk_esc_rst;
  2016. if (dsi->ulps_enabled) {
  2017. /* Keep Mark-1 state for 1ms (as per DSI spec) */
  2018. ktime_t wait = ns_to_ktime(1000 * 1000);
  2019. set_current_state(TASK_UNINTERRUPTIBLE);
  2020. schedule_hrtimeout(&wait, HRTIMER_MODE_REL);
  2021. /* Disable the override. The lanes should be set to Mark-11
  2022. * state by the HW */
  2023. dsi_cio_disable_lane_override(dsidev);
  2024. }
  2025. /* FORCE_TX_STOP_MODE_IO */
  2026. REG_FLD_MOD(dsidev, DSI_TIMING1, 0, 15, 15);
  2027. dsi_cio_timings(dsidev);
  2028. dsi->ulps_enabled = false;
  2029. DSSDBG("CIO init done\n");
  2030. return 0;
  2031. err_tx_clk_esc_rst:
  2032. REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 0, 20, 20); /* LP_CLK_ENABLE */
  2033. err_cio_pwr_dom:
  2034. dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_OFF);
  2035. err_cio_pwr:
  2036. if (dsi->ulps_enabled)
  2037. dsi_cio_disable_lane_override(dsidev);
  2038. err_scp_clk_dom:
  2039. dsi_disable_scp_clk(dsidev);
  2040. if (dsi->dsi_mux_pads)
  2041. dsi->dsi_mux_pads(false);
  2042. return r;
  2043. }
  2044. static void dsi_cio_uninit(struct platform_device *dsidev)
  2045. {
  2046. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2047. dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_OFF);
  2048. dsi_disable_scp_clk(dsidev);
  2049. if (dsi->dsi_mux_pads)
  2050. dsi->dsi_mux_pads(false);
  2051. }
  2052. static void dsi_config_tx_fifo(struct platform_device *dsidev,
  2053. enum fifo_size size1, enum fifo_size size2,
  2054. enum fifo_size size3, enum fifo_size size4)
  2055. {
  2056. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2057. u32 r = 0;
  2058. int add = 0;
  2059. int i;
  2060. dsi->vc[0].fifo_size = size1;
  2061. dsi->vc[1].fifo_size = size2;
  2062. dsi->vc[2].fifo_size = size3;
  2063. dsi->vc[3].fifo_size = size4;
  2064. for (i = 0; i < 4; i++) {
  2065. u8 v;
  2066. int size = dsi->vc[i].fifo_size;
  2067. if (add + size > 4) {
  2068. DSSERR("Illegal FIFO configuration\n");
  2069. BUG();
  2070. }
  2071. v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4);
  2072. r |= v << (8 * i);
  2073. /*DSSDBG("TX FIFO vc %d: size %d, add %d\n", i, size, add); */
  2074. add += size;
  2075. }
  2076. dsi_write_reg(dsidev, DSI_TX_FIFO_VC_SIZE, r);
  2077. }
  2078. static void dsi_config_rx_fifo(struct platform_device *dsidev,
  2079. enum fifo_size size1, enum fifo_size size2,
  2080. enum fifo_size size3, enum fifo_size size4)
  2081. {
  2082. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2083. u32 r = 0;
  2084. int add = 0;
  2085. int i;
  2086. dsi->vc[0].fifo_size = size1;
  2087. dsi->vc[1].fifo_size = size2;
  2088. dsi->vc[2].fifo_size = size3;
  2089. dsi->vc[3].fifo_size = size4;
  2090. for (i = 0; i < 4; i++) {
  2091. u8 v;
  2092. int size = dsi->vc[i].fifo_size;
  2093. if (add + size > 4) {
  2094. DSSERR("Illegal FIFO configuration\n");
  2095. BUG();
  2096. }
  2097. v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4);
  2098. r |= v << (8 * i);
  2099. /*DSSDBG("RX FIFO vc %d: size %d, add %d\n", i, size, add); */
  2100. add += size;
  2101. }
  2102. dsi_write_reg(dsidev, DSI_RX_FIFO_VC_SIZE, r);
  2103. }
  2104. static int dsi_force_tx_stop_mode_io(struct platform_device *dsidev)
  2105. {
  2106. u32 r;
  2107. r = dsi_read_reg(dsidev, DSI_TIMING1);
  2108. r = FLD_MOD(r, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
  2109. dsi_write_reg(dsidev, DSI_TIMING1, r);
  2110. if (wait_for_bit_change(dsidev, DSI_TIMING1, 15, 0) != 0) {
  2111. DSSERR("TX_STOP bit not going down\n");
  2112. return -EIO;
  2113. }
  2114. return 0;
  2115. }
  2116. static bool dsi_vc_is_enabled(struct platform_device *dsidev, int channel)
  2117. {
  2118. return REG_GET(dsidev, DSI_VC_CTRL(channel), 0, 0);
  2119. }
  2120. static void dsi_packet_sent_handler_vp(void *data, u32 mask)
  2121. {
  2122. struct dsi_packet_sent_handler_data *vp_data =
  2123. (struct dsi_packet_sent_handler_data *) data;
  2124. struct dsi_data *dsi = dsi_get_dsidrv_data(vp_data->dsidev);
  2125. const int channel = dsi->update_channel;
  2126. u8 bit = dsi->te_enabled ? 30 : 31;
  2127. if (REG_GET(vp_data->dsidev, DSI_VC_TE(channel), bit, bit) == 0)
  2128. complete(vp_data->completion);
  2129. }
  2130. static int dsi_sync_vc_vp(struct platform_device *dsidev, int channel)
  2131. {
  2132. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2133. DECLARE_COMPLETION_ONSTACK(completion);
  2134. struct dsi_packet_sent_handler_data vp_data = { dsidev, &completion };
  2135. int r = 0;
  2136. u8 bit;
  2137. bit = dsi->te_enabled ? 30 : 31;
  2138. r = dsi_register_isr_vc(dsidev, channel, dsi_packet_sent_handler_vp,
  2139. &vp_data, DSI_VC_IRQ_PACKET_SENT);
  2140. if (r)
  2141. goto err0;
  2142. /* Wait for completion only if TE_EN/TE_START is still set */
  2143. if (REG_GET(dsidev, DSI_VC_TE(channel), bit, bit)) {
  2144. if (wait_for_completion_timeout(&completion,
  2145. msecs_to_jiffies(10)) == 0) {
  2146. DSSERR("Failed to complete previous frame transfer\n");
  2147. r = -EIO;
  2148. goto err1;
  2149. }
  2150. }
  2151. dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_vp,
  2152. &vp_data, DSI_VC_IRQ_PACKET_SENT);
  2153. return 0;
  2154. err1:
  2155. dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_vp,
  2156. &vp_data, DSI_VC_IRQ_PACKET_SENT);
  2157. err0:
  2158. return r;
  2159. }
  2160. static void dsi_packet_sent_handler_l4(void *data, u32 mask)
  2161. {
  2162. struct dsi_packet_sent_handler_data *l4_data =
  2163. (struct dsi_packet_sent_handler_data *) data;
  2164. struct dsi_data *dsi = dsi_get_dsidrv_data(l4_data->dsidev);
  2165. const int channel = dsi->update_channel;
  2166. if (REG_GET(l4_data->dsidev, DSI_VC_CTRL(channel), 5, 5) == 0)
  2167. complete(l4_data->completion);
  2168. }
  2169. static int dsi_sync_vc_l4(struct platform_device *dsidev, int channel)
  2170. {
  2171. DECLARE_COMPLETION_ONSTACK(completion);
  2172. struct dsi_packet_sent_handler_data l4_data = { dsidev, &completion };
  2173. int r = 0;
  2174. r = dsi_register_isr_vc(dsidev, channel, dsi_packet_sent_handler_l4,
  2175. &l4_data, DSI_VC_IRQ_PACKET_SENT);
  2176. if (r)
  2177. goto err0;
  2178. /* Wait for completion only if TX_FIFO_NOT_EMPTY is still set */
  2179. if (REG_GET(dsidev, DSI_VC_CTRL(channel), 5, 5)) {
  2180. if (wait_for_completion_timeout(&completion,
  2181. msecs_to_jiffies(10)) == 0) {
  2182. DSSERR("Failed to complete previous l4 transfer\n");
  2183. r = -EIO;
  2184. goto err1;
  2185. }
  2186. }
  2187. dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_l4,
  2188. &l4_data, DSI_VC_IRQ_PACKET_SENT);
  2189. return 0;
  2190. err1:
  2191. dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_l4,
  2192. &l4_data, DSI_VC_IRQ_PACKET_SENT);
  2193. err0:
  2194. return r;
  2195. }
  2196. static int dsi_sync_vc(struct platform_device *dsidev, int channel)
  2197. {
  2198. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2199. WARN_ON(!dsi_bus_is_locked(dsidev));
  2200. WARN_ON(in_interrupt());
  2201. if (!dsi_vc_is_enabled(dsidev, channel))
  2202. return 0;
  2203. switch (dsi->vc[channel].mode) {
  2204. case DSI_VC_MODE_VP:
  2205. return dsi_sync_vc_vp(dsidev, channel);
  2206. case DSI_VC_MODE_L4:
  2207. return dsi_sync_vc_l4(dsidev, channel);
  2208. default:
  2209. BUG();
  2210. }
  2211. }
  2212. static int dsi_vc_enable(struct platform_device *dsidev, int channel,
  2213. bool enable)
  2214. {
  2215. DSSDBG("dsi_vc_enable channel %d, enable %d\n",
  2216. channel, enable);
  2217. enable = enable ? 1 : 0;
  2218. REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), enable, 0, 0);
  2219. if (wait_for_bit_change(dsidev, DSI_VC_CTRL(channel),
  2220. 0, enable) != enable) {
  2221. DSSERR("Failed to set dsi_vc_enable to %d\n", enable);
  2222. return -EIO;
  2223. }
  2224. return 0;
  2225. }
  2226. static void dsi_vc_initial_config(struct platform_device *dsidev, int channel)
  2227. {
  2228. u32 r;
  2229. DSSDBGF("%d", channel);
  2230. r = dsi_read_reg(dsidev, DSI_VC_CTRL(channel));
  2231. if (FLD_GET(r, 15, 15)) /* VC_BUSY */
  2232. DSSERR("VC(%d) busy when trying to configure it!\n",
  2233. channel);
  2234. r = FLD_MOD(r, 0, 1, 1); /* SOURCE, 0 = L4 */
  2235. r = FLD_MOD(r, 0, 2, 2); /* BTA_SHORT_EN */
  2236. r = FLD_MOD(r, 0, 3, 3); /* BTA_LONG_EN */
  2237. r = FLD_MOD(r, 0, 4, 4); /* MODE, 0 = command */
  2238. r = FLD_MOD(r, 1, 7, 7); /* CS_TX_EN */
  2239. r = FLD_MOD(r, 1, 8, 8); /* ECC_TX_EN */
  2240. r = FLD_MOD(r, 0, 9, 9); /* MODE_SPEED, high speed on/off */
  2241. if (dss_has_feature(FEAT_DSI_VC_OCP_WIDTH))
  2242. r = FLD_MOD(r, 3, 11, 10); /* OCP_WIDTH = 32 bit */
  2243. if (channel == 0)
  2244. r = FLD_MOD(r, 1, 11, 10); /* OCP_WIDTH = 32 bit */
  2245. r = FLD_MOD(r, 4, 29, 27); /* DMA_RX_REQ_NB = no dma */
  2246. r = FLD_MOD(r, 4, 23, 21); /* DMA_TX_REQ_NB = no dma */
  2247. dsi_write_reg(dsidev, DSI_VC_CTRL(channel), r);
  2248. }
  2249. static int dsi_vc_config_l4(struct platform_device *dsidev, int channel)
  2250. {
  2251. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2252. if (dsi->vc[channel].mode == DSI_VC_MODE_L4)
  2253. return 0;
  2254. DSSDBGF("%d", channel);
  2255. dsi_sync_vc(dsidev, channel);
  2256. dsi_vc_enable(dsidev, channel, 0);
  2257. /* VC_BUSY */
  2258. if (wait_for_bit_change(dsidev, DSI_VC_CTRL(channel), 15, 0) != 0) {
  2259. DSSERR("vc(%d) busy when trying to config for L4\n", channel);
  2260. return -EIO;
  2261. }
  2262. REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 0, 1, 1); /* SOURCE, 0 = L4 */
  2263. /* DCS_CMD_ENABLE */
  2264. if (dss_has_feature(FEAT_DSI_DCS_CMD_CONFIG_VC))
  2265. REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 0, 30, 30);
  2266. dsi_vc_enable(dsidev, channel, 1);
  2267. dsi->vc[channel].mode = DSI_VC_MODE_L4;
  2268. return 0;
  2269. }
  2270. static int dsi_vc_config_vp(struct platform_device *dsidev, int channel)
  2271. {
  2272. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2273. if (dsi->vc[channel].mode == DSI_VC_MODE_VP)
  2274. return 0;
  2275. DSSDBGF("%d", channel);
  2276. dsi_sync_vc(dsidev, channel);
  2277. dsi_vc_enable(dsidev, channel, 0);
  2278. /* VC_BUSY */
  2279. if (wait_for_bit_change(dsidev, DSI_VC_CTRL(channel), 15, 0) != 0) {
  2280. DSSERR("vc(%d) busy when trying to config for VP\n", channel);
  2281. return -EIO;
  2282. }
  2283. /* SOURCE, 1 = video port */
  2284. REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 1, 1, 1);
  2285. /* DCS_CMD_ENABLE */
  2286. if (dss_has_feature(FEAT_DSI_DCS_CMD_CONFIG_VC))
  2287. REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 1, 30, 30);
  2288. dsi_vc_enable(dsidev, channel, 1);
  2289. dsi->vc[channel].mode = DSI_VC_MODE_VP;
  2290. return 0;
  2291. }
  2292. void omapdss_dsi_vc_enable_hs(struct omap_dss_device *dssdev, int channel,
  2293. bool enable)
  2294. {
  2295. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  2296. DSSDBG("dsi_vc_enable_hs(%d, %d)\n", channel, enable);
  2297. WARN_ON(!dsi_bus_is_locked(dsidev));
  2298. dsi_vc_enable(dsidev, channel, 0);
  2299. dsi_if_enable(dsidev, 0);
  2300. REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), enable, 9, 9);
  2301. dsi_vc_enable(dsidev, channel, 1);
  2302. dsi_if_enable(dsidev, 1);
  2303. dsi_force_tx_stop_mode_io(dsidev);
  2304. }
  2305. EXPORT_SYMBOL(omapdss_dsi_vc_enable_hs);
  2306. static void dsi_vc_flush_long_data(struct platform_device *dsidev, int channel)
  2307. {
  2308. while (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) {
  2309. u32 val;
  2310. val = dsi_read_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel));
  2311. DSSDBG("\t\tb1 %#02x b2 %#02x b3 %#02x b4 %#02x\n",
  2312. (val >> 0) & 0xff,
  2313. (val >> 8) & 0xff,
  2314. (val >> 16) & 0xff,
  2315. (val >> 24) & 0xff);
  2316. }
  2317. }
  2318. static void dsi_show_rx_ack_with_err(u16 err)
  2319. {
  2320. DSSERR("\tACK with ERROR (%#x):\n", err);
  2321. if (err & (1 << 0))
  2322. DSSERR("\t\tSoT Error\n");
  2323. if (err & (1 << 1))
  2324. DSSERR("\t\tSoT Sync Error\n");
  2325. if (err & (1 << 2))
  2326. DSSERR("\t\tEoT Sync Error\n");
  2327. if (err & (1 << 3))
  2328. DSSERR("\t\tEscape Mode Entry Command Error\n");
  2329. if (err & (1 << 4))
  2330. DSSERR("\t\tLP Transmit Sync Error\n");
  2331. if (err & (1 << 5))
  2332. DSSERR("\t\tHS Receive Timeout Error\n");
  2333. if (err & (1 << 6))
  2334. DSSERR("\t\tFalse Control Error\n");
  2335. if (err & (1 << 7))
  2336. DSSERR("\t\t(reserved7)\n");
  2337. if (err & (1 << 8))
  2338. DSSERR("\t\tECC Error, single-bit (corrected)\n");
  2339. if (err & (1 << 9))
  2340. DSSERR("\t\tECC Error, multi-bit (not corrected)\n");
  2341. if (err & (1 << 10))
  2342. DSSERR("\t\tChecksum Error\n");
  2343. if (err & (1 << 11))
  2344. DSSERR("\t\tData type not recognized\n");
  2345. if (err & (1 << 12))
  2346. DSSERR("\t\tInvalid VC ID\n");
  2347. if (err & (1 << 13))
  2348. DSSERR("\t\tInvalid Transmission Length\n");
  2349. if (err & (1 << 14))
  2350. DSSERR("\t\t(reserved14)\n");
  2351. if (err & (1 << 15))
  2352. DSSERR("\t\tDSI Protocol Violation\n");
  2353. }
  2354. static u16 dsi_vc_flush_receive_data(struct platform_device *dsidev,
  2355. int channel)
  2356. {
  2357. /* RX_FIFO_NOT_EMPTY */
  2358. while (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) {
  2359. u32 val;
  2360. u8 dt;
  2361. val = dsi_read_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel));
  2362. DSSERR("\trawval %#08x\n", val);
  2363. dt = FLD_GET(val, 5, 0);
  2364. if (dt == DSI_DT_RX_ACK_WITH_ERR) {
  2365. u16 err = FLD_GET(val, 23, 8);
  2366. dsi_show_rx_ack_with_err(err);
  2367. } else if (dt == DSI_DT_RX_SHORT_READ_1) {
  2368. DSSERR("\tDCS short response, 1 byte: %#x\n",
  2369. FLD_GET(val, 23, 8));
  2370. } else if (dt == DSI_DT_RX_SHORT_READ_2) {
  2371. DSSERR("\tDCS short response, 2 byte: %#x\n",
  2372. FLD_GET(val, 23, 8));
  2373. } else if (dt == DSI_DT_RX_LONG_READ) {
  2374. DSSERR("\tlong response, len %d\n",
  2375. FLD_GET(val, 23, 8));
  2376. dsi_vc_flush_long_data(dsidev, channel);
  2377. } else if (dt == DSI_DT_RX_DCS_LONG_READ) {
  2378. DSSERR("\tDCS long response, len %d\n",
  2379. FLD_GET(val, 23, 8));
  2380. dsi_vc_flush_long_data(dsidev, channel);
  2381. } else {
  2382. DSSERR("\tunknown datatype 0x%02x\n", dt);
  2383. }
  2384. }
  2385. return 0;
  2386. }
  2387. static int dsi_vc_send_bta(struct platform_device *dsidev, int channel)
  2388. {
  2389. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2390. if (dsi->debug_write || dsi->debug_read)
  2391. DSSDBG("dsi_vc_send_bta %d\n", channel);
  2392. WARN_ON(!dsi_bus_is_locked(dsidev));
  2393. /* RX_FIFO_NOT_EMPTY */
  2394. if (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) {
  2395. DSSERR("rx fifo not empty when sending BTA, dumping data:\n");
  2396. dsi_vc_flush_receive_data(dsidev, channel);
  2397. }
  2398. REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 1, 6, 6); /* BTA_EN */
  2399. return 0;
  2400. }
  2401. int dsi_vc_send_bta_sync(struct omap_dss_device *dssdev, int channel)
  2402. {
  2403. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  2404. DECLARE_COMPLETION_ONSTACK(completion);
  2405. int r = 0;
  2406. u32 err;
  2407. r = dsi_register_isr_vc(dsidev, channel, dsi_completion_handler,
  2408. &completion, DSI_VC_IRQ_BTA);
  2409. if (r)
  2410. goto err0;
  2411. r = dsi_register_isr(dsidev, dsi_completion_handler, &completion,
  2412. DSI_IRQ_ERROR_MASK);
  2413. if (r)
  2414. goto err1;
  2415. r = dsi_vc_send_bta(dsidev, channel);
  2416. if (r)
  2417. goto err2;
  2418. if (wait_for_completion_timeout(&completion,
  2419. msecs_to_jiffies(500)) == 0) {
  2420. DSSERR("Failed to receive BTA\n");
  2421. r = -EIO;
  2422. goto err2;
  2423. }
  2424. err = dsi_get_errors(dsidev);
  2425. if (err) {
  2426. DSSERR("Error while sending BTA: %x\n", err);
  2427. r = -EIO;
  2428. goto err2;
  2429. }
  2430. err2:
  2431. dsi_unregister_isr(dsidev, dsi_completion_handler, &completion,
  2432. DSI_IRQ_ERROR_MASK);
  2433. err1:
  2434. dsi_unregister_isr_vc(dsidev, channel, dsi_completion_handler,
  2435. &completion, DSI_VC_IRQ_BTA);
  2436. err0:
  2437. return r;
  2438. }
  2439. EXPORT_SYMBOL(dsi_vc_send_bta_sync);
  2440. static inline void dsi_vc_write_long_header(struct platform_device *dsidev,
  2441. int channel, u8 data_type, u16 len, u8 ecc)
  2442. {
  2443. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2444. u32 val;
  2445. u8 data_id;
  2446. WARN_ON(!dsi_bus_is_locked(dsidev));
  2447. data_id = data_type | dsi->vc[channel].vc_id << 6;
  2448. val = FLD_VAL(data_id, 7, 0) | FLD_VAL(len, 23, 8) |
  2449. FLD_VAL(ecc, 31, 24);
  2450. dsi_write_reg(dsidev, DSI_VC_LONG_PACKET_HEADER(channel), val);
  2451. }
  2452. static inline void dsi_vc_write_long_payload(struct platform_device *dsidev,
  2453. int channel, u8 b1, u8 b2, u8 b3, u8 b4)
  2454. {
  2455. u32 val;
  2456. val = b4 << 24 | b3 << 16 | b2 << 8 | b1 << 0;
  2457. /* DSSDBG("\twriting %02x, %02x, %02x, %02x (%#010x)\n",
  2458. b1, b2, b3, b4, val); */
  2459. dsi_write_reg(dsidev, DSI_VC_LONG_PACKET_PAYLOAD(channel), val);
  2460. }
  2461. static int dsi_vc_send_long(struct platform_device *dsidev, int channel,
  2462. u8 data_type, u8 *data, u16 len, u8 ecc)
  2463. {
  2464. /*u32 val; */
  2465. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2466. int i;
  2467. u8 *p;
  2468. int r = 0;
  2469. u8 b1, b2, b3, b4;
  2470. if (dsi->debug_write)
  2471. DSSDBG("dsi_vc_send_long, %d bytes\n", len);
  2472. /* len + header */
  2473. if (dsi->vc[channel].fifo_size * 32 * 4 < len + 4) {
  2474. DSSERR("unable to send long packet: packet too long.\n");
  2475. return -EINVAL;
  2476. }
  2477. dsi_vc_config_l4(dsidev, channel);
  2478. dsi_vc_write_long_header(dsidev, channel, data_type, len, ecc);
  2479. p = data;
  2480. for (i = 0; i < len >> 2; i++) {
  2481. if (dsi->debug_write)
  2482. DSSDBG("\tsending full packet %d\n", i);
  2483. b1 = *p++;
  2484. b2 = *p++;
  2485. b3 = *p++;
  2486. b4 = *p++;
  2487. dsi_vc_write_long_payload(dsidev, channel, b1, b2, b3, b4);
  2488. }
  2489. i = len % 4;
  2490. if (i) {
  2491. b1 = 0; b2 = 0; b3 = 0;
  2492. if (dsi->debug_write)
  2493. DSSDBG("\tsending remainder bytes %d\n", i);
  2494. switch (i) {
  2495. case 3:
  2496. b1 = *p++;
  2497. b2 = *p++;
  2498. b3 = *p++;
  2499. break;
  2500. case 2:
  2501. b1 = *p++;
  2502. b2 = *p++;
  2503. break;
  2504. case 1:
  2505. b1 = *p++;
  2506. break;
  2507. }
  2508. dsi_vc_write_long_payload(dsidev, channel, b1, b2, b3, 0);
  2509. }
  2510. return r;
  2511. }
  2512. static int dsi_vc_send_short(struct platform_device *dsidev, int channel,
  2513. u8 data_type, u16 data, u8 ecc)
  2514. {
  2515. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2516. u32 r;
  2517. u8 data_id;
  2518. WARN_ON(!dsi_bus_is_locked(dsidev));
  2519. if (dsi->debug_write)
  2520. DSSDBG("dsi_vc_send_short(ch%d, dt %#x, b1 %#x, b2 %#x)\n",
  2521. channel,
  2522. data_type, data & 0xff, (data >> 8) & 0xff);
  2523. dsi_vc_config_l4(dsidev, channel);
  2524. if (FLD_GET(dsi_read_reg(dsidev, DSI_VC_CTRL(channel)), 16, 16)) {
  2525. DSSERR("ERROR FIFO FULL, aborting transfer\n");
  2526. return -EINVAL;
  2527. }
  2528. data_id = data_type | dsi->vc[channel].vc_id << 6;
  2529. r = (data_id << 0) | (data << 8) | (ecc << 24);
  2530. dsi_write_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel), r);
  2531. return 0;
  2532. }
  2533. int dsi_vc_send_null(struct omap_dss_device *dssdev, int channel)
  2534. {
  2535. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  2536. u8 nullpkg[] = {0, 0, 0, 0};
  2537. return dsi_vc_send_long(dsidev, channel, DSI_DT_NULL_PACKET, nullpkg,
  2538. 4, 0);
  2539. }
  2540. EXPORT_SYMBOL(dsi_vc_send_null);
  2541. int dsi_vc_dcs_write_nosync(struct omap_dss_device *dssdev, int channel,
  2542. u8 *data, int len)
  2543. {
  2544. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  2545. int r;
  2546. BUG_ON(len == 0);
  2547. if (len == 1) {
  2548. r = dsi_vc_send_short(dsidev, channel, DSI_DT_DCS_SHORT_WRITE_0,
  2549. data[0], 0);
  2550. } else if (len == 2) {
  2551. r = dsi_vc_send_short(dsidev, channel, DSI_DT_DCS_SHORT_WRITE_1,
  2552. data[0] | (data[1] << 8), 0);
  2553. } else {
  2554. /* 0x39 = DCS Long Write */
  2555. r = dsi_vc_send_long(dsidev, channel, DSI_DT_DCS_LONG_WRITE,
  2556. data, len, 0);
  2557. }
  2558. return r;
  2559. }
  2560. EXPORT_SYMBOL(dsi_vc_dcs_write_nosync);
  2561. int dsi_vc_dcs_write(struct omap_dss_device *dssdev, int channel, u8 *data,
  2562. int len)
  2563. {
  2564. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  2565. int r;
  2566. r = dsi_vc_dcs_write_nosync(dssdev, channel, data, len);
  2567. if (r)
  2568. goto err;
  2569. r = dsi_vc_send_bta_sync(dssdev, channel);
  2570. if (r)
  2571. goto err;
  2572. /* RX_FIFO_NOT_EMPTY */
  2573. if (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) {
  2574. DSSERR("rx fifo not empty after write, dumping data:\n");
  2575. dsi_vc_flush_receive_data(dsidev, channel);
  2576. r = -EIO;
  2577. goto err;
  2578. }
  2579. return 0;
  2580. err:
  2581. DSSERR("dsi_vc_dcs_write(ch %d, cmd 0x%02x, len %d) failed\n",
  2582. channel, data[0], len);
  2583. return r;
  2584. }
  2585. EXPORT_SYMBOL(dsi_vc_dcs_write);
  2586. int dsi_vc_dcs_write_0(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd)
  2587. {
  2588. return dsi_vc_dcs_write(dssdev, channel, &dcs_cmd, 1);
  2589. }
  2590. EXPORT_SYMBOL(dsi_vc_dcs_write_0);
  2591. int dsi_vc_dcs_write_1(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd,
  2592. u8 param)
  2593. {
  2594. u8 buf[2];
  2595. buf[0] = dcs_cmd;
  2596. buf[1] = param;
  2597. return dsi_vc_dcs_write(dssdev, channel, buf, 2);
  2598. }
  2599. EXPORT_SYMBOL(dsi_vc_dcs_write_1);
  2600. int dsi_vc_dcs_read(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd,
  2601. u8 *buf, int buflen)
  2602. {
  2603. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  2604. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2605. u32 val;
  2606. u8 dt;
  2607. int r;
  2608. if (dsi->debug_read)
  2609. DSSDBG("dsi_vc_dcs_read(ch%d, dcs_cmd %x)\n", channel, dcs_cmd);
  2610. r = dsi_vc_send_short(dsidev, channel, DSI_DT_DCS_READ, dcs_cmd, 0);
  2611. if (r)
  2612. goto err;
  2613. r = dsi_vc_send_bta_sync(dssdev, channel);
  2614. if (r)
  2615. goto err;
  2616. /* RX_FIFO_NOT_EMPTY */
  2617. if (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20) == 0) {
  2618. DSSERR("RX fifo empty when trying to read.\n");
  2619. r = -EIO;
  2620. goto err;
  2621. }
  2622. val = dsi_read_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel));
  2623. if (dsi->debug_read)
  2624. DSSDBG("\theader: %08x\n", val);
  2625. dt = FLD_GET(val, 5, 0);
  2626. if (dt == DSI_DT_RX_ACK_WITH_ERR) {
  2627. u16 err = FLD_GET(val, 23, 8);
  2628. dsi_show_rx_ack_with_err(err);
  2629. r = -EIO;
  2630. goto err;
  2631. } else if (dt == DSI_DT_RX_SHORT_READ_1) {
  2632. u8 data = FLD_GET(val, 15, 8);
  2633. if (dsi->debug_read)
  2634. DSSDBG("\tDCS short response, 1 byte: %02x\n", data);
  2635. if (buflen < 1) {
  2636. r = -EIO;
  2637. goto err;
  2638. }
  2639. buf[0] = data;
  2640. return 1;
  2641. } else if (dt == DSI_DT_RX_SHORT_READ_2) {
  2642. u16 data = FLD_GET(val, 23, 8);
  2643. if (dsi->debug_read)
  2644. DSSDBG("\tDCS short response, 2 byte: %04x\n", data);
  2645. if (buflen < 2) {
  2646. r = -EIO;
  2647. goto err;
  2648. }
  2649. buf[0] = data & 0xff;
  2650. buf[1] = (data >> 8) & 0xff;
  2651. return 2;
  2652. } else if (dt == DSI_DT_RX_DCS_LONG_READ || dt == DSI_DT_RX_LONG_READ) {
  2653. int w;
  2654. int len = FLD_GET(val, 23, 8);
  2655. if (dsi->debug_read)
  2656. DSSDBG("\tDCS long response, len %d\n", len);
  2657. if (len > buflen) {
  2658. r = -EIO;
  2659. goto err;
  2660. }
  2661. /* two byte checksum ends the packet, not included in len */
  2662. for (w = 0; w < len + 2;) {
  2663. int b;
  2664. val = dsi_read_reg(dsidev,
  2665. DSI_VC_SHORT_PACKET_HEADER(channel));
  2666. if (dsi->debug_read)
  2667. DSSDBG("\t\t%02x %02x %02x %02x\n",
  2668. (val >> 0) & 0xff,
  2669. (val >> 8) & 0xff,
  2670. (val >> 16) & 0xff,
  2671. (val >> 24) & 0xff);
  2672. for (b = 0; b < 4; ++b) {
  2673. if (w < len)
  2674. buf[w] = (val >> (b * 8)) & 0xff;
  2675. /* we discard the 2 byte checksum */
  2676. ++w;
  2677. }
  2678. }
  2679. return len;
  2680. } else {
  2681. DSSERR("\tunknown datatype 0x%02x\n", dt);
  2682. r = -EIO;
  2683. goto err;
  2684. }
  2685. BUG();
  2686. err:
  2687. DSSERR("dsi_vc_dcs_read(ch %d, cmd 0x%02x) failed\n",
  2688. channel, dcs_cmd);
  2689. return r;
  2690. }
  2691. EXPORT_SYMBOL(dsi_vc_dcs_read);
  2692. int dsi_vc_dcs_read_1(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd,
  2693. u8 *data)
  2694. {
  2695. int r;
  2696. r = dsi_vc_dcs_read(dssdev, channel, dcs_cmd, data, 1);
  2697. if (r < 0)
  2698. return r;
  2699. if (r != 1)
  2700. return -EIO;
  2701. return 0;
  2702. }
  2703. EXPORT_SYMBOL(dsi_vc_dcs_read_1);
  2704. int dsi_vc_dcs_read_2(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd,
  2705. u8 *data1, u8 *data2)
  2706. {
  2707. u8 buf[2];
  2708. int r;
  2709. r = dsi_vc_dcs_read(dssdev, channel, dcs_cmd, buf, 2);
  2710. if (r < 0)
  2711. return r;
  2712. if (r != 2)
  2713. return -EIO;
  2714. *data1 = buf[0];
  2715. *data2 = buf[1];
  2716. return 0;
  2717. }
  2718. EXPORT_SYMBOL(dsi_vc_dcs_read_2);
  2719. int dsi_vc_set_max_rx_packet_size(struct omap_dss_device *dssdev, int channel,
  2720. u16 len)
  2721. {
  2722. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  2723. return dsi_vc_send_short(dsidev, channel, DSI_DT_SET_MAX_RET_PKG_SIZE,
  2724. len, 0);
  2725. }
  2726. EXPORT_SYMBOL(dsi_vc_set_max_rx_packet_size);
  2727. static int dsi_enter_ulps(struct platform_device *dsidev)
  2728. {
  2729. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2730. DECLARE_COMPLETION_ONSTACK(completion);
  2731. int r;
  2732. DSSDBGF();
  2733. WARN_ON(!dsi_bus_is_locked(dsidev));
  2734. WARN_ON(dsi->ulps_enabled);
  2735. if (dsi->ulps_enabled)
  2736. return 0;
  2737. if (REG_GET(dsidev, DSI_CLK_CTRL, 13, 13)) {
  2738. DSSERR("DDR_CLK_ALWAYS_ON enabled when entering ULPS\n");
  2739. return -EIO;
  2740. }
  2741. dsi_sync_vc(dsidev, 0);
  2742. dsi_sync_vc(dsidev, 1);
  2743. dsi_sync_vc(dsidev, 2);
  2744. dsi_sync_vc(dsidev, 3);
  2745. dsi_force_tx_stop_mode_io(dsidev);
  2746. dsi_vc_enable(dsidev, 0, false);
  2747. dsi_vc_enable(dsidev, 1, false);
  2748. dsi_vc_enable(dsidev, 2, false);
  2749. dsi_vc_enable(dsidev, 3, false);
  2750. if (REG_GET(dsidev, DSI_COMPLEXIO_CFG2, 16, 16)) { /* HS_BUSY */
  2751. DSSERR("HS busy when enabling ULPS\n");
  2752. return -EIO;
  2753. }
  2754. if (REG_GET(dsidev, DSI_COMPLEXIO_CFG2, 17, 17)) { /* LP_BUSY */
  2755. DSSERR("LP busy when enabling ULPS\n");
  2756. return -EIO;
  2757. }
  2758. r = dsi_register_isr_cio(dsidev, dsi_completion_handler, &completion,
  2759. DSI_CIO_IRQ_ULPSACTIVENOT_ALL0);
  2760. if (r)
  2761. return r;
  2762. /* Assert TxRequestEsc for data lanes and TxUlpsClk for clk lane */
  2763. /* LANEx_ULPS_SIG2 */
  2764. REG_FLD_MOD(dsidev, DSI_COMPLEXIO_CFG2, (1 << 0) | (1 << 1) | (1 << 2),
  2765. 7, 5);
  2766. if (wait_for_completion_timeout(&completion,
  2767. msecs_to_jiffies(1000)) == 0) {
  2768. DSSERR("ULPS enable timeout\n");
  2769. r = -EIO;
  2770. goto err;
  2771. }
  2772. dsi_unregister_isr_cio(dsidev, dsi_completion_handler, &completion,
  2773. DSI_CIO_IRQ_ULPSACTIVENOT_ALL0);
  2774. /* Reset LANEx_ULPS_SIG2 */
  2775. REG_FLD_MOD(dsidev, DSI_COMPLEXIO_CFG2, (0 << 0) | (0 << 1) | (0 << 2),
  2776. 7, 5);
  2777. dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_ULPS);
  2778. dsi_if_enable(dsidev, false);
  2779. dsi->ulps_enabled = true;
  2780. return 0;
  2781. err:
  2782. dsi_unregister_isr_cio(dsidev, dsi_completion_handler, &completion,
  2783. DSI_CIO_IRQ_ULPSACTIVENOT_ALL0);
  2784. return r;
  2785. }
  2786. static void dsi_set_lp_rx_timeout(struct platform_device *dsidev,
  2787. unsigned ticks, bool x4, bool x16, bool to)
  2788. {
  2789. unsigned long fck;
  2790. unsigned long total_ticks;
  2791. u32 r;
  2792. BUG_ON(ticks > 0x1fff);
  2793. /* ticks in DSI_FCK */
  2794. fck = dsi_fclk_rate(dsidev);
  2795. r = dsi_read_reg(dsidev, DSI_TIMING2);
  2796. r = FLD_MOD(r, to ? 1 : 0, 15, 15); /* LP_RX_TO */
  2797. r = FLD_MOD(r, x16 ? 1 : 0, 14, 14); /* LP_RX_TO_X16 */
  2798. r = FLD_MOD(r, x4 ? 1 : 0, 13, 13); /* LP_RX_TO_X4 */
  2799. r = FLD_MOD(r, ticks, 12, 0); /* LP_RX_COUNTER */
  2800. dsi_write_reg(dsidev, DSI_TIMING2, r);
  2801. total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
  2802. DSSDBG("LP_RX_TO %lu ticks (%#x%s%s) = %lu ns\n",
  2803. total_ticks,
  2804. ticks, x4 ? " x4" : "", x16 ? " x16" : "",
  2805. (total_ticks * 1000) / (fck / 1000 / 1000));
  2806. }
  2807. static void dsi_set_ta_timeout(struct platform_device *dsidev, unsigned ticks,
  2808. bool x8, bool x16, bool to)
  2809. {
  2810. unsigned long fck;
  2811. unsigned long total_ticks;
  2812. u32 r;
  2813. BUG_ON(ticks > 0x1fff);
  2814. /* ticks in DSI_FCK */
  2815. fck = dsi_fclk_rate(dsidev);
  2816. r = dsi_read_reg(dsidev, DSI_TIMING1);
  2817. r = FLD_MOD(r, to ? 1 : 0, 31, 31); /* TA_TO */
  2818. r = FLD_MOD(r, x16 ? 1 : 0, 30, 30); /* TA_TO_X16 */
  2819. r = FLD_MOD(r, x8 ? 1 : 0, 29, 29); /* TA_TO_X8 */
  2820. r = FLD_MOD(r, ticks, 28, 16); /* TA_TO_COUNTER */
  2821. dsi_write_reg(dsidev, DSI_TIMING1, r);
  2822. total_ticks = ticks * (x16 ? 16 : 1) * (x8 ? 8 : 1);
  2823. DSSDBG("TA_TO %lu ticks (%#x%s%s) = %lu ns\n",
  2824. total_ticks,
  2825. ticks, x8 ? " x8" : "", x16 ? " x16" : "",
  2826. (total_ticks * 1000) / (fck / 1000 / 1000));
  2827. }
  2828. static void dsi_set_stop_state_counter(struct platform_device *dsidev,
  2829. unsigned ticks, bool x4, bool x16,
  2830. bool stop_mode)
  2831. {
  2832. unsigned long fck;
  2833. unsigned long total_ticks;
  2834. u32 r;
  2835. BUG_ON(ticks > 0x1fff);
  2836. /* ticks in DSI_FCK */
  2837. fck = dsi_fclk_rate(dsidev);
  2838. r = dsi_read_reg(dsidev, DSI_TIMING1);
  2839. r = FLD_MOD(r, stop_mode ? 1 : 0, 15, 15); /* FORCE_TX_STOP_MODE_IO */
  2840. r = FLD_MOD(r, x16 ? 1 : 0, 14, 14); /* STOP_STATE_X16_IO */
  2841. r = FLD_MOD(r, x4 ? 1 : 0, 13, 13); /* STOP_STATE_X4_IO */
  2842. r = FLD_MOD(r, ticks, 12, 0); /* STOP_STATE_COUNTER_IO */
  2843. dsi_write_reg(dsidev, DSI_TIMING1, r);
  2844. total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
  2845. DSSDBG("STOP_STATE_COUNTER %lu ticks (%#x%s%s) = %lu ns\n",
  2846. total_ticks,
  2847. ticks, x4 ? " x4" : "", x16 ? " x16" : "",
  2848. (total_ticks * 1000) / (fck / 1000 / 1000));
  2849. }
  2850. static void dsi_set_hs_tx_timeout(struct platform_device *dsidev,
  2851. unsigned ticks, bool x4, bool x16, bool to)
  2852. {
  2853. unsigned long fck;
  2854. unsigned long total_ticks;
  2855. u32 r;
  2856. BUG_ON(ticks > 0x1fff);
  2857. /* ticks in TxByteClkHS */
  2858. fck = dsi_get_txbyteclkhs(dsidev);
  2859. r = dsi_read_reg(dsidev, DSI_TIMING2);
  2860. r = FLD_MOD(r, to ? 1 : 0, 31, 31); /* HS_TX_TO */
  2861. r = FLD_MOD(r, x16 ? 1 : 0, 30, 30); /* HS_TX_TO_X16 */
  2862. r = FLD_MOD(r, x4 ? 1 : 0, 29, 29); /* HS_TX_TO_X8 (4 really) */
  2863. r = FLD_MOD(r, ticks, 28, 16); /* HS_TX_TO_COUNTER */
  2864. dsi_write_reg(dsidev, DSI_TIMING2, r);
  2865. total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
  2866. DSSDBG("HS_TX_TO %lu ticks (%#x%s%s) = %lu ns\n",
  2867. total_ticks,
  2868. ticks, x4 ? " x4" : "", x16 ? " x16" : "",
  2869. (total_ticks * 1000) / (fck / 1000 / 1000));
  2870. }
  2871. static int dsi_cmd_proto_config(struct omap_dss_device *dssdev)
  2872. {
  2873. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  2874. u32 r;
  2875. int buswidth = 0;
  2876. dsi_config_tx_fifo(dsidev, DSI_FIFO_SIZE_32,
  2877. DSI_FIFO_SIZE_32,
  2878. DSI_FIFO_SIZE_32,
  2879. DSI_FIFO_SIZE_32);
  2880. dsi_config_rx_fifo(dsidev, DSI_FIFO_SIZE_32,
  2881. DSI_FIFO_SIZE_32,
  2882. DSI_FIFO_SIZE_32,
  2883. DSI_FIFO_SIZE_32);
  2884. /* XXX what values for the timeouts? */
  2885. dsi_set_stop_state_counter(dsidev, 0x1000, false, false, true);
  2886. dsi_set_ta_timeout(dsidev, 0x1fff, true, true, true);
  2887. dsi_set_lp_rx_timeout(dsidev, 0x1fff, true, true, true);
  2888. dsi_set_hs_tx_timeout(dsidev, 0x1fff, true, true, true);
  2889. switch (dssdev->ctrl.pixel_size) {
  2890. case 16:
  2891. buswidth = 0;
  2892. break;
  2893. case 18:
  2894. buswidth = 1;
  2895. break;
  2896. case 24:
  2897. buswidth = 2;
  2898. break;
  2899. default:
  2900. BUG();
  2901. }
  2902. r = dsi_read_reg(dsidev, DSI_CTRL);
  2903. r = FLD_MOD(r, 1, 1, 1); /* CS_RX_EN */
  2904. r = FLD_MOD(r, 1, 2, 2); /* ECC_RX_EN */
  2905. r = FLD_MOD(r, 1, 3, 3); /* TX_FIFO_ARBITRATION */
  2906. r = FLD_MOD(r, 1, 4, 4); /* VP_CLK_RATIO, always 1, see errata*/
  2907. r = FLD_MOD(r, buswidth, 7, 6); /* VP_DATA_BUS_WIDTH */
  2908. r = FLD_MOD(r, 0, 8, 8); /* VP_CLK_POL */
  2909. r = FLD_MOD(r, 2, 13, 12); /* LINE_BUFFER, 2 lines */
  2910. r = FLD_MOD(r, 1, 14, 14); /* TRIGGER_RESET_MODE */
  2911. r = FLD_MOD(r, 1, 19, 19); /* EOT_ENABLE */
  2912. if (!dss_has_feature(FEAT_DSI_DCS_CMD_CONFIG_VC)) {
  2913. r = FLD_MOD(r, 1, 24, 24); /* DCS_CMD_ENABLE */
  2914. /* DCS_CMD_CODE, 1=start, 0=continue */
  2915. r = FLD_MOD(r, 0, 25, 25);
  2916. }
  2917. dsi_write_reg(dsidev, DSI_CTRL, r);
  2918. dsi_vc_initial_config(dsidev, 0);
  2919. dsi_vc_initial_config(dsidev, 1);
  2920. dsi_vc_initial_config(dsidev, 2);
  2921. dsi_vc_initial_config(dsidev, 3);
  2922. return 0;
  2923. }
  2924. static int dispc_to_dsi_clock(int val, int bytes_per_pixel, int lanes)
  2925. {
  2926. return (val * bytes_per_pixel + lanes / 2) / lanes;
  2927. }
  2928. static int dsi_video_proto_config(struct omap_dss_device *dssdev)
  2929. {
  2930. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  2931. struct omap_video_timings *timings = &dssdev->panel.timings;
  2932. int buswidth = 0;
  2933. u32 r;
  2934. int bytes_per_pixel;
  2935. int hbp, hfp, hsa, tl;
  2936. dsi_config_tx_fifo(dsidev, DSI_FIFO_SIZE_32,
  2937. DSI_FIFO_SIZE_32,
  2938. DSI_FIFO_SIZE_32,
  2939. DSI_FIFO_SIZE_32);
  2940. dsi_config_rx_fifo(dsidev, DSI_FIFO_SIZE_32,
  2941. DSI_FIFO_SIZE_32,
  2942. DSI_FIFO_SIZE_32,
  2943. DSI_FIFO_SIZE_32);
  2944. dsi_set_stop_state_counter(dsidev, 0x1fff, true, true, false);
  2945. dsi_set_ta_timeout(dsidev, 0x1fff, true, true, true);
  2946. dsi_set_lp_rx_timeout(dsidev, 0x1fff, true, true, false);
  2947. dsi_set_hs_tx_timeout(dsidev, 0x1fff, true, true, true);
  2948. switch (dssdev->ctrl.pixel_size) {
  2949. case 16:
  2950. buswidth = 0;
  2951. bytes_per_pixel = 2;
  2952. break;
  2953. case 18:
  2954. buswidth = 1;
  2955. bytes_per_pixel = 3;
  2956. break;
  2957. case 24:
  2958. buswidth = 2;
  2959. bytes_per_pixel = 3;
  2960. break;
  2961. default:
  2962. BUG();
  2963. }
  2964. r = dsi_read_reg(dsidev, DSI_CTRL);
  2965. r = FLD_MOD(r, 1, 3, 3); /* TX_FIFO_ARBITRATION */
  2966. r = FLD_MOD(r, 1, 4, 4); /* VP_CLK_RATIO, always 1, see errata*/
  2967. r = FLD_MOD(r, buswidth, 7, 6); /* VP_DATA_BUS_WIDTH */
  2968. r = FLD_MOD(r, 0, 8, 8); /* VP_CLK_POL */
  2969. r = FLD_MOD(r, 1, 9, 9); /* VP_DE_POL */
  2970. r = FLD_MOD(r, 0, 10, 10); /* VP_HSYNC_POL */
  2971. r = FLD_MOD(r, 1, 11, 11); /* VP_VSYNC_POL */
  2972. r = FLD_MOD(r, 2, 13, 12); /* LINE_BUFFER */
  2973. r = FLD_MOD(r, 1, 14, 14); /* TRIGGER_RESET_MODE */
  2974. r = FLD_MOD(r, 1, 15, 15); /* VP_VSYNC_START */
  2975. r = FLD_MOD(r, 1, 17, 17); /* VP_HSYNC_START */
  2976. r = FLD_MOD(r, 1, 19, 19); /* EOT_ENABLE */
  2977. r = FLD_MOD(r, 1, 20, 20); /* BLANKING_MODE */
  2978. r = FLD_MOD(r, 1, 21, 21); /* HFP_BLANKING */
  2979. r = FLD_MOD(r, 1, 22, 22); /* HBP_BLANKING */
  2980. r = FLD_MOD(r, 1, 23, 23); /* HSA_BLANKING */
  2981. dsi_write_reg(dsidev, DSI_CTRL, r);
  2982. if(!dssdev->skip_init){
  2983. dsi_vc_initial_config(dsidev, 0);
  2984. dsi_vc_initial_config(dsidev, 1);
  2985. dsi_vc_initial_config(dsidev, 2);
  2986. dsi_vc_initial_config(dsidev, 3);
  2987. }
  2988. hbp = dispc_to_dsi_clock(timings->hbp, bytes_per_pixel, 4);
  2989. hfp = dispc_to_dsi_clock(timings->hfp, bytes_per_pixel, 4);
  2990. hsa = dispc_to_dsi_clock(timings->hsw, bytes_per_pixel, 4);
  2991. tl = hbp + hfp + hsa +
  2992. dispc_to_dsi_clock(timings->x_res, bytes_per_pixel, 4);
  2993. r = dsi_read_reg(dsidev, DSI_VM_TIMING1);
  2994. r = FLD_MOD(r, hbp - 1, 11, 0); /* HBP */
  2995. r = FLD_MOD(r, hfp - 1, 23, 12); /* HFP */
  2996. r = FLD_MOD(r, hsa - 1, 31, 24); /* HSA */
  2997. dsi_write_reg(dsidev, DSI_VM_TIMING1, r);
  2998. r = dsi_read_reg(dsidev, DSI_VM_TIMING2);
  2999. r = FLD_MOD(r, timings->vbp, 7, 0); /* VBP */
  3000. r = FLD_MOD(r, timings->vfp, 15, 8); /* VFP */
  3001. r = FLD_MOD(r, timings->vsw, 23, 16); /* VSA */
  3002. r = FLD_MOD(r, 4, 27, 24); /* WINDOW_SYNC */
  3003. dsi_write_reg(dsidev, DSI_VM_TIMING2, r);
  3004. r = dsi_read_reg(dsidev, DSI_VM_TIMING3);
  3005. r = FLD_MOD(r, timings->y_res, 14, 0);
  3006. r = FLD_MOD(r, tl - 1, 31, 16);
  3007. dsi_write_reg(dsidev, DSI_VM_TIMING3, r);
  3008. /* TODO: either calculate these values or make them configurable */
  3009. r = FLD_VAL(72, 23, 16) | /* HSA_HS_INTERLEAVING */
  3010. FLD_VAL(114, 15, 8) | /* HFB_HS_INTERLEAVING */
  3011. FLD_VAL(150, 7, 0); /* HbB_HS_INTERLEAVING */
  3012. dsi_write_reg(dsidev, DSI_VM_TIMING4, r);
  3013. r = FLD_VAL(130, 23, 16) | /* HSA_LP_INTERLEAVING */
  3014. FLD_VAL(223, 15, 8) | /* HFB_LP_INTERLEAVING */
  3015. FLD_VAL(59, 7, 0); /* HBB_LP_INTERLEAVING */
  3016. dsi_write_reg(dsidev, DSI_VM_TIMING5, r);
  3017. r = FLD_VAL(0x7A67, 31, 16) | /* BL_HS_INTERLEAVING */
  3018. FLD_VAL(0x31D1, 15, 0); /* BL_LP_INTERLEAVING */
  3019. dsi_write_reg(dsidev, DSI_VM_TIMING6, r);
  3020. r = FLD_VAL(18, 31, 16) | /* ENTER_HS_MODE_LATENCY */
  3021. FLD_VAL(15, 15, 0); /* EXIT_HS_MODE_LATENCY */
  3022. dsi_write_reg(dsidev, DSI_VM_TIMING7, r);
  3023. return 0;
  3024. }
  3025. int dsi_video_mode_enable(struct omap_dss_device *dssdev, u8 data_type)
  3026. {
  3027. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3028. u16 word_count;
  3029. u32 r;
  3030. u32 header;
  3031. dsi_if_enable(dsidev, 0);
  3032. dsi_vc_enable(dsidev, 1, 0);
  3033. dsi_vc_enable(dsidev, 0, 0);
  3034. r = dsi_read_reg(dsidev, DSI_TIMING1);
  3035. r = FLD_MOD(r, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
  3036. dsi_write_reg(dsidev, DSI_TIMING1, r);
  3037. if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 15, 0) != 0)
  3038. BUG();
  3039. r = dsi_read_reg(dsidev, DSI_VC_CTRL(0));
  3040. r = FLD_MOD(r, 1, 4, 4);
  3041. r = FLD_MOD(r, 1, 9, 9);
  3042. dsi_write_reg(dsidev, DSI_VC_CTRL(0), r);
  3043. r = dsi_read_reg(dsidev, DSI_VC_CTRL(1));
  3044. r = FLD_MOD(r, 0, 4, 4);
  3045. r = FLD_MOD(r, 1, 9, 9);
  3046. dsi_write_reg(dsidev, DSI_VC_CTRL(1), r);
  3047. word_count = dssdev->panel.timings.x_res * 3;
  3048. header = FLD_VAL(0, 31, 24) | /* ECC */
  3049. FLD_VAL(word_count, 23, 8) | /* WORD_COUNT */
  3050. FLD_VAL(0, 7, 6) | /* VC_ID */
  3051. FLD_VAL(data_type, 5, 0);
  3052. dsi_write_reg(dsidev, DSI_VC_LONG_PACKET_HEADER(0), header);
  3053. dsi_vc_enable(dsidev, 1, 1);
  3054. dsi_vc_enable(dsidev, 0, 1);
  3055. dsi_if_enable(dsidev, 1);
  3056. return 0;
  3057. }
  3058. static void dsi_proto_timings(struct omap_dss_device *dssdev)
  3059. {
  3060. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3061. unsigned tlpx, tclk_zero, tclk_prepare, tclk_trail;
  3062. unsigned tclk_pre, tclk_post;
  3063. unsigned ths_prepare, ths_prepare_ths_zero, ths_zero;
  3064. unsigned ths_trail, ths_exit;
  3065. unsigned ddr_clk_pre, ddr_clk_post;
  3066. unsigned enter_hs_mode_lat, exit_hs_mode_lat;
  3067. unsigned ths_eot;
  3068. unsigned offset_ddr_clk;
  3069. u32 r;
  3070. r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG0);
  3071. ths_prepare = FLD_GET(r, 31, 24);
  3072. ths_prepare_ths_zero = FLD_GET(r, 23, 16);
  3073. ths_zero = ths_prepare_ths_zero - ths_prepare;
  3074. ths_trail = FLD_GET(r, 15, 8);
  3075. ths_exit = FLD_GET(r, 7, 0);
  3076. r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG1);
  3077. tlpx = FLD_GET(r, 22, 16) * 2;
  3078. tclk_trail = FLD_GET(r, 15, 8);
  3079. tclk_zero = FLD_GET(r, 7, 0);
  3080. r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG2);
  3081. tclk_prepare = FLD_GET(r, 7, 0);
  3082. /* min 8*UI */
  3083. tclk_pre = 20;
  3084. /* min 60ns + 52*UI */
  3085. tclk_post = ns2ddr(dsidev, 60) + 26;
  3086. ths_eot = DIV_ROUND_UP(4, dsi_get_num_data_lanes_dssdev(dssdev));
  3087. /* DDR PRE & DDR POST increased to keep LP-11 under 10 usec */
  3088. offset_ddr_clk = dssdev->clocks.dsi.offset_ddr_clk;
  3089. ddr_clk_pre = DIV_ROUND_UP(tclk_pre + tlpx + tclk_zero + tclk_prepare,
  3090. 4) + offset_ddr_clk;
  3091. ddr_clk_post = DIV_ROUND_UP(tclk_post + ths_trail, 4) + ths_eot
  3092. + offset_ddr_clk;
  3093. BUG_ON(ddr_clk_pre == 0 || ddr_clk_pre > 255);
  3094. BUG_ON(ddr_clk_post == 0 || ddr_clk_post > 255);
  3095. r = dsi_read_reg(dsidev, DSI_CLK_TIMING);
  3096. r = FLD_MOD(r, ddr_clk_pre, 15, 8);
  3097. r = FLD_MOD(r, ddr_clk_post, 7, 0);
  3098. dsi_write_reg(dsidev, DSI_CLK_TIMING, r);
  3099. DSSDBG("ddr_clk_pre %u, ddr_clk_post %u\n",
  3100. ddr_clk_pre,
  3101. ddr_clk_post);
  3102. enter_hs_mode_lat = 1 + DIV_ROUND_UP(tlpx, 4) +
  3103. DIV_ROUND_UP(ths_prepare, 4) +
  3104. DIV_ROUND_UP(ths_zero + 3, 4);
  3105. exit_hs_mode_lat = DIV_ROUND_UP(ths_trail + ths_exit, 4) + 1 + ths_eot;
  3106. r = FLD_VAL(enter_hs_mode_lat, 31, 16) |
  3107. FLD_VAL(exit_hs_mode_lat, 15, 0);
  3108. dsi_write_reg(dsidev, DSI_VM_TIMING7, r);
  3109. DSSDBG("enter_hs_mode_lat %u, exit_hs_mode_lat %u\n",
  3110. enter_hs_mode_lat, exit_hs_mode_lat);
  3111. }
  3112. #define DSI_DECL_VARS \
  3113. int __dsi_cb = 0; u32 __dsi_cv = 0;
  3114. #define DSI_FLUSH(dsidev, ch) \
  3115. if (__dsi_cb > 0) { \
  3116. /*DSSDBG("sending long packet %#010x\n", __dsi_cv);*/ \
  3117. dsi_write_reg(dsidev, DSI_VC_LONG_PACKET_PAYLOAD(ch), __dsi_cv); \
  3118. __dsi_cb = __dsi_cv = 0; \
  3119. }
  3120. #define DSI_PUSH(dsidev, ch, data) \
  3121. do { \
  3122. __dsi_cv |= (data) << (__dsi_cb * 8); \
  3123. /*DSSDBG("cv = %#010x, cb = %d\n", __dsi_cv, __dsi_cb);*/ \
  3124. if (++__dsi_cb > 3) \
  3125. DSI_FLUSH(dsidev, ch); \
  3126. } while (0)
  3127. static int dsi_update_screen_l4(struct omap_dss_device *dssdev,
  3128. int x, int y, int w, int h)
  3129. {
  3130. /* Note: supports only 24bit colors in 32bit container */
  3131. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3132. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3133. int first = 1;
  3134. int fifo_stalls = 0;
  3135. int max_dsi_packet_size;
  3136. int max_data_per_packet;
  3137. int max_pixels_per_packet;
  3138. int pixels_left;
  3139. int bytespp = dssdev->ctrl.pixel_size / 8;
  3140. int scr_width;
  3141. u32 __iomem *data;
  3142. int start_offset;
  3143. int horiz_inc;
  3144. int current_x;
  3145. struct omap_overlay *ovl;
  3146. debug_irq = 0;
  3147. DSSDBG("dsi_update_screen_l4 (%d,%d %dx%d)\n",
  3148. x, y, w, h);
  3149. ovl = dssdev->manager->overlays[0];
  3150. if (ovl->info.color_mode != OMAP_DSS_COLOR_RGB24U)
  3151. return -EINVAL;
  3152. if (dssdev->ctrl.pixel_size != 24)
  3153. return -EINVAL;
  3154. scr_width = ovl->info.screen_width;
  3155. data = ovl->info.vaddr;
  3156. start_offset = scr_width * y + x;
  3157. horiz_inc = scr_width - w;
  3158. current_x = x;
  3159. /* We need header(4) + DCSCMD(1) + pixels(numpix*bytespp) bytes
  3160. * in fifo */
  3161. /* When using CPU, max long packet size is TX buffer size */
  3162. max_dsi_packet_size = dsi->vc[0].fifo_size * 32 * 4;
  3163. /* we seem to get better perf if we divide the tx fifo to half,
  3164. and while the other half is being sent, we fill the other half
  3165. max_dsi_packet_size /= 2; */
  3166. max_data_per_packet = max_dsi_packet_size - 4 - 1;
  3167. max_pixels_per_packet = max_data_per_packet / bytespp;
  3168. DSSDBG("max_pixels_per_packet %d\n", max_pixels_per_packet);
  3169. pixels_left = w * h;
  3170. DSSDBG("total pixels %d\n", pixels_left);
  3171. data += start_offset;
  3172. while (pixels_left > 0) {
  3173. /* 0x2c = write_memory_start */
  3174. /* 0x3c = write_memory_continue */
  3175. u8 dcs_cmd = first ? 0x2c : 0x3c;
  3176. int pixels;
  3177. DSI_DECL_VARS;
  3178. first = 0;
  3179. #if 1
  3180. /* using fifo not empty */
  3181. /* TX_FIFO_NOT_EMPTY */
  3182. while (FLD_GET(dsi_read_reg(dsidev, DSI_VC_CTRL(0)), 5, 5)) {
  3183. fifo_stalls++;
  3184. if (fifo_stalls > 0xfffff) {
  3185. DSSERR("fifo stalls overflow, pixels left %d\n",
  3186. pixels_left);
  3187. dsi_if_enable(dsidev, 0);
  3188. return -EIO;
  3189. }
  3190. udelay(1);
  3191. }
  3192. #elif 1
  3193. /* using fifo emptiness */
  3194. while ((REG_GET(dsidev, DSI_TX_FIFO_VC_EMPTINESS, 7, 0)+1)*4 <
  3195. max_dsi_packet_size) {
  3196. fifo_stalls++;
  3197. if (fifo_stalls > 0xfffff) {
  3198. DSSERR("fifo stalls overflow, pixels left %d\n",
  3199. pixels_left);
  3200. dsi_if_enable(dsidev, 0);
  3201. return -EIO;
  3202. }
  3203. }
  3204. #else
  3205. while ((REG_GET(dsidev, DSI_TX_FIFO_VC_EMPTINESS,
  3206. 7, 0) + 1) * 4 == 0) {
  3207. fifo_stalls++;
  3208. if (fifo_stalls > 0xfffff) {
  3209. DSSERR("fifo stalls overflow, pixels left %d\n",
  3210. pixels_left);
  3211. dsi_if_enable(dsidev, 0);
  3212. return -EIO;
  3213. }
  3214. }
  3215. #endif
  3216. pixels = min(max_pixels_per_packet, pixels_left);
  3217. pixels_left -= pixels;
  3218. dsi_vc_write_long_header(dsidev, 0, DSI_DT_DCS_LONG_WRITE,
  3219. 1 + pixels * bytespp, 0);
  3220. DSI_PUSH(dsidev, 0, dcs_cmd);
  3221. while (pixels-- > 0) {
  3222. u32 pix = __raw_readl(data++);
  3223. DSI_PUSH(dsidev, 0, (pix >> 16) & 0xff);
  3224. DSI_PUSH(dsidev, 0, (pix >> 8) & 0xff);
  3225. DSI_PUSH(dsidev, 0, (pix >> 0) & 0xff);
  3226. current_x++;
  3227. if (current_x == x+w) {
  3228. current_x = x;
  3229. data += horiz_inc;
  3230. }
  3231. }
  3232. DSI_FLUSH(dsidev, 0);
  3233. }
  3234. return 0;
  3235. }
  3236. static void dsi_update_screen_dispc(struct omap_dss_device *dssdev,
  3237. u16 x, u16 y, u16 w, u16 h)
  3238. {
  3239. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3240. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3241. unsigned bytespp;
  3242. unsigned bytespl;
  3243. unsigned bytespf;
  3244. unsigned total_len;
  3245. unsigned packet_payload;
  3246. unsigned packet_len;
  3247. u32 l;
  3248. int r;
  3249. const unsigned channel = dsi->update_channel;
  3250. const unsigned line_buf_size = dsi_get_line_buf_size(dsidev);
  3251. DSSDBG("dsi_update_screen_dispc(%d,%d %dx%d)\n",
  3252. x, y, w, h);
  3253. if (dssdev->phy.dsi.type == OMAP_DSS_DSI_TYPE_VIDEO_MODE) {
  3254. dss_start_update(dssdev);
  3255. return;
  3256. }
  3257. dsi_vc_config_vp(dsidev, channel);
  3258. bytespp = dssdev->ctrl.pixel_size / 8;
  3259. bytespl = w * bytespp;
  3260. bytespf = bytespl * h;
  3261. /* NOTE: packet_payload has to be equal to N * bytespl, where N is
  3262. * number of lines in a packet. See errata about VP_CLK_RATIO */
  3263. if (bytespf < line_buf_size)
  3264. packet_payload = bytespf;
  3265. else
  3266. packet_payload = (line_buf_size) / bytespl * bytespl;
  3267. packet_len = packet_payload + 1; /* 1 byte for DCS cmd */
  3268. total_len = (bytespf / packet_payload) * packet_len;
  3269. if (bytespf % packet_payload)
  3270. total_len += (bytespf % packet_payload) + 1;
  3271. l = FLD_VAL(total_len, 23, 0); /* TE_SIZE */
  3272. dsi_write_reg(dsidev, DSI_VC_TE(channel), l);
  3273. dsi_vc_write_long_header(dsidev, channel, DSI_DT_DCS_LONG_WRITE,
  3274. packet_len, 0);
  3275. if (dsi->te_enabled)
  3276. l = FLD_MOD(l, 1, 30, 30); /* TE_EN */
  3277. else
  3278. l = FLD_MOD(l, 1, 31, 31); /* TE_START */
  3279. dsi_write_reg(dsidev, DSI_VC_TE(channel), l);
  3280. /* We put SIDLEMODE to no-idle for the duration of the transfer,
  3281. * because DSS interrupts are not capable of waking up the CPU and the
  3282. * framedone interrupt could be delayed for quite a long time. I think
  3283. * the same goes for any DSS interrupts, but for some reason I have not
  3284. * seen the problem anywhere else than here.
  3285. */
  3286. dispc_disable_sidle();
  3287. dsi_perf_mark_start(dsidev);
  3288. r = schedule_delayed_work(&dsi->framedone_timeout_work,
  3289. msecs_to_jiffies(250));
  3290. BUG_ON(r == 0);
  3291. dss_start_update(dssdev);
  3292. if (dsi->te_enabled) {
  3293. /* disable LP_RX_TO, so that we can receive TE. Time to wait
  3294. * for TE is longer than the timer allows */
  3295. REG_FLD_MOD(dsidev, DSI_TIMING2, 0, 15, 15); /* LP_RX_TO */
  3296. dsi_vc_send_bta(dsidev, channel);
  3297. #ifdef DSI_CATCH_MISSING_TE
  3298. mod_timer(&dsi->te_timer, jiffies + msecs_to_jiffies(250));
  3299. #endif
  3300. }
  3301. }
  3302. #ifdef DSI_CATCH_MISSING_TE
  3303. static void dsi_te_timeout(unsigned long arg)
  3304. {
  3305. DSSERR("TE not received for 250ms!\n");
  3306. }
  3307. #endif
  3308. static void dsi_handle_framedone(struct platform_device *dsidev, int error)
  3309. {
  3310. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3311. /* SIDLEMODE back to smart-idle */
  3312. dispc_enable_sidle();
  3313. if (dsi->te_enabled) {
  3314. /* enable LP_RX_TO again after the TE */
  3315. REG_FLD_MOD(dsidev, DSI_TIMING2, 1, 15, 15); /* LP_RX_TO */
  3316. }
  3317. dsi->framedone_callback(error, dsi->framedone_data);
  3318. if (!error)
  3319. dsi_perf_show(dsidev, "DISPC");
  3320. }
  3321. static void dsi_framedone_timeout_work_callback(struct work_struct *work)
  3322. {
  3323. struct dsi_data *dsi = container_of(work, struct dsi_data,
  3324. framedone_timeout_work.work);
  3325. /* XXX While extremely unlikely, we could get FRAMEDONE interrupt after
  3326. * 250ms which would conflict with this timeout work. What should be
  3327. * done is first cancel the transfer on the HW, and then cancel the
  3328. * possibly scheduled framedone work. However, cancelling the transfer
  3329. * on the HW is buggy, and would probably require resetting the whole
  3330. * DSI */
  3331. DSSERR("Framedone not received for 250ms!\n");
  3332. dsi_handle_framedone(dsi->pdev, -ETIMEDOUT);
  3333. }
  3334. static void dsi_framedone_irq_callback(void *data, u32 mask)
  3335. {
  3336. struct omap_dss_device *dssdev = (struct omap_dss_device *) data;
  3337. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3338. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3339. /* Note: We get FRAMEDONE when DISPC has finished sending pixels and
  3340. * turns itself off. However, DSI still has the pixels in its buffers,
  3341. * and is sending the data.
  3342. */
  3343. __cancel_delayed_work(&dsi->framedone_timeout_work);
  3344. dsi_handle_framedone(dsidev, 0);
  3345. #ifdef CONFIG_OMAP2_DSS_FAKE_VSYNC
  3346. dispc_fake_vsync_irq();
  3347. #endif
  3348. }
  3349. int omap_dsi_prepare_update(struct omap_dss_device *dssdev,
  3350. u16 *x, u16 *y, u16 *w, u16 *h,
  3351. bool enlarge_update_area)
  3352. {
  3353. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3354. u16 dw, dh;
  3355. dssdev->driver->get_resolution(dssdev, &dw, &dh);
  3356. if (*x > dw || *y > dh)
  3357. return -EINVAL;
  3358. if (*x + *w > dw)
  3359. return -EINVAL;
  3360. if (*y + *h > dh)
  3361. return -EINVAL;
  3362. if (*w == 1)
  3363. return -EINVAL;
  3364. if (*w == 0 || *h == 0)
  3365. return -EINVAL;
  3366. dsi_perf_mark_setup(dsidev);
  3367. if (dssdev->manager->caps & OMAP_DSS_OVL_MGR_CAP_DISPC) {
  3368. dss_setup_partial_planes(dssdev, x, y, w, h,
  3369. enlarge_update_area);
  3370. dispc_set_lcd_size(dssdev->manager->id, *w, *h);
  3371. }
  3372. return 0;
  3373. }
  3374. EXPORT_SYMBOL(omap_dsi_prepare_update);
  3375. int omap_dsi_update(struct omap_dss_device *dssdev,
  3376. int channel,
  3377. u16 x, u16 y, u16 w, u16 h,
  3378. void (*callback)(int, void *), void *data)
  3379. {
  3380. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3381. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3382. dsi->update_channel = channel;
  3383. /* OMAP DSS cannot send updates of odd widths.
  3384. * omap_dsi_prepare_update() makes the widths even, but add a BUG_ON
  3385. * here to make sure we catch erroneous updates. Otherwise we'll only
  3386. * see rather obscure HW error happening, as DSS halts. */
  3387. BUG_ON(x % 2 == 1);
  3388. if (dssdev->manager->caps & OMAP_DSS_OVL_MGR_CAP_DISPC) {
  3389. dsi->framedone_callback = callback;
  3390. dsi->framedone_data = data;
  3391. dsi->update_region.x = x;
  3392. dsi->update_region.y = y;
  3393. dsi->update_region.w = w;
  3394. dsi->update_region.h = h;
  3395. dsi->update_region.device = dssdev;
  3396. dsi_update_screen_dispc(dssdev, x, y, w, h);
  3397. } else {
  3398. int r;
  3399. r = dsi_update_screen_l4(dssdev, x, y, w, h);
  3400. if (r)
  3401. return r;
  3402. dsi_perf_show(dsidev, "L4");
  3403. callback(0, data);
  3404. }
  3405. return 0;
  3406. }
  3407. EXPORT_SYMBOL(omap_dsi_update);
  3408. /* Display funcs */
  3409. static int dsi_display_init_dispc(struct omap_dss_device *dssdev)
  3410. {
  3411. int r;
  3412. u32 irq;
  3413. irq = dssdev->manager->id == OMAP_DSS_CHANNEL_LCD ?
  3414. DISPC_IRQ_FRAMEDONE : DISPC_IRQ_FRAMEDONE2;
  3415. if (dssdev->phy.dsi.type == OMAP_DSS_DSI_TYPE_CMD_MODE) {
  3416. r = omap_dispc_register_isr(dsi_framedone_irq_callback, (void *) dssdev,
  3417. irq);
  3418. if (r) {
  3419. DSSERR("can't get FRAMEDONE irq\n");
  3420. return r;
  3421. }
  3422. dispc_set_parallel_interface_mode(dssdev->manager->id,
  3423. OMAP_DSS_PARALLELMODE_DSI);
  3424. dispc_enable_fifohandcheck(dssdev->manager->id, 1);
  3425. } else {
  3426. dispc_set_parallel_interface_mode(dssdev->manager->id,
  3427. OMAP_DSS_PARALLELMODE_BYPASS);
  3428. dispc_enable_fifohandcheck(dssdev->manager->id, 0);
  3429. }
  3430. dispc_set_lcd_display_type(dssdev->manager->id,
  3431. OMAP_DSS_LCD_DISPLAY_TFT);
  3432. dispc_set_tft_data_lines(dssdev->manager->id, dssdev->ctrl.pixel_size);
  3433. if(dssdev->phy.dsi.type == OMAP_DSS_DSI_TYPE_CMD_MODE) {
  3434. struct omap_video_timings timings = {
  3435. .hsw = 1,
  3436. .hfp = 1,
  3437. .hbp = 1,
  3438. .vsw = 1,
  3439. .vfp = 0,
  3440. .vbp = 0,
  3441. };
  3442. dispc_set_lcd_timings(dssdev->manager->id, &timings);
  3443. } else {
  3444. dispc_set_lcd_timings(dssdev->manager->id,
  3445. &dssdev->panel.timings);
  3446. }
  3447. return 0;
  3448. }
  3449. static void dsi_display_uninit_dispc(struct omap_dss_device *dssdev)
  3450. {
  3451. u32 irq;
  3452. irq = dssdev->manager->id == OMAP_DSS_CHANNEL_LCD ?
  3453. DISPC_IRQ_FRAMEDONE : DISPC_IRQ_FRAMEDONE2;
  3454. if(dssdev->phy.dsi.type == OMAP_DSS_DSI_TYPE_CMD_MODE)
  3455. omap_dispc_unregister_isr(dsi_framedone_irq_callback, (void *) dssdev,
  3456. irq);
  3457. }
  3458. static int dsi_configure_dsi_clocks(struct omap_dss_device *dssdev)
  3459. {
  3460. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3461. struct dsi_clock_info cinfo;
  3462. int r;
  3463. /* we always use DSS_CLK_SYSCK as input clock */
  3464. cinfo.use_sys_clk = true;
  3465. cinfo.regn = dssdev->clocks.dsi.regn;
  3466. cinfo.regm = dssdev->clocks.dsi.regm;
  3467. cinfo.regm_dispc = dssdev->clocks.dsi.regm_dispc;
  3468. cinfo.regm_dsi = dssdev->clocks.dsi.regm_dsi;
  3469. r = dsi_calc_clock_rates(dssdev, &cinfo);
  3470. if (r) {
  3471. DSSERR("Failed to calc dsi clocks\n");
  3472. return r;
  3473. }
  3474. r = dsi_pll_set_clock_div(dsidev, &cinfo);
  3475. if (r) {
  3476. DSSERR("Failed to set dsi clocks\n");
  3477. return r;
  3478. }
  3479. return 0;
  3480. }
  3481. static int dsi_configure_dispc_clocks(struct omap_dss_device *dssdev)
  3482. {
  3483. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3484. struct dispc_clock_info dispc_cinfo;
  3485. int r;
  3486. unsigned long long fck;
  3487. fck = dsi_get_pll_hsdiv_dispc_rate(dsidev);
  3488. dispc_cinfo.lck_div = dssdev->clocks.dispc.channel.lck_div;
  3489. dispc_cinfo.pck_div = dssdev->clocks.dispc.channel.pck_div;
  3490. r = dispc_calc_clock_rates(fck, &dispc_cinfo);
  3491. if (r) {
  3492. DSSERR("Failed to calc dispc clocks\n");
  3493. return r;
  3494. }
  3495. r = dispc_set_clock_div(dssdev->manager->id, &dispc_cinfo);
  3496. if (r) {
  3497. DSSERR("Failed to set dispc clocks\n");
  3498. return r;
  3499. }
  3500. return 0;
  3501. }
  3502. static int dsi_display_init_dsi(struct omap_dss_device *dssdev)
  3503. {
  3504. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3505. int dsi_module = dsi_get_dsidev_id(dsidev);
  3506. int r;
  3507. /* The SCPClk is required for PLL and complexio registers on OMAP4 */
  3508. if (cpu_is_omap44xx())
  3509. REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 1, 14, 14);
  3510. r = dsi_pll_init(dsidev, true, true);
  3511. if (r)
  3512. goto err0;
  3513. if(!dssdev->skip_init){
  3514. r = dsi_configure_dsi_clocks(dssdev);
  3515. if (r)
  3516. goto err1;
  3517. }
  3518. dss_select_dispc_clk_source(dssdev->clocks.dispc.dispc_fclk_src);
  3519. dss_select_dsi_clk_source(dsi_module, dssdev->clocks.dsi.dsi_fclk_src);
  3520. dss_select_lcd_clk_source(dssdev->manager->id,
  3521. dssdev->clocks.dispc.channel.lcd_clk_src);
  3522. DSSDBG("PLL OK\n");
  3523. if(!dssdev->skip_init){
  3524. r = dsi_configure_dispc_clocks(dssdev);
  3525. if (r)
  3526. goto err2;
  3527. }
  3528. if(!dssdev->skip_init){
  3529. r = dsi_cio_init(dssdev);
  3530. if (r)
  3531. goto err2;
  3532. }
  3533. else
  3534. dsi_enable_scp_clk(dsidev);
  3535. _dsi_print_reset_status(dsidev);
  3536. dsi_proto_timings(dssdev);
  3537. dsi_set_lp_clk_divisor(dssdev);
  3538. if (1)
  3539. _dsi_print_reset_status(dsidev);
  3540. if(dssdev->phy.dsi.type == OMAP_DSS_DSI_TYPE_CMD_MODE)
  3541. r = dsi_cmd_proto_config(dssdev);
  3542. else
  3543. r = dsi_video_proto_config(dssdev);
  3544. if (r)
  3545. goto err3;
  3546. /* enable interface */
  3547. if(!dssdev->skip_init){
  3548. dsi_vc_enable(dsidev, 0, 1);
  3549. dsi_vc_enable(dsidev, 1, 1);
  3550. dsi_vc_enable(dsidev, 2, 1);
  3551. dsi_vc_enable(dsidev, 3, 1);
  3552. dsi_if_enable(dsidev, 1);
  3553. dsi_force_tx_stop_mode_io(dsidev);
  3554. }
  3555. return 0;
  3556. err3:
  3557. dsi_cio_uninit(dsidev);
  3558. err2:
  3559. dss_select_dispc_clk_source(OMAP_DSS_CLK_SRC_FCK);
  3560. dss_select_dsi_clk_source(dsi_module, OMAP_DSS_CLK_SRC_FCK);
  3561. err1:
  3562. dsi_pll_uninit(dsidev, true);
  3563. err0:
  3564. return r;
  3565. }
  3566. static void dsi_display_uninit_dsi(struct omap_dss_device *dssdev,
  3567. bool disconnect_lanes, bool enter_ulps)
  3568. {
  3569. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3570. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3571. int dsi_module = dsi_get_dsidev_id(dsidev);
  3572. if (enter_ulps && !dsi->ulps_enabled)
  3573. dsi_enter_ulps(dsidev);
  3574. /* disable interface */
  3575. dsi_if_enable(dsidev, 0);
  3576. dsi_vc_enable(dsidev, 0, 0);
  3577. dsi_vc_enable(dsidev, 1, 0);
  3578. dsi_vc_enable(dsidev, 2, 0);
  3579. dsi_vc_enable(dsidev, 3, 0);
  3580. dss_select_dispc_clk_source(OMAP_DSS_CLK_SRC_FCK);
  3581. dss_select_dsi_clk_source(dsi_module, OMAP_DSS_CLK_SRC_FCK);
  3582. dsi_cio_uninit(dsidev);
  3583. dsi_pll_uninit(dsidev, disconnect_lanes);
  3584. }
  3585. int omapdss_dsi_display_enable(struct omap_dss_device *dssdev)
  3586. {
  3587. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3588. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3589. int r = 0;
  3590. DSSDBG("dsi_display_enable\n");
  3591. WARN_ON(!dsi_bus_is_locked(dsidev));
  3592. mutex_lock(&dsi->lock);
  3593. r = omap_dss_start_device(dssdev);
  3594. if (r) {
  3595. DSSERR("failed to start device\n");
  3596. goto err_start_dev;
  3597. }
  3598. r = dsi_runtime_get(dsidev);
  3599. if (r)
  3600. goto err_get_dsi;
  3601. if(!dssdev->skip_init)
  3602. dsi_enable_pll_clock(dsidev, 1);
  3603. _dsi_initialize_irq(dsidev);
  3604. if(!dssdev->skip_init){
  3605. r = dsi_display_init_dispc(dssdev);
  3606. if (r)
  3607. goto err_init_dispc;
  3608. }
  3609. r = dsi_display_init_dsi(dssdev);
  3610. if (r)
  3611. goto err_init_dsi;
  3612. mutex_unlock(&dsi->lock);
  3613. return 0;
  3614. err_init_dsi:
  3615. dsi_display_uninit_dispc(dssdev);
  3616. err_init_dispc:
  3617. dsi_enable_pll_clock(dsidev, 0);
  3618. dsi_runtime_put(dsidev);
  3619. err_get_dsi:
  3620. omap_dss_stop_device(dssdev);
  3621. err_start_dev:
  3622. mutex_unlock(&dsi->lock);
  3623. DSSDBG("dsi_display_enable FAILED\n");
  3624. return r;
  3625. }
  3626. EXPORT_SYMBOL(omapdss_dsi_display_enable);
  3627. void omapdss_dsi_display_disable(struct omap_dss_device *dssdev,
  3628. bool disconnect_lanes, bool enter_ulps)
  3629. {
  3630. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3631. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3632. DSSDBG("dsi_display_disable\n");
  3633. WARN_ON(!dsi_bus_is_locked(dsidev));
  3634. mutex_lock(&dsi->lock);
  3635. dsi_display_uninit_dispc(dssdev);
  3636. dsi_display_uninit_dsi(dssdev, disconnect_lanes, enter_ulps);
  3637. dsi_runtime_put(dsidev);
  3638. dsi_enable_pll_clock(dsidev, 0);
  3639. omap_dss_stop_device(dssdev);
  3640. mutex_unlock(&dsi->lock);
  3641. }
  3642. EXPORT_SYMBOL(omapdss_dsi_display_disable);
  3643. int omapdss_dsi_enable_te(struct omap_dss_device *dssdev, bool enable)
  3644. {
  3645. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3646. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3647. dsi->te_enabled = enable;
  3648. return 0;
  3649. }
  3650. EXPORT_SYMBOL(omapdss_dsi_enable_te);
  3651. void dsi_get_overlay_fifo_thresholds(enum omap_plane plane,
  3652. u32 fifo_size, enum omap_burst_size *burst_size,
  3653. u32 *fifo_low, u32 *fifo_high)
  3654. {
  3655. unsigned burst_size_bytes;
  3656. *burst_size = OMAP_DSS_BURST_16x32;
  3657. burst_size_bytes = 16 * 32 / 8;
  3658. *fifo_high = fifo_size - burst_size_bytes;
  3659. *fifo_low = fifo_size - burst_size_bytes * 2;
  3660. }
  3661. int dsi_init_display(struct omap_dss_device *dssdev)
  3662. {
  3663. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3664. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3665. int dsi_module = dsi_get_dsidev_id(dsidev);
  3666. DSSDBG("DSI init\n");
  3667. if(dssdev->phy.dsi.type == OMAP_DSS_DSI_TYPE_CMD_MODE) {
  3668. dssdev->caps = OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE |
  3669. OMAP_DSS_DISPLAY_CAP_TEAR_ELIM;
  3670. } else {
  3671. dssdev->caps = 0;
  3672. }
  3673. if (dsi->vdds_dsi_reg == NULL) {
  3674. struct regulator *vdds_dsi;
  3675. vdds_dsi = regulator_get(&dsi->pdev->dev, "vdds_dsi");
  3676. if (IS_ERR(vdds_dsi)) {
  3677. DSSERR("can't get VDDS_DSI regulator\n");
  3678. return PTR_ERR(vdds_dsi);
  3679. }
  3680. dsi->vdds_dsi_reg = vdds_dsi;
  3681. }
  3682. if (dsi_get_num_data_lanes_dssdev(dssdev) > dsi->num_data_lanes) {
  3683. DSSERR("DSI%d can't support more than %d data lanes\n",
  3684. dsi_module + 1, dsi->num_data_lanes);
  3685. return -EINVAL;
  3686. }
  3687. return 0;
  3688. }
  3689. int omap_dsi_request_vc(struct omap_dss_device *dssdev, int *channel)
  3690. {
  3691. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3692. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3693. int i;
  3694. for (i = 0; i < ARRAY_SIZE(dsi->vc); i++) {
  3695. if (!dsi->vc[i].dssdev) {
  3696. dsi->vc[i].dssdev = dssdev;
  3697. *channel = i;
  3698. return 0;
  3699. }
  3700. }
  3701. DSSERR("cannot get VC for display %s", dssdev->name);
  3702. return -ENOSPC;
  3703. }
  3704. EXPORT_SYMBOL(omap_dsi_request_vc);
  3705. int omap_dsi_set_vc_id(struct omap_dss_device *dssdev, int channel, int vc_id)
  3706. {
  3707. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3708. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3709. if (vc_id < 0 || vc_id > 3) {
  3710. DSSERR("VC ID out of range\n");
  3711. return -EINVAL;
  3712. }
  3713. if (channel < 0 || channel > 3) {
  3714. DSSERR("Virtual Channel out of range\n");
  3715. return -EINVAL;
  3716. }
  3717. if (dsi->vc[channel].dssdev != dssdev) {
  3718. DSSERR("Virtual Channel not allocated to display %s\n",
  3719. dssdev->name);
  3720. return -EINVAL;
  3721. }
  3722. dsi->vc[channel].vc_id = vc_id;
  3723. return 0;
  3724. }
  3725. EXPORT_SYMBOL(omap_dsi_set_vc_id);
  3726. void omap_dsi_release_vc(struct omap_dss_device *dssdev, int channel)
  3727. {
  3728. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3729. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3730. if ((channel >= 0 && channel <= 3) &&
  3731. dsi->vc[channel].dssdev == dssdev) {
  3732. dsi->vc[channel].dssdev = NULL;
  3733. dsi->vc[channel].vc_id = 0;
  3734. }
  3735. }
  3736. EXPORT_SYMBOL(omap_dsi_release_vc);
  3737. void dsi_wait_pll_hsdiv_dispc_active(struct platform_device *dsidev)
  3738. {
  3739. if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 7, 1) != 1)
  3740. DSSERR("%s (%s) not active\n",
  3741. dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC),
  3742. dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC));
  3743. }
  3744. void dsi_wait_pll_hsdiv_dsi_active(struct platform_device *dsidev)
  3745. {
  3746. if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 8, 1) != 1)
  3747. DSSERR("%s (%s) not active\n",
  3748. dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI),
  3749. dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI));
  3750. }
  3751. static void dsi_calc_clock_param_ranges(struct platform_device *dsidev)
  3752. {
  3753. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3754. dsi->regn_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGN);
  3755. dsi->regm_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM);
  3756. dsi->regm_dispc_max =
  3757. dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM_DISPC);
  3758. dsi->regm_dsi_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM_DSI);
  3759. dsi->fint_min = dss_feat_get_param_min(FEAT_PARAM_DSIPLL_FINT);
  3760. dsi->fint_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_FINT);
  3761. dsi->lpdiv_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_LPDIV);
  3762. }
  3763. static int dsi_get_clocks(struct platform_device *dsidev)
  3764. {
  3765. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3766. struct clk *clk;
  3767. clk = clk_get(&dsidev->dev, "dss_clk");
  3768. if (IS_ERR(clk)) {
  3769. DSSERR("can't get dss_clk\n");
  3770. return PTR_ERR(clk);
  3771. }
  3772. dsi->dss_clk = clk;
  3773. clk = clk_get(&dsidev->dev, "sys_clk");
  3774. if (IS_ERR(clk)) {
  3775. DSSERR("can't get sys_clk\n");
  3776. clk_put(dsi->dss_clk);
  3777. dsi->dss_clk = NULL;
  3778. return PTR_ERR(clk);
  3779. }
  3780. dsi->sys_clk = clk;
  3781. return 0;
  3782. }
  3783. static void dsi_put_clocks(struct platform_device *dsidev)
  3784. {
  3785. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3786. if (dsi->dss_clk)
  3787. clk_put(dsi->dss_clk);
  3788. if (dsi->sys_clk)
  3789. clk_put(dsi->sys_clk);
  3790. }
  3791. /* DSI1 HW IP initialisation */
  3792. static int omap_dsi1hw_probe(struct platform_device *dsidev)
  3793. {
  3794. struct omap_display_platform_data *dss_plat_data;
  3795. struct omap_dss_board_info *board_info;
  3796. u32 rev;
  3797. int r, i, dsi_module = dsi_get_dsidev_id(dsidev);
  3798. struct resource *dsi_mem;
  3799. struct dsi_data *dsi;
  3800. dsi = kzalloc(sizeof(*dsi), GFP_KERNEL);
  3801. if (!dsi) {
  3802. r = -ENOMEM;
  3803. goto err_alloc;
  3804. }
  3805. dsi->pdev = dsidev;
  3806. dsi_pdev_map[dsi_module] = dsidev;
  3807. dev_set_drvdata(&dsidev->dev, dsi);
  3808. dss_plat_data = dsidev->dev.platform_data;
  3809. board_info = dss_plat_data->board_data;
  3810. dsi->dsi_mux_pads = board_info->dsi_mux_pads;
  3811. spin_lock_init(&dsi->irq_lock);
  3812. spin_lock_init(&dsi->errors_lock);
  3813. dsi->errors = 0;
  3814. #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
  3815. spin_lock_init(&dsi->irq_stats_lock);
  3816. dsi->irq_stats.last_reset = jiffies;
  3817. #endif
  3818. mutex_init(&dsi->lock);
  3819. sema_init(&dsi->bus_lock, 1);
  3820. r = dsi_get_clocks(dsidev);
  3821. if (r)
  3822. goto err_get_clk;
  3823. mutex_init(&dsi->runtime_lock);
  3824. pm_runtime_enable(&dsidev->dev);
  3825. INIT_DELAYED_WORK_DEFERRABLE(&dsi->framedone_timeout_work,
  3826. dsi_framedone_timeout_work_callback);
  3827. #ifdef DSI_CATCH_MISSING_TE
  3828. init_timer(&dsi->te_timer);
  3829. dsi->te_timer.function = dsi_te_timeout;
  3830. dsi->te_timer.data = 0;
  3831. #endif
  3832. dsi_mem = platform_get_resource(dsi->pdev, IORESOURCE_MEM, 0);
  3833. if (!dsi_mem) {
  3834. DSSERR("can't get IORESOURCE_MEM DSI\n");
  3835. r = -EINVAL;
  3836. goto err_ioremap;
  3837. }
  3838. dsi->base = ioremap(dsi_mem->start, resource_size(dsi_mem));
  3839. if (!dsi->base) {
  3840. DSSERR("can't ioremap DSI\n");
  3841. r = -ENOMEM;
  3842. goto err_ioremap;
  3843. }
  3844. dsi->irq = platform_get_irq(dsi->pdev, 0);
  3845. if (dsi->irq < 0) {
  3846. DSSERR("platform_get_irq failed\n");
  3847. r = -ENODEV;
  3848. goto err_get_irq;
  3849. }
  3850. r = request_irq(dsi->irq, omap_dsi_irq_handler, IRQF_SHARED,
  3851. dev_name(&dsidev->dev), dsi->pdev);
  3852. if (r < 0) {
  3853. DSSERR("request_irq failed\n");
  3854. goto err_get_irq;
  3855. }
  3856. /* DSI VCs initialization */
  3857. for (i = 0; i < ARRAY_SIZE(dsi->vc); i++) {
  3858. dsi->vc[i].mode = DSI_VC_MODE_L4;
  3859. dsi->vc[i].dssdev = NULL;
  3860. dsi->vc[i].vc_id = 0;
  3861. }
  3862. dsi_calc_clock_param_ranges(dsidev);
  3863. r = dsi_runtime_get(dsidev);
  3864. if (r)
  3865. goto err_get_dsi;
  3866. rev = dsi_read_reg(dsidev, DSI_REVISION);
  3867. dev_dbg(&dsidev->dev, "OMAP DSI rev %d.%d\n",
  3868. FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
  3869. dsi->num_data_lanes = dsi_get_num_data_lanes(dsidev);
  3870. dsi_runtime_put(dsidev);
  3871. return 0;
  3872. err_get_dsi:
  3873. free_irq(dsi->irq, dsi->pdev);
  3874. err_get_irq:
  3875. iounmap(dsi->base);
  3876. err_ioremap:
  3877. pm_runtime_disable(&dsidev->dev);
  3878. err_get_clk:
  3879. kfree(dsi);
  3880. err_alloc:
  3881. return r;
  3882. }
  3883. static int omap_dsi1hw_remove(struct platform_device *dsidev)
  3884. {
  3885. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3886. WARN_ON(dsi->scp_clk_refcount > 0);
  3887. pm_runtime_disable(&dsidev->dev);
  3888. dsi_put_clocks(dsidev);
  3889. if (dsi->vdds_dsi_reg != NULL) {
  3890. if (dsi->vdds_dsi_enabled) {
  3891. regulator_disable(dsi->vdds_dsi_reg);
  3892. dsi->vdds_dsi_enabled = false;
  3893. }
  3894. regulator_put(dsi->vdds_dsi_reg);
  3895. dsi->vdds_dsi_reg = NULL;
  3896. }
  3897. free_irq(dsi->irq, dsi->pdev);
  3898. iounmap(dsi->base);
  3899. kfree(dsi);
  3900. return 0;
  3901. }
  3902. static struct platform_driver omap_dsi1hw_driver = {
  3903. .probe = omap_dsi1hw_probe,
  3904. .remove = omap_dsi1hw_remove,
  3905. .driver = {
  3906. .name = "omapdss_dsi1",
  3907. .owner = THIS_MODULE,
  3908. },
  3909. };
  3910. int dsi_init_platform_driver(void)
  3911. {
  3912. return platform_driver_register(&omap_dsi1hw_driver);
  3913. }
  3914. void dsi_uninit_platform_driver(void)
  3915. {
  3916. return platform_driver_unregister(&omap_dsi1hw_driver);
  3917. }