Commit 060530f1 authored by Rob Clark's avatar Rob Clark

drm/msm: use componentised device support

Signed-off-by: default avatarRob Clark <robdclark@gmail.com>
parent 4e1cbaa3
...@@ -41,8 +41,6 @@ MODULE_PARM_DESC(hang_debug, "Dump registers when hang is detected (can be slow! ...@@ -41,8 +41,6 @@ MODULE_PARM_DESC(hang_debug, "Dump registers when hang is detected (can be slow!
module_param_named(hang_debug, hang_debug, bool, 0600); module_param_named(hang_debug, hang_debug, bool, 0600);
static void a3xx_dump(struct msm_gpu *gpu); static void a3xx_dump(struct msm_gpu *gpu);
static struct platform_device *a3xx_pdev;
static void a3xx_me_init(struct msm_gpu *gpu) static void a3xx_me_init(struct msm_gpu *gpu)
{ {
struct msm_ringbuffer *ring = gpu->rb; struct msm_ringbuffer *ring = gpu->rb;
...@@ -320,7 +318,6 @@ static void a3xx_destroy(struct msm_gpu *gpu) ...@@ -320,7 +318,6 @@ static void a3xx_destroy(struct msm_gpu *gpu)
ocmem_free(OCMEM_GRAPHICS, a3xx_gpu->ocmem_hdl); ocmem_free(OCMEM_GRAPHICS, a3xx_gpu->ocmem_hdl);
#endif #endif
put_device(&a3xx_gpu->pdev->dev);
kfree(a3xx_gpu); kfree(a3xx_gpu);
} }
...@@ -473,7 +470,8 @@ struct msm_gpu *a3xx_gpu_init(struct drm_device *dev) ...@@ -473,7 +470,8 @@ struct msm_gpu *a3xx_gpu_init(struct drm_device *dev)
struct a3xx_gpu *a3xx_gpu = NULL; struct a3xx_gpu *a3xx_gpu = NULL;
struct adreno_gpu *adreno_gpu; struct adreno_gpu *adreno_gpu;
struct msm_gpu *gpu; struct msm_gpu *gpu;
struct platform_device *pdev = a3xx_pdev; struct msm_drm_private *priv = dev->dev_private;
struct platform_device *pdev = priv->gpu_pdev;
struct adreno_platform_config *config; struct adreno_platform_config *config;
int ret; int ret;
...@@ -494,7 +492,6 @@ struct msm_gpu *a3xx_gpu_init(struct drm_device *dev) ...@@ -494,7 +492,6 @@ struct msm_gpu *a3xx_gpu_init(struct drm_device *dev)
adreno_gpu = &a3xx_gpu->base; adreno_gpu = &a3xx_gpu->base;
gpu = &adreno_gpu->base; gpu = &adreno_gpu->base;
get_device(&pdev->dev);
a3xx_gpu->pdev = pdev; a3xx_gpu->pdev = pdev;
gpu->fast_rate = config->fast_rate; gpu->fast_rate = config->fast_rate;
...@@ -556,17 +553,24 @@ struct msm_gpu *a3xx_gpu_init(struct drm_device *dev) ...@@ -556,17 +553,24 @@ struct msm_gpu *a3xx_gpu_init(struct drm_device *dev)
# include <mach/kgsl.h> # include <mach/kgsl.h>
#endif #endif
static int a3xx_probe(struct platform_device *pdev) static void set_gpu_pdev(struct drm_device *dev,
struct platform_device *pdev)
{
struct msm_drm_private *priv = dev->dev_private;
priv->gpu_pdev = pdev;
}
static int a3xx_bind(struct device *dev, struct device *master, void *data)
{ {
static struct adreno_platform_config config = {}; static struct adreno_platform_config config = {};
#ifdef CONFIG_OF #ifdef CONFIG_OF
struct device_node *child, *node = pdev->dev.of_node; struct device_node *child, *node = dev->of_node;
u32 val; u32 val;
int ret; int ret;
ret = of_property_read_u32(node, "qcom,chipid", &val); ret = of_property_read_u32(node, "qcom,chipid", &val);
if (ret) { if (ret) {
dev_err(&pdev->dev, "could not find chipid: %d\n", ret); dev_err(dev, "could not find chipid: %d\n", ret);
return ret; return ret;
} }
...@@ -582,7 +586,7 @@ static int a3xx_probe(struct platform_device *pdev) ...@@ -582,7 +586,7 @@ static int a3xx_probe(struct platform_device *pdev)
for_each_child_of_node(child, pwrlvl) { for_each_child_of_node(child, pwrlvl) {
ret = of_property_read_u32(pwrlvl, "qcom,gpu-freq", &val); ret = of_property_read_u32(pwrlvl, "qcom,gpu-freq", &val);
if (ret) { if (ret) {
dev_err(&pdev->dev, "could not find gpu-freq: %d\n", ret); dev_err(dev, "could not find gpu-freq: %d\n", ret);
return ret; return ret;
} }
config.fast_rate = max(config.fast_rate, val); config.fast_rate = max(config.fast_rate, val);
...@@ -592,12 +596,12 @@ static int a3xx_probe(struct platform_device *pdev) ...@@ -592,12 +596,12 @@ static int a3xx_probe(struct platform_device *pdev)
} }
if (!config.fast_rate) { if (!config.fast_rate) {
dev_err(&pdev->dev, "could not find clk rates\n"); dev_err(dev, "could not find clk rates\n");
return -ENXIO; return -ENXIO;
} }
#else #else
struct kgsl_device_platform_data *pdata = pdev->dev.platform_data; struct kgsl_device_platform_data *pdata = dev->platform_data;
uint32_t version = socinfo_get_version(); uint32_t version = socinfo_get_version();
if (cpu_is_apq8064ab()) { if (cpu_is_apq8064ab()) {
config.fast_rate = 450000000; config.fast_rate = 450000000;
...@@ -643,14 +647,30 @@ static int a3xx_probe(struct platform_device *pdev) ...@@ -643,14 +647,30 @@ static int a3xx_probe(struct platform_device *pdev)
config.bus_scale_table = pdata->bus_scale_table; config.bus_scale_table = pdata->bus_scale_table;
# endif # endif
#endif #endif
pdev->dev.platform_data = &config; dev->platform_data = &config;
a3xx_pdev = pdev; set_gpu_pdev(dev_get_drvdata(master), to_platform_device(dev));
return 0; return 0;
} }
static void a3xx_unbind(struct device *dev, struct device *master,
void *data)
{
set_gpu_pdev(dev_get_drvdata(master), NULL);
}
static const struct component_ops a3xx_ops = {
.bind = a3xx_bind,
.unbind = a3xx_unbind,
};
static int a3xx_probe(struct platform_device *pdev)
{
return component_add(&pdev->dev, &a3xx_ops);
}
static int a3xx_remove(struct platform_device *pdev) static int a3xx_remove(struct platform_device *pdev)
{ {
a3xx_pdev = NULL; component_del(&pdev->dev, &a3xx_ops);
return 0; return 0;
} }
...@@ -658,7 +678,6 @@ static const struct of_device_id dt_match[] = { ...@@ -658,7 +678,6 @@ static const struct of_device_id dt_match[] = {
{ .compatible = "qcom,kgsl-3d0" }, { .compatible = "qcom,kgsl-3d0" },
{} {}
}; };
MODULE_DEVICE_TABLE(of, dt_match);
static struct platform_driver a3xx_driver = { static struct platform_driver a3xx_driver = {
.probe = a3xx_probe, .probe = a3xx_probe,
......
...@@ -17,8 +17,6 @@ ...@@ -17,8 +17,6 @@
#include "hdmi.h" #include "hdmi.h"
static struct platform_device *hdmi_pdev;
void hdmi_set_mode(struct hdmi *hdmi, bool power_on) void hdmi_set_mode(struct hdmi *hdmi, bool power_on)
{ {
uint32_t ctrl = 0; uint32_t ctrl = 0;
...@@ -68,8 +66,6 @@ void hdmi_destroy(struct kref *kref) ...@@ -68,8 +66,6 @@ void hdmi_destroy(struct kref *kref)
hdmi_i2c_destroy(hdmi->i2c); hdmi_i2c_destroy(hdmi->i2c);
platform_set_drvdata(hdmi->pdev, NULL); platform_set_drvdata(hdmi->pdev, NULL);
put_device(&hdmi->pdev->dev);
} }
/* initialize connector */ /* initialize connector */
...@@ -77,7 +73,7 @@ struct hdmi *hdmi_init(struct drm_device *dev, struct drm_encoder *encoder) ...@@ -77,7 +73,7 @@ struct hdmi *hdmi_init(struct drm_device *dev, struct drm_encoder *encoder)
{ {
struct hdmi *hdmi = NULL; struct hdmi *hdmi = NULL;
struct msm_drm_private *priv = dev->dev_private; struct msm_drm_private *priv = dev->dev_private;
struct platform_device *pdev = hdmi_pdev; struct platform_device *pdev = priv->hdmi_pdev;
struct hdmi_platform_config *config; struct hdmi_platform_config *config;
int i, ret; int i, ret;
...@@ -97,8 +93,6 @@ struct hdmi *hdmi_init(struct drm_device *dev, struct drm_encoder *encoder) ...@@ -97,8 +93,6 @@ struct hdmi *hdmi_init(struct drm_device *dev, struct drm_encoder *encoder)
kref_init(&hdmi->refcount); kref_init(&hdmi->refcount);
get_device(&pdev->dev);
hdmi->dev = dev; hdmi->dev = dev;
hdmi->pdev = pdev; hdmi->pdev = pdev;
hdmi->config = config; hdmi->config = config;
...@@ -255,17 +249,24 @@ struct hdmi *hdmi_init(struct drm_device *dev, struct drm_encoder *encoder) ...@@ -255,17 +249,24 @@ struct hdmi *hdmi_init(struct drm_device *dev, struct drm_encoder *encoder)
#include <linux/of_gpio.h> #include <linux/of_gpio.h>
static int hdmi_dev_probe(struct platform_device *pdev) static void set_hdmi_pdev(struct drm_device *dev,
struct platform_device *pdev)
{
struct msm_drm_private *priv = dev->dev_private;
priv->hdmi_pdev = pdev;
}
static int hdmi_bind(struct device *dev, struct device *master, void *data)
{ {
static struct hdmi_platform_config config = {}; static struct hdmi_platform_config config = {};
#ifdef CONFIG_OF #ifdef CONFIG_OF
struct device_node *of_node = pdev->dev.of_node; struct device_node *of_node = dev->of_node;
int get_gpio(const char *name) int get_gpio(const char *name)
{ {
int gpio = of_get_named_gpio(of_node, name, 0); int gpio = of_get_named_gpio(of_node, name, 0);
if (gpio < 0) { if (gpio < 0) {
dev_err(&pdev->dev, "failed to get gpio: %s (%d)\n", dev_err(dev, "failed to get gpio: %s (%d)\n",
name, gpio); name, gpio);
gpio = -1; gpio = -1;
} }
...@@ -342,14 +343,30 @@ static int hdmi_dev_probe(struct platform_device *pdev) ...@@ -342,14 +343,30 @@ static int hdmi_dev_probe(struct platform_device *pdev)
config.mux_sel_gpio = -1; config.mux_sel_gpio = -1;
} }
#endif #endif
pdev->dev.platform_data = &config; dev->platform_data = &config;
hdmi_pdev = pdev; set_hdmi_pdev(dev_get_drvdata(master), to_platform_device(dev));
return 0; return 0;
} }
static void hdmi_unbind(struct device *dev, struct device *master,
void *data)
{
set_hdmi_pdev(dev_get_drvdata(master), NULL);
}
static const struct component_ops hdmi_ops = {
.bind = hdmi_bind,
.unbind = hdmi_unbind,
};
static int hdmi_dev_probe(struct platform_device *pdev)
{
return component_add(&pdev->dev, &hdmi_ops);
}
static int hdmi_dev_remove(struct platform_device *pdev) static int hdmi_dev_remove(struct platform_device *pdev)
{ {
hdmi_pdev = NULL; component_del(&pdev->dev, &hdmi_ops);
return 0; return 0;
} }
...@@ -357,7 +374,6 @@ static const struct of_device_id dt_match[] = { ...@@ -357,7 +374,6 @@ static const struct of_device_id dt_match[] = {
{ .compatible = "qcom,hdmi-tx" }, { .compatible = "qcom,hdmi-tx" },
{} {}
}; };
MODULE_DEVICE_TABLE(of, dt_match);
static struct platform_driver hdmi_driver = { static struct platform_driver hdmi_driver = {
.probe = hdmi_dev_probe, .probe = hdmi_dev_probe,
......
...@@ -56,6 +56,10 @@ static char *vram; ...@@ -56,6 +56,10 @@ static char *vram;
MODULE_PARM_DESC(vram, "Configure VRAM size (for devices without IOMMU/GPUMMU"); MODULE_PARM_DESC(vram, "Configure VRAM size (for devices without IOMMU/GPUMMU");
module_param(vram, charp, 0); module_param(vram, charp, 0);
/*
* Util/helpers:
*/
void __iomem *msm_ioremap(struct platform_device *pdev, const char *name, void __iomem *msm_ioremap(struct platform_device *pdev, const char *name,
const char *dbgname) const char *dbgname)
{ {
...@@ -143,6 +147,8 @@ static int msm_unload(struct drm_device *dev) ...@@ -143,6 +147,8 @@ static int msm_unload(struct drm_device *dev)
priv->vram.paddr, &attrs); priv->vram.paddr, &attrs);
} }
component_unbind_all(dev->dev, dev);
dev->dev_private = NULL; dev->dev_private = NULL;
kfree(priv); kfree(priv);
...@@ -175,6 +181,7 @@ static int msm_load(struct drm_device *dev, unsigned long flags) ...@@ -175,6 +181,7 @@ static int msm_load(struct drm_device *dev, unsigned long flags)
struct msm_kms *kms; struct msm_kms *kms;
int ret; int ret;
priv = kzalloc(sizeof(*priv), GFP_KERNEL); priv = kzalloc(sizeof(*priv), GFP_KERNEL);
if (!priv) { if (!priv) {
dev_err(dev->dev, "failed to allocate private data\n"); dev_err(dev->dev, "failed to allocate private data\n");
...@@ -226,6 +233,13 @@ static int msm_load(struct drm_device *dev, unsigned long flags) ...@@ -226,6 +233,13 @@ static int msm_load(struct drm_device *dev, unsigned long flags)
(uint32_t)(priv->vram.paddr + size)); (uint32_t)(priv->vram.paddr + size));
} }
platform_set_drvdata(pdev, dev);
/* Bind all our sub-components: */
ret = component_bind_all(dev->dev, dev);
if (ret)
return ret;
switch (get_mdp_ver(pdev)) { switch (get_mdp_ver(pdev)) {
case 4: case 4:
kms = mdp4_kms_init(dev); kms = mdp4_kms_init(dev);
...@@ -281,8 +295,6 @@ static int msm_load(struct drm_device *dev, unsigned long flags) ...@@ -281,8 +295,6 @@ static int msm_load(struct drm_device *dev, unsigned long flags)
goto fail; goto fail;
} }
platform_set_drvdata(pdev, dev);
#ifdef CONFIG_DRM_MSM_FBDEV #ifdef CONFIG_DRM_MSM_FBDEV
priv->fbdev = msm_fbdev_init(dev); priv->fbdev = msm_fbdev_init(dev);
#endif #endif
...@@ -823,6 +835,98 @@ static const struct dev_pm_ops msm_pm_ops = { ...@@ -823,6 +835,98 @@ static const struct dev_pm_ops msm_pm_ops = {
SET_SYSTEM_SLEEP_PM_OPS(msm_pm_suspend, msm_pm_resume) SET_SYSTEM_SLEEP_PM_OPS(msm_pm_suspend, msm_pm_resume)
}; };
/*
* Componentized driver support:
*/
#ifdef CONFIG_OF
/* NOTE: the CONFIG_OF case duplicates the same code as exynos or imx
* (or probably any other).. so probably some room for some helpers
*/
static int compare_of(struct device *dev, void *data)
{
return dev->of_node == data;
}
static int msm_drm_add_components(struct device *master, struct master *m)
{
struct device_node *np = master->of_node;
unsigned i;
int ret;
for (i = 0; ; i++) {
struct device_node *node;
node = of_parse_phandle(np, "connectors", i);
if (!node)
break;
ret = component_master_add_child(m, compare_of, node);
of_node_put(node);
if (ret)
return ret;
}
return 0;
}
#else
static int compare_dev(struct device *dev, void *data)
{
return dev == data;
}
static int msm_drm_add_components(struct device *master, struct master *m)
{
/* For non-DT case, it kinda sucks. We don't actually have a way
* to know whether or not we are waiting for certain devices (or if
* they are simply not present). But for non-DT we only need to
* care about apq8064/apq8060/etc (all mdp4/a3xx):
*/
static const char *devnames[] = {
"hdmi_msm.0", "kgsl-3d0.0",
};
int i;
DBG("Adding components..");
for (i = 0; i < ARRAY_SIZE(devnames); i++) {
struct device *dev;
int ret;
dev = bus_find_device_by_name(&platform_bus_type,
NULL, devnames[i]);
if (!dev) {
dev_info(master, "still waiting for %s\n", devnames[i]);
return -EPROBE_DEFER;
}
ret = component_master_add_child(m, compare_dev, dev);
if (ret) {
DBG("could not add child: %d", ret);
return ret;
}
}
return 0;
}
#endif
static int msm_drm_bind(struct device *dev)
{
return drm_platform_init(&msm_driver, to_platform_device(dev));
}
static void msm_drm_unbind(struct device *dev)
{
drm_put_dev(platform_get_drvdata(to_platform_device(dev)));
}
static const struct component_master_ops msm_drm_ops = {
.add_components = msm_drm_add_components,
.bind = msm_drm_bind,
.unbind = msm_drm_unbind,
};
/* /*
* Platform driver: * Platform driver:
*/ */
...@@ -830,12 +934,12 @@ static const struct dev_pm_ops msm_pm_ops = { ...@@ -830,12 +934,12 @@ static const struct dev_pm_ops msm_pm_ops = {
static int msm_pdev_probe(struct platform_device *pdev) static int msm_pdev_probe(struct platform_device *pdev)
{ {
pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32); pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
return drm_platform_init(&msm_driver, pdev); return component_master_add(&pdev->dev, &msm_drm_ops);
} }
static int msm_pdev_remove(struct platform_device *pdev) static int msm_pdev_remove(struct platform_device *pdev)
{ {
drm_put_dev(platform_get_drvdata(pdev)); component_master_del(&pdev->dev, &msm_drm_ops);
return 0; return 0;
} }
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <linux/clk.h> #include <linux/clk.h>
#include <linux/cpufreq.h> #include <linux/cpufreq.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/component.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/pm.h> #include <linux/pm.h>
#include <linux/pm_runtime.h> #include <linux/pm_runtime.h>
...@@ -69,6 +70,9 @@ struct msm_drm_private { ...@@ -69,6 +70,9 @@ struct msm_drm_private {
struct msm_kms *kms; struct msm_kms *kms;
/* subordinate devices, if present: */
struct platform_device *hdmi_pdev, *gpu_pdev;
/* when we have more than one 'msm_gpu' these need to be an array: */ /* when we have more than one 'msm_gpu' these need to be an array: */
struct msm_gpu *gpu; struct msm_gpu *gpu;
struct msm_file_private *lastctx; struct msm_file_private *lastctx;
......
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