Path: blob/master/drivers/media/dvb/mantis/mantis_ioc.c
15112 views
/*1Mantis PCI bridge driver23Copyright (C) Manu Abraham ([email protected])45This program is free software; you can redistribute it and/or modify6it under the terms of the GNU General Public License as published by7the Free Software Foundation; either version 2 of the License, or8(at your option) any later version.910This program is distributed in the hope that it will be useful,11but WITHOUT ANY WARRANTY; without even the implied warranty of12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13GNU General Public License for more details.1415You should have received a copy of the GNU General Public License16along with this program; if not, write to the Free Software17Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.18*/1920#include <linux/kernel.h>21#include <linux/i2c.h>2223#include <linux/signal.h>24#include <linux/sched.h>25#include <linux/interrupt.h>2627#include "dmxdev.h"28#include "dvbdev.h"29#include "dvb_demux.h"30#include "dvb_frontend.h"31#include "dvb_net.h"3233#include "mantis_common.h"34#include "mantis_reg.h"35#include "mantis_ioc.h"3637static int read_eeprom_bytes(struct mantis_pci *mantis, u8 reg, u8 *data, u8 length)38{39struct i2c_adapter *adapter = &mantis->adapter;40int err;41u8 buf = reg;4243struct i2c_msg msg[] = {44{ .addr = 0x50, .flags = 0, .buf = &buf, .len = 1 },45{ .addr = 0x50, .flags = I2C_M_RD, .buf = data, .len = length },46};4748err = i2c_transfer(adapter, msg, 2);49if (err < 0) {50dprintk(MANTIS_ERROR, 1, "ERROR: i2c read: < err=%i d0=0x%02x d1=0x%02x >",51err, data[0], data[1]);5253return err;54}5556return 0;57}58int mantis_get_mac(struct mantis_pci *mantis)59{60int err;61u8 mac_addr[6] = {0};6263err = read_eeprom_bytes(mantis, 0x08, mac_addr, 6);64if (err < 0) {65dprintk(MANTIS_ERROR, 1, "ERROR: Mantis EEPROM read error <%d>", err);6667return err;68}6970dprintk(MANTIS_ERROR, 0, " MAC Address=[%pM]\n", mac_addr);7172return 0;73}74EXPORT_SYMBOL_GPL(mantis_get_mac);7576/* Turn the given bit on or off. */77void mantis_gpio_set_bits(struct mantis_pci *mantis, u32 bitpos, u8 value)78{79u32 cur;8081dprintk(MANTIS_DEBUG, 1, "Set Bit <%d> to <%d>", bitpos, value);82cur = mmread(MANTIS_GPIF_ADDR);83if (value)84mantis->gpio_status = cur | (1 << bitpos);85else86mantis->gpio_status = cur & (~(1 << bitpos));8788dprintk(MANTIS_DEBUG, 1, "GPIO Value <%02x>", mantis->gpio_status);89mmwrite(mantis->gpio_status, MANTIS_GPIF_ADDR);90mmwrite(0x00, MANTIS_GPIF_DOUT);91}92EXPORT_SYMBOL_GPL(mantis_gpio_set_bits);9394int mantis_stream_control(struct mantis_pci *mantis, enum mantis_stream_control stream_ctl)95{96u32 reg;9798reg = mmread(MANTIS_CONTROL);99switch (stream_ctl) {100case STREAM_TO_HIF:101dprintk(MANTIS_DEBUG, 1, "Set stream to HIF");102reg &= 0xff - MANTIS_BYPASS;103mmwrite(reg, MANTIS_CONTROL);104reg |= MANTIS_BYPASS;105mmwrite(reg, MANTIS_CONTROL);106break;107108case STREAM_TO_CAM:109dprintk(MANTIS_DEBUG, 1, "Set stream to CAM");110reg |= MANTIS_BYPASS;111mmwrite(reg, MANTIS_CONTROL);112reg &= 0xff - MANTIS_BYPASS;113mmwrite(reg, MANTIS_CONTROL);114break;115default:116dprintk(MANTIS_ERROR, 1, "Unknown MODE <%02x>", stream_ctl);117return -1;118}119120return 0;121}122EXPORT_SYMBOL_GPL(mantis_stream_control);123124125