Skip to content

Commit 45723a4

Browse files
Jeffrey Hugogregkh
authored andcommitted
bus: mhi: core: Offload register accesses to the controller
When reading or writing MHI registers, the core assumes that the physical link is a memory mapped PCI link. This assumption may not hold for all MHI devices. The controller knows what is the physical link (ie PCI, I2C, SPI, etc), and therefore knows the proper methods to access that link. The controller can also handle link specific error scenarios, such as reading -1 when the PCI link went down. Therefore, it is appropriate that the MHI core requests the controller to make register accesses on behalf of the core, which abstracts the core from link specifics, and end up removing an unnecessary assumption. Signed-off-by: Jeffrey Hugo <[email protected]> Reviewed-by: Hemant Kumar <[email protected]> Reviewed-by: Manivannan Sadhasivam <[email protected]> Signed-off-by: Manivannan Sadhasivam <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 85a087d commit 45723a4

File tree

4 files changed

+10
-14
lines changed

4 files changed

+10
-14
lines changed

drivers/bus/mhi/core/init.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,8 @@ int mhi_register_controller(struct mhi_controller *mhi_cntrl,
813813
return -EINVAL;
814814

815815
if (!mhi_cntrl->runtime_get || !mhi_cntrl->runtime_put ||
816-
!mhi_cntrl->status_cb)
816+
!mhi_cntrl->status_cb || !mhi_cntrl->read_reg ||
817+
!mhi_cntrl->write_reg)
817818
return -EINVAL;
818819

819820
ret = parse_config(mhi_cntrl, config);

drivers/bus/mhi/core/internal.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111

1212
extern struct bus_type mhi_bus_type;
1313

14-
/* MHI MMIO register mapping */
15-
#define PCI_INVALID_READ(val) (val == U32_MAX)
16-
1714
#define MHIREGLEN (0x0)
1815
#define MHIREGLEN_MHIREGLEN_MASK (0xFFFFFFFF)
1916
#define MHIREGLEN_MHIREGLEN_SHIFT (0)

drivers/bus/mhi/core/main.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,7 @@
1818
int __must_check mhi_read_reg(struct mhi_controller *mhi_cntrl,
1919
void __iomem *base, u32 offset, u32 *out)
2020
{
21-
u32 tmp = readl(base + offset);
22-
23-
/* If the value is invalid, the link is down */
24-
if (PCI_INVALID_READ(tmp))
25-
return -EIO;
26-
27-
*out = tmp;
28-
29-
return 0;
21+
return mhi_cntrl->read_reg(mhi_cntrl, base + offset, out);
3022
}
3123

3224
int __must_check mhi_read_reg_field(struct mhi_controller *mhi_cntrl,
@@ -48,7 +40,7 @@ int __must_check mhi_read_reg_field(struct mhi_controller *mhi_cntrl,
4840
void mhi_write_reg(struct mhi_controller *mhi_cntrl, void __iomem *base,
4941
u32 offset, u32 val)
5042
{
51-
writel(val, base + offset);
43+
mhi_cntrl->write_reg(mhi_cntrl, base + offset, val);
5244
}
5345

5446
void mhi_write_reg_field(struct mhi_controller *mhi_cntrl, void __iomem *base,

include/linux/mhi.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,8 @@ struct mhi_controller_config {
342342
* @runtimet_put: CB function to decrement pm usage (required)
343343
* @map_single: CB function to create TRE buffer
344344
* @unmap_single: CB function to destroy TRE buffer
345+
* @read_reg: Read a MHI register via the physical link (required)
346+
* @write_reg: Write a MHI register via the physical link (required)
345347
* @buffer_len: Bounce buffer length
346348
* @bounce_buf: Use of bounce buffer
347349
* @fbc_download: MHI host needs to do complete image transfer (optional)
@@ -425,6 +427,10 @@ struct mhi_controller {
425427
struct mhi_buf_info *buf);
426428
void (*unmap_single)(struct mhi_controller *mhi_cntrl,
427429
struct mhi_buf_info *buf);
430+
int (*read_reg)(struct mhi_controller *mhi_cntrl, void __iomem *addr,
431+
u32 *out);
432+
void (*write_reg)(struct mhi_controller *mhi_cntrl, void __iomem *addr,
433+
u32 val);
428434

429435
size_t buffer_len;
430436
bool bounce_buf;

0 commit comments

Comments
 (0)