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