mpp.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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[8];
  28. int i;
  29. printk(KERN_DEBUG "initial MPP regs:");
  30. if (mpp_nr_regs > ARRAY_SIZE(mpp_ctrl)) {
  31. printk(KERN_ERR "orion_mpp_conf: invalid mpp_max\n");
  32. return;
  33. }
  34. for (i = 0; i < mpp_nr_regs; i++) {
  35. mpp_ctrl[i] = readl(mpp_ctrl_addr(i, dev_bus));
  36. printk(" %08x", mpp_ctrl[i]);
  37. }
  38. printk("\n");
  39. for ( ; *mpp_list; mpp_list++) {
  40. unsigned int num = MPP_NUM(*mpp_list);
  41. unsigned int sel = MPP_SEL(*mpp_list);
  42. int shift, gpio_mode;
  43. if (num > mpp_max) {
  44. printk(KERN_ERR "orion_mpp_conf: invalid MPP "
  45. "number (%u)\n", num);
  46. continue;
  47. }
  48. if (variant_mask && !(*mpp_list & variant_mask)) {
  49. printk(KERN_WARNING
  50. "orion_mpp_conf: requested MPP%u config "
  51. "unavailable on this hardware\n", num);
  52. continue;
  53. }
  54. shift = (num & 7) << 2;
  55. mpp_ctrl[num / 8] &= ~(0xf << shift);
  56. mpp_ctrl[num / 8] |= sel << shift;
  57. gpio_mode = 0;
  58. if (*mpp_list & MPP_INPUT_MASK)
  59. gpio_mode |= GPIO_INPUT_OK;
  60. if (*mpp_list & MPP_OUTPUT_MASK)
  61. gpio_mode |= GPIO_OUTPUT_OK;
  62. orion_gpio_set_valid(num, gpio_mode);
  63. }
  64. printk(KERN_DEBUG " final MPP regs:");
  65. for (i = 0; i < mpp_nr_regs; i++) {
  66. writel(mpp_ctrl[i], mpp_ctrl_addr(i, dev_bus));
  67. printk(" %08x", mpp_ctrl[i]);
  68. }
  69. printk("\n");
  70. }