]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/pwm/pwmbus.c
Remove pwmbus_attach_bus(), it no longer has any callers. Also remove a
[FreeBSD/FreeBSD.git] / sys / dev / pwm / pwmbus.c
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2018 Emmanuel Vadot <manu@FreeBSD.org>
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.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
31
32 #include "opt_platform.h"
33
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/bus.h>
37 #include <sys/conf.h>
38 #include <sys/endian.h>
39 #include <sys/kernel.h>
40 #include <sys/module.h>
41
42 #include <machine/bus.h>
43
44 #include <dev/ofw/ofw_bus.h>
45 #include <dev/ofw/ofw_bus_subr.h>
46
47 #include <dev/pwm/pwmbus.h>
48
49 #include "pwmbus_if.h"
50 #include "pwm_if.h"
51
52 struct pwmbus_channel_data {
53         int     reserved;
54         char    *name;
55 };
56
57 struct pwmbus_softc {
58         device_t        busdev;
59         device_t        dev;
60
61         int             nchannels;
62 };
63
64 static int
65 pwmbus_probe(device_t dev)
66 {
67
68         device_set_desc(dev, "PWM bus");
69         return (BUS_PROBE_GENERIC);
70 }
71
72 static int
73 pwmbus_attach(device_t dev)
74 {
75         struct pwmbus_softc *sc;
76
77         sc = device_get_softc(dev);
78         sc->busdev = dev;
79         sc->dev = device_get_parent(dev);
80
81         if (PWM_CHANNEL_MAX(sc->dev, &sc->nchannels) != 0 ||
82             sc->nchannels == 0)
83                 return (ENXIO);
84
85         if (bootverbose)
86                 device_printf(dev, "Registering %d channel(s)\n", sc->nchannels);
87         bus_generic_probe(dev);
88
89         return (bus_generic_attach(dev));
90 }
91
92 static int
93 pwmbus_detach(device_t dev)
94 {
95         device_t *devlist;
96         int i, rv, ndevs;
97
98         rv = bus_generic_detach(dev);
99         if (rv != 0)
100                 return (rv);
101
102         rv = device_get_children(dev, &devlist, &ndevs);
103         if (rv != 0)
104                 return (rv);
105         for (i = 0; i < ndevs; i++)
106                 device_delete_child(dev, devlist[i]);
107
108         return (0);
109 }
110
111 static int
112 pwmbus_channel_config(device_t bus, int channel, unsigned int period, unsigned int duty)
113 {
114         struct pwmbus_softc *sc;
115
116         sc = device_get_softc(bus);
117
118         if (channel > sc->nchannels)
119                 return (EINVAL);
120
121         return (PWM_CHANNEL_CONFIG(sc->dev, channel, period, duty));
122 }
123
124 static int
125 pwmbus_channel_get_config(device_t bus, int channel, unsigned int *period, unsigned int *duty)
126 {
127         struct pwmbus_softc *sc;
128
129         sc = device_get_softc(bus);
130
131         if (channel > sc->nchannels)
132                 return (EINVAL);
133
134         return (PWM_CHANNEL_GET_CONFIG(sc->dev, channel, period, duty));
135 }
136
137 static int
138 pwmbus_channel_set_flags(device_t bus, int channel, uint32_t flags)
139 {
140         struct pwmbus_softc *sc;
141
142         sc = device_get_softc(bus);
143
144         if (channel > sc->nchannels)
145                 return (EINVAL);
146
147         return (PWM_CHANNEL_SET_FLAGS(sc->dev, channel, flags));
148 }
149
150 static int
151 pwmbus_channel_get_flags(device_t bus, int channel, uint32_t *flags)
152 {
153         struct pwmbus_softc *sc;
154
155         sc = device_get_softc(bus);
156
157         if (channel > sc->nchannels)
158                 return (EINVAL);
159
160         return (PWM_CHANNEL_GET_FLAGS(sc->dev, channel, flags));
161 }
162
163 static int
164 pwmbus_channel_enable(device_t bus, int channel, bool enable)
165 {
166         struct pwmbus_softc *sc;
167
168         sc = device_get_softc(bus);
169
170         if (channel > sc->nchannels)
171                 return (EINVAL);
172
173         return (PWM_CHANNEL_ENABLE(sc->dev, channel, enable));
174 }
175
176 static int
177 pwmbus_channel_is_enabled(device_t bus, int channel, bool *enable)
178 {
179         struct pwmbus_softc *sc;
180
181         sc = device_get_softc(bus);
182
183         if (channel > sc->nchannels)
184                 return (EINVAL);
185
186         return (PWM_CHANNEL_IS_ENABLED(sc->dev, channel, enable));
187 }
188
189 static device_method_t pwmbus_methods[] = {
190         /* device_if */
191         DEVMETHOD(device_probe, pwmbus_probe),
192         DEVMETHOD(device_attach, pwmbus_attach),
193         DEVMETHOD(device_detach, pwmbus_detach),
194
195         /* pwm interface */
196         DEVMETHOD(pwmbus_channel_config, pwmbus_channel_config),
197         DEVMETHOD(pwmbus_channel_get_config, pwmbus_channel_get_config),
198         DEVMETHOD(pwmbus_channel_set_flags, pwmbus_channel_set_flags),
199         DEVMETHOD(pwmbus_channel_get_flags, pwmbus_channel_get_flags),
200         DEVMETHOD(pwmbus_channel_enable, pwmbus_channel_enable),
201         DEVMETHOD(pwmbus_channel_is_enabled, pwmbus_channel_is_enabled),
202
203         DEVMETHOD_END
204 };
205
206 driver_t pwmbus_driver = {
207         "pwmbus",
208         pwmbus_methods,
209         sizeof(struct pwmbus_softc),
210 };
211 devclass_t pwmbus_devclass;
212
213 EARLY_DRIVER_MODULE(pwmbus, pwm, pwmbus_driver, pwmbus_devclass, 0, 0,
214   BUS_PASS_SUPPORTDEV + BUS_PASS_ORDER_MIDDLE);
215 MODULE_VERSION(pwmbus, 1);