hdmi.c 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930
  1. /*
  2. * hdmi.c
  3. *
  4. * HDMI interface DSS driver setting for TI's OMAP4 family of processor.
  5. * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com/
  6. * Authors: Yong Zhi
  7. * Mythri pk <mythripk@ti.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License version 2 as published by
  11. * the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but WITHOUT
  14. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  16. * more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along with
  19. * this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #define DSS_SUBSYS_NAME "HDMI"
  22. #include <linux/kernel.h>
  23. #include <linux/module.h>
  24. #include <linux/err.h>
  25. #include <linux/io.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/mutex.h>
  28. #include <linux/delay.h>
  29. #include <linux/string.h>
  30. #include <linux/platform_device.h>
  31. #include <linux/pm_runtime.h>
  32. #include <linux/clk.h>
  33. #include <video/omapdss.h>
  34. #if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \
  35. defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE)
  36. #include <sound/soc.h>
  37. #include <sound/pcm_params.h>
  38. #endif
  39. #include "ti_hdmi.h"
  40. #include "dss.h"
  41. #include "hdmi.h"
  42. #include "dss_features.h"
  43. #define HDMI_WP 0x0
  44. #define HDMI_CORE_SYS 0x400
  45. #define HDMI_CORE_AV 0x900
  46. #define HDMI_PLLCTRL 0x200
  47. #define HDMI_PHY 0x300
  48. static struct {
  49. struct mutex lock;
  50. struct omap_display_platform_data *pdata;
  51. struct platform_device *pdev;
  52. struct hdmi_ip_data ip_data;
  53. int code;
  54. int mode;
  55. u8 edid[HDMI_EDID_MAX_LENGTH];
  56. u8 edid_set;
  57. bool custom_set;
  58. struct clk *sys_clk;
  59. } hdmi;
  60. /*
  61. * Logic for the below structure :
  62. * user enters the CEA or VESA timings by specifying the HDMI/DVI code.
  63. * There is a correspondence between CEA/VESA timing and code, please
  64. * refer to section 6.3 in HDMI 1.3 specification for timing code.
  65. *
  66. * In the below structure, cea_vesa_timings corresponds to all OMAP4
  67. * supported CEA and VESA timing values.code_cea corresponds to the CEA
  68. * code, It is used to get the timing from cea_vesa_timing array.Similarly
  69. * with code_vesa. Code_index is used for back mapping, that is once EDID
  70. * is read from the TV, EDID is parsed to find the timing values and then
  71. * map it to corresponding CEA or VESA index.
  72. */
  73. static const struct hdmi_timings cea_vesa_timings[OMAP_HDMI_TIMINGS_NB] = {
  74. { {640, 480, 25200, 96, 16, 48, 2, 10, 33} , 0 , 0},
  75. { {1280, 720, 74250, 40, 440, 220, 5, 5, 20}, 1, 1},
  76. { {1280, 720, 74250, 40, 110, 220, 5, 5, 20}, 1, 1},
  77. { {720, 480, 27027, 62, 16, 60, 6, 9, 30}, 0, 0},
  78. { {2880, 576, 108000, 256, 48, 272, 5, 5, 39}, 0, 0},
  79. { {1440, 240, 27027, 124, 38, 114, 3, 4, 15}, 0, 0},
  80. { {1440, 288, 27000, 126, 24, 138, 3, 2, 19}, 0, 0},
  81. { {1920, 540, 74250, 44, 528, 148, 5, 2, 15}, 1, 1},
  82. { {1920, 540, 74250, 44, 88, 148, 5, 2, 15}, 1, 1},
  83. { {1920, 1080, 148500, 44, 88, 148, 5, 4, 36}, 1, 1},
  84. { {720, 576, 27000, 64, 12, 68, 5, 5, 39}, 0, 0},
  85. { {1440, 576, 54000, 128, 24, 136, 5, 5, 39}, 0, 0},
  86. { {1920, 1080, 148500, 44, 528, 148, 5, 4, 36}, 1, 1},
  87. { {2880, 480, 108108, 248, 64, 240, 6, 9, 30}, 0, 0},
  88. { {1920, 1080, 74250, 44, 638, 148, 5, 4, 36}, 1, 1},
  89. /* VESA From Here */
  90. { {640, 480, 25175, 96, 16, 48, 2 , 11, 31}, 0, 0},
  91. { {800, 600, 40000, 128, 40, 88, 4 , 1, 23}, 1, 1},
  92. { {848, 480, 33750, 112, 16, 112, 8 , 6, 23}, 1, 1},
  93. { {1280, 768, 79500, 128, 64, 192, 7 , 3, 20}, 1, 0},
  94. { {1280, 800, 83500, 128, 72, 200, 6 , 3, 22}, 1, 0},
  95. { {1360, 768, 85500, 112, 64, 256, 6 , 3, 18}, 1, 1},
  96. { {1280, 960, 108000, 112, 96, 312, 3 , 1, 36}, 1, 1},
  97. { {1280, 1024, 108000, 112, 48, 248, 3 , 1, 38}, 1, 1},
  98. { {1024, 768, 65000, 136, 24, 160, 6, 3, 29}, 0, 0},
  99. { {1400, 1050, 121750, 144, 88, 232, 4, 3, 32}, 1, 0},
  100. { {1440, 900, 106500, 152, 80, 232, 6, 3, 25}, 1, 0},
  101. { {1680, 1050, 146250, 176 , 104, 280, 6, 3, 30}, 1, 0},
  102. { {1366, 768, 85500, 143, 70, 213, 3, 3, 24}, 1, 1},
  103. { {1920, 1080, 148500, 44, 148, 80, 5, 4, 36}, 1, 1},
  104. { {1280, 768, 68250, 32, 48, 80, 7, 3, 12}, 0, 1},
  105. { {1400, 1050, 101000, 32, 48, 80, 4, 3, 23}, 0, 1},
  106. { {1680, 1050, 119000, 32, 48, 80, 6, 3, 21}, 0, 1},
  107. { {1280, 800, 79500, 32, 48, 80, 6, 3, 14}, 0, 1},
  108. { {1280, 720, 74250, 40, 110, 220, 5, 5, 20}, 1, 1}
  109. };
  110. /*
  111. * This is a static mapping array which maps the timing values
  112. * with corresponding CEA / VESA code
  113. */
  114. static const int code_index[OMAP_HDMI_TIMINGS_NB] = {
  115. 1, 19, 4, 2, 37, 6, 21, 20, 5, 16, 17, 29, 31, 35, 32,
  116. /* <--15 CEA 17--> vesa*/
  117. 4, 9, 0xE, 0x17, 0x1C, 0x27, 0x20, 0x23, 0x10, 0x2A,
  118. 0X2F, 0x3A, 0X51, 0X52, 0x16, 0x29, 0x39, 0x1B
  119. };
  120. /*
  121. * This is reverse static mapping which maps the CEA / VESA code
  122. * to the corresponding timing values
  123. */
  124. static const int code_cea[39] = {
  125. -1, 0, 3, 3, 2, 8, 5, 5, -1, -1,
  126. -1, -1, -1, -1, -1, -1, 9, 10, 10, 1,
  127. 7, 6, 6, -1, -1, -1, -1, -1, -1, 11,
  128. 11, 12, 14, -1, -1, 13, 13, 4, 4
  129. };
  130. static const int code_vesa[85] = {
  131. -1, -1, -1, -1, 15, -1, -1, -1, -1, 16,
  132. -1, -1, -1, -1, 17, -1, 23, -1, -1, -1,
  133. -1, -1, 29, 18, -1, -1, -1, 32, 19, -1,
  134. -1, -1, 21, -1, -1, 22, -1, -1, -1, 20,
  135. -1, 30, 24, -1, -1, -1, -1, 25, -1, -1,
  136. -1, -1, -1, -1, -1, -1, -1, 31, 26, -1,
  137. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  138. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  139. -1, 27, 28, -1, 33};
  140. static const u8 edid_header[8] = {0x0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0};
  141. static inline void hdmi_write_reg(void __iomem *base_addr,
  142. const struct hdmi_reg idx, u32 val)
  143. {
  144. __raw_writel(val, base_addr + idx.idx);
  145. }
  146. static inline u32 hdmi_read_reg(void __iomem *base_addr,
  147. const struct hdmi_reg idx)
  148. {
  149. return __raw_readl(base_addr + idx.idx);
  150. }
  151. static inline void __iomem *hdmi_wp_base(struct hdmi_ip_data *ip_data)
  152. {
  153. return ip_data->base_wp;
  154. }
  155. static inline void __iomem *hdmi_phy_base(struct hdmi_ip_data *ip_data)
  156. {
  157. return ip_data->base_wp + ip_data->phy_offset;
  158. }
  159. static inline void __iomem *hdmi_pll_base(struct hdmi_ip_data *ip_data)
  160. {
  161. return ip_data->base_wp + ip_data->pll_offset;
  162. }
  163. static inline void __iomem *hdmi_av_base(struct hdmi_ip_data *ip_data)
  164. {
  165. return ip_data->base_wp + ip_data->core_av_offset;
  166. }
  167. static inline void __iomem *hdmi_core_sys_base(struct hdmi_ip_data *ip_data)
  168. {
  169. return ip_data->base_wp + ip_data->core_sys_offset;
  170. }
  171. static inline int hdmi_wait_for_bit_change(void __iomem *base_addr,
  172. const struct hdmi_reg idx,
  173. int b2, int b1, u32 val)
  174. {
  175. u32 t = 0;
  176. while (val != REG_GET(base_addr, idx, b2, b1)) {
  177. udelay(1);
  178. if (t++ > 10000)
  179. return !val;
  180. }
  181. return val;
  182. }
  183. static int hdmi_runtime_get(void)
  184. {
  185. int r;
  186. DSSDBG("hdmi_runtime_get\n");
  187. r = pm_runtime_get_sync(&hdmi.pdev->dev);
  188. WARN_ON(r < 0);
  189. return r < 0 ? r : 0;
  190. }
  191. static void hdmi_runtime_put(void)
  192. {
  193. int r;
  194. DSSDBG("hdmi_runtime_put\n");
  195. r = pm_runtime_put(&hdmi.pdev->dev);
  196. WARN_ON(r < 0);
  197. }
  198. int hdmi_init_display(struct omap_dss_device *dssdev)
  199. {
  200. DSSDBG("init_display\n");
  201. return 0;
  202. }
  203. static int hdmi_pll_init(struct hdmi_ip_data *ip_data)
  204. {
  205. u32 r;
  206. void __iomem *pll_base = hdmi_pll_base(ip_data);
  207. struct hdmi_pll_info *fmt = &ip_data->pll_data;
  208. /* PLL start always use manual mode */
  209. REG_FLD_MOD(pll_base, PLLCTRL_PLL_CONTROL, 0x0, 0, 0);
  210. r = hdmi_read_reg(pll_base, PLLCTRL_CFG1);
  211. r = FLD_MOD(r, fmt->regm, 20, 9); /* CFG1_PLL_REGM */
  212. r = FLD_MOD(r, fmt->regn, 8, 1); /* CFG1_PLL_REGN */
  213. hdmi_write_reg(pll_base, PLLCTRL_CFG1, r);
  214. r = hdmi_read_reg(pll_base, PLLCTRL_CFG2);
  215. r = FLD_MOD(r, 0x0, 12, 12); /* PLL_HIGHFREQ divide by 2 */
  216. r = FLD_MOD(r, 0x1, 13, 13); /* PLL_REFEN */
  217. r = FLD_MOD(r, 0x0, 14, 14); /* PHY_CLKINEN de-assert during locking */
  218. r = FLD_MOD(r, fmt->refsel, 22, 21); /* REFSEL */
  219. if (fmt->dcofreq) {
  220. /* divider programming for frequency beyond 1000Mhz */
  221. REG_FLD_MOD(pll_base, PLLCTRL_CFG3, fmt->regsd, 17, 10);
  222. r = FLD_MOD(r, 0x4, 3, 1); /* 1000MHz and 2000MHz */
  223. } else {
  224. r = FLD_MOD(r, 0x2, 3, 1); /* 500MHz and 1000MHz */
  225. }
  226. hdmi_write_reg(pll_base, PLLCTRL_CFG2, r);
  227. r = hdmi_read_reg(pll_base, PLLCTRL_CFG4);
  228. r = FLD_MOD(r, fmt->regm2, 24, 18);
  229. r = FLD_MOD(r, fmt->regmf, 17, 0);
  230. hdmi_write_reg(pll_base, PLLCTRL_CFG4, r);
  231. /* go now */
  232. REG_FLD_MOD(pll_base, PLLCTRL_PLL_GO, 0x1, 0, 0);
  233. /* wait for bit change */
  234. if (hdmi_wait_for_bit_change(pll_base, PLLCTRL_PLL_GO,
  235. 0, 0, 1) != 1) {
  236. DSSERR("PLL GO bit not set\n");
  237. return -ETIMEDOUT;
  238. }
  239. /* Wait till the lock bit is set in PLL status */
  240. if (hdmi_wait_for_bit_change(pll_base,
  241. PLLCTRL_PLL_STATUS, 1, 1, 1) != 1) {
  242. DSSWARN("cannot lock PLL\n");
  243. DSSWARN("CFG1 0x%x\n",
  244. hdmi_read_reg(pll_base, PLLCTRL_CFG1));
  245. DSSWARN("CFG2 0x%x\n",
  246. hdmi_read_reg(pll_base, PLLCTRL_CFG2));
  247. DSSWARN("CFG4 0x%x\n",
  248. hdmi_read_reg(pll_base, PLLCTRL_CFG4));
  249. return -ETIMEDOUT;
  250. }
  251. DSSDBG("PLL locked!\n");
  252. return 0;
  253. }
  254. /* PHY_PWR_CMD */
  255. static int hdmi_set_phy_pwr(struct hdmi_ip_data *ip_data, enum hdmi_phy_pwr val)
  256. {
  257. /* Command for power control of HDMI PHY */
  258. REG_FLD_MOD(hdmi_wp_base(ip_data), HDMI_WP_PWR_CTRL, val, 7, 6);
  259. /* Status of the power control of HDMI PHY */
  260. if (hdmi_wait_for_bit_change(hdmi_wp_base(ip_data),
  261. HDMI_WP_PWR_CTRL, 5, 4, val) != val) {
  262. DSSERR("Failed to set PHY power mode to %d\n", val);
  263. return -ETIMEDOUT;
  264. }
  265. return 0;
  266. }
  267. /* PLL_PWR_CMD */
  268. int hdmi_set_pll_pwr(struct hdmi_ip_data *ip_data, enum hdmi_pll_pwr val)
  269. {
  270. /* Command for power control of HDMI PLL */
  271. REG_FLD_MOD(hdmi_wp_base(ip_data), HDMI_WP_PWR_CTRL, val, 3, 2);
  272. /* wait till PHY_PWR_STATUS is set */
  273. if (hdmi_wait_for_bit_change(hdmi_wp_base(ip_data), HDMI_WP_PWR_CTRL,
  274. 1, 0, val) != val) {
  275. DSSERR("Failed to set PHY_PWR_STATUS\n");
  276. return -ETIMEDOUT;
  277. }
  278. return 0;
  279. }
  280. static int hdmi_pll_reset(struct hdmi_ip_data *ip_data)
  281. {
  282. /* SYSRESET controlled by power FSM */
  283. REG_FLD_MOD(hdmi_pll_base(ip_data), PLLCTRL_PLL_CONTROL, 0x0, 3, 3);
  284. /* READ 0x0 reset is in progress */
  285. if (hdmi_wait_for_bit_change(hdmi_pll_base(ip_data),
  286. PLLCTRL_PLL_STATUS, 0, 0, 1) != 1) {
  287. DSSERR("Failed to sysreset PLL\n");
  288. return -ETIMEDOUT;
  289. }
  290. return 0;
  291. }
  292. static int hdmi_phy_init(struct hdmi_ip_data *ip_data)
  293. {
  294. u16 r = 0;
  295. void __iomem *phy_base = hdmi_phy_base(ip_data);
  296. r = hdmi_set_phy_pwr(ip_data, HDMI_PHYPWRCMD_LDOON);
  297. if (r)
  298. return r;
  299. r = hdmi_set_phy_pwr(ip_data, HDMI_PHYPWRCMD_TXON);
  300. if (r)
  301. return r;
  302. /*
  303. * Read address 0 in order to get the SCP reset done completed
  304. * Dummy access performed to make sure reset is done
  305. */
  306. hdmi_read_reg(phy_base, HDMI_TXPHY_TX_CTRL);
  307. /*
  308. * Write to phy address 0 to configure the clock
  309. * use HFBITCLK write HDMI_TXPHY_TX_CONTROL_FREQOUT field
  310. */
  311. REG_FLD_MOD(phy_base, HDMI_TXPHY_TX_CTRL, 0x1, 31, 30);
  312. /* Write to phy address 1 to start HDMI line (TXVALID and TMDSCLKEN) */
  313. hdmi_write_reg(phy_base, HDMI_TXPHY_DIGITAL_CTRL, 0xF0000000);
  314. /* Setup max LDO voltage */
  315. REG_FLD_MOD(phy_base, HDMI_TXPHY_POWER_CTRL, 0xB, 3, 0);
  316. /* Write to phy address 3 to change the polarity control */
  317. REG_FLD_MOD(phy_base, HDMI_TXPHY_PAD_CFG_CTRL, 0x1, 27, 27);
  318. return 0;
  319. }
  320. static int hdmi_pll_program(struct hdmi_ip_data *ip_data)
  321. {
  322. u16 r = 0;
  323. r = hdmi_set_pll_pwr(ip_data, HDMI_PLLPWRCMD_ALLOFF);
  324. if (r)
  325. return r;
  326. r = hdmi_set_pll_pwr(ip_data, HDMI_PLLPWRCMD_BOTHON_ALLCLKS);
  327. if (r)
  328. return r;
  329. r = hdmi_pll_reset(ip_data);
  330. if (r)
  331. return r;
  332. r = hdmi_pll_init(ip_data);
  333. if (r)
  334. return r;
  335. return 0;
  336. }
  337. static void hdmi_phy_off(struct hdmi_ip_data *ip_data)
  338. {
  339. hdmi_set_phy_pwr(ip_data, HDMI_PHYPWRCMD_OFF);
  340. }
  341. static int hdmi_core_ddc_edid(struct hdmi_ip_data *ip_data,
  342. u8 *pedid, int ext)
  343. {
  344. u32 i, j;
  345. char checksum = 0;
  346. u32 offset = 0;
  347. void __iomem *core_sys_base = hdmi_core_sys_base(ip_data);
  348. /* Turn on CLK for DDC */
  349. REG_FLD_MOD(hdmi_av_base(ip_data), HDMI_CORE_AV_DPD, 0x7, 2, 0);
  350. /*
  351. * SW HACK : Without the Delay DDC(i2c bus) reads 0 values /
  352. * right shifted values( The behavior is not consistent and seen only
  353. * with some TV's)
  354. */
  355. usleep_range(800, 1000);
  356. if (!ext) {
  357. /* Clk SCL Devices */
  358. REG_FLD_MOD(core_sys_base, HDMI_CORE_DDC_CMD, 0xA, 3, 0);
  359. /* HDMI_CORE_DDC_STATUS_IN_PROG */
  360. if (hdmi_wait_for_bit_change(core_sys_base,
  361. HDMI_CORE_DDC_STATUS, 4, 4, 0) != 0) {
  362. DSSERR("Failed to program DDC\n");
  363. return -ETIMEDOUT;
  364. }
  365. /* Clear FIFO */
  366. REG_FLD_MOD(core_sys_base, HDMI_CORE_DDC_CMD, 0x9, 3, 0);
  367. /* HDMI_CORE_DDC_STATUS_IN_PROG */
  368. if (hdmi_wait_for_bit_change(core_sys_base,
  369. HDMI_CORE_DDC_STATUS, 4, 4, 0) != 0) {
  370. DSSERR("Failed to program DDC\n");
  371. return -ETIMEDOUT;
  372. }
  373. } else {
  374. if (ext % 2 != 0)
  375. offset = 0x80;
  376. }
  377. /* Load Segment Address Register */
  378. REG_FLD_MOD(core_sys_base, HDMI_CORE_DDC_SEGM, ext/2, 7, 0);
  379. /* Load Slave Address Register */
  380. REG_FLD_MOD(core_sys_base, HDMI_CORE_DDC_ADDR, 0xA0 >> 1, 7, 1);
  381. /* Load Offset Address Register */
  382. REG_FLD_MOD(core_sys_base, HDMI_CORE_DDC_OFFSET, offset, 7, 0);
  383. /* Load Byte Count */
  384. REG_FLD_MOD(core_sys_base, HDMI_CORE_DDC_COUNT1, 0x80, 7, 0);
  385. REG_FLD_MOD(core_sys_base, HDMI_CORE_DDC_COUNT2, 0x0, 1, 0);
  386. /* Set DDC_CMD */
  387. if (ext)
  388. REG_FLD_MOD(core_sys_base, HDMI_CORE_DDC_CMD, 0x4, 3, 0);
  389. else
  390. REG_FLD_MOD(core_sys_base, HDMI_CORE_DDC_CMD, 0x2, 3, 0);
  391. /* HDMI_CORE_DDC_STATUS_BUS_LOW */
  392. if (REG_GET(core_sys_base, HDMI_CORE_DDC_STATUS, 6, 6) == 1) {
  393. DSSWARN("I2C Bus Low?\n");
  394. return -EIO;
  395. }
  396. /* HDMI_CORE_DDC_STATUS_NO_ACK */
  397. if (REG_GET(core_sys_base, HDMI_CORE_DDC_STATUS, 5, 5) == 1) {
  398. DSSWARN("I2C No Ack\n");
  399. return -EIO;
  400. }
  401. i = ext * 128;
  402. j = 0;
  403. while (((REG_GET(core_sys_base, HDMI_CORE_DDC_STATUS, 4, 4) == 1) ||
  404. (REG_GET(core_sys_base,
  405. HDMI_CORE_DDC_STATUS, 2, 2) == 0)) && j < 128) {
  406. if (REG_GET(core_sys_base, HDMI_CORE_DDC_STATUS, 2, 2) == 0) {
  407. /* FIFO not empty */
  408. pedid[i++] = REG_GET(core_sys_base,
  409. HDMI_CORE_DDC_DATA, 7, 0);
  410. j++;
  411. }
  412. }
  413. for (j = 0; j < 128; j++)
  414. checksum += pedid[j];
  415. if (checksum != 0) {
  416. DSSERR("E-EDID checksum failed!!\n");
  417. return -EIO;
  418. }
  419. return 0;
  420. }
  421. static int read_edid(struct hdmi_ip_data *ip_data, u8 *pedid, u16 max_length)
  422. {
  423. int r = 0, n = 0, i = 0;
  424. int max_ext_blocks = (max_length / 128) - 1;
  425. r = hdmi_core_ddc_edid(ip_data, pedid, 0);
  426. if (r) {
  427. return r;
  428. } else {
  429. n = pedid[0x7e];
  430. /*
  431. * README: need to comply with max_length set by the caller.
  432. * Better implementation should be to allocate necessary
  433. * memory to store EDID according to nb_block field found
  434. * in first block
  435. */
  436. if (n > max_ext_blocks)
  437. n = max_ext_blocks;
  438. for (i = 1; i <= n; i++) {
  439. r = hdmi_core_ddc_edid(ip_data, pedid, i);
  440. if (r)
  441. return r;
  442. }
  443. }
  444. return 0;
  445. }
  446. static void copy_hdmi_to_dss_timings(
  447. const struct hdmi_video_timings *hdmi_timings,
  448. struct omap_video_timings *timings)
  449. {
  450. timings->x_res = hdmi_timings->x_res;
  451. timings->y_res = hdmi_timings->y_res;
  452. timings->pixel_clock = hdmi_timings->pixel_clock;
  453. timings->hbp = hdmi_timings->hbp;
  454. timings->hfp = hdmi_timings->hfp;
  455. timings->hsw = hdmi_timings->hsw;
  456. timings->vbp = hdmi_timings->vbp;
  457. timings->vfp = hdmi_timings->vfp;
  458. timings->vsw = hdmi_timings->vsw;
  459. }
  460. static int get_timings_index(void)
  461. {
  462. int code;
  463. if (hdmi.mode == 0)
  464. code = code_vesa[hdmi.code];
  465. else
  466. code = code_cea[hdmi.code];
  467. if (code == -1) {
  468. /* HDMI code 4 corresponds to 640 * 480 VGA */
  469. hdmi.code = 4;
  470. /* DVI mode 1 corresponds to HDMI 0 to DVI */
  471. hdmi.mode = HDMI_DVI;
  472. code = code_vesa[hdmi.code];
  473. }
  474. return code;
  475. }
  476. static struct hdmi_cm hdmi_get_code(struct omap_video_timings *timing)
  477. {
  478. int i = 0, code = -1, temp_vsync = 0, temp_hsync = 0;
  479. int timing_vsync = 0, timing_hsync = 0;
  480. struct hdmi_video_timings temp;
  481. struct hdmi_cm cm = {-1};
  482. DSSDBG("hdmi_get_code\n");
  483. for (i = 0; i < OMAP_HDMI_TIMINGS_NB; i++) {
  484. temp = cea_vesa_timings[i].timings;
  485. if ((temp.pixel_clock == timing->pixel_clock) &&
  486. (temp.x_res == timing->x_res) &&
  487. (temp.y_res == timing->y_res)) {
  488. temp_hsync = temp.hfp + temp.hsw + temp.hbp;
  489. timing_hsync = timing->hfp + timing->hsw + timing->hbp;
  490. temp_vsync = temp.vfp + temp.vsw + temp.vbp;
  491. timing_vsync = timing->vfp + timing->vsw + timing->vbp;
  492. DSSDBG("temp_hsync = %d , temp_vsync = %d"
  493. "timing_hsync = %d, timing_vsync = %d\n",
  494. temp_hsync, temp_hsync,
  495. timing_hsync, timing_vsync);
  496. if ((temp_hsync == timing_hsync) &&
  497. (temp_vsync == timing_vsync)) {
  498. code = i;
  499. cm.code = code_index[i];
  500. if (code < 14)
  501. cm.mode = HDMI_HDMI;
  502. else
  503. cm.mode = HDMI_DVI;
  504. DSSDBG("Hdmi_code = %d mode = %d\n",
  505. cm.code, cm.mode);
  506. break;
  507. }
  508. }
  509. }
  510. return cm;
  511. }
  512. static void get_horz_vert_timing_info(int current_descriptor_addrs, u8 *edid ,
  513. struct omap_video_timings *timings)
  514. {
  515. /* X and Y resolution */
  516. timings->x_res = (((edid[current_descriptor_addrs + 4] & 0xF0) << 4) |
  517. edid[current_descriptor_addrs + 2]);
  518. timings->y_res = (((edid[current_descriptor_addrs + 7] & 0xF0) << 4) |
  519. edid[current_descriptor_addrs + 5]);
  520. timings->pixel_clock = ((edid[current_descriptor_addrs + 1] << 8) |
  521. edid[current_descriptor_addrs]);
  522. timings->pixel_clock = 10 * timings->pixel_clock;
  523. /* HORIZONTAL FRONT PORCH */
  524. timings->hfp = edid[current_descriptor_addrs + 8] |
  525. ((edid[current_descriptor_addrs + 11] & 0xc0) << 2);
  526. /* HORIZONTAL SYNC WIDTH */
  527. timings->hsw = edid[current_descriptor_addrs + 9] |
  528. ((edid[current_descriptor_addrs + 11] & 0x30) << 4);
  529. /* HORIZONTAL BACK PORCH */
  530. timings->hbp = (((edid[current_descriptor_addrs + 4] & 0x0F) << 8) |
  531. edid[current_descriptor_addrs + 3]) -
  532. (timings->hfp + timings->hsw);
  533. /* VERTICAL FRONT PORCH */
  534. timings->vfp = ((edid[current_descriptor_addrs + 10] & 0xF0) >> 4) |
  535. ((edid[current_descriptor_addrs + 11] & 0x0f) << 2);
  536. /* VERTICAL SYNC WIDTH */
  537. timings->vsw = (edid[current_descriptor_addrs + 10] & 0x0F) |
  538. ((edid[current_descriptor_addrs + 11] & 0x03) << 4);
  539. /* VERTICAL BACK PORCH */
  540. timings->vbp = (((edid[current_descriptor_addrs + 7] & 0x0F) << 8) |
  541. edid[current_descriptor_addrs + 6]) -
  542. (timings->vfp + timings->vsw);
  543. }
  544. /* Description : This function gets the resolution information from EDID */
  545. static void get_edid_timing_data(u8 *edid)
  546. {
  547. u8 count;
  548. u16 current_descriptor_addrs;
  549. struct hdmi_cm cm;
  550. struct omap_video_timings edid_timings;
  551. /* search block 0, there are 4 DTDs arranged in priority order */
  552. for (count = 0; count < EDID_SIZE_BLOCK0_TIMING_DESCRIPTOR; count++) {
  553. current_descriptor_addrs =
  554. EDID_DESCRIPTOR_BLOCK0_ADDRESS +
  555. count * EDID_TIMING_DESCRIPTOR_SIZE;
  556. get_horz_vert_timing_info(current_descriptor_addrs,
  557. edid, &edid_timings);
  558. cm = hdmi_get_code(&edid_timings);
  559. DSSDBG("Block0[%d] value matches code = %d , mode = %d\n",
  560. count, cm.code, cm.mode);
  561. if (cm.code == -1) {
  562. continue;
  563. } else {
  564. hdmi.code = cm.code;
  565. hdmi.mode = cm.mode;
  566. DSSDBG("code = %d , mode = %d\n",
  567. hdmi.code, hdmi.mode);
  568. return;
  569. }
  570. }
  571. if (edid[0x7e] != 0x00) {
  572. for (count = 0; count < EDID_SIZE_BLOCK1_TIMING_DESCRIPTOR;
  573. count++) {
  574. current_descriptor_addrs =
  575. EDID_DESCRIPTOR_BLOCK1_ADDRESS +
  576. count * EDID_TIMING_DESCRIPTOR_SIZE;
  577. get_horz_vert_timing_info(current_descriptor_addrs,
  578. edid, &edid_timings);
  579. cm = hdmi_get_code(&edid_timings);
  580. DSSDBG("Block1[%d] value matches code = %d, mode = %d",
  581. count, cm.code, cm.mode);
  582. if (cm.code == -1) {
  583. continue;
  584. } else {
  585. hdmi.code = cm.code;
  586. hdmi.mode = cm.mode;
  587. DSSDBG("code = %d , mode = %d\n",
  588. hdmi.code, hdmi.mode);
  589. return;
  590. }
  591. }
  592. }
  593. DSSINFO("no valid timing found , falling back to VGA\n");
  594. hdmi.code = 4; /* setting default value of 640 480 VGA */
  595. hdmi.mode = HDMI_DVI;
  596. }
  597. static void hdmi_read_edid(struct omap_video_timings *dp)
  598. {
  599. int ret = 0, code;
  600. memset(hdmi.edid, 0, HDMI_EDID_MAX_LENGTH);
  601. if (!hdmi.edid_set)
  602. ret = read_edid(&hdmi.ip_data, hdmi.edid,
  603. HDMI_EDID_MAX_LENGTH);
  604. if (!ret) {
  605. if (!memcmp(hdmi.edid, edid_header, sizeof(edid_header))) {
  606. /* search for timings of default resolution */
  607. get_edid_timing_data(hdmi.edid);
  608. hdmi.edid_set = true;
  609. }
  610. } else {
  611. DSSWARN("failed to read E-EDID\n");
  612. }
  613. if (!hdmi.edid_set) {
  614. DSSINFO("fallback to VGA\n");
  615. hdmi.code = 4; /* setting default value of 640 480 VGA */
  616. hdmi.mode = HDMI_DVI;
  617. }
  618. code = get_timings_index();
  619. copy_hdmi_to_dss_timings(&cea_vesa_timings[code].timings, dp);
  620. }
  621. static void hdmi_core_init(struct hdmi_core_video_config *video_cfg,
  622. struct hdmi_core_infoframe_avi *avi_cfg,
  623. struct hdmi_core_packet_enable_repeat *repeat_cfg)
  624. {
  625. DSSDBG("Enter hdmi_core_init\n");
  626. /* video core */
  627. video_cfg->ip_bus_width = HDMI_INPUT_8BIT;
  628. video_cfg->op_dither_truc = HDMI_OUTPUTTRUNCATION_8BIT;
  629. video_cfg->deep_color_pkt = HDMI_DEEPCOLORPACKECTDISABLE;
  630. video_cfg->pkt_mode = HDMI_PACKETMODERESERVEDVALUE;
  631. video_cfg->hdmi_dvi = HDMI_DVI;
  632. video_cfg->tclk_sel_clkmult = HDMI_FPLL10IDCK;
  633. /* info frame */
  634. avi_cfg->db1_format = 0;
  635. avi_cfg->db1_active_info = 0;
  636. avi_cfg->db1_bar_info_dv = 0;
  637. avi_cfg->db1_scan_info = 0;
  638. avi_cfg->db2_colorimetry = 0;
  639. avi_cfg->db2_aspect_ratio = 0;
  640. avi_cfg->db2_active_fmt_ar = 0;
  641. avi_cfg->db3_itc = 0;
  642. avi_cfg->db3_ec = 0;
  643. avi_cfg->db3_q_range = 0;
  644. avi_cfg->db3_nup_scaling = 0;
  645. avi_cfg->db4_videocode = 0;
  646. avi_cfg->db5_pixel_repeat = 0;
  647. avi_cfg->db6_7_line_eoftop = 0 ;
  648. avi_cfg->db8_9_line_sofbottom = 0;
  649. avi_cfg->db10_11_pixel_eofleft = 0;
  650. avi_cfg->db12_13_pixel_sofright = 0;
  651. /* packet enable and repeat */
  652. repeat_cfg->audio_pkt = 0;
  653. repeat_cfg->audio_pkt_repeat = 0;
  654. repeat_cfg->avi_infoframe = 0;
  655. repeat_cfg->avi_infoframe_repeat = 0;
  656. repeat_cfg->gen_cntrl_pkt = 0;
  657. repeat_cfg->gen_cntrl_pkt_repeat = 0;
  658. repeat_cfg->generic_pkt = 0;
  659. repeat_cfg->generic_pkt_repeat = 0;
  660. }
  661. static void hdmi_core_powerdown_disable(struct hdmi_ip_data *ip_data)
  662. {
  663. DSSDBG("Enter hdmi_core_powerdown_disable\n");
  664. REG_FLD_MOD(hdmi_core_sys_base(ip_data), HDMI_CORE_CTRL1, 0x0, 0, 0);
  665. }
  666. static void hdmi_core_swreset_release(struct hdmi_ip_data *ip_data)
  667. {
  668. DSSDBG("Enter hdmi_core_swreset_release\n");
  669. REG_FLD_MOD(hdmi_core_sys_base(ip_data), HDMI_CORE_SYS_SRST, 0x0, 0, 0);
  670. }
  671. static void hdmi_core_swreset_assert(struct hdmi_ip_data *ip_data)
  672. {
  673. DSSDBG("Enter hdmi_core_swreset_assert\n");
  674. REG_FLD_MOD(hdmi_core_sys_base(ip_data), HDMI_CORE_SYS_SRST, 0x1, 0, 0);
  675. }
  676. /* HDMI_CORE_VIDEO_CONFIG */
  677. static void hdmi_core_video_config(struct hdmi_ip_data *ip_data,
  678. struct hdmi_core_video_config *cfg)
  679. {
  680. u32 r = 0;
  681. void __iomem *core_sys_base = hdmi_core_sys_base(ip_data);
  682. /* sys_ctrl1 default configuration not tunable */
  683. r = hdmi_read_reg(core_sys_base, HDMI_CORE_CTRL1);
  684. r = FLD_MOD(r, HDMI_CORE_CTRL1_VEN_FOLLOWVSYNC, 5, 5);
  685. r = FLD_MOD(r, HDMI_CORE_CTRL1_HEN_FOLLOWHSYNC, 4, 4);
  686. r = FLD_MOD(r, HDMI_CORE_CTRL1_BSEL_24BITBUS, 2, 2);
  687. r = FLD_MOD(r, HDMI_CORE_CTRL1_EDGE_RISINGEDGE, 1, 1);
  688. hdmi_write_reg(core_sys_base, HDMI_CORE_CTRL1, r);
  689. REG_FLD_MOD(core_sys_base,
  690. HDMI_CORE_SYS_VID_ACEN, cfg->ip_bus_width, 7, 6);
  691. /* Vid_Mode */
  692. r = hdmi_read_reg(core_sys_base, HDMI_CORE_SYS_VID_MODE);
  693. /* dither truncation configuration */
  694. if (cfg->op_dither_truc > HDMI_OUTPUTTRUNCATION_12BIT) {
  695. r = FLD_MOD(r, cfg->op_dither_truc - 3, 7, 6);
  696. r = FLD_MOD(r, 1, 5, 5);
  697. } else {
  698. r = FLD_MOD(r, cfg->op_dither_truc, 7, 6);
  699. r = FLD_MOD(r, 0, 5, 5);
  700. }
  701. hdmi_write_reg(core_sys_base, HDMI_CORE_SYS_VID_MODE, r);
  702. /* HDMI_Ctrl */
  703. r = hdmi_read_reg(hdmi_av_base(ip_data), HDMI_CORE_AV_HDMI_CTRL);
  704. r = FLD_MOD(r, cfg->deep_color_pkt, 6, 6);
  705. r = FLD_MOD(r, cfg->pkt_mode, 5, 3);
  706. r = FLD_MOD(r, cfg->hdmi_dvi, 0, 0);
  707. hdmi_write_reg(hdmi_av_base(ip_data), HDMI_CORE_AV_HDMI_CTRL, r);
  708. /* TMDS_CTRL */
  709. REG_FLD_MOD(core_sys_base,
  710. HDMI_CORE_SYS_TMDS_CTRL, cfg->tclk_sel_clkmult, 6, 5);
  711. }
  712. static void hdmi_core_aux_infoframe_avi_config(struct hdmi_ip_data *ip_data,
  713. struct hdmi_core_infoframe_avi info_avi)
  714. {
  715. u32 val;
  716. char sum = 0, checksum = 0;
  717. void __iomem *av_base = hdmi_av_base(ip_data);
  718. sum += 0x82 + 0x002 + 0x00D;
  719. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_TYPE, 0x082);
  720. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_VERS, 0x002);
  721. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_LEN, 0x00D);
  722. val = (info_avi.db1_format << 5) |
  723. (info_avi.db1_active_info << 4) |
  724. (info_avi.db1_bar_info_dv << 2) |
  725. (info_avi.db1_scan_info);
  726. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(0), val);
  727. sum += val;
  728. val = (info_avi.db2_colorimetry << 6) |
  729. (info_avi.db2_aspect_ratio << 4) |
  730. (info_avi.db2_active_fmt_ar);
  731. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(1), val);
  732. sum += val;
  733. val = (info_avi.db3_itc << 7) |
  734. (info_avi.db3_ec << 4) |
  735. (info_avi.db3_q_range << 2) |
  736. (info_avi.db3_nup_scaling);
  737. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(2), val);
  738. sum += val;
  739. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(3),
  740. info_avi.db4_videocode);
  741. sum += info_avi.db4_videocode;
  742. val = info_avi.db5_pixel_repeat;
  743. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(4), val);
  744. sum += val;
  745. val = info_avi.db6_7_line_eoftop & 0x00FF;
  746. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(5), val);
  747. sum += val;
  748. val = ((info_avi.db6_7_line_eoftop >> 8) & 0x00FF);
  749. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(6), val);
  750. sum += val;
  751. val = info_avi.db8_9_line_sofbottom & 0x00FF;
  752. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(7), val);
  753. sum += val;
  754. val = ((info_avi.db8_9_line_sofbottom >> 8) & 0x00FF);
  755. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(8), val);
  756. sum += val;
  757. val = info_avi.db10_11_pixel_eofleft & 0x00FF;
  758. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(9), val);
  759. sum += val;
  760. val = ((info_avi.db10_11_pixel_eofleft >> 8) & 0x00FF);
  761. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(10), val);
  762. sum += val;
  763. val = info_avi.db12_13_pixel_sofright & 0x00FF;
  764. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(11), val);
  765. sum += val;
  766. val = ((info_avi.db12_13_pixel_sofright >> 8) & 0x00FF);
  767. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(12), val);
  768. sum += val;
  769. checksum = 0x100 - sum;
  770. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_CHSUM, checksum);
  771. }
  772. static void hdmi_core_av_packet_config(struct hdmi_ip_data *ip_data,
  773. struct hdmi_core_packet_enable_repeat repeat_cfg)
  774. {
  775. /* enable/repeat the infoframe */
  776. hdmi_write_reg(hdmi_av_base(ip_data), HDMI_CORE_AV_PB_CTRL1,
  777. (repeat_cfg.audio_pkt << 5) |
  778. (repeat_cfg.audio_pkt_repeat << 4) |
  779. (repeat_cfg.avi_infoframe << 1) |
  780. (repeat_cfg.avi_infoframe_repeat));
  781. /* enable/repeat the packet */
  782. hdmi_write_reg(hdmi_av_base(ip_data), HDMI_CORE_AV_PB_CTRL2,
  783. (repeat_cfg.gen_cntrl_pkt << 3) |
  784. (repeat_cfg.gen_cntrl_pkt_repeat << 2) |
  785. (repeat_cfg.generic_pkt << 1) |
  786. (repeat_cfg.generic_pkt_repeat));
  787. }
  788. static void hdmi_wp_init(struct omap_video_timings *timings,
  789. struct hdmi_video_format *video_fmt,
  790. struct hdmi_video_interface *video_int)
  791. {
  792. DSSDBG("Enter hdmi_wp_init\n");
  793. timings->hbp = 0;
  794. timings->hfp = 0;
  795. timings->hsw = 0;
  796. timings->vbp = 0;
  797. timings->vfp = 0;
  798. timings->vsw = 0;
  799. video_fmt->packing_mode = HDMI_PACK_10b_RGB_YUV444;
  800. video_fmt->y_res = 0;
  801. video_fmt->x_res = 0;
  802. video_int->vsp = 0;
  803. video_int->hsp = 0;
  804. video_int->interlacing = 0;
  805. video_int->tm = 0; /* HDMI_TIMING_SLAVE */
  806. }
  807. static void hdmi_wp_video_start(struct hdmi_ip_data *ip_data, bool start)
  808. {
  809. REG_FLD_MOD(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_CFG, start, 31, 31);
  810. }
  811. static void hdmi_wp_video_init_format(struct hdmi_video_format *video_fmt,
  812. struct omap_video_timings *timings, struct hdmi_config *param)
  813. {
  814. DSSDBG("Enter hdmi_wp_video_init_format\n");
  815. video_fmt->y_res = param->timings.timings.y_res;
  816. video_fmt->x_res = param->timings.timings.x_res;
  817. timings->hbp = param->timings.timings.hbp;
  818. timings->hfp = param->timings.timings.hfp;
  819. timings->hsw = param->timings.timings.hsw;
  820. timings->vbp = param->timings.timings.vbp;
  821. timings->vfp = param->timings.timings.vfp;
  822. timings->vsw = param->timings.timings.vsw;
  823. }
  824. static void hdmi_wp_video_config_format(struct hdmi_ip_data *ip_data,
  825. struct hdmi_video_format *video_fmt)
  826. {
  827. u32 l = 0;
  828. REG_FLD_MOD(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_CFG,
  829. video_fmt->packing_mode, 10, 8);
  830. l |= FLD_VAL(video_fmt->y_res, 31, 16);
  831. l |= FLD_VAL(video_fmt->x_res, 15, 0);
  832. hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_SIZE, l);
  833. }
  834. static void hdmi_wp_video_config_interface(struct hdmi_ip_data *ip_data,
  835. struct hdmi_video_interface *video_int)
  836. {
  837. u32 r;
  838. DSSDBG("Enter hdmi_wp_video_config_interface\n");
  839. r = hdmi_read_reg(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_CFG);
  840. r = FLD_MOD(r, video_int->vsp, 7, 7);
  841. r = FLD_MOD(r, video_int->hsp, 6, 6);
  842. r = FLD_MOD(r, video_int->interlacing, 3, 3);
  843. r = FLD_MOD(r, video_int->tm, 1, 0);
  844. hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_CFG, r);
  845. }
  846. static void hdmi_wp_video_config_timing(struct hdmi_ip_data *ip_data,
  847. struct omap_video_timings *timings)
  848. {
  849. u32 timing_h = 0;
  850. u32 timing_v = 0;
  851. DSSDBG("Enter hdmi_wp_video_config_timing\n");
  852. timing_h |= FLD_VAL(timings->hbp, 31, 20);
  853. timing_h |= FLD_VAL(timings->hfp, 19, 8);
  854. timing_h |= FLD_VAL(timings->hsw, 7, 0);
  855. hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_TIMING_H, timing_h);
  856. timing_v |= FLD_VAL(timings->vbp, 31, 20);
  857. timing_v |= FLD_VAL(timings->vfp, 19, 8);
  858. timing_v |= FLD_VAL(timings->vsw, 7, 0);
  859. hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_TIMING_V, timing_v);
  860. }
  861. static void hdmi_basic_configure(struct hdmi_ip_data *ip_data)
  862. {
  863. /* HDMI */
  864. struct omap_video_timings video_timing;
  865. struct hdmi_video_format video_format;
  866. struct hdmi_video_interface video_interface;
  867. /* HDMI core */
  868. struct hdmi_core_infoframe_avi avi_cfg;
  869. struct hdmi_core_video_config v_core_cfg;
  870. struct hdmi_core_packet_enable_repeat repeat_cfg;
  871. struct hdmi_config *cfg = &ip_data->cfg;
  872. hdmi_wp_init(&video_timing, &video_format,
  873. &video_interface);
  874. hdmi_core_init(&v_core_cfg,
  875. &avi_cfg,
  876. &repeat_cfg);
  877. hdmi_wp_video_init_format(&video_format, &video_timing, cfg);
  878. hdmi_wp_video_config_timing(ip_data, &video_timing);
  879. /* video config */
  880. video_format.packing_mode = HDMI_PACK_24b_RGB_YUV444_YUV422;
  881. hdmi_wp_video_config_format(ip_data, &video_format);
  882. video_interface.vsp = cfg->timings.vsync_pol;
  883. video_interface.hsp = cfg->timings.hsync_pol;
  884. video_interface.interlacing = cfg->interlace;
  885. video_interface.tm = 1 ; /* HDMI_TIMING_MASTER_24BIT */
  886. hdmi_wp_video_config_interface(ip_data, &video_interface);
  887. /*
  888. * configure core video part
  889. * set software reset in the core
  890. */
  891. hdmi_core_swreset_assert(ip_data);
  892. /* power down off */
  893. hdmi_core_powerdown_disable(ip_data);
  894. v_core_cfg.pkt_mode = HDMI_PACKETMODE24BITPERPIXEL;
  895. v_core_cfg.hdmi_dvi = cfg->cm.mode;
  896. hdmi_core_video_config(ip_data, &v_core_cfg);
  897. /* release software reset in the core */
  898. hdmi_core_swreset_release(ip_data);
  899. /*
  900. * configure packet
  901. * info frame video see doc CEA861-D page 65
  902. */
  903. avi_cfg.db1_format = HDMI_INFOFRAME_AVI_DB1Y_RGB;
  904. avi_cfg.db1_active_info =
  905. HDMI_INFOFRAME_AVI_DB1A_ACTIVE_FORMAT_OFF;
  906. avi_cfg.db1_bar_info_dv = HDMI_INFOFRAME_AVI_DB1B_NO;
  907. avi_cfg.db1_scan_info = HDMI_INFOFRAME_AVI_DB1S_0;
  908. avi_cfg.db2_colorimetry = HDMI_INFOFRAME_AVI_DB2C_NO;
  909. avi_cfg.db2_aspect_ratio = HDMI_INFOFRAME_AVI_DB2M_NO;
  910. avi_cfg.db2_active_fmt_ar = HDMI_INFOFRAME_AVI_DB2R_SAME;
  911. avi_cfg.db3_itc = HDMI_INFOFRAME_AVI_DB3ITC_NO;
  912. avi_cfg.db3_ec = HDMI_INFOFRAME_AVI_DB3EC_XVYUV601;
  913. avi_cfg.db3_q_range = HDMI_INFOFRAME_AVI_DB3Q_DEFAULT;
  914. avi_cfg.db3_nup_scaling = HDMI_INFOFRAME_AVI_DB3SC_NO;
  915. avi_cfg.db4_videocode = cfg->cm.code;
  916. avi_cfg.db5_pixel_repeat = HDMI_INFOFRAME_AVI_DB5PR_NO;
  917. avi_cfg.db6_7_line_eoftop = 0;
  918. avi_cfg.db8_9_line_sofbottom = 0;
  919. avi_cfg.db10_11_pixel_eofleft = 0;
  920. avi_cfg.db12_13_pixel_sofright = 0;
  921. hdmi_core_aux_infoframe_avi_config(ip_data, avi_cfg);
  922. /* enable/repeat the infoframe */
  923. repeat_cfg.avi_infoframe = HDMI_PACKETENABLE;
  924. repeat_cfg.avi_infoframe_repeat = HDMI_PACKETREPEATON;
  925. /* wakeup */
  926. repeat_cfg.audio_pkt = HDMI_PACKETENABLE;
  927. repeat_cfg.audio_pkt_repeat = HDMI_PACKETREPEATON;
  928. hdmi_core_av_packet_config(ip_data, repeat_cfg);
  929. }
  930. static void update_hdmi_timings(struct hdmi_config *cfg,
  931. struct omap_video_timings *timings, int code)
  932. {
  933. cfg->timings.timings.x_res = timings->x_res;
  934. cfg->timings.timings.y_res = timings->y_res;
  935. cfg->timings.timings.hbp = timings->hbp;
  936. cfg->timings.timings.hfp = timings->hfp;
  937. cfg->timings.timings.hsw = timings->hsw;
  938. cfg->timings.timings.vbp = timings->vbp;
  939. cfg->timings.timings.vfp = timings->vfp;
  940. cfg->timings.timings.vsw = timings->vsw;
  941. cfg->timings.timings.pixel_clock = timings->pixel_clock;
  942. cfg->timings.vsync_pol = cea_vesa_timings[code].vsync_pol;
  943. cfg->timings.hsync_pol = cea_vesa_timings[code].hsync_pol;
  944. }
  945. static void hdmi_compute_pll(struct omap_dss_device *dssdev, int phy,
  946. struct hdmi_pll_info *pi)
  947. {
  948. unsigned long clkin, refclk;
  949. u32 mf;
  950. clkin = clk_get_rate(hdmi.sys_clk) / 10000;
  951. /*
  952. * Input clock is predivided by N + 1
  953. * out put of which is reference clk
  954. */
  955. pi->regn = dssdev->clocks.hdmi.regn;
  956. refclk = clkin / (pi->regn + 1);
  957. /*
  958. * multiplier is pixel_clk/ref_clk
  959. * Multiplying by 100 to avoid fractional part removal
  960. */
  961. pi->regm = (phy * 100 / (refclk)) / 100;
  962. pi->regm2 = dssdev->clocks.hdmi.regm2;
  963. /*
  964. * fractional multiplier is remainder of the difference between
  965. * multiplier and actual phy(required pixel clock thus should be
  966. * multiplied by 2^18(262144) divided by the reference clock
  967. */
  968. mf = (phy - pi->regm * refclk) * 262144;
  969. pi->regmf = mf / (refclk);
  970. /*
  971. * Dcofreq should be set to 1 if required pixel clock
  972. * is greater than 1000MHz
  973. */
  974. pi->dcofreq = phy > 1000 * 100;
  975. pi->regsd = ((pi->regm * clkin / 10) / ((pi->regn + 1) * 250) + 5) / 10;
  976. /* Set the reference clock to sysclk reference */
  977. pi->refsel = HDMI_REFSEL_SYSCLK;
  978. DSSDBG("M = %d Mf = %d\n", pi->regm, pi->regmf);
  979. DSSDBG("range = %d sd = %d\n", pi->dcofreq, pi->regsd);
  980. }
  981. static int hdmi_power_on(struct omap_dss_device *dssdev)
  982. {
  983. int r, code = 0;
  984. struct omap_video_timings *p;
  985. unsigned long phy;
  986. r = hdmi_runtime_get();
  987. if (r)
  988. return r;
  989. dispc_mgr_enable(OMAP_DSS_CHANNEL_DIGIT, 0);
  990. p = &dssdev->panel.timings;
  991. DSSDBG("hdmi_power_on x_res= %d y_res = %d\n",
  992. dssdev->panel.timings.x_res,
  993. dssdev->panel.timings.y_res);
  994. if (!hdmi.custom_set) {
  995. DSSDBG("Read EDID as no EDID is not set on poweron\n");
  996. hdmi_read_edid(p);
  997. }
  998. code = get_timings_index();
  999. copy_hdmi_to_dss_timings(&cea_vesa_timings[code].timings,
  1000. &dssdev->panel.timings);
  1001. update_hdmi_timings(&hdmi.ip_data.cfg, p, code);
  1002. phy = p->pixel_clock;
  1003. hdmi_compute_pll(dssdev, phy, &hdmi.ip_data.pll_data);
  1004. hdmi_wp_video_start(&hdmi.ip_data, 0);
  1005. /* config the PLL and PHY hdmi_set_pll_pwrfirst */
  1006. r = hdmi_pll_program(&hdmi.ip_data);
  1007. if (r) {
  1008. DSSDBG("Failed to lock PLL\n");
  1009. goto err;
  1010. }
  1011. r = hdmi_phy_init(&hdmi.ip_data);
  1012. if (r) {
  1013. DSSDBG("Failed to start PHY\n");
  1014. goto err;
  1015. }
  1016. hdmi.ip_data.cfg.cm.mode = hdmi.mode;
  1017. hdmi.ip_data.cfg.cm.code = hdmi.code;
  1018. hdmi_basic_configure(&hdmi.ip_data);
  1019. /* Make selection of HDMI in DSS */
  1020. dss_select_hdmi_venc_clk_source(DSS_HDMI_M_PCLK);
  1021. /* Select the dispc clock source as PRCM clock, to ensure that it is not
  1022. * DSI PLL source as the clock selected by DSI PLL might not be
  1023. * sufficient for the resolution selected / that can be changed
  1024. * dynamically by user. This can be moved to single location , say
  1025. * Boardfile.
  1026. */
  1027. dss_select_dispc_clk_source(dssdev->clocks.dispc.dispc_fclk_src);
  1028. /* bypass TV gamma table */
  1029. dispc_enable_gamma_table(0);
  1030. /* tv size */
  1031. dispc_set_digit_size(dssdev->panel.timings.x_res,
  1032. dssdev->panel.timings.y_res);
  1033. dispc_mgr_enable(OMAP_DSS_CHANNEL_DIGIT, 1);
  1034. hdmi_wp_video_start(&hdmi.ip_data, 1);
  1035. return 0;
  1036. err:
  1037. hdmi_runtime_put();
  1038. return -EIO;
  1039. }
  1040. static void hdmi_power_off(struct omap_dss_device *dssdev)
  1041. {
  1042. dispc_mgr_enable(OMAP_DSS_CHANNEL_DIGIT, 0);
  1043. hdmi_wp_video_start(&hdmi.ip_data, 0);
  1044. hdmi_phy_off(&hdmi.ip_data);
  1045. hdmi_set_pll_pwr(&hdmi.ip_data, HDMI_PLLPWRCMD_ALLOFF);
  1046. hdmi_runtime_put();
  1047. hdmi.edid_set = 0;
  1048. }
  1049. int omapdss_hdmi_display_check_timing(struct omap_dss_device *dssdev,
  1050. struct omap_video_timings *timings)
  1051. {
  1052. struct hdmi_cm cm;
  1053. cm = hdmi_get_code(timings);
  1054. if (cm.code == -1) {
  1055. DSSERR("Invalid timing entered\n");
  1056. return -EINVAL;
  1057. }
  1058. return 0;
  1059. }
  1060. void omapdss_hdmi_display_set_timing(struct omap_dss_device *dssdev)
  1061. {
  1062. struct hdmi_cm cm;
  1063. hdmi.custom_set = 1;
  1064. cm = hdmi_get_code(&dssdev->panel.timings);
  1065. hdmi.code = cm.code;
  1066. hdmi.mode = cm.mode;
  1067. omapdss_hdmi_display_enable(dssdev);
  1068. hdmi.custom_set = 0;
  1069. }
  1070. int omapdss_hdmi_display_enable(struct omap_dss_device *dssdev)
  1071. {
  1072. int r = 0;
  1073. DSSDBG("ENTER hdmi_display_enable\n");
  1074. mutex_lock(&hdmi.lock);
  1075. if (dssdev->manager == NULL) {
  1076. DSSERR("failed to enable display: no manager\n");
  1077. r = -ENODEV;
  1078. goto err0;
  1079. }
  1080. r = omap_dss_start_device(dssdev);
  1081. if (r) {
  1082. DSSERR("failed to start device\n");
  1083. goto err0;
  1084. }
  1085. if (dssdev->platform_enable) {
  1086. r = dssdev->platform_enable(dssdev);
  1087. if (r) {
  1088. DSSERR("failed to enable GPIO's\n");
  1089. goto err1;
  1090. }
  1091. }
  1092. r = hdmi_power_on(dssdev);
  1093. if (r) {
  1094. DSSERR("failed to power on device\n");
  1095. goto err2;
  1096. }
  1097. mutex_unlock(&hdmi.lock);
  1098. return 0;
  1099. err2:
  1100. if (dssdev->platform_disable)
  1101. dssdev->platform_disable(dssdev);
  1102. err1:
  1103. omap_dss_stop_device(dssdev);
  1104. err0:
  1105. mutex_unlock(&hdmi.lock);
  1106. return r;
  1107. }
  1108. void omapdss_hdmi_display_disable(struct omap_dss_device *dssdev)
  1109. {
  1110. DSSDBG("Enter hdmi_display_disable\n");
  1111. mutex_lock(&hdmi.lock);
  1112. hdmi_power_off(dssdev);
  1113. if (dssdev->platform_disable)
  1114. dssdev->platform_disable(dssdev);
  1115. omap_dss_stop_device(dssdev);
  1116. mutex_unlock(&hdmi.lock);
  1117. }
  1118. #if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \
  1119. defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE)
  1120. static void hdmi_wp_audio_config_format(struct hdmi_ip_data *ip_data,
  1121. struct hdmi_audio_format *aud_fmt)
  1122. {
  1123. u32 r;
  1124. DSSDBG("Enter hdmi_wp_audio_config_format\n");
  1125. r = hdmi_read_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CFG);
  1126. r = FLD_MOD(r, aud_fmt->stereo_channels, 26, 24);
  1127. r = FLD_MOD(r, aud_fmt->active_chnnls_msk, 23, 16);
  1128. r = FLD_MOD(r, aud_fmt->en_sig_blk_strt_end, 5, 5);
  1129. r = FLD_MOD(r, aud_fmt->type, 4, 4);
  1130. r = FLD_MOD(r, aud_fmt->justification, 3, 3);
  1131. r = FLD_MOD(r, aud_fmt->sample_order, 2, 2);
  1132. r = FLD_MOD(r, aud_fmt->samples_per_word, 1, 1);
  1133. r = FLD_MOD(r, aud_fmt->sample_size, 0, 0);
  1134. hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CFG, r);
  1135. }
  1136. static void hdmi_wp_audio_config_dma(struct hdmi_ip_data *ip_data,
  1137. struct hdmi_audio_dma *aud_dma)
  1138. {
  1139. u32 r;
  1140. DSSDBG("Enter hdmi_wp_audio_config_dma\n");
  1141. r = hdmi_read_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CFG2);
  1142. r = FLD_MOD(r, aud_dma->transfer_size, 15, 8);
  1143. r = FLD_MOD(r, aud_dma->block_size, 7, 0);
  1144. hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CFG2, r);
  1145. r = hdmi_read_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CTRL);
  1146. r = FLD_MOD(r, aud_dma->mode, 9, 9);
  1147. r = FLD_MOD(r, aud_dma->fifo_threshold, 8, 0);
  1148. hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CTRL, r);
  1149. }
  1150. static void hdmi_core_audio_config(struct hdmi_ip_data *ip_data,
  1151. struct hdmi_core_audio_config *cfg)
  1152. {
  1153. u32 r;
  1154. void __iomem *av_base = hdmi_av_base(ip_data);
  1155. /* audio clock recovery parameters */
  1156. r = hdmi_read_reg(av_base, HDMI_CORE_AV_ACR_CTRL);
  1157. r = FLD_MOD(r, cfg->use_mclk, 2, 2);
  1158. r = FLD_MOD(r, cfg->en_acr_pkt, 1, 1);
  1159. r = FLD_MOD(r, cfg->cts_mode, 0, 0);
  1160. hdmi_write_reg(av_base, HDMI_CORE_AV_ACR_CTRL, r);
  1161. REG_FLD_MOD(av_base, HDMI_CORE_AV_N_SVAL1, cfg->n, 7, 0);
  1162. REG_FLD_MOD(av_base, HDMI_CORE_AV_N_SVAL2, cfg->n >> 8, 7, 0);
  1163. REG_FLD_MOD(av_base, HDMI_CORE_AV_N_SVAL3, cfg->n >> 16, 7, 0);
  1164. if (cfg->cts_mode == HDMI_AUDIO_CTS_MODE_SW) {
  1165. REG_FLD_MOD(av_base, HDMI_CORE_AV_CTS_SVAL1, cfg->cts, 7, 0);
  1166. REG_FLD_MOD(av_base,
  1167. HDMI_CORE_AV_CTS_SVAL2, cfg->cts >> 8, 7, 0);
  1168. REG_FLD_MOD(av_base,
  1169. HDMI_CORE_AV_CTS_SVAL3, cfg->cts >> 16, 7, 0);
  1170. } else {
  1171. /*
  1172. * HDMI IP uses this configuration to divide the MCLK to
  1173. * update CTS value.
  1174. */
  1175. REG_FLD_MOD(av_base,
  1176. HDMI_CORE_AV_FREQ_SVAL, cfg->mclk_mode, 2, 0);
  1177. /* Configure clock for audio packets */
  1178. REG_FLD_MOD(av_base, HDMI_CORE_AV_AUD_PAR_BUSCLK_1,
  1179. cfg->aud_par_busclk, 7, 0);
  1180. REG_FLD_MOD(av_base, HDMI_CORE_AV_AUD_PAR_BUSCLK_2,
  1181. (cfg->aud_par_busclk >> 8), 7, 0);
  1182. REG_FLD_MOD(av_base, HDMI_CORE_AV_AUD_PAR_BUSCLK_3,
  1183. (cfg->aud_par_busclk >> 16), 7, 0);
  1184. }
  1185. /* Override of SPDIF sample frequency with value in I2S_CHST4 */
  1186. REG_FLD_MOD(av_base, HDMI_CORE_AV_SPDIF_CTRL,
  1187. cfg->fs_override, 1, 1);
  1188. /* I2S parameters */
  1189. REG_FLD_MOD(av_base, HDMI_CORE_AV_I2S_CHST4,
  1190. cfg->freq_sample, 3, 0);
  1191. r = hdmi_read_reg(av_base, HDMI_CORE_AV_I2S_IN_CTRL);
  1192. r = FLD_MOD(r, cfg->i2s_cfg.en_high_bitrate_aud, 7, 7);
  1193. r = FLD_MOD(r, cfg->i2s_cfg.sck_edge_mode, 6, 6);
  1194. r = FLD_MOD(r, cfg->i2s_cfg.cbit_order, 5, 5);
  1195. r = FLD_MOD(r, cfg->i2s_cfg.vbit, 4, 4);
  1196. r = FLD_MOD(r, cfg->i2s_cfg.ws_polarity, 3, 3);
  1197. r = FLD_MOD(r, cfg->i2s_cfg.justification, 2, 2);
  1198. r = FLD_MOD(r, cfg->i2s_cfg.direction, 1, 1);
  1199. r = FLD_MOD(r, cfg->i2s_cfg.shift, 0, 0);
  1200. hdmi_write_reg(av_base, HDMI_CORE_AV_I2S_IN_CTRL, r);
  1201. r = hdmi_read_reg(av_base, HDMI_CORE_AV_I2S_CHST5);
  1202. r = FLD_MOD(r, cfg->freq_sample, 7, 4);
  1203. r = FLD_MOD(r, cfg->i2s_cfg.word_length, 3, 1);
  1204. r = FLD_MOD(r, cfg->i2s_cfg.word_max_length, 0, 0);
  1205. hdmi_write_reg(av_base, HDMI_CORE_AV_I2S_CHST5, r);
  1206. REG_FLD_MOD(av_base, HDMI_CORE_AV_I2S_IN_LEN,
  1207. cfg->i2s_cfg.in_length_bits, 3, 0);
  1208. /* Audio channels and mode parameters */
  1209. REG_FLD_MOD(av_base, HDMI_CORE_AV_HDMI_CTRL, cfg->layout, 2, 1);
  1210. r = hdmi_read_reg(av_base, HDMI_CORE_AV_AUD_MODE);
  1211. r = FLD_MOD(r, cfg->i2s_cfg.active_sds, 7, 4);
  1212. r = FLD_MOD(r, cfg->en_dsd_audio, 3, 3);
  1213. r = FLD_MOD(r, cfg->en_parallel_aud_input, 2, 2);
  1214. r = FLD_MOD(r, cfg->en_spdif, 1, 1);
  1215. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_MODE, r);
  1216. }
  1217. static void hdmi_core_audio_infoframe_config(struct hdmi_ip_data *ip_data,
  1218. struct hdmi_core_infoframe_audio *info_aud)
  1219. {
  1220. u8 val;
  1221. u8 sum = 0, checksum = 0;
  1222. void __iomem *av_base = hdmi_av_base(ip_data);
  1223. /*
  1224. * Set audio info frame type, version and length as
  1225. * described in HDMI 1.4a Section 8.2.2 specification.
  1226. * Checksum calculation is defined in Section 5.3.5.
  1227. */
  1228. hdmi_write_reg(av_base, HDMI_CORE_AV_AUDIO_TYPE, 0x84);
  1229. hdmi_write_reg(av_base, HDMI_CORE_AV_AUDIO_VERS, 0x01);
  1230. hdmi_write_reg(av_base, HDMI_CORE_AV_AUDIO_LEN, 0x0a);
  1231. sum += 0x84 + 0x001 + 0x00a;
  1232. val = (info_aud->db1_coding_type << 4)
  1233. | (info_aud->db1_channel_count - 1);
  1234. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(0), val);
  1235. sum += val;
  1236. val = (info_aud->db2_sample_freq << 2) | info_aud->db2_sample_size;
  1237. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(1), val);
  1238. sum += val;
  1239. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(2), 0x00);
  1240. val = info_aud->db4_channel_alloc;
  1241. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(3), val);
  1242. sum += val;
  1243. val = (info_aud->db5_downmix_inh << 7) | (info_aud->db5_lsv << 3);
  1244. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(4), val);
  1245. sum += val;
  1246. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(5), 0x00);
  1247. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(6), 0x00);
  1248. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(7), 0x00);
  1249. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(8), 0x00);
  1250. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(9), 0x00);
  1251. checksum = 0x100 - sum;
  1252. hdmi_write_reg(av_base,
  1253. HDMI_CORE_AV_AUDIO_CHSUM, checksum);
  1254. /*
  1255. * TODO: Add MPEG and SPD enable and repeat cfg when EDID parsing
  1256. * is available.
  1257. */
  1258. }
  1259. static int hdmi_config_audio_acr(struct hdmi_ip_data *ip_data,
  1260. u32 sample_freq, u32 *n, u32 *cts)
  1261. {
  1262. u32 r;
  1263. u32 deep_color = 0;
  1264. u32 pclk = hdmi.cfg.timings.timings.pixel_clock;
  1265. if (n == NULL || cts == NULL)
  1266. return -EINVAL;
  1267. /*
  1268. * Obtain current deep color configuration. This needed
  1269. * to calculate the TMDS clock based on the pixel clock.
  1270. */
  1271. r = REG_GET(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_CFG, 1, 0);
  1272. switch (r) {
  1273. case 1: /* No deep color selected */
  1274. deep_color = 100;
  1275. break;
  1276. case 2: /* 10-bit deep color selected */
  1277. deep_color = 125;
  1278. break;
  1279. case 3: /* 12-bit deep color selected */
  1280. deep_color = 150;
  1281. break;
  1282. default:
  1283. return -EINVAL;
  1284. }
  1285. switch (sample_freq) {
  1286. case 32000:
  1287. if ((deep_color == 125) && ((pclk == 54054)
  1288. || (pclk == 74250)))
  1289. *n = 8192;
  1290. else
  1291. *n = 4096;
  1292. break;
  1293. case 44100:
  1294. *n = 6272;
  1295. break;
  1296. case 48000:
  1297. if ((deep_color == 125) && ((pclk == 54054)
  1298. || (pclk == 74250)))
  1299. *n = 8192;
  1300. else
  1301. *n = 6144;
  1302. break;
  1303. default:
  1304. *n = 0;
  1305. return -EINVAL;
  1306. }
  1307. /* Calculate CTS. See HDMI 1.3a or 1.4a specifications */
  1308. *cts = pclk * (*n / 128) * deep_color / (sample_freq / 10);
  1309. return 0;
  1310. }
  1311. static int hdmi_audio_hw_params(struct hdmi_ip_data *ip_data,
  1312. struct snd_pcm_substream *substream,
  1313. struct snd_pcm_hw_params *params,
  1314. struct snd_soc_dai *dai)
  1315. {
  1316. struct hdmi_audio_format audio_format;
  1317. struct hdmi_audio_dma audio_dma;
  1318. struct hdmi_core_audio_config core_cfg;
  1319. struct hdmi_core_infoframe_audio aud_if_cfg;
  1320. int err, n, cts;
  1321. enum hdmi_core_audio_sample_freq sample_freq;
  1322. switch (params_format(params)) {
  1323. case SNDRV_PCM_FORMAT_S16_LE:
  1324. core_cfg.i2s_cfg.word_max_length =
  1325. HDMI_AUDIO_I2S_MAX_WORD_20BITS;
  1326. core_cfg.i2s_cfg.word_length = HDMI_AUDIO_I2S_CHST_WORD_16_BITS;
  1327. core_cfg.i2s_cfg.in_length_bits =
  1328. HDMI_AUDIO_I2S_INPUT_LENGTH_16;
  1329. core_cfg.i2s_cfg.justification = HDMI_AUDIO_JUSTIFY_LEFT;
  1330. audio_format.samples_per_word = HDMI_AUDIO_ONEWORD_TWOSAMPLES;
  1331. audio_format.sample_size = HDMI_AUDIO_SAMPLE_16BITS;
  1332. audio_format.justification = HDMI_AUDIO_JUSTIFY_LEFT;
  1333. audio_dma.transfer_size = 0x10;
  1334. break;
  1335. case SNDRV_PCM_FORMAT_S24_LE:
  1336. core_cfg.i2s_cfg.word_max_length =
  1337. HDMI_AUDIO_I2S_MAX_WORD_24BITS;
  1338. core_cfg.i2s_cfg.word_length = HDMI_AUDIO_I2S_CHST_WORD_24_BITS;
  1339. core_cfg.i2s_cfg.in_length_bits =
  1340. HDMI_AUDIO_I2S_INPUT_LENGTH_24;
  1341. audio_format.samples_per_word = HDMI_AUDIO_ONEWORD_ONESAMPLE;
  1342. audio_format.sample_size = HDMI_AUDIO_SAMPLE_24BITS;
  1343. audio_format.justification = HDMI_AUDIO_JUSTIFY_RIGHT;
  1344. core_cfg.i2s_cfg.justification = HDMI_AUDIO_JUSTIFY_RIGHT;
  1345. audio_dma.transfer_size = 0x20;
  1346. break;
  1347. default:
  1348. return -EINVAL;
  1349. }
  1350. switch (params_rate(params)) {
  1351. case 32000:
  1352. sample_freq = HDMI_AUDIO_FS_32000;
  1353. break;
  1354. case 44100:
  1355. sample_freq = HDMI_AUDIO_FS_44100;
  1356. break;
  1357. case 48000:
  1358. sample_freq = HDMI_AUDIO_FS_48000;
  1359. break;
  1360. default:
  1361. return -EINVAL;
  1362. }
  1363. err = hdmi_config_audio_acr(ip_data, params_rate(params), &n, &cts);
  1364. if (err < 0)
  1365. return err;
  1366. /* Audio wrapper config */
  1367. audio_format.stereo_channels = HDMI_AUDIO_STEREO_ONECHANNEL;
  1368. audio_format.active_chnnls_msk = 0x03;
  1369. audio_format.type = HDMI_AUDIO_TYPE_LPCM;
  1370. audio_format.sample_order = HDMI_AUDIO_SAMPLE_LEFT_FIRST;
  1371. /* Disable start/stop signals of IEC 60958 blocks */
  1372. audio_format.en_sig_blk_strt_end = HDMI_AUDIO_BLOCK_SIG_STARTEND_OFF;
  1373. audio_dma.block_size = 0xC0;
  1374. audio_dma.mode = HDMI_AUDIO_TRANSF_DMA;
  1375. audio_dma.fifo_threshold = 0x20; /* in number of samples */
  1376. hdmi_wp_audio_config_dma(ip_data, &audio_dma);
  1377. hdmi_wp_audio_config_format(ip_data, &audio_format);
  1378. /*
  1379. * I2S config
  1380. */
  1381. core_cfg.i2s_cfg.en_high_bitrate_aud = false;
  1382. /* Only used with high bitrate audio */
  1383. core_cfg.i2s_cfg.cbit_order = false;
  1384. /* Serial data and word select should change on sck rising edge */
  1385. core_cfg.i2s_cfg.sck_edge_mode = HDMI_AUDIO_I2S_SCK_EDGE_RISING;
  1386. core_cfg.i2s_cfg.vbit = HDMI_AUDIO_I2S_VBIT_FOR_PCM;
  1387. /* Set I2S word select polarity */
  1388. core_cfg.i2s_cfg.ws_polarity = HDMI_AUDIO_I2S_WS_POLARITY_LOW_IS_LEFT;
  1389. core_cfg.i2s_cfg.direction = HDMI_AUDIO_I2S_MSB_SHIFTED_FIRST;
  1390. /* Set serial data to word select shift. See Phillips spec. */
  1391. core_cfg.i2s_cfg.shift = HDMI_AUDIO_I2S_FIRST_BIT_SHIFT;
  1392. /* Enable one of the four available serial data channels */
  1393. core_cfg.i2s_cfg.active_sds = HDMI_AUDIO_I2S_SD0_EN;
  1394. /* Core audio config */
  1395. core_cfg.freq_sample = sample_freq;
  1396. core_cfg.n = n;
  1397. core_cfg.cts = cts;
  1398. if (dss_has_feature(FEAT_HDMI_CTS_SWMODE)) {
  1399. core_cfg.aud_par_busclk = 0;
  1400. core_cfg.cts_mode = HDMI_AUDIO_CTS_MODE_SW;
  1401. core_cfg.use_mclk = false;
  1402. } else {
  1403. core_cfg.aud_par_busclk = (((128 * 31) - 1) << 8);
  1404. core_cfg.cts_mode = HDMI_AUDIO_CTS_MODE_HW;
  1405. core_cfg.use_mclk = true;
  1406. core_cfg.mclk_mode = HDMI_AUDIO_MCLK_128FS;
  1407. }
  1408. core_cfg.layout = HDMI_AUDIO_LAYOUT_2CH;
  1409. core_cfg.en_spdif = false;
  1410. /* Use sample frequency from channel status word */
  1411. core_cfg.fs_override = true;
  1412. /* Enable ACR packets */
  1413. core_cfg.en_acr_pkt = true;
  1414. /* Disable direct streaming digital audio */
  1415. core_cfg.en_dsd_audio = false;
  1416. /* Use parallel audio interface */
  1417. core_cfg.en_parallel_aud_input = true;
  1418. hdmi_core_audio_config(ip_data, &core_cfg);
  1419. /*
  1420. * Configure packet
  1421. * info frame audio see doc CEA861-D page 74
  1422. */
  1423. aud_if_cfg.db1_coding_type = HDMI_INFOFRAME_AUDIO_DB1CT_FROM_STREAM;
  1424. aud_if_cfg.db1_channel_count = 2;
  1425. aud_if_cfg.db2_sample_freq = HDMI_INFOFRAME_AUDIO_DB2SF_FROM_STREAM;
  1426. aud_if_cfg.db2_sample_size = HDMI_INFOFRAME_AUDIO_DB2SS_FROM_STREAM;
  1427. aud_if_cfg.db4_channel_alloc = 0x00;
  1428. aud_if_cfg.db5_downmix_inh = false;
  1429. aud_if_cfg.db5_lsv = 0;
  1430. hdmi_core_audio_infoframe_config(ip_data, &aud_if_cfg);
  1431. return 0;
  1432. }
  1433. static int hdmi_audio_trigger(struct hdmi_ip_data *ip_data,
  1434. struct snd_pcm_substream *substream, int cmd,
  1435. struct snd_soc_dai *dai)
  1436. {
  1437. int err = 0;
  1438. switch (cmd) {
  1439. case SNDRV_PCM_TRIGGER_START:
  1440. case SNDRV_PCM_TRIGGER_RESUME:
  1441. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  1442. REG_FLD_MOD(hdmi_av_base(ip_data),
  1443. HDMI_CORE_AV_AUD_MODE, 1, 0, 0);
  1444. REG_FLD_MOD(hdmi_wp_base(ip_data),
  1445. HDMI_WP_AUDIO_CTRL, 1, 31, 31);
  1446. REG_FLD_MOD(hdmi_wp_base(ip_data),
  1447. HDMI_WP_AUDIO_CTRL, 1, 30, 30);
  1448. break;
  1449. case SNDRV_PCM_TRIGGER_STOP:
  1450. case SNDRV_PCM_TRIGGER_SUSPEND:
  1451. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  1452. REG_FLD_MOD(hdmi_av_base(ip_data),
  1453. HDMI_CORE_AV_AUD_MODE, 0, 0, 0);
  1454. REG_FLD_MOD(hdmi_wp_base(ip_data),
  1455. HDMI_WP_AUDIO_CTRL, 0, 30, 30);
  1456. REG_FLD_MOD(hdmi_wp_base(ip_data),
  1457. HDMI_WP_AUDIO_CTRL, 0, 31, 31);
  1458. break;
  1459. default:
  1460. err = -EINVAL;
  1461. }
  1462. return err;
  1463. }
  1464. static int hdmi_audio_startup(struct snd_pcm_substream *substream,
  1465. struct snd_soc_dai *dai)
  1466. {
  1467. if (!hdmi.mode) {
  1468. pr_err("Current video settings do not support audio.\n");
  1469. return -EIO;
  1470. }
  1471. return 0;
  1472. }
  1473. static struct snd_soc_codec_driver hdmi_audio_codec_drv = {
  1474. };
  1475. static struct snd_soc_dai_ops hdmi_audio_codec_ops = {
  1476. .hw_params = hdmi_audio_hw_params,
  1477. .trigger = hdmi_audio_trigger,
  1478. .startup = hdmi_audio_startup,
  1479. };
  1480. static struct snd_soc_dai_driver hdmi_codec_dai_drv = {
  1481. .name = "hdmi-audio-codec",
  1482. .playback = {
  1483. .channels_min = 2,
  1484. .channels_max = 2,
  1485. .rates = SNDRV_PCM_RATE_32000 |
  1486. SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000,
  1487. .formats = SNDRV_PCM_FMTBIT_S16_LE |
  1488. SNDRV_PCM_FMTBIT_S24_LE,
  1489. },
  1490. .ops = &hdmi_audio_codec_ops,
  1491. };
  1492. #endif
  1493. static int hdmi_get_clocks(struct platform_device *pdev)
  1494. {
  1495. struct clk *clk;
  1496. clk = clk_get(&pdev->dev, "sys_clk");
  1497. if (IS_ERR(clk)) {
  1498. DSSERR("can't get sys_clk\n");
  1499. return PTR_ERR(clk);
  1500. }
  1501. hdmi.sys_clk = clk;
  1502. return 0;
  1503. }
  1504. static void hdmi_put_clocks(void)
  1505. {
  1506. if (hdmi.sys_clk)
  1507. clk_put(hdmi.sys_clk);
  1508. }
  1509. /* HDMI HW IP initialisation */
  1510. static int omapdss_hdmihw_probe(struct platform_device *pdev)
  1511. {
  1512. struct resource *hdmi_mem;
  1513. int r;
  1514. hdmi.pdata = pdev->dev.platform_data;
  1515. hdmi.pdev = pdev;
  1516. mutex_init(&hdmi.lock);
  1517. hdmi_mem = platform_get_resource(hdmi.pdev, IORESOURCE_MEM, 0);
  1518. if (!hdmi_mem) {
  1519. DSSERR("can't get IORESOURCE_MEM HDMI\n");
  1520. return -EINVAL;
  1521. }
  1522. /* Base address taken from platform */
  1523. hdmi.ip_data.base_wp = ioremap(hdmi_mem->start,
  1524. resource_size(hdmi_mem));
  1525. if (!hdmi.ip_data.base_wp) {
  1526. DSSERR("can't ioremap WP\n");
  1527. return -ENOMEM;
  1528. }
  1529. r = hdmi_get_clocks(pdev);
  1530. if (r) {
  1531. iounmap(hdmi.ip_data.base_wp);
  1532. return r;
  1533. }
  1534. pm_runtime_enable(&pdev->dev);
  1535. hdmi.ip_data.core_sys_offset = HDMI_CORE_SYS;
  1536. hdmi.ip_data.core_av_offset = HDMI_CORE_AV;
  1537. hdmi.ip_data.pll_offset = HDMI_PLLCTRL;
  1538. hdmi.ip_data.phy_offset = HDMI_PHY;
  1539. hdmi_panel_init();
  1540. #if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \
  1541. defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE)
  1542. /* Register ASoC codec DAI */
  1543. r = snd_soc_register_codec(&pdev->dev, &hdmi_audio_codec_drv,
  1544. &hdmi_codec_dai_drv, 1);
  1545. if (r) {
  1546. DSSERR("can't register ASoC HDMI audio codec\n");
  1547. return r;
  1548. }
  1549. #endif
  1550. return 0;
  1551. }
  1552. static int omapdss_hdmihw_remove(struct platform_device *pdev)
  1553. {
  1554. hdmi_panel_exit();
  1555. #if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \
  1556. defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE)
  1557. snd_soc_unregister_codec(&pdev->dev);
  1558. #endif
  1559. pm_runtime_disable(&pdev->dev);
  1560. hdmi_put_clocks();
  1561. iounmap(hdmi.ip_data.base_wp);
  1562. return 0;
  1563. }
  1564. static int hdmi_runtime_suspend(struct device *dev)
  1565. {
  1566. clk_disable(hdmi.sys_clk);
  1567. dispc_runtime_put();
  1568. dss_runtime_put();
  1569. return 0;
  1570. }
  1571. static int hdmi_runtime_resume(struct device *dev)
  1572. {
  1573. int r;
  1574. r = dss_runtime_get();
  1575. if (r < 0)
  1576. goto err_get_dss;
  1577. r = dispc_runtime_get();
  1578. if (r < 0)
  1579. goto err_get_dispc;
  1580. clk_enable(hdmi.sys_clk);
  1581. return 0;
  1582. err_get_dispc:
  1583. dss_runtime_put();
  1584. err_get_dss:
  1585. return r;
  1586. }
  1587. static const struct dev_pm_ops hdmi_pm_ops = {
  1588. .runtime_suspend = hdmi_runtime_suspend,
  1589. .runtime_resume = hdmi_runtime_resume,
  1590. };
  1591. static struct platform_driver omapdss_hdmihw_driver = {
  1592. .probe = omapdss_hdmihw_probe,
  1593. .remove = omapdss_hdmihw_remove,
  1594. .driver = {
  1595. .name = "omapdss_hdmi",
  1596. .owner = THIS_MODULE,
  1597. .pm = &hdmi_pm_ops,
  1598. },
  1599. };
  1600. int hdmi_init_platform_driver(void)
  1601. {
  1602. return platform_driver_register(&omapdss_hdmihw_driver);
  1603. }
  1604. void hdmi_uninit_platform_driver(void)
  1605. {
  1606. return platform_driver_unregister(&omapdss_hdmihw_driver);
  1607. }