Home | History | Annotate | Line # | Download | only in usb
auvitek_board.c revision 1.1
      1  1.1  jmcneill /* $NetBSD: auvitek_board.c,v 1.1 2010/12/27 15:42:11 jmcneill Exp $ */
      2  1.1  jmcneill 
      3  1.1  jmcneill /*-
      4  1.1  jmcneill  * Copyright (c) 2010 Jared D. McNeill <jmcneill (at) invisible.ca>
      5  1.1  jmcneill  * All rights reserved.
      6  1.1  jmcneill  *
      7  1.1  jmcneill  * Redistribution and use in source and binary forms, with or without
      8  1.1  jmcneill  * modification, are permitted provided that the following conditions
      9  1.1  jmcneill  * are met:
     10  1.1  jmcneill  * 1. Redistributions of source code must retain the above copyright
     11  1.1  jmcneill  *    notice, this list of conditions and the following disclaimer.
     12  1.1  jmcneill  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  jmcneill  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  jmcneill  *    documentation and/or other materials provided with the distribution.
     15  1.1  jmcneill  *
     16  1.1  jmcneill  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     17  1.1  jmcneill  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18  1.1  jmcneill  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19  1.1  jmcneill  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     20  1.1  jmcneill  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21  1.1  jmcneill  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22  1.1  jmcneill  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23  1.1  jmcneill  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24  1.1  jmcneill  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25  1.1  jmcneill  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26  1.1  jmcneill  * POSSIBILITY OF SUCH DAMAGE.
     27  1.1  jmcneill  */
     28  1.1  jmcneill 
     29  1.1  jmcneill /*
     30  1.1  jmcneill  * Auvitek AU0828 USB controller - board specific initialization
     31  1.1  jmcneill  */
     32  1.1  jmcneill 
     33  1.1  jmcneill #include <sys/cdefs.h>
     34  1.1  jmcneill __KERNEL_RCSID(0, "$NetBSD: auvitek_board.c,v 1.1 2010/12/27 15:42:11 jmcneill Exp $");
     35  1.1  jmcneill 
     36  1.1  jmcneill #include <sys/param.h>
     37  1.1  jmcneill #include <sys/systm.h>
     38  1.1  jmcneill #include <sys/device.h>
     39  1.1  jmcneill #include <sys/conf.h>
     40  1.1  jmcneill #include <sys/bus.h>
     41  1.1  jmcneill #include <sys/module.h>
     42  1.1  jmcneill 
     43  1.1  jmcneill #include <dev/usb/usb.h>
     44  1.1  jmcneill #include <dev/usb/usbdi.h>
     45  1.1  jmcneill #include <dev/usb/usbdi_util.h>
     46  1.1  jmcneill #include <dev/usb/usbdevs.h>
     47  1.1  jmcneill 
     48  1.1  jmcneill #include <dev/usb/auvitekreg.h>
     49  1.1  jmcneill #include <dev/usb/auvitekvar.h>
     50  1.1  jmcneill 
     51  1.1  jmcneill static const struct auvitek_board_config {
     52  1.1  jmcneill 	uint16_t	reset;
     53  1.1  jmcneill 	uint16_t	enable;
     54  1.1  jmcneill 	uint8_t		clkdiv;
     55  1.1  jmcneill } auvitek_board_config[] = {
     56  1.1  jmcneill 	[AUVITEK_BOARD_HVR_950Q] = {
     57  1.1  jmcneill 		.reset = 0x02b0,
     58  1.1  jmcneill 		.enable = 0x02f0,
     59  1.1  jmcneill 		.clkdiv = AU0828_I2C_CLKDIV_30,
     60  1.1  jmcneill 	},
     61  1.1  jmcneill };
     62  1.1  jmcneill 
     63  1.1  jmcneill void
     64  1.1  jmcneill auvitek_board_init(struct auvitek_softc *sc)
     65  1.1  jmcneill {
     66  1.1  jmcneill 	uint16_t reset, enable;
     67  1.1  jmcneill 
     68  1.1  jmcneill 	/* power up device */
     69  1.1  jmcneill 	auvitek_write_1(sc, AU0828_REG_POWER_CTL, AU0828_POWER_EN);
     70  1.1  jmcneill 
     71  1.1  jmcneill 	reset = auvitek_board_config[sc->sc_board].reset;
     72  1.1  jmcneill 	enable = auvitek_board_config[sc->sc_board].enable;
     73  1.1  jmcneill 
     74  1.1  jmcneill 	/* stash i2c clock divider in softc */
     75  1.1  jmcneill 	sc->sc_i2c_clkdiv = auvitek_board_config[sc->sc_board].clkdiv;
     76  1.1  jmcneill 
     77  1.1  jmcneill 	/* configure gpio, if requested */
     78  1.1  jmcneill 	if (reset) {
     79  1.1  jmcneill 		auvitek_write_1(sc, AU0828_REG_GPIO2_PINDIR, reset >> 8);
     80  1.1  jmcneill 		auvitek_write_1(sc, AU0828_REG_GPIO1_PINDIR, reset & 0xff);
     81  1.1  jmcneill 		auvitek_write_1(sc, AU0828_REG_GPIO2_OUTEN, 0);
     82  1.1  jmcneill 		auvitek_write_1(sc, AU0828_REG_GPIO1_OUTEN, 0);
     83  1.1  jmcneill 		delay(100000);
     84  1.1  jmcneill 	}
     85  1.1  jmcneill 	if (enable) {
     86  1.1  jmcneill 		auvitek_write_1(sc, AU0828_REG_GPIO2_PINDIR, enable >> 8);
     87  1.1  jmcneill 		auvitek_write_1(sc, AU0828_REG_GPIO1_PINDIR, enable & 0xff);
     88  1.1  jmcneill 		auvitek_write_1(sc, AU0828_REG_GPIO2_OUTEN, enable >> 8);
     89  1.1  jmcneill 		auvitek_write_1(sc, AU0828_REG_GPIO1_OUTEN, enable & 0xff);
     90  1.1  jmcneill 		delay(250000);
     91  1.1  jmcneill 	}
     92  1.1  jmcneill }
     93  1.1  jmcneill 
     94  1.1  jmcneill int
     95  1.1  jmcneill auvitek_board_tuner_reset(struct auvitek_softc *sc)
     96  1.1  jmcneill {
     97  1.1  jmcneill 	uint8_t val;
     98  1.1  jmcneill 
     99  1.1  jmcneill 	switch (sc->sc_board) {
    100  1.1  jmcneill 	case AUVITEK_BOARD_HVR_950Q:
    101  1.1  jmcneill 		val = auvitek_read_1(sc, AU0828_REG_GPIO2_OUTEN);
    102  1.1  jmcneill 		val &= ~2;
    103  1.1  jmcneill 		auvitek_write_1(sc, AU0828_REG_GPIO2_OUTEN, val);
    104  1.1  jmcneill 		delay(10000);
    105  1.1  jmcneill 		val = auvitek_read_1(sc, AU0828_REG_GPIO2_OUTEN);
    106  1.1  jmcneill 		val |= 2;
    107  1.1  jmcneill 		auvitek_write_1(sc, AU0828_REG_GPIO2_OUTEN, val);
    108  1.1  jmcneill 		delay(10000);
    109  1.1  jmcneill 		break;
    110  1.1  jmcneill 	}
    111  1.1  jmcneill 
    112  1.1  jmcneill 	return 0;
    113  1.1  jmcneill }
    114