ogp_spi.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. * This file is part of the flashrom project.
  3. *
  4. * Copyright (C) 2010 Mark Marshall
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; version 2 of the License.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  18. */
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #include "flash.h"
  22. #include "programmer.h"
  23. #define PCI_VENDOR_ID_OGP 0x1227
  24. /* These are the register addresses for the OGD1 / OGA1. If they are
  25. * different for later versions of the hardware then we will need
  26. * logic to select between the different hardware versions. */
  27. #define OGA1_XP10_BPROM_SI 0x0040 /* W */
  28. #define OGA1_XP10_BPROM_SO 0x0040 /* R */
  29. #define OGA1_XP10_BPROM_CE_BAR 0x0044 /* W */
  30. #define OGA1_XP10_BPROM_SCK 0x0048 /* W */
  31. #define OGA1_XP10_BPROM_REG_SEL 0x004C /* W */
  32. #define OGA1_XP10_CPROM_SI 0x0050 /* W */
  33. #define OGA1_XP10_CPROM_SO 0x0050 /* R */
  34. #define OGA1_XP10_CPROM_CE_BAR 0x0054 /* W */
  35. #define OGA1_XP10_CPROM_SCK 0x0058 /* W */
  36. #define OGA1_XP10_CPROM_REG_SEL 0x005C /* W */
  37. static uint8_t *ogp_spibar;
  38. static uint32_t ogp_reg_sel;
  39. static uint32_t ogp_reg_siso;
  40. static uint32_t ogp_reg__ce;
  41. static uint32_t ogp_reg_sck;
  42. const struct pcidev_status ogp_spi[] = {
  43. {PCI_VENDOR_ID_OGP, 0x0000, OK, "Open Graphics Project", "Development Board OGD1"},
  44. {},
  45. };
  46. static void ogp_request_spibus(void)
  47. {
  48. pci_mmio_writel(1, ogp_spibar + ogp_reg_sel);
  49. }
  50. static void ogp_release_spibus(void)
  51. {
  52. pci_mmio_writel(0, ogp_spibar + ogp_reg_sel);
  53. }
  54. static void ogp_bitbang_set_cs(int val)
  55. {
  56. pci_mmio_writel(val, ogp_spibar + ogp_reg__ce);
  57. }
  58. static void ogp_bitbang_set_sck(int val)
  59. {
  60. pci_mmio_writel(val, ogp_spibar + ogp_reg_sck);
  61. }
  62. static void ogp_bitbang_set_mosi(int val)
  63. {
  64. pci_mmio_writel(val, ogp_spibar + ogp_reg_siso);
  65. }
  66. static int ogp_bitbang_get_miso(void)
  67. {
  68. uint32_t tmp;
  69. tmp = pci_mmio_readl(ogp_spibar + ogp_reg_siso);
  70. return tmp & 0x1;
  71. }
  72. static const struct bitbang_spi_master bitbang_spi_master_ogp = {
  73. .type = BITBANG_SPI_MASTER_OGP,
  74. .set_cs = ogp_bitbang_set_cs,
  75. .set_sck = ogp_bitbang_set_sck,
  76. .set_mosi = ogp_bitbang_set_mosi,
  77. .get_miso = ogp_bitbang_get_miso,
  78. .request_bus = ogp_request_spibus,
  79. .release_bus = ogp_release_spibus,
  80. };
  81. static int ogp_spi_shutdown(void *data)
  82. {
  83. physunmap(ogp_spibar, 4096);
  84. pci_cleanup(pacc);
  85. release_io_perms();
  86. return 0;
  87. }
  88. int ogp_spi_init(void)
  89. {
  90. char *type;
  91. type = extract_programmer_param("rom");
  92. if (!type) {
  93. msg_perr("Please use flashrom -p ogp_spi:rom=... to specify "
  94. "which flashchip you want to access.\n");
  95. return 1;
  96. } else if (!strcasecmp(type, "bprom") || !strcasecmp(type, "bios")) {
  97. ogp_reg_sel = OGA1_XP10_BPROM_REG_SEL;
  98. ogp_reg_siso = OGA1_XP10_BPROM_SI;
  99. ogp_reg__ce = OGA1_XP10_BPROM_CE_BAR;
  100. ogp_reg_sck = OGA1_XP10_BPROM_SCK;
  101. } else if (!strcasecmp(type, "cprom") || !strcasecmp(type, "s3")) {
  102. ogp_reg_sel = OGA1_XP10_CPROM_REG_SEL;
  103. ogp_reg_siso = OGA1_XP10_CPROM_SI;
  104. ogp_reg__ce = OGA1_XP10_CPROM_CE_BAR;
  105. ogp_reg_sck = OGA1_XP10_CPROM_SCK;
  106. } else {
  107. msg_perr("Invalid or missing rom= parameter.\n");
  108. return 1;
  109. }
  110. get_io_perms();
  111. io_base_addr = pcidev_init(PCI_BASE_ADDRESS_0, ogp_spi);
  112. ogp_spibar = physmap("OGP registers", io_base_addr, 4096);
  113. if (register_shutdown(ogp_spi_shutdown, NULL))
  114. return 1;
  115. /* no delay for now. */
  116. if (bitbang_spi_init(&bitbang_spi_master_ogp, 0))
  117. return 1;
  118. return 0;
  119. }