2019-05-27 13:55:01 +07:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
2017-01-22 06:30:47 +07:00
|
|
|
/*
|
|
|
|
* MIPI Display Bus Interface (DBI) LCD controller support
|
|
|
|
*
|
|
|
|
* Copyright 2016 Noralf Trønnes
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __LINUX_MIPI_DBI_H
|
|
|
|
#define __LINUX_MIPI_DBI_H
|
|
|
|
|
2019-02-25 21:42:30 +07:00
|
|
|
#include <linux/mutex.h>
|
|
|
|
#include <drm/drm_device.h>
|
|
|
|
#include <drm/drm_simple_kms_helper.h>
|
2017-01-22 06:30:47 +07:00
|
|
|
|
2019-01-15 11:36:41 +07:00
|
|
|
struct drm_rect;
|
2017-01-22 06:30:47 +07:00
|
|
|
struct spi_device;
|
|
|
|
struct gpio_desc;
|
|
|
|
struct regulator;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct mipi_dbi - MIPI DBI controller
|
|
|
|
* @spi: SPI device
|
|
|
|
* @enabled: Pipeline is enabled
|
|
|
|
* @cmdlock: Command lock
|
|
|
|
* @command: Bus specific callback executing commands.
|
|
|
|
* @read_commands: Array of read commands terminated by a zero entry.
|
|
|
|
* Reading is disabled if this is NULL.
|
|
|
|
* @dc: Optional D/C gpio.
|
|
|
|
* @tx_buf: Buffer used for transfer (copy clip rect area)
|
|
|
|
* @tx_buf9: Buffer used for Option 1 9-bit conversion
|
|
|
|
* @tx_buf9_len: Size of tx_buf9.
|
|
|
|
* @swap_bytes: Swap bytes in buffer before transfer
|
|
|
|
* @reset: Optional reset gpio
|
|
|
|
* @rotation: initial rotation in degrees Counter Clock Wise
|
|
|
|
* @backlight: backlight device (optional)
|
|
|
|
* @regulator: power regulator (optional)
|
|
|
|
*/
|
|
|
|
struct mipi_dbi {
|
2019-02-25 21:42:30 +07:00
|
|
|
/**
|
|
|
|
* @drm: DRM device
|
|
|
|
*/
|
|
|
|
struct drm_device drm;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @pipe: Display pipe structure
|
|
|
|
*/
|
|
|
|
struct drm_simple_display_pipe pipe;
|
|
|
|
|
2019-07-19 22:59:16 +07:00
|
|
|
/**
|
|
|
|
* @connector: Connector
|
|
|
|
*/
|
|
|
|
struct drm_connector connector;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @mode: Fixed display mode
|
|
|
|
*/
|
|
|
|
struct drm_display_mode mode;
|
|
|
|
|
2017-01-22 06:30:47 +07:00
|
|
|
struct spi_device *spi;
|
|
|
|
bool enabled;
|
|
|
|
struct mutex cmdlock;
|
2019-07-22 17:43:05 +07:00
|
|
|
int (*command)(struct mipi_dbi *dbi, u8 *cmd, u8 *param, size_t num);
|
2017-01-22 06:30:47 +07:00
|
|
|
const u8 *read_commands;
|
|
|
|
struct gpio_desc *dc;
|
|
|
|
u16 *tx_buf;
|
|
|
|
void *tx_buf9;
|
|
|
|
size_t tx_buf9_len;
|
|
|
|
bool swap_bytes;
|
|
|
|
struct gpio_desc *reset;
|
|
|
|
unsigned int rotation;
|
|
|
|
struct backlight_device *backlight;
|
|
|
|
struct regulator *regulator;
|
|
|
|
};
|
|
|
|
|
2019-02-10 20:10:34 +07:00
|
|
|
static inline struct mipi_dbi *drm_to_mipi_dbi(struct drm_device *drm)
|
2017-01-22 06:30:47 +07:00
|
|
|
{
|
2019-02-25 21:42:30 +07:00
|
|
|
return container_of(drm, struct mipi_dbi, drm);
|
2017-01-22 06:30:47 +07:00
|
|
|
}
|
|
|
|
|
2019-07-22 17:43:05 +07:00
|
|
|
int mipi_dbi_spi_init(struct spi_device *spi, struct mipi_dbi *dbi,
|
2017-08-04 05:33:45 +07:00
|
|
|
struct gpio_desc *dc);
|
2019-07-22 17:43:06 +07:00
|
|
|
int mipi_dbi_init_with_formats(struct mipi_dbi *dbidev,
|
2019-07-19 22:59:15 +07:00
|
|
|
const struct drm_simple_display_pipe_funcs *funcs,
|
|
|
|
const uint32_t *formats, unsigned int format_count,
|
|
|
|
const struct drm_display_mode *mode,
|
|
|
|
unsigned int rotation, size_t tx_buf_size);
|
2019-07-22 17:43:06 +07:00
|
|
|
int mipi_dbi_init(struct mipi_dbi *dbidev,
|
2019-02-25 21:42:30 +07:00
|
|
|
const struct drm_simple_display_pipe_funcs *funcs,
|
2017-01-22 06:30:47 +07:00
|
|
|
const struct drm_display_mode *mode, unsigned int rotation);
|
2019-02-25 21:42:30 +07:00
|
|
|
void mipi_dbi_release(struct drm_device *drm);
|
2019-01-15 11:36:42 +07:00
|
|
|
void mipi_dbi_pipe_update(struct drm_simple_display_pipe *pipe,
|
|
|
|
struct drm_plane_state *old_state);
|
2019-07-22 17:43:06 +07:00
|
|
|
void mipi_dbi_enable_flush(struct mipi_dbi *dbidev,
|
2018-03-23 22:35:09 +07:00
|
|
|
struct drm_crtc_state *crtc_state,
|
|
|
|
struct drm_plane_state *plan_state);
|
2017-01-22 06:30:47 +07:00
|
|
|
void mipi_dbi_pipe_disable(struct drm_simple_display_pipe *pipe);
|
2019-07-22 17:43:05 +07:00
|
|
|
void mipi_dbi_hw_reset(struct mipi_dbi *dbi);
|
|
|
|
bool mipi_dbi_display_is_on(struct mipi_dbi *dbi);
|
2019-07-22 17:43:06 +07:00
|
|
|
int mipi_dbi_poweron_reset(struct mipi_dbi *dbidev);
|
|
|
|
int mipi_dbi_poweron_conditional_reset(struct mipi_dbi *dbidev);
|
2019-07-19 22:59:12 +07:00
|
|
|
|
2017-11-20 03:12:07 +07:00
|
|
|
u32 mipi_dbi_spi_cmd_max_speed(struct spi_device *spi, size_t len);
|
2019-07-19 22:59:12 +07:00
|
|
|
int mipi_dbi_spi_transfer(struct spi_device *spi, u32 speed_hz,
|
|
|
|
u8 bpw, const void *buf, size_t len);
|
2017-01-22 06:30:47 +07:00
|
|
|
|
2019-07-22 17:43:05 +07:00
|
|
|
int mipi_dbi_command_read(struct mipi_dbi *dbi, u8 cmd, u8 *val);
|
|
|
|
int mipi_dbi_command_buf(struct mipi_dbi *dbi, u8 cmd, u8 *data, size_t len);
|
|
|
|
int mipi_dbi_command_stackbuf(struct mipi_dbi *dbi, u8 cmd, u8 *data, size_t len);
|
2017-11-20 03:12:07 +07:00
|
|
|
int mipi_dbi_buf_copy(void *dst, struct drm_framebuffer *fb,
|
2019-01-15 11:36:41 +07:00
|
|
|
struct drm_rect *clip, bool swap);
|
2017-01-22 06:30:47 +07:00
|
|
|
/**
|
|
|
|
* mipi_dbi_command - MIPI DCS command with optional parameter(s)
|
2019-07-22 17:43:05 +07:00
|
|
|
* @dbi: MIPI DBI structure
|
2017-01-22 06:30:47 +07:00
|
|
|
* @cmd: Command
|
|
|
|
* @seq...: Optional parameter(s)
|
|
|
|
*
|
|
|
|
* Send MIPI DCS command to the controller. Use mipi_dbi_command_read() for
|
|
|
|
* get/read.
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* Zero on success, negative error code on failure.
|
|
|
|
*/
|
2019-07-22 17:43:05 +07:00
|
|
|
#define mipi_dbi_command(dbi, cmd, seq...) \
|
2017-01-22 06:30:47 +07:00
|
|
|
({ \
|
|
|
|
u8 d[] = { seq }; \
|
2019-07-22 17:43:05 +07:00
|
|
|
mipi_dbi_command_stackbuf(dbi, cmd, d, ARRAY_SIZE(d)); \
|
2017-01-22 06:30:47 +07:00
|
|
|
})
|
|
|
|
|
|
|
|
#ifdef CONFIG_DEBUG_FS
|
|
|
|
int mipi_dbi_debugfs_init(struct drm_minor *minor);
|
|
|
|
#else
|
|
|
|
#define mipi_dbi_debugfs_init NULL
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* __LINUX_MIPI_DBI_H */
|