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: GPL-2.0-only */
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 <types.h>
10 
11 #define SUCCESS 0
12 
13 #define DUMMY_DATA_VAL 0
14 #define TIMEOUT_CNT 100
15 #define CS_ASSERT 1
16 #define CS_DEASSERT 0
17 #define NUM_PORTS 3
18 #define NUM_GSBI_PINS 3
19 #define TLMM_ARGS 6
20 #define NUM_CS 4
21 #define GSBI_PIN_IDX 0
22 #define FUNC_SEL_IDX 1
23 #define GPIO_DIR_IDX 2
24 #define PULL_CONF_IDX 3
25 #define DRV_STR_IDX 4
26 #define GPIO_EN_IDX 5
27 
28 /* Arbitrarily assigned error code values */
29 #define ETIMEDOUT -10
30 #define EINVAL -11
31 #define EIO -12
32 
33 #define GSBI_IDX_TO_GSBI(idx) (idx + 5)
34 
35 /* MX_INPUT_COUNT and MX_OUTPUT_COUNT are 16-bits. Zero has a special meaning
36  * (count function disabled) and does not hold significance in the count. */
37 #define MAX_PACKET_COUNT ((64 * KiB) - 1)
38 
39 /*
40  * TLMM Configuration for SPI NOR
41  * gsbi_pin_conf[bus_num][GPIO_NUM, FUNC_SEL, I/O,
42  * PULL UP/DOWN, DRV_STR, GPIO_FUNC]
43  * gsbi_pin_conf[0][x][y] -- GSBI5
44  * gsbi_pin_conf[1][x][y] -- GSBI6
45  * gsbi_pin_conf[2][x][y] -- GSBI7
46 */
47 static unsigned int gsbi_pin_conf[NUM_PORTS][NUM_GSBI_PINS][TLMM_ARGS] = {
48  {
49  /* GSBI5 CLK */
50  {
53  },
54  /* GSBI5 MISO */
55  {
58  },
59  /* GSBI5 MOSI */
60  {
63  }
64  },
65  {
66  /* GSBI6 CLK */
67  {
70  },
71  /* GSBI6 MISO */
72  {
75  },
76  /* GSBI6 MOSI */
77  {
80  }
81  },
82  {
83  /* GSBI7 CLK */
84  {
87  },
88  /* GSBI7 MISO */
89  {
92  },
93  /* GSBI7 MOSI */
94  {
97  }
98  }
99 };
100 
101 /*
102  * CS GPIO number array cs_gpio_array[port_num][cs_num]
103  * cs_gpio_array[0][x] -- GSBI5
104  * cs_gpio_array[1][x] -- GSBI6
105  * cs_gpio_array[2][x] -- GSBI7
106  */
107 static unsigned int cs_gpio_array[NUM_PORTS][NUM_CS] = {
108  {
110  },
111  {
112  GSBI6_SPI_CS_0, 0, 0, 0
113  },
114  {
115  GSBI7_SPI_CS_0, 0, 0, 0
116  }
117 };
118 
119 /*
120  * GSBI HCLK state register bit
121  * hclk_state[0] -- GSBI5
122  * hclk_state[1] -- GSBI6
123  * hclk_state[2] -- GSBI7
124 */
125 static unsigned int hclk_state[NUM_PORTS] = {
126  GSBI5_HCLK,
127  GSBI6_HCLK,
128  GSBI7_HCLK
129 };
130 
131 /*
132  * GSBI QUP_APPS_CLK state register bit
133  * qup_apps_clk_state[0] -- GSBI5
134  * qup_apps_clk_state[1] -- GSBI6
135  * qup_apps_clk_state[2] -- GSBI7
136 */
137 static unsigned int qup_apps_clk_state[NUM_PORTS] = {
141 };
142 
143 static int check_bit_state(uint32_t reg_addr, int bit_num, int val, int us_delay)
144 {
145  unsigned int count = TIMEOUT_CNT;
146  unsigned int bit_val = ((readl_i(reg_addr) >> bit_num) & 0x01);
147 
148  while (bit_val != val) {
149  count--;
150  if (count == 0)
151  return -ETIMEDOUT;
152  udelay(us_delay);
153  bit_val = ((readl_i(reg_addr) >> bit_num) & 0x01);
154  }
155 
156  return SUCCESS;
157 }
158 
159 /*
160  * Check whether GSBIn_QUP State is valid
161  */
162 static int check_qup_state_valid(struct ipq_spi_slave *ds)
163 {
164 
166  QUP_STATE_VALID, 1);
167 
168 }
169 
170 /*
171  * Configure GSBIn Core state
172  */
173 static int config_spi_state(struct ipq_spi_slave *ds, unsigned int state)
174 {
175  uint32_t val;
176  int ret;
177  uint32_t new_state;
178 
179  ret = check_qup_state_valid(ds);
180  if (ret != SUCCESS)
181  return ret;
182 
183  switch (state) {
184  case SPI_RUN_STATE:
185  new_state = QUP_STATE_RUN_STATE;
186  break;
187 
188  case SPI_RESET_STATE:
189  new_state = QUP_STATE_RESET_STATE;
190  break;
191 
192  case SPI_PAUSE_STATE:
193  new_state = QUP_STATE_PAUSE_STATE;
194  break;
195 
196  default:
198  "err: unsupported GSBI SPI state : %d\n", state);
199  return -EINVAL;
200  }
201 
202  /* Set the state as requested */
204  | new_state;
205  writel_i(val, ds->regs->qup_state);
206  return check_qup_state_valid(ds);
207 }
208 
209 /*
210  * Set GSBIn SPI Mode
211  */
212 static void spi_set_mode(struct ipq_spi_slave *ds, unsigned int mode)
213 {
214  unsigned int clk_idle_state;
215  unsigned int input_first_mode;
216  uint32_t val;
217 
218  switch (mode) {
219  case GSBI_SPI_MODE_0:
220  clk_idle_state = 0;
221  input_first_mode = SPI_INPUT_FIRST_MODE;
222  break;
223  case GSBI_SPI_MODE_1:
224  clk_idle_state = 0;
225  input_first_mode = 0;
226  break;
227  case GSBI_SPI_MODE_2:
228  clk_idle_state = 1;
229  input_first_mode = SPI_INPUT_FIRST_MODE;
230  break;
231  case GSBI_SPI_MODE_3:
232  clk_idle_state = 1;
233  input_first_mode = 0;
234  break;
235  default:
237  "err : unsupported spi mode : %d\n", mode);
238  return;
239  }
240 
241  val = readl_i(ds->regs->spi_config);
242  val |= input_first_mode;
243  writel_i(val, ds->regs->spi_config);
244 
245  val = readl_i(ds->regs->io_control);
246  if (clk_idle_state)
248  else
250 
251  writel_i(val, ds->regs->io_control);
252 }
253 
254 /*
255  * Check for HCLK state
256  */
257 static int check_hclk_state(unsigned int core_num, int enable)
258 {
260  hclk_state[core_num], enable, 5);
261 }
262 
263 /*
264  * Check for QUP APPS CLK state
265  */
266 static int check_qup_clk_state(unsigned int core_num, int enable)
267 {
269  qup_apps_clk_state[core_num], enable, 5);
270 }
271 
272 /*
273  * Function to assert and De-assert chip select
274  */
275 static void CS_change(int port_num, int cs_num, int enable)
276 {
277  unsigned int cs_gpio = cs_gpio_array[port_num][cs_num];
278  void *addr = GPIO_IN_OUT_ADDR(cs_gpio);
280 
281  val &= (~(1 << GPIO_OUTPUT));
282  if (!enable)
283  val |= (1 << GPIO_OUTPUT);
284  write32(addr, val);
285 }
286 
287 /*
288  * GSBIn TLMM configuration
289  */
290 static void gsbi_pin_config(unsigned int port_num, int cs_num)
291 {
292  unsigned int gpio;
293  unsigned int i;
294  /* Hold the GSBIn (core_num) core in reset */
297 
298  /*
299  * Configure SPI_CLK, SPI_MISO and SPI_MOSI
300  */
301  for (i = 0; i < NUM_GSBI_PINS; i++) {
302  unsigned int func_sel;
303  unsigned int io_config;
304  unsigned int pull_config;
305  unsigned int drv_strength;
306  unsigned int gpio_en;
307  unsigned int *ptr;
308 
309  ptr = gsbi_pin_conf[port_num][i];
310  gpio = *(ptr + GSBI_PIN_IDX);
311  func_sel = *(ptr + FUNC_SEL_IDX);
312  io_config = *(ptr + GPIO_DIR_IDX);
313  pull_config = *(ptr + PULL_CONF_IDX);
314  drv_strength = *(ptr + DRV_STR_IDX);
315  gpio_en = *(ptr + GPIO_EN_IDX);
316 
317  gpio_tlmm_config(gpio, func_sel, io_config,
318  pull_config, drv_strength, gpio_en);
319  }
320 
321  gpio = cs_gpio_array[port_num][cs_num];
322  /* configure CS */
325  CS_change(port_num, cs_num, CS_DEASSERT);
326 }
327 
328 /*
329  * Clock configuration for GSBIn Core
330  */
331 static int gsbi_clock_init(struct ipq_spi_slave *ds)
332 {
333  int ret;
334 
335  /* Hold the GSBIn (core_num) core in reset */
338 
339  /* Disable GSBIn (core_num) QUP core clock branch */
342 
343  ret = check_qup_clk_state(ds->slave.bus, 1);
344  if (ret) {
346  "QUP Clock Halt For GSBI%d failed!\n", ds->slave.bus);
347  return ret;
348  }
349 
350  /* Disable M/N:D counter and hold M/N:D counter in reset */
353 
354  /* Disable GSBIn (core_num) QUP core clock root */
356 
360  (0 << GSBI_PRE_DIV_SEL_SHFT));
361 
362  /* Program M/N:D values for GSBIn_QUP_APPS_CLK @50MHz */
364  (0x01 << GSBI_M_VAL_SHFT));
366  (0xF7 << GSBI_D_VAL_SHFT));
368  (0xF8 << GSBI_N_VAL_SHFT));
369 
370  /* Set MNCNTR_MODE = 0: Bypass mode */
373 
374  /* De-assert the M/N:D counter reset */
377 
378  /*
379  * Enable the GSBIn (core_num) QUP core clock root.
380  * Keep MND counter disabled
381  */
383 
384  /* Enable GSBIn (core_num) QUP core clock branch */
387 
388  ret = check_qup_clk_state(ds->slave.bus, 0);
389  if (ret) {
391  "QUP Clock Enable For GSBI%d"
392  " failed!\n", ds->slave.bus);
393  return ret;
394  }
395 
396  /* Enable GSBIn (core_num) core clock branch */
399 
400  ret = check_hclk_state(ds->slave.bus, 0);
401  if (ret) {
403  "HCLK Enable For GSBI%d failed!\n", ds->slave.bus);
404  return ret;
405  }
406 
407  /* Release GSBIn (core_num) core from reset */
409  GSBI1_RESET_MSK, 0);
410  udelay(50);
411 
412  return SUCCESS;
413 }
414 
415 /*
416  * Reset entire QUP and all mini cores
417  */
418 static void spi_reset(struct ipq_spi_slave *ds)
419 {
420  writel_i(0x1, ds->regs->qup_sw_reset);
421  udelay(5);
422 }
423 
424 static const struct gsbi_spi spi_reg[] = {
425  /* GSBI5 registers for SPI interface */
426  {
445  },
446  /* GSBI6 registers for SPI interface */
447  {
466  },
467  /* GSBI7 registers for SPI interface */
468  {
487  }
488 };
489 static struct ipq_spi_slave spi_slave_pool[2];
490 
491 static struct ipq_spi_slave *to_ipq_spi(const struct spi_slave *slave)
492 {
493  struct ipq_spi_slave *ds;
494  size_t i;
495 
496  for (i = 0; i < ARRAY_SIZE(spi_slave_pool); i++) {
497  ds = spi_slave_pool + i;
498 
499  if (!ds->allocated)
500  continue;
501 
502  if ((ds->slave.bus == slave->bus) &&
503  (ds->slave.cs == slave->cs))
504  return ds;
505  }
506 
507  return NULL;
508 }
509 
510 /*
511  * GSBIn SPI Hardware Initialisation
512  */
513 static int spi_hw_init(struct ipq_spi_slave *ds)
514 {
515  int ret;
516 
517  if (ds->initialized)
518  return 0;
519 
520  /* GSBI module configuration */
521  spi_reset(ds);
522 
523  /* Set the GSBIn QUP state */
525  if (ret)
526  return ret;
527 
528  /* Configure GSBI_CTRL register to set protocol_mode to SPI:011 */
529  clrsetbits32_i(ds->regs->gsbi_ctrl, PROTOCOL_CODE_MSK,
531 
532  /*
533  * Configure Mini core to SPI core with Input Output enabled,
534  * SPI master, N = 8 bits
535  */
543  SPI_8_BIT_WORD));
544 
545  /*
546  * Configure Input first SPI protocol,
547  * SPI master mode and no loopback
548  */
551  (NO_LOOP_BACK |
552  SLAVE_OPERATION));
553 
554  /*
555  * Configure SPI IO Control Register
556  * CLK_ALWAYS_ON = 0
557  * MX_CS_MODE = 0
558  * NO_TRI_STATE = 1
559  */
561  ds->regs->io_control);
562 
563  /*
564  * Configure SPI IO Modes.
565  * OUTPUT_BIT_SHIFT_EN = 1
566  * INPUT_MODE = Block Mode
567  * OUTPUT MODE = Block Mode
568  */
575 
576  spi_set_mode(ds, ds->mode);
577 
578  /* Disable Error mask */
579  writel_i(0, ds->regs->error_flags_en);
581 
582  ds->initialized = 1;
583 
584  return SUCCESS;
585 }
586 
587 static int spi_ctrlr_claim_bus(const struct spi_slave *slave)
588 {
589  struct ipq_spi_slave *ds = to_ipq_spi(slave);
590  unsigned int ret;
591 
592  if (ds->initialized)
593  return SUCCESS;
594 
595  /* GPIO Configuration for SPI port */
596  gsbi_pin_config(ds->slave.bus, ds->slave.cs);
597 
598  /* Clock configuration */
599  ret = gsbi_clock_init(ds);
600  if (ret)
601  return ret;
602 
603  ret = spi_hw_init(ds);
604  if (ret)
605  return -EIO;
606 
607  return SUCCESS;
608 }
609 
610 static void spi_ctrlr_release_bus(const struct spi_slave *slave)
611 {
612  struct ipq_spi_slave *ds = to_ipq_spi(slave);
613 
614  /* Reset the SPI hardware */
615  spi_reset(ds);
616  ds->initialized = 0;
617 }
618 
619 static int spi_xfer_tx_packet(struct ipq_spi_slave *ds,
620  const uint8_t *dout, unsigned int out_bytes)
621 {
622  int ret;
623 
624  writel_i(out_bytes, ds->regs->qup_mx_output_count);
625 
626  ret = config_spi_state(ds, SPI_RUN_STATE);
627  if (ret)
628  return ret;
629 
630  while (out_bytes) {
632  continue;
633 
634  writel_i(*dout++, ds->regs->qup_output_fifo);
635  out_bytes--;
636 
637  /* Wait for output FIFO to drain. */
638  if (!out_bytes)
639  while (readl_i(ds->regs->qup_operational) &
641  ;
642  }
643 
644  return config_spi_state(ds, SPI_RESET_STATE);
645 }
646 
647 static int spi_xfer_rx_packet(struct ipq_spi_slave *ds,
648  uint8_t *din, unsigned int in_bytes)
649 {
650  int ret;
651 
652  writel_i(in_bytes, ds->regs->qup_mx_input_count);
653  writel_i(in_bytes, ds->regs->qup_mx_output_count);
654 
655  ret = config_spi_state(ds, SPI_RUN_STATE);
656  if (ret)
657  return ret;
658 
659  /* Seed clocking */
660  writel_i(0xff, ds->regs->qup_output_fifo);
661  while (in_bytes) {
662  if (!(readl_i(ds->regs->qup_operational) &
664  continue;
665  /* Keep it clocking */
666  writel_i(0xff, ds->regs->qup_output_fifo);
667 
668  *din++ = readl_i(ds->regs->qup_input_fifo) & 0xff;
669  in_bytes--;
670  }
671 
672  return config_spi_state(ds, SPI_RESET_STATE);
673 }
674 
675 static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout,
676  size_t out_bytes, void *din, size_t in_bytes)
677 {
678  int ret;
679  struct ipq_spi_slave *ds = to_ipq_spi(slave);
680 
681  /* Assert the chip select */
682  CS_change(ds->slave.bus, ds->slave.cs, CS_ASSERT);
683 
685  if (ret)
686  goto out;
687 
688  if (!out_bytes)
689  goto spi_receive;
690 
691  /*
692  * Let's do the write side of the transaction first. Enable output
693  * FIFO.
694  */
697 
698  while (out_bytes) {
699  unsigned int todo = MIN(out_bytes, MAX_PACKET_COUNT);
700 
701  ret = spi_xfer_tx_packet(ds, dout, todo);
702  if (ret)
703  break;
704 
705  out_bytes -= todo;
706  dout += todo;
707  }
708 
709  if (ret)
710  goto out;
711 
712 spi_receive:
713  if (!in_bytes) /* Nothing to read. */
714  goto out;
715 
716  /* Enable input FIFO */
719 
720  while (in_bytes) {
721  unsigned int todo = MIN(in_bytes, MAX_PACKET_COUNT);
722 
723  ret = spi_xfer_rx_packet(ds, din, todo);
724  if (ret)
725  break;
726 
727  in_bytes -= todo;
728  din += todo;
729  }
730 
731 out:
732  /* Deassert CS */
733  CS_change(ds->slave.bus, ds->slave.cs, CS_DEASSERT);
734 
735  /*
736  * Put the SPI Core back in the Reset State
737  * to end the transfer
738  */
740 
741  return ret;
742 }
743 
744 static int spi_ctrlr_setup(const struct spi_slave *slave)
745 {
746  struct ipq_spi_slave *ds = NULL;
747  int i;
748  int bus = slave->bus;
749  int cs = slave->cs;
750 
751  /*
752  * IPQ GSBI (Generic Serial Bus Interface) supports SPI Flash
753  * on different GSBI5, GSBI6 and GSBI7
754  * with different number of chip selects (CS, channels):
755  */
756  if ((bus < GSBI5_SPI) || (bus > GSBI7_SPI)
757  || ((bus == GSBI5_SPI) && (cs > 3))
758  || ((bus == GSBI6_SPI) && (cs > 0))
759  || ((bus == GSBI7_SPI) && (cs > 0))) {
760  printk(BIOS_ERR, "SPI error: unsupported bus %d "
761  "(Supported buses 0,1 and 2) or chipselect\n", bus);
762  }
763 
764  for (i = 0; i < ARRAY_SIZE(spi_slave_pool); i++) {
765  if (spi_slave_pool[i].allocated)
766  continue;
767  ds = spi_slave_pool + i;
768 
769  ds->slave.bus = bus;
770  ds->slave.cs = cs;
771  ds->regs = &spi_reg[bus];
772 
773  /*
774  * TODO(vbendeb):
775  * hardcoded frequency and mode - we might need to find a way
776  * to configure this
777  */
778  ds->freq = 10000000;
779  ds->mode = GSBI_SPI_MODE_0;
780  ds->allocated = 1;
781 
782  return 0;
783  }
784 
785  printk(BIOS_ERR, "SPI error: all %d pools busy\n", i);
786  return -1;
787 }
788 
789 static const struct spi_ctrlr spi_ctrlr = {
791  .claim_bus = spi_ctrlr_claim_bus,
792  .release_bus = spi_ctrlr_release_bus,
793  .xfer = spi_ctrlr_xfer,
794  .max_xfer_size = MAX_PACKET_COUNT,
795 };
796 
797 const struct spi_ctrlr_buses spi_ctrlr_bus_map[] = {
798  {
799  .ctrlr = &spi_ctrlr,
800  .bus_start = GSBI5_SPI,
801  .bus_end = GSBI7_SPI,
802  },
803 };
804 
#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
#define ARRAY_SIZE(a)
Definition: helpers.h:12
#define MIN(a, b)
Definition: helpers.h:37
static u32 addr
Definition: cirrus.c:14
#define printk(level,...)
Definition: stdlib.h:16
#define QUP_STATE_VALID
Definition: qup.h:67
#define QUP_STATE_MASK
Definition: qup.h:68
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
Definition: loglevel.h:72
state
Definition: raminit.c:1787
#define readl_i(a)
Definition: iomap.h:15
#define writel_i(v, a)
Definition: iomap.h:16
#define GPIO_IN_OUT_ADDR(x)
Definition: iomap.h:67
#define clrsetbits32_i(addr, clear, set)
Definition: iomap.h:17
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
const struct spi_ctrlr spi_ctrlr
Definition: spi.c:261
#define GSBIn_HCLK_CTL_REG(n)
Definition: clock.h:27
#define MNCNTR_MODE_DUAL_EDGE
Definition: clock.h:105
#define FUNC_SEL_1
Definition: gpio.h:11
#define GPIO_DRV_STR_10MA
Definition: gpio.h:14
#define GPIO_DRV_STR_11MA
Definition: gpio.h:15
#define FUNC_SEL_3
Definition: gpio.h:12
#define FUNC_SEL_GPIO
Definition: gpio.h:13
#define GPIO_PULL_UP
Definition: gpio.h:24
static void gpio_tlmm_config(unsigned int gpio, unsigned int func, unsigned int dir, unsigned int pull, unsigned int drvstr, unsigned int enable)
Definition: gpio.h:82
#define GPIO_FUNC_DISABLE
Definition: gpio.h:10
#define GPIO_FUNC_ENABLE
Definition: gpio.h:9
#define GPIO_PULL_DOWN
Definition: gpio.h:23
#define QUP_CONFIG_MINI_CORE_MSK
Definition: spi.h:68
#define QUP_CONFIG_MINI_CORE_SPI
Definition: spi.h:69
#define PROTOCOL_CODE_MSK
Definition: spi.h:165
#define CLK_ROOT_ENA_MSK
Definition: spi.h:144
#define QUP_CLK_BRANCH_DIS
Definition: spi.h:143
#define GSBI1_RESET
Definition: spi.h:180
#define GSBI5_QUP_SW_RESET_REG
Definition: spi.h:103
#define QUP_STATE_PAUSE_STATE
Definition: spi.h:162
#define GSBI7_SPI
Definition: spi.h:243
#define GSBI5_SPI_CS_2
Definition: spi.h:219
#define GSBI6_QUP_OPERATIONAL_REG
Definition: spi.h:62
#define GSBI_PRE_DIV_SEL_SHFT
Definition: spi.h:198
#define GSBI5_SPI_ERROR_FLAGS_EN_REG
Definition: spi.h:41
#define GSBI7_QUP_MX_OUTPUT_COUNT_REG
Definition: spi.h:101
#define GSBI7_SPI_ERROR_FLAGS_REG
Definition: spi.h:39
#define GSBI_D_VAL_SHFT
Definition: spi.h:187
#define GSBI6_SPI_CONFIG_REG
Definition: spi.h:30
#define GSBI6_GSBI_CTRL_REG_REG
Definition: spi.h:46
#define GSBI7_SPI_CS_0
Definition: spi.h:226
#define GSBI5_SPI_CONFIG_REG
Definition: spi.h:29
#define GSBI5_QUP_MX_OUTPUT_COUNT_REG
Definition: spi.h:99
#define GSBI7_QUP_STATE_REG
Definition: spi.h:71
#define GSBI5_QUP_OUTPUT_FIFOc_REG(c)
Definition: spi.h:88
#define GSBIn_N_VAL_MSK
Definition: spi.h:186
#define GSBI6_SPI_CS_0
Definition: spi.h:222
#define QUP_STATE_RUN_STATE
Definition: spi.h:161
#define OUTPUT_BIT_SHIFT_MSK
Definition: spi.h:174
#define GSBI7_QUP_ERROR_FLAGS_REG
Definition: spi.h:55
#define GSBI5_QUP_ERROR_FLAGS_EN_REG
Definition: spi.h:57
#define SPI_INPUT_FIRST_MODE
Definition: spi.h:204
#define MX_CS_MODE
Definition: spi.h:172
#define GSBI_CLK_BRANCH_ENA_MSK
Definition: spi.h:138
#define GSBI5_GSBI_CTRL_REG_REG
Definition: spi.h:45
#define MNCNTR_DIS
Definition: spi.h:194
#define GSBIn_RESET_REG(n)
Definition: spi.h:108
#define GSBI6_QUP_ERROR_FLAGS_EN_REG
Definition: spi.h:58
#define GSBI5_SPI_MISO
Definition: spi.h:215
#define SPI_QUP_CONF_NO_INPUT
Definition: spi.h:155
#define GSBIn_QUP_APPS_MD_REG(n)
Definition: spi.h:127
#define GSBI7_QUP_OPERATIONAL_REG
Definition: spi.h:63
#define GSBI6_QUP_APPS_CLK
Definition: spi.h:136
#define GSBI6_QUP_ERROR_FLAGS_REG
Definition: spi.h:54
#define GSBIn_M_VAL_MSK
Definition: spi.h:184
#define GSBI_M_VAL_SHFT
Definition: spi.h:183
#define GSBI7_HCLK
Definition: spi.h:134
#define GSBI6_QUP_SW_RESET_REG
Definition: spi.h:104
#define GSBI5_QUP_ERROR_FLAGS_REG
Definition: spi.h:53
#define GSBI5_QUP_MX_INPUT_COUNT_REG
Definition: spi.h:95
#define GSBI6_QUP_MX_INPUT_COUNT_REG
Definition: spi.h:96
#define GSBI7_QUP_ERROR_FLAGS_EN_REG
Definition: spi.h:59
#define QUP_INPUT_FIFO_NOT_EMPTY
Definition: spi.h:211
#define GSBI6_SPI
Definition: spi.h:242
#define CLK_HALT_CFPB_STATEB_REG
Definition: spi.h:129
#define GSBI5_QUP_APPS_CLK
Definition: spi.h:135
#define MNCNTR_MSK
Definition: spi.h:192
#define SPI_QUP_CONF_OUTPUT_MSK
Definition: spi.h:156
#define MNCNTR_RST_ENA
Definition: spi.h:190
#define SPI_QUP_CONF_NO_OUTPUT
Definition: spi.h:158
#define QUP_OUTPUT_FIFO_NOT_EMPTY
Definition: spi.h:207
#define PROTOCOL_CODE_SPI
Definition: spi.h:166
#define INPUT_BLOCK_MODE
Definition: spi.h:177
#define GSBI6_QUP_OUTPUT_FIFOc_REG(c)
Definition: spi.h:90
#define GSBI7_SPI_CLK
Definition: spi.h:225
#define QUP_CLK_BRANCH_ENA_MSK
Definition: spi.h:141
#define GSBI_SPI_MODE_1
Definition: spi.h:238
#define MNCNTR_MODE_MSK
Definition: spi.h:195
#define MNCNTR_RST_DIS
Definition: spi.h:191
#define OUTPUT_BLOCK_MODE
Definition: spi.h:179
#define GSBI5_SPI_CS_3
Definition: spi.h:220
#define GSBIn_PLL_SRC_MSK
Definition: spi.h:200
#define QUP_OUTPUT_FIFO_FULL
Definition: spi.h:210
#define GSBI6_SPI_ERROR_FLAGS_EN_REG
Definition: spi.h:42
#define GSBI5_SPI_CLK
Definition: spi.h:214
#define GSBI7_SPI_MISO
Definition: spi.h:227
#define GSBI6_QUP_CONFIG_REG
Definition: spi.h:50
#define GSBI5_SPI_MOSI
Definition: spi.h:216
#define OUTPUT_BIT_SHIFT_EN
Definition: spi.h:175
#define GSBI7_SPI_IO_CONTROL_REG
Definition: spi.h:35
#define GSBI7_SPI_MOSI
Definition: spi.h:228
#define GSBI6_SPI_MOSI
Definition: spi.h:224
#define GSBI5_SPI
Definition: spi.h:241
#define GSBI7_QUP_MX_INPUT_COUNT_REG
Definition: spi.h:97
#define GSBI6_SPI_MISO
Definition: spi.h:223
#define GSBI5_SPI_IO_CONTROL_REG
Definition: spi.h:33
#define GSBI7_SPI_CONFIG_REG
Definition: spi.h:31
#define GSBI7_GSBI_CTRL_REG_REG
Definition: spi.h:47
#define GSBI5_QUP_STATE_REG
Definition: spi.h:69
#define GSBI7_QUP_OUTPUT_FIFOc_REG(c)
Definition: spi.h:92
#define GSBI1_RESET_MSK
Definition: spi.h:181
#define GSBI_N_VAL_SHFT
Definition: spi.h:185
#define GSBI7_QUP_CONFIG_REG
Definition: spi.h:51
#define QUP_CLK_BRANCH_ENA
Definition: spi.h:142
#define GSBIn_D_VAL_MSK
Definition: spi.h:188
#define SPI_RUN_STATE
Definition: spi.h:233
#define CLK_ALWAYS_ON
Definition: spi.h:171
#define QUP_STATE_VALID_BIT
Definition: spi.h:148
#define GSBIn_PLL_SRC_PLL8
Definition: spi.h:202
#define QUP_STATE_RESET_STATE
Definition: spi.h:160
#define SLAVE_OPERATION_MSK
Definition: spi.h:169
#define SPI_8_BIT_WORD
Definition: spi.h:164
#define GSBI5_SPI_CS_1
Definition: spi.h:218
#define SLAVE_OPERATION
Definition: spi.h:170
#define GSBI6_HCLK
Definition: spi.h:133
#define GSBI6_SPI_IO_CONTROL_REG
Definition: spi.h:34
#define SPI_RESET_STATE
Definition: spi.h:232
#define GSBI7_QUP_APPS_CLK
Definition: spi.h:137
#define GSBI6_QUP_INPUT_FIFOc_REG(c)
Definition: spi.h:83
#define CLK_ROOT_DIS
Definition: spi.h:146
#define SPI_QUP_CONF_INPUT_ENA
Definition: spi.h:154
#define GSBI5_HCLK
Definition: spi.h:132
#define SPI_IO_CONTROL_CLOCK_IDLE_HIGH
Definition: spi.h:205
#define SPI_QUP_CONF_OUTPUT_ENA
Definition: spi.h:159
#define GSBI7_SPI_ERROR_FLAGS_EN_REG
Definition: spi.h:43
#define GSBI5_QUP_IO_MODES_REG
Definition: spi.h:65
#define INPUT_BLOCK_MODE_MSK
Definition: spi.h:176
#define MNCNTR_RST_MSK
Definition: spi.h:189
#define GSBI_CLK_BRANCH_ENA
Definition: spi.h:139
#define GSBIn_QUP_APPS_NS_REG(n)
Definition: spi.h:125
#define GSBI5_QUP_CONFIG_REG
Definition: spi.h:49
#define GSBIn_PRE_DIV_SEL_MSK
Definition: spi.h:199
#define GSBI_SPI_MODE_2
Definition: spi.h:239
#define GSBI7_QUP_IO_MODES_REG
Definition: spi.h:67
#define GSBI_SPI_MODE_0
Definition: spi.h:237
#define SPI_QUP_CONF_INPUT_MSK
Definition: spi.h:153
#define GSBI5_SPI_CS_0
Definition: spi.h:217
#define GSBI5_SPI_ERROR_FLAGS_REG
Definition: spi.h:37
#define GSBI_SPI_MODE_3
Definition: spi.h:240
#define GSBI6_SPI_CLK
Definition: spi.h:221
#define GSBI6_QUP_MX_OUTPUT_COUNT_REG
Definition: spi.h:100
#define GSBI6_QUP_STATE_REG
Definition: spi.h:70
#define GSBI7_QUP_INPUT_FIFOc_REG(c)
Definition: spi.h:85
#define SPI_PAUSE_STATE
Definition: spi.h:234
#define NO_LOOP_BACK
Definition: spi.h:168
#define GSBI6_QUP_IO_MODES_REG
Definition: spi.h:66
#define NO_TRI_STATE
Definition: spi.h:173
#define GSBI5_QUP_OPERATIONAL_REG
Definition: spi.h:61
#define GSBI7_QUP_SW_RESET_REG
Definition: spi.h:105
#define CLK_ROOT_ENA
Definition: spi.h:145
#define SPI_BIT_WORD_MSK
Definition: spi.h:163
#define OUTPUT_BLOCK_MODE_MSK
Definition: spi.h:178
#define LOOP_BACK_MSK
Definition: spi.h:167
#define GSBI5_QUP_INPUT_FIFOc_REG(c)
Definition: spi.h:81
#define GSBI6_SPI_ERROR_FLAGS_REG
Definition: spi.h:38
#define MNCNTR_EN
Definition: spi.h:193
#define TLMM_ARGS
Definition: spi.c:19
static int check_bit_state(uint32_t reg_addr, int bit_num, int val, int us_delay)
Definition: spi.c:143
#define MAX_PACKET_COUNT
Definition: spi.c:37
#define PULL_CONF_IDX
Definition: spi.c:24
static void spi_ctrlr_release_bus(const struct spi_slave *slave)
Definition: spi.c:610
#define DRV_STR_IDX
Definition: spi.c:25
#define EINVAL
Definition: spi.c:30
#define NUM_CS
Definition: spi.c:20
static int check_qup_clk_state(unsigned int core_num, int enable)
Definition: spi.c:266
static int check_qup_state_valid(struct ipq_spi_slave *ds)
Definition: spi.c:162
static unsigned int hclk_state[NUM_PORTS]
Definition: spi.c:125
#define ETIMEDOUT
Definition: spi.c:29
#define CS_ASSERT
Definition: spi.c:15
static void spi_set_mode(struct ipq_spi_slave *ds, unsigned int mode)
Definition: spi.c:212
#define EIO
Definition: spi.c:31
static unsigned int qup_apps_clk_state[NUM_PORTS]
Definition: spi.c:137
static void spi_reset(struct ipq_spi_slave *ds)
Definition: spi.c:418
#define CS_DEASSERT
Definition: spi.c:16
static int gsbi_clock_init(struct ipq_spi_slave *ds)
Definition: spi.c:331
#define TIMEOUT_CNT
Definition: spi.c:14
#define GSBI_PIN_IDX
Definition: spi.c:21
static const struct gsbi_spi spi_reg[]
Definition: spi.c:424
#define FUNC_SEL_IDX
Definition: spi.c:22
#define SUCCESS
Definition: spi.c:11
#define GPIO_DIR_IDX
Definition: spi.c:23
static int config_spi_state(struct ipq_spi_slave *ds, unsigned int state)
Definition: spi.c:173
static struct ipq_spi_slave spi_slave_pool[2]
Definition: spi.c:489
static void CS_change(int port_num, int cs_num, int enable)
Definition: spi.c:275
static int spi_hw_init(struct ipq_spi_slave *ds)
Definition: spi.c:513
static int spi_ctrlr_claim_bus(const struct spi_slave *slave)
Definition: spi.c:587
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:675
static unsigned int cs_gpio_array[NUM_PORTS][NUM_CS]
Definition: spi.c:107
static void gsbi_pin_config(unsigned int port_num, int cs_num)
Definition: spi.c:290
static unsigned int gsbi_pin_conf[NUM_PORTS][NUM_GSBI_PINS][TLMM_ARGS]
Definition: spi.c:47
static int spi_xfer_tx_packet(struct ipq_spi_slave *ds, const uint8_t *dout, unsigned int out_bytes)
Definition: spi.c:619
static int spi_ctrlr_setup(const struct spi_slave *slave)
Definition: spi.c:744
static int check_hclk_state(unsigned int core_num, int enable)
Definition: spi.c:257
#define GPIO_EN_IDX
Definition: spi.c:26
#define GSBI_IDX_TO_GSBI(idx)
Definition: spi.c:33
#define NUM_GSBI_PINS
Definition: spi.c:18
static struct ipq_spi_slave * to_ipq_spi(const struct spi_slave *slave)
Definition: spi.c:491
#define NUM_PORTS
Definition: spi.c:17
static int spi_xfer_rx_packet(struct ipq_spi_slave *ds, uint8_t *din, unsigned int in_bytes)
Definition: spi.c:647
static struct spi_slave slave
Definition: spiconsole.c:7
#define NULL
Definition: stddef.h:19
unsigned int uint32_t
Definition: stdint.h:14
unsigned char uint8_t
Definition: stdint.h:8
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_state
Definition: spi.h:125
void * qup_mx_output_count
Definition: spi.h:129
void * error_flags_en
Definition: spi.h:119
void * qup_ns_reg
Definition: spi.h:131
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_md_reg
Definition: spi.h:132
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
Definition: pinmux.c:36
Definition: spi.h:245
const struct blsp_spi * regs
Definition: spi.h:152
unsigned int initialized
Definition: spi.h:154
struct spi_slave slave
Definition: spi.h:151
unsigned long freq
Definition: spi.h:155
int allocated
Definition: spi.h:156
unsigned int mode
Definition: spi.h:153
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)