Commit 9b5cbdbb authored by Miquel Raynal's avatar Miquel Raynal Committed by Heiko Stuebner

drm/rockchip: lvds: Create an RK3288 specific probe function

The probe function is highly adapted to the RK3288 specificities, move
all specific bits into an "rk3288_probe" function, also part of the
platform data.

The goal is to ease the addition of new flavors of Rockchip LVDS IPs.
Signed-off-by: default avatarMiquel Raynal <miquel.raynal@bootlin.com>
Signed-off-by: default avatarHeiko Stuebner <heiko@sntech.de>
Link: https://patchwork.freedesktop.org/patch/msgid/20191224143900.23567-7-miquel.raynal@bootlin.com
parent 36839e57
...@@ -31,6 +31,8 @@ ...@@ -31,6 +31,8 @@
#define DISPLAY_OUTPUT_LVDS 1 #define DISPLAY_OUTPUT_LVDS 1
#define DISPLAY_OUTPUT_DUAL_LVDS 2 #define DISPLAY_OUTPUT_DUAL_LVDS 2
struct rockchip_lvds;
#define connector_to_lvds(c) \ #define connector_to_lvds(c) \
container_of(c, struct rockchip_lvds, connector) container_of(c, struct rockchip_lvds, connector)
...@@ -39,9 +41,11 @@ ...@@ -39,9 +41,11 @@
/** /**
* rockchip_lvds_soc_data - rockchip lvds Soc private data * rockchip_lvds_soc_data - rockchip lvds Soc private data
* @probe: LVDS platform probe function
* @helper_funcs: LVDS connector helper functions * @helper_funcs: LVDS connector helper functions
*/ */
struct rockchip_lvds_soc_data { struct rockchip_lvds_soc_data {
int (*probe)(struct platform_device *pdev, struct rockchip_lvds *lvds);
const struct drm_encoder_helper_funcs *helper_funcs; const struct drm_encoder_helper_funcs *helper_funcs;
}; };
...@@ -303,6 +307,52 @@ static void rk3288_lvds_encoder_disable(struct drm_encoder *encoder) ...@@ -303,6 +307,52 @@ static void rk3288_lvds_encoder_disable(struct drm_encoder *encoder)
drm_panel_unprepare(lvds->panel); drm_panel_unprepare(lvds->panel);
} }
static int rk3288_lvds_probe(struct platform_device *pdev,
struct rockchip_lvds *lvds)
{
struct resource *res;
int ret;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
lvds->regs = devm_ioremap_resource(lvds->dev, res);
if (IS_ERR(lvds->regs))
return PTR_ERR(lvds->regs);
lvds->pclk = devm_clk_get(lvds->dev, "pclk_lvds");
if (IS_ERR(lvds->pclk)) {
DRM_DEV_ERROR(lvds->dev, "could not get pclk_lvds\n");
return PTR_ERR(lvds->pclk);
}
lvds->pins = devm_kzalloc(lvds->dev, sizeof(*lvds->pins),
GFP_KERNEL);
if (!lvds->pins)
return -ENOMEM;
lvds->pins->p = devm_pinctrl_get(lvds->dev);
if (IS_ERR(lvds->pins->p)) {
DRM_DEV_ERROR(lvds->dev, "no pinctrl handle\n");
devm_kfree(lvds->dev, lvds->pins);
lvds->pins = NULL;
} else {
lvds->pins->default_state =
pinctrl_lookup_state(lvds->pins->p, "lcdc");
if (IS_ERR(lvds->pins->default_state)) {
DRM_DEV_ERROR(lvds->dev, "no default pinctrl state\n");
devm_kfree(lvds->dev, lvds->pins);
lvds->pins = NULL;
}
}
ret = clk_prepare(lvds->pclk);
if (ret < 0) {
DRM_DEV_ERROR(lvds->dev, "failed to prepare pclk_lvds\n");
return ret;
}
return 0;
}
static const static const
struct drm_encoder_helper_funcs rk3288_lvds_encoder_helper_funcs = { struct drm_encoder_helper_funcs rk3288_lvds_encoder_helper_funcs = {
.enable = rk3288_lvds_encoder_enable, .enable = rk3288_lvds_encoder_enable,
...@@ -315,6 +365,7 @@ static const struct drm_encoder_funcs rockchip_lvds_encoder_funcs = { ...@@ -315,6 +365,7 @@ static const struct drm_encoder_funcs rockchip_lvds_encoder_funcs = {
}; };
static const struct rockchip_lvds_soc_data rk3288_lvds_data = { static const struct rockchip_lvds_soc_data rk3288_lvds_data = {
.probe = rk3288_lvds_probe,
.helper_funcs = &rk3288_lvds_encoder_helper_funcs, .helper_funcs = &rk3288_lvds_encoder_helper_funcs,
}; };
...@@ -488,7 +539,6 @@ static int rockchip_lvds_probe(struct platform_device *pdev) ...@@ -488,7 +539,6 @@ static int rockchip_lvds_probe(struct platform_device *pdev)
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct rockchip_lvds *lvds; struct rockchip_lvds *lvds;
const struct of_device_id *match; const struct of_device_id *match;
struct resource *res;
int ret; int ret;
if (!dev->of_node) if (!dev->of_node)
...@@ -504,37 +554,6 @@ static int rockchip_lvds_probe(struct platform_device *pdev) ...@@ -504,37 +554,6 @@ static int rockchip_lvds_probe(struct platform_device *pdev)
return -ENODEV; return -ENODEV;
lvds->soc_data = match->data; lvds->soc_data = match->data;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
lvds->regs = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(lvds->regs))
return PTR_ERR(lvds->regs);
lvds->pclk = devm_clk_get(&pdev->dev, "pclk_lvds");
if (IS_ERR(lvds->pclk)) {
DRM_DEV_ERROR(dev, "could not get pclk_lvds\n");
return PTR_ERR(lvds->pclk);
}
lvds->pins = devm_kzalloc(lvds->dev, sizeof(*lvds->pins),
GFP_KERNEL);
if (!lvds->pins)
return -ENOMEM;
lvds->pins->p = devm_pinctrl_get(lvds->dev);
if (IS_ERR(lvds->pins->p)) {
DRM_DEV_ERROR(dev, "no pinctrl handle\n");
devm_kfree(lvds->dev, lvds->pins);
lvds->pins = NULL;
} else {
lvds->pins->default_state =
pinctrl_lookup_state(lvds->pins->p, "lcdc");
if (IS_ERR(lvds->pins->default_state)) {
DRM_DEV_ERROR(dev, "no default pinctrl state\n");
devm_kfree(lvds->dev, lvds->pins);
lvds->pins = NULL;
}
}
lvds->grf = syscon_regmap_lookup_by_phandle(dev->of_node, lvds->grf = syscon_regmap_lookup_by_phandle(dev->of_node,
"rockchip,grf"); "rockchip,grf");
if (IS_ERR(lvds->grf)) { if (IS_ERR(lvds->grf)) {
...@@ -542,13 +561,14 @@ static int rockchip_lvds_probe(struct platform_device *pdev) ...@@ -542,13 +561,14 @@ static int rockchip_lvds_probe(struct platform_device *pdev)
return PTR_ERR(lvds->grf); return PTR_ERR(lvds->grf);
} }
dev_set_drvdata(dev, lvds); ret = lvds->soc_data->probe(pdev, lvds);
if (ret) {
ret = clk_prepare(lvds->pclk); DRM_DEV_ERROR(dev, "Platform initialization failed\n");
if (ret < 0) {
DRM_DEV_ERROR(dev, "failed to prepare pclk_lvds\n");
return ret; return ret;
} }
dev_set_drvdata(dev, lvds);
ret = component_add(&pdev->dev, &rockchip_lvds_component_ops); ret = component_add(&pdev->dev, &rockchip_lvds_component_ops);
if (ret < 0) { if (ret < 0) {
DRM_DEV_ERROR(dev, "failed to add component\n"); DRM_DEV_ERROR(dev, "failed to add component\n");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment