tvp514x.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167
  1. /*
  2. * drivers/media/video/tvp514x.c
  3. *
  4. * TI TVP5146/47 decoder driver
  5. *
  6. * Copyright (C) 2008 Texas Instruments Inc
  7. * Author: Vaibhav Hiremath <hvaibhav@ti.com>
  8. *
  9. * Contributors:
  10. * Sivaraj R <sivaraj@ti.com>
  11. * Brijesh R Jadav <brijesh.j@ti.com>
  12. * Hardik Shah <hardik.shah@ti.com>
  13. * Manjunath Hadli <mrh@ti.com>
  14. * Karicheri Muralidharan <m-karicheri2@ti.com>
  15. *
  16. * This package is free software; you can redistribute it and/or modify
  17. * it under the terms of the GNU General Public License version 2 as
  18. * published by the Free Software Foundation.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program; if not, write to the Free Software
  27. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  28. *
  29. */
  30. #include <linux/i2c.h>
  31. #include <linux/slab.h>
  32. #include <linux/delay.h>
  33. #include <linux/videodev2.h>
  34. #include <linux/module.h>
  35. #include <media/v4l2-device.h>
  36. #include <media/v4l2-common.h>
  37. #include <media/v4l2-mediabus.h>
  38. #include <media/v4l2-chip-ident.h>
  39. #include <media/v4l2-ctrls.h>
  40. #include <media/tvp514x.h>
  41. #include "tvp514x_regs.h"
  42. /* Module Name */
  43. #define TVP514X_MODULE_NAME "tvp514x"
  44. /* Private macros for TVP */
  45. #define I2C_RETRY_COUNT (5)
  46. #define LOCK_RETRY_COUNT (5)
  47. #define LOCK_RETRY_DELAY (200)
  48. /* Debug functions */
  49. static bool debug;
  50. module_param(debug, bool, 0644);
  51. MODULE_PARM_DESC(debug, "Debug level (0-1)");
  52. MODULE_AUTHOR("Texas Instruments");
  53. MODULE_DESCRIPTION("TVP514X linux decoder driver");
  54. MODULE_LICENSE("GPL");
  55. /* enum tvp514x_std - enum for supported standards */
  56. enum tvp514x_std {
  57. STD_NTSC_MJ = 0,
  58. STD_PAL_BDGHIN,
  59. STD_INVALID
  60. };
  61. /**
  62. * struct tvp514x_std_info - Structure to store standard informations
  63. * @width: Line width in pixels
  64. * @height:Number of active lines
  65. * @video_std: Value to write in REG_VIDEO_STD register
  66. * @standard: v4l2 standard structure information
  67. */
  68. struct tvp514x_std_info {
  69. unsigned long width;
  70. unsigned long height;
  71. u8 video_std;
  72. struct v4l2_standard standard;
  73. };
  74. static struct tvp514x_reg tvp514x_reg_list_default[0x40];
  75. static int tvp514x_s_stream(struct v4l2_subdev *sd, int enable);
  76. /**
  77. * struct tvp514x_decoder - TVP5146/47 decoder object
  78. * @sd: Subdevice Slave handle
  79. * @tvp514x_regs: copy of hw's regs with preset values.
  80. * @pdata: Board specific
  81. * @ver: Chip version
  82. * @streaming: TVP5146/47 decoder streaming - enabled or disabled.
  83. * @current_std: Current standard
  84. * @num_stds: Number of standards
  85. * @std_list: Standards list
  86. * @input: Input routing at chip level
  87. * @output: Output routing at chip level
  88. */
  89. struct tvp514x_decoder {
  90. struct v4l2_subdev sd;
  91. struct v4l2_ctrl_handler hdl;
  92. struct tvp514x_reg tvp514x_regs[ARRAY_SIZE(tvp514x_reg_list_default)];
  93. const struct tvp514x_platform_data *pdata;
  94. int ver;
  95. int streaming;
  96. enum tvp514x_std current_std;
  97. int num_stds;
  98. const struct tvp514x_std_info *std_list;
  99. /* Input and Output Routing parameters */
  100. u32 input;
  101. u32 output;
  102. };
  103. /* TVP514x default register values */
  104. static struct tvp514x_reg tvp514x_reg_list_default[] = {
  105. /* Composite selected */
  106. {TOK_WRITE, REG_INPUT_SEL, 0x05},
  107. {TOK_WRITE, REG_AFE_GAIN_CTRL, 0x0F},
  108. /* Auto mode */
  109. {TOK_WRITE, REG_VIDEO_STD, 0x00},
  110. {TOK_WRITE, REG_OPERATION_MODE, 0x00},
  111. {TOK_SKIP, REG_AUTOSWITCH_MASK, 0x3F},
  112. {TOK_WRITE, REG_COLOR_KILLER, 0x10},
  113. {TOK_WRITE, REG_LUMA_CONTROL1, 0x00},
  114. {TOK_WRITE, REG_LUMA_CONTROL2, 0x00},
  115. {TOK_WRITE, REG_LUMA_CONTROL3, 0x02},
  116. {TOK_WRITE, REG_BRIGHTNESS, 0x80},
  117. {TOK_WRITE, REG_CONTRAST, 0x80},
  118. {TOK_WRITE, REG_SATURATION, 0x80},
  119. {TOK_WRITE, REG_HUE, 0x00},
  120. {TOK_WRITE, REG_CHROMA_CONTROL1, 0x00},
  121. {TOK_WRITE, REG_CHROMA_CONTROL2, 0x0E},
  122. /* Reserved */
  123. {TOK_SKIP, 0x0F, 0x00},
  124. {TOK_WRITE, REG_COMP_PR_SATURATION, 0x80},
  125. {TOK_WRITE, REG_COMP_Y_CONTRAST, 0x80},
  126. {TOK_WRITE, REG_COMP_PB_SATURATION, 0x80},
  127. /* Reserved */
  128. {TOK_SKIP, 0x13, 0x00},
  129. {TOK_WRITE, REG_COMP_Y_BRIGHTNESS, 0x80},
  130. /* Reserved */
  131. {TOK_SKIP, 0x15, 0x00},
  132. /* NTSC timing */
  133. {TOK_SKIP, REG_AVID_START_PIXEL_LSB, 0x55},
  134. {TOK_SKIP, REG_AVID_START_PIXEL_MSB, 0x00},
  135. {TOK_SKIP, REG_AVID_STOP_PIXEL_LSB, 0x25},
  136. {TOK_SKIP, REG_AVID_STOP_PIXEL_MSB, 0x03},
  137. /* NTSC timing */
  138. {TOK_SKIP, REG_HSYNC_START_PIXEL_LSB, 0x00},
  139. {TOK_SKIP, REG_HSYNC_START_PIXEL_MSB, 0x00},
  140. {TOK_SKIP, REG_HSYNC_STOP_PIXEL_LSB, 0x40},
  141. {TOK_SKIP, REG_HSYNC_STOP_PIXEL_MSB, 0x00},
  142. /* NTSC timing */
  143. {TOK_SKIP, REG_VSYNC_START_LINE_LSB, 0x04},
  144. {TOK_SKIP, REG_VSYNC_START_LINE_MSB, 0x00},
  145. {TOK_SKIP, REG_VSYNC_STOP_LINE_LSB, 0x07},
  146. {TOK_SKIP, REG_VSYNC_STOP_LINE_MSB, 0x00},
  147. /* NTSC timing */
  148. {TOK_SKIP, REG_VBLK_START_LINE_LSB, 0x01},
  149. {TOK_SKIP, REG_VBLK_START_LINE_MSB, 0x00},
  150. {TOK_SKIP, REG_VBLK_STOP_LINE_LSB, 0x15},
  151. {TOK_SKIP, REG_VBLK_STOP_LINE_MSB, 0x00},
  152. /* Reserved */
  153. {TOK_SKIP, 0x26, 0x00},
  154. /* Reserved */
  155. {TOK_SKIP, 0x27, 0x00},
  156. {TOK_SKIP, REG_FAST_SWTICH_CONTROL, 0xCC},
  157. /* Reserved */
  158. {TOK_SKIP, 0x29, 0x00},
  159. {TOK_SKIP, REG_FAST_SWTICH_SCART_DELAY, 0x00},
  160. /* Reserved */
  161. {TOK_SKIP, 0x2B, 0x00},
  162. {TOK_SKIP, REG_SCART_DELAY, 0x00},
  163. {TOK_SKIP, REG_CTI_DELAY, 0x00},
  164. {TOK_SKIP, REG_CTI_CONTROL, 0x00},
  165. /* Reserved */
  166. {TOK_SKIP, 0x2F, 0x00},
  167. /* Reserved */
  168. {TOK_SKIP, 0x30, 0x00},
  169. /* Reserved */
  170. {TOK_SKIP, 0x31, 0x00},
  171. /* HS, VS active high */
  172. {TOK_WRITE, REG_SYNC_CONTROL, 0x00},
  173. /* 10-bit BT.656 */
  174. {TOK_WRITE, REG_OUTPUT_FORMATTER1, 0x00},
  175. /* Enable clk & data */
  176. {TOK_WRITE, REG_OUTPUT_FORMATTER2, 0x11},
  177. /* Enable AVID & FLD */
  178. {TOK_WRITE, REG_OUTPUT_FORMATTER3, 0xEE},
  179. /* Enable VS & HS */
  180. {TOK_WRITE, REG_OUTPUT_FORMATTER4, 0xAF},
  181. {TOK_WRITE, REG_OUTPUT_FORMATTER5, 0xFF},
  182. {TOK_WRITE, REG_OUTPUT_FORMATTER6, 0xFF},
  183. /* Clear status */
  184. {TOK_WRITE, REG_CLEAR_LOST_LOCK, 0x01},
  185. {TOK_TERM, 0, 0},
  186. };
  187. /**
  188. * Supported standards -
  189. *
  190. * Currently supports two standards only, need to add support for rest of the
  191. * modes, like SECAM, etc...
  192. */
  193. static const struct tvp514x_std_info tvp514x_std_list[] = {
  194. /* Standard: STD_NTSC_MJ */
  195. [STD_NTSC_MJ] = {
  196. .width = NTSC_NUM_ACTIVE_PIXELS,
  197. .height = NTSC_NUM_ACTIVE_LINES,
  198. .video_std = VIDEO_STD_NTSC_MJ_BIT,
  199. .standard = {
  200. .index = 0,
  201. .id = V4L2_STD_NTSC,
  202. .name = "NTSC",
  203. .frameperiod = {1001, 30000},
  204. .framelines = 525
  205. },
  206. /* Standard: STD_PAL_BDGHIN */
  207. },
  208. [STD_PAL_BDGHIN] = {
  209. .width = PAL_NUM_ACTIVE_PIXELS,
  210. .height = PAL_NUM_ACTIVE_LINES,
  211. .video_std = VIDEO_STD_PAL_BDGHIN_BIT,
  212. .standard = {
  213. .index = 1,
  214. .id = V4L2_STD_PAL,
  215. .name = "PAL",
  216. .frameperiod = {1, 25},
  217. .framelines = 625
  218. },
  219. },
  220. /* Standard: need to add for additional standard */
  221. };
  222. static inline struct tvp514x_decoder *to_decoder(struct v4l2_subdev *sd)
  223. {
  224. return container_of(sd, struct tvp514x_decoder, sd);
  225. }
  226. static inline struct v4l2_subdev *to_sd(struct v4l2_ctrl *ctrl)
  227. {
  228. return &container_of(ctrl->handler, struct tvp514x_decoder, hdl)->sd;
  229. }
  230. /**
  231. * tvp514x_read_reg() - Read a value from a register in an TVP5146/47.
  232. * @sd: ptr to v4l2_subdev struct
  233. * @reg: TVP5146/47 register address
  234. *
  235. * Returns value read if successful, or non-zero (-1) otherwise.
  236. */
  237. static int tvp514x_read_reg(struct v4l2_subdev *sd, u8 reg)
  238. {
  239. int err, retry = 0;
  240. struct i2c_client *client = v4l2_get_subdevdata(sd);
  241. read_again:
  242. err = i2c_smbus_read_byte_data(client, reg);
  243. if (err < 0) {
  244. if (retry <= I2C_RETRY_COUNT) {
  245. v4l2_warn(sd, "Read: retry ... %d\n", retry);
  246. retry++;
  247. msleep_interruptible(10);
  248. goto read_again;
  249. }
  250. }
  251. return err;
  252. }
  253. /**
  254. * dump_reg() - dump the register content of TVP5146/47.
  255. * @sd: ptr to v4l2_subdev struct
  256. * @reg: TVP5146/47 register address
  257. */
  258. static void dump_reg(struct v4l2_subdev *sd, u8 reg)
  259. {
  260. u32 val;
  261. val = tvp514x_read_reg(sd, reg);
  262. v4l2_info(sd, "Reg(0x%.2X): 0x%.2X\n", reg, val);
  263. }
  264. /**
  265. * tvp514x_write_reg() - Write a value to a register in TVP5146/47
  266. * @sd: ptr to v4l2_subdev struct
  267. * @reg: TVP5146/47 register address
  268. * @val: value to be written to the register
  269. *
  270. * Write a value to a register in an TVP5146/47 decoder device.
  271. * Returns zero if successful, or non-zero otherwise.
  272. */
  273. static int tvp514x_write_reg(struct v4l2_subdev *sd, u8 reg, u8 val)
  274. {
  275. int err, retry = 0;
  276. struct i2c_client *client = v4l2_get_subdevdata(sd);
  277. write_again:
  278. err = i2c_smbus_write_byte_data(client, reg, val);
  279. if (err) {
  280. if (retry <= I2C_RETRY_COUNT) {
  281. v4l2_warn(sd, "Write: retry ... %d\n", retry);
  282. retry++;
  283. msleep_interruptible(10);
  284. goto write_again;
  285. }
  286. }
  287. return err;
  288. }
  289. /**
  290. * tvp514x_write_regs() : Initializes a list of TVP5146/47 registers
  291. * @sd: ptr to v4l2_subdev struct
  292. * @reglist: list of TVP5146/47 registers and values
  293. *
  294. * Initializes a list of TVP5146/47 registers:-
  295. * if token is TOK_TERM, then entire write operation terminates
  296. * if token is TOK_DELAY, then a delay of 'val' msec is introduced
  297. * if token is TOK_SKIP, then the register write is skipped
  298. * if token is TOK_WRITE, then the register write is performed
  299. * Returns zero if successful, or non-zero otherwise.
  300. */
  301. static int tvp514x_write_regs(struct v4l2_subdev *sd,
  302. const struct tvp514x_reg reglist[])
  303. {
  304. int err;
  305. const struct tvp514x_reg *next = reglist;
  306. for (; next->token != TOK_TERM; next++) {
  307. if (next->token == TOK_DELAY) {
  308. msleep(next->val);
  309. continue;
  310. }
  311. if (next->token == TOK_SKIP)
  312. continue;
  313. err = tvp514x_write_reg(sd, next->reg, (u8) next->val);
  314. if (err) {
  315. v4l2_err(sd, "Write failed. Err[%d]\n", err);
  316. return err;
  317. }
  318. }
  319. return 0;
  320. }
  321. /**
  322. * tvp514x_query_current_std() : Query the current standard detected by TVP5146/47
  323. * @sd: ptr to v4l2_subdev struct
  324. *
  325. * Returns the current standard detected by TVP5146/47, STD_INVALID if there is no
  326. * standard detected.
  327. */
  328. static enum tvp514x_std tvp514x_query_current_std(struct v4l2_subdev *sd)
  329. {
  330. u8 std, std_status;
  331. std = tvp514x_read_reg(sd, REG_VIDEO_STD);
  332. if ((std & VIDEO_STD_MASK) == VIDEO_STD_AUTO_SWITCH_BIT)
  333. /* use the standard status register */
  334. std_status = tvp514x_read_reg(sd, REG_VIDEO_STD_STATUS);
  335. else
  336. /* use the standard register itself */
  337. std_status = std;
  338. switch (std_status & VIDEO_STD_MASK) {
  339. case VIDEO_STD_NTSC_MJ_BIT:
  340. return STD_NTSC_MJ;
  341. case VIDEO_STD_PAL_BDGHIN_BIT:
  342. return STD_PAL_BDGHIN;
  343. default:
  344. return STD_INVALID;
  345. }
  346. return STD_INVALID;
  347. }
  348. /* TVP5146/47 register dump function */
  349. static void tvp514x_reg_dump(struct v4l2_subdev *sd)
  350. {
  351. dump_reg(sd, REG_INPUT_SEL);
  352. dump_reg(sd, REG_AFE_GAIN_CTRL);
  353. dump_reg(sd, REG_VIDEO_STD);
  354. dump_reg(sd, REG_OPERATION_MODE);
  355. dump_reg(sd, REG_COLOR_KILLER);
  356. dump_reg(sd, REG_LUMA_CONTROL1);
  357. dump_reg(sd, REG_LUMA_CONTROL2);
  358. dump_reg(sd, REG_LUMA_CONTROL3);
  359. dump_reg(sd, REG_BRIGHTNESS);
  360. dump_reg(sd, REG_CONTRAST);
  361. dump_reg(sd, REG_SATURATION);
  362. dump_reg(sd, REG_HUE);
  363. dump_reg(sd, REG_CHROMA_CONTROL1);
  364. dump_reg(sd, REG_CHROMA_CONTROL2);
  365. dump_reg(sd, REG_COMP_PR_SATURATION);
  366. dump_reg(sd, REG_COMP_Y_CONTRAST);
  367. dump_reg(sd, REG_COMP_PB_SATURATION);
  368. dump_reg(sd, REG_COMP_Y_BRIGHTNESS);
  369. dump_reg(sd, REG_AVID_START_PIXEL_LSB);
  370. dump_reg(sd, REG_AVID_START_PIXEL_MSB);
  371. dump_reg(sd, REG_AVID_STOP_PIXEL_LSB);
  372. dump_reg(sd, REG_AVID_STOP_PIXEL_MSB);
  373. dump_reg(sd, REG_HSYNC_START_PIXEL_LSB);
  374. dump_reg(sd, REG_HSYNC_START_PIXEL_MSB);
  375. dump_reg(sd, REG_HSYNC_STOP_PIXEL_LSB);
  376. dump_reg(sd, REG_HSYNC_STOP_PIXEL_MSB);
  377. dump_reg(sd, REG_VSYNC_START_LINE_LSB);
  378. dump_reg(sd, REG_VSYNC_START_LINE_MSB);
  379. dump_reg(sd, REG_VSYNC_STOP_LINE_LSB);
  380. dump_reg(sd, REG_VSYNC_STOP_LINE_MSB);
  381. dump_reg(sd, REG_VBLK_START_LINE_LSB);
  382. dump_reg(sd, REG_VBLK_START_LINE_MSB);
  383. dump_reg(sd, REG_VBLK_STOP_LINE_LSB);
  384. dump_reg(sd, REG_VBLK_STOP_LINE_MSB);
  385. dump_reg(sd, REG_SYNC_CONTROL);
  386. dump_reg(sd, REG_OUTPUT_FORMATTER1);
  387. dump_reg(sd, REG_OUTPUT_FORMATTER2);
  388. dump_reg(sd, REG_OUTPUT_FORMATTER3);
  389. dump_reg(sd, REG_OUTPUT_FORMATTER4);
  390. dump_reg(sd, REG_OUTPUT_FORMATTER5);
  391. dump_reg(sd, REG_OUTPUT_FORMATTER6);
  392. dump_reg(sd, REG_CLEAR_LOST_LOCK);
  393. }
  394. /**
  395. * tvp514x_configure() - Configure the TVP5146/47 registers
  396. * @sd: ptr to v4l2_subdev struct
  397. * @decoder: ptr to tvp514x_decoder structure
  398. *
  399. * Returns zero if successful, or non-zero otherwise.
  400. */
  401. static int tvp514x_configure(struct v4l2_subdev *sd,
  402. struct tvp514x_decoder *decoder)
  403. {
  404. int err;
  405. /* common register initialization */
  406. err =
  407. tvp514x_write_regs(sd, decoder->tvp514x_regs);
  408. if (err)
  409. return err;
  410. if (debug)
  411. tvp514x_reg_dump(sd);
  412. return 0;
  413. }
  414. /**
  415. * tvp514x_detect() - Detect if an tvp514x is present, and if so which revision.
  416. * @sd: pointer to standard V4L2 sub-device structure
  417. * @decoder: pointer to tvp514x_decoder structure
  418. *
  419. * A device is considered to be detected if the chip ID (LSB and MSB)
  420. * registers match the expected values.
  421. * Any value of the rom version register is accepted.
  422. * Returns ENODEV error number if no device is detected, or zero
  423. * if a device is detected.
  424. */
  425. static int tvp514x_detect(struct v4l2_subdev *sd,
  426. struct tvp514x_decoder *decoder)
  427. {
  428. u8 chip_id_msb, chip_id_lsb, rom_ver;
  429. struct i2c_client *client = v4l2_get_subdevdata(sd);
  430. chip_id_msb = tvp514x_read_reg(sd, REG_CHIP_ID_MSB);
  431. chip_id_lsb = tvp514x_read_reg(sd, REG_CHIP_ID_LSB);
  432. rom_ver = tvp514x_read_reg(sd, REG_ROM_VERSION);
  433. v4l2_dbg(1, debug, sd,
  434. "chip id detected msb:0x%x lsb:0x%x rom version:0x%x\n",
  435. chip_id_msb, chip_id_lsb, rom_ver);
  436. if ((chip_id_msb != TVP514X_CHIP_ID_MSB)
  437. || ((chip_id_lsb != TVP5146_CHIP_ID_LSB)
  438. && (chip_id_lsb != TVP5147_CHIP_ID_LSB))) {
  439. /* We didn't read the values we expected, so this must not be
  440. * an TVP5146/47.
  441. */
  442. v4l2_err(sd, "chip id mismatch msb:0x%x lsb:0x%x\n",
  443. chip_id_msb, chip_id_lsb);
  444. return -ENODEV;
  445. }
  446. decoder->ver = rom_ver;
  447. v4l2_info(sd, "%s (Version - 0x%.2x) found at 0x%x (%s)\n",
  448. client->name, decoder->ver,
  449. client->addr << 1, client->adapter->name);
  450. return 0;
  451. }
  452. /**
  453. * tvp514x_querystd() - V4L2 decoder interface handler for querystd
  454. * @sd: pointer to standard V4L2 sub-device structure
  455. * @std_id: standard V4L2 std_id ioctl enum
  456. *
  457. * Returns the current standard detected by TVP5146/47. If no active input is
  458. * detected then *std_id is set to 0 and the function returns 0.
  459. */
  460. static int tvp514x_querystd(struct v4l2_subdev *sd, v4l2_std_id *std_id)
  461. {
  462. struct tvp514x_decoder *decoder = to_decoder(sd);
  463. enum tvp514x_std current_std;
  464. enum tvp514x_input input_sel;
  465. u8 sync_lock_status, lock_mask;
  466. if (std_id == NULL)
  467. return -EINVAL;
  468. *std_id = V4L2_STD_UNKNOWN;
  469. /* query the current standard */
  470. current_std = tvp514x_query_current_std(sd);
  471. if (current_std == STD_INVALID)
  472. return 0;
  473. input_sel = decoder->input;
  474. switch (input_sel) {
  475. case INPUT_CVBS_VI1A:
  476. case INPUT_CVBS_VI1B:
  477. case INPUT_CVBS_VI1C:
  478. case INPUT_CVBS_VI2A:
  479. case INPUT_CVBS_VI2B:
  480. case INPUT_CVBS_VI2C:
  481. case INPUT_CVBS_VI3A:
  482. case INPUT_CVBS_VI3B:
  483. case INPUT_CVBS_VI3C:
  484. case INPUT_CVBS_VI4A:
  485. lock_mask = STATUS_CLR_SUBCAR_LOCK_BIT |
  486. STATUS_HORZ_SYNC_LOCK_BIT |
  487. STATUS_VIRT_SYNC_LOCK_BIT;
  488. break;
  489. case INPUT_SVIDEO_VI2A_VI1A:
  490. case INPUT_SVIDEO_VI2B_VI1B:
  491. case INPUT_SVIDEO_VI2C_VI1C:
  492. case INPUT_SVIDEO_VI2A_VI3A:
  493. case INPUT_SVIDEO_VI2B_VI3B:
  494. case INPUT_SVIDEO_VI2C_VI3C:
  495. case INPUT_SVIDEO_VI4A_VI1A:
  496. case INPUT_SVIDEO_VI4A_VI1B:
  497. case INPUT_SVIDEO_VI4A_VI1C:
  498. case INPUT_SVIDEO_VI4A_VI3A:
  499. case INPUT_SVIDEO_VI4A_VI3B:
  500. case INPUT_SVIDEO_VI4A_VI3C:
  501. lock_mask = STATUS_HORZ_SYNC_LOCK_BIT |
  502. STATUS_VIRT_SYNC_LOCK_BIT;
  503. break;
  504. /*Need to add other interfaces*/
  505. default:
  506. return -EINVAL;
  507. }
  508. /* check whether signal is locked */
  509. sync_lock_status = tvp514x_read_reg(sd, REG_STATUS1);
  510. if (lock_mask != (sync_lock_status & lock_mask))
  511. return 0; /* No input detected */
  512. *std_id = decoder->std_list[current_std].standard.id;
  513. v4l2_dbg(1, debug, sd, "Current STD: %s\n",
  514. decoder->std_list[current_std].standard.name);
  515. return 0;
  516. }
  517. /**
  518. * tvp514x_s_std() - V4L2 decoder interface handler for s_std
  519. * @sd: pointer to standard V4L2 sub-device structure
  520. * @std_id: standard V4L2 v4l2_std_id ioctl enum
  521. *
  522. * If std_id is supported, sets the requested standard. Otherwise, returns
  523. * -EINVAL
  524. */
  525. static int tvp514x_s_std(struct v4l2_subdev *sd, v4l2_std_id std_id)
  526. {
  527. struct tvp514x_decoder *decoder = to_decoder(sd);
  528. int err, i;
  529. for (i = 0; i < decoder->num_stds; i++)
  530. if (std_id & decoder->std_list[i].standard.id)
  531. break;
  532. if ((i == decoder->num_stds) || (i == STD_INVALID))
  533. return -EINVAL;
  534. err = tvp514x_write_reg(sd, REG_VIDEO_STD,
  535. decoder->std_list[i].video_std);
  536. if (err)
  537. return err;
  538. decoder->current_std = i;
  539. decoder->tvp514x_regs[REG_VIDEO_STD].val =
  540. decoder->std_list[i].video_std;
  541. v4l2_dbg(1, debug, sd, "Standard set to: %s\n",
  542. decoder->std_list[i].standard.name);
  543. return 0;
  544. }
  545. /**
  546. * tvp514x_s_routing() - V4L2 decoder interface handler for s_routing
  547. * @sd: pointer to standard V4L2 sub-device structure
  548. * @input: input selector for routing the signal
  549. * @output: output selector for routing the signal
  550. * @config: config value. Not used
  551. *
  552. * If index is valid, selects the requested input. Otherwise, returns -EINVAL if
  553. * the input is not supported or there is no active signal present in the
  554. * selected input.
  555. */
  556. static int tvp514x_s_routing(struct v4l2_subdev *sd,
  557. u32 input, u32 output, u32 config)
  558. {
  559. struct tvp514x_decoder *decoder = to_decoder(sd);
  560. int err;
  561. enum tvp514x_input input_sel;
  562. enum tvp514x_output output_sel;
  563. u8 sync_lock_status, lock_mask;
  564. int try_count = LOCK_RETRY_COUNT;
  565. if ((input >= INPUT_INVALID) ||
  566. (output >= OUTPUT_INVALID))
  567. /* Index out of bound */
  568. return -EINVAL;
  569. /*
  570. * For the sequence streamon -> streamoff and again s_input
  571. * it fails to lock the signal, since streamoff puts TVP514x
  572. * into power off state which leads to failure in sub-sequent s_input.
  573. *
  574. * So power up the TVP514x device here, since it is important to lock
  575. * the signal at this stage.
  576. */
  577. if (!decoder->streaming)
  578. tvp514x_s_stream(sd, 1);
  579. input_sel = input;
  580. output_sel = output;
  581. err = tvp514x_write_reg(sd, REG_INPUT_SEL, input_sel);
  582. if (err)
  583. return err;
  584. output_sel |= tvp514x_read_reg(sd,
  585. REG_OUTPUT_FORMATTER1) & 0x7;
  586. err = tvp514x_write_reg(sd, REG_OUTPUT_FORMATTER1,
  587. output_sel);
  588. if (err)
  589. return err;
  590. decoder->tvp514x_regs[REG_INPUT_SEL].val = input_sel;
  591. decoder->tvp514x_regs[REG_OUTPUT_FORMATTER1].val = output_sel;
  592. /* Clear status */
  593. msleep(LOCK_RETRY_DELAY);
  594. err =
  595. tvp514x_write_reg(sd, REG_CLEAR_LOST_LOCK, 0x01);
  596. if (err)
  597. return err;
  598. switch (input_sel) {
  599. case INPUT_CVBS_VI1A:
  600. case INPUT_CVBS_VI1B:
  601. case INPUT_CVBS_VI1C:
  602. case INPUT_CVBS_VI2A:
  603. case INPUT_CVBS_VI2B:
  604. case INPUT_CVBS_VI2C:
  605. case INPUT_CVBS_VI3A:
  606. case INPUT_CVBS_VI3B:
  607. case INPUT_CVBS_VI3C:
  608. case INPUT_CVBS_VI4A:
  609. lock_mask = STATUS_CLR_SUBCAR_LOCK_BIT |
  610. STATUS_HORZ_SYNC_LOCK_BIT |
  611. STATUS_VIRT_SYNC_LOCK_BIT;
  612. break;
  613. case INPUT_SVIDEO_VI2A_VI1A:
  614. case INPUT_SVIDEO_VI2B_VI1B:
  615. case INPUT_SVIDEO_VI2C_VI1C:
  616. case INPUT_SVIDEO_VI2A_VI3A:
  617. case INPUT_SVIDEO_VI2B_VI3B:
  618. case INPUT_SVIDEO_VI2C_VI3C:
  619. case INPUT_SVIDEO_VI4A_VI1A:
  620. case INPUT_SVIDEO_VI4A_VI1B:
  621. case INPUT_SVIDEO_VI4A_VI1C:
  622. case INPUT_SVIDEO_VI4A_VI3A:
  623. case INPUT_SVIDEO_VI4A_VI3B:
  624. case INPUT_SVIDEO_VI4A_VI3C:
  625. lock_mask = STATUS_HORZ_SYNC_LOCK_BIT |
  626. STATUS_VIRT_SYNC_LOCK_BIT;
  627. break;
  628. /* Need to add other interfaces*/
  629. default:
  630. return -EINVAL;
  631. }
  632. while (try_count-- > 0) {
  633. /* Allow decoder to sync up with new input */
  634. msleep(LOCK_RETRY_DELAY);
  635. sync_lock_status = tvp514x_read_reg(sd,
  636. REG_STATUS1);
  637. if (lock_mask == (sync_lock_status & lock_mask))
  638. /* Input detected */
  639. break;
  640. }
  641. if (try_count < 0)
  642. return -EINVAL;
  643. decoder->input = input;
  644. decoder->output = output;
  645. v4l2_dbg(1, debug, sd, "Input set to: %d\n", input_sel);
  646. return 0;
  647. }
  648. /**
  649. * tvp514x_s_ctrl() - V4L2 decoder interface handler for s_ctrl
  650. * @ctrl: pointer to v4l2_ctrl structure
  651. *
  652. * If the requested control is supported, sets the control's current
  653. * value in HW. Otherwise, returns -EINVAL if the control is not supported.
  654. */
  655. static int tvp514x_s_ctrl(struct v4l2_ctrl *ctrl)
  656. {
  657. struct v4l2_subdev *sd = to_sd(ctrl);
  658. struct tvp514x_decoder *decoder = to_decoder(sd);
  659. int err = -EINVAL, value;
  660. value = ctrl->val;
  661. switch (ctrl->id) {
  662. case V4L2_CID_BRIGHTNESS:
  663. err = tvp514x_write_reg(sd, REG_BRIGHTNESS, value);
  664. if (!err)
  665. decoder->tvp514x_regs[REG_BRIGHTNESS].val = value;
  666. break;
  667. case V4L2_CID_CONTRAST:
  668. err = tvp514x_write_reg(sd, REG_CONTRAST, value);
  669. if (!err)
  670. decoder->tvp514x_regs[REG_CONTRAST].val = value;
  671. break;
  672. case V4L2_CID_SATURATION:
  673. err = tvp514x_write_reg(sd, REG_SATURATION, value);
  674. if (!err)
  675. decoder->tvp514x_regs[REG_SATURATION].val = value;
  676. break;
  677. case V4L2_CID_HUE:
  678. if (value == 180)
  679. value = 0x7F;
  680. else if (value == -180)
  681. value = 0x80;
  682. err = tvp514x_write_reg(sd, REG_HUE, value);
  683. if (!err)
  684. decoder->tvp514x_regs[REG_HUE].val = value;
  685. break;
  686. case V4L2_CID_AUTOGAIN:
  687. err = tvp514x_write_reg(sd, REG_AFE_GAIN_CTRL, value ? 0x0f : 0x0c);
  688. if (!err)
  689. decoder->tvp514x_regs[REG_AFE_GAIN_CTRL].val = value;
  690. break;
  691. }
  692. v4l2_dbg(1, debug, sd, "Set Control: ID - %d - %d\n",
  693. ctrl->id, ctrl->val);
  694. return err;
  695. }
  696. /**
  697. * tvp514x_enum_mbus_fmt() - V4L2 decoder interface handler for enum_mbus_fmt
  698. * @sd: pointer to standard V4L2 sub-device structure
  699. * @index: index of pixelcode to retrieve
  700. * @code: receives the pixelcode
  701. *
  702. * Enumerates supported mediabus formats
  703. */
  704. static int
  705. tvp514x_enum_mbus_fmt(struct v4l2_subdev *sd, unsigned index,
  706. enum v4l2_mbus_pixelcode *code)
  707. {
  708. if (index)
  709. return -EINVAL;
  710. *code = V4L2_MBUS_FMT_YUYV10_2X10;
  711. return 0;
  712. }
  713. /**
  714. * tvp514x_mbus_fmt_cap() - V4L2 decoder interface handler for try/s/g_mbus_fmt
  715. * @sd: pointer to standard V4L2 sub-device structure
  716. * @f: pointer to the mediabus format structure
  717. *
  718. * Negotiates the image capture size and mediabus format.
  719. */
  720. static int
  721. tvp514x_mbus_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *f)
  722. {
  723. struct tvp514x_decoder *decoder = to_decoder(sd);
  724. enum tvp514x_std current_std;
  725. if (f == NULL)
  726. return -EINVAL;
  727. /* Calculate height and width based on current standard */
  728. current_std = decoder->current_std;
  729. f->code = V4L2_MBUS_FMT_YUYV10_2X10;
  730. f->width = decoder->std_list[current_std].width;
  731. f->height = decoder->std_list[current_std].height;
  732. f->field = V4L2_FIELD_INTERLACED;
  733. f->colorspace = V4L2_COLORSPACE_SMPTE170M;
  734. v4l2_dbg(1, debug, sd, "MBUS_FMT: Width - %d, Height - %d\n",
  735. f->width, f->height);
  736. return 0;
  737. }
  738. /**
  739. * tvp514x_g_parm() - V4L2 decoder interface handler for g_parm
  740. * @sd: pointer to standard V4L2 sub-device structure
  741. * @a: pointer to standard V4L2 VIDIOC_G_PARM ioctl structure
  742. *
  743. * Returns the decoder's video CAPTURE parameters.
  744. */
  745. static int
  746. tvp514x_g_parm(struct v4l2_subdev *sd, struct v4l2_streamparm *a)
  747. {
  748. struct tvp514x_decoder *decoder = to_decoder(sd);
  749. struct v4l2_captureparm *cparm;
  750. enum tvp514x_std current_std;
  751. if (a == NULL)
  752. return -EINVAL;
  753. if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  754. /* only capture is supported */
  755. return -EINVAL;
  756. /* get the current standard */
  757. current_std = decoder->current_std;
  758. cparm = &a->parm.capture;
  759. cparm->capability = V4L2_CAP_TIMEPERFRAME;
  760. cparm->timeperframe =
  761. decoder->std_list[current_std].standard.frameperiod;
  762. return 0;
  763. }
  764. /**
  765. * tvp514x_s_parm() - V4L2 decoder interface handler for s_parm
  766. * @sd: pointer to standard V4L2 sub-device structure
  767. * @a: pointer to standard V4L2 VIDIOC_S_PARM ioctl structure
  768. *
  769. * Configures the decoder to use the input parameters, if possible. If
  770. * not possible, returns the appropriate error code.
  771. */
  772. static int
  773. tvp514x_s_parm(struct v4l2_subdev *sd, struct v4l2_streamparm *a)
  774. {
  775. struct tvp514x_decoder *decoder = to_decoder(sd);
  776. struct v4l2_fract *timeperframe;
  777. enum tvp514x_std current_std;
  778. if (a == NULL)
  779. return -EINVAL;
  780. if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  781. /* only capture is supported */
  782. return -EINVAL;
  783. timeperframe = &a->parm.capture.timeperframe;
  784. /* get the current standard */
  785. current_std = decoder->current_std;
  786. *timeperframe =
  787. decoder->std_list[current_std].standard.frameperiod;
  788. return 0;
  789. }
  790. /**
  791. * tvp514x_s_stream() - V4L2 decoder i/f handler for s_stream
  792. * @sd: pointer to standard V4L2 sub-device structure
  793. * @enable: streaming enable or disable
  794. *
  795. * Sets streaming to enable or disable, if possible.
  796. */
  797. static int tvp514x_s_stream(struct v4l2_subdev *sd, int enable)
  798. {
  799. int err = 0;
  800. struct i2c_client *client = v4l2_get_subdevdata(sd);
  801. struct tvp514x_decoder *decoder = to_decoder(sd);
  802. if (decoder->streaming == enable)
  803. return 0;
  804. switch (enable) {
  805. case 0:
  806. {
  807. /* Power Down Sequence */
  808. err = tvp514x_write_reg(sd, REG_OPERATION_MODE, 0x01);
  809. if (err) {
  810. v4l2_err(sd, "Unable to turn off decoder\n");
  811. return err;
  812. }
  813. decoder->streaming = enable;
  814. break;
  815. }
  816. case 1:
  817. {
  818. struct tvp514x_reg *int_seq = (struct tvp514x_reg *)
  819. client->driver->id_table->driver_data;
  820. /* Power Up Sequence */
  821. err = tvp514x_write_regs(sd, int_seq);
  822. if (err) {
  823. v4l2_err(sd, "Unable to turn on decoder\n");
  824. return err;
  825. }
  826. /* Detect if not already detected */
  827. err = tvp514x_detect(sd, decoder);
  828. if (err) {
  829. v4l2_err(sd, "Unable to detect decoder\n");
  830. return err;
  831. }
  832. err = tvp514x_configure(sd, decoder);
  833. if (err) {
  834. v4l2_err(sd, "Unable to configure decoder\n");
  835. return err;
  836. }
  837. decoder->streaming = enable;
  838. break;
  839. }
  840. default:
  841. err = -ENODEV;
  842. break;
  843. }
  844. return err;
  845. }
  846. static const struct v4l2_ctrl_ops tvp514x_ctrl_ops = {
  847. .s_ctrl = tvp514x_s_ctrl,
  848. };
  849. static const struct v4l2_subdev_core_ops tvp514x_core_ops = {
  850. .g_ext_ctrls = v4l2_subdev_g_ext_ctrls,
  851. .try_ext_ctrls = v4l2_subdev_try_ext_ctrls,
  852. .s_ext_ctrls = v4l2_subdev_s_ext_ctrls,
  853. .g_ctrl = v4l2_subdev_g_ctrl,
  854. .s_ctrl = v4l2_subdev_s_ctrl,
  855. .queryctrl = v4l2_subdev_queryctrl,
  856. .querymenu = v4l2_subdev_querymenu,
  857. .s_std = tvp514x_s_std,
  858. };
  859. static const struct v4l2_subdev_video_ops tvp514x_video_ops = {
  860. .s_routing = tvp514x_s_routing,
  861. .querystd = tvp514x_querystd,
  862. .enum_mbus_fmt = tvp514x_enum_mbus_fmt,
  863. .g_mbus_fmt = tvp514x_mbus_fmt,
  864. .try_mbus_fmt = tvp514x_mbus_fmt,
  865. .s_mbus_fmt = tvp514x_mbus_fmt,
  866. .g_parm = tvp514x_g_parm,
  867. .s_parm = tvp514x_s_parm,
  868. .s_stream = tvp514x_s_stream,
  869. };
  870. static const struct v4l2_subdev_ops tvp514x_ops = {
  871. .core = &tvp514x_core_ops,
  872. .video = &tvp514x_video_ops,
  873. };
  874. static struct tvp514x_decoder tvp514x_dev = {
  875. .streaming = 0,
  876. .current_std = STD_NTSC_MJ,
  877. .std_list = tvp514x_std_list,
  878. .num_stds = ARRAY_SIZE(tvp514x_std_list),
  879. };
  880. /**
  881. * tvp514x_probe() - decoder driver i2c probe handler
  882. * @client: i2c driver client device structure
  883. * @id: i2c driver id table
  884. *
  885. * Register decoder as an i2c client device and V4L2
  886. * device.
  887. */
  888. static int
  889. tvp514x_probe(struct i2c_client *client, const struct i2c_device_id *id)
  890. {
  891. struct tvp514x_decoder *decoder;
  892. struct v4l2_subdev *sd;
  893. /* Check if the adapter supports the needed features */
  894. if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
  895. return -EIO;
  896. if (!client->dev.platform_data) {
  897. v4l2_err(client, "No platform data!!\n");
  898. return -ENODEV;
  899. }
  900. decoder = kzalloc(sizeof(*decoder), GFP_KERNEL);
  901. if (!decoder)
  902. return -ENOMEM;
  903. /* Initialize the tvp514x_decoder with default configuration */
  904. *decoder = tvp514x_dev;
  905. /* Copy default register configuration */
  906. memcpy(decoder->tvp514x_regs, tvp514x_reg_list_default,
  907. sizeof(tvp514x_reg_list_default));
  908. /* Copy board specific information here */
  909. decoder->pdata = client->dev.platform_data;
  910. /**
  911. * Fetch platform specific data, and configure the
  912. * tvp514x_reg_list[] accordingly. Since this is one
  913. * time configuration, no need to preserve.
  914. */
  915. decoder->tvp514x_regs[REG_OUTPUT_FORMATTER2].val |=
  916. (decoder->pdata->clk_polarity << 1);
  917. decoder->tvp514x_regs[REG_SYNC_CONTROL].val |=
  918. ((decoder->pdata->hs_polarity << 2) |
  919. (decoder->pdata->vs_polarity << 3));
  920. /* Set default standard to auto */
  921. decoder->tvp514x_regs[REG_VIDEO_STD].val =
  922. VIDEO_STD_AUTO_SWITCH_BIT;
  923. /* Register with V4L2 layer as slave device */
  924. sd = &decoder->sd;
  925. v4l2_i2c_subdev_init(sd, client, &tvp514x_ops);
  926. v4l2_ctrl_handler_init(&decoder->hdl, 5);
  927. v4l2_ctrl_new_std(&decoder->hdl, &tvp514x_ctrl_ops,
  928. V4L2_CID_BRIGHTNESS, 0, 255, 1, 128);
  929. v4l2_ctrl_new_std(&decoder->hdl, &tvp514x_ctrl_ops,
  930. V4L2_CID_CONTRAST, 0, 255, 1, 128);
  931. v4l2_ctrl_new_std(&decoder->hdl, &tvp514x_ctrl_ops,
  932. V4L2_CID_SATURATION, 0, 255, 1, 128);
  933. v4l2_ctrl_new_std(&decoder->hdl, &tvp514x_ctrl_ops,
  934. V4L2_CID_HUE, -180, 180, 180, 0);
  935. v4l2_ctrl_new_std(&decoder->hdl, &tvp514x_ctrl_ops,
  936. V4L2_CID_AUTOGAIN, 0, 1, 1, 1);
  937. sd->ctrl_handler = &decoder->hdl;
  938. if (decoder->hdl.error) {
  939. int err = decoder->hdl.error;
  940. v4l2_ctrl_handler_free(&decoder->hdl);
  941. kfree(decoder);
  942. return err;
  943. }
  944. v4l2_ctrl_handler_setup(&decoder->hdl);
  945. v4l2_info(sd, "%s decoder driver registered !!\n", sd->name);
  946. return 0;
  947. }
  948. /**
  949. * tvp514x_remove() - decoder driver i2c remove handler
  950. * @client: i2c driver client device structure
  951. *
  952. * Unregister decoder as an i2c client device and V4L2
  953. * device. Complement of tvp514x_probe().
  954. */
  955. static int tvp514x_remove(struct i2c_client *client)
  956. {
  957. struct v4l2_subdev *sd = i2c_get_clientdata(client);
  958. struct tvp514x_decoder *decoder = to_decoder(sd);
  959. v4l2_device_unregister_subdev(sd);
  960. v4l2_ctrl_handler_free(&decoder->hdl);
  961. kfree(decoder);
  962. return 0;
  963. }
  964. /* TVP5146 Init/Power on Sequence */
  965. static const struct tvp514x_reg tvp5146_init_reg_seq[] = {
  966. {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS1, 0x02},
  967. {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS2, 0x00},
  968. {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS3, 0x80},
  969. {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x01},
  970. {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS1, 0x60},
  971. {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS2, 0x00},
  972. {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS3, 0xB0},
  973. {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x01},
  974. {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x00},
  975. {TOK_WRITE, REG_OPERATION_MODE, 0x01},
  976. {TOK_WRITE, REG_OPERATION_MODE, 0x00},
  977. {TOK_TERM, 0, 0},
  978. };
  979. /* TVP5147 Init/Power on Sequence */
  980. static const struct tvp514x_reg tvp5147_init_reg_seq[] = {
  981. {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS1, 0x02},
  982. {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS2, 0x00},
  983. {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS3, 0x80},
  984. {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x01},
  985. {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS1, 0x60},
  986. {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS2, 0x00},
  987. {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS3, 0xB0},
  988. {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x01},
  989. {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS1, 0x16},
  990. {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS2, 0x00},
  991. {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS3, 0xA0},
  992. {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x16},
  993. {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS1, 0x60},
  994. {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS2, 0x00},
  995. {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS3, 0xB0},
  996. {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x00},
  997. {TOK_WRITE, REG_OPERATION_MODE, 0x01},
  998. {TOK_WRITE, REG_OPERATION_MODE, 0x00},
  999. {TOK_TERM, 0, 0},
  1000. };
  1001. /* TVP5146M2/TVP5147M1 Init/Power on Sequence */
  1002. static const struct tvp514x_reg tvp514xm_init_reg_seq[] = {
  1003. {TOK_WRITE, REG_OPERATION_MODE, 0x01},
  1004. {TOK_WRITE, REG_OPERATION_MODE, 0x00},
  1005. {TOK_TERM, 0, 0},
  1006. };
  1007. /**
  1008. * I2C Device Table -
  1009. *
  1010. * name - Name of the actual device/chip.
  1011. * driver_data - Driver data
  1012. */
  1013. static const struct i2c_device_id tvp514x_id[] = {
  1014. {"tvp5146", (unsigned long)tvp5146_init_reg_seq},
  1015. {"tvp5146m2", (unsigned long)tvp514xm_init_reg_seq},
  1016. {"tvp5147", (unsigned long)tvp5147_init_reg_seq},
  1017. {"tvp5147m1", (unsigned long)tvp514xm_init_reg_seq},
  1018. {},
  1019. };
  1020. MODULE_DEVICE_TABLE(i2c, tvp514x_id);
  1021. static struct i2c_driver tvp514x_driver = {
  1022. .driver = {
  1023. .owner = THIS_MODULE,
  1024. .name = TVP514X_MODULE_NAME,
  1025. },
  1026. .probe = tvp514x_probe,
  1027. .remove = tvp514x_remove,
  1028. .id_table = tvp514x_id,
  1029. };
  1030. module_i2c_driver(tvp514x_driver);