tvp5150.c 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614
  1. // SPDX-License-Identifier: GPL-2.0
  2. //
  3. // tvp5150 - Texas Instruments TVP5150A/AM1 and TVP5151 video decoder driver
  4. //
  5. // Copyright (c) 2005,2006 Mauro Carvalho Chehab <mchehab@kernel.org>
  6. #include <dt-bindings/media/tvp5150.h>
  7. #include <linux/i2c.h>
  8. #include <linux/slab.h>
  9. #include <linux/videodev2.h>
  10. #include <linux/delay.h>
  11. #include <linux/gpio/consumer.h>
  12. #include <linux/module.h>
  13. #include <linux/of_graph.h>
  14. #include <media/v4l2-async.h>
  15. #include <media/v4l2-device.h>
  16. #include <media/v4l2-ctrls.h>
  17. #include <media/v4l2-fwnode.h>
  18. #include <media/v4l2-mc.h>
  19. #include "tvp5150_reg.h"
  20. #define TVP5150_H_MAX 720U
  21. #define TVP5150_V_MAX_525_60 480U
  22. #define TVP5150_V_MAX_OTHERS 576U
  23. #define TVP5150_MAX_CROP_LEFT 511
  24. #define TVP5150_MAX_CROP_TOP 127
  25. #define TVP5150_CROP_SHIFT 2
  26. MODULE_DESCRIPTION("Texas Instruments TVP5150A/TVP5150AM1/TVP5151 video decoder driver");
  27. MODULE_AUTHOR("Mauro Carvalho Chehab");
  28. MODULE_LICENSE("GPL v2");
  29. static int debug;
  30. module_param(debug, int, 0644);
  31. MODULE_PARM_DESC(debug, "Debug level (0-2)");
  32. #define dprintk0(__dev, __arg...) dev_dbg_lvl(__dev, 0, 0, __arg)
  33. struct tvp5150 {
  34. struct v4l2_subdev sd;
  35. #ifdef CONFIG_MEDIA_CONTROLLER
  36. struct media_pad pads[DEMOD_NUM_PADS];
  37. struct media_entity input_ent[TVP5150_INPUT_NUM];
  38. struct media_pad input_pad[TVP5150_INPUT_NUM];
  39. #endif
  40. struct v4l2_ctrl_handler hdl;
  41. struct v4l2_rect rect;
  42. v4l2_std_id norm; /* Current set standard */
  43. u32 input;
  44. u32 output;
  45. int enable;
  46. u16 dev_id;
  47. u16 rom_ver;
  48. enum v4l2_mbus_type mbus_type;
  49. };
  50. static inline struct tvp5150 *to_tvp5150(struct v4l2_subdev *sd)
  51. {
  52. return container_of(sd, struct tvp5150, sd);
  53. }
  54. static inline struct v4l2_subdev *to_sd(struct v4l2_ctrl *ctrl)
  55. {
  56. return &container_of(ctrl->handler, struct tvp5150, hdl)->sd;
  57. }
  58. static int tvp5150_read(struct v4l2_subdev *sd, unsigned char addr)
  59. {
  60. struct i2c_client *c = v4l2_get_subdevdata(sd);
  61. int rc;
  62. rc = i2c_smbus_read_byte_data(c, addr);
  63. if (rc < 0) {
  64. dev_err(sd->dev, "i2c i/o error: rc == %d\n", rc);
  65. return rc;
  66. }
  67. dev_dbg_lvl(sd->dev, 2, debug, "tvp5150: read 0x%02x = %02x\n", addr, rc);
  68. return rc;
  69. }
  70. static int tvp5150_write(struct v4l2_subdev *sd, unsigned char addr,
  71. unsigned char value)
  72. {
  73. struct i2c_client *c = v4l2_get_subdevdata(sd);
  74. int rc;
  75. dev_dbg_lvl(sd->dev, 2, debug, "tvp5150: writing %02x %02x\n", addr, value);
  76. rc = i2c_smbus_write_byte_data(c, addr, value);
  77. if (rc < 0)
  78. dev_err(sd->dev, "i2c i/o error: rc == %d\n", rc);
  79. return rc;
  80. }
  81. static void dump_reg_range(struct v4l2_subdev *sd, char *s, u8 init,
  82. const u8 end, int max_line)
  83. {
  84. u8 buf[16];
  85. int i = 0, j, len;
  86. if (max_line > 16) {
  87. dprintk0(sd->dev, "too much data to dump\n");
  88. return;
  89. }
  90. for (i = init; i < end; i += max_line) {
  91. len = (end - i > max_line) ? max_line : end - i;
  92. for (j = 0; j < len; j++)
  93. buf[j] = tvp5150_read(sd, i + j);
  94. dprintk0(sd->dev, "%s reg %02x = %*ph\n", s, i, len, buf);
  95. }
  96. }
  97. static int tvp5150_log_status(struct v4l2_subdev *sd)
  98. {
  99. dprintk0(sd->dev, "tvp5150: Video input source selection #1 = 0x%02x\n",
  100. tvp5150_read(sd, TVP5150_VD_IN_SRC_SEL_1));
  101. dprintk0(sd->dev, "tvp5150: Analog channel controls = 0x%02x\n",
  102. tvp5150_read(sd, TVP5150_ANAL_CHL_CTL));
  103. dprintk0(sd->dev, "tvp5150: Operation mode controls = 0x%02x\n",
  104. tvp5150_read(sd, TVP5150_OP_MODE_CTL));
  105. dprintk0(sd->dev, "tvp5150: Miscellaneous controls = 0x%02x\n",
  106. tvp5150_read(sd, TVP5150_MISC_CTL));
  107. dprintk0(sd->dev, "tvp5150: Autoswitch mask= 0x%02x\n",
  108. tvp5150_read(sd, TVP5150_AUTOSW_MSK));
  109. dprintk0(sd->dev, "tvp5150: Color killer threshold control = 0x%02x\n",
  110. tvp5150_read(sd, TVP5150_COLOR_KIL_THSH_CTL));
  111. dprintk0(sd->dev, "tvp5150: Luminance processing controls #1 #2 and #3 = %02x %02x %02x\n",
  112. tvp5150_read(sd, TVP5150_LUMA_PROC_CTL_1),
  113. tvp5150_read(sd, TVP5150_LUMA_PROC_CTL_2),
  114. tvp5150_read(sd, TVP5150_LUMA_PROC_CTL_3));
  115. dprintk0(sd->dev, "tvp5150: Brightness control = 0x%02x\n",
  116. tvp5150_read(sd, TVP5150_BRIGHT_CTL));
  117. dprintk0(sd->dev, "tvp5150: Color saturation control = 0x%02x\n",
  118. tvp5150_read(sd, TVP5150_SATURATION_CTL));
  119. dprintk0(sd->dev, "tvp5150: Hue control = 0x%02x\n",
  120. tvp5150_read(sd, TVP5150_HUE_CTL));
  121. dprintk0(sd->dev, "tvp5150: Contrast control = 0x%02x\n",
  122. tvp5150_read(sd, TVP5150_CONTRAST_CTL));
  123. dprintk0(sd->dev, "tvp5150: Outputs and data rates select = 0x%02x\n",
  124. tvp5150_read(sd, TVP5150_DATA_RATE_SEL));
  125. dprintk0(sd->dev, "tvp5150: Configuration shared pins = 0x%02x\n",
  126. tvp5150_read(sd, TVP5150_CONF_SHARED_PIN));
  127. dprintk0(sd->dev, "tvp5150: Active video cropping start = 0x%02x%02x\n",
  128. tvp5150_read(sd, TVP5150_ACT_VD_CROP_ST_MSB),
  129. tvp5150_read(sd, TVP5150_ACT_VD_CROP_ST_LSB));
  130. dprintk0(sd->dev, "tvp5150: Active video cropping stop = 0x%02x%02x\n",
  131. tvp5150_read(sd, TVP5150_ACT_VD_CROP_STP_MSB),
  132. tvp5150_read(sd, TVP5150_ACT_VD_CROP_STP_LSB));
  133. dprintk0(sd->dev, "tvp5150: Genlock/RTC = 0x%02x\n",
  134. tvp5150_read(sd, TVP5150_GENLOCK));
  135. dprintk0(sd->dev, "tvp5150: Horizontal sync start = 0x%02x\n",
  136. tvp5150_read(sd, TVP5150_HORIZ_SYNC_START));
  137. dprintk0(sd->dev, "tvp5150: Vertical blanking start = 0x%02x\n",
  138. tvp5150_read(sd, TVP5150_VERT_BLANKING_START));
  139. dprintk0(sd->dev, "tvp5150: Vertical blanking stop = 0x%02x\n",
  140. tvp5150_read(sd, TVP5150_VERT_BLANKING_STOP));
  141. dprintk0(sd->dev, "tvp5150: Chrominance processing control #1 and #2 = %02x %02x\n",
  142. tvp5150_read(sd, TVP5150_CHROMA_PROC_CTL_1),
  143. tvp5150_read(sd, TVP5150_CHROMA_PROC_CTL_2));
  144. dprintk0(sd->dev, "tvp5150: Interrupt reset register B = 0x%02x\n",
  145. tvp5150_read(sd, TVP5150_INT_RESET_REG_B));
  146. dprintk0(sd->dev, "tvp5150: Interrupt enable register B = 0x%02x\n",
  147. tvp5150_read(sd, TVP5150_INT_ENABLE_REG_B));
  148. dprintk0(sd->dev, "tvp5150: Interrupt configuration register B = 0x%02x\n",
  149. tvp5150_read(sd, TVP5150_INTT_CONFIG_REG_B));
  150. dprintk0(sd->dev, "tvp5150: Video standard = 0x%02x\n",
  151. tvp5150_read(sd, TVP5150_VIDEO_STD));
  152. dprintk0(sd->dev, "tvp5150: Chroma gain factor: Cb=0x%02x Cr=0x%02x\n",
  153. tvp5150_read(sd, TVP5150_CB_GAIN_FACT),
  154. tvp5150_read(sd, TVP5150_CR_GAIN_FACTOR));
  155. dprintk0(sd->dev, "tvp5150: Macrovision on counter = 0x%02x\n",
  156. tvp5150_read(sd, TVP5150_MACROVISION_ON_CTR));
  157. dprintk0(sd->dev, "tvp5150: Macrovision off counter = 0x%02x\n",
  158. tvp5150_read(sd, TVP5150_MACROVISION_OFF_CTR));
  159. dprintk0(sd->dev, "tvp5150: ITU-R BT.656.%d timing(TVP5150AM1 only)\n",
  160. (tvp5150_read(sd, TVP5150_REV_SELECT) & 1) ? 3 : 4);
  161. dprintk0(sd->dev, "tvp5150: Device ID = %02x%02x\n",
  162. tvp5150_read(sd, TVP5150_MSB_DEV_ID),
  163. tvp5150_read(sd, TVP5150_LSB_DEV_ID));
  164. dprintk0(sd->dev, "tvp5150: ROM version = (hex) %02x.%02x\n",
  165. tvp5150_read(sd, TVP5150_ROM_MAJOR_VER),
  166. tvp5150_read(sd, TVP5150_ROM_MINOR_VER));
  167. dprintk0(sd->dev, "tvp5150: Vertical line count = 0x%02x%02x\n",
  168. tvp5150_read(sd, TVP5150_VERT_LN_COUNT_MSB),
  169. tvp5150_read(sd, TVP5150_VERT_LN_COUNT_LSB));
  170. dprintk0(sd->dev, "tvp5150: Interrupt status register B = 0x%02x\n",
  171. tvp5150_read(sd, TVP5150_INT_STATUS_REG_B));
  172. dprintk0(sd->dev, "tvp5150: Interrupt active register B = 0x%02x\n",
  173. tvp5150_read(sd, TVP5150_INT_ACTIVE_REG_B));
  174. dprintk0(sd->dev, "tvp5150: Status regs #1 to #5 = %02x %02x %02x %02x %02x\n",
  175. tvp5150_read(sd, TVP5150_STATUS_REG_1),
  176. tvp5150_read(sd, TVP5150_STATUS_REG_2),
  177. tvp5150_read(sd, TVP5150_STATUS_REG_3),
  178. tvp5150_read(sd, TVP5150_STATUS_REG_4),
  179. tvp5150_read(sd, TVP5150_STATUS_REG_5));
  180. dump_reg_range(sd, "Teletext filter 1", TVP5150_TELETEXT_FIL1_INI,
  181. TVP5150_TELETEXT_FIL1_END, 8);
  182. dump_reg_range(sd, "Teletext filter 2", TVP5150_TELETEXT_FIL2_INI,
  183. TVP5150_TELETEXT_FIL2_END, 8);
  184. dprintk0(sd->dev, "tvp5150: Teletext filter enable = 0x%02x\n",
  185. tvp5150_read(sd, TVP5150_TELETEXT_FIL_ENA));
  186. dprintk0(sd->dev, "tvp5150: Interrupt status register A = 0x%02x\n",
  187. tvp5150_read(sd, TVP5150_INT_STATUS_REG_A));
  188. dprintk0(sd->dev, "tvp5150: Interrupt enable register A = 0x%02x\n",
  189. tvp5150_read(sd, TVP5150_INT_ENABLE_REG_A));
  190. dprintk0(sd->dev, "tvp5150: Interrupt configuration = 0x%02x\n",
  191. tvp5150_read(sd, TVP5150_INT_CONF));
  192. dprintk0(sd->dev, "tvp5150: VDP status register = 0x%02x\n",
  193. tvp5150_read(sd, TVP5150_VDP_STATUS_REG));
  194. dprintk0(sd->dev, "tvp5150: FIFO word count = 0x%02x\n",
  195. tvp5150_read(sd, TVP5150_FIFO_WORD_COUNT));
  196. dprintk0(sd->dev, "tvp5150: FIFO interrupt threshold = 0x%02x\n",
  197. tvp5150_read(sd, TVP5150_FIFO_INT_THRESHOLD));
  198. dprintk0(sd->dev, "tvp5150: FIFO reset = 0x%02x\n",
  199. tvp5150_read(sd, TVP5150_FIFO_RESET));
  200. dprintk0(sd->dev, "tvp5150: Line number interrupt = 0x%02x\n",
  201. tvp5150_read(sd, TVP5150_LINE_NUMBER_INT));
  202. dprintk0(sd->dev, "tvp5150: Pixel alignment register = 0x%02x%02x\n",
  203. tvp5150_read(sd, TVP5150_PIX_ALIGN_REG_HIGH),
  204. tvp5150_read(sd, TVP5150_PIX_ALIGN_REG_LOW));
  205. dprintk0(sd->dev, "tvp5150: FIFO output control = 0x%02x\n",
  206. tvp5150_read(sd, TVP5150_FIFO_OUT_CTRL));
  207. dprintk0(sd->dev, "tvp5150: Full field enable = 0x%02x\n",
  208. tvp5150_read(sd, TVP5150_FULL_FIELD_ENA));
  209. dprintk0(sd->dev, "tvp5150: Full field mode register = 0x%02x\n",
  210. tvp5150_read(sd, TVP5150_FULL_FIELD_MODE_REG));
  211. dump_reg_range(sd, "CC data", TVP5150_CC_DATA_INI,
  212. TVP5150_CC_DATA_END, 8);
  213. dump_reg_range(sd, "WSS data", TVP5150_WSS_DATA_INI,
  214. TVP5150_WSS_DATA_END, 8);
  215. dump_reg_range(sd, "VPS data", TVP5150_VPS_DATA_INI,
  216. TVP5150_VPS_DATA_END, 8);
  217. dump_reg_range(sd, "VITC data", TVP5150_VITC_DATA_INI,
  218. TVP5150_VITC_DATA_END, 10);
  219. dump_reg_range(sd, "Line mode", TVP5150_LINE_MODE_INI,
  220. TVP5150_LINE_MODE_END, 8);
  221. return 0;
  222. }
  223. /****************************************************************************
  224. Basic functions
  225. ****************************************************************************/
  226. static void tvp5150_selmux(struct v4l2_subdev *sd)
  227. {
  228. int opmode = 0;
  229. struct tvp5150 *decoder = to_tvp5150(sd);
  230. int input = 0;
  231. int val;
  232. /* Only tvp5150am1 and tvp5151 have signal generator support */
  233. if ((decoder->dev_id == 0x5150 && decoder->rom_ver == 0x0400) ||
  234. (decoder->dev_id == 0x5151 && decoder->rom_ver == 0x0100)) {
  235. if (!decoder->enable)
  236. input = 8;
  237. }
  238. switch (decoder->input) {
  239. case TVP5150_COMPOSITE1:
  240. input |= 2;
  241. /* fall through */
  242. case TVP5150_COMPOSITE0:
  243. break;
  244. case TVP5150_SVIDEO:
  245. default:
  246. input |= 1;
  247. break;
  248. }
  249. dev_dbg_lvl(sd->dev, 1, debug, "Selecting video route: route input=%i, output=%i => tvp5150 input=%i, opmode=%i\n",
  250. decoder->input, decoder->output,
  251. input, opmode);
  252. tvp5150_write(sd, TVP5150_OP_MODE_CTL, opmode);
  253. tvp5150_write(sd, TVP5150_VD_IN_SRC_SEL_1, input);
  254. /*
  255. * Setup the FID/GLCO/VLK/HVLK and INTREQ/GPCL/VBLK output signals. For
  256. * S-Video we output the vertical lock (VLK) signal on FID/GLCO/VLK/HVLK
  257. * and set INTREQ/GPCL/VBLK to logic 0. For composite we output the
  258. * field indicator (FID) signal on FID/GLCO/VLK/HVLK and set
  259. * INTREQ/GPCL/VBLK to logic 1.
  260. */
  261. val = tvp5150_read(sd, TVP5150_MISC_CTL);
  262. if (val < 0) {
  263. dev_err(sd->dev, "%s: failed with error = %d\n", __func__, val);
  264. return;
  265. }
  266. if (decoder->input == TVP5150_SVIDEO)
  267. val = (val & ~TVP5150_MISC_CTL_GPCL) | TVP5150_MISC_CTL_HVLK;
  268. else
  269. val = (val & ~TVP5150_MISC_CTL_HVLK) | TVP5150_MISC_CTL_GPCL;
  270. tvp5150_write(sd, TVP5150_MISC_CTL, val);
  271. };
  272. struct i2c_reg_value {
  273. unsigned char reg;
  274. unsigned char value;
  275. };
  276. /* Default values as sugested at TVP5150AM1 datasheet */
  277. static const struct i2c_reg_value tvp5150_init_default[] = {
  278. { /* 0x00 */
  279. TVP5150_VD_IN_SRC_SEL_1, 0x00
  280. },
  281. { /* 0x01 */
  282. TVP5150_ANAL_CHL_CTL, 0x15
  283. },
  284. { /* 0x02 */
  285. TVP5150_OP_MODE_CTL, 0x00
  286. },
  287. { /* 0x03 */
  288. TVP5150_MISC_CTL, 0x01
  289. },
  290. { /* 0x06 */
  291. TVP5150_COLOR_KIL_THSH_CTL, 0x10
  292. },
  293. { /* 0x07 */
  294. TVP5150_LUMA_PROC_CTL_1, 0x60
  295. },
  296. { /* 0x08 */
  297. TVP5150_LUMA_PROC_CTL_2, 0x00
  298. },
  299. { /* 0x09 */
  300. TVP5150_BRIGHT_CTL, 0x80
  301. },
  302. { /* 0x0a */
  303. TVP5150_SATURATION_CTL, 0x80
  304. },
  305. { /* 0x0b */
  306. TVP5150_HUE_CTL, 0x00
  307. },
  308. { /* 0x0c */
  309. TVP5150_CONTRAST_CTL, 0x80
  310. },
  311. { /* 0x0d */
  312. TVP5150_DATA_RATE_SEL, 0x47
  313. },
  314. { /* 0x0e */
  315. TVP5150_LUMA_PROC_CTL_3, 0x00
  316. },
  317. { /* 0x0f */
  318. TVP5150_CONF_SHARED_PIN, 0x08
  319. },
  320. { /* 0x11 */
  321. TVP5150_ACT_VD_CROP_ST_MSB, 0x00
  322. },
  323. { /* 0x12 */
  324. TVP5150_ACT_VD_CROP_ST_LSB, 0x00
  325. },
  326. { /* 0x13 */
  327. TVP5150_ACT_VD_CROP_STP_MSB, 0x00
  328. },
  329. { /* 0x14 */
  330. TVP5150_ACT_VD_CROP_STP_LSB, 0x00
  331. },
  332. { /* 0x15 */
  333. TVP5150_GENLOCK, 0x01
  334. },
  335. { /* 0x16 */
  336. TVP5150_HORIZ_SYNC_START, 0x80
  337. },
  338. { /* 0x18 */
  339. TVP5150_VERT_BLANKING_START, 0x00
  340. },
  341. { /* 0x19 */
  342. TVP5150_VERT_BLANKING_STOP, 0x00
  343. },
  344. { /* 0x1a */
  345. TVP5150_CHROMA_PROC_CTL_1, 0x0c
  346. },
  347. { /* 0x1b */
  348. TVP5150_CHROMA_PROC_CTL_2, 0x14
  349. },
  350. { /* 0x1c */
  351. TVP5150_INT_RESET_REG_B, 0x00
  352. },
  353. { /* 0x1d */
  354. TVP5150_INT_ENABLE_REG_B, 0x00
  355. },
  356. { /* 0x1e */
  357. TVP5150_INTT_CONFIG_REG_B, 0x00
  358. },
  359. { /* 0x28 */
  360. TVP5150_VIDEO_STD, 0x00
  361. },
  362. { /* 0x2e */
  363. TVP5150_MACROVISION_ON_CTR, 0x0f
  364. },
  365. { /* 0x2f */
  366. TVP5150_MACROVISION_OFF_CTR, 0x01
  367. },
  368. { /* 0xbb */
  369. TVP5150_TELETEXT_FIL_ENA, 0x00
  370. },
  371. { /* 0xc0 */
  372. TVP5150_INT_STATUS_REG_A, 0x00
  373. },
  374. { /* 0xc1 */
  375. TVP5150_INT_ENABLE_REG_A, 0x00
  376. },
  377. { /* 0xc2 */
  378. TVP5150_INT_CONF, 0x04
  379. },
  380. { /* 0xc8 */
  381. TVP5150_FIFO_INT_THRESHOLD, 0x80
  382. },
  383. { /* 0xc9 */
  384. TVP5150_FIFO_RESET, 0x00
  385. },
  386. { /* 0xca */
  387. TVP5150_LINE_NUMBER_INT, 0x00
  388. },
  389. { /* 0xcb */
  390. TVP5150_PIX_ALIGN_REG_LOW, 0x4e
  391. },
  392. { /* 0xcc */
  393. TVP5150_PIX_ALIGN_REG_HIGH, 0x00
  394. },
  395. { /* 0xcd */
  396. TVP5150_FIFO_OUT_CTRL, 0x01
  397. },
  398. { /* 0xcf */
  399. TVP5150_FULL_FIELD_ENA, 0x00
  400. },
  401. { /* 0xd0 */
  402. TVP5150_LINE_MODE_INI, 0x00
  403. },
  404. { /* 0xfc */
  405. TVP5150_FULL_FIELD_MODE_REG, 0x7f
  406. },
  407. { /* end of data */
  408. 0xff, 0xff
  409. }
  410. };
  411. /* Default values as sugested at TVP5150AM1 datasheet */
  412. static const struct i2c_reg_value tvp5150_init_enable[] = {
  413. {
  414. TVP5150_CONF_SHARED_PIN, 2
  415. }, { /* Automatic offset and AGC enabled */
  416. TVP5150_ANAL_CHL_CTL, 0x15
  417. }, { /* Activate YCrCb output 0x9 or 0xd ? */
  418. TVP5150_MISC_CTL, TVP5150_MISC_CTL_GPCL |
  419. TVP5150_MISC_CTL_INTREQ_OE |
  420. TVP5150_MISC_CTL_YCBCR_OE |
  421. TVP5150_MISC_CTL_SYNC_OE |
  422. TVP5150_MISC_CTL_VBLANK |
  423. TVP5150_MISC_CTL_CLOCK_OE,
  424. }, { /* Activates video std autodetection for all standards */
  425. TVP5150_AUTOSW_MSK, 0x0
  426. }, { /* Default format: 0x47. For 4:2:2: 0x40 */
  427. TVP5150_DATA_RATE_SEL, 0x47
  428. }, {
  429. TVP5150_CHROMA_PROC_CTL_1, 0x0c
  430. }, {
  431. TVP5150_CHROMA_PROC_CTL_2, 0x54
  432. }, { /* Non documented, but initialized on WinTV USB2 */
  433. 0x27, 0x20
  434. }, {
  435. 0xff, 0xff
  436. }
  437. };
  438. struct tvp5150_vbi_type {
  439. unsigned int vbi_type;
  440. unsigned int ini_line;
  441. unsigned int end_line;
  442. unsigned int by_field :1;
  443. };
  444. struct i2c_vbi_ram_value {
  445. u16 reg;
  446. struct tvp5150_vbi_type type;
  447. unsigned char values[16];
  448. };
  449. /* This struct have the values for each supported VBI Standard
  450. * by
  451. tvp5150_vbi_types should follow the same order as vbi_ram_default
  452. * value 0 means rom position 0x10, value 1 means rom position 0x30
  453. * and so on. There are 16 possible locations from 0 to 15.
  454. */
  455. static struct i2c_vbi_ram_value vbi_ram_default[] = {
  456. /*
  457. * FIXME: Current api doesn't handle all VBI types, those not
  458. * yet supported are placed under #if 0
  459. */
  460. #if 0
  461. [0] = {0x010, /* Teletext, SECAM, WST System A */
  462. {V4L2_SLICED_TELETEXT_SECAM, 6, 23, 1},
  463. { 0xaa, 0xaa, 0xff, 0xff, 0xe7, 0x2e, 0x20, 0x26,
  464. 0xe6, 0xb4, 0x0e, 0x00, 0x00, 0x00, 0x10, 0x00 }
  465. },
  466. #endif
  467. [1] = {0x030, /* Teletext, PAL, WST System B */
  468. {V4L2_SLICED_TELETEXT_B, 6, 22, 1},
  469. { 0xaa, 0xaa, 0xff, 0xff, 0x27, 0x2e, 0x20, 0x2b,
  470. 0xa6, 0x72, 0x10, 0x00, 0x00, 0x00, 0x10, 0x00 }
  471. },
  472. #if 0
  473. [2] = {0x050, /* Teletext, PAL, WST System C */
  474. {V4L2_SLICED_TELETEXT_PAL_C, 6, 22, 1},
  475. { 0xaa, 0xaa, 0xff, 0xff, 0xe7, 0x2e, 0x20, 0x22,
  476. 0xa6, 0x98, 0x0d, 0x00, 0x00, 0x00, 0x10, 0x00 }
  477. },
  478. [3] = {0x070, /* Teletext, NTSC, WST System B */
  479. {V4L2_SLICED_TELETEXT_NTSC_B, 10, 21, 1},
  480. { 0xaa, 0xaa, 0xff, 0xff, 0x27, 0x2e, 0x20, 0x23,
  481. 0x69, 0x93, 0x0d, 0x00, 0x00, 0x00, 0x10, 0x00 }
  482. },
  483. [4] = {0x090, /* Tetetext, NTSC NABTS System C */
  484. {V4L2_SLICED_TELETEXT_NTSC_C, 10, 21, 1},
  485. { 0xaa, 0xaa, 0xff, 0xff, 0xe7, 0x2e, 0x20, 0x22,
  486. 0x69, 0x93, 0x0d, 0x00, 0x00, 0x00, 0x15, 0x00 }
  487. },
  488. [5] = {0x0b0, /* Teletext, NTSC-J, NABTS System D */
  489. {V4L2_SLICED_TELETEXT_NTSC_D, 10, 21, 1},
  490. { 0xaa, 0xaa, 0xff, 0xff, 0xa7, 0x2e, 0x20, 0x23,
  491. 0x69, 0x93, 0x0d, 0x00, 0x00, 0x00, 0x10, 0x00 }
  492. },
  493. [6] = {0x0d0, /* Closed Caption, PAL/SECAM */
  494. {V4L2_SLICED_CAPTION_625, 22, 22, 1},
  495. { 0xaa, 0x2a, 0xff, 0x3f, 0x04, 0x51, 0x6e, 0x02,
  496. 0xa6, 0x7b, 0x09, 0x00, 0x00, 0x00, 0x27, 0x00 }
  497. },
  498. #endif
  499. [7] = {0x0f0, /* Closed Caption, NTSC */
  500. {V4L2_SLICED_CAPTION_525, 21, 21, 1},
  501. { 0xaa, 0x2a, 0xff, 0x3f, 0x04, 0x51, 0x6e, 0x02,
  502. 0x69, 0x8c, 0x09, 0x00, 0x00, 0x00, 0x27, 0x00 }
  503. },
  504. [8] = {0x110, /* Wide Screen Signal, PAL/SECAM */
  505. {V4L2_SLICED_WSS_625, 23, 23, 1},
  506. { 0x5b, 0x55, 0xc5, 0xff, 0x00, 0x71, 0x6e, 0x42,
  507. 0xa6, 0xcd, 0x0f, 0x00, 0x00, 0x00, 0x3a, 0x00 }
  508. },
  509. #if 0
  510. [9] = {0x130, /* Wide Screen Signal, NTSC C */
  511. {V4L2_SLICED_WSS_525, 20, 20, 1},
  512. { 0x38, 0x00, 0x3f, 0x00, 0x00, 0x71, 0x6e, 0x43,
  513. 0x69, 0x7c, 0x08, 0x00, 0x00, 0x00, 0x39, 0x00 }
  514. },
  515. [10] = {0x150, /* Vertical Interval Timecode (VITC), PAL/SECAM */
  516. {V4l2_SLICED_VITC_625, 6, 22, 0},
  517. { 0x00, 0x00, 0x00, 0x00, 0x00, 0x8f, 0x6d, 0x49,
  518. 0xa6, 0x85, 0x08, 0x00, 0x00, 0x00, 0x4c, 0x00 }
  519. },
  520. [11] = {0x170, /* Vertical Interval Timecode (VITC), NTSC */
  521. {V4l2_SLICED_VITC_525, 10, 20, 0},
  522. { 0x00, 0x00, 0x00, 0x00, 0x00, 0x8f, 0x6d, 0x49,
  523. 0x69, 0x94, 0x08, 0x00, 0x00, 0x00, 0x4c, 0x00 }
  524. },
  525. #endif
  526. [12] = {0x190, /* Video Program System (VPS), PAL */
  527. {V4L2_SLICED_VPS, 16, 16, 0},
  528. { 0xaa, 0xaa, 0xff, 0xff, 0xba, 0xce, 0x2b, 0x0d,
  529. 0xa6, 0xda, 0x0b, 0x00, 0x00, 0x00, 0x60, 0x00 }
  530. },
  531. /* 0x1d0 User programmable */
  532. };
  533. static int tvp5150_write_inittab(struct v4l2_subdev *sd,
  534. const struct i2c_reg_value *regs)
  535. {
  536. while (regs->reg != 0xff) {
  537. tvp5150_write(sd, regs->reg, regs->value);
  538. regs++;
  539. }
  540. return 0;
  541. }
  542. static int tvp5150_vdp_init(struct v4l2_subdev *sd)
  543. {
  544. unsigned int i;
  545. int j;
  546. /* Disable Full Field */
  547. tvp5150_write(sd, TVP5150_FULL_FIELD_ENA, 0);
  548. /* Before programming, Line mode should be at 0xff */
  549. for (i = TVP5150_LINE_MODE_INI; i <= TVP5150_LINE_MODE_END; i++)
  550. tvp5150_write(sd, i, 0xff);
  551. /* Load Ram Table */
  552. for (j = 0; j < ARRAY_SIZE(vbi_ram_default); j++) {
  553. const struct i2c_vbi_ram_value *regs = &vbi_ram_default[j];
  554. if (!regs->type.vbi_type)
  555. continue;
  556. tvp5150_write(sd, TVP5150_CONF_RAM_ADDR_HIGH, regs->reg >> 8);
  557. tvp5150_write(sd, TVP5150_CONF_RAM_ADDR_LOW, regs->reg);
  558. for (i = 0; i < 16; i++)
  559. tvp5150_write(sd, TVP5150_VDP_CONF_RAM_DATA, regs->values[i]);
  560. }
  561. return 0;
  562. }
  563. /* Fills VBI capabilities based on i2c_vbi_ram_value struct */
  564. static int tvp5150_g_sliced_vbi_cap(struct v4l2_subdev *sd,
  565. struct v4l2_sliced_vbi_cap *cap)
  566. {
  567. int line, i;
  568. dev_dbg_lvl(sd->dev, 1, debug, "g_sliced_vbi_cap\n");
  569. memset(cap, 0, sizeof(*cap));
  570. for (i = 0; i < ARRAY_SIZE(vbi_ram_default); i++) {
  571. const struct i2c_vbi_ram_value *regs = &vbi_ram_default[i];
  572. if (!regs->type.vbi_type)
  573. continue;
  574. for (line = regs->type.ini_line;
  575. line <= regs->type.end_line;
  576. line++) {
  577. cap->service_lines[0][line] |= regs->type.vbi_type;
  578. }
  579. cap->service_set |= regs->type.vbi_type;
  580. }
  581. return 0;
  582. }
  583. /* Set vbi processing
  584. * type - one of tvp5150_vbi_types
  585. * line - line to gather data
  586. * fields: bit 0 field1, bit 1, field2
  587. * flags (default=0xf0) is a bitmask, were set means:
  588. * bit 7: enable filtering null bytes on CC
  589. * bit 6: send data also to FIFO
  590. * bit 5: don't allow data with errors on FIFO
  591. * bit 4: enable ECC when possible
  592. * pix_align = pix alignment:
  593. * LSB = field1
  594. * MSB = field2
  595. */
  596. static int tvp5150_set_vbi(struct v4l2_subdev *sd,
  597. unsigned int type, u8 flags, int line,
  598. const int fields)
  599. {
  600. struct tvp5150 *decoder = to_tvp5150(sd);
  601. v4l2_std_id std = decoder->norm;
  602. u8 reg;
  603. int i, pos = 0;
  604. if (std == V4L2_STD_ALL) {
  605. dev_err(sd->dev, "VBI can't be configured without knowing number of lines\n");
  606. return 0;
  607. } else if (std & V4L2_STD_625_50) {
  608. /* Don't follow NTSC Line number convension */
  609. line += 3;
  610. }
  611. if (line < 6 || line > 27)
  612. return 0;
  613. for (i = 0; i < ARRAY_SIZE(vbi_ram_default); i++) {
  614. const struct i2c_vbi_ram_value *regs = &vbi_ram_default[i];
  615. if (!regs->type.vbi_type)
  616. continue;
  617. if ((type & regs->type.vbi_type) &&
  618. (line >= regs->type.ini_line) &&
  619. (line <= regs->type.end_line))
  620. break;
  621. pos++;
  622. }
  623. type = pos | (flags & 0xf0);
  624. reg = ((line - 6) << 1) + TVP5150_LINE_MODE_INI;
  625. if (fields & 1)
  626. tvp5150_write(sd, reg, type);
  627. if (fields & 2)
  628. tvp5150_write(sd, reg + 1, type);
  629. return type;
  630. }
  631. static int tvp5150_get_vbi(struct v4l2_subdev *sd, int line)
  632. {
  633. struct tvp5150 *decoder = to_tvp5150(sd);
  634. v4l2_std_id std = decoder->norm;
  635. u8 reg;
  636. int pos, type = 0;
  637. int i, ret = 0;
  638. if (std == V4L2_STD_ALL) {
  639. dev_err(sd->dev, "VBI can't be configured without knowing number of lines\n");
  640. return 0;
  641. } else if (std & V4L2_STD_625_50) {
  642. /* Don't follow NTSC Line number convension */
  643. line += 3;
  644. }
  645. if (line < 6 || line > 27)
  646. return 0;
  647. reg = ((line - 6) << 1) + TVP5150_LINE_MODE_INI;
  648. for (i = 0; i <= 1; i++) {
  649. ret = tvp5150_read(sd, reg + i);
  650. if (ret < 0) {
  651. dev_err(sd->dev, "%s: failed with error = %d\n",
  652. __func__, ret);
  653. return 0;
  654. }
  655. pos = ret & 0x0f;
  656. if (pos < ARRAY_SIZE(vbi_ram_default))
  657. type |= vbi_ram_default[pos].type.vbi_type;
  658. }
  659. return type;
  660. }
  661. static int tvp5150_set_std(struct v4l2_subdev *sd, v4l2_std_id std)
  662. {
  663. struct tvp5150 *decoder = to_tvp5150(sd);
  664. int fmt = 0;
  665. decoder->norm = std;
  666. /* First tests should be against specific std */
  667. if (std == V4L2_STD_NTSC_443) {
  668. fmt = VIDEO_STD_NTSC_4_43_BIT;
  669. } else if (std == V4L2_STD_PAL_M) {
  670. fmt = VIDEO_STD_PAL_M_BIT;
  671. } else if (std == V4L2_STD_PAL_N || std == V4L2_STD_PAL_Nc) {
  672. fmt = VIDEO_STD_PAL_COMBINATION_N_BIT;
  673. } else {
  674. /* Then, test against generic ones */
  675. if (std & V4L2_STD_NTSC)
  676. fmt = VIDEO_STD_NTSC_MJ_BIT;
  677. else if (std & V4L2_STD_PAL)
  678. fmt = VIDEO_STD_PAL_BDGHIN_BIT;
  679. else if (std & V4L2_STD_SECAM)
  680. fmt = VIDEO_STD_SECAM_BIT;
  681. }
  682. dev_dbg_lvl(sd->dev, 1, debug, "Set video std register to %d.\n", fmt);
  683. tvp5150_write(sd, TVP5150_VIDEO_STD, fmt);
  684. return 0;
  685. }
  686. static int tvp5150_s_std(struct v4l2_subdev *sd, v4l2_std_id std)
  687. {
  688. struct tvp5150 *decoder = to_tvp5150(sd);
  689. if (decoder->norm == std)
  690. return 0;
  691. /* Change cropping height limits */
  692. if (std & V4L2_STD_525_60)
  693. decoder->rect.height = TVP5150_V_MAX_525_60;
  694. else
  695. decoder->rect.height = TVP5150_V_MAX_OTHERS;
  696. return tvp5150_set_std(sd, std);
  697. }
  698. static int tvp5150_reset(struct v4l2_subdev *sd, u32 val)
  699. {
  700. struct tvp5150 *decoder = to_tvp5150(sd);
  701. /* Initializes TVP5150 to its default values */
  702. tvp5150_write_inittab(sd, tvp5150_init_default);
  703. /* Initializes VDP registers */
  704. tvp5150_vdp_init(sd);
  705. /* Selects decoder input */
  706. tvp5150_selmux(sd);
  707. /* Initializes TVP5150 to stream enabled values */
  708. tvp5150_write_inittab(sd, tvp5150_init_enable);
  709. /* Initialize image preferences */
  710. v4l2_ctrl_handler_setup(&decoder->hdl);
  711. tvp5150_set_std(sd, decoder->norm);
  712. if (decoder->mbus_type == V4L2_MBUS_PARALLEL)
  713. tvp5150_write(sd, TVP5150_DATA_RATE_SEL, 0x40);
  714. return 0;
  715. };
  716. static int tvp5150_s_ctrl(struct v4l2_ctrl *ctrl)
  717. {
  718. struct v4l2_subdev *sd = to_sd(ctrl);
  719. struct tvp5150 *decoder = to_tvp5150(sd);
  720. switch (ctrl->id) {
  721. case V4L2_CID_BRIGHTNESS:
  722. tvp5150_write(sd, TVP5150_BRIGHT_CTL, ctrl->val);
  723. return 0;
  724. case V4L2_CID_CONTRAST:
  725. tvp5150_write(sd, TVP5150_CONTRAST_CTL, ctrl->val);
  726. return 0;
  727. case V4L2_CID_SATURATION:
  728. tvp5150_write(sd, TVP5150_SATURATION_CTL, ctrl->val);
  729. return 0;
  730. case V4L2_CID_HUE:
  731. tvp5150_write(sd, TVP5150_HUE_CTL, ctrl->val);
  732. return 0;
  733. case V4L2_CID_TEST_PATTERN:
  734. decoder->enable = ctrl->val ? false : true;
  735. tvp5150_selmux(sd);
  736. return 0;
  737. }
  738. return -EINVAL;
  739. }
  740. static v4l2_std_id tvp5150_read_std(struct v4l2_subdev *sd)
  741. {
  742. int val = tvp5150_read(sd, TVP5150_STATUS_REG_5);
  743. switch (val & 0x0F) {
  744. case 0x01:
  745. return V4L2_STD_NTSC;
  746. case 0x03:
  747. return V4L2_STD_PAL;
  748. case 0x05:
  749. return V4L2_STD_PAL_M;
  750. case 0x07:
  751. return V4L2_STD_PAL_N | V4L2_STD_PAL_Nc;
  752. case 0x09:
  753. return V4L2_STD_NTSC_443;
  754. case 0xb:
  755. return V4L2_STD_SECAM;
  756. default:
  757. return V4L2_STD_UNKNOWN;
  758. }
  759. }
  760. static int tvp5150_fill_fmt(struct v4l2_subdev *sd,
  761. struct v4l2_subdev_pad_config *cfg,
  762. struct v4l2_subdev_format *format)
  763. {
  764. struct v4l2_mbus_framefmt *f;
  765. struct tvp5150 *decoder = to_tvp5150(sd);
  766. if (!format || (format->pad != DEMOD_PAD_VID_OUT))
  767. return -EINVAL;
  768. f = &format->format;
  769. f->width = decoder->rect.width;
  770. f->height = decoder->rect.height / 2;
  771. f->code = MEDIA_BUS_FMT_UYVY8_2X8;
  772. f->field = V4L2_FIELD_ALTERNATE;
  773. f->colorspace = V4L2_COLORSPACE_SMPTE170M;
  774. dev_dbg_lvl(sd->dev, 1, debug, "width = %d, height = %d\n", f->width,
  775. f->height);
  776. return 0;
  777. }
  778. static int tvp5150_set_selection(struct v4l2_subdev *sd,
  779. struct v4l2_subdev_pad_config *cfg,
  780. struct v4l2_subdev_selection *sel)
  781. {
  782. struct tvp5150 *decoder = to_tvp5150(sd);
  783. struct v4l2_rect rect = sel->r;
  784. v4l2_std_id std;
  785. int hmax;
  786. if (sel->which != V4L2_SUBDEV_FORMAT_ACTIVE ||
  787. sel->target != V4L2_SEL_TGT_CROP)
  788. return -EINVAL;
  789. dev_dbg_lvl(sd->dev, 1, debug, "%s left=%d, top=%d, width=%d, height=%d\n",
  790. __func__, rect.left, rect.top, rect.width, rect.height);
  791. /* tvp5150 has some special limits */
  792. rect.left = clamp(rect.left, 0, TVP5150_MAX_CROP_LEFT);
  793. rect.top = clamp(rect.top, 0, TVP5150_MAX_CROP_TOP);
  794. /* Calculate height based on current standard */
  795. if (decoder->norm == V4L2_STD_ALL)
  796. std = tvp5150_read_std(sd);
  797. else
  798. std = decoder->norm;
  799. if (std & V4L2_STD_525_60)
  800. hmax = TVP5150_V_MAX_525_60;
  801. else
  802. hmax = TVP5150_V_MAX_OTHERS;
  803. /*
  804. * alignments:
  805. * - width = 2 due to UYVY colorspace
  806. * - height, image = no special alignment
  807. */
  808. v4l_bound_align_image(&rect.width,
  809. TVP5150_H_MAX - TVP5150_MAX_CROP_LEFT - rect.left,
  810. TVP5150_H_MAX - rect.left, 1, &rect.height,
  811. hmax - TVP5150_MAX_CROP_TOP - rect.top,
  812. hmax - rect.top, 0, 0);
  813. tvp5150_write(sd, TVP5150_VERT_BLANKING_START, rect.top);
  814. tvp5150_write(sd, TVP5150_VERT_BLANKING_STOP,
  815. rect.top + rect.height - hmax);
  816. tvp5150_write(sd, TVP5150_ACT_VD_CROP_ST_MSB,
  817. rect.left >> TVP5150_CROP_SHIFT);
  818. tvp5150_write(sd, TVP5150_ACT_VD_CROP_ST_LSB,
  819. rect.left | (1 << TVP5150_CROP_SHIFT));
  820. tvp5150_write(sd, TVP5150_ACT_VD_CROP_STP_MSB,
  821. (rect.left + rect.width - TVP5150_MAX_CROP_LEFT) >>
  822. TVP5150_CROP_SHIFT);
  823. tvp5150_write(sd, TVP5150_ACT_VD_CROP_STP_LSB,
  824. rect.left + rect.width - TVP5150_MAX_CROP_LEFT);
  825. decoder->rect = rect;
  826. return 0;
  827. }
  828. static int tvp5150_get_selection(struct v4l2_subdev *sd,
  829. struct v4l2_subdev_pad_config *cfg,
  830. struct v4l2_subdev_selection *sel)
  831. {
  832. struct tvp5150 *decoder = container_of(sd, struct tvp5150, sd);
  833. v4l2_std_id std;
  834. if (sel->which != V4L2_SUBDEV_FORMAT_ACTIVE)
  835. return -EINVAL;
  836. switch (sel->target) {
  837. case V4L2_SEL_TGT_CROP_BOUNDS:
  838. case V4L2_SEL_TGT_CROP_DEFAULT:
  839. sel->r.left = 0;
  840. sel->r.top = 0;
  841. sel->r.width = TVP5150_H_MAX;
  842. /* Calculate height based on current standard */
  843. if (decoder->norm == V4L2_STD_ALL)
  844. std = tvp5150_read_std(sd);
  845. else
  846. std = decoder->norm;
  847. if (std & V4L2_STD_525_60)
  848. sel->r.height = TVP5150_V_MAX_525_60;
  849. else
  850. sel->r.height = TVP5150_V_MAX_OTHERS;
  851. return 0;
  852. case V4L2_SEL_TGT_CROP:
  853. sel->r = decoder->rect;
  854. return 0;
  855. default:
  856. return -EINVAL;
  857. }
  858. }
  859. static int tvp5150_g_mbus_config(struct v4l2_subdev *sd,
  860. struct v4l2_mbus_config *cfg)
  861. {
  862. struct tvp5150 *decoder = to_tvp5150(sd);
  863. cfg->type = decoder->mbus_type;
  864. cfg->flags = V4L2_MBUS_MASTER | V4L2_MBUS_PCLK_SAMPLE_RISING
  865. | V4L2_MBUS_FIELD_EVEN_LOW | V4L2_MBUS_DATA_ACTIVE_HIGH;
  866. return 0;
  867. }
  868. /****************************************************************************
  869. V4L2 subdev pad ops
  870. ****************************************************************************/
  871. static int tvp5150_enum_mbus_code(struct v4l2_subdev *sd,
  872. struct v4l2_subdev_pad_config *cfg,
  873. struct v4l2_subdev_mbus_code_enum *code)
  874. {
  875. if (code->pad || code->index)
  876. return -EINVAL;
  877. code->code = MEDIA_BUS_FMT_UYVY8_2X8;
  878. return 0;
  879. }
  880. static int tvp5150_enum_frame_size(struct v4l2_subdev *sd,
  881. struct v4l2_subdev_pad_config *cfg,
  882. struct v4l2_subdev_frame_size_enum *fse)
  883. {
  884. struct tvp5150 *decoder = to_tvp5150(sd);
  885. if (fse->index >= 8 || fse->code != MEDIA_BUS_FMT_UYVY8_2X8)
  886. return -EINVAL;
  887. fse->code = MEDIA_BUS_FMT_UYVY8_2X8;
  888. fse->min_width = decoder->rect.width;
  889. fse->max_width = decoder->rect.width;
  890. fse->min_height = decoder->rect.height / 2;
  891. fse->max_height = decoder->rect.height / 2;
  892. return 0;
  893. }
  894. /****************************************************************************
  895. Media entity ops
  896. ****************************************************************************/
  897. #ifdef CONFIG_MEDIA_CONTROLLER
  898. static int tvp5150_link_setup(struct media_entity *entity,
  899. const struct media_pad *local,
  900. const struct media_pad *remote, u32 flags)
  901. {
  902. struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
  903. struct tvp5150 *decoder = to_tvp5150(sd);
  904. int i;
  905. for (i = 0; i < TVP5150_INPUT_NUM; i++) {
  906. if (remote->entity == &decoder->input_ent[i])
  907. break;
  908. }
  909. /* Do nothing for entities that are not input connectors */
  910. if (i == TVP5150_INPUT_NUM)
  911. return 0;
  912. decoder->input = i;
  913. tvp5150_selmux(sd);
  914. return 0;
  915. }
  916. static const struct media_entity_operations tvp5150_sd_media_ops = {
  917. .link_setup = tvp5150_link_setup,
  918. };
  919. #endif
  920. /****************************************************************************
  921. I2C Command
  922. ****************************************************************************/
  923. static int tvp5150_s_stream(struct v4l2_subdev *sd, int enable)
  924. {
  925. struct tvp5150 *decoder = to_tvp5150(sd);
  926. int val;
  927. /* Enable or disable the video output signals. */
  928. val = tvp5150_read(sd, TVP5150_MISC_CTL);
  929. if (val < 0)
  930. return val;
  931. val &= ~(TVP5150_MISC_CTL_YCBCR_OE | TVP5150_MISC_CTL_SYNC_OE |
  932. TVP5150_MISC_CTL_CLOCK_OE);
  933. if (enable) {
  934. /*
  935. * Enable the YCbCr and clock outputs. In discrete sync mode
  936. * (non-BT.656) additionally enable the the sync outputs.
  937. */
  938. val |= TVP5150_MISC_CTL_YCBCR_OE | TVP5150_MISC_CTL_CLOCK_OE;
  939. if (decoder->mbus_type == V4L2_MBUS_PARALLEL)
  940. val |= TVP5150_MISC_CTL_SYNC_OE;
  941. }
  942. tvp5150_write(sd, TVP5150_MISC_CTL, val);
  943. return 0;
  944. }
  945. static int tvp5150_s_routing(struct v4l2_subdev *sd,
  946. u32 input, u32 output, u32 config)
  947. {
  948. struct tvp5150 *decoder = to_tvp5150(sd);
  949. decoder->input = input;
  950. decoder->output = output;
  951. if (output == TVP5150_BLACK_SCREEN)
  952. decoder->enable = false;
  953. else
  954. decoder->enable = true;
  955. tvp5150_selmux(sd);
  956. return 0;
  957. }
  958. static int tvp5150_s_raw_fmt(struct v4l2_subdev *sd, struct v4l2_vbi_format *fmt)
  959. {
  960. /*
  961. * this is for capturing 36 raw vbi lines
  962. * if there's a way to cut off the beginning 2 vbi lines
  963. * with the tvp5150 then the vbi line count could be lowered
  964. * to 17 lines/field again, although I couldn't find a register
  965. * which could do that cropping
  966. */
  967. if (fmt->sample_format == V4L2_PIX_FMT_GREY)
  968. tvp5150_write(sd, TVP5150_LUMA_PROC_CTL_1, 0x70);
  969. if (fmt->count[0] == 18 && fmt->count[1] == 18) {
  970. tvp5150_write(sd, TVP5150_VERT_BLANKING_START, 0x00);
  971. tvp5150_write(sd, TVP5150_VERT_BLANKING_STOP, 0x01);
  972. }
  973. return 0;
  974. }
  975. static int tvp5150_s_sliced_fmt(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *svbi)
  976. {
  977. int i;
  978. if (svbi->service_set != 0) {
  979. for (i = 0; i <= 23; i++) {
  980. svbi->service_lines[1][i] = 0;
  981. svbi->service_lines[0][i] =
  982. tvp5150_set_vbi(sd, svbi->service_lines[0][i],
  983. 0xf0, i, 3);
  984. }
  985. /* Enables FIFO */
  986. tvp5150_write(sd, TVP5150_FIFO_OUT_CTRL, 1);
  987. } else {
  988. /* Disables FIFO*/
  989. tvp5150_write(sd, TVP5150_FIFO_OUT_CTRL, 0);
  990. /* Disable Full Field */
  991. tvp5150_write(sd, TVP5150_FULL_FIELD_ENA, 0);
  992. /* Disable Line modes */
  993. for (i = TVP5150_LINE_MODE_INI; i <= TVP5150_LINE_MODE_END; i++)
  994. tvp5150_write(sd, i, 0xff);
  995. }
  996. return 0;
  997. }
  998. static int tvp5150_g_sliced_fmt(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *svbi)
  999. {
  1000. int i, mask = 0;
  1001. memset(svbi->service_lines, 0, sizeof(svbi->service_lines));
  1002. for (i = 0; i <= 23; i++) {
  1003. svbi->service_lines[0][i] =
  1004. tvp5150_get_vbi(sd, i);
  1005. mask |= svbi->service_lines[0][i];
  1006. }
  1007. svbi->service_set = mask;
  1008. return 0;
  1009. }
  1010. #ifdef CONFIG_VIDEO_ADV_DEBUG
  1011. static int tvp5150_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg)
  1012. {
  1013. int res;
  1014. res = tvp5150_read(sd, reg->reg & 0xff);
  1015. if (res < 0) {
  1016. dev_err(sd->dev, "%s: failed with error = %d\n", __func__, res);
  1017. return res;
  1018. }
  1019. reg->val = res;
  1020. reg->size = 1;
  1021. return 0;
  1022. }
  1023. static int tvp5150_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg)
  1024. {
  1025. return tvp5150_write(sd, reg->reg & 0xff, reg->val & 0xff);
  1026. }
  1027. #endif
  1028. static int tvp5150_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
  1029. {
  1030. int status = tvp5150_read(sd, 0x88);
  1031. vt->signal = ((status & 0x04) && (status & 0x02)) ? 0xffff : 0x0;
  1032. return 0;
  1033. }
  1034. static int tvp5150_registered(struct v4l2_subdev *sd)
  1035. {
  1036. #ifdef CONFIG_MEDIA_CONTROLLER
  1037. struct tvp5150 *decoder = to_tvp5150(sd);
  1038. int ret = 0;
  1039. int i;
  1040. for (i = 0; i < TVP5150_INPUT_NUM; i++) {
  1041. struct media_entity *input = &decoder->input_ent[i];
  1042. struct media_pad *pad = &decoder->input_pad[i];
  1043. if (!input->name)
  1044. continue;
  1045. decoder->input_pad[i].flags = MEDIA_PAD_FL_SOURCE;
  1046. ret = media_entity_pads_init(input, 1, pad);
  1047. if (ret < 0)
  1048. return ret;
  1049. ret = media_device_register_entity(sd->v4l2_dev->mdev, input);
  1050. if (ret < 0)
  1051. return ret;
  1052. ret = media_create_pad_link(input, 0, &sd->entity,
  1053. DEMOD_PAD_IF_INPUT, 0);
  1054. if (ret < 0) {
  1055. media_device_unregister_entity(input);
  1056. return ret;
  1057. }
  1058. }
  1059. #endif
  1060. return 0;
  1061. }
  1062. /* ----------------------------------------------------------------------- */
  1063. static const struct v4l2_ctrl_ops tvp5150_ctrl_ops = {
  1064. .s_ctrl = tvp5150_s_ctrl,
  1065. };
  1066. static const struct v4l2_subdev_core_ops tvp5150_core_ops = {
  1067. .log_status = tvp5150_log_status,
  1068. .reset = tvp5150_reset,
  1069. #ifdef CONFIG_VIDEO_ADV_DEBUG
  1070. .g_register = tvp5150_g_register,
  1071. .s_register = tvp5150_s_register,
  1072. #endif
  1073. };
  1074. static const struct v4l2_subdev_tuner_ops tvp5150_tuner_ops = {
  1075. .g_tuner = tvp5150_g_tuner,
  1076. };
  1077. static const struct v4l2_subdev_video_ops tvp5150_video_ops = {
  1078. .s_std = tvp5150_s_std,
  1079. .s_stream = tvp5150_s_stream,
  1080. .s_routing = tvp5150_s_routing,
  1081. .g_mbus_config = tvp5150_g_mbus_config,
  1082. };
  1083. static const struct v4l2_subdev_vbi_ops tvp5150_vbi_ops = {
  1084. .g_sliced_vbi_cap = tvp5150_g_sliced_vbi_cap,
  1085. .g_sliced_fmt = tvp5150_g_sliced_fmt,
  1086. .s_sliced_fmt = tvp5150_s_sliced_fmt,
  1087. .s_raw_fmt = tvp5150_s_raw_fmt,
  1088. };
  1089. static const struct v4l2_subdev_pad_ops tvp5150_pad_ops = {
  1090. .enum_mbus_code = tvp5150_enum_mbus_code,
  1091. .enum_frame_size = tvp5150_enum_frame_size,
  1092. .set_fmt = tvp5150_fill_fmt,
  1093. .get_fmt = tvp5150_fill_fmt,
  1094. .get_selection = tvp5150_get_selection,
  1095. .set_selection = tvp5150_set_selection,
  1096. };
  1097. static const struct v4l2_subdev_ops tvp5150_ops = {
  1098. .core = &tvp5150_core_ops,
  1099. .tuner = &tvp5150_tuner_ops,
  1100. .video = &tvp5150_video_ops,
  1101. .vbi = &tvp5150_vbi_ops,
  1102. .pad = &tvp5150_pad_ops,
  1103. };
  1104. static const struct v4l2_subdev_internal_ops tvp5150_internal_ops = {
  1105. .registered = tvp5150_registered,
  1106. };
  1107. /****************************************************************************
  1108. I2C Client & Driver
  1109. ****************************************************************************/
  1110. static int tvp5150_detect_version(struct tvp5150 *core)
  1111. {
  1112. struct v4l2_subdev *sd = &core->sd;
  1113. struct i2c_client *c = v4l2_get_subdevdata(sd);
  1114. unsigned int i;
  1115. u8 regs[4];
  1116. int res;
  1117. /*
  1118. * Read consequent registers - TVP5150_MSB_DEV_ID, TVP5150_LSB_DEV_ID,
  1119. * TVP5150_ROM_MAJOR_VER, TVP5150_ROM_MINOR_VER
  1120. */
  1121. for (i = 0; i < 4; i++) {
  1122. res = tvp5150_read(sd, TVP5150_MSB_DEV_ID + i);
  1123. if (res < 0)
  1124. return res;
  1125. regs[i] = res;
  1126. }
  1127. core->dev_id = (regs[0] << 8) | regs[1];
  1128. core->rom_ver = (regs[2] << 8) | regs[3];
  1129. dev_info(sd->dev, "tvp%04x (%u.%u) chip found @ 0x%02x (%s)\n",
  1130. core->dev_id, regs[2], regs[3], c->addr << 1,
  1131. c->adapter->name);
  1132. if (core->dev_id == 0x5150 && core->rom_ver == 0x0321) {
  1133. dev_info(sd->dev, "tvp5150a detected.\n");
  1134. } else if (core->dev_id == 0x5150 && core->rom_ver == 0x0400) {
  1135. dev_info(sd->dev, "tvp5150am1 detected.\n");
  1136. /* ITU-T BT.656.4 timing */
  1137. tvp5150_write(sd, TVP5150_REV_SELECT, 0);
  1138. } else if (core->dev_id == 0x5151 && core->rom_ver == 0x0100) {
  1139. dev_info(sd->dev, "tvp5151 detected.\n");
  1140. } else {
  1141. dev_info(sd->dev, "*** unknown tvp%04x chip detected.\n",
  1142. core->dev_id);
  1143. }
  1144. return 0;
  1145. }
  1146. static int tvp5150_init(struct i2c_client *c)
  1147. {
  1148. struct gpio_desc *pdn_gpio;
  1149. struct gpio_desc *reset_gpio;
  1150. pdn_gpio = devm_gpiod_get_optional(&c->dev, "pdn", GPIOD_OUT_HIGH);
  1151. if (IS_ERR(pdn_gpio))
  1152. return PTR_ERR(pdn_gpio);
  1153. if (pdn_gpio) {
  1154. gpiod_set_value_cansleep(pdn_gpio, 0);
  1155. /* Delay time between power supplies active and reset */
  1156. msleep(20);
  1157. }
  1158. reset_gpio = devm_gpiod_get_optional(&c->dev, "reset", GPIOD_OUT_HIGH);
  1159. if (IS_ERR(reset_gpio))
  1160. return PTR_ERR(reset_gpio);
  1161. if (reset_gpio) {
  1162. /* RESETB pulse duration */
  1163. ndelay(500);
  1164. gpiod_set_value_cansleep(reset_gpio, 0);
  1165. /* Delay time between end of reset to I2C active */
  1166. usleep_range(200, 250);
  1167. }
  1168. return 0;
  1169. }
  1170. static int tvp5150_parse_dt(struct tvp5150 *decoder, struct device_node *np)
  1171. {
  1172. struct v4l2_fwnode_endpoint bus_cfg;
  1173. struct device_node *ep;
  1174. #ifdef CONFIG_MEDIA_CONTROLLER
  1175. struct device_node *connectors, *child;
  1176. struct media_entity *input;
  1177. const char *name;
  1178. u32 input_type;
  1179. #endif
  1180. unsigned int flags;
  1181. int ret = 0;
  1182. ep = of_graph_get_next_endpoint(np, NULL);
  1183. if (!ep)
  1184. return -EINVAL;
  1185. ret = v4l2_fwnode_endpoint_parse(of_fwnode_handle(ep), &bus_cfg);
  1186. if (ret)
  1187. goto err;
  1188. flags = bus_cfg.bus.parallel.flags;
  1189. if (bus_cfg.bus_type == V4L2_MBUS_PARALLEL &&
  1190. !(flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH &&
  1191. flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH &&
  1192. flags & V4L2_MBUS_FIELD_EVEN_LOW)) {
  1193. ret = -EINVAL;
  1194. goto err;
  1195. }
  1196. decoder->mbus_type = bus_cfg.bus_type;
  1197. #ifdef CONFIG_MEDIA_CONTROLLER
  1198. connectors = of_get_child_by_name(np, "connectors");
  1199. if (!connectors)
  1200. goto err;
  1201. for_each_available_child_of_node(connectors, child) {
  1202. ret = of_property_read_u32(child, "input", &input_type);
  1203. if (ret) {
  1204. dev_err(decoder->sd.dev,
  1205. "missing type property in node %s\n",
  1206. child->name);
  1207. goto err_connector;
  1208. }
  1209. if (input_type >= TVP5150_INPUT_NUM) {
  1210. ret = -EINVAL;
  1211. goto err_connector;
  1212. }
  1213. input = &decoder->input_ent[input_type];
  1214. /* Each input connector can only be defined once */
  1215. if (input->name) {
  1216. dev_err(decoder->sd.dev,
  1217. "input %s with same type already exists\n",
  1218. input->name);
  1219. ret = -EINVAL;
  1220. goto err_connector;
  1221. }
  1222. switch (input_type) {
  1223. case TVP5150_COMPOSITE0:
  1224. case TVP5150_COMPOSITE1:
  1225. input->function = MEDIA_ENT_F_CONN_COMPOSITE;
  1226. break;
  1227. case TVP5150_SVIDEO:
  1228. input->function = MEDIA_ENT_F_CONN_SVIDEO;
  1229. break;
  1230. }
  1231. input->flags = MEDIA_ENT_FL_CONNECTOR;
  1232. ret = of_property_read_string(child, "label", &name);
  1233. if (ret < 0) {
  1234. dev_err(decoder->sd.dev,
  1235. "missing label property in node %s\n",
  1236. child->name);
  1237. goto err_connector;
  1238. }
  1239. input->name = name;
  1240. }
  1241. err_connector:
  1242. of_node_put(connectors);
  1243. #endif
  1244. err:
  1245. of_node_put(ep);
  1246. return ret;
  1247. }
  1248. static const char * const tvp5150_test_patterns[2] = {
  1249. "Disabled",
  1250. "Black screen"
  1251. };
  1252. static int tvp5150_probe(struct i2c_client *c,
  1253. const struct i2c_device_id *id)
  1254. {
  1255. struct tvp5150 *core;
  1256. struct v4l2_subdev *sd;
  1257. struct device_node *np = c->dev.of_node;
  1258. int res;
  1259. /* Check if the adapter supports the needed features */
  1260. if (!i2c_check_functionality(c->adapter,
  1261. I2C_FUNC_SMBUS_READ_BYTE | I2C_FUNC_SMBUS_WRITE_BYTE_DATA))
  1262. return -EIO;
  1263. res = tvp5150_init(c);
  1264. if (res)
  1265. return res;
  1266. core = devm_kzalloc(&c->dev, sizeof(*core), GFP_KERNEL);
  1267. if (!core)
  1268. return -ENOMEM;
  1269. sd = &core->sd;
  1270. if (IS_ENABLED(CONFIG_OF) && np) {
  1271. res = tvp5150_parse_dt(core, np);
  1272. if (res) {
  1273. dev_err(sd->dev, "DT parsing error: %d\n", res);
  1274. return res;
  1275. }
  1276. } else {
  1277. /* Default to BT.656 embedded sync */
  1278. core->mbus_type = V4L2_MBUS_BT656;
  1279. }
  1280. v4l2_i2c_subdev_init(sd, c, &tvp5150_ops);
  1281. sd->internal_ops = &tvp5150_internal_ops;
  1282. sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
  1283. #if defined(CONFIG_MEDIA_CONTROLLER)
  1284. core->pads[DEMOD_PAD_IF_INPUT].flags = MEDIA_PAD_FL_SINK;
  1285. core->pads[DEMOD_PAD_VID_OUT].flags = MEDIA_PAD_FL_SOURCE;
  1286. core->pads[DEMOD_PAD_VBI_OUT].flags = MEDIA_PAD_FL_SOURCE;
  1287. sd->entity.function = MEDIA_ENT_F_ATV_DECODER;
  1288. res = media_entity_pads_init(&sd->entity, DEMOD_NUM_PADS, core->pads);
  1289. if (res < 0)
  1290. return res;
  1291. sd->entity.ops = &tvp5150_sd_media_ops;
  1292. #endif
  1293. res = tvp5150_detect_version(core);
  1294. if (res < 0)
  1295. return res;
  1296. core->norm = V4L2_STD_ALL; /* Default is autodetect */
  1297. core->input = TVP5150_COMPOSITE1;
  1298. core->enable = true;
  1299. v4l2_ctrl_handler_init(&core->hdl, 5);
  1300. v4l2_ctrl_new_std(&core->hdl, &tvp5150_ctrl_ops,
  1301. V4L2_CID_BRIGHTNESS, 0, 255, 1, 128);
  1302. v4l2_ctrl_new_std(&core->hdl, &tvp5150_ctrl_ops,
  1303. V4L2_CID_CONTRAST, 0, 255, 1, 128);
  1304. v4l2_ctrl_new_std(&core->hdl, &tvp5150_ctrl_ops,
  1305. V4L2_CID_SATURATION, 0, 255, 1, 128);
  1306. v4l2_ctrl_new_std(&core->hdl, &tvp5150_ctrl_ops,
  1307. V4L2_CID_HUE, -128, 127, 1, 0);
  1308. v4l2_ctrl_new_std(&core->hdl, &tvp5150_ctrl_ops,
  1309. V4L2_CID_PIXEL_RATE, 27000000,
  1310. 27000000, 1, 27000000);
  1311. v4l2_ctrl_new_std_menu_items(&core->hdl, &tvp5150_ctrl_ops,
  1312. V4L2_CID_TEST_PATTERN,
  1313. ARRAY_SIZE(tvp5150_test_patterns) - 1,
  1314. 0, 0, tvp5150_test_patterns);
  1315. sd->ctrl_handler = &core->hdl;
  1316. if (core->hdl.error) {
  1317. res = core->hdl.error;
  1318. goto err;
  1319. }
  1320. /* Default is no cropping */
  1321. core->rect.top = 0;
  1322. if (tvp5150_read_std(sd) & V4L2_STD_525_60)
  1323. core->rect.height = TVP5150_V_MAX_525_60;
  1324. else
  1325. core->rect.height = TVP5150_V_MAX_OTHERS;
  1326. core->rect.left = 0;
  1327. core->rect.width = TVP5150_H_MAX;
  1328. tvp5150_reset(sd, 0); /* Calls v4l2_ctrl_handler_setup() */
  1329. res = v4l2_async_register_subdev(sd);
  1330. if (res < 0)
  1331. goto err;
  1332. if (debug > 1)
  1333. tvp5150_log_status(sd);
  1334. return 0;
  1335. err:
  1336. v4l2_ctrl_handler_free(&core->hdl);
  1337. return res;
  1338. }
  1339. static int tvp5150_remove(struct i2c_client *c)
  1340. {
  1341. struct v4l2_subdev *sd = i2c_get_clientdata(c);
  1342. struct tvp5150 *decoder = to_tvp5150(sd);
  1343. dev_dbg_lvl(sd->dev, 1, debug,
  1344. "tvp5150.c: removing tvp5150 adapter on address 0x%x\n",
  1345. c->addr << 1);
  1346. v4l2_async_unregister_subdev(sd);
  1347. v4l2_ctrl_handler_free(&decoder->hdl);
  1348. return 0;
  1349. }
  1350. /* ----------------------------------------------------------------------- */
  1351. static const struct i2c_device_id tvp5150_id[] = {
  1352. { "tvp5150", 0 },
  1353. { }
  1354. };
  1355. MODULE_DEVICE_TABLE(i2c, tvp5150_id);
  1356. #if IS_ENABLED(CONFIG_OF)
  1357. static const struct of_device_id tvp5150_of_match[] = {
  1358. { .compatible = "ti,tvp5150", },
  1359. { /* sentinel */ },
  1360. };
  1361. MODULE_DEVICE_TABLE(of, tvp5150_of_match);
  1362. #endif
  1363. static struct i2c_driver tvp5150_driver = {
  1364. .driver = {
  1365. .of_match_table = of_match_ptr(tvp5150_of_match),
  1366. .name = "tvp5150",
  1367. },
  1368. .probe = tvp5150_probe,
  1369. .remove = tvp5150_remove,
  1370. .id_table = tvp5150_id,
  1371. };
  1372. module_i2c_driver(tvp5150_driver);