source: rtems/c/src/lib/libbsp/powerpc/mpc55xxevb/startup/sd-card-init.c @ dafacfa7

4.115
Last change on this file since dafacfa7 was a762dc2, checked in by Sebastian Huber <sebastian.huber@…>, on 01/23/12 at 10:19:22

Support for MPC5643L.

Rework of the start sequence to reduce the amount assembler code and to
support configuration tables which may be provided by the application.

  • Property mode set to 100644
File size: 3.6 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup mpc55xx
5 *
6 * @brief SD Card initialization code.
7 */
8
9/*
10 * Copyright (c) 2008
11 * Embedded Brains GmbH
12 * Obere Lagerstr. 30
13 * D-82178 Puchheim
14 * Germany
15 * rtems@embedded-brains.de
16 *
17 * The license and distribution terms for this file may be found in the file
18 * LICENSE in this distribution or at http://www.rtems.com/license/LICENSE.
19 */
20
21#include <stdio.h>
22
23#include <mpc55xx/mpc55xx.h>
24#include <mpc55xx/regs.h>
25#include <mpc55xx/dspi.h>
26
27#include <bsp.h>
28
29#include <rtems/status-checks.h>
30
31#ifdef MPC55XX_BOARD_MPC5566EVB
32
33static rtems_status_code mpc55xx_dspi_init(void)
34{
35        int rv = 0;
36        int i = 0;
37        char device_name [] = "/dev/spi0";
38        union SIU_PCR_tag pcr = MPC55XX_ZERO_FLAGS;
39
40        rv = rtems_libi2c_initialize();
41        RTEMS_CHECK_RV_SC( rv, "rtems_libi2c_initialize");
42
43        /* DSPI D inputs are taken from DSPI C */
44        SIU.DISR.R = 0x000000FC;
45
46        /* DSPI A signals */
47        pcr.B.PA = 1;
48        pcr.B.ODE = 0;
49        pcr.B.HYS = 0;
50        pcr.B.SRC = 3;
51        pcr.B.WPE = 1;
52        pcr.B.WPS = 1;
53
54        /* SCK */
55        pcr.B.OBE = 1;
56        pcr.B.IBE = 0;
57        SIU.PCR [93].R = pcr.R;
58
59        /* SIN */
60        pcr.B.OBE = 0;
61        pcr.B.IBE = 1;
62        SIU.PCR [94].R = pcr.R;
63
64        /* SOUT */
65        pcr.B.OBE = 1;
66        pcr.B.IBE = 0;
67        SIU.PCR [95].R = pcr.R;
68
69        /* PCSx */
70        pcr.B.OBE = 1;
71        pcr.B.IBE = 0;
72        SIU.PCR [96].R = pcr.R;
73        SIU.PCR [97].R = pcr.R;
74        SIU.PCR [98].R = pcr.R;
75        SIU.PCR [99].R = pcr.R;
76        SIU.PCR [100].R = pcr.R;
77        SIU.PCR [101].R = pcr.R;
78
79        mpc55xx_dspi_bus_table [3].master = 0;
80        for (i = 0; i < MPC55XX_DSPI_NUMBER; ++i) {
81                device_name [8] = (char) ('0' + i);
82                rv = rtems_libi2c_register_bus( device_name, (rtems_libi2c_bus_t *) &mpc55xx_dspi_bus_table [i]);
83                RTEMS_CHECK_RV_SC( rv, device_name);
84        }
85
86        return RTEMS_SUCCESSFUL;
87}
88
89#include <stdio.h>
90#include <rtems/fsmount.h>
91#include <rtems/dosfs.h>
92#include <rtems/bdpart.h>
93#include <rtems/console.h>
94
95#include <libchip/spi-sd-card.h>
96
97#define MPC55XX_DEVICE "sd-card-a"
98#define MPC55XX_DEVICE_FILE "/dev/" MPC55XX_DEVICE
99#define MPC55XX_PARTITION "/dev/sd-card-a1"
100#define MPC55XX_MOUNT_POINT "/mnt"
101
102static fstab_t mpc55xx_fs_table [] = { {
103                MPC55XX_PARTITION, MPC55XX_MOUNT_POINT,
104                "dosfs", RTEMS_FILESYSTEM_READ_WRITE,
105                FSMOUNT_MNT_OK | FSMOUNT_MNTPNT_CRTERR | FSMOUNT_MNT_FAILED,
106                FSMOUNT_MNT_OK
107        }, {
108                MPC55XX_DEVICE_FILE, MPC55XX_MOUNT_POINT,
109                "dosfs", RTEMS_FILESYSTEM_READ_WRITE,
110                FSMOUNT_MNT_OK | FSMOUNT_MNTPNT_CRTERR | FSMOUNT_MNT_FAILED,
111                0
112        }
113};
114
115sd_card_driver_entry sd_card_driver_table [] = {
116        {
117                .device_name = "/dev/sd-card-a",
118                .bus = 0,
119                .transfer_mode = SD_CARD_TRANSFER_MODE_DEFAULT,
120                .command = SD_CARD_COMMAND_DEFAULT,
121                /* response : whatever, */
122                .response_index = SD_CARD_COMMAND_SIZE,
123                .n_ac_max = SD_CARD_N_AC_MAX_DEFAULT,
124                .block_number = 0,
125                .block_size = 0,
126                .block_size_shift = 0,
127                .busy = true,
128                .verbose = true,
129                .schedule_if_busy = false
130        }
131};
132
133size_t sd_card_driver_table_size = sizeof( sd_card_driver_table) / sizeof( sd_card_driver_table [0]);
134
135rtems_status_code mpc55xx_sd_card_init( bool mount)
136{
137        rtems_status_code sc = RTEMS_SUCCESSFUL;
138        int rv = 0;
139        sd_card_driver_entry *e = &sd_card_driver_table [0];
140
141        RTEMS_DEBUG_PRINT( "Task started\n");
142
143        sc = mpc55xx_dspi_init();
144        RTEMS_CHECK_SC( rv, "Intitalize DSPI bus");
145
146        e->bus = mpc55xx_dspi_bus_table [0].bus_number;
147
148        sc = sd_card_register();
149        RTEMS_CHECK_SC( sc, "Register SD Card");
150
151        if (mount) {
152                sc = rtems_bdpart_register_from_disk( MPC55XX_DEVICE_FILE);
153                RTEMS_CHECK_SC( sc, "Initialize IDE partition table");
154
155                rv = rtems_fsmount( mpc55xx_fs_table, sizeof( mpc55xx_fs_table) / sizeof( mpc55xx_fs_table [0]), NULL);
156                RTEMS_CHECK_RV_SC( rv, "Mount file systems");
157        }
158
159        return RTEMS_SUCCESSFUL;
160}
161
162#endif /* MPC55XX_BOARD_MPC5566EVB */
Note: See TracBrowser for help on using the repository browser.