David Herrmann | 43e5e7c | 2011-11-17 14:12:10 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * Debug support for HID Nintendo Wiimote devices |
| 3 | * Copyright (c) 2011 David Herrmann |
| 4 | */ |
| 5 | |
| 6 | /* |
| 7 | * This program is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License as published by the Free |
| 9 | * Software Foundation; either version 2 of the License, or (at your option) |
| 10 | * any later version. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/spinlock.h> |
| 15 | #include "hid-wiimote.h" |
| 16 | |
| 17 | struct wiimote_debug { |
| 18 | struct wiimote_data *wdata; |
| 19 | }; |
| 20 | |
| 21 | int wiidebug_init(struct wiimote_data *wdata) |
| 22 | { |
| 23 | struct wiimote_debug *dbg; |
| 24 | unsigned long flags; |
| 25 | |
| 26 | dbg = kzalloc(sizeof(*dbg), GFP_KERNEL); |
| 27 | if (!dbg) |
| 28 | return -ENOMEM; |
| 29 | |
| 30 | dbg->wdata = wdata; |
| 31 | |
| 32 | spin_lock_irqsave(&wdata->state.lock, flags); |
| 33 | wdata->debug = dbg; |
| 34 | spin_unlock_irqrestore(&wdata->state.lock, flags); |
| 35 | |
| 36 | return 0; |
| 37 | } |
| 38 | |
| 39 | void wiidebug_deinit(struct wiimote_data *wdata) |
| 40 | { |
| 41 | struct wiimote_debug *dbg = wdata->debug; |
| 42 | unsigned long flags; |
| 43 | |
| 44 | if (!dbg) |
| 45 | return; |
| 46 | |
| 47 | spin_lock_irqsave(&wdata->state.lock, flags); |
| 48 | wdata->debug = NULL; |
| 49 | spin_unlock_irqrestore(&wdata->state.lock, flags); |
| 50 | |
| 51 | kfree(dbg); |
| 52 | } |