Skip to content

Commit

Permalink
drm/exynos: consider deferred probe case
Browse files Browse the repository at this point in the history
This patch makes sure that exynos drm framework handles deferred
probe case correctly.

Sub drivers could be probed before resources, clock, regulator,
phy or panel, are ready for them so we should make sure that exynos
drm core waits until all resources are ready and sub drivers are
probed correctly.

Chagelog v2:
- Make sure that exynos drm core tries to bind sub drivers only in case that
  they have a pair: crtc and encoder/connector components should be a pair.
- Remove unnecessary patch:
  drm/exynos: mipi-dsi: consider panel driver-deferred probe
- Return error type correctly.

Signed-off-by: Inki Dae <inki.dae@samsung.com>
Acked-by: Kyungmin Park <kyungmin.park@samsung.com>
  • Loading branch information
Inki Dae committed Jun 2, 2014
1 parent 2e1ce1a commit df5225b
Show file tree
Hide file tree
Showing 8 changed files with 303 additions and 75 deletions.
18 changes: 16 additions & 2 deletions drivers/gpu/drm/exynos/exynos_dp_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1325,12 +1325,26 @@ static const struct component_ops exynos_dp_ops = {

static int exynos_dp_probe(struct platform_device *pdev)
{
return exynos_drm_component_add(&pdev->dev, &exynos_dp_ops);
int ret;

ret = exynos_drm_component_add(&pdev->dev, EXYNOS_DEVICE_TYPE_CONNECTOR,
exynos_dp_display.type);
if (ret)
return ret;

ret = component_add(&pdev->dev, &exynos_dp_ops);
if (ret)
exynos_drm_component_del(&pdev->dev,
EXYNOS_DEVICE_TYPE_CONNECTOR);

return ret;
}

static int exynos_dp_remove(struct platform_device *pdev)
{
exynos_drm_component_del(&pdev->dev, &exynos_dp_ops);
component_del(&pdev->dev, &exynos_dp_ops);
exynos_drm_component_del(&pdev->dev, EXYNOS_DEVICE_TYPE_CONNECTOR);

return 0;
}

Expand Down
22 changes: 19 additions & 3 deletions drivers/gpu/drm/exynos/exynos_drm_dpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,15 @@ struct exynos_drm_display *exynos_dpi_probe(struct device *dev)
struct exynos_dpi *ctx;
int ret;

ret = exynos_drm_component_add(dev,
EXYNOS_DEVICE_TYPE_CONNECTOR,
exynos_dpi_display.type);
if (ret)
return ERR_PTR(ret);

ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
if (!ctx)
return NULL;
goto err_del_component;

ctx->dev = dev;
exynos_dpi_display.ctx = ctx;
Expand All @@ -306,16 +312,24 @@ struct exynos_drm_display *exynos_dpi_probe(struct device *dev)
ret = exynos_dpi_parse_dt(ctx);
if (ret < 0) {
devm_kfree(dev, ctx);
return NULL;
goto err_del_component;
}

if (ctx->panel_node) {
ctx->panel = of_drm_find_panel(ctx->panel_node);
if (!ctx->panel)
if (!ctx->panel) {
exynos_drm_component_del(dev,
EXYNOS_DEVICE_TYPE_CONNECTOR);
return ERR_PTR(-EPROBE_DEFER);
}
}

return &exynos_dpi_display;

err_del_component:
exynos_drm_component_del(dev, EXYNOS_DEVICE_TYPE_CONNECTOR);

return NULL;
}

int exynos_dpi_remove(struct device *dev)
Expand All @@ -327,5 +341,7 @@ int exynos_dpi_remove(struct device *dev)
encoder->funcs->destroy(encoder);
drm_connector_cleanup(&ctx->connector);

exynos_drm_component_del(dev, EXYNOS_DEVICE_TYPE_CONNECTOR);

return 0;
}
138 changes: 116 additions & 22 deletions drivers/gpu/drm/exynos/exynos_drm_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ static LIST_HEAD(drm_component_list);

struct component_dev {
struct list_head list;
struct device *dev;
struct device *crtc_dev;
struct device *conn_dev;
enum exynos_drm_output_type out_type;
unsigned int dev_type_flag;
};

static int exynos_drm_load(struct drm_device *dev, unsigned long flags)
Expand Down Expand Up @@ -382,22 +385,65 @@ static const struct dev_pm_ops exynos_drm_pm_ops = {
};

