ALSA: hda - Don't access stereo amps for mono channel widgets
[linux-drm-fsl-dcu.git] / arch / arm / mach-pxa / idp.c
1 /*
2  *  linux/arch/arm/mach-pxa/idp.c
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License version 2 as
6  *  published by the Free Software Foundation.
7  *
8  *  Copyright (c) 2001 Cliff Brake, Accelent Systems Inc.
9  *
10  *  2001-09-13: Cliff Brake <cbrake@accelent.com>
11  *              Initial code
12  *
13  *  2005-02-15: Cliff Brake <cliff.brake@gmail.com>
14  *              <http://www.vibren.com> <http://bec-systems.com>
15  *              Updated for 2.6 kernel
16  *
17  */
18
19 #include <linux/init.h>
20 #include <linux/interrupt.h>
21 #include <linux/irq.h>
22 #include <linux/platform_device.h>
23 #include <linux/fb.h>
24
25 #include <asm/setup.h>
26 #include <asm/memory.h>
27 #include <asm/mach-types.h>
28 #include <mach/hardware.h>
29 #include <asm/irq.h>
30
31 #include <asm/mach/arch.h>
32 #include <asm/mach/map.h>
33
34 #include <mach/pxa25x.h>
35 #include <mach/idp.h>
36 #include <linux/platform_data/video-pxafb.h>
37 #include <mach/bitfield.h>
38 #include <linux/platform_data/mmc-pxamci.h>
39
40 #include "generic.h"
41 #include "devices.h"
42
43 /* TODO:
44  * - add pxa2xx_audio_ops_t device structure
45  * - Ethernet interrupt
46  */
47
48 static unsigned long idp_pin_config[] __initdata = {
49         /* LCD */
50         GPIOxx_LCD_DSTN_16BPP,
51
52         /* BTUART */
53         GPIO42_BTUART_RXD,
54         GPIO43_BTUART_TXD,
55         GPIO44_BTUART_CTS,
56         GPIO45_BTUART_RTS,
57
58         /* STUART */
59         GPIO46_STUART_RXD,
60         GPIO47_STUART_TXD,
61
62         /* MMC */
63         GPIO6_MMC_CLK,
64         GPIO8_MMC_CS0,
65
66         /* Ethernet */
67         GPIO33_nCS_5,   /* Ethernet CS */
68         GPIO4_GPIO,     /* Ethernet IRQ */
69 };
70
71 static struct resource smc91x_resources[] = {
72         [0] = {
73                 .start  = (IDP_ETH_PHYS + 0x300),
74                 .end    = (IDP_ETH_PHYS + 0xfffff),
75                 .flags  = IORESOURCE_MEM,
76         },
77         [1] = {
78                 .start  = PXA_GPIO_TO_IRQ(4),
79                 .end    = PXA_GPIO_TO_IRQ(4),
80                 .flags  = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
81         }
82 };
83
84 static struct smc91x_platdata smc91x_platdata = {
85         .flags = SMC91X_USE_32BIT | SMC91X_USE_DMA | SMC91X_NOWAIT,
86 };
87
88 static struct platform_device smc91x_device = {
89         .name           = "smc91x",
90         .id             = 0,
91         .num_resources  = ARRAY_SIZE(smc91x_resources),
92         .resource       = smc91x_resources,
93         .dev.platform_data = &smc91x_platdata,
94 };
95
96 static void idp_backlight_power(int on)
97 {
98         if (on) {
99                 IDP_CPLD_LCD |= (1<<1);
100         } else {
101                 IDP_CPLD_LCD &= ~(1<<1);
102         }
103 }
104
105 static void idp_vlcd(int on)
106 {
107         if (on) {
108                 IDP_CPLD_LCD |= (1<<2);
109         } else {
110                 IDP_CPLD_LCD &= ~(1<<2);
111         }
112 }
113
114 static void idp_lcd_power(int on, struct fb_var_screeninfo *var)
115 {
116         if (on) {
117                 IDP_CPLD_LCD |= (1<<0);
118         } else {
119                 IDP_CPLD_LCD &= ~(1<<0);
120         }
121
122         /* call idp_vlcd for now as core driver does not support
123          * both power and vlcd hooks.  Note, this is not technically
124          * the correct sequence, but seems to work.  Disclaimer:
125          * this may eventually damage the display.
126          */
127
128         idp_vlcd(on);
129 }
130
131 static struct pxafb_mode_info sharp_lm8v31_mode = {
132         .pixclock       = 270000,
133         .xres           = 640,
134         .yres           = 480,
135         .bpp            = 16,
136         .hsync_len      = 1,
137         .left_margin    = 3,
138         .right_margin   = 3,
139         .vsync_len      = 1,
140         .upper_margin   = 0,
141         .lower_margin   = 0,
142         .sync           = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
143         .cmap_greyscale = 0,
144 };
145
146 static struct pxafb_mach_info sharp_lm8v31 = {
147         .modes          = &sharp_lm8v31_mode,
148         .num_modes      = 1,
149         .cmap_inverse   = 0,
150         .cmap_static    = 0,
151         .lcd_conn       = LCD_COLOR_DSTN_16BPP | LCD_PCLK_EDGE_FALL |
152                           LCD_AC_BIAS_FREQ(255),
153         .pxafb_backlight_power = &idp_backlight_power,
154         .pxafb_lcd_power = &idp_lcd_power
155 };
156
157 static struct pxamci_platform_data idp_mci_platform_data = {
158         .ocr_mask               = MMC_VDD_32_33|MMC_VDD_33_34,
159         .gpio_card_detect       = -1,
160         .gpio_card_ro           = -1,
161         .gpio_power             = -1,
162 };
163
164 static void __init idp_init(void)
165 {
166         printk("idp_init()\n");
167
168         pxa2xx_mfp_config(ARRAY_AND_SIZE(idp_pin_config));
169         pxa_set_ffuart_info(NULL);
170         pxa_set_btuart_info(NULL);
171         pxa_set_stuart_info(NULL);
172
173         platform_device_register(&smc91x_device);
174         //platform_device_register(&mst_audio_device);
175         pxa_set_fb_info(NULL, &sharp_lm8v31);
176         pxa_set_mci_info(&idp_mci_platform_data);
177 }
178
179 static struct map_desc idp_io_desc[] __initdata = {
180         {
181                 .virtual        =  IDP_COREVOLT_VIRT,
182                 .pfn            = __phys_to_pfn(IDP_COREVOLT_PHYS),
183                 .length         = IDP_COREVOLT_SIZE,
184                 .type           = MT_DEVICE
185         }, {
186                 .virtual        =  IDP_CPLD_VIRT,
187                 .pfn            = __phys_to_pfn(IDP_CPLD_PHYS),
188                 .length         = IDP_CPLD_SIZE,
189                 .type           = MT_DEVICE
190         }
191 };
192
193 static void __init idp_map_io(void)
194 {
195         pxa25x_map_io();
196         iotable_init(idp_io_desc, ARRAY_SIZE(idp_io_desc));
197 }
198
199 /* LEDs */
200 #if defined(CONFIG_NEW_LEDS) && defined(CONFIG_LEDS_CLASS)
201 struct idp_led {
202         struct led_classdev     cdev;
203         u8                      mask;
204 };
205
206 /*
207  * The triggers lines up below will only be used if the
208  * LED triggers are compiled in.
209  */
210 static const struct {
211         const char *name;
212         const char *trigger;
213 } idp_leds[] = {
214         { "idp:green", "heartbeat", },
215         { "idp:red", "cpu0", },
216 };
217
218 static void idp_led_set(struct led_classdev *cdev,
219                 enum led_brightness b)
220 {
221         struct idp_led *led = container_of(cdev,
222                         struct idp_led, cdev);
223         u32 reg = IDP_CPLD_LED_CONTROL;
224
225         if (b != LED_OFF)
226                 reg &= ~led->mask;
227         else
228                 reg |= led->mask;
229
230         IDP_CPLD_LED_CONTROL = reg;
231 }
232
233 static enum led_brightness idp_led_get(struct led_classdev *cdev)
234 {
235         struct idp_led *led = container_of(cdev,
236                         struct idp_led, cdev);
237
238         return (IDP_CPLD_LED_CONTROL & led->mask) ? LED_OFF : LED_FULL;
239 }
240
241 static int __init idp_leds_init(void)
242 {
243         int i;
244
245         if (!machine_is_pxa_idp())
246                 return -ENODEV;
247
248         for (i = 0; i < ARRAY_SIZE(idp_leds); i++) {
249                 struct idp_led *led;
250
251                 led = kzalloc(sizeof(*led), GFP_KERNEL);
252                 if (!led)
253                         break;
254
255                 led->cdev.name = idp_leds[i].name;
256                 led->cdev.brightness_set = idp_led_set;
257                 led->cdev.brightness_get = idp_led_get;
258                 led->cdev.default_trigger = idp_leds[i].trigger;
259
260                 if (i == 0)
261                         led->mask = IDP_HB_LED;
262                 else
263                         led->mask = IDP_BUSY_LED;
264
265                 if (led_classdev_register(NULL, &led->cdev) < 0) {
266                         kfree(led);
267                         break;
268                 }
269         }
270
271         return 0;
272 }
273
274 /*
275  * Since we may have triggers on any subsystem, defer registration
276  * until after subsystem_init.
277  */
278 fs_initcall(idp_leds_init);
279 #endif
280
281 MACHINE_START(PXA_IDP, "Vibren PXA255 IDP")
282         /* Maintainer: Vibren Technologies */
283         .map_io         = idp_map_io,
284         .nr_irqs        = PXA_NR_IRQS,
285         .init_irq       = pxa25x_init_irq,
286         .handle_irq     = pxa25x_handle_irq,
287         .init_time      = pxa_timer_init,
288         .init_machine   = idp_init,
289         .restart        = pxa_restart,
290 MACHINE_END