xref: /linux/drivers/i3c/master/dw-i3c-master.h (revision a1ff5a7d78a036d6c2178ee5acd6ba4946243800)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (c) 2023 Code Construct
4  *
5  * Author: Jeremy Kerr <jk@codeconstruct.com.au>
6  */
7 
8 #include <linux/clk.h>
9 #include <linux/i3c/master.h>
10 #include <linux/reset.h>
11 #include <linux/types.h>
12 
13 #define DW_I3C_MAX_DEVS 32
14 
15 struct dw_i3c_master_caps {
16 	u8 cmdfifodepth;
17 	u8 datafifodepth;
18 };
19 
20 struct dw_i3c_dat_entry {
21 	u8 addr;
22 	bool is_i2c_addr;
23 	struct i3c_dev_desc *ibi_dev;
24 };
25 
26 struct dw_i3c_master {
27 	struct i3c_master_controller base;
28 	struct device *dev;
29 	u16 maxdevs;
30 	u16 datstartaddr;
31 	u32 free_pos;
32 	struct {
33 		struct list_head list;
34 		struct dw_i3c_xfer *cur;
35 		spinlock_t lock;
36 	} xferqueue;
37 	struct dw_i3c_master_caps caps;
38 	void __iomem *regs;
39 	struct reset_control *core_rst;
40 	struct clk *core_clk;
41 	struct clk *pclk;
42 	char version[5];
43 	char type[5];
44 	u32 sir_rej_mask;
45 	bool i2c_slv_prsnt;
46 	u32 dev_addr;
47 	u32 i3c_pp_timing;
48 	u32 i3c_od_timing;
49 	u32 ext_lcnt_timing;
50 	u32 bus_free_timing;
51 	u32 i2c_fm_timing;
52 	u32 i2c_fmp_timing;
53 	/*
54 	 * Per-device hardware data, used to manage the device address table
55 	 * (DAT)
56 	 *
57 	 * Locking: the devs array may be referenced in IRQ context while
58 	 * processing an IBI. However, IBIs (for a specific device, which
59 	 * implies a specific DAT entry) can only happen while interrupts are
60 	 * requested for that device, which is serialised against other
61 	 * insertions/removals from the array by the global i3c infrastructure.
62 	 * So, devs_lock protects against concurrent updates to devs->ibi_dev
63 	 * between request_ibi/free_ibi and the IBI irq event.
64 	 */
65 	struct dw_i3c_dat_entry devs[DW_I3C_MAX_DEVS];
66 	spinlock_t devs_lock;
67 
68 	/* platform-specific data */
69 	const struct dw_i3c_platform_ops *platform_ops;
70 
71 	struct work_struct hj_work;
72 };
73 
74 struct dw_i3c_platform_ops {
75 	/*
76 	 * Called on early bus init: the i3c has been set up, but before any
77 	 * transactions have taken place. Platform implementations may use to
78 	 * perform actual device enabling with the i3c core ready.
79 	 */
80 	int (*init)(struct dw_i3c_master *i3c);
81 
82 	/*
83 	 * Initialise a DAT entry to enable/disable IBIs. Allows the platform
84 	 * to perform any device workarounds on the DAT entry before
85 	 * inserting into the hardware table.
86 	 *
87 	 * Called with the DAT lock held; must not sleep.
88 	 */
89 	void (*set_dat_ibi)(struct dw_i3c_master *i3c,
90 			    struct i3c_dev_desc *dev, bool enable, u32 *reg);
91 };
92 
93 extern int dw_i3c_common_probe(struct dw_i3c_master *master,
94 			       struct platform_device *pdev);
95 extern void dw_i3c_common_remove(struct dw_i3c_master *master);
96 
97