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 | |
Noralf Trønnes | 3eba392 | 2019-02-25 15:42:30 +0100 | [diff] [blame^] | 15 | #include <linux/mutex.h> |
| 16 | #include <drm/drm_device.h> |
| 17 | #include <drm/drm_simple_kms_helper.h> |
Noralf Trønnes | 02dd95f | 2017-01-22 00:30:47 +0100 | [diff] [blame] | 18 | |
Noralf Trønnes | b051b34 | 2019-01-15 05:36:41 +0100 | [diff] [blame] | 19 | struct drm_rect; |
Noralf Trønnes | 02dd95f | 2017-01-22 00:30:47 +0100 | [diff] [blame] | 20 | struct spi_device; |
| 21 | struct gpio_desc; |
| 22 | struct regulator; |
| 23 | |
| 24 | /** |
| 25 | * struct mipi_dbi - MIPI DBI controller |
Noralf Trønnes | 02dd95f | 2017-01-22 00:30:47 +0100 | [diff] [blame] | 26 | * @spi: SPI device |
| 27 | * @enabled: Pipeline is enabled |
| 28 | * @cmdlock: Command lock |
| 29 | * @command: Bus specific callback executing commands. |
| 30 | * @read_commands: Array of read commands terminated by a zero entry. |
| 31 | * Reading is disabled if this is NULL. |
| 32 | * @dc: Optional D/C gpio. |
| 33 | * @tx_buf: Buffer used for transfer (copy clip rect area) |
| 34 | * @tx_buf9: Buffer used for Option 1 9-bit conversion |
| 35 | * @tx_buf9_len: Size of tx_buf9. |
| 36 | * @swap_bytes: Swap bytes in buffer before transfer |
| 37 | * @reset: Optional reset gpio |
| 38 | * @rotation: initial rotation in degrees Counter Clock Wise |
| 39 | * @backlight: backlight device (optional) |
| 40 | * @regulator: power regulator (optional) |
| 41 | */ |
| 42 | struct mipi_dbi { |
Noralf Trønnes | 3eba392 | 2019-02-25 15:42:30 +0100 | [diff] [blame^] | 43 | /** |
| 44 | * @drm: DRM device |
| 45 | */ |
| 46 | struct drm_device drm; |
| 47 | |
| 48 | /** |
| 49 | * @pipe: Display pipe structure |
| 50 | */ |
| 51 | struct drm_simple_display_pipe pipe; |
| 52 | |
Noralf Trønnes | 02dd95f | 2017-01-22 00:30:47 +0100 | [diff] [blame] | 53 | struct spi_device *spi; |
| 54 | bool enabled; |
| 55 | struct mutex cmdlock; |
| 56 | int (*command)(struct mipi_dbi *mipi, u8 cmd, u8 *param, size_t num); |
| 57 | const u8 *read_commands; |
| 58 | struct gpio_desc *dc; |
| 59 | u16 *tx_buf; |
| 60 | void *tx_buf9; |
| 61 | size_t tx_buf9_len; |
| 62 | bool swap_bytes; |
| 63 | struct gpio_desc *reset; |
| 64 | unsigned int rotation; |
| 65 | struct backlight_device *backlight; |
| 66 | struct regulator *regulator; |
| 67 | }; |
| 68 | |
Noralf Trønnes | 4f83479 | 2019-02-10 14:10:34 +0100 | [diff] [blame] | 69 | static inline struct mipi_dbi *drm_to_mipi_dbi(struct drm_device *drm) |
Noralf Trønnes | 02dd95f | 2017-01-22 00:30:47 +0100 | [diff] [blame] | 70 | { |
Noralf Trønnes | 3eba392 | 2019-02-25 15:42:30 +0100 | [diff] [blame^] | 71 | return container_of(drm, struct mipi_dbi, drm); |
Noralf Trønnes | 02dd95f | 2017-01-22 00:30:47 +0100 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | 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] | 75 | struct gpio_desc *dc); |
Noralf Trønnes | 3eba392 | 2019-02-25 15:42:30 +0100 | [diff] [blame^] | 76 | int mipi_dbi_init(struct mipi_dbi *mipi, |
| 77 | const struct drm_simple_display_pipe_funcs *funcs, |
Noralf Trønnes | 02dd95f | 2017-01-22 00:30:47 +0100 | [diff] [blame] | 78 | const struct drm_display_mode *mode, unsigned int rotation); |
Noralf Trønnes | 3eba392 | 2019-02-25 15:42:30 +0100 | [diff] [blame^] | 79 | void mipi_dbi_release(struct drm_device *drm); |
Noralf Trønnes | af74138 | 2019-01-15 05:36:42 +0100 | [diff] [blame] | 80 | void mipi_dbi_pipe_update(struct drm_simple_display_pipe *pipe, |
| 81 | struct drm_plane_state *old_state); |
Ville Syrjälä | e85d300 | 2018-03-23 17:35:09 +0200 | [diff] [blame] | 82 | void mipi_dbi_enable_flush(struct mipi_dbi *mipi, |
| 83 | struct drm_crtc_state *crtc_state, |
| 84 | struct drm_plane_state *plan_state); |
Noralf Trønnes | 02dd95f | 2017-01-22 00:30:47 +0100 | [diff] [blame] | 85 | void mipi_dbi_pipe_disable(struct drm_simple_display_pipe *pipe); |
| 86 | void mipi_dbi_hw_reset(struct mipi_dbi *mipi); |
| 87 | bool mipi_dbi_display_is_on(struct mipi_dbi *mipi); |
Noralf Trønnes | 070ab12 | 2018-01-10 19:59:37 +0100 | [diff] [blame] | 88 | int mipi_dbi_poweron_reset(struct mipi_dbi *mipi); |
| 89 | int mipi_dbi_poweron_conditional_reset(struct mipi_dbi *mipi); |
David Lechner | 13deee8 | 2017-11-19 14:12:07 -0600 | [diff] [blame] | 90 | 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] | 91 | |
| 92 | int mipi_dbi_command_read(struct mipi_dbi *mipi, u8 cmd, u8 *val); |
| 93 | 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] | 94 | int mipi_dbi_buf_copy(void *dst, struct drm_framebuffer *fb, |
Noralf Trønnes | b051b34 | 2019-01-15 05:36:41 +0100 | [diff] [blame] | 95 | struct drm_rect *clip, bool swap); |
Noralf Trønnes | 02dd95f | 2017-01-22 00:30:47 +0100 | [diff] [blame] | 96 | /** |
| 97 | * mipi_dbi_command - MIPI DCS command with optional parameter(s) |
| 98 | * @mipi: MIPI structure |
| 99 | * @cmd: Command |
| 100 | * @seq...: Optional parameter(s) |
| 101 | * |
| 102 | * Send MIPI DCS command to the controller. Use mipi_dbi_command_read() for |
| 103 | * get/read. |
| 104 | * |
| 105 | * Returns: |
| 106 | * Zero on success, negative error code on failure. |
| 107 | */ |
| 108 | #define mipi_dbi_command(mipi, cmd, seq...) \ |
| 109 | ({ \ |
| 110 | u8 d[] = { seq }; \ |
| 111 | mipi_dbi_command_buf(mipi, cmd, d, ARRAY_SIZE(d)); \ |
| 112 | }) |
| 113 | |
| 114 | #ifdef CONFIG_DEBUG_FS |
| 115 | int mipi_dbi_debugfs_init(struct drm_minor *minor); |
| 116 | #else |
| 117 | #define mipi_dbi_debugfs_init NULL |
| 118 | #endif |
| 119 | |
| 120 | #endif /* __LINUX_MIPI_DBI_H */ |