xref: /OK3568_Linux_fs/kernel/drivers/fsi/fsi-master.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-only */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * FSI master definitions. These comprise the core <--> master interface,
4*4882a593Smuzhiyun  * to allow the core to interact with the (hardware-specific) masters.
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  * Copyright (C) IBM Corporation 2016
7*4882a593Smuzhiyun  */
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun #ifndef DRIVERS_FSI_MASTER_H
10*4882a593Smuzhiyun #define DRIVERS_FSI_MASTER_H
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun #include <linux/device.h>
13*4882a593Smuzhiyun #include <linux/mutex.h>
14*4882a593Smuzhiyun 
15*4882a593Smuzhiyun /*
16*4882a593Smuzhiyun  * Master registers
17*4882a593Smuzhiyun  *
18*4882a593Smuzhiyun  * These are used by hardware masters, such as the one in the FSP2, AST2600 and
19*4882a593Smuzhiyun  * the hub master in POWER processors.
20*4882a593Smuzhiyun  */
21*4882a593Smuzhiyun 
22*4882a593Smuzhiyun /* Control Registers */
23*4882a593Smuzhiyun #define FSI_MMODE		0x0		/* R/W: mode */
24*4882a593Smuzhiyun #define FSI_MDLYR		0x4		/* R/W: delay */
25*4882a593Smuzhiyun #define FSI_MCRSP		0x8		/* R/W: clock rate */
26*4882a593Smuzhiyun #define FSI_MENP0		0x10		/* R/W: enable */
27*4882a593Smuzhiyun #define FSI_MLEVP0		0x18		/* R: plug detect */
28*4882a593Smuzhiyun #define FSI_MSENP0		0x18		/* S: Set enable */
29*4882a593Smuzhiyun #define FSI_MCENP0		0x20		/* C: Clear enable */
30*4882a593Smuzhiyun #define FSI_MAEB		0x70		/* R: Error address */
31*4882a593Smuzhiyun #define FSI_MVER		0x74		/* R: master version/type */
32*4882a593Smuzhiyun #define FSI_MSTAP0		0xd0		/* R: Port status */
33*4882a593Smuzhiyun #define FSI_MRESP0		0xd0		/* W: Port reset */
34*4882a593Smuzhiyun #define FSI_MESRB0		0x1d0		/* R: Master error status */
35*4882a593Smuzhiyun #define FSI_MRESB0		0x1d0		/* W: Reset bridge */
36*4882a593Smuzhiyun #define FSI_MSCSB0		0x1d4		/* R: Master sub command stack */
37*4882a593Smuzhiyun #define FSI_MATRB0		0x1d8		/* R: Master address trace */
38*4882a593Smuzhiyun #define FSI_MDTRB0		0x1dc		/* R: Master data trace */
39*4882a593Smuzhiyun #define FSI_MECTRL		0x2e0		/* W: Error control */
40*4882a593Smuzhiyun 
41*4882a593Smuzhiyun /* MMODE: Mode control */
42*4882a593Smuzhiyun #define FSI_MMODE_EIP		0x80000000	/* Enable interrupt polling */
43*4882a593Smuzhiyun #define FSI_MMODE_ECRC		0x40000000	/* Enable error recovery */
44*4882a593Smuzhiyun #define FSI_MMODE_RELA		0x20000000	/* Enable relative address commands */
45*4882a593Smuzhiyun #define FSI_MMODE_EPC		0x10000000	/* Enable parity checking */
46*4882a593Smuzhiyun #define FSI_MMODE_P8_TO_LSB	0x00000010	/* Timeout value LSB */
47*4882a593Smuzhiyun 						/*   MSB=1, LSB=0 is 0.8 ms */
48*4882a593Smuzhiyun 						/*   MSB=0, LSB=1 is 0.9 ms */
49*4882a593Smuzhiyun #define FSI_MMODE_CRS0SHFT	18		/* Clk rate selection 0 shift */
50*4882a593Smuzhiyun #define FSI_MMODE_CRS0MASK	0x3ff		/* Clk rate selection 0 mask */
51*4882a593Smuzhiyun #define FSI_MMODE_CRS1SHFT	8		/* Clk rate selection 1 shift */
52*4882a593Smuzhiyun #define FSI_MMODE_CRS1MASK	0x3ff		/* Clk rate selection 1 mask */
53*4882a593Smuzhiyun 
54*4882a593Smuzhiyun /* MRESB: Reset brindge */
55*4882a593Smuzhiyun #define FSI_MRESB_RST_GEN	0x80000000	/* General reset */
56*4882a593Smuzhiyun #define FSI_MRESB_RST_ERR	0x40000000	/* Error Reset */
57*4882a593Smuzhiyun 
58*4882a593Smuzhiyun /* MRESP: Reset port */
59*4882a593Smuzhiyun #define FSI_MRESP_RST_ALL_MASTER 0x20000000	/* Reset all FSI masters */
60*4882a593Smuzhiyun #define FSI_MRESP_RST_ALL_LINK	0x10000000	/* Reset all FSI port contr. */
61*4882a593Smuzhiyun #define FSI_MRESP_RST_MCR	0x08000000	/* Reset FSI master reg. */
62*4882a593Smuzhiyun #define FSI_MRESP_RST_PYE	0x04000000	/* Reset FSI parity error */
63*4882a593Smuzhiyun #define FSI_MRESP_RST_ALL	0xfc000000	/* Reset any error */
64*4882a593Smuzhiyun 
65*4882a593Smuzhiyun /* MECTRL: Error control */
66*4882a593Smuzhiyun #define FSI_MECTRL_EOAE		0x8000		/* Enable machine check when */
67*4882a593Smuzhiyun 						/* master 0 in error */
68*4882a593Smuzhiyun #define FSI_MECTRL_P8_AUTO_TERM	0x4000		/* Auto terminate */
69*4882a593Smuzhiyun 
70*4882a593Smuzhiyun #define FSI_HUB_LINK_OFFSET		0x80000
71*4882a593Smuzhiyun #define FSI_HUB_LINK_SIZE		0x80000
72*4882a593Smuzhiyun #define FSI_HUB_MASTER_MAX_LINKS	8
73*4882a593Smuzhiyun 
74*4882a593Smuzhiyun /*
75*4882a593Smuzhiyun  * Protocol definitions
76*4882a593Smuzhiyun  *
77*4882a593Smuzhiyun  * These are used by low level masters that bit-bang out the protocol
78*4882a593Smuzhiyun  */
79*4882a593Smuzhiyun 
80*4882a593Smuzhiyun /* Various protocol delays */
81*4882a593Smuzhiyun #define	FSI_ECHO_DELAY_CLOCKS	16	/* Number clocks for echo delay */
82*4882a593Smuzhiyun #define	FSI_SEND_DELAY_CLOCKS	16	/* Number clocks for send delay */
83*4882a593Smuzhiyun #define	FSI_PRE_BREAK_CLOCKS	50	/* Number clocks to prep for break */
84*4882a593Smuzhiyun #define	FSI_BREAK_CLOCKS	256	/* Number of clocks to issue break */
85*4882a593Smuzhiyun #define	FSI_POST_BREAK_CLOCKS	16000	/* Number clocks to set up cfam */
86*4882a593Smuzhiyun #define	FSI_INIT_CLOCKS		5000	/* Clock out any old data */
87*4882a593Smuzhiyun #define	FSI_MASTER_DPOLL_CLOCKS	50      /* < 21 will cause slave to hang */
88*4882a593Smuzhiyun #define	FSI_MASTER_EPOLL_CLOCKS	50      /* Number of clocks for E_POLL retry */
89*4882a593Smuzhiyun 
90*4882a593Smuzhiyun /* Various retry maximums */
91*4882a593Smuzhiyun #define FSI_CRC_ERR_RETRIES	10
92*4882a593Smuzhiyun #define	FSI_MASTER_MAX_BUSY	200
93*4882a593Smuzhiyun #define	FSI_MASTER_MTOE_COUNT	1000
94*4882a593Smuzhiyun 
95*4882a593Smuzhiyun /* Command encodings */
96*4882a593Smuzhiyun #define	FSI_CMD_DPOLL		0x2
97*4882a593Smuzhiyun #define	FSI_CMD_EPOLL		0x3
98*4882a593Smuzhiyun #define	FSI_CMD_TERM		0x3f
99*4882a593Smuzhiyun #define FSI_CMD_ABS_AR		0x4
100*4882a593Smuzhiyun #define FSI_CMD_REL_AR		0x5
101*4882a593Smuzhiyun #define FSI_CMD_SAME_AR		0x3	/* but only a 2-bit opcode... */
102*4882a593Smuzhiyun 
103*4882a593Smuzhiyun /* Slave responses */
104*4882a593Smuzhiyun #define	FSI_RESP_ACK		0	/* Success */
105*4882a593Smuzhiyun #define	FSI_RESP_BUSY		1	/* Slave busy */
106*4882a593Smuzhiyun #define	FSI_RESP_ERRA		2	/* Any (misc) Error */
107*4882a593Smuzhiyun #define	FSI_RESP_ERRC		3	/* Slave reports master CRC error */
108*4882a593Smuzhiyun 
109*4882a593Smuzhiyun /* Misc */
110*4882a593Smuzhiyun #define	FSI_CRC_SIZE		4
111*4882a593Smuzhiyun 
112*4882a593Smuzhiyun /* fsi-master definition and flags */
113*4882a593Smuzhiyun #define FSI_MASTER_FLAG_SWCLOCK		0x1
114*4882a593Smuzhiyun 
115*4882a593Smuzhiyun /*
116*4882a593Smuzhiyun  * Structures and function prototypes
117*4882a593Smuzhiyun  *
118*4882a593Smuzhiyun  * These are common to all masters
119*4882a593Smuzhiyun  */
120*4882a593Smuzhiyun 
121*4882a593Smuzhiyun struct fsi_master {
122*4882a593Smuzhiyun 	struct device	dev;
123*4882a593Smuzhiyun 	int		idx;
124*4882a593Smuzhiyun 	int		n_links;
125*4882a593Smuzhiyun 	int		flags;
126*4882a593Smuzhiyun 	struct mutex	scan_lock;
127*4882a593Smuzhiyun 	int		(*read)(struct fsi_master *, int link, uint8_t id,
128*4882a593Smuzhiyun 				uint32_t addr, void *val, size_t size);
129*4882a593Smuzhiyun 	int		(*write)(struct fsi_master *, int link, uint8_t id,
130*4882a593Smuzhiyun 				uint32_t addr, const void *val, size_t size);
131*4882a593Smuzhiyun 	int		(*term)(struct fsi_master *, int link, uint8_t id);
132*4882a593Smuzhiyun 	int		(*send_break)(struct fsi_master *, int link);
133*4882a593Smuzhiyun 	int		(*link_enable)(struct fsi_master *, int link,
134*4882a593Smuzhiyun 				       bool enable);
135*4882a593Smuzhiyun 	int		(*link_config)(struct fsi_master *, int link,
136*4882a593Smuzhiyun 				       u8 t_send_delay, u8 t_echo_delay);
137*4882a593Smuzhiyun };
138*4882a593Smuzhiyun 
139*4882a593Smuzhiyun #define dev_to_fsi_master(d) container_of(d, struct fsi_master, dev)
140*4882a593Smuzhiyun 
141*4882a593Smuzhiyun /**
142*4882a593Smuzhiyun  * fsi_master registration & lifetime: the fsi_master_register() and
143*4882a593Smuzhiyun  * fsi_master_unregister() functions will take ownership of the master, and
144*4882a593Smuzhiyun  * ->dev in particular. The registration path performs a get_device(), which
145*4882a593Smuzhiyun  * takes the first reference on the device. Similarly, the unregistration path
146*4882a593Smuzhiyun  * performs a put_device(), which may well drop the last reference.
147*4882a593Smuzhiyun  *
148*4882a593Smuzhiyun  * This means that master implementations *may* need to hold their own
149*4882a593Smuzhiyun  * reference (via get_device()) on master->dev. In particular, if the device's
150*4882a593Smuzhiyun  * ->release callback frees the fsi_master, then fsi_master_unregister will
151*4882a593Smuzhiyun  * invoke this free if no other reference is held.
152*4882a593Smuzhiyun  *
153*4882a593Smuzhiyun  * The same applies for the error path of fsi_master_register; if the call
154*4882a593Smuzhiyun  * fails, dev->release will have been invoked.
155*4882a593Smuzhiyun  */
156*4882a593Smuzhiyun extern int fsi_master_register(struct fsi_master *master);
157*4882a593Smuzhiyun extern void fsi_master_unregister(struct fsi_master *master);
158*4882a593Smuzhiyun 
159*4882a593Smuzhiyun extern int fsi_master_rescan(struct fsi_master *master);
160*4882a593Smuzhiyun 
161*4882a593Smuzhiyun #endif /* DRIVERS_FSI_MASTER_H */
162