basic_mmio_gpio.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. const char *label;
  20. int base;
  21. int ngpio;
  22. };
  23. struct device;
  24. struct bgpio_chip {
  25. struct gpio_chip gc;
  26. unsigned long (*read_reg)(void __iomem *reg);
  27. void (*write_reg)(void __iomem *reg, unsigned long data);
  28. void __iomem *reg_dat;
  29. void __iomem *reg_set;
  30. void __iomem *reg_clr;
  31. void __iomem *reg_dir;
  32. /* Number of bits (GPIOs): <register width> * 8. */
  33. int bits;
  34. /*
  35. * Some GPIO controllers work with the big-endian bits notation,
  36. * e.g. in a 8-bits register, GPIO7 is the least significant bit.
  37. */
  38. unsigned long (*pin2mask)(struct bgpio_chip *bgc, unsigned int pin);
  39. /*
  40. * Used to lock bgpio_chip->data. Also, this is needed to keep
  41. * shadowed and real data registers writes together.
  42. */
  43. spinlock_t lock;
  44. /* Shadowed data register to clear/set bits safely. */
  45. unsigned long data;
  46. /* Shadowed direction registers to clear/set direction safely. */
  47. unsigned long dir;
  48. };
  49. static inline struct bgpio_chip *to_bgpio_chip(struct gpio_chip *gc)
  50. {
  51. return container_of(gc, struct bgpio_chip, gc);
  52. }
  53. int bgpio_remove(struct bgpio_chip *bgc);
  54. int bgpio_init(struct bgpio_chip *bgc, struct device *dev,
  55. unsigned long sz, void __iomem *dat, void __iomem *set,
  56. void __iomem *clr, void __iomem *dirout, void __iomem *dirin,
  57. unsigned long flags);
  58. #define BGPIOF_BIG_ENDIAN BIT(0)
  59. #define BGPIOF_UNREADABLE_REG_SET BIT(1) /* reg_set is unreadable */
  60. #define BGPIOF_UNREADABLE_REG_DIR BIT(2) /* reg_dir is unreadable */
  61. #define BGPIOF_BIG_ENDIAN_BYTE_ORDER BIT(3)
  62. #define BGPIOF_READ_OUTPUT_REG_SET BIT(4) /* reg_set stores output value */
  63. #define BGPIOF_NO_OUTPUT BIT(5) /* only input */
  64. #endif /* __BASIC_MMIO_GPIO_H */