Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1 | /* |
| 2 | DVB device driver for cx231xx |
| 3 | |
| 4 | Copyright (C) 2008 <srinivasa.deevi at conexant dot com> |
Sri Deevi | b925517 | 2009-03-04 17:49:01 -0300 | [diff] [blame] | 5 | Based on em28xx driver |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 6 | |
| 7 | This program is free software; you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License as published by |
| 9 | the Free Software Foundation; either version 2 of the License, or |
| 10 | (at your option) any later version. |
| 11 | |
| 12 | This program is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | GNU General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License |
| 18 | along with this program; if not, write to the Free Software |
| 19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 20 | */ |
| 21 | |
Mauro Carvalho Chehab | 589dadf | 2014-11-01 08:09:44 -0300 | [diff] [blame] | 22 | #include "cx231xx.h" |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 23 | #include <linux/kernel.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 24 | #include <linux/slab.h> |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 25 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 26 | #include <media/v4l2-common.h> |
| 27 | #include <media/videobuf-vmalloc.h> |
Mauro Carvalho Chehab | 6168309 | 2016-02-11 22:39:52 -0200 | [diff] [blame] | 28 | #include <media/tuner.h> |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 29 | |
| 30 | #include "xc5000.h" |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 31 | #include "s5h1432.h" |
| 32 | #include "tda18271.h" |
| 33 | #include "s5h1411.h" |
Michael Krufky | 1a50fdd | 2010-07-06 18:23:53 -0300 | [diff] [blame] | 34 | #include "lgdt3305.h" |
Matthias Schwarzott | dd2e7dd | 2014-07-22 17:12:15 -0300 | [diff] [blame] | 35 | #include "si2165.h" |
Oleh Kravchenko | a096fd6 | 2017-01-29 16:03:51 -0200 | [diff] [blame] | 36 | #include "si2168.h" |
Mauro Carvalho Chehab | ede676c | 2010-09-27 23:44:27 -0300 | [diff] [blame] | 37 | #include "mb86a20s.h" |
Matthias Schwarzott | 9e49f7c | 2014-07-22 17:12:16 -0300 | [diff] [blame] | 38 | #include "si2157.h" |
Olli Salonen | 809abdb | 2015-02-28 12:25:24 -0300 | [diff] [blame] | 39 | #include "lgdt3306a.h" |
Oleh Kravchenko | 0f42b33 | 2017-04-22 12:47:13 -0300 | [diff] [blame] | 40 | #include "r820t.h" |
| 41 | #include "mn88473.h" |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 42 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 43 | MODULE_DESCRIPTION("driver for cx231xx based DVB cards"); |
| 44 | MODULE_AUTHOR("Srinivasa Deevi <srinivasa.deevi@conexant.com>"); |
| 45 | MODULE_LICENSE("GPL"); |
| 46 | |
| 47 | static unsigned int debug; |
| 48 | module_param(debug, int, 0644); |
| 49 | MODULE_PARM_DESC(debug, "enable debug messages [dvb]"); |
| 50 | |
| 51 | DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); |
| 52 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 53 | #define CX231XX_DVB_NUM_BUFS 5 |
| 54 | #define CX231XX_DVB_MAX_PACKETSIZE 564 |
| 55 | #define CX231XX_DVB_MAX_PACKETS 64 |
| 56 | |
| 57 | struct cx231xx_dvb { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 58 | struct dvb_frontend *frontend; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 59 | |
| 60 | /* feed count management */ |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 61 | struct mutex lock; |
| 62 | int nfeeds; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 63 | |
| 64 | /* general boilerplate stuff */ |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 65 | struct dvb_adapter adapter; |
| 66 | struct dvb_demux demux; |
| 67 | struct dmxdev dmxdev; |
| 68 | struct dmx_frontend fe_hw; |
| 69 | struct dmx_frontend fe_mem; |
| 70 | struct dvb_net net; |
Matthias Schwarzott | d28d7f8 | 2016-07-26 04:09:04 -0300 | [diff] [blame] | 71 | struct i2c_client *i2c_client_demod; |
Matthias Schwarzott | 6d3deba | 2014-07-22 17:12:14 -0300 | [diff] [blame] | 72 | struct i2c_client *i2c_client_tuner; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 73 | }; |
| 74 | |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 75 | static struct s5h1432_config dvico_s5h1432_config = { |
| 76 | .output_mode = S5H1432_SERIAL_OUTPUT, |
| 77 | .gpio = S5H1432_GPIO_ON, |
| 78 | .qam_if = S5H1432_IF_4000, |
| 79 | .vsb_if = S5H1432_IF_4000, |
| 80 | .inversion = S5H1432_INVERSION_OFF, |
| 81 | .status_mode = S5H1432_DEMODLOCKING, |
| 82 | .mpeg_timing = S5H1432_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK, |
| 83 | }; |
| 84 | |
| 85 | static struct tda18271_std_map cnxt_rde253s_tda18271_std_map = { |
| 86 | .dvbt_6 = { .if_freq = 4000, .agc_mode = 3, .std = 4, |
| 87 | .if_lvl = 1, .rfagc_top = 0x37, }, |
| 88 | .dvbt_7 = { .if_freq = 4000, .agc_mode = 3, .std = 5, |
| 89 | .if_lvl = 1, .rfagc_top = 0x37, }, |
| 90 | .dvbt_8 = { .if_freq = 4000, .agc_mode = 3, .std = 6, |
| 91 | .if_lvl = 1, .rfagc_top = 0x37, }, |
| 92 | }; |
| 93 | |
Mauro Carvalho Chehab | ede676c | 2010-09-27 23:44:27 -0300 | [diff] [blame] | 94 | static struct tda18271_std_map mb86a20s_tda18271_config = { |
Mauro Carvalho Chehab | 84c09d7 | 2013-03-03 07:49:50 -0300 | [diff] [blame] | 95 | .dvbt_6 = { .if_freq = 4000, .agc_mode = 3, .std = 4, |
| 96 | .if_lvl = 0, .rfagc_top = 0x37, }, |
Mauro Carvalho Chehab | ede676c | 2010-09-27 23:44:27 -0300 | [diff] [blame] | 97 | }; |
| 98 | |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 99 | static struct tda18271_config cnxt_rde253s_tunerconfig = { |
| 100 | .std_map = &cnxt_rde253s_tda18271_std_map, |
| 101 | .gate = TDA18271_GATE_ANALOG, |
| 102 | }; |
| 103 | |
| 104 | static struct s5h1411_config tda18271_s5h1411_config = { |
| 105 | .output_mode = S5H1411_SERIAL_OUTPUT, |
| 106 | .gpio = S5H1411_GPIO_OFF, |
| 107 | .vsb_if = S5H1411_IF_3250, |
| 108 | .qam_if = S5H1411_IF_4000, |
| 109 | .inversion = S5H1411_INVERSION_ON, |
| 110 | .status_mode = S5H1411_DEMODLOCKING, |
| 111 | .mpeg_timing = S5H1411_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK, |
| 112 | }; |
| 113 | static struct s5h1411_config xc5000_s5h1411_config = { |
| 114 | .output_mode = S5H1411_SERIAL_OUTPUT, |
| 115 | .gpio = S5H1411_GPIO_OFF, |
| 116 | .vsb_if = S5H1411_IF_3250, |
| 117 | .qam_if = S5H1411_IF_3250, |
| 118 | .inversion = S5H1411_INVERSION_OFF, |
| 119 | .status_mode = S5H1411_DEMODLOCKING, |
| 120 | .mpeg_timing = S5H1411_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK, |
| 121 | }; |
Michael Krufky | 1a50fdd | 2010-07-06 18:23:53 -0300 | [diff] [blame] | 122 | |
| 123 | static struct lgdt3305_config hcw_lgdt3305_config = { |
| 124 | .i2c_addr = 0x0e, |
| 125 | .mpeg_mode = LGDT3305_MPEG_SERIAL, |
| 126 | .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE, |
| 127 | .tpvalid_polarity = LGDT3305_TP_VALID_HIGH, |
| 128 | .deny_i2c_rptr = 1, |
| 129 | .spectral_inversion = 1, |
| 130 | .qam_if_khz = 4000, |
| 131 | .vsb_if_khz = 3250, |
| 132 | }; |
| 133 | |
| 134 | static struct tda18271_std_map hauppauge_tda18271_std_map = { |
| 135 | .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 4, |
| 136 | .if_lvl = 1, .rfagc_top = 0x58, }, |
| 137 | .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 5, |
| 138 | .if_lvl = 1, .rfagc_top = 0x58, }, |
| 139 | }; |
| 140 | |
| 141 | static struct tda18271_config hcw_tda18271_config = { |
| 142 | .std_map = &hauppauge_tda18271_std_map, |
| 143 | .gate = TDA18271_GATE_DIGITAL, |
| 144 | }; |
| 145 | |
Mauro Carvalho Chehab | ede676c | 2010-09-27 23:44:27 -0300 | [diff] [blame] | 146 | static const struct mb86a20s_config pv_mb86a20s_config = { |
| 147 | .demod_address = 0x10, |
Mauro Carvalho Chehab | 7572f9c | 2010-10-03 16:48:49 -0300 | [diff] [blame] | 148 | .is_serial = true, |
Mauro Carvalho Chehab | ede676c | 2010-09-27 23:44:27 -0300 | [diff] [blame] | 149 | }; |
| 150 | |
| 151 | static struct tda18271_config pv_tda18271_config = { |
| 152 | .std_map = &mb86a20s_tda18271_config, |
| 153 | .gate = TDA18271_GATE_DIGITAL, |
| 154 | .small_i2c = TDA18271_03_BYTE_CHUNK_INIT, |
| 155 | }; |
| 156 | |
Olli Salonen | 809abdb | 2015-02-28 12:25:24 -0300 | [diff] [blame] | 157 | static struct lgdt3306a_config hauppauge_955q_lgdt3306a_config = { |
| 158 | .i2c_addr = 0x59, |
| 159 | .qam_if_khz = 4000, |
| 160 | .vsb_if_khz = 3250, |
| 161 | .deny_i2c_rptr = 1, |
| 162 | .spectral_inversion = 1, |
| 163 | .mpeg_mode = LGDT3306A_MPEG_SERIAL, |
| 164 | .tpclk_edge = LGDT3306A_TPCLK_RISING_EDGE, |
| 165 | .tpvalid_polarity = LGDT3306A_TP_VALID_HIGH, |
| 166 | .xtalMHz = 25, |
| 167 | }; |
| 168 | |
Oleh Kravchenko | 0f42b33 | 2017-04-22 12:47:13 -0300 | [diff] [blame] | 169 | static struct r820t_config astrometa_t2hybrid_r820t_config = { |
| 170 | .i2c_addr = 0x3a, /* 0x74 >> 1 */ |
| 171 | .xtal = 16000000, |
| 172 | .rafael_chip = CHIP_R828D, |
| 173 | .max_i2c_msg_len = 2, |
| 174 | }; |
| 175 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 176 | static inline void print_err_status(struct cx231xx *dev, int packet, int status) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 177 | { |
| 178 | char *errmsg = "Unknown"; |
| 179 | |
| 180 | switch (status) { |
| 181 | case -ENOENT: |
| 182 | errmsg = "unlinked synchronuously"; |
| 183 | break; |
| 184 | case -ECONNRESET: |
| 185 | errmsg = "unlinked asynchronuously"; |
| 186 | break; |
| 187 | case -ENOSR: |
| 188 | errmsg = "Buffer error (overrun)"; |
| 189 | break; |
| 190 | case -EPIPE: |
| 191 | errmsg = "Stalled (device not responding)"; |
| 192 | break; |
| 193 | case -EOVERFLOW: |
| 194 | errmsg = "Babble (bad cable?)"; |
| 195 | break; |
| 196 | case -EPROTO: |
| 197 | errmsg = "Bit-stuff error (bad cable?)"; |
| 198 | break; |
| 199 | case -EILSEQ: |
| 200 | errmsg = "CRC/Timeout (could be anything)"; |
| 201 | break; |
| 202 | case -ETIME: |
| 203 | errmsg = "Device does not respond"; |
| 204 | break; |
| 205 | } |
| 206 | if (packet < 0) { |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 207 | dev_dbg(dev->dev, |
Mauro Carvalho Chehab | 3b795d0 | 2014-11-02 07:45:56 -0300 | [diff] [blame] | 208 | "URB status %d [%s].\n", status, errmsg); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 209 | } else { |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 210 | dev_dbg(dev->dev, |
Mauro Carvalho Chehab | 3b795d0 | 2014-11-02 07:45:56 -0300 | [diff] [blame] | 211 | "URB packet %d, status %d [%s].\n", |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 212 | packet, status, errmsg); |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | static inline int dvb_isoc_copy(struct cx231xx *dev, struct urb *urb) |
| 217 | { |
| 218 | int i; |
| 219 | |
| 220 | if (!dev) |
| 221 | return 0; |
| 222 | |
Mauro Carvalho Chehab | 990862a | 2012-01-10 09:48:50 -0200 | [diff] [blame] | 223 | if (dev->state & DEV_DISCONNECTED) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 224 | return 0; |
| 225 | |
| 226 | if (urb->status < 0) { |
| 227 | print_err_status(dev, -1, urb->status); |
| 228 | if (urb->status == -ENOENT) |
| 229 | return 0; |
| 230 | } |
| 231 | |
| 232 | for (i = 0; i < urb->number_of_packets; i++) { |
| 233 | int status = urb->iso_frame_desc[i].status; |
| 234 | |
| 235 | if (status < 0) { |
| 236 | print_err_status(dev, i, status); |
| 237 | if (urb->iso_frame_desc[i].status != -EPROTO) |
| 238 | continue; |
| 239 | } |
| 240 | |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 241 | dvb_dmx_swfilter(&dev->dvb->demux, |
| 242 | urb->transfer_buffer + |
| 243 | urb->iso_frame_desc[i].offset, |
| 244 | urb->iso_frame_desc[i].actual_length); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | return 0; |
| 248 | } |
| 249 | |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 250 | static inline int dvb_bulk_copy(struct cx231xx *dev, struct urb *urb) |
| 251 | { |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 252 | if (!dev) |
| 253 | return 0; |
| 254 | |
Mauro Carvalho Chehab | 990862a | 2012-01-10 09:48:50 -0200 | [diff] [blame] | 255 | if (dev->state & DEV_DISCONNECTED) |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 256 | return 0; |
| 257 | |
| 258 | if (urb->status < 0) { |
| 259 | print_err_status(dev, -1, urb->status); |
| 260 | if (urb->status == -ENOENT) |
| 261 | return 0; |
| 262 | } |
| 263 | |
| 264 | /* Feed the transport payload into the kernel demux */ |
| 265 | dvb_dmx_swfilter(&dev->dvb->demux, |
| 266 | urb->transfer_buffer, urb->actual_length); |
| 267 | |
| 268 | return 0; |
| 269 | } |
| 270 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 271 | static int start_streaming(struct cx231xx_dvb *dvb) |
| 272 | { |
| 273 | int rc; |
| 274 | struct cx231xx *dev = dvb->adapter.priv; |
| 275 | |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 276 | if (dev->USE_ISO) { |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 277 | dev_dbg(dev->dev, "DVB transfer mode is ISO.\n"); |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 278 | cx231xx_set_alt_setting(dev, INDEX_TS1, 4); |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 279 | rc = cx231xx_set_mode(dev, CX231XX_DIGITAL_MODE); |
| 280 | if (rc < 0) |
| 281 | return rc; |
| 282 | dev->mode_tv = 1; |
| 283 | return cx231xx_init_isoc(dev, CX231XX_DVB_MAX_PACKETS, |
| 284 | CX231XX_DVB_NUM_BUFS, |
| 285 | dev->ts1_mode.max_pkt_size, |
| 286 | dvb_isoc_copy); |
| 287 | } else { |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 288 | dev_dbg(dev->dev, "DVB transfer mode is BULK.\n"); |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 289 | cx231xx_set_alt_setting(dev, INDEX_TS1, 0); |
| 290 | rc = cx231xx_set_mode(dev, CX231XX_DIGITAL_MODE); |
| 291 | if (rc < 0) |
| 292 | return rc; |
| 293 | dev->mode_tv = 1; |
| 294 | return cx231xx_init_bulk(dev, CX231XX_DVB_MAX_PACKETS, |
| 295 | CX231XX_DVB_NUM_BUFS, |
| 296 | dev->ts1_mode.max_pkt_size, |
| 297 | dvb_bulk_copy); |
| 298 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 299 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | static int stop_streaming(struct cx231xx_dvb *dvb) |
| 303 | { |
| 304 | struct cx231xx *dev = dvb->adapter.priv; |
| 305 | |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 306 | if (dev->USE_ISO) |
| 307 | cx231xx_uninit_isoc(dev); |
| 308 | else |
| 309 | cx231xx_uninit_bulk(dev); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 310 | |
| 311 | cx231xx_set_mode(dev, CX231XX_SUSPEND); |
| 312 | |
| 313 | return 0; |
| 314 | } |
| 315 | |
| 316 | static int start_feed(struct dvb_demux_feed *feed) |
| 317 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 318 | struct dvb_demux *demux = feed->demux; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 319 | struct cx231xx_dvb *dvb = demux->priv; |
| 320 | int rc, ret; |
| 321 | |
| 322 | if (!demux->dmx.frontend) |
| 323 | return -EINVAL; |
| 324 | |
| 325 | mutex_lock(&dvb->lock); |
| 326 | dvb->nfeeds++; |
| 327 | rc = dvb->nfeeds; |
| 328 | |
| 329 | if (dvb->nfeeds == 1) { |
| 330 | ret = start_streaming(dvb); |
| 331 | if (ret < 0) |
| 332 | rc = ret; |
| 333 | } |
| 334 | |
| 335 | mutex_unlock(&dvb->lock); |
| 336 | return rc; |
| 337 | } |
| 338 | |
| 339 | static int stop_feed(struct dvb_demux_feed *feed) |
| 340 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 341 | struct dvb_demux *demux = feed->demux; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 342 | struct cx231xx_dvb *dvb = demux->priv; |
| 343 | int err = 0; |
| 344 | |
| 345 | mutex_lock(&dvb->lock); |
| 346 | dvb->nfeeds--; |
| 347 | |
| 348 | if (0 == dvb->nfeeds) |
| 349 | err = stop_streaming(dvb); |
| 350 | |
| 351 | mutex_unlock(&dvb->lock); |
| 352 | return err; |
| 353 | } |
| 354 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 355 | /* ------------------------------------------------------------------ */ |
| 356 | static int cx231xx_dvb_bus_ctrl(struct dvb_frontend *fe, int acquire) |
| 357 | { |
| 358 | struct cx231xx *dev = fe->dvb->priv; |
| 359 | |
| 360 | if (acquire) |
| 361 | return cx231xx_set_mode(dev, CX231XX_DIGITAL_MODE); |
| 362 | else |
| 363 | return cx231xx_set_mode(dev, CX231XX_SUSPEND); |
| 364 | } |
| 365 | |
| 366 | /* ------------------------------------------------------------------ */ |
| 367 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 368 | static struct xc5000_config cnxt_rde250_tunerconfig = { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 369 | .i2c_address = 0x61, |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 370 | .if_khz = 4000, |
| 371 | }; |
| 372 | static struct xc5000_config cnxt_rdu250_tunerconfig = { |
| 373 | .i2c_address = 0x61, |
| 374 | .if_khz = 3250, |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 375 | }; |
| 376 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 377 | /* ------------------------------------------------------------------ */ |
| 378 | #if 0 |
| 379 | static int attach_xc5000(u8 addr, struct cx231xx *dev) |
| 380 | { |
| 381 | |
| 382 | struct dvb_frontend *fe; |
| 383 | struct xc5000_config cfg; |
| 384 | |
| 385 | memset(&cfg, 0, sizeof(cfg)); |
Matthias Schwarzott | c3c3f1a | 2014-10-02 02:20:59 -0300 | [diff] [blame] | 386 | cfg.i2c_adap = cx231xx_get_i2c_adap(dev, dev->board.tuner_i2c_master); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 387 | cfg.i2c_addr = addr; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 388 | |
| 389 | if (!dev->dvb->frontend) { |
Mauro Carvalho Chehab | ba1da97 | 2016-10-18 17:44:14 -0200 | [diff] [blame] | 390 | dev_err(dev->dev, "%s/2: dvb frontend not attached. Can't attach xc5000\n", |
| 391 | dev->name); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 392 | return -EINVAL; |
| 393 | } |
| 394 | |
| 395 | fe = dvb_attach(xc5000_attach, dev->dvb->frontend, &cfg); |
| 396 | if (!fe) { |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 397 | dev_err(dev->dev, "%s/2: xc5000 attach failed\n", dev->name); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 398 | dvb_frontend_detach(dev->dvb->frontend); |
| 399 | dev->dvb->frontend = NULL; |
| 400 | return -EINVAL; |
| 401 | } |
| 402 | |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 403 | dev_info(dev->dev, "%s/2: xc5000 attached\n", dev->name); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 404 | |
| 405 | return 0; |
| 406 | } |
| 407 | #endif |
| 408 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 409 | int cx231xx_set_analog_freq(struct cx231xx *dev, u32 freq) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 410 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 411 | if ((dev->dvb != NULL) && (dev->dvb->frontend != NULL)) { |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 412 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 413 | struct dvb_tuner_ops *dops = &dev->dvb->frontend->ops.tuner_ops; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 414 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 415 | if (dops->set_analog_params != NULL) { |
| 416 | struct analog_parameters params; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 417 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 418 | params.frequency = freq; |
| 419 | params.std = dev->norm; |
| 420 | params.mode = 0; /* 0- Air; 1 - cable */ |
| 421 | /*params.audmode = ; */ |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 422 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 423 | /* Set the analog parameters to set the frequency */ |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 424 | dops->set_analog_params(dev->dvb->frontend, ¶ms); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 425 | } |
| 426 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 427 | } |
| 428 | |
Mauro Carvalho Chehab | ea21f70 | 2014-09-03 16:16:53 -0300 | [diff] [blame] | 429 | return 0; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | int cx231xx_reset_analog_tuner(struct cx231xx *dev) |
| 433 | { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 434 | int status = 0; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 435 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 436 | if ((dev->dvb != NULL) && (dev->dvb->frontend != NULL)) { |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 437 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 438 | struct dvb_tuner_ops *dops = &dev->dvb->frontend->ops.tuner_ops; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 439 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 440 | if (dops->init != NULL && !dev->xc_fw_load_done) { |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 441 | |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 442 | dev_dbg(dev->dev, |
Mauro Carvalho Chehab | b7085c0 | 2014-11-02 07:21:44 -0300 | [diff] [blame] | 443 | "Reloading firmware for XC5000\n"); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 444 | status = dops->init(dev->dvb->frontend); |
| 445 | if (status == 0) { |
| 446 | dev->xc_fw_load_done = 1; |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 447 | dev_dbg(dev->dev, |
Mauro Carvalho Chehab | b7085c0 | 2014-11-02 07:21:44 -0300 | [diff] [blame] | 448 | "XC5000 firmware download completed\n"); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 449 | } else { |
| 450 | dev->xc_fw_load_done = 0; |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 451 | dev_dbg(dev->dev, |
Mauro Carvalho Chehab | b7085c0 | 2014-11-02 07:21:44 -0300 | [diff] [blame] | 452 | "XC5000 firmware download failed !!!\n"); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 453 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 454 | } |
| 455 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 456 | } |
| 457 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 458 | return status; |
| 459 | } |
| 460 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 461 | /* ------------------------------------------------------------------ */ |
| 462 | |
| 463 | static int register_dvb(struct cx231xx_dvb *dvb, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 464 | struct module *module, |
| 465 | struct cx231xx *dev, struct device *device) |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 466 | { |
| 467 | int result; |
| 468 | |
| 469 | mutex_init(&dvb->lock); |
| 470 | |
Mauro Carvalho Chehab | 1d058bd | 2015-01-01 11:37:17 -0300 | [diff] [blame] | 471 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 472 | /* register adapter */ |
| 473 | result = dvb_register_adapter(&dvb->adapter, dev->name, module, device, |
| 474 | adapter_nr); |
| 475 | if (result < 0) { |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 476 | dev_warn(dev->dev, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 477 | "%s: dvb_register_adapter failed (errno = %d)\n", |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 478 | dev->name, result); |
| 479 | goto fail_adapter; |
| 480 | } |
Mauro Carvalho Chehab | 89a2c1d | 2015-03-02 11:26:14 -0300 | [diff] [blame] | 481 | dvb_register_media_controller(&dvb->adapter, dev->media_dev); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 482 | |
| 483 | /* Ensure all frontends negotiate bus access */ |
| 484 | dvb->frontend->ops.ts_bus_ctrl = cx231xx_dvb_bus_ctrl; |
| 485 | |
| 486 | dvb->adapter.priv = dev; |
| 487 | |
| 488 | /* register frontend */ |
| 489 | result = dvb_register_frontend(&dvb->adapter, dvb->frontend); |
| 490 | if (result < 0) { |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 491 | dev_warn(dev->dev, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 492 | "%s: dvb_register_frontend failed (errno = %d)\n", |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 493 | dev->name, result); |
| 494 | goto fail_frontend; |
| 495 | } |
| 496 | |
| 497 | /* register demux stuff */ |
| 498 | dvb->demux.dmx.capabilities = |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 499 | DMX_TS_FILTERING | DMX_SECTION_FILTERING | |
| 500 | DMX_MEMORY_BASED_FILTERING; |
| 501 | dvb->demux.priv = dvb; |
| 502 | dvb->demux.filternum = 256; |
| 503 | dvb->demux.feednum = 256; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 504 | dvb->demux.start_feed = start_feed; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 505 | dvb->demux.stop_feed = stop_feed; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 506 | |
| 507 | result = dvb_dmx_init(&dvb->demux); |
| 508 | if (result < 0) { |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 509 | dev_warn(dev->dev, |
Mauro Carvalho Chehab | 3b795d0 | 2014-11-02 07:45:56 -0300 | [diff] [blame] | 510 | "%s: dvb_dmx_init failed (errno = %d)\n", |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 511 | dev->name, result); |
| 512 | goto fail_dmx; |
| 513 | } |
| 514 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 515 | dvb->dmxdev.filternum = 256; |
| 516 | dvb->dmxdev.demux = &dvb->demux.dmx; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 517 | dvb->dmxdev.capabilities = 0; |
| 518 | result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter); |
| 519 | if (result < 0) { |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 520 | dev_warn(dev->dev, |
Mauro Carvalho Chehab | 3b795d0 | 2014-11-02 07:45:56 -0300 | [diff] [blame] | 521 | "%s: dvb_dmxdev_init failed (errno = %d)\n", |
| 522 | dev->name, result); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 523 | goto fail_dmxdev; |
| 524 | } |
| 525 | |
| 526 | dvb->fe_hw.source = DMX_FRONTEND_0; |
| 527 | result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw); |
| 528 | if (result < 0) { |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 529 | dev_warn(dev->dev, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 530 | "%s: add_frontend failed (DMX_FRONTEND_0, errno = %d)\n", |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 531 | dev->name, result); |
| 532 | goto fail_fe_hw; |
| 533 | } |
| 534 | |
| 535 | dvb->fe_mem.source = DMX_MEMORY_FE; |
| 536 | result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem); |
| 537 | if (result < 0) { |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 538 | dev_warn(dev->dev, |
Mauro Carvalho Chehab | 3b795d0 | 2014-11-02 07:45:56 -0300 | [diff] [blame] | 539 | "%s: add_frontend failed (DMX_MEMORY_FE, errno = %d)\n", |
| 540 | dev->name, result); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 541 | goto fail_fe_mem; |
| 542 | } |
| 543 | |
| 544 | result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw); |
| 545 | if (result < 0) { |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 546 | dev_warn(dev->dev, |
Mauro Carvalho Chehab | 3b795d0 | 2014-11-02 07:45:56 -0300 | [diff] [blame] | 547 | "%s: connect_frontend failed (errno = %d)\n", |
| 548 | dev->name, result); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 549 | goto fail_fe_conn; |
| 550 | } |
| 551 | |
| 552 | /* register network adapter */ |
| 553 | dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx); |
Mauro Carvalho Chehab | 6168309 | 2016-02-11 22:39:52 -0200 | [diff] [blame] | 554 | result = dvb_create_media_graph(&dvb->adapter, |
| 555 | dev->tuner_type == TUNER_ABSENT); |
Mauro Carvalho Chehab | 0d3ab84 | 2015-09-04 15:33:46 -0300 | [diff] [blame] | 556 | if (result < 0) |
| 557 | goto fail_create_graph; |
Mauro Carvalho Chehab | 480884b | 2015-03-02 10:49:04 -0300 | [diff] [blame] | 558 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 559 | return 0; |
| 560 | |
Mauro Carvalho Chehab | 0d3ab84 | 2015-09-04 15:33:46 -0300 | [diff] [blame] | 561 | fail_create_graph: |
| 562 | dvb_net_release(&dvb->net); |
Sri Deevi | b925517 | 2009-03-04 17:49:01 -0300 | [diff] [blame] | 563 | fail_fe_conn: |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 564 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem); |
Sri Deevi | b925517 | 2009-03-04 17:49:01 -0300 | [diff] [blame] | 565 | fail_fe_mem: |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 566 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw); |
Sri Deevi | b925517 | 2009-03-04 17:49:01 -0300 | [diff] [blame] | 567 | fail_fe_hw: |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 568 | dvb_dmxdev_release(&dvb->dmxdev); |
Sri Deevi | b925517 | 2009-03-04 17:49:01 -0300 | [diff] [blame] | 569 | fail_dmxdev: |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 570 | dvb_dmx_release(&dvb->demux); |
Sri Deevi | b925517 | 2009-03-04 17:49:01 -0300 | [diff] [blame] | 571 | fail_dmx: |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 572 | dvb_unregister_frontend(dvb->frontend); |
Sri Deevi | b925517 | 2009-03-04 17:49:01 -0300 | [diff] [blame] | 573 | fail_frontend: |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 574 | dvb_frontend_detach(dvb->frontend); |
| 575 | dvb_unregister_adapter(&dvb->adapter); |
Sri Deevi | b925517 | 2009-03-04 17:49:01 -0300 | [diff] [blame] | 576 | fail_adapter: |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 577 | return result; |
| 578 | } |
| 579 | |
| 580 | static void unregister_dvb(struct cx231xx_dvb *dvb) |
| 581 | { |
Matthias Schwarzott | 6d3deba | 2014-07-22 17:12:14 -0300 | [diff] [blame] | 582 | struct i2c_client *client; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 583 | dvb_net_release(&dvb->net); |
| 584 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem); |
| 585 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw); |
| 586 | dvb_dmxdev_release(&dvb->dmxdev); |
| 587 | dvb_dmx_release(&dvb->demux); |
Matthias Schwarzott | 6d3deba | 2014-07-22 17:12:14 -0300 | [diff] [blame] | 588 | /* remove I2C tuner */ |
Matthias Schwarzott | d28d7f8 | 2016-07-26 04:09:04 -0300 | [diff] [blame] | 589 | client = dvb->i2c_client_tuner; |
| 590 | if (client) { |
| 591 | module_put(client->dev.driver->owner); |
| 592 | i2c_unregister_device(client); |
| 593 | } |
| 594 | /* remove I2C demod */ |
| 595 | client = dvb->i2c_client_demod; |
Matthias Schwarzott | 6d3deba | 2014-07-22 17:12:14 -0300 | [diff] [blame] | 596 | if (client) { |
| 597 | module_put(client->dev.driver->owner); |
| 598 | i2c_unregister_device(client); |
| 599 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 600 | dvb_unregister_frontend(dvb->frontend); |
| 601 | dvb_frontend_detach(dvb->frontend); |
| 602 | dvb_unregister_adapter(&dvb->adapter); |
| 603 | } |
| 604 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 605 | static int dvb_init(struct cx231xx *dev) |
| 606 | { |
| 607 | int result = 0; |
| 608 | struct cx231xx_dvb *dvb; |
Matthias Schwarzott | c3c3f1a | 2014-10-02 02:20:59 -0300 | [diff] [blame] | 609 | struct i2c_adapter *tuner_i2c; |
| 610 | struct i2c_adapter *demod_i2c; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 611 | |
| 612 | if (!dev->board.has_dvb) { |
| 613 | /* This device does not support the extension */ |
| 614 | return 0; |
| 615 | } |
| 616 | |
| 617 | dvb = kzalloc(sizeof(struct cx231xx_dvb), GFP_KERNEL); |
| 618 | |
| 619 | if (dvb == NULL) { |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 620 | dev_info(dev->dev, |
Mauro Carvalho Chehab | 3b795d0 | 2014-11-02 07:45:56 -0300 | [diff] [blame] | 621 | "cx231xx_dvb: memory allocation failed\n"); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 622 | return -ENOMEM; |
| 623 | } |
| 624 | dev->dvb = dvb; |
| 625 | dev->cx231xx_set_analog_freq = cx231xx_set_analog_freq; |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 626 | dev->cx231xx_reset_analog_tuner = cx231xx_reset_analog_tuner; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 627 | |
Matthias Schwarzott | c3c3f1a | 2014-10-02 02:20:59 -0300 | [diff] [blame] | 628 | tuner_i2c = cx231xx_get_i2c_adap(dev, dev->board.tuner_i2c_master); |
| 629 | demod_i2c = cx231xx_get_i2c_adap(dev, dev->board.demod_i2c_master); |
Devin Heitmueller | 761f6cf | 2010-07-06 19:24:19 -0300 | [diff] [blame] | 630 | mutex_lock(&dev->lock); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 631 | cx231xx_set_mode(dev, CX231XX_DIGITAL_MODE); |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 632 | cx231xx_demod_reset(dev); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 633 | /* init frontend */ |
| 634 | switch (dev->model) { |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 635 | case CX231XX_BOARD_CNXT_CARRAERA: |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 636 | case CX231XX_BOARD_CNXT_RDE_250: |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 637 | |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 638 | dev->dvb->frontend = dvb_attach(s5h1432_attach, |
| 639 | &dvico_s5h1432_config, |
Matthias Schwarzott | c3c3f1a | 2014-10-02 02:20:59 -0300 | [diff] [blame] | 640 | demod_i2c); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 641 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 642 | if (dev->dvb->frontend == NULL) { |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 643 | dev_err(dev->dev, |
Mauro Carvalho Chehab | 3b795d0 | 2014-11-02 07:45:56 -0300 | [diff] [blame] | 644 | "Failed to attach s5h1432 front end\n"); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 645 | result = -EINVAL; |
| 646 | goto out_free; |
| 647 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 648 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 649 | /* define general-purpose callback pointer */ |
| 650 | dvb->frontend->callback = cx231xx_tuner_callback; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 651 | |
Márton Németh | d5abcc7 | 2010-01-16 13:21:59 -0300 | [diff] [blame] | 652 | if (!dvb_attach(xc5000_attach, dev->dvb->frontend, |
Matthias Schwarzott | c3c3f1a | 2014-10-02 02:20:59 -0300 | [diff] [blame] | 653 | tuner_i2c, |
Márton Németh | d5abcc7 | 2010-01-16 13:21:59 -0300 | [diff] [blame] | 654 | &cnxt_rde250_tunerconfig)) { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 655 | result = -EINVAL; |
| 656 | goto out_free; |
| 657 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 658 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 659 | break; |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 660 | case CX231XX_BOARD_CNXT_SHELBY: |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 661 | case CX231XX_BOARD_CNXT_RDU_250: |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 662 | |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 663 | dev->dvb->frontend = dvb_attach(s5h1411_attach, |
| 664 | &xc5000_s5h1411_config, |
Matthias Schwarzott | c3c3f1a | 2014-10-02 02:20:59 -0300 | [diff] [blame] | 665 | demod_i2c); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 666 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 667 | if (dev->dvb->frontend == NULL) { |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 668 | dev_err(dev->dev, |
Mauro Carvalho Chehab | 3b795d0 | 2014-11-02 07:45:56 -0300 | [diff] [blame] | 669 | "Failed to attach s5h1411 front end\n"); |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 670 | result = -EINVAL; |
| 671 | goto out_free; |
| 672 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 673 | |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 674 | /* define general-purpose callback pointer */ |
| 675 | dvb->frontend->callback = cx231xx_tuner_callback; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 676 | |
Márton Németh | d5abcc7 | 2010-01-16 13:21:59 -0300 | [diff] [blame] | 677 | if (!dvb_attach(xc5000_attach, dev->dvb->frontend, |
Matthias Schwarzott | c3c3f1a | 2014-10-02 02:20:59 -0300 | [diff] [blame] | 678 | tuner_i2c, |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 679 | &cnxt_rdu250_tunerconfig)) { |
| 680 | result = -EINVAL; |
| 681 | goto out_free; |
| 682 | } |
| 683 | break; |
| 684 | case CX231XX_BOARD_CNXT_RDE_253S: |
| 685 | |
| 686 | dev->dvb->frontend = dvb_attach(s5h1432_attach, |
| 687 | &dvico_s5h1432_config, |
Matthias Schwarzott | c3c3f1a | 2014-10-02 02:20:59 -0300 | [diff] [blame] | 688 | demod_i2c); |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 689 | |
| 690 | if (dev->dvb->frontend == NULL) { |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 691 | dev_err(dev->dev, |
Mauro Carvalho Chehab | 3b795d0 | 2014-11-02 07:45:56 -0300 | [diff] [blame] | 692 | "Failed to attach s5h1432 front end\n"); |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 693 | result = -EINVAL; |
| 694 | goto out_free; |
| 695 | } |
| 696 | |
| 697 | /* define general-purpose callback pointer */ |
| 698 | dvb->frontend->callback = cx231xx_tuner_callback; |
| 699 | |
| 700 | if (!dvb_attach(tda18271_attach, dev->dvb->frontend, |
Matthias Schwarzott | c3c3f1a | 2014-10-02 02:20:59 -0300 | [diff] [blame] | 701 | 0x60, tuner_i2c, |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 702 | &cnxt_rde253s_tunerconfig)) { |
| 703 | result = -EINVAL; |
| 704 | goto out_free; |
| 705 | } |
| 706 | break; |
| 707 | case CX231XX_BOARD_CNXT_RDU_253S: |
Johannes Erdfelt | 8b1255a | 2013-08-16 21:29:02 -0300 | [diff] [blame] | 708 | case CX231XX_BOARD_KWORLD_UB445_USB_HYBRID: |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 709 | |
| 710 | dev->dvb->frontend = dvb_attach(s5h1411_attach, |
| 711 | &tda18271_s5h1411_config, |
Matthias Schwarzott | c3c3f1a | 2014-10-02 02:20:59 -0300 | [diff] [blame] | 712 | demod_i2c); |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 713 | |
| 714 | if (dev->dvb->frontend == NULL) { |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 715 | dev_err(dev->dev, |
Mauro Carvalho Chehab | 3b795d0 | 2014-11-02 07:45:56 -0300 | [diff] [blame] | 716 | "Failed to attach s5h1411 front end\n"); |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 717 | result = -EINVAL; |
| 718 | goto out_free; |
| 719 | } |
| 720 | |
| 721 | /* define general-purpose callback pointer */ |
| 722 | dvb->frontend->callback = cx231xx_tuner_callback; |
| 723 | |
| 724 | if (!dvb_attach(tda18271_attach, dev->dvb->frontend, |
Matthias Schwarzott | c3c3f1a | 2014-10-02 02:20:59 -0300 | [diff] [blame] | 725 | 0x60, tuner_i2c, |
Palash Bandyopadhyay | 64fbf44 | 2010-07-06 18:12:25 -0300 | [diff] [blame] | 726 | &cnxt_rde253s_tunerconfig)) { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 727 | result = -EINVAL; |
| 728 | goto out_free; |
| 729 | } |
| 730 | break; |
Michael Krufky | 1a50fdd | 2010-07-06 18:23:53 -0300 | [diff] [blame] | 731 | case CX231XX_BOARD_HAUPPAUGE_EXETER: |
| 732 | |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 733 | dev_info(dev->dev, |
Mauro Carvalho Chehab | 3b795d0 | 2014-11-02 07:45:56 -0300 | [diff] [blame] | 734 | "%s: looking for tuner / demod on i2c bus: %d\n", |
Matthias Schwarzott | c3c3f1a | 2014-10-02 02:20:59 -0300 | [diff] [blame] | 735 | __func__, i2c_adapter_id(tuner_i2c)); |
Michael Krufky | 1a50fdd | 2010-07-06 18:23:53 -0300 | [diff] [blame] | 736 | |
| 737 | dev->dvb->frontend = dvb_attach(lgdt3305_attach, |
| 738 | &hcw_lgdt3305_config, |
Matthias Schwarzott | 599bedb | 2015-11-13 20:54:55 -0200 | [diff] [blame] | 739 | demod_i2c); |
Michael Krufky | 1a50fdd | 2010-07-06 18:23:53 -0300 | [diff] [blame] | 740 | |
| 741 | if (dev->dvb->frontend == NULL) { |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 742 | dev_err(dev->dev, |
Mauro Carvalho Chehab | 3b795d0 | 2014-11-02 07:45:56 -0300 | [diff] [blame] | 743 | "Failed to attach LG3305 front end\n"); |
Michael Krufky | 1a50fdd | 2010-07-06 18:23:53 -0300 | [diff] [blame] | 744 | result = -EINVAL; |
| 745 | goto out_free; |
| 746 | } |
| 747 | |
| 748 | /* define general-purpose callback pointer */ |
| 749 | dvb->frontend->callback = cx231xx_tuner_callback; |
| 750 | |
| 751 | dvb_attach(tda18271_attach, dev->dvb->frontend, |
Matthias Schwarzott | c3c3f1a | 2014-10-02 02:20:59 -0300 | [diff] [blame] | 752 | 0x60, tuner_i2c, |
Michael Krufky | 1a50fdd | 2010-07-06 18:23:53 -0300 | [diff] [blame] | 753 | &hcw_tda18271_config); |
| 754 | break; |
| 755 | |
Matthias Schwarzott | dd2e7dd | 2014-07-22 17:12:15 -0300 | [diff] [blame] | 756 | case CX231XX_BOARD_HAUPPAUGE_930C_HD_1113xx: |
Matthias Schwarzott | 773028f | 2016-07-26 04:09:05 -0300 | [diff] [blame] | 757 | { |
| 758 | struct i2c_client *client; |
| 759 | struct i2c_board_info info; |
| 760 | struct si2165_platform_data si2165_pdata; |
Matthias Schwarzott | dd2e7dd | 2014-07-22 17:12:15 -0300 | [diff] [blame] | 761 | |
Matthias Schwarzott | 773028f | 2016-07-26 04:09:05 -0300 | [diff] [blame] | 762 | /* attach demod */ |
| 763 | memset(&si2165_pdata, 0, sizeof(si2165_pdata)); |
| 764 | si2165_pdata.fe = &dev->dvb->frontend; |
| 765 | si2165_pdata.chip_mode = SI2165_MODE_PLL_XTAL, |
| 766 | si2165_pdata.ref_freq_Hz = 16000000, |
Matthias Schwarzott | dd2e7dd | 2014-07-22 17:12:15 -0300 | [diff] [blame] | 767 | |
Matthias Schwarzott | 773028f | 2016-07-26 04:09:05 -0300 | [diff] [blame] | 768 | memset(&info, 0, sizeof(struct i2c_board_info)); |
| 769 | strlcpy(info.type, "si2165", I2C_NAME_SIZE); |
| 770 | info.addr = 0x64; |
| 771 | info.platform_data = &si2165_pdata; |
| 772 | request_module(info.type); |
| 773 | client = i2c_new_device(demod_i2c, &info); |
| 774 | if (client == NULL || client->dev.driver == NULL || dev->dvb->frontend == NULL) { |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 775 | dev_err(dev->dev, |
Mauro Carvalho Chehab | 3b795d0 | 2014-11-02 07:45:56 -0300 | [diff] [blame] | 776 | "Failed to attach SI2165 front end\n"); |
Matthias Schwarzott | dd2e7dd | 2014-07-22 17:12:15 -0300 | [diff] [blame] | 777 | result = -EINVAL; |
| 778 | goto out_free; |
| 779 | } |
| 780 | |
Matthias Schwarzott | 773028f | 2016-07-26 04:09:05 -0300 | [diff] [blame] | 781 | if (!try_module_get(client->dev.driver->owner)) { |
| 782 | i2c_unregister_device(client); |
| 783 | result = -ENODEV; |
| 784 | goto out_free; |
| 785 | } |
| 786 | |
| 787 | dvb->i2c_client_demod = client; |
| 788 | |
Hans Verkuil | 3f9280a | 2014-08-21 11:34:02 -0300 | [diff] [blame] | 789 | dev->dvb->frontend->ops.i2c_gate_ctrl = NULL; |
Matthias Schwarzott | dd2e7dd | 2014-07-22 17:12:15 -0300 | [diff] [blame] | 790 | |
| 791 | /* define general-purpose callback pointer */ |
| 792 | dvb->frontend->callback = cx231xx_tuner_callback; |
| 793 | |
| 794 | dvb_attach(tda18271_attach, dev->dvb->frontend, |
| 795 | 0x60, |
Matthias Schwarzott | c3c3f1a | 2014-10-02 02:20:59 -0300 | [diff] [blame] | 796 | tuner_i2c, |
Matthias Schwarzott | dd2e7dd | 2014-07-22 17:12:15 -0300 | [diff] [blame] | 797 | &hcw_tda18271_config); |
| 798 | |
| 799 | dev->cx231xx_reset_analog_tuner = NULL; |
| 800 | break; |
Matthias Schwarzott | 773028f | 2016-07-26 04:09:05 -0300 | [diff] [blame] | 801 | } |
Matthias Schwarzott | 9e49f7c | 2014-07-22 17:12:16 -0300 | [diff] [blame] | 802 | case CX231XX_BOARD_HAUPPAUGE_930C_HD_1114xx: |
| 803 | { |
| 804 | struct i2c_client *client; |
| 805 | struct i2c_board_info info; |
Matthias Schwarzott | 773028f | 2016-07-26 04:09:05 -0300 | [diff] [blame] | 806 | struct si2165_platform_data si2165_pdata; |
Matthias Schwarzott | 9e49f7c | 2014-07-22 17:12:16 -0300 | [diff] [blame] | 807 | struct si2157_config si2157_config; |
| 808 | |
Matthias Schwarzott | 773028f | 2016-07-26 04:09:05 -0300 | [diff] [blame] | 809 | /* attach demod */ |
| 810 | memset(&si2165_pdata, 0, sizeof(si2165_pdata)); |
| 811 | si2165_pdata.fe = &dev->dvb->frontend; |
| 812 | si2165_pdata.chip_mode = SI2165_MODE_PLL_EXT, |
| 813 | si2165_pdata.ref_freq_Hz = 24000000, |
| 814 | |
Matthias Schwarzott | 9e49f7c | 2014-07-22 17:12:16 -0300 | [diff] [blame] | 815 | memset(&info, 0, sizeof(struct i2c_board_info)); |
Matthias Schwarzott | 773028f | 2016-07-26 04:09:05 -0300 | [diff] [blame] | 816 | strlcpy(info.type, "si2165", I2C_NAME_SIZE); |
| 817 | info.addr = 0x64; |
| 818 | info.platform_data = &si2165_pdata; |
| 819 | request_module(info.type); |
| 820 | client = i2c_new_device(demod_i2c, &info); |
| 821 | if (client == NULL || client->dev.driver == NULL || dev->dvb->frontend == NULL) { |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 822 | dev_err(dev->dev, |
Mauro Carvalho Chehab | 3b795d0 | 2014-11-02 07:45:56 -0300 | [diff] [blame] | 823 | "Failed to attach SI2165 front end\n"); |
Matthias Schwarzott | 9e49f7c | 2014-07-22 17:12:16 -0300 | [diff] [blame] | 824 | result = -EINVAL; |
| 825 | goto out_free; |
| 826 | } |
| 827 | |
Matthias Schwarzott | 773028f | 2016-07-26 04:09:05 -0300 | [diff] [blame] | 828 | if (!try_module_get(client->dev.driver->owner)) { |
| 829 | i2c_unregister_device(client); |
| 830 | result = -ENODEV; |
| 831 | goto out_free; |
| 832 | } |
| 833 | |
| 834 | dvb->i2c_client_demod = client; |
| 835 | |
| 836 | memset(&info, 0, sizeof(struct i2c_board_info)); |
| 837 | |
Hans Verkuil | 3f9280a | 2014-08-21 11:34:02 -0300 | [diff] [blame] | 838 | dev->dvb->frontend->ops.i2c_gate_ctrl = NULL; |
Matthias Schwarzott | 9e49f7c | 2014-07-22 17:12:16 -0300 | [diff] [blame] | 839 | |
| 840 | /* define general-purpose callback pointer */ |
| 841 | dvb->frontend->callback = cx231xx_tuner_callback; |
| 842 | |
| 843 | /* attach tuner */ |
| 844 | memset(&si2157_config, 0, sizeof(si2157_config)); |
| 845 | si2157_config.fe = dev->dvb->frontend; |
Mauro Carvalho Chehab | 133bc4e | 2016-02-11 22:18:36 -0200 | [diff] [blame] | 846 | #ifdef CONFIG_MEDIA_CONTROLLER_DVB |
| 847 | si2157_config.mdev = dev->media_dev; |
| 848 | #endif |
Olli Salonen | ee3c3e4 | 2015-05-05 13:54:17 -0300 | [diff] [blame] | 849 | si2157_config.if_port = 1; |
Matthias Schwarzott | 9e49f7c | 2014-07-22 17:12:16 -0300 | [diff] [blame] | 850 | si2157_config.inversion = true; |
| 851 | strlcpy(info.type, "si2157", I2C_NAME_SIZE); |
| 852 | info.addr = 0x60; |
| 853 | info.platform_data = &si2157_config; |
| 854 | request_module("si2157"); |
| 855 | |
| 856 | client = i2c_new_device( |
Matthias Schwarzott | c3c3f1a | 2014-10-02 02:20:59 -0300 | [diff] [blame] | 857 | tuner_i2c, |
Matthias Schwarzott | 9e49f7c | 2014-07-22 17:12:16 -0300 | [diff] [blame] | 858 | &info); |
| 859 | if (client == NULL || client->dev.driver == NULL) { |
| 860 | dvb_frontend_detach(dev->dvb->frontend); |
| 861 | result = -ENODEV; |
| 862 | goto out_free; |
| 863 | } |
| 864 | |
| 865 | if (!try_module_get(client->dev.driver->owner)) { |
| 866 | i2c_unregister_device(client); |
| 867 | dvb_frontend_detach(dev->dvb->frontend); |
| 868 | result = -ENODEV; |
| 869 | goto out_free; |
| 870 | } |
| 871 | |
| 872 | dev->cx231xx_reset_analog_tuner = NULL; |
| 873 | |
| 874 | dev->dvb->i2c_client_tuner = client; |
| 875 | break; |
| 876 | } |
Olli Salonen | 809abdb | 2015-02-28 12:25:24 -0300 | [diff] [blame] | 877 | case CX231XX_BOARD_HAUPPAUGE_955Q: |
| 878 | { |
| 879 | struct i2c_client *client; |
| 880 | struct i2c_board_info info; |
| 881 | struct si2157_config si2157_config; |
Matthias Schwarzott | 9e49f7c | 2014-07-22 17:12:16 -0300 | [diff] [blame] | 882 | |
Olli Salonen | 809abdb | 2015-02-28 12:25:24 -0300 | [diff] [blame] | 883 | memset(&info, 0, sizeof(struct i2c_board_info)); |
| 884 | |
| 885 | dev->dvb->frontend = dvb_attach(lgdt3306a_attach, |
| 886 | &hauppauge_955q_lgdt3306a_config, |
Matthias Schwarzott | 599bedb | 2015-11-13 20:54:55 -0200 | [diff] [blame] | 887 | demod_i2c |
Olli Salonen | 809abdb | 2015-02-28 12:25:24 -0300 | [diff] [blame] | 888 | ); |
| 889 | |
| 890 | if (dev->dvb->frontend == NULL) { |
| 891 | dev_err(dev->dev, |
| 892 | "Failed to attach LGDT3306A frontend.\n"); |
| 893 | result = -EINVAL; |
| 894 | goto out_free; |
| 895 | } |
| 896 | |
| 897 | dev->dvb->frontend->ops.i2c_gate_ctrl = NULL; |
| 898 | |
| 899 | /* define general-purpose callback pointer */ |
| 900 | dvb->frontend->callback = cx231xx_tuner_callback; |
| 901 | |
| 902 | /* attach tuner */ |
| 903 | memset(&si2157_config, 0, sizeof(si2157_config)); |
| 904 | si2157_config.fe = dev->dvb->frontend; |
Mauro Carvalho Chehab | 133bc4e | 2016-02-11 22:18:36 -0200 | [diff] [blame] | 905 | #ifdef CONFIG_MEDIA_CONTROLLER_DVB |
| 906 | si2157_config.mdev = dev->media_dev; |
| 907 | #endif |
Olli Salonen | ee3c3e4 | 2015-05-05 13:54:17 -0300 | [diff] [blame] | 908 | si2157_config.if_port = 1; |
Olli Salonen | 809abdb | 2015-02-28 12:25:24 -0300 | [diff] [blame] | 909 | si2157_config.inversion = true; |
| 910 | strlcpy(info.type, "si2157", I2C_NAME_SIZE); |
| 911 | info.addr = 0x60; |
| 912 | info.platform_data = &si2157_config; |
| 913 | request_module("si2157"); |
| 914 | |
| 915 | client = i2c_new_device( |
| 916 | tuner_i2c, |
| 917 | &info); |
| 918 | if (client == NULL || client->dev.driver == NULL) { |
| 919 | dvb_frontend_detach(dev->dvb->frontend); |
| 920 | result = -ENODEV; |
| 921 | goto out_free; |
| 922 | } |
| 923 | |
| 924 | if (!try_module_get(client->dev.driver->owner)) { |
| 925 | i2c_unregister_device(client); |
| 926 | dvb_frontend_detach(dev->dvb->frontend); |
| 927 | result = -ENODEV; |
| 928 | goto out_free; |
| 929 | } |
| 930 | |
| 931 | dev->cx231xx_reset_analog_tuner = NULL; |
| 932 | |
| 933 | dev->dvb->i2c_client_tuner = client; |
| 934 | break; |
| 935 | } |
Mauro Carvalho Chehab | ede676c | 2010-09-27 23:44:27 -0300 | [diff] [blame] | 936 | case CX231XX_BOARD_PV_PLAYTV_USB_HYBRID: |
Márcio Alves | eeaaf81 | 2011-04-11 19:57:15 -0300 | [diff] [blame] | 937 | case CX231XX_BOARD_KWORLD_UB430_USB_HYBRID: |
Mauro Carvalho Chehab | ede676c | 2010-09-27 23:44:27 -0300 | [diff] [blame] | 938 | |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 939 | dev_info(dev->dev, |
Mauro Carvalho Chehab | 3b795d0 | 2014-11-02 07:45:56 -0300 | [diff] [blame] | 940 | "%s: looking for demod on i2c bus: %d\n", |
| 941 | __func__, i2c_adapter_id(tuner_i2c)); |
Mauro Carvalho Chehab | ede676c | 2010-09-27 23:44:27 -0300 | [diff] [blame] | 942 | |
| 943 | dev->dvb->frontend = dvb_attach(mb86a20s_attach, |
| 944 | &pv_mb86a20s_config, |
Matthias Schwarzott | c3c3f1a | 2014-10-02 02:20:59 -0300 | [diff] [blame] | 945 | demod_i2c); |
Mauro Carvalho Chehab | ede676c | 2010-09-27 23:44:27 -0300 | [diff] [blame] | 946 | |
| 947 | if (dev->dvb->frontend == NULL) { |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 948 | dev_err(dev->dev, |
Mauro Carvalho Chehab | 3b795d0 | 2014-11-02 07:45:56 -0300 | [diff] [blame] | 949 | "Failed to attach mb86a20s demod\n"); |
Mauro Carvalho Chehab | ede676c | 2010-09-27 23:44:27 -0300 | [diff] [blame] | 950 | result = -EINVAL; |
| 951 | goto out_free; |
| 952 | } |
| 953 | |
| 954 | /* define general-purpose callback pointer */ |
| 955 | dvb->frontend->callback = cx231xx_tuner_callback; |
| 956 | |
| 957 | dvb_attach(tda18271_attach, dev->dvb->frontend, |
Matthias Schwarzott | c3c3f1a | 2014-10-02 02:20:59 -0300 | [diff] [blame] | 958 | 0x60, tuner_i2c, |
Mauro Carvalho Chehab | ede676c | 2010-09-27 23:44:27 -0300 | [diff] [blame] | 959 | &pv_tda18271_config); |
| 960 | break; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 961 | |
Oleh Kravchenko | a096fd6 | 2017-01-29 16:03:51 -0200 | [diff] [blame] | 962 | case CX231XX_BOARD_EVROMEDIA_FULL_HYBRID_FULLHD: |
| 963 | { |
| 964 | struct si2157_config si2157_config = {}; |
| 965 | struct si2168_config si2168_config = {}; |
| 966 | struct i2c_board_info info = {}; |
| 967 | struct i2c_client *client; |
| 968 | struct i2c_adapter *adapter; |
| 969 | |
| 970 | /* attach demodulator chip */ |
| 971 | si2168_config.ts_mode = SI2168_TS_SERIAL; /* from *.inf file */ |
| 972 | si2168_config.fe = &dev->dvb->frontend; |
| 973 | si2168_config.i2c_adapter = &adapter; |
| 974 | si2168_config.ts_clock_inv = true; |
| 975 | |
| 976 | strlcpy(info.type, "si2168", sizeof(info.type)); |
| 977 | info.addr = dev->board.demod_addr; |
| 978 | info.platform_data = &si2168_config; |
| 979 | |
| 980 | request_module(info.type); |
| 981 | client = i2c_new_device(demod_i2c, &info); |
| 982 | |
| 983 | if (client == NULL || client->dev.driver == NULL) { |
| 984 | result = -ENODEV; |
| 985 | goto out_free; |
| 986 | } |
| 987 | |
| 988 | if (!try_module_get(client->dev.driver->owner)) { |
| 989 | i2c_unregister_device(client); |
| 990 | result = -ENODEV; |
| 991 | goto out_free; |
| 992 | } |
| 993 | |
| 994 | dvb->i2c_client_demod = client; |
| 995 | |
| 996 | /* attach tuner chip */ |
| 997 | si2157_config.fe = dev->dvb->frontend; |
| 998 | #ifdef CONFIG_MEDIA_CONTROLLER_DVB |
| 999 | si2157_config.mdev = dev->media_dev; |
| 1000 | #endif |
| 1001 | si2157_config.if_port = 1; |
| 1002 | si2157_config.inversion = false; |
| 1003 | |
| 1004 | memset(&info, 0, sizeof(info)); |
| 1005 | strlcpy(info.type, "si2157", sizeof(info.type)); |
| 1006 | info.addr = dev->board.tuner_addr; |
| 1007 | info.platform_data = &si2157_config; |
| 1008 | |
| 1009 | request_module(info.type); |
| 1010 | client = i2c_new_device(tuner_i2c, &info); |
| 1011 | |
| 1012 | if (client == NULL || client->dev.driver == NULL) { |
| 1013 | module_put(dvb->i2c_client_demod->dev.driver->owner); |
| 1014 | i2c_unregister_device(dvb->i2c_client_demod); |
| 1015 | result = -ENODEV; |
| 1016 | goto out_free; |
| 1017 | } |
| 1018 | |
| 1019 | if (!try_module_get(client->dev.driver->owner)) { |
| 1020 | i2c_unregister_device(client); |
| 1021 | module_put(dvb->i2c_client_demod->dev.driver->owner); |
| 1022 | i2c_unregister_device(dvb->i2c_client_demod); |
| 1023 | result = -ENODEV; |
| 1024 | goto out_free; |
| 1025 | } |
| 1026 | |
| 1027 | dev->cx231xx_reset_analog_tuner = NULL; |
| 1028 | dev->dvb->i2c_client_tuner = client; |
| 1029 | break; |
| 1030 | } |
Oleh Kravchenko | 0f42b33 | 2017-04-22 12:47:13 -0300 | [diff] [blame] | 1031 | case CX231XX_BOARD_ASTROMETA_T2HYBRID: |
| 1032 | { |
| 1033 | struct i2c_client *client; |
| 1034 | struct i2c_board_info info = {}; |
| 1035 | struct mn88473_config mn88473_config = {}; |
| 1036 | |
| 1037 | /* attach demodulator chip */ |
| 1038 | mn88473_config.i2c_wr_max = 16; |
| 1039 | mn88473_config.xtal = 25000000; |
| 1040 | mn88473_config.fe = &dev->dvb->frontend; |
| 1041 | |
| 1042 | strlcpy(info.type, "mn88473", sizeof(info.type)); |
| 1043 | info.addr = dev->board.demod_addr; |
| 1044 | info.platform_data = &mn88473_config; |
| 1045 | |
| 1046 | request_module(info.type); |
| 1047 | client = i2c_new_device(demod_i2c, &info); |
| 1048 | |
| 1049 | if (client == NULL || client->dev.driver == NULL) { |
| 1050 | result = -ENODEV; |
| 1051 | goto out_free; |
| 1052 | } |
| 1053 | |
| 1054 | if (!try_module_get(client->dev.driver->owner)) { |
| 1055 | i2c_unregister_device(client); |
| 1056 | result = -ENODEV; |
| 1057 | goto out_free; |
| 1058 | } |
| 1059 | |
| 1060 | dvb->i2c_client_demod = client; |
| 1061 | |
| 1062 | /* define general-purpose callback pointer */ |
| 1063 | dvb->frontend->callback = cx231xx_tuner_callback; |
| 1064 | |
| 1065 | /* attach tuner chip */ |
| 1066 | dvb_attach(r820t_attach, dev->dvb->frontend, |
| 1067 | tuner_i2c, |
| 1068 | &astrometa_t2hybrid_r820t_config); |
| 1069 | break; |
| 1070 | } |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1071 | default: |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 1072 | dev_err(dev->dev, |
Mauro Carvalho Chehab | 3b795d0 | 2014-11-02 07:45:56 -0300 | [diff] [blame] | 1073 | "%s/2: The frontend of your DVB/ATSC card isn't supported yet\n", |
| 1074 | dev->name); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1075 | break; |
| 1076 | } |
| 1077 | if (NULL == dvb->frontend) { |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 1078 | dev_err(dev->dev, |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1079 | "%s/2: frontend initialization failed\n", dev->name); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1080 | result = -EINVAL; |
| 1081 | goto out_free; |
| 1082 | } |
| 1083 | |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1084 | /* register everything */ |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 1085 | result = register_dvb(dvb, THIS_MODULE, dev, dev->dev); |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1086 | |
| 1087 | if (result < 0) |
| 1088 | goto out_free; |
| 1089 | |
Devin Heitmueller | 761f6cf | 2010-07-06 19:24:19 -0300 | [diff] [blame] | 1090 | |
Mauro Carvalho Chehab | 336fea9 | 2014-11-03 06:07:38 -0300 | [diff] [blame] | 1091 | dev_info(dev->dev, "Successfully loaded cx231xx-dvb\n"); |
Devin Heitmueller | 761f6cf | 2010-07-06 19:24:19 -0300 | [diff] [blame] | 1092 | |
| 1093 | ret: |
| 1094 | cx231xx_set_mode(dev, CX231XX_SUSPEND); |
| 1095 | mutex_unlock(&dev->lock); |
| 1096 | return result; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1097 | |
Sri Deevi | b925517 | 2009-03-04 17:49:01 -0300 | [diff] [blame] | 1098 | out_free: |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1099 | kfree(dvb); |
| 1100 | dev->dvb = NULL; |
Devin Heitmueller | 761f6cf | 2010-07-06 19:24:19 -0300 | [diff] [blame] | 1101 | goto ret; |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1102 | } |
| 1103 | |
| 1104 | static int dvb_fini(struct cx231xx *dev) |
| 1105 | { |
| 1106 | if (!dev->board.has_dvb) { |
| 1107 | /* This device does not support the extension */ |
| 1108 | return 0; |
| 1109 | } |
| 1110 | |
| 1111 | if (dev->dvb) { |
| 1112 | unregister_dvb(dev->dvb); |
| 1113 | dev->dvb = NULL; |
| 1114 | } |
| 1115 | |
| 1116 | return 0; |
| 1117 | } |
| 1118 | |
| 1119 | static struct cx231xx_ops dvb_ops = { |
Mauro Carvalho Chehab | 84b5dbf | 2009-03-03 06:14:34 -0300 | [diff] [blame] | 1120 | .id = CX231XX_DVB, |
Sri Deevi | e0d3baf | 2009-03-03 14:37:50 -0300 | [diff] [blame] | 1121 | .name = "Cx231xx dvb Extension", |
| 1122 | .init = dvb_init, |
| 1123 | .fini = dvb_fini, |
| 1124 | }; |
| 1125 | |
| 1126 | static int __init cx231xx_dvb_register(void) |
| 1127 | { |
| 1128 | return cx231xx_register_extension(&dvb_ops); |
| 1129 | } |
| 1130 | |
| 1131 | static void __exit cx231xx_dvb_unregister(void) |
| 1132 | { |
| 1133 | cx231xx_unregister_extension(&dvb_ops); |
| 1134 | } |
| 1135 | |
| 1136 | module_init(cx231xx_dvb_register); |
| 1137 | module_exit(cx231xx_dvb_unregister); |