1*95e1ffb1Schristos /* $NetBSD: smdk2800_io_init.c,v 1.2 2005/12/11 12:17:09 christos Exp $ */
27fc9d147Sbsh
37fc9d147Sbsh /*
47fc9d147Sbsh * Copyright (c) 2002, 2003 Fujitsu Component Limited
57fc9d147Sbsh * Copyright (c) 2002, 2003 Genetec Corporation
67fc9d147Sbsh * All rights reserved.
77fc9d147Sbsh *
87fc9d147Sbsh * Redistribution and use in source and binary forms, with or without
97fc9d147Sbsh * modification, are permitted provided that the following conditions
107fc9d147Sbsh * are met:
117fc9d147Sbsh * 1. Redistributions of source code must retain the above copyright
127fc9d147Sbsh * notice, this list of conditions and the following disclaimer.
137fc9d147Sbsh * 2. Redistributions in binary form must reproduce the above copyright
147fc9d147Sbsh * notice, this list of conditions and the following disclaimer in the
157fc9d147Sbsh * documentation and/or other materials provided with the distribution.
167fc9d147Sbsh * 3. Neither the name of The Fujitsu Component Limited nor the name of
177fc9d147Sbsh * Genetec corporation may not be used to endorse or promote products
187fc9d147Sbsh * derived from this software without specific prior written permission.
197fc9d147Sbsh *
207fc9d147Sbsh * THIS SOFTWARE IS PROVIDED BY FUJITSU COMPONENT LIMITED AND GENETEC
217fc9d147Sbsh * CORPORATION ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
227fc9d147Sbsh * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
237fc9d147Sbsh * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
247fc9d147Sbsh * DISCLAIMED. IN NO EVENT SHALL FUJITSU COMPONENT LIMITED OR GENETEC
257fc9d147Sbsh * CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
267fc9d147Sbsh * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
277fc9d147Sbsh * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
287fc9d147Sbsh * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
297fc9d147Sbsh * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
307fc9d147Sbsh * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
317fc9d147Sbsh * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
327fc9d147Sbsh * SUCH DAMAGE.
337fc9d147Sbsh */
347fc9d147Sbsh
357fc9d147Sbsh #include <arm/s3c2xx0/s3c2800reg.h>
367fc9d147Sbsh
377fc9d147Sbsh #define EXTINTR_INIT ((EXTINTR_HIGH|EXTINTR_FALLING)<<28) | \
387fc9d147Sbsh ((EXTINTR_HIGH|EXTINTR_FALLING)<<24) | \
397fc9d147Sbsh ((EXTINTR_HIGH|EXTINTR_FALLING)<<20) | \
407fc9d147Sbsh ((EXTINTR_HIGH|EXTINTR_FALLING)<<16) | \
417fc9d147Sbsh ((EXTINTR_HIGH|EXTINTR_FALLING)<<12) | \
427fc9d147Sbsh ((EXTINTR_HIGH|EXTINTR_FALLING)<<8) | \
437fc9d147Sbsh ((EXTINTR_HIGH|EXTINTR_FALLING)<<4) | \
447fc9d147Sbsh ((EXTINTR_HIGH|EXTINTR_FALLING))
457fc9d147Sbsh #define FCLK 200000000
467fc9d147Sbsh #define F_1MHZ 1000000
477fc9d147Sbsh
487fc9d147Sbsh #define IOW(a, d) (*(volatile unsigned int *)(a) = (d))
497fc9d147Sbsh #define IOR(a) (*(volatile unsigned int *)(a))
507fc9d147Sbsh #define SETLED(d) IOW(S3C2800_GPIO_BASE+GPIO_PDATC,(d))
517fc9d147Sbsh
527fc9d147Sbsh void smdk2800_io_init(void);
537fc9d147Sbsh
547fc9d147Sbsh void
smdk2800_io_init(void)557fc9d147Sbsh smdk2800_io_init(void)
567fc9d147Sbsh {
577fc9d147Sbsh unsigned int hclk;
587fc9d147Sbsh unsigned int pclk;
597fc9d147Sbsh unsigned int tmdat;
607fc9d147Sbsh
617fc9d147Sbsh #define O PCON_OUTPUT
627fc9d147Sbsh #define I PCON_INPUT
637fc9d147Sbsh #define A PCON_ALTFUN
647fc9d147Sbsh #define _ 0
657fc9d147Sbsh #define _C(b7,b6,b5,b4,b3,b2,b1,b0) \
667fc9d147Sbsh ((b7<<14)|(b6<<12)|(b5<<10)|(b4<<8)|(b3<<6)|(b2<<4)|(b1<<2)|(b0<<0))
677fc9d147Sbsh
687fc9d147Sbsh /* GPIO port */
697fc9d147Sbsh IOW(S3C2800_GPIO_BASE+GPIO_PCONA, _C(O,O,A,A,A,A,A,A));
707fc9d147Sbsh IOW(S3C2800_GPIO_BASE+GPIO_PUPA, 0xff);
717fc9d147Sbsh IOW(S3C2800_GPIO_BASE+GPIO_PCONB, _C(I,O,A,A,A,A,A,A));
727fc9d147Sbsh IOW(S3C2800_GPIO_BASE+GPIO_PCONC, _C(_,_,_,_,O,A,A,A));
737fc9d147Sbsh IOW(S3C2800_GPIO_BASE+GPIO_PUPC, 0xff);
747fc9d147Sbsh IOW(S3C2800_GPIO_BASE+GPIO_PCOND, _C(A,A,A,A,A,A,A,A));
757fc9d147Sbsh IOW(S3C2800_GPIO_BASE+GPIO_PUPD, 0xff);
767fc9d147Sbsh IOW(S3C2800_GPIO_BASE+GPIO_PCONE, _C(O,O,O,O,A,A,A,A));
777fc9d147Sbsh IOW(S3C2800_GPIO_BASE+GPIO_PUPE, 0xff);
787fc9d147Sbsh IOW(S3C2800_GPIO_BASE+GPIO_PCONF, _C(A,A,A,A,A,A,A,A));
797fc9d147Sbsh IOW(S3C2800_GPIO_BASE+GPIO_PUPF, 0xff);
807fc9d147Sbsh IOW(S3C2800_GPIO_BASE+GPIO_EXTINTR, EXTINTR_INIT);
817fc9d147Sbsh
827fc9d147Sbsh #undef O
837fc9d147Sbsh #undef I
847fc9d147Sbsh #undef A
857fc9d147Sbsh #undef _
867fc9d147Sbsh #undef _C
877fc9d147Sbsh
887fc9d147Sbsh /* Get clock value */
897fc9d147Sbsh if(IOR(S3C2800_CLKMAN_BASE+CLKMAN_CLKCON) & CLKCON_HCLK)
907fc9d147Sbsh hclk = FCLK / 2;
917fc9d147Sbsh else
927fc9d147Sbsh hclk = FCLK;
937fc9d147Sbsh
947fc9d147Sbsh if(IOR(S3C2800_CLKMAN_BASE+CLKMAN_CLKCON) & CLKCON_PCLK)
957fc9d147Sbsh pclk = hclk / 2;
967fc9d147Sbsh else
977fc9d147Sbsh pclk = hclk;
987fc9d147Sbsh
997fc9d147Sbsh /* Timer */
1007fc9d147Sbsh if((pclk/F_1MHZ) < 1)
1017fc9d147Sbsh tmdat = 1<<16;
1027fc9d147Sbsh else
1037fc9d147Sbsh tmdat = (pclk/F_1MHZ)<<16;
1047fc9d147Sbsh
1057fc9d147Sbsh #define TMDAT_INIT 0xf424
1067fc9d147Sbsh
1077fc9d147Sbsh IOW(S3C2800_TIMER0_BASE+TIMER_TMDAT, (tmdat | TMDAT_INIT));
1087fc9d147Sbsh IOW(S3C2800_TIMER1_BASE+TIMER_TMDAT, (tmdat | TMDAT_INIT));
1097fc9d147Sbsh IOW(S3C2800_TIMER2_BASE+TIMER_TMDAT, (tmdat | TMDAT_INIT));
1107fc9d147Sbsh
1117fc9d147Sbsh IOW(S3C2800_TIMER0_BASE+TIMER_TMCON, TMCON_MUX_DIV32 | TMCON_INTENA | TMCON_ENABLE);
1127fc9d147Sbsh IOW(S3C2800_TIMER1_BASE+TIMER_TMCON, TMCON_MUX_DIV16 | TMCON_INTENA | TMCON_ENABLE);
1137fc9d147Sbsh IOW(S3C2800_TIMER2_BASE+TIMER_TMCON, TMCON_MUX_DIV8 | TMCON_INTENA | TMCON_ENABLE);
1147fc9d147Sbsh
1157fc9d147Sbsh /* Interrupt controller */
1167fc9d147Sbsh IOW(S3C2800_INTCTL_BASE+INTCTL_INTMOD, 0);
1177fc9d147Sbsh IOW(S3C2800_INTCTL_BASE+INTCTL_INTMSK, 0);
1187fc9d147Sbsh
1197fc9d147Sbsh /* Initial complete */
1207fc9d147Sbsh SETLED(0x0); /* All LEDs on (o o o) */
1217fc9d147Sbsh }
122