Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * altera-lpt.c
0004  *
0005  * altera FPGA driver
0006  *
0007  * Copyright (C) Altera Corporation 1998-2001
0008  * Copyright (C) 2010 NetUP Inc.
0009  * Copyright (C) 2010 Abylay Ospan <aospan@netup.ru>
0010  */
0011 
0012 #include <linux/io.h>
0013 #include <linux/kernel.h>
0014 #include "altera-exprt.h"
0015 
0016 static int lpt_hardware_initialized;
0017 
0018 static void byteblaster_write(int port, int data)
0019 {
0020     outb((u8)data, (u16)(port + 0x378));
0021 };
0022 
0023 static int byteblaster_read(int port)
0024 {
0025     int data = 0;
0026     data = inb((u16)(port + 0x378));
0027     return data & 0xff;
0028 };
0029 
0030 int netup_jtag_io_lpt(void *device, int tms, int tdi, int read_tdo)
0031 {
0032     int data = 0;
0033     int tdo = 0;
0034     int initial_lpt_ctrl = 0;
0035 
0036     if (!lpt_hardware_initialized) {
0037         initial_lpt_ctrl = byteblaster_read(2);
0038         byteblaster_write(2, (initial_lpt_ctrl | 0x02) & 0xdf);
0039         lpt_hardware_initialized = 1;
0040     }
0041 
0042     data = ((tdi ? 0x40 : 0) | (tms ? 0x02 : 0));
0043 
0044     byteblaster_write(0, data);
0045 
0046     if (read_tdo) {
0047         tdo = byteblaster_read(1);
0048         tdo = ((tdo & 0x80) ? 0 : 1);
0049     }
0050 
0051     byteblaster_write(0, data | 0x01);
0052 
0053     byteblaster_write(0, data);
0054 
0055     return tdo;
0056 }