exynos_hdmi.c 67 KB

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