From owner-svn-src-stable-11@freebsd.org Tue Sep 3 14:07:20 2019 Return-Path: Delivered-To: svn-src-stable-11@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id B7DA4DD7D4; Tue, 3 Sep 2019 14:07:16 +0000 (UTC) (envelope-from yuripv@freebsd.org) Received: from freefall.freebsd.org (freefall.freebsd.org [96.47.72.132]) (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 "freefall.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 46N80M5jRrz4QR5; Tue, 3 Sep 2019 14:07:15 +0000 (UTC) (envelope-from yuripv@freebsd.org) Received: by freefall.freebsd.org (Postfix, from userid 1452) id 67F811B3A1; Tue, 3 Sep 2019 14:06:34 +0000 (UTC) X-Original-To: yuripv@localmail.freebsd.org Delivered-To: yuripv@localmail.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [96.47.72.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client CN "mx1.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by freefall.freebsd.org (Postfix) with ESMTPS id A01586BFE; Mon, 22 Apr 2019 03:52:16 +0000 (UTC) (envelope-from owner-src-committers@freebsd.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2610:1c1:1:6074::16:84]) (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 "freefall.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4FBCF6F663; Mon, 22 Apr 2019 03:52:16 +0000 (UTC) (envelope-from owner-src-committers@freebsd.org) Received: by freefall.freebsd.org (Postfix, from userid 538) id 367366BFD; Mon, 22 Apr 2019 03:52:16 +0000 (UTC) Delivered-To: src-committers@localmail.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [96.47.72.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client CN "mx1.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by freefall.freebsd.org (Postfix) with ESMTPS id 853FC6BFB for ; Mon, 22 Apr 2019 03:52:13 +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 2DDFA6F65A; Mon, 22 Apr 2019 03:52:13 +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 E42BA7616; Mon, 22 Apr 2019 03:52:12 +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 x3M3qC7Y099058; Mon, 22 Apr 2019 03:52:12 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3M3qCoD099052; Mon, 22 Apr 2019 03:52:12 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201904220352.x3M3qCoD099052@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r346517 - in stable/11/sys: conf dev/spibus X-SVN-Group: stable-11 X-SVN-Commit-Author: ian X-SVN-Commit-Paths: in stable/11/sys: conf dev/spibus X-SVN-Commit-Revision: 346517 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk X-Loop: FreeBSD.org Sender: owner-src-committers@freebsd.org X-Rspamd-Queue-Id: 4FBCF6F663 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.98 / 15.00]; local_wl_from(0.00)[freebsd.org]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.98)[-0.978,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] Status: O X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.29 List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Date: Tue, 03 Sep 2019 14:07:20 -0000 X-Original-Date: Mon, 22 Apr 2019 03:52:11 +0000 (UTC) X-List-Received-Date: Tue, 03 Sep 2019 14:07:20 -0000 Author: ian Date: Mon Apr 22 03:52:11 2019 New Revision: 346517 URL: https://svnweb.freebsd.org/changeset/base/346517 Log: MFC r335506 r335506: Incorporate bus and chip select numbers into spigen(4) cdev names. Rather than assigning spigen device names in order of creation, this uses a device name that corresponds to the owning spibus and chip-select index. Example: /dev/spigen0.1 would be a child of spibus0, and use cs = 1 The intent is for systems like Raspberry Pi to have a consistent way of using an SPI interface with a specific cs value from a user application. Otherwise, there is no consistent way of knowing which cs pin will be assigned to a particular spigen device. The alternative is to specify everything in "the right order" in an overlay file, which is less than ideal. Additionally, this duplicates (to some extent) the way Linux handles a similar situation with their 'spidev' device, so it would be somewhat familiar to those who also use Linux. A new kernel config option, SPIGEN_LEGACY_CDEVNAME, causes the driver to also create /dev/spigenN device name aliases, with N incrementing in the order of device instantiation. This is provided to ease the transition for existing systems using the original naming convention (particularly when these changes are MFC'd to stable branches). Differential Revision: https://reviews.freebsd.org/D15301 Modified: stable/11/sys/conf/NOTES stable/11/sys/conf/options stable/11/sys/dev/spibus/spibus.c stable/11/sys/dev/spibus/spigen.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/conf/NOTES ============================================================================== --- stable/11/sys/conf/NOTES Mon Apr 22 03:25:49 2019 (r346516) +++ stable/11/sys/conf/NOTES Mon Apr 22 03:52:11 2019 (r346517) @@ -3074,4 +3074,7 @@ options EVDEV_DEBUG # enable event debug msgs device uinput # install /dev/uinput cdev options UINPUT_DEBUG # enable uinput debug msgs +# Enable legacy /dev/spigenN name aliases for /dev/spigenX.Y devices. +options SPIGEN_LEGACY_CDEVNAME # legacy device names for spigen + device xz # xz_embedded LZMA de-compression library Modified: stable/11/sys/conf/options ============================================================================== --- stable/11/sys/conf/options Mon Apr 22 03:25:49 2019 (r346516) +++ stable/11/sys/conf/options Mon Apr 22 03:52:11 2019 (r346517) @@ -992,6 +992,9 @@ BHND_LOGLEVEL opt_global.h # GPIO and child devices GPIO_SPI_DEBUG opt_gpio.h +# SPI devices +SPIGEN_LEGACY_CDEVNAME opt_spi.h + # etherswitch(4) driver RTL8366_SOFT_RESET opt_etherswitch.h Modified: stable/11/sys/dev/spibus/spibus.c ============================================================================== --- stable/11/sys/dev/spibus/spibus.c Mon Apr 22 03:25:49 2019 (r346516) +++ stable/11/sys/dev/spibus/spibus.c Mon Apr 22 03:52:11 2019 (r346517) @@ -122,8 +122,10 @@ spibus_child_location_str(device_t bus, device_t child size_t buflen) { struct spibus_ivar *devi = SPIBUS_IVAR(child); + int cs; - snprintf(buf, buflen, "cs=%d", devi->cs); + cs = devi->cs & ~SPIBUS_CS_HIGH; /* trim 'cs high' bit */ + snprintf(buf, buflen, "bus=%d cs=%d", device_get_unit(bus), cs); return (0); } Modified: stable/11/sys/dev/spibus/spigen.c ============================================================================== --- stable/11/sys/dev/spibus/spigen.c Mon Apr 22 03:25:49 2019 (r346516) +++ stable/11/sys/dev/spibus/spigen.c Mon Apr 22 03:52:11 2019 (r346517) @@ -26,6 +26,7 @@ __FBSDID("$FreeBSD$"); #include "opt_platform.h" +#include "opt_spi.h" #include #include @@ -64,6 +65,9 @@ __FBSDID("$FreeBSD$"); struct spigen_softc { device_t sc_dev; struct cdev *sc_cdev; +#ifdef SPIGEN_LEGACY_CDEVNAME + struct cdev *sc_adev; /* alias device */ +#endif struct mtx sc_mtx; uint32_t sc_command_length_max; /* cannot change while mmapped */ uint32_t sc_data_length_max; /* cannot change while mmapped */ @@ -186,15 +190,46 @@ spigen_attach(device_t dev) { struct spigen_softc *sc; const int unit = device_get_unit(dev); + int cs, res; + struct make_dev_args mda; + spibus_get_cs(dev, &cs); + cs &= ~SPIBUS_CS_HIGH; /* trim 'cs high' bit */ + sc = device_get_softc(dev); sc->sc_dev = dev; - sc->sc_cdev = make_dev(&spigen_cdevsw, unit, - UID_ROOT, GID_OPERATOR, 0660, "spigen%d", unit); - sc->sc_cdev->si_drv1 = dev; sc->sc_command_length_max = PAGE_SIZE; sc->sc_data_length_max = PAGE_SIZE; + mtx_init(&sc->sc_mtx, device_get_nameunit(dev), NULL, MTX_DEF); + + make_dev_args_init(&mda); + mda.mda_flags = MAKEDEV_WAITOK; + mda.mda_devsw = &spigen_cdevsw; + mda.mda_cr = NULL; + mda.mda_uid = UID_ROOT; + mda.mda_gid = GID_OPERATOR; + mda.mda_mode = 0660; + mda.mda_unit = unit; + mda.mda_si_drv1 = dev; + + res = make_dev_s(&mda, &(sc->sc_cdev), "spigen%d.%d", + device_get_unit(device_get_parent(dev)), cs); + if (res) { + return res; + } + +#ifdef SPIGEN_LEGACY_CDEVNAME + res = make_dev_alias_p(0, &sc->sc_adev, sc->sc_cdev, "spigen%d", unit); + if (res) { + if (sc->sc_cdev) { + destroy_dev(sc->sc_cdev); + sc->sc_cdev = NULL; + } + return res; + } +#endif + spigen_sysctl_init(sc); return (0); @@ -429,8 +464,13 @@ spigen_detach(device_t dev) mtx_destroy(&sc->sc_mtx); - if (sc->sc_cdev) - destroy_dev(sc->sc_cdev); +#ifdef SPIGEN_LEGACY_CDEVNAME + if (sc->sc_adev) + destroy_dev(sc->sc_adev); +#endif + + if (sc->sc_cdev) + destroy_dev(sc->sc_cdev); return (0); }