Home | History | Annotate | Line # | Download | only in usb
      1  1.3  jmcneill /* $NetBSD: auvitek_board.c,v 1.3 2011/07/09 15:00:44 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.3  jmcneill __KERNEL_RCSID(0, "$NetBSD: auvitek_board.c,v 1.3 2011/07/09 15:00:44 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.2  jmcneill 	[AUVITEK_BOARD_HVR_850] = {
     57  1.2  jmcneill 		.reset = 0x02b0,
     58  1.2  jmcneill 		.enable = 0x02f0,
     59  1.2  jmcneill 		.clkdiv = AU0828_I2C_CLKDIV_30,
     60  1.2  jmcneill 	},
     61  1.1  jmcneill 	[AUVITEK_BOARD_HVR_950Q] = {
     62  1.1  jmcneill 		.reset = 0x02b0,
     63  1.1  jmcneill 		.enable = 0x02f0,
     64  1.1  jmcneill 		.clkdiv = AU0828_I2C_CLKDIV_30,
     65  1.1  jmcneill 	},
     66  1.1  jmcneill };
     67  1.1  jmcneill 
     68  1.1  jmcneill void
     69  1.1  jmcneill auvitek_board_init(struct auvitek_softc *sc)
     70  1.1  jmcneill {
     71  1.1  jmcneill 	uint16_t reset, enable;
     72  1.1  jmcneill 
     73  1.1  jmcneill 	/* power up device */
     74  1.1  jmcneill 	auvitek_write_1(sc, AU0828_REG_POWER_CTL, AU0828_POWER_EN);
     75  1.1  jmcneill 
     76  1.1  jmcneill 	reset = auvitek_board_config[sc->sc_board].reset;
     77  1.1  jmcneill 	enable = auvitek_board_config[sc->sc_board].enable;
     78  1.1  jmcneill 
     79  1.1  jmcneill 	/* stash i2c clock divider in softc */
     80  1.1  jmcneill 	sc->sc_i2c_clkdiv = auvitek_board_config[sc->sc_board].clkdiv;
     81  1.1  jmcneill 
     82  1.1  jmcneill 	/* configure gpio, if requested */
     83  1.1  jmcneill 	if (reset) {
     84  1.1  jmcneill 		auvitek_write_1(sc, AU0828_REG_GPIO2_PINDIR, reset >> 8);
     85  1.1  jmcneill 		auvitek_write_1(sc, AU0828_REG_GPIO1_PINDIR, reset & 0xff);
     86  1.1  jmcneill 		auvitek_write_1(sc, AU0828_REG_GPIO2_OUTEN, 0);
     87  1.1  jmcneill 		auvitek_write_1(sc, AU0828_REG_GPIO1_OUTEN, 0);
     88  1.1  jmcneill 		delay(100000);
     89  1.1  jmcneill 	}
     90  1.1  jmcneill 	if (enable) {
     91  1.1  jmcneill 		auvitek_write_1(sc, AU0828_REG_GPIO2_PINDIR, enable >> 8);
     92  1.1  jmcneill 		auvitek_write_1(sc, AU0828_REG_GPIO1_PINDIR, enable & 0xff);
     93  1.1  jmcneill 		auvitek_write_1(sc, AU0828_REG_GPIO2_OUTEN, enable >> 8);
     94  1.1  jmcneill 		auvitek_write_1(sc, AU0828_REG_GPIO1_OUTEN, enable & 0xff);
     95  1.1  jmcneill 		delay(250000);
     96  1.1  jmcneill 	}
     97  1.1  jmcneill }
     98  1.1  jmcneill 
     99  1.1  jmcneill int
    100  1.3  jmcneill auvitek_board_tuner_reset(void *priv)
    101  1.1  jmcneill {
    102  1.3  jmcneill 	struct auvitek_softc *sc = priv;
    103  1.1  jmcneill 	uint8_t val;
    104  1.1  jmcneill 
    105  1.1  jmcneill 	switch (sc->sc_board) {
    106  1.2  jmcneill 	case AUVITEK_BOARD_HVR_850:
    107  1.1  jmcneill 	case AUVITEK_BOARD_HVR_950Q:
    108  1.1  jmcneill 		val = auvitek_read_1(sc, AU0828_REG_GPIO2_OUTEN);
    109  1.1  jmcneill 		val &= ~2;
    110  1.1  jmcneill 		auvitek_write_1(sc, AU0828_REG_GPIO2_OUTEN, val);
    111  1.1  jmcneill 		delay(10000);
    112  1.1  jmcneill 		val = auvitek_read_1(sc, AU0828_REG_GPIO2_OUTEN);
    113  1.1  jmcneill 		val |= 2;
    114  1.1  jmcneill 		auvitek_write_1(sc, AU0828_REG_GPIO2_OUTEN, val);
    115  1.1  jmcneill 		delay(10000);
    116  1.1  jmcneill 		break;
    117  1.1  jmcneill 	}
    118  1.1  jmcneill 
    119  1.1  jmcneill 	return 0;
    120  1.1  jmcneill }
    121  1.3  jmcneill 
    122  1.3  jmcneill unsigned int
    123  1.3  jmcneill auvitek_board_get_if_frequency(struct auvitek_softc *sc)
    124  1.3  jmcneill {
    125  1.3  jmcneill 	return 6000000;	/* 6MHz */
    126  1.3  jmcneill }
    127