Index: boot/fdt/dts/am335x-evm.dts =================================================================== --- boot/fdt/dts/am335x-evm.dts (revision 0) +++ boot/fdt/dts/am335x-evm.dts (working copy) @@ -0,0 +1,179 @@ +/*- + * Copyright (c) 2012 Damjan Marion + * 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: head/sys/boot/fdt/dts/beaglebone.dts 249946 2013-04-26 17:27:53Z gonzo $ + */ + +/dts-v1/; + +/include/ "am335x.dtsi" + +/ { + model = "TMDXEVM3358"; + + aliases { + soc = &SOC; + uart0 = &uart0; + }; + + memory { + device_type = "memory"; + reg = < 0x80000000 0x10000000 >; /* 256MB RAM */ + }; + + am335x { + scm@44e10000 { + /* Set of triplets < padname, muxname, padstate> */ + scm-pad-config = + /* I2C0 */ + "I2C0_SDA", "I2C0_SDA","i2c", + "I2C0_SCL", "I2C0_SCL","i2c", + /* Ethernet */ + "MII1_RX_ER", "gmii1_rxerr", "input_pulldown", + "MII1_TX_EN", "gmii1_txen", "output", + "MII1_RX_DV", "gmii1_rxdv", "input_pulldown", + "MII1_TXD3", "gmii1_txd3", "output", + "MII1_TXD2", "gmii1_txd2", "output", + "MII1_TXD1", "gmii1_txd1", "output", + "MII1_TXD0", "gmii1_txd0", "output", + "MII1_TX_CLK", "gmii1_txclk", "input_pulldown", + "MII1_RX_CLK", "gmii1_rxclk", "input_pulldown", + "MII1_RXD3", "gmii1_rxd3", "input_pulldown", + "MII1_RXD2", "gmii1_rxd2", "input_pulldown", + "MII1_RXD1", "gmii1_rxd1", "input_pulldown", + "MII1_RXD0", "gmii1_rxd0", "input_pulldown", + "MDIO", "mdio_data", "input_pullup", + "MDC", "mdio_clk", "output_pullup", + /* MMCSD0 */ + "MMC0_CMD", "mmc0_cmd", "input_pullup", + "MMC0_CLK", "mmc0_clk", "input_pullup", + "MMC0_DAT0", "mmc0_dat0", "input_pullup", + "MMC0_DAT1", "mmc0_dat1", "input_pullup", + "MMC0_DAT2", "mmc0_dat2", "input_pullup", + "MMC0_DAT3", "mmc0_dat3", "input_pullup", + /* GPIO */ + "GPMC_AD10", "gpio0_26", "input_pulldown", + "GPMC_AD11", "gpio0_27", "input_pulldown", + "GPMC_AD0", "gpio1_0", "input_pulldown", + "GPMC_AD1", "gpio1_1", "input_pulldown", + "GPMC_AD2", "gpio1_2", "input_pulldown", + "GPMC_AD3", "gpio1_3", "input_pulldown", + "GPMC_AD4", "gpio1_4", "input_pulldown", + "GPMC_AD5", "gpio1_5", "input_pulldown", + "GPMC_AD6", "gpio1_6", "input_pulldown", + "GPMC_AD7", "gpio1_7", "input_pulldown", + "GPMC_AD12", "gpio1_12", "input_pulldown", + "GPMC_AD13", "gpio1_13", "input_pulldown", + "GPMC_AD14", "gpio1_14", "input_pulldown", + "GPMC_AD15", "gpio1_15", "input_pulldown", + "GPMC_A0", "gpio1_16", "input_pulldown", + "GPMC_A1", "gpio1_17", "input_pulldown", + "GPMC_A5", "gpio1_21", "output", /* User LED 1 */ + "GPMC_A6", "gpio1_22", "output", /* User LED 2 */ + "GPMC_A7", "gpio1_23", "output", /* User LED 3 */ + "GPMC_A8", "gpio1_24", "output", /* User LED 4 */ + "GPMC_BEn1", "gpio1_28", "input_pulldown", + "GPMC_CSn0", "gpio1_29", "input_pulldown", + "GPMC_CSn1", "gpio1_30", "input_pulldown", + "GPMC_CSn2", "gpio1_31", "input_pulldown", + "MCASP0_FSR", "gpio3_19", "input_pulldown", + "MCASP0_AHCLKX", "gpio3_21", "input_pulldown", + /* TIMERs */ + "GPMC_ADVn_ALE", "timer4", "output", + "GPMC_BEn0_CLE", "timer5", "output", + "GPMC_WEn", "timer6", "output", + "GPMC_OEn_REn", "timer7", "output", + /* LCD */ + "GPMC_AD8", "lcd_data23", "output", + "GPMC_AD9", "lcd_data22", "output", + "GPMC_AD10", "lcd_data21", "output", + "GPMC_AD11", "lcd_data20", "output", + "GPMC_AD12", "lcd_data19", "output", + "GPMC_AD13", "lcd_data18", "output", + "GPMC_AD14", "lcd_data17", "output", + "GPMC_AD15", "lcd_data16", "output", + "GPMC_CLK", "lcd_memory_clk", "output", + "LCD_DATA0", "lcd_data0", "output", + "LCD_DATA1", "lcd_data1", "output", + "LCD_DATA2", "lcd_data2", "output", + "LCD_DATA3", "lcd_data3", "output", + "LCD_DATA4", "lcd_data4", "output", + "LCD_DATA5", "lcd_data5", "output", + "LCD_DATA6", "lcd_data6", "output", + "LCD_DATA7", "lcd_data7", "output", + "LCD_DATA8", "lcd_data8", "output", + "LCD_DATA9", "lcd_data9", "output", + "LCD_DATA10", "lcd_data10", "output", + "LCD_DATA11", "lcd_data11", "output", + "LCD_DATA12", "lcd_data12", "output", + "LCD_DATA13", "lcd_data13", "output", + "LCD_DATA14", "lcd_data14", "output", + "LCD_DATA15", "lcd_data15", "output", + "LCD_VSYNC", "lcd_vsync", "output", + "LCD_HSYNC", "lcd_hsync", "output", + "LCD_PCLK", "lcd_pclk", "output", + "LCD_AC_BIAS_EN", "lcd_ac_bias_en", "output", + "ECAP0_IN_PWM0_OUT", "eCAP0_in_PWM0_out", "output"; + + }; + + lcd@4830e000 { + panel_name = "TFC_S9700RTWV35TR_01B"; + panel_width = <800>; + panel_height = <480>; + panel_hfp = <39>; + panel_hbp = <39>; + panel_hsw = <47>; + panel_vfp = <13>; + panel_vbp = <29>; + panel_vsw = <2>; + panel_pxl_clk = <30000000>; + panel_invert_pxl_clk = <0>; + panel_type = <1>; /* Active or passive, compatibility */ + panel_max_bpp = <32>; /* compatibility */ + panel_min_bpp = <32>; /* compatibility */ + panel_shade = <1>; /* compatibility */ + ac_bias = <255>; + ac_bias_intrpt = <0>; + dma_burst_sz = <16>; + bpp = <32>; + fdd = <128>; + tft_alt_mode = <0>; /* compatiblity */ + stn_565_mode = <0>; /* compatibility */ + mono_8bit_mode = <0>; /* compatibilty */ + invert_line_clock = <1>; + invert_frm_clock = <1>; + sync_edge = <0>; + sync_ctrl = <1>; + raster_order = <0>; /* compatibity */ + }; + + }; + + chosen { + stdin = "uart0"; + stdout = "uart0"; + }; +}; Index: boot/fdt/dts/am335x.dtsi =================================================================== --- boot/fdt/dts/am335x.dtsi (revision 250037) +++ boot/fdt/dts/am335x.dtsi (working copy) @@ -142,5 +142,28 @@ interrupt-parent = <&AINTC>; i2c-device-id = <0>; }; + + pwm@48300000 { + compatible = "ti,am335x-pwm"; + #address-cells = <1>; + #size-cells = <1>; + reg = < 0x48300000 0x100 /* PWMSS */ + 0x48300100 0x80 /* eCAP0 */ + 0x48300180 0x80 /* eQEP0 */ + 0x48300200 0x60 /* ePWM0 */ + >; + interrupts = <86 58>; /* ePWM0INT, ePWM0_TZINT */ + interrupt-parent = <&AINTC>; + pwm-device-id = <0>; + }; + + lcd: lcd@4830e000 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "ti,am335x-lcd"; + reg =< 0x4830e000 0x1000 >; + interrupts = <36>; + interrupt-parent = <&AINTC>; + }; }; }; Index: arm/conf/AM335X-EVM =================================================================== --- arm/conf/AM335X-EVM (revision 0) +++ arm/conf/AM335X-EVM (working copy) @@ -0,0 +1,133 @@ +# 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: +# +# http://www.FreeBSD.org/doc/en_US.ISO8859-1/books/handbook/kernelconfig-config.html +# +# The handbook is also available locally in /usr/share/doc/handbook +# if you've installed the doc distribution, otherwise always see the +# FreeBSD World Wide Web server (http://www.FreeBSD.org/) for the +# 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 +# in NOTES. +# +# $FreeBSD: head/sys/arm/conf/BEAGLEBONE 246228 2013-02-02 06:01:57Z kientzle $ + +ident AM335X + +include "../ti/am335x/std.beaglebone" + +makeoptions MODULES_OVERRIDE="" +makeoptions WITHOUT_MODULES="ahc" + +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 TMPFS #Efficient memory filesystem +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 FREEBSD_BOOT_LOADER + +# 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 NFSD +options NFSLOCKD + +# Uncomment this for NFS root +#options NFS_ROOT #NFS usable as /, requires NFSCL +#options BOOTP_NFSROOT +#options BOOTP_COMPAT +#options BOOTP +#options BOOTP_NFSV3 +#options BOOTP_WIRED_TO=cpsw0 + + +# MMC/SD/SDIO card slot support +device mmc # mmc/sd bus +device mmcsd # mmc/sd flash cards + +# Boot device is 2nd slice on MMC/SD card +options ROOTDEVNAME=\"ufs:mmcsd0s2a\" + +# Console and misc +device uart +device uart_ns8250 +device pty +device snp +device md +device random # Entropy device + +# I2C support +device iicbus +device iic +device ti_i2c +device am335x_pmic # AM335x Power Management IC (TPC65217) + +# GPIO +device gpio + +# USB support +device usb +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) + +# Syscons +device sc +device kbdmux +options SC_DFLT_FONT # compile font in +makeoptions SC_DFLT_FONT=cp437 + +# Ethernet +device loop +device ether +device mii +device smscphy +device cpsw +device bpf + +# USB ethernet support, requires miibus +device miibus +device axe # ASIX Electronics USB Ethernet + +# Flattened Device Tree +options FDT +options FDT_DTB_STATIC +makeoptions FDT_DTS_FILE=am335x-evm.dts Index: arm/ti/am335x/am335x_pwm.c =================================================================== --- arm/ti/am335x/am335x_pwm.c (revision 0) +++ arm/ti/am335x/am335x_pwm.c (working copy) @@ -0,0 +1,285 @@ +/*- + * Copyright (c) 2013 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. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include + +#include +#include + +#include "am335x_pwm.h" +#include "am335x_scm.h" + +#define PWM_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx) +#define PWM_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx) +#define PWM_LOCK_INIT(_sc) mtx_init(&(_sc)->sc_mtx, \ + device_get_nameunit(_sc->sc_dev), "am335x_pwm softc", MTX_DEF) +#define PWM_LOCK_DESTROY(_sc) mtx_destroy(&(_sc)->sc_mtx); + +static struct resource_spec am335x_pwm_mem_spec[] = { + { SYS_RES_MEMORY, 0, RF_ACTIVE }, /* PWMSS */ + { SYS_RES_MEMORY, 1, RF_ACTIVE }, /* eCAP */ + { SYS_RES_MEMORY, 2, RF_ACTIVE }, /* eQEP */ + { SYS_RES_MEMORY, 3, RF_ACTIVE }, /*ePWM */ + { -1, 0, 0 } +}; + +#define PWMSS_READ4(_sc, reg) bus_read_4((_sc)->sc_mem_res[0], reg); +#define PWMSS_WRITE4(_sc, reg, value) \ + bus_write_4((_sc)->sc_mem_res[0], reg, value); + +#define ECAP_READ2(_sc, reg) bus_read_2((_sc)->sc_mem_res[1], reg); +#define ECAP_WRITE2(_sc, reg, value) \ + bus_write_2((_sc)->sc_mem_res[1], reg, value); +#define ECAP_READ4(_sc, reg) bus_read_4((_sc)->sc_mem_res[1], reg); +#define ECAP_WRITE4(_sc, reg, value) \ + bus_write_4((_sc)->sc_mem_res[1], reg, value); + +#define EPWM_READ2(_sc, reg) bus_read_2((_sc)->sc_mem_res[3], reg); +#define EPWM_WRITE2(_sc, reg, value) \ + bus_write_2((_sc)->sc_mem_res[3], reg, value); + +#define PWMSS_IDVER 0x00 +#define PWMSS_SYSCONFIG 0x04 +#define PWMSS_CLKCONFIG 0x08 +#define CLKCONFIG_EPWMCLK_EN (1 << 8) +#define PWMSS_CLKSTATUS 0x0C + +#define ECAP_TSCTR 0x00 +#define ECAP_CAP1 0x08 +#define ECAP_CAP2 0x0C +#define ECAP_CAP3 0x10 +#define ECAP_CAP4 0x14 +#define ECAP_ECCTL2 0x2A +#define ECCTL2_MODE_APWM (1 << 9) +#define ECCTL2_SYNCO_SEL (3 << 6) +#define ECCTL2_TSCTRSTOP_FREERUN (1 << 4) + +#define EPWM_TBCTL 0x00 +#define TBCTL_PHDIR_UP (1 << 13) +#define TBCTL_PHDIR_DOWN (0 << 13) +#define TBCTL_CLKDIV(x) ((x) << 10) +#define TBCTL_HSPCLKDIV(x) ((x) << 7) +#define TBCTL_SYNCOSEL_DISABLED (3 << 4) +#define TBCTL_PRDLD_SHADOW (0 << 3) +#define TBCTL_PRDLD_IMMEDIATE (0 << 3) +#define TBCTL_PHSEN_ENABLED (1 << 2) +#define TBCTL_PHSEN_DISABLED (0 << 2) +#define EPWM_TBSTS 0x02 +#define EPWM_TBPHSHR 0x04 +#define EPWM_TBPHS 0x06 +#define EPWM_TBCNT 0x08 +#define EPWM_TBPRD 0x0a +/* Counter-compare */ +#define EPWM_CMPCTL 0x0e +#define CMPCTL_SHDWBMODE_SHADOW (1 << 6) +#define CMPCTL_SHDWBMODE_IMMEDIATE (0 << 6) +#define CMPCTL_SHDWAMODE_SHADOW (1 << 4) +#define CMPCTL_SHDWAMODE_IMMEDIATE (0 << 4) +#define CMPCTL_LOADBMODE_ZERO (0 << 2) +#define CMPCTL_LOADBMODE_PRD (1 << 2) +#define CMPCTL_LOADBMODE_EITHER (2 << 2) +#define CMPCTL_LOADBMODE_FREEZE (3 << 2) +#define CMPCTL_LOADAMODE_ZERO (0 << 0) +#define CMPCTL_LOADAMODE_PRD (1 << 0) +#define CMPCTL_LOADAMODE_EITHER (2 << 0) +#define CMPCTL_LOADAMODE_FREEZE (3 << 0) +#define EPWM_CMPAHR 0x10 +#define EPWM_CMPA 0x12 +#define EPWM_CMPB 0x14 +/* CMPCTL_LOADAMODE_ZERO */ +#define EPWM_AQCTLA 0x16 +#define EPWM_AQCTLB 0x18 +#define AQCTL_CAU_NONE (0 << 0) +#define AQCTL_CAU_CLEAR (1 << 0) +#define AQCTL_CAU_SET (2 << 0) +#define AQCTL_CAU_TOGGLE (3 << 0) +#define AQCTL_ZRO_NONE (0 << 0) +#define AQCTL_ZRO_CLEAR (1 << 0) +#define AQCTL_ZRO_SET (2 << 0) +#define AQCTL_ZRO_TOGGLE (3 << 0) +#define EPWM_AQSFRC 0x1a +#define EPWM_AQCSFRC 0x1c + +static device_probe_t am335x_pwm_probe; +static device_attach_t am335x_pwm_attach; +static device_detach_t am335x_pwm_detach; + +struct am335x_pwm_softc { + device_t sc_dev; + struct mtx sc_mtx; + struct resource *sc_mem_res[4]; + int sc_id; +}; + +static device_method_t am335x_pwm_methods[] = { + DEVMETHOD(device_probe, am335x_pwm_probe), + DEVMETHOD(device_attach, am335x_pwm_attach), + DEVMETHOD(device_detach, am335x_pwm_detach), + + DEVMETHOD_END +}; + +static driver_t am335x_pwm_driver = { + "am335x_pwm", + am335x_pwm_methods, + sizeof(struct am335x_pwm_softc), +}; + +static devclass_t am335x_pwm_devclass; + +/* + * API function to set period/duty cycles for ECASx + */ +int +am335x_pwm_config_ecas(int unit, int period, int duty) +{ + device_t dev; + struct am335x_pwm_softc *sc; + uint16_t reg; + + dev = devclass_get_device(am335x_pwm_devclass, unit); + if (dev == NULL) + return (ENXIO); + + if (duty > period) + return (EINVAL); + + if (period == 0) + return (EINVAL); + + sc = device_get_softc(dev); + PWM_LOCK(sc); + + reg = ECAP_READ2(sc, ECAP_ECCTL2); + reg |= ECCTL2_MODE_APWM | ECCTL2_TSCTRSTOP_FREERUN | ECCTL2_SYNCO_SEL; + ECAP_WRITE2(sc, ECAP_ECCTL2, reg); + + /* CAP3 in APWM mode is APRD shadow register */ + ECAP_WRITE4(sc, ECAP_CAP3, period - 1); + + /* CAP4 in APWM mode is ACMP shadow register */ + ECAP_WRITE4(sc, ECAP_CAP4, duty); + /* Restart counter */ + ECAP_WRITE4(sc, ECAP_TSCTR, 0); + + PWM_UNLOCK(sc); + + return (0); +} + +static int +am335x_pwm_probe(device_t dev) +{ + if (!ofw_bus_is_compatible(dev, "ti,am335x-pwm")) + return (ENXIO); + + device_set_desc(dev, "AM335x PWM"); + + return (BUS_PROBE_DEFAULT); +} + +static int +am335x_pwm_attach(device_t dev) +{ + struct am335x_pwm_softc *sc; + int err; + uint32_t reg; + phandle_t node; + pcell_t did; + + sc = device_get_softc(dev); + sc->sc_dev = dev; + /* Get the PWM module id */ + node = ofw_bus_get_node(dev); + if ((OF_getprop(node, "pwm-device-id", &did, sizeof(did))) <= 0) { + device_printf(dev, "missing pwm-device-id attribute in FDT\n"); + return (ENXIO); + } + sc->sc_id = fdt32_to_cpu(did); + + PWM_LOCK_INIT(sc); + + err = bus_alloc_resources(dev, am335x_pwm_mem_spec, + sc->sc_mem_res); + if (err) { + device_printf(dev, "cannot allocate memory resources\n"); + goto fail; + } + + ti_prcm_clk_enable(PWMSS0_CLK + sc->sc_id); + ti_scm_reg_read_4(SCM_PWMSS_CTRL, ®); + reg |= (1 << sc->sc_id); + ti_scm_reg_write_4(SCM_PWMSS_CTRL, reg); + + return (0); +fail: + PWM_LOCK_DESTROY(sc); + if (sc->sc_mem_res[0]) + bus_release_resources(dev, am335x_pwm_mem_spec, + sc->sc_mem_res); + + return(ENXIO); +} + +static int +am335x_pwm_detach(device_t dev) +{ + struct am335x_pwm_softc *sc; + + sc = device_get_softc(dev); + + PWM_LOCK(sc); + if (sc->sc_mem_res[0]) + bus_release_resources(dev, am335x_pwm_mem_spec, + sc->sc_mem_res); + PWM_UNLOCK(sc); + + PWM_LOCK_DESTROY(sc); + + return (0); +} + +DRIVER_MODULE(am335x_pwm, simplebus, am335x_pwm_driver, am335x_pwm_devclass, 0, 0); +MODULE_VERSION(am335x_pwm, 1); +MODULE_DEPEND(am335x_pwm, simplebus, 1, 1, 1); Property changes on: arm/ti/am335x/am335x_pwm.c ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H Added: svn:eol-style ## -0,0 +1 ## +native Index: arm/ti/am335x/am335x_pwm.h =================================================================== --- arm/ti/am335x/am335x_pwm.h (revision 0) +++ arm/ti/am335x/am335x_pwm.h (working copy) @@ -0,0 +1,32 @@ +/*- + * Copyright (c) 2013 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. + */ +#ifndef __AM335X_PWM_H__ +#define __AM335X_PWM_H__ + +int am335x_pwm_config_ecas(int unit, int period, int duty); + +#endif /* __AM335X_PWM_H__ */ + Property changes on: arm/ti/am335x/am335x_pwm.h ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H Added: svn:eol-style ## -0,0 +1 ## +native Index: arm/ti/am335x/files.am335x =================================================================== --- arm/ti/am335x/files.am335x (revision 250037) +++ arm/ti/am335x/files.am335x (working copy) @@ -4,6 +4,9 @@ arm/ti/am335x/am335x_prcm.c standard arm/ti/am335x/am335x_dmtimer.c standard arm/ti/am335x/am335x_scm_padconf.c standard +arm/ti/am335x/am335x_lcd.c standard +arm/ti/am335x/am335x_lcd_syscons.c standard +arm/ti/am335x/am335x_pwm.c standard arm/ti/ti_edma3.c standard arm/ti/ti_mmchs.c optional mmc arm/ti/cpsw/if_cpsw.c optional cpsw Index: arm/ti/am335x/am335x_prcm.c =================================================================== --- arm/ti/am335x/am335x_prcm.c (revision 250037) +++ arm/ti/am335x/am335x_prcm.c (working copy) @@ -59,6 +59,7 @@ #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_LCDC_CLKCTRL (CM_PER + 0x018) #define CM_PER_USB0_CLKCTRL (CM_PER + 0x01C) #define CM_PER_TPTC0_CLKCTRL (CM_PER + 0x024) #define CM_PER_MMC0_CLKCTRL (CM_PER + 0x03C) @@ -72,6 +73,9 @@ #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_EPWMSS1_CLKCTRL (CM_PER + 0x0CC) +#define CM_PER_EPWMSS0_CLKCTRL (CM_PER + 0x0D4) +#define CM_PER_EPWMSS2_CLKCTRL (CM_PER + 0x0D8) #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) @@ -90,7 +94,10 @@ #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_IDLEST_DPLL_DISP (CM_WKUP + 0x048) +#define CM_WKUP_CM_CLKSEL_DPLL_DISP (CM_WKUP + 0x054) #define CM_WKUP_CM_CLKDCOLDO_DPLL_PER (CM_WKUP + 0x07C) +#define CM_WKUP_CM_CLKMODE_DPLL_DISP (CM_WKUP + 0x098) #define CM_WKUP_I2C0_CLKCTRL (CM_WKUP + 0x0B8) #define CM_DPLL 0x500 @@ -124,9 +131,11 @@ 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 int am335x_clk_get_arm_disp_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); +static int am335x_clk_lcdc_activate(struct ti_clock_dev *clkdev); #define AM335X_GENERIC_CLOCK_DEV(i) \ { .id = (i), \ @@ -190,6 +199,15 @@ .clk_get_source_freq = NULL, }, + /* LCD controller clocks */ + { .id = LCDC_CLK, + .clk_activate = am335x_clk_lcdc_activate, + .clk_deactivate = NULL, + .clk_set_source = NULL, + .clk_accessible = NULL, + .clk_get_source_freq = am335x_clk_get_arm_disp_freq, + }, + /* DMTimer */ AM335X_GENERIC_CLOCK_DEV(DMTIMER2_CLK), AM335X_GENERIC_CLOCK_DEV(DMTIMER3_CLK), @@ -220,6 +238,11 @@ AM335X_MMCHS_CLOCK_DEV(MMC1_CLK), AM335X_MMCHS_CLOCK_DEV(MMC2_CLK), + /* PWMSS */ + AM335X_GENERIC_CLOCK_DEV(PWMSS0_CLK), + AM335X_GENERIC_CLOCK_DEV(PWMSS1_CLK), + AM335X_GENERIC_CLOCK_DEV(PWMSS2_CLK), + { INVALID_CLK_IDENT, NULL, NULL, NULL, NULL } }; @@ -267,6 +290,11 @@ _CLK_DETAIL(MMC1_CLK, CM_PER_MMC1_CLKCTRL, 0), _CLK_DETAIL(MMC2_CLK, CM_PER_MMC1_CLKCTRL, 0), + /* PWMSS modules */ + _CLK_DETAIL(PWMSS0_CLK, CM_PER_EPWMSS0_CLKCTRL, 0), + _CLK_DETAIL(PWMSS1_CLK, CM_PER_EPWMSS1_CLKCTRL, 0), + _CLK_DETAIL(PWMSS2_CLK, CM_PER_EPWMSS2_CLKCTRL, 0), + { INVALID_CLK_IDENT, 0}, }; @@ -491,14 +519,15 @@ return (0); } +#define DPLL_BYP_CLKSEL(reg) ((reg>>23) & 1) +#define DPLL_DIV(reg) ((reg & 0x7f)+1) +#define DPLL_MULT(reg) ((reg>>8) & 0x7FF) + static int am335x_clk_get_arm_fclk_freq(struct ti_clock_dev *clkdev, unsigned int *freq) { uint32_t reg; uint32_t sysclk; -#define DPLL_BYP_CLKSEL(reg) ((reg>>23) & 1) -#define DPLL_DIV(reg) ((reg & 0x7f)+1) -#define DPLL_MULT(reg) ((reg>>8) & 0x7FF) reg = prcm_read_4(CM_WKUP_CM_CLKSEL_DPLL_MPU); @@ -511,6 +540,24 @@ return(0); } +static int +am335x_clk_get_arm_disp_freq(struct ti_clock_dev *clkdev, unsigned int *freq) +{ + uint32_t reg; + uint32_t sysclk; + + reg = prcm_read_4(CM_WKUP_CM_CLKSEL_DPLL_DISP); + + /*Check if we are running in bypass */ + if (DPLL_BYP_CLKSEL(reg)) + return ENXIO; + + am335x_clk_get_sysclk_freq(NULL, &sysclk); + printf("Sys clock: %d\n", sysclk); + *freq = DPLL_MULT(reg) * (sysclk / DPLL_DIV(reg)); + return(0); +} + static void am335x_prcm_reset(void) { @@ -565,4 +612,44 @@ return(0); } +static int +am335x_clk_lcdc_activate(struct ti_clock_dev *clkdev) +{ + struct am335x_prcm_softc *sc = am335x_prcm_sc; + if (sc == NULL) + return ENXIO; + + /* Bypass mode */ + prcm_write_4(CM_WKUP_CM_CLKMODE_DPLL_DISP, 0x4); + + /* Make sure it's in bypass mode */ + while (!(prcm_read_4(CM_WKUP_CM_IDLEST_DPLL_DISP) + & (1 << 8))) + DELAY(10); + + /* TODO: set divisors/multipliers here */ + prcm_write_4(CM_WKUP_CM_CLKSEL_DPLL_DISP, (5 << 8) | 0); + + /* Locked mode */ + prcm_write_4(CM_WKUP_CM_CLKMODE_DPLL_DISP, 0x7); + + int timeout = 10000; + while ((!(prcm_read_4(CM_WKUP_CM_IDLEST_DPLL_DISP) + & (1 << 0))) && timeout--) + DELAY(10); + + /*set MODULEMODE to ENABLE(2) */ + prcm_write_4(CM_PER_LCDC_CLKCTRL, 2); + + /* wait for MODULEMODE to become ENABLE(2) */ + while ((prcm_read_4(CM_PER_LCDC_CLKCTRL) & 0x3) != 2) + DELAY(10); + + /* wait for IDLEST to become Func(0) */ + while(prcm_read_4(CM_PER_LCDC_CLKCTRL) & (3<<16)) + DELAY(10); + + return(0); +} + Index: arm/ti/am335x/am335x_lcd.c =================================================================== --- arm/ti/am335x/am335x_lcd.c (revision 0) +++ arm/ti/am335x/am335x_lcd.c (working copy) @@ -0,0 +1,619 @@ +/*- + * Copyright 2013 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. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include + +#include +#include + +#include "am335x_lcd.h" +#include "am335x_pwm.h" + +#define LCD_PID 0x00 +#define LCD_CTRL 0x04 +#define CTRL_DIV_MASK 0xff +#define CTRL_DIV_SHIFT 8 +#define CTRL_AUTO_UFLOW_RESTART (1 << 1) +#define CTRL_RASTER_MODE 1 +#define CTRL_LIDD_MODE 0 +#define LCD_LIDD_CTRL 0x0C +#define LCD_LIDD_CS0_CONF 0x10 +#define LCD_LIDD_CS0_ADDR 0x14 +#define LCD_LIDD_CS0_DATA 0x18 +#define LCD_LIDD_CS1_CONF 0x1C +#define LCD_LIDD_CS1_ADDR 0x20 +#define LCD_LIDD_CS1_DATA 0x24 +#define LCD_RASTER_CTRL 0x28 +#define RASTER_CTRL_TFT24_UNPACKED (1 << 26) +#define RASTER_CTRL_TFT24 (1 << 25) +#define RASTER_CTRL_STN565 (1 << 24) +#define RASTER_CTRL_TFTPMAP (1 << 23) +#define RASTER_CTRL_NIBMODE (1 << 22) +#define RASTER_CTRL_PALMODE_SHIFT 20 +#define PALETTE_PALETTE_AND_DATA 0x00 +#define PALETTE_PALETTE_ONLY 0x01 +#define PALETTE_DATA_ONLY 0x02 +#define RASTER_CTRL_REQDLY_SHIFT 12 +#define RASTER_CTRL_MONO8B (1 << 9) +#define RASTER_CTRL_RBORDER (1 << 8) +#define RASTER_CTRL_LCDTFT (1 << 7) +#define RASTER_CTRL_LCDBW (1 << 1) +#define RASTER_CTRL_LCDEN (1 << 0) +#define LCD_RASTER_TIMING_0 0x2C +#define RASTER_TIMING_0_HBP_SHIFT 24 +#define RASTER_TIMING_0_HFP_SHIFT 16 +#define RASTER_TIMING_0_HSW_SHIFT 10 +#define RASTER_TIMING_0_PPLLSB_SHIFT 4 +#define RASTER_TIMING_0_PPLMSB_SHIFT 3 +#define LCD_RASTER_TIMING_1 0x30 +#define RASTER_TIMING_1_VBP_SHIFT 24 +#define RASTER_TIMING_1_VFP_SHIFT 16 +#define RASTER_TIMING_1_VSW_SHIFT 10 +#define RASTER_TIMING_1_LPP_SHIFT 0 +#define LCD_RASTER_TIMING_2 0x34 +#define RASTER_TIMING_2_HSWHI_SHIFT 27 +#define RASTER_TIMING_2_LPP_B10_SHIFT 26 +#define RASTER_TIMING_2_PHSVS (1 << 25) +#define RASTER_TIMING_2_PHSVS_RISE (1 << 24) +#define RASTER_TIMING_2_PHSVS_FALL (0 << 24) +#define RASTER_TIMING_2_IOE (1 << 23) +#define RASTER_TIMING_2_IPC (1 << 22) +#define RASTER_TIMING_2_IHS (1 << 21) +#define RASTER_TIMING_2_IVS (1 << 20) +#define RASTER_TIMING_2_ACBI_SHIFT 16 +#define RASTER_TIMING_2_ACB_SHIFT 8 +#define RASTER_TIMING_2_HBPHI_SHIFT 4 +#define RASTER_TIMING_2_HFPHI_SHIFT 0 +#define LCD_RASTER_SUBPANEL 0x38 +#define LCD_RASTER_SUBPANEL2 0x3C +#define LCD_LCDDMA_CTRL 0x40 +#define LCDDMA_CTRL_DMA_MASTER_PRIO_SHIFT 16 +#define LCDDMA_CTRL_TH_FIFO_RDY_SHIFT 8 +#define LCDDMA_CTRL_BURST_SIZE_SHIFT 4 +#define LCDDMA_CTRL_BYTES_SWAP (1 << 3) +#define LCDDMA_CTRL_BE (1 << 1) +#define LCDDMA_CTRL_FB0_ONLY 0 +#define LCDDMA_CTRL_FB0_FB1 (1 << 0) +#define LCD_LCDDMA_FB0_BASE 0x44 +#define LCD_LCDDMA_FB0_CEILING 0x48 +#define LCD_LCDDMA_FB1_BASE 0x4C +#define LCD_LCDDMA_FB1_CEILING 0x50 +#define LCD_SYSCONFIG 0x54 +#define LCD_IRQSTATUS_RAW 0x58 +#define LCD_IRQSTATUS 0x5C +#define LCD_IRQENABLE_SET 0x60 +#define LCD_IRQENABLE_CLEAR 0x64 +#define IRQ_EOF1 (1 << 9) +#define IRQ_EOF0 (1 << 8) +#define IRQ_PL (1 << 6) +#define IRQ_FUF (1 << 5) +#define IRQ_ACB (1 << 3) +#define IRQ_SYNC_LOST (1 << 2) +#define IRQ_RASTER_DONE (1 << 1) +#define IRQ_FRAME_DONE (1 << 0) +#define LCD_CLKC_ENABLE 0x6C +#define CLKC_ENABLE_DMA (1 << 2) +#define CLKC_ENABLE_LDID (1 << 1) +#define CLKC_ENABLE_CORE (1 << 0) +#define LCD_CLKC_RESET 0x70 +#define CLKC_RESET_MAIN (1 << 3) +#define CLKC_RESET_DMA (1 << 2) +#define CLKC_RESET_LDID (1 << 1) +#define CLKC_RESET_CORE (1 << 0) + +#define LCD_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx) +#define LCD_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx) +#define LCD_LOCK_INIT(_sc) mtx_init(&(_sc)->sc_mtx, \ + device_get_nameunit(_sc->sc_dev), "am335x_lcd", MTX_DEF) +#define LCD_LOCK_DESTROY(_sc) mtx_destroy(&(_sc)->sc_mtx); + +#define LCD_READ4(_sc, reg) bus_read_4((_sc)->sc_mem_res, reg); +#define LCD_WRITE4(_sc, reg, value) \ + bus_write_4((_sc)->sc_mem_res, reg, value); + + +/* Backlight is controlled by eCAS interface on PWM unit 0 */ +#define PWM_UNIT 0 +#define PWM_PERIOD 100 + +struct am335x_lcd_softc { + device_t sc_dev; + struct resource *sc_mem_res; + struct resource *sc_irq_res; + void *sc_intr_hl; + struct mtx sc_mtx; + int sc_backlight; + struct sysctl_oid *sc_oid; +}; + + vm_paddr_t paddr; + size_t fb_size; + +static int +am335x_lcd_sysctl_backlight(SYSCTL_HANDLER_ARGS) +{ + struct am335x_lcd_softc *sc = (struct am335x_lcd_softc*)arg1; + int error; + int backlight; + + backlight = sc->sc_backlight;; + error = sysctl_handle_int(oidp, &backlight, 0, req); + + if (error != 0 || req->newptr == NULL) + return (error); + + if (backlight < 0) + backlight = 0; + if (backlight > 100) + backlight = 100; + + LCD_LOCK(sc); + error = am335x_pwm_config_ecas(PWM_UNIT, PWM_PERIOD, + backlight*PWM_PERIOD/100); + if (error == 0) + sc->sc_backlight = backlight; + LCD_UNLOCK(sc); + + return (error); +} + +static int +am335x_read_panel_property(device_t dev, const char *name, uint32_t *val) +{ + phandle_t node; + pcell_t cell; + + node = ofw_bus_get_node(dev); + if ((OF_getprop(node, name, &cell, sizeof(cell))) <= 0) { + device_printf(dev, "missing '%s' attribute in LCD panel info\n", + name); + return (ENXIO); + } + + *val = fdt32_to_cpu(cell); + + return (0); +} + +static int +am335x_read_panel_info(device_t dev, struct panel_info *panel) +{ + int error; + + error = 0; + if ((error = am335x_read_panel_property(dev, + "panel_width", &panel->panel_width))) + goto out; + + if ((error = am335x_read_panel_property(dev, + "panel_height", &panel->panel_height))) + goto out; + + if ((error = am335x_read_panel_property(dev, + "panel_hfp", &panel->panel_hfp))) + goto out; + + if ((error = am335x_read_panel_property(dev, + "panel_hbp", &panel->panel_hbp))) + goto out; + + if ((error = am335x_read_panel_property(dev, + "panel_hsw", &panel->panel_hsw))) + goto out; + + if ((error = am335x_read_panel_property(dev, + "panel_vfp", &panel->panel_vfp))) + goto out; + + if ((error = am335x_read_panel_property(dev, + "panel_vbp", &panel->panel_vbp))) + goto out; + + if ((error = am335x_read_panel_property(dev, + "panel_vsw", &panel->panel_vsw))) + goto out; + + if ((error = am335x_read_panel_property(dev, + "panel_pxl_clk", &panel->panel_pxl_clk))) + goto out; + + if ((error = am335x_read_panel_property(dev, + "panel_invert_pxl_clk", &panel->panel_invert_pxl_clk))) + goto out; + + if ((error = am335x_read_panel_property(dev, + "ac_bias", &panel->ac_bias))) + goto out; + + if ((error = am335x_read_panel_property(dev, + "ac_bias_intrpt", &panel->ac_bias_intrpt))) + goto out; + + if ((error = am335x_read_panel_property(dev, + "dma_burst_sz", &panel->dma_burst_sz))) + goto out; + + if ((error = am335x_read_panel_property(dev, + "bpp", &panel->bpp))) + goto out; + + if ((error = am335x_read_panel_property(dev, + "fdd", &panel->fdd))) + goto out; + + if ((error = am335x_read_panel_property(dev, + "invert_line_clock", &panel->invert_line_clock))) + goto out; + + if ((error = am335x_read_panel_property(dev, + "invert_frm_clock", &panel->invert_frm_clock))) + goto out; + + if ((error = am335x_read_panel_property(dev, + "sync_edge", &panel->sync_edge))) + goto out; + + error = am335x_read_panel_property(dev, + "sync_ctrl", &panel->sync_ctrl); + +out: + return (error); +} + +static void +am335x_lcd_intr(void *arg) +{ + struct am335x_lcd_softc *sc = arg; + uint32_t reg; + + reg = LCD_READ4(sc, LCD_IRQSTATUS); + LCD_WRITE4(sc, LCD_IRQSTATUS, reg); + + if (reg & IRQ_SYNC_LOST) { + reg = LCD_READ4(sc, LCD_RASTER_CTRL); + reg &= ~RASTER_CTRL_LCDEN; + LCD_WRITE4(sc, LCD_RASTER_CTRL, reg); + + reg = LCD_READ4(sc, LCD_RASTER_CTRL); + reg |= RASTER_CTRL_LCDEN; + LCD_WRITE4(sc, LCD_RASTER_CTRL, reg); + return; + } + + if (reg & IRQ_PL) { + reg = LCD_READ4(sc, LCD_RASTER_CTRL); + reg &= ~RASTER_CTRL_LCDEN; + LCD_WRITE4(sc, LCD_RASTER_CTRL, reg); + + reg = LCD_READ4(sc, LCD_RASTER_CTRL); + reg |= RASTER_CTRL_LCDEN; + LCD_WRITE4(sc, LCD_RASTER_CTRL, reg); + return; + } + + if (reg & IRQ_EOF0) { + LCD_WRITE4(sc, LCD_LCDDMA_FB0_BASE, paddr); + LCD_WRITE4(sc, LCD_LCDDMA_FB0_CEILING, paddr + fb_size); + reg &= ~IRQ_EOF0; + } + + if (reg & IRQ_EOF1) { + LCD_WRITE4(sc, LCD_LCDDMA_FB1_BASE, paddr); + LCD_WRITE4(sc, LCD_LCDDMA_FB1_CEILING, paddr + fb_size); + reg &= ~IRQ_EOF1; + } + + if (reg & IRQ_FUF) { + /* TODO: Handle FUF */ + } + + if (reg & IRQ_ACB) { + /* TODO: Handle ACB */ + } +} + +static int +am335x_lcd_probe(device_t dev) +{ + if (!ofw_bus_is_compatible(dev, "ti,am335x-lcd")) + return (ENXIO); + + device_set_desc(dev, "AM335x LCD controller"); + + return (0); +} + +static int +am335x_lcd_attach(device_t dev) +{ + struct am335x_lcd_softc *sc; + int rid; + struct panel_info panel; + vm_offset_t vaddr; + uint32_t reg, timing0, timing1, timing2; + struct sysctl_ctx_list *ctx; + struct sysctl_oid *tree; + uint32_t burst_log; + + sc = device_get_softc(dev); + sc->sc_dev = dev; + + if (am335x_read_panel_info(dev, &panel)) + return (ENXIO); + + int ref_freq = 0; + ti_prcm_clk_enable(LCDC_CLK); + if (ti_prcm_clk_get_source_freq(LCDC_CLK, &ref_freq)) { + device_printf(dev, "Can't get reference frequency\n"); + return (ENXIO); + } + + 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 window\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); + } + + if (bus_setup_intr(dev, sc->sc_irq_res, INTR_TYPE_MISC | INTR_MPSAFE, + NULL, am335x_lcd_intr, sc, + &sc->sc_intr_hl) != 0) { + bus_release_resource(dev, SYS_RES_IRQ, rid, + sc->sc_irq_res); + bus_release_resource(dev, SYS_RES_MEMORY, rid, + sc->sc_mem_res); + device_printf(dev, "Unable to setup the irq handler.\n"); + return (ENXIO); + } + + LCD_LOCK_INIT(sc); + + /* Panle initialization */ + fb_size = round_page(panel.panel_width*panel.panel_height*panel.bpp/8); + vaddr = (vm_offset_t)contigmalloc(fb_size, M_DEVBUF, + M_NOWAIT, 0ul, ~0ul, PAGE_SIZE, 0); + memset ((void*)vaddr, 0xa5, fb_size); + paddr = pmap_kextract(vaddr); + + /* Redfine actual FB Size */ + fb_size = panel.panel_width*panel.panel_height*panel.bpp/8; + + /* Only raster mode is supported */ + reg = CTRL_RASTER_MODE; + reg |= (4 << CTRL_DIV_SHIFT); + LCD_WRITE4(sc, LCD_CTRL, reg); + + /* Set timing */ + timing0 = timing1 = timing2 = 0; + + /* Horizontal back porch */ + timing0 |= (panel.panel_hbp & 0xff) << RASTER_TIMING_0_HBP_SHIFT; + timing2 |= ((panel.panel_hbp >> 8) & 3) << RASTER_TIMING_2_HBPHI_SHIFT; + /* Horizontal front porch */ + timing0 |= (panel.panel_hfp & 0xff) << RASTER_TIMING_0_HFP_SHIFT; + timing2 |= ((panel.panel_hfp >> 8) & 3) << RASTER_TIMING_2_HFPHI_SHIFT; + /* Horizontal sync width */ + timing0 |= (panel.panel_hsw & 0x3f) << RASTER_TIMING_0_HSW_SHIFT; + timing2 |= ((panel.panel_hsw >> 6) & 0xf) << RASTER_TIMING_2_HSWHI_SHIFT; + + /* Vertical back porch, front porch, sync width */ + timing1 |= (panel.panel_vbp & 0xff) << RASTER_TIMING_1_VBP_SHIFT; + timing1 |= (panel.panel_vfp & 0xff) << RASTER_TIMING_1_VFP_SHIFT; + timing1 |= (panel.panel_vsw & 0x3f) << RASTER_TIMING_1_VSW_SHIFT; + + /* Pixels per line */ + timing0 |= (((panel.panel_width - 1) >> 10) & 1) + << RASTER_TIMING_0_PPLMSB_SHIFT; + timing0 |= (((panel.panel_width - 1) >> 4) & 0x3f) + << RASTER_TIMING_0_PPLLSB_SHIFT; + + /* Lines per panel */ + timing1 |= ((panel.panel_height - 1) & 0x3ff) + << RASTER_TIMING_1_LPP_SHIFT; + timing2 |= (((panel.panel_height - 1) >> 10 ) & 1) + << RASTER_TIMING_2_LPP_B10_SHIFT; + + /* clock signal settings */ + if (panel.sync_ctrl) + timing2 |= RASTER_TIMING_2_PHSVS; + if (panel.sync_edge) + timing2 |= RASTER_TIMING_2_PHSVS_RISE; + else + timing2 |= RASTER_TIMING_2_PHSVS_FALL; + if (panel.invert_line_clock) + timing2 |= RASTER_TIMING_2_IHS; + if (panel.invert_frm_clock) + timing2 |= RASTER_TIMING_2_IVS; + if (panel.panel_invert_pxl_clk) + timing2 |= RASTER_TIMING_2_IPC; + + /* AC bias */ + timing2 |= (panel.ac_bias << RASTER_TIMING_2_ACB_SHIFT); + timing2 |= (panel.ac_bias_intrpt << RASTER_TIMING_2_ACBI_SHIFT); + + LCD_WRITE4(sc, LCD_RASTER_TIMING_0, timing0); + LCD_WRITE4(sc, LCD_RASTER_TIMING_1, timing1); + LCD_WRITE4(sc, LCD_RASTER_TIMING_2, timing2); + + /* DMA settings */ + reg = LCDDMA_CTRL_FB0_FB1; + /* Find power of 2 for current burst size */ + switch (panel.dma_burst_sz) { + case 1: + burst_log = 0; + break; + case 2: + burst_log = 1; + break; + case 4: + burst_log = 2; + break; + case 8: + burst_log = 3; + break; + case 16: + default: + burst_log = 4; + break; + } + reg |= (burst_log << LCDDMA_CTRL_BURST_SIZE_SHIFT); + /* XXX: FIFO TH */ + reg |= (0 << LCDDMA_CTRL_TH_FIFO_RDY_SHIFT); + LCD_WRITE4(sc, LCD_LCDDMA_CTRL, reg); + + LCD_WRITE4(sc, LCD_LCDDMA_FB0_BASE, paddr); + LCD_WRITE4(sc, LCD_LCDDMA_FB0_CEILING, paddr + fb_size - 1); + LCD_WRITE4(sc, LCD_LCDDMA_FB1_BASE, paddr); + LCD_WRITE4(sc, LCD_LCDDMA_FB1_CEILING, paddr + fb_size - 1); + + /* Enable LCD */ + reg = RASTER_CTRL_LCDTFT; + reg |= (panel.fdd << RASTER_CTRL_REQDLY_SHIFT); + reg |= (PALETTE_DATA_ONLY << RASTER_CTRL_PALMODE_SHIFT); + if (panel.bpp >= 24) + reg |= RASTER_CTRL_TFT24; + if (panel.bpp == 32) + reg |= RASTER_CTRL_TFT24_UNPACKED; + LCD_WRITE4(sc, LCD_RASTER_CTRL, reg); + + LCD_WRITE4(sc, LCD_CLKC_ENABLE, + CLKC_ENABLE_DMA | CLKC_ENABLE_LDID | CLKC_ENABLE_CORE); + + LCD_WRITE4(sc, LCD_CLKC_RESET, CLKC_RESET_MAIN); + DELAY(100); + LCD_WRITE4(sc, LCD_CLKC_RESET, 0); + + reg = IRQ_EOF1 | IRQ_EOF0 | IRQ_FUF | IRQ_PL | + IRQ_ACB | IRQ_SYNC_LOST | IRQ_RASTER_DONE | + IRQ_FRAME_DONE; + LCD_WRITE4(sc, LCD_IRQENABLE_SET, reg); + + reg = LCD_READ4(sc, LCD_RASTER_CTRL); + reg |= RASTER_CTRL_LCDEN; + LCD_WRITE4(sc, LCD_RASTER_CTRL, reg); + + LCD_WRITE4(sc, LCD_SYSCONFIG, 0x28); + + /* Init backlight interface */ + ctx = device_get_sysctl_ctx(sc->sc_dev); + tree = device_get_sysctl_tree(sc->sc_dev); + sc->sc_oid = SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, + "backlight", CTLTYPE_INT | CTLFLAG_RW, sc, 0, + am335x_lcd_sysctl_backlight, "I", "voltage regulator"); + sc->sc_backlight = 0; + /* Check if eCAS interface is available at this point */ + if (am335x_pwm_config_ecas(PWM_UNIT, + PWM_PERIOD, PWM_PERIOD) == 0) + sc->sc_backlight = 100; + + am335x_lcd_syscons_setup(vaddr, paddr, &panel); + + return (0); +} + +static int +am335x_lcd_detach(device_t dev) +{ + struct am335x_lcd_softc *sc; + int rid; + + sc = device_get_softc(dev); + + LCD_LOCK(sc); + sysctl_remove_oid(sc->sc_oid, 1, 0); + rid = 0; + + if (sc->sc_intr_hl) + bus_teardown_intr(dev, sc->sc_irq_res, + sc->sc_intr_hl); + + if (sc->sc_mem_res) + bus_release_resource(dev, SYS_RES_MEMORY, + rid, sc->sc_mem_res); + + if (sc->sc_irq_res) + bus_release_resource(dev, SYS_RES_IRQ, + rid, sc->sc_irq_res); + + LCD_UNLOCK(sc); + + LCD_LOCK_DESTROY(sc); + + return (0); +} + +static device_method_t am335x_lcd_methods[] = { + DEVMETHOD(device_probe, am335x_lcd_probe), + DEVMETHOD(device_attach, am335x_lcd_attach), + DEVMETHOD(device_detach, am335x_lcd_detach), + + DEVMETHOD_END +}; + +static driver_t am335x_lcd_driver = { + "am335x_lcd", + am335x_lcd_methods, + sizeof(struct am335x_lcd_softc), +}; + +static devclass_t am335x_lcd_devclass; + +DRIVER_MODULE(am335x_lcd, simplebus, am335x_lcd_driver, am335x_lcd_devclass, 0, 0); +MODULE_VERSION(am335x_lcd, 1); +MODULE_DEPEND(am335x_lcd, simplebus, 1, 1, 1); Property changes on: arm/ti/am335x/am335x_lcd.c ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H Added: svn:eol-style ## -0,0 +1 ## +native Index: arm/ti/am335x/am335x_lcd.h =================================================================== --- arm/ti/am335x/am335x_lcd.h (revision 0) +++ arm/ti/am335x/am335x_lcd.h (working copy) @@ -0,0 +1,55 @@ +/*- + * Copyright (c) 2013 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. + */ +#ifndef __AM335X_LCD_H__ +#define __AM335X_LCD_H__ + +struct panel_info { + uint32_t panel_width; + uint32_t panel_height; + uint32_t panel_hfp; + uint32_t panel_hbp; + uint32_t panel_hsw; + uint32_t panel_vfp; + uint32_t panel_vbp; + uint32_t panel_vsw; + uint32_t ac_bias; + uint32_t ac_bias_intrpt; + uint32_t dma_burst_sz; + uint32_t bpp; + uint32_t fdd; + uint32_t invert_line_clock; + uint32_t invert_frm_clock; + uint32_t sync_edge; + uint32_t sync_ctrl; + uint32_t panel_pxl_clk; + uint32_t panel_invert_pxl_clk; +}; + +int am335x_lcd_syscons_setup(vm_offset_t vaddr, vm_paddr_t paddr, + struct panel_info *panel); + +#endif /* __AM335X_LCD_H__ */ + Property changes on: arm/ti/am335x/am335x_lcd.h ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H Added: svn:eol-style ## -0,0 +1 ## +native Index: arm/ti/am335x/am335x_lcd_syscons.c =================================================================== --- arm/ti/am335x/am335x_lcd_syscons.c (revision 0) +++ arm/ti/am335x/am335x_lcd_syscons.c (working copy) @@ -0,0 +1,777 @@ +/*- + * Copyright (c) 2013 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. + */ +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include + +#include "am335x_lcd.h" + +struct video_adapter_softc { + /* Videoadpater part */ + video_adapter_t va; + int console; + + intptr_t fb_addr; + intptr_t fb_paddr; + unsigned int fb_size; + + unsigned int height; + unsigned int width; + unsigned int depth; + unsigned int stride; + + unsigned int xmargin; + unsigned int ymargin; + + unsigned char *font; + int initialized; +}; + +struct argb { + uint8_t a; + uint8_t r; + uint8_t g; + uint8_t b; +}; + +static struct argb am335x_syscons_palette[16] = { + {0x00, 0x00, 0x00, 0x00}, + {0x00, 0x00, 0x00, 0xaa}, + {0x00, 0x00, 0xaa, 0x00}, + {0x00, 0x00, 0xaa, 0xaa}, + {0x00, 0xaa, 0x00, 0x00}, + {0x00, 0xaa, 0x00, 0xaa}, + {0x00, 0xaa, 0x55, 0x00}, + {0x00, 0xaa, 0xaa, 0xaa}, + {0x00, 0x55, 0x55, 0x55}, + {0x00, 0x55, 0x55, 0xff}, + {0x00, 0x55, 0xff, 0x55}, + {0x00, 0x55, 0xff, 0xff}, + {0x00, 0xff, 0x55, 0x55}, + {0x00, 0xff, 0x55, 0xff}, + {0x00, 0xff, 0xff, 0x55}, + {0x00, 0xff, 0xff, 0xff} +}; + +/* mouse pointer from dev/syscons/scgfbrndr.c */ +static u_char mouse_pointer[16] = { + 0x00, 0x40, 0x60, 0x70, 0x78, 0x7c, 0x7e, 0x68, + 0x0c, 0x0c, 0x06, 0x06, 0x00, 0x00, 0x00, 0x00 +}; + +#define AM335X_FONT_HEIGHT 16 + +#define FB_WIDTH 640 +#define FB_HEIGHT 480 +#define FB_DEPTH 24 + +static struct video_adapter_softc va_softc; + +static int am335x_syscons_configure(int flags); + +/* + * Video driver routines and glue. + */ +static vi_probe_t am335x_syscons_probe; +static vi_init_t am335x_syscons_init; +static vi_get_info_t am335x_syscons_get_info; +static vi_query_mode_t am335x_syscons_query_mode; +static vi_set_mode_t am335x_syscons_set_mode; +static vi_save_font_t am335x_syscons_save_font; +static vi_load_font_t am335x_syscons_load_font; +static vi_show_font_t am335x_syscons_show_font; +static vi_save_palette_t am335x_syscons_save_palette; +static vi_load_palette_t am335x_syscons_load_palette; +static vi_set_border_t am335x_syscons_set_border; +static vi_save_state_t am335x_syscons_save_state; +static vi_load_state_t am335x_syscons_load_state; +static vi_set_win_org_t am335x_syscons_set_win_org; +static vi_read_hw_cursor_t am335x_syscons_read_hw_cursor; +static vi_set_hw_cursor_t am335x_syscons_set_hw_cursor; +static vi_set_hw_cursor_shape_t am335x_syscons_set_hw_cursor_shape; +static vi_blank_display_t am335x_syscons_blank_display; +static vi_mmap_t am335x_syscons_mmap; +static vi_ioctl_t am335x_syscons_ioctl; +static vi_clear_t am335x_syscons_clear; +static vi_fill_rect_t am335x_syscons_fill_rect; +static vi_bitblt_t am335x_syscons_bitblt; +static vi_diag_t am335x_syscons_diag; +static vi_save_cursor_palette_t am335x_syscons_save_cursor_palette; +static vi_load_cursor_palette_t am335x_syscons_load_cursor_palette; +static vi_copy_t am335x_syscons_copy; +static vi_putp_t am335x_syscons_putp; +static vi_putc_t am335x_syscons_putc; +static vi_puts_t am335x_syscons_puts; +static vi_putm_t am335x_syscons_putm; + +static video_switch_t am335x_sysconsvidsw = { + .probe = am335x_syscons_probe, + .init = am335x_syscons_init, + .get_info = am335x_syscons_get_info, + .query_mode = am335x_syscons_query_mode, + .set_mode = am335x_syscons_set_mode, + .save_font = am335x_syscons_save_font, + .load_font = am335x_syscons_load_font, + .show_font = am335x_syscons_show_font, + .save_palette = am335x_syscons_save_palette, + .load_palette = am335x_syscons_load_palette, + .set_border = am335x_syscons_set_border, + .save_state = am335x_syscons_save_state, + .load_state = am335x_syscons_load_state, + .set_win_org = am335x_syscons_set_win_org, + .read_hw_cursor = am335x_syscons_read_hw_cursor, + .set_hw_cursor = am335x_syscons_set_hw_cursor, + .set_hw_cursor_shape = am335x_syscons_set_hw_cursor_shape, + .blank_display = am335x_syscons_blank_display, + .mmap = am335x_syscons_mmap, + .ioctl = am335x_syscons_ioctl, + .clear = am335x_syscons_clear, + .fill_rect = am335x_syscons_fill_rect, + .bitblt = am335x_syscons_bitblt, + .diag = am335x_syscons_diag, + .save_cursor_palette = am335x_syscons_save_cursor_palette, + .load_cursor_palette = am335x_syscons_load_cursor_palette, + .copy = am335x_syscons_copy, + .putp = am335x_syscons_putp, + .putc = am335x_syscons_putc, + .puts = am335x_syscons_puts, + .putm = am335x_syscons_putm, +}; + +VIDEO_DRIVER(am335x_syscons, am335x_sysconsvidsw, am335x_syscons_configure); + +static vr_init_t am335x_rend_init; +static vr_clear_t am335x_rend_clear; +static vr_draw_border_t am335x_rend_draw_border; +static vr_draw_t am335x_rend_draw; +static vr_set_cursor_t am335x_rend_set_cursor; +static vr_draw_cursor_t am335x_rend_draw_cursor; +static vr_blink_cursor_t am335x_rend_blink_cursor; +static vr_set_mouse_t am335x_rend_set_mouse; +static vr_draw_mouse_t am335x_rend_draw_mouse; + +/* + * We use our own renderer; this is because we must emulate a hardware + * cursor. + */ +static sc_rndr_sw_t am335x_rend = { + am335x_rend_init, + am335x_rend_clear, + am335x_rend_draw_border, + am335x_rend_draw, + am335x_rend_set_cursor, + am335x_rend_draw_cursor, + am335x_rend_blink_cursor, + am335x_rend_set_mouse, + am335x_rend_draw_mouse +}; + +RENDERER(am335x_syscons, 0, am335x_rend, gfb_set); +RENDERER_MODULE(am335x_syscons, gfb_set); + +static void +am335x_rend_init(scr_stat* scp) +{ +} + +static void +am335x_rend_clear(scr_stat* scp, int c, int attr) +{ +} + +static void +am335x_rend_draw_border(scr_stat* scp, int color) +{ +} + +static void +am335x_rend_draw(scr_stat* scp, int from, int count, int flip) +{ + video_adapter_t* adp = scp->sc->adp; + int i, c, a; + + if (!flip) { + /* Normal printing */ + vidd_puts(adp, from, (uint16_t*)sc_vtb_pointer(&scp->vtb, from), count); + } else { + /* This is for selections and such: invert the color attribute */ + for (i = count; i-- > 0; ++from) { + c = sc_vtb_getc(&scp->vtb, from); + a = sc_vtb_geta(&scp->vtb, from) >> 8; + vidd_putc(adp, from, c, (a >> 4) | ((a & 0xf) << 4)); + } + } +} + +static void +am335x_rend_set_cursor(scr_stat* scp, int base, int height, int blink) +{ +} + +static void +am335x_rend_draw_cursor(scr_stat* scp, int off, int blink, int on, int flip) +{ + video_adapter_t* adp = scp->sc->adp; + struct video_adapter_softc *sc; + int row, col; + uint8_t *addr; + int i, j, bytes; + + sc = (struct video_adapter_softc *)adp; + + if (scp->curs_attr.height <= 0) + return; + + if (sc->fb_addr == 0) + return; + + if (off >= adp->va_info.vi_width * adp->va_info.vi_height) + return; + + /* calculate the coordinates in the video buffer */ + row = (off / adp->va_info.vi_width) * adp->va_info.vi_cheight; + col = (off % adp->va_info.vi_width) * adp->va_info.vi_cwidth; + + addr = (uint8_t *)sc->fb_addr + + (row + sc->ymargin)*(sc->stride) + + (sc->depth/8) * (col + sc->xmargin); + + bytes = sc->depth/8; + + /* our cursor consists of simply inverting the char under it */ + for (i = 0; i < adp->va_info.vi_cheight; i++) { + for (j = 0; j < adp->va_info.vi_cwidth; j++) { + switch (sc->depth) { + case 32: + case 24: + addr[bytes*j + 2] ^= 0xff; + /* FALLTHROUGH */ + case 16: + addr[bytes*j + 1] ^= 0xff; + addr[bytes*j] ^= 0xff; + break; + default: + break; + } + } + + addr += sc->stride; + } +} + +static void +am335x_rend_blink_cursor(scr_stat* scp, int at, int flip) +{ +} + +static void +am335x_rend_set_mouse(scr_stat* scp) +{ +} + +static void +am335x_rend_draw_mouse(scr_stat* scp, int x, int y, int on) +{ + vidd_putm(scp->sc->adp, x, y, mouse_pointer, 0xffffffff, 16, 8); +} + +static uint16_t am335x_syscons_static_window[ROW*COL]; +extern u_char dflt_font_16[]; + +/* + * Update videoadapter settings after changing resolution + */ +static void +am335x_syscons_update_margins(video_adapter_t *adp) +{ + struct video_adapter_softc *sc; + video_info_t *vi; + + sc = (struct video_adapter_softc *)adp; + vi = &adp->va_info; + + sc->xmargin = (sc->width - (vi->vi_width * vi->vi_cwidth)) / 2; + sc->ymargin = (sc->height - (vi->vi_height * vi->vi_cheight))/2; +} + +static int +am335x_syscons_configure(int flags) +{ + struct video_adapter_softc *va_sc; + + va_sc = &va_softc; + phandle_t display, root; + pcell_t cell; + + if (va_sc->initialized) + return (0); + + va_sc->width = 0; + va_sc->height = 0; + + /* + * It seems there is no way to let syscons framework know + * that framebuffer resolution has changed. So just try + * to fetch data from FDT and go with defaults if failed + */ + root = OF_finddevice("/"); + if ((root != 0) && + (display = fdt_find_compatible(root, "ti,am335x-lcd", 1))) { + if ((OF_getprop(display, "panel_width", + &cell, sizeof(cell))) > 0) + va_sc->width = (int)fdt32_to_cpu(cell); + + if ((OF_getprop(display, "panel_height", + &cell, sizeof(cell))) > 0) + va_sc->height = (int)fdt32_to_cpu(cell); + } + + if (va_sc->width == 0) + va_sc->width = FB_WIDTH; + if (va_sc->height == 0) + va_sc->height = FB_HEIGHT; + + am335x_syscons_init(0, &va_sc->va, 0); + + va_sc->initialized = 1; + + return (0); +} + +static int +am335x_syscons_probe(int unit, video_adapter_t **adp, void *arg, int flags) +{ + + return (0); +} + +static int +am335x_syscons_init(int unit, video_adapter_t *adp, int flags) +{ + struct video_adapter_softc *sc; + video_info_t *vi; + + sc = (struct video_adapter_softc *)adp; + vi = &adp->va_info; + + vid_init_struct(adp, "am335x_syscons", -1, unit); + + sc->font = dflt_font_16; + vi->vi_cheight = AM335X_FONT_HEIGHT; + vi->vi_cwidth = 8; + + vi->vi_width = sc->width/8; + vi->vi_height = sc->height/vi->vi_cheight; + + /* + * Clamp width/height to syscons maximums + */ + if (vi->vi_width > COL) + vi->vi_width = COL; + if (vi->vi_height > ROW) + vi->vi_height = ROW; + + sc->xmargin = (sc->width - (vi->vi_width * vi->vi_cwidth)) / 2; + sc->ymargin = (sc->height - (vi->vi_height * vi->vi_cheight))/2; + + + adp->va_window = (vm_offset_t) am335x_syscons_static_window; + adp->va_flags |= V_ADP_FONT /* | V_ADP_COLOR | V_ADP_MODECHANGE */; + + vid_register(&sc->va); + + return (0); +} + +static int +am335x_syscons_get_info(video_adapter_t *adp, int mode, video_info_t *info) +{ + bcopy(&adp->va_info, info, sizeof(*info)); + return (0); +} + +static int +am335x_syscons_query_mode(video_adapter_t *adp, video_info_t *info) +{ + return (0); +} + +static int +am335x_syscons_set_mode(video_adapter_t *adp, int mode) +{ + return (0); +} + +static int +am335x_syscons_save_font(video_adapter_t *adp, int page, int size, int width, + u_char *data, int c, int count) +{ + return (0); +} + +static int +am335x_syscons_load_font(video_adapter_t *adp, int page, int size, int width, + u_char *data, int c, int count) +{ + struct video_adapter_softc *sc = (struct video_adapter_softc *)adp; + + sc->font = data; + + return (0); +} + +static int +am335x_syscons_show_font(video_adapter_t *adp, int page) +{ + return (0); +} + +static int +am335x_syscons_save_palette(video_adapter_t *adp, u_char *palette) +{ + return (0); +} + +static int +am335x_syscons_load_palette(video_adapter_t *adp, u_char *palette) +{ + return (0); +} + +static int +am335x_syscons_set_border(video_adapter_t *adp, int border) +{ + return (am335x_syscons_blank_display(adp, border)); +} + +static int +am335x_syscons_save_state(video_adapter_t *adp, void *p, size_t size) +{ + return (0); +} + +static int +am335x_syscons_load_state(video_adapter_t *adp, void *p) +{ + return (0); +} + +static int +am335x_syscons_set_win_org(video_adapter_t *adp, off_t offset) +{ + return (0); +} + +static int +am335x_syscons_read_hw_cursor(video_adapter_t *adp, int *col, int *row) +{ + *col = *row = 0; + + return (0); +} + +static int +am335x_syscons_set_hw_cursor(video_adapter_t *adp, int col, int row) +{ + return (0); +} + +static int +am335x_syscons_set_hw_cursor_shape(video_adapter_t *adp, int base, int height, + int celsize, int blink) +{ + return (0); +} + +static int +am335x_syscons_blank_display(video_adapter_t *adp, int mode) +{ + + struct video_adapter_softc *sc; + + sc = (struct video_adapter_softc *)adp; + if (sc && sc->fb_addr) + memset((void*)sc->fb_addr, 0, sc->fb_size); + + return (0); +} + +static int +am335x_syscons_mmap(video_adapter_t *adp, vm_ooffset_t offset, vm_paddr_t *paddr, + int prot, vm_memattr_t *memattr) +{ + struct video_adapter_softc *sc; + + sc = (struct video_adapter_softc *)adp; + + /* + * This might be a legacy VGA mem request: if so, just point it at the + * framebuffer, since it shouldn't be touched + */ + if (offset < sc->stride*sc->height) { + *paddr = sc->fb_paddr + offset; + return (0); + } + + return (EINVAL); +} + +static int +am335x_syscons_ioctl(video_adapter_t *adp, u_long cmd, caddr_t data) +{ + struct video_adapter_softc *sc; + struct fbtype *fb; + + sc = (struct video_adapter_softc *)adp; + + switch (cmd) { + case FBIOGTYPE: + fb = (struct fbtype *)data; + fb->fb_type = FBTYPE_PCIMISC; + fb->fb_height = sc->height; + fb->fb_width = sc->width; + fb->fb_depth = sc->depth; + if (sc->depth <= 1 || sc->depth > 8) + fb->fb_cmsize = 0; + else + fb->fb_cmsize = 1 << sc->depth; + fb->fb_size = sc->fb_size; + break; + default: + return (fb_commonioctl(adp, cmd, data)); + } + + return (0); +} + +static int +am335x_syscons_clear(video_adapter_t *adp) +{ + + return (am335x_syscons_blank_display(adp, 0)); +} + +static int +am335x_syscons_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy) +{ + + return (0); +} + +static int +am335x_syscons_bitblt(video_adapter_t *adp, ...) +{ + + return (0); +} + +static int +am335x_syscons_diag(video_adapter_t *adp, int level) +{ + + return (0); +} + +static int +am335x_syscons_save_cursor_palette(video_adapter_t *adp, u_char *palette) +{ + + return (0); +} + +static int +am335x_syscons_load_cursor_palette(video_adapter_t *adp, u_char *palette) +{ + + return (0); +} + +static int +am335x_syscons_copy(video_adapter_t *adp, vm_offset_t src, vm_offset_t dst, int n) +{ + + return (0); +} + +static int +am335x_syscons_putp(video_adapter_t *adp, vm_offset_t off, uint32_t p, uint32_t a, + int size, int bpp, int bit_ltor, int byte_ltor) +{ + + return (0); +} + +static int +am335x_syscons_putc(video_adapter_t *adp, vm_offset_t off, uint8_t c, uint8_t a) +{ + struct video_adapter_softc *sc; + int row; + int col; + int i, j, k; + uint8_t *addr; + u_char *p; + uint8_t fg, bg, color; + uint16_t rgb; + + sc = (struct video_adapter_softc *)adp; + + if (sc->fb_addr == 0) + return (0); + + row = (off / adp->va_info.vi_width) * adp->va_info.vi_cheight; + col = (off % adp->va_info.vi_width) * adp->va_info.vi_cwidth; + p = sc->font + c*AM335X_FONT_HEIGHT; + addr = (uint8_t *)sc->fb_addr + + (row + sc->ymargin)*(sc->stride) + + (sc->depth/8) * (col + sc->xmargin); + + fg = a & 0xf ; + bg = (a >> 4) & 0xf; + + for (i = 0; i < AM335X_FONT_HEIGHT; i++) { + for (j = 0, k = 7; j < 8; j++, k--) { + if ((p[i] & (1 << k)) == 0) + color = bg; + else + color = fg; + + switch (sc->depth) { + case 32: + addr[4*j+0] = am335x_syscons_palette[color].r; + addr[4*j+1] = am335x_syscons_palette[color].g; + addr[4*j+2] = am335x_syscons_palette[color].b; + addr[4*j+3] = am335x_syscons_palette[color].a; + break; + case 24: + addr[3*j] = am335x_syscons_palette[color].r; + addr[3*j+1] = am335x_syscons_palette[color].g; + addr[3*j+2] = am335x_syscons_palette[color].b; + break; + case 16: + rgb = (am335x_syscons_palette[color].r >> 3) << 11; + rgb |= (am335x_syscons_palette[color].g >> 2) << 5; + rgb |= (am335x_syscons_palette[color].b >> 3); + addr[2*j] = rgb & 0xff; + addr[2*j + 1] = (rgb >> 8) & 0xff; + default: + /* Not supported yet */ + break; + } + } + + addr += (sc->stride); + } + + return (0); +} + +static int +am335x_syscons_puts(video_adapter_t *adp, vm_offset_t off, u_int16_t *s, int len) +{ + int i; + + for (i = 0; i < len; i++) + am335x_syscons_putc(adp, off + i, s[i] & 0xff, (s[i] & 0xff00) >> 8); + + return (0); +} + +static int +am335x_syscons_putm(video_adapter_t *adp, int x, int y, uint8_t *pixel_image, + uint32_t pixel_mask, int size, int width) +{ + + return (0); +} + +/* Initialization function */ +int am335x_lcd_syscons_setup(vm_offset_t vaddr, vm_paddr_t paddr, + struct panel_info *panel) +{ + struct video_adapter_softc *va_sc = &va_softc; + + va_sc->fb_addr = vaddr; + va_sc->fb_paddr = paddr; + va_sc->depth = panel->bpp; + va_sc->stride = panel->bpp*panel->panel_width/8; + + va_sc->width = panel->panel_width; + va_sc->height = panel->panel_height; + va_sc->fb_size = va_sc->width * va_sc->height + * va_sc->depth/8; + am335x_syscons_update_margins(&va_sc->va); + + return (0); +} + +/* + * Define a stub keyboard driver in case one hasn't been + * compiled into the kernel + */ +#include +#include + +static int dummy_kbd_configure(int flags); + +keyboard_switch_t am335x_dummysw; + +static int +dummy_kbd_configure(int flags) +{ + + return (0); +} +KEYBOARD_DRIVER(am335x_dummy, am335x_dummysw, dummy_kbd_configure); Property changes on: arm/ti/am335x/am335x_lcd_syscons.c ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H Added: svn:eol-style ## -0,0 +1 ## +native Index: arm/ti/am335x/am335x_scm.h =================================================================== --- arm/ti/am335x/am335x_scm.h (revision 0) +++ arm/ti/am335x/am335x_scm.h (working copy) @@ -0,0 +1,37 @@ +/*- + * 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. + */ +#ifndef __AM335X_SCM_H__ +#define __AM335X_SCM_H__ + +/* AM335x-specific registers for control module (scm) */ +#define SCM_USB_CTRL0 0x620 +#define SCM_USB_STS0 0x624 +#define SCM_USB_CTRL1 0x628 +#define SCM_USB_STS1 0x62C +#define SCM_PWMSS_CTRL 0x664 + +#endif /* __AM335X_SCM_H__ */ + Property changes on: arm/ti/am335x/am335x_scm.h ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H Added: svn:eol-style ## -0,0 +1 ## +native Index: arm/ti/ti_prcm.h =================================================================== --- arm/ti/ti_prcm.h (revision 250037) +++ arm/ti/ti_prcm.h (working copy) @@ -141,6 +141,14 @@ EDMA_TPTC1_CLK, EDMA_TPTC2_CLK, + /* LCD controller module */ + LCDC_CLK = 1300, + + /* PWM modules */ + PWMSS0_CLK = 1400, + PWMSS1_CLK, + PWMSS2_CLK, + INVALID_CLK_IDENT } clk_ident_t;