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 /* 680f91c9d6SDavid Howells * Get the demodulator AGC PWM voltage setting supplied to the tuner. 690f91c9d6SDavid Howells */ 700f91c9d6SDavid Howells int m88ds3103_get_agc_pwm(struct dvb_frontend *fe, u8 *_agc_pwm) 710f91c9d6SDavid Howells { 720f91c9d6SDavid Howells struct m88ds3103_dev *dev = fe->demodulator_priv; 730f91c9d6SDavid Howells unsigned tmp; 740f91c9d6SDavid Howells int ret; 750f91c9d6SDavid Howells 760f91c9d6SDavid Howells ret = regmap_read(dev->regmap, 0x3f, &tmp); 770f91c9d6SDavid Howells if (ret == 0) 780f91c9d6SDavid Howells *_agc_pwm = tmp; 790f91c9d6SDavid Howells return ret; 800f91c9d6SDavid Howells } 810f91c9d6SDavid Howells EXPORT_SYMBOL(m88ds3103_get_agc_pwm); 820f91c9d6SDavid Howells 830df289a2SMauro Carvalho Chehab static int m88ds3103_read_status(struct dvb_frontend *fe, 840df289a2SMauro Carvalho Chehab enum fe_status *status) 85395d00d1SAntti Palosaari { 867978b8a1SAntti Palosaari struct m88ds3103_dev *dev = fe->demodulator_priv; 877978b8a1SAntti Palosaari struct i2c_client *client = dev->client; 88395d00d1SAntti Palosaari struct dtv_frontend_properties *c = &fe->dtv_property_cache; 89c1daf651SAntti Palosaari int ret, i, itmp; 90478932b1SAntti Palosaari unsigned int utmp; 91c1daf651SAntti Palosaari u8 buf[3]; 92395d00d1SAntti Palosaari 93395d00d1SAntti Palosaari *status = 0; 94395d00d1SAntti Palosaari 957978b8a1SAntti Palosaari if (!dev->warm) { 96395d00d1SAntti Palosaari ret = -EAGAIN; 97395d00d1SAntti Palosaari goto err; 98395d00d1SAntti Palosaari } 99395d00d1SAntti Palosaari 100395d00d1SAntti Palosaari switch (c->delivery_system) { 101395d00d1SAntti Palosaari case SYS_DVBS: 102478932b1SAntti Palosaari ret = regmap_read(dev->regmap, 0xd1, &utmp); 103395d00d1SAntti Palosaari if (ret) 104395d00d1SAntti Palosaari goto err; 105395d00d1SAntti Palosaari 106478932b1SAntti Palosaari if ((utmp & 0x07) == 0x07) 107395d00d1SAntti Palosaari *status = FE_HAS_SIGNAL | FE_HAS_CARRIER | 108395d00d1SAntti Palosaari FE_HAS_VITERBI | FE_HAS_SYNC | 109395d00d1SAntti Palosaari FE_HAS_LOCK; 110395d00d1SAntti Palosaari break; 111395d00d1SAntti Palosaari case SYS_DVBS2: 112478932b1SAntti Palosaari ret = regmap_read(dev->regmap, 0x0d, &utmp); 113395d00d1SAntti Palosaari if (ret) 114395d00d1SAntti Palosaari goto err; 115395d00d1SAntti Palosaari 116478932b1SAntti Palosaari if ((utmp & 0x8f) == 0x8f) 117395d00d1SAntti Palosaari *status = FE_HAS_SIGNAL | FE_HAS_CARRIER | 118395d00d1SAntti Palosaari FE_HAS_VITERBI | FE_HAS_SYNC | 119395d00d1SAntti Palosaari FE_HAS_LOCK; 120395d00d1SAntti Palosaari break; 121395d00d1SAntti Palosaari default: 1227978b8a1SAntti Palosaari dev_dbg(&client->dev, "invalid delivery_system\n"); 123395d00d1SAntti Palosaari ret = -EINVAL; 124395d00d1SAntti Palosaari goto err; 125395d00d1SAntti Palosaari } 126395d00d1SAntti Palosaari 1277978b8a1SAntti Palosaari dev->fe_status = *status; 128478932b1SAntti Palosaari dev_dbg(&client->dev, "lock=%02x status=%02x\n", utmp, *status); 129395d00d1SAntti Palosaari 130c1daf651SAntti Palosaari /* CNR */ 1317978b8a1SAntti Palosaari if (dev->fe_status & FE_HAS_VITERBI) { 132c1daf651SAntti Palosaari unsigned int cnr, noise, signal, noise_tot, signal_tot; 133c1daf651SAntti Palosaari 134c1daf651SAntti Palosaari cnr = 0; 135c1daf651SAntti Palosaari /* more iterations for more accurate estimation */ 136c1daf651SAntti Palosaari #define M88DS3103_SNR_ITERATIONS 3 137c1daf651SAntti Palosaari 138c1daf651SAntti Palosaari switch (c->delivery_system) { 139c1daf651SAntti Palosaari case SYS_DVBS: 140c1daf651SAntti Palosaari itmp = 0; 141c1daf651SAntti Palosaari 142c1daf651SAntti Palosaari for (i = 0; i < M88DS3103_SNR_ITERATIONS; i++) { 143478932b1SAntti Palosaari ret = regmap_read(dev->regmap, 0xff, &utmp); 144c1daf651SAntti Palosaari if (ret) 145c1daf651SAntti Palosaari goto err; 146c1daf651SAntti Palosaari 147478932b1SAntti Palosaari itmp += utmp; 148c1daf651SAntti Palosaari } 149c1daf651SAntti Palosaari 150c1daf651SAntti Palosaari /* use of single register limits max value to 15 dB */ 151c1daf651SAntti Palosaari /* SNR(X) dB = 10 * ln(X) / ln(10) dB */ 152c1daf651SAntti Palosaari itmp = DIV_ROUND_CLOSEST(itmp, 8 * M88DS3103_SNR_ITERATIONS); 153c1daf651SAntti Palosaari if (itmp) 154c1daf651SAntti Palosaari cnr = div_u64((u64) 10000 * intlog2(itmp), intlog2(10)); 155c1daf651SAntti Palosaari break; 156c1daf651SAntti Palosaari case SYS_DVBS2: 157c1daf651SAntti Palosaari noise_tot = 0; 158c1daf651SAntti Palosaari signal_tot = 0; 159c1daf651SAntti Palosaari 160c1daf651SAntti Palosaari for (i = 0; i < M88DS3103_SNR_ITERATIONS; i++) { 161478932b1SAntti Palosaari ret = regmap_bulk_read(dev->regmap, 0x8c, buf, 3); 162c1daf651SAntti Palosaari if (ret) 163c1daf651SAntti Palosaari goto err; 164c1daf651SAntti Palosaari 165c1daf651SAntti Palosaari noise = buf[1] << 6; /* [13:6] */ 166c1daf651SAntti Palosaari noise |= buf[0] & 0x3f; /* [5:0] */ 167c1daf651SAntti Palosaari noise >>= 2; 168c1daf651SAntti Palosaari signal = buf[2] * buf[2]; 169c1daf651SAntti Palosaari signal >>= 1; 170c1daf651SAntti Palosaari 171c1daf651SAntti Palosaari noise_tot += noise; 172c1daf651SAntti Palosaari signal_tot += signal; 173c1daf651SAntti Palosaari } 174c1daf651SAntti Palosaari 175c1daf651SAntti Palosaari noise = noise_tot / M88DS3103_SNR_ITERATIONS; 176c1daf651SAntti Palosaari signal = signal_tot / M88DS3103_SNR_ITERATIONS; 177c1daf651SAntti Palosaari 178c1daf651SAntti Palosaari /* SNR(X) dB = 10 * log10(X) dB */ 179c1daf651SAntti Palosaari if (signal > noise) { 180c1daf651SAntti Palosaari itmp = signal / noise; 181c1daf651SAntti Palosaari cnr = div_u64((u64) 10000 * intlog10(itmp), (1 << 24)); 182c1daf651SAntti Palosaari } 183c1daf651SAntti Palosaari break; 184c1daf651SAntti Palosaari default: 1857978b8a1SAntti Palosaari dev_dbg(&client->dev, "invalid delivery_system\n"); 186c1daf651SAntti Palosaari ret = -EINVAL; 187c1daf651SAntti Palosaari goto err; 188c1daf651SAntti Palosaari } 189c1daf651SAntti Palosaari 190c1daf651SAntti Palosaari if (cnr) { 191c1daf651SAntti Palosaari c->cnr.stat[0].scale = FE_SCALE_DECIBEL; 192c1daf651SAntti Palosaari c->cnr.stat[0].svalue = cnr; 193c1daf651SAntti Palosaari } else { 194c1daf651SAntti Palosaari c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; 195c1daf651SAntti Palosaari } 196c1daf651SAntti Palosaari } else { 197c1daf651SAntti Palosaari c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; 198c1daf651SAntti Palosaari } 199c1daf651SAntti Palosaari 200ce80d713SAntti Palosaari /* BER */ 2017978b8a1SAntti Palosaari if (dev->fe_status & FE_HAS_LOCK) { 202ce80d713SAntti Palosaari unsigned int utmp, post_bit_error, post_bit_count; 203ce80d713SAntti Palosaari 204ce80d713SAntti Palosaari switch (c->delivery_system) { 205ce80d713SAntti Palosaari case SYS_DVBS: 206478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xf9, 0x04); 207ce80d713SAntti Palosaari if (ret) 208ce80d713SAntti Palosaari goto err; 209ce80d713SAntti Palosaari 210478932b1SAntti Palosaari ret = regmap_read(dev->regmap, 0xf8, &utmp); 211ce80d713SAntti Palosaari if (ret) 212ce80d713SAntti Palosaari goto err; 213ce80d713SAntti Palosaari 214ce80d713SAntti Palosaari /* measurement ready? */ 215478932b1SAntti Palosaari if (!(utmp & 0x10)) { 216478932b1SAntti Palosaari ret = regmap_bulk_read(dev->regmap, 0xf6, buf, 2); 217ce80d713SAntti Palosaari if (ret) 218ce80d713SAntti Palosaari goto err; 219ce80d713SAntti Palosaari 220ce80d713SAntti Palosaari post_bit_error = buf[1] << 8 | buf[0] << 0; 221ce80d713SAntti Palosaari post_bit_count = 0x800000; 2227978b8a1SAntti Palosaari dev->post_bit_error += post_bit_error; 2237978b8a1SAntti Palosaari dev->post_bit_count += post_bit_count; 2247978b8a1SAntti Palosaari dev->dvbv3_ber = post_bit_error; 225ce80d713SAntti Palosaari 226ce80d713SAntti Palosaari /* restart measurement */ 227478932b1SAntti Palosaari utmp |= 0x10; 228478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xf8, utmp); 229ce80d713SAntti Palosaari if (ret) 230ce80d713SAntti Palosaari goto err; 231ce80d713SAntti Palosaari } 232ce80d713SAntti Palosaari break; 233ce80d713SAntti Palosaari case SYS_DVBS2: 234478932b1SAntti Palosaari ret = regmap_bulk_read(dev->regmap, 0xd5, buf, 3); 235ce80d713SAntti Palosaari if (ret) 236ce80d713SAntti Palosaari goto err; 237ce80d713SAntti Palosaari 238ce80d713SAntti Palosaari utmp = buf[2] << 16 | buf[1] << 8 | buf[0] << 0; 239ce80d713SAntti Palosaari 240ce80d713SAntti Palosaari /* enough data? */ 241ce80d713SAntti Palosaari if (utmp > 4000) { 242478932b1SAntti Palosaari ret = regmap_bulk_read(dev->regmap, 0xf7, buf, 2); 243ce80d713SAntti Palosaari if (ret) 244ce80d713SAntti Palosaari goto err; 245ce80d713SAntti Palosaari 246ce80d713SAntti Palosaari post_bit_error = buf[1] << 8 | buf[0] << 0; 247ce80d713SAntti Palosaari post_bit_count = 32 * utmp; /* TODO: FEC */ 2487978b8a1SAntti Palosaari dev->post_bit_error += post_bit_error; 2497978b8a1SAntti Palosaari dev->post_bit_count += post_bit_count; 2507978b8a1SAntti Palosaari dev->dvbv3_ber = post_bit_error; 251ce80d713SAntti Palosaari 252ce80d713SAntti Palosaari /* restart measurement */ 253478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xd1, 0x01); 254ce80d713SAntti Palosaari if (ret) 255ce80d713SAntti Palosaari goto err; 256ce80d713SAntti Palosaari 257478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xf9, 0x01); 258ce80d713SAntti Palosaari if (ret) 259ce80d713SAntti Palosaari goto err; 260ce80d713SAntti Palosaari 261478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xf9, 0x00); 262ce80d713SAntti Palosaari if (ret) 263ce80d713SAntti Palosaari goto err; 264ce80d713SAntti Palosaari 265478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xd1, 0x00); 266ce80d713SAntti Palosaari if (ret) 267ce80d713SAntti Palosaari goto err; 268ce80d713SAntti Palosaari } 269ce80d713SAntti Palosaari break; 270ce80d713SAntti Palosaari default: 2717978b8a1SAntti Palosaari dev_dbg(&client->dev, "invalid delivery_system\n"); 272ce80d713SAntti Palosaari ret = -EINVAL; 273ce80d713SAntti Palosaari goto err; 274ce80d713SAntti Palosaari } 275ce80d713SAntti Palosaari 276ce80d713SAntti Palosaari c->post_bit_error.stat[0].scale = FE_SCALE_COUNTER; 2777978b8a1SAntti Palosaari c->post_bit_error.stat[0].uvalue = dev->post_bit_error; 278ce80d713SAntti Palosaari c->post_bit_count.stat[0].scale = FE_SCALE_COUNTER; 2797978b8a1SAntti Palosaari c->post_bit_count.stat[0].uvalue = dev->post_bit_count; 280ce80d713SAntti Palosaari } else { 281ce80d713SAntti Palosaari c->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; 282ce80d713SAntti Palosaari c->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE; 283ce80d713SAntti Palosaari } 284ce80d713SAntti Palosaari 285395d00d1SAntti Palosaari return 0; 286395d00d1SAntti Palosaari err: 2877978b8a1SAntti Palosaari dev_dbg(&client->dev, "failed=%d\n", ret); 288395d00d1SAntti Palosaari return ret; 289395d00d1SAntti Palosaari } 290395d00d1SAntti Palosaari 291395d00d1SAntti Palosaari static int m88ds3103_set_frontend(struct dvb_frontend *fe) 292395d00d1SAntti Palosaari { 2937978b8a1SAntti Palosaari struct m88ds3103_dev *dev = fe->demodulator_priv; 2947978b8a1SAntti Palosaari struct i2c_client *client = dev->client; 295395d00d1SAntti Palosaari struct dtv_frontend_properties *c = &fe->dtv_property_cache; 29606487deeSAntti Palosaari int ret, len; 297395d00d1SAntti Palosaari const struct m88ds3103_reg_val *init; 298b6851419Snibble.max u8 u8tmp, u8tmp1 = 0, u8tmp2 = 0; /* silence compiler warning */ 299f4df95bcSnibble.max u8 buf[3]; 300334ef18eSAntti Palosaari u16 u16tmp; 301f5d9b88dSAntti Palosaari u32 tuner_frequency_khz, target_mclk; 302395d00d1SAntti Palosaari s32 s32tmp; 303981fbe3dSJames Hutchinson static const struct reg_sequence reset_buf[] = { 304981fbe3dSJames Hutchinson {0x07, 0x80}, {0x07, 0x00} 305981fbe3dSJames Hutchinson }; 30641b9aa00SAntti Palosaari 3077978b8a1SAntti Palosaari dev_dbg(&client->dev, 3087978b8a1SAntti Palosaari "delivery_system=%d modulation=%d frequency=%u symbol_rate=%d inversion=%d pilot=%d rolloff=%d\n", 3097978b8a1SAntti Palosaari c->delivery_system, c->modulation, c->frequency, c->symbol_rate, 310395d00d1SAntti Palosaari c->inversion, c->pilot, c->rolloff); 311395d00d1SAntti Palosaari 3127978b8a1SAntti Palosaari if (!dev->warm) { 313395d00d1SAntti Palosaari ret = -EAGAIN; 314395d00d1SAntti Palosaari goto err; 315395d00d1SAntti Palosaari } 316395d00d1SAntti Palosaari 317f4df95bcSnibble.max /* reset */ 318981fbe3dSJames Hutchinson ret = regmap_multi_reg_write(dev->regmap, reset_buf, 2); 319f4df95bcSnibble.max if (ret) 320f4df95bcSnibble.max goto err; 321f4df95bcSnibble.max 322f4df95bcSnibble.max /* Disable demod clock path */ 3237978b8a1SAntti Palosaari if (dev->chip_id == M88RS6000_CHIP_ID) { 324478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0x06, 0xe0); 325f4df95bcSnibble.max if (ret) 326f4df95bcSnibble.max goto err; 327f4df95bcSnibble.max } 328f4df95bcSnibble.max 329395d00d1SAntti Palosaari /* program tuner */ 330395d00d1SAntti Palosaari if (fe->ops.tuner_ops.set_params) { 331395d00d1SAntti Palosaari ret = fe->ops.tuner_ops.set_params(fe); 332395d00d1SAntti Palosaari if (ret) 333395d00d1SAntti Palosaari goto err; 334395d00d1SAntti Palosaari } 335395d00d1SAntti Palosaari 336395d00d1SAntti Palosaari if (fe->ops.tuner_ops.get_frequency) { 337f5d9b88dSAntti Palosaari ret = fe->ops.tuner_ops.get_frequency(fe, &tuner_frequency_khz); 338395d00d1SAntti Palosaari if (ret) 339395d00d1SAntti Palosaari goto err; 3402f9dff3fSAntti Palosaari } else { 3412f9dff3fSAntti Palosaari /* 3422f9dff3fSAntti Palosaari * Use nominal target frequency as tuner driver does not provide 3432f9dff3fSAntti Palosaari * actual frequency used. Carrier offset calculation is not 3442f9dff3fSAntti Palosaari * valid. 3452f9dff3fSAntti Palosaari */ 346f5d9b88dSAntti Palosaari tuner_frequency_khz = c->frequency; 347395d00d1SAntti Palosaari } 348395d00d1SAntti Palosaari 349f4df95bcSnibble.max /* select M88RS6000 demod main mclk and ts mclk from tuner die. */ 3507978b8a1SAntti Palosaari if (dev->chip_id == M88RS6000_CHIP_ID) { 351f4df95bcSnibble.max if (c->symbol_rate > 45010000) 352f5d9b88dSAntti Palosaari dev->mclk = 110250000; 353f4df95bcSnibble.max else 354f5d9b88dSAntti Palosaari dev->mclk = 96000000; 355395d00d1SAntti Palosaari 356f4df95bcSnibble.max if (c->delivery_system == SYS_DVBS) 357f5d9b88dSAntti Palosaari target_mclk = 96000000; 358f4df95bcSnibble.max else 359f5d9b88dSAntti Palosaari target_mclk = 144000000; 360395d00d1SAntti Palosaari 361f4df95bcSnibble.max /* Enable demod clock path */ 362478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0x06, 0x00); 363f4df95bcSnibble.max if (ret) 364f4df95bcSnibble.max goto err; 365f4df95bcSnibble.max usleep_range(10000, 20000); 366f4df95bcSnibble.max } else { 367f4df95bcSnibble.max /* set M88DS3103 mclk and ts mclk. */ 368f5d9b88dSAntti Palosaari dev->mclk = 96000000; 369f4df95bcSnibble.max 3707978b8a1SAntti Palosaari switch (dev->cfg->ts_mode) { 371395d00d1SAntti Palosaari case M88DS3103_TS_SERIAL: 372395d00d1SAntti Palosaari case M88DS3103_TS_SERIAL_D7: 3737978b8a1SAntti Palosaari target_mclk = dev->cfg->ts_clk; 374395d00d1SAntti Palosaari break; 375395d00d1SAntti Palosaari case M88DS3103_TS_PARALLEL: 376395d00d1SAntti Palosaari case M88DS3103_TS_CI: 377b6851419Snibble.max if (c->delivery_system == SYS_DVBS) 378f5d9b88dSAntti Palosaari target_mclk = 96000000; 379b6851419Snibble.max else { 380395d00d1SAntti Palosaari if (c->symbol_rate < 18000000) 381f5d9b88dSAntti Palosaari target_mclk = 96000000; 382395d00d1SAntti Palosaari else if (c->symbol_rate < 28000000) 383f5d9b88dSAntti Palosaari target_mclk = 144000000; 384395d00d1SAntti Palosaari else 385f5d9b88dSAntti Palosaari target_mclk = 192000000; 386b6851419Snibble.max } 387395d00d1SAntti Palosaari break; 388395d00d1SAntti Palosaari default: 3897978b8a1SAntti Palosaari dev_dbg(&client->dev, "invalid ts_mode\n"); 390395d00d1SAntti Palosaari ret = -EINVAL; 391395d00d1SAntti Palosaari goto err; 392395d00d1SAntti Palosaari } 393f4df95bcSnibble.max 394f4df95bcSnibble.max switch (target_mclk) { 395f5d9b88dSAntti Palosaari case 96000000: 396f4df95bcSnibble.max u8tmp1 = 0x02; /* 0b10 */ 397f4df95bcSnibble.max u8tmp2 = 0x01; /* 0b01 */ 398f4df95bcSnibble.max break; 399f5d9b88dSAntti Palosaari case 144000000: 400f4df95bcSnibble.max u8tmp1 = 0x00; /* 0b00 */ 401f4df95bcSnibble.max u8tmp2 = 0x01; /* 0b01 */ 402f4df95bcSnibble.max break; 403f5d9b88dSAntti Palosaari case 192000000: 404f4df95bcSnibble.max u8tmp1 = 0x03; /* 0b11 */ 405f4df95bcSnibble.max u8tmp2 = 0x00; /* 0b00 */ 406f4df95bcSnibble.max break; 407f4df95bcSnibble.max } 40856ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x22, 0xc0, u8tmp1 << 6); 409f4df95bcSnibble.max if (ret) 410f4df95bcSnibble.max goto err; 41156ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x24, 0xc0, u8tmp2 << 6); 412f4df95bcSnibble.max if (ret) 413f4df95bcSnibble.max goto err; 414f4df95bcSnibble.max } 415f4df95bcSnibble.max 416478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xb2, 0x01); 417f4df95bcSnibble.max if (ret) 418f4df95bcSnibble.max goto err; 419f4df95bcSnibble.max 420478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0x00, 0x01); 421f4df95bcSnibble.max if (ret) 422f4df95bcSnibble.max goto err; 423f4df95bcSnibble.max 424f4df95bcSnibble.max switch (c->delivery_system) { 425f4df95bcSnibble.max case SYS_DVBS: 4267978b8a1SAntti Palosaari if (dev->chip_id == M88RS6000_CHIP_ID) { 427f4df95bcSnibble.max len = ARRAY_SIZE(m88rs6000_dvbs_init_reg_vals); 428f4df95bcSnibble.max init = m88rs6000_dvbs_init_reg_vals; 429f4df95bcSnibble.max } else { 430f4df95bcSnibble.max len = ARRAY_SIZE(m88ds3103_dvbs_init_reg_vals); 431f4df95bcSnibble.max init = m88ds3103_dvbs_init_reg_vals; 432f4df95bcSnibble.max } 433f4df95bcSnibble.max break; 434f4df95bcSnibble.max case SYS_DVBS2: 4357978b8a1SAntti Palosaari if (dev->chip_id == M88RS6000_CHIP_ID) { 436f4df95bcSnibble.max len = ARRAY_SIZE(m88rs6000_dvbs2_init_reg_vals); 437f4df95bcSnibble.max init = m88rs6000_dvbs2_init_reg_vals; 438f4df95bcSnibble.max } else { 439f4df95bcSnibble.max len = ARRAY_SIZE(m88ds3103_dvbs2_init_reg_vals); 440f4df95bcSnibble.max init = m88ds3103_dvbs2_init_reg_vals; 441f4df95bcSnibble.max } 442395d00d1SAntti Palosaari break; 443395d00d1SAntti Palosaari default: 4447978b8a1SAntti Palosaari dev_dbg(&client->dev, "invalid delivery_system\n"); 445395d00d1SAntti Palosaari ret = -EINVAL; 446395d00d1SAntti Palosaari goto err; 447395d00d1SAntti Palosaari } 448395d00d1SAntti Palosaari 449395d00d1SAntti Palosaari /* program init table */ 4507978b8a1SAntti Palosaari if (c->delivery_system != dev->delivery_system) { 4517978b8a1SAntti Palosaari ret = m88ds3103_wr_reg_val_tab(dev, init, len); 452395d00d1SAntti Palosaari if (ret) 453395d00d1SAntti Palosaari goto err; 454395d00d1SAntti Palosaari } 455395d00d1SAntti Palosaari 4567978b8a1SAntti Palosaari if (dev->chip_id == M88RS6000_CHIP_ID) { 457f5d9b88dSAntti Palosaari if (c->delivery_system == SYS_DVBS2 && 458f5d9b88dSAntti Palosaari c->symbol_rate <= 5000000) { 459478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xc0, 0x04); 460f4df95bcSnibble.max if (ret) 461f4df95bcSnibble.max goto err; 462f4df95bcSnibble.max buf[0] = 0x09; 463f4df95bcSnibble.max buf[1] = 0x22; 464f4df95bcSnibble.max buf[2] = 0x88; 465478932b1SAntti Palosaari ret = regmap_bulk_write(dev->regmap, 0x8a, buf, 3); 466f4df95bcSnibble.max if (ret) 467f4df95bcSnibble.max goto err; 468f4df95bcSnibble.max } 46956ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x9d, 0x08, 0x08); 470f4df95bcSnibble.max if (ret) 471f4df95bcSnibble.max goto err; 472478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xf1, 0x01); 473f4df95bcSnibble.max if (ret) 474f4df95bcSnibble.max goto err; 47556ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x30, 0x80, 0x80); 476f4df95bcSnibble.max if (ret) 477f4df95bcSnibble.max goto err; 478f4df95bcSnibble.max } 479f4df95bcSnibble.max 4807978b8a1SAntti Palosaari switch (dev->cfg->ts_mode) { 481395d00d1SAntti Palosaari case M88DS3103_TS_SERIAL: 482395d00d1SAntti Palosaari u8tmp1 = 0x00; 48379d09330Snibble.max u8tmp = 0x06; 484395d00d1SAntti Palosaari break; 485395d00d1SAntti Palosaari case M88DS3103_TS_SERIAL_D7: 486395d00d1SAntti Palosaari u8tmp1 = 0x20; 48779d09330Snibble.max u8tmp = 0x06; 488395d00d1SAntti Palosaari break; 489395d00d1SAntti Palosaari case M88DS3103_TS_PARALLEL: 49079d09330Snibble.max u8tmp = 0x02; 491395d00d1SAntti Palosaari break; 492395d00d1SAntti Palosaari case M88DS3103_TS_CI: 49379d09330Snibble.max u8tmp = 0x03; 494395d00d1SAntti Palosaari break; 495395d00d1SAntti Palosaari default: 4967978b8a1SAntti Palosaari dev_dbg(&client->dev, "invalid ts_mode\n"); 497395d00d1SAntti Palosaari ret = -EINVAL; 498395d00d1SAntti Palosaari goto err; 499395d00d1SAntti Palosaari } 500395d00d1SAntti Palosaari 5017978b8a1SAntti Palosaari if (dev->cfg->ts_clk_pol) 50279d09330Snibble.max u8tmp |= 0x40; 50379d09330Snibble.max 504395d00d1SAntti Palosaari /* TS mode */ 505478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xfd, u8tmp); 506395d00d1SAntti Palosaari if (ret) 507395d00d1SAntti Palosaari goto err; 508395d00d1SAntti Palosaari 5097978b8a1SAntti Palosaari switch (dev->cfg->ts_mode) { 510395d00d1SAntti Palosaari case M88DS3103_TS_SERIAL: 511395d00d1SAntti Palosaari case M88DS3103_TS_SERIAL_D7: 51256ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x29, 0x20, u8tmp1); 513395d00d1SAntti Palosaari if (ret) 514395d00d1SAntti Palosaari goto err; 515334ef18eSAntti Palosaari u16tmp = 0; 516334ef18eSAntti Palosaari u8tmp1 = 0x3f; 517334ef18eSAntti Palosaari u8tmp2 = 0x3f; 518b6851419Snibble.max break; 519b6851419Snibble.max default: 520334ef18eSAntti Palosaari u16tmp = DIV_ROUND_UP(target_mclk, dev->cfg->ts_clk); 521334ef18eSAntti Palosaari u8tmp1 = u16tmp / 2 - 1; 522334ef18eSAntti Palosaari u8tmp2 = DIV_ROUND_UP(u16tmp, 2) - 1; 523395d00d1SAntti Palosaari } 524395d00d1SAntti Palosaari 525f5d9b88dSAntti Palosaari dev_dbg(&client->dev, "target_mclk=%u ts_clk=%u ts_clk_divide_ratio=%u\n", 526334ef18eSAntti Palosaari target_mclk, dev->cfg->ts_clk, u16tmp); 527395d00d1SAntti Palosaari 528395d00d1SAntti Palosaari /* u8tmp1[5:2] => fe[3:0], u8tmp1[1:0] => ea[7:6] */ 529395d00d1SAntti Palosaari /* u8tmp2[5:0] => ea[5:0] */ 530334ef18eSAntti Palosaari u8tmp = (u8tmp1 >> 2) & 0x0f; 531334ef18eSAntti Palosaari ret = regmap_update_bits(dev->regmap, 0xfe, 0x0f, u8tmp); 532395d00d1SAntti Palosaari if (ret) 533395d00d1SAntti Palosaari goto err; 534395d00d1SAntti Palosaari u8tmp = ((u8tmp1 & 0x03) << 6) | u8tmp2 >> 0; 535478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xea, u8tmp); 536395d00d1SAntti Palosaari if (ret) 537395d00d1SAntti Palosaari goto err; 538395d00d1SAntti Palosaari 539395d00d1SAntti Palosaari if (c->symbol_rate <= 3000000) 540395d00d1SAntti Palosaari u8tmp = 0x20; 541395d00d1SAntti Palosaari else if (c->symbol_rate <= 10000000) 542395d00d1SAntti Palosaari u8tmp = 0x10; 543395d00d1SAntti Palosaari else 544395d00d1SAntti Palosaari u8tmp = 0x06; 545395d00d1SAntti Palosaari 546478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xc3, 0x08); 547395d00d1SAntti Palosaari if (ret) 548395d00d1SAntti Palosaari goto err; 549395d00d1SAntti Palosaari 550478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xc8, u8tmp); 551395d00d1SAntti Palosaari if (ret) 552395d00d1SAntti Palosaari goto err; 553395d00d1SAntti Palosaari 554478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xc4, 0x08); 555395d00d1SAntti Palosaari if (ret) 556395d00d1SAntti Palosaari goto err; 557395d00d1SAntti Palosaari 558478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xc7, 0x00); 559395d00d1SAntti Palosaari if (ret) 560395d00d1SAntti Palosaari goto err; 561395d00d1SAntti Palosaari 562f5d9b88dSAntti Palosaari u16tmp = DIV_ROUND_CLOSEST_ULL((u64)c->symbol_rate * 0x10000, dev->mclk); 563395d00d1SAntti Palosaari buf[0] = (u16tmp >> 0) & 0xff; 564395d00d1SAntti Palosaari buf[1] = (u16tmp >> 8) & 0xff; 565478932b1SAntti Palosaari ret = regmap_bulk_write(dev->regmap, 0x61, buf, 2); 566395d00d1SAntti Palosaari if (ret) 567395d00d1SAntti Palosaari goto err; 568395d00d1SAntti Palosaari 56956ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x4d, 0x02, dev->cfg->spec_inv << 1); 570395d00d1SAntti Palosaari if (ret) 571395d00d1SAntti Palosaari goto err; 572395d00d1SAntti Palosaari 57356ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x30, 0x10, dev->cfg->agc_inv << 4); 574395d00d1SAntti Palosaari if (ret) 575395d00d1SAntti Palosaari goto err; 576395d00d1SAntti Palosaari 577478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0x33, dev->cfg->agc); 578395d00d1SAntti Palosaari if (ret) 579395d00d1SAntti Palosaari goto err; 580395d00d1SAntti Palosaari 5817978b8a1SAntti Palosaari dev_dbg(&client->dev, "carrier offset=%d\n", 582f5d9b88dSAntti Palosaari (tuner_frequency_khz - c->frequency)); 583395d00d1SAntti Palosaari 584f5d9b88dSAntti Palosaari /* Use 32-bit calc as there is no s64 version of DIV_ROUND_CLOSEST() */ 585f5d9b88dSAntti Palosaari s32tmp = 0x10000 * (tuner_frequency_khz - c->frequency); 586f5d9b88dSAntti Palosaari s32tmp = DIV_ROUND_CLOSEST(s32tmp, dev->mclk / 1000); 587395d00d1SAntti Palosaari buf[0] = (s32tmp >> 0) & 0xff; 588395d00d1SAntti Palosaari buf[1] = (s32tmp >> 8) & 0xff; 589478932b1SAntti Palosaari ret = regmap_bulk_write(dev->regmap, 0x5e, buf, 2); 590395d00d1SAntti Palosaari if (ret) 591395d00d1SAntti Palosaari goto err; 592395d00d1SAntti Palosaari 593478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0x00, 0x00); 594395d00d1SAntti Palosaari if (ret) 595395d00d1SAntti Palosaari goto err; 596395d00d1SAntti Palosaari 597478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xb2, 0x00); 598395d00d1SAntti Palosaari if (ret) 599395d00d1SAntti Palosaari goto err; 600395d00d1SAntti Palosaari 6017978b8a1SAntti Palosaari dev->delivery_system = c->delivery_system; 602395d00d1SAntti Palosaari 603395d00d1SAntti Palosaari return 0; 604395d00d1SAntti Palosaari err: 6057978b8a1SAntti Palosaari dev_dbg(&client->dev, "failed=%d\n", ret); 606395d00d1SAntti Palosaari return ret; 607395d00d1SAntti Palosaari } 608395d00d1SAntti Palosaari 609395d00d1SAntti Palosaari static int m88ds3103_init(struct dvb_frontend *fe) 610395d00d1SAntti Palosaari { 6117978b8a1SAntti Palosaari struct m88ds3103_dev *dev = fe->demodulator_priv; 6127978b8a1SAntti Palosaari struct i2c_client *client = dev->client; 613c1daf651SAntti Palosaari struct dtv_frontend_properties *c = &fe->dtv_property_cache; 61460701d5fSAntti Palosaari int ret, len, rem; 615478932b1SAntti Palosaari unsigned int utmp; 61660701d5fSAntti Palosaari const struct firmware *firmware; 61760701d5fSAntti Palosaari const char *name; 61841b9aa00SAntti Palosaari 6197978b8a1SAntti Palosaari dev_dbg(&client->dev, "\n"); 620395d00d1SAntti Palosaari 621395d00d1SAntti Palosaari /* set cold state by default */ 6227978b8a1SAntti Palosaari dev->warm = false; 623395d00d1SAntti Palosaari 624395d00d1SAntti Palosaari /* wake up device from sleep */ 62556ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x08, 0x01, 0x01); 626395d00d1SAntti Palosaari if (ret) 627395d00d1SAntti Palosaari goto err; 62856ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x04, 0x01, 0x00); 629395d00d1SAntti Palosaari if (ret) 630395d00d1SAntti Palosaari goto err; 63156ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x23, 0x10, 0x00); 632395d00d1SAntti Palosaari if (ret) 633395d00d1SAntti Palosaari goto err; 634395d00d1SAntti Palosaari 635395d00d1SAntti Palosaari /* firmware status */ 636478932b1SAntti Palosaari ret = regmap_read(dev->regmap, 0xb9, &utmp); 637395d00d1SAntti Palosaari if (ret) 638395d00d1SAntti Palosaari goto err; 639395d00d1SAntti Palosaari 640478932b1SAntti Palosaari dev_dbg(&client->dev, "firmware=%02x\n", utmp); 641395d00d1SAntti Palosaari 642478932b1SAntti Palosaari if (utmp) 64360701d5fSAntti Palosaari goto warm; 644395d00d1SAntti Palosaari 645f4df95bcSnibble.max /* global reset, global diseqc reset, golbal fec reset */ 646478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0x07, 0xe0); 647f4df95bcSnibble.max if (ret) 648f4df95bcSnibble.max goto err; 649478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0x07, 0x00); 650f4df95bcSnibble.max if (ret) 651f4df95bcSnibble.max goto err; 652f4df95bcSnibble.max 653395d00d1SAntti Palosaari /* cold state - try to download firmware */ 6547978b8a1SAntti Palosaari dev_info(&client->dev, "found a '%s' in cold state\n", 6557978b8a1SAntti Palosaari m88ds3103_ops.info.name); 656395d00d1SAntti Palosaari 6577978b8a1SAntti Palosaari if (dev->chip_id == M88RS6000_CHIP_ID) 65860701d5fSAntti Palosaari name = M88RS6000_FIRMWARE; 659f4df95bcSnibble.max else 66060701d5fSAntti Palosaari name = M88DS3103_FIRMWARE; 661395d00d1SAntti Palosaari /* request the firmware, this will block and timeout */ 66260701d5fSAntti Palosaari ret = request_firmware(&firmware, name, &client->dev); 663395d00d1SAntti Palosaari if (ret) { 66460701d5fSAntti Palosaari dev_err(&client->dev, "firmware file '%s' not found\n", name); 665395d00d1SAntti Palosaari goto err; 666395d00d1SAntti Palosaari } 667395d00d1SAntti Palosaari 66860701d5fSAntti Palosaari dev_info(&client->dev, "downloading firmware from file '%s'\n", name); 669395d00d1SAntti Palosaari 670478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xb2, 0x01); 671395d00d1SAntti Palosaari if (ret) 67260701d5fSAntti Palosaari goto err_release_firmware; 673395d00d1SAntti Palosaari 67460701d5fSAntti Palosaari for (rem = firmware->size; rem > 0; rem -= (dev->cfg->i2c_wr_max - 1)) { 67560701d5fSAntti Palosaari len = min(dev->cfg->i2c_wr_max - 1, rem); 676478932b1SAntti Palosaari ret = regmap_bulk_write(dev->regmap, 0xb0, 67760701d5fSAntti Palosaari &firmware->data[firmware->size - rem], 67860701d5fSAntti Palosaari len); 679395d00d1SAntti Palosaari if (ret) { 68060701d5fSAntti Palosaari dev_err(&client->dev, "firmware download failed %d\n", 6817978b8a1SAntti Palosaari ret); 68260701d5fSAntti Palosaari goto err_release_firmware; 683395d00d1SAntti Palosaari } 684395d00d1SAntti Palosaari } 685395d00d1SAntti Palosaari 686478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xb2, 0x00); 687395d00d1SAntti Palosaari if (ret) 68860701d5fSAntti Palosaari goto err_release_firmware; 689395d00d1SAntti Palosaari 69060701d5fSAntti Palosaari release_firmware(firmware); 691395d00d1SAntti Palosaari 692478932b1SAntti Palosaari ret = regmap_read(dev->regmap, 0xb9, &utmp); 693395d00d1SAntti Palosaari if (ret) 694395d00d1SAntti Palosaari goto err; 695395d00d1SAntti Palosaari 696478932b1SAntti Palosaari if (!utmp) { 69760701d5fSAntti Palosaari ret = -EINVAL; 6987978b8a1SAntti Palosaari dev_info(&client->dev, "firmware did not run\n"); 699395d00d1SAntti Palosaari goto err; 700395d00d1SAntti Palosaari } 701395d00d1SAntti Palosaari 7027978b8a1SAntti Palosaari dev_info(&client->dev, "found a '%s' in warm state\n", 7037978b8a1SAntti Palosaari m88ds3103_ops.info.name); 7047978b8a1SAntti Palosaari dev_info(&client->dev, "firmware version: %X.%X\n", 705478932b1SAntti Palosaari (utmp >> 4) & 0xf, (utmp >> 0 & 0xf)); 706395d00d1SAntti Palosaari 70760701d5fSAntti Palosaari warm: 708395d00d1SAntti Palosaari /* warm state */ 7097978b8a1SAntti Palosaari dev->warm = true; 7107978b8a1SAntti Palosaari 711c1daf651SAntti Palosaari /* init stats here in order signal app which stats are supported */ 712c1daf651SAntti Palosaari c->cnr.len = 1; 713c1daf651SAntti Palosaari c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; 714ce80d713SAntti Palosaari c->post_bit_error.len = 1; 715ce80d713SAntti Palosaari c->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; 716ce80d713SAntti Palosaari c->post_bit_count.len = 1; 717ce80d713SAntti Palosaari c->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE; 718395d00d1SAntti Palosaari 7197978b8a1SAntti Palosaari return 0; 72060701d5fSAntti Palosaari err_release_firmware: 72160701d5fSAntti Palosaari release_firmware(firmware); 7225ed0cf88SMarkus Elfring err: 7237978b8a1SAntti Palosaari dev_dbg(&client->dev, "failed=%d\n", ret); 724395d00d1SAntti Palosaari return ret; 725395d00d1SAntti Palosaari } 726395d00d1SAntti Palosaari 727395d00d1SAntti Palosaari static int m88ds3103_sleep(struct dvb_frontend *fe) 728395d00d1SAntti Palosaari { 7297978b8a1SAntti Palosaari struct m88ds3103_dev *dev = fe->demodulator_priv; 7307978b8a1SAntti Palosaari struct i2c_client *client = dev->client; 731395d00d1SAntti Palosaari int ret; 732478932b1SAntti Palosaari unsigned int utmp; 73341b9aa00SAntti Palosaari 7347978b8a1SAntti Palosaari dev_dbg(&client->dev, "\n"); 735395d00d1SAntti Palosaari 7367978b8a1SAntti Palosaari dev->fe_status = 0; 7377978b8a1SAntti Palosaari dev->delivery_system = SYS_UNDEFINED; 738395d00d1SAntti Palosaari 739395d00d1SAntti Palosaari /* TS Hi-Z */ 7407978b8a1SAntti Palosaari if (dev->chip_id == M88RS6000_CHIP_ID) 741478932b1SAntti Palosaari utmp = 0x29; 742f4df95bcSnibble.max else 743478932b1SAntti Palosaari utmp = 0x27; 74456ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, utmp, 0x01, 0x00); 745395d00d1SAntti Palosaari if (ret) 746395d00d1SAntti Palosaari goto err; 747395d00d1SAntti Palosaari 748395d00d1SAntti Palosaari /* sleep */ 74956ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x08, 0x01, 0x00); 750395d00d1SAntti Palosaari if (ret) 751395d00d1SAntti Palosaari goto err; 75256ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x04, 0x01, 0x01); 753395d00d1SAntti Palosaari if (ret) 754395d00d1SAntti Palosaari goto err; 75556ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x23, 0x10, 0x10); 756395d00d1SAntti Palosaari if (ret) 757395d00d1SAntti Palosaari goto err; 758395d00d1SAntti Palosaari 759395d00d1SAntti Palosaari return 0; 760395d00d1SAntti Palosaari err: 7617978b8a1SAntti Palosaari dev_dbg(&client->dev, "failed=%d\n", ret); 762395d00d1SAntti Palosaari return ret; 763395d00d1SAntti Palosaari } 764395d00d1SAntti Palosaari 7657e3e68bcSMauro Carvalho Chehab static int m88ds3103_get_frontend(struct dvb_frontend *fe, 7667e3e68bcSMauro Carvalho Chehab struct dtv_frontend_properties *c) 767395d00d1SAntti Palosaari { 7687978b8a1SAntti Palosaari struct m88ds3103_dev *dev = fe->demodulator_priv; 7697978b8a1SAntti Palosaari struct i2c_client *client = dev->client; 770395d00d1SAntti Palosaari int ret; 771395d00d1SAntti Palosaari u8 buf[3]; 77241b9aa00SAntti Palosaari 7737978b8a1SAntti Palosaari dev_dbg(&client->dev, "\n"); 774395d00d1SAntti Palosaari 7757978b8a1SAntti Palosaari if (!dev->warm || !(dev->fe_status & FE_HAS_LOCK)) { 7769240c384SAntti Palosaari ret = 0; 777395d00d1SAntti Palosaari goto err; 778395d00d1SAntti Palosaari } 779395d00d1SAntti Palosaari 780395d00d1SAntti Palosaari switch (c->delivery_system) { 781395d00d1SAntti Palosaari case SYS_DVBS: 782478932b1SAntti Palosaari ret = regmap_bulk_read(dev->regmap, 0xe0, &buf[0], 1); 783395d00d1SAntti Palosaari if (ret) 784395d00d1SAntti Palosaari goto err; 785395d00d1SAntti Palosaari 786478932b1SAntti Palosaari ret = regmap_bulk_read(dev->regmap, 0xe6, &buf[1], 1); 787395d00d1SAntti Palosaari if (ret) 788395d00d1SAntti Palosaari goto err; 789395d00d1SAntti Palosaari 790395d00d1SAntti Palosaari switch ((buf[0] >> 2) & 0x01) { 791395d00d1SAntti Palosaari case 0: 792395d00d1SAntti Palosaari c->inversion = INVERSION_OFF; 793395d00d1SAntti Palosaari break; 794395d00d1SAntti Palosaari case 1: 795395d00d1SAntti Palosaari c->inversion = INVERSION_ON; 796395d00d1SAntti Palosaari break; 797395d00d1SAntti Palosaari } 798395d00d1SAntti Palosaari 799395d00d1SAntti Palosaari switch ((buf[1] >> 5) & 0x07) { 800395d00d1SAntti Palosaari case 0: 801395d00d1SAntti Palosaari c->fec_inner = FEC_7_8; 802395d00d1SAntti Palosaari break; 803395d00d1SAntti Palosaari case 1: 804395d00d1SAntti Palosaari c->fec_inner = FEC_5_6; 805395d00d1SAntti Palosaari break; 806395d00d1SAntti Palosaari case 2: 807395d00d1SAntti Palosaari c->fec_inner = FEC_3_4; 808395d00d1SAntti Palosaari break; 809395d00d1SAntti Palosaari case 3: 810395d00d1SAntti Palosaari c->fec_inner = FEC_2_3; 811395d00d1SAntti Palosaari break; 812395d00d1SAntti Palosaari case 4: 813395d00d1SAntti Palosaari c->fec_inner = FEC_1_2; 814395d00d1SAntti Palosaari break; 815395d00d1SAntti Palosaari default: 8167978b8a1SAntti Palosaari dev_dbg(&client->dev, "invalid fec_inner\n"); 817395d00d1SAntti Palosaari } 818395d00d1SAntti Palosaari 819395d00d1SAntti Palosaari c->modulation = QPSK; 820395d00d1SAntti Palosaari 821395d00d1SAntti Palosaari break; 822395d00d1SAntti Palosaari case SYS_DVBS2: 823478932b1SAntti Palosaari ret = regmap_bulk_read(dev->regmap, 0x7e, &buf[0], 1); 824395d00d1SAntti Palosaari if (ret) 825395d00d1SAntti Palosaari goto err; 826395d00d1SAntti Palosaari 827478932b1SAntti Palosaari ret = regmap_bulk_read(dev->regmap, 0x89, &buf[1], 1); 828395d00d1SAntti Palosaari if (ret) 829395d00d1SAntti Palosaari goto err; 830395d00d1SAntti Palosaari 831478932b1SAntti Palosaari ret = regmap_bulk_read(dev->regmap, 0xf2, &buf[2], 1); 832395d00d1SAntti Palosaari if (ret) 833395d00d1SAntti Palosaari goto err; 834395d00d1SAntti Palosaari 835395d00d1SAntti Palosaari switch ((buf[0] >> 0) & 0x0f) { 836395d00d1SAntti Palosaari case 2: 837395d00d1SAntti Palosaari c->fec_inner = FEC_2_5; 838395d00d1SAntti Palosaari break; 839395d00d1SAntti Palosaari case 3: 840395d00d1SAntti Palosaari c->fec_inner = FEC_1_2; 841395d00d1SAntti Palosaari break; 842395d00d1SAntti Palosaari case 4: 843395d00d1SAntti Palosaari c->fec_inner = FEC_3_5; 844395d00d1SAntti Palosaari break; 845395d00d1SAntti Palosaari case 5: 846395d00d1SAntti Palosaari c->fec_inner = FEC_2_3; 847395d00d1SAntti Palosaari break; 848395d00d1SAntti Palosaari case 6: 849395d00d1SAntti Palosaari c->fec_inner = FEC_3_4; 850395d00d1SAntti Palosaari break; 851395d00d1SAntti Palosaari case 7: 852395d00d1SAntti Palosaari c->fec_inner = FEC_4_5; 853395d00d1SAntti Palosaari break; 854395d00d1SAntti Palosaari case 8: 855395d00d1SAntti Palosaari c->fec_inner = FEC_5_6; 856395d00d1SAntti Palosaari break; 857395d00d1SAntti Palosaari case 9: 858395d00d1SAntti Palosaari c->fec_inner = FEC_8_9; 859395d00d1SAntti Palosaari break; 860395d00d1SAntti Palosaari case 10: 861395d00d1SAntti Palosaari c->fec_inner = FEC_9_10; 862395d00d1SAntti Palosaari break; 863395d00d1SAntti Palosaari default: 8647978b8a1SAntti Palosaari dev_dbg(&client->dev, "invalid fec_inner\n"); 865395d00d1SAntti Palosaari } 866395d00d1SAntti Palosaari 867395d00d1SAntti Palosaari switch ((buf[0] >> 5) & 0x01) { 868395d00d1SAntti Palosaari case 0: 869395d00d1SAntti Palosaari c->pilot = PILOT_OFF; 870395d00d1SAntti Palosaari break; 871395d00d1SAntti Palosaari case 1: 872395d00d1SAntti Palosaari c->pilot = PILOT_ON; 873395d00d1SAntti Palosaari break; 874395d00d1SAntti Palosaari } 875395d00d1SAntti Palosaari 876395d00d1SAntti Palosaari switch ((buf[0] >> 6) & 0x07) { 877395d00d1SAntti Palosaari case 0: 878395d00d1SAntti Palosaari c->modulation = QPSK; 879395d00d1SAntti Palosaari break; 880395d00d1SAntti Palosaari case 1: 881395d00d1SAntti Palosaari c->modulation = PSK_8; 882395d00d1SAntti Palosaari break; 883395d00d1SAntti Palosaari case 2: 884395d00d1SAntti Palosaari c->modulation = APSK_16; 885395d00d1SAntti Palosaari break; 886395d00d1SAntti Palosaari case 3: 887395d00d1SAntti Palosaari c->modulation = APSK_32; 888395d00d1SAntti Palosaari break; 889395d00d1SAntti Palosaari default: 8907978b8a1SAntti Palosaari dev_dbg(&client->dev, "invalid modulation\n"); 891395d00d1SAntti Palosaari } 892395d00d1SAntti Palosaari 893395d00d1SAntti Palosaari switch ((buf[1] >> 7) & 0x01) { 894395d00d1SAntti Palosaari case 0: 895395d00d1SAntti Palosaari c->inversion = INVERSION_OFF; 896395d00d1SAntti Palosaari break; 897395d00d1SAntti Palosaari case 1: 898395d00d1SAntti Palosaari c->inversion = INVERSION_ON; 899395d00d1SAntti Palosaari break; 900395d00d1SAntti Palosaari } 901395d00d1SAntti Palosaari 902395d00d1SAntti Palosaari switch ((buf[2] >> 0) & 0x03) { 903395d00d1SAntti Palosaari case 0: 904395d00d1SAntti Palosaari c->rolloff = ROLLOFF_35; 905395d00d1SAntti Palosaari break; 906395d00d1SAntti Palosaari case 1: 907395d00d1SAntti Palosaari c->rolloff = ROLLOFF_25; 908395d00d1SAntti Palosaari break; 909395d00d1SAntti Palosaari case 2: 910395d00d1SAntti Palosaari c->rolloff = ROLLOFF_20; 911395d00d1SAntti Palosaari break; 912395d00d1SAntti Palosaari default: 9137978b8a1SAntti Palosaari dev_dbg(&client->dev, "invalid rolloff\n"); 914395d00d1SAntti Palosaari } 915395d00d1SAntti Palosaari break; 916395d00d1SAntti Palosaari default: 9177978b8a1SAntti Palosaari dev_dbg(&client->dev, "invalid delivery_system\n"); 918395d00d1SAntti Palosaari ret = -EINVAL; 919395d00d1SAntti Palosaari goto err; 920395d00d1SAntti Palosaari } 921395d00d1SAntti Palosaari 922478932b1SAntti Palosaari ret = regmap_bulk_read(dev->regmap, 0x6d, buf, 2); 923395d00d1SAntti Palosaari if (ret) 924395d00d1SAntti Palosaari goto err; 925395d00d1SAntti Palosaari 926f5d9b88dSAntti Palosaari c->symbol_rate = DIV_ROUND_CLOSEST_ULL((u64)(buf[1] << 8 | buf[0] << 0) * dev->mclk, 0x10000); 927395d00d1SAntti Palosaari 928395d00d1SAntti Palosaari return 0; 929395d00d1SAntti Palosaari err: 9307978b8a1SAntti Palosaari dev_dbg(&client->dev, "failed=%d\n", ret); 931395d00d1SAntti Palosaari return ret; 932395d00d1SAntti Palosaari } 933395d00d1SAntti Palosaari 934395d00d1SAntti Palosaari static int m88ds3103_read_snr(struct dvb_frontend *fe, u16 *snr) 935395d00d1SAntti Palosaari { 936395d00d1SAntti Palosaari struct dtv_frontend_properties *c = &fe->dtv_property_cache; 93741b9aa00SAntti Palosaari 938c1daf651SAntti Palosaari if (c->cnr.stat[0].scale == FE_SCALE_DECIBEL) 939c1daf651SAntti Palosaari *snr = div_s64(c->cnr.stat[0].svalue, 100); 940395d00d1SAntti Palosaari else 941395d00d1SAntti Palosaari *snr = 0; 942395d00d1SAntti Palosaari 943395d00d1SAntti Palosaari return 0; 944395d00d1SAntti Palosaari } 945395d00d1SAntti Palosaari 9464423a2baSAntti Palosaari static int m88ds3103_read_ber(struct dvb_frontend *fe, u32 *ber) 9474423a2baSAntti Palosaari { 9487978b8a1SAntti Palosaari struct m88ds3103_dev *dev = fe->demodulator_priv; 94941b9aa00SAntti Palosaari 9507978b8a1SAntti Palosaari *ber = dev->dvbv3_ber; 9514423a2baSAntti Palosaari 9524423a2baSAntti Palosaari return 0; 9534423a2baSAntti Palosaari } 954395d00d1SAntti Palosaari 955395d00d1SAntti Palosaari static int m88ds3103_set_tone(struct dvb_frontend *fe, 9560df289a2SMauro Carvalho Chehab enum fe_sec_tone_mode fe_sec_tone_mode) 957395d00d1SAntti Palosaari { 9587978b8a1SAntti Palosaari struct m88ds3103_dev *dev = fe->demodulator_priv; 9597978b8a1SAntti Palosaari struct i2c_client *client = dev->client; 960395d00d1SAntti Palosaari int ret; 961478932b1SAntti Palosaari unsigned int utmp, tone, reg_a1_mask; 96241b9aa00SAntti Palosaari 9637978b8a1SAntti Palosaari dev_dbg(&client->dev, "fe_sec_tone_mode=%d\n", fe_sec_tone_mode); 964395d00d1SAntti Palosaari 9657978b8a1SAntti Palosaari if (!dev->warm) { 966395d00d1SAntti Palosaari ret = -EAGAIN; 967395d00d1SAntti Palosaari goto err; 968395d00d1SAntti Palosaari } 969395d00d1SAntti Palosaari 970395d00d1SAntti Palosaari switch (fe_sec_tone_mode) { 971395d00d1SAntti Palosaari case SEC_TONE_ON: 972395d00d1SAntti Palosaari tone = 0; 973418a97cbSAntti Palosaari reg_a1_mask = 0x47; 974395d00d1SAntti Palosaari break; 975395d00d1SAntti Palosaari case SEC_TONE_OFF: 976395d00d1SAntti Palosaari tone = 1; 977395d00d1SAntti Palosaari reg_a1_mask = 0x00; 978395d00d1SAntti Palosaari break; 979395d00d1SAntti Palosaari default: 9807978b8a1SAntti Palosaari dev_dbg(&client->dev, "invalid fe_sec_tone_mode\n"); 981395d00d1SAntti Palosaari ret = -EINVAL; 982395d00d1SAntti Palosaari goto err; 983395d00d1SAntti Palosaari } 984395d00d1SAntti Palosaari 985478932b1SAntti Palosaari utmp = tone << 7 | dev->cfg->envelope_mode << 5; 98656ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0xa2, 0xe0, utmp); 987395d00d1SAntti Palosaari if (ret) 988395d00d1SAntti Palosaari goto err; 989395d00d1SAntti Palosaari 990478932b1SAntti Palosaari utmp = 1 << 2; 99156ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0xa1, reg_a1_mask, utmp); 992395d00d1SAntti Palosaari if (ret) 993395d00d1SAntti Palosaari goto err; 994395d00d1SAntti Palosaari 995395d00d1SAntti Palosaari return 0; 996395d00d1SAntti Palosaari err: 9977978b8a1SAntti Palosaari dev_dbg(&client->dev, "failed=%d\n", ret); 998395d00d1SAntti Palosaari return ret; 999395d00d1SAntti Palosaari } 1000395d00d1SAntti Palosaari 100179d09330Snibble.max static int m88ds3103_set_voltage(struct dvb_frontend *fe, 10020df289a2SMauro Carvalho Chehab enum fe_sec_voltage fe_sec_voltage) 100379d09330Snibble.max { 10047978b8a1SAntti Palosaari struct m88ds3103_dev *dev = fe->demodulator_priv; 10057978b8a1SAntti Palosaari struct i2c_client *client = dev->client; 1006d28677ffSAntti Palosaari int ret; 1007478932b1SAntti Palosaari unsigned int utmp; 1008d28677ffSAntti Palosaari bool voltage_sel, voltage_dis; 100979d09330Snibble.max 10107978b8a1SAntti Palosaari dev_dbg(&client->dev, "fe_sec_voltage=%d\n", fe_sec_voltage); 101179d09330Snibble.max 10127978b8a1SAntti Palosaari if (!dev->warm) { 1013d28677ffSAntti Palosaari ret = -EAGAIN; 1014d28677ffSAntti Palosaari goto err; 1015d28677ffSAntti Palosaari } 101679d09330Snibble.max 1017d28677ffSAntti Palosaari switch (fe_sec_voltage) { 101879d09330Snibble.max case SEC_VOLTAGE_18: 1019afbd6eb4SMauro Carvalho Chehab voltage_sel = true; 1020afbd6eb4SMauro Carvalho Chehab voltage_dis = false; 102179d09330Snibble.max break; 102279d09330Snibble.max case SEC_VOLTAGE_13: 1023afbd6eb4SMauro Carvalho Chehab voltage_sel = false; 1024afbd6eb4SMauro Carvalho Chehab voltage_dis = false; 102579d09330Snibble.max break; 102679d09330Snibble.max case SEC_VOLTAGE_OFF: 1027afbd6eb4SMauro Carvalho Chehab voltage_sel = false; 1028afbd6eb4SMauro Carvalho Chehab voltage_dis = true; 102979d09330Snibble.max break; 1030d28677ffSAntti Palosaari default: 10317978b8a1SAntti Palosaari dev_dbg(&client->dev, "invalid fe_sec_voltage\n"); 1032d28677ffSAntti Palosaari ret = -EINVAL; 1033d28677ffSAntti Palosaari goto err; 103479d09330Snibble.max } 1035d28677ffSAntti Palosaari 1036d28677ffSAntti Palosaari /* output pin polarity */ 10377978b8a1SAntti Palosaari voltage_sel ^= dev->cfg->lnb_hv_pol; 10387978b8a1SAntti Palosaari voltage_dis ^= dev->cfg->lnb_en_pol; 1039d28677ffSAntti Palosaari 1040478932b1SAntti Palosaari utmp = voltage_dis << 1 | voltage_sel << 0; 104156ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0xa2, 0x03, utmp); 1042d28677ffSAntti Palosaari if (ret) 1043d28677ffSAntti Palosaari goto err; 104479d09330Snibble.max 104579d09330Snibble.max return 0; 1046d28677ffSAntti Palosaari err: 10477978b8a1SAntti Palosaari dev_dbg(&client->dev, "failed=%d\n", ret); 1048d28677ffSAntti Palosaari return ret; 104979d09330Snibble.max } 105079d09330Snibble.max 1051395d00d1SAntti Palosaari static int m88ds3103_diseqc_send_master_cmd(struct dvb_frontend *fe, 1052395d00d1SAntti Palosaari struct dvb_diseqc_master_cmd *diseqc_cmd) 1053395d00d1SAntti Palosaari { 10547978b8a1SAntti Palosaari struct m88ds3103_dev *dev = fe->demodulator_priv; 10557978b8a1SAntti Palosaari struct i2c_client *client = dev->client; 1056befa0cc1SAntti Palosaari int ret; 1057478932b1SAntti Palosaari unsigned int utmp; 1058befa0cc1SAntti Palosaari unsigned long timeout; 105941b9aa00SAntti Palosaari 10607978b8a1SAntti Palosaari dev_dbg(&client->dev, "msg=%*ph\n", 1061395d00d1SAntti Palosaari diseqc_cmd->msg_len, diseqc_cmd->msg); 1062395d00d1SAntti Palosaari 10637978b8a1SAntti Palosaari if (!dev->warm) { 1064395d00d1SAntti Palosaari ret = -EAGAIN; 1065395d00d1SAntti Palosaari goto err; 1066395d00d1SAntti Palosaari } 1067395d00d1SAntti Palosaari 1068395d00d1SAntti Palosaari if (diseqc_cmd->msg_len < 3 || diseqc_cmd->msg_len > 6) { 1069395d00d1SAntti Palosaari ret = -EINVAL; 1070395d00d1SAntti Palosaari goto err; 1071395d00d1SAntti Palosaari } 1072395d00d1SAntti Palosaari 1073478932b1SAntti Palosaari utmp = dev->cfg->envelope_mode << 5; 107456ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0xa2, 0xe0, utmp); 1075395d00d1SAntti Palosaari if (ret) 1076395d00d1SAntti Palosaari goto err; 1077395d00d1SAntti Palosaari 1078478932b1SAntti Palosaari ret = regmap_bulk_write(dev->regmap, 0xa3, diseqc_cmd->msg, 1079395d00d1SAntti Palosaari diseqc_cmd->msg_len); 1080395d00d1SAntti Palosaari if (ret) 1081395d00d1SAntti Palosaari goto err; 1082395d00d1SAntti Palosaari 1083478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xa1, 1084395d00d1SAntti Palosaari (diseqc_cmd->msg_len - 1) << 3 | 0x07); 1085395d00d1SAntti Palosaari if (ret) 1086395d00d1SAntti Palosaari goto err; 1087395d00d1SAntti Palosaari 1088395d00d1SAntti Palosaari /* wait DiSEqC TX ready */ 1089befa0cc1SAntti Palosaari #define SEND_MASTER_CMD_TIMEOUT 120 1090befa0cc1SAntti Palosaari timeout = jiffies + msecs_to_jiffies(SEND_MASTER_CMD_TIMEOUT); 1091395d00d1SAntti Palosaari 10929ef3cdc1SAntti Palosaari /* DiSEqC message period is 13.5 ms per byte */ 10939ef3cdc1SAntti Palosaari utmp = diseqc_cmd->msg_len * 13500; 10949ef3cdc1SAntti Palosaari usleep_range(utmp - 4000, utmp); 1095befa0cc1SAntti Palosaari 1096478932b1SAntti Palosaari for (utmp = 1; !time_after(jiffies, timeout) && utmp;) { 1097478932b1SAntti Palosaari ret = regmap_read(dev->regmap, 0xa1, &utmp); 1098395d00d1SAntti Palosaari if (ret) 1099395d00d1SAntti Palosaari goto err; 1100478932b1SAntti Palosaari utmp = (utmp >> 6) & 0x1; 1101395d00d1SAntti Palosaari } 1102395d00d1SAntti Palosaari 1103478932b1SAntti Palosaari if (utmp == 0) { 11047978b8a1SAntti Palosaari dev_dbg(&client->dev, "diseqc tx took %u ms\n", 1105befa0cc1SAntti Palosaari jiffies_to_msecs(jiffies) - 1106befa0cc1SAntti Palosaari (jiffies_to_msecs(timeout) - SEND_MASTER_CMD_TIMEOUT)); 1107befa0cc1SAntti Palosaari } else { 11087978b8a1SAntti Palosaari dev_dbg(&client->dev, "diseqc tx timeout\n"); 1109395d00d1SAntti Palosaari 111056ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0xa1, 0xc0, 0x40); 1111395d00d1SAntti Palosaari if (ret) 1112395d00d1SAntti Palosaari goto err; 1113395d00d1SAntti Palosaari } 1114395d00d1SAntti Palosaari 111556ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0xa2, 0xc0, 0x80); 1116395d00d1SAntti Palosaari if (ret) 1117395d00d1SAntti Palosaari goto err; 1118395d00d1SAntti Palosaari 1119478932b1SAntti Palosaari if (utmp == 1) { 1120395d00d1SAntti Palosaari ret = -ETIMEDOUT; 1121395d00d1SAntti Palosaari goto err; 1122395d00d1SAntti Palosaari } 1123395d00d1SAntti Palosaari 1124395d00d1SAntti Palosaari return 0; 1125395d00d1SAntti Palosaari err: 11267978b8a1SAntti Palosaari dev_dbg(&client->dev, "failed=%d\n", ret); 1127395d00d1SAntti Palosaari return ret; 1128395d00d1SAntti Palosaari } 1129395d00d1SAntti Palosaari 1130395d00d1SAntti Palosaari static int m88ds3103_diseqc_send_burst(struct dvb_frontend *fe, 11310df289a2SMauro Carvalho Chehab enum fe_sec_mini_cmd fe_sec_mini_cmd) 1132395d00d1SAntti Palosaari { 11337978b8a1SAntti Palosaari struct m88ds3103_dev *dev = fe->demodulator_priv; 11347978b8a1SAntti Palosaari struct i2c_client *client = dev->client; 1135befa0cc1SAntti Palosaari int ret; 1136478932b1SAntti Palosaari unsigned int utmp, burst; 1137befa0cc1SAntti Palosaari unsigned long timeout; 113841b9aa00SAntti Palosaari 11397978b8a1SAntti Palosaari dev_dbg(&client->dev, "fe_sec_mini_cmd=%d\n", fe_sec_mini_cmd); 1140395d00d1SAntti Palosaari 11417978b8a1SAntti Palosaari if (!dev->warm) { 1142395d00d1SAntti Palosaari ret = -EAGAIN; 1143395d00d1SAntti Palosaari goto err; 1144395d00d1SAntti Palosaari } 1145395d00d1SAntti Palosaari 1146478932b1SAntti Palosaari utmp = dev->cfg->envelope_mode << 5; 114756ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0xa2, 0xe0, utmp); 1148395d00d1SAntti Palosaari if (ret) 1149395d00d1SAntti Palosaari goto err; 1150395d00d1SAntti Palosaari 1151395d00d1SAntti Palosaari switch (fe_sec_mini_cmd) { 1152395d00d1SAntti Palosaari case SEC_MINI_A: 1153395d00d1SAntti Palosaari burst = 0x02; 1154395d00d1SAntti Palosaari break; 1155395d00d1SAntti Palosaari case SEC_MINI_B: 1156395d00d1SAntti Palosaari burst = 0x01; 1157395d00d1SAntti Palosaari break; 1158395d00d1SAntti Palosaari default: 11597978b8a1SAntti Palosaari dev_dbg(&client->dev, "invalid fe_sec_mini_cmd\n"); 1160395d00d1SAntti Palosaari ret = -EINVAL; 1161395d00d1SAntti Palosaari goto err; 1162395d00d1SAntti Palosaari } 1163395d00d1SAntti Palosaari 1164478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xa1, burst); 1165395d00d1SAntti Palosaari if (ret) 1166395d00d1SAntti Palosaari goto err; 1167395d00d1SAntti Palosaari 1168395d00d1SAntti Palosaari /* wait DiSEqC TX ready */ 1169befa0cc1SAntti Palosaari #define SEND_BURST_TIMEOUT 40 1170befa0cc1SAntti Palosaari timeout = jiffies + msecs_to_jiffies(SEND_BURST_TIMEOUT); 1171395d00d1SAntti Palosaari 1172befa0cc1SAntti Palosaari /* DiSEqC ToneBurst period is 12.5 ms */ 1173befa0cc1SAntti Palosaari usleep_range(8500, 12500); 1174befa0cc1SAntti Palosaari 1175478932b1SAntti Palosaari for (utmp = 1; !time_after(jiffies, timeout) && utmp;) { 1176478932b1SAntti Palosaari ret = regmap_read(dev->regmap, 0xa1, &utmp); 1177395d00d1SAntti Palosaari if (ret) 1178395d00d1SAntti Palosaari goto err; 1179478932b1SAntti Palosaari utmp = (utmp >> 6) & 0x1; 1180395d00d1SAntti Palosaari } 1181395d00d1SAntti Palosaari 1182478932b1SAntti Palosaari if (utmp == 0) { 11837978b8a1SAntti Palosaari dev_dbg(&client->dev, "diseqc tx took %u ms\n", 1184befa0cc1SAntti Palosaari jiffies_to_msecs(jiffies) - 1185befa0cc1SAntti Palosaari (jiffies_to_msecs(timeout) - SEND_BURST_TIMEOUT)); 1186befa0cc1SAntti Palosaari } else { 11877978b8a1SAntti Palosaari dev_dbg(&client->dev, "diseqc tx timeout\n"); 1188befa0cc1SAntti Palosaari 118956ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0xa1, 0xc0, 0x40); 1190befa0cc1SAntti Palosaari if (ret) 1191befa0cc1SAntti Palosaari goto err; 1192befa0cc1SAntti Palosaari } 1193395d00d1SAntti Palosaari 119456ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0xa2, 0xc0, 0x80); 1195395d00d1SAntti Palosaari if (ret) 1196395d00d1SAntti Palosaari goto err; 1197395d00d1SAntti Palosaari 1198478932b1SAntti Palosaari if (utmp == 1) { 1199395d00d1SAntti Palosaari ret = -ETIMEDOUT; 1200395d00d1SAntti Palosaari goto err; 1201395d00d1SAntti Palosaari } 1202395d00d1SAntti Palosaari 1203395d00d1SAntti Palosaari return 0; 1204395d00d1SAntti Palosaari err: 12057978b8a1SAntti Palosaari dev_dbg(&client->dev, "failed=%d\n", ret); 1206395d00d1SAntti Palosaari return ret; 1207395d00d1SAntti Palosaari } 1208395d00d1SAntti Palosaari 1209395d00d1SAntti Palosaari static int m88ds3103_get_tune_settings(struct dvb_frontend *fe, 1210395d00d1SAntti Palosaari struct dvb_frontend_tune_settings *s) 1211395d00d1SAntti Palosaari { 1212395d00d1SAntti Palosaari s->min_delay_ms = 3000; 1213395d00d1SAntti Palosaari 1214395d00d1SAntti Palosaari return 0; 1215395d00d1SAntti Palosaari } 1216395d00d1SAntti Palosaari 121744b9055bSAntti Palosaari static void m88ds3103_release(struct dvb_frontend *fe) 1218395d00d1SAntti Palosaari { 12197978b8a1SAntti Palosaari struct m88ds3103_dev *dev = fe->demodulator_priv; 12207978b8a1SAntti Palosaari struct i2c_client *client = dev->client; 122141b9aa00SAntti Palosaari 1222f01919e8SAntti Palosaari i2c_unregister_device(client); 1223395d00d1SAntti Palosaari } 1224395d00d1SAntti Palosaari 1225e00fed40SPeter Rosin static int m88ds3103_select(struct i2c_mux_core *muxc, u32 chan) 1226395d00d1SAntti Palosaari { 1227e00fed40SPeter Rosin struct m88ds3103_dev *dev = i2c_mux_priv(muxc); 12287978b8a1SAntti Palosaari struct i2c_client *client = dev->client; 1229395d00d1SAntti Palosaari int ret; 1230478932b1SAntti Palosaari struct i2c_msg msg = { 12317978b8a1SAntti Palosaari .addr = client->addr, 1232395d00d1SAntti Palosaari .flags = 0, 1233395d00d1SAntti Palosaari .len = 2, 1234395d00d1SAntti Palosaari .buf = "\x03\x11", 1235395d00d1SAntti Palosaari }; 1236395d00d1SAntti Palosaari 1237478932b1SAntti Palosaari /* Open tuner I2C repeater for 1 xfer, closes automatically */ 1238478932b1SAntti Palosaari ret = __i2c_transfer(client->adapter, &msg, 1); 1239395d00d1SAntti Palosaari if (ret != 1) { 12407978b8a1SAntti Palosaari dev_warn(&client->dev, "i2c wr failed=%d\n", ret); 124144b9055bSAntti Palosaari if (ret >= 0) 1242395d00d1SAntti Palosaari ret = -EREMOTEIO; 1243395d00d1SAntti Palosaari return ret; 1244395d00d1SAntti Palosaari } 1245395d00d1SAntti Palosaari 124644b9055bSAntti Palosaari return 0; 124744b9055bSAntti Palosaari } 1248395d00d1SAntti Palosaari 1249f01919e8SAntti Palosaari /* 1250f01919e8SAntti Palosaari * XXX: That is wrapper to m88ds3103_probe() via driver core in order to provide 1251f01919e8SAntti Palosaari * proper I2C client for legacy media attach binding. 1252f01919e8SAntti Palosaari * New users must use I2C client binding directly! 1253f01919e8SAntti Palosaari */ 1254395d00d1SAntti Palosaari struct dvb_frontend *m88ds3103_attach(const struct m88ds3103_config *cfg, 1255b9c97c67SMauro Carvalho Chehab struct i2c_adapter *i2c, 1256b9c97c67SMauro Carvalho Chehab struct i2c_adapter **tuner_i2c_adapter) 1257395d00d1SAntti Palosaari { 1258f01919e8SAntti Palosaari struct i2c_client *client; 1259f01919e8SAntti Palosaari struct i2c_board_info board_info; 1260b9c97c67SMauro Carvalho Chehab struct m88ds3103_platform_data pdata = {}; 1261395d00d1SAntti Palosaari 1262f01919e8SAntti Palosaari pdata.clk = cfg->clock; 1263f01919e8SAntti Palosaari pdata.i2c_wr_max = cfg->i2c_wr_max; 1264f01919e8SAntti Palosaari pdata.ts_mode = cfg->ts_mode; 1265f01919e8SAntti Palosaari pdata.ts_clk = cfg->ts_clk; 1266f01919e8SAntti Palosaari pdata.ts_clk_pol = cfg->ts_clk_pol; 1267f01919e8SAntti Palosaari pdata.spec_inv = cfg->spec_inv; 1268f01919e8SAntti Palosaari pdata.agc = cfg->agc; 1269f01919e8SAntti Palosaari pdata.agc_inv = cfg->agc_inv; 1270f01919e8SAntti Palosaari pdata.clk_out = cfg->clock_out; 1271f01919e8SAntti Palosaari pdata.envelope_mode = cfg->envelope_mode; 1272f01919e8SAntti Palosaari pdata.lnb_hv_pol = cfg->lnb_hv_pol; 1273f01919e8SAntti Palosaari pdata.lnb_en_pol = cfg->lnb_en_pol; 1274f01919e8SAntti Palosaari pdata.attach_in_use = true; 1275395d00d1SAntti Palosaari 1276f01919e8SAntti Palosaari memset(&board_info, 0, sizeof(board_info)); 1277c0decac1SMauro Carvalho Chehab strscpy(board_info.type, "m88ds3103", I2C_NAME_SIZE); 1278f01919e8SAntti Palosaari board_info.addr = cfg->i2c_addr; 1279f01919e8SAntti Palosaari board_info.platform_data = &pdata; 1280aace5926SWolfram Sang client = i2c_new_client_device(i2c, &board_info); 1281aace5926SWolfram Sang if (!i2c_client_has_driver(client)) 1282395d00d1SAntti Palosaari return NULL; 1283f01919e8SAntti Palosaari 1284f01919e8SAntti Palosaari *tuner_i2c_adapter = pdata.get_i2c_adapter(client); 1285f01919e8SAntti Palosaari return pdata.get_dvb_frontend(client); 1286395d00d1SAntti Palosaari } 1287395d00d1SAntti Palosaari EXPORT_SYMBOL(m88ds3103_attach); 1288395d00d1SAntti Palosaari 1289bd336e63SMax Kellermann static const struct dvb_frontend_ops m88ds3103_ops = { 1290395d00d1SAntti Palosaari .delsys = {SYS_DVBS, SYS_DVBS2}, 1291395d00d1SAntti Palosaari .info = { 12927978b8a1SAntti Palosaari .name = "Montage Technology M88DS3103", 1293f1b1eabfSMauro Carvalho Chehab .frequency_min_hz = 950 * MHz, 1294f1b1eabfSMauro Carvalho Chehab .frequency_max_hz = 2150 * MHz, 1295f1b1eabfSMauro Carvalho Chehab .frequency_tolerance_hz = 5 * MHz, 1296395d00d1SAntti Palosaari .symbol_rate_min = 1000000, 1297395d00d1SAntti Palosaari .symbol_rate_max = 45000000, 1298395d00d1SAntti Palosaari .caps = FE_CAN_INVERSION_AUTO | 1299395d00d1SAntti Palosaari FE_CAN_FEC_1_2 | 1300395d00d1SAntti Palosaari FE_CAN_FEC_2_3 | 1301395d00d1SAntti Palosaari FE_CAN_FEC_3_4 | 1302395d00d1SAntti Palosaari FE_CAN_FEC_4_5 | 1303395d00d1SAntti Palosaari FE_CAN_FEC_5_6 | 1304395d00d1SAntti Palosaari FE_CAN_FEC_6_7 | 1305395d00d1SAntti Palosaari FE_CAN_FEC_7_8 | 1306395d00d1SAntti Palosaari FE_CAN_FEC_8_9 | 1307395d00d1SAntti Palosaari FE_CAN_FEC_AUTO | 1308395d00d1SAntti Palosaari FE_CAN_QPSK | 1309395d00d1SAntti Palosaari FE_CAN_RECOVER | 1310395d00d1SAntti Palosaari FE_CAN_2G_MODULATION 1311395d00d1SAntti Palosaari }, 1312395d00d1SAntti Palosaari 1313395d00d1SAntti Palosaari .release = m88ds3103_release, 1314395d00d1SAntti Palosaari 1315395d00d1SAntti Palosaari .get_tune_settings = m88ds3103_get_tune_settings, 1316395d00d1SAntti Palosaari 1317395d00d1SAntti Palosaari .init = m88ds3103_init, 1318395d00d1SAntti Palosaari .sleep = m88ds3103_sleep, 1319395d00d1SAntti Palosaari 1320395d00d1SAntti Palosaari .set_frontend = m88ds3103_set_frontend, 1321395d00d1SAntti Palosaari .get_frontend = m88ds3103_get_frontend, 1322395d00d1SAntti Palosaari 1323395d00d1SAntti Palosaari .read_status = m88ds3103_read_status, 1324395d00d1SAntti Palosaari .read_snr = m88ds3103_read_snr, 13254423a2baSAntti Palosaari .read_ber = m88ds3103_read_ber, 1326395d00d1SAntti Palosaari 1327395d00d1SAntti Palosaari .diseqc_send_master_cmd = m88ds3103_diseqc_send_master_cmd, 1328395d00d1SAntti Palosaari .diseqc_send_burst = m88ds3103_diseqc_send_burst, 1329395d00d1SAntti Palosaari 1330395d00d1SAntti Palosaari .set_tone = m88ds3103_set_tone, 133179d09330Snibble.max .set_voltage = m88ds3103_set_voltage, 1332395d00d1SAntti Palosaari }; 1333395d00d1SAntti Palosaari 1334f01919e8SAntti Palosaari static struct dvb_frontend *m88ds3103_get_dvb_frontend(struct i2c_client *client) 1335f01919e8SAntti Palosaari { 13367978b8a1SAntti Palosaari struct m88ds3103_dev *dev = i2c_get_clientdata(client); 1337f01919e8SAntti Palosaari 1338f01919e8SAntti Palosaari dev_dbg(&client->dev, "\n"); 1339f01919e8SAntti Palosaari 1340f01919e8SAntti Palosaari return &dev->fe; 1341f01919e8SAntti Palosaari } 1342f01919e8SAntti Palosaari 1343f01919e8SAntti Palosaari static struct i2c_adapter *m88ds3103_get_i2c_adapter(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 1349e00fed40SPeter Rosin return dev->muxc->adapter[0]; 1350f01919e8SAntti Palosaari } 1351f01919e8SAntti Palosaari 1352f01919e8SAntti Palosaari static int m88ds3103_probe(struct i2c_client *client, 1353f01919e8SAntti Palosaari const struct i2c_device_id *id) 1354f01919e8SAntti Palosaari { 13557978b8a1SAntti Palosaari struct m88ds3103_dev *dev; 1356f01919e8SAntti Palosaari struct m88ds3103_platform_data *pdata = client->dev.platform_data; 1357f01919e8SAntti Palosaari int ret; 1358478932b1SAntti Palosaari unsigned int utmp; 1359f01919e8SAntti Palosaari 1360f01919e8SAntti Palosaari dev = kzalloc(sizeof(*dev), GFP_KERNEL); 1361f01919e8SAntti Palosaari if (!dev) { 1362f01919e8SAntti Palosaari ret = -ENOMEM; 1363f01919e8SAntti Palosaari goto err; 1364f01919e8SAntti Palosaari } 1365f01919e8SAntti Palosaari 1366f01919e8SAntti Palosaari dev->client = client; 1367f01919e8SAntti Palosaari dev->config.clock = pdata->clk; 1368f01919e8SAntti Palosaari dev->config.i2c_wr_max = pdata->i2c_wr_max; 1369f01919e8SAntti Palosaari dev->config.ts_mode = pdata->ts_mode; 1370f5d9b88dSAntti Palosaari dev->config.ts_clk = pdata->ts_clk * 1000; 1371f01919e8SAntti Palosaari dev->config.ts_clk_pol = pdata->ts_clk_pol; 1372f01919e8SAntti Palosaari dev->config.spec_inv = pdata->spec_inv; 1373f01919e8SAntti Palosaari dev->config.agc_inv = pdata->agc_inv; 1374f01919e8SAntti Palosaari dev->config.clock_out = pdata->clk_out; 1375f01919e8SAntti Palosaari dev->config.envelope_mode = pdata->envelope_mode; 1376f01919e8SAntti Palosaari dev->config.agc = pdata->agc; 1377f01919e8SAntti Palosaari dev->config.lnb_hv_pol = pdata->lnb_hv_pol; 1378f01919e8SAntti Palosaari dev->config.lnb_en_pol = pdata->lnb_en_pol; 1379f01919e8SAntti Palosaari dev->cfg = &dev->config; 1380478932b1SAntti Palosaari /* create regmap */ 1381478932b1SAntti Palosaari dev->regmap_config.reg_bits = 8, 1382478932b1SAntti Palosaari dev->regmap_config.val_bits = 8, 1383478932b1SAntti Palosaari dev->regmap_config.lock_arg = dev, 1384478932b1SAntti Palosaari dev->regmap = devm_regmap_init_i2c(client, &dev->regmap_config); 1385478932b1SAntti Palosaari if (IS_ERR(dev->regmap)) { 1386478932b1SAntti Palosaari ret = PTR_ERR(dev->regmap); 1387478932b1SAntti Palosaari goto err_kfree; 1388478932b1SAntti Palosaari } 1389f01919e8SAntti Palosaari 1390f01919e8SAntti Palosaari /* 0x00: chip id[6:0], 0x01: chip ver[7:0], 0x02: chip ver[15:8] */ 1391478932b1SAntti Palosaari ret = regmap_read(dev->regmap, 0x00, &utmp); 1392f01919e8SAntti Palosaari if (ret) 1393f01919e8SAntti Palosaari goto err_kfree; 1394f01919e8SAntti Palosaari 1395478932b1SAntti Palosaari dev->chip_id = utmp >> 1; 1396478932b1SAntti Palosaari dev_dbg(&client->dev, "chip_id=%02x\n", dev->chip_id); 1397f01919e8SAntti Palosaari 1398478932b1SAntti Palosaari switch (dev->chip_id) { 1399f01919e8SAntti Palosaari case M88RS6000_CHIP_ID: 1400f01919e8SAntti Palosaari case M88DS3103_CHIP_ID: 1401f01919e8SAntti Palosaari break; 1402f01919e8SAntti Palosaari default: 1403b9c97c67SMauro Carvalho Chehab ret = -ENODEV; 1404b9c97c67SMauro Carvalho Chehab dev_err(&client->dev, "Unknown device. Chip_id=%02x\n", dev->chip_id); 1405f01919e8SAntti Palosaari goto err_kfree; 1406f01919e8SAntti Palosaari } 1407f01919e8SAntti Palosaari 1408f01919e8SAntti Palosaari switch (dev->cfg->clock_out) { 1409f01919e8SAntti Palosaari case M88DS3103_CLOCK_OUT_DISABLED: 1410478932b1SAntti Palosaari utmp = 0x80; 1411f01919e8SAntti Palosaari break; 1412f01919e8SAntti Palosaari case M88DS3103_CLOCK_OUT_ENABLED: 1413478932b1SAntti Palosaari utmp = 0x00; 1414f01919e8SAntti Palosaari break; 1415f01919e8SAntti Palosaari case M88DS3103_CLOCK_OUT_ENABLED_DIV2: 1416478932b1SAntti Palosaari utmp = 0x10; 1417f01919e8SAntti Palosaari break; 1418f01919e8SAntti Palosaari default: 14194347df6aSDan Carpenter ret = -EINVAL; 1420f01919e8SAntti Palosaari goto err_kfree; 1421f01919e8SAntti Palosaari } 1422f01919e8SAntti Palosaari 1423334ef18eSAntti Palosaari if (!pdata->ts_clk) { 1424334ef18eSAntti Palosaari ret = -EINVAL; 1425334ef18eSAntti Palosaari goto err_kfree; 1426334ef18eSAntti Palosaari } 1427334ef18eSAntti Palosaari 1428f01919e8SAntti Palosaari /* 0x29 register is defined differently for m88rs6000. */ 1429f01919e8SAntti Palosaari /* set internal tuner address to 0x21 */ 1430478932b1SAntti Palosaari if (dev->chip_id == M88RS6000_CHIP_ID) 1431478932b1SAntti Palosaari utmp = 0x00; 1432f01919e8SAntti Palosaari 1433478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0x29, utmp); 1434f01919e8SAntti Palosaari if (ret) 1435f01919e8SAntti Palosaari goto err_kfree; 1436f01919e8SAntti Palosaari 1437f01919e8SAntti Palosaari /* sleep */ 143856ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x08, 0x01, 0x00); 1439f01919e8SAntti Palosaari if (ret) 1440f01919e8SAntti Palosaari goto err_kfree; 144156ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x04, 0x01, 0x01); 1442f01919e8SAntti Palosaari if (ret) 1443f01919e8SAntti Palosaari goto err_kfree; 144456ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x23, 0x10, 0x10); 1445f01919e8SAntti Palosaari if (ret) 1446f01919e8SAntti Palosaari goto err_kfree; 1447f01919e8SAntti Palosaari 1448f01919e8SAntti Palosaari /* create mux i2c adapter for tuner */ 1449e00fed40SPeter Rosin dev->muxc = i2c_mux_alloc(client->adapter, &client->dev, 1, 0, 0, 1450e00fed40SPeter Rosin m88ds3103_select, NULL); 1451e00fed40SPeter Rosin if (!dev->muxc) { 14524347df6aSDan Carpenter ret = -ENOMEM; 1453f01919e8SAntti Palosaari goto err_kfree; 14544347df6aSDan Carpenter } 1455e00fed40SPeter Rosin dev->muxc->priv = dev; 1456e00fed40SPeter Rosin ret = i2c_mux_add_adapter(dev->muxc, 0, 0, 0); 1457e00fed40SPeter Rosin if (ret) 1458e00fed40SPeter Rosin goto err_kfree; 1459f01919e8SAntti Palosaari 1460f01919e8SAntti Palosaari /* create dvb_frontend */ 1461f01919e8SAntti Palosaari memcpy(&dev->fe.ops, &m88ds3103_ops, sizeof(struct dvb_frontend_ops)); 1462f01919e8SAntti Palosaari if (dev->chip_id == M88RS6000_CHIP_ID) 146385709cbfSMauro Carvalho Chehab strscpy(dev->fe.ops.info.name, "Montage Technology M88RS6000", 14647978b8a1SAntti Palosaari sizeof(dev->fe.ops.info.name)); 1465f01919e8SAntti Palosaari if (!pdata->attach_in_use) 1466f01919e8SAntti Palosaari dev->fe.ops.release = NULL; 1467f01919e8SAntti Palosaari dev->fe.demodulator_priv = dev; 1468f01919e8SAntti Palosaari i2c_set_clientdata(client, dev); 1469f01919e8SAntti Palosaari 1470f01919e8SAntti Palosaari /* setup callbacks */ 1471f01919e8SAntti Palosaari pdata->get_dvb_frontend = m88ds3103_get_dvb_frontend; 1472f01919e8SAntti Palosaari pdata->get_i2c_adapter = m88ds3103_get_i2c_adapter; 1473f01919e8SAntti Palosaari return 0; 1474f01919e8SAntti Palosaari err_kfree: 1475f01919e8SAntti Palosaari kfree(dev); 1476f01919e8SAntti Palosaari err: 1477f01919e8SAntti Palosaari dev_dbg(&client->dev, "failed=%d\n", ret); 1478f01919e8SAntti Palosaari return ret; 1479f01919e8SAntti Palosaari } 1480f01919e8SAntti Palosaari 1481f01919e8SAntti Palosaari static int m88ds3103_remove(struct i2c_client *client) 1482f01919e8SAntti Palosaari { 14837978b8a1SAntti Palosaari struct m88ds3103_dev *dev = i2c_get_clientdata(client); 1484f01919e8SAntti Palosaari 1485f01919e8SAntti Palosaari dev_dbg(&client->dev, "\n"); 1486f01919e8SAntti Palosaari 1487e00fed40SPeter Rosin i2c_mux_del_adapters(dev->muxc); 1488f01919e8SAntti Palosaari 1489f01919e8SAntti Palosaari kfree(dev); 1490f01919e8SAntti Palosaari return 0; 1491f01919e8SAntti Palosaari } 1492f01919e8SAntti Palosaari 1493f01919e8SAntti Palosaari static const struct i2c_device_id m88ds3103_id_table[] = { 1494f01919e8SAntti Palosaari {"m88ds3103", 0}, 1495f01919e8SAntti Palosaari {} 1496f01919e8SAntti Palosaari }; 1497f01919e8SAntti Palosaari MODULE_DEVICE_TABLE(i2c, m88ds3103_id_table); 1498f01919e8SAntti Palosaari 1499f01919e8SAntti Palosaari static struct i2c_driver m88ds3103_driver = { 1500f01919e8SAntti Palosaari .driver = { 1501f01919e8SAntti Palosaari .name = "m88ds3103", 1502f01919e8SAntti Palosaari .suppress_bind_attrs = true, 1503f01919e8SAntti Palosaari }, 1504f01919e8SAntti Palosaari .probe = m88ds3103_probe, 1505f01919e8SAntti Palosaari .remove = m88ds3103_remove, 1506f01919e8SAntti Palosaari .id_table = m88ds3103_id_table, 1507f01919e8SAntti Palosaari }; 1508f01919e8SAntti Palosaari 1509f01919e8SAntti Palosaari module_i2c_driver(m88ds3103_driver); 1510f01919e8SAntti Palosaari 1511395d00d1SAntti Palosaari MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>"); 15127978b8a1SAntti Palosaari MODULE_DESCRIPTION("Montage Technology M88DS3103 DVB-S/S2 demodulator driver"); 1513395d00d1SAntti Palosaari MODULE_LICENSE("GPL"); 1514395d00d1SAntti Palosaari MODULE_FIRMWARE(M88DS3103_FIRMWARE); 1515f4df95bcSnibble.max MODULE_FIRMWARE(M88RS6000_FIRMWARE); 1516