Re: [PATCH 2/3] drm/ast: Upcast from DRM device to ast structure via to_ast_private()

2020-06-12 Thread Daniel Vetter
On Fri, Jun 12, 2020 at 08:30:40AM +0200, Thomas Zimmermann wrote:
> Hi
> 
> Am 11.06.20 um 21:23 schrieb Sam Ravnborg:
> > Hi Thomas.
> > 
> > On Thu, Jun 11, 2020 at 10:28:08AM +0200, Thomas Zimmermann wrote:
> >> All upcasting from struct drm_device to struct ast_private is now
> >> performed via to_ast_private(). Using struct drm_device.dev_private is
> >> deprecated.
> > 
> > This is a simple 1:1 conversion.
> > But some cases - I checked ast_set_dp501_video_output() =>
> > ast_write_cmd(), ast_write_data()
> > 
> > could have been fixed by passing ast_private * rather than drm_device *.
> > And then no upcasting was needed.
> > 
> > That a more involved approach - but wanted to point it out.
> > Maybe for another day..
> 
> Good idea. I'll consider it, depending on whether it makes the overall
> patchset easier or harder to read.

tbh since the goal is to embed the structures (I assume) I wouldn't
bother. As soon as it's embedded it's the same for the compiler. If you
flip some of the parameters I'd wait until the embedding is completely,
otherwise you have a pile of churn again because of the switch from
pointer to embedded structure.
-Daniel

