exynos_hdmi.c 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152
  1. /*
  2. * Copyright (C) 2011 Samsung Electronics Co.Ltd
  3. * Authors:
  4. * Seung-Woo Kim <sw0312.kim@samsung.com>
  5. * Inki Dae <inki.dae@samsung.com>
  6. * Joonyoung Shim <jy0922.shim@samsung.com>
  7. *
  8. * Based on drivers/media/video/s5p-tv/hdmi_drv.c
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License as published by the
  12. * Free Software Foundation; either version 2 of the License, or (at your
  13. * option) any later version.
  14. *
  15. */
  16. #include <drm/drmP.h>
  17. #include <drm/drm_edid.h>
  18. #include <drm/drm_crtc_helper.h>
  19. #include "regs-hdmi.h"
  20. #include <linux/kernel.h>
  21. #include <linux/spinlock.h>
  22. #include <linux/wait.h>
  23. #include <linux/i2c.h>
  24. #include <linux/module.h>
  25. #include <linux/platform_device.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/irq.h>
  28. #include <linux/delay.h>
  29. #include <linux/pm_runtime.h>
  30. #include <linux/clk.h>
  31. #include <linux/regulator/consumer.h>
  32. #include <linux/io.h>
  33. #include <linux/of_gpio.h>
  34. #include <drm/exynos_drm.h>
  35. #include "exynos_drm_drv.h"
  36. #include "exynos_drm_hdmi.h"
  37. #include "exynos_hdmi.h"
  38. #include <linux/gpio.h>
  39. #include <media/s5p_hdmi.h>
  40. #define MAX_WIDTH 1920
  41. #define MAX_HEIGHT 1080
  42. #define get_hdmi_context(dev) platform_get_drvdata(to_platform_device(dev))
  43. /* AVI header and aspect ratio */
  44. #define HDMI_AVI_VERSION 0x02
  45. #define HDMI_AVI_LENGTH 0x0D
  46. #define AVI_PIC_ASPECT_RATIO_16_9 (2 << 4)
  47. #define AVI_SAME_AS_PIC_ASPECT_RATIO 8
  48. /* AUI header info */
  49. #define HDMI_AUI_VERSION 0x01
  50. #define HDMI_AUI_LENGTH 0x0A
  51. /* HDMI infoframe to configure HDMI out packet header, AUI and AVI */
  52. enum HDMI_PACKET_TYPE {
  53. /* refer to Table 5-8 Packet Type in HDMI specification v1.4a */
  54. /* InfoFrame packet type */
  55. HDMI_PACKET_TYPE_INFOFRAME = 0x80,
  56. /* Vendor-Specific InfoFrame */
  57. HDMI_PACKET_TYPE_VSI = HDMI_PACKET_TYPE_INFOFRAME + 1,
  58. /* Auxiliary Video information InfoFrame */
  59. HDMI_PACKET_TYPE_AVI = HDMI_PACKET_TYPE_INFOFRAME + 2,
  60. /* Audio information InfoFrame */
  61. HDMI_PACKET_TYPE_AUI = HDMI_PACKET_TYPE_INFOFRAME + 4
  62. };
  63. enum hdmi_type {
  64. HDMI_TYPE13,
  65. HDMI_TYPE14,
  66. };
  67. struct hdmi_resources {
  68. struct clk *hdmi;
  69. struct clk *sclk_hdmi;
  70. struct clk *sclk_pixel;
  71. struct clk *sclk_hdmiphy;
  72. struct clk *hdmiphy;
  73. struct clk *mout_hdmi;
  74. struct regulator_bulk_data *regul_bulk;
  75. int regul_count;
  76. };
  77. struct hdmi_tg_regs {
  78. u8 cmd[1];
  79. u8 h_fsz[2];
  80. u8 hact_st[2];
  81. u8 hact_sz[2];
  82. u8 v_fsz[2];
  83. u8 vsync[2];
  84. u8 vsync2[2];
  85. u8 vact_st[2];
  86. u8 vact_sz[2];
  87. u8 field_chg[2];
  88. u8 vact_st2[2];
  89. u8 vact_st3[2];
  90. u8 vact_st4[2];
  91. u8 vsync_top_hdmi[2];
  92. u8 vsync_bot_hdmi[2];
  93. u8 field_top_hdmi[2];
  94. u8 field_bot_hdmi[2];
  95. u8 tg_3d[1];
  96. };
  97. struct hdmi_v13_core_regs {
  98. u8 h_blank[2];
  99. u8 v_blank[3];
  100. u8 h_v_line[3];
  101. u8 vsync_pol[1];
  102. u8 int_pro_mode[1];
  103. u8 v_blank_f[3];
  104. u8 h_sync_gen[3];
  105. u8 v_sync_gen1[3];
  106. u8 v_sync_gen2[3];
  107. u8 v_sync_gen3[3];
  108. };
  109. struct hdmi_v14_core_regs {
  110. u8 h_blank[2];
  111. u8 v2_blank[2];
  112. u8 v1_blank[2];
  113. u8 v_line[2];
  114. u8 h_line[2];
  115. u8 hsync_pol[1];
  116. u8 vsync_pol[1];
  117. u8 int_pro_mode[1];
  118. u8 v_blank_f0[2];
  119. u8 v_blank_f1[2];
  120. u8 h_sync_start[2];
  121. u8 h_sync_end[2];
  122. u8 v_sync_line_bef_2[2];
  123. u8 v_sync_line_bef_1[2];
  124. u8 v_sync_line_aft_2[2];
  125. u8 v_sync_line_aft_1[2];
  126. u8 v_sync_line_aft_pxl_2[2];
  127. u8 v_sync_line_aft_pxl_1[2];
  128. u8 v_blank_f2[2]; /* for 3D mode */
  129. u8 v_blank_f3[2]; /* for 3D mode */
  130. u8 v_blank_f4[2]; /* for 3D mode */
  131. u8 v_blank_f5[2]; /* for 3D mode */
  132. u8 v_sync_line_aft_3[2];
  133. u8 v_sync_line_aft_4[2];
  134. u8 v_sync_line_aft_5[2];
  135. u8 v_sync_line_aft_6[2];
  136. u8 v_sync_line_aft_pxl_3[2];
  137. u8 v_sync_line_aft_pxl_4[2];
  138. u8 v_sync_line_aft_pxl_5[2];
  139. u8 v_sync_line_aft_pxl_6[2];
  140. u8 vact_space_1[2];
  141. u8 vact_space_2[2];
  142. u8 vact_space_3[2];
  143. u8 vact_space_4[2];
  144. u8 vact_space_5[2];
  145. u8 vact_space_6[2];
  146. };
  147. struct hdmi_v13_conf {
  148. struct hdmi_v13_core_regs core;
  149. struct hdmi_tg_regs tg;
  150. };
  151. struct hdmi_v14_conf {
  152. struct hdmi_v14_core_regs core;
  153. struct hdmi_tg_regs tg;
  154. };
  155. struct hdmi_conf_regs {
  156. int pixel_clock;
  157. int cea_video_id;
  158. union {
  159. struct hdmi_v13_conf v13_conf;
  160. struct hdmi_v14_conf v14_conf;
  161. } conf;
  162. };
  163. struct hdmi_context {
  164. struct device *dev;
  165. struct drm_device *drm_dev;
  166. bool hpd;
  167. bool powered;
  168. bool dvi_mode;
  169. struct mutex hdmi_mutex;
  170. void __iomem *regs;
  171. void *parent_ctx;
  172. int irq;
  173. struct i2c_client *ddc_port;
  174. struct i2c_client *hdmiphy_port;
  175. /* current hdmiphy conf regs */
  176. struct hdmi_conf_regs mode_conf;
  177. struct hdmi_resources res;
  178. int hpd_gpio;
  179. enum hdmi_type type;
  180. };
  181. struct hdmiphy_config {
  182. int pixel_clock;
  183. u8 conf[32];
  184. };
  185. /* list of phy config settings */
  186. static const struct hdmiphy_config hdmiphy_v13_configs[] = {
  187. {
  188. .pixel_clock = 27000000,
  189. .conf = {
  190. 0x01, 0x05, 0x00, 0xD8, 0x10, 0x1C, 0x30, 0x40,
  191. 0x6B, 0x10, 0x02, 0x51, 0xDF, 0xF2, 0x54, 0x87,
  192. 0x84, 0x00, 0x30, 0x38, 0x00, 0x08, 0x10, 0xE0,
  193. 0x22, 0x40, 0xE3, 0x26, 0x00, 0x00, 0x00, 0x00,
  194. },
  195. },
  196. {
  197. .pixel_clock = 27027000,
  198. .conf = {
  199. 0x01, 0x05, 0x00, 0xD4, 0x10, 0x9C, 0x09, 0x64,
  200. 0x6B, 0x10, 0x02, 0x51, 0xDF, 0xF2, 0x54, 0x87,
  201. 0x84, 0x00, 0x30, 0x38, 0x00, 0x08, 0x10, 0xE0,
  202. 0x22, 0x40, 0xE3, 0x26, 0x00, 0x00, 0x00, 0x00,
  203. },
  204. },
  205. {
  206. .pixel_clock = 74176000,
  207. .conf = {
  208. 0x01, 0x05, 0x00, 0xD8, 0x10, 0x9C, 0xef, 0x5B,
  209. 0x6D, 0x10, 0x01, 0x51, 0xef, 0xF3, 0x54, 0xb9,
  210. 0x84, 0x00, 0x30, 0x38, 0x00, 0x08, 0x10, 0xE0,
  211. 0x22, 0x40, 0xa5, 0x26, 0x01, 0x00, 0x00, 0x00,
  212. },
  213. },
  214. {
  215. .pixel_clock = 74250000,
  216. .conf = {
  217. 0x01, 0x05, 0x00, 0xd8, 0x10, 0x9c, 0xf8, 0x40,
  218. 0x6a, 0x10, 0x01, 0x51, 0xff, 0xf1, 0x54, 0xba,
  219. 0x84, 0x00, 0x10, 0x38, 0x00, 0x08, 0x10, 0xe0,
  220. 0x22, 0x40, 0xa4, 0x26, 0x01, 0x00, 0x00, 0x00,
  221. },
  222. },
  223. {
  224. .pixel_clock = 148500000,
  225. .conf = {
  226. 0x01, 0x05, 0x00, 0xD8, 0x10, 0x9C, 0xf8, 0x40,
  227. 0x6A, 0x18, 0x00, 0x51, 0xff, 0xF1, 0x54, 0xba,
  228. 0x84, 0x00, 0x10, 0x38, 0x00, 0x08, 0x10, 0xE0,
  229. 0x22, 0x40, 0xa4, 0x26, 0x02, 0x00, 0x00, 0x00,
  230. },
  231. },
  232. };
  233. static const struct hdmiphy_config hdmiphy_v14_configs[] = {
  234. {
  235. .pixel_clock = 25200000,
  236. .conf = {
  237. 0x01, 0x51, 0x2A, 0x75, 0x40, 0x01, 0x00, 0x08,
  238. 0x82, 0x80, 0xfc, 0xd8, 0x45, 0xa0, 0xac, 0x80,
  239. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  240. 0x54, 0xf4, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  241. },
  242. },
  243. {
  244. .pixel_clock = 27000000,
  245. .conf = {
  246. 0x01, 0xd1, 0x22, 0x51, 0x40, 0x08, 0xfc, 0x20,
  247. 0x98, 0xa0, 0xcb, 0xd8, 0x45, 0xa0, 0xac, 0x80,
  248. 0x06, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  249. 0x54, 0xe4, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  250. },
  251. },
  252. {
  253. .pixel_clock = 27027000,
  254. .conf = {
  255. 0x01, 0xd1, 0x2d, 0x72, 0x40, 0x64, 0x12, 0x08,
  256. 0x43, 0xa0, 0x0e, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  257. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  258. 0x54, 0xe3, 0x24, 0x00, 0x00, 0x00, 0x01, 0x00,
  259. },
  260. },
  261. {
  262. .pixel_clock = 36000000,
  263. .conf = {
  264. 0x01, 0x51, 0x2d, 0x55, 0x40, 0x01, 0x00, 0x08,
  265. 0x82, 0x80, 0x0e, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  266. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  267. 0x54, 0xab, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  268. },
  269. },
  270. {
  271. .pixel_clock = 40000000,
  272. .conf = {
  273. 0x01, 0x51, 0x32, 0x55, 0x40, 0x01, 0x00, 0x08,
  274. 0x82, 0x80, 0x2c, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  275. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  276. 0x54, 0x9a, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  277. },
  278. },
  279. {
  280. .pixel_clock = 65000000,
  281. .conf = {
  282. 0x01, 0xd1, 0x36, 0x34, 0x40, 0x1e, 0x0a, 0x08,
  283. 0x82, 0xa0, 0x45, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  284. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  285. 0x54, 0xbd, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  286. },
  287. },
  288. {
  289. .pixel_clock = 74176000,
  290. .conf = {
  291. 0x01, 0xd1, 0x3e, 0x35, 0x40, 0x5b, 0xde, 0x08,
  292. 0x82, 0xa0, 0x73, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  293. 0x56, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  294. 0x54, 0xa6, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  295. },
  296. },
  297. {
  298. .pixel_clock = 74250000,
  299. .conf = {
  300. 0x01, 0xd1, 0x1f, 0x10, 0x40, 0x40, 0xf8, 0x08,
  301. 0x81, 0xa0, 0xba, 0xd8, 0x45, 0xa0, 0xac, 0x80,
  302. 0x3c, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  303. 0x54, 0xa5, 0x24, 0x01, 0x00, 0x00, 0x01, 0x00,
  304. },
  305. },
  306. {
  307. .pixel_clock = 83500000,
  308. .conf = {
  309. 0x01, 0xd1, 0x23, 0x11, 0x40, 0x0c, 0xfb, 0x08,
  310. 0x85, 0xa0, 0xd1, 0xd8, 0x45, 0xa0, 0xac, 0x80,
  311. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  312. 0x54, 0x93, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  313. },
  314. },
  315. {
  316. .pixel_clock = 106500000,
  317. .conf = {
  318. 0x01, 0xd1, 0x2c, 0x12, 0x40, 0x0c, 0x09, 0x08,
  319. 0x84, 0xa0, 0x0a, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  320. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  321. 0x54, 0x73, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  322. },
  323. },
  324. {
  325. .pixel_clock = 108000000,
  326. .conf = {
  327. 0x01, 0x51, 0x2d, 0x15, 0x40, 0x01, 0x00, 0x08,
  328. 0x82, 0x80, 0x0e, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  329. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  330. 0x54, 0xc7, 0x25, 0x03, 0x00, 0x00, 0x01, 0x80,
  331. },
  332. },
  333. {
  334. .pixel_clock = 146250000,
  335. .conf = {
  336. 0x01, 0xd1, 0x3d, 0x15, 0x40, 0x18, 0xfd, 0x08,
  337. 0x83, 0xa0, 0x6e, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  338. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  339. 0x54, 0x50, 0x25, 0x03, 0x00, 0x00, 0x01, 0x80,
  340. },
  341. },
  342. {
  343. .pixel_clock = 148500000,
  344. .conf = {
  345. 0x01, 0xd1, 0x1f, 0x00, 0x40, 0x40, 0xf8, 0x08,
  346. 0x81, 0xa0, 0xba, 0xd8, 0x45, 0xa0, 0xac, 0x80,
  347. 0x3c, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  348. 0x54, 0x4b, 0x25, 0x03, 0x00, 0x00, 0x01, 0x00,
  349. },
  350. },
  351. };
  352. struct hdmi_infoframe {
  353. enum HDMI_PACKET_TYPE type;
  354. u8 ver;
  355. u8 len;
  356. };
  357. static inline u32 hdmi_reg_read(struct hdmi_context *hdata, u32 reg_id)
  358. {
  359. return readl(hdata->regs + reg_id);
  360. }
  361. static inline void hdmi_reg_writeb(struct hdmi_context *hdata,
  362. u32 reg_id, u8 value)
  363. {
  364. writeb(value, hdata->regs + reg_id);
  365. }
  366. static inline void hdmi_reg_writemask(struct hdmi_context *hdata,
  367. u32 reg_id, u32 value, u32 mask)
  368. {
  369. u32 old = readl(hdata->regs + reg_id);
  370. value = (value & mask) | (old & ~mask);
  371. writel(value, hdata->regs + reg_id);
  372. }
  373. static void hdmi_v13_regs_dump(struct hdmi_context *hdata, char *prefix)
  374. {
  375. #define DUMPREG(reg_id) \
  376. DRM_DEBUG_KMS("%s:" #reg_id " = %08x\n", prefix, \
  377. readl(hdata->regs + reg_id))
  378. DRM_DEBUG_KMS("%s: ---- CONTROL REGISTERS ----\n", prefix);
  379. DUMPREG(HDMI_INTC_FLAG);
  380. DUMPREG(HDMI_INTC_CON);
  381. DUMPREG(HDMI_HPD_STATUS);
  382. DUMPREG(HDMI_V13_PHY_RSTOUT);
  383. DUMPREG(HDMI_V13_PHY_VPLL);
  384. DUMPREG(HDMI_V13_PHY_CMU);
  385. DUMPREG(HDMI_V13_CORE_RSTOUT);
  386. DRM_DEBUG_KMS("%s: ---- CORE REGISTERS ----\n", prefix);
  387. DUMPREG(HDMI_CON_0);
  388. DUMPREG(HDMI_CON_1);
  389. DUMPREG(HDMI_CON_2);
  390. DUMPREG(HDMI_SYS_STATUS);
  391. DUMPREG(HDMI_V13_PHY_STATUS);
  392. DUMPREG(HDMI_STATUS_EN);
  393. DUMPREG(HDMI_HPD);
  394. DUMPREG(HDMI_MODE_SEL);
  395. DUMPREG(HDMI_V13_HPD_GEN);
  396. DUMPREG(HDMI_V13_DC_CONTROL);
  397. DUMPREG(HDMI_V13_VIDEO_PATTERN_GEN);
  398. DRM_DEBUG_KMS("%s: ---- CORE SYNC REGISTERS ----\n", prefix);
  399. DUMPREG(HDMI_H_BLANK_0);
  400. DUMPREG(HDMI_H_BLANK_1);
  401. DUMPREG(HDMI_V13_V_BLANK_0);
  402. DUMPREG(HDMI_V13_V_BLANK_1);
  403. DUMPREG(HDMI_V13_V_BLANK_2);
  404. DUMPREG(HDMI_V13_H_V_LINE_0);
  405. DUMPREG(HDMI_V13_H_V_LINE_1);
  406. DUMPREG(HDMI_V13_H_V_LINE_2);
  407. DUMPREG(HDMI_VSYNC_POL);
  408. DUMPREG(HDMI_INT_PRO_MODE);
  409. DUMPREG(HDMI_V13_V_BLANK_F_0);
  410. DUMPREG(HDMI_V13_V_BLANK_F_1);
  411. DUMPREG(HDMI_V13_V_BLANK_F_2);
  412. DUMPREG(HDMI_V13_H_SYNC_GEN_0);
  413. DUMPREG(HDMI_V13_H_SYNC_GEN_1);
  414. DUMPREG(HDMI_V13_H_SYNC_GEN_2);
  415. DUMPREG(HDMI_V13_V_SYNC_GEN_1_0);
  416. DUMPREG(HDMI_V13_V_SYNC_GEN_1_1);
  417. DUMPREG(HDMI_V13_V_SYNC_GEN_1_2);
  418. DUMPREG(HDMI_V13_V_SYNC_GEN_2_0);
  419. DUMPREG(HDMI_V13_V_SYNC_GEN_2_1);
  420. DUMPREG(HDMI_V13_V_SYNC_GEN_2_2);
  421. DUMPREG(HDMI_V13_V_SYNC_GEN_3_0);
  422. DUMPREG(HDMI_V13_V_SYNC_GEN_3_1);
  423. DUMPREG(HDMI_V13_V_SYNC_GEN_3_2);
  424. DRM_DEBUG_KMS("%s: ---- TG REGISTERS ----\n", prefix);
  425. DUMPREG(HDMI_TG_CMD);
  426. DUMPREG(HDMI_TG_H_FSZ_L);
  427. DUMPREG(HDMI_TG_H_FSZ_H);
  428. DUMPREG(HDMI_TG_HACT_ST_L);
  429. DUMPREG(HDMI_TG_HACT_ST_H);
  430. DUMPREG(HDMI_TG_HACT_SZ_L);
  431. DUMPREG(HDMI_TG_HACT_SZ_H);
  432. DUMPREG(HDMI_TG_V_FSZ_L);
  433. DUMPREG(HDMI_TG_V_FSZ_H);
  434. DUMPREG(HDMI_TG_VSYNC_L);
  435. DUMPREG(HDMI_TG_VSYNC_H);
  436. DUMPREG(HDMI_TG_VSYNC2_L);
  437. DUMPREG(HDMI_TG_VSYNC2_H);
  438. DUMPREG(HDMI_TG_VACT_ST_L);
  439. DUMPREG(HDMI_TG_VACT_ST_H);
  440. DUMPREG(HDMI_TG_VACT_SZ_L);
  441. DUMPREG(HDMI_TG_VACT_SZ_H);
  442. DUMPREG(HDMI_TG_FIELD_CHG_L);
  443. DUMPREG(HDMI_TG_FIELD_CHG_H);
  444. DUMPREG(HDMI_TG_VACT_ST2_L);
  445. DUMPREG(HDMI_TG_VACT_ST2_H);
  446. DUMPREG(HDMI_TG_VSYNC_TOP_HDMI_L);
  447. DUMPREG(HDMI_TG_VSYNC_TOP_HDMI_H);
  448. DUMPREG(HDMI_TG_VSYNC_BOT_HDMI_L);
  449. DUMPREG(HDMI_TG_VSYNC_BOT_HDMI_H);
  450. DUMPREG(HDMI_TG_FIELD_TOP_HDMI_L);
  451. DUMPREG(HDMI_TG_FIELD_TOP_HDMI_H);
  452. DUMPREG(HDMI_TG_FIELD_BOT_HDMI_L);
  453. DUMPREG(HDMI_TG_FIELD_BOT_HDMI_H);
  454. #undef DUMPREG
  455. }
  456. static void hdmi_v14_regs_dump(struct hdmi_context *hdata, char *prefix)
  457. {
  458. int i;
  459. #define DUMPREG(reg_id) \
  460. DRM_DEBUG_KMS("%s:" #reg_id " = %08x\n", prefix, \
  461. readl(hdata->regs + reg_id))
  462. DRM_DEBUG_KMS("%s: ---- CONTROL REGISTERS ----\n", prefix);
  463. DUMPREG(HDMI_INTC_CON);
  464. DUMPREG(HDMI_INTC_FLAG);
  465. DUMPREG(HDMI_HPD_STATUS);
  466. DUMPREG(HDMI_INTC_CON_1);
  467. DUMPREG(HDMI_INTC_FLAG_1);
  468. DUMPREG(HDMI_PHY_STATUS_0);
  469. DUMPREG(HDMI_PHY_STATUS_PLL);
  470. DUMPREG(HDMI_PHY_CON_0);
  471. DUMPREG(HDMI_PHY_RSTOUT);
  472. DUMPREG(HDMI_PHY_VPLL);
  473. DUMPREG(HDMI_PHY_CMU);
  474. DUMPREG(HDMI_CORE_RSTOUT);
  475. DRM_DEBUG_KMS("%s: ---- CORE REGISTERS ----\n", prefix);
  476. DUMPREG(HDMI_CON_0);
  477. DUMPREG(HDMI_CON_1);
  478. DUMPREG(HDMI_CON_2);
  479. DUMPREG(HDMI_SYS_STATUS);
  480. DUMPREG(HDMI_PHY_STATUS_0);
  481. DUMPREG(HDMI_STATUS_EN);
  482. DUMPREG(HDMI_HPD);
  483. DUMPREG(HDMI_MODE_SEL);
  484. DUMPREG(HDMI_ENC_EN);
  485. DUMPREG(HDMI_DC_CONTROL);
  486. DUMPREG(HDMI_VIDEO_PATTERN_GEN);
  487. DRM_DEBUG_KMS("%s: ---- CORE SYNC REGISTERS ----\n", prefix);
  488. DUMPREG(HDMI_H_BLANK_0);
  489. DUMPREG(HDMI_H_BLANK_1);
  490. DUMPREG(HDMI_V2_BLANK_0);
  491. DUMPREG(HDMI_V2_BLANK_1);
  492. DUMPREG(HDMI_V1_BLANK_0);
  493. DUMPREG(HDMI_V1_BLANK_1);
  494. DUMPREG(HDMI_V_LINE_0);
  495. DUMPREG(HDMI_V_LINE_1);
  496. DUMPREG(HDMI_H_LINE_0);
  497. DUMPREG(HDMI_H_LINE_1);
  498. DUMPREG(HDMI_HSYNC_POL);
  499. DUMPREG(HDMI_VSYNC_POL);
  500. DUMPREG(HDMI_INT_PRO_MODE);
  501. DUMPREG(HDMI_V_BLANK_F0_0);
  502. DUMPREG(HDMI_V_BLANK_F0_1);
  503. DUMPREG(HDMI_V_BLANK_F1_0);
  504. DUMPREG(HDMI_V_BLANK_F1_1);
  505. DUMPREG(HDMI_H_SYNC_START_0);
  506. DUMPREG(HDMI_H_SYNC_START_1);
  507. DUMPREG(HDMI_H_SYNC_END_0);
  508. DUMPREG(HDMI_H_SYNC_END_1);
  509. DUMPREG(HDMI_V_SYNC_LINE_BEF_2_0);
  510. DUMPREG(HDMI_V_SYNC_LINE_BEF_2_1);
  511. DUMPREG(HDMI_V_SYNC_LINE_BEF_1_0);
  512. DUMPREG(HDMI_V_SYNC_LINE_BEF_1_1);
  513. DUMPREG(HDMI_V_SYNC_LINE_AFT_2_0);
  514. DUMPREG(HDMI_V_SYNC_LINE_AFT_2_1);
  515. DUMPREG(HDMI_V_SYNC_LINE_AFT_1_0);
  516. DUMPREG(HDMI_V_SYNC_LINE_AFT_1_1);
  517. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_2_0);
  518. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_2_1);
  519. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_1_0);
  520. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_1_1);
  521. DUMPREG(HDMI_V_BLANK_F2_0);
  522. DUMPREG(HDMI_V_BLANK_F2_1);
  523. DUMPREG(HDMI_V_BLANK_F3_0);
  524. DUMPREG(HDMI_V_BLANK_F3_1);
  525. DUMPREG(HDMI_V_BLANK_F4_0);
  526. DUMPREG(HDMI_V_BLANK_F4_1);
  527. DUMPREG(HDMI_V_BLANK_F5_0);
  528. DUMPREG(HDMI_V_BLANK_F5_1);
  529. DUMPREG(HDMI_V_SYNC_LINE_AFT_3_0);
  530. DUMPREG(HDMI_V_SYNC_LINE_AFT_3_1);
  531. DUMPREG(HDMI_V_SYNC_LINE_AFT_4_0);
  532. DUMPREG(HDMI_V_SYNC_LINE_AFT_4_1);
  533. DUMPREG(HDMI_V_SYNC_LINE_AFT_5_0);
  534. DUMPREG(HDMI_V_SYNC_LINE_AFT_5_1);
  535. DUMPREG(HDMI_V_SYNC_LINE_AFT_6_0);
  536. DUMPREG(HDMI_V_SYNC_LINE_AFT_6_1);
  537. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_3_0);
  538. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_3_1);
  539. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_4_0);
  540. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_4_1);
  541. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_5_0);
  542. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_5_1);
  543. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_6_0);
  544. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_6_1);
  545. DUMPREG(HDMI_VACT_SPACE_1_0);
  546. DUMPREG(HDMI_VACT_SPACE_1_1);
  547. DUMPREG(HDMI_VACT_SPACE_2_0);
  548. DUMPREG(HDMI_VACT_SPACE_2_1);
  549. DUMPREG(HDMI_VACT_SPACE_3_0);
  550. DUMPREG(HDMI_VACT_SPACE_3_1);
  551. DUMPREG(HDMI_VACT_SPACE_4_0);
  552. DUMPREG(HDMI_VACT_SPACE_4_1);
  553. DUMPREG(HDMI_VACT_SPACE_5_0);
  554. DUMPREG(HDMI_VACT_SPACE_5_1);
  555. DUMPREG(HDMI_VACT_SPACE_6_0);
  556. DUMPREG(HDMI_VACT_SPACE_6_1);
  557. DRM_DEBUG_KMS("%s: ---- TG REGISTERS ----\n", prefix);
  558. DUMPREG(HDMI_TG_CMD);
  559. DUMPREG(HDMI_TG_H_FSZ_L);
  560. DUMPREG(HDMI_TG_H_FSZ_H);
  561. DUMPREG(HDMI_TG_HACT_ST_L);
  562. DUMPREG(HDMI_TG_HACT_ST_H);
  563. DUMPREG(HDMI_TG_HACT_SZ_L);
  564. DUMPREG(HDMI_TG_HACT_SZ_H);
  565. DUMPREG(HDMI_TG_V_FSZ_L);
  566. DUMPREG(HDMI_TG_V_FSZ_H);
  567. DUMPREG(HDMI_TG_VSYNC_L);
  568. DUMPREG(HDMI_TG_VSYNC_H);
  569. DUMPREG(HDMI_TG_VSYNC2_L);
  570. DUMPREG(HDMI_TG_VSYNC2_H);
  571. DUMPREG(HDMI_TG_VACT_ST_L);
  572. DUMPREG(HDMI_TG_VACT_ST_H);
  573. DUMPREG(HDMI_TG_VACT_SZ_L);
  574. DUMPREG(HDMI_TG_VACT_SZ_H);
  575. DUMPREG(HDMI_TG_FIELD_CHG_L);
  576. DUMPREG(HDMI_TG_FIELD_CHG_H);
  577. DUMPREG(HDMI_TG_VACT_ST2_L);
  578. DUMPREG(HDMI_TG_VACT_ST2_H);
  579. DUMPREG(HDMI_TG_VACT_ST3_L);
  580. DUMPREG(HDMI_TG_VACT_ST3_H);
  581. DUMPREG(HDMI_TG_VACT_ST4_L);
  582. DUMPREG(HDMI_TG_VACT_ST4_H);
  583. DUMPREG(HDMI_TG_VSYNC_TOP_HDMI_L);
  584. DUMPREG(HDMI_TG_VSYNC_TOP_HDMI_H);
  585. DUMPREG(HDMI_TG_VSYNC_BOT_HDMI_L);
  586. DUMPREG(HDMI_TG_VSYNC_BOT_HDMI_H);
  587. DUMPREG(HDMI_TG_FIELD_TOP_HDMI_L);
  588. DUMPREG(HDMI_TG_FIELD_TOP_HDMI_H);
  589. DUMPREG(HDMI_TG_FIELD_BOT_HDMI_L);
  590. DUMPREG(HDMI_TG_FIELD_BOT_HDMI_H);
  591. DUMPREG(HDMI_TG_3D);
  592. DRM_DEBUG_KMS("%s: ---- PACKET REGISTERS ----\n", prefix);
  593. DUMPREG(HDMI_AVI_CON);
  594. DUMPREG(HDMI_AVI_HEADER0);
  595. DUMPREG(HDMI_AVI_HEADER1);
  596. DUMPREG(HDMI_AVI_HEADER2);
  597. DUMPREG(HDMI_AVI_CHECK_SUM);
  598. DUMPREG(HDMI_VSI_CON);
  599. DUMPREG(HDMI_VSI_HEADER0);
  600. DUMPREG(HDMI_VSI_HEADER1);
  601. DUMPREG(HDMI_VSI_HEADER2);
  602. for (i = 0; i < 7; ++i)
  603. DUMPREG(HDMI_VSI_DATA(i));
  604. #undef DUMPREG
  605. }
  606. static void hdmi_regs_dump(struct hdmi_context *hdata, char *prefix)
  607. {
  608. if (hdata->type == HDMI_TYPE13)
  609. hdmi_v13_regs_dump(hdata, prefix);
  610. else
  611. hdmi_v14_regs_dump(hdata, prefix);
  612. }
  613. static u8 hdmi_chksum(struct hdmi_context *hdata,
  614. u32 start, u8 len, u32 hdr_sum)
  615. {
  616. int i;
  617. /* hdr_sum : header0 + header1 + header2
  618. * start : start address of packet byte1
  619. * len : packet bytes - 1 */
  620. for (i = 0; i < len; ++i)
  621. hdr_sum += 0xff & hdmi_reg_read(hdata, start + i * 4);
  622. /* return 2's complement of 8 bit hdr_sum */
  623. return (u8)(~(hdr_sum & 0xff) + 1);
  624. }
  625. static void hdmi_reg_infoframe(struct hdmi_context *hdata,
  626. struct hdmi_infoframe *infoframe)
  627. {
  628. u32 hdr_sum;
  629. u8 chksum;
  630. u32 aspect_ratio;
  631. u32 mod;
  632. u32 vic;
  633. mod = hdmi_reg_read(hdata, HDMI_MODE_SEL);
  634. if (hdata->dvi_mode) {
  635. hdmi_reg_writeb(hdata, HDMI_VSI_CON,
  636. HDMI_VSI_CON_DO_NOT_TRANSMIT);
  637. hdmi_reg_writeb(hdata, HDMI_AVI_CON,
  638. HDMI_AVI_CON_DO_NOT_TRANSMIT);
  639. hdmi_reg_writeb(hdata, HDMI_AUI_CON, HDMI_AUI_CON_NO_TRAN);
  640. return;
  641. }
  642. switch (infoframe->type) {
  643. case HDMI_PACKET_TYPE_AVI:
  644. hdmi_reg_writeb(hdata, HDMI_AVI_CON, HDMI_AVI_CON_EVERY_VSYNC);
  645. hdmi_reg_writeb(hdata, HDMI_AVI_HEADER0, infoframe->type);
  646. hdmi_reg_writeb(hdata, HDMI_AVI_HEADER1, infoframe->ver);
  647. hdmi_reg_writeb(hdata, HDMI_AVI_HEADER2, infoframe->len);
  648. hdr_sum = infoframe->type + infoframe->ver + infoframe->len;
  649. /* Output format zero hardcoded ,RGB YBCR selection */
  650. hdmi_reg_writeb(hdata, HDMI_AVI_BYTE(1), 0 << 5 |
  651. AVI_ACTIVE_FORMAT_VALID |
  652. AVI_UNDERSCANNED_DISPLAY_VALID);
  653. aspect_ratio = AVI_PIC_ASPECT_RATIO_16_9;
  654. hdmi_reg_writeb(hdata, HDMI_AVI_BYTE(2), aspect_ratio |
  655. AVI_SAME_AS_PIC_ASPECT_RATIO);
  656. vic = hdata->mode_conf.cea_video_id;
  657. hdmi_reg_writeb(hdata, HDMI_AVI_BYTE(4), vic);
  658. chksum = hdmi_chksum(hdata, HDMI_AVI_BYTE(1),
  659. infoframe->len, hdr_sum);
  660. DRM_DEBUG_KMS("AVI checksum = 0x%x\n", chksum);
  661. hdmi_reg_writeb(hdata, HDMI_AVI_CHECK_SUM, chksum);
  662. break;
  663. case HDMI_PACKET_TYPE_AUI:
  664. hdmi_reg_writeb(hdata, HDMI_AUI_CON, 0x02);
  665. hdmi_reg_writeb(hdata, HDMI_AUI_HEADER0, infoframe->type);
  666. hdmi_reg_writeb(hdata, HDMI_AUI_HEADER1, infoframe->ver);
  667. hdmi_reg_writeb(hdata, HDMI_AUI_HEADER2, infoframe->len);
  668. hdr_sum = infoframe->type + infoframe->ver + infoframe->len;
  669. chksum = hdmi_chksum(hdata, HDMI_AUI_BYTE(1),
  670. infoframe->len, hdr_sum);
  671. DRM_DEBUG_KMS("AUI checksum = 0x%x\n", chksum);
  672. hdmi_reg_writeb(hdata, HDMI_AUI_CHECK_SUM, chksum);
  673. break;
  674. default:
  675. break;
  676. }
  677. }
  678. static bool hdmi_is_connected(void *ctx)
  679. {
  680. struct hdmi_context *hdata = ctx;
  681. return hdata->hpd;
  682. }
  683. static struct edid *hdmi_get_edid(void *ctx, struct drm_connector *connector)
  684. {
  685. struct edid *raw_edid;
  686. struct hdmi_context *hdata = ctx;
  687. if (!hdata->ddc_port)
  688. return ERR_PTR(-ENODEV);
  689. raw_edid = drm_get_edid(connector, hdata->ddc_port->adapter);
  690. if (!raw_edid)
  691. return ERR_PTR(-ENODEV);
  692. hdata->dvi_mode = !drm_detect_hdmi_monitor(raw_edid);
  693. DRM_DEBUG_KMS("%s : width[%d] x height[%d]\n",
  694. (hdata->dvi_mode ? "dvi monitor" : "hdmi monitor"),
  695. raw_edid->width_cm, raw_edid->height_cm);
  696. return raw_edid;
  697. }
  698. static int hdmi_find_phy_conf(struct hdmi_context *hdata, u32 pixel_clock)
  699. {
  700. const struct hdmiphy_config *confs;
  701. int count, i;
  702. if (hdata->type == HDMI_TYPE13) {
  703. confs = hdmiphy_v13_configs;
  704. count = ARRAY_SIZE(hdmiphy_v13_configs);
  705. } else if (hdata->type == HDMI_TYPE14) {
  706. confs = hdmiphy_v14_configs;
  707. count = ARRAY_SIZE(hdmiphy_v14_configs);
  708. } else
  709. return -EINVAL;
  710. for (i = 0; i < count; i++)
  711. if (confs[i].pixel_clock == pixel_clock)
  712. return i;
  713. DRM_DEBUG_KMS("Could not find phy config for %d\n", pixel_clock);
  714. return -EINVAL;
  715. }
  716. static int hdmi_check_mode(void *ctx, struct drm_display_mode *mode)
  717. {
  718. struct hdmi_context *hdata = ctx;
  719. int ret;
  720. DRM_DEBUG_KMS("xres=%d, yres=%d, refresh=%d, intl=%d clock=%d\n",
  721. mode->hdisplay, mode->vdisplay, mode->vrefresh,
  722. (mode->flags & DRM_MODE_FLAG_INTERLACE) ? true :
  723. false, mode->clock * 1000);
  724. ret = hdmi_find_phy_conf(hdata, mode->clock * 1000);
  725. if (ret < 0)
  726. return ret;
  727. return 0;
  728. }
  729. static void hdmi_set_acr(u32 freq, u8 *acr)
  730. {
  731. u32 n, cts;
  732. switch (freq) {
  733. case 32000:
  734. n = 4096;
  735. cts = 27000;
  736. break;
  737. case 44100:
  738. n = 6272;
  739. cts = 30000;
  740. break;
  741. case 88200:
  742. n = 12544;
  743. cts = 30000;
  744. break;
  745. case 176400:
  746. n = 25088;
  747. cts = 30000;
  748. break;
  749. case 48000:
  750. n = 6144;
  751. cts = 27000;
  752. break;
  753. case 96000:
  754. n = 12288;
  755. cts = 27000;
  756. break;
  757. case 192000:
  758. n = 24576;
  759. cts = 27000;
  760. break;
  761. default:
  762. n = 0;
  763. cts = 0;
  764. break;
  765. }
  766. acr[1] = cts >> 16;
  767. acr[2] = cts >> 8 & 0xff;
  768. acr[3] = cts & 0xff;
  769. acr[4] = n >> 16;
  770. acr[5] = n >> 8 & 0xff;
  771. acr[6] = n & 0xff;
  772. }
  773. static void hdmi_reg_acr(struct hdmi_context *hdata, u8 *acr)
  774. {
  775. hdmi_reg_writeb(hdata, HDMI_ACR_N0, acr[6]);
  776. hdmi_reg_writeb(hdata, HDMI_ACR_N1, acr[5]);
  777. hdmi_reg_writeb(hdata, HDMI_ACR_N2, acr[4]);
  778. hdmi_reg_writeb(hdata, HDMI_ACR_MCTS0, acr[3]);
  779. hdmi_reg_writeb(hdata, HDMI_ACR_MCTS1, acr[2]);
  780. hdmi_reg_writeb(hdata, HDMI_ACR_MCTS2, acr[1]);
  781. hdmi_reg_writeb(hdata, HDMI_ACR_CTS0, acr[3]);
  782. hdmi_reg_writeb(hdata, HDMI_ACR_CTS1, acr[2]);
  783. hdmi_reg_writeb(hdata, HDMI_ACR_CTS2, acr[1]);
  784. if (hdata->type == HDMI_TYPE13)
  785. hdmi_reg_writeb(hdata, HDMI_V13_ACR_CON, 4);
  786. else
  787. hdmi_reg_writeb(hdata, HDMI_ACR_CON, 4);
  788. }
  789. static void hdmi_audio_init(struct hdmi_context *hdata)
  790. {
  791. u32 sample_rate, bits_per_sample, frame_size_code;
  792. u32 data_num, bit_ch, sample_frq;
  793. u32 val;
  794. u8 acr[7];
  795. sample_rate = 44100;
  796. bits_per_sample = 16;
  797. frame_size_code = 0;
  798. switch (bits_per_sample) {
  799. case 20:
  800. data_num = 2;
  801. bit_ch = 1;
  802. break;
  803. case 24:
  804. data_num = 3;
  805. bit_ch = 1;
  806. break;
  807. default:
  808. data_num = 1;
  809. bit_ch = 0;
  810. break;
  811. }
  812. hdmi_set_acr(sample_rate, acr);
  813. hdmi_reg_acr(hdata, acr);
  814. hdmi_reg_writeb(hdata, HDMI_I2S_MUX_CON, HDMI_I2S_IN_DISABLE
  815. | HDMI_I2S_AUD_I2S | HDMI_I2S_CUV_I2S_ENABLE
  816. | HDMI_I2S_MUX_ENABLE);
  817. hdmi_reg_writeb(hdata, HDMI_I2S_MUX_CH, HDMI_I2S_CH0_EN
  818. | HDMI_I2S_CH1_EN | HDMI_I2S_CH2_EN);
  819. hdmi_reg_writeb(hdata, HDMI_I2S_MUX_CUV, HDMI_I2S_CUV_RL_EN);
  820. sample_frq = (sample_rate == 44100) ? 0 :
  821. (sample_rate == 48000) ? 2 :
  822. (sample_rate == 32000) ? 3 :
  823. (sample_rate == 96000) ? 0xa : 0x0;
  824. hdmi_reg_writeb(hdata, HDMI_I2S_CLK_CON, HDMI_I2S_CLK_DIS);
  825. hdmi_reg_writeb(hdata, HDMI_I2S_CLK_CON, HDMI_I2S_CLK_EN);
  826. val = hdmi_reg_read(hdata, HDMI_I2S_DSD_CON) | 0x01;
  827. hdmi_reg_writeb(hdata, HDMI_I2S_DSD_CON, val);
  828. /* Configuration I2S input ports. Configure I2S_PIN_SEL_0~4 */
  829. hdmi_reg_writeb(hdata, HDMI_I2S_PIN_SEL_0, HDMI_I2S_SEL_SCLK(5)
  830. | HDMI_I2S_SEL_LRCK(6));
  831. hdmi_reg_writeb(hdata, HDMI_I2S_PIN_SEL_1, HDMI_I2S_SEL_SDATA1(1)
  832. | HDMI_I2S_SEL_SDATA2(4));
  833. hdmi_reg_writeb(hdata, HDMI_I2S_PIN_SEL_2, HDMI_I2S_SEL_SDATA3(1)
  834. | HDMI_I2S_SEL_SDATA2(2));
  835. hdmi_reg_writeb(hdata, HDMI_I2S_PIN_SEL_3, HDMI_I2S_SEL_DSD(0));
  836. /* I2S_CON_1 & 2 */
  837. hdmi_reg_writeb(hdata, HDMI_I2S_CON_1, HDMI_I2S_SCLK_FALLING_EDGE
  838. | HDMI_I2S_L_CH_LOW_POL);
  839. hdmi_reg_writeb(hdata, HDMI_I2S_CON_2, HDMI_I2S_MSB_FIRST_MODE
  840. | HDMI_I2S_SET_BIT_CH(bit_ch)
  841. | HDMI_I2S_SET_SDATA_BIT(data_num)
  842. | HDMI_I2S_BASIC_FORMAT);
  843. /* Configure register related to CUV information */
  844. hdmi_reg_writeb(hdata, HDMI_I2S_CH_ST_0, HDMI_I2S_CH_STATUS_MODE_0
  845. | HDMI_I2S_2AUD_CH_WITHOUT_PREEMPH
  846. | HDMI_I2S_COPYRIGHT
  847. | HDMI_I2S_LINEAR_PCM
  848. | HDMI_I2S_CONSUMER_FORMAT);
  849. hdmi_reg_writeb(hdata, HDMI_I2S_CH_ST_1, HDMI_I2S_CD_PLAYER);
  850. hdmi_reg_writeb(hdata, HDMI_I2S_CH_ST_2, HDMI_I2S_SET_SOURCE_NUM(0));
  851. hdmi_reg_writeb(hdata, HDMI_I2S_CH_ST_3, HDMI_I2S_CLK_ACCUR_LEVEL_2
  852. | HDMI_I2S_SET_SMP_FREQ(sample_frq));
  853. hdmi_reg_writeb(hdata, HDMI_I2S_CH_ST_4,
  854. HDMI_I2S_ORG_SMP_FREQ_44_1
  855. | HDMI_I2S_WORD_LEN_MAX24_24BITS
  856. | HDMI_I2S_WORD_LEN_MAX_24BITS);
  857. hdmi_reg_writeb(hdata, HDMI_I2S_CH_ST_CON, HDMI_I2S_CH_STATUS_RELOAD);
  858. }
  859. static void hdmi_audio_control(struct hdmi_context *hdata, bool onoff)
  860. {
  861. if (hdata->dvi_mode)
  862. return;
  863. hdmi_reg_writeb(hdata, HDMI_AUI_CON, onoff ? 2 : 0);
  864. hdmi_reg_writemask(hdata, HDMI_CON_0, onoff ?
  865. HDMI_ASP_EN : HDMI_ASP_DIS, HDMI_ASP_MASK);
  866. }
  867. static void hdmi_conf_reset(struct hdmi_context *hdata)
  868. {
  869. u32 reg;
  870. if (hdata->type == HDMI_TYPE13)
  871. reg = HDMI_V13_CORE_RSTOUT;
  872. else
  873. reg = HDMI_CORE_RSTOUT;
  874. /* resetting HDMI core */
  875. hdmi_reg_writemask(hdata, reg, 0, HDMI_CORE_SW_RSTOUT);
  876. usleep_range(10000, 12000);
  877. hdmi_reg_writemask(hdata, reg, ~0, HDMI_CORE_SW_RSTOUT);
  878. usleep_range(10000, 12000);
  879. }
  880. static void hdmi_conf_init(struct hdmi_context *hdata)
  881. {
  882. struct hdmi_infoframe infoframe;
  883. /* disable HPD interrupts from HDMI IP block, use GPIO instead */
  884. hdmi_reg_writemask(hdata, HDMI_INTC_CON, 0, HDMI_INTC_EN_GLOBAL |
  885. HDMI_INTC_EN_HPD_PLUG | HDMI_INTC_EN_HPD_UNPLUG);
  886. /* choose HDMI mode */
  887. hdmi_reg_writemask(hdata, HDMI_MODE_SEL,
  888. HDMI_MODE_HDMI_EN, HDMI_MODE_MASK);
  889. /* disable bluescreen */
  890. hdmi_reg_writemask(hdata, HDMI_CON_0, 0, HDMI_BLUE_SCR_EN);
  891. if (hdata->dvi_mode) {
  892. /* choose DVI mode */
  893. hdmi_reg_writemask(hdata, HDMI_MODE_SEL,
  894. HDMI_MODE_DVI_EN, HDMI_MODE_MASK);
  895. hdmi_reg_writeb(hdata, HDMI_CON_2,
  896. HDMI_VID_PREAMBLE_DIS | HDMI_GUARD_BAND_DIS);
  897. }
  898. if (hdata->type == HDMI_TYPE13) {
  899. /* choose bluescreen (fecal) color */
  900. hdmi_reg_writeb(hdata, HDMI_V13_BLUE_SCREEN_0, 0x12);
  901. hdmi_reg_writeb(hdata, HDMI_V13_BLUE_SCREEN_1, 0x34);
  902. hdmi_reg_writeb(hdata, HDMI_V13_BLUE_SCREEN_2, 0x56);
  903. /* enable AVI packet every vsync, fixes purple line problem */
  904. hdmi_reg_writeb(hdata, HDMI_V13_AVI_CON, 0x02);
  905. /* force RGB, look to CEA-861-D, table 7 for more detail */
  906. hdmi_reg_writeb(hdata, HDMI_V13_AVI_BYTE(0), 0 << 5);
  907. hdmi_reg_writemask(hdata, HDMI_CON_1, 0x10 << 5, 0x11 << 5);
  908. hdmi_reg_writeb(hdata, HDMI_V13_SPD_CON, 0x02);
  909. hdmi_reg_writeb(hdata, HDMI_V13_AUI_CON, 0x02);
  910. hdmi_reg_writeb(hdata, HDMI_V13_ACR_CON, 0x04);
  911. } else {
  912. infoframe.type = HDMI_PACKET_TYPE_AVI;
  913. infoframe.ver = HDMI_AVI_VERSION;
  914. infoframe.len = HDMI_AVI_LENGTH;
  915. hdmi_reg_infoframe(hdata, &infoframe);
  916. infoframe.type = HDMI_PACKET_TYPE_AUI;
  917. infoframe.ver = HDMI_AUI_VERSION;
  918. infoframe.len = HDMI_AUI_LENGTH;
  919. hdmi_reg_infoframe(hdata, &infoframe);
  920. /* enable AVI packet every vsync, fixes purple line problem */
  921. hdmi_reg_writemask(hdata, HDMI_CON_1, 2, 3 << 5);
  922. }
  923. }
  924. static void hdmi_v13_mode_apply(struct hdmi_context *hdata)
  925. {
  926. const struct hdmi_tg_regs *tg = &hdata->mode_conf.conf.v13_conf.tg;
  927. const struct hdmi_v13_core_regs *core =
  928. &hdata->mode_conf.conf.v13_conf.core;
  929. int tries;
  930. /* setting core registers */
  931. hdmi_reg_writeb(hdata, HDMI_H_BLANK_0, core->h_blank[0]);
  932. hdmi_reg_writeb(hdata, HDMI_H_BLANK_1, core->h_blank[1]);
  933. hdmi_reg_writeb(hdata, HDMI_V13_V_BLANK_0, core->v_blank[0]);
  934. hdmi_reg_writeb(hdata, HDMI_V13_V_BLANK_1, core->v_blank[1]);
  935. hdmi_reg_writeb(hdata, HDMI_V13_V_BLANK_2, core->v_blank[2]);
  936. hdmi_reg_writeb(hdata, HDMI_V13_H_V_LINE_0, core->h_v_line[0]);
  937. hdmi_reg_writeb(hdata, HDMI_V13_H_V_LINE_1, core->h_v_line[1]);
  938. hdmi_reg_writeb(hdata, HDMI_V13_H_V_LINE_2, core->h_v_line[2]);
  939. hdmi_reg_writeb(hdata, HDMI_VSYNC_POL, core->vsync_pol[0]);
  940. hdmi_reg_writeb(hdata, HDMI_INT_PRO_MODE, core->int_pro_mode[0]);
  941. hdmi_reg_writeb(hdata, HDMI_V13_V_BLANK_F_0, core->v_blank_f[0]);
  942. hdmi_reg_writeb(hdata, HDMI_V13_V_BLANK_F_1, core->v_blank_f[1]);
  943. hdmi_reg_writeb(hdata, HDMI_V13_V_BLANK_F_2, core->v_blank_f[2]);
  944. hdmi_reg_writeb(hdata, HDMI_V13_H_SYNC_GEN_0, core->h_sync_gen[0]);
  945. hdmi_reg_writeb(hdata, HDMI_V13_H_SYNC_GEN_1, core->h_sync_gen[1]);
  946. hdmi_reg_writeb(hdata, HDMI_V13_H_SYNC_GEN_2, core->h_sync_gen[2]);
  947. hdmi_reg_writeb(hdata, HDMI_V13_V_SYNC_GEN_1_0, core->v_sync_gen1[0]);
  948. hdmi_reg_writeb(hdata, HDMI_V13_V_SYNC_GEN_1_1, core->v_sync_gen1[1]);
  949. hdmi_reg_writeb(hdata, HDMI_V13_V_SYNC_GEN_1_2, core->v_sync_gen1[2]);
  950. hdmi_reg_writeb(hdata, HDMI_V13_V_SYNC_GEN_2_0, core->v_sync_gen2[0]);
  951. hdmi_reg_writeb(hdata, HDMI_V13_V_SYNC_GEN_2_1, core->v_sync_gen2[1]);
  952. hdmi_reg_writeb(hdata, HDMI_V13_V_SYNC_GEN_2_2, core->v_sync_gen2[2]);
  953. hdmi_reg_writeb(hdata, HDMI_V13_V_SYNC_GEN_3_0, core->v_sync_gen3[0]);
  954. hdmi_reg_writeb(hdata, HDMI_V13_V_SYNC_GEN_3_1, core->v_sync_gen3[1]);
  955. hdmi_reg_writeb(hdata, HDMI_V13_V_SYNC_GEN_3_2, core->v_sync_gen3[2]);
  956. /* Timing generator registers */
  957. hdmi_reg_writeb(hdata, HDMI_TG_H_FSZ_L, tg->h_fsz[0]);
  958. hdmi_reg_writeb(hdata, HDMI_TG_H_FSZ_H, tg->h_fsz[1]);
  959. hdmi_reg_writeb(hdata, HDMI_TG_HACT_ST_L, tg->hact_st[0]);
  960. hdmi_reg_writeb(hdata, HDMI_TG_HACT_ST_H, tg->hact_st[1]);
  961. hdmi_reg_writeb(hdata, HDMI_TG_HACT_SZ_L, tg->hact_sz[0]);
  962. hdmi_reg_writeb(hdata, HDMI_TG_HACT_SZ_H, tg->hact_sz[1]);
  963. hdmi_reg_writeb(hdata, HDMI_TG_V_FSZ_L, tg->v_fsz[0]);
  964. hdmi_reg_writeb(hdata, HDMI_TG_V_FSZ_H, tg->v_fsz[1]);
  965. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_L, tg->vsync[0]);
  966. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_H, tg->vsync[1]);
  967. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC2_L, tg->vsync2[0]);
  968. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC2_H, tg->vsync2[1]);
  969. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST_L, tg->vact_st[0]);
  970. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST_H, tg->vact_st[1]);
  971. hdmi_reg_writeb(hdata, HDMI_TG_VACT_SZ_L, tg->vact_sz[0]);
  972. hdmi_reg_writeb(hdata, HDMI_TG_VACT_SZ_H, tg->vact_sz[1]);
  973. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_CHG_L, tg->field_chg[0]);
  974. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_CHG_H, tg->field_chg[1]);
  975. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST2_L, tg->vact_st2[0]);
  976. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST2_H, tg->vact_st2[1]);
  977. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_TOP_HDMI_L, tg->vsync_top_hdmi[0]);
  978. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_TOP_HDMI_H, tg->vsync_top_hdmi[1]);
  979. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_BOT_HDMI_L, tg->vsync_bot_hdmi[0]);
  980. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_BOT_HDMI_H, tg->vsync_bot_hdmi[1]);
  981. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_TOP_HDMI_L, tg->field_top_hdmi[0]);
  982. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_TOP_HDMI_H, tg->field_top_hdmi[1]);
  983. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_BOT_HDMI_L, tg->field_bot_hdmi[0]);
  984. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_BOT_HDMI_H, tg->field_bot_hdmi[1]);
  985. /* waiting for HDMIPHY's PLL to get to steady state */
  986. for (tries = 100; tries; --tries) {
  987. u32 val = hdmi_reg_read(hdata, HDMI_V13_PHY_STATUS);
  988. if (val & HDMI_PHY_STATUS_READY)
  989. break;
  990. usleep_range(1000, 2000);
  991. }
  992. /* steady state not achieved */
  993. if (tries == 0) {
  994. DRM_ERROR("hdmiphy's pll could not reach steady state.\n");
  995. hdmi_regs_dump(hdata, "timing apply");
  996. }
  997. clk_disable_unprepare(hdata->res.sclk_hdmi);
  998. clk_set_parent(hdata->res.mout_hdmi, hdata->res.sclk_hdmiphy);
  999. clk_prepare_enable(hdata->res.sclk_hdmi);
  1000. /* enable HDMI and timing generator */
  1001. hdmi_reg_writemask(hdata, HDMI_CON_0, ~0, HDMI_EN);
  1002. if (core->int_pro_mode[0])
  1003. hdmi_reg_writemask(hdata, HDMI_TG_CMD, ~0, HDMI_TG_EN |
  1004. HDMI_FIELD_EN);
  1005. else
  1006. hdmi_reg_writemask(hdata, HDMI_TG_CMD, ~0, HDMI_TG_EN);
  1007. }
  1008. static void hdmi_v14_mode_apply(struct hdmi_context *hdata)
  1009. {
  1010. const struct hdmi_tg_regs *tg = &hdata->mode_conf.conf.v14_conf.tg;
  1011. const struct hdmi_v14_core_regs *core =
  1012. &hdata->mode_conf.conf.v14_conf.core;
  1013. int tries;
  1014. /* setting core registers */
  1015. hdmi_reg_writeb(hdata, HDMI_H_BLANK_0, core->h_blank[0]);
  1016. hdmi_reg_writeb(hdata, HDMI_H_BLANK_1, core->h_blank[1]);
  1017. hdmi_reg_writeb(hdata, HDMI_V2_BLANK_0, core->v2_blank[0]);
  1018. hdmi_reg_writeb(hdata, HDMI_V2_BLANK_1, core->v2_blank[1]);
  1019. hdmi_reg_writeb(hdata, HDMI_V1_BLANK_0, core->v1_blank[0]);
  1020. hdmi_reg_writeb(hdata, HDMI_V1_BLANK_1, core->v1_blank[1]);
  1021. hdmi_reg_writeb(hdata, HDMI_V_LINE_0, core->v_line[0]);
  1022. hdmi_reg_writeb(hdata, HDMI_V_LINE_1, core->v_line[1]);
  1023. hdmi_reg_writeb(hdata, HDMI_H_LINE_0, core->h_line[0]);
  1024. hdmi_reg_writeb(hdata, HDMI_H_LINE_1, core->h_line[1]);
  1025. hdmi_reg_writeb(hdata, HDMI_HSYNC_POL, core->hsync_pol[0]);
  1026. hdmi_reg_writeb(hdata, HDMI_VSYNC_POL, core->vsync_pol[0]);
  1027. hdmi_reg_writeb(hdata, HDMI_INT_PRO_MODE, core->int_pro_mode[0]);
  1028. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F0_0, core->v_blank_f0[0]);
  1029. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F0_1, core->v_blank_f0[1]);
  1030. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F1_0, core->v_blank_f1[0]);
  1031. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F1_1, core->v_blank_f1[1]);
  1032. hdmi_reg_writeb(hdata, HDMI_H_SYNC_START_0, core->h_sync_start[0]);
  1033. hdmi_reg_writeb(hdata, HDMI_H_SYNC_START_1, core->h_sync_start[1]);
  1034. hdmi_reg_writeb(hdata, HDMI_H_SYNC_END_0, core->h_sync_end[0]);
  1035. hdmi_reg_writeb(hdata, HDMI_H_SYNC_END_1, core->h_sync_end[1]);
  1036. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_BEF_2_0,
  1037. core->v_sync_line_bef_2[0]);
  1038. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_BEF_2_1,
  1039. core->v_sync_line_bef_2[1]);
  1040. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_BEF_1_0,
  1041. core->v_sync_line_bef_1[0]);
  1042. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_BEF_1_1,
  1043. core->v_sync_line_bef_1[1]);
  1044. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_2_0,
  1045. core->v_sync_line_aft_2[0]);
  1046. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_2_1,
  1047. core->v_sync_line_aft_2[1]);
  1048. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_1_0,
  1049. core->v_sync_line_aft_1[0]);
  1050. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_1_1,
  1051. core->v_sync_line_aft_1[1]);
  1052. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_2_0,
  1053. core->v_sync_line_aft_pxl_2[0]);
  1054. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_2_1,
  1055. core->v_sync_line_aft_pxl_2[1]);
  1056. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_1_0,
  1057. core->v_sync_line_aft_pxl_1[0]);
  1058. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_1_1,
  1059. core->v_sync_line_aft_pxl_1[1]);
  1060. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F2_0, core->v_blank_f2[0]);
  1061. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F2_1, core->v_blank_f2[1]);
  1062. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F3_0, core->v_blank_f3[0]);
  1063. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F3_1, core->v_blank_f3[1]);
  1064. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F4_0, core->v_blank_f4[0]);
  1065. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F4_1, core->v_blank_f4[1]);
  1066. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F5_0, core->v_blank_f5[0]);
  1067. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F5_1, core->v_blank_f5[1]);
  1068. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_3_0,
  1069. core->v_sync_line_aft_3[0]);
  1070. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_3_1,
  1071. core->v_sync_line_aft_3[1]);
  1072. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_4_0,
  1073. core->v_sync_line_aft_4[0]);
  1074. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_4_1,
  1075. core->v_sync_line_aft_4[1]);
  1076. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_5_0,
  1077. core->v_sync_line_aft_5[0]);
  1078. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_5_1,
  1079. core->v_sync_line_aft_5[1]);
  1080. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_6_0,
  1081. core->v_sync_line_aft_6[0]);
  1082. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_6_1,
  1083. core->v_sync_line_aft_6[1]);
  1084. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_3_0,
  1085. core->v_sync_line_aft_pxl_3[0]);
  1086. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_3_1,
  1087. core->v_sync_line_aft_pxl_3[1]);
  1088. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_4_0,
  1089. core->v_sync_line_aft_pxl_4[0]);
  1090. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_4_1,
  1091. core->v_sync_line_aft_pxl_4[1]);
  1092. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_5_0,
  1093. core->v_sync_line_aft_pxl_5[0]);
  1094. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_5_1,
  1095. core->v_sync_line_aft_pxl_5[1]);
  1096. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_6_0,
  1097. core->v_sync_line_aft_pxl_6[0]);
  1098. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_6_1,
  1099. core->v_sync_line_aft_pxl_6[1]);
  1100. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_1_0, core->vact_space_1[0]);
  1101. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_1_1, core->vact_space_1[1]);
  1102. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_2_0, core->vact_space_2[0]);
  1103. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_2_1, core->vact_space_2[1]);
  1104. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_3_0, core->vact_space_3[0]);
  1105. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_3_1, core->vact_space_3[1]);
  1106. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_4_0, core->vact_space_4[0]);
  1107. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_4_1, core->vact_space_4[1]);
  1108. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_5_0, core->vact_space_5[0]);
  1109. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_5_1, core->vact_space_5[1]);
  1110. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_6_0, core->vact_space_6[0]);
  1111. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_6_1, core->vact_space_6[1]);
  1112. /* Timing generator registers */
  1113. hdmi_reg_writeb(hdata, HDMI_TG_H_FSZ_L, tg->h_fsz[0]);
  1114. hdmi_reg_writeb(hdata, HDMI_TG_H_FSZ_H, tg->h_fsz[1]);
  1115. hdmi_reg_writeb(hdata, HDMI_TG_HACT_ST_L, tg->hact_st[0]);
  1116. hdmi_reg_writeb(hdata, HDMI_TG_HACT_ST_H, tg->hact_st[1]);
  1117. hdmi_reg_writeb(hdata, HDMI_TG_HACT_SZ_L, tg->hact_sz[0]);
  1118. hdmi_reg_writeb(hdata, HDMI_TG_HACT_SZ_H, tg->hact_sz[1]);
  1119. hdmi_reg_writeb(hdata, HDMI_TG_V_FSZ_L, tg->v_fsz[0]);
  1120. hdmi_reg_writeb(hdata, HDMI_TG_V_FSZ_H, tg->v_fsz[1]);
  1121. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_L, tg->vsync[0]);
  1122. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_H, tg->vsync[1]);
  1123. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC2_L, tg->vsync2[0]);
  1124. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC2_H, tg->vsync2[1]);
  1125. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST_L, tg->vact_st[0]);
  1126. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST_H, tg->vact_st[1]);
  1127. hdmi_reg_writeb(hdata, HDMI_TG_VACT_SZ_L, tg->vact_sz[0]);
  1128. hdmi_reg_writeb(hdata, HDMI_TG_VACT_SZ_H, tg->vact_sz[1]);
  1129. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_CHG_L, tg->field_chg[0]);
  1130. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_CHG_H, tg->field_chg[1]);
  1131. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST2_L, tg->vact_st2[0]);
  1132. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST2_H, tg->vact_st2[1]);
  1133. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST3_L, tg->vact_st3[0]);
  1134. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST3_H, tg->vact_st3[1]);
  1135. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST4_L, tg->vact_st4[0]);
  1136. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST4_H, tg->vact_st4[1]);
  1137. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_TOP_HDMI_L, tg->vsync_top_hdmi[0]);
  1138. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_TOP_HDMI_H, tg->vsync_top_hdmi[1]);
  1139. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_BOT_HDMI_L, tg->vsync_bot_hdmi[0]);
  1140. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_BOT_HDMI_H, tg->vsync_bot_hdmi[1]);
  1141. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_TOP_HDMI_L, tg->field_top_hdmi[0]);
  1142. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_TOP_HDMI_H, tg->field_top_hdmi[1]);
  1143. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_BOT_HDMI_L, tg->field_bot_hdmi[0]);
  1144. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_BOT_HDMI_H, tg->field_bot_hdmi[1]);
  1145. hdmi_reg_writeb(hdata, HDMI_TG_3D, tg->tg_3d[0]);
  1146. /* waiting for HDMIPHY's PLL to get to steady state */
  1147. for (tries = 100; tries; --tries) {
  1148. u32 val = hdmi_reg_read(hdata, HDMI_PHY_STATUS_0);
  1149. if (val & HDMI_PHY_STATUS_READY)
  1150. break;
  1151. usleep_range(1000, 2000);
  1152. }
  1153. /* steady state not achieved */
  1154. if (tries == 0) {
  1155. DRM_ERROR("hdmiphy's pll could not reach steady state.\n");
  1156. hdmi_regs_dump(hdata, "timing apply");
  1157. }
  1158. clk_disable_unprepare(hdata->res.sclk_hdmi);
  1159. clk_set_parent(hdata->res.mout_hdmi, hdata->res.sclk_hdmiphy);
  1160. clk_prepare_enable(hdata->res.sclk_hdmi);
  1161. /* enable HDMI and timing generator */
  1162. hdmi_reg_writemask(hdata, HDMI_CON_0, ~0, HDMI_EN);
  1163. if (core->int_pro_mode[0])
  1164. hdmi_reg_writemask(hdata, HDMI_TG_CMD, ~0, HDMI_TG_EN |
  1165. HDMI_FIELD_EN);
  1166. else
  1167. hdmi_reg_writemask(hdata, HDMI_TG_CMD, ~0, HDMI_TG_EN);
  1168. }
  1169. static void hdmi_mode_apply(struct hdmi_context *hdata)
  1170. {
  1171. if (hdata->type == HDMI_TYPE13)
  1172. hdmi_v13_mode_apply(hdata);
  1173. else
  1174. hdmi_v14_mode_apply(hdata);
  1175. }
  1176. static void hdmiphy_conf_reset(struct hdmi_context *hdata)
  1177. {
  1178. u8 buffer[2];
  1179. u32 reg;
  1180. clk_disable_unprepare(hdata->res.sclk_hdmi);
  1181. clk_set_parent(hdata->res.mout_hdmi, hdata->res.sclk_pixel);
  1182. clk_prepare_enable(hdata->res.sclk_hdmi);
  1183. /* operation mode */
  1184. buffer[0] = 0x1f;
  1185. buffer[1] = 0x00;
  1186. if (hdata->hdmiphy_port)
  1187. i2c_master_send(hdata->hdmiphy_port, buffer, 2);
  1188. if (hdata->type == HDMI_TYPE13)
  1189. reg = HDMI_V13_PHY_RSTOUT;
  1190. else
  1191. reg = HDMI_PHY_RSTOUT;
  1192. /* reset hdmiphy */
  1193. hdmi_reg_writemask(hdata, reg, ~0, HDMI_PHY_SW_RSTOUT);
  1194. usleep_range(10000, 12000);
  1195. hdmi_reg_writemask(hdata, reg, 0, HDMI_PHY_SW_RSTOUT);
  1196. usleep_range(10000, 12000);
  1197. }
  1198. static void hdmiphy_poweron(struct hdmi_context *hdata)
  1199. {
  1200. if (hdata->type == HDMI_TYPE14)
  1201. hdmi_reg_writemask(hdata, HDMI_PHY_CON_0, 0,
  1202. HDMI_PHY_POWER_OFF_EN);
  1203. }
  1204. static void hdmiphy_poweroff(struct hdmi_context *hdata)
  1205. {
  1206. if (hdata->type == HDMI_TYPE14)
  1207. hdmi_reg_writemask(hdata, HDMI_PHY_CON_0, ~0,
  1208. HDMI_PHY_POWER_OFF_EN);
  1209. }
  1210. static void hdmiphy_conf_apply(struct hdmi_context *hdata)
  1211. {
  1212. const u8 *hdmiphy_data;
  1213. u8 buffer[32];
  1214. u8 operation[2];
  1215. u8 read_buffer[32] = {0, };
  1216. int ret;
  1217. int i;
  1218. if (!hdata->hdmiphy_port) {
  1219. DRM_ERROR("hdmiphy is not attached\n");
  1220. return;
  1221. }
  1222. /* pixel clock */
  1223. i = hdmi_find_phy_conf(hdata, hdata->mode_conf.pixel_clock);
  1224. if (i < 0) {
  1225. DRM_ERROR("failed to find hdmiphy conf\n");
  1226. return;
  1227. }
  1228. if (hdata->type == HDMI_TYPE13)
  1229. hdmiphy_data = hdmiphy_v13_configs[i].conf;
  1230. else
  1231. hdmiphy_data = hdmiphy_v14_configs[i].conf;
  1232. memcpy(buffer, hdmiphy_data, 32);
  1233. ret = i2c_master_send(hdata->hdmiphy_port, buffer, 32);
  1234. if (ret != 32) {
  1235. DRM_ERROR("failed to configure HDMIPHY via I2C\n");
  1236. return;
  1237. }
  1238. usleep_range(10000, 12000);
  1239. /* operation mode */
  1240. operation[0] = 0x1f;
  1241. operation[1] = 0x80;
  1242. ret = i2c_master_send(hdata->hdmiphy_port, operation, 2);
  1243. if (ret != 2) {
  1244. DRM_ERROR("failed to enable hdmiphy\n");
  1245. return;
  1246. }
  1247. ret = i2c_master_recv(hdata->hdmiphy_port, read_buffer, 32);
  1248. if (ret < 0) {
  1249. DRM_ERROR("failed to read hdmiphy config\n");
  1250. return;
  1251. }
  1252. for (i = 0; i < ret; i++)
  1253. DRM_DEBUG_KMS("hdmiphy[0x%02x] write[0x%02x] - "
  1254. "recv [0x%02x]\n", i, buffer[i], read_buffer[i]);
  1255. }
  1256. static void hdmi_conf_apply(struct hdmi_context *hdata)
  1257. {
  1258. hdmiphy_conf_reset(hdata);
  1259. hdmiphy_conf_apply(hdata);
  1260. mutex_lock(&hdata->hdmi_mutex);
  1261. hdmi_conf_reset(hdata);
  1262. hdmi_conf_init(hdata);
  1263. mutex_unlock(&hdata->hdmi_mutex);
  1264. hdmi_audio_init(hdata);
  1265. /* setting core registers */
  1266. hdmi_mode_apply(hdata);
  1267. hdmi_audio_control(hdata, true);
  1268. hdmi_regs_dump(hdata, "start");
  1269. }
  1270. static void hdmi_set_reg(u8 *reg_pair, int num_bytes, u32 value)
  1271. {
  1272. int i;
  1273. BUG_ON(num_bytes > 4);
  1274. for (i = 0; i < num_bytes; i++)
  1275. reg_pair[i] = (value >> (8 * i)) & 0xff;
  1276. }
  1277. static void hdmi_v13_mode_set(struct hdmi_context *hdata,
  1278. struct drm_display_mode *m)
  1279. {
  1280. struct hdmi_v13_core_regs *core = &hdata->mode_conf.conf.v13_conf.core;
  1281. struct hdmi_tg_regs *tg = &hdata->mode_conf.conf.v13_conf.tg;
  1282. unsigned int val;
  1283. hdata->mode_conf.cea_video_id =
  1284. drm_match_cea_mode((struct drm_display_mode *)m);
  1285. hdata->mode_conf.pixel_clock = m->clock * 1000;
  1286. hdmi_set_reg(core->h_blank, 2, m->htotal - m->hdisplay);
  1287. hdmi_set_reg(core->h_v_line, 3, (m->htotal << 12) | m->vtotal);
  1288. val = (m->flags & DRM_MODE_FLAG_NVSYNC) ? 1 : 0;
  1289. hdmi_set_reg(core->vsync_pol, 1, val);
  1290. val = (m->flags & DRM_MODE_FLAG_INTERLACE) ? 1 : 0;
  1291. hdmi_set_reg(core->int_pro_mode, 1, val);
  1292. val = (m->hsync_start - m->hdisplay - 2);
  1293. val |= ((m->hsync_end - m->hdisplay - 2) << 10);
  1294. val |= ((m->flags & DRM_MODE_FLAG_NHSYNC) ? 1 : 0)<<20;
  1295. hdmi_set_reg(core->h_sync_gen, 3, val);
  1296. /*
  1297. * Quirk requirement for exynos HDMI IP design,
  1298. * 2 pixels less than the actual calculation for hsync_start
  1299. * and end.
  1300. */
  1301. /* Following values & calculations differ for different type of modes */
  1302. if (m->flags & DRM_MODE_FLAG_INTERLACE) {
  1303. /* Interlaced Mode */
  1304. val = ((m->vsync_end - m->vdisplay) / 2);
  1305. val |= ((m->vsync_start - m->vdisplay) / 2) << 12;
  1306. hdmi_set_reg(core->v_sync_gen1, 3, val);
  1307. val = m->vtotal / 2;
  1308. val |= ((m->vtotal - m->vdisplay) / 2) << 11;
  1309. hdmi_set_reg(core->v_blank, 3, val);
  1310. val = (m->vtotal +
  1311. ((m->vsync_end - m->vsync_start) * 4) + 5) / 2;
  1312. val |= m->vtotal << 11;
  1313. hdmi_set_reg(core->v_blank_f, 3, val);
  1314. val = ((m->vtotal / 2) + 7);
  1315. val |= ((m->vtotal / 2) + 2) << 12;
  1316. hdmi_set_reg(core->v_sync_gen2, 3, val);
  1317. val = ((m->htotal / 2) + (m->hsync_start - m->hdisplay));
  1318. val |= ((m->htotal / 2) +
  1319. (m->hsync_start - m->hdisplay)) << 12;
  1320. hdmi_set_reg(core->v_sync_gen3, 3, val);
  1321. hdmi_set_reg(tg->vact_st, 2, (m->vtotal - m->vdisplay) / 2);
  1322. hdmi_set_reg(tg->vact_sz, 2, m->vdisplay / 2);
  1323. hdmi_set_reg(tg->vact_st2, 2, 0x249);/* Reset value + 1*/
  1324. } else {
  1325. /* Progressive Mode */
  1326. val = m->vtotal;
  1327. val |= (m->vtotal - m->vdisplay) << 11;
  1328. hdmi_set_reg(core->v_blank, 3, val);
  1329. hdmi_set_reg(core->v_blank_f, 3, 0);
  1330. val = (m->vsync_end - m->vdisplay);
  1331. val |= ((m->vsync_start - m->vdisplay) << 12);
  1332. hdmi_set_reg(core->v_sync_gen1, 3, val);
  1333. hdmi_set_reg(core->v_sync_gen2, 3, 0x1001);/* Reset value */
  1334. hdmi_set_reg(core->v_sync_gen3, 3, 0x1001);/* Reset value */
  1335. hdmi_set_reg(tg->vact_st, 2, m->vtotal - m->vdisplay);
  1336. hdmi_set_reg(tg->vact_sz, 2, m->vdisplay);
  1337. hdmi_set_reg(tg->vact_st2, 2, 0x248); /* Reset value */
  1338. }
  1339. /* Timing generator registers */
  1340. hdmi_set_reg(tg->cmd, 1, 0x0);
  1341. hdmi_set_reg(tg->h_fsz, 2, m->htotal);
  1342. hdmi_set_reg(tg->hact_st, 2, m->htotal - m->hdisplay);
  1343. hdmi_set_reg(tg->hact_sz, 2, m->hdisplay);
  1344. hdmi_set_reg(tg->v_fsz, 2, m->vtotal);
  1345. hdmi_set_reg(tg->vsync, 2, 0x1);
  1346. hdmi_set_reg(tg->vsync2, 2, 0x233); /* Reset value */
  1347. hdmi_set_reg(tg->field_chg, 2, 0x233); /* Reset value */
  1348. hdmi_set_reg(tg->vsync_top_hdmi, 2, 0x1); /* Reset value */
  1349. hdmi_set_reg(tg->vsync_bot_hdmi, 2, 0x233); /* Reset value */
  1350. hdmi_set_reg(tg->field_top_hdmi, 2, 0x1); /* Reset value */
  1351. hdmi_set_reg(tg->field_bot_hdmi, 2, 0x233); /* Reset value */
  1352. hdmi_set_reg(tg->tg_3d, 1, 0x0); /* Not used */
  1353. }
  1354. static void hdmi_v14_mode_set(struct hdmi_context *hdata,
  1355. struct drm_display_mode *m)
  1356. {
  1357. struct hdmi_tg_regs *tg = &hdata->mode_conf.conf.v14_conf.tg;
  1358. struct hdmi_v14_core_regs *core =
  1359. &hdata->mode_conf.conf.v14_conf.core;
  1360. hdata->mode_conf.cea_video_id =
  1361. drm_match_cea_mode((struct drm_display_mode *)m);
  1362. hdata->mode_conf.pixel_clock = m->clock * 1000;
  1363. hdmi_set_reg(core->h_blank, 2, m->htotal - m->hdisplay);
  1364. hdmi_set_reg(core->v_line, 2, m->vtotal);
  1365. hdmi_set_reg(core->h_line, 2, m->htotal);
  1366. hdmi_set_reg(core->hsync_pol, 1,
  1367. (m->flags & DRM_MODE_FLAG_NHSYNC) ? 1 : 0);
  1368. hdmi_set_reg(core->vsync_pol, 1,
  1369. (m->flags & DRM_MODE_FLAG_NVSYNC) ? 1 : 0);
  1370. hdmi_set_reg(core->int_pro_mode, 1,
  1371. (m->flags & DRM_MODE_FLAG_INTERLACE) ? 1 : 0);
  1372. /*
  1373. * Quirk requirement for exynos 5 HDMI IP design,
  1374. * 2 pixels less than the actual calculation for hsync_start
  1375. * and end.
  1376. */
  1377. /* Following values & calculations differ for different type of modes */
  1378. if (m->flags & DRM_MODE_FLAG_INTERLACE) {
  1379. /* Interlaced Mode */
  1380. hdmi_set_reg(core->v_sync_line_bef_2, 2,
  1381. (m->vsync_end - m->vdisplay) / 2);
  1382. hdmi_set_reg(core->v_sync_line_bef_1, 2,
  1383. (m->vsync_start - m->vdisplay) / 2);
  1384. hdmi_set_reg(core->v2_blank, 2, m->vtotal / 2);
  1385. hdmi_set_reg(core->v1_blank, 2, (m->vtotal - m->vdisplay) / 2);
  1386. hdmi_set_reg(core->v_blank_f0, 2, m->vtotal - m->vdisplay / 2);
  1387. hdmi_set_reg(core->v_blank_f1, 2, m->vtotal);
  1388. hdmi_set_reg(core->v_sync_line_aft_2, 2, (m->vtotal / 2) + 7);
  1389. hdmi_set_reg(core->v_sync_line_aft_1, 2, (m->vtotal / 2) + 2);
  1390. hdmi_set_reg(core->v_sync_line_aft_pxl_2, 2,
  1391. (m->htotal / 2) + (m->hsync_start - m->hdisplay));
  1392. hdmi_set_reg(core->v_sync_line_aft_pxl_1, 2,
  1393. (m->htotal / 2) + (m->hsync_start - m->hdisplay));
  1394. hdmi_set_reg(tg->vact_st, 2, (m->vtotal - m->vdisplay) / 2);
  1395. hdmi_set_reg(tg->vact_sz, 2, m->vdisplay / 2);
  1396. hdmi_set_reg(tg->vact_st2, 2, m->vtotal - m->vdisplay / 2);
  1397. hdmi_set_reg(tg->vsync2, 2, (m->vtotal / 2) + 1);
  1398. hdmi_set_reg(tg->vsync_bot_hdmi, 2, (m->vtotal / 2) + 1);
  1399. hdmi_set_reg(tg->field_bot_hdmi, 2, (m->vtotal / 2) + 1);
  1400. hdmi_set_reg(tg->vact_st3, 2, 0x0);
  1401. hdmi_set_reg(tg->vact_st4, 2, 0x0);
  1402. } else {
  1403. /* Progressive Mode */
  1404. hdmi_set_reg(core->v_sync_line_bef_2, 2,
  1405. m->vsync_end - m->vdisplay);
  1406. hdmi_set_reg(core->v_sync_line_bef_1, 2,
  1407. m->vsync_start - m->vdisplay);
  1408. hdmi_set_reg(core->v2_blank, 2, m->vtotal);
  1409. hdmi_set_reg(core->v1_blank, 2, m->vtotal - m->vdisplay);
  1410. hdmi_set_reg(core->v_blank_f0, 2, 0xffff);
  1411. hdmi_set_reg(core->v_blank_f1, 2, 0xffff);
  1412. hdmi_set_reg(core->v_sync_line_aft_2, 2, 0xffff);
  1413. hdmi_set_reg(core->v_sync_line_aft_1, 2, 0xffff);
  1414. hdmi_set_reg(core->v_sync_line_aft_pxl_2, 2, 0xffff);
  1415. hdmi_set_reg(core->v_sync_line_aft_pxl_1, 2, 0xffff);
  1416. hdmi_set_reg(tg->vact_st, 2, m->vtotal - m->vdisplay);
  1417. hdmi_set_reg(tg->vact_sz, 2, m->vdisplay);
  1418. hdmi_set_reg(tg->vact_st2, 2, 0x248); /* Reset value */
  1419. hdmi_set_reg(tg->vact_st3, 2, 0x47b); /* Reset value */
  1420. hdmi_set_reg(tg->vact_st4, 2, 0x6ae); /* Reset value */
  1421. hdmi_set_reg(tg->vsync2, 2, 0x233); /* Reset value */
  1422. hdmi_set_reg(tg->vsync_bot_hdmi, 2, 0x233); /* Reset value */
  1423. hdmi_set_reg(tg->field_bot_hdmi, 2, 0x233); /* Reset value */
  1424. }
  1425. /* Following values & calculations are same irrespective of mode type */
  1426. hdmi_set_reg(core->h_sync_start, 2, m->hsync_start - m->hdisplay - 2);
  1427. hdmi_set_reg(core->h_sync_end, 2, m->hsync_end - m->hdisplay - 2);
  1428. hdmi_set_reg(core->vact_space_1, 2, 0xffff);
  1429. hdmi_set_reg(core->vact_space_2, 2, 0xffff);
  1430. hdmi_set_reg(core->vact_space_3, 2, 0xffff);
  1431. hdmi_set_reg(core->vact_space_4, 2, 0xffff);
  1432. hdmi_set_reg(core->vact_space_5, 2, 0xffff);
  1433. hdmi_set_reg(core->vact_space_6, 2, 0xffff);
  1434. hdmi_set_reg(core->v_blank_f2, 2, 0xffff);
  1435. hdmi_set_reg(core->v_blank_f3, 2, 0xffff);
  1436. hdmi_set_reg(core->v_blank_f4, 2, 0xffff);
  1437. hdmi_set_reg(core->v_blank_f5, 2, 0xffff);
  1438. hdmi_set_reg(core->v_sync_line_aft_3, 2, 0xffff);
  1439. hdmi_set_reg(core->v_sync_line_aft_4, 2, 0xffff);
  1440. hdmi_set_reg(core->v_sync_line_aft_5, 2, 0xffff);
  1441. hdmi_set_reg(core->v_sync_line_aft_6, 2, 0xffff);
  1442. hdmi_set_reg(core->v_sync_line_aft_pxl_3, 2, 0xffff);
  1443. hdmi_set_reg(core->v_sync_line_aft_pxl_4, 2, 0xffff);
  1444. hdmi_set_reg(core->v_sync_line_aft_pxl_5, 2, 0xffff);
  1445. hdmi_set_reg(core->v_sync_line_aft_pxl_6, 2, 0xffff);
  1446. /* Timing generator registers */
  1447. hdmi_set_reg(tg->cmd, 1, 0x0);
  1448. hdmi_set_reg(tg->h_fsz, 2, m->htotal);
  1449. hdmi_set_reg(tg->hact_st, 2, m->htotal - m->hdisplay);
  1450. hdmi_set_reg(tg->hact_sz, 2, m->hdisplay);
  1451. hdmi_set_reg(tg->v_fsz, 2, m->vtotal);
  1452. hdmi_set_reg(tg->vsync, 2, 0x1);
  1453. hdmi_set_reg(tg->field_chg, 2, 0x233); /* Reset value */
  1454. hdmi_set_reg(tg->vsync_top_hdmi, 2, 0x1); /* Reset value */
  1455. hdmi_set_reg(tg->field_top_hdmi, 2, 0x1); /* Reset value */
  1456. hdmi_set_reg(tg->tg_3d, 1, 0x0);
  1457. }
  1458. static void hdmi_mode_set(void *ctx, struct drm_display_mode *mode)
  1459. {
  1460. struct hdmi_context *hdata = ctx;
  1461. struct drm_display_mode *m = mode;
  1462. DRM_DEBUG_KMS("xres=%d, yres=%d, refresh=%d, intl=%s\n",
  1463. m->hdisplay, m->vdisplay,
  1464. m->vrefresh, (m->flags & DRM_MODE_FLAG_INTERLACE) ?
  1465. "INTERLACED" : "PROGERESSIVE");
  1466. if (hdata->type == HDMI_TYPE13)
  1467. hdmi_v13_mode_set(hdata, mode);
  1468. else
  1469. hdmi_v14_mode_set(hdata, mode);
  1470. }
  1471. static void hdmi_get_max_resol(void *ctx, unsigned int *width,
  1472. unsigned int *height)
  1473. {
  1474. *width = MAX_WIDTH;
  1475. *height = MAX_HEIGHT;
  1476. }
  1477. static void hdmi_commit(void *ctx)
  1478. {
  1479. struct hdmi_context *hdata = ctx;
  1480. mutex_lock(&hdata->hdmi_mutex);
  1481. if (!hdata->powered) {
  1482. mutex_unlock(&hdata->hdmi_mutex);
  1483. return;
  1484. }
  1485. mutex_unlock(&hdata->hdmi_mutex);
  1486. hdmi_conf_apply(hdata);
  1487. }
  1488. static void hdmi_poweron(struct hdmi_context *hdata)
  1489. {
  1490. struct hdmi_resources *res = &hdata->res;
  1491. mutex_lock(&hdata->hdmi_mutex);
  1492. if (hdata->powered) {
  1493. mutex_unlock(&hdata->hdmi_mutex);
  1494. return;
  1495. }
  1496. hdata->powered = true;
  1497. mutex_unlock(&hdata->hdmi_mutex);
  1498. if (regulator_bulk_enable(res->regul_count, res->regul_bulk))
  1499. DRM_DEBUG_KMS("failed to enable regulator bulk\n");
  1500. clk_prepare_enable(res->hdmiphy);
  1501. clk_prepare_enable(res->hdmi);
  1502. clk_prepare_enable(res->sclk_hdmi);
  1503. hdmiphy_poweron(hdata);
  1504. }
  1505. static void hdmi_poweroff(struct hdmi_context *hdata)
  1506. {
  1507. struct hdmi_resources *res = &hdata->res;
  1508. mutex_lock(&hdata->hdmi_mutex);
  1509. if (!hdata->powered)
  1510. goto out;
  1511. mutex_unlock(&hdata->hdmi_mutex);
  1512. /*
  1513. * The TV power domain needs any condition of hdmiphy to turn off and
  1514. * its reset state seems to meet the condition.
  1515. */
  1516. hdmiphy_conf_reset(hdata);
  1517. hdmiphy_poweroff(hdata);
  1518. clk_disable_unprepare(res->sclk_hdmi);
  1519. clk_disable_unprepare(res->hdmi);
  1520. clk_disable_unprepare(res->hdmiphy);
  1521. regulator_bulk_disable(res->regul_count, res->regul_bulk);
  1522. mutex_lock(&hdata->hdmi_mutex);
  1523. hdata->powered = false;
  1524. out:
  1525. mutex_unlock(&hdata->hdmi_mutex);
  1526. }
  1527. static void hdmi_dpms(void *ctx, int mode)
  1528. {
  1529. struct hdmi_context *hdata = ctx;
  1530. DRM_DEBUG_KMS("mode %d\n", mode);
  1531. switch (mode) {
  1532. case DRM_MODE_DPMS_ON:
  1533. if (pm_runtime_suspended(hdata->dev))
  1534. pm_runtime_get_sync(hdata->dev);
  1535. break;
  1536. case DRM_MODE_DPMS_STANDBY:
  1537. case DRM_MODE_DPMS_SUSPEND:
  1538. case DRM_MODE_DPMS_OFF:
  1539. if (!pm_runtime_suspended(hdata->dev))
  1540. pm_runtime_put_sync(hdata->dev);
  1541. break;
  1542. default:
  1543. DRM_DEBUG_KMS("unknown dpms mode: %d\n", mode);
  1544. break;
  1545. }
  1546. }
  1547. static struct exynos_hdmi_ops hdmi_ops = {
  1548. /* display */
  1549. .is_connected = hdmi_is_connected,
  1550. .get_edid = hdmi_get_edid,
  1551. .check_mode = hdmi_check_mode,
  1552. /* manager */
  1553. .mode_set = hdmi_mode_set,
  1554. .get_max_resol = hdmi_get_max_resol,
  1555. .commit = hdmi_commit,
  1556. .dpms = hdmi_dpms,
  1557. };
  1558. static irqreturn_t hdmi_irq_thread(int irq, void *arg)
  1559. {
  1560. struct exynos_drm_hdmi_context *ctx = arg;
  1561. struct hdmi_context *hdata = ctx->ctx;
  1562. mutex_lock(&hdata->hdmi_mutex);
  1563. hdata->hpd = gpio_get_value(hdata->hpd_gpio);
  1564. mutex_unlock(&hdata->hdmi_mutex);
  1565. if (ctx->drm_dev)
  1566. drm_helper_hpd_irq_event(ctx->drm_dev);
  1567. return IRQ_HANDLED;
  1568. }
  1569. static int hdmi_resources_init(struct hdmi_context *hdata)
  1570. {
  1571. struct device *dev = hdata->dev;
  1572. struct hdmi_resources *res = &hdata->res;
  1573. static char *supply[] = {
  1574. "hdmi-en",
  1575. "vdd",
  1576. "vdd_osc",
  1577. "vdd_pll",
  1578. };
  1579. int i, ret;
  1580. DRM_DEBUG_KMS("HDMI resource init\n");
  1581. memset(res, 0, sizeof(*res));
  1582. /* get clocks, power */
  1583. res->hdmi = devm_clk_get(dev, "hdmi");
  1584. if (IS_ERR(res->hdmi)) {
  1585. DRM_ERROR("failed to get clock 'hdmi'\n");
  1586. goto fail;
  1587. }
  1588. res->sclk_hdmi = devm_clk_get(dev, "sclk_hdmi");
  1589. if (IS_ERR(res->sclk_hdmi)) {
  1590. DRM_ERROR("failed to get clock 'sclk_hdmi'\n");
  1591. goto fail;
  1592. }
  1593. res->sclk_pixel = devm_clk_get(dev, "sclk_pixel");
  1594. if (IS_ERR(res->sclk_pixel)) {
  1595. DRM_ERROR("failed to get clock 'sclk_pixel'\n");
  1596. goto fail;
  1597. }
  1598. res->sclk_hdmiphy = devm_clk_get(dev, "sclk_hdmiphy");
  1599. if (IS_ERR(res->sclk_hdmiphy)) {
  1600. DRM_ERROR("failed to get clock 'sclk_hdmiphy'\n");
  1601. goto fail;
  1602. }
  1603. res->hdmiphy = devm_clk_get(dev, "hdmiphy");
  1604. if (IS_ERR(res->hdmiphy)) {
  1605. DRM_ERROR("failed to get clock 'hdmiphy'\n");
  1606. goto fail;
  1607. }
  1608. res->mout_hdmi = devm_clk_get(dev, "mout_hdmi");
  1609. if (IS_ERR(res->mout_hdmi)) {
  1610. DRM_ERROR("failed to get clock 'mout_hdmi'\n");
  1611. goto fail;
  1612. }
  1613. clk_set_parent(res->mout_hdmi, res->sclk_pixel);
  1614. res->regul_bulk = devm_kzalloc(dev, ARRAY_SIZE(supply) *
  1615. sizeof(res->regul_bulk[0]), GFP_KERNEL);
  1616. if (!res->regul_bulk) {
  1617. DRM_ERROR("failed to get memory for regulators\n");
  1618. goto fail;
  1619. }
  1620. for (i = 0; i < ARRAY_SIZE(supply); ++i) {
  1621. res->regul_bulk[i].supply = supply[i];
  1622. res->regul_bulk[i].consumer = NULL;
  1623. }
  1624. ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(supply), res->regul_bulk);
  1625. if (ret) {
  1626. DRM_ERROR("failed to get regulators\n");
  1627. goto fail;
  1628. }
  1629. res->regul_count = ARRAY_SIZE(supply);
  1630. return 0;
  1631. fail:
  1632. DRM_ERROR("HDMI resource init - failed\n");
  1633. return -ENODEV;
  1634. }
  1635. static struct i2c_client *hdmi_ddc, *hdmi_hdmiphy;
  1636. void hdmi_attach_ddc_client(struct i2c_client *ddc)
  1637. {
  1638. if (ddc)
  1639. hdmi_ddc = ddc;
  1640. }
  1641. void hdmi_attach_hdmiphy_client(struct i2c_client *hdmiphy)
  1642. {
  1643. if (hdmiphy)
  1644. hdmi_hdmiphy = hdmiphy;
  1645. }
  1646. #ifdef CONFIG_OF
  1647. static struct s5p_hdmi_platform_data *drm_hdmi_dt_parse_pdata
  1648. (struct device *dev)
  1649. {
  1650. struct device_node *np = dev->of_node;
  1651. struct s5p_hdmi_platform_data *pd;
  1652. u32 value;
  1653. pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL);
  1654. if (!pd) {
  1655. DRM_ERROR("memory allocation for pdata failed\n");
  1656. goto err_data;
  1657. }
  1658. if (!of_find_property(np, "hpd-gpio", &value)) {
  1659. DRM_ERROR("no hpd gpio property found\n");
  1660. goto err_data;
  1661. }
  1662. pd->hpd_gpio = of_get_named_gpio(np, "hpd-gpio", 0);
  1663. return pd;
  1664. err_data:
  1665. return NULL;
  1666. }
  1667. #else
  1668. static struct s5p_hdmi_platform_data *drm_hdmi_dt_parse_pdata
  1669. (struct device *dev)
  1670. {
  1671. return NULL;
  1672. }
  1673. #endif
  1674. static struct platform_device_id hdmi_driver_types[] = {
  1675. {
  1676. .name = "s5pv210-hdmi",
  1677. .driver_data = HDMI_TYPE13,
  1678. }, {
  1679. .name = "exynos4-hdmi",
  1680. .driver_data = HDMI_TYPE13,
  1681. }, {
  1682. .name = "exynos4-hdmi14",
  1683. .driver_data = HDMI_TYPE14,
  1684. }, {
  1685. .name = "exynos5-hdmi",
  1686. .driver_data = HDMI_TYPE14,
  1687. }, {
  1688. /* end node */
  1689. }
  1690. };
  1691. #ifdef CONFIG_OF
  1692. static struct of_device_id hdmi_match_types[] = {
  1693. {
  1694. .compatible = "samsung,exynos5-hdmi",
  1695. .data = (void *)HDMI_TYPE14,
  1696. }, {
  1697. .compatible = "samsung,exynos4212-hdmi",
  1698. .data = (void *)HDMI_TYPE14,
  1699. }, {
  1700. /* end node */
  1701. }
  1702. };
  1703. #endif
  1704. static int hdmi_probe(struct platform_device *pdev)
  1705. {
  1706. struct device *dev = &pdev->dev;
  1707. struct exynos_drm_hdmi_context *drm_hdmi_ctx;
  1708. struct hdmi_context *hdata;
  1709. struct s5p_hdmi_platform_data *pdata;
  1710. struct resource *res;
  1711. int ret;
  1712. if (dev->of_node) {
  1713. pdata = drm_hdmi_dt_parse_pdata(dev);
  1714. if (IS_ERR(pdata)) {
  1715. DRM_ERROR("failed to parse dt\n");
  1716. return PTR_ERR(pdata);
  1717. }
  1718. } else {
  1719. pdata = dev->platform_data;
  1720. }
  1721. if (!pdata) {
  1722. DRM_ERROR("no platform data specified\n");
  1723. return -EINVAL;
  1724. }
  1725. drm_hdmi_ctx = devm_kzalloc(dev, sizeof(*drm_hdmi_ctx),
  1726. GFP_KERNEL);
  1727. if (!drm_hdmi_ctx) {
  1728. DRM_ERROR("failed to allocate common hdmi context.\n");
  1729. return -ENOMEM;
  1730. }
  1731. hdata = devm_kzalloc(dev, sizeof(struct hdmi_context),
  1732. GFP_KERNEL);
  1733. if (!hdata) {
  1734. DRM_ERROR("out of memory\n");
  1735. return -ENOMEM;
  1736. }
  1737. mutex_init(&hdata->hdmi_mutex);
  1738. drm_hdmi_ctx->ctx = (void *)hdata;
  1739. hdata->parent_ctx = (void *)drm_hdmi_ctx;
  1740. platform_set_drvdata(pdev, drm_hdmi_ctx);
  1741. if (dev->of_node) {
  1742. const struct of_device_id *match;
  1743. match = of_match_node(of_match_ptr(hdmi_match_types),
  1744. dev->of_node);
  1745. if (match == NULL)
  1746. return -ENODEV;
  1747. hdata->type = (enum hdmi_type)match->data;
  1748. } else {
  1749. hdata->type = (enum hdmi_type)platform_get_device_id
  1750. (pdev)->driver_data;
  1751. }
  1752. hdata->hpd_gpio = pdata->hpd_gpio;
  1753. hdata->dev = dev;
  1754. ret = hdmi_resources_init(hdata);
  1755. if (ret) {
  1756. DRM_ERROR("hdmi_resources_init failed\n");
  1757. return -EINVAL;
  1758. }
  1759. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1760. hdata->regs = devm_ioremap_resource(dev, res);
  1761. if (IS_ERR(hdata->regs))
  1762. return PTR_ERR(hdata->regs);
  1763. ret = devm_gpio_request(dev, hdata->hpd_gpio, "HPD");
  1764. if (ret) {
  1765. DRM_ERROR("failed to request HPD gpio\n");
  1766. return ret;
  1767. }
  1768. /* DDC i2c driver */
  1769. if (i2c_add_driver(&ddc_driver)) {
  1770. DRM_ERROR("failed to register ddc i2c driver\n");
  1771. return -ENOENT;
  1772. }
  1773. hdata->ddc_port = hdmi_ddc;
  1774. /* hdmiphy i2c driver */
  1775. if (i2c_add_driver(&hdmiphy_driver)) {
  1776. DRM_ERROR("failed to register hdmiphy i2c driver\n");
  1777. ret = -ENOENT;
  1778. goto err_ddc;
  1779. }
  1780. hdata->hdmiphy_port = hdmi_hdmiphy;
  1781. hdata->irq = gpio_to_irq(hdata->hpd_gpio);
  1782. if (hdata->irq < 0) {
  1783. DRM_ERROR("failed to get GPIO irq\n");
  1784. ret = hdata->irq;
  1785. goto err_hdmiphy;
  1786. }
  1787. hdata->hpd = gpio_get_value(hdata->hpd_gpio);
  1788. ret = devm_request_threaded_irq(dev, hdata->irq, NULL,
  1789. hdmi_irq_thread, IRQF_TRIGGER_RISING |
  1790. IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
  1791. "hdmi", drm_hdmi_ctx);
  1792. if (ret) {
  1793. DRM_ERROR("failed to register hdmi interrupt\n");
  1794. goto err_hdmiphy;
  1795. }
  1796. /* Attach HDMI Driver to common hdmi. */
  1797. exynos_hdmi_drv_attach(drm_hdmi_ctx);
  1798. /* register specific callbacks to common hdmi. */
  1799. exynos_hdmi_ops_register(&hdmi_ops);
  1800. pm_runtime_enable(dev);
  1801. return 0;
  1802. err_hdmiphy:
  1803. i2c_del_driver(&hdmiphy_driver);
  1804. err_ddc:
  1805. i2c_del_driver(&ddc_driver);
  1806. return ret;
  1807. }
  1808. static int hdmi_remove(struct platform_device *pdev)
  1809. {
  1810. struct device *dev = &pdev->dev;
  1811. pm_runtime_disable(dev);
  1812. /* hdmiphy i2c driver */
  1813. i2c_del_driver(&hdmiphy_driver);
  1814. /* DDC i2c driver */
  1815. i2c_del_driver(&ddc_driver);
  1816. return 0;
  1817. }
  1818. #ifdef CONFIG_PM_SLEEP
  1819. static int hdmi_suspend(struct device *dev)
  1820. {
  1821. struct exynos_drm_hdmi_context *ctx = get_hdmi_context(dev);
  1822. struct hdmi_context *hdata = ctx->ctx;
  1823. disable_irq(hdata->irq);
  1824. hdata->hpd = false;
  1825. if (ctx->drm_dev)
  1826. drm_helper_hpd_irq_event(ctx->drm_dev);
  1827. if (pm_runtime_suspended(dev)) {
  1828. DRM_DEBUG_KMS("Already suspended\n");
  1829. return 0;
  1830. }
  1831. hdmi_poweroff(hdata);
  1832. return 0;
  1833. }
  1834. static int hdmi_resume(struct device *dev)
  1835. {
  1836. struct exynos_drm_hdmi_context *ctx = get_hdmi_context(dev);
  1837. struct hdmi_context *hdata = ctx->ctx;
  1838. hdata->hpd = gpio_get_value(hdata->hpd_gpio);
  1839. enable_irq(hdata->irq);
  1840. if (!pm_runtime_suspended(dev)) {
  1841. DRM_DEBUG_KMS("Already resumed\n");
  1842. return 0;
  1843. }
  1844. hdmi_poweron(hdata);
  1845. return 0;
  1846. }
  1847. #endif
  1848. #ifdef CONFIG_PM_RUNTIME
  1849. static int hdmi_runtime_suspend(struct device *dev)
  1850. {
  1851. struct exynos_drm_hdmi_context *ctx = get_hdmi_context(dev);
  1852. struct hdmi_context *hdata = ctx->ctx;
  1853. hdmi_poweroff(hdata);
  1854. return 0;
  1855. }
  1856. static int hdmi_runtime_resume(struct device *dev)
  1857. {
  1858. struct exynos_drm_hdmi_context *ctx = get_hdmi_context(dev);
  1859. struct hdmi_context *hdata = ctx->ctx;
  1860. hdmi_poweron(hdata);
  1861. return 0;
  1862. }
  1863. #endif
  1864. static const struct dev_pm_ops hdmi_pm_ops = {
  1865. SET_SYSTEM_SLEEP_PM_OPS(hdmi_suspend, hdmi_resume)
  1866. SET_RUNTIME_PM_OPS(hdmi_runtime_suspend, hdmi_runtime_resume, NULL)
  1867. };
  1868. struct platform_driver hdmi_driver = {
  1869. .probe = hdmi_probe,
  1870. .remove = hdmi_remove,
  1871. .id_table = hdmi_driver_types,
  1872. .driver = {
  1873. .name = "exynos-hdmi",
  1874. .owner = THIS_MODULE,
  1875. .pm = &hdmi_pm_ops,
  1876. .of_match_table = of_match_ptr(hdmi_match_types),
  1877. },
  1878. };