18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * CNS3xxx common devices 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright 2008 Cavium Networks 68c2ecf20Sopenharmony_ci * Scott Shu 78c2ecf20Sopenharmony_ci * Copyright 2010 MontaVista Software, LLC. 88c2ecf20Sopenharmony_ci * Anton Vorontsov <avorontsov@mvista.com> 98c2ecf20Sopenharmony_ci */ 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#include <linux/io.h> 128c2ecf20Sopenharmony_ci#include <linux/init.h> 138c2ecf20Sopenharmony_ci#include <linux/compiler.h> 148c2ecf20Sopenharmony_ci#include <linux/dma-mapping.h> 158c2ecf20Sopenharmony_ci#include <linux/platform_device.h> 168c2ecf20Sopenharmony_ci#include "cns3xxx.h" 178c2ecf20Sopenharmony_ci#include "pm.h" 188c2ecf20Sopenharmony_ci#include "core.h" 198c2ecf20Sopenharmony_ci#include "devices.h" 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci/* 228c2ecf20Sopenharmony_ci * AHCI 238c2ecf20Sopenharmony_ci */ 248c2ecf20Sopenharmony_cistatic struct resource cns3xxx_ahci_resource[] = { 258c2ecf20Sopenharmony_ci [0] = { 268c2ecf20Sopenharmony_ci .start = CNS3XXX_SATA2_BASE, 278c2ecf20Sopenharmony_ci .end = CNS3XXX_SATA2_BASE + CNS3XXX_SATA2_SIZE - 1, 288c2ecf20Sopenharmony_ci .flags = IORESOURCE_MEM, 298c2ecf20Sopenharmony_ci }, 308c2ecf20Sopenharmony_ci [1] = { 318c2ecf20Sopenharmony_ci .start = IRQ_CNS3XXX_SATA, 328c2ecf20Sopenharmony_ci .end = IRQ_CNS3XXX_SATA, 338c2ecf20Sopenharmony_ci .flags = IORESOURCE_IRQ, 348c2ecf20Sopenharmony_ci }, 358c2ecf20Sopenharmony_ci}; 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_cistatic u64 cns3xxx_ahci_dmamask = DMA_BIT_MASK(32); 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_cistatic struct platform_device cns3xxx_ahci_pdev = { 408c2ecf20Sopenharmony_ci .name = "ahci", 418c2ecf20Sopenharmony_ci .id = 0, 428c2ecf20Sopenharmony_ci .resource = cns3xxx_ahci_resource, 438c2ecf20Sopenharmony_ci .num_resources = ARRAY_SIZE(cns3xxx_ahci_resource), 448c2ecf20Sopenharmony_ci .dev = { 458c2ecf20Sopenharmony_ci .dma_mask = &cns3xxx_ahci_dmamask, 468c2ecf20Sopenharmony_ci .coherent_dma_mask = DMA_BIT_MASK(32), 478c2ecf20Sopenharmony_ci }, 488c2ecf20Sopenharmony_ci}; 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_civoid __init cns3xxx_ahci_init(void) 518c2ecf20Sopenharmony_ci{ 528c2ecf20Sopenharmony_ci u32 tmp; 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_ci tmp = __raw_readl(MISC_SATA_POWER_MODE); 558c2ecf20Sopenharmony_ci tmp |= 0x1 << 16; /* Disable SATA PHY 0 from SLUMBER Mode */ 568c2ecf20Sopenharmony_ci tmp |= 0x1 << 17; /* Disable SATA PHY 1 from SLUMBER Mode */ 578c2ecf20Sopenharmony_ci __raw_writel(tmp, MISC_SATA_POWER_MODE); 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci /* Enable SATA PHY */ 608c2ecf20Sopenharmony_ci cns3xxx_pwr_power_up(0x1 << PM_PLL_HM_PD_CTRL_REG_OFFSET_SATA_PHY0); 618c2ecf20Sopenharmony_ci cns3xxx_pwr_power_up(0x1 << PM_PLL_HM_PD_CTRL_REG_OFFSET_SATA_PHY1); 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci /* Enable SATA Clock */ 648c2ecf20Sopenharmony_ci cns3xxx_pwr_clk_en(0x1 << PM_CLK_GATE_REG_OFFSET_SATA); 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci /* De-Asscer SATA Reset */ 678c2ecf20Sopenharmony_ci cns3xxx_pwr_soft_rst(CNS3XXX_PWR_SOFTWARE_RST(SATA)); 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci platform_device_register(&cns3xxx_ahci_pdev); 708c2ecf20Sopenharmony_ci} 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ci/* 738c2ecf20Sopenharmony_ci * SDHCI 748c2ecf20Sopenharmony_ci */ 758c2ecf20Sopenharmony_cistatic struct resource cns3xxx_sdhci_resources[] = { 768c2ecf20Sopenharmony_ci [0] = { 778c2ecf20Sopenharmony_ci .start = CNS3XXX_SDIO_BASE, 788c2ecf20Sopenharmony_ci .end = CNS3XXX_SDIO_BASE + SZ_4K - 1, 798c2ecf20Sopenharmony_ci .flags = IORESOURCE_MEM, 808c2ecf20Sopenharmony_ci }, 818c2ecf20Sopenharmony_ci [1] = { 828c2ecf20Sopenharmony_ci .start = IRQ_CNS3XXX_SDIO, 838c2ecf20Sopenharmony_ci .end = IRQ_CNS3XXX_SDIO, 848c2ecf20Sopenharmony_ci .flags = IORESOURCE_IRQ, 858c2ecf20Sopenharmony_ci }, 868c2ecf20Sopenharmony_ci}; 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_cistatic struct platform_device cns3xxx_sdhci_pdev = { 898c2ecf20Sopenharmony_ci .name = "sdhci-cns3xxx", 908c2ecf20Sopenharmony_ci .id = 0, 918c2ecf20Sopenharmony_ci .num_resources = ARRAY_SIZE(cns3xxx_sdhci_resources), 928c2ecf20Sopenharmony_ci .resource = cns3xxx_sdhci_resources, 938c2ecf20Sopenharmony_ci}; 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_civoid __init cns3xxx_sdhci_init(void) 968c2ecf20Sopenharmony_ci{ 978c2ecf20Sopenharmony_ci u32 __iomem *gpioa = IOMEM(CNS3XXX_MISC_BASE_VIRT + 0x0014); 988c2ecf20Sopenharmony_ci u32 gpioa_pins = __raw_readl(gpioa); 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_ci /* MMC/SD pins share with GPIOA */ 1018c2ecf20Sopenharmony_ci gpioa_pins |= 0x1fff0004; 1028c2ecf20Sopenharmony_ci __raw_writel(gpioa_pins, gpioa); 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ci cns3xxx_pwr_clk_en(CNS3XXX_PWR_CLK_EN(SDIO)); 1058c2ecf20Sopenharmony_ci cns3xxx_pwr_soft_rst(CNS3XXX_PWR_SOFTWARE_RST(SDIO)); 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci platform_device_register(&cns3xxx_sdhci_pdev); 1088c2ecf20Sopenharmony_ci} 109