Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c52ebbd3 authored by Tony Truong's avatar Tony Truong Committed by Gerrit - the friendly Code Review server
Browse files

mhi: core: Read the EXEC_ENV from device



Read the EXEC_ENV register from device to determine the MHI
base state.

Change-Id: Id70a360cfa3775a7186e5059306385a37960df2d
Signed-off-by: default avatarAndrei Danaila <adanaila@codeaurora.org>
Signed-off-by: default avatarTony Truong <truong@codeaurora.org>
parent 87093e20
Loading
Loading
Loading
Loading
+0 −5
Original line number Diff line number Diff line
@@ -170,17 +170,12 @@ int bhi_probe(struct mhi_pcie_dev_info *mhi_pcie_device)
{
	struct bhi_ctxt_t *bhi_ctxt = &mhi_pcie_device->bhi_ctxt;
	int ret_val = 0;
	u32 pcie_word_val = 0;
	int r;

	if (NULL == mhi_pcie_device || 0 == mhi_pcie_device->core.bar0_base
	    || 0 == mhi_pcie_device->core.bar0_end)
		return -EIO;

	bhi_ctxt->bhi_base = mhi_pcie_device->core.bar0_base;
	pcie_word_val = mhi_reg_read(bhi_ctxt->bhi_base, BHIOFF);
	bhi_ctxt->bhi_base += pcie_word_val;

	mhi_log(MHI_MSG_INFO,
		"Successfully registered char dev. bhi base is: 0x%p.\n",
		bhi_ctxt->bhi_base);
+1 −8
Original line number Diff line number Diff line
@@ -167,17 +167,10 @@ int mhi_ctxt_init(struct mhi_pcie_dev_info *mhi_pcie_dev)
	pcie_device->dev.platform_data = &mhi_pcie_dev->mhi_ctxt;
	mhi_pcie_dev->mhi_ctxt.dev_info->plat_dev->dev.platform_data =
						&mhi_pcie_dev->mhi_ctxt;
	if (mhi_pcie_dev->mhi_ctxt.base_state == STATE_TRANSITION_BHI) {
		ret_val = bhi_probe(mhi_pcie_dev);
		if (ret_val) {
			mhi_log(MHI_MSG_ERROR, "Failed to initialize BHI.\n");
			goto mhi_state_transition_error;
		}
	}
	ret_val = mhi_reg_notifiers(&mhi_pcie_dev->mhi_ctxt);
	if (ret_val) {
		mhi_log(MHI_MSG_ERROR, "Failed to register for notifiers\n");
		return ret_val;
		goto mhi_state_transition_error;
	}
	mhi_log(MHI_MSG_INFO,
			"Finished all driver probing returning ret_val %d.\n",
+34 −18
Original line number Diff line number Diff line
@@ -12,6 +12,8 @@

#include <mhi_sys.h>
#include <mhi.h>
#include <mhi_bhi.h>
#include <mhi_hwio.h>

#include <soc/qcom/subsystem_restart.h>
#include <soc/qcom/subsystem_notif.h>
@@ -79,19 +81,6 @@ static struct notifier_block mhi_ssr_nb = {
	.notifier_call = mhi_ssr_notify_cb,
};

static void esoc_parse_link_type(struct mhi_device_ctxt *mhi_dev_ctxt)
{
	int ret_val;

	ret_val = strcmp(mhi_dev_ctxt->esoc_handle->link, "HSIC+PCIe");
	mhi_log(MHI_MSG_VERBOSE, "Link type is %s as indicated by ESOC\n",
					mhi_dev_ctxt->esoc_handle->link);
	if (ret_val)
		mhi_dev_ctxt->base_state = STATE_TRANSITION_BHI;
	else
		mhi_dev_ctxt->base_state = STATE_TRANSITION_RESET;
}

int mhi_esoc_register(struct mhi_device_ctxt *mhi_dev_ctxt)
{
	int ret_val = 0;
@@ -99,7 +88,6 @@ int mhi_esoc_register(struct mhi_device_ctxt *mhi_dev_ctxt)
	struct pci_driver *mhi_driver;
	struct device *dev = &mhi_dev_ctxt->dev_info->pcie_device->dev;

	mhi_dev_ctxt->base_state = STATE_TRANSITION_BHI;
	mhi_driver = mhi_dev_ctxt->dev_info->mhi_pcie_driver;
	np = dev->of_node;
	mhi_dev_ctxt->esoc_handle = devm_register_esoc_client(dev, "mdm");
@@ -113,8 +101,6 @@ int mhi_esoc_register(struct mhi_device_ctxt *mhi_dev_ctxt)
		return -EIO;
	}

	esoc_parse_link_type(mhi_dev_ctxt);

	mhi_dev_ctxt->esoc_ssr_handle = subsys_notif_register_notifier(
					mhi_dev_ctxt->esoc_handle->name,
					&mhi_ssr_nb);
@@ -162,6 +148,34 @@ void mhi_notify_clients(struct mhi_device_ctxt *mhi_dev_ctxt,
	}
}

static int set_mhi_base_state(struct mhi_pcie_dev_info *mhi_pcie_dev)
{
	u32 pcie_word_val = 0;
	int r = 0;
	struct mhi_device_ctxt *mhi_dev_ctxt = &mhi_pcie_dev->mhi_ctxt;

	mhi_pcie_dev->bhi_ctxt.bhi_base = mhi_pcie_dev->core.bar0_base;
	pcie_word_val = mhi_reg_read(mhi_pcie_dev->bhi_ctxt.bhi_base, BHIOFF);
	mhi_pcie_dev->bhi_ctxt.bhi_base += pcie_word_val;
	pcie_word_val = mhi_reg_read(mhi_pcie_dev->bhi_ctxt.bhi_base,
				     BHI_EXECENV);
	if (pcie_word_val == MHI_EXEC_ENV_AMSS) {
		mhi_dev_ctxt->base_state = STATE_TRANSITION_RESET;
	} else if (pcie_word_val == MHI_EXEC_ENV_PBL) {
		mhi_dev_ctxt->base_state = STATE_TRANSITION_BHI;
		r = bhi_probe(mhi_pcie_dev);
		if (r)
			mhi_log(MHI_MSG_ERROR, "Failed to initialize BHI.\n");
	} else {
		mhi_log(MHI_MSG_ERROR, "Invalid EXEC_ENV: 0x%x\n",
			pcie_word_val);
		r = -EIO;
	}
	mhi_log(MHI_MSG_INFO, "EXEC_ENV: %d Base state %d\n",
		pcie_word_val, mhi_dev_ctxt->base_state);
	return r;
}

void mhi_link_state_cb(struct msm_pcie_notify *notify)
{
	int ret_val = 0;
@@ -200,6 +214,9 @@ void mhi_link_state_cb(struct msm_pcie_notify *notify)
				mhi_dev_ctxt = &mhi_pcie_dev->mhi_ctxt;
				mhi_pcie_dev->mhi_ctxt.flags.link_up = 1;
				pci_set_master(mhi_pcie_dev->pcie_device);
				r = set_mhi_base_state(mhi_pcie_dev);
				if (r)
					return;
				init_mhi_base_state(mhi_dev_ctxt);
		} else {
			mhi_log(MHI_MSG_INFO,
@@ -242,8 +259,7 @@ int init_mhi_base_state(struct mhi_device_ctxt *mhi_dev_ctxt)
	if (r)
		mhi_log(MHI_MSG_INFO,
			"Failed to scale bus request to active set.\n");
	r = mhi_init_state_transition(mhi_dev_ctxt,
			mhi_dev_ctxt->base_state);
	r = mhi_init_state_transition(mhi_dev_ctxt, mhi_dev_ctxt->base_state);
	if (r) {
		mhi_log(MHI_MSG_CRITICAL,
		"Failed to start state change event, to %d\n",