altera-lpt.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * altera-lpt.c
  4. *
  5. * altera FPGA driver
  6. *
  7. * Copyright (C) Altera Corporation 1998-2001
  8. * Copyright (C) 2010 NetUP Inc.
  9. * Copyright (C) 2010 Abylay Ospan <[email protected]>
  10. */
  11. #include <linux/io.h>
  12. #include <linux/kernel.h>
  13. #include "altera-exprt.h"
  14. static int lpt_hardware_initialized;
  15. static void byteblaster_write(int port, int data)
  16. {
  17. outb((u8)data, (u16)(port + 0x378));
  18. };
  19. static int byteblaster_read(int port)
  20. {
  21. int data = 0;
  22. data = inb((u16)(port + 0x378));
  23. return data & 0xff;
  24. };
  25. int netup_jtag_io_lpt(void *device, int tms, int tdi, int read_tdo)
  26. {
  27. int data = 0;
  28. int tdo = 0;
  29. int initial_lpt_ctrl = 0;
  30. if (!lpt_hardware_initialized) {
  31. initial_lpt_ctrl = byteblaster_read(2);
  32. byteblaster_write(2, (initial_lpt_ctrl | 0x02) & 0xdf);
  33. lpt_hardware_initialized = 1;
  34. }
  35. data = ((tdi ? 0x40 : 0) | (tms ? 0x02 : 0));
  36. byteblaster_write(0, data);
  37. if (read_tdo) {
  38. tdo = byteblaster_read(1);
  39. tdo = ((tdo & 0x80) ? 0 : 1);
  40. }
  41. byteblaster_write(0, data | 0x01);
  42. byteblaster_write(0, data);
  43. return tdo;
  44. }