cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

radio-rtrack2.c (3492B)


      1// SPDX-License-Identifier: GPL-2.0-only
      2/*
      3 * RadioTrack II driver
      4 * Copyright 1998 Ben Pfaff
      5 *
      6 * Based on RadioTrack I/RadioReveal (C) 1997 M. Kirkwood
      7 * Converted to new API by Alan Cox <alan@lxorguk.ukuu.org.uk>
      8 * Various bugfixes and enhancements by Russell Kroll <rkroll@exploits.org>
      9 *
     10 * Converted to the radio-isa framework by Hans Verkuil <hans.verkuil@cisco.com>
     11 * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@kernel.org>
     12 *
     13 * Fully tested with actual hardware and the v4l2-compliance tool.
     14 */
     15
     16#include <linux/module.h>	/* Modules			*/
     17#include <linux/init.h>		/* Initdata			*/
     18#include <linux/ioport.h>	/* request_region		*/
     19#include <linux/delay.h>	/* udelay			*/
     20#include <linux/videodev2.h>	/* kernel radio structs		*/
     21#include <linux/mutex.h>
     22#include <linux/io.h>		/* outb, outb_p			*/
     23#include <linux/slab.h>
     24#include <media/v4l2-device.h>
     25#include <media/v4l2-ioctl.h>
     26#include "radio-isa.h"
     27
     28MODULE_AUTHOR("Ben Pfaff");
     29MODULE_DESCRIPTION("A driver for the RadioTrack II radio card.");
     30MODULE_LICENSE("GPL");
     31MODULE_VERSION("0.1.99");
     32
     33#ifndef CONFIG_RADIO_RTRACK2_PORT
     34#define CONFIG_RADIO_RTRACK2_PORT -1
     35#endif
     36
     37#define RTRACK2_MAX 2
     38
     39static int io[RTRACK2_MAX] = { [0] = CONFIG_RADIO_RTRACK2_PORT,
     40			      [1 ... (RTRACK2_MAX - 1)] = -1 };
     41static int radio_nr[RTRACK2_MAX] = { [0 ... (RTRACK2_MAX - 1)] = -1 };
     42
     43module_param_array(io, int, NULL, 0444);
     44MODULE_PARM_DESC(io, "I/O addresses of the RadioTrack card (0x20f or 0x30f)");
     45module_param_array(radio_nr, int, NULL, 0444);
     46MODULE_PARM_DESC(radio_nr, "Radio device numbers");
     47
     48static struct radio_isa_card *rtrack2_alloc(void)
     49{
     50	return kzalloc(sizeof(struct radio_isa_card), GFP_KERNEL);
     51}
     52
     53static void zero(struct radio_isa_card *isa)
     54{
     55	outb_p(1, isa->io);
     56	outb_p(3, isa->io);
     57	outb_p(1, isa->io);
     58}
     59
     60static void one(struct radio_isa_card *isa)
     61{
     62	outb_p(5, isa->io);
     63	outb_p(7, isa->io);
     64	outb_p(5, isa->io);
     65}
     66
     67static int rtrack2_s_frequency(struct radio_isa_card *isa, u32 freq)
     68{
     69	int i;
     70
     71	freq = freq / 200 + 856;
     72
     73	outb_p(0xc8, isa->io);
     74	outb_p(0xc9, isa->io);
     75	outb_p(0xc9, isa->io);
     76
     77	for (i = 0; i < 10; i++)
     78		zero(isa);
     79
     80	for (i = 14; i >= 0; i--)
     81		if (freq & (1 << i))
     82			one(isa);
     83		else
     84			zero(isa);
     85
     86	outb_p(0xc8, isa->io);
     87	outb_p(v4l2_ctrl_g_ctrl(isa->mute), isa->io);
     88	return 0;
     89}
     90
     91static u32 rtrack2_g_signal(struct radio_isa_card *isa)
     92{
     93	/* bit set = no signal present	*/
     94	return (inb(isa->io) & 2) ? 0 : 0xffff;
     95}
     96
     97static int rtrack2_s_mute_volume(struct radio_isa_card *isa, bool mute, int vol)
     98{
     99	outb(mute, isa->io);
    100	return 0;
    101}
    102
    103static const struct radio_isa_ops rtrack2_ops = {
    104	.alloc = rtrack2_alloc,
    105	.s_mute_volume = rtrack2_s_mute_volume,
    106	.s_frequency = rtrack2_s_frequency,
    107	.g_signal = rtrack2_g_signal,
    108};
    109
    110static const int rtrack2_ioports[] = { 0x20f, 0x30f };
    111
    112static struct radio_isa_driver rtrack2_driver = {
    113	.driver = {
    114		.match		= radio_isa_match,
    115		.probe		= radio_isa_probe,
    116		.remove		= radio_isa_remove,
    117		.driver		= {
    118			.name	= "radio-rtrack2",
    119		},
    120	},
    121	.io_params = io,
    122	.radio_nr_params = radio_nr,
    123	.io_ports = rtrack2_ioports,
    124	.num_of_io_ports = ARRAY_SIZE(rtrack2_ioports),
    125	.region_size = 4,
    126	.card = "AIMSlab RadioTrack II",
    127	.ops = &rtrack2_ops,
    128	.has_stereo = true,
    129};
    130
    131static int __init rtrack2_init(void)
    132{
    133	return isa_register_driver(&rtrack2_driver.driver, RTRACK2_MAX);
    134}
    135
    136static void __exit rtrack2_exit(void)
    137{
    138	isa_unregister_driver(&rtrack2_driver.driver);
    139}
    140
    141module_init(rtrack2_init);
    142module_exit(rtrack2_exit);