xref: /openbmc/linux/drivers/fsi/fsi-master.h (revision 93f5715e)
1 /*
2  * FSI master definitions. These comprise the core <--> master interface,
3  * to allow the core to interact with the (hardware-specific) masters.
4  *
5  * Copyright (C) IBM Corporation 2016
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  */
16 
17 #ifndef DRIVERS_FSI_MASTER_H
18 #define DRIVERS_FSI_MASTER_H
19 
20 #include <linux/device.h>
21 #include <linux/mutex.h>
22 
23 /* Various protocol delays */
24 #define	FSI_ECHO_DELAY_CLOCKS	16	/* Number clocks for echo delay */
25 #define	FSI_SEND_DELAY_CLOCKS	16	/* Number clocks for send delay */
26 #define	FSI_PRE_BREAK_CLOCKS	50	/* Number clocks to prep for break */
27 #define	FSI_BREAK_CLOCKS	256	/* Number of clocks to issue break */
28 #define	FSI_POST_BREAK_CLOCKS	16000	/* Number clocks to set up cfam */
29 #define	FSI_INIT_CLOCKS		5000	/* Clock out any old data */
30 #define	FSI_MASTER_DPOLL_CLOCKS	50      /* < 21 will cause slave to hang */
31 #define	FSI_MASTER_EPOLL_CLOCKS	50      /* Number of clocks for E_POLL retry */
32 
33 /* Various retry maximums */
34 #define FSI_CRC_ERR_RETRIES	10
35 #define	FSI_MASTER_MAX_BUSY	200
36 #define	FSI_MASTER_MTOE_COUNT	1000
37 
38 /* Command encodings */
39 #define	FSI_CMD_DPOLL		0x2
40 #define	FSI_CMD_EPOLL		0x3
41 #define	FSI_CMD_TERM		0x3f
42 #define FSI_CMD_ABS_AR		0x4
43 #define FSI_CMD_REL_AR		0x5
44 #define FSI_CMD_SAME_AR		0x3	/* but only a 2-bit opcode... */
45 
46 /* Slave responses */
47 #define	FSI_RESP_ACK		0	/* Success */
48 #define	FSI_RESP_BUSY		1	/* Slave busy */
49 #define	FSI_RESP_ERRA		2	/* Any (misc) Error */
50 #define	FSI_RESP_ERRC		3	/* Slave reports master CRC error */
51 
52 /* Misc */
53 #define	FSI_CRC_SIZE		4
54 
55 /* fsi-master definition and flags */
56 #define FSI_MASTER_FLAG_SWCLOCK		0x1
57 
58 struct fsi_master {
59 	struct device	dev;
60 	int		idx;
61 	int		n_links;
62 	int		flags;
63 	struct mutex	scan_lock;
64 	int		(*read)(struct fsi_master *, int link, uint8_t id,
65 				uint32_t addr, void *val, size_t size);
66 	int		(*write)(struct fsi_master *, int link, uint8_t id,
67 				uint32_t addr, const void *val, size_t size);
68 	int		(*term)(struct fsi_master *, int link, uint8_t id);
69 	int		(*send_break)(struct fsi_master *, int link);
70 	int		(*link_enable)(struct fsi_master *, int link);
71 	int		(*link_config)(struct fsi_master *, int link,
72 				       u8 t_send_delay, u8 t_echo_delay);
73 };
74 
75 #define dev_to_fsi_master(d) container_of(d, struct fsi_master, dev)
76 
77 /**
78  * fsi_master registration & lifetime: the fsi_master_register() and
79  * fsi_master_unregister() functions will take ownership of the master, and
80  * ->dev in particular. The registration path performs a get_device(), which
81  * takes the first reference on the device. Similarly, the unregistration path
82  * performs a put_device(), which may well drop the last reference.
83  *
84  * This means that master implementations *may* need to hold their own
85  * reference (via get_device()) on master->dev. In particular, if the device's
86  * ->release callback frees the fsi_master, then fsi_master_unregister will
87  * invoke this free if no other reference is held.
88  *
89  * The same applies for the error path of fsi_master_register; if the call
90  * fails, dev->release will have been invoked.
91  */
92 extern int fsi_master_register(struct fsi_master *master);
93 extern void fsi_master_unregister(struct fsi_master *master);
94 
95 extern int fsi_master_rescan(struct fsi_master *master);
96 
97 #endif /* DRIVERS_FSI_MASTER_H */
98