gpio.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * linux/arch/unicore32/kernel/gpio.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. /* in FPGA, no GPIO support */
  14. #include <linux/init.h>
  15. #include <linux/module.h>
  16. #include <linux/gpio.h>
  17. #include <mach/hardware.h>
  18. #ifdef CONFIG_LEDS
  19. #include <linux/leds.h>
  20. #include <linux/platform_device.h>
  21. static const struct gpio_led puv3_gpio_leds[] = {
  22. { .name = "cpuhealth", .gpio = GPO_CPU_HEALTH, .active_low = 0,
  23. .default_trigger = "heartbeat", },
  24. { .name = "hdd_led", .gpio = GPO_HDD_LED, .active_low = 1,
  25. .default_trigger = "ide-disk", },
  26. };
  27. static const struct gpio_led_platform_data puv3_gpio_led_data = {
  28. .num_leds = ARRAY_SIZE(puv3_gpio_leds),
  29. .leds = (void *) puv3_gpio_leds,
  30. };
  31. static struct platform_device puv3_gpio_gpio_leds = {
  32. .name = "leds-gpio",
  33. .id = -1,
  34. .dev = {
  35. .platform_data = (void *) &puv3_gpio_led_data,
  36. }
  37. };
  38. static int __init puv3_gpio_leds_init(void)
  39. {
  40. platform_device_register(&puv3_gpio_gpio_leds);
  41. return 0;
  42. }
  43. device_initcall(puv3_gpio_leds_init);
  44. #endif
  45. static int puv3_gpio_get(struct gpio_chip *chip, unsigned offset)
  46. {
  47. return readl(GPIO_GPLR) & GPIO_GPIO(offset);
  48. }
  49. static void puv3_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
  50. {
  51. if (value)
  52. writel(GPIO_GPIO(offset), GPIO_GPSR);
  53. else
  54. writel(GPIO_GPIO(offset), GPIO_GPCR);
  55. }
  56. static int puv3_direction_input(struct gpio_chip *chip, unsigned offset)
  57. {
  58. unsigned long flags;
  59. local_irq_save(flags);
  60. writel(readl(GPIO_GPDR) & ~GPIO_GPIO(offset), GPIO_GPDR);
  61. local_irq_restore(flags);
  62. return 0;
  63. }
  64. static int puv3_direction_output(struct gpio_chip *chip, unsigned offset,
  65. int value)
  66. {
  67. unsigned long flags;
  68. local_irq_save(flags);
  69. puv3_gpio_set(chip, offset, value);
  70. writel(readl(GPIO_GPDR) | GPIO_GPIO(offset), GPIO_GPDR);
  71. local_irq_restore(flags);
  72. return 0;
  73. }
  74. static struct gpio_chip puv3_gpio_chip = {
  75. .label = "gpio",
  76. .direction_input = puv3_direction_input,
  77. .direction_output = puv3_direction_output,
  78. .set = puv3_gpio_set,
  79. .get = puv3_gpio_get,
  80. .base = 0,
  81. .ngpio = GPIO_MAX + 1,
  82. };
  83. void __init puv3_init_gpio(void)
  84. {
  85. writel(GPIO_DIR, GPIO_GPDR);
  86. #if defined(CONFIG_PUV3_NB0916) || defined(CONFIG_PUV3_SMW0919) \
  87. || defined(CONFIG_PUV3_DB0913)
  88. gpio_set_value(GPO_WIFI_EN, 1);
  89. gpio_set_value(GPO_HDD_LED, 1);
  90. gpio_set_value(GPO_VGA_EN, 1);
  91. gpio_set_value(GPO_LCD_EN, 1);
  92. gpio_set_value(GPO_CAM_PWR_EN, 0);
  93. gpio_set_value(GPO_LCD_VCC_EN, 1);
  94. gpio_set_value(GPO_SOFT_OFF, 1);
  95. gpio_set_value(GPO_BT_EN, 1);
  96. gpio_set_value(GPO_FAN_ON, 0);
  97. gpio_set_value(GPO_SPKR, 0);
  98. gpio_set_value(GPO_CPU_HEALTH, 1);
  99. gpio_set_value(GPO_LAN_SEL, 1);
  100. /*
  101. * DO NOT modify the GPO_SET_V1 and GPO_SET_V2 in kernel
  102. * gpio_set_value(GPO_SET_V1, 1);
  103. * gpio_set_value(GPO_SET_V2, 1);
  104. */
  105. #endif
  106. gpiochip_add(&puv3_gpio_chip);
  107. }