Merge tag 'regmap-fix-v5.11-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux/fpc-iii.git] / drivers / media / usb / dvb-usb-v2 / mxl111sf.h
blobe57e5d2353b408251f3a7d5aea6c279ae75ab085
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3 * Copyright (C) 2010-2014 Michael Krufky (mkrufky@linuxtv.org)
5 * see Documentation/driver-api/media/drivers/dvb-usb.rst for more information
6 */
8 #ifndef _DVB_USB_MXL111SF_H_
9 #define _DVB_USB_MXL111SF_H_
11 #ifdef DVB_USB_LOG_PREFIX
12 #undef DVB_USB_LOG_PREFIX
13 #endif
14 #define DVB_USB_LOG_PREFIX "mxl111sf"
15 #include "dvb_usb.h"
16 #include <media/tveeprom.h>
17 #include <media/media-entity.h>
19 /* Max transfer size done by I2C transfer functions */
20 #define MXL_MAX_XFER_SIZE 64
22 #define MXL_EP1_REG_READ 1
23 #define MXL_EP2_REG_WRITE 2
24 #define MXL_EP3_INTERRUPT 3
25 #define MXL_EP4_MPEG2 4
26 #define MXL_EP5_I2S 5
27 #define MXL_EP6_656 6
28 #define MXL_EP6_MPEG2 6
30 #ifdef USING_ENUM_mxl111sf_current_mode
31 enum mxl111sf_current_mode {
32 mxl_mode_dvbt = MXL_EP4_MPEG2,
33 mxl_mode_mh = MXL_EP5_I2S,
34 mxl_mode_atsc = MXL_EP6_MPEG2,
36 #endif
38 enum mxl111sf_gpio_port_expander {
39 mxl111sf_gpio_hw,
40 mxl111sf_PCA9534,
43 struct mxl111sf_adap_state {
44 int alt_mode;
45 int gpio_mode;
46 int device_mode;
47 int ep6_clockphase;
48 int (*fe_init)(struct dvb_frontend *);
49 int (*fe_sleep)(struct dvb_frontend *);
52 enum mxl111sf_pads {
53 MXL111SF_PAD_RF_INPUT,
54 MXL111SF_PAD_OUTPUT,
55 MXL111SF_NUM_PADS
58 struct mxl111sf_state {
59 struct dvb_usb_device *d;
61 enum mxl111sf_gpio_port_expander gpio_port_expander;
62 u8 port_expander_addr;
64 u8 chip_id;
65 u8 chip_ver;
66 #define MXL111SF_V6 1
67 #define MXL111SF_V8_100 2
68 #define MXL111SF_V8_200 3
69 u8 chip_rev;
71 #ifdef USING_ENUM_mxl111sf_current_mode
72 enum mxl111sf_current_mode current_mode;
73 #endif
75 #define MXL_TUNER_MODE 0
76 #define MXL_SOC_MODE 1
77 #define MXL_DEV_MODE_MASK 0x01
78 #if 1
79 int device_mode;
80 #endif
81 /* use usb alt setting 1 for EP4 ISOC transfer (dvb-t),
82 EP5 BULK transfer (atsc-mh),
83 EP6 BULK transfer (atsc/qam),
84 use usb alt setting 2 for EP4 BULK transfer (dvb-t),
85 EP5 ISOC transfer (atsc-mh),
86 EP6 ISOC transfer (atsc/qam),
88 int alt_mode;
89 int gpio_mode;
90 struct tveeprom tv;
92 struct mutex fe_lock;
93 u8 num_frontends;
94 struct mxl111sf_adap_state adap_state[3];
95 u8 sndbuf[MXL_MAX_XFER_SIZE];
96 u8 rcvbuf[MXL_MAX_XFER_SIZE];
97 struct mutex msg_lock;
98 #ifdef CONFIG_MEDIA_CONTROLLER_DVB
99 struct media_entity tuner;
100 struct media_pad tuner_pads[MXL111SF_NUM_PADS];
101 #endif
104 int mxl111sf_read_reg(struct mxl111sf_state *state, u8 addr, u8 *data);
105 int mxl111sf_write_reg(struct mxl111sf_state *state, u8 addr, u8 data);
107 struct mxl111sf_reg_ctrl_info {
108 u8 addr;
109 u8 mask;
110 u8 data;
113 int mxl111sf_write_reg_mask(struct mxl111sf_state *state,
114 u8 addr, u8 mask, u8 data);
115 int mxl111sf_ctrl_program_regs(struct mxl111sf_state *state,
116 struct mxl111sf_reg_ctrl_info *ctrl_reg_info);
118 /* needed for hardware i2c functions in mxl111sf-i2c.c:
119 * mxl111sf_i2c_send_data / mxl111sf_i2c_get_data */
120 int mxl111sf_ctrl_msg(struct mxl111sf_state *state,
121 u8 cmd, u8 *wbuf, int wlen, u8 *rbuf, int rlen);
123 #define mxl_printk(kern, fmt, arg...) \
124 printk(kern "%s: " fmt "\n", __func__, ##arg)
126 #define mxl_info(fmt, arg...) \
127 mxl_printk(KERN_INFO, fmt, ##arg)
129 extern int dvb_usb_mxl111sf_debug;
130 #define mxl_debug(fmt, arg...) \
131 if (dvb_usb_mxl111sf_debug) \
132 mxl_printk(KERN_DEBUG, fmt, ##arg)
134 #define MXL_I2C_DBG 0x04
135 #define MXL_ADV_DBG 0x10
136 #define mxl_debug_adv(fmt, arg...) \
137 if (dvb_usb_mxl111sf_debug & MXL_ADV_DBG) \
138 mxl_printk(KERN_DEBUG, fmt, ##arg)
140 #define mxl_i2c(fmt, arg...) \
141 if (dvb_usb_mxl111sf_debug & MXL_I2C_DBG) \
142 mxl_printk(KERN_DEBUG, fmt, ##arg)
144 #define mxl_i2c_adv(fmt, arg...) \
145 if ((dvb_usb_mxl111sf_debug & (MXL_I2C_DBG | MXL_ADV_DBG)) == \
146 (MXL_I2C_DBG | MXL_ADV_DBG)) \
147 mxl_printk(KERN_DEBUG, fmt, ##arg)
149 /* The following allows the mxl_fail() macro defined below to work
150 * in externel modules, such as mxl111sf-tuner.ko, even though
151 * dvb_usb_mxl111sf_debug is not defined within those modules */
152 #if (defined(__MXL111SF_TUNER_H__)) || (defined(__MXL111SF_DEMOD_H__))
153 #define MXL_ADV_DEBUG_ENABLED MXL_ADV_DBG
154 #else
155 #define MXL_ADV_DEBUG_ENABLED dvb_usb_mxl111sf_debug
156 #endif
158 #define mxl_fail(ret) \
159 ({ \
160 int __ret; \
161 __ret = (ret < 0); \
162 if ((__ret) && (MXL_ADV_DEBUG_ENABLED & MXL_ADV_DBG)) \
163 mxl_printk(KERN_ERR, "error %d on line %d", \
164 ret, __LINE__); \
165 __ret; \
168 #endif /* _DVB_USB_MXL111SF_H_ */