pvrusb2-tuner.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. *
  3. *
  4. * Copyright (C) 2005 Mike Isely <isely@pobox.com>
  5. * Copyright (C) 2004 Aurelien Alleaume <slts@free.fr>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. *
  20. */
  21. #include "pvrusb2.h"
  22. #include "pvrusb2-util.h"
  23. #include "pvrusb2-tuner.h"
  24. #include "pvrusb2-hdw-internal.h"
  25. #include "pvrusb2-debug.h"
  26. #include <linux/videodev2.h>
  27. #include <media/tuner.h>
  28. #include <media/v4l2-common.h>
  29. struct pvr2_tuner_handler {
  30. struct pvr2_hdw *hdw;
  31. struct pvr2_i2c_client *client;
  32. struct pvr2_i2c_handler i2c_handler;
  33. int type_update_fl;
  34. };
  35. static void set_type(struct pvr2_tuner_handler *ctxt)
  36. {
  37. struct pvr2_hdw *hdw = ctxt->hdw;
  38. struct tuner_setup setup;
  39. pvr2_trace(PVR2_TRACE_CHIPS,"i2c tuner set_type(%d)",hdw->tuner_type);
  40. if (((int)(hdw->tuner_type)) < 0) return;
  41. setup.addr = ADDR_UNSET;
  42. setup.type = hdw->tuner_type;
  43. setup.mode_mask = T_RADIO | T_ANALOG_TV;
  44. /* We may really want mode_mask to be T_ANALOG_TV for now */
  45. pvr2_i2c_client_cmd(ctxt->client,TUNER_SET_TYPE_ADDR,&setup);
  46. ctxt->type_update_fl = 0;
  47. }
  48. static int tuner_check(struct pvr2_tuner_handler *ctxt)
  49. {
  50. struct pvr2_hdw *hdw = ctxt->hdw;
  51. if (hdw->tuner_updated) ctxt->type_update_fl = !0;
  52. return ctxt->type_update_fl != 0;
  53. }
  54. static void tuner_update(struct pvr2_tuner_handler *ctxt)
  55. {
  56. if (ctxt->type_update_fl) set_type(ctxt);
  57. }
  58. static void pvr2_tuner_detach(struct pvr2_tuner_handler *ctxt)
  59. {
  60. ctxt->client->handler = NULL;
  61. kfree(ctxt);
  62. }
  63. static unsigned int pvr2_tuner_describe(struct pvr2_tuner_handler *ctxt,char *buf,unsigned int cnt)
  64. {
  65. return scnprintf(buf,cnt,"handler: pvrusb2-tuner");
  66. }
  67. static const struct pvr2_i2c_handler_functions tuner_funcs = {
  68. .detach = (void (*)(void *))pvr2_tuner_detach,
  69. .check = (int (*)(void *))tuner_check,
  70. .update = (void (*)(void *))tuner_update,
  71. .describe = (unsigned int (*)(void *,char *,unsigned int))pvr2_tuner_describe,
  72. };
  73. int pvr2_i2c_tuner_setup(struct pvr2_hdw *hdw,struct pvr2_i2c_client *cp)
  74. {
  75. struct pvr2_tuner_handler *ctxt;
  76. if (cp->handler) return 0;
  77. ctxt = kzalloc(sizeof(*ctxt),GFP_KERNEL);
  78. if (!ctxt) return 0;
  79. ctxt->i2c_handler.func_data = ctxt;
  80. ctxt->i2c_handler.func_table = &tuner_funcs;
  81. ctxt->type_update_fl = !0;
  82. ctxt->client = cp;
  83. ctxt->hdw = hdw;
  84. cp->handler = &ctxt->i2c_handler;
  85. pvr2_trace(PVR2_TRACE_CHIPS,"i2c 0x%x tuner handler set up",
  86. cp->client->addr);
  87. return !0;
  88. }
  89. /*
  90. Stuff for Emacs to see, in order to encourage consistent editing style:
  91. *** Local Variables: ***
  92. *** mode: c ***
  93. *** fill-column: 70 ***
  94. *** tab-width: 8 ***
  95. *** c-basic-offset: 8 ***
  96. *** End: ***
  97. */