gpio-davinci.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * TI DaVinci GPIO Support
  3. *
  4. * Copyright (c) 2006 David Brownell
  5. * Copyright (c) 2007, MontaVista Software, Inc. <source@mvista.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. */
  12. #ifndef __DAVINCI_DAVINCI_GPIO_H
  13. #define __DAVINCI_DAVINCI_GPIO_H
  14. #include <linux/io.h>
  15. #include <linux/spinlock.h>
  16. #include <asm-generic/gpio.h>
  17. #include <mach/irqs.h>
  18. #include <mach/common.h>
  19. #define DAVINCI_GPIO_BASE 0x01C67000
  20. enum davinci_gpio_type {
  21. GPIO_TYPE_DAVINCI = 0,
  22. GPIO_TYPE_TNETV107X,
  23. };
  24. /*
  25. * basic gpio routines
  26. *
  27. * board-specific init should be done by arch/.../.../board-XXX.c (maybe
  28. * initializing banks together) rather than boot loaders; kexec() won't
  29. * go through boot loaders.
  30. *
  31. * the gpio clock will be turned on when gpios are used, and you may also
  32. * need to pay attention to PINMUX registers to be sure those pins are
  33. * used as gpios, not with other peripherals.
  34. *
  35. * On-chip GPIOs are numbered 0..(DAVINCI_N_GPIO-1). For documentation,
  36. * and maybe for later updates, code may write GPIO(N). These may be
  37. * all 1.8V signals, all 3.3V ones, or a mix of the two. A given chip
  38. * may not support all the GPIOs in that range.
  39. *
  40. * GPIOs can also be on external chips, numbered after the ones built-in
  41. * to the DaVinci chip. For now, they won't be usable as IRQ sources.
  42. */
  43. #define GPIO(X) (X) /* 0 <= X <= (DAVINCI_N_GPIO - 1) */
  44. /* Convert GPIO signal to GPIO pin number */
  45. #define GPIO_TO_PIN(bank, gpio) (16 * (bank) + (gpio))
  46. struct davinci_gpio_controller {
  47. struct gpio_chip chip;
  48. int irq_base;
  49. spinlock_t lock;
  50. void __iomem *regs;
  51. void __iomem *set_data;
  52. void __iomem *clr_data;
  53. void __iomem *in_data;
  54. };
  55. /* The __gpio_to_controller() and __gpio_mask() functions inline to constants
  56. * with constant parameters; or in outlined code they execute at runtime.
  57. *
  58. * You'd access the controller directly when reading or writing more than
  59. * one gpio value at a time, and to support wired logic where the value
  60. * being driven by the cpu need not match the value read back.
  61. *
  62. * These are NOT part of the cross-platform GPIO interface
  63. */
  64. static inline struct davinci_gpio_controller *
  65. __gpio_to_controller(unsigned gpio)
  66. {
  67. struct davinci_gpio_controller *ctlrs = davinci_soc_info.gpio_ctlrs;
  68. int index = gpio / 32;
  69. if (!ctlrs || index >= davinci_soc_info.gpio_ctlrs_num)
  70. return NULL;
  71. return ctlrs + index;
  72. }
  73. static inline u32 __gpio_mask(unsigned gpio)
  74. {
  75. return 1 << (gpio % 32);
  76. }
  77. #endif /* __DAVINCI_DAVINCI_GPIO_H */