mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-05-16 03:11:11 -04:00
drm/ili9486: Use regular atomic helpers; drop simple-display helpers
Replace simple-display helpers with regular atomic helpers. Store the pipeline elements in struct ili9486_device and initialize them as part of probing the device. Use mipi-dbi's existing helpers and initializer macros where possible. Effectively open-codes the modesetting code in the initializer helpers of mipi-dbi and simple-display. Ili9486 requires a custom helper for CRTC enablement, and non-freeing cleanup of the pipeline. v3: - set ili9486 variable (David) v2: - fix connector initialization Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de> Acked-by: David Lechner <david@lechnology.com> Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com> Link: https://patch.msgid.link/20260319160110.109610-9-tzimmermann@suse.de
This commit is contained in:
@@ -36,6 +36,20 @@
|
||||
#define ILI9486_MADCTL_MX BIT(6)
|
||||
#define ILI9486_MADCTL_MY BIT(7)
|
||||
|
||||
struct ili9486_device {
|
||||
struct mipi_dbi_dev dbidev;
|
||||
|
||||
struct drm_plane plane;
|
||||
struct drm_crtc crtc;
|
||||
struct drm_encoder encoder;
|
||||
struct drm_connector connector;
|
||||
};
|
||||
|
||||
static struct ili9486_device *to_ili9486_device(struct drm_device *dev)
|
||||
{
|
||||
return container_of(drm_to_mipi_dbi_dev(dev), struct ili9486_device, dbidev);
|
||||
}
|
||||
|
||||
/*
|
||||
* The PiScreen/waveshare rpi-lcd-35 has a SPI to 16-bit parallel bus converter
|
||||
* in front of the display controller. This means that 8-bit values have to be
|
||||
@@ -94,16 +108,34 @@ static int waveshare_command(struct mipi_dbi *mipi, u8 *cmd, u8 *par,
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void waveshare_enable(struct drm_simple_display_pipe *pipe,
|
||||
struct drm_crtc_state *crtc_state,
|
||||
struct drm_plane_state *plane_state)
|
||||
static const u32 ili9486_plane_formats[] = {
|
||||
DRM_MIPI_DBI_PLANE_FORMATS,
|
||||
};
|
||||
|
||||
static const u64 ili9486_plane_format_modifiers[] = {
|
||||
DRM_MIPI_DBI_PLANE_FORMAT_MODIFIERS,
|
||||
};
|
||||
|
||||
static const struct drm_plane_helper_funcs ili9486_plane_helper_funcs = {
|
||||
DRM_MIPI_DBI_PLANE_HELPER_FUNCS,
|
||||
};
|
||||
|
||||
static const struct drm_plane_funcs ili9486_plane_funcs = {
|
||||
DRM_MIPI_DBI_PLANE_FUNCS,
|
||||
.destroy = drm_plane_cleanup,
|
||||
};
|
||||
|
||||
static void ili9486_crtc_helper_atomic_enable(struct drm_crtc *crtc,
|
||||
struct drm_atomic_state *state)
|
||||
{
|
||||
struct mipi_dbi_dev *dbidev = drm_to_mipi_dbi_dev(pipe->crtc.dev);
|
||||
struct drm_device *drm = crtc->dev;
|
||||
struct ili9486_device *ili9486 = to_ili9486_device(drm);
|
||||
struct mipi_dbi_dev *dbidev = &ili9486->dbidev;
|
||||
struct mipi_dbi *dbi = &dbidev->dbi;
|
||||
u8 addr_mode;
|
||||
int ret, idx;
|
||||
|
||||
if (!drm_dev_enter(pipe->crtc.dev, &idx))
|
||||
if (!drm_dev_enter(drm, &idx))
|
||||
return;
|
||||
|
||||
DRM_DEBUG_KMS("\n");
|
||||
@@ -161,8 +193,35 @@ static void waveshare_enable(struct drm_simple_display_pipe *pipe,
|
||||
drm_dev_exit(idx);
|
||||
}
|
||||
|
||||
static const struct drm_simple_display_pipe_funcs waveshare_pipe_funcs = {
|
||||
DRM_MIPI_DBI_SIMPLE_DISPLAY_PIPE_FUNCS(waveshare_enable),
|
||||
static const struct drm_crtc_helper_funcs ili9486_crtc_helper_funcs = {
|
||||
DRM_MIPI_DBI_CRTC_HELPER_FUNCS,
|
||||
.atomic_enable = ili9486_crtc_helper_atomic_enable,
|
||||
};
|
||||
|
||||
static const struct drm_crtc_funcs ili9486_crtc_funcs = {
|
||||
DRM_MIPI_DBI_CRTC_FUNCS,
|
||||
.destroy = drm_crtc_cleanup,
|
||||
};
|
||||
|
||||
static const struct drm_encoder_funcs ili9486_encoder_funcs = {
|
||||
.destroy = drm_encoder_cleanup,
|
||||
};
|
||||
|
||||
static const struct drm_connector_helper_funcs ili9486_connector_helper_funcs = {
|
||||
DRM_MIPI_DBI_CONNECTOR_HELPER_FUNCS,
|
||||
};
|
||||
|
||||
static const struct drm_connector_funcs ili9486_connector_funcs = {
|
||||
DRM_MIPI_DBI_CONNECTOR_FUNCS,
|
||||
.destroy = drm_connector_cleanup,
|
||||
};
|
||||
|
||||
static const struct drm_mode_config_helper_funcs ili9486_mode_config_helper_funcs = {
|
||||
DRM_MIPI_DBI_MODE_CONFIG_HELPER_FUNCS,
|
||||
};
|
||||
|
||||
static const struct drm_mode_config_funcs ili9486_mode_config_funcs = {
|
||||
DRM_MIPI_DBI_MODE_CONFIG_FUNCS,
|
||||
};
|
||||
|
||||
static const struct drm_display_mode waveshare_mode = {
|
||||
@@ -201,18 +260,22 @@ MODULE_DEVICE_TABLE(spi, ili9486_id);
|
||||
static int ili9486_probe(struct spi_device *spi)
|
||||
{
|
||||
struct device *dev = &spi->dev;
|
||||
struct ili9486_device *ili9486;
|
||||
struct mipi_dbi_dev *dbidev;
|
||||
struct drm_device *drm;
|
||||
struct mipi_dbi *dbi;
|
||||
struct gpio_desc *dc;
|
||||
struct drm_plane *plane;
|
||||
struct drm_crtc *crtc;
|
||||
struct drm_encoder *encoder;
|
||||
struct drm_connector *connector;
|
||||
u32 rotation = 0;
|
||||
int ret;
|
||||
|
||||
dbidev = devm_drm_dev_alloc(dev, &ili9486_driver,
|
||||
struct mipi_dbi_dev, drm);
|
||||
if (IS_ERR(dbidev))
|
||||
return PTR_ERR(dbidev);
|
||||
|
||||
ili9486 = devm_drm_dev_alloc(dev, &ili9486_driver, struct ili9486_device, dbidev.drm);
|
||||
if (IS_ERR(ili9486))
|
||||
return PTR_ERR(ili9486);
|
||||
dbidev = &ili9486->dbidev;
|
||||
dbi = &dbidev->dbi;
|
||||
drm = &dbidev->drm;
|
||||
|
||||
@@ -237,8 +300,53 @@ static int ili9486_probe(struct spi_device *spi)
|
||||
dbi->command = waveshare_command;
|
||||
dbi->read_commands = NULL;
|
||||
|
||||
ret = mipi_dbi_dev_init(dbidev, &waveshare_pipe_funcs,
|
||||
&waveshare_mode, rotation);
|
||||
ret = drm_mipi_dbi_dev_init(dbidev, &waveshare_mode, ili9486_plane_formats[0],
|
||||
rotation, 0);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = drmm_mode_config_init(drm);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
drm->mode_config.min_width = dbidev->mode.hdisplay;
|
||||
drm->mode_config.max_width = dbidev->mode.hdisplay;
|
||||
drm->mode_config.min_height = dbidev->mode.vdisplay;
|
||||
drm->mode_config.max_height = dbidev->mode.vdisplay;
|
||||
drm->mode_config.funcs = &ili9486_mode_config_funcs;
|
||||
drm->mode_config.preferred_depth = 16;
|
||||
drm->mode_config.helper_private = &ili9486_mode_config_helper_funcs;
|
||||
|
||||
plane = &ili9486->plane;
|
||||
ret = drm_universal_plane_init(drm, plane, 0, &ili9486_plane_funcs,
|
||||
ili9486_plane_formats, ARRAY_SIZE(ili9486_plane_formats),
|
||||
ili9486_plane_format_modifiers,
|
||||
DRM_PLANE_TYPE_PRIMARY, NULL);
|
||||
if (ret)
|
||||
return ret;
|
||||
drm_plane_helper_add(plane, &ili9486_plane_helper_funcs);
|
||||
drm_plane_enable_fb_damage_clips(plane);
|
||||
|
||||
crtc = &ili9486->crtc;
|
||||
ret = drm_crtc_init_with_planes(drm, crtc, plane, NULL, &ili9486_crtc_funcs, NULL);
|
||||
if (ret)
|
||||
return ret;
|
||||
drm_crtc_helper_add(crtc, &ili9486_crtc_helper_funcs);
|
||||
|
||||
encoder = &ili9486->encoder;
|
||||
ret = drm_encoder_init(drm, encoder, &ili9486_encoder_funcs, DRM_MODE_ENCODER_NONE, NULL);
|
||||
if (ret)
|
||||
return ret;
|
||||
encoder->possible_crtcs = drm_crtc_mask(crtc);
|
||||
|
||||
connector = &ili9486->connector;
|
||||
ret = drm_connector_init(drm, connector, &ili9486_connector_funcs,
|
||||
DRM_MODE_CONNECTOR_SPI);
|
||||
if (ret)
|
||||
return ret;
|
||||
drm_connector_helper_add(connector, &ili9486_connector_helper_funcs);
|
||||
|
||||
ret = drm_connector_attach_encoder(connector, encoder);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user