radio-miropcm20.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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 bool 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. struct mutex lock;
  32. };
  33. static struct pcm20 pcm20_card = {
  34. .freq = 87*16000,
  35. .muted = 1,
  36. };
  37. static int pcm20_mute(struct pcm20 *dev, unsigned char mute)
  38. {
  39. dev->muted = mute;
  40. return snd_aci_cmd(dev->aci, ACI_SET_TUNERMUTE, mute, -1);
  41. }
  42. static int pcm20_stereo(struct pcm20 *dev, unsigned char stereo)
  43. {
  44. return snd_aci_cmd(dev->aci, ACI_SET_TUNERMONO, !stereo, -1);
  45. }
  46. static int pcm20_setfreq(struct pcm20 *dev, unsigned long freq)
  47. {
  48. unsigned char freql;
  49. unsigned char freqh;
  50. struct snd_miro_aci *aci = dev->aci;
  51. dev->freq = freq;
  52. freq /= 160;
  53. if (!(aci->aci_version == 0x07 || aci->aci_version >= 0xb0))
  54. freq /= 10; /* I don't know exactly which version
  55. * needs this hack */
  56. freql = freq & 0xff;
  57. freqh = freq >> 8;
  58. pcm20_stereo(dev, !mono);
  59. return snd_aci_cmd(aci, ACI_WRITE_TUNE, freql, freqh);
  60. }
  61. static const struct v4l2_file_operations pcm20_fops = {
  62. .owner = THIS_MODULE,
  63. .unlocked_ioctl = video_ioctl2,
  64. };
  65. static int vidioc_querycap(struct file *file, void *priv,
  66. struct v4l2_capability *v)
  67. {
  68. struct pcm20 *dev = video_drvdata(file);
  69. strlcpy(v->driver, "Miro PCM20", sizeof(v->driver));
  70. strlcpy(v->card, "Miro PCM20", sizeof(v->card));
  71. snprintf(v->bus_info, sizeof(v->bus_info), "ISA:%s", dev->v4l2_dev.name);
  72. v->device_caps = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
  73. v->capabilities = v->device_caps | V4L2_CAP_DEVICE_CAPS;
  74. return 0;
  75. }
  76. static int vidioc_g_tuner(struct file *file, void *priv,
  77. struct v4l2_tuner *v)
  78. {
  79. if (v->index) /* Only 1 tuner */
  80. return -EINVAL;
  81. strlcpy(v->name, "FM", sizeof(v->name));
  82. v->type = V4L2_TUNER_RADIO;
  83. v->rangelow = 87*16000;
  84. v->rangehigh = 108*16000;
  85. v->signal = 0xffff;
  86. v->rxsubchans = V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO;
  87. v->capability = V4L2_TUNER_CAP_LOW;
  88. v->audmode = V4L2_TUNER_MODE_MONO;
  89. return 0;
  90. }
  91. static int vidioc_s_tuner(struct file *file, void *priv,
  92. struct v4l2_tuner *v)
  93. {
  94. return v->index ? -EINVAL : 0;
  95. }
  96. static int vidioc_g_frequency(struct file *file, void *priv,
  97. struct v4l2_frequency *f)
  98. {
  99. struct pcm20 *dev = video_drvdata(file);
  100. if (f->tuner != 0)
  101. return -EINVAL;
  102. f->type = V4L2_TUNER_RADIO;
  103. f->frequency = dev->freq;
  104. return 0;
  105. }
  106. static int vidioc_s_frequency(struct file *file, void *priv,
  107. struct v4l2_frequency *f)
  108. {
  109. struct pcm20 *dev = video_drvdata(file);
  110. if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO)
  111. return -EINVAL;
  112. dev->freq = f->frequency;
  113. pcm20_setfreq(dev, f->frequency);
  114. return 0;
  115. }
  116. static int vidioc_queryctrl(struct file *file, void *priv,
  117. struct v4l2_queryctrl *qc)
  118. {
  119. switch (qc->id) {
  120. case V4L2_CID_AUDIO_MUTE:
  121. return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1);
  122. }
  123. return -EINVAL;
  124. }
  125. static int vidioc_g_ctrl(struct file *file, void *priv,
  126. struct v4l2_control *ctrl)
  127. {
  128. struct pcm20 *dev = video_drvdata(file);
  129. switch (ctrl->id) {
  130. case V4L2_CID_AUDIO_MUTE:
  131. ctrl->value = dev->muted;
  132. break;
  133. default:
  134. return -EINVAL;
  135. }
  136. return 0;
  137. }
  138. static int vidioc_s_ctrl(struct file *file, void *priv,
  139. struct v4l2_control *ctrl)
  140. {
  141. struct pcm20 *dev = video_drvdata(file);
  142. switch (ctrl->id) {
  143. case V4L2_CID_AUDIO_MUTE:
  144. pcm20_mute(dev, ctrl->value);
  145. break;
  146. default:
  147. return -EINVAL;
  148. }
  149. return 0;
  150. }
  151. static const struct v4l2_ioctl_ops pcm20_ioctl_ops = {
  152. .vidioc_querycap = vidioc_querycap,
  153. .vidioc_g_tuner = vidioc_g_tuner,
  154. .vidioc_s_tuner = vidioc_s_tuner,
  155. .vidioc_g_frequency = vidioc_g_frequency,
  156. .vidioc_s_frequency = vidioc_s_frequency,
  157. .vidioc_queryctrl = vidioc_queryctrl,
  158. .vidioc_g_ctrl = vidioc_g_ctrl,
  159. .vidioc_s_ctrl = vidioc_s_ctrl,
  160. };
  161. static int __init pcm20_init(void)
  162. {
  163. struct pcm20 *dev = &pcm20_card;
  164. struct v4l2_device *v4l2_dev = &dev->v4l2_dev;
  165. int res;
  166. dev->aci = snd_aci_get_aci();
  167. if (dev->aci == NULL) {
  168. v4l2_err(v4l2_dev,
  169. "you must load the snd-miro driver first!\n");
  170. return -ENODEV;
  171. }
  172. strlcpy(v4l2_dev->name, "radio-miropcm20", sizeof(v4l2_dev->name));
  173. mutex_init(&dev->lock);
  174. res = v4l2_device_register(NULL, v4l2_dev);
  175. if (res < 0) {
  176. v4l2_err(v4l2_dev, "could not register v4l2_device\n");
  177. return -EINVAL;
  178. }
  179. strlcpy(dev->vdev.name, v4l2_dev->name, sizeof(dev->vdev.name));
  180. dev->vdev.v4l2_dev = v4l2_dev;
  181. dev->vdev.fops = &pcm20_fops;
  182. dev->vdev.ioctl_ops = &pcm20_ioctl_ops;
  183. dev->vdev.release = video_device_release_empty;
  184. dev->vdev.lock = &dev->lock;
  185. video_set_drvdata(&dev->vdev, dev);
  186. if (video_register_device(&dev->vdev, VFL_TYPE_RADIO, radio_nr) < 0)
  187. goto fail;
  188. v4l2_info(v4l2_dev, "Mirosound PCM20 Radio tuner\n");
  189. return 0;
  190. fail:
  191. v4l2_device_unregister(v4l2_dev);
  192. return -EINVAL;
  193. }
  194. MODULE_AUTHOR("Ruurd Reitsma, Krzysztof Helt");
  195. MODULE_DESCRIPTION("A driver for the Miro PCM20 radio card.");
  196. MODULE_LICENSE("GPL");
  197. static void __exit pcm20_cleanup(void)
  198. {
  199. struct pcm20 *dev = &pcm20_card;
  200. video_unregister_device(&dev->vdev);
  201. v4l2_device_unregister(&dev->v4l2_dev);
  202. }
  203. module_init(pcm20_init);
  204. module_exit(pcm20_cleanup);