Deleted Added
full compact
ppb_1284.c (38061) ppb_1284.c (39134)
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.3 1998/01/31 07:23:06 eivind Exp $
26 * $Id: ppb_1284.c,v 1.4 1998/08/03 19:14:31 msmith Exp $
27 *
28 */
29
30#include "opt_debug_1284.h"
31
32#include <sys/param.h>
33#include <sys/systm.h>
34

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

102int
103nibble_1284_inbyte(struct ppb_device *dev, char *buffer)
104{
105 char nibble[2];
106 int i, error;
107
108 for (i = 0; i < 2; i++) {
109 /* ready to take data (nAUTO low) */
27 *
28 */
29
30#include "opt_debug_1284.h"
31
32#include <sys/param.h>
33#include <sys/systm.h>
34

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

102int
103nibble_1284_inbyte(struct ppb_device *dev, char *buffer)
104{
105 char nibble[2];
106 int i, error;
107
108 for (i = 0; i < 2; i++) {
109 /* ready to take data (nAUTO low) */
110 ppb_wctr(dev, AUTOFEED | nSTROBE | nINIT | nSELECTIN);
110 ppb_wctr(dev, AUTOFEED & ~(STROBE | SELECTIN));
111
112 if ((error = do_1284_wait(dev, nACK, 0)))
113 return (error);
114
115 /* read nibble */
116 nibble[i] = ppb_rstr(dev);
117
111
112 if ((error = do_1284_wait(dev, nACK, 0)))
113 return (error);
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 */
118 /* ack, not ready for another nibble */
123 ppb_wctr(dev, nAUTOFEED | nSTROBE | nINIT | nSELECTIN);
119 ppb_wctr(dev, 0 & ~(AUTOFEED | STROBE | SELECTIN));
124
125 /* wait ack from peripherial */
126 if ((error = do_1284_wait(dev, nACK, nACK)))
127 return (error);
128 }
129
130 *buffer = ((nibble2char(nibble[1]) << 4) & 0xf0) |
131 (nibble2char(nibble[0]) & 0x0f);
132
120
121 /* wait ack from peripherial */
122 if ((error = do_1284_wait(dev, nACK, nACK)))
123 return (error);
124 }
125
126 *buffer = ((nibble2char(nibble[1]) << 4) & 0xf0) |
127 (nibble2char(nibble[0]) & 0x0f);
128
133#ifdef DEBUG_1284
134 printf("nibble_1284_inbyte: byte=0x%x\n", *buffer);
135#endif
136
137 return (0);
138}
139
140/*
141 * nibble_1284_sync()
142 */
143void
144nibble_1284_sync(struct ppb_device *dev)

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

155 do_1284_wait(dev, nACK, nACK);
156
157 ppb_wctr(dev, (ctr & ~AUTOFEED) | SELECTIN);
158
159 return;
160}
161
162/*
129 return (0);
130}
131
132/*
133 * nibble_1284_sync()
134 */
135void
136nibble_1284_sync(struct ppb_device *dev)

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

147 do_1284_wait(dev, nACK, nACK);
148
149 ppb_wctr(dev, (ctr & ~AUTOFEED) | SELECTIN);
150
151 return;
152}
153
154/*
163 * nibble_1284_mode()
155 * ppb_1284_negociate()
164 *
165 * Normal nibble mode or request device id mode (see ppb_1284.h)
166 */
167int
156 *
157 * Normal nibble mode or request device id mode (see ppb_1284.h)
158 */
159int
168nibble_1284_mode(struct ppb_device *dev, int mode)
160ppb_1284_negociate(struct ppb_device *dev, int mode)
169{
161{
170 char ctrl;
171 int error;
162 int error;
163 int phase = 0;
172
164
173 ctrl = ppb_rctr(dev);
165 ppb_wctr(dev, (nINIT | SELECTIN) & ~(STROBE | AUTOFEED));
166 DELAY(1);
174
175 ppb_wdtr(dev, mode);
167
168 ppb_wdtr(dev, mode);
176 DELAY(5);
169 DELAY(1);
177
170
178 ppb_wctr(dev, (ctrl & ~SELECTIN) | AUTOFEED);
179 if ((error = do_1284_wait(dev, nACK | ERROR | SELECT | nFAULT,
180 ERROR | SELECT | nFAULT))) {
181 ppb_wctr(dev, ctrl);
182 return (error);
183 }
171 ppb_wctr(dev, (nINIT | AUTOFEED) & ~(STROBE | SELECTIN));
184
172
185 ppb_wctr(dev, ppb_rctr(dev) | STROBE);
186 DELAY(5);
173 if ((error = do_1284_wait(dev, nACK | PERROR | SELECT | nFAULT,
174 PERROR | SELECT | nFAULT)))
175 goto error;
187
176
188 ppb_wctr(dev, ppb_rctr(dev) & ~STROBE);
177 phase = 1;
178
179 ppb_wctr(dev, (nINIT | STROBE | AUTOFEED) & ~SELECTIN);
189 DELAY(5);
190
180 DELAY(5);
181
191 ppb_wctr(dev, ppb_rctr(dev) & ~AUTOFEED);
182 ppb_wctr(dev, nINIT & ~(SELECTIN | AUTOFEED | STROBE));
192
183
184#if 0 /* not respected by most devices */
185 if ((error = do_1284_wait(dev, nACK, nACK)))
186 goto error;
187
188 if (mode == 0)
189 if ((error = do_1284_wait(dev, SELECT, 0)))
190 goto error;
191 else
192 if ((error = do_1284_wait(dev, SELECT, SELECT)))
193 goto error;
194#endif
195
193 return (0);
196 return (0);
197
198error:
199 if (bootverbose)
200 printf("%s: status=0x%x %d\n", __FUNCTION__, ppb_rstr(dev), phase);
201
202 return (error);
194}
203}
204
205int
206ppb_1284_terminate(struct ppb_device *dev, int how)
207{
208 int error;
209
210 switch (how) {
211 case VALID_STATE:
212
213 ppb_wctr(dev, SELECTIN & ~(STROBE | AUTOFEED));
214
215 if ((error = do_1284_wait(dev, nACK | nBUSY | nFAULT, nFAULT)))
216 return (error);
217
218 ppb_wctr(dev, (SELECTIN | AUTOFEED) & ~STROBE);
219
220 if ((error = do_1284_wait(dev, nACK, nACK)))
221 return (error);
222
223 ppb_wctr(dev, SELECTIN & ~(STROBE | AUTOFEED));
224 break;
225
226 default:
227 return (EINVAL);
228 }
229
230 return (0);
231}