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 19bd336e63SMax Kellermann static const 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; 312*981fbe3dSJames Hutchinson static const struct reg_sequence reset_buf[] = { 313*981fbe3dSJames Hutchinson {0x07, 0x80}, {0x07, 0x00} 314*981fbe3dSJames Hutchinson }; 31541b9aa00SAntti Palosaari 3167978b8a1SAntti Palosaari dev_dbg(&client->dev, 3177978b8a1SAntti Palosaari "delivery_system=%d modulation=%d frequency=%u symbol_rate=%d inversion=%d pilot=%d rolloff=%d\n", 3187978b8a1SAntti Palosaari c->delivery_system, c->modulation, c->frequency, c->symbol_rate, 319395d00d1SAntti Palosaari c->inversion, c->pilot, c->rolloff); 320395d00d1SAntti Palosaari 3217978b8a1SAntti Palosaari if (!dev->warm) { 322395d00d1SAntti Palosaari ret = -EAGAIN; 323395d00d1SAntti Palosaari goto err; 324395d00d1SAntti Palosaari } 325395d00d1SAntti Palosaari 326f4df95bcSnibble.max /* reset */ 327*981fbe3dSJames Hutchinson ret = regmap_multi_reg_write(dev->regmap, reset_buf, 2); 328f4df95bcSnibble.max if (ret) 329f4df95bcSnibble.max goto err; 330f4df95bcSnibble.max 331f4df95bcSnibble.max /* Disable demod clock path */ 3327978b8a1SAntti Palosaari if (dev->chip_id == M88RS6000_CHIP_ID) { 333478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0x06, 0xe0); 334f4df95bcSnibble.max if (ret) 335f4df95bcSnibble.max goto err; 336f4df95bcSnibble.max } 337f4df95bcSnibble.max 338395d00d1SAntti Palosaari /* program tuner */ 339395d00d1SAntti Palosaari if (fe->ops.tuner_ops.set_params) { 340395d00d1SAntti Palosaari ret = fe->ops.tuner_ops.set_params(fe); 341395d00d1SAntti Palosaari if (ret) 342395d00d1SAntti Palosaari goto err; 343395d00d1SAntti Palosaari } 344395d00d1SAntti Palosaari 345395d00d1SAntti Palosaari if (fe->ops.tuner_ops.get_frequency) { 346f5d9b88dSAntti Palosaari ret = fe->ops.tuner_ops.get_frequency(fe, &tuner_frequency_khz); 347395d00d1SAntti Palosaari if (ret) 348395d00d1SAntti Palosaari goto err; 3492f9dff3fSAntti Palosaari } else { 3502f9dff3fSAntti Palosaari /* 3512f9dff3fSAntti Palosaari * Use nominal target frequency as tuner driver does not provide 3522f9dff3fSAntti Palosaari * actual frequency used. Carrier offset calculation is not 3532f9dff3fSAntti Palosaari * valid. 3542f9dff3fSAntti Palosaari */ 355f5d9b88dSAntti Palosaari tuner_frequency_khz = c->frequency; 356395d00d1SAntti Palosaari } 357395d00d1SAntti Palosaari 358f4df95bcSnibble.max /* select M88RS6000 demod main mclk and ts mclk from tuner die. */ 3597978b8a1SAntti Palosaari if (dev->chip_id == M88RS6000_CHIP_ID) { 360f4df95bcSnibble.max if (c->symbol_rate > 45010000) 361f5d9b88dSAntti Palosaari dev->mclk = 110250000; 362f4df95bcSnibble.max else 363f5d9b88dSAntti Palosaari dev->mclk = 96000000; 364395d00d1SAntti Palosaari 365f4df95bcSnibble.max if (c->delivery_system == SYS_DVBS) 366f5d9b88dSAntti Palosaari target_mclk = 96000000; 367f4df95bcSnibble.max else 368f5d9b88dSAntti Palosaari target_mclk = 144000000; 369395d00d1SAntti Palosaari 370f4df95bcSnibble.max /* Enable demod clock path */ 371478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0x06, 0x00); 372f4df95bcSnibble.max if (ret) 373f4df95bcSnibble.max goto err; 374f4df95bcSnibble.max usleep_range(10000, 20000); 375f4df95bcSnibble.max } else { 376f4df95bcSnibble.max /* set M88DS3103 mclk and ts mclk. */ 377f5d9b88dSAntti Palosaari dev->mclk = 96000000; 378f4df95bcSnibble.max 3797978b8a1SAntti Palosaari switch (dev->cfg->ts_mode) { 380395d00d1SAntti Palosaari case M88DS3103_TS_SERIAL: 381395d00d1SAntti Palosaari case M88DS3103_TS_SERIAL_D7: 3827978b8a1SAntti Palosaari target_mclk = dev->cfg->ts_clk; 383395d00d1SAntti Palosaari break; 384395d00d1SAntti Palosaari case M88DS3103_TS_PARALLEL: 385395d00d1SAntti Palosaari case M88DS3103_TS_CI: 386b6851419Snibble.max if (c->delivery_system == SYS_DVBS) 387f5d9b88dSAntti Palosaari target_mclk = 96000000; 388b6851419Snibble.max else { 389395d00d1SAntti Palosaari if (c->symbol_rate < 18000000) 390f5d9b88dSAntti Palosaari target_mclk = 96000000; 391395d00d1SAntti Palosaari else if (c->symbol_rate < 28000000) 392f5d9b88dSAntti Palosaari target_mclk = 144000000; 393395d00d1SAntti Palosaari else 394f5d9b88dSAntti Palosaari target_mclk = 192000000; 395b6851419Snibble.max } 396395d00d1SAntti Palosaari break; 397395d00d1SAntti Palosaari default: 3987978b8a1SAntti Palosaari dev_dbg(&client->dev, "invalid ts_mode\n"); 399395d00d1SAntti Palosaari ret = -EINVAL; 400395d00d1SAntti Palosaari goto err; 401395d00d1SAntti Palosaari } 402f4df95bcSnibble.max 403f4df95bcSnibble.max switch (target_mclk) { 404f5d9b88dSAntti Palosaari case 96000000: 405f4df95bcSnibble.max u8tmp1 = 0x02; /* 0b10 */ 406f4df95bcSnibble.max u8tmp2 = 0x01; /* 0b01 */ 407f4df95bcSnibble.max break; 408f5d9b88dSAntti Palosaari case 144000000: 409f4df95bcSnibble.max u8tmp1 = 0x00; /* 0b00 */ 410f4df95bcSnibble.max u8tmp2 = 0x01; /* 0b01 */ 411f4df95bcSnibble.max break; 412f5d9b88dSAntti Palosaari case 192000000: 413f4df95bcSnibble.max u8tmp1 = 0x03; /* 0b11 */ 414f4df95bcSnibble.max u8tmp2 = 0x00; /* 0b00 */ 415f4df95bcSnibble.max break; 416f4df95bcSnibble.max } 41756ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x22, 0xc0, u8tmp1 << 6); 418f4df95bcSnibble.max if (ret) 419f4df95bcSnibble.max goto err; 42056ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x24, 0xc0, u8tmp2 << 6); 421f4df95bcSnibble.max if (ret) 422f4df95bcSnibble.max goto err; 423f4df95bcSnibble.max } 424f4df95bcSnibble.max 425478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xb2, 0x01); 426f4df95bcSnibble.max if (ret) 427f4df95bcSnibble.max goto err; 428f4df95bcSnibble.max 429478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0x00, 0x01); 430f4df95bcSnibble.max if (ret) 431f4df95bcSnibble.max goto err; 432f4df95bcSnibble.max 433f4df95bcSnibble.max switch (c->delivery_system) { 434f4df95bcSnibble.max case SYS_DVBS: 4357978b8a1SAntti Palosaari if (dev->chip_id == M88RS6000_CHIP_ID) { 436f4df95bcSnibble.max len = ARRAY_SIZE(m88rs6000_dvbs_init_reg_vals); 437f4df95bcSnibble.max init = m88rs6000_dvbs_init_reg_vals; 438f4df95bcSnibble.max } else { 439f4df95bcSnibble.max len = ARRAY_SIZE(m88ds3103_dvbs_init_reg_vals); 440f4df95bcSnibble.max init = m88ds3103_dvbs_init_reg_vals; 441f4df95bcSnibble.max } 442f4df95bcSnibble.max break; 443f4df95bcSnibble.max case SYS_DVBS2: 4447978b8a1SAntti Palosaari if (dev->chip_id == M88RS6000_CHIP_ID) { 445f4df95bcSnibble.max len = ARRAY_SIZE(m88rs6000_dvbs2_init_reg_vals); 446f4df95bcSnibble.max init = m88rs6000_dvbs2_init_reg_vals; 447f4df95bcSnibble.max } else { 448f4df95bcSnibble.max len = ARRAY_SIZE(m88ds3103_dvbs2_init_reg_vals); 449f4df95bcSnibble.max init = m88ds3103_dvbs2_init_reg_vals; 450f4df95bcSnibble.max } 451395d00d1SAntti Palosaari break; 452395d00d1SAntti Palosaari default: 4537978b8a1SAntti Palosaari dev_dbg(&client->dev, "invalid delivery_system\n"); 454395d00d1SAntti Palosaari ret = -EINVAL; 455395d00d1SAntti Palosaari goto err; 456395d00d1SAntti Palosaari } 457395d00d1SAntti Palosaari 458395d00d1SAntti Palosaari /* program init table */ 4597978b8a1SAntti Palosaari if (c->delivery_system != dev->delivery_system) { 4607978b8a1SAntti Palosaari ret = m88ds3103_wr_reg_val_tab(dev, init, len); 461395d00d1SAntti Palosaari if (ret) 462395d00d1SAntti Palosaari goto err; 463395d00d1SAntti Palosaari } 464395d00d1SAntti Palosaari 4657978b8a1SAntti Palosaari if (dev->chip_id == M88RS6000_CHIP_ID) { 466f5d9b88dSAntti Palosaari if (c->delivery_system == SYS_DVBS2 && 467f5d9b88dSAntti Palosaari c->symbol_rate <= 5000000) { 468478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xc0, 0x04); 469f4df95bcSnibble.max if (ret) 470f4df95bcSnibble.max goto err; 471f4df95bcSnibble.max buf[0] = 0x09; 472f4df95bcSnibble.max buf[1] = 0x22; 473f4df95bcSnibble.max buf[2] = 0x88; 474478932b1SAntti Palosaari ret = regmap_bulk_write(dev->regmap, 0x8a, buf, 3); 475f4df95bcSnibble.max if (ret) 476f4df95bcSnibble.max goto err; 477f4df95bcSnibble.max } 47856ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x9d, 0x08, 0x08); 479f4df95bcSnibble.max if (ret) 480f4df95bcSnibble.max goto err; 481478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xf1, 0x01); 482f4df95bcSnibble.max if (ret) 483f4df95bcSnibble.max goto err; 48456ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x30, 0x80, 0x80); 485f4df95bcSnibble.max if (ret) 486f4df95bcSnibble.max goto err; 487f4df95bcSnibble.max } 488f4df95bcSnibble.max 4897978b8a1SAntti Palosaari switch (dev->cfg->ts_mode) { 490395d00d1SAntti Palosaari case M88DS3103_TS_SERIAL: 491395d00d1SAntti Palosaari u8tmp1 = 0x00; 49279d09330Snibble.max u8tmp = 0x06; 493395d00d1SAntti Palosaari break; 494395d00d1SAntti Palosaari case M88DS3103_TS_SERIAL_D7: 495395d00d1SAntti Palosaari u8tmp1 = 0x20; 49679d09330Snibble.max u8tmp = 0x06; 497395d00d1SAntti Palosaari break; 498395d00d1SAntti Palosaari case M88DS3103_TS_PARALLEL: 49979d09330Snibble.max u8tmp = 0x02; 500395d00d1SAntti Palosaari break; 501395d00d1SAntti Palosaari case M88DS3103_TS_CI: 50279d09330Snibble.max u8tmp = 0x03; 503395d00d1SAntti Palosaari break; 504395d00d1SAntti Palosaari default: 5057978b8a1SAntti Palosaari dev_dbg(&client->dev, "invalid ts_mode\n"); 506395d00d1SAntti Palosaari ret = -EINVAL; 507395d00d1SAntti Palosaari goto err; 508395d00d1SAntti Palosaari } 509395d00d1SAntti Palosaari 5107978b8a1SAntti Palosaari if (dev->cfg->ts_clk_pol) 51179d09330Snibble.max u8tmp |= 0x40; 51279d09330Snibble.max 513395d00d1SAntti Palosaari /* TS mode */ 514478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xfd, u8tmp); 515395d00d1SAntti Palosaari if (ret) 516395d00d1SAntti Palosaari goto err; 517395d00d1SAntti Palosaari 5187978b8a1SAntti Palosaari switch (dev->cfg->ts_mode) { 519395d00d1SAntti Palosaari case M88DS3103_TS_SERIAL: 520395d00d1SAntti Palosaari case M88DS3103_TS_SERIAL_D7: 52156ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x29, 0x20, u8tmp1); 522395d00d1SAntti Palosaari if (ret) 523395d00d1SAntti Palosaari goto err; 524334ef18eSAntti Palosaari u16tmp = 0; 525334ef18eSAntti Palosaari u8tmp1 = 0x3f; 526334ef18eSAntti Palosaari u8tmp2 = 0x3f; 527b6851419Snibble.max break; 528b6851419Snibble.max default: 529334ef18eSAntti Palosaari u16tmp = DIV_ROUND_UP(target_mclk, dev->cfg->ts_clk); 530334ef18eSAntti Palosaari u8tmp1 = u16tmp / 2 - 1; 531334ef18eSAntti Palosaari u8tmp2 = DIV_ROUND_UP(u16tmp, 2) - 1; 532395d00d1SAntti Palosaari } 533395d00d1SAntti Palosaari 534f5d9b88dSAntti Palosaari dev_dbg(&client->dev, "target_mclk=%u ts_clk=%u ts_clk_divide_ratio=%u\n", 535334ef18eSAntti Palosaari target_mclk, dev->cfg->ts_clk, u16tmp); 536395d00d1SAntti Palosaari 537395d00d1SAntti Palosaari /* u8tmp1[5:2] => fe[3:0], u8tmp1[1:0] => ea[7:6] */ 538395d00d1SAntti Palosaari /* u8tmp2[5:0] => ea[5:0] */ 539334ef18eSAntti Palosaari u8tmp = (u8tmp1 >> 2) & 0x0f; 540334ef18eSAntti Palosaari ret = regmap_update_bits(dev->regmap, 0xfe, 0x0f, u8tmp); 541395d00d1SAntti Palosaari if (ret) 542395d00d1SAntti Palosaari goto err; 543395d00d1SAntti Palosaari u8tmp = ((u8tmp1 & 0x03) << 6) | u8tmp2 >> 0; 544478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xea, u8tmp); 545395d00d1SAntti Palosaari if (ret) 546395d00d1SAntti Palosaari goto err; 547395d00d1SAntti Palosaari 548395d00d1SAntti Palosaari if (c->symbol_rate <= 3000000) 549395d00d1SAntti Palosaari u8tmp = 0x20; 550395d00d1SAntti Palosaari else if (c->symbol_rate <= 10000000) 551395d00d1SAntti Palosaari u8tmp = 0x10; 552395d00d1SAntti Palosaari else 553395d00d1SAntti Palosaari u8tmp = 0x06; 554395d00d1SAntti Palosaari 555478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xc3, 0x08); 556395d00d1SAntti Palosaari if (ret) 557395d00d1SAntti Palosaari goto err; 558395d00d1SAntti Palosaari 559478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xc8, u8tmp); 560395d00d1SAntti Palosaari if (ret) 561395d00d1SAntti Palosaari goto err; 562395d00d1SAntti Palosaari 563478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xc4, 0x08); 564395d00d1SAntti Palosaari if (ret) 565395d00d1SAntti Palosaari goto err; 566395d00d1SAntti Palosaari 567478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xc7, 0x00); 568395d00d1SAntti Palosaari if (ret) 569395d00d1SAntti Palosaari goto err; 570395d00d1SAntti Palosaari 571f5d9b88dSAntti Palosaari u16tmp = DIV_ROUND_CLOSEST_ULL((u64)c->symbol_rate * 0x10000, dev->mclk); 572395d00d1SAntti Palosaari buf[0] = (u16tmp >> 0) & 0xff; 573395d00d1SAntti Palosaari buf[1] = (u16tmp >> 8) & 0xff; 574478932b1SAntti Palosaari ret = regmap_bulk_write(dev->regmap, 0x61, buf, 2); 575395d00d1SAntti Palosaari if (ret) 576395d00d1SAntti Palosaari goto err; 577395d00d1SAntti Palosaari 57856ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x4d, 0x02, dev->cfg->spec_inv << 1); 579395d00d1SAntti Palosaari if (ret) 580395d00d1SAntti Palosaari goto err; 581395d00d1SAntti Palosaari 58256ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x30, 0x10, dev->cfg->agc_inv << 4); 583395d00d1SAntti Palosaari if (ret) 584395d00d1SAntti Palosaari goto err; 585395d00d1SAntti Palosaari 586478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0x33, dev->cfg->agc); 587395d00d1SAntti Palosaari if (ret) 588395d00d1SAntti Palosaari goto err; 589395d00d1SAntti Palosaari 5907978b8a1SAntti Palosaari dev_dbg(&client->dev, "carrier offset=%d\n", 591f5d9b88dSAntti Palosaari (tuner_frequency_khz - c->frequency)); 592395d00d1SAntti Palosaari 593f5d9b88dSAntti Palosaari /* Use 32-bit calc as there is no s64 version of DIV_ROUND_CLOSEST() */ 594f5d9b88dSAntti Palosaari s32tmp = 0x10000 * (tuner_frequency_khz - c->frequency); 595f5d9b88dSAntti Palosaari s32tmp = DIV_ROUND_CLOSEST(s32tmp, dev->mclk / 1000); 596395d00d1SAntti Palosaari buf[0] = (s32tmp >> 0) & 0xff; 597395d00d1SAntti Palosaari buf[1] = (s32tmp >> 8) & 0xff; 598478932b1SAntti Palosaari ret = regmap_bulk_write(dev->regmap, 0x5e, buf, 2); 599395d00d1SAntti Palosaari if (ret) 600395d00d1SAntti Palosaari goto err; 601395d00d1SAntti Palosaari 602478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0x00, 0x00); 603395d00d1SAntti Palosaari if (ret) 604395d00d1SAntti Palosaari goto err; 605395d00d1SAntti Palosaari 606478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xb2, 0x00); 607395d00d1SAntti Palosaari if (ret) 608395d00d1SAntti Palosaari goto err; 609395d00d1SAntti Palosaari 6107978b8a1SAntti Palosaari dev->delivery_system = c->delivery_system; 611395d00d1SAntti Palosaari 612395d00d1SAntti Palosaari return 0; 613395d00d1SAntti Palosaari err: 6147978b8a1SAntti Palosaari dev_dbg(&client->dev, "failed=%d\n", ret); 615395d00d1SAntti Palosaari return ret; 616395d00d1SAntti Palosaari } 617395d00d1SAntti Palosaari 618395d00d1SAntti Palosaari static int m88ds3103_init(struct dvb_frontend *fe) 619395d00d1SAntti Palosaari { 6207978b8a1SAntti Palosaari struct m88ds3103_dev *dev = fe->demodulator_priv; 6217978b8a1SAntti Palosaari struct i2c_client *client = dev->client; 622c1daf651SAntti Palosaari struct dtv_frontend_properties *c = &fe->dtv_property_cache; 62360701d5fSAntti Palosaari int ret, len, rem; 624478932b1SAntti Palosaari unsigned int utmp; 62560701d5fSAntti Palosaari const struct firmware *firmware; 62660701d5fSAntti Palosaari const char *name; 62741b9aa00SAntti Palosaari 6287978b8a1SAntti Palosaari dev_dbg(&client->dev, "\n"); 629395d00d1SAntti Palosaari 630395d00d1SAntti Palosaari /* set cold state by default */ 6317978b8a1SAntti Palosaari dev->warm = false; 632395d00d1SAntti Palosaari 633395d00d1SAntti Palosaari /* wake up device from sleep */ 63456ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x08, 0x01, 0x01); 635395d00d1SAntti Palosaari if (ret) 636395d00d1SAntti Palosaari goto err; 63756ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x04, 0x01, 0x00); 638395d00d1SAntti Palosaari if (ret) 639395d00d1SAntti Palosaari goto err; 64056ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x23, 0x10, 0x00); 641395d00d1SAntti Palosaari if (ret) 642395d00d1SAntti Palosaari goto err; 643395d00d1SAntti Palosaari 644395d00d1SAntti Palosaari /* firmware status */ 645478932b1SAntti Palosaari ret = regmap_read(dev->regmap, 0xb9, &utmp); 646395d00d1SAntti Palosaari if (ret) 647395d00d1SAntti Palosaari goto err; 648395d00d1SAntti Palosaari 649478932b1SAntti Palosaari dev_dbg(&client->dev, "firmware=%02x\n", utmp); 650395d00d1SAntti Palosaari 651478932b1SAntti Palosaari if (utmp) 65260701d5fSAntti Palosaari goto warm; 653395d00d1SAntti Palosaari 654f4df95bcSnibble.max /* global reset, global diseqc reset, golbal fec reset */ 655478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0x07, 0xe0); 656f4df95bcSnibble.max if (ret) 657f4df95bcSnibble.max goto err; 658478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0x07, 0x00); 659f4df95bcSnibble.max if (ret) 660f4df95bcSnibble.max goto err; 661f4df95bcSnibble.max 662395d00d1SAntti Palosaari /* cold state - try to download firmware */ 6637978b8a1SAntti Palosaari dev_info(&client->dev, "found a '%s' in cold state\n", 6647978b8a1SAntti Palosaari m88ds3103_ops.info.name); 665395d00d1SAntti Palosaari 6667978b8a1SAntti Palosaari if (dev->chip_id == M88RS6000_CHIP_ID) 66760701d5fSAntti Palosaari name = M88RS6000_FIRMWARE; 668f4df95bcSnibble.max else 66960701d5fSAntti Palosaari name = M88DS3103_FIRMWARE; 670395d00d1SAntti Palosaari /* request the firmware, this will block and timeout */ 67160701d5fSAntti Palosaari ret = request_firmware(&firmware, name, &client->dev); 672395d00d1SAntti Palosaari if (ret) { 67360701d5fSAntti Palosaari dev_err(&client->dev, "firmware file '%s' not found\n", name); 674395d00d1SAntti Palosaari goto err; 675395d00d1SAntti Palosaari } 676395d00d1SAntti Palosaari 67760701d5fSAntti Palosaari dev_info(&client->dev, "downloading firmware from file '%s'\n", name); 678395d00d1SAntti Palosaari 679478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xb2, 0x01); 680395d00d1SAntti Palosaari if (ret) 68160701d5fSAntti Palosaari goto err_release_firmware; 682395d00d1SAntti Palosaari 68360701d5fSAntti Palosaari for (rem = firmware->size; rem > 0; rem -= (dev->cfg->i2c_wr_max - 1)) { 68460701d5fSAntti Palosaari len = min(dev->cfg->i2c_wr_max - 1, rem); 685478932b1SAntti Palosaari ret = regmap_bulk_write(dev->regmap, 0xb0, 68660701d5fSAntti Palosaari &firmware->data[firmware->size - rem], 68760701d5fSAntti Palosaari len); 688395d00d1SAntti Palosaari if (ret) { 68960701d5fSAntti Palosaari dev_err(&client->dev, "firmware download failed %d\n", 6907978b8a1SAntti Palosaari ret); 69160701d5fSAntti Palosaari goto err_release_firmware; 692395d00d1SAntti Palosaari } 693395d00d1SAntti Palosaari } 694395d00d1SAntti Palosaari 695478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xb2, 0x00); 696395d00d1SAntti Palosaari if (ret) 69760701d5fSAntti Palosaari goto err_release_firmware; 698395d00d1SAntti Palosaari 69960701d5fSAntti Palosaari release_firmware(firmware); 700395d00d1SAntti Palosaari 701478932b1SAntti Palosaari ret = regmap_read(dev->regmap, 0xb9, &utmp); 702395d00d1SAntti Palosaari if (ret) 703395d00d1SAntti Palosaari goto err; 704395d00d1SAntti Palosaari 705478932b1SAntti Palosaari if (!utmp) { 70660701d5fSAntti Palosaari ret = -EINVAL; 7077978b8a1SAntti Palosaari dev_info(&client->dev, "firmware did not run\n"); 708395d00d1SAntti Palosaari goto err; 709395d00d1SAntti Palosaari } 710395d00d1SAntti Palosaari 7117978b8a1SAntti Palosaari dev_info(&client->dev, "found a '%s' in warm state\n", 7127978b8a1SAntti Palosaari m88ds3103_ops.info.name); 7137978b8a1SAntti Palosaari dev_info(&client->dev, "firmware version: %X.%X\n", 714478932b1SAntti Palosaari (utmp >> 4) & 0xf, (utmp >> 0 & 0xf)); 715395d00d1SAntti Palosaari 71660701d5fSAntti Palosaari warm: 717395d00d1SAntti Palosaari /* warm state */ 7187978b8a1SAntti Palosaari dev->warm = true; 7197978b8a1SAntti Palosaari 720c1daf651SAntti Palosaari /* init stats here in order signal app which stats are supported */ 721c1daf651SAntti Palosaari c->cnr.len = 1; 722c1daf651SAntti Palosaari c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; 723ce80d713SAntti Palosaari c->post_bit_error.len = 1; 724ce80d713SAntti Palosaari c->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; 725ce80d713SAntti Palosaari c->post_bit_count.len = 1; 726ce80d713SAntti Palosaari c->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE; 727395d00d1SAntti Palosaari 7287978b8a1SAntti Palosaari return 0; 72960701d5fSAntti Palosaari err_release_firmware: 73060701d5fSAntti Palosaari release_firmware(firmware); 7315ed0cf88SMarkus Elfring err: 7327978b8a1SAntti Palosaari dev_dbg(&client->dev, "failed=%d\n", ret); 733395d00d1SAntti Palosaari return ret; 734395d00d1SAntti Palosaari } 735395d00d1SAntti Palosaari 736395d00d1SAntti Palosaari static int m88ds3103_sleep(struct dvb_frontend *fe) 737395d00d1SAntti Palosaari { 7387978b8a1SAntti Palosaari struct m88ds3103_dev *dev = fe->demodulator_priv; 7397978b8a1SAntti Palosaari struct i2c_client *client = dev->client; 740395d00d1SAntti Palosaari int ret; 741478932b1SAntti Palosaari unsigned int utmp; 74241b9aa00SAntti Palosaari 7437978b8a1SAntti Palosaari dev_dbg(&client->dev, "\n"); 744395d00d1SAntti Palosaari 7457978b8a1SAntti Palosaari dev->fe_status = 0; 7467978b8a1SAntti Palosaari dev->delivery_system = SYS_UNDEFINED; 747395d00d1SAntti Palosaari 748395d00d1SAntti Palosaari /* TS Hi-Z */ 7497978b8a1SAntti Palosaari if (dev->chip_id == M88RS6000_CHIP_ID) 750478932b1SAntti Palosaari utmp = 0x29; 751f4df95bcSnibble.max else 752478932b1SAntti Palosaari utmp = 0x27; 75356ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, utmp, 0x01, 0x00); 754395d00d1SAntti Palosaari if (ret) 755395d00d1SAntti Palosaari goto err; 756395d00d1SAntti Palosaari 757395d00d1SAntti Palosaari /* sleep */ 75856ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x08, 0x01, 0x00); 759395d00d1SAntti Palosaari if (ret) 760395d00d1SAntti Palosaari goto err; 76156ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x04, 0x01, 0x01); 762395d00d1SAntti Palosaari if (ret) 763395d00d1SAntti Palosaari goto err; 76456ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x23, 0x10, 0x10); 765395d00d1SAntti Palosaari if (ret) 766395d00d1SAntti Palosaari goto err; 767395d00d1SAntti Palosaari 768395d00d1SAntti Palosaari return 0; 769395d00d1SAntti Palosaari err: 7707978b8a1SAntti Palosaari dev_dbg(&client->dev, "failed=%d\n", ret); 771395d00d1SAntti Palosaari return ret; 772395d00d1SAntti Palosaari } 773395d00d1SAntti Palosaari 7747e3e68bcSMauro Carvalho Chehab static int m88ds3103_get_frontend(struct dvb_frontend *fe, 7757e3e68bcSMauro Carvalho Chehab struct dtv_frontend_properties *c) 776395d00d1SAntti Palosaari { 7777978b8a1SAntti Palosaari struct m88ds3103_dev *dev = fe->demodulator_priv; 7787978b8a1SAntti Palosaari struct i2c_client *client = dev->client; 779395d00d1SAntti Palosaari int ret; 780395d00d1SAntti Palosaari u8 buf[3]; 78141b9aa00SAntti Palosaari 7827978b8a1SAntti Palosaari dev_dbg(&client->dev, "\n"); 783395d00d1SAntti Palosaari 7847978b8a1SAntti Palosaari if (!dev->warm || !(dev->fe_status & FE_HAS_LOCK)) { 7859240c384SAntti Palosaari ret = 0; 786395d00d1SAntti Palosaari goto err; 787395d00d1SAntti Palosaari } 788395d00d1SAntti Palosaari 789395d00d1SAntti Palosaari switch (c->delivery_system) { 790395d00d1SAntti Palosaari case SYS_DVBS: 791478932b1SAntti Palosaari ret = regmap_bulk_read(dev->regmap, 0xe0, &buf[0], 1); 792395d00d1SAntti Palosaari if (ret) 793395d00d1SAntti Palosaari goto err; 794395d00d1SAntti Palosaari 795478932b1SAntti Palosaari ret = regmap_bulk_read(dev->regmap, 0xe6, &buf[1], 1); 796395d00d1SAntti Palosaari if (ret) 797395d00d1SAntti Palosaari goto err; 798395d00d1SAntti Palosaari 799395d00d1SAntti Palosaari switch ((buf[0] >> 2) & 0x01) { 800395d00d1SAntti Palosaari case 0: 801395d00d1SAntti Palosaari c->inversion = INVERSION_OFF; 802395d00d1SAntti Palosaari break; 803395d00d1SAntti Palosaari case 1: 804395d00d1SAntti Palosaari c->inversion = INVERSION_ON; 805395d00d1SAntti Palosaari break; 806395d00d1SAntti Palosaari } 807395d00d1SAntti Palosaari 808395d00d1SAntti Palosaari switch ((buf[1] >> 5) & 0x07) { 809395d00d1SAntti Palosaari case 0: 810395d00d1SAntti Palosaari c->fec_inner = FEC_7_8; 811395d00d1SAntti Palosaari break; 812395d00d1SAntti Palosaari case 1: 813395d00d1SAntti Palosaari c->fec_inner = FEC_5_6; 814395d00d1SAntti Palosaari break; 815395d00d1SAntti Palosaari case 2: 816395d00d1SAntti Palosaari c->fec_inner = FEC_3_4; 817395d00d1SAntti Palosaari break; 818395d00d1SAntti Palosaari case 3: 819395d00d1SAntti Palosaari c->fec_inner = FEC_2_3; 820395d00d1SAntti Palosaari break; 821395d00d1SAntti Palosaari case 4: 822395d00d1SAntti Palosaari c->fec_inner = FEC_1_2; 823395d00d1SAntti Palosaari break; 824395d00d1SAntti Palosaari default: 8257978b8a1SAntti Palosaari dev_dbg(&client->dev, "invalid fec_inner\n"); 826395d00d1SAntti Palosaari } 827395d00d1SAntti Palosaari 828395d00d1SAntti Palosaari c->modulation = QPSK; 829395d00d1SAntti Palosaari 830395d00d1SAntti Palosaari break; 831395d00d1SAntti Palosaari case SYS_DVBS2: 832478932b1SAntti Palosaari ret = regmap_bulk_read(dev->regmap, 0x7e, &buf[0], 1); 833395d00d1SAntti Palosaari if (ret) 834395d00d1SAntti Palosaari goto err; 835395d00d1SAntti Palosaari 836478932b1SAntti Palosaari ret = regmap_bulk_read(dev->regmap, 0x89, &buf[1], 1); 837395d00d1SAntti Palosaari if (ret) 838395d00d1SAntti Palosaari goto err; 839395d00d1SAntti Palosaari 840478932b1SAntti Palosaari ret = regmap_bulk_read(dev->regmap, 0xf2, &buf[2], 1); 841395d00d1SAntti Palosaari if (ret) 842395d00d1SAntti Palosaari goto err; 843395d00d1SAntti Palosaari 844395d00d1SAntti Palosaari switch ((buf[0] >> 0) & 0x0f) { 845395d00d1SAntti Palosaari case 2: 846395d00d1SAntti Palosaari c->fec_inner = FEC_2_5; 847395d00d1SAntti Palosaari break; 848395d00d1SAntti Palosaari case 3: 849395d00d1SAntti Palosaari c->fec_inner = FEC_1_2; 850395d00d1SAntti Palosaari break; 851395d00d1SAntti Palosaari case 4: 852395d00d1SAntti Palosaari c->fec_inner = FEC_3_5; 853395d00d1SAntti Palosaari break; 854395d00d1SAntti Palosaari case 5: 855395d00d1SAntti Palosaari c->fec_inner = FEC_2_3; 856395d00d1SAntti Palosaari break; 857395d00d1SAntti Palosaari case 6: 858395d00d1SAntti Palosaari c->fec_inner = FEC_3_4; 859395d00d1SAntti Palosaari break; 860395d00d1SAntti Palosaari case 7: 861395d00d1SAntti Palosaari c->fec_inner = FEC_4_5; 862395d00d1SAntti Palosaari break; 863395d00d1SAntti Palosaari case 8: 864395d00d1SAntti Palosaari c->fec_inner = FEC_5_6; 865395d00d1SAntti Palosaari break; 866395d00d1SAntti Palosaari case 9: 867395d00d1SAntti Palosaari c->fec_inner = FEC_8_9; 868395d00d1SAntti Palosaari break; 869395d00d1SAntti Palosaari case 10: 870395d00d1SAntti Palosaari c->fec_inner = FEC_9_10; 871395d00d1SAntti Palosaari break; 872395d00d1SAntti Palosaari default: 8737978b8a1SAntti Palosaari dev_dbg(&client->dev, "invalid fec_inner\n"); 874395d00d1SAntti Palosaari } 875395d00d1SAntti Palosaari 876395d00d1SAntti Palosaari switch ((buf[0] >> 5) & 0x01) { 877395d00d1SAntti Palosaari case 0: 878395d00d1SAntti Palosaari c->pilot = PILOT_OFF; 879395d00d1SAntti Palosaari break; 880395d00d1SAntti Palosaari case 1: 881395d00d1SAntti Palosaari c->pilot = PILOT_ON; 882395d00d1SAntti Palosaari break; 883395d00d1SAntti Palosaari } 884395d00d1SAntti Palosaari 885395d00d1SAntti Palosaari switch ((buf[0] >> 6) & 0x07) { 886395d00d1SAntti Palosaari case 0: 887395d00d1SAntti Palosaari c->modulation = QPSK; 888395d00d1SAntti Palosaari break; 889395d00d1SAntti Palosaari case 1: 890395d00d1SAntti Palosaari c->modulation = PSK_8; 891395d00d1SAntti Palosaari break; 892395d00d1SAntti Palosaari case 2: 893395d00d1SAntti Palosaari c->modulation = APSK_16; 894395d00d1SAntti Palosaari break; 895395d00d1SAntti Palosaari case 3: 896395d00d1SAntti Palosaari c->modulation = APSK_32; 897395d00d1SAntti Palosaari break; 898395d00d1SAntti Palosaari default: 8997978b8a1SAntti Palosaari dev_dbg(&client->dev, "invalid modulation\n"); 900395d00d1SAntti Palosaari } 901395d00d1SAntti Palosaari 902395d00d1SAntti Palosaari switch ((buf[1] >> 7) & 0x01) { 903395d00d1SAntti Palosaari case 0: 904395d00d1SAntti Palosaari c->inversion = INVERSION_OFF; 905395d00d1SAntti Palosaari break; 906395d00d1SAntti Palosaari case 1: 907395d00d1SAntti Palosaari c->inversion = INVERSION_ON; 908395d00d1SAntti Palosaari break; 909395d00d1SAntti Palosaari } 910395d00d1SAntti Palosaari 911395d00d1SAntti Palosaari switch ((buf[2] >> 0) & 0x03) { 912395d00d1SAntti Palosaari case 0: 913395d00d1SAntti Palosaari c->rolloff = ROLLOFF_35; 914395d00d1SAntti Palosaari break; 915395d00d1SAntti Palosaari case 1: 916395d00d1SAntti Palosaari c->rolloff = ROLLOFF_25; 917395d00d1SAntti Palosaari break; 918395d00d1SAntti Palosaari case 2: 919395d00d1SAntti Palosaari c->rolloff = ROLLOFF_20; 920395d00d1SAntti Palosaari break; 921395d00d1SAntti Palosaari default: 9227978b8a1SAntti Palosaari dev_dbg(&client->dev, "invalid rolloff\n"); 923395d00d1SAntti Palosaari } 924395d00d1SAntti Palosaari break; 925395d00d1SAntti Palosaari default: 9267978b8a1SAntti Palosaari dev_dbg(&client->dev, "invalid delivery_system\n"); 927395d00d1SAntti Palosaari ret = -EINVAL; 928395d00d1SAntti Palosaari goto err; 929395d00d1SAntti Palosaari } 930395d00d1SAntti Palosaari 931478932b1SAntti Palosaari ret = regmap_bulk_read(dev->regmap, 0x6d, buf, 2); 932395d00d1SAntti Palosaari if (ret) 933395d00d1SAntti Palosaari goto err; 934395d00d1SAntti Palosaari 935f5d9b88dSAntti Palosaari c->symbol_rate = DIV_ROUND_CLOSEST_ULL((u64)(buf[1] << 8 | buf[0] << 0) * dev->mclk, 0x10000); 936395d00d1SAntti Palosaari 937395d00d1SAntti Palosaari return 0; 938395d00d1SAntti Palosaari err: 9397978b8a1SAntti Palosaari dev_dbg(&client->dev, "failed=%d\n", ret); 940395d00d1SAntti Palosaari return ret; 941395d00d1SAntti Palosaari } 942395d00d1SAntti Palosaari 943395d00d1SAntti Palosaari static int m88ds3103_read_snr(struct dvb_frontend *fe, u16 *snr) 944395d00d1SAntti Palosaari { 945395d00d1SAntti Palosaari struct dtv_frontend_properties *c = &fe->dtv_property_cache; 94641b9aa00SAntti Palosaari 947c1daf651SAntti Palosaari if (c->cnr.stat[0].scale == FE_SCALE_DECIBEL) 948c1daf651SAntti Palosaari *snr = div_s64(c->cnr.stat[0].svalue, 100); 949395d00d1SAntti Palosaari else 950395d00d1SAntti Palosaari *snr = 0; 951395d00d1SAntti Palosaari 952395d00d1SAntti Palosaari return 0; 953395d00d1SAntti Palosaari } 954395d00d1SAntti Palosaari 9554423a2baSAntti Palosaari static int m88ds3103_read_ber(struct dvb_frontend *fe, u32 *ber) 9564423a2baSAntti Palosaari { 9577978b8a1SAntti Palosaari struct m88ds3103_dev *dev = fe->demodulator_priv; 95841b9aa00SAntti Palosaari 9597978b8a1SAntti Palosaari *ber = dev->dvbv3_ber; 9604423a2baSAntti Palosaari 9614423a2baSAntti Palosaari return 0; 9624423a2baSAntti Palosaari } 963395d00d1SAntti Palosaari 964395d00d1SAntti Palosaari static int m88ds3103_set_tone(struct dvb_frontend *fe, 9650df289a2SMauro Carvalho Chehab enum fe_sec_tone_mode fe_sec_tone_mode) 966395d00d1SAntti Palosaari { 9677978b8a1SAntti Palosaari struct m88ds3103_dev *dev = fe->demodulator_priv; 9687978b8a1SAntti Palosaari struct i2c_client *client = dev->client; 969395d00d1SAntti Palosaari int ret; 970478932b1SAntti Palosaari unsigned int utmp, tone, reg_a1_mask; 97141b9aa00SAntti Palosaari 9727978b8a1SAntti Palosaari dev_dbg(&client->dev, "fe_sec_tone_mode=%d\n", fe_sec_tone_mode); 973395d00d1SAntti Palosaari 9747978b8a1SAntti Palosaari if (!dev->warm) { 975395d00d1SAntti Palosaari ret = -EAGAIN; 976395d00d1SAntti Palosaari goto err; 977395d00d1SAntti Palosaari } 978395d00d1SAntti Palosaari 979395d00d1SAntti Palosaari switch (fe_sec_tone_mode) { 980395d00d1SAntti Palosaari case SEC_TONE_ON: 981395d00d1SAntti Palosaari tone = 0; 982418a97cbSAntti Palosaari reg_a1_mask = 0x47; 983395d00d1SAntti Palosaari break; 984395d00d1SAntti Palosaari case SEC_TONE_OFF: 985395d00d1SAntti Palosaari tone = 1; 986395d00d1SAntti Palosaari reg_a1_mask = 0x00; 987395d00d1SAntti Palosaari break; 988395d00d1SAntti Palosaari default: 9897978b8a1SAntti Palosaari dev_dbg(&client->dev, "invalid fe_sec_tone_mode\n"); 990395d00d1SAntti Palosaari ret = -EINVAL; 991395d00d1SAntti Palosaari goto err; 992395d00d1SAntti Palosaari } 993395d00d1SAntti Palosaari 994478932b1SAntti Palosaari utmp = tone << 7 | dev->cfg->envelope_mode << 5; 99556ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0xa2, 0xe0, utmp); 996395d00d1SAntti Palosaari if (ret) 997395d00d1SAntti Palosaari goto err; 998395d00d1SAntti Palosaari 999478932b1SAntti Palosaari utmp = 1 << 2; 100056ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0xa1, reg_a1_mask, utmp); 1001395d00d1SAntti Palosaari if (ret) 1002395d00d1SAntti Palosaari goto err; 1003395d00d1SAntti Palosaari 1004395d00d1SAntti Palosaari return 0; 1005395d00d1SAntti Palosaari err: 10067978b8a1SAntti Palosaari dev_dbg(&client->dev, "failed=%d\n", ret); 1007395d00d1SAntti Palosaari return ret; 1008395d00d1SAntti Palosaari } 1009395d00d1SAntti Palosaari 101079d09330Snibble.max static int m88ds3103_set_voltage(struct dvb_frontend *fe, 10110df289a2SMauro Carvalho Chehab enum fe_sec_voltage fe_sec_voltage) 101279d09330Snibble.max { 10137978b8a1SAntti Palosaari struct m88ds3103_dev *dev = fe->demodulator_priv; 10147978b8a1SAntti Palosaari struct i2c_client *client = dev->client; 1015d28677ffSAntti Palosaari int ret; 1016478932b1SAntti Palosaari unsigned int utmp; 1017d28677ffSAntti Palosaari bool voltage_sel, voltage_dis; 101879d09330Snibble.max 10197978b8a1SAntti Palosaari dev_dbg(&client->dev, "fe_sec_voltage=%d\n", fe_sec_voltage); 102079d09330Snibble.max 10217978b8a1SAntti Palosaari if (!dev->warm) { 1022d28677ffSAntti Palosaari ret = -EAGAIN; 1023d28677ffSAntti Palosaari goto err; 1024d28677ffSAntti Palosaari } 102579d09330Snibble.max 1026d28677ffSAntti Palosaari switch (fe_sec_voltage) { 102779d09330Snibble.max case SEC_VOLTAGE_18: 1028afbd6eb4SMauro Carvalho Chehab voltage_sel = true; 1029afbd6eb4SMauro Carvalho Chehab voltage_dis = false; 103079d09330Snibble.max break; 103179d09330Snibble.max case SEC_VOLTAGE_13: 1032afbd6eb4SMauro Carvalho Chehab voltage_sel = false; 1033afbd6eb4SMauro Carvalho Chehab voltage_dis = false; 103479d09330Snibble.max break; 103579d09330Snibble.max case SEC_VOLTAGE_OFF: 1036afbd6eb4SMauro Carvalho Chehab voltage_sel = false; 1037afbd6eb4SMauro Carvalho Chehab voltage_dis = true; 103879d09330Snibble.max break; 1039d28677ffSAntti Palosaari default: 10407978b8a1SAntti Palosaari dev_dbg(&client->dev, "invalid fe_sec_voltage\n"); 1041d28677ffSAntti Palosaari ret = -EINVAL; 1042d28677ffSAntti Palosaari goto err; 104379d09330Snibble.max } 1044d28677ffSAntti Palosaari 1045d28677ffSAntti Palosaari /* output pin polarity */ 10467978b8a1SAntti Palosaari voltage_sel ^= dev->cfg->lnb_hv_pol; 10477978b8a1SAntti Palosaari voltage_dis ^= dev->cfg->lnb_en_pol; 1048d28677ffSAntti Palosaari 1049478932b1SAntti Palosaari utmp = voltage_dis << 1 | voltage_sel << 0; 105056ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0xa2, 0x03, utmp); 1051d28677ffSAntti Palosaari if (ret) 1052d28677ffSAntti Palosaari goto err; 105379d09330Snibble.max 105479d09330Snibble.max return 0; 1055d28677ffSAntti Palosaari err: 10567978b8a1SAntti Palosaari dev_dbg(&client->dev, "failed=%d\n", ret); 1057d28677ffSAntti Palosaari return ret; 105879d09330Snibble.max } 105979d09330Snibble.max 1060395d00d1SAntti Palosaari static int m88ds3103_diseqc_send_master_cmd(struct dvb_frontend *fe, 1061395d00d1SAntti Palosaari struct dvb_diseqc_master_cmd *diseqc_cmd) 1062395d00d1SAntti Palosaari { 10637978b8a1SAntti Palosaari struct m88ds3103_dev *dev = fe->demodulator_priv; 10647978b8a1SAntti Palosaari struct i2c_client *client = dev->client; 1065befa0cc1SAntti Palosaari int ret; 1066478932b1SAntti Palosaari unsigned int utmp; 1067befa0cc1SAntti Palosaari unsigned long timeout; 106841b9aa00SAntti Palosaari 10697978b8a1SAntti Palosaari dev_dbg(&client->dev, "msg=%*ph\n", 1070395d00d1SAntti Palosaari diseqc_cmd->msg_len, diseqc_cmd->msg); 1071395d00d1SAntti Palosaari 10727978b8a1SAntti Palosaari if (!dev->warm) { 1073395d00d1SAntti Palosaari ret = -EAGAIN; 1074395d00d1SAntti Palosaari goto err; 1075395d00d1SAntti Palosaari } 1076395d00d1SAntti Palosaari 1077395d00d1SAntti Palosaari if (diseqc_cmd->msg_len < 3 || diseqc_cmd->msg_len > 6) { 1078395d00d1SAntti Palosaari ret = -EINVAL; 1079395d00d1SAntti Palosaari goto err; 1080395d00d1SAntti Palosaari } 1081395d00d1SAntti Palosaari 1082478932b1SAntti Palosaari utmp = dev->cfg->envelope_mode << 5; 108356ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0xa2, 0xe0, utmp); 1084395d00d1SAntti Palosaari if (ret) 1085395d00d1SAntti Palosaari goto err; 1086395d00d1SAntti Palosaari 1087478932b1SAntti Palosaari ret = regmap_bulk_write(dev->regmap, 0xa3, diseqc_cmd->msg, 1088395d00d1SAntti Palosaari diseqc_cmd->msg_len); 1089395d00d1SAntti Palosaari if (ret) 1090395d00d1SAntti Palosaari goto err; 1091395d00d1SAntti Palosaari 1092478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xa1, 1093395d00d1SAntti Palosaari (diseqc_cmd->msg_len - 1) << 3 | 0x07); 1094395d00d1SAntti Palosaari if (ret) 1095395d00d1SAntti Palosaari goto err; 1096395d00d1SAntti Palosaari 1097395d00d1SAntti Palosaari /* wait DiSEqC TX ready */ 1098befa0cc1SAntti Palosaari #define SEND_MASTER_CMD_TIMEOUT 120 1099befa0cc1SAntti Palosaari timeout = jiffies + msecs_to_jiffies(SEND_MASTER_CMD_TIMEOUT); 1100395d00d1SAntti Palosaari 11019ef3cdc1SAntti Palosaari /* DiSEqC message period is 13.5 ms per byte */ 11029ef3cdc1SAntti Palosaari utmp = diseqc_cmd->msg_len * 13500; 11039ef3cdc1SAntti Palosaari usleep_range(utmp - 4000, utmp); 1104befa0cc1SAntti Palosaari 1105478932b1SAntti Palosaari for (utmp = 1; !time_after(jiffies, timeout) && utmp;) { 1106478932b1SAntti Palosaari ret = regmap_read(dev->regmap, 0xa1, &utmp); 1107395d00d1SAntti Palosaari if (ret) 1108395d00d1SAntti Palosaari goto err; 1109478932b1SAntti Palosaari utmp = (utmp >> 6) & 0x1; 1110395d00d1SAntti Palosaari } 1111395d00d1SAntti Palosaari 1112478932b1SAntti Palosaari if (utmp == 0) { 11137978b8a1SAntti Palosaari dev_dbg(&client->dev, "diseqc tx took %u ms\n", 1114befa0cc1SAntti Palosaari jiffies_to_msecs(jiffies) - 1115befa0cc1SAntti Palosaari (jiffies_to_msecs(timeout) - SEND_MASTER_CMD_TIMEOUT)); 1116befa0cc1SAntti Palosaari } else { 11177978b8a1SAntti Palosaari dev_dbg(&client->dev, "diseqc tx timeout\n"); 1118395d00d1SAntti Palosaari 111956ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0xa1, 0xc0, 0x40); 1120395d00d1SAntti Palosaari if (ret) 1121395d00d1SAntti Palosaari goto err; 1122395d00d1SAntti Palosaari } 1123395d00d1SAntti Palosaari 112456ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0xa2, 0xc0, 0x80); 1125395d00d1SAntti Palosaari if (ret) 1126395d00d1SAntti Palosaari goto err; 1127395d00d1SAntti Palosaari 1128478932b1SAntti Palosaari if (utmp == 1) { 1129395d00d1SAntti Palosaari ret = -ETIMEDOUT; 1130395d00d1SAntti Palosaari goto err; 1131395d00d1SAntti Palosaari } 1132395d00d1SAntti Palosaari 1133395d00d1SAntti Palosaari return 0; 1134395d00d1SAntti Palosaari err: 11357978b8a1SAntti Palosaari dev_dbg(&client->dev, "failed=%d\n", ret); 1136395d00d1SAntti Palosaari return ret; 1137395d00d1SAntti Palosaari } 1138395d00d1SAntti Palosaari 1139395d00d1SAntti Palosaari static int m88ds3103_diseqc_send_burst(struct dvb_frontend *fe, 11400df289a2SMauro Carvalho Chehab enum fe_sec_mini_cmd fe_sec_mini_cmd) 1141395d00d1SAntti Palosaari { 11427978b8a1SAntti Palosaari struct m88ds3103_dev *dev = fe->demodulator_priv; 11437978b8a1SAntti Palosaari struct i2c_client *client = dev->client; 1144befa0cc1SAntti Palosaari int ret; 1145478932b1SAntti Palosaari unsigned int utmp, burst; 1146befa0cc1SAntti Palosaari unsigned long timeout; 114741b9aa00SAntti Palosaari 11487978b8a1SAntti Palosaari dev_dbg(&client->dev, "fe_sec_mini_cmd=%d\n", fe_sec_mini_cmd); 1149395d00d1SAntti Palosaari 11507978b8a1SAntti Palosaari if (!dev->warm) { 1151395d00d1SAntti Palosaari ret = -EAGAIN; 1152395d00d1SAntti Palosaari goto err; 1153395d00d1SAntti Palosaari } 1154395d00d1SAntti Palosaari 1155478932b1SAntti Palosaari utmp = dev->cfg->envelope_mode << 5; 115656ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0xa2, 0xe0, utmp); 1157395d00d1SAntti Palosaari if (ret) 1158395d00d1SAntti Palosaari goto err; 1159395d00d1SAntti Palosaari 1160395d00d1SAntti Palosaari switch (fe_sec_mini_cmd) { 1161395d00d1SAntti Palosaari case SEC_MINI_A: 1162395d00d1SAntti Palosaari burst = 0x02; 1163395d00d1SAntti Palosaari break; 1164395d00d1SAntti Palosaari case SEC_MINI_B: 1165395d00d1SAntti Palosaari burst = 0x01; 1166395d00d1SAntti Palosaari break; 1167395d00d1SAntti Palosaari default: 11687978b8a1SAntti Palosaari dev_dbg(&client->dev, "invalid fe_sec_mini_cmd\n"); 1169395d00d1SAntti Palosaari ret = -EINVAL; 1170395d00d1SAntti Palosaari goto err; 1171395d00d1SAntti Palosaari } 1172395d00d1SAntti Palosaari 1173478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0xa1, burst); 1174395d00d1SAntti Palosaari if (ret) 1175395d00d1SAntti Palosaari goto err; 1176395d00d1SAntti Palosaari 1177395d00d1SAntti Palosaari /* wait DiSEqC TX ready */ 1178befa0cc1SAntti Palosaari #define SEND_BURST_TIMEOUT 40 1179befa0cc1SAntti Palosaari timeout = jiffies + msecs_to_jiffies(SEND_BURST_TIMEOUT); 1180395d00d1SAntti Palosaari 1181befa0cc1SAntti Palosaari /* DiSEqC ToneBurst period is 12.5 ms */ 1182befa0cc1SAntti Palosaari usleep_range(8500, 12500); 1183befa0cc1SAntti Palosaari 1184478932b1SAntti Palosaari for (utmp = 1; !time_after(jiffies, timeout) && utmp;) { 1185478932b1SAntti Palosaari ret = regmap_read(dev->regmap, 0xa1, &utmp); 1186395d00d1SAntti Palosaari if (ret) 1187395d00d1SAntti Palosaari goto err; 1188478932b1SAntti Palosaari utmp = (utmp >> 6) & 0x1; 1189395d00d1SAntti Palosaari } 1190395d00d1SAntti Palosaari 1191478932b1SAntti Palosaari if (utmp == 0) { 11927978b8a1SAntti Palosaari dev_dbg(&client->dev, "diseqc tx took %u ms\n", 1193befa0cc1SAntti Palosaari jiffies_to_msecs(jiffies) - 1194befa0cc1SAntti Palosaari (jiffies_to_msecs(timeout) - SEND_BURST_TIMEOUT)); 1195befa0cc1SAntti Palosaari } else { 11967978b8a1SAntti Palosaari dev_dbg(&client->dev, "diseqc tx timeout\n"); 1197befa0cc1SAntti Palosaari 119856ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0xa1, 0xc0, 0x40); 1199befa0cc1SAntti Palosaari if (ret) 1200befa0cc1SAntti Palosaari goto err; 1201befa0cc1SAntti Palosaari } 1202395d00d1SAntti Palosaari 120356ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0xa2, 0xc0, 0x80); 1204395d00d1SAntti Palosaari if (ret) 1205395d00d1SAntti Palosaari goto err; 1206395d00d1SAntti Palosaari 1207478932b1SAntti Palosaari if (utmp == 1) { 1208395d00d1SAntti Palosaari ret = -ETIMEDOUT; 1209395d00d1SAntti Palosaari goto err; 1210395d00d1SAntti Palosaari } 1211395d00d1SAntti Palosaari 1212395d00d1SAntti Palosaari return 0; 1213395d00d1SAntti Palosaari err: 12147978b8a1SAntti Palosaari dev_dbg(&client->dev, "failed=%d\n", ret); 1215395d00d1SAntti Palosaari return ret; 1216395d00d1SAntti Palosaari } 1217395d00d1SAntti Palosaari 1218395d00d1SAntti Palosaari static int m88ds3103_get_tune_settings(struct dvb_frontend *fe, 1219395d00d1SAntti Palosaari struct dvb_frontend_tune_settings *s) 1220395d00d1SAntti Palosaari { 1221395d00d1SAntti Palosaari s->min_delay_ms = 3000; 1222395d00d1SAntti Palosaari 1223395d00d1SAntti Palosaari return 0; 1224395d00d1SAntti Palosaari } 1225395d00d1SAntti Palosaari 122644b9055bSAntti Palosaari static void m88ds3103_release(struct dvb_frontend *fe) 1227395d00d1SAntti Palosaari { 12287978b8a1SAntti Palosaari struct m88ds3103_dev *dev = fe->demodulator_priv; 12297978b8a1SAntti Palosaari struct i2c_client *client = dev->client; 123041b9aa00SAntti Palosaari 1231f01919e8SAntti Palosaari i2c_unregister_device(client); 1232395d00d1SAntti Palosaari } 1233395d00d1SAntti Palosaari 1234e00fed40SPeter Rosin static int m88ds3103_select(struct i2c_mux_core *muxc, u32 chan) 1235395d00d1SAntti Palosaari { 1236e00fed40SPeter Rosin struct m88ds3103_dev *dev = i2c_mux_priv(muxc); 12377978b8a1SAntti Palosaari struct i2c_client *client = dev->client; 1238395d00d1SAntti Palosaari int ret; 1239478932b1SAntti Palosaari struct i2c_msg msg = { 12407978b8a1SAntti Palosaari .addr = client->addr, 1241395d00d1SAntti Palosaari .flags = 0, 1242395d00d1SAntti Palosaari .len = 2, 1243395d00d1SAntti Palosaari .buf = "\x03\x11", 1244395d00d1SAntti Palosaari }; 1245395d00d1SAntti Palosaari 1246478932b1SAntti Palosaari /* Open tuner I2C repeater for 1 xfer, closes automatically */ 1247478932b1SAntti Palosaari ret = __i2c_transfer(client->adapter, &msg, 1); 1248395d00d1SAntti Palosaari if (ret != 1) { 12497978b8a1SAntti Palosaari dev_warn(&client->dev, "i2c wr failed=%d\n", ret); 125044b9055bSAntti Palosaari if (ret >= 0) 1251395d00d1SAntti Palosaari ret = -EREMOTEIO; 1252395d00d1SAntti Palosaari return ret; 1253395d00d1SAntti Palosaari } 1254395d00d1SAntti Palosaari 125544b9055bSAntti Palosaari return 0; 125644b9055bSAntti Palosaari } 1257395d00d1SAntti Palosaari 1258f01919e8SAntti Palosaari /* 1259f01919e8SAntti Palosaari * XXX: That is wrapper to m88ds3103_probe() via driver core in order to provide 1260f01919e8SAntti Palosaari * proper I2C client for legacy media attach binding. 1261f01919e8SAntti Palosaari * New users must use I2C client binding directly! 1262f01919e8SAntti Palosaari */ 1263395d00d1SAntti Palosaari struct dvb_frontend *m88ds3103_attach(const struct m88ds3103_config *cfg, 1264b9c97c67SMauro Carvalho Chehab struct i2c_adapter *i2c, 1265b9c97c67SMauro Carvalho Chehab struct i2c_adapter **tuner_i2c_adapter) 1266395d00d1SAntti Palosaari { 1267f01919e8SAntti Palosaari struct i2c_client *client; 1268f01919e8SAntti Palosaari struct i2c_board_info board_info; 1269b9c97c67SMauro Carvalho Chehab 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)); 1286c0decac1SMauro Carvalho Chehab strscpy(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 1298bd336e63SMax Kellermann static const struct dvb_frontend_ops m88ds3103_ops = { 1299395d00d1SAntti Palosaari .delsys = {SYS_DVBS, SYS_DVBS2}, 1300395d00d1SAntti Palosaari .info = { 13017978b8a1SAntti Palosaari .name = "Montage Technology M88DS3103", 1302f1b1eabfSMauro Carvalho Chehab .frequency_min_hz = 950 * MHz, 1303f1b1eabfSMauro Carvalho Chehab .frequency_max_hz = 2150 * MHz, 1304f1b1eabfSMauro Carvalho Chehab .frequency_tolerance_hz = 5 * MHz, 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: 1412b9c97c67SMauro Carvalho Chehab ret = -ENODEV; 1413b9c97c67SMauro Carvalho Chehab dev_err(&client->dev, "Unknown device. Chip_id=%02x\n", dev->chip_id); 1414f01919e8SAntti Palosaari goto err_kfree; 1415f01919e8SAntti Palosaari } 1416f01919e8SAntti Palosaari 1417f01919e8SAntti Palosaari switch (dev->cfg->clock_out) { 1418f01919e8SAntti Palosaari case M88DS3103_CLOCK_OUT_DISABLED: 1419478932b1SAntti Palosaari utmp = 0x80; 1420f01919e8SAntti Palosaari break; 1421f01919e8SAntti Palosaari case M88DS3103_CLOCK_OUT_ENABLED: 1422478932b1SAntti Palosaari utmp = 0x00; 1423f01919e8SAntti Palosaari break; 1424f01919e8SAntti Palosaari case M88DS3103_CLOCK_OUT_ENABLED_DIV2: 1425478932b1SAntti Palosaari utmp = 0x10; 1426f01919e8SAntti Palosaari break; 1427f01919e8SAntti Palosaari default: 14284347df6aSDan Carpenter ret = -EINVAL; 1429f01919e8SAntti Palosaari goto err_kfree; 1430f01919e8SAntti Palosaari } 1431f01919e8SAntti Palosaari 1432334ef18eSAntti Palosaari if (!pdata->ts_clk) { 1433334ef18eSAntti Palosaari ret = -EINVAL; 1434334ef18eSAntti Palosaari goto err_kfree; 1435334ef18eSAntti Palosaari } 1436334ef18eSAntti Palosaari 1437f01919e8SAntti Palosaari /* 0x29 register is defined differently for m88rs6000. */ 1438f01919e8SAntti Palosaari /* set internal tuner address to 0x21 */ 1439478932b1SAntti Palosaari if (dev->chip_id == M88RS6000_CHIP_ID) 1440478932b1SAntti Palosaari utmp = 0x00; 1441f01919e8SAntti Palosaari 1442478932b1SAntti Palosaari ret = regmap_write(dev->regmap, 0x29, utmp); 1443f01919e8SAntti Palosaari if (ret) 1444f01919e8SAntti Palosaari goto err_kfree; 1445f01919e8SAntti Palosaari 1446f01919e8SAntti Palosaari /* sleep */ 144756ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x08, 0x01, 0x00); 1448f01919e8SAntti Palosaari if (ret) 1449f01919e8SAntti Palosaari goto err_kfree; 145056ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x04, 0x01, 0x01); 1451f01919e8SAntti Palosaari if (ret) 1452f01919e8SAntti Palosaari goto err_kfree; 145356ea37daSAntti Palosaari ret = m88ds3103_update_bits(dev, 0x23, 0x10, 0x10); 1454f01919e8SAntti Palosaari if (ret) 1455f01919e8SAntti Palosaari goto err_kfree; 1456f01919e8SAntti Palosaari 1457f01919e8SAntti Palosaari /* create mux i2c adapter for tuner */ 1458e00fed40SPeter Rosin dev->muxc = i2c_mux_alloc(client->adapter, &client->dev, 1, 0, 0, 1459e00fed40SPeter Rosin m88ds3103_select, NULL); 1460e00fed40SPeter Rosin if (!dev->muxc) { 14614347df6aSDan Carpenter ret = -ENOMEM; 1462f01919e8SAntti Palosaari goto err_kfree; 14634347df6aSDan Carpenter } 1464e00fed40SPeter Rosin dev->muxc->priv = dev; 1465e00fed40SPeter Rosin ret = i2c_mux_add_adapter(dev->muxc, 0, 0, 0); 1466e00fed40SPeter Rosin if (ret) 1467e00fed40SPeter Rosin goto err_kfree; 1468f01919e8SAntti Palosaari 1469f01919e8SAntti Palosaari /* create dvb_frontend */ 1470f01919e8SAntti Palosaari memcpy(&dev->fe.ops, &m88ds3103_ops, sizeof(struct dvb_frontend_ops)); 1471f01919e8SAntti Palosaari if (dev->chip_id == M88RS6000_CHIP_ID) 14727978b8a1SAntti Palosaari strncpy(dev->fe.ops.info.name, "Montage Technology M88RS6000", 14737978b8a1SAntti Palosaari sizeof(dev->fe.ops.info.name)); 1474f01919e8SAntti Palosaari if (!pdata->attach_in_use) 1475f01919e8SAntti Palosaari dev->fe.ops.release = NULL; 1476f01919e8SAntti Palosaari dev->fe.demodulator_priv = dev; 1477f01919e8SAntti Palosaari i2c_set_clientdata(client, dev); 1478f01919e8SAntti Palosaari 1479f01919e8SAntti Palosaari /* setup callbacks */ 1480f01919e8SAntti Palosaari pdata->get_dvb_frontend = m88ds3103_get_dvb_frontend; 1481f01919e8SAntti Palosaari pdata->get_i2c_adapter = m88ds3103_get_i2c_adapter; 1482f01919e8SAntti Palosaari return 0; 1483f01919e8SAntti Palosaari err_kfree: 1484f01919e8SAntti Palosaari kfree(dev); 1485f01919e8SAntti Palosaari err: 1486f01919e8SAntti Palosaari dev_dbg(&client->dev, "failed=%d\n", ret); 1487f01919e8SAntti Palosaari return ret; 1488f01919e8SAntti Palosaari } 1489f01919e8SAntti Palosaari 1490f01919e8SAntti Palosaari static int m88ds3103_remove(struct i2c_client *client) 1491f01919e8SAntti Palosaari { 14927978b8a1SAntti Palosaari struct m88ds3103_dev *dev = i2c_get_clientdata(client); 1493f01919e8SAntti Palosaari 1494f01919e8SAntti Palosaari dev_dbg(&client->dev, "\n"); 1495f01919e8SAntti Palosaari 1496e00fed40SPeter Rosin i2c_mux_del_adapters(dev->muxc); 1497f01919e8SAntti Palosaari 1498f01919e8SAntti Palosaari kfree(dev); 1499f01919e8SAntti Palosaari return 0; 1500f01919e8SAntti Palosaari } 1501f01919e8SAntti Palosaari 1502f01919e8SAntti Palosaari static const struct i2c_device_id m88ds3103_id_table[] = { 1503f01919e8SAntti Palosaari {"m88ds3103", 0}, 1504f01919e8SAntti Palosaari {} 1505f01919e8SAntti Palosaari }; 1506f01919e8SAntti Palosaari MODULE_DEVICE_TABLE(i2c, m88ds3103_id_table); 1507f01919e8SAntti Palosaari 1508f01919e8SAntti Palosaari static struct i2c_driver m88ds3103_driver = { 1509f01919e8SAntti Palosaari .driver = { 1510f01919e8SAntti Palosaari .name = "m88ds3103", 1511f01919e8SAntti Palosaari .suppress_bind_attrs = true, 1512f01919e8SAntti Palosaari }, 1513f01919e8SAntti Palosaari .probe = m88ds3103_probe, 1514f01919e8SAntti Palosaari .remove = m88ds3103_remove, 1515f01919e8SAntti Palosaari .id_table = m88ds3103_id_table, 1516f01919e8SAntti Palosaari }; 1517f01919e8SAntti Palosaari 1518f01919e8SAntti Palosaari module_i2c_driver(m88ds3103_driver); 1519f01919e8SAntti Palosaari 1520395d00d1SAntti Palosaari MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>"); 15217978b8a1SAntti Palosaari MODULE_DESCRIPTION("Montage Technology M88DS3103 DVB-S/S2 demodulator driver"); 1522395d00d1SAntti Palosaari MODULE_LICENSE("GPL"); 1523395d00d1SAntti Palosaari MODULE_FIRMWARE(M88DS3103_FIRMWARE); 1524f4df95bcSnibble.max MODULE_FIRMWARE(M88RS6000_FIRMWARE); 1525