gpio.c 3.1 KB

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