2 * Goramo MultiLink router platform code
3 * Copyright (C) 2006-2009 Krzysztof Halasa <khc@pm.waw.pl>
6 #include <linux/delay.h>
7 #include <linux/hdlc.h>
8 #include <linux/i2c-gpio.h>
10 #include <linux/irq.h>
11 #include <linux/kernel.h>
12 #include <linux/pci.h>
13 #include <linux/serial_8250.h>
14 #include <asm/mach-types.h>
15 #include <asm/mach/arch.h>
16 #include <asm/mach/flash.h>
17 #include <asm/mach/pci.h>
19 #define SLOT_ETHA 0x0B /* IDSEL = AD21 */
20 #define SLOT_ETHB 0x0C /* IDSEL = AD20 */
21 #define SLOT_MPCI 0x0D /* IDSEL = AD19 */
22 #define SLOT_NEC 0x0E /* IDSEL = AD18 */
28 #define GPIO_IRQ_NEC 3
29 #define GPIO_IRQ_ETHA 4
30 #define GPIO_IRQ_ETHB 5
31 #define GPIO_HSS0_DCD_N 6
32 #define GPIO_HSS1_DCD_N 7
33 #define GPIO_UART0_DCD 8
34 #define GPIO_UART1_DCD 9
35 #define GPIO_HSS0_CTS_N 10
36 #define GPIO_HSS1_CTS_N 11
37 #define GPIO_IRQ_MPCI 12
38 #define GPIO_HSS1_RTS_N 13
39 #define GPIO_HSS0_RTS_N 14
40 /* GPIO15 is not connected */
42 /* Control outputs from 74HC4094 */
43 #define CONTROL_HSS0_CLK_INT 0
44 #define CONTROL_HSS1_CLK_INT 1
45 #define CONTROL_HSS0_DTR_N 2
46 #define CONTROL_HSS1_DTR_N 3
48 #define CONTROL_AUTO_RESET 5
49 #define CONTROL_PCI_RESET_N 6
50 #define CONTROL_EEPROM_WC_N 7
52 /* offsets from start of flash ROM = 0x50000000 */
53 #define CFG_ETH0_ADDRESS 0x40 /* 6 bytes */
54 #define CFG_ETH1_ADDRESS 0x46 /* 6 bytes */
55 #define CFG_REV 0x4C /* u32 */
56 #define CFG_SDRAM_SIZE 0x50 /* u32 */
57 #define CFG_SDRAM_CONF 0x54 /* u32 */
58 #define CFG_SDRAM_MODE 0x58 /* u32 */
59 #define CFG_SDRAM_REFRESH 0x5C /* u32 */
61 #define CFG_HW_BITS 0x60 /* u32 */
62 #define CFG_HW_USB_PORTS 0x00000007 /* 0 = no NEC chip, 1-5 = ports # */
63 #define CFG_HW_HAS_PCI_SLOT 0x00000008
64 #define CFG_HW_HAS_ETH0 0x00000010
65 #define CFG_HW_HAS_ETH1 0x00000020
66 #define CFG_HW_HAS_HSS0 0x00000040
67 #define CFG_HW_HAS_HSS1 0x00000080
68 #define CFG_HW_HAS_UART0 0x00000100
69 #define CFG_HW_HAS_UART1 0x00000200
70 #define CFG_HW_HAS_EEPROM 0x00000400
72 #define FLASH_CMD_READ_ARRAY 0xFF
73 #define FLASH_CMD_READ_ID 0x90
74 #define FLASH_SER_OFF 0x102 /* 0x81 in 16-bit mode */
76 static u32 hw_bits
= 0xFFFFFFFD; /* assume all hardware present */;
77 static u8 control_value
;
79 static void set_scl(u8 value
)
81 gpio_line_set(GPIO_SCL
, !!value
);
85 static void set_sda(u8 value
)
87 gpio_line_set(GPIO_SDA
, !!value
);
91 static void set_str(u8 value
)
93 gpio_line_set(GPIO_STR
, !!value
);
97 static inline void set_control(int line
, int value
)
100 control_value
|= (1 << line
);
102 control_value
&= ~(1 << line
);
106 static void output_control(void)
110 gpio_line_config(GPIO_SCL
, IXP4XX_GPIO_OUT
);
111 gpio_line_config(GPIO_SDA
, IXP4XX_GPIO_OUT
);
113 for (i
= 0; i
< 8; i
++) {
115 set_sda(control_value
& (0x80 >> i
)); /* MSB first */
116 set_scl(1); /* active edge */
123 set_sda(1); /* Be ready for START */
128 static void (*set_carrier_cb_tab
[2])(void *pdev
, int carrier
);
130 static int hss_set_clock(int port
, unsigned int clock_type
)
132 int ctrl_int
= port
? CONTROL_HSS1_CLK_INT
: CONTROL_HSS0_CLK_INT
;
134 switch (clock_type
) {
137 set_control(ctrl_int
, 0);
142 set_control(ctrl_int
, 1);
151 static irqreturn_t
hss_dcd_irq(int irq
, void *pdev
)
153 int i
, port
= (irq
== IXP4XX_GPIO_IRQ(GPIO_HSS1_DCD_N
));
154 gpio_line_get(port
? GPIO_HSS1_DCD_N
: GPIO_HSS0_DCD_N
, &i
);
155 set_carrier_cb_tab
[port
](pdev
, !i
);
160 static int hss_open(int port
, void *pdev
,
161 void (*set_carrier_cb
)(void *pdev
, int carrier
))
166 irq
= IXP4XX_GPIO_IRQ(GPIO_HSS0_DCD_N
);
168 irq
= IXP4XX_GPIO_IRQ(GPIO_HSS1_DCD_N
);
170 gpio_line_get(port
? GPIO_HSS1_DCD_N
: GPIO_HSS0_DCD_N
, &i
);
171 set_carrier_cb(pdev
, !i
);
173 set_carrier_cb_tab
[!!port
] = set_carrier_cb
;
175 if ((i
= request_irq(irq
, hss_dcd_irq
, 0, "IXP4xx HSS", pdev
)) != 0) {
176 printk(KERN_ERR
"ixp4xx_hss: failed to request IRQ%i (%i)\n",
181 set_control(port
? CONTROL_HSS1_DTR_N
: CONTROL_HSS0_DTR_N
, 0);
183 gpio_line_set(port
? GPIO_HSS1_RTS_N
: GPIO_HSS0_RTS_N
, 0);
187 static void hss_close(int port
, void *pdev
)
189 free_irq(port
? IXP4XX_GPIO_IRQ(GPIO_HSS1_DCD_N
) :
190 IXP4XX_GPIO_IRQ(GPIO_HSS0_DCD_N
), pdev
);
191 set_carrier_cb_tab
[!!port
] = NULL
; /* catch bugs */
193 set_control(port
? CONTROL_HSS1_DTR_N
: CONTROL_HSS0_DTR_N
, 1);
195 gpio_line_set(port
? GPIO_HSS1_RTS_N
: GPIO_HSS0_RTS_N
, 1);
200 static struct flash_platform_data flash_data
= {
201 .map_name
= "cfi_probe",
205 static struct resource flash_resource
= {
206 .flags
= IORESOURCE_MEM
,
209 static struct platform_device device_flash
= {
210 .name
= "IXP4XX-Flash",
212 .dev
= { .platform_data
= &flash_data
},
214 .resource
= &flash_resource
,
219 static struct i2c_gpio_platform_data i2c_data
= {
224 static struct platform_device device_i2c
= {
227 .dev
= { .platform_data
= &i2c_data
},
231 /* IXP425 2 UART ports */
232 static struct resource uart_resources
[] = {
234 .start
= IXP4XX_UART1_BASE_PHYS
,
235 .end
= IXP4XX_UART1_BASE_PHYS
+ 0x0fff,
236 .flags
= IORESOURCE_MEM
,
239 .start
= IXP4XX_UART2_BASE_PHYS
,
240 .end
= IXP4XX_UART2_BASE_PHYS
+ 0x0fff,
241 .flags
= IORESOURCE_MEM
,
245 static struct plat_serial8250_port uart_data
[] = {
247 .mapbase
= IXP4XX_UART1_BASE_PHYS
,
248 .membase
= (char __iomem
*)IXP4XX_UART1_BASE_VIRT
+
250 .irq
= IRQ_IXP4XX_UART1
,
251 .flags
= UPF_BOOT_AUTOCONF
| UPF_SKIP_TEST
,
254 .uartclk
= IXP4XX_UART_XTAL
,
257 .mapbase
= IXP4XX_UART2_BASE_PHYS
,
258 .membase
= (char __iomem
*)IXP4XX_UART2_BASE_VIRT
+
260 .irq
= IRQ_IXP4XX_UART2
,
261 .flags
= UPF_BOOT_AUTOCONF
| UPF_SKIP_TEST
,
264 .uartclk
= IXP4XX_UART_XTAL
,
269 static struct platform_device device_uarts
= {
270 .name
= "serial8250",
271 .id
= PLAT8250_DEV_PLATFORM
,
272 .dev
.platform_data
= uart_data
,
274 .resource
= uart_resources
,
278 /* Built-in 10/100 Ethernet MAC interfaces */
279 static struct eth_plat_info eth_plat
[] = {
291 static struct platform_device device_eth_tab
[] = {
293 .name
= "ixp4xx_eth",
294 .id
= IXP4XX_ETH_NPEB
,
295 .dev
.platform_data
= eth_plat
,
297 .name
= "ixp4xx_eth",
298 .id
= IXP4XX_ETH_NPEC
,
299 .dev
.platform_data
= eth_plat
+ 1,
304 /* IXP425 2 synchronous serial ports */
305 static struct hss_plat_info hss_plat
[] = {
307 .set_clock
= hss_set_clock
,
312 .set_clock
= hss_set_clock
,
319 static struct platform_device device_hss_tab
[] = {
321 .name
= "ixp4xx_hss",
323 .dev
.platform_data
= hss_plat
,
325 .name
= "ixp4xx_hss",
327 .dev
.platform_data
= hss_plat
+ 1,
332 static struct platform_device
*device_tab
[6] __initdata
= {
333 &device_flash
, /* index 0 */
336 static inline u8 __init
flash_readb(u8 __iomem
*flash
, u32 addr
)
339 return __raw_readb(flash
+ addr
);
341 return __raw_readb(flash
+ (addr
^ 3));
345 static inline u16 __init
flash_readw(u8 __iomem
*flash
, u32 addr
)
348 return __raw_readw(flash
+ addr
);
350 return __raw_readw(flash
+ (addr
^ 2));
354 static void __init
gmlr_init(void)
357 int i
, devices
= 1; /* flash */
361 if ((flash
= ioremap(IXP4XX_EXP_BUS_BASE_PHYS
, 0x80)) == NULL
)
362 printk(KERN_ERR
"goramo-mlr: unable to access system"
363 " configuration data\n");
365 system_rev
= __raw_readl(flash
+ CFG_REV
);
366 hw_bits
= __raw_readl(flash
+ CFG_HW_BITS
);
368 for (i
= 0; i
< ETH_ALEN
; i
++) {
369 eth_plat
[0].hwaddr
[i
] =
370 flash_readb(flash
, CFG_ETH0_ADDRESS
+ i
);
371 eth_plat
[1].hwaddr
[i
] =
372 flash_readb(flash
, CFG_ETH1_ADDRESS
+ i
);
375 __raw_writew(FLASH_CMD_READ_ID
, flash
);
376 system_serial_high
= flash_readw(flash
, FLASH_SER_OFF
);
377 system_serial_high
<<= 16;
378 system_serial_high
|= flash_readw(flash
, FLASH_SER_OFF
+ 2);
379 system_serial_low
= flash_readw(flash
, FLASH_SER_OFF
+ 4);
380 system_serial_low
<<= 16;
381 system_serial_low
|= flash_readw(flash
, FLASH_SER_OFF
+ 6);
382 __raw_writew(FLASH_CMD_READ_ARRAY
, flash
);
387 switch (hw_bits
& (CFG_HW_HAS_UART0
| CFG_HW_HAS_UART1
)) {
388 case CFG_HW_HAS_UART0
:
389 memset(&uart_data
[1], 0, sizeof(uart_data
[1]));
390 device_uarts
.num_resources
= 1;
393 case CFG_HW_HAS_UART1
:
394 device_uarts
.dev
.platform_data
= &uart_data
[1];
395 device_uarts
.resource
= &uart_resources
[1];
396 device_uarts
.num_resources
= 1;
399 if (hw_bits
& (CFG_HW_HAS_UART0
| CFG_HW_HAS_UART1
))
400 device_tab
[devices
++] = &device_uarts
; /* max index 1 */
402 if (hw_bits
& CFG_HW_HAS_ETH0
)
403 device_tab
[devices
++] = &device_eth_tab
[0]; /* max index 2 */
404 if (hw_bits
& CFG_HW_HAS_ETH1
)
405 device_tab
[devices
++] = &device_eth_tab
[1]; /* max index 3 */
407 if (hw_bits
& CFG_HW_HAS_HSS0
)
408 device_tab
[devices
++] = &device_hss_tab
[0]; /* max index 4 */
409 if (hw_bits
& CFG_HW_HAS_HSS1
)
410 device_tab
[devices
++] = &device_hss_tab
[1]; /* max index 5 */
412 if (hw_bits
& CFG_HW_HAS_EEPROM
)
413 device_tab
[devices
++] = &device_i2c
; /* max index 6 */
415 gpio_line_config(GPIO_SCL
, IXP4XX_GPIO_OUT
);
416 gpio_line_config(GPIO_SDA
, IXP4XX_GPIO_OUT
);
417 gpio_line_config(GPIO_STR
, IXP4XX_GPIO_OUT
);
418 gpio_line_config(GPIO_HSS0_RTS_N
, IXP4XX_GPIO_OUT
);
419 gpio_line_config(GPIO_HSS1_RTS_N
, IXP4XX_GPIO_OUT
);
420 gpio_line_config(GPIO_HSS0_DCD_N
, IXP4XX_GPIO_IN
);
421 gpio_line_config(GPIO_HSS1_DCD_N
, IXP4XX_GPIO_IN
);
422 irq_set_irq_type(IXP4XX_GPIO_IRQ(GPIO_HSS0_DCD_N
), IRQ_TYPE_EDGE_BOTH
);
423 irq_set_irq_type(IXP4XX_GPIO_IRQ(GPIO_HSS1_DCD_N
), IRQ_TYPE_EDGE_BOTH
);
425 set_control(CONTROL_HSS0_DTR_N
, 1);
426 set_control(CONTROL_HSS1_DTR_N
, 1);
427 set_control(CONTROL_EEPROM_WC_N
, 1);
428 set_control(CONTROL_PCI_RESET_N
, 1);
431 msleep(1); /* Wait for PCI devices to initialize */
433 flash_resource
.start
= IXP4XX_EXP_BUS_BASE(0);
434 flash_resource
.end
= IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size
- 1;
436 platform_add_devices(device_tab
, devices
);
441 static void __init
gmlr_pci_preinit(void)
443 irq_set_irq_type(IXP4XX_GPIO_IRQ(GPIO_IRQ_ETHA
), IRQ_TYPE_LEVEL_LOW
);
444 irq_set_irq_type(IXP4XX_GPIO_IRQ(GPIO_IRQ_ETHB
), IRQ_TYPE_LEVEL_LOW
);
445 irq_set_irq_type(IXP4XX_GPIO_IRQ(GPIO_IRQ_NEC
), IRQ_TYPE_LEVEL_LOW
);
446 irq_set_irq_type(IXP4XX_GPIO_IRQ(GPIO_IRQ_MPCI
), IRQ_TYPE_LEVEL_LOW
);
447 ixp4xx_pci_preinit();
450 static void __init
gmlr_pci_postinit(void)
452 if ((hw_bits
& CFG_HW_USB_PORTS
) >= 2 &&
453 (hw_bits
& CFG_HW_USB_PORTS
) < 5) {
454 /* need to adjust number of USB ports on NEC chip */
455 u32 value
, addr
= BIT(32 - SLOT_NEC
) | 0xE0;
456 if (!ixp4xx_pci_read(addr
, NP_CMD_CONFIGREAD
, &value
)) {
458 value
|= (hw_bits
& CFG_HW_USB_PORTS
);
459 ixp4xx_pci_write(addr
, NP_CMD_CONFIGWRITE
, value
);
464 static int __init
gmlr_map_irq(const struct pci_dev
*dev
, u8 slot
, u8 pin
)
467 case SLOT_ETHA
: return IXP4XX_GPIO_IRQ(GPIO_IRQ_ETHA
);
468 case SLOT_ETHB
: return IXP4XX_GPIO_IRQ(GPIO_IRQ_ETHB
);
469 case SLOT_NEC
: return IXP4XX_GPIO_IRQ(GPIO_IRQ_NEC
);
470 default: return IXP4XX_GPIO_IRQ(GPIO_IRQ_MPCI
);
474 static struct hw_pci gmlr_hw_pci __initdata
= {
477 .preinit
= gmlr_pci_preinit
,
478 .postinit
= gmlr_pci_postinit
,
479 .setup
= ixp4xx_setup
,
480 .map_irq
= gmlr_map_irq
,
483 static int __init
gmlr_pci_init(void)
485 if (machine_is_goramo_mlr() &&
486 (hw_bits
& (CFG_HW_USB_PORTS
| CFG_HW_HAS_PCI_SLOT
)))
487 pci_common_init(&gmlr_hw_pci
);
491 subsys_initcall(gmlr_pci_init
);
492 #endif /* CONFIG_PCI */
495 MACHINE_START(GORAMO_MLR
, "MultiLink")
496 /* Maintainer: Krzysztof Halasa */
497 .map_io
= ixp4xx_map_io
,
498 .init_early
= ixp4xx_init_early
,
499 .init_irq
= ixp4xx_init_irq
,
500 .timer
= &ixp4xx_timer
,
501 .atag_offset
= 0x100,
502 .init_machine
= gmlr_init
,
503 #if defined(CONFIG_PCI)
504 .dma_zone_size
= SZ_64M
,
506 .restart
= ixp4xx_restart
,