Skip to content

Commit

Permalink
Merge tag 'sunxi-drm-for-4.12' of https://git.kernel.org/pub/scm/linu…
Browse files Browse the repository at this point in the history
…x/kernel/git/mripard/linux into drm-next

Allwinner DRM changes for 4.12

Not any functional changes, but a lot of preliminary rework in order to
support multiple display pipelines.

* tag 'sunxi-drm-for-4.12' of https://git.kernel.org/pub/scm/linux/kernel/git/mripard/linux: (26 commits)
  MAINTAINERS: Add sun4i-drm git repo
  drm/sun4i: Pass pointer for underlying backend into layer init
  drm/sun4i: Pass pointers for associated backend and tcon into crtc init
  drm/sun4i: tv: Get tcon and backend pointers from associated crtc
  drm/sun4i: Use embedded tcon pointer to get the tcon's output port node
  drm/sun4i: Fix tcon channel 0 comment about backporch = backporch + hsync
  drm/sun4i: Fix TCON clock and regmap initialization sequence
  drm/sun4i: Grab reserved memory region
  drm/sun4i: Add backend and tcon pointers to sun4i_crtc
  drm/sun4i: Add backend pointer to sun4i_layer
  drm/sun4i: rgb: Pass tcon pointer when initializing RGB encoder
  drm/sun4i: tv: Switch to drm_of_find_possible_crtcs
  drm/sun4i: Drop hardcoded .possible_crtcs values from layers
  drm/sun4i: Drop primary layer pointer from sun4i_drv
  drm/sun4i: Initialize crtc from tcon bind function
  drm/sun4i: Move layers from sun4i_drv to sun4i_crtc
  drm/sun4i: Add end of list element for sun4i_layers_init's returned list
  drm/sun4i: Set drm_crtc.port to the underlying TCON's output port node
  drm/sun4i: Make sunxi_rgb2yuv_coef constant
  drm/sun4i: Make sun4i_crtc_init return ERR_PTR style error codes
  ...
  • Loading branch information
Dave Airlie committed Apr 20, 2017
2 parents 856ee92 + 2da042a commit cb2e77c
Show file tree
Hide file tree
Showing 15 changed files with 164 additions and 107 deletions.
1 change: 1 addition & 0 deletions MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -4247,6 +4247,7 @@ L: dri-devel@lists.freedesktop.org
S: Supported
F: drivers/gpu/drm/sun4i/
F: Documentation/devicetree/bindings/display/sunxi/sun4i-drm.txt
T: git git://git.kernel.org/pub/scm/linux/kernel/git/mripard/linux.git

DRM DRIVERS FOR AMLOGIC SOCS
M: Neil Armstrong <narmstrong@baylibre.com>
Expand Down
4 changes: 2 additions & 2 deletions drivers/gpu/drm/sun4i/Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
sun4i-drm-y += sun4i_crtc.o
sun4i-drm-y += sun4i_drv.o
sun4i-drm-y += sun4i_framebuffer.o
sun4i-drm-y += sun4i_layer.o

sun4i-tcon-y += sun4i_tcon.o
sun4i-tcon-y += sun4i_rgb.o
sun4i-tcon-y += sun4i_dotclock.o
sun4i-tcon-y += sun4i_crtc.o
sun4i-tcon-y += sun4i_layer.o

obj-$(CONFIG_DRM_SUN4I) += sun4i-drm.o sun4i-tcon.o
obj-$(CONFIG_DRM_SUN4I) += sun4i_backend.o
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpu/drm/sun4i/sun4i_backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "sun4i_backend.h"
#include "sun4i_drv.h"

