1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (C) 2013 Texas Instruments Incorporated - https://www.ti.com/
8 #include <linux/kernel.h>
11 #include <linux/platform_device.h>
12 #include <linux/slab.h>
13 #include <linux/seq_file.h>
19 void hdmi_phy_dump(struct hdmi_phy_data *phy, struct seq_file *s)
21 #define DUMPPHY(r) seq_printf(s, "%-35s %08x\n", #r,\
22 hdmi_read_reg(phy->base, r))
24 DUMPPHY(HDMI_TXPHY_TX_CTRL);
25 DUMPPHY(HDMI_TXPHY_DIGITAL_CTRL);
26 DUMPPHY(HDMI_TXPHY_POWER_CTRL);
27 DUMPPHY(HDMI_TXPHY_PAD_CFG_CTRL);
28 if (phy->features->bist_ctrl)
29 DUMPPHY(HDMI_TXPHY_BIST_CONTROL);
32 int hdmi_phy_parse_lanes(struct hdmi_phy_data *phy, const u32 *lanes)
36 for (i = 0; i < 8; i += 2) {
43 if (dx < 0 || dx >= 8)
46 if (dy < 0 || dy >= 8)
61 phy->lane_function[lane] = i / 2;
62 phy->lane_polarity[lane] = pol;
68 static void hdmi_phy_configure_lanes(struct hdmi_phy_data *phy)
70 static const u16 pad_cfg_list[] = {
99 unsigned int lane_cfg_val;
102 for (i = 0; i < 4; ++i)
103 lane_cfg |= phy->lane_function[i] << ((3 - i) * 4);
105 pol_val |= phy->lane_polarity[0] << 0;
106 pol_val |= phy->lane_polarity[1] << 3;
107 pol_val |= phy->lane_polarity[2] << 2;
108 pol_val |= phy->lane_polarity[3] << 1;
110 for (i = 0; i < ARRAY_SIZE(pad_cfg_list); ++i)
111 if (pad_cfg_list[i] == lane_cfg)
114 if (WARN_ON(i == ARRAY_SIZE(pad_cfg_list)))
119 REG_FLD_MOD(phy->base, HDMI_TXPHY_PAD_CFG_CTRL, lane_cfg_val, 26, 22);
120 REG_FLD_MOD(phy->base, HDMI_TXPHY_PAD_CFG_CTRL, pol_val, 30, 27);
123 int hdmi_phy_configure(struct hdmi_phy_data *phy, unsigned long hfbitclk,
124 unsigned long lfbitclk)
129 * Read address 0 in order to get the SCP reset done completed
130 * Dummy access performed to make sure reset is done
132 hdmi_read_reg(phy->base, HDMI_TXPHY_TX_CTRL);
135 * In OMAP5+, the HFBITCLK must be divided by 2 before issuing the
136 * HDMI_PHYPWRCMD_LDOON command.
138 if (phy->features->bist_ctrl)
139 REG_FLD_MOD(phy->base, HDMI_TXPHY_BIST_CONTROL, 1, 11, 11);
142 * If the hfbitclk != lfbitclk, it means the lfbitclk was configured
143 * to be used for TMDS.
145 if (hfbitclk != lfbitclk)
147 else if (hfbitclk / 10 < phy->features->max_phy)
153 * Write to phy address 0 to configure the clock
154 * use HFBITCLK write HDMI_TXPHY_TX_CONTROL_FREQOUT field
156 REG_FLD_MOD(phy->base, HDMI_TXPHY_TX_CTRL, freqout, 31, 30);
158 /* Write to phy address 1 to start HDMI line (TXVALID and TMDSCLKEN) */
159 hdmi_write_reg(phy->base, HDMI_TXPHY_DIGITAL_CTRL, 0xF0000000);
161 /* Setup max LDO voltage */
162 if (phy->features->ldo_voltage)
163 REG_FLD_MOD(phy->base, HDMI_TXPHY_POWER_CTRL, 0xB, 3, 0);
165 hdmi_phy_configure_lanes(phy);
170 static const struct hdmi_phy_features omap44xx_phy_feats = {
173 .max_phy = 185675000,
176 static const struct hdmi_phy_features omap54xx_phy_feats = {
178 .ldo_voltage = false,
179 .max_phy = 186000000,
182 int hdmi_phy_init(struct platform_device *pdev, struct hdmi_phy_data *phy,
183 unsigned int version)
185 struct resource *res;
188 phy->features = &omap44xx_phy_feats;
190 phy->features = &omap54xx_phy_feats;
192 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "phy");
193 phy->base = devm_ioremap_resource(&pdev->dev, res);
194 if (IS_ERR(phy->base))
195 return PTR_ERR(phy->base);