em28xx-core.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237
  1. /*
  2. em28xx-core.c - driver for Empia EM2800/EM2820/2840 USB video capture devices
  3. Copyright (C) 2005 Ludovico Cavedon <cavedon@sssup.it>
  4. Markus Rechberger <mrechberger@gmail.com>
  5. Mauro Carvalho Chehab <mchehab@infradead.org>
  6. Sascha Sommer <saschasommer@freenet.de>
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  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. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19. #include <linux/init.h>
  20. #include <linux/list.h>
  21. #include <linux/module.h>
  22. #include <linux/slab.h>
  23. #include <linux/usb.h>
  24. #include <linux/vmalloc.h>
  25. #include <media/v4l2-common.h>
  26. #include "em28xx.h"
  27. /* #define ENABLE_DEBUG_ISOC_FRAMES */
  28. static unsigned int core_debug;
  29. module_param(core_debug, int, 0644);
  30. MODULE_PARM_DESC(core_debug, "enable debug messages [core]");
  31. #define em28xx_coredbg(fmt, arg...) do {\
  32. if (core_debug) \
  33. printk(KERN_INFO "%s %s :"fmt, \
  34. dev->name, __func__ , ##arg); } while (0)
  35. static unsigned int reg_debug;
  36. module_param(reg_debug, int, 0644);
  37. MODULE_PARM_DESC(reg_debug, "enable debug messages [URB reg]");
  38. #define em28xx_regdbg(fmt, arg...) do {\
  39. if (reg_debug) \
  40. printk(KERN_INFO "%s %s :"fmt, \
  41. dev->name, __func__ , ##arg); } while (0)
  42. static int alt;
  43. module_param(alt, int, 0644);
  44. MODULE_PARM_DESC(alt, "alternate setting to use for video endpoint");
  45. static unsigned int disable_vbi;
  46. module_param(disable_vbi, int, 0644);
  47. MODULE_PARM_DESC(disable_vbi, "disable vbi support");
  48. /* FIXME */
  49. #define em28xx_isocdbg(fmt, arg...) do {\
  50. if (core_debug) \
  51. printk(KERN_INFO "%s %s :"fmt, \
  52. dev->name, __func__ , ##arg); } while (0)
  53. /*
  54. * em28xx_read_reg_req()
  55. * reads data from the usb device specifying bRequest
  56. */
  57. int em28xx_read_reg_req_len(struct em28xx *dev, u8 req, u16 reg,
  58. char *buf, int len)
  59. {
  60. int ret;
  61. int pipe = usb_rcvctrlpipe(dev->udev, 0);
  62. if (dev->state & DEV_DISCONNECTED)
  63. return -ENODEV;
  64. if (len > URB_MAX_CTRL_SIZE)
  65. return -EINVAL;
  66. if (reg_debug) {
  67. printk(KERN_DEBUG "(pipe 0x%08x): "
  68. "IN: %02x %02x %02x %02x %02x %02x %02x %02x ",
  69. pipe,
  70. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  71. req, 0, 0,
  72. reg & 0xff, reg >> 8,
  73. len & 0xff, len >> 8);
  74. }
  75. mutex_lock(&dev->ctrl_urb_lock);
  76. ret = usb_control_msg(dev->udev, pipe, req,
  77. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  78. 0x0000, reg, dev->urb_buf, len, HZ);
  79. if (ret < 0) {
  80. if (reg_debug)
  81. printk(" failed!\n");
  82. mutex_unlock(&dev->ctrl_urb_lock);
  83. return ret;
  84. }
  85. if (len)
  86. memcpy(buf, dev->urb_buf, len);
  87. mutex_unlock(&dev->ctrl_urb_lock);
  88. if (reg_debug) {
  89. int byte;
  90. printk("<<<");
  91. for (byte = 0; byte < len; byte++)
  92. printk(" %02x", (unsigned char)buf[byte]);
  93. printk("\n");
  94. }
  95. return ret;
  96. }
  97. /*
  98. * em28xx_read_reg_req()
  99. * reads data from the usb device specifying bRequest
  100. */
  101. int em28xx_read_reg_req(struct em28xx *dev, u8 req, u16 reg)
  102. {
  103. int ret;
  104. u8 val;
  105. ret = em28xx_read_reg_req_len(dev, req, reg, &val, 1);
  106. if (ret < 0)
  107. return ret;
  108. return val;
  109. }
  110. int em28xx_read_reg(struct em28xx *dev, u16 reg)
  111. {
  112. return em28xx_read_reg_req(dev, USB_REQ_GET_STATUS, reg);
  113. }
  114. /*
  115. * em28xx_write_regs_req()
  116. * sends data to the usb device, specifying bRequest
  117. */
  118. int em28xx_write_regs_req(struct em28xx *dev, u8 req, u16 reg, char *buf,
  119. int len)
  120. {
  121. int ret;
  122. int pipe = usb_sndctrlpipe(dev->udev, 0);
  123. if (dev->state & DEV_DISCONNECTED)
  124. return -ENODEV;
  125. if ((len < 1) || (len > URB_MAX_CTRL_SIZE))
  126. return -EINVAL;
  127. if (reg_debug) {
  128. int byte;
  129. printk(KERN_DEBUG "(pipe 0x%08x): "
  130. "OUT: %02x %02x %02x %02x %02x %02x %02x %02x >>>",
  131. pipe,
  132. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  133. req, 0, 0,
  134. reg & 0xff, reg >> 8,
  135. len & 0xff, len >> 8);
  136. for (byte = 0; byte < len; byte++)
  137. printk(" %02x", (unsigned char)buf[byte]);
  138. printk("\n");
  139. }
  140. mutex_lock(&dev->ctrl_urb_lock);
  141. memcpy(dev->urb_buf, buf, len);
  142. ret = usb_control_msg(dev->udev, pipe, req,
  143. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  144. 0x0000, reg, dev->urb_buf, len, HZ);
  145. mutex_unlock(&dev->ctrl_urb_lock);
  146. if (dev->wait_after_write)
  147. msleep(dev->wait_after_write);
  148. return ret;
  149. }
  150. int em28xx_write_regs(struct em28xx *dev, u16 reg, char *buf, int len)
  151. {
  152. int rc;
  153. rc = em28xx_write_regs_req(dev, USB_REQ_GET_STATUS, reg, buf, len);
  154. /* Stores GPO/GPIO values at the cache, if changed
  155. Only write values should be stored, since input on a GPIO
  156. register will return the input bits.
  157. Not sure what happens on reading GPO register.
  158. */
  159. if (rc >= 0) {
  160. if (reg == dev->reg_gpo_num)
  161. dev->reg_gpo = buf[0];
  162. else if (reg == dev->reg_gpio_num)
  163. dev->reg_gpio = buf[0];
  164. }
  165. return rc;
  166. }
  167. /* Write a single register */
  168. int em28xx_write_reg(struct em28xx *dev, u16 reg, u8 val)
  169. {
  170. return em28xx_write_regs(dev, reg, &val, 1);
  171. }
  172. /*
  173. * em28xx_write_reg_bits()
  174. * sets only some bits (specified by bitmask) of a register, by first reading
  175. * the actual value
  176. */
  177. int em28xx_write_reg_bits(struct em28xx *dev, u16 reg, u8 val,
  178. u8 bitmask)
  179. {
  180. int oldval;
  181. u8 newval;
  182. /* Uses cache for gpo/gpio registers */
  183. if (reg == dev->reg_gpo_num)
  184. oldval = dev->reg_gpo;
  185. else if (reg == dev->reg_gpio_num)
  186. oldval = dev->reg_gpio;
  187. else
  188. oldval = em28xx_read_reg(dev, reg);
  189. if (oldval < 0)
  190. return oldval;
  191. newval = (((u8) oldval) & ~bitmask) | (val & bitmask);
  192. return em28xx_write_regs(dev, reg, &newval, 1);
  193. }
  194. /*
  195. * em28xx_is_ac97_ready()
  196. * Checks if ac97 is ready
  197. */
  198. static int em28xx_is_ac97_ready(struct em28xx *dev)
  199. {
  200. int ret, i;
  201. /* Wait up to 50 ms for AC97 command to complete */
  202. for (i = 0; i < 10; i++, msleep(5)) {
  203. ret = em28xx_read_reg(dev, EM28XX_R43_AC97BUSY);
  204. if (ret < 0)
  205. return ret;
  206. if (!(ret & 0x01))
  207. return 0;
  208. }
  209. em28xx_warn("AC97 command still being executed: not handled properly!\n");
  210. return -EBUSY;
  211. }
  212. /*
  213. * em28xx_read_ac97()
  214. * write a 16 bit value to the specified AC97 address (LSB first!)
  215. */
  216. int em28xx_read_ac97(struct em28xx *dev, u8 reg)
  217. {
  218. int ret;
  219. u8 addr = (reg & 0x7f) | 0x80;
  220. u16 val;
  221. ret = em28xx_is_ac97_ready(dev);
  222. if (ret < 0)
  223. return ret;
  224. ret = em28xx_write_regs(dev, EM28XX_R42_AC97ADDR, &addr, 1);
  225. if (ret < 0)
  226. return ret;
  227. ret = dev->em28xx_read_reg_req_len(dev, 0, EM28XX_R40_AC97LSB,
  228. (u8 *)&val, sizeof(val));
  229. if (ret < 0)
  230. return ret;
  231. return le16_to_cpu(val);
  232. }
  233. /*
  234. * em28xx_write_ac97()
  235. * write a 16 bit value to the specified AC97 address (LSB first!)
  236. */
  237. int em28xx_write_ac97(struct em28xx *dev, u8 reg, u16 val)
  238. {
  239. int ret;
  240. u8 addr = reg & 0x7f;
  241. __le16 value;
  242. value = cpu_to_le16(val);
  243. ret = em28xx_is_ac97_ready(dev);
  244. if (ret < 0)
  245. return ret;
  246. ret = em28xx_write_regs(dev, EM28XX_R40_AC97LSB, (u8 *) &value, 2);
  247. if (ret < 0)
  248. return ret;
  249. ret = em28xx_write_regs(dev, EM28XX_R42_AC97ADDR, &addr, 1);
  250. if (ret < 0)
  251. return ret;
  252. return 0;
  253. }
  254. struct em28xx_vol_table {
  255. enum em28xx_amux mux;
  256. u8 reg;
  257. };
  258. static struct em28xx_vol_table inputs[] = {
  259. { EM28XX_AMUX_VIDEO, AC97_VIDEO_VOL },
  260. { EM28XX_AMUX_LINE_IN, AC97_LINEIN_VOL },
  261. { EM28XX_AMUX_PHONE, AC97_PHONE_VOL },
  262. { EM28XX_AMUX_MIC, AC97_MIC_VOL },
  263. { EM28XX_AMUX_CD, AC97_CD_VOL },
  264. { EM28XX_AMUX_AUX, AC97_AUX_VOL },
  265. { EM28XX_AMUX_PCM_OUT, AC97_PCM_OUT_VOL },
  266. };
  267. static int set_ac97_input(struct em28xx *dev)
  268. {
  269. int ret, i;
  270. enum em28xx_amux amux = dev->ctl_ainput;
  271. /* EM28XX_AMUX_VIDEO2 is a special case used to indicate that
  272. em28xx should point to LINE IN, while AC97 should use VIDEO
  273. */
  274. if (amux == EM28XX_AMUX_VIDEO2)
  275. amux = EM28XX_AMUX_VIDEO;
  276. /* Mute all entres but the one that were selected */
  277. for (i = 0; i < ARRAY_SIZE(inputs); i++) {
  278. if (amux == inputs[i].mux)
  279. ret = em28xx_write_ac97(dev, inputs[i].reg, 0x0808);
  280. else
  281. ret = em28xx_write_ac97(dev, inputs[i].reg, 0x8000);
  282. if (ret < 0)
  283. em28xx_warn("couldn't setup AC97 register %d\n",
  284. inputs[i].reg);
  285. }
  286. return 0;
  287. }
  288. static int em28xx_set_audio_source(struct em28xx *dev)
  289. {
  290. int ret;
  291. u8 input;
  292. if (dev->board.is_em2800) {
  293. if (dev->ctl_ainput == EM28XX_AMUX_VIDEO)
  294. input = EM2800_AUDIO_SRC_TUNER;
  295. else
  296. input = EM2800_AUDIO_SRC_LINE;
  297. ret = em28xx_write_regs(dev, EM2800_R08_AUDIOSRC, &input, 1);
  298. if (ret < 0)
  299. return ret;
  300. }
  301. if (dev->board.has_msp34xx)
  302. input = EM28XX_AUDIO_SRC_TUNER;
  303. else {
  304. switch (dev->ctl_ainput) {
  305. case EM28XX_AMUX_VIDEO:
  306. input = EM28XX_AUDIO_SRC_TUNER;
  307. break;
  308. default:
  309. input = EM28XX_AUDIO_SRC_LINE;
  310. break;
  311. }
  312. }
  313. if (dev->board.mute_gpio && dev->mute)
  314. em28xx_gpio_set(dev, dev->board.mute_gpio);
  315. else
  316. em28xx_gpio_set(dev, INPUT(dev->ctl_input)->gpio);
  317. ret = em28xx_write_reg_bits(dev, EM28XX_R0E_AUDIOSRC, input, 0xc0);
  318. if (ret < 0)
  319. return ret;
  320. msleep(5);
  321. switch (dev->audio_mode.ac97) {
  322. case EM28XX_NO_AC97:
  323. break;
  324. default:
  325. ret = set_ac97_input(dev);
  326. }
  327. return ret;
  328. }
  329. static const struct em28xx_vol_table outputs[] = {
  330. { EM28XX_AOUT_MASTER, AC97_MASTER_VOL },
  331. { EM28XX_AOUT_LINE, AC97_LINE_LEVEL_VOL },
  332. { EM28XX_AOUT_MONO, AC97_MASTER_MONO_VOL },
  333. { EM28XX_AOUT_LFE, AC97_LFE_MASTER_VOL },
  334. { EM28XX_AOUT_SURR, AC97_SURR_MASTER_VOL },
  335. };
  336. int em28xx_audio_analog_set(struct em28xx *dev)
  337. {
  338. int ret, i;
  339. u8 xclk;
  340. if (!dev->audio_mode.has_audio)
  341. return 0;
  342. /* It is assumed that all devices use master volume for output.
  343. It would be possible to use also line output.
  344. */
  345. if (dev->audio_mode.ac97 != EM28XX_NO_AC97) {
  346. /* Mute all outputs */
  347. for (i = 0; i < ARRAY_SIZE(outputs); i++) {
  348. ret = em28xx_write_ac97(dev, outputs[i].reg, 0x8000);
  349. if (ret < 0)
  350. em28xx_warn("couldn't setup AC97 register %d\n",
  351. outputs[i].reg);
  352. }
  353. }
  354. xclk = dev->board.xclk & 0x7f;
  355. if (!dev->mute)
  356. xclk |= EM28XX_XCLK_AUDIO_UNMUTE;
  357. ret = em28xx_write_reg(dev, EM28XX_R0F_XCLK, xclk);
  358. if (ret < 0)
  359. return ret;
  360. msleep(10);
  361. /* Selects the proper audio input */
  362. ret = em28xx_set_audio_source(dev);
  363. /* Sets volume */
  364. if (dev->audio_mode.ac97 != EM28XX_NO_AC97) {
  365. int vol;
  366. em28xx_write_ac97(dev, AC97_POWER_DOWN_CTRL, 0x4200);
  367. em28xx_write_ac97(dev, AC97_EXT_AUD_CTRL, 0x0031);
  368. em28xx_write_ac97(dev, AC97_PCM_IN_SRATE, 0xbb80);
  369. /* LSB: left channel - both channels with the same level */
  370. vol = (0x1f - dev->volume) | ((0x1f - dev->volume) << 8);
  371. /* Mute device, if needed */
  372. if (dev->mute)
  373. vol |= 0x8000;
  374. /* Sets volume */
  375. for (i = 0; i < ARRAY_SIZE(outputs); i++) {
  376. if (dev->ctl_aoutput & outputs[i].mux)
  377. ret = em28xx_write_ac97(dev, outputs[i].reg,
  378. vol);
  379. if (ret < 0)
  380. em28xx_warn("couldn't setup AC97 register %d\n",
  381. outputs[i].reg);
  382. }
  383. if (dev->ctl_aoutput & EM28XX_AOUT_PCM_IN) {
  384. int sel = ac97_return_record_select(dev->ctl_aoutput);
  385. /* Use the same input for both left and right
  386. channels */
  387. sel |= (sel << 8);
  388. em28xx_write_ac97(dev, AC97_RECORD_SELECT, sel);
  389. }
  390. }
  391. return ret;
  392. }
  393. EXPORT_SYMBOL_GPL(em28xx_audio_analog_set);
  394. int em28xx_audio_setup(struct em28xx *dev)
  395. {
  396. int vid1, vid2, feat, cfg;
  397. u32 vid;
  398. if (dev->chip_id == CHIP_ID_EM2870 || dev->chip_id == CHIP_ID_EM2874) {
  399. /* Digital only device - don't load any alsa module */
  400. dev->audio_mode.has_audio = 0;
  401. dev->has_audio_class = 0;
  402. dev->has_alsa_audio = 0;
  403. return 0;
  404. }
  405. /* If device doesn't support Usb Audio Class, use vendor class */
  406. if (!dev->has_audio_class)
  407. dev->has_alsa_audio = 1;
  408. dev->audio_mode.has_audio = 1;
  409. /* See how this device is configured */
  410. cfg = em28xx_read_reg(dev, EM28XX_R00_CHIPCFG);
  411. em28xx_info("Config register raw data: 0x%02x\n", cfg);
  412. if (cfg < 0) {
  413. /* Register read error? */
  414. cfg = EM28XX_CHIPCFG_AC97; /* Be conservative */
  415. } else if ((cfg & EM28XX_CHIPCFG_AUDIOMASK) == 0x00) {
  416. /* The device doesn't have vendor audio at all */
  417. dev->has_alsa_audio = 0;
  418. dev->audio_mode.has_audio = 0;
  419. return 0;
  420. } else if ((cfg & EM28XX_CHIPCFG_AUDIOMASK) ==
  421. EM28XX_CHIPCFG_I2S_3_SAMPRATES) {
  422. em28xx_info("I2S Audio (3 sample rates)\n");
  423. dev->audio_mode.i2s_3rates = 1;
  424. } else if ((cfg & EM28XX_CHIPCFG_AUDIOMASK) ==
  425. EM28XX_CHIPCFG_I2S_5_SAMPRATES) {
  426. em28xx_info("I2S Audio (5 sample rates)\n");
  427. dev->audio_mode.i2s_5rates = 1;
  428. }
  429. if ((cfg & EM28XX_CHIPCFG_AUDIOMASK) != EM28XX_CHIPCFG_AC97) {
  430. /* Skip the code that does AC97 vendor detection */
  431. dev->audio_mode.ac97 = EM28XX_NO_AC97;
  432. goto init_audio;
  433. }
  434. dev->audio_mode.ac97 = EM28XX_AC97_OTHER;
  435. vid1 = em28xx_read_ac97(dev, AC97_VENDOR_ID1);
  436. if (vid1 < 0) {
  437. /*
  438. * Device likely doesn't support AC97
  439. * Note: (some) em2800 devices without eeprom reports 0x91 on
  440. * CHIPCFG register, even not having an AC97 chip
  441. */
  442. em28xx_warn("AC97 chip type couldn't be determined\n");
  443. dev->audio_mode.ac97 = EM28XX_NO_AC97;
  444. dev->has_alsa_audio = 0;
  445. dev->audio_mode.has_audio = 0;
  446. goto init_audio;
  447. }
  448. vid2 = em28xx_read_ac97(dev, AC97_VENDOR_ID2);
  449. if (vid2 < 0)
  450. goto init_audio;
  451. vid = vid1 << 16 | vid2;
  452. dev->audio_mode.ac97_vendor_id = vid;
  453. em28xx_warn("AC97 vendor ID = 0x%08x\n", vid);
  454. feat = em28xx_read_ac97(dev, AC97_RESET);
  455. if (feat < 0)
  456. goto init_audio;
  457. dev->audio_mode.ac97_feat = feat;
  458. em28xx_warn("AC97 features = 0x%04x\n", feat);
  459. /* Try to identify what audio processor we have */
  460. if ((vid == 0xffffffff) && (feat == 0x6a90))
  461. dev->audio_mode.ac97 = EM28XX_AC97_EM202;
  462. else if ((vid >> 8) == 0x838476)
  463. dev->audio_mode.ac97 = EM28XX_AC97_SIGMATEL;
  464. init_audio:
  465. /* Reports detected AC97 processor */
  466. switch (dev->audio_mode.ac97) {
  467. case EM28XX_NO_AC97:
  468. em28xx_info("No AC97 audio processor\n");
  469. break;
  470. case EM28XX_AC97_EM202:
  471. em28xx_info("Empia 202 AC97 audio processor detected\n");
  472. break;
  473. case EM28XX_AC97_SIGMATEL:
  474. em28xx_info("Sigmatel audio processor detected(stac 97%02x)\n",
  475. dev->audio_mode.ac97_vendor_id & 0xff);
  476. break;
  477. case EM28XX_AC97_OTHER:
  478. em28xx_warn("Unknown AC97 audio processor detected!\n");
  479. break;
  480. default:
  481. break;
  482. }
  483. return em28xx_audio_analog_set(dev);
  484. }
  485. EXPORT_SYMBOL_GPL(em28xx_audio_setup);
  486. int em28xx_colorlevels_set_default(struct em28xx *dev)
  487. {
  488. em28xx_write_reg(dev, EM28XX_R20_YGAIN, 0x10); /* contrast */
  489. em28xx_write_reg(dev, EM28XX_R21_YOFFSET, 0x00); /* brightness */
  490. em28xx_write_reg(dev, EM28XX_R22_UVGAIN, 0x10); /* saturation */
  491. em28xx_write_reg(dev, EM28XX_R23_UOFFSET, 0x00);
  492. em28xx_write_reg(dev, EM28XX_R24_VOFFSET, 0x00);
  493. em28xx_write_reg(dev, EM28XX_R25_SHARPNESS, 0x00);
  494. em28xx_write_reg(dev, EM28XX_R14_GAMMA, 0x20);
  495. em28xx_write_reg(dev, EM28XX_R15_RGAIN, 0x20);
  496. em28xx_write_reg(dev, EM28XX_R16_GGAIN, 0x20);
  497. em28xx_write_reg(dev, EM28XX_R17_BGAIN, 0x20);
  498. em28xx_write_reg(dev, EM28XX_R18_ROFFSET, 0x00);
  499. em28xx_write_reg(dev, EM28XX_R19_GOFFSET, 0x00);
  500. return em28xx_write_reg(dev, EM28XX_R1A_BOFFSET, 0x00);
  501. }
  502. int em28xx_capture_start(struct em28xx *dev, int start)
  503. {
  504. int rc;
  505. if (dev->chip_id == CHIP_ID_EM2874) {
  506. /* The Transport Stream Enable Register moved in em2874 */
  507. if (!start) {
  508. rc = em28xx_write_reg_bits(dev, EM2874_R5F_TS_ENABLE,
  509. 0x00,
  510. EM2874_TS1_CAPTURE_ENABLE);
  511. return rc;
  512. }
  513. /* Enable Transport Stream */
  514. rc = em28xx_write_reg_bits(dev, EM2874_R5F_TS_ENABLE,
  515. EM2874_TS1_CAPTURE_ENABLE,
  516. EM2874_TS1_CAPTURE_ENABLE);
  517. return rc;
  518. }
  519. /* FIXME: which is the best order? */
  520. /* video registers are sampled by VREF */
  521. rc = em28xx_write_reg_bits(dev, EM28XX_R0C_USBSUSP,
  522. start ? 0x10 : 0x00, 0x10);
  523. if (rc < 0)
  524. return rc;
  525. if (!start) {
  526. /* disable video capture */
  527. rc = em28xx_write_reg(dev, EM28XX_R12_VINENABLE, 0x27);
  528. return rc;
  529. }
  530. if (dev->board.is_webcam)
  531. rc = em28xx_write_reg(dev, 0x13, 0x0c);
  532. /* enable video capture */
  533. rc = em28xx_write_reg(dev, 0x48, 0x00);
  534. if (dev->mode == EM28XX_ANALOG_MODE)
  535. rc = em28xx_write_reg(dev, EM28XX_R12_VINENABLE, 0x67);
  536. else
  537. rc = em28xx_write_reg(dev, EM28XX_R12_VINENABLE, 0x37);
  538. msleep(6);
  539. return rc;
  540. }
  541. int em28xx_vbi_supported(struct em28xx *dev)
  542. {
  543. /* Modprobe option to manually disable */
  544. if (disable_vbi == 1)
  545. return 0;
  546. if (dev->chip_id == CHIP_ID_EM2860 ||
  547. dev->chip_id == CHIP_ID_EM2883)
  548. return 1;
  549. /* Version of em28xx that does not support VBI */
  550. return 0;
  551. }
  552. int em28xx_set_outfmt(struct em28xx *dev)
  553. {
  554. int ret;
  555. u8 vinctrl;
  556. ret = em28xx_write_reg_bits(dev, EM28XX_R27_OUTFMT,
  557. dev->format->reg | 0x20, 0xff);
  558. if (ret < 0)
  559. return ret;
  560. ret = em28xx_write_reg(dev, EM28XX_R10_VINMODE, dev->vinmode);
  561. if (ret < 0)
  562. return ret;
  563. vinctrl = dev->vinctl;
  564. if (em28xx_vbi_supported(dev) == 1) {
  565. vinctrl |= EM28XX_VINCTRL_VBI_RAW;
  566. em28xx_write_reg(dev, EM28XX_R34_VBI_START_H, 0x00);
  567. em28xx_write_reg(dev, EM28XX_R36_VBI_WIDTH, dev->vbi_width/4);
  568. em28xx_write_reg(dev, EM28XX_R37_VBI_HEIGHT, dev->vbi_height);
  569. if (dev->norm & V4L2_STD_525_60) {
  570. /* NTSC */
  571. em28xx_write_reg(dev, EM28XX_R35_VBI_START_V, 0x09);
  572. } else if (dev->norm & V4L2_STD_625_50) {
  573. /* PAL */
  574. em28xx_write_reg(dev, EM28XX_R35_VBI_START_V, 0x07);
  575. }
  576. }
  577. return em28xx_write_reg(dev, EM28XX_R11_VINCTRL, vinctrl);
  578. }
  579. static int em28xx_accumulator_set(struct em28xx *dev, u8 xmin, u8 xmax,
  580. u8 ymin, u8 ymax)
  581. {
  582. em28xx_coredbg("em28xx Scale: (%d,%d)-(%d,%d)\n",
  583. xmin, ymin, xmax, ymax);
  584. em28xx_write_regs(dev, EM28XX_R28_XMIN, &xmin, 1);
  585. em28xx_write_regs(dev, EM28XX_R29_XMAX, &xmax, 1);
  586. em28xx_write_regs(dev, EM28XX_R2A_YMIN, &ymin, 1);
  587. return em28xx_write_regs(dev, EM28XX_R2B_YMAX, &ymax, 1);
  588. }
  589. static int em28xx_capture_area_set(struct em28xx *dev, u8 hstart, u8 vstart,
  590. u16 width, u16 height)
  591. {
  592. u8 cwidth = width;
  593. u8 cheight = height;
  594. u8 overflow = (height >> 7 & 0x02) | (width >> 8 & 0x01);
  595. em28xx_coredbg("em28xx Area Set: (%d,%d)\n",
  596. (width | (overflow & 2) << 7),
  597. (height | (overflow & 1) << 8));
  598. em28xx_write_regs(dev, EM28XX_R1C_HSTART, &hstart, 1);
  599. em28xx_write_regs(dev, EM28XX_R1D_VSTART, &vstart, 1);
  600. em28xx_write_regs(dev, EM28XX_R1E_CWIDTH, &cwidth, 1);
  601. em28xx_write_regs(dev, EM28XX_R1F_CHEIGHT, &cheight, 1);
  602. return em28xx_write_regs(dev, EM28XX_R1B_OFLOW, &overflow, 1);
  603. }
  604. static int em28xx_scaler_set(struct em28xx *dev, u16 h, u16 v)
  605. {
  606. u8 mode;
  607. /* the em2800 scaler only supports scaling down to 50% */
  608. if (dev->board.is_em2800) {
  609. mode = (v ? 0x20 : 0x00) | (h ? 0x10 : 0x00);
  610. } else {
  611. u8 buf[2];
  612. buf[0] = h;
  613. buf[1] = h >> 8;
  614. em28xx_write_regs(dev, EM28XX_R30_HSCALELOW, (char *)buf, 2);
  615. buf[0] = v;
  616. buf[1] = v >> 8;
  617. em28xx_write_regs(dev, EM28XX_R32_VSCALELOW, (char *)buf, 2);
  618. /* it seems that both H and V scalers must be active
  619. to work correctly */
  620. mode = (h || v) ? 0x30 : 0x00;
  621. }
  622. return em28xx_write_reg_bits(dev, EM28XX_R26_COMPR, mode, 0x30);
  623. }
  624. /* FIXME: this only function read values from dev */
  625. int em28xx_resolution_set(struct em28xx *dev)
  626. {
  627. int width, height;
  628. width = norm_maxw(dev);
  629. height = norm_maxh(dev);
  630. /* Properly setup VBI */
  631. dev->vbi_width = 720;
  632. if (dev->norm & V4L2_STD_525_60)
  633. dev->vbi_height = 12;
  634. else
  635. dev->vbi_height = 18;
  636. if (!dev->progressive)
  637. height >>= norm_maxh(dev);
  638. em28xx_set_outfmt(dev);
  639. em28xx_accumulator_set(dev, 1, (width - 4) >> 2, 1, (height - 4) >> 2);
  640. /* If we don't set the start position to 2 in VBI mode, we end up
  641. with line 20/21 being YUYV encoded instead of being in 8-bit
  642. greyscale. The core of the issue is that line 21 (and line 23 for
  643. PAL WSS) are inside of active video region, and as a result they
  644. get the pixelformatting associated with that area. So by cropping
  645. it out, we end up with the same format as the rest of the VBI
  646. region */
  647. if (em28xx_vbi_supported(dev) == 1)
  648. em28xx_capture_area_set(dev, 0, 2, width >> 2, height >> 2);
  649. else
  650. em28xx_capture_area_set(dev, 0, 0, width >> 2, height >> 2);
  651. return em28xx_scaler_set(dev, dev->hscale, dev->vscale);
  652. }
  653. int em28xx_set_alternate(struct em28xx *dev)
  654. {
  655. int errCode, prev_alt = dev->alt;
  656. int i;
  657. unsigned int min_pkt_size = dev->width * 2 + 4;
  658. /*
  659. * alt = 0 is used only for control messages, so, only values
  660. * greater than 0 can be used for streaming.
  661. */
  662. if (alt && alt < dev->num_alt) {
  663. em28xx_coredbg("alternate forced to %d\n", dev->alt);
  664. dev->alt = alt;
  665. goto set_alt;
  666. }
  667. /* When image size is bigger than a certain value,
  668. the frame size should be increased, otherwise, only
  669. green screen will be received.
  670. */
  671. if (dev->width * 2 * dev->height > 720 * 240 * 2)
  672. min_pkt_size *= 2;
  673. for (i = 0; i < dev->num_alt; i++) {
  674. /* stop when the selected alt setting offers enough bandwidth */
  675. if (dev->alt_max_pkt_size[i] >= min_pkt_size) {
  676. dev->alt = i;
  677. break;
  678. /* otherwise make sure that we end up with the maximum bandwidth
  679. because the min_pkt_size equation might be wrong...
  680. */
  681. } else if (dev->alt_max_pkt_size[i] >
  682. dev->alt_max_pkt_size[dev->alt])
  683. dev->alt = i;
  684. }
  685. set_alt:
  686. if (dev->alt != prev_alt) {
  687. em28xx_coredbg("minimum isoc packet size: %u (alt=%d)\n",
  688. min_pkt_size, dev->alt);
  689. dev->max_pkt_size = dev->alt_max_pkt_size[dev->alt];
  690. em28xx_coredbg("setting alternate %d with wMaxPacketSize=%u\n",
  691. dev->alt, dev->max_pkt_size);
  692. errCode = usb_set_interface(dev->udev, 0, dev->alt);
  693. if (errCode < 0) {
  694. em28xx_errdev("cannot change alternate number to %d (error=%i)\n",
  695. dev->alt, errCode);
  696. return errCode;
  697. }
  698. }
  699. return 0;
  700. }
  701. int em28xx_gpio_set(struct em28xx *dev, struct em28xx_reg_seq *gpio)
  702. {
  703. int rc = 0;
  704. if (!gpio)
  705. return rc;
  706. if (dev->mode != EM28XX_SUSPEND) {
  707. em28xx_write_reg(dev, 0x48, 0x00);
  708. if (dev->mode == EM28XX_ANALOG_MODE)
  709. em28xx_write_reg(dev, EM28XX_R12_VINENABLE, 0x67);
  710. else
  711. em28xx_write_reg(dev, EM28XX_R12_VINENABLE, 0x37);
  712. msleep(6);
  713. }
  714. /* Send GPIO reset sequences specified at board entry */
  715. while (gpio->sleep >= 0) {
  716. if (gpio->reg >= 0) {
  717. rc = em28xx_write_reg_bits(dev,
  718. gpio->reg,
  719. gpio->val,
  720. gpio->mask);
  721. if (rc < 0)
  722. return rc;
  723. }
  724. if (gpio->sleep > 0)
  725. msleep(gpio->sleep);
  726. gpio++;
  727. }
  728. return rc;
  729. }
  730. int em28xx_set_mode(struct em28xx *dev, enum em28xx_mode set_mode)
  731. {
  732. if (dev->mode == set_mode)
  733. return 0;
  734. if (set_mode == EM28XX_SUSPEND) {
  735. dev->mode = set_mode;
  736. /* FIXME: add suspend support for ac97 */
  737. return em28xx_gpio_set(dev, dev->board.suspend_gpio);
  738. }
  739. dev->mode = set_mode;
  740. if (dev->mode == EM28XX_DIGITAL_MODE)
  741. return em28xx_gpio_set(dev, dev->board.dvb_gpio);
  742. else
  743. return em28xx_gpio_set(dev, INPUT(dev->ctl_input)->gpio);
  744. }
  745. EXPORT_SYMBOL_GPL(em28xx_set_mode);
  746. /* ------------------------------------------------------------------
  747. URB control
  748. ------------------------------------------------------------------*/
  749. /*
  750. * IRQ callback, called by URB callback
  751. */
  752. static void em28xx_irq_callback(struct urb *urb)
  753. {
  754. struct em28xx *dev = urb->context;
  755. int rc, i;
  756. switch (urb->status) {
  757. case 0: /* success */
  758. case -ETIMEDOUT: /* NAK */
  759. break;
  760. case -ECONNRESET: /* kill */
  761. case -ENOENT:
  762. case -ESHUTDOWN:
  763. return;
  764. default: /* error */
  765. em28xx_isocdbg("urb completition error %d.\n", urb->status);
  766. break;
  767. }
  768. /* Copy data from URB */
  769. spin_lock(&dev->slock);
  770. rc = dev->isoc_ctl.isoc_copy(dev, urb);
  771. spin_unlock(&dev->slock);
  772. /* Reset urb buffers */
  773. for (i = 0; i < urb->number_of_packets; i++) {
  774. urb->iso_frame_desc[i].status = 0;
  775. urb->iso_frame_desc[i].actual_length = 0;
  776. }
  777. urb->status = 0;
  778. urb->status = usb_submit_urb(urb, GFP_ATOMIC);
  779. if (urb->status) {
  780. em28xx_isocdbg("urb resubmit failed (error=%i)\n",
  781. urb->status);
  782. }
  783. }
  784. /*
  785. * Stop and Deallocate URBs
  786. */
  787. void em28xx_uninit_isoc(struct em28xx *dev)
  788. {
  789. struct urb *urb;
  790. int i;
  791. em28xx_isocdbg("em28xx: called em28xx_uninit_isoc\n");
  792. dev->isoc_ctl.nfields = -1;
  793. for (i = 0; i < dev->isoc_ctl.num_bufs; i++) {
  794. urb = dev->isoc_ctl.urb[i];
  795. if (urb) {
  796. if (!irqs_disabled())
  797. usb_kill_urb(urb);
  798. else
  799. usb_unlink_urb(urb);
  800. if (dev->isoc_ctl.transfer_buffer[i]) {
  801. usb_free_coherent(dev->udev,
  802. urb->transfer_buffer_length,
  803. dev->isoc_ctl.transfer_buffer[i],
  804. urb->transfer_dma);
  805. }
  806. usb_free_urb(urb);
  807. dev->isoc_ctl.urb[i] = NULL;
  808. }
  809. dev->isoc_ctl.transfer_buffer[i] = NULL;
  810. }
  811. kfree(dev->isoc_ctl.urb);
  812. kfree(dev->isoc_ctl.transfer_buffer);
  813. dev->isoc_ctl.urb = NULL;
  814. dev->isoc_ctl.transfer_buffer = NULL;
  815. dev->isoc_ctl.num_bufs = 0;
  816. em28xx_capture_start(dev, 0);
  817. }
  818. EXPORT_SYMBOL_GPL(em28xx_uninit_isoc);
  819. /*
  820. * Allocate URBs and start IRQ
  821. */
  822. int em28xx_init_isoc(struct em28xx *dev, int max_packets,
  823. int num_bufs, int max_pkt_size,
  824. int (*isoc_copy) (struct em28xx *dev, struct urb *urb))
  825. {
  826. struct em28xx_dmaqueue *dma_q = &dev->vidq;
  827. struct em28xx_dmaqueue *vbi_dma_q = &dev->vbiq;
  828. int i;
  829. int sb_size, pipe;
  830. struct urb *urb;
  831. int j, k;
  832. int rc;
  833. em28xx_isocdbg("em28xx: called em28xx_prepare_isoc\n");
  834. /* De-allocates all pending stuff */
  835. em28xx_uninit_isoc(dev);
  836. dev->isoc_ctl.isoc_copy = isoc_copy;
  837. dev->isoc_ctl.num_bufs = num_bufs;
  838. dev->isoc_ctl.urb = kzalloc(sizeof(void *)*num_bufs, GFP_KERNEL);
  839. if (!dev->isoc_ctl.urb) {
  840. em28xx_errdev("cannot alloc memory for usb buffers\n");
  841. return -ENOMEM;
  842. }
  843. dev->isoc_ctl.transfer_buffer = kzalloc(sizeof(void *)*num_bufs,
  844. GFP_KERNEL);
  845. if (!dev->isoc_ctl.transfer_buffer) {
  846. em28xx_errdev("cannot allocate memory for usb transfer\n");
  847. kfree(dev->isoc_ctl.urb);
  848. return -ENOMEM;
  849. }
  850. dev->isoc_ctl.max_pkt_size = max_pkt_size;
  851. dev->isoc_ctl.vid_buf = NULL;
  852. dev->isoc_ctl.vbi_buf = NULL;
  853. sb_size = max_packets * dev->isoc_ctl.max_pkt_size;
  854. /* allocate urbs and transfer buffers */
  855. for (i = 0; i < dev->isoc_ctl.num_bufs; i++) {
  856. urb = usb_alloc_urb(max_packets, GFP_KERNEL);
  857. if (!urb) {
  858. em28xx_err("cannot alloc isoc_ctl.urb %i\n", i);
  859. em28xx_uninit_isoc(dev);
  860. return -ENOMEM;
  861. }
  862. dev->isoc_ctl.urb[i] = urb;
  863. dev->isoc_ctl.transfer_buffer[i] = usb_alloc_coherent(dev->udev,
  864. sb_size, GFP_KERNEL, &urb->transfer_dma);
  865. if (!dev->isoc_ctl.transfer_buffer[i]) {
  866. em28xx_err("unable to allocate %i bytes for transfer"
  867. " buffer %i%s\n",
  868. sb_size, i,
  869. in_interrupt() ? " while in int" : "");
  870. em28xx_uninit_isoc(dev);
  871. return -ENOMEM;
  872. }
  873. memset(dev->isoc_ctl.transfer_buffer[i], 0, sb_size);
  874. /* FIXME: this is a hack - should be
  875. 'desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK'
  876. should also be using 'desc.bInterval'
  877. */
  878. pipe = usb_rcvisocpipe(dev->udev,
  879. dev->mode == EM28XX_ANALOG_MODE ? 0x82 : 0x84);
  880. usb_fill_int_urb(urb, dev->udev, pipe,
  881. dev->isoc_ctl.transfer_buffer[i], sb_size,
  882. em28xx_irq_callback, dev, 1);
  883. urb->number_of_packets = max_packets;
  884. urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
  885. k = 0;
  886. for (j = 0; j < max_packets; j++) {
  887. urb->iso_frame_desc[j].offset = k;
  888. urb->iso_frame_desc[j].length =
  889. dev->isoc_ctl.max_pkt_size;
  890. k += dev->isoc_ctl.max_pkt_size;
  891. }
  892. }
  893. init_waitqueue_head(&dma_q->wq);
  894. init_waitqueue_head(&vbi_dma_q->wq);
  895. em28xx_capture_start(dev, 1);
  896. /* submit urbs and enables IRQ */
  897. for (i = 0; i < dev->isoc_ctl.num_bufs; i++) {
  898. rc = usb_submit_urb(dev->isoc_ctl.urb[i], GFP_ATOMIC);
  899. if (rc) {
  900. em28xx_err("submit of urb %i failed (error=%i)\n", i,
  901. rc);
  902. em28xx_uninit_isoc(dev);
  903. return rc;
  904. }
  905. }
  906. return 0;
  907. }
  908. EXPORT_SYMBOL_GPL(em28xx_init_isoc);
  909. /* Determine the packet size for the DVB stream for the given device
  910. (underlying value programmed into the eeprom) */
  911. int em28xx_isoc_dvb_max_packetsize(struct em28xx *dev)
  912. {
  913. unsigned int chip_cfg2;
  914. unsigned int packet_size = 564;
  915. if (dev->chip_id == CHIP_ID_EM2874) {
  916. /* FIXME - for now assume 564 like it was before, but the
  917. em2874 code should be added to return the proper value... */
  918. packet_size = 564;
  919. } else {
  920. /* TS max packet size stored in bits 1-0 of R01 */
  921. chip_cfg2 = em28xx_read_reg(dev, EM28XX_R01_CHIPCFG2);
  922. switch (chip_cfg2 & EM28XX_CHIPCFG2_TS_PACKETSIZE_MASK) {
  923. case EM28XX_CHIPCFG2_TS_PACKETSIZE_188:
  924. packet_size = 188;
  925. break;
  926. case EM28XX_CHIPCFG2_TS_PACKETSIZE_376:
  927. packet_size = 376;
  928. break;
  929. case EM28XX_CHIPCFG2_TS_PACKETSIZE_564:
  930. packet_size = 564;
  931. break;
  932. case EM28XX_CHIPCFG2_TS_PACKETSIZE_752:
  933. packet_size = 752;
  934. break;
  935. }
  936. }
  937. em28xx_coredbg("dvb max packet size=%d\n", packet_size);
  938. return packet_size;
  939. }
  940. EXPORT_SYMBOL_GPL(em28xx_isoc_dvb_max_packetsize);
  941. /*
  942. * em28xx_wake_i2c()
  943. * configure i2c attached devices
  944. */
  945. void em28xx_wake_i2c(struct em28xx *dev)
  946. {
  947. v4l2_device_call_all(&dev->v4l2_dev, 0, core, reset, 0);
  948. v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_routing,
  949. INPUT(dev->ctl_input)->vmux, 0, 0);
  950. v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_stream, 0);
  951. }
  952. /*
  953. * Device control list
  954. */
  955. static LIST_HEAD(em28xx_devlist);
  956. static DEFINE_MUTEX(em28xx_devlist_mutex);
  957. /*
  958. * em28xx_realease_resources()
  959. * unregisters the v4l2,i2c and usb devices
  960. * called when the device gets disconected or at module unload
  961. */
  962. void em28xx_remove_from_devlist(struct em28xx *dev)
  963. {
  964. mutex_lock(&em28xx_devlist_mutex);
  965. list_del(&dev->devlist);
  966. mutex_unlock(&em28xx_devlist_mutex);
  967. };
  968. void em28xx_add_into_devlist(struct em28xx *dev)
  969. {
  970. mutex_lock(&em28xx_devlist_mutex);
  971. list_add_tail(&dev->devlist, &em28xx_devlist);
  972. mutex_unlock(&em28xx_devlist_mutex);
  973. };
  974. /*
  975. * Extension interface
  976. */
  977. static LIST_HEAD(em28xx_extension_devlist);
  978. int em28xx_register_extension(struct em28xx_ops *ops)
  979. {
  980. struct em28xx *dev = NULL;
  981. mutex_lock(&em28xx_devlist_mutex);
  982. list_add_tail(&ops->next, &em28xx_extension_devlist);
  983. list_for_each_entry(dev, &em28xx_devlist, devlist) {
  984. ops->init(dev);
  985. }
  986. printk(KERN_INFO "Em28xx: Initialized (%s) extension\n", ops->name);
  987. mutex_unlock(&em28xx_devlist_mutex);
  988. return 0;
  989. }
  990. EXPORT_SYMBOL(em28xx_register_extension);
  991. void em28xx_unregister_extension(struct em28xx_ops *ops)
  992. {
  993. struct em28xx *dev = NULL;
  994. mutex_lock(&em28xx_devlist_mutex);
  995. list_for_each_entry(dev, &em28xx_devlist, devlist) {
  996. ops->fini(dev);
  997. }
  998. printk(KERN_INFO "Em28xx: Removed (%s) extension\n", ops->name);
  999. list_del(&ops->next);
  1000. mutex_unlock(&em28xx_devlist_mutex);
  1001. }
  1002. EXPORT_SYMBOL(em28xx_unregister_extension);
  1003. void em28xx_init_extension(struct em28xx *dev)
  1004. {
  1005. struct em28xx_ops *ops = NULL;
  1006. mutex_lock(&em28xx_devlist_mutex);
  1007. if (!list_empty(&em28xx_extension_devlist)) {
  1008. list_for_each_entry(ops, &em28xx_extension_devlist, next) {
  1009. if (ops->init)
  1010. ops->init(dev);
  1011. }
  1012. }
  1013. mutex_unlock(&em28xx_devlist_mutex);
  1014. }
  1015. void em28xx_close_extension(struct em28xx *dev)
  1016. {
  1017. struct em28xx_ops *ops = NULL;
  1018. mutex_lock(&em28xx_devlist_mutex);
  1019. if (!list_empty(&em28xx_extension_devlist)) {
  1020. list_for_each_entry(ops, &em28xx_extension_devlist, next) {
  1021. if (ops->fini)
  1022. ops->fini(dev);
  1023. }
  1024. }
  1025. mutex_unlock(&em28xx_devlist_mutex);
  1026. }