i3c: mipi-i3c-hci: Factor out i3c_hci_sysdev()

The MIPI I3C HCI driver needs to identify the underlying system device
used for DMA mapping and PM operations. The logic for determining that
device is currently embedded in the DMA implementation.

Factor this code out into i3c_hci_sysdev() so it can be shared by other
parts of the driver and keep the device-selection logic in one place.

The explanatory comment moves with the code, reworked as kernel-doc now
that it documents a function rather than an inline block.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Reviewed-by: Frank Li <Frank.Li@nxp.com>
Acked-by: Mukesh Savaliya <mukesh.savaliya@oss.qualcomm.com>
Link: https://patch.msgid.link/20260807145638.168865-14-adrian.hunter@intel.com
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
This commit is contained in:
Adrian Hunter 2026-08-07 17:56:37 +03:00 committed by Alexandre Belloni
parent 94da8edf84
commit 842e46925e
3 changed files with 19 additions and 14 deletions

View File

@ -15,6 +15,7 @@
#include <linux/interrupt.h>
#include <linux/iopoll.h>
#include <linux/module.h>
#include <linux/pci.h>
#include <linux/platform_data/mipi-i3c-hci.h>
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>
@ -117,6 +118,21 @@ static inline struct i3c_hci *to_i3c_hci(struct i3c_master_controller *m)
return container_of(m, struct i3c_hci, master);
}
/**
* i3c_hci_sysdev() - Get the device to use for DMA
* @dev: Device the HCI controller is bound to
*
* When an IOMMU is enabled, DMA API calls must use the device that IOMMU
* setup was done for. Under PCI enumeration that is the PCI device, not
* the "mipi-i3c-hci" platform device below it.
*
* Return: @dev's parent if it is a PCI device, otherwise @dev.
*/
struct device *i3c_hci_sysdev(struct device *dev)
{
return dev->parent && dev_is_pci(dev->parent) ? dev->parent : dev;
}
static void i3c_hci_set_master_dyn_addr(struct i3c_hci *hci)
{
reg_write(MASTER_DEVICE_ADDR,

View File

@ -15,7 +15,6 @@
#include <linux/errno.h>
#include <linux/i3c/master.h>
#include <linux/io.h>
#include <linux/pci.h>
#include "hci.h"
#include "cmd.h"
@ -301,23 +300,11 @@ static int hci_dma_init(struct i3c_hci *hci)
{
struct hci_rings_data *rings;
struct hci_rh_data *rh;
struct device *sysdev;
u32 regval;
unsigned int i, nr_rings, xfers_sz, resps_sz;
unsigned int ibi_status_ring_sz, ibi_data_ring_sz;
int ret;
/*
* Set pointer to a physical device that does DMA and has IOMMU setup
* done for it in case of enabled IOMMU and use it with the DMA API.
* Here such device is either
* "mipi-i3c-hci" platform device (OF/ACPI enumeration) parent or
* grandparent (PCI enumeration).
*/
sysdev = hci->master.dev.parent;
if (sysdev->parent && dev_is_pci(sysdev->parent))
sysdev = sysdev->parent;
regval = rhs_reg_read(CONTROL);
nr_rings = FIELD_GET(MAX_HEADER_COUNT_CAP, regval);
dev_dbg(&hci->master.dev, "%d DMA rings available\n", nr_rings);
@ -332,7 +319,7 @@ static int hci_dma_init(struct i3c_hci *hci)
return -ENOMEM;
hci->io_data = rings;
rings->total = nr_rings;
rings->sysdev = sysdev;
rings->sysdev = i3c_hci_sysdev(hci->master.dev.parent);
for (i = 0; i < rings->total; i++) {
u32 offset = rhs_reg_read(RHn_OFFSET(i));

View File

@ -184,6 +184,8 @@ void amd_set_resp_buf_thld(struct i3c_hci *hci);
void i3c_hci_sync_irq_inactive(struct i3c_hci *hci);
int i3c_hci_process_xfer(struct i3c_hci *hci, struct hci_xfer *xfer, int n);
struct device *i3c_hci_sysdev(struct device *dev);
#define DEFAULT_AUTOSUSPEND_DELAY_MS 1000
int i3c_hci_rpm_suspend(struct device *dev);