ths8200.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. /*
  2. * ths8200 - Texas Instruments THS8200 video encoder driver
  3. *
  4. * Copyright 2013 Cisco Systems, Inc. and/or its affiliates.
  5. *
  6. * This program is free software; you may redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; version 2 of the License.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation version 2.
  13. *
  14. * This program is distributed .as is. WITHOUT ANY WARRANTY of any
  15. * kind, whether express or implied; without even the implied warranty
  16. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. */
  19. #include <linux/i2c.h>
  20. #include <linux/module.h>
  21. #include <linux/v4l2-dv-timings.h>
  22. #include <media/v4l2-dv-timings.h>
  23. #include <media/v4l2-async.h>
  24. #include <media/v4l2-device.h>
  25. #include "ths8200_regs.h"
  26. static int debug;
  27. module_param(debug, int, 0644);
  28. MODULE_PARM_DESC(debug, "debug level (0-2)");
  29. MODULE_DESCRIPTION("Texas Instruments THS8200 video encoder driver");
  30. MODULE_AUTHOR("Mats Randgaard <mats.randgaard@cisco.com>");
  31. MODULE_AUTHOR("Martin Bugge <martin.bugge@cisco.com>");
  32. MODULE_LICENSE("GPL v2");
  33. struct ths8200_state {
  34. struct v4l2_subdev sd;
  35. uint8_t chip_version;
  36. /* Is the ths8200 powered on? */
  37. bool power_on;
  38. struct v4l2_dv_timings dv_timings;
  39. };
  40. static const struct v4l2_dv_timings ths8200_timings[] = {
  41. V4L2_DV_BT_CEA_720X480P59_94,
  42. V4L2_DV_BT_CEA_1280X720P24,
  43. V4L2_DV_BT_CEA_1280X720P25,
  44. V4L2_DV_BT_CEA_1280X720P30,
  45. V4L2_DV_BT_CEA_1280X720P50,
  46. V4L2_DV_BT_CEA_1280X720P60,
  47. V4L2_DV_BT_CEA_1920X1080P24,
  48. V4L2_DV_BT_CEA_1920X1080P25,
  49. V4L2_DV_BT_CEA_1920X1080P30,
  50. V4L2_DV_BT_CEA_1920X1080P50,
  51. V4L2_DV_BT_CEA_1920X1080P60,
  52. };
  53. static inline struct ths8200_state *to_state(struct v4l2_subdev *sd)
  54. {
  55. return container_of(sd, struct ths8200_state, sd);
  56. }
  57. static inline unsigned hblanking(const struct v4l2_bt_timings *t)
  58. {
  59. return V4L2_DV_BT_BLANKING_WIDTH(t);
  60. }
  61. static inline unsigned htotal(const struct v4l2_bt_timings *t)
  62. {
  63. return V4L2_DV_BT_FRAME_WIDTH(t);
  64. }
  65. static inline unsigned vblanking(const struct v4l2_bt_timings *t)
  66. {
  67. return V4L2_DV_BT_BLANKING_HEIGHT(t);
  68. }
  69. static inline unsigned vtotal(const struct v4l2_bt_timings *t)
  70. {
  71. return V4L2_DV_BT_FRAME_HEIGHT(t);
  72. }
  73. static int ths8200_read(struct v4l2_subdev *sd, u8 reg)
  74. {
  75. struct i2c_client *client = v4l2_get_subdevdata(sd);
  76. return i2c_smbus_read_byte_data(client, reg);
  77. }
  78. static int ths8200_write(struct v4l2_subdev *sd, u8 reg, u8 val)
  79. {
  80. struct i2c_client *client = v4l2_get_subdevdata(sd);
  81. int ret;
  82. int i;
  83. for (i = 0; i < 3; i++) {
  84. ret = i2c_smbus_write_byte_data(client, reg, val);
  85. if (ret == 0)
  86. return 0;
  87. }
  88. v4l2_err(sd, "I2C Write Problem\n");
  89. return ret;
  90. }
  91. /* To set specific bits in the register, a clear-mask is given (to be AND-ed),
  92. * and then the value-mask (to be OR-ed).
  93. */
  94. static inline void
  95. ths8200_write_and_or(struct v4l2_subdev *sd, u8 reg,
  96. uint8_t clr_mask, uint8_t val_mask)
  97. {
  98. ths8200_write(sd, reg, (ths8200_read(sd, reg) & clr_mask) | val_mask);
  99. }
  100. #ifdef CONFIG_VIDEO_ADV_DEBUG
  101. static int ths8200_g_register(struct v4l2_subdev *sd,
  102. struct v4l2_dbg_register *reg)
  103. {
  104. reg->val = ths8200_read(sd, reg->reg & 0xff);
  105. reg->size = 1;
  106. return 0;
  107. }
  108. static int ths8200_s_register(struct v4l2_subdev *sd,
  109. const struct v4l2_dbg_register *reg)
  110. {
  111. ths8200_write(sd, reg->reg & 0xff, reg->val & 0xff);
  112. return 0;
  113. }
  114. #endif
  115. static void ths8200_print_timings(struct v4l2_subdev *sd,
  116. struct v4l2_dv_timings *timings,
  117. const char *txt, bool detailed)
  118. {
  119. struct v4l2_bt_timings *bt = &timings->bt;
  120. u32 htot, vtot;
  121. if (timings->type != V4L2_DV_BT_656_1120)
  122. return;
  123. htot = htotal(bt);
  124. vtot = vtotal(bt);
  125. v4l2_info(sd, "%s %dx%d%s%d (%dx%d)",
  126. txt, bt->width, bt->height, bt->interlaced ? "i" : "p",
  127. (htot * vtot) > 0 ? ((u32)bt->pixelclock / (htot * vtot)) : 0,
  128. htot, vtot);
  129. if (detailed) {
  130. v4l2_info(sd, " horizontal: fp = %d, %ssync = %d, bp = %d\n",
  131. bt->hfrontporch,
  132. (bt->polarities & V4L2_DV_HSYNC_POS_POL) ? "+" : "-",
  133. bt->hsync, bt->hbackporch);
  134. v4l2_info(sd, " vertical: fp = %d, %ssync = %d, bp = %d\n",
  135. bt->vfrontporch,
  136. (bt->polarities & V4L2_DV_VSYNC_POS_POL) ? "+" : "-",
  137. bt->vsync, bt->vbackporch);
  138. v4l2_info(sd,
  139. " pixelclock: %lld, flags: 0x%x, standards: 0x%x\n",
  140. bt->pixelclock, bt->flags, bt->standards);
  141. }
  142. }
  143. static int ths8200_log_status(struct v4l2_subdev *sd)
  144. {
  145. struct ths8200_state *state = to_state(sd);
  146. uint8_t reg_03 = ths8200_read(sd, THS8200_CHIP_CTL);
  147. v4l2_info(sd, "----- Chip status -----\n");
  148. v4l2_info(sd, "version: %u\n", state->chip_version);
  149. v4l2_info(sd, "power: %s\n", (reg_03 & 0x0c) ? "off" : "on");
  150. v4l2_info(sd, "reset: %s\n", (reg_03 & 0x01) ? "off" : "on");
  151. v4l2_info(sd, "test pattern: %s\n",
  152. (reg_03 & 0x20) ? "enabled" : "disabled");
  153. v4l2_info(sd, "format: %ux%u\n",
  154. ths8200_read(sd, THS8200_DTG2_PIXEL_CNT_MSB) * 256 +
  155. ths8200_read(sd, THS8200_DTG2_PIXEL_CNT_LSB),
  156. (ths8200_read(sd, THS8200_DTG2_LINE_CNT_MSB) & 0x07) * 256 +
  157. ths8200_read(sd, THS8200_DTG2_LINE_CNT_LSB));
  158. ths8200_print_timings(sd, &state->dv_timings,
  159. "Configured format:", true);
  160. return 0;
  161. }
  162. /* Power up/down ths8200 */
  163. static int ths8200_s_power(struct v4l2_subdev *sd, int on)
  164. {
  165. struct ths8200_state *state = to_state(sd);
  166. v4l2_dbg(1, debug, sd, "%s: power %s\n", __func__, on ? "on" : "off");
  167. state->power_on = on;
  168. /* Power up/down - leave in reset state until input video is present */
  169. ths8200_write_and_or(sd, THS8200_CHIP_CTL, 0xf2, (on ? 0x00 : 0x0c));
  170. return 0;
  171. }
  172. static const struct v4l2_subdev_core_ops ths8200_core_ops = {
  173. .log_status = ths8200_log_status,
  174. .s_power = ths8200_s_power,
  175. #ifdef CONFIG_VIDEO_ADV_DEBUG
  176. .g_register = ths8200_g_register,
  177. .s_register = ths8200_s_register,
  178. #endif
  179. };
  180. /* -----------------------------------------------------------------------------
  181. * V4L2 subdev video operations
  182. */
  183. static int ths8200_s_stream(struct v4l2_subdev *sd, int enable)
  184. {
  185. struct ths8200_state *state = to_state(sd);
  186. if (enable && !state->power_on)
  187. ths8200_s_power(sd, true);
  188. ths8200_write_and_or(sd, THS8200_CHIP_CTL, 0xfe,
  189. (enable ? 0x01 : 0x00));
  190. v4l2_dbg(1, debug, sd, "%s: %sable\n",
  191. __func__, (enable ? "en" : "dis"));
  192. return 0;
  193. }
  194. static void ths8200_core_init(struct v4l2_subdev *sd)
  195. {
  196. /* setup clocks */
  197. ths8200_write_and_or(sd, THS8200_CHIP_CTL, 0x3f, 0xc0);
  198. /**** Data path control (DATA) ****/
  199. /* Set FSADJ 700 mV,
  200. * bypass 422-444 interpolation,
  201. * input format 30 bit RGB444
  202. */
  203. ths8200_write(sd, THS8200_DATA_CNTL, 0x70);
  204. /* DTG Mode (Video blocked during blanking
  205. * VESA slave
  206. */
  207. ths8200_write(sd, THS8200_DTG1_MODE, 0x87);
  208. /**** Display Timing Generator Control, Part 1 (DTG1). ****/
  209. /* Disable embedded syncs on the output by setting
  210. * the amplitude to zero for all channels.
  211. */
  212. ths8200_write(sd, THS8200_DTG1_Y_SYNC_MSB, 0x2a);
  213. ths8200_write(sd, THS8200_DTG1_CBCR_SYNC_MSB, 0x2a);
  214. }
  215. static void ths8200_setup(struct v4l2_subdev *sd, struct v4l2_bt_timings *bt)
  216. {
  217. uint8_t polarity = 0;
  218. uint16_t line_start_active_video = (bt->vsync + bt->vbackporch);
  219. uint16_t line_start_front_porch = (vtotal(bt) - bt->vfrontporch);
  220. /*** System ****/
  221. /* Set chip in reset while it is configured */
  222. ths8200_s_stream(sd, false);
  223. /* configure video output timings */
  224. ths8200_write(sd, THS8200_DTG1_SPEC_A, bt->hsync);
  225. ths8200_write(sd, THS8200_DTG1_SPEC_B, bt->hfrontporch);
  226. /* Zero for progressive scan formats.*/
  227. if (!bt->interlaced)
  228. ths8200_write(sd, THS8200_DTG1_SPEC_C, 0x00);
  229. /* Distance from leading edge of h sync to start of active video.
  230. * MSB in 0x2b
  231. */
  232. ths8200_write(sd, THS8200_DTG1_SPEC_D_LSB,
  233. (bt->hbackporch + bt->hsync) & 0xff);
  234. /* Zero for SDTV-mode. MSB in 0x2b */
  235. ths8200_write(sd, THS8200_DTG1_SPEC_E_LSB, 0x00);
  236. /*
  237. * MSB for dtg1_spec(d/e/h). See comment for
  238. * corresponding LSB registers.
  239. */
  240. ths8200_write(sd, THS8200_DTG1_SPEC_DEH_MSB,
  241. ((bt->hbackporch + bt->hsync) & 0x100) >> 1);
  242. /* h front porch */
  243. ths8200_write(sd, THS8200_DTG1_SPEC_K_LSB, (bt->hfrontporch) & 0xff);
  244. ths8200_write(sd, THS8200_DTG1_SPEC_K_MSB,
  245. ((bt->hfrontporch) & 0x700) >> 8);
  246. /* Half the line length. Used to calculate SDTV line types. */
  247. ths8200_write(sd, THS8200_DTG1_SPEC_G_LSB, (htotal(bt)/2) & 0xff);
  248. ths8200_write(sd, THS8200_DTG1_SPEC_G_MSB,
  249. ((htotal(bt)/2) >> 8) & 0x0f);
  250. /* Total pixels per line (ex. 720p: 1650) */
  251. ths8200_write(sd, THS8200_DTG1_TOT_PIXELS_MSB, htotal(bt) >> 8);
  252. ths8200_write(sd, THS8200_DTG1_TOT_PIXELS_LSB, htotal(bt) & 0xff);
  253. /* Frame height and field height */
  254. /* Field height should be programmed higher than frame_size for
  255. * progressive scan formats
  256. */
  257. ths8200_write(sd, THS8200_DTG1_FRAME_FIELD_SZ_MSB,
  258. ((vtotal(bt) >> 4) & 0xf0) + 0x7);
  259. ths8200_write(sd, THS8200_DTG1_FRAME_SZ_LSB, vtotal(bt) & 0xff);
  260. /* Should be programmed higher than frame_size
  261. * for progressive formats
  262. */
  263. if (!bt->interlaced)
  264. ths8200_write(sd, THS8200_DTG1_FIELD_SZ_LSB, 0xff);
  265. /**** Display Timing Generator Control, Part 2 (DTG2). ****/
  266. /* Set breakpoint line numbers and types
  267. * THS8200 generates line types with different properties. A line type
  268. * that sets all the RGB-outputs to zero is used in the blanking areas,
  269. * while a line type that enable the RGB-outputs is used in active video
  270. * area. The line numbers for start of active video, start of front
  271. * porch and after the last line in the frame must be set with the
  272. * corresponding line types.
  273. *
  274. * Line types:
  275. * 0x9 - Full normal sync pulse: Blocks data when dtg1_pass is off.
  276. * Used in blanking area.
  277. * 0x0 - Active video: Video data is always passed. Used in active
  278. * video area.
  279. */
  280. ths8200_write_and_or(sd, THS8200_DTG2_BP1_2_MSB, 0x88,
  281. ((line_start_active_video >> 4) & 0x70) +
  282. ((line_start_front_porch >> 8) & 0x07));
  283. ths8200_write(sd, THS8200_DTG2_BP3_4_MSB, ((vtotal(bt)) >> 4) & 0x70);
  284. ths8200_write(sd, THS8200_DTG2_BP1_LSB, line_start_active_video & 0xff);
  285. ths8200_write(sd, THS8200_DTG2_BP2_LSB, line_start_front_porch & 0xff);
  286. ths8200_write(sd, THS8200_DTG2_BP3_LSB, (vtotal(bt)) & 0xff);
  287. /* line types */
  288. ths8200_write(sd, THS8200_DTG2_LINETYPE1, 0x90);
  289. ths8200_write(sd, THS8200_DTG2_LINETYPE2, 0x90);
  290. /* h sync width transmitted */
  291. ths8200_write(sd, THS8200_DTG2_HLENGTH_LSB, bt->hsync & 0xff);
  292. ths8200_write_and_or(sd, THS8200_DTG2_HLENGTH_LSB_HDLY_MSB, 0x3f,
  293. (bt->hsync >> 2) & 0xc0);
  294. /* The pixel value h sync is asserted on */
  295. ths8200_write_and_or(sd, THS8200_DTG2_HLENGTH_LSB_HDLY_MSB, 0xe0,
  296. (htotal(bt) >> 8) & 0x1f);
  297. ths8200_write(sd, THS8200_DTG2_HLENGTH_HDLY_LSB, htotal(bt));
  298. /* v sync width transmitted */
  299. ths8200_write(sd, THS8200_DTG2_VLENGTH1_LSB, (bt->vsync) & 0xff);
  300. ths8200_write_and_or(sd, THS8200_DTG2_VLENGTH1_MSB_VDLY1_MSB, 0x3f,
  301. ((bt->vsync) >> 2) & 0xc0);
  302. /* The pixel value v sync is asserted on */
  303. ths8200_write_and_or(sd, THS8200_DTG2_VLENGTH1_MSB_VDLY1_MSB, 0xf8,
  304. (vtotal(bt)>>8) & 0x7);
  305. ths8200_write(sd, THS8200_DTG2_VDLY1_LSB, vtotal(bt));
  306. /* For progressive video vlength2 must be set to all 0 and vdly2 must
  307. * be set to all 1.
  308. */
  309. ths8200_write(sd, THS8200_DTG2_VLENGTH2_LSB, 0x00);
  310. ths8200_write(sd, THS8200_DTG2_VLENGTH2_MSB_VDLY2_MSB, 0x07);
  311. ths8200_write(sd, THS8200_DTG2_VDLY2_LSB, 0xff);
  312. /* Internal delay factors to synchronize the sync pulses and the data */
  313. /* Experimental values delays (hor 4, ver 1) */
  314. ths8200_write(sd, THS8200_DTG2_HS_IN_DLY_MSB, (htotal(bt)>>8) & 0x1f);
  315. ths8200_write(sd, THS8200_DTG2_HS_IN_DLY_LSB, (htotal(bt) - 4) & 0xff);
  316. ths8200_write(sd, THS8200_DTG2_VS_IN_DLY_MSB, 0);
  317. ths8200_write(sd, THS8200_DTG2_VS_IN_DLY_LSB, 1);
  318. /* Polarity of received and transmitted sync signals */
  319. if (bt->polarities & V4L2_DV_HSYNC_POS_POL) {
  320. polarity |= 0x01; /* HS_IN */
  321. polarity |= 0x08; /* HS_OUT */
  322. }
  323. if (bt->polarities & V4L2_DV_VSYNC_POS_POL) {
  324. polarity |= 0x02; /* VS_IN */
  325. polarity |= 0x10; /* VS_OUT */
  326. }
  327. /* RGB mode, no embedded timings */
  328. /* Timing of video input bus is derived from HS, VS, and FID dedicated
  329. * inputs
  330. */
  331. ths8200_write(sd, THS8200_DTG2_CNTL, 0x47 | polarity);
  332. /* leave reset */
  333. ths8200_s_stream(sd, true);
  334. v4l2_dbg(1, debug, sd, "%s: frame %dx%d, polarity %d\n"
  335. "horizontal: front porch %d, back porch %d, sync %d\n"
  336. "vertical: sync %d\n", __func__, htotal(bt), vtotal(bt),
  337. polarity, bt->hfrontporch, bt->hbackporch,
  338. bt->hsync, bt->vsync);
  339. }
  340. static int ths8200_s_dv_timings(struct v4l2_subdev *sd,
  341. struct v4l2_dv_timings *timings)
  342. {
  343. struct ths8200_state *state = to_state(sd);
  344. int i;
  345. v4l2_dbg(1, debug, sd, "%s:\n", __func__);
  346. if (timings->type != V4L2_DV_BT_656_1120)
  347. return -EINVAL;
  348. /* TODO Support interlaced formats */
  349. if (timings->bt.interlaced) {
  350. v4l2_dbg(1, debug, sd, "TODO Support interlaced formats\n");
  351. return -EINVAL;
  352. }
  353. for (i = 0; i < ARRAY_SIZE(ths8200_timings); i++) {
  354. if (v4l_match_dv_timings(&ths8200_timings[i], timings, 10))
  355. break;
  356. }
  357. if (i == ARRAY_SIZE(ths8200_timings)) {
  358. v4l2_dbg(1, debug, sd, "Unsupported format\n");
  359. return -EINVAL;
  360. }
  361. timings->bt.flags &= ~V4L2_DV_FL_REDUCED_FPS;
  362. /* save timings */
  363. state->dv_timings = *timings;
  364. ths8200_setup(sd, &timings->bt);
  365. return 0;
  366. }
  367. static int ths8200_g_dv_timings(struct v4l2_subdev *sd,
  368. struct v4l2_dv_timings *timings)
  369. {
  370. struct ths8200_state *state = to_state(sd);
  371. v4l2_dbg(1, debug, sd, "%s:\n", __func__);
  372. *timings = state->dv_timings;
  373. return 0;
  374. }
  375. static int ths8200_enum_dv_timings(struct v4l2_subdev *sd,
  376. struct v4l2_enum_dv_timings *timings)
  377. {
  378. /* Check requested format index is within range */
  379. if (timings->index >= ARRAY_SIZE(ths8200_timings))
  380. return -EINVAL;
  381. timings->timings = ths8200_timings[timings->index];
  382. return 0;
  383. }
  384. static int ths8200_dv_timings_cap(struct v4l2_subdev *sd,
  385. struct v4l2_dv_timings_cap *cap)
  386. {
  387. cap->type = V4L2_DV_BT_656_1120;
  388. cap->bt.max_width = 1920;
  389. cap->bt.max_height = 1080;
  390. cap->bt.min_pixelclock = 27000000;
  391. cap->bt.max_pixelclock = 148500000;
  392. cap->bt.standards = V4L2_DV_BT_STD_CEA861;
  393. cap->bt.capabilities = V4L2_DV_BT_CAP_PROGRESSIVE;
  394. return 0;
  395. }
  396. /* Specific video subsystem operation handlers */
  397. static const struct v4l2_subdev_video_ops ths8200_video_ops = {
  398. .s_stream = ths8200_s_stream,
  399. .s_dv_timings = ths8200_s_dv_timings,
  400. .g_dv_timings = ths8200_g_dv_timings,
  401. .enum_dv_timings = ths8200_enum_dv_timings,
  402. .dv_timings_cap = ths8200_dv_timings_cap,
  403. };
  404. /* V4L2 top level operation handlers */
  405. static const struct v4l2_subdev_ops ths8200_ops = {
  406. .core = &ths8200_core_ops,
  407. .video = &ths8200_video_ops,
  408. };
  409. static int ths8200_probe(struct i2c_client *client,
  410. const struct i2c_device_id *id)
  411. {
  412. struct ths8200_state *state;
  413. struct v4l2_subdev *sd;
  414. int error;
  415. /* Check if the adapter supports the needed features */
  416. if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
  417. return -EIO;
  418. state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL);
  419. if (!state)
  420. return -ENOMEM;
  421. sd = &state->sd;
  422. v4l2_i2c_subdev_init(sd, client, &ths8200_ops);
  423. state->chip_version = ths8200_read(sd, THS8200_VERSION);
  424. v4l2_dbg(1, debug, sd, "chip version 0x%x\n", state->chip_version);
  425. ths8200_core_init(sd);
  426. error = v4l2_async_register_subdev(&state->sd);
  427. if (error)
  428. return error;
  429. v4l2_info(sd, "%s found @ 0x%x (%s)\n", client->name,
  430. client->addr << 1, client->adapter->name);
  431. return 0;
  432. }
  433. static int ths8200_remove(struct i2c_client *client)
  434. {
  435. struct v4l2_subdev *sd = i2c_get_clientdata(client);
  436. struct ths8200_state *decoder = to_state(sd);
  437. v4l2_dbg(1, debug, sd, "%s removed @ 0x%x (%s)\n", client->name,
  438. client->addr << 1, client->adapter->name);
  439. ths8200_s_power(sd, false);
  440. v4l2_async_unregister_subdev(&decoder->sd);
  441. v4l2_device_unregister_subdev(sd);
  442. return 0;
  443. }
  444. static struct i2c_device_id ths8200_id[] = {
  445. { "ths8200", 0 },
  446. {},
  447. };
  448. MODULE_DEVICE_TABLE(i2c, ths8200_id);
  449. #if IS_ENABLED(CONFIG_OF)
  450. static const struct of_device_id ths8200_of_match[] = {
  451. { .compatible = "ti,ths8200", },
  452. { /* sentinel */ },
  453. };
  454. MODULE_DEVICE_TABLE(of, ths8200_of_match);
  455. #endif
  456. static struct i2c_driver ths8200_driver = {
  457. .driver = {
  458. .owner = THIS_MODULE,
  459. .name = "ths8200",
  460. .of_match_table = of_match_ptr(ths8200_of_match),
  461. },
  462. .probe = ths8200_probe,
  463. .remove = ths8200_remove,
  464. .id_table = ths8200_id,
  465. };
  466. module_i2c_driver(ths8200_driver);