mpp.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * arch/arm/plat-orion/mpp.c
  3. *
  4. * MPP functions for Marvell orion SoCs
  5. *
  6. * This file is licensed under the terms of the GNU General Public
  7. * License version 2. This program is licensed "as is" without any
  8. * warranty of any kind, whether express or implied.
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/init.h>
  12. #include <linux/mbus.h>
  13. #include <linux/io.h>
  14. #include <linux/gpio.h>
  15. #include <plat/orion-gpio.h>
  16. #include <plat/mpp.h>
  17. /* Address of the ith MPP control register */
  18. static __init void __iomem *mpp_ctrl_addr(unsigned int i,
  19. void __iomem *dev_bus)
  20. {
  21. return dev_bus + (i) * 4;
  22. }
  23. void __init orion_mpp_conf(unsigned int *mpp_list, unsigned int variant_mask,
  24. unsigned int mpp_max, void __iomem *dev_bus)
  25. {
  26. unsigned int mpp_nr_regs = (1 + mpp_max/8);
  27. u32 mpp_ctrl[mpp_nr_regs];
  28. int i;
  29. printk(KERN_DEBUG "initial MPP regs:");
  30. for (i = 0; i < mpp_nr_regs; i++) {
  31. mpp_ctrl[i] = readl(mpp_ctrl_addr(i, dev_bus));
  32. printk(" %08x", mpp_ctrl[i]);
  33. }
  34. printk("\n");
  35. for ( ; *mpp_list; mpp_list++) {
  36. unsigned int num = MPP_NUM(*mpp_list);
  37. unsigned int sel = MPP_SEL(*mpp_list);
  38. int shift, gpio_mode;
  39. if (num > mpp_max) {
  40. printk(KERN_ERR "orion_mpp_conf: invalid MPP "
  41. "number (%u)\n", num);
  42. continue;
  43. }
  44. if (variant_mask && !(*mpp_list & variant_mask)) {
  45. printk(KERN_WARNING
  46. "orion_mpp_conf: requested MPP%u config "
  47. "unavailable on this hardware\n", num);
  48. continue;
  49. }
  50. shift = (num & 7) << 2;
  51. mpp_ctrl[num / 8] &= ~(0xf << shift);
  52. mpp_ctrl[num / 8] |= sel << shift;
  53. gpio_mode = 0;
  54. if (*mpp_list & MPP_INPUT_MASK)
  55. gpio_mode |= GPIO_INPUT_OK;
  56. if (*mpp_list & MPP_OUTPUT_MASK)
  57. gpio_mode |= GPIO_OUTPUT_OK;
  58. orion_gpio_set_valid(num, gpio_mode);
  59. }
  60. printk(KERN_DEBUG " final MPP regs:");
  61. for (i = 0; i < mpp_nr_regs; i++) {
  62. writel(mpp_ctrl[i], mpp_ctrl_addr(i, dev_bus));
  63. printk(" %08x", mpp_ctrl[i]);
  64. }
  65. printk("\n");
  66. }