exynos_hdmi.c 72 KB

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