radio-timb.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /*
  2. * radio-timb.c Timberdale FPGA Radio driver
  3. * Copyright (c) 2009 Intel Corporation
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. #include <linux/io.h>
  19. #include <media/v4l2-ioctl.h>
  20. #include <media/v4l2-device.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/slab.h>
  24. #include <linux/i2c.h>
  25. #include <media/timb_radio.h>
  26. #define DRIVER_NAME "timb-radio"
  27. struct timbradio {
  28. struct timb_radio_platform_data pdata;
  29. struct v4l2_subdev *sd_tuner;
  30. struct v4l2_subdev *sd_dsp;
  31. struct video_device video_dev;
  32. struct v4l2_device v4l2_dev;
  33. struct mutex lock;
  34. };
  35. static int timbradio_vidioc_querycap(struct file *file, void *priv,
  36. struct v4l2_capability *v)
  37. {
  38. strlcpy(v->driver, DRIVER_NAME, sizeof(v->driver));
  39. strlcpy(v->card, "Timberdale Radio", sizeof(v->card));
  40. snprintf(v->bus_info, sizeof(v->bus_info), "platform:"DRIVER_NAME);
  41. v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
  42. return 0;
  43. }
  44. static int timbradio_vidioc_g_tuner(struct file *file, void *priv,
  45. struct v4l2_tuner *v)
  46. {
  47. struct timbradio *tr = video_drvdata(file);
  48. return v4l2_subdev_call(tr->sd_tuner, tuner, g_tuner, v);
  49. }
  50. static int timbradio_vidioc_s_tuner(struct file *file, void *priv,
  51. struct v4l2_tuner *v)
  52. {
  53. struct timbradio *tr = video_drvdata(file);
  54. return v4l2_subdev_call(tr->sd_tuner, tuner, s_tuner, v);
  55. }
  56. static int timbradio_vidioc_g_input(struct file *filp, void *priv,
  57. unsigned int *i)
  58. {
  59. *i = 0;
  60. return 0;
  61. }
  62. static int timbradio_vidioc_s_input(struct file *filp, void *priv,
  63. unsigned int i)
  64. {
  65. return i ? -EINVAL : 0;
  66. }
  67. static int timbradio_vidioc_g_audio(struct file *file, void *priv,
  68. struct v4l2_audio *a)
  69. {
  70. a->index = 0;
  71. strlcpy(a->name, "Radio", sizeof(a->name));
  72. a->capability = V4L2_AUDCAP_STEREO;
  73. return 0;
  74. }
  75. static int timbradio_vidioc_s_audio(struct file *file, void *priv,
  76. struct v4l2_audio *a)
  77. {
  78. return a->index ? -EINVAL : 0;
  79. }
  80. static int timbradio_vidioc_s_frequency(struct file *file, void *priv,
  81. struct v4l2_frequency *f)
  82. {
  83. struct timbradio *tr = video_drvdata(file);
  84. return v4l2_subdev_call(tr->sd_tuner, tuner, s_frequency, f);
  85. }
  86. static int timbradio_vidioc_g_frequency(struct file *file, void *priv,
  87. struct v4l2_frequency *f)
  88. {
  89. struct timbradio *tr = video_drvdata(file);
  90. return v4l2_subdev_call(tr->sd_tuner, tuner, g_frequency, f);
  91. }
  92. static int timbradio_vidioc_queryctrl(struct file *file, void *priv,
  93. struct v4l2_queryctrl *qc)
  94. {
  95. struct timbradio *tr = video_drvdata(file);
  96. return v4l2_subdev_call(tr->sd_dsp, core, queryctrl, qc);
  97. }
  98. static int timbradio_vidioc_g_ctrl(struct file *file, void *priv,
  99. struct v4l2_control *ctrl)
  100. {
  101. struct timbradio *tr = video_drvdata(file);
  102. return v4l2_subdev_call(tr->sd_dsp, core, g_ctrl, ctrl);
  103. }
  104. static int timbradio_vidioc_s_ctrl(struct file *file, void *priv,
  105. struct v4l2_control *ctrl)
  106. {
  107. struct timbradio *tr = video_drvdata(file);
  108. return v4l2_subdev_call(tr->sd_dsp, core, s_ctrl, ctrl);
  109. }
  110. static const struct v4l2_ioctl_ops timbradio_ioctl_ops = {
  111. .vidioc_querycap = timbradio_vidioc_querycap,
  112. .vidioc_g_tuner = timbradio_vidioc_g_tuner,
  113. .vidioc_s_tuner = timbradio_vidioc_s_tuner,
  114. .vidioc_g_frequency = timbradio_vidioc_g_frequency,
  115. .vidioc_s_frequency = timbradio_vidioc_s_frequency,
  116. .vidioc_g_input = timbradio_vidioc_g_input,
  117. .vidioc_s_input = timbradio_vidioc_s_input,
  118. .vidioc_g_audio = timbradio_vidioc_g_audio,
  119. .vidioc_s_audio = timbradio_vidioc_s_audio,
  120. .vidioc_queryctrl = timbradio_vidioc_queryctrl,
  121. .vidioc_g_ctrl = timbradio_vidioc_g_ctrl,
  122. .vidioc_s_ctrl = timbradio_vidioc_s_ctrl
  123. };
  124. static const struct v4l2_file_operations timbradio_fops = {
  125. .owner = THIS_MODULE,
  126. .unlocked_ioctl = video_ioctl2,
  127. };
  128. static int __devinit timbradio_probe(struct platform_device *pdev)
  129. {
  130. struct timb_radio_platform_data *pdata = pdev->dev.platform_data;
  131. struct timbradio *tr;
  132. int err;
  133. if (!pdata) {
  134. dev_err(&pdev->dev, "Platform data missing\n");
  135. err = -EINVAL;
  136. goto err;
  137. }
  138. tr = kzalloc(sizeof(*tr), GFP_KERNEL);
  139. if (!tr) {
  140. err = -ENOMEM;
  141. goto err;
  142. }
  143. tr->pdata = *pdata;
  144. mutex_init(&tr->lock);
  145. strlcpy(tr->video_dev.name, "Timberdale Radio",
  146. sizeof(tr->video_dev.name));
  147. tr->video_dev.fops = &timbradio_fops;
  148. tr->video_dev.ioctl_ops = &timbradio_ioctl_ops;
  149. tr->video_dev.release = video_device_release_empty;
  150. tr->video_dev.minor = -1;
  151. tr->video_dev.lock = &tr->lock;
  152. strlcpy(tr->v4l2_dev.name, DRIVER_NAME, sizeof(tr->v4l2_dev.name));
  153. err = v4l2_device_register(NULL, &tr->v4l2_dev);
  154. if (err)
  155. goto err_v4l2_dev;
  156. tr->video_dev.v4l2_dev = &tr->v4l2_dev;
  157. err = video_register_device(&tr->video_dev, VFL_TYPE_RADIO, -1);
  158. if (err) {
  159. dev_err(&pdev->dev, "Error reg video\n");
  160. goto err_video_req;
  161. }
  162. video_set_drvdata(&tr->video_dev, tr);
  163. platform_set_drvdata(pdev, tr);
  164. return 0;
  165. err_video_req:
  166. video_device_release_empty(&tr->video_dev);
  167. v4l2_device_unregister(&tr->v4l2_dev);
  168. err_v4l2_dev:
  169. kfree(tr);
  170. err:
  171. dev_err(&pdev->dev, "Failed to register: %d\n", err);
  172. return err;
  173. }
  174. static int __devexit timbradio_remove(struct platform_device *pdev)
  175. {
  176. struct timbradio *tr = platform_get_drvdata(pdev);
  177. video_unregister_device(&tr->video_dev);
  178. video_device_release_empty(&tr->video_dev);
  179. v4l2_device_unregister(&tr->v4l2_dev);
  180. kfree(tr);
  181. return 0;
  182. }
  183. static struct platform_driver timbradio_platform_driver = {
  184. .driver = {
  185. .name = DRIVER_NAME,
  186. .owner = THIS_MODULE,
  187. },
  188. .probe = timbradio_probe,
  189. .remove = timbradio_remove,
  190. };
  191. /*--------------------------------------------------------------------------*/
  192. static int __init timbradio_init(void)
  193. {
  194. return platform_driver_register(&timbradio_platform_driver);
  195. }
  196. static void __exit timbradio_exit(void)
  197. {
  198. platform_driver_unregister(&timbradio_platform_driver);
  199. }
  200. module_init(timbradio_init);
  201. module_exit(timbradio_exit);
  202. MODULE_DESCRIPTION("Timberdale Radio driver");
  203. MODULE_AUTHOR("Mocean Laboratories <info@mocean-labs.com>");
  204. MODULE_LICENSE("GPL v2");
  205. MODULE_VERSION("0.0.2");
  206. MODULE_ALIAS("platform:"DRIVER_NAME);