blob: f653f75da7be175d1115317dfd31a398b6090f58 [file] [log] [blame]
Jeremy Kerr09aecfa2017-06-06 16:08:36 -05001/*
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
Benjamin Herrenschmidtfea9cf32018-06-10 16:25:25 +100022/* Various protocol delays */
23#define FSI_ECHO_DELAY_CLOCKS 16 /* Number clocks for echo delay */
24#define FSI_SEND_DELAY_CLOCKS 16 /* Number clocks for send delay */
25#define FSI_PRE_BREAK_CLOCKS 50 /* Number clocks to prep for break */
26#define FSI_BREAK_CLOCKS 256 /* Number of clocks to issue break */
27#define FSI_POST_BREAK_CLOCKS 16000 /* Number clocks to set up cfam */
28#define FSI_INIT_CLOCKS 5000 /* Clock out any old data */
29#define FSI_MASTER_DPOLL_CLOCKS 50 /* < 21 will cause slave to hang */
30#define FSI_MASTER_EPOLL_CLOCKS 50 /* Number of clocks for E_POLL retry */
31
32/* Various retry maximums */
33#define FSI_CRC_ERR_RETRIES 10
34#define FSI_MASTER_MAX_BUSY 200
35#define FSI_MASTER_MTOE_COUNT 1000
36
37/* Command encodings */
38#define FSI_CMD_DPOLL 0x2
39#define FSI_CMD_EPOLL 0x3
40#define FSI_CMD_TERM 0x3f
41#define FSI_CMD_ABS_AR 0x4
42#define FSI_CMD_REL_AR 0x5
43#define FSI_CMD_SAME_AR 0x3 /* but only a 2-bit opcode... */
44
45/* Slave responses */
46#define FSI_RESP_ACK 0 /* Success */
47#define FSI_RESP_BUSY 1 /* Slave busy */
48#define FSI_RESP_ERRA 2 /* Any (misc) Error */
49#define FSI_RESP_ERRC 3 /* Slave reports master CRC error */
50
51/* Misc */
52#define FSI_CRC_SIZE 4
53
54/* fsi-master definition and flags */
Jeremy Kerr4af889b2017-06-06 16:08:58 -050055#define FSI_MASTER_FLAG_SWCLOCK 0x1
56
Jeremy Kerr09aecfa2017-06-06 16:08:36 -050057struct fsi_master {
58 struct device dev;
59 int idx;
60 int n_links;
61 int flags;
62 int (*read)(struct fsi_master *, int link, uint8_t id,
63 uint32_t addr, void *val, size_t size);
64 int (*write)(struct fsi_master *, int link, uint8_t id,
65 uint32_t addr, const void *val, size_t size);
66 int (*term)(struct fsi_master *, int link, uint8_t id);
67 int (*send_break)(struct fsi_master *, int link);
68 int (*link_enable)(struct fsi_master *, int link);
Benjamin Herrenschmidta2e7da82018-05-29 15:01:07 +100069 int (*link_config)(struct fsi_master *, int link,
70 u8 t_send_delay, u8 t_echo_delay);
Jeremy Kerr09aecfa2017-06-06 16:08:36 -050071};
72
73#define dev_to_fsi_master(d) container_of(d, struct fsi_master, dev)
74
Jeremy Kerre0c24bd2018-02-12 15:45:47 +103075/**
76 * fsi_master registration & lifetime: the fsi_master_register() and
77 * fsi_master_unregister() functions will take ownership of the master, and
78 * ->dev in particular. The registration path performs a get_device(), which
79 * takes the first reference on the device. Similarly, the unregistration path
80 * performs a put_device(), which may well drop the last reference.
81 *
82 * This means that master implementations *may* need to hold their own
83 * reference (via get_device()) on master->dev. In particular, if the device's
84 * ->release callback frees the fsi_master, then fsi_master_unregister will
85 * invoke this free if no other reference is held.
86 *
87 * The same applies for the error path of fsi_master_register; if the call
88 * fails, dev->release will have been invoked.
89 */
Jeremy Kerr09aecfa2017-06-06 16:08:36 -050090extern int fsi_master_register(struct fsi_master *master);
91extern void fsi_master_unregister(struct fsi_master *master);
92
Jeremy Kerr15362d62018-02-12 15:45:40 +103093extern int fsi_master_rescan(struct fsi_master *master);
94
Jeremy Kerr09aecfa2017-06-06 16:08:36 -050095#endif /* DRIVERS_FSI_MASTER_H */