Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * PC-Speaker driver for Linux
0004  *
0005  * Copyright (C) 1993-1997  Michael Beck
0006  * Copyright (C) 1997-2001  David Woodhouse
0007  * Copyright (C) 2001-2008  Stas Sergeev
0008  */
0009 
0010 #ifndef __PCSP_H__
0011 #define __PCSP_H__
0012 
0013 #include <linux/hrtimer.h>
0014 #include <linux/i8253.h>
0015 #include <linux/timex.h>
0016 
0017 #define PCSP_SOUND_VERSION 0x400    /* read 4.00 */
0018 #define PCSP_DEBUG 0
0019 
0020 /* default timer freq for PC-Speaker: 18643 Hz */
0021 #define DIV_18KHZ 64
0022 #define MAX_DIV DIV_18KHZ
0023 #define CALC_DIV(d) (MAX_DIV >> (d))
0024 #define CUR_DIV() CALC_DIV(chip->treble)
0025 #define PCSP_MAX_TREBLE 1
0026 
0027 /* unfortunately, with hrtimers 37KHz does not work very well :( */
0028 #define PCSP_DEFAULT_TREBLE 0
0029 #define MIN_DIV (MAX_DIV >> PCSP_MAX_TREBLE)
0030 
0031 /* wild guess */
0032 #define PCSP_MIN_LPJ 1000000
0033 #define PCSP_DEFAULT_SDIV (DIV_18KHZ >> 1)
0034 #define PCSP_DEFAULT_SRATE (PIT_TICK_RATE / PCSP_DEFAULT_SDIV)
0035 #define PCSP_INDEX_INC() (1 << (PCSP_MAX_TREBLE - chip->treble))
0036 #define PCSP_CALC_RATE(i) (PIT_TICK_RATE / CALC_DIV(i))
0037 #define PCSP_RATE() PCSP_CALC_RATE(chip->treble)
0038 #define PCSP_MIN_RATE__1 MAX_DIV/PIT_TICK_RATE
0039 #define PCSP_MAX_RATE__1 MIN_DIV/PIT_TICK_RATE
0040 #define PCSP_MAX_PERIOD_NS (1000000000ULL * PCSP_MIN_RATE__1)
0041 #define PCSP_MIN_PERIOD_NS (1000000000ULL * PCSP_MAX_RATE__1)
0042 #define PCSP_CALC_NS(div) ({ \
0043     u64 __val = 1000000000ULL * (div); \
0044     do_div(__val, PIT_TICK_RATE); \
0045     __val; \
0046 })
0047 #define PCSP_PERIOD_NS() PCSP_CALC_NS(CUR_DIV())
0048 
0049 #define PCSP_MAX_PERIOD_SIZE    (64*1024)
0050 #define PCSP_MAX_PERIODS    512
0051 #define PCSP_BUFFER_SIZE    (128*1024)
0052 
0053 struct snd_pcsp {
0054     struct snd_card *card;
0055     struct snd_pcm *pcm;
0056     struct input_dev *input_dev;
0057     struct hrtimer timer;
0058     unsigned short port, irq, dma;
0059     spinlock_t substream_lock;
0060     struct snd_pcm_substream *playback_substream;
0061     unsigned int fmt_size;
0062     unsigned int is_signed;
0063     size_t playback_ptr;
0064     size_t period_ptr;
0065     atomic_t timer_active;
0066     int thalf;
0067     u64 ns_rem;
0068     unsigned char val61;
0069     int enable;
0070     int max_treble;
0071     int treble;
0072     int pcspkr;
0073 };
0074 
0075 extern struct snd_pcsp pcsp_chip;
0076 
0077 extern enum hrtimer_restart pcsp_do_timer(struct hrtimer *handle);
0078 extern void pcsp_sync_stop(struct snd_pcsp *chip);
0079 
0080 extern int snd_pcsp_new_pcm(struct snd_pcsp *chip);
0081 extern int snd_pcsp_new_mixer(struct snd_pcsp *chip, int nopcm);
0082 
0083 #endif