18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (c) 2014-2015, The Linux Foundation. All rights reserved.
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#include "edp.h"
78c2ecf20Sopenharmony_ci#include "edp.xml.h"
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#define EDP_MAX_LANE	4
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_cistruct edp_phy {
128c2ecf20Sopenharmony_ci	void __iomem *base;
138c2ecf20Sopenharmony_ci};
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_cibool msm_edp_phy_ready(struct edp_phy *phy)
168c2ecf20Sopenharmony_ci{
178c2ecf20Sopenharmony_ci	u32 status;
188c2ecf20Sopenharmony_ci	int cnt = 100;
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci	while (--cnt) {
218c2ecf20Sopenharmony_ci		status = edp_read(phy->base +
228c2ecf20Sopenharmony_ci				REG_EDP_PHY_GLB_PHY_STATUS);
238c2ecf20Sopenharmony_ci		if (status & 0x01)
248c2ecf20Sopenharmony_ci			break;
258c2ecf20Sopenharmony_ci		usleep_range(500, 1000);
268c2ecf20Sopenharmony_ci	}
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci	if (cnt == 0) {
298c2ecf20Sopenharmony_ci		pr_err("%s: PHY NOT ready\n", __func__);
308c2ecf20Sopenharmony_ci		return false;
318c2ecf20Sopenharmony_ci	} else {
328c2ecf20Sopenharmony_ci		return true;
338c2ecf20Sopenharmony_ci	}
348c2ecf20Sopenharmony_ci}
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_civoid msm_edp_phy_ctrl(struct edp_phy *phy, int enable)
378c2ecf20Sopenharmony_ci{
388c2ecf20Sopenharmony_ci	DBG("enable=%d", enable);
398c2ecf20Sopenharmony_ci	if (enable) {
408c2ecf20Sopenharmony_ci		/* Reset */
418c2ecf20Sopenharmony_ci		edp_write(phy->base + REG_EDP_PHY_CTRL,
428c2ecf20Sopenharmony_ci			EDP_PHY_CTRL_SW_RESET | EDP_PHY_CTRL_SW_RESET_PLL);
438c2ecf20Sopenharmony_ci		/* Make sure fully reset */
448c2ecf20Sopenharmony_ci		wmb();
458c2ecf20Sopenharmony_ci		usleep_range(500, 1000);
468c2ecf20Sopenharmony_ci		edp_write(phy->base + REG_EDP_PHY_CTRL, 0x000);
478c2ecf20Sopenharmony_ci		edp_write(phy->base + REG_EDP_PHY_GLB_PD_CTL, 0x3f);
488c2ecf20Sopenharmony_ci		edp_write(phy->base + REG_EDP_PHY_GLB_CFG, 0x1);
498c2ecf20Sopenharmony_ci	} else {
508c2ecf20Sopenharmony_ci		edp_write(phy->base + REG_EDP_PHY_GLB_PD_CTL, 0xc0);
518c2ecf20Sopenharmony_ci	}
528c2ecf20Sopenharmony_ci}
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci/* voltage mode and pre emphasis cfg */
558c2ecf20Sopenharmony_civoid msm_edp_phy_vm_pe_init(struct edp_phy *phy)
568c2ecf20Sopenharmony_ci{
578c2ecf20Sopenharmony_ci	edp_write(phy->base + REG_EDP_PHY_GLB_VM_CFG0, 0x3);
588c2ecf20Sopenharmony_ci	edp_write(phy->base + REG_EDP_PHY_GLB_VM_CFG1, 0x64);
598c2ecf20Sopenharmony_ci	edp_write(phy->base + REG_EDP_PHY_GLB_MISC9, 0x6c);
608c2ecf20Sopenharmony_ci}
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_civoid msm_edp_phy_vm_pe_cfg(struct edp_phy *phy, u32 v0, u32 v1)
638c2ecf20Sopenharmony_ci{
648c2ecf20Sopenharmony_ci	edp_write(phy->base + REG_EDP_PHY_GLB_VM_CFG0, v0);
658c2ecf20Sopenharmony_ci	edp_write(phy->base + REG_EDP_PHY_GLB_VM_CFG1, v1);
668c2ecf20Sopenharmony_ci}
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_civoid msm_edp_phy_lane_power_ctrl(struct edp_phy *phy, bool up, u32 max_lane)
698c2ecf20Sopenharmony_ci{
708c2ecf20Sopenharmony_ci	u32 i;
718c2ecf20Sopenharmony_ci	u32 data;
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci	if (up)
748c2ecf20Sopenharmony_ci		data = 0;	/* power up */
758c2ecf20Sopenharmony_ci	else
768c2ecf20Sopenharmony_ci		data = 0x7;	/* power down */
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci	for (i = 0; i < max_lane; i++)
798c2ecf20Sopenharmony_ci		edp_write(phy->base + REG_EDP_PHY_LN_PD_CTL(i) , data);
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci	/* power down unused lane */
828c2ecf20Sopenharmony_ci	data = 0x7;	/* power down */
838c2ecf20Sopenharmony_ci	for (i = max_lane; i < EDP_MAX_LANE; i++)
848c2ecf20Sopenharmony_ci		edp_write(phy->base + REG_EDP_PHY_LN_PD_CTL(i) , data);
858c2ecf20Sopenharmony_ci}
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_civoid *msm_edp_phy_init(struct device *dev, void __iomem *regbase)
888c2ecf20Sopenharmony_ci{
898c2ecf20Sopenharmony_ci	struct edp_phy *phy = NULL;
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci	phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL);
928c2ecf20Sopenharmony_ci	if (!phy)
938c2ecf20Sopenharmony_ci		return NULL;
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci	phy->base = regbase;
968c2ecf20Sopenharmony_ci	return phy;
978c2ecf20Sopenharmony_ci}
988c2ecf20Sopenharmony_ci
99