Date: Tue, 05 Jun 2012 19:47:08 +0000 From: aleek@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r237153 - in soc2012/aleek/beaglexm-armv6/sys: arm/conf arm/ti arm/ti/am37x boot/fdt/dts Message-ID: <20120605194708.58AB41065670@hub.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: aleek Date: Tue Jun 5 19:47:07 2012 New Revision: 237153 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=237153 Log: added mapping for devices etc. Board boots to initarm():setttb() Added: soc2012/aleek/beaglexm-armv6/sys/arm/ti/am37x/am37x_dmtimer.c soc2012/aleek/beaglexm-armv6/sys/arm/ti/am37x/am37x_pmic.c soc2012/aleek/beaglexm-armv6/sys/arm/ti/am37x/am37x_prcm.c soc2012/aleek/beaglexm-armv6/sys/arm/ti/am37x/am37x_reg.h soc2012/aleek/beaglexm-armv6/sys/arm/ti/am37x/am37x_scm_padconf.c soc2012/aleek/beaglexm-armv6/sys/boot/fdt/dts/beagleboardxm.dts Deleted: soc2012/aleek/beaglexm-armv6/sys/arm/ti/am37x/am37x_gptimer.c soc2012/aleek/beaglexm-armv6/sys/arm/ti/am37x/am37x_gptimer.h soc2012/aleek/beaglexm-armv6/sys/arm/ti/am37x/am37x_timer.c Modified: soc2012/aleek/beaglexm-armv6/sys/arm/conf/BEAGLEBOARD-XM soc2012/aleek/beaglexm-armv6/sys/arm/ti/am37x/files.am37x soc2012/aleek/beaglexm-armv6/sys/arm/ti/am37x/files.beagleboardxm soc2012/aleek/beaglexm-armv6/sys/arm/ti/am37x/std.am37x soc2012/aleek/beaglexm-armv6/sys/arm/ti/am37x/std.beagleboardxm soc2012/aleek/beaglexm-armv6/sys/arm/ti/ti_machdep.c Modified: soc2012/aleek/beaglexm-armv6/sys/arm/conf/BEAGLEBOARD-XM ============================================================================== --- soc2012/aleek/beaglexm-armv6/sys/arm/conf/BEAGLEBOARD-XM Tue Jun 5 18:58:05 2012 (r237152) +++ soc2012/aleek/beaglexm-armv6/sys/arm/conf/BEAGLEBOARD-XM Tue Jun 5 19:47:07 2012 (r237153) @@ -1,5 +1,5 @@ -# BEAGLEBOARD -- Custom configuration for the BeagleBoard ARM development -# platform, check out www.beaglebaord.org +# BEAGLEBONE -- Custom configuration for the BeagleBone ARM development +# platform, check out http://www.beagleboard.org/bone # # For more information on this file, please read the handbook section on # Kernel Configuration Files: @@ -12,109 +12,114 @@ # latest information. # # An exhaustive list of options and more detailed explanations of the -# device lines is also present in the ../../conf/NOTES and NOTES files. -# If you are in doubt as to the purpose or necessity of a line, check first +# device lines is also present in the ../../conf/NOTES and NOTES files. +# If you are in doubt as to the purpose or necessity of a line, check first # in NOTES. # # $FreeBSD$ -ident BEAGLEBAORD-XM +ident BEAGLEBOARD-XM -# This probably wants to move somewhere else. Maybe we can create a basic -# OMAP3530 config, then make a BEAGLEBOARD config that includes the basic one, -# adds the start addresses and custom devices plus pulls in this hints file. +include "../ti/am37x/std.beagleboardxm" -#hints "BEAGLEBOARD.hints" - -include "../ti/am37x/std.beagleboardxm" - -#To statically compile in device wiring instead of /boot/device.hints makeoptions MODULES_OVERRIDE="" -makeoptions WITHOUT_MODULES="ahc" +makeoptions WITHOUT_MODULES="ahc" -makeoptions DEBUG=-g #Build kernel with gdb(1) debug symbols -makeoptions WERROR= -options HZ=100 +options HZ=100 +options SCHED_4BSD #4BSD scheduler +#options INET #InterNETworking +#options INET6 #IPv6 communications protocols +options FFS #Berkeley Fast Filesystem +options SOFTUPDATES #Enable FFS soft updates support +options UFS_ACL #Support for access control lists +options UFS_DIRHASH #Improve performance on big directories +options MSDOSFS #MSDOS Filesystem +options CD9660 #ISO 9660 Filesystem +options PROCFS #Process filesystem (requires PSEUDOFS) +options PSEUDOFS #Pseudo-filesystem framework +options COMPAT_43 #Compatible with BSD 4.3 [KEEP THIS!] +options SCSI_DELAY=5000 #Delay (in ms) before probing SCSI +options KTRACE #ktrace(1) support +options SYSVSHM #SYSV-style shared memory +options SYSVMSG #SYSV-style message queues +options SYSVSEM #SYSV-style semaphores +options _KPOSIX_PRIORITY_SCHEDULING #Posix P1003_1B real-time extensions +options KBD_INSTALL_CDEV # install a CDEV entry in /dev +options PREEMPTION -options SCHED_4BSD #4BSD scheduler -#options INET #InterNETworking -#options INET6 #IPv6 communications protocols -options FFS #Berkeley Fast Filesystem -options SOFTUPDATES #Enable FFS soft updates support -options UFS_ACL #Support for access control lists -options UFS_DIRHASH #Improve performance on big directories -#options NFSCLIENT #Network Filesystem Client -#options NFSSERVER #Network Filesystem Server -#options NFS_ROOT #NFS usable as /, requires NFSCLIENT -#options MSDOSFS #MSDOS Filesystem -#options CD9660 #ISO 9660 Filesystem -#options PROCFS #Process filesystem (requires PSEUDOFS) -options PSEUDOFS #Pseudo-filesystem framework -options COMPAT_43 #Compatible with BSD 4.3 [KEEP THIS!] -options SCSI_DELAY=5000 #Delay (in ms) before probing SCSI -options KTRACE #ktrace(1) support -options SYSVSHM #SYSV-style shared memory -options SYSVMSG #SYSV-style message queues -options SYSVSEM #SYSV-style semaphores -options _KPOSIX_PRIORITY_SCHEDULING #Posix P1003_1B real-time extensions -options KBD_INSTALL_CDEV # install a CDEV entry in /dev +# Debugging +makeoptions DEBUG=-g #Build kernel with gdb(1) debug symbols +options BREAK_TO_DEBUGGER +#options VERBOSE_SYSINIT #Enable verbose sysinit messages +options KDB +options DDB #Enable the kernel debugger +options INVARIANTS #Enable calls of extra sanity checking +options INVARIANT_SUPPORT #Extra sanity checks of internal structures, required by INVARIANTS +options WITNESS #Enable checks to detect deadlocks and cycles +options WITNESS_SKIPSPIN #Don't run witness on spinlocks for speed +#options DIAGNOSTIC + +# NFS support +#options NFSCL +#options NFSSERVER #Network Filesystem Server +#options NFSCLIENT #Network Filesystem Client + +# Uncomment this for NFS root +#options NFS_ROOT #NFS usable as /, requires NFSCLIENT +#options BOOTP_NFSROOT +#options BOOTP_COMPAT +#options BOOTP +#options BOOTP_NFSV3 +#options BOOTP_WIRED_TO=cpsw0 -options PREEMPTION -# MMC/SD/SDIO Card slot support -#device mmc # mmc/sd bus +# MMC/SD/SDIO card slot support +#device mmc # mmc/sd bus #device mmcsd # mmc/sd flash cards -# I2C support -#device iicbus -#device iic - -device loop -#device ether -#device mii -#device smc -#device smcphy -#device uart -#device uart_ns8250 +# Boot device is 2nd slice on MMC/SD card +options ROOTDEVNAME=\"ufs:mmcsd0s2\" +# Console and misc +device uart +device uart_ns8250 device pty - -#device gpio - -# Debugging for use in -current -options VERBOSE_SYSINIT #Enable verbose sysinit messages -options KDB -options DDB #Enable the kernel debugger -#options INVARIANTS #Enable calls of extra sanity checking -#options INVARIANT_SUPPORT #Extra sanity checks of internal structures, required by INVARIANTS -#options WITNESS #Enable checks to detect deadlocks and cycles -#options WITNESS_SKIPSPIN #Don't run witness on spinlocks for speed -#options DIAGNOSTIC -options BREAK_TO_DEBUGGER - +device snp device md +device random # Entropy device -# The following enables MFS as root, this seems similar to an initramfs or initrd -# as used in Linux. -# options MD_ROOT -# options MD_ROOT_SIZE=7560 +# I2C support +#device iicbus +#device iic +#device ti_i2c +#device am37x_pmic # AM335x Power Management IC (TPC65217) -device random # Entropy device +# GPIO +#device gpio # USB support #device usb -#device ohci -#device ehci +#options USB_DEBUG +#options USB_REQ_DEBUG +#options USB_VERBOSE +#device musb #device umass -#device scbus # SCSI bus (required for SCSI) -#device da # Direct Access (disks) +#device scbus # SCSI bus (required for SCSI) +#device da # Direct Access (disks) -# USB Ethernet support, requires miibus +# Ethernet +device loop +#device ether +#device mii +#device smcphy + +# USB ethernet support, requires miibus #device miibus +#device cpsw #device axe # ASIX Electronics USB Ethernet - # Flattened Device Tree -#options FDT -#options FDT_DTB_STATIC -#makeoptions FDT_DTS_FILE=beaglebone.dts +options FDT +options FDT_DTB_STATIC +makeoptions FDT_DTS_FILE=beagleboardxm.dts + Added: soc2012/aleek/beaglexm-armv6/sys/arm/ti/am37x/am37x_dmtimer.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2012/aleek/beaglexm-armv6/sys/arm/ti/am37x/am37x_dmtimer.c Tue Jun 5 19:47:07 2012 (r237153) @@ -0,0 +1,385 @@ +/*- + * Copyright (c) 2012 Damjan Marion <dmarion@Freebsd.org> + * 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 <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/bus.h> +#include <sys/kernel.h> +#include <sys/module.h> +#include <sys/malloc.h> +#include <sys/rman.h> +#include <sys/timeet.h> +#include <sys/timetc.h> +#include <sys/watchdog.h> +#include <machine/bus.h> +#include <machine/cpu.h> +#include <machine/frame.h> +#include <machine/intr.h> + +#include <dev/fdt/fdt_common.h> +#include <dev/ofw/openfirm.h> +#include <dev/ofw/ofw_bus.h> +#include <dev/ofw/ofw_bus_subr.h> + +#include <machine/bus.h> +#include <machine/fdt.h> + +#include <arm/ti/ti_prcm.h> + +#define AM335X_NUM_TIMERS 8 + +#define DMTIMER_TIDR 0x00 /* Identification Register */ +#define DMTIMER_TIOCP_CFG 0x10 /* Timer OCP Configuration Reg */ +#define DMTIMER_IQR_EOI 0x20 /* Timer IRQ End-Of-Interrupt Reg */ +#define DMTIMER_IRQSTATUS_RAW 0x24 /* Timer IRQSTATUS Raw Reg */ +#define DMTIMER_IRQSTATUS 0x28 /* Timer IRQSTATUS Reg */ +#define DMTIMER_IRQENABLE_SET 0x2c /* Timer IRQSTATUS Set Reg */ +#define DMTIMER_IRQENABLE_CLR 0x30 /* Timer IRQSTATUS Clear Reg */ +#define DMTIMER_IRQWAKEEN 0x34 /* Timer IRQ Wakeup Enable Reg */ +#define DMTIMER_TCLR 0x38 /* Timer Control Register */ +#define DMTIMER_TCRR 0x3C /* Timer Counter Register */ +#define DMTIMER_TLDR 0x40 /* Timer Load Reg */ +#define DMTIMER_TTGR 0x44 /* Timer Trigger Reg */ +#define DMTIMER_TWPS 0x48 /* Timer Write Posted Status Reg */ +#define DMTIMER_TMAR 0x4C /* Timer Match Reg */ +#define DMTIMER_TCAR1 0x50 /* Timer Capture Reg */ +#define DMTIMER_TSICR 0x54 /* Timer Synchr. Interface Control Reg */ +#define DMTIMER_TCAR2 0x48 /* Timer Capture Reg */ + + +struct am335x_dmtimer_softc { + struct resource * tmr_mem_res[AM335X_NUM_TIMERS]; + struct resource * tmr_irq_res[AM335X_NUM_TIMERS]; + uint32_t sysclk_freq; + struct am335x_dmtimer { + bus_space_tag_t bst; + bus_space_handle_t bsh; + struct eventtimer et; + } t[AM335X_NUM_TIMERS]; +}; + +static struct resource_spec am335x_dmtimer_mem_spec[] = { + { SYS_RES_MEMORY, 0, RF_ACTIVE }, + { SYS_RES_MEMORY, 1, RF_ACTIVE }, + { SYS_RES_MEMORY, 2, RF_ACTIVE }, + { SYS_RES_MEMORY, 3, RF_ACTIVE }, + { SYS_RES_MEMORY, 4, RF_ACTIVE }, + { SYS_RES_MEMORY, 5, RF_ACTIVE }, + { SYS_RES_MEMORY, 6, RF_ACTIVE }, + { SYS_RES_MEMORY, 7, RF_ACTIVE }, + { -1, 0, 0 } +}; +static struct resource_spec am335x_dmtimer_irq_spec[] = { + { SYS_RES_IRQ, 0, RF_ACTIVE }, + { SYS_RES_IRQ, 1, RF_ACTIVE }, + { SYS_RES_IRQ, 2, RF_ACTIVE }, + { SYS_RES_IRQ, 3, RF_ACTIVE }, + { SYS_RES_IRQ, 4, RF_ACTIVE }, + { SYS_RES_IRQ, 5, RF_ACTIVE }, + { SYS_RES_IRQ, 6, RF_ACTIVE }, + { SYS_RES_IRQ, 7, RF_ACTIVE }, + { -1, 0, 0 } +}; + +static struct am335x_dmtimer *am335x_dmtimer_tc_tmr = NULL; + +/* Read/Write macros for Timer used as timecounter */ +#define am335x_dmtimer_tc_read_4(reg) \ + bus_space_read_4(am335x_dmtimer_tc_tmr->bst, \ + am335x_dmtimer_tc_tmr->bsh, reg) + +#define am335x_dmtimer_tc_write_4(reg, val) \ + bus_space_write_4(am335x_dmtimer_tc_tmr->bst, \ + am335x_dmtimer_tc_tmr->bsh, reg, val) + +/* Read/Write macros for Timer used as eventtimer */ +#define am335x_dmtimer_et_read_4(reg) \ + bus_space_read_4(tmr->bst, tmr->bsh, reg) + +#define am335x_dmtimer_et_write_4(reg, val) \ + bus_space_write_4(tmr->bst, tmr->bsh, reg, val) + +static unsigned am335x_dmtimer_tc_get_timecount(struct timecounter *); + +static struct timecounter am335x_dmtimer_tc = { + .tc_name = "AM335x Timecouter", + .tc_get_timecount = am335x_dmtimer_tc_get_timecount, + .tc_poll_pps = NULL, + .tc_counter_mask = ~0u, + .tc_frequency = 0, + .tc_quality = 1000, +}; + +static unsigned +am335x_dmtimer_tc_get_timecount(struct timecounter *tc) +{ + return am335x_dmtimer_tc_read_4(DMTIMER_TCRR); +} + +static int +am335x_dmtimer_start(struct eventtimer *et, struct bintime *first, + struct bintime *period) +{ + struct am335x_dmtimer *tmr = (struct am335x_dmtimer *)et->et_priv; + uint32_t load, count; + uint32_t tclr = 0; + + if (period != NULL) { + load = (et->et_frequency * (period->frac >> 32)) >> 32; + if (period->sec > 0) + load += et->et_frequency * period->sec; + tclr |= 2; /* autoreload bit */ + panic("periodic timer not implemented\n"); + } else { + load = 0; + } + + if (first != NULL) { + count = (tmr->et.et_frequency * (first->frac >> 32)) >> 32; + if (first->sec != 0) + count += tmr->et.et_frequency * first->sec; + } else { + count = load; + } + + /* Reset Timer */ + am335x_dmtimer_et_write_4(DMTIMER_TSICR, 2); + + /* Wait for reset to complete */ + while (am335x_dmtimer_et_read_4(DMTIMER_TIOCP_CFG) & 1); + + /* set load value */ + am335x_dmtimer_et_write_4(DMTIMER_TLDR, 0xFFFFFFFE - load); + + /* set counter value */ + am335x_dmtimer_et_write_4(DMTIMER_TCRR, 0xFFFFFFFE - count); + + /* enable overflow interrupt */ + am335x_dmtimer_et_write_4(DMTIMER_IRQENABLE_SET, 2); + + /* start timer(ST) */ + tclr |= 1; + am335x_dmtimer_et_write_4(DMTIMER_TCLR, tclr); + + return (0); +} + +static int +am335x_dmtimer_stop(struct eventtimer *et) +{ + struct am335x_dmtimer *tmr = (struct am335x_dmtimer *)et->et_priv; + + /* Disable all interrupts */ + am335x_dmtimer_et_write_4(DMTIMER_IRQENABLE_CLR, 7); + + /* Stop Timer */ + am335x_dmtimer_et_write_4(DMTIMER_TCLR, 0); + + return (0); +} + +static int +am335x_dmtimer_intr(void *arg) +{ + struct am335x_dmtimer *tmr = (struct am335x_dmtimer *)arg; + + /* Ack interrupt */ + am335x_dmtimer_et_write_4(DMTIMER_IRQSTATUS, 7); + if (tmr->et.et_active) + tmr->et.et_event_cb(&tmr->et, tmr->et.et_arg); + + return (FILTER_HANDLED); +} + +static int +am335x_dmtimer_probe(device_t dev) +{ + struct am335x_dmtimer_softc *sc; + sc = (struct am335x_dmtimer_softc *)device_get_softc(dev); + + if (ofw_bus_is_compatible(dev, "ti,am335x-dmtimer")) { + device_set_desc(dev, "AM335x DMTimer"); + return(BUS_PROBE_DEFAULT); + } + + return (ENXIO); +} + +static int +am335x_dmtimer_attach(device_t dev) +{ + struct am335x_dmtimer_softc *sc = device_get_softc(dev); + void *ihl; + int err; + int i; + + if (am335x_dmtimer_tc_tmr != NULL) + return (EINVAL); + + /* Get the base clock frequency */ + err = ti_prcm_clk_get_source_freq(SYS_CLK, &sc->sysclk_freq); + if (err) { + device_printf(dev, "Error: could not get sysclk frequency\n"); + return (ENXIO); + } + + /* Request the memory resources */ + err = bus_alloc_resources(dev, am335x_dmtimer_mem_spec, + sc->tmr_mem_res); + if (err) { + device_printf(dev, "Error: could not allocate mem resources\n"); + return (ENXIO); + } + + /* Request the IRQ resources */ + err = bus_alloc_resources(dev, am335x_dmtimer_irq_spec, + sc->tmr_irq_res); + if (err) { + device_printf(dev, "Error: could not allocate irq resources\n"); + return (ENXIO); + } + + for(i=0;i<AM335X_NUM_TIMERS;i++) { + sc->t[i].bst = rman_get_bustag(sc->tmr_mem_res[i]); + sc->t[i].bsh = rman_get_bushandle(sc->tmr_mem_res[i]); + } + + /* Configure DMTimer2 and DMTimer3 source and enable them */ + err = ti_prcm_clk_set_source(DMTIMER2_CLK, SYSCLK_CLK); + err |= ti_prcm_clk_enable(DMTIMER2_CLK); + err |= ti_prcm_clk_set_source(DMTIMER3_CLK, SYSCLK_CLK); + err |= ti_prcm_clk_enable(DMTIMER3_CLK); + if (err) { + device_printf(dev, "Error: could not setup timer clock\n"); + return (ENXIO); + } + + /* Take DMTimer2 for TC */ + am335x_dmtimer_tc_tmr = &sc->t[2]; + + /* Reset Timer */ + am335x_dmtimer_tc_write_4(DMTIMER_TSICR, 2); + + /* Wait for reset to complete */ + while (am335x_dmtimer_tc_read_4(DMTIMER_TIOCP_CFG) & 1); + + /* set load value */ + am335x_dmtimer_tc_write_4(DMTIMER_TLDR, 0); + + /* set counter value */ + am335x_dmtimer_tc_write_4(DMTIMER_TCRR, 0); + + /* Set Timer autoreload(AR) and start timer(ST) */ + am335x_dmtimer_tc_write_4(DMTIMER_TCLR, 3); + + am335x_dmtimer_tc.tc_frequency = sc->sysclk_freq; + tc_init(&am335x_dmtimer_tc); + + /* Register DMTimer3 as ET */ + + /* Setup and enable the timer */ + if (bus_setup_intr(dev, sc->tmr_irq_res[3], INTR_TYPE_CLK, + am335x_dmtimer_intr, NULL, &sc->t[3], &ihl) != 0) { + bus_release_resources(dev, am335x_dmtimer_irq_spec, + sc->tmr_irq_res); + device_printf(dev, "Unable to setup the clock irq handler.\n"); + return (ENXIO); + } + + sc->t[3].et.et_name = "AM335x Eventtimer0"; + sc->t[3].et.et_flags = ET_FLAGS_PERIODIC | ET_FLAGS_ONESHOT; + sc->t[3].et.et_quality = 1000; + sc->t[3].et.et_frequency = sc->sysclk_freq; + sc->t[3].et.et_min_period.sec = 0; + sc->t[3].et.et_min_period.frac = + ((0x00000002LLU << 32) / sc->t[3].et.et_frequency) << 32; + sc->t[3].et.et_max_period.sec = 0xfffffff0U / sc->t[3].et.et_frequency; + sc->t[3].et.et_max_period.frac = + ((0xfffffffeLLU << 32) / sc->t[3].et.et_frequency) << 32; + sc->t[3].et.et_start = am335x_dmtimer_start; + sc->t[3].et.et_stop = am335x_dmtimer_stop; + sc->t[3].et.et_priv = &sc->t[3]; + et_register(&sc->t[3].et); + + return (0); +} + +static device_method_t am335x_dmtimer_methods[] = { + DEVMETHOD(device_probe, am335x_dmtimer_probe), + DEVMETHOD(device_attach, am335x_dmtimer_attach), + { 0, 0 } +}; + +static driver_t am335x_dmtimer_driver = { + "am335x_dmtimer", + am335x_dmtimer_methods, + sizeof(struct am335x_dmtimer_softc), +}; + +static devclass_t am335x_dmtimer_devclass; + +DRIVER_MODULE(am335x_dmtimer, simplebus, am335x_dmtimer_driver, am335x_dmtimer_devclass, 0, 0); +MODULE_DEPEND(am335x_dmtimer, am335x_prcm, 1, 1, 1); + +void +cpu_initclocks(void) +{ + cpu_initclocks_bsp(); +} + +void +DELAY(int usec) +{ + int32_t counts; + uint32_t first, last; + + if (am335x_dmtimer_tc_tmr == NULL) { + for (; usec > 0; usec--) + for (counts = 200; counts > 0; counts--) + /* Prevent gcc from optimizing out the loop */ + cpufunc_nullop(); + return; + } + + /* Get the number of times to count */ + counts = usec * ((am335x_dmtimer_tc.tc_frequency / 1000000) + 1);; + + first = am335x_dmtimer_tc_read_4(DMTIMER_TCRR); + + while (counts > 0) { + last = am335x_dmtimer_tc_read_4(DMTIMER_TCRR); + if (last>first) { + counts -= (int32_t)(last - first); + } else { + counts -= (int32_t)((0xFFFFFFFF - first) + last); + } + first = last; + } +} + Added: soc2012/aleek/beaglexm-armv6/sys/arm/ti/am37x/am37x_pmic.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2012/aleek/beaglexm-armv6/sys/arm/ti/am37x/am37x_pmic.c Tue Jun 5 19:47:07 2012 (r237153) @@ -0,0 +1,176 @@ +/*- + * Copyright (c) 2012 Damjan Marion <dmarion@Freebsd.org> + * 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 <sys/cdefs.h> +__FBSDID("$FreeBSD$"); +/* +* TPS65217 PMIC companion chip for AM335x SoC sitting on I2C bus +*/ +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/kernel.h> +#include <sys/module.h> +#include <sys/clock.h> +#include <sys/time.h> +#include <sys/bus.h> +#include <sys/resource.h> +#include <sys/rman.h> + +#include <dev/iicbus/iicbus.h> +#include <dev/iicbus/iiconf.h> + +#include <dev/ofw/openfirm.h> +#include <dev/ofw/ofw_bus.h> +#include <dev/ofw/ofw_bus_subr.h> + +#include "iicbus_if.h" + +#define TPS65217A 0x7 +#define TPS65217B 0xF + +/* TPS65217 Reisters */ +#define TPS65217_CHIPID_REG 0x00 +#define TPS65217_STATUS_REG 0x0A + +#define MAX_IIC_DATA_SIZE 2 + + +struct am335x_pmic_softc { + device_t sc_dev; + uint32_t sc_addr; + struct intr_config_hook enum_hook; +}; + +static int +am335x_pmic_read(device_t dev, uint8_t addr, uint8_t *data, uint8_t size) +{ + struct am335x_pmic_softc *sc = device_get_softc(dev); + struct iic_msg msg[] = { + { sc->sc_addr, IIC_M_WR, 1, &addr }, + { sc->sc_addr, IIC_M_RD, size, data }, + }; + return (iicbus_transfer(dev, msg, 2)); +} + +#ifdef notyet +static int +am335x_pmic_write(device_t dev, uint8_t address, uint8_t *data, uint8_t size) +{ + uint8_t buffer[MAX_IIC_DATA_SIZE + 1]; + struct am335x_pmic_softc *sc = device_get_softc(dev); + struct iic_msg msg[] = { + { sc->sc_addr, IIC_M_WR, size + 1, buffer }, + }; + + if (size > MAX_IIC_DATA_SIZE) + return (ENOMEM); + + buffer[0] = address; + memcpy(buffer + 1, data, size); + + return (iicbus_transfer(dev, msg, 1)); +} +#endif + +static int +am335x_pmic_probe(device_t dev) +{ + struct am335x_pmic_softc *sc; + + if (!ofw_bus_is_compatible(dev, "ti,am335x-pmic")) + return (ENXIO); + + sc = device_get_softc(dev); + sc->sc_dev = dev; + sc->sc_addr = iicbus_get_addr(dev); + + device_set_desc(dev, "TI TPS65217 Power Management IC"); + + return (0); +} + +static void +am335x_pmic_start(void *xdev) +{ + struct am335x_pmic_softc *sc; + device_t dev = (device_t)xdev; + uint8_t reg; + char name[20]; + char pwr[4][11] = {"Unknown", "USB", "AC", "USB and AC"}; + + sc = device_get_softc(dev); + + am335x_pmic_read(dev, TPS65217_CHIPID_REG, ®, 1); + switch (reg>>4) { + case TPS65217A: + sprintf(name, "TPS65217A ver 1.%u", reg & 0xF); + break; + case TPS65217B: + sprintf(name, "TPS65217B ver 1.%u", reg & 0xF); + break; + default: + sprintf(name, "Unknown PMIC"); + } + + am335x_pmic_read(dev, TPS65217_STATUS_REG, ®, 1); + device_printf(dev, "%s powered by %s\n", name, pwr[(reg>>2)&0x03]); + + config_intrhook_disestablish(&sc->enum_hook); +} + +static int +am335x_pmic_attach(device_t dev) +{ + struct am335x_pmic_softc *sc; + + sc = device_get_softc(dev); + + sc->enum_hook.ich_func = am335x_pmic_start; + sc->enum_hook.ich_arg = dev; + + if (config_intrhook_establish(&sc->enum_hook) != 0) + return (ENOMEM); + + return (0); +} + +static device_method_t am335x_pmic_methods[] = { + DEVMETHOD(device_probe, am335x_pmic_probe), + DEVMETHOD(device_attach, am335x_pmic_attach), + {0, 0}, +}; + +static driver_t am335x_pmic_driver = { + "am335x_pmic", + am335x_pmic_methods, + sizeof(struct am335x_pmic_softc), +}; + +static devclass_t am335x_pmic_devclass; + +DRIVER_MODULE(am335x_pmic, iicbus, am335x_pmic_driver, am335x_pmic_devclass, 0, 0); +MODULE_VERSION(am335x_pmic, 1); +MODULE_DEPEND(am335x_pmic, iicbus, 1, 1, 1); Added: soc2012/aleek/beaglexm-armv6/sys/arm/ti/am37x/am37x_prcm.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2012/aleek/beaglexm-armv6/sys/arm/ti/am37x/am37x_prcm.c Tue Jun 5 19:47:07 2012 (r237153) @@ -0,0 +1,534 @@ +/*- + * Copyright (c) 2012 Damjan Marion <dmarion@Freebsd.org> + * 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 <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/bus.h> +#include <sys/kernel.h> +#include <sys/module.h> +#include <sys/malloc.h> +#include <sys/rman.h> +#include <sys/timeet.h> +#include <sys/timetc.h> +#include <sys/watchdog.h> +#include <machine/bus.h> +#include <machine/cpu.h> +#include <machine/frame.h> +#include <machine/intr.h> + +#include <arm/ti/tivar.h> +#include <arm/ti/ti_scm.h> +#include <arm/ti/ti_prcm.h> + +#include <dev/fdt/fdt_common.h> +#include <dev/ofw/openfirm.h> +#include <dev/ofw/ofw_bus.h> +#include <dev/ofw/ofw_bus_subr.h> + +#include <machine/bus.h> +#include <machine/fdt.h> + +#define CM_PER 0 +#define CM_PER_L4LS_CLKSTCTRL (CM_PER + 0x000) +#define CM_PER_L3S_CLKSTCTRL (CM_PER + 0x004) +#define CM_PER_L3_CLKSTCTRL (CM_PER + 0x00C) +#define CM_PER_CPGMAC0_CLKCTRL (CM_PER + 0x014) +#define CM_PER_USB0_CLKCTRL (CM_PER + 0x01C) +#define CM_PER_TPTC0_CLKCTRL (CM_PER + 0x024) +#define CM_PER_MMC0_CLKCTRL (CM_PER + 0x03C) +#define CM_PER_I2C2_CLKCTRL (CM_PER + 0x044) +#define CM_PER_I2C1_CLKCTRL (CM_PER + 0x048) +#define CM_PER_TIMER7_CLKCTRL (CM_PER + 0x07C) +#define CM_PER_TIMER2_CLKCTRL (CM_PER + 0x080) +#define CM_PER_TIMER3_CLKCTRL (CM_PER + 0x084) +#define CM_PER_TIMER4_CLKCTRL (CM_PER + 0x088) +#define CM_PER_GPIO1_CLKCTRL (CM_PER + 0x0AC) +#define CM_PER_GPIO2_CLKCTRL (CM_PER + 0x0B0) +#define CM_PER_GPIO3_CLKCTRL (CM_PER + 0x0B4) +#define CM_PER_TPCC_CLKCTRL (CM_PER + 0x0BC) +#define CM_PER_L3_INSTR_CLKCTRL (CM_PER + 0x0DC) +#define CM_PER_L3_CLKCTRL (CM_PER + 0x0E0) +#define CM_PER_TIMER5_CLKCTRL (CM_PER + 0x0EC) +#define CM_PER_TIMER6_CLKCTRL (CM_PER + 0x0F0) +#define CM_PER_MMC1_CLKCTRL (CM_PER + 0x0F4) +#define CM_PER_MMC2_CLKCTRL (CM_PER + 0x0F8) +#define CM_PER_TPTC1_CLKCTRL (CM_PER + 0x0FC) +#define CM_PER_TPTC2_CLKCTRL (CM_PER + 0x100) +#define CM_PER_OCPWP_L3_CLKSTCTRL (CM_PER + 0x12C) +#define CM_PER_OCPWP_CLKCTRL (CM_PER + 0x130) +#define CM_PER_CPSW_CLKSTCTRL (CM_PER + 0x144) + +#define CM_WKUP 0x400 +#define CM_WKUP_CLKSTCTRL (CM_WKUP + 0x000) +#define CM_WKUP_CONTROL_CLKCTRL (CM_WKUP + 0x004) +#define CM_WKUP_GPIO0_CLKCTRL (CM_WKUP + 0x008) +#define CM_WKUP_CM_L3_AON_CLKSTCTRL (CM_WKUP + 0x01C) +#define CM_WKUP_CM_CLKSEL_DPLL_MPU (CM_WKUP + 0x02C) +#define CM_WKUP_CM_CLKDCOLDO_DPLL_PER (CM_WKUP + 0x07C) +#define CM_WKUP_I2C0_CLKCTRL (CM_WKUP + 0x0B8) + +#define CM_DPLL 0x500 +#define CLKSEL_TIMER7_CLK (CM_DPLL + 0x004) +#define CLKSEL_TIMER2_CLK (CM_DPLL + 0x008) +#define CLKSEL_TIMER3_CLK (CM_DPLL + 0x00C) +#define CLKSEL_TIMER4_CLK (CM_DPLL + 0x010) +#define CLKSEL_TIMER5_CLK (CM_DPLL + 0x018) +#define CLKSEL_TIMER6_CLK (CM_DPLL + 0x01C) + +#define PRM_DEVICE_OFFSET 0xF00 +#define PRM_RSTCTRL (PRM_DEVICE_OFFSET + 0x00) + +struct am335x_prcm_softc { + struct resource * res[2]; + bus_space_tag_t bst; + bus_space_handle_t bsh; +}; + +static struct resource_spec am335x_prcm_spec[] = { + { SYS_RES_MEMORY, 0, RF_ACTIVE }, + { -1, 0 } +}; + +static struct am335x_prcm_softc *am335x_prcm_sc = NULL; + +static int am335x_clk_generic_activate(struct ti_clock_dev *clkdev); +static int am335x_clk_generic_deactivate(struct ti_clock_dev *clkdev); +static int am335x_clk_generic_set_source(struct ti_clock_dev *clkdev, clk_src_t clksrc); +static int am335x_clk_hsmmc_get_source_freq(struct ti_clock_dev *clkdev, unsigned int *freq); +static int am335x_clk_get_sysclk_freq(struct ti_clock_dev *clkdev, unsigned int *freq); +static int am335x_clk_get_arm_fclk_freq(struct ti_clock_dev *clkdev, unsigned int *freq); +static void am335x_prcm_reset(void); +static int am335x_clk_cpsw_activate(struct ti_clock_dev *clkdev); +static int am335x_clk_musb0_activate(struct ti_clock_dev *clkdev); + +#define AM335X_GENERIC_CLOCK_DEV(i) \ + { .id = (i), \ + .clk_activate = am335x_clk_generic_activate, \ + .clk_deactivate = am335x_clk_generic_deactivate, \ + .clk_set_source = am335x_clk_generic_set_source, \ + .clk_accessible = NULL, \ + .clk_get_source_freq = NULL \ + } + +#define AM335X_MMCHS_CLOCK_DEV(i) \ + { .id = (i), \ + .clk_activate = am335x_clk_generic_activate, \ + .clk_deactivate = am335x_clk_generic_deactivate, \ + .clk_set_source = am335x_clk_generic_set_source, \ + .clk_accessible = NULL, \ + .clk_get_source_freq = am335x_clk_hsmmc_get_source_freq \ + } + +struct ti_clock_dev ti_clk_devmap[] = { + /* System clocks */ + { .id = SYS_CLK, + .clk_activate = NULL, + .clk_deactivate = NULL, + .clk_set_source = NULL, + .clk_accessible = NULL, + .clk_get_source_freq = am335x_clk_get_sysclk_freq, + }, + /* MPU (ARM) core clocks */ + { .id = MPU_CLK, + .clk_activate = NULL, + .clk_deactivate = NULL, + .clk_set_source = NULL, + .clk_accessible = NULL, + .clk_get_source_freq = am335x_clk_get_arm_fclk_freq, + }, + /* CPSW Ethernet Switch core clocks */ + { .id = CPSW_CLK, + .clk_activate = am335x_clk_cpsw_activate, + .clk_deactivate = NULL, + .clk_set_source = NULL, + .clk_accessible = NULL, + .clk_get_source_freq = NULL, + }, + + /* Mentor USB HS controller core clocks */ + { .id = MUSB0_CLK, + .clk_activate = am335x_clk_musb0_activate, + .clk_deactivate = NULL, + .clk_set_source = NULL, + .clk_accessible = NULL, + .clk_get_source_freq = NULL, + }, + + /* DMTimer */ + AM335X_GENERIC_CLOCK_DEV(DMTIMER2_CLK), + AM335X_GENERIC_CLOCK_DEV(DMTIMER3_CLK), + AM335X_GENERIC_CLOCK_DEV(DMTIMER4_CLK), + AM335X_GENERIC_CLOCK_DEV(DMTIMER5_CLK), + AM335X_GENERIC_CLOCK_DEV(DMTIMER6_CLK), + AM335X_GENERIC_CLOCK_DEV(DMTIMER7_CLK), + + /* GPIO */ + AM335X_GENERIC_CLOCK_DEV(GPIO0_CLK), + AM335X_GENERIC_CLOCK_DEV(GPIO1_CLK), + AM335X_GENERIC_CLOCK_DEV(GPIO2_CLK), + AM335X_GENERIC_CLOCK_DEV(GPIO3_CLK), + + /* I2C */ + AM335X_GENERIC_CLOCK_DEV(I2C0_CLK), + AM335X_GENERIC_CLOCK_DEV(I2C1_CLK), + AM335X_GENERIC_CLOCK_DEV(I2C2_CLK), + + /* EDMA */ + AM335X_GENERIC_CLOCK_DEV(EDMA_TPCC_CLK), + AM335X_GENERIC_CLOCK_DEV(EDMA_TPTC0_CLK), + AM335X_GENERIC_CLOCK_DEV(EDMA_TPTC1_CLK), + AM335X_GENERIC_CLOCK_DEV(EDMA_TPTC2_CLK), + + /* MMCHS */ + AM335X_MMCHS_CLOCK_DEV(MMC0_CLK), + AM335X_MMCHS_CLOCK_DEV(MMC1_CLK), + AM335X_MMCHS_CLOCK_DEV(MMC2_CLK), + + { INVALID_CLK_IDENT, NULL, NULL, NULL, NULL } +}; + +struct am335x_clk_details { + clk_ident_t id; + uint32_t clkctrl_reg; + uint32_t clksel_reg; +}; + +#define _CLK_DETAIL(i, c, s) \ + { .id = (i), \ + .clkctrl_reg = (c), \ + .clksel_reg = (s), \ + } *** DIFF OUTPUT TRUNCATED AT 1000 LINES ***
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120605194708.58AB41065670>