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

4.104.115
Last change on this file since e2d78b0b was d605a2c2, checked in by Ralf Corsepius <ralf.corsepius@…>, on 02/11/09 at 05:21:46

2009-02-11 Ralf Corsépius <ralf.corsepius@…>

  • startup/sd-card-init.c: Comment out fields having dropped out from sd_card_driver_entry.
  • Property mode set to 100644
File size: 3.9 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 <libchip/spi-sd-card.h>
28
29#define DEBUG
30
31#include <rtems/status-checks.h>
32
33#include <bsp.h>
34
35static rtems_status_code mpc55xx_dspi_init(void)
36{
37        int rv = 0;
38        int i = 0;
39        char device_name [] = "/dev/spi0";
40        union SIU_PCR_tag pcr = MPC55XX_ZERO_FLAGS;
41
42        rv = rtems_libi2c_initialize();
43        RTEMS_CHECK_RV_SC( rv, "rtems_libi2c_initialize");
44
45        /* DSPI D inputs are taken from DSPI C */
46        SIU.DISR.R = 0x000000FC;
47
48        /* DSPI A signals */
49        pcr.B.PA = 1;
50        pcr.B.ODE = 0;
51        pcr.B.HYS = 0;
52        pcr.B.SRC = 3;
53        pcr.B.WPE = 1;
54        pcr.B.WPS = 1;
55
56        /* SCK */
57        pcr.B.OBE = 1;
58        pcr.B.IBE = 0;
59        SIU.PCR [93].R = pcr.R;
60
61        /* SIN */
62        pcr.B.OBE = 0;
63        pcr.B.IBE = 1;
64        SIU.PCR [94].R = pcr.R;
65
66        /* SOUT */
67        pcr.B.OBE = 1;
68        pcr.B.IBE = 0;
69        SIU.PCR [95].R = pcr.R;
70
71        /* PCSx */
72        pcr.B.OBE = 1;
73        pcr.B.IBE = 0;
74        SIU.PCR [96].R = pcr.R;
75        SIU.PCR [97].R = pcr.R;
76        SIU.PCR [98].R = pcr.R;
77        SIU.PCR [99].R = pcr.R;
78        SIU.PCR [100].R = pcr.R;
79        SIU.PCR [101].R = pcr.R;
80
81        mpc55xx_dspi_bus_table [3].master = 0;
82        for (i = 0; i < MPC55XX_DSPI_NUMBER; ++i) {
83                device_name [8] = (char) ('0' + i);
84                rv = rtems_libi2c_register_bus( device_name, (rtems_libi2c_bus_t *) &mpc55xx_dspi_bus_table [i]);
85                RTEMS_CHECK_RV_SC( rv, device_name);
86        }
87
88        return RTEMS_SUCCESSFUL;
89}
90
91#include <sys/types.h>
92#include <sys/stat.h>
93#include <unistd.h>
94#include <fcntl.h>
95#include <dirent.h>
96#include <stdio.h>
97#include <rtems/fsmount.h>
98#include <rtems/dosfs.h>
99#include <rtems/ide_part_table.h>
100#include <rtems/console.h>
101
102#define MPC55XX_DEVICE "sd-card-a"
103#define MPC55XX_DEVICE_FILE "/dev/" MPC55XX_DEVICE
104#define MPC55XX_PARTITION "/dev/sd-card-a1"
105#define MPC55XX_MOUNT_POINT "/mnt"
106
107static fstab_t mpc55xx_fs_table [] = { {
108                MPC55XX_PARTITION, MPC55XX_MOUNT_POINT,
109                &msdos_ops, RTEMS_FILESYSTEM_READ_WRITE,
110                FSMOUNT_MNT_OK | FSMOUNT_MNTPNT_CRTERR | FSMOUNT_MNT_FAILED,
111                FSMOUNT_MNT_OK
112        }, {
113                MPC55XX_DEVICE_FILE, MPC55XX_MOUNT_POINT,
114                &msdos_ops, RTEMS_FILESYSTEM_READ_WRITE,
115                FSMOUNT_MNT_OK | FSMOUNT_MNTPNT_CRTERR | FSMOUNT_MNT_FAILED,
116                0
117        }
118};
119
120#define SD_CARD_NUMBER 1
121
122sd_card_driver_entry sd_card_driver_table [SD_CARD_NUMBER] = { {
123#if 0
124                .driver = {
125                        .ops = &sd_card_driver_ops,
126                        .size = sizeof( sd_card_driver_entry)
127                },
128                .table_index = 0,
129                .minor = 0,
130#endif
131                .device_name = "sd-card-a",
132#if 0
133                .disk_device_name = "/dev/sd-card-a",
134#endif
135                .transfer_mode = SD_CARD_TRANSFER_MODE_DEFAULT,
136                .command = SD_CARD_COMMAND_DEFAULT,
137                /* response : whatever, */
138                .response_index = SD_CARD_COMMAND_SIZE,
139                .n_ac_max = SD_CARD_N_AC_MAX_DEFAULT,
140                .block_number = 0,
141                .block_size = 0,
142                .block_size_shift = 0,
143                .busy = 1,
144                .verbose = 1,
145                .schedule_if_busy = 0,
146        }
147};
148
149rtems_status_code mpc55xx_sd_card_init(void)
150{
151        rtems_status_code sc = RTEMS_SUCCESSFUL;
152        int rv = 0;
153        sd_card_driver_entry *e = &sd_card_driver_table [0];
154
155        RTEMS_DEBUG_PRINT( "Task started\n");
156
157        sc = mpc55xx_dspi_init();
158        RTEMS_CHECK_SC( rv, "Intitalize DSPI bus");
159
160        rv = rtems_libi2c_register_drv( e->device_name, (rtems_libi2c_drv_t *) e, mpc55xx_dspi_bus_table [0].bus_number, 0);
161        RTEMS_CHECK_RV_SC( rv, "Register SD Card driver");
162
163        sc = rtems_ide_part_table_initialize( MPC55XX_DEVICE_FILE);
164        RTEMS_CHECK_SC( sc, "Initialize IDE partition table");
165
166        rv = mkdir( MPC55XX_MOUNT_POINT, S_IRWXU);
167        RTEMS_CHECK_RV_SC( rv, "Create mount point");
168
169        rv = rtems_fsmount( mpc55xx_fs_table, sizeof( mpc55xx_fs_table) / sizeof( mpc55xx_fs_table [0]), NULL);
170        RTEMS_CHECK_RV_SC( rv, "Mount file systems");
171
172        return RTEMS_SUCCESSFUL;
173}
Note: See TracBrowser for help on using the repository browser.