1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * Generic framer header file
5 * Copyright 2023 CS GROUP France
7 * Author: Herve Codina <herve.codina@bootlin.com>
10 #ifndef __DRIVERS_FRAMER_H
11 #define __DRIVERS_FRAMER_H
13 #include <linux/err.h>
14 #include <linux/mutex.h>
15 #include <linux/notifier.h>
17 #include <linux/device.h>
18 #include <linux/workqueue.h>
21 * enum framer_iface - Framer interface
22 * @FRAMER_IFACE_E1: E1 interface
23 * @FRAMER_IFACE_T1: T1 interface
31 * enum framer_clock_type - Framer clock type
32 * @FRAMER_CLOCK_EXT: External clock
33 * @FRAMER_CLOCK_INT: Internal clock
35 enum framer_clock_type
{
41 * struct framer_config - Framer configuration
42 * @iface: Framer line interface
43 * @clock_type: Framer clock type
44 * @line_clock_rate: Framer line clock rate
46 struct framer_config
{
47 enum framer_iface iface
;
48 enum framer_clock_type clock_type
;
49 unsigned long line_clock_rate
;
53 * struct framer_status - Framer status
54 * @link_is_on: Framer link state. true, the link is on, false, the link is off.
56 struct framer_status
{
61 * enum framer_event - Event available for notification
62 * @FRAMER_EVENT_STATUS: Event notified on framer_status changes
69 * struct framer - represents the framer device
71 * @id: id of the framer device
72 * @ops: function pointers for performing framer operations
73 * @mutex: mutex to protect framer_ops
74 * @init_count: used to protect when the framer is used by multiple consumers
75 * @power_count: used to protect when the framer is used by multiple consumers
76 * @pwr: power regulator associated with the framer
77 * @notify_status_work: work structure used for status notifications
78 * @notifier_list: notifier list used for notifications
79 * @polling_work: delayed work structure used for the polling task
80 * @prev_status: previous read status used by the polling task to detect changes
85 const struct framer_ops
*ops
;
86 struct mutex mutex
; /* Protect framer */
89 struct regulator
*pwr
;
90 struct work_struct notify_status_work
;
91 struct blocking_notifier_head notifier_list
;
92 struct delayed_work polling_work
;
93 struct framer_status prev_status
;
96 #if IS_ENABLED(CONFIG_GENERIC_FRAMER)
97 int framer_pm_runtime_get(struct framer
*framer
);
98 int framer_pm_runtime_get_sync(struct framer
*framer
);
99 int framer_pm_runtime_put(struct framer
*framer
);
100 int framer_pm_runtime_put_sync(struct framer
*framer
);
101 int framer_init(struct framer
*framer
);
102 int framer_exit(struct framer
*framer
);
103 int framer_power_on(struct framer
*framer
);
104 int framer_power_off(struct framer
*framer
);
105 int framer_get_status(struct framer
*framer
, struct framer_status
*status
);
106 int framer_get_config(struct framer
*framer
, struct framer_config
*config
);
107 int framer_set_config(struct framer
*framer
, const struct framer_config
*config
);
108 int framer_notifier_register(struct framer
*framer
, struct notifier_block
*nb
);
109 int framer_notifier_unregister(struct framer
*framer
, struct notifier_block
*nb
);
111 struct framer
*framer_get(struct device
*dev
, const char *con_id
);
112 void framer_put(struct device
*dev
, struct framer
*framer
);
114 struct framer
*devm_framer_get(struct device
*dev
, const char *con_id
);
115 struct framer
*devm_framer_optional_get(struct device
*dev
, const char *con_id
);
117 static inline int framer_pm_runtime_get(struct framer
*framer
)
122 static inline int framer_pm_runtime_get_sync(struct framer
*framer
)
127 static inline int framer_pm_runtime_put(struct framer
*framer
)
132 static inline int framer_pm_runtime_put_sync(struct framer
*framer
)
137 static inline int framer_init(struct framer
*framer
)
142 static inline int framer_exit(struct framer
*framer
)
147 static inline int framer_power_on(struct framer
*framer
)
152 static inline int framer_power_off(struct framer
*framer
)
157 static inline int framer_get_status(struct framer
*framer
, struct framer_status
*status
)
162 static inline int framer_get_config(struct framer
*framer
, struct framer_config
*config
)
167 static inline int framer_set_config(struct framer
*framer
, const struct framer_config
*config
)
172 static inline int framer_notifier_register(struct framer
*framer
,
173 struct notifier_block
*nb
)
178 static inline int framer_notifier_unregister(struct framer
*framer
,
179 struct notifier_block
*nb
)
184 static inline struct framer
*framer_get(struct device
*dev
, const char *con_id
)
186 return ERR_PTR(-ENOSYS
);
189 static inline void framer_put(struct device
*dev
, struct framer
*framer
)
193 static inline struct framer
*devm_framer_get(struct device
*dev
, const char *con_id
)
195 return ERR_PTR(-ENOSYS
);
198 static inline struct framer
*devm_framer_optional_get(struct device
*dev
, const char *con_id
)
205 #endif /* __DRIVERS_FRAMER_H */