summaryrefslogtreecommitdiff
path: root/drivers/spi/quad_spi.c
blob: 7afeacf72e92ad880307c97d3c47e590c119c974 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
 * Copyright 2012 Freescale Semiconductor, Inc.
 *
 * See file CREDITS for list of people who contributed to this
 * project.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 * MA 02111-1307 USA
 */

#include <common.h>
#include <spi.h>
#include <malloc.h>
#include <asm/arch/quadspi.h>

struct quadspi_slave {
	struct spi_slave slave;
	uint baudrate;
	int charbit;
};

int quadspi_xfer(struct spi_slave *slave, uint bitlen, const void *dout,
	       void *din, ulong flags);
struct spi_slave *quadspi_setup_slave(struct quadspi_slave *slave, uint mode);
void quadspi_init(void);
void quadspi_tx(u32 ctrl, u16 data);
u16 quadspi_rx(void);

extern void setup_iomux_quadspi(void);
extern int quadspi_claim_bus(uint bus, uint cs);
extern void quadspi_release_bus(uint bus, uint cs);

DECLARE_GLOBAL_DATA_PTR;

#ifdef CONFIG_QUAD_SPI
void quadspi_init(void)
{
	setup_iomux_quadspi();	/* port configuration */
}

void quadspi_tx(u32 ctrl, u16 data)
{
}

u16 quadspi_rx(void)
{
	return 0;
}

int quadspi_xfer(struct spi_slave *slave, uint bitlen, const void *dout,
	       void *din, ulong flags)
{
	return 0;
}

struct spi_slave *quadspi_setup_slave(struct quadspi_slave *slave, uint mode)
{
	return 0;
}
#endif				/* CONFIG_QUAD_SPI */

#ifdef CONFIG_CMD_SPI
int spi_cs_is_valid(unsigned int bus, unsigned int cs)
{
	return 0;
}

void spi_init_f(void)
{
}

void spi_init_r(void)
{
}

void spi_init(void)
{
	quadspi_init();
}

struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
				  unsigned int max_hz, unsigned int mode)
{
	struct quadspi_slave *slave;

	if (!spi_cs_is_valid(bus, cs))
		return NULL;

	slave = malloc(sizeof(struct quadspi_slave));
	if (!slave)
		return NULL;

	slave->slave.bus = bus;
	slave->slave.cs = cs;
	slave->baudrate = max_hz;

	/* specific setup */
	return quadspi_setup_slave(slave, mode);
}

void spi_free_slave(struct spi_slave *slave)
{
	free(slave);
}

int spi_claim_bus(struct spi_slave *slave)
{
	return quadspi_claim_bus(slave->bus, slave->cs);
}

void spi_release_bus(struct spi_slave *slave)
{
	quadspi_release_bus(slave->bus, slave->cs);
}

int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,
	     void *din, unsigned long flags)
{
	return quadspi_xfer(slave, bitlen, dout, din, flags);
}
#endif				/* CONFIG_CMD_SPI */