Home | History | Annotate | Line # | Download | only in imx
imx23_clkctrl.c revision 1.1.4.2
      1  1.1.4.2  rmind /* $Id: imx23_clkctrl.c,v 1.1.4.2 2014/05/18 17:44:58 rmind Exp $ */
      2  1.1.4.2  rmind 
      3  1.1.4.2  rmind /*
      4  1.1.4.2  rmind * Copyright (c) 2013 The NetBSD Foundation, Inc.
      5  1.1.4.2  rmind * All rights reserved.
      6  1.1.4.2  rmind *
      7  1.1.4.2  rmind * This code is derived from software contributed to The NetBSD Foundation
      8  1.1.4.2  rmind * by Petri Laakso.
      9  1.1.4.2  rmind *
     10  1.1.4.2  rmind * Redistribution and use in source and binary forms, with or without
     11  1.1.4.2  rmind * modification, are permitted provided that the following conditions
     12  1.1.4.2  rmind * are met:
     13  1.1.4.2  rmind * 1. Redistributions of source code must retain the above copyright
     14  1.1.4.2  rmind *    notice, this list of conditions and the following disclaimer.
     15  1.1.4.2  rmind * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1.4.2  rmind *    notice, this list of conditions and the following disclaimer in the
     17  1.1.4.2  rmind *    documentation and/or other materials provided with the distribution.
     18  1.1.4.2  rmind *
     19  1.1.4.2  rmind * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.1.4.2  rmind * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.1.4.2  rmind * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.1.4.2  rmind * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.1.4.2  rmind * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.1.4.2  rmind * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.1.4.2  rmind * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.1.4.2  rmind * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.1.4.2  rmind * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.1.4.2  rmind * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.1.4.2  rmind * POSSIBILITY OF SUCH DAMAGE.
     30  1.1.4.2  rmind */
     31  1.1.4.2  rmind 
     32  1.1.4.2  rmind #include <sys/param.h>
     33  1.1.4.2  rmind #include <sys/types.h>
     34  1.1.4.2  rmind #include <sys/bus.h>
     35  1.1.4.2  rmind #include <sys/cdefs.h>
     36  1.1.4.2  rmind #include <sys/device.h>
     37  1.1.4.2  rmind #include <sys/errno.h>
     38  1.1.4.2  rmind 
     39  1.1.4.2  rmind #include <arm/imx/imx23_clkctrlreg.h>
     40  1.1.4.2  rmind #include <arm/imx/imx23_clkctrlvar.h>
     41  1.1.4.2  rmind #include <arm/imx/imx23var.h>
     42  1.1.4.2  rmind 
     43  1.1.4.2  rmind typedef struct clkctrl_softc {
     44  1.1.4.2  rmind 	device_t sc_dev;
     45  1.1.4.2  rmind 	bus_space_tag_t sc_iot;
     46  1.1.4.2  rmind 	bus_space_handle_t sc_hdl;
     47  1.1.4.2  rmind } *clkctrl_softc_t;
     48  1.1.4.2  rmind 
     49  1.1.4.2  rmind static int	clkctrl_match(device_t, cfdata_t, void *);
     50  1.1.4.2  rmind static void	clkctrl_attach(device_t, device_t, void *);
     51  1.1.4.2  rmind static int	clkctrl_activate(device_t, enum devact);
     52  1.1.4.2  rmind 
     53  1.1.4.2  rmind static void     clkctrl_init(struct clkctrl_softc *);
     54  1.1.4.2  rmind 
     55  1.1.4.2  rmind static clkctrl_softc_t _sc = NULL;
     56  1.1.4.2  rmind 
     57  1.1.4.2  rmind CFATTACH_DECL3_NEW(clkctrl,
     58  1.1.4.2  rmind         sizeof(struct clkctrl_softc),
     59  1.1.4.2  rmind         clkctrl_match,
     60  1.1.4.2  rmind         clkctrl_attach,
     61  1.1.4.2  rmind         NULL,
     62  1.1.4.2  rmind         clkctrl_activate,
     63  1.1.4.2  rmind         NULL,
     64  1.1.4.2  rmind         NULL,
     65  1.1.4.2  rmind         0
     66  1.1.4.2  rmind );
     67  1.1.4.2  rmind 
     68  1.1.4.2  rmind #define CLKCTRL_RD(sc, reg)                                                 \
     69  1.1.4.2  rmind         bus_space_read_4(sc->sc_iot, sc->sc_hdl, (reg))
     70  1.1.4.2  rmind #define CLKCTRL_WR(sc, reg, val)                                            \
     71  1.1.4.2  rmind         bus_space_write_4(sc->sc_iot, sc->sc_hdl, (reg), (val))
     72  1.1.4.2  rmind 
     73  1.1.4.2  rmind #define CLKCTRL_SOFT_RST_LOOP 455 /* At least 1 us ... */
     74  1.1.4.2  rmind 
     75  1.1.4.2  rmind static int
     76  1.1.4.2  rmind clkctrl_match(device_t parent, cfdata_t match, void *aux)
     77  1.1.4.2  rmind {
     78  1.1.4.2  rmind 	struct apb_attach_args *aa = aux;
     79  1.1.4.2  rmind 
     80  1.1.4.2  rmind 	if ((aa->aa_addr == HW_CLKCTRL_BASE) &&
     81  1.1.4.2  rmind 	    (aa->aa_size == HW_CLKCTRL_SIZE))
     82  1.1.4.2  rmind 		return 1;
     83  1.1.4.2  rmind 
     84  1.1.4.2  rmind 	return 0;
     85  1.1.4.2  rmind }
     86  1.1.4.2  rmind 
     87  1.1.4.2  rmind static void
     88  1.1.4.2  rmind clkctrl_attach(device_t parent, device_t self, void *aux)
     89  1.1.4.2  rmind {
     90  1.1.4.2  rmind 	struct clkctrl_softc *sc = device_private(self);
     91  1.1.4.2  rmind 	struct apb_attach_args *aa = aux;
     92  1.1.4.2  rmind 	static int clkctrl_attached = 0;
     93  1.1.4.2  rmind 
     94  1.1.4.2  rmind 	sc->sc_dev = self;
     95  1.1.4.2  rmind 	sc->sc_iot = aa->aa_iot;
     96  1.1.4.2  rmind 
     97  1.1.4.2  rmind 	if (clkctrl_attached) {
     98  1.1.4.2  rmind 		aprint_error_dev(sc->sc_dev, "already attached\n");
     99  1.1.4.2  rmind 		return;
    100  1.1.4.2  rmind 	}
    101  1.1.4.2  rmind 
    102  1.1.4.2  rmind 	if (bus_space_map(sc->sc_iot, aa->aa_addr, aa->aa_size, 0,
    103  1.1.4.2  rmind 	    &sc->sc_hdl))
    104  1.1.4.2  rmind 	{
    105  1.1.4.2  rmind 		aprint_error_dev(sc->sc_dev, "Unable to map bus space\n");
    106  1.1.4.2  rmind 		return;
    107  1.1.4.2  rmind 	}
    108  1.1.4.2  rmind 
    109  1.1.4.2  rmind 
    110  1.1.4.2  rmind 	clkctrl_init(sc);
    111  1.1.4.2  rmind 
    112  1.1.4.2  rmind 	aprint_normal("\n");
    113  1.1.4.2  rmind 
    114  1.1.4.2  rmind 	clkctrl_attached = 1;
    115  1.1.4.2  rmind 
    116  1.1.4.2  rmind 	return;
    117  1.1.4.2  rmind }
    118  1.1.4.2  rmind 
    119  1.1.4.2  rmind static int
    120  1.1.4.2  rmind clkctrl_activate(device_t self, enum devact act)
    121  1.1.4.2  rmind {
    122  1.1.4.2  rmind 
    123  1.1.4.2  rmind 	return EOPNOTSUPP;
    124  1.1.4.2  rmind }
    125  1.1.4.2  rmind 
    126  1.1.4.2  rmind static void
    127  1.1.4.2  rmind clkctrl_init(struct clkctrl_softc *sc)
    128  1.1.4.2  rmind {
    129  1.1.4.2  rmind 	_sc = sc;
    130  1.1.4.2  rmind 	return;
    131  1.1.4.2  rmind }
    132  1.1.4.2  rmind 
    133  1.1.4.2  rmind /*
    134  1.1.4.2  rmind  * Power up 8-phase PLL outputs for USB PHY
    135  1.1.4.2  rmind  *
    136  1.1.4.2  rmind  */
    137  1.1.4.2  rmind void
    138  1.1.4.2  rmind clkctrl_en_usb(void)
    139  1.1.4.2  rmind {
    140  1.1.4.2  rmind 	struct clkctrl_softc *sc = _sc;
    141  1.1.4.2  rmind 
    142  1.1.4.2  rmind         if (sc == NULL) {
    143  1.1.4.2  rmind                 aprint_error("clkctrl is not initalized");
    144  1.1.4.2  rmind                 return;
    145  1.1.4.2  rmind         }
    146  1.1.4.2  rmind 
    147  1.1.4.2  rmind 	CLKCTRL_WR(sc, HW_CLKCTRL_PLLCTRL0_SET,
    148  1.1.4.2  rmind 	    HW_CLKCTRL_PLLCTRL0_EN_USB_CLKS);
    149  1.1.4.2  rmind 
    150  1.1.4.2  rmind 	return;
    151  1.1.4.2  rmind }
    152