Noralf Trønnes | 02dd95f | 2017-01-22 00:30:47 +0100 | [diff] [blame] | 1 | /* |
| 2 | * MIPI Display Bus Interface (DBI) LCD controller support |
| 3 | * |
| 4 | * Copyright 2016 Noralf Trønnes |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | */ |
| 11 | |
| 12 | #ifndef __LINUX_MIPI_DBI_H |
| 13 | #define __LINUX_MIPI_DBI_H |
| 14 | |
| 15 | #include <drm/tinydrm/tinydrm.h> |
| 16 | |
Noralf Trønnes | b051b34 | 2019-01-15 05:36:41 +0100 | [diff] [blame^] | 17 | struct drm_rect; |
Noralf Trønnes | 02dd95f | 2017-01-22 00:30:47 +0100 | [diff] [blame] | 18 | struct spi_device; |
| 19 | struct gpio_desc; |
| 20 | struct regulator; |
| 21 | |
| 22 | /** |
| 23 | * struct mipi_dbi - MIPI DBI controller |
| 24 | * @tinydrm: tinydrm base |
| 25 | * @spi: SPI device |
| 26 | * @enabled: Pipeline is enabled |
| 27 | * @cmdlock: Command lock |
| 28 | * @command: Bus specific callback executing commands. |
| 29 | * @read_commands: Array of read commands terminated by a zero entry. |
| 30 | * Reading is disabled if this is NULL. |
| 31 | * @dc: Optional D/C gpio. |
| 32 | * @tx_buf: Buffer used for transfer (copy clip rect area) |
| 33 | * @tx_buf9: Buffer used for Option 1 9-bit conversion |
| 34 | * @tx_buf9_len: Size of tx_buf9. |
| 35 | * @swap_bytes: Swap bytes in buffer before transfer |
| 36 | * @reset: Optional reset gpio |
| 37 | * @rotation: initial rotation in degrees Counter Clock Wise |
| 38 | * @backlight: backlight device (optional) |
| 39 | * @regulator: power regulator (optional) |
| 40 | */ |
| 41 | struct mipi_dbi { |
| 42 | struct tinydrm_device tinydrm; |
| 43 | struct spi_device *spi; |
| 44 | bool enabled; |
| 45 | struct mutex cmdlock; |
| 46 | int (*command)(struct mipi_dbi *mipi, u8 cmd, u8 *param, size_t num); |
| 47 | const u8 *read_commands; |
| 48 | struct gpio_desc *dc; |
| 49 | u16 *tx_buf; |
| 50 | void *tx_buf9; |
| 51 | size_t tx_buf9_len; |
| 52 | bool swap_bytes; |
| 53 | struct gpio_desc *reset; |
| 54 | unsigned int rotation; |
| 55 | struct backlight_device *backlight; |
| 56 | struct regulator *regulator; |
| 57 | }; |
| 58 | |
| 59 | static inline struct mipi_dbi * |
| 60 | mipi_dbi_from_tinydrm(struct tinydrm_device *tdev) |
| 61 | { |
| 62 | return container_of(tdev, struct mipi_dbi, tinydrm); |
| 63 | } |
| 64 | |
| 65 | int mipi_dbi_spi_init(struct spi_device *spi, struct mipi_dbi *mipi, |
David Lechner | ace9881 | 2017-08-03 17:33:45 -0500 | [diff] [blame] | 66 | struct gpio_desc *dc); |
Noralf Trønnes | 02dd95f | 2017-01-22 00:30:47 +0100 | [diff] [blame] | 67 | int mipi_dbi_init(struct device *dev, struct mipi_dbi *mipi, |
| 68 | const struct drm_simple_display_pipe_funcs *pipe_funcs, |
| 69 | struct drm_driver *driver, |
| 70 | const struct drm_display_mode *mode, unsigned int rotation); |
Ville Syrjälä | e85d300 | 2018-03-23 17:35:09 +0200 | [diff] [blame] | 71 | void mipi_dbi_enable_flush(struct mipi_dbi *mipi, |
| 72 | struct drm_crtc_state *crtc_state, |
| 73 | struct drm_plane_state *plan_state); |
Noralf Trønnes | 02dd95f | 2017-01-22 00:30:47 +0100 | [diff] [blame] | 74 | void mipi_dbi_pipe_disable(struct drm_simple_display_pipe *pipe); |
| 75 | void mipi_dbi_hw_reset(struct mipi_dbi *mipi); |
| 76 | bool mipi_dbi_display_is_on(struct mipi_dbi *mipi); |
Noralf Trønnes | 070ab12 | 2018-01-10 19:59:37 +0100 | [diff] [blame] | 77 | int mipi_dbi_poweron_reset(struct mipi_dbi *mipi); |
| 78 | int mipi_dbi_poweron_conditional_reset(struct mipi_dbi *mipi); |
David Lechner | 13deee8 | 2017-11-19 14:12:07 -0600 | [diff] [blame] | 79 | u32 mipi_dbi_spi_cmd_max_speed(struct spi_device *spi, size_t len); |
Noralf Trønnes | 02dd95f | 2017-01-22 00:30:47 +0100 | [diff] [blame] | 80 | |
| 81 | int mipi_dbi_command_read(struct mipi_dbi *mipi, u8 cmd, u8 *val); |
| 82 | int mipi_dbi_command_buf(struct mipi_dbi *mipi, u8 cmd, u8 *data, size_t len); |
David Lechner | 13deee8 | 2017-11-19 14:12:07 -0600 | [diff] [blame] | 83 | int mipi_dbi_buf_copy(void *dst, struct drm_framebuffer *fb, |
Noralf Trønnes | b051b34 | 2019-01-15 05:36:41 +0100 | [diff] [blame^] | 84 | struct drm_rect *clip, bool swap); |
Noralf Trønnes | 02dd95f | 2017-01-22 00:30:47 +0100 | [diff] [blame] | 85 | /** |
| 86 | * mipi_dbi_command - MIPI DCS command with optional parameter(s) |
| 87 | * @mipi: MIPI structure |
| 88 | * @cmd: Command |
| 89 | * @seq...: Optional parameter(s) |
| 90 | * |
| 91 | * Send MIPI DCS command to the controller. Use mipi_dbi_command_read() for |
| 92 | * get/read. |
| 93 | * |
| 94 | * Returns: |
| 95 | * Zero on success, negative error code on failure. |
| 96 | */ |
| 97 | #define mipi_dbi_command(mipi, cmd, seq...) \ |
| 98 | ({ \ |
| 99 | u8 d[] = { seq }; \ |
| 100 | mipi_dbi_command_buf(mipi, cmd, d, ARRAY_SIZE(d)); \ |
| 101 | }) |
| 102 | |
| 103 | #ifdef CONFIG_DEBUG_FS |
| 104 | int mipi_dbi_debugfs_init(struct drm_minor *minor); |
| 105 | #else |
| 106 | #define mipi_dbi_debugfs_init NULL |
| 107 | #endif |
| 108 | |
| 109 | #endif /* __LINUX_MIPI_DBI_H */ |