1c942fddfSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later 2395d00d1SAntti Palosaari /* 37978b8a1SAntti Palosaari * Montage Technology M88DS3103/M88RS6000 demodulator driver 4395d00d1SAntti Palosaari * 5395d00d1SAntti Palosaari * Copyright (C) 2013 Antti Palosaari <crope@iki.fi> 6395d00d1SAntti Palosaari */ 7395d00d1SAntti Palosaari 8395d00d1SAntti Palosaari #include "m88ds3103_priv.h" 9395d00d1SAntti Palosaari 10bd336e63SMax Kellermann static const struct dvb_frontend_ops m88ds3103_ops; 11395d00d1SAntti Palosaari 1256ea37daSAntti Palosaari /* write single register with mask */ 1356ea37daSAntti Palosaari static int m88ds3103_update_bits(struct m88ds3103_dev *dev, 1456ea37daSAntti Palosaari u8 reg, u8 mask, u8 val) 1556ea37daSAntti Palosaari { 1656ea37daSAntti Palosaari int ret; 1756ea37daSAntti Palosaari u8 tmp; 1856ea37daSAntti Palosaari 1956ea37daSAntti Palosaari /* no need for read if whole reg is written */ 2056ea37daSAntti Palosaari if (mask != 0xff) { 2156ea37daSAntti Palosaari ret = regmap_bulk_read(dev->regmap, reg, &tmp, 1); 2256ea37daSAntti Palosaari if (ret) 2356ea37daSAntti Palosaari return ret; 2456ea37daSAntti Palosaari 2556ea37daSAntti Palosaari val &= mask; 2656ea37daSAntti Palosaari tmp &= ~mask; 2756ea37daSAntti Palosaari val |= tmp; 2856ea37daSAntti Palosaari } 2956ea37daSAntti Palosaari 3056ea37daSAntti Palosaari return regmap_bulk_write(dev->regmap, reg, &val, 1); 3156ea37daSAntti Palosaari } 3256ea37daSAntti Palosaari 3306487deeSAntti Palosaari /* write reg val table using reg addr auto increment */ 347978b8a1SAntti Palosaari static int m88ds3103_wr_reg_val_tab(struct m88ds3103_dev *dev, 3506487deeSAntti Palosaari const struct m88ds3103_reg_val *tab, int tab_len) 3606487deeSAntti Palosaari { 377978b8a1SAntti Palosaari struct i2c_client *client = dev->client; 3806487deeSAntti Palosaari int ret, i, j; 3906487deeSAntti Palosaari u8 buf[83]; 4041b9aa00SAntti Palosaari 417978b8a1SAntti Palosaari dev_dbg(&client->dev, "tab_len=%d\n", tab_len); 4206487deeSAntti Palosaari 43f4df95bcSnibble.max if (tab_len > 86) { 4406487deeSAntti Palosaari ret = -EINVAL; 4506487deeSAntti Palosaari goto err; 4606487deeSAntti Palosaari } 4706487deeSAntti Palosaari 4806487deeSAntti Palosaari for (i = 0, j = 0; i < tab_len; i++, j++) { 4906487deeSAntti Palosaari buf[j] = tab[i].val; 5006487deeSAntti Palosaari 5106487deeSAntti Palosaari if (i == tab_len - 1 || tab[i].reg != tab[i + 1].reg - 1 || 527978b8a1SAntti Palosaari !((j + 1) % (dev->cfg->i2c_wr_max - 1))) { 53478932b1SAntti Palosaari ret = regmap_bulk_write(dev->regmap, tab[i].reg - j, buf, j + 1); 5406487deeSAntti Palosaari if (ret) 5506487deeSAntti Palosaari goto err; 5606487deeSAntti Palosaari 5706487deeSAntti Palosaari j = -1; 5806487deeSAntti Palosaari } 5906487deeSAntti Palosaari } 6006487deeSAntti Palosaari 6106487deeSAntti Palosaari return 0; 6206487deeSAntti Palosaari err: 637978b8a1SAntti Palosaari dev_dbg(&client->dev, "failed=%d\n", ret); 6406487deeSAntti Palosaari return ret; 6506487deeSAntti Palosaari } 6606487deeSAntti Palosaari 670f91c9d6SDavid Howells /* 68e6089fecSBrad Love * m88ds3103b demod has an internal device related to clocking. First the i2c 69e6089fecSBrad Love * gate must be opened, for one transaction, then writes will be allowed. 70e6089fecSBrad Love */ 71e6089fecSBrad Love static int m88ds3103b_dt_write(struct m88ds3103_dev *dev, int reg, int data) 72e6089fecSBrad Love { 73e6089fecSBrad Love struct i2c_client *client = dev->client; 74e6089fecSBrad Love u8 buf[] = {reg, data}; 75e6089fecSBrad Love u8 val; 76e6089fecSBrad Love int ret; 77e6089fecSBrad Love struct i2c_msg msg = { 78e6089fecSBrad Love .addr = dev->dt_addr, .flags = 0, .buf = buf, .len = 2 79e6089fecSBrad Love }; 80e6089fecSBrad Love 81e6089fecSBrad Love m88ds3103_update_bits(dev, 0x11, 0x01, 0x00); 82e6089fecSBrad Love 83e6089fecSBrad Love val = 0x11; 84e6089fecSBrad Love ret = regmap_write(dev->regmap, 0x03, val); 85e6089fecSBrad Love if (ret) 86e6089fecSBrad Love dev_dbg(&client->dev, "fail=%d\n", ret); 87e6089fecSBrad Love 88e6089fecSBrad Love ret = i2c_transfer(dev->dt_client->adapter, &msg, 1); 89e6089fecSBrad Love if (ret != 1) { 90e6089fecSBrad Love dev_err(&client->dev, "0x%02x (ret=%i, reg=0x%02x, value=0x%02x)\n", 91e6089fecSBrad Love dev->dt_addr, ret, reg, data); 92e6089fecSBrad Love 93e6089fecSBrad Love m88ds3103_update_bits(dev, 0x11, 0x01, 0x01); 94e6089fecSBrad Love return -EREMOTEIO; 95e6089fecSBrad Love } 96e6089fecSBrad Love m88ds3103_update_bits(dev, 0x11, 0x01, 0x01); 97e6089fecSBrad Love 98e6089fecSBrad Love dev_dbg(&client->dev, "0x%02x reg 0x%02x, value 0x%02x\n", 99e6089fecSBrad Love dev->dt_addr, reg, data); 100e6089fecSBrad Love 101e6089fecSBrad Love return 0; 102e6089fecSBrad Love } 103e6089fecSBrad Love 104e6089fecSBrad Love /* 105e6089fecSBrad Love * m88ds3103b demod has an internal device related to clocking. First the i2c 106e6089fecSBrad Love * gate must be opened, for two transactions, then reads will be allowed. 107e6089fecSBrad Love */ 108e6089fecSBrad Love static int m88ds3103b_dt_read(struct m88ds3103_dev *dev, u8 reg) 109e6089fecSBrad Love { 110e6089fecSBrad Love struct i2c_client *client = dev->client; 111e6089fecSBrad Love int ret; 112e6089fecSBrad Love u8 val; 113e6089fecSBrad Love u8 b0[] = { reg }; 114e6089fecSBrad Love u8 b1[] = { 0 }; 115e6089fecSBrad Love struct i2c_msg msg[] = { 116e6089fecSBrad Love { 117e6089fecSBrad Love .addr = dev->dt_addr, 118e6089fecSBrad Love .flags = 0, 119e6089fecSBrad Love .buf = b0, 120e6089fecSBrad Love .len = 1 121e6089fecSBrad Love }, 122e6089fecSBrad Love { 123e6089fecSBrad Love .addr = dev->dt_addr, 124e6089fecSBrad Love .flags = I2C_M_RD, 125e6089fecSBrad Love .buf = b1, 126e6089fecSBrad Love .len = 1 127e6089fecSBrad Love } 128e6089fecSBrad Love }; 129e6089fecSBrad Love 130e6089fecSBrad Love m88ds3103_update_bits(dev, 0x11, 0x01, 0x00); 131e6089fecSBrad Love 132e6089fecSBrad Love val = 0x12; 133e6089fecSBrad Love ret = regmap_write(dev->regmap, 0x03, val); 134e6089fecSBrad Love if (ret) 135e6089fecSBrad Love dev_dbg(&client->dev, "fail=%d\n", ret); 136e6089fecSBrad Love 137e6089fecSBrad Love ret = i2c_transfer(dev->dt_client->adapter, msg, 2); 138e6089fecSBrad Love if (ret != 2) { 139e6089fecSBrad Love dev_err(&client->dev, "0x%02x (ret=%d, reg=0x%02x)\n", 140e6089fecSBrad Love dev->dt_addr, ret, reg); 141e6089fecSBrad Love 142e6089fecSBrad Love m88ds3103_update_bits(dev, 0x11, 0x01, 0x01); 143e6089fecSBrad Love return -EREMOTEIO; 144e6089fecSBrad Love } 145e6089fecSBrad Love m88ds3103_update_bits(dev, 0x11, 0x01, 0x01); 146e6089fecSBrad Love 147e6089fecSBrad Love dev_dbg(&client->dev, "0x%02x reg 0x%02x, value 0x%02x\n", 148e6089fecSBrad Love dev->dt_addr, reg, b1[0]); 149e6089fecSBrad Love 150e6089fecSBrad Love return b1[0]; 151e6089fecSBrad Love } 152e6089fecSBrad Love 153e6089fecSBrad Love /* 1540f91c9d6SDavid Howells * Get the demodulator AGC PWM voltage setting supplied to the tuner. 1550f91c9d6SDavid Howells */ 1560f91c9d6SDavid Howells int m88ds3103_get_agc_pwm(struct dvb_frontend *fe, u8 *_agc_pwm) 1570f91c9d6SDavid Howells { 1580f91c9d6SDavid Howells struct m88ds3103_dev *dev = fe->demodulator_priv; 1590f91c9d6SDavid Howells unsigned tmp; 1600f91c9d6SDavid Howells int ret; 1610f91c9d6SDavid Howells 1620f91c9d6SDavid Howells ret = regmap_read(dev->regmap, 0x3f, &tmp); 1630f91c9d6SDavid Howells if (ret == 0) 1640f91c9d6SDavid Howells *_agc_pwm = tmp; 1650f91c9d6SDavid Howells return ret; 1660f91c9d6SDavid Howells } 1670f91c9d6SDavid Howells EXPORT_SYMBOL(m88ds3103_get_agc_pwm); 1680f91c9d6SDavid Howells 1690df289a2SMauro Carvalho Chehab static int m88ds3103_read_status(struct dvb_frontend *fe, 1700df289a2SMauro Carvalho Chehab enum fe_status *status) 171395d00d1SAntti Palosaari { 1727978b8a1SAntti Palosaari struct m88ds3103_dev *dev = fe->demodulator_priv; 1737978b8a1SAntti Palosaari struct i2c_client *client = dev->client; 174395d00d1SAntti Palosaari struct dtv_frontend_properties *c = &fe->dtv_property_cache; 175c1daf651SAntti Palosaari int ret, i, itmp; 176478932b1SAntti Palosaari unsigned int utmp; 177c1daf651SAntti Palosaari u8 buf[3]; 178395d00d1SAntti Palosaari 179395d00d1SAntti Palosaari *status = 0; 180395d00d1SAntti Palosaari 1817978b8a1SAntti Palosaari if (!dev->warm) { 182395d00d1SAntti Palosaari ret = -EAGAIN; 183395d00d1SAntti Palosaari goto err; 184395d00d1SAntti Palosaari } 185395d00d1SAntti Palosaari 186395d00d1SAntti Palosaari switch (c->delivery_system) { 187395d00d1SAntti Palosaari case SYS_DVBS: 188478932b1SAntti Palosaari ret = regmap_read(dev->regmap, 0xd1, &utmp); 189395d00d1SAntti Palosaari if (ret) 190395d00d1SAntti Palosaari goto err; 191395d00d1SAntti Palosaari 192478932b1SAntti Palosaari if ((utmp & 0x07) == 0x07) 193395d00d1SAntti Palosaari *status = FE_HAS_SIGNAL | FE_HAS_CARRIER | 194395d00d1SAntti Palosaari FE_HAS_VITERBI | FE_HAS_SYNC | 195395d00d1SAntti Palosaari FE_HAS_LOCK; 196395d00d1SAntti Palosaari break; 197395d00d1SAntti Palosaari case SYS_DVBS2: 198478932b1SAntti Palosaari ret = regmap_read(dev->regmap, 0x0d, &utmp); 199395d00d1SAntti Palosaari if (ret) 200395d00d1SAntti Palosaari goto err; 201395d00d1SAntti Palosaari 202478932b1SAntti Palosaari if ((utmp & 0x8f) == 0x8f) 203395d00d1SAntti Palosaari *status = FE_HAS_SIGNAL | FE_HAS_CARRIER | 204395d00d1SAntti Palosaari FE_HAS_VITERBI | FE_HAS_SYNC | 205395d00d1SAntti Palosaari FE_HAS_LOCK; 206395d00d1SAntti Palosaari break; 207395d00d1SAntti Palosaari default: 2087978b8a1SAntti Palosaari dev_dbg(&client->dev, "invalid delivery_system\n"); 209395d00d1SAntti Palosaari ret = -EINVAL; 210395d00d1SAntti Palosaari goto err; 211395d00d1SAntti Palosaari } 212395d00d1SAntti Palosaari 2137978b8a1SAntti Palosaari dev->fe_status = *status; 214478932b1SAntti Palosaari dev_dbg(&client->dev, "lock=%02x status=%02x\n", utmp, *status); 215395d00d1SAntti Palosaari 216c1daf651SAntti Palosaari /* CNR */ 2177978b8a1SAntti Palosaari if (dev->fe_status & FE_HAS_VITERBI) { 218c1daf651SAntti Palosaari unsigned int cnr, noise, signal, noise_tot, signal_tot; 219c1daf651SAntti Palosaari 220c1daf651SAntti Palosaari cnr = 0; 221c1daf651SAntti Palosaari /* more iterations for more accurate estimation */ 222c1daf651SAntti Palosaari #define M88DS3103_SNR_ITERATIONS 3 223c1daf651SAntti Palosaari 224c1daf651SAntti Palosaari switch (c->delivery_system) { 225c1daf651SAntti Palosaari case SYS_DVBS: 226c1daf651SAntti Palosaari itmp = 0; 227c1daf651SAntti Palosaari 228c1daf651SAntti Palosaari for (i = 0; i < M88DS3103_SNR_ITERATIONS; i++) { 229478932b1SAntti Palosaari ret = regmap_read(dev->regmap, 0xff, &utmp); 230c1daf651SAntti Palosaari if (ret) 231c1daf651SAntti Palosaari goto err; 232c1daf651SAntti Palosaari 233478932b1SAntti Palosaari itmp += utmp; 234c1daf651SAntti Palosaari } 235c1daf651SAntti Palosaari 236c1daf651SAntti Palosaari /* use of single register limits max value to 15 dB */ 237c1daf651SAntti Palosaari /* SNR(X) dB = 10 * ln(X) / ln(10) dB */ 238c1daf651SAntti Palosaari itmp = DIV_ROUND_CLOSEST(itmp, 8 * M88DS3103_SNR_ITERATIONS); 239c1daf651SAntti Palosaari if (itmp) 240c1daf651SAntti Palosaari cnr = div_u64((u64) 10000 * intlog2(itmp), intlog2(10)); 241c1daf651SAntti Palosaari break; 242c1daf651SAntti Palosaari case SYS_DVBS2: 243c1daf651SAntti Palosaari noise_tot = 0; 244c1daf651SAntti Palosaari signal_tot = 0; 245c1daf651SAntti Palosaari 246c1daf651SAntti Palosaari for (i = 0; i < M88DS3103_SNR_ITERATIONS; i++) { 247478932b1SAntti Palosaari ret = regmap_bulk_read(dev->regmap, 0x8c, buf, 3); 248c1daf651SAntti Palosaari if (ret) 249c1daf651SAntti Palosaari goto err; 250c1daf651SAntti Palosaari 251c1daf651SAntti Palosaari noise = buf[1] << 6; /* [13:6] */ 252c1daf651SAntti Palosaari noise |= buf[0] & 0x3f; /* [5:0] */ 253c1daf651SAntti Palosaari noise >>= 2; 254c1daf651SAntti Palosaari signal = buf[2] * buf[2]; 255c1daf651SAntti Palosaari signal >>= 1; 256c1daf651SAntti Palosaari 257c1daf651SAntti Palosaari noise_tot += noise; 258c1daf651SAntti Palosaari signal_tot += signal; 259c1daf651SAntti Palosaari } 260c1daf651SAntti Palosaari 261c1daf651SAntti Palosaari noise = noise_tot / M88DS3103_SNR_ITERATIONS; 262c1daf651SAntti Palosaari signal = signal_tot / M88DS3103_SNR_ITERATIONS; 263c1daf651SAntti Palosaari 264c1daf651SAntti Palosaari /* SNR(X) dB = 10 * log10(X) dB */ 265c1daf651SAntti Palosaari if (signal > noise) { 266c1daf651SAntti Palosaari itmp = signal / noise; 267c1daf651SAntti Palosaari cnr = div_u64((u64) 10000 * intlog10(itmp), (1 << 24)); 268c1daf651SAntti Palosaari } 269c1daf651SAntti Palosaari break; 270c1daf651SAntti Palosaari default: 2717978b8a1SAntti Palosaari dev_dbg(&client->dev, "invalid delivery_system\n"); 272c1daf651SAntti Palosaari ret = -EINVAL; 273c1daf651SAntti Palosaari goto err; 274c1daf651SAntti Palosaari } 275c1daf651SAntti Palosaari 276c1daf651SAntti Palosaari if (cnr) { 277c1daf651SAntti Palosaari c->cnr.stat[0].scale = FE_SCALE_DECIBEL; 278c1daf651SAntti Palosaari c->cnr.stat[0].svalue = cnr; 279c1daf651SAntti Palosaari } else { 280c1daf651SAntti Palosaari c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; 281c1daf651SAntti Palosaari } 282c1daf651SAntti Palosaari } else { 283c1daf651SAntti Palosaari c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; 284c1daf651SAntti Palosaari } 285c1daf651SAntti Palosaari 286ce80d713SAntti Palosaari /* BER */ 2877978b8a1SAntti Palosaari if (dev->fe_status & FE_HAS_LOCK) { 288ce80d713SAntti Palosaari unsigned int utmp, post_bit_error, post_bit_count; 289ce80d713SAntti Palosaari 290ce80d713SAntti Palosaari switch (c->delivery_system) { 291ce80d713SAntti Palosaari case SYS_DVBS: 292478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xf9, 0x04); 293ce80d713SAntti Palosaari if (ret) 294ce80d713SAntti Palosaari goto err; 295ce80d713SAntti Palosaari 296478932b1SAntti Palosaari ret = regmap_read(dev->regmap, 0xf8, &utmp); 297ce80d713SAntti Palosaari if (ret) 298ce80d713SAntti Palosaari goto err; 299ce80d713SAntti Palosaari 300ce80d713SAntti Palosaari /* measurement ready? */ 301478932b1SAntti Palosaari if (!(utmp & 0x10)) { 302478932b1SAntti Palosaari ret = regmap_bulk_read(dev->regmap, 0xf6, buf, 2); 303ce80d713SAntti Palosaari if (ret) 304ce80d713SAntti Palosaari goto err; 305ce80d713SAntti Palosaari 306ce80d713SAntti Palosaari post_bit_error = buf[1] << 8 | buf[0] << 0; 307ce80d713SAntti Palosaari post_bit_count = 0x800000; 3087978b8a1SAntti Palosaari dev->post_bit_error += post_bit_error; 3097978b8a1SAntti Palosaari dev->post_bit_count += post_bit_count; 3107978b8a1SAntti Palosaari dev->dvbv3_ber = post_bit_error; 311ce80d713SAntti Palosaari 312ce80d713SAntti Palosaari /* restart measurement */ 313478932b1SAntti Palosaari utmp |= 0x10; 314478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xf8, utmp); 315ce80d713SAntti Palosaari if (ret) 316ce80d713SAntti Palosaari goto err; 317ce80d713SAntti Palosaari } 318ce80d713SAntti Palosaari break; 319ce80d713SAntti Palosaari case SYS_DVBS2: 320478932b1SAntti Palosaari ret = regmap_bulk_read(dev->regmap, 0xd5, buf, 3); 321ce80d713SAntti Palosaari if (ret) 322ce80d713SAntti Palosaari goto err; 323ce80d713SAntti Palosaari 324ce80d713SAntti Palosaari utmp = buf[2] << 16 | buf[1] << 8 | buf[0] << 0; 325ce80d713SAntti Palosaari 326ce80d713SAntti Palosaari /* enough data? */ 327ce80d713SAntti Palosaari if (utmp > 4000) { 328478932b1SAntti Palosaari ret = regmap_bulk_read(dev->regmap, 0xf7, buf, 2); 329ce80d713SAntti Palosaari if (ret) 330ce80d713SAntti Palosaari goto err; 331ce80d713SAntti Palosaari 332ce80d713SAntti Palosaari post_bit_error = buf[1] << 8 | buf[0] << 0; 333ce80d713SAntti Palosaari post_bit_count = 32 * utmp; /* TODO: FEC */ 3347978b8a1SAntti Palosaari dev->post_bit_error += post_bit_error; 3357978b8a1SAntti Palosaari dev->post_bit_count += post_bit_count; 3367978b8a1SAntti Palosaari dev->dvbv3_ber = post_bit_error; 337ce80d713SAntti Palosaari 338ce80d713SAntti Palosaari /* restart measurement */ 339478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xd1, 0x01); 340ce80d713SAntti Palosaari if (ret) 341ce80d713SAntti Palosaari goto err; 342ce80d713SAntti Palosaari 343478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xf9, 0x01); 344ce80d713SAntti Palosaari if (ret) 345ce80d713SAntti Palosaari goto err; 346ce80d713SAntti Palosaari 347478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xf9, 0x00); 348ce80d713SAntti Palosaari if (ret) 349ce80d713SAntti Palosaari goto err; 350ce80d713SAntti Palosaari 351478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xd1, 0x00); 352ce80d713SAntti Palosaari if (ret) 353ce80d713SAntti Palosaari goto err; 354ce80d713SAntti Palosaari } 355ce80d713SAntti Palosaari break; 356ce80d713SAntti Palosaari default: 3577978b8a1SAntti Palosaari dev_dbg(&client->dev, "invalid delivery_system\n"); 358ce80d713SAntti Palosaari ret = -EINVAL; 359ce80d713SAntti Palosaari goto err; 360ce80d713SAntti Palosaari } 361ce80d713SAntti Palosaari 362ce80d713SAntti Palosaari c->post_bit_error.stat[0].scale = FE_SCALE_COUNTER; 3637978b8a1SAntti Palosaari c->post_bit_error.stat[0].uvalue = dev->post_bit_error; 364ce80d713SAntti Palosaari c->post_bit_count.stat[0].scale = FE_SCALE_COUNTER; 3657978b8a1SAntti Palosaari c->post_bit_count.stat[0].uvalue = dev->post_bit_count; 366ce80d713SAntti Palosaari } else { 367ce80d713SAntti Palosaari c->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; 368ce80d713SAntti Palosaari c->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE; 369ce80d713SAntti Palosaari } 370ce80d713SAntti Palosaari 371395d00d1SAntti Palosaari return 0; 372395d00d1SAntti Palosaari err: 3737978b8a1SAntti Palosaari dev_dbg(&client->dev, "failed=%d\n", ret); 374395d00d1SAntti Palosaari return ret; 375395d00d1SAntti Palosaari } 376395d00d1SAntti Palosaari 377e6089fecSBrad Love static int m88ds3103b_select_mclk(struct m88ds3103_dev *dev) 378e6089fecSBrad Love { 379e6089fecSBrad Love struct i2c_client *client = dev->client; 380e6089fecSBrad Love struct dtv_frontend_properties *c = &dev->fe.dtv_property_cache; 381e6089fecSBrad Love u32 adc_Freq_MHz[3] = {96, 93, 99}; 382e6089fecSBrad Love u8 reg16_list[3] = {96, 92, 100}, reg16, reg15; 383e6089fecSBrad Love u32 offset_MHz[3]; 384e6089fecSBrad Love u32 max_offset = 0; 385e6089fecSBrad Love u32 old_setting = dev->mclk; 386e6089fecSBrad Love u32 tuner_freq_MHz = c->frequency / 1000; 387e6089fecSBrad Love u8 i; 388e6089fecSBrad Love char big_symbol = 0; 389e6089fecSBrad Love 390e6089fecSBrad Love big_symbol = (c->symbol_rate > 45010000) ? 1 : 0; 391e6089fecSBrad Love 392e6089fecSBrad Love if (big_symbol) { 393e6089fecSBrad Love reg16 = 115; 394e6089fecSBrad Love } else { 395e6089fecSBrad Love reg16 = 96; 396e6089fecSBrad Love 397e6089fecSBrad Love /* TODO: IS THIS NECESSARY ? */ 398e6089fecSBrad Love for (i = 0; i < 3; i++) { 399e6089fecSBrad Love offset_MHz[i] = tuner_freq_MHz % adc_Freq_MHz[i]; 400e6089fecSBrad Love 401e6089fecSBrad Love if (offset_MHz[i] > (adc_Freq_MHz[i] / 2)) 402e6089fecSBrad Love offset_MHz[i] = adc_Freq_MHz[i] - offset_MHz[i]; 403e6089fecSBrad Love 404e6089fecSBrad Love if (offset_MHz[i] > max_offset) { 405e6089fecSBrad Love max_offset = offset_MHz[i]; 406e6089fecSBrad Love reg16 = reg16_list[i]; 407e6089fecSBrad Love dev->mclk = adc_Freq_MHz[i] * 1000 * 1000; 408e6089fecSBrad Love 409e6089fecSBrad Love if (big_symbol) 410e6089fecSBrad Love dev->mclk /= 2; 411e6089fecSBrad Love 412e6089fecSBrad Love dev_dbg(&client->dev, "modifying mclk %u -> %u\n", 413e6089fecSBrad Love old_setting, dev->mclk); 414e6089fecSBrad Love } 415e6089fecSBrad Love } 416e6089fecSBrad Love } 417e6089fecSBrad Love 418e6089fecSBrad Love if (dev->mclk == 93000000) 419e6089fecSBrad Love regmap_write(dev->regmap, 0xA0, 0x42); 420e6089fecSBrad Love else if (dev->mclk == 96000000) 421e6089fecSBrad Love regmap_write(dev->regmap, 0xA0, 0x44); 422e6089fecSBrad Love else if (dev->mclk == 99000000) 423e6089fecSBrad Love regmap_write(dev->regmap, 0xA0, 0x46); 424e6089fecSBrad Love else if (dev->mclk == 110250000) 425e6089fecSBrad Love regmap_write(dev->regmap, 0xA0, 0x4E); 426e6089fecSBrad Love else 427e6089fecSBrad Love regmap_write(dev->regmap, 0xA0, 0x44); 428e6089fecSBrad Love 429e6089fecSBrad Love reg15 = m88ds3103b_dt_read(dev, 0x15); 430e6089fecSBrad Love 431e6089fecSBrad Love m88ds3103b_dt_write(dev, 0x05, 0x40); 432e6089fecSBrad Love m88ds3103b_dt_write(dev, 0x11, 0x08); 433e6089fecSBrad Love 434e6089fecSBrad Love if (big_symbol) 435e6089fecSBrad Love reg15 |= 0x02; 436e6089fecSBrad Love else 437e6089fecSBrad Love reg15 &= ~0x02; 438e6089fecSBrad Love 439e6089fecSBrad Love m88ds3103b_dt_write(dev, 0x15, reg15); 440e6089fecSBrad Love m88ds3103b_dt_write(dev, 0x16, reg16); 441e6089fecSBrad Love 442e6089fecSBrad Love usleep_range(5000, 5500); 443e6089fecSBrad Love 444e6089fecSBrad Love m88ds3103b_dt_write(dev, 0x05, 0x00); 445e6089fecSBrad Love m88ds3103b_dt_write(dev, 0x11, (u8)(big_symbol ? 0x0E : 0x0A)); 446e6089fecSBrad Love 447e6089fecSBrad Love usleep_range(5000, 5500); 448e6089fecSBrad Love 449e6089fecSBrad Love return 0; 450e6089fecSBrad Love } 451e6089fecSBrad Love 452e6089fecSBrad Love static int m88ds3103b_set_mclk(struct m88ds3103_dev *dev, u32 mclk_khz) 453e6089fecSBrad Love { 454e6089fecSBrad Love u8 reg11 = 0x0A, reg15, reg16, reg1D, reg1E, reg1F, tmp; 455e6089fecSBrad Love u8 sm, f0 = 0, f1 = 0, f2 = 0, f3 = 0; 456e6089fecSBrad Love u16 pll_div_fb, N; 457e6089fecSBrad Love u32 div; 458e6089fecSBrad Love 459e6089fecSBrad Love reg15 = m88ds3103b_dt_read(dev, 0x15); 460e6089fecSBrad Love reg16 = m88ds3103b_dt_read(dev, 0x16); 461e6089fecSBrad Love reg1D = m88ds3103b_dt_read(dev, 0x1D); 462e6089fecSBrad Love 463e6089fecSBrad Love if (dev->cfg->ts_mode != M88DS3103_TS_SERIAL) { 464e6089fecSBrad Love if (reg16 == 92) 465e6089fecSBrad Love tmp = 93; 466e6089fecSBrad Love else if (reg16 == 100) 467e6089fecSBrad Love tmp = 99; 468e6089fecSBrad Love else 469e6089fecSBrad Love tmp = 96; 470e6089fecSBrad Love 471e6089fecSBrad Love mclk_khz *= tmp; 472e6089fecSBrad Love mclk_khz /= 96; 473e6089fecSBrad Love } 474e6089fecSBrad Love 475e6089fecSBrad Love pll_div_fb = (reg15 & 0x01) << 8; 476e6089fecSBrad Love pll_div_fb += reg16; 477e6089fecSBrad Love pll_div_fb += 32; 478e6089fecSBrad Love 479e6089fecSBrad Love div = 9000 * pll_div_fb * 4; 480e6089fecSBrad Love div /= mclk_khz; 481e6089fecSBrad Love 482e6089fecSBrad Love if (dev->cfg->ts_mode == M88DS3103_TS_SERIAL) { 483e6089fecSBrad Love reg11 |= 0x02; 484e6089fecSBrad Love 485e6089fecSBrad Love if (div <= 32) { 486e6089fecSBrad Love N = 2; 487e6089fecSBrad Love 488e6089fecSBrad Love f0 = 0; 489e6089fecSBrad Love f1 = div / N; 490e6089fecSBrad Love f2 = div - f1; 491e6089fecSBrad Love f3 = 0; 492e6089fecSBrad Love } else if (div <= 34) { 493e6089fecSBrad Love N = 3; 494e6089fecSBrad Love 495e6089fecSBrad Love f0 = div / N; 496e6089fecSBrad Love f1 = (div - f0) / (N - 1); 497e6089fecSBrad Love f2 = div - f0 - f1; 498e6089fecSBrad Love f3 = 0; 499e6089fecSBrad Love } else if (div <= 64) { 500e6089fecSBrad Love N = 4; 501e6089fecSBrad Love 502e6089fecSBrad Love f0 = div / N; 503e6089fecSBrad Love f1 = (div - f0) / (N - 1); 504e6089fecSBrad Love f2 = (div - f0 - f1) / (N - 2); 505e6089fecSBrad Love f3 = div - f0 - f1 - f2; 506e6089fecSBrad Love } else { 507e6089fecSBrad Love N = 4; 508e6089fecSBrad Love 509e6089fecSBrad Love f0 = 16; 510e6089fecSBrad Love f1 = 16; 511e6089fecSBrad Love f2 = 16; 512e6089fecSBrad Love f3 = 16; 513e6089fecSBrad Love } 514e6089fecSBrad Love 515e6089fecSBrad Love if (f0 == 16) 516e6089fecSBrad Love f0 = 0; 517e6089fecSBrad Love else if ((f0 < 8) && (f0 != 0)) 518e6089fecSBrad Love f0 = 8; 519e6089fecSBrad Love 520e6089fecSBrad Love if (f1 == 16) 521e6089fecSBrad Love f1 = 0; 522e6089fecSBrad Love else if ((f1 < 8) && (f1 != 0)) 523e6089fecSBrad Love f1 = 8; 524e6089fecSBrad Love 525e6089fecSBrad Love if (f2 == 16) 526e6089fecSBrad Love f2 = 0; 527e6089fecSBrad Love else if ((f2 < 8) && (f2 != 0)) 528e6089fecSBrad Love f2 = 8; 529e6089fecSBrad Love 530e6089fecSBrad Love if (f3 == 16) 531e6089fecSBrad Love f3 = 0; 532e6089fecSBrad Love else if ((f3 < 8) && (f3 != 0)) 533e6089fecSBrad Love f3 = 8; 534e6089fecSBrad Love } else { 535e6089fecSBrad Love reg11 &= ~0x02; 536e6089fecSBrad Love 537e6089fecSBrad Love if (div <= 32) { 538e6089fecSBrad Love N = 2; 539e6089fecSBrad Love 540e6089fecSBrad Love f0 = 0; 541e6089fecSBrad Love f1 = div / N; 542e6089fecSBrad Love f2 = div - f1; 543e6089fecSBrad Love f3 = 0; 544e6089fecSBrad Love } else if (div <= 48) { 545e6089fecSBrad Love N = 3; 546e6089fecSBrad Love 547e6089fecSBrad Love f0 = div / N; 548e6089fecSBrad Love f1 = (div - f0) / (N - 1); 549e6089fecSBrad Love f2 = div - f0 - f1; 550e6089fecSBrad Love f3 = 0; 551e6089fecSBrad Love } else if (div <= 64) { 552e6089fecSBrad Love N = 4; 553e6089fecSBrad Love 554e6089fecSBrad Love f0 = div / N; 555e6089fecSBrad Love f1 = (div - f0) / (N - 1); 556e6089fecSBrad Love f2 = (div - f0 - f1) / (N - 2); 557e6089fecSBrad Love f3 = div - f0 - f1 - f2; 558e6089fecSBrad Love } else { 559e6089fecSBrad Love N = 4; 560e6089fecSBrad Love 561e6089fecSBrad Love f0 = 16; 562e6089fecSBrad Love f1 = 16; 563e6089fecSBrad Love f2 = 16; 564e6089fecSBrad Love f3 = 16; 565e6089fecSBrad Love } 566e6089fecSBrad Love 567e6089fecSBrad Love if (f0 == 16) 568e6089fecSBrad Love f0 = 0; 569e6089fecSBrad Love else if ((f0 < 9) && (f0 != 0)) 570e6089fecSBrad Love f0 = 9; 571e6089fecSBrad Love 572e6089fecSBrad Love if (f1 == 16) 573e6089fecSBrad Love f1 = 0; 574e6089fecSBrad Love else if ((f1 < 9) && (f1 != 0)) 575e6089fecSBrad Love f1 = 9; 576e6089fecSBrad Love 577e6089fecSBrad Love if (f2 == 16) 578e6089fecSBrad Love f2 = 0; 579e6089fecSBrad Love else if ((f2 < 9) && (f2 != 0)) 580e6089fecSBrad Love f2 = 9; 581e6089fecSBrad Love 582e6089fecSBrad Love if (f3 == 16) 583e6089fecSBrad Love f3 = 0; 584e6089fecSBrad Love else if ((f3 < 9) && (f3 != 0)) 585e6089fecSBrad Love f3 = 9; 586e6089fecSBrad Love } 587e6089fecSBrad Love 588e6089fecSBrad Love sm = N - 1; 589e6089fecSBrad Love 590e6089fecSBrad Love /* Write to registers */ 591e6089fecSBrad Love //reg15 &= 0x01; 592e6089fecSBrad Love //reg15 |= (pll_div_fb >> 8) & 0x01; 593e6089fecSBrad Love 594e6089fecSBrad Love //reg16 = pll_div_fb & 0xFF; 595e6089fecSBrad Love 596e6089fecSBrad Love reg1D &= ~0x03; 597e6089fecSBrad Love reg1D |= sm; 598e6089fecSBrad Love reg1D |= 0x80; 599e6089fecSBrad Love 600e6089fecSBrad Love reg1E = ((f3 << 4) + f2) & 0xFF; 601e6089fecSBrad Love reg1F = ((f1 << 4) + f0) & 0xFF; 602e6089fecSBrad Love 603e6089fecSBrad Love m88ds3103b_dt_write(dev, 0x05, 0x40); 604e6089fecSBrad Love m88ds3103b_dt_write(dev, 0x11, 0x08); 605e6089fecSBrad Love m88ds3103b_dt_write(dev, 0x1D, reg1D); 606e6089fecSBrad Love m88ds3103b_dt_write(dev, 0x1E, reg1E); 607e6089fecSBrad Love m88ds3103b_dt_write(dev, 0x1F, reg1F); 608e6089fecSBrad Love 609e6089fecSBrad Love m88ds3103b_dt_write(dev, 0x17, 0xc1); 610e6089fecSBrad Love m88ds3103b_dt_write(dev, 0x17, 0x81); 611e6089fecSBrad Love 612e6089fecSBrad Love usleep_range(5000, 5500); 613e6089fecSBrad Love 614e6089fecSBrad Love m88ds3103b_dt_write(dev, 0x05, 0x00); 615e6089fecSBrad Love m88ds3103b_dt_write(dev, 0x11, 0x0A); 616e6089fecSBrad Love 617e6089fecSBrad Love usleep_range(5000, 5500); 618e6089fecSBrad Love 619e6089fecSBrad Love return 0; 620e6089fecSBrad Love } 621e6089fecSBrad Love 622395d00d1SAntti Palosaari static int m88ds3103_set_frontend(struct dvb_frontend *fe) 623395d00d1SAntti Palosaari { 6247978b8a1SAntti Palosaari struct m88ds3103_dev *dev = fe->demodulator_priv; 6257978b8a1SAntti Palosaari struct i2c_client *client = dev->client; 626395d00d1SAntti Palosaari struct dtv_frontend_properties *c = &fe->dtv_property_cache; 62706487deeSAntti Palosaari int ret, len; 628395d00d1SAntti Palosaari const struct m88ds3103_reg_val *init; 629b6851419Snibble.max u8 u8tmp, u8tmp1 = 0, u8tmp2 = 0; /* silence compiler warning */ 630f4df95bcSnibble.max u8 buf[3]; 631334ef18eSAntti Palosaari u16 u16tmp; 632e6089fecSBrad Love u32 tuner_frequency_khz, target_mclk, u32tmp; 633395d00d1SAntti Palosaari s32 s32tmp; 634981fbe3dSJames Hutchinson static const struct reg_sequence reset_buf[] = { 635981fbe3dSJames Hutchinson {0x07, 0x80}, {0x07, 0x00} 636981fbe3dSJames Hutchinson }; 63741b9aa00SAntti Palosaari 6387978b8a1SAntti Palosaari dev_dbg(&client->dev, 6397978b8a1SAntti Palosaari "delivery_system=%d modulation=%d frequency=%u symbol_rate=%d inversion=%d pilot=%d rolloff=%d\n", 6407978b8a1SAntti Palosaari c->delivery_system, c->modulation, c->frequency, c->symbol_rate, 641395d00d1SAntti Palosaari c->inversion, c->pilot, c->rolloff); 642395d00d1SAntti Palosaari 6437978b8a1SAntti Palosaari if (!dev->warm) { 644395d00d1SAntti Palosaari ret = -EAGAIN; 645395d00d1SAntti Palosaari goto err; 646395d00d1SAntti Palosaari } 647395d00d1SAntti Palosaari 648f4df95bcSnibble.max /* reset */ 649981fbe3dSJames Hutchinson ret = regmap_multi_reg_write(dev->regmap, reset_buf, 2); 650f4df95bcSnibble.max if (ret) 651f4df95bcSnibble.max goto err; 652f4df95bcSnibble.max 653f4df95bcSnibble.max /* Disable demod clock path */ 6547978b8a1SAntti Palosaari if (dev->chip_id == M88RS6000_CHIP_ID) { 655e6089fecSBrad Love if (dev->chiptype == M88DS3103_CHIPTYPE_3103B) { 656e6089fecSBrad Love ret = regmap_read(dev->regmap, 0xb2, &u32tmp); 657e6089fecSBrad Love if (ret) 658e6089fecSBrad Love goto err; 659e6089fecSBrad Love if (u32tmp == 0x01) { 660e6089fecSBrad Love ret = regmap_write(dev->regmap, 0x00, 0x00); 661e6089fecSBrad Love if (ret) 662e6089fecSBrad Love goto err; 663e6089fecSBrad Love ret = regmap_write(dev->regmap, 0xb2, 0x00); 664e6089fecSBrad Love if (ret) 665e6089fecSBrad Love goto err; 666e6089fecSBrad Love } 667e6089fecSBrad Love } 668e6089fecSBrad Love 669478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0x06, 0xe0); 670f4df95bcSnibble.max if (ret) 671f4df95bcSnibble.max goto err; 672f4df95bcSnibble.max } 673f4df95bcSnibble.max 674395d00d1SAntti Palosaari /* program tuner */ 675395d00d1SAntti Palosaari if (fe->ops.tuner_ops.set_params) { 676395d00d1SAntti Palosaari ret = fe->ops.tuner_ops.set_params(fe); 677395d00d1SAntti Palosaari if (ret) 678395d00d1SAntti Palosaari goto err; 679395d00d1SAntti Palosaari } 680395d00d1SAntti Palosaari 681395d00d1SAntti Palosaari if (fe->ops.tuner_ops.get_frequency) { 682f5d9b88dSAntti Palosaari ret = fe->ops.tuner_ops.get_frequency(fe, &tuner_frequency_khz); 683395d00d1SAntti Palosaari if (ret) 684395d00d1SAntti Palosaari goto err; 6852f9dff3fSAntti Palosaari } else { 6862f9dff3fSAntti Palosaari /* 6872f9dff3fSAntti Palosaari * Use nominal target frequency as tuner driver does not provide 6882f9dff3fSAntti Palosaari * actual frequency used. Carrier offset calculation is not 6892f9dff3fSAntti Palosaari * valid. 6902f9dff3fSAntti Palosaari */ 691f5d9b88dSAntti Palosaari tuner_frequency_khz = c->frequency; 692395d00d1SAntti Palosaari } 693395d00d1SAntti Palosaari 694e6089fecSBrad Love /* set M88RS6000/DS3103B demod main mclk and ts mclk from tuner die */ 6957978b8a1SAntti Palosaari if (dev->chip_id == M88RS6000_CHIP_ID) { 696f4df95bcSnibble.max if (c->symbol_rate > 45010000) 697f5d9b88dSAntti Palosaari dev->mclk = 110250000; 698f4df95bcSnibble.max else 699f5d9b88dSAntti Palosaari dev->mclk = 96000000; 700395d00d1SAntti Palosaari 701f4df95bcSnibble.max if (c->delivery_system == SYS_DVBS) 702f5d9b88dSAntti Palosaari target_mclk = 96000000; 703f4df95bcSnibble.max else 704f5d9b88dSAntti Palosaari target_mclk = 144000000; 705395d00d1SAntti Palosaari 706e6089fecSBrad Love if (dev->chiptype == M88DS3103_CHIPTYPE_3103B) { 707e6089fecSBrad Love m88ds3103b_select_mclk(dev); 708e6089fecSBrad Love m88ds3103b_set_mclk(dev, target_mclk / 1000); 709e6089fecSBrad Love } 710e6089fecSBrad Love 711f4df95bcSnibble.max /* Enable demod clock path */ 712478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0x06, 0x00); 713f4df95bcSnibble.max if (ret) 714f4df95bcSnibble.max goto err; 715f4df95bcSnibble.max usleep_range(10000, 20000); 716f4df95bcSnibble.max } else { 717f4df95bcSnibble.max /* set M88DS3103 mclk and ts mclk. */ 718f5d9b88dSAntti Palosaari dev->mclk = 96000000; 719f4df95bcSnibble.max 7207978b8a1SAntti Palosaari switch (dev->cfg->ts_mode) { 721395d00d1SAntti Palosaari case M88DS3103_TS_SERIAL: 722395d00d1SAntti Palosaari case M88DS3103_TS_SERIAL_D7: 7237978b8a1SAntti Palosaari target_mclk = dev->cfg->ts_clk; 724395d00d1SAntti Palosaari break; 725395d00d1SAntti Palosaari case M88DS3103_TS_PARALLEL: 726395d00d1SAntti Palosaari case M88DS3103_TS_CI: 727b6851419Snibble.max if (c->delivery_system == SYS_DVBS) 728f5d9b88dSAntti Palosaari target_mclk = 96000000; 729b6851419Snibble.max else { 730395d00d1SAntti Palosaari if (c->symbol_rate < 18000000) 731f5d9b88dSAntti Palosaari target_mclk = 96000000; 732395d00d1SAntti Palosaari else if (c->symbol_rate < 28000000) 733f5d9b88dSAntti Palosaari target_mclk = 144000000; 734395d00d1SAntti Palosaari else 735f5d9b88dSAntti Palosaari target_mclk = 192000000; 736b6851419Snibble.max } 737395d00d1SAntti Palosaari break; 738395d00d1SAntti Palosaari default: 7397978b8a1SAntti Palosaari dev_dbg(&client->dev, "invalid ts_mode\n"); 740395d00d1SAntti Palosaari ret = -EINVAL; 741395d00d1SAntti Palosaari goto err; 742395d00d1SAntti Palosaari } 743f4df95bcSnibble.max 744f4df95bcSnibble.max switch (target_mclk) { 745f5d9b88dSAntti Palosaari case 96000000: 746f4df95bcSnibble.max u8tmp1 = 0x02; /* 0b10 */ 747f4df95bcSnibble.max u8tmp2 = 0x01; /* 0b01 */ 748f4df95bcSnibble.max break; 749f5d9b88dSAntti Palosaari case 144000000: 750f4df95bcSnibble.max u8tmp1 = 0x00; /* 0b00 */ 751f4df95bcSnibble.max u8tmp2 = 0x01; /* 0b01 */ 752f4df95bcSnibble.max break; 753f5d9b88dSAntti Palosaari case 192000000: 754f4df95bcSnibble.max u8tmp1 = 0x03; /* 0b11 */ 755f4df95bcSnibble.max u8tmp2 = 0x00; /* 0b00 */ 756f4df95bcSnibble.max break; 757f4df95bcSnibble.max } 75856ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x22, 0xc0, u8tmp1 << 6); 759f4df95bcSnibble.max if (ret) 760f4df95bcSnibble.max goto err; 76156ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x24, 0xc0, u8tmp2 << 6); 762f4df95bcSnibble.max if (ret) 763f4df95bcSnibble.max goto err; 764f4df95bcSnibble.max } 765f4df95bcSnibble.max 766478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xb2, 0x01); 767f4df95bcSnibble.max if (ret) 768f4df95bcSnibble.max goto err; 769f4df95bcSnibble.max 770478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0x00, 0x01); 771f4df95bcSnibble.max if (ret) 772f4df95bcSnibble.max goto err; 773f4df95bcSnibble.max 774f4df95bcSnibble.max switch (c->delivery_system) { 775f4df95bcSnibble.max case SYS_DVBS: 7767978b8a1SAntti Palosaari if (dev->chip_id == M88RS6000_CHIP_ID) { 777f4df95bcSnibble.max len = ARRAY_SIZE(m88rs6000_dvbs_init_reg_vals); 778f4df95bcSnibble.max init = m88rs6000_dvbs_init_reg_vals; 779f4df95bcSnibble.max } else { 780f4df95bcSnibble.max len = ARRAY_SIZE(m88ds3103_dvbs_init_reg_vals); 781f4df95bcSnibble.max init = m88ds3103_dvbs_init_reg_vals; 782f4df95bcSnibble.max } 783f4df95bcSnibble.max break; 784f4df95bcSnibble.max case SYS_DVBS2: 7857978b8a1SAntti Palosaari if (dev->chip_id == M88RS6000_CHIP_ID) { 786f4df95bcSnibble.max len = ARRAY_SIZE(m88rs6000_dvbs2_init_reg_vals); 787f4df95bcSnibble.max init = m88rs6000_dvbs2_init_reg_vals; 788f4df95bcSnibble.max } else { 789f4df95bcSnibble.max len = ARRAY_SIZE(m88ds3103_dvbs2_init_reg_vals); 790f4df95bcSnibble.max init = m88ds3103_dvbs2_init_reg_vals; 791f4df95bcSnibble.max } 792395d00d1SAntti Palosaari break; 793395d00d1SAntti Palosaari default: 7947978b8a1SAntti Palosaari dev_dbg(&client->dev, "invalid delivery_system\n"); 795395d00d1SAntti Palosaari ret = -EINVAL; 796395d00d1SAntti Palosaari goto err; 797395d00d1SAntti Palosaari } 798395d00d1SAntti Palosaari 799395d00d1SAntti Palosaari /* program init table */ 8007978b8a1SAntti Palosaari if (c->delivery_system != dev->delivery_system) { 8017978b8a1SAntti Palosaari ret = m88ds3103_wr_reg_val_tab(dev, init, len); 802395d00d1SAntti Palosaari if (ret) 803395d00d1SAntti Palosaari goto err; 804395d00d1SAntti Palosaari } 805395d00d1SAntti Palosaari 8067978b8a1SAntti Palosaari if (dev->chip_id == M88RS6000_CHIP_ID) { 807f5d9b88dSAntti Palosaari if (c->delivery_system == SYS_DVBS2 && 808f5d9b88dSAntti Palosaari c->symbol_rate <= 5000000) { 809478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xc0, 0x04); 810f4df95bcSnibble.max if (ret) 811f4df95bcSnibble.max goto err; 812f4df95bcSnibble.max buf[0] = 0x09; 813f4df95bcSnibble.max buf[1] = 0x22; 814f4df95bcSnibble.max buf[2] = 0x88; 815478932b1SAntti Palosaari ret = regmap_bulk_write(dev->regmap, 0x8a, buf, 3); 816f4df95bcSnibble.max if (ret) 817f4df95bcSnibble.max goto err; 818f4df95bcSnibble.max } 81956ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x9d, 0x08, 0x08); 820f4df95bcSnibble.max if (ret) 821f4df95bcSnibble.max goto err; 822e6089fecSBrad Love 823e6089fecSBrad Love if (dev->chiptype == M88DS3103_CHIPTYPE_3103B) { 824e6089fecSBrad Love buf[0] = m88ds3103b_dt_read(dev, 0x15); 825e6089fecSBrad Love buf[1] = m88ds3103b_dt_read(dev, 0x16); 826e6089fecSBrad Love 827e6089fecSBrad Love if (c->symbol_rate > 45010000) { 828e6089fecSBrad Love buf[0] &= ~0x03; 829e6089fecSBrad Love buf[0] |= 0x02; 830e6089fecSBrad Love buf[0] |= ((147 - 32) >> 8) & 0x01; 831e6089fecSBrad Love buf[1] = (147 - 32) & 0xFF; 832e6089fecSBrad Love 833e6089fecSBrad Love dev->mclk = 110250 * 1000; 834e6089fecSBrad Love } else { 835e6089fecSBrad Love buf[0] &= ~0x03; 836e6089fecSBrad Love buf[0] |= ((128 - 32) >> 8) & 0x01; 837e6089fecSBrad Love buf[1] = (128 - 32) & 0xFF; 838e6089fecSBrad Love 839e6089fecSBrad Love dev->mclk = 96000 * 1000; 840e6089fecSBrad Love } 841e6089fecSBrad Love m88ds3103b_dt_write(dev, 0x15, buf[0]); 842e6089fecSBrad Love m88ds3103b_dt_write(dev, 0x16, buf[1]); 843e6089fecSBrad Love 844e6089fecSBrad Love regmap_read(dev->regmap, 0x30, &u32tmp); 845e6089fecSBrad Love u32tmp &= ~0x80; 846e6089fecSBrad Love regmap_write(dev->regmap, 0x30, u32tmp & 0xff); 847e6089fecSBrad Love } 848e6089fecSBrad Love 849478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xf1, 0x01); 850f4df95bcSnibble.max if (ret) 851f4df95bcSnibble.max goto err; 852e6089fecSBrad Love 853e6089fecSBrad Love if (dev->chiptype != M88DS3103_CHIPTYPE_3103B) { 85456ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x30, 0x80, 0x80); 855f4df95bcSnibble.max if (ret) 856f4df95bcSnibble.max goto err; 857f4df95bcSnibble.max } 858e6089fecSBrad Love } 859f4df95bcSnibble.max 8607978b8a1SAntti Palosaari switch (dev->cfg->ts_mode) { 861395d00d1SAntti Palosaari case M88DS3103_TS_SERIAL: 862395d00d1SAntti Palosaari u8tmp1 = 0x00; 86379d09330Snibble.max u8tmp = 0x06; 864395d00d1SAntti Palosaari break; 865395d00d1SAntti Palosaari case M88DS3103_TS_SERIAL_D7: 866395d00d1SAntti Palosaari u8tmp1 = 0x20; 86779d09330Snibble.max u8tmp = 0x06; 868395d00d1SAntti Palosaari break; 869395d00d1SAntti Palosaari case M88DS3103_TS_PARALLEL: 87079d09330Snibble.max u8tmp = 0x02; 871e6089fecSBrad Love if (dev->chiptype == M88DS3103_CHIPTYPE_3103B) { 872e6089fecSBrad Love u8tmp = 0x01; 873e6089fecSBrad Love u8tmp1 = 0x01; 874e6089fecSBrad Love } 875395d00d1SAntti Palosaari break; 876395d00d1SAntti Palosaari case M88DS3103_TS_CI: 87779d09330Snibble.max u8tmp = 0x03; 878395d00d1SAntti Palosaari break; 879395d00d1SAntti Palosaari default: 8807978b8a1SAntti Palosaari dev_dbg(&client->dev, "invalid ts_mode\n"); 881395d00d1SAntti Palosaari ret = -EINVAL; 882395d00d1SAntti Palosaari goto err; 883395d00d1SAntti Palosaari } 884395d00d1SAntti Palosaari 8857978b8a1SAntti Palosaari if (dev->cfg->ts_clk_pol) 88679d09330Snibble.max u8tmp |= 0x40; 88779d09330Snibble.max 888395d00d1SAntti Palosaari /* TS mode */ 889478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xfd, u8tmp); 890395d00d1SAntti Palosaari if (ret) 891395d00d1SAntti Palosaari goto err; 892395d00d1SAntti Palosaari 8937978b8a1SAntti Palosaari switch (dev->cfg->ts_mode) { 894395d00d1SAntti Palosaari case M88DS3103_TS_SERIAL: 895395d00d1SAntti Palosaari case M88DS3103_TS_SERIAL_D7: 89656ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x29, 0x20, u8tmp1); 897395d00d1SAntti Palosaari if (ret) 898395d00d1SAntti Palosaari goto err; 899334ef18eSAntti Palosaari u16tmp = 0; 900334ef18eSAntti Palosaari u8tmp1 = 0x3f; 901334ef18eSAntti Palosaari u8tmp2 = 0x3f; 902b6851419Snibble.max break; 903e6089fecSBrad Love case M88DS3103_TS_PARALLEL: 904e6089fecSBrad Love if (dev->chiptype == M88DS3103_CHIPTYPE_3103B) { 905e6089fecSBrad Love ret = m88ds3103_update_bits(dev, 0x29, 0x01, u8tmp1); 906e6089fecSBrad Love if (ret) 907e6089fecSBrad Love goto err; 908e6089fecSBrad Love } 9091771e9fbSGustavo A. R. Silva fallthrough; 910b6851419Snibble.max default: 911334ef18eSAntti Palosaari u16tmp = DIV_ROUND_UP(target_mclk, dev->cfg->ts_clk); 912334ef18eSAntti Palosaari u8tmp1 = u16tmp / 2 - 1; 913334ef18eSAntti Palosaari u8tmp2 = DIV_ROUND_UP(u16tmp, 2) - 1; 914395d00d1SAntti Palosaari } 915395d00d1SAntti Palosaari 916f5d9b88dSAntti Palosaari dev_dbg(&client->dev, "target_mclk=%u ts_clk=%u ts_clk_divide_ratio=%u\n", 917334ef18eSAntti Palosaari target_mclk, dev->cfg->ts_clk, u16tmp); 918395d00d1SAntti Palosaari 919395d00d1SAntti Palosaari /* u8tmp1[5:2] => fe[3:0], u8tmp1[1:0] => ea[7:6] */ 920395d00d1SAntti Palosaari /* u8tmp2[5:0] => ea[5:0] */ 921334ef18eSAntti Palosaari u8tmp = (u8tmp1 >> 2) & 0x0f; 922334ef18eSAntti Palosaari ret = regmap_update_bits(dev->regmap, 0xfe, 0x0f, u8tmp); 923395d00d1SAntti Palosaari if (ret) 924395d00d1SAntti Palosaari goto err; 925395d00d1SAntti Palosaari u8tmp = ((u8tmp1 & 0x03) << 6) | u8tmp2 >> 0; 926478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xea, u8tmp); 927395d00d1SAntti Palosaari if (ret) 928395d00d1SAntti Palosaari goto err; 929395d00d1SAntti Palosaari 930395d00d1SAntti Palosaari if (c->symbol_rate <= 3000000) 931395d00d1SAntti Palosaari u8tmp = 0x20; 932395d00d1SAntti Palosaari else if (c->symbol_rate <= 10000000) 933395d00d1SAntti Palosaari u8tmp = 0x10; 934395d00d1SAntti Palosaari else 935395d00d1SAntti Palosaari u8tmp = 0x06; 936395d00d1SAntti Palosaari 937e6089fecSBrad Love if (dev->chiptype == M88DS3103_CHIPTYPE_3103B) 938e6089fecSBrad Love m88ds3103b_set_mclk(dev, target_mclk / 1000); 939e6089fecSBrad Love 940478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xc3, 0x08); 941395d00d1SAntti Palosaari if (ret) 942395d00d1SAntti Palosaari goto err; 943395d00d1SAntti Palosaari 944478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xc8, u8tmp); 945395d00d1SAntti Palosaari if (ret) 946395d00d1SAntti Palosaari goto err; 947395d00d1SAntti Palosaari 948478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xc4, 0x08); 949395d00d1SAntti Palosaari if (ret) 950395d00d1SAntti Palosaari goto err; 951395d00d1SAntti Palosaari 952478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xc7, 0x00); 953395d00d1SAntti Palosaari if (ret) 954395d00d1SAntti Palosaari goto err; 955395d00d1SAntti Palosaari 956f5d9b88dSAntti Palosaari u16tmp = DIV_ROUND_CLOSEST_ULL((u64)c->symbol_rate * 0x10000, dev->mclk); 957395d00d1SAntti Palosaari buf[0] = (u16tmp >> 0) & 0xff; 958395d00d1SAntti Palosaari buf[1] = (u16tmp >> 8) & 0xff; 959478932b1SAntti Palosaari ret = regmap_bulk_write(dev->regmap, 0x61, buf, 2); 960395d00d1SAntti Palosaari if (ret) 961395d00d1SAntti Palosaari goto err; 962395d00d1SAntti Palosaari 96356ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x4d, 0x02, dev->cfg->spec_inv << 1); 964395d00d1SAntti Palosaari if (ret) 965395d00d1SAntti Palosaari goto err; 966395d00d1SAntti Palosaari 96756ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x30, 0x10, dev->cfg->agc_inv << 4); 968395d00d1SAntti Palosaari if (ret) 969395d00d1SAntti Palosaari goto err; 970395d00d1SAntti Palosaari 971478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0x33, dev->cfg->agc); 972395d00d1SAntti Palosaari if (ret) 973395d00d1SAntti Palosaari goto err; 974395d00d1SAntti Palosaari 975e6089fecSBrad Love if (dev->chiptype == M88DS3103_CHIPTYPE_3103B) { 976e6089fecSBrad Love /* enable/disable 192M LDPC clock */ 977e6089fecSBrad Love ret = m88ds3103_update_bits(dev, 0x29, 0x10, 978e6089fecSBrad Love (c->delivery_system == SYS_DVBS) ? 0x10 : 0x0); 979e6089fecSBrad Love if (ret) 980e6089fecSBrad Love goto err; 981e6089fecSBrad Love 982e6089fecSBrad Love ret = m88ds3103_update_bits(dev, 0xc9, 0x08, 0x08); 983c4ed27cfSSean Young if (ret) 984c4ed27cfSSean Young goto err; 985e6089fecSBrad Love } 986e6089fecSBrad Love 9877978b8a1SAntti Palosaari dev_dbg(&client->dev, "carrier offset=%d\n", 988f5d9b88dSAntti Palosaari (tuner_frequency_khz - c->frequency)); 989395d00d1SAntti Palosaari 990f5d9b88dSAntti Palosaari /* Use 32-bit calc as there is no s64 version of DIV_ROUND_CLOSEST() */ 991f5d9b88dSAntti Palosaari s32tmp = 0x10000 * (tuner_frequency_khz - c->frequency); 992f5d9b88dSAntti Palosaari s32tmp = DIV_ROUND_CLOSEST(s32tmp, dev->mclk / 1000); 993395d00d1SAntti Palosaari buf[0] = (s32tmp >> 0) & 0xff; 994395d00d1SAntti Palosaari buf[1] = (s32tmp >> 8) & 0xff; 995478932b1SAntti Palosaari ret = regmap_bulk_write(dev->regmap, 0x5e, buf, 2); 996395d00d1SAntti Palosaari if (ret) 997395d00d1SAntti Palosaari goto err; 998395d00d1SAntti Palosaari 999478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0x00, 0x00); 1000395d00d1SAntti Palosaari if (ret) 1001395d00d1SAntti Palosaari goto err; 1002395d00d1SAntti Palosaari 1003478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xb2, 0x00); 1004395d00d1SAntti Palosaari if (ret) 1005395d00d1SAntti Palosaari goto err; 1006395d00d1SAntti Palosaari 10077978b8a1SAntti Palosaari dev->delivery_system = c->delivery_system; 1008395d00d1SAntti Palosaari 1009395d00d1SAntti Palosaari return 0; 1010395d00d1SAntti Palosaari err: 10117978b8a1SAntti Palosaari dev_dbg(&client->dev, "failed=%d\n", ret); 1012395d00d1SAntti Palosaari return ret; 1013395d00d1SAntti Palosaari } 1014395d00d1SAntti Palosaari 1015395d00d1SAntti Palosaari static int m88ds3103_init(struct dvb_frontend *fe) 1016395d00d1SAntti Palosaari { 10177978b8a1SAntti Palosaari struct m88ds3103_dev *dev = fe->demodulator_priv; 10187978b8a1SAntti Palosaari struct i2c_client *client = dev->client; 1019c1daf651SAntti Palosaari struct dtv_frontend_properties *c = &fe->dtv_property_cache; 102060701d5fSAntti Palosaari int ret, len, rem; 1021478932b1SAntti Palosaari unsigned int utmp; 102260701d5fSAntti Palosaari const struct firmware *firmware; 102360701d5fSAntti Palosaari const char *name; 102441b9aa00SAntti Palosaari 10257978b8a1SAntti Palosaari dev_dbg(&client->dev, "\n"); 1026395d00d1SAntti Palosaari 1027395d00d1SAntti Palosaari /* set cold state by default */ 10287978b8a1SAntti Palosaari dev->warm = false; 1029395d00d1SAntti Palosaari 1030395d00d1SAntti Palosaari /* wake up device from sleep */ 103156ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x08, 0x01, 0x01); 1032395d00d1SAntti Palosaari if (ret) 1033395d00d1SAntti Palosaari goto err; 103456ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x04, 0x01, 0x00); 1035395d00d1SAntti Palosaari if (ret) 1036395d00d1SAntti Palosaari goto err; 103756ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x23, 0x10, 0x00); 1038395d00d1SAntti Palosaari if (ret) 1039395d00d1SAntti Palosaari goto err; 1040395d00d1SAntti Palosaari 1041395d00d1SAntti Palosaari /* firmware status */ 1042478932b1SAntti Palosaari ret = regmap_read(dev->regmap, 0xb9, &utmp); 1043395d00d1SAntti Palosaari if (ret) 1044395d00d1SAntti Palosaari goto err; 1045395d00d1SAntti Palosaari 1046478932b1SAntti Palosaari dev_dbg(&client->dev, "firmware=%02x\n", utmp); 1047395d00d1SAntti Palosaari 1048478932b1SAntti Palosaari if (utmp) 104960701d5fSAntti Palosaari goto warm; 1050395d00d1SAntti Palosaari 1051e6089fecSBrad Love /* global reset, global diseqc reset, global fec reset */ 1052478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0x07, 0xe0); 1053f4df95bcSnibble.max if (ret) 1054f4df95bcSnibble.max goto err; 1055478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0x07, 0x00); 1056f4df95bcSnibble.max if (ret) 1057f4df95bcSnibble.max goto err; 1058f4df95bcSnibble.max 1059395d00d1SAntti Palosaari /* cold state - try to download firmware */ 10607978b8a1SAntti Palosaari dev_info(&client->dev, "found a '%s' in cold state\n", 1061e6089fecSBrad Love dev->fe.ops.info.name); 1062395d00d1SAntti Palosaari 1063e6089fecSBrad Love if (dev->chiptype == M88DS3103_CHIPTYPE_3103B) 1064e6089fecSBrad Love name = M88DS3103B_FIRMWARE; 1065e6089fecSBrad Love else if (dev->chip_id == M88RS6000_CHIP_ID) 106660701d5fSAntti Palosaari name = M88RS6000_FIRMWARE; 1067f4df95bcSnibble.max else 106860701d5fSAntti Palosaari name = M88DS3103_FIRMWARE; 1069e6089fecSBrad Love 1070395d00d1SAntti Palosaari /* request the firmware, this will block and timeout */ 107160701d5fSAntti Palosaari ret = request_firmware(&firmware, name, &client->dev); 1072395d00d1SAntti Palosaari if (ret) { 107360701d5fSAntti Palosaari dev_err(&client->dev, "firmware file '%s' not found\n", name); 1074395d00d1SAntti Palosaari goto err; 1075395d00d1SAntti Palosaari } 1076395d00d1SAntti Palosaari 107760701d5fSAntti Palosaari dev_info(&client->dev, "downloading firmware from file '%s'\n", name); 1078395d00d1SAntti Palosaari 1079478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xb2, 0x01); 1080395d00d1SAntti Palosaari if (ret) 108160701d5fSAntti Palosaari goto err_release_firmware; 1082395d00d1SAntti Palosaari 108360701d5fSAntti Palosaari for (rem = firmware->size; rem > 0; rem -= (dev->cfg->i2c_wr_max - 1)) { 108460701d5fSAntti Palosaari len = min(dev->cfg->i2c_wr_max - 1, rem); 1085478932b1SAntti Palosaari ret = regmap_bulk_write(dev->regmap, 0xb0, 108660701d5fSAntti Palosaari &firmware->data[firmware->size - rem], 108760701d5fSAntti Palosaari len); 1088395d00d1SAntti Palosaari if (ret) { 108960701d5fSAntti Palosaari dev_err(&client->dev, "firmware download failed %d\n", 10907978b8a1SAntti Palosaari ret); 109160701d5fSAntti Palosaari goto err_release_firmware; 1092395d00d1SAntti Palosaari } 1093395d00d1SAntti Palosaari } 1094395d00d1SAntti Palosaari 1095478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xb2, 0x00); 1096395d00d1SAntti Palosaari if (ret) 109760701d5fSAntti Palosaari goto err_release_firmware; 1098395d00d1SAntti Palosaari 109960701d5fSAntti Palosaari release_firmware(firmware); 1100395d00d1SAntti Palosaari 1101478932b1SAntti Palosaari ret = regmap_read(dev->regmap, 0xb9, &utmp); 1102395d00d1SAntti Palosaari if (ret) 1103395d00d1SAntti Palosaari goto err; 1104395d00d1SAntti Palosaari 1105478932b1SAntti Palosaari if (!utmp) { 110660701d5fSAntti Palosaari ret = -EINVAL; 11077978b8a1SAntti Palosaari dev_info(&client->dev, "firmware did not run\n"); 1108395d00d1SAntti Palosaari goto err; 1109395d00d1SAntti Palosaari } 1110395d00d1SAntti Palosaari 11117978b8a1SAntti Palosaari dev_info(&client->dev, "found a '%s' in warm state\n", 1112e6089fecSBrad Love dev->fe.ops.info.name); 11137978b8a1SAntti Palosaari dev_info(&client->dev, "firmware version: %X.%X\n", 1114478932b1SAntti Palosaari (utmp >> 4) & 0xf, (utmp >> 0 & 0xf)); 1115395d00d1SAntti Palosaari 1116e6089fecSBrad Love if (dev->chiptype == M88DS3103_CHIPTYPE_3103B) { 1117e6089fecSBrad Love m88ds3103b_dt_write(dev, 0x21, 0x92); 1118e6089fecSBrad Love m88ds3103b_dt_write(dev, 0x15, 0x6C); 1119e6089fecSBrad Love m88ds3103b_dt_write(dev, 0x17, 0xC1); 1120e6089fecSBrad Love m88ds3103b_dt_write(dev, 0x17, 0x81); 1121e6089fecSBrad Love } 112260701d5fSAntti Palosaari warm: 1123395d00d1SAntti Palosaari /* warm state */ 11247978b8a1SAntti Palosaari dev->warm = true; 11257978b8a1SAntti Palosaari 1126c1daf651SAntti Palosaari /* init stats here in order signal app which stats are supported */ 1127c1daf651SAntti Palosaari c->cnr.len = 1; 1128c1daf651SAntti Palosaari c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; 1129ce80d713SAntti Palosaari c->post_bit_error.len = 1; 1130ce80d713SAntti Palosaari c->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; 1131ce80d713SAntti Palosaari c->post_bit_count.len = 1; 1132ce80d713SAntti Palosaari c->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE; 1133395d00d1SAntti Palosaari 11347978b8a1SAntti Palosaari return 0; 113560701d5fSAntti Palosaari err_release_firmware: 113660701d5fSAntti Palosaari release_firmware(firmware); 11375ed0cf88SMarkus Elfring err: 11387978b8a1SAntti Palosaari dev_dbg(&client->dev, "failed=%d\n", ret); 1139395d00d1SAntti Palosaari return ret; 1140395d00d1SAntti Palosaari } 1141395d00d1SAntti Palosaari 1142395d00d1SAntti Palosaari static int m88ds3103_sleep(struct dvb_frontend *fe) 1143395d00d1SAntti Palosaari { 11447978b8a1SAntti Palosaari struct m88ds3103_dev *dev = fe->demodulator_priv; 11457978b8a1SAntti Palosaari struct i2c_client *client = dev->client; 1146395d00d1SAntti Palosaari int ret; 1147478932b1SAntti Palosaari unsigned int utmp; 114841b9aa00SAntti Palosaari 11497978b8a1SAntti Palosaari dev_dbg(&client->dev, "\n"); 1150395d00d1SAntti Palosaari 11517978b8a1SAntti Palosaari dev->fe_status = 0; 11527978b8a1SAntti Palosaari dev->delivery_system = SYS_UNDEFINED; 1153395d00d1SAntti Palosaari 1154395d00d1SAntti Palosaari /* TS Hi-Z */ 11557978b8a1SAntti Palosaari if (dev->chip_id == M88RS6000_CHIP_ID) 1156478932b1SAntti Palosaari utmp = 0x29; 1157f4df95bcSnibble.max else 1158478932b1SAntti Palosaari utmp = 0x27; 115956ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, utmp, 0x01, 0x00); 1160395d00d1SAntti Palosaari if (ret) 1161395d00d1SAntti Palosaari goto err; 1162395d00d1SAntti Palosaari 1163395d00d1SAntti Palosaari /* sleep */ 116456ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x08, 0x01, 0x00); 1165395d00d1SAntti Palosaari if (ret) 1166395d00d1SAntti Palosaari goto err; 116756ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x04, 0x01, 0x01); 1168395d00d1SAntti Palosaari if (ret) 1169395d00d1SAntti Palosaari goto err; 117056ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x23, 0x10, 0x10); 1171395d00d1SAntti Palosaari if (ret) 1172395d00d1SAntti Palosaari goto err; 1173395d00d1SAntti Palosaari 1174395d00d1SAntti Palosaari return 0; 1175395d00d1SAntti Palosaari err: 11767978b8a1SAntti Palosaari dev_dbg(&client->dev, "failed=%d\n", ret); 1177395d00d1SAntti Palosaari return ret; 1178395d00d1SAntti Palosaari } 1179395d00d1SAntti Palosaari 11807e3e68bcSMauro Carvalho Chehab static int m88ds3103_get_frontend(struct dvb_frontend *fe, 11817e3e68bcSMauro Carvalho Chehab struct dtv_frontend_properties *c) 1182395d00d1SAntti Palosaari { 11837978b8a1SAntti Palosaari struct m88ds3103_dev *dev = fe->demodulator_priv; 11847978b8a1SAntti Palosaari struct i2c_client *client = dev->client; 1185395d00d1SAntti Palosaari int ret; 1186395d00d1SAntti Palosaari u8 buf[3]; 118741b9aa00SAntti Palosaari 11887978b8a1SAntti Palosaari dev_dbg(&client->dev, "\n"); 1189395d00d1SAntti Palosaari 11907978b8a1SAntti Palosaari if (!dev->warm || !(dev->fe_status & FE_HAS_LOCK)) { 11919240c384SAntti Palosaari ret = 0; 1192395d00d1SAntti Palosaari goto err; 1193395d00d1SAntti Palosaari } 1194395d00d1SAntti Palosaari 1195395d00d1SAntti Palosaari switch (c->delivery_system) { 1196395d00d1SAntti Palosaari case SYS_DVBS: 1197478932b1SAntti Palosaari ret = regmap_bulk_read(dev->regmap, 0xe0, &buf[0], 1); 1198395d00d1SAntti Palosaari if (ret) 1199395d00d1SAntti Palosaari goto err; 1200395d00d1SAntti Palosaari 1201478932b1SAntti Palosaari ret = regmap_bulk_read(dev->regmap, 0xe6, &buf[1], 1); 1202395d00d1SAntti Palosaari if (ret) 1203395d00d1SAntti Palosaari goto err; 1204395d00d1SAntti Palosaari 1205395d00d1SAntti Palosaari switch ((buf[0] >> 2) & 0x01) { 1206395d00d1SAntti Palosaari case 0: 1207395d00d1SAntti Palosaari c->inversion = INVERSION_OFF; 1208395d00d1SAntti Palosaari break; 1209395d00d1SAntti Palosaari case 1: 1210395d00d1SAntti Palosaari c->inversion = INVERSION_ON; 1211395d00d1SAntti Palosaari break; 1212395d00d1SAntti Palosaari } 1213395d00d1SAntti Palosaari 1214395d00d1SAntti Palosaari switch ((buf[1] >> 5) & 0x07) { 1215395d00d1SAntti Palosaari case 0: 1216395d00d1SAntti Palosaari c->fec_inner = FEC_7_8; 1217395d00d1SAntti Palosaari break; 1218395d00d1SAntti Palosaari case 1: 1219395d00d1SAntti Palosaari c->fec_inner = FEC_5_6; 1220395d00d1SAntti Palosaari break; 1221395d00d1SAntti Palosaari case 2: 1222395d00d1SAntti Palosaari c->fec_inner = FEC_3_4; 1223395d00d1SAntti Palosaari break; 1224395d00d1SAntti Palosaari case 3: 1225395d00d1SAntti Palosaari c->fec_inner = FEC_2_3; 1226395d00d1SAntti Palosaari break; 1227395d00d1SAntti Palosaari case 4: 1228395d00d1SAntti Palosaari c->fec_inner = FEC_1_2; 1229395d00d1SAntti Palosaari break; 1230395d00d1SAntti Palosaari default: 12317978b8a1SAntti Palosaari dev_dbg(&client->dev, "invalid fec_inner\n"); 1232395d00d1SAntti Palosaari } 1233395d00d1SAntti Palosaari 1234395d00d1SAntti Palosaari c->modulation = QPSK; 1235395d00d1SAntti Palosaari 1236395d00d1SAntti Palosaari break; 1237395d00d1SAntti Palosaari case SYS_DVBS2: 1238478932b1SAntti Palosaari ret = regmap_bulk_read(dev->regmap, 0x7e, &buf[0], 1); 1239395d00d1SAntti Palosaari if (ret) 1240395d00d1SAntti Palosaari goto err; 1241395d00d1SAntti Palosaari 1242478932b1SAntti Palosaari ret = regmap_bulk_read(dev->regmap, 0x89, &buf[1], 1); 1243395d00d1SAntti Palosaari if (ret) 1244395d00d1SAntti Palosaari goto err; 1245395d00d1SAntti Palosaari 1246478932b1SAntti Palosaari ret = regmap_bulk_read(dev->regmap, 0xf2, &buf[2], 1); 1247395d00d1SAntti Palosaari if (ret) 1248395d00d1SAntti Palosaari goto err; 1249395d00d1SAntti Palosaari 1250395d00d1SAntti Palosaari switch ((buf[0] >> 0) & 0x0f) { 1251395d00d1SAntti Palosaari case 2: 1252395d00d1SAntti Palosaari c->fec_inner = FEC_2_5; 1253395d00d1SAntti Palosaari break; 1254395d00d1SAntti Palosaari case 3: 1255395d00d1SAntti Palosaari c->fec_inner = FEC_1_2; 1256395d00d1SAntti Palosaari break; 1257395d00d1SAntti Palosaari case 4: 1258395d00d1SAntti Palosaari c->fec_inner = FEC_3_5; 1259395d00d1SAntti Palosaari break; 1260395d00d1SAntti Palosaari case 5: 1261395d00d1SAntti Palosaari c->fec_inner = FEC_2_3; 1262395d00d1SAntti Palosaari break; 1263395d00d1SAntti Palosaari case 6: 1264395d00d1SAntti Palosaari c->fec_inner = FEC_3_4; 1265395d00d1SAntti Palosaari break; 1266395d00d1SAntti Palosaari case 7: 1267395d00d1SAntti Palosaari c->fec_inner = FEC_4_5; 1268395d00d1SAntti Palosaari break; 1269395d00d1SAntti Palosaari case 8: 1270395d00d1SAntti Palosaari c->fec_inner = FEC_5_6; 1271395d00d1SAntti Palosaari break; 1272395d00d1SAntti Palosaari case 9: 1273395d00d1SAntti Palosaari c->fec_inner = FEC_8_9; 1274395d00d1SAntti Palosaari break; 1275395d00d1SAntti Palosaari case 10: 1276395d00d1SAntti Palosaari c->fec_inner = FEC_9_10; 1277395d00d1SAntti Palosaari break; 1278395d00d1SAntti Palosaari default: 12797978b8a1SAntti Palosaari dev_dbg(&client->dev, "invalid fec_inner\n"); 1280395d00d1SAntti Palosaari } 1281395d00d1SAntti Palosaari 1282395d00d1SAntti Palosaari switch ((buf[0] >> 5) & 0x01) { 1283395d00d1SAntti Palosaari case 0: 1284395d00d1SAntti Palosaari c->pilot = PILOT_OFF; 1285395d00d1SAntti Palosaari break; 1286395d00d1SAntti Palosaari case 1: 1287395d00d1SAntti Palosaari c->pilot = PILOT_ON; 1288395d00d1SAntti Palosaari break; 1289395d00d1SAntti Palosaari } 1290395d00d1SAntti Palosaari 1291395d00d1SAntti Palosaari switch ((buf[0] >> 6) & 0x07) { 1292395d00d1SAntti Palosaari case 0: 1293395d00d1SAntti Palosaari c->modulation = QPSK; 1294395d00d1SAntti Palosaari break; 1295395d00d1SAntti Palosaari case 1: 1296395d00d1SAntti Palosaari c->modulation = PSK_8; 1297395d00d1SAntti Palosaari break; 1298395d00d1SAntti Palosaari case 2: 1299395d00d1SAntti Palosaari c->modulation = APSK_16; 1300395d00d1SAntti Palosaari break; 1301395d00d1SAntti Palosaari case 3: 1302395d00d1SAntti Palosaari c->modulation = APSK_32; 1303395d00d1SAntti Palosaari break; 1304395d00d1SAntti Palosaari default: 13057978b8a1SAntti Palosaari dev_dbg(&client->dev, "invalid modulation\n"); 1306395d00d1SAntti Palosaari } 1307395d00d1SAntti Palosaari 1308395d00d1SAntti Palosaari switch ((buf[1] >> 7) & 0x01) { 1309395d00d1SAntti Palosaari case 0: 1310395d00d1SAntti Palosaari c->inversion = INVERSION_OFF; 1311395d00d1SAntti Palosaari break; 1312395d00d1SAntti Palosaari case 1: 1313395d00d1SAntti Palosaari c->inversion = INVERSION_ON; 1314395d00d1SAntti Palosaari break; 1315395d00d1SAntti Palosaari } 1316395d00d1SAntti Palosaari 1317395d00d1SAntti Palosaari switch ((buf[2] >> 0) & 0x03) { 1318395d00d1SAntti Palosaari case 0: 1319395d00d1SAntti Palosaari c->rolloff = ROLLOFF_35; 1320395d00d1SAntti Palosaari break; 1321395d00d1SAntti Palosaari case 1: 1322395d00d1SAntti Palosaari c->rolloff = ROLLOFF_25; 1323395d00d1SAntti Palosaari break; 1324395d00d1SAntti Palosaari case 2: 1325395d00d1SAntti Palosaari c->rolloff = ROLLOFF_20; 1326395d00d1SAntti Palosaari break; 1327395d00d1SAntti Palosaari default: 13287978b8a1SAntti Palosaari dev_dbg(&client->dev, "invalid rolloff\n"); 1329395d00d1SAntti Palosaari } 1330395d00d1SAntti Palosaari break; 1331395d00d1SAntti Palosaari default: 13327978b8a1SAntti Palosaari dev_dbg(&client->dev, "invalid delivery_system\n"); 1333395d00d1SAntti Palosaari ret = -EINVAL; 1334395d00d1SAntti Palosaari goto err; 1335395d00d1SAntti Palosaari } 1336395d00d1SAntti Palosaari 1337478932b1SAntti Palosaari ret = regmap_bulk_read(dev->regmap, 0x6d, buf, 2); 1338395d00d1SAntti Palosaari if (ret) 1339395d00d1SAntti Palosaari goto err; 1340395d00d1SAntti Palosaari 1341f5d9b88dSAntti Palosaari c->symbol_rate = DIV_ROUND_CLOSEST_ULL((u64)(buf[1] << 8 | buf[0] << 0) * dev->mclk, 0x10000); 1342395d00d1SAntti Palosaari 1343395d00d1SAntti Palosaari return 0; 1344395d00d1SAntti Palosaari err: 13457978b8a1SAntti Palosaari dev_dbg(&client->dev, "failed=%d\n", ret); 1346395d00d1SAntti Palosaari return ret; 1347395d00d1SAntti Palosaari } 1348395d00d1SAntti Palosaari 1349395d00d1SAntti Palosaari static int m88ds3103_read_snr(struct dvb_frontend *fe, u16 *snr) 1350395d00d1SAntti Palosaari { 1351395d00d1SAntti Palosaari struct dtv_frontend_properties *c = &fe->dtv_property_cache; 135241b9aa00SAntti Palosaari 1353c1daf651SAntti Palosaari if (c->cnr.stat[0].scale == FE_SCALE_DECIBEL) 1354c1daf651SAntti Palosaari *snr = div_s64(c->cnr.stat[0].svalue, 100); 1355395d00d1SAntti Palosaari else 1356395d00d1SAntti Palosaari *snr = 0; 1357395d00d1SAntti Palosaari 1358395d00d1SAntti Palosaari return 0; 1359395d00d1SAntti Palosaari } 1360395d00d1SAntti Palosaari 13614423a2baSAntti Palosaari static int m88ds3103_read_ber(struct dvb_frontend *fe, u32 *ber) 13624423a2baSAntti Palosaari { 13637978b8a1SAntti Palosaari struct m88ds3103_dev *dev = fe->demodulator_priv; 136441b9aa00SAntti Palosaari 13657978b8a1SAntti Palosaari *ber = dev->dvbv3_ber; 13664423a2baSAntti Palosaari 13674423a2baSAntti Palosaari return 0; 13684423a2baSAntti Palosaari } 1369395d00d1SAntti Palosaari 1370395d00d1SAntti Palosaari static int m88ds3103_set_tone(struct dvb_frontend *fe, 13710df289a2SMauro Carvalho Chehab enum fe_sec_tone_mode fe_sec_tone_mode) 1372395d00d1SAntti Palosaari { 13737978b8a1SAntti Palosaari struct m88ds3103_dev *dev = fe->demodulator_priv; 13747978b8a1SAntti Palosaari struct i2c_client *client = dev->client; 1375395d00d1SAntti Palosaari int ret; 1376478932b1SAntti Palosaari unsigned int utmp, tone, reg_a1_mask; 137741b9aa00SAntti Palosaari 13787978b8a1SAntti Palosaari dev_dbg(&client->dev, "fe_sec_tone_mode=%d\n", fe_sec_tone_mode); 1379395d00d1SAntti Palosaari 13807978b8a1SAntti Palosaari if (!dev->warm) { 1381395d00d1SAntti Palosaari ret = -EAGAIN; 1382395d00d1SAntti Palosaari goto err; 1383395d00d1SAntti Palosaari } 1384395d00d1SAntti Palosaari 1385395d00d1SAntti Palosaari switch (fe_sec_tone_mode) { 1386395d00d1SAntti Palosaari case SEC_TONE_ON: 1387395d00d1SAntti Palosaari tone = 0; 1388418a97cbSAntti Palosaari reg_a1_mask = 0x47; 1389395d00d1SAntti Palosaari break; 1390395d00d1SAntti Palosaari case SEC_TONE_OFF: 1391395d00d1SAntti Palosaari tone = 1; 1392395d00d1SAntti Palosaari reg_a1_mask = 0x00; 1393395d00d1SAntti Palosaari break; 1394395d00d1SAntti Palosaari default: 13957978b8a1SAntti Palosaari dev_dbg(&client->dev, "invalid fe_sec_tone_mode\n"); 1396395d00d1SAntti Palosaari ret = -EINVAL; 1397395d00d1SAntti Palosaari goto err; 1398395d00d1SAntti Palosaari } 1399395d00d1SAntti Palosaari 1400478932b1SAntti Palosaari utmp = tone << 7 | dev->cfg->envelope_mode << 5; 140156ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0xa2, 0xe0, utmp); 1402395d00d1SAntti Palosaari if (ret) 1403395d00d1SAntti Palosaari goto err; 1404395d00d1SAntti Palosaari 1405478932b1SAntti Palosaari utmp = 1 << 2; 140656ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0xa1, reg_a1_mask, utmp); 1407395d00d1SAntti Palosaari if (ret) 1408395d00d1SAntti Palosaari goto err; 1409395d00d1SAntti Palosaari 1410395d00d1SAntti Palosaari return 0; 1411395d00d1SAntti Palosaari err: 14127978b8a1SAntti Palosaari dev_dbg(&client->dev, "failed=%d\n", ret); 1413395d00d1SAntti Palosaari return ret; 1414395d00d1SAntti Palosaari } 1415395d00d1SAntti Palosaari 141679d09330Snibble.max static int m88ds3103_set_voltage(struct dvb_frontend *fe, 14170df289a2SMauro Carvalho Chehab enum fe_sec_voltage fe_sec_voltage) 141879d09330Snibble.max { 14197978b8a1SAntti Palosaari struct m88ds3103_dev *dev = fe->demodulator_priv; 14207978b8a1SAntti Palosaari struct i2c_client *client = dev->client; 1421d28677ffSAntti Palosaari int ret; 1422478932b1SAntti Palosaari unsigned int utmp; 1423d28677ffSAntti Palosaari bool voltage_sel, voltage_dis; 142479d09330Snibble.max 14257978b8a1SAntti Palosaari dev_dbg(&client->dev, "fe_sec_voltage=%d\n", fe_sec_voltage); 142679d09330Snibble.max 14277978b8a1SAntti Palosaari if (!dev->warm) { 1428d28677ffSAntti Palosaari ret = -EAGAIN; 1429d28677ffSAntti Palosaari goto err; 1430d28677ffSAntti Palosaari } 143179d09330Snibble.max 1432d28677ffSAntti Palosaari switch (fe_sec_voltage) { 143379d09330Snibble.max case SEC_VOLTAGE_18: 1434afbd6eb4SMauro Carvalho Chehab voltage_sel = true; 1435afbd6eb4SMauro Carvalho Chehab voltage_dis = false; 143679d09330Snibble.max break; 143779d09330Snibble.max case SEC_VOLTAGE_13: 1438afbd6eb4SMauro Carvalho Chehab voltage_sel = false; 1439afbd6eb4SMauro Carvalho Chehab voltage_dis = false; 144079d09330Snibble.max break; 144179d09330Snibble.max case SEC_VOLTAGE_OFF: 1442afbd6eb4SMauro Carvalho Chehab voltage_sel = false; 1443afbd6eb4SMauro Carvalho Chehab voltage_dis = true; 144479d09330Snibble.max break; 1445d28677ffSAntti Palosaari default: 14467978b8a1SAntti Palosaari dev_dbg(&client->dev, "invalid fe_sec_voltage\n"); 1447d28677ffSAntti Palosaari ret = -EINVAL; 1448d28677ffSAntti Palosaari goto err; 144979d09330Snibble.max } 1450d28677ffSAntti Palosaari 1451d28677ffSAntti Palosaari /* output pin polarity */ 14527978b8a1SAntti Palosaari voltage_sel ^= dev->cfg->lnb_hv_pol; 14537978b8a1SAntti Palosaari voltage_dis ^= dev->cfg->lnb_en_pol; 1454d28677ffSAntti Palosaari 1455478932b1SAntti Palosaari utmp = voltage_dis << 1 | voltage_sel << 0; 145656ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0xa2, 0x03, utmp); 1457d28677ffSAntti Palosaari if (ret) 1458d28677ffSAntti Palosaari goto err; 145979d09330Snibble.max 146079d09330Snibble.max return 0; 1461d28677ffSAntti Palosaari err: 14627978b8a1SAntti Palosaari dev_dbg(&client->dev, "failed=%d\n", ret); 1463d28677ffSAntti Palosaari return ret; 146479d09330Snibble.max } 146579d09330Snibble.max 1466395d00d1SAntti Palosaari static int m88ds3103_diseqc_send_master_cmd(struct dvb_frontend *fe, 1467395d00d1SAntti Palosaari struct dvb_diseqc_master_cmd *diseqc_cmd) 1468395d00d1SAntti Palosaari { 14697978b8a1SAntti Palosaari struct m88ds3103_dev *dev = fe->demodulator_priv; 14707978b8a1SAntti Palosaari struct i2c_client *client = dev->client; 1471befa0cc1SAntti Palosaari int ret; 1472478932b1SAntti Palosaari unsigned int utmp; 1473befa0cc1SAntti Palosaari unsigned long timeout; 147441b9aa00SAntti Palosaari 14757978b8a1SAntti Palosaari dev_dbg(&client->dev, "msg=%*ph\n", 1476395d00d1SAntti Palosaari diseqc_cmd->msg_len, diseqc_cmd->msg); 1477395d00d1SAntti Palosaari 14787978b8a1SAntti Palosaari if (!dev->warm) { 1479395d00d1SAntti Palosaari ret = -EAGAIN; 1480395d00d1SAntti Palosaari goto err; 1481395d00d1SAntti Palosaari } 1482395d00d1SAntti Palosaari 1483395d00d1SAntti Palosaari if (diseqc_cmd->msg_len < 3 || diseqc_cmd->msg_len > 6) { 1484395d00d1SAntti Palosaari ret = -EINVAL; 1485395d00d1SAntti Palosaari goto err; 1486395d00d1SAntti Palosaari } 1487395d00d1SAntti Palosaari 1488478932b1SAntti Palosaari utmp = dev->cfg->envelope_mode << 5; 148956ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0xa2, 0xe0, utmp); 1490395d00d1SAntti Palosaari if (ret) 1491395d00d1SAntti Palosaari goto err; 1492395d00d1SAntti Palosaari 1493478932b1SAntti Palosaari ret = regmap_bulk_write(dev->regmap, 0xa3, diseqc_cmd->msg, 1494395d00d1SAntti Palosaari diseqc_cmd->msg_len); 1495395d00d1SAntti Palosaari if (ret) 1496395d00d1SAntti Palosaari goto err; 1497395d00d1SAntti Palosaari 1498478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xa1, 1499395d00d1SAntti Palosaari (diseqc_cmd->msg_len - 1) << 3 | 0x07); 1500395d00d1SAntti Palosaari if (ret) 1501395d00d1SAntti Palosaari goto err; 1502395d00d1SAntti Palosaari 1503395d00d1SAntti Palosaari /* wait DiSEqC TX ready */ 1504befa0cc1SAntti Palosaari #define SEND_MASTER_CMD_TIMEOUT 120 1505befa0cc1SAntti Palosaari timeout = jiffies + msecs_to_jiffies(SEND_MASTER_CMD_TIMEOUT); 1506395d00d1SAntti Palosaari 15079ef3cdc1SAntti Palosaari /* DiSEqC message period is 13.5 ms per byte */ 15089ef3cdc1SAntti Palosaari utmp = diseqc_cmd->msg_len * 13500; 15099ef3cdc1SAntti Palosaari usleep_range(utmp - 4000, utmp); 1510befa0cc1SAntti Palosaari 1511478932b1SAntti Palosaari for (utmp = 1; !time_after(jiffies, timeout) && utmp;) { 1512478932b1SAntti Palosaari ret = regmap_read(dev->regmap, 0xa1, &utmp); 1513395d00d1SAntti Palosaari if (ret) 1514395d00d1SAntti Palosaari goto err; 1515478932b1SAntti Palosaari utmp = (utmp >> 6) & 0x1; 1516395d00d1SAntti Palosaari } 1517395d00d1SAntti Palosaari 1518478932b1SAntti Palosaari if (utmp == 0) { 15197978b8a1SAntti Palosaari dev_dbg(&client->dev, "diseqc tx took %u ms\n", 1520befa0cc1SAntti Palosaari jiffies_to_msecs(jiffies) - 1521befa0cc1SAntti Palosaari (jiffies_to_msecs(timeout) - SEND_MASTER_CMD_TIMEOUT)); 1522befa0cc1SAntti Palosaari } else { 15237978b8a1SAntti Palosaari dev_dbg(&client->dev, "diseqc tx timeout\n"); 1524395d00d1SAntti Palosaari 152556ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0xa1, 0xc0, 0x40); 1526395d00d1SAntti Palosaari if (ret) 1527395d00d1SAntti Palosaari goto err; 1528395d00d1SAntti Palosaari } 1529395d00d1SAntti Palosaari 153056ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0xa2, 0xc0, 0x80); 1531395d00d1SAntti Palosaari if (ret) 1532395d00d1SAntti Palosaari goto err; 1533395d00d1SAntti Palosaari 1534478932b1SAntti Palosaari if (utmp == 1) { 1535395d00d1SAntti Palosaari ret = -ETIMEDOUT; 1536395d00d1SAntti Palosaari goto err; 1537395d00d1SAntti Palosaari } 1538395d00d1SAntti Palosaari 1539395d00d1SAntti Palosaari return 0; 1540395d00d1SAntti Palosaari err: 15417978b8a1SAntti Palosaari dev_dbg(&client->dev, "failed=%d\n", ret); 1542395d00d1SAntti Palosaari return ret; 1543395d00d1SAntti Palosaari } 1544395d00d1SAntti Palosaari 1545395d00d1SAntti Palosaari static int m88ds3103_diseqc_send_burst(struct dvb_frontend *fe, 15460df289a2SMauro Carvalho Chehab enum fe_sec_mini_cmd fe_sec_mini_cmd) 1547395d00d1SAntti Palosaari { 15487978b8a1SAntti Palosaari struct m88ds3103_dev *dev = fe->demodulator_priv; 15497978b8a1SAntti Palosaari struct i2c_client *client = dev->client; 1550befa0cc1SAntti Palosaari int ret; 1551478932b1SAntti Palosaari unsigned int utmp, burst; 1552befa0cc1SAntti Palosaari unsigned long timeout; 155341b9aa00SAntti Palosaari 15547978b8a1SAntti Palosaari dev_dbg(&client->dev, "fe_sec_mini_cmd=%d\n", fe_sec_mini_cmd); 1555395d00d1SAntti Palosaari 15567978b8a1SAntti Palosaari if (!dev->warm) { 1557395d00d1SAntti Palosaari ret = -EAGAIN; 1558395d00d1SAntti Palosaari goto err; 1559395d00d1SAntti Palosaari } 1560395d00d1SAntti Palosaari 1561478932b1SAntti Palosaari utmp = dev->cfg->envelope_mode << 5; 156256ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0xa2, 0xe0, utmp); 1563395d00d1SAntti Palosaari if (ret) 1564395d00d1SAntti Palosaari goto err; 1565395d00d1SAntti Palosaari 1566395d00d1SAntti Palosaari switch (fe_sec_mini_cmd) { 1567395d00d1SAntti Palosaari case SEC_MINI_A: 1568395d00d1SAntti Palosaari burst = 0x02; 1569395d00d1SAntti Palosaari break; 1570395d00d1SAntti Palosaari case SEC_MINI_B: 1571395d00d1SAntti Palosaari burst = 0x01; 1572395d00d1SAntti Palosaari break; 1573395d00d1SAntti Palosaari default: 15747978b8a1SAntti Palosaari dev_dbg(&client->dev, "invalid fe_sec_mini_cmd\n"); 1575395d00d1SAntti Palosaari ret = -EINVAL; 1576395d00d1SAntti Palosaari goto err; 1577395d00d1SAntti Palosaari } 1578395d00d1SAntti Palosaari 1579478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xa1, burst); 1580395d00d1SAntti Palosaari if (ret) 1581395d00d1SAntti Palosaari goto err; 1582395d00d1SAntti Palosaari 1583395d00d1SAntti Palosaari /* wait DiSEqC TX ready */ 1584befa0cc1SAntti Palosaari #define SEND_BURST_TIMEOUT 40 1585befa0cc1SAntti Palosaari timeout = jiffies + msecs_to_jiffies(SEND_BURST_TIMEOUT); 1586395d00d1SAntti Palosaari 1587befa0cc1SAntti Palosaari /* DiSEqC ToneBurst period is 12.5 ms */ 1588befa0cc1SAntti Palosaari usleep_range(8500, 12500); 1589befa0cc1SAntti Palosaari 1590478932b1SAntti Palosaari for (utmp = 1; !time_after(jiffies, timeout) && utmp;) { 1591478932b1SAntti Palosaari ret = regmap_read(dev->regmap, 0xa1, &utmp); 1592395d00d1SAntti Palosaari if (ret) 1593395d00d1SAntti Palosaari goto err; 1594478932b1SAntti Palosaari utmp = (utmp >> 6) & 0x1; 1595395d00d1SAntti Palosaari } 1596395d00d1SAntti Palosaari 1597478932b1SAntti Palosaari if (utmp == 0) { 15987978b8a1SAntti Palosaari dev_dbg(&client->dev, "diseqc tx took %u ms\n", 1599befa0cc1SAntti Palosaari jiffies_to_msecs(jiffies) - 1600befa0cc1SAntti Palosaari (jiffies_to_msecs(timeout) - SEND_BURST_TIMEOUT)); 1601befa0cc1SAntti Palosaari } else { 16027978b8a1SAntti Palosaari dev_dbg(&client->dev, "diseqc tx timeout\n"); 1603befa0cc1SAntti Palosaari 160456ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0xa1, 0xc0, 0x40); 1605befa0cc1SAntti Palosaari if (ret) 1606befa0cc1SAntti Palosaari goto err; 1607befa0cc1SAntti Palosaari } 1608395d00d1SAntti Palosaari 160956ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0xa2, 0xc0, 0x80); 1610395d00d1SAntti Palosaari if (ret) 1611395d00d1SAntti Palosaari goto err; 1612395d00d1SAntti Palosaari 1613478932b1SAntti Palosaari if (utmp == 1) { 1614395d00d1SAntti Palosaari ret = -ETIMEDOUT; 1615395d00d1SAntti Palosaari goto err; 1616395d00d1SAntti Palosaari } 1617395d00d1SAntti Palosaari 1618395d00d1SAntti Palosaari return 0; 1619395d00d1SAntti Palosaari err: 16207978b8a1SAntti Palosaari dev_dbg(&client->dev, "failed=%d\n", ret); 1621395d00d1SAntti Palosaari return ret; 1622395d00d1SAntti Palosaari } 1623395d00d1SAntti Palosaari 1624395d00d1SAntti Palosaari static int m88ds3103_get_tune_settings(struct dvb_frontend *fe, 1625395d00d1SAntti Palosaari struct dvb_frontend_tune_settings *s) 1626395d00d1SAntti Palosaari { 1627395d00d1SAntti Palosaari s->min_delay_ms = 3000; 1628395d00d1SAntti Palosaari 1629395d00d1SAntti Palosaari return 0; 1630395d00d1SAntti Palosaari } 1631395d00d1SAntti Palosaari 163244b9055bSAntti Palosaari static void m88ds3103_release(struct dvb_frontend *fe) 1633395d00d1SAntti Palosaari { 16347978b8a1SAntti Palosaari struct m88ds3103_dev *dev = fe->demodulator_priv; 16357978b8a1SAntti Palosaari struct i2c_client *client = dev->client; 163641b9aa00SAntti Palosaari 1637f01919e8SAntti Palosaari i2c_unregister_device(client); 1638395d00d1SAntti Palosaari } 1639395d00d1SAntti Palosaari 1640e00fed40SPeter Rosin static int m88ds3103_select(struct i2c_mux_core *muxc, u32 chan) 1641395d00d1SAntti Palosaari { 1642e00fed40SPeter Rosin struct m88ds3103_dev *dev = i2c_mux_priv(muxc); 16437978b8a1SAntti Palosaari struct i2c_client *client = dev->client; 1644395d00d1SAntti Palosaari int ret; 1645478932b1SAntti Palosaari struct i2c_msg msg = { 16467978b8a1SAntti Palosaari .addr = client->addr, 1647395d00d1SAntti Palosaari .flags = 0, 1648395d00d1SAntti Palosaari .len = 2, 1649395d00d1SAntti Palosaari .buf = "\x03\x11", 1650395d00d1SAntti Palosaari }; 1651395d00d1SAntti Palosaari 1652478932b1SAntti Palosaari /* Open tuner I2C repeater for 1 xfer, closes automatically */ 1653478932b1SAntti Palosaari ret = __i2c_transfer(client->adapter, &msg, 1); 1654395d00d1SAntti Palosaari if (ret != 1) { 16557978b8a1SAntti Palosaari dev_warn(&client->dev, "i2c wr failed=%d\n", ret); 165644b9055bSAntti Palosaari if (ret >= 0) 1657395d00d1SAntti Palosaari ret = -EREMOTEIO; 1658395d00d1SAntti Palosaari return ret; 1659395d00d1SAntti Palosaari } 1660395d00d1SAntti Palosaari 166144b9055bSAntti Palosaari return 0; 166244b9055bSAntti Palosaari } 1663395d00d1SAntti Palosaari 1664f01919e8SAntti Palosaari /* 1665f01919e8SAntti Palosaari * XXX: That is wrapper to m88ds3103_probe() via driver core in order to provide 1666f01919e8SAntti Palosaari * proper I2C client for legacy media attach binding. 1667f01919e8SAntti Palosaari * New users must use I2C client binding directly! 1668f01919e8SAntti Palosaari */ 1669395d00d1SAntti Palosaari struct dvb_frontend *m88ds3103_attach(const struct m88ds3103_config *cfg, 1670b9c97c67SMauro Carvalho Chehab struct i2c_adapter *i2c, 1671b9c97c67SMauro Carvalho Chehab struct i2c_adapter **tuner_i2c_adapter) 1672395d00d1SAntti Palosaari { 1673f01919e8SAntti Palosaari struct i2c_client *client; 1674f01919e8SAntti Palosaari struct i2c_board_info board_info; 1675b9c97c67SMauro Carvalho Chehab struct m88ds3103_platform_data pdata = {}; 1676395d00d1SAntti Palosaari 1677f01919e8SAntti Palosaari pdata.clk = cfg->clock; 1678f01919e8SAntti Palosaari pdata.i2c_wr_max = cfg->i2c_wr_max; 1679f01919e8SAntti Palosaari pdata.ts_mode = cfg->ts_mode; 1680f01919e8SAntti Palosaari pdata.ts_clk = cfg->ts_clk; 1681f01919e8SAntti Palosaari pdata.ts_clk_pol = cfg->ts_clk_pol; 1682f01919e8SAntti Palosaari pdata.spec_inv = cfg->spec_inv; 1683f01919e8SAntti Palosaari pdata.agc = cfg->agc; 1684f01919e8SAntti Palosaari pdata.agc_inv = cfg->agc_inv; 1685f01919e8SAntti Palosaari pdata.clk_out = cfg->clock_out; 1686f01919e8SAntti Palosaari pdata.envelope_mode = cfg->envelope_mode; 1687f01919e8SAntti Palosaari pdata.lnb_hv_pol = cfg->lnb_hv_pol; 1688f01919e8SAntti Palosaari pdata.lnb_en_pol = cfg->lnb_en_pol; 1689f01919e8SAntti Palosaari pdata.attach_in_use = true; 1690395d00d1SAntti Palosaari 1691f01919e8SAntti Palosaari memset(&board_info, 0, sizeof(board_info)); 1692c0decac1SMauro Carvalho Chehab strscpy(board_info.type, "m88ds3103", I2C_NAME_SIZE); 1693f01919e8SAntti Palosaari board_info.addr = cfg->i2c_addr; 1694f01919e8SAntti Palosaari board_info.platform_data = &pdata; 1695aace5926SWolfram Sang client = i2c_new_client_device(i2c, &board_info); 1696aace5926SWolfram Sang if (!i2c_client_has_driver(client)) 1697395d00d1SAntti Palosaari return NULL; 1698f01919e8SAntti Palosaari 1699f01919e8SAntti Palosaari *tuner_i2c_adapter = pdata.get_i2c_adapter(client); 1700f01919e8SAntti Palosaari return pdata.get_dvb_frontend(client); 1701395d00d1SAntti Palosaari } 1702395d00d1SAntti Palosaari EXPORT_SYMBOL(m88ds3103_attach); 1703395d00d1SAntti Palosaari 1704bd336e63SMax Kellermann static const struct dvb_frontend_ops m88ds3103_ops = { 1705395d00d1SAntti Palosaari .delsys = {SYS_DVBS, SYS_DVBS2}, 1706395d00d1SAntti Palosaari .info = { 17077978b8a1SAntti Palosaari .name = "Montage Technology M88DS3103", 1708f1b1eabfSMauro Carvalho Chehab .frequency_min_hz = 950 * MHz, 1709f1b1eabfSMauro Carvalho Chehab .frequency_max_hz = 2150 * MHz, 1710f1b1eabfSMauro Carvalho Chehab .frequency_tolerance_hz = 5 * MHz, 1711395d00d1SAntti Palosaari .symbol_rate_min = 1000000, 1712395d00d1SAntti Palosaari .symbol_rate_max = 45000000, 1713395d00d1SAntti Palosaari .caps = FE_CAN_INVERSION_AUTO | 1714395d00d1SAntti Palosaari FE_CAN_FEC_1_2 | 1715395d00d1SAntti Palosaari FE_CAN_FEC_2_3 | 1716395d00d1SAntti Palosaari FE_CAN_FEC_3_4 | 1717395d00d1SAntti Palosaari FE_CAN_FEC_4_5 | 1718395d00d1SAntti Palosaari FE_CAN_FEC_5_6 | 1719395d00d1SAntti Palosaari FE_CAN_FEC_6_7 | 1720395d00d1SAntti Palosaari FE_CAN_FEC_7_8 | 1721395d00d1SAntti Palosaari FE_CAN_FEC_8_9 | 1722395d00d1SAntti Palosaari FE_CAN_FEC_AUTO | 1723395d00d1SAntti Palosaari FE_CAN_QPSK | 1724395d00d1SAntti Palosaari FE_CAN_RECOVER | 1725395d00d1SAntti Palosaari FE_CAN_2G_MODULATION 1726395d00d1SAntti Palosaari }, 1727395d00d1SAntti Palosaari 1728395d00d1SAntti Palosaari .release = m88ds3103_release, 1729395d00d1SAntti Palosaari 1730395d00d1SAntti Palosaari .get_tune_settings = m88ds3103_get_tune_settings, 1731395d00d1SAntti Palosaari 1732395d00d1SAntti Palosaari .init = m88ds3103_init, 1733395d00d1SAntti Palosaari .sleep = m88ds3103_sleep, 1734395d00d1SAntti Palosaari 1735395d00d1SAntti Palosaari .set_frontend = m88ds3103_set_frontend, 1736395d00d1SAntti Palosaari .get_frontend = m88ds3103_get_frontend, 1737395d00d1SAntti Palosaari 1738395d00d1SAntti Palosaari .read_status = m88ds3103_read_status, 1739395d00d1SAntti Palosaari .read_snr = m88ds3103_read_snr, 17404423a2baSAntti Palosaari .read_ber = m88ds3103_read_ber, 1741395d00d1SAntti Palosaari 1742395d00d1SAntti Palosaari .diseqc_send_master_cmd = m88ds3103_diseqc_send_master_cmd, 1743395d00d1SAntti Palosaari .diseqc_send_burst = m88ds3103_diseqc_send_burst, 1744395d00d1SAntti Palosaari 1745395d00d1SAntti Palosaari .set_tone = m88ds3103_set_tone, 174679d09330Snibble.max .set_voltage = m88ds3103_set_voltage, 1747395d00d1SAntti Palosaari }; 1748395d00d1SAntti Palosaari 1749f01919e8SAntti Palosaari static struct dvb_frontend *m88ds3103_get_dvb_frontend(struct i2c_client *client) 1750f01919e8SAntti Palosaari { 17517978b8a1SAntti Palosaari struct m88ds3103_dev *dev = i2c_get_clientdata(client); 1752f01919e8SAntti Palosaari 1753f01919e8SAntti Palosaari dev_dbg(&client->dev, "\n"); 1754f01919e8SAntti Palosaari 1755f01919e8SAntti Palosaari return &dev->fe; 1756f01919e8SAntti Palosaari } 1757f01919e8SAntti Palosaari 1758f01919e8SAntti Palosaari static struct i2c_adapter *m88ds3103_get_i2c_adapter(struct i2c_client *client) 1759f01919e8SAntti Palosaari { 17607978b8a1SAntti Palosaari struct m88ds3103_dev *dev = i2c_get_clientdata(client); 1761f01919e8SAntti Palosaari 1762f01919e8SAntti Palosaari dev_dbg(&client->dev, "\n"); 1763f01919e8SAntti Palosaari 1764e00fed40SPeter Rosin return dev->muxc->adapter[0]; 1765f01919e8SAntti Palosaari } 1766f01919e8SAntti Palosaari 1767f01919e8SAntti Palosaari static int m88ds3103_probe(struct i2c_client *client, 1768f01919e8SAntti Palosaari const struct i2c_device_id *id) 1769f01919e8SAntti Palosaari { 17707978b8a1SAntti Palosaari struct m88ds3103_dev *dev; 1771f01919e8SAntti Palosaari struct m88ds3103_platform_data *pdata = client->dev.platform_data; 1772f01919e8SAntti Palosaari int ret; 1773478932b1SAntti Palosaari unsigned int utmp; 1774f01919e8SAntti Palosaari 1775f01919e8SAntti Palosaari dev = kzalloc(sizeof(*dev), GFP_KERNEL); 1776f01919e8SAntti Palosaari if (!dev) { 1777f01919e8SAntti Palosaari ret = -ENOMEM; 1778f01919e8SAntti Palosaari goto err; 1779f01919e8SAntti Palosaari } 1780f01919e8SAntti Palosaari 1781f01919e8SAntti Palosaari dev->client = client; 1782f01919e8SAntti Palosaari dev->config.clock = pdata->clk; 1783f01919e8SAntti Palosaari dev->config.i2c_wr_max = pdata->i2c_wr_max; 1784f01919e8SAntti Palosaari dev->config.ts_mode = pdata->ts_mode; 1785f5d9b88dSAntti Palosaari dev->config.ts_clk = pdata->ts_clk * 1000; 1786f01919e8SAntti Palosaari dev->config.ts_clk_pol = pdata->ts_clk_pol; 1787f01919e8SAntti Palosaari dev->config.spec_inv = pdata->spec_inv; 1788f01919e8SAntti Palosaari dev->config.agc_inv = pdata->agc_inv; 1789f01919e8SAntti Palosaari dev->config.clock_out = pdata->clk_out; 1790f01919e8SAntti Palosaari dev->config.envelope_mode = pdata->envelope_mode; 1791f01919e8SAntti Palosaari dev->config.agc = pdata->agc; 1792f01919e8SAntti Palosaari dev->config.lnb_hv_pol = pdata->lnb_hv_pol; 1793f01919e8SAntti Palosaari dev->config.lnb_en_pol = pdata->lnb_en_pol; 1794f01919e8SAntti Palosaari dev->cfg = &dev->config; 1795478932b1SAntti Palosaari /* create regmap */ 1796478932b1SAntti Palosaari dev->regmap_config.reg_bits = 8, 1797478932b1SAntti Palosaari dev->regmap_config.val_bits = 8, 1798478932b1SAntti Palosaari dev->regmap_config.lock_arg = dev, 1799478932b1SAntti Palosaari dev->regmap = devm_regmap_init_i2c(client, &dev->regmap_config); 1800478932b1SAntti Palosaari if (IS_ERR(dev->regmap)) { 1801478932b1SAntti Palosaari ret = PTR_ERR(dev->regmap); 1802478932b1SAntti Palosaari goto err_kfree; 1803478932b1SAntti Palosaari } 1804f01919e8SAntti Palosaari 1805f01919e8SAntti Palosaari /* 0x00: chip id[6:0], 0x01: chip ver[7:0], 0x02: chip ver[15:8] */ 1806478932b1SAntti Palosaari ret = regmap_read(dev->regmap, 0x00, &utmp); 1807f01919e8SAntti Palosaari if (ret) 1808f01919e8SAntti Palosaari goto err_kfree; 1809f01919e8SAntti Palosaari 1810478932b1SAntti Palosaari dev->chip_id = utmp >> 1; 1811e6089fecSBrad Love dev->chiptype = (u8)id->driver_data; 1812e6089fecSBrad Love 1813478932b1SAntti Palosaari dev_dbg(&client->dev, "chip_id=%02x\n", dev->chip_id); 1814f01919e8SAntti Palosaari 1815478932b1SAntti Palosaari switch (dev->chip_id) { 1816f01919e8SAntti Palosaari case M88RS6000_CHIP_ID: 1817f01919e8SAntti Palosaari case M88DS3103_CHIP_ID: 1818f01919e8SAntti Palosaari break; 1819f01919e8SAntti Palosaari default: 1820b9c97c67SMauro Carvalho Chehab ret = -ENODEV; 1821b9c97c67SMauro Carvalho Chehab dev_err(&client->dev, "Unknown device. Chip_id=%02x\n", dev->chip_id); 1822f01919e8SAntti Palosaari goto err_kfree; 1823f01919e8SAntti Palosaari } 1824f01919e8SAntti Palosaari 1825f01919e8SAntti Palosaari switch (dev->cfg->clock_out) { 1826f01919e8SAntti Palosaari case M88DS3103_CLOCK_OUT_DISABLED: 1827478932b1SAntti Palosaari utmp = 0x80; 1828f01919e8SAntti Palosaari break; 1829f01919e8SAntti Palosaari case M88DS3103_CLOCK_OUT_ENABLED: 1830478932b1SAntti Palosaari utmp = 0x00; 1831f01919e8SAntti Palosaari break; 1832f01919e8SAntti Palosaari case M88DS3103_CLOCK_OUT_ENABLED_DIV2: 1833478932b1SAntti Palosaari utmp = 0x10; 1834f01919e8SAntti Palosaari break; 1835f01919e8SAntti Palosaari default: 18364347df6aSDan Carpenter ret = -EINVAL; 1837f01919e8SAntti Palosaari goto err_kfree; 1838f01919e8SAntti Palosaari } 1839f01919e8SAntti Palosaari 1840334ef18eSAntti Palosaari if (!pdata->ts_clk) { 1841334ef18eSAntti Palosaari ret = -EINVAL; 1842334ef18eSAntti Palosaari goto err_kfree; 1843334ef18eSAntti Palosaari } 1844334ef18eSAntti Palosaari 1845f01919e8SAntti Palosaari /* 0x29 register is defined differently for m88rs6000. */ 1846f01919e8SAntti Palosaari /* set internal tuner address to 0x21 */ 1847478932b1SAntti Palosaari if (dev->chip_id == M88RS6000_CHIP_ID) 1848478932b1SAntti Palosaari utmp = 0x00; 1849f01919e8SAntti Palosaari 1850478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0x29, utmp); 1851f01919e8SAntti Palosaari if (ret) 1852f01919e8SAntti Palosaari goto err_kfree; 1853f01919e8SAntti Palosaari 1854f01919e8SAntti Palosaari /* sleep */ 185556ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x08, 0x01, 0x00); 1856f01919e8SAntti Palosaari if (ret) 1857f01919e8SAntti Palosaari goto err_kfree; 185856ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x04, 0x01, 0x01); 1859f01919e8SAntti Palosaari if (ret) 1860f01919e8SAntti Palosaari goto err_kfree; 186156ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x23, 0x10, 0x10); 1862f01919e8SAntti Palosaari if (ret) 1863f01919e8SAntti Palosaari goto err_kfree; 1864f01919e8SAntti Palosaari 1865f01919e8SAntti Palosaari /* create mux i2c adapter for tuner */ 1866e00fed40SPeter Rosin dev->muxc = i2c_mux_alloc(client->adapter, &client->dev, 1, 0, 0, 1867e00fed40SPeter Rosin m88ds3103_select, NULL); 1868e00fed40SPeter Rosin if (!dev->muxc) { 18694347df6aSDan Carpenter ret = -ENOMEM; 1870f01919e8SAntti Palosaari goto err_kfree; 18714347df6aSDan Carpenter } 1872e00fed40SPeter Rosin dev->muxc->priv = dev; 1873e00fed40SPeter Rosin ret = i2c_mux_add_adapter(dev->muxc, 0, 0, 0); 1874e00fed40SPeter Rosin if (ret) 1875e00fed40SPeter Rosin goto err_kfree; 1876f01919e8SAntti Palosaari 1877f01919e8SAntti Palosaari /* create dvb_frontend */ 1878f01919e8SAntti Palosaari memcpy(&dev->fe.ops, &m88ds3103_ops, sizeof(struct dvb_frontend_ops)); 1879e6089fecSBrad Love if (dev->chiptype == M88DS3103_CHIPTYPE_3103B) 1880e6089fecSBrad Love strscpy(dev->fe.ops.info.name, "Montage Technology M88DS3103B", 1881e6089fecSBrad Love sizeof(dev->fe.ops.info.name)); 1882e6089fecSBrad Love else if (dev->chip_id == M88RS6000_CHIP_ID) 188385709cbfSMauro Carvalho Chehab strscpy(dev->fe.ops.info.name, "Montage Technology M88RS6000", 18847978b8a1SAntti Palosaari sizeof(dev->fe.ops.info.name)); 1885f01919e8SAntti Palosaari if (!pdata->attach_in_use) 1886f01919e8SAntti Palosaari dev->fe.ops.release = NULL; 1887f01919e8SAntti Palosaari dev->fe.demodulator_priv = dev; 1888f01919e8SAntti Palosaari i2c_set_clientdata(client, dev); 1889f01919e8SAntti Palosaari 1890f01919e8SAntti Palosaari /* setup callbacks */ 1891f01919e8SAntti Palosaari pdata->get_dvb_frontend = m88ds3103_get_dvb_frontend; 1892f01919e8SAntti Palosaari pdata->get_i2c_adapter = m88ds3103_get_i2c_adapter; 1893e6089fecSBrad Love 1894e6089fecSBrad Love if (dev->chiptype == M88DS3103_CHIPTYPE_3103B) { 1895e6089fecSBrad Love /* enable i2c repeater for tuner */ 1896e6089fecSBrad Love m88ds3103_update_bits(dev, 0x11, 0x01, 0x01); 1897e6089fecSBrad Love 1898e6089fecSBrad Love /* get frontend address */ 1899e6089fecSBrad Love ret = regmap_read(dev->regmap, 0x29, &utmp); 1900e6089fecSBrad Love if (ret) 1901e6089fecSBrad Love goto err_kfree; 1902e6089fecSBrad Love dev->dt_addr = ((utmp & 0x80) == 0) ? 0x42 >> 1 : 0x40 >> 1; 1903c77591a8SChristophe JAILLET dev_dbg(&client->dev, "dt addr is 0x%02x\n", dev->dt_addr); 1904e6089fecSBrad Love 1905e6089fecSBrad Love dev->dt_client = i2c_new_dummy_device(client->adapter, 1906e6089fecSBrad Love dev->dt_addr); 1907e6089fecSBrad Love if (!dev->dt_client) { 1908e6089fecSBrad Love ret = -ENODEV; 1909e6089fecSBrad Love goto err_kfree; 1910e6089fecSBrad Love } 1911e6089fecSBrad Love } 1912e6089fecSBrad Love 1913f01919e8SAntti Palosaari return 0; 1914f01919e8SAntti Palosaari err_kfree: 1915f01919e8SAntti Palosaari kfree(dev); 1916f01919e8SAntti Palosaari err: 1917f01919e8SAntti Palosaari dev_dbg(&client->dev, "failed=%d\n", ret); 1918f01919e8SAntti Palosaari return ret; 1919f01919e8SAntti Palosaari } 1920f01919e8SAntti Palosaari 1921f01919e8SAntti Palosaari static int m88ds3103_remove(struct i2c_client *client) 1922f01919e8SAntti Palosaari { 19237978b8a1SAntti Palosaari struct m88ds3103_dev *dev = i2c_get_clientdata(client); 1924f01919e8SAntti Palosaari 1925f01919e8SAntti Palosaari dev_dbg(&client->dev, "\n"); 1926f01919e8SAntti Palosaari 1927e6089fecSBrad Love if (dev->dt_client) 1928e6089fecSBrad Love i2c_unregister_device(dev->dt_client); 1929e6089fecSBrad Love 1930e00fed40SPeter Rosin i2c_mux_del_adapters(dev->muxc); 1931f01919e8SAntti Palosaari 1932f01919e8SAntti Palosaari kfree(dev); 1933f01919e8SAntti Palosaari return 0; 1934f01919e8SAntti Palosaari } 1935f01919e8SAntti Palosaari 1936f01919e8SAntti Palosaari static const struct i2c_device_id m88ds3103_id_table[] = { 1937e6089fecSBrad Love {"m88ds3103", M88DS3103_CHIPTYPE_3103}, 1938e6089fecSBrad Love {"m88rs6000", M88DS3103_CHIPTYPE_RS6000}, 1939e6089fecSBrad Love {"m88ds3103b", M88DS3103_CHIPTYPE_3103B}, 1940f01919e8SAntti Palosaari {} 1941f01919e8SAntti Palosaari }; 1942f01919e8SAntti Palosaari MODULE_DEVICE_TABLE(i2c, m88ds3103_id_table); 1943f01919e8SAntti Palosaari 1944f01919e8SAntti Palosaari static struct i2c_driver m88ds3103_driver = { 1945f01919e8SAntti Palosaari .driver = { 1946f01919e8SAntti Palosaari .name = "m88ds3103", 1947f01919e8SAntti Palosaari .suppress_bind_attrs = true, 1948f01919e8SAntti Palosaari }, 1949f01919e8SAntti Palosaari .probe = m88ds3103_probe, 1950f01919e8SAntti Palosaari .remove = m88ds3103_remove, 1951f01919e8SAntti Palosaari .id_table = m88ds3103_id_table, 1952f01919e8SAntti Palosaari }; 1953f01919e8SAntti Palosaari 1954f01919e8SAntti Palosaari module_i2c_driver(m88ds3103_driver); 1955f01919e8SAntti Palosaari 1956395d00d1SAntti Palosaari MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>"); 19577978b8a1SAntti Palosaari MODULE_DESCRIPTION("Montage Technology M88DS3103 DVB-S/S2 demodulator driver"); 1958395d00d1SAntti Palosaari MODULE_LICENSE("GPL"); 1959395d00d1SAntti Palosaari MODULE_FIRMWARE(M88DS3103_FIRMWARE); 1960f4df95bcSnibble.max MODULE_FIRMWARE(M88RS6000_FIRMWARE); 1961e6089fecSBrad Love MODULE_FIRMWARE(M88DS3103B_FIRMWARE); 1962