// SPDX-License-Identifier: GPL-2.0-only
/*
* Sharp VA3A5JZ921 One Seg Broadcast Module driver
* This device is labeled as just S. 921 at the top of the frontend can
*
* Copyright (C) 2009-2010 Mauro Carvalho Chehab
* Copyright (C) 2009-2010 Douglas Landgraf <dougsland@redhat.com>
*
* Developed for Leadership SBTVD 1seg device sold in Brazil
*
* Frontend module based on cx24123 driver, getting some info from
* the old s921 driver.
*
* FIXME: Need to port to DVB v5.2 API
*/
#include <linux/kernel.h>
#include <asm /div64.h>
#include <media/dvb_frontend.h>
#include "s921.h"
static int debug = 1 ;
module_param(debug, int , 0644 );
MODULE_PARM_DESC(debug, "Activates frontend debugging (default:0)" );
#define rc(args...) do { \
printk(KERN_ERR "s921: " args); \
} while (0 )
#define dprintk(args...) \
do { \
if (debug) { \
printk(KERN_DEBUG "s921: %s: " , __func__); \
printk(args); \
} \
} while (0 )
struct s921_state {
struct i2c_adapter *i2c;
const struct s921_config *config;
struct dvb_frontend frontend;
/* The Demod can't easily provide these, we cache them */
u32 currentfreq;
};
/*
* Various tuner defaults need to be established for a given frequency kHz.
* fixme: The bounds on the bands do not match the doc in real life.
* fixme: Some of them have been moved, other might need adjustment.
*/
static struct s921_bandselect_val {
u32 freq_low;
u8 band_reg;
} s921_bandselect[] = {
{ 0 , 0 x7b },
{ 485140000 , 0 x5b },
{ 515140000 , 0 x3b },
{ 545140000 , 0 x1b },
{ 599140000 , 0 xfb },
{ 623140000 , 0 xdb },
{ 659140000 , 0 xbb },
{ 713140000 , 0 x9b },
};
struct regdata {
u8 reg;
u8 data;
};
static struct regdata s921_init[] = {
{ 0 x01, 0 x80 }, /* Probably, a reset sequence */
{ 0 x01, 0 x40 },
{ 0 x01, 0 x80 },
{ 0 x01, 0 x40 },
{ 0 x02, 0 x00 },
{ 0 x03, 0 x40 },
{ 0 x04, 0 x01 },
{ 0 x05, 0 x00 },
{ 0 x06, 0 x00 },
{ 0 x07, 0 x00 },
{ 0 x08, 0 x00 },
{ 0 x09, 0 x00 },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 x6e, 0 x00 },
{ 0 x70, 0 x10 },
{ 0 x71, 0 x00 },
{ 0 x75, 0 x00 },
{ 0 x76, 0 x30 },
{ 0 x77, 0 x01 },
{ 0 xaf, 0 x00 },
{ 0 xb0, 0 xa0 },
{ 0 xb2, 0 x3d },
{ 0 xb3, 0 x25 },
{ 0 xb4, 0 x8b },
{ 0 xb5, 0 x4b },
{ 0 xb6, 0 x3f },
{ 0 xb7, 0 xff },
{ 0 xb8, 0 xff },
{ 0 xb9, 0 xfc },
{ 0 xba, 0 x00 },
{ 0 xbb, 0 x00 },
{ 0 xbc, 0 x00 },
{ 0 xd0, 0 x30 },
{ 0 xe4, 0 x84 },
{ 0 xf0, 0 x48 },
{ 0 xf1, 0 x19 },
{ 0 xf2, 0 x5a },
{ 0 xf3, 0 x8e },
{ 0 xf4, 0 x2d },
{ 0 xf5, 0 x07 },
{ 0 xf6, 0 x5a },
{ 0 xf7, 0 xba },
{ 0 xf8, 0 xd7 },
};
static struct regdata s921_prefreq[] = {
{ 0 x47, 0 x60 },
{ 0 x68, 0 x00 },
{ 0 x69, 0 x89 },
{ 0 xf0, 0 x48 },
{ 0 xf1, 0 x19 },
};
static struct regdata s921_postfreq[] = {
{ 0 xf5, 0 xae },
{ 0 xf6, 0 xb7 },
{ 0 xf7, 0 xba },
{ 0 xf8, 0 xd7 },
{ 0 x68, 0 x0a },
{ 0 x69, 0 x09 },
};
static int s921_i2c_writereg(struct s921_state *state,
u8 i2c_addr, int reg, int data)
{
u8 buf[] = { reg, data };
struct i2c_msg msg = {
.addr = i2c_addr, .flags = 0 , .buf = buf, .len = 2
};
int rc;
rc = i2c_transfer(state->i2c, &msg, 1 );
if (rc != 1 ) {
printk("%s: writereg rcor(rc == %i, reg == 0x%02x, data == 0x%02x)\n" ,
__func__, rc, reg, data);
return rc;
}
return 0 ;
}
static int s921_i2c_writeregdata(struct s921_state *state, u8 i2c_addr,
struct regdata *rd, int size)
{
int i, rc;
for (i = 0 ; i < size; i++) {
rc = s921_i2c_writereg(state, i2c_addr, rd[i].reg, rd[i].data);
if (rc < 0 )
return rc;
}
return 0 ;
}
static int s921_i2c_readreg(struct s921_state *state, u8 i2c_addr, u8 reg)
{
u8 val;
int rc;
struct i2c_msg msg[] = {
{ .addr = i2c_addr, .flags = 0 , .buf = ®, .len = 1 },
{ .addr = i2c_addr, .flags = I2C_M_RD, .buf = &val, .len = 1 }
};
rc = i2c_transfer(state->i2c, msg, 2 );
if (rc != 2 ) {
rc("%s: reg=0x%x (rcor=%d)\n" , __func__, reg, rc);
return rc;
}
return val;
}
#define s921_readreg(state, reg) \
s921_i2c_readreg(state, state->config->demod_address, reg)
#define s921_writereg(state, reg, val) \
s921_i2c_writereg(state, state->config->demod_address, reg, val)
#define s921_writeregdata(state, regdata) \
s921_i2c_writeregdata(state, state->config->demod_address, \
regdata, ARRAY_SIZE(regdata))
static int s921_pll_tune(struct dvb_frontend *fe)
{
struct dtv_frontend_properties *p = &fe->dtv_property_cache;
struct s921_state *state = fe->demodulator_priv;
int band, rc, i;
unsigned long f_offset;
u8 f_switch;
u64 offset;
dprintk("frequency=%i\n" , p->frequency);
for (band = 0 ; band < ARRAY_SIZE(s921_bandselect); band++)
if (p->frequency < s921_bandselect[band].freq_low)
break ;
band--;
if (band < 0 ) {
rc("%s: frequency out of range\n" , __func__);
return -EINVAL;
}
f_switch = s921_bandselect[band].band_reg;
offset = ((u64)p->frequency) * 258 ;
do_div(offset, 6000000 );
f_offset = ((unsigned long )offset) + 2321 ;
rc = s921_writeregdata(state, s921_prefreq);
if (rc < 0 )
return rc;
rc = s921_writereg(state, 0 xf2, (f_offset >> 8 ) & 0 xff);
if (rc < 0 )
return rc;
rc = s921_writereg(state, 0 xf3, f_offset & 0 xff);
if (rc < 0 )
return rc;
rc = s921_writereg(state, 0 xf4, f_switch);
if (rc < 0 )
return rc;
rc = s921_writeregdata(state, s921_postfreq);
if (rc < 0 )
return rc;
for (i = 0 ; i < 6 ; i++) {
rc = s921_readreg(state, 0 x80);
dprintk("status 0x80: %02x\n" , rc);
}
rc = s921_writereg(state, 0 x01, 0 x40);
if (rc < 0 )
return rc;
rc = s921_readreg(state, 0 x01);
dprintk("status 0x01: %02x\n" , rc);
rc = s921_readreg(state, 0 x80);
dprintk("status 0x80: %02x\n" , rc);
rc = s921_readreg(state, 0 x80);
dprintk("status 0x80: %02x\n" , rc);
rc = s921_readreg(state, 0 x32);
dprintk("status 0x32: %02x\n" , rc);
dprintk("pll tune band=%d, pll=%d\n" , f_switch, (int )f_offset);
return 0 ;
}
static int s921_initfe(struct dvb_frontend *fe)
{
struct s921_state *state = fe->demodulator_priv;
int rc;
dprintk("\n" );
rc = s921_writeregdata(state, s921_init);
if (rc < 0 )
return rc;
return 0 ;
}
static int s921_read_status(struct dvb_frontend *fe, enum fe_status *status)
{
struct s921_state *state = fe->demodulator_priv;
int regstatus, rc;
*status = 0 ;
rc = s921_readreg(state, 0 x81);
if (rc < 0 )
return rc;
regstatus = rc << 8 ;
rc = s921_readreg(state, 0 x82);
if (rc < 0 )
return rc;
regstatus |= rc;
dprintk("status = %04x\n" , regstatus);
/* Full Sync - We don't know what each bit means on regs 0x81/0x82 */
if ((regstatus & 0 xff) == 0 x40) {
*status = FE_HAS_SIGNAL |
FE_HAS_CARRIER |
FE_HAS_VITERBI |
FE_HAS_SYNC |
FE_HAS_LOCK;
} else if (regstatus & 0 x40) {
/* This is close to Full Sync, but not enough to get useful info */
*status = FE_HAS_SIGNAL |
FE_HAS_CARRIER |
FE_HAS_VITERBI |
FE_HAS_SYNC;
}
return 0 ;
}
static int s921_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
{
enum fe_status status;
struct s921_state *state = fe->demodulator_priv;
int rc;
/* FIXME: Use the proper register for it... 0x80? */
rc = s921_read_status(fe, &status);
if (rc < 0 )
return rc;
*strength = (status & FE_HAS_LOCK) ? 0 xffff : 0 ;
dprintk("strength = 0x%04x\n" , *strength);
rc = s921_readreg(state, 0 x01);
dprintk("status 0x01: %02x\n" , rc);
rc = s921_readreg(state, 0 x80);
dprintk("status 0x80: %02x\n" , rc);
rc = s921_readreg(state, 0 x32);
dprintk("status 0x32: %02x\n" , rc);
return 0 ;
}
static int s921_set_frontend(struct dvb_frontend *fe)
{
struct dtv_frontend_properties *p = &fe->dtv_property_cache;
struct s921_state *state = fe->demodulator_priv;
int rc;
dprintk("\n" );
/* FIXME: We don't know how to use non-auto mode */
rc = s921_pll_tune(fe);
if (rc < 0 )
return rc;
state->currentfreq = p->frequency;
return 0 ;
}
static int s921_get_frontend(struct dvb_frontend *fe,
struct dtv_frontend_properties *p)
{
struct s921_state *state = fe->demodulator_priv;
/* FIXME: Probably it is possible to get it from regs f1 and f2 */
p->frequency = state->currentfreq;
p->delivery_system = SYS_ISDBT;
return 0 ;
}
static int s921_tune(struct dvb_frontend *fe,
bool re_tune,
unsigned int mode_flags,
unsigned int *delay,
enum fe_status *status)
{
int rc = 0 ;
dprintk("\n" );
if (re_tune)
rc = s921_set_frontend(fe);
if (!(mode_flags & FE_TUNE_MODE_ONESHOT))
s921_read_status(fe, status);
return rc;
}
static enum dvbfe_algo s921_get_algo(struct dvb_frontend *fe)
{
return DVBFE_ALGO_HW;
}
static void s921_release(struct dvb_frontend *fe)
{
struct s921_state *state = fe->demodulator_priv;
dprintk("\n" );
kfree(state);
}
static const struct dvb_frontend_ops s921_ops;
struct dvb_frontend *s921_attach(const struct s921_config *config,
struct i2c_adapter *i2c)
{
/* allocate memory for the internal state */
struct s921_state *state =
kzalloc(sizeof (struct s921_state), GFP_KERNEL);
dprintk("\n" );
if (!state) {
rc("Unable to kzalloc\n" );
return NULL;
}
/* setup the state */
state->config = config;
state->i2c = i2c;
/* create dvb_frontend */
memcpy(&state->frontend.ops, &s921_ops,
sizeof (struct dvb_frontend_ops));
state->frontend.demodulator_priv = state;
return &state->frontend;
}
EXPORT_SYMBOL_GPL(s921_attach);
static const struct dvb_frontend_ops s921_ops = {
.delsys = { SYS_ISDBT },
/* Use dib8000 values per default */
.info = {
.name = "Sharp S921" ,
.frequency_min_hz = 470 * MHz,
/*
* Max should be 770MHz instead, according with Sharp docs,
* but Leadership doc says it works up to 806 MHz. This is
* required to get channel 69, used in Brazil
*/
.frequency_max_hz = 806 * MHz,
.caps = FE_CAN_INVERSION_AUTO |
FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 |
FE_CAN_QAM_AUTO | FE_CAN_TRANSMISSION_MODE_AUTO |
FE_CAN_GUARD_INTERVAL_AUTO | FE_CAN_RECOVER |
FE_CAN_HIERARCHY_AUTO,
},
.release = s921_release,
.init = s921_initfe,
.set_frontend = s921_set_frontend,
.get_frontend = s921_get_frontend,
.read_status = s921_read_status,
.read_signal_strength = s921_read_signal_strength,
.tune = s921_tune,
.get_frontend_algo = s921_get_algo,
};
MODULE_DESCRIPTION("DVB Frontend module for Sharp S921 hardware" );
MODULE_AUTHOR("Mauro Carvalho Chehab" );
MODULE_AUTHOR("Douglas Landgraf <dougsland@redhat.com>" );
MODULE_LICENSE("GPL" );
Messung V0.5 in Prozent C=95 H=93 G=93
¤ Dauer der Verarbeitung: 0.14 Sekunden
(vorverarbeitet am 2026-06-08)
¤
*© Formatika GbR, Deutschland