* [PATCH 0/2] media: i2c: adv748x: Refactor sw_reset handling
@ 2019-01-11 17:41 Kieran Bingham
2019-01-11 17:41 ` [PATCH 1/2] media: i2c: adv748x: Convert SW reset routine to function Kieran Bingham
2019-01-11 17:41 ` [PATCH 2/2] media: i2c: adv748x: Remove PAGE_WAIT Kieran Bingham
0 siblings, 2 replies; 12+ messages in thread
From: Kieran Bingham @ 2019-01-11 17:41 UTC (permalink / raw)
To: Koji Matsuoka, Jacopo Mondi, Laurent Pinchart,
Niklas Söderlund, Steve Longerbeam
Cc: linux-renesas-soc, linux-media, Kieran Bingham
The sw_reset functionality was implemented through a poorly documented
set of 'required writes' from a table.
This also included an delay in the table which required a 'hack' in the
adv748x_write() routines.
These patches rework the reset handling to a function and remove the
delay workaround.
Kieran Bingham (2):
media: i2c: adv748x: Convert SW reset routine to function
media: i2c: adv748x: Remove PAGE_WAIT
drivers/media/i2c/adv748x/adv748x-core.c | 49 ++++++++++++++----------
drivers/media/i2c/adv748x/adv748x.h | 17 +++++++-
2 files changed, 44 insertions(+), 22 deletions(-)
--
2.17.1
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 1/2] media: i2c: adv748x: Convert SW reset routine to function
2019-01-11 17:41 [PATCH 0/2] media: i2c: adv748x: Refactor sw_reset handling Kieran Bingham
@ 2019-01-11 17:41 ` Kieran Bingham
2019-01-11 20:15 ` Laurent Pinchart
` (2 more replies)
2019-01-11 17:41 ` [PATCH 2/2] media: i2c: adv748x: Remove PAGE_WAIT Kieran Bingham
1 sibling, 3 replies; 12+ messages in thread
From: Kieran Bingham @ 2019-01-11 17:41 UTC (permalink / raw)
To: Koji Matsuoka, Jacopo Mondi, Laurent Pinchart,
Niklas Söderlund, Steve Longerbeam
Cc: linux-renesas-soc, linux-media, Kieran Bingham
The ADV748x is currently reset by writting a small table of registers to
the device.
The table lacks documentation and contains magic values to perform the
actions, including using a fake register address to introduce a delay
loop.
Remove the table, and convert to code, documenting the purpose of the
specific writes along the way.
Signed-off-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
---
drivers/media/i2c/adv748x/adv748x-core.c | 32 ++++++++++++++++--------
drivers/media/i2c/adv748x/adv748x.h | 16 ++++++++++++
2 files changed, 38 insertions(+), 10 deletions(-)
diff --git a/drivers/media/i2c/adv748x/adv748x-core.c b/drivers/media/i2c/adv748x/adv748x-core.c
index 02f9c440301c..252bdb28b18b 100644
--- a/drivers/media/i2c/adv748x/adv748x-core.c
+++ b/drivers/media/i2c/adv748x/adv748x-core.c
@@ -389,15 +389,6 @@ static const struct media_entity_operations adv748x_media_ops = {
* HW setup
*/
-static const struct adv748x_reg_value adv748x_sw_reset[] = {
-
- {ADV748X_PAGE_IO, 0xff, 0xff}, /* SW reset */
- {ADV748X_PAGE_WAIT, 0x00, 0x05},/* delay 5 */
- {ADV748X_PAGE_IO, 0x01, 0x76}, /* ADI Required Write */
- {ADV748X_PAGE_IO, 0xf2, 0x01}, /* Enable I2C Read Auto-Increment */
- {ADV748X_PAGE_EOR, 0xff, 0xff} /* End of register table */
-};
-
/* Initialize CP Core with RGB888 format. */
static const struct adv748x_reg_value adv748x_init_hdmi[] = {
/* Disable chip powerdown & Enable HDMI Rx block */
@@ -474,12 +465,33 @@ static const struct adv748x_reg_value adv748x_init_afe[] = {
{ADV748X_PAGE_EOR, 0xff, 0xff} /* End of register table */
};
+static int adv748x_sw_reset(struct adv748x_state *state)
+{
+ int ret;
+
+ ret = io_write(state, ADV748X_IO_REG_FF, ADV748X_IO_REG_FF_MAIN_RESET);
+ if (ret)
+ return ret;
+
+ usleep_range(5000, 6000);
+
+ /* Disable CEC Wakeup from power-down mode */
+ ret = io_clrset(state, ADV748X_IO_REG_01, ADV748X_IO_REG_01_PWRDN_MASK,
+ ADV748X_IO_REG_01_PWRDNB);
+ if (ret)
+ return ret;
+
+ /* Enable I2C Read Auto-Increment for consecutive reads */
+ return io_write(state, ADV748X_IO_REG_F2,
+ ADV748X_IO_REG_F2_READ_AUTO_INC);
+}
+
static int adv748x_reset(struct adv748x_state *state)
{
int ret;
u8 regval = 0;
- ret = adv748x_write_regs(state, adv748x_sw_reset);
+ ret = adv748x_sw_reset(state);
if (ret < 0)
return ret;
diff --git a/drivers/media/i2c/adv748x/adv748x.h b/drivers/media/i2c/adv748x/adv748x.h
index b00c1995efb0..2f8d751cfbb0 100644
--- a/drivers/media/i2c/adv748x/adv748x.h
+++ b/drivers/media/i2c/adv748x/adv748x.h
@@ -211,6 +211,11 @@ struct adv748x_state {
#define ADV748X_IO_PD 0x00 /* power down controls */
#define ADV748X_IO_PD_RX_EN BIT(6)
+#define ADV748X_IO_REG_01 0x01 /* pwrdn{2}b, prog_xtal_freq */
+#define ADV748X_IO_REG_01_PWRDN_MASK (BIT(7) | BIT(6))
+#define ADV748X_IO_REG_01_PWRDN2B BIT(7) /* CEC Wakeup Support */
+#define ADV748X_IO_REG_01_PWRDNB BIT(6) /* CEC Wakeup Support */
+
#define ADV748X_IO_REG_04 0x04
#define ADV748X_IO_REG_04_FORCE_FR BIT(0) /* Force CP free-run */
@@ -229,8 +234,19 @@ struct adv748x_state {
#define ADV748X_IO_CHIP_REV_ID_1 0xdf
#define ADV748X_IO_CHIP_REV_ID_2 0xe0
+#define ADV748X_IO_REG_F2 0xf2
+#define ADV748X_IO_REG_F2_READ_AUTO_INC BIT(0)
+
+/* For PAGE slave address offsets */
#define ADV748X_IO_SLAVE_ADDR_BASE 0xf2
+/*
+ * The ADV748x_Recommended_Settings_PrA_2014-08-20.pdf details both 0x80 and
+ * 0xff as examples for performing a software reset.
+ */
+#define ADV748X_IO_REG_FF 0xff
+#define ADV748X_IO_REG_FF_MAIN_RESET 0xff
+
/* HDMI RX Map */
#define ADV748X_HDMI_LW1 0x07 /* line width_1 */
#define ADV748X_HDMI_LW1_VERT_FILTER BIT(7)
--
2.17.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 2/2] media: i2c: adv748x: Remove PAGE_WAIT
2019-01-11 17:41 [PATCH 0/2] media: i2c: adv748x: Refactor sw_reset handling Kieran Bingham
2019-01-11 17:41 ` [PATCH 1/2] media: i2c: adv748x: Convert SW reset routine to function Kieran Bingham
@ 2019-01-11 17:41 ` Kieran Bingham
2019-01-11 20:23 ` Laurent Pinchart
2019-01-14 14:44 ` Niklas Söderlund
1 sibling, 2 replies; 12+ messages in thread
From: Kieran Bingham @ 2019-01-11 17:41 UTC (permalink / raw)
To: Koji Matsuoka, Jacopo Mondi, Laurent Pinchart,
Niklas Söderlund, Steve Longerbeam
Cc: linux-renesas-soc, linux-media, Kieran Bingham
The ADV748X_PAGE_WAIT is a fake page to insert arbitrary delays in the
register tables.
Its only usage was removed, so we can remove the handling and simplify
the code.
Signed-off-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
---
drivers/media/i2c/adv748x/adv748x-core.c | 17 ++++++-----------
drivers/media/i2c/adv748x/adv748x.h | 1 -
2 files changed, 6 insertions(+), 12 deletions(-)
diff --git a/drivers/media/i2c/adv748x/adv748x-core.c b/drivers/media/i2c/adv748x/adv748x-core.c
index 252bdb28b18b..8199e0b20790 100644
--- a/drivers/media/i2c/adv748x/adv748x-core.c
+++ b/drivers/media/i2c/adv748x/adv748x-core.c
@@ -219,18 +219,13 @@ static int adv748x_write_regs(struct adv748x_state *state,
int ret;
while (regs->page != ADV748X_PAGE_EOR) {
- if (regs->page == ADV748X_PAGE_WAIT) {
- msleep(regs->value);
- } else {
- ret = adv748x_write(state, regs->page, regs->reg,
- regs->value);
- if (ret < 0) {
- adv_err(state,
- "Error regs page: 0x%02x reg: 0x%02x\n",
- regs->page, regs->reg);
- return ret;
- }
+ ret = adv748x_write(state, regs->page, regs->reg, regs->value);
+ if (ret < 0) {
+ adv_err(state, "Error regs page: 0x%02x reg: 0x%02x\n",
+ regs->page, regs->reg);
+ return ret;
}
+
regs++;
}
diff --git a/drivers/media/i2c/adv748x/adv748x.h b/drivers/media/i2c/adv748x/adv748x.h
index 2f8d751cfbb0..5042f9e94aee 100644
--- a/drivers/media/i2c/adv748x/adv748x.h
+++ b/drivers/media/i2c/adv748x/adv748x.h
@@ -39,7 +39,6 @@ enum adv748x_page {
ADV748X_PAGE_MAX,
/* Fake pages for register sequences */
- ADV748X_PAGE_WAIT, /* Wait x msec */
ADV748X_PAGE_EOR, /* End Mark */
};
--
2.17.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH 1/2] media: i2c: adv748x: Convert SW reset routine to function
2019-01-11 17:41 ` [PATCH 1/2] media: i2c: adv748x: Convert SW reset routine to function Kieran Bingham
@ 2019-01-11 20:15 ` Laurent Pinchart
2019-01-12 16:50 ` Kieran Bingham
2019-01-14 14:43 ` Niklas Söderlund
2019-01-18 12:09 ` Hans Verkuil
2 siblings, 1 reply; 12+ messages in thread
From: Laurent Pinchart @ 2019-01-11 20:15 UTC (permalink / raw)
To: Kieran Bingham
Cc: Koji Matsuoka, Jacopo Mondi, Niklas Söderlund,
Steve Longerbeam, linux-renesas-soc, linux-media
Hi Kieran,
Thank you for the patch.
On Friday, 11 January 2019 19:41:40 EET Kieran Bingham wrote:
> The ADV748x is currently reset by writting a small table of registers to
> the device.
>
> The table lacks documentation and contains magic values to perform the
> actions, including using a fake register address to introduce a delay
> loop.
>
> Remove the table, and convert to code, documenting the purpose of the
> specific writes along the way.
>
> Signed-off-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
> ---
> drivers/media/i2c/adv748x/adv748x-core.c | 32 ++++++++++++++++--------
> drivers/media/i2c/adv748x/adv748x.h | 16 ++++++++++++
> 2 files changed, 38 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/media/i2c/adv748x/adv748x-core.c
> b/drivers/media/i2c/adv748x/adv748x-core.c index 02f9c440301c..252bdb28b18b
> 100644
> --- a/drivers/media/i2c/adv748x/adv748x-core.c
> +++ b/drivers/media/i2c/adv748x/adv748x-core.c
> @@ -389,15 +389,6 @@ static const struct media_entity_operations
> adv748x_media_ops = { * HW setup
> */
>
> -static const struct adv748x_reg_value adv748x_sw_reset[] = {
> -
> - {ADV748X_PAGE_IO, 0xff, 0xff}, /* SW reset */
> - {ADV748X_PAGE_WAIT, 0x00, 0x05},/* delay 5 */
> - {ADV748X_PAGE_IO, 0x01, 0x76}, /* ADI Required Write */
> - {ADV748X_PAGE_IO, 0xf2, 0x01}, /* Enable I2C Read Auto-Increment */
> - {ADV748X_PAGE_EOR, 0xff, 0xff} /* End of register table */
> -};
> -
> /* Initialize CP Core with RGB888 format. */
> static const struct adv748x_reg_value adv748x_init_hdmi[] = {
> /* Disable chip powerdown & Enable HDMI Rx block */
> @@ -474,12 +465,33 @@ static const struct adv748x_reg_value
> adv748x_init_afe[] = { {ADV748X_PAGE_EOR, 0xff, 0xff} /* End of register
> table */
> };
>
> +static int adv748x_sw_reset(struct adv748x_state *state)
> +{
> + int ret;
> +
> + ret = io_write(state, ADV748X_IO_REG_FF, ADV748X_IO_REG_FF_MAIN_RESET);
> + if (ret)
> + return ret;
> +
> + usleep_range(5000, 6000);
> +
> + /* Disable CEC Wakeup from power-down mode */
> + ret = io_clrset(state, ADV748X_IO_REG_01, ADV748X_IO_REG_01_PWRDN_MASK,
> + ADV748X_IO_REG_01_PWRDNB);
What's the reason for io_clrset() instead of io_write() ?
Apart from this,
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> + if (ret)
> + return ret;
> +
> + /* Enable I2C Read Auto-Increment for consecutive reads */
> + return io_write(state, ADV748X_IO_REG_F2,
> + ADV748X_IO_REG_F2_READ_AUTO_INC);
> +}
> +
> static int adv748x_reset(struct adv748x_state *state)
> {
> int ret;
> u8 regval = 0;
>
> - ret = adv748x_write_regs(state, adv748x_sw_reset);
> + ret = adv748x_sw_reset(state);
> if (ret < 0)
> return ret;
>
> diff --git a/drivers/media/i2c/adv748x/adv748x.h
> b/drivers/media/i2c/adv748x/adv748x.h index b00c1995efb0..2f8d751cfbb0
> 100644
> --- a/drivers/media/i2c/adv748x/adv748x.h
> +++ b/drivers/media/i2c/adv748x/adv748x.h
> @@ -211,6 +211,11 @@ struct adv748x_state {
> #define ADV748X_IO_PD 0x00 /* power down controls */
> #define ADV748X_IO_PD_RX_EN BIT(6)
>
> +#define ADV748X_IO_REG_01 0x01 /* pwrdn{2}b, prog_xtal_freq */
> +#define ADV748X_IO_REG_01_PWRDN_MASK (BIT(7) | BIT(6))
> +#define ADV748X_IO_REG_01_PWRDN2B BIT(7) /* CEC Wakeup Support */
> +#define ADV748X_IO_REG_01_PWRDNB BIT(6) /* CEC Wakeup Support */
> +
> #define ADV748X_IO_REG_04 0x04
> #define ADV748X_IO_REG_04_FORCE_FR BIT(0) /* Force CP free-run */
>
> @@ -229,8 +234,19 @@ struct adv748x_state {
> #define ADV748X_IO_CHIP_REV_ID_1 0xdf
> #define ADV748X_IO_CHIP_REV_ID_2 0xe0
>
> +#define ADV748X_IO_REG_F2 0xf2
> +#define ADV748X_IO_REG_F2_READ_AUTO_INC BIT(0)
> +
> +/* For PAGE slave address offsets */
> #define ADV748X_IO_SLAVE_ADDR_BASE 0xf2
>
> +/*
> + * The ADV748x_Recommended_Settings_PrA_2014-08-20.pdf details both 0x80
> and + * 0xff as examples for performing a software reset.
> + */
> +#define ADV748X_IO_REG_FF 0xff
> +#define ADV748X_IO_REG_FF_MAIN_RESET 0xff
> +
> /* HDMI RX Map */
> #define ADV748X_HDMI_LW1 0x07 /* line width_1 */
> #define ADV748X_HDMI_LW1_VERT_FILTER BIT(7)
--
Regards,
Laurent Pinchart
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 2/2] media: i2c: adv748x: Remove PAGE_WAIT
2019-01-11 17:41 ` [PATCH 2/2] media: i2c: adv748x: Remove PAGE_WAIT Kieran Bingham
@ 2019-01-11 20:23 ` Laurent Pinchart
2019-01-12 16:51 ` Kieran Bingham
2019-01-14 14:44 ` Niklas Söderlund
1 sibling, 1 reply; 12+ messages in thread
From: Laurent Pinchart @ 2019-01-11 20:23 UTC (permalink / raw)
To: Kieran Bingham
Cc: Koji Matsuoka, Jacopo Mondi, Niklas Söderlund,
Steve Longerbeam, linux-renesas-soc, linux-media
Hi Kieran,
Thank you for the patch.
On Friday, 11 January 2019 19:41:41 EET Kieran Bingham wrote:
> The ADV748X_PAGE_WAIT is a fake page to insert arbitrary delays in the
> register tables.
>
> Its only usage was removed, so we can remove the handling and simplify
> the code.
>
> Signed-off-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
> ---
> drivers/media/i2c/adv748x/adv748x-core.c | 17 ++++++-----------
> drivers/media/i2c/adv748x/adv748x.h | 1 -
> 2 files changed, 6 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/media/i2c/adv748x/adv748x-core.c
> b/drivers/media/i2c/adv748x/adv748x-core.c index 252bdb28b18b..8199e0b20790
> 100644
> --- a/drivers/media/i2c/adv748x/adv748x-core.c
> +++ b/drivers/media/i2c/adv748x/adv748x-core.c
> @@ -219,18 +219,13 @@ static int adv748x_write_regs(struct adv748x_state
> *state, int ret;
>
> while (regs->page != ADV748X_PAGE_EOR) {
While at it you could write this as
for (; regs->page != ADV748X_PAGE_EOR; ++regs)
and remove the regs++ below.
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> - if (regs->page == ADV748X_PAGE_WAIT) {
> - msleep(regs->value);
> - } else {
> - ret = adv748x_write(state, regs->page, regs->reg,
> - regs->value);
> - if (ret < 0) {
> - adv_err(state,
> - "Error regs page: 0x%02x reg: 0x%02x\n",
> - regs->page, regs->reg);
> - return ret;
> - }
> + ret = adv748x_write(state, regs->page, regs->reg, regs->value);
> + if (ret < 0) {
> + adv_err(state, "Error regs page: 0x%02x reg: 0x%02x\n",
> + regs->page, regs->reg);
> + return ret;
> }
> +
> regs++;
> }
>
> diff --git a/drivers/media/i2c/adv748x/adv748x.h
> b/drivers/media/i2c/adv748x/adv748x.h index 2f8d751cfbb0..5042f9e94aee
> 100644
> --- a/drivers/media/i2c/adv748x/adv748x.h
> +++ b/drivers/media/i2c/adv748x/adv748x.h
> @@ -39,7 +39,6 @@ enum adv748x_page {
> ADV748X_PAGE_MAX,
>
> /* Fake pages for register sequences */
> - ADV748X_PAGE_WAIT, /* Wait x msec */
> ADV748X_PAGE_EOR, /* End Mark */
> };
--
Regards,
Laurent Pinchart
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 1/2] media: i2c: adv748x: Convert SW reset routine to function
2019-01-11 20:15 ` Laurent Pinchart
@ 2019-01-12 16:50 ` Kieran Bingham
2019-01-18 12:26 ` Laurent Pinchart
0 siblings, 1 reply; 12+ messages in thread
From: Kieran Bingham @ 2019-01-12 16:50 UTC (permalink / raw)
To: Laurent Pinchart
Cc: Koji Matsuoka, Jacopo Mondi, Niklas Söderlund,
Steve Longerbeam, linux-renesas-soc, linux-media
Hi Laurent,
Thanks for the review,
On 11/01/2019 20:15, Laurent Pinchart wrote:
> Hi Kieran,
>
> Thank you for the patch.
>
> On Friday, 11 January 2019 19:41:40 EET Kieran Bingham wrote:
>> The ADV748x is currently reset by writting a small table of registers to
>> the device.
>>
>> The table lacks documentation and contains magic values to perform the
>> actions, including using a fake register address to introduce a delay
>> loop.
>>
>> Remove the table, and convert to code, documenting the purpose of the
>> specific writes along the way.
>>
>> Signed-off-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
>> ---
>> drivers/media/i2c/adv748x/adv748x-core.c | 32 ++++++++++++++++--------
>> drivers/media/i2c/adv748x/adv748x.h | 16 ++++++++++++
>> 2 files changed, 38 insertions(+), 10 deletions(-)
>>
>> diff --git a/drivers/media/i2c/adv748x/adv748x-core.c
>> b/drivers/media/i2c/adv748x/adv748x-core.c index 02f9c440301c..252bdb28b18b
>> 100644
>> --- a/drivers/media/i2c/adv748x/adv748x-core.c
>> +++ b/drivers/media/i2c/adv748x/adv748x-core.c
>> @@ -389,15 +389,6 @@ static const struct media_entity_operations
>> adv748x_media_ops = { * HW setup
>> */
>>
>> -static const struct adv748x_reg_value adv748x_sw_reset[] = {
>> -
>> - {ADV748X_PAGE_IO, 0xff, 0xff}, /* SW reset */
>> - {ADV748X_PAGE_WAIT, 0x00, 0x05},/* delay 5 */
>> - {ADV748X_PAGE_IO, 0x01, 0x76}, /* ADI Required Write */
>> - {ADV748X_PAGE_IO, 0xf2, 0x01}, /* Enable I2C Read Auto-Increment */
>> - {ADV748X_PAGE_EOR, 0xff, 0xff} /* End of register table */
>> -};
>> -
>> /* Initialize CP Core with RGB888 format. */
>> static const struct adv748x_reg_value adv748x_init_hdmi[] = {
>> /* Disable chip powerdown & Enable HDMI Rx block */
>> @@ -474,12 +465,33 @@ static const struct adv748x_reg_value
>> adv748x_init_afe[] = { {ADV748X_PAGE_EOR, 0xff, 0xff} /* End of register
>> table */
>> };
>>
>> +static int adv748x_sw_reset(struct adv748x_state *state)
>> +{
>> + int ret;
>> +
>> + ret = io_write(state, ADV748X_IO_REG_FF, ADV748X_IO_REG_FF_MAIN_RESET);
>> + if (ret)
>> + return ret;
>> +
>> + usleep_range(5000, 6000);
>> +
>> + /* Disable CEC Wakeup from power-down mode */
>> + ret = io_clrset(state, ADV748X_IO_REG_01, ADV748X_IO_REG_01_PWRDN_MASK,
>> + ADV748X_IO_REG_01_PWRDNB);
>
> What's the reason for io_clrset() instead of io_write() ?
>
The register is multi-purpose, and controls CEC Wakeup and *part* of the
prog_xtal_freq clock parameters.
The original table writes the default value of the clock parameter - but
that itself is split over two registers I think - so I didn't want to be
'half setting' some parameter, which should already be at its default
anyway.
I felt it was cleaner to be precise and make this code perform only the
actual *change* that was required (which is the adjustment of the cec
powerdown mode control, as described by the comment).
> Apart from this,
>
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Thanks
--
Kieran
>
>> + if (ret)
>> + return ret;
>> +
>> + /* Enable I2C Read Auto-Increment for consecutive reads */
>> + return io_write(state, ADV748X_IO_REG_F2,
>> + ADV748X_IO_REG_F2_READ_AUTO_INC);
>> +}
>> +
>> static int adv748x_reset(struct adv748x_state *state)
>> {
>> int ret;
>> u8 regval = 0;
>>
>> - ret = adv748x_write_regs(state, adv748x_sw_reset);
>> + ret = adv748x_sw_reset(state);
>> if (ret < 0)
>> return ret;
>>
>> diff --git a/drivers/media/i2c/adv748x/adv748x.h
>> b/drivers/media/i2c/adv748x/adv748x.h index b00c1995efb0..2f8d751cfbb0
>> 100644
>> --- a/drivers/media/i2c/adv748x/adv748x.h
>> +++ b/drivers/media/i2c/adv748x/adv748x.h
>> @@ -211,6 +211,11 @@ struct adv748x_state {
>> #define ADV748X_IO_PD 0x00 /* power down controls */
>> #define ADV748X_IO_PD_RX_EN BIT(6)
>>
>> +#define ADV748X_IO_REG_01 0x01 /* pwrdn{2}b, prog_xtal_freq */
>> +#define ADV748X_IO_REG_01_PWRDN_MASK (BIT(7) | BIT(6))
>> +#define ADV748X_IO_REG_01_PWRDN2B BIT(7) /* CEC Wakeup Support */
>> +#define ADV748X_IO_REG_01_PWRDNB BIT(6) /* CEC Wakeup Support */
>> +
>> #define ADV748X_IO_REG_04 0x04
>> #define ADV748X_IO_REG_04_FORCE_FR BIT(0) /* Force CP free-run */
>>
>> @@ -229,8 +234,19 @@ struct adv748x_state {
>> #define ADV748X_IO_CHIP_REV_ID_1 0xdf
>> #define ADV748X_IO_CHIP_REV_ID_2 0xe0
>>
>> +#define ADV748X_IO_REG_F2 0xf2
>> +#define ADV748X_IO_REG_F2_READ_AUTO_INC BIT(0)
>> +
>> +/* For PAGE slave address offsets */
>> #define ADV748X_IO_SLAVE_ADDR_BASE 0xf2
>>
>> +/*
>> + * The ADV748x_Recommended_Settings_PrA_2014-08-20.pdf details both 0x80
>> and + * 0xff as examples for performing a software reset.
>> + */
>> +#define ADV748X_IO_REG_FF 0xff
>> +#define ADV748X_IO_REG_FF_MAIN_RESET 0xff
>> +
>> /* HDMI RX Map */
>> #define ADV748X_HDMI_LW1 0x07 /* line width_1 */
>> #define ADV748X_HDMI_LW1_VERT_FILTER BIT(7)
>
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 2/2] media: i2c: adv748x: Remove PAGE_WAIT
2019-01-11 20:23 ` Laurent Pinchart
@ 2019-01-12 16:51 ` Kieran Bingham
0 siblings, 0 replies; 12+ messages in thread
From: Kieran Bingham @ 2019-01-12 16:51 UTC (permalink / raw)
To: Laurent Pinchart
Cc: Koji Matsuoka, Jacopo Mondi, Niklas Söderlund,
Steve Longerbeam, linux-renesas-soc, linux-media
Hi Laurent,
On 11/01/2019 20:23, Laurent Pinchart wrote:
> Hi Kieran,
>
> Thank you for the patch.
>
> On Friday, 11 January 2019 19:41:41 EET Kieran Bingham wrote:
>> The ADV748X_PAGE_WAIT is a fake page to insert arbitrary delays in the
>> register tables.
>>
>> Its only usage was removed, so we can remove the handling and simplify
>> the code.
>>
>> Signed-off-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
>> ---
>> drivers/media/i2c/adv748x/adv748x-core.c | 17 ++++++-----------
>> drivers/media/i2c/adv748x/adv748x.h | 1 -
>> 2 files changed, 6 insertions(+), 12 deletions(-)
>>
>> diff --git a/drivers/media/i2c/adv748x/adv748x-core.c
>> b/drivers/media/i2c/adv748x/adv748x-core.c index 252bdb28b18b..8199e0b20790
>> 100644
>> --- a/drivers/media/i2c/adv748x/adv748x-core.c
>> +++ b/drivers/media/i2c/adv748x/adv748x-core.c
>> @@ -219,18 +219,13 @@ static int adv748x_write_regs(struct adv748x_state
>> *state, int ret;
>>
>> while (regs->page != ADV748X_PAGE_EOR) {
>
> While at it you could write this as
>
> for (; regs->page != ADV748X_PAGE_EOR; ++regs)
>
> and remove the regs++ below.
ah yes - good idea. I'll update this.
--
Kieran
>
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
>
>> - if (regs->page == ADV748X_PAGE_WAIT) {
>> - msleep(regs->value);
>> - } else {
>> - ret = adv748x_write(state, regs->page, regs->reg,
>> - regs->value);
>> - if (ret < 0) {
>> - adv_err(state,
>> - "Error regs page: 0x%02x reg: 0x%02x\n",
>> - regs->page, regs->reg);
>> - return ret;
>> - }
>> + ret = adv748x_write(state, regs->page, regs->reg, regs->value);
>> + if (ret < 0) {
>> + adv_err(state, "Error regs page: 0x%02x reg: 0x%02x\n",
>> + regs->page, regs->reg);
>> + return ret;
>> }
>> +
>> regs++;
>> }
>>
>> diff --git a/drivers/media/i2c/adv748x/adv748x.h
>> b/drivers/media/i2c/adv748x/adv748x.h index 2f8d751cfbb0..5042f9e94aee
>> 100644
>> --- a/drivers/media/i2c/adv748x/adv748x.h
>> +++ b/drivers/media/i2c/adv748x/adv748x.h
>> @@ -39,7 +39,6 @@ enum adv748x_page {
>> ADV748X_PAGE_MAX,
>>
>> /* Fake pages for register sequences */
>> - ADV748X_PAGE_WAIT, /* Wait x msec */
>> ADV748X_PAGE_EOR, /* End Mark */
>> };
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 1/2] media: i2c: adv748x: Convert SW reset routine to function
2019-01-11 17:41 ` [PATCH 1/2] media: i2c: adv748x: Convert SW reset routine to function Kieran Bingham
2019-01-11 20:15 ` Laurent Pinchart
@ 2019-01-14 14:43 ` Niklas Söderlund
2019-01-18 12:09 ` Hans Verkuil
2 siblings, 0 replies; 12+ messages in thread
From: Niklas Söderlund @ 2019-01-14 14:43 UTC (permalink / raw)
To: Kieran Bingham
Cc: Koji Matsuoka, Jacopo Mondi, Laurent Pinchart, Steve Longerbeam,
linux-renesas-soc, linux-media
Hi Kieran,
Thanks for your work.
On 2019-01-11 17:41:40 +0000, Kieran Bingham wrote:
> The ADV748x is currently reset by writting a small table of registers to
> the device.
>
> The table lacks documentation and contains magic values to perform the
> actions, including using a fake register address to introduce a delay
> loop.
>
> Remove the table, and convert to code, documenting the purpose of the
> specific writes along the way.
>
> Signed-off-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
> ---
> drivers/media/i2c/adv748x/adv748x-core.c | 32 ++++++++++++++++--------
> drivers/media/i2c/adv748x/adv748x.h | 16 ++++++++++++
> 2 files changed, 38 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/media/i2c/adv748x/adv748x-core.c b/drivers/media/i2c/adv748x/adv748x-core.c
> index 02f9c440301c..252bdb28b18b 100644
> --- a/drivers/media/i2c/adv748x/adv748x-core.c
> +++ b/drivers/media/i2c/adv748x/adv748x-core.c
> @@ -389,15 +389,6 @@ static const struct media_entity_operations adv748x_media_ops = {
> * HW setup
> */
>
> -static const struct adv748x_reg_value adv748x_sw_reset[] = {
> -
> - {ADV748X_PAGE_IO, 0xff, 0xff}, /* SW reset */
> - {ADV748X_PAGE_WAIT, 0x00, 0x05},/* delay 5 */
> - {ADV748X_PAGE_IO, 0x01, 0x76}, /* ADI Required Write */
> - {ADV748X_PAGE_IO, 0xf2, 0x01}, /* Enable I2C Read Auto-Increment */
> - {ADV748X_PAGE_EOR, 0xff, 0xff} /* End of register table */
> -};
> -
> /* Initialize CP Core with RGB888 format. */
> static const struct adv748x_reg_value adv748x_init_hdmi[] = {
> /* Disable chip powerdown & Enable HDMI Rx block */
> @@ -474,12 +465,33 @@ static const struct adv748x_reg_value adv748x_init_afe[] = {
> {ADV748X_PAGE_EOR, 0xff, 0xff} /* End of register table */
> };
>
> +static int adv748x_sw_reset(struct adv748x_state *state)
> +{
> + int ret;
> +
> + ret = io_write(state, ADV748X_IO_REG_FF, ADV748X_IO_REG_FF_MAIN_RESET);
> + if (ret)
> + return ret;
> +
> + usleep_range(5000, 6000);
> +
> + /* Disable CEC Wakeup from power-down mode */
> + ret = io_clrset(state, ADV748X_IO_REG_01, ADV748X_IO_REG_01_PWRDN_MASK,
> + ADV748X_IO_REG_01_PWRDNB);
> + if (ret)
> + return ret;
> +
> + /* Enable I2C Read Auto-Increment for consecutive reads */
> + return io_write(state, ADV748X_IO_REG_F2,
> + ADV748X_IO_REG_F2_READ_AUTO_INC);
> +}
> +
> static int adv748x_reset(struct adv748x_state *state)
> {
> int ret;
> u8 regval = 0;
>
> - ret = adv748x_write_regs(state, adv748x_sw_reset);
> + ret = adv748x_sw_reset(state);
> if (ret < 0)
> return ret;
>
> diff --git a/drivers/media/i2c/adv748x/adv748x.h b/drivers/media/i2c/adv748x/adv748x.h
> index b00c1995efb0..2f8d751cfbb0 100644
> --- a/drivers/media/i2c/adv748x/adv748x.h
> +++ b/drivers/media/i2c/adv748x/adv748x.h
> @@ -211,6 +211,11 @@ struct adv748x_state {
> #define ADV748X_IO_PD 0x00 /* power down controls */
> #define ADV748X_IO_PD_RX_EN BIT(6)
>
> +#define ADV748X_IO_REG_01 0x01 /* pwrdn{2}b, prog_xtal_freq */
> +#define ADV748X_IO_REG_01_PWRDN_MASK (BIT(7) | BIT(6))
> +#define ADV748X_IO_REG_01_PWRDN2B BIT(7) /* CEC Wakeup Support */
> +#define ADV748X_IO_REG_01_PWRDNB BIT(6) /* CEC Wakeup Support */
> +
> #define ADV748X_IO_REG_04 0x04
> #define ADV748X_IO_REG_04_FORCE_FR BIT(0) /* Force CP free-run */
>
> @@ -229,8 +234,19 @@ struct adv748x_state {
> #define ADV748X_IO_CHIP_REV_ID_1 0xdf
> #define ADV748X_IO_CHIP_REV_ID_2 0xe0
>
> +#define ADV748X_IO_REG_F2 0xf2
> +#define ADV748X_IO_REG_F2_READ_AUTO_INC BIT(0)
> +
> +/* For PAGE slave address offsets */
> #define ADV748X_IO_SLAVE_ADDR_BASE 0xf2
>
> +/*
> + * The ADV748x_Recommended_Settings_PrA_2014-08-20.pdf details both 0x80 and
> + * 0xff as examples for performing a software reset.
> + */
> +#define ADV748X_IO_REG_FF 0xff
> +#define ADV748X_IO_REG_FF_MAIN_RESET 0xff
> +
> /* HDMI RX Map */
> #define ADV748X_HDMI_LW1 0x07 /* line width_1 */
> #define ADV748X_HDMI_LW1_VERT_FILTER BIT(7)
> --
> 2.17.1
>
--
Regards,
Niklas Söderlund
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 2/2] media: i2c: adv748x: Remove PAGE_WAIT
2019-01-11 17:41 ` [PATCH 2/2] media: i2c: adv748x: Remove PAGE_WAIT Kieran Bingham
2019-01-11 20:23 ` Laurent Pinchart
@ 2019-01-14 14:44 ` Niklas Söderlund
1 sibling, 0 replies; 12+ messages in thread
From: Niklas Söderlund @ 2019-01-14 14:44 UTC (permalink / raw)
To: Kieran Bingham
Cc: Koji Matsuoka, Jacopo Mondi, Laurent Pinchart, Steve Longerbeam,
linux-renesas-soc, linux-media
Hi Kieran,
Thanks for your patch.
On 2019-01-11 17:41:41 +0000, Kieran Bingham wrote:
> The ADV748X_PAGE_WAIT is a fake page to insert arbitrary delays in the
> register tables.
>
> Its only usage was removed, so we can remove the handling and simplify
> the code.
>
> Signed-off-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
With the change Laurent points out,
Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
> ---
> drivers/media/i2c/adv748x/adv748x-core.c | 17 ++++++-----------
> drivers/media/i2c/adv748x/adv748x.h | 1 -
> 2 files changed, 6 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/media/i2c/adv748x/adv748x-core.c b/drivers/media/i2c/adv748x/adv748x-core.c
> index 252bdb28b18b..8199e0b20790 100644
> --- a/drivers/media/i2c/adv748x/adv748x-core.c
> +++ b/drivers/media/i2c/adv748x/adv748x-core.c
> @@ -219,18 +219,13 @@ static int adv748x_write_regs(struct adv748x_state *state,
> int ret;
>
> while (regs->page != ADV748X_PAGE_EOR) {
> - if (regs->page == ADV748X_PAGE_WAIT) {
> - msleep(regs->value);
> - } else {
> - ret = adv748x_write(state, regs->page, regs->reg,
> - regs->value);
> - if (ret < 0) {
> - adv_err(state,
> - "Error regs page: 0x%02x reg: 0x%02x\n",
> - regs->page, regs->reg);
> - return ret;
> - }
> + ret = adv748x_write(state, regs->page, regs->reg, regs->value);
> + if (ret < 0) {
> + adv_err(state, "Error regs page: 0x%02x reg: 0x%02x\n",
> + regs->page, regs->reg);
> + return ret;
> }
> +
> regs++;
> }
>
> diff --git a/drivers/media/i2c/adv748x/adv748x.h b/drivers/media/i2c/adv748x/adv748x.h
> index 2f8d751cfbb0..5042f9e94aee 100644
> --- a/drivers/media/i2c/adv748x/adv748x.h
> +++ b/drivers/media/i2c/adv748x/adv748x.h
> @@ -39,7 +39,6 @@ enum adv748x_page {
> ADV748X_PAGE_MAX,
>
> /* Fake pages for register sequences */
> - ADV748X_PAGE_WAIT, /* Wait x msec */
> ADV748X_PAGE_EOR, /* End Mark */
> };
>
> --
> 2.17.1
>
--
Regards,
Niklas Söderlund
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 1/2] media: i2c: adv748x: Convert SW reset routine to function
2019-01-11 17:41 ` [PATCH 1/2] media: i2c: adv748x: Convert SW reset routine to function Kieran Bingham
2019-01-11 20:15 ` Laurent Pinchart
2019-01-14 14:43 ` Niklas Söderlund
@ 2019-01-18 12:09 ` Hans Verkuil
2019-01-18 13:34 ` Kieran Bingham
2 siblings, 1 reply; 12+ messages in thread
From: Hans Verkuil @ 2019-01-18 12:09 UTC (permalink / raw)
To: Kieran Bingham, Koji Matsuoka, Jacopo Mondi, Laurent Pinchart,
Niklas Söderlund, Steve Longerbeam
Cc: linux-renesas-soc, linux-media
On 1/11/19 6:41 PM, Kieran Bingham wrote:
> The ADV748x is currently reset by writting a small table of registers to
> the device.
>
> The table lacks documentation and contains magic values to perform the
> actions, including using a fake register address to introduce a delay
> loop.
>
> Remove the table, and convert to code, documenting the purpose of the
> specific writes along the way.
>
> Signed-off-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
Hmm, this patch doesn't apply to the master branch.
Does it depend on other patches being merged first, or it is just out-of-date?
Regards,
Hans
> ---
> drivers/media/i2c/adv748x/adv748x-core.c | 32 ++++++++++++++++--------
> drivers/media/i2c/adv748x/adv748x.h | 16 ++++++++++++
> 2 files changed, 38 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/media/i2c/adv748x/adv748x-core.c b/drivers/media/i2c/adv748x/adv748x-core.c
> index 02f9c440301c..252bdb28b18b 100644
> --- a/drivers/media/i2c/adv748x/adv748x-core.c
> +++ b/drivers/media/i2c/adv748x/adv748x-core.c
> @@ -389,15 +389,6 @@ static const struct media_entity_operations adv748x_media_ops = {
> * HW setup
> */
>
> -static const struct adv748x_reg_value adv748x_sw_reset[] = {
> -
> - {ADV748X_PAGE_IO, 0xff, 0xff}, /* SW reset */
> - {ADV748X_PAGE_WAIT, 0x00, 0x05},/* delay 5 */
> - {ADV748X_PAGE_IO, 0x01, 0x76}, /* ADI Required Write */
> - {ADV748X_PAGE_IO, 0xf2, 0x01}, /* Enable I2C Read Auto-Increment */
> - {ADV748X_PAGE_EOR, 0xff, 0xff} /* End of register table */
> -};
> -
> /* Initialize CP Core with RGB888 format. */
> static const struct adv748x_reg_value adv748x_init_hdmi[] = {
> /* Disable chip powerdown & Enable HDMI Rx block */
> @@ -474,12 +465,33 @@ static const struct adv748x_reg_value adv748x_init_afe[] = {
> {ADV748X_PAGE_EOR, 0xff, 0xff} /* End of register table */
> };
>
> +static int adv748x_sw_reset(struct adv748x_state *state)
> +{
> + int ret;
> +
> + ret = io_write(state, ADV748X_IO_REG_FF, ADV748X_IO_REG_FF_MAIN_RESET);
> + if (ret)
> + return ret;
> +
> + usleep_range(5000, 6000);
> +
> + /* Disable CEC Wakeup from power-down mode */
> + ret = io_clrset(state, ADV748X_IO_REG_01, ADV748X_IO_REG_01_PWRDN_MASK,
> + ADV748X_IO_REG_01_PWRDNB);
> + if (ret)
> + return ret;
> +
> + /* Enable I2C Read Auto-Increment for consecutive reads */
> + return io_write(state, ADV748X_IO_REG_F2,
> + ADV748X_IO_REG_F2_READ_AUTO_INC);
> +}
> +
> static int adv748x_reset(struct adv748x_state *state)
> {
> int ret;
> u8 regval = 0;
>
> - ret = adv748x_write_regs(state, adv748x_sw_reset);
> + ret = adv748x_sw_reset(state);
> if (ret < 0)
> return ret;
>
> diff --git a/drivers/media/i2c/adv748x/adv748x.h b/drivers/media/i2c/adv748x/adv748x.h
> index b00c1995efb0..2f8d751cfbb0 100644
> --- a/drivers/media/i2c/adv748x/adv748x.h
> +++ b/drivers/media/i2c/adv748x/adv748x.h
> @@ -211,6 +211,11 @@ struct adv748x_state {
> #define ADV748X_IO_PD 0x00 /* power down controls */
> #define ADV748X_IO_PD_RX_EN BIT(6)
>
> +#define ADV748X_IO_REG_01 0x01 /* pwrdn{2}b, prog_xtal_freq */
> +#define ADV748X_IO_REG_01_PWRDN_MASK (BIT(7) | BIT(6))
> +#define ADV748X_IO_REG_01_PWRDN2B BIT(7) /* CEC Wakeup Support */
> +#define ADV748X_IO_REG_01_PWRDNB BIT(6) /* CEC Wakeup Support */
> +
> #define ADV748X_IO_REG_04 0x04
> #define ADV748X_IO_REG_04_FORCE_FR BIT(0) /* Force CP free-run */
>
> @@ -229,8 +234,19 @@ struct adv748x_state {
> #define ADV748X_IO_CHIP_REV_ID_1 0xdf
> #define ADV748X_IO_CHIP_REV_ID_2 0xe0
>
> +#define ADV748X_IO_REG_F2 0xf2
> +#define ADV748X_IO_REG_F2_READ_AUTO_INC BIT(0)
> +
> +/* For PAGE slave address offsets */
> #define ADV748X_IO_SLAVE_ADDR_BASE 0xf2
>
> +/*
> + * The ADV748x_Recommended_Settings_PrA_2014-08-20.pdf details both 0x80 and
> + * 0xff as examples for performing a software reset.
> + */
> +#define ADV748X_IO_REG_FF 0xff
> +#define ADV748X_IO_REG_FF_MAIN_RESET 0xff
> +
> /* HDMI RX Map */
> #define ADV748X_HDMI_LW1 0x07 /* line width_1 */
> #define ADV748X_HDMI_LW1_VERT_FILTER BIT(7)
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 1/2] media: i2c: adv748x: Convert SW reset routine to function
2019-01-12 16:50 ` Kieran Bingham
@ 2019-01-18 12:26 ` Laurent Pinchart
0 siblings, 0 replies; 12+ messages in thread
From: Laurent Pinchart @ 2019-01-18 12:26 UTC (permalink / raw)
To: Kieran Bingham
Cc: Koji Matsuoka, Jacopo Mondi, Niklas Söderlund,
Steve Longerbeam, linux-renesas-soc, linux-media
Hi Kieran,
On Sat, Jan 12, 2019 at 04:50:32PM +0000, Kieran Bingham wrote:
> On 11/01/2019 20:15, Laurent Pinchart wrote:
> > On Friday, 11 January 2019 19:41:40 EET Kieran Bingham wrote:
> >> The ADV748x is currently reset by writting a small table of registers to
> >> the device.
> >>
> >> The table lacks documentation and contains magic values to perform the
> >> actions, including using a fake register address to introduce a delay
> >> loop.
> >>
> >> Remove the table, and convert to code, documenting the purpose of the
> >> specific writes along the way.
> >>
> >> Signed-off-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
> >> ---
> >> drivers/media/i2c/adv748x/adv748x-core.c | 32 ++++++++++++++++--------
> >> drivers/media/i2c/adv748x/adv748x.h | 16 ++++++++++++
> >> 2 files changed, 38 insertions(+), 10 deletions(-)
> >>
> >> diff --git a/drivers/media/i2c/adv748x/adv748x-core.c
> >> b/drivers/media/i2c/adv748x/adv748x-core.c index 02f9c440301c..252bdb28b18b
> >> 100644
> >> --- a/drivers/media/i2c/adv748x/adv748x-core.c
> >> +++ b/drivers/media/i2c/adv748x/adv748x-core.c
> >> @@ -389,15 +389,6 @@ static const struct media_entity_operations
> >> adv748x_media_ops = { * HW setup
> >> */
> >>
> >> -static const struct adv748x_reg_value adv748x_sw_reset[] = {
> >> -
> >> - {ADV748X_PAGE_IO, 0xff, 0xff}, /* SW reset */
> >> - {ADV748X_PAGE_WAIT, 0x00, 0x05},/* delay 5 */
> >> - {ADV748X_PAGE_IO, 0x01, 0x76}, /* ADI Required Write */
> >> - {ADV748X_PAGE_IO, 0xf2, 0x01}, /* Enable I2C Read Auto-Increment */
> >> - {ADV748X_PAGE_EOR, 0xff, 0xff} /* End of register table */
> >> -};
> >> -
> >> /* Initialize CP Core with RGB888 format. */
> >> static const struct adv748x_reg_value adv748x_init_hdmi[] = {
> >> /* Disable chip powerdown & Enable HDMI Rx block */
> >> @@ -474,12 +465,33 @@ static const struct adv748x_reg_value
> >> adv748x_init_afe[] = { {ADV748X_PAGE_EOR, 0xff, 0xff} /* End of register
> >> table */
> >> };
> >>
> >> +static int adv748x_sw_reset(struct adv748x_state *state)
> >> +{
> >> + int ret;
> >> +
> >> + ret = io_write(state, ADV748X_IO_REG_FF, ADV748X_IO_REG_FF_MAIN_RESET);
> >> + if (ret)
> >> + return ret;
> >> +
> >> + usleep_range(5000, 6000);
> >> +
> >> + /* Disable CEC Wakeup from power-down mode */
> >> + ret = io_clrset(state, ADV748X_IO_REG_01, ADV748X_IO_REG_01_PWRDN_MASK,
> >> + ADV748X_IO_REG_01_PWRDNB);
> >
> > What's the reason for io_clrset() instead of io_write() ?
> >
>
> The register is multi-purpose, and controls CEC Wakeup and *part* of the
> prog_xtal_freq clock parameters.
>
> The original table writes the default value of the clock parameter - but
> that itself is split over two registers I think - so I didn't want to be
> 'half setting' some parameter, which should already be at its default
> anyway.
>
> I felt it was cleaner to be precise and make this code perform only the
> actual *change* that was required (which is the adjustment of the cec
> powerdown mode control, as described by the comment).
I agree with you in general, but as the write comes just after a reset,
I thought a full register write would be better. Up to you.
> > Apart from this,
> >
> > Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> >
> >> + if (ret)
> >> + return ret;
> >> +
> >> + /* Enable I2C Read Auto-Increment for consecutive reads */
> >> + return io_write(state, ADV748X_IO_REG_F2,
> >> + ADV748X_IO_REG_F2_READ_AUTO_INC);
> >> +}
> >> +
> >> static int adv748x_reset(struct adv748x_state *state)
> >> {
> >> int ret;
> >> u8 regval = 0;
> >>
> >> - ret = adv748x_write_regs(state, adv748x_sw_reset);
> >> + ret = adv748x_sw_reset(state);
> >> if (ret < 0)
> >> return ret;
> >>
> >> diff --git a/drivers/media/i2c/adv748x/adv748x.h
> >> b/drivers/media/i2c/adv748x/adv748x.h index b00c1995efb0..2f8d751cfbb0
> >> 100644
> >> --- a/drivers/media/i2c/adv748x/adv748x.h
> >> +++ b/drivers/media/i2c/adv748x/adv748x.h
> >> @@ -211,6 +211,11 @@ struct adv748x_state {
> >> #define ADV748X_IO_PD 0x00 /* power down controls */
> >> #define ADV748X_IO_PD_RX_EN BIT(6)
> >>
> >> +#define ADV748X_IO_REG_01 0x01 /* pwrdn{2}b, prog_xtal_freq */
> >> +#define ADV748X_IO_REG_01_PWRDN_MASK (BIT(7) | BIT(6))
> >> +#define ADV748X_IO_REG_01_PWRDN2B BIT(7) /* CEC Wakeup Support */
> >> +#define ADV748X_IO_REG_01_PWRDNB BIT(6) /* CEC Wakeup Support */
> >> +
> >> #define ADV748X_IO_REG_04 0x04
> >> #define ADV748X_IO_REG_04_FORCE_FR BIT(0) /* Force CP free-run */
> >>
> >> @@ -229,8 +234,19 @@ struct adv748x_state {
> >> #define ADV748X_IO_CHIP_REV_ID_1 0xdf
> >> #define ADV748X_IO_CHIP_REV_ID_2 0xe0
> >>
> >> +#define ADV748X_IO_REG_F2 0xf2
> >> +#define ADV748X_IO_REG_F2_READ_AUTO_INC BIT(0)
> >> +
> >> +/* For PAGE slave address offsets */
> >> #define ADV748X_IO_SLAVE_ADDR_BASE 0xf2
> >>
> >> +/*
> >> + * The ADV748x_Recommended_Settings_PrA_2014-08-20.pdf details both 0x80
> >> and + * 0xff as examples for performing a software reset.
> >> + */
> >> +#define ADV748X_IO_REG_FF 0xff
> >> +#define ADV748X_IO_REG_FF_MAIN_RESET 0xff
> >> +
> >> /* HDMI RX Map */
> >> #define ADV748X_HDMI_LW1 0x07 /* line width_1 */
> >> #define ADV748X_HDMI_LW1_VERT_FILTER BIT(7)
--
Regards,
Laurent Pinchart
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 1/2] media: i2c: adv748x: Convert SW reset routine to function
2019-01-18 12:09 ` Hans Verkuil
@ 2019-01-18 13:34 ` Kieran Bingham
0 siblings, 0 replies; 12+ messages in thread
From: Kieran Bingham @ 2019-01-18 13:34 UTC (permalink / raw)
To: Hans Verkuil, Koji Matsuoka, Jacopo Mondi, Laurent Pinchart,
Niklas Söderlund, Steve Longerbeam
Cc: linux-renesas-soc, linux-media
Hi Hans,
On 18/01/2019 12:09, Hans Verkuil wrote:
> On 1/11/19 6:41 PM, Kieran Bingham wrote:
>> The ADV748x is currently reset by writting a small table of registers to
>> the device.
s/writting/writing/
>>
>> The table lacks documentation and contains magic values to perform the
>> actions, including using a fake register address to introduce a delay
>> loop.
>>
>> Remove the table, and convert to code, documenting the purpose of the
>> specific writes along the way.
>>
>> Signed-off-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
>
> Hmm, this patch doesn't apply to the master branch.
>
> Does it depend on other patches being merged first, or it is just out-of-date?
Hi Hans,
Sorry - I should have specified - They are dependant upon Jacopo's series.
--
Kieran
>
> Regards,
>
> Hans
>
>> ---
>> drivers/media/i2c/adv748x/adv748x-core.c | 32 ++++++++++++++++--------
>> drivers/media/i2c/adv748x/adv748x.h | 16 ++++++++++++
>> 2 files changed, 38 insertions(+), 10 deletions(-)
>>
>> diff --git a/drivers/media/i2c/adv748x/adv748x-core.c b/drivers/media/i2c/adv748x/adv748x-core.c
>> index 02f9c440301c..252bdb28b18b 100644
>> --- a/drivers/media/i2c/adv748x/adv748x-core.c
>> +++ b/drivers/media/i2c/adv748x/adv748x-core.c
>> @@ -389,15 +389,6 @@ static const struct media_entity_operations adv748x_media_ops = {
>> * HW setup
>> */
>>
>> -static const struct adv748x_reg_value adv748x_sw_reset[] = {
>> -
>> - {ADV748X_PAGE_IO, 0xff, 0xff}, /* SW reset */
>> - {ADV748X_PAGE_WAIT, 0x00, 0x05},/* delay 5 */
>> - {ADV748X_PAGE_IO, 0x01, 0x76}, /* ADI Required Write */
>> - {ADV748X_PAGE_IO, 0xf2, 0x01}, /* Enable I2C Read Auto-Increment */
>> - {ADV748X_PAGE_EOR, 0xff, 0xff} /* End of register table */
>> -};
>> -
>> /* Initialize CP Core with RGB888 format. */
>> static const struct adv748x_reg_value adv748x_init_hdmi[] = {
>> /* Disable chip powerdown & Enable HDMI Rx block */
>> @@ -474,12 +465,33 @@ static const struct adv748x_reg_value adv748x_init_afe[] = {
>> {ADV748X_PAGE_EOR, 0xff, 0xff} /* End of register table */
>> };
>>
>> +static int adv748x_sw_reset(struct adv748x_state *state)
>> +{
>> + int ret;
>> +
>> + ret = io_write(state, ADV748X_IO_REG_FF, ADV748X_IO_REG_FF_MAIN_RESET);
>> + if (ret)
>> + return ret;
>> +
>> + usleep_range(5000, 6000);
>> +
>> + /* Disable CEC Wakeup from power-down mode */
>> + ret = io_clrset(state, ADV748X_IO_REG_01, ADV748X_IO_REG_01_PWRDN_MASK,
>> + ADV748X_IO_REG_01_PWRDNB);
>> + if (ret)
>> + return ret;
>> +
>> + /* Enable I2C Read Auto-Increment for consecutive reads */
>> + return io_write(state, ADV748X_IO_REG_F2,
>> + ADV748X_IO_REG_F2_READ_AUTO_INC);
>> +}
>> +
>> static int adv748x_reset(struct adv748x_state *state)
>> {
>> int ret;
>> u8 regval = 0;
>>
>> - ret = adv748x_write_regs(state, adv748x_sw_reset);
>> + ret = adv748x_sw_reset(state);
>> if (ret < 0)
>> return ret;
>>
>> diff --git a/drivers/media/i2c/adv748x/adv748x.h b/drivers/media/i2c/adv748x/adv748x.h
>> index b00c1995efb0..2f8d751cfbb0 100644
>> --- a/drivers/media/i2c/adv748x/adv748x.h
>> +++ b/drivers/media/i2c/adv748x/adv748x.h
>> @@ -211,6 +211,11 @@ struct adv748x_state {
>> #define ADV748X_IO_PD 0x00 /* power down controls */
>> #define ADV748X_IO_PD_RX_EN BIT(6)
>>
>> +#define ADV748X_IO_REG_01 0x01 /* pwrdn{2}b, prog_xtal_freq */
>> +#define ADV748X_IO_REG_01_PWRDN_MASK (BIT(7) | BIT(6))
>> +#define ADV748X_IO_REG_01_PWRDN2B BIT(7) /* CEC Wakeup Support */
>> +#define ADV748X_IO_REG_01_PWRDNB BIT(6) /* CEC Wakeup Support */
>> +
>> #define ADV748X_IO_REG_04 0x04
>> #define ADV748X_IO_REG_04_FORCE_FR BIT(0) /* Force CP free-run */
>>
>> @@ -229,8 +234,19 @@ struct adv748x_state {
>> #define ADV748X_IO_CHIP_REV_ID_1 0xdf
>> #define ADV748X_IO_CHIP_REV_ID_2 0xe0
>>
>> +#define ADV748X_IO_REG_F2 0xf2
>> +#define ADV748X_IO_REG_F2_READ_AUTO_INC BIT(0)
>> +
>> +/* For PAGE slave address offsets */
>> #define ADV748X_IO_SLAVE_ADDR_BASE 0xf2
>>
>> +/*
>> + * The ADV748x_Recommended_Settings_PrA_2014-08-20.pdf details both 0x80 and
>> + * 0xff as examples for performing a software reset.
>> + */
>> +#define ADV748X_IO_REG_FF 0xff
>> +#define ADV748X_IO_REG_FF_MAIN_RESET 0xff
>> +
>> /* HDMI RX Map */
>> #define ADV748X_HDMI_LW1 0x07 /* line width_1 */
>> #define ADV748X_HDMI_LW1_VERT_FILTER BIT(7)
>>
>
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2019-01-18 13:34 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-11 17:41 [PATCH 0/2] media: i2c: adv748x: Refactor sw_reset handling Kieran Bingham
2019-01-11 17:41 ` [PATCH 1/2] media: i2c: adv748x: Convert SW reset routine to function Kieran Bingham
2019-01-11 20:15 ` Laurent Pinchart
2019-01-12 16:50 ` Kieran Bingham
2019-01-18 12:26 ` Laurent Pinchart
2019-01-14 14:43 ` Niklas Söderlund
2019-01-18 12:09 ` Hans Verkuil
2019-01-18 13:34 ` Kieran Bingham
2019-01-11 17:41 ` [PATCH 2/2] media: i2c: adv748x: Remove PAGE_WAIT Kieran Bingham
2019-01-11 20:23 ` Laurent Pinchart
2019-01-12 16:51 ` Kieran Bingham
2019-01-14 14:44 ` Niklas Söderlund
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).