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