Commit be5a8a63 authored by hanetzer's avatar hanetzer

drm/panfrost: add basic drm driver

Signed-off-by: hanetzer's avatarMarty E. Plummer <hanetzer@startmail.com>
parent 49acff10
panfrost-y := \
panfrost_drv.o
panfrost_drv.o \
panfrost_device.o
obj-$(CONFIG_DRM_PANFROST) += panfrost.o
// SPDX-License-Identifier: GPL-2.0
/* Copyright 2018 Panfrost Team */
#include "panfrost_device.h"
int panfrost_device_init(struct panfrost_device *pfdev)
{
pfdev->id = panfrost_gpu_malit760;
return 0;
}
void panfrost_device_fini(struct panfrost_device *pfdev)
{
}
// SPDX-License-Identifier: GPL-2.0
/* Copyright 2018 Panfrost Team */
#ifndef __PANFROST_DEVICE_H__
#define __PANFROST_DEVICE_H__
#include <drm/drmP.h>
enum panfrost_gpu_id {
panfrost_gpu_malit760 = 0,
panfrost_gpu_num,
};
struct panfrost_device {
struct device *dev;
struct drm_device *ddev;
struct platform_device *pdev;
enum panfrost_gpu_id id;
};
int panfrost_device_init(struct panfrost_device *pfdev);
void panfrost_device_fini(struct panfrost_device *pfdev);
#endif
......@@ -3,14 +3,105 @@
#include <linux/module.h>
#include <linux/of_platform.h>
#include <drm/panfrost_drm.h>
#include "panfrost_device.h"
static int panfrost_ioctl_info(struct drm_device *ddev, void *data, struct drm_file *file)
{
struct drm_panfrost_info *info = data;
struct panfrost_device *pfdev = ddev->dev_private;
switch (pfdev->id) {
case panfrost_gpu_malit760:
info->gpu_id = PANFROST_INFO_GPU_MALI_T760;
break;
default:
return -ENODEV;
}
return 0;
}
static const struct drm_ioctl_desc panfrost_drm_driver_ioctls[] = {
DRM_IOCTL_DEF_DRV(PANFROST_INFO, panfrost_ioctl_info, DRM_AUTH|DRM_RENDER_ALLOW),
};
static const struct file_operations panfrost_drm_driver_fops = {
.owner = THIS_MODULE,
.open = drm_open,
.release = drm_release,
.unlocked_ioctl = drm_ioctl,
#ifdef CONFIG_COMPAT
.compat_ioctl = drm_compat_ioctl,
#endif
};
static struct drm_driver panfrost_drm_driver = {
.driver_features = DRIVER_RENDER,
.ioctls = panfrost_drm_driver_ioctls,
.num_ioctls = ARRAY_SIZE(panfrost_drm_driver_ioctls),
.fops = &panfrost_drm_driver_fops,
.name = "panfrost",
.desc = "panfrost DRM",
.date = "20180908",
.major = 1,
.minor = 0,
};
static int panfrost_pdev_probe(struct platform_device *pdev)
{
struct panfrost_device *pfdev;
struct drm_device *ddev;
int err;
pfdev = devm_kzalloc(&pdev->dev, sizeof(*pfdev), GFP_KERNEL);
if (!pfdev)
return -ENOMEM;
pfdev->pdev = pdev;
pfdev->dev = &pdev->dev;
platform_set_drvdata(pdev, pfdev);
/* Allocate and initialze the DRM device. */
ddev = drm_dev_alloc(&panfrost_drm_driver, &pdev->dev);
if (IS_ERR(ddev))
return PTR_ERR(ddev);
ddev->dev_private = pfdev;
pfdev->ddev = ddev;
err = panfrost_device_init(pfdev);
if (err) {
dev_err(&pdev->dev, "Fatal error during GPU init\n");
goto err_out0;
}
/*
* Register the DRM device with the core and the connectors with
* sysfs
*/
err = drm_dev_register(ddev, 0);
if (err < 0)
goto err_out1;
return 0;
err_out1:
panfrost_device_fini(pfdev);
err_out0:
drm_dev_unref(ddev);
return err;
}
static int panfrost_pdev_remove(struct platform_device *pdev)
{
struct panfrost_device *pfdev = platform_get_drvdata(pdev);
struct drm_device *ddev = pfdev->ddev;
drm_dev_unregister(ddev);
panfrost_device_fini(pfdev);
drm_dev_unref(ddev);
return 0;
}
......@@ -33,7 +124,7 @@ static int __init panfrost_init(void)
{
int ret;
ret = platform_device_register(&panfrost_platform_driver);
ret = platform_driver_register(&panfrost_platform_driver);
return ret;
}
......@@ -41,7 +132,7 @@ module_init(panfrost_init);
static void __exit panfrost_exit(void)
{
platform_device_unregister(&panfrost_platform_driver);
platform_driver_unregister(&panfrost_platform_driver);
}
module_exit(panfrost_exit);
......
// SPDX-License-Identifier: GPL-2.0
/* Copyright 2018 Panfrost Team */
#ifndef __PANFROST_DRM_H__
#define __PANFROST_DRM_H__
#include "drm.h"
#if defined(__cplusplus)
extern "C" {
#endif
#define PANFROST_INFO_GPU_MALI_T760 0x00
struct drm_panfrost_info {
__u32 gpu_id; /* out */
};
#define DRM_PANFROST_INFO 0x00
#define DRM_IOCTL_PANFROST_INFO DRM_IOR(DRM_COMMAND_BASE + DRM_PANFROST_INFO, struct drm_panfrost_info)
#if defined(__cplusplus)
}
#endif
#endif /* __PANFROST_DRM_H__ */
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