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 <mach/hardware.h>
  16. #include <plat/orion-gpio.h>
  17. #include <plat/mpp.h>
  18. /* Address of the ith MPP control register */
  19. static __init void __iomem *mpp_ctrl_addr(unsigned int i,
  20. void __iomem *dev_bus)
  21. {
  22. return dev_bus + (i) * 4;
  23. }
  24. void __init orion_mpp_conf(unsigned int *mpp_list, unsigned int variant_mask,
  25. unsigned int mpp_max, void __iomem *dev_bus)
  26. {
  27. unsigned int mpp_nr_regs = (1 + mpp_max/8);
  28. u32 mpp_ctrl[mpp_nr_regs];
  29. int i;
  30. printk(KERN_DEBUG "initial MPP regs:");
  31. for (i = 0; i < mpp_nr_regs; i++) {
  32. mpp_ctrl[i] = readl(mpp_ctrl_addr(i, dev_bus));
  33. printk(" %08x", mpp_ctrl[i]);
  34. }
  35. printk("\n");
  36. for ( ; *mpp_list; mpp_list++) {
  37. unsigned int num = MPP_NUM(*mpp_list);
  38. unsigned int sel = MPP_SEL(*mpp_list);
  39. int shift, gpio_mode;
  40. if (num > mpp_max) {
  41. printk(KERN_ERR "orion_mpp_conf: invalid MPP "
  42. "number (%u)\n", num);
  43. continue;
  44. }
  45. if (variant_mask & !(*mpp_list & variant_mask)) {
  46. printk(KERN_WARNING
  47. "orion_mpp_conf: requested MPP%u config "
  48. "unavailable on this hardware\n", num);
  49. continue;
  50. }
  51. shift = (num & 7) << 2;
  52. mpp_ctrl[num / 8] &= ~(0xf << shift);
  53. mpp_ctrl[num / 8] |= sel << shift;
  54. gpio_mode = 0;
  55. if (*mpp_list & MPP_INPUT_MASK)
  56. gpio_mode |= GPIO_INPUT_OK;
  57. if (*mpp_list & MPP_OUTPUT_MASK)
  58. gpio_mode |= GPIO_OUTPUT_OK;
  59. orion_gpio_set_valid(num, gpio_mode);
  60. }
  61. printk(KERN_DEBUG " final MPP regs:");
  62. for (i = 0; i < mpp_nr_regs; i++) {
  63. writel(mpp_ctrl[i], mpp_ctrl_addr(i, dev_bus));
  64. printk(" %08x", mpp_ctrl[i]);
  65. }
  66. printk("\n");
  67. }