bhnd_sprom_chipc.c revision 300548
1/*-
2 * Copyright (c) 2015-2016 Landon Fuller <landon@landonf.org>
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 *    notice, this list of conditions and the following disclaimer,
10 *    without modification.
11 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12 *    similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
13 *    redistribution must be conditioned upon including a substantially
14 *    similar Disclaimer requirement for further binary redistribution.
15 *
16 * NO WARRANTY
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
20 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
22 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27 * THE POSSIBILITY OF SUCH DAMAGES.
28 */
29
30#include <sys/cdefs.h>
31__FBSDID("$FreeBSD: head/sys/dev/bhnd/cores/chipc/bhnd_sprom_chipc.c 300548 2016-05-24 01:12:19Z adrian $");
32
33/*
34 * ChipCommon SPROM driver.
35 */
36
37#include <sys/param.h>
38#include <sys/kernel.h>
39#include <sys/bus.h>
40#include <sys/limits.h>
41#include <sys/malloc.h>
42#include <sys/module.h>
43#include <sys/systm.h>
44
45#include <dev/bhnd/bhnd.h>
46#include <dev/bhnd/nvram/bhnd_nvram.h>
47#include <dev/bhnd/nvram/bhnd_spromvar.h>
48
49#include "bhnd_chipc_if.h"
50#include "bhnd_nvram_if.h"
51
52static int
53chipc_sprom_probe(device_t dev)
54{
55	device_t	chipc;
56	int		error;
57
58	chipc = device_get_parent(dev);
59
60	/* Only match on SPROM devices */
61	if (BHND_CHIPC_NVRAM_SRC(chipc) != BHND_NVRAM_SRC_SPROM)
62		return (ENXIO);
63
64	/* Defer to default driver implementation */
65	if ((error = bhnd_sprom_probe(dev)) > 0)
66		return (error);
67
68	return (BUS_PROBE_NOWILDCARD);
69}
70
71static int
72chipc_sprom_attach(device_t dev)
73{
74	device_t	chipc;
75	int		error;
76
77	/* Request that ChipCommon enable access to SPROM hardware before
78	 * delegating attachment (and SPROM parsing) to the common driver */
79	chipc = device_get_parent(dev);
80	if ((error = BHND_CHIPC_ENABLE_SPROM(chipc)))
81		return (error);
82
83	error = bhnd_sprom_attach(dev);
84	BHND_CHIPC_DISABLE_SPROM(chipc);
85	return (error);
86}
87
88static device_method_t chipc_sprom_methods[] = {
89	/* Device interface */
90	DEVMETHOD(device_probe,			chipc_sprom_probe),
91	DEVMETHOD(device_attach,		chipc_sprom_attach),
92	DEVMETHOD_END
93};
94
95DEFINE_CLASS_1(bhnd_nvram, chipc_sprom_driver, chipc_sprom_methods, sizeof(struct bhnd_sprom_softc), bhnd_sprom_driver);
96DRIVER_MODULE(bhnd_chipc_sprom, bhnd_chipc, chipc_sprom_driver, bhnd_nvram_devclass, NULL, NULL);
97
98MODULE_DEPEND(bhnd_chipc_sprom, bhnd, 1, 1, 1);
99MODULE_DEPEND(bhnd_chipc_sprom, bhnd_chipc, 1, 1, 1);
100MODULE_DEPEND(bhnd_chipc_sprom, bhnd_sprom, 1, 1, 1);
101MODULE_VERSION(bhnd_chipc_sprom, 1);
102