1 /* SPDX-License-Identifier: GPL-2.0 */ 1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 2 /* 3 * Turris Mox module configuration bus driver 3 * Turris Mox module configuration bus driver 4 * 4 * 5 * Copyright (C) 2019 Marek BehĂșn <kabel@kern 5 * Copyright (C) 2019 Marek BehĂșn <kabel@kernel.org> 6 */ 6 */ 7 7 8 #ifndef __LINUX_MOXTET_H 8 #ifndef __LINUX_MOXTET_H 9 #define __LINUX_MOXTET_H 9 #define __LINUX_MOXTET_H 10 10 11 #include <linux/device.h> 11 #include <linux/device.h> 12 #include <linux/irq.h> 12 #include <linux/irq.h> 13 #include <linux/irqdomain.h> 13 #include <linux/irqdomain.h> 14 #include <linux/mutex.h> 14 #include <linux/mutex.h> 15 15 16 #define TURRIS_MOX_MAX_MODULES 10 16 #define TURRIS_MOX_MAX_MODULES 10 17 17 18 enum turris_mox_cpu_module_id { 18 enum turris_mox_cpu_module_id { 19 TURRIS_MOX_CPU_ID_EMMC = 0x00, 19 TURRIS_MOX_CPU_ID_EMMC = 0x00, 20 TURRIS_MOX_CPU_ID_SD = 0x10, 20 TURRIS_MOX_CPU_ID_SD = 0x10, 21 }; 21 }; 22 22 23 enum turris_mox_module_id { 23 enum turris_mox_module_id { 24 TURRIS_MOX_MODULE_FIRST = 0x01 24 TURRIS_MOX_MODULE_FIRST = 0x01, 25 25 26 TURRIS_MOX_MODULE_SFP = 0x01 26 TURRIS_MOX_MODULE_SFP = 0x01, 27 TURRIS_MOX_MODULE_PCI = 0x02 27 TURRIS_MOX_MODULE_PCI = 0x02, 28 TURRIS_MOX_MODULE_TOPAZ = 0x03 28 TURRIS_MOX_MODULE_TOPAZ = 0x03, 29 TURRIS_MOX_MODULE_PERIDOT = 0x04 29 TURRIS_MOX_MODULE_PERIDOT = 0x04, 30 TURRIS_MOX_MODULE_USB3 = 0x05 30 TURRIS_MOX_MODULE_USB3 = 0x05, 31 TURRIS_MOX_MODULE_PCI_BRIDGE = 0x06 31 TURRIS_MOX_MODULE_PCI_BRIDGE = 0x06, 32 32 33 TURRIS_MOX_MODULE_LAST = 0x06 33 TURRIS_MOX_MODULE_LAST = 0x06, 34 }; 34 }; 35 35 36 #define MOXTET_NIRQS 16 36 #define MOXTET_NIRQS 16 37 37 38 struct moxtet { 38 struct moxtet { 39 struct device *dev; 39 struct device *dev; 40 struct mutex lock; 40 struct mutex lock; 41 u8 module 41 u8 modules[TURRIS_MOX_MAX_MODULES]; 42 int count; 42 int count; 43 u8 tx[TUR 43 u8 tx[TURRIS_MOX_MAX_MODULES]; 44 int dev_ir 44 int dev_irq; 45 struct { 45 struct { 46 struct irq_domain *domai 46 struct irq_domain *domain; 47 struct irq_chip chip; 47 struct irq_chip chip; 48 unsigned long masked 48 unsigned long masked, exists; 49 struct moxtet_irqpos { 49 struct moxtet_irqpos { 50 u8 idx 50 u8 idx; 51 u8 bit 51 u8 bit; 52 } position[MOXTET_NIRQS]; 52 } position[MOXTET_NIRQS]; 53 } irq; 53 } irq; 54 #ifdef CONFIG_DEBUG_FS 54 #ifdef CONFIG_DEBUG_FS 55 struct dentry *debug 55 struct dentry *debugfs_root; 56 #endif 56 #endif 57 }; 57 }; 58 58 59 struct moxtet_driver { 59 struct moxtet_driver { 60 const enum turris_mox_module_id *id_ta 60 const enum turris_mox_module_id *id_table; 61 struct device_driver driver 61 struct device_driver driver; 62 }; 62 }; 63 63 64 #define to_moxtet_driver(__drv) \ !! 64 static inline struct moxtet_driver * 65 ( __drv ? container_of_const(__drv, st !! 65 to_moxtet_driver(struct device_driver *drv) >> 66 { >> 67 if (!drv) >> 68 return NULL; >> 69 return container_of(drv, struct moxtet_driver, driver); >> 70 } 66 71 67 extern int __moxtet_register_driver(struct mod 72 extern int __moxtet_register_driver(struct module *owner, 68 struct mox 73 struct moxtet_driver *mdrv); 69 74 70 static inline void moxtet_unregister_driver(st 75 static inline void moxtet_unregister_driver(struct moxtet_driver *mdrv) 71 { 76 { 72 if (mdrv) 77 if (mdrv) 73 driver_unregister(&mdrv->drive 78 driver_unregister(&mdrv->driver); 74 } 79 } 75 80 76 #define moxtet_register_driver(driver) \ 81 #define moxtet_register_driver(driver) \ 77 __moxtet_register_driver(THIS_MODULE, 82 __moxtet_register_driver(THIS_MODULE, driver) 78 83 79 #define module_moxtet_driver(__moxtet_driver) 84 #define module_moxtet_driver(__moxtet_driver) \ 80 module_driver(__moxtet_driver, moxtet_ 85 module_driver(__moxtet_driver, moxtet_register_driver, \ 81 moxtet_unregister_driv 86 moxtet_unregister_driver) 82 87 83 struct moxtet_device { 88 struct moxtet_device { 84 struct device dev; 89 struct device dev; 85 struct moxtet *moxte 90 struct moxtet *moxtet; 86 enum turris_mox_module_id id; 91 enum turris_mox_module_id id; 87 unsigned int idx; 92 unsigned int idx; 88 }; 93 }; 89 94 90 extern int moxtet_device_read(struct device *d 95 extern int moxtet_device_read(struct device *dev); 91 extern int moxtet_device_write(struct device * 96 extern int moxtet_device_write(struct device *dev, u8 val); 92 extern int moxtet_device_written(struct device 97 extern int moxtet_device_written(struct device *dev); 93 98 94 static inline struct moxtet_device * 99 static inline struct moxtet_device * 95 to_moxtet_device(struct device *dev) 100 to_moxtet_device(struct device *dev) 96 { 101 { 97 if (!dev) 102 if (!dev) 98 return NULL; 103 return NULL; 99 return container_of(dev, struct moxtet 104 return container_of(dev, struct moxtet_device, dev); 100 } 105 } 101 106 102 #endif /* __LINUX_MOXTET_H */ 107 #endif /* __LINUX_MOXTET_H */ 103 108
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.