radio-si470x.c 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813
  1. /*
  2. * drivers/media/radio/radio-si470x.c
  3. *
  4. * Driver for USB radios for the Silicon Labs Si470x FM Radio Receivers:
  5. * - Silicon Labs USB FM Radio Reference Design
  6. * - ADS/Tech FM Radio Receiver (formerly Instant FM Music) (RDX-155-EF)
  7. *
  8. * Copyright (c) 2008 Tobias Lorenz <tobias.lorenz@gmx.net>
  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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. */
  24. /*
  25. * User Notes:
  26. * - USB Audio is provided by the alsa snd_usb_audio module.
  27. * For listing you have to redirect the sound, for example using:
  28. * arecord -D hw:1,0 -r96000 -c2 -f S16_LE | artsdsp aplay -B -
  29. * - regarding module parameters in /sys/module/radio_si470x/parameters:
  30. * the contents of read-only files (0444) are not updated, even if
  31. * space, band and de are changed using private video controls
  32. * - increase tune_timeout, if you often get -EIO errors
  33. * - hw_freq_seek returns -EAGAIN, when timed out or band limit is reached
  34. */
  35. /*
  36. * History:
  37. * 2008-01-12 Tobias Lorenz <tobias.lorenz@gmx.net>
  38. * Version 1.0.0
  39. * - First working version
  40. * 2008-01-13 Tobias Lorenz <tobias.lorenz@gmx.net>
  41. * Version 1.0.1
  42. * - Improved error handling, every function now returns errno
  43. * - Improved multi user access (start/mute/stop)
  44. * - Channel doesn't get lost anymore after start/mute/stop
  45. * - RDS support added (polling mode via interrupt EP 1)
  46. * - marked default module parameters with *value*
  47. * - switched from bit structs to bit masks
  48. * - header file cleaned and integrated
  49. * 2008-01-14 Tobias Lorenz <tobias.lorenz@gmx.net>
  50. * Version 1.0.2
  51. * - hex values are now lower case
  52. * - commented USB ID for ADS/Tech moved on todo list
  53. * - blacklisted si470x in hid-quirks.c
  54. * - rds buffer handling functions integrated into *_work, *_read
  55. * - rds_command in si470x_poll exchanged against simple retval
  56. * - check for firmware version 15
  57. * - code order and prototypes still remain the same
  58. * - spacing and bottom of band codes remain the same
  59. * 2008-01-16 Tobias Lorenz <tobias.lorenz@gmx.net>
  60. * Version 1.0.3
  61. * - code reordered to avoid function prototypes
  62. * - switch/case defaults are now more user-friendly
  63. * - unified comment style
  64. * - applied all checkpatch.pl v1.12 suggestions
  65. * except the warning about the too long lines with bit comments
  66. * - renamed FMRADIO to RADIO to cut line length (checkpatch.pl)
  67. * 2008-01-22 Tobias Lorenz <tobias.lorenz@gmx.net>
  68. * Version 1.0.4
  69. * - avoid poss. locking when doing copy_to_user which may sleep
  70. * - RDS is automatically activated on read now
  71. * - code cleaned of unnecessary rds_commands
  72. * - USB Vendor/Product ID for ADS/Tech FM Radio Receiver verified
  73. * (thanks to Guillaume RAMOUSSE)
  74. * 2008-01-27 Tobias Lorenz <tobias.lorenz@gmx.net>
  75. * Version 1.0.5
  76. * - number of seek_retries changed to tune_timeout
  77. * - fixed problem with incomplete tune operations by own buffers
  78. * - optimization of variables and printf types
  79. * - improved error logging
  80. * 2008-01-31 Tobias Lorenz <tobias.lorenz@gmx.net>
  81. * Oliver Neukum <oliver@neukum.org>
  82. * Version 1.0.6
  83. * - fixed coverity checker warnings in *_usb_driver_disconnect
  84. * - probe()/open() race by correct ordering in probe()
  85. * - DMA coherency rules by separate allocation of all buffers
  86. * - use of endianness macros
  87. * - abuse of spinlock, replaced by mutex
  88. * - racy handling of timer in disconnect,
  89. * replaced by delayed_work
  90. * - racy interruptible_sleep_on(),
  91. * replaced with wait_event_interruptible()
  92. * - handle signals in read()
  93. * 2008-02-08 Tobias Lorenz <tobias.lorenz@gmx.net>
  94. * Oliver Neukum <oliver@neukum.org>
  95. * Version 1.0.7
  96. * - usb autosuspend support
  97. * - unplugging fixed
  98. * 2008-05-07 Tobias Lorenz <tobias.lorenz@gmx.net>
  99. * Version 1.0.8
  100. * - hardware frequency seek support
  101. * - afc indication
  102. * - more safety checks, let si470x_get_freq return errno
  103. *
  104. * ToDo:
  105. * - add firmware download/update support
  106. * - RDS support: interrupt mode, instead of polling
  107. * - add LED status output (check if that's not already done in firmware)
  108. */
  109. /* driver definitions */
  110. #define DRIVER_AUTHOR "Tobias Lorenz <tobias.lorenz@gmx.net>"
  111. #define DRIVER_NAME "radio-si470x"
  112. #define DRIVER_KERNEL_VERSION KERNEL_VERSION(1, 0, 8)
  113. #define DRIVER_CARD "Silicon Labs Si470x FM Radio Receiver"
  114. #define DRIVER_DESC "USB radio driver for Si470x FM Radio Receivers"
  115. #define DRIVER_VERSION "1.0.8"
  116. /* kernel includes */
  117. #include <linux/kernel.h>
  118. #include <linux/module.h>
  119. #include <linux/init.h>
  120. #include <linux/slab.h>
  121. #include <linux/input.h>
  122. #include <linux/usb.h>
  123. #include <linux/hid.h>
  124. #include <linux/version.h>
  125. #include <linux/videodev2.h>
  126. #include <linux/mutex.h>
  127. #include <media/v4l2-common.h>
  128. #include <media/rds.h>
  129. #include <asm/unaligned.h>
  130. /* USB Device ID List */
  131. static struct usb_device_id si470x_usb_driver_id_table[] = {
  132. /* Silicon Labs USB FM Radio Reference Design */
  133. { USB_DEVICE_AND_INTERFACE_INFO(0x10c4, 0x818a, USB_CLASS_HID, 0, 0) },
  134. /* ADS/Tech FM Radio Receiver (formerly Instant FM Music) */
  135. { USB_DEVICE_AND_INTERFACE_INFO(0x06e1, 0xa155, USB_CLASS_HID, 0, 0) },
  136. /* Terminating entry */
  137. { }
  138. };
  139. MODULE_DEVICE_TABLE(usb, si470x_usb_driver_id_table);
  140. /**************************************************************************
  141. * Module Parameters
  142. **************************************************************************/
  143. /* Radio Nr */
  144. static int radio_nr = -1;
  145. module_param(radio_nr, int, 0);
  146. MODULE_PARM_DESC(radio_nr, "Radio Nr");
  147. /* Spacing (kHz) */
  148. /* 0: 200 kHz (USA, Australia) */
  149. /* 1: 100 kHz (Europe, Japan) */
  150. /* 2: 50 kHz */
  151. static unsigned short space = 2;
  152. module_param(space, ushort, 0);
  153. MODULE_PARM_DESC(radio_nr, "Spacing: 0=200kHz 1=100kHz *2=50kHz*");
  154. /* Bottom of Band (MHz) */
  155. /* 0: 87.5 - 108 MHz (USA, Europe)*/
  156. /* 1: 76 - 108 MHz (Japan wide band) */
  157. /* 2: 76 - 90 MHz (Japan) */
  158. static unsigned short band = 1;
  159. module_param(band, ushort, 0);
  160. MODULE_PARM_DESC(radio_nr, "Band: 0=87.5..108MHz *1=76..108MHz* 2=76..90MHz");
  161. /* De-emphasis */
  162. /* 0: 75 us (USA) */
  163. /* 1: 50 us (Europe, Australia, Japan) */
  164. static unsigned short de = 1;
  165. module_param(de, ushort, 0);
  166. MODULE_PARM_DESC(radio_nr, "De-emphasis: 0=75us *1=50us*");
  167. /* USB timeout */
  168. static unsigned int usb_timeout = 500;
  169. module_param(usb_timeout, uint, 0);
  170. MODULE_PARM_DESC(usb_timeout, "USB timeout (ms): *500*");
  171. /* Tune timeout */
  172. static unsigned int tune_timeout = 3000;
  173. module_param(tune_timeout, uint, 0);
  174. MODULE_PARM_DESC(tune_timeout, "Tune timeout: *3000*");
  175. /* Seek timeout */
  176. static unsigned int seek_timeout = 5000;
  177. module_param(seek_timeout, uint, 0);
  178. MODULE_PARM_DESC(seek_timeout, "Seek timeout: *5000*");
  179. /* RDS buffer blocks */
  180. static unsigned int rds_buf = 100;
  181. module_param(rds_buf, uint, 0);
  182. MODULE_PARM_DESC(rds_buf, "RDS buffer entries: *100*");
  183. /* RDS maximum block errors */
  184. static unsigned short max_rds_errors = 1;
  185. /* 0 means 0 errors requiring correction */
  186. /* 1 means 1-2 errors requiring correction (used by original USBRadio.exe) */
  187. /* 2 means 3-5 errors requiring correction */
  188. /* 3 means 6+ errors or errors in checkword, correction not possible */
  189. module_param(max_rds_errors, ushort, 0);
  190. MODULE_PARM_DESC(max_rds_errors, "RDS maximum block errors: *1*");
  191. /* RDS poll frequency */
  192. static unsigned int rds_poll_time = 40;
  193. /* 40 is used by the original USBRadio.exe */
  194. /* 50 is used by radio-cadet */
  195. /* 75 should be okay */
  196. /* 80 is the usual RDS receive interval */
  197. module_param(rds_poll_time, uint, 0);
  198. MODULE_PARM_DESC(rds_poll_time, "RDS poll time (ms): *40*");
  199. /**************************************************************************
  200. * Register Definitions
  201. **************************************************************************/
  202. #define RADIO_REGISTER_SIZE 2 /* 16 register bit width */
  203. #define RADIO_REGISTER_NUM 16 /* DEVICEID ... RDSD */
  204. #define RDS_REGISTER_NUM 6 /* STATUSRSSI ... RDSD */
  205. #define DEVICEID 0 /* Device ID */
  206. #define DEVICEID_PN 0xf000 /* bits 15..12: Part Number */
  207. #define DEVICEID_MFGID 0x0fff /* bits 11..00: Manufacturer ID */
  208. #define CHIPID 1 /* Chip ID */
  209. #define CHIPID_REV 0xfc00 /* bits 15..10: Chip Version */
  210. #define CHIPID_DEV 0x0200 /* bits 09..09: Device */
  211. #define CHIPID_FIRMWARE 0x01ff /* bits 08..00: Firmware Version */
  212. #define POWERCFG 2 /* Power Configuration */
  213. #define POWERCFG_DSMUTE 0x8000 /* bits 15..15: Softmute Disable */
  214. #define POWERCFG_DMUTE 0x4000 /* bits 14..14: Mute Disable */
  215. #define POWERCFG_MONO 0x2000 /* bits 13..13: Mono Select */
  216. #define POWERCFG_RDSM 0x0800 /* bits 11..11: RDS Mode (Si4701 only) */
  217. #define POWERCFG_SKMODE 0x0400 /* bits 10..10: Seek Mode */
  218. #define POWERCFG_SEEKUP 0x0200 /* bits 09..09: Seek Direction */
  219. #define POWERCFG_SEEK 0x0100 /* bits 08..08: Seek */
  220. #define POWERCFG_DISABLE 0x0040 /* bits 06..06: Powerup Disable */
  221. #define POWERCFG_ENABLE 0x0001 /* bits 00..00: Powerup Enable */
  222. #define CHANNEL 3 /* Channel */
  223. #define CHANNEL_TUNE 0x8000 /* bits 15..15: Tune */
  224. #define CHANNEL_CHAN 0x03ff /* bits 09..00: Channel Select */
  225. #define SYSCONFIG1 4 /* System Configuration 1 */
  226. #define SYSCONFIG1_RDSIEN 0x8000 /* bits 15..15: RDS Interrupt Enable (Si4701 only) */
  227. #define SYSCONFIG1_STCIEN 0x4000 /* bits 14..14: Seek/Tune Complete Interrupt Enable */
  228. #define SYSCONFIG1_RDS 0x1000 /* bits 12..12: RDS Enable (Si4701 only) */
  229. #define SYSCONFIG1_DE 0x0800 /* bits 11..11: De-emphasis (0=75us 1=50us) */
  230. #define SYSCONFIG1_AGCD 0x0400 /* bits 10..10: AGC Disable */
  231. #define SYSCONFIG1_BLNDADJ 0x00c0 /* bits 07..06: Stereo/Mono Blend Level Adjustment */
  232. #define SYSCONFIG1_GPIO3 0x0030 /* bits 05..04: General Purpose I/O 3 */
  233. #define SYSCONFIG1_GPIO2 0x000c /* bits 03..02: General Purpose I/O 2 */
  234. #define SYSCONFIG1_GPIO1 0x0003 /* bits 01..00: General Purpose I/O 1 */
  235. #define SYSCONFIG2 5 /* System Configuration 2 */
  236. #define SYSCONFIG2_SEEKTH 0xff00 /* bits 15..08: RSSI Seek Threshold */
  237. #define SYSCONFIG2_BAND 0x0080 /* bits 07..06: Band Select */
  238. #define SYSCONFIG2_SPACE 0x0030 /* bits 05..04: Channel Spacing */
  239. #define SYSCONFIG2_VOLUME 0x000f /* bits 03..00: Volume */
  240. #define SYSCONFIG3 6 /* System Configuration 3 */
  241. #define SYSCONFIG3_SMUTER 0xc000 /* bits 15..14: Softmute Attack/Recover Rate */
  242. #define SYSCONFIG3_SMUTEA 0x3000 /* bits 13..12: Softmute Attenuation */
  243. #define SYSCONFIG3_SKSNR 0x00f0 /* bits 07..04: Seek SNR Threshold */
  244. #define SYSCONFIG3_SKCNT 0x000f /* bits 03..00: Seek FM Impulse Detection Threshold */
  245. #define TEST1 7 /* Test 1 */
  246. #define TEST1_AHIZEN 0x4000 /* bits 14..14: Audio High-Z Enable */
  247. #define TEST2 8 /* Test 2 */
  248. /* TEST2 only contains reserved bits */
  249. #define BOOTCONFIG 9 /* Boot Configuration */
  250. /* BOOTCONFIG only contains reserved bits */
  251. #define STATUSRSSI 10 /* Status RSSI */
  252. #define STATUSRSSI_RDSR 0x8000 /* bits 15..15: RDS Ready (Si4701 only) */
  253. #define STATUSRSSI_STC 0x4000 /* bits 14..14: Seek/Tune Complete */
  254. #define STATUSRSSI_SF 0x2000 /* bits 13..13: Seek Fail/Band Limit */
  255. #define STATUSRSSI_AFCRL 0x1000 /* bits 12..12: AFC Rail */
  256. #define STATUSRSSI_RDSS 0x0800 /* bits 11..11: RDS Synchronized (Si4701 only) */
  257. #define STATUSRSSI_BLERA 0x0600 /* bits 10..09: RDS Block A Errors (Si4701 only) */
  258. #define STATUSRSSI_ST 0x0100 /* bits 08..08: Stereo Indicator */
  259. #define STATUSRSSI_RSSI 0x00ff /* bits 07..00: RSSI (Received Signal Strength Indicator) */
  260. #define READCHAN 11 /* Read Channel */
  261. #define READCHAN_BLERB 0xc000 /* bits 15..14: RDS Block D Errors (Si4701 only) */
  262. #define READCHAN_BLERC 0x3000 /* bits 13..12: RDS Block C Errors (Si4701 only) */
  263. #define READCHAN_BLERD 0x0c00 /* bits 11..10: RDS Block B Errors (Si4701 only) */
  264. #define READCHAN_READCHAN 0x03ff /* bits 09..00: Read Channel */
  265. #define RDSA 12 /* RDSA */
  266. #define RDSA_RDSA 0xffff /* bits 15..00: RDS Block A Data (Si4701 only) */
  267. #define RDSB 13 /* RDSB */
  268. #define RDSB_RDSB 0xffff /* bits 15..00: RDS Block B Data (Si4701 only) */
  269. #define RDSC 14 /* RDSC */
  270. #define RDSC_RDSC 0xffff /* bits 15..00: RDS Block C Data (Si4701 only) */
  271. #define RDSD 15 /* RDSD */
  272. #define RDSD_RDSD 0xffff /* bits 15..00: RDS Block D Data (Si4701 only) */
  273. /**************************************************************************
  274. * USB HID Reports
  275. **************************************************************************/
  276. /* Reports 1-16 give direct read/write access to the 16 Si470x registers */
  277. /* with the (REPORT_ID - 1) corresponding to the register address across USB */
  278. /* endpoint 0 using GET_REPORT and SET_REPORT */
  279. #define REGISTER_REPORT_SIZE (RADIO_REGISTER_SIZE + 1)
  280. #define REGISTER_REPORT(reg) ((reg) + 1)
  281. /* Report 17 gives direct read/write access to the entire Si470x register */
  282. /* map across endpoint 0 using GET_REPORT and SET_REPORT */
  283. #define ENTIRE_REPORT_SIZE (RADIO_REGISTER_NUM * RADIO_REGISTER_SIZE + 1)
  284. #define ENTIRE_REPORT 17
  285. /* Report 18 is used to send the lowest 6 Si470x registers up the HID */
  286. /* interrupt endpoint 1 to Windows every 20 milliseconds for status */
  287. #define RDS_REPORT_SIZE (RDS_REGISTER_NUM * RADIO_REGISTER_SIZE + 1)
  288. #define RDS_REPORT 18
  289. /* Report 19: LED state */
  290. #define LED_REPORT_SIZE 3
  291. #define LED_REPORT 19
  292. /* Report 19: stream */
  293. #define STREAM_REPORT_SIZE 3
  294. #define STREAM_REPORT 19
  295. /* Report 20: scratch */
  296. #define SCRATCH_PAGE_SIZE 63
  297. #define SCRATCH_REPORT_SIZE (SCRATCH_PAGE_SIZE + 1)
  298. #define SCRATCH_REPORT 20
  299. /* Reports 19-22: flash upgrade of the C8051F321 */
  300. #define WRITE_REPORT 19
  301. #define FLASH_REPORT 20
  302. #define CRC_REPORT 21
  303. #define RESPONSE_REPORT 22
  304. /* Report 23: currently unused, but can accept 60 byte reports on the HID */
  305. /* interrupt out endpoint 2 every 1 millisecond */
  306. #define UNUSED_REPORT 23
  307. /**************************************************************************
  308. * Software/Hardware Versions
  309. **************************************************************************/
  310. #define RADIO_SW_VERSION_NOT_BOOTLOADABLE 6
  311. #define RADIO_SW_VERSION 7
  312. #define RADIO_SW_VERSION_CURRENT 15
  313. #define RADIO_HW_VERSION 1
  314. #define SCRATCH_PAGE_SW_VERSION 1
  315. #define SCRATCH_PAGE_HW_VERSION 2
  316. /**************************************************************************
  317. * LED State Definitions
  318. **************************************************************************/
  319. #define LED_COMMAND 0x35
  320. #define NO_CHANGE_LED 0x00
  321. #define ALL_COLOR_LED 0x01 /* streaming state */
  322. #define BLINK_GREEN_LED 0x02 /* connect state */
  323. #define BLINK_RED_LED 0x04
  324. #define BLINK_ORANGE_LED 0x10 /* disconnect state */
  325. #define SOLID_GREEN_LED 0x20 /* tuning/seeking state */
  326. #define SOLID_RED_LED 0x40 /* bootload state */
  327. #define SOLID_ORANGE_LED 0x80
  328. /**************************************************************************
  329. * Stream State Definitions
  330. **************************************************************************/
  331. #define STREAM_COMMAND 0x36
  332. #define STREAM_VIDPID 0x00
  333. #define STREAM_AUDIO 0xff
  334. /**************************************************************************
  335. * Bootloader / Flash Commands
  336. **************************************************************************/
  337. /* unique id sent to bootloader and required to put into a bootload state */
  338. #define UNIQUE_BL_ID 0x34
  339. /* mask for the flash data */
  340. #define FLASH_DATA_MASK 0x55
  341. /* bootloader commands */
  342. #define GET_SW_VERSION_COMMAND 0x00
  343. #define SET_PAGE_COMMAND 0x01
  344. #define ERASE_PAGE_COMMAND 0x02
  345. #define WRITE_PAGE_COMMAND 0x03
  346. #define CRC_ON_PAGE_COMMAND 0x04
  347. #define READ_FLASH_BYTE_COMMAND 0x05
  348. #define RESET_DEVICE_COMMAND 0x06
  349. #define GET_HW_VERSION_COMMAND 0x07
  350. #define BLANK 0xff
  351. /* bootloader command responses */
  352. #define COMMAND_OK 0x01
  353. #define COMMAND_FAILED 0x02
  354. #define COMMAND_PENDING 0x03
  355. /* buffer sizes */
  356. #define COMMAND_BUFFER_SIZE 4
  357. #define RESPONSE_BUFFER_SIZE 2
  358. #define FLASH_BUFFER_SIZE 64
  359. #define CRC_BUFFER_SIZE 3
  360. /**************************************************************************
  361. * General Driver Definitions
  362. **************************************************************************/
  363. /*
  364. * si470x_device - private data
  365. */
  366. struct si470x_device {
  367. /* reference to USB and video device */
  368. struct usb_device *usbdev;
  369. struct usb_interface *intf;
  370. struct video_device *videodev;
  371. /* driver management */
  372. unsigned int users;
  373. unsigned char disconnected;
  374. struct mutex disconnect_lock;
  375. /* Silabs internal registers (0..15) */
  376. unsigned short registers[RADIO_REGISTER_NUM];
  377. /* RDS receive buffer */
  378. struct delayed_work work;
  379. wait_queue_head_t read_queue;
  380. struct mutex lock; /* buffer locking */
  381. unsigned char *buffer; /* size is always multiple of three */
  382. unsigned int buf_size;
  383. unsigned int rd_index;
  384. unsigned int wr_index;
  385. };
  386. /*
  387. * The frequency is set in units of 62.5 Hz when using V4L2_TUNER_CAP_LOW,
  388. * 62.5 kHz otherwise.
  389. * The tuner is able to have a channel spacing of 50, 100 or 200 kHz.
  390. * tuner->capability is therefore set to V4L2_TUNER_CAP_LOW
  391. * The FREQ_MUL is then: 1 MHz / 62.5 Hz = 16000
  392. */
  393. #define FREQ_MUL (1000000 / 62.5)
  394. /**************************************************************************
  395. * General Driver Functions
  396. **************************************************************************/
  397. /*
  398. * si470x_get_report - receive a HID report
  399. */
  400. static int si470x_get_report(struct si470x_device *radio, void *buf, int size)
  401. {
  402. unsigned char *report = (unsigned char *) buf;
  403. int retval;
  404. retval = usb_control_msg(radio->usbdev,
  405. usb_rcvctrlpipe(radio->usbdev, 0),
  406. HID_REQ_GET_REPORT,
  407. USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
  408. report[0], 2,
  409. buf, size, usb_timeout);
  410. if (retval < 0)
  411. printk(KERN_WARNING DRIVER_NAME
  412. ": si470x_get_report: usb_control_msg returned %d\n",
  413. retval);
  414. return retval;
  415. }
  416. /*
  417. * si470x_set_report - send a HID report
  418. */
  419. static int si470x_set_report(struct si470x_device *radio, void *buf, int size)
  420. {
  421. unsigned char *report = (unsigned char *) buf;
  422. int retval;
  423. retval = usb_control_msg(radio->usbdev,
  424. usb_sndctrlpipe(radio->usbdev, 0),
  425. HID_REQ_SET_REPORT,
  426. USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
  427. report[0], 2,
  428. buf, size, usb_timeout);
  429. if (retval < 0)
  430. printk(KERN_WARNING DRIVER_NAME
  431. ": si470x_set_report: usb_control_msg returned %d\n",
  432. retval);
  433. return retval;
  434. }
  435. /*
  436. * si470x_get_register - read register
  437. */
  438. static int si470x_get_register(struct si470x_device *radio, int regnr)
  439. {
  440. unsigned char buf[REGISTER_REPORT_SIZE];
  441. int retval;
  442. buf[0] = REGISTER_REPORT(regnr);
  443. retval = si470x_get_report(radio, (void *) &buf, sizeof(buf));
  444. if (retval >= 0)
  445. radio->registers[regnr] = get_unaligned_be16(&buf[1]);
  446. return (retval < 0) ? -EINVAL : 0;
  447. }
  448. /*
  449. * si470x_set_register - write register
  450. */
  451. static int si470x_set_register(struct si470x_device *radio, int regnr)
  452. {
  453. unsigned char buf[REGISTER_REPORT_SIZE];
  454. int retval;
  455. buf[0] = REGISTER_REPORT(regnr);
  456. put_unaligned_be16(radio->registers[regnr], &buf[1]);
  457. retval = si470x_set_report(radio, (void *) &buf, sizeof(buf));
  458. return (retval < 0) ? -EINVAL : 0;
  459. }
  460. /*
  461. * si470x_get_all_registers - read entire registers
  462. */
  463. static int si470x_get_all_registers(struct si470x_device *radio)
  464. {
  465. unsigned char buf[ENTIRE_REPORT_SIZE];
  466. int retval;
  467. unsigned char regnr;
  468. buf[0] = ENTIRE_REPORT;
  469. retval = si470x_get_report(radio, (void *) &buf, sizeof(buf));
  470. if (retval >= 0)
  471. for (regnr = 0; regnr < RADIO_REGISTER_NUM; regnr++)
  472. radio->registers[regnr] = get_unaligned_be16(
  473. &buf[regnr * RADIO_REGISTER_SIZE + 1]);
  474. return (retval < 0) ? -EINVAL : 0;
  475. }
  476. /*
  477. * si470x_get_rds_registers - read rds registers
  478. */
  479. static int si470x_get_rds_registers(struct si470x_device *radio)
  480. {
  481. unsigned char buf[RDS_REPORT_SIZE];
  482. int retval;
  483. int size;
  484. unsigned char regnr;
  485. buf[0] = RDS_REPORT;
  486. retval = usb_interrupt_msg(radio->usbdev,
  487. usb_rcvintpipe(radio->usbdev, 1),
  488. (void *) &buf, sizeof(buf), &size, usb_timeout);
  489. if (size != sizeof(buf))
  490. printk(KERN_WARNING DRIVER_NAME ": si470x_get_rds_registers: "
  491. "return size differs: %d != %zu\n", size, sizeof(buf));
  492. if (retval < 0)
  493. printk(KERN_WARNING DRIVER_NAME ": si470x_get_rds_registers: "
  494. "usb_interrupt_msg returned %d\n", retval);
  495. if (retval >= 0)
  496. for (regnr = 0; regnr < RDS_REGISTER_NUM; regnr++)
  497. radio->registers[STATUSRSSI + regnr] =
  498. get_unaligned_be16(
  499. &buf[regnr * RADIO_REGISTER_SIZE + 1]);
  500. return (retval < 0) ? -EINVAL : 0;
  501. }
  502. /*
  503. * si470x_set_chan - set the channel
  504. */
  505. static int si470x_set_chan(struct si470x_device *radio, unsigned short chan)
  506. {
  507. int retval;
  508. unsigned long timeout;
  509. bool timed_out = 0;
  510. /* start tuning */
  511. radio->registers[CHANNEL] &= ~CHANNEL_CHAN;
  512. radio->registers[CHANNEL] |= CHANNEL_TUNE | chan;
  513. retval = si470x_set_register(radio, CHANNEL);
  514. if (retval < 0)
  515. goto done;
  516. /* wait till tune operation has completed */
  517. timeout = jiffies + msecs_to_jiffies(tune_timeout);
  518. do {
  519. retval = si470x_get_register(radio, STATUSRSSI);
  520. if (retval < 0)
  521. goto stop;
  522. timed_out = time_after(jiffies, timeout);
  523. } while (((radio->registers[STATUSRSSI] & STATUSRSSI_STC) == 0) &&
  524. (!timed_out));
  525. if ((radio->registers[STATUSRSSI] & STATUSRSSI_STC) == 0)
  526. printk(KERN_WARNING DRIVER_NAME ": tune does not complete\n");
  527. if (timed_out)
  528. printk(KERN_WARNING DRIVER_NAME
  529. ": tune timed out after %u ms\n", tune_timeout);
  530. stop:
  531. /* stop tuning */
  532. radio->registers[CHANNEL] &= ~CHANNEL_TUNE;
  533. retval = si470x_set_register(radio, CHANNEL);
  534. done:
  535. return retval;
  536. }
  537. /*
  538. * si470x_get_freq - get the frequency
  539. */
  540. static int si470x_get_freq(struct si470x_device *radio, unsigned int *freq)
  541. {
  542. unsigned int spacing, band_bottom;
  543. unsigned short chan;
  544. int retval;
  545. /* Spacing (kHz) */
  546. switch (space) {
  547. /* 0: 200 kHz (USA, Australia) */
  548. case 0 : spacing = 0.200 * FREQ_MUL; break;
  549. /* 1: 100 kHz (Europe, Japan) */
  550. case 1 : spacing = 0.100 * FREQ_MUL; break;
  551. /* 2: 50 kHz */
  552. default: spacing = 0.050 * FREQ_MUL; break;
  553. };
  554. /* Bottom of Band (MHz) */
  555. switch (band) {
  556. /* 0: 87.5 - 108 MHz (USA, Europe) */
  557. case 0 : band_bottom = 87.5 * FREQ_MUL; break;
  558. /* 1: 76 - 108 MHz (Japan wide band) */
  559. default: band_bottom = 76 * FREQ_MUL; break;
  560. /* 2: 76 - 90 MHz (Japan) */
  561. case 2 : band_bottom = 76 * FREQ_MUL; break;
  562. };
  563. /* read channel */
  564. retval = si470x_get_register(radio, READCHAN);
  565. chan = radio->registers[READCHAN] & READCHAN_READCHAN;
  566. /* Frequency (MHz) = Spacing (kHz) x Channel + Bottom of Band (MHz) */
  567. *freq = chan * spacing + band_bottom;
  568. return retval;
  569. }
  570. /*
  571. * si470x_set_freq - set the frequency
  572. */
  573. static int si470x_set_freq(struct si470x_device *radio, unsigned int freq)
  574. {
  575. unsigned int spacing, band_bottom;
  576. unsigned short chan;
  577. /* Spacing (kHz) */
  578. switch (space) {
  579. /* 0: 200 kHz (USA, Australia) */
  580. case 0 : spacing = 0.200 * FREQ_MUL; break;
  581. /* 1: 100 kHz (Europe, Japan) */
  582. case 1 : spacing = 0.100 * FREQ_MUL; break;
  583. /* 2: 50 kHz */
  584. default: spacing = 0.050 * FREQ_MUL; break;
  585. };
  586. /* Bottom of Band (MHz) */
  587. switch (band) {
  588. /* 0: 87.5 - 108 MHz (USA, Europe) */
  589. case 0 : band_bottom = 87.5 * FREQ_MUL; break;
  590. /* 1: 76 - 108 MHz (Japan wide band) */
  591. default: band_bottom = 76 * FREQ_MUL; break;
  592. /* 2: 76 - 90 MHz (Japan) */
  593. case 2 : band_bottom = 76 * FREQ_MUL; break;
  594. };
  595. /* Chan = [ Freq (Mhz) - Bottom of Band (MHz) ] / Spacing (kHz) */
  596. chan = (freq - band_bottom) / spacing;
  597. return si470x_set_chan(radio, chan);
  598. }
  599. /*
  600. * si470x_set_seek - set seek
  601. */
  602. static int si470x_set_seek(struct si470x_device *radio,
  603. unsigned int wrap_around, unsigned int seek_upward)
  604. {
  605. int retval = 0;
  606. unsigned long timeout;
  607. bool timed_out = 0;
  608. /* start seeking */
  609. radio->registers[POWERCFG] |= POWERCFG_SEEK;
  610. if (wrap_around == 1)
  611. radio->registers[POWERCFG] &= ~POWERCFG_SKMODE;
  612. else
  613. radio->registers[POWERCFG] |= POWERCFG_SKMODE;
  614. if (seek_upward == 1)
  615. radio->registers[POWERCFG] |= POWERCFG_SEEKUP;
  616. else
  617. radio->registers[POWERCFG] &= ~POWERCFG_SEEKUP;
  618. retval = si470x_set_register(radio, POWERCFG);
  619. if (retval < 0)
  620. goto done;
  621. /* wait till seek operation has completed */
  622. timeout = jiffies + msecs_to_jiffies(seek_timeout);
  623. do {
  624. retval = si470x_get_register(radio, STATUSRSSI);
  625. if (retval < 0)
  626. goto stop;
  627. timed_out = time_after(jiffies, timeout);
  628. } while (((radio->registers[STATUSRSSI] & STATUSRSSI_STC) == 0) &&
  629. (!timed_out));
  630. if ((radio->registers[STATUSRSSI] & STATUSRSSI_STC) == 0)
  631. printk(KERN_WARNING DRIVER_NAME ": seek does not complete\n");
  632. if (radio->registers[STATUSRSSI] & STATUSRSSI_SF)
  633. printk(KERN_WARNING DRIVER_NAME
  634. ": seek failed / band limit reached\n");
  635. if (timed_out)
  636. printk(KERN_WARNING DRIVER_NAME
  637. ": seek timed out after %u ms\n", seek_timeout);
  638. stop:
  639. /* stop seeking */
  640. radio->registers[POWERCFG] &= ~POWERCFG_SEEK;
  641. retval = si470x_set_register(radio, POWERCFG);
  642. done:
  643. /* try again, if timed out */
  644. if ((retval == 0) && timed_out)
  645. retval = -EAGAIN;
  646. return retval;
  647. }
  648. /*
  649. * si470x_start - switch on radio
  650. */
  651. static int si470x_start(struct si470x_device *radio)
  652. {
  653. int retval;
  654. /* powercfg */
  655. radio->registers[POWERCFG] =
  656. POWERCFG_DMUTE | POWERCFG_ENABLE | POWERCFG_RDSM;
  657. retval = si470x_set_register(radio, POWERCFG);
  658. if (retval < 0)
  659. goto done;
  660. /* sysconfig 1 */
  661. radio->registers[SYSCONFIG1] = SYSCONFIG1_DE;
  662. retval = si470x_set_register(radio, SYSCONFIG1);
  663. if (retval < 0)
  664. goto done;
  665. /* sysconfig 2 */
  666. radio->registers[SYSCONFIG2] =
  667. (0x3f << 8) | /* SEEKTH */
  668. ((band << 6) & SYSCONFIG2_BAND) | /* BAND */
  669. ((space << 4) & SYSCONFIG2_SPACE) | /* SPACE */
  670. 15; /* VOLUME (max) */
  671. retval = si470x_set_register(radio, SYSCONFIG2);
  672. if (retval < 0)
  673. goto done;
  674. /* reset last channel */
  675. retval = si470x_set_chan(radio,
  676. radio->registers[CHANNEL] & CHANNEL_CHAN);
  677. done:
  678. return retval;
  679. }
  680. /*
  681. * si470x_stop - switch off radio
  682. */
  683. static int si470x_stop(struct si470x_device *radio)
  684. {
  685. int retval;
  686. /* sysconfig 1 */
  687. radio->registers[SYSCONFIG1] &= ~SYSCONFIG1_RDS;
  688. retval = si470x_set_register(radio, SYSCONFIG1);
  689. if (retval < 0)
  690. goto done;
  691. /* powercfg */
  692. radio->registers[POWERCFG] &= ~POWERCFG_DMUTE;
  693. /* POWERCFG_ENABLE has to automatically go low */
  694. radio->registers[POWERCFG] |= POWERCFG_ENABLE | POWERCFG_DISABLE;
  695. retval = si470x_set_register(radio, POWERCFG);
  696. done:
  697. return retval;
  698. }
  699. /*
  700. * si470x_rds_on - switch on rds reception
  701. */
  702. static int si470x_rds_on(struct si470x_device *radio)
  703. {
  704. int retval;
  705. /* sysconfig 1 */
  706. mutex_lock(&radio->lock);
  707. radio->registers[SYSCONFIG1] |= SYSCONFIG1_RDS;
  708. retval = si470x_set_register(radio, SYSCONFIG1);
  709. if (retval < 0)
  710. radio->registers[SYSCONFIG1] &= ~SYSCONFIG1_RDS;
  711. mutex_unlock(&radio->lock);
  712. return retval;
  713. }
  714. /**************************************************************************
  715. * RDS Driver Functions
  716. **************************************************************************/
  717. /*
  718. * si470x_rds - rds processing function
  719. */
  720. static void si470x_rds(struct si470x_device *radio)
  721. {
  722. unsigned char blocknum;
  723. unsigned short bler; /* rds block errors */
  724. unsigned short rds;
  725. unsigned char tmpbuf[3];
  726. /* get rds blocks */
  727. if (si470x_get_rds_registers(radio) < 0)
  728. return;
  729. if ((radio->registers[STATUSRSSI] & STATUSRSSI_RDSR) == 0) {
  730. /* No RDS group ready */
  731. return;
  732. }
  733. if ((radio->registers[STATUSRSSI] & STATUSRSSI_RDSS) == 0) {
  734. /* RDS decoder not synchronized */
  735. return;
  736. }
  737. /* copy all four RDS blocks to internal buffer */
  738. mutex_lock(&radio->lock);
  739. for (blocknum = 0; blocknum < 4; blocknum++) {
  740. switch (blocknum) {
  741. default:
  742. bler = (radio->registers[STATUSRSSI] &
  743. STATUSRSSI_BLERA) >> 9;
  744. rds = radio->registers[RDSA];
  745. break;
  746. case 1:
  747. bler = (radio->registers[READCHAN] &
  748. READCHAN_BLERB) >> 14;
  749. rds = radio->registers[RDSB];
  750. break;
  751. case 2:
  752. bler = (radio->registers[READCHAN] &
  753. READCHAN_BLERC) >> 12;
  754. rds = radio->registers[RDSC];
  755. break;
  756. case 3:
  757. bler = (radio->registers[READCHAN] &
  758. READCHAN_BLERD) >> 10;
  759. rds = radio->registers[RDSD];
  760. break;
  761. };
  762. /* Fill the V4L2 RDS buffer */
  763. put_unaligned_le16(rds, &tmpbuf);
  764. tmpbuf[2] = blocknum; /* offset name */
  765. tmpbuf[2] |= blocknum << 3; /* received offset */
  766. if (bler > max_rds_errors)
  767. tmpbuf[2] |= 0x80; /* uncorrectable errors */
  768. else if (bler > 0)
  769. tmpbuf[2] |= 0x40; /* corrected error(s) */
  770. /* copy RDS block to internal buffer */
  771. memcpy(&radio->buffer[radio->wr_index], &tmpbuf, 3);
  772. radio->wr_index += 3;
  773. /* wrap write pointer */
  774. if (radio->wr_index >= radio->buf_size)
  775. radio->wr_index = 0;
  776. /* check for overflow */
  777. if (radio->wr_index == radio->rd_index) {
  778. /* increment and wrap read pointer */
  779. radio->rd_index += 3;
  780. if (radio->rd_index >= radio->buf_size)
  781. radio->rd_index = 0;
  782. }
  783. }
  784. mutex_unlock(&radio->lock);
  785. /* wake up read queue */
  786. if (radio->wr_index != radio->rd_index)
  787. wake_up_interruptible(&radio->read_queue);
  788. }
  789. /*
  790. * si470x_work - rds work function
  791. */
  792. static void si470x_work(struct work_struct *work)
  793. {
  794. struct si470x_device *radio = container_of(work, struct si470x_device,
  795. work.work);
  796. /* safety checks */
  797. if (radio->disconnected)
  798. return;
  799. if ((radio->registers[SYSCONFIG1] & SYSCONFIG1_RDS) == 0)
  800. return;
  801. si470x_rds(radio);
  802. schedule_delayed_work(&radio->work, msecs_to_jiffies(rds_poll_time));
  803. }
  804. /**************************************************************************
  805. * File Operations Interface
  806. **************************************************************************/
  807. /*
  808. * si470x_fops_read - read RDS data
  809. */
  810. static ssize_t si470x_fops_read(struct file *file, char __user *buf,
  811. size_t count, loff_t *ppos)
  812. {
  813. struct si470x_device *radio = video_get_drvdata(video_devdata(file));
  814. int retval = 0;
  815. unsigned int block_count = 0;
  816. /* switch on rds reception */
  817. if ((radio->registers[SYSCONFIG1] & SYSCONFIG1_RDS) == 0) {
  818. si470x_rds_on(radio);
  819. schedule_delayed_work(&radio->work,
  820. msecs_to_jiffies(rds_poll_time));
  821. }
  822. /* block if no new data available */
  823. while (radio->wr_index == radio->rd_index) {
  824. if (file->f_flags & O_NONBLOCK) {
  825. retval = -EWOULDBLOCK;
  826. goto done;
  827. }
  828. if (wait_event_interruptible(radio->read_queue,
  829. radio->wr_index != radio->rd_index) < 0) {
  830. retval = -EINTR;
  831. goto done;
  832. }
  833. }
  834. /* calculate block count from byte count */
  835. count /= 3;
  836. /* copy RDS block out of internal buffer and to user buffer */
  837. mutex_lock(&radio->lock);
  838. while (block_count < count) {
  839. if (radio->rd_index == radio->wr_index)
  840. break;
  841. /* always transfer rds complete blocks */
  842. if (copy_to_user(buf, &radio->buffer[radio->rd_index], 3))
  843. /* retval = -EFAULT; */
  844. break;
  845. /* increment and wrap read pointer */
  846. radio->rd_index += 3;
  847. if (radio->rd_index >= radio->buf_size)
  848. radio->rd_index = 0;
  849. /* increment counters */
  850. block_count++;
  851. buf += 3;
  852. retval += 3;
  853. }
  854. mutex_unlock(&radio->lock);
  855. done:
  856. return retval;
  857. }
  858. /*
  859. * si470x_fops_poll - poll RDS data
  860. */
  861. static unsigned int si470x_fops_poll(struct file *file,
  862. struct poll_table_struct *pts)
  863. {
  864. struct si470x_device *radio = video_get_drvdata(video_devdata(file));
  865. int retval = 0;
  866. /* switch on rds reception */
  867. if ((radio->registers[SYSCONFIG1] & SYSCONFIG1_RDS) == 0) {
  868. si470x_rds_on(radio);
  869. schedule_delayed_work(&radio->work,
  870. msecs_to_jiffies(rds_poll_time));
  871. }
  872. poll_wait(file, &radio->read_queue, pts);
  873. if (radio->rd_index != radio->wr_index)
  874. retval = POLLIN | POLLRDNORM;
  875. return retval;
  876. }
  877. /*
  878. * si470x_fops_open - file open
  879. */
  880. static int si470x_fops_open(struct inode *inode, struct file *file)
  881. {
  882. struct si470x_device *radio = video_get_drvdata(video_devdata(file));
  883. int retval;
  884. radio->users++;
  885. retval = usb_autopm_get_interface(radio->intf);
  886. if (retval < 0) {
  887. radio->users--;
  888. retval = -EIO;
  889. goto done;
  890. }
  891. if (radio->users == 1) {
  892. retval = si470x_start(radio);
  893. if (retval < 0)
  894. usb_autopm_put_interface(radio->intf);
  895. }
  896. done:
  897. return retval;
  898. }
  899. /*
  900. * si470x_fops_release - file release
  901. */
  902. static int si470x_fops_release(struct inode *inode, struct file *file)
  903. {
  904. struct si470x_device *radio = video_get_drvdata(video_devdata(file));
  905. int retval = 0;
  906. /* safety check */
  907. if (!radio) {
  908. retval = -ENODEV;
  909. goto done;
  910. }
  911. mutex_lock(&radio->disconnect_lock);
  912. radio->users--;
  913. if (radio->users == 0) {
  914. if (radio->disconnected) {
  915. video_unregister_device(radio->videodev);
  916. kfree(radio->buffer);
  917. kfree(radio);
  918. goto unlock;
  919. }
  920. /* stop rds reception */
  921. cancel_delayed_work_sync(&radio->work);
  922. /* cancel read processes */
  923. wake_up_interruptible(&radio->read_queue);
  924. retval = si470x_stop(radio);
  925. usb_autopm_put_interface(radio->intf);
  926. }
  927. unlock:
  928. mutex_unlock(&radio->disconnect_lock);
  929. done:
  930. return retval;
  931. }
  932. /*
  933. * si470x_fops - file operations interface
  934. */
  935. static const struct file_operations si470x_fops = {
  936. .owner = THIS_MODULE,
  937. .llseek = no_llseek,
  938. .read = si470x_fops_read,
  939. .poll = si470x_fops_poll,
  940. .ioctl = video_ioctl2,
  941. #ifdef CONFIG_COMPAT
  942. .compat_ioctl = v4l_compat_ioctl32,
  943. #endif
  944. .open = si470x_fops_open,
  945. .release = si470x_fops_release,
  946. };
  947. /**************************************************************************
  948. * Video4Linux Interface
  949. **************************************************************************/
  950. /*
  951. * si470x_v4l2_queryctrl - query control
  952. */
  953. static struct v4l2_queryctrl si470x_v4l2_queryctrl[] = {
  954. /* HINT: the disabled controls are only here to satify kradio and such apps */
  955. {
  956. .id = V4L2_CID_AUDIO_VOLUME,
  957. .type = V4L2_CTRL_TYPE_INTEGER,
  958. .name = "Volume",
  959. .minimum = 0,
  960. .maximum = 15,
  961. .step = 1,
  962. .default_value = 15,
  963. },
  964. {
  965. .id = V4L2_CID_AUDIO_BALANCE,
  966. .flags = V4L2_CTRL_FLAG_DISABLED,
  967. },
  968. {
  969. .id = V4L2_CID_AUDIO_BASS,
  970. .flags = V4L2_CTRL_FLAG_DISABLED,
  971. },
  972. {
  973. .id = V4L2_CID_AUDIO_TREBLE,
  974. .flags = V4L2_CTRL_FLAG_DISABLED,
  975. },
  976. {
  977. .id = V4L2_CID_AUDIO_MUTE,
  978. .type = V4L2_CTRL_TYPE_BOOLEAN,
  979. .name = "Mute",
  980. .minimum = 0,
  981. .maximum = 1,
  982. .step = 1,
  983. .default_value = 1,
  984. },
  985. {
  986. .id = V4L2_CID_AUDIO_LOUDNESS,
  987. .flags = V4L2_CTRL_FLAG_DISABLED,
  988. },
  989. };
  990. /*
  991. * si470x_vidioc_querycap - query device capabilities
  992. */
  993. static int si470x_vidioc_querycap(struct file *file, void *priv,
  994. struct v4l2_capability *capability)
  995. {
  996. strlcpy(capability->driver, DRIVER_NAME, sizeof(capability->driver));
  997. strlcpy(capability->card, DRIVER_CARD, sizeof(capability->card));
  998. sprintf(capability->bus_info, "USB");
  999. capability->version = DRIVER_KERNEL_VERSION;
  1000. capability->capabilities = V4L2_CAP_HW_FREQ_SEEK |
  1001. V4L2_CAP_TUNER | V4L2_CAP_RADIO;
  1002. return 0;
  1003. }
  1004. /*
  1005. * si470x_vidioc_g_input - get input
  1006. */
  1007. static int si470x_vidioc_g_input(struct file *file, void *priv,
  1008. unsigned int *i)
  1009. {
  1010. *i = 0;
  1011. return 0;
  1012. }
  1013. /*
  1014. * si470x_vidioc_s_input - set input
  1015. */
  1016. static int si470x_vidioc_s_input(struct file *file, void *priv, unsigned int i)
  1017. {
  1018. int retval = 0;
  1019. /* safety checks */
  1020. if (i != 0)
  1021. retval = -EINVAL;
  1022. if (retval < 0)
  1023. printk(KERN_WARNING DRIVER_NAME
  1024. ": set input failed with %d\n", retval);
  1025. return retval;
  1026. }
  1027. /*
  1028. * si470x_vidioc_queryctrl - enumerate control items
  1029. */
  1030. static int si470x_vidioc_queryctrl(struct file *file, void *priv,
  1031. struct v4l2_queryctrl *qc)
  1032. {
  1033. unsigned char i;
  1034. int retval = -EINVAL;
  1035. /* safety checks */
  1036. if (!qc->id)
  1037. goto done;
  1038. for (i = 0; i < ARRAY_SIZE(si470x_v4l2_queryctrl); i++) {
  1039. if (qc->id == si470x_v4l2_queryctrl[i].id) {
  1040. memcpy(qc, &(si470x_v4l2_queryctrl[i]), sizeof(*qc));
  1041. retval = 0;
  1042. break;
  1043. }
  1044. }
  1045. done:
  1046. if (retval < 0)
  1047. printk(KERN_WARNING DRIVER_NAME
  1048. ": query controls failed with %d\n", retval);
  1049. return retval;
  1050. }
  1051. /*
  1052. * si470x_vidioc_g_ctrl - get the value of a control
  1053. */
  1054. static int si470x_vidioc_g_ctrl(struct file *file, void *priv,
  1055. struct v4l2_control *ctrl)
  1056. {
  1057. struct si470x_device *radio = video_get_drvdata(video_devdata(file));
  1058. int retval = 0;
  1059. /* safety checks */
  1060. if (radio->disconnected) {
  1061. retval = -EIO;
  1062. goto done;
  1063. }
  1064. switch (ctrl->id) {
  1065. case V4L2_CID_AUDIO_VOLUME:
  1066. ctrl->value = radio->registers[SYSCONFIG2] &
  1067. SYSCONFIG2_VOLUME;
  1068. break;
  1069. case V4L2_CID_AUDIO_MUTE:
  1070. ctrl->value = ((radio->registers[POWERCFG] &
  1071. POWERCFG_DMUTE) == 0) ? 1 : 0;
  1072. break;
  1073. default:
  1074. retval = -EINVAL;
  1075. }
  1076. done:
  1077. if (retval < 0)
  1078. printk(KERN_WARNING DRIVER_NAME
  1079. ": get control failed with %d\n", retval);
  1080. return retval;
  1081. }
  1082. /*
  1083. * si470x_vidioc_s_ctrl - set the value of a control
  1084. */
  1085. static int si470x_vidioc_s_ctrl(struct file *file, void *priv,
  1086. struct v4l2_control *ctrl)
  1087. {
  1088. struct si470x_device *radio = video_get_drvdata(video_devdata(file));
  1089. int retval = 0;
  1090. /* safety checks */
  1091. if (radio->disconnected) {
  1092. retval = -EIO;
  1093. goto done;
  1094. }
  1095. switch (ctrl->id) {
  1096. case V4L2_CID_AUDIO_VOLUME:
  1097. radio->registers[SYSCONFIG2] &= ~SYSCONFIG2_VOLUME;
  1098. radio->registers[SYSCONFIG2] |= ctrl->value;
  1099. retval = si470x_set_register(radio, SYSCONFIG2);
  1100. break;
  1101. case V4L2_CID_AUDIO_MUTE:
  1102. if (ctrl->value == 1)
  1103. radio->registers[POWERCFG] &= ~POWERCFG_DMUTE;
  1104. else
  1105. radio->registers[POWERCFG] |= POWERCFG_DMUTE;
  1106. retval = si470x_set_register(radio, POWERCFG);
  1107. break;
  1108. default:
  1109. retval = -EINVAL;
  1110. }
  1111. done:
  1112. if (retval < 0)
  1113. printk(KERN_WARNING DRIVER_NAME
  1114. ": set control failed with %d\n", retval);
  1115. return retval;
  1116. }
  1117. /*
  1118. * si470x_vidioc_g_audio - get audio attributes
  1119. */
  1120. static int si470x_vidioc_g_audio(struct file *file, void *priv,
  1121. struct v4l2_audio *audio)
  1122. {
  1123. int retval = 0;
  1124. /* safety checks */
  1125. if (audio->index != 0) {
  1126. retval = -EINVAL;
  1127. goto done;
  1128. }
  1129. strcpy(audio->name, "Radio");
  1130. audio->capability = V4L2_AUDCAP_STEREO;
  1131. done:
  1132. if (retval < 0)
  1133. printk(KERN_WARNING DRIVER_NAME
  1134. ": get audio failed with %d\n", retval);
  1135. return retval;
  1136. }
  1137. /*
  1138. * si470x_vidioc_s_audio - set audio attributes
  1139. */
  1140. static int si470x_vidioc_s_audio(struct file *file, void *priv,
  1141. struct v4l2_audio *audio)
  1142. {
  1143. int retval = 0;
  1144. /* safety checks */
  1145. if (audio->index != 0) {
  1146. retval = -EINVAL;
  1147. goto done;
  1148. }
  1149. done:
  1150. if (retval < 0)
  1151. printk(KERN_WARNING DRIVER_NAME
  1152. ": set audio failed with %d\n", retval);
  1153. return retval;
  1154. }
  1155. /*
  1156. * si470x_vidioc_g_tuner - get tuner attributes
  1157. */
  1158. static int si470x_vidioc_g_tuner(struct file *file, void *priv,
  1159. struct v4l2_tuner *tuner)
  1160. {
  1161. struct si470x_device *radio = video_get_drvdata(video_devdata(file));
  1162. int retval = 0;
  1163. /* safety checks */
  1164. if (radio->disconnected) {
  1165. retval = -EIO;
  1166. goto done;
  1167. }
  1168. if ((tuner->index != 0) && (tuner->type != V4L2_TUNER_RADIO)) {
  1169. retval = -EINVAL;
  1170. goto done;
  1171. }
  1172. retval = si470x_get_register(radio, STATUSRSSI);
  1173. if (retval < 0)
  1174. goto done;
  1175. strcpy(tuner->name, "FM");
  1176. switch (band) {
  1177. /* 0: 87.5 - 108 MHz (USA, Europe, default) */
  1178. default:
  1179. tuner->rangelow = 87.5 * FREQ_MUL;
  1180. tuner->rangehigh = 108 * FREQ_MUL;
  1181. break;
  1182. /* 1: 76 - 108 MHz (Japan wide band) */
  1183. case 1 :
  1184. tuner->rangelow = 76 * FREQ_MUL;
  1185. tuner->rangehigh = 108 * FREQ_MUL;
  1186. break;
  1187. /* 2: 76 - 90 MHz (Japan) */
  1188. case 2 :
  1189. tuner->rangelow = 76 * FREQ_MUL;
  1190. tuner->rangehigh = 90 * FREQ_MUL;
  1191. break;
  1192. };
  1193. tuner->rxsubchans = V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO;
  1194. tuner->capability = V4L2_TUNER_CAP_LOW;
  1195. /* Stereo indicator == Stereo (instead of Mono) */
  1196. if ((radio->registers[STATUSRSSI] & STATUSRSSI_ST) == 1)
  1197. tuner->audmode = V4L2_TUNER_MODE_STEREO;
  1198. else
  1199. tuner->audmode = V4L2_TUNER_MODE_MONO;
  1200. /* min is worst, max is best; signal:0..0xffff; rssi: 0..0xff */
  1201. tuner->signal = (radio->registers[STATUSRSSI] & STATUSRSSI_RSSI)
  1202. * 0x0101;
  1203. /* automatic frequency control: -1: freq to low, 1 freq to high */
  1204. /* AFCRL does only indicate that freq. differs, not if too low/high */
  1205. tuner->afc = (radio->registers[STATUSRSSI] & STATUSRSSI_AFCRL) ? 1 : 0;
  1206. done:
  1207. if (retval < 0)
  1208. printk(KERN_WARNING DRIVER_NAME
  1209. ": get tuner failed with %d\n", retval);
  1210. return retval;
  1211. }
  1212. /*
  1213. * si470x_vidioc_s_tuner - set tuner attributes
  1214. */
  1215. static int si470x_vidioc_s_tuner(struct file *file, void *priv,
  1216. struct v4l2_tuner *tuner)
  1217. {
  1218. struct si470x_device *radio = video_get_drvdata(video_devdata(file));
  1219. int retval = 0;
  1220. /* safety checks */
  1221. if (radio->disconnected) {
  1222. retval = -EIO;
  1223. goto done;
  1224. }
  1225. if ((tuner->index != 0) && (tuner->type != V4L2_TUNER_RADIO)) {
  1226. retval = -EINVAL;
  1227. goto done;
  1228. }
  1229. if (tuner->audmode == V4L2_TUNER_MODE_MONO)
  1230. radio->registers[POWERCFG] |= POWERCFG_MONO; /* force mono */
  1231. else
  1232. radio->registers[POWERCFG] &= ~POWERCFG_MONO; /* try stereo */
  1233. retval = si470x_set_register(radio, POWERCFG);
  1234. done:
  1235. if (retval < 0)
  1236. printk(KERN_WARNING DRIVER_NAME
  1237. ": set tuner failed with %d\n", retval);
  1238. return retval;
  1239. }
  1240. /*
  1241. * si470x_vidioc_g_frequency - get tuner or modulator radio frequency
  1242. */
  1243. static int si470x_vidioc_g_frequency(struct file *file, void *priv,
  1244. struct v4l2_frequency *freq)
  1245. {
  1246. struct si470x_device *radio = video_get_drvdata(video_devdata(file));
  1247. int retval = 0;
  1248. /* safety checks */
  1249. if (radio->disconnected) {
  1250. retval = -EIO;
  1251. goto done;
  1252. }
  1253. if ((freq->tuner != 0) && (freq->type != V4L2_TUNER_RADIO)) {
  1254. retval = -EINVAL;
  1255. goto done;
  1256. }
  1257. retval = si470x_get_freq(radio, &freq->frequency);
  1258. done:
  1259. if (retval < 0)
  1260. printk(KERN_WARNING DRIVER_NAME
  1261. ": get frequency failed with %d\n", retval);
  1262. return retval;
  1263. }
  1264. /*
  1265. * si470x_vidioc_s_frequency - set tuner or modulator radio frequency
  1266. */
  1267. static int si470x_vidioc_s_frequency(struct file *file, void *priv,
  1268. struct v4l2_frequency *freq)
  1269. {
  1270. struct si470x_device *radio = video_get_drvdata(video_devdata(file));
  1271. int retval = 0;
  1272. /* safety checks */
  1273. if (radio->disconnected) {
  1274. retval = -EIO;
  1275. goto done;
  1276. }
  1277. if ((freq->tuner != 0) && (freq->type != V4L2_TUNER_RADIO)) {
  1278. retval = -EINVAL;
  1279. goto done;
  1280. }
  1281. retval = si470x_set_freq(radio, freq->frequency);
  1282. done:
  1283. if (retval < 0)
  1284. printk(KERN_WARNING DRIVER_NAME
  1285. ": set frequency failed with %d\n", retval);
  1286. return retval;
  1287. }
  1288. /*
  1289. * si470x_vidioc_s_hw_freq_seek - set hardware frequency seek
  1290. */
  1291. static int si470x_vidioc_s_hw_freq_seek(struct file *file, void *priv,
  1292. struct v4l2_hw_freq_seek *seek)
  1293. {
  1294. struct si470x_device *radio = video_get_drvdata(video_devdata(file));
  1295. int retval = 0;
  1296. /* safety checks */
  1297. if (radio->disconnected) {
  1298. retval = -EIO;
  1299. goto done;
  1300. }
  1301. if ((seek->tuner != 0) && (seek->type != V4L2_TUNER_RADIO)) {
  1302. retval = -EINVAL;
  1303. goto done;
  1304. }
  1305. retval = si470x_set_seek(radio, seek->wrap_around, seek->seek_upward);
  1306. done:
  1307. if (retval < 0)
  1308. printk(KERN_WARNING DRIVER_NAME
  1309. ": set hardware frequency seek failed with %d\n",
  1310. retval);
  1311. return retval;
  1312. }
  1313. /*
  1314. * si470x_viddev_tamples - video device interface
  1315. */
  1316. static struct video_device si470x_viddev_template = {
  1317. .fops = &si470x_fops,
  1318. .name = DRIVER_NAME,
  1319. .type = VID_TYPE_TUNER,
  1320. .release = video_device_release,
  1321. .vidioc_querycap = si470x_vidioc_querycap,
  1322. .vidioc_g_input = si470x_vidioc_g_input,
  1323. .vidioc_s_input = si470x_vidioc_s_input,
  1324. .vidioc_queryctrl = si470x_vidioc_queryctrl,
  1325. .vidioc_g_ctrl = si470x_vidioc_g_ctrl,
  1326. .vidioc_s_ctrl = si470x_vidioc_s_ctrl,
  1327. .vidioc_g_audio = si470x_vidioc_g_audio,
  1328. .vidioc_s_audio = si470x_vidioc_s_audio,
  1329. .vidioc_g_tuner = si470x_vidioc_g_tuner,
  1330. .vidioc_s_tuner = si470x_vidioc_s_tuner,
  1331. .vidioc_g_frequency = si470x_vidioc_g_frequency,
  1332. .vidioc_s_frequency = si470x_vidioc_s_frequency,
  1333. .vidioc_s_hw_freq_seek = si470x_vidioc_s_hw_freq_seek,
  1334. .owner = THIS_MODULE,
  1335. };
  1336. /**************************************************************************
  1337. * USB Interface
  1338. **************************************************************************/
  1339. /*
  1340. * si470x_usb_driver_probe - probe for the device
  1341. */
  1342. static int si470x_usb_driver_probe(struct usb_interface *intf,
  1343. const struct usb_device_id *id)
  1344. {
  1345. struct si470x_device *radio;
  1346. int retval = 0;
  1347. /* private data allocation and initialization */
  1348. radio = kzalloc(sizeof(struct si470x_device), GFP_KERNEL);
  1349. if (!radio) {
  1350. retval = -ENOMEM;
  1351. goto err_initial;
  1352. }
  1353. radio->users = 0;
  1354. radio->disconnected = 0;
  1355. radio->usbdev = interface_to_usbdev(intf);
  1356. radio->intf = intf;
  1357. mutex_init(&radio->disconnect_lock);
  1358. mutex_init(&radio->lock);
  1359. /* video device allocation and initialization */
  1360. radio->videodev = video_device_alloc();
  1361. if (!radio->videodev) {
  1362. retval = -ENOMEM;
  1363. goto err_radio;
  1364. }
  1365. memcpy(radio->videodev, &si470x_viddev_template,
  1366. sizeof(si470x_viddev_template));
  1367. video_set_drvdata(radio->videodev, radio);
  1368. /* show some infos about the specific device */
  1369. if (si470x_get_all_registers(radio) < 0) {
  1370. retval = -EIO;
  1371. goto err_all;
  1372. }
  1373. printk(KERN_INFO DRIVER_NAME ": DeviceID=0x%4.4hx ChipID=0x%4.4hx\n",
  1374. radio->registers[DEVICEID], radio->registers[CHIPID]);
  1375. /* check if firmware is current */
  1376. if ((radio->registers[CHIPID] & CHIPID_FIRMWARE)
  1377. < RADIO_SW_VERSION_CURRENT) {
  1378. printk(KERN_WARNING DRIVER_NAME
  1379. ": This driver is known to work with "
  1380. "firmware version %hu,\n", RADIO_SW_VERSION_CURRENT);
  1381. printk(KERN_WARNING DRIVER_NAME
  1382. ": but the device has firmware version %hu.\n",
  1383. radio->registers[CHIPID] & CHIPID_FIRMWARE);
  1384. printk(KERN_WARNING DRIVER_NAME
  1385. ": If you have some trouble using this driver,\n");
  1386. printk(KERN_WARNING DRIVER_NAME
  1387. ": please report to V4L ML at "
  1388. "video4linux-list@redhat.com\n");
  1389. }
  1390. /* set initial frequency */
  1391. si470x_set_freq(radio, 87.5 * FREQ_MUL); /* available in all regions */
  1392. /* rds buffer allocation */
  1393. radio->buf_size = rds_buf * 3;
  1394. radio->buffer = kmalloc(radio->buf_size, GFP_KERNEL);
  1395. if (!radio->buffer) {
  1396. retval = -EIO;
  1397. goto err_all;
  1398. }
  1399. /* rds buffer configuration */
  1400. radio->wr_index = 0;
  1401. radio->rd_index = 0;
  1402. init_waitqueue_head(&radio->read_queue);
  1403. /* prepare rds work function */
  1404. INIT_DELAYED_WORK(&radio->work, si470x_work);
  1405. /* register video device */
  1406. if (video_register_device(radio->videodev, VFL_TYPE_RADIO, radio_nr)) {
  1407. retval = -EIO;
  1408. printk(KERN_WARNING DRIVER_NAME
  1409. ": Could not register video device\n");
  1410. goto err_all;
  1411. }
  1412. usb_set_intfdata(intf, radio);
  1413. return 0;
  1414. err_all:
  1415. video_device_release(radio->videodev);
  1416. kfree(radio->buffer);
  1417. err_radio:
  1418. kfree(radio);
  1419. err_initial:
  1420. return retval;
  1421. }
  1422. /*
  1423. * si470x_usb_driver_suspend - suspend the device
  1424. */
  1425. static int si470x_usb_driver_suspend(struct usb_interface *intf,
  1426. pm_message_t message)
  1427. {
  1428. struct si470x_device *radio = usb_get_intfdata(intf);
  1429. printk(KERN_INFO DRIVER_NAME ": suspending now...\n");
  1430. cancel_delayed_work_sync(&radio->work);
  1431. return 0;
  1432. }
  1433. /*
  1434. * si470x_usb_driver_resume - resume the device
  1435. */
  1436. static int si470x_usb_driver_resume(struct usb_interface *intf)
  1437. {
  1438. struct si470x_device *radio = usb_get_intfdata(intf);
  1439. printk(KERN_INFO DRIVER_NAME ": resuming now...\n");
  1440. mutex_lock(&radio->lock);
  1441. if (radio->users && radio->registers[SYSCONFIG1] & SYSCONFIG1_RDS)
  1442. schedule_delayed_work(&radio->work,
  1443. msecs_to_jiffies(rds_poll_time));
  1444. mutex_unlock(&radio->lock);
  1445. return 0;
  1446. }
  1447. /*
  1448. * si470x_usb_driver_disconnect - disconnect the device
  1449. */
  1450. static void si470x_usb_driver_disconnect(struct usb_interface *intf)
  1451. {
  1452. struct si470x_device *radio = usb_get_intfdata(intf);
  1453. mutex_lock(&radio->disconnect_lock);
  1454. radio->disconnected = 1;
  1455. cancel_delayed_work_sync(&radio->work);
  1456. usb_set_intfdata(intf, NULL);
  1457. if (radio->users == 0) {
  1458. video_unregister_device(radio->videodev);
  1459. kfree(radio->buffer);
  1460. kfree(radio);
  1461. }
  1462. mutex_unlock(&radio->disconnect_lock);
  1463. }
  1464. /*
  1465. * si470x_usb_driver - usb driver interface
  1466. */
  1467. static struct usb_driver si470x_usb_driver = {
  1468. .name = DRIVER_NAME,
  1469. .probe = si470x_usb_driver_probe,
  1470. .disconnect = si470x_usb_driver_disconnect,
  1471. .suspend = si470x_usb_driver_suspend,
  1472. .resume = si470x_usb_driver_resume,
  1473. .id_table = si470x_usb_driver_id_table,
  1474. .supports_autosuspend = 1,
  1475. };
  1476. /**************************************************************************
  1477. * Module Interface
  1478. **************************************************************************/
  1479. /*
  1480. * si470x_module_init - module init
  1481. */
  1482. static int __init si470x_module_init(void)
  1483. {
  1484. printk(KERN_INFO DRIVER_DESC ", Version " DRIVER_VERSION "\n");
  1485. return usb_register(&si470x_usb_driver);
  1486. }
  1487. /*
  1488. * si470x_module_exit - module exit
  1489. */
  1490. static void __exit si470x_module_exit(void)
  1491. {
  1492. usb_deregister(&si470x_usb_driver);
  1493. }
  1494. module_init(si470x_module_init);
  1495. module_exit(si470x_module_exit);
  1496. MODULE_LICENSE("GPL");
  1497. MODULE_AUTHOR(DRIVER_AUTHOR);
  1498. MODULE_DESCRIPTION(DRIVER_DESC);
  1499. MODULE_VERSION(DRIVER_VERSION);