static u32 sunxi_rgb2yuv_coef[12] = {
static const u32 sunxi_rgb2yuv_coef[12] = {
0x00000107, 0x00000204, 0x00000064, 0x00000108,
0x00003f69, 0x00003ed6, 0x000001c1, 0x00000808,
0x000001c1, 0x00003e88, 0x00003fb8, 0x00000808
Expand Down
70 changes: 53 additions & 17 deletions drivers/gpu/drm/sun4i/sun4i_crtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <linux/clk-provider.h>
#include <linux/ioport.h>
#include <linux/of_address.h>
#include <linux/of_graph.h>
#include <linux/of_irq.h>
#include <linux/regmap.h>

Expand All @@ -27,6 +28,7 @@
#include "sun4i_backend.h"
#include "sun4i_crtc.h"
#include "sun4i_drv.h"
#include "sun4i_layer.h"
#include "sun4i_tcon.h"

static void sun4i_crtc_atomic_begin(struct drm_crtc *crtc,
Expand All @@ -50,12 +52,11 @@ static void sun4i_crtc_atomic_flush(struct drm_crtc *crtc,
struct drm_crtc_state *old_state)
{
struct sun4i_crtc *scrtc = drm_crtc_to_sun4i_crtc(crtc);
struct sun4i_drv *drv = scrtc->drv;
struct drm_pending_vblank_event *event = crtc->state->event;

DRM_DEBUG_DRIVER("Committing plane changes\n");

sun4i_backend_commit(drv->backend);
sun4i_backend_commit(scrtc->backend);

if (event) {
crtc->state->event = NULL;
Expand All @@ -72,11 +73,10 @@ static void sun4i_crtc_atomic_flush(struct drm_crtc *crtc,
static void sun4i_crtc_disable(struct drm_crtc *crtc)
{
struct sun4i_crtc *scrtc = drm_crtc_to_sun4i_crtc(crtc);
struct sun4i_drv *drv = scrtc->drv;

DRM_DEBUG_DRIVER("Disabling the CRTC\n");

sun4i_tcon_disable(drv->tcon);
sun4i_tcon_disable(scrtc->tcon);

if (crtc->state->event && !crtc->state->active) {
spin_lock_irq(&crtc->dev->event_lock);
Expand All @@ -90,11 +90,10 @@ static void sun4i_crtc_disable(struct drm_crtc *crtc)
static void sun4i_crtc_enable(struct drm_crtc *crtc)
{
struct sun4i_crtc *scrtc = drm_crtc_to_sun4i_crtc(crtc);
struct sun4i_drv *drv = scrtc->drv;

DRM_DEBUG_DRIVER("Enabling the CRTC\n");

sun4i_tcon_enable(drv->tcon);
sun4i_tcon_enable(scrtc->tcon);
}

static const struct drm_crtc_helper_funcs sun4i_crtc_helper_funcs = {
Expand All @@ -107,23 +106,21 @@ static const struct drm_crtc_helper_funcs sun4i_crtc_helper_funcs = {
static int sun4i_crtc_enable_vblank(struct drm_crtc *crtc)
{
struct sun4i_crtc *scrtc = drm_crtc_to_sun4i_crtc(crtc);
struct sun4i_drv *drv = scrtc->drv;

DRM_DEBUG_DRIVER("Enabling VBLANK on crtc %p\n", crtc);

sun4i_tcon_enable_vblank(drv->tcon, true);
sun4i_tcon_enable_vblank(scrtc->tcon, true);

return 0;
}

static void sun4i_crtc_disable_vblank(struct drm_crtc *crtc)
{
struct sun4i_crtc *scrtc = drm_crtc_to_sun4i_crtc(crtc);
struct sun4i_drv *drv = scrtc->drv;

DRM_DEBUG_DRIVER("Disabling VBLANK on crtc %p\n", crtc);

sun4i_tcon_enable_vblank(drv->tcon, false);
sun4i_tcon_enable_vblank(scrtc->tcon, false);
}

static const struct drm_crtc_funcs sun4i_crtc_funcs = {
Expand All @@ -137,28 +134,67 @@ static const struct drm_crtc_funcs sun4i_crtc_funcs = {
.disable_vblank = sun4i_crtc_disable_vblank,
};

struct sun4i_crtc *sun4i_crtc_init(struct drm_device *drm)
struct sun4i_crtc *sun4i_crtc_init(struct drm_device *drm,
struct sun4i_backend *backend,
struct sun4i_tcon *tcon)
{
struct sun4i_drv *drv = drm->dev_private;
struct sun4i_crtc *scrtc;
int ret;
struct drm_plane *primary = NULL, *cursor = NULL;
int ret, i;

scrtc = devm_kzalloc(drm->dev, sizeof(*scrtc), GFP_KERNEL);
if (!scrtc)
return ERR_PTR(-ENOMEM);
scrtc->backend = backend;
scrtc->tcon = tcon;

/* Create our layers */
scrtc->layers = sun4i_layers_init(drm, scrtc->backend);
if (IS_ERR(scrtc->layers)) {
dev_err(drm->dev, "Couldn't create the planes\n");
return NULL;
scrtc->drv = drv;
}

/* find primary and cursor planes for drm_crtc_init_with_planes */
for (i = 0; scrtc->layers[i]; i++) {
struct sun4i_layer *layer = scrtc->layers[i];

switch (layer->plane.type) {
case DRM_PLANE_TYPE_PRIMARY:
primary = &layer->plane;
break;
case DRM_PLANE_TYPE_CURSOR:
cursor = &layer->plane;
break;
default:
break;
}
}

ret = drm_crtc_init_with_planes(drm, &scrtc->crtc,
drv->primary,
NULL,
primary,
cursor,
&sun4i_crtc_funcs,
NULL);
if (ret) {
dev_err(drm->dev, "Couldn't init DRM CRTC\n");
return NULL;
return ERR_PTR(ret);
}

drm_crtc_helper_add(&scrtc->crtc, &sun4i_crtc_helper_funcs);

/* Set crtc.port to output port node of the tcon */
scrtc->crtc.port = of_graph_get_port_by_id(scrtc->tcon->dev->of_node,
1);

/* Set possible_crtcs to this crtc for overlay planes */
for (i = 0; scrtc->layers[i]; i++) {
uint32_t possible_crtcs = BIT(drm_crtc_index(&scrtc->crtc));
struct sun4i_layer *layer = scrtc->layers[i];

if (layer->plane.type == DRM_PLANE_TYPE_OVERLAY)
layer->plane.possible_crtcs = possible_crtcs;
}

return scrtc;
}
8 changes: 6 additions & 2 deletions drivers/gpu/drm/sun4i/sun4i_crtc.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@ struct sun4i_crtc {
struct drm_crtc crtc;
struct drm_pending_vblank_event *event;

struct sun4i_drv *drv;
struct sun4i_backend *backend;
struct sun4i_tcon *tcon;
struct sun4i_layer **layers;
};

static inline struct sun4i_crtc *drm_crtc_to_sun4i_crtc(struct drm_crtc *crtc)
{
return container_of(crtc, struct sun4i_crtc, crtc);
}

struct sun4i_crtc *sun4i_crtc_init(struct drm_device *drm);
struct sun4i_crtc *sun4i_crtc_init(struct drm_device *drm,
struct sun4i_backend *backend,
struct sun4i_tcon *tcon);

#endif /* _SUN4I_CRTC_H_ */
47 changes: 26 additions & 21 deletions drivers/gpu/drm/sun4i/sun4i_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include <linux/component.h>
#include <linux/of_graph.h>
#include <linux/of_reserved_mem.h>

#include <drm/drmP.h>
#include <drm/drm_crtc_helper.h>
Expand All @@ -20,10 +21,9 @@
#include <drm/drm_fb_helper.h>
#include <drm/drm_of.h>

#include "sun4i_crtc.h"
#include "sun4i_drv.h"
#include "sun4i_framebuffer.h"
#include "sun4i_layer.h"
#include "sun4i_tcon.h"

DEFINE_DRM_GEM_CMA_FOPS(sun4i_drv_fops);

Expand Down Expand Up @@ -92,30 +92,25 @@ static int sun4i_drv_bind(struct device *dev)
}
drm->dev_private = drv;

drm_vblank_init(drm, 1);
ret = of_reserved_mem_device_init(dev);
if (ret && ret != -ENODEV) {
dev_err(drm->dev, "Couldn't claim our memory region\n");
goto free_drm;
}

/* drm_vblank_init calls kcalloc, which can fail */
ret = drm_vblank_init(drm, 1);
if (ret)
goto free_mem_region;

drm_mode_config_init(drm);

ret = component_bind_all(drm->dev, drm);
if (ret) {
dev_err(drm->dev, "Couldn't bind all pipelines components\n");
goto free_drm;
}

/* Create our layers */
drv->layers = sun4i_layers_init(drm);
if (IS_ERR(drv->layers)) {
dev_err(drm->dev, "Couldn't create the planes\n");
ret = PTR_ERR(drv->layers);
goto free_drm;
goto cleanup_mode_config;
}

/* Create our CRTC */
drv->crtc = sun4i_crtc_init(drm);
if (!drv->crtc) {
dev_err(drm->dev, "Couldn't create the CRTC\n");
ret = -EINVAL;
goto free_drm;
}
drm->irq_enabled = true;

/* Remove early framebuffers (ie. simplefb) */
Expand All @@ -126,18 +121,26 @@ static int sun4i_drv_bind(struct device *dev)
if (IS_ERR(drv->fbdev)) {
dev_err(drm->dev, "Couldn't create our framebuffer\n");
ret = PTR_ERR(drv->fbdev);
goto free_drm;
goto cleanup_mode_config;
}

/* Enable connectors polling */
drm_kms_helper_poll_init(drm);

ret = drm_dev_register(drm, 0);
if (ret)
goto free_drm;
goto finish_poll;

return 0;

finish_poll:
drm_kms_helper_poll_fini(drm);
sun4i_framebuffer_free(drm);
cleanup_mode_config:
drm_mode_config_cleanup(drm);
drm_vblank_cleanup(drm);
free_mem_region:
of_reserved_mem_device_release(dev);
free_drm:
drm_dev_unref(drm);
return ret;
Expand All @@ -150,7 +153,9 @@ static void sun4i_drv_unbind(struct device *dev)
drm_dev_unregister(drm);
drm_kms_helper_poll_fini(drm);
sun4i_framebuffer_free(drm);
drm_mode_config_cleanup(drm);
drm_vblank_cleanup(drm);
of_reserved_mem_device_release(dev);
drm_dev_unref(drm);
}

Expand Down
4 changes: 0 additions & 4 deletions drivers/gpu/drm/sun4i/sun4i_drv.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,9 @@

struct sun4i_drv {
struct sun4i_backend *backend;
struct sun4i_crtc *crtc;
struct sun4i_tcon *tcon;

struct drm_plane *primary;
struct drm_fbdev_cma *fbdev;

struct sun4i_layer **layers;
};

#endif /* _SUN4I_DRV_H_ */
1 change: 0 additions & 1 deletion drivers/gpu/drm/sun4i/sun4i_framebuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,4 @@ void sun4i_framebuffer_free(struct drm_device *drm)
struct sun4i_drv *drv = drm->dev_private;

drm_fbdev_cma_fini(drv->fbdev);
drm_mode_config_cleanup(drm);
}
Loading

0 comments on commit cb2e77c

Please sign in to comment.