hdmi.c 53 KB

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