Home | History | Annotate | Line # | Download | only in obs405
obs600_machdep.c revision 1.15
      1  1.15       rin /*	$NetBSD: obs600_machdep.c,v 1.15 2021/03/30 04:28:50 rin Exp $	*/
      2   1.1  kiyohara /*	Original: md_machdep.c,v 1.3 2005/01/24 18:47:37 shige Exp $	*/
      3   1.1  kiyohara 
      4   1.1  kiyohara /*
      5   1.1  kiyohara  * Copyright 2001, 2002 Wasabi Systems, Inc.
      6   1.1  kiyohara  * All rights reserved.
      7   1.1  kiyohara  *
      8   1.1  kiyohara  * Written by Eduardo Horvath and Simon Burge for Wasabi Systems, Inc.
      9   1.1  kiyohara  *
     10   1.1  kiyohara  * Redistribution and use in source and binary forms, with or without
     11   1.1  kiyohara  * modification, are permitted provided that the following conditions
     12   1.1  kiyohara  * are met:
     13   1.1  kiyohara  * 1. Redistributions of source code must retain the above copyright
     14   1.1  kiyohara  *    notice, this list of conditions and the following disclaimer.
     15   1.1  kiyohara  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1  kiyohara  *    notice, this list of conditions and the following disclaimer in the
     17   1.1  kiyohara  *    documentation and/or other materials provided with the distribution.
     18   1.1  kiyohara  * 3. All advertising materials mentioning features or use of this software
     19   1.1  kiyohara  *    must display the following acknowledgement:
     20   1.1  kiyohara  *      This product includes software developed for the NetBSD Project by
     21   1.1  kiyohara  *      Wasabi Systems, Inc.
     22   1.1  kiyohara  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     23   1.1  kiyohara  *    or promote products derived from this software without specific prior
     24   1.1  kiyohara  *    written permission.
     25   1.1  kiyohara  *
     26   1.1  kiyohara  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     27   1.1  kiyohara  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28   1.1  kiyohara  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29   1.1  kiyohara  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     30   1.1  kiyohara  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31   1.1  kiyohara  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32   1.1  kiyohara  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33   1.1  kiyohara  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34   1.1  kiyohara  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35   1.1  kiyohara  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36   1.1  kiyohara  * POSSIBILITY OF SUCH DAMAGE.
     37   1.1  kiyohara  */
     38   1.1  kiyohara 
     39   1.1  kiyohara /*
     40   1.1  kiyohara  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
     41   1.1  kiyohara  * Copyright (C) 1995, 1996 TooLs GmbH.
     42   1.1  kiyohara  * All rights reserved.
     43   1.1  kiyohara  *
     44   1.1  kiyohara  * Redistribution and use in source and binary forms, with or without
     45   1.1  kiyohara  * modification, are permitted provided that the following conditions
     46   1.1  kiyohara  * are met:
     47   1.1  kiyohara  * 1. Redistributions of source code must retain the above copyright
     48   1.1  kiyohara  *    notice, this list of conditions and the following disclaimer.
     49   1.1  kiyohara  * 2. Redistributions in binary form must reproduce the above copyright
     50   1.1  kiyohara  *    notice, this list of conditions and the following disclaimer in the
     51   1.1  kiyohara  *    documentation and/or other materials provided with the distribution.
     52   1.1  kiyohara  * 3. All advertising materials mentioning features or use of this software
     53   1.1  kiyohara  *    must display the following acknowledgement:
     54   1.1  kiyohara  *	This product includes software developed by TooLs GmbH.
     55   1.1  kiyohara  * 4. The name of TooLs GmbH may not be used to endorse or promote products
     56   1.1  kiyohara  *    derived from this software without specific prior written permission.
     57   1.1  kiyohara  *
     58   1.1  kiyohara  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
     59   1.1  kiyohara  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     60   1.1  kiyohara  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     61   1.1  kiyohara  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     62   1.1  kiyohara  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     63   1.1  kiyohara  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     64   1.1  kiyohara  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     65   1.1  kiyohara  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     66   1.1  kiyohara  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     67   1.1  kiyohara  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     68   1.1  kiyohara  */
     69   1.1  kiyohara 
     70   1.1  kiyohara #include <sys/cdefs.h>
     71  1.15       rin __KERNEL_RCSID(0, "$NetBSD: obs600_machdep.c,v 1.15 2021/03/30 04:28:50 rin Exp $");
     72   1.1  kiyohara 
     73   1.1  kiyohara #include "opt_ddb.h"
     74   1.1  kiyohara 
     75   1.1  kiyohara #include <sys/param.h>
     76   1.1  kiyohara #include <sys/bus.h>
     77  1.15       rin #include <sys/device.h>
     78   1.1  kiyohara #include <sys/errno.h>
     79   1.1  kiyohara #include <sys/kernel.h>
     80  1.15       rin #include <sys/module.h>
     81   1.1  kiyohara #include <sys/reboot.h>
     82   1.1  kiyohara #include <sys/systm.h>
     83   1.1  kiyohara 
     84  1.15       rin #include <machine/obs600.h>
     85   1.1  kiyohara 
     86  1.15       rin #include <powerpc/spr.h>
     87  1.15       rin #include <powerpc/ibm4xx/spr.h>
     88   1.1  kiyohara 
     89   1.1  kiyohara #include <powerpc/ibm4xx/amcc405ex.h>
     90   1.6      matt #include <powerpc/ibm4xx/cpu.h>
     91   1.1  kiyohara #include <powerpc/ibm4xx/dcr4xx.h>
     92  1.15       rin #include <powerpc/ibm4xx/tlb.h>
     93  1.15       rin 
     94   1.1  kiyohara #include <powerpc/ibm4xx/dev/gpiicreg.h>
     95   1.1  kiyohara #include <powerpc/ibm4xx/dev/opbvar.h>
     96   1.6      matt 
     97   1.1  kiyohara #include "com.h"
     98   1.1  kiyohara #if (NCOM > 0)
     99   1.1  kiyohara #include <sys/termios.h>
    100  1.15       rin #include <powerpc/ibm4xx/dev/comopbvar.h>
    101  1.15       rin #include <dev/ic/comreg.h>
    102   1.1  kiyohara 
    103   1.1  kiyohara #ifndef CONADDR
    104   1.1  kiyohara #define CONADDR		AMCC405EX_UART0_BASE
    105   1.1  kiyohara #endif
    106   1.1  kiyohara #ifndef CONSPEED
    107   1.1  kiyohara #define CONSPEED	B115200
    108   1.1  kiyohara #endif
    109   1.1  kiyohara #ifndef CONMODE
    110   1.1  kiyohara 			/* 8N1 */
    111   1.1  kiyohara #define CONMODE		((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8)
    112   1.1  kiyohara #endif
    113   1.1  kiyohara #endif	/* NCOM */
    114   1.1  kiyohara 
    115   1.1  kiyohara /*
    116   1.1  kiyohara  * XXXX:
    117   1.1  kiyohara  * It is very troublesome though we can calculate from various registers. X-<
    118   1.1  kiyohara  */
    119   1.1  kiyohara #define OBS600_CPU_FREQ	(600 * 1000 * 1000)
    120   1.1  kiyohara #define OBS600_MEM_SIZE	(1 * 1024 * 1024 * 1024)
    121   1.1  kiyohara 
    122   1.1  kiyohara #define	TLB_PG_SIZE 	(16 * 1024 * 1024)
    123   1.1  kiyohara 
    124   1.7      matt void initppc(vaddr_t, vaddr_t, int, char *[], char *);
    125   1.1  kiyohara static int read_eeprom(int, char *);
    126   1.1  kiyohara 
    127   1.1  kiyohara 
    128   1.1  kiyohara void
    129   1.7      matt initppc(vaddr_t startkernel, vaddr_t endkernel, int argc, char *argv[],
    130   1.1  kiyohara 	char *argstr)
    131   1.1  kiyohara {
    132   1.1  kiyohara 	vaddr_t va;
    133   1.1  kiyohara 	u_int memsize;
    134   1.1  kiyohara 
    135   1.1  kiyohara 	memsize = OBS600_MEM_SIZE;
    136   1.1  kiyohara 
    137   1.1  kiyohara 	/* Linear map kernel memory */
    138   1.1  kiyohara 	for (va = 0; va < endkernel; va += TLB_PG_SIZE)
    139   1.1  kiyohara 		ppc4xx_tlb_reserve(va, va, TLB_PG_SIZE, TLB_EX);
    140   1.1  kiyohara 
    141   1.1  kiyohara 	/*
    142   1.1  kiyohara 	 * Map console and I2C after RAM. (see pmap_tlbmiss())
    143   1.1  kiyohara 	 * All peripherals mapped on a page.
    144   1.1  kiyohara 	 */
    145   1.1  kiyohara 	ppc4xx_tlb_reserve(AMCC405EX_OPB_BASE, roundup(memsize, TLB_PG_SIZE),
    146   1.1  kiyohara 	    TLB_PG_SIZE, TLB_I | TLB_G);
    147   1.1  kiyohara 
    148   1.1  kiyohara 	/* Initialize AMCC 405EX CPU */
    149   1.1  kiyohara 	ibm40x_memsize_init(memsize, startkernel);
    150   1.7      matt 	ibm4xx_init(startkernel, endkernel, pic_ext_intr);
    151   1.1  kiyohara 
    152   1.1  kiyohara #ifdef DDB
    153   1.1  kiyohara 	if (boothowto & RB_KDB)
    154   1.1  kiyohara 		Debugger();
    155   1.1  kiyohara #endif
    156   1.4       mrg 
    157   1.4       mrg 	/*
    158   1.4       mrg 	 * Look for the ibm4xx modules in the right place.
    159   1.4       mrg 	 */
    160   1.4       mrg 	module_machine = module_machine_ibm4xx;
    161   1.1  kiyohara }
    162   1.1  kiyohara 
    163   1.1  kiyohara void
    164   1.1  kiyohara consinit(void)
    165   1.1  kiyohara {
    166   1.1  kiyohara 
    167   1.1  kiyohara #if (NCOM > 0)
    168   1.1  kiyohara 	com_opb_cnattach(OBS600_COM_FREQ, CONADDR, CONSPEED, CONMODE);
    169   1.1  kiyohara #endif /* NCOM */
    170   1.1  kiyohara }
    171   1.1  kiyohara 
    172   1.1  kiyohara /*
    173   1.1  kiyohara  * Machine dependent startup code.
    174   1.1  kiyohara  */
    175   1.1  kiyohara void
    176   1.1  kiyohara cpu_startup(void)
    177   1.1  kiyohara {
    178   1.1  kiyohara 	prop_number_t pn;
    179   1.1  kiyohara 	prop_data_t pd;
    180   1.1  kiyohara 	u_char *macaddr, *macaddr1;
    181   1.1  kiyohara 	static u_char buf[16];	/* MAC address x2 buffer */
    182   1.1  kiyohara 
    183   1.1  kiyohara 	/*
    184   1.1  kiyohara 	 * cpu common startup
    185   1.1  kiyohara 	 */
    186   1.1  kiyohara 	ibm4xx_cpu_startup("OpenBlockS600 AMCC PowerPC 405EX Board");
    187   1.1  kiyohara 
    188   1.1  kiyohara 	/*
    189   1.1  kiyohara 	 * Set up the board properties database.
    190   1.1  kiyohara 	 */
    191   1.1  kiyohara 	board_info_init();
    192   1.1  kiyohara 
    193   1.1  kiyohara 	pn = prop_number_create_integer(OBS600_CPU_FREQ);
    194   1.1  kiyohara 	KASSERT(pn != NULL);
    195   1.1  kiyohara 	if (prop_dictionary_set(board_properties, "processor-frequency", pn) ==
    196   1.1  kiyohara 	    false)
    197   1.1  kiyohara 		panic("setting processor-frequency");
    198   1.1  kiyohara 	prop_object_release(pn);
    199   1.1  kiyohara 
    200   1.1  kiyohara 	pn = prop_number_create_integer(OBS600_MEM_SIZE);
    201   1.1  kiyohara 	KASSERT(pn != NULL);
    202   1.1  kiyohara 	if (prop_dictionary_set(board_properties, "mem-size", pn) == false)
    203   1.1  kiyohara 		panic("setting mem-size");
    204   1.1  kiyohara 	prop_object_release(pn);
    205   1.1  kiyohara 
    206  1.11       rin 	calc_delayconst(); /* required by read_eeprom() */
    207  1.11       rin 
    208   1.1  kiyohara #define ETHER_ADDR_LEN	6
    209   1.1  kiyohara 
    210  1.11       rin 	read_eeprom(sizeof(buf), buf);
    211  1.11       rin 	macaddr = &buf[0];
    212  1.11       rin 	macaddr1 = &buf[8];
    213  1.11       rin 
    214   1.1  kiyohara 	pd = prop_data_create_data_nocopy(macaddr, ETHER_ADDR_LEN);
    215   1.1  kiyohara 	KASSERT(pd != NULL);
    216   1.1  kiyohara 	if (prop_dictionary_set(board_properties, "emac0-mac-addr", pd) ==
    217   1.1  kiyohara 	    false)
    218   1.1  kiyohara 		panic("setting emac0-mac-addr");
    219   1.1  kiyohara 	prop_object_release(pd);
    220   1.1  kiyohara 	pd = prop_data_create_data_nocopy(macaddr1, ETHER_ADDR_LEN);
    221   1.1  kiyohara 	KASSERT(pd != NULL);
    222   1.1  kiyohara 	if (prop_dictionary_set(board_properties, "emac1-mac-addr", pd) ==
    223   1.1  kiyohara 	    false)
    224   1.1  kiyohara 		panic("setting emac1-mac-addr");
    225   1.1  kiyohara 	prop_object_release(pd);
    226   1.1  kiyohara 
    227   1.1  kiyohara 	/* emac0 connects to phy 2 and emac1 to phy 3 via RGMII. */
    228   1.1  kiyohara 	pn = prop_number_create_integer(2);
    229   1.1  kiyohara 	KASSERT(pn != NULL);
    230   1.1  kiyohara 	if (prop_dictionary_set(board_properties, "emac0-mii-phy", pn) == false)
    231   1.1  kiyohara 		panic("setting emac0-mii-phy");
    232   1.1  kiyohara 	prop_object_release(pn);
    233   1.1  kiyohara 	pn = prop_number_create_integer(3);
    234   1.1  kiyohara 	KASSERT(pn != NULL);
    235   1.1  kiyohara 	if (prop_dictionary_set(board_properties, "emac1-mii-phy", pn) == false)
    236   1.1  kiyohara 		panic("setting emac1-mii-phy");
    237   1.1  kiyohara 	prop_object_release(pn);
    238   1.1  kiyohara 
    239   1.1  kiyohara 	/*
    240  1.12       rin 	 * Now that we have VM, malloc()s are OK in bus_space.
    241  1.12       rin 	 */
    242  1.12       rin 	bus_space_mallocok();
    243  1.12       rin 
    244  1.12       rin 	/*
    245   1.1  kiyohara 	 * no fake mapiodev
    246   1.1  kiyohara 	 */
    247   1.1  kiyohara 	fake_mapiodev = 0;
    248   1.3  kiyohara 
    249   1.3  kiyohara 	splraise(-1);
    250   1.1  kiyohara }
    251   1.1  kiyohara 
    252   1.1  kiyohara /*
    253   1.9  kiyohara  * Read EEPROM via I2C.  We don't use bus_space(9) here.  This is MD-part and,
    254   1.9  kiyohara  * don't support bus_space_unmap() to a space on reserved space? X-<
    255   1.9  kiyohara  *
    256   1.9  kiyohara  * XXXX: Also this function assume already initialized for I2C...
    257   1.9  kiyohara  */
    258   1.1  kiyohara static int
    259   1.1  kiyohara read_eeprom(int len, char *buf)
    260   1.1  kiyohara {
    261   1.9  kiyohara 	volatile uint8_t *iic0;
    262   1.9  kiyohara #define IIC0_READ(r)		(*(iic0 + (r)))
    263   1.9  kiyohara #define IIC0_WRITE(r, v)	(*(iic0 + (r)) = (v))
    264   1.9  kiyohara 	uint8_t sts;
    265   1.1  kiyohara 	int cnt, i = 0;
    266   1.1  kiyohara 
    267   1.1  kiyohara #define I2C_EEPROM_ADDR	0x52
    268   1.1  kiyohara 
    269   1.9  kiyohara 	if ((iic0 = ppc4xx_tlb_mapiodev(AMCC405EX_IIC0_BASE, IIC_NREG)) == NULL)
    270   1.1  kiyohara 		return ENOMEM; /* ??? */
    271   1.1  kiyohara 
    272   1.1  kiyohara 	/* Clear Stop Complete Bit */
    273   1.9  kiyohara 	IIC0_WRITE(IIC_STS, IIC_STS_SCMP);
    274   1.1  kiyohara 	/* Check init */
    275   1.1  kiyohara 	do {
    276   1.1  kiyohara 		/* Get status */
    277   1.9  kiyohara 		sts = IIC0_READ(IIC_STS);
    278   1.1  kiyohara 	} while ((sts & IIC_STS_PT));
    279   1.1  kiyohara 
    280   1.9  kiyohara 	IIC0_WRITE(IIC_MDCNTL,
    281   1.9  kiyohara 	    IIC0_READ(IIC_MDCNTL) | IIC_MDCNTL_FMDB | IIC_MDCNTL_FSDB);
    282   1.1  kiyohara 
    283   1.1  kiyohara 	/* 7-bit adressing */
    284   1.9  kiyohara 	IIC0_WRITE(IIC_HMADR, 0);
    285   1.9  kiyohara 	IIC0_WRITE(IIC_LMADR, I2C_EEPROM_ADDR << 1);
    286   1.1  kiyohara 
    287   1.9  kiyohara 	IIC0_WRITE(IIC_MDBUF, 0);
    288   1.9  kiyohara 	IIC0_WRITE(IIC_CNTL, IIC_CNTL_PT);
    289   1.1  kiyohara 	do {
    290   1.1  kiyohara 		/* Get status */
    291   1.9  kiyohara 		sts = IIC0_READ(IIC_STS);
    292   1.1  kiyohara 	} while ((sts & IIC_STS_PT) && !(sts & IIC_STS_ERR));
    293   1.1  kiyohara 
    294   1.1  kiyohara 	cnt = 0;
    295   1.1  kiyohara 	while (cnt < len) {
    296   1.1  kiyohara 		/* always read 4byte */
    297   1.9  kiyohara 		IIC0_WRITE(IIC_CNTL,
    298   1.9  kiyohara 		    IIC_CNTL_PT				|
    299   1.9  kiyohara 		    IIC_CNTL_RW				|
    300   1.9  kiyohara 		    ((cnt == 0) ? IIC_CNTL_RPST : 0)	|
    301   1.9  kiyohara 		    IIC_CNTL_TCT);
    302   1.1  kiyohara 		do {
    303   1.1  kiyohara 			/* Get status */
    304   1.9  kiyohara 			sts = IIC0_READ(IIC_STS);
    305   1.1  kiyohara 		} while ((sts & IIC_STS_PT) && !(sts & IIC_STS_ERR));
    306   1.1  kiyohara 
    307   1.1  kiyohara 		if ((sts & IIC_STS_PT) || (sts & IIC_STS_ERR))
    308   1.1  kiyohara 			break;
    309   1.1  kiyohara 		if (sts & IIC_STS_MDBS) {
    310   1.1  kiyohara 			delay(1);
    311   1.1  kiyohara 			/* read 4byte */
    312   1.1  kiyohara 			for (i = 0; i < 4 && cnt < len; i++, cnt++)
    313   1.9  kiyohara 				buf[cnt] = IIC0_READ(IIC_MDBUF);
    314   1.1  kiyohara 		}
    315   1.1  kiyohara 	}
    316   1.1  kiyohara 	for ( ; i < 4; i++)
    317   1.9  kiyohara 		(void) IIC0_READ(IIC_MDBUF);
    318   1.1  kiyohara 
    319   1.1  kiyohara 	return (cnt == len) ? 0 : EINVAL;
    320   1.1  kiyohara }
    321