1395d00d1SAntti Palosaari /* 27978b8a1SAntti Palosaari * Montage Technology M88DS3103/M88RS6000 demodulator driver 3395d00d1SAntti Palosaari * 4395d00d1SAntti Palosaari * Copyright (C) 2013 Antti Palosaari <crope@iki.fi> 5395d00d1SAntti Palosaari * 6395d00d1SAntti Palosaari * This program is free software; you can redistribute it and/or modify 7395d00d1SAntti Palosaari * it under the terms of the GNU General Public License as published by 8395d00d1SAntti Palosaari * the Free Software Foundation; either version 2 of the License, or 9395d00d1SAntti Palosaari * (at your option) any later version. 10395d00d1SAntti Palosaari * 11395d00d1SAntti Palosaari * This program is distributed in the hope that it will be useful, 12395d00d1SAntti Palosaari * but WITHOUT ANY WARRANTY; without even the implied warranty of 13395d00d1SAntti Palosaari * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14395d00d1SAntti Palosaari * GNU General Public License for more details. 15395d00d1SAntti Palosaari */ 16395d00d1SAntti Palosaari 17395d00d1SAntti Palosaari #include "m88ds3103_priv.h" 18395d00d1SAntti Palosaari 19395d00d1SAntti Palosaari static struct dvb_frontend_ops m88ds3103_ops; 20395d00d1SAntti Palosaari 2156ea37daSAntti Palosaari /* write single register with mask */ 2256ea37daSAntti Palosaari static int m88ds3103_update_bits(struct m88ds3103_dev *dev, 2356ea37daSAntti Palosaari u8 reg, u8 mask, u8 val) 2456ea37daSAntti Palosaari { 2556ea37daSAntti Palosaari int ret; 2656ea37daSAntti Palosaari u8 tmp; 2756ea37daSAntti Palosaari 2856ea37daSAntti Palosaari /* no need for read if whole reg is written */ 2956ea37daSAntti Palosaari if (mask != 0xff) { 3056ea37daSAntti Palosaari ret = regmap_bulk_read(dev->regmap, reg, &tmp, 1); 3156ea37daSAntti Palosaari if (ret) 3256ea37daSAntti Palosaari return ret; 3356ea37daSAntti Palosaari 3456ea37daSAntti Palosaari val &= mask; 3556ea37daSAntti Palosaari tmp &= ~mask; 3656ea37daSAntti Palosaari val |= tmp; 3756ea37daSAntti Palosaari } 3856ea37daSAntti Palosaari 3956ea37daSAntti Palosaari return regmap_bulk_write(dev->regmap, reg, &val, 1); 4056ea37daSAntti Palosaari } 4156ea37daSAntti Palosaari 4206487deeSAntti Palosaari /* write reg val table using reg addr auto increment */ 437978b8a1SAntti Palosaari static int m88ds3103_wr_reg_val_tab(struct m88ds3103_dev *dev, 4406487deeSAntti Palosaari const struct m88ds3103_reg_val *tab, int tab_len) 4506487deeSAntti Palosaari { 467978b8a1SAntti Palosaari struct i2c_client *client = dev->client; 4706487deeSAntti Palosaari int ret, i, j; 4806487deeSAntti Palosaari u8 buf[83]; 4941b9aa00SAntti Palosaari 507978b8a1SAntti Palosaari dev_dbg(&client->dev, "tab_len=%d\n", tab_len); 5106487deeSAntti Palosaari 52f4df95bcSnibble.max if (tab_len > 86) { 5306487deeSAntti Palosaari ret = -EINVAL; 5406487deeSAntti Palosaari goto err; 5506487deeSAntti Palosaari } 5606487deeSAntti Palosaari 5706487deeSAntti Palosaari for (i = 0, j = 0; i < tab_len; i++, j++) { 5806487deeSAntti Palosaari buf[j] = tab[i].val; 5906487deeSAntti Palosaari 6006487deeSAntti Palosaari if (i == tab_len - 1 || tab[i].reg != tab[i + 1].reg - 1 || 617978b8a1SAntti Palosaari !((j + 1) % (dev->cfg->i2c_wr_max - 1))) { 62478932b1SAntti Palosaari ret = regmap_bulk_write(dev->regmap, tab[i].reg - j, buf, j + 1); 6306487deeSAntti Palosaari if (ret) 6406487deeSAntti Palosaari goto err; 6506487deeSAntti Palosaari 6606487deeSAntti Palosaari j = -1; 6706487deeSAntti Palosaari } 6806487deeSAntti Palosaari } 6906487deeSAntti Palosaari 7006487deeSAntti Palosaari return 0; 7106487deeSAntti Palosaari err: 727978b8a1SAntti Palosaari dev_dbg(&client->dev, "failed=%d\n", ret); 7306487deeSAntti Palosaari return ret; 7406487deeSAntti Palosaari } 7506487deeSAntti Palosaari 760f91c9d6SDavid Howells /* 770f91c9d6SDavid Howells * Get the demodulator AGC PWM voltage setting supplied to the tuner. 780f91c9d6SDavid Howells */ 790f91c9d6SDavid Howells int m88ds3103_get_agc_pwm(struct dvb_frontend *fe, u8 *_agc_pwm) 800f91c9d6SDavid Howells { 810f91c9d6SDavid Howells struct m88ds3103_dev *dev = fe->demodulator_priv; 820f91c9d6SDavid Howells unsigned tmp; 830f91c9d6SDavid Howells int ret; 840f91c9d6SDavid Howells 850f91c9d6SDavid Howells ret = regmap_read(dev->regmap, 0x3f, &tmp); 860f91c9d6SDavid Howells if (ret == 0) 870f91c9d6SDavid Howells *_agc_pwm = tmp; 880f91c9d6SDavid Howells return ret; 890f91c9d6SDavid Howells } 900f91c9d6SDavid Howells EXPORT_SYMBOL(m88ds3103_get_agc_pwm); 910f91c9d6SDavid Howells 920df289a2SMauro Carvalho Chehab static int m88ds3103_read_status(struct dvb_frontend *fe, 930df289a2SMauro Carvalho Chehab enum fe_status *status) 94395d00d1SAntti Palosaari { 957978b8a1SAntti Palosaari struct m88ds3103_dev *dev = fe->demodulator_priv; 967978b8a1SAntti Palosaari struct i2c_client *client = dev->client; 97395d00d1SAntti Palosaari struct dtv_frontend_properties *c = &fe->dtv_property_cache; 98c1daf651SAntti Palosaari int ret, i, itmp; 99478932b1SAntti Palosaari unsigned int utmp; 100c1daf651SAntti Palosaari u8 buf[3]; 101395d00d1SAntti Palosaari 102395d00d1SAntti Palosaari *status = 0; 103395d00d1SAntti Palosaari 1047978b8a1SAntti Palosaari if (!dev->warm) { 105395d00d1SAntti Palosaari ret = -EAGAIN; 106395d00d1SAntti Palosaari goto err; 107395d00d1SAntti Palosaari } 108395d00d1SAntti Palosaari 109395d00d1SAntti Palosaari switch (c->delivery_system) { 110395d00d1SAntti Palosaari case SYS_DVBS: 111478932b1SAntti Palosaari ret = regmap_read(dev->regmap, 0xd1, &utmp); 112395d00d1SAntti Palosaari if (ret) 113395d00d1SAntti Palosaari goto err; 114395d00d1SAntti Palosaari 115478932b1SAntti Palosaari if ((utmp & 0x07) == 0x07) 116395d00d1SAntti Palosaari *status = FE_HAS_SIGNAL | FE_HAS_CARRIER | 117395d00d1SAntti Palosaari FE_HAS_VITERBI | FE_HAS_SYNC | 118395d00d1SAntti Palosaari FE_HAS_LOCK; 119395d00d1SAntti Palosaari break; 120395d00d1SAntti Palosaari case SYS_DVBS2: 121478932b1SAntti Palosaari ret = regmap_read(dev->regmap, 0x0d, &utmp); 122395d00d1SAntti Palosaari if (ret) 123395d00d1SAntti Palosaari goto err; 124395d00d1SAntti Palosaari 125478932b1SAntti Palosaari if ((utmp & 0x8f) == 0x8f) 126395d00d1SAntti Palosaari *status = FE_HAS_SIGNAL | FE_HAS_CARRIER | 127395d00d1SAntti Palosaari FE_HAS_VITERBI | FE_HAS_SYNC | 128395d00d1SAntti Palosaari FE_HAS_LOCK; 129395d00d1SAntti Palosaari break; 130395d00d1SAntti Palosaari default: 1317978b8a1SAntti Palosaari dev_dbg(&client->dev, "invalid delivery_system\n"); 132395d00d1SAntti Palosaari ret = -EINVAL; 133395d00d1SAntti Palosaari goto err; 134395d00d1SAntti Palosaari } 135395d00d1SAntti Palosaari 1367978b8a1SAntti Palosaari dev->fe_status = *status; 137478932b1SAntti Palosaari dev_dbg(&client->dev, "lock=%02x status=%02x\n", utmp, *status); 138395d00d1SAntti Palosaari 139c1daf651SAntti Palosaari /* CNR */ 1407978b8a1SAntti Palosaari if (dev->fe_status & FE_HAS_VITERBI) { 141c1daf651SAntti Palosaari unsigned int cnr, noise, signal, noise_tot, signal_tot; 142c1daf651SAntti Palosaari 143c1daf651SAntti Palosaari cnr = 0; 144c1daf651SAntti Palosaari /* more iterations for more accurate estimation */ 145c1daf651SAntti Palosaari #define M88DS3103_SNR_ITERATIONS 3 146c1daf651SAntti Palosaari 147c1daf651SAntti Palosaari switch (c->delivery_system) { 148c1daf651SAntti Palosaari case SYS_DVBS: 149c1daf651SAntti Palosaari itmp = 0; 150c1daf651SAntti Palosaari 151c1daf651SAntti Palosaari for (i = 0; i < M88DS3103_SNR_ITERATIONS; i++) { 152478932b1SAntti Palosaari ret = regmap_read(dev->regmap, 0xff, &utmp); 153c1daf651SAntti Palosaari if (ret) 154c1daf651SAntti Palosaari goto err; 155c1daf651SAntti Palosaari 156478932b1SAntti Palosaari itmp += utmp; 157c1daf651SAntti Palosaari } 158c1daf651SAntti Palosaari 159c1daf651SAntti Palosaari /* use of single register limits max value to 15 dB */ 160c1daf651SAntti Palosaari /* SNR(X) dB = 10 * ln(X) / ln(10) dB */ 161c1daf651SAntti Palosaari itmp = DIV_ROUND_CLOSEST(itmp, 8 * M88DS3103_SNR_ITERATIONS); 162c1daf651SAntti Palosaari if (itmp) 163c1daf651SAntti Palosaari cnr = div_u64((u64) 10000 * intlog2(itmp), intlog2(10)); 164c1daf651SAntti Palosaari break; 165c1daf651SAntti Palosaari case SYS_DVBS2: 166c1daf651SAntti Palosaari noise_tot = 0; 167c1daf651SAntti Palosaari signal_tot = 0; 168c1daf651SAntti Palosaari 169c1daf651SAntti Palosaari for (i = 0; i < M88DS3103_SNR_ITERATIONS; i++) { 170478932b1SAntti Palosaari ret = regmap_bulk_read(dev->regmap, 0x8c, buf, 3); 171c1daf651SAntti Palosaari if (ret) 172c1daf651SAntti Palosaari goto err; 173c1daf651SAntti Palosaari 174c1daf651SAntti Palosaari noise = buf[1] << 6; /* [13:6] */ 175c1daf651SAntti Palosaari noise |= buf[0] & 0x3f; /* [5:0] */ 176c1daf651SAntti Palosaari noise >>= 2; 177c1daf651SAntti Palosaari signal = buf[2] * buf[2]; 178c1daf651SAntti Palosaari signal >>= 1; 179c1daf651SAntti Palosaari 180c1daf651SAntti Palosaari noise_tot += noise; 181c1daf651SAntti Palosaari signal_tot += signal; 182c1daf651SAntti Palosaari } 183c1daf651SAntti Palosaari 184c1daf651SAntti Palosaari noise = noise_tot / M88DS3103_SNR_ITERATIONS; 185c1daf651SAntti Palosaari signal = signal_tot / M88DS3103_SNR_ITERATIONS; 186c1daf651SAntti Palosaari 187c1daf651SAntti Palosaari /* SNR(X) dB = 10 * log10(X) dB */ 188c1daf651SAntti Palosaari if (signal > noise) { 189c1daf651SAntti Palosaari itmp = signal / noise; 190c1daf651SAntti Palosaari cnr = div_u64((u64) 10000 * intlog10(itmp), (1 << 24)); 191c1daf651SAntti Palosaari } 192c1daf651SAntti Palosaari break; 193c1daf651SAntti Palosaari default: 1947978b8a1SAntti Palosaari dev_dbg(&client->dev, "invalid delivery_system\n"); 195c1daf651SAntti Palosaari ret = -EINVAL; 196c1daf651SAntti Palosaari goto err; 197c1daf651SAntti Palosaari } 198c1daf651SAntti Palosaari 199c1daf651SAntti Palosaari if (cnr) { 200c1daf651SAntti Palosaari c->cnr.stat[0].scale = FE_SCALE_DECIBEL; 201c1daf651SAntti Palosaari c->cnr.stat[0].svalue = cnr; 202c1daf651SAntti Palosaari } else { 203c1daf651SAntti Palosaari c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; 204c1daf651SAntti Palosaari } 205c1daf651SAntti Palosaari } else { 206c1daf651SAntti Palosaari c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; 207c1daf651SAntti Palosaari } 208c1daf651SAntti Palosaari 209ce80d713SAntti Palosaari /* BER */ 2107978b8a1SAntti Palosaari if (dev->fe_status & FE_HAS_LOCK) { 211ce80d713SAntti Palosaari unsigned int utmp, post_bit_error, post_bit_count; 212ce80d713SAntti Palosaari 213ce80d713SAntti Palosaari switch (c->delivery_system) { 214ce80d713SAntti Palosaari case SYS_DVBS: 215478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xf9, 0x04); 216ce80d713SAntti Palosaari if (ret) 217ce80d713SAntti Palosaari goto err; 218ce80d713SAntti Palosaari 219478932b1SAntti Palosaari ret = regmap_read(dev->regmap, 0xf8, &utmp); 220ce80d713SAntti Palosaari if (ret) 221ce80d713SAntti Palosaari goto err; 222ce80d713SAntti Palosaari 223ce80d713SAntti Palosaari /* measurement ready? */ 224478932b1SAntti Palosaari if (!(utmp & 0x10)) { 225478932b1SAntti Palosaari ret = regmap_bulk_read(dev->regmap, 0xf6, buf, 2); 226ce80d713SAntti Palosaari if (ret) 227ce80d713SAntti Palosaari goto err; 228ce80d713SAntti Palosaari 229ce80d713SAntti Palosaari post_bit_error = buf[1] << 8 | buf[0] << 0; 230ce80d713SAntti Palosaari post_bit_count = 0x800000; 2317978b8a1SAntti Palosaari dev->post_bit_error += post_bit_error; 2327978b8a1SAntti Palosaari dev->post_bit_count += post_bit_count; 2337978b8a1SAntti Palosaari dev->dvbv3_ber = post_bit_error; 234ce80d713SAntti Palosaari 235ce80d713SAntti Palosaari /* restart measurement */ 236478932b1SAntti Palosaari utmp |= 0x10; 237478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xf8, utmp); 238ce80d713SAntti Palosaari if (ret) 239ce80d713SAntti Palosaari goto err; 240ce80d713SAntti Palosaari } 241ce80d713SAntti Palosaari break; 242ce80d713SAntti Palosaari case SYS_DVBS2: 243478932b1SAntti Palosaari ret = regmap_bulk_read(dev->regmap, 0xd5, buf, 3); 244ce80d713SAntti Palosaari if (ret) 245ce80d713SAntti Palosaari goto err; 246ce80d713SAntti Palosaari 247ce80d713SAntti Palosaari utmp = buf[2] << 16 | buf[1] << 8 | buf[0] << 0; 248ce80d713SAntti Palosaari 249ce80d713SAntti Palosaari /* enough data? */ 250ce80d713SAntti Palosaari if (utmp > 4000) { 251478932b1SAntti Palosaari ret = regmap_bulk_read(dev->regmap, 0xf7, buf, 2); 252ce80d713SAntti Palosaari if (ret) 253ce80d713SAntti Palosaari goto err; 254ce80d713SAntti Palosaari 255ce80d713SAntti Palosaari post_bit_error = buf[1] << 8 | buf[0] << 0; 256ce80d713SAntti Palosaari post_bit_count = 32 * utmp; /* TODO: FEC */ 2577978b8a1SAntti Palosaari dev->post_bit_error += post_bit_error; 2587978b8a1SAntti Palosaari dev->post_bit_count += post_bit_count; 2597978b8a1SAntti Palosaari dev->dvbv3_ber = post_bit_error; 260ce80d713SAntti Palosaari 261ce80d713SAntti Palosaari /* restart measurement */ 262478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xd1, 0x01); 263ce80d713SAntti Palosaari if (ret) 264ce80d713SAntti Palosaari goto err; 265ce80d713SAntti Palosaari 266478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xf9, 0x01); 267ce80d713SAntti Palosaari if (ret) 268ce80d713SAntti Palosaari goto err; 269ce80d713SAntti Palosaari 270478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xf9, 0x00); 271ce80d713SAntti Palosaari if (ret) 272ce80d713SAntti Palosaari goto err; 273ce80d713SAntti Palosaari 274478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xd1, 0x00); 275ce80d713SAntti Palosaari if (ret) 276ce80d713SAntti Palosaari goto err; 277ce80d713SAntti Palosaari } 278ce80d713SAntti Palosaari break; 279ce80d713SAntti Palosaari default: 2807978b8a1SAntti Palosaari dev_dbg(&client->dev, "invalid delivery_system\n"); 281ce80d713SAntti Palosaari ret = -EINVAL; 282ce80d713SAntti Palosaari goto err; 283ce80d713SAntti Palosaari } 284ce80d713SAntti Palosaari 285ce80d713SAntti Palosaari c->post_bit_error.stat[0].scale = FE_SCALE_COUNTER; 2867978b8a1SAntti Palosaari c->post_bit_error.stat[0].uvalue = dev->post_bit_error; 287ce80d713SAntti Palosaari c->post_bit_count.stat[0].scale = FE_SCALE_COUNTER; 2887978b8a1SAntti Palosaari c->post_bit_count.stat[0].uvalue = dev->post_bit_count; 289ce80d713SAntti Palosaari } else { 290ce80d713SAntti Palosaari c->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; 291ce80d713SAntti Palosaari c->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE; 292ce80d713SAntti Palosaari } 293ce80d713SAntti Palosaari 294395d00d1SAntti Palosaari return 0; 295395d00d1SAntti Palosaari err: 2967978b8a1SAntti Palosaari dev_dbg(&client->dev, "failed=%d\n", ret); 297395d00d1SAntti Palosaari return ret; 298395d00d1SAntti Palosaari } 299395d00d1SAntti Palosaari 300395d00d1SAntti Palosaari static int m88ds3103_set_frontend(struct dvb_frontend *fe) 301395d00d1SAntti Palosaari { 3027978b8a1SAntti Palosaari struct m88ds3103_dev *dev = fe->demodulator_priv; 3037978b8a1SAntti Palosaari struct i2c_client *client = dev->client; 304395d00d1SAntti Palosaari struct dtv_frontend_properties *c = &fe->dtv_property_cache; 30506487deeSAntti Palosaari int ret, len; 306395d00d1SAntti Palosaari const struct m88ds3103_reg_val *init; 307b6851419Snibble.max u8 u8tmp, u8tmp1 = 0, u8tmp2 = 0; /* silence compiler warning */ 308f4df95bcSnibble.max u8 buf[3]; 309334ef18eSAntti Palosaari u16 u16tmp; 310f5d9b88dSAntti Palosaari u32 tuner_frequency_khz, target_mclk; 311395d00d1SAntti Palosaari s32 s32tmp; 31241b9aa00SAntti Palosaari 3137978b8a1SAntti Palosaari dev_dbg(&client->dev, 3147978b8a1SAntti Palosaari "delivery_system=%d modulation=%d frequency=%u symbol_rate=%d inversion=%d pilot=%d rolloff=%d\n", 3157978b8a1SAntti Palosaari c->delivery_system, c->modulation, c->frequency, c->symbol_rate, 316395d00d1SAntti Palosaari c->inversion, c->pilot, c->rolloff); 317395d00d1SAntti Palosaari 3187978b8a1SAntti Palosaari if (!dev->warm) { 319395d00d1SAntti Palosaari ret = -EAGAIN; 320395d00d1SAntti Palosaari goto err; 321395d00d1SAntti Palosaari } 322395d00d1SAntti Palosaari 323f4df95bcSnibble.max /* reset */ 324478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0x07, 0x80); 325f4df95bcSnibble.max if (ret) 326f4df95bcSnibble.max goto err; 327f4df95bcSnibble.max 328478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0x07, 0x00); 329f4df95bcSnibble.max if (ret) 330f4df95bcSnibble.max goto err; 331f4df95bcSnibble.max 332f4df95bcSnibble.max /* Disable demod clock path */ 3337978b8a1SAntti Palosaari if (dev->chip_id == M88RS6000_CHIP_ID) { 334478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0x06, 0xe0); 335f4df95bcSnibble.max if (ret) 336f4df95bcSnibble.max goto err; 337f4df95bcSnibble.max } 338f4df95bcSnibble.max 339395d00d1SAntti Palosaari /* program tuner */ 340395d00d1SAntti Palosaari if (fe->ops.tuner_ops.set_params) { 341395d00d1SAntti Palosaari ret = fe->ops.tuner_ops.set_params(fe); 342395d00d1SAntti Palosaari if (ret) 343395d00d1SAntti Palosaari goto err; 344395d00d1SAntti Palosaari } 345395d00d1SAntti Palosaari 346395d00d1SAntti Palosaari if (fe->ops.tuner_ops.get_frequency) { 347f5d9b88dSAntti Palosaari ret = fe->ops.tuner_ops.get_frequency(fe, &tuner_frequency_khz); 348395d00d1SAntti Palosaari if (ret) 349395d00d1SAntti Palosaari goto err; 3502f9dff3fSAntti Palosaari } else { 3512f9dff3fSAntti Palosaari /* 3522f9dff3fSAntti Palosaari * Use nominal target frequency as tuner driver does not provide 3532f9dff3fSAntti Palosaari * actual frequency used. Carrier offset calculation is not 3542f9dff3fSAntti Palosaari * valid. 3552f9dff3fSAntti Palosaari */ 356f5d9b88dSAntti Palosaari tuner_frequency_khz = c->frequency; 357395d00d1SAntti Palosaari } 358395d00d1SAntti Palosaari 359f4df95bcSnibble.max /* select M88RS6000 demod main mclk and ts mclk from tuner die. */ 3607978b8a1SAntti Palosaari if (dev->chip_id == M88RS6000_CHIP_ID) { 361f4df95bcSnibble.max if (c->symbol_rate > 45010000) 362f5d9b88dSAntti Palosaari dev->mclk = 110250000; 363f4df95bcSnibble.max else 364f5d9b88dSAntti Palosaari dev->mclk = 96000000; 365395d00d1SAntti Palosaari 366f4df95bcSnibble.max if (c->delivery_system == SYS_DVBS) 367f5d9b88dSAntti Palosaari target_mclk = 96000000; 368f4df95bcSnibble.max else 369f5d9b88dSAntti Palosaari target_mclk = 144000000; 370395d00d1SAntti Palosaari 371f4df95bcSnibble.max /* Enable demod clock path */ 372478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0x06, 0x00); 373f4df95bcSnibble.max if (ret) 374f4df95bcSnibble.max goto err; 375f4df95bcSnibble.max usleep_range(10000, 20000); 376f4df95bcSnibble.max } else { 377f4df95bcSnibble.max /* set M88DS3103 mclk and ts mclk. */ 378f5d9b88dSAntti Palosaari dev->mclk = 96000000; 379f4df95bcSnibble.max 3807978b8a1SAntti Palosaari switch (dev->cfg->ts_mode) { 381395d00d1SAntti Palosaari case M88DS3103_TS_SERIAL: 382395d00d1SAntti Palosaari case M88DS3103_TS_SERIAL_D7: 3837978b8a1SAntti Palosaari target_mclk = dev->cfg->ts_clk; 384395d00d1SAntti Palosaari break; 385395d00d1SAntti Palosaari case M88DS3103_TS_PARALLEL: 386395d00d1SAntti Palosaari case M88DS3103_TS_CI: 387b6851419Snibble.max if (c->delivery_system == SYS_DVBS) 388f5d9b88dSAntti Palosaari target_mclk = 96000000; 389b6851419Snibble.max else { 390395d00d1SAntti Palosaari if (c->symbol_rate < 18000000) 391f5d9b88dSAntti Palosaari target_mclk = 96000000; 392395d00d1SAntti Palosaari else if (c->symbol_rate < 28000000) 393f5d9b88dSAntti Palosaari target_mclk = 144000000; 394395d00d1SAntti Palosaari else 395f5d9b88dSAntti Palosaari target_mclk = 192000000; 396b6851419Snibble.max } 397395d00d1SAntti Palosaari break; 398395d00d1SAntti Palosaari default: 3997978b8a1SAntti Palosaari dev_dbg(&client->dev, "invalid ts_mode\n"); 400395d00d1SAntti Palosaari ret = -EINVAL; 401395d00d1SAntti Palosaari goto err; 402395d00d1SAntti Palosaari } 403f4df95bcSnibble.max 404f4df95bcSnibble.max switch (target_mclk) { 405f5d9b88dSAntti Palosaari case 96000000: 406f4df95bcSnibble.max u8tmp1 = 0x02; /* 0b10 */ 407f4df95bcSnibble.max u8tmp2 = 0x01; /* 0b01 */ 408f4df95bcSnibble.max break; 409f5d9b88dSAntti Palosaari case 144000000: 410f4df95bcSnibble.max u8tmp1 = 0x00; /* 0b00 */ 411f4df95bcSnibble.max u8tmp2 = 0x01; /* 0b01 */ 412f4df95bcSnibble.max break; 413f5d9b88dSAntti Palosaari case 192000000: 414f4df95bcSnibble.max u8tmp1 = 0x03; /* 0b11 */ 415f4df95bcSnibble.max u8tmp2 = 0x00; /* 0b00 */ 416f4df95bcSnibble.max break; 417f4df95bcSnibble.max } 41856ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x22, 0xc0, u8tmp1 << 6); 419f4df95bcSnibble.max if (ret) 420f4df95bcSnibble.max goto err; 42156ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x24, 0xc0, u8tmp2 << 6); 422f4df95bcSnibble.max if (ret) 423f4df95bcSnibble.max goto err; 424f4df95bcSnibble.max } 425f4df95bcSnibble.max 426478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xb2, 0x01); 427f4df95bcSnibble.max if (ret) 428f4df95bcSnibble.max goto err; 429f4df95bcSnibble.max 430478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0x00, 0x01); 431f4df95bcSnibble.max if (ret) 432f4df95bcSnibble.max goto err; 433f4df95bcSnibble.max 434f4df95bcSnibble.max switch (c->delivery_system) { 435f4df95bcSnibble.max case SYS_DVBS: 4367978b8a1SAntti Palosaari if (dev->chip_id == M88RS6000_CHIP_ID) { 437f4df95bcSnibble.max len = ARRAY_SIZE(m88rs6000_dvbs_init_reg_vals); 438f4df95bcSnibble.max init = m88rs6000_dvbs_init_reg_vals; 439f4df95bcSnibble.max } else { 440f4df95bcSnibble.max len = ARRAY_SIZE(m88ds3103_dvbs_init_reg_vals); 441f4df95bcSnibble.max init = m88ds3103_dvbs_init_reg_vals; 442f4df95bcSnibble.max } 443f4df95bcSnibble.max break; 444f4df95bcSnibble.max case SYS_DVBS2: 4457978b8a1SAntti Palosaari if (dev->chip_id == M88RS6000_CHIP_ID) { 446f4df95bcSnibble.max len = ARRAY_SIZE(m88rs6000_dvbs2_init_reg_vals); 447f4df95bcSnibble.max init = m88rs6000_dvbs2_init_reg_vals; 448f4df95bcSnibble.max } else { 449f4df95bcSnibble.max len = ARRAY_SIZE(m88ds3103_dvbs2_init_reg_vals); 450f4df95bcSnibble.max init = m88ds3103_dvbs2_init_reg_vals; 451f4df95bcSnibble.max } 452395d00d1SAntti Palosaari break; 453395d00d1SAntti Palosaari default: 4547978b8a1SAntti Palosaari dev_dbg(&client->dev, "invalid delivery_system\n"); 455395d00d1SAntti Palosaari ret = -EINVAL; 456395d00d1SAntti Palosaari goto err; 457395d00d1SAntti Palosaari } 458395d00d1SAntti Palosaari 459395d00d1SAntti Palosaari /* program init table */ 4607978b8a1SAntti Palosaari if (c->delivery_system != dev->delivery_system) { 4617978b8a1SAntti Palosaari ret = m88ds3103_wr_reg_val_tab(dev, init, len); 462395d00d1SAntti Palosaari if (ret) 463395d00d1SAntti Palosaari goto err; 464395d00d1SAntti Palosaari } 465395d00d1SAntti Palosaari 4667978b8a1SAntti Palosaari if (dev->chip_id == M88RS6000_CHIP_ID) { 467f5d9b88dSAntti Palosaari if (c->delivery_system == SYS_DVBS2 && 468f5d9b88dSAntti Palosaari c->symbol_rate <= 5000000) { 469478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xc0, 0x04); 470f4df95bcSnibble.max if (ret) 471f4df95bcSnibble.max goto err; 472f4df95bcSnibble.max buf[0] = 0x09; 473f4df95bcSnibble.max buf[1] = 0x22; 474f4df95bcSnibble.max buf[2] = 0x88; 475478932b1SAntti Palosaari ret = regmap_bulk_write(dev->regmap, 0x8a, buf, 3); 476f4df95bcSnibble.max if (ret) 477f4df95bcSnibble.max goto err; 478f4df95bcSnibble.max } 47956ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x9d, 0x08, 0x08); 480f4df95bcSnibble.max if (ret) 481f4df95bcSnibble.max goto err; 482478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xf1, 0x01); 483f4df95bcSnibble.max if (ret) 484f4df95bcSnibble.max goto err; 48556ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x30, 0x80, 0x80); 486f4df95bcSnibble.max if (ret) 487f4df95bcSnibble.max goto err; 488f4df95bcSnibble.max } 489f4df95bcSnibble.max 4907978b8a1SAntti Palosaari switch (dev->cfg->ts_mode) { 491395d00d1SAntti Palosaari case M88DS3103_TS_SERIAL: 492395d00d1SAntti Palosaari u8tmp1 = 0x00; 49379d09330Snibble.max u8tmp = 0x06; 494395d00d1SAntti Palosaari break; 495395d00d1SAntti Palosaari case M88DS3103_TS_SERIAL_D7: 496395d00d1SAntti Palosaari u8tmp1 = 0x20; 49779d09330Snibble.max u8tmp = 0x06; 498395d00d1SAntti Palosaari break; 499395d00d1SAntti Palosaari case M88DS3103_TS_PARALLEL: 50079d09330Snibble.max u8tmp = 0x02; 501395d00d1SAntti Palosaari break; 502395d00d1SAntti Palosaari case M88DS3103_TS_CI: 50379d09330Snibble.max u8tmp = 0x03; 504395d00d1SAntti Palosaari break; 505395d00d1SAntti Palosaari default: 5067978b8a1SAntti Palosaari dev_dbg(&client->dev, "invalid ts_mode\n"); 507395d00d1SAntti Palosaari ret = -EINVAL; 508395d00d1SAntti Palosaari goto err; 509395d00d1SAntti Palosaari } 510395d00d1SAntti Palosaari 5117978b8a1SAntti Palosaari if (dev->cfg->ts_clk_pol) 51279d09330Snibble.max u8tmp |= 0x40; 51379d09330Snibble.max 514395d00d1SAntti Palosaari /* TS mode */ 515478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xfd, u8tmp); 516395d00d1SAntti Palosaari if (ret) 517395d00d1SAntti Palosaari goto err; 518395d00d1SAntti Palosaari 5197978b8a1SAntti Palosaari switch (dev->cfg->ts_mode) { 520395d00d1SAntti Palosaari case M88DS3103_TS_SERIAL: 521395d00d1SAntti Palosaari case M88DS3103_TS_SERIAL_D7: 52256ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x29, 0x20, u8tmp1); 523395d00d1SAntti Palosaari if (ret) 524395d00d1SAntti Palosaari goto err; 525334ef18eSAntti Palosaari u16tmp = 0; 526334ef18eSAntti Palosaari u8tmp1 = 0x3f; 527334ef18eSAntti Palosaari u8tmp2 = 0x3f; 528b6851419Snibble.max break; 529b6851419Snibble.max default: 530334ef18eSAntti Palosaari u16tmp = DIV_ROUND_UP(target_mclk, dev->cfg->ts_clk); 531334ef18eSAntti Palosaari u8tmp1 = u16tmp / 2 - 1; 532334ef18eSAntti Palosaari u8tmp2 = DIV_ROUND_UP(u16tmp, 2) - 1; 533395d00d1SAntti Palosaari } 534395d00d1SAntti Palosaari 535f5d9b88dSAntti Palosaari dev_dbg(&client->dev, "target_mclk=%u ts_clk=%u ts_clk_divide_ratio=%u\n", 536334ef18eSAntti Palosaari target_mclk, dev->cfg->ts_clk, u16tmp); 537395d00d1SAntti Palosaari 538395d00d1SAntti Palosaari /* u8tmp1[5:2] => fe[3:0], u8tmp1[1:0] => ea[7:6] */ 539395d00d1SAntti Palosaari /* u8tmp2[5:0] => ea[5:0] */ 540334ef18eSAntti Palosaari u8tmp = (u8tmp1 >> 2) & 0x0f; 541334ef18eSAntti Palosaari ret = regmap_update_bits(dev->regmap, 0xfe, 0x0f, u8tmp); 542395d00d1SAntti Palosaari if (ret) 543395d00d1SAntti Palosaari goto err; 544395d00d1SAntti Palosaari u8tmp = ((u8tmp1 & 0x03) << 6) | u8tmp2 >> 0; 545478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xea, u8tmp); 546395d00d1SAntti Palosaari if (ret) 547395d00d1SAntti Palosaari goto err; 548395d00d1SAntti Palosaari 549395d00d1SAntti Palosaari if (c->symbol_rate <= 3000000) 550395d00d1SAntti Palosaari u8tmp = 0x20; 551395d00d1SAntti Palosaari else if (c->symbol_rate <= 10000000) 552395d00d1SAntti Palosaari u8tmp = 0x10; 553395d00d1SAntti Palosaari else 554395d00d1SAntti Palosaari u8tmp = 0x06; 555395d00d1SAntti Palosaari 556478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xc3, 0x08); 557395d00d1SAntti Palosaari if (ret) 558395d00d1SAntti Palosaari goto err; 559395d00d1SAntti Palosaari 560478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xc8, u8tmp); 561395d00d1SAntti Palosaari if (ret) 562395d00d1SAntti Palosaari goto err; 563395d00d1SAntti Palosaari 564478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xc4, 0x08); 565395d00d1SAntti Palosaari if (ret) 566395d00d1SAntti Palosaari goto err; 567395d00d1SAntti Palosaari 568478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xc7, 0x00); 569395d00d1SAntti Palosaari if (ret) 570395d00d1SAntti Palosaari goto err; 571395d00d1SAntti Palosaari 572f5d9b88dSAntti Palosaari u16tmp = DIV_ROUND_CLOSEST_ULL((u64)c->symbol_rate * 0x10000, dev->mclk); 573395d00d1SAntti Palosaari buf[0] = (u16tmp >> 0) & 0xff; 574395d00d1SAntti Palosaari buf[1] = (u16tmp >> 8) & 0xff; 575478932b1SAntti Palosaari ret = regmap_bulk_write(dev->regmap, 0x61, buf, 2); 576395d00d1SAntti Palosaari if (ret) 577395d00d1SAntti Palosaari goto err; 578395d00d1SAntti Palosaari 57956ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x4d, 0x02, dev->cfg->spec_inv << 1); 580395d00d1SAntti Palosaari if (ret) 581395d00d1SAntti Palosaari goto err; 582395d00d1SAntti Palosaari 58356ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x30, 0x10, dev->cfg->agc_inv << 4); 584395d00d1SAntti Palosaari if (ret) 585395d00d1SAntti Palosaari goto err; 586395d00d1SAntti Palosaari 587478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0x33, dev->cfg->agc); 588395d00d1SAntti Palosaari if (ret) 589395d00d1SAntti Palosaari goto err; 590395d00d1SAntti Palosaari 5917978b8a1SAntti Palosaari dev_dbg(&client->dev, "carrier offset=%d\n", 592f5d9b88dSAntti Palosaari (tuner_frequency_khz - c->frequency)); 593395d00d1SAntti Palosaari 594f5d9b88dSAntti Palosaari /* Use 32-bit calc as there is no s64 version of DIV_ROUND_CLOSEST() */ 595f5d9b88dSAntti Palosaari s32tmp = 0x10000 * (tuner_frequency_khz - c->frequency); 596f5d9b88dSAntti Palosaari s32tmp = DIV_ROUND_CLOSEST(s32tmp, dev->mclk / 1000); 597395d00d1SAntti Palosaari buf[0] = (s32tmp >> 0) & 0xff; 598395d00d1SAntti Palosaari buf[1] = (s32tmp >> 8) & 0xff; 599478932b1SAntti Palosaari ret = regmap_bulk_write(dev->regmap, 0x5e, buf, 2); 600395d00d1SAntti Palosaari if (ret) 601395d00d1SAntti Palosaari goto err; 602395d00d1SAntti Palosaari 603478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0x00, 0x00); 604395d00d1SAntti Palosaari if (ret) 605395d00d1SAntti Palosaari goto err; 606395d00d1SAntti Palosaari 607478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xb2, 0x00); 608395d00d1SAntti Palosaari if (ret) 609395d00d1SAntti Palosaari goto err; 610395d00d1SAntti Palosaari 6117978b8a1SAntti Palosaari dev->delivery_system = c->delivery_system; 612395d00d1SAntti Palosaari 613395d00d1SAntti Palosaari return 0; 614395d00d1SAntti Palosaari err: 6157978b8a1SAntti Palosaari dev_dbg(&client->dev, "failed=%d\n", ret); 616395d00d1SAntti Palosaari return ret; 617395d00d1SAntti Palosaari } 618395d00d1SAntti Palosaari 619395d00d1SAntti Palosaari static int m88ds3103_init(struct dvb_frontend *fe) 620395d00d1SAntti Palosaari { 6217978b8a1SAntti Palosaari struct m88ds3103_dev *dev = fe->demodulator_priv; 6227978b8a1SAntti Palosaari struct i2c_client *client = dev->client; 623c1daf651SAntti Palosaari struct dtv_frontend_properties *c = &fe->dtv_property_cache; 624*60701d5fSAntti Palosaari int ret, len, rem; 625478932b1SAntti Palosaari unsigned int utmp; 626*60701d5fSAntti Palosaari const struct firmware *firmware; 627*60701d5fSAntti Palosaari const char *name; 62841b9aa00SAntti Palosaari 6297978b8a1SAntti Palosaari dev_dbg(&client->dev, "\n"); 630395d00d1SAntti Palosaari 631395d00d1SAntti Palosaari /* set cold state by default */ 6327978b8a1SAntti Palosaari dev->warm = false; 633395d00d1SAntti Palosaari 634395d00d1SAntti Palosaari /* wake up device from sleep */ 63556ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x08, 0x01, 0x01); 636395d00d1SAntti Palosaari if (ret) 637395d00d1SAntti Palosaari goto err; 63856ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x04, 0x01, 0x00); 639395d00d1SAntti Palosaari if (ret) 640395d00d1SAntti Palosaari goto err; 64156ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x23, 0x10, 0x00); 642395d00d1SAntti Palosaari if (ret) 643395d00d1SAntti Palosaari goto err; 644395d00d1SAntti Palosaari 645395d00d1SAntti Palosaari /* firmware status */ 646478932b1SAntti Palosaari ret = regmap_read(dev->regmap, 0xb9, &utmp); 647395d00d1SAntti Palosaari if (ret) 648395d00d1SAntti Palosaari goto err; 649395d00d1SAntti Palosaari 650478932b1SAntti Palosaari dev_dbg(&client->dev, "firmware=%02x\n", utmp); 651395d00d1SAntti Palosaari 652478932b1SAntti Palosaari if (utmp) 653*60701d5fSAntti Palosaari goto warm; 654395d00d1SAntti Palosaari 655f4df95bcSnibble.max /* global reset, global diseqc reset, golbal fec reset */ 656478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0x07, 0xe0); 657f4df95bcSnibble.max if (ret) 658f4df95bcSnibble.max goto err; 659478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0x07, 0x00); 660f4df95bcSnibble.max if (ret) 661f4df95bcSnibble.max goto err; 662f4df95bcSnibble.max 663395d00d1SAntti Palosaari /* cold state - try to download firmware */ 6647978b8a1SAntti Palosaari dev_info(&client->dev, "found a '%s' in cold state\n", 6657978b8a1SAntti Palosaari m88ds3103_ops.info.name); 666395d00d1SAntti Palosaari 6677978b8a1SAntti Palosaari if (dev->chip_id == M88RS6000_CHIP_ID) 668*60701d5fSAntti Palosaari name = M88RS6000_FIRMWARE; 669f4df95bcSnibble.max else 670*60701d5fSAntti Palosaari name = M88DS3103_FIRMWARE; 671395d00d1SAntti Palosaari /* request the firmware, this will block and timeout */ 672*60701d5fSAntti Palosaari ret = request_firmware(&firmware, name, &client->dev); 673395d00d1SAntti Palosaari if (ret) { 674*60701d5fSAntti Palosaari dev_err(&client->dev, "firmware file '%s' not found\n", name); 675395d00d1SAntti Palosaari goto err; 676395d00d1SAntti Palosaari } 677395d00d1SAntti Palosaari 678*60701d5fSAntti Palosaari dev_info(&client->dev, "downloading firmware from file '%s'\n", name); 679395d00d1SAntti Palosaari 680478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xb2, 0x01); 681395d00d1SAntti Palosaari if (ret) 682*60701d5fSAntti Palosaari goto err_release_firmware; 683395d00d1SAntti Palosaari 684*60701d5fSAntti Palosaari for (rem = firmware->size; rem > 0; rem -= (dev->cfg->i2c_wr_max - 1)) { 685*60701d5fSAntti Palosaari len = min(dev->cfg->i2c_wr_max - 1, rem); 686478932b1SAntti Palosaari ret = regmap_bulk_write(dev->regmap, 0xb0, 687*60701d5fSAntti Palosaari &firmware->data[firmware->size - rem], 688*60701d5fSAntti Palosaari len); 689395d00d1SAntti Palosaari if (ret) { 690*60701d5fSAntti Palosaari dev_err(&client->dev, "firmware download failed %d\n", 6917978b8a1SAntti Palosaari ret); 692*60701d5fSAntti Palosaari goto err_release_firmware; 693395d00d1SAntti Palosaari } 694395d00d1SAntti Palosaari } 695395d00d1SAntti Palosaari 696478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xb2, 0x00); 697395d00d1SAntti Palosaari if (ret) 698*60701d5fSAntti Palosaari goto err_release_firmware; 699395d00d1SAntti Palosaari 700*60701d5fSAntti Palosaari release_firmware(firmware); 701395d00d1SAntti Palosaari 702478932b1SAntti Palosaari ret = regmap_read(dev->regmap, 0xb9, &utmp); 703395d00d1SAntti Palosaari if (ret) 704395d00d1SAntti Palosaari goto err; 705395d00d1SAntti Palosaari 706478932b1SAntti Palosaari if (!utmp) { 707*60701d5fSAntti Palosaari ret = -EINVAL; 7087978b8a1SAntti Palosaari dev_info(&client->dev, "firmware did not run\n"); 709395d00d1SAntti Palosaari goto err; 710395d00d1SAntti Palosaari } 711395d00d1SAntti Palosaari 7127978b8a1SAntti Palosaari dev_info(&client->dev, "found a '%s' in warm state\n", 7137978b8a1SAntti Palosaari m88ds3103_ops.info.name); 7147978b8a1SAntti Palosaari dev_info(&client->dev, "firmware version: %X.%X\n", 715478932b1SAntti Palosaari (utmp >> 4) & 0xf, (utmp >> 0 & 0xf)); 716395d00d1SAntti Palosaari 717*60701d5fSAntti Palosaari warm: 718395d00d1SAntti Palosaari /* warm state */ 7197978b8a1SAntti Palosaari dev->warm = true; 7207978b8a1SAntti Palosaari 721c1daf651SAntti Palosaari /* init stats here in order signal app which stats are supported */ 722c1daf651SAntti Palosaari c->cnr.len = 1; 723c1daf651SAntti Palosaari c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; 724ce80d713SAntti Palosaari c->post_bit_error.len = 1; 725ce80d713SAntti Palosaari c->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; 726ce80d713SAntti Palosaari c->post_bit_count.len = 1; 727ce80d713SAntti Palosaari c->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE; 728395d00d1SAntti Palosaari 7297978b8a1SAntti Palosaari return 0; 730*60701d5fSAntti Palosaari err_release_firmware: 731*60701d5fSAntti Palosaari release_firmware(firmware); 7325ed0cf88SMarkus Elfring err: 7337978b8a1SAntti Palosaari dev_dbg(&client->dev, "failed=%d\n", ret); 734395d00d1SAntti Palosaari return ret; 735395d00d1SAntti Palosaari } 736395d00d1SAntti Palosaari 737395d00d1SAntti Palosaari static int m88ds3103_sleep(struct dvb_frontend *fe) 738395d00d1SAntti Palosaari { 7397978b8a1SAntti Palosaari struct m88ds3103_dev *dev = fe->demodulator_priv; 7407978b8a1SAntti Palosaari struct i2c_client *client = dev->client; 741395d00d1SAntti Palosaari int ret; 742478932b1SAntti Palosaari unsigned int utmp; 74341b9aa00SAntti Palosaari 7447978b8a1SAntti Palosaari dev_dbg(&client->dev, "\n"); 745395d00d1SAntti Palosaari 7467978b8a1SAntti Palosaari dev->fe_status = 0; 7477978b8a1SAntti Palosaari dev->delivery_system = SYS_UNDEFINED; 748395d00d1SAntti Palosaari 749395d00d1SAntti Palosaari /* TS Hi-Z */ 7507978b8a1SAntti Palosaari if (dev->chip_id == M88RS6000_CHIP_ID) 751478932b1SAntti Palosaari utmp = 0x29; 752f4df95bcSnibble.max else 753478932b1SAntti Palosaari utmp = 0x27; 75456ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, utmp, 0x01, 0x00); 755395d00d1SAntti Palosaari if (ret) 756395d00d1SAntti Palosaari goto err; 757395d00d1SAntti Palosaari 758395d00d1SAntti Palosaari /* sleep */ 75956ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x08, 0x01, 0x00); 760395d00d1SAntti Palosaari if (ret) 761395d00d1SAntti Palosaari goto err; 76256ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x04, 0x01, 0x01); 763395d00d1SAntti Palosaari if (ret) 764395d00d1SAntti Palosaari goto err; 76556ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x23, 0x10, 0x10); 766395d00d1SAntti Palosaari if (ret) 767395d00d1SAntti Palosaari goto err; 768395d00d1SAntti Palosaari 769395d00d1SAntti Palosaari return 0; 770395d00d1SAntti Palosaari err: 7717978b8a1SAntti Palosaari dev_dbg(&client->dev, "failed=%d\n", ret); 772395d00d1SAntti Palosaari return ret; 773395d00d1SAntti Palosaari } 774395d00d1SAntti Palosaari 7757e3e68bcSMauro Carvalho Chehab static int m88ds3103_get_frontend(struct dvb_frontend *fe, 7767e3e68bcSMauro Carvalho Chehab struct dtv_frontend_properties *c) 777395d00d1SAntti Palosaari { 7787978b8a1SAntti Palosaari struct m88ds3103_dev *dev = fe->demodulator_priv; 7797978b8a1SAntti Palosaari struct i2c_client *client = dev->client; 780395d00d1SAntti Palosaari int ret; 781395d00d1SAntti Palosaari u8 buf[3]; 78241b9aa00SAntti Palosaari 7837978b8a1SAntti Palosaari dev_dbg(&client->dev, "\n"); 784395d00d1SAntti Palosaari 7857978b8a1SAntti Palosaari if (!dev->warm || !(dev->fe_status & FE_HAS_LOCK)) { 7869240c384SAntti Palosaari ret = 0; 787395d00d1SAntti Palosaari goto err; 788395d00d1SAntti Palosaari } 789395d00d1SAntti Palosaari 790395d00d1SAntti Palosaari switch (c->delivery_system) { 791395d00d1SAntti Palosaari case SYS_DVBS: 792478932b1SAntti Palosaari ret = regmap_bulk_read(dev->regmap, 0xe0, &buf[0], 1); 793395d00d1SAntti Palosaari if (ret) 794395d00d1SAntti Palosaari goto err; 795395d00d1SAntti Palosaari 796478932b1SAntti Palosaari ret = regmap_bulk_read(dev->regmap, 0xe6, &buf[1], 1); 797395d00d1SAntti Palosaari if (ret) 798395d00d1SAntti Palosaari goto err; 799395d00d1SAntti Palosaari 800395d00d1SAntti Palosaari switch ((buf[0] >> 2) & 0x01) { 801395d00d1SAntti Palosaari case 0: 802395d00d1SAntti Palosaari c->inversion = INVERSION_OFF; 803395d00d1SAntti Palosaari break; 804395d00d1SAntti Palosaari case 1: 805395d00d1SAntti Palosaari c->inversion = INVERSION_ON; 806395d00d1SAntti Palosaari break; 807395d00d1SAntti Palosaari } 808395d00d1SAntti Palosaari 809395d00d1SAntti Palosaari switch ((buf[1] >> 5) & 0x07) { 810395d00d1SAntti Palosaari case 0: 811395d00d1SAntti Palosaari c->fec_inner = FEC_7_8; 812395d00d1SAntti Palosaari break; 813395d00d1SAntti Palosaari case 1: 814395d00d1SAntti Palosaari c->fec_inner = FEC_5_6; 815395d00d1SAntti Palosaari break; 816395d00d1SAntti Palosaari case 2: 817395d00d1SAntti Palosaari c->fec_inner = FEC_3_4; 818395d00d1SAntti Palosaari break; 819395d00d1SAntti Palosaari case 3: 820395d00d1SAntti Palosaari c->fec_inner = FEC_2_3; 821395d00d1SAntti Palosaari break; 822395d00d1SAntti Palosaari case 4: 823395d00d1SAntti Palosaari c->fec_inner = FEC_1_2; 824395d00d1SAntti Palosaari break; 825395d00d1SAntti Palosaari default: 8267978b8a1SAntti Palosaari dev_dbg(&client->dev, "invalid fec_inner\n"); 827395d00d1SAntti Palosaari } 828395d00d1SAntti Palosaari 829395d00d1SAntti Palosaari c->modulation = QPSK; 830395d00d1SAntti Palosaari 831395d00d1SAntti Palosaari break; 832395d00d1SAntti Palosaari case SYS_DVBS2: 833478932b1SAntti Palosaari ret = regmap_bulk_read(dev->regmap, 0x7e, &buf[0], 1); 834395d00d1SAntti Palosaari if (ret) 835395d00d1SAntti Palosaari goto err; 836395d00d1SAntti Palosaari 837478932b1SAntti Palosaari ret = regmap_bulk_read(dev->regmap, 0x89, &buf[1], 1); 838395d00d1SAntti Palosaari if (ret) 839395d00d1SAntti Palosaari goto err; 840395d00d1SAntti Palosaari 841478932b1SAntti Palosaari ret = regmap_bulk_read(dev->regmap, 0xf2, &buf[2], 1); 842395d00d1SAntti Palosaari if (ret) 843395d00d1SAntti Palosaari goto err; 844395d00d1SAntti Palosaari 845395d00d1SAntti Palosaari switch ((buf[0] >> 0) & 0x0f) { 846395d00d1SAntti Palosaari case 2: 847395d00d1SAntti Palosaari c->fec_inner = FEC_2_5; 848395d00d1SAntti Palosaari break; 849395d00d1SAntti Palosaari case 3: 850395d00d1SAntti Palosaari c->fec_inner = FEC_1_2; 851395d00d1SAntti Palosaari break; 852395d00d1SAntti Palosaari case 4: 853395d00d1SAntti Palosaari c->fec_inner = FEC_3_5; 854395d00d1SAntti Palosaari break; 855395d00d1SAntti Palosaari case 5: 856395d00d1SAntti Palosaari c->fec_inner = FEC_2_3; 857395d00d1SAntti Palosaari break; 858395d00d1SAntti Palosaari case 6: 859395d00d1SAntti Palosaari c->fec_inner = FEC_3_4; 860395d00d1SAntti Palosaari break; 861395d00d1SAntti Palosaari case 7: 862395d00d1SAntti Palosaari c->fec_inner = FEC_4_5; 863395d00d1SAntti Palosaari break; 864395d00d1SAntti Palosaari case 8: 865395d00d1SAntti Palosaari c->fec_inner = FEC_5_6; 866395d00d1SAntti Palosaari break; 867395d00d1SAntti Palosaari case 9: 868395d00d1SAntti Palosaari c->fec_inner = FEC_8_9; 869395d00d1SAntti Palosaari break; 870395d00d1SAntti Palosaari case 10: 871395d00d1SAntti Palosaari c->fec_inner = FEC_9_10; 872395d00d1SAntti Palosaari break; 873395d00d1SAntti Palosaari default: 8747978b8a1SAntti Palosaari dev_dbg(&client->dev, "invalid fec_inner\n"); 875395d00d1SAntti Palosaari } 876395d00d1SAntti Palosaari 877395d00d1SAntti Palosaari switch ((buf[0] >> 5) & 0x01) { 878395d00d1SAntti Palosaari case 0: 879395d00d1SAntti Palosaari c->pilot = PILOT_OFF; 880395d00d1SAntti Palosaari break; 881395d00d1SAntti Palosaari case 1: 882395d00d1SAntti Palosaari c->pilot = PILOT_ON; 883395d00d1SAntti Palosaari break; 884395d00d1SAntti Palosaari } 885395d00d1SAntti Palosaari 886395d00d1SAntti Palosaari switch ((buf[0] >> 6) & 0x07) { 887395d00d1SAntti Palosaari case 0: 888395d00d1SAntti Palosaari c->modulation = QPSK; 889395d00d1SAntti Palosaari break; 890395d00d1SAntti Palosaari case 1: 891395d00d1SAntti Palosaari c->modulation = PSK_8; 892395d00d1SAntti Palosaari break; 893395d00d1SAntti Palosaari case 2: 894395d00d1SAntti Palosaari c->modulation = APSK_16; 895395d00d1SAntti Palosaari break; 896395d00d1SAntti Palosaari case 3: 897395d00d1SAntti Palosaari c->modulation = APSK_32; 898395d00d1SAntti Palosaari break; 899395d00d1SAntti Palosaari default: 9007978b8a1SAntti Palosaari dev_dbg(&client->dev, "invalid modulation\n"); 901395d00d1SAntti Palosaari } 902395d00d1SAntti Palosaari 903395d00d1SAntti Palosaari switch ((buf[1] >> 7) & 0x01) { 904395d00d1SAntti Palosaari case 0: 905395d00d1SAntti Palosaari c->inversion = INVERSION_OFF; 906395d00d1SAntti Palosaari break; 907395d00d1SAntti Palosaari case 1: 908395d00d1SAntti Palosaari c->inversion = INVERSION_ON; 909395d00d1SAntti Palosaari break; 910395d00d1SAntti Palosaari } 911395d00d1SAntti Palosaari 912395d00d1SAntti Palosaari switch ((buf[2] >> 0) & 0x03) { 913395d00d1SAntti Palosaari case 0: 914395d00d1SAntti Palosaari c->rolloff = ROLLOFF_35; 915395d00d1SAntti Palosaari break; 916395d00d1SAntti Palosaari case 1: 917395d00d1SAntti Palosaari c->rolloff = ROLLOFF_25; 918395d00d1SAntti Palosaari break; 919395d00d1SAntti Palosaari case 2: 920395d00d1SAntti Palosaari c->rolloff = ROLLOFF_20; 921395d00d1SAntti Palosaari break; 922395d00d1SAntti Palosaari default: 9237978b8a1SAntti Palosaari dev_dbg(&client->dev, "invalid rolloff\n"); 924395d00d1SAntti Palosaari } 925395d00d1SAntti Palosaari break; 926395d00d1SAntti Palosaari default: 9277978b8a1SAntti Palosaari dev_dbg(&client->dev, "invalid delivery_system\n"); 928395d00d1SAntti Palosaari ret = -EINVAL; 929395d00d1SAntti Palosaari goto err; 930395d00d1SAntti Palosaari } 931395d00d1SAntti Palosaari 932478932b1SAntti Palosaari ret = regmap_bulk_read(dev->regmap, 0x6d, buf, 2); 933395d00d1SAntti Palosaari if (ret) 934395d00d1SAntti Palosaari goto err; 935395d00d1SAntti Palosaari 936f5d9b88dSAntti Palosaari c->symbol_rate = DIV_ROUND_CLOSEST_ULL((u64)(buf[1] << 8 | buf[0] << 0) * dev->mclk, 0x10000); 937395d00d1SAntti Palosaari 938395d00d1SAntti Palosaari return 0; 939395d00d1SAntti Palosaari err: 9407978b8a1SAntti Palosaari dev_dbg(&client->dev, "failed=%d\n", ret); 941395d00d1SAntti Palosaari return ret; 942395d00d1SAntti Palosaari } 943395d00d1SAntti Palosaari 944395d00d1SAntti Palosaari static int m88ds3103_read_snr(struct dvb_frontend *fe, u16 *snr) 945395d00d1SAntti Palosaari { 946395d00d1SAntti Palosaari struct dtv_frontend_properties *c = &fe->dtv_property_cache; 94741b9aa00SAntti Palosaari 948c1daf651SAntti Palosaari if (c->cnr.stat[0].scale == FE_SCALE_DECIBEL) 949c1daf651SAntti Palosaari *snr = div_s64(c->cnr.stat[0].svalue, 100); 950395d00d1SAntti Palosaari else 951395d00d1SAntti Palosaari *snr = 0; 952395d00d1SAntti Palosaari 953395d00d1SAntti Palosaari return 0; 954395d00d1SAntti Palosaari } 955395d00d1SAntti Palosaari 9564423a2baSAntti Palosaari static int m88ds3103_read_ber(struct dvb_frontend *fe, u32 *ber) 9574423a2baSAntti Palosaari { 9587978b8a1SAntti Palosaari struct m88ds3103_dev *dev = fe->demodulator_priv; 95941b9aa00SAntti Palosaari 9607978b8a1SAntti Palosaari *ber = dev->dvbv3_ber; 9614423a2baSAntti Palosaari 9624423a2baSAntti Palosaari return 0; 9634423a2baSAntti Palosaari } 964395d00d1SAntti Palosaari 965395d00d1SAntti Palosaari static int m88ds3103_set_tone(struct dvb_frontend *fe, 9660df289a2SMauro Carvalho Chehab enum fe_sec_tone_mode fe_sec_tone_mode) 967395d00d1SAntti Palosaari { 9687978b8a1SAntti Palosaari struct m88ds3103_dev *dev = fe->demodulator_priv; 9697978b8a1SAntti Palosaari struct i2c_client *client = dev->client; 970395d00d1SAntti Palosaari int ret; 971478932b1SAntti Palosaari unsigned int utmp, tone, reg_a1_mask; 97241b9aa00SAntti Palosaari 9737978b8a1SAntti Palosaari dev_dbg(&client->dev, "fe_sec_tone_mode=%d\n", fe_sec_tone_mode); 974395d00d1SAntti Palosaari 9757978b8a1SAntti Palosaari if (!dev->warm) { 976395d00d1SAntti Palosaari ret = -EAGAIN; 977395d00d1SAntti Palosaari goto err; 978395d00d1SAntti Palosaari } 979395d00d1SAntti Palosaari 980395d00d1SAntti Palosaari switch (fe_sec_tone_mode) { 981395d00d1SAntti Palosaari case SEC_TONE_ON: 982395d00d1SAntti Palosaari tone = 0; 983418a97cbSAntti Palosaari reg_a1_mask = 0x47; 984395d00d1SAntti Palosaari break; 985395d00d1SAntti Palosaari case SEC_TONE_OFF: 986395d00d1SAntti Palosaari tone = 1; 987395d00d1SAntti Palosaari reg_a1_mask = 0x00; 988395d00d1SAntti Palosaari break; 989395d00d1SAntti Palosaari default: 9907978b8a1SAntti Palosaari dev_dbg(&client->dev, "invalid fe_sec_tone_mode\n"); 991395d00d1SAntti Palosaari ret = -EINVAL; 992395d00d1SAntti Palosaari goto err; 993395d00d1SAntti Palosaari } 994395d00d1SAntti Palosaari 995478932b1SAntti Palosaari utmp = tone << 7 | dev->cfg->envelope_mode << 5; 99656ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0xa2, 0xe0, utmp); 997395d00d1SAntti Palosaari if (ret) 998395d00d1SAntti Palosaari goto err; 999395d00d1SAntti Palosaari 1000478932b1SAntti Palosaari utmp = 1 << 2; 100156ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0xa1, reg_a1_mask, utmp); 1002395d00d1SAntti Palosaari if (ret) 1003395d00d1SAntti Palosaari goto err; 1004395d00d1SAntti Palosaari 1005395d00d1SAntti Palosaari return 0; 1006395d00d1SAntti Palosaari err: 10077978b8a1SAntti Palosaari dev_dbg(&client->dev, "failed=%d\n", ret); 1008395d00d1SAntti Palosaari return ret; 1009395d00d1SAntti Palosaari } 1010395d00d1SAntti Palosaari 101179d09330Snibble.max static int m88ds3103_set_voltage(struct dvb_frontend *fe, 10120df289a2SMauro Carvalho Chehab enum fe_sec_voltage fe_sec_voltage) 101379d09330Snibble.max { 10147978b8a1SAntti Palosaari struct m88ds3103_dev *dev = fe->demodulator_priv; 10157978b8a1SAntti Palosaari struct i2c_client *client = dev->client; 1016d28677ffSAntti Palosaari int ret; 1017478932b1SAntti Palosaari unsigned int utmp; 1018d28677ffSAntti Palosaari bool voltage_sel, voltage_dis; 101979d09330Snibble.max 10207978b8a1SAntti Palosaari dev_dbg(&client->dev, "fe_sec_voltage=%d\n", fe_sec_voltage); 102179d09330Snibble.max 10227978b8a1SAntti Palosaari if (!dev->warm) { 1023d28677ffSAntti Palosaari ret = -EAGAIN; 1024d28677ffSAntti Palosaari goto err; 1025d28677ffSAntti Palosaari } 102679d09330Snibble.max 1027d28677ffSAntti Palosaari switch (fe_sec_voltage) { 102879d09330Snibble.max case SEC_VOLTAGE_18: 1029afbd6eb4SMauro Carvalho Chehab voltage_sel = true; 1030afbd6eb4SMauro Carvalho Chehab voltage_dis = false; 103179d09330Snibble.max break; 103279d09330Snibble.max case SEC_VOLTAGE_13: 1033afbd6eb4SMauro Carvalho Chehab voltage_sel = false; 1034afbd6eb4SMauro Carvalho Chehab voltage_dis = false; 103579d09330Snibble.max break; 103679d09330Snibble.max case SEC_VOLTAGE_OFF: 1037afbd6eb4SMauro Carvalho Chehab voltage_sel = false; 1038afbd6eb4SMauro Carvalho Chehab voltage_dis = true; 103979d09330Snibble.max break; 1040d28677ffSAntti Palosaari default: 10417978b8a1SAntti Palosaari dev_dbg(&client->dev, "invalid fe_sec_voltage\n"); 1042d28677ffSAntti Palosaari ret = -EINVAL; 1043d28677ffSAntti Palosaari goto err; 104479d09330Snibble.max } 1045d28677ffSAntti Palosaari 1046d28677ffSAntti Palosaari /* output pin polarity */ 10477978b8a1SAntti Palosaari voltage_sel ^= dev->cfg->lnb_hv_pol; 10487978b8a1SAntti Palosaari voltage_dis ^= dev->cfg->lnb_en_pol; 1049d28677ffSAntti Palosaari 1050478932b1SAntti Palosaari utmp = voltage_dis << 1 | voltage_sel << 0; 105156ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0xa2, 0x03, utmp); 1052d28677ffSAntti Palosaari if (ret) 1053d28677ffSAntti Palosaari goto err; 105479d09330Snibble.max 105579d09330Snibble.max return 0; 1056d28677ffSAntti Palosaari err: 10577978b8a1SAntti Palosaari dev_dbg(&client->dev, "failed=%d\n", ret); 1058d28677ffSAntti Palosaari return ret; 105979d09330Snibble.max } 106079d09330Snibble.max 1061395d00d1SAntti Palosaari static int m88ds3103_diseqc_send_master_cmd(struct dvb_frontend *fe, 1062395d00d1SAntti Palosaari struct dvb_diseqc_master_cmd *diseqc_cmd) 1063395d00d1SAntti Palosaari { 10647978b8a1SAntti Palosaari struct m88ds3103_dev *dev = fe->demodulator_priv; 10657978b8a1SAntti Palosaari struct i2c_client *client = dev->client; 1066befa0cc1SAntti Palosaari int ret; 1067478932b1SAntti Palosaari unsigned int utmp; 1068befa0cc1SAntti Palosaari unsigned long timeout; 106941b9aa00SAntti Palosaari 10707978b8a1SAntti Palosaari dev_dbg(&client->dev, "msg=%*ph\n", 1071395d00d1SAntti Palosaari diseqc_cmd->msg_len, diseqc_cmd->msg); 1072395d00d1SAntti Palosaari 10737978b8a1SAntti Palosaari if (!dev->warm) { 1074395d00d1SAntti Palosaari ret = -EAGAIN; 1075395d00d1SAntti Palosaari goto err; 1076395d00d1SAntti Palosaari } 1077395d00d1SAntti Palosaari 1078395d00d1SAntti Palosaari if (diseqc_cmd->msg_len < 3 || diseqc_cmd->msg_len > 6) { 1079395d00d1SAntti Palosaari ret = -EINVAL; 1080395d00d1SAntti Palosaari goto err; 1081395d00d1SAntti Palosaari } 1082395d00d1SAntti Palosaari 1083478932b1SAntti Palosaari utmp = dev->cfg->envelope_mode << 5; 108456ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0xa2, 0xe0, utmp); 1085395d00d1SAntti Palosaari if (ret) 1086395d00d1SAntti Palosaari goto err; 1087395d00d1SAntti Palosaari 1088478932b1SAntti Palosaari ret = regmap_bulk_write(dev->regmap, 0xa3, diseqc_cmd->msg, 1089395d00d1SAntti Palosaari diseqc_cmd->msg_len); 1090395d00d1SAntti Palosaari if (ret) 1091395d00d1SAntti Palosaari goto err; 1092395d00d1SAntti Palosaari 1093478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xa1, 1094395d00d1SAntti Palosaari (diseqc_cmd->msg_len - 1) << 3 | 0x07); 1095395d00d1SAntti Palosaari if (ret) 1096395d00d1SAntti Palosaari goto err; 1097395d00d1SAntti Palosaari 1098395d00d1SAntti Palosaari /* wait DiSEqC TX ready */ 1099befa0cc1SAntti Palosaari #define SEND_MASTER_CMD_TIMEOUT 120 1100befa0cc1SAntti Palosaari timeout = jiffies + msecs_to_jiffies(SEND_MASTER_CMD_TIMEOUT); 1101395d00d1SAntti Palosaari 11029ef3cdc1SAntti Palosaari /* DiSEqC message period is 13.5 ms per byte */ 11039ef3cdc1SAntti Palosaari utmp = diseqc_cmd->msg_len * 13500; 11049ef3cdc1SAntti Palosaari usleep_range(utmp - 4000, utmp); 1105befa0cc1SAntti Palosaari 1106478932b1SAntti Palosaari for (utmp = 1; !time_after(jiffies, timeout) && utmp;) { 1107478932b1SAntti Palosaari ret = regmap_read(dev->regmap, 0xa1, &utmp); 1108395d00d1SAntti Palosaari if (ret) 1109395d00d1SAntti Palosaari goto err; 1110478932b1SAntti Palosaari utmp = (utmp >> 6) & 0x1; 1111395d00d1SAntti Palosaari } 1112395d00d1SAntti Palosaari 1113478932b1SAntti Palosaari if (utmp == 0) { 11147978b8a1SAntti Palosaari dev_dbg(&client->dev, "diseqc tx took %u ms\n", 1115befa0cc1SAntti Palosaari jiffies_to_msecs(jiffies) - 1116befa0cc1SAntti Palosaari (jiffies_to_msecs(timeout) - SEND_MASTER_CMD_TIMEOUT)); 1117befa0cc1SAntti Palosaari } else { 11187978b8a1SAntti Palosaari dev_dbg(&client->dev, "diseqc tx timeout\n"); 1119395d00d1SAntti Palosaari 112056ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0xa1, 0xc0, 0x40); 1121395d00d1SAntti Palosaari if (ret) 1122395d00d1SAntti Palosaari goto err; 1123395d00d1SAntti Palosaari } 1124395d00d1SAntti Palosaari 112556ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0xa2, 0xc0, 0x80); 1126395d00d1SAntti Palosaari if (ret) 1127395d00d1SAntti Palosaari goto err; 1128395d00d1SAntti Palosaari 1129478932b1SAntti Palosaari if (utmp == 1) { 1130395d00d1SAntti Palosaari ret = -ETIMEDOUT; 1131395d00d1SAntti Palosaari goto err; 1132395d00d1SAntti Palosaari } 1133395d00d1SAntti Palosaari 1134395d00d1SAntti Palosaari return 0; 1135395d00d1SAntti Palosaari err: 11367978b8a1SAntti Palosaari dev_dbg(&client->dev, "failed=%d\n", ret); 1137395d00d1SAntti Palosaari return ret; 1138395d00d1SAntti Palosaari } 1139395d00d1SAntti Palosaari 1140395d00d1SAntti Palosaari static int m88ds3103_diseqc_send_burst(struct dvb_frontend *fe, 11410df289a2SMauro Carvalho Chehab enum fe_sec_mini_cmd fe_sec_mini_cmd) 1142395d00d1SAntti Palosaari { 11437978b8a1SAntti Palosaari struct m88ds3103_dev *dev = fe->demodulator_priv; 11447978b8a1SAntti Palosaari struct i2c_client *client = dev->client; 1145befa0cc1SAntti Palosaari int ret; 1146478932b1SAntti Palosaari unsigned int utmp, burst; 1147befa0cc1SAntti Palosaari unsigned long timeout; 114841b9aa00SAntti Palosaari 11497978b8a1SAntti Palosaari dev_dbg(&client->dev, "fe_sec_mini_cmd=%d\n", fe_sec_mini_cmd); 1150395d00d1SAntti Palosaari 11517978b8a1SAntti Palosaari if (!dev->warm) { 1152395d00d1SAntti Palosaari ret = -EAGAIN; 1153395d00d1SAntti Palosaari goto err; 1154395d00d1SAntti Palosaari } 1155395d00d1SAntti Palosaari 1156478932b1SAntti Palosaari utmp = dev->cfg->envelope_mode << 5; 115756ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0xa2, 0xe0, utmp); 1158395d00d1SAntti Palosaari if (ret) 1159395d00d1SAntti Palosaari goto err; 1160395d00d1SAntti Palosaari 1161395d00d1SAntti Palosaari switch (fe_sec_mini_cmd) { 1162395d00d1SAntti Palosaari case SEC_MINI_A: 1163395d00d1SAntti Palosaari burst = 0x02; 1164395d00d1SAntti Palosaari break; 1165395d00d1SAntti Palosaari case SEC_MINI_B: 1166395d00d1SAntti Palosaari burst = 0x01; 1167395d00d1SAntti Palosaari break; 1168395d00d1SAntti Palosaari default: 11697978b8a1SAntti Palosaari dev_dbg(&client->dev, "invalid fe_sec_mini_cmd\n"); 1170395d00d1SAntti Palosaari ret = -EINVAL; 1171395d00d1SAntti Palosaari goto err; 1172395d00d1SAntti Palosaari } 1173395d00d1SAntti Palosaari 1174478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xa1, burst); 1175395d00d1SAntti Palosaari if (ret) 1176395d00d1SAntti Palosaari goto err; 1177395d00d1SAntti Palosaari 1178395d00d1SAntti Palosaari /* wait DiSEqC TX ready */ 1179befa0cc1SAntti Palosaari #define SEND_BURST_TIMEOUT 40 1180befa0cc1SAntti Palosaari timeout = jiffies + msecs_to_jiffies(SEND_BURST_TIMEOUT); 1181395d00d1SAntti Palosaari 1182befa0cc1SAntti Palosaari /* DiSEqC ToneBurst period is 12.5 ms */ 1183befa0cc1SAntti Palosaari usleep_range(8500, 12500); 1184befa0cc1SAntti Palosaari 1185478932b1SAntti Palosaari for (utmp = 1; !time_after(jiffies, timeout) && utmp;) { 1186478932b1SAntti Palosaari ret = regmap_read(dev->regmap, 0xa1, &utmp); 1187395d00d1SAntti Palosaari if (ret) 1188395d00d1SAntti Palosaari goto err; 1189478932b1SAntti Palosaari utmp = (utmp >> 6) & 0x1; 1190395d00d1SAntti Palosaari } 1191395d00d1SAntti Palosaari 1192478932b1SAntti Palosaari if (utmp == 0) { 11937978b8a1SAntti Palosaari dev_dbg(&client->dev, "diseqc tx took %u ms\n", 1194befa0cc1SAntti Palosaari jiffies_to_msecs(jiffies) - 1195befa0cc1SAntti Palosaari (jiffies_to_msecs(timeout) - SEND_BURST_TIMEOUT)); 1196befa0cc1SAntti Palosaari } else { 11977978b8a1SAntti Palosaari dev_dbg(&client->dev, "diseqc tx timeout\n"); 1198befa0cc1SAntti Palosaari 119956ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0xa1, 0xc0, 0x40); 1200befa0cc1SAntti Palosaari if (ret) 1201befa0cc1SAntti Palosaari goto err; 1202befa0cc1SAntti Palosaari } 1203395d00d1SAntti Palosaari 120456ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0xa2, 0xc0, 0x80); 1205395d00d1SAntti Palosaari if (ret) 1206395d00d1SAntti Palosaari goto err; 1207395d00d1SAntti Palosaari 1208478932b1SAntti Palosaari if (utmp == 1) { 1209395d00d1SAntti Palosaari ret = -ETIMEDOUT; 1210395d00d1SAntti Palosaari goto err; 1211395d00d1SAntti Palosaari } 1212395d00d1SAntti Palosaari 1213395d00d1SAntti Palosaari return 0; 1214395d00d1SAntti Palosaari err: 12157978b8a1SAntti Palosaari dev_dbg(&client->dev, "failed=%d\n", ret); 1216395d00d1SAntti Palosaari return ret; 1217395d00d1SAntti Palosaari } 1218395d00d1SAntti Palosaari 1219395d00d1SAntti Palosaari static int m88ds3103_get_tune_settings(struct dvb_frontend *fe, 1220395d00d1SAntti Palosaari struct dvb_frontend_tune_settings *s) 1221395d00d1SAntti Palosaari { 1222395d00d1SAntti Palosaari s->min_delay_ms = 3000; 1223395d00d1SAntti Palosaari 1224395d00d1SAntti Palosaari return 0; 1225395d00d1SAntti Palosaari } 1226395d00d1SAntti Palosaari 122744b9055bSAntti Palosaari static void m88ds3103_release(struct dvb_frontend *fe) 1228395d00d1SAntti Palosaari { 12297978b8a1SAntti Palosaari struct m88ds3103_dev *dev = fe->demodulator_priv; 12307978b8a1SAntti Palosaari struct i2c_client *client = dev->client; 123141b9aa00SAntti Palosaari 1232f01919e8SAntti Palosaari i2c_unregister_device(client); 1233395d00d1SAntti Palosaari } 1234395d00d1SAntti Palosaari 1235e00fed40SPeter Rosin static int m88ds3103_select(struct i2c_mux_core *muxc, u32 chan) 1236395d00d1SAntti Palosaari { 1237e00fed40SPeter Rosin struct m88ds3103_dev *dev = i2c_mux_priv(muxc); 12387978b8a1SAntti Palosaari struct i2c_client *client = dev->client; 1239395d00d1SAntti Palosaari int ret; 1240478932b1SAntti Palosaari struct i2c_msg msg = { 12417978b8a1SAntti Palosaari .addr = client->addr, 1242395d00d1SAntti Palosaari .flags = 0, 1243395d00d1SAntti Palosaari .len = 2, 1244395d00d1SAntti Palosaari .buf = "\x03\x11", 1245395d00d1SAntti Palosaari }; 1246395d00d1SAntti Palosaari 1247478932b1SAntti Palosaari /* Open tuner I2C repeater for 1 xfer, closes automatically */ 1248478932b1SAntti Palosaari ret = __i2c_transfer(client->adapter, &msg, 1); 1249395d00d1SAntti Palosaari if (ret != 1) { 12507978b8a1SAntti Palosaari dev_warn(&client->dev, "i2c wr failed=%d\n", ret); 125144b9055bSAntti Palosaari if (ret >= 0) 1252395d00d1SAntti Palosaari ret = -EREMOTEIO; 1253395d00d1SAntti Palosaari return ret; 1254395d00d1SAntti Palosaari } 1255395d00d1SAntti Palosaari 125644b9055bSAntti Palosaari return 0; 125744b9055bSAntti Palosaari } 1258395d00d1SAntti Palosaari 1259f01919e8SAntti Palosaari /* 1260f01919e8SAntti Palosaari * XXX: That is wrapper to m88ds3103_probe() via driver core in order to provide 1261f01919e8SAntti Palosaari * proper I2C client for legacy media attach binding. 1262f01919e8SAntti Palosaari * New users must use I2C client binding directly! 1263f01919e8SAntti Palosaari */ 1264395d00d1SAntti Palosaari struct dvb_frontend *m88ds3103_attach(const struct m88ds3103_config *cfg, 1265395d00d1SAntti Palosaari struct i2c_adapter *i2c, struct i2c_adapter **tuner_i2c_adapter) 1266395d00d1SAntti Palosaari { 1267f01919e8SAntti Palosaari struct i2c_client *client; 1268f01919e8SAntti Palosaari struct i2c_board_info board_info; 1269f01919e8SAntti Palosaari struct m88ds3103_platform_data pdata; 1270395d00d1SAntti Palosaari 1271f01919e8SAntti Palosaari pdata.clk = cfg->clock; 1272f01919e8SAntti Palosaari pdata.i2c_wr_max = cfg->i2c_wr_max; 1273f01919e8SAntti Palosaari pdata.ts_mode = cfg->ts_mode; 1274f01919e8SAntti Palosaari pdata.ts_clk = cfg->ts_clk; 1275f01919e8SAntti Palosaari pdata.ts_clk_pol = cfg->ts_clk_pol; 1276f01919e8SAntti Palosaari pdata.spec_inv = cfg->spec_inv; 1277f01919e8SAntti Palosaari pdata.agc = cfg->agc; 1278f01919e8SAntti Palosaari pdata.agc_inv = cfg->agc_inv; 1279f01919e8SAntti Palosaari pdata.clk_out = cfg->clock_out; 1280f01919e8SAntti Palosaari pdata.envelope_mode = cfg->envelope_mode; 1281f01919e8SAntti Palosaari pdata.lnb_hv_pol = cfg->lnb_hv_pol; 1282f01919e8SAntti Palosaari pdata.lnb_en_pol = cfg->lnb_en_pol; 1283f01919e8SAntti Palosaari pdata.attach_in_use = true; 1284395d00d1SAntti Palosaari 1285f01919e8SAntti Palosaari memset(&board_info, 0, sizeof(board_info)); 1286f01919e8SAntti Palosaari strlcpy(board_info.type, "m88ds3103", I2C_NAME_SIZE); 1287f01919e8SAntti Palosaari board_info.addr = cfg->i2c_addr; 1288f01919e8SAntti Palosaari board_info.platform_data = &pdata; 1289f01919e8SAntti Palosaari client = i2c_new_device(i2c, &board_info); 1290f01919e8SAntti Palosaari if (!client || !client->dev.driver) 1291395d00d1SAntti Palosaari return NULL; 1292f01919e8SAntti Palosaari 1293f01919e8SAntti Palosaari *tuner_i2c_adapter = pdata.get_i2c_adapter(client); 1294f01919e8SAntti Palosaari return pdata.get_dvb_frontend(client); 1295395d00d1SAntti Palosaari } 1296395d00d1SAntti Palosaari EXPORT_SYMBOL(m88ds3103_attach); 1297395d00d1SAntti Palosaari 1298395d00d1SAntti Palosaari static struct dvb_frontend_ops m88ds3103_ops = { 1299395d00d1SAntti Palosaari .delsys = {SYS_DVBS, SYS_DVBS2}, 1300395d00d1SAntti Palosaari .info = { 13017978b8a1SAntti Palosaari .name = "Montage Technology M88DS3103", 1302395d00d1SAntti Palosaari .frequency_min = 950000, 1303395d00d1SAntti Palosaari .frequency_max = 2150000, 1304395d00d1SAntti Palosaari .frequency_tolerance = 5000, 1305395d00d1SAntti Palosaari .symbol_rate_min = 1000000, 1306395d00d1SAntti Palosaari .symbol_rate_max = 45000000, 1307395d00d1SAntti Palosaari .caps = FE_CAN_INVERSION_AUTO | 1308395d00d1SAntti Palosaari FE_CAN_FEC_1_2 | 1309395d00d1SAntti Palosaari FE_CAN_FEC_2_3 | 1310395d00d1SAntti Palosaari FE_CAN_FEC_3_4 | 1311395d00d1SAntti Palosaari FE_CAN_FEC_4_5 | 1312395d00d1SAntti Palosaari FE_CAN_FEC_5_6 | 1313395d00d1SAntti Palosaari FE_CAN_FEC_6_7 | 1314395d00d1SAntti Palosaari FE_CAN_FEC_7_8 | 1315395d00d1SAntti Palosaari FE_CAN_FEC_8_9 | 1316395d00d1SAntti Palosaari FE_CAN_FEC_AUTO | 1317395d00d1SAntti Palosaari FE_CAN_QPSK | 1318395d00d1SAntti Palosaari FE_CAN_RECOVER | 1319395d00d1SAntti Palosaari FE_CAN_2G_MODULATION 1320395d00d1SAntti Palosaari }, 1321395d00d1SAntti Palosaari 1322395d00d1SAntti Palosaari .release = m88ds3103_release, 1323395d00d1SAntti Palosaari 1324395d00d1SAntti Palosaari .get_tune_settings = m88ds3103_get_tune_settings, 1325395d00d1SAntti Palosaari 1326395d00d1SAntti Palosaari .init = m88ds3103_init, 1327395d00d1SAntti Palosaari .sleep = m88ds3103_sleep, 1328395d00d1SAntti Palosaari 1329395d00d1SAntti Palosaari .set_frontend = m88ds3103_set_frontend, 1330395d00d1SAntti Palosaari .get_frontend = m88ds3103_get_frontend, 1331395d00d1SAntti Palosaari 1332395d00d1SAntti Palosaari .read_status = m88ds3103_read_status, 1333395d00d1SAntti Palosaari .read_snr = m88ds3103_read_snr, 13344423a2baSAntti Palosaari .read_ber = m88ds3103_read_ber, 1335395d00d1SAntti Palosaari 1336395d00d1SAntti Palosaari .diseqc_send_master_cmd = m88ds3103_diseqc_send_master_cmd, 1337395d00d1SAntti Palosaari .diseqc_send_burst = m88ds3103_diseqc_send_burst, 1338395d00d1SAntti Palosaari 1339395d00d1SAntti Palosaari .set_tone = m88ds3103_set_tone, 134079d09330Snibble.max .set_voltage = m88ds3103_set_voltage, 1341395d00d1SAntti Palosaari }; 1342395d00d1SAntti Palosaari 1343f01919e8SAntti Palosaari static struct dvb_frontend *m88ds3103_get_dvb_frontend(struct i2c_client *client) 1344f01919e8SAntti Palosaari { 13457978b8a1SAntti Palosaari struct m88ds3103_dev *dev = i2c_get_clientdata(client); 1346f01919e8SAntti Palosaari 1347f01919e8SAntti Palosaari dev_dbg(&client->dev, "\n"); 1348f01919e8SAntti Palosaari 1349f01919e8SAntti Palosaari return &dev->fe; 1350f01919e8SAntti Palosaari } 1351f01919e8SAntti Palosaari 1352f01919e8SAntti Palosaari static struct i2c_adapter *m88ds3103_get_i2c_adapter(struct i2c_client *client) 1353f01919e8SAntti Palosaari { 13547978b8a1SAntti Palosaari struct m88ds3103_dev *dev = i2c_get_clientdata(client); 1355f01919e8SAntti Palosaari 1356f01919e8SAntti Palosaari dev_dbg(&client->dev, "\n"); 1357f01919e8SAntti Palosaari 1358e00fed40SPeter Rosin return dev->muxc->adapter[0]; 1359f01919e8SAntti Palosaari } 1360f01919e8SAntti Palosaari 1361f01919e8SAntti Palosaari static int m88ds3103_probe(struct i2c_client *client, 1362f01919e8SAntti Palosaari const struct i2c_device_id *id) 1363f01919e8SAntti Palosaari { 13647978b8a1SAntti Palosaari struct m88ds3103_dev *dev; 1365f01919e8SAntti Palosaari struct m88ds3103_platform_data *pdata = client->dev.platform_data; 1366f01919e8SAntti Palosaari int ret; 1367478932b1SAntti Palosaari unsigned int utmp; 1368f01919e8SAntti Palosaari 1369f01919e8SAntti Palosaari dev = kzalloc(sizeof(*dev), GFP_KERNEL); 1370f01919e8SAntti Palosaari if (!dev) { 1371f01919e8SAntti Palosaari ret = -ENOMEM; 1372f01919e8SAntti Palosaari goto err; 1373f01919e8SAntti Palosaari } 1374f01919e8SAntti Palosaari 1375f01919e8SAntti Palosaari dev->client = client; 1376f01919e8SAntti Palosaari dev->config.clock = pdata->clk; 1377f01919e8SAntti Palosaari dev->config.i2c_wr_max = pdata->i2c_wr_max; 1378f01919e8SAntti Palosaari dev->config.ts_mode = pdata->ts_mode; 1379f5d9b88dSAntti Palosaari dev->config.ts_clk = pdata->ts_clk * 1000; 1380f01919e8SAntti Palosaari dev->config.ts_clk_pol = pdata->ts_clk_pol; 1381f01919e8SAntti Palosaari dev->config.spec_inv = pdata->spec_inv; 1382f01919e8SAntti Palosaari dev->config.agc_inv = pdata->agc_inv; 1383f01919e8SAntti Palosaari dev->config.clock_out = pdata->clk_out; 1384f01919e8SAntti Palosaari dev->config.envelope_mode = pdata->envelope_mode; 1385f01919e8SAntti Palosaari dev->config.agc = pdata->agc; 1386f01919e8SAntti Palosaari dev->config.lnb_hv_pol = pdata->lnb_hv_pol; 1387f01919e8SAntti Palosaari dev->config.lnb_en_pol = pdata->lnb_en_pol; 1388f01919e8SAntti Palosaari dev->cfg = &dev->config; 1389478932b1SAntti Palosaari /* create regmap */ 1390478932b1SAntti Palosaari dev->regmap_config.reg_bits = 8, 1391478932b1SAntti Palosaari dev->regmap_config.val_bits = 8, 1392478932b1SAntti Palosaari dev->regmap_config.lock_arg = dev, 1393478932b1SAntti Palosaari dev->regmap = devm_regmap_init_i2c(client, &dev->regmap_config); 1394478932b1SAntti Palosaari if (IS_ERR(dev->regmap)) { 1395478932b1SAntti Palosaari ret = PTR_ERR(dev->regmap); 1396478932b1SAntti Palosaari goto err_kfree; 1397478932b1SAntti Palosaari } 1398f01919e8SAntti Palosaari 1399f01919e8SAntti Palosaari /* 0x00: chip id[6:0], 0x01: chip ver[7:0], 0x02: chip ver[15:8] */ 1400478932b1SAntti Palosaari ret = regmap_read(dev->regmap, 0x00, &utmp); 1401f01919e8SAntti Palosaari if (ret) 1402f01919e8SAntti Palosaari goto err_kfree; 1403f01919e8SAntti Palosaari 1404478932b1SAntti Palosaari dev->chip_id = utmp >> 1; 1405478932b1SAntti Palosaari dev_dbg(&client->dev, "chip_id=%02x\n", dev->chip_id); 1406f01919e8SAntti Palosaari 1407478932b1SAntti Palosaari switch (dev->chip_id) { 1408f01919e8SAntti Palosaari case M88RS6000_CHIP_ID: 1409f01919e8SAntti Palosaari case M88DS3103_CHIP_ID: 1410f01919e8SAntti Palosaari break; 1411f01919e8SAntti Palosaari default: 1412f01919e8SAntti Palosaari goto err_kfree; 1413f01919e8SAntti Palosaari } 1414f01919e8SAntti Palosaari 1415f01919e8SAntti Palosaari switch (dev->cfg->clock_out) { 1416f01919e8SAntti Palosaari case M88DS3103_CLOCK_OUT_DISABLED: 1417478932b1SAntti Palosaari utmp = 0x80; 1418f01919e8SAntti Palosaari break; 1419f01919e8SAntti Palosaari case M88DS3103_CLOCK_OUT_ENABLED: 1420478932b1SAntti Palosaari utmp = 0x00; 1421f01919e8SAntti Palosaari break; 1422f01919e8SAntti Palosaari case M88DS3103_CLOCK_OUT_ENABLED_DIV2: 1423478932b1SAntti Palosaari utmp = 0x10; 1424f01919e8SAntti Palosaari break; 1425f01919e8SAntti Palosaari default: 14264347df6aSDan Carpenter ret = -EINVAL; 1427f01919e8SAntti Palosaari goto err_kfree; 1428f01919e8SAntti Palosaari } 1429f01919e8SAntti Palosaari 1430334ef18eSAntti Palosaari if (!pdata->ts_clk) { 1431334ef18eSAntti Palosaari ret = -EINVAL; 1432334ef18eSAntti Palosaari goto err_kfree; 1433334ef18eSAntti Palosaari } 1434334ef18eSAntti Palosaari 1435f01919e8SAntti Palosaari /* 0x29 register is defined differently for m88rs6000. */ 1436f01919e8SAntti Palosaari /* set internal tuner address to 0x21 */ 1437478932b1SAntti Palosaari if (dev->chip_id == M88RS6000_CHIP_ID) 1438478932b1SAntti Palosaari utmp = 0x00; 1439f01919e8SAntti Palosaari 1440478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0x29, utmp); 1441f01919e8SAntti Palosaari if (ret) 1442f01919e8SAntti Palosaari goto err_kfree; 1443f01919e8SAntti Palosaari 1444f01919e8SAntti Palosaari /* sleep */ 144556ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x08, 0x01, 0x00); 1446f01919e8SAntti Palosaari if (ret) 1447f01919e8SAntti Palosaari goto err_kfree; 144856ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x04, 0x01, 0x01); 1449f01919e8SAntti Palosaari if (ret) 1450f01919e8SAntti Palosaari goto err_kfree; 145156ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x23, 0x10, 0x10); 1452f01919e8SAntti Palosaari if (ret) 1453f01919e8SAntti Palosaari goto err_kfree; 1454f01919e8SAntti Palosaari 1455f01919e8SAntti Palosaari /* create mux i2c adapter for tuner */ 1456e00fed40SPeter Rosin dev->muxc = i2c_mux_alloc(client->adapter, &client->dev, 1, 0, 0, 1457e00fed40SPeter Rosin m88ds3103_select, NULL); 1458e00fed40SPeter Rosin if (!dev->muxc) { 14594347df6aSDan Carpenter ret = -ENOMEM; 1460f01919e8SAntti Palosaari goto err_kfree; 14614347df6aSDan Carpenter } 1462e00fed40SPeter Rosin dev->muxc->priv = dev; 1463e00fed40SPeter Rosin ret = i2c_mux_add_adapter(dev->muxc, 0, 0, 0); 1464e00fed40SPeter Rosin if (ret) 1465e00fed40SPeter Rosin goto err_kfree; 1466f01919e8SAntti Palosaari 1467f01919e8SAntti Palosaari /* create dvb_frontend */ 1468f01919e8SAntti Palosaari memcpy(&dev->fe.ops, &m88ds3103_ops, sizeof(struct dvb_frontend_ops)); 1469f01919e8SAntti Palosaari if (dev->chip_id == M88RS6000_CHIP_ID) 14707978b8a1SAntti Palosaari strncpy(dev->fe.ops.info.name, "Montage Technology M88RS6000", 14717978b8a1SAntti Palosaari sizeof(dev->fe.ops.info.name)); 1472f01919e8SAntti Palosaari if (!pdata->attach_in_use) 1473f01919e8SAntti Palosaari dev->fe.ops.release = NULL; 1474f01919e8SAntti Palosaari dev->fe.demodulator_priv = dev; 1475f01919e8SAntti Palosaari i2c_set_clientdata(client, dev); 1476f01919e8SAntti Palosaari 1477f01919e8SAntti Palosaari /* setup callbacks */ 1478f01919e8SAntti Palosaari pdata->get_dvb_frontend = m88ds3103_get_dvb_frontend; 1479f01919e8SAntti Palosaari pdata->get_i2c_adapter = m88ds3103_get_i2c_adapter; 1480f01919e8SAntti Palosaari return 0; 1481f01919e8SAntti Palosaari err_kfree: 1482f01919e8SAntti Palosaari kfree(dev); 1483f01919e8SAntti Palosaari err: 1484f01919e8SAntti Palosaari dev_dbg(&client->dev, "failed=%d\n", ret); 1485f01919e8SAntti Palosaari return ret; 1486f01919e8SAntti Palosaari } 1487f01919e8SAntti Palosaari 1488f01919e8SAntti Palosaari static int m88ds3103_remove(struct i2c_client *client) 1489f01919e8SAntti Palosaari { 14907978b8a1SAntti Palosaari struct m88ds3103_dev *dev = i2c_get_clientdata(client); 1491f01919e8SAntti Palosaari 1492f01919e8SAntti Palosaari dev_dbg(&client->dev, "\n"); 1493f01919e8SAntti Palosaari 1494e00fed40SPeter Rosin i2c_mux_del_adapters(dev->muxc); 1495f01919e8SAntti Palosaari 1496f01919e8SAntti Palosaari kfree(dev); 1497f01919e8SAntti Palosaari return 0; 1498f01919e8SAntti Palosaari } 1499f01919e8SAntti Palosaari 1500f01919e8SAntti Palosaari static const struct i2c_device_id m88ds3103_id_table[] = { 1501f01919e8SAntti Palosaari {"m88ds3103", 0}, 1502f01919e8SAntti Palosaari {} 1503f01919e8SAntti Palosaari }; 1504f01919e8SAntti Palosaari MODULE_DEVICE_TABLE(i2c, m88ds3103_id_table); 1505f01919e8SAntti Palosaari 1506f01919e8SAntti Palosaari static struct i2c_driver m88ds3103_driver = { 1507f01919e8SAntti Palosaari .driver = { 1508f01919e8SAntti Palosaari .name = "m88ds3103", 1509f01919e8SAntti Palosaari .suppress_bind_attrs = true, 1510f01919e8SAntti Palosaari }, 1511f01919e8SAntti Palosaari .probe = m88ds3103_probe, 1512f01919e8SAntti Palosaari .remove = m88ds3103_remove, 1513f01919e8SAntti Palosaari .id_table = m88ds3103_id_table, 1514f01919e8SAntti Palosaari }; 1515f01919e8SAntti Palosaari 1516f01919e8SAntti Palosaari module_i2c_driver(m88ds3103_driver); 1517f01919e8SAntti Palosaari 1518395d00d1SAntti Palosaari MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>"); 15197978b8a1SAntti Palosaari MODULE_DESCRIPTION("Montage Technology M88DS3103 DVB-S/S2 demodulator driver"); 1520395d00d1SAntti Palosaari MODULE_LICENSE("GPL"); 1521395d00d1SAntti Palosaari MODULE_FIRMWARE(M88DS3103_FIRMWARE); 1522f4df95bcSnibble.max MODULE_FIRMWARE(M88RS6000_FIRMWARE); 1523