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/dvb/README.dvb-usb 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 21 #define MXL_EP1_REG_READ 1 22 #define MXL_EP2_REG_WRITE 2 23 #define MXL_EP3_INTERRUPT 3 24 #define MXL_EP4_MPEG2 4 25 #define MXL_EP5_I2S 5 26 #define MXL_EP6_656 6 27 #define MXL_EP6_MPEG2 6 28 29 #ifdef USING_ENUM_mxl111sf_current_mode 30 enum mxl111sf_current_mode { 31 mxl_mode_dvbt = MXL_EP4_MPEG2, 32 mxl_mode_mh = MXL_EP5_I2S, 33 mxl_mode_atsc = MXL_EP6_MPEG2, 34 }; 35 #endif 36 37 enum mxl111sf_gpio_port_expander { 38 mxl111sf_gpio_hw, 39 mxl111sf_PCA9534, 40 }; 41 42 struct mxl111sf_adap_state { 43 int alt_mode; 44 int gpio_mode; 45 int device_mode; 46 int ep6_clockphase; 47 int (*fe_init)(struct dvb_frontend *); 48 int (*fe_sleep)(struct dvb_frontend *); 49 }; 50 51 struct mxl111sf_state { 52 struct dvb_usb_device *d; 53 54 enum mxl111sf_gpio_port_expander gpio_port_expander; 55 u8 port_expander_addr; 56 57 u8 chip_id; 58 u8 chip_ver; 59 #define MXL111SF_V6 1 60 #define MXL111SF_V8_100 2 61 #define MXL111SF_V8_200 3 62 u8 chip_rev; 63 64 #ifdef USING_ENUM_mxl111sf_current_mode 65 enum mxl111sf_current_mode current_mode; 66 #endif 67 68 #define MXL_TUNER_MODE 0 69 #define MXL_SOC_MODE 1 70 #define MXL_DEV_MODE_MASK 0x01 71 #if 1 72 int device_mode; 73 #endif 74 /* use usb alt setting 1 for EP4 ISOC transfer (dvb-t), 75 EP5 BULK transfer (atsc-mh), 76 EP6 BULK transfer (atsc/qam), 77 use usb alt setting 2 for EP4 BULK transfer (dvb-t), 78 EP5 ISOC transfer (atsc-mh), 79 EP6 ISOC transfer (atsc/qam), 80 */ 81 int alt_mode; 82 int gpio_mode; 83 struct tveeprom tv; 84 85 struct mutex fe_lock; 86 u8 num_frontends; 87 struct mxl111sf_adap_state adap_state[3]; 88 }; 89 90 int mxl111sf_read_reg(struct mxl111sf_state *state, u8 addr, u8 *data); 91 int mxl111sf_write_reg(struct mxl111sf_state *state, u8 addr, u8 data); 92 93 struct mxl111sf_reg_ctrl_info { 94 u8 addr; 95 u8 mask; 96 u8 data; 97 }; 98 99 int mxl111sf_write_reg_mask(struct mxl111sf_state *state, 100 u8 addr, u8 mask, u8 data); 101 int mxl111sf_ctrl_program_regs(struct mxl111sf_state *state, 102 struct mxl111sf_reg_ctrl_info *ctrl_reg_info); 103 104 /* needed for hardware i2c functions in mxl111sf-i2c.c: 105 * mxl111sf_i2c_send_data / mxl111sf_i2c_get_data */ 106 int mxl111sf_ctrl_msg(struct dvb_usb_device *d, 107 u8 cmd, u8 *wbuf, int wlen, u8 *rbuf, int rlen); 108 109 #define mxl_printk(kern, fmt, arg...) \ 110 printk(kern "%s: " fmt "\n", __func__, ##arg) 111 112 #define mxl_info(fmt, arg...) \ 113 mxl_printk(KERN_INFO, fmt, ##arg) 114 115 extern int dvb_usb_mxl111sf_debug; 116 #define mxl_debug(fmt, arg...) \ 117 if (dvb_usb_mxl111sf_debug) \ 118 mxl_printk(KERN_DEBUG, fmt, ##arg) 119 120 #define MXL_I2C_DBG 0x04 121 #define MXL_ADV_DBG 0x10 122 #define mxl_debug_adv(fmt, arg...) \ 123 if (dvb_usb_mxl111sf_debug & MXL_ADV_DBG) \ 124 mxl_printk(KERN_DEBUG, fmt, ##arg) 125 126 #define mxl_i2c(fmt, arg...) \ 127 if (dvb_usb_mxl111sf_debug & MXL_I2C_DBG) \ 128 mxl_printk(KERN_DEBUG, fmt, ##arg) 129 130 #define mxl_i2c_adv(fmt, arg...) \ 131 if ((dvb_usb_mxl111sf_debug & (MXL_I2C_DBG | MXL_ADV_DBG)) == \ 132 (MXL_I2C_DBG | MXL_ADV_DBG)) \ 133 mxl_printk(KERN_DEBUG, fmt, ##arg) 134 135 /* The following allows the mxl_fail() macro defined below to work 136 * in externel modules, such as mxl111sf-tuner.ko, even though 137 * dvb_usb_mxl111sf_debug is not defined within those modules */ 138 #if (defined(__MXL111SF_TUNER_H__)) || (defined(__MXL111SF_DEMOD_H__)) 139 #define MXL_ADV_DEBUG_ENABLED MXL_ADV_DBG 140 #else 141 #define MXL_ADV_DEBUG_ENABLED dvb_usb_mxl111sf_debug 142 #endif 143 144 #define mxl_fail(ret) \ 145 ({ \ 146 int __ret; \ 147 __ret = (ret < 0); \ 148 if ((__ret) && (MXL_ADV_DEBUG_ENABLED & MXL_ADV_DBG)) \ 149 mxl_printk(KERN_ERR, "error %d on line %d", \ 150 ret, __LINE__); \ 151 __ret; \ 152 }) 153 154 #endif /* _DVB_USB_MXL111SF_H_ */ 155 156 /* 157 * Local variables: 158 * c-basic-offset: 8 159 * End: 160 */ 161