summaryrefslogtreecommitdiffstats
path: root/include/linux/moxtet.h
diff options
context:
space:
mode:
authorMarek BehĂșn <marek.behun@nic.cz>2019-08-12 12:11:14 -0400
committerArnd Bergmann <arnd@arndb.de>2019-08-14 09:30:35 -0400
commit5bc7f990cd98f3f7977d62bfe75c50b4b33d13f6 (patch)
treedd418e4969d39534a970c240d08bf79964bd461f /include/linux/moxtet.h
parent5ef9eb7ca372a97d347cf2d38e0ad2209585078b (diff)
bus: Add support for Moxtet bus
On the Turris Mox router different modules can be connected to the main CPU board: currently a module with a SFP cage, a module with MiniPCIe connector, a PCIe pass-through MiniPCIe connector module, a 4-port switch module, an 8-port switch module, and a 4-port USB3 module. For example: [CPU]-[PCIe-pass-through]-[PCIe]-[8-port switch]-[8-port switch]-[SFP] Each of this modules has an input and output shift register, and these are connected via SPI to the CPU board. Via SPI we are able to discover which modules are connected, in which order, and we can also read some information about the modules (eg. their interrupt status), and configure them. From each module 8 bits can be read (of which low 4 bits identify the module) and 8 bits can be written. For example from the module with a SFP cage we can read the LOS, TX-FAULT and MOD-DEF0 signals, while we can write TX-DISABLE and RATE-SELECT signals. This driver creates a new bus type, called "moxtet". For each Mox module it finds via SPI, it creates a new device on the moxtet bus so that drivers can be written for them. It also implements a virtual interrupt controller for the modules which send their interrupt status over the SPI shift register. These modules do this in addition to sending their interrupt status via the shared interrupt line. When the shared interrupt is triggered, we read from the shift register and handle IRQs for all devices which are in interrupt. The topology of how Mox modules are connected can then be read by listing /sys/bus/moxtet/devices. Link: https://lore.kernel.org/r/20190812161118.21476-2-marek.behun@nic.cz Signed-off-by: Marek BehĂșn <marek.behun@nic.cz> Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Diffstat (limited to 'include/linux/moxtet.h')
-rw-r--r--include/linux/moxtet.h109
1 files changed, 109 insertions, 0 deletions
diff --git a/include/linux/moxtet.h b/include/linux/moxtet.h
new file mode 100644
index 000000000000..490db6886dcc
--- /dev/null
+++ b/include/linux/moxtet.h
@@ -0,0 +1,109 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Turris Mox module configuration bus driver
4 *
5 * Copyright (C) 2019 Marek Behun <marek.behun@nic.cz>
6 */
7
8#ifndef __LINUX_MOXTET_H
9#define __LINUX_MOXTET_H
10
11#include <linux/device.h>
12#include <linux/irq.h>
13#include <linux/irqdomain.h>
14#include <linux/mutex.h>
15
16#define TURRIS_MOX_MAX_MODULES 10
17
18enum turris_mox_cpu_module_id {
19 TURRIS_MOX_CPU_ID_EMMC = 0x00,
20 TURRIS_MOX_CPU_ID_SD = 0x10,
21};
22
23enum turris_mox_module_id {
24 TURRIS_MOX_MODULE_FIRST = 0x01,
25
26 TURRIS_MOX_MODULE_SFP = 0x01,
27 TURRIS_MOX_MODULE_PCI = 0x02,
28 TURRIS_MOX_MODULE_TOPAZ = 0x03,
29 TURRIS_MOX_MODULE_PERIDOT = 0x04,
30 TURRIS_MOX_MODULE_USB3 = 0x05,
31 TURRIS_MOX_MODULE_PCI_BRIDGE = 0x06,
32
33 TURRIS_MOX_MODULE_LAST = 0x06,
34};
35
36#define MOXTET_NIRQS 16
37
38extern struct bus_type moxtet_type;
39
40struct moxtet {
41 struct device *dev;
42 struct mutex lock;
43 u8 modules[TURRIS_MOX_MAX_MODULES];
44 int count;
45 u8 tx[TURRIS_MOX_MAX_MODULES];
46 int dev_irq;
47 struct {
48 struct irq_domain *domain;
49 struct irq_chip chip;
50 unsigned long masked, exists;
51 struct moxtet_irqpos {
52 u8 idx;
53 u8 bit;
54 } position[MOXTET_NIRQS];
55 } irq;
56#ifdef CONFIG_DEBUG_FS
57 struct dentry *debugfs_root;
58#endif
59};
60
61struct moxtet_driver {
62 const enum turris_mox_module_id *id_table;
63 struct device_driver driver;
64};
65
66static inline struct moxtet_driver *
67to_moxtet_driver(struct device_driver *drv)
68{
69 if (!drv)
70 return NULL;
71 return container_of(drv, struct moxtet_driver, driver);
72}
73
74extern int __moxtet_register_driver(struct module *owner,
75 struct moxtet_driver *mdrv);
76
77static inline void moxtet_unregister_driver(struct moxtet_driver *mdrv)
78{
79 if (mdrv)
80 driver_unregister(&mdrv->driver);
81}
82
83#define moxtet_register_driver(driver) \
84 __moxtet_register_driver(THIS_MODULE, driver)
85
86#define module_moxtet_driver(__moxtet_driver) \
87 module_driver(__moxtet_driver, moxtet_register_driver, \
88 moxtet_unregister_driver)
89
90struct moxtet_device {
91 struct device dev;
92 struct moxtet *moxtet;
93 enum turris_mox_module_id id;
94 unsigned int idx;
95};
96
97extern int moxtet_device_read(struct device *dev);
98extern int moxtet_device_write(struct device *dev, u8 val);
99extern int moxtet_device_written(struct device *dev);
100
101static inline struct moxtet_device *
102to_moxtet_device(struct device *dev)
103{
104 if (!dev)
105 return NULL;
106 return container_of(dev, struct moxtet_device, dev);
107}
108
109#endif /* __LINUX_MOXTET_H */