pvrusb2-demod.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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-demod.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_demod_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_config(struct pvr2_demod_handler *ctxt)
  37. {
  38. struct pvr2_hdw *hdw = ctxt->hdw;
  39. int cfg = 0;
  40. switch (hdw->tuner_type) {
  41. case TUNER_PHILIPS_FM1216ME_MK3:
  42. case TUNER_PHILIPS_FM1236_MK3:
  43. cfg = TDA9887_PORT1_ACTIVE|TDA9887_PORT2_ACTIVE;
  44. break;
  45. default:
  46. break;
  47. }
  48. pvr2_trace(PVR2_TRACE_CHIPS,"i2c demod set_config(0x%x)",cfg);
  49. pvr2_i2c_client_cmd(ctxt->client,TDA9887_SET_CONFIG,&cfg);
  50. ctxt->type_update_fl = 0;
  51. }
  52. static int demod_check(struct pvr2_demod_handler *ctxt)
  53. {
  54. struct pvr2_hdw *hdw = ctxt->hdw;
  55. if (hdw->tuner_updated) ctxt->type_update_fl = !0;
  56. return ctxt->type_update_fl != 0;
  57. }
  58. static void demod_update(struct pvr2_demod_handler *ctxt)
  59. {
  60. if (ctxt->type_update_fl) set_config(ctxt);
  61. }
  62. static void demod_detach(struct pvr2_demod_handler *ctxt)
  63. {
  64. ctxt->client->handler = 0;
  65. kfree(ctxt);
  66. }
  67. static unsigned int demod_describe(struct pvr2_demod_handler *ctxt,char *buf,unsigned int cnt)
  68. {
  69. return scnprintf(buf,cnt,"handler: pvrusb2-demod");
  70. }
  71. const static struct pvr2_i2c_handler_functions tuner_funcs = {
  72. .detach = (void (*)(void *))demod_detach,
  73. .check = (int (*)(void *))demod_check,
  74. .update = (void (*)(void *))demod_update,
  75. .describe = (unsigned int (*)(void *,char *,unsigned int))demod_describe,
  76. };
  77. int pvr2_i2c_demod_setup(struct pvr2_hdw *hdw,struct pvr2_i2c_client *cp)
  78. {
  79. struct pvr2_demod_handler *ctxt;
  80. if (cp->handler) return 0;
  81. ctxt = kmalloc(sizeof(*ctxt),GFP_KERNEL);
  82. if (!ctxt) return 0;
  83. memset(ctxt,0,sizeof(*ctxt));
  84. ctxt->i2c_handler.func_data = ctxt;
  85. ctxt->i2c_handler.func_table = &tuner_funcs;
  86. ctxt->type_update_fl = !0;
  87. ctxt->client = cp;
  88. ctxt->hdw = hdw;
  89. cp->handler = &ctxt->i2c_handler;
  90. pvr2_trace(PVR2_TRACE_CHIPS,"i2c 0x%x tda9887 V4L2 handler set up",
  91. cp->client->addr);
  92. return !0;
  93. }
  94. /*
  95. Stuff for Emacs to see, in order to encourage consistent editing style:
  96. *** Local Variables: ***
  97. *** mode: c ***
  98. *** fill-column: 70 ***
  99. *** tab-width: 8 ***
  100. *** c-basic-offset: 8 ***
  101. *** End: ***
  102. */