Home | History | Annotate | Line # | Download | only in s3c2xx0
s3c2410.c revision 1.8.2.1
      1  1.8.2.1      yamt /*	$NetBSD: s3c2410.c,v 1.8.2.1 2006/06/21 14:49:34 yamt Exp $ */
      2      1.1       bsh 
      3      1.1       bsh /*
      4      1.6       bsh  * Copyright (c) 2003, 2005  Genetec corporation.  All rights reserved.
      5      1.1       bsh  * Written by Hiroyuki Bessho for Genetec corporation.
      6      1.1       bsh  *
      7      1.1       bsh  * Redistribution and use in source and binary forms, with or without
      8      1.1       bsh  * modification, are permitted provided that the following conditions
      9      1.1       bsh  * are met:
     10      1.1       bsh  * 1. Redistributions of source code must retain the above copyright
     11      1.1       bsh  *    notice, this list of conditions and the following disclaimer.
     12      1.1       bsh  * 2. Redistributions in binary form must reproduce the above copyright
     13      1.1       bsh  *    notice, this list of conditions and the following disclaimer in the
     14      1.1       bsh  *    documentation and/or other materials provided with the distribution.
     15      1.1       bsh  * 3. The name of Genetec corporation may not be used to endorse
     16      1.1       bsh  *    or promote products derived from this software without specific prior
     17      1.1       bsh  *    written permission.
     18      1.1       bsh  *
     19      1.1       bsh  * THIS SOFTWARE IS PROVIDED BY GENETEC CORP. ``AS IS'' AND
     20      1.1       bsh  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21      1.1       bsh  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22      1.1       bsh  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL GENETEC CORP.
     23      1.1       bsh  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24      1.1       bsh  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25      1.1       bsh  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26      1.1       bsh  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27      1.1       bsh  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28      1.1       bsh  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29      1.1       bsh  * POSSIBILITY OF SUCH DAMAGE.
     30      1.1       bsh  */
     31      1.1       bsh 
     32      1.1       bsh #include <sys/cdefs.h>
     33  1.8.2.1      yamt __KERNEL_RCSID(0, "$NetBSD: s3c2410.c,v 1.8.2.1 2006/06/21 14:49:34 yamt Exp $");
     34      1.1       bsh 
     35      1.1       bsh #include <sys/param.h>
     36      1.1       bsh #include <sys/systm.h>
     37      1.1       bsh #include <sys/device.h>
     38      1.1       bsh #include <sys/kernel.h>
     39      1.1       bsh #include <sys/reboot.h>
     40      1.1       bsh 
     41      1.1       bsh #include <machine/cpu.h>
     42      1.1       bsh #include <machine/bus.h>
     43      1.1       bsh 
     44      1.1       bsh #include <arm/cpufunc.h>
     45      1.1       bsh #include <arm/mainbus/mainbus.h>
     46      1.1       bsh #include <arm/s3c2xx0/s3c2410reg.h>
     47      1.1       bsh #include <arm/s3c2xx0/s3c2410var.h>
     48      1.1       bsh 
     49      1.1       bsh #include "locators.h"
     50      1.1       bsh #include "opt_cpuoptions.h"
     51      1.1       bsh 
     52      1.1       bsh /* prototypes */
     53      1.1       bsh static int	s3c2410_match(struct device *, struct cfdata *, void *);
     54      1.1       bsh static void	s3c2410_attach(struct device *, struct device *, void *);
     55      1.8  drochner static int	s3c2410_search(struct device *, struct cfdata *,
     56  1.8.2.1      yamt 			       const int *, void *);
     57      1.1       bsh 
     58      1.1       bsh /* attach structures */
     59      1.1       bsh CFATTACH_DECL(ssio, sizeof(struct s3c24x0_softc), s3c2410_match, s3c2410_attach,
     60      1.1       bsh     NULL, NULL);
     61      1.1       bsh 
     62      1.1       bsh extern struct bus_space s3c2xx0_bs_tag;
     63      1.1       bsh 
     64      1.1       bsh struct s3c2xx0_softc *s3c2xx0_softc;
     65      1.1       bsh 
     66      1.1       bsh #ifdef DEBUG_PORTF
     67      1.1       bsh volatile uint8_t *portf;	/* for debug */
     68      1.1       bsh #endif
     69      1.1       bsh 
     70      1.1       bsh static int
     71      1.1       bsh s3c2410_print(void *aux, const char *name)
     72      1.1       bsh {
     73      1.1       bsh 	struct s3c2xx0_attach_args *sa = (struct s3c2xx0_attach_args *) aux;
     74      1.1       bsh 
     75      1.1       bsh 	if (sa->sa_size)
     76      1.1       bsh 		aprint_normal(" addr 0x%lx", sa->sa_addr);
     77      1.1       bsh 	if (sa->sa_size > 1)
     78      1.1       bsh 		aprint_normal("-0x%lx", sa->sa_addr + sa->sa_size - 1);
     79      1.1       bsh 	if (sa->sa_intr != SSIOCF_INTR_DEFAULT)
     80      1.1       bsh 		aprint_normal(" intr %d", sa->sa_intr);
     81      1.1       bsh 	if (sa->sa_index != SSIOCF_INDEX_DEFAULT)
     82      1.1       bsh 		aprint_normal(" unit %d", sa->sa_index);
     83      1.1       bsh 
     84      1.1       bsh 	return (UNCONF);
     85      1.1       bsh }
     86      1.1       bsh 
     87      1.1       bsh int
     88      1.1       bsh s3c2410_match(struct device *parent, struct cfdata *match, void *aux)
     89      1.1       bsh {
     90      1.1       bsh 	return 1;
     91      1.1       bsh }
     92      1.1       bsh 
     93      1.1       bsh void
     94      1.1       bsh s3c2410_attach(struct device *parent, struct device *self, void *aux)
     95      1.1       bsh {
     96      1.1       bsh 	struct s3c24x0_softc *sc = (struct s3c24x0_softc *) self;
     97      1.1       bsh 	bus_space_tag_t iot;
     98      1.1       bsh 	const char *which_registers;	/* for panic message */
     99      1.1       bsh 
    100      1.1       bsh #define FAIL(which)  do { \
    101      1.1       bsh 	which_registers=(which); goto abort; }while(/*CONSTCOND*/0)
    102      1.1       bsh 
    103      1.1       bsh 	s3c2xx0_softc = &(sc->sc_sx);
    104      1.1       bsh 	sc->sc_sx.sc_iot = iot = &s3c2xx0_bs_tag;
    105      1.1       bsh 
    106      1.1       bsh 	if (bus_space_map(iot,
    107      1.1       bsh 		S3C2410_INTCTL_BASE, S3C2410_INTCTL_SIZE,
    108      1.1       bsh 		BUS_SPACE_MAP_LINEAR, &sc->sc_sx.sc_intctl_ioh))
    109      1.1       bsh 		FAIL("intc");
    110      1.1       bsh 	/* tell register addresses to interrupt handler */
    111      1.1       bsh 	s3c2410_intr_init(sc);
    112      1.1       bsh 
    113      1.1       bsh 	/* Map the GPIO registers */
    114      1.1       bsh 	if (bus_space_map(iot, S3C2410_GPIO_BASE, S3C2410_GPIO_SIZE,
    115      1.1       bsh 		0, &sc->sc_sx.sc_gpio_ioh))
    116      1.1       bsh 		FAIL("GPIO");
    117      1.1       bsh #ifdef DEBUG_PORTF
    118      1.1       bsh 	{
    119      1.1       bsh 		extern volatile uint8_t *portf;
    120      1.1       bsh 		/* make all ports output */
    121      1.1       bsh 		bus_space_write_2(iot, sc->sc_sx.sc_gpio_ioh, GPIO_PCONF, 0x5555);
    122      1.1       bsh 		portf = (volatile uint8_t *)
    123      1.1       bsh 			((char *)bus_space_vaddr(iot, sc->sc_sx.sc_gpio_ioh) + GPIO_PDATF);
    124      1.1       bsh 	}
    125      1.1       bsh #endif
    126      1.1       bsh 
    127      1.1       bsh #if 0
    128      1.1       bsh 	/* Map the DMA controller registers */
    129      1.1       bsh 	if (bus_space_map(iot, S3C2410_DMAC_BASE, S3C2410_DMAC_SIZE,
    130      1.1       bsh 		0, &sc->sc_sx.sc_dmach))
    131      1.1       bsh 		FAIL("DMAC");
    132      1.1       bsh #endif
    133      1.1       bsh 
    134      1.1       bsh 	/* Memory controller */
    135      1.1       bsh 	if (bus_space_map(iot, S3C2410_MEMCTL_BASE,
    136      1.4       bsh 		S3C24X0_MEMCTL_SIZE, 0, &sc->sc_sx.sc_memctl_ioh))
    137      1.1       bsh 		FAIL("MEMC");
    138      1.1       bsh 	/* Clock manager */
    139      1.1       bsh 	if (bus_space_map(iot, S3C2410_CLKMAN_BASE,
    140      1.4       bsh 		S3C24X0_CLKMAN_SIZE, 0, &sc->sc_sx.sc_clkman_ioh))
    141      1.1       bsh 		FAIL("CLK");
    142      1.1       bsh 
    143      1.1       bsh #if 0
    144      1.1       bsh 	/* Real time clock */
    145      1.1       bsh 	if (bus_space_map(iot, S3C2410_RTC_BASE,
    146      1.4       bsh 		S3C24X0_RTC_SIZE, 0, &sc->sc_sx.sc_rtc_ioh))
    147      1.1       bsh 		FAIL("RTC");
    148      1.1       bsh #endif
    149      1.1       bsh 
    150      1.1       bsh 	if (bus_space_map(iot, S3C2410_TIMER_BASE,
    151      1.4       bsh 		S3C24X0_TIMER_SIZE, 0, &sc->sc_timer_ioh))
    152      1.2       bsh 		FAIL("TIMER");
    153      1.1       bsh 
    154      1.1       bsh 	/* calculate current clock frequency */
    155      1.1       bsh 	s3c24x0_clock_freq(&sc->sc_sx);
    156      1.6       bsh 	aprint_normal(": fclk %d MHz hclk %d MHz pclk %d MHz\n",
    157      1.1       bsh 	       sc->sc_sx.sc_fclk / 1000000, sc->sc_sx.sc_hclk / 1000000,
    158      1.1       bsh 	       sc->sc_sx.sc_pclk / 1000000);
    159      1.1       bsh 
    160      1.6       bsh 	aprint_naive("\n");
    161      1.2       bsh 
    162      1.3       bsh 	/* get busdma tag for the platform */
    163      1.3       bsh 	sc->sc_sx.sc_dmat = s3c2xx0_bus_dma_init(&s3c2xx0_bus_dma);
    164      1.1       bsh 
    165      1.1       bsh 	/*
    166      1.1       bsh 	 *  Attach devices.
    167      1.1       bsh 	 */
    168      1.8  drochner 	config_search_ia(s3c2410_search, self, "ssio", NULL);
    169      1.1       bsh 	return;
    170      1.1       bsh 
    171      1.1       bsh abort:
    172      1.1       bsh 	panic("%s: unable to map %s registers",
    173      1.1       bsh 	    self->dv_xname, which_registers);
    174      1.1       bsh 
    175      1.1       bsh #undef FAIL
    176      1.1       bsh }
    177      1.1       bsh 
    178      1.1       bsh int
    179      1.8  drochner s3c2410_search(struct device * parent, struct cfdata * cf,
    180  1.8.2.1      yamt 	       const int *ldesc, void *aux)
    181      1.1       bsh {
    182      1.1       bsh 	struct s3c24x0_softc *sc = (struct s3c24x0_softc *) parent;
    183      1.1       bsh 	struct s3c2xx0_attach_args aa;
    184      1.1       bsh 
    185      1.1       bsh 	aa.sa_sc = sc;
    186      1.1       bsh 	aa.sa_iot = sc->sc_sx.sc_iot;
    187      1.1       bsh 	aa.sa_addr = cf->cf_loc[SSIOCF_ADDR];
    188      1.1       bsh 	aa.sa_size = cf->cf_loc[SSIOCF_SIZE];
    189      1.1       bsh 	aa.sa_index = cf->cf_loc[SSIOCF_INDEX];
    190      1.1       bsh 	aa.sa_intr = cf->cf_loc[SSIOCF_INTR];
    191      1.3       bsh 
    192      1.3       bsh 	aa.sa_dmat = sc->sc_sx.sc_dmat;
    193      1.1       bsh 
    194      1.1       bsh 	if (config_match(parent, cf, &aa))
    195      1.1       bsh 		config_attach(parent, cf, &aa, s3c2410_print);
    196      1.1       bsh 
    197      1.1       bsh 	return 0;
    198      1.1       bsh }
    199      1.1       bsh 
    200      1.1       bsh /*
    201      1.1       bsh  * fill sc_pclk, sc_hclk, sc_fclk from values of clock controller register.
    202      1.7       bsh  *
    203      1.7       bsh  * s3c24x0_clock_freq2() is meant to be called from kernel startup routines.
    204      1.7       bsh  * s3c24x0_clock_freq() is for after kernel initialization is done.
    205      1.1       bsh  */
    206      1.1       bsh void
    207      1.7       bsh s3c24x0_clock_freq2(vaddr_t clkman_base, int *fclk, int *hclk, int *pclk)
    208      1.1       bsh {
    209      1.7       bsh 	uint32_t pllcon, divn;
    210      1.1       bsh 	int mdiv, pdiv, sdiv;
    211      1.7       bsh 	int f, h, p;
    212      1.1       bsh 
    213      1.7       bsh 	pllcon = *(volatile uint32_t *)(clkman_base + CLKMAN_MPLLCON);
    214      1.7       bsh 	divn = *(volatile uint32_t *)(clkman_base + CLKMAN_CLKDIVN);
    215      1.1       bsh 
    216      1.1       bsh 	mdiv = (pllcon & PLLCON_MDIV_MASK) >> PLLCON_MDIV_SHIFT;
    217      1.1       bsh 	pdiv = (pllcon & PLLCON_PDIV_MASK) >> PLLCON_PDIV_SHIFT;
    218      1.1       bsh 	sdiv = (pllcon & PLLCON_SDIV_MASK) >> PLLCON_SDIV_SHIFT;
    219      1.1       bsh 
    220      1.7       bsh 	f = ((mdiv + 8) * S3C2XX0_XTAL_CLK) / ((pdiv + 2) * (1 << sdiv));
    221      1.7       bsh 	h = f;
    222      1.1       bsh 	if (divn & CLKDIVN_HDIVN)
    223      1.7       bsh 		h /= 2;
    224      1.7       bsh 	p = h;
    225      1.1       bsh 	if (divn & CLKDIVN_PDIVN)
    226      1.7       bsh 		p /= 2;
    227      1.7       bsh 
    228      1.7       bsh 	if (fclk) *fclk = f;
    229      1.7       bsh 	if (hclk) *hclk = h;
    230      1.7       bsh 	if (pclk) *pclk = p;
    231      1.7       bsh 
    232      1.7       bsh }
    233      1.7       bsh 
    234      1.7       bsh void
    235      1.7       bsh s3c24x0_clock_freq(struct s3c2xx0_softc *sc)
    236      1.7       bsh {
    237      1.7       bsh 	s3c24x0_clock_freq2(
    238      1.7       bsh 		(vaddr_t)bus_space_vaddr(sc->sc_iot, sc->sc_clkman_ioh),
    239      1.7       bsh 		&sc->sc_fclk, &sc->sc_hclk, &sc->sc_pclk);
    240      1.1       bsh }
    241      1.1       bsh 
    242      1.1       bsh /*
    243      1.1       bsh  * Issue software reset command.
    244      1.1       bsh  * called with MMU off.
    245      1.5       bsh  *
    246      1.5       bsh  * S3C2410 doesn't have sowtware reset bit like S3C2800.
    247      1.5       bsh  * use watch dog timer and make it fire immediately.
    248      1.1       bsh  */
    249      1.1       bsh void
    250      1.1       bsh s3c2410_softreset(void)
    251      1.1       bsh {
    252      1.5       bsh 	disable_interrupts(I32_bit|F32_bit);
    253      1.5       bsh 
    254      1.5       bsh 	*(volatile unsigned int *)(S3C2410_WDT_BASE + WDT_WTCON)
    255      1.5       bsh 		= (0 << WTCON_PRESCALE_SHIFT) | WTCON_ENABLE |
    256      1.5       bsh 		WTCON_CLKSEL_16 | WTCON_ENRST;
    257      1.1       bsh }
    258      1.1       bsh 
    259      1.5       bsh 
    260