Made header file usage more consistent
[reactos.git] / reactos / drivers / dd / parallel / parallel.c
1 /* $Id: parallel.c,v 1.5 2000/06/29 23:35:49 dwelch Exp $
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: services/parallel/parallel.c
6 * PURPOSE: Parallel port driver
7 * PROGRAMMER: David Welch (welch@mcmail.com)
8 * UPDATE HISTORY:
9 * ??/??/??: Created
10 * 18/06/98: Made more NT like
11 */
12
13 /* FUNCTIONS **************************************************************/
14
15 #include <ddk/ntddk.h>
16 #include "../../../ntoskrnl/include/internal/i386/io.h"
17
18 #include "parallel.h"
19
20 #define NDEBUG
21 #include <debug.h>
22
23
24 #define LP_B (0x378)
25 #define LP_S (inb_p(LP_B+1))
26 #define LP_C (LP_B+2)
27
28 static void Parallel_Reset(void)
29 /*
30 * FUNCTION: Resets the device attached to the parallel port
31 */
32 {
33 int i;
34
35 outb_p(LP_C,0);
36 for (i=0;i<LP_DELAY;i++);
37 outb_p(LP_C,LP_PSELECP | LP_PINITP);
38 }
39
40 static void Parallel_putchar(unsigned char ch)
41 /*
42 * FUNCTION: Writes a character to the parallel port
43 * ARGUMENTS:
44 * ch = character to write
45 */
46 {
47
48 int count=0;
49 int status;
50 int wait=0;
51
52 do
53 {
54 status=LP_S;
55 count++;
56 }
57 while ( count < 500000 && !(status & LP_PBUSY) );
58
59 if (count==500000)
60 {
61 DPRINT("printer_putchar(): timed out\n");
62 return;
63 }
64
65 outb_p(LP_B,ch);
66 while (wait != 10000) { wait++; }
67 outb_p(LP_C, (LP_PSELECP | LP_PINITP | LP_PSTROBE ));
68 while (wait) { wait--; }
69 outb_p(LP_C, LP_PSELECP | LP_PINITP);
70 }
71
72 NTSTATUS Dispatch(PDEVICE_OBJECT DeviceObject, PIRP Irp)
73 /*
74 * FUNCTION: Handles user mode requests
75 * ARGUMENTS:
76 * DeviceObject = Device for request
77 * Irp = I/O request packet describing request
78 * RETURNS: Success or failure
79 */
80 {
81 PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation(Irp);
82 NTSTATUS status;
83 int i;
84
85 switch (Stack->MajorFunction)
86 {
87 case IRP_MJ_CREATE:
88 DPRINT("(Parallel Port Driver) Creating\n");
89 Parallel_Reset();
90 status = STATUS_SUCCESS;
91 break;
92
93 case IRP_MJ_CLOSE:
94 status = STATUS_SUCCESS;
95 break;
96
97 case IRP_MJ_WRITE:
98 DPRINT("(Parallel Port Driver) Writing %d bytes\n",
99 Stack->Parameters.Write.Length);
100 for (i=0;i<Stack->Parameters.Write.Length;i++)
101 {
102 Parallel_putchar(((char *)Irp->UserBuffer)[i]);
103 }
104 status = STATUS_SUCCESS;
105 break;
106
107 default:
108 status = STATUS_NOT_IMPLEMENTED;
109 break;
110 }
111
112 Irp->IoStatus.Status = status;
113 Irp->IoStatus.Information = 0;
114
115 IoCompleteRequest(Irp, IO_NO_INCREMENT);
116 return(status);
117 }
118
119 NTSTATUS STDCALL
120 DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
121 /*
122 * FUNCTION: Called by the system to initalize the driver
123 * ARGUMENTS:
124 * DriverObject = object describing this driver
125 * RegistryPath = path to our configuration entries
126 * RETURNS: Success or failure
127 */
128 {
129 PDEVICE_OBJECT DeviceObject;
130 NTSTATUS ret;
131 ANSI_STRING ansi_device_name;
132 UNICODE_STRING device_name;
133
134 DbgPrint("Parallel Port Driver 0.0.1\n");
135
136 RtlInitAnsiString (&ansi_device_name, "\\Device\\Parallel");
137 RtlAnsiStringToUnicodeString (&device_name, &ansi_device_name, TRUE);
138 ret = IoCreateDevice(DriverObject,
139 0,
140 &device_name,
141 FILE_DEVICE_PARALLEL_PORT,
142 0,
143 FALSE,
144 &DeviceObject);
145 if (ret!=STATUS_SUCCESS)
146 {
147 return(ret);
148 }
149
150 DeviceObject->Flags=0;
151 DriverObject->MajorFunction[IRP_MJ_CLOSE] = Dispatch;
152 DriverObject->MajorFunction[IRP_MJ_CREATE] = Dispatch;
153 DriverObject->MajorFunction[IRP_MJ_WRITE] = Dispatch;
154 DriverObject->MajorFunction[IRP_MJ_WRITE] = Dispatch;
155 DriverObject->DriverUnload = NULL;
156
157 return(STATUS_SUCCESS);
158 }
159