int exynos_drm_component_add(struct device *dev,
const struct component_ops *ops)
enum exynos_drm_device_type dev_type,
enum exynos_drm_output_type out_type)
{
struct component_dev *cdev;
int ret;

if (dev_type != EXYNOS_DEVICE_TYPE_CRTC &&
dev_type != EXYNOS_DEVICE_TYPE_CONNECTOR) {
DRM_ERROR("invalid device type.\n");
return -EINVAL;
}

mutex_lock(&drm_component_lock);

/*
* Make sure to check if there is a component which has two device
* objects, for connector and for encoder/connector.
* It should make sure that crtc and encoder/connector drivers are
* ready before exynos drm core binds them.
*/
list_for_each_entry(cdev, &drm_component_list, list) {
if (cdev->out_type == out_type) {
/*
* If crtc and encoder/connector device objects are
* added already just return.
*/
if (cdev->dev_type_flag == (EXYNOS_DEVICE_TYPE_CRTC |
EXYNOS_DEVICE_TYPE_CONNECTOR)) {
mutex_unlock(&drm_component_lock);
return 0;
}

if (dev_type == EXYNOS_DEVICE_TYPE_CRTC) {
cdev->crtc_dev = dev;
cdev->dev_type_flag |= dev_type;
}

if (dev_type == EXYNOS_DEVICE_TYPE_CONNECTOR) {
cdev->conn_dev = dev;
cdev->dev_type_flag |= dev_type;
}

mutex_unlock(&drm_component_lock);
return 0;
}
}

mutex_unlock(&drm_component_lock);

cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
if (!cdev)
return -ENOMEM;

ret = component_add(dev, ops);
if (ret) {
kfree(cdev);
return ret;
}
if (dev_type == EXYNOS_DEVICE_TYPE_CRTC)
cdev->crtc_dev = dev;
if (dev_type == EXYNOS_DEVICE_TYPE_CONNECTOR)
cdev->conn_dev = dev;

cdev->dev = dev;
cdev->out_type = out_type;
cdev->dev_type_flag = dev_type;

mutex_lock(&drm_component_lock);
list_add_tail(&cdev->list, &drm_component_list);
Expand All @@ -407,23 +453,40 @@ int exynos_drm_component_add(struct device *dev,
}

void exynos_drm_component_del(struct device *dev,
const struct component_ops *ops)
enum exynos_drm_device_type dev_type)
{
struct component_dev *cdev, *next;

mutex_lock(&drm_component_lock);

list_for_each_entry_safe(cdev, next, &drm_component_list, list) {
if (dev == cdev->dev) {
if (dev_type == EXYNOS_DEVICE_TYPE_CRTC) {
if (cdev->crtc_dev == dev) {
cdev->crtc_dev = NULL;
cdev->dev_type_flag &= ~dev_type;
}
}

if (dev_type == EXYNOS_DEVICE_TYPE_CONNECTOR) {
if (cdev->conn_dev == dev) {
cdev->conn_dev = NULL;
cdev->dev_type_flag &= ~dev_type;
}
}

/*
* Release cdev object only in case that both of crtc and
* encoder/connector device objects are NULL.
*/
if (!cdev->crtc_dev && !cdev->conn_dev) {
list_del(&cdev->list);
kfree(cdev);
break;
}

break;
}

mutex_unlock(&drm_component_lock);

component_del(dev, ops);
}

static int compare_of(struct device *dev, void *data)
Expand All @@ -433,29 +496,60 @@ static int compare_of(struct device *dev, void *data)

static int exynos_drm_add_components(struct device *dev, struct master *m)
{
unsigned int attached_cnt = 0;
struct component_dev *cdev;
unsigned int attach_cnt = 0;

mutex_lock(&drm_component_lock);

list_for_each_entry(cdev, &drm_component_list, list) {
int ret;

/*
* Add components to master only in case that crtc and
* encoder/connector device objects exist.
*/
if (!cdev->crtc_dev || !cdev->conn_dev)
continue;

attach_cnt++;

mutex_unlock(&drm_component_lock);

ret = component_master_add_child(m, compare_of, cdev->dev);
if (!ret)
attached_cnt++;
/*
* fimd and dpi modules have same device object so add
* only crtc device object in this case.
*
* TODO. if dpi module follows driver-model driver then
* below codes can be removed.
*/
if (cdev->crtc_dev == cdev->conn_dev) {
ret = component_master_add_child(m, compare_of,
cdev->crtc_dev);
if (ret < 0)
return ret;

goto out_lock;
}

/*
* Do not chage below call order.
* crtc device first should be added to master because
* connector/encoder need pipe number of crtc when they
* are created.
*/
ret = component_master_add_child(m, compare_of, cdev->crtc_dev);
ret |= component_master_add_child(m, compare_of,
cdev->conn_dev);
if (ret < 0)
return ret;

out_lock:
mutex_lock(&drm_component_lock);
}

mutex_unlock(&drm_component_lock);

if (!attached_cnt)
return -ENXIO;

return 0;
return attach_cnt ? 0 : -ENODEV;
}

static int exynos_drm_bind(struct device *dev)
Expand Down
13 changes: 10 additions & 3 deletions drivers/gpu/drm/exynos/exynos_drm_drv.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ struct drm_connector;

extern unsigned int drm_vblank_offdelay;

/* This enumerates device type. */
enum exynos_drm_device_type {
EXYNOS_DEVICE_TYPE_NONE,
EXYNOS_DEVICE_TYPE_CRTC,
EXYNOS_DEVICE_TYPE_CONNECTOR,
};

/* this enumerates display type. */
enum exynos_drm_output_type {
EXYNOS_DISPLAY_TYPE_NONE,
Expand Down Expand Up @@ -354,12 +361,12 @@ void exynos_drm_remove_vidi(void);
int exynos_drm_create_enc_conn(struct drm_device *dev,
struct exynos_drm_display *display);

struct component_ops;
int exynos_drm_component_add(struct device *dev,
const struct component_ops *ops);
enum exynos_drm_device_type dev_type,
enum exynos_drm_output_type out_type);

void exynos_drm_component_del(struct device *dev,
const struct component_ops *ops);
enum exynos_drm_device_type dev_type);

extern struct platform_driver fimd_driver;
extern struct platform_driver dp_driver;
Expand Down
Loading

0 comments on commit df5225b

Please sign in to comment.