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