pvrusb2-wm8775.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. memset(&route,0,sizeof(route));
  45. switch(hdw->input_val) {
  46. case PVR2_CVAL_INPUT_RADIO:
  47. route.input = 1;
  48. break;
  49. default:
  50. /* All other cases just use the second input */
  51. route.input = 2;
  52. break;
  53. }
  54. pvr2_trace(PVR2_TRACE_CHIPS,"i2c wm8775 set_input(val=%d route=0x%x)",
  55. hdw->input_val,route.input);
  56. pvr2_i2c_client_cmd(ctxt->client,VIDIOC_INT_S_AUDIO_ROUTING,&route);
  57. }
  58. static int check_input(struct pvr2_v4l_wm8775 *ctxt)
  59. {
  60. struct pvr2_hdw *hdw = ctxt->hdw;
  61. return hdw->input_dirty != 0;
  62. }
  63. struct pvr2_v4l_wm8775_ops {
  64. void (*update)(struct pvr2_v4l_wm8775 *);
  65. int (*check)(struct pvr2_v4l_wm8775 *);
  66. };
  67. static const struct pvr2_v4l_wm8775_ops wm8775_ops[] = {
  68. { .update = set_input, .check = check_input},
  69. };
  70. static unsigned int wm8775_describe(struct pvr2_v4l_wm8775 *ctxt,
  71. char *buf,unsigned int cnt)
  72. {
  73. return scnprintf(buf,cnt,"handler: pvrusb2-wm8775");
  74. }
  75. static void wm8775_detach(struct pvr2_v4l_wm8775 *ctxt)
  76. {
  77. ctxt->client->handler = NULL;
  78. kfree(ctxt);
  79. }
  80. static int wm8775_check(struct pvr2_v4l_wm8775 *ctxt)
  81. {
  82. unsigned long msk;
  83. unsigned int idx;
  84. for (idx = 0; idx < ARRAY_SIZE(wm8775_ops); idx++) {
  85. msk = 1 << idx;
  86. if (ctxt->stale_mask & msk) continue;
  87. if (wm8775_ops[idx].check(ctxt)) {
  88. ctxt->stale_mask |= msk;
  89. }
  90. }
  91. return ctxt->stale_mask != 0;
  92. }
  93. static void wm8775_update(struct pvr2_v4l_wm8775 *ctxt)
  94. {
  95. unsigned long msk;
  96. unsigned int idx;
  97. for (idx = 0; idx < ARRAY_SIZE(wm8775_ops); idx++) {
  98. msk = 1 << idx;
  99. if (!(ctxt->stale_mask & msk)) continue;
  100. ctxt->stale_mask &= ~msk;
  101. wm8775_ops[idx].update(ctxt);
  102. }
  103. }
  104. static const struct pvr2_i2c_handler_functions hfuncs = {
  105. .detach = (void (*)(void *))wm8775_detach,
  106. .check = (int (*)(void *))wm8775_check,
  107. .update = (void (*)(void *))wm8775_update,
  108. .describe = (unsigned int (*)(void *,char *,unsigned int))wm8775_describe,
  109. };
  110. int pvr2_i2c_wm8775_setup(struct pvr2_hdw *hdw,struct pvr2_i2c_client *cp)
  111. {
  112. struct pvr2_v4l_wm8775 *ctxt;
  113. if (cp->handler) return 0;
  114. ctxt = kzalloc(sizeof(*ctxt),GFP_KERNEL);
  115. if (!ctxt) return 0;
  116. ctxt->handler.func_data = ctxt;
  117. ctxt->handler.func_table = &hfuncs;
  118. ctxt->client = cp;
  119. ctxt->hdw = hdw;
  120. ctxt->stale_mask = (1 << ARRAY_SIZE(wm8775_ops)) - 1;
  121. cp->handler = &ctxt->handler;
  122. pvr2_trace(PVR2_TRACE_CHIPS,"i2c 0x%x wm8775 V4L2 handler set up",
  123. cp->client->addr);
  124. return !0;
  125. }
  126. /*
  127. Stuff for Emacs to see, in order to encourage consistent editing style:
  128. *** Local Variables: ***
  129. *** mode: c ***
  130. *** fill-column: 70 ***
  131. *** tab-width: 8 ***
  132. *** c-basic-offset: 8 ***
  133. *** End: ***
  134. */