1*b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 29ab4d072SStas Sergeev /* 39ab4d072SStas Sergeev * PC-Speaker driver for Linux 49ab4d072SStas Sergeev * 59ab4d072SStas Sergeev * Copyright (C) 1993-1997 Michael Beck 69ab4d072SStas Sergeev * Copyright (C) 1997-2001 David Woodhouse 79ab4d072SStas Sergeev * Copyright (C) 2001-2008 Stas Sergeev 89ab4d072SStas Sergeev */ 99ab4d072SStas Sergeev 109ab4d072SStas Sergeev #ifndef __PCSP_H__ 119ab4d072SStas Sergeev #define __PCSP_H__ 129ab4d072SStas Sergeev 139ab4d072SStas Sergeev #include <linux/hrtimer.h> 14334955efSRalf Baechle #include <linux/i8253.h> 158e1b5adfSRalf Baechle #include <linux/timex.h> 169ab4d072SStas Sergeev 179ab4d072SStas Sergeev #define PCSP_SOUND_VERSION 0x400 /* read 4.00 */ 189ab4d072SStas Sergeev #define PCSP_DEBUG 0 199ab4d072SStas Sergeev 209ab4d072SStas Sergeev /* default timer freq for PC-Speaker: 18643 Hz */ 219ab4d072SStas Sergeev #define DIV_18KHZ 64 229ab4d072SStas Sergeev #define MAX_DIV DIV_18KHZ 2397e08f5dSStas Sergeev #define CALC_DIV(d) (MAX_DIV >> (d)) 2497e08f5dSStas Sergeev #define CUR_DIV() CALC_DIV(chip->treble) 259ab4d072SStas Sergeev #define PCSP_MAX_TREBLE 1 269ab4d072SStas Sergeev 279ab4d072SStas Sergeev /* unfortunately, with hrtimers 37KHz does not work very well :( */ 289ab4d072SStas Sergeev #define PCSP_DEFAULT_TREBLE 0 299ab4d072SStas Sergeev #define MIN_DIV (MAX_DIV >> PCSP_MAX_TREBLE) 309ab4d072SStas Sergeev 319ab4d072SStas Sergeev /* wild guess */ 329ab4d072SStas Sergeev #define PCSP_MIN_LPJ 1000000 339ab4d072SStas Sergeev #define PCSP_DEFAULT_SDIV (DIV_18KHZ >> 1) 349ab4d072SStas Sergeev #define PCSP_DEFAULT_SRATE (PIT_TICK_RATE / PCSP_DEFAULT_SDIV) 359ab4d072SStas Sergeev #define PCSP_INDEX_INC() (1 << (PCSP_MAX_TREBLE - chip->treble)) 3697e08f5dSStas Sergeev #define PCSP_CALC_RATE(i) (PIT_TICK_RATE / CALC_DIV(i)) 3797e08f5dSStas Sergeev #define PCSP_RATE() PCSP_CALC_RATE(chip->treble) 389ab4d072SStas Sergeev #define PCSP_MIN_RATE__1 MAX_DIV/PIT_TICK_RATE 399ab4d072SStas Sergeev #define PCSP_MAX_RATE__1 MIN_DIV/PIT_TICK_RATE 409ab4d072SStas Sergeev #define PCSP_MAX_PERIOD_NS (1000000000ULL * PCSP_MIN_RATE__1) 419ab4d072SStas Sergeev #define PCSP_MIN_PERIOD_NS (1000000000ULL * PCSP_MAX_RATE__1) 429ab4d072SStas Sergeev #define PCSP_CALC_NS(div) ({ \ 439ab4d072SStas Sergeev u64 __val = 1000000000ULL * (div); \ 449ab4d072SStas Sergeev do_div(__val, PIT_TICK_RATE); \ 459ab4d072SStas Sergeev __val; \ 469ab4d072SStas Sergeev }) 479ab4d072SStas Sergeev #define PCSP_PERIOD_NS() PCSP_CALC_NS(CUR_DIV()) 489ab4d072SStas Sergeev 499ab4d072SStas Sergeev #define PCSP_MAX_PERIOD_SIZE (64*1024) 509ab4d072SStas Sergeev #define PCSP_MAX_PERIODS 512 519ab4d072SStas Sergeev #define PCSP_BUFFER_SIZE (128*1024) 529ab4d072SStas Sergeev 539ab4d072SStas Sergeev struct snd_pcsp { 549ab4d072SStas Sergeev struct snd_card *card; 559ab4d072SStas Sergeev struct snd_pcm *pcm; 569ab4d072SStas Sergeev struct input_dev *input_dev; 579ab4d072SStas Sergeev struct hrtimer timer; 589ab4d072SStas Sergeev unsigned short port, irq, dma; 599ab4d072SStas Sergeev spinlock_t substream_lock; 609ab4d072SStas Sergeev struct snd_pcm_substream *playback_substream; 61eea0579fSTakashi Iwai unsigned int fmt_size; 62eea0579fSTakashi Iwai unsigned int is_signed; 639ab4d072SStas Sergeev size_t playback_ptr; 649ab4d072SStas Sergeev size_t period_ptr; 659ab4d072SStas Sergeev atomic_t timer_active; 669ab4d072SStas Sergeev int thalf; 679ab4d072SStas Sergeev u64 ns_rem; 689ab4d072SStas Sergeev unsigned char val61; 699ab4d072SStas Sergeev int enable; 709ab4d072SStas Sergeev int max_treble; 719ab4d072SStas Sergeev int treble; 729ab4d072SStas Sergeev int pcspkr; 739ab4d072SStas Sergeev }; 749ab4d072SStas Sergeev 759ab4d072SStas Sergeev extern struct snd_pcsp pcsp_chip; 769ab4d072SStas Sergeev 779ab4d072SStas Sergeev extern enum hrtimer_restart pcsp_do_timer(struct hrtimer *handle); 7896c7d478STakashi Iwai extern void pcsp_sync_stop(struct snd_pcsp *chip); 799ab4d072SStas Sergeev 809ab4d072SStas Sergeev extern int snd_pcsp_new_pcm(struct snd_pcsp *chip); 81bcc2c6b7SStas Sergeev extern int snd_pcsp_new_mixer(struct snd_pcsp *chip, int nopcm); 829ab4d072SStas Sergeev 839ab4d072SStas Sergeev #endif 84