aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/tinydrm/core
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/drm/tinydrm/core')
-rw-r--r--drivers/gpu/drm/tinydrm/core/Makefile4
-rw-r--r--drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c207
-rw-r--r--drivers/gpu/drm/tinydrm/core/tinydrm-pipe.c179
3 files changed, 0 insertions, 390 deletions
diff --git a/drivers/gpu/drm/tinydrm/core/Makefile b/drivers/gpu/drm/tinydrm/core/Makefile
deleted file mode 100644
index 01065e920aea..000000000000
--- a/drivers/gpu/drm/tinydrm/core/Makefile
+++ /dev/null
@@ -1,4 +0,0 @@
-# SPDX-License-Identifier: GPL-2.0-only
-tinydrm-y := tinydrm-pipe.o tinydrm-helpers.o
-
-obj-$(CONFIG_DRM_TINYDRM) += tinydrm.o
diff --git a/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c b/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c
deleted file mode 100644
index dfeafac4c656..000000000000
--- a/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c
+++ /dev/null
@@ -1,207 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-or-later
-/*
- * Copyright (C) 2016 Noralf Trønnes
- */
-
-#include <linux/backlight.h>
-#include <linux/dma-buf.h>
-#include <linux/module.h>
-#include <linux/pm.h>
-#include <linux/spi/spi.h>
-#include <linux/swab.h>
-
-#include <drm/drm_device.h>
-#include <drm/drm_drv.h>
-#include <drm/drm_fourcc.h>
-#include <drm/drm_framebuffer.h>
-#include <drm/drm_print.h>
-#include <drm/drm_rect.h>
-#include <drm/tinydrm/tinydrm-helpers.h>
-
-static unsigned int spi_max;
-module_param(spi_max, uint, 0400);
-MODULE_PARM_DESC(spi_max, "Set a lower SPI max transfer size");
-
-#if IS_ENABLED(CONFIG_SPI)
-
-/**
- * tinydrm_spi_max_transfer_size - Determine max SPI transfer size
- * @spi: SPI device
- * @max_len: Maximum buffer size needed (optional)
- *
- * This function returns the maximum size to use for SPI transfers. It checks
- * the SPI master, the optional @max_len and the module parameter spi_max and
- * returns the smallest.
- *
- * Returns:
- * Maximum size for SPI transfers
- */
-size_t tinydrm_spi_max_transfer_size(struct spi_device *spi, size_t max_len)
-{
- size_t ret;
-
- ret = min(spi_max_transfer_size(spi), spi->master->max_dma_len);
- if (max_len)
- ret = min(ret, max_len);
- if (spi_max)
- ret = min_t(size_t, ret, spi_max);
- ret &= ~0x3;
- if (ret < 4)
- ret = 4;
-
- return ret;
-}
-EXPORT_SYMBOL(tinydrm_spi_max_transfer_size);
-
-/**
- * tinydrm_spi_bpw_supported - Check if bits per word is supported
- * @spi: SPI device
- * @bpw: Bits per word
- *
- * This function checks to see if the SPI master driver supports @bpw.
- *
- * Returns:
- * True if @bpw is supported, false otherwise.
- */
-bool tinydrm_spi_bpw_supported(struct spi_device *spi, u8 bpw)
-{
- u32 bpw_mask = spi->master->bits_per_word_mask;
-
- if (bpw == 8)
- return true;
-
- if (!bpw_mask) {
- dev_warn_once(&spi->dev,
- "bits_per_word_mask not set, assume 8-bit only\n");
- return false;
- }
-
- if (bpw_mask & SPI_BPW_MASK(bpw))
- return true;
-
- return false;
-}
-EXPORT_SYMBOL(tinydrm_spi_bpw_supported);
-
-static void
-tinydrm_dbg_spi_print(struct spi_device *spi, struct spi_transfer *tr,
- const void *buf, int idx, bool tx)
-{
- u32 speed_hz = tr->speed_hz ? tr->speed_hz : spi->max_speed_hz;
- char linebuf[3 * 32];
-
- hex_dump_to_buffer(buf, tr->len, 16,
- DIV_ROUND_UP(tr->bits_per_word, 8),
- linebuf, sizeof(linebuf), false);
-
- printk(KERN_DEBUG
- " tr(%i): speed=%u%s, bpw=%i, len=%u, %s_buf=[%s%s]\n", idx,
- speed_hz > 1000000 ? speed_hz / 1000000 : speed_hz / 1000,
- speed_hz > 1000000 ? "MHz" : "kHz", tr->bits_per_word, tr->len,
- tx ? "tx" : "rx", linebuf, tr->len > 16 ? " ..." : "");
-}
-
-/* called through tinydrm_dbg_spi_message() */
-void _tinydrm_dbg_spi_message(struct spi_device *spi, struct spi_message *m)
-{
- struct spi_transfer *tmp;
- int i = 0;
-
- list_for_each_entry(tmp, &m->transfers, transfer_list) {
-
- if (tmp->tx_buf)
- tinydrm_dbg_spi_print(spi, tmp, tmp->tx_buf, i, true);
- if (tmp->rx_buf)
- tinydrm_dbg_spi_print(spi, tmp, tmp->rx_buf, i, false);
- i++;
- }
-}
-EXPORT_SYMBOL(_tinydrm_dbg_spi_message);
-
-/**
- * tinydrm_spi_transfer - SPI transfer helper
- * @spi: SPI device
- * @speed_hz: Override speed (optional)
- * @header: Optional header transfer
- * @bpw: Bits per word
- * @buf: Buffer to transfer
- * @len: Buffer length
- *
- * This SPI transfer helper breaks up the transfer of @buf into chunks which
- * the SPI master driver can handle. If the machine is Little Endian and the
- * SPI master driver doesn't support 16 bits per word, it swaps the bytes and
- * does a 8-bit transfer.
- * If @header is set, it is prepended to each SPI message.
- *
- * Returns:
- * Zero on success, negative error code on failure.
- */
-int tinydrm_spi_transfer(struct spi_device *spi, u32 speed_hz,
- struct spi_transfer *header, u8 bpw, const void *buf,
- size_t len)
-{
- struct spi_transfer tr = {
- .bits_per_word = bpw,
- .speed_hz = speed_hz,
- };
- struct spi_message m;
- u16 *swap_buf = NULL;
- size_t max_chunk;
- size_t chunk;
- int ret = 0;
-
- if (WARN_ON_ONCE(bpw != 8 && bpw != 16))
- return -EINVAL;
-
- max_chunk = tinydrm_spi_max_transfer_size(spi, 0);
-
- if (drm_debug & DRM_UT_DRIVER)
- pr_debug("[drm:%s] bpw=%u, max_chunk=%zu, transfers:\n",
- __func__, bpw, max_chunk);
-
- if (bpw == 16 && !tinydrm_spi_bpw_supported(spi, 16)) {
- tr.bits_per_word = 8;
- if (tinydrm_machine_little_endian()) {
- swap_buf = kmalloc(min(len, max_chunk), GFP_KERNEL);
- if (!swap_buf)
- return -ENOMEM;
- }
- }
-
- spi_message_init(&m);
- if (header)
- spi_message_add_tail(header, &m);
- spi_message_add_tail(&tr, &m);
-
- while (len) {
- chunk = min(len, max_chunk);
-
- tr.tx_buf = buf;
- tr.len = chunk;
-
- if (swap_buf) {
- const u16 *buf16 = buf;
- unsigned int i;
-
- for (i = 0; i < chunk / 2; i++)
- swap_buf[i] = swab16(buf16[i]);
-
- tr.tx_buf = swap_buf;
- }
-
- buf += chunk;
- len -= chunk;
-
- tinydrm_dbg_spi_message(spi, &m);
- ret = spi_sync(spi, &m);
- if (ret)
- return ret;
- }
-
- return 0;
-}
-EXPORT_SYMBOL(tinydrm_spi_transfer);
-
-#endif /* CONFIG_SPI */
-
-MODULE_LICENSE("GPL");
diff --git a/drivers/gpu/drm/tinydrm/core/tinydrm-pipe.c b/drivers/gpu/drm/tinydrm/core/tinydrm-pipe.c
deleted file mode 100644
index ed798fd95152..000000000000
--- a/drivers/gpu/drm/tinydrm/core/tinydrm-pipe.c
+++ /dev/null
@@ -1,179 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-or-later
-/*
- * Copyright (C) 2016 Noralf Trønnes
- */
-
-#include <drm/drm_atomic_helper.h>
-#include <drm/drm_drv.h>
-#include <drm/drm_gem_framebuffer_helper.h>
-#include <drm/drm_modes.h>
-#include <drm/drm_probe_helper.h>
-#include <drm/drm_print.h>
-#include <drm/drm_simple_kms_helper.h>
-
-struct tinydrm_connector {
- struct drm_connector base;
- struct drm_display_mode mode;
-};
-
-static inline struct tinydrm_connector *
-to_tinydrm_connector(struct drm_connector *connector)
-{
- return container_of(connector, struct tinydrm_connector, base);
-}
-
-static int tinydrm_connector_get_modes(struct drm_connector *connector)
-{
- struct tinydrm_connector *tconn = to_tinydrm_connector(connector);
- struct drm_display_mode *mode;
-
- mode = drm_mode_duplicate(connector->dev, &tconn->mode);
- if (!mode) {
- DRM_ERROR("Failed to duplicate mode\n");
- return 0;
- }
-
- if (mode->name[0] == '\0')
- drm_mode_set_name(mode);
-
- mode->type |= DRM_MODE_TYPE_PREFERRED;
- drm_mode_probed_add(connector, mode);
-
- if (mode->width_mm) {
- connector->display_info.width_mm = mode->width_mm;
- connector->display_info.height_mm = mode->height_mm;
- }
-
- return 1;
-}
-
-static const struct drm_connector_helper_funcs tinydrm_connector_hfuncs = {
- .get_modes = tinydrm_connector_get_modes,
-};
-
-static enum drm_connector_status
-tinydrm_connector_detect(struct drm_connector *connector, bool force)
-{
- if (drm_dev_is_unplugged(connector->dev))
- return connector_status_disconnected;
-
- return connector->status;
-}
-
-static void tinydrm_connector_destroy(struct drm_connector *connector)
-{
- struct tinydrm_connector *tconn = to_tinydrm_connector(connector);
-
- drm_connector_cleanup(connector);
- kfree(tconn);
-}
-
-static const struct drm_connector_funcs tinydrm_connector_funcs = {
- .reset = drm_atomic_helper_connector_reset,
- .detect = tinydrm_connector_detect,
- .fill_modes = drm_helper_probe_single_connector_modes,
- .destroy = tinydrm_connector_destroy,
- .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
- .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
-};
-
-struct drm_connector *
-tinydrm_connector_create(struct drm_device *drm,
- const struct drm_display_mode *mode,
- int connector_type)
-{
- struct tinydrm_connector *tconn;
- struct drm_connector *connector;
- int ret;
-
- tconn = kzalloc(sizeof(*tconn), GFP_KERNEL);
- if (!tconn)
- return ERR_PTR(-ENOMEM);
-
- drm_mode_copy(&tconn->mode, mode);
- connector = &tconn->base;
-
- drm_connector_helper_add(connector, &tinydrm_connector_hfuncs);
- ret = drm_connector_init(drm, connector, &tinydrm_connector_funcs,
- connector_type);
- if (ret) {
- kfree(tconn);
- return ERR_PTR(ret);
- }
-
- connector->status = connector_status_connected;
-
- return connector;
-}
-
-static int tinydrm_rotate_mode(struct drm_display_mode *mode,
- unsigned int rotation)
-{
- if (rotation == 0 || rotation == 180) {
- return 0;
- } else if (rotation == 90 || rotation == 270) {
- swap(mode->hdisplay, mode->vdisplay);
- swap(mode->hsync_start, mode->vsync_start);
- swap(mode->hsync_end, mode->vsync_end);
- swap(mode->htotal, mode->vtotal);
- swap(mode->width_mm, mode->height_mm);
- return 0;
- } else {
- return -EINVAL;
- }
-}
-
-/**
- * tinydrm_display_pipe_init - Initialize display pipe
- * @drm: DRM device
- * @pipe: Display pipe
- * @funcs: Display pipe functions
- * @connector_type: Connector type
- * @formats: Array of supported formats (DRM_FORMAT\_\*)
- * @format_count: Number of elements in @formats
- * @mode: Supported mode
- * @rotation: Initial @mode rotation in degrees Counter Clock Wise
- *
- * This function sets up a &drm_simple_display_pipe with a &drm_connector that
- * has one fixed &drm_display_mode which is rotated according to @rotation.
- *
- * Returns:
- * Zero on success, negative error code on failure.
- */
-int tinydrm_display_pipe_init(struct drm_device *drm,
- struct drm_simple_display_pipe *pipe,
- const struct drm_simple_display_pipe_funcs *funcs,
- int connector_type,
- const uint32_t *formats,
- unsigned int format_count,
- const struct drm_display_mode *mode,
- unsigned int rotation)
-{
- struct drm_display_mode mode_copy;
- struct drm_connector *connector;
- int ret;
- static const uint64_t modifiers[] = {
- DRM_FORMAT_MOD_LINEAR,
- DRM_FORMAT_MOD_INVALID
- };
-
- drm_mode_copy(&mode_copy, mode);
- ret = tinydrm_rotate_mode(&mode_copy, rotation);
- if (ret) {
- DRM_ERROR("Illegal rotation value %u\n", rotation);
- return -EINVAL;
- }
-
- drm->mode_config.min_width = mode_copy.hdisplay;
- drm->mode_config.max_width = mode_copy.hdisplay;
- drm->mode_config.min_height = mode_copy.vdisplay;
- drm->mode_config.max_height = mode_copy.vdisplay;
-
- connector = tinydrm_connector_create(drm, &mode_copy, connector_type);
- if (IS_ERR(connector))
- return PTR_ERR(connector);
-
- return drm_simple_display_pipe_init(drm, pipe, funcs, formats,
- format_count, modifiers, connector);
-}
-EXPORT_SYMBOL(tinydrm_display_pipe_init);