pvrusb2-wm8775.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. /*
  23. This source file is specifically designed to interface with the
  24. wm8775.
  25. */
  26. #include "pvrusb2-wm8775.h"
  27. #include "pvrusb2-i2c-cmd-v4l2.h"
  28. #include "pvrusb2-hdw-internal.h"
  29. #include "pvrusb2-debug.h"
  30. #include <linux/videodev2.h>
  31. #include <media/v4l2-common.h>
  32. #include <linux/errno.h>
  33. #include <linux/slab.h>
  34. struct pvr2_v4l_wm8775 {
  35. struct pvr2_i2c_handler handler;
  36. struct pvr2_i2c_client *client;
  37. struct pvr2_hdw *hdw;
  38. unsigned long stale_mask;
  39. };
  40. static void set_input(struct pvr2_v4l_wm8775 *ctxt)
  41. {
  42. struct v4l2_routing route;
  43. struct pvr2_hdw *hdw = ctxt->hdw;
  44. int msk = 0;
  45. memset(&route,0,sizeof(route));
  46. pvr2_trace(PVR2_TRACE_CHIPS,"i2c wm8775 set_input(val=%d msk=0x%x)",
  47. hdw->input_val,msk);
  48. // Always point to input #1 no matter what
  49. route.input = 2;
  50. pvr2_i2c_client_cmd(ctxt->client,VIDIOC_INT_S_AUDIO_ROUTING,&route);
  51. }
  52. static int check_input(struct pvr2_v4l_wm8775 *ctxt)
  53. {
  54. struct pvr2_hdw *hdw = ctxt->hdw;
  55. return hdw->input_dirty != 0;
  56. }
  57. struct pvr2_v4l_wm8775_ops {
  58. void (*update)(struct pvr2_v4l_wm8775 *);
  59. int (*check)(struct pvr2_v4l_wm8775 *);
  60. };
  61. static const struct pvr2_v4l_wm8775_ops wm8775_ops[] = {
  62. { .update = set_input, .check = check_input},
  63. };
  64. static unsigned int wm8775_describe(struct pvr2_v4l_wm8775 *ctxt,
  65. char *buf,unsigned int cnt)
  66. {
  67. return scnprintf(buf,cnt,"handler: pvrusb2-wm8775");
  68. }
  69. static void wm8775_detach(struct pvr2_v4l_wm8775 *ctxt)
  70. {
  71. ctxt->client->handler = NULL;
  72. kfree(ctxt);
  73. }
  74. static int wm8775_check(struct pvr2_v4l_wm8775 *ctxt)
  75. {
  76. unsigned long msk;
  77. unsigned int idx;
  78. for (idx = 0; idx < sizeof(wm8775_ops)/sizeof(wm8775_ops[0]);
  79. idx++) {
  80. msk = 1 << idx;
  81. if (ctxt->stale_mask & msk) continue;
  82. if (wm8775_ops[idx].check(ctxt)) {
  83. ctxt->stale_mask |= msk;
  84. }
  85. }
  86. return ctxt->stale_mask != 0;
  87. }
  88. static void wm8775_update(struct pvr2_v4l_wm8775 *ctxt)
  89. {
  90. unsigned long msk;
  91. unsigned int idx;
  92. for (idx = 0; idx < sizeof(wm8775_ops)/sizeof(wm8775_ops[0]);
  93. idx++) {
  94. msk = 1 << idx;
  95. if (!(ctxt->stale_mask & msk)) continue;
  96. ctxt->stale_mask &= ~msk;
  97. wm8775_ops[idx].update(ctxt);
  98. }
  99. }
  100. const static struct pvr2_i2c_handler_functions hfuncs = {
  101. .detach = (void (*)(void *))wm8775_detach,
  102. .check = (int (*)(void *))wm8775_check,
  103. .update = (void (*)(void *))wm8775_update,
  104. .describe = (unsigned int (*)(void *,char *,unsigned int))wm8775_describe,
  105. };
  106. int pvr2_i2c_wm8775_setup(struct pvr2_hdw *hdw,struct pvr2_i2c_client *cp)
  107. {
  108. struct pvr2_v4l_wm8775 *ctxt;
  109. if (cp->handler) return 0;
  110. ctxt = kmalloc(sizeof(*ctxt),GFP_KERNEL);
  111. if (!ctxt) return 0;
  112. memset(ctxt,0,sizeof(*ctxt));
  113. ctxt->handler.func_data = ctxt;
  114. ctxt->handler.func_table = &hfuncs;
  115. ctxt->client = cp;
  116. ctxt->hdw = hdw;
  117. ctxt->stale_mask = (1 << (sizeof(wm8775_ops)/
  118. sizeof(wm8775_ops[0]))) - 1;
  119. cp->handler = &ctxt->handler;
  120. pvr2_trace(PVR2_TRACE_CHIPS,"i2c 0x%x wm8775 V4L2 handler set up",
  121. cp->client->addr);
  122. return !0;
  123. }
  124. /*
  125. Stuff for Emacs to see, in order to encourage consistent editing style:
  126. *** Local Variables: ***
  127. *** mode: c ***
  128. *** fill-column: 70 ***
  129. *** tab-width: 8 ***
  130. *** c-basic-offset: 8 ***
  131. *** End: ***
  132. */