uart_bus_pccard.c revision 302408
1227064Sbz/*-
2250340Sdavidcs * Copyright (c) 2001 M. Warner Losh.  All rights reserved.
3227064Sbz * Copyright (c) 2003 Norikatsu Shigemura, Takenori Watanabe All rights reserved.
4227064Sbz *
5227064Sbz * Redistribution and use in source and binary forms, with or without
6227064Sbz * modification, are permitted provided that the following conditions
7227064Sbz * are met:
8227064Sbz * 1. Redistributions of source code must retain the above copyright
9227064Sbz *    notice, this list of conditions and the following disclaimer.
10227064Sbz * 2. Redistributions in binary form must reproduce the above copyright
11227064Sbz *    notice, this list of conditions and the following disclaimer in the
12227064Sbz *    documentation and/or other materials provided with the distribution.
13227064Sbz *
14227064Sbz * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15227064Sbz * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16227064Sbz * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17227064Sbz * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18227064Sbz * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19227064Sbz * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20227064Sbz * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21227064Sbz * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22227064Sbz * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23227064Sbz * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24227064Sbz */
25227064Sbz
26227064Sbz#include <sys/cdefs.h>
27227064Sbz__FBSDID("$FreeBSD: stable/11/sys/dev/uart/uart_bus_pccard.c 292079 2015-12-11 05:27:56Z imp $");
28227064Sbz
29227064Sbz#include <sys/param.h>
30227064Sbz#include <sys/systm.h>
31227064Sbz#include <sys/bus.h>
32227064Sbz#include <sys/conf.h>
33227064Sbz#include <sys/kernel.h>
34227064Sbz#include <sys/module.h>
35227064Sbz#include <machine/bus.h>
36227064Sbz#include <machine/resource.h>
37227064Sbz
38227064Sbz#include <dev/pccard/pccard_cis.h>
39227064Sbz#include <dev/pccard/pccardvar.h>
40227064Sbz
41227064Sbz#include <dev/uart/uart.h>
42227064Sbz#include <dev/uart/uart_bus.h>
43227064Sbz
44227064Sbz#include "pccarddevs.h"
45227064Sbz
46227064Sbzstatic	int	uart_pccard_probe(device_t dev);
47227064Sbzstatic	int	uart_pccard_attach(device_t dev);
48227064Sbz
49227064Sbzstatic device_method_t uart_pccard_methods[] = {
50227064Sbz	/* Device interface */
51227064Sbz	DEVMETHOD(device_probe,		uart_pccard_probe),
52227064Sbz	DEVMETHOD(device_attach,	uart_pccard_attach),
53227064Sbz	DEVMETHOD(device_detach,	uart_bus_detach),
54227064Sbz
55227064Sbz	{ 0, 0 }
56227064Sbz};
57227064Sbz
58227064Sbzstatic uint32_t uart_pccard_function = PCCARD_FUNCTION_SERIAL;
59227064Sbz
60227064Sbzstatic driver_t uart_pccard_driver = {
61227064Sbz	uart_driver_name,
62227064Sbz	uart_pccard_methods,
63227064Sbz	sizeof(struct uart_softc),
64227064Sbz};
65227064Sbz
66227064Sbzstatic int
67227064Sbzuart_pccard_probe(device_t dev)
68227064Sbz{
69227064Sbz	int error;
70227064Sbz	uint32_t fcn;
71227064Sbz
72227064Sbz	fcn = PCCARD_FUNCTION_UNSPEC;
73227064Sbz	error = pccard_get_function(dev, &fcn);
74227064Sbz	if (error != 0)
75227064Sbz		return (error);
76227064Sbz	/*
77227064Sbz	 * If a serial card, we are likely the right driver.  However,
78227064Sbz	 * some serial cards are better serviced by other drivers, so
79227064Sbz	 * allow other drivers to claim it, if they want.
80227064Sbz	 */
81227064Sbz	if (fcn == uart_pccard_function)
82227064Sbz		return (BUS_PROBE_GENERIC);
83227064Sbz
84227064Sbz	return (ENXIO);
85227064Sbz}
86227064Sbz
87227064Sbzstatic int
88227064Sbzuart_pccard_attach(device_t dev)
89227064Sbz{
90227064Sbz	struct uart_softc *sc;
91227064Sbz	int error;
92227064Sbz
93227064Sbz	sc = device_get_softc(dev);
94227064Sbz	sc->sc_class = &uart_ns8250_class;
95227064Sbz
96227064Sbz	error = uart_bus_probe(dev, 0, 0, 0, 0);
97227064Sbz	if (error > 0)
98227064Sbz		return (error);
99227064Sbz	return (uart_bus_attach(dev));
100227064Sbz}
101227064Sbz
102227064SbzDRIVER_MODULE(uart, pccard, uart_pccard_driver, uart_devclass, 0, 0);
103227064SbzMODULE_PNP_INFO("U32:function_type;", pccard, uart, &uart_pccard_function,
104227064Sbz    sizeof(uart_pccard_function), 1);
105227064Sbz