uboot/arch/powerpc/lib/ide.c
<<
>>
Prefs
   1/*
   2 * (C) Copyright 2000-2011
   3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
   4 *
   5 * SPDX-License-Identifier:     GPL-2.0+
   6 */
   7
   8/* Code taken from cmd_ide.c */
   9#include <common.h>
  10#include <ata.h>
  11#include "ide.h"
  12
  13#ifdef CONFIG_IDE_8xx_DIRECT
  14#include <mpc8xx.h>
  15#include <pcmcia.h>
  16DECLARE_GLOBAL_DATA_PTR;
  17
  18/* Timings for IDE Interface
  19 *
  20 * SETUP / LENGTH / HOLD - cycles valid for 50 MHz clk
  21 * 70      165      30     PIO-Mode 0, [ns]
  22 *  4        9       2                 [Cycles]
  23 * 50      125      20     PIO-Mode 1, [ns]
  24 *  3        7       2                 [Cycles]
  25 * 30      100      15     PIO-Mode 2, [ns]
  26 *  2        6       1                 [Cycles]
  27 * 30       80      10     PIO-Mode 3, [ns]
  28 *  2        5       1                 [Cycles]
  29 * 25       70      10     PIO-Mode 4, [ns]
  30 *  2        4       1                 [Cycles]
  31 */
  32
  33static const pio_config_t pio_config_ns[IDE_MAX_PIO_MODE+1] = {
  34    /*  Setup  Length  Hold  */
  35        { 70,   165,    30 },           /* PIO-Mode 0, [ns]     */
  36        { 50,   125,    20 },           /* PIO-Mode 1, [ns]     */
  37        { 30,   101,    15 },           /* PIO-Mode 2, [ns]     */
  38        { 30,    80,    10 },           /* PIO-Mode 3, [ns]     */
  39        { 25,    70,    10 },           /* PIO-Mode 4, [ns]     */
  40};
  41
  42static pio_config_t pio_config_clk[IDE_MAX_PIO_MODE+1];
  43
  44#ifndef CONFIG_SYS_PIO_MODE
  45#define CONFIG_SYS_PIO_MODE     0       /* use a relaxed default */
  46#endif
  47static int pio_mode = CONFIG_SYS_PIO_MODE;
  48
  49/* Make clock cycles and always round up */
  50
  51#define PCMCIA_MK_CLKS(t, T) (((t) * (T) + 999U) / 1000U)
  52
  53static void set_pcmcia_timing(int pmode)
  54{
  55        volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
  56        volatile pcmconf8xx_t *pcmp = &(immr->im_pcmcia);
  57        ulong timings;
  58
  59        debug("Set timing for PIO Mode %d\n", pmode);
  60
  61        timings = PCMCIA_SHT(pio_config_clk[pmode].t_hold)
  62                | PCMCIA_SST(pio_config_clk[pmode].t_setup)
  63                | PCMCIA_SL(pio_config_clk[pmode].t_length);
  64
  65        /*
  66         * IDE 0
  67         */
  68        pcmp->pcmc_pbr0 = CONFIG_SYS_PCMCIA_PBR0;
  69#if (CONFIG_SYS_PCMCIA_POR0 != 0)
  70        pcmp->pcmc_por0 = CONFIG_SYS_PCMCIA_POR0 | timings;
  71#else
  72        pcmp->pcmc_por0 = CONFIG_SYS_PCMCIA_POR0;
  73#endif
  74        debug("PBR0: %08x  POR0: %08x\n", pcmp->pcmc_pbr0, pcmp->pcmc_por0);
  75
  76        pcmp->pcmc_pbr1 = CONFIG_SYS_PCMCIA_PBR1;
  77#if (CONFIG_SYS_PCMCIA_POR1 != 0)
  78        pcmp->pcmc_por1 = CONFIG_SYS_PCMCIA_POR1 | timings;
  79#else
  80        pcmp->pcmc_por1 = CONFIG_SYS_PCMCIA_POR1;
  81#endif
  82        debug("PBR1: %08x  POR1: %08x\n", pcmp->pcmc_pbr1, pcmp->pcmc_por1);
  83
  84        pcmp->pcmc_pbr2 = CONFIG_SYS_PCMCIA_PBR2;
  85#if (CONFIG_SYS_PCMCIA_POR2 != 0)
  86        pcmp->pcmc_por2 = CONFIG_SYS_PCMCIA_POR2 | timings;
  87#else
  88        pcmp->pcmc_por2 = CONFIG_SYS_PCMCIA_POR2;
  89#endif
  90        debug("PBR2: %08x  POR2: %08x\n", pcmp->pcmc_pbr2, pcmp->pcmc_por2);
  91
  92        pcmp->pcmc_pbr3 = CONFIG_SYS_PCMCIA_PBR3;
  93#if (CONFIG_SYS_PCMCIA_POR3 != 0)
  94        pcmp->pcmc_por3 = CONFIG_SYS_PCMCIA_POR3 | timings;
  95#else
  96        pcmp->pcmc_por3 = CONFIG_SYS_PCMCIA_POR3;
  97#endif
  98        debug("PBR3: %08x  POR3: %08x\n", pcmp->pcmc_pbr3, pcmp->pcmc_por3);
  99
 100        /*
 101         * IDE 1
 102         */
 103        pcmp->pcmc_pbr4 = CONFIG_SYS_PCMCIA_PBR4;
 104#if (CONFIG_SYS_PCMCIA_POR4 != 0)
 105        pcmp->pcmc_por4 = CONFIG_SYS_PCMCIA_POR4 | timings;
 106#else
 107        pcmp->pcmc_por4 = CONFIG_SYS_PCMCIA_POR4;
 108#endif
 109        debug("PBR4: %08x  POR4: %08x\n", pcmp->pcmc_pbr4, pcmp->pcmc_por4);
 110
 111        pcmp->pcmc_pbr5 = CONFIG_SYS_PCMCIA_PBR5;
 112#if (CONFIG_SYS_PCMCIA_POR5 != 0)
 113        pcmp->pcmc_por5 = CONFIG_SYS_PCMCIA_POR5 | timings;
 114#else
 115        pcmp->pcmc_por5 = CONFIG_SYS_PCMCIA_POR5;
 116#endif
 117        debug("PBR5: %08x  POR5: %08x\n", pcmp->pcmc_pbr5, pcmp->pcmc_por5);
 118
 119        pcmp->pcmc_pbr6 = CONFIG_SYS_PCMCIA_PBR6;
 120#if (CONFIG_SYS_PCMCIA_POR6 != 0)
 121        pcmp->pcmc_por6 = CONFIG_SYS_PCMCIA_POR6 | timings;
 122#else
 123        pcmp->pcmc_por6 = CONFIG_SYS_PCMCIA_POR6;
 124#endif
 125        debug("PBR6: %08x  POR6: %08x\n", pcmp->pcmc_pbr6, pcmp->pcmc_por6);
 126
 127        pcmp->pcmc_pbr7 = CONFIG_SYS_PCMCIA_PBR7;
 128#if (CONFIG_SYS_PCMCIA_POR7 != 0)
 129        pcmp->pcmc_por7 = CONFIG_SYS_PCMCIA_POR7 | timings;
 130#else
 131        pcmp->pcmc_por7 = CONFIG_SYS_PCMCIA_POR7;
 132#endif
 133        debug("PBR7: %08x  POR7: %08x\n", pcmp->pcmc_pbr7, pcmp->pcmc_por7);
 134
 135}
 136
 137int ide_preinit(void)
 138{
 139        int i;
 140        /* Initialize PIO timing tables */
 141        for (i = 0; i <= IDE_MAX_PIO_MODE; ++i) {
 142                pio_config_clk[i].t_setup =
 143                        PCMCIA_MK_CLKS(pio_config_ns[i].t_setup, gd->bus_clk);
 144                pio_config_clk[i].t_length =
 145                        PCMCIA_MK_CLKS(pio_config_ns[i].t_length, gd->bus_clk);
 146                pio_config_clk[i].t_hold =
 147                        PCMCIA_MK_CLKS(pio_config_ns[i].t_hold, gd->bus_clk);
 148                debug("PIO Mode %d: setup=%2d ns/%d clk" "  len=%3d ns/%d clk"
 149                        "  hold=%2d ns/%d clk\n", i, pio_config_ns[i].t_setup,
 150                        pio_config_clk[i].t_setup, pio_config_ns[i].t_length,
 151                        pio_config_clk[i].t_length, pio_config_ns[i].t_hold,
 152                        pio_config_clk[i].t_hold);
 153        }
 154
 155        return 0;
 156}
 157
 158int ide_init_postreset(void)
 159{
 160        volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
 161        volatile pcmconf8xx_t *pcmp = &(immr->im_pcmcia);
 162
 163        /* PCMCIA / IDE initialization for common mem space */
 164        pcmp->pcmc_pgcrb = 0;
 165
 166        /* start in PIO mode 0 - most relaxed timings */
 167        pio_mode = 0;
 168        set_pcmcia_timing(pio_mode);
 169        return 0;
 170}
 171#endif /* CONFIG_IDE_8xx_DIRECT */
 172
 173#ifdef CONFIG_IDE_8xx_PCCARD
 174int ide_preinit(void)
 175{
 176        ide_devices_found = 0;
 177        /* initialize the PCMCIA IDE adapter card */
 178        pcmcia_on();
 179        if (!ide_devices_found)
 180                return 1;
 181        udelay(1000000);/* 1 s */
 182        return 0;
 183}
 184#endif
 185