Path: blob/master/drivers/media/dvb/mantis/mantis_uart.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/spinlock.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_uart.h"3637struct mantis_uart_params {38enum mantis_baud baud_rate;39enum mantis_parity parity;40};4142static struct {43char string[7];44} rates[5] = {45{ "9600" },46{ "19200" },47{ "38400" },48{ "57600" },49{ "115200" }50};5152static struct {53char string[5];54} parity[3] = {55{ "NONE" },56{ "ODD" },57{ "EVEN" }58};5960#define UART_MAX_BUF 166162int mantis_uart_read(struct mantis_pci *mantis, u8 *data)63{64struct mantis_hwconfig *config = mantis->hwconfig;65u32 stat = 0, i;6667/* get data */68for (i = 0; i < (config->bytes + 1); i++) {6970stat = mmread(MANTIS_UART_STAT);7172if (stat & MANTIS_UART_RXFIFO_FULL) {73dprintk(MANTIS_ERROR, 1, "RX Fifo FULL");74}75data[i] = mmread(MANTIS_UART_RXD) & 0x3f;7677dprintk(MANTIS_DEBUG, 1, "Reading ... <%02x>", data[i] & 0x3f);7879if (data[i] & (1 << 7)) {80dprintk(MANTIS_ERROR, 1, "UART framing error");81return -EINVAL;82}83if (data[i] & (1 << 6)) {84dprintk(MANTIS_ERROR, 1, "UART parity error");85return -EINVAL;86}87}8889return 0;90}9192static void mantis_uart_work(struct work_struct *work)93{94struct mantis_pci *mantis = container_of(work, struct mantis_pci, uart_work);95struct mantis_hwconfig *config = mantis->hwconfig;96u8 buf[16];97int i;9899mantis_uart_read(mantis, buf);100101for (i = 0; i < (config->bytes + 1); i++)102dprintk(MANTIS_INFO, 1, "UART BUF:%d <%02x> ", i, buf[i]);103104dprintk(MANTIS_DEBUG, 0, "\n");105}106107static int mantis_uart_setup(struct mantis_pci *mantis,108struct mantis_uart_params *params)109{110u32 reg;111112mmwrite((mmread(MANTIS_UART_CTL) | (params->parity & 0x3)), MANTIS_UART_CTL);113114reg = mmread(MANTIS_UART_BAUD);115116switch (params->baud_rate) {117case MANTIS_BAUD_9600:118reg |= 0xd8;119break;120case MANTIS_BAUD_19200:121reg |= 0x6c;122break;123case MANTIS_BAUD_38400:124reg |= 0x36;125break;126case MANTIS_BAUD_57600:127reg |= 0x23;128break;129case MANTIS_BAUD_115200:130reg |= 0x11;131break;132default:133return -EINVAL;134}135136mmwrite(reg, MANTIS_UART_BAUD);137138return 0;139}140141int mantis_uart_init(struct mantis_pci *mantis)142{143struct mantis_hwconfig *config = mantis->hwconfig;144struct mantis_uart_params params;145146/* default parity: */147params.baud_rate = config->baud_rate;148params.parity = config->parity;149dprintk(MANTIS_INFO, 1, "Initializing UART @ %sbps parity:%s",150rates[params.baud_rate].string,151parity[params.parity].string);152153init_waitqueue_head(&mantis->uart_wq);154spin_lock_init(&mantis->uart_lock);155156INIT_WORK(&mantis->uart_work, mantis_uart_work);157158/* disable interrupt */159mmwrite(mmread(MANTIS_UART_CTL) & 0xffef, MANTIS_UART_CTL);160161mantis_uart_setup(mantis, ¶ms);162163/* default 1 byte */164mmwrite((mmread(MANTIS_UART_BAUD) | (config->bytes << 8)), MANTIS_UART_BAUD);165166/* flush buffer */167mmwrite((mmread(MANTIS_UART_CTL) | MANTIS_UART_RXFLUSH), MANTIS_UART_CTL);168169/* enable interrupt */170mmwrite(mmread(MANTIS_INT_MASK) | 0x800, MANTIS_INT_MASK);171mmwrite(mmread(MANTIS_UART_CTL) | MANTIS_UART_RXINT, MANTIS_UART_CTL);172173schedule_work(&mantis->uart_work);174dprintk(MANTIS_DEBUG, 1, "UART successfully initialized");175176return 0;177}178EXPORT_SYMBOL_GPL(mantis_uart_init);179180void mantis_uart_exit(struct mantis_pci *mantis)181{182/* disable interrupt */183mmwrite(mmread(MANTIS_UART_CTL) & 0xffef, MANTIS_UART_CTL);184flush_work_sync(&mantis->uart_work);185}186EXPORT_SYMBOL_GPL(mantis_uart_exit);187188189