basic_mmio_gpio.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. #include <linux/spinlock_types.h>
  18. struct bgpio_pdata {
  19. int base;
  20. int ngpio;
  21. };
  22. struct device;
  23. struct bgpio_chip {
  24. struct gpio_chip gc;
  25. unsigned long (*read_reg)(void __iomem *reg);
  26. void (*write_reg)(void __iomem *reg, unsigned long data);
  27. void __iomem *reg_dat;
  28. void __iomem *reg_set;
  29. void __iomem *reg_clr;
  30. void __iomem *reg_dir;
  31. /* Number of bits (GPIOs): <register width> * 8. */
  32. int bits;
  33. /*
  34. * Some GPIO controllers work with the big-endian bits notation,
  35. * e.g. in a 8-bits register, GPIO7 is the least significant bit.
  36. */
  37. unsigned long (*pin2mask)(struct bgpio_chip *bgc, unsigned int pin);
  38. /*
  39. * Used to lock bgpio_chip->data. Also, this is needed to keep
  40. * shadowed and real data registers writes together.
  41. */
  42. spinlock_t lock;
  43. /* Shadowed data register to clear/set bits safely. */
  44. unsigned long data;
  45. /* Shadowed direction registers to clear/set direction safely. */
  46. unsigned long dir;
  47. };
  48. static inline struct bgpio_chip *to_bgpio_chip(struct gpio_chip *gc)
  49. {
  50. return container_of(gc, struct bgpio_chip, gc);
  51. }
  52. int bgpio_remove(struct bgpio_chip *bgc);
  53. int bgpio_init(struct bgpio_chip *bgc, struct device *dev,
  54. unsigned long sz, void __iomem *dat, void __iomem *set,
  55. void __iomem *clr, void __iomem *dirout, void __iomem *dirin,
  56. bool big_endian);
  57. #endif /* __BASIC_MMIO_GPIO_H */