Date: Thu, 20 Oct 2016 11:26:51 +0000 (UTC) From: Wojciech Macek <wma@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r307669 - in head/sys: arm/annapurna/alpine boot/fdt/dts/arm conf Message-ID: <201610201126.u9KBQpX7069210@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: wma Date: Thu Oct 20 11:26:51 2016 New Revision: 307669 URL: https://svnweb.freebsd.org/changeset/base/307669 Log: Support for Alpine Serializer/Deserializer. The exported functions will be used by Alpine Ethernet driver. Obtained from: Semihalf Submitted by: Michal Stanek <mst@semihalf.com> Sponsored by: Annapurna Labs Reviewed by: wma Differential Revision: https://reviews.freebsd.org/D7763 Added: head/sys/arm/annapurna/alpine/alpine_serdes.c (contents, props changed) head/sys/arm/annapurna/alpine/alpine_serdes.h (contents, props changed) Modified: head/sys/boot/fdt/dts/arm/annapurna-alpine.dts head/sys/conf/files.arm head/sys/conf/files.arm64 Added: head/sys/arm/annapurna/alpine/alpine_serdes.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/arm/annapurna/alpine/alpine_serdes.c Thu Oct 20 11:26:51 2016 (r307669) @@ -0,0 +1,225 @@ +/*- + * Copyright (c) 2015,2016 Annapurna Labs Ltd. and affiliates + * All rights reserved. + * + * Developed by Semihalf. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/kernel.h> +#include <sys/module.h> +#include <sys/bus.h> +#include <sys/rman.h> +#include <sys/conf.h> +#include <sys/resource.h> + +#include <machine/bus.h> +#include <dev/ofw/ofw_bus_subr.h> + +#include "al_serdes.h" +#include "alpine_serdes.h" + +#define SERDES_NUM_GROUPS 5 + +static void *serdes_base; +static uint32_t serdes_grp_offset[] = {0, 0x400, 0x800, 0xc00, 0x2000}; + +static struct alpine_serdes_eth_group_mode { + struct mtx lock; + enum alpine_serdes_eth_mode mode; + bool mode_set; +} alpine_serdes_eth_group_mode[SERDES_NUM_GROUPS]; + +static int al_serdes_probe(device_t dev); +static int al_serdes_attach(device_t dev); +static int al_serdes_detach(device_t dev); + +static struct resource_spec al_serdes_spec[] = { + { SYS_RES_MEMORY, 0, RF_ACTIVE }, + { -1, 0 } +}; + +struct al_serdes_softc { + struct resource *res; +}; + +static device_method_t al_serdes_methods[] = { + DEVMETHOD(device_probe, al_serdes_probe), + DEVMETHOD(device_attach, al_serdes_attach), + DEVMETHOD(device_detach, al_serdes_detach), + + DEVMETHOD_END +}; + +static driver_t al_serdes_driver = { + "serdes", + al_serdes_methods, + sizeof(struct al_serdes_softc) +}; + +static devclass_t al_serdes_devclass; + +DRIVER_MODULE(al_serdes, simplebus, al_serdes_driver, + al_serdes_devclass, 0, 0); +DRIVER_MODULE(al_serdes, ofwbus, al_serdes_driver, + al_serdes_devclass, 0, 0); + +static int +al_serdes_probe(device_t dev) +{ + + if (!ofw_bus_status_okay(dev)) + return (ENXIO); + + if (!ofw_bus_is_compatible(dev, "annapurna-labs,al-serdes")) + return (ENXIO); + + device_set_desc(dev, "Alpine Serdes"); + + return (BUS_PROBE_DEFAULT); +} + +static int +al_serdes_attach(device_t dev) +{ + struct al_serdes_softc *sc; + int err; + + sc = device_get_softc(dev); + + err = bus_alloc_resources(dev, al_serdes_spec, &sc->res); + if (err != 0) { + device_printf(dev, "could not allocate resources\n"); + return (err); + } + + /* Initialize Serdes group locks and mode */ + for (int i = 0; i < nitems(alpine_serdes_eth_group_mode); i++) { + mtx_init(&alpine_serdes_eth_group_mode[i].lock, "AlSerdesMtx", + NULL, MTX_DEF); + alpine_serdes_eth_group_mode[i].mode_set = false; + } + + serdes_base = (void *)rman_get_bushandle(sc->res); + + return (0); +} + +static int +al_serdes_detach(device_t dev) +{ + struct al_serdes_softc *sc; + + sc = device_get_softc(dev); + + bus_release_resources(dev, al_serdes_spec, &sc->res); + + for (int i = 0; i < nitems(alpine_serdes_eth_group_mode); i++) { + mtx_destroy(&alpine_serdes_eth_group_mode[i].lock); + alpine_serdes_eth_group_mode[i].mode_set = false; + } + + return (0); +} + +void * +alpine_serdes_resource_get(uint32_t group) +{ + void *base; + + base = NULL; + if (group >= SERDES_NUM_GROUPS) + return (NULL); + + if (serdes_base != NULL) + base = (void *)((uintptr_t)serdes_base + + serdes_grp_offset[group]); + + return (base); +} + +int +alpine_serdes_eth_mode_set(uint32_t group, enum alpine_serdes_eth_mode mode) +{ + struct alpine_serdes_eth_group_mode *group_mode; + + group_mode = &alpine_serdes_eth_group_mode[group]; + + if (serdes_base == NULL) + return (EINVAL); + + if (group >= SERDES_NUM_GROUPS) + return (EINVAL); + + mtx_lock(&group_mode->lock); + + if (!group_mode->mode_set || (group_mode->mode != mode)) { + struct al_serdes_grp_obj obj; + + al_serdes_handle_grp_init(alpine_serdes_resource_get(group), + group, &obj); + + if (mode == ALPINE_SERDES_ETH_MODE_SGMII) + obj.mode_set_sgmii(&obj); + else + obj.mode_set_kr(&obj); + + group_mode->mode = mode; + group_mode->mode_set = true; + } + + mtx_unlock(&group_mode->lock); + + return (0); +} + +void +alpine_serdes_eth_group_lock(uint32_t group) +{ + struct alpine_serdes_eth_group_mode *group_mode; + + group_mode = &alpine_serdes_eth_group_mode[group]; + + if (mtx_initialized(&group_mode->lock) == 0) + return; + + mtx_lock(&group_mode->lock); +} + +void +alpine_serdes_eth_group_unlock(uint32_t group) +{ + struct alpine_serdes_eth_group_mode *group_mode; + + group_mode = &alpine_serdes_eth_group_mode[group]; + + if (mtx_initialized(&group_mode->lock) == 0) + return; + + mtx_unlock(&group_mode->lock); +} Added: head/sys/arm/annapurna/alpine/alpine_serdes.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/arm/annapurna/alpine/alpine_serdes.h Thu Oct 20 11:26:51 2016 (r307669) @@ -0,0 +1,61 @@ +/*- + * Copyright (c) 2015,2016 Annapurna Labs Ltd. and affiliates + * All rights reserved. + * + * Developed by Semihalf. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef __ALPINE_SERDES_H__ +#define __ALPINE_SERDES_H__ + +/* SerDes ETH mode */ +enum alpine_serdes_eth_mode { + ALPINE_SERDES_ETH_MODE_SGMII, + ALPINE_SERDES_ETH_MODE_KR, +}; + +/* + * Get SerDes group regs base, to be used in relevant Alpine drivers. + * Valid group is 0..3. + * Returns virtual base address of the group regs base. + */ +void *alpine_serdes_resource_get(uint32_t group); + +/* + * Set SerDes ETH mode for an entire group, unless already set + * Valid group is 0..3. + * Returns 0 upon success. + */ +int alpine_serdes_eth_mode_set(uint32_t group, + enum alpine_serdes_eth_mode mode); + +/* Lock the all serdes group for using common registers */ +void alpine_serdes_eth_group_lock(uint32_t group); + +/* Unlock the all serdes group for using common registers */ +void alpine_serdes_eth_group_unlock(uint32_t group); + +#endif /* __ALPINE_SERDES_H__ */ Modified: head/sys/boot/fdt/dts/arm/annapurna-alpine.dts ============================================================================== --- head/sys/boot/fdt/dts/arm/annapurna-alpine.dts Thu Oct 20 11:23:59 2016 (r307668) +++ head/sys/boot/fdt/dts/arm/annapurna-alpine.dts Thu Oct 20 11:26:51 2016 (r307669) @@ -159,6 +159,12 @@ interrupt-parent = <&MPIC>; }; + /* SerDes */ + serdes { + compatible = "annapurna-labs,al-serdes"; + reg = <0x28c0000 0x1000>; + }; + serial0: serial@2883000 { compatible = "ns16550"; reg = <0x2883000 0x20>; Modified: head/sys/conf/files.arm ============================================================================== --- head/sys/conf/files.arm Thu Oct 20 11:23:59 2016 (r307668) +++ head/sys/conf/files.arm Thu Oct 20 11:26:51 2016 (r307669) @@ -15,6 +15,9 @@ arm/annapurna/alpine/alpine_ccu.c optio arm/annapurna/alpine/alpine_nb_service.c optional al_nb_service fdt arm/annapurna/alpine/alpine_pci.c optional al_pci fdt arm/annapurna/alpine/alpine_pci_msix.c optional al_pci fdt +arm/annapurna/alpine/alpine_serdes.c optional al_serdes fdt \ + no-depend \ + compile-with "${CC} -c -o ${.TARGET} ${CFLAGS} -I$S/contrib/alpine-hal -I$S/contrib/alpine-hal/eth ${PROF} ${.IMPSRC}" arm/arm/autoconf.c standard arm/arm/bcopy_page.S standard arm/arm/bcopyinout.S standard Modified: head/sys/conf/files.arm64 ============================================================================== --- head/sys/conf/files.arm64 Thu Oct 20 11:23:59 2016 (r307668) +++ head/sys/conf/files.arm64 Thu Oct 20 11:26:51 2016 (r307669) @@ -42,6 +42,9 @@ arm/annapurna/alpine/alpine_ccu.c optio arm/annapurna/alpine/alpine_nb_service.c optional al_nb_service fdt arm/annapurna/alpine/alpine_pci.c optional al_pci fdt arm/annapurna/alpine/alpine_pci_msix.c optional al_pci fdt +arm/annapurna/alpine/alpine_serdes.c optional al_serdes fdt \ + no-depend \ + compile-with "${CC} -c -o ${.TARGET} ${CFLAGS} -I$S/contrib/alpine-hal -I$S/contrib/alpine-hal/eth ${PROF} ${.IMPSRC}" arm/arm/generic_timer.c standard arm/arm/gic.c standard arm/arm/gic_fdt.c optional fdt
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201610201126.u9KBQpX7069210>