> 
> Best regards
> Thomas
> 
> > 
> > Sam
> > 
> > 
> > The ast variable in ast_crtc_helperatomic_check() is unused,
> > s/ast_crtc_helperatomic_check/ast_crtc_helper_atomic_check/
> >> so removed it.
> >>
> >> Signed-off-by: Thomas Zimmermann 
> > Acked-by: Sam Ravnborg 
> > 
> >> ---
> >>  drivers/gpu/drm/ast/ast_dp501.c | 24 +--
> >>  drivers/gpu/drm/ast/ast_drv.h   |  5 
> >>  drivers/gpu/drm/ast/ast_main.c  | 10 
> >>  drivers/gpu/drm/ast/ast_mode.c  | 41 -
> >>  drivers/gpu/drm/ast/ast_post.c  | 16 ++---
> >>  5 files changed, 50 insertions(+), 46 deletions(-)
> >>
> >> diff --git a/drivers/gpu/drm/ast/ast_dp501.c 
> >> b/drivers/gpu/drm/ast/ast_dp501.c
> >> index 98cd69269263f..4b85a504825a2 100644
> >> --- a/drivers/gpu/drm/ast/ast_dp501.c
> >> +++ b/drivers/gpu/drm/ast/ast_dp501.c
> >> @@ -10,7 +10,7 @@ MODULE_FIRMWARE("ast_dp501_fw.bin");
> >>  
> >>  static int ast_load_dp501_microcode(struct drm_device *dev)
> >>  {
> >> -  struct ast_private *ast = dev->dev_private;
> >> +  struct ast_private *ast = to_ast_private(dev);
> >>  
> >>return request_firmware(>dp501_fw, "ast_dp501_fw.bin", dev->dev);
> >>  }
> >> @@ -93,7 +93,7 @@ static bool wait_fw_ready(struct ast_private *ast)
> >>  
> >>  static bool ast_write_cmd(struct drm_device *dev, u8 data)
> >>  {
> >> -  struct ast_private *ast = dev->dev_private;
> >> +  struct ast_private *ast = to_ast_private(dev);
> >>int retry = 0;
> >>if (wait_nack(ast)) {
> >>send_nack(ast);
> >> @@ -115,7 +115,7 @@ static bool ast_write_cmd(struct drm_device *dev, u8 
> >> data)
> >>  
> >>  static bool ast_write_data(struct drm_device *dev, u8 data)
> >>  {
> >> -  struct ast_private *ast = dev->dev_private;
> >> +  struct ast_private *ast = to_ast_private(dev);
> >>  
> >>if (wait_nack(ast)) {
> >>send_nack(ast);
> >> @@ -133,7 +133,7 @@ static bool ast_write_data(struct drm_device *dev, u8 
> >> data)
> >>  #if 0
> >>  static bool ast_read_data(struct drm_device *dev, u8 *data)
> >>  {
> >> -  struct ast_private *ast = dev->dev_private;
> >> +  struct ast_private *ast = to_ast_private(dev);
> >>u8 tmp;
> >>  
> >>*data = 0;
> >> @@ -172,7 +172,7 @@ static u32 get_fw_base(struct ast_private *ast)
> >>  
> >>  bool ast_backup_fw(struct drm_device *dev, u8 *addr, u32 size)
> >>  {
> >> -  struct ast_private *ast = dev->dev_private;
> >> +  struct ast_private *ast = to_ast_private(dev);
> >>u32 i, data;
> >>u32 boot_address;
> >>  
> >> @@ -188,7 +188,7 @@ bool ast_backup_fw(struct drm_device *dev, u8 *addr, 
> >> u32 size)
> >>  
> >>  static bool ast_launch_m68k(struct drm_device *dev)
> >>  {
> >> -  struct ast_private *ast = dev->dev_private;
> >> +  struct ast_private *ast = to_ast_private(dev);
> >>u32 i, data, len = 0;
> >>u32 boot_address;
> >>u8 *fw_addr = NULL;
> >> @@ -255,7 +255,7 @@ static bool ast_launch_m68k(struct drm_device *dev)
> >>  
> >>  u8 ast_get_dp501_max_clk(struct drm_device *dev)
> >>  {
> >> -  struct ast_private *ast = dev->dev_private;
> >> +  struct ast_private *ast = to_ast_private(dev);
> >>u32 boot_address, offset, data;
> >>u8 linkcap[4], linkrate, linklanes, maxclk = 0xff;
> >>  
> >> @@ -283,7 +283,7 @@ u8 ast_get_dp501_max_clk(struct drm_device *dev)
> >>  
> >>  bool ast_dp501_read_edid(struct drm_device *dev, u8 *ediddata)
> >>  {
> >> -  struct ast_private *ast = dev->dev_private;
> >> +  struct ast_private *ast = to_ast_private(dev);
> >>u32 i, boot_address, offset, data;
> >>  
> >>boot_address = get_fw_base(ast);
> >> @@ -312,7 +312,7 @@ bool ast_dp501_read_edid(struct drm_device *dev, u8 
> >> *ediddata)
> >>  
> >>  static bool ast_init_dvo(struct drm_device *dev)
> >>  {
> >> -  struct ast_private *ast = 

Re: [PATCH 2/3] drm/ast: Upcast from DRM device to ast structure via to_ast_private()

2020-06-12 Thread Thomas Zimmermann
Hi

Am 11.06.20 um 19:32 schrieb Daniel Vetter:
> On Thu, Jun 11, 2020 at 10:28:08AM +0200, Thomas Zimmermann wrote:
>> All upcasting from struct drm_device to struct ast_private is now
>> performed via to_ast_private(). Using struct drm_device.dev_private is
>> deprecated. The ast variable in ast_crtc_helperatomic_check() is unused,
>> so removed it.
>>
>> Signed-off-by: Thomas Zimmermann 
> 
> Reviewed-by: Daniel Vetter 
> 
> Aside, the check in ast_pm_freeze is bogus, you can't resume/freeze before
> the driver has completed loading.

Ah, OK. I'll remove it then.

Best regards
Thomas

> 
> I suspect this is a remnant from the old days of dri1 where freeze/resume
> before the driver finished loading was very much possible with the shadow
> attach stuff. So probably just copypasta stuff.
> 
> In general when you spot that in a modern kms driver, then just delete it.
> that = checking whether the drm_device or dev_private is set. Definitely
> not a pattern we should propagate.
> 
> Cheers, Daniel
> 
>> ---
>>  drivers/gpu/drm/ast/ast_dp501.c | 24 +--
>>  drivers/gpu/drm/ast/ast_drv.h   |  5 
>>  drivers/gpu/drm/ast/ast_main.c  | 10 
>>  drivers/gpu/drm/ast/ast_mode.c  | 41 -
>>  drivers/gpu/drm/ast/ast_post.c  | 16 ++---
>>  5 files changed, 50 insertions(+), 46 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/ast/ast_dp501.c 
>> b/drivers/gpu/drm/ast/ast_dp501.c
>> index 98cd69269263f..4b85a504825a2 100644
>> --- a/drivers/gpu/drm/ast/ast_dp501.c
>> +++ b/drivers/gpu/drm/ast/ast_dp501.c
>> @@ -10,7 +10,7 @@ MODULE_FIRMWARE("ast_dp501_fw.bin");
>>  
>>  static int ast_load_dp501_microcode(struct drm_device *dev)
>>  {
>> -struct ast_private *ast = dev->dev_private;
>> +struct ast_private *ast = to_ast_private(dev);
>>  
>>  return request_firmware(>dp501_fw, "ast_dp501_fw.bin", dev->dev);
>>  }
>> @@ -93,7 +93,7 @@ static bool wait_fw_ready(struct ast_private *ast)
>>  
>>  static bool ast_write_cmd(struct drm_device *dev, u8 data)
>>  {
>> -struct ast_private *ast = dev->dev_private;
>> +struct ast_private *ast = to_ast_private(dev);
>>  int retry = 0;
>>  if (wait_nack(ast)) {
>>  send_nack(ast);
>> @@ -115,7 +115,7 @@ static bool ast_write_cmd(struct drm_device *dev, u8 
>> data)
>>  
>>  static bool ast_write_data(struct drm_device *dev, u8 data)
>>  {
>> -struct ast_private *ast = dev->dev_private;
>> +struct ast_private *ast = to_ast_private(dev);
>>  
>>  if (wait_nack(ast)) {
>>  send_nack(ast);
>> @@ -133,7 +133,7 @@ static bool ast_write_data(struct drm_device *dev, u8 
>> data)
>>  #if 0
>>  static bool ast_read_data(struct drm_device *dev, u8 *data)
>>  {
>> -struct ast_private *ast = dev->dev_private;
>> +struct ast_private *ast = to_ast_private(dev);
>>  u8 tmp;
>>  
>>  *data = 0;
>> @@ -172,7 +172,7 @@ static u32 get_fw_base(struct ast_private *ast)
>>  
>>  bool ast_backup_fw(struct drm_device *dev, u8 *addr, u32 size)
>>  {
>> -struct ast_private *ast = dev->dev_private;
>> +struct ast_private *ast = to_ast_private(dev);
>>  u32 i, data;
>>  u32 boot_address;
>>  
>> @@ -188,7 +188,7 @@ bool ast_backup_fw(struct drm_device *dev, u8 *addr, u32 
>> size)
>>  
>>  static bool ast_launch_m68k(struct drm_device *dev)
>>  {
>> -struct ast_private *ast = dev->dev_private;
>> +struct ast_private *ast = to_ast_private(dev);
>>  u32 i, data, len = 0;
>>  u32 boot_address;
>>  u8 *fw_addr = NULL;
>> @@ -255,7 +255,7 @@ static bool ast_launch_m68k(struct drm_device *dev)
>>  
>>  u8 ast_get_dp501_max_clk(struct drm_device *dev)
>>  {
>> -struct ast_private *ast = dev->dev_private;
>> +struct ast_private *ast = to_ast_private(dev);
>>  u32 boot_address, offset, data;
>>  u8 linkcap[4], linkrate, linklanes, maxclk = 0xff;
>>  
>> @@ -283,7 +283,7 @@ u8 ast_get_dp501_max_clk(struct drm_device *dev)
>>  
>>  bool ast_dp501_read_edid(struct drm_device *dev, u8 *ediddata)
>>  {
>> -struct ast_private *ast = dev->dev_private;
>> +struct ast_private *ast = to_ast_private(dev);
>>  u32 i, boot_address, offset, data;
>>  
>>  boot_address = get_fw_base(ast);
>> @@ -312,7 +312,7 @@ bool ast_dp501_read_edid(struct drm_device *dev, u8 
>> *ediddata)
>>  
>>  static bool ast_init_dvo(struct drm_device *dev)
>>  {
>> -struct ast_private *ast = dev->dev_private;
>> +struct ast_private *ast = to_ast_private(dev);
>>  u8 jreg;
>>  u32 data;
>>  ast_write32(ast, 0xf004, 0x1e6e);
>> @@ -385,7 +385,7 @@ static bool ast_init_dvo(struct drm_device *dev)
>>  
>>  static void ast_init_analog(struct drm_device *dev)
>>  {
>> -struct ast_private *ast = dev->dev_private;
>> +struct ast_private *ast = to_ast_private(dev);
>>  u32 data;
>>  
>>  /*
>> @@ -412,7 +412,7 @@ static void ast_init_analog(struct drm_device *dev)
>>  
>>  void ast_init_3rdtx(struct drm_device *dev)
>>  

Re: [PATCH 2/3] drm/ast: Upcast from DRM device to ast structure via to_ast_private()

2020-06-12 Thread Thomas Zimmermann
Hi

Am 11.06.20 um 21:23 schrieb Sam Ravnborg:
> Hi Thomas.
> 
> On Thu, Jun 11, 2020 at 10:28:08AM +0200, Thomas Zimmermann wrote:
>> All upcasting from struct drm_device to struct ast_private is now
>> performed via to_ast_private(). Using struct drm_device.dev_private is
>> deprecated.
> 
> This is a simple 1:1 conversion.
> But some cases - I checked ast_set_dp501_video_output() =>
> ast_write_cmd(), ast_write_data()
> 
> could have been fixed by passing ast_private * rather than drm_device *.
> And then no upcasting was needed.
> 
> That a more involved approach - but wanted to point it out.
> Maybe for another day..

Good idea. I'll consider it, depending on whether it makes the overall
patchset easier or harder to read.

Best regards
Thomas

> 
>   Sam
> 
> 
> The ast variable in ast_crtc_helperatomic_check() is unused,
> s/ast_crtc_helperatomic_check/ast_crtc_helper_atomic_check/
>> so removed it.
>>
>> Signed-off-by: Thomas Zimmermann 
> Acked-by: Sam Ravnborg 
> 
>> ---
>>  drivers/gpu/drm/ast/ast_dp501.c | 24 +--
>>  drivers/gpu/drm/ast/ast_drv.h   |  5 
>>  drivers/gpu/drm/ast/ast_main.c  | 10 
>>  drivers/gpu/drm/ast/ast_mode.c  | 41 -
>>  drivers/gpu/drm/ast/ast_post.c  | 16 ++---
>>  5 files changed, 50 insertions(+), 46 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/ast/ast_dp501.c 
>> b/drivers/gpu/drm/ast/ast_dp501.c
>> index 98cd69269263f..4b85a504825a2 100644
>> --- a/drivers/gpu/drm/ast/ast_dp501.c
>> +++ b/drivers/gpu/drm/ast/ast_dp501.c
>> @@ -10,7 +10,7 @@ MODULE_FIRMWARE("ast_dp501_fw.bin");
>>  
>>  static int ast_load_dp501_microcode(struct drm_device *dev)
>>  {
>> -struct ast_private *ast = dev->dev_private;
>> +struct ast_private *ast = to_ast_private(dev);
>>  
>>  return request_firmware(>dp501_fw, "ast_dp501_fw.bin", dev->dev);
>>  }
>> @@ -93,7 +93,7 @@ static bool wait_fw_ready(struct ast_private *ast)
>>  
>>  static bool ast_write_cmd(struct drm_device *dev, u8 data)
>>  {
>> -struct ast_private *ast = dev->dev_private;
>> +struct ast_private *ast = to_ast_private(dev);
>>  int retry = 0;
>>  if (wait_nack(ast)) {
>>  send_nack(ast);
>> @@ -115,7 +115,7 @@ static bool ast_write_cmd(struct drm_device *dev, u8 
>> data)
>>  
>>  static bool ast_write_data(struct drm_device *dev, u8 data)
>>  {
>> -struct ast_private *ast = dev->dev_private;
>> +struct ast_private *ast = to_ast_private(dev);
>>  
>>  if (wait_nack(ast)) {
>>  send_nack(ast);
>> @@ -133,7 +133,7 @@ static bool ast_write_data(struct drm_device *dev, u8 
>> data)
>>  #if 0
>>  static bool ast_read_data(struct drm_device *dev, u8 *data)
>>  {
>> -struct ast_private *ast = dev->dev_private;
>> +struct ast_private *ast = to_ast_private(dev);
>>  u8 tmp;
>>  
>>  *data = 0;
>> @@ -172,7 +172,7 @@ static u32 get_fw_base(struct ast_private *ast)
>>  
>>  bool ast_backup_fw(struct drm_device *dev, u8 *addr, u32 size)
>>  {
>> -struct ast_private *ast = dev->dev_private;
>> +struct ast_private *ast = to_ast_private(dev);
>>  u32 i, data;
>>  u32 boot_address;
>>  
>> @@ -188,7 +188,7 @@ bool ast_backup_fw(struct drm_device *dev, u8 *addr, u32 
>> size)
>>  
>>  static bool ast_launch_m68k(struct drm_device *dev)
>>  {
>> -struct ast_private *ast = dev->dev_private;
>> +struct ast_private *ast = to_ast_private(dev);
>>  u32 i, data, len = 0;
>>  u32 boot_address;
>>  u8 *fw_addr = NULL;
>> @@ -255,7 +255,7 @@ static bool ast_launch_m68k(struct drm_device *dev)
>>  
>>  u8 ast_get_dp501_max_clk(struct drm_device *dev)
>>  {
>> -struct ast_private *ast = dev->dev_private;
>> +struct ast_private *ast = to_ast_private(dev);
>>  u32 boot_address, offset, data;
>>  u8 linkcap[4], linkrate, linklanes, maxclk = 0xff;
>>  
>> @@ -283,7 +283,7 @@ u8 ast_get_dp501_max_clk(struct drm_device *dev)
>>  
>>  bool ast_dp501_read_edid(struct drm_device *dev, u8 *ediddata)
>>  {
>> -struct ast_private *ast = dev->dev_private;
>> +struct ast_private *ast = to_ast_private(dev);
>>  u32 i, boot_address, offset, data;
>>  
>>  boot_address = get_fw_base(ast);
>> @@ -312,7 +312,7 @@ bool ast_dp501_read_edid(struct drm_device *dev, u8 
>> *ediddata)
>>  
>>  static bool ast_init_dvo(struct drm_device *dev)
>>  {
>> -struct ast_private *ast = dev->dev_private;
>> +struct ast_private *ast = to_ast_private(dev);
>>  u8 jreg;
>>  u32 data;
>>  ast_write32(ast, 0xf004, 0x1e6e);
>> @@ -385,7 +385,7 @@ static bool ast_init_dvo(struct drm_device *dev)
>>  
>>  static void ast_init_analog(struct drm_device *dev)
>>  {
>> -struct ast_private *ast = dev->dev_private;
>> +struct ast_private *ast = to_ast_private(dev);
>>  u32 data;
>>  
>>  /*
>> @@ -412,7 +412,7 @@ static void ast_init_analog(struct drm_device *dev)
>>  
>>  void ast_init_3rdtx(struct drm_device *dev)
>>  {
>> -struct 

Re: [PATCH 2/3] drm/ast: Upcast from DRM device to ast structure via to_ast_private()

2020-06-11 Thread Sam Ravnborg
Hi Thomas.

On Thu, Jun 11, 2020 at 10:28:08AM +0200, Thomas Zimmermann wrote:
> All upcasting from struct drm_device to struct ast_private is now
> performed via to_ast_private(). Using struct drm_device.dev_private is
> deprecated.

This is a simple 1:1 conversion.
But some cases - I checked ast_set_dp501_video_output() =>
ast_write_cmd(), ast_write_data()

could have been fixed by passing ast_private * rather than drm_device *.
And then no upcasting was needed.

That a more involved approach - but wanted to point it out.
Maybe for another day..

Sam


The ast variable in ast_crtc_helperatomic_check() is unused,
s/ast_crtc_helperatomic_check/ast_crtc_helper_atomic_check/
> so removed it.
> 
> Signed-off-by: Thomas Zimmermann 
Acked-by: Sam Ravnborg 

> ---
>  drivers/gpu/drm/ast/ast_dp501.c | 24 +--
>  drivers/gpu/drm/ast/ast_drv.h   |  5 
>  drivers/gpu/drm/ast/ast_main.c  | 10 
>  drivers/gpu/drm/ast/ast_mode.c  | 41 -
>  drivers/gpu/drm/ast/ast_post.c  | 16 ++---
>  5 files changed, 50 insertions(+), 46 deletions(-)
> 
> diff --git a/drivers/gpu/drm/ast/ast_dp501.c b/drivers/gpu/drm/ast/ast_dp501.c
> index 98cd69269263f..4b85a504825a2 100644
> --- a/drivers/gpu/drm/ast/ast_dp501.c
> +++ b/drivers/gpu/drm/ast/ast_dp501.c
> @@ -10,7 +10,7 @@ MODULE_FIRMWARE("ast_dp501_fw.bin");
>  
>  static int ast_load_dp501_microcode(struct drm_device *dev)
>  {
> - struct ast_private *ast = dev->dev_private;
> + struct ast_private *ast = to_ast_private(dev);
>  
>   return request_firmware(>dp501_fw, "ast_dp501_fw.bin", dev->dev);
>  }
> @@ -93,7 +93,7 @@ static bool wait_fw_ready(struct ast_private *ast)
>  
>  static bool ast_write_cmd(struct drm_device *dev, u8 data)
>  {
> - struct ast_private *ast = dev->dev_private;
> + struct ast_private *ast = to_ast_private(dev);
>   int retry = 0;
>   if (wait_nack(ast)) {
>   send_nack(ast);
> @@ -115,7 +115,7 @@ static bool ast_write_cmd(struct drm_device *dev, u8 data)
>  
>  static bool ast_write_data(struct drm_device *dev, u8 data)
>  {
> - struct ast_private *ast = dev->dev_private;
> + struct ast_private *ast = to_ast_private(dev);
>  
>   if (wait_nack(ast)) {
>   send_nack(ast);
> @@ -133,7 +133,7 @@ static bool ast_write_data(struct drm_device *dev, u8 
> data)
>  #if 0
>  static bool ast_read_data(struct drm_device *dev, u8 *data)
>  {
> - struct ast_private *ast = dev->dev_private;
> + struct ast_private *ast = to_ast_private(dev);
>   u8 tmp;
>  
>   *data = 0;
> @@ -172,7 +172,7 @@ static u32 get_fw_base(struct ast_private *ast)
>  
>  bool ast_backup_fw(struct drm_device *dev, u8 *addr, u32 size)
>  {
> - struct ast_private *ast = dev->dev_private;
> + struct ast_private *ast = to_ast_private(dev);
>   u32 i, data;
>   u32 boot_address;
>  
> @@ -188,7 +188,7 @@ bool ast_backup_fw(struct drm_device *dev, u8 *addr, u32 
> size)
>  
>  static bool ast_launch_m68k(struct drm_device *dev)
>  {
> - struct ast_private *ast = dev->dev_private;
> + struct ast_private *ast = to_ast_private(dev);
>   u32 i, data, len = 0;
>   u32 boot_address;
>   u8 *fw_addr = NULL;
> @@ -255,7 +255,7 @@ static bool ast_launch_m68k(struct drm_device *dev)
>  
>  u8 ast_get_dp501_max_clk(struct drm_device *dev)
>  {
> - struct ast_private *ast = dev->dev_private;
> + struct ast_private *ast = to_ast_private(dev);
>   u32 boot_address, offset, data;
>   u8 linkcap[4], linkrate, linklanes, maxclk = 0xff;
>  
> @@ -283,7 +283,7 @@ u8 ast_get_dp501_max_clk(struct drm_device *dev)
>  
>  bool ast_dp501_read_edid(struct drm_device *dev, u8 *ediddata)
>  {
> - struct ast_private *ast = dev->dev_private;
> + struct ast_private *ast = to_ast_private(dev);
>   u32 i, boot_address, offset, data;
>  
>   boot_address = get_fw_base(ast);
> @@ -312,7 +312,7 @@ bool ast_dp501_read_edid(struct drm_device *dev, u8 
> *ediddata)
>  
>  static bool ast_init_dvo(struct drm_device *dev)
>  {
> - struct ast_private *ast = dev->dev_private;
> + struct ast_private *ast = to_ast_private(dev);
>   u8 jreg;
>   u32 data;
>   ast_write32(ast, 0xf004, 0x1e6e);
> @@ -385,7 +385,7 @@ static bool ast_init_dvo(struct drm_device *dev)
>  
>  static void ast_init_analog(struct drm_device *dev)
>  {
> - struct ast_private *ast = dev->dev_private;
> + struct ast_private *ast = to_ast_private(dev);
>   u32 data;
>  
>   /*
> @@ -412,7 +412,7 @@ static void ast_init_analog(struct drm_device *dev)
>  
>  void ast_init_3rdtx(struct drm_device *dev)
>  {
> - struct ast_private *ast = dev->dev_private;
> + struct ast_private *ast = to_ast_private(dev);
>   u8 jreg;
>  
>   if (ast->chip == AST2300 || ast->chip == AST2400) {
> @@ -438,7 +438,7 @@ void ast_init_3rdtx(struct drm_device *dev)
>  
>  void ast_release_firmware(struct drm_device *dev)
>  {

Re: [PATCH 2/3] drm/ast: Upcast from DRM device to ast structure via to_ast_private()

2020-06-11 Thread Daniel Vetter
On Thu, Jun 11, 2020 at 10:28:08AM +0200, Thomas Zimmermann wrote:
> All upcasting from struct drm_device to struct ast_private is now
> performed via to_ast_private(). Using struct drm_device.dev_private is
> deprecated. The ast variable in ast_crtc_helperatomic_check() is unused,
> so removed it.
> 
> Signed-off-by: Thomas Zimmermann 

Reviewed-by: Daniel Vetter 

Aside, the check in ast_pm_freeze is bogus, you can't resume/freeze before
the driver has completed loading.

I suspect this is a remnant from the old days of dri1 where freeze/resume
before the driver finished loading was very much possible with the shadow
attach stuff. So probably just copypasta stuff.

In general when you spot that in a modern kms driver, then just delete it.
that = checking whether the drm_device or dev_private is set. Definitely
not a pattern we should propagate.

Cheers, Daniel

> ---
>  drivers/gpu/drm/ast/ast_dp501.c | 24 +--
>  drivers/gpu/drm/ast/ast_drv.h   |  5 
>  drivers/gpu/drm/ast/ast_main.c  | 10 
>  drivers/gpu/drm/ast/ast_mode.c  | 41 -
>  drivers/gpu/drm/ast/ast_post.c  | 16 ++---
>  5 files changed, 50 insertions(+), 46 deletions(-)
> 
> diff --git a/drivers/gpu/drm/ast/ast_dp501.c b/drivers/gpu/drm/ast/ast_dp501.c
> index 98cd69269263f..4b85a504825a2 100644
> --- a/drivers/gpu/drm/ast/ast_dp501.c
> +++ b/drivers/gpu/drm/ast/ast_dp501.c
> @@ -10,7 +10,7 @@ MODULE_FIRMWARE("ast_dp501_fw.bin");
>  
>  static int ast_load_dp501_microcode(struct drm_device *dev)
>  {
> - struct ast_private *ast = dev->dev_private;
> + struct ast_private *ast = to_ast_private(dev);
>  
>   return request_firmware(>dp501_fw, "ast_dp501_fw.bin", dev->dev);
>  }
> @@ -93,7 +93,7 @@ static bool wait_fw_ready(struct ast_private *ast)
>  
>  static bool ast_write_cmd(struct drm_device *dev, u8 data)
>  {
> - struct ast_private *ast = dev->dev_private;
> + struct ast_private *ast = to_ast_private(dev);
>   int retry = 0;
>   if (wait_nack(ast)) {
>   send_nack(ast);
> @@ -115,7 +115,7 @@ static bool ast_write_cmd(struct drm_device *dev, u8 data)
>  
>  static bool ast_write_data(struct drm_device *dev, u8 data)
>  {
> - struct ast_private *ast = dev->dev_private;
> + struct ast_private *ast = to_ast_private(dev);
>  
>   if (wait_nack(ast)) {
>   send_nack(ast);
> @@ -133,7 +133,7 @@ static bool ast_write_data(struct drm_device *dev, u8 
> data)
>  #if 0
>  static bool ast_read_data(struct drm_device *dev, u8 *data)
>  {
> - struct ast_private *ast = dev->dev_private;
> + struct ast_private *ast = to_ast_private(dev);
>   u8 tmp;
>  
>   *data = 0;
> @@ -172,7 +172,7 @@ static u32 get_fw_base(struct ast_private *ast)
>  
>  bool ast_backup_fw(struct drm_device *dev, u8 *addr, u32 size)
>  {
> - struct ast_private *ast = dev->dev_private;
> + struct ast_private *ast = to_ast_private(dev);
>   u32 i, data;
>   u32 boot_address;
>  
> @@ -188,7 +188,7 @@ bool ast_backup_fw(struct drm_device *dev, u8 *addr, u32 
> size)
>  
>  static bool ast_launch_m68k(struct drm_device *dev)
>  {
> - struct ast_private *ast = dev->dev_private;
> + struct ast_private *ast = to_ast_private(dev);
>   u32 i, data, len = 0;
>   u32 boot_address;
>   u8 *fw_addr = NULL;
> @@ -255,7 +255,7 @@ static bool ast_launch_m68k(struct drm_device *dev)
>  
>  u8 ast_get_dp501_max_clk(struct drm_device *dev)
>  {
> - struct ast_private *ast = dev->dev_private;
> + struct ast_private *ast = to_ast_private(dev);
>   u32 boot_address, offset, data;
>   u8 linkcap[4], linkrate, linklanes, maxclk = 0xff;
>  
> @@ -283,7 +283,7 @@ u8 ast_get_dp501_max_clk(struct drm_device *dev)
>  
>  bool ast_dp501_read_edid(struct drm_device *dev, u8 *ediddata)
>  {
> - struct ast_private *ast = dev->dev_private;
> + struct ast_private *ast = to_ast_private(dev);
>   u32 i, boot_address, offset, data;
>  
>   boot_address = get_fw_base(ast);
> @@ -312,7 +312,7 @@ bool ast_dp501_read_edid(struct drm_device *dev, u8 
> *ediddata)
>  
>  static bool ast_init_dvo(struct drm_device *dev)
>  {
> - struct ast_private *ast = dev->dev_private;
> + struct ast_private *ast = to_ast_private(dev);
>   u8 jreg;
>   u32 data;
>   ast_write32(ast, 0xf004, 0x1e6e);
> @@ -385,7 +385,7 @@ static bool ast_init_dvo(struct drm_device *dev)
>  
>  static void ast_init_analog(struct drm_device *dev)
>  {
> - struct ast_private *ast = dev->dev_private;
> + struct ast_private *ast = to_ast_private(dev);
>   u32 data;
>  
>   /*
> @@ -412,7 +412,7 @@ static void ast_init_analog(struct drm_device *dev)
>  
>  void ast_init_3rdtx(struct drm_device *dev)
>  {
> - struct ast_private *ast = dev->dev_private;
> + struct ast_private *ast = to_ast_private(dev);
>   u8 jreg;
>  
>   if (ast->chip == AST2300 || ast->chip == AST2400) {
> @@ -438,7 +438,7 @@ 

[PATCH 2/3] drm/ast: Upcast from DRM device to ast structure via to_ast_private()

2020-06-11 Thread Thomas Zimmermann
All upcasting from struct drm_device to struct ast_private is now
performed via to_ast_private(). Using struct drm_device.dev_private is
deprecated. The ast variable in ast_crtc_helperatomic_check() is unused,
so removed it.

Signed-off-by: Thomas Zimmermann 
---
 drivers/gpu/drm/ast/ast_dp501.c | 24 +--
 drivers/gpu/drm/ast/ast_drv.h   |  5 
 drivers/gpu/drm/ast/ast_main.c  | 10 
 drivers/gpu/drm/ast/ast_mode.c  | 41 -
 drivers/gpu/drm/ast/ast_post.c  | 16 ++---
 5 files changed, 50 insertions(+), 46 deletions(-)

diff --git a/drivers/gpu/drm/ast/ast_dp501.c b/drivers/gpu/drm/ast/ast_dp501.c
index 98cd69269263f..4b85a504825a2 100644
--- a/drivers/gpu/drm/ast/ast_dp501.c
+++ b/drivers/gpu/drm/ast/ast_dp501.c
@@ -10,7 +10,7 @@ MODULE_FIRMWARE("ast_dp501_fw.bin");
 
 static int ast_load_dp501_microcode(struct drm_device *dev)
 {
-   struct ast_private *ast = dev->dev_private;
+   struct ast_private *ast = to_ast_private(dev);
 
return request_firmware(>dp501_fw, "ast_dp501_fw.bin", dev->dev);
 }
@@ -93,7 +93,7 @@ static bool wait_fw_ready(struct ast_private *ast)
 
 static bool ast_write_cmd(struct drm_device *dev, u8 data)
 {
-   struct ast_private *ast = dev->dev_private;
+   struct ast_private *ast = to_ast_private(dev);
int retry = 0;
if (wait_nack(ast)) {
send_nack(ast);
@@ -115,7 +115,7 @@ static bool ast_write_cmd(struct drm_device *dev, u8 data)
 
 static bool ast_write_data(struct drm_device *dev, u8 data)
 {
-   struct ast_private *ast = dev->dev_private;
+   struct ast_private *ast = to_ast_private(dev);
 
if (wait_nack(ast)) {
send_nack(ast);
@@ -133,7 +133,7 @@ static bool ast_write_data(struct drm_device *dev, u8 data)
 #if 0
 static bool ast_read_data(struct drm_device *dev, u8 *data)
 {
-   struct ast_private *ast = dev->dev_private;
+   struct ast_private *ast = to_ast_private(dev);
u8 tmp;
 
*data = 0;
@@ -172,7 +172,7 @@ static u32 get_fw_base(struct ast_private *ast)
 
 bool ast_backup_fw(struct drm_device *dev, u8 *addr, u32 size)
 {
-   struct ast_private *ast = dev->dev_private;
+   struct ast_private *ast = to_ast_private(dev);
u32 i, data;
u32 boot_address;
 
@@ -188,7 +188,7 @@ bool ast_backup_fw(struct drm_device *dev, u8 *addr, u32 
size)
 
 static bool ast_launch_m68k(struct drm_device *dev)
 {
-   struct ast_private *ast = dev->dev_private;
+   struct ast_private *ast = to_ast_private(dev);
u32 i, data, len = 0;
u32 boot_address;
u8 *fw_addr = NULL;
@@ -255,7 +255,7 @@ static bool ast_launch_m68k(struct drm_device *dev)
 
 u8 ast_get_dp501_max_clk(struct drm_device *dev)
 {
-   struct ast_private *ast = dev->dev_private;
+   struct ast_private *ast = to_ast_private(dev);
u32 boot_address, offset, data;
u8 linkcap[4], linkrate, linklanes, maxclk = 0xff;
 
@@ -283,7 +283,7 @@ u8 ast_get_dp501_max_clk(struct drm_device *dev)
 
 bool ast_dp501_read_edid(struct drm_device *dev, u8 *ediddata)
 {
-   struct ast_private *ast = dev->dev_private;
+   struct ast_private *ast = to_ast_private(dev);
u32 i, boot_address, offset, data;
 
boot_address = get_fw_base(ast);
@@ -312,7 +312,7 @@ bool ast_dp501_read_edid(struct drm_device *dev, u8 
*ediddata)
 
 static bool ast_init_dvo(struct drm_device *dev)
 {
-   struct ast_private *ast = dev->dev_private;
+   struct ast_private *ast = to_ast_private(dev);
u8 jreg;
u32 data;
ast_write32(ast, 0xf004, 0x1e6e);
@@ -385,7 +385,7 @@ static bool ast_init_dvo(struct drm_device *dev)
 
 static void ast_init_analog(struct drm_device *dev)
 {
-   struct ast_private *ast = dev->dev_private;
+   struct ast_private *ast = to_ast_private(dev);
u32 data;
 
/*
@@ -412,7 +412,7 @@ static void ast_init_analog(struct drm_device *dev)
 
 void ast_init_3rdtx(struct drm_device *dev)
 {
-   struct ast_private *ast = dev->dev_private;
+   struct ast_private *ast = to_ast_private(dev);
u8 jreg;
 
if (ast->chip == AST2300 || ast->chip == AST2400) {
@@ -438,7 +438,7 @@ void ast_init_3rdtx(struct drm_device *dev)
 
 void ast_release_firmware(struct drm_device *dev)
 {
-   struct ast_private *ast = dev->dev_private;
+   struct ast_private *ast = to_ast_private(dev);
 
release_firmware(ast->dp501_fw);
ast->dp501_fw = NULL;
diff --git a/drivers/gpu/drm/ast/ast_drv.h b/drivers/gpu/drm/ast/ast_drv.h
index 09f2659e29118..c44c1376c6977 100644
--- a/drivers/gpu/drm/ast/ast_drv.h
+++ b/drivers/gpu/drm/ast/ast_drv.h
@@ -136,6 +136,11 @@ struct ast_private {
const struct firmware *dp501_fw;/* dp501 fw */
 };
 
+static inline struct ast_private *to_ast_private(struct drm_device *dev)
+{
+   return dev->dev_private;
+}
+
 int ast_driver_load(struct drm_device *dev, unsigned long