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

Commit 6cb9e75f authored by Sujeev Dias's avatar Sujeev Dias
Browse files

mhi: core: Bind devices with variable PCIe device IDs with same device node



In order to bind devices with variable PCIe device IDs with same device
tree node, make PCIe device ID optional parameter in device tree node.
If PCIe device ID not specified in device tree, any device can be bind
with the node.

CRs-Fixed: 2040899
Change-Id: Iaedcb40db15fa0e8c5c30eb147c904a10cd7569d
Signed-off-by: default avatarSujeev Dias <sdias@codeaurora.org>
parent aa2cd681
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@ Main node properties:
  Definition: "qcom,mhi"

- qcom,pci-dev_id
  Usage: required
  Usage: optional
  Value type: <u32>
  Definition: Device id reported by modem

+28 −21
Original line number Diff line number Diff line
@@ -153,16 +153,19 @@ static int mhi_pci_probe(struct pci_dev *pcie_device,
	u32 slot = PCI_SLOT(pcie_device->devfn);
	unsigned long msi_requested, msi_required;
	struct msm_pcie_register_event *mhi_pci_link_event;
	struct pcie_core_info *core;
	int i;
	char node[32];

	/* Find correct device context based on bdf & dev_id */
	mutex_lock(&mhi_device_drv->lock);
	list_for_each_entry(itr, &mhi_device_drv->head, node) {
		struct pcie_core_info *core = &itr->core;

		if (core->domain == domain &&
		    core->bus == bus &&
		    core->dev_id == dev_id &&
		core = &itr->core;
		if (core->domain == domain && core->bus == bus &&
		    (core->dev_id == PCI_ANY_ID || (core->dev_id == dev_id)) &&
		    core->slot == slot) {
			/* change default dev_id to actual dev_id */
			core->dev_id = dev_id;
			mhi_dev_ctxt = itr;
			break;
		}
@@ -171,6 +174,11 @@ static int mhi_pci_probe(struct pci_dev *pcie_device,
	if (!mhi_dev_ctxt)
		return -EPROBE_DEFER;

	snprintf(node, sizeof(node), "mhi_%04x_%02u.%02u.%02u",
		 core->dev_id, core->domain, core->bus, core->slot);
	mhi_dev_ctxt->mhi_ipc_log =
		ipc_log_context_create(MHI_IPC_LOG_PAGES, node, 0);

	mhi_log(mhi_dev_ctxt, MHI_MSG_INFO,
		"Processing Domain:%02u Bus:%04u dev:0x%04x slot:%04u\n",
		domain, bus, dev_id, slot);
@@ -280,9 +288,22 @@ static int mhi_pci_probe(struct pci_dev *pcie_device,
	mutex_lock(&mhi_dev_ctxt->pm_lock);
	write_lock_irq(&mhi_dev_ctxt->pm_xfer_lock);
	mhi_dev_ctxt->mhi_pm_state = MHI_PM_POR;
	ret_val = set_mhi_base_state(mhi_dev_ctxt);
	write_unlock_irq(&mhi_dev_ctxt->pm_xfer_lock);

	/* notify all registered clients we probed */
	for (i = 0; i < MHI_MAX_CHANNELS; i++) {
		struct mhi_client_handle *client_handle =
			mhi_dev_ctxt->client_handle_list[i];

		if (!client_handle)
			continue;
		client_handle->dev_id = core->dev_id;
		mhi_notify_client(client_handle, MHI_CB_MHI_PROBED);
	}
	write_lock_irq(&mhi_dev_ctxt->pm_xfer_lock);
	ret_val = set_mhi_base_state(mhi_dev_ctxt);
	write_unlock_irq(&mhi_dev_ctxt->pm_xfer_lock);

	if (ret_val) {
		mhi_log(mhi_dev_ctxt,
			MHI_MSG_ERROR,
@@ -344,7 +365,6 @@ static int mhi_plat_probe(struct platform_device *pdev)
	int r = 0, len;
	struct mhi_device_ctxt *mhi_dev_ctxt;
	struct pcie_core_info *core;
	char node[32];
	struct device_node *of_node = pdev->dev.of_node;
	u64 address_window[2];

@@ -377,7 +397,7 @@ static int mhi_plat_probe(struct platform_device *pdev)
	core = &mhi_dev_ctxt->core;
	r = of_property_read_u32(of_node, "qcom,pci-dev_id", &core->dev_id);
	if (r)
		return r;
		core->dev_id = PCI_ANY_ID;

	r = of_property_read_u32(of_node, "qcom,pci-slot", &core->slot);
	if (r)
@@ -391,14 +411,6 @@ static int mhi_plat_probe(struct platform_device *pdev)
	if (r)
		return r;

	snprintf(node, sizeof(node),
		 "mhi_%04x_%02u.%02u.%02u",
		 core->dev_id, core->domain, core->bus, core->slot);
	mhi_dev_ctxt->mhi_ipc_log =
		ipc_log_context_create(MHI_IPC_LOG_PAGES, node, 0);
	if (!mhi_dev_ctxt->mhi_ipc_log)
		pr_err("%s: Error creating ipc_log buffer\n", __func__);

	r = of_property_read_u32(of_node, "qcom,mhi-ready-timeout",
				 &mhi_dev_ctxt->poll_reset_timeout_ms);
	if (r)
@@ -407,10 +419,6 @@ static int mhi_plat_probe(struct platform_device *pdev)

	mhi_dev_ctxt->dev_space.start_win_addr = address_window[0];
	mhi_dev_ctxt->dev_space.end_win_addr = address_window[1];
	mhi_log(mhi_dev_ctxt, MHI_MSG_INFO,
		"Start Addr:0x%llx End_Addr:0x%llx\n",
		mhi_dev_ctxt->dev_space.start_win_addr,
		mhi_dev_ctxt->dev_space.end_win_addr);

	r = of_property_read_u32(of_node, "qcom,bhi-alignment",
				 &mhi_dev_ctxt->bhi_ctxt.alignment);
@@ -471,7 +479,6 @@ static int mhi_plat_probe(struct platform_device *pdev)
	mutex_lock(&mhi_device_drv->lock);
	list_add_tail(&mhi_dev_ctxt->node, &mhi_device_drv->head);
	mutex_unlock(&mhi_device_drv->lock);
	mhi_log(mhi_dev_ctxt, MHI_MSG_INFO, "Exited\n");

	return 0;
}
+27 −11
Original line number Diff line number Diff line
@@ -563,6 +563,7 @@ int mhi_register_channel(struct mhi_client_handle **client_handle,
	(*client_handle)->domain = mhi_dev_ctxt->core.domain;
	(*client_handle)->bus = mhi_dev_ctxt->core.bus;
	(*client_handle)->slot = mhi_dev_ctxt->core.slot;
	(*client_handle)->enabled = false;
	client_config = (*client_handle)->client_config;
	client_config->mhi_dev_ctxt = mhi_dev_ctxt;
	client_config->user_data = client_info->user_data;
@@ -589,11 +590,8 @@ int mhi_register_channel(struct mhi_client_handle **client_handle,
	}

	if (mhi_dev_ctxt->dev_exec_env == MHI_EXEC_ENV_AMSS &&
	    mhi_dev_ctxt->flags.mhi_initialized) {
		mhi_log(mhi_dev_ctxt, MHI_MSG_INFO,
			"Exec env is AMSS notify client now chan:%u\n", chan);
		mhi_notify_client(*client_handle, MHI_CB_MHI_ENABLED);
	}
	    mhi_dev_ctxt->flags.mhi_initialized)
		(*client_handle)->enabled = true;

	mhi_log(mhi_dev_ctxt, MHI_MSG_VERBOSE,
		"Successfuly registered chan:%u\n", chan);
@@ -1790,6 +1788,8 @@ int mhi_register_device(struct mhi_device *mhi_device,
	u32 dev_id = pci_dev->device;
	u32 slot = PCI_SLOT(pci_dev->devfn);
	int ret, i;
	char node[32];
	struct pcie_core_info *core;

	of_node = of_parse_phandle(mhi_device->dev->of_node, node_name, 0);
	if (!of_node)
@@ -1802,13 +1802,13 @@ int mhi_register_device(struct mhi_device *mhi_device,
	mutex_lock(&mhi_device_drv->lock);
	list_for_each_entry(itr, &mhi_device_drv->head, node) {
		struct platform_device *pdev = itr->plat_dev;
		struct pcie_core_info *core = &itr->core;

		if (pdev->dev.of_node == of_node &&
		    core->domain == domain &&
		    core->bus == bus &&
		    core->dev_id == dev_id &&
		    core->slot == slot) {
		core = &itr->core;
		if (pdev->dev.of_node == of_node && core->domain == domain &&
		    core->bus == bus && core->slot == slot &&
		    (core->dev_id == PCI_ANY_ID || (core->dev_id == dev_id))) {
			/* change default dev_id to current dev_id */
			core->dev_id = dev_id;
			mhi_dev_ctxt = itr;
			break;
		}
@@ -1819,6 +1819,11 @@ int mhi_register_device(struct mhi_device *mhi_device,
	if (!mhi_dev_ctxt)
		return -EPROBE_DEFER;

	snprintf(node, sizeof(node), "mhi_%04x_%02u.%02u.%02u",
		 core->dev_id, core->domain, core->bus, core->slot);
	mhi_dev_ctxt->mhi_ipc_log =
		ipc_log_context_create(MHI_IPC_LOG_PAGES, node, 0);

	mhi_log(mhi_dev_ctxt, MHI_MSG_INFO,
		"Registering Domain:%02u Bus:%04u dev:0x%04x slot:%04u\n",
		domain, bus, dev_id, slot);
@@ -1900,6 +1905,17 @@ int mhi_register_device(struct mhi_device *mhi_device,
			mhi_dev_ctxt->bhi_ctxt.rddm_size);
	}

	/* notify all the registered clients we probed */
	for (i = 0; i < MHI_MAX_CHANNELS; i++) {
		struct mhi_client_handle *client_handle =
			mhi_dev_ctxt->client_handle_list[i];

		if (!client_handle)
			continue;
		client_handle->dev_id = core->dev_id;
		mhi_notify_client(client_handle, MHI_CB_MHI_PROBED);
	}

	mhi_log(mhi_dev_ctxt, MHI_MSG_INFO, "Exit success\n");
	return 0;
}
+11 −11
Original line number Diff line number Diff line
@@ -593,24 +593,24 @@ static void enable_clients(struct mhi_device_ctxt *mhi_dev_ctxt,
			   enum MHI_EXEC_ENV exec_env)
{
	struct mhi_client_handle *client_handle = NULL;
	struct mhi_cb_info cb_info;
	int i = 0, r = 0;
	struct mhi_chan_info chan_info;

	cb_info.cb_reason = MHI_CB_MHI_ENABLED;
	struct mhi_chan_info *chan_info;
	int i = 0;

	mhi_log(mhi_dev_ctxt, MHI_MSG_INFO,
		"Enabling Clients, exec env %d.\n", exec_env);

	for (i = 0; i < MHI_MAX_CHANNELS; ++i) {
		if (!VALID_CHAN_NR(i))
		if (!mhi_dev_ctxt->client_handle_list[i])
			continue;

		client_handle = mhi_dev_ctxt->client_handle_list[i];
		r = get_chan_props(mhi_dev_ctxt, i, &chan_info);
		if (!r && client_handle &&
		    exec_env == GET_CHAN_PROPS(CHAN_BRINGUP_STAGE,
						chan_info.flags))
		chan_info = &client_handle->client_config->chan_info;
		if (exec_env == GET_CHAN_PROPS(CHAN_BRINGUP_STAGE,
					       chan_info->flags)) {
			client_handle->enabled = true;
			mhi_notify_client(client_handle, MHI_CB_MHI_ENABLED);
		}
	}

	mhi_log(mhi_dev_ctxt, MHI_MSG_INFO, "Done.\n");
}
+2 −0
Original line number Diff line number Diff line
@@ -81,6 +81,7 @@ enum MHI_CB_REASON {
	MHI_CB_MHI_SHUTDOWN,
	MHI_CB_SYS_ERROR,
	MHI_CB_RDDM,
	MHI_CB_MHI_PROBED,
};

enum MHI_FLAGS {
@@ -119,6 +120,7 @@ struct mhi_client_handle {
	u32 domain;
	u32 bus;
	u32 slot;
	bool enabled;
	struct mhi_client_config *client_config;
};