mipi-dbi.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. #ifndef __LINUX_MIPI_DBI_H
  12. #define __LINUX_MIPI_DBI_H
  13. #include <drm/tinydrm/tinydrm.h>
  14. struct spi_device;
  15. struct gpio_desc;
  16. struct regulator;
  17. /**
  18. * struct mipi_dbi - MIPI DBI controller
  19. * @tinydrm: tinydrm base
  20. * @spi: SPI device
  21. * @enabled: Pipeline is enabled
  22. * @cmdlock: Command lock
  23. * @command: Bus specific callback executing commands.
  24. * @read_commands: Array of read commands terminated by a zero entry.
  25. * Reading is disabled if this is NULL.
  26. * @dc: Optional D/C gpio.
  27. * @tx_buf: Buffer used for transfer (copy clip rect area)
  28. * @tx_buf9: Buffer used for Option 1 9-bit conversion
  29. * @tx_buf9_len: Size of tx_buf9.
  30. * @swap_bytes: Swap bytes in buffer before transfer
  31. * @reset: Optional reset gpio
  32. * @rotation: initial rotation in degrees Counter Clock Wise
  33. * @backlight: backlight device (optional)
  34. * @regulator: power regulator (optional)
  35. */
  36. struct mipi_dbi {
  37. struct tinydrm_device tinydrm;
  38. struct spi_device *spi;
  39. bool enabled;
  40. struct mutex cmdlock;
  41. int (*command)(struct mipi_dbi *mipi, u8 *cmd, u8 *param, size_t num);
  42. const u8 *read_commands;
  43. struct gpio_desc *dc;
  44. u16 *tx_buf;
  45. void *tx_buf9;
  46. size_t tx_buf9_len;
  47. bool swap_bytes;
  48. struct gpio_desc *reset;
  49. unsigned int rotation;
  50. struct backlight_device *backlight;
  51. struct regulator *regulator;
  52. };
  53. static inline struct mipi_dbi *
  54. mipi_dbi_from_tinydrm(struct tinydrm_device *tdev)
  55. {
  56. return container_of(tdev, struct mipi_dbi, tinydrm);
  57. }
  58. int mipi_dbi_spi_init(struct spi_device *spi, struct mipi_dbi *mipi,
  59. struct gpio_desc *dc);
  60. int mipi_dbi_init(struct device *dev, struct mipi_dbi *mipi,
  61. const struct drm_simple_display_pipe_funcs *pipe_funcs,
  62. struct drm_driver *driver,
  63. const struct drm_display_mode *mode, unsigned int rotation);
  64. void mipi_dbi_enable_flush(struct mipi_dbi *mipi,
  65. struct drm_crtc_state *crtc_state,
  66. struct drm_plane_state *plan_state);
  67. void mipi_dbi_pipe_disable(struct drm_simple_display_pipe *pipe);
  68. void mipi_dbi_hw_reset(struct mipi_dbi *mipi);
  69. bool mipi_dbi_display_is_on(struct mipi_dbi *mipi);
  70. int mipi_dbi_poweron_reset(struct mipi_dbi *mipi);
  71. int mipi_dbi_poweron_conditional_reset(struct mipi_dbi *mipi);
  72. u32 mipi_dbi_spi_cmd_max_speed(struct spi_device *spi, size_t len);
  73. int mipi_dbi_command_read(struct mipi_dbi *mipi, u8 cmd, u8 *val);
  74. int mipi_dbi_command_buf(struct mipi_dbi *mipi, u8 cmd, u8 *data, size_t len);
  75. int mipi_dbi_command_stackbuf(struct mipi_dbi *mipi, u8 cmd, u8 *data, size_t len);
  76. int mipi_dbi_buf_copy(void *dst, struct drm_framebuffer *fb,
  77. struct drm_clip_rect *clip, bool swap);
  78. /**
  79. * mipi_dbi_command - MIPI DCS command with optional parameter(s)
  80. * @mipi: MIPI structure
  81. * @cmd: Command
  82. * @seq...: Optional parameter(s)
  83. *
  84. * Send MIPI DCS command to the controller. Use mipi_dbi_command_read() for
  85. * get/read.
  86. *
  87. * Returns:
  88. * Zero on success, negative error code on failure.
  89. */
  90. #define mipi_dbi_command(mipi, cmd, seq...) \
  91. ({ \
  92. u8 d[] = { seq }; \
  93. mipi_dbi_command_stackbuf(mipi, cmd, d, ARRAY_SIZE(d)); \
  94. })
  95. #ifdef CONFIG_DEBUG_FS
  96. int mipi_dbi_debugfs_init(struct drm_minor *minor);
  97. #else
  98. #define mipi_dbi_debugfs_init NULL
  99. #endif
  100. #endif /* __LINUX_MIPI_DBI_H */