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