exynos_hdmi.c 75 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719
  1. /*
  2. * Copyright (C) 2011 Samsung Electronics Co.Ltd
  3. * Authors:
  4. * Seung-Woo Kim <sw0312.kim@samsung.com>
  5. * Inki Dae <inki.dae@samsung.com>
  6. * Joonyoung Shim <jy0922.shim@samsung.com>
  7. *
  8. * Based on drivers/media/video/s5p-tv/hdmi_drv.c
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License as published by the
  12. * Free Software Foundation; either version 2 of the License, or (at your
  13. * option) any later version.
  14. *
  15. */
  16. #include <drm/drmP.h>
  17. #include <drm/drm_edid.h>
  18. #include <drm/drm_crtc_helper.h>
  19. #include "regs-hdmi.h"
  20. #include <linux/kernel.h>
  21. #include <linux/spinlock.h>
  22. #include <linux/wait.h>
  23. #include <linux/i2c.h>
  24. #include <linux/module.h>
  25. #include <linux/platform_device.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/irq.h>
  28. #include <linux/delay.h>
  29. #include <linux/pm_runtime.h>
  30. #include <linux/clk.h>
  31. #include <linux/regulator/consumer.h>
  32. #include <linux/io.h>
  33. #include <linux/of_gpio.h>
  34. #include <plat/gpio-cfg.h>
  35. #include <drm/exynos_drm.h>
  36. #include "exynos_drm_drv.h"
  37. #include "exynos_drm_hdmi.h"
  38. #include "exynos_hdmi.h"
  39. #include <linux/gpio.h>
  40. #include <media/s5p_hdmi.h>
  41. #define MAX_WIDTH 1920
  42. #define MAX_HEIGHT 1080
  43. #define get_hdmi_context(dev) platform_get_drvdata(to_platform_device(dev))
  44. /* AVI header and aspect ratio */
  45. #define HDMI_AVI_VERSION 0x02
  46. #define HDMI_AVI_LENGTH 0x0D
  47. #define AVI_PIC_ASPECT_RATIO_16_9 (2 << 4)
  48. #define AVI_SAME_AS_PIC_ASPECT_RATIO 8
  49. /* AUI header info */
  50. #define HDMI_AUI_VERSION 0x01
  51. #define HDMI_AUI_LENGTH 0x0A
  52. /* HDMI infoframe to configure HDMI out packet header, AUI and AVI */
  53. enum HDMI_PACKET_TYPE {
  54. /* refer to Table 5-8 Packet Type in HDMI specification v1.4a */
  55. /* InfoFrame packet type */
  56. HDMI_PACKET_TYPE_INFOFRAME = 0x80,
  57. /* Vendor-Specific InfoFrame */
  58. HDMI_PACKET_TYPE_VSI = HDMI_PACKET_TYPE_INFOFRAME + 1,
  59. /* Auxiliary Video information InfoFrame */
  60. HDMI_PACKET_TYPE_AVI = HDMI_PACKET_TYPE_INFOFRAME + 2,
  61. /* Audio information InfoFrame */
  62. HDMI_PACKET_TYPE_AUI = HDMI_PACKET_TYPE_INFOFRAME + 4
  63. };
  64. enum hdmi_type {
  65. HDMI_TYPE13,
  66. HDMI_TYPE14,
  67. };
  68. struct hdmi_resources {
  69. struct clk *hdmi;
  70. struct clk *sclk_hdmi;
  71. struct clk *sclk_pixel;
  72. struct clk *sclk_hdmiphy;
  73. struct clk *hdmiphy;
  74. struct regulator_bulk_data *regul_bulk;
  75. int regul_count;
  76. };
  77. struct hdmi_context {
  78. struct device *dev;
  79. struct drm_device *drm_dev;
  80. bool hpd;
  81. bool powered;
  82. bool dvi_mode;
  83. struct mutex hdmi_mutex;
  84. void __iomem *regs;
  85. void *parent_ctx;
  86. int external_irq;
  87. int internal_irq;
  88. struct i2c_client *ddc_port;
  89. struct i2c_client *hdmiphy_port;
  90. /* current hdmiphy conf index */
  91. int cur_conf;
  92. struct hdmi_resources res;
  93. int hpd_gpio;
  94. enum hdmi_type type;
  95. };
  96. /* HDMI Version 1.3 */
  97. static const u8 hdmiphy_v13_conf27[32] = {
  98. 0x01, 0x05, 0x00, 0xD8, 0x10, 0x1C, 0x30, 0x40,
  99. 0x6B, 0x10, 0x02, 0x51, 0xDF, 0xF2, 0x54, 0x87,
  100. 0x84, 0x00, 0x30, 0x38, 0x00, 0x08, 0x10, 0xE0,
  101. 0x22, 0x40, 0xE3, 0x26, 0x00, 0x00, 0x00, 0x00,
  102. };
  103. static const u8 hdmiphy_v13_conf27_027[32] = {
  104. 0x01, 0x05, 0x00, 0xD4, 0x10, 0x9C, 0x09, 0x64,
  105. 0x6B, 0x10, 0x02, 0x51, 0xDF, 0xF2, 0x54, 0x87,
  106. 0x84, 0x00, 0x30, 0x38, 0x00, 0x08, 0x10, 0xE0,
  107. 0x22, 0x40, 0xE3, 0x26, 0x00, 0x00, 0x00, 0x00,
  108. };
  109. static const u8 hdmiphy_v13_conf74_175[32] = {
  110. 0x01, 0x05, 0x00, 0xD8, 0x10, 0x9C, 0xef, 0x5B,
  111. 0x6D, 0x10, 0x01, 0x51, 0xef, 0xF3, 0x54, 0xb9,
  112. 0x84, 0x00, 0x30, 0x38, 0x00, 0x08, 0x10, 0xE0,
  113. 0x22, 0x40, 0xa5, 0x26, 0x01, 0x00, 0x00, 0x00,
  114. };
  115. static const u8 hdmiphy_v13_conf74_25[32] = {
  116. 0x01, 0x05, 0x00, 0xd8, 0x10, 0x9c, 0xf8, 0x40,
  117. 0x6a, 0x10, 0x01, 0x51, 0xff, 0xf1, 0x54, 0xba,
  118. 0x84, 0x00, 0x10, 0x38, 0x00, 0x08, 0x10, 0xe0,
  119. 0x22, 0x40, 0xa4, 0x26, 0x01, 0x00, 0x00, 0x00,
  120. };
  121. static const u8 hdmiphy_v13_conf148_5[32] = {
  122. 0x01, 0x05, 0x00, 0xD8, 0x10, 0x9C, 0xf8, 0x40,
  123. 0x6A, 0x18, 0x00, 0x51, 0xff, 0xF1, 0x54, 0xba,
  124. 0x84, 0x00, 0x10, 0x38, 0x00, 0x08, 0x10, 0xE0,
  125. 0x22, 0x40, 0xa4, 0x26, 0x02, 0x00, 0x00, 0x00,
  126. };
  127. struct hdmi_v13_tg_regs {
  128. u8 cmd;
  129. u8 h_fsz_l;
  130. u8 h_fsz_h;
  131. u8 hact_st_l;
  132. u8 hact_st_h;
  133. u8 hact_sz_l;
  134. u8 hact_sz_h;
  135. u8 v_fsz_l;
  136. u8 v_fsz_h;
  137. u8 vsync_l;
  138. u8 vsync_h;
  139. u8 vsync2_l;
  140. u8 vsync2_h;
  141. u8 vact_st_l;
  142. u8 vact_st_h;
  143. u8 vact_sz_l;
  144. u8 vact_sz_h;
  145. u8 field_chg_l;
  146. u8 field_chg_h;
  147. u8 vact_st2_l;
  148. u8 vact_st2_h;
  149. u8 vsync_top_hdmi_l;
  150. u8 vsync_top_hdmi_h;
  151. u8 vsync_bot_hdmi_l;
  152. u8 vsync_bot_hdmi_h;
  153. u8 field_top_hdmi_l;
  154. u8 field_top_hdmi_h;
  155. u8 field_bot_hdmi_l;
  156. u8 field_bot_hdmi_h;
  157. };
  158. struct hdmi_v13_core_regs {
  159. u8 h_blank[2];
  160. u8 v_blank[3];
  161. u8 h_v_line[3];
  162. u8 vsync_pol[1];
  163. u8 int_pro_mode[1];
  164. u8 v_blank_f[3];
  165. u8 h_sync_gen[3];
  166. u8 v_sync_gen1[3];
  167. u8 v_sync_gen2[3];
  168. u8 v_sync_gen3[3];
  169. };
  170. struct hdmi_v13_preset_conf {
  171. struct hdmi_v13_core_regs core;
  172. struct hdmi_v13_tg_regs tg;
  173. };
  174. struct hdmi_v13_conf {
  175. int width;
  176. int height;
  177. int vrefresh;
  178. bool interlace;
  179. int cea_video_id;
  180. const u8 *hdmiphy_data;
  181. const struct hdmi_v13_preset_conf *conf;
  182. };
  183. static const struct hdmi_v13_preset_conf hdmi_v13_conf_480p = {
  184. .core = {
  185. .h_blank = {0x8a, 0x00},
  186. .v_blank = {0x0d, 0x6a, 0x01},
  187. .h_v_line = {0x0d, 0xa2, 0x35},
  188. .vsync_pol = {0x01},
  189. .int_pro_mode = {0x00},
  190. .v_blank_f = {0x00, 0x00, 0x00},
  191. .h_sync_gen = {0x0e, 0x30, 0x11},
  192. .v_sync_gen1 = {0x0f, 0x90, 0x00},
  193. /* other don't care */
  194. },
  195. .tg = {
  196. 0x00, /* cmd */
  197. 0x5a, 0x03, /* h_fsz */
  198. 0x8a, 0x00, 0xd0, 0x02, /* hact */
  199. 0x0d, 0x02, /* v_fsz */
  200. 0x01, 0x00, 0x33, 0x02, /* vsync */
  201. 0x2d, 0x00, 0xe0, 0x01, /* vact */
  202. 0x33, 0x02, /* field_chg */
  203. 0x49, 0x02, /* vact_st2 */
  204. 0x01, 0x00, 0x33, 0x02, /* vsync top/bot */
  205. 0x01, 0x00, 0x33, 0x02, /* field top/bot */
  206. },
  207. };
  208. static const struct hdmi_v13_preset_conf hdmi_v13_conf_720p60 = {
  209. .core = {
  210. .h_blank = {0x72, 0x01},
  211. .v_blank = {0xee, 0xf2, 0x00},
  212. .h_v_line = {0xee, 0x22, 0x67},
  213. .vsync_pol = {0x00},
  214. .int_pro_mode = {0x00},
  215. .v_blank_f = {0x00, 0x00, 0x00}, /* don't care */
  216. .h_sync_gen = {0x6c, 0x50, 0x02},
  217. .v_sync_gen1 = {0x0a, 0x50, 0x00},
  218. .v_sync_gen2 = {0x01, 0x10, 0x00},
  219. .v_sync_gen3 = {0x01, 0x10, 0x00},
  220. /* other don't care */
  221. },
  222. .tg = {
  223. 0x00, /* cmd */
  224. 0x72, 0x06, /* h_fsz */
  225. 0x71, 0x01, 0x01, 0x05, /* hact */
  226. 0xee, 0x02, /* v_fsz */
  227. 0x01, 0x00, 0x33, 0x02, /* vsync */
  228. 0x1e, 0x00, 0xd0, 0x02, /* vact */
  229. 0x33, 0x02, /* field_chg */
  230. 0x49, 0x02, /* vact_st2 */
  231. 0x01, 0x00, 0x01, 0x00, /* vsync top/bot */
  232. 0x01, 0x00, 0x33, 0x02, /* field top/bot */
  233. },
  234. };
  235. static const struct hdmi_v13_preset_conf hdmi_v13_conf_1080i50 = {
  236. .core = {
  237. .h_blank = {0xd0, 0x02},
  238. .v_blank = {0x32, 0xB2, 0x00},
  239. .h_v_line = {0x65, 0x04, 0xa5},
  240. .vsync_pol = {0x00},
  241. .int_pro_mode = {0x01},
  242. .v_blank_f = {0x49, 0x2A, 0x23},
  243. .h_sync_gen = {0x0E, 0xEA, 0x08},
  244. .v_sync_gen1 = {0x07, 0x20, 0x00},
  245. .v_sync_gen2 = {0x39, 0x42, 0x23},
  246. .v_sync_gen3 = {0x38, 0x87, 0x73},
  247. /* other don't care */
  248. },
  249. .tg = {
  250. 0x00, /* cmd */
  251. 0x50, 0x0A, /* h_fsz */
  252. 0xCF, 0x02, 0x81, 0x07, /* hact */
  253. 0x65, 0x04, /* v_fsz */
  254. 0x01, 0x00, 0x33, 0x02, /* vsync */
  255. 0x16, 0x00, 0x1c, 0x02, /* vact */
  256. 0x33, 0x02, /* field_chg */
  257. 0x49, 0x02, /* vact_st2 */
  258. 0x01, 0x00, 0x33, 0x02, /* vsync top/bot */
  259. 0x01, 0x00, 0x33, 0x02, /* field top/bot */
  260. },
  261. };
  262. static const struct hdmi_v13_preset_conf hdmi_v13_conf_1080p50 = {
  263. .core = {
  264. .h_blank = {0xd0, 0x02},
  265. .v_blank = {0x65, 0x6c, 0x01},
  266. .h_v_line = {0x65, 0x04, 0xa5},
  267. .vsync_pol = {0x00},
  268. .int_pro_mode = {0x00},
  269. .v_blank_f = {0x00, 0x00, 0x00}, /* don't care */
  270. .h_sync_gen = {0x0e, 0xea, 0x08},
  271. .v_sync_gen1 = {0x09, 0x40, 0x00},
  272. .v_sync_gen2 = {0x01, 0x10, 0x00},
  273. .v_sync_gen3 = {0x01, 0x10, 0x00},
  274. /* other don't care */
  275. },
  276. .tg = {
  277. 0x00, /* cmd */
  278. 0x50, 0x0A, /* h_fsz */
  279. 0xCF, 0x02, 0x81, 0x07, /* hact */
  280. 0x65, 0x04, /* v_fsz */
  281. 0x01, 0x00, 0x33, 0x02, /* vsync */
  282. 0x2d, 0x00, 0x38, 0x04, /* vact */
  283. 0x33, 0x02, /* field_chg */
  284. 0x48, 0x02, /* vact_st2 */
  285. 0x01, 0x00, 0x01, 0x00, /* vsync top/bot */
  286. 0x01, 0x00, 0x33, 0x02, /* field top/bot */
  287. },
  288. };
  289. static const struct hdmi_v13_preset_conf hdmi_v13_conf_1080i60 = {
  290. .core = {
  291. .h_blank = {0x18, 0x01},
  292. .v_blank = {0x32, 0xB2, 0x00},
  293. .h_v_line = {0x65, 0x84, 0x89},
  294. .vsync_pol = {0x00},
  295. .int_pro_mode = {0x01},
  296. .v_blank_f = {0x49, 0x2A, 0x23},
  297. .h_sync_gen = {0x56, 0x08, 0x02},
  298. .v_sync_gen1 = {0x07, 0x20, 0x00},
  299. .v_sync_gen2 = {0x39, 0x42, 0x23},
  300. .v_sync_gen3 = {0xa4, 0x44, 0x4a},
  301. /* other don't care */
  302. },
  303. .tg = {
  304. 0x00, /* cmd */
  305. 0x98, 0x08, /* h_fsz */
  306. 0x17, 0x01, 0x81, 0x07, /* hact */
  307. 0x65, 0x04, /* v_fsz */
  308. 0x01, 0x00, 0x33, 0x02, /* vsync */
  309. 0x16, 0x00, 0x1c, 0x02, /* vact */
  310. 0x33, 0x02, /* field_chg */
  311. 0x49, 0x02, /* vact_st2 */
  312. 0x01, 0x00, 0x33, 0x02, /* vsync top/bot */
  313. 0x01, 0x00, 0x33, 0x02, /* field top/bot */
  314. },
  315. };
  316. static const struct hdmi_v13_preset_conf hdmi_v13_conf_1080p60 = {
  317. .core = {
  318. .h_blank = {0x18, 0x01},
  319. .v_blank = {0x65, 0x6c, 0x01},
  320. .h_v_line = {0x65, 0x84, 0x89},
  321. .vsync_pol = {0x00},
  322. .int_pro_mode = {0x00},
  323. .v_blank_f = {0x00, 0x00, 0x00}, /* don't care */
  324. .h_sync_gen = {0x56, 0x08, 0x02},
  325. .v_sync_gen1 = {0x09, 0x40, 0x00},
  326. .v_sync_gen2 = {0x01, 0x10, 0x00},
  327. .v_sync_gen3 = {0x01, 0x10, 0x00},
  328. /* other don't care */
  329. },
  330. .tg = {
  331. 0x00, /* cmd */
  332. 0x98, 0x08, /* h_fsz */
  333. 0x17, 0x01, 0x81, 0x07, /* hact */
  334. 0x65, 0x04, /* v_fsz */
  335. 0x01, 0x00, 0x33, 0x02, /* vsync */
  336. 0x2d, 0x00, 0x38, 0x04, /* vact */
  337. 0x33, 0x02, /* field_chg */
  338. 0x48, 0x02, /* vact_st2 */
  339. 0x01, 0x00, 0x01, 0x00, /* vsync top/bot */
  340. 0x01, 0x00, 0x33, 0x02, /* field top/bot */
  341. },
  342. };
  343. static const struct hdmi_v13_conf hdmi_v13_confs[] = {
  344. { 1280, 720, 60, false, 4, hdmiphy_v13_conf74_25,
  345. &hdmi_v13_conf_720p60 },
  346. { 1280, 720, 50, false, 19, hdmiphy_v13_conf74_25,
  347. &hdmi_v13_conf_720p60 },
  348. { 720, 480, 60, false, 3, hdmiphy_v13_conf27_027,
  349. &hdmi_v13_conf_480p },
  350. { 1920, 1080, 50, true, 20, hdmiphy_v13_conf74_25,
  351. &hdmi_v13_conf_1080i50 },
  352. { 1920, 1080, 50, false, 31, hdmiphy_v13_conf148_5,
  353. &hdmi_v13_conf_1080p50 },
  354. { 1920, 1080, 60, true, 5, hdmiphy_v13_conf74_25,
  355. &hdmi_v13_conf_1080i60 },
  356. { 1920, 1080, 60, false, 16, hdmiphy_v13_conf148_5,
  357. &hdmi_v13_conf_1080p60 },
  358. };
  359. /* HDMI Version 1.4 */
  360. static const u8 hdmiphy_conf27_027[32] = {
  361. 0x01, 0xd1, 0x2d, 0x72, 0x40, 0x64, 0x12, 0x08,
  362. 0x43, 0xa0, 0x0e, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  363. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  364. 0x54, 0xe3, 0x24, 0x00, 0x00, 0x00, 0x01, 0x00,
  365. };
  366. static const u8 hdmiphy_conf74_176[32] = {
  367. 0x01, 0xd1, 0x1f, 0x10, 0x40, 0x5b, 0xef, 0x08,
  368. 0x81, 0xa0, 0xb9, 0xd8, 0x45, 0xa0, 0xac, 0x80,
  369. 0x5a, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  370. 0x54, 0xa6, 0x24, 0x01, 0x00, 0x00, 0x01, 0x00,
  371. };
  372. static const u8 hdmiphy_conf74_25[32] = {
  373. 0x01, 0xd1, 0x1f, 0x10, 0x40, 0x40, 0xf8, 0x08,
  374. 0x81, 0xa0, 0xba, 0xd8, 0x45, 0xa0, 0xac, 0x80,
  375. 0x3c, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  376. 0x54, 0xa5, 0x24, 0x01, 0x00, 0x00, 0x01, 0x00,
  377. };
  378. static const u8 hdmiphy_conf148_5[32] = {
  379. 0x01, 0xd1, 0x1f, 0x00, 0x40, 0x40, 0xf8, 0x08,
  380. 0x81, 0xa0, 0xba, 0xd8, 0x45, 0xa0, 0xac, 0x80,
  381. 0x3c, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  382. 0x54, 0x4b, 0x25, 0x03, 0x00, 0x00, 0x01, 0x00,
  383. };
  384. struct hdmi_tg_regs {
  385. u8 cmd;
  386. u8 h_fsz_l;
  387. u8 h_fsz_h;
  388. u8 hact_st_l;
  389. u8 hact_st_h;
  390. u8 hact_sz_l;
  391. u8 hact_sz_h;
  392. u8 v_fsz_l;
  393. u8 v_fsz_h;
  394. u8 vsync_l;
  395. u8 vsync_h;
  396. u8 vsync2_l;
  397. u8 vsync2_h;
  398. u8 vact_st_l;
  399. u8 vact_st_h;
  400. u8 vact_sz_l;
  401. u8 vact_sz_h;
  402. u8 field_chg_l;
  403. u8 field_chg_h;
  404. u8 vact_st2_l;
  405. u8 vact_st2_h;
  406. u8 vact_st3_l;
  407. u8 vact_st3_h;
  408. u8 vact_st4_l;
  409. u8 vact_st4_h;
  410. u8 vsync_top_hdmi_l;
  411. u8 vsync_top_hdmi_h;
  412. u8 vsync_bot_hdmi_l;
  413. u8 vsync_bot_hdmi_h;
  414. u8 field_top_hdmi_l;
  415. u8 field_top_hdmi_h;
  416. u8 field_bot_hdmi_l;
  417. u8 field_bot_hdmi_h;
  418. u8 tg_3d;
  419. };
  420. struct hdmi_core_regs {
  421. u8 h_blank[2];
  422. u8 v2_blank[2];
  423. u8 v1_blank[2];
  424. u8 v_line[2];
  425. u8 h_line[2];
  426. u8 hsync_pol[1];
  427. u8 vsync_pol[1];
  428. u8 int_pro_mode[1];
  429. u8 v_blank_f0[2];
  430. u8 v_blank_f1[2];
  431. u8 h_sync_start[2];
  432. u8 h_sync_end[2];
  433. u8 v_sync_line_bef_2[2];
  434. u8 v_sync_line_bef_1[2];
  435. u8 v_sync_line_aft_2[2];
  436. u8 v_sync_line_aft_1[2];
  437. u8 v_sync_line_aft_pxl_2[2];
  438. u8 v_sync_line_aft_pxl_1[2];
  439. u8 v_blank_f2[2]; /* for 3D mode */
  440. u8 v_blank_f3[2]; /* for 3D mode */
  441. u8 v_blank_f4[2]; /* for 3D mode */
  442. u8 v_blank_f5[2]; /* for 3D mode */
  443. u8 v_sync_line_aft_3[2];
  444. u8 v_sync_line_aft_4[2];
  445. u8 v_sync_line_aft_5[2];
  446. u8 v_sync_line_aft_6[2];
  447. u8 v_sync_line_aft_pxl_3[2];
  448. u8 v_sync_line_aft_pxl_4[2];
  449. u8 v_sync_line_aft_pxl_5[2];
  450. u8 v_sync_line_aft_pxl_6[2];
  451. u8 vact_space_1[2];
  452. u8 vact_space_2[2];
  453. u8 vact_space_3[2];
  454. u8 vact_space_4[2];
  455. u8 vact_space_5[2];
  456. u8 vact_space_6[2];
  457. };
  458. struct hdmi_preset_conf {
  459. struct hdmi_core_regs core;
  460. struct hdmi_tg_regs tg;
  461. };
  462. struct hdmi_conf {
  463. int width;
  464. int height;
  465. int vrefresh;
  466. bool interlace;
  467. int cea_video_id;
  468. const u8 *hdmiphy_data;
  469. const struct hdmi_preset_conf *conf;
  470. };
  471. static const struct hdmi_preset_conf hdmi_conf_480p60 = {
  472. .core = {
  473. .h_blank = {0x8a, 0x00},
  474. .v2_blank = {0x0d, 0x02},
  475. .v1_blank = {0x2d, 0x00},
  476. .v_line = {0x0d, 0x02},
  477. .h_line = {0x5a, 0x03},
  478. .hsync_pol = {0x01},
  479. .vsync_pol = {0x01},
  480. .int_pro_mode = {0x00},
  481. .v_blank_f0 = {0xff, 0xff},
  482. .v_blank_f1 = {0xff, 0xff},
  483. .h_sync_start = {0x0e, 0x00},
  484. .h_sync_end = {0x4c, 0x00},
  485. .v_sync_line_bef_2 = {0x0f, 0x00},
  486. .v_sync_line_bef_1 = {0x09, 0x00},
  487. .v_sync_line_aft_2 = {0xff, 0xff},
  488. .v_sync_line_aft_1 = {0xff, 0xff},
  489. .v_sync_line_aft_pxl_2 = {0xff, 0xff},
  490. .v_sync_line_aft_pxl_1 = {0xff, 0xff},
  491. .v_blank_f2 = {0xff, 0xff},
  492. .v_blank_f3 = {0xff, 0xff},
  493. .v_blank_f4 = {0xff, 0xff},
  494. .v_blank_f5 = {0xff, 0xff},
  495. .v_sync_line_aft_3 = {0xff, 0xff},
  496. .v_sync_line_aft_4 = {0xff, 0xff},
  497. .v_sync_line_aft_5 = {0xff, 0xff},
  498. .v_sync_line_aft_6 = {0xff, 0xff},
  499. .v_sync_line_aft_pxl_3 = {0xff, 0xff},
  500. .v_sync_line_aft_pxl_4 = {0xff, 0xff},
  501. .v_sync_line_aft_pxl_5 = {0xff, 0xff},
  502. .v_sync_line_aft_pxl_6 = {0xff, 0xff},
  503. .vact_space_1 = {0xff, 0xff},
  504. .vact_space_2 = {0xff, 0xff},
  505. .vact_space_3 = {0xff, 0xff},
  506. .vact_space_4 = {0xff, 0xff},
  507. .vact_space_5 = {0xff, 0xff},
  508. .vact_space_6 = {0xff, 0xff},
  509. /* other don't care */
  510. },
  511. .tg = {
  512. 0x00, /* cmd */
  513. 0x5a, 0x03, /* h_fsz */
  514. 0x8a, 0x00, 0xd0, 0x02, /* hact */
  515. 0x0d, 0x02, /* v_fsz */
  516. 0x01, 0x00, 0x33, 0x02, /* vsync */
  517. 0x2d, 0x00, 0xe0, 0x01, /* vact */
  518. 0x33, 0x02, /* field_chg */
  519. 0x48, 0x02, /* vact_st2 */
  520. 0x00, 0x00, /* vact_st3 */
  521. 0x00, 0x00, /* vact_st4 */
  522. 0x01, 0x00, 0x01, 0x00, /* vsync top/bot */
  523. 0x01, 0x00, 0x33, 0x02, /* field top/bot */
  524. 0x00, /* 3d FP */
  525. },
  526. };
  527. static const struct hdmi_preset_conf hdmi_conf_720p50 = {
  528. .core = {
  529. .h_blank = {0xbc, 0x02},
  530. .v2_blank = {0xee, 0x02},
  531. .v1_blank = {0x1e, 0x00},
  532. .v_line = {0xee, 0x02},
  533. .h_line = {0xbc, 0x07},
  534. .hsync_pol = {0x00},
  535. .vsync_pol = {0x00},
  536. .int_pro_mode = {0x00},
  537. .v_blank_f0 = {0xff, 0xff},
  538. .v_blank_f1 = {0xff, 0xff},
  539. .h_sync_start = {0xb6, 0x01},
  540. .h_sync_end = {0xde, 0x01},
  541. .v_sync_line_bef_2 = {0x0a, 0x00},
  542. .v_sync_line_bef_1 = {0x05, 0x00},
  543. .v_sync_line_aft_2 = {0xff, 0xff},
  544. .v_sync_line_aft_1 = {0xff, 0xff},
  545. .v_sync_line_aft_pxl_2 = {0xff, 0xff},
  546. .v_sync_line_aft_pxl_1 = {0xff, 0xff},
  547. .v_blank_f2 = {0xff, 0xff},
  548. .v_blank_f3 = {0xff, 0xff},
  549. .v_blank_f4 = {0xff, 0xff},
  550. .v_blank_f5 = {0xff, 0xff},
  551. .v_sync_line_aft_3 = {0xff, 0xff},
  552. .v_sync_line_aft_4 = {0xff, 0xff},
  553. .v_sync_line_aft_5 = {0xff, 0xff},
  554. .v_sync_line_aft_6 = {0xff, 0xff},
  555. .v_sync_line_aft_pxl_3 = {0xff, 0xff},
  556. .v_sync_line_aft_pxl_4 = {0xff, 0xff},
  557. .v_sync_line_aft_pxl_5 = {0xff, 0xff},
  558. .v_sync_line_aft_pxl_6 = {0xff, 0xff},
  559. .vact_space_1 = {0xff, 0xff},
  560. .vact_space_2 = {0xff, 0xff},
  561. .vact_space_3 = {0xff, 0xff},
  562. .vact_space_4 = {0xff, 0xff},
  563. .vact_space_5 = {0xff, 0xff},
  564. .vact_space_6 = {0xff, 0xff},
  565. /* other don't care */
  566. },
  567. .tg = {
  568. 0x00, /* cmd */
  569. 0xbc, 0x07, /* h_fsz */
  570. 0xbc, 0x02, 0x00, 0x05, /* hact */
  571. 0xee, 0x02, /* v_fsz */
  572. 0x01, 0x00, 0x33, 0x02, /* vsync */
  573. 0x1e, 0x00, 0xd0, 0x02, /* vact */
  574. 0x33, 0x02, /* field_chg */
  575. 0x48, 0x02, /* vact_st2 */
  576. 0x00, 0x00, /* vact_st3 */
  577. 0x00, 0x00, /* vact_st4 */
  578. 0x01, 0x00, 0x01, 0x00, /* vsync top/bot */
  579. 0x01, 0x00, 0x33, 0x02, /* field top/bot */
  580. 0x00, /* 3d FP */
  581. },
  582. };
  583. static const struct hdmi_preset_conf hdmi_conf_720p60 = {
  584. .core = {
  585. .h_blank = {0x72, 0x01},
  586. .v2_blank = {0xee, 0x02},
  587. .v1_blank = {0x1e, 0x00},
  588. .v_line = {0xee, 0x02},
  589. .h_line = {0x72, 0x06},
  590. .hsync_pol = {0x00},
  591. .vsync_pol = {0x00},
  592. .int_pro_mode = {0x00},
  593. .v_blank_f0 = {0xff, 0xff},
  594. .v_blank_f1 = {0xff, 0xff},
  595. .h_sync_start = {0x6c, 0x00},
  596. .h_sync_end = {0x94, 0x00},
  597. .v_sync_line_bef_2 = {0x0a, 0x00},
  598. .v_sync_line_bef_1 = {0x05, 0x00},
  599. .v_sync_line_aft_2 = {0xff, 0xff},
  600. .v_sync_line_aft_1 = {0xff, 0xff},
  601. .v_sync_line_aft_pxl_2 = {0xff, 0xff},
  602. .v_sync_line_aft_pxl_1 = {0xff, 0xff},
  603. .v_blank_f2 = {0xff, 0xff},
  604. .v_blank_f3 = {0xff, 0xff},
  605. .v_blank_f4 = {0xff, 0xff},
  606. .v_blank_f5 = {0xff, 0xff},
  607. .v_sync_line_aft_3 = {0xff, 0xff},
  608. .v_sync_line_aft_4 = {0xff, 0xff},
  609. .v_sync_line_aft_5 = {0xff, 0xff},
  610. .v_sync_line_aft_6 = {0xff, 0xff},
  611. .v_sync_line_aft_pxl_3 = {0xff, 0xff},
  612. .v_sync_line_aft_pxl_4 = {0xff, 0xff},
  613. .v_sync_line_aft_pxl_5 = {0xff, 0xff},
  614. .v_sync_line_aft_pxl_6 = {0xff, 0xff},
  615. .vact_space_1 = {0xff, 0xff},
  616. .vact_space_2 = {0xff, 0xff},
  617. .vact_space_3 = {0xff, 0xff},
  618. .vact_space_4 = {0xff, 0xff},
  619. .vact_space_5 = {0xff, 0xff},
  620. .vact_space_6 = {0xff, 0xff},
  621. /* other don't care */
  622. },
  623. .tg = {
  624. 0x00, /* cmd */
  625. 0x72, 0x06, /* h_fsz */
  626. 0x72, 0x01, 0x00, 0x05, /* hact */
  627. 0xee, 0x02, /* v_fsz */
  628. 0x01, 0x00, 0x33, 0x02, /* vsync */
  629. 0x1e, 0x00, 0xd0, 0x02, /* vact */
  630. 0x33, 0x02, /* field_chg */
  631. 0x48, 0x02, /* vact_st2 */
  632. 0x00, 0x00, /* vact_st3 */
  633. 0x00, 0x00, /* vact_st4 */
  634. 0x01, 0x00, 0x01, 0x00, /* vsync top/bot */
  635. 0x01, 0x00, 0x33, 0x02, /* field top/bot */
  636. 0x00, /* 3d FP */
  637. },
  638. };
  639. static const struct hdmi_preset_conf hdmi_conf_1080i50 = {
  640. .core = {
  641. .h_blank = {0xd0, 0x02},
  642. .v2_blank = {0x32, 0x02},
  643. .v1_blank = {0x16, 0x00},
  644. .v_line = {0x65, 0x04},
  645. .h_line = {0x50, 0x0a},
  646. .hsync_pol = {0x00},
  647. .vsync_pol = {0x00},
  648. .int_pro_mode = {0x01},
  649. .v_blank_f0 = {0x49, 0x02},
  650. .v_blank_f1 = {0x65, 0x04},
  651. .h_sync_start = {0x0e, 0x02},
  652. .h_sync_end = {0x3a, 0x02},
  653. .v_sync_line_bef_2 = {0x07, 0x00},
  654. .v_sync_line_bef_1 = {0x02, 0x00},
  655. .v_sync_line_aft_2 = {0x39, 0x02},
  656. .v_sync_line_aft_1 = {0x34, 0x02},
  657. .v_sync_line_aft_pxl_2 = {0x38, 0x07},
  658. .v_sync_line_aft_pxl_1 = {0x38, 0x07},
  659. .v_blank_f2 = {0xff, 0xff},
  660. .v_blank_f3 = {0xff, 0xff},
  661. .v_blank_f4 = {0xff, 0xff},
  662. .v_blank_f5 = {0xff, 0xff},
  663. .v_sync_line_aft_3 = {0xff, 0xff},
  664. .v_sync_line_aft_4 = {0xff, 0xff},
  665. .v_sync_line_aft_5 = {0xff, 0xff},
  666. .v_sync_line_aft_6 = {0xff, 0xff},
  667. .v_sync_line_aft_pxl_3 = {0xff, 0xff},
  668. .v_sync_line_aft_pxl_4 = {0xff, 0xff},
  669. .v_sync_line_aft_pxl_5 = {0xff, 0xff},
  670. .v_sync_line_aft_pxl_6 = {0xff, 0xff},
  671. .vact_space_1 = {0xff, 0xff},
  672. .vact_space_2 = {0xff, 0xff},
  673. .vact_space_3 = {0xff, 0xff},
  674. .vact_space_4 = {0xff, 0xff},
  675. .vact_space_5 = {0xff, 0xff},
  676. .vact_space_6 = {0xff, 0xff},
  677. /* other don't care */
  678. },
  679. .tg = {
  680. 0x00, /* cmd */
  681. 0x50, 0x0a, /* h_fsz */
  682. 0xd0, 0x02, 0x80, 0x07, /* hact */
  683. 0x65, 0x04, /* v_fsz */
  684. 0x01, 0x00, 0x33, 0x02, /* vsync */
  685. 0x16, 0x00, 0x1c, 0x02, /* vact */
  686. 0x33, 0x02, /* field_chg */
  687. 0x49, 0x02, /* vact_st2 */
  688. 0x00, 0x00, /* vact_st3 */
  689. 0x00, 0x00, /* vact_st4 */
  690. 0x01, 0x00, 0x33, 0x02, /* vsync top/bot */
  691. 0x01, 0x00, 0x33, 0x02, /* field top/bot */
  692. 0x00, /* 3d FP */
  693. },
  694. };
  695. static const struct hdmi_preset_conf hdmi_conf_1080i60 = {
  696. .core = {
  697. .h_blank = {0x18, 0x01},
  698. .v2_blank = {0x32, 0x02},
  699. .v1_blank = {0x16, 0x00},
  700. .v_line = {0x65, 0x04},
  701. .h_line = {0x98, 0x08},
  702. .hsync_pol = {0x00},
  703. .vsync_pol = {0x00},
  704. .int_pro_mode = {0x01},
  705. .v_blank_f0 = {0x49, 0x02},
  706. .v_blank_f1 = {0x65, 0x04},
  707. .h_sync_start = {0x56, 0x00},
  708. .h_sync_end = {0x82, 0x00},
  709. .v_sync_line_bef_2 = {0x07, 0x00},
  710. .v_sync_line_bef_1 = {0x02, 0x00},
  711. .v_sync_line_aft_2 = {0x39, 0x02},
  712. .v_sync_line_aft_1 = {0x34, 0x02},
  713. .v_sync_line_aft_pxl_2 = {0xa4, 0x04},
  714. .v_sync_line_aft_pxl_1 = {0xa4, 0x04},
  715. .v_blank_f2 = {0xff, 0xff},
  716. .v_blank_f3 = {0xff, 0xff},
  717. .v_blank_f4 = {0xff, 0xff},
  718. .v_blank_f5 = {0xff, 0xff},
  719. .v_sync_line_aft_3 = {0xff, 0xff},
  720. .v_sync_line_aft_4 = {0xff, 0xff},
  721. .v_sync_line_aft_5 = {0xff, 0xff},
  722. .v_sync_line_aft_6 = {0xff, 0xff},
  723. .v_sync_line_aft_pxl_3 = {0xff, 0xff},
  724. .v_sync_line_aft_pxl_4 = {0xff, 0xff},
  725. .v_sync_line_aft_pxl_5 = {0xff, 0xff},
  726. .v_sync_line_aft_pxl_6 = {0xff, 0xff},
  727. .vact_space_1 = {0xff, 0xff},
  728. .vact_space_2 = {0xff, 0xff},
  729. .vact_space_3 = {0xff, 0xff},
  730. .vact_space_4 = {0xff, 0xff},
  731. .vact_space_5 = {0xff, 0xff},
  732. .vact_space_6 = {0xff, 0xff},
  733. /* other don't care */
  734. },
  735. .tg = {
  736. 0x00, /* cmd */
  737. 0x98, 0x08, /* h_fsz */
  738. 0x18, 0x01, 0x80, 0x07, /* hact */
  739. 0x65, 0x04, /* v_fsz */
  740. 0x01, 0x00, 0x33, 0x02, /* vsync */
  741. 0x16, 0x00, 0x1c, 0x02, /* vact */
  742. 0x33, 0x02, /* field_chg */
  743. 0x49, 0x02, /* vact_st2 */
  744. 0x00, 0x00, /* vact_st3 */
  745. 0x00, 0x00, /* vact_st4 */
  746. 0x01, 0x00, 0x33, 0x02, /* vsync top/bot */
  747. 0x01, 0x00, 0x33, 0x02, /* field top/bot */
  748. 0x00, /* 3d FP */
  749. },
  750. };
  751. static const struct hdmi_preset_conf hdmi_conf_1080p30 = {
  752. .core = {
  753. .h_blank = {0x18, 0x01},
  754. .v2_blank = {0x65, 0x04},
  755. .v1_blank = {0x2d, 0x00},
  756. .v_line = {0x65, 0x04},
  757. .h_line = {0x98, 0x08},
  758. .hsync_pol = {0x00},
  759. .vsync_pol = {0x00},
  760. .int_pro_mode = {0x00},
  761. .v_blank_f0 = {0xff, 0xff},
  762. .v_blank_f1 = {0xff, 0xff},
  763. .h_sync_start = {0x56, 0x00},
  764. .h_sync_end = {0x82, 0x00},
  765. .v_sync_line_bef_2 = {0x09, 0x00},
  766. .v_sync_line_bef_1 = {0x04, 0x00},
  767. .v_sync_line_aft_2 = {0xff, 0xff},
  768. .v_sync_line_aft_1 = {0xff, 0xff},
  769. .v_sync_line_aft_pxl_2 = {0xff, 0xff},
  770. .v_sync_line_aft_pxl_1 = {0xff, 0xff},
  771. .v_blank_f2 = {0xff, 0xff},
  772. .v_blank_f3 = {0xff, 0xff},
  773. .v_blank_f4 = {0xff, 0xff},
  774. .v_blank_f5 = {0xff, 0xff},
  775. .v_sync_line_aft_3 = {0xff, 0xff},
  776. .v_sync_line_aft_4 = {0xff, 0xff},
  777. .v_sync_line_aft_5 = {0xff, 0xff},
  778. .v_sync_line_aft_6 = {0xff, 0xff},
  779. .v_sync_line_aft_pxl_3 = {0xff, 0xff},
  780. .v_sync_line_aft_pxl_4 = {0xff, 0xff},
  781. .v_sync_line_aft_pxl_5 = {0xff, 0xff},
  782. .v_sync_line_aft_pxl_6 = {0xff, 0xff},
  783. .vact_space_1 = {0xff, 0xff},
  784. .vact_space_2 = {0xff, 0xff},
  785. .vact_space_3 = {0xff, 0xff},
  786. .vact_space_4 = {0xff, 0xff},
  787. .vact_space_5 = {0xff, 0xff},
  788. .vact_space_6 = {0xff, 0xff},
  789. /* other don't care */
  790. },
  791. .tg = {
  792. 0x00, /* cmd */
  793. 0x98, 0x08, /* h_fsz */
  794. 0x18, 0x01, 0x80, 0x07, /* hact */
  795. 0x65, 0x04, /* v_fsz */
  796. 0x01, 0x00, 0x33, 0x02, /* vsync */
  797. 0x2d, 0x00, 0x38, 0x04, /* vact */
  798. 0x33, 0x02, /* field_chg */
  799. 0x48, 0x02, /* vact_st2 */
  800. 0x00, 0x00, /* vact_st3 */
  801. 0x00, 0x00, /* vact_st4 */
  802. 0x01, 0x00, 0x01, 0x00, /* vsync top/bot */
  803. 0x01, 0x00, 0x33, 0x02, /* field top/bot */
  804. 0x00, /* 3d FP */
  805. },
  806. };
  807. static const struct hdmi_preset_conf hdmi_conf_1080p50 = {
  808. .core = {
  809. .h_blank = {0xd0, 0x02},
  810. .v2_blank = {0x65, 0x04},
  811. .v1_blank = {0x2d, 0x00},
  812. .v_line = {0x65, 0x04},
  813. .h_line = {0x50, 0x0a},
  814. .hsync_pol = {0x00},
  815. .vsync_pol = {0x00},
  816. .int_pro_mode = {0x00},
  817. .v_blank_f0 = {0xff, 0xff},
  818. .v_blank_f1 = {0xff, 0xff},
  819. .h_sync_start = {0x0e, 0x02},
  820. .h_sync_end = {0x3a, 0x02},
  821. .v_sync_line_bef_2 = {0x09, 0x00},
  822. .v_sync_line_bef_1 = {0x04, 0x00},
  823. .v_sync_line_aft_2 = {0xff, 0xff},
  824. .v_sync_line_aft_1 = {0xff, 0xff},
  825. .v_sync_line_aft_pxl_2 = {0xff, 0xff},
  826. .v_sync_line_aft_pxl_1 = {0xff, 0xff},
  827. .v_blank_f2 = {0xff, 0xff},
  828. .v_blank_f3 = {0xff, 0xff},
  829. .v_blank_f4 = {0xff, 0xff},
  830. .v_blank_f5 = {0xff, 0xff},
  831. .v_sync_line_aft_3 = {0xff, 0xff},
  832. .v_sync_line_aft_4 = {0xff, 0xff},
  833. .v_sync_line_aft_5 = {0xff, 0xff},
  834. .v_sync_line_aft_6 = {0xff, 0xff},
  835. .v_sync_line_aft_pxl_3 = {0xff, 0xff},
  836. .v_sync_line_aft_pxl_4 = {0xff, 0xff},
  837. .v_sync_line_aft_pxl_5 = {0xff, 0xff},
  838. .v_sync_line_aft_pxl_6 = {0xff, 0xff},
  839. .vact_space_1 = {0xff, 0xff},
  840. .vact_space_2 = {0xff, 0xff},
  841. .vact_space_3 = {0xff, 0xff},
  842. .vact_space_4 = {0xff, 0xff},
  843. .vact_space_5 = {0xff, 0xff},
  844. .vact_space_6 = {0xff, 0xff},
  845. /* other don't care */
  846. },
  847. .tg = {
  848. 0x00, /* cmd */
  849. 0x50, 0x0a, /* h_fsz */
  850. 0xd0, 0x02, 0x80, 0x07, /* hact */
  851. 0x65, 0x04, /* v_fsz */
  852. 0x01, 0x00, 0x33, 0x02, /* vsync */
  853. 0x2d, 0x00, 0x38, 0x04, /* vact */
  854. 0x33, 0x02, /* field_chg */
  855. 0x48, 0x02, /* vact_st2 */
  856. 0x00, 0x00, /* vact_st3 */
  857. 0x00, 0x00, /* vact_st4 */
  858. 0x01, 0x00, 0x01, 0x00, /* vsync top/bot */
  859. 0x01, 0x00, 0x33, 0x02, /* field top/bot */
  860. 0x00, /* 3d FP */
  861. },
  862. };
  863. static const struct hdmi_preset_conf hdmi_conf_1080p60 = {
  864. .core = {
  865. .h_blank = {0x18, 0x01},
  866. .v2_blank = {0x65, 0x04},
  867. .v1_blank = {0x2d, 0x00},
  868. .v_line = {0x65, 0x04},
  869. .h_line = {0x98, 0x08},
  870. .hsync_pol = {0x00},
  871. .vsync_pol = {0x00},
  872. .int_pro_mode = {0x00},
  873. .v_blank_f0 = {0xff, 0xff},
  874. .v_blank_f1 = {0xff, 0xff},
  875. .h_sync_start = {0x56, 0x00},
  876. .h_sync_end = {0x82, 0x00},
  877. .v_sync_line_bef_2 = {0x09, 0x00},
  878. .v_sync_line_bef_1 = {0x04, 0x00},
  879. .v_sync_line_aft_2 = {0xff, 0xff},
  880. .v_sync_line_aft_1 = {0xff, 0xff},
  881. .v_sync_line_aft_pxl_2 = {0xff, 0xff},
  882. .v_sync_line_aft_pxl_1 = {0xff, 0xff},
  883. .v_blank_f2 = {0xff, 0xff},
  884. .v_blank_f3 = {0xff, 0xff},
  885. .v_blank_f4 = {0xff, 0xff},
  886. .v_blank_f5 = {0xff, 0xff},
  887. .v_sync_line_aft_3 = {0xff, 0xff},
  888. .v_sync_line_aft_4 = {0xff, 0xff},
  889. .v_sync_line_aft_5 = {0xff, 0xff},
  890. .v_sync_line_aft_6 = {0xff, 0xff},
  891. .v_sync_line_aft_pxl_3 = {0xff, 0xff},
  892. .v_sync_line_aft_pxl_4 = {0xff, 0xff},
  893. .v_sync_line_aft_pxl_5 = {0xff, 0xff},
  894. .v_sync_line_aft_pxl_6 = {0xff, 0xff},
  895. /* other don't care */
  896. },
  897. .tg = {
  898. 0x00, /* cmd */
  899. 0x98, 0x08, /* h_fsz */
  900. 0x18, 0x01, 0x80, 0x07, /* hact */
  901. 0x65, 0x04, /* v_fsz */
  902. 0x01, 0x00, 0x33, 0x02, /* vsync */
  903. 0x2d, 0x00, 0x38, 0x04, /* vact */
  904. 0x33, 0x02, /* field_chg */
  905. 0x48, 0x02, /* vact_st2 */
  906. 0x00, 0x00, /* vact_st3 */
  907. 0x00, 0x00, /* vact_st4 */
  908. 0x01, 0x00, 0x01, 0x00, /* vsync top/bot */
  909. 0x01, 0x00, 0x33, 0x02, /* field top/bot */
  910. 0x00, /* 3d FP */
  911. },
  912. };
  913. static const struct hdmi_conf hdmi_confs[] = {
  914. { 720, 480, 60, false, 3, hdmiphy_conf27_027, &hdmi_conf_480p60 },
  915. { 1280, 720, 50, false, 19, hdmiphy_conf74_25, &hdmi_conf_720p50 },
  916. { 1280, 720, 60, false, 4, hdmiphy_conf74_25, &hdmi_conf_720p60 },
  917. { 1920, 1080, 50, true, 20, hdmiphy_conf74_25, &hdmi_conf_1080i50 },
  918. { 1920, 1080, 60, true, 5, hdmiphy_conf74_25, &hdmi_conf_1080i60 },
  919. { 1920, 1080, 30, false, 34, hdmiphy_conf74_176, &hdmi_conf_1080p30 },
  920. { 1920, 1080, 50, false, 31, hdmiphy_conf148_5, &hdmi_conf_1080p50 },
  921. { 1920, 1080, 60, false, 16, hdmiphy_conf148_5, &hdmi_conf_1080p60 },
  922. };
  923. struct hdmi_infoframe {
  924. enum HDMI_PACKET_TYPE type;
  925. u8 ver;
  926. u8 len;
  927. };
  928. static inline u32 hdmi_reg_read(struct hdmi_context *hdata, u32 reg_id)
  929. {
  930. return readl(hdata->regs + reg_id);
  931. }
  932. static inline void hdmi_reg_writeb(struct hdmi_context *hdata,
  933. u32 reg_id, u8 value)
  934. {
  935. writeb(value, hdata->regs + reg_id);
  936. }
  937. static inline void hdmi_reg_writemask(struct hdmi_context *hdata,
  938. u32 reg_id, u32 value, u32 mask)
  939. {
  940. u32 old = readl(hdata->regs + reg_id);
  941. value = (value & mask) | (old & ~mask);
  942. writel(value, hdata->regs + reg_id);
  943. }
  944. static void hdmi_v13_regs_dump(struct hdmi_context *hdata, char *prefix)
  945. {
  946. #define DUMPREG(reg_id) \
  947. DRM_DEBUG_KMS("%s:" #reg_id " = %08x\n", prefix, \
  948. readl(hdata->regs + reg_id))
  949. DRM_DEBUG_KMS("%s: ---- CONTROL REGISTERS ----\n", prefix);
  950. DUMPREG(HDMI_INTC_FLAG);
  951. DUMPREG(HDMI_INTC_CON);
  952. DUMPREG(HDMI_HPD_STATUS);
  953. DUMPREG(HDMI_V13_PHY_RSTOUT);
  954. DUMPREG(HDMI_V13_PHY_VPLL);
  955. DUMPREG(HDMI_V13_PHY_CMU);
  956. DUMPREG(HDMI_V13_CORE_RSTOUT);
  957. DRM_DEBUG_KMS("%s: ---- CORE REGISTERS ----\n", prefix);
  958. DUMPREG(HDMI_CON_0);
  959. DUMPREG(HDMI_CON_1);
  960. DUMPREG(HDMI_CON_2);
  961. DUMPREG(HDMI_SYS_STATUS);
  962. DUMPREG(HDMI_V13_PHY_STATUS);
  963. DUMPREG(HDMI_STATUS_EN);
  964. DUMPREG(HDMI_HPD);
  965. DUMPREG(HDMI_MODE_SEL);
  966. DUMPREG(HDMI_V13_HPD_GEN);
  967. DUMPREG(HDMI_V13_DC_CONTROL);
  968. DUMPREG(HDMI_V13_VIDEO_PATTERN_GEN);
  969. DRM_DEBUG_KMS("%s: ---- CORE SYNC REGISTERS ----\n", prefix);
  970. DUMPREG(HDMI_H_BLANK_0);
  971. DUMPREG(HDMI_H_BLANK_1);
  972. DUMPREG(HDMI_V13_V_BLANK_0);
  973. DUMPREG(HDMI_V13_V_BLANK_1);
  974. DUMPREG(HDMI_V13_V_BLANK_2);
  975. DUMPREG(HDMI_V13_H_V_LINE_0);
  976. DUMPREG(HDMI_V13_H_V_LINE_1);
  977. DUMPREG(HDMI_V13_H_V_LINE_2);
  978. DUMPREG(HDMI_VSYNC_POL);
  979. DUMPREG(HDMI_INT_PRO_MODE);
  980. DUMPREG(HDMI_V13_V_BLANK_F_0);
  981. DUMPREG(HDMI_V13_V_BLANK_F_1);
  982. DUMPREG(HDMI_V13_V_BLANK_F_2);
  983. DUMPREG(HDMI_V13_H_SYNC_GEN_0);
  984. DUMPREG(HDMI_V13_H_SYNC_GEN_1);
  985. DUMPREG(HDMI_V13_H_SYNC_GEN_2);
  986. DUMPREG(HDMI_V13_V_SYNC_GEN_1_0);
  987. DUMPREG(HDMI_V13_V_SYNC_GEN_1_1);
  988. DUMPREG(HDMI_V13_V_SYNC_GEN_1_2);
  989. DUMPREG(HDMI_V13_V_SYNC_GEN_2_0);
  990. DUMPREG(HDMI_V13_V_SYNC_GEN_2_1);
  991. DUMPREG(HDMI_V13_V_SYNC_GEN_2_2);
  992. DUMPREG(HDMI_V13_V_SYNC_GEN_3_0);
  993. DUMPREG(HDMI_V13_V_SYNC_GEN_3_1);
  994. DUMPREG(HDMI_V13_V_SYNC_GEN_3_2);
  995. DRM_DEBUG_KMS("%s: ---- TG REGISTERS ----\n", prefix);
  996. DUMPREG(HDMI_TG_CMD);
  997. DUMPREG(HDMI_TG_H_FSZ_L);
  998. DUMPREG(HDMI_TG_H_FSZ_H);
  999. DUMPREG(HDMI_TG_HACT_ST_L);
  1000. DUMPREG(HDMI_TG_HACT_ST_H);
  1001. DUMPREG(HDMI_TG_HACT_SZ_L);
  1002. DUMPREG(HDMI_TG_HACT_SZ_H);
  1003. DUMPREG(HDMI_TG_V_FSZ_L);
  1004. DUMPREG(HDMI_TG_V_FSZ_H);
  1005. DUMPREG(HDMI_TG_VSYNC_L);
  1006. DUMPREG(HDMI_TG_VSYNC_H);
  1007. DUMPREG(HDMI_TG_VSYNC2_L);
  1008. DUMPREG(HDMI_TG_VSYNC2_H);
  1009. DUMPREG(HDMI_TG_VACT_ST_L);
  1010. DUMPREG(HDMI_TG_VACT_ST_H);
  1011. DUMPREG(HDMI_TG_VACT_SZ_L);
  1012. DUMPREG(HDMI_TG_VACT_SZ_H);
  1013. DUMPREG(HDMI_TG_FIELD_CHG_L);
  1014. DUMPREG(HDMI_TG_FIELD_CHG_H);
  1015. DUMPREG(HDMI_TG_VACT_ST2_L);
  1016. DUMPREG(HDMI_TG_VACT_ST2_H);
  1017. DUMPREG(HDMI_TG_VSYNC_TOP_HDMI_L);
  1018. DUMPREG(HDMI_TG_VSYNC_TOP_HDMI_H);
  1019. DUMPREG(HDMI_TG_VSYNC_BOT_HDMI_L);
  1020. DUMPREG(HDMI_TG_VSYNC_BOT_HDMI_H);
  1021. DUMPREG(HDMI_TG_FIELD_TOP_HDMI_L);
  1022. DUMPREG(HDMI_TG_FIELD_TOP_HDMI_H);
  1023. DUMPREG(HDMI_TG_FIELD_BOT_HDMI_L);
  1024. DUMPREG(HDMI_TG_FIELD_BOT_HDMI_H);
  1025. #undef DUMPREG
  1026. }
  1027. static void hdmi_v14_regs_dump(struct hdmi_context *hdata, char *prefix)
  1028. {
  1029. int i;
  1030. #define DUMPREG(reg_id) \
  1031. DRM_DEBUG_KMS("%s:" #reg_id " = %08x\n", prefix, \
  1032. readl(hdata->regs + reg_id))
  1033. DRM_DEBUG_KMS("%s: ---- CONTROL REGISTERS ----\n", prefix);
  1034. DUMPREG(HDMI_INTC_CON);
  1035. DUMPREG(HDMI_INTC_FLAG);
  1036. DUMPREG(HDMI_HPD_STATUS);
  1037. DUMPREG(HDMI_INTC_CON_1);
  1038. DUMPREG(HDMI_INTC_FLAG_1);
  1039. DUMPREG(HDMI_PHY_STATUS_0);
  1040. DUMPREG(HDMI_PHY_STATUS_PLL);
  1041. DUMPREG(HDMI_PHY_CON_0);
  1042. DUMPREG(HDMI_PHY_RSTOUT);
  1043. DUMPREG(HDMI_PHY_VPLL);
  1044. DUMPREG(HDMI_PHY_CMU);
  1045. DUMPREG(HDMI_CORE_RSTOUT);
  1046. DRM_DEBUG_KMS("%s: ---- CORE REGISTERS ----\n", prefix);
  1047. DUMPREG(HDMI_CON_0);
  1048. DUMPREG(HDMI_CON_1);
  1049. DUMPREG(HDMI_CON_2);
  1050. DUMPREG(HDMI_SYS_STATUS);
  1051. DUMPREG(HDMI_PHY_STATUS_0);
  1052. DUMPREG(HDMI_STATUS_EN);
  1053. DUMPREG(HDMI_HPD);
  1054. DUMPREG(HDMI_MODE_SEL);
  1055. DUMPREG(HDMI_ENC_EN);
  1056. DUMPREG(HDMI_DC_CONTROL);
  1057. DUMPREG(HDMI_VIDEO_PATTERN_GEN);
  1058. DRM_DEBUG_KMS("%s: ---- CORE SYNC REGISTERS ----\n", prefix);
  1059. DUMPREG(HDMI_H_BLANK_0);
  1060. DUMPREG(HDMI_H_BLANK_1);
  1061. DUMPREG(HDMI_V2_BLANK_0);
  1062. DUMPREG(HDMI_V2_BLANK_1);
  1063. DUMPREG(HDMI_V1_BLANK_0);
  1064. DUMPREG(HDMI_V1_BLANK_1);
  1065. DUMPREG(HDMI_V_LINE_0);
  1066. DUMPREG(HDMI_V_LINE_1);
  1067. DUMPREG(HDMI_H_LINE_0);
  1068. DUMPREG(HDMI_H_LINE_1);
  1069. DUMPREG(HDMI_HSYNC_POL);
  1070. DUMPREG(HDMI_VSYNC_POL);
  1071. DUMPREG(HDMI_INT_PRO_MODE);
  1072. DUMPREG(HDMI_V_BLANK_F0_0);
  1073. DUMPREG(HDMI_V_BLANK_F0_1);
  1074. DUMPREG(HDMI_V_BLANK_F1_0);
  1075. DUMPREG(HDMI_V_BLANK_F1_1);
  1076. DUMPREG(HDMI_H_SYNC_START_0);
  1077. DUMPREG(HDMI_H_SYNC_START_1);
  1078. DUMPREG(HDMI_H_SYNC_END_0);
  1079. DUMPREG(HDMI_H_SYNC_END_1);
  1080. DUMPREG(HDMI_V_SYNC_LINE_BEF_2_0);
  1081. DUMPREG(HDMI_V_SYNC_LINE_BEF_2_1);
  1082. DUMPREG(HDMI_V_SYNC_LINE_BEF_1_0);
  1083. DUMPREG(HDMI_V_SYNC_LINE_BEF_1_1);
  1084. DUMPREG(HDMI_V_SYNC_LINE_AFT_2_0);
  1085. DUMPREG(HDMI_V_SYNC_LINE_AFT_2_1);
  1086. DUMPREG(HDMI_V_SYNC_LINE_AFT_1_0);
  1087. DUMPREG(HDMI_V_SYNC_LINE_AFT_1_1);
  1088. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_2_0);
  1089. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_2_1);
  1090. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_1_0);
  1091. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_1_1);
  1092. DUMPREG(HDMI_V_BLANK_F2_0);
  1093. DUMPREG(HDMI_V_BLANK_F2_1);
  1094. DUMPREG(HDMI_V_BLANK_F3_0);
  1095. DUMPREG(HDMI_V_BLANK_F3_1);
  1096. DUMPREG(HDMI_V_BLANK_F4_0);
  1097. DUMPREG(HDMI_V_BLANK_F4_1);
  1098. DUMPREG(HDMI_V_BLANK_F5_0);
  1099. DUMPREG(HDMI_V_BLANK_F5_1);
  1100. DUMPREG(HDMI_V_SYNC_LINE_AFT_3_0);
  1101. DUMPREG(HDMI_V_SYNC_LINE_AFT_3_1);
  1102. DUMPREG(HDMI_V_SYNC_LINE_AFT_4_0);
  1103. DUMPREG(HDMI_V_SYNC_LINE_AFT_4_1);
  1104. DUMPREG(HDMI_V_SYNC_LINE_AFT_5_0);
  1105. DUMPREG(HDMI_V_SYNC_LINE_AFT_5_1);
  1106. DUMPREG(HDMI_V_SYNC_LINE_AFT_6_0);
  1107. DUMPREG(HDMI_V_SYNC_LINE_AFT_6_1);
  1108. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_3_0);
  1109. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_3_1);
  1110. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_4_0);
  1111. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_4_1);
  1112. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_5_0);
  1113. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_5_1);
  1114. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_6_0);
  1115. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_6_1);
  1116. DUMPREG(HDMI_VACT_SPACE_1_0);
  1117. DUMPREG(HDMI_VACT_SPACE_1_1);
  1118. DUMPREG(HDMI_VACT_SPACE_2_0);
  1119. DUMPREG(HDMI_VACT_SPACE_2_1);
  1120. DUMPREG(HDMI_VACT_SPACE_3_0);
  1121. DUMPREG(HDMI_VACT_SPACE_3_1);
  1122. DUMPREG(HDMI_VACT_SPACE_4_0);
  1123. DUMPREG(HDMI_VACT_SPACE_4_1);
  1124. DUMPREG(HDMI_VACT_SPACE_5_0);
  1125. DUMPREG(HDMI_VACT_SPACE_5_1);
  1126. DUMPREG(HDMI_VACT_SPACE_6_0);
  1127. DUMPREG(HDMI_VACT_SPACE_6_1);
  1128. DRM_DEBUG_KMS("%s: ---- TG REGISTERS ----\n", prefix);
  1129. DUMPREG(HDMI_TG_CMD);
  1130. DUMPREG(HDMI_TG_H_FSZ_L);
  1131. DUMPREG(HDMI_TG_H_FSZ_H);
  1132. DUMPREG(HDMI_TG_HACT_ST_L);
  1133. DUMPREG(HDMI_TG_HACT_ST_H);
  1134. DUMPREG(HDMI_TG_HACT_SZ_L);
  1135. DUMPREG(HDMI_TG_HACT_SZ_H);
  1136. DUMPREG(HDMI_TG_V_FSZ_L);
  1137. DUMPREG(HDMI_TG_V_FSZ_H);
  1138. DUMPREG(HDMI_TG_VSYNC_L);
  1139. DUMPREG(HDMI_TG_VSYNC_H);
  1140. DUMPREG(HDMI_TG_VSYNC2_L);
  1141. DUMPREG(HDMI_TG_VSYNC2_H);
  1142. DUMPREG(HDMI_TG_VACT_ST_L);
  1143. DUMPREG(HDMI_TG_VACT_ST_H);
  1144. DUMPREG(HDMI_TG_VACT_SZ_L);
  1145. DUMPREG(HDMI_TG_VACT_SZ_H);
  1146. DUMPREG(HDMI_TG_FIELD_CHG_L);
  1147. DUMPREG(HDMI_TG_FIELD_CHG_H);
  1148. DUMPREG(HDMI_TG_VACT_ST2_L);
  1149. DUMPREG(HDMI_TG_VACT_ST2_H);
  1150. DUMPREG(HDMI_TG_VACT_ST3_L);
  1151. DUMPREG(HDMI_TG_VACT_ST3_H);
  1152. DUMPREG(HDMI_TG_VACT_ST4_L);
  1153. DUMPREG(HDMI_TG_VACT_ST4_H);
  1154. DUMPREG(HDMI_TG_VSYNC_TOP_HDMI_L);
  1155. DUMPREG(HDMI_TG_VSYNC_TOP_HDMI_H);
  1156. DUMPREG(HDMI_TG_VSYNC_BOT_HDMI_L);
  1157. DUMPREG(HDMI_TG_VSYNC_BOT_HDMI_H);
  1158. DUMPREG(HDMI_TG_FIELD_TOP_HDMI_L);
  1159. DUMPREG(HDMI_TG_FIELD_TOP_HDMI_H);
  1160. DUMPREG(HDMI_TG_FIELD_BOT_HDMI_L);
  1161. DUMPREG(HDMI_TG_FIELD_BOT_HDMI_H);
  1162. DUMPREG(HDMI_TG_3D);
  1163. DRM_DEBUG_KMS("%s: ---- PACKET REGISTERS ----\n", prefix);
  1164. DUMPREG(HDMI_AVI_CON);
  1165. DUMPREG(HDMI_AVI_HEADER0);
  1166. DUMPREG(HDMI_AVI_HEADER1);
  1167. DUMPREG(HDMI_AVI_HEADER2);
  1168. DUMPREG(HDMI_AVI_CHECK_SUM);
  1169. DUMPREG(HDMI_VSI_CON);
  1170. DUMPREG(HDMI_VSI_HEADER0);
  1171. DUMPREG(HDMI_VSI_HEADER1);
  1172. DUMPREG(HDMI_VSI_HEADER2);
  1173. for (i = 0; i < 7; ++i)
  1174. DUMPREG(HDMI_VSI_DATA(i));
  1175. #undef DUMPREG
  1176. }
  1177. static void hdmi_regs_dump(struct hdmi_context *hdata, char *prefix)
  1178. {
  1179. if (hdata->type == HDMI_TYPE13)
  1180. hdmi_v13_regs_dump(hdata, prefix);
  1181. else
  1182. hdmi_v14_regs_dump(hdata, prefix);
  1183. }
  1184. static int hdmi_v13_conf_index(struct drm_display_mode *mode)
  1185. {
  1186. int i;
  1187. for (i = 0; i < ARRAY_SIZE(hdmi_v13_confs); ++i)
  1188. if (hdmi_v13_confs[i].width == mode->hdisplay &&
  1189. hdmi_v13_confs[i].height == mode->vdisplay &&
  1190. hdmi_v13_confs[i].vrefresh == mode->vrefresh &&
  1191. hdmi_v13_confs[i].interlace ==
  1192. ((mode->flags & DRM_MODE_FLAG_INTERLACE) ?
  1193. true : false))
  1194. return i;
  1195. return -EINVAL;
  1196. }
  1197. static int hdmi_v14_conf_index(struct drm_display_mode *mode)
  1198. {
  1199. int i;
  1200. for (i = 0; i < ARRAY_SIZE(hdmi_confs); ++i)
  1201. if (hdmi_confs[i].width == mode->hdisplay &&
  1202. hdmi_confs[i].height == mode->vdisplay &&
  1203. hdmi_confs[i].vrefresh == mode->vrefresh &&
  1204. hdmi_confs[i].interlace ==
  1205. ((mode->flags & DRM_MODE_FLAG_INTERLACE) ?
  1206. true : false))
  1207. return i;
  1208. return -EINVAL;
  1209. }
  1210. static int hdmi_conf_index(struct hdmi_context *hdata,
  1211. struct drm_display_mode *mode)
  1212. {
  1213. if (hdata->type == HDMI_TYPE13)
  1214. return hdmi_v13_conf_index(mode);
  1215. return hdmi_v14_conf_index(mode);
  1216. }
  1217. static u8 hdmi_chksum(struct hdmi_context *hdata,
  1218. u32 start, u8 len, u32 hdr_sum)
  1219. {
  1220. int i;
  1221. /* hdr_sum : header0 + header1 + header2
  1222. * start : start address of packet byte1
  1223. * len : packet bytes - 1 */
  1224. for (i = 0; i < len; ++i)
  1225. hdr_sum += 0xff & hdmi_reg_read(hdata, start + i * 4);
  1226. /* return 2's complement of 8 bit hdr_sum */
  1227. return (u8)(~(hdr_sum & 0xff) + 1);
  1228. }
  1229. static void hdmi_reg_infoframe(struct hdmi_context *hdata,
  1230. struct hdmi_infoframe *infoframe)
  1231. {
  1232. u32 hdr_sum;
  1233. u8 chksum;
  1234. u32 aspect_ratio;
  1235. u32 mod;
  1236. u32 vic;
  1237. DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
  1238. mod = hdmi_reg_read(hdata, HDMI_MODE_SEL);
  1239. if (hdata->dvi_mode) {
  1240. hdmi_reg_writeb(hdata, HDMI_VSI_CON,
  1241. HDMI_VSI_CON_DO_NOT_TRANSMIT);
  1242. hdmi_reg_writeb(hdata, HDMI_AVI_CON,
  1243. HDMI_AVI_CON_DO_NOT_TRANSMIT);
  1244. hdmi_reg_writeb(hdata, HDMI_AUI_CON, HDMI_AUI_CON_NO_TRAN);
  1245. return;
  1246. }
  1247. switch (infoframe->type) {
  1248. case HDMI_PACKET_TYPE_AVI:
  1249. hdmi_reg_writeb(hdata, HDMI_AVI_CON, HDMI_AVI_CON_EVERY_VSYNC);
  1250. hdmi_reg_writeb(hdata, HDMI_AVI_HEADER0, infoframe->type);
  1251. hdmi_reg_writeb(hdata, HDMI_AVI_HEADER1, infoframe->ver);
  1252. hdmi_reg_writeb(hdata, HDMI_AVI_HEADER2, infoframe->len);
  1253. hdr_sum = infoframe->type + infoframe->ver + infoframe->len;
  1254. /* Output format zero hardcoded ,RGB YBCR selection */
  1255. hdmi_reg_writeb(hdata, HDMI_AVI_BYTE(1), 0 << 5 |
  1256. AVI_ACTIVE_FORMAT_VALID |
  1257. AVI_UNDERSCANNED_DISPLAY_VALID);
  1258. aspect_ratio = AVI_PIC_ASPECT_RATIO_16_9;
  1259. hdmi_reg_writeb(hdata, HDMI_AVI_BYTE(2), aspect_ratio |
  1260. AVI_SAME_AS_PIC_ASPECT_RATIO);
  1261. if (hdata->type == HDMI_TYPE13)
  1262. vic = hdmi_v13_confs[hdata->cur_conf].cea_video_id;
  1263. else
  1264. vic = hdmi_confs[hdata->cur_conf].cea_video_id;
  1265. hdmi_reg_writeb(hdata, HDMI_AVI_BYTE(4), vic);
  1266. chksum = hdmi_chksum(hdata, HDMI_AVI_BYTE(1),
  1267. infoframe->len, hdr_sum);
  1268. DRM_DEBUG_KMS("AVI checksum = 0x%x\n", chksum);
  1269. hdmi_reg_writeb(hdata, HDMI_AVI_CHECK_SUM, chksum);
  1270. break;
  1271. case HDMI_PACKET_TYPE_AUI:
  1272. hdmi_reg_writeb(hdata, HDMI_AUI_CON, 0x02);
  1273. hdmi_reg_writeb(hdata, HDMI_AUI_HEADER0, infoframe->type);
  1274. hdmi_reg_writeb(hdata, HDMI_AUI_HEADER1, infoframe->ver);
  1275. hdmi_reg_writeb(hdata, HDMI_AUI_HEADER2, infoframe->len);
  1276. hdr_sum = infoframe->type + infoframe->ver + infoframe->len;
  1277. chksum = hdmi_chksum(hdata, HDMI_AUI_BYTE(1),
  1278. infoframe->len, hdr_sum);
  1279. DRM_DEBUG_KMS("AUI checksum = 0x%x\n", chksum);
  1280. hdmi_reg_writeb(hdata, HDMI_AUI_CHECK_SUM, chksum);
  1281. break;
  1282. default:
  1283. break;
  1284. }
  1285. }
  1286. static bool hdmi_is_connected(void *ctx)
  1287. {
  1288. struct hdmi_context *hdata = ctx;
  1289. return hdata->hpd;
  1290. }
  1291. static int hdmi_get_edid(void *ctx, struct drm_connector *connector,
  1292. u8 *edid, int len)
  1293. {
  1294. struct edid *raw_edid;
  1295. struct hdmi_context *hdata = ctx;
  1296. DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
  1297. if (!hdata->ddc_port)
  1298. return -ENODEV;
  1299. raw_edid = drm_get_edid(connector, hdata->ddc_port->adapter);
  1300. if (raw_edid) {
  1301. hdata->dvi_mode = !drm_detect_hdmi_monitor(raw_edid);
  1302. memcpy(edid, raw_edid, min((1 + raw_edid->extensions)
  1303. * EDID_LENGTH, len));
  1304. DRM_DEBUG_KMS("%s : width[%d] x height[%d]\n",
  1305. (hdata->dvi_mode ? "dvi monitor" : "hdmi monitor"),
  1306. raw_edid->width_cm, raw_edid->height_cm);
  1307. kfree(raw_edid);
  1308. } else {
  1309. return -ENODEV;
  1310. }
  1311. return 0;
  1312. }
  1313. static int hdmi_v13_check_timing(struct fb_videomode *check_timing)
  1314. {
  1315. int i;
  1316. DRM_DEBUG_KMS("valid mode : xres=%d, yres=%d, refresh=%d, intl=%d\n",
  1317. check_timing->xres, check_timing->yres,
  1318. check_timing->refresh, (check_timing->vmode &
  1319. FB_VMODE_INTERLACED) ? true : false);
  1320. for (i = 0; i < ARRAY_SIZE(hdmi_v13_confs); ++i)
  1321. if (hdmi_v13_confs[i].width == check_timing->xres &&
  1322. hdmi_v13_confs[i].height == check_timing->yres &&
  1323. hdmi_v13_confs[i].vrefresh == check_timing->refresh &&
  1324. hdmi_v13_confs[i].interlace ==
  1325. ((check_timing->vmode & FB_VMODE_INTERLACED) ?
  1326. true : false))
  1327. return 0;
  1328. /* TODO */
  1329. return -EINVAL;
  1330. }
  1331. static int hdmi_v14_check_timing(struct fb_videomode *check_timing)
  1332. {
  1333. int i;
  1334. DRM_DEBUG_KMS("valid mode : xres=%d, yres=%d, refresh=%d, intl=%d\n",
  1335. check_timing->xres, check_timing->yres,
  1336. check_timing->refresh, (check_timing->vmode &
  1337. FB_VMODE_INTERLACED) ? true : false);
  1338. for (i = 0; i < ARRAY_SIZE(hdmi_confs); i++)
  1339. if (hdmi_confs[i].width == check_timing->xres &&
  1340. hdmi_confs[i].height == check_timing->yres &&
  1341. hdmi_confs[i].vrefresh == check_timing->refresh &&
  1342. hdmi_confs[i].interlace ==
  1343. ((check_timing->vmode & FB_VMODE_INTERLACED) ?
  1344. true : false))
  1345. return 0;
  1346. /* TODO */
  1347. return -EINVAL;
  1348. }
  1349. static int hdmi_check_timing(void *ctx, void *timing)
  1350. {
  1351. struct hdmi_context *hdata = ctx;
  1352. struct fb_videomode *check_timing = timing;
  1353. DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
  1354. DRM_DEBUG_KMS("[%d]x[%d] [%d]Hz [%x]\n", check_timing->xres,
  1355. check_timing->yres, check_timing->refresh,
  1356. check_timing->vmode);
  1357. if (hdata->type == HDMI_TYPE13)
  1358. return hdmi_v13_check_timing(check_timing);
  1359. else
  1360. return hdmi_v14_check_timing(check_timing);
  1361. }
  1362. static void hdmi_set_acr(u32 freq, u8 *acr)
  1363. {
  1364. u32 n, cts;
  1365. switch (freq) {
  1366. case 32000:
  1367. n = 4096;
  1368. cts = 27000;
  1369. break;
  1370. case 44100:
  1371. n = 6272;
  1372. cts = 30000;
  1373. break;
  1374. case 88200:
  1375. n = 12544;
  1376. cts = 30000;
  1377. break;
  1378. case 176400:
  1379. n = 25088;
  1380. cts = 30000;
  1381. break;
  1382. case 48000:
  1383. n = 6144;
  1384. cts = 27000;
  1385. break;
  1386. case 96000:
  1387. n = 12288;
  1388. cts = 27000;
  1389. break;
  1390. case 192000:
  1391. n = 24576;
  1392. cts = 27000;
  1393. break;
  1394. default:
  1395. n = 0;
  1396. cts = 0;
  1397. break;
  1398. }
  1399. acr[1] = cts >> 16;
  1400. acr[2] = cts >> 8 & 0xff;
  1401. acr[3] = cts & 0xff;
  1402. acr[4] = n >> 16;
  1403. acr[5] = n >> 8 & 0xff;
  1404. acr[6] = n & 0xff;
  1405. }
  1406. static void hdmi_reg_acr(struct hdmi_context *hdata, u8 *acr)
  1407. {
  1408. hdmi_reg_writeb(hdata, HDMI_ACR_N0, acr[6]);
  1409. hdmi_reg_writeb(hdata, HDMI_ACR_N1, acr[5]);
  1410. hdmi_reg_writeb(hdata, HDMI_ACR_N2, acr[4]);
  1411. hdmi_reg_writeb(hdata, HDMI_ACR_MCTS0, acr[3]);
  1412. hdmi_reg_writeb(hdata, HDMI_ACR_MCTS1, acr[2]);
  1413. hdmi_reg_writeb(hdata, HDMI_ACR_MCTS2, acr[1]);
  1414. hdmi_reg_writeb(hdata, HDMI_ACR_CTS0, acr[3]);
  1415. hdmi_reg_writeb(hdata, HDMI_ACR_CTS1, acr[2]);
  1416. hdmi_reg_writeb(hdata, HDMI_ACR_CTS2, acr[1]);
  1417. if (hdata->type == HDMI_TYPE13)
  1418. hdmi_reg_writeb(hdata, HDMI_V13_ACR_CON, 4);
  1419. else
  1420. hdmi_reg_writeb(hdata, HDMI_ACR_CON, 4);
  1421. }
  1422. static void hdmi_audio_init(struct hdmi_context *hdata)
  1423. {
  1424. u32 sample_rate, bits_per_sample, frame_size_code;
  1425. u32 data_num, bit_ch, sample_frq;
  1426. u32 val;
  1427. u8 acr[7];
  1428. sample_rate = 44100;
  1429. bits_per_sample = 16;
  1430. frame_size_code = 0;
  1431. switch (bits_per_sample) {
  1432. case 20:
  1433. data_num = 2;
  1434. bit_ch = 1;
  1435. break;
  1436. case 24:
  1437. data_num = 3;
  1438. bit_ch = 1;
  1439. break;
  1440. default:
  1441. data_num = 1;
  1442. bit_ch = 0;
  1443. break;
  1444. }
  1445. hdmi_set_acr(sample_rate, acr);
  1446. hdmi_reg_acr(hdata, acr);
  1447. hdmi_reg_writeb(hdata, HDMI_I2S_MUX_CON, HDMI_I2S_IN_DISABLE
  1448. | HDMI_I2S_AUD_I2S | HDMI_I2S_CUV_I2S_ENABLE
  1449. | HDMI_I2S_MUX_ENABLE);
  1450. hdmi_reg_writeb(hdata, HDMI_I2S_MUX_CH, HDMI_I2S_CH0_EN
  1451. | HDMI_I2S_CH1_EN | HDMI_I2S_CH2_EN);
  1452. hdmi_reg_writeb(hdata, HDMI_I2S_MUX_CUV, HDMI_I2S_CUV_RL_EN);
  1453. sample_frq = (sample_rate == 44100) ? 0 :
  1454. (sample_rate == 48000) ? 2 :
  1455. (sample_rate == 32000) ? 3 :
  1456. (sample_rate == 96000) ? 0xa : 0x0;
  1457. hdmi_reg_writeb(hdata, HDMI_I2S_CLK_CON, HDMI_I2S_CLK_DIS);
  1458. hdmi_reg_writeb(hdata, HDMI_I2S_CLK_CON, HDMI_I2S_CLK_EN);
  1459. val = hdmi_reg_read(hdata, HDMI_I2S_DSD_CON) | 0x01;
  1460. hdmi_reg_writeb(hdata, HDMI_I2S_DSD_CON, val);
  1461. /* Configuration I2S input ports. Configure I2S_PIN_SEL_0~4 */
  1462. hdmi_reg_writeb(hdata, HDMI_I2S_PIN_SEL_0, HDMI_I2S_SEL_SCLK(5)
  1463. | HDMI_I2S_SEL_LRCK(6));
  1464. hdmi_reg_writeb(hdata, HDMI_I2S_PIN_SEL_1, HDMI_I2S_SEL_SDATA1(1)
  1465. | HDMI_I2S_SEL_SDATA2(4));
  1466. hdmi_reg_writeb(hdata, HDMI_I2S_PIN_SEL_2, HDMI_I2S_SEL_SDATA3(1)
  1467. | HDMI_I2S_SEL_SDATA2(2));
  1468. hdmi_reg_writeb(hdata, HDMI_I2S_PIN_SEL_3, HDMI_I2S_SEL_DSD(0));
  1469. /* I2S_CON_1 & 2 */
  1470. hdmi_reg_writeb(hdata, HDMI_I2S_CON_1, HDMI_I2S_SCLK_FALLING_EDGE
  1471. | HDMI_I2S_L_CH_LOW_POL);
  1472. hdmi_reg_writeb(hdata, HDMI_I2S_CON_2, HDMI_I2S_MSB_FIRST_MODE
  1473. | HDMI_I2S_SET_BIT_CH(bit_ch)
  1474. | HDMI_I2S_SET_SDATA_BIT(data_num)
  1475. | HDMI_I2S_BASIC_FORMAT);
  1476. /* Configure register related to CUV information */
  1477. hdmi_reg_writeb(hdata, HDMI_I2S_CH_ST_0, HDMI_I2S_CH_STATUS_MODE_0
  1478. | HDMI_I2S_2AUD_CH_WITHOUT_PREEMPH
  1479. | HDMI_I2S_COPYRIGHT
  1480. | HDMI_I2S_LINEAR_PCM
  1481. | HDMI_I2S_CONSUMER_FORMAT);
  1482. hdmi_reg_writeb(hdata, HDMI_I2S_CH_ST_1, HDMI_I2S_CD_PLAYER);
  1483. hdmi_reg_writeb(hdata, HDMI_I2S_CH_ST_2, HDMI_I2S_SET_SOURCE_NUM(0));
  1484. hdmi_reg_writeb(hdata, HDMI_I2S_CH_ST_3, HDMI_I2S_CLK_ACCUR_LEVEL_2
  1485. | HDMI_I2S_SET_SMP_FREQ(sample_frq));
  1486. hdmi_reg_writeb(hdata, HDMI_I2S_CH_ST_4,
  1487. HDMI_I2S_ORG_SMP_FREQ_44_1
  1488. | HDMI_I2S_WORD_LEN_MAX24_24BITS
  1489. | HDMI_I2S_WORD_LEN_MAX_24BITS);
  1490. hdmi_reg_writeb(hdata, HDMI_I2S_CH_ST_CON, HDMI_I2S_CH_STATUS_RELOAD);
  1491. }
  1492. static void hdmi_audio_control(struct hdmi_context *hdata, bool onoff)
  1493. {
  1494. if (hdata->dvi_mode)
  1495. return;
  1496. hdmi_reg_writeb(hdata, HDMI_AUI_CON, onoff ? 2 : 0);
  1497. hdmi_reg_writemask(hdata, HDMI_CON_0, onoff ?
  1498. HDMI_ASP_EN : HDMI_ASP_DIS, HDMI_ASP_MASK);
  1499. }
  1500. static void hdmi_conf_reset(struct hdmi_context *hdata)
  1501. {
  1502. u32 reg;
  1503. if (hdata->type == HDMI_TYPE13)
  1504. reg = HDMI_V13_CORE_RSTOUT;
  1505. else
  1506. reg = HDMI_CORE_RSTOUT;
  1507. /* resetting HDMI core */
  1508. hdmi_reg_writemask(hdata, reg, 0, HDMI_CORE_SW_RSTOUT);
  1509. mdelay(10);
  1510. hdmi_reg_writemask(hdata, reg, ~0, HDMI_CORE_SW_RSTOUT);
  1511. mdelay(10);
  1512. }
  1513. static void hdmi_conf_init(struct hdmi_context *hdata)
  1514. {
  1515. struct hdmi_infoframe infoframe;
  1516. /* disable HPD interrupts */
  1517. hdmi_reg_writemask(hdata, HDMI_INTC_CON, 0, HDMI_INTC_EN_GLOBAL |
  1518. HDMI_INTC_EN_HPD_PLUG | HDMI_INTC_EN_HPD_UNPLUG);
  1519. /* choose HDMI mode */
  1520. hdmi_reg_writemask(hdata, HDMI_MODE_SEL,
  1521. HDMI_MODE_HDMI_EN, HDMI_MODE_MASK);
  1522. /* disable bluescreen */
  1523. hdmi_reg_writemask(hdata, HDMI_CON_0, 0, HDMI_BLUE_SCR_EN);
  1524. if (hdata->dvi_mode) {
  1525. /* choose DVI mode */
  1526. hdmi_reg_writemask(hdata, HDMI_MODE_SEL,
  1527. HDMI_MODE_DVI_EN, HDMI_MODE_MASK);
  1528. hdmi_reg_writeb(hdata, HDMI_CON_2,
  1529. HDMI_VID_PREAMBLE_DIS | HDMI_GUARD_BAND_DIS);
  1530. }
  1531. if (hdata->type == HDMI_TYPE13) {
  1532. /* choose bluescreen (fecal) color */
  1533. hdmi_reg_writeb(hdata, HDMI_V13_BLUE_SCREEN_0, 0x12);
  1534. hdmi_reg_writeb(hdata, HDMI_V13_BLUE_SCREEN_1, 0x34);
  1535. hdmi_reg_writeb(hdata, HDMI_V13_BLUE_SCREEN_2, 0x56);
  1536. /* enable AVI packet every vsync, fixes purple line problem */
  1537. hdmi_reg_writeb(hdata, HDMI_V13_AVI_CON, 0x02);
  1538. /* force RGB, look to CEA-861-D, table 7 for more detail */
  1539. hdmi_reg_writeb(hdata, HDMI_V13_AVI_BYTE(0), 0 << 5);
  1540. hdmi_reg_writemask(hdata, HDMI_CON_1, 0x10 << 5, 0x11 << 5);
  1541. hdmi_reg_writeb(hdata, HDMI_V13_SPD_CON, 0x02);
  1542. hdmi_reg_writeb(hdata, HDMI_V13_AUI_CON, 0x02);
  1543. hdmi_reg_writeb(hdata, HDMI_V13_ACR_CON, 0x04);
  1544. } else {
  1545. infoframe.type = HDMI_PACKET_TYPE_AVI;
  1546. infoframe.ver = HDMI_AVI_VERSION;
  1547. infoframe.len = HDMI_AVI_LENGTH;
  1548. hdmi_reg_infoframe(hdata, &infoframe);
  1549. infoframe.type = HDMI_PACKET_TYPE_AUI;
  1550. infoframe.ver = HDMI_AUI_VERSION;
  1551. infoframe.len = HDMI_AUI_LENGTH;
  1552. hdmi_reg_infoframe(hdata, &infoframe);
  1553. /* enable AVI packet every vsync, fixes purple line problem */
  1554. hdmi_reg_writemask(hdata, HDMI_CON_1, 2, 3 << 5);
  1555. }
  1556. }
  1557. static void hdmi_v13_timing_apply(struct hdmi_context *hdata)
  1558. {
  1559. const struct hdmi_v13_preset_conf *conf =
  1560. hdmi_v13_confs[hdata->cur_conf].conf;
  1561. const struct hdmi_v13_core_regs *core = &conf->core;
  1562. const struct hdmi_v13_tg_regs *tg = &conf->tg;
  1563. int tries;
  1564. /* setting core registers */
  1565. hdmi_reg_writeb(hdata, HDMI_H_BLANK_0, core->h_blank[0]);
  1566. hdmi_reg_writeb(hdata, HDMI_H_BLANK_1, core->h_blank[1]);
  1567. hdmi_reg_writeb(hdata, HDMI_V13_V_BLANK_0, core->v_blank[0]);
  1568. hdmi_reg_writeb(hdata, HDMI_V13_V_BLANK_1, core->v_blank[1]);
  1569. hdmi_reg_writeb(hdata, HDMI_V13_V_BLANK_2, core->v_blank[2]);
  1570. hdmi_reg_writeb(hdata, HDMI_V13_H_V_LINE_0, core->h_v_line[0]);
  1571. hdmi_reg_writeb(hdata, HDMI_V13_H_V_LINE_1, core->h_v_line[1]);
  1572. hdmi_reg_writeb(hdata, HDMI_V13_H_V_LINE_2, core->h_v_line[2]);
  1573. hdmi_reg_writeb(hdata, HDMI_VSYNC_POL, core->vsync_pol[0]);
  1574. hdmi_reg_writeb(hdata, HDMI_INT_PRO_MODE, core->int_pro_mode[0]);
  1575. hdmi_reg_writeb(hdata, HDMI_V13_V_BLANK_F_0, core->v_blank_f[0]);
  1576. hdmi_reg_writeb(hdata, HDMI_V13_V_BLANK_F_1, core->v_blank_f[1]);
  1577. hdmi_reg_writeb(hdata, HDMI_V13_V_BLANK_F_2, core->v_blank_f[2]);
  1578. hdmi_reg_writeb(hdata, HDMI_V13_H_SYNC_GEN_0, core->h_sync_gen[0]);
  1579. hdmi_reg_writeb(hdata, HDMI_V13_H_SYNC_GEN_1, core->h_sync_gen[1]);
  1580. hdmi_reg_writeb(hdata, HDMI_V13_H_SYNC_GEN_2, core->h_sync_gen[2]);
  1581. hdmi_reg_writeb(hdata, HDMI_V13_V_SYNC_GEN_1_0, core->v_sync_gen1[0]);
  1582. hdmi_reg_writeb(hdata, HDMI_V13_V_SYNC_GEN_1_1, core->v_sync_gen1[1]);
  1583. hdmi_reg_writeb(hdata, HDMI_V13_V_SYNC_GEN_1_2, core->v_sync_gen1[2]);
  1584. hdmi_reg_writeb(hdata, HDMI_V13_V_SYNC_GEN_2_0, core->v_sync_gen2[0]);
  1585. hdmi_reg_writeb(hdata, HDMI_V13_V_SYNC_GEN_2_1, core->v_sync_gen2[1]);
  1586. hdmi_reg_writeb(hdata, HDMI_V13_V_SYNC_GEN_2_2, core->v_sync_gen2[2]);
  1587. hdmi_reg_writeb(hdata, HDMI_V13_V_SYNC_GEN_3_0, core->v_sync_gen3[0]);
  1588. hdmi_reg_writeb(hdata, HDMI_V13_V_SYNC_GEN_3_1, core->v_sync_gen3[1]);
  1589. hdmi_reg_writeb(hdata, HDMI_V13_V_SYNC_GEN_3_2, core->v_sync_gen3[2]);
  1590. /* Timing generator registers */
  1591. hdmi_reg_writeb(hdata, HDMI_TG_H_FSZ_L, tg->h_fsz_l);
  1592. hdmi_reg_writeb(hdata, HDMI_TG_H_FSZ_H, tg->h_fsz_h);
  1593. hdmi_reg_writeb(hdata, HDMI_TG_HACT_ST_L, tg->hact_st_l);
  1594. hdmi_reg_writeb(hdata, HDMI_TG_HACT_ST_H, tg->hact_st_h);
  1595. hdmi_reg_writeb(hdata, HDMI_TG_HACT_SZ_L, tg->hact_sz_l);
  1596. hdmi_reg_writeb(hdata, HDMI_TG_HACT_SZ_H, tg->hact_sz_h);
  1597. hdmi_reg_writeb(hdata, HDMI_TG_V_FSZ_L, tg->v_fsz_l);
  1598. hdmi_reg_writeb(hdata, HDMI_TG_V_FSZ_H, tg->v_fsz_h);
  1599. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_L, tg->vsync_l);
  1600. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_H, tg->vsync_h);
  1601. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC2_L, tg->vsync2_l);
  1602. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC2_H, tg->vsync2_h);
  1603. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST_L, tg->vact_st_l);
  1604. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST_H, tg->vact_st_h);
  1605. hdmi_reg_writeb(hdata, HDMI_TG_VACT_SZ_L, tg->vact_sz_l);
  1606. hdmi_reg_writeb(hdata, HDMI_TG_VACT_SZ_H, tg->vact_sz_h);
  1607. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_CHG_L, tg->field_chg_l);
  1608. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_CHG_H, tg->field_chg_h);
  1609. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST2_L, tg->vact_st2_l);
  1610. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST2_H, tg->vact_st2_h);
  1611. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_TOP_HDMI_L, tg->vsync_top_hdmi_l);
  1612. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_TOP_HDMI_H, tg->vsync_top_hdmi_h);
  1613. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_BOT_HDMI_L, tg->vsync_bot_hdmi_l);
  1614. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_BOT_HDMI_H, tg->vsync_bot_hdmi_h);
  1615. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_TOP_HDMI_L, tg->field_top_hdmi_l);
  1616. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_TOP_HDMI_H, tg->field_top_hdmi_h);
  1617. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_BOT_HDMI_L, tg->field_bot_hdmi_l);
  1618. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_BOT_HDMI_H, tg->field_bot_hdmi_h);
  1619. /* waiting for HDMIPHY's PLL to get to steady state */
  1620. for (tries = 100; tries; --tries) {
  1621. u32 val = hdmi_reg_read(hdata, HDMI_V13_PHY_STATUS);
  1622. if (val & HDMI_PHY_STATUS_READY)
  1623. break;
  1624. mdelay(1);
  1625. }
  1626. /* steady state not achieved */
  1627. if (tries == 0) {
  1628. DRM_ERROR("hdmiphy's pll could not reach steady state.\n");
  1629. hdmi_regs_dump(hdata, "timing apply");
  1630. }
  1631. clk_disable(hdata->res.sclk_hdmi);
  1632. clk_set_parent(hdata->res.sclk_hdmi, hdata->res.sclk_hdmiphy);
  1633. clk_enable(hdata->res.sclk_hdmi);
  1634. /* enable HDMI and timing generator */
  1635. hdmi_reg_writemask(hdata, HDMI_CON_0, ~0, HDMI_EN);
  1636. if (core->int_pro_mode[0])
  1637. hdmi_reg_writemask(hdata, HDMI_TG_CMD, ~0, HDMI_TG_EN |
  1638. HDMI_FIELD_EN);
  1639. else
  1640. hdmi_reg_writemask(hdata, HDMI_TG_CMD, ~0, HDMI_TG_EN);
  1641. }
  1642. static void hdmi_v14_timing_apply(struct hdmi_context *hdata)
  1643. {
  1644. const struct hdmi_preset_conf *conf = hdmi_confs[hdata->cur_conf].conf;
  1645. const struct hdmi_core_regs *core = &conf->core;
  1646. const struct hdmi_tg_regs *tg = &conf->tg;
  1647. int tries;
  1648. /* setting core registers */
  1649. hdmi_reg_writeb(hdata, HDMI_H_BLANK_0, core->h_blank[0]);
  1650. hdmi_reg_writeb(hdata, HDMI_H_BLANK_1, core->h_blank[1]);
  1651. hdmi_reg_writeb(hdata, HDMI_V2_BLANK_0, core->v2_blank[0]);
  1652. hdmi_reg_writeb(hdata, HDMI_V2_BLANK_1, core->v2_blank[1]);
  1653. hdmi_reg_writeb(hdata, HDMI_V1_BLANK_0, core->v1_blank[0]);
  1654. hdmi_reg_writeb(hdata, HDMI_V1_BLANK_1, core->v1_blank[1]);
  1655. hdmi_reg_writeb(hdata, HDMI_V_LINE_0, core->v_line[0]);
  1656. hdmi_reg_writeb(hdata, HDMI_V_LINE_1, core->v_line[1]);
  1657. hdmi_reg_writeb(hdata, HDMI_H_LINE_0, core->h_line[0]);
  1658. hdmi_reg_writeb(hdata, HDMI_H_LINE_1, core->h_line[1]);
  1659. hdmi_reg_writeb(hdata, HDMI_HSYNC_POL, core->hsync_pol[0]);
  1660. hdmi_reg_writeb(hdata, HDMI_VSYNC_POL, core->vsync_pol[0]);
  1661. hdmi_reg_writeb(hdata, HDMI_INT_PRO_MODE, core->int_pro_mode[0]);
  1662. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F0_0, core->v_blank_f0[0]);
  1663. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F0_1, core->v_blank_f0[1]);
  1664. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F1_0, core->v_blank_f1[0]);
  1665. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F1_1, core->v_blank_f1[1]);
  1666. hdmi_reg_writeb(hdata, HDMI_H_SYNC_START_0, core->h_sync_start[0]);
  1667. hdmi_reg_writeb(hdata, HDMI_H_SYNC_START_1, core->h_sync_start[1]);
  1668. hdmi_reg_writeb(hdata, HDMI_H_SYNC_END_0, core->h_sync_end[0]);
  1669. hdmi_reg_writeb(hdata, HDMI_H_SYNC_END_1, core->h_sync_end[1]);
  1670. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_BEF_2_0,
  1671. core->v_sync_line_bef_2[0]);
  1672. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_BEF_2_1,
  1673. core->v_sync_line_bef_2[1]);
  1674. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_BEF_1_0,
  1675. core->v_sync_line_bef_1[0]);
  1676. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_BEF_1_1,
  1677. core->v_sync_line_bef_1[1]);
  1678. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_2_0,
  1679. core->v_sync_line_aft_2[0]);
  1680. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_2_1,
  1681. core->v_sync_line_aft_2[1]);
  1682. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_1_0,
  1683. core->v_sync_line_aft_1[0]);
  1684. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_1_1,
  1685. core->v_sync_line_aft_1[1]);
  1686. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_2_0,
  1687. core->v_sync_line_aft_pxl_2[0]);
  1688. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_2_1,
  1689. core->v_sync_line_aft_pxl_2[1]);
  1690. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_1_0,
  1691. core->v_sync_line_aft_pxl_1[0]);
  1692. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_1_1,
  1693. core->v_sync_line_aft_pxl_1[1]);
  1694. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F2_0, core->v_blank_f2[0]);
  1695. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F2_1, core->v_blank_f2[1]);
  1696. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F3_0, core->v_blank_f3[0]);
  1697. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F3_1, core->v_blank_f3[1]);
  1698. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F4_0, core->v_blank_f4[0]);
  1699. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F4_1, core->v_blank_f4[1]);
  1700. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F5_0, core->v_blank_f5[0]);
  1701. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F5_1, core->v_blank_f5[1]);
  1702. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_3_0,
  1703. core->v_sync_line_aft_3[0]);
  1704. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_3_1,
  1705. core->v_sync_line_aft_3[1]);
  1706. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_4_0,
  1707. core->v_sync_line_aft_4[0]);
  1708. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_4_1,
  1709. core->v_sync_line_aft_4[1]);
  1710. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_5_0,
  1711. core->v_sync_line_aft_5[0]);
  1712. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_5_1,
  1713. core->v_sync_line_aft_5[1]);
  1714. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_6_0,
  1715. core->v_sync_line_aft_6[0]);
  1716. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_6_1,
  1717. core->v_sync_line_aft_6[1]);
  1718. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_3_0,
  1719. core->v_sync_line_aft_pxl_3[0]);
  1720. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_3_1,
  1721. core->v_sync_line_aft_pxl_3[1]);
  1722. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_4_0,
  1723. core->v_sync_line_aft_pxl_4[0]);
  1724. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_4_1,
  1725. core->v_sync_line_aft_pxl_4[1]);
  1726. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_5_0,
  1727. core->v_sync_line_aft_pxl_5[0]);
  1728. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_5_1,
  1729. core->v_sync_line_aft_pxl_5[1]);
  1730. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_6_0,
  1731. core->v_sync_line_aft_pxl_6[0]);
  1732. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_6_1,
  1733. core->v_sync_line_aft_pxl_6[1]);
  1734. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_1_0, core->vact_space_1[0]);
  1735. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_1_1, core->vact_space_1[1]);
  1736. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_2_0, core->vact_space_2[0]);
  1737. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_2_1, core->vact_space_2[1]);
  1738. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_3_0, core->vact_space_3[0]);
  1739. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_3_1, core->vact_space_3[1]);
  1740. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_4_0, core->vact_space_4[0]);
  1741. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_4_1, core->vact_space_4[1]);
  1742. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_5_0, core->vact_space_5[0]);
  1743. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_5_1, core->vact_space_5[1]);
  1744. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_6_0, core->vact_space_6[0]);
  1745. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_6_1, core->vact_space_6[1]);
  1746. /* Timing generator registers */
  1747. hdmi_reg_writeb(hdata, HDMI_TG_H_FSZ_L, tg->h_fsz_l);
  1748. hdmi_reg_writeb(hdata, HDMI_TG_H_FSZ_H, tg->h_fsz_h);
  1749. hdmi_reg_writeb(hdata, HDMI_TG_HACT_ST_L, tg->hact_st_l);
  1750. hdmi_reg_writeb(hdata, HDMI_TG_HACT_ST_H, tg->hact_st_h);
  1751. hdmi_reg_writeb(hdata, HDMI_TG_HACT_SZ_L, tg->hact_sz_l);
  1752. hdmi_reg_writeb(hdata, HDMI_TG_HACT_SZ_H, tg->hact_sz_h);
  1753. hdmi_reg_writeb(hdata, HDMI_TG_V_FSZ_L, tg->v_fsz_l);
  1754. hdmi_reg_writeb(hdata, HDMI_TG_V_FSZ_H, tg->v_fsz_h);
  1755. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_L, tg->vsync_l);
  1756. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_H, tg->vsync_h);
  1757. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC2_L, tg->vsync2_l);
  1758. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC2_H, tg->vsync2_h);
  1759. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST_L, tg->vact_st_l);
  1760. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST_H, tg->vact_st_h);
  1761. hdmi_reg_writeb(hdata, HDMI_TG_VACT_SZ_L, tg->vact_sz_l);
  1762. hdmi_reg_writeb(hdata, HDMI_TG_VACT_SZ_H, tg->vact_sz_h);
  1763. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_CHG_L, tg->field_chg_l);
  1764. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_CHG_H, tg->field_chg_h);
  1765. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST2_L, tg->vact_st2_l);
  1766. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST2_H, tg->vact_st2_h);
  1767. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST3_L, tg->vact_st3_l);
  1768. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST3_H, tg->vact_st3_h);
  1769. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST4_L, tg->vact_st4_l);
  1770. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST4_H, tg->vact_st4_h);
  1771. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_TOP_HDMI_L, tg->vsync_top_hdmi_l);
  1772. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_TOP_HDMI_H, tg->vsync_top_hdmi_h);
  1773. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_BOT_HDMI_L, tg->vsync_bot_hdmi_l);
  1774. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_BOT_HDMI_H, tg->vsync_bot_hdmi_h);
  1775. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_TOP_HDMI_L, tg->field_top_hdmi_l);
  1776. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_TOP_HDMI_H, tg->field_top_hdmi_h);
  1777. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_BOT_HDMI_L, tg->field_bot_hdmi_l);
  1778. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_BOT_HDMI_H, tg->field_bot_hdmi_h);
  1779. hdmi_reg_writeb(hdata, HDMI_TG_3D, tg->tg_3d);
  1780. /* waiting for HDMIPHY's PLL to get to steady state */
  1781. for (tries = 100; tries; --tries) {
  1782. u32 val = hdmi_reg_read(hdata, HDMI_PHY_STATUS_0);
  1783. if (val & HDMI_PHY_STATUS_READY)
  1784. break;
  1785. mdelay(1);
  1786. }
  1787. /* steady state not achieved */
  1788. if (tries == 0) {
  1789. DRM_ERROR("hdmiphy's pll could not reach steady state.\n");
  1790. hdmi_regs_dump(hdata, "timing apply");
  1791. }
  1792. clk_disable(hdata->res.sclk_hdmi);
  1793. clk_set_parent(hdata->res.sclk_hdmi, hdata->res.sclk_hdmiphy);
  1794. clk_enable(hdata->res.sclk_hdmi);
  1795. /* enable HDMI and timing generator */
  1796. hdmi_reg_writemask(hdata, HDMI_CON_0, ~0, HDMI_EN);
  1797. if (core->int_pro_mode[0])
  1798. hdmi_reg_writemask(hdata, HDMI_TG_CMD, ~0, HDMI_TG_EN |
  1799. HDMI_FIELD_EN);
  1800. else
  1801. hdmi_reg_writemask(hdata, HDMI_TG_CMD, ~0, HDMI_TG_EN);
  1802. }
  1803. static void hdmi_timing_apply(struct hdmi_context *hdata)
  1804. {
  1805. if (hdata->type == HDMI_TYPE13)
  1806. hdmi_v13_timing_apply(hdata);
  1807. else
  1808. hdmi_v14_timing_apply(hdata);
  1809. }
  1810. static void hdmiphy_conf_reset(struct hdmi_context *hdata)
  1811. {
  1812. u8 buffer[2];
  1813. u32 reg;
  1814. clk_disable(hdata->res.sclk_hdmi);
  1815. clk_set_parent(hdata->res.sclk_hdmi, hdata->res.sclk_pixel);
  1816. clk_enable(hdata->res.sclk_hdmi);
  1817. /* operation mode */
  1818. buffer[0] = 0x1f;
  1819. buffer[1] = 0x00;
  1820. if (hdata->hdmiphy_port)
  1821. i2c_master_send(hdata->hdmiphy_port, buffer, 2);
  1822. if (hdata->type == HDMI_TYPE13)
  1823. reg = HDMI_V13_PHY_RSTOUT;
  1824. else
  1825. reg = HDMI_PHY_RSTOUT;
  1826. /* reset hdmiphy */
  1827. hdmi_reg_writemask(hdata, reg, ~0, HDMI_PHY_SW_RSTOUT);
  1828. mdelay(10);
  1829. hdmi_reg_writemask(hdata, reg, 0, HDMI_PHY_SW_RSTOUT);
  1830. mdelay(10);
  1831. }
  1832. static void hdmiphy_poweron(struct hdmi_context *hdata)
  1833. {
  1834. DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
  1835. if (hdata->type == HDMI_TYPE14)
  1836. hdmi_reg_writemask(hdata, HDMI_PHY_CON_0, 0,
  1837. HDMI_PHY_POWER_OFF_EN);
  1838. }
  1839. static void hdmiphy_poweroff(struct hdmi_context *hdata)
  1840. {
  1841. DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
  1842. if (hdata->type == HDMI_TYPE14)
  1843. hdmi_reg_writemask(hdata, HDMI_PHY_CON_0, ~0,
  1844. HDMI_PHY_POWER_OFF_EN);
  1845. }
  1846. static void hdmiphy_conf_apply(struct hdmi_context *hdata)
  1847. {
  1848. const u8 *hdmiphy_data;
  1849. u8 buffer[32];
  1850. u8 operation[2];
  1851. u8 read_buffer[32] = {0, };
  1852. int ret;
  1853. int i;
  1854. if (!hdata->hdmiphy_port) {
  1855. DRM_ERROR("hdmiphy is not attached\n");
  1856. return;
  1857. }
  1858. /* pixel clock */
  1859. if (hdata->type == HDMI_TYPE13)
  1860. hdmiphy_data = hdmi_v13_confs[hdata->cur_conf].hdmiphy_data;
  1861. else
  1862. hdmiphy_data = hdmi_confs[hdata->cur_conf].hdmiphy_data;
  1863. memcpy(buffer, hdmiphy_data, 32);
  1864. ret = i2c_master_send(hdata->hdmiphy_port, buffer, 32);
  1865. if (ret != 32) {
  1866. DRM_ERROR("failed to configure HDMIPHY via I2C\n");
  1867. return;
  1868. }
  1869. mdelay(10);
  1870. /* operation mode */
  1871. operation[0] = 0x1f;
  1872. operation[1] = 0x80;
  1873. ret = i2c_master_send(hdata->hdmiphy_port, operation, 2);
  1874. if (ret != 2) {
  1875. DRM_ERROR("failed to enable hdmiphy\n");
  1876. return;
  1877. }
  1878. ret = i2c_master_recv(hdata->hdmiphy_port, read_buffer, 32);
  1879. if (ret < 0) {
  1880. DRM_ERROR("failed to read hdmiphy config\n");
  1881. return;
  1882. }
  1883. for (i = 0; i < ret; i++)
  1884. DRM_DEBUG_KMS("hdmiphy[0x%02x] write[0x%02x] - "
  1885. "recv [0x%02x]\n", i, buffer[i], read_buffer[i]);
  1886. }
  1887. static void hdmi_conf_apply(struct hdmi_context *hdata)
  1888. {
  1889. DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
  1890. hdmiphy_conf_reset(hdata);
  1891. hdmiphy_conf_apply(hdata);
  1892. mutex_lock(&hdata->hdmi_mutex);
  1893. hdmi_conf_reset(hdata);
  1894. hdmi_conf_init(hdata);
  1895. mutex_unlock(&hdata->hdmi_mutex);
  1896. hdmi_audio_init(hdata);
  1897. /* setting core registers */
  1898. hdmi_timing_apply(hdata);
  1899. hdmi_audio_control(hdata, true);
  1900. hdmi_regs_dump(hdata, "start");
  1901. }
  1902. static void hdmi_mode_fixup(void *ctx, struct drm_connector *connector,
  1903. const struct drm_display_mode *mode,
  1904. struct drm_display_mode *adjusted_mode)
  1905. {
  1906. struct drm_display_mode *m;
  1907. struct hdmi_context *hdata = ctx;
  1908. int index;
  1909. DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
  1910. drm_mode_set_crtcinfo(adjusted_mode, 0);
  1911. if (hdata->type == HDMI_TYPE13)
  1912. index = hdmi_v13_conf_index(adjusted_mode);
  1913. else
  1914. index = hdmi_v14_conf_index(adjusted_mode);
  1915. /* just return if user desired mode exists. */
  1916. if (index >= 0)
  1917. return;
  1918. /*
  1919. * otherwise, find the most suitable mode among modes and change it
  1920. * to adjusted_mode.
  1921. */
  1922. list_for_each_entry(m, &connector->modes, head) {
  1923. if (hdata->type == HDMI_TYPE13)
  1924. index = hdmi_v13_conf_index(m);
  1925. else
  1926. index = hdmi_v14_conf_index(m);
  1927. if (index >= 0) {
  1928. struct drm_mode_object base;
  1929. struct list_head head;
  1930. DRM_INFO("desired mode doesn't exist so\n");
  1931. DRM_INFO("use the most suitable mode among modes.\n");
  1932. /* preserve display mode header while copying. */
  1933. head = adjusted_mode->head;
  1934. base = adjusted_mode->base;
  1935. memcpy(adjusted_mode, m, sizeof(*m));
  1936. adjusted_mode->head = head;
  1937. adjusted_mode->base = base;
  1938. break;
  1939. }
  1940. }
  1941. }
  1942. static void hdmi_mode_set(void *ctx, void *mode)
  1943. {
  1944. struct hdmi_context *hdata = ctx;
  1945. int conf_idx;
  1946. DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
  1947. conf_idx = hdmi_conf_index(hdata, mode);
  1948. if (conf_idx >= 0)
  1949. hdata->cur_conf = conf_idx;
  1950. else
  1951. DRM_DEBUG_KMS("not supported mode\n");
  1952. }
  1953. static void hdmi_get_max_resol(void *ctx, unsigned int *width,
  1954. unsigned int *height)
  1955. {
  1956. DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
  1957. *width = MAX_WIDTH;
  1958. *height = MAX_HEIGHT;
  1959. }
  1960. static void hdmi_commit(void *ctx)
  1961. {
  1962. struct hdmi_context *hdata = ctx;
  1963. DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
  1964. hdmi_conf_apply(hdata);
  1965. }
  1966. static void hdmi_poweron(struct hdmi_context *hdata)
  1967. {
  1968. struct hdmi_resources *res = &hdata->res;
  1969. DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
  1970. mutex_lock(&hdata->hdmi_mutex);
  1971. if (hdata->powered) {
  1972. mutex_unlock(&hdata->hdmi_mutex);
  1973. return;
  1974. }
  1975. hdata->powered = true;
  1976. mutex_unlock(&hdata->hdmi_mutex);
  1977. regulator_bulk_enable(res->regul_count, res->regul_bulk);
  1978. clk_enable(res->hdmiphy);
  1979. clk_enable(res->hdmi);
  1980. clk_enable(res->sclk_hdmi);
  1981. hdmiphy_poweron(hdata);
  1982. }
  1983. static void hdmi_poweroff(struct hdmi_context *hdata)
  1984. {
  1985. struct hdmi_resources *res = &hdata->res;
  1986. DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
  1987. mutex_lock(&hdata->hdmi_mutex);
  1988. if (!hdata->powered)
  1989. goto out;
  1990. mutex_unlock(&hdata->hdmi_mutex);
  1991. /*
  1992. * The TV power domain needs any condition of hdmiphy to turn off and
  1993. * its reset state seems to meet the condition.
  1994. */
  1995. hdmiphy_conf_reset(hdata);
  1996. hdmiphy_poweroff(hdata);
  1997. clk_disable(res->sclk_hdmi);
  1998. clk_disable(res->hdmi);
  1999. clk_disable(res->hdmiphy);
  2000. regulator_bulk_disable(res->regul_count, res->regul_bulk);
  2001. mutex_lock(&hdata->hdmi_mutex);
  2002. hdata->powered = false;
  2003. out:
  2004. mutex_unlock(&hdata->hdmi_mutex);
  2005. }
  2006. static void hdmi_dpms(void *ctx, int mode)
  2007. {
  2008. struct hdmi_context *hdata = ctx;
  2009. DRM_DEBUG_KMS("[%d] %s mode %d\n", __LINE__, __func__, mode);
  2010. switch (mode) {
  2011. case DRM_MODE_DPMS_ON:
  2012. if (pm_runtime_suspended(hdata->dev))
  2013. pm_runtime_get_sync(hdata->dev);
  2014. break;
  2015. case DRM_MODE_DPMS_STANDBY:
  2016. case DRM_MODE_DPMS_SUSPEND:
  2017. case DRM_MODE_DPMS_OFF:
  2018. if (!pm_runtime_suspended(hdata->dev))
  2019. pm_runtime_put_sync(hdata->dev);
  2020. break;
  2021. default:
  2022. DRM_DEBUG_KMS("unknown dpms mode: %d\n", mode);
  2023. break;
  2024. }
  2025. }
  2026. static struct exynos_hdmi_ops hdmi_ops = {
  2027. /* display */
  2028. .is_connected = hdmi_is_connected,
  2029. .get_edid = hdmi_get_edid,
  2030. .check_timing = hdmi_check_timing,
  2031. /* manager */
  2032. .mode_fixup = hdmi_mode_fixup,
  2033. .mode_set = hdmi_mode_set,
  2034. .get_max_resol = hdmi_get_max_resol,
  2035. .commit = hdmi_commit,
  2036. .dpms = hdmi_dpms,
  2037. };
  2038. static irqreturn_t hdmi_external_irq_thread(int irq, void *arg)
  2039. {
  2040. struct exynos_drm_hdmi_context *ctx = arg;
  2041. struct hdmi_context *hdata = ctx->ctx;
  2042. mutex_lock(&hdata->hdmi_mutex);
  2043. hdata->hpd = gpio_get_value(hdata->hpd_gpio);
  2044. mutex_unlock(&hdata->hdmi_mutex);
  2045. if (ctx->drm_dev)
  2046. drm_helper_hpd_irq_event(ctx->drm_dev);
  2047. return IRQ_HANDLED;
  2048. }
  2049. static irqreturn_t hdmi_internal_irq_thread(int irq, void *arg)
  2050. {
  2051. struct exynos_drm_hdmi_context *ctx = arg;
  2052. struct hdmi_context *hdata = ctx->ctx;
  2053. u32 intc_flag;
  2054. intc_flag = hdmi_reg_read(hdata, HDMI_INTC_FLAG);
  2055. /* clearing flags for HPD plug/unplug */
  2056. if (intc_flag & HDMI_INTC_FLAG_HPD_UNPLUG) {
  2057. DRM_DEBUG_KMS("unplugged\n");
  2058. hdmi_reg_writemask(hdata, HDMI_INTC_FLAG, ~0,
  2059. HDMI_INTC_FLAG_HPD_UNPLUG);
  2060. }
  2061. if (intc_flag & HDMI_INTC_FLAG_HPD_PLUG) {
  2062. DRM_DEBUG_KMS("plugged\n");
  2063. hdmi_reg_writemask(hdata, HDMI_INTC_FLAG, ~0,
  2064. HDMI_INTC_FLAG_HPD_PLUG);
  2065. }
  2066. if (ctx->drm_dev)
  2067. drm_helper_hpd_irq_event(ctx->drm_dev);
  2068. return IRQ_HANDLED;
  2069. }
  2070. static int hdmi_resources_init(struct hdmi_context *hdata)
  2071. {
  2072. struct device *dev = hdata->dev;
  2073. struct hdmi_resources *res = &hdata->res;
  2074. static char *supply[] = {
  2075. "hdmi-en",
  2076. "vdd",
  2077. "vdd_osc",
  2078. "vdd_pll",
  2079. };
  2080. int i, ret;
  2081. DRM_DEBUG_KMS("HDMI resource init\n");
  2082. memset(res, 0, sizeof(*res));
  2083. /* get clocks, power */
  2084. res->hdmi = devm_clk_get(dev, "hdmi");
  2085. if (IS_ERR_OR_NULL(res->hdmi)) {
  2086. DRM_ERROR("failed to get clock 'hdmi'\n");
  2087. goto fail;
  2088. }
  2089. res->sclk_hdmi = devm_clk_get(dev, "sclk_hdmi");
  2090. if (IS_ERR_OR_NULL(res->sclk_hdmi)) {
  2091. DRM_ERROR("failed to get clock 'sclk_hdmi'\n");
  2092. goto fail;
  2093. }
  2094. res->sclk_pixel = devm_clk_get(dev, "sclk_pixel");
  2095. if (IS_ERR_OR_NULL(res->sclk_pixel)) {
  2096. DRM_ERROR("failed to get clock 'sclk_pixel'\n");
  2097. goto fail;
  2098. }
  2099. res->sclk_hdmiphy = devm_clk_get(dev, "sclk_hdmiphy");
  2100. if (IS_ERR_OR_NULL(res->sclk_hdmiphy)) {
  2101. DRM_ERROR("failed to get clock 'sclk_hdmiphy'\n");
  2102. goto fail;
  2103. }
  2104. res->hdmiphy = devm_clk_get(dev, "hdmiphy");
  2105. if (IS_ERR_OR_NULL(res->hdmiphy)) {
  2106. DRM_ERROR("failed to get clock 'hdmiphy'\n");
  2107. goto fail;
  2108. }
  2109. clk_set_parent(res->sclk_hdmi, res->sclk_pixel);
  2110. res->regul_bulk = devm_kzalloc(dev, ARRAY_SIZE(supply) *
  2111. sizeof(res->regul_bulk[0]), GFP_KERNEL);
  2112. if (!res->regul_bulk) {
  2113. DRM_ERROR("failed to get memory for regulators\n");
  2114. goto fail;
  2115. }
  2116. for (i = 0; i < ARRAY_SIZE(supply); ++i) {
  2117. res->regul_bulk[i].supply = supply[i];
  2118. res->regul_bulk[i].consumer = NULL;
  2119. }
  2120. ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(supply), res->regul_bulk);
  2121. if (ret) {
  2122. DRM_ERROR("failed to get regulators\n");
  2123. goto fail;
  2124. }
  2125. res->regul_count = ARRAY_SIZE(supply);
  2126. return 0;
  2127. fail:
  2128. DRM_ERROR("HDMI resource init - failed\n");
  2129. return -ENODEV;
  2130. }
  2131. static struct i2c_client *hdmi_ddc, *hdmi_hdmiphy;
  2132. void hdmi_attach_ddc_client(struct i2c_client *ddc)
  2133. {
  2134. if (ddc)
  2135. hdmi_ddc = ddc;
  2136. }
  2137. void hdmi_attach_hdmiphy_client(struct i2c_client *hdmiphy)
  2138. {
  2139. if (hdmiphy)
  2140. hdmi_hdmiphy = hdmiphy;
  2141. }
  2142. #ifdef CONFIG_OF
  2143. static struct s5p_hdmi_platform_data *drm_hdmi_dt_parse_pdata
  2144. (struct device *dev)
  2145. {
  2146. struct device_node *np = dev->of_node;
  2147. struct s5p_hdmi_platform_data *pd;
  2148. enum of_gpio_flags flags;
  2149. u32 value;
  2150. pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL);
  2151. if (!pd) {
  2152. DRM_ERROR("memory allocation for pdata failed\n");
  2153. goto err_data;
  2154. }
  2155. if (!of_find_property(np, "hpd-gpio", &value)) {
  2156. DRM_ERROR("no hpd gpio property found\n");
  2157. goto err_data;
  2158. }
  2159. pd->hpd_gpio = of_get_named_gpio_flags(np, "hpd-gpio", 0, &flags);
  2160. return pd;
  2161. err_data:
  2162. return NULL;
  2163. }
  2164. #else
  2165. static struct s5p_hdmi_platform_data *drm_hdmi_dt_parse_pdata
  2166. (struct device *dev)
  2167. {
  2168. return NULL;
  2169. }
  2170. #endif
  2171. static struct platform_device_id hdmi_driver_types[] = {
  2172. {
  2173. .name = "s5pv210-hdmi",
  2174. .driver_data = HDMI_TYPE13,
  2175. }, {
  2176. .name = "exynos4-hdmi",
  2177. .driver_data = HDMI_TYPE13,
  2178. }, {
  2179. .name = "exynos4-hdmi14",
  2180. .driver_data = HDMI_TYPE14,
  2181. }, {
  2182. .name = "exynos5-hdmi",
  2183. .driver_data = HDMI_TYPE14,
  2184. }, {
  2185. /* end node */
  2186. }
  2187. };
  2188. #ifdef CONFIG_OF
  2189. static struct of_device_id hdmi_match_types[] = {
  2190. {
  2191. .compatible = "samsung,exynos5-hdmi",
  2192. .data = (void *)HDMI_TYPE14,
  2193. }, {
  2194. /* end node */
  2195. }
  2196. };
  2197. #endif
  2198. static int hdmi_probe(struct platform_device *pdev)
  2199. {
  2200. struct device *dev = &pdev->dev;
  2201. struct exynos_drm_hdmi_context *drm_hdmi_ctx;
  2202. struct hdmi_context *hdata;
  2203. struct s5p_hdmi_platform_data *pdata;
  2204. struct resource *res;
  2205. int ret;
  2206. DRM_DEBUG_KMS("[%d]\n", __LINE__);
  2207. if (pdev->dev.of_node) {
  2208. pdata = drm_hdmi_dt_parse_pdata(dev);
  2209. if (IS_ERR(pdata)) {
  2210. DRM_ERROR("failed to parse dt\n");
  2211. return PTR_ERR(pdata);
  2212. }
  2213. } else {
  2214. pdata = pdev->dev.platform_data;
  2215. }
  2216. if (!pdata) {
  2217. DRM_ERROR("no platform data specified\n");
  2218. return -EINVAL;
  2219. }
  2220. drm_hdmi_ctx = devm_kzalloc(&pdev->dev, sizeof(*drm_hdmi_ctx),
  2221. GFP_KERNEL);
  2222. if (!drm_hdmi_ctx) {
  2223. DRM_ERROR("failed to allocate common hdmi context.\n");
  2224. return -ENOMEM;
  2225. }
  2226. hdata = devm_kzalloc(&pdev->dev, sizeof(struct hdmi_context),
  2227. GFP_KERNEL);
  2228. if (!hdata) {
  2229. DRM_ERROR("out of memory\n");
  2230. return -ENOMEM;
  2231. }
  2232. mutex_init(&hdata->hdmi_mutex);
  2233. drm_hdmi_ctx->ctx = (void *)hdata;
  2234. hdata->parent_ctx = (void *)drm_hdmi_ctx;
  2235. platform_set_drvdata(pdev, drm_hdmi_ctx);
  2236. if (dev->of_node) {
  2237. const struct of_device_id *match;
  2238. match = of_match_node(of_match_ptr(hdmi_match_types),
  2239. pdev->dev.of_node);
  2240. if (match == NULL)
  2241. return -ENODEV;
  2242. hdata->type = (enum hdmi_type)match->data;
  2243. } else {
  2244. hdata->type = (enum hdmi_type)platform_get_device_id
  2245. (pdev)->driver_data;
  2246. }
  2247. hdata->hpd_gpio = pdata->hpd_gpio;
  2248. hdata->dev = dev;
  2249. ret = hdmi_resources_init(hdata);
  2250. if (ret) {
  2251. DRM_ERROR("hdmi_resources_init failed\n");
  2252. return -EINVAL;
  2253. }
  2254. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  2255. if (!res) {
  2256. DRM_ERROR("failed to find registers\n");
  2257. return -ENOENT;
  2258. }
  2259. hdata->regs = devm_request_and_ioremap(&pdev->dev, res);
  2260. if (!hdata->regs) {
  2261. DRM_ERROR("failed to map registers\n");
  2262. return -ENXIO;
  2263. }
  2264. ret = devm_gpio_request(&pdev->dev, hdata->hpd_gpio, "HPD");
  2265. if (ret) {
  2266. DRM_ERROR("failed to request HPD gpio\n");
  2267. return ret;
  2268. }
  2269. /* DDC i2c driver */
  2270. if (i2c_add_driver(&ddc_driver)) {
  2271. DRM_ERROR("failed to register ddc i2c driver\n");
  2272. return -ENOENT;
  2273. }
  2274. hdata->ddc_port = hdmi_ddc;
  2275. /* hdmiphy i2c driver */
  2276. if (i2c_add_driver(&hdmiphy_driver)) {
  2277. DRM_ERROR("failed to register hdmiphy i2c driver\n");
  2278. ret = -ENOENT;
  2279. goto err_ddc;
  2280. }
  2281. hdata->hdmiphy_port = hdmi_hdmiphy;
  2282. hdata->external_irq = gpio_to_irq(hdata->hpd_gpio);
  2283. if (hdata->external_irq < 0) {
  2284. DRM_ERROR("failed to get GPIO external irq\n");
  2285. ret = hdata->external_irq;
  2286. goto err_hdmiphy;
  2287. }
  2288. hdata->internal_irq = platform_get_irq(pdev, 0);
  2289. if (hdata->internal_irq < 0) {
  2290. DRM_ERROR("failed to get platform internal irq\n");
  2291. ret = hdata->internal_irq;
  2292. goto err_hdmiphy;
  2293. }
  2294. hdata->hpd = gpio_get_value(hdata->hpd_gpio);
  2295. ret = request_threaded_irq(hdata->external_irq, NULL,
  2296. hdmi_external_irq_thread, IRQF_TRIGGER_RISING |
  2297. IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
  2298. "hdmi_external", drm_hdmi_ctx);
  2299. if (ret) {
  2300. DRM_ERROR("failed to register hdmi external interrupt\n");
  2301. goto err_hdmiphy;
  2302. }
  2303. ret = request_threaded_irq(hdata->internal_irq, NULL,
  2304. hdmi_internal_irq_thread, IRQF_ONESHOT,
  2305. "hdmi_internal", drm_hdmi_ctx);
  2306. if (ret) {
  2307. DRM_ERROR("failed to register hdmi internal interrupt\n");
  2308. goto err_free_irq;
  2309. }
  2310. /* Attach HDMI Driver to common hdmi. */
  2311. exynos_hdmi_drv_attach(drm_hdmi_ctx);
  2312. /* register specific callbacks to common hdmi. */
  2313. exynos_hdmi_ops_register(&hdmi_ops);
  2314. pm_runtime_enable(dev);
  2315. return 0;
  2316. err_free_irq:
  2317. free_irq(hdata->external_irq, drm_hdmi_ctx);
  2318. err_hdmiphy:
  2319. i2c_del_driver(&hdmiphy_driver);
  2320. err_ddc:
  2321. i2c_del_driver(&ddc_driver);
  2322. return ret;
  2323. }
  2324. static int hdmi_remove(struct platform_device *pdev)
  2325. {
  2326. struct device *dev = &pdev->dev;
  2327. struct exynos_drm_hdmi_context *ctx = platform_get_drvdata(pdev);
  2328. struct hdmi_context *hdata = ctx->ctx;
  2329. DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
  2330. pm_runtime_disable(dev);
  2331. free_irq(hdata->internal_irq, hdata);
  2332. free_irq(hdata->external_irq, hdata);
  2333. /* hdmiphy i2c driver */
  2334. i2c_del_driver(&hdmiphy_driver);
  2335. /* DDC i2c driver */
  2336. i2c_del_driver(&ddc_driver);
  2337. return 0;
  2338. }
  2339. #ifdef CONFIG_PM_SLEEP
  2340. static int hdmi_suspend(struct device *dev)
  2341. {
  2342. struct exynos_drm_hdmi_context *ctx = get_hdmi_context(dev);
  2343. struct hdmi_context *hdata = ctx->ctx;
  2344. DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
  2345. disable_irq(hdata->internal_irq);
  2346. disable_irq(hdata->external_irq);
  2347. hdata->hpd = false;
  2348. if (ctx->drm_dev)
  2349. drm_helper_hpd_irq_event(ctx->drm_dev);
  2350. if (pm_runtime_suspended(dev)) {
  2351. DRM_DEBUG_KMS("%s : Already suspended\n", __func__);
  2352. return 0;
  2353. }
  2354. hdmi_poweroff(hdata);
  2355. return 0;
  2356. }
  2357. static int hdmi_resume(struct device *dev)
  2358. {
  2359. struct exynos_drm_hdmi_context *ctx = get_hdmi_context(dev);
  2360. struct hdmi_context *hdata = ctx->ctx;
  2361. DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
  2362. hdata->hpd = gpio_get_value(hdata->hpd_gpio);
  2363. enable_irq(hdata->external_irq);
  2364. enable_irq(hdata->internal_irq);
  2365. if (!pm_runtime_suspended(dev)) {
  2366. DRM_DEBUG_KMS("%s : Already resumed\n", __func__);
  2367. return 0;
  2368. }
  2369. hdmi_poweron(hdata);
  2370. return 0;
  2371. }
  2372. #endif
  2373. #ifdef CONFIG_PM_RUNTIME
  2374. static int hdmi_runtime_suspend(struct device *dev)
  2375. {
  2376. struct exynos_drm_hdmi_context *ctx = get_hdmi_context(dev);
  2377. struct hdmi_context *hdata = ctx->ctx;
  2378. DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
  2379. hdmi_poweroff(hdata);
  2380. return 0;
  2381. }
  2382. static int hdmi_runtime_resume(struct device *dev)
  2383. {
  2384. struct exynos_drm_hdmi_context *ctx = get_hdmi_context(dev);
  2385. struct hdmi_context *hdata = ctx->ctx;
  2386. DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
  2387. hdmi_poweron(hdata);
  2388. return 0;
  2389. }
  2390. #endif
  2391. static const struct dev_pm_ops hdmi_pm_ops = {
  2392. SET_SYSTEM_SLEEP_PM_OPS(hdmi_suspend, hdmi_resume)
  2393. SET_RUNTIME_PM_OPS(hdmi_runtime_suspend, hdmi_runtime_resume, NULL)
  2394. };
  2395. struct platform_driver hdmi_driver = {
  2396. .probe = hdmi_probe,
  2397. .remove = hdmi_remove,
  2398. .id_table = hdmi_driver_types,
  2399. .driver = {
  2400. .name = "exynos-hdmi",
  2401. .owner = THIS_MODULE,
  2402. .pm = &hdmi_pm_ops,
  2403. .of_match_table = of_match_ptr(hdmi_match_types),
  2404. },
  2405. };