Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 221622
b: refs/heads/master
c: 2c24a5d
h: refs/heads/master
v: v3
  • Loading branch information
Sjur Brændeland authored and David S. Miller committed Nov 4, 2010
1 parent b84ba92 commit 01fda5e
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 20 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: f2527ec436fd675f08a8e7434f6e940688cb96d0
refs/heads/master: 2c24a5d1b4f48900f3ed1b1ad70c51f1983df822
57 changes: 42 additions & 15 deletions trunk/drivers/net/caif/caif_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ MODULE_LICENSE("GPL");
MODULE_AUTHOR("Daniel Martensson<daniel.martensson@stericsson.com>");
MODULE_DESCRIPTION("CAIF SPI driver");

/* Returns the number of padding bytes for alignment. */
#define PAD_POW2(x, pow) ((((x)&((pow)-1))==0) ? 0 : (((pow)-((x)&((pow)-1)))))

static int spi_loop;
module_param(spi_loop, bool, S_IRUGO);
MODULE_PARM_DESC(spi_loop, "SPI running in loopback mode.");
Expand All @@ -41,7 +44,10 @@ MODULE_PARM_DESC(spi_loop, "SPI running in loopback mode.");
module_param(spi_frm_align, int, S_IRUGO);
MODULE_PARM_DESC(spi_frm_align, "SPI frame alignment.");

/* SPI padding options. */
/*
* SPI padding options.
* Warning: must be a base of 2 (& operation used) and can not be zero !
*/
module_param(spi_up_head_align, int, S_IRUGO);
MODULE_PARM_DESC(spi_up_head_align, "SPI uplink head alignment.");

