Index: stable/11/sys/arm/ti/am335x/am335x_scm.c =================================================================== --- stable/11/sys/arm/ti/am335x/am335x_scm.c (nonexistent) +++ stable/11/sys/arm/ti/am335x/am335x_scm.c (revision 310856) @@ -0,0 +1,169 @@ +/*- + * Copyright (c) 2016 Rubicon Communications, LLC (Netgate) + * All rights reserved. + * + * 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 +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include + +#define TZ_ZEROC 2731 + +struct am335x_scm_softc { + int sc_last_temp; + struct sysctl_oid *sc_temp_oid; +}; + +static int +am335x_scm_temp_sysctl(SYSCTL_HANDLER_ARGS) +{ + device_t dev; + int i, temp; + struct am335x_scm_softc *sc; + uint32_t reg; + + dev = (device_t)arg1; + sc = device_get_softc(dev); + + /* Read the temperature and convert to Kelvin. */ + for(i = 50; i > 0; i--) { + ti_scm_reg_read_4(SCM_BGAP_CTRL, ®); + if ((reg & SCM_BGAP_EOCZ) == 0) + break; + DELAY(50); + } + if ((reg & SCM_BGAP_EOCZ) == 0) { + sc->sc_last_temp = + (reg >> SCM_BGAP_TEMP_SHIFT) & SCM_BGAP_TEMP_MASK; + sc->sc_last_temp *= 10; + } + temp = sc->sc_last_temp + TZ_ZEROC; + + return (sysctl_handle_int(oidp, &temp, 0, req)); +} + +static void +am335x_scm_identify(driver_t *driver, device_t parent) +{ + device_t child; + + /* AM335x only. */ + if (ti_chip() != CHIP_AM335X) + return; + + /* Make sure we attach only once. */ + if (device_find_child(parent, "am335x_scm", -1) != NULL) + return; + + child = device_add_child(parent, "am335x_scm", -1); + if (child == NULL) + device_printf(parent, "cannot add ti_scm child\n"); +} + +static int +am335x_scm_probe(device_t dev) +{ + + device_set_desc(dev, "AM335x Control Module Extension"); + + return (BUS_PROBE_DEFAULT); +} + +static int +am335x_scm_attach(device_t dev) +{ + struct am335x_scm_softc *sc; + struct sysctl_ctx_list *ctx; + struct sysctl_oid_list *tree; + uint32_t reg; + + /* Set ADC to continous mode, clear output reset. */ + reg = SCM_BGAP_CLRZ | SCM_BGAP_CONTCONV; + ti_scm_reg_write_4(SCM_BGAP_CTRL, reg); + /* Flush write. */ + ti_scm_reg_read_4(SCM_BGAP_CTRL, ®); + /* Start the ADC conversion. */ + reg = SCM_BGAP_CLRZ | SCM_BGAP_CONTCONV | SCM_BGAP_SOC; + ti_scm_reg_write_4(SCM_BGAP_CTRL, reg); + + /* Temperature sysctl. */ + sc = device_get_softc(dev); + ctx = device_get_sysctl_ctx(dev); + tree = SYSCTL_CHILDREN(device_get_sysctl_tree(dev)); + sc->sc_temp_oid = SYSCTL_ADD_PROC(ctx, tree, OID_AUTO, + "temperature", CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MPSAFE, + dev, 0, am335x_scm_temp_sysctl, "IK", "Current temperature"); + + return (0); +} + +static int +am335x_scm_detach(device_t dev) +{ + struct am335x_scm_softc *sc; + + sc = device_get_softc(dev); + + /* Remove temperature sysctl. */ + if (sc->sc_temp_oid != NULL) + sysctl_remove_oid(sc->sc_temp_oid, 1, 0); + + /* Stop the bandgap ADC. */ + ti_scm_reg_write_4(SCM_BGAP_CTRL, SCM_BGAP_BGOFF); + + return (0); +} + +static device_method_t am335x_scm_methods[] = { + DEVMETHOD(device_identify, am335x_scm_identify), + DEVMETHOD(device_probe, am335x_scm_probe), + DEVMETHOD(device_attach, am335x_scm_attach), + DEVMETHOD(device_detach, am335x_scm_detach), + + DEVMETHOD_END +}; + +static driver_t am335x_scm_driver = { + "am335x_scm", + am335x_scm_methods, + sizeof(struct am335x_scm_softc), +}; + +static devclass_t am335x_scm_devclass; + +DRIVER_MODULE(am335x_scm, ti_scm, am335x_scm_driver, am335x_scm_devclass, 0, 0); +MODULE_VERSION(am335x_scm, 1); +MODULE_DEPEND(am335x_scm, ti_scm, 1, 1, 1); Property changes on: stable/11/sys/arm/ti/am335x/am335x_scm.c ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: stable/11/sys/arm/ti/am335x/am335x_scm.h =================================================================== --- stable/11/sys/arm/ti/am335x/am335x_scm.h (revision 310855) +++ stable/11/sys/arm/ti/am335x/am335x_scm.h (revision 310856) @@ -1,41 +1,49 @@ /*- * Copyright (c) 2012 Oleksandr Tymoshenko * All rights reserved. * * 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 __AM335X_SCM_H__ #define __AM335X_SCM_H__ /* AM335x-specific registers for control module (scm) */ #define SCM_CTRL_STATUS 0x40 +#define SCM_BGAP_CTRL 0x448 +#define SCM_BGAP_TEMP_MASK 0xff +#define SCM_BGAP_TEMP_SHIFT 8 +#define SCM_BGAP_BGOFF (1 << 6) +#define SCM_BGAP_SOC (1 << 4) +#define SCM_BGAP_CLRZ (1 << 3) +#define SCM_BGAP_CONTCONV (1 << 2) +#define SCM_BGAP_EOCZ (1 << 1) #define SCM_USB_CTRL0 0x620 #define SCM_USB_STS0 0x624 #define SCM_USB_CTRL1 0x628 #define SCM_USB_STS1 0x62C #define SCM_MAC_ID0_LO 0x630 #define SCM_MAC_ID0_HI 0x634 #define SCM_PWMSS_CTRL 0x664 #endif /* __AM335X_SCM_H__ */ Index: stable/11/sys/arm/ti/am335x/files.am335x =================================================================== --- stable/11/sys/arm/ti/am335x/files.am335x (revision 310855) +++ stable/11/sys/arm/ti/am335x/files.am335x (revision 310856) @@ -1,23 +1,24 @@ #$FreeBSD$ arm/ti/aintc.c standard arm/ti/am335x/am335x_dmtimer.c standard arm/ti/am335x/am335x_dmtpps.c optional am335x_dmtpps arm/ti/am335x/am335x_gpio.c optional gpio arm/ti/am335x/am335x_lcd.c optional sc | vt arm/ti/am335x/am335x_lcd_syscons.c optional sc arm/ti/am335x/am335x_pmic.c optional am335x_pmic arm/ti/am335x/am335x_prcm.c standard arm/ti/am335x/am335x_pwmss.c standard arm/ti/am335x/am335x_ehrpwm.c standard arm/ti/am335x/am335x_ecap.c standard arm/ti/am335x/am335x_rtc.c optional am335x_rtc +arm/ti/am335x/am335x_scm.c standard arm/ti/am335x/am335x_scm_padconf.c standard arm/ti/am335x/am335x_usbss.c optional musb fdt arm/ti/am335x/am335x_musb.c optional musb fdt arm/ti/am335x/tda19988.c optional hdmi arm/ti/ti_edma3.c standard arm/ti/cpsw/if_cpsw.c optional cpsw Index: stable/11/sys/arm/ti/ti_scm.c =================================================================== --- stable/11/sys/arm/ti/ti_scm.c (revision 310855) +++ stable/11/sys/arm/ti/ti_scm.c (revision 310856) @@ -1,172 +1,175 @@ /* * Copyright (c) 2010 * Ben Gray . * All rights reserved. * * 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. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Ben Gray. * 4. The name of the company nor the name of the author may be used to * endorse or promote products derived from this software without specific * prior written permission. * * THIS SOFTWARE IS PROVIDED BY BEN GRAY ``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 BEN GRAY 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. */ /** * SCM - System Control Module * * Hopefully in the end this module will contain a bunch of utility functions * for configuring and querying the general system control registers, but for * now it only does pin(pad) multiplexing. * * This is different from the GPIO module in that it is used to configure the * pins between modules not just GPIO input/output. * * This file contains the generic top level driver, however it relies on chip * specific settings and therefore expects an array of ti_scm_padconf structs * call ti_padconf_devmap to be located somewhere in the kernel. * */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "ti_scm.h" static struct resource_spec ti_scm_res_spec[] = { { SYS_RES_MEMORY, 0, RF_ACTIVE }, /* Control memory window */ { -1, 0 } }; static struct ti_scm_softc *ti_scm_sc; #define ti_scm_read_4(sc, reg) \ bus_space_read_4((sc)->sc_bst, (sc)->sc_bsh, (reg)) #define ti_scm_write_4(sc, reg, val) \ bus_space_write_4((sc)->sc_bst, (sc)->sc_bsh, (reg), (val)) /* * Device part of OMAP SCM driver */ static int ti_scm_probe(device_t dev) { if (!ofw_bus_status_okay(dev)) return (ENXIO); if (!ofw_bus_is_compatible(dev, "syscon")) return (ENXIO); if (ti_scm_sc) { return (EEXIST); } device_set_desc(dev, "TI Control Module"); return (BUS_PROBE_DEFAULT); } /** * ti_scm_attach - attaches the timer to the simplebus * @dev: new device * * Reserves memory and interrupt resources, stores the softc structure * globally and registers both the timecount and eventtimer objects. * * RETURNS * Zero on success or ENXIO if an error occuried. */ static int ti_scm_attach(device_t dev) { struct ti_scm_softc *sc = device_get_softc(dev); sc->sc_dev = dev; if (bus_alloc_resources(dev, ti_scm_res_spec, sc->sc_res)) { device_printf(dev, "could not allocate resources\n"); return (ENXIO); } /* Global timer interface */ sc->sc_bst = rman_get_bustag(sc->sc_res[0]); sc->sc_bsh = rman_get_bushandle(sc->sc_res[0]); ti_scm_sc = sc; - return (0); + /* Attach platform extensions, if any. */ + bus_generic_probe(dev); + + return (bus_generic_attach(dev)); } int ti_scm_reg_read_4(uint32_t reg, uint32_t *val) { if (!ti_scm_sc) return (ENXIO); *val = ti_scm_read_4(ti_scm_sc, reg); return (0); } int ti_scm_reg_write_4(uint32_t reg, uint32_t val) { if (!ti_scm_sc) return (ENXIO); ti_scm_write_4(ti_scm_sc, reg, val); return (0); } static device_method_t ti_scm_methods[] = { DEVMETHOD(device_probe, ti_scm_probe), DEVMETHOD(device_attach, ti_scm_attach), { 0, 0 } }; static driver_t ti_scm_driver = { "ti_scm", ti_scm_methods, sizeof(struct ti_scm_softc), }; static devclass_t ti_scm_devclass; EARLY_DRIVER_MODULE(ti_scm, simplebus, ti_scm_driver, ti_scm_devclass, 0, 0, BUS_PASS_BUS + BUS_PASS_ORDER_MIDDLE); Index: stable/11 =================================================================== --- stable/11 (revision 310855) +++ stable/11 (revision 310856) Property changes on: stable/11 ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /head:r305114-305115,305149