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