blob: 5b9c57c43241dbbcdafde5862b5328bc178fa0bb [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * arch/sh/boards/renesas/edosk7705/io.c
3 *
4 * Copyright (C) 2001 Ian da Silva, Jeremy Siegel
5 * Based largely on io_se.c.
6 *
7 * I/O routines for Hitachi EDOSK7705 board.
8 *
9 */
10
11#include <linux/kernel.h>
12#include <linux/types.h>
Paul Mundt866ef8f2008-12-17 13:57:15 +090013#include <linux/io.h>
Paul Mundt7639a452008-10-20 13:02:48 +090014#include <mach/edosk7705.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <asm/addrspace.h>
16
17#define SMC_IOADDR 0xA2000000
18
Linus Torvalds1da177e2005-04-16 15:20:36 -070019/* Map the Ethernet addresses as if it is at 0x300 - 0x320 */
Paul Mundt866ef8f2008-12-17 13:57:15 +090020static unsigned long sh_edosk7705_isa_port2addr(unsigned long port)
Linus Torvalds1da177e2005-04-16 15:20:36 -070021{
Paul Mundt866ef8f2008-12-17 13:57:15 +090022 /*
23 * SMC91C96 registers are 4 byte aligned rather than the
24 * usual 2 byte!
25 */
26 if (port >= 0x300 && port < 0x320)
27 return SMC_IOADDR + ((port - 0x300) * 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Paul Mundt866ef8f2008-12-17 13:57:15 +090029 maybebadio(port);
30 return port;
Linus Torvalds1da177e2005-04-16 15:20:36 -070031}
32
33/* Trying to read / write bytes on odd-byte boundaries to the Ethernet
34 * registers causes problems. So we bit-shift the value and read / write
35 * in 2 byte chunks. Setting the low byte to 0 does not cause problems
36 * now as odd byte writes are only made on the bit mask / interrupt
37 * register. This may not be the case in future Mar-2003 SJD
38 */
39unsigned char sh_edosk7705_inb(unsigned long port)
40{
Paul Mundt866ef8f2008-12-17 13:57:15 +090041 if (port >= 0x300 && port < 0x320 && port & 0x01)
42 return __raw_readw(port - 1) >> 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Paul Mundt866ef8f2008-12-17 13:57:15 +090044 return __raw_readb(sh_edosk7705_isa_port2addr(port));
Linus Torvalds1da177e2005-04-16 15:20:36 -070045}
46
47void sh_edosk7705_outb(unsigned char value, unsigned long port)
48{
49 if (port >= 0x300 && port < 0x320 && port & 0x01) {
Paul Mundt866ef8f2008-12-17 13:57:15 +090050 __raw_writew(((unsigned short)value << 8), port - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 return;
52 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
Paul Mundt866ef8f2008-12-17 13:57:15 +090054 __raw_writeb(value, sh_edosk7705_isa_port2addr(port));
Linus Torvalds1da177e2005-04-16 15:20:36 -070055}
56
57void sh_edosk7705_insb(unsigned long port, void *addr, unsigned long count)
58{
59 unsigned char *p = addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 while (count--)
Paul Mundt866ef8f2008-12-17 13:57:15 +090062 *p++ = sh_edosk7705_inb(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063}
64
65void sh_edosk7705_outsb(unsigned long port, const void *addr, unsigned long count)
66{
Paul Mundt866ef8f2008-12-17 13:57:15 +090067 unsigned char *p = (unsigned char *)addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
Paul Mundt866ef8f2008-12-17 13:57:15 +090069 while (count--)
70 sh_edosk7705_outb(*p++, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -070071}