Index: head/sys/conf/files.powerpc =================================================================== --- head/sys/conf/files.powerpc (revision 316379) +++ head/sys/conf/files.powerpc (revision 316380) @@ -1,259 +1,260 @@ # This file tells config what files go into building a kernel, # files marked standard are always included. # # $FreeBSD$ # # The long compile-with and dependency lines are required because of # limitations in config: backslash-newline doesn't work in strings, and # dependency lines other than the first are silently ignored. # # font.h optional sc \ compile-with "uudecode < /usr/share/syscons/fonts/${SC_DFLT_FONT}-8x16.fnt && file2c 'u_char dflt_font_16[16*256] = {' '};' < ${SC_DFLT_FONT}-8x16 > font.h && uudecode < /usr/share/syscons/fonts/${SC_DFLT_FONT}-8x14.fnt && file2c 'u_char dflt_font_14[14*256] = {' '};' < ${SC_DFLT_FONT}-8x14 >> font.h && uudecode < /usr/share/syscons/fonts/${SC_DFLT_FONT}-8x8.fnt && file2c 'u_char dflt_font_8[8*256] = {' '};' < ${SC_DFLT_FONT}-8x8 >> font.h" \ no-obj no-implicit-rule before-depend \ clean "font.h ${SC_DFLT_FONT}-8x14 ${SC_DFLT_FONT}-8x16 ${SC_DFLT_FONT}-8x8" # # There is only an asm version on ppc64. cddl/compat/opensolaris/kern/opensolaris_atomic.c optional zfs powerpc | dtrace powerpc compile-with "${ZFS_C}" cddl/contrib/opensolaris/common/atomic/powerpc64/opensolaris_atomic.S optional zfs powerpc64 | dtrace powerpc64 compile-with "${ZFS_S}" cddl/dev/dtrace/powerpc/dtrace_asm.S optional dtrace compile-with "${DTRACE_S}" cddl/dev/dtrace/powerpc/dtrace_subr.c optional dtrace compile-with "${DTRACE_C}" cddl/dev/fbt/powerpc/fbt_isa.c optional dtrace_fbt | dtraceall compile-with "${FBT_C}" crypto/blowfish/bf_enc.c optional crypto | ipsec | ipsec_support crypto/des/des_enc.c optional crypto | ipsec | ipsec_support | netsmb dev/bm/if_bm.c optional bm powermac dev/adb/adb_bus.c optional adb dev/adb/adb_kbd.c optional adb dev/adb/adb_mouse.c optional adb dev/adb/adb_hb_if.m optional adb dev/adb/adb_if.m optional adb dev/adb/adb_buttons.c optional adb dev/agp/agp_apple.c optional agp powermac dev/fb/fb.c optional sc dev/fdt/fdt_powerpc.c optional fdt # ofwbus depends on simplebus. dev/fdt/simplebus.c optional aim | fdt dev/hwpmc/hwpmc_e500.c optional hwpmc dev/hwpmc/hwpmc_mpc7xxx.c optional hwpmc dev/hwpmc/hwpmc_powerpc.c optional hwpmc dev/hwpmc/hwpmc_ppc970.c optional hwpmc dev/iicbus/ad7417.c optional ad7417 powermac dev/iicbus/adm1030.c optional powermac windtunnel | adm1030 powermac dev/iicbus/adt746x.c optional adt746x powermac dev/iicbus/ds1631.c optional ds1631 powermac dev/iicbus/ds1775.c optional ds1775 powermac dev/iicbus/max6690.c optional max6690 powermac dev/iicbus/ofw_iicbus.c optional iicbus aim dev/nand/nfc_fsl.c optional nand mpc85xx dev/nand/nfc_rb.c optional nand mpc85xx # ofw can be either aim or fdt: fdt case handled in files. aim only powerpc specific. dev/ofw/openfirm.c optional aim dev/ofw/openfirmio.c optional aim dev/ofw/ofw_bus_if.m optional aim dev/ofw/ofw_cpu.c optional aim dev/ofw/ofw_if.m optional aim dev/ofw/ofw_bus_subr.c optional aim dev/ofw/ofw_console.c optional aim dev/ofw/ofw_disk.c optional ofwd aim dev/ofw/ofwbus.c optional aim | fdt dev/ofw/ofwpci.c optional pci dev/ofw/ofw_standard.c optional aim powerpc dev/ofw/ofw_subr.c optional aim powerpc dev/powermac_nvram/powermac_nvram.c optional powermac_nvram powermac dev/quicc/quicc_bfe_fdt.c optional quicc mpc85xx dev/scc/scc_bfe_macio.c optional scc powermac dev/sdhci/fsl_sdhci.c optional mpc85xx sdhci dev/sec/sec.c optional sec mpc85xx dev/sound/macio/aoa.c optional snd_davbus | snd_ai2s powermac dev/sound/macio/davbus.c optional snd_davbus powermac dev/sound/macio/i2s.c optional snd_ai2s powermac dev/sound/macio/onyx.c optional snd_ai2s iicbus powermac dev/sound/macio/snapper.c optional snd_ai2s iicbus powermac dev/sound/macio/tumbler.c optional snd_ai2s iicbus powermac dev/syscons/scgfbrndr.c optional sc dev/syscons/scterm-teken.c optional sc dev/syscons/scvtb.c optional sc dev/tsec/if_tsec.c optional tsec dev/tsec/if_tsec_fdt.c optional tsec fdt dev/uart/uart_cpu_powerpc.c optional uart dev/usb/controller/ehci_fsl.c optional ehci mpc85xx dev/vt/hw/ofwfb/ofwfb.c optional vt aim kern/kern_clocksource.c standard kern/subr_dummy_vdso_tc.c standard kern/syscalls.c optional ktr kern/subr_sfbuf.c standard libkern/ashldi3.c optional powerpc | powerpcspe libkern/ashrdi3.c optional powerpc | powerpcspe libkern/bcmp.c standard libkern/cmpdi2.c optional powerpc | powerpcspe libkern/divdi3.c optional powerpc | powerpcspe libkern/ffs.c standard libkern/ffsl.c standard libkern/ffsll.c standard libkern/fls.c standard libkern/flsl.c standard libkern/flsll.c standard libkern/lshrdi3.c optional powerpc | powerpcspe libkern/memmove.c standard libkern/memset.c standard libkern/moddi3.c optional powerpc | powerpcspe libkern/qdivrem.c optional powerpc | powerpcspe libkern/ucmpdi2.c optional powerpc | powerpcspe libkern/udivdi3.c optional powerpc | powerpcspe libkern/umoddi3.c optional powerpc | powerpcspe powerpc/aim/locore.S optional aim no-obj powerpc/aim/aim_machdep.c optional aim powerpc/aim/mmu_oea.c optional aim powerpc powerpc/aim/mmu_oea64.c optional aim powerpc/aim/moea64_if.m optional aim powerpc/aim/moea64_native.c optional aim powerpc/aim/mp_cpudep.c optional aim powerpc/aim/slb.c optional aim powerpc64 powerpc/booke/locore.S optional booke no-obj powerpc/booke/booke_machdep.c optional booke powerpc/booke/machdep_e500.c optional booke_e500 powerpc/booke/mp_cpudep.c optional booke smp powerpc/booke/platform_bare.c optional booke powerpc/booke/pmap.c optional booke powerpc/booke/spe.c optional powerpcspe powerpc/cpufreq/dfs.c optional cpufreq powerpc/cpufreq/pcr.c optional cpufreq aim powerpc/cpufreq/pmufreq.c optional cpufreq aim pmu powerpc/fpu/fpu_add.c optional fpu_emu powerpc/fpu/fpu_compare.c optional fpu_emu powerpc/fpu/fpu_div.c optional fpu_emu powerpc/fpu/fpu_emu.c optional fpu_emu powerpc/fpu/fpu_explode.c optional fpu_emu powerpc/fpu/fpu_implode.c optional fpu_emu powerpc/fpu/fpu_mul.c optional fpu_emu powerpc/fpu/fpu_sqrt.c optional fpu_emu powerpc/fpu/fpu_subr.c optional fpu_emu powerpc/mambo/mambocall.S optional mambo powerpc/mambo/mambo.c optional mambo powerpc/mambo/mambo_console.c optional mambo powerpc/mambo/mambo_disk.c optional mambo powerpc/mikrotik/platform_rb.c optional mikrotik powerpc/mikrotik/rb_led.c optional mikrotik powerpc/mpc85xx/atpic.c optional mpc85xx isa powerpc/mpc85xx/ds1553_bus_fdt.c optional ds1553 fdt powerpc/mpc85xx/ds1553_core.c optional ds1553 powerpc/mpc85xx/fsl_diu.c optional mpc85xx diu +powerpc/mpc85xx/fsl_espi.c optional mpc85xx spibus powerpc/mpc85xx/i2c.c optional iicbus fdt powerpc/mpc85xx/isa.c optional mpc85xx isa powerpc/mpc85xx/lbc.c optional mpc85xx powerpc/mpc85xx/mpc85xx.c optional mpc85xx powerpc/mpc85xx/mpc85xx_gpio.c optional mpc85xx gpio powerpc/mpc85xx/platform_mpc85xx.c optional mpc85xx powerpc/mpc85xx/pci_mpc85xx.c optional pci mpc85xx powerpc/mpc85xx/pci_mpc85xx_pcib.c optional pci mpc85xx powerpc/mpc85xx/qoriq_gpio.c optional mpc85xx gpio powerpc/ofw/ofw_machdep.c standard powerpc/ofw/ofw_pcibus.c optional pci powerpc/ofw/ofw_pcib_pci.c optional pci powerpc/ofw/ofw_real.c optional aim powerpc/ofw/ofw_syscons.c optional sc aim powerpc/ofw/ofwcall32.S optional aim powerpc powerpc/ofw/ofwcall64.S optional aim powerpc64 powerpc/ofw/ofwmagic.S optional aim powerpc/ofw/openpic_ofw.c optional aim | fdt powerpc/ofw/rtas.c optional aim powerpc/powermac/ata_kauai.c optional powermac ata | powermac atamacio powerpc/powermac/ata_macio.c optional powermac ata | powermac atamacio powerpc/powermac/ata_dbdma.c optional powermac ata | powermac atamacio powerpc/powermac/atibl.c optional powermac atibl powerpc/powermac/cuda.c optional powermac cuda powerpc/powermac/cpcht.c optional powermac pci powerpc/powermac/dbdma.c optional powermac pci powerpc/powermac/fcu.c optional powermac fcu powerpc/powermac/grackle.c optional powermac pci powerpc/powermac/hrowpic.c optional powermac pci powerpc/powermac/kiic.c optional powermac kiic powerpc/powermac/macgpio.c optional powermac pci powerpc/powermac/macio.c optional powermac pci powerpc/powermac/nvbl.c optional powermac nvbl powerpc/powermac/platform_powermac.c optional powermac powerpc/powermac/powermac_thermal.c optional powermac powerpc/powermac/pswitch.c optional powermac pswitch powerpc/powermac/pmu.c optional powermac pmu powerpc/powermac/smu.c optional powermac smu powerpc/powermac/smusat.c optional powermac smu powerpc/powermac/uninorth.c optional powermac powerpc/powermac/uninorthpci.c optional powermac pci powerpc/powermac/vcoregpio.c optional powermac powerpc/powerpc/altivec.c optional powerpc | powerpc64 powerpc/powerpc/autoconf.c standard powerpc/powerpc/bcopy.c standard powerpc/powerpc/bus_machdep.c standard powerpc/powerpc/busdma_machdep.c standard powerpc/powerpc/clock.c standard powerpc/powerpc/copyinout.c standard powerpc/powerpc/copystr.c standard powerpc/powerpc/cpu.c standard powerpc/powerpc/db_disasm.c optional ddb powerpc/powerpc/db_hwwatch.c optional ddb powerpc/powerpc/db_interface.c optional ddb powerpc/powerpc/db_trace.c optional ddb powerpc/powerpc/dump_machdep.c standard powerpc/powerpc/elf32_machdep.c optional powerpc | powerpcspe | compat_freebsd32 powerpc/powerpc/elf64_machdep.c optional powerpc64 powerpc/powerpc/exec_machdep.c standard powerpc/powerpc/fpu.c standard powerpc/powerpc/fuswintr.c standard powerpc/powerpc/gdb_machdep.c optional gdb powerpc/powerpc/in_cksum.c optional inet | inet6 powerpc/powerpc/interrupt.c standard powerpc/powerpc/intr_machdep.c standard powerpc/powerpc/iommu_if.m standard powerpc/powerpc/machdep.c standard powerpc/powerpc/mem.c optional mem powerpc/powerpc/mmu_if.m standard powerpc/powerpc/mp_machdep.c optional smp powerpc/powerpc/nexus.c standard powerpc/powerpc/openpic.c standard powerpc/powerpc/pic_if.m standard powerpc/powerpc/pmap_dispatch.c standard powerpc/powerpc/platform.c standard powerpc/powerpc/platform_if.m standard powerpc/powerpc/ptrace_machdep.c standard powerpc/powerpc/sc_machdep.c optional sc powerpc/powerpc/setjmp.S standard powerpc/powerpc/sigcode32.S optional powerpc | powerpcspe | compat_freebsd32 powerpc/powerpc/sigcode64.S optional powerpc64 powerpc/powerpc/swtch32.S optional powerpc | powerpcspe powerpc/powerpc/swtch64.S optional powerpc64 powerpc/powerpc/stack_machdep.c optional ddb | stack powerpc/powerpc/suswintr.c standard powerpc/powerpc/syncicache.c standard powerpc/powerpc/sys_machdep.c standard powerpc/powerpc/trap.c standard powerpc/powerpc/uio_machdep.c standard powerpc/powerpc/uma_machdep.c standard powerpc/powerpc/vm_machdep.c standard powerpc/ps3/ehci_ps3.c optional ps3 ehci powerpc/ps3/ohci_ps3.c optional ps3 ohci powerpc/ps3/if_glc.c optional ps3 glc powerpc/ps3/mmu_ps3.c optional ps3 powerpc/ps3/platform_ps3.c optional ps3 powerpc/ps3/ps3bus.c optional ps3 powerpc/ps3/ps3cdrom.c optional ps3 scbus powerpc/ps3/ps3disk.c optional ps3 powerpc/ps3/ps3pic.c optional ps3 powerpc/ps3/ps3_syscons.c optional ps3 vt powerpc/ps3/ps3-hvcall.S optional ps3 powerpc/pseries/phyp-hvcall.S optional pseries powerpc64 powerpc/pseries/mmu_phyp.c optional pseries powerpc64 powerpc/pseries/phyp_console.c optional pseries powerpc64 uart powerpc/pseries/phyp_llan.c optional llan powerpc/pseries/phyp_vscsi.c optional pseries powerpc64 scbus powerpc/pseries/platform_chrp.c optional pseries powerpc/pseries/plpar_iommu.c optional pseries powerpc64 powerpc/pseries/plpar_pcibus.c optional pseries powerpc64 pci powerpc/pseries/rtas_dev.c optional pseries powerpc/pseries/rtas_pci.c optional pseries pci powerpc/pseries/vdevice.c optional pseries powerpc64 powerpc/pseries/xics.c optional pseries powerpc64 powerpc/psim/iobus.c optional psim powerpc/psim/ata_iobus.c optional ata psim powerpc/psim/openpic_iobus.c optional psim powerpc/psim/uart_iobus.c optional uart psim Index: head/sys/powerpc/conf/MPC85XX =================================================================== --- head/sys/powerpc/conf/MPC85XX (revision 316379) +++ head/sys/powerpc/conf/MPC85XX (revision 316380) @@ -1,111 +1,113 @@ # # Custom kernel for Freescale MPC85XX development boards like the CDS etc. # # $FreeBSD$ # cpu BOOKE cpu BOOKE_E500 ident MPC85XX machine powerpc powerpc include "dpaa/config.dpaa" makeoptions DEBUG="-Wa,-me500 -g" makeoptions WERROR="-Werror -Wno-format -Wno-redundant-decls" makeoptions NO_MODULES=yes options FPU_EMU options _KPOSIX_PRIORITY_SCHEDULING options ALT_BREAK_TO_DEBUGGER options BREAK_TO_DEBUGGER options BOOTP options BOOTP_NFSROOT #options BOOTP_NFSV3 options CD9660 options COMPAT_43 options DDB #options DEADLKRES options DEVICE_POLLING #options DIAGNOSTIC options FDT #makeoptions FDT_DTS_FILE=mpc8555cds.dts options FFS options GDB options GEOM_PART_GPT options INET options INET6 options TCP_HHOOK # hhook(9) framework for TCP options INVARIANTS options INVARIANT_SUPPORT options KDB options KTRACE options MD_ROOT options MPC85XX options MSDOSFS options NFS_ROOT options NFSCL options NFSLOCKD options PROCFS options PSEUDOFS options SCHED_ULE options CAPABILITIES options CAPABILITY_MODE options SMP options SYSVMSG options SYSVSEM options SYSVSHM options WITNESS options WITNESS_SKIPSPIN options COMPAT_FREEBSD10 options COMPAT_FREEBSD11 options HWPMC_HOOKS options KDTRACE_HOOKS # Kernel DTrace hooks options DDB_CTF # Kernel ELF linker loads CTF data device ata device bpf device cfi device crypto device cryptodev device da device ds1553 device em device alc device ether device fxp device gpio device gpiopower device iic device iicbus #device isa device loop device md device miibus device mmc device mmcsd device pass device pci device quicc device random #device rl device scbus device scc device sec +device spibus +device spigen device tsec device dpaa device tun device uart options USB_DEBUG # enable debug msgs #device uhci device ehci device umass device usb device vlan # P1022 DIU device diu device videomode device vt device fbd Index: head/sys/powerpc/conf/MPC85XXSPE =================================================================== --- head/sys/powerpc/conf/MPC85XXSPE (revision 316379) +++ head/sys/powerpc/conf/MPC85XXSPE (revision 316380) @@ -1,112 +1,114 @@ # # Custom kernel for Freescale MPC85XX development boards like the CDS etc. # # $FreeBSD$ # cpu BOOKE cpu BOOKE_E500 ident MPC85XX machine powerpc powerpcspe include "dpaa/config.dpaa" makeoptions DEBUG="-Wa,-me500 -g" makeoptions WERROR="-Werror -Wno-format -Wno-redundant-decls" makeoptions NO_MODULES=yes options FPU_EMU options _KPOSIX_PRIORITY_SCHEDULING options ALT_BREAK_TO_DEBUGGER options BREAK_TO_DEBUGGER options BOOTP options BOOTP_NFSROOT #options BOOTP_NFSV3 options CD9660 options COMPAT_43 options DDB #options DEADLKRES options DEVICE_POLLING #options DIAGNOSTIC options FDT #makeoptions FDT_DTS_FILE=mpc8555cds.dts options FFS options GDB options GEOM_PART_GPT options INET options INET6 options TCP_HHOOK # hhook(9) framework for TCP options INVARIANTS options INVARIANT_SUPPORT options KDB options KTRACE options MD_ROOT options MPC85XX options MSDOSFS options NFS_ROOT options NFSCL options NFSLOCKD options PROCFS options PSEUDOFS options SCHED_ULE options CAPABILITIES options CAPABILITY_MODE options SMP options SYSVMSG options SYSVSEM options SYSVSHM options WITNESS options WITNESS_SKIPSPIN options COMPAT_FREEBSD10 options COMPAT_FREEBSD11 options HWPMC_HOOKS options KDTRACE_HOOKS # Kernel DTrace hooks options DDB_CTF # Kernel ELF linker loads CTF data device ata device bpf device cfi device crypto device cryptodev device da device ds1553 device em device alc device ether device fxp device gpio device gpiopower device iic device iicbus #device isa device loop device md device miibus device mmc device mmcsd device pass device pci device quicc device random #device rl device scbus device scc device sdhci device sec +device spibus +device spigen device tsec device dpaa device tun device uart options USB_DEBUG # enable debug msgs #device uhci device ehci device umass device usb device vlan # P1022 DIU device diu device videomode device vt device fbd Index: head/sys/powerpc/mpc85xx/fsl_espi.c =================================================================== --- head/sys/powerpc/mpc85xx/fsl_espi.c (nonexistent) +++ head/sys/powerpc/mpc85xx/fsl_espi.c (revision 316380) @@ -0,0 +1,434 @@ +/*- + * Copyright (c) 2017 Justin Hibbits + * 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 +#include + +#include +#include + +#include + +#include "spibus_if.h" + +/* TODO: + * + * Optimize FIFO reads and writes to do word-at-a-time instead of byte-at-a-time + */ +#define ESPI_SPMODE 0x0 +#define ESPI_SPMODE_EN 0x80000000 +#define ESPI_SPMODE_LOOP 0x40000000 +#define ESPI_SPMODE_HO_ADJ_M 0x00070000 +#define ESPI_SPMODE_TXTHR_M 0x00003f00 +#define ESPI_SPMODE_TXTHR_S 8 +#define ESPI_SPMODE_RXTHR_M 0x0000001f +#define ESPI_SPMODE_RXTHR_S 0 +#define ESPI_SPIE 0x4 +#define ESPI_SPIE_RXCNT_M 0x3f000000 +#define ESPI_SPIE_RXCNT_S 24 +#define ESPI_SPIE_TXCNT_M 0x003f0000 +#define ESPI_SPIE_TXCNT_S 16 +#define ESPI_SPIE_TXE 0x00008000 +#define ESPI_SPIE_DON 0x00004000 +#define ESPI_SPIE_RXT 0x00002000 +#define ESPI_SPIE_RXF 0x00001000 +#define ESPI_SPIE_TXT 0x00000800 +#define ESPI_SPIE_RNE 0x00000200 +#define ESPI_SPIE_TNF 0x00000100 +#define ESPI_SPIM 0x8 +#define ESPI_SPCOM 0xc +#define ESPI_SPCOM_CS_M 0xc0000000 +#define ESPI_SPCOM_CS_S 30 +#define ESPI_SPCOM_RXDELAY 0x20000000 +#define ESPI_SPCOM_DO 0x10000000 +#define ESPI_SPCOM_TO 0x08000000 +#define ESPI_SPCOM_HLD 0x04000000 +#define ESPI_SPCOM_RXSKIP_M 0x00ff0000 +#define ESPI_SPCOM_TRANLEN_M 0x0000ffff +#define ESPI_SPITF 0x10 +#define ESPI_SPIRF 0x14 +#define ESPI_SPMODE0 0x20 +#define ESPI_SPMODE1 0x24 +#define ESPI_SPMODE2 0x28 +#define ESPI_SPMODE3 0x2c +#define ESPI_CSMODE_CI 0x80000000 +#define ESPI_CSMODE_CP 0x40000000 +#define ESPI_CSMODE_REV 0x20000000 +#define ESPI_CSMODE_DIV16 0x10000000 +#define ESPI_CSMODE_PM_M 0x0f000000 +#define ESPI_CSMODE_PM_S 24 +#define ESPI_CSMODE_ODD 0x00800000 +#define ESPI_CSMODE_POL 0x00100000 +#define ESPI_CSMODE_LEN_M 0x000f0000 +#define ESPI_CSMODE_LEN(x) (x << 16) +#define ESPI_CSMODE_CSBEF_M 0x0000f000 +#define ESPI_CSMODE_CSAFT_M 0x00000f00 +#define ESPI_CSMODE_CSCG_M 0x000000f8 +#define ESPI_CSMODE_CSCG(x) (x << 3) +#define ESPI_CSMODE(n) (ESPI_SPMODE0 + n * 4) + +#define FSL_ESPI_WRITE(sc,off,val) bus_write_4(sc->sc_mem_res, off, val) +#define FSL_ESPI_READ(sc,off) bus_read_4(sc->sc_mem_res, off) +#define FSL_ESPI_WRITE_FIFO(sc,off,val) bus_write_1(sc->sc_mem_res, off, val) +#define FSL_ESPI_READ_FIFO(sc,off) bus_read_1(sc->sc_mem_res, off) + +#define FSL_ESPI_LOCK(_sc) \ + mtx_lock(&(_sc)->sc_mtx) +#define FSL_ESPI_UNLOCK(_sc) \ + mtx_unlock(&(_sc)->sc_mtx) + +struct fsl_espi_softc +{ + device_t sc_dev; + struct resource *sc_mem_res; + struct resource *sc_irq_res; + struct mtx sc_mtx; + int sc_num_cs; + struct spi_command *sc_cmd; + uint32_t sc_len; + uint32_t sc_read; + uint32_t sc_flags; +#define FSL_ESPI_BUSY 0x00000001 + uint32_t sc_written; + void * sc_intrhand; +}; + +static void fsl_espi_intr(void *); + +static int +fsl_espi_probe(device_t dev) +{ + + if (!ofw_bus_status_okay(dev)) + return (ENXIO); + + if (!ofw_bus_is_compatible(dev, "fsl,mpc8536-espi")) + return (ENXIO); + + device_set_desc(dev, "Freescale eSPI controller"); + + return (BUS_PROBE_DEFAULT); +} + +static int +fsl_espi_attach(device_t dev) +{ + struct fsl_espi_softc *sc; + int rid; + phandle_t node; + + sc = device_get_softc(dev); + sc->sc_dev = dev; + node = ofw_bus_get_node(dev); + + rid = 0; + sc->sc_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, + RF_ACTIVE); + if (!sc->sc_mem_res) { + device_printf(dev, "cannot allocate memory resource\n"); + return (ENXIO); + } + + rid = 0; + sc->sc_irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, + RF_ACTIVE); + if (!sc->sc_irq_res) { + bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->sc_mem_res); + device_printf(dev, "cannot allocate interrupt\n"); + return (ENXIO); + } + + /* Hook up our interrupt handler. */ + if (bus_setup_intr(dev, sc->sc_irq_res, INTR_TYPE_MISC | INTR_MPSAFE, + NULL, fsl_espi_intr, sc, &sc->sc_intrhand)) { + bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sc_irq_res); + bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->sc_mem_res); + device_printf(dev, "cannot setup the interrupt handler\n"); + return (ENXIO); + } + if (OF_getencprop(node, "fsl,espi-num-chipselects", + &sc->sc_num_cs, sizeof(sc->sc_num_cs)) < 0 ) + sc->sc_num_cs = 4; + + mtx_init(&sc->sc_mtx, "fsl_espi", NULL, MTX_DEF); + + /* Enable the SPI controller. */ + FSL_ESPI_WRITE(sc, ESPI_SPMODE, ESPI_SPMODE_EN | + (16 << ESPI_SPMODE_TXTHR_S) | (15 << ESPI_SPMODE_RXTHR_S)); + + /* Disable all interrupts until we start transfers */ + FSL_ESPI_WRITE(sc, ESPI_SPIM, 0); + + device_add_child(dev, "spibus", -1); + + return (bus_generic_attach(dev)); +} + +static int +fsl_espi_detach(device_t dev) +{ + struct fsl_espi_softc *sc; + + bus_generic_detach(dev); + + sc = device_get_softc(dev); + FSL_ESPI_WRITE(sc, ESPI_SPMODE, 0); + + sc = device_get_softc(dev); + mtx_destroy(&sc->sc_mtx); + if (sc->sc_intrhand) + bus_teardown_intr(dev, sc->sc_irq_res, sc->sc_intrhand); + if (sc->sc_irq_res) + bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sc_irq_res); + if (sc->sc_mem_res) + bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->sc_mem_res); + + return (0); +} + +static void +fsl_espi_fill_fifo(struct fsl_espi_softc *sc) +{ + struct spi_command *cmd; + uint32_t spier, written; + uint8_t *data; + + cmd = sc->sc_cmd; + spier = FSL_ESPI_READ(sc, ESPI_SPIE); + while (sc->sc_written < sc->sc_len && + (spier & ESPI_SPIE_TNF)) { + data = (uint8_t *)cmd->tx_cmd; + written = sc->sc_written++; + if (written >= cmd->tx_cmd_sz) { + data = (uint8_t *)cmd->tx_data; + written -= cmd->tx_cmd_sz; + } + FSL_ESPI_WRITE_FIFO(sc, ESPI_SPITF, data[written]); + spier = FSL_ESPI_READ(sc, ESPI_SPIE); + } +} + +static void +fsl_espi_drain_fifo(struct fsl_espi_softc *sc) +{ + struct spi_command *cmd; + uint32_t spier, read; + uint8_t *data; + uint8_t r; + + cmd = sc->sc_cmd; + spier = FSL_ESPI_READ(sc, ESPI_SPIE); + while (sc->sc_read < sc->sc_len && (spier & ESPI_SPIE_RNE)) { + data = (uint8_t *)cmd->rx_cmd; + read = sc->sc_read++; + if (read >= cmd->rx_cmd_sz) { + data = (uint8_t *)cmd->rx_data; + read -= cmd->rx_cmd_sz; + } + r = FSL_ESPI_READ_FIFO(sc, ESPI_SPIRF); + data[read] = r; + spier = FSL_ESPI_READ(sc, ESPI_SPIE); + } +} + +static void +fsl_espi_intr(void *arg) +{ + struct fsl_espi_softc *sc; + uint32_t spie; + + sc = (struct fsl_espi_softc *)arg; + FSL_ESPI_LOCK(sc); + + /* Filter stray interrupts. */ + if ((sc->sc_flags & FSL_ESPI_BUSY) == 0) { + FSL_ESPI_UNLOCK(sc); + return; + } + spie = FSL_ESPI_READ(sc, ESPI_SPIE); + FSL_ESPI_WRITE(sc, ESPI_SPIE, spie); + + /* TX - Fill up the FIFO. */ + fsl_espi_fill_fifo(sc); + + /* RX - Drain the FIFO. */ + fsl_espi_drain_fifo(sc); + + /* Check for end of transfer. */ + if (spie & ESPI_SPIE_DON) + wakeup(sc->sc_dev); + + FSL_ESPI_UNLOCK(sc); +} + +static int +fsl_espi_transfer(device_t dev, device_t child, struct spi_command *cmd) +{ + struct fsl_espi_softc *sc; + u_long plat_clk; + uint32_t csmode, spi_clk, spi_mode; + int cs, err, pm; + + sc = device_get_softc(dev); + + KASSERT(cmd->tx_cmd_sz == cmd->rx_cmd_sz, + ("TX/RX command sizes should be equal")); + KASSERT(cmd->tx_data_sz == cmd->rx_data_sz, + ("TX/RX data sizes should be equal")); + + /* Restrict transmit length to command max length */ + if (cmd->tx_cmd_sz + cmd->tx_data_sz > ESPI_SPCOM_TRANLEN_M + 1) { + return (EINVAL); + } + + /* Get the proper chip select for this child. */ + spibus_get_cs(child, &cs); + if (cs < 0 || cs > sc->sc_num_cs) { + device_printf(dev, + "Invalid chip select %d requested by %s\n", cs, + device_get_nameunit(child)); + return (EINVAL); + } + spibus_get_clock(child, &spi_clk); + spibus_get_mode(child, &spi_mode); + + FSL_ESPI_LOCK(sc); + + /* If the controller is in use wait until it is available. */ + while (sc->sc_flags & FSL_ESPI_BUSY) + mtx_sleep(dev, &sc->sc_mtx, 0, "fsl_espi", 0); + + /* Now we have control over SPI controller. */ + sc->sc_flags = FSL_ESPI_BUSY; + + /* Save a pointer to the SPI command. */ + sc->sc_cmd = cmd; + sc->sc_read = 0; + sc->sc_written = 0; + sc->sc_len = cmd->tx_cmd_sz + cmd->tx_data_sz; + + plat_clk = mpc85xx_get_system_clock(); + spi_clk = max(spi_clk, plat_clk / (16 * 16)); + if (plat_clk == 0) { + device_printf(dev, + "unable to get platform clock, giving up.\n"); + return (EINVAL); + } + csmode = 0; + if (plat_clk > spi_clk * 16 * 2) { + csmode |= ESPI_CSMODE_DIV16; + plat_clk /= 16; + } + pm = howmany(plat_clk, spi_clk * 2) - 1; + if (pm < 0) + pm = 1; + if (pm > 15) + pm = 15; + + csmode |= (pm << ESPI_CSMODE_PM_S); + csmode |= ESPI_CSMODE_REV; + if (spi_mode == SPIBUS_MODE_CPOL || spi_mode == SPIBUS_MODE_CPOL_CPHA) + csmode |= ESPI_CSMODE_CI; + if (spi_mode == SPIBUS_MODE_CPHA || spi_mode == SPIBUS_MODE_CPOL_CPHA) + csmode |= ESPI_CSMODE_CP; + if (!(cs & SPIBUS_CS_HIGH)) + csmode |= ESPI_CSMODE_POL; + csmode |= ESPI_CSMODE_LEN(7);/* Only deal with 8-bit characters. */ + csmode |= ESPI_CSMODE_CSCG(1); /* XXX: Make this configurable? */ + /* Configure transaction */ + FSL_ESPI_WRITE(sc, ESPI_SPCOM, (cs << ESPI_SPCOM_CS_S) | (sc->sc_len - 1)); + FSL_ESPI_WRITE(sc, ESPI_CSMODE(cs), csmode); + /* Enable interrupts we need. */ + FSL_ESPI_WRITE(sc, ESPI_SPIM, + ESPI_SPIE_TXE | ESPI_SPIE_DON | ESPI_SPIE_RXF); + + /* Wait for the transaction to complete. */ + err = mtx_sleep(dev, &sc->sc_mtx, 0, "fsl_espi", hz * 2); + FSL_ESPI_WRITE(sc, ESPI_SPIM, 0); + + /* Release the controller and wakeup the next thread waiting for it. */ + sc->sc_flags = 0; + wakeup_one(dev); + FSL_ESPI_UNLOCK(sc); + + /* + * Check for transfer timeout. The SPI controller doesn't + * return errors. + */ + if (err == EWOULDBLOCK) { + device_printf(sc->sc_dev, "SPI error\n"); + err = EIO; + } + + return (err); +} + +static phandle_t +fsl_espi_get_node(device_t bus, device_t dev) +{ + + /* We only have one child, the SPI bus, which needs our own node. */ + return (ofw_bus_get_node(bus)); +} + +static device_method_t fsl_espi_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, fsl_espi_probe), + DEVMETHOD(device_attach, fsl_espi_attach), + DEVMETHOD(device_detach, fsl_espi_detach), + + /* SPI interface */ + DEVMETHOD(spibus_transfer, fsl_espi_transfer), + + /* ofw_bus interface */ + DEVMETHOD(ofw_bus_get_node, fsl_espi_get_node), + + DEVMETHOD_END +}; + +static devclass_t fsl_espi_devclass; + +static driver_t fsl_espi_driver = { + "spi", + fsl_espi_methods, + sizeof(struct fsl_espi_softc), +}; + +DRIVER_MODULE(fsl_espi, simplebus, fsl_espi_driver, fsl_espi_devclass, 0, 0); Property changes on: head/sys/powerpc/mpc85xx/fsl_espi.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