Message ID | 20220319151016.983348-2-alvin@pqrs.dk (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | drm: bridge: adv7511: CEC support for ADV7535 | expand |
On Sat, 19 Mar 2022 at 16:10, Alvin Šipraga <alvin@pqrs.dk> wrote: > > From: Alvin Šipraga <alsi@bang-olufsen.dk> > > Like the ADV7533, the ADV7535 has an offset for the CEC register map, > and it is the same value (ADV7533_REG_CEC_OFFSET = 0x70). > > Rather than testing for numerous chip types in the offset calculations > throughout the driver, just compute it during driver probe and put it in > the private adv7511 data structure. > > Signed-off-by: Alvin Šipraga <alsi@bang-olufsen.dk> > --- > drivers/gpu/drm/bridge/adv7511/adv7511.h | 1 + > drivers/gpu/drm/bridge/adv7511/adv7511_cec.c | 18 ++++++------------ > drivers/gpu/drm/bridge/adv7511/adv7511_drv.c | 5 +++-- > 3 files changed, 10 insertions(+), 14 deletions(-) > > diff --git a/drivers/gpu/drm/bridge/adv7511/adv7511.h b/drivers/gpu/drm/bridge/adv7511/adv7511.h > index 6a882891d91c..da6d8ee2cd84 100644 > --- a/drivers/gpu/drm/bridge/adv7511/adv7511.h > +++ b/drivers/gpu/drm/bridge/adv7511/adv7511.h > @@ -335,6 +335,7 @@ struct adv7511 { > > struct regmap *regmap; > struct regmap *regmap_cec; > + unsigned int reg_cec_offset; > enum drm_connector_status status; > bool powered; > > diff --git a/drivers/gpu/drm/bridge/adv7511/adv7511_cec.c b/drivers/gpu/drm/bridge/adv7511/adv7511_cec.c > index 28d9becc939c..1f619389e201 100644 > --- a/drivers/gpu/drm/bridge/adv7511/adv7511_cec.c > +++ b/drivers/gpu/drm/bridge/adv7511/adv7511_cec.c > @@ -21,8 +21,7 @@ > > static void adv_cec_tx_raw_status(struct adv7511 *adv7511, u8 tx_raw_status) > { > - unsigned int offset = adv7511->type == ADV7533 ? > - ADV7533_REG_CEC_OFFSET : 0; > + unsigned int offset = adv7511->reg_cec_offset; > unsigned int val; > > if (regmap_read(adv7511->regmap_cec, > @@ -73,8 +72,7 @@ static void adv_cec_tx_raw_status(struct adv7511 *adv7511, u8 tx_raw_status) > > void adv7511_cec_irq_process(struct adv7511 *adv7511, unsigned int irq1) > { > - unsigned int offset = adv7511->type == ADV7533 ? > - ADV7533_REG_CEC_OFFSET : 0; > + unsigned int offset = adv7511->reg_cec_offset; > const u32 irq_tx_mask = ADV7511_INT1_CEC_TX_READY | > ADV7511_INT1_CEC_TX_ARBIT_LOST | > ADV7511_INT1_CEC_TX_RETRY_TIMEOUT; > @@ -118,8 +116,7 @@ void adv7511_cec_irq_process(struct adv7511 *adv7511, unsigned int irq1) > static int adv7511_cec_adap_enable(struct cec_adapter *adap, bool enable) > { > struct adv7511 *adv7511 = cec_get_drvdata(adap); > - unsigned int offset = adv7511->type == ADV7533 ? > - ADV7533_REG_CEC_OFFSET : 0; > + unsigned int offset = adv7511->reg_cec_offset; > > if (adv7511->i2c_cec == NULL) > return -EIO; > @@ -165,8 +162,7 @@ static int adv7511_cec_adap_enable(struct cec_adapter *adap, bool enable) > static int adv7511_cec_adap_log_addr(struct cec_adapter *adap, u8 addr) > { > struct adv7511 *adv7511 = cec_get_drvdata(adap); > - unsigned int offset = adv7511->type == ADV7533 ? > - ADV7533_REG_CEC_OFFSET : 0; > + unsigned int offset = adv7511->reg_cec_offset; > unsigned int i, free_idx = ADV7511_MAX_ADDRS; > > if (!adv7511->cec_enabled_adap) > @@ -235,8 +231,7 @@ static int adv7511_cec_adap_transmit(struct cec_adapter *adap, u8 attempts, > u32 signal_free_time, struct cec_msg *msg) > { > struct adv7511 *adv7511 = cec_get_drvdata(adap); > - unsigned int offset = adv7511->type == ADV7533 ? > - ADV7533_REG_CEC_OFFSET : 0; > + unsigned int offset = adv7511->reg_cec_offset; > u8 len = msg->len; > unsigned int i; > > @@ -289,8 +284,7 @@ static int adv7511_cec_parse_dt(struct device *dev, struct adv7511 *adv7511) > > int adv7511_cec_init(struct device *dev, struct adv7511 *adv7511) > { > - unsigned int offset = adv7511->type == ADV7533 ? > - ADV7533_REG_CEC_OFFSET : 0; > + unsigned int offset = adv7511->reg_cec_offset; > int ret = adv7511_cec_parse_dt(dev, adv7511); > > if (ret) > diff --git a/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c b/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c > index 005bf18682ff..0be65a1ffc47 100644 > --- a/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c > +++ b/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c > @@ -1027,8 +1027,7 @@ static bool adv7511_cec_register_volatile(struct device *dev, unsigned int reg) > struct i2c_client *i2c = to_i2c_client(dev); > struct adv7511 *adv7511 = i2c_get_clientdata(i2c); > > - if (adv7511->type == ADV7533 || adv7511->type == ADV7535) > - reg -= ADV7533_REG_CEC_OFFSET; > + reg -= adv7511->reg_cec_offset; > > switch (reg) { > case ADV7511_REG_CEC_RX_FRAME_HDR: > @@ -1073,6 +1072,8 @@ static int adv7511_init_cec_regmap(struct adv7511 *adv) > ret = adv7533_patch_cec_registers(adv); > if (ret) > goto err; > + > + adv->reg_cec_offset = ADV7533_REG_CEC_OFFSET; > } > > return 0; Reviewed-by: Robert Foss <robert.foss@linaro.org>
diff --git a/drivers/gpu/drm/bridge/adv7511/adv7511.h b/drivers/gpu/drm/bridge/adv7511/adv7511.h index 6a882891d91c..da6d8ee2cd84 100644 --- a/drivers/gpu/drm/bridge/adv7511/adv7511.h +++ b/drivers/gpu/drm/bridge/adv7511/adv7511.h @@ -335,6 +335,7 @@ struct adv7511 { struct regmap *regmap; struct regmap *regmap_cec; + unsigned int reg_cec_offset; enum drm_connector_status status; bool powered; diff --git a/drivers/gpu/drm/bridge/adv7511/adv7511_cec.c b/drivers/gpu/drm/bridge/adv7511/adv7511_cec.c index 28d9becc939c..1f619389e201 100644 --- a/drivers/gpu/drm/bridge/adv7511/adv7511_cec.c +++ b/drivers/gpu/drm/bridge/adv7511/adv7511_cec.c @@ -21,8 +21,7 @@ static void adv_cec_tx_raw_status(struct adv7511 *adv7511, u8 tx_raw_status) { - unsigned int offset = adv7511->type == ADV7533 ? - ADV7533_REG_CEC_OFFSET : 0; + unsigned int offset = adv7511->reg_cec_offset; unsigned int val; if (regmap_read(adv7511->regmap_cec, @@ -73,8 +72,7 @@ static void adv_cec_tx_raw_status(struct adv7511 *adv7511, u8 tx_raw_status) void adv7511_cec_irq_process(struct adv7511 *adv7511, unsigned int irq1) { - unsigned int offset = adv7511->type == ADV7533 ? - ADV7533_REG_CEC_OFFSET : 0; + unsigned int offset = adv7511->reg_cec_offset; const u32 irq_tx_mask = ADV7511_INT1_CEC_TX_READY | ADV7511_INT1_CEC_TX_ARBIT_LOST | ADV7511_INT1_CEC_TX_RETRY_TIMEOUT; @@ -118,8 +116,7 @@ void adv7511_cec_irq_process(struct adv7511 *adv7511, unsigned int irq1) static int adv7511_cec_adap_enable(struct cec_adapter *adap, bool enable) { struct adv7511 *adv7511 = cec_get_drvdata(adap); - unsigned int offset = adv7511->type == ADV7533 ? - ADV7533_REG_CEC_OFFSET : 0; + unsigned int offset = adv7511->reg_cec_offset; if (adv7511->i2c_cec == NULL) return -EIO; @@ -165,8 +162,7 @@ static int adv7511_cec_adap_enable(struct cec_adapter *adap, bool enable) static int adv7511_cec_adap_log_addr(struct cec_adapter *adap, u8 addr) { struct adv7511 *adv7511 = cec_get_drvdata(adap); - unsigned int offset = adv7511->type == ADV7533 ? - ADV7533_REG_CEC_OFFSET : 0; + unsigned int offset = adv7511->reg_cec_offset; unsigned int i, free_idx = ADV7511_MAX_ADDRS; if (!adv7511->cec_enabled_adap) @@ -235,8 +231,7 @@ static int adv7511_cec_adap_transmit(struct cec_adapter *adap, u8 attempts, u32 signal_free_time, struct cec_msg *msg) { struct adv7511 *adv7511 = cec_get_drvdata(adap); - unsigned int offset = adv7511->type == ADV7533 ? - ADV7533_REG_CEC_OFFSET : 0; + unsigned int offset = adv7511->reg_cec_offset; u8 len = msg->len; unsigned int i; @@ -289,8 +284,7 @@ static int adv7511_cec_parse_dt(struct device *dev, struct adv7511 *adv7511) int adv7511_cec_init(struct device *dev, struct adv7511 *adv7511) { - unsigned int offset = adv7511->type == ADV7533 ? - ADV7533_REG_CEC_OFFSET : 0; + unsigned int offset = adv7511->reg_cec_offset; int ret = adv7511_cec_parse_dt(dev, adv7511); if (ret) diff --git a/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c b/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c index 005bf18682ff..0be65a1ffc47 100644 --- a/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c +++ b/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c @@ -1027,8 +1027,7 @@ static bool adv7511_cec_register_volatile(struct device *dev, unsigned int reg) struct i2c_client *i2c = to_i2c_client(dev); struct adv7511 *adv7511 = i2c_get_clientdata(i2c); - if (adv7511->type == ADV7533 || adv7511->type == ADV7535) - reg -= ADV7533_REG_CEC_OFFSET; + reg -= adv7511->reg_cec_offset; switch (reg) { case ADV7511_REG_CEC_RX_FRAME_HDR: @@ -1073,6 +1072,8 @@ static int adv7511_init_cec_regmap(struct adv7511 *adv) ret = adv7533_patch_cec_registers(adv); if (ret) goto err; + + adv->reg_cec_offset = ADV7533_REG_CEC_OFFSET; } return 0;