summaryrefslogtreecommitdiffstats
path: root/private/ntos/ndis/irmini/parallax.c
blob: a9f12aab0c61a2d92d62d0d772609595615ac5ea (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
 *  PARALLAX.C
 *
 *
 *
 */

#ifndef IRMINILIB

	#include "dongle.h"


	/*
	 *  The programming interface to a UART (COM serial port)
	 *  consists of eight consecutive registers.
	 *  These are the port offsets from the UART's base I/O address.
	 */
	typedef enum comPortRegOffsets {
		XFER_REG_OFFSET						= 0,
		INT_ENABLE_REG_OFFSET				= 1,
		INT_ID_AND_FIFO_CNTRL_REG_OFFSET	= 2,
		LINE_CONTROL_REG_OFFSET				= 3,
		MODEM_CONTROL_REG_OFFSET			= 4,
		LINE_STAT_REG_OFFSET				= 5,
		MODEM_STAT_REG_OFFSET				= 6,
		SCRATCH_REG_OFFSET					= 7
	} comPortRegOffset;


	#define PARALLAX_IRDA_SPEEDS	( \
										NDIS_IRDA_SPEED_2400	|	\
										NDIS_IRDA_SPEED_9600	|	\
										NDIS_IRDA_SPEED_19200	|	\
										NDIS_IRDA_SPEED_38400	|	\
										NDIS_IRDA_SPEED_57600	|	\
										NDIS_IRDA_SPEED_115200		\
									)



	BOOLEAN PARALLAX_Init(UINT comBase, dongleCapabilities *caps, UINT *context)
	{
		UCHAR modemCntrlVal;

		IRMINI_RawReadPort(comBase+MODEM_CONTROL_REG_OFFSET, &modemCntrlVal);
		modemCntrlVal |= 3;
		IRMINI_RawWritePort(comBase+MODEM_CONTROL_REG_OFFSET, modemCntrlVal);
		IRMINI_StallExecution(1000);

		caps->supportedSpeedsMask	= PARALLAX_IRDA_SPEEDS;
		caps->turnAroundTime_usec	= 5000;
		caps->extraBOFsRequired		= 0;

		*context = 0;

		return TRUE;
	}

	VOID PARALLAX_Deinit(UINT comBase, UINT context)
	{
		
	}

	BOOLEAN PARALLAX_SetSpeed(UINT comBase, UINT bitsPerSec, UINT context)
	{
		UCHAR modemCntrlVal;
		UINT numToggles;

		IRMINI_RawReadPort(comBase+MODEM_CONTROL_REG_OFFSET, &modemCntrlVal);

		/*
		 *  First set the speed to 115200 baud.
		 */
		modemCntrlVal &= ~2;
		IRMINI_RawWritePort(comBase+MODEM_CONTROL_REG_OFFSET, modemCntrlVal);
		IRMINI_StallExecution(1000);
		modemCntrlVal |= 2;
		IRMINI_RawWritePort(comBase+MODEM_CONTROL_REG_OFFSET, modemCntrlVal);
		IRMINI_StallExecution(1000);

		/*
		 *  Now, "count down" from 115.2 Kbaud.
		 */
		switch (bitsPerSec){
			case 2400:		numToggles = 6;		break;
			case 4800:		numToggles = 5;		break;
			case 9600:		numToggles = 4;		break;
			case 19200:		numToggles = 3;		break;
			case 38400:		numToggles = 2;		break;
			case 57600:		numToggles = 1;		break;
			case 115200:	numToggles = 0;		break;
			default:
				/*
				 *  Illegal speed
				 */
				return FALSE;
		}

		while (numToggles-- > 0){
			modemCntrlVal &= ~1;
			IRMINI_RawWritePort(comBase+MODEM_CONTROL_REG_OFFSET, modemCntrlVal);
			IRMINI_StallExecution(1000);
			modemCntrlVal |= 1;
			IRMINI_RawWritePort(comBase+MODEM_CONTROL_REG_OFFSET, modemCntrlVal);
			IRMINI_StallExecution(1000);
		}

		return TRUE;
	}


#endif