radio-si470x.c 48 KB

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