hdmi.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206
  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 "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. /* HDMI EDID Length move this */
  48. #define HDMI_EDID_MAX_LENGTH 256
  49. #define EDID_TIMING_DESCRIPTOR_SIZE 0x12
  50. #define EDID_DESCRIPTOR_BLOCK0_ADDRESS 0x36
  51. #define EDID_DESCRIPTOR_BLOCK1_ADDRESS 0x80
  52. #define EDID_SIZE_BLOCK0_TIMING_DESCRIPTOR 4
  53. #define EDID_SIZE_BLOCK1_TIMING_DESCRIPTOR 4
  54. #define OMAP_HDMI_TIMINGS_NB 34
  55. static struct {
  56. struct mutex lock;
  57. struct omap_display_platform_data *pdata;
  58. struct platform_device *pdev;
  59. struct hdmi_ip_data ip_data;
  60. int code;
  61. int mode;
  62. u8 edid[HDMI_EDID_MAX_LENGTH];
  63. u8 edid_set;
  64. bool custom_set;
  65. struct clk *sys_clk;
  66. } hdmi;
  67. /*
  68. * Logic for the below structure :
  69. * user enters the CEA or VESA timings by specifying the HDMI/DVI code.
  70. * There is a correspondence between CEA/VESA timing and code, please
  71. * refer to section 6.3 in HDMI 1.3 specification for timing code.
  72. *
  73. * In the below structure, cea_vesa_timings corresponds to all OMAP4
  74. * supported CEA and VESA timing values.code_cea corresponds to the CEA
  75. * code, It is used to get the timing from cea_vesa_timing array.Similarly
  76. * with code_vesa. Code_index is used for back mapping, that is once EDID
  77. * is read from the TV, EDID is parsed to find the timing values and then
  78. * map it to corresponding CEA or VESA index.
  79. */
  80. static const struct hdmi_timings cea_vesa_timings[OMAP_HDMI_TIMINGS_NB] = {
  81. { {640, 480, 25200, 96, 16, 48, 2, 10, 33} , 0 , 0},
  82. { {1280, 720, 74250, 40, 440, 220, 5, 5, 20}, 1, 1},
  83. { {1280, 720, 74250, 40, 110, 220, 5, 5, 20}, 1, 1},
  84. { {720, 480, 27027, 62, 16, 60, 6, 9, 30}, 0, 0},
  85. { {2880, 576, 108000, 256, 48, 272, 5, 5, 39}, 0, 0},
  86. { {1440, 240, 27027, 124, 38, 114, 3, 4, 15}, 0, 0},
  87. { {1440, 288, 27000, 126, 24, 138, 3, 2, 19}, 0, 0},
  88. { {1920, 540, 74250, 44, 528, 148, 5, 2, 15}, 1, 1},
  89. { {1920, 540, 74250, 44, 88, 148, 5, 2, 15}, 1, 1},
  90. { {1920, 1080, 148500, 44, 88, 148, 5, 4, 36}, 1, 1},
  91. { {720, 576, 27000, 64, 12, 68, 5, 5, 39}, 0, 0},
  92. { {1440, 576, 54000, 128, 24, 136, 5, 5, 39}, 0, 0},
  93. { {1920, 1080, 148500, 44, 528, 148, 5, 4, 36}, 1, 1},
  94. { {2880, 480, 108108, 248, 64, 240, 6, 9, 30}, 0, 0},
  95. { {1920, 1080, 74250, 44, 638, 148, 5, 4, 36}, 1, 1},
  96. /* VESA From Here */
  97. { {640, 480, 25175, 96, 16, 48, 2 , 11, 31}, 0, 0},
  98. { {800, 600, 40000, 128, 40, 88, 4 , 1, 23}, 1, 1},
  99. { {848, 480, 33750, 112, 16, 112, 8 , 6, 23}, 1, 1},
  100. { {1280, 768, 79500, 128, 64, 192, 7 , 3, 20}, 1, 0},
  101. { {1280, 800, 83500, 128, 72, 200, 6 , 3, 22}, 1, 0},
  102. { {1360, 768, 85500, 112, 64, 256, 6 , 3, 18}, 1, 1},
  103. { {1280, 960, 108000, 112, 96, 312, 3 , 1, 36}, 1, 1},
  104. { {1280, 1024, 108000, 112, 48, 248, 3 , 1, 38}, 1, 1},
  105. { {1024, 768, 65000, 136, 24, 160, 6, 3, 29}, 0, 0},
  106. { {1400, 1050, 121750, 144, 88, 232, 4, 3, 32}, 1, 0},
  107. { {1440, 900, 106500, 152, 80, 232, 6, 3, 25}, 1, 0},
  108. { {1680, 1050, 146250, 176 , 104, 280, 6, 3, 30}, 1, 0},
  109. { {1366, 768, 85500, 143, 70, 213, 3, 3, 24}, 1, 1},
  110. { {1920, 1080, 148500, 44, 148, 80, 5, 4, 36}, 1, 1},
  111. { {1280, 768, 68250, 32, 48, 80, 7, 3, 12}, 0, 1},
  112. { {1400, 1050, 101000, 32, 48, 80, 4, 3, 23}, 0, 1},
  113. { {1680, 1050, 119000, 32, 48, 80, 6, 3, 21}, 0, 1},
  114. { {1280, 800, 79500, 32, 48, 80, 6, 3, 14}, 0, 1},
  115. { {1280, 720, 74250, 40, 110, 220, 5, 5, 20}, 1, 1}
  116. };
  117. /*
  118. * This is a static mapping array which maps the timing values
  119. * with corresponding CEA / VESA code
  120. */
  121. static const int code_index[OMAP_HDMI_TIMINGS_NB] = {
  122. 1, 19, 4, 2, 37, 6, 21, 20, 5, 16, 17, 29, 31, 35, 32,
  123. /* <--15 CEA 17--> vesa*/
  124. 4, 9, 0xE, 0x17, 0x1C, 0x27, 0x20, 0x23, 0x10, 0x2A,
  125. 0X2F, 0x3A, 0X51, 0X52, 0x16, 0x29, 0x39, 0x1B
  126. };
  127. /*
  128. * This is reverse static mapping which maps the CEA / VESA code
  129. * to the corresponding timing values
  130. */
  131. static const int code_cea[39] = {
  132. -1, 0, 3, 3, 2, 8, 5, 5, -1, -1,
  133. -1, -1, -1, -1, -1, -1, 9, 10, 10, 1,
  134. 7, 6, 6, -1, -1, -1, -1, -1, -1, 11,
  135. 11, 12, 14, -1, -1, 13, 13, 4, 4
  136. };
  137. static const int code_vesa[85] = {
  138. -1, -1, -1, -1, 15, -1, -1, -1, -1, 16,
  139. -1, -1, -1, -1, 17, -1, 23, -1, -1, -1,
  140. -1, -1, 29, 18, -1, -1, -1, 32, 19, -1,
  141. -1, -1, 21, -1, -1, 22, -1, -1, -1, 20,
  142. -1, 30, 24, -1, -1, -1, -1, 25, -1, -1,
  143. -1, -1, -1, -1, -1, -1, -1, 31, 26, -1,
  144. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  145. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  146. -1, 27, 28, -1, 33};
  147. static const u8 edid_header[8] = {0x0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0};
  148. static int hdmi_runtime_get(void)
  149. {
  150. int r;
  151. DSSDBG("hdmi_runtime_get\n");
  152. r = pm_runtime_get_sync(&hdmi.pdev->dev);
  153. WARN_ON(r < 0);
  154. return r < 0 ? r : 0;
  155. }
  156. static void hdmi_runtime_put(void)
  157. {
  158. int r;
  159. DSSDBG("hdmi_runtime_put\n");
  160. r = pm_runtime_put(&hdmi.pdev->dev);
  161. WARN_ON(r < 0);
  162. }
  163. int hdmi_init_display(struct omap_dss_device *dssdev)
  164. {
  165. DSSDBG("init_display\n");
  166. return 0;
  167. }
  168. static void copy_hdmi_to_dss_timings(
  169. const struct hdmi_video_timings *hdmi_timings,
  170. struct omap_video_timings *timings)
  171. {
  172. timings->x_res = hdmi_timings->x_res;
  173. timings->y_res = hdmi_timings->y_res;
  174. timings->pixel_clock = hdmi_timings->pixel_clock;
  175. timings->hbp = hdmi_timings->hbp;
  176. timings->hfp = hdmi_timings->hfp;
  177. timings->hsw = hdmi_timings->hsw;
  178. timings->vbp = hdmi_timings->vbp;
  179. timings->vfp = hdmi_timings->vfp;
  180. timings->vsw = hdmi_timings->vsw;
  181. }
  182. static int get_timings_index(void)
  183. {
  184. int code;
  185. if (hdmi.mode == 0)
  186. code = code_vesa[hdmi.code];
  187. else
  188. code = code_cea[hdmi.code];
  189. if (code == -1) {
  190. /* HDMI code 4 corresponds to 640 * 480 VGA */
  191. hdmi.code = 4;
  192. /* DVI mode 1 corresponds to HDMI 0 to DVI */
  193. hdmi.mode = HDMI_DVI;
  194. code = code_vesa[hdmi.code];
  195. }
  196. return code;
  197. }
  198. static struct hdmi_cm hdmi_get_code(struct omap_video_timings *timing)
  199. {
  200. int i = 0, code = -1, temp_vsync = 0, temp_hsync = 0;
  201. int timing_vsync = 0, timing_hsync = 0;
  202. struct hdmi_video_timings temp;
  203. struct hdmi_cm cm = {-1};
  204. DSSDBG("hdmi_get_code\n");
  205. for (i = 0; i < OMAP_HDMI_TIMINGS_NB; i++) {
  206. temp = cea_vesa_timings[i].timings;
  207. if ((temp.pixel_clock == timing->pixel_clock) &&
  208. (temp.x_res == timing->x_res) &&
  209. (temp.y_res == timing->y_res)) {
  210. temp_hsync = temp.hfp + temp.hsw + temp.hbp;
  211. timing_hsync = timing->hfp + timing->hsw + timing->hbp;
  212. temp_vsync = temp.vfp + temp.vsw + temp.vbp;
  213. timing_vsync = timing->vfp + timing->vsw + timing->vbp;
  214. DSSDBG("temp_hsync = %d , temp_vsync = %d"
  215. "timing_hsync = %d, timing_vsync = %d\n",
  216. temp_hsync, temp_hsync,
  217. timing_hsync, timing_vsync);
  218. if ((temp_hsync == timing_hsync) &&
  219. (temp_vsync == timing_vsync)) {
  220. code = i;
  221. cm.code = code_index[i];
  222. if (code < 14)
  223. cm.mode = HDMI_HDMI;
  224. else
  225. cm.mode = HDMI_DVI;
  226. DSSDBG("Hdmi_code = %d mode = %d\n",
  227. cm.code, cm.mode);
  228. break;
  229. }
  230. }
  231. }
  232. return cm;
  233. }
  234. static void get_horz_vert_timing_info(int current_descriptor_addrs, u8 *edid ,
  235. struct omap_video_timings *timings)
  236. {
  237. /* X and Y resolution */
  238. timings->x_res = (((edid[current_descriptor_addrs + 4] & 0xF0) << 4) |
  239. edid[current_descriptor_addrs + 2]);
  240. timings->y_res = (((edid[current_descriptor_addrs + 7] & 0xF0) << 4) |
  241. edid[current_descriptor_addrs + 5]);
  242. timings->pixel_clock = ((edid[current_descriptor_addrs + 1] << 8) |
  243. edid[current_descriptor_addrs]);
  244. timings->pixel_clock = 10 * timings->pixel_clock;
  245. /* HORIZONTAL FRONT PORCH */
  246. timings->hfp = edid[current_descriptor_addrs + 8] |
  247. ((edid[current_descriptor_addrs + 11] & 0xc0) << 2);
  248. /* HORIZONTAL SYNC WIDTH */
  249. timings->hsw = edid[current_descriptor_addrs + 9] |
  250. ((edid[current_descriptor_addrs + 11] & 0x30) << 4);
  251. /* HORIZONTAL BACK PORCH */
  252. timings->hbp = (((edid[current_descriptor_addrs + 4] & 0x0F) << 8) |
  253. edid[current_descriptor_addrs + 3]) -
  254. (timings->hfp + timings->hsw);
  255. /* VERTICAL FRONT PORCH */
  256. timings->vfp = ((edid[current_descriptor_addrs + 10] & 0xF0) >> 4) |
  257. ((edid[current_descriptor_addrs + 11] & 0x0f) << 2);
  258. /* VERTICAL SYNC WIDTH */
  259. timings->vsw = (edid[current_descriptor_addrs + 10] & 0x0F) |
  260. ((edid[current_descriptor_addrs + 11] & 0x03) << 4);
  261. /* VERTICAL BACK PORCH */
  262. timings->vbp = (((edid[current_descriptor_addrs + 7] & 0x0F) << 8) |
  263. edid[current_descriptor_addrs + 6]) -
  264. (timings->vfp + timings->vsw);
  265. }
  266. /* Description : This function gets the resolution information from EDID */
  267. static void get_edid_timing_data(u8 *edid)
  268. {
  269. u8 count;
  270. u16 current_descriptor_addrs;
  271. struct hdmi_cm cm;
  272. struct omap_video_timings edid_timings;
  273. /* search block 0, there are 4 DTDs arranged in priority order */
  274. for (count = 0; count < EDID_SIZE_BLOCK0_TIMING_DESCRIPTOR; count++) {
  275. current_descriptor_addrs =
  276. EDID_DESCRIPTOR_BLOCK0_ADDRESS +
  277. count * EDID_TIMING_DESCRIPTOR_SIZE;
  278. get_horz_vert_timing_info(current_descriptor_addrs,
  279. edid, &edid_timings);
  280. cm = hdmi_get_code(&edid_timings);
  281. DSSDBG("Block0[%d] value matches code = %d , mode = %d\n",
  282. count, cm.code, cm.mode);
  283. if (cm.code == -1) {
  284. continue;
  285. } else {
  286. hdmi.code = cm.code;
  287. hdmi.mode = cm.mode;
  288. DSSDBG("code = %d , mode = %d\n",
  289. hdmi.code, hdmi.mode);
  290. return;
  291. }
  292. }
  293. if (edid[0x7e] != 0x00) {
  294. for (count = 0; count < EDID_SIZE_BLOCK1_TIMING_DESCRIPTOR;
  295. count++) {
  296. current_descriptor_addrs =
  297. EDID_DESCRIPTOR_BLOCK1_ADDRESS +
  298. count * EDID_TIMING_DESCRIPTOR_SIZE;
  299. get_horz_vert_timing_info(current_descriptor_addrs,
  300. edid, &edid_timings);
  301. cm = hdmi_get_code(&edid_timings);
  302. DSSDBG("Block1[%d] value matches code = %d, mode = %d",
  303. count, cm.code, cm.mode);
  304. if (cm.code == -1) {
  305. continue;
  306. } else {
  307. hdmi.code = cm.code;
  308. hdmi.mode = cm.mode;
  309. DSSDBG("code = %d , mode = %d\n",
  310. hdmi.code, hdmi.mode);
  311. return;
  312. }
  313. }
  314. }
  315. DSSINFO("no valid timing found , falling back to VGA\n");
  316. hdmi.code = 4; /* setting default value of 640 480 VGA */
  317. hdmi.mode = HDMI_DVI;
  318. }
  319. static void hdmi_read_edid(struct omap_video_timings *dp)
  320. {
  321. int ret = 0, code;
  322. memset(hdmi.edid, 0, HDMI_EDID_MAX_LENGTH);
  323. if (!hdmi.edid_set)
  324. ret = read_edid(&hdmi.ip_data, hdmi.edid,
  325. HDMI_EDID_MAX_LENGTH);
  326. if (!ret) {
  327. if (!memcmp(hdmi.edid, edid_header, sizeof(edid_header))) {
  328. /* search for timings of default resolution */
  329. get_edid_timing_data(hdmi.edid);
  330. hdmi.edid_set = true;
  331. }
  332. } else {
  333. DSSWARN("failed to read E-EDID\n");
  334. }
  335. if (!hdmi.edid_set) {
  336. DSSINFO("fallback to VGA\n");
  337. hdmi.code = 4; /* setting default value of 640 480 VGA */
  338. hdmi.mode = HDMI_DVI;
  339. }
  340. code = get_timings_index();
  341. copy_hdmi_to_dss_timings(&cea_vesa_timings[code].timings, dp);
  342. }
  343. static void update_hdmi_timings(struct hdmi_config *cfg,
  344. struct omap_video_timings *timings, int code)
  345. {
  346. cfg->timings.timings.x_res = timings->x_res;
  347. cfg->timings.timings.y_res = timings->y_res;
  348. cfg->timings.timings.hbp = timings->hbp;
  349. cfg->timings.timings.hfp = timings->hfp;
  350. cfg->timings.timings.hsw = timings->hsw;
  351. cfg->timings.timings.vbp = timings->vbp;
  352. cfg->timings.timings.vfp = timings->vfp;
  353. cfg->timings.timings.vsw = timings->vsw;
  354. cfg->timings.timings.pixel_clock = timings->pixel_clock;
  355. cfg->timings.vsync_pol = cea_vesa_timings[code].vsync_pol;
  356. cfg->timings.hsync_pol = cea_vesa_timings[code].hsync_pol;
  357. }
  358. static void hdmi_compute_pll(struct omap_dss_device *dssdev, int phy,
  359. struct hdmi_pll_info *pi)
  360. {
  361. unsigned long clkin, refclk;
  362. u32 mf;
  363. clkin = clk_get_rate(hdmi.sys_clk) / 10000;
  364. /*
  365. * Input clock is predivided by N + 1
  366. * out put of which is reference clk
  367. */
  368. pi->regn = dssdev->clocks.hdmi.regn;
  369. refclk = clkin / (pi->regn + 1);
  370. /*
  371. * multiplier is pixel_clk/ref_clk
  372. * Multiplying by 100 to avoid fractional part removal
  373. */
  374. pi->regm = (phy * 100 / (refclk)) / 100;
  375. pi->regm2 = dssdev->clocks.hdmi.regm2;
  376. /*
  377. * fractional multiplier is remainder of the difference between
  378. * multiplier and actual phy(required pixel clock thus should be
  379. * multiplied by 2^18(262144) divided by the reference clock
  380. */
  381. mf = (phy - pi->regm * refclk) * 262144;
  382. pi->regmf = mf / (refclk);
  383. /*
  384. * Dcofreq should be set to 1 if required pixel clock
  385. * is greater than 1000MHz
  386. */
  387. pi->dcofreq = phy > 1000 * 100;
  388. pi->regsd = ((pi->regm * clkin / 10) / ((pi->regn + 1) * 250) + 5) / 10;
  389. /* Set the reference clock to sysclk reference */
  390. pi->refsel = HDMI_REFSEL_SYSCLK;
  391. DSSDBG("M = %d Mf = %d\n", pi->regm, pi->regmf);
  392. DSSDBG("range = %d sd = %d\n", pi->dcofreq, pi->regsd);
  393. }
  394. static int hdmi_power_on(struct omap_dss_device *dssdev)
  395. {
  396. int r, code = 0;
  397. struct omap_video_timings *p;
  398. unsigned long phy;
  399. r = hdmi_runtime_get();
  400. if (r)
  401. return r;
  402. dispc_mgr_enable(OMAP_DSS_CHANNEL_DIGIT, 0);
  403. p = &dssdev->panel.timings;
  404. DSSDBG("hdmi_power_on x_res= %d y_res = %d\n",
  405. dssdev->panel.timings.x_res,
  406. dssdev->panel.timings.y_res);
  407. if (!hdmi.custom_set) {
  408. DSSDBG("Read EDID as no EDID is not set on poweron\n");
  409. hdmi_read_edid(p);
  410. }
  411. code = get_timings_index();
  412. copy_hdmi_to_dss_timings(&cea_vesa_timings[code].timings,
  413. &dssdev->panel.timings);
  414. update_hdmi_timings(&hdmi.ip_data.cfg, p, code);
  415. phy = p->pixel_clock;
  416. hdmi_compute_pll(dssdev, phy, &hdmi.ip_data.pll_data);
  417. hdmi_wp_video_start(&hdmi.ip_data, 0);
  418. /* config the PLL and PHY hdmi_set_pll_pwrfirst */
  419. r = hdmi_pll_program(&hdmi.ip_data);
  420. if (r) {
  421. DSSDBG("Failed to lock PLL\n");
  422. goto err;
  423. }
  424. r = hdmi_phy_init(&hdmi.ip_data);
  425. if (r) {
  426. DSSDBG("Failed to start PHY\n");
  427. goto err;
  428. }
  429. hdmi.ip_data.cfg.cm.mode = hdmi.mode;
  430. hdmi.ip_data.cfg.cm.code = hdmi.code;
  431. hdmi_basic_configure(&hdmi.ip_data);
  432. /* Make selection of HDMI in DSS */
  433. dss_select_hdmi_venc_clk_source(DSS_HDMI_M_PCLK);
  434. /* Select the dispc clock source as PRCM clock, to ensure that it is not
  435. * DSI PLL source as the clock selected by DSI PLL might not be
  436. * sufficient for the resolution selected / that can be changed
  437. * dynamically by user. This can be moved to single location , say
  438. * Boardfile.
  439. */
  440. dss_select_dispc_clk_source(dssdev->clocks.dispc.dispc_fclk_src);
  441. /* bypass TV gamma table */
  442. dispc_enable_gamma_table(0);
  443. /* tv size */
  444. dispc_set_digit_size(dssdev->panel.timings.x_res,
  445. dssdev->panel.timings.y_res);
  446. dispc_mgr_enable(OMAP_DSS_CHANNEL_DIGIT, 1);
  447. hdmi_wp_video_start(&hdmi.ip_data, 1);
  448. return 0;
  449. err:
  450. hdmi_runtime_put();
  451. return -EIO;
  452. }
  453. static void hdmi_power_off(struct omap_dss_device *dssdev)
  454. {
  455. dispc_mgr_enable(OMAP_DSS_CHANNEL_DIGIT, 0);
  456. hdmi_wp_video_start(&hdmi.ip_data, 0);
  457. hdmi_phy_off(&hdmi.ip_data);
  458. hdmi_set_pll_pwr(&hdmi.ip_data, HDMI_PLLPWRCMD_ALLOFF);
  459. hdmi_runtime_put();
  460. hdmi.edid_set = 0;
  461. }
  462. int omapdss_hdmi_display_check_timing(struct omap_dss_device *dssdev,
  463. struct omap_video_timings *timings)
  464. {
  465. struct hdmi_cm cm;
  466. cm = hdmi_get_code(timings);
  467. if (cm.code == -1) {
  468. DSSERR("Invalid timing entered\n");
  469. return -EINVAL;
  470. }
  471. return 0;
  472. }
  473. void omapdss_hdmi_display_set_timing(struct omap_dss_device *dssdev)
  474. {
  475. struct hdmi_cm cm;
  476. hdmi.custom_set = 1;
  477. cm = hdmi_get_code(&dssdev->panel.timings);
  478. hdmi.code = cm.code;
  479. hdmi.mode = cm.mode;
  480. omapdss_hdmi_display_enable(dssdev);
  481. hdmi.custom_set = 0;
  482. }
  483. int omapdss_hdmi_display_enable(struct omap_dss_device *dssdev)
  484. {
  485. int r = 0;
  486. DSSDBG("ENTER hdmi_display_enable\n");
  487. mutex_lock(&hdmi.lock);
  488. if (dssdev->manager == NULL) {
  489. DSSERR("failed to enable display: no manager\n");
  490. r = -ENODEV;
  491. goto err0;
  492. }
  493. r = omap_dss_start_device(dssdev);
  494. if (r) {
  495. DSSERR("failed to start device\n");
  496. goto err0;
  497. }
  498. if (dssdev->platform_enable) {
  499. r = dssdev->platform_enable(dssdev);
  500. if (r) {
  501. DSSERR("failed to enable GPIO's\n");
  502. goto err1;
  503. }
  504. }
  505. r = hdmi_power_on(dssdev);
  506. if (r) {
  507. DSSERR("failed to power on device\n");
  508. goto err2;
  509. }
  510. mutex_unlock(&hdmi.lock);
  511. return 0;
  512. err2:
  513. if (dssdev->platform_disable)
  514. dssdev->platform_disable(dssdev);
  515. err1:
  516. omap_dss_stop_device(dssdev);
  517. err0:
  518. mutex_unlock(&hdmi.lock);
  519. return r;
  520. }
  521. void omapdss_hdmi_display_disable(struct omap_dss_device *dssdev)
  522. {
  523. DSSDBG("Enter hdmi_display_disable\n");
  524. mutex_lock(&hdmi.lock);
  525. hdmi_power_off(dssdev);
  526. if (dssdev->platform_disable)
  527. dssdev->platform_disable(dssdev);
  528. omap_dss_stop_device(dssdev);
  529. mutex_unlock(&hdmi.lock);
  530. }
  531. #if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \
  532. defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE)
  533. static void hdmi_wp_audio_config_format(struct hdmi_ip_data *ip_data,
  534. struct hdmi_audio_format *aud_fmt)
  535. {
  536. u32 r;
  537. DSSDBG("Enter hdmi_wp_audio_config_format\n");
  538. r = hdmi_read_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CFG);
  539. r = FLD_MOD(r, aud_fmt->stereo_channels, 26, 24);
  540. r = FLD_MOD(r, aud_fmt->active_chnnls_msk, 23, 16);
  541. r = FLD_MOD(r, aud_fmt->en_sig_blk_strt_end, 5, 5);
  542. r = FLD_MOD(r, aud_fmt->type, 4, 4);
  543. r = FLD_MOD(r, aud_fmt->justification, 3, 3);
  544. r = FLD_MOD(r, aud_fmt->sample_order, 2, 2);
  545. r = FLD_MOD(r, aud_fmt->samples_per_word, 1, 1);
  546. r = FLD_MOD(r, aud_fmt->sample_size, 0, 0);
  547. hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CFG, r);
  548. }
  549. static void hdmi_wp_audio_config_dma(struct hdmi_ip_data *ip_data,
  550. struct hdmi_audio_dma *aud_dma)
  551. {
  552. u32 r;
  553. DSSDBG("Enter hdmi_wp_audio_config_dma\n");
  554. r = hdmi_read_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CFG2);
  555. r = FLD_MOD(r, aud_dma->transfer_size, 15, 8);
  556. r = FLD_MOD(r, aud_dma->block_size, 7, 0);
  557. hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CFG2, r);
  558. r = hdmi_read_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CTRL);
  559. r = FLD_MOD(r, aud_dma->mode, 9, 9);
  560. r = FLD_MOD(r, aud_dma->fifo_threshold, 8, 0);
  561. hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CTRL, r);
  562. }
  563. static void hdmi_core_audio_config(struct hdmi_ip_data *ip_data,
  564. struct hdmi_core_audio_config *cfg)
  565. {
  566. u32 r;
  567. void __iomem *av_base = hdmi_av_base(ip_data);
  568. /* audio clock recovery parameters */
  569. r = hdmi_read_reg(av_base, HDMI_CORE_AV_ACR_CTRL);
  570. r = FLD_MOD(r, cfg->use_mclk, 2, 2);
  571. r = FLD_MOD(r, cfg->en_acr_pkt, 1, 1);
  572. r = FLD_MOD(r, cfg->cts_mode, 0, 0);
  573. hdmi_write_reg(av_base, HDMI_CORE_AV_ACR_CTRL, r);
  574. REG_FLD_MOD(av_base, HDMI_CORE_AV_N_SVAL1, cfg->n, 7, 0);
  575. REG_FLD_MOD(av_base, HDMI_CORE_AV_N_SVAL2, cfg->n >> 8, 7, 0);
  576. REG_FLD_MOD(av_base, HDMI_CORE_AV_N_SVAL3, cfg->n >> 16, 7, 0);
  577. if (cfg->cts_mode == HDMI_AUDIO_CTS_MODE_SW) {
  578. REG_FLD_MOD(av_base, HDMI_CORE_AV_CTS_SVAL1, cfg->cts, 7, 0);
  579. REG_FLD_MOD(av_base,
  580. HDMI_CORE_AV_CTS_SVAL2, cfg->cts >> 8, 7, 0);
  581. REG_FLD_MOD(av_base,
  582. HDMI_CORE_AV_CTS_SVAL3, cfg->cts >> 16, 7, 0);
  583. } else {
  584. /*
  585. * HDMI IP uses this configuration to divide the MCLK to
  586. * update CTS value.
  587. */
  588. REG_FLD_MOD(av_base,
  589. HDMI_CORE_AV_FREQ_SVAL, cfg->mclk_mode, 2, 0);
  590. /* Configure clock for audio packets */
  591. REG_FLD_MOD(av_base, HDMI_CORE_AV_AUD_PAR_BUSCLK_1,
  592. cfg->aud_par_busclk, 7, 0);
  593. REG_FLD_MOD(av_base, HDMI_CORE_AV_AUD_PAR_BUSCLK_2,
  594. (cfg->aud_par_busclk >> 8), 7, 0);
  595. REG_FLD_MOD(av_base, HDMI_CORE_AV_AUD_PAR_BUSCLK_3,
  596. (cfg->aud_par_busclk >> 16), 7, 0);
  597. }
  598. /* Override of SPDIF sample frequency with value in I2S_CHST4 */
  599. REG_FLD_MOD(av_base, HDMI_CORE_AV_SPDIF_CTRL,
  600. cfg->fs_override, 1, 1);
  601. /* I2S parameters */
  602. REG_FLD_MOD(av_base, HDMI_CORE_AV_I2S_CHST4,
  603. cfg->freq_sample, 3, 0);
  604. r = hdmi_read_reg(av_base, HDMI_CORE_AV_I2S_IN_CTRL);
  605. r = FLD_MOD(r, cfg->i2s_cfg.en_high_bitrate_aud, 7, 7);
  606. r = FLD_MOD(r, cfg->i2s_cfg.sck_edge_mode, 6, 6);
  607. r = FLD_MOD(r, cfg->i2s_cfg.cbit_order, 5, 5);
  608. r = FLD_MOD(r, cfg->i2s_cfg.vbit, 4, 4);
  609. r = FLD_MOD(r, cfg->i2s_cfg.ws_polarity, 3, 3);
  610. r = FLD_MOD(r, cfg->i2s_cfg.justification, 2, 2);
  611. r = FLD_MOD(r, cfg->i2s_cfg.direction, 1, 1);
  612. r = FLD_MOD(r, cfg->i2s_cfg.shift, 0, 0);
  613. hdmi_write_reg(av_base, HDMI_CORE_AV_I2S_IN_CTRL, r);
  614. r = hdmi_read_reg(av_base, HDMI_CORE_AV_I2S_CHST5);
  615. r = FLD_MOD(r, cfg->freq_sample, 7, 4);
  616. r = FLD_MOD(r, cfg->i2s_cfg.word_length, 3, 1);
  617. r = FLD_MOD(r, cfg->i2s_cfg.word_max_length, 0, 0);
  618. hdmi_write_reg(av_base, HDMI_CORE_AV_I2S_CHST5, r);
  619. REG_FLD_MOD(av_base, HDMI_CORE_AV_I2S_IN_LEN,
  620. cfg->i2s_cfg.in_length_bits, 3, 0);
  621. /* Audio channels and mode parameters */
  622. REG_FLD_MOD(av_base, HDMI_CORE_AV_HDMI_CTRL, cfg->layout, 2, 1);
  623. r = hdmi_read_reg(av_base, HDMI_CORE_AV_AUD_MODE);
  624. r = FLD_MOD(r, cfg->i2s_cfg.active_sds, 7, 4);
  625. r = FLD_MOD(r, cfg->en_dsd_audio, 3, 3);
  626. r = FLD_MOD(r, cfg->en_parallel_aud_input, 2, 2);
  627. r = FLD_MOD(r, cfg->en_spdif, 1, 1);
  628. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_MODE, r);
  629. }
  630. static void hdmi_core_audio_infoframe_config(struct hdmi_ip_data *ip_data,
  631. struct hdmi_core_infoframe_audio *info_aud)
  632. {
  633. u8 val;
  634. u8 sum = 0, checksum = 0;
  635. void __iomem *av_base = hdmi_av_base(ip_data);
  636. /*
  637. * Set audio info frame type, version and length as
  638. * described in HDMI 1.4a Section 8.2.2 specification.
  639. * Checksum calculation is defined in Section 5.3.5.
  640. */
  641. hdmi_write_reg(av_base, HDMI_CORE_AV_AUDIO_TYPE, 0x84);
  642. hdmi_write_reg(av_base, HDMI_CORE_AV_AUDIO_VERS, 0x01);
  643. hdmi_write_reg(av_base, HDMI_CORE_AV_AUDIO_LEN, 0x0a);
  644. sum += 0x84 + 0x001 + 0x00a;
  645. val = (info_aud->db1_coding_type << 4)
  646. | (info_aud->db1_channel_count - 1);
  647. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(0), val);
  648. sum += val;
  649. val = (info_aud->db2_sample_freq << 2) | info_aud->db2_sample_size;
  650. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(1), val);
  651. sum += val;
  652. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(2), 0x00);
  653. val = info_aud->db4_channel_alloc;
  654. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(3), val);
  655. sum += val;
  656. val = (info_aud->db5_downmix_inh << 7) | (info_aud->db5_lsv << 3);
  657. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(4), val);
  658. sum += val;
  659. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(5), 0x00);
  660. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(6), 0x00);
  661. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(7), 0x00);
  662. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(8), 0x00);
  663. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(9), 0x00);
  664. checksum = 0x100 - sum;
  665. hdmi_write_reg(av_base,
  666. HDMI_CORE_AV_AUDIO_CHSUM, checksum);
  667. /*
  668. * TODO: Add MPEG and SPD enable and repeat cfg when EDID parsing
  669. * is available.
  670. */
  671. }
  672. static int hdmi_config_audio_acr(struct hdmi_ip_data *ip_data,
  673. u32 sample_freq, u32 *n, u32 *cts)
  674. {
  675. u32 r;
  676. u32 deep_color = 0;
  677. u32 pclk = hdmi.cfg.timings.timings.pixel_clock;
  678. if (n == NULL || cts == NULL)
  679. return -EINVAL;
  680. /*
  681. * Obtain current deep color configuration. This needed
  682. * to calculate the TMDS clock based on the pixel clock.
  683. */
  684. r = REG_GET(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_CFG, 1, 0);
  685. switch (r) {
  686. case 1: /* No deep color selected */
  687. deep_color = 100;
  688. break;
  689. case 2: /* 10-bit deep color selected */
  690. deep_color = 125;
  691. break;
  692. case 3: /* 12-bit deep color selected */
  693. deep_color = 150;
  694. break;
  695. default:
  696. return -EINVAL;
  697. }
  698. switch (sample_freq) {
  699. case 32000:
  700. if ((deep_color == 125) && ((pclk == 54054)
  701. || (pclk == 74250)))
  702. *n = 8192;
  703. else
  704. *n = 4096;
  705. break;
  706. case 44100:
  707. *n = 6272;
  708. break;
  709. case 48000:
  710. if ((deep_color == 125) && ((pclk == 54054)
  711. || (pclk == 74250)))
  712. *n = 8192;
  713. else
  714. *n = 6144;
  715. break;
  716. default:
  717. *n = 0;
  718. return -EINVAL;
  719. }
  720. /* Calculate CTS. See HDMI 1.3a or 1.4a specifications */
  721. *cts = pclk * (*n / 128) * deep_color / (sample_freq / 10);
  722. return 0;
  723. }
  724. static int hdmi_audio_hw_params(struct hdmi_ip_data *ip_data,
  725. struct snd_pcm_substream *substream,
  726. struct snd_pcm_hw_params *params,
  727. struct snd_soc_dai *dai)
  728. {
  729. struct hdmi_audio_format audio_format;
  730. struct hdmi_audio_dma audio_dma;
  731. struct hdmi_core_audio_config core_cfg;
  732. struct hdmi_core_infoframe_audio aud_if_cfg;
  733. int err, n, cts;
  734. enum hdmi_core_audio_sample_freq sample_freq;
  735. switch (params_format(params)) {
  736. case SNDRV_PCM_FORMAT_S16_LE:
  737. core_cfg.i2s_cfg.word_max_length =
  738. HDMI_AUDIO_I2S_MAX_WORD_20BITS;
  739. core_cfg.i2s_cfg.word_length = HDMI_AUDIO_I2S_CHST_WORD_16_BITS;
  740. core_cfg.i2s_cfg.in_length_bits =
  741. HDMI_AUDIO_I2S_INPUT_LENGTH_16;
  742. core_cfg.i2s_cfg.justification = HDMI_AUDIO_JUSTIFY_LEFT;
  743. audio_format.samples_per_word = HDMI_AUDIO_ONEWORD_TWOSAMPLES;
  744. audio_format.sample_size = HDMI_AUDIO_SAMPLE_16BITS;
  745. audio_format.justification = HDMI_AUDIO_JUSTIFY_LEFT;
  746. audio_dma.transfer_size = 0x10;
  747. break;
  748. case SNDRV_PCM_FORMAT_S24_LE:
  749. core_cfg.i2s_cfg.word_max_length =
  750. HDMI_AUDIO_I2S_MAX_WORD_24BITS;
  751. core_cfg.i2s_cfg.word_length = HDMI_AUDIO_I2S_CHST_WORD_24_BITS;
  752. core_cfg.i2s_cfg.in_length_bits =
  753. HDMI_AUDIO_I2S_INPUT_LENGTH_24;
  754. audio_format.samples_per_word = HDMI_AUDIO_ONEWORD_ONESAMPLE;
  755. audio_format.sample_size = HDMI_AUDIO_SAMPLE_24BITS;
  756. audio_format.justification = HDMI_AUDIO_JUSTIFY_RIGHT;
  757. core_cfg.i2s_cfg.justification = HDMI_AUDIO_JUSTIFY_RIGHT;
  758. audio_dma.transfer_size = 0x20;
  759. break;
  760. default:
  761. return -EINVAL;
  762. }
  763. switch (params_rate(params)) {
  764. case 32000:
  765. sample_freq = HDMI_AUDIO_FS_32000;
  766. break;
  767. case 44100:
  768. sample_freq = HDMI_AUDIO_FS_44100;
  769. break;
  770. case 48000:
  771. sample_freq = HDMI_AUDIO_FS_48000;
  772. break;
  773. default:
  774. return -EINVAL;
  775. }
  776. err = hdmi_config_audio_acr(ip_data, params_rate(params), &n, &cts);
  777. if (err < 0)
  778. return err;
  779. /* Audio wrapper config */
  780. audio_format.stereo_channels = HDMI_AUDIO_STEREO_ONECHANNEL;
  781. audio_format.active_chnnls_msk = 0x03;
  782. audio_format.type = HDMI_AUDIO_TYPE_LPCM;
  783. audio_format.sample_order = HDMI_AUDIO_SAMPLE_LEFT_FIRST;
  784. /* Disable start/stop signals of IEC 60958 blocks */
  785. audio_format.en_sig_blk_strt_end = HDMI_AUDIO_BLOCK_SIG_STARTEND_OFF;
  786. audio_dma.block_size = 0xC0;
  787. audio_dma.mode = HDMI_AUDIO_TRANSF_DMA;
  788. audio_dma.fifo_threshold = 0x20; /* in number of samples */
  789. hdmi_wp_audio_config_dma(ip_data, &audio_dma);
  790. hdmi_wp_audio_config_format(ip_data, &audio_format);
  791. /*
  792. * I2S config
  793. */
  794. core_cfg.i2s_cfg.en_high_bitrate_aud = false;
  795. /* Only used with high bitrate audio */
  796. core_cfg.i2s_cfg.cbit_order = false;
  797. /* Serial data and word select should change on sck rising edge */
  798. core_cfg.i2s_cfg.sck_edge_mode = HDMI_AUDIO_I2S_SCK_EDGE_RISING;
  799. core_cfg.i2s_cfg.vbit = HDMI_AUDIO_I2S_VBIT_FOR_PCM;
  800. /* Set I2S word select polarity */
  801. core_cfg.i2s_cfg.ws_polarity = HDMI_AUDIO_I2S_WS_POLARITY_LOW_IS_LEFT;
  802. core_cfg.i2s_cfg.direction = HDMI_AUDIO_I2S_MSB_SHIFTED_FIRST;
  803. /* Set serial data to word select shift. See Phillips spec. */
  804. core_cfg.i2s_cfg.shift = HDMI_AUDIO_I2S_FIRST_BIT_SHIFT;
  805. /* Enable one of the four available serial data channels */
  806. core_cfg.i2s_cfg.active_sds = HDMI_AUDIO_I2S_SD0_EN;
  807. /* Core audio config */
  808. core_cfg.freq_sample = sample_freq;
  809. core_cfg.n = n;
  810. core_cfg.cts = cts;
  811. if (dss_has_feature(FEAT_HDMI_CTS_SWMODE)) {
  812. core_cfg.aud_par_busclk = 0;
  813. core_cfg.cts_mode = HDMI_AUDIO_CTS_MODE_SW;
  814. core_cfg.use_mclk = false;
  815. } else {
  816. core_cfg.aud_par_busclk = (((128 * 31) - 1) << 8);
  817. core_cfg.cts_mode = HDMI_AUDIO_CTS_MODE_HW;
  818. core_cfg.use_mclk = true;
  819. core_cfg.mclk_mode = HDMI_AUDIO_MCLK_128FS;
  820. }
  821. core_cfg.layout = HDMI_AUDIO_LAYOUT_2CH;
  822. core_cfg.en_spdif = false;
  823. /* Use sample frequency from channel status word */
  824. core_cfg.fs_override = true;
  825. /* Enable ACR packets */
  826. core_cfg.en_acr_pkt = true;
  827. /* Disable direct streaming digital audio */
  828. core_cfg.en_dsd_audio = false;
  829. /* Use parallel audio interface */
  830. core_cfg.en_parallel_aud_input = true;
  831. hdmi_core_audio_config(ip_data, &core_cfg);
  832. /*
  833. * Configure packet
  834. * info frame audio see doc CEA861-D page 74
  835. */
  836. aud_if_cfg.db1_coding_type = HDMI_INFOFRAME_AUDIO_DB1CT_FROM_STREAM;
  837. aud_if_cfg.db1_channel_count = 2;
  838. aud_if_cfg.db2_sample_freq = HDMI_INFOFRAME_AUDIO_DB2SF_FROM_STREAM;
  839. aud_if_cfg.db2_sample_size = HDMI_INFOFRAME_AUDIO_DB2SS_FROM_STREAM;
  840. aud_if_cfg.db4_channel_alloc = 0x00;
  841. aud_if_cfg.db5_downmix_inh = false;
  842. aud_if_cfg.db5_lsv = 0;
  843. hdmi_core_audio_infoframe_config(ip_data, &aud_if_cfg);
  844. return 0;
  845. }
  846. static int hdmi_audio_trigger(struct hdmi_ip_data *ip_data,
  847. struct snd_pcm_substream *substream, int cmd,
  848. struct snd_soc_dai *dai)
  849. {
  850. int err = 0;
  851. switch (cmd) {
  852. case SNDRV_PCM_TRIGGER_START:
  853. case SNDRV_PCM_TRIGGER_RESUME:
  854. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  855. REG_FLD_MOD(hdmi_av_base(ip_data),
  856. HDMI_CORE_AV_AUD_MODE, 1, 0, 0);
  857. REG_FLD_MOD(hdmi_wp_base(ip_data),
  858. HDMI_WP_AUDIO_CTRL, 1, 31, 31);
  859. REG_FLD_MOD(hdmi_wp_base(ip_data),
  860. HDMI_WP_AUDIO_CTRL, 1, 30, 30);
  861. break;
  862. case SNDRV_PCM_TRIGGER_STOP:
  863. case SNDRV_PCM_TRIGGER_SUSPEND:
  864. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  865. REG_FLD_MOD(hdmi_av_base(ip_data),
  866. HDMI_CORE_AV_AUD_MODE, 0, 0, 0);
  867. REG_FLD_MOD(hdmi_wp_base(ip_data),
  868. HDMI_WP_AUDIO_CTRL, 0, 30, 30);
  869. REG_FLD_MOD(hdmi_wp_base(ip_data),
  870. HDMI_WP_AUDIO_CTRL, 0, 31, 31);
  871. break;
  872. default:
  873. err = -EINVAL;
  874. }
  875. return err;
  876. }
  877. static int hdmi_audio_startup(struct snd_pcm_substream *substream,
  878. struct snd_soc_dai *dai)
  879. {
  880. if (!hdmi.mode) {
  881. pr_err("Current video settings do not support audio.\n");
  882. return -EIO;
  883. }
  884. return 0;
  885. }
  886. static struct snd_soc_codec_driver hdmi_audio_codec_drv = {
  887. };
  888. static struct snd_soc_dai_ops hdmi_audio_codec_ops = {
  889. .hw_params = hdmi_audio_hw_params,
  890. .trigger = hdmi_audio_trigger,
  891. .startup = hdmi_audio_startup,
  892. };
  893. static struct snd_soc_dai_driver hdmi_codec_dai_drv = {
  894. .name = "hdmi-audio-codec",
  895. .playback = {
  896. .channels_min = 2,
  897. .channels_max = 2,
  898. .rates = SNDRV_PCM_RATE_32000 |
  899. SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000,
  900. .formats = SNDRV_PCM_FMTBIT_S16_LE |
  901. SNDRV_PCM_FMTBIT_S24_LE,
  902. },
  903. .ops = &hdmi_audio_codec_ops,
  904. };
  905. #endif
  906. static int hdmi_get_clocks(struct platform_device *pdev)
  907. {
  908. struct clk *clk;
  909. clk = clk_get(&pdev->dev, "sys_clk");
  910. if (IS_ERR(clk)) {
  911. DSSERR("can't get sys_clk\n");
  912. return PTR_ERR(clk);
  913. }
  914. hdmi.sys_clk = clk;
  915. return 0;
  916. }
  917. static void hdmi_put_clocks(void)
  918. {
  919. if (hdmi.sys_clk)
  920. clk_put(hdmi.sys_clk);
  921. }
  922. /* HDMI HW IP initialisation */
  923. static int omapdss_hdmihw_probe(struct platform_device *pdev)
  924. {
  925. struct resource *hdmi_mem;
  926. int r;
  927. hdmi.pdata = pdev->dev.platform_data;
  928. hdmi.pdev = pdev;
  929. mutex_init(&hdmi.lock);
  930. hdmi_mem = platform_get_resource(hdmi.pdev, IORESOURCE_MEM, 0);
  931. if (!hdmi_mem) {
  932. DSSERR("can't get IORESOURCE_MEM HDMI\n");
  933. return -EINVAL;
  934. }
  935. /* Base address taken from platform */
  936. hdmi.ip_data.base_wp = ioremap(hdmi_mem->start,
  937. resource_size(hdmi_mem));
  938. if (!hdmi.ip_data.base_wp) {
  939. DSSERR("can't ioremap WP\n");
  940. return -ENOMEM;
  941. }
  942. r = hdmi_get_clocks(pdev);
  943. if (r) {
  944. iounmap(hdmi.ip_data.base_wp);
  945. return r;
  946. }
  947. pm_runtime_enable(&pdev->dev);
  948. hdmi.ip_data.core_sys_offset = HDMI_CORE_SYS;
  949. hdmi.ip_data.core_av_offset = HDMI_CORE_AV;
  950. hdmi.ip_data.pll_offset = HDMI_PLLCTRL;
  951. hdmi.ip_data.phy_offset = HDMI_PHY;
  952. hdmi_panel_init();
  953. #if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \
  954. defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE)
  955. /* Register ASoC codec DAI */
  956. r = snd_soc_register_codec(&pdev->dev, &hdmi_audio_codec_drv,
  957. &hdmi_codec_dai_drv, 1);
  958. if (r) {
  959. DSSERR("can't register ASoC HDMI audio codec\n");
  960. return r;
  961. }
  962. #endif
  963. return 0;
  964. }
  965. static int omapdss_hdmihw_remove(struct platform_device *pdev)
  966. {
  967. hdmi_panel_exit();
  968. #if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \
  969. defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE)
  970. snd_soc_unregister_codec(&pdev->dev);
  971. #endif
  972. pm_runtime_disable(&pdev->dev);
  973. hdmi_put_clocks();
  974. iounmap(hdmi.ip_data.base_wp);
  975. return 0;
  976. }
  977. static int hdmi_runtime_suspend(struct device *dev)
  978. {
  979. clk_disable(hdmi.sys_clk);
  980. dispc_runtime_put();
  981. dss_runtime_put();
  982. return 0;
  983. }
  984. static int hdmi_runtime_resume(struct device *dev)
  985. {
  986. int r;
  987. r = dss_runtime_get();
  988. if (r < 0)
  989. goto err_get_dss;
  990. r = dispc_runtime_get();
  991. if (r < 0)
  992. goto err_get_dispc;
  993. clk_enable(hdmi.sys_clk);
  994. return 0;
  995. err_get_dispc:
  996. dss_runtime_put();
  997. err_get_dss:
  998. return r;
  999. }
  1000. static const struct dev_pm_ops hdmi_pm_ops = {
  1001. .runtime_suspend = hdmi_runtime_suspend,
  1002. .runtime_resume = hdmi_runtime_resume,
  1003. };
  1004. static struct platform_driver omapdss_hdmihw_driver = {
  1005. .probe = omapdss_hdmihw_probe,
  1006. .remove = omapdss_hdmihw_remove,
  1007. .driver = {
  1008. .name = "omapdss_hdmi",
  1009. .owner = THIS_MODULE,
  1010. .pm = &hdmi_pm_ops,
  1011. },
  1012. };
  1013. int hdmi_init_platform_driver(void)
  1014. {
  1015. return platform_driver_register(&omapdss_hdmihw_driver);
  1016. }
  1017. void hdmi_uninit_platform_driver(void)
  1018. {
  1019. return platform_driver_unregister(&omapdss_hdmihw_driver);
  1020. }