ite-it66121.c 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) 2020 BayLibre, SAS
  4. * Author: Phong LE <[email protected]>
  5. * Copyright (C) 2018-2019, Artem Mygaiev
  6. * Copyright (C) 2017, Fresco Logic, Incorporated.
  7. *
  8. */
  9. #include <linux/media-bus-format.h>
  10. #include <linux/module.h>
  11. #include <linux/device.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/i2c.h>
  14. #include <linux/bitfield.h>
  15. #include <linux/property.h>
  16. #include <linux/regmap.h>
  17. #include <linux/of_graph.h>
  18. #include <linux/gpio/consumer.h>
  19. #include <linux/pinctrl/consumer.h>
  20. #include <linux/regulator/consumer.h>
  21. #include <drm/drm_atomic_helper.h>
  22. #include <drm/drm_bridge.h>
  23. #include <drm/drm_crtc_helper.h>
  24. #include <drm/drm_edid.h>
  25. #include <drm/drm_modes.h>
  26. #include <drm/drm_print.h>
  27. #include <drm/drm_probe_helper.h>
  28. #include <sound/hdmi-codec.h>
  29. #define IT66121_VENDOR_ID0_REG 0x00
  30. #define IT66121_VENDOR_ID1_REG 0x01
  31. #define IT66121_DEVICE_ID0_REG 0x02
  32. #define IT66121_DEVICE_ID1_REG 0x03
  33. #define IT66121_VENDOR_ID0 0x54
  34. #define IT66121_VENDOR_ID1 0x49
  35. #define IT66121_DEVICE_ID0 0x12
  36. #define IT66121_DEVICE_ID1 0x06
  37. #define IT66121_REVISION_MASK GENMASK(7, 4)
  38. #define IT66121_DEVICE_ID1_MASK GENMASK(3, 0)
  39. #define IT66121_MASTER_SEL_REG 0x10
  40. #define IT66121_MASTER_SEL_HOST BIT(0)
  41. #define IT66121_AFE_DRV_REG 0x61
  42. #define IT66121_AFE_DRV_RST BIT(4)
  43. #define IT66121_AFE_DRV_PWD BIT(5)
  44. #define IT66121_INPUT_MODE_REG 0x70
  45. #define IT66121_INPUT_MODE_RGB (0 << 6)
  46. #define IT66121_INPUT_MODE_YUV422 BIT(6)
  47. #define IT66121_INPUT_MODE_YUV444 (2 << 6)
  48. #define IT66121_INPUT_MODE_CCIR656 BIT(4)
  49. #define IT66121_INPUT_MODE_SYNCEMB BIT(3)
  50. #define IT66121_INPUT_MODE_DDR BIT(2)
  51. #define IT66121_INPUT_CSC_REG 0x72
  52. #define IT66121_INPUT_CSC_ENDITHER BIT(7)
  53. #define IT66121_INPUT_CSC_ENUDFILTER BIT(6)
  54. #define IT66121_INPUT_CSC_DNFREE_GO BIT(5)
  55. #define IT66121_INPUT_CSC_RGB_TO_YUV 0x02
  56. #define IT66121_INPUT_CSC_YUV_TO_RGB 0x03
  57. #define IT66121_INPUT_CSC_NO_CONV 0x00
  58. #define IT66121_AFE_XP_REG 0x62
  59. #define IT66121_AFE_XP_GAINBIT BIT(7)
  60. #define IT66121_AFE_XP_PWDPLL BIT(6)
  61. #define IT66121_AFE_XP_ENI BIT(5)
  62. #define IT66121_AFE_XP_ENO BIT(4)
  63. #define IT66121_AFE_XP_RESETB BIT(3)
  64. #define IT66121_AFE_XP_PWDI BIT(2)
  65. #define IT66121_AFE_IP_REG 0x64
  66. #define IT66121_AFE_IP_GAINBIT BIT(7)
  67. #define IT66121_AFE_IP_PWDPLL BIT(6)
  68. #define IT66121_AFE_IP_CKSEL_05 (0 << 4)
  69. #define IT66121_AFE_IP_CKSEL_1 BIT(4)
  70. #define IT66121_AFE_IP_CKSEL_2 (2 << 4)
  71. #define IT66121_AFE_IP_CKSEL_2OR4 (3 << 4)
  72. #define IT66121_AFE_IP_ER0 BIT(3)
  73. #define IT66121_AFE_IP_RESETB BIT(2)
  74. #define IT66121_AFE_IP_ENC BIT(1)
  75. #define IT66121_AFE_IP_EC1 BIT(0)
  76. #define IT66121_AFE_XP_EC1_REG 0x68
  77. #define IT66121_AFE_XP_EC1_LOWCLK BIT(4)
  78. #define IT66121_SW_RST_REG 0x04
  79. #define IT66121_SW_RST_REF BIT(5)
  80. #define IT66121_SW_RST_AREF BIT(4)
  81. #define IT66121_SW_RST_VID BIT(3)
  82. #define IT66121_SW_RST_AUD BIT(2)
  83. #define IT66121_SW_RST_HDCP BIT(0)
  84. #define IT66121_DDC_COMMAND_REG 0x15
  85. #define IT66121_DDC_COMMAND_BURST_READ 0x0
  86. #define IT66121_DDC_COMMAND_EDID_READ 0x3
  87. #define IT66121_DDC_COMMAND_FIFO_CLR 0x9
  88. #define IT66121_DDC_COMMAND_SCL_PULSE 0xA
  89. #define IT66121_DDC_COMMAND_ABORT 0xF
  90. #define IT66121_HDCP_REG 0x20
  91. #define IT66121_HDCP_CPDESIRED BIT(0)
  92. #define IT66121_HDCP_EN1P1FEAT BIT(1)
  93. #define IT66121_INT_STATUS1_REG 0x06
  94. #define IT66121_INT_STATUS1_AUD_OVF BIT(7)
  95. #define IT66121_INT_STATUS1_DDC_NOACK BIT(5)
  96. #define IT66121_INT_STATUS1_DDC_FIFOERR BIT(4)
  97. #define IT66121_INT_STATUS1_DDC_BUSHANG BIT(2)
  98. #define IT66121_INT_STATUS1_RX_SENS_STATUS BIT(1)
  99. #define IT66121_INT_STATUS1_HPD_STATUS BIT(0)
  100. #define IT66121_DDC_HEADER_REG 0x11
  101. #define IT66121_DDC_HEADER_HDCP 0x74
  102. #define IT66121_DDC_HEADER_EDID 0xA0
  103. #define IT66121_DDC_OFFSET_REG 0x12
  104. #define IT66121_DDC_BYTE_REG 0x13
  105. #define IT66121_DDC_SEGMENT_REG 0x14
  106. #define IT66121_DDC_RD_FIFO_REG 0x17
  107. #define IT66121_CLK_BANK_REG 0x0F
  108. #define IT66121_CLK_BANK_PWROFF_RCLK BIT(6)
  109. #define IT66121_CLK_BANK_PWROFF_ACLK BIT(5)
  110. #define IT66121_CLK_BANK_PWROFF_TXCLK BIT(4)
  111. #define IT66121_CLK_BANK_PWROFF_CRCLK BIT(3)
  112. #define IT66121_CLK_BANK_0 0
  113. #define IT66121_CLK_BANK_1 1
  114. #define IT66121_INT_REG 0x05
  115. #define IT66121_INT_ACTIVE_HIGH BIT(7)
  116. #define IT66121_INT_OPEN_DRAIN BIT(6)
  117. #define IT66121_INT_TX_CLK_OFF BIT(0)
  118. #define IT66121_INT_MASK1_REG 0x09
  119. #define IT66121_INT_MASK1_AUD_OVF BIT(7)
  120. #define IT66121_INT_MASK1_DDC_NOACK BIT(5)
  121. #define IT66121_INT_MASK1_DDC_FIFOERR BIT(4)
  122. #define IT66121_INT_MASK1_DDC_BUSHANG BIT(2)
  123. #define IT66121_INT_MASK1_RX_SENS BIT(1)
  124. #define IT66121_INT_MASK1_HPD BIT(0)
  125. #define IT66121_INT_CLR1_REG 0x0C
  126. #define IT66121_INT_CLR1_PKTACP BIT(7)
  127. #define IT66121_INT_CLR1_PKTNULL BIT(6)
  128. #define IT66121_INT_CLR1_PKTGEN BIT(5)
  129. #define IT66121_INT_CLR1_KSVLISTCHK BIT(4)
  130. #define IT66121_INT_CLR1_AUTHDONE BIT(3)
  131. #define IT66121_INT_CLR1_AUTHFAIL BIT(2)
  132. #define IT66121_INT_CLR1_RX_SENS BIT(1)
  133. #define IT66121_INT_CLR1_HPD BIT(0)
  134. #define IT66121_AV_MUTE_REG 0xC1
  135. #define IT66121_AV_MUTE_ON BIT(0)
  136. #define IT66121_AV_MUTE_BLUESCR BIT(1)
  137. #define IT66121_PKT_CTS_CTRL_REG 0xC5
  138. #define IT66121_PKT_CTS_CTRL_SEL BIT(1)
  139. #define IT66121_PKT_GEN_CTRL_REG 0xC6
  140. #define IT66121_PKT_GEN_CTRL_ON BIT(0)
  141. #define IT66121_PKT_GEN_CTRL_RPT BIT(1)
  142. #define IT66121_AVIINFO_DB1_REG 0x158
  143. #define IT66121_AVIINFO_DB2_REG 0x159
  144. #define IT66121_AVIINFO_DB3_REG 0x15A
  145. #define IT66121_AVIINFO_DB4_REG 0x15B
  146. #define IT66121_AVIINFO_DB5_REG 0x15C
  147. #define IT66121_AVIINFO_CSUM_REG 0x15D
  148. #define IT66121_AVIINFO_DB6_REG 0x15E
  149. #define IT66121_AVIINFO_DB7_REG 0x15F
  150. #define IT66121_AVIINFO_DB8_REG 0x160
  151. #define IT66121_AVIINFO_DB9_REG 0x161
  152. #define IT66121_AVIINFO_DB10_REG 0x162
  153. #define IT66121_AVIINFO_DB11_REG 0x163
  154. #define IT66121_AVIINFO_DB12_REG 0x164
  155. #define IT66121_AVIINFO_DB13_REG 0x165
  156. #define IT66121_AVI_INFO_PKT_REG 0xCD
  157. #define IT66121_AVI_INFO_PKT_ON BIT(0)
  158. #define IT66121_AVI_INFO_PKT_RPT BIT(1)
  159. #define IT66121_HDMI_MODE_REG 0xC0
  160. #define IT66121_HDMI_MODE_HDMI BIT(0)
  161. #define IT66121_SYS_STATUS_REG 0x0E
  162. #define IT66121_SYS_STATUS_ACTIVE_IRQ BIT(7)
  163. #define IT66121_SYS_STATUS_HPDETECT BIT(6)
  164. #define IT66121_SYS_STATUS_SENDECTECT BIT(5)
  165. #define IT66121_SYS_STATUS_VID_STABLE BIT(4)
  166. #define IT66121_SYS_STATUS_AUD_CTS_CLR BIT(1)
  167. #define IT66121_SYS_STATUS_CLEAR_IRQ BIT(0)
  168. #define IT66121_DDC_STATUS_REG 0x16
  169. #define IT66121_DDC_STATUS_TX_DONE BIT(7)
  170. #define IT66121_DDC_STATUS_ACTIVE BIT(6)
  171. #define IT66121_DDC_STATUS_NOACK BIT(5)
  172. #define IT66121_DDC_STATUS_WAIT_BUS BIT(4)
  173. #define IT66121_DDC_STATUS_ARBI_LOSE BIT(3)
  174. #define IT66121_DDC_STATUS_FIFO_FULL BIT(2)
  175. #define IT66121_DDC_STATUS_FIFO_EMPTY BIT(1)
  176. #define IT66121_DDC_STATUS_FIFO_VALID BIT(0)
  177. #define IT66121_EDID_SLEEP_US 20000
  178. #define IT66121_EDID_TIMEOUT_US 200000
  179. #define IT66121_EDID_FIFO_SIZE 32
  180. #define IT66121_CLK_CTRL0_REG 0x58
  181. #define IT66121_CLK_CTRL0_AUTO_OVER_SAMPLING BIT(4)
  182. #define IT66121_CLK_CTRL0_EXT_MCLK_MASK GENMASK(3, 2)
  183. #define IT66121_CLK_CTRL0_EXT_MCLK_128FS (0 << 2)
  184. #define IT66121_CLK_CTRL0_EXT_MCLK_256FS BIT(2)
  185. #define IT66121_CLK_CTRL0_EXT_MCLK_512FS (2 << 2)
  186. #define IT66121_CLK_CTRL0_EXT_MCLK_1024FS (3 << 2)
  187. #define IT66121_CLK_CTRL0_AUTO_IPCLK BIT(0)
  188. #define IT66121_CLK_STATUS1_REG 0x5E
  189. #define IT66121_CLK_STATUS2_REG 0x5F
  190. #define IT66121_AUD_CTRL0_REG 0xE0
  191. #define IT66121_AUD_SWL (3 << 6)
  192. #define IT66121_AUD_16BIT (0 << 6)
  193. #define IT66121_AUD_18BIT BIT(6)
  194. #define IT66121_AUD_20BIT (2 << 6)
  195. #define IT66121_AUD_24BIT (3 << 6)
  196. #define IT66121_AUD_SPDIFTC BIT(5)
  197. #define IT66121_AUD_SPDIF BIT(4)
  198. #define IT66121_AUD_I2S (0 << 4)
  199. #define IT66121_AUD_EN_I2S3 BIT(3)
  200. #define IT66121_AUD_EN_I2S2 BIT(2)
  201. #define IT66121_AUD_EN_I2S1 BIT(1)
  202. #define IT66121_AUD_EN_I2S0 BIT(0)
  203. #define IT66121_AUD_CTRL0_AUD_SEL BIT(4)
  204. #define IT66121_AUD_CTRL1_REG 0xE1
  205. #define IT66121_AUD_FIFOMAP_REG 0xE2
  206. #define IT66121_AUD_CTRL3_REG 0xE3
  207. #define IT66121_AUD_SRCVALID_FLAT_REG 0xE4
  208. #define IT66121_AUD_FLAT_SRC0 BIT(4)
  209. #define IT66121_AUD_FLAT_SRC1 BIT(5)
  210. #define IT66121_AUD_FLAT_SRC2 BIT(6)
  211. #define IT66121_AUD_FLAT_SRC3 BIT(7)
  212. #define IT66121_AUD_HDAUDIO_REG 0xE5
  213. #define IT66121_AUD_PKT_CTS0_REG 0x130
  214. #define IT66121_AUD_PKT_CTS1_REG 0x131
  215. #define IT66121_AUD_PKT_CTS2_REG 0x132
  216. #define IT66121_AUD_PKT_N0_REG 0x133
  217. #define IT66121_AUD_PKT_N1_REG 0x134
  218. #define IT66121_AUD_PKT_N2_REG 0x135
  219. #define IT66121_AUD_CHST_MODE_REG 0x191
  220. #define IT66121_AUD_CHST_CAT_REG 0x192
  221. #define IT66121_AUD_CHST_SRCNUM_REG 0x193
  222. #define IT66121_AUD_CHST_CHTNUM_REG 0x194
  223. #define IT66121_AUD_CHST_CA_FS_REG 0x198
  224. #define IT66121_AUD_CHST_OFS_WL_REG 0x199
  225. #define IT66121_AUD_PKT_CTS_CNT0_REG 0x1A0
  226. #define IT66121_AUD_PKT_CTS_CNT1_REG 0x1A1
  227. #define IT66121_AUD_PKT_CTS_CNT2_REG 0x1A2
  228. #define IT66121_AUD_FS_22P05K 0x4
  229. #define IT66121_AUD_FS_44P1K 0x0
  230. #define IT66121_AUD_FS_88P2K 0x8
  231. #define IT66121_AUD_FS_176P4K 0xC
  232. #define IT66121_AUD_FS_24K 0x6
  233. #define IT66121_AUD_FS_48K 0x2
  234. #define IT66121_AUD_FS_96K 0xA
  235. #define IT66121_AUD_FS_192K 0xE
  236. #define IT66121_AUD_FS_768K 0x9
  237. #define IT66121_AUD_FS_32K 0x3
  238. #define IT66121_AUD_FS_OTHER 0x1
  239. #define IT66121_AUD_SWL_21BIT 0xD
  240. #define IT66121_AUD_SWL_24BIT 0xB
  241. #define IT66121_AUD_SWL_23BIT 0x9
  242. #define IT66121_AUD_SWL_22BIT 0x5
  243. #define IT66121_AUD_SWL_20BIT 0x3
  244. #define IT66121_AUD_SWL_17BIT 0xC
  245. #define IT66121_AUD_SWL_19BIT 0x8
  246. #define IT66121_AUD_SWL_18BIT 0x4
  247. #define IT66121_AUD_SWL_16BIT 0x2
  248. #define IT66121_AUD_SWL_NOT_INDICATED 0x0
  249. #define IT66121_VENDOR_ID0 0x54
  250. #define IT66121_VENDOR_ID1 0x49
  251. #define IT66121_DEVICE_ID0 0x12
  252. #define IT66121_DEVICE_ID1 0x06
  253. #define IT66121_DEVICE_MASK 0x0F
  254. #define IT66121_AFE_CLK_HIGH 80000 /* Khz */
  255. struct it66121_ctx {
  256. struct regmap *regmap;
  257. struct drm_bridge bridge;
  258. struct drm_bridge *next_bridge;
  259. struct drm_connector *connector;
  260. struct device *dev;
  261. struct gpio_desc *gpio_reset;
  262. struct i2c_client *client;
  263. struct regulator_bulk_data supplies[3];
  264. u32 bus_width;
  265. struct mutex lock; /* Protects fields below and device registers */
  266. struct hdmi_avi_infoframe hdmi_avi_infoframe;
  267. struct {
  268. struct platform_device *pdev;
  269. u8 ch_enable;
  270. u8 fs;
  271. u8 swl;
  272. bool auto_cts;
  273. } audio;
  274. };
  275. static const struct regmap_range_cfg it66121_regmap_banks[] = {
  276. {
  277. .name = "it66121",
  278. .range_min = 0x00,
  279. .range_max = 0x1FF,
  280. .selector_reg = IT66121_CLK_BANK_REG,
  281. .selector_mask = 0x1,
  282. .selector_shift = 0,
  283. .window_start = 0x00,
  284. .window_len = 0x100,
  285. },
  286. };
  287. static const struct regmap_config it66121_regmap_config = {
  288. .val_bits = 8,
  289. .reg_bits = 8,
  290. .max_register = 0x1FF,
  291. .ranges = it66121_regmap_banks,
  292. .num_ranges = ARRAY_SIZE(it66121_regmap_banks),
  293. };
  294. static void it66121_hw_reset(struct it66121_ctx *ctx)
  295. {
  296. gpiod_set_value(ctx->gpio_reset, 1);
  297. msleep(20);
  298. gpiod_set_value(ctx->gpio_reset, 0);
  299. }
  300. static inline int ite66121_power_on(struct it66121_ctx *ctx)
  301. {
  302. return regulator_bulk_enable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
  303. }
  304. static inline int ite66121_power_off(struct it66121_ctx *ctx)
  305. {
  306. return regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
  307. }
  308. static inline int it66121_preamble_ddc(struct it66121_ctx *ctx)
  309. {
  310. return regmap_write(ctx->regmap, IT66121_MASTER_SEL_REG, IT66121_MASTER_SEL_HOST);
  311. }
  312. static inline int it66121_fire_afe(struct it66121_ctx *ctx)
  313. {
  314. return regmap_write(ctx->regmap, IT66121_AFE_DRV_REG, 0);
  315. }
  316. /* TOFIX: Handle YCbCr Input & Output */
  317. static int it66121_configure_input(struct it66121_ctx *ctx)
  318. {
  319. int ret;
  320. u8 mode = IT66121_INPUT_MODE_RGB;
  321. if (ctx->bus_width == 12)
  322. mode |= IT66121_INPUT_MODE_DDR;
  323. ret = regmap_write(ctx->regmap, IT66121_INPUT_MODE_REG, mode);
  324. if (ret)
  325. return ret;
  326. return regmap_write(ctx->regmap, IT66121_INPUT_CSC_REG, IT66121_INPUT_CSC_NO_CONV);
  327. }
  328. /**
  329. * it66121_configure_afe() - Configure the analog front end
  330. * @ctx: it66121_ctx object
  331. * @mode: mode to configure
  332. *
  333. * RETURNS:
  334. * zero if success, a negative error code otherwise.
  335. */
  336. static int it66121_configure_afe(struct it66121_ctx *ctx,
  337. const struct drm_display_mode *mode)
  338. {
  339. int ret;
  340. ret = regmap_write(ctx->regmap, IT66121_AFE_DRV_REG,
  341. IT66121_AFE_DRV_RST);
  342. if (ret)
  343. return ret;
  344. if (mode->clock > IT66121_AFE_CLK_HIGH) {
  345. ret = regmap_write_bits(ctx->regmap, IT66121_AFE_XP_REG,
  346. IT66121_AFE_XP_GAINBIT |
  347. IT66121_AFE_XP_ENO,
  348. IT66121_AFE_XP_GAINBIT);
  349. if (ret)
  350. return ret;
  351. ret = regmap_write_bits(ctx->regmap, IT66121_AFE_IP_REG,
  352. IT66121_AFE_IP_GAINBIT |
  353. IT66121_AFE_IP_ER0 |
  354. IT66121_AFE_IP_EC1,
  355. IT66121_AFE_IP_GAINBIT);
  356. if (ret)
  357. return ret;
  358. ret = regmap_write_bits(ctx->regmap, IT66121_AFE_XP_EC1_REG,
  359. IT66121_AFE_XP_EC1_LOWCLK, 0x80);
  360. if (ret)
  361. return ret;
  362. } else {
  363. ret = regmap_write_bits(ctx->regmap, IT66121_AFE_XP_REG,
  364. IT66121_AFE_XP_GAINBIT |
  365. IT66121_AFE_XP_ENO,
  366. IT66121_AFE_XP_ENO);
  367. if (ret)
  368. return ret;
  369. ret = regmap_write_bits(ctx->regmap, IT66121_AFE_IP_REG,
  370. IT66121_AFE_IP_GAINBIT |
  371. IT66121_AFE_IP_ER0 |
  372. IT66121_AFE_IP_EC1, IT66121_AFE_IP_ER0 |
  373. IT66121_AFE_IP_EC1);
  374. if (ret)
  375. return ret;
  376. ret = regmap_write_bits(ctx->regmap, IT66121_AFE_XP_EC1_REG,
  377. IT66121_AFE_XP_EC1_LOWCLK,
  378. IT66121_AFE_XP_EC1_LOWCLK);
  379. if (ret)
  380. return ret;
  381. }
  382. /* Clear reset flags */
  383. ret = regmap_write_bits(ctx->regmap, IT66121_SW_RST_REG,
  384. IT66121_SW_RST_REF | IT66121_SW_RST_VID, 0);
  385. if (ret)
  386. return ret;
  387. return it66121_fire_afe(ctx);
  388. }
  389. static inline int it66121_wait_ddc_ready(struct it66121_ctx *ctx)
  390. {
  391. int ret, val;
  392. u32 busy = IT66121_DDC_STATUS_NOACK | IT66121_DDC_STATUS_WAIT_BUS |
  393. IT66121_DDC_STATUS_ARBI_LOSE;
  394. ret = regmap_read_poll_timeout(ctx->regmap, IT66121_DDC_STATUS_REG, val, true,
  395. IT66121_EDID_SLEEP_US, IT66121_EDID_TIMEOUT_US);
  396. if (ret)
  397. return ret;
  398. if (val & busy)
  399. return -EAGAIN;
  400. return 0;
  401. }
  402. static int it66121_clear_ddc_fifo(struct it66121_ctx *ctx)
  403. {
  404. int ret;
  405. ret = it66121_preamble_ddc(ctx);
  406. if (ret)
  407. return ret;
  408. return regmap_write(ctx->regmap, IT66121_DDC_COMMAND_REG,
  409. IT66121_DDC_COMMAND_FIFO_CLR);
  410. }
  411. static int it66121_abort_ddc_ops(struct it66121_ctx *ctx)
  412. {
  413. int ret;
  414. unsigned int swreset, cpdesire;
  415. ret = regmap_read(ctx->regmap, IT66121_SW_RST_REG, &swreset);
  416. if (ret)
  417. return ret;
  418. ret = regmap_read(ctx->regmap, IT66121_HDCP_REG, &cpdesire);
  419. if (ret)
  420. return ret;
  421. ret = regmap_write(ctx->regmap, IT66121_HDCP_REG,
  422. cpdesire & (~IT66121_HDCP_CPDESIRED & 0xFF));
  423. if (ret)
  424. return ret;
  425. ret = regmap_write(ctx->regmap, IT66121_SW_RST_REG,
  426. (swreset | IT66121_SW_RST_HDCP));
  427. if (ret)
  428. return ret;
  429. ret = it66121_preamble_ddc(ctx);
  430. if (ret)
  431. return ret;
  432. ret = regmap_write(ctx->regmap, IT66121_DDC_COMMAND_REG,
  433. IT66121_DDC_COMMAND_ABORT);
  434. if (ret)
  435. return ret;
  436. return it66121_wait_ddc_ready(ctx);
  437. }
  438. static int it66121_get_edid_block(void *context, u8 *buf,
  439. unsigned int block, size_t len)
  440. {
  441. struct it66121_ctx *ctx = context;
  442. unsigned int val;
  443. int remain = len;
  444. int offset = 0;
  445. int ret, cnt;
  446. offset = (block % 2) * len;
  447. block = block / 2;
  448. ret = regmap_read(ctx->regmap, IT66121_INT_STATUS1_REG, &val);
  449. if (ret)
  450. return ret;
  451. if (val & IT66121_INT_STATUS1_DDC_BUSHANG) {
  452. ret = it66121_abort_ddc_ops(ctx);
  453. if (ret)
  454. return ret;
  455. }
  456. ret = it66121_clear_ddc_fifo(ctx);
  457. if (ret)
  458. return ret;
  459. while (remain > 0) {
  460. cnt = (remain > IT66121_EDID_FIFO_SIZE) ?
  461. IT66121_EDID_FIFO_SIZE : remain;
  462. ret = it66121_preamble_ddc(ctx);
  463. if (ret)
  464. return ret;
  465. ret = regmap_write(ctx->regmap, IT66121_DDC_COMMAND_REG,
  466. IT66121_DDC_COMMAND_FIFO_CLR);
  467. if (ret)
  468. return ret;
  469. ret = it66121_wait_ddc_ready(ctx);
  470. if (ret)
  471. return ret;
  472. ret = regmap_read(ctx->regmap, IT66121_INT_STATUS1_REG, &val);
  473. if (ret)
  474. return ret;
  475. if (val & IT66121_INT_STATUS1_DDC_BUSHANG) {
  476. ret = it66121_abort_ddc_ops(ctx);
  477. if (ret)
  478. return ret;
  479. }
  480. ret = it66121_preamble_ddc(ctx);
  481. if (ret)
  482. return ret;
  483. ret = regmap_write(ctx->regmap, IT66121_DDC_HEADER_REG,
  484. IT66121_DDC_HEADER_EDID);
  485. if (ret)
  486. return ret;
  487. ret = regmap_write(ctx->regmap, IT66121_DDC_OFFSET_REG, offset);
  488. if (ret)
  489. return ret;
  490. ret = regmap_write(ctx->regmap, IT66121_DDC_BYTE_REG, cnt);
  491. if (ret)
  492. return ret;
  493. ret = regmap_write(ctx->regmap, IT66121_DDC_SEGMENT_REG, block);
  494. if (ret)
  495. return ret;
  496. ret = regmap_write(ctx->regmap, IT66121_DDC_COMMAND_REG,
  497. IT66121_DDC_COMMAND_EDID_READ);
  498. if (ret)
  499. return ret;
  500. offset += cnt;
  501. remain -= cnt;
  502. /* Per programming manual, sleep here before emptying the FIFO */
  503. msleep(20);
  504. ret = it66121_wait_ddc_ready(ctx);
  505. if (ret)
  506. return ret;
  507. do {
  508. ret = regmap_read(ctx->regmap, IT66121_DDC_RD_FIFO_REG, &val);
  509. if (ret)
  510. return ret;
  511. *(buf++) = val;
  512. cnt--;
  513. } while (cnt > 0);
  514. }
  515. return 0;
  516. }
  517. static bool it66121_is_hpd_detect(struct it66121_ctx *ctx)
  518. {
  519. int val;
  520. if (regmap_read(ctx->regmap, IT66121_SYS_STATUS_REG, &val))
  521. return false;
  522. return val & IT66121_SYS_STATUS_HPDETECT;
  523. }
  524. static int it66121_bridge_attach(struct drm_bridge *bridge,
  525. enum drm_bridge_attach_flags flags)
  526. {
  527. struct it66121_ctx *ctx = container_of(bridge, struct it66121_ctx, bridge);
  528. int ret;
  529. if (!(flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR))
  530. return -EINVAL;
  531. ret = drm_bridge_attach(bridge->encoder, ctx->next_bridge, bridge, flags);
  532. if (ret)
  533. return ret;
  534. ret = regmap_write_bits(ctx->regmap, IT66121_CLK_BANK_REG,
  535. IT66121_CLK_BANK_PWROFF_RCLK, 0);
  536. if (ret)
  537. return ret;
  538. ret = regmap_write_bits(ctx->regmap, IT66121_INT_REG,
  539. IT66121_INT_TX_CLK_OFF, 0);
  540. if (ret)
  541. return ret;
  542. ret = regmap_write_bits(ctx->regmap, IT66121_AFE_DRV_REG,
  543. IT66121_AFE_DRV_PWD, 0);
  544. if (ret)
  545. return ret;
  546. ret = regmap_write_bits(ctx->regmap, IT66121_AFE_XP_REG,
  547. IT66121_AFE_XP_PWDI | IT66121_AFE_XP_PWDPLL, 0);
  548. if (ret)
  549. return ret;
  550. ret = regmap_write_bits(ctx->regmap, IT66121_AFE_IP_REG,
  551. IT66121_AFE_IP_PWDPLL, 0);
  552. if (ret)
  553. return ret;
  554. ret = regmap_write_bits(ctx->regmap, IT66121_AFE_DRV_REG,
  555. IT66121_AFE_DRV_RST, 0);
  556. if (ret)
  557. return ret;
  558. ret = regmap_write_bits(ctx->regmap, IT66121_AFE_XP_REG,
  559. IT66121_AFE_XP_RESETB, IT66121_AFE_XP_RESETB);
  560. if (ret)
  561. return ret;
  562. ret = regmap_write_bits(ctx->regmap, IT66121_AFE_IP_REG,
  563. IT66121_AFE_IP_RESETB, IT66121_AFE_IP_RESETB);
  564. if (ret)
  565. return ret;
  566. ret = regmap_write_bits(ctx->regmap, IT66121_SW_RST_REG,
  567. IT66121_SW_RST_REF,
  568. IT66121_SW_RST_REF);
  569. if (ret)
  570. return ret;
  571. /* Per programming manual, sleep here for bridge to settle */
  572. msleep(50);
  573. /* Start interrupts */
  574. return regmap_write_bits(ctx->regmap, IT66121_INT_MASK1_REG,
  575. IT66121_INT_MASK1_DDC_NOACK |
  576. IT66121_INT_MASK1_DDC_FIFOERR |
  577. IT66121_INT_MASK1_DDC_BUSHANG, 0);
  578. }
  579. static int it66121_set_mute(struct it66121_ctx *ctx, bool mute)
  580. {
  581. int ret;
  582. unsigned int val = 0;
  583. if (mute)
  584. val = IT66121_AV_MUTE_ON;
  585. ret = regmap_write_bits(ctx->regmap, IT66121_AV_MUTE_REG, IT66121_AV_MUTE_ON, val);
  586. if (ret)
  587. return ret;
  588. return regmap_write(ctx->regmap, IT66121_PKT_GEN_CTRL_REG,
  589. IT66121_PKT_GEN_CTRL_ON | IT66121_PKT_GEN_CTRL_RPT);
  590. }
  591. #define MAX_OUTPUT_SEL_FORMATS 1
  592. static u32 *it66121_bridge_atomic_get_output_bus_fmts(struct drm_bridge *bridge,
  593. struct drm_bridge_state *bridge_state,
  594. struct drm_crtc_state *crtc_state,
  595. struct drm_connector_state *conn_state,
  596. unsigned int *num_output_fmts)
  597. {
  598. u32 *output_fmts;
  599. output_fmts = kcalloc(MAX_OUTPUT_SEL_FORMATS, sizeof(*output_fmts),
  600. GFP_KERNEL);
  601. if (!output_fmts)
  602. return NULL;
  603. /* TOFIX handle more than MEDIA_BUS_FMT_RGB888_1X24 as output format */
  604. output_fmts[0] = MEDIA_BUS_FMT_RGB888_1X24;
  605. *num_output_fmts = 1;
  606. return output_fmts;
  607. }
  608. #define MAX_INPUT_SEL_FORMATS 1
  609. static u32 *it66121_bridge_atomic_get_input_bus_fmts(struct drm_bridge *bridge,
  610. struct drm_bridge_state *bridge_state,
  611. struct drm_crtc_state *crtc_state,
  612. struct drm_connector_state *conn_state,
  613. u32 output_fmt,
  614. unsigned int *num_input_fmts)
  615. {
  616. struct it66121_ctx *ctx = container_of(bridge, struct it66121_ctx, bridge);
  617. u32 *input_fmts;
  618. *num_input_fmts = 0;
  619. input_fmts = kcalloc(MAX_INPUT_SEL_FORMATS, sizeof(*input_fmts),
  620. GFP_KERNEL);
  621. if (!input_fmts)
  622. return NULL;
  623. if (ctx->bus_width == 12)
  624. /* IT66121FN Datasheet specifies Little-Endian ordering */
  625. input_fmts[0] = MEDIA_BUS_FMT_RGB888_2X12_LE;
  626. else
  627. /* TOFIX support more input bus formats in 24bit width */
  628. input_fmts[0] = MEDIA_BUS_FMT_RGB888_1X24;
  629. *num_input_fmts = 1;
  630. return input_fmts;
  631. }
  632. static void it66121_bridge_enable(struct drm_bridge *bridge,
  633. struct drm_bridge_state *bridge_state)
  634. {
  635. struct it66121_ctx *ctx = container_of(bridge, struct it66121_ctx, bridge);
  636. struct drm_atomic_state *state = bridge_state->base.state;
  637. ctx->connector = drm_atomic_get_new_connector_for_encoder(state, bridge->encoder);
  638. it66121_set_mute(ctx, false);
  639. }
  640. static void it66121_bridge_disable(struct drm_bridge *bridge,
  641. struct drm_bridge_state *bridge_state)
  642. {
  643. struct it66121_ctx *ctx = container_of(bridge, struct it66121_ctx, bridge);
  644. it66121_set_mute(ctx, true);
  645. ctx->connector = NULL;
  646. }
  647. static
  648. void it66121_bridge_mode_set(struct drm_bridge *bridge,
  649. const struct drm_display_mode *mode,
  650. const struct drm_display_mode *adjusted_mode)
  651. {
  652. int ret, i;
  653. u8 buf[HDMI_INFOFRAME_SIZE(AVI)];
  654. struct it66121_ctx *ctx = container_of(bridge, struct it66121_ctx, bridge);
  655. const u16 aviinfo_reg[HDMI_AVI_INFOFRAME_SIZE] = {
  656. IT66121_AVIINFO_DB1_REG,
  657. IT66121_AVIINFO_DB2_REG,
  658. IT66121_AVIINFO_DB3_REG,
  659. IT66121_AVIINFO_DB4_REG,
  660. IT66121_AVIINFO_DB5_REG,
  661. IT66121_AVIINFO_DB6_REG,
  662. IT66121_AVIINFO_DB7_REG,
  663. IT66121_AVIINFO_DB8_REG,
  664. IT66121_AVIINFO_DB9_REG,
  665. IT66121_AVIINFO_DB10_REG,
  666. IT66121_AVIINFO_DB11_REG,
  667. IT66121_AVIINFO_DB12_REG,
  668. IT66121_AVIINFO_DB13_REG
  669. };
  670. mutex_lock(&ctx->lock);
  671. hdmi_avi_infoframe_init(&ctx->hdmi_avi_infoframe);
  672. ret = drm_hdmi_avi_infoframe_from_display_mode(&ctx->hdmi_avi_infoframe, ctx->connector,
  673. adjusted_mode);
  674. if (ret) {
  675. DRM_ERROR("Failed to setup AVI infoframe: %d\n", ret);
  676. goto unlock;
  677. }
  678. ret = hdmi_avi_infoframe_pack(&ctx->hdmi_avi_infoframe, buf, sizeof(buf));
  679. if (ret < 0) {
  680. DRM_ERROR("Failed to pack infoframe: %d\n", ret);
  681. goto unlock;
  682. }
  683. /* Write new AVI infoframe packet */
  684. for (i = 0; i < HDMI_AVI_INFOFRAME_SIZE; i++) {
  685. if (regmap_write(ctx->regmap, aviinfo_reg[i], buf[i + HDMI_INFOFRAME_HEADER_SIZE]))
  686. goto unlock;
  687. }
  688. if (regmap_write(ctx->regmap, IT66121_AVIINFO_CSUM_REG, buf[3]))
  689. goto unlock;
  690. /* Enable AVI infoframe */
  691. if (regmap_write(ctx->regmap, IT66121_AVI_INFO_PKT_REG,
  692. IT66121_AVI_INFO_PKT_ON | IT66121_AVI_INFO_PKT_RPT))
  693. goto unlock;
  694. /* Set TX mode to HDMI */
  695. if (regmap_write(ctx->regmap, IT66121_HDMI_MODE_REG, IT66121_HDMI_MODE_HDMI))
  696. goto unlock;
  697. if (regmap_write_bits(ctx->regmap, IT66121_CLK_BANK_REG,
  698. IT66121_CLK_BANK_PWROFF_TXCLK, IT66121_CLK_BANK_PWROFF_TXCLK))
  699. goto unlock;
  700. if (it66121_configure_input(ctx))
  701. goto unlock;
  702. if (it66121_configure_afe(ctx, adjusted_mode))
  703. goto unlock;
  704. regmap_write_bits(ctx->regmap, IT66121_CLK_BANK_REG, IT66121_CLK_BANK_PWROFF_TXCLK, 0);
  705. unlock:
  706. mutex_unlock(&ctx->lock);
  707. }
  708. static enum drm_mode_status it66121_bridge_mode_valid(struct drm_bridge *bridge,
  709. const struct drm_display_info *info,
  710. const struct drm_display_mode *mode)
  711. {
  712. struct it66121_ctx *ctx = container_of(bridge, struct it66121_ctx, bridge);
  713. unsigned long max_clock;
  714. max_clock = (ctx->bus_width == 12) ? 74250 : 148500;
  715. if (mode->clock > max_clock)
  716. return MODE_CLOCK_HIGH;
  717. if (mode->clock < 25000)
  718. return MODE_CLOCK_LOW;
  719. return MODE_OK;
  720. }
  721. static enum drm_connector_status it66121_bridge_detect(struct drm_bridge *bridge)
  722. {
  723. struct it66121_ctx *ctx = container_of(bridge, struct it66121_ctx, bridge);
  724. return it66121_is_hpd_detect(ctx) ? connector_status_connected
  725. : connector_status_disconnected;
  726. }
  727. static void it66121_bridge_hpd_enable(struct drm_bridge *bridge)
  728. {
  729. struct it66121_ctx *ctx = container_of(bridge, struct it66121_ctx, bridge);
  730. int ret;
  731. ret = regmap_write_bits(ctx->regmap, IT66121_INT_MASK1_REG, IT66121_INT_MASK1_HPD, 0);
  732. if (ret)
  733. dev_err(ctx->dev, "failed to enable HPD IRQ\n");
  734. }
  735. static void it66121_bridge_hpd_disable(struct drm_bridge *bridge)
  736. {
  737. struct it66121_ctx *ctx = container_of(bridge, struct it66121_ctx, bridge);
  738. int ret;
  739. ret = regmap_write_bits(ctx->regmap, IT66121_INT_MASK1_REG,
  740. IT66121_INT_MASK1_HPD, IT66121_INT_MASK1_HPD);
  741. if (ret)
  742. dev_err(ctx->dev, "failed to disable HPD IRQ\n");
  743. }
  744. static struct edid *it66121_bridge_get_edid(struct drm_bridge *bridge,
  745. struct drm_connector *connector)
  746. {
  747. struct it66121_ctx *ctx = container_of(bridge, struct it66121_ctx, bridge);
  748. struct edid *edid;
  749. mutex_lock(&ctx->lock);
  750. edid = drm_do_get_edid(connector, it66121_get_edid_block, ctx);
  751. mutex_unlock(&ctx->lock);
  752. return edid;
  753. }
  754. static const struct drm_bridge_funcs it66121_bridge_funcs = {
  755. .atomic_duplicate_state = drm_atomic_helper_bridge_duplicate_state,
  756. .atomic_destroy_state = drm_atomic_helper_bridge_destroy_state,
  757. .atomic_reset = drm_atomic_helper_bridge_reset,
  758. .attach = it66121_bridge_attach,
  759. .atomic_get_output_bus_fmts = it66121_bridge_atomic_get_output_bus_fmts,
  760. .atomic_get_input_bus_fmts = it66121_bridge_atomic_get_input_bus_fmts,
  761. .atomic_enable = it66121_bridge_enable,
  762. .atomic_disable = it66121_bridge_disable,
  763. .mode_set = it66121_bridge_mode_set,
  764. .mode_valid = it66121_bridge_mode_valid,
  765. .detect = it66121_bridge_detect,
  766. .get_edid = it66121_bridge_get_edid,
  767. .hpd_enable = it66121_bridge_hpd_enable,
  768. .hpd_disable = it66121_bridge_hpd_disable,
  769. };
  770. static irqreturn_t it66121_irq_threaded_handler(int irq, void *dev_id)
  771. {
  772. int ret;
  773. unsigned int val;
  774. struct it66121_ctx *ctx = dev_id;
  775. struct device *dev = ctx->dev;
  776. enum drm_connector_status status;
  777. bool event = false;
  778. mutex_lock(&ctx->lock);
  779. ret = regmap_read(ctx->regmap, IT66121_SYS_STATUS_REG, &val);
  780. if (ret)
  781. goto unlock;
  782. if (!(val & IT66121_SYS_STATUS_ACTIVE_IRQ))
  783. goto unlock;
  784. ret = regmap_read(ctx->regmap, IT66121_INT_STATUS1_REG, &val);
  785. if (ret) {
  786. dev_err(dev, "Cannot read STATUS1_REG %d\n", ret);
  787. } else {
  788. if (val & IT66121_INT_STATUS1_DDC_FIFOERR)
  789. it66121_clear_ddc_fifo(ctx);
  790. if (val & (IT66121_INT_STATUS1_DDC_BUSHANG |
  791. IT66121_INT_STATUS1_DDC_NOACK))
  792. it66121_abort_ddc_ops(ctx);
  793. if (val & IT66121_INT_STATUS1_HPD_STATUS) {
  794. regmap_write_bits(ctx->regmap, IT66121_INT_CLR1_REG,
  795. IT66121_INT_CLR1_HPD, IT66121_INT_CLR1_HPD);
  796. status = it66121_is_hpd_detect(ctx) ? connector_status_connected
  797. : connector_status_disconnected;
  798. event = true;
  799. }
  800. }
  801. regmap_write_bits(ctx->regmap, IT66121_SYS_STATUS_REG,
  802. IT66121_SYS_STATUS_CLEAR_IRQ,
  803. IT66121_SYS_STATUS_CLEAR_IRQ);
  804. unlock:
  805. mutex_unlock(&ctx->lock);
  806. if (event)
  807. drm_bridge_hpd_notify(&ctx->bridge, status);
  808. return IRQ_HANDLED;
  809. }
  810. static int it661221_set_chstat(struct it66121_ctx *ctx, u8 iec60958_chstat[])
  811. {
  812. int ret;
  813. ret = regmap_write(ctx->regmap, IT66121_AUD_CHST_MODE_REG, iec60958_chstat[0] & 0x7C);
  814. if (ret)
  815. return ret;
  816. ret = regmap_write(ctx->regmap, IT66121_AUD_CHST_CAT_REG, iec60958_chstat[1]);
  817. if (ret)
  818. return ret;
  819. ret = regmap_write(ctx->regmap, IT66121_AUD_CHST_SRCNUM_REG, iec60958_chstat[2] & 0x0F);
  820. if (ret)
  821. return ret;
  822. ret = regmap_write(ctx->regmap, IT66121_AUD_CHST_CHTNUM_REG,
  823. (iec60958_chstat[2] >> 4) & 0x0F);
  824. if (ret)
  825. return ret;
  826. ret = regmap_write(ctx->regmap, IT66121_AUD_CHST_CA_FS_REG, iec60958_chstat[3]);
  827. if (ret)
  828. return ret;
  829. return regmap_write(ctx->regmap, IT66121_AUD_CHST_OFS_WL_REG, iec60958_chstat[4]);
  830. }
  831. static int it661221_set_lpcm_audio(struct it66121_ctx *ctx, u8 audio_src_num, u8 audio_swl)
  832. {
  833. int ret;
  834. unsigned int audio_enable = 0;
  835. unsigned int audio_format = 0;
  836. switch (audio_swl) {
  837. case 16:
  838. audio_enable |= IT66121_AUD_16BIT;
  839. break;
  840. case 18:
  841. audio_enable |= IT66121_AUD_18BIT;
  842. break;
  843. case 20:
  844. audio_enable |= IT66121_AUD_20BIT;
  845. break;
  846. case 24:
  847. default:
  848. audio_enable |= IT66121_AUD_24BIT;
  849. break;
  850. }
  851. audio_format |= 0x40;
  852. switch (audio_src_num) {
  853. case 4:
  854. audio_enable |= IT66121_AUD_EN_I2S3 | IT66121_AUD_EN_I2S2 |
  855. IT66121_AUD_EN_I2S1 | IT66121_AUD_EN_I2S0;
  856. break;
  857. case 3:
  858. audio_enable |= IT66121_AUD_EN_I2S2 | IT66121_AUD_EN_I2S1 |
  859. IT66121_AUD_EN_I2S0;
  860. break;
  861. case 2:
  862. audio_enable |= IT66121_AUD_EN_I2S1 | IT66121_AUD_EN_I2S0;
  863. break;
  864. case 1:
  865. default:
  866. audio_format &= ~0x40;
  867. audio_enable |= IT66121_AUD_EN_I2S0;
  868. break;
  869. }
  870. audio_format |= 0x01;
  871. ctx->audio.ch_enable = audio_enable;
  872. ret = regmap_write(ctx->regmap, IT66121_AUD_CTRL0_REG, audio_enable & 0xF0);
  873. if (ret)
  874. return ret;
  875. ret = regmap_write(ctx->regmap, IT66121_AUD_CTRL1_REG, audio_format);
  876. if (ret)
  877. return ret;
  878. ret = regmap_write(ctx->regmap, IT66121_AUD_FIFOMAP_REG, 0xE4);
  879. if (ret)
  880. return ret;
  881. ret = regmap_write(ctx->regmap, IT66121_AUD_CTRL3_REG, 0x00);
  882. if (ret)
  883. return ret;
  884. ret = regmap_write(ctx->regmap, IT66121_AUD_SRCVALID_FLAT_REG, 0x00);
  885. if (ret)
  886. return ret;
  887. return regmap_write(ctx->regmap, IT66121_AUD_HDAUDIO_REG, 0x00);
  888. }
  889. static int it661221_set_ncts(struct it66121_ctx *ctx, u8 fs)
  890. {
  891. int ret;
  892. unsigned int n;
  893. switch (fs) {
  894. case IT66121_AUD_FS_32K:
  895. n = 4096;
  896. break;
  897. case IT66121_AUD_FS_44P1K:
  898. n = 6272;
  899. break;
  900. case IT66121_AUD_FS_48K:
  901. n = 6144;
  902. break;
  903. case IT66121_AUD_FS_88P2K:
  904. n = 12544;
  905. break;
  906. case IT66121_AUD_FS_96K:
  907. n = 12288;
  908. break;
  909. case IT66121_AUD_FS_176P4K:
  910. n = 25088;
  911. break;
  912. case IT66121_AUD_FS_192K:
  913. n = 24576;
  914. break;
  915. case IT66121_AUD_FS_768K:
  916. n = 24576;
  917. break;
  918. default:
  919. n = 6144;
  920. break;
  921. }
  922. ret = regmap_write(ctx->regmap, IT66121_AUD_PKT_N0_REG, (u8)((n) & 0xFF));
  923. if (ret)
  924. return ret;
  925. ret = regmap_write(ctx->regmap, IT66121_AUD_PKT_N1_REG, (u8)((n >> 8) & 0xFF));
  926. if (ret)
  927. return ret;
  928. ret = regmap_write(ctx->regmap, IT66121_AUD_PKT_N2_REG, (u8)((n >> 16) & 0xF));
  929. if (ret)
  930. return ret;
  931. if (ctx->audio.auto_cts) {
  932. u8 loop_cnt = 255;
  933. u8 cts_stable_cnt = 0;
  934. unsigned int sum_cts = 0;
  935. unsigned int cts = 0;
  936. unsigned int last_cts = 0;
  937. unsigned int diff;
  938. unsigned int val;
  939. while (loop_cnt--) {
  940. msleep(30);
  941. regmap_read(ctx->regmap, IT66121_AUD_PKT_CTS_CNT2_REG, &val);
  942. cts = val << 12;
  943. regmap_read(ctx->regmap, IT66121_AUD_PKT_CTS_CNT1_REG, &val);
  944. cts |= val << 4;
  945. regmap_read(ctx->regmap, IT66121_AUD_PKT_CTS_CNT0_REG, &val);
  946. cts |= val >> 4;
  947. if (cts == 0) {
  948. continue;
  949. } else {
  950. if (last_cts > cts)
  951. diff = last_cts - cts;
  952. else
  953. diff = cts - last_cts;
  954. last_cts = cts;
  955. if (diff < 5) {
  956. cts_stable_cnt++;
  957. sum_cts += cts;
  958. } else {
  959. cts_stable_cnt = 0;
  960. sum_cts = 0;
  961. continue;
  962. }
  963. if (cts_stable_cnt >= 32) {
  964. last_cts = (sum_cts >> 5);
  965. break;
  966. }
  967. }
  968. }
  969. regmap_write(ctx->regmap, IT66121_AUD_PKT_CTS0_REG, (u8)((last_cts) & 0xFF));
  970. regmap_write(ctx->regmap, IT66121_AUD_PKT_CTS1_REG, (u8)((last_cts >> 8) & 0xFF));
  971. regmap_write(ctx->regmap, IT66121_AUD_PKT_CTS2_REG, (u8)((last_cts >> 16) & 0x0F));
  972. }
  973. ret = regmap_write(ctx->regmap, 0xF8, 0xC3);
  974. if (ret)
  975. return ret;
  976. ret = regmap_write(ctx->regmap, 0xF8, 0xA5);
  977. if (ret)
  978. return ret;
  979. if (ctx->audio.auto_cts) {
  980. ret = regmap_write_bits(ctx->regmap, IT66121_PKT_CTS_CTRL_REG,
  981. IT66121_PKT_CTS_CTRL_SEL,
  982. 1);
  983. } else {
  984. ret = regmap_write_bits(ctx->regmap, IT66121_PKT_CTS_CTRL_REG,
  985. IT66121_PKT_CTS_CTRL_SEL,
  986. 0);
  987. }
  988. if (ret)
  989. return ret;
  990. return regmap_write(ctx->regmap, 0xF8, 0xFF);
  991. }
  992. static int it661221_audio_output_enable(struct it66121_ctx *ctx, bool enable)
  993. {
  994. int ret;
  995. if (enable) {
  996. ret = regmap_write_bits(ctx->regmap, IT66121_SW_RST_REG,
  997. IT66121_SW_RST_AUD | IT66121_SW_RST_AREF,
  998. 0);
  999. if (ret)
  1000. return ret;
  1001. ret = regmap_write_bits(ctx->regmap, IT66121_AUD_CTRL0_REG,
  1002. IT66121_AUD_EN_I2S3 | IT66121_AUD_EN_I2S2 |
  1003. IT66121_AUD_EN_I2S1 | IT66121_AUD_EN_I2S0,
  1004. ctx->audio.ch_enable);
  1005. } else {
  1006. ret = regmap_write_bits(ctx->regmap, IT66121_AUD_CTRL0_REG,
  1007. IT66121_AUD_EN_I2S3 | IT66121_AUD_EN_I2S2 |
  1008. IT66121_AUD_EN_I2S1 | IT66121_AUD_EN_I2S0,
  1009. ctx->audio.ch_enable & 0xF0);
  1010. if (ret)
  1011. return ret;
  1012. ret = regmap_write_bits(ctx->regmap, IT66121_SW_RST_REG,
  1013. IT66121_SW_RST_AUD | IT66121_SW_RST_AREF,
  1014. IT66121_SW_RST_AUD | IT66121_SW_RST_AREF);
  1015. }
  1016. return ret;
  1017. }
  1018. static int it661221_audio_ch_enable(struct it66121_ctx *ctx, bool enable)
  1019. {
  1020. int ret;
  1021. if (enable) {
  1022. ret = regmap_write(ctx->regmap, IT66121_AUD_SRCVALID_FLAT_REG, 0);
  1023. if (ret)
  1024. return ret;
  1025. ret = regmap_write(ctx->regmap, IT66121_AUD_CTRL0_REG, ctx->audio.ch_enable);
  1026. } else {
  1027. ret = regmap_write(ctx->regmap, IT66121_AUD_CTRL0_REG, ctx->audio.ch_enable & 0xF0);
  1028. }
  1029. return ret;
  1030. }
  1031. static int it66121_audio_hw_params(struct device *dev, void *data,
  1032. struct hdmi_codec_daifmt *daifmt,
  1033. struct hdmi_codec_params *params)
  1034. {
  1035. u8 fs;
  1036. u8 swl;
  1037. int ret;
  1038. struct it66121_ctx *ctx = dev_get_drvdata(dev);
  1039. static u8 iec60958_chstat[5];
  1040. unsigned int channels = params->channels;
  1041. unsigned int sample_rate = params->sample_rate;
  1042. unsigned int sample_width = params->sample_width;
  1043. mutex_lock(&ctx->lock);
  1044. dev_dbg(dev, "%s: %u, %u, %u, %u\n", __func__,
  1045. daifmt->fmt, sample_rate, sample_width, channels);
  1046. switch (daifmt->fmt) {
  1047. case HDMI_I2S:
  1048. dev_dbg(dev, "Using HDMI I2S\n");
  1049. break;
  1050. default:
  1051. dev_err(dev, "Invalid or unsupported DAI format %d\n", daifmt->fmt);
  1052. ret = -EINVAL;
  1053. goto out;
  1054. }
  1055. // Set audio clock recovery (N/CTS)
  1056. ret = regmap_write(ctx->regmap, IT66121_CLK_CTRL0_REG,
  1057. IT66121_CLK_CTRL0_AUTO_OVER_SAMPLING |
  1058. IT66121_CLK_CTRL0_EXT_MCLK_256FS |
  1059. IT66121_CLK_CTRL0_AUTO_IPCLK);
  1060. if (ret)
  1061. goto out;
  1062. ret = regmap_write_bits(ctx->regmap, IT66121_AUD_CTRL0_REG,
  1063. IT66121_AUD_CTRL0_AUD_SEL, 0); // remove spdif selection
  1064. if (ret)
  1065. goto out;
  1066. switch (sample_rate) {
  1067. case 44100L:
  1068. fs = IT66121_AUD_FS_44P1K;
  1069. break;
  1070. case 88200L:
  1071. fs = IT66121_AUD_FS_88P2K;
  1072. break;
  1073. case 176400L:
  1074. fs = IT66121_AUD_FS_176P4K;
  1075. break;
  1076. case 32000L:
  1077. fs = IT66121_AUD_FS_32K;
  1078. break;
  1079. case 48000L:
  1080. fs = IT66121_AUD_FS_48K;
  1081. break;
  1082. case 96000L:
  1083. fs = IT66121_AUD_FS_96K;
  1084. break;
  1085. case 192000L:
  1086. fs = IT66121_AUD_FS_192K;
  1087. break;
  1088. case 768000L:
  1089. fs = IT66121_AUD_FS_768K;
  1090. break;
  1091. default:
  1092. fs = IT66121_AUD_FS_48K;
  1093. break;
  1094. }
  1095. ctx->audio.fs = fs;
  1096. ret = it661221_set_ncts(ctx, fs);
  1097. if (ret) {
  1098. dev_err(dev, "Failed to set N/CTS: %d\n", ret);
  1099. goto out;
  1100. }
  1101. // Set audio format register (except audio channel enable)
  1102. ret = it661221_set_lpcm_audio(ctx, (channels + 1) / 2, sample_width);
  1103. if (ret) {
  1104. dev_err(dev, "Failed to set LPCM audio: %d\n", ret);
  1105. goto out;
  1106. }
  1107. // Set audio channel status
  1108. iec60958_chstat[0] = 0;
  1109. if ((channels + 1) / 2 == 1)
  1110. iec60958_chstat[0] |= 0x1;
  1111. iec60958_chstat[0] &= ~(1 << 1);
  1112. iec60958_chstat[1] = 0;
  1113. iec60958_chstat[2] = (channels + 1) / 2;
  1114. iec60958_chstat[2] |= (channels << 4) & 0xF0;
  1115. iec60958_chstat[3] = fs;
  1116. switch (sample_width) {
  1117. case 21L:
  1118. swl = IT66121_AUD_SWL_21BIT;
  1119. break;
  1120. case 24L:
  1121. swl = IT66121_AUD_SWL_24BIT;
  1122. break;
  1123. case 23L:
  1124. swl = IT66121_AUD_SWL_23BIT;
  1125. break;
  1126. case 22L:
  1127. swl = IT66121_AUD_SWL_22BIT;
  1128. break;
  1129. case 20L:
  1130. swl = IT66121_AUD_SWL_20BIT;
  1131. break;
  1132. case 17L:
  1133. swl = IT66121_AUD_SWL_17BIT;
  1134. break;
  1135. case 19L:
  1136. swl = IT66121_AUD_SWL_19BIT;
  1137. break;
  1138. case 18L:
  1139. swl = IT66121_AUD_SWL_18BIT;
  1140. break;
  1141. case 16L:
  1142. swl = IT66121_AUD_SWL_16BIT;
  1143. break;
  1144. default:
  1145. swl = IT66121_AUD_SWL_NOT_INDICATED;
  1146. break;
  1147. }
  1148. iec60958_chstat[4] = (((~fs) << 4) & 0xF0) | swl;
  1149. ret = it661221_set_chstat(ctx, iec60958_chstat);
  1150. if (ret) {
  1151. dev_err(dev, "Failed to set channel status: %d\n", ret);
  1152. goto out;
  1153. }
  1154. // Enable audio channel enable while input clock stable (if SPDIF).
  1155. ret = it661221_audio_ch_enable(ctx, true);
  1156. if (ret) {
  1157. dev_err(dev, "Failed to enable audio channel: %d\n", ret);
  1158. goto out;
  1159. }
  1160. ret = regmap_write_bits(ctx->regmap, IT66121_INT_MASK1_REG,
  1161. IT66121_INT_MASK1_AUD_OVF,
  1162. 0);
  1163. if (ret)
  1164. goto out;
  1165. dev_dbg(dev, "HDMI audio enabled.\n");
  1166. out:
  1167. mutex_unlock(&ctx->lock);
  1168. return ret;
  1169. }
  1170. static int it66121_audio_startup(struct device *dev, void *data)
  1171. {
  1172. int ret;
  1173. struct it66121_ctx *ctx = dev_get_drvdata(dev);
  1174. dev_dbg(dev, "%s\n", __func__);
  1175. mutex_lock(&ctx->lock);
  1176. ret = it661221_audio_output_enable(ctx, true);
  1177. if (ret)
  1178. dev_err(dev, "Failed to enable audio output: %d\n", ret);
  1179. mutex_unlock(&ctx->lock);
  1180. return ret;
  1181. }
  1182. static void it66121_audio_shutdown(struct device *dev, void *data)
  1183. {
  1184. int ret;
  1185. struct it66121_ctx *ctx = dev_get_drvdata(dev);
  1186. dev_dbg(dev, "%s\n", __func__);
  1187. mutex_lock(&ctx->lock);
  1188. ret = it661221_audio_output_enable(ctx, false);
  1189. if (ret)
  1190. dev_err(dev, "Failed to disable audio output: %d\n", ret);
  1191. mutex_unlock(&ctx->lock);
  1192. }
  1193. static int it66121_audio_mute(struct device *dev, void *data,
  1194. bool enable, int direction)
  1195. {
  1196. int ret;
  1197. struct it66121_ctx *ctx = dev_get_drvdata(dev);
  1198. dev_dbg(dev, "%s: enable=%s, direction=%d\n",
  1199. __func__, enable ? "true" : "false", direction);
  1200. mutex_lock(&ctx->lock);
  1201. if (enable) {
  1202. ret = regmap_write_bits(ctx->regmap, IT66121_AUD_SRCVALID_FLAT_REG,
  1203. IT66121_AUD_FLAT_SRC0 | IT66121_AUD_FLAT_SRC1 |
  1204. IT66121_AUD_FLAT_SRC2 | IT66121_AUD_FLAT_SRC3,
  1205. IT66121_AUD_FLAT_SRC0 | IT66121_AUD_FLAT_SRC1 |
  1206. IT66121_AUD_FLAT_SRC2 | IT66121_AUD_FLAT_SRC3);
  1207. } else {
  1208. ret = regmap_write_bits(ctx->regmap, IT66121_AUD_SRCVALID_FLAT_REG,
  1209. IT66121_AUD_FLAT_SRC0 | IT66121_AUD_FLAT_SRC1 |
  1210. IT66121_AUD_FLAT_SRC2 | IT66121_AUD_FLAT_SRC3,
  1211. 0);
  1212. }
  1213. mutex_unlock(&ctx->lock);
  1214. return ret;
  1215. }
  1216. static int it66121_audio_get_eld(struct device *dev, void *data,
  1217. u8 *buf, size_t len)
  1218. {
  1219. struct it66121_ctx *ctx = dev_get_drvdata(dev);
  1220. mutex_lock(&ctx->lock);
  1221. if (!ctx->connector) {
  1222. /* Pass en empty ELD if connector not available */
  1223. dev_dbg(dev, "No connector present, passing empty EDID data");
  1224. memset(buf, 0, len);
  1225. } else {
  1226. memcpy(buf, ctx->connector->eld,
  1227. min(sizeof(ctx->connector->eld), len));
  1228. }
  1229. mutex_unlock(&ctx->lock);
  1230. return 0;
  1231. }
  1232. static const struct hdmi_codec_ops it66121_audio_codec_ops = {
  1233. .hw_params = it66121_audio_hw_params,
  1234. .audio_startup = it66121_audio_startup,
  1235. .audio_shutdown = it66121_audio_shutdown,
  1236. .mute_stream = it66121_audio_mute,
  1237. .get_eld = it66121_audio_get_eld,
  1238. .no_capture_mute = 1,
  1239. };
  1240. static int it66121_audio_codec_init(struct it66121_ctx *ctx, struct device *dev)
  1241. {
  1242. struct hdmi_codec_pdata codec_data = {
  1243. .ops = &it66121_audio_codec_ops,
  1244. .i2s = 1, /* Only i2s support for now */
  1245. .spdif = 0,
  1246. .max_i2s_channels = 8,
  1247. };
  1248. dev_dbg(dev, "%s\n", __func__);
  1249. if (!of_property_read_bool(dev->of_node, "#sound-dai-cells")) {
  1250. dev_info(dev, "No \"#sound-dai-cells\", no audio\n");
  1251. return 0;
  1252. }
  1253. ctx->audio.pdev = platform_device_register_data(dev,
  1254. HDMI_CODEC_DRV_NAME,
  1255. PLATFORM_DEVID_AUTO,
  1256. &codec_data,
  1257. sizeof(codec_data));
  1258. if (IS_ERR(ctx->audio.pdev)) {
  1259. dev_err(dev, "Failed to initialize HDMI audio codec: %d\n",
  1260. PTR_ERR_OR_ZERO(ctx->audio.pdev));
  1261. }
  1262. return PTR_ERR_OR_ZERO(ctx->audio.pdev);
  1263. }
  1264. static int it66121_probe(struct i2c_client *client,
  1265. const struct i2c_device_id *id)
  1266. {
  1267. u32 revision_id, vendor_ids[2] = { 0 }, device_ids[2] = { 0 };
  1268. struct device_node *ep;
  1269. int ret;
  1270. struct it66121_ctx *ctx;
  1271. struct device *dev = &client->dev;
  1272. if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
  1273. dev_err(dev, "I2C check functionality failed.\n");
  1274. return -ENXIO;
  1275. }
  1276. ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
  1277. if (!ctx)
  1278. return -ENOMEM;
  1279. ep = of_graph_get_endpoint_by_regs(dev->of_node, 0, 0);
  1280. if (!ep)
  1281. return -EINVAL;
  1282. ctx->dev = dev;
  1283. ctx->client = client;
  1284. of_property_read_u32(ep, "bus-width", &ctx->bus_width);
  1285. of_node_put(ep);
  1286. if (ctx->bus_width != 12 && ctx->bus_width != 24)
  1287. return -EINVAL;
  1288. ep = of_graph_get_remote_node(dev->of_node, 1, -1);
  1289. if (!ep) {
  1290. dev_err(ctx->dev, "The endpoint is unconnected\n");
  1291. return -EINVAL;
  1292. }
  1293. if (!of_device_is_available(ep)) {
  1294. of_node_put(ep);
  1295. dev_err(ctx->dev, "The remote device is disabled\n");
  1296. return -ENODEV;
  1297. }
  1298. ctx->next_bridge = of_drm_find_bridge(ep);
  1299. of_node_put(ep);
  1300. if (!ctx->next_bridge) {
  1301. dev_dbg(ctx->dev, "Next bridge not found, deferring probe\n");
  1302. return -EPROBE_DEFER;
  1303. }
  1304. i2c_set_clientdata(client, ctx);
  1305. mutex_init(&ctx->lock);
  1306. ctx->supplies[0].supply = "vcn33";
  1307. ctx->supplies[1].supply = "vcn18";
  1308. ctx->supplies[2].supply = "vrf12";
  1309. ret = devm_regulator_bulk_get(ctx->dev, 3, ctx->supplies);
  1310. if (ret) {
  1311. dev_err(ctx->dev, "regulator_bulk failed\n");
  1312. return ret;
  1313. }
  1314. ret = ite66121_power_on(ctx);
  1315. if (ret)
  1316. return ret;
  1317. it66121_hw_reset(ctx);
  1318. ctx->regmap = devm_regmap_init_i2c(client, &it66121_regmap_config);
  1319. if (IS_ERR(ctx->regmap)) {
  1320. ite66121_power_off(ctx);
  1321. return PTR_ERR(ctx->regmap);
  1322. }
  1323. regmap_read(ctx->regmap, IT66121_VENDOR_ID0_REG, &vendor_ids[0]);
  1324. regmap_read(ctx->regmap, IT66121_VENDOR_ID1_REG, &vendor_ids[1]);
  1325. regmap_read(ctx->regmap, IT66121_DEVICE_ID0_REG, &device_ids[0]);
  1326. regmap_read(ctx->regmap, IT66121_DEVICE_ID1_REG, &device_ids[1]);
  1327. /* Revision is shared with DEVICE_ID1 */
  1328. revision_id = FIELD_GET(IT66121_REVISION_MASK, device_ids[1]);
  1329. device_ids[1] &= IT66121_DEVICE_ID1_MASK;
  1330. if (vendor_ids[0] != IT66121_VENDOR_ID0 || vendor_ids[1] != IT66121_VENDOR_ID1 ||
  1331. device_ids[0] != IT66121_DEVICE_ID0 || device_ids[1] != IT66121_DEVICE_ID1) {
  1332. ite66121_power_off(ctx);
  1333. return -ENODEV;
  1334. }
  1335. ctx->bridge.funcs = &it66121_bridge_funcs;
  1336. ctx->bridge.of_node = dev->of_node;
  1337. ctx->bridge.type = DRM_MODE_CONNECTOR_HDMIA;
  1338. ctx->bridge.ops = DRM_BRIDGE_OP_DETECT | DRM_BRIDGE_OP_EDID | DRM_BRIDGE_OP_HPD;
  1339. ret = devm_request_threaded_irq(dev, client->irq, NULL, it66121_irq_threaded_handler,
  1340. IRQF_ONESHOT, dev_name(dev), ctx);
  1341. if (ret < 0) {
  1342. dev_err(dev, "Failed to request irq %d:%d\n", client->irq, ret);
  1343. ite66121_power_off(ctx);
  1344. return ret;
  1345. }
  1346. it66121_audio_codec_init(ctx, dev);
  1347. drm_bridge_add(&ctx->bridge);
  1348. dev_info(ctx->dev, "IT66121 revision %d probed\n", revision_id);
  1349. return 0;
  1350. }
  1351. static void it66121_remove(struct i2c_client *client)
  1352. {
  1353. struct it66121_ctx *ctx = i2c_get_clientdata(client);
  1354. ite66121_power_off(ctx);
  1355. drm_bridge_remove(&ctx->bridge);
  1356. mutex_destroy(&ctx->lock);
  1357. }
  1358. static const struct of_device_id it66121_dt_match[] = {
  1359. { .compatible = "ite,it66121" },
  1360. { }
  1361. };
  1362. MODULE_DEVICE_TABLE(of, it66121_dt_match);
  1363. static const struct i2c_device_id it66121_id[] = {
  1364. { "it66121", 0 },
  1365. { }
  1366. };
  1367. MODULE_DEVICE_TABLE(i2c, it66121_id);
  1368. static struct i2c_driver it66121_driver = {
  1369. .driver = {
  1370. .name = "it66121",
  1371. .of_match_table = it66121_dt_match,
  1372. },
  1373. .probe = it66121_probe,
  1374. .remove = it66121_remove,
  1375. .id_table = it66121_id,
  1376. };
  1377. module_i2c_driver(it66121_driver);
  1378. MODULE_AUTHOR("Phong LE");
  1379. MODULE_DESCRIPTION("IT66121 HDMI transmitter driver");
  1380. MODULE_LICENSE("GPL v2");