mtk_pinctrl.c revision 297667
1/*-
2 * Copyright (c) 2016 Stanislav Galabov
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, immediately at the beginning of the file.
11 * 2. The name of the author may not be used to endorse or promote products
12 *    derived from this software without specific prior written permission.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
18 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 */
27
28#include <sys/cdefs.h>
29__FBSDID("$FreeBSD: head/sys/mips/mediatek/mtk_pinctrl.c 297667 2016-04-07 11:08:50Z sgalabov $");
30
31#include <sys/param.h>
32#include <sys/kernel.h>
33#include <sys/bus.h>
34#include <sys/module.h>
35
36#include <dev/fdt/fdt_common.h>
37#include <dev/ofw/openfirm.h>
38#include <dev/ofw/ofw_bus.h>
39#include <dev/ofw/ofw_bus_subr.h>
40
41#include <dev/fdt/fdt_pinctrl.h>
42#include <mips/mediatek/mtk_sysctl.h>
43
44#include "fdt_pinctrl_if.h"
45
46static const struct ofw_compat_data compat_data[] = {
47	{ "ralink,rt2880-pinctrl",	1 },
48
49	/* Sentinel */
50	{ NULL,				0 }
51};
52
53static int
54mtk_pinctrl_probe(device_t dev)
55{
56
57	if (!ofw_bus_status_okay(dev))
58		return (ENXIO);
59
60	if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0)
61		return (ENXIO);
62
63	device_set_desc(dev, "MTK Pin Controller");
64
65	return (0);
66}
67
68static int
69mtk_pinctrl_attach(device_t dev)
70{
71
72	if (device_get_unit(dev) != 0) {
73		device_printf(dev, "Only one pin control allowed\n");
74		return (ENXIO);
75	}
76
77	fdt_pinctrl_register(dev, "pinctrl-single,bits");
78	fdt_pinctrl_configure_tree(dev);
79
80	if (bootverbose)
81		device_printf(dev, "GPIO mode: 0x%08x\n",
82		    mtk_sysctl_get(SYSCTL_GPIOMODE));
83
84	return (0);
85}
86
87static int
88mtk_pinctrl_configure(device_t dev, phandle_t cfgxref)
89{
90
91	return (EINVAL);
92}
93
94static device_method_t mtk_pinctrl_methods[] = {
95	DEVMETHOD(device_probe,			mtk_pinctrl_probe),
96	DEVMETHOD(device_attach,		mtk_pinctrl_attach),
97
98	/* fdt_pinctrl interface */
99	DEVMETHOD(fdt_pinctrl_configure,	mtk_pinctrl_configure),
100
101	DEVMETHOD_END
102};
103
104static driver_t mtk_pinctrl_driver = {
105	"pinctrl",
106	mtk_pinctrl_methods,
107	0,
108};
109static devclass_t mtk_pinctrl_devclass;
110
111EARLY_DRIVER_MODULE(mtk_pinctrl, simplebus, mtk_pinctrl_driver,
112    mtk_pinctrl_devclass, 0, 0, BUS_PASS_INTERRUPT + BUS_PASS_ORDER_EARLY);
113
114MODULE_DEPEND(mtk_pinctrl, mtk_sysctl, 1, 1, 1);
115