1301409Slandonf/*-
2301409Slandonf * Copyright (c) 2016 Michael Zhilin <mizhka@gmail.com>
3301409Slandonf * All rights reserved.
4301409Slandonf *
5301409Slandonf * Redistribution and use in source and binary forms, with or without
6301409Slandonf * modification, are permitted provided that the following conditions
7301409Slandonf * are met:
8301409Slandonf * 1. Redistributions of source code must retain the above copyright
9301409Slandonf *    notice, this list of conditions and the following disclaimer,
10301409Slandonf *    without modification.
11301409Slandonf * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12301409Slandonf *    similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
13301409Slandonf *    redistribution must be conditioned upon including a substantially
14301409Slandonf *    similar Disclaimer requirement for further binary redistribution.
15301409Slandonf *
16301409Slandonf * NO WARRANTY
17301409Slandonf * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18301409Slandonf * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19301409Slandonf * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
20301409Slandonf * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21301409Slandonf * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
22301409Slandonf * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23301409Slandonf * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24301409Slandonf * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25301409Slandonf * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26301409Slandonf * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27301409Slandonf * THE POSSIBILITY OF SUCH DAMAGES.
28301409Slandonf */
29301409Slandonf
30301409Slandonf#include <sys/cdefs.h>
31301409Slandonf__FBSDID("$FreeBSD$");
32301409Slandonf
33301409Slandonf#include <sys/param.h>
34301409Slandonf#include <sys/systm.h>
35301409Slandonf#include <sys/kernel.h>
36301409Slandonf#include <sys/module.h>
37301409Slandonf#include <sys/bus.h>
38301409Slandonf#include <sys/rman.h>
39301409Slandonf#include <sys/conf.h>
40301409Slandonf
41301409Slandonf#include <machine/bus.h>
42301409Slandonf
43301409Slandonf#include <dev/cfi/cfi_var.h>
44301409Slandonf
45301409Slandonf#include "bhnd_chipc_if.h"
46302189Slandonf
47301409Slandonf#include "chipcreg.h"
48301409Slandonf#include "chipcvar.h"
49302189Slandonf#include "chipc_slicer.h"
50301409Slandonf
51301409Slandonfstatic int
52301409Slandonfchipc_cfi_probe(device_t dev)
53301409Slandonf{
54302189Slandonf	struct cfi_softc	*sc;
55301409Slandonf	int			error;
56301409Slandonf
57301409Slandonf	sc = device_get_softc(dev);
58301409Slandonf
59302189Slandonf	sc->sc_width = 0;
60302189Slandonf	if ((error = cfi_probe(dev)) > 0)
61302189Slandonf		return (error);
62301409Slandonf
63302189Slandonf	device_set_desc(dev, "Broadcom ChipCommon CFI");
64301409Slandonf	return (error);
65301409Slandonf}
66301409Slandonf
67301409Slandonfstatic int
68301409Slandonfchipc_cfi_attach(device_t dev)
69301409Slandonf{
70302189Slandonf	chipc_register_slicer(CHIPC_PFLASH_CFI);
71302189Slandonf	return (cfi_attach(dev));
72301409Slandonf}
73301409Slandonf
74301409Slandonfstatic device_method_t chipc_cfi_methods[] = {
75301409Slandonf	/* device interface */
76301409Slandonf	DEVMETHOD(device_probe,		chipc_cfi_probe),
77301409Slandonf	DEVMETHOD(device_attach,	chipc_cfi_attach),
78301409Slandonf	DEVMETHOD(device_detach,	cfi_detach),
79301409Slandonf
80301409Slandonf	{0, 0}
81301409Slandonf};
82301409Slandonf
83301409Slandonfstatic driver_t chipc_cfi_driver = {
84301409Slandonf	cfi_driver_name,
85301409Slandonf	chipc_cfi_methods,
86301409Slandonf	sizeof(struct cfi_softc),
87301409Slandonf};
88301409Slandonf
89301409SlandonfDRIVER_MODULE(cfi, bhnd_chipc, chipc_cfi_driver, cfi_devclass, 0, 0);
90