1 /* SPDX-License-Identifier: GPL-2.0-or-later * 1 /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 /* 2 /* 3 * Generic framer profider header file 3 * Generic framer profider header file 4 * 4 * 5 * Copyright 2023 CS GROUP France 5 * Copyright 2023 CS GROUP France 6 * 6 * 7 * Author: Herve Codina <herve.codina@bootlin. 7 * Author: Herve Codina <herve.codina@bootlin.com> 8 */ 8 */ 9 9 10 #ifndef __DRIVERS_PROVIDER_FRAMER_H 10 #ifndef __DRIVERS_PROVIDER_FRAMER_H 11 #define __DRIVERS_PROVIDER_FRAMER_H 11 #define __DRIVERS_PROVIDER_FRAMER_H 12 12 13 #include <linux/export.h> 13 #include <linux/export.h> 14 #include <linux/framer/framer.h> 14 #include <linux/framer/framer.h> 15 #include <linux/types.h> 15 #include <linux/types.h> 16 16 17 #define FRAMER_FLAG_POLL_STATUS BIT(0) 17 #define FRAMER_FLAG_POLL_STATUS BIT(0) 18 18 19 /** 19 /** 20 * struct framer_ops - set of function pointer 20 * struct framer_ops - set of function pointers for performing framer operations 21 * @init: operation to be performed for initia 21 * @init: operation to be performed for initializing the framer 22 * @exit: operation to be performed while exit 22 * @exit: operation to be performed while exiting 23 * @power_on: powering on the framer 23 * @power_on: powering on the framer 24 * @power_off: powering off the framer 24 * @power_off: powering off the framer 25 * @flags: OR-ed flags (FRAMER_FLAG_*) to ask 25 * @flags: OR-ed flags (FRAMER_FLAG_*) to ask for core functionality 26 * - @FRAMER_FLAG_POLL_STATUS: 26 * - @FRAMER_FLAG_POLL_STATUS: 27 * Ask the core to perform a pollin 27 * Ask the core to perform a polling to get the framer status and 28 * notify consumers on change. 28 * notify consumers on change. 29 * The framer should call @framer_n 29 * The framer should call @framer_notify_status_change() when it 30 * detects a status change. This is 30 * detects a status change. This is usually done using interrupts. 31 * If the framer cannot detect this 31 * If the framer cannot detect this change, it can ask the core for 32 * a status polling. The core will 32 * a status polling. The core will call @get_status() periodically 33 * and, on change detected, it will 33 * and, on change detected, it will notify the consumer. 34 * the @get_status() 34 * the @get_status() 35 * @owner: the module owner containing the ops 35 * @owner: the module owner containing the ops 36 */ 36 */ 37 struct framer_ops { 37 struct framer_ops { 38 int (*init)(struct framer *framer) 38 int (*init)(struct framer *framer); 39 void (*exit)(struct framer *framer) 39 void (*exit)(struct framer *framer); 40 int (*power_on)(struct framer *fra 40 int (*power_on)(struct framer *framer); 41 int (*power_off)(struct framer *fr 41 int (*power_off)(struct framer *framer); 42 42 43 /** 43 /** 44 * @get_status: 44 * @get_status: 45 * 45 * 46 * Optional. 46 * Optional. 47 * 47 * 48 * Used to get the framer status. fram 48 * Used to get the framer status. framer_init() must have 49 * been called on the framer. 49 * been called on the framer. 50 * 50 * 51 * Returns: 0 if successful, an negati 51 * Returns: 0 if successful, an negative error code otherwise 52 */ 52 */ 53 int (*get_status)(struct framer *f 53 int (*get_status)(struct framer *framer, struct framer_status *status); 54 54 55 /** 55 /** 56 * @set_config: 56 * @set_config: 57 * 57 * 58 * Optional. 58 * Optional. 59 * 59 * 60 * Used to set the framer configuratio 60 * Used to set the framer configuration. framer_init() must have 61 * been called on the framer. 61 * been called on the framer. 62 * 62 * 63 * Returns: 0 if successful, an negati 63 * Returns: 0 if successful, an negative error code otherwise 64 */ 64 */ 65 int (*set_config)(struct framer *f 65 int (*set_config)(struct framer *framer, const struct framer_config *config); 66 66 67 /** 67 /** 68 * @get_config: 68 * @get_config: 69 * 69 * 70 * Optional. 70 * Optional. 71 * 71 * 72 * Used to get the framer configuratio 72 * Used to get the framer configuration. framer_init() must have 73 * been called on the framer. 73 * been called on the framer. 74 * 74 * 75 * Returns: 0 if successful, an negati 75 * Returns: 0 if successful, an negative error code otherwise 76 */ 76 */ 77 int (*get_config)(struct framer *f 77 int (*get_config)(struct framer *framer, struct framer_config *config); 78 78 79 u32 flags; 79 u32 flags; 80 struct module *owner; 80 struct module *owner; 81 }; 81 }; 82 82 83 /** 83 /** 84 * struct framer_provider - represents the fra 84 * struct framer_provider - represents the framer provider 85 * @dev: framer provider device 85 * @dev: framer provider device 86 * @owner: the module owner having of_xlate 86 * @owner: the module owner having of_xlate 87 * @list: to maintain a linked list of framer 87 * @list: to maintain a linked list of framer providers 88 * @of_xlate: function pointer to obtain frame 88 * @of_xlate: function pointer to obtain framer instance from framer pointer 89 */ 89 */ 90 struct framer_provider { 90 struct framer_provider { 91 struct device *dev; 91 struct device *dev; 92 struct module *owner; 92 struct module *owner; 93 struct list_head list; 93 struct list_head list; 94 struct framer * (*of_xlate)(struct dev 94 struct framer * (*of_xlate)(struct device *dev, 95 const stru 95 const struct of_phandle_args *args); 96 }; 96 }; 97 97 98 static inline void framer_set_drvdata(struct f 98 static inline void framer_set_drvdata(struct framer *framer, void *data) 99 { 99 { 100 dev_set_drvdata(&framer->dev, data); 100 dev_set_drvdata(&framer->dev, data); 101 } 101 } 102 102 103 static inline void *framer_get_drvdata(struct 103 static inline void *framer_get_drvdata(struct framer *framer) 104 { 104 { 105 return dev_get_drvdata(&framer->dev); 105 return dev_get_drvdata(&framer->dev); 106 } 106 } 107 107 108 #if IS_ENABLED(CONFIG_GENERIC_FRAMER) 108 #if IS_ENABLED(CONFIG_GENERIC_FRAMER) 109 109 110 /* Create and destroy a framer */ 110 /* Create and destroy a framer */ 111 struct framer *framer_create(struct device *de 111 struct framer *framer_create(struct device *dev, struct device_node *node, 112 const struct fram 112 const struct framer_ops *ops); 113 void framer_destroy(struct framer *framer); 113 void framer_destroy(struct framer *framer); 114 114 115 /* devm version */ 115 /* devm version */ 116 struct framer *devm_framer_create(struct devic 116 struct framer *devm_framer_create(struct device *dev, struct device_node *node, 117 const struct 117 const struct framer_ops *ops); 118 118 119 struct framer *framer_provider_simple_of_xlate 119 struct framer *framer_provider_simple_of_xlate(struct device *dev, 120 120 const struct of_phandle_args *args); 121 121 122 struct framer_provider * 122 struct framer_provider * 123 __framer_provider_of_register(struct device *d 123 __framer_provider_of_register(struct device *dev, struct module *owner, 124 struct framer *( 124 struct framer *(*of_xlate)(struct device *dev, 125 125 const struct of_phandle_args *args)); 126 126 127 void framer_provider_of_unregister(struct fram 127 void framer_provider_of_unregister(struct framer_provider *framer_provider); 128 128 129 struct framer_provider * 129 struct framer_provider * 130 __devm_framer_provider_of_register(struct devi 130 __devm_framer_provider_of_register(struct device *dev, struct module *owner, 131 struct fram 131 struct framer *(*of_xlate)(struct device *dev, 132 132 const struct of_phandle_args *args)); 133 133 134 void framer_notify_status_change(struct framer 134 void framer_notify_status_change(struct framer *framer); 135 135 136 #else /* IS_ENABLED(CONFIG_GENERIC_FRAMER) */ 136 #else /* IS_ENABLED(CONFIG_GENERIC_FRAMER) */ 137 137 138 static inline struct framer *framer_create(str 138 static inline struct framer *framer_create(struct device *dev, struct device_node *node, 139 con 139 const struct framer_ops *ops) 140 { 140 { 141 return ERR_PTR(-ENOSYS); 141 return ERR_PTR(-ENOSYS); 142 } 142 } 143 143 144 static inline void framer_destroy(struct frame 144 static inline void framer_destroy(struct framer *framer) 145 { 145 { 146 } 146 } 147 147 148 /* devm version */ 148 /* devm version */ 149 static inline struct framer *devm_framer_creat 149 static inline struct framer *devm_framer_create(struct device *dev, struct device_node *node, 150 150 const struct framer_ops *ops) 151 { 151 { 152 return ERR_PTR(-ENOSYS); 152 return ERR_PTR(-ENOSYS); 153 } 153 } 154 154 155 static inline struct framer *framer_provider_s 155 static inline struct framer *framer_provider_simple_of_xlate(struct device *dev, 156 156 const struct of_phandle_args *args) 157 { 157 { 158 return ERR_PTR(-ENOSYS); 158 return ERR_PTR(-ENOSYS); 159 } 159 } 160 160 161 static inline struct framer_provider * 161 static inline struct framer_provider * 162 __framer_provider_of_register(struct device *d 162 __framer_provider_of_register(struct device *dev, struct module *owner, 163 struct framer *( 163 struct framer *(*of_xlate)(struct device *dev, 164 164 const struct of_phandle_args *args)) 165 { 165 { 166 return ERR_PTR(-ENOSYS); 166 return ERR_PTR(-ENOSYS); 167 } 167 } 168 168 169 void framer_provider_of_unregister(struct fram 169 void framer_provider_of_unregister(struct framer_provider *framer_provider) 170 { 170 { 171 } 171 } 172 172 173 static inline struct framer_provider * 173 static inline struct framer_provider * 174 __devm_framer_provider_of_register(struct devi 174 __devm_framer_provider_of_register(struct device *dev, struct module *owner, 175 struct fram 175 struct framer *(*of_xlate)(struct device *dev, 176 176 const struct of_phandle_args *args)) 177 { 177 { 178 return ERR_PTR(-ENOSYS); 178 return ERR_PTR(-ENOSYS); 179 } 179 } 180 180 181 void framer_notify_status_change(struct framer 181 void framer_notify_status_change(struct framer *framer) 182 { 182 { 183 } 183 } 184 184 185 #endif /* IS_ENABLED(CONFIG_GENERIC_FRAMER) */ 185 #endif /* IS_ENABLED(CONFIG_GENERIC_FRAMER) */ 186 186 187 #define framer_provider_of_register(dev, xlate 187 #define framer_provider_of_register(dev, xlate) \ 188 __framer_provider_of_register((dev), T 188 __framer_provider_of_register((dev), THIS_MODULE, (xlate)) 189 189 190 #define devm_framer_provider_of_register(dev, 190 #define devm_framer_provider_of_register(dev, xlate) \ 191 __devm_framer_provider_of_register((de 191 __devm_framer_provider_of_register((dev), THIS_MODULE, (xlate)) 192 192 193 #endif /* __DRIVERS_PROVIDER_FRAMER_H */ 193 #endif /* __DRIVERS_PROVIDER_FRAMER_H */ 194 194
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.