Skip to content

Commit

Permalink
Staging: add CSR Wifi "os helper" module
Browse files Browse the repository at this point in the history
This module is used by the CSR wifi driver to "abstract" away the
OS-specific parts of core functions.  It will be eventually deleted, but
for now is needed as the CSR driver relies on it.

Cc: Mikko Virkkilä <mikko.virkkila@bluegiga.com>
Cc: Lauri Hintsala <Lauri.Hintsala@bluegiga.com>
Cc: Riku Mettälä <riku.mettala@bluegiga.com>
Cc: Veli-Pekka Peltola <veli-pekka.peltola@bluegiga.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Greg Kroah-Hartman committed Jun 19, 2012
1 parent 55232ec commit 15a4bc1
Show file tree
Hide file tree
Showing 30 changed files with 1,451 additions and 0 deletions.
2 changes: 2 additions & 0 deletions drivers/staging/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,6 @@ source "drivers/staging/ipack/Kconfig"

source "drivers/staging/gdm72xx/Kconfig"

source "drivers/staging/csr/Kconfig"

endif # STAGING
1 change: 1 addition & 0 deletions drivers/staging/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,4 @@ obj-$(CONFIG_RAMSTER) += ramster/
obj-$(CONFIG_USB_WPAN_HCD) += ozwpan/
obj-$(CONFIG_USB_G_CCG) += ccg/
obj-$(CONFIG_WIMAX_GDM72XX) += gdm72xx/
obj-$(CONFIG_CSR_WIFI) += csr/
7 changes: 7 additions & 0 deletions drivers/staging/csr/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
config CSR_WIFI
tristate "CSR wireless driver"
depends on PCI
help
Driver for the CSR wireless SDIO device.

If unsure, select N.
1 change: 1 addition & 0 deletions drivers/staging/csr/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
obj-$(CONFIG_CSR_WIFI) += oska/
12 changes: 12 additions & 0 deletions drivers/staging/csr/oska/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
obj-$(CONFIG_CSR_WIFI) := csr_oska.o

csr_oska-y := \
list.o \
refcount.o \
compat.o \
event.o \
oska_module.o \
print.o \
thread.o \
timer.o

61 changes: 61 additions & 0 deletions drivers/staging/csr/oska/all.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Operating system kernel abstraction -- all functions
*
* Copyright (C) 2007 Cambridge Silicon Radio Ltd.
*
* Refer to LICENSE.txt included with this source code for details on
* the license terms.
*/
#ifndef __OSKA_ALL_H
#define __OSKA_ALL_H

/**
* @mainpage Operating System Kernel Abstraction
*
* @section intro Introduction
*
* The Operating System Kernel Abstraction (oska) is a software
* package providing an abstraction for various operating system
* kernel facilities for use by device drivers and other OS kernel
* software (e.g., SDIO stacks). Oska is modularized and intended to
* be a lightweight wrapper around an OSes interfaces.
*
* @section modules Modules
*
* Oska is organized into the modules, each of which has it's own
* header file providing the interface.
*
* - \ref alloc "Memory allocation" <oska/alloc.h>
* - \ref event "Events" <oska/event.h>
* - \ref mutex "Mutexes" <oska/mutex.h>
* - \ref print "Console output" <oska/print.h>
* - \ref spinlock "Spinlocks" <oska/spinlock.h>
* - \ref thread "Threading" <oska/thread.h>
* - \ref time "Timing and delays" <oska/time.h>
* - \ref timer "Timers" <oska/timer.h>
* - \ref types "Standard Types" <oska/types.h>
* - \ref util "Miscellaneous utilities" <oska/util.h>
*
* An <oska/all.h> header is provided which includes all the above
* modules.
*
* There are additional modules that are not included in <oska/all.h>.
*
* - \ref io "Memory mapped I/O" <oska/io.h>
* - \ref refcount "Reference Counting" <oska/refcount.h>
* - \ref list "Linked lists" <oska/list.h>
* - \ref trace "Tracing messages" <oska/trace.h>
*/

#include "alloc.h"
#include "event.h"
#include "mutex.h"
#include "print.h"
#include "spinlock.h"
#include "thread.h"
#include "time.h"
#include "timer.h"
#include "types.h"
#include "util.h"

#endif /* __OSKA_ALL_H */
41 changes: 41 additions & 0 deletions drivers/staging/csr/oska/alloc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* OSKA Linux implementation -- memory allocation
*
* Copyright (C) 2007 Cambridge Silicon Radio Ltd.
*
* Refer to LICENSE.txt included with this source code for details on
* the license terms.
*/
#ifndef __OSKA_LINUX_ALLOC_H
#define __OSKA_LINUX_ALLOC_H

#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/vmalloc.h>

static inline void *os_alloc(size_t size)
{
return kzalloc(size, GFP_ATOMIC);
}

static inline void *os_alloc_nonzeroed(size_t size)
{
return kmalloc(size, GFP_KERNEL);
}

static inline void os_free(void *ptr)
{
kfree(ptr);
}

static inline void *os_alloc_big(size_t size)
{
return vmalloc(size);
}

static inline void os_free_big(void *ptr)
{
vfree(ptr);
}

#endif /* #ifndef __OSKA_LINUX_ALLOC_H */
54 changes: 54 additions & 0 deletions drivers/staging/csr/oska/compat.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Linux version compatibility functions.
*
* Copyright (C) 2008 Cambridge Silicon Radio Ltd.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version
* 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* Refer to LICENSE.txt included with this source code for details on
* the license terms.
*/
#include "kernel-compat.h"

#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26)

