xref: /linux/drivers/dpll/dpll_core.h (revision c532de5a67a70f8533d495f8f2aaa9a0491c3ad0)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  *  Copyright (c) 2023 Meta Platforms, Inc. and affiliates
4  *  Copyright (c) 2023 Intel and affiliates
5  */
6 
7 #ifndef __DPLL_CORE_H__
8 #define __DPLL_CORE_H__
9 
10 #include <linux/dpll.h>
11 #include <linux/list.h>
12 #include <linux/refcount.h>
13 #include "dpll_nl.h"
14 
15 #define DPLL_REGISTERED		XA_MARK_1
16 
17 /**
18  * struct dpll_device - stores DPLL device internal data
19  * @id:			unique id number for device given by dpll subsystem
20  * @device_idx:		id given by dev driver
21  * @clock_id:		unique identifier (clock_id) of a dpll
22  * @module:		module of creator
23  * @type:		type of a dpll
24  * @pin_refs:		stores pins registered within a dpll
25  * @refcount:		refcount
26  * @registration_list:	list of registered ops and priv data of dpll owners
27  **/
28 struct dpll_device {
29 	u32 id;
30 	u32 device_idx;
31 	u64 clock_id;
32 	struct module *module;
33 	enum dpll_type type;
34 	struct xarray pin_refs;
35 	refcount_t refcount;
36 	struct list_head registration_list;
37 };
38 
39 /**
40  * struct dpll_pin - structure for a dpll pin
41  * @id:			unique id number for pin given by dpll subsystem
42  * @pin_idx:		index of a pin given by dev driver
43  * @clock_id:		clock_id of creator
44  * @module:		module of creator
45  * @dpll_refs:		hold referencees to dplls pin was registered with
46  * @parent_refs:	hold references to parent pins pin was registered with
47  * @prop:		pin properties copied from the registerer
48  * @rclk_dev_name:	holds name of device when pin can recover clock from it
49  * @refcount:		refcount
50  * @rcu:		rcu_head for kfree_rcu()
51  **/
52 struct dpll_pin {
53 	u32 id;
54 	u32 pin_idx;
55 	u64 clock_id;
56 	struct module *module;
57 	struct xarray dpll_refs;
58 	struct xarray parent_refs;
59 	struct dpll_pin_properties prop;
60 	refcount_t refcount;
61 	struct rcu_head rcu;
62 };
63 
64 /**
65  * struct dpll_pin_ref - structure for referencing either dpll or pins
66  * @dpll:		pointer to a dpll
67  * @pin:		pointer to a pin
68  * @registration_list:	list of ops and priv data registered with the ref
69  * @refcount:		refcount
70  **/
71 struct dpll_pin_ref {
72 	union {
73 		struct dpll_device *dpll;
74 		struct dpll_pin *pin;
75 	};
76 	struct list_head registration_list;
77 	refcount_t refcount;
78 };
79 
80 void *dpll_priv(struct dpll_device *dpll);
81 void *dpll_pin_on_dpll_priv(struct dpll_device *dpll, struct dpll_pin *pin);
82 void *dpll_pin_on_pin_priv(struct dpll_pin *parent, struct dpll_pin *pin);
83 
84 const struct dpll_device_ops *dpll_device_ops(struct dpll_device *dpll);
85 struct dpll_device *dpll_device_get_by_id(int id);
86 const struct dpll_pin_ops *dpll_pin_ops(struct dpll_pin_ref *ref);
87 struct dpll_pin_ref *dpll_xa_ref_dpll_first(struct xarray *xa_refs);
88 extern struct xarray dpll_device_xa;
89 extern struct xarray dpll_pin_xa;
90 extern struct mutex dpll_lock;
91 #endif
92