basic_mmio_gpio.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Basic memory-mapped GPIO controllers.
  3. *
  4. * Copyright 2008 MontaVista Software, Inc.
  5. * Copyright 2008,2010 Anton Vorontsov <cbouatmailru@gmail.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation; either version 2 of the License, or (at your
  10. * option) any later version.
  11. */
  12. #ifndef __BASIC_MMIO_GPIO_H
  13. #define __BASIC_MMIO_GPIO_H
  14. #include <linux/gpio.h>
  15. #include <linux/types.h>
  16. #include <linux/compiler.h>
  17. struct bgpio_pdata {
  18. int base;
  19. int ngpio;
  20. };
  21. struct device;
  22. struct bgpio_chip {
  23. struct gpio_chip gc;
  24. unsigned long (*read_reg)(void __iomem *reg);
  25. void (*write_reg)(void __iomem *reg, unsigned long data);
  26. void __iomem *reg_dat;
  27. void __iomem *reg_set;
  28. void __iomem *reg_clr;
  29. void __iomem *reg_dir;
  30. /* Number of bits (GPIOs): <register width> * 8. */
  31. int bits;
  32. /*
  33. * Some GPIO controllers work with the big-endian bits notation,
  34. * e.g. in a 8-bits register, GPIO7 is the least significant bit.
  35. */
  36. unsigned long (*pin2mask)(struct bgpio_chip *bgc, unsigned int pin);
  37. /*
  38. * Used to lock bgpio_chip->data. Also, this is needed to keep
  39. * shadowed and real data registers writes together.
  40. */
  41. spinlock_t lock;
  42. /* Shadowed data register to clear/set bits safely. */
  43. unsigned long data;
  44. /* Shadowed direction registers to clear/set direction safely. */
  45. unsigned long dir;
  46. };
  47. static inline struct bgpio_chip *to_bgpio_chip(struct gpio_chip *gc)
  48. {
  49. return container_of(gc, struct bgpio_chip, gc);
  50. }
  51. int __devexit bgpio_remove(struct bgpio_chip *bgc);
  52. int __devinit bgpio_init(struct bgpio_chip *bgc,
  53. struct device *dev,
  54. unsigned long sz,
  55. void __iomem *dat,
  56. void __iomem *set,
  57. void __iomem *clr,
  58. void __iomem *dirout,
  59. void __iomem *dirin,
  60. bool big_endian);
  61. #endif /* __BASIC_MMIO_GPIO_H */