4 * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published by
8 * the Free Software Foundation.
11 #include <linux/kernel.h>
12 #include <linux/err.h>
14 #include <linux/platform_device.h>
15 #include <linux/slab.h>
16 #include <linux/seq_file.h>
22 void hdmi_phy_dump(struct hdmi_phy_data
*phy
, struct seq_file
*s
)
24 #define DUMPPHY(r) seq_printf(s, "%-35s %08x\n", #r,\
25 hdmi_read_reg(phy->base, r))
27 DUMPPHY(HDMI_TXPHY_TX_CTRL
);
28 DUMPPHY(HDMI_TXPHY_DIGITAL_CTRL
);
29 DUMPPHY(HDMI_TXPHY_POWER_CTRL
);
30 DUMPPHY(HDMI_TXPHY_PAD_CFG_CTRL
);
31 if (phy
->features
->bist_ctrl
)
32 DUMPPHY(HDMI_TXPHY_BIST_CONTROL
);
35 int hdmi_phy_parse_lanes(struct hdmi_phy_data
*phy
, const u32
*lanes
)
39 for (i
= 0; i
< 8; i
+= 2) {
46 if (dx
< 0 || dx
>= 8)
49 if (dy
< 0 || dy
>= 8)
64 phy
->lane_function
[lane
] = i
/ 2;
65 phy
->lane_polarity
[lane
] = pol
;
71 static void hdmi_phy_configure_lanes(struct hdmi_phy_data
*phy
)
73 static const u16 pad_cfg_list
[] = {
102 unsigned lane_cfg_val
;
105 for (i
= 0; i
< 4; ++i
)
106 lane_cfg
|= phy
->lane_function
[i
] << ((3 - i
) * 4);
108 pol_val
|= phy
->lane_polarity
[0] << 0;
109 pol_val
|= phy
->lane_polarity
[1] << 3;
110 pol_val
|= phy
->lane_polarity
[2] << 2;
111 pol_val
|= phy
->lane_polarity
[3] << 1;
113 for (i
= 0; i
< ARRAY_SIZE(pad_cfg_list
); ++i
)
114 if (pad_cfg_list
[i
] == lane_cfg
)
117 if (WARN_ON(i
== ARRAY_SIZE(pad_cfg_list
)))
122 REG_FLD_MOD(phy
->base
, HDMI_TXPHY_PAD_CFG_CTRL
, lane_cfg_val
, 26, 22);
123 REG_FLD_MOD(phy
->base
, HDMI_TXPHY_PAD_CFG_CTRL
, pol_val
, 30, 27);
126 int hdmi_phy_configure(struct hdmi_phy_data
*phy
, unsigned long hfbitclk
,
127 unsigned long lfbitclk
)
132 * Read address 0 in order to get the SCP reset done completed
133 * Dummy access performed to make sure reset is done
135 hdmi_read_reg(phy
->base
, HDMI_TXPHY_TX_CTRL
);
138 * In OMAP5+, the HFBITCLK must be divided by 2 before issuing the
139 * HDMI_PHYPWRCMD_LDOON command.
141 if (phy
->features
->bist_ctrl
)
142 REG_FLD_MOD(phy
->base
, HDMI_TXPHY_BIST_CONTROL
, 1, 11, 11);
145 * If the hfbitclk != lfbitclk, it means the lfbitclk was configured
146 * to be used for TMDS.
148 if (hfbitclk
!= lfbitclk
)
150 else if (hfbitclk
/ 10 < phy
->features
->max_phy
)
156 * Write to phy address 0 to configure the clock
157 * use HFBITCLK write HDMI_TXPHY_TX_CONTROL_FREQOUT field
159 REG_FLD_MOD(phy
->base
, HDMI_TXPHY_TX_CTRL
, freqout
, 31, 30);
161 /* Write to phy address 1 to start HDMI line (TXVALID and TMDSCLKEN) */
162 hdmi_write_reg(phy
->base
, HDMI_TXPHY_DIGITAL_CTRL
, 0xF0000000);
164 /* Setup max LDO voltage */
165 if (phy
->features
->ldo_voltage
)
166 REG_FLD_MOD(phy
->base
, HDMI_TXPHY_POWER_CTRL
, 0xB, 3, 0);
168 hdmi_phy_configure_lanes(phy
);
173 static const struct hdmi_phy_features omap44xx_phy_feats
= {
176 .max_phy
= 185675000,
179 static const struct hdmi_phy_features omap54xx_phy_feats
= {
181 .ldo_voltage
= false,
182 .max_phy
= 186000000,
185 int hdmi_phy_init(struct platform_device
*pdev
, struct hdmi_phy_data
*phy
,
186 unsigned int version
)
188 struct resource
*res
;
191 phy
->features
= &omap44xx_phy_feats
;
193 phy
->features
= &omap54xx_phy_feats
;
195 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
, "phy");
196 phy
->base
= devm_ioremap_resource(&pdev
->dev
, res
);
197 if (IS_ERR(phy
->base
))
198 return PTR_ERR(phy
->base
);