Loc Ho | 81d01bf | 2014-03-14 17:53:20 -0600 | [diff] [blame] | 1 | /* |
| 2 | * AppliedMicro X-Gene SoC SATA Host Controller Driver |
| 3 | * |
| 4 | * Copyright (c) 2014, Applied Micro Circuits Corporation |
| 5 | * Author: Loc Ho <lho@apm.com> |
| 6 | * Tuan Phan <tphan@apm.com> |
| 7 | * Suman Tripathi <stripathi@apm.com> |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify it |
| 10 | * under the terms of the GNU General Public License as published by the |
| 11 | * Free Software Foundation; either version 2 of the License, or (at your |
| 12 | * option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 | * |
| 22 | * NOTE: PM support is not currently available. |
| 23 | * |
| 24 | */ |
| 25 | #include <linux/module.h> |
| 26 | #include <linux/platform_device.h> |
| 27 | #include <linux/ahci_platform.h> |
| 28 | #include <linux/of_address.h> |
| 29 | #include <linux/of_irq.h> |
| 30 | #include <linux/phy/phy.h> |
| 31 | #include "ahci.h" |
| 32 | |
| 33 | /* Max # of disk per a controller */ |
| 34 | #define MAX_AHCI_CHN_PERCTR 2 |
| 35 | |
| 36 | /* MUX CSR */ |
| 37 | #define SATA_ENET_CONFIG_REG 0x00000000 |
| 38 | #define CFG_SATA_ENET_SELECT_MASK 0x00000001 |
| 39 | |
| 40 | /* SATA core host controller CSR */ |
| 41 | #define SLVRDERRATTRIBUTES 0x00000000 |
| 42 | #define SLVWRERRATTRIBUTES 0x00000004 |
| 43 | #define MSTRDERRATTRIBUTES 0x00000008 |
| 44 | #define MSTWRERRATTRIBUTES 0x0000000c |
| 45 | #define BUSCTLREG 0x00000014 |
| 46 | #define IOFMSTRWAUX 0x00000018 |
| 47 | #define INTSTATUSMASK 0x0000002c |
| 48 | #define ERRINTSTATUS 0x00000030 |
| 49 | #define ERRINTSTATUSMASK 0x00000034 |
| 50 | |
| 51 | /* SATA host AHCI CSR */ |
| 52 | #define PORTCFG 0x000000a4 |
| 53 | #define PORTADDR_SET(dst, src) \ |
| 54 | (((dst) & ~0x0000003f) | (((u32)(src)) & 0x0000003f)) |
| 55 | #define PORTPHY1CFG 0x000000a8 |
| 56 | #define PORTPHY1CFG_FRCPHYRDY_SET(dst, src) \ |
| 57 | (((dst) & ~0x00100000) | (((u32)(src) << 0x14) & 0x00100000)) |
| 58 | #define PORTPHY2CFG 0x000000ac |
| 59 | #define PORTPHY3CFG 0x000000b0 |
| 60 | #define PORTPHY4CFG 0x000000b4 |
| 61 | #define PORTPHY5CFG 0x000000b8 |
| 62 | #define SCTL0 0x0000012C |
| 63 | #define PORTPHY5CFG_RTCHG_SET(dst, src) \ |
| 64 | (((dst) & ~0xfff00000) | (((u32)(src) << 0x14) & 0xfff00000)) |
| 65 | #define PORTAXICFG_EN_CONTEXT_SET(dst, src) \ |
| 66 | (((dst) & ~0x01000000) | (((u32)(src) << 0x18) & 0x01000000)) |
| 67 | #define PORTAXICFG 0x000000bc |
| 68 | #define PORTAXICFG_OUTTRANS_SET(dst, src) \ |
| 69 | (((dst) & ~0x00f00000) | (((u32)(src) << 0x14) & 0x00f00000)) |
Suman Tripathi | aeae4dc | 2014-07-29 12:24:49 +0530 | [diff] [blame] | 70 | #define PORTRANSCFG 0x000000c8 |
| 71 | #define PORTRANSCFG_RXWM_SET(dst, src) \ |
| 72 | (((dst) & ~0x0000007f) | (((u32)(src)) & 0x0000007f)) |
Loc Ho | 81d01bf | 2014-03-14 17:53:20 -0600 | [diff] [blame] | 73 | |
| 74 | /* SATA host controller AXI CSR */ |
| 75 | #define INT_SLV_TMOMASK 0x00000010 |
| 76 | |
| 77 | /* SATA diagnostic CSR */ |
| 78 | #define CFG_MEM_RAM_SHUTDOWN 0x00000070 |
| 79 | #define BLOCK_MEM_RDY 0x00000074 |
| 80 | |
| 81 | struct xgene_ahci_context { |
| 82 | struct ahci_host_priv *hpriv; |
| 83 | struct device *dev; |
Suman Tripathi | 2a0bdff | 2014-07-07 22:33:05 +0530 | [diff] [blame] | 84 | u8 last_cmd[MAX_AHCI_CHN_PERCTR]; /* tracking the last command issued*/ |
Loc Ho | 81d01bf | 2014-03-14 17:53:20 -0600 | [diff] [blame] | 85 | void __iomem *csr_core; /* Core CSR address of IP */ |
| 86 | void __iomem *csr_diag; /* Diag CSR address of IP */ |
| 87 | void __iomem *csr_axi; /* AXI CSR address of IP */ |
| 88 | void __iomem *csr_mux; /* MUX CSR address of IP */ |
| 89 | }; |
| 90 | |
| 91 | static int xgene_ahci_init_memram(struct xgene_ahci_context *ctx) |
| 92 | { |
| 93 | dev_dbg(ctx->dev, "Release memory from shutdown\n"); |
| 94 | writel(0x0, ctx->csr_diag + CFG_MEM_RAM_SHUTDOWN); |
| 95 | readl(ctx->csr_diag + CFG_MEM_RAM_SHUTDOWN); /* Force a barrier */ |
| 96 | msleep(1); /* reset may take up to 1ms */ |
| 97 | if (readl(ctx->csr_diag + BLOCK_MEM_RDY) != 0xFFFFFFFF) { |
| 98 | dev_err(ctx->dev, "failed to release memory from shutdown\n"); |
| 99 | return -ENODEV; |
| 100 | } |
| 101 | return 0; |
| 102 | } |
| 103 | |
| 104 | /** |
Suman Tripathi | 2a0bdff | 2014-07-07 22:33:05 +0530 | [diff] [blame] | 105 | * xgene_ahci_restart_engine - Restart the dma engine. |
| 106 | * @ap : ATA port of interest |
| 107 | * |
| 108 | * Restarts the dma engine inside the controller. |
| 109 | */ |
| 110 | static int xgene_ahci_restart_engine(struct ata_port *ap) |
| 111 | { |
| 112 | struct ahci_host_priv *hpriv = ap->host->private_data; |
| 113 | |
| 114 | ahci_stop_engine(ap); |
| 115 | ahci_start_fis_rx(ap); |
| 116 | hpriv->start_engine(ap); |
| 117 | |
| 118 | return 0; |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * xgene_ahci_qc_issue - Issue commands to the device |
| 123 | * @qc: Command to issue |
| 124 | * |
| 125 | * Due to Hardware errata for IDENTIFY DEVICE command, the controller cannot |
| 126 | * clear the BSY bit after receiving the PIO setup FIS. This results in the dma |
| 127 | * state machine goes into the CMFatalErrorUpdate state and locks up. By |
| 128 | * restarting the dma engine, it removes the controller out of lock up state. |
| 129 | */ |
| 130 | static unsigned int xgene_ahci_qc_issue(struct ata_queued_cmd *qc) |
| 131 | { |
| 132 | struct ata_port *ap = qc->ap; |
| 133 | struct ahci_host_priv *hpriv = ap->host->private_data; |
| 134 | struct xgene_ahci_context *ctx = hpriv->plat_data; |
| 135 | int rc = 0; |
| 136 | |
| 137 | if (unlikely(ctx->last_cmd[ap->port_no] == ATA_CMD_ID_ATA)) |
| 138 | xgene_ahci_restart_engine(ap); |
| 139 | |
| 140 | rc = ahci_qc_issue(qc); |
| 141 | |
| 142 | /* Save the last command issued */ |
| 143 | ctx->last_cmd[ap->port_no] = qc->tf.command; |
| 144 | |
| 145 | return rc; |
| 146 | } |
| 147 | |
Suman Tripathi | 0bed13b | 2014-08-28 14:51:21 +0530 | [diff] [blame^] | 148 | static bool xgene_ahci_is_memram_inited(struct xgene_ahci_context *ctx) |
| 149 | { |
| 150 | void __iomem *diagcsr = ctx->csr_diag; |
| 151 | |
| 152 | return (readl(diagcsr + CFG_MEM_RAM_SHUTDOWN) == 0 && |
| 153 | readl(diagcsr + BLOCK_MEM_RDY) == 0xFFFFFFFF); |
| 154 | } |
| 155 | |
Suman Tripathi | 2a0bdff | 2014-07-07 22:33:05 +0530 | [diff] [blame] | 156 | /** |
Loc Ho | 81d01bf | 2014-03-14 17:53:20 -0600 | [diff] [blame] | 157 | * xgene_ahci_read_id - Read ID data from the specified device |
| 158 | * @dev: device |
| 159 | * @tf: proposed taskfile |
| 160 | * @id: data buffer |
| 161 | * |
| 162 | * This custom read ID function is required due to the fact that the HW |
Suman Tripathi | 2a0bdff | 2014-07-07 22:33:05 +0530 | [diff] [blame] | 163 | * does not support DEVSLP. |
Loc Ho | 81d01bf | 2014-03-14 17:53:20 -0600 | [diff] [blame] | 164 | */ |
| 165 | static unsigned int xgene_ahci_read_id(struct ata_device *dev, |
| 166 | struct ata_taskfile *tf, u16 *id) |
| 167 | { |
| 168 | u32 err_mask; |
Loc Ho | 81d01bf | 2014-03-14 17:53:20 -0600 | [diff] [blame] | 169 | |
| 170 | err_mask = ata_do_dev_read_id(dev, tf, id); |
| 171 | if (err_mask) |
| 172 | return err_mask; |
| 173 | |
| 174 | /* |
| 175 | * Mask reserved area. Word78 spec of Link Power Management |
| 176 | * bit15-8: reserved |
| 177 | * bit7: NCQ autosence |
| 178 | * bit6: Software settings preservation supported |
| 179 | * bit5: reserved |
| 180 | * bit4: In-order sata delivery supported |
| 181 | * bit3: DIPM requests supported |
| 182 | * bit2: DMA Setup FIS Auto-Activate optimization supported |
| 183 | * bit1: DMA Setup FIX non-Zero buffer offsets supported |
| 184 | * bit0: Reserved |
| 185 | * |
| 186 | * Clear reserved bit 8 (DEVSLP bit) as we don't support DEVSLP |
| 187 | */ |
| 188 | id[ATA_ID_FEATURE_SUPP] &= ~(1 << 8); |
| 189 | |
Loc Ho | 81d01bf | 2014-03-14 17:53:20 -0600 | [diff] [blame] | 190 | return 0; |
| 191 | } |
| 192 | |
| 193 | static void xgene_ahci_set_phy_cfg(struct xgene_ahci_context *ctx, int channel) |
| 194 | { |
| 195 | void __iomem *mmio = ctx->hpriv->mmio; |
| 196 | u32 val; |
| 197 | |
| 198 | dev_dbg(ctx->dev, "port configure mmio 0x%p channel %d\n", |
| 199 | mmio, channel); |
| 200 | val = readl(mmio + PORTCFG); |
| 201 | val = PORTADDR_SET(val, channel == 0 ? 2 : 3); |
| 202 | writel(val, mmio + PORTCFG); |
| 203 | readl(mmio + PORTCFG); /* Force a barrier */ |
| 204 | /* Disable fix rate */ |
| 205 | writel(0x0001fffe, mmio + PORTPHY1CFG); |
| 206 | readl(mmio + PORTPHY1CFG); /* Force a barrier */ |
Suman Tripathi | 0185b1b | 2014-07-29 12:24:51 +0530 | [diff] [blame] | 207 | writel(0x28183219, mmio + PORTPHY2CFG); |
Loc Ho | 81d01bf | 2014-03-14 17:53:20 -0600 | [diff] [blame] | 208 | readl(mmio + PORTPHY2CFG); /* Force a barrier */ |
Suman Tripathi | 0185b1b | 2014-07-29 12:24:51 +0530 | [diff] [blame] | 209 | writel(0x13081008, mmio + PORTPHY3CFG); |
Loc Ho | 81d01bf | 2014-03-14 17:53:20 -0600 | [diff] [blame] | 210 | readl(mmio + PORTPHY3CFG); /* Force a barrier */ |
Suman Tripathi | 0185b1b | 2014-07-29 12:24:51 +0530 | [diff] [blame] | 211 | writel(0x00480815, mmio + PORTPHY4CFG); |
Loc Ho | 81d01bf | 2014-03-14 17:53:20 -0600 | [diff] [blame] | 212 | readl(mmio + PORTPHY4CFG); /* Force a barrier */ |
| 213 | /* Set window negotiation */ |
| 214 | val = readl(mmio + PORTPHY5CFG); |
| 215 | val = PORTPHY5CFG_RTCHG_SET(val, 0x300); |
| 216 | writel(val, mmio + PORTPHY5CFG); |
| 217 | readl(mmio + PORTPHY5CFG); /* Force a barrier */ |
| 218 | val = readl(mmio + PORTAXICFG); |
| 219 | val = PORTAXICFG_EN_CONTEXT_SET(val, 0x1); /* Enable context mgmt */ |
| 220 | val = PORTAXICFG_OUTTRANS_SET(val, 0xe); /* Set outstanding */ |
| 221 | writel(val, mmio + PORTAXICFG); |
| 222 | readl(mmio + PORTAXICFG); /* Force a barrier */ |
Suman Tripathi | aeae4dc | 2014-07-29 12:24:49 +0530 | [diff] [blame] | 223 | /* Set the watermark threshold of the receive FIFO */ |
| 224 | val = readl(mmio + PORTRANSCFG); |
| 225 | val = PORTRANSCFG_RXWM_SET(val, 0x30); |
| 226 | writel(val, mmio + PORTRANSCFG); |
Loc Ho | 81d01bf | 2014-03-14 17:53:20 -0600 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | /** |
| 230 | * xgene_ahci_do_hardreset - Issue the actual COMRESET |
| 231 | * @link: link to reset |
| 232 | * @deadline: deadline jiffies for the operation |
| 233 | * @online: Return value to indicate if device online |
| 234 | * |
| 235 | * Due to the limitation of the hardware PHY, a difference set of setting is |
| 236 | * required for each supported disk speed - Gen3 (6.0Gbps), Gen2 (3.0Gbps), |
| 237 | * and Gen1 (1.5Gbps). Otherwise during long IO stress test, the PHY will |
| 238 | * report disparity error and etc. In addition, during COMRESET, there can |
| 239 | * be error reported in the register PORT_SCR_ERR. For SERR_DISPARITY and |
| 240 | * SERR_10B_8B_ERR, the PHY receiver line must be reseted. The following |
| 241 | * algorithm is followed to proper configure the hardware PHY during COMRESET: |
| 242 | * |
| 243 | * Alg Part 1: |
| 244 | * 1. Start the PHY at Gen3 speed (default setting) |
| 245 | * 2. Issue the COMRESET |
| 246 | * 3. If no link, go to Alg Part 3 |
| 247 | * 4. If link up, determine if the negotiated speed matches the PHY |
| 248 | * configured speed |
| 249 | * 5. If they matched, go to Alg Part 2 |
| 250 | * 6. If they do not matched and first time, configure the PHY for the linked |
| 251 | * up disk speed and repeat step 2 |
| 252 | * 7. Go to Alg Part 2 |
| 253 | * |
| 254 | * Alg Part 2: |
| 255 | * 1. On link up, if there are any SERR_DISPARITY and SERR_10B_8B_ERR error |
| 256 | * reported in the register PORT_SCR_ERR, then reset the PHY receiver line |
| 257 | * 2. Go to Alg Part 3 |
| 258 | * |
| 259 | * Alg Part 3: |
| 260 | * 1. Clear any pending from register PORT_SCR_ERR. |
| 261 | * |
| 262 | * NOTE: For the initial version, we will NOT support Gen1/Gen2. In addition |
| 263 | * and until the underlying PHY supports an method to reset the receiver |
| 264 | * line, on detection of SERR_DISPARITY or SERR_10B_8B_ERR errors, |
| 265 | * an warning message will be printed. |
| 266 | */ |
| 267 | static int xgene_ahci_do_hardreset(struct ata_link *link, |
| 268 | unsigned long deadline, bool *online) |
| 269 | { |
| 270 | const unsigned long *timing = sata_ehc_deb_timing(&link->eh_context); |
| 271 | struct ata_port *ap = link->ap; |
| 272 | struct ahci_host_priv *hpriv = ap->host->private_data; |
| 273 | struct xgene_ahci_context *ctx = hpriv->plat_data; |
| 274 | struct ahci_port_priv *pp = ap->private_data; |
| 275 | u8 *d2h_fis = pp->rx_fis + RX_FIS_D2H_REG; |
| 276 | void __iomem *port_mmio = ahci_port_base(ap); |
| 277 | struct ata_taskfile tf; |
| 278 | int rc; |
| 279 | u32 val; |
| 280 | |
| 281 | /* clear D2H reception area to properly wait for D2H FIS */ |
| 282 | ata_tf_init(link->device, &tf); |
| 283 | tf.command = ATA_BUSY; |
| 284 | ata_tf_to_fis(&tf, 0, 0, d2h_fis); |
| 285 | rc = sata_link_hardreset(link, timing, deadline, online, |
| 286 | ahci_check_ready); |
| 287 | |
| 288 | val = readl(port_mmio + PORT_SCR_ERR); |
| 289 | if (val & (SERR_DISPARITY | SERR_10B_8B_ERR)) |
| 290 | dev_warn(ctx->dev, "link has error\n"); |
| 291 | |
| 292 | /* clear all errors if any pending */ |
| 293 | val = readl(port_mmio + PORT_SCR_ERR); |
| 294 | writel(val, port_mmio + PORT_SCR_ERR); |
| 295 | |
| 296 | return rc; |
| 297 | } |
| 298 | |
| 299 | static int xgene_ahci_hardreset(struct ata_link *link, unsigned int *class, |
| 300 | unsigned long deadline) |
| 301 | { |
| 302 | struct ata_port *ap = link->ap; |
| 303 | struct ahci_host_priv *hpriv = ap->host->private_data; |
| 304 | void __iomem *port_mmio = ahci_port_base(ap); |
| 305 | bool online; |
| 306 | int rc; |
| 307 | u32 portcmd_saved; |
| 308 | u32 portclb_saved; |
| 309 | u32 portclbhi_saved; |
| 310 | u32 portrxfis_saved; |
| 311 | u32 portrxfishi_saved; |
| 312 | |
| 313 | /* As hardreset resets these CSR, save it to restore later */ |
| 314 | portcmd_saved = readl(port_mmio + PORT_CMD); |
| 315 | portclb_saved = readl(port_mmio + PORT_LST_ADDR); |
| 316 | portclbhi_saved = readl(port_mmio + PORT_LST_ADDR_HI); |
| 317 | portrxfis_saved = readl(port_mmio + PORT_FIS_ADDR); |
| 318 | portrxfishi_saved = readl(port_mmio + PORT_FIS_ADDR_HI); |
| 319 | |
| 320 | ahci_stop_engine(ap); |
| 321 | |
| 322 | rc = xgene_ahci_do_hardreset(link, deadline, &online); |
| 323 | |
| 324 | /* As controller hardreset clears them, restore them */ |
| 325 | writel(portcmd_saved, port_mmio + PORT_CMD); |
| 326 | writel(portclb_saved, port_mmio + PORT_LST_ADDR); |
| 327 | writel(portclbhi_saved, port_mmio + PORT_LST_ADDR_HI); |
| 328 | writel(portrxfis_saved, port_mmio + PORT_FIS_ADDR); |
| 329 | writel(portrxfishi_saved, port_mmio + PORT_FIS_ADDR_HI); |
| 330 | |
| 331 | hpriv->start_engine(ap); |
| 332 | |
| 333 | if (online) |
| 334 | *class = ahci_dev_classify(ap); |
| 335 | |
| 336 | return rc; |
| 337 | } |
| 338 | |
| 339 | static void xgene_ahci_host_stop(struct ata_host *host) |
| 340 | { |
| 341 | struct ahci_host_priv *hpriv = host->private_data; |
| 342 | |
| 343 | ahci_platform_disable_resources(hpriv); |
| 344 | } |
| 345 | |
| 346 | static struct ata_port_operations xgene_ahci_ops = { |
| 347 | .inherits = &ahci_ops, |
| 348 | .host_stop = xgene_ahci_host_stop, |
| 349 | .hardreset = xgene_ahci_hardreset, |
| 350 | .read_id = xgene_ahci_read_id, |
Suman Tripathi | 2a0bdff | 2014-07-07 22:33:05 +0530 | [diff] [blame] | 351 | .qc_issue = xgene_ahci_qc_issue, |
Loc Ho | 81d01bf | 2014-03-14 17:53:20 -0600 | [diff] [blame] | 352 | }; |
| 353 | |
| 354 | static const struct ata_port_info xgene_ahci_port_info = { |
Suman Tripathi | 72f79f9 | 2014-08-08 21:44:25 +0530 | [diff] [blame] | 355 | .flags = AHCI_FLAG_COMMON, |
Loc Ho | 81d01bf | 2014-03-14 17:53:20 -0600 | [diff] [blame] | 356 | .pio_mask = ATA_PIO4, |
| 357 | .udma_mask = ATA_UDMA6, |
| 358 | .port_ops = &xgene_ahci_ops, |
| 359 | }; |
| 360 | |
| 361 | static int xgene_ahci_hw_init(struct ahci_host_priv *hpriv) |
| 362 | { |
| 363 | struct xgene_ahci_context *ctx = hpriv->plat_data; |
| 364 | int i; |
| 365 | int rc; |
| 366 | u32 val; |
| 367 | |
| 368 | /* Remove IP RAM out of shutdown */ |
| 369 | rc = xgene_ahci_init_memram(ctx); |
| 370 | if (rc) |
| 371 | return rc; |
| 372 | |
| 373 | for (i = 0; i < MAX_AHCI_CHN_PERCTR; i++) |
| 374 | xgene_ahci_set_phy_cfg(ctx, i); |
| 375 | |
| 376 | /* AXI disable Mask */ |
| 377 | writel(0xffffffff, hpriv->mmio + HOST_IRQ_STAT); |
| 378 | readl(hpriv->mmio + HOST_IRQ_STAT); /* Force a barrier */ |
| 379 | writel(0, ctx->csr_core + INTSTATUSMASK); |
Loc Ho | 6a96918 | 2014-03-18 12:14:37 -0600 | [diff] [blame] | 380 | val = readl(ctx->csr_core + INTSTATUSMASK); /* Force a barrier */ |
Loc Ho | 81d01bf | 2014-03-14 17:53:20 -0600 | [diff] [blame] | 381 | dev_dbg(ctx->dev, "top level interrupt mask 0x%X value 0x%08X\n", |
| 382 | INTSTATUSMASK, val); |
| 383 | |
| 384 | writel(0x0, ctx->csr_core + ERRINTSTATUSMASK); |
| 385 | readl(ctx->csr_core + ERRINTSTATUSMASK); /* Force a barrier */ |
| 386 | writel(0x0, ctx->csr_axi + INT_SLV_TMOMASK); |
| 387 | readl(ctx->csr_axi + INT_SLV_TMOMASK); |
| 388 | |
| 389 | /* Enable AXI Interrupt */ |
| 390 | writel(0xffffffff, ctx->csr_core + SLVRDERRATTRIBUTES); |
| 391 | writel(0xffffffff, ctx->csr_core + SLVWRERRATTRIBUTES); |
| 392 | writel(0xffffffff, ctx->csr_core + MSTRDERRATTRIBUTES); |
| 393 | writel(0xffffffff, ctx->csr_core + MSTWRERRATTRIBUTES); |
| 394 | |
| 395 | /* Enable coherency */ |
| 396 | val = readl(ctx->csr_core + BUSCTLREG); |
| 397 | val &= ~0x00000002; /* Enable write coherency */ |
| 398 | val &= ~0x00000001; /* Enable read coherency */ |
| 399 | writel(val, ctx->csr_core + BUSCTLREG); |
| 400 | |
| 401 | val = readl(ctx->csr_core + IOFMSTRWAUX); |
| 402 | val |= (1 << 3); /* Enable read coherency */ |
| 403 | val |= (1 << 9); /* Enable write coherency */ |
| 404 | writel(val, ctx->csr_core + IOFMSTRWAUX); |
| 405 | val = readl(ctx->csr_core + IOFMSTRWAUX); |
| 406 | dev_dbg(ctx->dev, "coherency 0x%X value 0x%08X\n", |
| 407 | IOFMSTRWAUX, val); |
| 408 | |
| 409 | return rc; |
| 410 | } |
| 411 | |
| 412 | static int xgene_ahci_mux_select(struct xgene_ahci_context *ctx) |
| 413 | { |
| 414 | u32 val; |
| 415 | |
| 416 | /* Check for optional MUX resource */ |
| 417 | if (IS_ERR(ctx->csr_mux)) |
| 418 | return 0; |
| 419 | |
| 420 | val = readl(ctx->csr_mux + SATA_ENET_CONFIG_REG); |
| 421 | val &= ~CFG_SATA_ENET_SELECT_MASK; |
| 422 | writel(val, ctx->csr_mux + SATA_ENET_CONFIG_REG); |
| 423 | val = readl(ctx->csr_mux + SATA_ENET_CONFIG_REG); |
| 424 | return val & CFG_SATA_ENET_SELECT_MASK ? -1 : 0; |
| 425 | } |
| 426 | |
| 427 | static int xgene_ahci_probe(struct platform_device *pdev) |
| 428 | { |
| 429 | struct device *dev = &pdev->dev; |
| 430 | struct ahci_host_priv *hpriv; |
| 431 | struct xgene_ahci_context *ctx; |
| 432 | struct resource *res; |
| 433 | int rc; |
| 434 | |
| 435 | hpriv = ahci_platform_get_resources(pdev); |
| 436 | if (IS_ERR(hpriv)) |
| 437 | return PTR_ERR(hpriv); |
| 438 | |
| 439 | ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); |
| 440 | if (!ctx) |
| 441 | return -ENOMEM; |
| 442 | |
| 443 | hpriv->plat_data = ctx; |
| 444 | ctx->hpriv = hpriv; |
| 445 | ctx->dev = dev; |
| 446 | |
| 447 | /* Retrieve the IP core resource */ |
| 448 | res = platform_get_resource(pdev, IORESOURCE_MEM, 1); |
| 449 | ctx->csr_core = devm_ioremap_resource(dev, res); |
| 450 | if (IS_ERR(ctx->csr_core)) |
| 451 | return PTR_ERR(ctx->csr_core); |
| 452 | |
| 453 | /* Retrieve the IP diagnostic resource */ |
| 454 | res = platform_get_resource(pdev, IORESOURCE_MEM, 2); |
| 455 | ctx->csr_diag = devm_ioremap_resource(dev, res); |
| 456 | if (IS_ERR(ctx->csr_diag)) |
| 457 | return PTR_ERR(ctx->csr_diag); |
| 458 | |
| 459 | /* Retrieve the IP AXI resource */ |
| 460 | res = platform_get_resource(pdev, IORESOURCE_MEM, 3); |
| 461 | ctx->csr_axi = devm_ioremap_resource(dev, res); |
| 462 | if (IS_ERR(ctx->csr_axi)) |
| 463 | return PTR_ERR(ctx->csr_axi); |
| 464 | |
| 465 | /* Retrieve the optional IP mux resource */ |
| 466 | res = platform_get_resource(pdev, IORESOURCE_MEM, 4); |
| 467 | ctx->csr_mux = devm_ioremap_resource(dev, res); |
| 468 | |
| 469 | dev_dbg(dev, "VAddr 0x%p Mmio VAddr 0x%p\n", ctx->csr_core, |
| 470 | hpriv->mmio); |
| 471 | |
| 472 | /* Select ATA */ |
| 473 | if ((rc = xgene_ahci_mux_select(ctx))) { |
| 474 | dev_err(dev, "SATA mux selection failed error %d\n", rc); |
| 475 | return -ENODEV; |
| 476 | } |
| 477 | |
Suman Tripathi | 0bed13b | 2014-08-28 14:51:21 +0530 | [diff] [blame^] | 478 | if (xgene_ahci_is_memram_inited(ctx)) { |
| 479 | dev_info(dev, "skip clock and PHY initialization\n"); |
| 480 | goto skip_clk_phy; |
| 481 | } |
| 482 | |
Loc Ho | 81d01bf | 2014-03-14 17:53:20 -0600 | [diff] [blame] | 483 | /* Due to errata, HW requires full toggle transition */ |
| 484 | rc = ahci_platform_enable_clks(hpriv); |
| 485 | if (rc) |
| 486 | goto disable_resources; |
| 487 | ahci_platform_disable_clks(hpriv); |
| 488 | |
| 489 | rc = ahci_platform_enable_resources(hpriv); |
| 490 | if (rc) |
| 491 | goto disable_resources; |
| 492 | |
| 493 | /* Configure the host controller */ |
| 494 | xgene_ahci_hw_init(hpriv); |
Suman Tripathi | 0bed13b | 2014-08-28 14:51:21 +0530 | [diff] [blame^] | 495 | skip_clk_phy: |
Suman Tripathi | 72f79f9 | 2014-08-08 21:44:25 +0530 | [diff] [blame] | 496 | hpriv->flags = AHCI_HFLAG_NO_PMP | AHCI_HFLAG_NO_NCQ; |
Kefeng Wang | f9f3691 | 2014-05-14 14:13:41 +0800 | [diff] [blame] | 497 | |
Antoine Ténart | 725c7b5 | 2014-07-30 20:13:56 +0200 | [diff] [blame] | 498 | rc = ahci_platform_init_host(pdev, hpriv, &xgene_ahci_port_info); |
Loc Ho | 81d01bf | 2014-03-14 17:53:20 -0600 | [diff] [blame] | 499 | if (rc) |
| 500 | goto disable_resources; |
| 501 | |
| 502 | dev_dbg(dev, "X-Gene SATA host controller initialized\n"); |
| 503 | return 0; |
| 504 | |
| 505 | disable_resources: |
| 506 | ahci_platform_disable_resources(hpriv); |
| 507 | return rc; |
| 508 | } |
| 509 | |
| 510 | static const struct of_device_id xgene_ahci_of_match[] = { |
| 511 | {.compatible = "apm,xgene-ahci"}, |
| 512 | {}, |
| 513 | }; |
| 514 | MODULE_DEVICE_TABLE(of, xgene_ahci_of_match); |
| 515 | |
| 516 | static struct platform_driver xgene_ahci_driver = { |
| 517 | .probe = xgene_ahci_probe, |
| 518 | .remove = ata_platform_remove_one, |
| 519 | .driver = { |
| 520 | .name = "xgene-ahci", |
| 521 | .owner = THIS_MODULE, |
| 522 | .of_match_table = xgene_ahci_of_match, |
| 523 | }, |
| 524 | }; |
| 525 | |
| 526 | module_platform_driver(xgene_ahci_driver); |
| 527 | |
| 528 | MODULE_DESCRIPTION("APM X-Gene AHCI SATA driver"); |
| 529 | MODULE_AUTHOR("Loc Ho <lho@apm.com>"); |
| 530 | MODULE_LICENSE("GPL"); |
| 531 | MODULE_VERSION("0.4"); |