coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
spi.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 
3 #include <device/mmio.h>
4 #include <console/console.h>
5 #include <delay.h>
6 #include <gpio.h>
7 #include <soc/iomap.h>
8 #include <soc/spi.h>
9 #include <soc/clock.h>
10 #include <spi_flash.h>
11 #include <timer.h>
12 
13 static const struct blsp_spi spi_reg[] = {
14  /* BLSP0 registers for SPI interface */
15  {
31  0,
32  0,
35  },
36  {0}, {0}, {0},
37  /* BLSP4 registers for SPI interface */
38  {
54  0,
55  0,
58  },
59  /* BLSP5 registers for SPI interface */
60  {
76  0,
77  0,
80  },
81 };
82 
83 static int check_bit_state(void *reg_addr, int mask,
84  int val, int us_delay)
85 {
86  unsigned int count = TIMEOUT_CNT;
87 
88  while ((read32(reg_addr) & mask) != val) {
89  count--;
90  if (count == 0)
91  return -ETIMEDOUT;
92  udelay(us_delay);
93  }
94 
95  return SUCCESS;
96 }
97 
98 /*
99  * Check whether QUPn State is valid
100  */
101 static int check_qup_state_valid(struct qcs_spi_slave *ds)
102 {
104  QUP_STATE_VALID, 1);
105 }
106 
107 /*
108  * Configure QUPn Core state
109  */
110 static int config_spi_state(struct qcs_spi_slave *ds, unsigned int state)
111 {
112  uint32_t val;
113  int ret = SUCCESS;
114 
115  ret = check_qup_state_valid(ds);
116  if (ret != SUCCESS)
117  return ret;
118 
119  switch (state) {
120  case QUP_STATE_RUN:
121  /* Set the state to RUN */
122  val = ((read32(ds->regs->qup_state) & ~QUP_STATE_MASK)
123  | QUP_STATE_RUN);
124  write32(ds->regs->qup_state, val);
125  ret = check_qup_state_valid(ds);
126  break;
127  case QUP_STATE_RESET:
128  /* Set the state to RESET */
129  val = ((read32(ds->regs->qup_state) & ~QUP_STATE_MASK)
130  | QUP_STATE_RESET);
131  write32(ds->regs->qup_state, val);
132  ret = check_qup_state_valid(ds);
133  break;
134  default:
135  printk(BIOS_ERR, "unsupported QUP SPI state : %d\n", state);
136  ret = -EINVAL;
137  break;
138  }
139 
140  return ret;
141 }
142 
143 /*
144  * Set QUPn SPI Mode
145  */
146 static void spi_set_mode(struct qcs_spi_slave *ds, unsigned int mode)
147 {
148  unsigned int clk_idle_state;
149  unsigned int input_first_mode;
150  uint32_t val;
151 
152  switch (mode) {
153  case SPI_MODE0:
154  clk_idle_state = 0;
155  input_first_mode = SPI_CONFIG_INPUT_FIRST;
156  break;
157  case SPI_MODE1:
158  clk_idle_state = 0;
159  input_first_mode = 0;
160  break;
161  case SPI_MODE2:
162  clk_idle_state = 1;
163  input_first_mode = SPI_CONFIG_INPUT_FIRST;
164  break;
165  case SPI_MODE3:
166  clk_idle_state = 1;
167  input_first_mode = 0;
168  break;
169  default:
170  printk(BIOS_ERR, "unsupported spi mode : %d\n", mode);
171  return;
172  }
173 
174  val = read32(ds->regs->spi_config);
175  val |= input_first_mode;
176  write32(ds->regs->spi_config, val);
177  val = read32(ds->regs->io_control);
178 
179  if (clk_idle_state)
181  else
183 
184  write32(ds->regs->io_control, val);
185 }
186 
187 /*
188  * Reset entire QUP and all mini cores
189  */
190 static void spi_reset(struct qcs_spi_slave *ds)
191 {
192  write32(ds->regs->qup_sw_reset, 0x1);
193  udelay(5);
195 }
196 
197 static struct qcs_spi_slave spi_slave_pool[3];
198 
199 static struct qcs_spi_slave *to_qcs_spi(const struct spi_slave *slave)
200 {
201  struct qcs_spi_slave *ds;
202  size_t i;
203 
204  for (i = 0; i < ARRAY_SIZE(spi_slave_pool); i++) {
205  ds = spi_slave_pool + i;
206 
207  if (!ds->allocated)
208  continue;
209 
210  if ((ds->slave.bus == slave->bus) &&
211  (ds->slave.cs == slave->cs))
212  return ds;
213  }
214 
215  return NULL;
216 }
217 
218 static void write_force_cs(const struct spi_slave *slave, int assert)
219 {
220  struct qcs_spi_slave *ds = to_qcs_spi(slave);
221  if (assert)
224  else
227 }
228 
229 /*
230  * BLSP QUPn SPI Hardware Initialisation
231  */
232 static int spi_hw_init(struct qcs_spi_slave *ds)
233 {
234  int ret;
235 
236  ds->initialized = 0;
237 
238  /* QUPn module configuration */
239  spi_reset(ds);
240 
241  /* Set the QUPn state */
243  if (ret)
244  return ret;
245 
246  /*
247  * Configure Mini core to SPI core with Input Output enabled,
248  * SPI master, N = 8 bits
249  */
258 
259  /*
260  * Configure Input first SPI protocol,
261  * SPI master mode and no loopback
262  */
267 
268  /*
269  * Configure SPI IO Control Register
270  * CLK_ALWAYS_ON = 0
271  * MX_CS_MODE = 0
272  * NO_TRI_STATE = 1
273  */
276 
277  /*
278  * Configure SPI IO Modes.
279  * OUTPUT_BIT_SHIFT_EN = 1
280  * INPUT_MODE = Block Mode
281  * OUTPUT MODE = Block Mode
282  */
290 
291  spi_set_mode(ds, ds->mode);
292 
293  /* Disable Error mask */
294  write32(ds->regs->error_flags_en, 0);
296  write32(ds->regs->qup_deassert_wait, 0);
297 
298  ds->initialized = 1;
299 
300  return SUCCESS;
301 }
302 
303 static int spi_ctrlr_claim_bus(const struct spi_slave *slave)
304 {
305  struct qcs_spi_slave *ds = to_qcs_spi(slave);
306  unsigned int ret;
307 
308  ret = spi_hw_init(ds);
309  if (ret)
310  return -EIO;
311  switch (slave->bus) {
312  case 4:
314  (GPIO(37), 2, GPIO_PULL_DOWN, GPIO_6MA, GPIO_INPUT); // MOSI
316  (GPIO(38), 2, GPIO_PULL_DOWN, GPIO_6MA, GPIO_OUTPUT); // MISO
318  (GPIO(117), 2, GPIO_NO_PULL, GPIO_6MA, GPIO_OUTPUT); // CS
320  (GPIO(118), 2, GPIO_PULL_DOWN, GPIO_6MA, GPIO_OUTPUT);// CLK
321  break;
322  case 5:
324  (GPIO(26), 3, GPIO_NO_PULL, GPIO_16MA, GPIO_INPUT); // MOSI
326  (GPIO(27), 3, GPIO_NO_PULL, GPIO_16MA, GPIO_INPUT); // MISO
328  (GPIO(28), 4, GPIO_PULL_UP, GPIO_16MA, GPIO_INPUT); // CS
330  (GPIO(29), 4, GPIO_NO_PULL, GPIO_16MA, GPIO_INPUT); // CLK
331  break;
332  default:
333  printk(BIOS_ERR, "SPI error: unsupported bus %d "
334  "(Supported buses 0, 1, 2, 3, 4, 5)\n", slave->bus);
335  break;
336  }
337  write_force_cs(slave, 1);
338 
339  return SUCCESS;
340 }
341 
342 static void spi_ctrlr_release_bus(const struct spi_slave *slave)
343 {
344  struct qcs_spi_slave *ds = to_qcs_spi(slave);
345 
346  /* Reset the SPI hardware */
347  write_force_cs(slave, 0);
348  spi_reset(ds);
349  ds->initialized = 0;
350 }
351 
352 /*
353  * Function to write data to OUTPUT FIFO
354  */
355 static void spi_write_byte(struct qcs_spi_slave *ds, unsigned char data)
356 {
357  /* Wait for space in the FIFO */
358  while ((read32(ds->regs->qup_operational) & OUTPUT_FIFO_FULL))
359  udelay(1);
360 
361  /* Write the byte of data */
362  write32(ds->regs->qup_output_fifo, data);
363 }
364 
365 /*
366  * Function to read data from Input FIFO
367  */
368 static unsigned char spi_read_byte(struct qcs_spi_slave *ds)
369 {
370  /* Wait for Data in FIFO */
372  udelay(1);
373 
374  /* Read a byte of data */
375  return read32(ds->regs->qup_input_fifo) & 0xff;
376 }
377 
378 /*
379  * Function to check whether Input or Output FIFO
380  * has data to be serviced
381  */
382 static int check_fifo_status(void *reg_addr)
383 {
384  unsigned int count = TIMEOUT_CNT;
385  unsigned int status_flag;
386  unsigned int val;
387 
388  do {
389  val = read32(reg_addr);
390  count--;
391  if (count == 0)
392  return -ETIMEDOUT;
393  status_flag = ((val & OUTPUT_SERVICE_FLAG) |
394  (val & INPUT_SERVICE_FLAG));
395  } while (!status_flag);
396 
397  return SUCCESS;
398 }
399 
400 /*
401  * Function to configure Input and Output enable/disable
402  */
403 static void enable_io_config(struct qcs_spi_slave *ds,
404  uint32_t write_cnt, uint32_t read_cnt)
405 {
406 
407  if (write_cnt) {
410  } else {
413  }
414 
415  if (read_cnt) {
418  } else {
421  }
422 }
423 
424 /*
425  * Function to read bytes number of data from the Input FIFO
426  */
427 static int __blsp_spi_read(struct qcs_spi_slave *ds, u8 *data_buffer,
428  unsigned int bytes)
429 {
430  uint32_t val;
431  unsigned int i;
432  unsigned int fifo_count;
433  int ret = SUCCESS;
434  int state_config;
435  struct stopwatch sw;
436 
437  /* Configure no of bytes to read */
438  state_config = config_spi_state(ds, QUP_STATE_RESET);
439  if (state_config)
440  return state_config;
441 
442  /* Configure input and output enable */
443  enable_io_config(ds, 0, bytes);
444 
445  write32(ds->regs->qup_mx_input_count, bytes);
446 
447  state_config = config_spi_state(ds, QUP_STATE_RUN);
448  if (state_config)
449  return state_config;
450 
451  while (bytes) {
453  if (ret != SUCCESS)
454  goto out;
455 
456  val = read32(ds->regs->qup_operational);
457  if (val & INPUT_SERVICE_FLAG) {
458  /*
459  * acknowledge to hw that software will
460  * read input data
461  */
464 
465  fifo_count = ((bytes > SPI_INPUT_BLOCK_SIZE) ?
466  SPI_INPUT_BLOCK_SIZE : bytes);
467 
468  for (i = 0; i < fifo_count; i++) {
469  *data_buffer = spi_read_byte(ds);
470  data_buffer++;
471  bytes--;
472  }
473  }
474  }
475 
477 
478  do {
479  val = read32(ds->regs->qup_operational);
480  if (stopwatch_expired(&sw)) {
481  printk(BIOS_ERR, "SPI FIFO read timeout\n");
482  ret = -ETIMEDOUT;
483  goto out;
484  }
485  } while (!(val & MAX_INPUT_DONE_FLAG));
486 
487 out:
488  /*
489  * Put the SPI Core back in the Reset State
490  * to end the transfer
491  */
493  return ret;
494 }
495 
496 static int blsp_spi_read(struct qcs_spi_slave *ds, u8 *data_buffer,
497  unsigned int bytes)
498 {
499  int length, ret;
500 
501  while (bytes) {
502  length = (bytes < MAX_COUNT_SIZE) ? bytes : MAX_COUNT_SIZE;
503 
504  ret = __blsp_spi_read(ds, data_buffer, length);
505  if (ret != SUCCESS)
506  return ret;
507 
508  data_buffer += length;
509  bytes -= length;
510  }
511 
512  return 0;
513 }
514 
515 /*
516  * Function to write data to the Output FIFO
517  */
518 static int __blsp_spi_write(struct qcs_spi_slave *ds, const u8 *cmd_buffer,
519  unsigned int bytes)
520 {
521  uint32_t val;
522  unsigned int i;
523  unsigned int write_len = bytes;
524  unsigned int read_len = bytes;
525  unsigned int fifo_count;
526  int ret = SUCCESS;
527  int state_config;
528  struct stopwatch sw;
529 
530  state_config = config_spi_state(ds, QUP_STATE_RESET);
531  if (state_config)
532  return state_config;
533 
534  /* Configure input and output enable */
535  enable_io_config(ds, write_len, read_len);
536  /* No of bytes to be written in Output FIFO */
537  write32(ds->regs->qup_mx_output_count, bytes);
538  write32(ds->regs->qup_mx_input_count, bytes);
539  state_config = config_spi_state(ds, QUP_STATE_RUN);
540 
541  if (state_config)
542  return state_config;
543 
544  /*
545  * read_len considered to ensure that we read the dummy data for the
546  * write we performed. This is needed to ensure with WR-RD transaction
547  * to get the actual data on the subsequent read cycle that happens
548  */
549  while (write_len || read_len) {
551  if (ret != SUCCESS)
552  goto out;
553 
554  val = read32(ds->regs->qup_operational);
555  if (val & OUTPUT_SERVICE_FLAG) {
556  /*
557  * acknowledge to hw that software will write
558  * expected output data
559  */
562 
563  if (write_len > SPI_OUTPUT_BLOCK_SIZE)
564  fifo_count = SPI_OUTPUT_BLOCK_SIZE;
565  else
566  fifo_count = write_len;
567 
568  for (i = 0; i < fifo_count; i++) {
569  /* Write actual data to output FIFO */
570  spi_write_byte(ds, *cmd_buffer);
571  cmd_buffer++;
572  write_len--;
573  }
574  }
575 
576  if (val & INPUT_SERVICE_FLAG) {
577  /*
578  * acknowledge to hw that software
579  * will read input data
580  */
583 
584  if (read_len > SPI_INPUT_BLOCK_SIZE)
585  fifo_count = SPI_INPUT_BLOCK_SIZE;
586  else
587  fifo_count = read_len;
588 
589  for (i = 0; i < fifo_count; i++) {
590  /* Read dummy data for the data written */
591  (void)spi_read_byte(ds);
592 
593  /* Decrement the read count after reading the
594  * dummy data from the device. This is to make
595  * sure we read dummy data before we write the
596  * data to fifo
597  */
598  read_len--;
599  }
600  }
601  }
602 
604 
605  do {
606  val = read32(ds->regs->qup_operational);
607  if (stopwatch_expired(&sw)) {
608  printk(BIOS_ERR, "SPI FIFO write timeout\n");
609  ret = -ETIMEDOUT;
610  goto out;
611  }
612 
613  } while (!(val & MAX_OUTPUT_DONE_FLAG));
614 
615 out:
616  /*
617  * Put the SPI Core back in the Reset State
618  * to end the transfer
619  */
621 
622  return ret;
623 }
624 
625 static int blsp_spi_write(struct qcs_spi_slave *ds, u8 *cmd_buffer,
626  unsigned int bytes)
627 {
628  int length, ret;
629 
630  while (bytes) {
631  length = (bytes < MAX_COUNT_SIZE) ? bytes : MAX_COUNT_SIZE;
632 
633  ret = __blsp_spi_write(ds, cmd_buffer, length);
634  if (ret != SUCCESS) {
635  printk(BIOS_ERR, "SPI:DBG write not success\n");
636  return ret;
637  }
638 
639  cmd_buffer += length;
640  bytes -= length;
641  }
642 
643  return 0;
644 }
645 
646 /*
647  * This function is invoked with either tx_buf or rx_buf.
648  * Calling this function with both null does a chip select change.
649  */
650 static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout,
651  size_t out_bytes, void *din, size_t in_bytes)
652 {
653  struct qcs_spi_slave *ds = to_qcs_spi(slave);
654  u8 *txp = (u8 *)dout;
655  u8 *rxp = (u8 *)din;
656  int ret;
657 
659  if (ret != SUCCESS)
660  return ret;
661 
662  if (dout != NULL) {
663  ret = blsp_spi_write(ds, txp, (unsigned int) out_bytes);
664  if (ret != SUCCESS)
665  goto out;
666  }
667 
668  if (din != NULL) {
669  ret = blsp_spi_read(ds, rxp, in_bytes);
670  if (ret != SUCCESS)
671  goto out;
672  }
673 
674 out:
675  /*
676  * Put the SPI Core back in the Reset State
677  * to end the transfer
678  */
680 
681  return ret;
682 }
683 
684 static int spi_ctrlr_setup(const struct spi_slave *slave)
685 {
686  struct qcs_spi_slave *ds = NULL;
687  int i;
688  unsigned int bus = slave->bus;
689  unsigned int cs = slave->cs;
690  int qup = 0;
691  int blsp = 2;
692 
693  if (((bus != BLSP4_SPI) && (bus != BLSP5_SPI)) || cs != 0) {
695  "SPI error: unsupported bus %d or cs %d\n", bus, cs);
696  return -1;
697  }
698 
699  for (i = 0; i < ARRAY_SIZE(spi_slave_pool); i++) {
700  if (spi_slave_pool[i].allocated)
701  continue;
702  ds = spi_slave_pool + i;
703  ds->slave.bus = bus;
704  ds->slave.cs = cs;
705  ds->regs = &spi_reg[bus];
706  ds->mode = SPI_MODE0;
707  ds->freq = 50000000;
708 
709  if (bus == BLSP4_SPI) {
710  ds->freq = 1000000;
711  qup = 4;
712  blsp = 1;
713  }
714 
715  clock_configure_spi(blsp, qup, ds->freq);
716  clock_enable_spi(blsp, qup);
717 
718  ds->allocated = 1;
719 
720  return 0;
721  }
722 
723  printk(BIOS_ERR, "SPI error: all %d pools busy\n", i);
724  return -1;
725 }
726 
727 static int xfer_vectors(const struct spi_slave *slave,
728  struct spi_op vectors[], size_t count)
729 {
731 }
732 
733 static const struct spi_ctrlr spi_ctrlr = {
735  .claim_bus = spi_ctrlr_claim_bus,
736  .release_bus = spi_ctrlr_release_bus,
737  .xfer = spi_ctrlr_xfer,
738  .xfer_vector = xfer_vectors,
739  .max_xfer_size = MAX_PACKET_COUNT,
740 };
741 
742 const struct spi_ctrlr_buses spi_ctrlr_bus_map[] = {
743  {
744  .ctrlr = &spi_ctrlr,
745  .bus_start = BLSP5_SPI,
746  .bus_end = BLSP5_SPI,
747  },
748  {
749  .ctrlr = &spi_ctrlr,
750  .bus_start = BLSP4_SPI,
751  .bus_end = BLSP4_SPI,
752  },
753 };
754 
#define GPIO_OUTPUT
Definition: gpio_ftns.h:23
#define GPIO_INPUT
Definition: gpio_ftns.h:24
static void write32(void *addr, uint32_t val)
Definition: mmio.h:40
static uint32_t read32(const void *addr)
Definition: mmio.h:22
#define assert(statement)
Definition: assert.h:74
#define ARRAY_SIZE(a)
Definition: helpers.h:12
#define printk(level,...)
Definition: stdlib.h:16
@ GPIO
Definition: chip.h:84
@ SUCCESS
uint64_t length
Definition: fw_cfg_if.h:1
#define clrsetbits32(addr, clear, set)
Definition: mmio.h:16
static int stopwatch_expired(struct stopwatch *sw)
Definition: timer.h:152
static void stopwatch_init_msecs_expire(struct stopwatch *sw, long ms)
Definition: timer.h:133
#define OUTPUT_FIFO_FULL
Definition: qup.h:43
#define OUTPUT_SERVICE_FLAG
Definition: qup.h:47
#define QUP_STATE_VALID_MASK
Definition: qup.h:69
#define QUP_STATE_VALID
Definition: qup.h:67
#define QUP_STATE_RESET
Definition: qup.h:64
#define INPUT_SERVICE_FLAG
Definition: qup.h:46
#define QUP_STATE_RUN
Definition: qup.h:65
#define QUP_STATE_MASK
Definition: qup.h:68
#define INPUT_FIFO_NOT_EMPTY
Definition: qup.h:44
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
Definition: loglevel.h:72
state
Definition: raminit.c:1787
#define MAX_INPUT_DONE_FLAG
Definition: qup.h:45
#define MAX_OUTPUT_DONE_FLAG
Definition: qup.h:44
@ GPIO_6MA
Definition: gpio_common.h:72
@ GPIO_16MA
Definition: gpio_common.h:77
@ GPIO_NO_PULL
Definition: gpio_common.h:62
const struct spi_ctrlr_buses spi_ctrlr_bus_map[]
Definition: spi.c:401
const size_t spi_ctrlr_bus_map_count
Definition: spi.c:408
static const int mask[4]
Definition: gpio.c:308
const struct spi_ctrlr spi_ctrlr
Definition: spi.c:261
void gpio_configure(gpio_t gpio, uint32_t func, uint32_t pull, uint32_t drive_str, uint32_t enable)
Definition: gpio.c:7
#define GPIO_PULL_UP
Definition: gpio.h:24
#define GPIO_PULL_DOWN
Definition: gpio.h:23
#define BLSP0_SPI_ERROR_FLAGS_EN_REG
Definition: spi.h:25
#define SPI_CONFIG_LOOP_BACK_MSK
Definition: spi.h:81
#define BLSP0_QUP_OUTPUT_FIFOc_REG(c)
Definition: spi.h:54
#define QUP_IO_MODES_OUTPUT_MODE_MSK
Definition: spi.h:98
#define BLSP0_QUP_MX_INPUT_COUNT_REG
Definition: spi.h:59
#define SPI_INPUT_BLOCK_SIZE
Definition: spi.h:101
#define BLSP0_SPI_DEASSERT_WAIT_REG
Definition: spi.h:23
#define BLSP0_QUP_OPERATIONAL_REG
Definition: spi.h:40
#define QUP_CONF_OUTPUT_MSK
Definition: spi.h:73
#define SPI_CONFIG_INPUT_FIRST
Definition: spi.h:79
#define SPI_IO_CTRL_CLK_ALWAYS_ON
Definition: spi.h:86
#define SPI_MODE3
Definition: spi.h:111
#define QUP_CONF_OUTPUT_ENA
Definition: spi.h:74
#define QUP_IO_MODES_OUTPUT_BIT_SHIFT_MSK
Definition: spi.h:94
#define BLSP0_QUP_ERROR_FLAGS_EN_REG
Definition: spi.h:34
#define BLSP0_QUP_ERROR_FLAGS_REG
Definition: spi.h:31
#define BLSP0_QUP_OPERATIONAL_MASK
Definition: spi.h:37
#define BLSP0_SPI_IO_CONTROL_REG
Definition: spi.h:17
#define SPI_IO_CTRL_CLOCK_IDLE_HIGH
Definition: spi.h:92
#define QUP_CONF_N_SPI_8_BIT_WORD
Definition: spi.h:77
#define SPI_OUTPUT_BLOCK_SIZE
Definition: spi.h:102
#define QUP_CONFIG_MINI_CORE_MSK
Definition: spi.h:68
#define SPI_IO_CTRL_FORCE_CS_DIS
Definition: spi.h:91
#define BLSP0_QUP_MX_OUTPUT_COUNT_REG
Definition: spi.h:62
#define SPI_IO_CTRL_MX_CS_MODE
Definition: spi.h:87
#define SPI_MODE1
Definition: spi.h:109
#define SPI_IO_CTRL_NO_TRI_STATE
Definition: spi.h:88
#define QUP_IO_MODES_INPUT_MODE_MSK
Definition: spi.h:96
#define SPI_MODE2
Definition: spi.h:110
#define QUP_CONF_NO_OUTPUT
Definition: spi.h:75
#define BLSP0_SPI_ERROR_FLAGS_REG
Definition: spi.h:20
#define BLSP0_QUP_STATE_REG
Definition: spi.h:46
#define MAX_COUNT_SIZE
Definition: spi.h:104
#define BLSP0_QUP_INPUT_FIFOc_REG(c)
Definition: spi.h:49
#define SPI_IO_CTRL_FORCE_CS_MSK
Definition: spi.h:89
#define SPI_CONFIG_NO_LOOP_BACK
Definition: spi.h:82
#define SPI_MODE0
Definition: spi.h:108
#define QUP_IO_MODES_INPUT_BLOCK_MODE
Definition: spi.h:97
#define QUP_CONF_NO_INPUT
Definition: spi.h:72
#define QUP_CONF_INPUT_MSK
Definition: spi.h:70
#define BLSP0_SPI_CONFIG_REG
Definition: spi.h:14
#define QUP_IO_MODES_OUTPUT_BIT_SHIFT_EN
Definition: spi.h:95
#define QUP_CONFIG_MINI_CORE_SPI
Definition: spi.h:69
#define QUP_CONF_N_MASK
Definition: spi.h:76
#define BLSP0_QUP_CONFIG_REG
Definition: spi.h:28
#define QUP_CONF_INPUT_ENA
Definition: spi.h:71
#define BLSP0_QUP_IO_MODES_REG
Definition: spi.h:43
#define SPI_CONFIG_NO_SLAVE_OPER
Definition: spi.h:84
#define SPI_IO_CTRL_FORCE_CS_EN
Definition: spi.h:90
#define BLSP0_QUP_SW_RESET_REG
Definition: spi.h:65
#define QUP_IO_MODES_OUTPUT_BLOCK_MODE
Definition: spi.h:99
#define SPI_CONFIG_NO_SLAVE_OPER_MSK
Definition: spi.h:83
#define MAX_PACKET_COUNT
Definition: spi.c:37
#define EINVAL
Definition: spi.c:30
#define ETIMEDOUT
Definition: spi.c:29
#define EIO
Definition: spi.c:31
#define TIMEOUT_CNT
Definition: spi.c:14
void clock_configure_spi(int blsp, int qup, uint32_t hz)
Definition: clock.c:198
void clock_enable_spi(int blsp, int qup)
Definition: clock.c:256
#define BLSP4_QUP_STATE_REG
Definition: spi.h:59
#define BLSP5_QUP_OPERATIONAL_MASK
Definition: spi.h:48
#define BLSP4_QUP_IO_MODES_REG
Definition: spi.h:55
#define BLSP5_QUP_STATE_REG
Definition: spi.h:60
#define BLSP5_QUP_MX_OUTPUT_COUNT_REG
Definition: spi.h:82
#define BLSP5_QUP_ERROR_FLAGS_EN_REG
Definition: spi.h:44
#define BLSP5_QUP_ERROR_FLAGS_REG
Definition: spi.h:40
#define BLSP5_QUP_SW_RESET_REG
Definition: spi.h:86
#define BLSP5_QUP_IO_MODES_REG
Definition: spi.h:56
#define BLSP5_SPI_ERROR_FLAGS_REG
Definition: spi.h:25
#define BLSP4_QUP_SW_RESET_REG
Definition: spi.h:85
#define BLSP5_QUP_OPERATIONAL_REG
Definition: spi.h:52
#define BLSP5_SPI_CONFIG_REG
Definition: spi.h:17
#define BLSP4_SPI
Definition: spi.h:133
#define BLSP4_SPI_IO_CONTROL_REG
Definition: spi.h:20
#define BLSP4_SPI_CONFIG_REG
Definition: spi.h:16
#define BLSP4_SPI_ERROR_FLAGS_EN_REG
Definition: spi.h:31
#define BLSP4_QUP_OUTPUT_FIFOc_REG(c)
Definition: spi.h:71
#define BLSP5_QUP_MX_INPUT_COUNT_REG
Definition: spi.h:78
#define BLSP5_QUP_CONFIG_REG
Definition: spi.h:36
#define BLSP4_QUP_MX_INPUT_COUNT_REG
Definition: spi.h:77
#define BLSP5_SPI_DEASSERT_WAIT_REG
Definition: spi.h:29
#define BLSP4_QUP_ERROR_FLAGS_EN_REG
Definition: spi.h:43
#define BLSP5_SPI_ERROR_FLAGS_EN_REG
Definition: spi.h:32
#define BLSP4_SPI_DEASSERT_WAIT_REG
Definition: spi.h:28
#define BLSP4_SPI_ERROR_FLAGS_REG
Definition: spi.h:24
#define BLSP4_QUP_OPERATIONAL_MASK
Definition: spi.h:47
#define BLSP4_QUP_CONFIG_REG
Definition: spi.h:35
#define BLSP5_QUP_INPUT_FIFOc_REG(c)
Definition: spi.h:66
#define BLSP4_QUP_MX_OUTPUT_COUNT_REG
Definition: spi.h:81
#define BLSP4_QUP_OPERATIONAL_REG
Definition: spi.h:51
#define BLSP5_QUP_OUTPUT_FIFOc_REG(c)
Definition: spi.h:73
#define BLSP5_SPI
Definition: spi.h:134
#define BLSP4_QUP_ERROR_FLAGS_REG
Definition: spi.h:39
#define BLSP4_QUP_INPUT_FIFOc_REG(c)
Definition: spi.h:64
#define BLSP5_SPI_IO_CONTROL_REG
Definition: spi.h:21
static struct qcs_spi_slave * to_qcs_spi(const struct spi_slave *slave)
Definition: spi.c:199
static void spi_reset(struct qcs_spi_slave *ds)
Definition: spi.c:190
static void spi_ctrlr_release_bus(const struct spi_slave *slave)
Definition: spi.c:342
static int xfer_vectors(const struct spi_slave *slave, struct spi_op vectors[], size_t count)
Definition: spi.c:727
static int check_bit_state(void *reg_addr, int mask, int val, int us_delay)
Definition: spi.c:83
static struct qcs_spi_slave spi_slave_pool[3]
Definition: spi.c:197
static void spi_write_byte(struct qcs_spi_slave *ds, unsigned char data)
Definition: spi.c:355
static int spi_hw_init(struct qcs_spi_slave *ds)
Definition: spi.c:232
static unsigned char spi_read_byte(struct qcs_spi_slave *ds)
Definition: spi.c:368
static int blsp_spi_write(struct qcs_spi_slave *ds, u8 *cmd_buffer, unsigned int bytes)
Definition: spi.c:625
static int check_fifo_status(void *reg_addr)
Definition: spi.c:382
static int config_spi_state(struct qcs_spi_slave *ds, unsigned int state)
Definition: spi.c:110
static int blsp_spi_read(struct qcs_spi_slave *ds, u8 *data_buffer, unsigned int bytes)
Definition: spi.c:496
static int __blsp_spi_read(struct qcs_spi_slave *ds, u8 *data_buffer, unsigned int bytes)
Definition: spi.c:427
static void write_force_cs(const struct spi_slave *slave, int assert)
Definition: spi.c:218
static int spi_ctrlr_claim_bus(const struct spi_slave *slave)
Definition: spi.c:303
static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout, size_t out_bytes, void *din, size_t in_bytes)
Definition: spi.c:650
static void spi_set_mode(struct qcs_spi_slave *ds, unsigned int mode)
Definition: spi.c:146
static void enable_io_config(struct qcs_spi_slave *ds, uint32_t write_cnt, uint32_t read_cnt)
Definition: spi.c:403
static int __blsp_spi_write(struct qcs_spi_slave *ds, const u8 *cmd_buffer, unsigned int bytes)
Definition: spi.c:518
static int spi_ctrlr_setup(const struct spi_slave *slave)
Definition: spi.c:684
static const struct blsp_spi spi_reg[]
Definition: spi.c:13
static int check_qup_state_valid(struct qcs_spi_slave *ds)
Definition: spi.c:101
int spi_flash_vector_helper(const struct spi_slave *slave, struct spi_op vectors[], size_t count, int(*func)(const struct spi_slave *slave, const void *dout, size_t bytesout, void *din, size_t bytesin))
Definition: spi_flash.c:745
static struct spi_slave slave
Definition: spiconsole.c:7
#define NULL
Definition: stddef.h:19
unsigned int uint32_t
Definition: stdint.h:14
uint8_t u8
Definition: stdint.h:45
Definition: spi.h:115
void * qup_output_fifo
Definition: spi.h:127
void * io_control
Definition: spi.h:117
void * spi_config
Definition: spi.h:116
void * qup_operational
Definition: spi.h:123
void * qup_deassert_wait
Definition: spi.h:134
void * qup_state
Definition: spi.h:125
void * qup_mx_output_count
Definition: spi.h:129
void * error_flags_en
Definition: spi.h:119
void * qup_config
Definition: spi.h:120
void * qup_input_fifo
Definition: spi.h:126
void * qup_io_modes
Definition: spi.h:124
void * qup_sw_reset
Definition: spi.h:130
void * qup_error_flags_en
Definition: spi.h:122
void * qup_mx_input_count
Definition: spi.h:128
Definition: device.h:76
const struct blsp_spi * regs
Definition: spi.h:173
unsigned int initialized
Definition: spi.h:175
struct spi_slave slave
Definition: spi.h:172
int allocated
Definition: spi.h:177
unsigned long freq
Definition: spi.h:176
unsigned int mode
Definition: spi.h:174
const struct spi_ctrlr * ctrlr
Definition: spi-generic.h:175
int(* setup)(const struct spi_slave *slave)
Definition: spi-generic.h:151
unsigned int bus
Definition: spi-generic.h:41
unsigned int cs
Definition: spi-generic.h:42
u8 val
Definition: sys.c:300
void udelay(uint32_t us)
Definition: udelay.c:15
#define count
typedef void(X86APIP X86EMU_intrFuncs)(int num)