1 /* 2 * (C) Copyright 2008-2017 Fuzhou Rockchip Electronics Co., Ltd 3 * 4 * SPDX-License-Identifier: GPL-2.0+ 5 */ 6 7 #include <config.h> 8 #include <common.h> 9 #include <dm/device.h> 10 #include <errno.h> 11 #include <asm/unaligned.h> 12 #include <linux/list.h> 13 14 #include "rockchip_display.h" 15 #include "rockchip_crtc.h" 16 #include "rockchip_connector.h" 17 #include "rockchip_phy.h" 18 19 #ifdef CONFIG_DRM_ROCKCHIP_DW_MIPI_DSI 20 static const struct rockchip_phy rockchip_inno_mipi_dphy_data = { 21 .funcs = &inno_mipi_dphy_funcs, 22 }; 23 #endif 24 25 #ifdef CONFIG_ROCKCHIP_INNO_HDMI_PHY 26 static const struct rockchip_phy rockchip_inno_hdmi_phy_data = { 27 .funcs = &inno_hdmi_phy_funcs, 28 }; 29 #endif 30 31 static const struct udevice_id rockchip_phy_ids[] = { 32 #ifdef CONFIG_DRM_ROCKCHIP_DW_MIPI_DSI 33 { 34 .compatible = "rockchip,px30-mipi-dphy", 35 .data = (ulong)&rockchip_inno_mipi_dphy_data, 36 }, 37 { 38 .compatible = "rockchip,rk3128-mipi-dphy", 39 .data = (ulong)&rockchip_inno_mipi_dphy_data, 40 }, 41 { 42 .compatible = "rockchip,rk3366-mipi-dphy", 43 .data = (ulong)&rockchip_inno_mipi_dphy_data, 44 }, 45 { 46 .compatible = "rockchip,rk3368-mipi-dphy", 47 .data = (ulong)&rockchip_inno_mipi_dphy_data, 48 }, 49 { 50 .compatible = "rockchip,rv1108-mipi-dphy", 51 .data = (ulong)&rockchip_inno_mipi_dphy_data, 52 }, 53 #endif 54 #ifdef CONFIG_ROCKCHIP_INNO_HDMI_PHY 55 { 56 .compatible = "rockchip,rk3328-hdmi-phy", 57 .data = (ulong)&rockchip_inno_hdmi_phy_data, 58 }, 59 { 60 .compatible = "rockchip,rk3228-hdmi-phy", 61 .data = (ulong)&rockchip_inno_hdmi_phy_data, 62 }, 63 64 #endif 65 {} 66 }; 67 68 static int rockchip_phy_probe(struct udevice *dev) 69 { 70 return 0; 71 } 72 73 static int rockchip_phy_bind(struct udevice *dev) 74 { 75 return 0; 76 } 77 78 U_BOOT_DRIVER(rockchip_phy) = { 79 .name = "rockchip_phy", 80 .id = UCLASS_PHY, 81 .of_match = rockchip_phy_ids, 82 .bind = rockchip_phy_bind, 83 .probe = rockchip_phy_probe, 84 }; 85 86 int rockchip_phy_power_on(struct display_state *state) 87 { 88 struct connector_state *conn_state = &state->conn_state; 89 const struct rockchip_phy *phy = conn_state->phy; 90 91 if (!phy || !phy->funcs || !phy->funcs->power_on) { 92 printf("%s: failed to find phy power on funcs\n", __func__); 93 return -ENODEV; 94 } 95 96 return phy->funcs->power_on(state); 97 } 98 99 int rockchip_phy_power_off(struct display_state *state) 100 { 101 struct connector_state *conn_state = &state->conn_state; 102 const struct rockchip_phy *phy = conn_state->phy; 103 104 if (!phy || !phy->funcs || !phy->funcs->power_off) { 105 printf("%s: failed to find phy power_off funcs\n", __func__); 106 return -ENODEV; 107 } 108 109 return phy->funcs->power_off(state); 110 } 111 112 unsigned long rockchip_phy_set_pll(struct display_state *state, 113 unsigned long rate) 114 { 115 struct connector_state *conn_state = &state->conn_state; 116 const struct rockchip_phy *phy = conn_state->phy; 117 118 if (!phy || !phy->funcs || !phy->funcs->set_pll) { 119 printf("%s: failed to find phy set_pll funcs\n", __func__); 120 return -ENODEV; 121 } 122 123 return phy->funcs->set_pll(state, rate); 124 } 125 126 void rockchip_phy_set_bus_width(struct display_state *state, u32 bus_width) 127 { 128 struct connector_state *conn_state = &state->conn_state; 129 const struct rockchip_phy *phy = 130 (struct rockchip_phy *)conn_state->phy; 131 132 if (!phy || !phy->funcs || !phy->funcs->set_bus_width) { 133 debug("%s: failed to find phy set_bus_width funcs\n", __func__); 134 return; 135 } 136 137 return phy->funcs->set_bus_width(state, bus_width); 138 } 139 140 long rockchip_phy_round_rate(struct display_state *state, unsigned long rate) 141 { 142 struct connector_state *conn_state = &state->conn_state; 143 const struct rockchip_phy *phy = 144 (struct rockchip_phy *)conn_state->phy; 145 146 if (!phy || !phy->funcs || !phy->funcs->round_rate) { 147 debug("%s: failed to find phy round_rate funcs\n", __func__); 148 return -ENODEV; 149 } 150 151 return phy->funcs->round_rate(state, rate); 152 } 153