puv3-nb0916.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. #include <linux/init.h>
  14. #include <linux/device.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/mtd/physmap.h>
  17. #include <linux/io.h>
  18. #include <linux/reboot.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/i2c.h>
  21. #include <linux/pwm_backlight.h>
  22. #include <linux/gpio.h>
  23. #include <linux/gpio_keys.h>
  24. #include <linux/input.h>
  25. #include <mach/hardware.h>
  26. static struct physmap_flash_data physmap_flash_data = {
  27. .width = 1,
  28. };
  29. static struct resource physmap_flash_resource = {
  30. .start = 0xFFF80000,
  31. .end = 0xFFFFFFFF,
  32. .flags = IORESOURCE_MEM,
  33. };
  34. static struct resource puv3_i2c_resources[] = {
  35. [0] = {
  36. .start = io_v2p(PKUNITY_I2C_BASE),
  37. .end = io_v2p(PKUNITY_I2C_BASE) + 0xff,
  38. .flags = IORESOURCE_MEM,
  39. },
  40. [1] = {
  41. .start = IRQ_I2C,
  42. .end = IRQ_I2C,
  43. .flags = IORESOURCE_IRQ,
  44. }
  45. };
  46. static struct platform_pwm_backlight_data nb0916_backlight_data = {
  47. .pwm_id = 0,
  48. .max_brightness = 100,
  49. .dft_brightness = 100,
  50. .pwm_period_ns = 70 * 1024,
  51. };
  52. static struct gpio_keys_button nb0916_gpio_keys[] = {
  53. {
  54. .type = EV_KEY,
  55. .code = KEY_POWER,
  56. .gpio = GPI_SOFF_REQ,
  57. .desc = "Power Button",
  58. .wakeup = 1,
  59. .active_low = 1,
  60. },
  61. {
  62. .type = EV_KEY,
  63. .code = BTN_TOUCH,
  64. .gpio = GPI_BTN_TOUCH,
  65. .desc = "Touchpad Button",
  66. .wakeup = 1,
  67. .active_low = 1,
  68. },
  69. };
  70. static struct gpio_keys_platform_data nb0916_gpio_button_data = {
  71. .buttons = nb0916_gpio_keys,
  72. .nbuttons = ARRAY_SIZE(nb0916_gpio_keys),
  73. };
  74. static irqreturn_t nb0916_lcdcaseoff_handler(int irq, void *dev_id)
  75. {
  76. if (gpio_get_value(GPI_LCD_CASE_OFF))
  77. gpio_set_value(GPO_LCD_EN, 1);
  78. else
  79. gpio_set_value(GPO_LCD_EN, 0);
  80. return IRQ_HANDLED;
  81. }
  82. static irqreturn_t nb0916_overheat_handler(int irq, void *dev_id)
  83. {
  84. machine_halt();
  85. /* SYSTEM HALT, NO RETURN */
  86. return IRQ_HANDLED;
  87. }
  88. static struct i2c_board_info __initdata puv3_i2c_devices[] = {
  89. { I2C_BOARD_INFO("lm75", I2C_TAR_THERMAL), },
  90. { I2C_BOARD_INFO("bq27200", I2C_TAR_PWIC), },
  91. { I2C_BOARD_INFO("24c02", I2C_TAR_EEPROM), },
  92. };
  93. int __init mach_nb0916_init(void)
  94. {
  95. i2c_register_board_info(0, puv3_i2c_devices,
  96. ARRAY_SIZE(puv3_i2c_devices));
  97. platform_device_register_simple("PKUnity-v3-I2C", -1,
  98. puv3_i2c_resources, ARRAY_SIZE(puv3_i2c_resources));
  99. platform_device_register_data(&platform_bus, "pwm-backlight", -1,
  100. &nb0916_backlight_data, sizeof(nb0916_backlight_data));
  101. platform_device_register_data(&platform_bus, "gpio-keys", -1,
  102. &nb0916_gpio_button_data, sizeof(nb0916_gpio_button_data));
  103. platform_device_register_resndata(&platform_bus, "physmap-flash", -1,
  104. &physmap_flash_resource, 1,
  105. &physmap_flash_data, sizeof(physmap_flash_data));
  106. if (request_irq(gpio_to_irq(GPI_LCD_CASE_OFF),
  107. &nb0916_lcdcaseoff_handler,
  108. IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
  109. "NB0916 lcd case off", NULL) < 0) {
  110. printk(KERN_DEBUG "LCD-Case-OFF IRQ %d not available\n",
  111. gpio_to_irq(GPI_LCD_CASE_OFF));
  112. }
  113. if (request_irq(gpio_to_irq(GPI_OTP_INT), &nb0916_overheat_handler,
  114. IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
  115. "NB0916 overheating protection", NULL) < 0) {
  116. printk(KERN_DEBUG "Overheating Protection IRQ %d not available\n",
  117. gpio_to_irq(GPI_OTP_INT));
  118. }
  119. return 0;
  120. }
  121. subsys_initcall_sync(mach_nb0916_init);