Deleted Added
full compact
ppb_1284.c (32929) ppb_1284.c (38061)
1/*-
2 * Copyright (c) 1997 Nicolas Souchu
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
1/*-
2 * Copyright (c) 1997 Nicolas Souchu
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $Id: ppb_1284.c,v 1.2 1997/09/01 00:51:44 bde Exp $
26 * $Id: ppb_1284.c,v 1.3 1998/01/31 07:23:06 eivind Exp $
27 *
28 */
29
30#include "opt_debug_1284.h"
31
32#include <sys/param.h>
33#include <sys/systm.h>
34
35#include <machine/clock.h>
36
37#include <dev/ppbus/ppbconf.h>
38#include <dev/ppbus/ppb_1284.h>
39
40/*
27 *
28 */
29
30#include "opt_debug_1284.h"
31
32#include <sys/param.h>
33#include <sys/systm.h>
34
35#include <machine/clock.h>
36
37#include <dev/ppbus/ppbconf.h>
38#include <dev/ppbus/ppb_1284.h>
39
40/*
41 * nibble_1284_wait()
41 * do_1284_wait()
42 *
43 * Wait for the peripherial up to 40ms
44 */
45int
42 *
43 * Wait for the peripherial up to 40ms
44 */
45int
46nibble_1284_wait(struct ppb_device *dev, char mask, char status)
46do_1284_wait(struct ppb_device *dev, char mask, char status)
47{
48 int i;
47{
48 int i;
49 char r;
49
50
51 /* try up to 5ms */
52 for (i = 0; i < 20; i++) {
53 r = ppb_rstr(dev);
54 DELAY(25);
55 if ((r & mask) == status)
56 return (0);
57 }
58
50 return (ppb_poll_device(dev, 4, mask, status, PPB_NOINTR));
51}
52
53#define nibble2char(s) (((s & ~nACK) >> 3) | (~s & nBUSY) >> 4)
54
55/*
59 return (ppb_poll_device(dev, 4, mask, status, PPB_NOINTR));
60}
61
62#define nibble2char(s) (((s & ~nACK) >> 3) | (~s & nBUSY) >> 4)
63
64/*
65 * byte_1284_inbyte()
66 *
67 * Read 1 byte in BYTE mode
68 */
69int
70byte_1284_inbyte(struct ppb_device *dev, char *buffer)
71{
72 int error;
73
74 /* notify the peripherial to put data on the lines */
75 ppb_wctr(dev, PCD | AUTOFEED | nSTROBE | nINIT | nSELECTIN);
76
77 /* wait for valid byte signal */
78 if ((error = do_1284_wait(dev, nACK, 0)))
79 return (error);
80
81 /* fetch data */
82 *buffer = ppb_rdtr(dev);
83
84 /* indicate that data has been received, not ready for another */
85 ppb_wctr(dev, PCD | nAUTOFEED | nSTROBE | nINIT | nSELECTIN);
86
87 /* wait peripherial's acknowledgement */
88 if ((error = do_1284_wait(dev, nACK, nACK)))
89 return (error);
90
91 /* acknowledge the peripherial */
92 ppb_wctr(dev, PCD | nAUTOFEED | STROBE | nINIT | nSELECTIN);
93
94 return (0);
95}
96
97/*
56 * nibble_1284_inbyte()
57 *
98 * nibble_1284_inbyte()
99 *
58 * Read data in NIBBLE mode
100 * Read 1 byte in NIBBLE mode
59 */
60int
61nibble_1284_inbyte(struct ppb_device *dev, char *buffer)
62{
101 */
102int
103nibble_1284_inbyte(struct ppb_device *dev, char *buffer)
104{
63 char nibble[2], r;
105 char nibble[2];
64 int i, error;
65
106 int i, error;
107
66 r = ppb_rctr(dev);
67
68 for (i = 0; i < 2; i++) {
69 /* ready to take data (nAUTO low) */
108 for (i = 0; i < 2; i++) {
109 /* ready to take data (nAUTO low) */
70 ppb_wctr(dev, r | AUTOFEED);
110 ppb_wctr(dev, AUTOFEED | nSTROBE | nINIT | nSELECTIN);
71
111
72 if ((error = nibble_1284_wait(dev, nACK, 0))) {
73 ppb_wctr(dev, r);
112 if ((error = do_1284_wait(dev, nACK, 0)))
74 return (error);
113 return (error);
75 }
76
77 /* read nibble */
78 nibble[i] = ppb_rstr(dev);
79
80#ifdef DEBUG_1284
81 printf("nibble_1284_inbyte: nibble[%d]=0x%x\n", i, nibble[i]);
82#endif
83
84 /* ack, not ready for another nibble */
114
115 /* read nibble */
116 nibble[i] = ppb_rstr(dev);
117
118#ifdef DEBUG_1284
119 printf("nibble_1284_inbyte: nibble[%d]=0x%x\n", i, nibble[i]);
120#endif
121
122 /* ack, not ready for another nibble */
85 ppb_wctr(dev, r & ~AUTOFEED);
123 ppb_wctr(dev, nAUTOFEED | nSTROBE | nINIT | nSELECTIN);
86
87 /* wait ack from peripherial */
124
125 /* wait ack from peripherial */
88 if ((error = nibble_1284_wait(dev, nACK, nACK))) {
89 ppb_wctr(dev, r);
126 if ((error = do_1284_wait(dev, nACK, nACK)))
90 return (error);
127 return (error);
91 }
92 }
93
94 *buffer = ((nibble2char(nibble[1]) << 4) & 0xf0) |
95 (nibble2char(nibble[0]) & 0x0f);
96
97#ifdef DEBUG_1284
98 printf("nibble_1284_inbyte: byte=0x%x\n", *buffer);
99#endif

--- 7 unchanged lines hidden (view full) ---

107void
108nibble_1284_sync(struct ppb_device *dev)
109{
110 char ctr;
111
112 ctr = ppb_rctr(dev);
113
114 ppb_wctr(dev, (ctr & ~AUTOFEED) | SELECTIN);
128 }
129
130 *buffer = ((nibble2char(nibble[1]) << 4) & 0xf0) |
131 (nibble2char(nibble[0]) & 0x0f);
132
133#ifdef DEBUG_1284
134 printf("nibble_1284_inbyte: byte=0x%x\n", *buffer);
135#endif

--- 7 unchanged lines hidden (view full) ---

143void
144nibble_1284_sync(struct ppb_device *dev)
145{
146 char ctr;
147
148 ctr = ppb_rctr(dev);
149
150 ppb_wctr(dev, (ctr & ~AUTOFEED) | SELECTIN);
115 if (nibble_1284_wait(dev, nACK, 0))
151 if (do_1284_wait(dev, nACK, 0))
116 return;
117
118 ppb_wctr(dev, ctr | AUTOFEED);
152 return;
153
154 ppb_wctr(dev, ctr | AUTOFEED);
119 nibble_1284_wait(dev, nACK, nACK);
155 do_1284_wait(dev, nACK, nACK);
120
121 ppb_wctr(dev, (ctr & ~AUTOFEED) | SELECTIN);
122
123 return;
124}
125
126/*
127 * nibble_1284_mode()

--- 7 unchanged lines hidden (view full) ---

135 int error;
136
137 ctrl = ppb_rctr(dev);
138
139 ppb_wdtr(dev, mode);
140 DELAY(5);
141
142 ppb_wctr(dev, (ctrl & ~SELECTIN) | AUTOFEED);
156
157 ppb_wctr(dev, (ctr & ~AUTOFEED) | SELECTIN);
158
159 return;
160}
161
162/*
163 * nibble_1284_mode()

--- 7 unchanged lines hidden (view full) ---

171 int error;
172
173 ctrl = ppb_rctr(dev);
174
175 ppb_wdtr(dev, mode);
176 DELAY(5);
177
178 ppb_wctr(dev, (ctrl & ~SELECTIN) | AUTOFEED);
143 if ((error = nibble_1284_wait(dev, nACK | ERROR | SELECT | nFAULT,
179 if ((error = do_1284_wait(dev, nACK | ERROR | SELECT | nFAULT,
144 ERROR | SELECT | nFAULT))) {
145 ppb_wctr(dev, ctrl);
146 return (error);
147 }
148
149 ppb_wctr(dev, ppb_rctr(dev) | STROBE);
150 DELAY(5);
151
152 ppb_wctr(dev, ppb_rctr(dev) & ~STROBE);
153 DELAY(5);
154
155 ppb_wctr(dev, ppb_rctr(dev) & ~AUTOFEED);
156
157 return (0);
158}
180 ERROR | SELECT | nFAULT))) {
181 ppb_wctr(dev, ctrl);
182 return (error);
183 }
184
185 ppb_wctr(dev, ppb_rctr(dev) | STROBE);
186 DELAY(5);
187
188 ppb_wctr(dev, ppb_rctr(dev) & ~STROBE);
189 DELAY(5);
190
191 ppb_wctr(dev, ppb_rctr(dev) & ~AUTOFEED);
192
193 return (0);
194}