blob: 7025ac986e3ceb34f95264dcf7e40f9f3fa1a559 [file] [log] [blame]
Yannick Fertré9712c822019-10-07 15:29:05 +02001// SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
2/*
3 * Copyright (C) 2019, STMicroelectronics - All Rights Reserved
4 */
5
Yannick Fertré9712c822019-10-07 15:29:05 +02006#include <display.h>
7#include <dm.h>
8#include <dsi_host.h>
9
10/**
11 * struct sandbox_dsi_host_priv - private data for driver
12 * @device: DSI peripheral device
13 * @timing: Display timings
14 * @max_data_lanes: maximum number of data lines
15 * @phy_ops: set of function pointers for performing physical operations
16 */
17struct sandbox_dsi_host_priv {
18 struct mipi_dsi_device *device;
19 struct display_timing *timings;
20 unsigned int max_data_lanes;
21 const struct mipi_dsi_phy_ops *phy_ops;
22};
23
24static int sandbox_dsi_host_init(struct udevice *dev,
25 struct mipi_dsi_device *device,
26 struct display_timing *timings,
27 unsigned int max_data_lanes,
28 const struct mipi_dsi_phy_ops *phy_ops)
29{
30 struct sandbox_dsi_host_priv *priv = dev_get_priv(dev);
31
32 if (!device)
33 return -1;
34
35 if (!timings)
36 return -2;
37
38 if (max_data_lanes == 0)
39 return -3;
40
41 if (!phy_ops)
42 return -4;
43
44 if (!phy_ops->init || !phy_ops->get_lane_mbps ||
45 !phy_ops->post_set_mode)
46 return -5;
47
48 priv->max_data_lanes = max_data_lanes;
49 priv->phy_ops = phy_ops;
50 priv->timings = timings;
51 priv->device = device;
52
53 return 0;
54}
55
56static int sandbox_dsi_host_enable(struct udevice *dev)
57{
58 struct sandbox_dsi_host_priv *priv = dev_get_priv(dev);
59 unsigned int lane_mbps;
60 int ret;
61
62 priv->phy_ops->init(priv->device);
63 ret = priv->phy_ops->get_lane_mbps(priv->device, priv->timings, 2,
64 MIPI_DSI_FMT_RGB888, &lane_mbps);
65 if (ret)
66 return -1;
67
68 priv->phy_ops->post_set_mode(priv->device, MIPI_DSI_MODE_VIDEO);
69
70 return 0;
71}
72
73struct dsi_host_ops sandbox_dsi_host_ops = {
74 .init = sandbox_dsi_host_init,
75 .enable = sandbox_dsi_host_enable,
76};
77
78static const struct udevice_id sandbox_dsi_host_ids[] = {
79 { .compatible = "sandbox,dsi-host"},
80 { }
81};
82
83U_BOOT_DRIVER(sandbox_dsi_host) = {
84 .name = "sandbox-dsi-host",
85 .id = UCLASS_DSI_HOST,
86 .of_match = sandbox_dsi_host_ids,
87 .ops = &sandbox_dsi_host_ops,
Simon Glass8a2b47f2020-12-03 16:55:17 -070088 .priv_auto = sizeof(struct sandbox_dsi_host_priv),
Yannick Fertré9712c822019-10-07 15:29:05 +020089};