Home | History | Annotate | Line # | Download | only in imx
imx51_ipuv3.c revision 1.1.6.1
      1      1.1  bsh /*	$NetBSD: imx51_ipuv3.c,v 1.1.6.1 2014/08/20 00:02:46 tls Exp $	*/
      2      1.1  bsh 
      3      1.1  bsh /*
      4      1.1  bsh  * Copyright (c) 2011, 2012  Genetec Corporation.  All rights reserved.
      5      1.1  bsh  * Written by Hashimoto Kenichi for Genetec Corporation.
      6      1.1  bsh  *
      7      1.1  bsh  * Redistribution and use in source and binary forms, with or without
      8      1.1  bsh  * modification, are permitted provided that the following conditions
      9      1.1  bsh  * are met:
     10      1.1  bsh  * 1. Redistributions of source code must retain the above copyright
     11      1.1  bsh  *    notice, this list of conditions and the following disclaimer.
     12      1.1  bsh  * 2. Redistributions in binary form must reproduce the above copyright
     13      1.1  bsh  *    notice, this list of conditions and the following disclaimer in the
     14      1.1  bsh  *    documentation and/or other materials provided with the distribution.
     15      1.1  bsh  *
     16      1.1  bsh  * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
     17      1.1  bsh  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18      1.1  bsh  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19      1.1  bsh  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL GENETEC CORPORATION
     20      1.1  bsh  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21      1.1  bsh  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22      1.1  bsh  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23      1.1  bsh  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24      1.1  bsh  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25      1.1  bsh  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26      1.1  bsh  * POSSIBILITY OF SUCH DAMAGE.
     27      1.1  bsh  */
     28      1.1  bsh 
     29      1.1  bsh #include <sys/cdefs.h>
     30      1.1  bsh __KERNEL_RCSID(0, "$NetBSD: imx51_ipuv3.c,v 1.1.6.1 2014/08/20 00:02:46 tls Exp $");
     31      1.1  bsh 
     32      1.1  bsh #include <sys/param.h>
     33      1.1  bsh #include <sys/systm.h>
     34      1.1  bsh #include <sys/conf.h>
     35      1.1  bsh #include <sys/uio.h>
     36      1.1  bsh #include <sys/malloc.h>
     37      1.1  bsh #include <sys/kernel.h>			/* for cold */
     38  1.1.6.1  tls #include <sys/pmf.h>
     39      1.1  bsh 
     40      1.1  bsh #include <uvm/uvm_extern.h>
     41      1.1  bsh 
     42      1.1  bsh #include <dev/cons.h>
     43      1.1  bsh #include <dev/wscons/wsconsio.h>
     44      1.1  bsh #include <dev/wscons/wsdisplayvar.h>
     45      1.1  bsh #include <dev/wscons/wscons_callbacks.h>
     46      1.1  bsh #include <dev/rasops/rasops.h>
     47      1.1  bsh #include <dev/wsfont/wsfont.h>
     48      1.1  bsh #include <dev/wscons/wsdisplay_vconsvar.h>
     49      1.1  bsh 
     50      1.1  bsh #include <sys/bus.h>
     51      1.1  bsh #include <machine/cpu.h>
     52      1.1  bsh #include <arm/cpufunc.h>
     53      1.1  bsh 
     54      1.1  bsh #include <arm/imx/imx51var.h>
     55      1.1  bsh #include <arm/imx/imx51reg.h>
     56      1.1  bsh #include <arm/imx/imx51_ipuv3var.h>
     57      1.1  bsh #include <arm/imx/imx51_ipuv3reg.h>
     58      1.1  bsh #include <arm/imx/imx51_ccmvar.h>
     59      1.1  bsh #include <arm/imx/imx51_ccmreg.h>
     60      1.1  bsh 
     61      1.1  bsh #include "imxccm.h"	/* if CCM driver is configured into the kernel */
     62      1.1  bsh #include "wsdisplay.h"
     63      1.1  bsh #include "opt_imx51_ipuv3.h"
     64      1.1  bsh 
     65      1.1  bsh /*
     66      1.1  bsh  * Console variables. These are necessary since console is setup very early,
     67      1.1  bsh  * before devices get attached.
     68      1.1  bsh  */
     69      1.1  bsh struct {
     70  1.1.6.1  tls 	int is_console;
     71  1.1.6.1  tls 	struct imx51_wsscreen_descr *descr;
     72  1.1.6.1  tls 	struct wsdisplay_accessops *accessops;
     73  1.1.6.1  tls 	const struct lcd_panel_geometry *geom;
     74      1.1  bsh } imx51_ipuv3_console;
     75      1.1  bsh 
     76      1.1  bsh #define	IPUV3_READ(ipuv3, module, reg)					      \
     77      1.1  bsh 	bus_space_read_4((ipuv3)->iot, (ipuv3)->module##_ioh, (reg))
     78      1.1  bsh #define	IPUV3_WRITE(ipuv3, module, reg, val)				      \
     79      1.1  bsh 	bus_space_write_4((ipuv3)->iot, (ipuv3)->module##_ioh, (reg), (val))
     80      1.1  bsh 
     81      1.1  bsh #ifdef IPUV3_DEBUG
     82      1.1  bsh int ipuv3_debug = IPUV3_DEBUG;
     83      1.1  bsh #define	DPRINTFN(n,x)   if (ipuv3_debug>(n)) printf x; else
     84      1.1  bsh #else
     85      1.1  bsh #define	DPRINTFN(n,x)
     86      1.1  bsh #endif
     87      1.1  bsh 
     88      1.1  bsh int ipuv3intr(void *);
     89      1.1  bsh 
     90      1.1  bsh static void imx51_ipuv3_initialize(struct imx51_ipuv3_softc *,
     91      1.1  bsh     const struct lcd_panel_geometry *);
     92      1.1  bsh #if NWSDISPLAY > 0
     93      1.1  bsh static void imx51_ipuv3_setup_rasops(struct imx51_ipuv3_softc *,
     94      1.1  bsh     struct rasops_info *, struct imx51_wsscreen_descr *,
     95      1.1  bsh     const struct lcd_panel_geometry *);
     96      1.1  bsh #endif
     97      1.1  bsh static void imx51_ipuv3_set_idma_param(uint32_t *, uint32_t, uint32_t);
     98      1.1  bsh 
     99  1.1.6.1  tls static bool imx51_ipuv3_resume(device_t, const pmf_qual_t *);
    100  1.1.6.1  tls static bool imx51_ipuv3_suspend(device_t, const pmf_qual_t *);
    101      1.1  bsh 
    102      1.1  bsh #ifdef IPUV3_DEBUG
    103      1.1  bsh static void
    104      1.1  bsh imx51_ipuv3_dump(struct imx51_ipuv3_softc *sc)
    105      1.1  bsh {
    106      1.1  bsh 	int i;
    107      1.1  bsh 
    108      1.1  bsh 	DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
    109      1.1  bsh 
    110      1.1  bsh #define	__DUMP(grp, reg)						\
    111      1.1  bsh 	DPRINTFN(4, ("%-16s = 0x%08X\n", #reg, IPUV3_READ(sc, grp, IPU_##reg)))
    112      1.1  bsh 
    113      1.1  bsh 	__DUMP(cm, CM_CONF);
    114      1.1  bsh 	__DUMP(cm, CM_DISP_GEN);
    115      1.1  bsh 	__DUMP(idmac, IDMAC_CONF);
    116      1.1  bsh 	__DUMP(idmac, IDMAC_CH_EN_1);
    117      1.1  bsh 	__DUMP(idmac, IDMAC_CH_EN_2);
    118      1.1  bsh 	__DUMP(idmac, IDMAC_CH_PRI_1);
    119      1.1  bsh 	__DUMP(idmac, IDMAC_CH_PRI_2);
    120      1.1  bsh 	__DUMP(idmac, IDMAC_BNDM_EN_1);
    121      1.1  bsh 	__DUMP(idmac, IDMAC_BNDM_EN_2);
    122      1.1  bsh 	__DUMP(cm, CM_CH_DB_MODE_SEL_0);
    123      1.1  bsh 	__DUMP(cm, CM_CH_DB_MODE_SEL_1);
    124      1.1  bsh 	__DUMP(dmfc, DMFC_WR_CHAN);
    125      1.1  bsh 	__DUMP(dmfc, DMFC_WR_CHAN_DEF);
    126      1.1  bsh 	__DUMP(dmfc, DMFC_DP_CHAN);
    127      1.1  bsh 	__DUMP(dmfc, DMFC_DP_CHAN_DEF);
    128      1.1  bsh 	__DUMP(dmfc, DMFC_IC_CTRL);
    129      1.1  bsh 	__DUMP(cm, CM_FS_PROC_FLOW1);
    130      1.1  bsh 	__DUMP(cm, CM_FS_PROC_FLOW2);
    131      1.1  bsh 	__DUMP(cm, CM_FS_PROC_FLOW3);
    132      1.1  bsh 	__DUMP(cm, CM_FS_DISP_FLOW1);
    133      1.1  bsh 	__DUMP(dc, DC_DISP_CONF1_0);
    134      1.1  bsh 	__DUMP(dc, DC_DISP_CONF2_0);
    135      1.1  bsh 	__DUMP(dc, DC_WR_CH_CONF_5);
    136      1.1  bsh 
    137      1.1  bsh 	printf("*** IPU ***\n");
    138      1.1  bsh 	for (i = 0; i <= 0x17c; i += 4)
    139      1.1  bsh 		DPRINTFN(6, ("0x%08X = 0x%08X\n", i, IPUV3_READ(sc, cm, i)));
    140      1.1  bsh 	printf("*** IDMAC ***\n");
    141      1.1  bsh 	for (i = 0; i <= 0x104; i += 4)
    142      1.1  bsh 		DPRINTFN(6, ("0x%08X = 0x%08X\n", i, IPUV3_READ(sc, idmac, i)));
    143      1.1  bsh 	printf("*** CPMEM ***\n");
    144      1.1  bsh 	for (i = 0x5c0; i <= 0x600; i += 4)
    145      1.1  bsh 		DPRINTFN(6, ("0x%08X = 0x%08X\n", i, IPUV3_READ(sc, cpmem, i)));
    146      1.1  bsh 
    147      1.1  bsh #undef __DUMP
    148      1.1  bsh 
    149      1.1  bsh }
    150      1.1  bsh #endif
    151      1.1  bsh 
    152      1.1  bsh static void
    153      1.1  bsh imx51_ipuv3_enable_display(struct imx51_ipuv3_softc *sc)
    154      1.1  bsh {
    155      1.1  bsh 	uint32_t reg = 0;
    156      1.1  bsh 
    157      1.1  bsh 	DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
    158      1.1  bsh 
    159      1.1  bsh 	/* enable sub modules */
    160      1.1  bsh 	reg = IPUV3_READ(sc, cm, IPU_CM_CONF);
    161      1.1  bsh 	reg |= CM_CONF_DP_EN |
    162      1.1  bsh 	    CM_CONF_DC_EN |
    163      1.1  bsh 	    CM_CONF_DMFC_EN |
    164      1.1  bsh 	    CM_CONF_DI0_EN;
    165      1.1  bsh 	IPUV3_WRITE(sc, cm, IPU_CM_CONF, reg);
    166      1.1  bsh }
    167      1.1  bsh 
    168      1.1  bsh static void
    169      1.1  bsh imx51_ipuv3_dmfc_init(struct imx51_ipuv3_softc *sc)
    170      1.1  bsh {
    171      1.1  bsh 	DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
    172      1.1  bsh 
    173      1.1  bsh 	/* IC channel is disabled */
    174      1.1  bsh 	IPUV3_WRITE(sc, dmfc, IPU_DMFC_IC_CTRL,
    175      1.1  bsh 	    IC_IN_PORT_DISABLE);
    176      1.1  bsh 
    177      1.1  bsh 	IPUV3_WRITE(sc, dmfc, IPU_DMFC_WR_CHAN, 0x00000000);
    178      1.1  bsh 	IPUV3_WRITE(sc, dmfc, IPU_DMFC_WR_CHAN_DEF, 0x20202020);
    179      1.1  bsh 	IPUV3_WRITE(sc, dmfc, IPU_DMFC_DP_CHAN, 0x00000094);
    180      1.1  bsh 	IPUV3_WRITE(sc, dmfc, IPU_DMFC_DP_CHAN_DEF, 0x202020F6);
    181      1.1  bsh 
    182      1.1  bsh 	IPUV3_WRITE(sc, dmfc, IPU_DMFC_GENERAL1,
    183      1.1  bsh 	    DCDP_SYNC_PR_ROUNDROBIN);
    184      1.1  bsh 
    185      1.1  bsh #ifdef IPUV3_DEBUG
    186      1.1  bsh 	int i;
    187      1.1  bsh 	printf("*** DMFC ***\n");
    188      1.1  bsh 	for (i = 0; i <= 0x34; i += 4)
    189      1.1  bsh 		printf("0x%08X = 0x%08X\n", i, IPUV3_READ(sc, dmfc, i));
    190      1.1  bsh 
    191      1.1  bsh 	printf("%s: DMFC_IC_CTRL         0x%08X\n", __func__,
    192      1.1  bsh 	    IPUV3_READ(sc, dmfc, IPU_DMFC_IC_CTRL));
    193      1.1  bsh 	printf("%s: IPU_DMFC_WR_CHAN     0x%08X\n", __func__,
    194      1.1  bsh 	    IPUV3_READ(sc, dmfc, IPU_DMFC_WR_CHAN));
    195      1.1  bsh 	printf("%s: IPU_DMFC_WR_CHAN_DEF 0x%08X\n", __func__,
    196      1.1  bsh 	    IPUV3_READ(sc, dmfc, IPU_DMFC_WR_CHAN_DEF));
    197      1.1  bsh 	printf("%s: IPU_DMFC_GENERAL1    0x%08X\n", __func__,
    198      1.1  bsh 	    IPUV3_READ(sc, dmfc, IPU_DMFC_GENERAL1));
    199      1.1  bsh #endif
    200      1.1  bsh }
    201      1.1  bsh 
    202      1.1  bsh static void
    203      1.1  bsh imx51_ipuv3_dc_map_clear(struct imx51_ipuv3_softc *sc, int map)
    204      1.1  bsh {
    205      1.1  bsh 	DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
    206      1.1  bsh 
    207      1.1  bsh 	uint32_t reg;
    208      1.1  bsh 	uint32_t addr;
    209      1.1  bsh 
    210      1.1  bsh 	addr = IPU_DC_MAP_CONF_PNTR(map / 2);
    211      1.1  bsh 	reg = IPUV3_READ(sc, dc, addr);
    212      1.1  bsh 	reg &= ~(0xFFFF << (16 * (map & 0x1)));
    213      1.1  bsh 	IPUV3_WRITE(sc, dc, addr, reg);
    214      1.1  bsh }
    215      1.1  bsh 
    216      1.1  bsh static void
    217      1.1  bsh imx51_ipuv3_dc_map_conf(struct imx51_ipuv3_softc *sc,
    218      1.1  bsh     int map, int byte, int offset, uint8_t mask)
    219      1.1  bsh {
    220      1.1  bsh 	DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
    221      1.1  bsh 
    222      1.1  bsh 	uint32_t reg;
    223      1.1  bsh 	uint32_t addr;
    224      1.1  bsh 
    225      1.1  bsh 	addr = IPU_DC_MAP_CONF_MASK((map * 3 + byte) / 2);
    226      1.1  bsh 	reg = IPUV3_READ(sc, dc, addr);
    227      1.1  bsh 	reg &= ~(0xFFFF << (16 * ((map * 3 + byte) & 0x1)));
    228      1.1  bsh 	reg |= ((offset << 8) | mask) << (16 * ((map * 3 + byte) & 0x1));
    229      1.1  bsh 	IPUV3_WRITE(sc, dc, addr, reg);
    230      1.1  bsh #ifdef IPUV3_DEBUG
    231      1.1  bsh 	printf("%s: addr 0x%08X reg 0x%08X\n", __func__, addr, reg);
    232      1.1  bsh #endif
    233      1.1  bsh 
    234      1.1  bsh 	addr = IPU_DC_MAP_CONF_PNTR(map / 2);
    235      1.1  bsh 	reg = IPUV3_READ(sc, dc, addr);
    236      1.1  bsh 	reg &= ~(0x1F << ((16 * (map & 0x1)) + (5 * byte)));
    237      1.1  bsh 	reg |= ((map * 3) + byte) << ((16 * (map & 0x1)) + (5 * byte));
    238      1.1  bsh 	IPUV3_WRITE(sc, dc, addr, reg);
    239      1.1  bsh #ifdef IPUV3_DEBUG
    240      1.1  bsh 	printf("%s: addr 0x%08X reg 0x%08X\n", __func__, addr, reg);
    241      1.1  bsh #endif
    242      1.1  bsh }
    243      1.1  bsh 
    244      1.1  bsh static void
    245      1.1  bsh imx51_ipuv3_dc_template_command(struct imx51_ipuv3_softc *sc,
    246      1.1  bsh     int index, int sync, int gluelogic, int waveform, int mapping,
    247      1.1  bsh     int operand, int opecode, int stop)
    248      1.1  bsh {
    249      1.1  bsh 	DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
    250      1.1  bsh 
    251      1.1  bsh 	uint32_t reg;
    252      1.1  bsh 
    253      1.1  bsh 	reg = (sync << 0) |
    254      1.1  bsh 	    (gluelogic << 4) |
    255      1.1  bsh 	    (waveform << 11) |
    256      1.1  bsh 	    (mapping << 15) |
    257      1.1  bsh 	    (operand << 20);
    258      1.1  bsh 	IPUV3_WRITE(sc, dctmpl, index * 8, reg);
    259      1.1  bsh #ifdef IPUV3_DEBUG
    260      1.1  bsh 	printf("%s: addr 0x%08X reg 0x%08X\n", __func__, index * 8, reg);
    261      1.1  bsh #endif
    262      1.1  bsh 	reg = (opecode << 0) |
    263      1.1  bsh 	    (stop << 9);
    264      1.1  bsh 	IPUV3_WRITE(sc, dctmpl, index * 8 + 4, reg);
    265      1.1  bsh #ifdef IPUV3_DEBUG
    266      1.1  bsh 	printf("%s: addr 0x%08X reg 0x%08X\n", __func__, index * 8 + 4, reg);
    267      1.1  bsh #endif
    268      1.1  bsh }
    269      1.1  bsh 
    270      1.1  bsh static void
    271      1.1  bsh imx51_ipuv3_set_routine_link(struct imx51_ipuv3_softc *sc,
    272      1.1  bsh     int base, int evt, int addr, int pri)
    273      1.1  bsh {
    274      1.1  bsh 	DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
    275      1.1  bsh 
    276      1.1  bsh 	uint32_t reg;
    277      1.1  bsh 
    278      1.1  bsh 	reg = IPUV3_READ(sc, dc, IPU_DC_RL(base, evt));
    279      1.1  bsh 	reg &= ~(0xFFFF << (16 * (evt & 0x1)));
    280      1.1  bsh 	reg |= ((addr << 8) | pri) << (16 * (evt & 0x1));
    281      1.1  bsh 	IPUV3_WRITE(sc, dc, IPU_DC_RL(base, evt), reg);
    282      1.1  bsh #ifdef IPUV3_DEBUG
    283      1.1  bsh 	printf("%s: event %d addr %d priority %d\n", __func__,
    284      1.1  bsh 	    evt, addr, pri);
    285      1.1  bsh 	printf("%s: %p = 0x%08X\n", __func__,
    286      1.1  bsh 	    (void *)IPU_DC_RL(base, evt), reg);
    287      1.1  bsh #endif
    288      1.1  bsh }
    289      1.1  bsh 
    290      1.1  bsh static void
    291      1.1  bsh imx51_ipuv3_dc_init(struct imx51_ipuv3_softc *sc)
    292      1.1  bsh {
    293      1.1  bsh 	uint32_t reg;
    294      1.1  bsh 
    295      1.1  bsh 	DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
    296      1.1  bsh 
    297      1.1  bsh 	imx51_ipuv3_dc_map_clear(sc, 0);
    298      1.1  bsh 	imx51_ipuv3_dc_map_conf(sc, 0, 0,  7, 0xff);
    299      1.1  bsh 	imx51_ipuv3_dc_map_conf(sc, 0, 1, 15, 0xff);
    300      1.1  bsh 	imx51_ipuv3_dc_map_conf(sc, 0, 2, 23, 0xff);
    301      1.1  bsh 	imx51_ipuv3_dc_map_clear(sc, 1);
    302      1.1  bsh 	imx51_ipuv3_dc_map_conf(sc, 1, 0,  5, 0xfc);
    303      1.1  bsh 	imx51_ipuv3_dc_map_conf(sc, 1, 1, 11, 0xfc);
    304      1.1  bsh 	imx51_ipuv3_dc_map_conf(sc, 1, 2, 17, 0xfc);
    305      1.1  bsh 	imx51_ipuv3_dc_map_clear(sc, 2);
    306      1.1  bsh 	imx51_ipuv3_dc_map_conf(sc, 2, 0, 15, 0xff);
    307      1.1  bsh 	imx51_ipuv3_dc_map_conf(sc, 2, 1, 23, 0xff);
    308      1.1  bsh 	imx51_ipuv3_dc_map_conf(sc, 2, 2,  7, 0xff);
    309      1.1  bsh 	imx51_ipuv3_dc_map_clear(sc, 3);
    310      1.1  bsh 	imx51_ipuv3_dc_map_conf(sc, 3, 0,  4, 0xf8);
    311      1.1  bsh 	imx51_ipuv3_dc_map_conf(sc, 3, 1, 10, 0xfc);
    312      1.1  bsh 	imx51_ipuv3_dc_map_conf(sc, 3, 2, 15, 0xf8);
    313      1.1  bsh 	imx51_ipuv3_dc_map_clear(sc, 4);
    314      1.1  bsh 	imx51_ipuv3_dc_map_conf(sc, 4, 0,  5, 0xfc);
    315      1.1  bsh 	imx51_ipuv3_dc_map_conf(sc, 4, 1, 13, 0xfc);
    316      1.1  bsh 	imx51_ipuv3_dc_map_conf(sc, 4, 2, 21, 0xfc);
    317      1.1  bsh 
    318      1.1  bsh 	/* microcode */
    319      1.1  bsh 	imx51_ipuv3_dc_template_command(sc,
    320      1.1  bsh 	    5, 5, 8, 1, 5, 0, 0x180, 1);
    321      1.1  bsh 	imx51_ipuv3_dc_template_command(sc,
    322      1.1  bsh 	    6, 5, 4, 1, 5, 0, 0x180, 1);
    323      1.1  bsh 	imx51_ipuv3_dc_template_command(sc,
    324      1.1  bsh 	    7, 5, 0, 1, 5, 0, 0x180, 1);
    325      1.1  bsh 
    326      1.1  bsh 	reg = (4 << 5) | 0x2;
    327      1.1  bsh 	IPUV3_WRITE(sc, dc, IPU_DC_WR_CH_CONF_5, reg);
    328      1.1  bsh 	IPUV3_WRITE(sc, dc, IPU_DC_WR_CH_CONF_1, 0x4);
    329      1.1  bsh 	IPUV3_WRITE(sc, dc, IPU_DC_WR_CH_ADDR_5, 0x0);
    330      1.1  bsh 	IPUV3_WRITE(sc, dc, IPU_DC_GEN, 0x44);
    331      1.1  bsh 
    332      1.1  bsh 	imx51_ipuv3_set_routine_link(sc, DC_RL_CH_5, DC_RL_EVT_NL, 5, 3);
    333      1.1  bsh 	imx51_ipuv3_set_routine_link(sc, DC_RL_CH_5, DC_RL_EVT_EOL, 6, 2);
    334      1.1  bsh 	imx51_ipuv3_set_routine_link(sc, DC_RL_CH_5, DC_RL_EVT_NEW_DATA, 7, 1);
    335      1.1  bsh 	imx51_ipuv3_set_routine_link(sc, DC_RL_CH_5, DC_RL_EVT_NF, 0, 0);
    336      1.1  bsh 	imx51_ipuv3_set_routine_link(sc, DC_RL_CH_5, DC_RL_EVT_NFIELD, 0, 0);
    337      1.1  bsh 	imx51_ipuv3_set_routine_link(sc, DC_RL_CH_5, DC_RL_EVT_EOF, 0, 0);
    338      1.1  bsh 	imx51_ipuv3_set_routine_link(sc, DC_RL_CH_5, DC_RL_EVT_EOFIELD, 0, 0);
    339      1.1  bsh 	imx51_ipuv3_set_routine_link(sc, DC_RL_CH_5, DC_RL_EVT_NEW_CHAN, 0, 0);
    340      1.1  bsh 	imx51_ipuv3_set_routine_link(sc, DC_RL_CH_5, DC_RL_EVT_NEW_ADDR, 0, 0);
    341      1.1  bsh 
    342      1.1  bsh #ifdef IPUV3_DEBUG
    343      1.1  bsh 	int i;
    344      1.1  bsh 	printf("*** DC ***\n");
    345      1.1  bsh 	for (i = 0; i <= 0x1C8; i += 4)
    346      1.1  bsh 		printf("0x%08X = 0x%08X\n", i, IPUV3_READ(sc, dc, i));
    347      1.1  bsh 	printf("*** DCTEMPL ***\n");
    348      1.1  bsh 	for (i = 0; i <= 0x100; i += 4)
    349      1.1  bsh 		printf("0x%08X = 0x%08X\n", i, IPUV3_READ(sc, dctmpl, i));
    350      1.1  bsh #endif
    351      1.1  bsh }
    352      1.1  bsh 
    353      1.1  bsh static void
    354      1.1  bsh imx51_ipuv3_dc_display_config(struct imx51_ipuv3_softc *sc, int width)
    355      1.1  bsh {
    356      1.1  bsh 	DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
    357      1.1  bsh 
    358      1.1  bsh 	IPUV3_WRITE(sc, dc, IPU_DC_DISP_CONF2_0, width);
    359      1.1  bsh }
    360      1.1  bsh 
    361      1.1  bsh static void
    362      1.1  bsh imx51_ipuv3_di_sync_conf(struct imx51_ipuv3_softc *sc, int no,
    363      1.1  bsh     uint32_t reg_gen0, uint32_t reg_gen1, uint32_t repeat)
    364      1.1  bsh {
    365      1.1  bsh 	DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
    366      1.1  bsh 
    367      1.1  bsh 	uint32_t reg;
    368      1.1  bsh 
    369      1.1  bsh 	IPUV3_WRITE(sc, di0, IPU_DI_SW_GEN0(no), reg_gen0);
    370      1.1  bsh 	IPUV3_WRITE(sc, di0, IPU_DI_SW_GEN1(no), reg_gen1);
    371      1.1  bsh 	reg = IPUV3_READ(sc, di0, IPU_DI_STP_REP(no));
    372      1.1  bsh 	reg &= ~DI_STP_REP_MASK(no);
    373      1.1  bsh 	reg |= repeat << DI_STP_REP_SHIFT(no);
    374      1.1  bsh 	IPUV3_WRITE(sc, di0, IPU_DI_STP_REP(no), reg);
    375      1.1  bsh 
    376      1.1  bsh #ifdef IPUV3_DEBUG
    377      1.1  bsh 	printf("%s: no %d\n", __func__, no);
    378      1.1  bsh 	printf("%s: addr 0x%08X reg_gen0   0x%08X\n", __func__,
    379      1.1  bsh 	    IPU_DI_SW_GEN0(no), reg_gen0);
    380      1.1  bsh 	printf("%s: addr 0x%08X reg_gen1   0x%08X\n", __func__,
    381      1.1  bsh 	    IPU_DI_SW_GEN1(no), reg_gen1);
    382      1.1  bsh 	printf("%s: addr 0x%08X DI_STP_REP 0x%08X\n", __func__,
    383      1.1  bsh 	    IPU_DI_STP_REP(no), reg);
    384      1.1  bsh #endif
    385      1.1  bsh }
    386      1.1  bsh 
    387      1.1  bsh static void
    388      1.1  bsh imx51_ipuv3_di_init(struct imx51_ipuv3_softc *sc)
    389      1.1  bsh {
    390      1.1  bsh 	DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
    391      1.1  bsh 
    392      1.1  bsh 	uint32_t reg;
    393      1.1  bsh 	uint32_t div;
    394      1.1  bsh 	u_int ipuclk;
    395      1.1  bsh 	const struct lcd_panel_geometry *geom = sc->geometry;
    396      1.1  bsh 
    397      1.1  bsh #if NIMXCCM > 0
    398      1.1  bsh 	ipuclk = imx51_get_clock(IMX51CLK_IPU_HSP_CLK_ROOT);
    399      1.1  bsh #elif !defined(IMX51_IPU_HSP_CLOCK)
    400      1.1  bsh #error	IMX51_CPU_HSP_CLOCK need to be defined.
    401      1.1  bsh #else
    402      1.1  bsh 	ipuclk = IMX51_IPU_HSP_CLOCK;
    403      1.1  bsh #endif
    404      1.1  bsh 	DPRINTFN(3, ("IPU HSP clock = %d\n", ipuclk));
    405      1.1  bsh 	div = (ipuclk * 16) / geom->pixel_clk;
    406      1.1  bsh 	div = div < 16 ? 16 : div & 0xff8;
    407      1.1  bsh 
    408      1.1  bsh 	/* DI counter */
    409      1.1  bsh 	reg = IPUV3_READ(sc, cm, IPU_CM_DISP_GEN);
    410      1.1  bsh 	reg &= ~(CM_DISP_GEN_DI1_COUNTER_RELEASE |
    411      1.1  bsh 	    CM_DISP_GEN_DI0_COUNTER_RELEASE);
    412      1.1  bsh 	IPUV3_WRITE(sc, cm, IPU_CM_DISP_GEN, reg);
    413      1.1  bsh 
    414      1.1  bsh 	IPUV3_WRITE(sc, di0, IPU_DI_BS_CLKGEN0, div);
    415      1.1  bsh 	IPUV3_WRITE(sc, di0, IPU_DI_BS_CLKGEN1,
    416      1.1  bsh 	    (div / 16) << DI_BS_CLKGEN1_DOWN_SHIFT);
    417      1.1  bsh #ifdef IPUV3_DEBUG
    418      1.1  bsh 	printf("%s: IPU_DI_BS_CLKGEN0 = 0x%08X\n", __func__,
    419      1.1  bsh 	    IPUV3_READ(sc, di0, IPU_DI_BS_CLKGEN0));
    420      1.1  bsh 	printf("%s: IPU_DI_BS_CLKGEN1 = 0x%08X\n", __func__,
    421      1.1  bsh 	    IPUV3_READ(sc, di0, IPU_DI_BS_CLKGEN1));
    422      1.1  bsh #endif
    423      1.1  bsh 	/* Display Time settings */
    424      1.1  bsh 	reg = ((div / 16 - 1) << DI_DW_GEN_ACCESS_SIZE_SHIFT) |
    425      1.1  bsh 	    ((div / 16 - 1) << DI_DW_GEN_COMPONNENT_SIZE_SHIFT) |
    426      1.1  bsh 	    (3 << DI_DW_GEN_PIN_SHIFT(15));
    427      1.1  bsh 	IPUV3_WRITE(sc, di0, IPU_DI_DW_GEN(0), reg);
    428      1.1  bsh #ifdef IPUV3_DEBUG
    429      1.1  bsh 	printf("%s: div = %d\n", __func__, div);
    430      1.1  bsh 	printf("%s: IPU_DI_DW_GEN(0) 0x%08X = 0x%08X\n", __func__,
    431      1.1  bsh 	    IPU_DI_DW_GEN(0), reg);
    432      1.1  bsh #endif
    433      1.1  bsh 
    434      1.1  bsh 	/* Up & Down Data Wave Set */
    435      1.1  bsh 	reg = (div / 16 * 2) << DI_DW_SET_DOWN_SHIFT;
    436      1.1  bsh 	IPUV3_WRITE(sc, di0, IPU_DI_DW_SET(0, 3), reg);
    437      1.1  bsh #ifdef IPUV3_DEBUG
    438      1.1  bsh 	printf("%s: IPU_DI_DW_SET(0, 3) 0x%08X = 0x%08X\n", __func__,
    439      1.1  bsh 	    IPU_DI_DW_SET(0, 3), reg);
    440      1.1  bsh #endif
    441      1.1  bsh 
    442      1.1  bsh 	/* internal HSCYNC */
    443      1.1  bsh 	imx51_ipuv3_di_sync_conf(sc, 1,
    444      1.1  bsh 	    __DI_SW_GEN0(geom->panel_width + geom->hsync_width +
    445      1.1  bsh 		geom->left + geom->right - 1, 1, 0, 0),
    446      1.1  bsh 	    __DI_SW_GEN1(0, 1, 0, 0, 0, 0, 0),
    447      1.1  bsh 	    0);
    448      1.1  bsh 
    449      1.1  bsh 	/* HSYNC */
    450      1.1  bsh 	imx51_ipuv3_di_sync_conf(sc, 2,
    451      1.1  bsh 	    __DI_SW_GEN0(geom->panel_width + geom->hsync_width +
    452      1.1  bsh 		geom->left + geom->right - 1, 1, 0, 1),
    453      1.1  bsh 	    __DI_SW_GEN1(1, 1, 0, geom->hsync_width * 2, 1, 0, 0),
    454      1.1  bsh 	    0);
    455      1.1  bsh 
    456      1.1  bsh 	/* VSYNC */
    457      1.1  bsh 	imx51_ipuv3_di_sync_conf(sc, 3,
    458      1.1  bsh 	    __DI_SW_GEN0(geom->panel_height + geom->vsync_width +
    459      1.1  bsh 		geom->upper + geom->lower - 1, 2, 0, 0),
    460      1.1  bsh 	    __DI_SW_GEN1(1, 1, 0, geom->vsync_width * 2, 2, 0, 0),
    461      1.1  bsh 	    0);
    462      1.1  bsh 
    463      1.1  bsh 	IPUV3_WRITE(sc, di0, IPU_DI_SCR_CONF,
    464      1.1  bsh 	    geom->panel_height + geom->vsync_width + geom->upper +
    465      1.1  bsh 	    geom->lower - 1);
    466      1.1  bsh 
    467      1.1  bsh 	/* Active Lines Start */
    468      1.1  bsh 	imx51_ipuv3_di_sync_conf(sc, 4,
    469      1.1  bsh 	    __DI_SW_GEN0(0, 3, geom->vsync_width + geom->upper, 3),
    470      1.1  bsh 	    __DI_SW_GEN1(0, 0, 4, 0, 0, 0, 0),
    471      1.1  bsh 	    geom->panel_height);
    472      1.1  bsh 
    473      1.1  bsh 	/* Active Clock Start */
    474      1.1  bsh 	imx51_ipuv3_di_sync_conf(sc, 5,
    475      1.1  bsh 	    __DI_SW_GEN0(0, 1, geom->hsync_width + geom->left, 1),
    476      1.1  bsh 	    __DI_SW_GEN1(0, 0, 5, 0, 0, 0, 0),
    477      1.1  bsh 	    geom->panel_width);
    478      1.1  bsh 
    479      1.1  bsh 	IPUV3_WRITE(sc, di0, IPU_DI_SW_GEN0(6), 0);
    480      1.1  bsh 	IPUV3_WRITE(sc, di0, IPU_DI_SW_GEN1(6), 0);
    481      1.1  bsh 	IPUV3_WRITE(sc, di0, IPU_DI_SW_GEN0(7), 0);
    482      1.1  bsh 	IPUV3_WRITE(sc, di0, IPU_DI_SW_GEN1(7), 0);
    483      1.1  bsh 	IPUV3_WRITE(sc, di0, IPU_DI_SW_GEN0(8), 0);
    484      1.1  bsh 	IPUV3_WRITE(sc, di0, IPU_DI_SW_GEN1(8), 0);
    485      1.1  bsh 	IPUV3_WRITE(sc, di0, IPU_DI_SW_GEN0(9), 0);
    486      1.1  bsh 	IPUV3_WRITE(sc, di0, IPU_DI_SW_GEN1(9), 0);
    487      1.1  bsh 
    488      1.1  bsh 	reg = IPUV3_READ(sc, di0, IPU_DI_STP_REP(6));
    489      1.1  bsh 	reg &= ~DI_STP_REP_MASK(6);
    490      1.1  bsh 	IPUV3_WRITE(sc, di0, IPU_DI_STP_REP(6), reg);
    491      1.1  bsh 	IPUV3_WRITE(sc, di0, IPU_DI_STP_REP(7), 0);
    492      1.1  bsh 	IPUV3_WRITE(sc, di0, IPU_DI_STP_REP(9), 0);
    493      1.1  bsh 
    494      1.1  bsh 	IPUV3_WRITE(sc, di0, IPU_DI_GENERAL, 0);
    495      1.1  bsh 	reg = ((3 - 1) << DI_SYNC_AS_GEN_VSYNC_SEL_SHIFT) | 0x2;
    496      1.1  bsh 	IPUV3_WRITE(sc, di0, IPU_DI_SYNC_AS_GEN, reg);
    497      1.1  bsh 	IPUV3_WRITE(sc, di0, IPU_DI_POL, DI_POL_DRDY_POLARITY_15);
    498      1.1  bsh 
    499      1.1  bsh 	/* release DI counter */
    500      1.1  bsh 	reg = IPUV3_READ(sc, cm, IPU_CM_DISP_GEN);
    501      1.1  bsh 	reg |= CM_DISP_GEN_DI0_COUNTER_RELEASE;
    502      1.1  bsh 	IPUV3_WRITE(sc, cm, IPU_CM_DISP_GEN, reg);
    503      1.1  bsh 
    504      1.1  bsh #ifdef IPUV3_DEBUG
    505      1.1  bsh 	int i;
    506      1.1  bsh 	printf("*** DI0 ***\n");
    507      1.1  bsh 	for (i = 0; i <= 0x174; i += 4)
    508      1.1  bsh 		printf("0x%08X = 0x%08X\n", i, IPUV3_READ(sc, di0, i));
    509      1.1  bsh 
    510      1.1  bsh 	printf("%s: IPU_CM_DISP_GEN    : 0x%08X\n", __func__,
    511      1.1  bsh 	    IPUV3_READ(sc, cm, IPU_CM_DISP_GEN));
    512      1.1  bsh 	printf("%s: IPU_DI_SYNC_AS_GEN : 0x%08X\n", __func__,
    513      1.1  bsh 	    IPUV3_READ(sc, di0, IPU_DI_SYNC_AS_GEN));
    514      1.1  bsh 	printf("%s: IPU_DI_GENERAL     : 0x%08X\n", __func__,
    515      1.1  bsh 	    IPUV3_READ(sc, di0, IPU_DI_GENERAL));
    516      1.1  bsh 	printf("%s: IPU_DI_POL         : 0x%08X\n", __func__,
    517      1.1  bsh 	    IPUV3_READ(sc, di0, IPU_DI_POL));
    518      1.1  bsh #endif
    519      1.1  bsh }
    520      1.1  bsh 
    521      1.1  bsh 
    522      1.1  bsh void
    523      1.1  bsh imx51_ipuv3_geometry(struct imx51_ipuv3_softc *sc,
    524      1.1  bsh     const struct lcd_panel_geometry *geom)
    525      1.1  bsh {
    526      1.1  bsh 	DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
    527      1.1  bsh 
    528      1.1  bsh 	sc->geometry = geom;
    529      1.1  bsh 
    530      1.1  bsh #ifdef IPUV3_DEBUG
    531      1.1  bsh 	printf("%s: screen height = %d\n",__func__ , geom->panel_height);
    532      1.1  bsh 	printf("%s:        width  = %d\n",__func__ , geom->panel_width);
    533      1.1  bsh 	printf("%s: IPU Clock = %d\n", __func__,
    534      1.1  bsh 	    imx51_get_clock(IMX51CLK_IPU_HSP_CLK_ROOT));
    535      1.1  bsh 	printf("%s: Pixel Clock = %d\n", __func__, geom->pixel_clk);
    536      1.1  bsh #endif
    537      1.1  bsh 
    538      1.1  bsh 	imx51_ipuv3_di_init(sc);
    539      1.1  bsh 
    540      1.1  bsh #ifdef IPUV3_DEBUG
    541      1.1  bsh 	printf("%s: IPU_CM_DISP_GEN    : 0x%08X\n", __func__,
    542      1.1  bsh 	    IPUV3_READ(sc, cm, IPU_CM_DISP_GEN));
    543      1.1  bsh #endif
    544      1.1  bsh 
    545      1.1  bsh 	imx51_ipuv3_dc_display_config(sc, geom->panel_width);
    546      1.1  bsh 
    547      1.1  bsh 	return;
    548      1.1  bsh }
    549      1.1  bsh 
    550      1.1  bsh /*
    551      1.1  bsh  * Initialize the IPUV3 controller.
    552      1.1  bsh  */
    553      1.1  bsh static void
    554      1.1  bsh imx51_ipuv3_initialize(struct imx51_ipuv3_softc *sc,
    555      1.1  bsh     const struct lcd_panel_geometry *geom)
    556      1.1  bsh {
    557      1.1  bsh 	uint32_t reg;
    558      1.1  bsh 
    559      1.1  bsh 	DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
    560      1.1  bsh 
    561      1.1  bsh 	IPUV3_WRITE(sc, cm, IPU_CM_CONF, 0);
    562      1.1  bsh 
    563      1.1  bsh 	/* reset */
    564      1.1  bsh 	IPUV3_WRITE(sc, cm, IPU_CM_MEM_RST, CM_MEM_START | CM_MEM_EN);
    565      1.1  bsh 	while (IPUV3_READ(sc, cm, IPU_CM_MEM_RST) & CM_MEM_START)
    566      1.1  bsh 		; /* wait */
    567      1.1  bsh 
    568      1.1  bsh 	imx51_ipuv3_dmfc_init(sc);
    569      1.1  bsh 	imx51_ipuv3_dc_init(sc);
    570      1.1  bsh 
    571      1.1  bsh 	imx51_ipuv3_geometry(sc, geom);
    572      1.1  bsh 
    573      1.1  bsh 	/* set global alpha */
    574      1.1  bsh 	IPUV3_WRITE(sc, dp, IPU_DP_GRAPH_WIND_CTRL_SYNC, 0x80 << 24);
    575      1.1  bsh 	IPUV3_WRITE(sc, dp, IPU_DP_COM_CONF_SYNC, DP_DP_GWAM_SYNC);
    576      1.1  bsh 
    577      1.1  bsh 	reg = IPUV3_READ(sc, cm, IPU_CM_DISP_GEN);
    578      1.1  bsh 	reg |= CM_DISP_GEN_MCU_MAX_BURST_STOP |
    579      1.1  bsh 	    CM_DISP_GEN_MCU_T(0x8);
    580      1.1  bsh 	IPUV3_WRITE(sc, cm, IPU_CM_DISP_GEN, reg);
    581      1.1  bsh }
    582      1.1  bsh 
    583      1.1  bsh static void
    584      1.1  bsh imx51_ipuv3_init_screen(void *cookie, struct vcons_screen *scr,
    585      1.1  bsh 		    int existing, long *defattr)
    586      1.1  bsh {
    587      1.1  bsh 	DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
    588      1.1  bsh 
    589      1.1  bsh 	struct imx51_ipuv3_softc *sc = cookie;
    590      1.1  bsh 	struct rasops_info *ri = &scr->scr_ri;
    591  1.1.6.1  tls 	struct imx51_wsscreen_descr *descr = imx51_ipuv3_console.descr;
    592      1.1  bsh 
    593      1.1  bsh 	if ((scr == &sc->console) && (sc->vd.active != NULL))
    594      1.1  bsh 		return;
    595      1.1  bsh 
    596      1.1  bsh 	ri->ri_bits = sc->active->buf_va;
    597      1.1  bsh 
    598      1.1  bsh 	scr->scr_flags |= VCONS_DONT_READ;
    599      1.1  bsh 	if (existing)
    600      1.1  bsh 		ri->ri_flg |= RI_CLEAR;
    601      1.1  bsh 
    602      1.1  bsh 	imx51_ipuv3_setup_rasops(sc, ri, descr, sc->geometry);
    603      1.1  bsh 
    604      1.1  bsh 	ri->ri_caps = WSSCREEN_WSCOLORS;
    605      1.1  bsh 
    606      1.1  bsh 	rasops_reconfig(ri,
    607      1.1  bsh 	    ri->ri_height / ri->ri_font->fontheight,
    608      1.1  bsh 	    ri->ri_width / ri->ri_font->fontwidth);
    609      1.1  bsh 
    610      1.1  bsh 	ri->ri_hw = scr;
    611      1.1  bsh }
    612      1.1  bsh 
    613      1.1  bsh /*
    614      1.1  bsh  * Common driver attachment code.
    615      1.1  bsh  */
    616      1.1  bsh void
    617      1.1  bsh imx51_ipuv3_attach_sub(struct imx51_ipuv3_softc *sc,
    618      1.1  bsh     struct axi_attach_args *axia, const struct lcd_panel_geometry *geom)
    619      1.1  bsh {
    620      1.1  bsh 	DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
    621      1.1  bsh 
    622      1.1  bsh 	bus_space_tag_t iot = axia->aa_iot;
    623      1.1  bsh 	bus_space_handle_t ioh;
    624      1.1  bsh 	int error;
    625      1.1  bsh 
    626      1.1  bsh 	aprint_normal(": i.MX51 IPUV3 controller\n");
    627      1.1  bsh 
    628      1.1  bsh 	sc->n_screens = 0;
    629      1.1  bsh 	LIST_INIT(&sc->screens);
    630      1.1  bsh 
    631      1.1  bsh 	sc->iot = iot;
    632      1.1  bsh 	sc->dma_tag = &imx_bus_dma_tag;
    633      1.1  bsh 
    634      1.1  bsh 	/* map controller registers */
    635      1.1  bsh 	error = bus_space_map(iot, IPU_CM_BASE, IPU_CM_SIZE, 0, &ioh);
    636      1.1  bsh 	if (error)
    637      1.1  bsh 		goto fail_retarn_cm;
    638      1.1  bsh 	sc->cm_ioh = ioh;
    639      1.1  bsh 
    640      1.1  bsh 	/* map Display Multi FIFO Controller registers */
    641      1.1  bsh 	error = bus_space_map(iot, IPU_DMFC_BASE, IPU_DMFC_SIZE, 0, &ioh);
    642      1.1  bsh 	if (error)
    643      1.1  bsh 		goto fail_retarn_dmfc;
    644      1.1  bsh 	sc->dmfc_ioh = ioh;
    645      1.1  bsh 
    646      1.1  bsh 	/* map Display Interface registers */
    647      1.1  bsh 	error = bus_space_map(iot, IPU_DI0_BASE, IPU_DI0_SIZE, 0, &ioh);
    648      1.1  bsh 	if (error)
    649      1.1  bsh 		goto fail_retarn_di0;
    650      1.1  bsh 	sc->di0_ioh = ioh;
    651      1.1  bsh 
    652      1.1  bsh 	/* map Display Processor registers */
    653      1.1  bsh 	error = bus_space_map(iot, IPU_DP_BASE, IPU_DP_SIZE, 0, &ioh);
    654      1.1  bsh 	if (error)
    655      1.1  bsh 		goto fail_retarn_dp;
    656      1.1  bsh 	sc->dp_ioh = ioh;
    657      1.1  bsh 
    658      1.1  bsh 	/* map Display Controller registers */
    659      1.1  bsh 	error = bus_space_map(iot, IPU_DC_BASE, IPU_DC_SIZE, 0, &ioh);
    660      1.1  bsh 	if (error)
    661      1.1  bsh 		goto fail_retarn_dc;
    662      1.1  bsh 	sc->dc_ioh = ioh;
    663      1.1  bsh 
    664      1.1  bsh 	/* map Image DMA Controller registers */
    665      1.1  bsh 	error = bus_space_map(iot, IPU_IDMAC_BASE, IPU_IDMAC_SIZE, 0, &ioh);
    666      1.1  bsh 	if (error)
    667      1.1  bsh 		goto fail_retarn_idmac;
    668      1.1  bsh 	sc->idmac_ioh = ioh;
    669      1.1  bsh 
    670      1.1  bsh 	/* map CPMEM registers */
    671      1.1  bsh 	error = bus_space_map(iot, IPU_CPMEM_BASE, IPU_CPMEM_SIZE, 0, &ioh);
    672      1.1  bsh 	if (error)
    673      1.1  bsh 		goto fail_retarn_cpmem;
    674      1.1  bsh 	sc->cpmem_ioh = ioh;
    675      1.1  bsh 
    676      1.1  bsh 	/* map DCTEMPL registers */
    677      1.1  bsh 	error = bus_space_map(iot, IPU_DCTMPL_BASE, IPU_DCTMPL_SIZE, 0, &ioh);
    678      1.1  bsh 	if (error)
    679      1.1  bsh 		goto fail_retarn_dctmpl;
    680      1.1  bsh 	sc->dctmpl_ioh = ioh;
    681      1.1  bsh 
    682      1.1  bsh #ifdef notyet
    683      1.1  bsh 	sc->ih = imx51_ipuv3_intr_establish(IMX51_INT_IPUV3, IPL_BIO,
    684      1.1  bsh 	    ipuv3intr, sc);
    685      1.1  bsh 	if (sc->ih == NULL) {
    686      1.1  bsh 		aprint_error_dev(sc->dev,
    687      1.1  bsh 		    "unable to establish interrupt at irq %d\n",
    688      1.1  bsh 		    IMX51_INT_IPUV3);
    689      1.1  bsh 		return;
    690      1.1  bsh 	}
    691      1.1  bsh #endif
    692      1.1  bsh 
    693      1.1  bsh 	imx51_ipuv3_initialize(sc, geom);
    694      1.1  bsh 
    695      1.1  bsh #if NWSDISPLAY > 0
    696  1.1.6.1  tls 	struct imx51_wsscreen_descr *descr = imx51_ipuv3_console.descr;
    697      1.1  bsh 	struct imx51_ipuv3_screen *scr;
    698      1.1  bsh 
    699      1.1  bsh 	sc->mode = WSDISPLAYIO_MODE_EMUL;
    700      1.1  bsh 	error = imx51_ipuv3_new_screen(sc, descr->depth, &scr);
    701      1.1  bsh 	if (error) {
    702      1.1  bsh 		aprint_error_dev(sc->dev,
    703      1.1  bsh 		    "unable to create new screen (errno=%d)", error);
    704      1.1  bsh 		return;
    705      1.1  bsh 	}
    706      1.1  bsh 	sc->active = scr;
    707      1.1  bsh 
    708  1.1.6.1  tls 	vcons_init(&sc->vd, sc, &descr->c,
    709  1.1.6.1  tls 	    imx51_ipuv3_console.accessops);
    710      1.1  bsh 	sc->vd.init_screen = imx51_ipuv3_init_screen;
    711      1.1  bsh 
    712      1.1  bsh #ifdef IPUV3_DEBUG
    713      1.1  bsh 	printf("%s: IPUV3 console ? %d\n", __func__, imx51_ipuv3_console.is_console);
    714      1.1  bsh #endif
    715      1.1  bsh 
    716      1.1  bsh 	struct rasops_info *ri;
    717      1.1  bsh 	long defattr;
    718      1.1  bsh 	ri = &sc->console.scr_ri;
    719      1.1  bsh 
    720  1.1.6.1  tls 	vcons_init_screen(&sc->vd, &sc->console, 1,
    721  1.1.6.1  tls 	    &defattr);
    722  1.1.6.1  tls 	sc->console.scr_flags |= VCONS_SCREEN_IS_STATIC;
    723  1.1.6.1  tls 
    724  1.1.6.1  tls 	descr->c.nrows = ri->ri_rows;
    725  1.1.6.1  tls 	descr->c.ncols = ri->ri_cols;
    726  1.1.6.1  tls 	descr->c.textops = &ri->ri_ops;
    727  1.1.6.1  tls 	descr->c.capabilities = ri->ri_caps;
    728      1.1  bsh 
    729  1.1.6.1  tls 	if (imx51_ipuv3_console.is_console) {
    730      1.1  bsh 		wsdisplay_cnattach(&descr->c, ri, 0, 0, defattr);
    731      1.1  bsh 		aprint_normal_dev(sc->dev, "console\n");
    732      1.1  bsh 	}
    733      1.1  bsh 
    734  1.1.6.1  tls 	vcons_replay_msgbuf(&sc->console);
    735      1.1  bsh 
    736  1.1.6.1  tls 	imx51_ipuv3_start_dma(sc, scr);
    737      1.1  bsh #endif
    738      1.1  bsh 
    739  1.1.6.1  tls 	if (!pmf_device_register(sc->dev, imx51_ipuv3_suspend,
    740  1.1.6.1  tls 		imx51_ipuv3_resume)) {
    741  1.1.6.1  tls 		aprint_error_dev(sc->dev, "can't establish power hook\n");
    742  1.1.6.1  tls 	}
    743  1.1.6.1  tls 
    744      1.1  bsh 	return;
    745      1.1  bsh 
    746      1.1  bsh fail_retarn_dctmpl:
    747      1.1  bsh 	bus_space_unmap(sc->iot, sc->cpmem_ioh, IPU_CPMEM_SIZE);
    748      1.1  bsh fail_retarn_cpmem:
    749      1.1  bsh 	bus_space_unmap(sc->iot, sc->idmac_ioh, IPU_IDMAC_SIZE);
    750      1.1  bsh fail_retarn_idmac:
    751      1.1  bsh 	bus_space_unmap(sc->iot, sc->dc_ioh, IPU_DC_SIZE);
    752      1.1  bsh fail_retarn_dp:
    753      1.1  bsh 	bus_space_unmap(sc->iot, sc->dp_ioh, IPU_DP_SIZE);
    754      1.1  bsh fail_retarn_dc:
    755      1.1  bsh 	bus_space_unmap(sc->iot, sc->di0_ioh, IPU_DI0_SIZE);
    756      1.1  bsh fail_retarn_di0:
    757      1.1  bsh 	bus_space_unmap(sc->iot, sc->dmfc_ioh, IPU_DMFC_SIZE);
    758      1.1  bsh fail_retarn_dmfc:
    759      1.1  bsh 	bus_space_unmap(sc->iot, sc->dc_ioh, IPU_CM_SIZE);
    760      1.1  bsh fail_retarn_cm:
    761      1.1  bsh 	aprint_error_dev(sc->dev,
    762      1.1  bsh 	    "failed to map registers (errno=%d)\n", error);
    763      1.1  bsh 	return;
    764      1.1  bsh }
    765      1.1  bsh 
    766      1.1  bsh int
    767  1.1.6.1  tls imx51_ipuv3_cnattach(bool isconsole, struct imx51_wsscreen_descr *descr,
    768  1.1.6.1  tls     struct wsdisplay_accessops *accessops,
    769  1.1.6.1  tls     const struct lcd_panel_geometry *geom)
    770      1.1  bsh {
    771      1.1  bsh 	DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
    772  1.1.6.1  tls 	imx51_ipuv3_console.descr = descr;
    773  1.1.6.1  tls 	imx51_ipuv3_console.geom = geom;
    774  1.1.6.1  tls 	imx51_ipuv3_console.accessops = accessops;
    775  1.1.6.1  tls 	imx51_ipuv3_console.is_console = isconsole;
    776      1.1  bsh 	return 0;
    777      1.1  bsh }
    778      1.1  bsh 
    779      1.1  bsh #ifdef notyet
    780      1.1  bsh /*
    781      1.1  bsh  * Interrupt handler.
    782      1.1  bsh  */
    783      1.1  bsh int
    784      1.1  bsh ipuv3intr(void *arg)
    785      1.1  bsh {
    786      1.1  bsh 	DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
    787      1.1  bsh 
    788      1.1  bsh 	struct imx51_ipuv3_softc *sc = (struct imx51_ipuv3_softc *)arg;
    789      1.1  bsh 	bus_space_tag_t iot = sc->iot;
    790      1.1  bsh 	bus_space_handle_t ioh = sc->dc_ioh;
    791      1.1  bsh 	uint32_t status;
    792      1.1  bsh 
    793      1.1  bsh 	status = IPUV3_READ(ioh, V3CR);
    794      1.1  bsh 	/* Clear stickey status bits */
    795      1.1  bsh 	IPUV3_WRITE(ioh, V3CR, status);
    796      1.1  bsh 
    797      1.1  bsh 	return 1;
    798      1.1  bsh }
    799      1.1  bsh #endif
    800      1.1  bsh 
    801      1.1  bsh static void
    802      1.1  bsh imx51_ipuv3_write_dmaparam(struct imx51_ipuv3_softc *sc,
    803      1.1  bsh     int ch, uint32_t *value, int size)
    804      1.1  bsh {
    805      1.1  bsh 	DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
    806      1.1  bsh 
    807      1.1  bsh 	int i;
    808      1.1  bsh 	uint32_t addr = ch * 0x40;
    809      1.1  bsh 
    810      1.1  bsh 	for (i = 0; i < size; i++) {
    811      1.1  bsh 		IPUV3_WRITE(sc, cpmem, addr + ((i % 5) * 0x4) +
    812      1.1  bsh 		    ((i / 5) * 0x20), value[i]);
    813      1.1  bsh #ifdef IPUV3_DEBUG
    814      1.1  bsh 		printf("%s: addr = 0x%08X, val = 0x%08X\n", __func__,
    815      1.1  bsh 		    addr + ((i % 5) * 0x4) + ((i / 5) * 0x20),
    816      1.1  bsh 		    IPUV3_READ(sc, cpmem, addr + ((i % 5) * 0x4) +
    817      1.1  bsh 			((i / 5) * 0x20)));
    818      1.1  bsh #endif
    819      1.1  bsh 	}
    820      1.1  bsh }
    821      1.1  bsh 
    822      1.1  bsh static void
    823      1.1  bsh imx51_ipuv3_build_param(struct imx51_ipuv3_softc *sc,
    824      1.1  bsh     struct imx51_ipuv3_screen *scr,
    825      1.1  bsh     uint32_t *params)
    826      1.1  bsh {
    827      1.1  bsh 	const struct lcd_panel_geometry *geom = sc->geometry;
    828      1.1  bsh 
    829      1.1  bsh 	DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
    830      1.1  bsh 
    831      1.1  bsh 	imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_FW,
    832      1.1  bsh 	    (geom->panel_width - 1));
    833      1.1  bsh 	imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_FH,
    834      1.1  bsh 	    (geom->panel_height - 1));
    835      1.1  bsh 	imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_EBA0,
    836      1.1  bsh 	    scr->segs[0].ds_addr >> 3);
    837      1.1  bsh 	imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_EBA1,
    838      1.1  bsh 	    scr->segs[0].ds_addr >> 3);
    839      1.1  bsh 	imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_SL,
    840      1.1  bsh 	    (scr->stride - 1));
    841      1.1  bsh 
    842      1.1  bsh 	imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_PFS, 0x7);
    843      1.1  bsh 	imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_NPB, 32 - 1);
    844      1.1  bsh 
    845      1.1  bsh 	switch (scr->depth) {
    846      1.1  bsh 	case 32:
    847      1.1  bsh 		/* ARBG888 */
    848      1.1  bsh 		imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_BPP, 0x0);
    849      1.1  bsh 
    850      1.1  bsh 		imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_OFS0, 0);
    851      1.1  bsh 		imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_OFS1, 8);
    852      1.1  bsh 		imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_OFS2, 16);
    853      1.1  bsh 		imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_OFS3, 24);
    854      1.1  bsh 
    855      1.1  bsh 		imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_WID0, 8 - 1);
    856      1.1  bsh 		imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_WID1, 8 - 1);
    857      1.1  bsh 		imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_WID2, 8 - 1);
    858      1.1  bsh 		imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_WID3, 8 - 1);
    859      1.1  bsh 		break;
    860      1.1  bsh 	case 24:
    861      1.1  bsh 		/* RBG888 */
    862      1.1  bsh 		imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_BPP, 0x1);
    863      1.1  bsh 
    864      1.1  bsh 		imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_OFS0, 0);
    865      1.1  bsh 		imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_OFS1, 8);
    866      1.1  bsh 		imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_OFS2, 16);
    867      1.1  bsh 		imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_OFS3, 24);
    868      1.1  bsh 
    869      1.1  bsh 		imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_WID0, 8 - 1);
    870      1.1  bsh 		imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_WID1, 8 - 1);
    871      1.1  bsh 		imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_WID2, 8 - 1);
    872      1.1  bsh 		imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_WID3, 0);
    873      1.1  bsh 		break;
    874      1.1  bsh 	case 16:
    875      1.1  bsh 		/* RBG565 */
    876      1.1  bsh 		imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_BPP, 0x3);
    877      1.1  bsh 
    878      1.1  bsh 		imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_OFS0, 0);
    879      1.1  bsh 		imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_OFS1, 5);
    880      1.1  bsh 		imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_OFS2, 11);
    881      1.1  bsh 		imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_OFS3, 16);
    882      1.1  bsh 
    883      1.1  bsh 		imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_WID0, 5 - 1);
    884      1.1  bsh 		imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_WID1, 6 - 1);
    885      1.1  bsh 		imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_WID2, 5 - 1);
    886      1.1  bsh 		imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_WID3, 0);
    887      1.1  bsh 		break;
    888      1.1  bsh 	default:
    889      1.1  bsh 		panic("%s: unsupported depth %d\n", __func__, scr->depth);
    890      1.1  bsh 		break;
    891      1.1  bsh 	}
    892      1.1  bsh 
    893      1.1  bsh 	imx51_ipuv3_set_idma_param(params, IDMAC_Ch_PARAM_ID, 1);
    894      1.1  bsh }
    895      1.1  bsh 
    896      1.1  bsh static void
    897      1.1  bsh imx51_ipuv3_set_idma_param(uint32_t *params, uint32_t name, uint32_t val)
    898      1.1  bsh {
    899      1.1  bsh 	int word = (name >> 16) & 0xff;
    900      1.1  bsh 	int shift = (name >> 8) & 0xff;
    901      1.1  bsh 	int width = name & 0xff;
    902      1.1  bsh 	int index;
    903      1.1  bsh 
    904      1.1  bsh 	DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
    905      1.1  bsh 
    906      1.1  bsh 	index = word * 5;
    907      1.1  bsh 	index += shift / 32;
    908      1.1  bsh 	shift = shift % 32;
    909      1.1  bsh 
    910      1.1  bsh 	params[index] |= val << shift;
    911      1.1  bsh 	shift = 32 - shift;
    912      1.1  bsh 
    913      1.1  bsh 	if (width > shift)
    914      1.1  bsh 		params[index+1] |= val >> shift;
    915      1.1  bsh }
    916      1.1  bsh 
    917      1.1  bsh /*
    918      1.1  bsh  * Enable DMA to cause the display to be refreshed periodically.
    919      1.1  bsh  * This brings the screen to life...
    920      1.1  bsh  */
    921      1.1  bsh void
    922      1.1  bsh imx51_ipuv3_start_dma(struct imx51_ipuv3_softc *sc,
    923      1.1  bsh     struct imx51_ipuv3_screen *scr)
    924      1.1  bsh {
    925      1.1  bsh 	int save;
    926      1.1  bsh 	uint32_t params[10];
    927      1.1  bsh 	uint32_t reg;
    928      1.1  bsh 
    929      1.1  bsh 	DPRINTFN(3, ("%s: Pixel depth = %d\n", __func__, scr->depth));
    930      1.1  bsh 
    931      1.1  bsh 	reg = IPUV3_READ(sc, idmac, IPU_IDMAC_CH_EN_1);
    932      1.1  bsh 	reg &= ~__BIT(CH_PANNEL_BG);
    933      1.1  bsh 	IPUV3_WRITE(sc, idmac, IPU_IDMAC_CH_EN_1, reg);
    934      1.1  bsh 
    935      1.1  bsh 	memset(params, 0, sizeof(params));
    936      1.1  bsh 	imx51_ipuv3_build_param(sc, scr, params);
    937      1.1  bsh 
    938      1.1  bsh 	save = disable_interrupts(I32_bit);
    939      1.1  bsh 
    940      1.1  bsh 	/* IDMAC configuration */
    941      1.1  bsh 	imx51_ipuv3_write_dmaparam(sc, CH_PANNEL_BG, params,
    942      1.1  bsh 	    sizeof(params) / sizeof(params[0]));
    943      1.1  bsh 
    944      1.1  bsh 	IPUV3_WRITE(sc, idmac, IPU_IDMAC_CH_PRI_1, __BIT(CH_PANNEL_BG));
    945      1.1  bsh 
    946      1.1  bsh 	/* double buffer */
    947      1.1  bsh 	reg = IPUV3_READ(sc, cm, IPU_CM_CH_DB_MODE_SEL_0);
    948      1.1  bsh 	reg |= __BIT(CH_PANNEL_BG);
    949      1.1  bsh 	IPUV3_WRITE(sc, cm, IPU_CM_CH_DB_MODE_SEL_0, reg);
    950      1.1  bsh 
    951      1.1  bsh 	reg = IPUV3_READ(sc, idmac, IPU_IDMAC_CH_EN_1);
    952      1.1  bsh 	reg |= __BIT(CH_PANNEL_BG);
    953      1.1  bsh 	IPUV3_WRITE(sc, idmac, IPU_IDMAC_CH_EN_1, reg);
    954      1.1  bsh 
    955      1.1  bsh 	reg = IPUV3_READ(sc, cm, IPU_CM_GPR);
    956      1.1  bsh 	reg &= ~CM_GPR_IPU_CH_BUF0_RDY0_CLR;
    957      1.1  bsh 	IPUV3_WRITE(sc, cm, IPU_CM_GPR, reg);
    958      1.1  bsh 
    959      1.1  bsh 	IPUV3_WRITE(sc, cm, IPU_CM_CUR_BUF_0, __BIT(CH_PANNEL_BG));
    960      1.1  bsh 
    961      1.1  bsh 	restore_interrupts(save);
    962      1.1  bsh 
    963      1.1  bsh 	imx51_ipuv3_enable_display(sc);
    964      1.1  bsh 
    965      1.1  bsh #ifdef IPUV3_DEBUG
    966      1.1  bsh 	imx51_ipuv3_dump(sc);
    967      1.1  bsh #endif
    968      1.1  bsh }
    969      1.1  bsh 
    970      1.1  bsh /*
    971      1.1  bsh  * Disable screen refresh.
    972      1.1  bsh  */
    973      1.1  bsh static void
    974      1.1  bsh imx51_ipuv3_stop_dma(struct imx51_ipuv3_softc *sc)
    975      1.1  bsh {
    976      1.1  bsh 	DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
    977      1.1  bsh 
    978      1.1  bsh 	return;
    979      1.1  bsh }
    980      1.1  bsh 
    981      1.1  bsh /*
    982      1.1  bsh  * Create and initialize a new screen buffer.
    983      1.1  bsh  */
    984      1.1  bsh int
    985      1.1  bsh imx51_ipuv3_new_screen(struct imx51_ipuv3_softc *sc, int depth,
    986      1.1  bsh     struct imx51_ipuv3_screen **scrpp)
    987      1.1  bsh {
    988      1.1  bsh 	const struct lcd_panel_geometry *geometry;
    989      1.1  bsh 	struct imx51_ipuv3_screen *scr = NULL;
    990      1.1  bsh 	int width, height;
    991      1.1  bsh 	bus_size_t size;
    992      1.1  bsh 	int error;
    993      1.1  bsh 	int busdma_flag = (cold ? BUS_DMA_NOWAIT : BUS_DMA_WAITOK);
    994      1.1  bsh 
    995      1.1  bsh 	DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
    996      1.1  bsh 
    997      1.1  bsh 	geometry = sc->geometry;
    998      1.1  bsh 
    999      1.1  bsh 	width = geometry->panel_width;
   1000      1.1  bsh 	height = geometry->panel_height;
   1001      1.1  bsh 
   1002      1.1  bsh 	scr = malloc(sizeof(*scr), M_DEVBUF, M_NOWAIT);
   1003      1.1  bsh 	if (scr == NULL)
   1004      1.1  bsh 		return ENOMEM;
   1005      1.1  bsh 
   1006      1.1  bsh 	memset(scr, 0, sizeof(*scr));
   1007      1.1  bsh 
   1008      1.1  bsh 	scr->nsegs = 0;
   1009      1.1  bsh 	scr->depth = depth;
   1010      1.1  bsh 	scr->stride = width * depth / 8;
   1011      1.1  bsh 	scr->buf_size = size = scr->stride * height;
   1012      1.1  bsh 	scr->buf_va = NULL;
   1013      1.1  bsh 
   1014      1.1  bsh 	error = bus_dmamem_alloc(sc->dma_tag, size, 16, 0, scr->segs, 1,
   1015      1.1  bsh 	    &scr->nsegs, busdma_flag);
   1016      1.1  bsh 
   1017      1.1  bsh 	if (error || scr->nsegs != 1) {
   1018      1.1  bsh 		/* XXX:
   1019      1.1  bsh 		 * Actually we can handle nsegs>1 case by means
   1020      1.1  bsh 		 * of multiple DMA descriptors for a panel.  It
   1021      1.1  bsh 		 * will make code here a bit hairly.
   1022      1.1  bsh 		 */
   1023      1.1  bsh 		if (error == 0)
   1024      1.1  bsh 			error = E2BIG;
   1025      1.1  bsh 		goto bad;
   1026      1.1  bsh 	}
   1027      1.1  bsh 
   1028      1.1  bsh 	error = bus_dmamem_map(sc->dma_tag, scr->segs, scr->nsegs, size,
   1029      1.1  bsh 	    (void **)&scr->buf_va, busdma_flag | BUS_DMA_COHERENT);
   1030      1.1  bsh 	if (error)
   1031      1.1  bsh 		goto bad;
   1032      1.1  bsh 
   1033      1.1  bsh 	memset(scr->buf_va, 0, scr->buf_size);
   1034      1.1  bsh 
   1035      1.1  bsh 	/* map memory for DMA */
   1036      1.1  bsh 	error = bus_dmamap_create(sc->dma_tag, 1024*1024*2, 1, 1024*1024*2, 0,
   1037      1.1  bsh 	    busdma_flag, &scr->dma);
   1038      1.1  bsh 	if (error)
   1039      1.1  bsh 		goto bad;
   1040      1.1  bsh 
   1041      1.1  bsh 	error = bus_dmamap_load(sc->dma_tag, scr->dma, scr->buf_va, size,
   1042      1.1  bsh 	    NULL, busdma_flag);
   1043      1.1  bsh 	if (error)
   1044      1.1  bsh 		goto bad;
   1045      1.1  bsh 
   1046      1.1  bsh 	LIST_INSERT_HEAD(&sc->screens, scr, link);
   1047      1.1  bsh 	sc->n_screens++;
   1048      1.1  bsh 
   1049      1.1  bsh #ifdef IPUV3_DEBUG
   1050      1.1  bsh 	printf("%s: screen buffer width  %d\n", __func__, width);
   1051      1.1  bsh 	printf("%s: screen buffer height %d\n", __func__, height);
   1052      1.1  bsh 	printf("%s: screen buffer depth  %d\n", __func__, depth);
   1053      1.1  bsh 	printf("%s: screen buffer stride %d\n", __func__, scr->stride);
   1054      1.1  bsh 	printf("%s: screen buffer size   0x%08X\n", __func__,
   1055      1.1  bsh 	    (uint32_t)scr->buf_size);
   1056      1.1  bsh 	printf("%s: screen buffer addr virtual  %p\n", __func__, scr->buf_va);
   1057      1.1  bsh 	printf("%s: screen buffer addr physical %p\n", __func__,
   1058      1.1  bsh 	    (void *)scr->segs[0].ds_addr);
   1059      1.1  bsh #endif
   1060      1.1  bsh 
   1061      1.1  bsh 	scr->map_size = size;		/* used when unmap this. */
   1062      1.1  bsh 
   1063      1.1  bsh 	*scrpp = scr;
   1064      1.1  bsh 
   1065      1.1  bsh 	return 0;
   1066      1.1  bsh 
   1067      1.1  bsh bad:
   1068      1.1  bsh #ifdef IPUV3_DEBUG
   1069      1.1  bsh 	printf("%s: error = 0x%08X\n", __func__, error);
   1070      1.1  bsh #endif
   1071      1.1  bsh 	if (scr) {
   1072      1.1  bsh 		if (scr->buf_va)
   1073      1.1  bsh 			bus_dmamem_unmap(sc->dma_tag, scr->buf_va, size);
   1074      1.1  bsh 		if (scr->nsegs)
   1075      1.1  bsh 			bus_dmamem_free(sc->dma_tag, scr->segs, scr->nsegs);
   1076      1.1  bsh 		free(scr, M_DEVBUF);
   1077      1.1  bsh 	}
   1078      1.1  bsh 	*scrpp = NULL;
   1079      1.1  bsh 	return error;
   1080      1.1  bsh }
   1081      1.1  bsh 
   1082      1.1  bsh #if NWSDISPLAY > 0
   1083      1.1  bsh /*
   1084      1.1  bsh  * Initialize rasops for a screen, as well as struct wsscreen_descr if this
   1085      1.1  bsh  * is the first screen creation.
   1086      1.1  bsh  */
   1087      1.1  bsh static void
   1088      1.1  bsh imx51_ipuv3_setup_rasops(struct imx51_ipuv3_softc *sc, struct rasops_info *rinfo,
   1089      1.1  bsh     struct imx51_wsscreen_descr *descr,
   1090      1.1  bsh     const struct lcd_panel_geometry *geom)
   1091      1.1  bsh {
   1092      1.1  bsh 
   1093      1.1  bsh 	DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
   1094      1.1  bsh 
   1095      1.1  bsh 	rinfo->ri_flg = descr->flags;
   1096      1.1  bsh 	rinfo->ri_depth = descr->depth;
   1097      1.1  bsh 	rinfo->ri_width = geom->panel_width;
   1098      1.1  bsh 	rinfo->ri_height = geom->panel_height;
   1099      1.1  bsh 	rinfo->ri_stride = rinfo->ri_width * rinfo->ri_depth / 8;
   1100      1.1  bsh 
   1101      1.1  bsh 	/* swap B and R */
   1102      1.1  bsh 	if (descr->depth == 16) {
   1103      1.1  bsh 		rinfo->ri_rnum = 5;
   1104      1.1  bsh 		rinfo->ri_rpos = 11;
   1105      1.1  bsh 		rinfo->ri_gnum = 6;
   1106      1.1  bsh 		rinfo->ri_gpos = 5;
   1107      1.1  bsh 		rinfo->ri_bnum = 5;
   1108      1.1  bsh 		rinfo->ri_bpos = 0;
   1109      1.1  bsh 	}
   1110      1.1  bsh 
   1111      1.1  bsh 	if (descr->c.nrows == 0) {
   1112      1.1  bsh 		/* get rasops to compute screen size the first time */
   1113      1.1  bsh 		rasops_init(rinfo, 100, 100);
   1114      1.1  bsh 	} else {
   1115      1.1  bsh 		rasops_init(rinfo, descr->c.nrows, descr->c.ncols);
   1116      1.1  bsh 	}
   1117      1.1  bsh 
   1118      1.1  bsh 	descr->c.nrows = rinfo->ri_rows;
   1119      1.1  bsh 	descr->c.ncols = rinfo->ri_cols;
   1120      1.1  bsh 	descr->c.capabilities = rinfo->ri_caps;
   1121      1.1  bsh 	descr->c.textops = &rinfo->ri_ops;
   1122      1.1  bsh }
   1123      1.1  bsh #endif
   1124      1.1  bsh /*
   1125      1.1  bsh  * Power management
   1126      1.1  bsh  */
   1127  1.1.6.1  tls static bool
   1128  1.1.6.1  tls imx51_ipuv3_suspend(device_t dv, const pmf_qual_t *qual)
   1129      1.1  bsh {
   1130  1.1.6.1  tls 	struct imx51_ipuv3_softc *sc = device_private(dv);
   1131      1.1  bsh 	DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
   1132  1.1.6.1  tls 	if (sc->active)
   1133      1.1  bsh 		imx51_ipuv3_stop_dma(sc);
   1134  1.1.6.1  tls 	return true;
   1135      1.1  bsh }
   1136      1.1  bsh 
   1137  1.1.6.1  tls static bool
   1138  1.1.6.1  tls imx51_ipuv3_resume(device_t dv, const pmf_qual_t *qual)
   1139      1.1  bsh {
   1140  1.1.6.1  tls 	struct imx51_ipuv3_softc *sc = device_private(dv);
   1141      1.1  bsh 	DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
   1142      1.1  bsh 	if (sc->active) {
   1143      1.1  bsh 		imx51_ipuv3_initialize(sc, sc->geometry);
   1144      1.1  bsh 		imx51_ipuv3_start_dma(sc, sc->active);
   1145      1.1  bsh 	}
   1146  1.1.6.1  tls 	return true;
   1147  1.1.6.1  tls }
   1148  1.1.6.1  tls 
   1149  1.1.6.1  tls #if NWSDISPLAY > 0
   1150  1.1.6.1  tls int
   1151  1.1.6.1  tls imx51_ipuv3_show_screen(void *v, void *cookie, int waitok,
   1152  1.1.6.1  tls     void (*cb)(void *, int, int), void *cbarg)
   1153  1.1.6.1  tls {
   1154  1.1.6.1  tls 	struct vcons_data *vd = v;
   1155  1.1.6.1  tls 	struct imx51_ipuv3_softc *sc = vd->cookie;
   1156  1.1.6.1  tls 	struct imx51_ipuv3_screen *scr = cookie, *old;
   1157  1.1.6.1  tls 	DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
   1158  1.1.6.1  tls 
   1159  1.1.6.1  tls 	old = sc->active;
   1160  1.1.6.1  tls 	if (old == scr)
   1161  1.1.6.1  tls 		return 0;
   1162  1.1.6.1  tls 	if (old)
   1163  1.1.6.1  tls 		imx51_ipuv3_stop_dma(sc);
   1164  1.1.6.1  tls 	imx51_ipuv3_start_dma(sc, scr);
   1165  1.1.6.1  tls 	sc->active = scr;
   1166  1.1.6.1  tls 	return 0;
   1167  1.1.6.1  tls }
   1168  1.1.6.1  tls 
   1169  1.1.6.1  tls int
   1170  1.1.6.1  tls imx51_ipuv3_alloc_screen(void *v, const struct wsscreen_descr *_type,
   1171  1.1.6.1  tls     void **cookiep, int *curxp, int *curyp, long *attrp)
   1172  1.1.6.1  tls {
   1173  1.1.6.1  tls 	struct vcons_data *vd = v;
   1174  1.1.6.1  tls 	struct imx51_ipuv3_softc *sc = vd->cookie;
   1175  1.1.6.1  tls 	struct imx51_ipuv3_screen *scr;
   1176  1.1.6.1  tls 	const struct imx51_wsscreen_descr *type =
   1177  1.1.6.1  tls 		(const struct imx51_wsscreen_descr *)_type;
   1178  1.1.6.1  tls 	int error;
   1179  1.1.6.1  tls 	DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
   1180  1.1.6.1  tls 
   1181  1.1.6.1  tls 	error = imx51_ipuv3_new_screen(sc, type->depth, &scr);
   1182  1.1.6.1  tls 	if (error)
   1183  1.1.6.1  tls 		return error;
   1184  1.1.6.1  tls 
   1185  1.1.6.1  tls 	/*
   1186  1.1.6.1  tls 	 * initialize raster operation for this screen.
   1187  1.1.6.1  tls 	 */
   1188  1.1.6.1  tls 	scr->rinfo.ri_flg = 0;
   1189  1.1.6.1  tls 	scr->rinfo.ri_depth = type->depth;
   1190  1.1.6.1  tls 	scr->rinfo.ri_bits = scr->buf_va;
   1191  1.1.6.1  tls 	scr->rinfo.ri_width = sc->geometry->panel_width;
   1192  1.1.6.1  tls 	scr->rinfo.ri_height = sc->geometry->panel_height;
   1193  1.1.6.1  tls 	scr->rinfo.ri_stride = scr->rinfo.ri_width * scr->rinfo.ri_depth / 8;
   1194  1.1.6.1  tls #ifdef CPU_XSCALE_PXA270
   1195  1.1.6.1  tls 	if (scr->rinfo.ri_depth > 16)
   1196  1.1.6.1  tls 		scr->rinfo.ri_stride = scr->rinfo.ri_width * 4;
   1197  1.1.6.1  tls #endif
   1198  1.1.6.1  tls 	scr->rinfo.ri_wsfcookie = -1;	/* XXX */
   1199  1.1.6.1  tls 
   1200  1.1.6.1  tls 	rasops_init(&scr->rinfo, type->c.nrows, type->c.ncols);
   1201  1.1.6.1  tls 
   1202  1.1.6.1  tls 	(*scr->rinfo.ri_ops.allocattr)(&scr->rinfo, 0, 0, 0, attrp);
   1203  1.1.6.1  tls 
   1204  1.1.6.1  tls 	*cookiep = scr;
   1205  1.1.6.1  tls 	*curxp = 0;
   1206  1.1.6.1  tls 	*curyp = 0;
   1207  1.1.6.1  tls 
   1208  1.1.6.1  tls 	return 0;
   1209      1.1  bsh }
   1210      1.1  bsh 
   1211      1.1  bsh void
   1212  1.1.6.1  tls imx51_ipuv3_free_screen(void *v, void *cookie)
   1213      1.1  bsh {
   1214  1.1.6.1  tls 	struct vcons_data *vd = v;
   1215  1.1.6.1  tls 	struct imx51_ipuv3_softc *sc = vd->cookie;
   1216  1.1.6.1  tls 	struct imx51_ipuv3_screen *scr = cookie;
   1217      1.1  bsh 	DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
   1218      1.1  bsh 
   1219  1.1.6.1  tls 	LIST_REMOVE(scr, link);
   1220  1.1.6.1  tls 	sc->n_screens--;
   1221  1.1.6.1  tls 	if (scr == sc->active) {
   1222  1.1.6.1  tls 		/* at first, we need to stop LCD DMA */
   1223  1.1.6.1  tls 		sc->active = NULL;
   1224      1.1  bsh 
   1225  1.1.6.1  tls 		printf("lcd_free on active screen\n");
   1226      1.1  bsh 
   1227  1.1.6.1  tls 		imx51_ipuv3_stop_dma(sc);
   1228      1.1  bsh 	}
   1229  1.1.6.1  tls 
   1230  1.1.6.1  tls 	if (scr->buf_va)
   1231  1.1.6.1  tls 		bus_dmamem_unmap(sc->dma_tag, scr->buf_va, scr->map_size);
   1232  1.1.6.1  tls 	if (scr->nsegs > 0)
   1233  1.1.6.1  tls 		bus_dmamem_free(sc->dma_tag, scr->segs, scr->nsegs);
   1234  1.1.6.1  tls 	free(scr, M_DEVBUF);
   1235      1.1  bsh }
   1236      1.1  bsh 
   1237      1.1  bsh int
   1238      1.1  bsh imx51_ipuv3_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
   1239      1.1  bsh     struct lwp *l)
   1240      1.1  bsh {
   1241      1.1  bsh 	struct vcons_data *vd = v;
   1242      1.1  bsh 	struct imx51_ipuv3_softc *sc = vd->cookie;
   1243      1.1  bsh 	struct wsdisplay_fbinfo *wsdisp_info;
   1244      1.1  bsh 	struct vcons_screen *ms = vd->active;
   1245      1.1  bsh 
   1246  1.1.6.1  tls 	DPRINTFN(5, ("%s : cmd 0x%X (%d)\n", __func__, (u_int)cmd, (int)IOCGROUP(cmd)));
   1247  1.1.6.1  tls 
   1248      1.1  bsh 	switch (cmd) {
   1249      1.1  bsh 	case WSDISPLAYIO_GTYPE:
   1250      1.1  bsh 		*(int *)data = WSDISPLAY_TYPE_IMXIPU;
   1251      1.1  bsh 		return 0;
   1252      1.1  bsh 
   1253      1.1  bsh 	case WSDISPLAYIO_GINFO:
   1254      1.1  bsh 		wsdisp_info = (struct wsdisplay_fbinfo *)data;
   1255      1.1  bsh 		wsdisp_info->height = ms->scr_ri.ri_height;
   1256      1.1  bsh 		wsdisp_info->width = ms->scr_ri.ri_width;
   1257      1.1  bsh 		wsdisp_info->depth = ms->scr_ri.ri_depth;
   1258      1.1  bsh 		wsdisp_info->cmsize = 0;
   1259      1.1  bsh 		return 0;
   1260      1.1  bsh 
   1261      1.1  bsh 	case WSDISPLAYIO_LINEBYTES:
   1262      1.1  bsh 		*(u_int *)data = ms->scr_ri.ri_stride;
   1263      1.1  bsh 		return 0;
   1264      1.1  bsh 
   1265      1.1  bsh 	case WSDISPLAYIO_GETCMAP:
   1266      1.1  bsh 	case WSDISPLAYIO_PUTCMAP:
   1267      1.1  bsh 		return EPASSTHROUGH;	/* XXX Colormap */
   1268      1.1  bsh 
   1269      1.1  bsh 	case WSDISPLAYIO_SVIDEO:
   1270      1.1  bsh 		if (*(int *)data == WSDISPLAYIO_VIDEO_ON) {
   1271      1.1  bsh 			/* turn it on */
   1272      1.1  bsh 		}
   1273      1.1  bsh 		else {
   1274      1.1  bsh 			/* start IPUV3 shutdown */
   1275      1.1  bsh 			/* sleep until interrupt */
   1276      1.1  bsh 		}
   1277      1.1  bsh 		return 0;
   1278      1.1  bsh 
   1279      1.1  bsh 	case WSDISPLAYIO_GVIDEO:
   1280      1.1  bsh 		*(u_int *)data =  WSDISPLAYIO_VIDEO_ON;
   1281      1.1  bsh 		return 0;
   1282      1.1  bsh 
   1283      1.1  bsh 	case WSDISPLAYIO_GCURPOS:
   1284      1.1  bsh 	case WSDISPLAYIO_SCURPOS:
   1285      1.1  bsh 	case WSDISPLAYIO_GCURMAX:
   1286      1.1  bsh 	case WSDISPLAYIO_GCURSOR:
   1287      1.1  bsh 	case WSDISPLAYIO_SCURSOR:
   1288      1.1  bsh 		return EPASSTHROUGH;	/* XXX */
   1289      1.1  bsh 	case WSDISPLAYIO_SMODE:
   1290      1.1  bsh 		{
   1291      1.1  bsh 			int new_mode = *(int*)data;
   1292      1.1  bsh 
   1293      1.1  bsh 			/* notify the bus backend */
   1294      1.1  bsh 			if (new_mode != sc->mode) {
   1295      1.1  bsh 				sc->mode = new_mode;
   1296      1.1  bsh 				if(new_mode == WSDISPLAYIO_MODE_EMUL)
   1297      1.1  bsh 					vcons_redraw_screen(ms);
   1298      1.1  bsh 			}
   1299      1.1  bsh 		}
   1300      1.1  bsh 		return 0;
   1301      1.1  bsh 	}
   1302      1.1  bsh 
   1303      1.1  bsh 	return EPASSTHROUGH;
   1304      1.1  bsh }
   1305      1.1  bsh 
   1306      1.1  bsh paddr_t
   1307      1.1  bsh imx51_ipuv3_mmap(void *v, void *vs, off_t offset, int prot)
   1308      1.1  bsh {
   1309      1.1  bsh 	DPRINTFN(5, ("%s : %d\n", __func__, __LINE__));
   1310      1.1  bsh 
   1311      1.1  bsh 	struct vcons_data *vd = v;
   1312      1.1  bsh 	struct imx51_ipuv3_softc *sc = vd->cookie;
   1313      1.1  bsh 	struct imx51_ipuv3_screen *scr = sc->active;
   1314      1.1  bsh 
   1315      1.1  bsh 	return bus_dmamem_mmap(sc->dma_tag, scr->segs, scr->nsegs,
   1316      1.1  bsh 	    offset, prot,
   1317      1.1  bsh 	    BUS_DMA_WAITOK | BUS_DMA_COHERENT);
   1318      1.1  bsh }
   1319      1.1  bsh #endif /* NWSDISPLAY > 0 */
   1320      1.1  bsh 
   1321