From owner-svn-src-head@freebsd.org Sat Jun 15 22:25:41 2019 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 5656F15D1431; Sat, 15 Jun 2019 22:25:41 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id E9DFD8E664; Sat, 15 Jun 2019 22:25:40 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id C07065880; Sat, 15 Jun 2019 22:25:40 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x5FMPe24099891; Sat, 15 Jun 2019 22:25:40 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x5FMPd3v099885; Sat, 15 Jun 2019 22:25:39 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201906152225.x5FMPd3v099885@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Sat, 15 Jun 2019 22:25:39 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r349086 - in head/sys: arm/allwinner conf dev/pwm X-SVN-Group: head X-SVN-Commit-Author: ian X-SVN-Commit-Paths: in head/sys: arm/allwinner conf dev/pwm X-SVN-Commit-Revision: 349086 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: E9DFD8E664 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.97 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.97)[-0.972,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 15 Jun 2019 22:25:41 -0000 Author: ian Date: Sat Jun 15 22:25:39 2019 New Revision: 349086 URL: https://svnweb.freebsd.org/changeset/base/349086 Log: Restructure the pwm device hirearchy and interfaces. The pwm and pwmbus interfaces were nearly identical, this merges them into a single pwmbus interface. The pwmbus driver now implements the pwmbus interface by simply passing all calls through to its parent (the hardware driver). The channel_count method moves from pwm to pwmbus, and the get_bus method is deleted (just no longer needed). The net effect is that the interface for doing pwm stuff is now the same regardless of whether you're a child of pwmbus, or some random driver elsewhere in the hierarchy that is bypassing the pwmbus layer and is talking directly to the hardware driver via cross-hierarchy connections established using fdt data. The pwmc driver is now a child of pwmbus, instead of being its sibling (that's why the get_bus method is no longer needed; pwmc now gets the device_t of the bus using device_get_parent()). Deleted: head/sys/dev/pwm/pwm_if.m Modified: head/sys/arm/allwinner/aw_pwm.c head/sys/conf/files head/sys/dev/pwm/ofw_pwm.c head/sys/dev/pwm/pwmbus.c head/sys/dev/pwm/pwmbus.h head/sys/dev/pwm/pwmbus_if.m head/sys/dev/pwm/pwmc.c Modified: head/sys/arm/allwinner/aw_pwm.c ============================================================================== --- head/sys/arm/allwinner/aw_pwm.c Sat Jun 15 21:51:55 2019 (r349085) +++ head/sys/arm/allwinner/aw_pwm.c Sat Jun 15 22:25:39 2019 (r349086) @@ -46,7 +46,7 @@ __FBSDID("$FreeBSD$"); #include -#include "pwm_if.h" +#include "pwmbus_if.h" #define AW_PWM_CTRL 0x00 #define AW_PWM_CTRL_PRESCALE_MASK 0xF @@ -346,28 +346,18 @@ aw_pwm_channel_is_enabled(device_t dev, int channel, b return (0); } -static device_t -aw_pwm_get_bus(device_t dev) -{ - struct aw_pwm_softc *sc; - - sc = device_get_softc(dev); - - return (sc->busdev); -} static device_method_t aw_pwm_methods[] = { /* Device interface */ DEVMETHOD(device_probe, aw_pwm_probe), DEVMETHOD(device_attach, aw_pwm_attach), DEVMETHOD(device_detach, aw_pwm_detach), - /* pwm interface */ - DEVMETHOD(pwm_get_bus, aw_pwm_get_bus), - DEVMETHOD(pwm_channel_count, aw_pwm_channel_count), - DEVMETHOD(pwm_channel_config, aw_pwm_channel_config), - DEVMETHOD(pwm_channel_get_config, aw_pwm_channel_get_config), - DEVMETHOD(pwm_channel_enable, aw_pwm_channel_enable), - DEVMETHOD(pwm_channel_is_enabled, aw_pwm_channel_is_enabled), + /* pwmbus interface */ + DEVMETHOD(pwmbus_channel_count, aw_pwm_channel_count), + DEVMETHOD(pwmbus_channel_config, aw_pwm_channel_config), + DEVMETHOD(pwmbus_channel_get_config, aw_pwm_channel_get_config), + DEVMETHOD(pwmbus_channel_enable, aw_pwm_channel_enable), + DEVMETHOD(pwmbus_channel_is_enabled, aw_pwm_channel_is_enabled), DEVMETHOD_END }; Modified: head/sys/conf/files ============================================================================== --- head/sys/conf/files Sat Jun 15 21:51:55 2019 (r349085) +++ head/sys/conf/files Sat Jun 15 22:25:39 2019 (r349086) @@ -2702,7 +2702,6 @@ dev/puc/puc_pccard.c optional puc pccard dev/puc/puc_pci.c optional puc pci dev/pwm/pwmc.c optional pwm | pwmc dev/pwm/pwmbus.c optional pwm | pwmbus -dev/pwm/pwm_if.m optional pwm | pwmbus dev/pwm/pwmbus_if.m optional pwm | pwmbus dev/pwm/ofw_pwm.c optional pwm fdt | pwmbus fdt dev/quicc/quicc_core.c optional quicc Modified: head/sys/dev/pwm/ofw_pwm.c ============================================================================== --- head/sys/dev/pwm/ofw_pwm.c Sat Jun 15 21:51:55 2019 (r349085) +++ head/sys/dev/pwm/ofw_pwm.c Sat Jun 15 22:25:39 2019 (r349086) @@ -40,7 +40,7 @@ __FBSDID("$FreeBSD$"); #include -#include "pwm_if.h" +#include "pwmbus_if.h" int pwm_get_by_ofw_propidx(device_t consumer, phandle_t node, @@ -58,12 +58,6 @@ pwm_get_by_ofw_propidx(device_t consumer, phandle_t no channel.dev = OF_device_from_xref(xref); if (channel.dev == NULL) { - OF_prop_free(cells); - return (ENODEV); - } - - channel.busdev = PWM_GET_BUS(channel.dev); - if (channel.busdev == NULL) { OF_prop_free(cells); return (ENODEV); } Modified: head/sys/dev/pwm/pwmbus.c ============================================================================== --- head/sys/dev/pwm/pwmbus.c Sat Jun 15 21:51:55 2019 (r349085) +++ head/sys/dev/pwm/pwmbus.c Sat Jun 15 22:25:39 2019 (r349086) @@ -47,7 +47,6 @@ __FBSDID("$FreeBSD$"); #include #include "pwmbus_if.h" -#include "pwm_if.h" struct pwmbus_channel_data { int reserved; @@ -55,8 +54,8 @@ struct pwmbus_channel_data { }; struct pwmbus_softc { - device_t busdev; device_t dev; + device_t parent; int nchannels; }; @@ -75,15 +74,18 @@ pwmbus_attach(device_t dev) struct pwmbus_softc *sc; sc = device_get_softc(dev); - sc->busdev = dev; - sc->dev = device_get_parent(dev); + sc->dev = dev; + sc->parent = device_get_parent(dev); - if (PWM_CHANNEL_COUNT(sc->dev, &sc->nchannels) != 0 || - sc->nchannels == 0) + if (PWMBUS_CHANNEL_COUNT(sc->parent, &sc->nchannels) != 0 || + sc->nchannels == 0) { + device_printf(sc->dev, "No channels on parent %s\n", + device_get_nameunit(sc->parent)); return (ENXIO); + } - if (bootverbose) - device_printf(dev, "Registering %d channel(s)\n", sc->nchannels); + device_add_child(sc->dev, "pwmc", -1); + bus_generic_probe(dev); return (bus_generic_attach(dev)); @@ -101,96 +103,61 @@ pwmbus_detach(device_t dev) } static int -pwmbus_channel_config(device_t bus, int chan, u_int period, u_int duty) +pwmbus_channel_config(device_t dev, int chan, u_int period, u_int duty) { - struct pwmbus_softc *sc; - - sc = device_get_softc(bus); - - if (chan > sc->nchannels) - return (EINVAL); - - return (PWM_CHANNEL_CONFIG(sc->dev, chan, period, duty)); + return (PWMBUS_CHANNEL_CONFIG(device_get_parent(dev), chan, period, duty)); } static int -pwmbus_channel_get_config(device_t bus, int chan, u_int *period, u_int *duty) +pwmbus_channel_get_config(device_t dev, int chan, u_int *period, u_int *duty) { - struct pwmbus_softc *sc; - - sc = device_get_softc(bus); - - if (chan > sc->nchannels) - return (EINVAL); - - return (PWM_CHANNEL_GET_CONFIG(sc->dev, chan, period, duty)); + return (PWMBUS_CHANNEL_GET_CONFIG(device_get_parent(dev), chan, period, duty)); } static int -pwmbus_channel_set_flags(device_t bus, int chan, uint32_t flags) +pwmbus_channel_get_flags(device_t dev, int chan, uint32_t *flags) { - struct pwmbus_softc *sc; - - sc = device_get_softc(bus); - - if (chan > sc->nchannels) - return (EINVAL); - - return (PWM_CHANNEL_SET_FLAGS(sc->dev, chan, flags)); + return (PWMBUS_CHANNEL_GET_FLAGS(device_get_parent(dev), chan, flags)); } static int -pwmbus_channel_get_flags(device_t bus, int chan, uint32_t *flags) +pwmbus_channel_enable(device_t dev, int chan, bool enable) { - struct pwmbus_softc *sc; - - sc = device_get_softc(bus); - - if (chan > sc->nchannels) - return (EINVAL); - - return (PWM_CHANNEL_GET_FLAGS(sc->dev, chan, flags)); + return (PWMBUS_CHANNEL_ENABLE(device_get_parent(dev), chan, enable)); } static int -pwmbus_channel_enable(device_t bus, int chan, bool enable) +pwmbus_channel_set_flags(device_t dev, int chan, uint32_t flags) { - struct pwmbus_softc *sc; - - sc = device_get_softc(bus); - - if (chan > sc->nchannels) - return (EINVAL); - - return (PWM_CHANNEL_ENABLE(sc->dev, chan, enable)); + return (PWMBUS_CHANNEL_SET_FLAGS(device_get_parent(dev), chan, flags)); } static int -pwmbus_channel_is_enabled(device_t bus, int chan, bool *enable) +pwmbus_channel_is_enabled(device_t dev, int chan, bool *enable) { - struct pwmbus_softc *sc; + return (PWMBUS_CHANNEL_IS_ENABLED(device_get_parent(dev), chan, enable)); +} - sc = device_get_softc(bus); - - if (chan > sc->nchannels) - return (EINVAL); - - return (PWM_CHANNEL_IS_ENABLED(sc->dev, chan, enable)); +static int +pwmbus_channel_count(device_t dev, int *nchannel) +{ + return (PWMBUS_CHANNEL_COUNT(device_get_parent(dev), nchannel)); } static device_method_t pwmbus_methods[] = { /* device_if */ - DEVMETHOD(device_probe, pwmbus_probe), + DEVMETHOD(device_probe, pwmbus_probe), DEVMETHOD(device_attach, pwmbus_attach), DEVMETHOD(device_detach, pwmbus_detach), - /* pwm interface */ - DEVMETHOD(pwmbus_channel_config, pwmbus_channel_config), - DEVMETHOD(pwmbus_channel_get_config, pwmbus_channel_get_config), - DEVMETHOD(pwmbus_channel_set_flags, pwmbus_channel_set_flags), - DEVMETHOD(pwmbus_channel_get_flags, pwmbus_channel_get_flags), - DEVMETHOD(pwmbus_channel_enable, pwmbus_channel_enable), - DEVMETHOD(pwmbus_channel_is_enabled, pwmbus_channel_is_enabled), + /* pwmbus_if */ + DEVMETHOD(pwmbus_channel_count, pwmbus_channel_count), + DEVMETHOD(pwmbus_channel_config, pwmbus_channel_config), + DEVMETHOD(pwmbus_channel_get_config, pwmbus_channel_get_config), + DEVMETHOD(pwmbus_channel_set_flags, pwmbus_channel_set_flags), + DEVMETHOD(pwmbus_channel_get_flags, pwmbus_channel_get_flags), + DEVMETHOD(pwmbus_channel_enable, pwmbus_channel_enable), + DEVMETHOD(pwmbus_channel_is_enabled, pwmbus_channel_is_enabled), DEVMETHOD_END }; Modified: head/sys/dev/pwm/pwmbus.h ============================================================================== --- head/sys/dev/pwm/pwmbus.h Sat Jun 15 21:51:55 2019 (r349085) +++ head/sys/dev/pwm/pwmbus.h Sat Jun 15 22:25:39 2019 (r349086) @@ -34,7 +34,6 @@ struct pwm_channel { device_t dev; - device_t busdev; int channel; uint64_t period; uint64_t duty; Modified: head/sys/dev/pwm/pwmbus_if.m ============================================================================== --- head/sys/dev/pwm/pwmbus_if.m Sat Jun 15 21:51:55 2019 (r349085) +++ head/sys/dev/pwm/pwmbus_if.m Sat Jun 15 22:25:39 2019 (r349086) @@ -105,3 +105,11 @@ METHOD int channel_is_enabled { int channel; bool *enabled; }; + +# +# Get the number of channels +# +METHOD int channel_count { + device_t bus; + int *nchannel; +}; Modified: head/sys/dev/pwm/pwmc.c ============================================================================== --- head/sys/dev/pwm/pwmc.c Sat Jun 15 21:51:55 2019 (r349085) +++ head/sys/dev/pwm/pwmc.c Sat Jun 15 22:25:39 2019 (r349086) @@ -40,11 +40,9 @@ __FBSDID("$FreeBSD$"); #include #include "pwmbus_if.h" -#include "pwm_if.h" struct pwmc_softc { device_t dev; - device_t pdev; struct cdev *pwm_dev; char name[32]; }; @@ -60,14 +58,12 @@ pwm_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int rv = 0; sc = dev->si_drv1; - bus = PWM_GET_BUS(sc->pdev); - if (bus == NULL) - return (EINVAL); + bus = device_get_parent(sc->dev); switch (cmd) { case PWMMAXCHANNEL: nchannel = -1; - rv = PWM_CHANNEL_COUNT(sc->pdev, &nchannel); + rv = PWMBUS_CHANNEL_COUNT(bus, &nchannel); bcopy(&nchannel, data, sizeof(nchannel)); break; case PWMSETSTATE: @@ -106,7 +102,7 @@ pwmc_probe(device_t dev) { device_set_desc(dev, "PWM Controller"); - return (0); + return (BUS_PROBE_NOWILDCARD); } static int @@ -117,7 +113,6 @@ pwmc_attach(device_t dev) sc = device_get_softc(dev); sc->dev = dev; - sc->pdev = device_get_parent(dev); snprintf(sc->name, sizeof(sc->name), "pwmc%d", device_get_unit(dev)); make_dev_args_init(&args); @@ -161,5 +156,6 @@ static driver_t pwmc_driver = { }; static devclass_t pwmc_devclass; -DRIVER_MODULE(pwmc, pwm, pwmc_driver, pwmc_devclass, 0, 0); +DRIVER_MODULE(pwmc, pwmbus, pwmc_driver, pwmc_devclass, 0, 0); +MODULE_DEPEND(pwmc, pwmbus, 1, 1, 1); MODULE_VERSION(pwmc, 1);