pluto2.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808
  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. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23. *
  24. */
  25. #include <linux/i2c.h>
  26. #include <linux/i2c-algo-bit.h>
  27. #include <linux/init.h>
  28. #include <linux/kernel.h>
  29. #include <linux/module.h>
  30. #include <linux/pci.h>
  31. #include <linux/dma-mapping.h>
  32. #include "demux.h"
  33. #include "dmxdev.h"
  34. #include "dvb_demux.h"
  35. #include "dvb_frontend.h"
  36. #include "dvb_net.h"
  37. #include "dvbdev.h"
  38. #include "tda1004x.h"
  39. #define DRIVER_NAME "pluto2"
  40. #define REG_PIDn(n) ((n) << 2) /* PID n pattern registers */
  41. #define REG_PCAR 0x0020 /* PC address register */
  42. #define REG_TSCR 0x0024 /* TS ctrl & status */
  43. #define REG_MISC 0x0028 /* miscellaneous */
  44. #define REG_MMAC 0x002c /* MSB MAC address */
  45. #define REG_IMAC 0x0030 /* ISB MAC address */
  46. #define REG_LMAC 0x0034 /* LSB MAC address */
  47. #define REG_SPID 0x0038 /* SPI data */
  48. #define REG_SLCS 0x003c /* serial links ctrl/status */
  49. #define PID0_NOFIL (0x0001 << 16)
  50. #define PIDn_ENP (0x0001 << 15)
  51. #define PID0_END (0x0001 << 14)
  52. #define PID0_AFIL (0x0001 << 13)
  53. #define PIDn_PID (0x1fff << 0)
  54. #define TSCR_NBPACKETS (0x00ff << 24)
  55. #define TSCR_DEM (0x0001 << 17)
  56. #define TSCR_DE (0x0001 << 16)
  57. #define TSCR_RSTN (0x0001 << 15)
  58. #define TSCR_MSKO (0x0001 << 14)
  59. #define TSCR_MSKA (0x0001 << 13)
  60. #define TSCR_MSKL (0x0001 << 12)
  61. #define TSCR_OVR (0x0001 << 11)
  62. #define TSCR_AFUL (0x0001 << 10)
  63. #define TSCR_LOCK (0x0001 << 9)
  64. #define TSCR_IACK (0x0001 << 8)
  65. #define TSCR_ADEF (0x007f << 0)
  66. #define MISC_DVR (0x0fff << 4)
  67. #define MISC_ALED (0x0001 << 3)
  68. #define MISC_FRST (0x0001 << 2)
  69. #define MISC_LED1 (0x0001 << 1)
  70. #define MISC_LED0 (0x0001 << 0)
  71. #define SPID_SPIDR (0x00ff << 0)
  72. #define SLCS_SCL (0x0001 << 7)
  73. #define SLCS_SDA (0x0001 << 6)
  74. #define SLCS_CSN (0x0001 << 2)
  75. #define SLCS_OVR (0x0001 << 1)
  76. #define SLCS_SWC (0x0001 << 0)
  77. #define TS_DMA_PACKETS (8)
  78. #define TS_DMA_BYTES (188 * TS_DMA_PACKETS)
  79. #define I2C_ADDR_TDA10046 0x10
  80. #define I2C_ADDR_TUA6034 0xc2
  81. #define NHWFILTERS 8
  82. struct pluto {
  83. /* pci */
  84. struct pci_dev *pdev;
  85. u8 __iomem *io_mem;
  86. /* dvb */
  87. struct dmx_frontend hw_frontend;
  88. struct dmx_frontend mem_frontend;
  89. struct dmxdev dmxdev;
  90. struct dvb_adapter dvb_adapter;
  91. struct dvb_demux demux;
  92. struct dvb_frontend *fe;
  93. struct dvb_net dvbnet;
  94. unsigned int full_ts_users;
  95. unsigned int users;
  96. /* i2c */
  97. struct i2c_algo_bit_data i2c_bit;
  98. struct i2c_adapter i2c_adap;
  99. unsigned int i2cbug;
  100. /* irq */
  101. unsigned int overflow;
  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_setsda(void *data, int state)
  131. {
  132. struct pluto *pluto = data;
  133. if (state)
  134. pluto_rw(pluto, REG_SLCS, SLCS_SDA, SLCS_SDA);
  135. else
  136. pluto_rw(pluto, REG_SLCS, SLCS_SDA, 0);
  137. }
  138. static void pluto_setscl(void *data, int state)
  139. {
  140. struct pluto *pluto = data;
  141. if (state)
  142. pluto_rw(pluto, REG_SLCS, SLCS_SCL, SLCS_SCL);
  143. else
  144. pluto_rw(pluto, REG_SLCS, SLCS_SCL, 0);
  145. /* try to detect i2c_inb() to workaround hardware bug:
  146. * reset SDA to high after SCL has been set to low */
  147. if ((state) && (pluto->i2cbug == 0)) {
  148. pluto->i2cbug = 1;
  149. } else {
  150. if ((!state) && (pluto->i2cbug == 1))
  151. pluto_setsda(pluto, 1);
  152. pluto->i2cbug = 0;
  153. }
  154. }
  155. static int pluto_getsda(void *data)
  156. {
  157. struct pluto *pluto = data;
  158. return pluto_readreg(pluto, REG_SLCS) & SLCS_SDA;
  159. }
  160. static int pluto_getscl(void *data)
  161. {
  162. struct pluto *pluto = data;
  163. return pluto_readreg(pluto, REG_SLCS) & SLCS_SCL;
  164. }
  165. static void pluto_reset_frontend(struct pluto *pluto, int reenable)
  166. {
  167. u32 val = pluto_readreg(pluto, REG_MISC);
  168. if (val & MISC_FRST) {
  169. val &= ~MISC_FRST;
  170. pluto_writereg(pluto, REG_MISC, val);
  171. }
  172. if (reenable) {
  173. val |= MISC_FRST;
  174. pluto_writereg(pluto, REG_MISC, val);
  175. }
  176. }
  177. static void pluto_reset_ts(struct pluto *pluto, int reenable)
  178. {
  179. u32 val = pluto_readreg(pluto, REG_TSCR);
  180. if (val & TSCR_RSTN) {
  181. val &= ~TSCR_RSTN;
  182. pluto_writereg(pluto, REG_TSCR, val);
  183. }
  184. if (reenable) {
  185. val |= TSCR_RSTN;
  186. pluto_writereg(pluto, REG_TSCR, val);
  187. }
  188. }
  189. static void pluto_set_dma_addr(struct pluto *pluto)
  190. {
  191. pluto_writereg(pluto, REG_PCAR, cpu_to_le32(pluto->dma_addr));
  192. }
  193. static int __devinit pluto_dma_map(struct pluto *pluto)
  194. {
  195. pluto->dma_addr = pci_map_single(pluto->pdev, pluto->dma_buf,
  196. TS_DMA_BYTES, PCI_DMA_FROMDEVICE);
  197. return pci_dma_mapping_error(pluto->dma_addr);
  198. }
  199. static void pluto_dma_unmap(struct pluto *pluto)
  200. {
  201. pci_unmap_single(pluto->pdev, pluto->dma_addr,
  202. TS_DMA_BYTES, PCI_DMA_FROMDEVICE);
  203. }
  204. static int pluto_start_feed(struct dvb_demux_feed *f)
  205. {
  206. struct pluto *pluto = feed_to_pluto(f);
  207. /* enable PID filtering */
  208. if (pluto->users++ == 0)
  209. pluto_rw(pluto, REG_PIDn(0), PID0_AFIL | PID0_NOFIL, 0);
  210. if ((f->pid < 0x2000) && (f->index < NHWFILTERS))
  211. pluto_rw(pluto, REG_PIDn(f->index), PIDn_ENP | PIDn_PID, PIDn_ENP | f->pid);
  212. else if (pluto->full_ts_users++ == 0)
  213. pluto_rw(pluto, REG_PIDn(0), PID0_NOFIL, PID0_NOFIL);
  214. return 0;
  215. }
  216. static int pluto_stop_feed(struct dvb_demux_feed *f)
  217. {
  218. struct pluto *pluto = feed_to_pluto(f);
  219. /* disable PID filtering */
  220. if (--pluto->users == 0)
  221. pluto_rw(pluto, REG_PIDn(0), PID0_AFIL, PID0_AFIL);
  222. if ((f->pid < 0x2000) && (f->index < NHWFILTERS))
  223. pluto_rw(pluto, REG_PIDn(f->index), PIDn_ENP | PIDn_PID, 0x1fff);
  224. else if (--pluto->full_ts_users == 0)
  225. pluto_rw(pluto, REG_PIDn(0), PID0_NOFIL, 0);
  226. return 0;
  227. }
  228. static void pluto_dma_end(struct pluto *pluto, unsigned int nbpackets)
  229. {
  230. /* synchronize the DMA transfer with the CPU
  231. * first so that we see updated contents. */
  232. pci_dma_sync_single_for_cpu(pluto->pdev, pluto->dma_addr,
  233. TS_DMA_BYTES, PCI_DMA_FROMDEVICE);
  234. /* Workaround for broken hardware:
  235. * [1] On startup NBPACKETS seems to contain an uninitialized value,
  236. * but no packets have been transfered.
  237. * [2] Sometimes (actually very often) NBPACKETS stays at zero
  238. * although one packet has been transfered.
  239. */
  240. if ((nbpackets == 0) || (nbpackets > TS_DMA_PACKETS)) {
  241. unsigned int i = 0, valid;
  242. while (pluto->dma_buf[i] == 0x47)
  243. i += 188;
  244. valid = i / 188;
  245. if (nbpackets != valid) {
  246. dev_err(&pluto->pdev->dev, "nbpackets=%u valid=%u\n",
  247. nbpackets, valid);
  248. nbpackets = valid;
  249. }
  250. }
  251. dvb_dmx_swfilter_packets(&pluto->demux, pluto->dma_buf, nbpackets);
  252. /* clear the dma buffer. this is needed to be able to identify
  253. * new valid ts packets above */
  254. memset(pluto->dma_buf, 0, nbpackets * 188);
  255. /* reset the dma address */
  256. pluto_set_dma_addr(pluto);
  257. /* sync the buffer and give it back to the card */
  258. pci_dma_sync_single_for_device(pluto->pdev, pluto->dma_addr,
  259. TS_DMA_BYTES, PCI_DMA_FROMDEVICE);
  260. }
  261. static irqreturn_t pluto_irq(int irq, void *dev_id, struct pt_regs *regs)
  262. {
  263. struct pluto *pluto = dev_id;
  264. u32 tscr;
  265. /* check whether an interrupt occured on this device */
  266. tscr = pluto_readreg(pluto, REG_TSCR);
  267. if (!(tscr & (TSCR_DE | TSCR_OVR)))
  268. return IRQ_NONE;
  269. if (tscr == 0xffffffff) {
  270. // FIXME: maybe recover somehow
  271. dev_err(&pluto->pdev->dev, "card hung up :(\n");
  272. return IRQ_HANDLED;
  273. }
  274. /* dma end interrupt */
  275. if (tscr & TSCR_DE) {
  276. pluto_dma_end(pluto, (tscr & TSCR_NBPACKETS) >> 24);
  277. /* overflow interrupt */
  278. if (tscr & TSCR_OVR)
  279. pluto->overflow++;
  280. if (pluto->overflow) {
  281. dev_err(&pluto->pdev->dev, "overflow irq (%d)\n",
  282. pluto->overflow);
  283. pluto_reset_ts(pluto, 1);
  284. pluto->overflow = 0;
  285. }
  286. } else if (tscr & TSCR_OVR) {
  287. pluto->overflow++;
  288. }
  289. /* ACK the interrupt */
  290. pluto_writereg(pluto, REG_TSCR, tscr | TSCR_IACK);
  291. return IRQ_HANDLED;
  292. }
  293. static void __devinit pluto_enable_irqs(struct pluto *pluto)
  294. {
  295. u32 val = pluto_readreg(pluto, REG_TSCR);
  296. /* set the number of packets */
  297. val &= ~TSCR_ADEF;
  298. val |= TS_DMA_PACKETS / 2;
  299. /* disable AFUL and LOCK interrupts */
  300. val |= (TSCR_MSKA | TSCR_MSKL);
  301. /* enable DMA and OVERFLOW interrupts */
  302. val &= ~(TSCR_DEM | TSCR_MSKO);
  303. /* clear pending interrupts */
  304. val |= TSCR_IACK;
  305. pluto_writereg(pluto, REG_TSCR, val);
  306. }
  307. static void pluto_disable_irqs(struct pluto *pluto)
  308. {
  309. u32 val = pluto_readreg(pluto, REG_TSCR);
  310. /* disable all interrupts */
  311. val |= (TSCR_DEM | TSCR_MSKO | TSCR_MSKA | TSCR_MSKL);
  312. /* clear pending interrupts */
  313. val |= TSCR_IACK;
  314. pluto_writereg(pluto, REG_TSCR, val);
  315. }
  316. static int __devinit pluto_hw_init(struct pluto *pluto)
  317. {
  318. pluto_reset_frontend(pluto, 1);
  319. /* set automatic LED control by FPGA */
  320. pluto_rw(pluto, REG_MISC, MISC_ALED, MISC_ALED);
  321. /* set data endianess */
  322. #ifdef __LITTLE_ENDIAN
  323. pluto_rw(pluto, REG_PIDn(0), PID0_END, PID0_END);
  324. #else
  325. pluto_rw(pluto, REG_PIDn(0), PID0_END, 0);
  326. #endif
  327. /* map DMA and set address */
  328. pluto_dma_map(pluto);
  329. pluto_set_dma_addr(pluto);
  330. /* enable interrupts */
  331. pluto_enable_irqs(pluto);
  332. /* reset TS logic */
  333. pluto_reset_ts(pluto, 1);
  334. return 0;
  335. }
  336. static void pluto_hw_exit(struct pluto *pluto)
  337. {
  338. /* disable interrupts */
  339. pluto_disable_irqs(pluto);
  340. pluto_reset_ts(pluto, 0);
  341. /* LED: disable automatic control, enable yellow, disable green */
  342. pluto_rw(pluto, REG_MISC, MISC_ALED | MISC_LED1 | MISC_LED0, MISC_LED1);
  343. /* unmap DMA */
  344. pluto_dma_unmap(pluto);
  345. pluto_reset_frontend(pluto, 0);
  346. }
  347. static inline u32 divide(u32 numerator, u32 denominator)
  348. {
  349. if (denominator == 0)
  350. return ~0;
  351. return (numerator + denominator / 2) / denominator;
  352. }
  353. /* LG Innotek TDTE-E001P (Infineon TUA6034) */
  354. static int lg_tdtpe001p_pll_set(struct dvb_frontend *fe,
  355. struct dvb_frontend_parameters *p)
  356. {
  357. struct pluto *pluto = frontend_to_pluto(fe);
  358. struct i2c_msg msg;
  359. int ret;
  360. u8 buf[4];
  361. u32 div;
  362. // Fref = 166.667 Hz
  363. // Fref * 3 = 500.000 Hz
  364. // IF = 36166667
  365. // IF / Fref = 217
  366. //div = divide(p->frequency + 36166667, 166667);
  367. div = divide(p->frequency * 3, 500000) + 217;
  368. buf[0] = (div >> 8) & 0x7f;
  369. buf[1] = (div >> 0) & 0xff;
  370. if (p->frequency < 611000000)
  371. buf[2] = 0xb4;
  372. else if (p->frequency < 811000000)
  373. buf[2] = 0xbc;
  374. else
  375. buf[2] = 0xf4;
  376. // VHF: 174-230 MHz
  377. // center: 350 MHz
  378. // UHF: 470-862 MHz
  379. if (p->frequency < 350000000)
  380. buf[3] = 0x02;
  381. else
  382. buf[3] = 0x04;
  383. if (p->u.ofdm.bandwidth == BANDWIDTH_8_MHZ)
  384. buf[3] |= 0x08;
  385. if (sizeof(buf) == 6) {
  386. buf[4] = buf[2];
  387. buf[4] &= ~0x1c;
  388. buf[4] |= 0x18;
  389. buf[5] = (0 << 7) | (2 << 4);
  390. }
  391. msg.addr = I2C_ADDR_TUA6034 >> 1;
  392. msg.flags = 0;
  393. msg.buf = buf;
  394. msg.len = sizeof(buf);
  395. ret = i2c_transfer(&pluto->i2c_adap, &msg, 1);
  396. if (ret < 0)
  397. return ret;
  398. else if (ret == 0)
  399. return -EREMOTEIO;
  400. return 0;
  401. }
  402. static int pluto2_request_firmware(struct dvb_frontend *fe,
  403. const struct firmware **fw, char *name)
  404. {
  405. struct pluto *pluto = frontend_to_pluto(fe);
  406. return request_firmware(fw, name, &pluto->pdev->dev);
  407. }
  408. static struct tda1004x_config pluto2_fe_config __devinitdata = {
  409. .demod_address = I2C_ADDR_TDA10046 >> 1,
  410. .invert = 1,
  411. .invert_oclk = 0,
  412. .xtal_freq = TDA10046_XTAL_16M,
  413. .agc_config = TDA10046_AGC_DEFAULT,
  414. .if_freq = TDA10046_FREQ_3617,
  415. .pll_set = lg_tdtpe001p_pll_set,
  416. .pll_sleep = NULL,
  417. .request_firmware = pluto2_request_firmware,
  418. };
  419. static int __devinit frontend_init(struct pluto *pluto)
  420. {
  421. int ret;
  422. pluto->fe = tda10046_attach(&pluto2_fe_config, &pluto->i2c_adap);
  423. if (!pluto->fe) {
  424. dev_err(&pluto->pdev->dev, "could not attach frontend\n");
  425. return -ENODEV;
  426. }
  427. ret = dvb_register_frontend(&pluto->dvb_adapter, pluto->fe);
  428. if (ret < 0) {
  429. if (pluto->fe->ops->release)
  430. pluto->fe->ops->release(pluto->fe);
  431. return ret;
  432. }
  433. return 0;
  434. }
  435. static void __devinit pluto_read_rev(struct pluto *pluto)
  436. {
  437. u32 val = pluto_readreg(pluto, REG_MISC) & MISC_DVR;
  438. dev_info(&pluto->pdev->dev, "board revision %d.%d\n",
  439. (val >> 12) & 0x0f, (val >> 4) & 0xff);
  440. }
  441. static void __devinit pluto_read_mac(struct pluto *pluto, u8 *mac)
  442. {
  443. u32 val = pluto_readreg(pluto, REG_MMAC);
  444. mac[0] = (val >> 8) & 0xff;
  445. mac[1] = (val >> 0) & 0xff;
  446. val = pluto_readreg(pluto, REG_IMAC);
  447. mac[2] = (val >> 8) & 0xff;
  448. mac[3] = (val >> 0) & 0xff;
  449. val = pluto_readreg(pluto, REG_LMAC);
  450. mac[4] = (val >> 8) & 0xff;
  451. mac[5] = (val >> 0) & 0xff;
  452. dev_info(&pluto->pdev->dev, "MAC %02x:%02x:%02x:%02x:%02x:%02x\n",
  453. mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
  454. }
  455. static int __devinit pluto_read_serial(struct pluto *pluto)
  456. {
  457. struct pci_dev *pdev = pluto->pdev;
  458. unsigned int i, j;
  459. u8 __iomem *cis;
  460. cis = pci_iomap(pdev, 1, 0);
  461. if (!cis)
  462. return -EIO;
  463. dev_info(&pdev->dev, "S/N ");
  464. for (i = 0xe0; i < 0x100; i += 4) {
  465. u32 val = readl(&cis[i]);
  466. for (j = 0; j < 32; j += 8) {
  467. if ((val & 0xff) == 0xff)
  468. goto out;
  469. printk("%c", val & 0xff);
  470. val >>= 8;
  471. }
  472. }
  473. out:
  474. printk("\n");
  475. pci_iounmap(pdev, cis);
  476. return 0;
  477. }
  478. static int __devinit pluto2_probe(struct pci_dev *pdev,
  479. const struct pci_device_id *ent)
  480. {
  481. struct pluto *pluto;
  482. struct dvb_adapter *dvb_adapter;
  483. struct dvb_demux *dvbdemux;
  484. struct dmx_demux *dmx;
  485. int ret = -ENOMEM;
  486. pluto = kmalloc(sizeof(struct pluto), GFP_KERNEL);
  487. if (!pluto)
  488. goto out;
  489. memset(pluto, 0, sizeof(struct pluto));
  490. pluto->pdev = pdev;
  491. ret = pci_enable_device(pdev);
  492. if (ret < 0)
  493. goto err_kfree;
  494. /* enable interrupts */
  495. pci_write_config_dword(pdev, 0x6c, 0x8000);
  496. ret = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
  497. if (ret < 0)
  498. goto err_pci_disable_device;
  499. pci_set_master(pdev);
  500. ret = pci_request_regions(pdev, DRIVER_NAME);
  501. if (ret < 0)
  502. goto err_pci_disable_device;
  503. pluto->io_mem = pci_iomap(pdev, 0, 0x40);
  504. if (!pluto->io_mem) {
  505. ret = -EIO;
  506. goto err_pci_release_regions;
  507. }
  508. pci_set_drvdata(pdev, pluto);
  509. ret = request_irq(pdev->irq, pluto_irq, SA_SHIRQ, DRIVER_NAME, pluto);
  510. if (ret < 0)
  511. goto err_pci_iounmap;
  512. ret = pluto_hw_init(pluto);
  513. if (ret < 0)
  514. goto err_free_irq;
  515. /* i2c */
  516. i2c_set_adapdata(&pluto->i2c_adap, pluto);
  517. strcpy(pluto->i2c_adap.name, DRIVER_NAME);
  518. pluto->i2c_adap.owner = THIS_MODULE;
  519. pluto->i2c_adap.class = I2C_CLASS_TV_DIGITAL;
  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, THIS_MODULE);
  537. if (ret < 0)
  538. goto err_i2c_bit_del_bus;
  539. dvb_adapter = &pluto->dvb_adapter;
  540. pluto_read_rev(pluto);
  541. pluto_read_serial(pluto);
  542. pluto_read_mac(pluto, dvb_adapter->proposed_mac);
  543. dvbdemux = &pluto->demux;
  544. dvbdemux->filternum = 256;
  545. dvbdemux->feednum = 256;
  546. dvbdemux->start_feed = pluto_start_feed;
  547. dvbdemux->stop_feed = pluto_stop_feed;
  548. dvbdemux->dmx.capabilities = (DMX_TS_FILTERING |
  549. DMX_SECTION_FILTERING | DMX_MEMORY_BASED_FILTERING);
  550. ret = dvb_dmx_init(dvbdemux);
  551. if (ret < 0)
  552. goto err_dvb_unregister_adapter;
  553. dmx = &dvbdemux->dmx;
  554. pluto->hw_frontend.source = DMX_FRONTEND_0;
  555. pluto->mem_frontend.source = DMX_MEMORY_FE;
  556. pluto->dmxdev.filternum = NHWFILTERS;
  557. pluto->dmxdev.demux = dmx;
  558. ret = dvb_dmxdev_init(&pluto->dmxdev, dvb_adapter);
  559. if (ret < 0)
  560. goto err_dvb_dmx_release;
  561. ret = dmx->add_frontend(dmx, &pluto->hw_frontend);
  562. if (ret < 0)
  563. goto err_dvb_dmxdev_release;
  564. ret = dmx->add_frontend(dmx, &pluto->mem_frontend);
  565. if (ret < 0)
  566. goto err_remove_hw_frontend;
  567. ret = dmx->connect_frontend(dmx, &pluto->hw_frontend);
  568. if (ret < 0)
  569. goto err_remove_mem_frontend;
  570. ret = frontend_init(pluto);
  571. if (ret < 0)
  572. goto err_disconnect_frontend;
  573. dvb_net_init(dvb_adapter, &pluto->dvbnet, dmx);
  574. out:
  575. return ret;
  576. err_disconnect_frontend:
  577. dmx->disconnect_frontend(dmx);
  578. err_remove_mem_frontend:
  579. dmx->remove_frontend(dmx, &pluto->mem_frontend);
  580. err_remove_hw_frontend:
  581. dmx->remove_frontend(dmx, &pluto->hw_frontend);
  582. err_dvb_dmxdev_release:
  583. dvb_dmxdev_release(&pluto->dmxdev);
  584. err_dvb_dmx_release:
  585. dvb_dmx_release(dvbdemux);
  586. err_dvb_unregister_adapter:
  587. dvb_unregister_adapter(dvb_adapter);
  588. err_i2c_bit_del_bus:
  589. i2c_bit_del_bus(&pluto->i2c_adap);
  590. err_pluto_hw_exit:
  591. pluto_hw_exit(pluto);
  592. err_free_irq:
  593. free_irq(pdev->irq, pluto);
  594. err_pci_iounmap:
  595. pci_iounmap(pdev, pluto->io_mem);
  596. err_pci_release_regions:
  597. pci_release_regions(pdev);
  598. err_pci_disable_device:
  599. pci_disable_device(pdev);
  600. err_kfree:
  601. pci_set_drvdata(pdev, NULL);
  602. kfree(pluto);
  603. goto out;
  604. }
  605. static void __devexit 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_bit_del_bus(&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. pci_set_drvdata(pdev, NULL);
  628. kfree(pluto);
  629. }
  630. #ifndef PCI_VENDOR_ID_SCM
  631. #define PCI_VENDOR_ID_SCM 0x0432
  632. #endif
  633. #ifndef PCI_DEVICE_ID_PLUTO2
  634. #define PCI_DEVICE_ID_PLUTO2 0x0001
  635. #endif
  636. static struct pci_device_id pluto2_id_table[] __devinitdata = {
  637. {
  638. .vendor = PCI_VENDOR_ID_SCM,
  639. .device = PCI_DEVICE_ID_PLUTO2,
  640. .subvendor = PCI_ANY_ID,
  641. .subdevice = PCI_ANY_ID,
  642. }, {
  643. /* empty */
  644. },
  645. };
  646. MODULE_DEVICE_TABLE(pci, pluto2_id_table);
  647. static struct pci_driver pluto2_driver = {
  648. .name = DRIVER_NAME,
  649. .id_table = pluto2_id_table,
  650. .probe = pluto2_probe,
  651. .remove = __devexit_p(pluto2_remove),
  652. };
  653. static int __init pluto2_init(void)
  654. {
  655. return pci_register_driver(&pluto2_driver);
  656. }
  657. static void __exit pluto2_exit(void)
  658. {
  659. pci_unregister_driver(&pluto2_driver);
  660. }
  661. module_init(pluto2_init);
  662. module_exit(pluto2_exit);
  663. MODULE_AUTHOR("Andreas Oberritter <obi@linuxtv.org>");
  664. MODULE_DESCRIPTION("Pluto2 driver");
  665. MODULE_LICENSE("GPL");