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