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 | |
---|
35 | static 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 | CHECK_RVSC( 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 | CHECK_RVSC( 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 | |
---|
107 | static 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 | |
---|
122 | sd_card_driver_entry sd_card_driver_table [SD_CARD_NUMBER] = { { |
---|
123 | .driver = { |
---|
124 | .ops = &sd_card_driver_ops, |
---|
125 | .size = sizeof( sd_card_driver_entry) |
---|
126 | }, |
---|
127 | .table_index = 0, |
---|
128 | .minor = 0, |
---|
129 | .device_name = "sd-card-a", |
---|
130 | .disk_device_name = "/dev/sd-card-a", |
---|
131 | .transfer_mode = SD_CARD_TRANSFER_MODE_DEFAULT, |
---|
132 | .command = SD_CARD_COMMAND_DEFAULT, |
---|
133 | /* response : whatever, */ |
---|
134 | .response_index = SD_CARD_COMMAND_SIZE, |
---|
135 | .n_ac_max = SD_CARD_N_AC_MAX_DEFAULT, |
---|
136 | .block_number = 0, |
---|
137 | .block_size = 0, |
---|
138 | .block_size_shift = 0, |
---|
139 | .busy = 1, |
---|
140 | .verbose = 1, |
---|
141 | .schedule_if_busy = 0, |
---|
142 | } |
---|
143 | }; |
---|
144 | |
---|
145 | rtems_status_code mpc55xx_sd_card_init(void) |
---|
146 | { |
---|
147 | rtems_status_code sc = RTEMS_SUCCESSFUL; |
---|
148 | int rv = 0; |
---|
149 | sd_card_driver_entry *e = &sd_card_driver_table [0]; |
---|
150 | |
---|
151 | DEBUG_PRINT( "Task started\n"); |
---|
152 | |
---|
153 | sc = mpc55xx_dspi_init(); |
---|
154 | CHECK_SC( rv, "Intitalize DSPI bus"); |
---|
155 | |
---|
156 | rv = rtems_libi2c_register_drv( e->device_name, (rtems_libi2c_drv_t *) e, mpc55xx_dspi_bus_table [0].bus_number, 0); |
---|
157 | CHECK_RVSC( rv, "Register SD Card driver"); |
---|
158 | |
---|
159 | sc = rtems_ide_part_table_initialize( MPC55XX_DEVICE_FILE); |
---|
160 | CHECK_SC( sc, "Initialize IDE partition table"); |
---|
161 | |
---|
162 | rv = mkdir( MPC55XX_MOUNT_POINT, S_IRWXU); |
---|
163 | CHECK_RVSC( rv, "Create mount point"); |
---|
164 | |
---|
165 | rv = rtems_fsmount( mpc55xx_fs_table, sizeof( mpc55xx_fs_table) / sizeof( mpc55xx_fs_table [0]), NULL); |
---|
166 | CHECK_RVSC( rv, "Mount file systems"); |
---|
167 | |
---|
168 | return RTEMS_SUCCESSFUL; |
---|
169 | } |
---|