cx25840-core.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /* cx25840 internal API header
  2. *
  3. * Copyright (C) 2003-2004 Chris Kennedy
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version 2
  8. * of the License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #ifndef _CX25840_CORE_H_
  16. #define _CX25840_CORE_H_
  17. #include <linux/videodev2.h>
  18. #include <media/v4l2-device.h>
  19. #include <media/v4l2-ctrls.h>
  20. #include <linux/i2c.h>
  21. struct cx25840_ir_state;
  22. enum cx25840_model {
  23. CX23885_AV,
  24. CX23887_AV,
  25. CX23888_AV,
  26. CX2310X_AV,
  27. CX25840,
  28. CX25841,
  29. CX25842,
  30. CX25843,
  31. CX25836,
  32. CX25837,
  33. };
  34. enum cx25840_media_pads {
  35. CX25840_PAD_INPUT,
  36. CX25840_PAD_VID_OUT,
  37. CX25840_PAD_VBI_OUT,
  38. CX25840_NUM_PADS
  39. };
  40. /**
  41. * struct cx25840_state - a device instance private data
  42. * @c: i2c_client struct representing this device
  43. * @sd: our V4L2 sub-device
  44. * @hdl: our V4L2 control handler
  45. * @volume: audio volume V4L2 control (non-cx2583x devices only)
  46. * @mute: audio mute V4L2 control (non-cx2583x devices only)
  47. * @pvr150_workaround: whether we enable workaround for Hauppauge PVR150
  48. * hardware bug (audio dropping out)
  49. * @radio: set if we are currently in the radio mode, otherwise
  50. * the current mode is non-radio (that is, video)
  51. * @std: currently set video standard
  52. * @vid_input: currently set video input
  53. * @aud_input: currently set audio input
  54. * @audclk_freq: currently set audio sample rate
  55. * @audmode: currently set audio mode (when in non-radio mode)
  56. * @vbi_line_offset: vbi line number offset
  57. * @id: exact device model
  58. * @rev: raw device id read from the chip
  59. * @is_initialized: whether we have already loaded firmware into the chip
  60. * and initialized it
  61. * @vbi_regs_offset: offset of vbi regs
  62. * @fw_wait: wait queue to wake an initalization function up when
  63. * firmware loading (on a separate workqueue) finishes
  64. * @fw_work: a work that actually loads the firmware on a separate
  65. * workqueue
  66. * @ir_state: a pointer to chip IR controller private data
  67. * @pads: array of supported chip pads (currently only a stub)
  68. */
  69. struct cx25840_state {
  70. struct i2c_client *c;
  71. struct v4l2_subdev sd;
  72. struct v4l2_ctrl_handler hdl;
  73. struct {
  74. /* volume cluster */
  75. struct v4l2_ctrl *volume;
  76. struct v4l2_ctrl *mute;
  77. };
  78. int pvr150_workaround;
  79. int radio;
  80. v4l2_std_id std;
  81. enum cx25840_video_input vid_input;
  82. enum cx25840_audio_input aud_input;
  83. u32 audclk_freq;
  84. int audmode;
  85. int vbi_line_offset;
  86. enum cx25840_model id;
  87. u32 rev;
  88. int is_initialized;
  89. unsigned vbi_regs_offset;
  90. wait_queue_head_t fw_wait;
  91. struct work_struct fw_work;
  92. struct cx25840_ir_state *ir_state;
  93. #if defined(CONFIG_MEDIA_CONTROLLER)
  94. struct media_pad pads[CX25840_NUM_PADS];
  95. #endif
  96. };
  97. static inline struct cx25840_state *to_state(struct v4l2_subdev *sd)
  98. {
  99. return container_of(sd, struct cx25840_state, sd);
  100. }
  101. static inline struct v4l2_subdev *to_sd(struct v4l2_ctrl *ctrl)
  102. {
  103. return &container_of(ctrl->handler, struct cx25840_state, hdl)->sd;
  104. }
  105. static inline bool is_cx2583x(struct cx25840_state *state)
  106. {
  107. return state->id == CX25836 ||
  108. state->id == CX25837;
  109. }
  110. static inline bool is_cx231xx(struct cx25840_state *state)
  111. {
  112. return state->id == CX2310X_AV;
  113. }
  114. static inline bool is_cx2388x(struct cx25840_state *state)
  115. {
  116. return state->id == CX23885_AV ||
  117. state->id == CX23887_AV ||
  118. state->id == CX23888_AV;
  119. }
  120. static inline bool is_cx23885(struct cx25840_state *state)
  121. {
  122. return state->id == CX23885_AV;
  123. }
  124. static inline bool is_cx23887(struct cx25840_state *state)
  125. {
  126. return state->id == CX23887_AV;
  127. }
  128. static inline bool is_cx23888(struct cx25840_state *state)
  129. {
  130. return state->id == CX23888_AV;
  131. }
  132. /* ----------------------------------------------------------------------- */
  133. /* cx25850-core.c */
  134. int cx25840_write(struct i2c_client *client, u16 addr, u8 value);
  135. int cx25840_write4(struct i2c_client *client, u16 addr, u32 value);
  136. u8 cx25840_read(struct i2c_client *client, u16 addr);
  137. u32 cx25840_read4(struct i2c_client *client, u16 addr);
  138. int cx25840_and_or(struct i2c_client *client, u16 addr, unsigned mask, u8 value);
  139. int cx25840_and_or4(struct i2c_client *client, u16 addr, u32 and_mask,
  140. u32 or_value);
  141. void cx25840_std_setup(struct i2c_client *client);
  142. /* ----------------------------------------------------------------------- */
  143. /* cx25850-firmware.c */
  144. int cx25840_loadfw(struct i2c_client *client);
  145. /* ----------------------------------------------------------------------- */
  146. /* cx25850-audio.c */
  147. void cx25840_audio_set_path(struct i2c_client *client);
  148. int cx25840_s_clock_freq(struct v4l2_subdev *sd, u32 freq);
  149. extern const struct v4l2_ctrl_ops cx25840_audio_ctrl_ops;
  150. /* ----------------------------------------------------------------------- */
  151. /* cx25850-vbi.c */
  152. int cx25840_s_raw_fmt(struct v4l2_subdev *sd, struct v4l2_vbi_format *fmt);
  153. int cx25840_s_sliced_fmt(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *fmt);
  154. int cx25840_g_sliced_fmt(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *fmt);
  155. int cx25840_decode_vbi_line(struct v4l2_subdev *sd, struct v4l2_decode_vbi_line *vbi);
  156. /* ----------------------------------------------------------------------- */
  157. /* cx25850-ir.c */
  158. extern const struct v4l2_subdev_ir_ops cx25840_ir_ops;
  159. int cx25840_ir_log_status(struct v4l2_subdev *sd);
  160. int cx25840_ir_irq_handler(struct v4l2_subdev *sd, u32 status, bool *handled);
  161. int cx25840_ir_probe(struct v4l2_subdev *sd);
  162. int cx25840_ir_remove(struct v4l2_subdev *sd);
  163. #endif