pluto2.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798
  1. /*
  2. * pluto2.c - Satelco Easywatch Mobile Terrestrial Receiver [DVB-T]
  3. *
  4. * Copyright (C) 2005 Andreas Oberritter <obi@linuxtv.org>
  5. *
  6. * based on pluto2.c 1.10 - http://instinct-wp8.no-ip.org/pluto/
  7. * by Dany Salman <salmandany@yahoo.fr>
  8. * Copyright (c) 2004 TDF
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. */
  21. #include <linux/i2c.h>
  22. #include <linux/i2c-algo-bit.h>
  23. #include <linux/init.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/kernel.h>
  26. #include <linux/module.h>
  27. #include <linux/pci.h>
  28. #include <linux/dma-mapping.h>
  29. #include <linux/slab.h>
  30. #include "demux.h"
  31. #include "dmxdev.h"
  32. #include "dvb_demux.h"
  33. #include "dvb_frontend.h"
  34. #include "dvb_net.h"
  35. #include "dvbdev.h"
  36. #include "tda1004x.h"
  37. DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
  38. #define DRIVER_NAME "pluto2"
  39. #define REG_PIDn(n) ((n) << 2) /* PID n pattern registers */
  40. #define REG_PCAR 0x0020 /* PC address register */
  41. #define REG_TSCR 0x0024 /* TS ctrl & status */
  42. #define REG_MISC 0x0028 /* miscellaneous */
  43. #define REG_MMAC 0x002c /* MSB MAC address */
  44. #define REG_IMAC 0x0030 /* ISB MAC address */
  45. #define REG_LMAC 0x0034 /* LSB MAC address */
  46. #define REG_SPID 0x0038 /* SPI data */
  47. #define REG_SLCS 0x003c /* serial links ctrl/status */
  48. #define PID0_NOFIL (0x0001 << 16)
  49. #define PIDn_ENP (0x0001 << 15)
  50. #define PID0_END (0x0001 << 14)
  51. #define PID0_AFIL (0x0001 << 13)
  52. #define PIDn_PID (0x1fff << 0)
  53. #define TSCR_NBPACKETS (0x00ff << 24)
  54. #define TSCR_DEM (0x0001 << 17)
  55. #define TSCR_DE (0x0001 << 16)
  56. #define TSCR_RSTN (0x0001 << 15)
  57. #define TSCR_MSKO (0x0001 << 14)
  58. #define TSCR_MSKA (0x0001 << 13)
  59. #define TSCR_MSKL (0x0001 << 12)
  60. #define TSCR_OVR (0x0001 << 11)
  61. #define TSCR_AFUL (0x0001 << 10)
  62. #define TSCR_LOCK (0x0001 << 9)
  63. #define TSCR_IACK (0x0001 << 8)
  64. #define TSCR_ADEF (0x007f << 0)
  65. #define MISC_DVR (0x0fff << 4)
  66. #define MISC_ALED (0x0001 << 3)
  67. #define MISC_FRST (0x0001 << 2)
  68. #define MISC_LED1 (0x0001 << 1)
  69. #define MISC_LED0 (0x0001 << 0)
  70. #define SPID_SPIDR (0x00ff << 0)
  71. #define SLCS_SCL (0x0001 << 7)
  72. #define SLCS_SDA (0x0001 << 6)
  73. #define SLCS_CSN (0x0001 << 2)
  74. #define SLCS_OVR (0x0001 << 1)
  75. #define SLCS_SWC (0x0001 << 0)
  76. #define TS_DMA_PACKETS (8)
  77. #define TS_DMA_BYTES (188 * TS_DMA_PACKETS)
  78. #define I2C_ADDR_TDA10046 0x10
  79. #define I2C_ADDR_TUA6034 0xc2
  80. #define NHWFILTERS 8
  81. struct pluto {
  82. /* pci */
  83. struct pci_dev *pdev;
  84. u8 __iomem *io_mem;
  85. /* dvb */
  86. struct dmx_frontend hw_frontend;
  87. struct dmx_frontend mem_frontend;
  88. struct dmxdev dmxdev;
  89. struct dvb_adapter dvb_adapter;
  90. struct dvb_demux demux;
  91. struct dvb_frontend *fe;
  92. struct dvb_net dvbnet;
  93. unsigned int full_ts_users;
  94. unsigned int users;
  95. /* i2c */
  96. struct i2c_algo_bit_data i2c_bit;
  97. struct i2c_adapter i2c_adap;
  98. unsigned int i2cbug;
  99. /* irq */
  100. unsigned int overflow;
  101. unsigned int dead;
  102. /* dma */
  103. dma_addr_t dma_addr;
  104. u8 dma_buf[TS_DMA_BYTES];
  105. u8 dummy[4096];
  106. };
  107. static inline struct pluto *feed_to_pluto(struct dvb_demux_feed *feed)
  108. {
  109. return container_of(feed->demux, struct pluto, demux);
  110. }
  111. static inline struct pluto *frontend_to_pluto(struct dvb_frontend *fe)
  112. {
  113. return container_of(fe->dvb, struct pluto, dvb_adapter);
  114. }
  115. static inline u32 pluto_readreg(struct pluto *pluto, u32 reg)
  116. {
  117. return readl(&pluto->io_mem[reg]);
  118. }
  119. static inline void pluto_writereg(struct pluto *pluto, u32 reg, u32 val)
  120. {
  121. writel(val, &pluto->io_mem[reg]);
  122. }
  123. static inline void pluto_rw(struct pluto *pluto, u32 reg, u32 mask, u32 bits)
  124. {
  125. u32 val = readl(&pluto->io_mem[reg]);
  126. val &= ~mask;
  127. val |= bits;
  128. writel(val, &pluto->io_mem[reg]);
  129. }
  130. static void pluto_write_tscr(struct pluto *pluto, u32 val)
  131. {
  132. /* set the number of packets */
  133. val &= ~TSCR_ADEF;
  134. val |= TS_DMA_PACKETS / 2;
  135. pluto_writereg(pluto, REG_TSCR, val);
  136. }
  137. static void pluto_setsda(void *data, int state)
  138. {
  139. struct pluto *pluto = data;
  140. if (state)
  141. pluto_rw(pluto, REG_SLCS, SLCS_SDA, SLCS_SDA);
  142. else
  143. pluto_rw(pluto, REG_SLCS, SLCS_SDA, 0);
  144. }
  145. static void pluto_setscl(void *data, int state)
  146. {
  147. struct pluto *pluto = data;
  148. if (state)
  149. pluto_rw(pluto, REG_SLCS, SLCS_SCL, SLCS_SCL);
  150. else
  151. pluto_rw(pluto, REG_SLCS, SLCS_SCL, 0);
  152. /* try to detect i2c_inb() to workaround hardware bug:
  153. * reset SDA to high after SCL has been set to low */
  154. if ((state) && (pluto->i2cbug == 0)) {
  155. pluto->i2cbug = 1;
  156. } else {
  157. if ((!state) && (pluto->i2cbug == 1))
  158. pluto_setsda(pluto, 1);
  159. pluto->i2cbug = 0;
  160. }
  161. }
  162. static int pluto_getsda(void *data)
  163. {
  164. struct pluto *pluto = data;
  165. return pluto_readreg(pluto, REG_SLCS) & SLCS_SDA;
  166. }
  167. static int pluto_getscl(void *data)
  168. {
  169. struct pluto *pluto = data;
  170. return pluto_readreg(pluto, REG_SLCS) & SLCS_SCL;
  171. }
  172. static void pluto_reset_frontend(struct pluto *pluto, int reenable)
  173. {
  174. u32 val = pluto_readreg(pluto, REG_MISC);
  175. if (val & MISC_FRST) {
  176. val &= ~MISC_FRST;
  177. pluto_writereg(pluto, REG_MISC, val);
  178. }
  179. if (reenable) {
  180. val |= MISC_FRST;
  181. pluto_writereg(pluto, REG_MISC, val);
  182. }
  183. }
  184. static void pluto_reset_ts(struct pluto *pluto, int reenable)
  185. {
  186. u32 val = pluto_readreg(pluto, REG_TSCR);
  187. if (val & TSCR_RSTN) {
  188. val &= ~TSCR_RSTN;
  189. pluto_write_tscr(pluto, val);
  190. }
  191. if (reenable) {
  192. val |= TSCR_RSTN;
  193. pluto_write_tscr(pluto, val);
  194. }
  195. }
  196. static void pluto_set_dma_addr(struct pluto *pluto)
  197. {
  198. pluto_writereg(pluto, REG_PCAR, pluto->dma_addr);
  199. }
  200. static int pluto_dma_map(struct pluto *pluto)
  201. {
  202. pluto->dma_addr = pci_map_single(pluto->pdev, pluto->dma_buf,
  203. TS_DMA_BYTES, PCI_DMA_FROMDEVICE);
  204. return pci_dma_mapping_error(pluto->pdev, pluto->dma_addr);
  205. }
  206. static void pluto_dma_unmap(struct pluto *pluto)
  207. {
  208. pci_unmap_single(pluto->pdev, pluto->dma_addr,
  209. TS_DMA_BYTES, PCI_DMA_FROMDEVICE);
  210. }
  211. static int pluto_start_feed(struct dvb_demux_feed *f)
  212. {
  213. struct pluto *pluto = feed_to_pluto(f);
  214. /* enable PID filtering */
  215. if (pluto->users++ == 0)
  216. pluto_rw(pluto, REG_PIDn(0), PID0_AFIL | PID0_NOFIL, 0);
  217. if ((f->pid < 0x2000) && (f->index < NHWFILTERS))
  218. pluto_rw(pluto, REG_PIDn(f->index), PIDn_ENP | PIDn_PID, PIDn_ENP | f->pid);
  219. else if (pluto->full_ts_users++ == 0)
  220. pluto_rw(pluto, REG_PIDn(0), PID0_NOFIL, PID0_NOFIL);
  221. return 0;
  222. }
  223. static int pluto_stop_feed(struct dvb_demux_feed *f)
  224. {
  225. struct pluto *pluto = feed_to_pluto(f);
  226. /* disable PID filtering */
  227. if (--pluto->users == 0)
  228. pluto_rw(pluto, REG_PIDn(0), PID0_AFIL, PID0_AFIL);
  229. if ((f->pid < 0x2000) && (f->index < NHWFILTERS))
  230. pluto_rw(pluto, REG_PIDn(f->index), PIDn_ENP | PIDn_PID, 0x1fff);
  231. else if (--pluto->full_ts_users == 0)
  232. pluto_rw(pluto, REG_PIDn(0), PID0_NOFIL, 0);
  233. return 0;
  234. }
  235. static void pluto_dma_end(struct pluto *pluto, unsigned int nbpackets)
  236. {
  237. /* synchronize the DMA transfer with the CPU
  238. * first so that we see updated contents. */
  239. pci_dma_sync_single_for_cpu(pluto->pdev, pluto->dma_addr,
  240. TS_DMA_BYTES, PCI_DMA_FROMDEVICE);
  241. /* Workaround for broken hardware:
  242. * [1] On startup NBPACKETS seems to contain an uninitialized value,
  243. * but no packets have been transferred.
  244. * [2] Sometimes (actually very often) NBPACKETS stays at zero
  245. * although one packet has been transferred.
  246. * [3] Sometimes (actually rarely), the card gets into an erroneous
  247. * mode where it continuously generates interrupts, claiming it
  248. * has received nbpackets>TS_DMA_PACKETS packets, but no packet
  249. * has been transferred. Only a reset seems to solve this
  250. */
  251. if ((nbpackets == 0) || (nbpackets > TS_DMA_PACKETS)) {
  252. unsigned int i = 0;
  253. while (pluto->dma_buf[i] == 0x47)
  254. i += 188;
  255. nbpackets = i / 188;
  256. if (i == 0) {
  257. pluto_reset_ts(pluto, 1);
  258. dev_printk(KERN_DEBUG, &pluto->pdev->dev, "resetting TS because of invalid packet counter\n");
  259. }
  260. }
  261. dvb_dmx_swfilter_packets(&pluto->demux, pluto->dma_buf, nbpackets);
  262. /* clear the dma buffer. this is needed to be able to identify
  263. * new valid ts packets above */
  264. memset(pluto->dma_buf, 0, nbpackets * 188);
  265. /* reset the dma address */
  266. pluto_set_dma_addr(pluto);
  267. /* sync the buffer and give it back to the card */
  268. pci_dma_sync_single_for_device(pluto->pdev, pluto->dma_addr,
  269. TS_DMA_BYTES, PCI_DMA_FROMDEVICE);
  270. }
  271. static irqreturn_t pluto_irq(int irq, void *dev_id)
  272. {
  273. struct pluto *pluto = dev_id;
  274. u32 tscr;
  275. /* check whether an interrupt occurred on this device */
  276. tscr = pluto_readreg(pluto, REG_TSCR);
  277. if (!(tscr & (TSCR_DE | TSCR_OVR)))
  278. return IRQ_NONE;
  279. if (tscr == 0xffffffff) {
  280. if (pluto->dead == 0)
  281. dev_err(&pluto->pdev->dev, "card has hung or been ejected.\n");
  282. /* It's dead Jim */
  283. pluto->dead = 1;
  284. return IRQ_HANDLED;
  285. }
  286. /* dma end interrupt */
  287. if (tscr & TSCR_DE) {
  288. pluto_dma_end(pluto, (tscr & TSCR_NBPACKETS) >> 24);
  289. /* overflow interrupt */
  290. if (tscr & TSCR_OVR)
  291. pluto->overflow++;
  292. if (pluto->overflow) {
  293. dev_err(&pluto->pdev->dev, "overflow irq (%d)\n",
  294. pluto->overflow);
  295. pluto_reset_ts(pluto, 1);
  296. pluto->overflow = 0;
  297. }
  298. } else if (tscr & TSCR_OVR) {
  299. pluto->overflow++;
  300. }
  301. /* ACK the interrupt */
  302. pluto_write_tscr(pluto, tscr | TSCR_IACK);
  303. return IRQ_HANDLED;
  304. }
  305. static void pluto_enable_irqs(struct pluto *pluto)
  306. {
  307. u32 val = pluto_readreg(pluto, REG_TSCR);
  308. /* disable AFUL and LOCK interrupts */
  309. val |= (TSCR_MSKA | TSCR_MSKL);
  310. /* enable DMA and OVERFLOW interrupts */
  311. val &= ~(TSCR_DEM | TSCR_MSKO);
  312. /* clear pending interrupts */
  313. val |= TSCR_IACK;
  314. pluto_write_tscr(pluto, val);
  315. }
  316. static void pluto_disable_irqs(struct pluto *pluto)
  317. {
  318. u32 val = pluto_readreg(pluto, REG_TSCR);
  319. /* disable all interrupts */
  320. val |= (TSCR_DEM | TSCR_MSKO | TSCR_MSKA | TSCR_MSKL);
  321. /* clear pending interrupts */
  322. val |= TSCR_IACK;
  323. pluto_write_tscr(pluto, val);
  324. }
  325. static int pluto_hw_init(struct pluto *pluto)
  326. {
  327. pluto_reset_frontend(pluto, 1);
  328. /* set automatic LED control by FPGA */
  329. pluto_rw(pluto, REG_MISC, MISC_ALED, MISC_ALED);
  330. /* set data endianness */
  331. #ifdef __LITTLE_ENDIAN
  332. pluto_rw(pluto, REG_PIDn(0), PID0_END, PID0_END);
  333. #else
  334. pluto_rw(pluto, REG_PIDn(0), PID0_END, 0);
  335. #endif
  336. /* map DMA and set address */
  337. pluto_dma_map(pluto);
  338. pluto_set_dma_addr(pluto);
  339. /* enable interrupts */
  340. pluto_enable_irqs(pluto);
  341. /* reset TS logic */
  342. pluto_reset_ts(pluto, 1);
  343. return 0;
  344. }
  345. static void pluto_hw_exit(struct pluto *pluto)
  346. {
  347. /* disable interrupts */
  348. pluto_disable_irqs(pluto);
  349. pluto_reset_ts(pluto, 0);
  350. /* LED: disable automatic control, enable yellow, disable green */
  351. pluto_rw(pluto, REG_MISC, MISC_ALED | MISC_LED1 | MISC_LED0, MISC_LED1);
  352. /* unmap DMA */
  353. pluto_dma_unmap(pluto);
  354. pluto_reset_frontend(pluto, 0);
  355. }
  356. static inline u32 divide(u32 numerator, u32 denominator)
  357. {
  358. if (denominator == 0)
  359. return ~0;
  360. return DIV_ROUND_CLOSEST(numerator, denominator);
  361. }
  362. /* LG Innotek TDTE-E001P (Infineon TUA6034) */
  363. static int lg_tdtpe001p_tuner_set_params(struct dvb_frontend *fe)
  364. {
  365. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  366. struct pluto *pluto = frontend_to_pluto(fe);
  367. struct i2c_msg msg;
  368. int ret;
  369. u8 buf[4];
  370. u32 div;
  371. // Fref = 166.667 Hz
  372. // Fref * 3 = 500.000 Hz
  373. // IF = 36166667
  374. // IF / Fref = 217
  375. //div = divide(p->frequency + 36166667, 166667);
  376. div = divide(p->frequency * 3, 500000) + 217;
  377. buf[0] = (div >> 8) & 0x7f;
  378. buf[1] = (div >> 0) & 0xff;
  379. if (p->frequency < 611000000)
  380. buf[2] = 0xb4;
  381. else if (p->frequency < 811000000)
  382. buf[2] = 0xbc;
  383. else
  384. buf[2] = 0xf4;
  385. // VHF: 174-230 MHz
  386. // center: 350 MHz
  387. // UHF: 470-862 MHz
  388. if (p->frequency < 350000000)
  389. buf[3] = 0x02;
  390. else
  391. buf[3] = 0x04;
  392. if (p->bandwidth_hz == 8000000)
  393. buf[3] |= 0x08;
  394. msg.addr = I2C_ADDR_TUA6034 >> 1;
  395. msg.flags = 0;
  396. msg.buf = buf;
  397. msg.len = sizeof(buf);
  398. if (fe->ops.i2c_gate_ctrl)
  399. fe->ops.i2c_gate_ctrl(fe, 1);
  400. ret = i2c_transfer(&pluto->i2c_adap, &msg, 1);
  401. if (ret < 0)
  402. return ret;
  403. else if (ret == 0)
  404. return -EREMOTEIO;
  405. return 0;
  406. }
  407. static int pluto2_request_firmware(struct dvb_frontend *fe,
  408. const struct firmware **fw, char *name)
  409. {
  410. struct pluto *pluto = frontend_to_pluto(fe);
  411. return request_firmware(fw, name, &pluto->pdev->dev);
  412. }
  413. static struct tda1004x_config pluto2_fe_config = {
  414. .demod_address = I2C_ADDR_TDA10046 >> 1,
  415. .invert = 1,
  416. .invert_oclk = 0,
  417. .xtal_freq = TDA10046_XTAL_16M,
  418. .agc_config = TDA10046_AGC_DEFAULT,
  419. .if_freq = TDA10046_FREQ_3617,
  420. .request_firmware = pluto2_request_firmware,
  421. };
  422. static int frontend_init(struct pluto *pluto)
  423. {
  424. int ret;
  425. pluto->fe = tda10046_attach(&pluto2_fe_config, &pluto->i2c_adap);
  426. if (!pluto->fe) {
  427. dev_err(&pluto->pdev->dev, "could not attach frontend\n");
  428. return -ENODEV;
  429. }
  430. pluto->fe->ops.tuner_ops.set_params = lg_tdtpe001p_tuner_set_params;
  431. ret = dvb_register_frontend(&pluto->dvb_adapter, pluto->fe);
  432. if (ret < 0) {
  433. if (pluto->fe->ops.release)
  434. pluto->fe->ops.release(pluto->fe);
  435. return ret;
  436. }
  437. return 0;
  438. }
  439. static void pluto_read_rev(struct pluto *pluto)
  440. {
  441. u32 val = pluto_readreg(pluto, REG_MISC) & MISC_DVR;
  442. dev_info(&pluto->pdev->dev, "board revision %d.%d\n",
  443. (val >> 12) & 0x0f, (val >> 4) & 0xff);
  444. }
  445. static void pluto_read_mac(struct pluto *pluto, u8 *mac)
  446. {
  447. u32 val = pluto_readreg(pluto, REG_MMAC);
  448. mac[0] = (val >> 8) & 0xff;
  449. mac[1] = (val >> 0) & 0xff;
  450. val = pluto_readreg(pluto, REG_IMAC);
  451. mac[2] = (val >> 8) & 0xff;
  452. mac[3] = (val >> 0) & 0xff;
  453. val = pluto_readreg(pluto, REG_LMAC);
  454. mac[4] = (val >> 8) & 0xff;
  455. mac[5] = (val >> 0) & 0xff;
  456. dev_info(&pluto->pdev->dev, "MAC %pM\n", mac);
  457. }
  458. static int pluto_read_serial(struct pluto *pluto)
  459. {
  460. struct pci_dev *pdev = pluto->pdev;
  461. unsigned int i, j;
  462. u8 __iomem *cis;
  463. cis = pci_iomap(pdev, 1, 0);
  464. if (!cis)
  465. return -EIO;
  466. dev_info(&pdev->dev, "S/N ");
  467. for (i = 0xe0; i < 0x100; i += 4) {
  468. u32 val = readl(&cis[i]);
  469. for (j = 0; j < 32; j += 8) {
  470. if ((val & 0xff) == 0xff)
  471. goto out;
  472. printk(KERN_CONT "%c", val & 0xff);
  473. val >>= 8;
  474. }
  475. }
  476. out:
  477. printk(KERN_CONT "\n");
  478. pci_iounmap(pdev, cis);
  479. return 0;
  480. }
  481. static int pluto2_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  482. {
  483. struct pluto *pluto;
  484. struct dvb_adapter *dvb_adapter;
  485. struct dvb_demux *dvbdemux;
  486. struct dmx_demux *dmx;
  487. int ret = -ENOMEM;
  488. pluto = kzalloc(sizeof(struct pluto), GFP_KERNEL);
  489. if (!pluto)
  490. goto out;
  491. pluto->pdev = pdev;
  492. ret = pci_enable_device(pdev);
  493. if (ret < 0)
  494. goto err_kfree;
  495. /* enable interrupts */
  496. pci_write_config_dword(pdev, 0x6c, 0x8000);
  497. ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  498. if (ret < 0)
  499. goto err_pci_disable_device;
  500. pci_set_master(pdev);
  501. ret = pci_request_regions(pdev, DRIVER_NAME);
  502. if (ret < 0)
  503. goto err_pci_disable_device;
  504. pluto->io_mem = pci_iomap(pdev, 0, 0x40);
  505. if (!pluto->io_mem) {
  506. ret = -EIO;
  507. goto err_pci_release_regions;
  508. }
  509. pci_set_drvdata(pdev, pluto);
  510. ret = request_irq(pdev->irq, pluto_irq, IRQF_SHARED, DRIVER_NAME, pluto);
  511. if (ret < 0)
  512. goto err_pci_iounmap;
  513. ret = pluto_hw_init(pluto);
  514. if (ret < 0)
  515. goto err_free_irq;
  516. /* i2c */
  517. i2c_set_adapdata(&pluto->i2c_adap, pluto);
  518. strcpy(pluto->i2c_adap.name, DRIVER_NAME);
  519. pluto->i2c_adap.owner = THIS_MODULE;
  520. pluto->i2c_adap.dev.parent = &pdev->dev;
  521. pluto->i2c_adap.algo_data = &pluto->i2c_bit;
  522. pluto->i2c_bit.data = pluto;
  523. pluto->i2c_bit.setsda = pluto_setsda;
  524. pluto->i2c_bit.setscl = pluto_setscl;
  525. pluto->i2c_bit.getsda = pluto_getsda;
  526. pluto->i2c_bit.getscl = pluto_getscl;
  527. pluto->i2c_bit.udelay = 10;
  528. pluto->i2c_bit.timeout = 10;
  529. /* Raise SCL and SDA */
  530. pluto_setsda(pluto, 1);
  531. pluto_setscl(pluto, 1);
  532. ret = i2c_bit_add_bus(&pluto->i2c_adap);
  533. if (ret < 0)
  534. goto err_pluto_hw_exit;
  535. /* dvb */
  536. ret = dvb_register_adapter(&pluto->dvb_adapter, DRIVER_NAME,
  537. THIS_MODULE, &pdev->dev, adapter_nr);
  538. if (ret < 0)
  539. goto err_i2c_del_adapter;
  540. dvb_adapter = &pluto->dvb_adapter;
  541. pluto_read_rev(pluto);
  542. pluto_read_serial(pluto);
  543. pluto_read_mac(pluto, dvb_adapter->proposed_mac);
  544. dvbdemux = &pluto->demux;
  545. dvbdemux->filternum = 256;
  546. dvbdemux->feednum = 256;
  547. dvbdemux->start_feed = pluto_start_feed;
  548. dvbdemux->stop_feed = pluto_stop_feed;
  549. dvbdemux->dmx.capabilities = (DMX_TS_FILTERING |
  550. DMX_SECTION_FILTERING | DMX_MEMORY_BASED_FILTERING);
  551. ret = dvb_dmx_init(dvbdemux);
  552. if (ret < 0)
  553. goto err_dvb_unregister_adapter;
  554. dmx = &dvbdemux->dmx;
  555. pluto->hw_frontend.source = DMX_FRONTEND_0;
  556. pluto->mem_frontend.source = DMX_MEMORY_FE;
  557. pluto->dmxdev.filternum = NHWFILTERS;
  558. pluto->dmxdev.demux = dmx;
  559. ret = dvb_dmxdev_init(&pluto->dmxdev, dvb_adapter);
  560. if (ret < 0)
  561. goto err_dvb_dmx_release;
  562. ret = dmx->add_frontend(dmx, &pluto->hw_frontend);
  563. if (ret < 0)
  564. goto err_dvb_dmxdev_release;
  565. ret = dmx->add_frontend(dmx, &pluto->mem_frontend);
  566. if (ret < 0)
  567. goto err_remove_hw_frontend;
  568. ret = dmx->connect_frontend(dmx, &pluto->hw_frontend);
  569. if (ret < 0)
  570. goto err_remove_mem_frontend;
  571. ret = frontend_init(pluto);
  572. if (ret < 0)
  573. goto err_disconnect_frontend;
  574. dvb_net_init(dvb_adapter, &pluto->dvbnet, dmx);
  575. out:
  576. return ret;
  577. err_disconnect_frontend:
  578. dmx->disconnect_frontend(dmx);
  579. err_remove_mem_frontend:
  580. dmx->remove_frontend(dmx, &pluto->mem_frontend);
  581. err_remove_hw_frontend:
  582. dmx->remove_frontend(dmx, &pluto->hw_frontend);
  583. err_dvb_dmxdev_release:
  584. dvb_dmxdev_release(&pluto->dmxdev);
  585. err_dvb_dmx_release:
  586. dvb_dmx_release(dvbdemux);
  587. err_dvb_unregister_adapter:
  588. dvb_unregister_adapter(dvb_adapter);
  589. err_i2c_del_adapter:
  590. i2c_del_adapter(&pluto->i2c_adap);
  591. err_pluto_hw_exit:
  592. pluto_hw_exit(pluto);
  593. err_free_irq:
  594. free_irq(pdev->irq, pluto);
  595. err_pci_iounmap:
  596. pci_iounmap(pdev, pluto->io_mem);
  597. err_pci_release_regions:
  598. pci_release_regions(pdev);
  599. err_pci_disable_device:
  600. pci_disable_device(pdev);
  601. err_kfree:
  602. kfree(pluto);
  603. goto out;
  604. }
  605. static void pluto2_remove(struct pci_dev *pdev)
  606. {
  607. struct pluto *pluto = pci_get_drvdata(pdev);
  608. struct dvb_adapter *dvb_adapter = &pluto->dvb_adapter;
  609. struct dvb_demux *dvbdemux = &pluto->demux;
  610. struct dmx_demux *dmx = &dvbdemux->dmx;
  611. dmx->close(dmx);
  612. dvb_net_release(&pluto->dvbnet);
  613. if (pluto->fe)
  614. dvb_unregister_frontend(pluto->fe);
  615. dmx->disconnect_frontend(dmx);
  616. dmx->remove_frontend(dmx, &pluto->mem_frontend);
  617. dmx->remove_frontend(dmx, &pluto->hw_frontend);
  618. dvb_dmxdev_release(&pluto->dmxdev);
  619. dvb_dmx_release(dvbdemux);
  620. dvb_unregister_adapter(dvb_adapter);
  621. i2c_del_adapter(&pluto->i2c_adap);
  622. pluto_hw_exit(pluto);
  623. free_irq(pdev->irq, pluto);
  624. pci_iounmap(pdev, pluto->io_mem);
  625. pci_release_regions(pdev);
  626. pci_disable_device(pdev);
  627. kfree(pluto);
  628. }
  629. #ifndef PCI_VENDOR_ID_SCM
  630. #define PCI_VENDOR_ID_SCM 0x0432
  631. #endif
  632. #ifndef PCI_DEVICE_ID_PLUTO2
  633. #define PCI_DEVICE_ID_PLUTO2 0x0001
  634. #endif
  635. static const struct pci_device_id pluto2_id_table[] = {
  636. {
  637. .vendor = PCI_VENDOR_ID_SCM,
  638. .device = PCI_DEVICE_ID_PLUTO2,
  639. .subvendor = PCI_ANY_ID,
  640. .subdevice = PCI_ANY_ID,
  641. }, {
  642. /* empty */
  643. },
  644. };
  645. MODULE_DEVICE_TABLE(pci, pluto2_id_table);
  646. static struct pci_driver pluto2_driver = {
  647. .name = DRIVER_NAME,
  648. .id_table = pluto2_id_table,
  649. .probe = pluto2_probe,
  650. .remove = pluto2_remove,
  651. };
  652. module_pci_driver(pluto2_driver);
  653. MODULE_AUTHOR("Andreas Oberritter <obi@linuxtv.org>");
  654. MODULE_DESCRIPTION("Pluto2 driver");
  655. MODULE_LICENSE("GPL");