radio-timb.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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 <linux/module.h>
  26. #include <media/timb_radio.h>
  27. #define DRIVER_NAME "timb-radio"
  28. struct timbradio {
  29. struct timb_radio_platform_data pdata;
  30. struct v4l2_subdev *sd_tuner;
  31. struct v4l2_subdev *sd_dsp;
  32. struct video_device video_dev;
  33. struct v4l2_device v4l2_dev;
  34. struct mutex lock;
  35. };
  36. static int timbradio_vidioc_querycap(struct file *file, void *priv,
  37. struct v4l2_capability *v)
  38. {
  39. strlcpy(v->driver, DRIVER_NAME, sizeof(v->driver));
  40. strlcpy(v->card, "Timberdale Radio", sizeof(v->card));
  41. snprintf(v->bus_info, sizeof(v->bus_info), "platform:"DRIVER_NAME);
  42. v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
  43. return 0;
  44. }
  45. static int timbradio_vidioc_g_tuner(struct file *file, void *priv,
  46. struct v4l2_tuner *v)
  47. {
  48. struct timbradio *tr = video_drvdata(file);
  49. return v4l2_subdev_call(tr->sd_tuner, tuner, g_tuner, v);
  50. }
  51. static int timbradio_vidioc_s_tuner(struct file *file, void *priv,
  52. struct v4l2_tuner *v)
  53. {
  54. struct timbradio *tr = video_drvdata(file);
  55. return v4l2_subdev_call(tr->sd_tuner, tuner, s_tuner, v);
  56. }
  57. static int timbradio_vidioc_g_input(struct file *filp, void *priv,
  58. unsigned int *i)
  59. {
  60. *i = 0;
  61. return 0;
  62. }
  63. static int timbradio_vidioc_s_input(struct file *filp, void *priv,
  64. unsigned int i)
  65. {
  66. return i ? -EINVAL : 0;
  67. }
  68. static int timbradio_vidioc_g_audio(struct file *file, void *priv,
  69. struct v4l2_audio *a)
  70. {
  71. a->index = 0;
  72. strlcpy(a->name, "Radio", sizeof(a->name));
  73. a->capability = V4L2_AUDCAP_STEREO;
  74. return 0;
  75. }
  76. static int timbradio_vidioc_s_audio(struct file *file, void *priv,
  77. struct v4l2_audio *a)
  78. {
  79. return a->index ? -EINVAL : 0;
  80. }
  81. static int timbradio_vidioc_s_frequency(struct file *file, void *priv,
  82. struct v4l2_frequency *f)
  83. {
  84. struct timbradio *tr = video_drvdata(file);
  85. return v4l2_subdev_call(tr->sd_tuner, tuner, s_frequency, f);
  86. }
  87. static int timbradio_vidioc_g_frequency(struct file *file, void *priv,
  88. struct v4l2_frequency *f)
  89. {
  90. struct timbradio *tr = video_drvdata(file);
  91. return v4l2_subdev_call(tr->sd_tuner, tuner, g_frequency, f);
  92. }
  93. static int timbradio_vidioc_queryctrl(struct file *file, void *priv,
  94. struct v4l2_queryctrl *qc)
  95. {
  96. struct timbradio *tr = video_drvdata(file);
  97. return v4l2_subdev_call(tr->sd_dsp, core, queryctrl, qc);
  98. }
  99. static int timbradio_vidioc_g_ctrl(struct file *file, void *priv,
  100. struct v4l2_control *ctrl)
  101. {
  102. struct timbradio *tr = video_drvdata(file);
  103. return v4l2_subdev_call(tr->sd_dsp, core, g_ctrl, ctrl);
  104. }
  105. static int timbradio_vidioc_s_ctrl(struct file *file, void *priv,
  106. struct v4l2_control *ctrl)
  107. {
  108. struct timbradio *tr = video_drvdata(file);
  109. return v4l2_subdev_call(tr->sd_dsp, core, s_ctrl, ctrl);
  110. }
  111. static const struct v4l2_ioctl_ops timbradio_ioctl_ops = {
  112. .vidioc_querycap = timbradio_vidioc_querycap,
  113. .vidioc_g_tuner = timbradio_vidioc_g_tuner,
  114. .vidioc_s_tuner = timbradio_vidioc_s_tuner,
  115. .vidioc_g_frequency = timbradio_vidioc_g_frequency,
  116. .vidioc_s_frequency = timbradio_vidioc_s_frequency,
  117. .vidioc_g_input = timbradio_vidioc_g_input,
  118. .vidioc_s_input = timbradio_vidioc_s_input,
  119. .vidioc_g_audio = timbradio_vidioc_g_audio,
  120. .vidioc_s_audio = timbradio_vidioc_s_audio,
  121. .vidioc_queryctrl = timbradio_vidioc_queryctrl,
  122. .vidioc_g_ctrl = timbradio_vidioc_g_ctrl,
  123. .vidioc_s_ctrl = timbradio_vidioc_s_ctrl
  124. };
  125. static const struct v4l2_file_operations timbradio_fops = {
  126. .owner = THIS_MODULE,
  127. .unlocked_ioctl = video_ioctl2,
  128. };
  129. static int __devinit timbradio_probe(struct platform_device *pdev)
  130. {
  131. struct timb_radio_platform_data *pdata = pdev->dev.platform_data;
  132. struct timbradio *tr;
  133. int err;
  134. if (!pdata) {
  135. dev_err(&pdev->dev, "Platform data missing\n");
  136. err = -EINVAL;
  137. goto err;
  138. }
  139. tr = kzalloc(sizeof(*tr), GFP_KERNEL);
  140. if (!tr) {
  141. err = -ENOMEM;
  142. goto err;
  143. }
  144. tr->pdata = *pdata;
  145. mutex_init(&tr->lock);
  146. strlcpy(tr->video_dev.name, "Timberdale Radio",
  147. sizeof(tr->video_dev.name));
  148. tr->video_dev.fops = &timbradio_fops;
  149. tr->video_dev.ioctl_ops = &timbradio_ioctl_ops;
  150. tr->video_dev.release = video_device_release_empty;
  151. tr->video_dev.minor = -1;
  152. tr->video_dev.lock = &tr->lock;
  153. strlcpy(tr->v4l2_dev.name, DRIVER_NAME, sizeof(tr->v4l2_dev.name));
  154. err = v4l2_device_register(NULL, &tr->v4l2_dev);
  155. if (err)
  156. goto err_v4l2_dev;
  157. tr->video_dev.v4l2_dev = &tr->v4l2_dev;
  158. err = video_register_device(&tr->video_dev, VFL_TYPE_RADIO, -1);
  159. if (err) {
  160. dev_err(&pdev->dev, "Error reg video\n");
  161. goto err_video_req;
  162. }
  163. video_set_drvdata(&tr->video_dev, tr);
  164. platform_set_drvdata(pdev, tr);
  165. return 0;
  166. err_video_req:
  167. video_device_release_empty(&tr->video_dev);
  168. v4l2_device_unregister(&tr->v4l2_dev);
  169. err_v4l2_dev:
  170. kfree(tr);
  171. err:
  172. dev_err(&pdev->dev, "Failed to register: %d\n", err);
  173. return err;
  174. }
  175. static int __devexit timbradio_remove(struct platform_device *pdev)
  176. {
  177. struct timbradio *tr = platform_get_drvdata(pdev);
  178. video_unregister_device(&tr->video_dev);
  179. video_device_release_empty(&tr->video_dev);
  180. v4l2_device_unregister(&tr->v4l2_dev);
  181. kfree(tr);
  182. return 0;
  183. }
  184. static struct platform_driver timbradio_platform_driver = {
  185. .driver = {
  186. .name = DRIVER_NAME,
  187. .owner = THIS_MODULE,
  188. },
  189. .probe = timbradio_probe,
  190. .remove = timbradio_remove,
  191. };
  192. module_platform_driver(timbradio_platform_driver);
  193. MODULE_DESCRIPTION("Timberdale Radio driver");
  194. MODULE_AUTHOR("Mocean Laboratories <info@mocean-labs.com>");
  195. MODULE_LICENSE("GPL v2");
  196. MODULE_VERSION("0.0.2");
  197. MODULE_ALIAS("platform:"DRIVER_NAME);