exynos_hdmi.c 74 KB

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