gpio-config.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* linux/arch/arm/plat-s5pc1xx/gpio-config.c
  2. *
  3. * Copyright 2009 Samsung Electronics
  4. *
  5. * S5PC1XX GPIO Configuration.
  6. *
  7. * Based on plat-s3c64xx/gpio-config.c
  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/kernel.h>
  14. #include <linux/module.h>
  15. #include <linux/gpio.h>
  16. #include <linux/io.h>
  17. #include <mach/gpio-core.h>
  18. #include <plat/gpio-cfg-s5pc1xx.h>
  19. s5p_gpio_drvstr_t s5p_gpio_get_drvstr(unsigned int pin, unsigned int off)
  20. {
  21. struct s3c_gpio_chip *chip = s3c_gpiolib_getchip(pin);
  22. void __iomem *reg;
  23. int shift = off * 2;
  24. u32 drvstr;
  25. if (!chip)
  26. return -EINVAL;
  27. reg = chip->base + 0x0C;
  28. drvstr = __raw_readl(reg);
  29. drvstr = 0xffff & (0x3 << shift);
  30. drvstr = drvstr >> shift;
  31. return (__force s5p_gpio_drvstr_t)drvstr;
  32. }
  33. EXPORT_SYMBOL(s5p_gpio_get_drvstr);
  34. int s5p_gpio_set_drvstr(unsigned int pin, unsigned int off,
  35. s5p_gpio_drvstr_t drvstr)
  36. {
  37. struct s3c_gpio_chip *chip = s3c_gpiolib_getchip(pin);
  38. void __iomem *reg;
  39. int shift = off * 2;
  40. u32 tmp;
  41. if (!chip)
  42. return -EINVAL;
  43. reg = chip->base + 0x0C;
  44. tmp = __raw_readl(reg);
  45. tmp |= drvstr << shift;
  46. __raw_writel(tmp, reg);
  47. return 0;
  48. }
  49. EXPORT_SYMBOL(s5p_gpio_set_drvstr);