1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Turris Mox module configuration bus driver
5 * Copyright (C) 2019 Marek BehĂșn <kabel@kernel.org>
8 #ifndef __LINUX_MOXTET_H
9 #define __LINUX_MOXTET_H
11 #include <linux/device.h>
12 #include <linux/irq.h>
13 #include <linux/irqdomain.h>
14 #include <linux/mutex.h>
16 #define TURRIS_MOX_MAX_MODULES 10
18 enum turris_mox_cpu_module_id {
19 TURRIS_MOX_CPU_ID_EMMC = 0x00,
20 TURRIS_MOX_CPU_ID_SD = 0x10,
23 enum turris_mox_module_id {
24 TURRIS_MOX_MODULE_FIRST = 0x01,
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,
33 TURRIS_MOX_MODULE_LAST = 0x06,
36 #define MOXTET_NIRQS 16
38 extern struct bus_type moxtet_type;
43 u8 modules[TURRIS_MOX_MAX_MODULES];
45 u8 tx[TURRIS_MOX_MAX_MODULES];
48 struct irq_domain *domain;
50 unsigned long masked, exists;
51 struct moxtet_irqpos {
54 } position[MOXTET_NIRQS];
56 #ifdef CONFIG_DEBUG_FS
57 struct dentry *debugfs_root;
61 struct moxtet_driver {
62 const enum turris_mox_module_id *id_table;
63 struct device_driver driver;
66 static inline struct moxtet_driver *
67 to_moxtet_driver(struct device_driver *drv)
71 return container_of(drv, struct moxtet_driver, driver);
74 extern int __moxtet_register_driver(struct module *owner,
75 struct moxtet_driver *mdrv);
77 static inline void moxtet_unregister_driver(struct moxtet_driver *mdrv)
80 driver_unregister(&mdrv->driver);
83 #define moxtet_register_driver(driver) \
84 __moxtet_register_driver(THIS_MODULE, driver)
86 #define module_moxtet_driver(__moxtet_driver) \
87 module_driver(__moxtet_driver, moxtet_register_driver, \
88 moxtet_unregister_driver)
90 struct moxtet_device {
92 struct moxtet *moxtet;
93 enum turris_mox_module_id id;
97 extern int moxtet_device_read(struct device *dev);
98 extern int moxtet_device_write(struct device *dev, u8 val);
99 extern int moxtet_device_written(struct device *dev);
101 static inline struct moxtet_device *
102 to_moxtet_device(struct device *dev)
106 return container_of(dev, struct moxtet_device, dev);
109 #endif /* __LINUX_MOXTET_H */