Inaky Perez-Gonzalez | 183b9b5 | 2008-09-17 16:34:06 +0100 | [diff] [blame] | 1 | /* |
| 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 Vrabel | dcc7461 | 2008-11-26 13:36:59 +0000 | [diff] [blame] | 19 | #include <linux/debugfs.h> |
Inaky Perez-Gonzalez | 183b9b5 | 2008-09-17 16:34:06 +0100 | [diff] [blame] | 20 | #include <linux/uwb.h> |
Paul Gortmaker | 475c0a6 | 2011-07-10 13:18:02 -0400 | [diff] [blame] | 21 | #include <linux/export.h> |
Inaky Perez-Gonzalez | 183b9b5 | 2008-09-17 16:34:06 +0100 | [diff] [blame] | 22 | |
| 23 | #include "uwb-internal.h" |
| 24 | |
| 25 | /** |
| 26 | * uwb_pal_init - initialize a UWB PAL |
| 27 | * @pal: the PAL to initialize |
| 28 | */ |
| 29 | void uwb_pal_init(struct uwb_pal *pal) |
| 30 | { |
| 31 | INIT_LIST_HEAD(&pal->node); |
| 32 | } |
| 33 | EXPORT_SYMBOL_GPL(uwb_pal_init); |
| 34 | |
| 35 | /** |
| 36 | * uwb_pal_register - register a UWB PAL |
Inaky Perez-Gonzalez | 183b9b5 | 2008-09-17 16:34:06 +0100 | [diff] [blame] | 37 | * @pal: the PAL |
| 38 | * |
| 39 | * The PAL must be initialized with uwb_pal_init(). |
| 40 | */ |
David Vrabel | 6fae35f | 2008-11-17 15:53:42 +0000 | [diff] [blame] | 41 | int uwb_pal_register(struct uwb_pal *pal) |
Inaky Perez-Gonzalez | 183b9b5 | 2008-09-17 16:34:06 +0100 | [diff] [blame] | 42 | { |
David Vrabel | 6fae35f | 2008-11-17 15:53:42 +0000 | [diff] [blame] | 43 | struct uwb_rc *rc = pal->rc; |
David Vrabel | b60066c | 2008-09-17 16:34:40 +0100 | [diff] [blame] | 44 | int ret; |
| 45 | |
| 46 | if (pal->device) { |
Thomas Pugliese | a899575 | 2013-06-24 14:26:35 -0500 | [diff] [blame] | 47 | /* create a link to the uwb_rc in the PAL device's directory. */ |
David Vrabel | b60066c | 2008-09-17 16:34:40 +0100 | [diff] [blame] | 48 | ret = sysfs_create_link(&pal->device->kobj, |
| 49 | &rc->uwb_dev.dev.kobj, "uwb_rc"); |
| 50 | if (ret < 0) |
| 51 | return ret; |
Thomas Pugliese | a899575 | 2013-06-24 14:26:35 -0500 | [diff] [blame] | 52 | /* create a link to the PAL in the UWB device's directory. */ |
David Vrabel | b60066c | 2008-09-17 16:34:40 +0100 | [diff] [blame] | 53 | ret = sysfs_create_link(&rc->uwb_dev.dev.kobj, |
| 54 | &pal->device->kobj, pal->name); |
| 55 | if (ret < 0) { |
| 56 | sysfs_remove_link(&pal->device->kobj, "uwb_rc"); |
| 57 | return ret; |
| 58 | } |
| 59 | } |
| 60 | |
David Vrabel | dcc7461 | 2008-11-26 13:36:59 +0000 | [diff] [blame] | 61 | pal->debugfs_dir = uwb_dbg_create_pal_dir(pal); |
| 62 | |
David Vrabel | 6fae35f | 2008-11-17 15:53:42 +0000 | [diff] [blame] | 63 | mutex_lock(&rc->uwb_dev.mutex); |
Inaky Perez-Gonzalez | 183b9b5 | 2008-09-17 16:34:06 +0100 | [diff] [blame] | 64 | list_add(&pal->node, &rc->pals); |
David Vrabel | 6fae35f | 2008-11-17 15:53:42 +0000 | [diff] [blame] | 65 | mutex_unlock(&rc->uwb_dev.mutex); |
Inaky Perez-Gonzalez | 183b9b5 | 2008-09-17 16:34:06 +0100 | [diff] [blame] | 66 | |
| 67 | return 0; |
| 68 | } |
| 69 | EXPORT_SYMBOL_GPL(uwb_pal_register); |
| 70 | |
| 71 | /** |
| 72 | * uwb_pal_register - unregister a UWB PAL |
Inaky Perez-Gonzalez | 183b9b5 | 2008-09-17 16:34:06 +0100 | [diff] [blame] | 73 | * @pal: the PAL |
| 74 | */ |
David Vrabel | 6fae35f | 2008-11-17 15:53:42 +0000 | [diff] [blame] | 75 | void uwb_pal_unregister(struct uwb_pal *pal) |
Inaky Perez-Gonzalez | 183b9b5 | 2008-09-17 16:34:06 +0100 | [diff] [blame] | 76 | { |
David Vrabel | 6fae35f | 2008-11-17 15:53:42 +0000 | [diff] [blame] | 77 | struct uwb_rc *rc = pal->rc; |
| 78 | |
| 79 | uwb_radio_stop(pal); |
| 80 | |
| 81 | mutex_lock(&rc->uwb_dev.mutex); |
Inaky Perez-Gonzalez | 183b9b5 | 2008-09-17 16:34:06 +0100 | [diff] [blame] | 82 | list_del(&pal->node); |
David Vrabel | 6fae35f | 2008-11-17 15:53:42 +0000 | [diff] [blame] | 83 | mutex_unlock(&rc->uwb_dev.mutex); |
David Vrabel | b60066c | 2008-09-17 16:34:40 +0100 | [diff] [blame] | 84 | |
David Vrabel | dcc7461 | 2008-11-26 13:36:59 +0000 | [diff] [blame] | 85 | debugfs_remove(pal->debugfs_dir); |
| 86 | |
David Vrabel | b60066c | 2008-09-17 16:34:40 +0100 | [diff] [blame] | 87 | if (pal->device) { |
| 88 | sysfs_remove_link(&rc->uwb_dev.dev.kobj, pal->name); |
| 89 | sysfs_remove_link(&pal->device->kobj, "uwb_rc"); |
| 90 | } |
Inaky Perez-Gonzalez | 183b9b5 | 2008-09-17 16:34:06 +0100 | [diff] [blame] | 91 | } |
| 92 | EXPORT_SYMBOL_GPL(uwb_pal_unregister); |
| 93 | |
| 94 | /** |
| 95 | * uwb_rc_pal_init - initialize the PAL related parts of a radio controller |
| 96 | * @rc: the radio controller |
| 97 | */ |
| 98 | void uwb_rc_pal_init(struct uwb_rc *rc) |
| 99 | { |
Inaky Perez-Gonzalez | 183b9b5 | 2008-09-17 16:34:06 +0100 | [diff] [blame] | 100 | INIT_LIST_HEAD(&rc->pals); |
| 101 | } |