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

4.104.114.95
Last change on this file since bd79292 was bb6c1e56, checked in by Ralf Corsepius <ralf.corsepius@…>, on 08/20/08 at 05:12:45

Add missing prototypes.

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