2019-06-03 07:44:50 +02:00
// SPDX-License-Identifier: GPL-2.0-only
2015-01-06 11:13:28 +01:00
/*
* Copyright ( C ) 2014 Traphandler
* Copyright ( C ) 2014 Free Electrons
*
* Author : Jean - Jacques Hiblot < jjhiblot @ traphandler . com >
* Author : Boris BREZILLON < boris . brezillon @ free - electrons . com >
*/
# include <linux/clk.h>
2022-06-30 22:51:13 +03:00
# include <linux/media-bus-format.h>
2019-06-30 08:19:03 +02:00
# include <linux/mfd/atmel-hlcdc.h>
# include <linux/pinctrl/consumer.h>
2015-01-06 11:13:28 +01:00
# include <linux/pm.h>
# include <linux/pm_runtime.h>
2019-06-30 08:19:03 +02:00
# include <video/videomode.h>
# include <drm/drm_atomic.h>
# include <drm/drm_atomic_helper.h>
2015-01-06 11:13:28 +01:00
# include <drm/drm_crtc.h>
2019-06-30 08:19:03 +02:00
# include <drm/drm_modeset_helper_vtables.h>
2019-01-17 22:03:34 +01:00
# include <drm/drm_probe_helper.h>
2019-06-30 08:19:03 +02:00
# include <drm/drm_vblank.h>
2015-01-06 11:13:28 +01:00
# include "atmel_hlcdc_dc.h"
2016-01-06 11:14:15 +01:00
/**
2020-11-12 19:00:22 +00:00
* struct atmel_hlcdc_crtc_state - Atmel HLCDC CRTC state structure
2016-01-06 11:14:15 +01:00
*
* @ base : base CRTC state
* @ output_mode : RGBXXX output mode
*/
struct atmel_hlcdc_crtc_state {
struct drm_crtc_state base ;
unsigned int output_mode ;
} ;
static inline struct atmel_hlcdc_crtc_state *
drm_crtc_state_to_atmel_hlcdc_crtc_state ( struct drm_crtc_state * state )
{
return container_of ( state , struct atmel_hlcdc_crtc_state , base ) ;
}
2015-01-06 11:13:28 +01:00
/**
2020-11-12 19:00:22 +00:00
* struct atmel_hlcdc_crtc - Atmel HLCDC CRTC structure
2015-01-06 11:13:28 +01:00
*
* @ base : base DRM CRTC structure
2020-11-12 19:00:22 +00:00
* @ dc : pointer to the atmel_hlcdc structure provided by the MFD device
2015-01-06 11:13:28 +01:00
* @ event : pointer to the current page flip event
* @ id : CRTC id ( returned by drm_crtc_index )
*/
struct atmel_hlcdc_crtc {
struct drm_crtc base ;
struct atmel_hlcdc_dc * dc ;
struct drm_pending_vblank_event * event ;
int id ;
} ;
static inline struct atmel_hlcdc_crtc *
drm_crtc_to_atmel_hlcdc_crtc ( struct drm_crtc * crtc )
{
return container_of ( crtc , struct atmel_hlcdc_crtc , base ) ;
}
2015-02-05 16:32:33 +01:00
static void atmel_hlcdc_crtc_mode_set_nofb ( struct drm_crtc * c )
2015-01-06 11:13:28 +01:00
{
struct atmel_hlcdc_crtc * crtc = drm_crtc_to_atmel_hlcdc_crtc ( c ) ;
struct regmap * regmap = crtc - > dc - > hlcdc - > regmap ;
2015-02-05 16:32:33 +01:00
struct drm_display_mode * adj = & c - > state - > adjusted_mode ;
2023-06-09 16:48:43 +02:00
struct drm_encoder * encoder = NULL , * en_iter ;
struct drm_connector * connector = NULL ;
2016-01-06 11:14:15 +01:00
struct atmel_hlcdc_crtc_state * state ;
2023-06-09 16:48:43 +02:00
struct drm_device * ddev = c - > dev ;
struct drm_connector_list_iter iter ;
2015-01-06 11:13:28 +01:00
unsigned long mode_rate ;
struct videomode vm ;
unsigned long prate ;
2019-04-25 12:36:09 +00:00
unsigned int mask = ATMEL_HLCDC_CLKDIV_MASK | ATMEL_HLCDC_CLKPOL ;
unsigned int cfg = 0 ;
2019-12-18 14:28:25 +02:00
int div , ret ;
2023-06-09 16:48:43 +02:00
/* get encoder from crtc */
drm_for_each_encoder ( en_iter , ddev ) {
if ( en_iter - > crtc = = c ) {
encoder = en_iter ;
break ;
}
}
if ( encoder ) {
/* Get the connector from encoder */
drm_connector_list_iter_begin ( ddev , & iter ) ;
drm_for_each_connector_iter ( connector , & iter )
if ( connector - > encoder = = encoder )
break ;
drm_connector_list_iter_end ( & iter ) ;
}
2019-12-18 14:28:25 +02:00
ret = clk_prepare_enable ( crtc - > dc - > hlcdc - > sys_clk ) ;
if ( ret )
return ;
2015-01-06 11:13:28 +01:00
vm . vfront_porch = adj - > crtc_vsync_start - adj - > crtc_vdisplay ;
vm . vback_porch = adj - > crtc_vtotal - adj - > crtc_vsync_end ;
vm . vsync_len = adj - > crtc_vsync_end - adj - > crtc_vsync_start ;
vm . hfront_porch = adj - > crtc_hsync_start - adj - > crtc_hdisplay ;
vm . hback_porch = adj - > crtc_htotal - adj - > crtc_hsync_end ;
vm . hsync_len = adj - > crtc_hsync_end - adj - > crtc_hsync_start ;
regmap_write ( regmap , ATMEL_HLCDC_CFG ( 1 ) ,
( vm . hsync_len - 1 ) | ( ( vm . vsync_len - 1 ) < < 16 ) ) ;
regmap_write ( regmap , ATMEL_HLCDC_CFG ( 2 ) ,
( vm . vfront_porch - 1 ) | ( vm . vback_porch < < 16 ) ) ;
regmap_write ( regmap , ATMEL_HLCDC_CFG ( 3 ) ,
( vm . hfront_porch - 1 ) | ( ( vm . hback_porch - 1 ) < < 16 ) ) ;
regmap_write ( regmap , ATMEL_HLCDC_CFG ( 4 ) ,
( adj - > crtc_hdisplay - 1 ) |
( ( adj - > crtc_vdisplay - 1 ) < < 16 ) ) ;
2019-12-18 14:28:24 +02:00
prate = clk_get_rate ( crtc - > dc - > hlcdc - > sys_clk ) ;
mode_rate = adj - > crtc_clock * 1000 ;
2019-04-25 12:36:09 +00:00
if ( ! crtc - > dc - > desc - > fixed_clksrc ) {
2019-12-18 14:28:24 +02:00
prate * = 2 ;
2019-04-25 12:36:09 +00:00
cfg | = ATMEL_HLCDC_CLKSEL ;
mask | = ATMEL_HLCDC_CLKSEL ;
}
2015-01-06 11:13:28 +01:00
div = DIV_ROUND_UP ( prate , mode_rate ) ;
2018-08-24 11:24:57 +02:00
if ( div < 2 ) {
2015-01-06 11:13:28 +01:00
div = 2 ;
2018-08-24 11:24:57 +02:00
} else if ( ATMEL_HLCDC_CLKDIV ( div ) & ~ ATMEL_HLCDC_CLKDIV_MASK ) {
/* The divider ended up too big, try a lower base rate. */
cfg & = ~ ATMEL_HLCDC_CLKSEL ;
prate / = 2 ;
div = DIV_ROUND_UP ( prate , mode_rate ) ;
if ( ATMEL_HLCDC_CLKDIV ( div ) & ~ ATMEL_HLCDC_CLKDIV_MASK )
div = ATMEL_HLCDC_CLKDIV_MASK ;
2018-08-24 11:24:58 +02:00
} else {
int div_low = prate / mode_rate ;
if ( div_low > = 2 & &
2019-12-18 14:28:28 +02:00
( 10 * ( prate / div_low - mode_rate ) <
( mode_rate - prate / div ) ) )
2018-08-24 11:24:58 +02:00
/*
* At least 10 times better when using a higher
* frequency than requested , instead of a lower .
* So , go with that .
*/
div = div_low ;
2018-08-24 11:24:57 +02:00
}
2015-01-06 11:13:28 +01:00
cfg | = ATMEL_HLCDC_CLKDIV ( div ) ;
2023-06-09 16:48:43 +02:00
if ( connector & &
connector - > display_info . bus_flags & DRM_BUS_FLAG_PIXDATA_DRIVE_NEGEDGE )
cfg | = ATMEL_HLCDC_CLKPOL ;
2019-04-25 12:36:09 +00:00
regmap_update_bits ( regmap , ATMEL_HLCDC_CFG ( 0 ) , mask , cfg ) ;
2015-01-06 11:13:28 +01:00
2019-04-25 12:36:16 +00:00
state = drm_crtc_state_to_atmel_hlcdc_crtc_state ( c - > state ) ;
cfg = state - > output_mode < < 8 ;
2015-01-06 11:13:28 +01:00
2015-02-05 16:32:33 +01:00
if ( adj - > flags & DRM_MODE_FLAG_NVSYNC )
2015-01-06 11:13:28 +01:00
cfg | = ATMEL_HLCDC_VSPOL ;
2015-02-05 16:32:33 +01:00
if ( adj - > flags & DRM_MODE_FLAG_NHSYNC )
2015-01-06 11:13:28 +01:00
cfg | = ATMEL_HLCDC_HSPOL ;
regmap_update_bits ( regmap , ATMEL_HLCDC_CFG ( 5 ) ,
ATMEL_HLCDC_HSPOL | ATMEL_HLCDC_VSPOL |
ATMEL_HLCDC_VSPDLYS | ATMEL_HLCDC_VSPDLYE |
ATMEL_HLCDC_DISPPOL | ATMEL_HLCDC_DISPDLY |
ATMEL_HLCDC_VSPSU | ATMEL_HLCDC_VSPHO |
2016-01-06 11:14:15 +01:00
ATMEL_HLCDC_GUARDTIME_MASK | ATMEL_HLCDC_MODE_MASK ,
2015-01-06 11:13:28 +01:00
cfg ) ;
2019-12-18 14:28:25 +02:00
clk_disable_unprepare ( crtc - > dc - > hlcdc - > sys_clk ) ;
2015-01-06 11:13:28 +01:00
}
2017-05-25 15:19:21 +01:00
static enum drm_mode_status
atmel_hlcdc_crtc_mode_valid ( struct drm_crtc * c ,
const struct drm_display_mode * mode )
2016-01-05 18:27:49 +01:00
{
struct atmel_hlcdc_crtc * crtc = drm_crtc_to_atmel_hlcdc_crtc ( c ) ;
2017-05-25 15:19:21 +01:00
return atmel_hlcdc_dc_mode_valid ( crtc - > dc , mode ) ;
2016-01-05 18:27:49 +01:00
}
2017-06-30 12:36:45 +03:00
static void atmel_hlcdc_crtc_atomic_disable ( struct drm_crtc * c ,
drm/atomic: Pass the full state to CRTC atomic enable/disable
If the CRTC driver ever needs to access the full DRM state, it can't do so
at atomic_enable / atomic_disable time since drm_atomic_helper_swap_state
will have cleared the pointer from the struct drm_crtc_state to the struct
drm_atomic_state before calling those hooks.
In order to allow that, let's pass the full DRM state to atomic_enable and
atomic_disable. The conversion was done using the coccinelle script below,
built tested on all the drivers and actually tested on vc4.
virtual report
@@
struct drm_crtc_helper_funcs *FUNCS;
identifier dev, state;
identifier crtc, crtc_state;
@@
disable_outputs(struct drm_device *dev, struct drm_atomic_state *state)
{
<...
- FUNCS->atomic_disable(crtc, crtc_state);
+ FUNCS->atomic_disable(crtc, state);
...>
}
@@
struct drm_crtc_helper_funcs *FUNCS;
identifier dev, state;
identifier crtc, crtc_state;
@@
drm_atomic_helper_commit_modeset_enables(struct drm_device *dev, struct drm_atomic_state *state)
{
<...
- FUNCS->atomic_enable(crtc, crtc_state);
+ FUNCS->atomic_enable(crtc, state);
...>
}
@@
identifier crtc, old_state;
@@
struct drm_crtc_helper_funcs {
...
- void (*atomic_enable)(struct drm_crtc *crtc, struct drm_crtc_state *old_state);
+ void (*atomic_enable)(struct drm_crtc *crtc, struct drm_atomic_state *state);
...
- void (*atomic_disable)(struct drm_crtc *crtc, struct drm_crtc_state *old_state);
+ void (*atomic_disable)(struct drm_crtc *crtc, struct drm_atomic_state *state);
...
}
@ crtc_atomic_func @
identifier helpers;
identifier func;
@@
(
static struct drm_crtc_helper_funcs helpers = {
...,
.atomic_enable = func,
...,
};
|
static struct drm_crtc_helper_funcs helpers = {
...,
.atomic_disable = func,
...,
};
)
@ ignores_old_state @
identifier crtc_atomic_func.func;
identifier crtc, old_state;
@@
void func(struct drm_crtc *crtc,
struct drm_crtc_state *old_state)
{
... when != old_state
}
@ adds_old_state depends on crtc_atomic_func && !ignores_old_state @
identifier crtc_atomic_func.func;
identifier crtc, old_state;
@@
void func(struct drm_crtc *crtc, struct drm_crtc_state *old_state)
{
+ struct drm_crtc_state *old_state = drm_atomic_get_old_crtc_state(state, crtc);
...
}
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
expression E;
type T;
@@
void func(...)
{
...
- T state = E;
+ T crtc_state = E;
<+...
- state
+ crtc_state
...+>
}
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
type T;
@@
void func(...)
{
...
- T state;
+ T crtc_state;
<+...
- state
+ crtc_state
...+>
}
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
identifier old_state;
identifier crtc;
@@
void func(struct drm_crtc *crtc,
- struct drm_crtc_state *old_state
+ struct drm_atomic_state *state
)
{ ... }
@ include depends on adds_old_state @
@@
#include <drm/drm_atomic.h>
@ no_include depends on !include && adds_old_state @
@@
+ #include <drm/drm_atomic.h>
#include <drm/...>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/845aa10ef171fc0ea060495efef142a0c13f7870.1602161031.git-series.maxime@cerno.tech
2020-10-08 14:44:08 +02:00
struct drm_atomic_state * state )
2015-01-06 11:13:28 +01:00
{
2015-02-05 16:32:33 +01:00
struct drm_device * dev = c - > dev ;
struct atmel_hlcdc_crtc * crtc = drm_crtc_to_atmel_hlcdc_crtc ( c ) ;
struct regmap * regmap = crtc - > dc - > hlcdc - > regmap ;
unsigned int status ;
drm_crtc_vblank_off ( c ) ;
pm_runtime_get_sync ( dev - > dev ) ;
regmap_write ( regmap , ATMEL_HLCDC_DIS , ATMEL_HLCDC_DISP ) ;
while ( ! regmap_read ( regmap , ATMEL_HLCDC_SR , & status ) & &
( status & ATMEL_HLCDC_DISP ) )
cpu_relax ( ) ;
regmap_write ( regmap , ATMEL_HLCDC_DIS , ATMEL_HLCDC_SYNC ) ;
while ( ! regmap_read ( regmap , ATMEL_HLCDC_SR , & status ) & &
( status & ATMEL_HLCDC_SYNC ) )
cpu_relax ( ) ;
regmap_write ( regmap , ATMEL_HLCDC_DIS , ATMEL_HLCDC_PIXEL_CLK ) ;
while ( ! regmap_read ( regmap , ATMEL_HLCDC_SR , & status ) & &
( status & ATMEL_HLCDC_PIXEL_CLK ) )
cpu_relax ( ) ;
clk_disable_unprepare ( crtc - > dc - > hlcdc - > sys_clk ) ;
2015-02-22 18:51:04 +01:00
pinctrl_pm_select_sleep_state ( dev - > dev ) ;
2015-02-05 16:32:33 +01:00
pm_runtime_allow ( dev - > dev ) ;
pm_runtime_put_sync ( dev - > dev ) ;
2015-01-06 11:13:28 +01:00
}
2017-06-30 12:36:44 +03:00
static void atmel_hlcdc_crtc_atomic_enable ( struct drm_crtc * c ,
drm/atomic: Pass the full state to CRTC atomic enable/disable
If the CRTC driver ever needs to access the full DRM state, it can't do so
at atomic_enable / atomic_disable time since drm_atomic_helper_swap_state
will have cleared the pointer from the struct drm_crtc_state to the struct
drm_atomic_state before calling those hooks.
In order to allow that, let's pass the full DRM state to atomic_enable and
atomic_disable. The conversion was done using the coccinelle script below,
built tested on all the drivers and actually tested on vc4.
virtual report
@@
struct drm_crtc_helper_funcs *FUNCS;
identifier dev, state;
identifier crtc, crtc_state;
@@
disable_outputs(struct drm_device *dev, struct drm_atomic_state *state)
{
<...
- FUNCS->atomic_disable(crtc, crtc_state);
+ FUNCS->atomic_disable(crtc, state);
...>
}
@@
struct drm_crtc_helper_funcs *FUNCS;
identifier dev, state;
identifier crtc, crtc_state;
@@
drm_atomic_helper_commit_modeset_enables(struct drm_device *dev, struct drm_atomic_state *state)
{
<...
- FUNCS->atomic_enable(crtc, crtc_state);
+ FUNCS->atomic_enable(crtc, state);
...>
}
@@
identifier crtc, old_state;
@@
struct drm_crtc_helper_funcs {
...
- void (*atomic_enable)(struct drm_crtc *crtc, struct drm_crtc_state *old_state);
+ void (*atomic_enable)(struct drm_crtc *crtc, struct drm_atomic_state *state);
...
- void (*atomic_disable)(struct drm_crtc *crtc, struct drm_crtc_state *old_state);
+ void (*atomic_disable)(struct drm_crtc *crtc, struct drm_atomic_state *state);
...
}
@ crtc_atomic_func @
identifier helpers;
identifier func;
@@
(
static struct drm_crtc_helper_funcs helpers = {
...,
.atomic_enable = func,
...,
};
|
static struct drm_crtc_helper_funcs helpers = {
...,
.atomic_disable = func,
...,
};
)
@ ignores_old_state @
identifier crtc_atomic_func.func;
identifier crtc, old_state;
@@
void func(struct drm_crtc *crtc,
struct drm_crtc_state *old_state)
{
... when != old_state
}
@ adds_old_state depends on crtc_atomic_func && !ignores_old_state @
identifier crtc_atomic_func.func;
identifier crtc, old_state;
@@
void func(struct drm_crtc *crtc, struct drm_crtc_state *old_state)
{
+ struct drm_crtc_state *old_state = drm_atomic_get_old_crtc_state(state, crtc);
...
}
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
expression E;
type T;
@@
void func(...)
{
...
- T state = E;
+ T crtc_state = E;
<+...
- state
+ crtc_state
...+>
}
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
type T;
@@
void func(...)
{
...
- T state;
+ T crtc_state;
<+...
- state
+ crtc_state
...+>
}
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
identifier old_state;
identifier crtc;
@@
void func(struct drm_crtc *crtc,
- struct drm_crtc_state *old_state
+ struct drm_atomic_state *state
)
{ ... }
@ include depends on adds_old_state @
@@
#include <drm/drm_atomic.h>
@ no_include depends on !include && adds_old_state @
@@
+ #include <drm/drm_atomic.h>
#include <drm/...>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/845aa10ef171fc0ea060495efef142a0c13f7870.1602161031.git-series.maxime@cerno.tech
2020-10-08 14:44:08 +02:00
struct drm_atomic_state * state )
2015-01-06 11:13:28 +01:00
{
2015-02-05 16:32:33 +01:00
struct drm_device * dev = c - > dev ;
struct atmel_hlcdc_crtc * crtc = drm_crtc_to_atmel_hlcdc_crtc ( c ) ;
struct regmap * regmap = crtc - > dc - > hlcdc - > regmap ;
unsigned int status ;
pm_runtime_get_sync ( dev - > dev ) ;
pm_runtime_forbid ( dev - > dev ) ;
2015-02-22 18:51:04 +01:00
pinctrl_pm_select_default_state ( dev - > dev ) ;
2015-02-05 16:32:33 +01:00
clk_prepare_enable ( crtc - > dc - > hlcdc - > sys_clk ) ;
regmap_write ( regmap , ATMEL_HLCDC_EN , ATMEL_HLCDC_PIXEL_CLK ) ;
while ( ! regmap_read ( regmap , ATMEL_HLCDC_SR , & status ) & &
! ( status & ATMEL_HLCDC_PIXEL_CLK ) )
cpu_relax ( ) ;
regmap_write ( regmap , ATMEL_HLCDC_EN , ATMEL_HLCDC_SYNC ) ;
while ( ! regmap_read ( regmap , ATMEL_HLCDC_SR , & status ) & &
! ( status & ATMEL_HLCDC_SYNC ) )
cpu_relax ( ) ;
regmap_write ( regmap , ATMEL_HLCDC_EN , ATMEL_HLCDC_DISP ) ;
while ( ! regmap_read ( regmap , ATMEL_HLCDC_SR , & status ) & &
! ( status & ATMEL_HLCDC_DISP ) )
cpu_relax ( ) ;
pm_runtime_put_sync ( dev - > dev ) ;
2015-03-12 19:47:19 +01:00
}
2016-01-06 11:14:15 +01:00
# define ATMEL_HLCDC_RGB444_OUTPUT BIT(0)
# define ATMEL_HLCDC_RGB565_OUTPUT BIT(1)
# define ATMEL_HLCDC_RGB666_OUTPUT BIT(2)
# define ATMEL_HLCDC_RGB888_OUTPUT BIT(3)
# define ATMEL_HLCDC_OUTPUT_MODE_MASK GENMASK(3, 0)
2018-08-25 10:56:20 +02:00
static int atmel_hlcdc_connector_output_mode ( struct drm_connector_state * state )
{
struct drm_connector * connector = state - > connector ;
struct drm_display_info * info = & connector - > display_info ;
struct drm_encoder * encoder ;
unsigned int supported_fmts = 0 ;
int j ;
encoder = state - > best_encoder ;
if ( ! encoder )
encoder = connector - > encoder ;
switch ( atmel_hlcdc_encoder_get_bus_fmt ( encoder ) ) {
case 0 :
break ;
case MEDIA_BUS_FMT_RGB444_1X12 :
return ATMEL_HLCDC_RGB444_OUTPUT ;
case MEDIA_BUS_FMT_RGB565_1X16 :
return ATMEL_HLCDC_RGB565_OUTPUT ;
case MEDIA_BUS_FMT_RGB666_1X18 :
return ATMEL_HLCDC_RGB666_OUTPUT ;
case MEDIA_BUS_FMT_RGB888_1X24 :
return ATMEL_HLCDC_RGB888_OUTPUT ;
default :
return - EINVAL ;
}
for ( j = 0 ; j < info - > num_bus_formats ; j + + ) {
switch ( info - > bus_formats [ j ] ) {
case MEDIA_BUS_FMT_RGB444_1X12 :
supported_fmts | = ATMEL_HLCDC_RGB444_OUTPUT ;
break ;
case MEDIA_BUS_FMT_RGB565_1X16 :
supported_fmts | = ATMEL_HLCDC_RGB565_OUTPUT ;
break ;
case MEDIA_BUS_FMT_RGB666_1X18 :
supported_fmts | = ATMEL_HLCDC_RGB666_OUTPUT ;
break ;
case MEDIA_BUS_FMT_RGB888_1X24 :
supported_fmts | = ATMEL_HLCDC_RGB888_OUTPUT ;
break ;
default :
break ;
}
}
return supported_fmts ;
}
2016-01-06 11:14:15 +01:00
static int atmel_hlcdc_crtc_select_output_mode ( struct drm_crtc_state * state )
{
unsigned int output_fmts = ATMEL_HLCDC_OUTPUT_MODE_MASK ;
struct atmel_hlcdc_crtc_state * hstate ;
struct drm_connector_state * cstate ;
struct drm_connector * connector ;
struct atmel_hlcdc_crtc * crtc ;
int i ;
crtc = drm_crtc_to_atmel_hlcdc_crtc ( state - > crtc ) ;
2017-07-12 10:13:36 +02:00
for_each_new_connector_in_state ( state - > state , connector , cstate , i ) {
2016-01-06 11:14:15 +01:00
unsigned int supported_fmts = 0 ;
if ( ! cstate - > crtc )
continue ;
2018-08-25 10:56:20 +02:00
supported_fmts = atmel_hlcdc_connector_output_mode ( cstate ) ;
2016-01-06 11:14:15 +01:00
if ( crtc - > dc - > desc - > conflicting_output_formats )
output_fmts & = supported_fmts ;
else
output_fmts | = supported_fmts ;
}
if ( ! output_fmts )
return - EINVAL ;
hstate = drm_crtc_state_to_atmel_hlcdc_crtc_state ( state ) ;
hstate - > output_mode = fls ( output_fmts ) - 1 ;
return 0 ;
}
2015-02-05 16:32:33 +01:00
static int atmel_hlcdc_crtc_atomic_check ( struct drm_crtc * c ,
drm/atomic: Pass the full state to CRTC atomic_check
The current atomic helpers have either their object state being passed as
an argument or the full atomic state.
The former is the pattern that was done at first, before switching to the
latter for new hooks or when it was needed.
Let's start convert all the remaining helpers to provide a consistent
interface, starting with the CRTC's atomic_check.
The conversion was done using the coccinelle script below,
built tested on all the drivers and actually tested on vc4.
virtual report
@@
struct drm_crtc_helper_funcs *FUNCS;
struct drm_crtc *crtc;
struct drm_crtc_state *crtc_state;
identifier dev, state;
identifier ret, f;
@@
f(struct drm_device *dev, struct drm_atomic_state *state)
{
<...
- ret = FUNCS->atomic_check(crtc, crtc_state);
+ ret = FUNCS->atomic_check(crtc, state);
...>
}
@@
identifier crtc, new_state;
@@
struct drm_crtc_helper_funcs {
...
- int (*atomic_check)(struct drm_crtc *crtc, struct drm_crtc_state *new_state);
+ int (*atomic_check)(struct drm_crtc *crtc, struct drm_atomic_state *state);
...
}
@ crtc_atomic_func @
identifier helpers;
identifier func;
@@
static struct drm_crtc_helper_funcs helpers = {
...,
.atomic_check = func,
...,
};
@ ignores_new_state @
identifier crtc_atomic_func.func;
identifier crtc, new_state;
@@
int func(struct drm_crtc *crtc,
struct drm_crtc_state *new_state)
{
... when != new_state
}
@ adds_new_state depends on crtc_atomic_func && !ignores_new_state @
identifier crtc_atomic_func.func;
identifier crtc, new_state;
@@
int func(struct drm_crtc *crtc, struct drm_crtc_state *new_state)
{
+ struct drm_crtc_state *new_state = drm_atomic_get_new_crtc_state(state, crtc);
...
}
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
expression E;
type T;
@@
int func(...)
{
...
- T state = E;
+ T crtc_state = E;
<+...
- state
+ crtc_state
...+>
}
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
type T;
@@
int func(...)
{
...
- T state;
+ T crtc_state;
<+...
- state
+ crtc_state
...+>
}
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
identifier new_state;
identifier crtc;
@@
int func(struct drm_crtc *crtc,
- struct drm_crtc_state *new_state
+ struct drm_atomic_state *state
)
{ ... }
@@
identifier new_state;
identifier crtc;
@@
int vmw_du_crtc_atomic_check(struct drm_crtc *crtc,
- struct drm_crtc_state *new_state
+ struct drm_atomic_state *state
)
{
+ struct drm_crtc_state *new_state = drm_atomic_get_new_crtc_state(state, crtc);
...
}
@@
identifier new_state;
identifier crtc;
@@
int vmw_du_crtc_atomic_check(struct drm_crtc *crtc,
- struct drm_crtc_state *new_state
+ struct drm_atomic_state *state
);
@ include depends on adds_new_state @
@@
#include <drm/drm_atomic.h>
@ no_include depends on !include && adds_new_state @
@@
+ #include <drm/drm_atomic.h>
#include <drm/...>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: https://patchwork.freedesktop.org/patch/msgid/20201028123222.1732139-1-maxime@cerno.tech
2020-10-28 13:32:21 +01:00
struct drm_atomic_state * state )
2015-01-06 11:13:28 +01:00
{
drm/atomic: Pass the full state to CRTC atomic_check
The current atomic helpers have either their object state being passed as
an argument or the full atomic state.
The former is the pattern that was done at first, before switching to the
latter for new hooks or when it was needed.
Let's start convert all the remaining helpers to provide a consistent
interface, starting with the CRTC's atomic_check.
The conversion was done using the coccinelle script below,
built tested on all the drivers and actually tested on vc4.
virtual report
@@
struct drm_crtc_helper_funcs *FUNCS;
struct drm_crtc *crtc;
struct drm_crtc_state *crtc_state;
identifier dev, state;
identifier ret, f;
@@
f(struct drm_device *dev, struct drm_atomic_state *state)
{
<...
- ret = FUNCS->atomic_check(crtc, crtc_state);
+ ret = FUNCS->atomic_check(crtc, state);
...>
}
@@
identifier crtc, new_state;
@@
struct drm_crtc_helper_funcs {
...
- int (*atomic_check)(struct drm_crtc *crtc, struct drm_crtc_state *new_state);
+ int (*atomic_check)(struct drm_crtc *crtc, struct drm_atomic_state *state);
...
}
@ crtc_atomic_func @
identifier helpers;
identifier func;
@@
static struct drm_crtc_helper_funcs helpers = {
...,
.atomic_check = func,
...,
};
@ ignores_new_state @
identifier crtc_atomic_func.func;
identifier crtc, new_state;
@@
int func(struct drm_crtc *crtc,
struct drm_crtc_state *new_state)
{
... when != new_state
}
@ adds_new_state depends on crtc_atomic_func && !ignores_new_state @
identifier crtc_atomic_func.func;
identifier crtc, new_state;
@@
int func(struct drm_crtc *crtc, struct drm_crtc_state *new_state)
{
+ struct drm_crtc_state *new_state = drm_atomic_get_new_crtc_state(state, crtc);
...
}
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
expression E;
type T;
@@
int func(...)
{
...
- T state = E;
+ T crtc_state = E;
<+...
- state
+ crtc_state
...+>
}
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
type T;
@@
int func(...)
{
...
- T state;
+ T crtc_state;
<+...
- state
+ crtc_state
...+>
}
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
identifier new_state;
identifier crtc;
@@
int func(struct drm_crtc *crtc,
- struct drm_crtc_state *new_state
+ struct drm_atomic_state *state
)
{ ... }
@@
identifier new_state;
identifier crtc;
@@
int vmw_du_crtc_atomic_check(struct drm_crtc *crtc,
- struct drm_crtc_state *new_state
+ struct drm_atomic_state *state
)
{
+ struct drm_crtc_state *new_state = drm_atomic_get_new_crtc_state(state, crtc);
...
}
@@
identifier new_state;
identifier crtc;
@@
int vmw_du_crtc_atomic_check(struct drm_crtc *crtc,
- struct drm_crtc_state *new_state
+ struct drm_atomic_state *state
);
@ include depends on adds_new_state @
@@
#include <drm/drm_atomic.h>
@ no_include depends on !include && adds_new_state @
@@
+ #include <drm/drm_atomic.h>
#include <drm/...>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: https://patchwork.freedesktop.org/patch/msgid/20201028123222.1732139-1-maxime@cerno.tech
2020-10-28 13:32:21 +01:00
struct drm_crtc_state * s = drm_atomic_get_new_crtc_state ( state , c ) ;
2016-01-06 11:14:15 +01:00
int ret ;
2015-02-05 16:32:33 +01:00
2016-01-06 11:14:15 +01:00
ret = atmel_hlcdc_crtc_select_output_mode ( s ) ;
if ( ret )
return ret ;
2016-03-15 18:01:08 +01:00
ret = atmel_hlcdc_plane_prepare_disc_area ( s ) ;
if ( ret )
return ret ;
return atmel_hlcdc_plane_prepare_ahb_routing ( s ) ;
2015-01-06 11:13:28 +01:00
}
2015-07-21 13:28:58 +02:00
static void atmel_hlcdc_crtc_atomic_begin ( struct drm_crtc * c ,
drm/atomic: Pass the full state to CRTC atomic begin and flush
The current atomic helpers have either their object state being passed as
an argument or the full atomic state.
The former is the pattern that was done at first, before switching to the
latter for new hooks or when it was needed.
Let's start convert all the remaining helpers to provide a consistent
interface, starting with the CRTC's atomic_begin and atomic_flush.
The conversion was done using the coccinelle script below, built tested on
all the drivers and actually tested on vc4.
virtual report
@@
struct drm_crtc_helper_funcs *FUNCS;
identifier old_crtc_state, old_state;
identifier crtc;
identifier f;
@@
f(struct drm_crtc_state *old_crtc_state)
{
...
struct drm_atomic_state *old_state = old_crtc_state->state;
<...
- FUNCS->atomic_begin(crtc, old_crtc_state);
+ FUNCS->atomic_begin(crtc, old_state);
...>
}
@@
struct drm_crtc_helper_funcs *FUNCS;
identifier old_crtc_state, old_state;
identifier crtc;
identifier f;
@@
f(struct drm_crtc_state *old_crtc_state)
{
...
struct drm_atomic_state *old_state = old_crtc_state->state;
<...
- FUNCS->atomic_flush(crtc, old_crtc_state);
+ FUNCS->atomic_flush(crtc, old_state);
...>
}
@@
struct drm_crtc_helper_funcs *FUNCS;
struct drm_crtc *crtc;
struct drm_crtc_state *crtc_state;
identifier dev, state;
identifier f;
@@
f(struct drm_device *dev, struct drm_atomic_state *state, ...)
{
<...
- FUNCS->atomic_begin(crtc, crtc_state);
+ FUNCS->atomic_begin(crtc, state);
...>
}
@@
struct drm_crtc_helper_funcs *FUNCS;
struct drm_crtc *crtc;
struct drm_crtc_state *crtc_state;
identifier dev, state;
identifier f;
@@
f(struct drm_device *dev, struct drm_atomic_state *state, ...)
{
<...
- FUNCS->atomic_flush(crtc, crtc_state);
+ FUNCS->atomic_flush(crtc, state);
...>
}
@@
identifier crtc, old_state;
@@
struct drm_crtc_helper_funcs {
...
- void (*atomic_begin)(struct drm_crtc *crtc, struct drm_crtc_state *old_state);
+ void (*atomic_begin)(struct drm_crtc *crtc, struct drm_atomic_state *state);
...
- void (*atomic_flush)(struct drm_crtc *crtc, struct drm_crtc_state *old_state);
+ void (*atomic_flush)(struct drm_crtc *crtc, struct drm_atomic_state *state);
...
}
@ crtc_atomic_func @
identifier helpers;
identifier func;
@@
(
static struct drm_crtc_helper_funcs helpers = {
...,
.atomic_begin = func,
...,
};
|
static struct drm_crtc_helper_funcs helpers = {
...,
.atomic_flush = func,
...,
};
)
@ ignores_old_state @
identifier crtc_atomic_func.func;
identifier crtc, old_state;
@@
void func(struct drm_crtc *crtc,
struct drm_crtc_state *old_state)
{
... when != old_state
}
@ adds_old_state depends on crtc_atomic_func && !ignores_old_state @
identifier crtc_atomic_func.func;
identifier crtc, old_state;
@@
void func(struct drm_crtc *crtc, struct drm_crtc_state *old_state)
{
+ struct drm_crtc_state *old_state = drm_atomic_get_old_crtc_state(state, crtc);
...
}
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
expression E;
type T;
@@
void func(...)
{
...
- T state = E;
+ T crtc_state = E;
<+...
- state
+ crtc_state
...+>
}
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
type T;
@@
void func(...)
{
...
- T state;
+ T crtc_state;
<+...
- state
+ crtc_state
...+>
}
@@
identifier old_state;
identifier crtc;
@@
void vc4_hvs_atomic_flush(struct drm_crtc *crtc,
- struct drm_crtc_state *old_state
+ struct drm_atomic_state *state
)
{
+ struct drm_crtc_state *old_state = drm_atomic_get_old_crtc_state(state, crtc);
...
}
@@
identifier old_state;
identifier crtc;
@@
void vc4_hvs_atomic_flush(struct drm_crtc *crtc,
- struct drm_crtc_state *old_state
+ struct drm_atomic_state *state
);
@@
identifier old_state;
identifier crtc;
@@
void vmw_du_crtc_atomic_begin(struct drm_crtc *crtc,
- struct drm_crtc_state *old_state
+ struct drm_atomic_state *state
)
{
...
}
@@
identifier old_state;
identifier crtc;
@@
void vmw_du_crtc_atomic_begin(struct drm_crtc *crtc,
- struct drm_crtc_state *old_state
+ struct drm_atomic_state *state
);
@@
identifier old_state;
identifier crtc;
@@
void vmw_du_crtc_atomic_flush(struct drm_crtc *crtc,
- struct drm_crtc_state *old_state
+ struct drm_atomic_state *state
)
{
...
}
@@
identifier old_state;
identifier crtc;
@@
void vmw_du_crtc_atomic_flush(struct drm_crtc *crtc,
- struct drm_crtc_state *old_state
+ struct drm_atomic_state *state
);
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
identifier old_state;
identifier crtc;
@@
void func(struct drm_crtc *crtc,
- struct drm_crtc_state *old_state
+ struct drm_atomic_state *state
)
{ ... }
@ include depends on adds_old_state @
@@
#include <drm/drm_atomic.h>
@ no_include depends on !include && adds_old_state @
@@
+ #include <drm/drm_atomic.h>
#include <drm/...>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: https://patchwork.freedesktop.org/patch/msgid/20201028123222.1732139-2-maxime@cerno.tech
2020-10-28 13:32:22 +01:00
struct drm_atomic_state * state )
2021-06-02 09:08:45 -07:00
{
drm_crtc_vblank_on ( c ) ;
}
static void atmel_hlcdc_crtc_atomic_flush ( struct drm_crtc * c ,
struct drm_atomic_state * state )
2015-01-06 11:13:28 +01:00
{
2015-02-05 16:32:33 +01:00
struct atmel_hlcdc_crtc * crtc = drm_crtc_to_atmel_hlcdc_crtc ( c ) ;
2021-06-02 09:08:45 -07:00
unsigned long flags ;
spin_lock_irqsave ( & c - > dev - > event_lock , flags ) ;
2015-01-06 11:13:28 +01:00
2015-02-05 16:32:33 +01:00
if ( c - > state - > event ) {
c - > state - > event - > pipe = drm_crtc_index ( c ) ;
2015-01-06 11:13:28 +01:00
2015-02-05 16:32:33 +01:00
WARN_ON ( drm_crtc_vblank_get ( c ) ! = 0 ) ;
2015-01-06 11:13:28 +01:00
2015-02-05 16:32:33 +01:00
crtc - > event = c - > state - > event ;
c - > state - > event = NULL ;
2015-01-06 11:13:28 +01:00
}
2021-06-02 09:08:45 -07:00
spin_unlock_irqrestore ( & c - > dev - > event_lock , flags ) ;
2015-02-05 16:32:33 +01:00
}
2015-01-06 11:13:28 +01:00
static const struct drm_crtc_helper_funcs lcdc_crtc_helper_funcs = {
2017-05-25 15:19:21 +01:00
. mode_valid = atmel_hlcdc_crtc_mode_valid ,
2015-02-05 16:32:33 +01:00
. mode_set_nofb = atmel_hlcdc_crtc_mode_set_nofb ,
. atomic_check = atmel_hlcdc_crtc_atomic_check ,
. atomic_begin = atmel_hlcdc_crtc_atomic_begin ,
. atomic_flush = atmel_hlcdc_crtc_atomic_flush ,
2017-06-30 12:36:44 +03:00
. atomic_enable = atmel_hlcdc_crtc_atomic_enable ,
2017-06-30 12:36:45 +03:00
. atomic_disable = atmel_hlcdc_crtc_atomic_disable ,
2015-01-06 11:13:28 +01:00
} ;
static void atmel_hlcdc_crtc_destroy ( struct drm_crtc * c )
{
struct atmel_hlcdc_crtc * crtc = drm_crtc_to_atmel_hlcdc_crtc ( c ) ;
drm_crtc_cleanup ( c ) ;
kfree ( crtc ) ;
}
static void atmel_hlcdc_crtc_finish_page_flip ( struct atmel_hlcdc_crtc * crtc )
{
struct drm_device * dev = crtc - > base . dev ;
unsigned long flags ;
spin_lock_irqsave ( & dev - > event_lock , flags ) ;
if ( crtc - > event ) {
2016-06-06 11:41:34 -03:00
drm_crtc_send_vblank_event ( & crtc - > base , crtc - > event ) ;
2016-06-06 11:41:41 -03:00
drm_crtc_vblank_put ( & crtc - > base ) ;
2015-01-06 11:13:28 +01:00
crtc - > event = NULL ;
}
spin_unlock_irqrestore ( & dev - > event_lock , flags ) ;
}
void atmel_hlcdc_crtc_irq ( struct drm_crtc * c )
{
2016-07-04 21:04:49 -03:00
drm_crtc_handle_vblank ( c ) ;
2015-01-06 11:13:28 +01:00
atmel_hlcdc_crtc_finish_page_flip ( drm_crtc_to_atmel_hlcdc_crtc ( c ) ) ;
}
2016-07-11 12:19:40 +02:00
static void atmel_hlcdc_crtc_reset ( struct drm_crtc * crtc )
2016-01-06 11:14:15 +01:00
{
struct atmel_hlcdc_crtc_state * state ;
if ( crtc - > state ) {
2016-04-22 21:28:32 +02:00
__drm_atomic_helper_crtc_destroy_state ( crtc - > state ) ;
2016-01-06 11:14:15 +01:00
state = drm_crtc_state_to_atmel_hlcdc_crtc_state ( crtc - > state ) ;
kfree ( state ) ;
2016-04-22 21:28:32 +02:00
crtc - > state = NULL ;
2016-01-06 11:14:15 +01:00
}
state = kzalloc ( sizeof ( * state ) , GFP_KERNEL ) ;
drm/atomic-helper: reset vblank on crtc reset
Only when vblanks are supported ofc.
Some drivers do this already, but most unfortunately missed it. This
opens up bugs after driver load, before the crtc is enabled for the
first time. syzbot spotted this when loading vkms as a secondary
output. Given how many drivers are buggy it's best to solve this once
and for all in shared helper code.
Aside from moving the few existing calls to drm_crtc_vblank_reset into
helpers (i915 doesn't use helpers, so keeps its own) I think the
regression risk is minimal: atomic helpers already rely on drivers
calling drm_crtc_vblank_on/off correctly in their hooks when they
support vblanks. And driver that's failing to handle vblanks after
this is missing those calls already, and vblanks could only work by
accident when enabling a CRTC for the first time right after boot.
Big thanks to Tetsuo for helping track down what's going wrong here.
There's only a few drivers which already had the necessary call and
needed some updating:
- komeda, atmel and tidss also needed to be changed to call
__drm_atomic_helper_crtc_reset() intead of open coding it
- tegra and msm even had it in the same place already, just code
motion, and malidp already uses __drm_atomic_helper_crtc_reset().
- Laurent noticed that rcar-du and omap open-code their crtc reset and
hence would actually be broken by this patch now. So fix them up by
reusing the helpers, which brings the drm_crtc_vblank_reset() back.
Only call left is in i915, which doesn't use drm_mode_config_reset,
but has its own fastboot infrastructure. So that's the only case where
we actually want this in the driver still.
I've also reviewed all other drivers which set up vblank support with
drm_vblank_init. After the previous patch fixing mxsfb all atomic
drivers do call drm_crtc_vblank_on/off as they should, the remaining
drivers are either legacy kms or legacy dri1 drivers, so not affected
by this change to atomic helpers.
v2: Use the drm_dev_has_vblank() helper.
v3: Laurent pointed out that omap and rcar-du used drm_crtc_vblank_off
instead of drm_crtc_vblank_reset. Adjust them too.
v4: Laurent noticed that rcar-du and omap open-code their crtc reset
and hence would actually be broken by this patch now. So fix them up
by reusing the helpers, which brings the drm_crtc_vblank_reset() back.
v5: also mention rcar-du and ompadrm in the proper commit message
above (Laurent).
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Maxime Ripard <mripard@kernel.org>
Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Acked-by: Liviu Dudau <liviu.dudau@arm.com>
Acked-by: Thierry Reding <treding@nvidia.com>
Link: https://syzkaller.appspot.com/bug?id=0ba17d70d062b2595e1f061231474800f076c7cb
Reported-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Reported-by: syzbot+0871b14ca2e2fb64f6e3@syzkaller.appspotmail.com
Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: "James (Qian) Wang" <james.qian.wang@arm.com>
Cc: Liviu Dudau <liviu.dudau@arm.com>
Cc: Mihail Atanassov <mihail.atanassov@arm.com>
Cc: Brian Starkey <brian.starkey@arm.com>
Cc: Sam Ravnborg <sam@ravnborg.org>
Cc: Boris Brezillon <bbrezillon@kernel.org>
Cc: Nicolas Ferre <nicolas.ferre@microchip.com>
Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
Cc: Ludovic Desroches <ludovic.desroches@microchip.com>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: David Airlie <airlied@linux.ie>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: Thierry Reding <thierry.reding@gmail.com>
Cc: Jonathan Hunter <jonathanh@nvidia.com>
Cc: Jyri Sarha <jsarha@ti.com>
Cc: Tomi Valkeinen <tomi.valkeinen@ti.com>
Cc: Rob Clark <robdclark@gmail.com>
Cc: Sean Paul <seanpaul@chromium.org>
Cc: Brian Masney <masneyb@onstation.org>
Cc: Emil Velikov <emil.velikov@collabora.com>
Cc: zhengbin <zhengbin13@huawei.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-tegra@vger.kernel.org
Cc: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-renesas-soc@vger.kernel.org
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20200612160056.2082681-1-daniel.vetter@ffwll.ch
2020-06-12 18:00:49 +02:00
if ( state )
__drm_atomic_helper_crtc_reset ( crtc , & state - > base ) ;
2016-01-06 11:14:15 +01:00
}
static struct drm_crtc_state *
atmel_hlcdc_crtc_duplicate_state ( struct drm_crtc * crtc )
{
struct atmel_hlcdc_crtc_state * state , * cur ;
if ( WARN_ON ( ! crtc - > state ) )
return NULL ;
state = kmalloc ( sizeof ( * state ) , GFP_KERNEL ) ;
2016-04-25 12:04:54 +03:00
if ( ! state )
return NULL ;
__drm_atomic_helper_crtc_duplicate_state ( crtc , & state - > base ) ;
2016-01-06 11:14:15 +01:00
cur = drm_crtc_state_to_atmel_hlcdc_crtc_state ( crtc - > state ) ;
state - > output_mode = cur - > output_mode ;
return & state - > base ;
}
static void atmel_hlcdc_crtc_destroy_state ( struct drm_crtc * crtc ,
struct drm_crtc_state * s )
{
struct atmel_hlcdc_crtc_state * state ;
state = drm_crtc_state_to_atmel_hlcdc_crtc_state ( s ) ;
2016-05-09 16:34:09 +02:00
__drm_atomic_helper_crtc_destroy_state ( s ) ;
2016-01-06 11:14:15 +01:00
kfree ( state ) ;
}
2017-02-07 17:16:19 +08:00
static int atmel_hlcdc_crtc_enable_vblank ( struct drm_crtc * c )
{
struct atmel_hlcdc_crtc * crtc = drm_crtc_to_atmel_hlcdc_crtc ( c ) ;
struct regmap * regmap = crtc - > dc - > hlcdc - > regmap ;
/* Enable SOF (Start Of Frame) interrupt for vblank counting */
regmap_write ( regmap , ATMEL_HLCDC_IER , ATMEL_HLCDC_SOF ) ;
return 0 ;
}
static void atmel_hlcdc_crtc_disable_vblank ( struct drm_crtc * c )
{
struct atmel_hlcdc_crtc * crtc = drm_crtc_to_atmel_hlcdc_crtc ( c ) ;
struct regmap * regmap = crtc - > dc - > hlcdc - > regmap ;
regmap_write ( regmap , ATMEL_HLCDC_IDR , ATMEL_HLCDC_SOF ) ;
}
2015-01-06 11:13:28 +01:00
static const struct drm_crtc_funcs atmel_hlcdc_crtc_funcs = {
2015-02-05 16:32:33 +01:00
. page_flip = drm_atomic_helper_page_flip ,
. set_config = drm_atomic_helper_set_config ,
2015-01-06 11:13:28 +01:00
. destroy = atmel_hlcdc_crtc_destroy ,
2016-01-06 11:14:15 +01:00
. reset = atmel_hlcdc_crtc_reset ,
. atomic_duplicate_state = atmel_hlcdc_crtc_duplicate_state ,
. atomic_destroy_state = atmel_hlcdc_crtc_destroy_state ,
2017-02-07 17:16:19 +08:00
. enable_vblank = atmel_hlcdc_crtc_enable_vblank ,
. disable_vblank = atmel_hlcdc_crtc_disable_vblank ,
2015-01-06 11:13:28 +01:00
} ;
int atmel_hlcdc_crtc_create ( struct drm_device * dev )
{
2017-02-06 18:57:19 +01:00
struct atmel_hlcdc_plane * primary = NULL , * cursor = NULL ;
2015-01-06 11:13:28 +01:00
struct atmel_hlcdc_dc * dc = dev - > dev_private ;
struct atmel_hlcdc_crtc * crtc ;
int ret ;
int i ;
crtc = kzalloc ( sizeof ( * crtc ) , GFP_KERNEL ) ;
if ( ! crtc )
return - ENOMEM ;
crtc - > dc = dc ;
2017-02-06 18:57:19 +01:00
for ( i = 0 ; i < ATMEL_HLCDC_MAX_LAYERS ; i + + ) {
if ( ! dc - > layers [ i ] )
continue ;
switch ( dc - > layers [ i ] - > desc - > type ) {
case ATMEL_HLCDC_BASE_LAYER :
primary = atmel_hlcdc_layer_to_plane ( dc - > layers [ i ] ) ;
break ;
case ATMEL_HLCDC_CURSOR_LAYER :
cursor = atmel_hlcdc_layer_to_plane ( dc - > layers [ i ] ) ;
break ;
default :
break ;
}
}
ret = drm_crtc_init_with_planes ( dev , & crtc - > base , & primary - > base ,
& cursor - > base , & atmel_hlcdc_crtc_funcs ,
NULL ) ;
2015-01-06 11:13:28 +01:00
if ( ret < 0 )
goto fail ;
crtc - > id = drm_crtc_index ( & crtc - > base ) ;
2017-02-06 18:57:19 +01:00
for ( i = 0 ; i < ATMEL_HLCDC_MAX_LAYERS ; i + + ) {
struct atmel_hlcdc_plane * overlay ;
2015-01-06 11:13:28 +01:00
2017-02-06 18:57:19 +01:00
if ( dc - > layers [ i ] & &
dc - > layers [ i ] - > desc - > type = = ATMEL_HLCDC_OVERLAY_LAYER ) {
overlay = atmel_hlcdc_layer_to_plane ( dc - > layers [ i ] ) ;
overlay - > base . possible_crtcs = 1 < < crtc - > id ;
}
}
2015-01-06 11:13:28 +01:00
drm_crtc_helper_add ( & crtc - > base , & lcdc_crtc_helper_funcs ) ;
2017-06-22 07:03:11 +02:00
drm_mode_crtc_set_gamma_size ( & crtc - > base , ATMEL_HLCDC_CLUT_SIZE ) ;
drm_crtc_enable_color_mgmt ( & crtc - > base , 0 , false ,
ATMEL_HLCDC_CLUT_SIZE ) ;
2015-01-06 11:13:28 +01:00
dc - > crtc = & crtc - > base ;
return 0 ;
fail :
atmel_hlcdc_crtc_destroy ( & crtc - > base ) ;
return ret ;
}