cx231xx-dvb.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187
  1. /*
  2. DVB device driver for cx231xx
  3. Copyright (C) 2008 <srinivasa.deevi at conexant dot com>
  4. Based on em28xx driver
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. */
  17. #include "cx231xx.h"
  18. #include <linux/kernel.h>
  19. #include <linux/slab.h>
  20. #include <media/dvbdev.h>
  21. #include <media/dmxdev.h>
  22. #include <media/dvb_demux.h>
  23. #include <media/dvb_net.h>
  24. #include <media/dvb_frontend.h>
  25. #include <media/v4l2-common.h>
  26. #include <media/tuner.h>
  27. #include "xc5000.h"
  28. #include "s5h1432.h"
  29. #include "tda18271.h"
  30. #include "s5h1411.h"
  31. #include "lgdt3305.h"
  32. #include "si2165.h"
  33. #include "si2168.h"
  34. #include "mb86a20s.h"
  35. #include "si2157.h"
  36. #include "lgdt3306a.h"
  37. #include "r820t.h"
  38. #include "mn88473.h"
  39. MODULE_DESCRIPTION("driver for cx231xx based DVB cards");
  40. MODULE_AUTHOR("Srinivasa Deevi <srinivasa.deevi@conexant.com>");
  41. MODULE_LICENSE("GPL");
  42. static unsigned int debug;
  43. module_param(debug, int, 0644);
  44. MODULE_PARM_DESC(debug, "enable debug messages [dvb]");
  45. DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
  46. #define CX231XX_DVB_NUM_BUFS 5
  47. #define CX231XX_DVB_MAX_PACKETSIZE 564
  48. #define CX231XX_DVB_MAX_PACKETS 64
  49. #define CX231XX_DVB_MAX_FRONTENDS 2
  50. struct cx231xx_dvb {
  51. struct dvb_frontend *frontend[CX231XX_DVB_MAX_FRONTENDS];
  52. /* feed count management */
  53. struct mutex lock;
  54. int nfeeds;
  55. /* general boilerplate stuff */
  56. struct dvb_adapter adapter;
  57. struct dvb_demux demux;
  58. struct dmxdev dmxdev;
  59. struct dmx_frontend fe_hw;
  60. struct dmx_frontend fe_mem;
  61. struct dvb_net net;
  62. struct i2c_client *i2c_client_demod[2];
  63. struct i2c_client *i2c_client_tuner;
  64. };
  65. static struct s5h1432_config dvico_s5h1432_config = {
  66. .output_mode = S5H1432_SERIAL_OUTPUT,
  67. .gpio = S5H1432_GPIO_ON,
  68. .qam_if = S5H1432_IF_4000,
  69. .vsb_if = S5H1432_IF_4000,
  70. .inversion = S5H1432_INVERSION_OFF,
  71. .status_mode = S5H1432_DEMODLOCKING,
  72. .mpeg_timing = S5H1432_MPEGTIMING_CONTINUOUS_NONINVERTING_CLOCK,
  73. };
  74. static struct tda18271_std_map cnxt_rde253s_tda18271_std_map = {
  75. .dvbt_6 = { .if_freq = 4000, .agc_mode = 3, .std = 4,
  76. .if_lvl = 1, .rfagc_top = 0x37, },
  77. .dvbt_7 = { .if_freq = 4000, .agc_mode = 3, .std = 5,
  78. .if_lvl = 1, .rfagc_top = 0x37, },
  79. .dvbt_8 = { .if_freq = 4000, .agc_mode = 3, .std = 6,
  80. .if_lvl = 1, .rfagc_top = 0x37, },
  81. };
  82. static struct tda18271_std_map mb86a20s_tda18271_config = {
  83. .dvbt_6 = { .if_freq = 4000, .agc_mode = 3, .std = 4,
  84. .if_lvl = 0, .rfagc_top = 0x37, },
  85. };
  86. static struct tda18271_config cnxt_rde253s_tunerconfig = {
  87. .std_map = &cnxt_rde253s_tda18271_std_map,
  88. .gate = TDA18271_GATE_ANALOG,
  89. };
  90. static struct s5h1411_config tda18271_s5h1411_config = {
  91. .output_mode = S5H1411_SERIAL_OUTPUT,
  92. .gpio = S5H1411_GPIO_OFF,
  93. .vsb_if = S5H1411_IF_3250,
  94. .qam_if = S5H1411_IF_4000,
  95. .inversion = S5H1411_INVERSION_ON,
  96. .status_mode = S5H1411_DEMODLOCKING,
  97. .mpeg_timing = S5H1411_MPEGTIMING_CONTINUOUS_NONINVERTING_CLOCK,
  98. };
  99. static struct s5h1411_config xc5000_s5h1411_config = {
  100. .output_mode = S5H1411_SERIAL_OUTPUT,
  101. .gpio = S5H1411_GPIO_OFF,
  102. .vsb_if = S5H1411_IF_3250,
  103. .qam_if = S5H1411_IF_3250,
  104. .inversion = S5H1411_INVERSION_OFF,
  105. .status_mode = S5H1411_DEMODLOCKING,
  106. .mpeg_timing = S5H1411_MPEGTIMING_CONTINUOUS_NONINVERTING_CLOCK,
  107. };
  108. static struct lgdt3305_config hcw_lgdt3305_config = {
  109. .i2c_addr = 0x0e,
  110. .mpeg_mode = LGDT3305_MPEG_SERIAL,
  111. .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE,
  112. .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
  113. .deny_i2c_rptr = 1,
  114. .spectral_inversion = 1,
  115. .qam_if_khz = 4000,
  116. .vsb_if_khz = 3250,
  117. };
  118. static struct tda18271_std_map hauppauge_tda18271_std_map = {
  119. .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 4,
  120. .if_lvl = 1, .rfagc_top = 0x58, },
  121. .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 5,
  122. .if_lvl = 1, .rfagc_top = 0x58, },
  123. };
  124. static struct tda18271_config hcw_tda18271_config = {
  125. .std_map = &hauppauge_tda18271_std_map,
  126. .gate = TDA18271_GATE_DIGITAL,
  127. };
  128. static const struct mb86a20s_config pv_mb86a20s_config = {
  129. .demod_address = 0x10,
  130. .is_serial = true,
  131. };
  132. static struct tda18271_config pv_tda18271_config = {
  133. .std_map = &mb86a20s_tda18271_config,
  134. .gate = TDA18271_GATE_DIGITAL,
  135. .small_i2c = TDA18271_03_BYTE_CHUNK_INIT,
  136. };
  137. static struct lgdt3306a_config hauppauge_955q_lgdt3306a_config = {
  138. .qam_if_khz = 4000,
  139. .vsb_if_khz = 3250,
  140. .spectral_inversion = 1,
  141. .mpeg_mode = LGDT3306A_MPEG_SERIAL,
  142. .tpclk_edge = LGDT3306A_TPCLK_RISING_EDGE,
  143. .tpvalid_polarity = LGDT3306A_TP_VALID_HIGH,
  144. .xtalMHz = 25,
  145. };
  146. static struct r820t_config astrometa_t2hybrid_r820t_config = {
  147. .i2c_addr = 0x3a, /* 0x74 >> 1 */
  148. .xtal = 16000000,
  149. .rafael_chip = CHIP_R828D,
  150. .max_i2c_msg_len = 2,
  151. };
  152. static inline void print_err_status(struct cx231xx *dev, int packet, int status)
  153. {
  154. char *errmsg = "Unknown";
  155. switch (status) {
  156. case -ENOENT:
  157. errmsg = "unlinked synchronously";
  158. break;
  159. case -ECONNRESET:
  160. errmsg = "unlinked asynchronously";
  161. break;
  162. case -ENOSR:
  163. errmsg = "Buffer error (overrun)";
  164. break;
  165. case -EPIPE:
  166. errmsg = "Stalled (device not responding)";
  167. break;
  168. case -EOVERFLOW:
  169. errmsg = "Babble (bad cable?)";
  170. break;
  171. case -EPROTO:
  172. errmsg = "Bit-stuff error (bad cable?)";
  173. break;
  174. case -EILSEQ:
  175. errmsg = "CRC/Timeout (could be anything)";
  176. break;
  177. case -ETIME:
  178. errmsg = "Device does not respond";
  179. break;
  180. }
  181. if (packet < 0) {
  182. dev_dbg(dev->dev,
  183. "URB status %d [%s].\n", status, errmsg);
  184. } else {
  185. dev_dbg(dev->dev,
  186. "URB packet %d, status %d [%s].\n",
  187. packet, status, errmsg);
  188. }
  189. }
  190. static inline int dvb_isoc_copy(struct cx231xx *dev, struct urb *urb)
  191. {
  192. int i;
  193. if (!dev)
  194. return 0;
  195. if (dev->state & DEV_DISCONNECTED)
  196. return 0;
  197. if (urb->status < 0) {
  198. print_err_status(dev, -1, urb->status);
  199. if (urb->status == -ENOENT)
  200. return 0;
  201. }
  202. for (i = 0; i < urb->number_of_packets; i++) {
  203. int status = urb->iso_frame_desc[i].status;
  204. if (status < 0) {
  205. print_err_status(dev, i, status);
  206. if (urb->iso_frame_desc[i].status != -EPROTO)
  207. continue;
  208. }
  209. dvb_dmx_swfilter(&dev->dvb->demux,
  210. urb->transfer_buffer +
  211. urb->iso_frame_desc[i].offset,
  212. urb->iso_frame_desc[i].actual_length);
  213. }
  214. return 0;
  215. }
  216. static inline int dvb_bulk_copy(struct cx231xx *dev, struct urb *urb)
  217. {
  218. if (!dev)
  219. return 0;
  220. if (dev->state & DEV_DISCONNECTED)
  221. return 0;
  222. if (urb->status < 0) {
  223. print_err_status(dev, -1, urb->status);
  224. if (urb->status == -ENOENT)
  225. return 0;
  226. }
  227. /* Feed the transport payload into the kernel demux */
  228. dvb_dmx_swfilter(&dev->dvb->demux,
  229. urb->transfer_buffer, urb->actual_length);
  230. return 0;
  231. }
  232. static int start_streaming(struct cx231xx_dvb *dvb)
  233. {
  234. int rc;
  235. struct cx231xx *dev = dvb->adapter.priv;
  236. if (dev->USE_ISO) {
  237. dev_dbg(dev->dev, "DVB transfer mode is ISO.\n");
  238. cx231xx_set_alt_setting(dev, INDEX_TS1, 5);
  239. rc = cx231xx_set_mode(dev, CX231XX_DIGITAL_MODE);
  240. if (rc < 0)
  241. return rc;
  242. dev->mode_tv = 1;
  243. return cx231xx_init_isoc(dev, CX231XX_DVB_MAX_PACKETS,
  244. CX231XX_DVB_NUM_BUFS,
  245. dev->ts1_mode.max_pkt_size,
  246. dvb_isoc_copy);
  247. } else {
  248. dev_dbg(dev->dev, "DVB transfer mode is BULK.\n");
  249. cx231xx_set_alt_setting(dev, INDEX_TS1, 0);
  250. rc = cx231xx_set_mode(dev, CX231XX_DIGITAL_MODE);
  251. if (rc < 0)
  252. return rc;
  253. dev->mode_tv = 1;
  254. return cx231xx_init_bulk(dev, CX231XX_DVB_MAX_PACKETS,
  255. CX231XX_DVB_NUM_BUFS,
  256. dev->ts1_mode.max_pkt_size,
  257. dvb_bulk_copy);
  258. }
  259. }
  260. static int stop_streaming(struct cx231xx_dvb *dvb)
  261. {
  262. struct cx231xx *dev = dvb->adapter.priv;
  263. if (dev->USE_ISO)
  264. cx231xx_uninit_isoc(dev);
  265. else
  266. cx231xx_uninit_bulk(dev);
  267. cx231xx_set_mode(dev, CX231XX_SUSPEND);
  268. return 0;
  269. }
  270. static int start_feed(struct dvb_demux_feed *feed)
  271. {
  272. struct dvb_demux *demux = feed->demux;
  273. struct cx231xx_dvb *dvb = demux->priv;
  274. int rc, ret;
  275. if (!demux->dmx.frontend)
  276. return -EINVAL;
  277. mutex_lock(&dvb->lock);
  278. dvb->nfeeds++;
  279. rc = dvb->nfeeds;
  280. if (dvb->nfeeds == 1) {
  281. ret = start_streaming(dvb);
  282. if (ret < 0)
  283. rc = ret;
  284. }
  285. mutex_unlock(&dvb->lock);
  286. return rc;
  287. }
  288. static int stop_feed(struct dvb_demux_feed *feed)
  289. {
  290. struct dvb_demux *demux = feed->demux;
  291. struct cx231xx_dvb *dvb = demux->priv;
  292. int err = 0;
  293. mutex_lock(&dvb->lock);
  294. dvb->nfeeds--;
  295. if (0 == dvb->nfeeds)
  296. err = stop_streaming(dvb);
  297. mutex_unlock(&dvb->lock);
  298. return err;
  299. }
  300. /* ------------------------------------------------------------------ */
  301. static int cx231xx_dvb_bus_ctrl(struct dvb_frontend *fe, int acquire)
  302. {
  303. struct cx231xx *dev = fe->dvb->priv;
  304. if (acquire)
  305. return cx231xx_set_mode(dev, CX231XX_DIGITAL_MODE);
  306. else
  307. return cx231xx_set_mode(dev, CX231XX_SUSPEND);
  308. }
  309. /* ------------------------------------------------------------------ */
  310. static struct xc5000_config cnxt_rde250_tunerconfig = {
  311. .i2c_address = 0x61,
  312. .if_khz = 4000,
  313. };
  314. static struct xc5000_config cnxt_rdu250_tunerconfig = {
  315. .i2c_address = 0x61,
  316. .if_khz = 3250,
  317. };
  318. /* ------------------------------------------------------------------ */
  319. #if 0
  320. static int attach_xc5000(u8 addr, struct cx231xx *dev)
  321. {
  322. struct dvb_frontend *fe;
  323. struct xc5000_config cfg;
  324. memset(&cfg, 0, sizeof(cfg));
  325. cfg.i2c_adap = cx231xx_get_i2c_adap(dev, dev->board.tuner_i2c_master);
  326. cfg.i2c_addr = addr;
  327. if (!dev->dvb->frontend[0]) {
  328. dev_err(dev->dev, "%s/2: dvb frontend not attached. Can't attach xc5000\n",
  329. dev->name);
  330. return -EINVAL;
  331. }
  332. fe = dvb_attach(xc5000_attach, dev->dvb->frontend[0], &cfg);
  333. if (!fe) {
  334. dev_err(dev->dev, "%s/2: xc5000 attach failed\n", dev->name);
  335. dvb_frontend_detach(dev->dvb->frontend[0]);
  336. dev->dvb->frontend[0] = NULL;
  337. return -EINVAL;
  338. }
  339. dev_info(dev->dev, "%s/2: xc5000 attached\n", dev->name);
  340. return 0;
  341. }
  342. #endif
  343. int cx231xx_set_analog_freq(struct cx231xx *dev, u32 freq)
  344. {
  345. if (dev->dvb && dev->dvb->frontend[0]) {
  346. struct dvb_tuner_ops *dops = &dev->dvb->frontend[0]->ops.tuner_ops;
  347. if (dops->set_analog_params != NULL) {
  348. struct analog_parameters params;
  349. params.frequency = freq;
  350. params.std = dev->norm;
  351. params.mode = 0; /* 0- Air; 1 - cable */
  352. /*params.audmode = ; */
  353. /* Set the analog parameters to set the frequency */
  354. dops->set_analog_params(dev->dvb->frontend[0], &params);
  355. }
  356. }
  357. return 0;
  358. }
  359. int cx231xx_reset_analog_tuner(struct cx231xx *dev)
  360. {
  361. int status = 0;
  362. if (dev->dvb && dev->dvb->frontend[0]) {
  363. struct dvb_tuner_ops *dops = &dev->dvb->frontend[0]->ops.tuner_ops;
  364. if (dops->init != NULL && !dev->xc_fw_load_done) {
  365. dev_dbg(dev->dev,
  366. "Reloading firmware for XC5000\n");
  367. status = dops->init(dev->dvb->frontend[0]);
  368. if (status == 0) {
  369. dev->xc_fw_load_done = 1;
  370. dev_dbg(dev->dev,
  371. "XC5000 firmware download completed\n");
  372. } else {
  373. dev->xc_fw_load_done = 0;
  374. dev_dbg(dev->dev,
  375. "XC5000 firmware download failed !!!\n");
  376. }
  377. }
  378. }
  379. return status;
  380. }
  381. /* ------------------------------------------------------------------ */
  382. static int register_dvb(struct cx231xx_dvb *dvb,
  383. struct module *module,
  384. struct cx231xx *dev, struct device *device)
  385. {
  386. int result;
  387. mutex_init(&dvb->lock);
  388. /* register adapter */
  389. result = dvb_register_adapter(&dvb->adapter, dev->name, module, device,
  390. adapter_nr);
  391. if (result < 0) {
  392. dev_warn(dev->dev,
  393. "%s: dvb_register_adapter failed (errno = %d)\n",
  394. dev->name, result);
  395. goto fail_adapter;
  396. }
  397. dvb_register_media_controller(&dvb->adapter, dev->media_dev);
  398. /* Ensure all frontends negotiate bus access */
  399. dvb->frontend[0]->ops.ts_bus_ctrl = cx231xx_dvb_bus_ctrl;
  400. if (dvb->frontend[1])
  401. dvb->frontend[1]->ops.ts_bus_ctrl = cx231xx_dvb_bus_ctrl;
  402. dvb->adapter.priv = dev;
  403. /* register frontend */
  404. result = dvb_register_frontend(&dvb->adapter, dvb->frontend[0]);
  405. if (result < 0) {
  406. dev_warn(dev->dev,
  407. "%s: dvb_register_frontend failed (errno = %d)\n",
  408. dev->name, result);
  409. goto fail_frontend0;
  410. }
  411. if (dvb->frontend[1]) {
  412. result = dvb_register_frontend(&dvb->adapter, dvb->frontend[1]);
  413. if (result < 0) {
  414. dev_warn(dev->dev,
  415. "%s: 2nd dvb_register_frontend failed (errno = %d)\n",
  416. dev->name, result);
  417. goto fail_frontend1;
  418. }
  419. /* MFE lock */
  420. dvb->adapter.mfe_shared = 1;
  421. }
  422. /* register demux stuff */
  423. dvb->demux.dmx.capabilities =
  424. DMX_TS_FILTERING | DMX_SECTION_FILTERING |
  425. DMX_MEMORY_BASED_FILTERING;
  426. dvb->demux.priv = dvb;
  427. dvb->demux.filternum = 256;
  428. dvb->demux.feednum = 256;
  429. dvb->demux.start_feed = start_feed;
  430. dvb->demux.stop_feed = stop_feed;
  431. result = dvb_dmx_init(&dvb->demux);
  432. if (result < 0) {
  433. dev_warn(dev->dev,
  434. "%s: dvb_dmx_init failed (errno = %d)\n",
  435. dev->name, result);
  436. goto fail_dmx;
  437. }
  438. dvb->dmxdev.filternum = 256;
  439. dvb->dmxdev.demux = &dvb->demux.dmx;
  440. dvb->dmxdev.capabilities = 0;
  441. result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter);
  442. if (result < 0) {
  443. dev_warn(dev->dev,
  444. "%s: dvb_dmxdev_init failed (errno = %d)\n",
  445. dev->name, result);
  446. goto fail_dmxdev;
  447. }
  448. dvb->fe_hw.source = DMX_FRONTEND_0;
  449. result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw);
  450. if (result < 0) {
  451. dev_warn(dev->dev,
  452. "%s: add_frontend failed (DMX_FRONTEND_0, errno = %d)\n",
  453. dev->name, result);
  454. goto fail_fe_hw;
  455. }
  456. dvb->fe_mem.source = DMX_MEMORY_FE;
  457. result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem);
  458. if (result < 0) {
  459. dev_warn(dev->dev,
  460. "%s: add_frontend failed (DMX_MEMORY_FE, errno = %d)\n",
  461. dev->name, result);
  462. goto fail_fe_mem;
  463. }
  464. result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw);
  465. if (result < 0) {
  466. dev_warn(dev->dev,
  467. "%s: connect_frontend failed (errno = %d)\n",
  468. dev->name, result);
  469. goto fail_fe_conn;
  470. }
  471. /* register network adapter */
  472. dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx);
  473. result = dvb_create_media_graph(&dvb->adapter,
  474. dev->tuner_type == TUNER_ABSENT);
  475. if (result < 0)
  476. goto fail_create_graph;
  477. return 0;
  478. fail_create_graph:
  479. dvb_net_release(&dvb->net);
  480. fail_fe_conn:
  481. dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
  482. fail_fe_mem:
  483. dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
  484. fail_fe_hw:
  485. dvb_dmxdev_release(&dvb->dmxdev);
  486. fail_dmxdev:
  487. dvb_dmx_release(&dvb->demux);
  488. fail_dmx:
  489. if (dvb->frontend[1])
  490. dvb_unregister_frontend(dvb->frontend[1]);
  491. dvb_unregister_frontend(dvb->frontend[0]);
  492. fail_frontend1:
  493. if (dvb->frontend[1])
  494. dvb_frontend_detach(dvb->frontend[1]);
  495. fail_frontend0:
  496. dvb_frontend_detach(dvb->frontend[0]);
  497. dvb_unregister_adapter(&dvb->adapter);
  498. fail_adapter:
  499. return result;
  500. }
  501. static void unregister_dvb(struct cx231xx_dvb *dvb)
  502. {
  503. dvb_net_release(&dvb->net);
  504. dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
  505. dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
  506. dvb_dmxdev_release(&dvb->dmxdev);
  507. dvb_dmx_release(&dvb->demux);
  508. if (dvb->frontend[1])
  509. dvb_unregister_frontend(dvb->frontend[1]);
  510. dvb_unregister_frontend(dvb->frontend[0]);
  511. if (dvb->frontend[1])
  512. dvb_frontend_detach(dvb->frontend[1]);
  513. dvb_frontend_detach(dvb->frontend[0]);
  514. dvb_unregister_adapter(&dvb->adapter);
  515. /* remove I2C tuner */
  516. dvb_module_release(dvb->i2c_client_tuner);
  517. dvb->i2c_client_tuner = NULL;
  518. /* remove I2C demod(s) */
  519. dvb_module_release(dvb->i2c_client_demod[1]);
  520. dvb->i2c_client_demod[1] = NULL;
  521. dvb_module_release(dvb->i2c_client_demod[0]);
  522. dvb->i2c_client_demod[0] = NULL;
  523. }
  524. static int dvb_init(struct cx231xx *dev)
  525. {
  526. int result;
  527. struct cx231xx_dvb *dvb;
  528. struct i2c_adapter *tuner_i2c;
  529. struct i2c_adapter *demod_i2c;
  530. struct i2c_client *client;
  531. struct i2c_adapter *adapter;
  532. if (!dev->board.has_dvb) {
  533. /* This device does not support the extension */
  534. return 0;
  535. }
  536. dvb = kzalloc(sizeof(struct cx231xx_dvb), GFP_KERNEL);
  537. if (dvb == NULL) {
  538. dev_info(dev->dev,
  539. "cx231xx_dvb: memory allocation failed\n");
  540. return -ENOMEM;
  541. }
  542. dev->dvb = dvb;
  543. dev->cx231xx_set_analog_freq = cx231xx_set_analog_freq;
  544. dev->cx231xx_reset_analog_tuner = cx231xx_reset_analog_tuner;
  545. tuner_i2c = cx231xx_get_i2c_adap(dev, dev->board.tuner_i2c_master);
  546. demod_i2c = cx231xx_get_i2c_adap(dev, dev->board.demod_i2c_master);
  547. mutex_lock(&dev->lock);
  548. cx231xx_set_mode(dev, CX231XX_DIGITAL_MODE);
  549. cx231xx_demod_reset(dev);
  550. /* init frontend */
  551. switch (dev->model) {
  552. case CX231XX_BOARD_CNXT_CARRAERA:
  553. case CX231XX_BOARD_CNXT_RDE_250:
  554. dev->dvb->frontend[0] = dvb_attach(s5h1432_attach,
  555. &dvico_s5h1432_config,
  556. demod_i2c);
  557. if (!dev->dvb->frontend[0]) {
  558. dev_err(dev->dev,
  559. "Failed to attach s5h1432 front end\n");
  560. result = -EINVAL;
  561. goto out_free;
  562. }
  563. /* define general-purpose callback pointer */
  564. dvb->frontend[0]->callback = cx231xx_tuner_callback;
  565. if (!dvb_attach(xc5000_attach, dev->dvb->frontend[0],
  566. tuner_i2c,
  567. &cnxt_rde250_tunerconfig)) {
  568. result = -EINVAL;
  569. goto out_free;
  570. }
  571. break;
  572. case CX231XX_BOARD_CNXT_SHELBY:
  573. case CX231XX_BOARD_CNXT_RDU_250:
  574. dev->dvb->frontend[0] = dvb_attach(s5h1411_attach,
  575. &xc5000_s5h1411_config,
  576. demod_i2c);
  577. if (!dev->dvb->frontend[0]) {
  578. dev_err(dev->dev,
  579. "Failed to attach s5h1411 front end\n");
  580. result = -EINVAL;
  581. goto out_free;
  582. }
  583. /* define general-purpose callback pointer */
  584. dvb->frontend[0]->callback = cx231xx_tuner_callback;
  585. if (!dvb_attach(xc5000_attach, dev->dvb->frontend[0],
  586. tuner_i2c,
  587. &cnxt_rdu250_tunerconfig)) {
  588. result = -EINVAL;
  589. goto out_free;
  590. }
  591. break;
  592. case CX231XX_BOARD_CNXT_RDE_253S:
  593. dev->dvb->frontend[0] = dvb_attach(s5h1432_attach,
  594. &dvico_s5h1432_config,
  595. demod_i2c);
  596. if (!dev->dvb->frontend[0]) {
  597. dev_err(dev->dev,
  598. "Failed to attach s5h1432 front end\n");
  599. result = -EINVAL;
  600. goto out_free;
  601. }
  602. /* define general-purpose callback pointer */
  603. dvb->frontend[0]->callback = cx231xx_tuner_callback;
  604. if (!dvb_attach(tda18271_attach, dev->dvb->frontend[0],
  605. dev->board.tuner_addr, tuner_i2c,
  606. &cnxt_rde253s_tunerconfig)) {
  607. result = -EINVAL;
  608. goto out_free;
  609. }
  610. break;
  611. case CX231XX_BOARD_CNXT_RDU_253S:
  612. case CX231XX_BOARD_KWORLD_UB445_USB_HYBRID:
  613. dev->dvb->frontend[0] = dvb_attach(s5h1411_attach,
  614. &tda18271_s5h1411_config,
  615. demod_i2c);
  616. if (!dev->dvb->frontend[0]) {
  617. dev_err(dev->dev,
  618. "Failed to attach s5h1411 front end\n");
  619. result = -EINVAL;
  620. goto out_free;
  621. }
  622. /* define general-purpose callback pointer */
  623. dvb->frontend[0]->callback = cx231xx_tuner_callback;
  624. if (!dvb_attach(tda18271_attach, dev->dvb->frontend[0],
  625. dev->board.tuner_addr, tuner_i2c,
  626. &cnxt_rde253s_tunerconfig)) {
  627. result = -EINVAL;
  628. goto out_free;
  629. }
  630. break;
  631. case CX231XX_BOARD_HAUPPAUGE_EXETER:
  632. dev_info(dev->dev,
  633. "%s: looking for tuner / demod on i2c bus: %d\n",
  634. __func__, i2c_adapter_id(tuner_i2c));
  635. dev->dvb->frontend[0] = dvb_attach(lgdt3305_attach,
  636. &hcw_lgdt3305_config,
  637. demod_i2c);
  638. if (!dev->dvb->frontend[0]) {
  639. dev_err(dev->dev,
  640. "Failed to attach LG3305 front end\n");
  641. result = -EINVAL;
  642. goto out_free;
  643. }
  644. /* define general-purpose callback pointer */
  645. dvb->frontend[0]->callback = cx231xx_tuner_callback;
  646. dvb_attach(tda18271_attach, dev->dvb->frontend[0],
  647. dev->board.tuner_addr, tuner_i2c,
  648. &hcw_tda18271_config);
  649. break;
  650. case CX231XX_BOARD_HAUPPAUGE_930C_HD_1113xx:
  651. {
  652. struct si2165_platform_data si2165_pdata = {};
  653. /* attach demod */
  654. si2165_pdata.fe = &dev->dvb->frontend[0];
  655. si2165_pdata.chip_mode = SI2165_MODE_PLL_XTAL;
  656. si2165_pdata.ref_freq_hz = 16000000;
  657. /* perform probe/init/attach */
  658. client = dvb_module_probe("si2165", NULL, demod_i2c,
  659. dev->board.demod_addr,
  660. &si2165_pdata);
  661. if (!client) {
  662. result = -ENODEV;
  663. goto out_free;
  664. }
  665. dvb->i2c_client_demod[0] = client;
  666. dev->dvb->frontend[0]->ops.i2c_gate_ctrl = NULL;
  667. /* define general-purpose callback pointer */
  668. dvb->frontend[0]->callback = cx231xx_tuner_callback;
  669. dvb_attach(tda18271_attach, dev->dvb->frontend[0],
  670. dev->board.tuner_addr, tuner_i2c,
  671. &hcw_tda18271_config);
  672. dev->cx231xx_reset_analog_tuner = NULL;
  673. break;
  674. }
  675. case CX231XX_BOARD_HAUPPAUGE_930C_HD_1114xx:
  676. {
  677. struct si2165_platform_data si2165_pdata = {};
  678. struct si2157_config si2157_config = {};
  679. /* attach demod */
  680. si2165_pdata.fe = &dev->dvb->frontend[0];
  681. si2165_pdata.chip_mode = SI2165_MODE_PLL_EXT;
  682. si2165_pdata.ref_freq_hz = 24000000;
  683. /* perform probe/init/attach */
  684. client = dvb_module_probe("si2165", NULL, demod_i2c,
  685. dev->board.demod_addr,
  686. &si2165_pdata);
  687. if (!client) {
  688. result = -ENODEV;
  689. goto out_free;
  690. }
  691. dvb->i2c_client_demod[0] = client;
  692. dev->dvb->frontend[0]->ops.i2c_gate_ctrl = NULL;
  693. /* define general-purpose callback pointer */
  694. dvb->frontend[0]->callback = cx231xx_tuner_callback;
  695. /* attach tuner */
  696. si2157_config.fe = dev->dvb->frontend[0];
  697. #ifdef CONFIG_MEDIA_CONTROLLER_DVB
  698. si2157_config.mdev = dev->media_dev;
  699. #endif
  700. si2157_config.if_port = 1;
  701. si2157_config.inversion = true;
  702. /* perform probe/init/attach */
  703. client = dvb_module_probe("si2157", NULL, tuner_i2c,
  704. dev->board.tuner_addr,
  705. &si2157_config);
  706. if (!client) {
  707. result = -ENODEV;
  708. goto out_free;
  709. }
  710. dev->cx231xx_reset_analog_tuner = NULL;
  711. dev->dvb->i2c_client_tuner = client;
  712. break;
  713. }
  714. case CX231XX_BOARD_HAUPPAUGE_955Q:
  715. {
  716. struct si2157_config si2157_config = {};
  717. struct lgdt3306a_config lgdt3306a_config = {};
  718. lgdt3306a_config = hauppauge_955q_lgdt3306a_config;
  719. lgdt3306a_config.fe = &dev->dvb->frontend[0];
  720. lgdt3306a_config.i2c_adapter = &adapter;
  721. /* perform probe/init/attach */
  722. client = dvb_module_probe("lgdt3306a", NULL, demod_i2c,
  723. dev->board.demod_addr,
  724. &lgdt3306a_config);
  725. if (!client) {
  726. result = -ENODEV;
  727. goto out_free;
  728. }
  729. dvb->i2c_client_demod[0] = client;
  730. dev->dvb->frontend[0]->ops.i2c_gate_ctrl = NULL;
  731. /* define general-purpose callback pointer */
  732. dvb->frontend[0]->callback = cx231xx_tuner_callback;
  733. /* attach tuner */
  734. si2157_config.fe = dev->dvb->frontend[0];
  735. #ifdef CONFIG_MEDIA_CONTROLLER_DVB
  736. si2157_config.mdev = dev->media_dev;
  737. #endif
  738. si2157_config.if_port = 1;
  739. si2157_config.inversion = true;
  740. /* perform probe/init/attach */
  741. client = dvb_module_probe("si2157", NULL, tuner_i2c,
  742. dev->board.tuner_addr,
  743. &si2157_config);
  744. if (!client) {
  745. result = -ENODEV;
  746. goto out_free;
  747. }
  748. dev->cx231xx_reset_analog_tuner = NULL;
  749. dev->dvb->i2c_client_tuner = client;
  750. break;
  751. }
  752. case CX231XX_BOARD_PV_PLAYTV_USB_HYBRID:
  753. case CX231XX_BOARD_KWORLD_UB430_USB_HYBRID:
  754. dev_info(dev->dev,
  755. "%s: looking for demod on i2c bus: %d\n",
  756. __func__, i2c_adapter_id(tuner_i2c));
  757. dev->dvb->frontend[0] = dvb_attach(mb86a20s_attach,
  758. &pv_mb86a20s_config,
  759. demod_i2c);
  760. if (!dev->dvb->frontend[0]) {
  761. dev_err(dev->dev,
  762. "Failed to attach mb86a20s demod\n");
  763. result = -EINVAL;
  764. goto out_free;
  765. }
  766. /* define general-purpose callback pointer */
  767. dvb->frontend[0]->callback = cx231xx_tuner_callback;
  768. dvb_attach(tda18271_attach, dev->dvb->frontend[0],
  769. dev->board.tuner_addr, tuner_i2c,
  770. &pv_tda18271_config);
  771. break;
  772. case CX231XX_BOARD_EVROMEDIA_FULL_HYBRID_FULLHD:
  773. {
  774. struct si2157_config si2157_config = {};
  775. struct si2168_config si2168_config = {};
  776. /* attach demodulator chip */
  777. si2168_config.ts_mode = SI2168_TS_SERIAL; /* from *.inf file */
  778. si2168_config.fe = &dev->dvb->frontend[0];
  779. si2168_config.i2c_adapter = &adapter;
  780. si2168_config.ts_clock_inv = true;
  781. /* perform probe/init/attach */
  782. client = dvb_module_probe("si2168", NULL, demod_i2c,
  783. dev->board.demod_addr,
  784. &si2168_config);
  785. if (!client) {
  786. result = -ENODEV;
  787. goto out_free;
  788. }
  789. dvb->i2c_client_demod[0] = client;
  790. /* attach tuner chip */
  791. si2157_config.fe = dev->dvb->frontend[0];
  792. #ifdef CONFIG_MEDIA_CONTROLLER_DVB
  793. si2157_config.mdev = dev->media_dev;
  794. #endif
  795. si2157_config.if_port = 1;
  796. si2157_config.inversion = false;
  797. /* perform probe/init/attach */
  798. client = dvb_module_probe("si2157", NULL, tuner_i2c,
  799. dev->board.tuner_addr,
  800. &si2157_config);
  801. if (!client) {
  802. result = -ENODEV;
  803. goto out_free;
  804. }
  805. dev->cx231xx_reset_analog_tuner = NULL;
  806. dev->dvb->i2c_client_tuner = client;
  807. break;
  808. }
  809. case CX231XX_BOARD_ASTROMETA_T2HYBRID:
  810. {
  811. struct mn88473_config mn88473_config = {};
  812. /* attach demodulator chip */
  813. mn88473_config.i2c_wr_max = 16;
  814. mn88473_config.xtal = 25000000;
  815. mn88473_config.fe = &dev->dvb->frontend[0];
  816. /* perform probe/init/attach */
  817. client = dvb_module_probe("mn88473", NULL, demod_i2c,
  818. dev->board.demod_addr,
  819. &mn88473_config);
  820. if (!client) {
  821. result = -ENODEV;
  822. goto out_free;
  823. }
  824. dvb->i2c_client_demod[0] = client;
  825. /* define general-purpose callback pointer */
  826. dvb->frontend[0]->callback = cx231xx_tuner_callback;
  827. /* attach tuner chip */
  828. dvb_attach(r820t_attach, dev->dvb->frontend[0],
  829. tuner_i2c,
  830. &astrometa_t2hybrid_r820t_config);
  831. break;
  832. }
  833. case CX231XX_BOARD_HAUPPAUGE_935C:
  834. {
  835. struct si2157_config si2157_config = {};
  836. struct si2168_config si2168_config = {};
  837. /* attach demodulator chip */
  838. si2168_config.ts_mode = SI2168_TS_SERIAL;
  839. si2168_config.fe = &dev->dvb->frontend[0];
  840. si2168_config.i2c_adapter = &adapter;
  841. si2168_config.ts_clock_inv = true;
  842. /* perform probe/init/attach */
  843. client = dvb_module_probe("si2168", NULL, demod_i2c,
  844. dev->board.demod_addr,
  845. &si2168_config);
  846. if (!client) {
  847. result = -ENODEV;
  848. goto out_free;
  849. }
  850. dvb->i2c_client_demod[0] = client;
  851. dev->dvb->frontend[0]->ops.i2c_gate_ctrl = NULL;
  852. /* define general-purpose callback pointer */
  853. dvb->frontend[0]->callback = cx231xx_tuner_callback;
  854. /* attach tuner */
  855. si2157_config.fe = dev->dvb->frontend[0];
  856. #ifdef CONFIG_MEDIA_CONTROLLER_DVB
  857. si2157_config.mdev = dev->media_dev;
  858. #endif
  859. si2157_config.if_port = 1;
  860. si2157_config.inversion = true;
  861. /* perform probe/init/attach */
  862. client = dvb_module_probe("si2157", NULL, tuner_i2c,
  863. dev->board.tuner_addr,
  864. &si2157_config);
  865. if (!client) {
  866. result = -ENODEV;
  867. goto out_free;
  868. }
  869. dev->cx231xx_reset_analog_tuner = NULL;
  870. dev->dvb->i2c_client_tuner = client;
  871. break;
  872. }
  873. case CX231XX_BOARD_HAUPPAUGE_975:
  874. {
  875. struct i2c_adapter *adapter2;
  876. struct si2157_config si2157_config = {};
  877. struct lgdt3306a_config lgdt3306a_config = {};
  878. struct si2168_config si2168_config = {};
  879. /* attach first demodulator chip */
  880. lgdt3306a_config = hauppauge_955q_lgdt3306a_config;
  881. lgdt3306a_config.fe = &dev->dvb->frontend[0];
  882. lgdt3306a_config.i2c_adapter = &adapter;
  883. /* perform probe/init/attach */
  884. client = dvb_module_probe("lgdt3306a", NULL, demod_i2c,
  885. dev->board.demod_addr,
  886. &lgdt3306a_config);
  887. if (!client) {
  888. result = -ENODEV;
  889. goto out_free;
  890. }
  891. dvb->i2c_client_demod[0] = client;
  892. /* attach second demodulator chip */
  893. si2168_config.ts_mode = SI2168_TS_SERIAL;
  894. si2168_config.fe = &dev->dvb->frontend[1];
  895. si2168_config.i2c_adapter = &adapter2;
  896. si2168_config.ts_clock_inv = true;
  897. /* perform probe/init/attach */
  898. client = dvb_module_probe("si2168", NULL, adapter,
  899. dev->board.demod_addr2,
  900. &si2168_config);
  901. if (!client) {
  902. result = -ENODEV;
  903. goto out_free;
  904. }
  905. dvb->i2c_client_demod[1] = client;
  906. dvb->frontend[1]->id = 1;
  907. /* define general-purpose callback pointer */
  908. dvb->frontend[0]->callback = cx231xx_tuner_callback;
  909. dvb->frontend[1]->callback = cx231xx_tuner_callback;
  910. /* attach tuner */
  911. si2157_config.fe = dev->dvb->frontend[0];
  912. #ifdef CONFIG_MEDIA_CONTROLLER_DVB
  913. si2157_config.mdev = dev->media_dev;
  914. #endif
  915. si2157_config.if_port = 1;
  916. si2157_config.inversion = true;
  917. /* perform probe/init/attach */
  918. client = dvb_module_probe("si2157", NULL, adapter,
  919. dev->board.tuner_addr,
  920. &si2157_config);
  921. if (!client) {
  922. result = -ENODEV;
  923. goto out_free;
  924. }
  925. dev->cx231xx_reset_analog_tuner = NULL;
  926. dvb->i2c_client_tuner = client;
  927. dvb->frontend[1]->tuner_priv = dvb->frontend[0]->tuner_priv;
  928. memcpy(&dvb->frontend[1]->ops.tuner_ops,
  929. &dvb->frontend[0]->ops.tuner_ops,
  930. sizeof(struct dvb_tuner_ops));
  931. break;
  932. }
  933. default:
  934. dev_err(dev->dev,
  935. "%s/2: The frontend of your DVB/ATSC card isn't supported yet\n",
  936. dev->name);
  937. break;
  938. }
  939. if (!dvb->frontend[0]) {
  940. dev_err(dev->dev,
  941. "%s/2: frontend initialization failed\n", dev->name);
  942. result = -EINVAL;
  943. goto out_free;
  944. }
  945. /* register everything */
  946. result = register_dvb(dvb, THIS_MODULE, dev, dev->dev);
  947. if (result < 0)
  948. goto out_free;
  949. dev_info(dev->dev, "Successfully loaded cx231xx-dvb\n");
  950. ret:
  951. cx231xx_set_mode(dev, CX231XX_SUSPEND);
  952. mutex_unlock(&dev->lock);
  953. return result;
  954. out_free:
  955. /* remove I2C tuner */
  956. dvb_module_release(dvb->i2c_client_tuner);
  957. dvb->i2c_client_tuner = NULL;
  958. /* remove I2C demod(s) */
  959. dvb_module_release(dvb->i2c_client_demod[1]);
  960. dvb->i2c_client_demod[1] = NULL;
  961. dvb_module_release(dvb->i2c_client_demod[0]);
  962. dvb->i2c_client_demod[0] = NULL;
  963. kfree(dvb);
  964. dev->dvb = NULL;
  965. goto ret;
  966. }
  967. static int dvb_fini(struct cx231xx *dev)
  968. {
  969. if (!dev->board.has_dvb) {
  970. /* This device does not support the extension */
  971. return 0;
  972. }
  973. if (dev->dvb) {
  974. unregister_dvb(dev->dvb);
  975. dev->dvb = NULL;
  976. }
  977. return 0;
  978. }
  979. static struct cx231xx_ops dvb_ops = {
  980. .id = CX231XX_DVB,
  981. .name = "Cx231xx dvb Extension",
  982. .init = dvb_init,
  983. .fini = dvb_fini,
  984. };
  985. static int __init cx231xx_dvb_register(void)
  986. {
  987. return cx231xx_register_extension(&dvb_ops);
  988. }
  989. static void __exit cx231xx_dvb_unregister(void)
  990. {
  991. cx231xx_unregister_extension(&dvb_ops);
  992. }
  993. module_init(cx231xx_dvb_register);
  994. module_exit(cx231xx_dvb_unregister);