| Stas Sergeev | 9ab4d07 | 2008-03-03 10:53:54 +0100 | [diff] [blame] | 1 | /* | 
|  | 2 | * PC-Speaker driver for Linux | 
|  | 3 | * | 
|  | 4 | * Copyright (C) 1993-1997  Michael Beck | 
|  | 5 | * Copyright (C) 1997-2001  David Woodhouse | 
|  | 6 | * Copyright (C) 2001-2008  Stas Sergeev | 
|  | 7 | */ | 
|  | 8 |  | 
|  | 9 | #ifndef __PCSP_H__ | 
|  | 10 | #define __PCSP_H__ | 
|  | 11 |  | 
|  | 12 | #include <linux/hrtimer.h> | 
|  | 13 | #if defined(CONFIG_MIPS) || defined(CONFIG_X86) | 
|  | 14 | /* Use the global PIT lock ! */ | 
|  | 15 | #include <asm/i8253.h> | 
|  | 16 | #else | 
|  | 17 | #include <asm/8253pit.h> | 
|  | 18 | static DEFINE_SPINLOCK(i8253_lock); | 
|  | 19 | #endif | 
|  | 20 |  | 
|  | 21 | #define PCSP_SOUND_VERSION 0x400	/* read 4.00 */ | 
|  | 22 | #define PCSP_DEBUG 0 | 
|  | 23 |  | 
|  | 24 | /* default timer freq for PC-Speaker: 18643 Hz */ | 
|  | 25 | #define DIV_18KHZ 64 | 
|  | 26 | #define MAX_DIV DIV_18KHZ | 
| Stas Sergeev | 97e08f5 | 2008-05-24 18:05:47 +0200 | [diff] [blame] | 27 | #define CALC_DIV(d) (MAX_DIV >> (d)) | 
|  | 28 | #define CUR_DIV() CALC_DIV(chip->treble) | 
| Stas Sergeev | 9ab4d07 | 2008-03-03 10:53:54 +0100 | [diff] [blame] | 29 | #define PCSP_MAX_TREBLE 1 | 
|  | 30 |  | 
|  | 31 | /* unfortunately, with hrtimers 37KHz does not work very well :( */ | 
|  | 32 | #define PCSP_DEFAULT_TREBLE 0 | 
|  | 33 | #define MIN_DIV (MAX_DIV >> PCSP_MAX_TREBLE) | 
|  | 34 |  | 
|  | 35 | /* wild guess */ | 
|  | 36 | #define PCSP_MIN_LPJ 1000000 | 
|  | 37 | #define PCSP_DEFAULT_SDIV (DIV_18KHZ >> 1) | 
|  | 38 | #define PCSP_DEFAULT_SRATE (PIT_TICK_RATE / PCSP_DEFAULT_SDIV) | 
|  | 39 | #define PCSP_INDEX_INC() (1 << (PCSP_MAX_TREBLE - chip->treble)) | 
| Stas Sergeev | 97e08f5 | 2008-05-24 18:05:47 +0200 | [diff] [blame] | 40 | #define PCSP_CALC_RATE(i) (PIT_TICK_RATE / CALC_DIV(i)) | 
|  | 41 | #define PCSP_RATE() PCSP_CALC_RATE(chip->treble) | 
| Stas Sergeev | 9ab4d07 | 2008-03-03 10:53:54 +0100 | [diff] [blame] | 42 | #define PCSP_MIN_RATE__1 MAX_DIV/PIT_TICK_RATE | 
|  | 43 | #define PCSP_MAX_RATE__1 MIN_DIV/PIT_TICK_RATE | 
|  | 44 | #define PCSP_MAX_PERIOD_NS (1000000000ULL * PCSP_MIN_RATE__1) | 
|  | 45 | #define PCSP_MIN_PERIOD_NS (1000000000ULL * PCSP_MAX_RATE__1) | 
|  | 46 | #define PCSP_CALC_NS(div) ({ \ | 
|  | 47 | u64 __val = 1000000000ULL * (div); \ | 
|  | 48 | do_div(__val, PIT_TICK_RATE); \ | 
|  | 49 | __val; \ | 
|  | 50 | }) | 
|  | 51 | #define PCSP_PERIOD_NS() PCSP_CALC_NS(CUR_DIV()) | 
|  | 52 |  | 
|  | 53 | #define PCSP_MAX_PERIOD_SIZE	(64*1024) | 
|  | 54 | #define PCSP_MAX_PERIODS	512 | 
|  | 55 | #define PCSP_BUFFER_SIZE	(128*1024) | 
|  | 56 |  | 
|  | 57 | struct snd_pcsp { | 
|  | 58 | struct snd_card *card; | 
|  | 59 | struct snd_pcm *pcm; | 
|  | 60 | struct input_dev *input_dev; | 
|  | 61 | struct hrtimer timer; | 
|  | 62 | unsigned short port, irq, dma; | 
|  | 63 | spinlock_t substream_lock; | 
|  | 64 | struct snd_pcm_substream *playback_substream; | 
|  | 65 | size_t playback_ptr; | 
|  | 66 | size_t period_ptr; | 
|  | 67 | atomic_t timer_active; | 
|  | 68 | int thalf; | 
|  | 69 | u64 ns_rem; | 
|  | 70 | unsigned char val61; | 
|  | 71 | int enable; | 
|  | 72 | int max_treble; | 
|  | 73 | int treble; | 
|  | 74 | int pcspkr; | 
|  | 75 | }; | 
|  | 76 |  | 
|  | 77 | extern struct snd_pcsp pcsp_chip; | 
|  | 78 |  | 
|  | 79 | extern enum hrtimer_restart pcsp_do_timer(struct hrtimer *handle); | 
|  | 80 |  | 
|  | 81 | extern int snd_pcsp_new_pcm(struct snd_pcsp *chip); | 
|  | 82 | extern int snd_pcsp_new_mixer(struct snd_pcsp *chip); | 
|  | 83 |  | 
|  | 84 | #endif |