register a GPIO LEDs and buttons on the PB44 board
[librecmc/librecmc.git] / target / linux / ar71xx / files / arch / mips / ar71xx / mach-pb44.c
1 /*
2  *  Atheros PB44 board support
3  *
4  *  Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
5  *
6  *  This program is free software; you can redistribute it and/or modify it
7  *  under the terms of the GNU General Public License version 2 as published
8  *  by the Free Software Foundation.
9  */
10
11 #include <linux/init.h>
12 #include <linux/bitops.h>
13 #include <linux/input.h>
14 #include <linux/platform_device.h>
15 #include <linux/spi/spi.h>
16 #include <linux/spi/flash.h>
17 #include <linux/i2c.h>
18 #include <linux/i2c-gpio.h>
19 #include <linux/i2c/pcf857x.h>
20
21 #include <asm/mips_machine.h>
22 #include <asm/mach-ar71xx/ar71xx.h>
23 #include <asm/mach-ar71xx/pci.h>
24
25 #include "devices.h"
26
27 #define PB44_PCF8757_VSC7385_CS 0
28 #define PB44_PCF8757_STEREO_CS  1
29 #define PB44_PCF8757_SLIC_CS0   2
30 #define PB44_PCF8757_SLIC_TEST  3
31 #define PB44_PCF8757_SLIC_INT0  4
32 #define PB44_PCF8757_SLIC_INT1  5
33 #define PB44_PCF8757_SW_RESET   6
34 #define PB44_PCF8757_SW_JUMP    8
35 #define PB44_PCF8757_LED_JUMP1  9
36 #define PB44_PCF8757_LED_JUMP2  10
37 #define PB44_PCF8757_TP24       11
38 #define PB44_PCF8757_TP25       12
39 #define PB44_PCF8757_TP26       13
40 #define PB44_PCF8757_TP27       14
41 #define PB44_PCF8757_TP28       15
42
43 #define PB44_GPIO_I2C_SCL       0
44 #define PB44_GPIO_I2C_SDA       1
45
46 #define PB44_GPIO_EXP_BASE      16
47 #define PB44_GPIO_SW_RESET      (PB44_GPIO_EXP_BASE + PB44_PCF8757_SW_RESET)
48 #define PB44_GPIO_SW_JUMP       (PB44_GPIO_EXP_BASE + PB44_PCF8757_SW_JUMP)
49 #define PB44_GPIO_LED_JUMP1     (PB44_GPIO_EXP_BASE + PB44_PCF8757_LED_JUMP1)
50 #define PB44_GPIO_LED_JUMP2     (PB44_GPIO_EXP_BASE + PB44_PCF8757_LED_JUMP2)
51
52 static struct spi_board_info pb44_spi_info[] = {
53         {
54                 .bus_num        = 0,
55                 .chip_select    = 0,
56                 .max_speed_hz   = 25000000,
57                 .modalias       = "m25p80",
58         }
59 };
60
61 static struct ar71xx_pci_irq pb44_pci_irqs[] __initdata = {
62         {
63                 .slot   = 0,
64                 .pin    = 1,
65                 .irq    = AR71XX_PCI_IRQ_DEV0,
66         }, {
67                 .slot   = 1,
68                 .pin    = 1,
69                 .irq    = AR71XX_PCI_IRQ_DEV1,
70         }, {
71                 .slot   = 2,
72                 .pin    = 1,
73                 .irq    = AR71XX_PCI_IRQ_DEV2,
74         }
75 };
76
77 static struct i2c_gpio_platform_data pb44_i2c_gpio_data = {
78         .sda_pin        = PB44_GPIO_I2C_SDA,
79         .scl_pin        = PB44_GPIO_I2C_SCL,
80 };
81
82 static struct platform_device pb44_i2c_gpio_device = {
83         .name           = "i2c-gpio",
84         .id             = 0,
85         .dev = {
86                 .platform_data  = &pb44_i2c_gpio_data,
87         }
88 };
89
90 static struct pcf857x_platform_data pb44_pcf857x_data = {
91         .gpio_base      = PB44_GPIO_EXP_BASE,
92 };
93
94 static struct i2c_board_info pb44_i2c_board_info[] __initdata = {
95         {
96                 I2C_BOARD_INFO("pcf8575", 0x20),
97                 .platform_data  = &pb44_pcf857x_data,
98         },
99 };
100
101 static struct gpio_led pb44_leds_gpio[] __initdata = {
102         {
103                 .name           = "pb44:amber:jump1",
104                 .gpio           = PB44_GPIO_LED_JUMP1,
105                 .active_low     = 1,
106         }, {
107                 .name           = "pb44:green:jump2",
108                 .gpio           = PB44_GPIO_LED_JUMP2,
109                 .active_low     = 1,
110         },
111 };
112
113 static struct gpio_button pb44_gpio_buttons[] __initdata = {
114         {
115                 .desc           = "soft_reset",
116                 .type           = EV_KEY,
117                 .code           = BTN_0,
118                 .threshold      = 5,
119                 .gpio           = PB44_GPIO_SW_RESET,
120                 .active_low     = 1,
121         } , {
122                 .desc           = "jumpstart",
123                 .type           = EV_KEY,
124                 .code           = BTN_1,
125                 .threshold      = 5,
126                 .gpio           = PB44_GPIO_SW_JUMP,
127                 .active_low     = 1,
128         }
129 };
130
131 #define PB44_WAN_PHYMASK        BIT(0)
132 #define PB44_LAN_PHYMASK        0
133 #define PB44_MDIO_PHYMASK       (PB44_LAN_PHYMASK | PB44_WAN_PHYMASK)
134
135 static void __init pb44_init(void)
136 {
137         ar71xx_add_device_spi(NULL, pb44_spi_info,
138                                 ARRAY_SIZE(pb44_spi_info));
139
140         ar71xx_add_device_mdio(~PB44_MDIO_PHYMASK);
141
142         ar71xx_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
143         ar71xx_eth0_data.phy_mask = PB44_WAN_PHYMASK;
144
145         ar71xx_add_device_eth(0);
146
147         ar71xx_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_RGMII;
148         ar71xx_eth1_data.phy_mask = PB44_LAN_PHYMASK;
149         ar71xx_eth1_data.speed = SPEED_1000;
150         ar71xx_eth1_data.duplex = DUPLEX_FULL;
151
152         ar71xx_add_device_eth(1);
153
154         ar71xx_add_device_usb();
155
156         ar71xx_pci_init(ARRAY_SIZE(pb44_pci_irqs), pb44_pci_irqs);
157
158         i2c_register_board_info(0, pb44_i2c_board_info,
159                                 ARRAY_SIZE(pb44_i2c_board_info));
160
161         platform_device_register(&pb44_i2c_gpio_device);
162
163         ar71xx_add_device_leds_gpio(-1, ARRAY_SIZE(pb44_leds_gpio),
164                                     pb44_leds_gpio);
165
166         ar71xx_add_device_gpio_buttons(-1, 20, ARRAY_SIZE(pb44_gpio_buttons),
167                                        pb44_gpio_buttons);
168 }
169
170 MIPS_MACHINE(AR71XX_MACH_PB44, "Atheros PB44", pb44_init);