source: rtems/c/src/lib/libbsp/powerpc/gen83xx/spi/spi_init.c @ 8a54204

4.115
Last change on this file since 8a54204 was 8a54204, checked in by Sebastian Huber <sebastian.huber@…>, on 11/12/10 at 14:16:57

2010-11-12 Sebastian Huber <sebastian.huber@…>

  • console/console.h, console/console.c, console/config.c, console/ns16550cfg.c: Removed files.
  • console/console-config.c: New file.
  • Makefile.am: Reflect changes above.
  • configure.ac: New BSP options.
  • include/bsp.h: Use new BSP options.
  • network/network.c: Avoid memory leak.
  • startup/bspstart.c: Initialize console port table.
  • spi/spi_init.c: Update for SD card API changes.
  • Property mode set to 100644
File size: 12.4 KB
Line 
1/*===============================================================*\
2| Project: RTEMS support for MPC83xx                              |
3+-----------------------------------------------------------------+
4|                    Copyright (c) 2007                           |
5|                    Embedded Brains GmbH                         |
6|                    Obere Lagerstr. 30                           |
7|                    D-82178 Puchheim                             |
8|                    Germany                                      |
9|                    rtems@embedded-brains.de                     |
10+-----------------------------------------------------------------+
11| The license and distribution terms for this file may be         |
12| found in the file LICENSE in this distribution or at            |
13|                                                                 |
14| http://www.rtems.com/license/LICENSE.                           |
15|                                                                 |
16+-----------------------------------------------------------------+
17| this file contains the low level MPC83xx SPI driver parameters  |
18| and board-specific functions                                    |
19\*===============================================================*/
20#include <mpc83xx/mpc83xx_spidrv.h>
21#include <bsp/irq.h>
22#include <bsp.h>
23
24#if defined( MPC8313ERDB)
25
26#include <libchip/spi-sd-card.h>
27
28#elif defined( MPC8349EAMDS)
29
30#include <libchip/spi-flash-m25p40.h>
31
32#elif defined( HSC_CM01)
33
34#include <libchip/spi-fram-fm25l256.h>
35
36#else
37
38#warning No SPI configuration available
39
40#endif
41
42/*=========================================================================*\
43| Board-specific adaptation functions                                       |
44\*=========================================================================*/
45
46/*=========================================================================*\
47| Function:                                                                 |
48\*-------------------------------------------------------------------------*/
49static rtems_status_code bsp_spi_sel_addr
50(
51/*-------------------------------------------------------------------------*\
52| Purpose:                                                                  |
53|   address a slave device on the bus                                       |
54+---------------------------------------------------------------------------+
55| Input Parameters:                                                         |
56\*-------------------------------------------------------------------------*/
57 rtems_libi2c_bus_t *bh,                 /* bus specifier structure        */
58 uint32_t addr,                          /* address to send on bus         */
59 int rw                                  /* 0=write,1=read                 */
60)
61/*-------------------------------------------------------------------------*\
62| Return Value:                                                             |
63|    o = ok or error code                                                   |
64\*=========================================================================*/
65{
66
67#if defined( MPC8313ERDB)
68
69  /* Check address */
70  if (addr > 0) {
71    return RTEMS_INVALID_NUMBER;
72  }
73
74  /* SCS (active low) */
75  mpc83xx.gpio [0].gpdat &= ~0x20000000;
76
77#elif defined( MPC8349EAMDS)
78
79  /*
80   * check device address for valid range
81   */
82  if (addr > 0) {
83    return RTEMS_INVALID_NUMBER;
84  }
85  /*
86   * select given device
87   * GPIO1[0] is nSEL_SPI for M25P40
88   * set it to be active/low
89   */
90  mpc83xx.gpio[0].gpdat &= ~(1 << (31- 0));
91
92#elif defined( HSC_CM01)
93
94  /*
95   * check device address for valid range
96   */
97  if (addr > 7) {
98    return RTEMS_INVALID_NUMBER;
99  }
100  /*
101   * select given device
102   */
103  /*
104   * GPIO1[24] is SPI_A0
105   * GPIO1[25] is SPI_A1
106   * GPIO1[26] is SPI_A2
107   * set pins to address
108   */
109  mpc83xx.gpio[0].gpdat =
110    (mpc83xx.gpio[0].gpdat & ~(0x7  << (31-26)))
111    |                         (addr << (31-26));
112  /*
113   * GPIO1[27] is high-active strobe
114   */
115  mpc83xx.gpio[0].gpdat |= (1 << (31- 27));
116
117#endif
118
119  return  RTEMS_SUCCESSFUL;
120}
121
122/*=========================================================================*\
123| Function:                                                                 |
124\*-------------------------------------------------------------------------*/
125static rtems_status_code bsp_spi_send_start_dummy
126(
127/*-------------------------------------------------------------------------*\
128| Purpose:                                                                  |
129|   dummy function, SPI has no start condition                              |
130+---------------------------------------------------------------------------+
131| Input Parameters:                                                         |
132\*-------------------------------------------------------------------------*/
133 rtems_libi2c_bus_t *bh                  /* bus specifier structure        */
134)
135/*-------------------------------------------------------------------------*\
136| Return Value:                                                             |
137|    o = ok or error code                                                   |
138\*=========================================================================*/
139{
140
141#if defined( MPC8313ERDB)
142
143  /* SCS (inactive high) */
144  mpc83xx.gpio [0].gpdat |= 0x20000000;
145
146#elif defined( MPC8349EAMDS)
147
148  /*
149   * GPIO1[0] is nSEL_SPI for M25P40
150   * set it to inactive/high
151   */
152  mpc83xx.gpio[0].gpdat |=  (1 << (31- 0));
153
154#elif defined( HSC_CM01)
155
156  /*
157   * GPIO1[27] is high-active strobe
158   * set it to inactive/ low
159   */
160  mpc83xx.gpio[0].gpdat &= ~(0x1 << (31-27));
161
162#endif
163
164  return 0;
165}
166
167/*=========================================================================*\
168| Function:                                                                 |
169\*-------------------------------------------------------------------------*/
170static rtems_status_code bsp_spi_send_stop
171(
172/*-------------------------------------------------------------------------*\
173| Purpose:                                                                  |
174|   deselect SPI                                                            |
175+---------------------------------------------------------------------------+
176| Input Parameters:                                                         |
177\*-------------------------------------------------------------------------*/
178 rtems_libi2c_bus_t *bh                  /* bus specifier structure        */
179)
180/*-------------------------------------------------------------------------*\
181| Return Value:                                                             |
182|    o = ok or error code                                                   |
183\*=========================================================================*/
184{
185#if defined(DEBUG)
186  printk("bsp_spi_send_stop called... ");
187#endif
188
189#if defined( MPC8313ERDB)
190
191  /* SCS (inactive high) */
192  mpc83xx.gpio [0].gpdat |= 0x20000000;
193
194#elif defined( MPC8349EAMDS)
195
196  /*
197   * deselect given device
198   * GPIO1[0] is nSEL_SPI for M25P40
199   * set it to be inactive/high
200   */
201  mpc83xx.gpio[0].gpdat |=  (1 << (31- 0));
202
203#elif defined( HSC_CM01)
204
205  /*
206   * deselect device
207   * GPIO1[27] is high-active strobe
208   */
209  mpc83xx.gpio[0].gpdat &= ~(1 << (31- 27));
210
211#endif
212
213#if defined(DEBUG)
214  printk("... exit OK\r\n");
215#endif
216  return 0;
217}
218
219/*=========================================================================*\
220| list of handlers                                                          |
221\*=========================================================================*/
222
223rtems_libi2c_bus_ops_t bsp_spi_ops = {
224  .init = mpc83xx_spi_init,
225  .send_start = bsp_spi_send_start_dummy,
226  .send_stop = bsp_spi_send_stop,
227  .send_addr = bsp_spi_sel_addr,
228  .read_bytes = mpc83xx_spi_read_bytes,
229  .write_bytes = mpc83xx_spi_write_bytes,
230  .ioctl = mpc83xx_spi_ioctl
231};
232
233static mpc83xx_spi_desc_t bsp_spi_bus_desc = {
234  {/* public fields */
235    .ops = &bsp_spi_ops,
236    .size = sizeof(bsp_spi_bus_desc)
237  },
238  { /* our private fields */
239    .reg_ptr =&mpc83xx.spi,
240    .initialized = FALSE,
241    .irq_number = BSP_IPIC_IRQ_SPI,
242    .base_frq = 0 /* filled in during init */
243  }
244};
245
246#ifdef MPC8313ERDB
247
248#include <libchip/spi-sd-card.h>
249
250#define SD_CARD_NUMBER 1
251
252size_t sd_card_driver_table_size = SD_CARD_NUMBER;
253
254sd_card_driver_entry sd_card_driver_table [SD_CARD_NUMBER] = {
255  {
256    .device_name = "/dev/sd-card-a",
257    .bus = 0,
258    .transfer_mode = SD_CARD_TRANSFER_MODE_DEFAULT,
259    .command = SD_CARD_COMMAND_DEFAULT,
260    /* .response = whatever, */
261    .response_index = SD_CARD_COMMAND_SIZE,
262    .n_ac_max = SD_CARD_N_AC_MAX_DEFAULT,
263    .block_number = 0,
264    .block_size = 0,
265    .block_size_shift = 0,
266    .busy = true,
267    .verbose = true,
268    .schedule_if_busy = false
269  }
270};
271
272#endif /* MPC8313ERDB */
273
274
275/*=========================================================================*\
276| initialization                                                            |
277\*=========================================================================*/
278
279/*=========================================================================*\
280| Function:                                                                 |
281\*-------------------------------------------------------------------------*/
282rtems_status_code bsp_register_spi
283(
284/*-------------------------------------------------------------------------*\
285| Purpose:                                                                  |
286|   register SPI bus and devices                                            |
287+---------------------------------------------------------------------------+
288| Input Parameters:                                                         |
289\*-------------------------------------------------------------------------*/
290 void                                    /* <none>                         */
291)
292/*-------------------------------------------------------------------------*\
293| Return Value:                                                             |
294|    0 or error code                                                        |
295\*=========================================================================*/
296{
297  rtems_status_code sc = RTEMS_SUCCESSFUL;
298  int ret_code;
299  unsigned spi_busno;
300
301  /*
302   * init I2C library (if not already done)
303   */
304  rtems_libi2c_initialize ();
305
306  /*
307   * init port pins used to address/select SPI devices
308   */
309
310#if defined( MPC8313ERDB)
311
312  /*
313   * Configured as master (direct connection to SD card)
314   *
315   * GPIO[28] : SOUT
316   * GPIO[29] : SIN
317   * GPIO[30] : SCLK
318   * GPIO[02] : SCS (inactive high), GPIO[02] is normally connected to U43 at
319   * pin 15 of MC74LCX244DT.
320   */
321
322  /* Function */
323  mpc83xx.syscon.sicrl = (mpc83xx.syscon.sicrl & ~0x03fc0000) | 0x30000000;
324
325  /* Direction */
326  mpc83xx.gpio [0].gpdir = (mpc83xx.gpio [0].gpdir & ~0x0000000f) | 0x2000000b;
327
328  /* Data */
329  mpc83xx.gpio [0].gpdat |= 0x20000000;
330
331  /* Open Drain */
332  /* mpc83xx.gpio [0].gpdr  |= 0x0000000f; */
333
334#elif defined( MPC8349EAMDS)
335
336  /*
337   * GPIO1[0] is nSEL_SPI for M25P40
338   * set it to be output, high
339   */
340  mpc83xx.gpio[0].gpdat |=  (1 << (31- 0));
341  mpc83xx.gpio[0].gpdir |=  (1 << (31- 0));
342  mpc83xx.gpio[0].gpdr  &= ~(1 << (31- 0));
343
344#elif defined( HSC_CM01)
345
346  /*
347   * GPIO1[24] is SPI_A0
348   * GPIO1[25] is SPI_A1
349   * GPIO1[26] is SPI_A2
350   * GPIO1[27] is high-active strobe
351   * set pins to be output, low
352   */
353  mpc83xx.gpio[0].gpdat &= ~(0xf << (31-27));
354  mpc83xx.gpio[0].gpdir |=  (0xf << (31-27));
355  mpc83xx.gpio[0].gpdr  &= ~(0xf << (31-27));
356
357#endif
358
359  /*
360   * update base frequency in spi descriptor
361   */
362  bsp_spi_bus_desc.softc.base_frq = BSP_bus_frequency;
363
364  /*
365   * register SPI bus
366   */
367  ret_code = rtems_libi2c_register_bus("/dev/spi",
368                                       &(bsp_spi_bus_desc.bus_desc));
369  if (ret_code < 0) {
370    return -ret_code;
371  }
372  spi_busno = (unsigned) ret_code;
373
374#if defined( MPC8313ERDB)
375
376  /* Register SD Card driver */
377  sd_card_driver_table [0].bus = spi_busno;
378  sc = sd_card_register();
379  if (sc != RTEMS_SUCCESSFUL) {
380    return sc;
381  }
382
383#elif defined( MPC8349EAMDS)
384
385  /*
386   * register M25P40 Flash
387   */
388  ret_code = rtems_libi2c_register_drv(RTEMS_BSP_SPI_FLASH_DEVICE_NAME,
389                                       spi_flash_m25p40_rw_driver_descriptor,
390                                       spi_busno,0x00);
391#elif defined(HSC_CM01)
392
393  /*
394   * register FM25L256 FRAM
395   */
396  ret_code = rtems_libi2c_register_drv(RTEMS_BSP_SPI_FRAM_DEVICE_NAME,
397                                       spi_fram_fm25l256_rw_driver_descriptor,
398                                       spi_busno,0x02);
399
400#endif
401
402  if (ret_code < 0) {
403    return -ret_code;
404  }
405
406  /*
407   * FIXME: further drivers, when available
408   */
409  return 0;
410}
Note: See TracBrowser for help on using the repository browser.