1/*	$NetBSD: ns87307.c,v 1.7 2016/07/07 06:55:38 msaitoh Exp $	*/
2
3/*
4 * Copyright 1997
5 * Digital Equipment Corporation. All rights reserved.
6 *
7 * This software is furnished under license and may be used and
8 * copied only in accordance with the following terms and conditions.
9 * Subject to these conditions, you may download, copy, install,
10 * use, modify and distribute this software in source and/or binary
11 * form. No title or ownership is transferred hereby.
12 *
13 * 1) Any source code used, modified or distributed must reproduce
14 *    and retain this copyright notice and list of conditions as
15 *    they appear in the source file.
16 *
17 * 2) No right is granted to use any trade name, trademark, or logo of
18 *    Digital Equipment Corporation. Neither the "Digital Equipment
19 *    Corporation" name nor any trademark or logo of Digital Equipment
20 *    Corporation may be used to endorse or promote products derived
21 *    from this software without the prior written permission of
22 *    Digital Equipment Corporation.
23 *
24 * 3) This software is provided "AS-IS" and any express or implied
25 *    warranties, including but not limited to, any implied warranties
26 *    of merchantability, fitness for a particular purpose, or
27 *    non-infringement are disclaimed. In no event shall DIGITAL be
28 *    liable for any damages whatsoever, and in particular, DIGITAL
29 *    shall not be liable for special, indirect, consequential, or
30 *    incidental damages or damages for lost profits, loss of
31 *    revenue or loss of use, whether such damages arise in contract,
32 *    negligence, tort, under statute, in equity, at law or otherwise,
33 *    even if advised of the possibility of such damage.
34 */
35
36/*
37**++
38**
39**  FACILITY:
40**
41**    ns87307 SuperIO chip configuration functions.
42**
43**  ABSTRACT:
44**
45**    This file contains routines to configure the National Semiconductor
46**    PC87307VUL SuperIO chip.
47**
48**  AUTHORS:
49**
50**    John Court, Digital Equipment Corporation.
51**
52**  CREATION DATE:
53**
54**    16/4/1997
55**
56**--
57*/
58
59#include <sys/cdefs.h>
60__KERNEL_RCSID(0, "$NetBSD: ns87307.c,v 1.7 2016/07/07 06:55:38 msaitoh Exp $");
61
62#include "opt_ddb.h"
63
64#include <sys/param.h>
65#include <sys/device.h>
66#include <sys/systm.h>
67#include <sys/bus.h>
68
69#include <machine/intr.h>
70
71#include <dev/isa/isavar.h>
72#include <shark/shark/ns87307reg.h>
73
74
75
76
77
78
79
80
81
82/*
83**++
84**  FUNCTION NAME:
85**
86**      i87307KbdConfig
87**
88**  FUNCTIONAL DESCRIPTION:
89**
90**     This function configures the Keyboard controller logical
91**     device on the ns87307 SuperIO hardware.  It sets up the addresses
92**     of the data and command ports and configures the irq number and
93**     triggering for the device.  It then activates the device.
94**
95**  FORMAL PARAMETERS:
96**
97**       iot
98**       kbdBase
99**       irqNum
100**
101**  IMPLICIT INPUTS:
102**
103**      None.
104**
105**  IMPLICIT OUTPUTS:
106**
107**      None.
108**
109**  function value or completion codes
110**
111**      true    configuration of the kdb device was successful.
112**      false   configuration of the kdb device failed.
113**
114**  SIDE EFFECTS:
115**
116**      None.
117**--
118*/
119int
120i87307KbdConfig(bus_space_tag_t iot,
121		u_int           kbdBase,
122		u_int           irqNum )
123{
124    u_int                configured = false;
125    bus_space_handle_t   ioh;
126
127
128    if (!(bus_space_map( iot, CONNSIOADDR, NSIO_NPORTS, 0 , &ioh )))
129    {
130	NSIO_SELECT_DEV( iot, ioh,  NSIO_DEV_KBC );
131	NSIO_DEACTIVATE_DEV( iot, ioh );
132	NSIO_CONFIG_IRQ( iot, ioh, irqNum, NSIO_IRQ_LEVEL | NSIO_IRQ_HIGH );
133	NSIO_CONFIG_KBCDATA( iot, ioh, kbdBase );
134	NSIO_CONFIG_KBCCMD(iot, ioh, kbdBase+4);
135	NSIO_WRITE_REG( iot, ioh, NSIO_KBC_CFG, 0x80 );
136	NSIO_ACTIVATE_DEV( iot, ioh );
137	NSIO_CONFIG_KBCDEBUG( iot, ioh );
138
139	/* unmap the space so can probe later
140	*/
141	bus_space_unmap( iot, ioh, NSIO_NPORTS );
142
143	configured = true;
144    }
145
146    return (configured);
147} /* End i87307KbdConfig() */
148
149
150
151/*
152**++
153**  FUNCTION NAME:
154**
155**      i87307MouseConfig
156**
157**  FUNCTIONAL DESCRIPTION:
158**
159**     This function configures the Mouse logical device on the ns87307
160**     SuperIO chip. It sets up only the interrupt parameters since the
161**     mouse shares the device ports with the Keyboard. It also activates
162**     the device.
163**
164**  FORMAL PARAMETERS:
165**
166**       iot
167**       irqNum
168**
169**  IMPLICIT INPUTS:
170**
171**      None.
172**
173**  IMPLICIT OUTPUTS:
174**
175**      None.
176**
177**  function value or completion codes
178**
179**      true    configuration of the kdb device was successful.
180**      false   configuration of the kdb device failed.
181**
182**  SIDE EFFECTS:
183**
184**      None.
185**--
186*/
187int
188i87307MouseConfig(bus_space_tag_t iot,
189		  u_int           irqNum )
190{
191    u_int                configured;
192    bus_space_handle_t   ioh;
193
194    configured = false; /* be a pessimist */
195
196    if (!(bus_space_map( iot, CONNSIOADDR, NSIO_NPORTS, 0 , &ioh )))
197    {
198	/* Now do the mouse logical device IRQ settup.
199	*/
200	NSIO_SELECT_DEV( iot, ioh, NSIO_DEV_MOUSE );
201	NSIO_DEACTIVATE_DEV( iot, ioh );
202	NSIO_CONFIG_IRQ( iot, ioh, irqNum, NSIO_IRQ_LEVEL | NSIO_IRQ_HIGH);
203	NSIO_ACTIVATE_DEV( iot, ioh );
204	NSIO_CONFIG_DEBUG( iot, ioh );
205	/* unmap the space so can probe later
206	*/
207	bus_space_unmap( iot, ioh, NSIO_NPORTS );
208
209	configured = true;
210    }
211
212
213    return (configured);
214} /* End i87307MouseConfig() */
215
216
217
218/*
219**++
220**  FUNCTION NAME:
221**
222**      i87307PrinterConfig
223**
224**  FUNCTIONAL DESCRIPTION:
225**
226**     This function configures the Parrel logical device on the ns87307
227**     SuperIO chip.
228**     the device.
229**
230**  FORMAL PARAMETERS:
231**
232**       iot
233**       irqNum
234**
235**  IMPLICIT INPUTS:
236**
237**      None.
238**
239**  IMPLICIT OUTPUTS:
240**
241**      None.
242**
243**  function value or completion codes
244**
245**      true    configuration of the kdb device was successful.
246**      false   configuration of the kdb device failed.
247**
248**  SIDE EFFECTS:
249**
250**      None.
251**--
252*/
253int
254i87307PrinterConfig(bus_space_tag_t iot,
255		  u_int           irqNum )
256{
257    u_int                configured = false;
258    bus_space_handle_t   ioh;
259
260    u_char value;
261
262    if (!(bus_space_map( iot, CONNSIOADDR, NSIO_NPORTS, 0 , &ioh )))
263    {
264        /* select the printer */
265        NSIO_SELECT_DEV( iot, ioh,  NSIO_DEV_LPT );
266    	NSIO_DEACTIVATE_DEV( iot, ioh );
267
268        value = NSIO_LPT_TRISTATE_DISABLE |
269                NSIO_LPT_CLOCK_DISABLE    |
270                NSIO_LPT_REPORT_SPP       |
271                NSIO_LPT_REG403_DISABLE   |
272                NSIO_LPT_SPP_EXTENDED;
273    	NSIO_WRITE_REG( iot, ioh, NSIO_CFG_REG0, value);
274
275        /* set the type of interrupt */
276        value = NSIO_IRQ_HIGH |
277                NSIO_IRQ_LEVEL;
278        NSIO_CONFIG_IRQ( iot, ioh, irqNum,value);
279
280    	/* activate the device */
281    	NSIO_ACTIVATE_DEV( iot, ioh );
282
283
284        /* unmap the space so can probe later */
285    	bus_space_unmap( iot, ioh, NSIO_NPORTS );
286
287    	configured = true;
288    }
289
290
291    return (configured);
292} /* End i87307PrinterConfig() */
293
294
295
296/*
297**++
298**  FUNCTION NAME:
299**
300**      nsioConfigPrint
301**
302**  FUNCTIONAL DESCRIPTION:
303**
304**     This function prints out the irq, iobase etc, for the
305**     currently selected logical device.  It is intended to
306**     be used for debugging only.
307**
308**  FORMAL PARAMETERS:
309**
310**       sc     pointer to the nsio's softc structure
311**
312**  IMPLICIT INPUTS:
313**
314**      None.
315**
316**  IMPLICIT OUTPUTS:
317**
318**      None.
319**
320**  function value or completion codes
321**
322**      None
323**
324**  SIDE EFFECTS:
325**
326**      None.
327**
328**--
329*/
330//#ifdef DDB
331void nsioConfigPrint(bus_space_tag_t nsioIot,
332                     bus_space_handle_t  nsioIoh )
333{
334    u_char     dev;
335    u_char     activate;
336    u_char     iorange;
337    u_char     iobaseh;
338    u_char     iobasel;
339    u_char     irq;
340    u_char     irqType;
341    u_char     dma1;
342    u_char     dma2;
343    u_char     reg0;
344
345    NSIO_READ_REG( nsioIot, nsioIoh, NSIO_CFG_LOGDEV, dev );
346    NSIO_READ_REG( nsioIot, nsioIoh, NSIO_CFG_ACTIVATE, activate );
347    NSIO_READ_REG( nsioIot, nsioIoh, NSIO_CFG_IORNGCHK, iorange );
348    NSIO_READ_REG( nsioIot, nsioIoh, NSIO_CFG_IOBASEH, iobaseh );
349    NSIO_READ_REG( nsioIot, nsioIoh, NSIO_CFG_IOBASEL, iobasel );
350    NSIO_READ_REG( nsioIot, nsioIoh, NSIO_CFG_IRQ, irq );
351    NSIO_READ_REG( nsioIot, nsioIoh, NSIO_CFG_IRQTYPE, irqType );
352    NSIO_READ_REG( nsioIot, nsioIoh, NSIO_CFG_DMA1, dma1 );
353    NSIO_READ_REG( nsioIot, nsioIoh, NSIO_CFG_DMA2, dma2 );
354    NSIO_READ_REG( nsioIot, nsioIoh, NSIO_CFG_REG0, reg0 );
355
356    printf("nsio config for logical device %d\n", dev );
357    printf("activate:   %x\n",activate);
358    printf("iorange:    %x\n",iorange);
359    printf("iobase:     %x\n",(iobaseh << 8) | iobasel);
360    printf("irq:        %x\n",irq);
361    printf("irqtype:    %x\n",irqType);
362    printf("dma1:       %x\n",dma1);
363    printf("dma2:       %x\n",dma2) ;
364    printf("reg0:       %x\n",reg0);
365}
366//#endif
367