19a0bf528SMauro Carvalho Chehab /* 29a0bf528SMauro Carvalho Chehab * Samsung s5h1432 DVB-T demodulator driver 39a0bf528SMauro Carvalho Chehab * 49a0bf528SMauro Carvalho Chehab * Copyright (C) 2009 Bill Liu <Bill.Liu@Conexant.com> 59a0bf528SMauro Carvalho Chehab * 69a0bf528SMauro Carvalho Chehab * This program is free software; you can redistribute it and/or modify 79a0bf528SMauro Carvalho Chehab * it under the terms of the GNU General Public License as published by 89a0bf528SMauro Carvalho Chehab * the Free Software Foundation; either version 2 of the License, or 99a0bf528SMauro Carvalho Chehab * (at your option) any later version. 109a0bf528SMauro Carvalho Chehab * 119a0bf528SMauro Carvalho Chehab * This program is distributed in the hope that it will be useful, 129a0bf528SMauro Carvalho Chehab * but WITHOUT ANY WARRANTY; without even the implied warranty of 139a0bf528SMauro Carvalho Chehab * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 149a0bf528SMauro Carvalho Chehab * GNU General Public License for more details. 159a0bf528SMauro Carvalho Chehab * 169a0bf528SMauro Carvalho Chehab * You should have received a copy of the GNU General Public License 179a0bf528SMauro Carvalho Chehab * along with this program; if not, write to the Free Software 189a0bf528SMauro Carvalho Chehab * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 199a0bf528SMauro Carvalho Chehab */ 209a0bf528SMauro Carvalho Chehab 219a0bf528SMauro Carvalho Chehab #include <linux/kernel.h> 229a0bf528SMauro Carvalho Chehab #include <linux/init.h> 239a0bf528SMauro Carvalho Chehab #include <linux/module.h> 249a0bf528SMauro Carvalho Chehab #include <linux/string.h> 259a0bf528SMauro Carvalho Chehab #include <linux/slab.h> 269a0bf528SMauro Carvalho Chehab #include <linux/delay.h> 279a0bf528SMauro Carvalho Chehab #include "dvb_frontend.h" 289a0bf528SMauro Carvalho Chehab #include "s5h1432.h" 299a0bf528SMauro Carvalho Chehab 309a0bf528SMauro Carvalho Chehab struct s5h1432_state { 319a0bf528SMauro Carvalho Chehab 329a0bf528SMauro Carvalho Chehab struct i2c_adapter *i2c; 339a0bf528SMauro Carvalho Chehab 349a0bf528SMauro Carvalho Chehab /* configuration settings */ 359a0bf528SMauro Carvalho Chehab const struct s5h1432_config *config; 369a0bf528SMauro Carvalho Chehab 379a0bf528SMauro Carvalho Chehab struct dvb_frontend frontend; 389a0bf528SMauro Carvalho Chehab 390df289a2SMauro Carvalho Chehab enum fe_modulation current_modulation; 409a0bf528SMauro Carvalho Chehab unsigned int first_tune:1; 419a0bf528SMauro Carvalho Chehab 429a0bf528SMauro Carvalho Chehab u32 current_frequency; 439a0bf528SMauro Carvalho Chehab int if_freq; 449a0bf528SMauro Carvalho Chehab 459a0bf528SMauro Carvalho Chehab u8 inversion; 469a0bf528SMauro Carvalho Chehab }; 479a0bf528SMauro Carvalho Chehab 489a0bf528SMauro Carvalho Chehab static int debug; 499a0bf528SMauro Carvalho Chehab 509a0bf528SMauro Carvalho Chehab #define dprintk(arg...) do { \ 519a0bf528SMauro Carvalho Chehab if (debug) \ 529a0bf528SMauro Carvalho Chehab printk(arg); \ 539a0bf528SMauro Carvalho Chehab } while (0) 549a0bf528SMauro Carvalho Chehab 559a0bf528SMauro Carvalho Chehab static int s5h1432_writereg(struct s5h1432_state *state, 569a0bf528SMauro Carvalho Chehab u8 addr, u8 reg, u8 data) 579a0bf528SMauro Carvalho Chehab { 589a0bf528SMauro Carvalho Chehab int ret; 599a0bf528SMauro Carvalho Chehab u8 buf[] = { reg, data }; 609a0bf528SMauro Carvalho Chehab 619a0bf528SMauro Carvalho Chehab struct i2c_msg msg = {.addr = addr, .flags = 0, .buf = buf, .len = 2 }; 629a0bf528SMauro Carvalho Chehab 639a0bf528SMauro Carvalho Chehab ret = i2c_transfer(state->i2c, &msg, 1); 649a0bf528SMauro Carvalho Chehab 659a0bf528SMauro Carvalho Chehab if (ret != 1) 669a0bf528SMauro Carvalho Chehab printk(KERN_ERR "%s: writereg error 0x%02x 0x%02x 0x%04x, " 679a0bf528SMauro Carvalho Chehab "ret == %i)\n", __func__, addr, reg, data, ret); 689a0bf528SMauro Carvalho Chehab 699a0bf528SMauro Carvalho Chehab return (ret != 1) ? -1 : 0; 709a0bf528SMauro Carvalho Chehab } 719a0bf528SMauro Carvalho Chehab 729a0bf528SMauro Carvalho Chehab static u8 s5h1432_readreg(struct s5h1432_state *state, u8 addr, u8 reg) 739a0bf528SMauro Carvalho Chehab { 749a0bf528SMauro Carvalho Chehab int ret; 759a0bf528SMauro Carvalho Chehab u8 b0[] = { reg }; 769a0bf528SMauro Carvalho Chehab u8 b1[] = { 0 }; 779a0bf528SMauro Carvalho Chehab 789a0bf528SMauro Carvalho Chehab struct i2c_msg msg[] = { 799a0bf528SMauro Carvalho Chehab {.addr = addr, .flags = 0, .buf = b0, .len = 1}, 809a0bf528SMauro Carvalho Chehab {.addr = addr, .flags = I2C_M_RD, .buf = b1, .len = 1} 819a0bf528SMauro Carvalho Chehab }; 829a0bf528SMauro Carvalho Chehab 839a0bf528SMauro Carvalho Chehab ret = i2c_transfer(state->i2c, msg, 2); 849a0bf528SMauro Carvalho Chehab 859a0bf528SMauro Carvalho Chehab if (ret != 2) 869a0bf528SMauro Carvalho Chehab printk(KERN_ERR "%s: readreg error (ret == %i)\n", 879a0bf528SMauro Carvalho Chehab __func__, ret); 889a0bf528SMauro Carvalho Chehab return b1[0]; 899a0bf528SMauro Carvalho Chehab } 909a0bf528SMauro Carvalho Chehab 919a0bf528SMauro Carvalho Chehab static int s5h1432_sleep(struct dvb_frontend *fe) 929a0bf528SMauro Carvalho Chehab { 939a0bf528SMauro Carvalho Chehab return 0; 949a0bf528SMauro Carvalho Chehab } 959a0bf528SMauro Carvalho Chehab 969a0bf528SMauro Carvalho Chehab static int s5h1432_set_channel_bandwidth(struct dvb_frontend *fe, 979a0bf528SMauro Carvalho Chehab u32 bandwidth) 989a0bf528SMauro Carvalho Chehab { 999a0bf528SMauro Carvalho Chehab struct s5h1432_state *state = fe->demodulator_priv; 1009a0bf528SMauro Carvalho Chehab 1019a0bf528SMauro Carvalho Chehab u8 reg = 0; 1029a0bf528SMauro Carvalho Chehab 1039a0bf528SMauro Carvalho Chehab /* Register [0x2E] bit 3:2 : 8MHz = 0; 7MHz = 1; 6MHz = 2 */ 1049a0bf528SMauro Carvalho Chehab reg = s5h1432_readreg(state, S5H1432_I2C_TOP_ADDR, 0x2E); 1059a0bf528SMauro Carvalho Chehab reg &= ~(0x0C); 1069a0bf528SMauro Carvalho Chehab switch (bandwidth) { 1079a0bf528SMauro Carvalho Chehab case 6: 1089a0bf528SMauro Carvalho Chehab reg |= 0x08; 1099a0bf528SMauro Carvalho Chehab break; 1109a0bf528SMauro Carvalho Chehab case 7: 1119a0bf528SMauro Carvalho Chehab reg |= 0x04; 1129a0bf528SMauro Carvalho Chehab break; 1139a0bf528SMauro Carvalho Chehab case 8: 1149a0bf528SMauro Carvalho Chehab reg |= 0x00; 1159a0bf528SMauro Carvalho Chehab break; 1169a0bf528SMauro Carvalho Chehab default: 1179a0bf528SMauro Carvalho Chehab return 0; 1189a0bf528SMauro Carvalho Chehab } 1199a0bf528SMauro Carvalho Chehab s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0x2E, reg); 1209a0bf528SMauro Carvalho Chehab return 1; 1219a0bf528SMauro Carvalho Chehab } 1229a0bf528SMauro Carvalho Chehab 1239a0bf528SMauro Carvalho Chehab static int s5h1432_set_IF(struct dvb_frontend *fe, u32 ifFreqHz) 1249a0bf528SMauro Carvalho Chehab { 1259a0bf528SMauro Carvalho Chehab struct s5h1432_state *state = fe->demodulator_priv; 1269a0bf528SMauro Carvalho Chehab 1279a0bf528SMauro Carvalho Chehab switch (ifFreqHz) { 1289a0bf528SMauro Carvalho Chehab case TAIWAN_HI_IF_FREQ_44_MHZ: 1299a0bf528SMauro Carvalho Chehab s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xe4, 0x55); 1309a0bf528SMauro Carvalho Chehab s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xe5, 0x55); 1319a0bf528SMauro Carvalho Chehab s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xe7, 0x15); 1329a0bf528SMauro Carvalho Chehab break; 1339a0bf528SMauro Carvalho Chehab case EUROPE_HI_IF_FREQ_36_MHZ: 1349a0bf528SMauro Carvalho Chehab s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xe4, 0x00); 1359a0bf528SMauro Carvalho Chehab s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xe5, 0x00); 1369a0bf528SMauro Carvalho Chehab s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xe7, 0x40); 1379a0bf528SMauro Carvalho Chehab break; 1389a0bf528SMauro Carvalho Chehab case IF_FREQ_6_MHZ: 1399a0bf528SMauro Carvalho Chehab s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xe4, 0x00); 1409a0bf528SMauro Carvalho Chehab s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xe5, 0x00); 1419a0bf528SMauro Carvalho Chehab s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xe7, 0xe0); 1429a0bf528SMauro Carvalho Chehab break; 1439a0bf528SMauro Carvalho Chehab case IF_FREQ_3point3_MHZ: 1449a0bf528SMauro Carvalho Chehab s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xe4, 0x66); 1459a0bf528SMauro Carvalho Chehab s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xe5, 0x66); 1469a0bf528SMauro Carvalho Chehab s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xe7, 0xEE); 1479a0bf528SMauro Carvalho Chehab break; 1489a0bf528SMauro Carvalho Chehab case IF_FREQ_3point5_MHZ: 1499a0bf528SMauro Carvalho Chehab s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xe4, 0x55); 1509a0bf528SMauro Carvalho Chehab s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xe5, 0x55); 1519a0bf528SMauro Carvalho Chehab s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xe7, 0xED); 1529a0bf528SMauro Carvalho Chehab break; 1539a0bf528SMauro Carvalho Chehab case IF_FREQ_4_MHZ: 1549a0bf528SMauro Carvalho Chehab s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xe4, 0xAA); 1559a0bf528SMauro Carvalho Chehab s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xe5, 0xAA); 1569a0bf528SMauro Carvalho Chehab s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xe7, 0xEA); 1579a0bf528SMauro Carvalho Chehab break; 1589a0bf528SMauro Carvalho Chehab default: 1599a0bf528SMauro Carvalho Chehab { 1609a0bf528SMauro Carvalho Chehab u32 value = 0; 1619a0bf528SMauro Carvalho Chehab value = (u32) (((48000 - (ifFreqHz / 1000)) * 512 * 1629a0bf528SMauro Carvalho Chehab (u32) 32768) / (48 * 1000)); 1639a0bf528SMauro Carvalho Chehab printk(KERN_INFO 1649a0bf528SMauro Carvalho Chehab "Default IFFreq %d :reg value = 0x%x\n", 1659a0bf528SMauro Carvalho Chehab ifFreqHz, value); 1669a0bf528SMauro Carvalho Chehab s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xe4, 1679a0bf528SMauro Carvalho Chehab (u8) value & 0xFF); 1689a0bf528SMauro Carvalho Chehab s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xe5, 1699a0bf528SMauro Carvalho Chehab (u8) (value >> 8) & 0xFF); 1709a0bf528SMauro Carvalho Chehab s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xe7, 1719a0bf528SMauro Carvalho Chehab (u8) (value >> 16) & 0xFF); 1729a0bf528SMauro Carvalho Chehab break; 1739a0bf528SMauro Carvalho Chehab } 1749a0bf528SMauro Carvalho Chehab 1759a0bf528SMauro Carvalho Chehab } 1769a0bf528SMauro Carvalho Chehab 1779a0bf528SMauro Carvalho Chehab return 1; 1789a0bf528SMauro Carvalho Chehab } 1799a0bf528SMauro Carvalho Chehab 1809a0bf528SMauro Carvalho Chehab /* Talk to the demod, set the FEC, GUARD, QAM settings etc */ 1819a0bf528SMauro Carvalho Chehab static int s5h1432_set_frontend(struct dvb_frontend *fe) 1829a0bf528SMauro Carvalho Chehab { 1839a0bf528SMauro Carvalho Chehab struct dtv_frontend_properties *p = &fe->dtv_property_cache; 1849a0bf528SMauro Carvalho Chehab u32 dvb_bandwidth = 8; 1859a0bf528SMauro Carvalho Chehab struct s5h1432_state *state = fe->demodulator_priv; 1869a0bf528SMauro Carvalho Chehab 1879a0bf528SMauro Carvalho Chehab if (p->frequency == state->current_frequency) { 1889a0bf528SMauro Carvalho Chehab /*current_frequency = p->frequency; */ 1899a0bf528SMauro Carvalho Chehab /*state->current_frequency = p->frequency; */ 1909a0bf528SMauro Carvalho Chehab } else { 1919a0bf528SMauro Carvalho Chehab fe->ops.tuner_ops.set_params(fe); 1929a0bf528SMauro Carvalho Chehab msleep(300); 1939a0bf528SMauro Carvalho Chehab s5h1432_set_channel_bandwidth(fe, dvb_bandwidth); 1949a0bf528SMauro Carvalho Chehab switch (p->bandwidth_hz) { 1959a0bf528SMauro Carvalho Chehab case 6000000: 1969a0bf528SMauro Carvalho Chehab dvb_bandwidth = 6; 1979a0bf528SMauro Carvalho Chehab s5h1432_set_IF(fe, IF_FREQ_4_MHZ); 1989a0bf528SMauro Carvalho Chehab break; 1999a0bf528SMauro Carvalho Chehab case 7000000: 2009a0bf528SMauro Carvalho Chehab dvb_bandwidth = 7; 2019a0bf528SMauro Carvalho Chehab s5h1432_set_IF(fe, IF_FREQ_4_MHZ); 2029a0bf528SMauro Carvalho Chehab break; 2039a0bf528SMauro Carvalho Chehab case 8000000: 2049a0bf528SMauro Carvalho Chehab dvb_bandwidth = 8; 2059a0bf528SMauro Carvalho Chehab s5h1432_set_IF(fe, IF_FREQ_4_MHZ); 2069a0bf528SMauro Carvalho Chehab break; 2079a0bf528SMauro Carvalho Chehab default: 2089a0bf528SMauro Carvalho Chehab return 0; 2099a0bf528SMauro Carvalho Chehab } 2109a0bf528SMauro Carvalho Chehab /*fe->ops.tuner_ops.set_params(fe); */ 2119a0bf528SMauro Carvalho Chehab /*Soft Reset chip*/ 2129a0bf528SMauro Carvalho Chehab msleep(30); 2139a0bf528SMauro Carvalho Chehab s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0x09, 0x1a); 2149a0bf528SMauro Carvalho Chehab msleep(30); 2159a0bf528SMauro Carvalho Chehab s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0x09, 0x1b); 2169a0bf528SMauro Carvalho Chehab 2179a0bf528SMauro Carvalho Chehab s5h1432_set_channel_bandwidth(fe, dvb_bandwidth); 2189a0bf528SMauro Carvalho Chehab switch (p->bandwidth_hz) { 2199a0bf528SMauro Carvalho Chehab case 6000000: 2209a0bf528SMauro Carvalho Chehab dvb_bandwidth = 6; 2219a0bf528SMauro Carvalho Chehab s5h1432_set_IF(fe, IF_FREQ_4_MHZ); 2229a0bf528SMauro Carvalho Chehab break; 2239a0bf528SMauro Carvalho Chehab case 7000000: 2249a0bf528SMauro Carvalho Chehab dvb_bandwidth = 7; 2259a0bf528SMauro Carvalho Chehab s5h1432_set_IF(fe, IF_FREQ_4_MHZ); 2269a0bf528SMauro Carvalho Chehab break; 2279a0bf528SMauro Carvalho Chehab case 8000000: 2289a0bf528SMauro Carvalho Chehab dvb_bandwidth = 8; 2299a0bf528SMauro Carvalho Chehab s5h1432_set_IF(fe, IF_FREQ_4_MHZ); 2309a0bf528SMauro Carvalho Chehab break; 2319a0bf528SMauro Carvalho Chehab default: 2329a0bf528SMauro Carvalho Chehab return 0; 2339a0bf528SMauro Carvalho Chehab } 2349a0bf528SMauro Carvalho Chehab /*fe->ops.tuner_ops.set_params(fe); */ 2359a0bf528SMauro Carvalho Chehab /*Soft Reset chip*/ 2369a0bf528SMauro Carvalho Chehab msleep(30); 2379a0bf528SMauro Carvalho Chehab s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0x09, 0x1a); 2389a0bf528SMauro Carvalho Chehab msleep(30); 2399a0bf528SMauro Carvalho Chehab s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0x09, 0x1b); 2409a0bf528SMauro Carvalho Chehab 2419a0bf528SMauro Carvalho Chehab } 2429a0bf528SMauro Carvalho Chehab 2439a0bf528SMauro Carvalho Chehab state->current_frequency = p->frequency; 2449a0bf528SMauro Carvalho Chehab 2459a0bf528SMauro Carvalho Chehab return 0; 2469a0bf528SMauro Carvalho Chehab } 2479a0bf528SMauro Carvalho Chehab 2489a0bf528SMauro Carvalho Chehab static int s5h1432_init(struct dvb_frontend *fe) 2499a0bf528SMauro Carvalho Chehab { 2509a0bf528SMauro Carvalho Chehab struct s5h1432_state *state = fe->demodulator_priv; 2519a0bf528SMauro Carvalho Chehab 2529a0bf528SMauro Carvalho Chehab u8 reg = 0; 2539a0bf528SMauro Carvalho Chehab state->current_frequency = 0; 2549a0bf528SMauro Carvalho Chehab printk(KERN_INFO " s5h1432_init().\n"); 2559a0bf528SMauro Carvalho Chehab 2569a0bf528SMauro Carvalho Chehab /*Set VSB mode as default, this also does a soft reset */ 2579a0bf528SMauro Carvalho Chehab /*Initialize registers */ 2589a0bf528SMauro Carvalho Chehab 2599a0bf528SMauro Carvalho Chehab s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0x04, 0xa8); 2609a0bf528SMauro Carvalho Chehab s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0x05, 0x01); 2619a0bf528SMauro Carvalho Chehab s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0x07, 0x70); 2629a0bf528SMauro Carvalho Chehab s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0x19, 0x80); 2639a0bf528SMauro Carvalho Chehab s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0x1b, 0x9D); 2649a0bf528SMauro Carvalho Chehab s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0x1c, 0x30); 2659a0bf528SMauro Carvalho Chehab s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0x1d, 0x20); 2669a0bf528SMauro Carvalho Chehab s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0x1e, 0x1B); 2679a0bf528SMauro Carvalho Chehab s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0x2e, 0x40); 2689a0bf528SMauro Carvalho Chehab s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0x42, 0x84); 2699a0bf528SMauro Carvalho Chehab s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0x50, 0x5a); 2709a0bf528SMauro Carvalho Chehab s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0x5a, 0xd3); 2719a0bf528SMauro Carvalho Chehab s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0x68, 0x50); 2729a0bf528SMauro Carvalho Chehab s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xb8, 0x3c); 2739a0bf528SMauro Carvalho Chehab s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xc4, 0x10); 2749a0bf528SMauro Carvalho Chehab s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xcc, 0x9c); 2759a0bf528SMauro Carvalho Chehab s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xDA, 0x00); 2769a0bf528SMauro Carvalho Chehab s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xe1, 0x94); 2779a0bf528SMauro Carvalho Chehab /* s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xf4, 0xa1); */ 2789a0bf528SMauro Carvalho Chehab s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xf9, 0x00); 2799a0bf528SMauro Carvalho Chehab 2809a0bf528SMauro Carvalho Chehab /*For NXP tuner*/ 2819a0bf528SMauro Carvalho Chehab 2829a0bf528SMauro Carvalho Chehab /*Set 3.3MHz as default IF frequency */ 2839a0bf528SMauro Carvalho Chehab s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xe4, 0x66); 2849a0bf528SMauro Carvalho Chehab s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xe5, 0x66); 2859a0bf528SMauro Carvalho Chehab s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0xe7, 0xEE); 2869a0bf528SMauro Carvalho Chehab /* Set reg 0x1E to get the full dynamic range */ 2879a0bf528SMauro Carvalho Chehab s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0x1e, 0x31); 2889a0bf528SMauro Carvalho Chehab 2899a0bf528SMauro Carvalho Chehab /* Mode setting in demod */ 2909a0bf528SMauro Carvalho Chehab reg = s5h1432_readreg(state, S5H1432_I2C_TOP_ADDR, 0x42); 2919a0bf528SMauro Carvalho Chehab reg |= 0x80; 2929a0bf528SMauro Carvalho Chehab s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0x42, reg); 2939a0bf528SMauro Carvalho Chehab /* Serial mode */ 2949a0bf528SMauro Carvalho Chehab 2959a0bf528SMauro Carvalho Chehab /* Soft Reset chip */ 2969a0bf528SMauro Carvalho Chehab 2979a0bf528SMauro Carvalho Chehab s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0x09, 0x1a); 2989a0bf528SMauro Carvalho Chehab msleep(30); 2999a0bf528SMauro Carvalho Chehab s5h1432_writereg(state, S5H1432_I2C_TOP_ADDR, 0x09, 0x1b); 3009a0bf528SMauro Carvalho Chehab 3019a0bf528SMauro Carvalho Chehab 3029a0bf528SMauro Carvalho Chehab return 0; 3039a0bf528SMauro Carvalho Chehab } 3049a0bf528SMauro Carvalho Chehab 3050df289a2SMauro Carvalho Chehab static int s5h1432_read_status(struct dvb_frontend *fe, enum fe_status *status) 3069a0bf528SMauro Carvalho Chehab { 3079a0bf528SMauro Carvalho Chehab return 0; 3089a0bf528SMauro Carvalho Chehab } 3099a0bf528SMauro Carvalho Chehab 3109a0bf528SMauro Carvalho Chehab static int s5h1432_read_signal_strength(struct dvb_frontend *fe, 3119a0bf528SMauro Carvalho Chehab u16 *signal_strength) 3129a0bf528SMauro Carvalho Chehab { 3139a0bf528SMauro Carvalho Chehab return 0; 3149a0bf528SMauro Carvalho Chehab } 3159a0bf528SMauro Carvalho Chehab 3169a0bf528SMauro Carvalho Chehab static int s5h1432_read_snr(struct dvb_frontend *fe, u16 *snr) 3179a0bf528SMauro Carvalho Chehab { 3189a0bf528SMauro Carvalho Chehab return 0; 3199a0bf528SMauro Carvalho Chehab } 3209a0bf528SMauro Carvalho Chehab 3219a0bf528SMauro Carvalho Chehab static int s5h1432_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks) 3229a0bf528SMauro Carvalho Chehab { 3239a0bf528SMauro Carvalho Chehab 3249a0bf528SMauro Carvalho Chehab return 0; 3259a0bf528SMauro Carvalho Chehab } 3269a0bf528SMauro Carvalho Chehab 3279a0bf528SMauro Carvalho Chehab static int s5h1432_read_ber(struct dvb_frontend *fe, u32 *ber) 3289a0bf528SMauro Carvalho Chehab { 3299a0bf528SMauro Carvalho Chehab return 0; 3309a0bf528SMauro Carvalho Chehab } 3319a0bf528SMauro Carvalho Chehab 3329a0bf528SMauro Carvalho Chehab static int s5h1432_get_tune_settings(struct dvb_frontend *fe, 3339a0bf528SMauro Carvalho Chehab struct dvb_frontend_tune_settings *tune) 3349a0bf528SMauro Carvalho Chehab { 3359a0bf528SMauro Carvalho Chehab return 0; 3369a0bf528SMauro Carvalho Chehab } 3379a0bf528SMauro Carvalho Chehab 3389a0bf528SMauro Carvalho Chehab static void s5h1432_release(struct dvb_frontend *fe) 3399a0bf528SMauro Carvalho Chehab { 3409a0bf528SMauro Carvalho Chehab struct s5h1432_state *state = fe->demodulator_priv; 3419a0bf528SMauro Carvalho Chehab kfree(state); 3429a0bf528SMauro Carvalho Chehab } 3439a0bf528SMauro Carvalho Chehab 3449a0bf528SMauro Carvalho Chehab static struct dvb_frontend_ops s5h1432_ops; 3459a0bf528SMauro Carvalho Chehab 3469a0bf528SMauro Carvalho Chehab struct dvb_frontend *s5h1432_attach(const struct s5h1432_config *config, 3479a0bf528SMauro Carvalho Chehab struct i2c_adapter *i2c) 3489a0bf528SMauro Carvalho Chehab { 3499a0bf528SMauro Carvalho Chehab struct s5h1432_state *state = NULL; 3509a0bf528SMauro Carvalho Chehab 3519a0bf528SMauro Carvalho Chehab printk(KERN_INFO " Enter s5h1432_attach(). attach success!\n"); 3529a0bf528SMauro Carvalho Chehab /* allocate memory for the internal state */ 3539a0bf528SMauro Carvalho Chehab state = kmalloc(sizeof(struct s5h1432_state), GFP_KERNEL); 35447aab4abSPeter Senna Tschudin if (!state) 35547aab4abSPeter Senna Tschudin return NULL; 3569a0bf528SMauro Carvalho Chehab 3579a0bf528SMauro Carvalho Chehab /* setup the state */ 3589a0bf528SMauro Carvalho Chehab state->config = config; 3599a0bf528SMauro Carvalho Chehab state->i2c = i2c; 3609a0bf528SMauro Carvalho Chehab state->current_modulation = QAM_16; 3619a0bf528SMauro Carvalho Chehab state->inversion = state->config->inversion; 3629a0bf528SMauro Carvalho Chehab 3639a0bf528SMauro Carvalho Chehab /* create dvb_frontend */ 3649a0bf528SMauro Carvalho Chehab memcpy(&state->frontend.ops, &s5h1432_ops, 3659a0bf528SMauro Carvalho Chehab sizeof(struct dvb_frontend_ops)); 3669a0bf528SMauro Carvalho Chehab 3679a0bf528SMauro Carvalho Chehab state->frontend.demodulator_priv = state; 3689a0bf528SMauro Carvalho Chehab 3699a0bf528SMauro Carvalho Chehab return &state->frontend; 3709a0bf528SMauro Carvalho Chehab } 3719a0bf528SMauro Carvalho Chehab EXPORT_SYMBOL(s5h1432_attach); 3729a0bf528SMauro Carvalho Chehab 3739a0bf528SMauro Carvalho Chehab static struct dvb_frontend_ops s5h1432_ops = { 3749a0bf528SMauro Carvalho Chehab .delsys = { SYS_DVBT }, 3759a0bf528SMauro Carvalho Chehab .info = { 3769a0bf528SMauro Carvalho Chehab .name = "Samsung s5h1432 DVB-T Frontend", 3779a0bf528SMauro Carvalho Chehab .frequency_min = 177000000, 3789a0bf528SMauro Carvalho Chehab .frequency_max = 858000000, 3799a0bf528SMauro Carvalho Chehab .frequency_stepsize = 166666, 3809a0bf528SMauro Carvalho Chehab .caps = FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 | 3819a0bf528SMauro Carvalho Chehab FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO | 3829a0bf528SMauro Carvalho Chehab FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO | 3839a0bf528SMauro Carvalho Chehab FE_CAN_HIERARCHY_AUTO | FE_CAN_GUARD_INTERVAL_AUTO | 3849a0bf528SMauro Carvalho Chehab FE_CAN_TRANSMISSION_MODE_AUTO | FE_CAN_RECOVER}, 3859a0bf528SMauro Carvalho Chehab 3869a0bf528SMauro Carvalho Chehab .init = s5h1432_init, 3879a0bf528SMauro Carvalho Chehab .sleep = s5h1432_sleep, 3889a0bf528SMauro Carvalho Chehab .set_frontend = s5h1432_set_frontend, 3899a0bf528SMauro Carvalho Chehab .get_tune_settings = s5h1432_get_tune_settings, 3909a0bf528SMauro Carvalho Chehab .read_status = s5h1432_read_status, 3919a0bf528SMauro Carvalho Chehab .read_ber = s5h1432_read_ber, 3929a0bf528SMauro Carvalho Chehab .read_signal_strength = s5h1432_read_signal_strength, 3939a0bf528SMauro Carvalho Chehab .read_snr = s5h1432_read_snr, 3949a0bf528SMauro Carvalho Chehab .read_ucblocks = s5h1432_read_ucblocks, 3959a0bf528SMauro Carvalho Chehab .release = s5h1432_release, 3969a0bf528SMauro Carvalho Chehab }; 3979a0bf528SMauro Carvalho Chehab 3989a0bf528SMauro Carvalho Chehab module_param(debug, int, 0644); 3999a0bf528SMauro Carvalho Chehab MODULE_PARM_DESC(debug, "Enable verbose debug messages"); 4009a0bf528SMauro Carvalho Chehab 4019a0bf528SMauro Carvalho Chehab MODULE_DESCRIPTION("Samsung s5h1432 DVB-T Demodulator driver"); 4029a0bf528SMauro Carvalho Chehab MODULE_AUTHOR("Bill Liu"); 4039a0bf528SMauro Carvalho Chehab MODULE_LICENSE("GPL"); 404