radio-timb.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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/version.h>
  19. #include <linux/io.h>
  20. #include <media/v4l2-ioctl.h>
  21. #include <media/v4l2-device.h>
  22. #include <linux/platform_device.h>
  23. #include <linux/interrupt.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. };
  34. static int timbradio_vidioc_querycap(struct file *file, void *priv,
  35. struct v4l2_capability *v)
  36. {
  37. strlcpy(v->driver, DRIVER_NAME, sizeof(v->driver));
  38. strlcpy(v->card, "Timberdale Radio", sizeof(v->card));
  39. snprintf(v->bus_info, sizeof(v->bus_info), "platform:"DRIVER_NAME);
  40. v->version = KERNEL_VERSION(0, 0, 1);
  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. .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. strlcpy(tr->video_dev.name, "Timberdale Radio",
  145. sizeof(tr->video_dev.name));
  146. tr->video_dev.fops = &timbradio_fops;
  147. tr->video_dev.ioctl_ops = &timbradio_ioctl_ops;
  148. tr->video_dev.release = video_device_release_empty;
  149. tr->video_dev.minor = -1;
  150. strlcpy(tr->v4l2_dev.name, DRIVER_NAME, sizeof(tr->v4l2_dev.name));
  151. err = v4l2_device_register(NULL, &tr->v4l2_dev);
  152. if (err)
  153. goto err_v4l2_dev;
  154. tr->video_dev.v4l2_dev = &tr->v4l2_dev;
  155. err = video_register_device(&tr->video_dev, VFL_TYPE_RADIO, -1);
  156. if (err) {
  157. dev_err(&pdev->dev, "Error reg video\n");
  158. goto err_video_req;
  159. }
  160. video_set_drvdata(&tr->video_dev, tr);
  161. platform_set_drvdata(pdev, tr);
  162. return 0;
  163. err_video_req:
  164. video_device_release_empty(&tr->video_dev);
  165. v4l2_device_unregister(&tr->v4l2_dev);
  166. err_v4l2_dev:
  167. kfree(tr);
  168. err:
  169. dev_err(&pdev->dev, "Failed to register: %d\n", err);
  170. return err;
  171. }
  172. static int __devexit timbradio_remove(struct platform_device *pdev)
  173. {
  174. struct timbradio *tr = platform_get_drvdata(pdev);
  175. video_unregister_device(&tr->video_dev);
  176. video_device_release_empty(&tr->video_dev);
  177. v4l2_device_unregister(&tr->v4l2_dev);
  178. kfree(tr);
  179. return 0;
  180. }
  181. static struct platform_driver timbradio_platform_driver = {
  182. .driver = {
  183. .name = DRIVER_NAME,
  184. .owner = THIS_MODULE,
  185. },
  186. .probe = timbradio_probe,
  187. .remove = timbradio_remove,
  188. };
  189. /*--------------------------------------------------------------------------*/
  190. static int __init timbradio_init(void)
  191. {
  192. return platform_driver_register(&timbradio_platform_driver);
  193. }
  194. static void __exit timbradio_exit(void)
  195. {
  196. platform_driver_unregister(&timbradio_platform_driver);
  197. }
  198. module_init(timbradio_init);
  199. module_exit(timbradio_exit);
  200. MODULE_DESCRIPTION("Timberdale Radio driver");
  201. MODULE_AUTHOR("Mocean Laboratories <info@mocean-labs.com>");
  202. MODULE_LICENSE("GPL v2");
  203. MODULE_ALIAS("platform:"DRIVER_NAME);