Home | History | Annotate | Line # | Download | only in dev
mq200.c revision 1.36
      1  1.36    andvar /*	$NetBSD: mq200.c,v 1.36 2022/05/28 15:57:18 andvar Exp $	*/
      2   1.1  takemura 
      3   1.1  takemura /*-
      4  1.13  takemura  * Copyright (c) 2000, 2001 TAKEMURA Shin
      5   1.1  takemura  * All rights reserved.
      6   1.1  takemura  *
      7   1.1  takemura  * Redistribution and use in source and binary forms, with or without
      8   1.1  takemura  * modification, are permitted provided that the following conditions
      9   1.1  takemura  * are met:
     10   1.1  takemura  * 1. Redistributions of source code must retain the above copyright
     11   1.1  takemura  *    notice, this list of conditions and the following disclaimer.
     12   1.1  takemura  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1  takemura  *    notice, this list of conditions and the following disclaimer in the
     14   1.1  takemura  *    documentation and/or other materials provided with the distribution.
     15   1.1  takemura  * 3. The name of the author may not be used to endorse or promote products
     16   1.1  takemura  *    derived from this software without specific prior written permission.
     17   1.1  takemura  *
     18   1.1  takemura  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     19   1.1  takemura  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     20   1.1  takemura  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     21   1.1  takemura  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     22   1.1  takemura  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     23   1.1  takemura  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     24   1.1  takemura  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     25   1.1  takemura  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     26   1.1  takemura  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     27   1.1  takemura  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     28   1.1  takemura  * SUCH DAMAGE.
     29   1.1  takemura  *
     30   1.1  takemura  */
     31  1.22     lukem 
     32  1.22     lukem #include <sys/cdefs.h>
     33  1.36    andvar __KERNEL_RCSID(0, "$NetBSD: mq200.c,v 1.36 2022/05/28 15:57:18 andvar Exp $");
     34   1.1  takemura 
     35   1.1  takemura #include <sys/param.h>
     36  1.32      matt #include <sys/bus.h>
     37  1.32      matt #include <sys/device.h>
     38   1.1  takemura #include <sys/kernel.h>
     39   1.1  takemura #include <sys/systm.h>
     40   1.2      sato #include <sys/reboot.h>
     41   1.1  takemura 
     42   1.1  takemura #include <uvm/uvm_extern.h>
     43   1.1  takemura 
     44   1.1  takemura #include <dev/wscons/wsconsio.h>
     45   1.1  takemura 
     46  1.32      matt #include <mips/locore.h>
     47  1.32      matt 
     48   1.1  takemura #include <machine/bootinfo.h>
     49   1.1  takemura #include <machine/autoconf.h>
     50   1.1  takemura #include <machine/config_hook.h>
     51   1.1  takemura #include <machine/platid.h>
     52   1.1  takemura #include <machine/platid_mask.h>
     53   1.1  takemura 
     54  1.13  takemura #include "opt_mq200.h"
     55   1.1  takemura #include <hpcmips/dev/mq200reg.h>
     56   1.1  takemura #include <hpcmips/dev/mq200var.h>
     57  1.13  takemura #include <hpcmips/dev/mq200priv.h>
     58  1.13  takemura 
     59   1.2      sato #include "bivideo.h"
     60   1.2      sato #if NBIVIDEO > 0
     61  1.26     blymn #include <dev/hpc/bivideovar.h>
     62   1.2      sato #endif
     63   1.1  takemura 
     64   1.1  takemura /*
     65   1.1  takemura  * function prototypes
     66   1.1  takemura  */
     67  1.18       uch static void	mq200_power(int, void *);
     68  1.18       uch static int	mq200_hardpower(void *, int, long, void *);
     69  1.18       uch static int	mq200_fbinit(struct hpcfb_fbconf *);
     70  1.28  christos static int	mq200_ioctl(void *, u_long, void *, int, struct lwp *);
     71  1.18       uch static paddr_t	mq200_mmap(void *, off_t offset, int);
     72  1.18       uch static void	mq200_update_powerstate(struct mq200_softc *, int);
     73  1.18       uch void	mq200_init_backlight(struct mq200_softc *, int);
     74  1.18       uch void	mq200_init_brightness(struct mq200_softc *, int);
     75  1.18       uch void	mq200_init_contrast(struct mq200_softc *, int);
     76  1.18       uch void	mq200_set_brightness(struct mq200_softc *, int);
     77  1.18       uch void	mq200_set_contrast(struct mq200_softc *, int);
     78   1.1  takemura 
     79   1.1  takemura /*
     80   1.1  takemura  * static variables
     81   1.1  takemura  */
     82   1.1  takemura struct hpcfb_accessops mq200_ha = {
     83   1.1  takemura 	mq200_ioctl, mq200_mmap
     84   1.1  takemura };
     85   1.1  takemura 
     86  1.13  takemura #ifdef MQ200_DEBUG
     87  1.13  takemura int mq200_debug = MQ200DEBUG_CONF;
     88  1.13  takemura #endif
     89  1.13  takemura 
     90   1.1  takemura int
     91  1.18       uch mq200_probe(bus_space_tag_t iot, bus_space_handle_t ioh)
     92   1.1  takemura {
     93   1.1  takemura 	unsigned long regval;
     94   1.1  takemura 
     95   1.2      sato #if NBIVIDEO > 0
     96   1.2      sato 	if (bivideo_dont_attach) /* some video driver already attached */
     97   1.2      sato 		return (0);
     98   1.2      sato #endif /* NBIVIDEO > 0 */
     99   1.2      sato 
    100   1.1  takemura 	regval = bus_space_read_4(iot, ioh, MQ200_PC00R);
    101  1.13  takemura 	VPRINTF("probe: vendor id=%04lx product id=%04lx\n",
    102  1.18       uch 	    regval & 0xffff, (regval >> 16) & 0xffff);
    103   1.1  takemura 	if (regval != ((MQ200_PRODUCT_ID << 16) | MQ200_VENDOR_ID))
    104   1.1  takemura 		return (0);
    105   1.1  takemura 
    106   1.1  takemura 	return (1);
    107   1.1  takemura }
    108   1.1  takemura 
    109   1.1  takemura void
    110  1.18       uch mq200_attach(struct mq200_softc *sc)
    111   1.1  takemura {
    112   1.1  takemura 	unsigned long regval;
    113   1.1  takemura 	struct hpcfb_attach_args ha;
    114   1.1  takemura 	int console = (bootinfo->bi_cnuse & BI_CNUSE_SERIAL) ? 0 : 1;
    115   1.1  takemura 
    116   1.8      sato 	printf(": ");
    117   1.8      sato 	if (mq200_fbinit(&sc->sc_fbconf) != 0) {
    118   1.8      sato 		/* just return so that hpcfb will not be attached */
    119   1.8      sato 		return;
    120   1.8      sato 	}
    121   1.8      sato 
    122   1.8      sato 	sc->sc_fbconf.hf_baseaddr = (u_long)bootinfo->fb_addr;
    123   1.8      sato 	sc->sc_fbconf.hf_offset	= (u_long)sc->sc_fbconf.hf_baseaddr -
    124   1.8      sato 	    MIPS_PHYS_TO_KSEG1(mips_ptob(mips_btop(sc->sc_baseaddr)));
    125  1.13  takemura 	DPRINTF("hf_baseaddr=%lx\n", sc->sc_fbconf.hf_baseaddr);
    126  1.13  takemura 	DPRINTF("hf_offset=%lx\n", sc->sc_fbconf.hf_offset);
    127   1.8      sato 
    128  1.13  takemura 	regval = mq200_read(sc, MQ200_PC08R);
    129   1.8      sato 	printf("MQ200 Rev.%02lx video controller", regval & 0xff);
    130   1.8      sato 	if (console) {
    131   1.8      sato 		printf(", console");
    132   1.8      sato 	}
    133   1.8      sato 	printf("\n");
    134   1.8      sato         printf("%s: framebuffer address: 0x%08lx\n",
    135  1.31       chs 	    device_xname(sc->sc_dev), (u_long)bootinfo->fb_addr);
    136  1.13  takemura 
    137  1.13  takemura 	/*
    138  1.13  takemura 	 * setup registers
    139  1.13  takemura 	 */
    140  1.13  takemura 	sc->sc_flags = 0;
    141  1.13  takemura 	sc->sc_baseclock = 12288;	/* 12.288 MHz */
    142  1.13  takemura #ifdef MQ200_DEBUG
    143  1.13  takemura 	if (bootverbose) {
    144  1.13  takemura 		/* dump current setting	*/
    145  1.13  takemura 		mq200_dump_all(sc);
    146  1.13  takemura 		mq200_dump_pll(sc);
    147  1.13  takemura 	}
    148  1.13  takemura #endif
    149  1.13  takemura 	mq200_setup_regctx(sc);
    150  1.13  takemura 	mq200_mdsetup(sc);
    151  1.13  takemura 	if (sc->sc_md) {
    152  1.20  takemura 		int mode;
    153  1.20  takemura 
    154  1.20  takemura 		switch (sc->sc_fbconf.hf_pixel_width) {
    155  1.20  takemura 		case  1:	mode = MQ200_GCC_1BPP;		break;
    156  1.20  takemura 		case  2:	mode = MQ200_GCC_2BPP;		break;
    157  1.20  takemura 		case  4:	mode = MQ200_GCC_4BPP;		break;
    158  1.20  takemura 		case  8:	mode = MQ200_GCC_8BPP;		break;
    159  1.20  takemura 		case 16:	mode = MQ200_GCC_16BPP_DIRECT;	break;
    160  1.20  takemura 		default:
    161  1.20  takemura 			printf("%s: %dbpp isn't supported\n",
    162  1.31       chs 			    device_xname(sc->sc_dev), sc->sc_fbconf.hf_pixel_width);
    163  1.20  takemura 			return;
    164  1.20  takemura 		}
    165  1.20  takemura 
    166  1.13  takemura 		if (sc->sc_md->md_flags & MQ200_MD_HAVEFP) {
    167  1.13  takemura 			sc->sc_flags |= MQ200_SC_GC2_ENABLE;	/* FP	*/
    168  1.13  takemura 		}
    169  1.13  takemura #if MQ200_USECRT
    170  1.13  takemura 		if (sc->sc_md->md_flags & MQ200_MD_HAVECRT) {
    171  1.13  takemura 			int i;
    172  1.13  takemura 			sc->sc_flags |= MQ200_SC_GC1_ENABLE;	/* CRT	*/
    173  1.13  takemura 			for (i = 0; i < mq200_crt_nparams; i++) {
    174  1.13  takemura 				sc->sc_crt = &mq200_crt_params[i];
    175  1.13  takemura 				if (sc->sc_md->md_fp_width <=
    176  1.13  takemura 				    mq200_crt_params[i].width &&
    177  1.13  takemura 				    sc->sc_md->md_fp_height <=
    178  1.13  takemura 				    mq200_crt_params[i].height)
    179  1.13  takemura 					break;
    180  1.13  takemura 			}
    181  1.13  takemura 		}
    182  1.13  takemura #endif
    183  1.13  takemura 		mq200_setup(sc);
    184  1.13  takemura 
    185  1.13  takemura 		if (sc->sc_flags & MQ200_SC_GC2_ENABLE)	/* FP	*/
    186  1.20  takemura 			mq200_win_enable(sc, MQ200_GC2, mode,
    187  1.20  takemura 			    sc->sc_fbconf.hf_baseaddr,
    188  1.20  takemura 			    sc->sc_fbconf.hf_width, sc->sc_fbconf.hf_height,
    189  1.20  takemura 			    sc->sc_fbconf.hf_bytes_per_plane);
    190  1.13  takemura 		if (sc->sc_flags & MQ200_SC_GC1_ENABLE)	/* CRT	*/
    191  1.20  takemura 			mq200_win_enable(sc, MQ200_GC1, mode,
    192  1.20  takemura 			    sc->sc_fbconf.hf_baseaddr,
    193  1.20  takemura 			    sc->sc_fbconf.hf_width, sc->sc_fbconf.hf_height,
    194  1.20  takemura 			    sc->sc_fbconf.hf_bytes_per_plane);
    195  1.13  takemura 	}
    196  1.13  takemura #ifdef MQ200_DEBUG
    197  1.13  takemura 	if (sc->sc_md == NULL || bootverbose) {
    198  1.13  takemura 		mq200_dump_pll(sc);
    199  1.13  takemura 	}
    200  1.13  takemura #endif
    201  1.26     blymn 
    202   1.1  takemura 	/* Add a power hook to power saving */
    203  1.10      sato 	sc->sc_mq200pwstate = MQ200_POWERSTATE_D0;
    204  1.31       chs 	sc->sc_powerhook = powerhook_establish(device_xname(sc->sc_dev),
    205  1.27  jmcneill 	    mq200_power, sc);
    206   1.1  takemura 	if (sc->sc_powerhook == NULL)
    207   1.1  takemura 		printf("%s: WARNING: unable to establish power hook\n",
    208  1.31       chs 		    device_xname(sc->sc_dev));
    209   1.1  takemura 
    210   1.1  takemura 	/* Add a hard power hook to power saving */
    211   1.1  takemura 	sc->sc_hardpowerhook = config_hook(CONFIG_HOOK_PMEVENT,
    212  1.18       uch 	    CONFIG_HOOK_PMEVENT_HARDPOWER,
    213  1.18       uch 	    CONFIG_HOOK_SHARE,
    214  1.18       uch 	    mq200_hardpower, sc);
    215   1.1  takemura 	if (sc->sc_hardpowerhook == NULL)
    216   1.1  takemura 		printf("%s: WARNING: unable to establish hard power hook\n",
    217  1.31       chs 		    device_xname(sc->sc_dev));
    218   1.1  takemura 
    219  1.10      sato 	/* initialize backlight brightness and lcd contrast */
    220  1.14      sato 	sc->sc_lcd_inited = 0;
    221  1.14      sato 	mq200_init_brightness(sc, 1);
    222  1.14      sato 	mq200_init_contrast(sc, 1);
    223  1.14      sato 	mq200_init_backlight(sc, 1);
    224  1.10      sato 
    225   1.1  takemura 	if (console && hpcfb_cnattach(&sc->sc_fbconf) != 0) {
    226   1.1  takemura 		panic("mq200_attach: can't init fb console");
    227   1.1  takemura 	}
    228   1.1  takemura 
    229   1.1  takemura 	ha.ha_console = console;
    230   1.1  takemura 	ha.ha_accessops = &mq200_ha;
    231   1.1  takemura 	ha.ha_accessctx = sc;
    232   1.1  takemura 	ha.ha_curfbconf = 0;
    233   1.1  takemura 	ha.ha_nfbconf = 1;
    234   1.1  takemura 	ha.ha_fbconflist = &sc->sc_fbconf;
    235   1.1  takemura 	ha.ha_curdspconf = 0;
    236   1.1  takemura 	ha.ha_ndspconf = 1;
    237   1.1  takemura 	ha.ha_dspconflist = &sc->sc_dspconf;
    238   1.1  takemura 
    239  1.34   thorpej 	config_found(sc->sc_dev, &ha, hpcfbprint, CFARGS_NONE);
    240   1.1  takemura 
    241   1.2      sato #if NBIVIDEO > 0
    242   1.1  takemura 	/*
    243   1.1  takemura 	 * bivideo is no longer need
    244   1.1  takemura 	 */
    245   1.1  takemura 	bivideo_dont_attach = 1;
    246   1.2      sato #endif /* NBIVIDEO > 0 */
    247   1.1  takemura }
    248   1.1  takemura 
    249  1.10      sato static void
    250  1.18       uch mq200_update_powerstate(struct mq200_softc *sc, int updates)
    251  1.10      sato {
    252  1.12      sato 
    253  1.10      sato 	if (updates & PWRSTAT_LCD)
    254  1.10      sato 		config_hook_call(CONFIG_HOOK_POWERCONTROL,
    255  1.10      sato 		    CONFIG_HOOK_POWERCONTROL_LCD,
    256  1.26     blymn 		    (void*)!(sc->sc_powerstate &
    257  1.18       uch 			(PWRSTAT_VIDEOOFF|PWRSTAT_SUSPEND)));
    258  1.10      sato 
    259  1.10      sato 	if (updates & PWRSTAT_BACKLIGHT)
    260  1.10      sato 		config_hook_call(CONFIG_HOOK_POWERCONTROL,
    261  1.10      sato 		    CONFIG_HOOK_POWERCONTROL_LCDLIGHT,
    262  1.26     blymn 		    (void*)(!(sc->sc_powerstate &
    263  1.18       uch 			(PWRSTAT_VIDEOOFF|PWRSTAT_SUSPEND)) &&
    264  1.18       uch 			(sc->sc_powerstate & PWRSTAT_BACKLIGHT)));
    265  1.10      sato }
    266  1.10      sato 
    267  1.26     blymn static void
    268  1.18       uch mq200_power(int why, void *arg)
    269   1.1  takemura {
    270   1.1  takemura 	struct mq200_softc *sc = arg;
    271   1.1  takemura 
    272   1.1  takemura 	switch (why) {
    273   1.1  takemura 	case PWR_SUSPEND:
    274  1.10      sato 		sc->sc_powerstate |= PWRSTAT_SUSPEND;
    275  1.10      sato 		mq200_update_powerstate(sc, PWRSTAT_ALL);
    276   1.1  takemura 		break;
    277   1.1  takemura 	case PWR_STANDBY:
    278  1.10      sato 		sc->sc_powerstate |= PWRSTAT_SUSPEND;
    279  1.10      sato 		mq200_update_powerstate(sc, PWRSTAT_ALL);
    280   1.1  takemura 		break;
    281   1.1  takemura 	case PWR_RESUME:
    282  1.10      sato 		sc->sc_powerstate &= ~PWRSTAT_SUSPEND;
    283  1.10      sato 		mq200_update_powerstate(sc, PWRSTAT_ALL);
    284   1.1  takemura 		break;
    285   1.1  takemura 	}
    286   1.1  takemura }
    287   1.1  takemura 
    288   1.1  takemura static int
    289  1.18       uch mq200_hardpower(void *ctx, int type, long id, void *msg)
    290   1.1  takemura {
    291   1.1  takemura 	struct mq200_softc *sc = ctx;
    292   1.1  takemura 	int why = (int)msg;
    293   1.1  takemura 
    294   1.1  takemura 	switch (why) {
    295   1.1  takemura 	case PWR_SUSPEND:
    296  1.10      sato 		sc->sc_mq200pwstate = MQ200_POWERSTATE_D2;
    297   1.1  takemura 		break;
    298   1.1  takemura 	case PWR_STANDBY:
    299  1.10      sato 		sc->sc_mq200pwstate = MQ200_POWERSTATE_D3;
    300   1.1  takemura 		break;
    301   1.1  takemura 	case PWR_RESUME:
    302  1.10      sato 		sc->sc_mq200pwstate = MQ200_POWERSTATE_D0;
    303   1.1  takemura 		break;
    304   1.1  takemura 	}
    305   1.1  takemura 
    306   1.1  takemura 	bus_space_write_4(sc->sc_iot, sc->sc_ioh,
    307  1.18       uch 	    MQ200_PMCSR, sc->sc_mq200pwstate);
    308   1.1  takemura 
    309   1.1  takemura 	/*
    310   1.1  takemura 	 * you should wait until the
    311   1.1  takemura 	 * power state transit sequence will end.
    312   1.1  takemura 	 */
    313   1.1  takemura 	{
    314   1.1  takemura 		unsigned long tmp;
    315   1.1  takemura 		do {
    316   1.1  takemura 			tmp = bus_space_read_4(sc->sc_iot, sc->sc_ioh,
    317  1.18       uch 			    MQ200_PMCSR);
    318  1.10      sato 		} while ((tmp & 0x3) != (sc->sc_mq200pwstate & 0x3));
    319   1.1  takemura 		delay(100000); /* XXX */
    320   1.1  takemura 	}
    321   1.1  takemura 
    322   1.1  takemura 	return (0);
    323   1.1  takemura }
    324   1.1  takemura 
    325   1.1  takemura 
    326   1.1  takemura static int
    327  1.18       uch mq200_fbinit(struct hpcfb_fbconf *fb)
    328   1.1  takemura {
    329   1.1  takemura 
    330   1.1  takemura 	/*
    331   1.1  takemura 	 * get fb settings from bootinfo
    332   1.1  takemura 	 */
    333   1.1  takemura 	if (bootinfo == NULL ||
    334   1.1  takemura 	    bootinfo->fb_addr == 0 ||
    335   1.1  takemura 	    bootinfo->fb_line_bytes == 0 ||
    336   1.1  takemura 	    bootinfo->fb_width == 0 ||
    337   1.1  takemura 	    bootinfo->fb_height == 0) {
    338  1.16    toshii 		printf("no frame buffer information.\n");
    339   1.1  takemura 		return (-1);
    340   1.1  takemura 	}
    341   1.1  takemura 
    342   1.1  takemura 	/* zero fill */
    343  1.30    cegger 	memset(fb, 0, sizeof(*fb));
    344   1.1  takemura 
    345   1.1  takemura 	fb->hf_conf_index	= 0;	/* configuration index		*/
    346   1.1  takemura 	fb->hf_nconfs		= 1;   	/* how many configurations	*/
    347   1.1  takemura 	strcpy(fb->hf_name, "built-in video");
    348   1.1  takemura 					/* frame buffer name		*/
    349   1.1  takemura 	strcpy(fb->hf_conf_name, "default");
    350   1.1  takemura 					/* configuration name		*/
    351   1.1  takemura 	fb->hf_height		= bootinfo->fb_height;
    352   1.1  takemura 	fb->hf_width		= bootinfo->fb_width;
    353   1.1  takemura 	fb->hf_baseaddr		= mips_ptob(mips_btop(bootinfo->fb_addr));
    354   1.1  takemura 	fb->hf_offset		= (u_long)bootinfo->fb_addr - fb->hf_baseaddr;
    355   1.1  takemura 					/* frame buffer start offset   	*/
    356   1.1  takemura 	fb->hf_bytes_per_line	= bootinfo->fb_line_bytes;
    357   1.1  takemura 	fb->hf_nplanes		= 1;
    358   1.1  takemura 	fb->hf_bytes_per_plane	= bootinfo->fb_height *
    359  1.18       uch 	    bootinfo->fb_line_bytes;
    360   1.1  takemura 
    361   1.1  takemura 	fb->hf_access_flags |= HPCFB_ACCESS_BYTE;
    362   1.1  takemura 	fb->hf_access_flags |= HPCFB_ACCESS_WORD;
    363   1.1  takemura 	fb->hf_access_flags |= HPCFB_ACCESS_DWORD;
    364   1.1  takemura 
    365   1.1  takemura 	switch (bootinfo->fb_type) {
    366  1.20  takemura 		/*
    367  1.20  takemura 		 * monochrome
    368  1.20  takemura 		 */
    369  1.20  takemura 	case BIFB_D1_M2L_1:
    370  1.20  takemura 		fb->hf_access_flags |= HPCFB_ACCESS_REVERSE;
    371  1.20  takemura 		/* fall through */
    372  1.20  takemura 	case BIFB_D1_M2L_0:
    373  1.20  takemura 		fb->hf_class = HPCFB_CLASS_GRAYSCALE;
    374  1.20  takemura 		fb->hf_access_flags |= HPCFB_ACCESS_STATIC;
    375  1.20  takemura 		fb->hf_pack_width = 8;
    376  1.20  takemura 		fb->hf_pixels_per_pack = 8;
    377  1.20  takemura 		fb->hf_pixel_width = 1;
    378  1.20  takemura 		fb->hf_class_data_length = sizeof(struct hf_gray_tag);
    379  1.20  takemura 		fb->hf_u.hf_gray.hf_flags = 0;	/* reserved for future use */
    380  1.20  takemura 		break;
    381  1.20  takemura 
    382   1.1  takemura 		/*
    383   1.1  takemura 		 * gray scale
    384   1.1  takemura 		 */
    385   1.1  takemura 	case BIFB_D2_M2L_3:
    386   1.1  takemura 	case BIFB_D2_M2L_3x2:
    387   1.1  takemura 		fb->hf_access_flags |= HPCFB_ACCESS_REVERSE;
    388   1.1  takemura 		/* fall through */
    389   1.1  takemura 	case BIFB_D2_M2L_0:
    390   1.1  takemura 	case BIFB_D2_M2L_0x2:
    391   1.1  takemura 		fb->hf_class = HPCFB_CLASS_GRAYSCALE;
    392   1.1  takemura 		fb->hf_access_flags |= HPCFB_ACCESS_STATIC;
    393   1.1  takemura 		fb->hf_pack_width = 8;
    394   1.1  takemura 		fb->hf_pixels_per_pack = 4;
    395   1.1  takemura 		fb->hf_pixel_width = 2;
    396   1.7  takemura 		fb->hf_class_data_length = sizeof(struct hf_gray_tag);
    397   1.7  takemura 		fb->hf_u.hf_gray.hf_flags = 0;	/* reserved for future use */
    398   1.7  takemura 		break;
    399   1.7  takemura 
    400   1.7  takemura 	case BIFB_D4_M2L_F:
    401   1.7  takemura 	case BIFB_D4_M2L_Fx2:
    402   1.7  takemura 		fb->hf_access_flags |= HPCFB_ACCESS_REVERSE;
    403   1.7  takemura 		/* fall through */
    404   1.7  takemura 	case BIFB_D4_M2L_0:
    405   1.7  takemura 	case BIFB_D4_M2L_0x2:
    406   1.7  takemura 		fb->hf_class = HPCFB_CLASS_GRAYSCALE;
    407   1.7  takemura 		fb->hf_access_flags |= HPCFB_ACCESS_STATIC;
    408   1.7  takemura 		fb->hf_pack_width = 8;
    409   1.7  takemura 		fb->hf_pixels_per_pack = 2;
    410   1.7  takemura 		fb->hf_pixel_width = 4;
    411   1.1  takemura 		fb->hf_class_data_length = sizeof(struct hf_gray_tag);
    412   1.1  takemura 		fb->hf_u.hf_gray.hf_flags = 0;	/* reserved for future use */
    413   1.1  takemura 		break;
    414   1.1  takemura 
    415   1.1  takemura 		/*
    416   1.1  takemura 		 * indexed color
    417   1.1  takemura 		 */
    418   1.1  takemura 	case BIFB_D8_FF:
    419   1.1  takemura 		fb->hf_access_flags |= HPCFB_ACCESS_REVERSE;
    420   1.1  takemura 		/* fall through */
    421   1.1  takemura 	case BIFB_D8_00:
    422   1.1  takemura 		fb->hf_class = HPCFB_CLASS_INDEXCOLOR;
    423   1.1  takemura 		fb->hf_access_flags |= HPCFB_ACCESS_STATIC;
    424   1.1  takemura 		fb->hf_pack_width = 8;
    425   1.1  takemura 		fb->hf_pixels_per_pack = 1;
    426   1.1  takemura 		fb->hf_pixel_width = 8;
    427   1.1  takemura 		fb->hf_class_data_length = sizeof(struct hf_indexed_tag);
    428   1.1  takemura 		fb->hf_u.hf_indexed.hf_flags = 0; /* reserved for future use */
    429   1.1  takemura 		break;
    430   1.1  takemura 
    431   1.1  takemura 		/*
    432   1.1  takemura 		 * RGB color
    433   1.1  takemura 		 */
    434   1.1  takemura 	case BIFB_D16_FFFF:
    435   1.1  takemura 		fb->hf_access_flags |= HPCFB_ACCESS_REVERSE;
    436   1.1  takemura 		/* fall through */
    437   1.1  takemura 	case BIFB_D16_0000:
    438   1.1  takemura 		fb->hf_class = HPCFB_CLASS_RGBCOLOR;
    439   1.1  takemura 		fb->hf_access_flags |= HPCFB_ACCESS_STATIC;
    440  1.17  takemura 		fb->hf_order_flags = HPCFB_REVORDER_BYTE;
    441   1.1  takemura 		fb->hf_pack_width = 16;
    442   1.1  takemura 		fb->hf_pixels_per_pack = 1;
    443   1.1  takemura 		fb->hf_pixel_width = 16;
    444   1.1  takemura 
    445   1.1  takemura 		fb->hf_class_data_length = sizeof(struct hf_rgb_tag);
    446   1.1  takemura 		fb->hf_u.hf_rgb.hf_flags = 0;	/* reserved for future use */
    447   1.1  takemura 
    448   1.1  takemura 		fb->hf_u.hf_rgb.hf_red_width = 5;
    449   1.1  takemura 		fb->hf_u.hf_rgb.hf_red_shift = 11;
    450   1.1  takemura 		fb->hf_u.hf_rgb.hf_green_width = 6;
    451   1.1  takemura 		fb->hf_u.hf_rgb.hf_green_shift = 5;
    452   1.1  takemura 		fb->hf_u.hf_rgb.hf_blue_width = 5;
    453   1.1  takemura 		fb->hf_u.hf_rgb.hf_blue_shift = 0;
    454   1.1  takemura 		fb->hf_u.hf_rgb.hf_alpha_width = 0;
    455   1.1  takemura 		fb->hf_u.hf_rgb.hf_alpha_shift = 0;
    456   1.1  takemura 		break;
    457   1.1  takemura 
    458   1.1  takemura 	default:
    459   1.1  takemura 		printf("unknown type (=%d).\n", bootinfo->fb_type);
    460   1.1  takemura 		return (-1);
    461   1.1  takemura 		break;
    462   1.1  takemura 	}
    463   1.1  takemura 
    464   1.1  takemura 	return (0); /* no error */
    465   1.1  takemura }
    466   1.1  takemura 
    467   1.1  takemura int
    468  1.29       dsl mq200_ioctl(void *v, u_long cmd, void *data, int flag, struct lwp *l)
    469   1.1  takemura {
    470   1.1  takemura 	struct mq200_softc *sc = (struct mq200_softc *)v;
    471   1.1  takemura 	struct hpcfb_fbconf *fbconf;
    472   1.1  takemura 	struct hpcfb_dspconf *dspconf;
    473   1.1  takemura 	struct wsdisplay_cmap *cmap;
    474   1.6      sato 	struct wsdisplay_param *dispparam;
    475   1.1  takemura 
    476   1.1  takemura 	switch (cmd) {
    477   1.1  takemura 	case WSDISPLAYIO_GETCMAP:
    478  1.23       chs 		cmap = (struct wsdisplay_cmap *)data;
    479   1.1  takemura 
    480   1.1  takemura 		if (sc->sc_fbconf.hf_class != HPCFB_CLASS_INDEXCOLOR ||
    481   1.1  takemura 		    sc->sc_fbconf.hf_pack_width != 8 ||
    482   1.1  takemura 		    256 <= cmap->index ||
    483  1.21    itojun 		    256 - cmap->index < cmap->count)
    484   1.1  takemura 			return (EINVAL);
    485   1.1  takemura 
    486  1.23       chs 		/*
    487  1.23       chs 		 * This driver can't get color map.
    488  1.23       chs 		 */
    489  1.23       chs 		return (EINVAL);
    490   1.1  takemura 
    491   1.1  takemura 	case WSDISPLAYIO_PUTCMAP:
    492   1.1  takemura 		/*
    493   1.1  takemura 		 * This driver can't set color map.
    494   1.1  takemura 		 */
    495   1.1  takemura 		return (EINVAL);
    496  1.26     blymn 
    497  1.11      sato 	case WSDISPLAYIO_SVIDEO:
    498  1.11      sato 		if (*(int *)data == WSDISPLAYIO_VIDEO_OFF)
    499  1.11      sato 			sc->sc_powerstate |= PWRSTAT_VIDEOOFF;
    500  1.11      sato 		else
    501  1.11      sato 			sc->sc_powerstate &= ~PWRSTAT_VIDEOOFF;
    502  1.11      sato 		mq200_update_powerstate(sc, PWRSTAT_ALL);
    503  1.11      sato 		return 0;
    504  1.11      sato 
    505  1.11      sato 	case WSDISPLAYIO_GVIDEO:
    506  1.26     blymn 		*(int *)data = (sc->sc_powerstate&PWRSTAT_VIDEOOFF) ?
    507  1.18       uch 		    WSDISPLAYIO_VIDEO_OFF:WSDISPLAYIO_VIDEO_ON;
    508  1.11      sato 		return 0;
    509   1.6      sato 
    510   1.6      sato 	case WSDISPLAYIO_GETPARAM:
    511   1.6      sato 		dispparam = (struct wsdisplay_param*)data;
    512   1.6      sato 		switch (dispparam->param) {
    513   1.6      sato 		case WSDISPLAYIO_PARAM_BACKLIGHT:
    514  1.14      sato 			VPRINTF("ioctl: GET:BACKLIGHT\n");
    515  1.14      sato 			mq200_init_brightness(sc, 0);
    516  1.14      sato 			mq200_init_backlight(sc, 0);
    517  1.14      sato 			VPRINTF("ioctl: GET:(real)BACKLIGHT %d\n",
    518  1.18       uch 			    (sc->sc_powerstate&PWRSTAT_BACKLIGHT)? 1: 0);
    519  1.10      sato 			dispparam->min = 0;
    520  1.10      sato 			dispparam->max = 1;
    521  1.10      sato 			if (sc->sc_max_brightness > 0)
    522  1.18       uch 				dispparam->curval = sc->sc_brightness > 0
    523  1.18       uch 				    ? 1: 0;
    524  1.10      sato 			else
    525  1.10      sato 				dispparam->curval =
    526  1.18       uch 				    (sc->sc_powerstate&PWRSTAT_BACKLIGHT)
    527  1.18       uch 				    ? 1: 0;
    528  1.14      sato 			VPRINTF("ioctl: GET:BACKLIGHT:%d(%s)\n",
    529  1.18       uch 			    dispparam->curval,
    530  1.18       uch 			    sc->sc_max_brightness > 0? "brightness": "light");
    531  1.10      sato 			return 0;
    532  1.10      sato 			break;
    533   1.6      sato 		case WSDISPLAYIO_PARAM_CONTRAST:
    534  1.14      sato 			VPRINTF("ioctl: GET:CONTRAST\n");
    535  1.14      sato 			mq200_init_contrast(sc, 0);
    536  1.10      sato 			if (sc->sc_max_contrast > 0) {
    537  1.10      sato 				dispparam->min = 0;
    538  1.10      sato 				dispparam->max = sc->sc_max_contrast;
    539  1.10      sato 				dispparam->curval = sc->sc_contrast;
    540  1.18       uch 				VPRINTF("ioctl: GET:CONTRAST"
    541  1.18       uch 				    " max=%d, current=%d\n",
    542  1.18       uch 				    sc->sc_max_contrast, sc->sc_contrast);
    543  1.10      sato 				return 0;
    544  1.10      sato 			} else {
    545  1.14      sato 				VPRINTF("ioctl: GET:CONTRAST EINVAL\n");
    546  1.10      sato 				return (EINVAL);
    547  1.10      sato 			}
    548  1.26     blymn 			break;
    549   1.6      sato 		case WSDISPLAYIO_PARAM_BRIGHTNESS:
    550  1.14      sato 			VPRINTF("ioctl: GET:BRIGHTNESS\n");
    551  1.14      sato 			mq200_init_brightness(sc, 0);
    552  1.10      sato 			if (sc->sc_max_brightness > 0) {
    553  1.10      sato 				dispparam->min = 0;
    554  1.10      sato 				dispparam->max = sc->sc_max_brightness;
    555  1.10      sato 				dispparam->curval = sc->sc_brightness;
    556  1.18       uch 				VPRINTF("ioctl: GET:BRIGHTNESS"
    557  1.18       uch 				    " max=%d, current=%d\n",
    558  1.18       uch 				    sc->sc_max_brightness, sc->sc_brightness);
    559  1.10      sato 				return 0;
    560  1.10      sato 			} else {
    561  1.14      sato 				VPRINTF("ioctl: GET:BRIGHTNESS EINVAL\n");
    562  1.10      sato 				return (EINVAL);
    563  1.10      sato 			}
    564   1.6      sato 			return (EINVAL);
    565   1.6      sato 		default:
    566   1.6      sato 			return (EINVAL);
    567   1.6      sato 		}
    568   1.6      sato 		return (0);
    569   1.6      sato 
    570   1.6      sato 	case WSDISPLAYIO_SETPARAM:
    571   1.6      sato 		dispparam = (struct wsdisplay_param*)data;
    572   1.6      sato 		switch (dispparam->param) {
    573   1.6      sato 		case WSDISPLAYIO_PARAM_BACKLIGHT:
    574  1.14      sato 			VPRINTF("ioctl: SET:BACKLIGHT\n");
    575  1.10      sato 			if (dispparam->curval < 0 ||
    576  1.10      sato 			    1 < dispparam->curval)
    577  1.10      sato 				return (EINVAL);
    578  1.14      sato 			mq200_init_brightness(sc, 0);
    579  1.18       uch 			VPRINTF("ioctl: SET:max brightness=%d\n",
    580  1.18       uch 			    sc->sc_max_brightness);
    581  1.10      sato 			if (sc->sc_max_brightness > 0) { /* dimmer */
    582  1.10      sato 				if (dispparam->curval == 0){
    583  1.18       uch 					sc->sc_brightness_save =
    584  1.18       uch 					    sc->sc_brightness;
    585  1.18       uch 					mq200_set_brightness(sc, 0); /* min */
    586  1.10      sato 				} else {
    587  1.10      sato 					if (sc->sc_brightness_save == 0)
    588  1.18       uch 						sc->sc_brightness_save =
    589  1.18       uch 						    sc->sc_max_brightness;
    590  1.18       uch 					mq200_set_brightness(sc,
    591  1.18       uch 					    sc->sc_brightness_save);
    592  1.10      sato 				}
    593  1.18       uch 				VPRINTF("ioctl: SET:BACKLIGHT:"
    594  1.18       uch 				    " brightness=%d\n", sc->sc_brightness);
    595  1.10      sato 			} else { /* off */
    596  1.10      sato 				if (dispparam->curval == 0)
    597  1.10      sato 					sc->sc_powerstate &= ~PWRSTAT_BACKLIGHT;
    598  1.10      sato 				else
    599  1.10      sato 					sc->sc_powerstate |= PWRSTAT_BACKLIGHT;
    600  1.18       uch 				VPRINTF("ioctl: SET:BACKLIGHT:"
    601  1.18       uch 				    " powerstate %d\n",
    602  1.18       uch 				    (sc->sc_powerstate & PWRSTAT_BACKLIGHT)
    603  1.18       uch 				    ? 1 : 0);
    604  1.10      sato 				mq200_update_powerstate(sc, PWRSTAT_BACKLIGHT);
    605  1.14      sato 				VPRINTF("ioctl: SET:BACKLIGHT:%d\n",
    606  1.18       uch 				    (sc->sc_powerstate & PWRSTAT_BACKLIGHT)
    607  1.18       uch 				    ? 1 : 0);
    608  1.10      sato 			}
    609  1.10      sato 			return 0;
    610  1.10      sato 			break;
    611   1.6      sato 		case WSDISPLAYIO_PARAM_CONTRAST:
    612  1.14      sato 			VPRINTF("ioctl: SET:CONTRAST\n");
    613  1.14      sato 			mq200_init_contrast(sc, 0);
    614  1.10      sato 			if (dispparam->curval < 0 ||
    615  1.10      sato 			    sc->sc_max_contrast < dispparam->curval)
    616  1.10      sato 				return (EINVAL);
    617  1.10      sato 			if (sc->sc_max_contrast > 0) {
    618  1.10      sato 				int org = sc->sc_contrast;
    619  1.18       uch 				mq200_set_contrast(sc, dispparam->curval);
    620  1.18       uch 				VPRINTF("ioctl: SET:CONTRAST"
    621  1.18       uch 				    " org=%d, current=%d\n", org,
    622  1.18       uch 				    sc->sc_contrast);
    623  1.18       uch 				VPRINTF("ioctl: SETPARAM:"
    624  1.18       uch 				    " CONTRAST org=%d, current=%d\n", org,
    625  1.18       uch 				    sc->sc_contrast);
    626  1.10      sato 				return 0;
    627  1.10      sato 			} else {
    628  1.14      sato 				VPRINTF("ioctl: SET:CONTRAST EINVAL\n");
    629  1.10      sato 				return (EINVAL);
    630  1.10      sato 			}
    631  1.10      sato 			break;
    632   1.6      sato 		case WSDISPLAYIO_PARAM_BRIGHTNESS:
    633  1.14      sato 			VPRINTF("ioctl: SET:BRIGHTNESS\n");
    634  1.14      sato 			mq200_init_brightness(sc, 0);
    635  1.10      sato 			if (dispparam->curval < 0 ||
    636  1.10      sato 			    sc->sc_max_brightness < dispparam->curval)
    637  1.10      sato 				return (EINVAL);
    638  1.10      sato 			if (sc->sc_max_brightness > 0) {
    639  1.10      sato 				int org = sc->sc_brightness;
    640  1.18       uch 				mq200_set_brightness(sc, dispparam->curval);
    641  1.18       uch 				VPRINTF("ioctl: SET:BRIGHTNESS"
    642  1.18       uch 				    " org=%d, current=%d\n", org,
    643  1.18       uch 				    sc->sc_brightness);
    644  1.10      sato 				return 0;
    645  1.10      sato 			} else {
    646  1.14      sato 				VPRINTF("ioctl: SET:BRIGHTNESS EINVAL\n");
    647  1.10      sato 				return (EINVAL);
    648  1.10      sato 			}
    649  1.10      sato 			break;
    650   1.6      sato 		default:
    651   1.6      sato 			return (EINVAL);
    652   1.6      sato 		}
    653   1.6      sato 		return (0);
    654   1.1  takemura 
    655   1.1  takemura 	case HPCFBIO_GCONF:
    656   1.1  takemura 		fbconf = (struct hpcfb_fbconf *)data;
    657   1.1  takemura 		if (fbconf->hf_conf_index != 0 &&
    658   1.1  takemura 		    fbconf->hf_conf_index != HPCFB_CURRENT_CONFIG) {
    659   1.1  takemura 			return (EINVAL);
    660   1.1  takemura 		}
    661   1.1  takemura 		*fbconf = sc->sc_fbconf;	/* structure assignment */
    662   1.1  takemura 		return (0);
    663   1.1  takemura 	case HPCFBIO_SCONF:
    664   1.1  takemura 		fbconf = (struct hpcfb_fbconf *)data;
    665   1.1  takemura 		if (fbconf->hf_conf_index != 0 &&
    666   1.1  takemura 		    fbconf->hf_conf_index != HPCFB_CURRENT_CONFIG) {
    667   1.1  takemura 			return (EINVAL);
    668   1.1  takemura 		}
    669   1.1  takemura 		/*
    670  1.24       abs 		 * nothing to do because we have only one configuration
    671   1.1  takemura 		 */
    672   1.1  takemura 		return (0);
    673   1.1  takemura 	case HPCFBIO_GDSPCONF:
    674   1.1  takemura 		dspconf = (struct hpcfb_dspconf *)data;
    675   1.1  takemura 		if ((dspconf->hd_unit_index != 0 &&
    676  1.18       uch 		    dspconf->hd_unit_index != HPCFB_CURRENT_UNIT) ||
    677   1.1  takemura 		    (dspconf->hd_conf_index != 0 &&
    678  1.18       uch 			dspconf->hd_conf_index != HPCFB_CURRENT_CONFIG)) {
    679   1.1  takemura 			return (EINVAL);
    680   1.1  takemura 		}
    681   1.1  takemura 		*dspconf = sc->sc_dspconf;	/* structure assignment */
    682   1.1  takemura 		return (0);
    683   1.1  takemura 	case HPCFBIO_SDSPCONF:
    684   1.1  takemura 		dspconf = (struct hpcfb_dspconf *)data;
    685   1.1  takemura 		if ((dspconf->hd_unit_index != 0 &&
    686  1.18       uch 		    dspconf->hd_unit_index != HPCFB_CURRENT_UNIT) ||
    687   1.1  takemura 		    (dspconf->hd_conf_index != 0 &&
    688  1.18       uch 			dspconf->hd_conf_index != HPCFB_CURRENT_CONFIG)) {
    689   1.1  takemura 			return (EINVAL);
    690   1.1  takemura 		}
    691   1.1  takemura 		/*
    692   1.1  takemura 		 * nothing to do
    693  1.24       abs 		 * because we have only one unit and one configuration
    694   1.1  takemura 		 */
    695   1.1  takemura 		return (0);
    696   1.1  takemura 	case HPCFBIO_GOP:
    697   1.1  takemura 	case HPCFBIO_SOP:
    698   1.1  takemura 		/*
    699  1.36    andvar 		 * currently not implemented...
    700   1.1  takemura 		 */
    701   1.1  takemura 		return (EINVAL);
    702   1.1  takemura 	}
    703   1.1  takemura 
    704  1.19    atatat 	return (EPASSTHROUGH);
    705   1.1  takemura }
    706   1.1  takemura 
    707   1.1  takemura paddr_t
    708  1.18       uch mq200_mmap(void *ctx, off_t offset, int prot)
    709   1.1  takemura {
    710   1.1  takemura 	struct mq200_softc *sc = (struct mq200_softc *)ctx;
    711   1.1  takemura 
    712   1.3  takemura 	if (offset < 0 || MQ200_MAPSIZE <= offset)
    713   1.1  takemura 		return -1;
    714   1.1  takemura 
    715   1.3  takemura 	return mips_btop(sc->sc_baseaddr + offset);
    716  1.10      sato }
    717  1.10      sato 
    718  1.10      sato 
    719  1.10      sato void
    720  1.18       uch mq200_init_backlight(struct mq200_softc *sc, int inattach)
    721  1.10      sato {
    722  1.10      sato 	int val = -1;
    723  1.10      sato 
    724  1.14      sato 	if (sc->sc_lcd_inited&BACKLIGHT_INITED)
    725  1.14      sato 		return;
    726  1.14      sato 
    727  1.26     blymn 	if (config_hook_call(CONFIG_HOOK_GET,
    728  1.18       uch 	    CONFIG_HOOK_POWER_LCDLIGHT, &val) != -1) {
    729  1.14      sato 		/* we can get real light state */
    730  1.14      sato 		VPRINTF("init_backlight: real backlight=%d\n", val);
    731  1.12      sato 		if (val == 0)
    732  1.12      sato 			sc->sc_powerstate &= ~PWRSTAT_BACKLIGHT;
    733  1.12      sato 		else
    734  1.12      sato 			sc->sc_powerstate |= PWRSTAT_BACKLIGHT;
    735  1.14      sato 		sc->sc_lcd_inited |= BACKLIGHT_INITED;
    736  1.14      sato 	} else if (inattach) {
    737  1.26     blymn 		/*
    738  1.14      sato 		   we cannot get real light state in attach time
    739  1.14      sato 		   because light device not yet attached.
    740  1.14      sato 		   we will retry in !inattach.
    741  1.14      sato 		   temporary assume light is on.
    742  1.18       uch 		*/
    743  1.12      sato 		sc->sc_powerstate |= PWRSTAT_BACKLIGHT;
    744  1.14      sato 	} else {
    745  1.14      sato 		/* we cannot get real light state, so work by myself state */
    746  1.14      sato 		sc->sc_lcd_inited |= BACKLIGHT_INITED;
    747  1.14      sato 	}
    748  1.10      sato }
    749  1.10      sato 
    750  1.10      sato void
    751  1.18       uch mq200_init_brightness(struct mq200_softc *sc, int inattach)
    752  1.10      sato {
    753  1.10      sato 	int val = -1;
    754  1.10      sato 
    755  1.14      sato 	if (sc->sc_lcd_inited&BRIGHTNESS_INITED)
    756  1.14      sato 		return;
    757  1.14      sato 
    758  1.13  takemura 	VPRINTF("init_brightness\n");
    759  1.26     blymn 	if (config_hook_call(CONFIG_HOOK_GET,
    760  1.18       uch 	    CONFIG_HOOK_BRIGHTNESS_MAX, &val) != -1) {
    761  1.14      sato 		/* we can get real brightness max */
    762  1.14      sato 		VPRINTF("init_brightness: real brightness max=%d\n", val);
    763  1.10      sato 		sc->sc_max_brightness = val;
    764  1.14      sato 		val = -1;
    765  1.26     blymn 		if (config_hook_call(CONFIG_HOOK_GET,
    766  1.18       uch 		    CONFIG_HOOK_BRIGHTNESS, &val) != -1) {
    767  1.14      sato 			/* we can get real brightness */
    768  1.14      sato 			VPRINTF("init_brightness: real brightness=%d\n", val);
    769  1.14      sato 			sc->sc_brightness_save = sc->sc_brightness = val;
    770  1.14      sato 		} else {
    771  1.14      sato 			sc->sc_brightness_save =
    772  1.18       uch 			    sc->sc_brightness = sc->sc_max_brightness;
    773  1.14      sato 		}
    774  1.14      sato 		sc->sc_lcd_inited |= BRIGHTNESS_INITED;
    775  1.14      sato 	} else if (inattach) {
    776  1.26     blymn 		/*
    777  1.14      sato 		   we cannot get real brightness in attach time
    778  1.14      sato 		   because brightness device not yet attached.
    779  1.14      sato 		   we will retry in !inattach.
    780  1.18       uch 		*/
    781  1.14      sato 		sc->sc_max_brightness = -1;
    782  1.14      sato 		sc->sc_brightness = -1;
    783  1.14      sato 		sc->sc_brightness_save = -1;
    784  1.14      sato 	} else {
    785  1.14      sato 		/* we cannot get real brightness */
    786  1.14      sato 		sc->sc_lcd_inited |= BRIGHTNESS_INITED;
    787  1.10      sato 	}
    788  1.14      sato 
    789  1.10      sato 	return;
    790  1.10      sato }
    791  1.10      sato 
    792  1.10      sato 
    793  1.10      sato void
    794  1.18       uch mq200_init_contrast(struct mq200_softc *sc, int inattach)
    795  1.10      sato {
    796  1.10      sato 	int val = -1;
    797  1.10      sato 
    798  1.14      sato 	if (sc->sc_lcd_inited&CONTRAST_INITED)
    799  1.14      sato 		return;
    800  1.14      sato 
    801  1.13  takemura 	VPRINTF("init_contrast\n");
    802  1.26     blymn 	if (config_hook_call(CONFIG_HOOK_GET,
    803  1.18       uch 	    CONFIG_HOOK_CONTRAST_MAX, &val) != -1) {
    804  1.14      sato 		/* we can get real contrast max */
    805  1.14      sato 		VPRINTF("init_contrast: real contrast max=%d\n", val);
    806  1.10      sato 		sc->sc_max_contrast = val;
    807  1.14      sato 		val = -1;
    808  1.26     blymn 		if (config_hook_call(CONFIG_HOOK_GET,
    809  1.18       uch 		    CONFIG_HOOK_CONTRAST, &val) != -1) {
    810  1.14      sato 			/* we can get real contrast */
    811  1.14      sato 			VPRINTF("init_contrast: real contrast=%d\n", val);
    812  1.14      sato 			sc->sc_contrast = val;
    813  1.14      sato 		} else {
    814  1.14      sato 			sc->sc_contrast = sc->sc_max_contrast;
    815  1.14      sato 		}
    816  1.14      sato 		sc->sc_lcd_inited |= CONTRAST_INITED;
    817  1.14      sato 	} else if (inattach) {
    818  1.26     blymn 		/*
    819  1.14      sato 		   we cannot get real contrast in attach time
    820  1.14      sato 		   because contrast device not yet attached.
    821  1.14      sato 		   we will retry in !inattach.
    822  1.18       uch 		*/
    823  1.14      sato 		sc->sc_max_contrast = -1;
    824  1.14      sato 		sc->sc_contrast = -1;
    825  1.14      sato 	} else {
    826  1.14      sato 		/* we cannot get real contrast */
    827  1.14      sato 		sc->sc_lcd_inited |= CONTRAST_INITED;
    828  1.10      sato 	}
    829  1.14      sato 
    830  1.10      sato 	return;
    831  1.10      sato }
    832  1.14      sato 
    833  1.10      sato 
    834  1.10      sato void
    835  1.18       uch mq200_set_brightness(struct mq200_softc *sc, int val)
    836  1.10      sato {
    837  1.10      sato 	sc->sc_brightness = val;
    838  1.10      sato 
    839  1.10      sato 	config_hook_call(CONFIG_HOOK_SET, CONFIG_HOOK_BRIGHTNESS, &val);
    840  1.26     blymn 	if (config_hook_call(CONFIG_HOOK_GET,
    841  1.18       uch 	    CONFIG_HOOK_BRIGHTNESS, &val) != -1) {
    842  1.10      sato 		sc->sc_brightness = val;
    843  1.10      sato 	}
    844  1.10      sato }
    845  1.10      sato 
    846  1.10      sato void
    847  1.18       uch mq200_set_contrast(struct mq200_softc *sc, int val)
    848  1.10      sato {
    849  1.10      sato 	sc->sc_contrast = val;
    850  1.10      sato 
    851  1.10      sato 	config_hook_call(CONFIG_HOOK_SET, CONFIG_HOOK_CONTRAST, &val);
    852  1.26     blymn 	if (config_hook_call(CONFIG_HOOK_GET,
    853  1.18       uch 	    CONFIG_HOOK_CONTRAST, &val) != -1) {
    854  1.10      sato 		sc->sc_contrast = val;
    855  1.10      sato 	}
    856   1.1  takemura }
    857