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