pvrusb2-tuner.c 3.2 KB

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