1 // SPDX-License-Identifier: GPL-2.0-only
3 * linux/arch/unicore32/kernel/puv3-nb0916.c
5 * Code specific to PKUnity SoC and UniCore ISA
7 * Maintained by GUAN Xue-tao <gxt@mprc.pku.edu.cn>
8 * Copyright (C) 2001-2010 Guan Xuetao
11 #include <linux/init.h>
12 #include <linux/device.h>
13 #include <linux/platform_device.h>
14 #include <linux/mtd/physmap.h>
16 #include <linux/reboot.h>
17 #include <linux/interrupt.h>
18 #include <linux/i2c.h>
19 #include <linux/pwm.h>
20 #include <linux/pwm_backlight.h>
21 #include <linux/gpio.h>
22 #include <linux/gpio_keys.h>
23 #include <linux/input.h>
25 #include <mach/hardware.h>
27 static struct physmap_flash_data physmap_flash_data
= {
31 static struct resource physmap_flash_resource
= {
34 .flags
= IORESOURCE_MEM
,
37 static struct resource puv3_i2c_resources
[] = {
39 .start
= io_v2p(PKUNITY_I2C_BASE
),
40 .end
= io_v2p(PKUNITY_I2C_BASE
) + 0xff,
41 .flags
= IORESOURCE_MEM
,
46 .flags
= IORESOURCE_IRQ
,
50 static struct pwm_lookup nb0916_pwm_lookup
[] = {
51 PWM_LOOKUP("PKUnity-v3-PWM", 0, "pwm-backlight", NULL
, 70 * 1024,
55 static struct platform_pwm_backlight_data nb0916_backlight_data
= {
56 .max_brightness
= 100,
57 .dft_brightness
= 100,
61 static struct gpio_keys_button nb0916_gpio_keys
[] = {
66 .desc
= "Power Button",
73 .gpio
= GPI_BTN_TOUCH
,
74 .desc
= "Touchpad Button",
80 static struct gpio_keys_platform_data nb0916_gpio_button_data
= {
81 .buttons
= nb0916_gpio_keys
,
82 .nbuttons
= ARRAY_SIZE(nb0916_gpio_keys
),
85 static irqreturn_t
nb0916_lcdcaseoff_handler(int irq
, void *dev_id
)
87 if (gpio_get_value(GPI_LCD_CASE_OFF
))
88 gpio_set_value(GPO_LCD_EN
, 1);
90 gpio_set_value(GPO_LCD_EN
, 0);
95 static irqreturn_t
nb0916_overheat_handler(int irq
, void *dev_id
)
98 /* SYSTEM HALT, NO RETURN */
102 static struct i2c_board_info __initdata puv3_i2c_devices
[] = {
103 { I2C_BOARD_INFO("lm75", I2C_TAR_THERMAL
), },
104 { I2C_BOARD_INFO("bq27200", I2C_TAR_PWIC
), },
105 { I2C_BOARD_INFO("24c02", I2C_TAR_EEPROM
), },
108 int __init
mach_nb0916_init(void)
110 i2c_register_board_info(0, puv3_i2c_devices
,
111 ARRAY_SIZE(puv3_i2c_devices
));
113 platform_device_register_simple("PKUnity-v3-I2C", -1,
114 puv3_i2c_resources
, ARRAY_SIZE(puv3_i2c_resources
));
116 pwm_add_table(nb0916_pwm_lookup
, ARRAY_SIZE(nb0916_pwm_lookup
));
118 platform_device_register_data(NULL
, "pwm-backlight", -1,
119 &nb0916_backlight_data
, sizeof(nb0916_backlight_data
));
121 platform_device_register_data(NULL
, "gpio-keys", -1,
122 &nb0916_gpio_button_data
, sizeof(nb0916_gpio_button_data
));
124 platform_device_register_resndata(NULL
, "physmap-flash", -1,
125 &physmap_flash_resource
, 1,
126 &physmap_flash_data
, sizeof(physmap_flash_data
));
128 if (request_irq(gpio_to_irq(GPI_LCD_CASE_OFF
),
129 &nb0916_lcdcaseoff_handler
,
130 IRQF_TRIGGER_RISING
| IRQF_TRIGGER_FALLING
,
131 "NB0916 lcd case off", NULL
) < 0) {
133 printk(KERN_DEBUG
"LCD-Case-OFF IRQ %d not available\n",
134 gpio_to_irq(GPI_LCD_CASE_OFF
));
137 if (request_irq(gpio_to_irq(GPI_OTP_INT
), &nb0916_overheat_handler
,
138 IRQF_TRIGGER_RISING
| IRQF_TRIGGER_FALLING
,
139 "NB0916 overheating protection", NULL
) < 0) {
141 printk(KERN_DEBUG
"Overheating Protection IRQ %d not available\n",
142 gpio_to_irq(GPI_OTP_INT
));
148 subsys_initcall_sync(mach_nb0916_init
);