fc2580.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. /*
  2. * FCI FC2580 silicon tuner driver
  3. *
  4. * Copyright (C) 2012 Antti Palosaari <crope@iki.fi>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. */
  20. #include "fc2580_priv.h"
  21. /*
  22. * TODO:
  23. * I2C write and read works only for one single register. Multiple registers
  24. * could not be accessed using normal register address auto-increment.
  25. * There could be (very likely) register to change that behavior....
  26. */
  27. /* write single register conditionally only when value differs from 0xff
  28. * XXX: This is special routine meant only for writing fc2580_freq_regs_lut[]
  29. * values. Do not use for the other purposes. */
  30. static int fc2580_wr_reg_ff(struct fc2580_dev *dev, u8 reg, u8 val)
  31. {
  32. if (val == 0xff)
  33. return 0;
  34. else
  35. return regmap_write(dev->regmap, reg, val);
  36. }
  37. static int fc2580_set_params(struct fc2580_dev *dev)
  38. {
  39. struct i2c_client *client = dev->client;
  40. int ret, i;
  41. unsigned int uitmp, div_ref, div_ref_val, div_n, k, k_cw, div_out;
  42. u64 f_vco;
  43. u8 synth_config;
  44. unsigned long timeout;
  45. if (!dev->active) {
  46. dev_dbg(&client->dev, "tuner is sleeping\n");
  47. return 0;
  48. }
  49. /*
  50. * Fractional-N synthesizer
  51. *
  52. * +---------------------------------------+
  53. * v |
  54. * Fref +----+ +----+ +-------+ +----+ +------+ +---+
  55. * ------> | /R | --> | PD | --> | VCO | ------> | /2 | --> | /N.F | <-- | K |
  56. * +----+ +----+ +-------+ +----+ +------+ +---+
  57. * |
  58. * |
  59. * v
  60. * +-------+ Fout
  61. * | /Rout | ------>
  62. * +-------+
  63. */
  64. for (i = 0; i < ARRAY_SIZE(fc2580_pll_lut); i++) {
  65. if (dev->f_frequency <= fc2580_pll_lut[i].freq)
  66. break;
  67. }
  68. if (i == ARRAY_SIZE(fc2580_pll_lut)) {
  69. ret = -EINVAL;
  70. goto err;
  71. }
  72. #define DIV_PRE_N 2
  73. #define F_REF dev->clk
  74. div_out = fc2580_pll_lut[i].div_out;
  75. f_vco = (u64) dev->f_frequency * div_out;
  76. synth_config = fc2580_pll_lut[i].band;
  77. if (f_vco < 2600000000ULL)
  78. synth_config |= 0x06;
  79. else
  80. synth_config |= 0x0e;
  81. /* select reference divider R (keep PLL div N in valid range) */
  82. #define DIV_N_MIN 76
  83. if (f_vco >= div_u64((u64) DIV_PRE_N * DIV_N_MIN * F_REF, 1)) {
  84. div_ref = 1;
  85. div_ref_val = 0x00;
  86. } else if (f_vco >= div_u64((u64) DIV_PRE_N * DIV_N_MIN * F_REF, 2)) {
  87. div_ref = 2;
  88. div_ref_val = 0x10;
  89. } else {
  90. div_ref = 4;
  91. div_ref_val = 0x20;
  92. }
  93. /* calculate PLL integer and fractional control word */
  94. uitmp = DIV_PRE_N * F_REF / div_ref;
  95. div_n = div_u64_rem(f_vco, uitmp, &k);
  96. k_cw = div_u64((u64) k * 0x100000, uitmp);
  97. dev_dbg(&client->dev,
  98. "frequency=%u bandwidth=%u f_vco=%llu F_REF=%u div_ref=%u div_n=%u k=%u div_out=%u k_cw=%0x\n",
  99. dev->f_frequency, dev->f_bandwidth, f_vco, F_REF, div_ref,
  100. div_n, k, div_out, k_cw);
  101. ret = regmap_write(dev->regmap, 0x02, synth_config);
  102. if (ret)
  103. goto err;
  104. ret = regmap_write(dev->regmap, 0x18, div_ref_val << 0 | k_cw >> 16);
  105. if (ret)
  106. goto err;
  107. ret = regmap_write(dev->regmap, 0x1a, (k_cw >> 8) & 0xff);
  108. if (ret)
  109. goto err;
  110. ret = regmap_write(dev->regmap, 0x1b, (k_cw >> 0) & 0xff);
  111. if (ret)
  112. goto err;
  113. ret = regmap_write(dev->regmap, 0x1c, div_n);
  114. if (ret)
  115. goto err;
  116. /* registers */
  117. for (i = 0; i < ARRAY_SIZE(fc2580_freq_regs_lut); i++) {
  118. if (dev->f_frequency <= fc2580_freq_regs_lut[i].freq)
  119. break;
  120. }
  121. if (i == ARRAY_SIZE(fc2580_freq_regs_lut)) {
  122. ret = -EINVAL;
  123. goto err;
  124. }
  125. ret = fc2580_wr_reg_ff(dev, 0x25, fc2580_freq_regs_lut[i].r25_val);
  126. if (ret)
  127. goto err;
  128. ret = fc2580_wr_reg_ff(dev, 0x27, fc2580_freq_regs_lut[i].r27_val);
  129. if (ret)
  130. goto err;
  131. ret = fc2580_wr_reg_ff(dev, 0x28, fc2580_freq_regs_lut[i].r28_val);
  132. if (ret)
  133. goto err;
  134. ret = fc2580_wr_reg_ff(dev, 0x29, fc2580_freq_regs_lut[i].r29_val);
  135. if (ret)
  136. goto err;
  137. ret = fc2580_wr_reg_ff(dev, 0x2b, fc2580_freq_regs_lut[i].r2b_val);
  138. if (ret)
  139. goto err;
  140. ret = fc2580_wr_reg_ff(dev, 0x2c, fc2580_freq_regs_lut[i].r2c_val);
  141. if (ret)
  142. goto err;
  143. ret = fc2580_wr_reg_ff(dev, 0x2d, fc2580_freq_regs_lut[i].r2d_val);
  144. if (ret)
  145. goto err;
  146. ret = fc2580_wr_reg_ff(dev, 0x30, fc2580_freq_regs_lut[i].r30_val);
  147. if (ret)
  148. goto err;
  149. ret = fc2580_wr_reg_ff(dev, 0x44, fc2580_freq_regs_lut[i].r44_val);
  150. if (ret)
  151. goto err;
  152. ret = fc2580_wr_reg_ff(dev, 0x50, fc2580_freq_regs_lut[i].r50_val);
  153. if (ret)
  154. goto err;
  155. ret = fc2580_wr_reg_ff(dev, 0x53, fc2580_freq_regs_lut[i].r53_val);
  156. if (ret)
  157. goto err;
  158. ret = fc2580_wr_reg_ff(dev, 0x5f, fc2580_freq_regs_lut[i].r5f_val);
  159. if (ret)
  160. goto err;
  161. ret = fc2580_wr_reg_ff(dev, 0x61, fc2580_freq_regs_lut[i].r61_val);
  162. if (ret)
  163. goto err;
  164. ret = fc2580_wr_reg_ff(dev, 0x62, fc2580_freq_regs_lut[i].r62_val);
  165. if (ret)
  166. goto err;
  167. ret = fc2580_wr_reg_ff(dev, 0x63, fc2580_freq_regs_lut[i].r63_val);
  168. if (ret)
  169. goto err;
  170. ret = fc2580_wr_reg_ff(dev, 0x67, fc2580_freq_regs_lut[i].r67_val);
  171. if (ret)
  172. goto err;
  173. ret = fc2580_wr_reg_ff(dev, 0x68, fc2580_freq_regs_lut[i].r68_val);
  174. if (ret)
  175. goto err;
  176. ret = fc2580_wr_reg_ff(dev, 0x69, fc2580_freq_regs_lut[i].r69_val);
  177. if (ret)
  178. goto err;
  179. ret = fc2580_wr_reg_ff(dev, 0x6a, fc2580_freq_regs_lut[i].r6a_val);
  180. if (ret)
  181. goto err;
  182. ret = fc2580_wr_reg_ff(dev, 0x6b, fc2580_freq_regs_lut[i].r6b_val);
  183. if (ret)
  184. goto err;
  185. ret = fc2580_wr_reg_ff(dev, 0x6c, fc2580_freq_regs_lut[i].r6c_val);
  186. if (ret)
  187. goto err;
  188. ret = fc2580_wr_reg_ff(dev, 0x6d, fc2580_freq_regs_lut[i].r6d_val);
  189. if (ret)
  190. goto err;
  191. ret = fc2580_wr_reg_ff(dev, 0x6e, fc2580_freq_regs_lut[i].r6e_val);
  192. if (ret)
  193. goto err;
  194. ret = fc2580_wr_reg_ff(dev, 0x6f, fc2580_freq_regs_lut[i].r6f_val);
  195. if (ret)
  196. goto err;
  197. /* IF filters */
  198. for (i = 0; i < ARRAY_SIZE(fc2580_if_filter_lut); i++) {
  199. if (dev->f_bandwidth <= fc2580_if_filter_lut[i].freq)
  200. break;
  201. }
  202. if (i == ARRAY_SIZE(fc2580_if_filter_lut)) {
  203. ret = -EINVAL;
  204. goto err;
  205. }
  206. ret = regmap_write(dev->regmap, 0x36, fc2580_if_filter_lut[i].r36_val);
  207. if (ret)
  208. goto err;
  209. uitmp = (unsigned int) 8058000 - (dev->f_bandwidth * 122 / 100 / 2);
  210. uitmp = div64_u64((u64) dev->clk * uitmp, 1000000000000ULL);
  211. ret = regmap_write(dev->regmap, 0x37, uitmp);
  212. if (ret)
  213. goto err;
  214. ret = regmap_write(dev->regmap, 0x39, fc2580_if_filter_lut[i].r39_val);
  215. if (ret)
  216. goto err;
  217. timeout = jiffies + msecs_to_jiffies(30);
  218. for (uitmp = ~0xc0; !time_after(jiffies, timeout) && uitmp != 0xc0;) {
  219. /* trigger filter */
  220. ret = regmap_write(dev->regmap, 0x2e, 0x09);
  221. if (ret)
  222. goto err;
  223. /* locked when [7:6] are set (val: d7 6MHz, d5 7MHz, cd 8MHz) */
  224. ret = regmap_read(dev->regmap, 0x2f, &uitmp);
  225. if (ret)
  226. goto err;
  227. uitmp &= 0xc0;
  228. ret = regmap_write(dev->regmap, 0x2e, 0x01);
  229. if (ret)
  230. goto err;
  231. }
  232. if (uitmp != 0xc0)
  233. dev_dbg(&client->dev, "filter did not lock %02x\n", uitmp);
  234. return 0;
  235. err:
  236. dev_dbg(&client->dev, "failed=%d\n", ret);
  237. return ret;
  238. }
  239. static int fc2580_init(struct fc2580_dev *dev)
  240. {
  241. struct i2c_client *client = dev->client;
  242. int ret, i;
  243. dev_dbg(&client->dev, "\n");
  244. for (i = 0; i < ARRAY_SIZE(fc2580_init_reg_vals); i++) {
  245. ret = regmap_write(dev->regmap, fc2580_init_reg_vals[i].reg,
  246. fc2580_init_reg_vals[i].val);
  247. if (ret)
  248. goto err;
  249. }
  250. dev->active = true;
  251. return 0;
  252. err:
  253. dev_dbg(&client->dev, "failed=%d\n", ret);
  254. return ret;
  255. }
  256. static int fc2580_sleep(struct fc2580_dev *dev)
  257. {
  258. struct i2c_client *client = dev->client;
  259. int ret;
  260. dev_dbg(&client->dev, "\n");
  261. dev->active = false;
  262. ret = regmap_write(dev->regmap, 0x02, 0x0a);
  263. if (ret)
  264. goto err;
  265. return 0;
  266. err:
  267. dev_dbg(&client->dev, "failed=%d\n", ret);
  268. return ret;
  269. }
  270. /*
  271. * DVB API
  272. */
  273. static int fc2580_dvb_set_params(struct dvb_frontend *fe)
  274. {
  275. struct fc2580_dev *dev = fe->tuner_priv;
  276. struct dtv_frontend_properties *c = &fe->dtv_property_cache;
  277. dev->f_frequency = c->frequency;
  278. dev->f_bandwidth = c->bandwidth_hz;
  279. return fc2580_set_params(dev);
  280. }
  281. static int fc2580_dvb_init(struct dvb_frontend *fe)
  282. {
  283. return fc2580_init(fe->tuner_priv);
  284. }
  285. static int fc2580_dvb_sleep(struct dvb_frontend *fe)
  286. {
  287. return fc2580_sleep(fe->tuner_priv);
  288. }
  289. static int fc2580_dvb_get_if_frequency(struct dvb_frontend *fe, u32 *frequency)
  290. {
  291. *frequency = 0; /* Zero-IF */
  292. return 0;
  293. }
  294. static const struct dvb_tuner_ops fc2580_dvb_tuner_ops = {
  295. .info = {
  296. .name = "FCI FC2580",
  297. .frequency_min = 174000000,
  298. .frequency_max = 862000000,
  299. },
  300. .init = fc2580_dvb_init,
  301. .sleep = fc2580_dvb_sleep,
  302. .set_params = fc2580_dvb_set_params,
  303. .get_if_frequency = fc2580_dvb_get_if_frequency,
  304. };
  305. /*
  306. * V4L2 API
  307. */
  308. #if IS_ENABLED(CONFIG_VIDEO_V4L2)
  309. static const struct v4l2_frequency_band bands[] = {
  310. {
  311. .type = V4L2_TUNER_RF,
  312. .index = 0,
  313. .capability = V4L2_TUNER_CAP_1HZ | V4L2_TUNER_CAP_FREQ_BANDS,
  314. .rangelow = 130000000,
  315. .rangehigh = 2000000000,
  316. },
  317. };
  318. static inline struct fc2580_dev *fc2580_subdev_to_dev(struct v4l2_subdev *sd)
  319. {
  320. return container_of(sd, struct fc2580_dev, subdev);
  321. }
  322. static int fc2580_s_power(struct v4l2_subdev *sd, int on)
  323. {
  324. struct fc2580_dev *dev = fc2580_subdev_to_dev(sd);
  325. struct i2c_client *client = dev->client;
  326. int ret;
  327. dev_dbg(&client->dev, "on=%d\n", on);
  328. if (on)
  329. ret = fc2580_init(dev);
  330. else
  331. ret = fc2580_sleep(dev);
  332. if (ret)
  333. return ret;
  334. return fc2580_set_params(dev);
  335. }
  336. static const struct v4l2_subdev_core_ops fc2580_subdev_core_ops = {
  337. .s_power = fc2580_s_power,
  338. };
  339. static int fc2580_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *v)
  340. {
  341. struct fc2580_dev *dev = fc2580_subdev_to_dev(sd);
  342. struct i2c_client *client = dev->client;
  343. dev_dbg(&client->dev, "index=%d\n", v->index);
  344. strlcpy(v->name, "FCI FC2580", sizeof(v->name));
  345. v->type = V4L2_TUNER_RF;
  346. v->capability = V4L2_TUNER_CAP_1HZ | V4L2_TUNER_CAP_FREQ_BANDS;
  347. v->rangelow = bands[0].rangelow;
  348. v->rangehigh = bands[0].rangehigh;
  349. return 0;
  350. }
  351. static int fc2580_s_tuner(struct v4l2_subdev *sd, const struct v4l2_tuner *v)
  352. {
  353. struct fc2580_dev *dev = fc2580_subdev_to_dev(sd);
  354. struct i2c_client *client = dev->client;
  355. dev_dbg(&client->dev, "index=%d\n", v->index);
  356. return 0;
  357. }
  358. static int fc2580_g_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *f)
  359. {
  360. struct fc2580_dev *dev = fc2580_subdev_to_dev(sd);
  361. struct i2c_client *client = dev->client;
  362. dev_dbg(&client->dev, "tuner=%d\n", f->tuner);
  363. f->frequency = dev->f_frequency;
  364. return 0;
  365. }
  366. static int fc2580_s_frequency(struct v4l2_subdev *sd,
  367. const struct v4l2_frequency *f)
  368. {
  369. struct fc2580_dev *dev = fc2580_subdev_to_dev(sd);
  370. struct i2c_client *client = dev->client;
  371. dev_dbg(&client->dev, "tuner=%d type=%d frequency=%u\n",
  372. f->tuner, f->type, f->frequency);
  373. dev->f_frequency = clamp_t(unsigned int, f->frequency,
  374. bands[0].rangelow, bands[0].rangehigh);
  375. return fc2580_set_params(dev);
  376. }
  377. static int fc2580_enum_freq_bands(struct v4l2_subdev *sd,
  378. struct v4l2_frequency_band *band)
  379. {
  380. struct fc2580_dev *dev = fc2580_subdev_to_dev(sd);
  381. struct i2c_client *client = dev->client;
  382. dev_dbg(&client->dev, "tuner=%d type=%d index=%d\n",
  383. band->tuner, band->type, band->index);
  384. if (band->index >= ARRAY_SIZE(bands))
  385. return -EINVAL;
  386. band->capability = bands[band->index].capability;
  387. band->rangelow = bands[band->index].rangelow;
  388. band->rangehigh = bands[band->index].rangehigh;
  389. return 0;
  390. }
  391. static const struct v4l2_subdev_tuner_ops fc2580_subdev_tuner_ops = {
  392. .g_tuner = fc2580_g_tuner,
  393. .s_tuner = fc2580_s_tuner,
  394. .g_frequency = fc2580_g_frequency,
  395. .s_frequency = fc2580_s_frequency,
  396. .enum_freq_bands = fc2580_enum_freq_bands,
  397. };
  398. static const struct v4l2_subdev_ops fc2580_subdev_ops = {
  399. .core = &fc2580_subdev_core_ops,
  400. .tuner = &fc2580_subdev_tuner_ops,
  401. };
  402. static int fc2580_s_ctrl(struct v4l2_ctrl *ctrl)
  403. {
  404. struct fc2580_dev *dev = container_of(ctrl->handler, struct fc2580_dev, hdl);
  405. struct i2c_client *client = dev->client;
  406. int ret;
  407. dev_dbg(&client->dev, "ctrl: id=%d name=%s cur.val=%d val=%d\n",
  408. ctrl->id, ctrl->name, ctrl->cur.val, ctrl->val);
  409. switch (ctrl->id) {
  410. case V4L2_CID_RF_TUNER_BANDWIDTH_AUTO:
  411. case V4L2_CID_RF_TUNER_BANDWIDTH:
  412. /*
  413. * TODO: Auto logic does not work 100% correctly as tuner driver
  414. * do not have information to calculate maximum suitable
  415. * bandwidth. Calculating it is responsible of master driver.
  416. */
  417. dev->f_bandwidth = dev->bandwidth->val;
  418. ret = fc2580_set_params(dev);
  419. break;
  420. default:
  421. dev_dbg(&client->dev, "unknown ctrl");
  422. ret = -EINVAL;
  423. }
  424. return ret;
  425. }
  426. static const struct v4l2_ctrl_ops fc2580_ctrl_ops = {
  427. .s_ctrl = fc2580_s_ctrl,
  428. };
  429. #endif
  430. static struct v4l2_subdev *fc2580_get_v4l2_subdev(struct i2c_client *client)
  431. {
  432. struct fc2580_dev *dev = i2c_get_clientdata(client);
  433. if (dev->subdev.ops)
  434. return &dev->subdev;
  435. else
  436. return NULL;
  437. }
  438. static int fc2580_probe(struct i2c_client *client,
  439. const struct i2c_device_id *id)
  440. {
  441. struct fc2580_dev *dev;
  442. struct fc2580_platform_data *pdata = client->dev.platform_data;
  443. struct dvb_frontend *fe = pdata->dvb_frontend;
  444. int ret;
  445. unsigned int uitmp;
  446. static const struct regmap_config regmap_config = {
  447. .reg_bits = 8,
  448. .val_bits = 8,
  449. };
  450. dev = kzalloc(sizeof(*dev), GFP_KERNEL);
  451. if (!dev) {
  452. ret = -ENOMEM;
  453. goto err;
  454. }
  455. if (pdata->clk)
  456. dev->clk = pdata->clk;
  457. else
  458. dev->clk = 16384000; /* internal clock */
  459. dev->client = client;
  460. dev->regmap = devm_regmap_init_i2c(client, &regmap_config);
  461. if (IS_ERR(dev->regmap)) {
  462. ret = PTR_ERR(dev->regmap);
  463. goto err_kfree;
  464. }
  465. /* check if the tuner is there */
  466. ret = regmap_read(dev->regmap, 0x01, &uitmp);
  467. if (ret)
  468. goto err_kfree;
  469. dev_dbg(&client->dev, "chip_id=%02x\n", uitmp);
  470. switch (uitmp) {
  471. case 0x56:
  472. case 0x5a:
  473. break;
  474. default:
  475. ret = -ENODEV;
  476. goto err_kfree;
  477. }
  478. #if IS_ENABLED(CONFIG_VIDEO_V4L2)
  479. /* Register controls */
  480. v4l2_ctrl_handler_init(&dev->hdl, 2);
  481. dev->bandwidth_auto = v4l2_ctrl_new_std(&dev->hdl, &fc2580_ctrl_ops,
  482. V4L2_CID_RF_TUNER_BANDWIDTH_AUTO,
  483. 0, 1, 1, 1);
  484. dev->bandwidth = v4l2_ctrl_new_std(&dev->hdl, &fc2580_ctrl_ops,
  485. V4L2_CID_RF_TUNER_BANDWIDTH,
  486. 3000, 10000000, 1, 3000);
  487. v4l2_ctrl_auto_cluster(2, &dev->bandwidth_auto, 0, false);
  488. if (dev->hdl.error) {
  489. ret = dev->hdl.error;
  490. dev_err(&client->dev, "Could not initialize controls\n");
  491. v4l2_ctrl_handler_free(&dev->hdl);
  492. goto err_kfree;
  493. }
  494. dev->subdev.ctrl_handler = &dev->hdl;
  495. dev->f_frequency = bands[0].rangelow;
  496. dev->f_bandwidth = dev->bandwidth->val;
  497. v4l2_i2c_subdev_init(&dev->subdev, client, &fc2580_subdev_ops);
  498. #endif
  499. fe->tuner_priv = dev;
  500. memcpy(&fe->ops.tuner_ops, &fc2580_dvb_tuner_ops,
  501. sizeof(fe->ops.tuner_ops));
  502. pdata->get_v4l2_subdev = fc2580_get_v4l2_subdev;
  503. i2c_set_clientdata(client, dev);
  504. dev_info(&client->dev, "FCI FC2580 successfully identified\n");
  505. return 0;
  506. err_kfree:
  507. kfree(dev);
  508. err:
  509. dev_dbg(&client->dev, "failed=%d\n", ret);
  510. return ret;
  511. }
  512. static int fc2580_remove(struct i2c_client *client)
  513. {
  514. struct fc2580_dev *dev = i2c_get_clientdata(client);
  515. dev_dbg(&client->dev, "\n");
  516. #if IS_ENABLED(CONFIG_VIDEO_V4L2)
  517. v4l2_ctrl_handler_free(&dev->hdl);
  518. #endif
  519. kfree(dev);
  520. return 0;
  521. }
  522. static const struct i2c_device_id fc2580_id_table[] = {
  523. {"fc2580", 0},
  524. {}
  525. };
  526. MODULE_DEVICE_TABLE(i2c, fc2580_id_table);
  527. static struct i2c_driver fc2580_driver = {
  528. .driver = {
  529. .name = "fc2580",
  530. .suppress_bind_attrs = true,
  531. },
  532. .probe = fc2580_probe,
  533. .remove = fc2580_remove,
  534. .id_table = fc2580_id_table,
  535. };
  536. module_i2c_driver(fc2580_driver);
  537. MODULE_DESCRIPTION("FCI FC2580 silicon tuner driver");
  538. MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
  539. MODULE_LICENSE("GPL");