blob: 99a19c199095fd817ceb519922389a6a424abba9 [file] [log] [blame]
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +01001/*
2 * UWB PAL support.
3 *
4 * Copyright (C) 2008 Cambridge Silicon Radio Ltd.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License version
8 * 2 as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18#include <linux/kernel.h>
David Vrabeldcc74612008-11-26 13:36:59 +000019#include <linux/debugfs.h>
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +010020#include <linux/uwb.h>
21
22#include "uwb-internal.h"
23
24/**
25 * uwb_pal_init - initialize a UWB PAL
26 * @pal: the PAL to initialize
27 */
28void uwb_pal_init(struct uwb_pal *pal)
29{
30 INIT_LIST_HEAD(&pal->node);
31}
32EXPORT_SYMBOL_GPL(uwb_pal_init);
33
34/**
35 * uwb_pal_register - register a UWB PAL
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +010036 * @pal: the PAL
37 *
38 * The PAL must be initialized with uwb_pal_init().
39 */
David Vrabel6fae35f2008-11-17 15:53:42 +000040int uwb_pal_register(struct uwb_pal *pal)
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +010041{
David Vrabel6fae35f2008-11-17 15:53:42 +000042 struct uwb_rc *rc = pal->rc;
David Vrabelb60066c2008-09-17 16:34:40 +010043 int ret;
44
45 if (pal->device) {
46 ret = sysfs_create_link(&pal->device->kobj,
47 &rc->uwb_dev.dev.kobj, "uwb_rc");
48 if (ret < 0)
49 return ret;
50 ret = sysfs_create_link(&rc->uwb_dev.dev.kobj,
51 &pal->device->kobj, pal->name);
52 if (ret < 0) {
53 sysfs_remove_link(&pal->device->kobj, "uwb_rc");
54 return ret;
55 }
56 }
57
David Vrabeldcc74612008-11-26 13:36:59 +000058 pal->debugfs_dir = uwb_dbg_create_pal_dir(pal);
59
David Vrabel6fae35f2008-11-17 15:53:42 +000060 mutex_lock(&rc->uwb_dev.mutex);
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +010061 list_add(&pal->node, &rc->pals);
David Vrabel6fae35f2008-11-17 15:53:42 +000062 mutex_unlock(&rc->uwb_dev.mutex);
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +010063
64 return 0;
65}
66EXPORT_SYMBOL_GPL(uwb_pal_register);
67
68/**
69 * uwb_pal_register - unregister a UWB PAL
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +010070 * @pal: the PAL
71 */
David Vrabel6fae35f2008-11-17 15:53:42 +000072void uwb_pal_unregister(struct uwb_pal *pal)
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +010073{
David Vrabel6fae35f2008-11-17 15:53:42 +000074 struct uwb_rc *rc = pal->rc;
75
76 uwb_radio_stop(pal);
77
78 mutex_lock(&rc->uwb_dev.mutex);
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +010079 list_del(&pal->node);
David Vrabel6fae35f2008-11-17 15:53:42 +000080 mutex_unlock(&rc->uwb_dev.mutex);
David Vrabelb60066c2008-09-17 16:34:40 +010081
David Vrabeldcc74612008-11-26 13:36:59 +000082 debugfs_remove(pal->debugfs_dir);
83
David Vrabelb60066c2008-09-17 16:34:40 +010084 if (pal->device) {
85 sysfs_remove_link(&rc->uwb_dev.dev.kobj, pal->name);
86 sysfs_remove_link(&pal->device->kobj, "uwb_rc");
87 }
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +010088}
89EXPORT_SYMBOL_GPL(uwb_pal_unregister);
90
91/**
92 * uwb_rc_pal_init - initialize the PAL related parts of a radio controller
93 * @rc: the radio controller
94 */
95void uwb_rc_pal_init(struct uwb_rc *rc)
96{
Inaky Perez-Gonzalez183b9b52008-09-17 16:34:06 +010097 INIT_LIST_HEAD(&rc->pals);
98}