hdmi.c 52 KB

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