Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  * MIPI Display Bus Interface (DBI) LCD controller support
0004  *
0005  * Copyright 2016 Noralf Trønnes
0006  */
0007 
0008 #ifndef __LINUX_MIPI_DBI_H
0009 #define __LINUX_MIPI_DBI_H
0010 
0011 #include <linux/mutex.h>
0012 #include <drm/drm_device.h>
0013 #include <drm/drm_simple_kms_helper.h>
0014 
0015 struct drm_rect;
0016 struct spi_device;
0017 struct gpio_desc;
0018 struct regulator;
0019 
0020 /**
0021  * struct mipi_dbi - MIPI DBI interface
0022  */
0023 struct mipi_dbi {
0024     /**
0025      * @cmdlock: Command lock
0026      */
0027     struct mutex cmdlock;
0028 
0029     /**
0030      * @command: Bus specific callback executing commands.
0031      */
0032     int (*command)(struct mipi_dbi *dbi, u8 *cmd, u8 *param, size_t num);
0033 
0034     /**
0035      * @read_commands: Array of read commands terminated by a zero entry.
0036      *                 Reading is disabled if this is NULL.
0037      */
0038     const u8 *read_commands;
0039 
0040     /**
0041      * @swap_bytes: Swap bytes in buffer before transfer
0042      */
0043     bool swap_bytes;
0044 
0045     /**
0046      * @reset: Optional reset gpio
0047      */
0048     struct gpio_desc *reset;
0049 
0050     /* Type C specific */
0051 
0052     /**
0053      * @spi: SPI device
0054      */
0055     struct spi_device *spi;
0056 
0057     /**
0058      * @dc: Optional D/C gpio.
0059      */
0060     struct gpio_desc *dc;
0061 
0062     /**
0063      * @tx_buf9: Buffer used for Option 1 9-bit conversion
0064      */
0065     void *tx_buf9;
0066 
0067     /**
0068      * @tx_buf9_len: Size of tx_buf9.
0069      */
0070     size_t tx_buf9_len;
0071 };
0072 
0073 /**
0074  * struct mipi_dbi_dev - MIPI DBI device
0075  */
0076 struct mipi_dbi_dev {
0077     /**
0078      * @drm: DRM device
0079      */
0080     struct drm_device drm;
0081 
0082     /**
0083      * @pipe: Display pipe structure
0084      */
0085     struct drm_simple_display_pipe pipe;
0086 
0087     /**
0088      * @connector: Connector
0089      */
0090     struct drm_connector connector;
0091 
0092     /**
0093      * @mode: Fixed display mode
0094      */
0095     struct drm_display_mode mode;
0096 
0097     /**
0098      * @tx_buf: Buffer used for transfer (copy clip rect area)
0099      */
0100     u16 *tx_buf;
0101 
0102     /**
0103      * @rotation: initial rotation in degrees Counter Clock Wise
0104      */
0105     unsigned int rotation;
0106 
0107     /**
0108      * @left_offset: Horizontal offset of the display relative to the
0109      *               controller's driver array
0110      */
0111     unsigned int left_offset;
0112 
0113     /**
0114      * @top_offset: Vertical offset of the display relative to the
0115      *              controller's driver array
0116      */
0117     unsigned int top_offset;
0118 
0119     /**
0120      * @backlight: backlight device (optional)
0121      */
0122     struct backlight_device *backlight;
0123 
0124     /**
0125      * @regulator: power regulator (optional)
0126      */
0127     struct regulator *regulator;
0128 
0129     /**
0130      * @dbi: MIPI DBI interface
0131      */
0132     struct mipi_dbi dbi;
0133 
0134     /**
0135      * @driver_private: Driver private data.
0136      *                  Necessary for drivers with private data since devm_drm_dev_alloc()
0137      *                  can't allocate structures that embed a structure which then again
0138      *                  embeds drm_device.
0139      */
0140     void *driver_private;
0141 };
0142 
0143 static inline struct mipi_dbi_dev *drm_to_mipi_dbi_dev(struct drm_device *drm)
0144 {
0145     return container_of(drm, struct mipi_dbi_dev, drm);
0146 }
0147 
0148 int mipi_dbi_spi_init(struct spi_device *spi, struct mipi_dbi *dbi,
0149               struct gpio_desc *dc);
0150 int mipi_dbi_dev_init_with_formats(struct mipi_dbi_dev *dbidev,
0151                    const struct drm_simple_display_pipe_funcs *funcs,
0152                    const uint32_t *formats, unsigned int format_count,
0153                    const struct drm_display_mode *mode,
0154                    unsigned int rotation, size_t tx_buf_size);
0155 int mipi_dbi_dev_init(struct mipi_dbi_dev *dbidev,
0156               const struct drm_simple_display_pipe_funcs *funcs,
0157               const struct drm_display_mode *mode, unsigned int rotation);
0158 void mipi_dbi_pipe_update(struct drm_simple_display_pipe *pipe,
0159               struct drm_plane_state *old_state);
0160 void mipi_dbi_enable_flush(struct mipi_dbi_dev *dbidev,
0161                struct drm_crtc_state *crtc_state,
0162                struct drm_plane_state *plan_state);
0163 void mipi_dbi_pipe_disable(struct drm_simple_display_pipe *pipe);
0164 void mipi_dbi_hw_reset(struct mipi_dbi *dbi);
0165 bool mipi_dbi_display_is_on(struct mipi_dbi *dbi);
0166 int mipi_dbi_poweron_reset(struct mipi_dbi_dev *dbidev);
0167 int mipi_dbi_poweron_conditional_reset(struct mipi_dbi_dev *dbidev);
0168 
0169 u32 mipi_dbi_spi_cmd_max_speed(struct spi_device *spi, size_t len);
0170 int mipi_dbi_spi_transfer(struct spi_device *spi, u32 speed_hz,
0171               u8 bpw, const void *buf, size_t len);
0172 
0173 int mipi_dbi_command_read(struct mipi_dbi *dbi, u8 cmd, u8 *val);
0174 int mipi_dbi_command_buf(struct mipi_dbi *dbi, u8 cmd, u8 *data, size_t len);
0175 int mipi_dbi_command_stackbuf(struct mipi_dbi *dbi, u8 cmd, const u8 *data,
0176                   size_t len);
0177 int mipi_dbi_buf_copy(void *dst, struct drm_framebuffer *fb,
0178               struct drm_rect *clip, bool swap);
0179 /**
0180  * mipi_dbi_command - MIPI DCS command with optional parameter(s)
0181  * @dbi: MIPI DBI structure
0182  * @cmd: Command
0183  * @seq: Optional parameter(s)
0184  *
0185  * Send MIPI DCS command to the controller. Use mipi_dbi_command_read() for
0186  * get/read.
0187  *
0188  * Returns:
0189  * Zero on success, negative error code on failure.
0190  */
0191 #define mipi_dbi_command(dbi, cmd, seq...) \
0192 ({ \
0193     const u8 d[] = { seq }; \
0194     struct device *dev = &(dbi)->spi->dev;  \
0195     int ret; \
0196     ret = mipi_dbi_command_stackbuf(dbi, cmd, d, ARRAY_SIZE(d)); \
0197     if (ret) \
0198         dev_err_ratelimited(dev, "error %d when sending command %#02x\n", ret, cmd); \
0199     ret; \
0200 })
0201 
0202 #ifdef CONFIG_DEBUG_FS
0203 void mipi_dbi_debugfs_init(struct drm_minor *minor);
0204 #else
0205 static inline void mipi_dbi_debugfs_init(struct drm_minor *minor) {}
0206 #endif
0207 
0208 #endif /* __LINUX_MIPI_DBI_H */