gpio.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * s6000 gpio driver
  3. *
  4. * Copyright (c) 2009 emlix GmbH
  5. * Authors: Oskar Schirmer <os@emlix.com>
  6. * Johannes Weiner <jw@emlix.com>
  7. */
  8. #include <linux/kernel.h>
  9. #include <linux/module.h>
  10. #include <linux/init.h>
  11. #include <linux/io.h>
  12. #include <linux/gpio.h>
  13. #include <variant/hardware.h>
  14. #define S6_GPIO_DATA 0x000
  15. #define S6_GPIO_IS 0x404
  16. #define S6_GPIO_IBE 0x408
  17. #define S6_GPIO_IEV 0x40C
  18. #define S6_GPIO_IE 0x410
  19. #define S6_GPIO_RIS 0x414
  20. #define S6_GPIO_MIS 0x418
  21. #define S6_GPIO_IC 0x41C
  22. #define S6_GPIO_AFSEL 0x420
  23. #define S6_GPIO_DIR 0x800
  24. #define S6_GPIO_BANK(nr) ((nr) * 0x1000)
  25. #define S6_GPIO_MASK(nr) (4 << (nr))
  26. #define S6_GPIO_OFFSET(nr) \
  27. (S6_GPIO_BANK((nr) >> 3) + S6_GPIO_MASK((nr) & 7))
  28. static int direction_input(struct gpio_chip *chip, unsigned int off)
  29. {
  30. writeb(0, S6_REG_GPIO + S6_GPIO_DIR + S6_GPIO_OFFSET(off));
  31. return 0;
  32. }
  33. static int get(struct gpio_chip *chip, unsigned int off)
  34. {
  35. return readb(S6_REG_GPIO + S6_GPIO_DATA + S6_GPIO_OFFSET(off));
  36. }
  37. static int direction_output(struct gpio_chip *chip, unsigned int off, int val)
  38. {
  39. unsigned rel = S6_GPIO_OFFSET(off);
  40. writeb(~0, S6_REG_GPIO + S6_GPIO_DIR + rel);
  41. writeb(val ? ~0 : 0, S6_REG_GPIO + S6_GPIO_DATA + rel);
  42. return 0;
  43. }
  44. static void set(struct gpio_chip *chip, unsigned int off, int val)
  45. {
  46. writeb(val ? ~0 : 0, S6_REG_GPIO + S6_GPIO_DATA + S6_GPIO_OFFSET(off));
  47. }
  48. static struct gpio_chip gpiochip = {
  49. .owner = THIS_MODULE,
  50. .direction_input = direction_input,
  51. .get = get,
  52. .direction_output = direction_output,
  53. .set = set,
  54. .base = 0,
  55. .ngpio = 24,
  56. .can_sleep = 0, /* no blocking io needed */
  57. .exported = 0, /* no exporting to userspace */
  58. };
  59. int s6_gpio_init(void)
  60. {
  61. return gpiochip_add(&gpiochip);
  62. }