1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (C) 2008 Cambridge Silicon Radio Ltd.
7 #include <linux/kernel.h>
8 #include <linux/debugfs.h>
10 #include <linux/export.h>
12 #include "uwb-internal.h"
15 * uwb_pal_init - initialize a UWB PAL
16 * @pal: the PAL to initialize
18 void uwb_pal_init(struct uwb_pal *pal)
20 INIT_LIST_HEAD(&pal->node);
22 EXPORT_SYMBOL_GPL(uwb_pal_init);
25 * uwb_pal_register - register a UWB PAL
28 * The PAL must be initialized with uwb_pal_init().
30 int uwb_pal_register(struct uwb_pal *pal)
32 struct uwb_rc *rc = pal->rc;
36 /* create a link to the uwb_rc in the PAL device's directory. */
37 ret = sysfs_create_link(&pal->device->kobj,
38 &rc->uwb_dev.dev.kobj, "uwb_rc");
41 /* create a link to the PAL in the UWB device's directory. */
42 ret = sysfs_create_link(&rc->uwb_dev.dev.kobj,
43 &pal->device->kobj, pal->name);
45 sysfs_remove_link(&pal->device->kobj, "uwb_rc");
50 pal->debugfs_dir = uwb_dbg_create_pal_dir(pal);
52 mutex_lock(&rc->uwb_dev.mutex);
53 list_add(&pal->node, &rc->pals);
54 mutex_unlock(&rc->uwb_dev.mutex);
58 EXPORT_SYMBOL_GPL(uwb_pal_register);
60 static int find_rc(struct device *dev, const void *data)
62 const struct uwb_rc *target_rc = data;
63 struct uwb_rc *rc = dev_get_drvdata(dev);
69 if (rc == target_rc) {
79 * Given a radio controller descriptor see if it is registered.
81 * @returns false if the rc does not exist or is quiescing; true otherwise.
83 static bool uwb_rc_class_device_exists(struct uwb_rc *target_rc)
87 dev = class_find_device(&uwb_rc_class, NULL, target_rc, find_rc);
95 * uwb_pal_unregister - unregister a UWB PAL
98 void uwb_pal_unregister(struct uwb_pal *pal)
100 struct uwb_rc *rc = pal->rc;
104 mutex_lock(&rc->uwb_dev.mutex);
105 list_del(&pal->node);
106 mutex_unlock(&rc->uwb_dev.mutex);
108 debugfs_remove(pal->debugfs_dir);
111 /* remove link to the PAL in the UWB device's directory. */
112 if (uwb_rc_class_device_exists(rc))
113 sysfs_remove_link(&rc->uwb_dev.dev.kobj, pal->name);
115 /* remove link to uwb_rc in the PAL device's directory. */
116 sysfs_remove_link(&pal->device->kobj, "uwb_rc");
119 EXPORT_SYMBOL_GPL(uwb_pal_unregister);
122 * uwb_rc_pal_init - initialize the PAL related parts of a radio controller
123 * @rc: the radio controller
125 void uwb_rc_pal_init(struct uwb_rc *rc)
127 INIT_LIST_HEAD(&rc->pals);