blob: 1e123077923d79edc59a98524c00e0516bd91b98 [file] [log] [blame]
Stas Sergeev9ab4d072008-03-03 10:53:54 +01001/*
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>
Arnd Bergmann08604bd2009-06-16 15:31:12 -070013#include <linux/timex.h>
Stas Sergeev9ab4d072008-03-03 10:53:54 +010014#if defined(CONFIG_MIPS) || defined(CONFIG_X86)
15/* Use the global PIT lock ! */
16#include <asm/i8253.h>
17#else
18#include <asm/8253pit.h>
19static DEFINE_SPINLOCK(i8253_lock);
20#endif
21
22#define PCSP_SOUND_VERSION 0x400 /* read 4.00 */
23#define PCSP_DEBUG 0
24
25/* default timer freq for PC-Speaker: 18643 Hz */
26#define DIV_18KHZ 64
27#define MAX_DIV DIV_18KHZ
Stas Sergeev97e08f52008-05-24 18:05:47 +020028#define CALC_DIV(d) (MAX_DIV >> (d))
29#define CUR_DIV() CALC_DIV(chip->treble)
Stas Sergeev9ab4d072008-03-03 10:53:54 +010030#define PCSP_MAX_TREBLE 1
31
32/* unfortunately, with hrtimers 37KHz does not work very well :( */
33#define PCSP_DEFAULT_TREBLE 0
34#define MIN_DIV (MAX_DIV >> PCSP_MAX_TREBLE)
35
36/* wild guess */
37#define PCSP_MIN_LPJ 1000000
38#define PCSP_DEFAULT_SDIV (DIV_18KHZ >> 1)
39#define PCSP_DEFAULT_SRATE (PIT_TICK_RATE / PCSP_DEFAULT_SDIV)
40#define PCSP_INDEX_INC() (1 << (PCSP_MAX_TREBLE - chip->treble))
Stas Sergeev97e08f52008-05-24 18:05:47 +020041#define PCSP_CALC_RATE(i) (PIT_TICK_RATE / CALC_DIV(i))
42#define PCSP_RATE() PCSP_CALC_RATE(chip->treble)
Stas Sergeev9ab4d072008-03-03 10:53:54 +010043#define PCSP_MIN_RATE__1 MAX_DIV/PIT_TICK_RATE
44#define PCSP_MAX_RATE__1 MIN_DIV/PIT_TICK_RATE
45#define PCSP_MAX_PERIOD_NS (1000000000ULL * PCSP_MIN_RATE__1)
46#define PCSP_MIN_PERIOD_NS (1000000000ULL * PCSP_MAX_RATE__1)
47#define PCSP_CALC_NS(div) ({ \
48 u64 __val = 1000000000ULL * (div); \
49 do_div(__val, PIT_TICK_RATE); \
50 __val; \
51})
52#define PCSP_PERIOD_NS() PCSP_CALC_NS(CUR_DIV())
53
54#define PCSP_MAX_PERIOD_SIZE (64*1024)
55#define PCSP_MAX_PERIODS 512
56#define PCSP_BUFFER_SIZE (128*1024)
57
58struct snd_pcsp {
59 struct snd_card *card;
60 struct snd_pcm *pcm;
61 struct input_dev *input_dev;
62 struct hrtimer timer;
63 unsigned short port, irq, dma;
64 spinlock_t substream_lock;
65 struct snd_pcm_substream *playback_substream;
Takashi Iwaieea05792008-11-26 14:13:03 +010066 unsigned int fmt_size;
67 unsigned int is_signed;
Stas Sergeev9ab4d072008-03-03 10:53:54 +010068 size_t playback_ptr;
69 size_t period_ptr;
70 atomic_t timer_active;
71 int thalf;
72 u64 ns_rem;
73 unsigned char val61;
74 int enable;
75 int max_treble;
76 int treble;
77 int pcspkr;
78};
79
80extern struct snd_pcsp pcsp_chip;
81
82extern enum hrtimer_restart pcsp_do_timer(struct hrtimer *handle);
Takashi Iwai96c7d472008-08-11 10:18:39 +020083extern void pcsp_sync_stop(struct snd_pcsp *chip);
Stas Sergeev9ab4d072008-03-03 10:53:54 +010084
85extern int snd_pcsp_new_pcm(struct snd_pcsp *chip);
Stas Sergeevbcc2c6b2009-11-01 11:13:19 +010086extern int snd_pcsp_new_mixer(struct snd_pcsp *chip, int nopcm);
Stas Sergeev9ab4d072008-03-03 10:53:54 +010087
88#endif