tvp514x.c 32 KB

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