2019-06-03 07:44:50 +02:00
// SPDX-License-Identifier: GPL-2.0-only
2009-08-07 13:15:50 +03:00
/*
* Copyright ( C ) 2009 Nokia Corporation
2018-05-24 14:46:19 +03:00
* Author : Tomi Valkeinen < tomi . valkeinen @ ti . com >
2009-08-07 13:15:50 +03:00
*
* Some code and ideas taken from drivers / video / omap / driver
* by Imre Deak .
*/
# define DSS_SUBSYS_NAME "DPI"
2020-02-26 13:25:05 +02:00
# include <linux/clk.h>
2009-08-07 13:15:50 +03:00
# include <linux/delay.h>
2010-02-04 17:03:41 +02:00
# include <linux/err.h>
2009-08-07 13:15:50 +03:00
# include <linux/errno.h>
2020-02-26 13:25:05 +02:00
# include <linux/export.h>
# include <linux/kernel.h>
# include <linux/of.h>
2010-02-04 17:03:41 +02:00
# include <linux/platform_device.h>
# include <linux/regulator/consumer.h>
2012-09-28 10:03:03 +03:00
# include <linux/string.h>
2017-08-05 01:44:12 +03:00
# include <linux/sys_soc.h>
2009-08-07 13:15:50 +03:00
2020-02-26 13:25:08 +02:00
# include <drm/drm_bridge.h>
2009-08-07 13:15:50 +03:00
# include "dss.h"
2020-02-26 13:25:05 +02:00
# include "omapdss.h"
2009-08-07 13:15:50 +03:00
2014-05-30 16:26:22 +05:30
struct dpi_data {
2013-03-19 11:33:52 +02:00
struct platform_device * pdev ;
2017-08-05 01:43:56 +03:00
enum dss_model dss_model ;
2018-02-13 14:00:24 +02:00
struct dss_device * dss ;
2018-03-04 21:49:28 +02:00
unsigned int id ;
2013-03-19 11:33:52 +02:00
2010-02-04 17:03:41 +02:00
struct regulator * vdds_dsi_reg ;
2016-05-17 16:08:54 +03:00
enum dss_clk_source clk_src ;
2014-10-22 14:49:14 +03:00
struct dss_pll * pll ;
2012-06-29 14:19:13 +05:30
struct dss_lcd_mgr_config mgr_config ;
2018-09-21 22:12:46 +03:00
unsigned long pixelclock ;
2012-07-06 15:30:52 +05:30
int data_lines ;
2012-09-26 16:30:49 +05:30
OMAPDSS: combine omap_dss_output into omap_dss_device
We currently have omap_dss_device, which represents an external display
device, sometimes an external encoder, sometimes a panel. Then we have
omap_dss_output, which represents DSS's output encoder.
In the future with new display device model, we construct a video
pipeline from the display blocks. To accomplish this, all the blocks
need to be presented by the same entity.
Thus, this patch combines omap_dss_output into omap_dss_device. Some of
the fields in omap_dss_output are already found in omap_dss_device, but
some are not. This means we'll have DSS output specific fields in
omap_dss_device, which is not very nice. However, it is easier to just
keep those output specific fields there for now, and after transition to
new display device model is made, they can be cleaned up easier than
could be done now.
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
2013-04-19 15:09:34 +03:00
struct omap_dss_device output ;
2020-02-26 13:25:08 +02:00
struct drm_bridge bridge ;
2014-05-30 16:26:22 +05:30
} ;
2020-02-26 13:25:08 +02:00
# define drm_bridge_to_dpi(bridge) container_of(bridge, struct dpi_data, bridge)
2014-06-01 12:47:44 +05:30
2020-02-26 13:25:06 +02:00
/* -----------------------------------------------------------------------------
* Clock Handling and PLL
*/
2018-02-13 14:00:30 +02:00
static enum dss_clk_source dpi_get_clk_src_dra7xx ( struct dpi_data * dpi ,
enum omap_channel channel )
2016-08-10 11:04:29 +03:00
{
/*
* Possible clock sources :
* LCD1 : FCK / PLL1_1 / HDMI_PLL
* LCD2 : FCK / PLL1_3 / HDMI_PLL ( DRA74x : PLL2_3 )
* LCD3 : FCK / PLL1_3 / HDMI_PLL ( DRA74x : PLL2_1 )
*/
switch ( channel ) {
case OMAP_DSS_CHANNEL_LCD :
{
2018-02-13 14:00:30 +02:00
if ( dss_pll_find_by_src ( dpi - > dss , DSS_CLK_SRC_PLL1_1 ) )
2016-08-10 11:04:29 +03:00
return DSS_CLK_SRC_PLL1_1 ;
break ;
}
case OMAP_DSS_CHANNEL_LCD2 :
{
2018-02-13 14:00:30 +02:00
if ( dss_pll_find_by_src ( dpi - > dss , DSS_CLK_SRC_PLL1_3 ) )
2016-08-10 11:04:29 +03:00
return DSS_CLK_SRC_PLL1_3 ;
2018-02-13 14:00:30 +02:00
if ( dss_pll_find_by_src ( dpi - > dss , DSS_CLK_SRC_PLL2_3 ) )
2016-08-10 11:04:29 +03:00
return DSS_CLK_SRC_PLL2_3 ;
break ;
}
case OMAP_DSS_CHANNEL_LCD3 :
{
2018-02-13 14:00:30 +02:00
if ( dss_pll_find_by_src ( dpi - > dss , DSS_CLK_SRC_PLL2_1 ) )
2016-08-10 11:04:29 +03:00
return DSS_CLK_SRC_PLL2_1 ;
2018-02-13 14:00:30 +02:00
if ( dss_pll_find_by_src ( dpi - > dss , DSS_CLK_SRC_PLL1_3 ) )
2016-08-10 11:04:29 +03:00
return DSS_CLK_SRC_PLL1_3 ;
break ;
}
default :
break ;
}
return DSS_CLK_SRC_FCK ;
}
2017-08-05 01:43:56 +03:00
static enum dss_clk_source dpi_get_clk_src ( struct dpi_data * dpi )
2011-05-12 17:26:26 +05:30
{
2017-08-05 01:43:56 +03:00
enum omap_channel channel = dpi - > output . dispc_channel ;
OMAPDSS: fix TV-out issue with DSI PLL
Commit 0e8276ef75f5c7811b038d1d23b2b42c16efc5ac (OMAPDSS: DPI: always
use DSI PLL if available) made dpi.c use DSI PLL for its clock. This
works fine, for DPI, but has a nasty side effect on OMAP3:
On OMAP3 the same clock is used for DISPC fclk and LCD output. Thus,
after the above patch, DSI PLL is used for DISPC and LCD output. If
TV-out is used, the TV-out needs DISPC. And if DPI is turned off, the
DSI PLL is also turned off, disabling DISPC.
For this to work, we'd need proper DSS internal clock handling, with
refcounts, which is a non-trivial project.
This patch fixes the issue for now by disabling the use of DSI PLL for
DPI on OMAP3.
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
2012-12-13 14:21:30 +02:00
/*
* XXX we can ' t currently use DSI PLL for DPI with OMAP3 , as the DSI PLL
* would also be used for DISPC fclk . Meaning , when the DPI output is
* disabled , DISPC clock will be disabled , and TV out will stop .
*/
2017-08-05 01:43:56 +03:00
switch ( dpi - > dss_model ) {
case DSS_MODEL_OMAP2 :
case DSS_MODEL_OMAP3 :
2016-05-17 16:08:54 +03:00
return DSS_CLK_SRC_FCK ;
OMAPDSS: fix TV-out issue with DSI PLL
Commit 0e8276ef75f5c7811b038d1d23b2b42c16efc5ac (OMAPDSS: DPI: always
use DSI PLL if available) made dpi.c use DSI PLL for its clock. This
works fine, for DPI, but has a nasty side effect on OMAP3:
On OMAP3 the same clock is used for DISPC fclk and LCD output. Thus,
after the above patch, DSI PLL is used for DISPC and LCD output. If
TV-out is used, the TV-out needs DISPC. And if DPI is turned off, the
DSI PLL is also turned off, disabling DISPC.
For this to work, we'd need proper DSS internal clock handling, with
refcounts, which is a non-trivial project.
This patch fixes the issue for now by disabling the use of DSI PLL for
DPI on OMAP3.
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
2012-12-13 14:21:30 +02:00
2017-08-05 01:43:56 +03:00
case DSS_MODEL_OMAP4 :
2013-03-11 13:57:38 +02:00
switch ( channel ) {
case OMAP_DSS_CHANNEL_LCD :
2016-05-17 16:08:54 +03:00
return DSS_CLK_SRC_PLL1_1 ;
2013-03-11 13:57:38 +02:00
case OMAP_DSS_CHANNEL_LCD2 :
2016-05-17 16:08:54 +03:00
return DSS_CLK_SRC_PLL2_1 ;
2013-03-11 13:57:38 +02:00
default :
2016-05-17 16:08:54 +03:00
return DSS_CLK_SRC_FCK ;
2013-03-11 13:57:38 +02:00
}
2017-08-05 01:43:56 +03:00
case DSS_MODEL_OMAP5 :
2013-03-11 13:57:38 +02:00
switch ( channel ) {
case OMAP_DSS_CHANNEL_LCD :
2016-05-17 16:08:54 +03:00
return DSS_CLK_SRC_PLL1_1 ;
2013-03-11 13:57:38 +02:00
case OMAP_DSS_CHANNEL_LCD3 :
2016-05-17 16:08:54 +03:00
return DSS_CLK_SRC_PLL2_1 ;
case OMAP_DSS_CHANNEL_LCD2 :
2013-03-11 13:57:38 +02:00
default :
2016-05-17 16:08:54 +03:00
return DSS_CLK_SRC_FCK ;
2013-03-11 13:57:38 +02:00
}
2017-08-05 01:43:56 +03:00
case DSS_MODEL_DRA7 :
2018-02-13 14:00:30 +02:00
return dpi_get_clk_src_dra7xx ( dpi , channel ) ;
2014-12-31 11:26:06 +02:00
2012-10-22 16:12:58 +03:00
default :
2016-05-17 14:01:10 +03:00
return DSS_CLK_SRC_FCK ;
2012-10-22 16:12:58 +03:00
}
2011-04-12 13:52:26 +05:30
}
2013-03-05 17:07:16 +02:00
struct dpi_clk_calc_ctx {
2018-04-05 09:55:37 +03:00
struct dpi_data * dpi ;
2018-02-11 15:07:34 +02:00
unsigned int clkout_idx ;
2013-03-05 17:07:16 +02:00
/* inputs */
unsigned long pck_min , pck_max ;
/* outputs */
2016-05-18 12:22:32 +03:00
struct dss_pll_clock_info pll_cinfo ;
2014-01-28 08:50:47 +02:00
unsigned long fck ;
2013-03-05 17:07:16 +02:00
struct dispc_clock_info dispc_cinfo ;
} ;
static bool dpi_calc_dispc_cb ( int lckd , int pckd , unsigned long lck ,
unsigned long pck , void * data )
{
struct dpi_clk_calc_ctx * ctx = data ;
/*
* Odd dividers give us uneven duty cycle , causing problem when level
* shifted . So skip all odd dividers when the pixel clock is on the
* higher side .
*/
2013-06-12 09:44:52 +03:00
if ( ctx - > pck_min > = 100000000 ) {
2013-03-05 17:07:16 +02:00
if ( lckd > 1 & & lckd % 2 ! = 0 )
return false ;
if ( pckd > 1 & & pckd % 2 ! = 0 )
return false ;
}
ctx - > dispc_cinfo . lck_div = lckd ;
ctx - > dispc_cinfo . pck_div = pckd ;
ctx - > dispc_cinfo . lck = lck ;
ctx - > dispc_cinfo . pck = pck ;
return true ;
}
2014-10-22 14:49:14 +03:00
static bool dpi_calc_hsdiv_cb ( int m_dispc , unsigned long dispc ,
2013-03-05 17:07:16 +02:00
void * data )
{
struct dpi_clk_calc_ctx * ctx = data ;
2016-05-18 12:22:32 +03:00
ctx - > pll_cinfo . mX [ ctx - > clkout_idx ] = m_dispc ;
ctx - > pll_cinfo . clkout [ ctx - > clkout_idx ] = dispc ;
2013-03-05 17:07:16 +02:00
2018-04-05 09:55:37 +03:00
return dispc_div_calc ( ctx - > dpi - > dss - > dispc , dispc ,
2018-02-13 14:00:43 +02:00
ctx - > pck_min , ctx - > pck_max ,
dpi_calc_dispc_cb , ctx ) ;
2013-03-05 17:07:16 +02:00
}
2014-10-22 14:49:14 +03:00
static bool dpi_calc_pll_cb ( int n , int m , unsigned long fint ,
unsigned long clkdco ,
2013-03-05 17:07:16 +02:00
void * data )
{
struct dpi_clk_calc_ctx * ctx = data ;
2016-05-18 12:22:32 +03:00
ctx - > pll_cinfo . n = n ;
ctx - > pll_cinfo . m = m ;
ctx - > pll_cinfo . fint = fint ;
ctx - > pll_cinfo . clkdco = clkdco ;
2013-03-05 17:07:16 +02:00
2018-04-05 09:55:37 +03:00
return dss_pll_hsdiv_calc_a ( ctx - > dpi - > pll , clkdco ,
ctx - > pck_min , dss_get_max_fck_rate ( ctx - > dpi - > dss ) ,
2014-10-22 14:49:14 +03:00
dpi_calc_hsdiv_cb , ctx ) ;
2013-03-05 17:07:16 +02:00
}
2013-10-31 14:44:23 +02:00
static bool dpi_calc_dss_cb ( unsigned long fck , void * data )
2013-03-05 17:07:16 +02:00
{
struct dpi_clk_calc_ctx * ctx = data ;
2013-10-31 14:44:23 +02:00
ctx - > fck = fck ;
2013-03-05 17:07:16 +02:00
2018-04-05 09:55:37 +03:00
return dispc_div_calc ( ctx - > dpi - > dss - > dispc , fck ,
2018-02-13 14:00:43 +02:00
ctx - > pck_min , ctx - > pck_max ,
dpi_calc_dispc_cb , ctx ) ;
2013-03-05 17:07:16 +02:00
}
2016-05-18 12:22:32 +03:00
static bool dpi_pll_clk_calc ( struct dpi_data * dpi , unsigned long pck ,
2014-05-30 16:26:22 +05:30
struct dpi_clk_calc_ctx * ctx )
2013-03-05 17:07:16 +02:00
{
unsigned long clkin ;
memset ( ctx , 0 , sizeof ( * ctx ) ) ;
2018-04-05 09:55:37 +03:00
ctx - > dpi = dpi ;
2016-05-17 16:20:07 +03:00
ctx - > clkout_idx = dss_pll_get_clkout_idx_for_src ( dpi - > clk_src ) ;
2013-03-05 17:07:16 +02:00
2016-05-18 12:06:49 +03:00
clkin = clk_get_rate ( dpi - > pll - > clkin ) ;
2013-03-05 17:07:16 +02:00
2016-05-18 12:06:49 +03:00
if ( dpi - > pll - > hw - > type = = DSS_PLL_TYPE_A ) {
unsigned long pll_min , pll_max ;
2014-10-22 14:49:14 +03:00
2016-05-18 12:06:49 +03:00
ctx - > pck_min = pck - 1000 ;
ctx - > pck_max = pck + 1000 ;
pll_min = 0 ;
pll_max = 0 ;
2018-04-05 09:55:37 +03:00
return dss_pll_calc_a ( ctx - > dpi - > pll , clkin ,
2016-05-18 12:06:49 +03:00
pll_min , pll_max ,
dpi_calc_pll_cb , ctx ) ;
} else { /* DSS_PLL_TYPE_B */
2016-05-18 12:22:32 +03:00
dss_pll_calc_b ( dpi - > pll , clkin , pck , & ctx - > pll_cinfo ) ;
2016-05-18 12:06:49 +03:00
ctx - > dispc_cinfo . lck_div = 1 ;
ctx - > dispc_cinfo . pck_div = 1 ;
2016-05-18 12:22:32 +03:00
ctx - > dispc_cinfo . lck = ctx - > pll_cinfo . clkout [ 0 ] ;
2016-05-18 12:06:49 +03:00
ctx - > dispc_cinfo . pck = ctx - > dispc_cinfo . lck ;
return true ;
}
2013-03-05 17:07:16 +02:00
}
2018-02-13 14:00:26 +02:00
static bool dpi_dss_clk_calc ( struct dpi_data * dpi , unsigned long pck ,
struct dpi_clk_calc_ctx * ctx )
2013-03-05 17:07:16 +02:00
{
int i ;
/*
* DSS fck gives us very few possibilities , so finding a good pixel
* clock may not be possible . We try multiple times to find the clock ,
* each time widening the pixel clock range we look for , up to
2013-04-10 14:54:54 +03:00
* + / - ~ 15 MHz .
2013-03-05 17:07:16 +02:00
*/
2013-04-10 14:54:54 +03:00
for ( i = 0 ; i < 25 ; + + i ) {
2013-03-05 17:07:16 +02:00
bool ok ;
memset ( ctx , 0 , sizeof ( * ctx ) ) ;
2018-04-05 09:55:37 +03:00
ctx - > dpi = dpi ;
2013-03-05 17:07:16 +02:00
if ( pck > 1000 * i * i * i )
ctx - > pck_min = max ( pck - 1000 * i * i * i , 0lu ) ;
else
ctx - > pck_min = 0 ;
ctx - > pck_max = pck + 1000 * i * i * i ;
2018-02-13 14:00:26 +02:00
ok = dss_div_calc ( dpi - > dss , pck , ctx - > pck_min ,
dpi_calc_dss_cb , ctx ) ;
2013-03-05 17:07:16 +02:00
if ( ok )
return ok ;
}
return false ;
}
2020-02-26 13:25:07 +02:00
static int dpi_set_pll_clk ( struct dpi_data * dpi , unsigned long pck_req )
2009-08-07 13:15:50 +03:00
{
2013-03-05 17:07:16 +02:00
struct dpi_clk_calc_ctx ctx ;
2009-08-07 13:15:50 +03:00
int r ;
2013-03-05 17:07:16 +02:00
bool ok ;
2009-08-07 13:15:50 +03:00
2016-05-18 12:22:32 +03:00
ok = dpi_pll_clk_calc ( dpi , pck_req , & ctx ) ;
2013-03-05 17:07:16 +02:00
if ( ! ok )
return - EINVAL ;
2009-08-07 13:15:50 +03:00
2016-05-18 12:22:32 +03:00
r = dss_pll_set_config ( dpi - > pll , & ctx . pll_cinfo ) ;
2009-08-07 13:15:50 +03:00
if ( r )
return r ;
2020-02-26 13:25:07 +02:00
dss_select_lcd_clk_source ( dpi - > dss , dpi - > output . dispc_channel ,
dpi - > clk_src ) ;
2009-08-07 13:15:50 +03:00
2014-05-30 16:26:22 +05:30
dpi - > mgr_config . clock_info = ctx . dispc_cinfo ;
2009-08-07 13:15:50 +03:00
return 0 ;
}
2011-04-12 13:52:26 +05:30
2020-02-26 13:25:07 +02:00
static int dpi_set_dispc_clk ( struct dpi_data * dpi , unsigned long pck_req )
2009-08-07 13:15:50 +03:00
{
2013-03-05 17:07:16 +02:00
struct dpi_clk_calc_ctx ctx ;
2009-08-07 13:15:50 +03:00
int r ;
2013-03-05 17:07:16 +02:00
bool ok ;
2009-08-07 13:15:50 +03:00
2018-02-13 14:00:26 +02:00
ok = dpi_dss_clk_calc ( dpi , pck_req , & ctx ) ;
2013-03-05 17:07:16 +02:00
if ( ! ok )
return - EINVAL ;
2009-08-07 13:15:50 +03:00
2018-02-13 14:00:26 +02:00
r = dss_set_fck_rate ( dpi - > dss , ctx . fck ) ;
2009-08-07 13:15:50 +03:00
if ( r )
return r ;
2014-05-30 16:26:22 +05:30
dpi - > mgr_config . clock_info = ctx . dispc_cinfo ;
2009-08-07 13:15:50 +03:00
return 0 ;
}
2014-05-30 16:26:22 +05:30
static int dpi_set_mode ( struct dpi_data * dpi )
2009-08-07 13:15:50 +03:00
{
2020-02-26 13:25:07 +02:00
int r ;
2009-08-07 13:15:50 +03:00
2014-10-22 14:49:14 +03:00
if ( dpi - > pll )
2020-02-26 13:25:07 +02:00
r = dpi_set_pll_clk ( dpi , dpi - > pixelclock ) ;
2011-04-12 13:52:26 +05:30
else
2020-02-26 13:25:07 +02:00
r = dpi_set_dispc_clk ( dpi , dpi - > pixelclock ) ;
2009-08-07 13:15:50 +03:00
2020-02-26 13:25:07 +02:00
return r ;
2009-08-07 13:15:50 +03:00
}
2014-05-30 16:26:22 +05:30
static void dpi_config_lcd_manager ( struct dpi_data * dpi )
2009-08-07 13:15:50 +03:00
{
2014-05-30 16:26:22 +05:30
dpi - > mgr_config . io_pad_mode = DSS_IO_PAD_MODE_BYPASS ;
2011-08-22 17:41:57 +05:30
2014-05-30 16:26:22 +05:30
dpi - > mgr_config . stallmode = false ;
dpi - > mgr_config . fifohandcheck = false ;
2012-06-29 14:19:13 +05:30
2014-05-30 16:26:22 +05:30
dpi - > mgr_config . video_port_width = dpi - > data_lines ;
2012-06-29 14:19:13 +05:30
2014-05-30 16:26:22 +05:30
dpi - > mgr_config . lcden_sig_polarity = 0 ;
2012-06-29 14:19:13 +05:30
2018-02-13 14:00:38 +02:00
dss_mgr_set_lcd_config ( & dpi - > output , & dpi - > mgr_config ) ;
2009-08-07 13:15:50 +03:00
}
2020-02-26 13:25:08 +02:00
static int dpi_clock_update ( struct dpi_data * dpi , unsigned long * clock )
{
int lck_div , pck_div ;
unsigned long fck ;
struct dpi_clk_calc_ctx ctx ;
if ( dpi - > pll ) {
if ( ! dpi_pll_clk_calc ( dpi , * clock , & ctx ) )
return - EINVAL ;
fck = ctx . pll_cinfo . clkout [ ctx . clkout_idx ] ;
} else {
if ( ! dpi_dss_clk_calc ( dpi , * clock , & ctx ) )
return - EINVAL ;
fck = ctx . fck ;
}
lck_div = ctx . dispc_cinfo . lck_div ;
pck_div = ctx . dispc_cinfo . pck_div ;
* clock = fck / lck_div / pck_div ;
return 0 ;
}
2020-02-26 13:25:06 +02:00
static int dpi_verify_pll ( struct dss_pll * pll )
{
int r ;
/* do initial setup with the PLL to see if it is operational */
r = dss_pll_enable ( pll ) ;
if ( r )
return r ;
dss_pll_disable ( pll ) ;
return 0 ;
}
static void dpi_init_pll ( struct dpi_data * dpi )
{
struct dss_pll * pll ;
if ( dpi - > pll )
return ;
dpi - > clk_src = dpi_get_clk_src ( dpi ) ;
pll = dss_pll_find_by_src ( dpi - > dss , dpi - > clk_src ) ;
if ( ! pll )
return ;
if ( dpi_verify_pll ( pll ) ) {
DSSWARN ( " PLL not operational \n " ) ;
return ;
}
dpi - > pll = pll ;
}
/* -----------------------------------------------------------------------------
2020-02-26 13:25:08 +02:00
* DRM Bridge Operations
2020-02-26 13:25:06 +02:00
*/
2020-02-26 13:25:08 +02:00
static int dpi_bridge_attach ( struct drm_bridge * bridge ,
enum drm_bridge_attach_flags flags )
2020-02-26 13:25:06 +02:00
{
2020-02-26 13:25:08 +02:00
struct dpi_data * dpi = drm_bridge_to_dpi ( bridge ) ;
if ( ! ( flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR ) )
return - EINVAL ;
2020-02-26 13:25:06 +02:00
dpi_init_pll ( dpi ) ;
2020-02-26 13:25:08 +02:00
return drm_bridge_attach ( bridge - > encoder , dpi - > output . next_bridge ,
bridge , flags ) ;
2020-02-26 13:25:06 +02:00
}
2020-02-26 13:25:08 +02:00
static enum drm_mode_status
dpi_bridge_mode_valid ( struct drm_bridge * bridge ,
const struct drm_display_mode * mode )
2020-02-26 13:25:06 +02:00
{
2020-02-26 13:25:08 +02:00
struct dpi_data * dpi = drm_bridge_to_dpi ( bridge ) ;
unsigned long clock = mode - > clock * 1000 ;
int ret ;
if ( mode - > hdisplay % 8 ! = 0 )
return MODE_BAD_WIDTH ;
if ( mode - > clock = = 0 )
return MODE_NOCLOCK ;
ret = dpi_clock_update ( dpi , & clock ) ;
if ( ret < 0 )
return MODE_CLOCK_RANGE ;
return MODE_OK ;
2020-02-26 13:25:06 +02:00
}
2020-02-26 13:25:08 +02:00
static bool dpi_bridge_mode_fixup ( struct drm_bridge * bridge ,
const struct drm_display_mode * mode ,
struct drm_display_mode * adjusted_mode )
2009-08-07 13:15:50 +03:00
{
2020-02-26 13:25:08 +02:00
struct dpi_data * dpi = drm_bridge_to_dpi ( bridge ) ;
unsigned long clock = mode - > clock * 1000 ;
int ret ;
ret = dpi_clock_update ( dpi , & clock ) ;
if ( ret < 0 )
return false ;
adjusted_mode - > clock = clock / 1000 ;
return true ;
}
2009-08-07 13:15:50 +03:00
2020-02-26 13:25:08 +02:00
static void dpi_bridge_mode_set ( struct drm_bridge * bridge ,
const struct drm_display_mode * mode ,
const struct drm_display_mode * adjusted_mode )
{
struct dpi_data * dpi = drm_bridge_to_dpi ( bridge ) ;
dpi - > pixelclock = adjusted_mode - > clock * 1000 ;
}
static void dpi_bridge_enable ( struct drm_bridge * bridge )
{
struct dpi_data * dpi = drm_bridge_to_dpi ( bridge ) ;
int r ;
2012-07-05 12:52:46 +05:30
2017-08-05 01:43:49 +03:00
if ( dpi - > vdds_dsi_reg ) {
2014-05-30 16:26:22 +05:30
r = regulator_enable ( dpi - > vdds_dsi_reg ) ;
2010-02-04 17:03:41 +02:00
if ( r )
2020-02-26 13:25:08 +02:00
return ;
2010-02-04 17:03:41 +02:00
}
2018-02-13 14:00:42 +02:00
r = dispc_runtime_get ( dpi - > dss - > dispc ) ;
2009-08-07 13:15:50 +03:00
if ( r )
2011-05-27 10:52:19 +03:00
goto err_get_dispc ;
2020-02-26 13:25:08 +02:00
r = dss_dpi_select_source ( dpi - > dss , dpi - > id , dpi - > output . dispc_channel ) ;
2012-09-21 12:09:54 +03:00
if ( r )
goto err_src_sel ;
2014-10-22 14:49:14 +03:00
if ( dpi - > pll ) {
r = dss_pll_enable ( dpi - > pll ) ;
2011-04-12 13:52:26 +05:30
if ( r )
2016-05-18 12:22:32 +03:00
goto err_pll_init ;
2011-04-12 13:52:26 +05:30
}
2014-05-30 16:26:22 +05:30
r = dpi_set_mode ( dpi ) ;
2009-08-07 13:15:50 +03:00
if ( r )
2011-05-27 10:52:19 +03:00
goto err_set_mode ;
2009-08-07 13:15:50 +03:00
2014-05-30 16:26:22 +05:30
dpi_config_lcd_manager ( dpi ) ;
2012-06-29 14:19:13 +05:30
2009-08-07 13:15:50 +03:00
mdelay ( 2 ) ;
2018-02-13 14:00:38 +02:00
r = dss_mgr_enable ( & dpi - > output ) ;
2011-11-21 13:42:58 +02:00
if ( r )
goto err_mgr_enable ;
2009-08-07 13:15:50 +03:00
2018-08-24 19:38:07 +03:00
return ;
2009-08-07 13:15:50 +03:00
2011-11-21 13:42:58 +02:00
err_mgr_enable :
2011-05-27 10:52:19 +03:00
err_set_mode :
2014-10-22 14:49:14 +03:00
if ( dpi - > pll )
dss_pll_disable ( dpi - > pll ) ;
2016-05-18 12:22:32 +03:00
err_pll_init :
2012-09-21 12:09:54 +03:00
err_src_sel :
2018-02-13 14:00:42 +02:00
dispc_runtime_put ( dpi - > dss - > dispc ) ;
2011-05-27 10:52:19 +03:00
err_get_dispc :
2017-08-05 01:43:49 +03:00
if ( dpi - > vdds_dsi_reg )
2014-05-30 16:26:22 +05:30
regulator_disable ( dpi - > vdds_dsi_reg ) ;
2009-08-07 13:15:50 +03:00
}
2020-02-26 13:25:08 +02:00
static void dpi_bridge_disable ( struct drm_bridge * bridge )
2009-08-07 13:15:50 +03:00
{
2020-02-26 13:25:08 +02:00
struct dpi_data * dpi = drm_bridge_to_dpi ( bridge ) ;
2012-07-05 12:52:46 +05:30
2018-02-13 14:00:38 +02:00
dss_mgr_disable ( & dpi - > output ) ;
2009-08-07 13:15:50 +03:00
2014-10-22 14:49:14 +03:00
if ( dpi - > pll ) {
2018-02-13 14:00:38 +02:00
dss_select_lcd_clk_source ( dpi - > dss , dpi - > output . dispc_channel ,
DSS_CLK_SRC_FCK ) ;
2014-10-22 14:49:14 +03:00
dss_pll_disable ( dpi - > pll ) ;
2011-04-12 13:52:26 +05:30
}
2009-08-07 13:15:50 +03:00
2018-02-13 14:00:42 +02:00
dispc_runtime_put ( dpi - > dss - > dispc ) ;
2009-08-07 13:15:50 +03:00
2017-08-05 01:43:49 +03:00
if ( dpi - > vdds_dsi_reg )
2014-05-30 16:26:22 +05:30
regulator_disable ( dpi - > vdds_dsi_reg ) ;
2009-08-07 13:15:50 +03:00
}
2020-02-26 13:25:08 +02:00
static const struct drm_bridge_funcs dpi_bridge_funcs = {
. attach = dpi_bridge_attach ,
. mode_valid = dpi_bridge_mode_valid ,
. mode_fixup = dpi_bridge_mode_fixup ,
. mode_set = dpi_bridge_mode_set ,
. enable = dpi_bridge_enable ,
. disable = dpi_bridge_disable ,
} ;
2009-08-07 13:15:50 +03:00
2020-02-26 13:25:08 +02:00
static void dpi_bridge_init ( struct dpi_data * dpi )
{
dpi - > bridge . funcs = & dpi_bridge_funcs ;
dpi - > bridge . of_node = dpi - > pdev - > dev . of_node ;
dpi - > bridge . type = DRM_MODE_CONNECTOR_DPI ;
2009-08-07 13:15:50 +03:00
2020-02-26 13:25:08 +02:00
drm_bridge_add ( & dpi - > bridge ) ;
2009-08-07 13:15:50 +03:00
}
2020-02-26 13:25:08 +02:00
static void dpi_bridge_cleanup ( struct dpi_data * dpi )
2012-10-30 12:57:43 +02:00
{
2020-02-26 13:25:08 +02:00
drm_bridge_remove ( & dpi - > bridge ) ;
2012-10-30 12:57:43 +02:00
}
2020-02-26 13:25:08 +02:00
/* -----------------------------------------------------------------------------
* Initialisation and Cleanup
*/
2013-04-19 16:52:27 +03:00
2013-02-13 11:23:54 +02:00
/*
* Return a hardcoded channel for the DPI output . This should work for
* current use cases , but this can be later expanded to either resolve
* the channel in some more dynamic manner , or get the channel as a user
* parameter .
*/
2018-03-04 21:49:28 +02:00
static enum omap_channel dpi_get_channel ( struct dpi_data * dpi )
2013-02-13 11:23:54 +02:00
{
2017-08-05 01:43:56 +03:00
switch ( dpi - > dss_model ) {
case DSS_MODEL_OMAP2 :
case DSS_MODEL_OMAP3 :
2013-02-13 11:23:54 +02:00
return OMAP_DSS_CHANNEL_LCD ;
2017-08-05 01:43:56 +03:00
case DSS_MODEL_DRA7 :
2018-03-04 21:49:28 +02:00
switch ( dpi - > id ) {
2014-12-31 11:26:06 +02:00
case 2 :
return OMAP_DSS_CHANNEL_LCD3 ;
case 1 :
return OMAP_DSS_CHANNEL_LCD2 ;
case 0 :
default :
return OMAP_DSS_CHANNEL_LCD ;
}
2017-08-05 01:43:56 +03:00
case DSS_MODEL_OMAP4 :
2013-02-13 11:23:54 +02:00
return OMAP_DSS_CHANNEL_LCD2 ;
2017-08-05 01:43:56 +03:00
case DSS_MODEL_OMAP5 :
2013-02-13 11:23:54 +02:00
return OMAP_DSS_CHANNEL_LCD3 ;
default :
DSSWARN ( " unsupported DSS version \n " ) ;
return OMAP_DSS_CHANNEL_LCD ;
}
}
2018-03-02 22:13:06 +02:00
static int dpi_init_output_port ( struct dpi_data * dpi , struct device_node * port )
2014-06-02 14:11:51 +05:30
{
struct omap_dss_device * out = & dpi - > output ;
2018-03-04 21:49:28 +02:00
u32 port_num = 0 ;
2018-03-06 01:25:13 +02:00
int r ;
2014-05-06 17:07:39 +05:30
2020-02-26 13:25:08 +02:00
dpi_bridge_init ( dpi ) ;
2018-03-04 21:49:28 +02:00
of_property_read_u32 ( port , " reg " , & port_num ) ;
dpi - > id = port_num < = 2 ? port_num : 0 ;
2014-05-06 17:07:39 +05:30
switch ( port_num ) {
case 2 :
out - > name = " dpi.2 " ;
break ;
case 1 :
out - > name = " dpi.1 " ;
break ;
case 0 :
default :
out - > name = " dpi.0 " ;
break ;
}
2014-06-02 14:11:51 +05:30
2017-08-05 01:43:56 +03:00
out - > dev = & dpi - > pdev - > dev ;
2014-06-02 14:11:51 +05:30
out - > id = OMAP_DSS_OUTPUT_DPI ;
2018-12-10 14:00:38 +02:00
out - > type = OMAP_DISPLAY_TYPE_DPI ;
2018-03-04 21:49:28 +02:00
out - > dispc_channel = dpi_get_channel ( dpi ) ;
2020-02-26 13:24:45 +02:00
out - > of_port = port_num ;
2014-06-02 14:11:51 +05:30
out - > owner = THIS_MODULE ;
2020-02-26 13:25:08 +02:00
r = omapdss_device_init_output ( out , & dpi - > bridge ) ;
if ( r < 0 ) {
dpi_bridge_cleanup ( dpi ) ;
2018-03-06 01:25:13 +02:00
return r ;
2020-02-26 13:25:08 +02:00
}
2018-03-06 01:25:13 +02:00
2018-03-02 01:25:32 +02:00
omapdss_device_register ( out ) ;
2018-03-02 22:13:06 +02:00
return 0 ;
2014-06-02 14:11:51 +05:30
}
2015-06-04 14:12:16 +03:00
static void dpi_uninit_output_port ( struct device_node * port )
2014-06-02 14:11:51 +05:30
{
struct dpi_data * dpi = port - > data ;
struct omap_dss_device * out = & dpi - > output ;
2018-03-02 01:25:32 +02:00
omapdss_device_unregister ( out ) ;
2018-09-12 19:41:31 +03:00
omapdss_device_cleanup_output ( out ) ;
2020-02-26 13:25:08 +02:00
dpi_bridge_cleanup ( dpi ) ;
2014-06-02 14:11:51 +05:30
}
2020-02-26 13:25:06 +02:00
/* -----------------------------------------------------------------------------
* Initialisation and Cleanup
*/
2018-03-05 00:10:55 +02:00
static const struct soc_device_attribute dpi_soc_devices [ ] = {
{ . machine = " OMAP3[456]* " } ,
{ . machine = " [AD]M37* " } ,
{ /* sentinel */ }
} ;
static int dpi_init_regulator ( struct dpi_data * dpi )
{
struct regulator * vdds_dsi ;
/*
* The DPI uses the DSI VDDS on OMAP34xx , OMAP35xx , OMAP36xx , AM37xx and
* DM37xx only .
*/
if ( ! soc_device_match ( dpi_soc_devices ) )
return 0 ;
vdds_dsi = devm_regulator_get ( & dpi - > pdev - > dev , " vdds_dsi " ) ;
if ( IS_ERR ( vdds_dsi ) ) {
if ( PTR_ERR ( vdds_dsi ) ! = - EPROBE_DEFER )
DSSERR ( " can't get VDDS_DSI regulator \n " ) ;
return PTR_ERR ( vdds_dsi ) ;
}
dpi - > vdds_dsi_reg = vdds_dsi ;
return 0 ;
}
2018-02-13 14:00:24 +02:00
int dpi_init_port ( struct dss_device * dss , struct platform_device * pdev ,
struct device_node * port , enum dss_model dss_model )
2013-12-16 15:13:24 +02:00
{
2014-06-01 12:47:44 +05:30
struct dpi_data * dpi ;
2013-12-16 15:13:24 +02:00
struct device_node * ep ;
u32 datalines ;
int r ;
2014-06-01 12:47:44 +05:30
dpi = devm_kzalloc ( & pdev - > dev , sizeof ( * dpi ) , GFP_KERNEL ) ;
if ( ! dpi )
return - ENOMEM ;
2017-03-22 08:26:08 -05:00
ep = of_get_next_child ( port , NULL ) ;
2013-12-16 15:13:24 +02:00
if ( ! ep )
return 0 ;
r = of_property_read_u32 ( ep , " data-lines " , & datalines ) ;
2018-03-02 21:38:21 +02:00
of_node_put ( ep ) ;
2013-12-16 15:13:24 +02:00
if ( r ) {
DSSERR ( " failed to parse datalines \n " ) ;
2018-03-02 21:38:21 +02:00
return r ;
2013-12-16 15:13:24 +02:00
}
2014-05-30 16:26:22 +05:30
dpi - > data_lines = datalines ;
2013-12-16 15:13:24 +02:00
2014-05-30 16:26:22 +05:30
dpi - > pdev = pdev ;
2017-08-05 01:43:56 +03:00
dpi - > dss_model = dss_model ;
2018-02-13 14:00:24 +02:00
dpi - > dss = dss ;
2014-06-02 14:11:51 +05:30
port - > data = dpi ;
2013-12-16 15:13:24 +02:00
2018-03-05 00:10:55 +02:00
r = dpi_init_regulator ( dpi ) ;
if ( r )
return r ;
2018-03-02 22:13:06 +02:00
return dpi_init_output_port ( dpi , port ) ;
2013-12-16 15:13:24 +02:00
}
2015-06-04 14:12:16 +03:00
void dpi_uninit_port ( struct device_node * port )
2013-12-16 15:13:24 +02:00
{
2014-06-02 14:11:51 +05:30
struct dpi_data * dpi = port - > data ;
2014-05-30 16:26:22 +05:30
2017-10-13 17:59:03 +03:00
if ( ! dpi )
2013-12-16 15:13:24 +02:00
return ;
2014-06-02 14:11:51 +05:30
dpi_uninit_output_port ( port ) ;
2013-12-16 15:13:24 +02:00
}