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

4.11
Last change on this file since 0e27119 was 0e27119, checked in by Joel Sherrill <joel.sherrill@…>, on Oct 11, 2012 at 8:52:18 PM

Use proper 3 line form of license text

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