Expand Down Expand Up @@ -240,15 +246,13 @@ static ssize_t dbgfs_frame(struct file *file, char __user *user_buf,
static const struct file_operations dbgfs_state_fops = {
.open = dbgfs_open,
.read = dbgfs_state,
.owner = THIS_MODULE,
.llseek = default_llseek,
.owner = THIS_MODULE
};

static const struct file_operations dbgfs_frame_fops = {
.open = dbgfs_open,
.read = dbgfs_frame,
.owner = THIS_MODULE,
.llseek = default_llseek,
.owner = THIS_MODULE
};

static inline void dev_debugfs_add(struct cfspi *cfspi)
Expand Down Expand Up @@ -337,6 +341,9 @@ int cfspi_xmitfrm(struct cfspi *cfspi, u8 *buf, size_t len)
u8 *dst = buf;
caif_assert(buf);

if (cfspi->slave && !cfspi->slave_talked)
cfspi->slave_talked = true;

do {
struct sk_buff *skb;
struct caif_payload_info *info;
Expand All @@ -357,8 +364,8 @@ int cfspi_xmitfrm(struct cfspi *cfspi, u8 *buf, size_t len)
* Compute head offset i.e. number of bytes to add to
* get the start of the payload aligned.
*/
if (spi_up_head_align) {
spad = 1 + ((info->hdr_len + 1) & spi_up_head_align);
if (spi_up_head_align > 1) {
spad = 1 + PAD_POW2((info->hdr_len + 1), spi_up_head_align);
*dst = (u8)(spad - 1);
dst += spad;
}
Expand All @@ -373,7 +380,7 @@ int cfspi_xmitfrm(struct cfspi *cfspi, u8 *buf, size_t len)
* Compute tail offset i.e. number of bytes to add to
* get the complete CAIF frame aligned.
*/
epad = (skb->len + spad) & spi_up_tail_align;
epad = PAD_POW2((skb->len + spad), spi_up_tail_align);
dst += epad;

dev_kfree_skb(skb);
Expand Down Expand Up @@ -417,14 +424,14 @@ int cfspi_xmitlen(struct cfspi *cfspi)
* Compute head offset i.e. number of bytes to add to
* get the start of the payload aligned.
*/
if (spi_up_head_align)
spad = 1 + ((info->hdr_len + 1) & spi_up_head_align);
if (spi_up_head_align > 1)
spad = 1 + PAD_POW2((info->hdr_len + 1), spi_up_head_align);

/*
* Compute tail offset i.e. number of bytes to add to
* get the complete CAIF frame aligned.
*/
epad = (skb->len + spad) & spi_up_tail_align;
epad = PAD_POW2((skb->len + spad), spi_up_tail_align);

if ((skb->len + spad + epad + frm_len) <= CAIF_MAX_SPI_FRAME) {
skb_queue_tail(&cfspi->chead, skb);
Expand All @@ -433,6 +440,7 @@ int cfspi_xmitlen(struct cfspi *cfspi)
} else {
/* Put back packet. */
skb_queue_head(&cfspi->qhead, skb);
break;
}
} while (pkts <= CAIF_MAX_SPI_PKTS);

Expand All @@ -453,6 +461,15 @@ static void cfspi_ss_cb(bool assert, struct cfspi_ifc *ifc)
{
struct cfspi *cfspi = (struct cfspi *)ifc->priv;

/*
* The slave device is the master on the link. Interrupts before the
* slave has transmitted are considered spurious.
*/
if (cfspi->slave && !cfspi->slave_talked) {
printk(KERN_WARNING "CFSPI: Spurious SS interrupt.\n");
return;
}

if (!in_interrupt())
spin_lock(&cfspi->lock);
if (assert) {
Expand All @@ -465,7 +482,8 @@ static void cfspi_ss_cb(bool assert, struct cfspi_ifc *ifc)
spin_unlock(&cfspi->lock);

/* Wake up the xfer thread. */
wake_up_interruptible(&cfspi->wait);
if (assert)
wake_up_interruptible(&cfspi->wait);
}

static void cfspi_xfer_done_cb(struct cfspi_ifc *ifc)
Expand Down Expand Up @@ -523,7 +541,7 @@ int cfspi_rxfrm(struct cfspi *cfspi, u8 *buf, size_t len)
* Compute head offset i.e. number of bytes added to
* get the start of the payload aligned.
*/
if (spi_down_head_align) {
if (spi_down_head_align > 1) {
spad = 1 + *src;
src += spad;
}
Expand Down Expand Up @@ -564,7 +582,7 @@ int cfspi_rxfrm(struct cfspi *cfspi, u8 *buf, size_t len)
* Compute tail offset i.e. number of bytes added to
* get the complete CAIF frame aligned.
*/
epad = (pkt_len + spad) & spi_down_tail_align;
epad = PAD_POW2((pkt_len + spad), spi_down_tail_align);
src += epad;
} while ((src - buf) < len);

Expand Down Expand Up @@ -625,11 +643,20 @@ int cfspi_spi_probe(struct platform_device *pdev)
cfspi->ndev = ndev;
cfspi->pdev = pdev;

/* Set flow info */
/* Set flow info. */
cfspi->flow_off_sent = 0;
cfspi->qd_low_mark = LOW_WATER_MARK;
cfspi->qd_high_mark = HIGH_WATER_MARK;

/* Set slave info. */
if (!strncmp(cfspi_spi_driver.driver.name, "cfspi_sspi", 10)) {
cfspi->slave = true;
cfspi->slave_talked = false;
} else {
cfspi->slave = false;
cfspi->slave_talked = false;
}

/* Assign the SPI device. */
cfspi->dev = dev;
/* Assign the device ifc to this SPI interface. */
Expand Down
13 changes: 9 additions & 4 deletions trunk/drivers/net/caif/caif_spi_slave.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,15 @@ static inline int forward_to_spi_cmd(struct cfspi *cfspi)
#endif

int spi_frm_align = 2;
int spi_up_head_align = 1;
int spi_up_tail_align;
int spi_down_head_align = 3;
int spi_down_tail_align = 1;

/*
* SPI padding options.
* Warning: must be a base of 2 (& operation used) and can not be zero !
*/
int spi_up_head_align = 1 << 1;
int spi_up_tail_align = 1 << 0;
int spi_down_head_align = 1 << 2;
int spi_down_tail_align = 1 << 1;

#ifdef CONFIG_DEBUG_FS
static inline void debugfs_store_prev(struct cfspi *cfspi)
Expand Down
2 changes: 2 additions & 0 deletions trunk/include/net/caif/caif_spi.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ struct cfspi {
wait_queue_head_t wait;
spinlock_t lock;
bool flow_stop;
bool slave;
bool slave_talked;
#ifdef CONFIG_DEBUG_FS
enum cfspi_state dbg_state;
u16 pcmd;
Expand Down

0 comments on commit 01fda5e

Please sign in to comment.