]> git.karo-electronics.de Git - karo-tx-linux.git/blob - arch/unicore32/kernel/puv3-nb0916.c
181108b8ecce766d0102b9e12ac070e6510337b0
[karo-tx-linux.git] / arch / unicore32 / kernel / puv3-nb0916.c
1 /*
2  * linux/arch/unicore32/kernel/puv3-nb0916.c
3  *
4  * Code specific to PKUnity SoC and UniCore ISA
5  *
6  *      Maintained by GUAN Xue-tao <gxt@mprc.pku.edu.cn>
7  *      Copyright (C) 2001-2010 Guan Xuetao
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License version 2 as
11  * published by the Free Software Foundation.
12  */
13
14 #include <linux/init.h>
15 #include <linux/device.h>
16 #include <linux/platform_device.h>
17 #include <linux/mtd/physmap.h>
18 #include <linux/io.h>
19 #include <linux/reboot.h>
20 #include <linux/interrupt.h>
21 #include <linux/i2c.h>
22 #include <linux/pwm_backlight.h>
23 #include <linux/gpio.h>
24 #include <linux/gpio_keys.h>
25 #include <linux/input.h>
26
27 #include <mach/hardware.h>
28
29 static struct physmap_flash_data physmap_flash_data = {
30         .width          = 1,
31 };
32
33 static struct resource physmap_flash_resource = {
34         .start          = 0xFFF80000,
35         .end            = 0xFFFFFFFF,
36         .flags          = IORESOURCE_MEM,
37 };
38
39 static struct resource puv3_i2c_resources[] = {
40         [0] = {
41                 .start = io_v2p(PKUNITY_I2C_BASE),
42                 .end   = io_v2p(PKUNITY_I2C_BASE) + 0xff,
43                 .flags = IORESOURCE_MEM,
44         },
45         [1] = {
46                 .start = IRQ_I2C,
47                 .end   = IRQ_I2C,
48                 .flags = IORESOURCE_IRQ,
49         }
50 };
51
52 static struct platform_pwm_backlight_data nb0916_backlight_data = {
53         .pwm_id         = 0,
54         .max_brightness = 100,
55         .dft_brightness = 100,
56         .pwm_period_ns  = 70 * 1024,
57 };
58
59 static struct gpio_keys_button nb0916_gpio_keys[] = {
60         {
61                 .type   = EV_KEY,
62                 .code   = KEY_POWER,
63                 .gpio   = GPI_SOFF_REQ,
64                 .desc   = "Power Button",
65                 .wakeup = 1,
66                 .active_low = 1,
67         },
68         {
69                 .type   = EV_KEY,
70                 .code   = BTN_TOUCH,
71                 .gpio   = GPI_BTN_TOUCH,
72                 .desc   = "Touchpad Button",
73                 .wakeup = 1,
74                 .active_low = 1,
75         },
76 };
77
78 static struct gpio_keys_platform_data nb0916_gpio_button_data = {
79         .buttons        = nb0916_gpio_keys,
80         .nbuttons       = ARRAY_SIZE(nb0916_gpio_keys),
81 };
82
83 static irqreturn_t nb0916_lcdcaseoff_handler(int irq, void *dev_id)
84 {
85         if (gpio_get_value(GPI_LCD_CASE_OFF))
86                 gpio_set_value(GPO_LCD_EN, 1);
87         else
88                 gpio_set_value(GPO_LCD_EN, 0);
89
90         return IRQ_HANDLED;
91 }
92
93 static irqreturn_t nb0916_overheat_handler(int irq, void *dev_id)
94 {
95         machine_halt();
96         /* SYSTEM HALT, NO RETURN */
97         return IRQ_HANDLED;
98 }
99
100 static struct i2c_board_info __initdata puv3_i2c_devices[] = {
101         {       I2C_BOARD_INFO("lm75",          I2C_TAR_THERMAL),       },
102         {       I2C_BOARD_INFO("bq27200",       I2C_TAR_PWIC),          },
103         {       I2C_BOARD_INFO("24c02",         I2C_TAR_EEPROM),        },
104 };
105
106 int __init mach_nb0916_init(void)
107 {
108         i2c_register_board_info(0, puv3_i2c_devices,
109                         ARRAY_SIZE(puv3_i2c_devices));
110
111         platform_device_register_simple("PKUnity-v3-I2C", -1,
112                         puv3_i2c_resources, ARRAY_SIZE(puv3_i2c_resources));
113
114         platform_device_register_data(&platform_bus, "pwm-backlight", -1,
115                         &nb0916_backlight_data, sizeof(nb0916_backlight_data));
116
117         platform_device_register_data(&platform_bus, "gpio-keys", -1,
118                         &nb0916_gpio_button_data, sizeof(nb0916_gpio_button_data));
119
120         platform_device_register_resndata(&platform_bus, "physmap-flash", -1,
121                         &physmap_flash_resource, 1,
122                         &physmap_flash_data, sizeof(physmap_flash_data));
123
124         if (request_irq(gpio_to_irq(GPI_LCD_CASE_OFF),
125                 &nb0916_lcdcaseoff_handler,
126                 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
127                 "NB0916 lcd case off", NULL) < 0) {
128
129                 printk(KERN_DEBUG "LCD-Case-OFF IRQ %d not available\n",
130                         gpio_to_irq(GPI_LCD_CASE_OFF));
131         }
132
133         if (request_irq(gpio_to_irq(GPI_OTP_INT), &nb0916_overheat_handler,
134                 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
135                 "NB0916 overheating protection", NULL) < 0) {
136
137                 printk(KERN_DEBUG "Overheating Protection IRQ %d not available\n",
138                         gpio_to_irq(GPI_OTP_INT));
139         }
140
141         return 0;
142 }
143
144 subsys_initcall_sync(mach_nb0916_init);