puv3-nb0916.c 3.6 KB

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