atkbdc_subr.c revision 330897
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer as
12 *    the first lines of this file unmodified.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in the
15 *    documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 *	from: FreeBSD: src/sys/isa/atkbdc_isa.c,v 1.31 2005/05/29 04:42:28 nyan Exp
29 */
30
31#include <sys/cdefs.h>
32__FBSDID("$FreeBSD: stable/11/sys/dev/atkbdc/atkbdc_subr.c 330897 2018-03-14 03:19:51Z eadler $");
33
34#include "opt_kbd.h"
35
36#include <sys/param.h>
37#include <sys/systm.h>
38#include <sys/kernel.h>
39#include <sys/module.h>
40#include <sys/bus.h>
41#include <sys/malloc.h>
42#include <machine/resource.h>
43#include <sys/rman.h>
44
45#include <dev/atkbdc/atkbdc_subr.h>
46#include <dev/atkbdc/atkbdcreg.h>
47
48MALLOC_DEFINE(M_ATKBDDEV, "atkbddev", "AT Keyboard device");
49
50devclass_t atkbdc_devclass;
51
52int
53atkbdc_print_child(device_t bus, device_t dev)
54{
55	atkbdc_device_t *kbdcdev;
56	rman_res_t irq;
57	int flags;
58	int retval = 0;
59
60	kbdcdev = (atkbdc_device_t *)device_get_ivars(dev);
61
62	retval += bus_print_child_header(bus, dev);
63	flags = device_get_flags(dev);
64	if (flags != 0)
65		retval += printf(" flags 0x%x", flags);
66	irq = bus_get_resource_start(dev, SYS_RES_IRQ, kbdcdev->rid);
67	if (irq != 0)
68		retval += printf(" irq %jd", irq);
69	retval += bus_print_child_footer(bus, dev);
70
71	return (retval);
72}
73
74int
75atkbdc_read_ivar(device_t bus, device_t dev, int index, uintptr_t *val)
76{
77	atkbdc_device_t *ivar;
78
79	ivar = (atkbdc_device_t *)device_get_ivars(dev);
80	switch (index) {
81	case KBDC_IVAR_VENDORID:
82		*val = (u_long)ivar->vendorid;
83		break;
84	case KBDC_IVAR_SERIAL:
85		*val = (u_long)ivar->serial;
86		break;
87	case KBDC_IVAR_LOGICALID:
88		*val = (u_long)ivar->logicalid;
89		break;
90	case KBDC_IVAR_COMPATID:
91		*val = (u_long)ivar->compatid;
92		break;
93	default:
94		return ENOENT;
95	}
96	return 0;
97}
98
99int
100atkbdc_write_ivar(device_t bus, device_t dev, int index, uintptr_t val)
101{
102	atkbdc_device_t *ivar;
103
104	ivar = (atkbdc_device_t *)device_get_ivars(dev);
105	switch (index) {
106	case KBDC_IVAR_VENDORID:
107		ivar->vendorid = (u_int32_t)val;
108		break;
109	case KBDC_IVAR_SERIAL:
110		ivar->serial = (u_int32_t)val;
111		break;
112	case KBDC_IVAR_LOGICALID:
113		ivar->logicalid = (u_int32_t)val;
114		break;
115	case KBDC_IVAR_COMPATID:
116		ivar->compatid = (u_int32_t)val;
117		break;
118	default:
119		return ENOENT;
120	}
121	return 0;
122}
123
124struct resource_list
125*atkbdc_get_resource_list(device_t bus, device_t dev)
126{
127	atkbdc_device_t *ivar;
128
129	ivar = (atkbdc_device_t *)device_get_ivars(dev);
130	return &ivar->resources;
131}
132