tvp5150.c 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609
  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. break;
  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.width = clamp_t(unsigned int, rect.width,
  794. TVP5150_H_MAX - TVP5150_MAX_CROP_LEFT - rect.left,
  795. TVP5150_H_MAX - rect.left);
  796. rect.top = clamp(rect.top, 0, TVP5150_MAX_CROP_TOP);
  797. /* Calculate height based on current standard */
  798. if (decoder->norm == V4L2_STD_ALL)
  799. std = tvp5150_read_std(sd);
  800. else
  801. std = decoder->norm;
  802. if (std & V4L2_STD_525_60)
  803. hmax = TVP5150_V_MAX_525_60;
  804. else
  805. hmax = TVP5150_V_MAX_OTHERS;
  806. rect.height = clamp_t(unsigned int, rect.height,
  807. hmax - TVP5150_MAX_CROP_TOP - rect.top,
  808. hmax - rect.top);
  809. tvp5150_write(sd, TVP5150_VERT_BLANKING_START, rect.top);
  810. tvp5150_write(sd, TVP5150_VERT_BLANKING_STOP,
  811. rect.top + rect.height - hmax);
  812. tvp5150_write(sd, TVP5150_ACT_VD_CROP_ST_MSB,
  813. rect.left >> TVP5150_CROP_SHIFT);
  814. tvp5150_write(sd, TVP5150_ACT_VD_CROP_ST_LSB,
  815. rect.left | (1 << TVP5150_CROP_SHIFT));
  816. tvp5150_write(sd, TVP5150_ACT_VD_CROP_STP_MSB,
  817. (rect.left + rect.width - TVP5150_MAX_CROP_LEFT) >>
  818. TVP5150_CROP_SHIFT);
  819. tvp5150_write(sd, TVP5150_ACT_VD_CROP_STP_LSB,
  820. rect.left + rect.width - TVP5150_MAX_CROP_LEFT);
  821. decoder->rect = rect;
  822. return 0;
  823. }
  824. static int tvp5150_get_selection(struct v4l2_subdev *sd,
  825. struct v4l2_subdev_pad_config *cfg,
  826. struct v4l2_subdev_selection *sel)
  827. {
  828. struct tvp5150 *decoder = container_of(sd, struct tvp5150, sd);
  829. v4l2_std_id std;
  830. if (sel->which != V4L2_SUBDEV_FORMAT_ACTIVE)
  831. return -EINVAL;
  832. switch (sel->target) {
  833. case V4L2_SEL_TGT_CROP_BOUNDS:
  834. case V4L2_SEL_TGT_CROP_DEFAULT:
  835. sel->r.left = 0;
  836. sel->r.top = 0;
  837. sel->r.width = TVP5150_H_MAX;
  838. /* Calculate height based on current standard */
  839. if (decoder->norm == V4L2_STD_ALL)
  840. std = tvp5150_read_std(sd);
  841. else
  842. std = decoder->norm;
  843. if (std & V4L2_STD_525_60)
  844. sel->r.height = TVP5150_V_MAX_525_60;
  845. else
  846. sel->r.height = TVP5150_V_MAX_OTHERS;
  847. return 0;
  848. case V4L2_SEL_TGT_CROP:
  849. sel->r = decoder->rect;
  850. return 0;
  851. default:
  852. return -EINVAL;
  853. }
  854. }
  855. static int tvp5150_g_mbus_config(struct v4l2_subdev *sd,
  856. struct v4l2_mbus_config *cfg)
  857. {
  858. struct tvp5150 *decoder = to_tvp5150(sd);
  859. cfg->type = decoder->mbus_type;
  860. cfg->flags = V4L2_MBUS_MASTER | V4L2_MBUS_PCLK_SAMPLE_RISING
  861. | V4L2_MBUS_FIELD_EVEN_LOW | V4L2_MBUS_DATA_ACTIVE_HIGH;
  862. return 0;
  863. }
  864. /****************************************************************************
  865. V4L2 subdev pad ops
  866. ****************************************************************************/
  867. static int tvp5150_enum_mbus_code(struct v4l2_subdev *sd,
  868. struct v4l2_subdev_pad_config *cfg,
  869. struct v4l2_subdev_mbus_code_enum *code)
  870. {
  871. if (code->pad || code->index)
  872. return -EINVAL;
  873. code->code = MEDIA_BUS_FMT_UYVY8_2X8;
  874. return 0;
  875. }
  876. static int tvp5150_enum_frame_size(struct v4l2_subdev *sd,
  877. struct v4l2_subdev_pad_config *cfg,
  878. struct v4l2_subdev_frame_size_enum *fse)
  879. {
  880. struct tvp5150 *decoder = to_tvp5150(sd);
  881. if (fse->index >= 8 || fse->code != MEDIA_BUS_FMT_UYVY8_2X8)
  882. return -EINVAL;
  883. fse->code = MEDIA_BUS_FMT_UYVY8_2X8;
  884. fse->min_width = decoder->rect.width;
  885. fse->max_width = decoder->rect.width;
  886. fse->min_height = decoder->rect.height / 2;
  887. fse->max_height = decoder->rect.height / 2;
  888. return 0;
  889. }
  890. /****************************************************************************
  891. Media entity ops
  892. ****************************************************************************/
  893. #ifdef CONFIG_MEDIA_CONTROLLER
  894. static int tvp5150_link_setup(struct media_entity *entity,
  895. const struct media_pad *local,
  896. const struct media_pad *remote, u32 flags)
  897. {
  898. struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
  899. struct tvp5150 *decoder = to_tvp5150(sd);
  900. int i;
  901. for (i = 0; i < TVP5150_INPUT_NUM; i++) {
  902. if (remote->entity == &decoder->input_ent[i])
  903. break;
  904. }
  905. /* Do nothing for entities that are not input connectors */
  906. if (i == TVP5150_INPUT_NUM)
  907. return 0;
  908. decoder->input = i;
  909. tvp5150_selmux(sd);
  910. return 0;
  911. }
  912. static const struct media_entity_operations tvp5150_sd_media_ops = {
  913. .link_setup = tvp5150_link_setup,
  914. };
  915. #endif
  916. /****************************************************************************
  917. I2C Command
  918. ****************************************************************************/
  919. static int tvp5150_s_stream(struct v4l2_subdev *sd, int enable)
  920. {
  921. struct tvp5150 *decoder = to_tvp5150(sd);
  922. int val;
  923. /* Enable or disable the video output signals. */
  924. val = tvp5150_read(sd, TVP5150_MISC_CTL);
  925. if (val < 0)
  926. return val;
  927. val &= ~(TVP5150_MISC_CTL_YCBCR_OE | TVP5150_MISC_CTL_SYNC_OE |
  928. TVP5150_MISC_CTL_CLOCK_OE);
  929. if (enable) {
  930. /*
  931. * Enable the YCbCr and clock outputs. In discrete sync mode
  932. * (non-BT.656) additionally enable the the sync outputs.
  933. */
  934. val |= TVP5150_MISC_CTL_YCBCR_OE | TVP5150_MISC_CTL_CLOCK_OE;
  935. if (decoder->mbus_type == V4L2_MBUS_PARALLEL)
  936. val |= TVP5150_MISC_CTL_SYNC_OE;
  937. }
  938. tvp5150_write(sd, TVP5150_MISC_CTL, val);
  939. return 0;
  940. }
  941. static int tvp5150_s_routing(struct v4l2_subdev *sd,
  942. u32 input, u32 output, u32 config)
  943. {
  944. struct tvp5150 *decoder = to_tvp5150(sd);
  945. decoder->input = input;
  946. decoder->output = output;
  947. if (output == TVP5150_BLACK_SCREEN)
  948. decoder->enable = false;
  949. else
  950. decoder->enable = true;
  951. tvp5150_selmux(sd);
  952. return 0;
  953. }
  954. static int tvp5150_s_raw_fmt(struct v4l2_subdev *sd, struct v4l2_vbi_format *fmt)
  955. {
  956. /*
  957. * this is for capturing 36 raw vbi lines
  958. * if there's a way to cut off the beginning 2 vbi lines
  959. * with the tvp5150 then the vbi line count could be lowered
  960. * to 17 lines/field again, although I couldn't find a register
  961. * which could do that cropping
  962. */
  963. if (fmt->sample_format == V4L2_PIX_FMT_GREY)
  964. tvp5150_write(sd, TVP5150_LUMA_PROC_CTL_1, 0x70);
  965. if (fmt->count[0] == 18 && fmt->count[1] == 18) {
  966. tvp5150_write(sd, TVP5150_VERT_BLANKING_START, 0x00);
  967. tvp5150_write(sd, TVP5150_VERT_BLANKING_STOP, 0x01);
  968. }
  969. return 0;
  970. }
  971. static int tvp5150_s_sliced_fmt(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *svbi)
  972. {
  973. int i;
  974. if (svbi->service_set != 0) {
  975. for (i = 0; i <= 23; i++) {
  976. svbi->service_lines[1][i] = 0;
  977. svbi->service_lines[0][i] =
  978. tvp5150_set_vbi(sd, svbi->service_lines[0][i],
  979. 0xf0, i, 3);
  980. }
  981. /* Enables FIFO */
  982. tvp5150_write(sd, TVP5150_FIFO_OUT_CTRL, 1);
  983. } else {
  984. /* Disables FIFO*/
  985. tvp5150_write(sd, TVP5150_FIFO_OUT_CTRL, 0);
  986. /* Disable Full Field */
  987. tvp5150_write(sd, TVP5150_FULL_FIELD_ENA, 0);
  988. /* Disable Line modes */
  989. for (i = TVP5150_LINE_MODE_INI; i <= TVP5150_LINE_MODE_END; i++)
  990. tvp5150_write(sd, i, 0xff);
  991. }
  992. return 0;
  993. }
  994. static int tvp5150_g_sliced_fmt(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *svbi)
  995. {
  996. int i, mask = 0;
  997. memset(svbi->service_lines, 0, sizeof(svbi->service_lines));
  998. for (i = 0; i <= 23; i++) {
  999. svbi->service_lines[0][i] =
  1000. tvp5150_get_vbi(sd, i);
  1001. mask |= svbi->service_lines[0][i];
  1002. }
  1003. svbi->service_set = mask;
  1004. return 0;
  1005. }
  1006. #ifdef CONFIG_VIDEO_ADV_DEBUG
  1007. static int tvp5150_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg)
  1008. {
  1009. int res;
  1010. res = tvp5150_read(sd, reg->reg & 0xff);
  1011. if (res < 0) {
  1012. dev_err(sd->dev, "%s: failed with error = %d\n", __func__, res);
  1013. return res;
  1014. }
  1015. reg->val = res;
  1016. reg->size = 1;
  1017. return 0;
  1018. }
  1019. static int tvp5150_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg)
  1020. {
  1021. return tvp5150_write(sd, reg->reg & 0xff, reg->val & 0xff);
  1022. }
  1023. #endif
  1024. static int tvp5150_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
  1025. {
  1026. int status = tvp5150_read(sd, 0x88);
  1027. vt->signal = ((status & 0x04) && (status & 0x02)) ? 0xffff : 0x0;
  1028. return 0;
  1029. }
  1030. static int tvp5150_registered(struct v4l2_subdev *sd)
  1031. {
  1032. #ifdef CONFIG_MEDIA_CONTROLLER
  1033. struct tvp5150 *decoder = to_tvp5150(sd);
  1034. int ret = 0;
  1035. int i;
  1036. for (i = 0; i < TVP5150_INPUT_NUM; i++) {
  1037. struct media_entity *input = &decoder->input_ent[i];
  1038. struct media_pad *pad = &decoder->input_pad[i];
  1039. if (!input->name)
  1040. continue;
  1041. decoder->input_pad[i].flags = MEDIA_PAD_FL_SOURCE;
  1042. ret = media_entity_pads_init(input, 1, pad);
  1043. if (ret < 0)
  1044. return ret;
  1045. ret = media_device_register_entity(sd->v4l2_dev->mdev, input);
  1046. if (ret < 0)
  1047. return ret;
  1048. ret = media_create_pad_link(input, 0, &sd->entity,
  1049. DEMOD_PAD_IF_INPUT, 0);
  1050. if (ret < 0) {
  1051. media_device_unregister_entity(input);
  1052. return ret;
  1053. }
  1054. }
  1055. #endif
  1056. return 0;
  1057. }
  1058. /* ----------------------------------------------------------------------- */
  1059. static const struct v4l2_ctrl_ops tvp5150_ctrl_ops = {
  1060. .s_ctrl = tvp5150_s_ctrl,
  1061. };
  1062. static const struct v4l2_subdev_core_ops tvp5150_core_ops = {
  1063. .log_status = tvp5150_log_status,
  1064. .reset = tvp5150_reset,
  1065. #ifdef CONFIG_VIDEO_ADV_DEBUG
  1066. .g_register = tvp5150_g_register,
  1067. .s_register = tvp5150_s_register,
  1068. #endif
  1069. };
  1070. static const struct v4l2_subdev_tuner_ops tvp5150_tuner_ops = {
  1071. .g_tuner = tvp5150_g_tuner,
  1072. };
  1073. static const struct v4l2_subdev_video_ops tvp5150_video_ops = {
  1074. .s_std = tvp5150_s_std,
  1075. .s_stream = tvp5150_s_stream,
  1076. .s_routing = tvp5150_s_routing,
  1077. .g_mbus_config = tvp5150_g_mbus_config,
  1078. };
  1079. static const struct v4l2_subdev_vbi_ops tvp5150_vbi_ops = {
  1080. .g_sliced_vbi_cap = tvp5150_g_sliced_vbi_cap,
  1081. .g_sliced_fmt = tvp5150_g_sliced_fmt,
  1082. .s_sliced_fmt = tvp5150_s_sliced_fmt,
  1083. .s_raw_fmt = tvp5150_s_raw_fmt,
  1084. };
  1085. static const struct v4l2_subdev_pad_ops tvp5150_pad_ops = {
  1086. .enum_mbus_code = tvp5150_enum_mbus_code,
  1087. .enum_frame_size = tvp5150_enum_frame_size,
  1088. .set_fmt = tvp5150_fill_fmt,
  1089. .get_fmt = tvp5150_fill_fmt,
  1090. .get_selection = tvp5150_get_selection,
  1091. .set_selection = tvp5150_set_selection,
  1092. };
  1093. static const struct v4l2_subdev_ops tvp5150_ops = {
  1094. .core = &tvp5150_core_ops,
  1095. .tuner = &tvp5150_tuner_ops,
  1096. .video = &tvp5150_video_ops,
  1097. .vbi = &tvp5150_vbi_ops,
  1098. .pad = &tvp5150_pad_ops,
  1099. };
  1100. static const struct v4l2_subdev_internal_ops tvp5150_internal_ops = {
  1101. .registered = tvp5150_registered,
  1102. };
  1103. /****************************************************************************
  1104. I2C Client & Driver
  1105. ****************************************************************************/
  1106. static int tvp5150_detect_version(struct tvp5150 *core)
  1107. {
  1108. struct v4l2_subdev *sd = &core->sd;
  1109. struct i2c_client *c = v4l2_get_subdevdata(sd);
  1110. unsigned int i;
  1111. u8 regs[4];
  1112. int res;
  1113. /*
  1114. * Read consequent registers - TVP5150_MSB_DEV_ID, TVP5150_LSB_DEV_ID,
  1115. * TVP5150_ROM_MAJOR_VER, TVP5150_ROM_MINOR_VER
  1116. */
  1117. for (i = 0; i < 4; i++) {
  1118. res = tvp5150_read(sd, TVP5150_MSB_DEV_ID + i);
  1119. if (res < 0)
  1120. return res;
  1121. regs[i] = res;
  1122. }
  1123. core->dev_id = (regs[0] << 8) | regs[1];
  1124. core->rom_ver = (regs[2] << 8) | regs[3];
  1125. dev_info(sd->dev, "tvp%04x (%u.%u) chip found @ 0x%02x (%s)\n",
  1126. core->dev_id, regs[2], regs[3], c->addr << 1,
  1127. c->adapter->name);
  1128. if (core->dev_id == 0x5150 && core->rom_ver == 0x0321) {
  1129. dev_info(sd->dev, "tvp5150a detected.\n");
  1130. } else if (core->dev_id == 0x5150 && core->rom_ver == 0x0400) {
  1131. dev_info(sd->dev, "tvp5150am1 detected.\n");
  1132. /* ITU-T BT.656.4 timing */
  1133. tvp5150_write(sd, TVP5150_REV_SELECT, 0);
  1134. } else if (core->dev_id == 0x5151 && core->rom_ver == 0x0100) {
  1135. dev_info(sd->dev, "tvp5151 detected.\n");
  1136. } else {
  1137. dev_info(sd->dev, "*** unknown tvp%04x chip detected.\n",
  1138. core->dev_id);
  1139. }
  1140. return 0;
  1141. }
  1142. static int tvp5150_init(struct i2c_client *c)
  1143. {
  1144. struct gpio_desc *pdn_gpio;
  1145. struct gpio_desc *reset_gpio;
  1146. pdn_gpio = devm_gpiod_get_optional(&c->dev, "pdn", GPIOD_OUT_HIGH);
  1147. if (IS_ERR(pdn_gpio))
  1148. return PTR_ERR(pdn_gpio);
  1149. if (pdn_gpio) {
  1150. gpiod_set_value_cansleep(pdn_gpio, 0);
  1151. /* Delay time between power supplies active and reset */
  1152. msleep(20);
  1153. }
  1154. reset_gpio = devm_gpiod_get_optional(&c->dev, "reset", GPIOD_OUT_HIGH);
  1155. if (IS_ERR(reset_gpio))
  1156. return PTR_ERR(reset_gpio);
  1157. if (reset_gpio) {
  1158. /* RESETB pulse duration */
  1159. ndelay(500);
  1160. gpiod_set_value_cansleep(reset_gpio, 0);
  1161. /* Delay time between end of reset to I2C active */
  1162. usleep_range(200, 250);
  1163. }
  1164. return 0;
  1165. }
  1166. static int tvp5150_parse_dt(struct tvp5150 *decoder, struct device_node *np)
  1167. {
  1168. struct v4l2_fwnode_endpoint bus_cfg;
  1169. struct device_node *ep;
  1170. #ifdef CONFIG_MEDIA_CONTROLLER
  1171. struct device_node *connectors, *child;
  1172. struct media_entity *input;
  1173. const char *name;
  1174. u32 input_type;
  1175. #endif
  1176. unsigned int flags;
  1177. int ret = 0;
  1178. ep = of_graph_get_next_endpoint(np, NULL);
  1179. if (!ep)
  1180. return -EINVAL;
  1181. ret = v4l2_fwnode_endpoint_parse(of_fwnode_handle(ep), &bus_cfg);
  1182. if (ret)
  1183. goto err;
  1184. flags = bus_cfg.bus.parallel.flags;
  1185. if (bus_cfg.bus_type == V4L2_MBUS_PARALLEL &&
  1186. !(flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH &&
  1187. flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH &&
  1188. flags & V4L2_MBUS_FIELD_EVEN_LOW)) {
  1189. ret = -EINVAL;
  1190. goto err;
  1191. }
  1192. decoder->mbus_type = bus_cfg.bus_type;
  1193. #ifdef CONFIG_MEDIA_CONTROLLER
  1194. connectors = of_get_child_by_name(np, "connectors");
  1195. if (!connectors)
  1196. goto err;
  1197. for_each_available_child_of_node(connectors, child) {
  1198. ret = of_property_read_u32(child, "input", &input_type);
  1199. if (ret) {
  1200. dev_err(decoder->sd.dev,
  1201. "missing type property in node %s\n",
  1202. child->name);
  1203. goto err_connector;
  1204. }
  1205. if (input_type >= TVP5150_INPUT_NUM) {
  1206. ret = -EINVAL;
  1207. goto err_connector;
  1208. }
  1209. input = &decoder->input_ent[input_type];
  1210. /* Each input connector can only be defined once */
  1211. if (input->name) {
  1212. dev_err(decoder->sd.dev,
  1213. "input %s with same type already exists\n",
  1214. input->name);
  1215. ret = -EINVAL;
  1216. goto err_connector;
  1217. }
  1218. switch (input_type) {
  1219. case TVP5150_COMPOSITE0:
  1220. case TVP5150_COMPOSITE1:
  1221. input->function = MEDIA_ENT_F_CONN_COMPOSITE;
  1222. break;
  1223. case TVP5150_SVIDEO:
  1224. input->function = MEDIA_ENT_F_CONN_SVIDEO;
  1225. break;
  1226. }
  1227. input->flags = MEDIA_ENT_FL_CONNECTOR;
  1228. ret = of_property_read_string(child, "label", &name);
  1229. if (ret < 0) {
  1230. dev_err(decoder->sd.dev,
  1231. "missing label property in node %s\n",
  1232. child->name);
  1233. goto err_connector;
  1234. }
  1235. input->name = name;
  1236. }
  1237. err_connector:
  1238. of_node_put(connectors);
  1239. #endif
  1240. err:
  1241. of_node_put(ep);
  1242. return ret;
  1243. }
  1244. static const char * const tvp5150_test_patterns[2] = {
  1245. "Disabled",
  1246. "Black screen"
  1247. };
  1248. static int tvp5150_probe(struct i2c_client *c,
  1249. const struct i2c_device_id *id)
  1250. {
  1251. struct tvp5150 *core;
  1252. struct v4l2_subdev *sd;
  1253. struct device_node *np = c->dev.of_node;
  1254. int res;
  1255. /* Check if the adapter supports the needed features */
  1256. if (!i2c_check_functionality(c->adapter,
  1257. I2C_FUNC_SMBUS_READ_BYTE | I2C_FUNC_SMBUS_WRITE_BYTE_DATA))
  1258. return -EIO;
  1259. res = tvp5150_init(c);
  1260. if (res)
  1261. return res;
  1262. core = devm_kzalloc(&c->dev, sizeof(*core), GFP_KERNEL);
  1263. if (!core)
  1264. return -ENOMEM;
  1265. sd = &core->sd;
  1266. if (IS_ENABLED(CONFIG_OF) && np) {
  1267. res = tvp5150_parse_dt(core, np);
  1268. if (res) {
  1269. dev_err(sd->dev, "DT parsing error: %d\n", res);
  1270. return res;
  1271. }
  1272. } else {
  1273. /* Default to BT.656 embedded sync */
  1274. core->mbus_type = V4L2_MBUS_BT656;
  1275. }
  1276. v4l2_i2c_subdev_init(sd, c, &tvp5150_ops);
  1277. sd->internal_ops = &tvp5150_internal_ops;
  1278. sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
  1279. #if defined(CONFIG_MEDIA_CONTROLLER)
  1280. core->pads[DEMOD_PAD_IF_INPUT].flags = MEDIA_PAD_FL_SINK;
  1281. core->pads[DEMOD_PAD_VID_OUT].flags = MEDIA_PAD_FL_SOURCE;
  1282. core->pads[DEMOD_PAD_VBI_OUT].flags = MEDIA_PAD_FL_SOURCE;
  1283. sd->entity.function = MEDIA_ENT_F_ATV_DECODER;
  1284. res = media_entity_pads_init(&sd->entity, DEMOD_NUM_PADS, core->pads);
  1285. if (res < 0)
  1286. return res;
  1287. sd->entity.ops = &tvp5150_sd_media_ops;
  1288. #endif
  1289. res = tvp5150_detect_version(core);
  1290. if (res < 0)
  1291. return res;
  1292. core->norm = V4L2_STD_ALL; /* Default is autodetect */
  1293. core->input = TVP5150_COMPOSITE1;
  1294. core->enable = true;
  1295. v4l2_ctrl_handler_init(&core->hdl, 5);
  1296. v4l2_ctrl_new_std(&core->hdl, &tvp5150_ctrl_ops,
  1297. V4L2_CID_BRIGHTNESS, 0, 255, 1, 128);
  1298. v4l2_ctrl_new_std(&core->hdl, &tvp5150_ctrl_ops,
  1299. V4L2_CID_CONTRAST, 0, 255, 1, 128);
  1300. v4l2_ctrl_new_std(&core->hdl, &tvp5150_ctrl_ops,
  1301. V4L2_CID_SATURATION, 0, 255, 1, 128);
  1302. v4l2_ctrl_new_std(&core->hdl, &tvp5150_ctrl_ops,
  1303. V4L2_CID_HUE, -128, 127, 1, 0);
  1304. v4l2_ctrl_new_std(&core->hdl, &tvp5150_ctrl_ops,
  1305. V4L2_CID_PIXEL_RATE, 27000000,
  1306. 27000000, 1, 27000000);
  1307. v4l2_ctrl_new_std_menu_items(&core->hdl, &tvp5150_ctrl_ops,
  1308. V4L2_CID_TEST_PATTERN,
  1309. ARRAY_SIZE(tvp5150_test_patterns),
  1310. 0, 0, tvp5150_test_patterns);
  1311. sd->ctrl_handler = &core->hdl;
  1312. if (core->hdl.error) {
  1313. res = core->hdl.error;
  1314. goto err;
  1315. }
  1316. /* Default is no cropping */
  1317. core->rect.top = 0;
  1318. if (tvp5150_read_std(sd) & V4L2_STD_525_60)
  1319. core->rect.height = TVP5150_V_MAX_525_60;
  1320. else
  1321. core->rect.height = TVP5150_V_MAX_OTHERS;
  1322. core->rect.left = 0;
  1323. core->rect.width = TVP5150_H_MAX;
  1324. tvp5150_reset(sd, 0); /* Calls v4l2_ctrl_handler_setup() */
  1325. res = v4l2_async_register_subdev(sd);
  1326. if (res < 0)
  1327. goto err;
  1328. if (debug > 1)
  1329. tvp5150_log_status(sd);
  1330. return 0;
  1331. err:
  1332. v4l2_ctrl_handler_free(&core->hdl);
  1333. return res;
  1334. }
  1335. static int tvp5150_remove(struct i2c_client *c)
  1336. {
  1337. struct v4l2_subdev *sd = i2c_get_clientdata(c);
  1338. struct tvp5150 *decoder = to_tvp5150(sd);
  1339. dev_dbg_lvl(sd->dev, 1, debug,
  1340. "tvp5150.c: removing tvp5150 adapter on address 0x%x\n",
  1341. c->addr << 1);
  1342. v4l2_async_unregister_subdev(sd);
  1343. v4l2_ctrl_handler_free(&decoder->hdl);
  1344. return 0;
  1345. }
  1346. /* ----------------------------------------------------------------------- */
  1347. static const struct i2c_device_id tvp5150_id[] = {
  1348. { "tvp5150", 0 },
  1349. { }
  1350. };
  1351. MODULE_DEVICE_TABLE(i2c, tvp5150_id);
  1352. #if IS_ENABLED(CONFIG_OF)
  1353. static const struct of_device_id tvp5150_of_match[] = {
  1354. { .compatible = "ti,tvp5150", },
  1355. { /* sentinel */ },
  1356. };
  1357. MODULE_DEVICE_TABLE(of, tvp5150_of_match);
  1358. #endif
  1359. static struct i2c_driver tvp5150_driver = {
  1360. .driver = {
  1361. .of_match_table = of_match_ptr(tvp5150_of_match),
  1362. .name = "tvp5150",
  1363. },
  1364. .probe = tvp5150_probe,
  1365. .remove = tvp5150_remove,
  1366. .id_table = tvp5150_id,
  1367. };
  1368. module_i2c_driver(tvp5150_driver);