exynos_hdmi.c 69 KB

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