18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * radio-aztech.c - Aztech radio card driver 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Converted to the radio-isa framework by Hans Verkuil <hans.verkuil@xs4all.nl> 68c2ecf20Sopenharmony_ci * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@kernel.org> 78c2ecf20Sopenharmony_ci * Adapted to support the Video for Linux API by 88c2ecf20Sopenharmony_ci * Russell Kroll <rkroll@exploits.org>. Based on original tuner code by: 98c2ecf20Sopenharmony_ci * 108c2ecf20Sopenharmony_ci * Quay Ly 118c2ecf20Sopenharmony_ci * Donald Song 128c2ecf20Sopenharmony_ci * Jason Lewis (jlewis@twilight.vtc.vsc.edu) 138c2ecf20Sopenharmony_ci * Scott McGrath (smcgrath@twilight.vtc.vsc.edu) 148c2ecf20Sopenharmony_ci * William McGrath (wmcgrath@twilight.vtc.vsc.edu) 158c2ecf20Sopenharmony_ci * 168c2ecf20Sopenharmony_ci * Fully tested with the Keene USB FM Transmitter and the v4l2-compliance tool. 178c2ecf20Sopenharmony_ci*/ 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci#include <linux/module.h> /* Modules */ 208c2ecf20Sopenharmony_ci#include <linux/init.h> /* Initdata */ 218c2ecf20Sopenharmony_ci#include <linux/ioport.h> /* request_region */ 228c2ecf20Sopenharmony_ci#include <linux/delay.h> /* udelay */ 238c2ecf20Sopenharmony_ci#include <linux/videodev2.h> /* kernel radio structs */ 248c2ecf20Sopenharmony_ci#include <linux/io.h> /* outb, outb_p */ 258c2ecf20Sopenharmony_ci#include <linux/slab.h> 268c2ecf20Sopenharmony_ci#include <media/v4l2-device.h> 278c2ecf20Sopenharmony_ci#include <media/v4l2-ioctl.h> 288c2ecf20Sopenharmony_ci#include <media/v4l2-ctrls.h> 298c2ecf20Sopenharmony_ci#include "radio-isa.h" 308c2ecf20Sopenharmony_ci#include "lm7000.h" 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ciMODULE_AUTHOR("Russell Kroll, Quay Lu, Donald Song, Jason Lewis, Scott McGrath, William McGrath"); 338c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("A driver for the Aztech radio card."); 348c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL"); 358c2ecf20Sopenharmony_ciMODULE_VERSION("1.0.0"); 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci/* acceptable ports: 0x350 (JP3 shorted), 0x358 (JP3 open) */ 388c2ecf20Sopenharmony_ci#ifndef CONFIG_RADIO_AZTECH_PORT 398c2ecf20Sopenharmony_ci#define CONFIG_RADIO_AZTECH_PORT -1 408c2ecf20Sopenharmony_ci#endif 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci#define AZTECH_MAX 2 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_cistatic int io[AZTECH_MAX] = { [0] = CONFIG_RADIO_AZTECH_PORT, 458c2ecf20Sopenharmony_ci [1 ... (AZTECH_MAX - 1)] = -1 }; 468c2ecf20Sopenharmony_cistatic int radio_nr[AZTECH_MAX] = { [0 ... (AZTECH_MAX - 1)] = -1 }; 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_cimodule_param_array(io, int, NULL, 0444); 498c2ecf20Sopenharmony_ciMODULE_PARM_DESC(io, "I/O addresses of the Aztech card (0x350 or 0x358)"); 508c2ecf20Sopenharmony_cimodule_param_array(radio_nr, int, NULL, 0444); 518c2ecf20Sopenharmony_ciMODULE_PARM_DESC(radio_nr, "Radio device numbers"); 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_cistruct aztech { 548c2ecf20Sopenharmony_ci struct radio_isa_card isa; 558c2ecf20Sopenharmony_ci int curvol; 568c2ecf20Sopenharmony_ci}; 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci/* bit definitions for register read */ 598c2ecf20Sopenharmony_ci#define AZTECH_BIT_NOT_TUNED (1 << 0) 608c2ecf20Sopenharmony_ci#define AZTECH_BIT_MONO (1 << 1) 618c2ecf20Sopenharmony_ci/* bit definitions for register write */ 628c2ecf20Sopenharmony_ci#define AZTECH_BIT_TUN_CE (1 << 1) 638c2ecf20Sopenharmony_ci#define AZTECH_BIT_TUN_CLK (1 << 6) 648c2ecf20Sopenharmony_ci#define AZTECH_BIT_TUN_DATA (1 << 7) 658c2ecf20Sopenharmony_ci/* bits 0 and 2 are volume control, bits 3..5 are not connected */ 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_cistatic void aztech_set_pins(void *handle, u8 pins) 688c2ecf20Sopenharmony_ci{ 698c2ecf20Sopenharmony_ci struct radio_isa_card *isa = handle; 708c2ecf20Sopenharmony_ci struct aztech *az = container_of(isa, struct aztech, isa); 718c2ecf20Sopenharmony_ci u8 bits = az->curvol; 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ci if (pins & LM7000_DATA) 748c2ecf20Sopenharmony_ci bits |= AZTECH_BIT_TUN_DATA; 758c2ecf20Sopenharmony_ci if (pins & LM7000_CLK) 768c2ecf20Sopenharmony_ci bits |= AZTECH_BIT_TUN_CLK; 778c2ecf20Sopenharmony_ci if (pins & LM7000_CE) 788c2ecf20Sopenharmony_ci bits |= AZTECH_BIT_TUN_CE; 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci outb_p(bits, az->isa.io); 818c2ecf20Sopenharmony_ci} 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_cistatic struct radio_isa_card *aztech_alloc(void) 848c2ecf20Sopenharmony_ci{ 858c2ecf20Sopenharmony_ci struct aztech *az = kzalloc(sizeof(*az), GFP_KERNEL); 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci return az ? &az->isa : NULL; 888c2ecf20Sopenharmony_ci} 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_cistatic int aztech_s_frequency(struct radio_isa_card *isa, u32 freq) 918c2ecf20Sopenharmony_ci{ 928c2ecf20Sopenharmony_ci lm7000_set_freq(freq, isa, aztech_set_pins); 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci return 0; 958c2ecf20Sopenharmony_ci} 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_cistatic u32 aztech_g_rxsubchans(struct radio_isa_card *isa) 988c2ecf20Sopenharmony_ci{ 998c2ecf20Sopenharmony_ci if (inb(isa->io) & AZTECH_BIT_MONO) 1008c2ecf20Sopenharmony_ci return V4L2_TUNER_SUB_MONO; 1018c2ecf20Sopenharmony_ci return V4L2_TUNER_SUB_STEREO; 1028c2ecf20Sopenharmony_ci} 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_cistatic u32 aztech_g_signal(struct radio_isa_card *isa) 1058c2ecf20Sopenharmony_ci{ 1068c2ecf20Sopenharmony_ci return (inb(isa->io) & AZTECH_BIT_NOT_TUNED) ? 0 : 0xffff; 1078c2ecf20Sopenharmony_ci} 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_cistatic int aztech_s_mute_volume(struct radio_isa_card *isa, bool mute, int vol) 1108c2ecf20Sopenharmony_ci{ 1118c2ecf20Sopenharmony_ci struct aztech *az = container_of(isa, struct aztech, isa); 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ci if (mute) 1148c2ecf20Sopenharmony_ci vol = 0; 1158c2ecf20Sopenharmony_ci az->curvol = (vol & 1) + ((vol & 2) << 1); 1168c2ecf20Sopenharmony_ci outb(az->curvol, isa->io); 1178c2ecf20Sopenharmony_ci return 0; 1188c2ecf20Sopenharmony_ci} 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_cistatic const struct radio_isa_ops aztech_ops = { 1218c2ecf20Sopenharmony_ci .alloc = aztech_alloc, 1228c2ecf20Sopenharmony_ci .s_mute_volume = aztech_s_mute_volume, 1238c2ecf20Sopenharmony_ci .s_frequency = aztech_s_frequency, 1248c2ecf20Sopenharmony_ci .g_rxsubchans = aztech_g_rxsubchans, 1258c2ecf20Sopenharmony_ci .g_signal = aztech_g_signal, 1268c2ecf20Sopenharmony_ci}; 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_cistatic const int aztech_ioports[] = { 0x350, 0x358 }; 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_cistatic struct radio_isa_driver aztech_driver = { 1318c2ecf20Sopenharmony_ci .driver = { 1328c2ecf20Sopenharmony_ci .match = radio_isa_match, 1338c2ecf20Sopenharmony_ci .probe = radio_isa_probe, 1348c2ecf20Sopenharmony_ci .remove = radio_isa_remove, 1358c2ecf20Sopenharmony_ci .driver = { 1368c2ecf20Sopenharmony_ci .name = "radio-aztech", 1378c2ecf20Sopenharmony_ci }, 1388c2ecf20Sopenharmony_ci }, 1398c2ecf20Sopenharmony_ci .io_params = io, 1408c2ecf20Sopenharmony_ci .radio_nr_params = radio_nr, 1418c2ecf20Sopenharmony_ci .io_ports = aztech_ioports, 1428c2ecf20Sopenharmony_ci .num_of_io_ports = ARRAY_SIZE(aztech_ioports), 1438c2ecf20Sopenharmony_ci .region_size = 8, 1448c2ecf20Sopenharmony_ci .card = "Aztech Radio", 1458c2ecf20Sopenharmony_ci .ops = &aztech_ops, 1468c2ecf20Sopenharmony_ci .has_stereo = true, 1478c2ecf20Sopenharmony_ci .max_volume = 3, 1488c2ecf20Sopenharmony_ci}; 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_cistatic int __init aztech_init(void) 1518c2ecf20Sopenharmony_ci{ 1528c2ecf20Sopenharmony_ci return isa_register_driver(&aztech_driver.driver, AZTECH_MAX); 1538c2ecf20Sopenharmony_ci} 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_cistatic void __exit aztech_exit(void) 1568c2ecf20Sopenharmony_ci{ 1578c2ecf20Sopenharmony_ci isa_unregister_driver(&aztech_driver.driver); 1588c2ecf20Sopenharmony_ci} 1598c2ecf20Sopenharmony_ci 1608c2ecf20Sopenharmony_cimodule_init(aztech_init); 1618c2ecf20Sopenharmony_cimodule_exit(aztech_exit); 162