puv3-nb0916.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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.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 pwm_lookup nb0916_pwm_lookup[] = {
  48. PWM_LOOKUP("PKUnity-v3-PWM", 0, "pwm-backlight", NULL, 70 * 1024,
  49. PWM_POLARITY_NORMAL),
  50. };
  51. static struct platform_pwm_backlight_data nb0916_backlight_data = {
  52. .max_brightness = 100,
  53. .dft_brightness = 100,
  54. .enable_gpio = -1,
  55. };
  56. static struct gpio_keys_button nb0916_gpio_keys[] = {
  57. {
  58. .type = EV_KEY,
  59. .code = KEY_POWER,
  60. .gpio = GPI_SOFF_REQ,
  61. .desc = "Power Button",
  62. .wakeup = 1,
  63. .active_low = 1,
  64. },
  65. {
  66. .type = EV_KEY,
  67. .code = BTN_TOUCH,
  68. .gpio = GPI_BTN_TOUCH,
  69. .desc = "Touchpad Button",
  70. .wakeup = 1,
  71. .active_low = 1,
  72. },
  73. };
  74. static struct gpio_keys_platform_data nb0916_gpio_button_data = {
  75. .buttons = nb0916_gpio_keys,
  76. .nbuttons = ARRAY_SIZE(nb0916_gpio_keys),
  77. };
  78. static irqreturn_t nb0916_lcdcaseoff_handler(int irq, void *dev_id)
  79. {
  80. if (gpio_get_value(GPI_LCD_CASE_OFF))
  81. gpio_set_value(GPO_LCD_EN, 1);
  82. else
  83. gpio_set_value(GPO_LCD_EN, 0);
  84. return IRQ_HANDLED;
  85. }
  86. static irqreturn_t nb0916_overheat_handler(int irq, void *dev_id)
  87. {
  88. machine_halt();
  89. /* SYSTEM HALT, NO RETURN */
  90. return IRQ_HANDLED;
  91. }
  92. static struct i2c_board_info __initdata puv3_i2c_devices[] = {
  93. { I2C_BOARD_INFO("lm75", I2C_TAR_THERMAL), },
  94. { I2C_BOARD_INFO("bq27200", I2C_TAR_PWIC), },
  95. { I2C_BOARD_INFO("24c02", I2C_TAR_EEPROM), },
  96. };
  97. int __init mach_nb0916_init(void)
  98. {
  99. i2c_register_board_info(0, puv3_i2c_devices,
  100. ARRAY_SIZE(puv3_i2c_devices));
  101. platform_device_register_simple("PKUnity-v3-I2C", -1,
  102. puv3_i2c_resources, ARRAY_SIZE(puv3_i2c_resources));
  103. pwm_add_table(nb0916_pwm_lookup, ARRAY_SIZE(nb0916_pwm_lookup));
  104. platform_device_register_data(NULL, "pwm-backlight", -1,
  105. &nb0916_backlight_data, sizeof(nb0916_backlight_data));
  106. platform_device_register_data(NULL, "gpio-keys", -1,
  107. &nb0916_gpio_button_data, sizeof(nb0916_gpio_button_data));
  108. platform_device_register_resndata(NULL, "physmap-flash", -1,
  109. &physmap_flash_resource, 1,
  110. &physmap_flash_data, sizeof(physmap_flash_data));
  111. if (request_irq(gpio_to_irq(GPI_LCD_CASE_OFF),
  112. &nb0916_lcdcaseoff_handler,
  113. IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
  114. "NB0916 lcd case off", NULL) < 0) {
  115. printk(KERN_DEBUG "LCD-Case-OFF IRQ %d not available\n",
  116. gpio_to_irq(GPI_LCD_CASE_OFF));
  117. }
  118. if (request_irq(gpio_to_irq(GPI_OTP_INT), &nb0916_overheat_handler,
  119. IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
  120. "NB0916 overheating protection", NULL) < 0) {
  121. printk(KERN_DEBUG "Overheating Protection IRQ %d not available\n",
  122. gpio_to_irq(GPI_OTP_INT));
  123. }
  124. return 0;
  125. }
  126. subsys_initcall_sync(mach_nb0916_init);