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> |
Ralf Baechle | 334955e | 2011-06-01 19:04:57 +0100 | [diff] [blame] | 13 | #include <linux/i8253.h> |
Ralf Baechle | 8e1b5ad | 2011-06-01 19:05:03 +0100 | [diff] [blame] | 14 | #include <linux/timex.h> |
Stas Sergeev | 9ab4d07 | 2008-03-03 10:53:54 +0100 | [diff] [blame] | 15 | |
| 16 | #define PCSP_SOUND_VERSION 0x400 /* read 4.00 */ |
| 17 | #define PCSP_DEBUG 0 |
| 18 | |
| 19 | /* default timer freq for PC-Speaker: 18643 Hz */ |
| 20 | #define DIV_18KHZ 64 |
| 21 | #define MAX_DIV DIV_18KHZ |
Stas Sergeev | 97e08f5 | 2008-05-24 18:05:47 +0200 | [diff] [blame] | 22 | #define CALC_DIV(d) (MAX_DIV >> (d)) |
| 23 | #define CUR_DIV() CALC_DIV(chip->treble) |
Stas Sergeev | 9ab4d07 | 2008-03-03 10:53:54 +0100 | [diff] [blame] | 24 | #define PCSP_MAX_TREBLE 1 |
| 25 | |
| 26 | /* unfortunately, with hrtimers 37KHz does not work very well :( */ |
| 27 | #define PCSP_DEFAULT_TREBLE 0 |
| 28 | #define MIN_DIV (MAX_DIV >> PCSP_MAX_TREBLE) |
| 29 | |
| 30 | /* wild guess */ |
| 31 | #define PCSP_MIN_LPJ 1000000 |
| 32 | #define PCSP_DEFAULT_SDIV (DIV_18KHZ >> 1) |
| 33 | #define PCSP_DEFAULT_SRATE (PIT_TICK_RATE / PCSP_DEFAULT_SDIV) |
| 34 | #define PCSP_INDEX_INC() (1 << (PCSP_MAX_TREBLE - chip->treble)) |
Stas Sergeev | 97e08f5 | 2008-05-24 18:05:47 +0200 | [diff] [blame] | 35 | #define PCSP_CALC_RATE(i) (PIT_TICK_RATE / CALC_DIV(i)) |
| 36 | #define PCSP_RATE() PCSP_CALC_RATE(chip->treble) |
Stas Sergeev | 9ab4d07 | 2008-03-03 10:53:54 +0100 | [diff] [blame] | 37 | #define PCSP_MIN_RATE__1 MAX_DIV/PIT_TICK_RATE |
| 38 | #define PCSP_MAX_RATE__1 MIN_DIV/PIT_TICK_RATE |
| 39 | #define PCSP_MAX_PERIOD_NS (1000000000ULL * PCSP_MIN_RATE__1) |
| 40 | #define PCSP_MIN_PERIOD_NS (1000000000ULL * PCSP_MAX_RATE__1) |
| 41 | #define PCSP_CALC_NS(div) ({ \ |
| 42 | u64 __val = 1000000000ULL * (div); \ |
| 43 | do_div(__val, PIT_TICK_RATE); \ |
| 44 | __val; \ |
| 45 | }) |
| 46 | #define PCSP_PERIOD_NS() PCSP_CALC_NS(CUR_DIV()) |
| 47 | |
| 48 | #define PCSP_MAX_PERIOD_SIZE (64*1024) |
| 49 | #define PCSP_MAX_PERIODS 512 |
| 50 | #define PCSP_BUFFER_SIZE (128*1024) |
| 51 | |
| 52 | struct snd_pcsp { |
| 53 | struct snd_card *card; |
| 54 | struct snd_pcm *pcm; |
| 55 | struct input_dev *input_dev; |
| 56 | struct hrtimer timer; |
| 57 | unsigned short port, irq, dma; |
| 58 | spinlock_t substream_lock; |
| 59 | struct snd_pcm_substream *playback_substream; |
Takashi Iwai | eea0579 | 2008-11-26 14:13:03 +0100 | [diff] [blame] | 60 | unsigned int fmt_size; |
| 61 | unsigned int is_signed; |
Stas Sergeev | 9ab4d07 | 2008-03-03 10:53:54 +0100 | [diff] [blame] | 62 | size_t playback_ptr; |
| 63 | size_t period_ptr; |
| 64 | atomic_t timer_active; |
| 65 | int thalf; |
| 66 | u64 ns_rem; |
| 67 | unsigned char val61; |
| 68 | int enable; |
| 69 | int max_treble; |
| 70 | int treble; |
| 71 | int pcspkr; |
| 72 | }; |
| 73 | |
| 74 | extern struct snd_pcsp pcsp_chip; |
| 75 | |
| 76 | extern enum hrtimer_restart pcsp_do_timer(struct hrtimer *handle); |
Takashi Iwai | 96c7d47 | 2008-08-11 10:18:39 +0200 | [diff] [blame] | 77 | extern void pcsp_sync_stop(struct snd_pcsp *chip); |
Stas Sergeev | 9ab4d07 | 2008-03-03 10:53:54 +0100 | [diff] [blame] | 78 | |
| 79 | extern int snd_pcsp_new_pcm(struct snd_pcsp *chip); |
Stas Sergeev | bcc2c6b | 2009-11-01 11:13:19 +0100 | [diff] [blame] | 80 | extern int snd_pcsp_new_mixer(struct snd_pcsp *chip, int nopcm); |
Stas Sergeev | 9ab4d07 | 2008-03-03 10:53:54 +0100 | [diff] [blame] | 81 | |
| 82 | #endif |