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

4.115
Last change on this file since e570c313 was e570c313, checked in by Joel Sherrill <joel.sherrill@…>, on 01/24/11 at 15:32:04

2011-01-24 Joel Sherrill <joel.sherrill@…>

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