forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/drivers/gpu/drm/panel/panel-simple.c
....@@ -28,6 +28,7 @@
2828 #include <linux/of_platform.h>
2929 #include <linux/platform_device.h>
3030 #include <linux/regulator/consumer.h>
31
+#include <linux/spi/spi.h>
3132
3233 #include <video/display_timing.h>
3334 #include <video/mipi_display.h>
....@@ -41,6 +42,11 @@
4142 #include <drm/drm_dsc.h>
4243
4344 #include "panel-simple.h"
45
+
46
+enum panel_simple_cmd_type {
47
+ CMD_TYPE_DEFAULT,
48
+ CMD_TYPE_SPI
49
+};
4450
4551 struct panel_cmd_header {
4652 u8 data_type;
....@@ -124,6 +130,11 @@
124130
125131 struct panel_cmd_seq *init_seq;
126132 struct panel_cmd_seq *exit_seq;
133
+
134
+ enum panel_simple_cmd_type cmd_type;
135
+
136
+ int (*spi_read)(struct device *dev, const u8 cmd, u8 *val);
137
+ int (*spi_write)(struct device *dev, const u8 *data, size_t len, u8 type);
127138 };
128139
129140 struct panel_simple {
....@@ -148,6 +159,11 @@
148159 struct drm_dsc_picture_parameter_set *pps;
149160 enum drm_panel_orientation orientation;
150161 };
162
+
163
+static inline void panel_simple_msleep(unsigned int msecs)
164
+{
165
+ usleep_range(msecs * 1000, msecs * 1000 + 100);
166
+}
151167
152168 static inline struct panel_simple *to_panel_simple(struct drm_panel *panel)
153169 {
....@@ -266,7 +282,30 @@
266282 dev_err(dev, "failed to write dcs cmd: %d\n", err);
267283
268284 if (cmd->header.delay)
269
- msleep(cmd->header.delay);
285
+ panel_simple_msleep(cmd->header.delay);
286
+ }
287
+
288
+ return 0;
289
+}
290
+
291
+static int panel_simple_xfer_spi_cmd_seq(struct panel_simple *panel, struct panel_cmd_seq *cmds)
292
+{
293
+ int i;
294
+ int ret;
295
+
296
+ if (!cmds)
297
+ return -EINVAL;
298
+
299
+ for (i = 0; i < cmds->cmd_cnt; i++) {
300
+ struct panel_cmd_desc *cmd = &cmds->cmds[i];
301
+
302
+ ret = panel->desc->spi_write(panel->base.dev, cmd->payload,
303
+ cmd->header.payload_length, cmd->header.data_type);
304
+ if (ret)
305
+ return ret;
306
+
307
+ if (cmd->header.delay)
308
+ panel_simple_msleep(cmd->header.delay);
270309 }
271310
272311 return 0;
....@@ -444,7 +483,7 @@
444483 return 0;
445484
446485 if (p->desc->delay.disable)
447
- msleep(p->desc->delay.disable);
486
+ panel_simple_msleep(p->desc->delay.disable);
448487
449488 p->enabled = false;
450489
....@@ -458,9 +497,17 @@
458497 if (!p->prepared)
459498 return 0;
460499
461
- if (p->desc->exit_seq)
462
- if (p->dsi)
463
- panel_simple_xfer_dsi_cmd_seq(p, p->desc->exit_seq);
500
+ if (p->desc->exit_seq) {
501
+ if (p->desc->cmd_type == CMD_TYPE_SPI) {
502
+ if (panel_simple_xfer_spi_cmd_seq(p, p->desc->exit_seq)) {
503
+ dev_err(panel->dev, "failed to send exit spi cmds seq\n");
504
+ return -EINVAL;
505
+ }
506
+ } else {
507
+ if (p->dsi)
508
+ panel_simple_xfer_dsi_cmd_seq(p, p->desc->exit_seq);
509
+ }
510
+ }
464511
465512 gpiod_direction_output(p->reset_gpio, 1);
466513 gpiod_direction_output(p->enable_gpio, 0);
....@@ -468,7 +515,7 @@
468515 panel_simple_regulator_disable(p);
469516
470517 if (p->desc->delay.unprepare)
471
- msleep(p->desc->delay.unprepare);
518
+ panel_simple_msleep(p->desc->delay.unprepare);
472519
473520 p->prepared = false;
474521
....@@ -522,7 +569,7 @@
522569 if (p->no_hpd)
523570 delay += p->desc->delay.hpd_absent_delay;
524571 if (delay)
525
- msleep(delay);
572
+ panel_simple_msleep(delay);
526573
527574 if (p->hpd_gpio) {
528575 if (IS_ERR(p->hpd_gpio)) {
....@@ -547,16 +594,24 @@
547594 gpiod_direction_output(p->reset_gpio, 1);
548595
549596 if (p->desc->delay.reset)
550
- msleep(p->desc->delay.reset);
597
+ panel_simple_msleep(p->desc->delay.reset);
551598
552599 gpiod_direction_output(p->reset_gpio, 0);
553600
554601 if (p->desc->delay.init)
555
- msleep(p->desc->delay.init);
602
+ panel_simple_msleep(p->desc->delay.init);
556603
557
- if (p->desc->init_seq)
558
- if (p->dsi)
559
- panel_simple_xfer_dsi_cmd_seq(p, p->desc->init_seq);
604
+ if (p->desc->init_seq) {
605
+ if (p->desc->cmd_type == CMD_TYPE_SPI) {
606
+ if (panel_simple_xfer_spi_cmd_seq(p, p->desc->init_seq)) {
607
+ dev_err(panel->dev, "failed to send init spi cmds seq\n");
608
+ return -EINVAL;
609
+ }
610
+ } else {
611
+ if (p->dsi)
612
+ panel_simple_xfer_dsi_cmd_seq(p, p->desc->init_seq);
613
+ }
614
+ }
560615
561616 p->prepared = true;
562617
....@@ -571,7 +626,7 @@
571626 return 0;
572627
573628 if (p->desc->delay.enable)
574
- msleep(p->desc->delay.enable);
629
+ panel_simple_msleep(p->desc->delay.enable);
575630
576631 p->enabled = true;
577632
....@@ -992,8 +1047,8 @@
9921047 .num_modes = 1,
9931048 .bpc = 8,
9941049 .size = {
995
- .width = 105,
996
- .height = 67,
1050
+ .width = 99,
1051
+ .height = 58,
9971052 },
9981053 .bus_format = MEDIA_BUS_FMT_RGB888_1X24,
9991054 };
....@@ -1298,21 +1353,21 @@
12981353 },
12991354 };
13001355
1301
-static const struct drm_display_mode auo_g121ean01_mode = {
1302
- .clock = 66700,
1303
- .hdisplay = 1280,
1304
- .hsync_start = 1280 + 58,
1305
- .hsync_end = 1280 + 58 + 8,
1306
- .htotal = 1280 + 58 + 8 + 70,
1307
- .vdisplay = 800,
1308
- .vsync_start = 800 + 6,
1309
- .vsync_end = 800 + 6 + 4,
1310
- .vtotal = 800 + 6 + 4 + 10,
1356
+static const struct display_timing auo_g121ean01_timing = {
1357
+ .pixelclock = { 60000000, 74400000, 90000000 },
1358
+ .hactive = { 1280, 1280, 1280 },
1359
+ .hfront_porch = { 20, 50, 100 },
1360
+ .hback_porch = { 20, 50, 100 },
1361
+ .hsync_len = { 30, 100, 200 },
1362
+ .vactive = { 800, 800, 800 },
1363
+ .vfront_porch = { 2, 10, 25 },
1364
+ .vback_porch = { 2, 10, 25 },
1365
+ .vsync_len = { 4, 18, 50 },
13111366 };
13121367
13131368 static const struct panel_desc auo_g121ean01 = {
1314
- .modes = &auo_g121ean01_mode,
1315
- .num_modes = 1,
1369
+ .timings = &auo_g121ean01_timing,
1370
+ .num_timings = 1,
13161371 .bpc = 8,
13171372 .size = {
13181373 .width = 261,
....@@ -1488,7 +1543,9 @@
14881543 .delay = {
14891544 .disable = 5,
14901545 .unprepare = 1000,
1491
- }
1546
+ },
1547
+ .bus_format = MEDIA_BUS_FMT_RGB888_1X7X4_SPWG,
1548
+ .connector_type = DRM_MODE_CONNECTOR_LVDS,
14921549 };
14931550
14941551 static const struct drm_display_mode avic_tm070ddh03_mode = {
....@@ -2379,6 +2436,7 @@
23792436 .height = 54,
23802437 },
23812438 .bus_format = MEDIA_BUS_FMT_RGB888_1X24,
2439
+ .connector_type = DRM_MODE_CONNECTOR_DPI,
23822440 .bus_flags = DRM_BUS_FLAG_DE_HIGH | DRM_BUS_FLAG_PIXDATA_DRIVE_POSEDGE,
23832441 };
23842442
....@@ -3440,6 +3498,7 @@
34403498 .vsync_start = 480 + 49,
34413499 .vsync_end = 480 + 49 + 2,
34423500 .vtotal = 480 + 49 + 2 + 22,
3501
+ .flags = DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NHSYNC,
34433502 };
34443503
34453504 static const struct panel_desc powertip_ph800480t013_idf02 = {
....@@ -5109,6 +5168,113 @@
51095168 .shutdown = panel_simple_dsi_shutdown,
51105169 };
51115170
5171
+static int panel_simple_spi_read(struct device *dev, const u8 cmd, u8 *data)
5172
+{
5173
+ return 0;
5174
+}
5175
+
5176
+static int panel_simple_spi_write_word(struct device *dev, u16 data)
5177
+{
5178
+ struct spi_device *spi = to_spi_device(dev);
5179
+ struct spi_transfer xfer = {
5180
+ .len = 2,
5181
+ .tx_buf = &data,
5182
+ };
5183
+ struct spi_message msg;
5184
+
5185
+ spi_message_init(&msg);
5186
+ spi_message_add_tail(&xfer, &msg);
5187
+
5188
+ return spi_sync(spi, &msg);
5189
+}
5190
+
5191
+static int panel_simple_spi_write(struct device *dev, const u8 *data, size_t len, u8 type)
5192
+{
5193
+ int ret = 0;
5194
+ int i;
5195
+ u16 mask = type ? 0x100 : 0;
5196
+
5197
+ for (i = 0; i < len; i++) {
5198
+ ret = panel_simple_spi_write_word(dev, *data | mask);
5199
+ if (ret) {
5200
+ dev_err(dev, "failed to write spi seq: %*ph\n", (int)len, data);
5201
+ return ret;
5202
+ }
5203
+ data++;
5204
+ }
5205
+
5206
+ return ret;
5207
+}
5208
+
5209
+static const struct of_device_id panel_simple_spi_of_match[] = {
5210
+ { .compatible = "simple-panel-spi", .data = NULL },
5211
+ { /* sentinel */ }
5212
+};
5213
+MODULE_DEVICE_TABLE(of, panel_simple_spi_of_match);
5214
+
5215
+static int panel_simple_spi_probe(struct spi_device *spi)
5216
+{
5217
+ struct device *dev = &spi->dev;
5218
+ const struct of_device_id *id;
5219
+ const struct panel_desc *desc;
5220
+ struct panel_desc *d;
5221
+ int ret;
5222
+
5223
+ id = of_match_node(panel_simple_spi_of_match, dev->of_node);
5224
+ if (!id)
5225
+ return -ENODEV;
5226
+
5227
+ if (!id->data) {
5228
+ d = devm_kzalloc(dev, sizeof(*d), GFP_KERNEL);
5229
+ if (!d)
5230
+ return -ENOMEM;
5231
+
5232
+ ret = panel_simple_of_get_desc_data(dev, d);
5233
+ if (ret) {
5234
+ dev_err(dev, "failed to get desc data: %d\n", ret);
5235
+ return ret;
5236
+ }
5237
+
5238
+ d->spi_write = panel_simple_spi_write;
5239
+ d->spi_read = panel_simple_spi_read;
5240
+ d->cmd_type = CMD_TYPE_SPI;
5241
+ }
5242
+ desc = id->data ? id->data : d;
5243
+
5244
+ /*
5245
+ * Set spi to 3 lines and 9bits/word mode.
5246
+ */
5247
+ spi->bits_per_word = 9;
5248
+ spi->mode = SPI_MODE_3;
5249
+ ret = spi_setup(spi);
5250
+ if (ret < 0) {
5251
+ dev_err(dev, "spi setup failed.\n");
5252
+ return ret;
5253
+ }
5254
+
5255
+ return panel_simple_probe(dev, desc);
5256
+}
5257
+
5258
+static int panel_simple_spi_remove(struct spi_device *spi)
5259
+{
5260
+ return panel_simple_remove(&spi->dev);
5261
+}
5262
+
5263
+static void panel_simple_spi_shutdown(struct spi_device *spi)
5264
+{
5265
+ panel_simple_shutdown(&spi->dev);
5266
+}
5267
+
5268
+static struct spi_driver panel_simple_spi_driver = {
5269
+ .driver = {
5270
+ .name = "panel-simple-spi",
5271
+ .of_match_table = panel_simple_spi_of_match,
5272
+ },
5273
+ .probe = panel_simple_spi_probe,
5274
+ .remove = panel_simple_spi_remove,
5275
+ .shutdown = panel_simple_spi_shutdown,
5276
+};
5277
+
51125278 static int __init panel_simple_init(void)
51135279 {
51145280 int err;
....@@ -5116,6 +5282,12 @@
51165282 err = platform_driver_register(&panel_simple_platform_driver);
51175283 if (err < 0)
51185284 return err;
5285
+
5286
+ if (IS_ENABLED(CONFIG_SPI_MASTER)) {
5287
+ err = spi_register_driver(&panel_simple_spi_driver);
5288
+ if (err < 0)
5289
+ return err;
5290
+ }
51195291
51205292 if (IS_ENABLED(CONFIG_DRM_MIPI_DSI)) {
51215293 err = mipi_dsi_driver_register(&panel_simple_dsi_driver);
....@@ -5132,6 +5304,9 @@
51325304 if (IS_ENABLED(CONFIG_DRM_MIPI_DSI))
51335305 mipi_dsi_driver_unregister(&panel_simple_dsi_driver);
51345306
5307
+ if (IS_ENABLED(CONFIG_SPI_MASTER))
5308
+ spi_unregister_driver(&panel_simple_spi_driver);
5309
+
51355310 platform_driver_unregister(&panel_simple_platform_driver);
51365311 }
51375312 module_exit(panel_simple_exit);