2019-05-27 08:55:01 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2017-01-22 00:19:51 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2016 Noralf Trønnes
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <linux/backlight.h>
|
2017-06-08 17:14:34 +02:00
|
|
|
#include <linux/dma-buf.h>
|
2018-11-10 15:56:47 +01:00
|
|
|
#include <linux/module.h>
|
2017-01-22 00:19:51 +01:00
|
|
|
#include <linux/pm.h>
|
|
|
|
|
#include <linux/spi/spi.h>
|
|
|
|
|
#include <linux/swab.h>
|
|
|
|
|
|
2018-11-10 15:56:47 +01:00
|
|
|
#include <drm/drm_device.h>
|
|
|
|
|
#include <drm/drm_drv.h>
|
|
|
|
|
#include <drm/drm_fourcc.h>
|
2019-01-15 05:36:42 +01:00
|
|
|
#include <drm/drm_framebuffer.h>
|
2018-11-10 15:56:47 +01:00
|
|
|
#include <drm/drm_print.h>
|
2019-01-15 05:36:41 +01:00
|
|
|
#include <drm/drm_rect.h>
|
2017-06-08 17:14:34 +02:00
|
|
|
#include <drm/tinydrm/tinydrm-helpers.h>
|
|
|
|
|
|
2017-01-22 00:19:51 +01:00
|
|
|
#if IS_ENABLED(CONFIG_SPI)
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* tinydrm_spi_transfer - SPI transfer helper
|
|
|
|
|
* @spi: SPI device
|
|
|
|
|
* @speed_hz: Override speed (optional)
|
|
|
|
|
* @bpw: Bits per word
|
|
|
|
|
* @buf: Buffer to transfer
|
|
|
|
|
* @len: Buffer length
|
|
|
|
|
*
|
|
|
|
|
* This SPI transfer helper breaks up the transfer of @buf into chunks which
|
2019-07-19 17:59:11 +02:00
|
|
|
* the SPI controller driver can handle.
|
2017-01-22 00:19:51 +01:00
|
|
|
*
|
|
|
|
|
* Returns:
|
|
|
|
|
* Zero on success, negative error code on failure.
|
|
|
|
|
*/
|
|
|
|
|
int tinydrm_spi_transfer(struct spi_device *spi, u32 speed_hz,
|
2019-07-19 17:59:11 +02:00
|
|
|
u8 bpw, const void *buf, size_t len)
|
2017-01-22 00:19:51 +01:00
|
|
|
{
|
2019-07-19 17:59:10 +02:00
|
|
|
size_t max_chunk = spi_max_transfer_size(spi);
|
2017-01-22 00:19:51 +01:00
|
|
|
struct spi_transfer tr = {
|
|
|
|
|
.bits_per_word = bpw,
|
|
|
|
|
.speed_hz = speed_hz,
|
|
|
|
|
};
|
|
|
|
|
struct spi_message m;
|
|
|
|
|
size_t chunk;
|
2019-07-19 17:59:11 +02:00
|
|
|
int ret;
|
2017-01-22 00:19:51 +01:00
|
|
|
|
2019-07-19 17:59:11 +02:00
|
|
|
spi_message_init_with_transfers(&m, &tr, 1);
|
2017-01-22 00:19:51 +01:00
|
|
|
|
|
|
|
|
while (len) {
|
|
|
|
|
chunk = min(len, max_chunk);
|
|
|
|
|
|
|
|
|
|
tr.tx_buf = buf;
|
|
|
|
|
tr.len = chunk;
|
|
|
|
|
buf += chunk;
|
|
|
|
|
len -= chunk;
|
|
|
|
|
|
|
|
|
|
ret = spi_sync(spi, &m);
|
|
|
|
|
if (ret)
|
|
|
|
|
return ret;
|
2017-02-24 00:46:48 +08:00
|
|
|
}
|
2017-01-22 00:19:51 +01:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
EXPORT_SYMBOL(tinydrm_spi_transfer);
|
|
|
|
|
|
|
|
|
|
#endif /* CONFIG_SPI */
|
2019-02-25 15:42:31 +01:00
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|