|
@@ -49,6 +49,8 @@ struct mxc_spi_slave {
|
|
#endif
|
|
#endif
|
|
int gpio;
|
|
int gpio;
|
|
int ss_pol;
|
|
int ss_pol;
|
|
|
|
+ unsigned int max_hz;
|
|
|
|
+ unsigned int mode;
|
|
};
|
|
};
|
|
|
|
|
|
static inline struct mxc_spi_slave *to_mxc_spi_slave(struct spi_slave *slave)
|
|
static inline struct mxc_spi_slave *to_mxc_spi_slave(struct spi_slave *slave)
|
|
@@ -83,12 +85,13 @@ u32 get_cspi_div(u32 div)
|
|
}
|
|
}
|
|
|
|
|
|
#ifdef MXC_CSPI
|
|
#ifdef MXC_CSPI
|
|
-static s32 spi_cfg_mxc(struct mxc_spi_slave *mxcs, unsigned int cs,
|
|
|
|
- unsigned int max_hz, unsigned int mode)
|
|
|
|
|
|
+static s32 spi_cfg_mxc(struct mxc_spi_slave *mxcs, unsigned int cs)
|
|
{
|
|
{
|
|
unsigned int ctrl_reg;
|
|
unsigned int ctrl_reg;
|
|
u32 clk_src;
|
|
u32 clk_src;
|
|
u32 div;
|
|
u32 div;
|
|
|
|
+ unsigned int max_hz = mxcs->max_hz;
|
|
|
|
+ unsigned int mode = mxcs->mode;
|
|
|
|
|
|
clk_src = mxc_get_clock(MXC_CSPI_CLK);
|
|
clk_src = mxc_get_clock(MXC_CSPI_CLK);
|
|
|
|
|
|
@@ -120,19 +123,15 @@ static s32 spi_cfg_mxc(struct mxc_spi_slave *mxcs, unsigned int cs,
|
|
#endif
|
|
#endif
|
|
|
|
|
|
#ifdef MXC_ECSPI
|
|
#ifdef MXC_ECSPI
|
|
-static s32 spi_cfg_mxc(struct mxc_spi_slave *mxcs, unsigned int cs,
|
|
|
|
- unsigned int max_hz, unsigned int mode)
|
|
|
|
|
|
+static s32 spi_cfg_mxc(struct mxc_spi_slave *mxcs, unsigned int cs)
|
|
{
|
|
{
|
|
u32 clk_src = mxc_get_clock(MXC_CSPI_CLK);
|
|
u32 clk_src = mxc_get_clock(MXC_CSPI_CLK);
|
|
s32 reg_ctrl, reg_config;
|
|
s32 reg_ctrl, reg_config;
|
|
u32 ss_pol = 0, sclkpol = 0, sclkpha = 0, sclkctl = 0;
|
|
u32 ss_pol = 0, sclkpol = 0, sclkpha = 0, sclkctl = 0;
|
|
u32 pre_div = 0, post_div = 0;
|
|
u32 pre_div = 0, post_div = 0;
|
|
struct cspi_regs *regs = (struct cspi_regs *)mxcs->base;
|
|
struct cspi_regs *regs = (struct cspi_regs *)mxcs->base;
|
|
-
|
|
|
|
- if (max_hz == 0) {
|
|
|
|
- printf("Error: desired clock is 0\n");
|
|
|
|
- return -1;
|
|
|
|
- }
|
|
|
|
|
|
+ unsigned int max_hz = mxcs->max_hz;
|
|
|
|
+ unsigned int mode = mxcs->mode;
|
|
|
|
|
|
/*
|
|
/*
|
|
* Reset SPI and set all CSs to master mode, if toggling
|
|
* Reset SPI and set all CSs to master mode, if toggling
|
|
@@ -409,6 +408,11 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
|
|
if (bus >= ARRAY_SIZE(spi_bases))
|
|
if (bus >= ARRAY_SIZE(spi_bases))
|
|
return NULL;
|
|
return NULL;
|
|
|
|
|
|
|
|
+ if (max_hz == 0) {
|
|
|
|
+ printf("Error: desired clock is 0\n");
|
|
|
|
+ return NULL;
|
|
|
|
+ }
|
|
|
|
+
|
|
mxcs = spi_alloc_slave(struct mxc_spi_slave, bus, cs);
|
|
mxcs = spi_alloc_slave(struct mxc_spi_slave, bus, cs);
|
|
if (!mxcs) {
|
|
if (!mxcs) {
|
|
puts("mxc_spi: SPI Slave not allocated !\n");
|
|
puts("mxc_spi: SPI Slave not allocated !\n");
|
|
@@ -424,13 +428,9 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
|
|
}
|
|
}
|
|
|
|
|
|
mxcs->base = spi_bases[bus];
|
|
mxcs->base = spi_bases[bus];
|
|
|
|
+ mxcs->max_hz = max_hz;
|
|
|
|
+ mxcs->mode = mode;
|
|
|
|
|
|
- ret = spi_cfg_mxc(mxcs, cs, max_hz, mode);
|
|
|
|
- if (ret) {
|
|
|
|
- printf("mxc_spi: cannot setup SPI controller\n");
|
|
|
|
- free(mxcs);
|
|
|
|
- return NULL;
|
|
|
|
- }
|
|
|
|
return &mxcs->slave;
|
|
return &mxcs->slave;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -443,12 +443,17 @@ void spi_free_slave(struct spi_slave *slave)
|
|
|
|
|
|
int spi_claim_bus(struct spi_slave *slave)
|
|
int spi_claim_bus(struct spi_slave *slave)
|
|
{
|
|
{
|
|
|
|
+ int ret;
|
|
struct mxc_spi_slave *mxcs = to_mxc_spi_slave(slave);
|
|
struct mxc_spi_slave *mxcs = to_mxc_spi_slave(slave);
|
|
struct cspi_regs *regs = (struct cspi_regs *)mxcs->base;
|
|
struct cspi_regs *regs = (struct cspi_regs *)mxcs->base;
|
|
|
|
|
|
reg_write(®s->rxdata, 1);
|
|
reg_write(®s->rxdata, 1);
|
|
udelay(1);
|
|
udelay(1);
|
|
- reg_write(®s->ctrl, mxcs->ctrl_reg);
|
|
|
|
|
|
+ ret = spi_cfg_mxc(mxcs, slave->cs);
|
|
|
|
+ if (ret) {
|
|
|
|
+ printf("mxc_spi: cannot setup SPI controller\n");
|
|
|
|
+ return ret;
|
|
|
|
+ }
|
|
reg_write(®s->period, MXC_CSPIPERIOD_32KHZ);
|
|
reg_write(®s->period, MXC_CSPIPERIOD_32KHZ);
|
|
reg_write(®s->intr, 0);
|
|
reg_write(®s->intr, 0);
|
|
|
|
|