Release 4.11 drivers/gpu/drm/rockchip/rockchip_drm_drv.c
/*
* Copyright (C) Fuzhou Rockchip Electronics Co.Ltd
* Author:Mark Yao <mark.yao@rock-chips.com>
*
* based on exynos_drm_drv.c
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include <drm/drmP.h>
#include <drm/drm_crtc_helper.h>
#include <drm/drm_fb_helper.h>
#include <drm/drm_gem_cma_helper.h>
#include <drm/drm_of.h>
#include <linux/dma-mapping.h>
#include <linux/dma-iommu.h>
#include <linux/pm_runtime.h>
#include <linux/module.h>
#include <linux/of_graph.h>
#include <linux/component.h>
#include <linux/console.h>
#include <linux/iommu.h>
#include "rockchip_drm_drv.h"
#include "rockchip_drm_fb.h"
#include "rockchip_drm_fbdev.h"
#include "rockchip_drm_gem.h"
#define DRIVER_NAME "rockchip"
#define DRIVER_DESC "RockChip Soc DRM"
#define DRIVER_DATE "20140818"
#define DRIVER_MAJOR 1
#define DRIVER_MINOR 0
static bool is_support_iommu = true;
static struct drm_driver rockchip_drm_driver;
/*
* Attach a (component) device to the shared drm dma mapping from master drm
* device. This is used by the VOPs to map GEM buffers to a common DMA
* mapping.
*/
int rockchip_drm_dma_attach_device(struct drm_device *drm_dev,
struct device *dev)
{
struct rockchip_drm_private *private = drm_dev->dev_private;
int ret;
if (!is_support_iommu)
return 0;
ret = iommu_attach_device(private->domain, dev);
if (ret) {
dev_err(dev, "Failed to attach iommu device\n");
return ret;
}
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Mark Yao | 49 | 75.38% | 2 | 66.67% |
Shunqian Zheng | 16 | 24.62% | 1 | 33.33% |
Total | 65 | 100.00% | 3 | 100.00% |
void rockchip_drm_dma_detach_device(struct drm_device *drm_dev,
struct device *dev)
{
struct rockchip_drm_private *private = drm_dev->dev_private;
struct iommu_domain *domain = private->domain;
if (!is_support_iommu)
return;
iommu_detach_device(domain, dev);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Mark Yao | 25 | 54.35% | 2 | 66.67% |
Shunqian Zheng | 21 | 45.65% | 1 | 33.33% |
Total | 46 | 100.00% | 3 | 100.00% |
int rockchip_register_crtc_funcs(struct drm_crtc *crtc,
const struct rockchip_crtc_funcs *crtc_funcs)
{
int pipe = drm_crtc_index(crtc);
struct rockchip_drm_private *priv = crtc->dev->dev_private;
if (pipe >= ROCKCHIP_MAX_CRTC)
return -EINVAL;
priv->crtc_funcs[pipe] = crtc_funcs;
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Mark Yao | 56 | 98.25% | 2 | 66.67% |
Dan Carpenter | 1 | 1.75% | 1 | 33.33% |
Total | 57 | 100.00% | 3 | 100.00% |
void rockchip_unregister_crtc_funcs(struct drm_crtc *crtc)
{
int pipe = drm_crtc_index(crtc);
struct rockchip_drm_private *priv = crtc->dev->dev_private;
if (pipe >= ROCKCHIP_MAX_CRTC)
return;
priv->crtc_funcs[pipe] = NULL;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Mark Yao | 44 | 97.78% | 2 | 66.67% |
Dan Carpenter | 1 | 2.22% | 1 | 33.33% |
Total | 45 | 100.00% | 3 | 100.00% |
static int rockchip_drm_crtc_enable_vblank(struct drm_device *dev,
unsigned int pipe)
{
struct rockchip_drm_private *priv = dev->dev_private;
struct drm_crtc *crtc = drm_crtc_from_index(dev, pipe);
if (crtc && priv->crtc_funcs[pipe] &&
priv->crtc_funcs[pipe]->enable_vblank)
return priv->crtc_funcs[pipe]->enable_vblank(crtc);
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Mark Yao | 70 | 97.22% | 1 | 33.33% |
Thierry Reding | 1 | 1.39% | 1 | 33.33% |
Shawn Guo | 1 | 1.39% | 1 | 33.33% |
Total | 72 | 100.00% | 3 | 100.00% |
static void rockchip_drm_crtc_disable_vblank(struct drm_device *dev,
unsigned int pipe)
{
struct rockchip_drm_private *priv = dev->dev_private;
struct drm_crtc *crtc = drm_crtc_from_index(dev, pipe);
if (crtc && priv->crtc_funcs[pipe] &&
priv->crtc_funcs[pipe]->enable_vblank)
priv->crtc_funcs[pipe]->disable_vblank(crtc);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Mark Yao | 66 | 97.06% | 1 | 33.33% |
Thierry Reding | 1 | 1.47% | 1 | 33.33% |
Shawn Guo | 1 | 1.47% | 1 | 33.33% |
Total | 68 | 100.00% | 3 | 100.00% |
static int rockchip_drm_init_iommu(struct drm_device *drm_dev)
{
struct rockchip_drm_private *private = drm_dev->dev_private;
struct iommu_domain_geometry *geometry;
u64 start, end;
if (!is_support_iommu)
return 0;
private->domain = iommu_domain_alloc(&platform_bus_type);
if (!private->domain)
return -ENOMEM;
geometry = &private->domain->geometry;
start = geometry->aperture_start;
end = geometry->aperture_end;
DRM_DEBUG("IOMMU context initialized (aperture: %#llx-%#llx)\n",
start, end);
drm_mm_init(&private->mm, start, end - start + 1);
mutex_init(&private->mm_lock);
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Shunqian Zheng | 116 | 100.00% | 1 | 100.00% |
Total | 116 | 100.00% | 1 | 100.00% |
static void rockchip_iommu_cleanup(struct drm_device *drm_dev)
{
struct rockchip_drm_private *private = drm_dev->dev_private;
if (!is_support_iommu)
return;
drm_mm_takedown(&private->mm);
iommu_domain_free(private->domain);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Shunqian Zheng | 41 | 100.00% | 1 | 100.00% |
Total | 41 | 100.00% | 1 | 100.00% |
static int rockchip_drm_bind(struct device *dev)
{
struct drm_device *drm_dev;
struct rockchip_drm_private *private;
int ret;
drm_dev = drm_dev_alloc(&rockchip_drm_driver, dev);
if (IS_ERR(drm_dev))
return PTR_ERR(drm_dev);
dev_set_drvdata(dev, drm_dev);
private = devm_kzalloc(drm_dev->dev, sizeof(*private), GFP_KERNEL);
if (!private) {
ret = -ENOMEM;
goto err_free;
}
drm_dev->dev_private = private;
INIT_LIST_HEAD(&private->psr_list);
spin_lock_init(&private->psr_list_lock);
drm_mode_config_init(drm_dev);
rockchip_drm_mode_config_init(drm_dev);
ret = rockchip_drm_init_iommu(drm_dev);
if (ret)
goto err_config_cleanup;
/* Try to bind all sub drivers. */
ret = component_bind_all(dev, drm_dev);
if (ret)
goto err_iommu_cleanup;
/* init kms poll for handling hpd */
drm_kms_helper_poll_init(drm_dev);
/*
* enable drm irq mode.
* - with irq_enabled = true, we can use the vblank feature.
*/
drm_dev->irq_enabled = true;
ret = drm_vblank_init(drm_dev, ROCKCHIP_MAX_CRTC);
if (ret)
goto err_kms_helper_poll_fini;
drm_mode_config_reset(drm_dev);
ret = rockchip_drm_fbdev_init(drm_dev);
if (ret)
goto err_vblank_cleanup;
ret = drm_dev_register(drm_dev, 0);
if (ret)
goto err_fbdev_fini;
return 0;
err_fbdev_fini:
rockchip_drm_fbdev_fini(drm_dev);
err_vblank_cleanup:
drm_vblank_cleanup(drm_dev);
err_kms_helper_poll_fini:
drm_kms_helper_poll_fini(drm_dev);
component_unbind_all(dev, drm_dev);
err_iommu_cleanup:
rockchip_iommu_cleanup(drm_dev);
err_config_cleanup:
drm_mode_config_cleanup(drm_dev);
drm_dev->dev_private = NULL;
err_free:
drm_dev_unref(drm_dev);
return ret;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Mark Yao | 175 | 63.87% | 2 | 25.00% |
Tomeu Vizoso | 45 | 16.42% | 1 | 12.50% |
Tomasz Figa | 24 | 8.76% | 1 | 12.50% |
Yakir Yang | 14 | 5.11% | 1 | 12.50% |
Shunqian Zheng | 7 | 2.55% | 1 | 12.50% |
Tom Gundersen | 7 | 2.55% | 1 | 12.50% |
Sean Paul | 2 | 0.73% | 1 | 12.50% |
Total | 274 | 100.00% | 8 | 100.00% |
static void rockchip_drm_unbind(struct device *dev)
{
struct drm_device *drm_dev = dev_get_drvdata(dev);
rockchip_drm_fbdev_fini(drm_dev);
drm_vblank_cleanup(drm_dev);
drm_kms_helper_poll_fini(drm_dev);
component_unbind_all(dev, drm_dev);
rockchip_iommu_cleanup(drm_dev);
drm_mode_config_cleanup(drm_dev);
drm_dev->dev_private = NULL;
drm_dev_unregister(drm_dev);
drm_dev_unref(drm_dev);
dev_set_drvdata(dev, NULL);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Mark Yao | 48 | 63.16% | 1 | 33.33% |
Tomeu Vizoso | 26 | 34.21% | 1 | 33.33% |
Shunqian Zheng | 2 | 2.63% | 1 | 33.33% |
Total | 76 | 100.00% | 3 | 100.00% |
static void rockchip_drm_lastclose(struct drm_device *dev)
{
struct rockchip_drm_private *priv = dev->dev_private;
drm_fb_helper_restore_fbdev_mode_unlocked(&priv->fbdev_helper);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Mark Yao | 27 | 96.43% | 1 | 50.00% |
John Keeping | 1 | 3.57% | 1 | 50.00% |
Total | 28 | 100.00% | 2 | 100.00% |
static const struct file_operations rockchip_drm_driver_fops = {
.owner = THIS_MODULE,
.open = drm_open,
.mmap = rockchip_gem_mmap,
.poll = drm_poll,
.read = drm_read,
.unlocked_ioctl = drm_ioctl,
.compat_ioctl = drm_compat_ioctl,
.release = drm_release,
};
static struct drm_driver rockchip_drm_driver = {
.driver_features = DRIVER_MODESET | DRIVER_GEM |
DRIVER_PRIME | DRIVER_ATOMIC,
.lastclose = rockchip_drm_lastclose,
.get_vblank_counter = drm_vblank_no_hw_counter,
.enable_vblank = rockchip_drm_crtc_enable_vblank,
.disable_vblank = rockchip_drm_crtc_disable_vblank,
.gem_vm_ops = &drm_gem_cma_vm_ops,
.gem_free_object_unlocked = rockchip_gem_free_object,
.dumb_create = rockchip_gem_dumb_create,
.dumb_map_offset = rockchip_gem_dumb_map_offset,
.dumb_destroy = drm_gem_dumb_destroy,
.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
.gem_prime_import = drm_gem_prime_import,
.gem_prime_export = drm_gem_prime_export,
.gem_prime_get_sg_table = rockchip_gem_prime_get_sg_table,
.gem_prime_vmap = rockchip_gem_prime_vmap,
.gem_prime_vunmap = rockchip_gem_prime_vunmap,
.gem_prime_mmap = rockchip_gem_mmap_buf,
.fops = &rockchip_drm_driver_fops,
.name = DRIVER_NAME,
.desc = DRIVER_DESC,
.date = DRIVER_DATE,
.major = DRIVER_MAJOR,
.minor = DRIVER_MINOR,
};
#ifdef CONFIG_PM_SLEEP
static void rockchip_drm_fb_suspend(struct drm_device *drm)
{
struct rockchip_drm_private *priv = drm->dev_private;
console_lock();
drm_fb_helper_set_suspend(&priv->fbdev_helper, 1);
console_unlock();
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Tomeu Vizoso | 35 | 97.22% | 1 | 50.00% |
Baoyou Xie | 1 | 2.78% | 1 | 50.00% |
Total | 36 | 100.00% | 2 | 100.00% |
static void rockchip_drm_fb_resume(struct drm_device *drm)
{
struct rockchip_drm_private *priv = drm->dev_private;
console_lock();
drm_fb_helper_set_suspend(&priv->fbdev_helper, 0);
console_unlock();
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Tomeu Vizoso | 35 | 97.22% | 1 | 50.00% |
Baoyou Xie | 1 | 2.78% | 1 | 50.00% |
Total | 36 | 100.00% | 2 | 100.00% |
static int rockchip_drm_sys_suspend(struct device *dev)
{
struct drm_device *drm = dev_get_drvdata(dev);
struct rockchip_drm_private *priv = drm->dev_private;
drm_kms_helper_poll_disable(drm);
rockchip_drm_fb_suspend(drm);
priv->state = drm_atomic_helper_suspend(drm);
if (IS_ERR(priv->state)) {
rockchip_drm_fb_resume(drm);
drm_kms_helper_poll_enable(drm);
return PTR_ERR(priv->state);
}
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Mark Yao | 45 | 55.56% | 1 | 50.00% |
Tomeu Vizoso | 36 | 44.44% | 1 | 50.00% |
Total | 81 | 100.00% | 2 | 100.00% |
static int rockchip_drm_sys_resume(struct device *dev)
{
struct drm_device *drm = dev_get_drvdata(dev);
struct rockchip_drm_private *priv = drm->dev_private;
drm_atomic_helper_resume(drm, priv->state);
rockchip_drm_fb_resume(drm);
drm_kms_helper_poll_enable(drm);
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Mark Yao | 43 | 82.69% | 1 | 50.00% |
Tomeu Vizoso | 9 | 17.31% | 1 | 50.00% |
Total | 52 | 100.00% | 2 | 100.00% |
#endif
static const struct dev_pm_ops rockchip_drm_pm_ops = {
SET_SYSTEM_SLEEP_PM_OPS(rockchip_drm_sys_suspend,
rockchip_drm_sys_resume)
};
static int compare_of(struct device *dev, void *data)
{
struct device_node *np = data;
return dev->of_node == np;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Mark Yao | 29 | 100.00% | 1 | 100.00% |
Total | 29 | 100.00% | 1 | 100.00% |
static void rockchip_add_endpoints(struct device *dev,
struct component_match **match,
struct device_node *port)
{
struct device_node *ep, *remote;
for_each_child_of_node(port, ep) {
remote = of_graph_get_remote_port_parent(ep);
if (!remote || !of_device_is_available(remote)) {
of_node_put(remote);
continue;
} else if (!of_device_is_available(remote->parent)) {
dev_warn(dev, "parent device of %s is not available\n",
remote->full_name);
of_node_put(remote);
continue;
}
drm_of_component_match_add(dev, match, compare_of, remote);
of_node_put(remote);
}
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Mark Yao | 109 | 99.09% | 1 | 50.00% |
Russell King | 1 | 0.91% | 1 | 50.00% |
Total | 110 | 100.00% | 2 | 100.00% |
static const struct component_master_ops rockchip_drm_ops = {
.bind = rockchip_drm_bind,
.unbind = rockchip_drm_unbind,
};
static int rockchip_drm_platform_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct component_match *match = NULL;
struct device_node *np = dev->of_node;
struct device_node *port;
int i;
if (!np)
return -ENODEV;
/*
* Bind the crtc ports first, so that
* drm_of_find_possible_crtcs called from encoder .bind callbacks
* works as expected.
*/
for (i = 0;; i++) {
struct device_node *iommu;
port = of_parse_phandle(np, "ports", i);
if (!port)
break;
if (!of_device_is_available(port->parent)) {
of_node_put(port);
continue;
}
iommu = of_parse_phandle(port->parent, "iommus", 0);
if (!iommu || !of_device_is_available(iommu->parent)) {
dev_dbg(dev, "no iommu attached for %s, using non-iommu buffers\n",
port->parent->full_name);
/*
* if there is a crtc not support iommu, force set all
* crtc use non-iommu buffer.
*/
is_support_iommu = false;
}
of_node_put(iommu);
drm_of_component_match_add(dev, &match, compare_of,
port->parent);
of_node_put(port);
}
if (i == 0) {
dev_err(dev, "missing 'ports' property\n");
return -ENODEV;
}
if (!match) {
dev_err(dev, "No available vop found for display-subsystem.\n");
return -ENODEV;
}
/*
* For each bound crtc, bind the encoders attached to its
* remote endpoint.
*/
for (i = 0;; i++) {
port = of_parse_phandle(np, "ports", i);
if (!port)
break;
if (!of_device_is_available(port->parent)) {
of_node_put(port);
continue;
}
rockchip_add_endpoints(dev, &match, port);
of_node_put(port);
}
return component_master_add_with_match(dev, &rockchip_drm_ops, match);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Mark Yao | 282 | 97.92% | 3 | 60.00% |
Peter Chen | 5 | 1.74% | 1 | 20.00% |
Russell King | 1 | 0.35% | 1 | 20.00% |
Total | 288 | 100.00% | 5 | 100.00% |
static int rockchip_drm_platform_remove(struct platform_device *pdev)
{
component_master_del(&pdev->dev, &rockchip_drm_ops);
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Mark Yao | 25 | 100.00% | 1 | 100.00% |
Total | 25 | 100.00% | 1 | 100.00% |
static const struct of_device_id rockchip_drm_dt_ids[] = {
{ .compatible = "rockchip,display-subsystem", },
{ /* sentinel */ },
};
MODULE_DEVICE_TABLE(of, rockchip_drm_dt_ids);
static struct platform_driver rockchip_drm_platform_driver = {
.probe = rockchip_drm_platform_probe,
.remove = rockchip_drm_platform_remove,
.driver = {
.name = "rockchip-drm",
.of_match_table = rockchip_drm_dt_ids,
.pm = &rockchip_drm_pm_ops,
},
};
module_platform_driver(rockchip_drm_platform_driver);
MODULE_AUTHOR("Mark Yao <mark.yao@rock-chips.com>");
MODULE_DESCRIPTION("ROCKCHIP DRM Driver");
MODULE_LICENSE("GPL v2");
Overall Contributors
Person | Tokens | Prop | Commits | CommitProp |
Mark Yao | 1457 | 75.30% | 5 | 21.74% |
Shunqian Zheng | 209 | 10.80% | 1 | 4.35% |
Tomeu Vizoso | 194 | 10.03% | 2 | 8.70% |
Tomasz Figa | 24 | 1.24% | 1 | 4.35% |
Yakir Yang | 14 | 0.72% | 1 | 4.35% |
Tom Gundersen | 7 | 0.36% | 1 | 4.35% |
Peter Chen | 5 | 0.26% | 1 | 4.35% |
Russell King | 5 | 0.26% | 1 | 4.35% |
Daniel Vetter | 5 | 0.26% | 2 | 8.70% |
Paul Gortmaker | 3 | 0.16% | 1 | 4.35% |
Shawn Guo | 2 | 0.10% | 1 | 4.35% |
Thierry Reding | 2 | 0.10% | 1 | 4.35% |
Dan Carpenter | 2 | 0.10% | 1 | 4.35% |
Baoyou Xie | 2 | 0.10% | 1 | 4.35% |
Sean Paul | 2 | 0.10% | 1 | 4.35% |
John Keeping | 1 | 0.05% | 1 | 4.35% |
Ville Syrjälä | 1 | 0.05% | 1 | 4.35% |
Total | 1935 | 100.00% | 23 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.