linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] i2c: davinci: Add block read functionality for IPMI
@ 2014-05-01 18:49 Murali Karicheri
  2014-05-05 20:30 ` Karicheri, Muralidharan
  2014-05-22 10:51 ` Sekhar Nori
  0 siblings, 2 replies; 6+ messages in thread
From: Murali Karicheri @ 2014-05-01 18:49 UTC (permalink / raw)
  To: davinci-linux-open-source, linux-i2c, linux-kernel
  Cc: Murali Karicheri, Garrett Ding, Sekhar Nori, Kevin Hilman,
	Wolfram Sang, Santosh Shilimkar

Intelligent Plaform Management Interface (IPMI) requires I2C driver
to support block read, where the first byte received from slave is
the length of following data:-
 Added length check if the read type is block read (I2C_M_RECV_LEN)
 Send NACK/STOP bits before last byte is received

Signed-off-by: Garrett Ding <g-ding@ti.com>
Signed-off-by: Murali Karicheri <m-karicheri2@ti.com>
Tested-by: Garrett Ding <g-ding@ti.com>
CC: Sekhar Nori <nsekhar@ti.com>
CC: Kevin Hilman <khilman@deeprootsystems.com>
CC: Wolfram Sang <wsa@the-dreams.de>
CC: Santosh Shilimkar <santosh.shilimkar@ti.com>
---
 Tested on a customer board based on K2HK SoC
 drivers/i2c/busses/i2c-davinci.c |   42 +++++++++++++++++++++++++++++++++-----
 1 file changed, 37 insertions(+), 5 deletions(-)

diff --git a/drivers/i2c/busses/i2c-davinci.c b/drivers/i2c/busses/i2c-davinci.c
index 389bc68..cd97920 100644
--- a/drivers/i2c/busses/i2c-davinci.c
+++ b/drivers/i2c/busses/i2c-davinci.c
@@ -97,6 +97,10 @@
 #define DAVINCI_I2C_IMR_NACK	BIT(1)
 #define DAVINCI_I2C_IMR_AL	BIT(0)
 
+/* capabilities */
+#define I2C_CAPABILITIES	(I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | \
+				 I2C_FUNC_SMBUS_READ_BLOCK_DATA)
+
 struct davinci_i2c_dev {
 	struct device           *dev;
 	void __iomem		*base;
@@ -318,7 +322,13 @@ i2c_davinci_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, int stop)
 	davinci_i2c_write_reg(dev, DAVINCI_I2C_SAR_REG, msg->addr);
 
 	dev->buf = msg->buf;
-	dev->buf_len = msg->len;
+
+	 /* if first received byte is length, set buf_len = 0xffff as flag */
+	if (msg->flags & I2C_M_RECV_LEN)
+		dev->buf_len = 0xffff;
+	else
+		dev->buf_len = msg->len;
+
 	dev->stop = stop;
 
 	davinci_i2c_write_reg(dev, DAVINCI_I2C_CNT_REG, dev->buf_len);
@@ -456,7 +466,7 @@ i2c_davinci_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
 
 static u32 i2c_davinci_func(struct i2c_adapter *adap)
 {
-	return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
+	return I2C_CAPABILITIES;
 }
 
 static void terminate_read(struct davinci_i2c_dev *dev)
@@ -528,10 +538,32 @@ static irqreturn_t i2c_davinci_isr(int this_irq, void *dev_id)
 
 		case DAVINCI_I2C_IVR_RDR:
 			if (dev->buf_len) {
-				*dev->buf++ =
-				    davinci_i2c_read_reg(dev,
-							 DAVINCI_I2C_DRR_REG);
+				*dev->buf++ = davinci_i2c_read_reg(dev,
+							DAVINCI_I2C_DRR_REG);
+				/*
+				 * check if the first received byte is message
+				 * length, i.e, I2C_M_RECV_LEN
+				 */
+				if (dev->buf_len == 0xffff)
+					dev->buf_len = *(dev->buf - 1) + 1;
+
 				dev->buf_len--;
+				/*
+				 * send NACK/STOP bits BEFORE last byte is
+				 * received
+				 */
+				if (dev->buf_len == 1) {
+					w = davinci_i2c_read_reg(dev,
+							DAVINCI_I2C_MDR_REG);
+					w |= DAVINCI_I2C_MDR_NACK;
+					davinci_i2c_write_reg(dev,
+							DAVINCI_I2C_MDR_REG, w);
+
+					w |= DAVINCI_I2C_MDR_STP;
+					davinci_i2c_write_reg(dev,
+							DAVINCI_I2C_MDR_REG, w);
+				}
+
 				if (dev->buf_len)
 					continue;
 
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-06-02 16:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-01 18:49 [PATCH] i2c: davinci: Add block read functionality for IPMI Murali Karicheri
2014-05-05 20:30 ` Karicheri, Muralidharan
2014-05-22  9:00   ` Wolfram Sang
2014-06-02 16:28     ` Murali Karicheri
2014-05-22 10:51 ` Sekhar Nori
2014-06-02 16:29   ` Murali Karicheri

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).