18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci Mantis PCI bridge driver 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci Copyright (C) Manu Abraham (abraham.manu@gmail.com) 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci*/ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#include <linux/kernel.h> 108c2ecf20Sopenharmony_ci#include <linux/i2c.h> 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#include <linux/signal.h> 138c2ecf20Sopenharmony_ci#include <linux/sched.h> 148c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 158c2ecf20Sopenharmony_ci#include <asm/io.h> 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#include <media/dmxdev.h> 188c2ecf20Sopenharmony_ci#include <media/dvbdev.h> 198c2ecf20Sopenharmony_ci#include <media/dvb_demux.h> 208c2ecf20Sopenharmony_ci#include <media/dvb_frontend.h> 218c2ecf20Sopenharmony_ci#include <media/dvb_net.h> 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci#include "mantis_common.h" 248c2ecf20Sopenharmony_ci#include "mantis_reg.h" 258c2ecf20Sopenharmony_ci#include "mantis_ioc.h" 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_cistatic int read_eeprom_bytes(struct mantis_pci *mantis, u8 reg, u8 *data, u8 length) 288c2ecf20Sopenharmony_ci{ 298c2ecf20Sopenharmony_ci struct i2c_adapter *adapter = &mantis->adapter; 308c2ecf20Sopenharmony_ci int err; 318c2ecf20Sopenharmony_ci u8 buf = reg; 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci struct i2c_msg msg[] = { 348c2ecf20Sopenharmony_ci { .addr = 0x50, .flags = 0, .buf = &buf, .len = 1 }, 358c2ecf20Sopenharmony_ci { .addr = 0x50, .flags = I2C_M_RD, .buf = data, .len = length }, 368c2ecf20Sopenharmony_ci }; 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci err = i2c_transfer(adapter, msg, 2); 398c2ecf20Sopenharmony_ci if (err < 0) { 408c2ecf20Sopenharmony_ci dprintk(MANTIS_ERROR, 1, "ERROR: i2c read: < err=%i d0=0x%02x d1=0x%02x >", 418c2ecf20Sopenharmony_ci err, data[0], data[1]); 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci return err; 448c2ecf20Sopenharmony_ci } 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci return 0; 478c2ecf20Sopenharmony_ci} 488c2ecf20Sopenharmony_ciint mantis_get_mac(struct mantis_pci *mantis) 498c2ecf20Sopenharmony_ci{ 508c2ecf20Sopenharmony_ci int err; 518c2ecf20Sopenharmony_ci u8 mac_addr[6] = {0}; 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci err = read_eeprom_bytes(mantis, 0x08, mac_addr, 6); 548c2ecf20Sopenharmony_ci if (err < 0) { 558c2ecf20Sopenharmony_ci dprintk(MANTIS_ERROR, 1, "ERROR: Mantis EEPROM read error <%d>", err); 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci return err; 588c2ecf20Sopenharmony_ci } 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci dprintk(MANTIS_ERROR, 0, " MAC Address=[%pM]\n", mac_addr); 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci return 0; 638c2ecf20Sopenharmony_ci} 648c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(mantis_get_mac); 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci/* Turn the given bit on or off. */ 678c2ecf20Sopenharmony_civoid mantis_gpio_set_bits(struct mantis_pci *mantis, u32 bitpos, u8 value) 688c2ecf20Sopenharmony_ci{ 698c2ecf20Sopenharmony_ci u32 cur; 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci dprintk(MANTIS_DEBUG, 1, "Set Bit <%d> to <%d>", bitpos, value); 728c2ecf20Sopenharmony_ci cur = mmread(MANTIS_GPIF_ADDR); 738c2ecf20Sopenharmony_ci if (value) 748c2ecf20Sopenharmony_ci mantis->gpio_status = cur | (1 << bitpos); 758c2ecf20Sopenharmony_ci else 768c2ecf20Sopenharmony_ci mantis->gpio_status = cur & (~(1 << bitpos)); 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci dprintk(MANTIS_DEBUG, 1, "GPIO Value <%02x>", mantis->gpio_status); 798c2ecf20Sopenharmony_ci mmwrite(mantis->gpio_status, MANTIS_GPIF_ADDR); 808c2ecf20Sopenharmony_ci mmwrite(0x00, MANTIS_GPIF_DOUT); 818c2ecf20Sopenharmony_ci} 828c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(mantis_gpio_set_bits); 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_ciint mantis_stream_control(struct mantis_pci *mantis, enum mantis_stream_control stream_ctl) 858c2ecf20Sopenharmony_ci{ 868c2ecf20Sopenharmony_ci u32 reg; 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci reg = mmread(MANTIS_CONTROL); 898c2ecf20Sopenharmony_ci switch (stream_ctl) { 908c2ecf20Sopenharmony_ci case STREAM_TO_HIF: 918c2ecf20Sopenharmony_ci dprintk(MANTIS_DEBUG, 1, "Set stream to HIF"); 928c2ecf20Sopenharmony_ci reg &= 0xff - MANTIS_BYPASS; 938c2ecf20Sopenharmony_ci mmwrite(reg, MANTIS_CONTROL); 948c2ecf20Sopenharmony_ci reg |= MANTIS_BYPASS; 958c2ecf20Sopenharmony_ci mmwrite(reg, MANTIS_CONTROL); 968c2ecf20Sopenharmony_ci break; 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ci case STREAM_TO_CAM: 998c2ecf20Sopenharmony_ci dprintk(MANTIS_DEBUG, 1, "Set stream to CAM"); 1008c2ecf20Sopenharmony_ci reg |= MANTIS_BYPASS; 1018c2ecf20Sopenharmony_ci mmwrite(reg, MANTIS_CONTROL); 1028c2ecf20Sopenharmony_ci reg &= 0xff - MANTIS_BYPASS; 1038c2ecf20Sopenharmony_ci mmwrite(reg, MANTIS_CONTROL); 1048c2ecf20Sopenharmony_ci break; 1058c2ecf20Sopenharmony_ci default: 1068c2ecf20Sopenharmony_ci dprintk(MANTIS_ERROR, 1, "Unknown MODE <%02x>", stream_ctl); 1078c2ecf20Sopenharmony_ci return -1; 1088c2ecf20Sopenharmony_ci } 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_ci return 0; 1118c2ecf20Sopenharmony_ci} 1128c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(mantis_stream_control); 113