Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/panel: st7701: Add support for SPI for configuration

The ST7701 supports not only MIPI DSI, but also SPI as an interface
for configuration. To support a panel connected via SPI with an RGB
parallel interface, add support for SPI using MIPI DBI helpers.

Signed-off-by: Hironori KIKUCHI <kikuchan98@gmail.com>
Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org>
Reviewed-by: Jessica Zhang <quic_jesszhan@quicinc.com>
Reviewed-by: Conor Dooley <conor.dooley@microchip.com>
Link: https://lore.kernel.org/r/20240804061503.881283-5-kikuchan98@gmail.com
Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20240804061503.881283-5-kikuchan98@gmail.com

authored by

Hironori KIKUCHI and committed by
Neil Armstrong
6a60273a 9a01fb40

+110 -16
+2 -1
drivers/gpu/drm/panel/Kconfig
··· 784 784 config DRM_PANEL_SITRONIX_ST7701 785 785 tristate "Sitronix ST7701 panel driver" 786 786 depends on OF 787 - depends on DRM_MIPI_DSI 787 + depends on SPI || DRM_MIPI_DSI 788 + select DRM_MIPI_DBI if SPI 788 789 depends on BACKLIGHT_CLASS_DEVICE 789 790 help 790 791 Say Y here if you want to enable support for the Sitronix
+108 -15
drivers/gpu/drm/panel/panel-sitronix-st7701.c
··· 4 4 * Author: Jagan Teki <jagan@amarulasolutions.com> 5 5 */ 6 6 7 + #include <drm/drm_mipi_dbi.h> 7 8 #include <drm/drm_mipi_dsi.h> 8 9 #include <drm/drm_modes.h> 9 10 #include <drm/drm_panel.h> ··· 15 14 #include <linux/module.h> 16 15 #include <linux/of.h> 17 16 #include <linux/regulator/consumer.h> 17 + #include <linux/spi/spi.h> 18 18 19 19 #include <video/mipi_display.h> 20 20 ··· 132 130 struct st7701 { 133 131 struct drm_panel panel; 134 132 struct mipi_dsi_device *dsi; 133 + struct mipi_dbi dbi; 135 134 const struct st7701_panel_desc *desc; 136 135 137 136 struct regulator_bulk_data supplies[2]; 138 137 struct gpio_desc *reset; 139 138 unsigned int sleep_delay; 140 139 enum drm_panel_orientation orientation; 140 + 141 + int (*write_command)(struct st7701 *st7701, u8 cmd, const u8 *seq, 142 + size_t len); 141 143 }; 142 144 143 145 static inline struct st7701 *panel_to_st7701(struct drm_panel *panel) ··· 149 143 return container_of(panel, struct st7701, panel); 150 144 } 151 145 152 - static inline int st7701_dsi_write(struct st7701 *st7701, const void *seq, 153 - size_t len) 146 + static int st7701_dsi_write(struct st7701 *st7701, u8 cmd, const u8 *seq, 147 + size_t len) 154 148 { 155 - return mipi_dsi_dcs_write_buffer(st7701->dsi, seq, len); 149 + return mipi_dsi_dcs_write(st7701->dsi, cmd, seq, len); 156 150 } 157 151 158 - #define ST7701_WRITE(st7701, seq...) \ 159 - { \ 160 - const u8 d[] = { seq }; \ 161 - st7701_dsi_write(st7701, d, ARRAY_SIZE(d)); \ 152 + static int st7701_dbi_write(struct st7701 *st7701, u8 cmd, const u8 *seq, 153 + size_t len) 154 + { 155 + return mipi_dbi_command_stackbuf(&st7701->dbi, cmd, seq, len); 156 + } 157 + 158 + #define ST7701_WRITE(st7701, cmd, seq...) \ 159 + { \ 160 + const u8 d[] = { seq }; \ 161 + st7701->write_command(st7701, cmd, d, ARRAY_SIZE(d)); \ 162 162 } 163 163 164 164 static u8 st7701_vgls_map(struct st7701 *st7701) ··· 223 211 /* Command2, BK0 */ 224 212 st7701_switch_cmd_bkx(st7701, true, 0); 225 213 226 - mipi_dsi_dcs_write(st7701->dsi, ST7701_CMD2_BK0_PVGAMCTRL, 227 - desc->pv_gamma, ARRAY_SIZE(desc->pv_gamma)); 228 - mipi_dsi_dcs_write(st7701->dsi, ST7701_CMD2_BK0_NVGAMCTRL, 229 - desc->nv_gamma, ARRAY_SIZE(desc->nv_gamma)); 214 + st7701->write_command(st7701, ST7701_CMD2_BK0_PVGAMCTRL, desc->pv_gamma, 215 + ARRAY_SIZE(desc->pv_gamma)); 216 + st7701->write_command(st7701, ST7701_CMD2_BK0_NVGAMCTRL, desc->nv_gamma, 217 + ARRAY_SIZE(desc->nv_gamma)); 230 218 /* 231 219 * Vertical line count configuration: 232 220 * Line[6:0]: select number of vertical lines of the TFT matrix in ··· 1063 1051 1064 1052 st7701 = dev_get_drvdata(&dsi->dev); 1065 1053 st7701->dsi = dsi; 1054 + st7701->write_command = st7701_dsi_write; 1055 + 1056 + if (!st7701->desc->lanes) 1057 + return dev_err_probe(&dsi->dev, -EINVAL, "This panel is not for MIPI DSI\n"); 1066 1058 1067 1059 dsi->mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_BURST | 1068 1060 MIPI_DSI_MODE_LPM | MIPI_DSI_CLOCK_NON_CONTINUOUS; ··· 1080 1064 return 0; 1081 1065 } 1082 1066 1067 + static int st7701_spi_probe(struct spi_device *spi) 1068 + { 1069 + struct st7701 *st7701; 1070 + struct gpio_desc *dc; 1071 + int err; 1072 + 1073 + err = st7701_probe(&spi->dev, DRM_MODE_CONNECTOR_DPI); 1074 + if (err) 1075 + return err; 1076 + 1077 + st7701 = dev_get_drvdata(&spi->dev); 1078 + st7701->write_command = st7701_dbi_write; 1079 + 1080 + dc = devm_gpiod_get_optional(&spi->dev, "dc", GPIOD_OUT_LOW); 1081 + if (IS_ERR(dc)) 1082 + return dev_err_probe(&spi->dev, PTR_ERR(dc), "Failed to get GPIO for D/CX\n"); 1083 + 1084 + err = mipi_dbi_spi_init(spi, &st7701->dbi, dc); 1085 + if (err) 1086 + return dev_err_probe(&spi->dev, err, "Failed to init MIPI DBI\n"); 1087 + st7701->dbi.read_commands = NULL; 1088 + 1089 + return 0; 1090 + } 1091 + 1083 1092 static void st7701_dsi_remove(struct mipi_dsi_device *dsi) 1084 1093 { 1085 1094 mipi_dsi_detach(dsi); 1086 1095 } 1087 1096 1088 - static const struct of_device_id st7701_of_match[] = { 1097 + static const struct of_device_id st7701_dsi_of_match[] = { 1089 1098 { .compatible = "anbernic,rg-arc-panel", .data = &rg_arc_desc }, 1090 1099 { .compatible = "densitron,dmt028vghmcmi-1a", .data = &dmt028vghmcmi_1a_desc }, 1091 1100 { .compatible = "elida,kd50t048a", .data = &kd50t048a_desc }, 1092 1101 { .compatible = "techstar,ts8550b", .data = &ts8550b_desc }, 1093 1102 { } 1094 1103 }; 1095 - MODULE_DEVICE_TABLE(of, st7701_of_match); 1104 + MODULE_DEVICE_TABLE(of, st7701_dsi_of_match); 1105 + 1106 + static const struct of_device_id st7701_spi_of_match[] = { 1107 + { /* sentinel */ } 1108 + }; 1109 + MODULE_DEVICE_TABLE(of, st7701_spi_of_match); 1110 + 1111 + static const struct spi_device_id st7701_spi_ids[] = { 1112 + { /* sentinel */ } 1113 + }; 1114 + MODULE_DEVICE_TABLE(spi, st7701_spi_ids); 1096 1115 1097 1116 static struct mipi_dsi_driver st7701_dsi_driver = { 1098 1117 .probe = st7701_dsi_probe, 1099 1118 .remove = st7701_dsi_remove, 1100 1119 .driver = { 1101 1120 .name = "st7701", 1102 - .of_match_table = st7701_of_match, 1121 + .of_match_table = st7701_dsi_of_match, 1103 1122 }, 1104 1123 }; 1105 - module_mipi_dsi_driver(st7701_dsi_driver); 1124 + 1125 + static struct spi_driver st7701_spi_driver = { 1126 + .probe = st7701_spi_probe, 1127 + .id_table = st7701_spi_ids, 1128 + .driver = { 1129 + .name = "st7701", 1130 + .of_match_table = st7701_spi_of_match, 1131 + }, 1132 + }; 1133 + 1134 + static int __init st7701_driver_init(void) 1135 + { 1136 + int err; 1137 + 1138 + if (IS_ENABLED(CONFIG_SPI)) { 1139 + err = spi_register_driver(&st7701_spi_driver); 1140 + if (err) 1141 + return err; 1142 + } 1143 + 1144 + if (IS_ENABLED(CONFIG_DRM_MIPI_DSI)) { 1145 + err = mipi_dsi_driver_register(&st7701_dsi_driver); 1146 + if (err) { 1147 + if (IS_ENABLED(CONFIG_SPI)) 1148 + spi_unregister_driver(&st7701_spi_driver); 1149 + return err; 1150 + } 1151 + } 1152 + 1153 + return 0; 1154 + } 1155 + module_init(st7701_driver_init); 1156 + 1157 + static void __exit st7701_driver_exit(void) 1158 + { 1159 + if (IS_ENABLED(CONFIG_DRM_MIPI_DSI)) 1160 + mipi_dsi_driver_unregister(&st7701_dsi_driver); 1161 + 1162 + if (IS_ENABLED(CONFIG_SPI)) 1163 + spi_unregister_driver(&st7701_spi_driver); 1164 + } 1165 + module_exit(st7701_driver_exit); 1106 1166 1107 1167 MODULE_AUTHOR("Jagan Teki <jagan@amarulasolutions.com>"); 1168 + MODULE_AUTHOR("Hironori KIKUCHI <kikuchan98@gmail.com>"); 1108 1169 MODULE_DESCRIPTION("Sitronix ST7701 LCD Panel Driver"); 1109 1170 MODULE_LICENSE("GPL");