exynos_hdmi.c 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539
  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/platform_device.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/irq.h>
  27. #include <linux/delay.h>
  28. #include <linux/pm_runtime.h>
  29. #include <linux/clk.h>
  30. #include <linux/regulator/consumer.h>
  31. #include <linux/io.h>
  32. #include <linux/of.h>
  33. #include <linux/of_address.h>
  34. #include <linux/of_gpio.h>
  35. #include <linux/hdmi.h>
  36. #include <linux/component.h>
  37. #include <linux/mfd/syscon.h>
  38. #include <linux/regmap.h>
  39. #include <drm/exynos_drm.h>
  40. #include "exynos_drm_drv.h"
  41. #include "exynos_drm_crtc.h"
  42. #include "exynos_mixer.h"
  43. #include <linux/gpio.h>
  44. #include <media/s5p_hdmi.h>
  45. #define get_hdmi_display(dev) platform_get_drvdata(to_platform_device(dev))
  46. #define ctx_from_connector(c) container_of(c, struct hdmi_context, connector)
  47. #define HOTPLUG_DEBOUNCE_MS 1100
  48. /* AVI header and aspect ratio */
  49. #define HDMI_AVI_VERSION 0x02
  50. #define HDMI_AVI_LENGTH 0x0D
  51. /* AUI header info */
  52. #define HDMI_AUI_VERSION 0x01
  53. #define HDMI_AUI_LENGTH 0x0A
  54. #define AVI_SAME_AS_PIC_ASPECT_RATIO 0x8
  55. #define AVI_4_3_CENTER_RATIO 0x9
  56. #define AVI_16_9_CENTER_RATIO 0xa
  57. enum hdmi_type {
  58. HDMI_TYPE13,
  59. HDMI_TYPE14,
  60. };
  61. struct hdmi_driver_data {
  62. unsigned int type;
  63. const struct hdmiphy_config *phy_confs;
  64. unsigned int phy_conf_count;
  65. unsigned int is_apb_phy:1;
  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 *mout_hdmi;
  73. struct regulator_bulk_data *regul_bulk;
  74. struct regulator *reg_hdmi_en;
  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. enum hdmi_picture_aspect aspect_ratio;
  159. union {
  160. struct hdmi_v13_conf v13_conf;
  161. struct hdmi_v14_conf v14_conf;
  162. } conf;
  163. };
  164. struct hdmi_context {
  165. struct device *dev;
  166. struct drm_device *drm_dev;
  167. struct drm_connector connector;
  168. struct drm_encoder *encoder;
  169. bool hpd;
  170. bool powered;
  171. bool dvi_mode;
  172. struct mutex hdmi_mutex;
  173. void __iomem *regs;
  174. int irq;
  175. struct delayed_work hotplug_work;
  176. struct i2c_adapter *ddc_adpt;
  177. struct i2c_client *hdmiphy_port;
  178. /* current hdmiphy conf regs */
  179. struct drm_display_mode current_mode;
  180. struct hdmi_conf_regs mode_conf;
  181. struct hdmi_resources res;
  182. int hpd_gpio;
  183. void __iomem *regs_hdmiphy;
  184. const struct hdmiphy_config *phy_confs;
  185. unsigned int phy_conf_count;
  186. struct regmap *pmureg;
  187. enum hdmi_type type;
  188. };
  189. struct hdmiphy_config {
  190. int pixel_clock;
  191. u8 conf[32];
  192. };
  193. /* list of phy config settings */
  194. static const struct hdmiphy_config hdmiphy_v13_configs[] = {
  195. {
  196. .pixel_clock = 27000000,
  197. .conf = {
  198. 0x01, 0x05, 0x00, 0xD8, 0x10, 0x1C, 0x30, 0x40,
  199. 0x6B, 0x10, 0x02, 0x51, 0xDF, 0xF2, 0x54, 0x87,
  200. 0x84, 0x00, 0x30, 0x38, 0x00, 0x08, 0x10, 0xE0,
  201. 0x22, 0x40, 0xE3, 0x26, 0x00, 0x00, 0x00, 0x00,
  202. },
  203. },
  204. {
  205. .pixel_clock = 27027000,
  206. .conf = {
  207. 0x01, 0x05, 0x00, 0xD4, 0x10, 0x9C, 0x09, 0x64,
  208. 0x6B, 0x10, 0x02, 0x51, 0xDF, 0xF2, 0x54, 0x87,
  209. 0x84, 0x00, 0x30, 0x38, 0x00, 0x08, 0x10, 0xE0,
  210. 0x22, 0x40, 0xE3, 0x26, 0x00, 0x00, 0x00, 0x00,
  211. },
  212. },
  213. {
  214. .pixel_clock = 74176000,
  215. .conf = {
  216. 0x01, 0x05, 0x00, 0xD8, 0x10, 0x9C, 0xef, 0x5B,
  217. 0x6D, 0x10, 0x01, 0x51, 0xef, 0xF3, 0x54, 0xb9,
  218. 0x84, 0x00, 0x30, 0x38, 0x00, 0x08, 0x10, 0xE0,
  219. 0x22, 0x40, 0xa5, 0x26, 0x01, 0x00, 0x00, 0x00,
  220. },
  221. },
  222. {
  223. .pixel_clock = 74250000,
  224. .conf = {
  225. 0x01, 0x05, 0x00, 0xd8, 0x10, 0x9c, 0xf8, 0x40,
  226. 0x6a, 0x10, 0x01, 0x51, 0xff, 0xf1, 0x54, 0xba,
  227. 0x84, 0x00, 0x10, 0x38, 0x00, 0x08, 0x10, 0xe0,
  228. 0x22, 0x40, 0xa4, 0x26, 0x01, 0x00, 0x00, 0x00,
  229. },
  230. },
  231. {
  232. .pixel_clock = 148500000,
  233. .conf = {
  234. 0x01, 0x05, 0x00, 0xD8, 0x10, 0x9C, 0xf8, 0x40,
  235. 0x6A, 0x18, 0x00, 0x51, 0xff, 0xF1, 0x54, 0xba,
  236. 0x84, 0x00, 0x10, 0x38, 0x00, 0x08, 0x10, 0xE0,
  237. 0x22, 0x40, 0xa4, 0x26, 0x02, 0x00, 0x00, 0x00,
  238. },
  239. },
  240. };
  241. static const struct hdmiphy_config hdmiphy_v14_configs[] = {
  242. {
  243. .pixel_clock = 25200000,
  244. .conf = {
  245. 0x01, 0x51, 0x2A, 0x75, 0x40, 0x01, 0x00, 0x08,
  246. 0x82, 0x80, 0xfc, 0xd8, 0x45, 0xa0, 0xac, 0x80,
  247. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  248. 0x54, 0xf4, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  249. },
  250. },
  251. {
  252. .pixel_clock = 27000000,
  253. .conf = {
  254. 0x01, 0xd1, 0x22, 0x51, 0x40, 0x08, 0xfc, 0x20,
  255. 0x98, 0xa0, 0xcb, 0xd8, 0x45, 0xa0, 0xac, 0x80,
  256. 0x06, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  257. 0x54, 0xe4, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  258. },
  259. },
  260. {
  261. .pixel_clock = 27027000,
  262. .conf = {
  263. 0x01, 0xd1, 0x2d, 0x72, 0x40, 0x64, 0x12, 0x08,
  264. 0x43, 0xa0, 0x0e, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  265. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  266. 0x54, 0xe3, 0x24, 0x00, 0x00, 0x00, 0x01, 0x00,
  267. },
  268. },
  269. {
  270. .pixel_clock = 36000000,
  271. .conf = {
  272. 0x01, 0x51, 0x2d, 0x55, 0x40, 0x01, 0x00, 0x08,
  273. 0x82, 0x80, 0x0e, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  274. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  275. 0x54, 0xab, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  276. },
  277. },
  278. {
  279. .pixel_clock = 40000000,
  280. .conf = {
  281. 0x01, 0x51, 0x32, 0x55, 0x40, 0x01, 0x00, 0x08,
  282. 0x82, 0x80, 0x2c, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  283. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  284. 0x54, 0x9a, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  285. },
  286. },
  287. {
  288. .pixel_clock = 65000000,
  289. .conf = {
  290. 0x01, 0xd1, 0x36, 0x34, 0x40, 0x1e, 0x0a, 0x08,
  291. 0x82, 0xa0, 0x45, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  292. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  293. 0x54, 0xbd, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  294. },
  295. },
  296. {
  297. .pixel_clock = 71000000,
  298. .conf = {
  299. 0x01, 0xd1, 0x3b, 0x35, 0x40, 0x0c, 0x04, 0x08,
  300. 0x85, 0xa0, 0x63, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  301. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  302. 0x54, 0xad, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  303. },
  304. },
  305. {
  306. .pixel_clock = 73250000,
  307. .conf = {
  308. 0x01, 0xd1, 0x3d, 0x35, 0x40, 0x18, 0x02, 0x08,
  309. 0x83, 0xa0, 0x6e, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  310. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  311. 0x54, 0xa8, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  312. },
  313. },
  314. {
  315. .pixel_clock = 74176000,
  316. .conf = {
  317. 0x01, 0xd1, 0x3e, 0x35, 0x40, 0x5b, 0xde, 0x08,
  318. 0x82, 0xa0, 0x73, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  319. 0x56, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  320. 0x54, 0xa6, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  321. },
  322. },
  323. {
  324. .pixel_clock = 74250000,
  325. .conf = {
  326. 0x01, 0xd1, 0x1f, 0x10, 0x40, 0x40, 0xf8, 0x08,
  327. 0x81, 0xa0, 0xba, 0xd8, 0x45, 0xa0, 0xac, 0x80,
  328. 0x3c, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  329. 0x54, 0xa5, 0x24, 0x01, 0x00, 0x00, 0x01, 0x00,
  330. },
  331. },
  332. {
  333. .pixel_clock = 83500000,
  334. .conf = {
  335. 0x01, 0xd1, 0x23, 0x11, 0x40, 0x0c, 0xfb, 0x08,
  336. 0x85, 0xa0, 0xd1, 0xd8, 0x45, 0xa0, 0xac, 0x80,
  337. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  338. 0x54, 0x93, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  339. },
  340. },
  341. {
  342. .pixel_clock = 106500000,
  343. .conf = {
  344. 0x01, 0xd1, 0x2c, 0x12, 0x40, 0x0c, 0x09, 0x08,
  345. 0x84, 0xa0, 0x0a, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  346. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  347. 0x54, 0x73, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  348. },
  349. },
  350. {
  351. .pixel_clock = 108000000,
  352. .conf = {
  353. 0x01, 0x51, 0x2d, 0x15, 0x40, 0x01, 0x00, 0x08,
  354. 0x82, 0x80, 0x0e, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  355. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  356. 0x54, 0xc7, 0x25, 0x03, 0x00, 0x00, 0x01, 0x80,
  357. },
  358. },
  359. {
  360. .pixel_clock = 115500000,
  361. .conf = {
  362. 0x01, 0xd1, 0x30, 0x12, 0x40, 0x40, 0x10, 0x08,
  363. 0x80, 0x80, 0x21, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  364. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  365. 0x54, 0xaa, 0x25, 0x03, 0x00, 0x00, 0x01, 0x80,
  366. },
  367. },
  368. {
  369. .pixel_clock = 119000000,
  370. .conf = {
  371. 0x01, 0xd1, 0x32, 0x1a, 0x40, 0x30, 0xd8, 0x08,
  372. 0x04, 0xa0, 0x2a, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  373. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  374. 0x54, 0x9d, 0x25, 0x03, 0x00, 0x00, 0x01, 0x80,
  375. },
  376. },
  377. {
  378. .pixel_clock = 146250000,
  379. .conf = {
  380. 0x01, 0xd1, 0x3d, 0x15, 0x40, 0x18, 0xfd, 0x08,
  381. 0x83, 0xa0, 0x6e, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  382. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  383. 0x54, 0x50, 0x25, 0x03, 0x00, 0x00, 0x01, 0x80,
  384. },
  385. },
  386. {
  387. .pixel_clock = 148500000,
  388. .conf = {
  389. 0x01, 0xd1, 0x1f, 0x00, 0x40, 0x40, 0xf8, 0x08,
  390. 0x81, 0xa0, 0xba, 0xd8, 0x45, 0xa0, 0xac, 0x80,
  391. 0x3c, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  392. 0x54, 0x4b, 0x25, 0x03, 0x00, 0x00, 0x01, 0x00,
  393. },
  394. },
  395. };
  396. static const struct hdmiphy_config hdmiphy_5420_configs[] = {
  397. {
  398. .pixel_clock = 25200000,
  399. .conf = {
  400. 0x01, 0x52, 0x3F, 0x55, 0x40, 0x01, 0x00, 0xC8,
  401. 0x82, 0xC8, 0xBD, 0xD8, 0x45, 0xA0, 0xAC, 0x80,
  402. 0x06, 0x80, 0x01, 0x84, 0x05, 0x02, 0x24, 0x66,
  403. 0x54, 0xF4, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  404. },
  405. },
  406. {
  407. .pixel_clock = 27000000,
  408. .conf = {
  409. 0x01, 0xD1, 0x22, 0x51, 0x40, 0x08, 0xFC, 0xE0,
  410. 0x98, 0xE8, 0xCB, 0xD8, 0x45, 0xA0, 0xAC, 0x80,
  411. 0x06, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  412. 0x54, 0xE4, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  413. },
  414. },
  415. {
  416. .pixel_clock = 27027000,
  417. .conf = {
  418. 0x01, 0xD1, 0x2D, 0x72, 0x40, 0x64, 0x12, 0xC8,
  419. 0x43, 0xE8, 0x0E, 0xD9, 0x45, 0xA0, 0xAC, 0x80,
  420. 0x26, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  421. 0x54, 0xE3, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  422. },
  423. },
  424. {
  425. .pixel_clock = 36000000,
  426. .conf = {
  427. 0x01, 0x51, 0x2D, 0x55, 0x40, 0x40, 0x00, 0xC8,
  428. 0x02, 0xC8, 0x0E, 0xD9, 0x45, 0xA0, 0xAC, 0x80,
  429. 0x08, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  430. 0x54, 0xAB, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  431. },
  432. },
  433. {
  434. .pixel_clock = 40000000,
  435. .conf = {
  436. 0x01, 0xD1, 0x21, 0x31, 0x40, 0x3C, 0x28, 0xC8,
  437. 0x87, 0xE8, 0xC8, 0xD8, 0x45, 0xA0, 0xAC, 0x80,
  438. 0x08, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  439. 0x54, 0x9A, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  440. },
  441. },
  442. {
  443. .pixel_clock = 65000000,
  444. .conf = {
  445. 0x01, 0xD1, 0x36, 0x34, 0x40, 0x0C, 0x04, 0xC8,
  446. 0x82, 0xE8, 0x45, 0xD9, 0x45, 0xA0, 0xAC, 0x80,
  447. 0x08, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  448. 0x54, 0xBD, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  449. },
  450. },
  451. {
  452. .pixel_clock = 71000000,
  453. .conf = {
  454. 0x01, 0xD1, 0x3B, 0x35, 0x40, 0x0C, 0x04, 0xC8,
  455. 0x85, 0xE8, 0x63, 0xD9, 0x45, 0xA0, 0xAC, 0x80,
  456. 0x08, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  457. 0x54, 0x57, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  458. },
  459. },
  460. {
  461. .pixel_clock = 73250000,
  462. .conf = {
  463. 0x01, 0xD1, 0x1F, 0x10, 0x40, 0x78, 0x8D, 0xC8,
  464. 0x81, 0xE8, 0xB7, 0xD8, 0x45, 0xA0, 0xAC, 0x80,
  465. 0x56, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  466. 0x54, 0xA8, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  467. },
  468. },
  469. {
  470. .pixel_clock = 74176000,
  471. .conf = {
  472. 0x01, 0xD1, 0x1F, 0x10, 0x40, 0x5B, 0xEF, 0xC8,
  473. 0x81, 0xE8, 0xB9, 0xD8, 0x45, 0xA0, 0xAC, 0x80,
  474. 0x56, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  475. 0x54, 0xA6, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  476. },
  477. },
  478. {
  479. .pixel_clock = 74250000,
  480. .conf = {
  481. 0x01, 0xD1, 0x1F, 0x10, 0x40, 0x40, 0xF8, 0x08,
  482. 0x81, 0xE8, 0xBA, 0xD8, 0x45, 0xA0, 0xAC, 0x80,
  483. 0x26, 0x80, 0x09, 0x84, 0x05, 0x22, 0x24, 0x66,
  484. 0x54, 0xA5, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  485. },
  486. },
  487. {
  488. .pixel_clock = 83500000,
  489. .conf = {
  490. 0x01, 0xD1, 0x23, 0x11, 0x40, 0x0C, 0xFB, 0xC8,
  491. 0x85, 0xE8, 0xD1, 0xD8, 0x45, 0xA0, 0xAC, 0x80,
  492. 0x08, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  493. 0x54, 0x4A, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  494. },
  495. },
  496. {
  497. .pixel_clock = 88750000,
  498. .conf = {
  499. 0x01, 0xD1, 0x25, 0x11, 0x40, 0x18, 0xFF, 0xC8,
  500. 0x83, 0xE8, 0xDE, 0xD8, 0x45, 0xA0, 0xAC, 0x80,
  501. 0x08, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  502. 0x54, 0x45, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  503. },
  504. },
  505. {
  506. .pixel_clock = 106500000,
  507. .conf = {
  508. 0x01, 0xD1, 0x2C, 0x12, 0x40, 0x0C, 0x09, 0xC8,
  509. 0x84, 0xE8, 0x0A, 0xD9, 0x45, 0xA0, 0xAC, 0x80,
  510. 0x08, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  511. 0x54, 0x73, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  512. },
  513. },
  514. {
  515. .pixel_clock = 108000000,
  516. .conf = {
  517. 0x01, 0x51, 0x2D, 0x15, 0x40, 0x01, 0x00, 0xC8,
  518. 0x82, 0xC8, 0x0E, 0xD9, 0x45, 0xA0, 0xAC, 0x80,
  519. 0x08, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  520. 0x54, 0xC7, 0x25, 0x03, 0x00, 0x00, 0x01, 0x80,
  521. },
  522. },
  523. {
  524. .pixel_clock = 115500000,
  525. .conf = {
  526. 0x01, 0xD1, 0x30, 0x14, 0x40, 0x0C, 0x03, 0xC8,
  527. 0x88, 0xE8, 0x21, 0xD9, 0x45, 0xA0, 0xAC, 0x80,
  528. 0x08, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  529. 0x54, 0x6A, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  530. },
  531. },
  532. {
  533. .pixel_clock = 146250000,
  534. .conf = {
  535. 0x01, 0xD1, 0x3D, 0x15, 0x40, 0x18, 0xFD, 0xC8,
  536. 0x83, 0xE8, 0x6E, 0xD9, 0x45, 0xA0, 0xAC, 0x80,
  537. 0x08, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  538. 0x54, 0x54, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  539. },
  540. },
  541. {
  542. .pixel_clock = 148500000,
  543. .conf = {
  544. 0x01, 0xD1, 0x1F, 0x00, 0x40, 0x40, 0xF8, 0x08,
  545. 0x81, 0xE8, 0xBA, 0xD8, 0x45, 0xA0, 0xAC, 0x80,
  546. 0x26, 0x80, 0x09, 0x84, 0x05, 0x22, 0x24, 0x66,
  547. 0x54, 0x4B, 0x25, 0x03, 0x00, 0x80, 0x01, 0x80,
  548. },
  549. },
  550. };
  551. static struct hdmi_driver_data exynos5420_hdmi_driver_data = {
  552. .type = HDMI_TYPE14,
  553. .phy_confs = hdmiphy_5420_configs,
  554. .phy_conf_count = ARRAY_SIZE(hdmiphy_5420_configs),
  555. .is_apb_phy = 1,
  556. };
  557. static struct hdmi_driver_data exynos4212_hdmi_driver_data = {
  558. .type = HDMI_TYPE14,
  559. .phy_confs = hdmiphy_v14_configs,
  560. .phy_conf_count = ARRAY_SIZE(hdmiphy_v14_configs),
  561. .is_apb_phy = 0,
  562. };
  563. static struct hdmi_driver_data exynos4210_hdmi_driver_data = {
  564. .type = HDMI_TYPE13,
  565. .phy_confs = hdmiphy_v13_configs,
  566. .phy_conf_count = ARRAY_SIZE(hdmiphy_v13_configs),
  567. .is_apb_phy = 0,
  568. };
  569. static struct hdmi_driver_data exynos5_hdmi_driver_data = {
  570. .type = HDMI_TYPE14,
  571. .phy_confs = hdmiphy_v13_configs,
  572. .phy_conf_count = ARRAY_SIZE(hdmiphy_v13_configs),
  573. .is_apb_phy = 0,
  574. };
  575. static inline u32 hdmi_reg_read(struct hdmi_context *hdata, u32 reg_id)
  576. {
  577. return readl(hdata->regs + reg_id);
  578. }
  579. static inline void hdmi_reg_writeb(struct hdmi_context *hdata,
  580. u32 reg_id, u8 value)
  581. {
  582. writeb(value, hdata->regs + reg_id);
  583. }
  584. static inline void hdmi_reg_writemask(struct hdmi_context *hdata,
  585. u32 reg_id, u32 value, u32 mask)
  586. {
  587. u32 old = readl(hdata->regs + reg_id);
  588. value = (value & mask) | (old & ~mask);
  589. writel(value, hdata->regs + reg_id);
  590. }
  591. static int hdmiphy_reg_writeb(struct hdmi_context *hdata,
  592. u32 reg_offset, u8 value)
  593. {
  594. if (hdata->hdmiphy_port) {
  595. u8 buffer[2];
  596. int ret;
  597. buffer[0] = reg_offset;
  598. buffer[1] = value;
  599. ret = i2c_master_send(hdata->hdmiphy_port, buffer, 2);
  600. if (ret == 2)
  601. return 0;
  602. return ret;
  603. } else {
  604. writeb(value, hdata->regs_hdmiphy + (reg_offset<<2));
  605. return 0;
  606. }
  607. }
  608. static int hdmiphy_reg_write_buf(struct hdmi_context *hdata,
  609. u32 reg_offset, const u8 *buf, u32 len)
  610. {
  611. if ((reg_offset + len) > 32)
  612. return -EINVAL;
  613. if (hdata->hdmiphy_port) {
  614. int ret;
  615. ret = i2c_master_send(hdata->hdmiphy_port, buf, len);
  616. if (ret == len)
  617. return 0;
  618. return ret;
  619. } else {
  620. int i;
  621. for (i = 0; i < len; i++)
  622. writeb(buf[i], hdata->regs_hdmiphy +
  623. ((reg_offset + i)<<2));
  624. return 0;
  625. }
  626. }
  627. static void hdmi_v13_regs_dump(struct hdmi_context *hdata, char *prefix)
  628. {
  629. #define DUMPREG(reg_id) \
  630. DRM_DEBUG_KMS("%s:" #reg_id " = %08x\n", prefix, \
  631. readl(hdata->regs + reg_id))
  632. DRM_DEBUG_KMS("%s: ---- CONTROL REGISTERS ----\n", prefix);
  633. DUMPREG(HDMI_INTC_FLAG);
  634. DUMPREG(HDMI_INTC_CON);
  635. DUMPREG(HDMI_HPD_STATUS);
  636. DUMPREG(HDMI_V13_PHY_RSTOUT);
  637. DUMPREG(HDMI_V13_PHY_VPLL);
  638. DUMPREG(HDMI_V13_PHY_CMU);
  639. DUMPREG(HDMI_V13_CORE_RSTOUT);
  640. DRM_DEBUG_KMS("%s: ---- CORE REGISTERS ----\n", prefix);
  641. DUMPREG(HDMI_CON_0);
  642. DUMPREG(HDMI_CON_1);
  643. DUMPREG(HDMI_CON_2);
  644. DUMPREG(HDMI_SYS_STATUS);
  645. DUMPREG(HDMI_V13_PHY_STATUS);
  646. DUMPREG(HDMI_STATUS_EN);
  647. DUMPREG(HDMI_HPD);
  648. DUMPREG(HDMI_MODE_SEL);
  649. DUMPREG(HDMI_V13_HPD_GEN);
  650. DUMPREG(HDMI_V13_DC_CONTROL);
  651. DUMPREG(HDMI_V13_VIDEO_PATTERN_GEN);
  652. DRM_DEBUG_KMS("%s: ---- CORE SYNC REGISTERS ----\n", prefix);
  653. DUMPREG(HDMI_H_BLANK_0);
  654. DUMPREG(HDMI_H_BLANK_1);
  655. DUMPREG(HDMI_V13_V_BLANK_0);
  656. DUMPREG(HDMI_V13_V_BLANK_1);
  657. DUMPREG(HDMI_V13_V_BLANK_2);
  658. DUMPREG(HDMI_V13_H_V_LINE_0);
  659. DUMPREG(HDMI_V13_H_V_LINE_1);
  660. DUMPREG(HDMI_V13_H_V_LINE_2);
  661. DUMPREG(HDMI_VSYNC_POL);
  662. DUMPREG(HDMI_INT_PRO_MODE);
  663. DUMPREG(HDMI_V13_V_BLANK_F_0);
  664. DUMPREG(HDMI_V13_V_BLANK_F_1);
  665. DUMPREG(HDMI_V13_V_BLANK_F_2);
  666. DUMPREG(HDMI_V13_H_SYNC_GEN_0);
  667. DUMPREG(HDMI_V13_H_SYNC_GEN_1);
  668. DUMPREG(HDMI_V13_H_SYNC_GEN_2);
  669. DUMPREG(HDMI_V13_V_SYNC_GEN_1_0);
  670. DUMPREG(HDMI_V13_V_SYNC_GEN_1_1);
  671. DUMPREG(HDMI_V13_V_SYNC_GEN_1_2);
  672. DUMPREG(HDMI_V13_V_SYNC_GEN_2_0);
  673. DUMPREG(HDMI_V13_V_SYNC_GEN_2_1);
  674. DUMPREG(HDMI_V13_V_SYNC_GEN_2_2);
  675. DUMPREG(HDMI_V13_V_SYNC_GEN_3_0);
  676. DUMPREG(HDMI_V13_V_SYNC_GEN_3_1);
  677. DUMPREG(HDMI_V13_V_SYNC_GEN_3_2);
  678. DRM_DEBUG_KMS("%s: ---- TG REGISTERS ----\n", prefix);
  679. DUMPREG(HDMI_TG_CMD);
  680. DUMPREG(HDMI_TG_H_FSZ_L);
  681. DUMPREG(HDMI_TG_H_FSZ_H);
  682. DUMPREG(HDMI_TG_HACT_ST_L);
  683. DUMPREG(HDMI_TG_HACT_ST_H);
  684. DUMPREG(HDMI_TG_HACT_SZ_L);
  685. DUMPREG(HDMI_TG_HACT_SZ_H);
  686. DUMPREG(HDMI_TG_V_FSZ_L);
  687. DUMPREG(HDMI_TG_V_FSZ_H);
  688. DUMPREG(HDMI_TG_VSYNC_L);
  689. DUMPREG(HDMI_TG_VSYNC_H);
  690. DUMPREG(HDMI_TG_VSYNC2_L);
  691. DUMPREG(HDMI_TG_VSYNC2_H);
  692. DUMPREG(HDMI_TG_VACT_ST_L);
  693. DUMPREG(HDMI_TG_VACT_ST_H);
  694. DUMPREG(HDMI_TG_VACT_SZ_L);
  695. DUMPREG(HDMI_TG_VACT_SZ_H);
  696. DUMPREG(HDMI_TG_FIELD_CHG_L);
  697. DUMPREG(HDMI_TG_FIELD_CHG_H);
  698. DUMPREG(HDMI_TG_VACT_ST2_L);
  699. DUMPREG(HDMI_TG_VACT_ST2_H);
  700. DUMPREG(HDMI_TG_VSYNC_TOP_HDMI_L);
  701. DUMPREG(HDMI_TG_VSYNC_TOP_HDMI_H);
  702. DUMPREG(HDMI_TG_VSYNC_BOT_HDMI_L);
  703. DUMPREG(HDMI_TG_VSYNC_BOT_HDMI_H);
  704. DUMPREG(HDMI_TG_FIELD_TOP_HDMI_L);
  705. DUMPREG(HDMI_TG_FIELD_TOP_HDMI_H);
  706. DUMPREG(HDMI_TG_FIELD_BOT_HDMI_L);
  707. DUMPREG(HDMI_TG_FIELD_BOT_HDMI_H);
  708. #undef DUMPREG
  709. }
  710. static void hdmi_v14_regs_dump(struct hdmi_context *hdata, char *prefix)
  711. {
  712. int i;
  713. #define DUMPREG(reg_id) \
  714. DRM_DEBUG_KMS("%s:" #reg_id " = %08x\n", prefix, \
  715. readl(hdata->regs + reg_id))
  716. DRM_DEBUG_KMS("%s: ---- CONTROL REGISTERS ----\n", prefix);
  717. DUMPREG(HDMI_INTC_CON);
  718. DUMPREG(HDMI_INTC_FLAG);
  719. DUMPREG(HDMI_HPD_STATUS);
  720. DUMPREG(HDMI_INTC_CON_1);
  721. DUMPREG(HDMI_INTC_FLAG_1);
  722. DUMPREG(HDMI_PHY_STATUS_0);
  723. DUMPREG(HDMI_PHY_STATUS_PLL);
  724. DUMPREG(HDMI_PHY_CON_0);
  725. DUMPREG(HDMI_PHY_RSTOUT);
  726. DUMPREG(HDMI_PHY_VPLL);
  727. DUMPREG(HDMI_PHY_CMU);
  728. DUMPREG(HDMI_CORE_RSTOUT);
  729. DRM_DEBUG_KMS("%s: ---- CORE REGISTERS ----\n", prefix);
  730. DUMPREG(HDMI_CON_0);
  731. DUMPREG(HDMI_CON_1);
  732. DUMPREG(HDMI_CON_2);
  733. DUMPREG(HDMI_SYS_STATUS);
  734. DUMPREG(HDMI_PHY_STATUS_0);
  735. DUMPREG(HDMI_STATUS_EN);
  736. DUMPREG(HDMI_HPD);
  737. DUMPREG(HDMI_MODE_SEL);
  738. DUMPREG(HDMI_ENC_EN);
  739. DUMPREG(HDMI_DC_CONTROL);
  740. DUMPREG(HDMI_VIDEO_PATTERN_GEN);
  741. DRM_DEBUG_KMS("%s: ---- CORE SYNC REGISTERS ----\n", prefix);
  742. DUMPREG(HDMI_H_BLANK_0);
  743. DUMPREG(HDMI_H_BLANK_1);
  744. DUMPREG(HDMI_V2_BLANK_0);
  745. DUMPREG(HDMI_V2_BLANK_1);
  746. DUMPREG(HDMI_V1_BLANK_0);
  747. DUMPREG(HDMI_V1_BLANK_1);
  748. DUMPREG(HDMI_V_LINE_0);
  749. DUMPREG(HDMI_V_LINE_1);
  750. DUMPREG(HDMI_H_LINE_0);
  751. DUMPREG(HDMI_H_LINE_1);
  752. DUMPREG(HDMI_HSYNC_POL);
  753. DUMPREG(HDMI_VSYNC_POL);
  754. DUMPREG(HDMI_INT_PRO_MODE);
  755. DUMPREG(HDMI_V_BLANK_F0_0);
  756. DUMPREG(HDMI_V_BLANK_F0_1);
  757. DUMPREG(HDMI_V_BLANK_F1_0);
  758. DUMPREG(HDMI_V_BLANK_F1_1);
  759. DUMPREG(HDMI_H_SYNC_START_0);
  760. DUMPREG(HDMI_H_SYNC_START_1);
  761. DUMPREG(HDMI_H_SYNC_END_0);
  762. DUMPREG(HDMI_H_SYNC_END_1);
  763. DUMPREG(HDMI_V_SYNC_LINE_BEF_2_0);
  764. DUMPREG(HDMI_V_SYNC_LINE_BEF_2_1);
  765. DUMPREG(HDMI_V_SYNC_LINE_BEF_1_0);
  766. DUMPREG(HDMI_V_SYNC_LINE_BEF_1_1);
  767. DUMPREG(HDMI_V_SYNC_LINE_AFT_2_0);
  768. DUMPREG(HDMI_V_SYNC_LINE_AFT_2_1);
  769. DUMPREG(HDMI_V_SYNC_LINE_AFT_1_0);
  770. DUMPREG(HDMI_V_SYNC_LINE_AFT_1_1);
  771. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_2_0);
  772. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_2_1);
  773. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_1_0);
  774. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_1_1);
  775. DUMPREG(HDMI_V_BLANK_F2_0);
  776. DUMPREG(HDMI_V_BLANK_F2_1);
  777. DUMPREG(HDMI_V_BLANK_F3_0);
  778. DUMPREG(HDMI_V_BLANK_F3_1);
  779. DUMPREG(HDMI_V_BLANK_F4_0);
  780. DUMPREG(HDMI_V_BLANK_F4_1);
  781. DUMPREG(HDMI_V_BLANK_F5_0);
  782. DUMPREG(HDMI_V_BLANK_F5_1);
  783. DUMPREG(HDMI_V_SYNC_LINE_AFT_3_0);
  784. DUMPREG(HDMI_V_SYNC_LINE_AFT_3_1);
  785. DUMPREG(HDMI_V_SYNC_LINE_AFT_4_0);
  786. DUMPREG(HDMI_V_SYNC_LINE_AFT_4_1);
  787. DUMPREG(HDMI_V_SYNC_LINE_AFT_5_0);
  788. DUMPREG(HDMI_V_SYNC_LINE_AFT_5_1);
  789. DUMPREG(HDMI_V_SYNC_LINE_AFT_6_0);
  790. DUMPREG(HDMI_V_SYNC_LINE_AFT_6_1);
  791. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_3_0);
  792. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_3_1);
  793. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_4_0);
  794. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_4_1);
  795. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_5_0);
  796. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_5_1);
  797. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_6_0);
  798. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_6_1);
  799. DUMPREG(HDMI_VACT_SPACE_1_0);
  800. DUMPREG(HDMI_VACT_SPACE_1_1);
  801. DUMPREG(HDMI_VACT_SPACE_2_0);
  802. DUMPREG(HDMI_VACT_SPACE_2_1);
  803. DUMPREG(HDMI_VACT_SPACE_3_0);
  804. DUMPREG(HDMI_VACT_SPACE_3_1);
  805. DUMPREG(HDMI_VACT_SPACE_4_0);
  806. DUMPREG(HDMI_VACT_SPACE_4_1);
  807. DUMPREG(HDMI_VACT_SPACE_5_0);
  808. DUMPREG(HDMI_VACT_SPACE_5_1);
  809. DUMPREG(HDMI_VACT_SPACE_6_0);
  810. DUMPREG(HDMI_VACT_SPACE_6_1);
  811. DRM_DEBUG_KMS("%s: ---- TG REGISTERS ----\n", prefix);
  812. DUMPREG(HDMI_TG_CMD);
  813. DUMPREG(HDMI_TG_H_FSZ_L);
  814. DUMPREG(HDMI_TG_H_FSZ_H);
  815. DUMPREG(HDMI_TG_HACT_ST_L);
  816. DUMPREG(HDMI_TG_HACT_ST_H);
  817. DUMPREG(HDMI_TG_HACT_SZ_L);
  818. DUMPREG(HDMI_TG_HACT_SZ_H);
  819. DUMPREG(HDMI_TG_V_FSZ_L);
  820. DUMPREG(HDMI_TG_V_FSZ_H);
  821. DUMPREG(HDMI_TG_VSYNC_L);
  822. DUMPREG(HDMI_TG_VSYNC_H);
  823. DUMPREG(HDMI_TG_VSYNC2_L);
  824. DUMPREG(HDMI_TG_VSYNC2_H);
  825. DUMPREG(HDMI_TG_VACT_ST_L);
  826. DUMPREG(HDMI_TG_VACT_ST_H);
  827. DUMPREG(HDMI_TG_VACT_SZ_L);
  828. DUMPREG(HDMI_TG_VACT_SZ_H);
  829. DUMPREG(HDMI_TG_FIELD_CHG_L);
  830. DUMPREG(HDMI_TG_FIELD_CHG_H);
  831. DUMPREG(HDMI_TG_VACT_ST2_L);
  832. DUMPREG(HDMI_TG_VACT_ST2_H);
  833. DUMPREG(HDMI_TG_VACT_ST3_L);
  834. DUMPREG(HDMI_TG_VACT_ST3_H);
  835. DUMPREG(HDMI_TG_VACT_ST4_L);
  836. DUMPREG(HDMI_TG_VACT_ST4_H);
  837. DUMPREG(HDMI_TG_VSYNC_TOP_HDMI_L);
  838. DUMPREG(HDMI_TG_VSYNC_TOP_HDMI_H);
  839. DUMPREG(HDMI_TG_VSYNC_BOT_HDMI_L);
  840. DUMPREG(HDMI_TG_VSYNC_BOT_HDMI_H);
  841. DUMPREG(HDMI_TG_FIELD_TOP_HDMI_L);
  842. DUMPREG(HDMI_TG_FIELD_TOP_HDMI_H);
  843. DUMPREG(HDMI_TG_FIELD_BOT_HDMI_L);
  844. DUMPREG(HDMI_TG_FIELD_BOT_HDMI_H);
  845. DUMPREG(HDMI_TG_3D);
  846. DRM_DEBUG_KMS("%s: ---- PACKET REGISTERS ----\n", prefix);
  847. DUMPREG(HDMI_AVI_CON);
  848. DUMPREG(HDMI_AVI_HEADER0);
  849. DUMPREG(HDMI_AVI_HEADER1);
  850. DUMPREG(HDMI_AVI_HEADER2);
  851. DUMPREG(HDMI_AVI_CHECK_SUM);
  852. DUMPREG(HDMI_VSI_CON);
  853. DUMPREG(HDMI_VSI_HEADER0);
  854. DUMPREG(HDMI_VSI_HEADER1);
  855. DUMPREG(HDMI_VSI_HEADER2);
  856. for (i = 0; i < 7; ++i)
  857. DUMPREG(HDMI_VSI_DATA(i));
  858. #undef DUMPREG
  859. }
  860. static void hdmi_regs_dump(struct hdmi_context *hdata, char *prefix)
  861. {
  862. if (hdata->type == HDMI_TYPE13)
  863. hdmi_v13_regs_dump(hdata, prefix);
  864. else
  865. hdmi_v14_regs_dump(hdata, prefix);
  866. }
  867. static u8 hdmi_chksum(struct hdmi_context *hdata,
  868. u32 start, u8 len, u32 hdr_sum)
  869. {
  870. int i;
  871. /* hdr_sum : header0 + header1 + header2
  872. * start : start address of packet byte1
  873. * len : packet bytes - 1 */
  874. for (i = 0; i < len; ++i)
  875. hdr_sum += 0xff & hdmi_reg_read(hdata, start + i * 4);
  876. /* return 2's complement of 8 bit hdr_sum */
  877. return (u8)(~(hdr_sum & 0xff) + 1);
  878. }
  879. static void hdmi_reg_infoframe(struct hdmi_context *hdata,
  880. union hdmi_infoframe *infoframe)
  881. {
  882. u32 hdr_sum;
  883. u8 chksum;
  884. u32 mod;
  885. u32 vic;
  886. mod = hdmi_reg_read(hdata, HDMI_MODE_SEL);
  887. if (hdata->dvi_mode) {
  888. hdmi_reg_writeb(hdata, HDMI_VSI_CON,
  889. HDMI_VSI_CON_DO_NOT_TRANSMIT);
  890. hdmi_reg_writeb(hdata, HDMI_AVI_CON,
  891. HDMI_AVI_CON_DO_NOT_TRANSMIT);
  892. hdmi_reg_writeb(hdata, HDMI_AUI_CON, HDMI_AUI_CON_NO_TRAN);
  893. return;
  894. }
  895. switch (infoframe->any.type) {
  896. case HDMI_INFOFRAME_TYPE_AVI:
  897. hdmi_reg_writeb(hdata, HDMI_AVI_CON, HDMI_AVI_CON_EVERY_VSYNC);
  898. hdmi_reg_writeb(hdata, HDMI_AVI_HEADER0, infoframe->any.type);
  899. hdmi_reg_writeb(hdata, HDMI_AVI_HEADER1,
  900. infoframe->any.version);
  901. hdmi_reg_writeb(hdata, HDMI_AVI_HEADER2, infoframe->any.length);
  902. hdr_sum = infoframe->any.type + infoframe->any.version +
  903. infoframe->any.length;
  904. /* Output format zero hardcoded ,RGB YBCR selection */
  905. hdmi_reg_writeb(hdata, HDMI_AVI_BYTE(1), 0 << 5 |
  906. AVI_ACTIVE_FORMAT_VALID |
  907. AVI_UNDERSCANNED_DISPLAY_VALID);
  908. /*
  909. * Set the aspect ratio as per the mode, mentioned in
  910. * Table 9 AVI InfoFrame Data Byte 2 of CEA-861-D Standard
  911. */
  912. switch (hdata->mode_conf.aspect_ratio) {
  913. case HDMI_PICTURE_ASPECT_4_3:
  914. hdmi_reg_writeb(hdata, HDMI_AVI_BYTE(2),
  915. hdata->mode_conf.aspect_ratio |
  916. AVI_4_3_CENTER_RATIO);
  917. break;
  918. case HDMI_PICTURE_ASPECT_16_9:
  919. hdmi_reg_writeb(hdata, HDMI_AVI_BYTE(2),
  920. hdata->mode_conf.aspect_ratio |
  921. AVI_16_9_CENTER_RATIO);
  922. break;
  923. case HDMI_PICTURE_ASPECT_NONE:
  924. default:
  925. hdmi_reg_writeb(hdata, HDMI_AVI_BYTE(2),
  926. hdata->mode_conf.aspect_ratio |
  927. AVI_SAME_AS_PIC_ASPECT_RATIO);
  928. break;
  929. }
  930. vic = hdata->mode_conf.cea_video_id;
  931. hdmi_reg_writeb(hdata, HDMI_AVI_BYTE(4), vic);
  932. chksum = hdmi_chksum(hdata, HDMI_AVI_BYTE(1),
  933. infoframe->any.length, hdr_sum);
  934. DRM_DEBUG_KMS("AVI checksum = 0x%x\n", chksum);
  935. hdmi_reg_writeb(hdata, HDMI_AVI_CHECK_SUM, chksum);
  936. break;
  937. case HDMI_INFOFRAME_TYPE_AUDIO:
  938. hdmi_reg_writeb(hdata, HDMI_AUI_CON, 0x02);
  939. hdmi_reg_writeb(hdata, HDMI_AUI_HEADER0, infoframe->any.type);
  940. hdmi_reg_writeb(hdata, HDMI_AUI_HEADER1,
  941. infoframe->any.version);
  942. hdmi_reg_writeb(hdata, HDMI_AUI_HEADER2, infoframe->any.length);
  943. hdr_sum = infoframe->any.type + infoframe->any.version +
  944. infoframe->any.length;
  945. chksum = hdmi_chksum(hdata, HDMI_AUI_BYTE(1),
  946. infoframe->any.length, hdr_sum);
  947. DRM_DEBUG_KMS("AUI checksum = 0x%x\n", chksum);
  948. hdmi_reg_writeb(hdata, HDMI_AUI_CHECK_SUM, chksum);
  949. break;
  950. default:
  951. break;
  952. }
  953. }
  954. static enum drm_connector_status hdmi_detect(struct drm_connector *connector,
  955. bool force)
  956. {
  957. struct hdmi_context *hdata = ctx_from_connector(connector);
  958. hdata->hpd = gpio_get_value(hdata->hpd_gpio);
  959. return hdata->hpd ? connector_status_connected :
  960. connector_status_disconnected;
  961. }
  962. static void hdmi_connector_destroy(struct drm_connector *connector)
  963. {
  964. drm_connector_unregister(connector);
  965. drm_connector_cleanup(connector);
  966. }
  967. static struct drm_connector_funcs hdmi_connector_funcs = {
  968. .dpms = drm_helper_connector_dpms,
  969. .fill_modes = drm_helper_probe_single_connector_modes,
  970. .detect = hdmi_detect,
  971. .destroy = hdmi_connector_destroy,
  972. };
  973. static int hdmi_get_modes(struct drm_connector *connector)
  974. {
  975. struct hdmi_context *hdata = ctx_from_connector(connector);
  976. struct edid *edid;
  977. if (!hdata->ddc_adpt)
  978. return -ENODEV;
  979. edid = drm_get_edid(connector, hdata->ddc_adpt);
  980. if (!edid)
  981. return -ENODEV;
  982. hdata->dvi_mode = !drm_detect_hdmi_monitor(edid);
  983. DRM_DEBUG_KMS("%s : width[%d] x height[%d]\n",
  984. (hdata->dvi_mode ? "dvi monitor" : "hdmi monitor"),
  985. edid->width_cm, edid->height_cm);
  986. drm_mode_connector_update_edid_property(connector, edid);
  987. return drm_add_edid_modes(connector, edid);
  988. }
  989. static int hdmi_find_phy_conf(struct hdmi_context *hdata, u32 pixel_clock)
  990. {
  991. int i;
  992. for (i = 0; i < hdata->phy_conf_count; i++)
  993. if (hdata->phy_confs[i].pixel_clock == pixel_clock)
  994. return i;
  995. DRM_DEBUG_KMS("Could not find phy config for %d\n", pixel_clock);
  996. return -EINVAL;
  997. }
  998. static int hdmi_mode_valid(struct drm_connector *connector,
  999. struct drm_display_mode *mode)
  1000. {
  1001. struct hdmi_context *hdata = ctx_from_connector(connector);
  1002. int ret;
  1003. DRM_DEBUG_KMS("xres=%d, yres=%d, refresh=%d, intl=%d clock=%d\n",
  1004. mode->hdisplay, mode->vdisplay, mode->vrefresh,
  1005. (mode->flags & DRM_MODE_FLAG_INTERLACE) ? true :
  1006. false, mode->clock * 1000);
  1007. ret = mixer_check_mode(mode);
  1008. if (ret)
  1009. return MODE_BAD;
  1010. ret = hdmi_find_phy_conf(hdata, mode->clock * 1000);
  1011. if (ret < 0)
  1012. return MODE_BAD;
  1013. return MODE_OK;
  1014. }
  1015. static struct drm_encoder *hdmi_best_encoder(struct drm_connector *connector)
  1016. {
  1017. struct hdmi_context *hdata = ctx_from_connector(connector);
  1018. return hdata->encoder;
  1019. }
  1020. static struct drm_connector_helper_funcs hdmi_connector_helper_funcs = {
  1021. .get_modes = hdmi_get_modes,
  1022. .mode_valid = hdmi_mode_valid,
  1023. .best_encoder = hdmi_best_encoder,
  1024. };
  1025. static int hdmi_create_connector(struct exynos_drm_display *display,
  1026. struct drm_encoder *encoder)
  1027. {
  1028. struct hdmi_context *hdata = display->ctx;
  1029. struct drm_connector *connector = &hdata->connector;
  1030. int ret;
  1031. hdata->encoder = encoder;
  1032. connector->interlace_allowed = true;
  1033. connector->polled = DRM_CONNECTOR_POLL_HPD;
  1034. ret = drm_connector_init(hdata->drm_dev, connector,
  1035. &hdmi_connector_funcs, DRM_MODE_CONNECTOR_HDMIA);
  1036. if (ret) {
  1037. DRM_ERROR("Failed to initialize connector with drm\n");
  1038. return ret;
  1039. }
  1040. drm_connector_helper_add(connector, &hdmi_connector_helper_funcs);
  1041. drm_connector_register(connector);
  1042. drm_mode_connector_attach_encoder(connector, encoder);
  1043. return 0;
  1044. }
  1045. static void hdmi_mode_fixup(struct exynos_drm_display *display,
  1046. struct drm_connector *connector,
  1047. const struct drm_display_mode *mode,
  1048. struct drm_display_mode *adjusted_mode)
  1049. {
  1050. struct drm_display_mode *m;
  1051. int mode_ok;
  1052. DRM_DEBUG_KMS("%s\n", __FILE__);
  1053. drm_mode_set_crtcinfo(adjusted_mode, 0);
  1054. mode_ok = hdmi_mode_valid(connector, adjusted_mode);
  1055. /* just return if user desired mode exists. */
  1056. if (mode_ok == MODE_OK)
  1057. return;
  1058. /*
  1059. * otherwise, find the most suitable mode among modes and change it
  1060. * to adjusted_mode.
  1061. */
  1062. list_for_each_entry(m, &connector->modes, head) {
  1063. mode_ok = hdmi_mode_valid(connector, m);
  1064. if (mode_ok == MODE_OK) {
  1065. DRM_INFO("desired mode doesn't exist so\n");
  1066. DRM_INFO("use the most suitable mode among modes.\n");
  1067. DRM_DEBUG_KMS("Adjusted Mode: [%d]x[%d] [%d]Hz\n",
  1068. m->hdisplay, m->vdisplay, m->vrefresh);
  1069. drm_mode_copy(adjusted_mode, m);
  1070. break;
  1071. }
  1072. }
  1073. }
  1074. static void hdmi_set_acr(u32 freq, u8 *acr)
  1075. {
  1076. u32 n, cts;
  1077. switch (freq) {
  1078. case 32000:
  1079. n = 4096;
  1080. cts = 27000;
  1081. break;
  1082. case 44100:
  1083. n = 6272;
  1084. cts = 30000;
  1085. break;
  1086. case 88200:
  1087. n = 12544;
  1088. cts = 30000;
  1089. break;
  1090. case 176400:
  1091. n = 25088;
  1092. cts = 30000;
  1093. break;
  1094. case 48000:
  1095. n = 6144;
  1096. cts = 27000;
  1097. break;
  1098. case 96000:
  1099. n = 12288;
  1100. cts = 27000;
  1101. break;
  1102. case 192000:
  1103. n = 24576;
  1104. cts = 27000;
  1105. break;
  1106. default:
  1107. n = 0;
  1108. cts = 0;
  1109. break;
  1110. }
  1111. acr[1] = cts >> 16;
  1112. acr[2] = cts >> 8 & 0xff;
  1113. acr[3] = cts & 0xff;
  1114. acr[4] = n >> 16;
  1115. acr[5] = n >> 8 & 0xff;
  1116. acr[6] = n & 0xff;
  1117. }
  1118. static void hdmi_reg_acr(struct hdmi_context *hdata, u8 *acr)
  1119. {
  1120. hdmi_reg_writeb(hdata, HDMI_ACR_N0, acr[6]);
  1121. hdmi_reg_writeb(hdata, HDMI_ACR_N1, acr[5]);
  1122. hdmi_reg_writeb(hdata, HDMI_ACR_N2, acr[4]);
  1123. hdmi_reg_writeb(hdata, HDMI_ACR_MCTS0, acr[3]);
  1124. hdmi_reg_writeb(hdata, HDMI_ACR_MCTS1, acr[2]);
  1125. hdmi_reg_writeb(hdata, HDMI_ACR_MCTS2, acr[1]);
  1126. hdmi_reg_writeb(hdata, HDMI_ACR_CTS0, acr[3]);
  1127. hdmi_reg_writeb(hdata, HDMI_ACR_CTS1, acr[2]);
  1128. hdmi_reg_writeb(hdata, HDMI_ACR_CTS2, acr[1]);
  1129. if (hdata->type == HDMI_TYPE13)
  1130. hdmi_reg_writeb(hdata, HDMI_V13_ACR_CON, 4);
  1131. else
  1132. hdmi_reg_writeb(hdata, HDMI_ACR_CON, 4);
  1133. }
  1134. static void hdmi_audio_init(struct hdmi_context *hdata)
  1135. {
  1136. u32 sample_rate, bits_per_sample;
  1137. u32 data_num, bit_ch, sample_frq;
  1138. u32 val;
  1139. u8 acr[7];
  1140. sample_rate = 44100;
  1141. bits_per_sample = 16;
  1142. switch (bits_per_sample) {
  1143. case 20:
  1144. data_num = 2;
  1145. bit_ch = 1;
  1146. break;
  1147. case 24:
  1148. data_num = 3;
  1149. bit_ch = 1;
  1150. break;
  1151. default:
  1152. data_num = 1;
  1153. bit_ch = 0;
  1154. break;
  1155. }
  1156. hdmi_set_acr(sample_rate, acr);
  1157. hdmi_reg_acr(hdata, acr);
  1158. hdmi_reg_writeb(hdata, HDMI_I2S_MUX_CON, HDMI_I2S_IN_DISABLE
  1159. | HDMI_I2S_AUD_I2S | HDMI_I2S_CUV_I2S_ENABLE
  1160. | HDMI_I2S_MUX_ENABLE);
  1161. hdmi_reg_writeb(hdata, HDMI_I2S_MUX_CH, HDMI_I2S_CH0_EN
  1162. | HDMI_I2S_CH1_EN | HDMI_I2S_CH2_EN);
  1163. hdmi_reg_writeb(hdata, HDMI_I2S_MUX_CUV, HDMI_I2S_CUV_RL_EN);
  1164. sample_frq = (sample_rate == 44100) ? 0 :
  1165. (sample_rate == 48000) ? 2 :
  1166. (sample_rate == 32000) ? 3 :
  1167. (sample_rate == 96000) ? 0xa : 0x0;
  1168. hdmi_reg_writeb(hdata, HDMI_I2S_CLK_CON, HDMI_I2S_CLK_DIS);
  1169. hdmi_reg_writeb(hdata, HDMI_I2S_CLK_CON, HDMI_I2S_CLK_EN);
  1170. val = hdmi_reg_read(hdata, HDMI_I2S_DSD_CON) | 0x01;
  1171. hdmi_reg_writeb(hdata, HDMI_I2S_DSD_CON, val);
  1172. /* Configuration I2S input ports. Configure I2S_PIN_SEL_0~4 */
  1173. hdmi_reg_writeb(hdata, HDMI_I2S_PIN_SEL_0, HDMI_I2S_SEL_SCLK(5)
  1174. | HDMI_I2S_SEL_LRCK(6));
  1175. hdmi_reg_writeb(hdata, HDMI_I2S_PIN_SEL_1, HDMI_I2S_SEL_SDATA1(1)
  1176. | HDMI_I2S_SEL_SDATA2(4));
  1177. hdmi_reg_writeb(hdata, HDMI_I2S_PIN_SEL_2, HDMI_I2S_SEL_SDATA3(1)
  1178. | HDMI_I2S_SEL_SDATA2(2));
  1179. hdmi_reg_writeb(hdata, HDMI_I2S_PIN_SEL_3, HDMI_I2S_SEL_DSD(0));
  1180. /* I2S_CON_1 & 2 */
  1181. hdmi_reg_writeb(hdata, HDMI_I2S_CON_1, HDMI_I2S_SCLK_FALLING_EDGE
  1182. | HDMI_I2S_L_CH_LOW_POL);
  1183. hdmi_reg_writeb(hdata, HDMI_I2S_CON_2, HDMI_I2S_MSB_FIRST_MODE
  1184. | HDMI_I2S_SET_BIT_CH(bit_ch)
  1185. | HDMI_I2S_SET_SDATA_BIT(data_num)
  1186. | HDMI_I2S_BASIC_FORMAT);
  1187. /* Configure register related to CUV information */
  1188. hdmi_reg_writeb(hdata, HDMI_I2S_CH_ST_0, HDMI_I2S_CH_STATUS_MODE_0
  1189. | HDMI_I2S_2AUD_CH_WITHOUT_PREEMPH
  1190. | HDMI_I2S_COPYRIGHT
  1191. | HDMI_I2S_LINEAR_PCM
  1192. | HDMI_I2S_CONSUMER_FORMAT);
  1193. hdmi_reg_writeb(hdata, HDMI_I2S_CH_ST_1, HDMI_I2S_CD_PLAYER);
  1194. hdmi_reg_writeb(hdata, HDMI_I2S_CH_ST_2, HDMI_I2S_SET_SOURCE_NUM(0));
  1195. hdmi_reg_writeb(hdata, HDMI_I2S_CH_ST_3, HDMI_I2S_CLK_ACCUR_LEVEL_2
  1196. | HDMI_I2S_SET_SMP_FREQ(sample_frq));
  1197. hdmi_reg_writeb(hdata, HDMI_I2S_CH_ST_4,
  1198. HDMI_I2S_ORG_SMP_FREQ_44_1
  1199. | HDMI_I2S_WORD_LEN_MAX24_24BITS
  1200. | HDMI_I2S_WORD_LEN_MAX_24BITS);
  1201. hdmi_reg_writeb(hdata, HDMI_I2S_CH_ST_CON, HDMI_I2S_CH_STATUS_RELOAD);
  1202. }
  1203. static void hdmi_audio_control(struct hdmi_context *hdata, bool onoff)
  1204. {
  1205. if (hdata->dvi_mode)
  1206. return;
  1207. hdmi_reg_writeb(hdata, HDMI_AUI_CON, onoff ? 2 : 0);
  1208. hdmi_reg_writemask(hdata, HDMI_CON_0, onoff ?
  1209. HDMI_ASP_EN : HDMI_ASP_DIS, HDMI_ASP_MASK);
  1210. }
  1211. static void hdmi_start(struct hdmi_context *hdata, bool start)
  1212. {
  1213. u32 val = start ? HDMI_TG_EN : 0;
  1214. if (hdata->current_mode.flags & DRM_MODE_FLAG_INTERLACE)
  1215. val |= HDMI_FIELD_EN;
  1216. hdmi_reg_writemask(hdata, HDMI_CON_0, val, HDMI_EN);
  1217. hdmi_reg_writemask(hdata, HDMI_TG_CMD, val, HDMI_TG_EN | HDMI_FIELD_EN);
  1218. }
  1219. static void hdmi_conf_init(struct hdmi_context *hdata)
  1220. {
  1221. union hdmi_infoframe infoframe;
  1222. /* disable HPD interrupts from HDMI IP block, use GPIO instead */
  1223. hdmi_reg_writemask(hdata, HDMI_INTC_CON, 0, HDMI_INTC_EN_GLOBAL |
  1224. HDMI_INTC_EN_HPD_PLUG | HDMI_INTC_EN_HPD_UNPLUG);
  1225. /* choose HDMI mode */
  1226. hdmi_reg_writemask(hdata, HDMI_MODE_SEL,
  1227. HDMI_MODE_HDMI_EN, HDMI_MODE_MASK);
  1228. /* Apply Video preable and Guard band in HDMI mode only */
  1229. hdmi_reg_writeb(hdata, HDMI_CON_2, 0);
  1230. /* disable bluescreen */
  1231. hdmi_reg_writemask(hdata, HDMI_CON_0, 0, HDMI_BLUE_SCR_EN);
  1232. if (hdata->dvi_mode) {
  1233. /* choose DVI mode */
  1234. hdmi_reg_writemask(hdata, HDMI_MODE_SEL,
  1235. HDMI_MODE_DVI_EN, HDMI_MODE_MASK);
  1236. hdmi_reg_writeb(hdata, HDMI_CON_2,
  1237. HDMI_VID_PREAMBLE_DIS | HDMI_GUARD_BAND_DIS);
  1238. }
  1239. if (hdata->type == HDMI_TYPE13) {
  1240. /* choose bluescreen (fecal) color */
  1241. hdmi_reg_writeb(hdata, HDMI_V13_BLUE_SCREEN_0, 0x12);
  1242. hdmi_reg_writeb(hdata, HDMI_V13_BLUE_SCREEN_1, 0x34);
  1243. hdmi_reg_writeb(hdata, HDMI_V13_BLUE_SCREEN_2, 0x56);
  1244. /* enable AVI packet every vsync, fixes purple line problem */
  1245. hdmi_reg_writeb(hdata, HDMI_V13_AVI_CON, 0x02);
  1246. /* force RGB, look to CEA-861-D, table 7 for more detail */
  1247. hdmi_reg_writeb(hdata, HDMI_V13_AVI_BYTE(0), 0 << 5);
  1248. hdmi_reg_writemask(hdata, HDMI_CON_1, 0x10 << 5, 0x11 << 5);
  1249. hdmi_reg_writeb(hdata, HDMI_V13_SPD_CON, 0x02);
  1250. hdmi_reg_writeb(hdata, HDMI_V13_AUI_CON, 0x02);
  1251. hdmi_reg_writeb(hdata, HDMI_V13_ACR_CON, 0x04);
  1252. } else {
  1253. infoframe.any.type = HDMI_INFOFRAME_TYPE_AVI;
  1254. infoframe.any.version = HDMI_AVI_VERSION;
  1255. infoframe.any.length = HDMI_AVI_LENGTH;
  1256. hdmi_reg_infoframe(hdata, &infoframe);
  1257. infoframe.any.type = HDMI_INFOFRAME_TYPE_AUDIO;
  1258. infoframe.any.version = HDMI_AUI_VERSION;
  1259. infoframe.any.length = HDMI_AUI_LENGTH;
  1260. hdmi_reg_infoframe(hdata, &infoframe);
  1261. /* enable AVI packet every vsync, fixes purple line problem */
  1262. hdmi_reg_writemask(hdata, HDMI_CON_1, 2, 3 << 5);
  1263. }
  1264. }
  1265. static void hdmi_v13_mode_apply(struct hdmi_context *hdata)
  1266. {
  1267. const struct hdmi_tg_regs *tg = &hdata->mode_conf.conf.v13_conf.tg;
  1268. const struct hdmi_v13_core_regs *core =
  1269. &hdata->mode_conf.conf.v13_conf.core;
  1270. int tries;
  1271. /* setting core registers */
  1272. hdmi_reg_writeb(hdata, HDMI_H_BLANK_0, core->h_blank[0]);
  1273. hdmi_reg_writeb(hdata, HDMI_H_BLANK_1, core->h_blank[1]);
  1274. hdmi_reg_writeb(hdata, HDMI_V13_V_BLANK_0, core->v_blank[0]);
  1275. hdmi_reg_writeb(hdata, HDMI_V13_V_BLANK_1, core->v_blank[1]);
  1276. hdmi_reg_writeb(hdata, HDMI_V13_V_BLANK_2, core->v_blank[2]);
  1277. hdmi_reg_writeb(hdata, HDMI_V13_H_V_LINE_0, core->h_v_line[0]);
  1278. hdmi_reg_writeb(hdata, HDMI_V13_H_V_LINE_1, core->h_v_line[1]);
  1279. hdmi_reg_writeb(hdata, HDMI_V13_H_V_LINE_2, core->h_v_line[2]);
  1280. hdmi_reg_writeb(hdata, HDMI_VSYNC_POL, core->vsync_pol[0]);
  1281. hdmi_reg_writeb(hdata, HDMI_INT_PRO_MODE, core->int_pro_mode[0]);
  1282. hdmi_reg_writeb(hdata, HDMI_V13_V_BLANK_F_0, core->v_blank_f[0]);
  1283. hdmi_reg_writeb(hdata, HDMI_V13_V_BLANK_F_1, core->v_blank_f[1]);
  1284. hdmi_reg_writeb(hdata, HDMI_V13_V_BLANK_F_2, core->v_blank_f[2]);
  1285. hdmi_reg_writeb(hdata, HDMI_V13_H_SYNC_GEN_0, core->h_sync_gen[0]);
  1286. hdmi_reg_writeb(hdata, HDMI_V13_H_SYNC_GEN_1, core->h_sync_gen[1]);
  1287. hdmi_reg_writeb(hdata, HDMI_V13_H_SYNC_GEN_2, core->h_sync_gen[2]);
  1288. hdmi_reg_writeb(hdata, HDMI_V13_V_SYNC_GEN_1_0, core->v_sync_gen1[0]);
  1289. hdmi_reg_writeb(hdata, HDMI_V13_V_SYNC_GEN_1_1, core->v_sync_gen1[1]);
  1290. hdmi_reg_writeb(hdata, HDMI_V13_V_SYNC_GEN_1_2, core->v_sync_gen1[2]);
  1291. hdmi_reg_writeb(hdata, HDMI_V13_V_SYNC_GEN_2_0, core->v_sync_gen2[0]);
  1292. hdmi_reg_writeb(hdata, HDMI_V13_V_SYNC_GEN_2_1, core->v_sync_gen2[1]);
  1293. hdmi_reg_writeb(hdata, HDMI_V13_V_SYNC_GEN_2_2, core->v_sync_gen2[2]);
  1294. hdmi_reg_writeb(hdata, HDMI_V13_V_SYNC_GEN_3_0, core->v_sync_gen3[0]);
  1295. hdmi_reg_writeb(hdata, HDMI_V13_V_SYNC_GEN_3_1, core->v_sync_gen3[1]);
  1296. hdmi_reg_writeb(hdata, HDMI_V13_V_SYNC_GEN_3_2, core->v_sync_gen3[2]);
  1297. /* Timing generator registers */
  1298. hdmi_reg_writeb(hdata, HDMI_TG_H_FSZ_L, tg->h_fsz[0]);
  1299. hdmi_reg_writeb(hdata, HDMI_TG_H_FSZ_H, tg->h_fsz[1]);
  1300. hdmi_reg_writeb(hdata, HDMI_TG_HACT_ST_L, tg->hact_st[0]);
  1301. hdmi_reg_writeb(hdata, HDMI_TG_HACT_ST_H, tg->hact_st[1]);
  1302. hdmi_reg_writeb(hdata, HDMI_TG_HACT_SZ_L, tg->hact_sz[0]);
  1303. hdmi_reg_writeb(hdata, HDMI_TG_HACT_SZ_H, tg->hact_sz[1]);
  1304. hdmi_reg_writeb(hdata, HDMI_TG_V_FSZ_L, tg->v_fsz[0]);
  1305. hdmi_reg_writeb(hdata, HDMI_TG_V_FSZ_H, tg->v_fsz[1]);
  1306. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_L, tg->vsync[0]);
  1307. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_H, tg->vsync[1]);
  1308. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC2_L, tg->vsync2[0]);
  1309. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC2_H, tg->vsync2[1]);
  1310. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST_L, tg->vact_st[0]);
  1311. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST_H, tg->vact_st[1]);
  1312. hdmi_reg_writeb(hdata, HDMI_TG_VACT_SZ_L, tg->vact_sz[0]);
  1313. hdmi_reg_writeb(hdata, HDMI_TG_VACT_SZ_H, tg->vact_sz[1]);
  1314. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_CHG_L, tg->field_chg[0]);
  1315. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_CHG_H, tg->field_chg[1]);
  1316. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST2_L, tg->vact_st2[0]);
  1317. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST2_H, tg->vact_st2[1]);
  1318. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_TOP_HDMI_L, tg->vsync_top_hdmi[0]);
  1319. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_TOP_HDMI_H, tg->vsync_top_hdmi[1]);
  1320. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_BOT_HDMI_L, tg->vsync_bot_hdmi[0]);
  1321. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_BOT_HDMI_H, tg->vsync_bot_hdmi[1]);
  1322. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_TOP_HDMI_L, tg->field_top_hdmi[0]);
  1323. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_TOP_HDMI_H, tg->field_top_hdmi[1]);
  1324. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_BOT_HDMI_L, tg->field_bot_hdmi[0]);
  1325. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_BOT_HDMI_H, tg->field_bot_hdmi[1]);
  1326. /* waiting for HDMIPHY's PLL to get to steady state */
  1327. for (tries = 100; tries; --tries) {
  1328. u32 val = hdmi_reg_read(hdata, HDMI_V13_PHY_STATUS);
  1329. if (val & HDMI_PHY_STATUS_READY)
  1330. break;
  1331. usleep_range(1000, 2000);
  1332. }
  1333. /* steady state not achieved */
  1334. if (tries == 0) {
  1335. DRM_ERROR("hdmiphy's pll could not reach steady state.\n");
  1336. hdmi_regs_dump(hdata, "timing apply");
  1337. }
  1338. clk_disable_unprepare(hdata->res.sclk_hdmi);
  1339. clk_set_parent(hdata->res.mout_hdmi, hdata->res.sclk_hdmiphy);
  1340. clk_prepare_enable(hdata->res.sclk_hdmi);
  1341. /* enable HDMI and timing generator */
  1342. hdmi_start(hdata, true);
  1343. }
  1344. static void hdmi_v14_mode_apply(struct hdmi_context *hdata)
  1345. {
  1346. const struct hdmi_tg_regs *tg = &hdata->mode_conf.conf.v14_conf.tg;
  1347. const struct hdmi_v14_core_regs *core =
  1348. &hdata->mode_conf.conf.v14_conf.core;
  1349. int tries;
  1350. /* setting core registers */
  1351. hdmi_reg_writeb(hdata, HDMI_H_BLANK_0, core->h_blank[0]);
  1352. hdmi_reg_writeb(hdata, HDMI_H_BLANK_1, core->h_blank[1]);
  1353. hdmi_reg_writeb(hdata, HDMI_V2_BLANK_0, core->v2_blank[0]);
  1354. hdmi_reg_writeb(hdata, HDMI_V2_BLANK_1, core->v2_blank[1]);
  1355. hdmi_reg_writeb(hdata, HDMI_V1_BLANK_0, core->v1_blank[0]);
  1356. hdmi_reg_writeb(hdata, HDMI_V1_BLANK_1, core->v1_blank[1]);
  1357. hdmi_reg_writeb(hdata, HDMI_V_LINE_0, core->v_line[0]);
  1358. hdmi_reg_writeb(hdata, HDMI_V_LINE_1, core->v_line[1]);
  1359. hdmi_reg_writeb(hdata, HDMI_H_LINE_0, core->h_line[0]);
  1360. hdmi_reg_writeb(hdata, HDMI_H_LINE_1, core->h_line[1]);
  1361. hdmi_reg_writeb(hdata, HDMI_HSYNC_POL, core->hsync_pol[0]);
  1362. hdmi_reg_writeb(hdata, HDMI_VSYNC_POL, core->vsync_pol[0]);
  1363. hdmi_reg_writeb(hdata, HDMI_INT_PRO_MODE, core->int_pro_mode[0]);
  1364. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F0_0, core->v_blank_f0[0]);
  1365. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F0_1, core->v_blank_f0[1]);
  1366. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F1_0, core->v_blank_f1[0]);
  1367. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F1_1, core->v_blank_f1[1]);
  1368. hdmi_reg_writeb(hdata, HDMI_H_SYNC_START_0, core->h_sync_start[0]);
  1369. hdmi_reg_writeb(hdata, HDMI_H_SYNC_START_1, core->h_sync_start[1]);
  1370. hdmi_reg_writeb(hdata, HDMI_H_SYNC_END_0, core->h_sync_end[0]);
  1371. hdmi_reg_writeb(hdata, HDMI_H_SYNC_END_1, core->h_sync_end[1]);
  1372. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_BEF_2_0,
  1373. core->v_sync_line_bef_2[0]);
  1374. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_BEF_2_1,
  1375. core->v_sync_line_bef_2[1]);
  1376. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_BEF_1_0,
  1377. core->v_sync_line_bef_1[0]);
  1378. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_BEF_1_1,
  1379. core->v_sync_line_bef_1[1]);
  1380. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_2_0,
  1381. core->v_sync_line_aft_2[0]);
  1382. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_2_1,
  1383. core->v_sync_line_aft_2[1]);
  1384. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_1_0,
  1385. core->v_sync_line_aft_1[0]);
  1386. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_1_1,
  1387. core->v_sync_line_aft_1[1]);
  1388. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_2_0,
  1389. core->v_sync_line_aft_pxl_2[0]);
  1390. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_2_1,
  1391. core->v_sync_line_aft_pxl_2[1]);
  1392. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_1_0,
  1393. core->v_sync_line_aft_pxl_1[0]);
  1394. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_1_1,
  1395. core->v_sync_line_aft_pxl_1[1]);
  1396. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F2_0, core->v_blank_f2[0]);
  1397. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F2_1, core->v_blank_f2[1]);
  1398. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F3_0, core->v_blank_f3[0]);
  1399. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F3_1, core->v_blank_f3[1]);
  1400. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F4_0, core->v_blank_f4[0]);
  1401. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F4_1, core->v_blank_f4[1]);
  1402. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F5_0, core->v_blank_f5[0]);
  1403. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F5_1, core->v_blank_f5[1]);
  1404. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_3_0,
  1405. core->v_sync_line_aft_3[0]);
  1406. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_3_1,
  1407. core->v_sync_line_aft_3[1]);
  1408. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_4_0,
  1409. core->v_sync_line_aft_4[0]);
  1410. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_4_1,
  1411. core->v_sync_line_aft_4[1]);
  1412. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_5_0,
  1413. core->v_sync_line_aft_5[0]);
  1414. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_5_1,
  1415. core->v_sync_line_aft_5[1]);
  1416. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_6_0,
  1417. core->v_sync_line_aft_6[0]);
  1418. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_6_1,
  1419. core->v_sync_line_aft_6[1]);
  1420. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_3_0,
  1421. core->v_sync_line_aft_pxl_3[0]);
  1422. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_3_1,
  1423. core->v_sync_line_aft_pxl_3[1]);
  1424. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_4_0,
  1425. core->v_sync_line_aft_pxl_4[0]);
  1426. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_4_1,
  1427. core->v_sync_line_aft_pxl_4[1]);
  1428. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_5_0,
  1429. core->v_sync_line_aft_pxl_5[0]);
  1430. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_5_1,
  1431. core->v_sync_line_aft_pxl_5[1]);
  1432. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_6_0,
  1433. core->v_sync_line_aft_pxl_6[0]);
  1434. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_6_1,
  1435. core->v_sync_line_aft_pxl_6[1]);
  1436. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_1_0, core->vact_space_1[0]);
  1437. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_1_1, core->vact_space_1[1]);
  1438. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_2_0, core->vact_space_2[0]);
  1439. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_2_1, core->vact_space_2[1]);
  1440. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_3_0, core->vact_space_3[0]);
  1441. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_3_1, core->vact_space_3[1]);
  1442. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_4_0, core->vact_space_4[0]);
  1443. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_4_1, core->vact_space_4[1]);
  1444. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_5_0, core->vact_space_5[0]);
  1445. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_5_1, core->vact_space_5[1]);
  1446. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_6_0, core->vact_space_6[0]);
  1447. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_6_1, core->vact_space_6[1]);
  1448. /* Timing generator registers */
  1449. hdmi_reg_writeb(hdata, HDMI_TG_H_FSZ_L, tg->h_fsz[0]);
  1450. hdmi_reg_writeb(hdata, HDMI_TG_H_FSZ_H, tg->h_fsz[1]);
  1451. hdmi_reg_writeb(hdata, HDMI_TG_HACT_ST_L, tg->hact_st[0]);
  1452. hdmi_reg_writeb(hdata, HDMI_TG_HACT_ST_H, tg->hact_st[1]);
  1453. hdmi_reg_writeb(hdata, HDMI_TG_HACT_SZ_L, tg->hact_sz[0]);
  1454. hdmi_reg_writeb(hdata, HDMI_TG_HACT_SZ_H, tg->hact_sz[1]);
  1455. hdmi_reg_writeb(hdata, HDMI_TG_V_FSZ_L, tg->v_fsz[0]);
  1456. hdmi_reg_writeb(hdata, HDMI_TG_V_FSZ_H, tg->v_fsz[1]);
  1457. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_L, tg->vsync[0]);
  1458. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_H, tg->vsync[1]);
  1459. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC2_L, tg->vsync2[0]);
  1460. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC2_H, tg->vsync2[1]);
  1461. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST_L, tg->vact_st[0]);
  1462. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST_H, tg->vact_st[1]);
  1463. hdmi_reg_writeb(hdata, HDMI_TG_VACT_SZ_L, tg->vact_sz[0]);
  1464. hdmi_reg_writeb(hdata, HDMI_TG_VACT_SZ_H, tg->vact_sz[1]);
  1465. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_CHG_L, tg->field_chg[0]);
  1466. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_CHG_H, tg->field_chg[1]);
  1467. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST2_L, tg->vact_st2[0]);
  1468. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST2_H, tg->vact_st2[1]);
  1469. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST3_L, tg->vact_st3[0]);
  1470. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST3_H, tg->vact_st3[1]);
  1471. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST4_L, tg->vact_st4[0]);
  1472. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST4_H, tg->vact_st4[1]);
  1473. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_TOP_HDMI_L, tg->vsync_top_hdmi[0]);
  1474. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_TOP_HDMI_H, tg->vsync_top_hdmi[1]);
  1475. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_BOT_HDMI_L, tg->vsync_bot_hdmi[0]);
  1476. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_BOT_HDMI_H, tg->vsync_bot_hdmi[1]);
  1477. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_TOP_HDMI_L, tg->field_top_hdmi[0]);
  1478. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_TOP_HDMI_H, tg->field_top_hdmi[1]);
  1479. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_BOT_HDMI_L, tg->field_bot_hdmi[0]);
  1480. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_BOT_HDMI_H, tg->field_bot_hdmi[1]);
  1481. hdmi_reg_writeb(hdata, HDMI_TG_3D, tg->tg_3d[0]);
  1482. /* waiting for HDMIPHY's PLL to get to steady state */
  1483. for (tries = 100; tries; --tries) {
  1484. u32 val = hdmi_reg_read(hdata, HDMI_PHY_STATUS_0);
  1485. if (val & HDMI_PHY_STATUS_READY)
  1486. break;
  1487. usleep_range(1000, 2000);
  1488. }
  1489. /* steady state not achieved */
  1490. if (tries == 0) {
  1491. DRM_ERROR("hdmiphy's pll could not reach steady state.\n");
  1492. hdmi_regs_dump(hdata, "timing apply");
  1493. }
  1494. clk_disable_unprepare(hdata->res.sclk_hdmi);
  1495. clk_set_parent(hdata->res.mout_hdmi, hdata->res.sclk_hdmiphy);
  1496. clk_prepare_enable(hdata->res.sclk_hdmi);
  1497. /* enable HDMI and timing generator */
  1498. hdmi_start(hdata, true);
  1499. }
  1500. static void hdmi_mode_apply(struct hdmi_context *hdata)
  1501. {
  1502. if (hdata->type == HDMI_TYPE13)
  1503. hdmi_v13_mode_apply(hdata);
  1504. else
  1505. hdmi_v14_mode_apply(hdata);
  1506. }
  1507. static void hdmiphy_conf_reset(struct hdmi_context *hdata)
  1508. {
  1509. u8 buffer[2];
  1510. u32 reg;
  1511. clk_disable_unprepare(hdata->res.sclk_hdmi);
  1512. clk_set_parent(hdata->res.mout_hdmi, hdata->res.sclk_pixel);
  1513. clk_prepare_enable(hdata->res.sclk_hdmi);
  1514. /* operation mode */
  1515. buffer[0] = 0x1f;
  1516. buffer[1] = 0x00;
  1517. if (hdata->hdmiphy_port)
  1518. i2c_master_send(hdata->hdmiphy_port, buffer, 2);
  1519. if (hdata->type == HDMI_TYPE13)
  1520. reg = HDMI_V13_PHY_RSTOUT;
  1521. else
  1522. reg = HDMI_PHY_RSTOUT;
  1523. /* reset hdmiphy */
  1524. hdmi_reg_writemask(hdata, reg, ~0, HDMI_PHY_SW_RSTOUT);
  1525. usleep_range(10000, 12000);
  1526. hdmi_reg_writemask(hdata, reg, 0, HDMI_PHY_SW_RSTOUT);
  1527. usleep_range(10000, 12000);
  1528. }
  1529. static void hdmiphy_poweron(struct hdmi_context *hdata)
  1530. {
  1531. if (hdata->type != HDMI_TYPE14)
  1532. return;
  1533. DRM_DEBUG_KMS("\n");
  1534. /* For PHY Mode Setting */
  1535. hdmiphy_reg_writeb(hdata, HDMIPHY_MODE_SET_DONE,
  1536. HDMI_PHY_ENABLE_MODE_SET);
  1537. /* Phy Power On */
  1538. hdmiphy_reg_writeb(hdata, HDMIPHY_POWER,
  1539. HDMI_PHY_POWER_ON);
  1540. /* For PHY Mode Setting */
  1541. hdmiphy_reg_writeb(hdata, HDMIPHY_MODE_SET_DONE,
  1542. HDMI_PHY_DISABLE_MODE_SET);
  1543. /* PHY SW Reset */
  1544. hdmiphy_conf_reset(hdata);
  1545. }
  1546. static void hdmiphy_poweroff(struct hdmi_context *hdata)
  1547. {
  1548. if (hdata->type != HDMI_TYPE14)
  1549. return;
  1550. DRM_DEBUG_KMS("\n");
  1551. /* PHY SW Reset */
  1552. hdmiphy_conf_reset(hdata);
  1553. /* For PHY Mode Setting */
  1554. hdmiphy_reg_writeb(hdata, HDMIPHY_MODE_SET_DONE,
  1555. HDMI_PHY_ENABLE_MODE_SET);
  1556. /* PHY Power Off */
  1557. hdmiphy_reg_writeb(hdata, HDMIPHY_POWER,
  1558. HDMI_PHY_POWER_OFF);
  1559. /* For PHY Mode Setting */
  1560. hdmiphy_reg_writeb(hdata, HDMIPHY_MODE_SET_DONE,
  1561. HDMI_PHY_DISABLE_MODE_SET);
  1562. }
  1563. static void hdmiphy_conf_apply(struct hdmi_context *hdata)
  1564. {
  1565. int ret;
  1566. int i;
  1567. /* pixel clock */
  1568. i = hdmi_find_phy_conf(hdata, hdata->mode_conf.pixel_clock);
  1569. if (i < 0) {
  1570. DRM_ERROR("failed to find hdmiphy conf\n");
  1571. return;
  1572. }
  1573. ret = hdmiphy_reg_write_buf(hdata, 0, hdata->phy_confs[i].conf, 32);
  1574. if (ret) {
  1575. DRM_ERROR("failed to configure hdmiphy\n");
  1576. return;
  1577. }
  1578. usleep_range(10000, 12000);
  1579. ret = hdmiphy_reg_writeb(hdata, HDMIPHY_MODE_SET_DONE,
  1580. HDMI_PHY_DISABLE_MODE_SET);
  1581. if (ret) {
  1582. DRM_ERROR("failed to enable hdmiphy\n");
  1583. return;
  1584. }
  1585. }
  1586. static void hdmi_conf_apply(struct hdmi_context *hdata)
  1587. {
  1588. hdmiphy_conf_reset(hdata);
  1589. hdmiphy_conf_apply(hdata);
  1590. mutex_lock(&hdata->hdmi_mutex);
  1591. hdmi_start(hdata, false);
  1592. hdmi_conf_init(hdata);
  1593. mutex_unlock(&hdata->hdmi_mutex);
  1594. hdmi_audio_init(hdata);
  1595. /* setting core registers */
  1596. hdmi_mode_apply(hdata);
  1597. hdmi_audio_control(hdata, true);
  1598. hdmi_regs_dump(hdata, "start");
  1599. }
  1600. static void hdmi_set_reg(u8 *reg_pair, int num_bytes, u32 value)
  1601. {
  1602. int i;
  1603. BUG_ON(num_bytes > 4);
  1604. for (i = 0; i < num_bytes; i++)
  1605. reg_pair[i] = (value >> (8 * i)) & 0xff;
  1606. }
  1607. static void hdmi_v13_mode_set(struct hdmi_context *hdata,
  1608. struct drm_display_mode *m)
  1609. {
  1610. struct hdmi_v13_core_regs *core = &hdata->mode_conf.conf.v13_conf.core;
  1611. struct hdmi_tg_regs *tg = &hdata->mode_conf.conf.v13_conf.tg;
  1612. unsigned int val;
  1613. hdata->mode_conf.cea_video_id =
  1614. drm_match_cea_mode((struct drm_display_mode *)m);
  1615. hdata->mode_conf.pixel_clock = m->clock * 1000;
  1616. hdata->mode_conf.aspect_ratio = m->picture_aspect_ratio;
  1617. hdmi_set_reg(core->h_blank, 2, m->htotal - m->hdisplay);
  1618. hdmi_set_reg(core->h_v_line, 3, (m->htotal << 12) | m->vtotal);
  1619. val = (m->flags & DRM_MODE_FLAG_NVSYNC) ? 1 : 0;
  1620. hdmi_set_reg(core->vsync_pol, 1, val);
  1621. val = (m->flags & DRM_MODE_FLAG_INTERLACE) ? 1 : 0;
  1622. hdmi_set_reg(core->int_pro_mode, 1, val);
  1623. val = (m->hsync_start - m->hdisplay - 2);
  1624. val |= ((m->hsync_end - m->hdisplay - 2) << 10);
  1625. val |= ((m->flags & DRM_MODE_FLAG_NHSYNC) ? 1 : 0)<<20;
  1626. hdmi_set_reg(core->h_sync_gen, 3, val);
  1627. /*
  1628. * Quirk requirement for exynos HDMI IP design,
  1629. * 2 pixels less than the actual calculation for hsync_start
  1630. * and end.
  1631. */
  1632. /* Following values & calculations differ for different type of modes */
  1633. if (m->flags & DRM_MODE_FLAG_INTERLACE) {
  1634. /* Interlaced Mode */
  1635. val = ((m->vsync_end - m->vdisplay) / 2);
  1636. val |= ((m->vsync_start - m->vdisplay) / 2) << 12;
  1637. hdmi_set_reg(core->v_sync_gen1, 3, val);
  1638. val = m->vtotal / 2;
  1639. val |= ((m->vtotal - m->vdisplay) / 2) << 11;
  1640. hdmi_set_reg(core->v_blank, 3, val);
  1641. val = (m->vtotal +
  1642. ((m->vsync_end - m->vsync_start) * 4) + 5) / 2;
  1643. val |= m->vtotal << 11;
  1644. hdmi_set_reg(core->v_blank_f, 3, val);
  1645. val = ((m->vtotal / 2) + 7);
  1646. val |= ((m->vtotal / 2) + 2) << 12;
  1647. hdmi_set_reg(core->v_sync_gen2, 3, val);
  1648. val = ((m->htotal / 2) + (m->hsync_start - m->hdisplay));
  1649. val |= ((m->htotal / 2) +
  1650. (m->hsync_start - m->hdisplay)) << 12;
  1651. hdmi_set_reg(core->v_sync_gen3, 3, val);
  1652. hdmi_set_reg(tg->vact_st, 2, (m->vtotal - m->vdisplay) / 2);
  1653. hdmi_set_reg(tg->vact_sz, 2, m->vdisplay / 2);
  1654. hdmi_set_reg(tg->vact_st2, 2, 0x249);/* Reset value + 1*/
  1655. } else {
  1656. /* Progressive Mode */
  1657. val = m->vtotal;
  1658. val |= (m->vtotal - m->vdisplay) << 11;
  1659. hdmi_set_reg(core->v_blank, 3, val);
  1660. hdmi_set_reg(core->v_blank_f, 3, 0);
  1661. val = (m->vsync_end - m->vdisplay);
  1662. val |= ((m->vsync_start - m->vdisplay) << 12);
  1663. hdmi_set_reg(core->v_sync_gen1, 3, val);
  1664. hdmi_set_reg(core->v_sync_gen2, 3, 0x1001);/* Reset value */
  1665. hdmi_set_reg(core->v_sync_gen3, 3, 0x1001);/* Reset value */
  1666. hdmi_set_reg(tg->vact_st, 2, m->vtotal - m->vdisplay);
  1667. hdmi_set_reg(tg->vact_sz, 2, m->vdisplay);
  1668. hdmi_set_reg(tg->vact_st2, 2, 0x248); /* Reset value */
  1669. }
  1670. /* Timing generator registers */
  1671. hdmi_set_reg(tg->cmd, 1, 0x0);
  1672. hdmi_set_reg(tg->h_fsz, 2, m->htotal);
  1673. hdmi_set_reg(tg->hact_st, 2, m->htotal - m->hdisplay);
  1674. hdmi_set_reg(tg->hact_sz, 2, m->hdisplay);
  1675. hdmi_set_reg(tg->v_fsz, 2, m->vtotal);
  1676. hdmi_set_reg(tg->vsync, 2, 0x1);
  1677. hdmi_set_reg(tg->vsync2, 2, 0x233); /* Reset value */
  1678. hdmi_set_reg(tg->field_chg, 2, 0x233); /* Reset value */
  1679. hdmi_set_reg(tg->vsync_top_hdmi, 2, 0x1); /* Reset value */
  1680. hdmi_set_reg(tg->vsync_bot_hdmi, 2, 0x233); /* Reset value */
  1681. hdmi_set_reg(tg->field_top_hdmi, 2, 0x1); /* Reset value */
  1682. hdmi_set_reg(tg->field_bot_hdmi, 2, 0x233); /* Reset value */
  1683. hdmi_set_reg(tg->tg_3d, 1, 0x0); /* Not used */
  1684. }
  1685. static void hdmi_v14_mode_set(struct hdmi_context *hdata,
  1686. struct drm_display_mode *m)
  1687. {
  1688. struct hdmi_tg_regs *tg = &hdata->mode_conf.conf.v14_conf.tg;
  1689. struct hdmi_v14_core_regs *core =
  1690. &hdata->mode_conf.conf.v14_conf.core;
  1691. hdata->mode_conf.cea_video_id =
  1692. drm_match_cea_mode((struct drm_display_mode *)m);
  1693. hdata->mode_conf.pixel_clock = m->clock * 1000;
  1694. hdata->mode_conf.aspect_ratio = m->picture_aspect_ratio;
  1695. hdmi_set_reg(core->h_blank, 2, m->htotal - m->hdisplay);
  1696. hdmi_set_reg(core->v_line, 2, m->vtotal);
  1697. hdmi_set_reg(core->h_line, 2, m->htotal);
  1698. hdmi_set_reg(core->hsync_pol, 1,
  1699. (m->flags & DRM_MODE_FLAG_NHSYNC) ? 1 : 0);
  1700. hdmi_set_reg(core->vsync_pol, 1,
  1701. (m->flags & DRM_MODE_FLAG_NVSYNC) ? 1 : 0);
  1702. hdmi_set_reg(core->int_pro_mode, 1,
  1703. (m->flags & DRM_MODE_FLAG_INTERLACE) ? 1 : 0);
  1704. /*
  1705. * Quirk requirement for exynos 5 HDMI IP design,
  1706. * 2 pixels less than the actual calculation for hsync_start
  1707. * and end.
  1708. */
  1709. /* Following values & calculations differ for different type of modes */
  1710. if (m->flags & DRM_MODE_FLAG_INTERLACE) {
  1711. /* Interlaced Mode */
  1712. hdmi_set_reg(core->v_sync_line_bef_2, 2,
  1713. (m->vsync_end - m->vdisplay) / 2);
  1714. hdmi_set_reg(core->v_sync_line_bef_1, 2,
  1715. (m->vsync_start - m->vdisplay) / 2);
  1716. hdmi_set_reg(core->v2_blank, 2, m->vtotal / 2);
  1717. hdmi_set_reg(core->v1_blank, 2, (m->vtotal - m->vdisplay) / 2);
  1718. hdmi_set_reg(core->v_blank_f0, 2, m->vtotal - m->vdisplay / 2);
  1719. hdmi_set_reg(core->v_blank_f1, 2, m->vtotal);
  1720. hdmi_set_reg(core->v_sync_line_aft_2, 2, (m->vtotal / 2) + 7);
  1721. hdmi_set_reg(core->v_sync_line_aft_1, 2, (m->vtotal / 2) + 2);
  1722. hdmi_set_reg(core->v_sync_line_aft_pxl_2, 2,
  1723. (m->htotal / 2) + (m->hsync_start - m->hdisplay));
  1724. hdmi_set_reg(core->v_sync_line_aft_pxl_1, 2,
  1725. (m->htotal / 2) + (m->hsync_start - m->hdisplay));
  1726. hdmi_set_reg(tg->vact_st, 2, (m->vtotal - m->vdisplay) / 2);
  1727. hdmi_set_reg(tg->vact_sz, 2, m->vdisplay / 2);
  1728. hdmi_set_reg(tg->vact_st2, 2, m->vtotal - m->vdisplay / 2);
  1729. hdmi_set_reg(tg->vsync2, 2, (m->vtotal / 2) + 1);
  1730. hdmi_set_reg(tg->vsync_bot_hdmi, 2, (m->vtotal / 2) + 1);
  1731. hdmi_set_reg(tg->field_bot_hdmi, 2, (m->vtotal / 2) + 1);
  1732. hdmi_set_reg(tg->vact_st3, 2, 0x0);
  1733. hdmi_set_reg(tg->vact_st4, 2, 0x0);
  1734. } else {
  1735. /* Progressive Mode */
  1736. hdmi_set_reg(core->v_sync_line_bef_2, 2,
  1737. m->vsync_end - m->vdisplay);
  1738. hdmi_set_reg(core->v_sync_line_bef_1, 2,
  1739. m->vsync_start - m->vdisplay);
  1740. hdmi_set_reg(core->v2_blank, 2, m->vtotal);
  1741. hdmi_set_reg(core->v1_blank, 2, m->vtotal - m->vdisplay);
  1742. hdmi_set_reg(core->v_blank_f0, 2, 0xffff);
  1743. hdmi_set_reg(core->v_blank_f1, 2, 0xffff);
  1744. hdmi_set_reg(core->v_sync_line_aft_2, 2, 0xffff);
  1745. hdmi_set_reg(core->v_sync_line_aft_1, 2, 0xffff);
  1746. hdmi_set_reg(core->v_sync_line_aft_pxl_2, 2, 0xffff);
  1747. hdmi_set_reg(core->v_sync_line_aft_pxl_1, 2, 0xffff);
  1748. hdmi_set_reg(tg->vact_st, 2, m->vtotal - m->vdisplay);
  1749. hdmi_set_reg(tg->vact_sz, 2, m->vdisplay);
  1750. hdmi_set_reg(tg->vact_st2, 2, 0x248); /* Reset value */
  1751. hdmi_set_reg(tg->vact_st3, 2, 0x47b); /* Reset value */
  1752. hdmi_set_reg(tg->vact_st4, 2, 0x6ae); /* Reset value */
  1753. hdmi_set_reg(tg->vsync2, 2, 0x233); /* Reset value */
  1754. hdmi_set_reg(tg->vsync_bot_hdmi, 2, 0x233); /* Reset value */
  1755. hdmi_set_reg(tg->field_bot_hdmi, 2, 0x233); /* Reset value */
  1756. }
  1757. /* Following values & calculations are same irrespective of mode type */
  1758. hdmi_set_reg(core->h_sync_start, 2, m->hsync_start - m->hdisplay - 2);
  1759. hdmi_set_reg(core->h_sync_end, 2, m->hsync_end - m->hdisplay - 2);
  1760. hdmi_set_reg(core->vact_space_1, 2, 0xffff);
  1761. hdmi_set_reg(core->vact_space_2, 2, 0xffff);
  1762. hdmi_set_reg(core->vact_space_3, 2, 0xffff);
  1763. hdmi_set_reg(core->vact_space_4, 2, 0xffff);
  1764. hdmi_set_reg(core->vact_space_5, 2, 0xffff);
  1765. hdmi_set_reg(core->vact_space_6, 2, 0xffff);
  1766. hdmi_set_reg(core->v_blank_f2, 2, 0xffff);
  1767. hdmi_set_reg(core->v_blank_f3, 2, 0xffff);
  1768. hdmi_set_reg(core->v_blank_f4, 2, 0xffff);
  1769. hdmi_set_reg(core->v_blank_f5, 2, 0xffff);
  1770. hdmi_set_reg(core->v_sync_line_aft_3, 2, 0xffff);
  1771. hdmi_set_reg(core->v_sync_line_aft_4, 2, 0xffff);
  1772. hdmi_set_reg(core->v_sync_line_aft_5, 2, 0xffff);
  1773. hdmi_set_reg(core->v_sync_line_aft_6, 2, 0xffff);
  1774. hdmi_set_reg(core->v_sync_line_aft_pxl_3, 2, 0xffff);
  1775. hdmi_set_reg(core->v_sync_line_aft_pxl_4, 2, 0xffff);
  1776. hdmi_set_reg(core->v_sync_line_aft_pxl_5, 2, 0xffff);
  1777. hdmi_set_reg(core->v_sync_line_aft_pxl_6, 2, 0xffff);
  1778. /* Timing generator registers */
  1779. hdmi_set_reg(tg->cmd, 1, 0x0);
  1780. hdmi_set_reg(tg->h_fsz, 2, m->htotal);
  1781. hdmi_set_reg(tg->hact_st, 2, m->htotal - m->hdisplay);
  1782. hdmi_set_reg(tg->hact_sz, 2, m->hdisplay);
  1783. hdmi_set_reg(tg->v_fsz, 2, m->vtotal);
  1784. hdmi_set_reg(tg->vsync, 2, 0x1);
  1785. hdmi_set_reg(tg->field_chg, 2, 0x233); /* Reset value */
  1786. hdmi_set_reg(tg->vsync_top_hdmi, 2, 0x1); /* Reset value */
  1787. hdmi_set_reg(tg->field_top_hdmi, 2, 0x1); /* Reset value */
  1788. hdmi_set_reg(tg->tg_3d, 1, 0x0);
  1789. }
  1790. static void hdmi_mode_set(struct exynos_drm_display *display,
  1791. struct drm_display_mode *mode)
  1792. {
  1793. struct hdmi_context *hdata = display->ctx;
  1794. struct drm_display_mode *m = mode;
  1795. DRM_DEBUG_KMS("xres=%d, yres=%d, refresh=%d, intl=%s\n",
  1796. m->hdisplay, m->vdisplay,
  1797. m->vrefresh, (m->flags & DRM_MODE_FLAG_INTERLACE) ?
  1798. "INTERLACED" : "PROGERESSIVE");
  1799. /* preserve mode information for later use. */
  1800. drm_mode_copy(&hdata->current_mode, mode);
  1801. if (hdata->type == HDMI_TYPE13)
  1802. hdmi_v13_mode_set(hdata, mode);
  1803. else
  1804. hdmi_v14_mode_set(hdata, mode);
  1805. }
  1806. static void hdmi_commit(struct exynos_drm_display *display)
  1807. {
  1808. struct hdmi_context *hdata = display->ctx;
  1809. mutex_lock(&hdata->hdmi_mutex);
  1810. if (!hdata->powered) {
  1811. mutex_unlock(&hdata->hdmi_mutex);
  1812. return;
  1813. }
  1814. mutex_unlock(&hdata->hdmi_mutex);
  1815. hdmi_conf_apply(hdata);
  1816. }
  1817. static void hdmi_poweron(struct exynos_drm_display *display)
  1818. {
  1819. struct hdmi_context *hdata = display->ctx;
  1820. struct hdmi_resources *res = &hdata->res;
  1821. mutex_lock(&hdata->hdmi_mutex);
  1822. if (hdata->powered) {
  1823. mutex_unlock(&hdata->hdmi_mutex);
  1824. return;
  1825. }
  1826. hdata->powered = true;
  1827. mutex_unlock(&hdata->hdmi_mutex);
  1828. pm_runtime_get_sync(hdata->dev);
  1829. if (regulator_bulk_enable(res->regul_count, res->regul_bulk))
  1830. DRM_DEBUG_KMS("failed to enable regulator bulk\n");
  1831. /* set pmu hdmiphy control bit to enable hdmiphy */
  1832. regmap_update_bits(hdata->pmureg, PMU_HDMI_PHY_CONTROL,
  1833. PMU_HDMI_PHY_ENABLE_BIT, 1);
  1834. clk_prepare_enable(res->hdmi);
  1835. clk_prepare_enable(res->sclk_hdmi);
  1836. hdmiphy_poweron(hdata);
  1837. hdmi_commit(display);
  1838. }
  1839. static void hdmi_poweroff(struct exynos_drm_display *display)
  1840. {
  1841. struct hdmi_context *hdata = display->ctx;
  1842. struct hdmi_resources *res = &hdata->res;
  1843. mutex_lock(&hdata->hdmi_mutex);
  1844. if (!hdata->powered)
  1845. goto out;
  1846. mutex_unlock(&hdata->hdmi_mutex);
  1847. /* HDMI System Disable */
  1848. hdmi_reg_writemask(hdata, HDMI_CON_0, 0, HDMI_EN);
  1849. hdmiphy_poweroff(hdata);
  1850. cancel_delayed_work(&hdata->hotplug_work);
  1851. clk_disable_unprepare(res->sclk_hdmi);
  1852. clk_disable_unprepare(res->hdmi);
  1853. /* reset pmu hdmiphy control bit to disable hdmiphy */
  1854. regmap_update_bits(hdata->pmureg, PMU_HDMI_PHY_CONTROL,
  1855. PMU_HDMI_PHY_ENABLE_BIT, 0);
  1856. regulator_bulk_disable(res->regul_count, res->regul_bulk);
  1857. pm_runtime_put_sync(hdata->dev);
  1858. mutex_lock(&hdata->hdmi_mutex);
  1859. hdata->powered = false;
  1860. out:
  1861. mutex_unlock(&hdata->hdmi_mutex);
  1862. }
  1863. static void hdmi_dpms(struct exynos_drm_display *display, int mode)
  1864. {
  1865. struct hdmi_context *hdata = display->ctx;
  1866. struct drm_encoder *encoder = hdata->encoder;
  1867. struct drm_crtc *crtc = encoder->crtc;
  1868. struct drm_crtc_helper_funcs *funcs = NULL;
  1869. DRM_DEBUG_KMS("mode %d\n", mode);
  1870. switch (mode) {
  1871. case DRM_MODE_DPMS_ON:
  1872. hdmi_poweron(display);
  1873. break;
  1874. case DRM_MODE_DPMS_STANDBY:
  1875. case DRM_MODE_DPMS_SUSPEND:
  1876. case DRM_MODE_DPMS_OFF:
  1877. /*
  1878. * The SFRs of VP and Mixer are updated by Vertical Sync of
  1879. * Timing generator which is a part of HDMI so the sequence
  1880. * to disable TV Subsystem should be as following,
  1881. * VP -> Mixer -> HDMI
  1882. *
  1883. * Below codes will try to disable Mixer and VP(if used)
  1884. * prior to disabling HDMI.
  1885. */
  1886. if (crtc)
  1887. funcs = crtc->helper_private;
  1888. if (funcs && funcs->dpms)
  1889. (*funcs->dpms)(crtc, mode);
  1890. hdmi_poweroff(display);
  1891. break;
  1892. default:
  1893. DRM_DEBUG_KMS("unknown dpms mode: %d\n", mode);
  1894. break;
  1895. }
  1896. }
  1897. static struct exynos_drm_display_ops hdmi_display_ops = {
  1898. .create_connector = hdmi_create_connector,
  1899. .mode_fixup = hdmi_mode_fixup,
  1900. .mode_set = hdmi_mode_set,
  1901. .dpms = hdmi_dpms,
  1902. .commit = hdmi_commit,
  1903. };
  1904. static struct exynos_drm_display hdmi_display = {
  1905. .type = EXYNOS_DISPLAY_TYPE_HDMI,
  1906. .ops = &hdmi_display_ops,
  1907. };
  1908. static void hdmi_hotplug_work_func(struct work_struct *work)
  1909. {
  1910. struct hdmi_context *hdata;
  1911. hdata = container_of(work, struct hdmi_context, hotplug_work.work);
  1912. mutex_lock(&hdata->hdmi_mutex);
  1913. hdata->hpd = gpio_get_value(hdata->hpd_gpio);
  1914. mutex_unlock(&hdata->hdmi_mutex);
  1915. if (hdata->drm_dev)
  1916. drm_helper_hpd_irq_event(hdata->drm_dev);
  1917. }
  1918. static irqreturn_t hdmi_irq_thread(int irq, void *arg)
  1919. {
  1920. struct hdmi_context *hdata = arg;
  1921. mod_delayed_work(system_wq, &hdata->hotplug_work,
  1922. msecs_to_jiffies(HOTPLUG_DEBOUNCE_MS));
  1923. return IRQ_HANDLED;
  1924. }
  1925. static int hdmi_resources_init(struct hdmi_context *hdata)
  1926. {
  1927. struct device *dev = hdata->dev;
  1928. struct hdmi_resources *res = &hdata->res;
  1929. static char *supply[] = {
  1930. "vdd",
  1931. "vdd_osc",
  1932. "vdd_pll",
  1933. };
  1934. int i, ret;
  1935. DRM_DEBUG_KMS("HDMI resource init\n");
  1936. /* get clocks, power */
  1937. res->hdmi = devm_clk_get(dev, "hdmi");
  1938. if (IS_ERR(res->hdmi)) {
  1939. DRM_ERROR("failed to get clock 'hdmi'\n");
  1940. ret = PTR_ERR(res->hdmi);
  1941. goto fail;
  1942. }
  1943. res->sclk_hdmi = devm_clk_get(dev, "sclk_hdmi");
  1944. if (IS_ERR(res->sclk_hdmi)) {
  1945. DRM_ERROR("failed to get clock 'sclk_hdmi'\n");
  1946. ret = PTR_ERR(res->sclk_hdmi);
  1947. goto fail;
  1948. }
  1949. res->sclk_pixel = devm_clk_get(dev, "sclk_pixel");
  1950. if (IS_ERR(res->sclk_pixel)) {
  1951. DRM_ERROR("failed to get clock 'sclk_pixel'\n");
  1952. ret = PTR_ERR(res->sclk_pixel);
  1953. goto fail;
  1954. }
  1955. res->sclk_hdmiphy = devm_clk_get(dev, "sclk_hdmiphy");
  1956. if (IS_ERR(res->sclk_hdmiphy)) {
  1957. DRM_ERROR("failed to get clock 'sclk_hdmiphy'\n");
  1958. ret = PTR_ERR(res->sclk_hdmiphy);
  1959. goto fail;
  1960. }
  1961. res->mout_hdmi = devm_clk_get(dev, "mout_hdmi");
  1962. if (IS_ERR(res->mout_hdmi)) {
  1963. DRM_ERROR("failed to get clock 'mout_hdmi'\n");
  1964. ret = PTR_ERR(res->mout_hdmi);
  1965. goto fail;
  1966. }
  1967. clk_set_parent(res->mout_hdmi, res->sclk_pixel);
  1968. res->regul_bulk = devm_kzalloc(dev, ARRAY_SIZE(supply) *
  1969. sizeof(res->regul_bulk[0]), GFP_KERNEL);
  1970. if (!res->regul_bulk) {
  1971. ret = -ENOMEM;
  1972. goto fail;
  1973. }
  1974. for (i = 0; i < ARRAY_SIZE(supply); ++i) {
  1975. res->regul_bulk[i].supply = supply[i];
  1976. res->regul_bulk[i].consumer = NULL;
  1977. }
  1978. ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(supply), res->regul_bulk);
  1979. if (ret) {
  1980. DRM_ERROR("failed to get regulators\n");
  1981. return ret;
  1982. }
  1983. res->regul_count = ARRAY_SIZE(supply);
  1984. res->reg_hdmi_en = devm_regulator_get(dev, "hdmi-en");
  1985. if (IS_ERR(res->reg_hdmi_en) && PTR_ERR(res->reg_hdmi_en) != -ENOENT) {
  1986. DRM_ERROR("failed to get hdmi-en regulator\n");
  1987. return PTR_ERR(res->reg_hdmi_en);
  1988. }
  1989. if (!IS_ERR(res->reg_hdmi_en)) {
  1990. ret = regulator_enable(res->reg_hdmi_en);
  1991. if (ret) {
  1992. DRM_ERROR("failed to enable hdmi-en regulator\n");
  1993. return ret;
  1994. }
  1995. } else
  1996. res->reg_hdmi_en = NULL;
  1997. return ret;
  1998. fail:
  1999. DRM_ERROR("HDMI resource init - failed\n");
  2000. return ret;
  2001. }
  2002. static struct s5p_hdmi_platform_data *drm_hdmi_dt_parse_pdata
  2003. (struct device *dev)
  2004. {
  2005. struct device_node *np = dev->of_node;
  2006. struct s5p_hdmi_platform_data *pd;
  2007. u32 value;
  2008. pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL);
  2009. if (!pd)
  2010. goto err_data;
  2011. if (!of_find_property(np, "hpd-gpio", &value)) {
  2012. DRM_ERROR("no hpd gpio property found\n");
  2013. goto err_data;
  2014. }
  2015. pd->hpd_gpio = of_get_named_gpio(np, "hpd-gpio", 0);
  2016. return pd;
  2017. err_data:
  2018. return NULL;
  2019. }
  2020. static struct of_device_id hdmi_match_types[] = {
  2021. {
  2022. .compatible = "samsung,exynos5-hdmi",
  2023. .data = &exynos5_hdmi_driver_data,
  2024. }, {
  2025. .compatible = "samsung,exynos4210-hdmi",
  2026. .data = &exynos4210_hdmi_driver_data,
  2027. }, {
  2028. .compatible = "samsung,exynos4212-hdmi",
  2029. .data = &exynos4212_hdmi_driver_data,
  2030. }, {
  2031. .compatible = "samsung,exynos5420-hdmi",
  2032. .data = &exynos5420_hdmi_driver_data,
  2033. }, {
  2034. /* end node */
  2035. }
  2036. };
  2037. MODULE_DEVICE_TABLE (of, hdmi_match_types);
  2038. static int hdmi_bind(struct device *dev, struct device *master, void *data)
  2039. {
  2040. struct drm_device *drm_dev = data;
  2041. struct hdmi_context *hdata;
  2042. hdata = hdmi_display.ctx;
  2043. hdata->drm_dev = drm_dev;
  2044. return exynos_drm_create_enc_conn(drm_dev, &hdmi_display);
  2045. }
  2046. static void hdmi_unbind(struct device *dev, struct device *master, void *data)
  2047. {
  2048. }
  2049. static const struct component_ops hdmi_component_ops = {
  2050. .bind = hdmi_bind,
  2051. .unbind = hdmi_unbind,
  2052. };
  2053. static struct device_node *hdmi_legacy_ddc_dt_binding(struct device *dev)
  2054. {
  2055. const char *compatible_str = "samsung,exynos4210-hdmiddc";
  2056. struct device_node *np;
  2057. np = of_find_compatible_node(NULL, NULL, compatible_str);
  2058. if (np)
  2059. return of_get_next_parent(np);
  2060. return NULL;
  2061. }
  2062. static struct device_node *hdmi_legacy_phy_dt_binding(struct device *dev)
  2063. {
  2064. const char *compatible_str = "samsung,exynos4212-hdmiphy";
  2065. return of_find_compatible_node(NULL, NULL, compatible_str);
  2066. }
  2067. static int hdmi_probe(struct platform_device *pdev)
  2068. {
  2069. struct device_node *ddc_node, *phy_node;
  2070. struct s5p_hdmi_platform_data *pdata;
  2071. struct hdmi_driver_data *drv_data;
  2072. const struct of_device_id *match;
  2073. struct device *dev = &pdev->dev;
  2074. struct hdmi_context *hdata;
  2075. struct resource *res;
  2076. int ret;
  2077. ret = exynos_drm_component_add(&pdev->dev, EXYNOS_DEVICE_TYPE_CONNECTOR,
  2078. hdmi_display.type);
  2079. if (ret)
  2080. return ret;
  2081. if (!dev->of_node) {
  2082. ret = -ENODEV;
  2083. goto err_del_component;
  2084. }
  2085. pdata = drm_hdmi_dt_parse_pdata(dev);
  2086. if (!pdata) {
  2087. ret = -EINVAL;
  2088. goto err_del_component;
  2089. }
  2090. hdata = devm_kzalloc(dev, sizeof(struct hdmi_context), GFP_KERNEL);
  2091. if (!hdata) {
  2092. ret = -ENOMEM;
  2093. goto err_del_component;
  2094. }
  2095. mutex_init(&hdata->hdmi_mutex);
  2096. platform_set_drvdata(pdev, &hdmi_display);
  2097. match = of_match_node(hdmi_match_types, dev->of_node);
  2098. if (!match) {
  2099. ret = -ENODEV;
  2100. goto err_del_component;
  2101. }
  2102. drv_data = (struct hdmi_driver_data *)match->data;
  2103. hdata->type = drv_data->type;
  2104. hdata->phy_confs = drv_data->phy_confs;
  2105. hdata->phy_conf_count = drv_data->phy_conf_count;
  2106. hdata->hpd_gpio = pdata->hpd_gpio;
  2107. hdata->dev = dev;
  2108. ret = hdmi_resources_init(hdata);
  2109. if (ret) {
  2110. DRM_ERROR("hdmi_resources_init failed\n");
  2111. return ret;
  2112. }
  2113. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  2114. hdata->regs = devm_ioremap_resource(dev, res);
  2115. if (IS_ERR(hdata->regs)) {
  2116. ret = PTR_ERR(hdata->regs);
  2117. goto err_del_component;
  2118. }
  2119. ret = devm_gpio_request(dev, hdata->hpd_gpio, "HPD");
  2120. if (ret) {
  2121. DRM_ERROR("failed to request HPD gpio\n");
  2122. goto err_del_component;
  2123. }
  2124. ddc_node = hdmi_legacy_ddc_dt_binding(dev);
  2125. if (ddc_node)
  2126. goto out_get_ddc_adpt;
  2127. /* DDC i2c driver */
  2128. ddc_node = of_parse_phandle(dev->of_node, "ddc", 0);
  2129. if (!ddc_node) {
  2130. DRM_ERROR("Failed to find ddc node in device tree\n");
  2131. ret = -ENODEV;
  2132. goto err_del_component;
  2133. }
  2134. out_get_ddc_adpt:
  2135. hdata->ddc_adpt = of_find_i2c_adapter_by_node(ddc_node);
  2136. if (!hdata->ddc_adpt) {
  2137. DRM_ERROR("Failed to get ddc i2c adapter by node\n");
  2138. return -EPROBE_DEFER;
  2139. }
  2140. phy_node = hdmi_legacy_phy_dt_binding(dev);
  2141. if (phy_node)
  2142. goto out_get_phy_port;
  2143. /* hdmiphy i2c driver */
  2144. phy_node = of_parse_phandle(dev->of_node, "phy", 0);
  2145. if (!phy_node) {
  2146. DRM_ERROR("Failed to find hdmiphy node in device tree\n");
  2147. ret = -ENODEV;
  2148. goto err_ddc;
  2149. }
  2150. out_get_phy_port:
  2151. if (drv_data->is_apb_phy) {
  2152. hdata->regs_hdmiphy = of_iomap(phy_node, 0);
  2153. if (!hdata->regs_hdmiphy) {
  2154. DRM_ERROR("failed to ioremap hdmi phy\n");
  2155. ret = -ENOMEM;
  2156. goto err_ddc;
  2157. }
  2158. } else {
  2159. hdata->hdmiphy_port = of_find_i2c_device_by_node(phy_node);
  2160. if (!hdata->hdmiphy_port) {
  2161. DRM_ERROR("Failed to get hdmi phy i2c client\n");
  2162. ret = -EPROBE_DEFER;
  2163. goto err_ddc;
  2164. }
  2165. }
  2166. hdata->irq = gpio_to_irq(hdata->hpd_gpio);
  2167. if (hdata->irq < 0) {
  2168. DRM_ERROR("failed to get GPIO irq\n");
  2169. ret = hdata->irq;
  2170. goto err_hdmiphy;
  2171. }
  2172. hdata->hpd = gpio_get_value(hdata->hpd_gpio);
  2173. INIT_DELAYED_WORK(&hdata->hotplug_work, hdmi_hotplug_work_func);
  2174. ret = devm_request_threaded_irq(dev, hdata->irq, NULL,
  2175. hdmi_irq_thread, IRQF_TRIGGER_RISING |
  2176. IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
  2177. "hdmi", hdata);
  2178. if (ret) {
  2179. DRM_ERROR("failed to register hdmi interrupt\n");
  2180. goto err_hdmiphy;
  2181. }
  2182. hdata->pmureg = syscon_regmap_lookup_by_phandle(dev->of_node,
  2183. "samsung,syscon-phandle");
  2184. if (IS_ERR(hdata->pmureg)) {
  2185. DRM_ERROR("syscon regmap lookup failed.\n");
  2186. ret = -EPROBE_DEFER;
  2187. goto err_hdmiphy;
  2188. }
  2189. pm_runtime_enable(dev);
  2190. hdmi_display.ctx = hdata;
  2191. ret = component_add(&pdev->dev, &hdmi_component_ops);
  2192. if (ret)
  2193. goto err_disable_pm_runtime;
  2194. return ret;
  2195. err_disable_pm_runtime:
  2196. pm_runtime_disable(dev);
  2197. err_hdmiphy:
  2198. if (hdata->hdmiphy_port)
  2199. put_device(&hdata->hdmiphy_port->dev);
  2200. err_ddc:
  2201. put_device(&hdata->ddc_adpt->dev);
  2202. err_del_component:
  2203. exynos_drm_component_del(&pdev->dev, EXYNOS_DEVICE_TYPE_CONNECTOR);
  2204. return ret;
  2205. }
  2206. static int hdmi_remove(struct platform_device *pdev)
  2207. {
  2208. struct hdmi_context *hdata = hdmi_display.ctx;
  2209. cancel_delayed_work_sync(&hdata->hotplug_work);
  2210. if (hdata->res.reg_hdmi_en)
  2211. regulator_disable(hdata->res.reg_hdmi_en);
  2212. if (hdata->hdmiphy_port)
  2213. put_device(&hdata->hdmiphy_port->dev);
  2214. put_device(&hdata->ddc_adpt->dev);
  2215. pm_runtime_disable(&pdev->dev);
  2216. component_del(&pdev->dev, &hdmi_component_ops);
  2217. exynos_drm_component_del(&pdev->dev, EXYNOS_DEVICE_TYPE_CONNECTOR);
  2218. return 0;
  2219. }
  2220. struct platform_driver hdmi_driver = {
  2221. .probe = hdmi_probe,
  2222. .remove = hdmi_remove,
  2223. .driver = {
  2224. .name = "exynos-hdmi",
  2225. .owner = THIS_MODULE,
  2226. .of_match_table = hdmi_match_types,
  2227. },
  2228. };