00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00021
#ifndef _LISO_H_
00022
#define _LISO_H_
00023
00024
#include <linux/config.h>
00025
#include <linux/devfs_fs_kernel.h>
00026
#include <linux/fs.h>
00027
#include <linux/init.h>
00028
#include <linux/kernel.h>
00029
#include <linux/kmod.h>
00030
#include <linux/major.h>
00031
#include <linux/module.h>
00032
#include <linux/modversions.h>
00033
#include <linux/poll.h>
00034
#include <linux/proc_fs.h>
00035
#include <linux/sched.h>
00036
#include <linux/slab.h>
00037
#include <linux/sound.h>
00038
#include <linux/soundcard.h>
00039
#include <linux/spinlock.h>
00040
#include <linux/timer.h>
00041
#include <linux/tqueue.h>
00042
#include <linux/types.h>
00043
#include <linux/wait.h>
00044
00045
#include <asm/atomic.h>
00046
#include <asm/byteorder.h>
00047
#include <asm/semaphore.h>
00048
#include <asm/uaccess.h>
00049
00050
#include "lisodsp_debug.h"
00051
00052
typedef struct _liso_t liso_t;
00053
00054
00068 #define LISO_MAX_SUBDEV (sizeof(int)<<3)
00069
00076 #define LISO_MAX_CHANNEL (LISO_MAX_SUBDEV-1)
00077
00079 #define LISO_DEF_CHANNEL 8
00080
00082 #define LISO_RD_CHANNEL LISO_MAX_CHANNEL
00083
00085 #define LISO_RD_MASK (1<<LISO_RD_CHANNEL)
00086
00088
#ifndef LISO_DEF_SAMPLING
00089 # define LISO_DEF_SAMPLING 44100
00090
#endif
00091
00093
#ifndef LISO_MAX_SAMPLING
00094 # define LISO_MAX_SAMPLING 48000
00095
#endif
00096
00098
#ifndef LISO_MIN_SAMPLING
00099 # define LISO_MIN_SAMPLING (LISO_MAX_SAMPLING/10)
00100
#endif
00101
00103 #define LISO_DEF_FORMAT_STR "S2WN"
00104
00113 #define LISO_MIXER_FIX 14
00114
00120
00121
00122
00123
00150 typedef void (*
liso_topcm_t)(
int *d,
const void *s,
int n);
00151
00172 typedef void (*
liso_tofmt_t)(
void *d,
const int *s,
const int f,
int n);
00173
00175 typedef char liso_fmt_desc_t[24];
00176
00178 typedef struct {
00179 int format;
00180 int log2;
00181 const char * desc;
00182 liso_topcm_t topcm[2];
00183 liso_tofmt_t tofmt[2];
00184 }
liso_convertor_t;
00185
00196
const liso_convertor_t *
liso_pcmconv_get(
int fmt);
00197
00207
char *
liso_pcmconv_desc(
const liso_convertor_t * convertor,
00208 liso_fmt_desc_t buf,
int sampling,
int stereo);
00209
00214
int liso_pcmconv_get_fmts(
void);
00215
00222
00223
00224
00225
00234 typedef struct {
00235 int bit;
00236 int tgt;
00237 int cnt;
00238 int * buf;
00239 }
liso_frag_t;
00240
00242 typedef struct {
00243 atomic_t cnt;
00244 atomic_t idx;
00245 int msk;
00246 int siz;
00247 liso_frag_t frag[8];
00248 }
liso_frags_t;
00249
00255
void liso_frag_mix(
liso_frag_t *
const d,
const liso_frag_t *
const s);
00256
00264
00265
00266
00267
00282 typedef struct {
00283
00284 liso_t * lisodsp;
00285 int status;
00286 struct semaphore lock;
00287 wait_queue_head_t * sleepyq;
00288 wait_queue_head_t * wakeupq;
00297 int channel;
00298
00306 struct task_struct * owner;
00307
00310
struct {
00311 int ok;
00312 liso_fmt_desc_t desc;
00314 const liso_convertor_t * convertor;
00315
00316
liso_topcm_t topcm;
00317
liso_tofmt_t tofmt;
00319
unsigned int sampling;
00320
int stereo;
00321
int log2pcm;
00322 } fmt;
00323
00326
struct {
00327 int frag_siz;
00328 int log2pcm;
00329 liso_topcm_t topcm;
00330 liso_tofmt_t tofmt;
00331 } cur_frag;
00332
00336
struct {
00337 int format;
00338 int stereo;
00339 unsigned int sampling;
00340 } req_fmt;
00341
00344
struct {
00345 int cnt;
00346 int idx;
00347 void * data;
00348 } buf;
00349
00350 int frag_cnt;
00351 int lost_cnt;
00355 liso_frags_t frags;
00356
00357 }
liso_subdev_t;
00358
00362 #define LISO_DEVICE_USED 0
00363 #define LISO_DEVICE_IDLE 1
00364 #define LISO_DEVICE_DEAD 2
00365 #define LISO_DEVICE_SLEEP 3
00366
00367 #define LISO_DEVICE_ALERT 4
00368
00369
00370 #define LISO_DEVICE_USED_MSK (1<<LISO_DEVICE_USED)
00371 #define LISO_DEVICE_IDLE_MSK (1<<LISO_DEVICE_IDLE)
00372 #define LISO_DEVICE_DEAD_MSK (1<<LISO_DEVICE_DEAD)
00373 #define LISO_DEVICE_UD_MSK (LISO_DEVICE_USED_MSK|LISO_DEVICE_DEAD_MSK)
00374 #define LISO_DEVICE_UID_MSK (LISO_DEVICE_IDLE_MSK|LISO_DEVICE_UD_MSK)
00375
00393
void liso_subdev_preinit(
liso_subdev_t *
const sd,
00394 liso_t *
const lisodsp,
int chn);
00395
00412
int liso_subdev_init(
liso_subdev_t *
const sd);
00413
00435
int liso_subdev_set_format(
liso_subdev_t *
const sd);
00436
00440 inline static void liso_subdev_set_cur_frag(
liso_subdev_t *
const sd)
00441 {
00442 sd->
cur_frag.frag_siz = sd->
frags.
siz;
00443 sd->
cur_frag.log2pcm = sd->
fmt.log2pcm;
00444 sd->
cur_frag.topcm = sd->
fmt.topcm;
00445 sd->
cur_frag.tofmt = sd->
fmt.tofmt;
00446 }
00447
00465
const char *
liso_subdev_status(
const liso_subdev_t *
const sd);
00466
00467
00476 inline static void liso_subdev_asleep(
liso_subdev_t *
const sd)
00477 {
00478 interruptible_sleep_on(sd->
sleepyq);
00479 }
00480
00489 inline static void liso_subdev_wakeup_partner(
liso_subdev_t *
const sd)
00490 {
00491 wake_up_interruptible(sd->
wakeupq);
00492 }
00493
00504 inline static int liso_subdev_has_sleepy_partner(
liso_subdev_t *
const sd)
00505 {
00506
return waitqueue_active(sd->
wakeupq);
00507 }
00508
00509
00520 inline static int liso_subdev_is_reader(
const liso_subdev_t *
const sd)
00521 {
00522
return (sd->
channel ==
LISO_RD_CHANNEL);
00523 }
00524
00535 inline static int liso_subdev_is_writer(
const liso_subdev_t *
const sd)
00536 {
00537
return !
liso_subdev_is_reader(sd);
00538 }
00539
00550 inline static int liso_subdev_is_active(
const liso_subdev_t *
const sd)
00551 {
00552
return (sd->
status &
LISO_DEVICE_UID_MSK) ==
LISO_DEVICE_USED_MSK;
00553 }
00554
00565 inline static int liso_subdev_is_valid(
const liso_subdev_t *
const sd)
00566 {
00567
return (sd->
status &
LISO_DEVICE_UD_MSK) ==
LISO_DEVICE_USED_MSK;
00568 }
00569
00588 inline static int liso_subdev_lock(
liso_subdev_t * sd)
00589 {
00590
return down_interruptible(&sd->
lock);
00591 }
00592
00603 inline static int liso_subdev_trylock(
liso_subdev_t * sd)
00604 {
00605
return down_trylock(&sd->
lock);
00606 }
00607
00629 inline static int liso_subdev_xlock(
liso_subdev_t * sd,
const int nonblock)
00630 {
00631
return !nonblock
00632 ? (!
liso_subdev_lock(sd) ? 0 : -ERESTARTSYS)
00633 : (!
liso_subdev_trylock(sd) ? 0 : -EAGAIN);
00634 }
00635
00644 inline static void liso_subdev_unlock(
liso_subdev_t * sd)
00645 {
00646 up(&sd->
lock);
00647 }
00648
00668
int liso_writer_open(
struct inode * inode,
struct file * filp);
00669
00682
int liso_reader_open(
struct inode * inode,
struct file * filp);
00683
00692
int liso_subdev_release(
struct inode * inode,
struct file * filp);
00693
00707
int liso_subdev_ioctl(
struct inode *inode,
struct file *filp,
00708
unsigned int cmd,
unsigned long arg);
00709
00718
unsigned int liso_subdevice_poll(
struct file *filp, poll_table *wait);
00719
00743
int liso_subdev_wait_idx(
liso_subdev_t *
const sd,
const int idx);
00744
00763
int liso_subdev_synchronize(
liso_subdev_t *
const sd,
const int lock);
00764
00778
void liso_writer_synchronize(
liso_subdev_t *
const writer);
00779
00792
void liso_reader_synchronize(
liso_subdev_t *
const reader);
00793
00812
int liso_writer_flush(
liso_subdev_t *
const writer);
00813
00821
00822
00823
00824
00834 struct _liso_t {
00835 liso_t *
magic;
00836 volatile int unload;
00837 volatile int fake_reader;
00838 struct proc_dir_entry *
proc;
00840 liso_fmt_desc_t def_desc;
00841 int def_sampling;
00842 int def_stereo;
00843 const liso_convertor_t *
def_convertor;
00844 int def_format;
00845 int min_sampling;
00846 int max_sampling;
00847 int max_frag_size;
00848 unsigned int frag_us;
00849 atomic_t
output_delay_us;
00851 unsigned int timer_offset;
00852 int dev_unit;
00853 struct semaphore w_open_sem;
00854 struct semaphore r_open_sem;
00856 int max_writers;
00857 int idleness_threshold;
00859 volatile int active_devices;
00865 liso_subdev_t subdev[
LISO_MAX_SUBDEV-1];
00866
00871 liso_subdev_t reader;
00872
00873 wait_queue_head_t
wr_waitq;
00874 wait_queue_head_t
rd_waitq;
00879
struct {
00880 int disabled;
00881 struct timer_list list;
00882 struct tq_struct task;
00883 wait_queue_head_t * wait;
00884 volatile unsigned cnt;
00885 unsigned int offset;
00886 } timer;
00887 };
00888
00889
00895
int liso_device_init(liso_t * lisodsp);
00896
00898
int liso_device_shutdown(liso_t * lisodsp);
00899
00911 extern liso_t
g_lisodsp;
00912
00929 extern int liso_volume[];
00930
00941
int liso_device_update_active(liso_t *
const lisodsp);
00942
00952 inline static int liso_device_active_writers(
const liso_t *
const lisodsp)
00953 {
00954
return lisodsp->
active_devices & ~(1 <<
LISO_RD_CHANNEL);
00955 }
00956
00969 inline static void liso_wakeup_writers(liso_t * lisodsp)
00970 {
00971 wake_up_interruptible(&lisodsp->
wr_waitq);
00972 }
00973
00982 inline static void liso_wakeup_reader(liso_t * lisodsp)
00983 {
00984 wake_up_interruptible(&lisodsp->
rd_waitq);
00985 }
00986
01021
int liso_timer_start(liso_t * lisodsp,
01022
unsigned int offset,
void (*task)(
void *));
01023
01033
int liso_timer_stop(liso_t * lisodsp);
01034
01045
01046
01054
01055
01056
01057
01077
int liso_proc_init(liso_t * lisodsp);
01078
01085
int liso_proc_shutdown(liso_t * lisodsp);
01086
01094
#endif