ahci_octeon.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * SATA glue for Cavium Octeon III SOCs.
  3. *
  4. *
  5. * This file is subject to the terms and conditions of the GNU General Public
  6. * License. See the file "COPYING" in the main directory of this archive
  7. * for more details.
  8. *
  9. * Copyright (C) 2010-2015 Cavium Networks
  10. *
  11. */
  12. #include <linux/module.h>
  13. #include <linux/dma-mapping.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/of_platform.h>
  16. #include <asm/octeon/octeon.h>
  17. #include <asm/bitfield.h>
  18. #define CVMX_SATA_UCTL_SHIM_CFG 0xE8
  19. #define SATA_UCTL_ENDIAN_MODE_BIG 1
  20. #define SATA_UCTL_ENDIAN_MODE_LITTLE 0
  21. #define SATA_UCTL_ENDIAN_MODE_MASK 3
  22. #define SATA_UCTL_DMA_ENDIAN_MODE_SHIFT 8
  23. #define SATA_UCTL_CSR_ENDIAN_MODE_SHIFT 0
  24. #define SATA_UCTL_DMA_READ_CMD_SHIFT 12
  25. static int ahci_octeon_probe(struct platform_device *pdev)
  26. {
  27. struct device *dev = &pdev->dev;
  28. struct device_node *node = dev->of_node;
  29. struct resource *res;
  30. void __iomem *base;
  31. u64 cfg;
  32. int ret;
  33. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  34. if (!res) {
  35. dev_err(&pdev->dev, "Platform resource[0] is missing\n");
  36. return -ENODEV;
  37. }
  38. base = devm_ioremap_resource(&pdev->dev, res);
  39. if (IS_ERR(base))
  40. return PTR_ERR(base);
  41. cfg = cvmx_readq_csr(base + CVMX_SATA_UCTL_SHIM_CFG);
  42. cfg &= ~(SATA_UCTL_ENDIAN_MODE_MASK << SATA_UCTL_DMA_ENDIAN_MODE_SHIFT);
  43. cfg &= ~(SATA_UCTL_ENDIAN_MODE_MASK << SATA_UCTL_CSR_ENDIAN_MODE_SHIFT);
  44. #ifdef __BIG_ENDIAN
  45. cfg |= SATA_UCTL_ENDIAN_MODE_BIG << SATA_UCTL_DMA_ENDIAN_MODE_SHIFT;
  46. cfg |= SATA_UCTL_ENDIAN_MODE_BIG << SATA_UCTL_CSR_ENDIAN_MODE_SHIFT;
  47. #else
  48. cfg |= SATA_UCTL_ENDIAN_MODE_LITTLE << SATA_UCTL_DMA_ENDIAN_MODE_SHIFT;
  49. cfg |= SATA_UCTL_ENDIAN_MODE_LITTLE << SATA_UCTL_CSR_ENDIAN_MODE_SHIFT;
  50. #endif
  51. cfg |= 1 << SATA_UCTL_DMA_READ_CMD_SHIFT;
  52. cvmx_writeq_csr(base + CVMX_SATA_UCTL_SHIM_CFG, cfg);
  53. if (!node) {
  54. dev_err(dev, "no device node, failed to add octeon sata\n");
  55. return -ENODEV;
  56. }
  57. ret = of_platform_populate(node, NULL, NULL, dev);
  58. if (ret) {
  59. dev_err(dev, "failed to add ahci-platform core\n");
  60. return ret;
  61. }
  62. return 0;
  63. }
  64. static int ahci_octeon_remove(struct platform_device *pdev)
  65. {
  66. return 0;
  67. }
  68. static const struct of_device_id octeon_ahci_match[] = {
  69. { .compatible = "cavium,octeon-7130-sata-uctl", },
  70. {},
  71. };
  72. MODULE_DEVICE_TABLE(of, octeon_ahci_match);
  73. static struct platform_driver ahci_octeon_driver = {
  74. .probe = ahci_octeon_probe,
  75. .remove = ahci_octeon_remove,
  76. .driver = {
  77. .name = "octeon-ahci",
  78. .of_match_table = octeon_ahci_match,
  79. },
  80. };
  81. module_platform_driver(ahci_octeon_driver);
  82. MODULE_LICENSE("GPL");
  83. MODULE_AUTHOR("Cavium, Inc. <[email protected]>");
  84. MODULE_DESCRIPTION("Cavium Inc. sata config.");