radio-miropcm20.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. /* Miro PCM20 radio driver for Linux radio support
  2. * (c) 1998 Ruurd Reitsma <R.A.Reitsma@wbmt.tudelft.nl>
  3. * Thanks to Norberto Pellici for the ACI device interface specification
  4. * The API part is based on the radiotrack driver by M. Kirkwood
  5. * This driver relies on the aci mixer provided by the snd-miro
  6. * ALSA driver.
  7. * Look there for further info...
  8. */
  9. /* What ever you think about the ACI, version 0x07 is not very well!
  10. * I can't get frequency, 'tuner status', 'tuner flags' or mute/mono
  11. * conditions... Robert
  12. */
  13. #include <linux/module.h>
  14. #include <linux/init.h>
  15. #include <linux/videodev2.h>
  16. #include <media/v4l2-device.h>
  17. #include <media/v4l2-ioctl.h>
  18. #include <sound/aci.h>
  19. static int radio_nr = -1;
  20. module_param(radio_nr, int, 0);
  21. MODULE_PARM_DESC(radio_nr, "Set radio device number (/dev/radioX). Default: -1 (autodetect)");
  22. static int mono;
  23. module_param(mono, bool, 0);
  24. MODULE_PARM_DESC(mono, "Force tuner into mono mode.");
  25. struct pcm20 {
  26. struct v4l2_device v4l2_dev;
  27. struct video_device vdev;
  28. unsigned long freq;
  29. int muted;
  30. struct snd_miro_aci *aci;
  31. };
  32. static struct pcm20 pcm20_card = {
  33. .freq = 87*16000,
  34. .muted = 1,
  35. };
  36. static int pcm20_mute(struct pcm20 *dev, unsigned char mute)
  37. {
  38. dev->muted = mute;
  39. return snd_aci_cmd(dev->aci, ACI_SET_TUNERMUTE, mute, -1);
  40. }
  41. static int pcm20_stereo(struct pcm20 *dev, unsigned char stereo)
  42. {
  43. return snd_aci_cmd(dev->aci, ACI_SET_TUNERMONO, !stereo, -1);
  44. }
  45. static int pcm20_setfreq(struct pcm20 *dev, unsigned long freq)
  46. {
  47. unsigned char freql;
  48. unsigned char freqh;
  49. struct snd_miro_aci *aci = dev->aci;
  50. dev->freq = freq;
  51. freq /= 160;
  52. if (!(aci->aci_version == 0x07 || aci->aci_version >= 0xb0))
  53. freq /= 10; /* I don't know exactly which version
  54. * needs this hack */
  55. freql = freq & 0xff;
  56. freqh = freq >> 8;
  57. pcm20_stereo(dev, !mono);
  58. return snd_aci_cmd(aci, ACI_WRITE_TUNE, freql, freqh);
  59. }
  60. static const struct v4l2_file_operations pcm20_fops = {
  61. .owner = THIS_MODULE,
  62. .ioctl = video_ioctl2,
  63. };
  64. static int vidioc_querycap(struct file *file, void *priv,
  65. struct v4l2_capability *v)
  66. {
  67. strlcpy(v->driver, "Miro PCM20", sizeof(v->driver));
  68. strlcpy(v->card, "Miro PCM20", sizeof(v->card));
  69. strlcpy(v->bus_info, "ISA", sizeof(v->bus_info));
  70. v->version = 0x1;
  71. v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
  72. return 0;
  73. }
  74. static int vidioc_g_tuner(struct file *file, void *priv,
  75. struct v4l2_tuner *v)
  76. {
  77. if (v->index) /* Only 1 tuner */
  78. return -EINVAL;
  79. strlcpy(v->name, "FM", sizeof(v->name));
  80. v->type = V4L2_TUNER_RADIO;
  81. v->rangelow = 87*16000;
  82. v->rangehigh = 108*16000;
  83. v->signal = 0xffff;
  84. v->rxsubchans = V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO;
  85. v->capability = V4L2_TUNER_CAP_LOW;
  86. v->audmode = V4L2_TUNER_MODE_MONO;
  87. return 0;
  88. }
  89. static int vidioc_s_tuner(struct file *file, void *priv,
  90. struct v4l2_tuner *v)
  91. {
  92. return v->index ? -EINVAL : 0;
  93. }
  94. static int vidioc_g_frequency(struct file *file, void *priv,
  95. struct v4l2_frequency *f)
  96. {
  97. struct pcm20 *dev = video_drvdata(file);
  98. if (f->tuner != 0)
  99. return -EINVAL;
  100. f->type = V4L2_TUNER_RADIO;
  101. f->frequency = dev->freq;
  102. return 0;
  103. }
  104. static int vidioc_s_frequency(struct file *file, void *priv,
  105. struct v4l2_frequency *f)
  106. {
  107. struct pcm20 *dev = video_drvdata(file);
  108. if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO)
  109. return -EINVAL;
  110. dev->freq = f->frequency;
  111. pcm20_setfreq(dev, f->frequency);
  112. return 0;
  113. }
  114. static int vidioc_queryctrl(struct file *file, void *priv,
  115. struct v4l2_queryctrl *qc)
  116. {
  117. switch (qc->id) {
  118. case V4L2_CID_AUDIO_MUTE:
  119. return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1);
  120. }
  121. return -EINVAL;
  122. }
  123. static int vidioc_g_ctrl(struct file *file, void *priv,
  124. struct v4l2_control *ctrl)
  125. {
  126. struct pcm20 *dev = video_drvdata(file);
  127. switch (ctrl->id) {
  128. case V4L2_CID_AUDIO_MUTE:
  129. ctrl->value = dev->muted;
  130. break;
  131. default:
  132. return -EINVAL;
  133. }
  134. return 0;
  135. }
  136. static int vidioc_s_ctrl(struct file *file, void *priv,
  137. struct v4l2_control *ctrl)
  138. {
  139. struct pcm20 *dev = video_drvdata(file);
  140. switch (ctrl->id) {
  141. case V4L2_CID_AUDIO_MUTE:
  142. pcm20_mute(dev, ctrl->value);
  143. break;
  144. default:
  145. return -EINVAL;
  146. }
  147. return 0;
  148. }
  149. static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
  150. {
  151. *i = 0;
  152. return 0;
  153. }
  154. static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
  155. {
  156. return i ? -EINVAL : 0;
  157. }
  158. static int vidioc_g_audio(struct file *file, void *priv,
  159. struct v4l2_audio *a)
  160. {
  161. a->index = 0;
  162. strlcpy(a->name, "Radio", sizeof(a->name));
  163. a->capability = V4L2_AUDCAP_STEREO;
  164. return 0;
  165. }
  166. static int vidioc_s_audio(struct file *file, void *priv,
  167. struct v4l2_audio *a)
  168. {
  169. return a->index ? -EINVAL : 0;
  170. }
  171. static const struct v4l2_ioctl_ops pcm20_ioctl_ops = {
  172. .vidioc_querycap = vidioc_querycap,
  173. .vidioc_g_tuner = vidioc_g_tuner,
  174. .vidioc_s_tuner = vidioc_s_tuner,
  175. .vidioc_g_frequency = vidioc_g_frequency,
  176. .vidioc_s_frequency = vidioc_s_frequency,
  177. .vidioc_queryctrl = vidioc_queryctrl,
  178. .vidioc_g_ctrl = vidioc_g_ctrl,
  179. .vidioc_s_ctrl = vidioc_s_ctrl,
  180. .vidioc_g_audio = vidioc_g_audio,
  181. .vidioc_s_audio = vidioc_s_audio,
  182. .vidioc_g_input = vidioc_g_input,
  183. .vidioc_s_input = vidioc_s_input,
  184. };
  185. static int __init pcm20_init(void)
  186. {
  187. struct pcm20 *dev = &pcm20_card;
  188. struct v4l2_device *v4l2_dev = &dev->v4l2_dev;
  189. int res;
  190. dev->aci = snd_aci_get_aci();
  191. if (dev->aci == NULL) {
  192. v4l2_err(v4l2_dev,
  193. "you must load the snd-miro driver first!\n");
  194. return -ENODEV;
  195. }
  196. strlcpy(v4l2_dev->name, "miropcm20", sizeof(v4l2_dev->name));
  197. res = v4l2_device_register(NULL, v4l2_dev);
  198. if (res < 0) {
  199. v4l2_err(v4l2_dev, "could not register v4l2_device\n");
  200. return -EINVAL;
  201. }
  202. strlcpy(dev->vdev.name, v4l2_dev->name, sizeof(dev->vdev.name));
  203. dev->vdev.v4l2_dev = v4l2_dev;
  204. dev->vdev.fops = &pcm20_fops;
  205. dev->vdev.ioctl_ops = &pcm20_ioctl_ops;
  206. dev->vdev.release = video_device_release_empty;
  207. video_set_drvdata(&dev->vdev, dev);
  208. if (video_register_device(&dev->vdev, VFL_TYPE_RADIO, radio_nr) < 0)
  209. goto fail;
  210. v4l2_info(v4l2_dev, "Mirosound PCM20 Radio tuner\n");
  211. return 0;
  212. fail:
  213. v4l2_device_unregister(v4l2_dev);
  214. return -EINVAL;
  215. }
  216. MODULE_AUTHOR("Ruurd Reitsma, Krzysztof Helt");
  217. MODULE_DESCRIPTION("A driver for the Miro PCM20 radio card.");
  218. MODULE_LICENSE("GPL");
  219. static void __exit pcm20_cleanup(void)
  220. {
  221. struct pcm20 *dev = &pcm20_card;
  222. video_unregister_device(&dev->vdev);
  223. v4l2_device_unregister(&dev->v4l2_dev);
  224. }
  225. module_init(pcm20_init);
  226. module_exit(pcm20_cleanup);