devices.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * CNS3xxx common devices
  4. *
  5. * Copyright 2008 Cavium Networks
  6. * Scott Shu
  7. * Copyright 2010 MontaVista Software, LLC.
  8. * Anton Vorontsov <[email protected]>
  9. */
  10. #include <linux/io.h>
  11. #include <linux/init.h>
  12. #include <linux/compiler.h>
  13. #include <linux/dma-mapping.h>
  14. #include <linux/platform_device.h>
  15. #include "cns3xxx.h"
  16. #include "pm.h"
  17. #include "core.h"
  18. #include "devices.h"
  19. /*
  20. * AHCI
  21. */
  22. static struct resource cns3xxx_ahci_resource[] = {
  23. [0] = {
  24. .start = CNS3XXX_SATA2_BASE,
  25. .end = CNS3XXX_SATA2_BASE + CNS3XXX_SATA2_SIZE - 1,
  26. .flags = IORESOURCE_MEM,
  27. },
  28. [1] = {
  29. .start = IRQ_CNS3XXX_SATA,
  30. .end = IRQ_CNS3XXX_SATA,
  31. .flags = IORESOURCE_IRQ,
  32. },
  33. };
  34. static u64 cns3xxx_ahci_dmamask = DMA_BIT_MASK(32);
  35. static struct platform_device cns3xxx_ahci_pdev = {
  36. .name = "ahci",
  37. .id = 0,
  38. .resource = cns3xxx_ahci_resource,
  39. .num_resources = ARRAY_SIZE(cns3xxx_ahci_resource),
  40. .dev = {
  41. .dma_mask = &cns3xxx_ahci_dmamask,
  42. .coherent_dma_mask = DMA_BIT_MASK(32),
  43. },
  44. };
  45. void __init cns3xxx_ahci_init(void)
  46. {
  47. u32 tmp;
  48. tmp = __raw_readl(MISC_SATA_POWER_MODE);
  49. tmp |= 0x1 << 16; /* Disable SATA PHY 0 from SLUMBER Mode */
  50. tmp |= 0x1 << 17; /* Disable SATA PHY 1 from SLUMBER Mode */
  51. __raw_writel(tmp, MISC_SATA_POWER_MODE);
  52. /* Enable SATA PHY */
  53. cns3xxx_pwr_power_up(0x1 << PM_PLL_HM_PD_CTRL_REG_OFFSET_SATA_PHY0);
  54. cns3xxx_pwr_power_up(0x1 << PM_PLL_HM_PD_CTRL_REG_OFFSET_SATA_PHY1);
  55. /* Enable SATA Clock */
  56. cns3xxx_pwr_clk_en(0x1 << PM_CLK_GATE_REG_OFFSET_SATA);
  57. /* De-Asscer SATA Reset */
  58. cns3xxx_pwr_soft_rst(CNS3XXX_PWR_SOFTWARE_RST(SATA));
  59. platform_device_register(&cns3xxx_ahci_pdev);
  60. }
  61. /*
  62. * SDHCI
  63. */
  64. static struct resource cns3xxx_sdhci_resources[] = {
  65. [0] = {
  66. .start = CNS3XXX_SDIO_BASE,
  67. .end = CNS3XXX_SDIO_BASE + SZ_4K - 1,
  68. .flags = IORESOURCE_MEM,
  69. },
  70. [1] = {
  71. .start = IRQ_CNS3XXX_SDIO,
  72. .end = IRQ_CNS3XXX_SDIO,
  73. .flags = IORESOURCE_IRQ,
  74. },
  75. };
  76. static struct platform_device cns3xxx_sdhci_pdev = {
  77. .name = "sdhci-cns3xxx",
  78. .id = 0,
  79. .num_resources = ARRAY_SIZE(cns3xxx_sdhci_resources),
  80. .resource = cns3xxx_sdhci_resources,
  81. };
  82. void __init cns3xxx_sdhci_init(void)
  83. {
  84. u32 __iomem *gpioa = IOMEM(CNS3XXX_MISC_BASE_VIRT + 0x0014);
  85. u32 gpioa_pins = __raw_readl(gpioa);
  86. /* MMC/SD pins share with GPIOA */
  87. gpioa_pins |= 0x1fff0004;
  88. __raw_writel(gpioa_pins, gpioa);
  89. cns3xxx_pwr_clk_en(CNS3XXX_PWR_CLK_EN(SDIO));
  90. cns3xxx_pwr_soft_rst(CNS3XXX_PWR_SOFTWARE_RST(SDIO));
  91. platform_device_register(&cns3xxx_sdhci_pdev);
  92. }