geode_32.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * AMD Geode southbridge support code
  3. * Copyright (C) 2006, Advanced Micro Devices, Inc.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of version 2 of the GNU General Public License
  7. * as published by the Free Software Foundation.
  8. */
  9. #include <linux/kernel.h>
  10. #include <linux/module.h>
  11. #include <linux/ioport.h>
  12. #include <linux/io.h>
  13. #include <asm/msr.h>
  14. #include <asm/geode.h>
  15. static struct {
  16. char *name;
  17. u32 msr;
  18. int size;
  19. u32 base;
  20. } lbars[] = {
  21. { "geode-pms", MSR_LBAR_PMS, LBAR_PMS_SIZE, 0 },
  22. { "geode-acpi", MSR_LBAR_ACPI, LBAR_ACPI_SIZE, 0 },
  23. { "geode-gpio", MSR_LBAR_GPIO, LBAR_GPIO_SIZE, 0 },
  24. { "geode-mfgpt", MSR_LBAR_MFGPT, LBAR_MFGPT_SIZE, 0 }
  25. };
  26. static void __init init_lbars(void)
  27. {
  28. u32 lo, hi;
  29. int i;
  30. for (i = 0; i < ARRAY_SIZE(lbars); i++) {
  31. rdmsr(lbars[i].msr, lo, hi);
  32. if (hi & 0x01)
  33. lbars[i].base = lo & 0x0000ffff;
  34. if (lbars[i].base == 0)
  35. printk(KERN_ERR "geode: Couldn't initialize '%s'\n",
  36. lbars[i].name);
  37. }
  38. }
  39. int geode_get_dev_base(unsigned int dev)
  40. {
  41. BUG_ON(dev >= ARRAY_SIZE(lbars));
  42. return lbars[dev].base;
  43. }
  44. EXPORT_SYMBOL_GPL(geode_get_dev_base);
  45. /* === GPIO API === */
  46. void geode_gpio_set(unsigned int gpio, unsigned int reg)
  47. {
  48. u32 base = geode_get_dev_base(GEODE_DEV_GPIO);
  49. if (!base)
  50. return;
  51. if (gpio < 16)
  52. outl(1 << gpio, base + reg);
  53. else
  54. outl(1 << (gpio - 16), base + 0x80 + reg);
  55. }
  56. EXPORT_SYMBOL_GPL(geode_gpio_set);
  57. void geode_gpio_clear(unsigned int gpio, unsigned int reg)
  58. {
  59. u32 base = geode_get_dev_base(GEODE_DEV_GPIO);
  60. if (!base)
  61. return;
  62. if (gpio < 16)
  63. outl(1 << (gpio + 16), base + reg);
  64. else
  65. outl(1 << gpio, base + 0x80 + reg);
  66. }
  67. EXPORT_SYMBOL_GPL(geode_gpio_clear);
  68. int geode_gpio_isset(unsigned int gpio, unsigned int reg)
  69. {
  70. u32 base = geode_get_dev_base(GEODE_DEV_GPIO);
  71. if (!base)
  72. return 0;
  73. if (gpio < 16)
  74. return (inl(base + reg) & (1 << gpio)) ? 1 : 0;
  75. else
  76. return (inl(base + 0x80 + reg) & (1 << (gpio - 16))) ? 1 : 0;
  77. }
  78. EXPORT_SYMBOL_GPL(geode_gpio_isset);
  79. void geode_gpio_set_irq(unsigned int group, unsigned int irq)
  80. {
  81. u32 lo, hi;
  82. if (group > 7 || irq > 15)
  83. return;
  84. rdmsr(MSR_PIC_ZSEL_HIGH, lo, hi);
  85. lo &= ~(0xF << (group * 4));
  86. lo |= (irq & 0xF) << (group * 4);
  87. wrmsr(MSR_PIC_ZSEL_HIGH, lo, hi);
  88. }
  89. EXPORT_SYMBOL_GPL(geode_gpio_set_irq);
  90. void geode_gpio_setup_event(unsigned int gpio, int pair, int pme)
  91. {
  92. u32 base = geode_get_dev_base(GEODE_DEV_GPIO);
  93. u32 offset, shift, val;
  94. if (gpio >= 24)
  95. offset = GPIO_MAP_W;
  96. else if (gpio >= 16)
  97. offset = GPIO_MAP_Z;
  98. else if (gpio >= 8)
  99. offset = GPIO_MAP_Y;
  100. else
  101. offset = GPIO_MAP_X;
  102. shift = (gpio % 8) * 4;
  103. val = inl(base + offset);
  104. /* Clear whatever was there before */
  105. val &= ~(0xF << shift);
  106. /* And set the new value */
  107. val |= ((pair & 7) << shift);
  108. /* Set the PME bit if this is a PME event */
  109. if (pme)
  110. val |= (1 << (shift + 3));
  111. outl(val, base + offset);
  112. }
  113. EXPORT_SYMBOL_GPL(geode_gpio_setup_event);
  114. static int __init geode_southbridge_init(void)
  115. {
  116. int timers;
  117. if (!is_geode())
  118. return -ENODEV;
  119. init_lbars();
  120. timers = geode_mfgpt_detect();
  121. printk(KERN_INFO "geode: %d MFGPT timers available.\n", timers);
  122. return 0;
  123. }
  124. postcore_initcall(geode_southbridge_init);