int dev_set_name(struct device *dev, const char *fmt, ...)
{
va_list vargs;

va_start(vargs, fmt);
vsnprintf(dev->bus_id, sizeof(dev->bus_id), fmt, vargs);
va_end(vargs);
return 0;
}
EXPORT_SYMBOL_GPL(dev_set_name);

#endif /* Linux kernel < 2.6.26 */

#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25)

struct device *class_find_device(struct class *class, struct device *start,
void *data, int (*match)(struct device *, void *))
{
struct device *dev;

list_for_each_entry(dev, &class->devices, node) {
if (match(dev, data)) {
get_device(dev);
return dev;
}
}
return NULL;
}
EXPORT_SYMBOL_GPL(class_find_device);

#endif /* Linux kernel < 2.6.25 */
82 changes: 82 additions & 0 deletions drivers/staging/csr/oska/event.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Linux event functions.
*
* Copyright (C) 2009 Cambridge Silicon Radio Ltd.
*
* Refer to LICENSE.txt included with this source code for details on
* the license terms.
*/
#include <linux/module.h>
#include <linux/sched.h>

#include "event.h"

void os_event_init(os_event_t *evt)
{
init_waitqueue_head(&evt->wq);
spin_lock_init(&evt->lock);
evt->events = 0;
}
EXPORT_SYMBOL(os_event_init);

uint16_t os_event_wait(os_event_t *evt)
{
uint16_t e;
unsigned long flags;

wait_event(evt->wq, evt->events != 0);

spin_lock_irqsave(&evt->lock, flags);
e = evt->events;
evt->events &= ~e;
spin_unlock_irqrestore(&evt->lock, flags);

return e;
}
EXPORT_SYMBOL(os_event_wait);

uint16_t os_event_wait_interruptible(os_event_t *evt)
{
uint16_t e;
unsigned long flags;

wait_event_interruptible(evt->wq, evt->events != 0);

spin_lock_irqsave(&evt->lock, flags);
e = evt->events;
evt->events &= ~e;
spin_unlock_irqrestore(&evt->lock, flags);

return e;
}
EXPORT_SYMBOL(os_event_wait_interruptible);

uint16_t os_event_wait_timed(os_event_t *evt, unsigned timeout_ms)
{
uint16_t e;
unsigned long flags;

wait_event_interruptible_timeout(evt->wq,
evt->events != 0,
msecs_to_jiffies(timeout_ms));

spin_lock_irqsave(&evt->lock, flags);
e = evt->events;
evt->events &= ~e;
spin_unlock_irqrestore(&evt->lock, flags);

return e;
}
EXPORT_SYMBOL(os_event_wait_timed);

void os_event_raise(os_event_t *evt, uint16_t events)
{
unsigned long flags;

spin_lock_irqsave(&evt->lock, flags);
evt->events |= events;
spin_unlock_irqrestore(&evt->lock, flags);

wake_up(&evt->wq);
}
EXPORT_SYMBOL(os_event_raise);
33 changes: 33 additions & 0 deletions drivers/staging/csr/oska/event.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* OSKA Linux implementation -- events
*
* Copyright (C) 2009 Cambridge Silicon Radio Ltd.
*
* Refer to LICENSE.txt included with this source code for details on
* the license terms.
*/
#ifndef __OSKA_LINUX_EVENT_H
#define __OSKA_LINUX_EVENT_H

#include <linux/kernel.h>
#include <linux/wait.h>
#include <linux/spinlock.h>

typedef struct {
wait_queue_head_t wq;
spinlock_t lock;
uint16_t events;
} os_event_t;

void os_event_init(os_event_t *evt);

static inline void os_event_destroy(os_event_t *evt)
{
}

uint16_t os_event_wait(os_event_t *evt);
uint16_t os_event_wait_interruptible(os_event_t *evt);
uint16_t os_event_wait_timed(os_event_t *evt, unsigned timeout_ms);
void os_event_raise(os_event_t *evt, uint16_t events);

#endif /* #ifndef __OSKA_LINUX_EVENT_H */
63 changes: 63 additions & 0 deletions drivers/staging/csr/oska/io.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* OSKA Linux implementation -- memory mapped I/O.
*
* Copyright (C) 2009 Cambridge Silicon Radio Ltd.
*
* Refer to LICENSE.txt included with this source code for details on
* the license terms.
*/
#ifndef __OSKA_LINUX_IO_H
#define __OSKA_LINUX_IO_H

#include <linux/kernel.h>
#include <linux/io.h>
#include <linux/kernel-compat.h>

typedef void __iomem *os_io_mem_t;

static inline uint8_t os_io_read8(os_io_mem_t base, unsigned offset)
{
return readb(base + offset);
}

static inline uint16_t os_io_read16(os_io_mem_t base, unsigned offset)
{
return readw(base + offset);
}

static inline uint32_t os_io_read32(os_io_mem_t base, unsigned offset)
{
return readl(base + offset);
}

static inline uint64_t os_io_read64(os_io_mem_t base, unsigned offset)
{
return readq(base + offset);
}

static inline void os_io_write8(os_io_mem_t base, unsigned offset, uint8_t val)
{
writeb(val, base + offset);
}

static inline void os_io_write16(os_io_mem_t base, unsigned offset, uint16_t val)
{
writew(val, base + offset);
}

static inline void os_io_write32(os_io_mem_t base, unsigned offset, uint32_t val)
{
writel(val, base + offset);
}

static inline void os_io_write64(os_io_mem_t base, unsigned offset, uint64_t val)
{
writeq(val, base + offset);
}

static inline void os_io_memory_barrier(void)
{
mb();
}

#endif /* #ifndef __OSKA_LINUX_IO_H */
Loading

0 comments on commit 15a4bc1

Please sign in to comment.