1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * Generic framer profider header file
5 * Copyright 2023 CS GROUP France
7 * Author: Herve Codina <herve.codina@bootlin.com>
10 #ifndef __DRIVERS_PROVIDER_FRAMER_H
11 #define __DRIVERS_PROVIDER_FRAMER_H
13 #include <linux/export.h>
14 #include <linux/framer/framer.h>
15 #include <linux/types.h>
17 #define FRAMER_FLAG_POLL_STATUS BIT(0)
20 * struct framer_ops - set of function pointers for performing framer operations
21 * @init: operation to be performed for initializing the framer
22 * @exit: operation to be performed while exiting
23 * @power_on: powering on the framer
24 * @power_off: powering off the framer
25 * @flags: OR-ed flags (FRAMER_FLAG_*) to ask for core functionality
26 * - @FRAMER_FLAG_POLL_STATUS:
27 * Ask the core to perform a polling to get the framer status and
28 * notify consumers on change.
29 * The framer should call @framer_notify_status_change() when it
30 * detects a status change. This is usually done using interrupts.
31 * If the framer cannot detect this change, it can ask the core for
32 * a status polling. The core will call @get_status() periodically
33 * and, on change detected, it will notify the consumer.
35 * @owner: the module owner containing the ops
38 int (*init)(struct framer *framer);
39 void (*exit)(struct framer *framer);
40 int (*power_on)(struct framer *framer);
41 int (*power_off)(struct framer *framer);
48 * Used to get the framer status. framer_init() must have
49 * been called on the framer.
51 * Returns: 0 if successful, an negative error code otherwise
53 int (*get_status)(struct framer *framer, struct framer_status *status);
60 * Used to set the framer configuration. framer_init() must have
61 * been called on the framer.
63 * Returns: 0 if successful, an negative error code otherwise
65 int (*set_config)(struct framer *framer, const struct framer_config *config);
72 * Used to get the framer configuration. framer_init() must have
73 * been called on the framer.
75 * Returns: 0 if successful, an negative error code otherwise
77 int (*get_config)(struct framer *framer, struct framer_config *config);
84 * struct framer_provider - represents the framer provider
85 * @dev: framer provider device
86 * @owner: the module owner having of_xlate
87 * @list: to maintain a linked list of framer providers
88 * @of_xlate: function pointer to obtain framer instance from framer pointer
90 struct framer_provider {
93 struct list_head list;
94 struct framer * (*of_xlate)(struct device *dev,
95 const struct of_phandle_args *args);
98 static inline void framer_set_drvdata(struct framer *framer, void *data)
100 dev_set_drvdata(&framer->dev, data);
103 static inline void *framer_get_drvdata(struct framer *framer)
105 return dev_get_drvdata(&framer->dev);
108 #if IS_ENABLED(CONFIG_GENERIC_FRAMER)
110 /* Create and destroy a framer */
111 struct framer *framer_create(struct device *dev, struct device_node *node,
112 const struct framer_ops *ops);
113 void framer_destroy(struct framer *framer);
116 struct framer *devm_framer_create(struct device *dev, struct device_node *node,
117 const struct framer_ops *ops);
119 struct framer *framer_provider_simple_of_xlate(struct device *dev,
120 const struct of_phandle_args *args);
122 struct framer_provider *
123 __framer_provider_of_register(struct device *dev, struct module *owner,
124 struct framer *(*of_xlate)(struct device *dev,
125 const struct of_phandle_args *args));
127 void framer_provider_of_unregister(struct framer_provider *framer_provider);
129 struct framer_provider *
130 __devm_framer_provider_of_register(struct device *dev, struct module *owner,
131 struct framer *(*of_xlate)(struct device *dev,
132 const struct of_phandle_args *args));
134 void framer_notify_status_change(struct framer *framer);
136 #else /* IS_ENABLED(CONFIG_GENERIC_FRAMER) */
138 static inline struct framer *framer_create(struct device *dev, struct device_node *node,
139 const struct framer_ops *ops)
141 return ERR_PTR(-ENOSYS);
144 static inline void framer_destroy(struct framer *framer)
149 static inline struct framer *devm_framer_create(struct device *dev, struct device_node *node,
150 const struct framer_ops *ops)
152 return ERR_PTR(-ENOSYS);
155 static inline struct framer *framer_provider_simple_of_xlate(struct device *dev,
156 const struct of_phandle_args *args)
158 return ERR_PTR(-ENOSYS);
161 static inline struct framer_provider *
162 __framer_provider_of_register(struct device *dev, struct module *owner,
163 struct framer *(*of_xlate)(struct device *dev,
164 const struct of_phandle_args *args))
166 return ERR_PTR(-ENOSYS);
169 void framer_provider_of_unregister(struct framer_provider *framer_provider)
173 static inline struct framer_provider *
174 __devm_framer_provider_of_register(struct device *dev, struct module *owner,
175 struct framer *(*of_xlate)(struct device *dev,
176 const struct of_phandle_args *args))
178 return ERR_PTR(-ENOSYS);
181 void framer_notify_status_change(struct framer *framer)
185 #endif /* IS_ENABLED(CONFIG_GENERIC_FRAMER) */
187 #define framer_provider_of_register(dev, xlate) \
188 __framer_provider_of_register((dev), THIS_MODULE, (xlate))
190 #define devm_framer_provider_of_register(dev, xlate) \
191 __devm_framer_provider_of_register((dev), THIS_MODULE, (xlate))
193 #endif /* __DRIVERS_PROVIDER_FRAMER_H */