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