s3c2440_gpio.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright (C) 2012
  3. * Gabriel Huau <contact@huau-gabriel.fr>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <asm/arch/s3c2440.h>
  9. #include <asm/gpio.h>
  10. #include <asm/io.h>
  11. #define GPIO_INPUT 0x0
  12. #define GPIO_OUTPUT 0x1
  13. /* 0x4 means that we want DAT and not CON register */
  14. #define GPIO_PORT(x) ((((x) >> 5) & 0x3) + 0x4)
  15. #define GPIO_BIT(x) ((x) & 0x3f)
  16. /*
  17. * It's how we calculate the full port address
  18. * We have to get the number of the port + 1 (Port A is at 0x56000001 ...)
  19. * We move it at the second digit, and finally we add 0x4 because we want
  20. * to modify GPIO DAT and not CON
  21. */
  22. #define GPIO_FULLPORT(x) (S3C24X0_GPIO_BASE | ((GPIO_PORT(gpio) + 1) << 1))
  23. int gpio_set_value(unsigned gpio, int value)
  24. {
  25. unsigned l = readl(GPIO_FULLPORT(gpio));
  26. unsigned bit;
  27. unsigned port = GPIO_FULLPORT(gpio);
  28. /*
  29. * All GPIO Port have a configuration on
  30. * 2 bits excepted the first GPIO (A) which
  31. * have only 1 bit of configuration.
  32. */
  33. if (!GPIO_PORT(gpio))
  34. bit = (0x1 << GPIO_BIT(gpio));
  35. else
  36. bit = (0x3 << GPIO_BIT(gpio));
  37. if (value)
  38. l |= bit;
  39. else
  40. l &= ~bit;
  41. return writel(l, port);
  42. }
  43. int gpio_get_value(unsigned gpio)
  44. {
  45. unsigned l = readl(GPIO_FULLPORT(gpio));
  46. if (GPIO_PORT(gpio) == 0) /* PORT A */
  47. return (l >> GPIO_BIT(gpio)) & 0x1;
  48. return (l >> GPIO_BIT(gpio)) & 0x3;
  49. }
  50. int gpio_request(unsigned gpio, const char *label)
  51. {
  52. return 0;
  53. }
  54. int gpio_free(unsigned gpio)
  55. {
  56. return 0;
  57. }
  58. int gpio_direction_input(unsigned gpio)
  59. {
  60. return writel(GPIO_INPUT << GPIO_BIT(gpio), GPIO_FULLPORT(gpio));
  61. }
  62. int gpio_direction_output(unsigned gpio, int value)
  63. {
  64. writel(GPIO_OUTPUT << GPIO_BIT(gpio), GPIO_FULLPORT(gpio));
  65. return gpio_set_value(gpio, value);
  66. }