Home | History | Annotate | Line # | Download | only in dev
octeon_asx.c revision 1.3
      1 /*	$NetBSD: octeon_asx.c,v 1.3 2020/06/22 02:26:19 simonb Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2007 Internet Initiative Japan, Inc.
      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 REGENTS AND CONTRIBUTORS ``AS IS'' AND
     17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  * SUCH DAMAGE.
     27  */
     28 
     29 #include <sys/cdefs.h>
     30 __KERNEL_RCSID(0, "$NetBSD: octeon_asx.c,v 1.3 2020/06/22 02:26:19 simonb Exp $");
     31 
     32 #include "opt_octeon.h"
     33 
     34 #include <sys/param.h>
     35 #include <sys/systm.h>
     36 #include <sys/malloc.h>
     37 #include <mips/cavium/octeonvar.h>
     38 #include <mips/cavium/dev/octeon_asxreg.h>
     39 #include <mips/cavium/dev/octeon_asxvar.h>
     40 
     41 /* XXX */
     42 void
     43 octasx_init(struct octasx_attach_args *aa, struct octasx_softc **rsc)
     44 {
     45 	struct octasx_softc *sc;
     46 	int status;
     47 
     48 	sc = malloc(sizeof(*sc), M_DEVBUF, M_WAITOK | M_ZERO);
     49 	if (sc == NULL)
     50 		panic("can't allocate memory: %s", __func__);
     51 
     52 	sc->sc_port = aa->aa_port;
     53 	sc->sc_regt = aa->aa_regt;
     54 
     55 	status = bus_space_map(sc->sc_regt, ASX0_BASE, ASX0_SIZE, 0,
     56 	    &sc->sc_regh);
     57 	if (status != 0)
     58 		panic("can't map %s space", "asx register");
     59 
     60 	*rsc = sc;
     61 }
     62 
     63 #define	_ASX_RD8(sc, off) \
     64 	bus_space_read_8((sc)->sc_regt, (sc)->sc_regh, (off))
     65 #define	_ASX_WR8(sc, off, v) \
     66 	bus_space_write_8((sc)->sc_regt, (sc)->sc_regh, (off), (v))
     67 
     68 static int	octasx_enable_tx(struct octasx_softc *, int);
     69 static int	octasx_enable_rx(struct octasx_softc *, int);
     70 
     71 int
     72 octasx_enable(struct octasx_softc *sc, int enable)
     73 {
     74 
     75 	octasx_enable_tx(sc, enable);
     76 	octasx_enable_rx(sc, enable);
     77 	return 0;
     78 }
     79 
     80 static int
     81 octasx_enable_tx(struct octasx_softc *sc, int enable)
     82 {
     83 	uint64_t asx_tx_port;
     84 
     85 	asx_tx_port = _ASX_RD8(sc, ASX0_TX_PRT_EN_OFFSET);
     86 	if (enable)
     87 		SET(asx_tx_port, 1 << sc->sc_port);
     88 	else
     89 		CLR(asx_tx_port, 1 << sc->sc_port);
     90 	_ASX_WR8(sc, ASX0_TX_PRT_EN_OFFSET, asx_tx_port);
     91 	return 0;
     92 }
     93 
     94 static int
     95 octasx_enable_rx(struct octasx_softc *sc, int enable)
     96 {
     97 	uint64_t asx_rx_port;
     98 
     99 	asx_rx_port = _ASX_RD8(sc, ASX0_RX_PRT_EN_OFFSET);
    100 	if (enable)
    101 		SET(asx_rx_port, 1 << sc->sc_port);
    102 	else
    103 		CLR(asx_rx_port, 1 << sc->sc_port);
    104 	_ASX_WR8(sc, ASX0_RX_PRT_EN_OFFSET, asx_rx_port);
    105 	return 0;
    106 }
    107 
    108 int
    109 octasx_clk_set(struct octasx_softc *sc, int tx_setting, int rx_setting)
    110 {
    111 	_ASX_WR8(sc, ASX0_TX_CLK_SET0_OFFSET + 8 * sc->sc_port, tx_setting);
    112 	_ASX_WR8(sc, ASX0_RX_CLK_SET0_OFFSET + 8 * sc->sc_port, rx_setting);
    113 	return 0;
    114 }
    115