pwmc.c (0af7a9a45179bc98c1f62c21c5272d7cae74e9ed) pwmc.c (b43e2c8b56b9f494a962c82572e0306ac06ad8d7)
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

--- 15 unchanged lines hidden (view full) ---

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
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

--- 15 unchanged lines hidden (view full) ---

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
32#include <sys/param.h>
33#include <sys/systm.h>
34#include <sys/bus.h>
35#include <sys/conf.h>
36#include <sys/kernel.h>
37#include <sys/module.h>
38#include <sys/time.h>
39
40#include <dev/pwm/pwmbus.h>
41#include <dev/pwm/pwmc.h>
42
43#include "pwmbus_if.h"
44
34#include <sys/param.h>
35#include <sys/systm.h>
36#include <sys/bus.h>
37#include <sys/conf.h>
38#include <sys/kernel.h>
39#include <sys/module.h>
40#include <sys/time.h>
41
42#include <dev/pwm/pwmbus.h>
43#include <dev/pwm/pwmc.h>
44
45#include "pwmbus_if.h"
46
47#ifdef FDT
48#include <dev/ofw/openfirm.h>
49#include <dev/ofw/ofw_bus.h>
50#include <dev/ofw/ofw_bus_subr.h>
51
52static struct ofw_compat_data compat_data[] = {
53 {"freebsd,pwmc", true},
54 {NULL, false},
55};
56
57PWMBUS_FDT_PNP_INFO(compat_data);
58
59#endif
60
45struct pwmc_softc {
46 device_t dev;
47 struct cdev *cdev;
48 u_int chan;
49};
50
51static int
52pwm_ioctl(struct cdev *dev, u_long cmd, caddr_t data,

--- 40 unchanged lines hidden (view full) ---

93}
94
95static struct cdevsw pwm_cdevsw = {
96 .d_version = D_VERSION,
97 .d_name = "pwmc",
98 .d_ioctl = pwm_ioctl
99};
100
61struct pwmc_softc {
62 device_t dev;
63 struct cdev *cdev;
64 u_int chan;
65};
66
67static int
68pwm_ioctl(struct cdev *dev, u_long cmd, caddr_t data,

--- 40 unchanged lines hidden (view full) ---

109}
110
111static struct cdevsw pwm_cdevsw = {
112 .d_version = D_VERSION,
113 .d_name = "pwmc",
114 .d_ioctl = pwm_ioctl
115};
116
117#ifdef FDT
118
119static void
120pwmc_setup_label(struct pwmc_softc *sc)
121{
122 void *label;
123
124 if (OF_getprop_alloc(ofw_bus_get_node(sc->dev), "label", &label) > 0) {
125 make_dev_alias(sc->cdev, "pwm/%s", (char *)label);
126 OF_prop_free(label);
127 }
128}
129
130#else /* FDT */
131
132static void
133pwmc_setup_label(struct pwmc_softc *sc)
134{
135 char *label;
136
137 if (resource_string_value(device_get_name(sc->dev),
138 device_get_unit(sc->dev), "label", &label) == 0) {
139 make_dev_alias(sc->cdev, "pwm/%s", label);
140 }
141}
142
143#endif /* FDT */
144
101static int
102pwmc_probe(device_t dev)
103{
145static int
146pwmc_probe(device_t dev)
147{
148 int rv;
104
149
150 rv = BUS_PROBE_NOWILDCARD;
151
152#ifdef FDT
153 if (!ofw_bus_status_okay(dev))
154 return (ENXIO);
155
156 if (ofw_bus_search_compatible(dev, compat_data)->ocd_data != 0) {
157 rv = BUS_PROBE_DEFAULT;
158 }
159#endif
160
105 device_set_desc(dev, "PWM Control");
161 device_set_desc(dev, "PWM Control");
106 return (BUS_PROBE_NOWILDCARD);
162 return (rv);
107}
108
109static int
110pwmc_attach(device_t dev)
111{
112 struct pwmc_softc *sc;
113 struct make_dev_args args;
163}
164
165static int
166pwmc_attach(device_t dev)
167{
168 struct pwmc_softc *sc;
169 struct make_dev_args args;
114 const char *label;
115 int error;
116
117 sc = device_get_softc(dev);
118 sc->dev = dev;
119
120 if ((error = pwmbus_get_channel(dev, &sc->chan)) != 0)
121 return (error);
122

--- 6 unchanged lines hidden (view full) ---

129 args.mda_si_drv1 = sc;
130 error = make_dev_s(&args, &sc->cdev, "pwmc%d.%d",
131 device_get_unit(device_get_parent(dev)), sc->chan);
132 if (error != 0) {
133 device_printf(dev, "Failed to make PWM device\n");
134 return (error);
135 }
136
170 int error;
171
172 sc = device_get_softc(dev);
173 sc->dev = dev;
174
175 if ((error = pwmbus_get_channel(dev, &sc->chan)) != 0)
176 return (error);
177

--- 6 unchanged lines hidden (view full) ---

184 args.mda_si_drv1 = sc;
185 error = make_dev_s(&args, &sc->cdev, "pwmc%d.%d",
186 device_get_unit(device_get_parent(dev)), sc->chan);
187 if (error != 0) {
188 device_printf(dev, "Failed to make PWM device\n");
189 return (error);
190 }
191
137 /* If there is a label hint, create an alias with that name. */
138 if (resource_string_value(device_get_name(dev), device_get_unit(dev),
139 "label", &label) == 0) {
140 make_dev_alias(sc->cdev, "pwm/%s", label);
141 }
192 pwmc_setup_label(sc);
142
143 return (0);
144}
145
146static int
147pwmc_detach(device_t dev)
148{
149 struct pwmc_softc *sc;

--- 26 unchanged lines hidden ---
193
194 return (0);
195}
196
197static int
198pwmc_detach(device_t dev)
199{
200 struct pwmc_softc *sc;

--- 26 unchanged lines hidden ---