exynos_hdmi.c 73 KB

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