[PATCH 0/3][Bionic][SRU Artful] thunderx2: i2c driver PEC and ACPI clock fixes

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH 0/3][Bionic][SRU Artful] thunderx2: i2c driver PEC and ACPI clock fixes

dann frazier-4
BugLink: https://bugs.launchpad.net/bugs/1738073

All clean cherry picks from upstream.

Jayachandran C (2):
  ACPI / APD: Add clock frequency for ThunderX2 I2C controller
  i2c: xlp9xx: Get clock frequency with clk API

Kamlakant Patel (1):
  i2c: xlp9xx: Handle I2C_M_RECV_LEN in msg->flags

 drivers/acpi/acpi_apd.c         |  5 +++++
 drivers/i2c/busses/i2c-xlp9xx.c | 44 +++++++++++++++++++++++++++++++++++++----
 2 files changed, 45 insertions(+), 4 deletions(-)

--
2.15.1


--
kernel-team mailing list
[hidden email]
https://lists.ubuntu.com/mailman/listinfo/kernel-team
Reply | Threaded
Open this post in threaded view
|

[PATCH 1/3][Bionic][SRU Artful] ACPI / APD: Add clock frequency for ThunderX2 I2C controller

dann frazier-4
From: Jayachandran C <[hidden email]>

BugLink: https://bugs.launchpad.net/bugs/1738073

Add the input frequency of 125MHz for the ThunderX2 I2C controller block.
The ACPI ID used is "CAV9007".

Signed-off-by: Jayachandran C <[hidden email]>
Signed-off-by: Kamlakant Patel <[hidden email]>
Acked-by: Mika Westerberg <[hidden email]>
Acked-by: Rafael J. Wysocki <[hidden email]>
Signed-off-by: Wolfram Sang <[hidden email]>
(cherry picked from commit 1977dbefe92c0baefefb62927df6e3908af8c453)
Signed-off-by: dann frazier <[hidden email]>
---
 drivers/acpi/acpi_apd.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/acpi/acpi_apd.c b/drivers/acpi/acpi_apd.c
index d5999eb41c00..d553b0087947 100644
--- a/drivers/acpi/acpi_apd.c
+++ b/drivers/acpi/acpi_apd.c
@@ -116,6 +116,10 @@ static const struct apd_device_desc hip08_i2c_desc = {
  .setup = acpi_apd_setup,
  .fixed_clk_rate = 250000000,
 };
+static const struct apd_device_desc thunderx2_i2c_desc = {
+ .setup = acpi_apd_setup,
+ .fixed_clk_rate = 125000000,
+};
 #endif
 
 #else
@@ -180,6 +184,7 @@ static const struct acpi_device_id acpi_apd_device_ids[] = {
  { "APMC0D0F", APD_ADDR(xgene_i2c_desc) },
  { "BRCM900D", APD_ADDR(vulcan_spi_desc) },
  { "CAV900D",  APD_ADDR(vulcan_spi_desc) },
+ { "CAV9007",  APD_ADDR(thunderx2_i2c_desc) },
  { "HISI02A1", APD_ADDR(hip07_i2c_desc) },
  { "HISI02A2", APD_ADDR(hip08_i2c_desc) },
 #endif
--
2.15.1


--
kernel-team mailing list
[hidden email]
https://lists.ubuntu.com/mailman/listinfo/kernel-team
Reply | Threaded
Open this post in threaded view
|

[PATCH 2/3][Bionic][SRU Artful] i2c: xlp9xx: Get clock frequency with clk API

dann frazier-4
In reply to this post by dann frazier-4
From: Jayachandran C <[hidden email]>

BugLink: https://bugs.launchpad.net/bugs/1738073

Get the input clock frequency to the controller from the linux clk
API, if it is available. This allows us to pass in the block input
frequency either from ACPI (using APD) or from device tree.

The old hardcoded frequency is used as default for backwards compatibility.

Signed-off-by: Jayachandran C <[hidden email]>
Signed-off-by: Kamlakant Patel <[hidden email]>
Reviewed-by: Mika Westerberg <[hidden email]>
Signed-off-by: Wolfram Sang <[hidden email]>
(cherry picked from commit c347b8fc22b21899154cc153a4951aaf226b4e1a)
Signed-off-by: dann frazier <[hidden email]>
---
 drivers/i2c/busses/i2c-xlp9xx.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-xlp9xx.c b/drivers/i2c/busses/i2c-xlp9xx.c
index 6b106e94bc09..f0bef2d5306c 100644
--- a/drivers/i2c/busses/i2c-xlp9xx.c
+++ b/drivers/i2c/busses/i2c-xlp9xx.c
@@ -7,6 +7,7 @@
  */
 
 #include <linux/acpi.h>
+#include <linux/clk.h>
 #include <linux/completion.h>
 #include <linux/i2c.h>
 #include <linux/init.h>
@@ -84,6 +85,7 @@ struct xlp9xx_i2c_dev {
  u32 __iomem *base;
  u32 msg_buf_remaining;
  u32 msg_len;
+ u32 ip_clk_hz;
  u32 clk_hz;
  u32 msg_err;
  u8 *msg_buf;
@@ -213,7 +215,7 @@ static int xlp9xx_i2c_init(struct xlp9xx_i2c_dev *priv)
  * The controller uses 5 * SCL clock internally.
  * So prescale value should be divided by 5.
  */
- prescale = DIV_ROUND_UP(XLP9XX_I2C_IP_CLK_FREQ, priv->clk_hz);
+ prescale = DIV_ROUND_UP(priv->ip_clk_hz, priv->clk_hz);
  prescale = ((prescale - 8) / 5) - 1;
  xlp9xx_write_i2c_reg(priv, XLP9XX_I2C_CTRL, XLP9XX_I2C_CTRL_RST);
  xlp9xx_write_i2c_reg(priv, XLP9XX_I2C_CTRL, XLP9XX_I2C_CTRL_EN |
@@ -342,9 +344,19 @@ static const struct i2c_algorithm xlp9xx_i2c_algo = {
 static int xlp9xx_i2c_get_frequency(struct platform_device *pdev,
     struct xlp9xx_i2c_dev *priv)
 {
+ struct clk *clk;
  u32 freq;
  int err;
 
+ clk = devm_clk_get(&pdev->dev, NULL);
+ if (IS_ERR(clk)) {
+ priv->ip_clk_hz = XLP9XX_I2C_IP_CLK_FREQ;
+ dev_dbg(&pdev->dev, "using default input frequency %u\n",
+ priv->ip_clk_hz);
+ } else {
+ priv->ip_clk_hz = clk_get_rate(clk);
+ }
+
  err = device_property_read_u32(&pdev->dev, "clock-frequency", &freq);
  if (err) {
  freq = XLP9XX_I2C_DEFAULT_FREQ;
--
2.15.1


--
kernel-team mailing list
[hidden email]
https://lists.ubuntu.com/mailman/listinfo/kernel-team
Reply | Threaded
Open this post in threaded view
|

[PATCH 3/3][Bionic][SRU Artful] i2c: xlp9xx: Handle I2C_M_RECV_LEN in msg->flags

dann frazier-4
In reply to this post by dann frazier-4
From: Kamlakant Patel <[hidden email]>

BugLink: https://bugs.launchpad.net/bugs/1738073

The driver needs to handle the flag I2C_M_RECV_LEN during receive to
support SMBus emulation.

Update receive logic to handle the case where the length is received
as the first byte of a transaction.

Also update the code to handle I2C_CLIENT_PEC, which is set when the
client sends a packet error checking code byte.

Signed-off-by: Jayachandran C <[hidden email]>
Signed-off-by: Kamlakant Patel <[hidden email]>
Reviewed-by: Mika Westerberg <[hidden email]>
Signed-off-by: Wolfram Sang <[hidden email]>
(cherry picked from commit 5515ae112172e20667f02b16f45fbf992923dcb0)
Signed-off-by: dann frazier <[hidden email]>
---
 drivers/i2c/busses/i2c-xlp9xx.c | 30 +++++++++++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)

diff --git a/drivers/i2c/busses/i2c-xlp9xx.c b/drivers/i2c/busses/i2c-xlp9xx.c
index f0bef2d5306c..b970bf8f38e5 100644
--- a/drivers/i2c/busses/i2c-xlp9xx.c
+++ b/drivers/i2c/busses/i2c-xlp9xx.c
@@ -82,6 +82,8 @@ struct xlp9xx_i2c_dev {
  struct completion msg_complete;
  int irq;
  bool msg_read;
+ bool len_recv;
+ bool client_pec;
  u32 __iomem *base;
  u32 msg_buf_remaining;
  u32 msg_len;
@@ -143,10 +145,25 @@ static void xlp9xx_i2c_fill_tx_fifo(struct xlp9xx_i2c_dev *priv)
 static void xlp9xx_i2c_drain_rx_fifo(struct xlp9xx_i2c_dev *priv)
 {
  u32 len, i;
- u8 *buf = priv->msg_buf;
+ u8 rlen, *buf = priv->msg_buf;
 
  len = xlp9xx_read_i2c_reg(priv, XLP9XX_I2C_FIFOWCNT) &
   XLP9XX_I2C_FIFO_WCNT_MASK;
+ if (!len)
+ return;
+ if (priv->len_recv) {
+ /* read length byte */
+ rlen = xlp9xx_read_i2c_reg(priv, XLP9XX_I2C_MRXFIFO);
+ *buf++ = rlen;
+ len--;
+ if (priv->client_pec)
+ ++rlen;
+ /* update remaining bytes and message length */
+ priv->msg_buf_remaining = rlen;
+ priv->msg_len = rlen + 1;
+ priv->len_recv = false;
+ }
+
  len = min(priv->msg_buf_remaining, len);
  for (i = 0; i < len; i++, buf++)
  *buf = xlp9xx_read_i2c_reg(priv, XLP9XX_I2C_MRXFIFO);
@@ -230,7 +247,7 @@ static int xlp9xx_i2c_xfer_msg(struct xlp9xx_i2c_dev *priv, struct i2c_msg *msg,
        int last_msg)
 {
  unsigned long timeleft;
- u32 intr_mask, cmd, val;
+ u32 intr_mask, cmd, val, len;
 
  priv->msg_buf = msg->buf;
  priv->msg_buf_remaining = priv->msg_len = msg->len;
@@ -263,9 +280,13 @@ static int xlp9xx_i2c_xfer_msg(struct xlp9xx_i2c_dev *priv, struct i2c_msg *msg,
  else
  val &= ~XLP9XX_I2C_CTRL_ADDMODE;
 
+ priv->len_recv = msg->flags & I2C_M_RECV_LEN;
+ len = priv->len_recv ? XLP9XX_I2C_FIFO_SIZE : msg->len;
+ priv->client_pec = msg->flags & I2C_CLIENT_PEC;
+
  /* set data length to be transferred */
  val = (val & ~XLP9XX_I2C_CTRL_MCTLEN_MASK) |
-      (msg->len << XLP9XX_I2C_CTRL_MCTLEN_SHIFT);
+      (len << XLP9XX_I2C_CTRL_MCTLEN_SHIFT);
  xlp9xx_write_i2c_reg(priv, XLP9XX_I2C_CTRL, val);
 
  /* fill fifo during tx */
@@ -312,6 +333,9 @@ static int xlp9xx_i2c_xfer_msg(struct xlp9xx_i2c_dev *priv, struct i2c_msg *msg,
  return -ETIMEDOUT;
  }
 
+ /* update msg->len with actual received length */
+ if (msg->flags & I2C_M_RECV_LEN)
+ msg->len = priv->msg_len;
  return 0;
 }
 
--
2.15.1


--
kernel-team mailing list
[hidden email]
https://lists.ubuntu.com/mailman/listinfo/kernel-team
Reply | Threaded
Open this post in threaded view
|

ACK/APPLIED[B]: [PATCH 0/3][Bionic][SRU Artful] thunderx2: i2c driver PEC and ACPI clock fixes

Seth Forshee
In reply to this post by dann frazier-4
On Wed, Dec 13, 2017 at 02:35:13PM -0700, dann frazier wrote:
> BugLink: https://bugs.launchpad.net/bugs/1738073
>
> All clean cherry picks from upstream.

Clean cherry picks, scope limited to a single driver.

Acked-by: Seth Forshee <[hidden email]>

Applied to bionic/master-next. Thanks!

--
kernel-team mailing list
[hidden email]
https://lists.ubuntu.com/mailman/listinfo/kernel-team
Reply | Threaded
Open this post in threaded view
|

[RESEND][PATCH 1/3][SRU Artful] ACPI / APD: Add clock frequency for ThunderX2 I2C controller

dann frazier-4
In reply to this post by dann frazier-4
From: Jayachandran C <[hidden email]>

BugLink: https://bugs.launchpad.net/bugs/1738073

Add the input frequency of 125MHz for the ThunderX2 I2C controller block.
The ACPI ID used is "CAV9007".

Signed-off-by: Jayachandran C <[hidden email]>
Signed-off-by: Kamlakant Patel <[hidden email]>
Acked-by: Mika Westerberg <[hidden email]>
Acked-by: Rafael J. Wysocki <[hidden email]>
Signed-off-by: Wolfram Sang <[hidden email]>
(cherry picked from commit 1977dbefe92c0baefefb62927df6e3908af8c453)
Signed-off-by: dann frazier <[hidden email]>
---
 drivers/acpi/acpi_apd.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/acpi/acpi_apd.c b/drivers/acpi/acpi_apd.c
index d5999eb41c00..d553b0087947 100644
--- a/drivers/acpi/acpi_apd.c
+++ b/drivers/acpi/acpi_apd.c
@@ -116,6 +116,10 @@ static const struct apd_device_desc hip08_i2c_desc = {
  .setup = acpi_apd_setup,
  .fixed_clk_rate = 250000000,
 };
+static const struct apd_device_desc thunderx2_i2c_desc = {
+ .setup = acpi_apd_setup,
+ .fixed_clk_rate = 125000000,
+};
 #endif
 
 #else
@@ -180,6 +184,7 @@ static const struct acpi_device_id acpi_apd_device_ids[] = {
  { "APMC0D0F", APD_ADDR(xgene_i2c_desc) },
  { "BRCM900D", APD_ADDR(vulcan_spi_desc) },
  { "CAV900D",  APD_ADDR(vulcan_spi_desc) },
+ { "CAV9007",  APD_ADDR(thunderx2_i2c_desc) },
  { "HISI02A1", APD_ADDR(hip07_i2c_desc) },
  { "HISI02A2", APD_ADDR(hip08_i2c_desc) },
 #endif
--
2.15.1


--
kernel-team mailing list
[hidden email]
https://lists.ubuntu.com/mailman/listinfo/kernel-team

--
kernel-team mailing list
[hidden email]
https://lists.ubuntu.com/mailman/listinfo/kernel-team
Reply | Threaded
Open this post in threaded view
|

[RESEND][PATCH 2/3][SRU Artful] i2c: xlp9xx: Get clock frequency with clk API

dann frazier-4
In reply to this post by dann frazier-4
From: Jayachandran C <[hidden email]>

BugLink: https://bugs.launchpad.net/bugs/1738073

Get the input clock frequency to the controller from the linux clk
API, if it is available. This allows us to pass in the block input
frequency either from ACPI (using APD) or from device tree.

The old hardcoded frequency is used as default for backwards compatibility.

Signed-off-by: Jayachandran C <[hidden email]>
Signed-off-by: Kamlakant Patel <[hidden email]>
Reviewed-by: Mika Westerberg <[hidden email]>
Signed-off-by: Wolfram Sang <[hidden email]>
(cherry picked from commit c347b8fc22b21899154cc153a4951aaf226b4e1a)
Signed-off-by: dann frazier <[hidden email]>
---
 drivers/i2c/busses/i2c-xlp9xx.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-xlp9xx.c b/drivers/i2c/busses/i2c-xlp9xx.c
index 6b106e94bc09..f0bef2d5306c 100644
--- a/drivers/i2c/busses/i2c-xlp9xx.c
+++ b/drivers/i2c/busses/i2c-xlp9xx.c
@@ -7,6 +7,7 @@
  */
 
 #include <linux/acpi.h>
+#include <linux/clk.h>
 #include <linux/completion.h>
 #include <linux/i2c.h>
 #include <linux/init.h>
@@ -84,6 +85,7 @@ struct xlp9xx_i2c_dev {
  u32 __iomem *base;
  u32 msg_buf_remaining;
  u32 msg_len;
+ u32 ip_clk_hz;
  u32 clk_hz;
  u32 msg_err;
  u8 *msg_buf;
@@ -213,7 +215,7 @@ static int xlp9xx_i2c_init(struct xlp9xx_i2c_dev *priv)
  * The controller uses 5 * SCL clock internally.
  * So prescale value should be divided by 5.
  */
- prescale = DIV_ROUND_UP(XLP9XX_I2C_IP_CLK_FREQ, priv->clk_hz);
+ prescale = DIV_ROUND_UP(priv->ip_clk_hz, priv->clk_hz);
  prescale = ((prescale - 8) / 5) - 1;
  xlp9xx_write_i2c_reg(priv, XLP9XX_I2C_CTRL, XLP9XX_I2C_CTRL_RST);
  xlp9xx_write_i2c_reg(priv, XLP9XX_I2C_CTRL, XLP9XX_I2C_CTRL_EN |
@@ -342,9 +344,19 @@ static const struct i2c_algorithm xlp9xx_i2c_algo = {
 static int xlp9xx_i2c_get_frequency(struct platform_device *pdev,
     struct xlp9xx_i2c_dev *priv)
 {
+ struct clk *clk;
  u32 freq;
  int err;
 
+ clk = devm_clk_get(&pdev->dev, NULL);
+ if (IS_ERR(clk)) {
+ priv->ip_clk_hz = XLP9XX_I2C_IP_CLK_FREQ;
+ dev_dbg(&pdev->dev, "using default input frequency %u\n",
+ priv->ip_clk_hz);
+ } else {
+ priv->ip_clk_hz = clk_get_rate(clk);
+ }
+
  err = device_property_read_u32(&pdev->dev, "clock-frequency", &freq);
  if (err) {
  freq = XLP9XX_I2C_DEFAULT_FREQ;
--
2.15.1


--
kernel-team mailing list
[hidden email]
https://lists.ubuntu.com/mailman/listinfo/kernel-team

--
kernel-team mailing list
[hidden email]
https://lists.ubuntu.com/mailman/listinfo/kernel-team
Reply | Threaded
Open this post in threaded view
|

[RESEND][PATCH 3/3][SRU Artful] i2c: xlp9xx: Handle I2C_M_RECV_LEN in msg->flags

dann frazier-4
In reply to this post by dann frazier-4
From: Kamlakant Patel <[hidden email]>

BugLink: https://bugs.launchpad.net/bugs/1738073

The driver needs to handle the flag I2C_M_RECV_LEN during receive to
support SMBus emulation.

Update receive logic to handle the case where the length is received
as the first byte of a transaction.

Also update the code to handle I2C_CLIENT_PEC, which is set when the
client sends a packet error checking code byte.

Signed-off-by: Jayachandran C <[hidden email]>
Signed-off-by: Kamlakant Patel <[hidden email]>
Reviewed-by: Mika Westerberg <[hidden email]>
Signed-off-by: Wolfram Sang <[hidden email]>
(cherry picked from commit 5515ae112172e20667f02b16f45fbf992923dcb0)
Signed-off-by: dann frazier <[hidden email]>
---
 drivers/i2c/busses/i2c-xlp9xx.c | 30 +++++++++++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)

diff --git a/drivers/i2c/busses/i2c-xlp9xx.c b/drivers/i2c/busses/i2c-xlp9xx.c
index f0bef2d5306c..b970bf8f38e5 100644
--- a/drivers/i2c/busses/i2c-xlp9xx.c
+++ b/drivers/i2c/busses/i2c-xlp9xx.c
@@ -82,6 +82,8 @@ struct xlp9xx_i2c_dev {
  struct completion msg_complete;
  int irq;
  bool msg_read;
+ bool len_recv;
+ bool client_pec;
  u32 __iomem *base;
  u32 msg_buf_remaining;
  u32 msg_len;
@@ -143,10 +145,25 @@ static void xlp9xx_i2c_fill_tx_fifo(struct xlp9xx_i2c_dev *priv)
 static void xlp9xx_i2c_drain_rx_fifo(struct xlp9xx_i2c_dev *priv)
 {
  u32 len, i;
- u8 *buf = priv->msg_buf;
+ u8 rlen, *buf = priv->msg_buf;
 
  len = xlp9xx_read_i2c_reg(priv, XLP9XX_I2C_FIFOWCNT) &
   XLP9XX_I2C_FIFO_WCNT_MASK;
+ if (!len)
+ return;
+ if (priv->len_recv) {
+ /* read length byte */
+ rlen = xlp9xx_read_i2c_reg(priv, XLP9XX_I2C_MRXFIFO);
+ *buf++ = rlen;
+ len--;
+ if (priv->client_pec)
+ ++rlen;
+ /* update remaining bytes and message length */
+ priv->msg_buf_remaining = rlen;
+ priv->msg_len = rlen + 1;
+ priv->len_recv = false;
+ }
+
  len = min(priv->msg_buf_remaining, len);
  for (i = 0; i < len; i++, buf++)
  *buf = xlp9xx_read_i2c_reg(priv, XLP9XX_I2C_MRXFIFO);
@@ -230,7 +247,7 @@ static int xlp9xx_i2c_xfer_msg(struct xlp9xx_i2c_dev *priv, struct i2c_msg *msg,
        int last_msg)
 {
  unsigned long timeleft;
- u32 intr_mask, cmd, val;
+ u32 intr_mask, cmd, val, len;
 
  priv->msg_buf = msg->buf;
  priv->msg_buf_remaining = priv->msg_len = msg->len;
@@ -263,9 +280,13 @@ static int xlp9xx_i2c_xfer_msg(struct xlp9xx_i2c_dev *priv, struct i2c_msg *msg,
  else
  val &= ~XLP9XX_I2C_CTRL_ADDMODE;
 
+ priv->len_recv = msg->flags & I2C_M_RECV_LEN;
+ len = priv->len_recv ? XLP9XX_I2C_FIFO_SIZE : msg->len;
+ priv->client_pec = msg->flags & I2C_CLIENT_PEC;
+
  /* set data length to be transferred */
  val = (val & ~XLP9XX_I2C_CTRL_MCTLEN_MASK) |
-      (msg->len << XLP9XX_I2C_CTRL_MCTLEN_SHIFT);
+      (len << XLP9XX_I2C_CTRL_MCTLEN_SHIFT);
  xlp9xx_write_i2c_reg(priv, XLP9XX_I2C_CTRL, val);
 
  /* fill fifo during tx */
@@ -312,6 +333,9 @@ static int xlp9xx_i2c_xfer_msg(struct xlp9xx_i2c_dev *priv, struct i2c_msg *msg,
  return -ETIMEDOUT;
  }
 
+ /* update msg->len with actual received length */
+ if (msg->flags & I2C_M_RECV_LEN)
+ msg->len = priv->msg_len;
  return 0;
 }
 
--
2.15.1


--
kernel-team mailing list
[hidden email]
https://lists.ubuntu.com/mailman/listinfo/kernel-team

--
kernel-team mailing list
[hidden email]
https://lists.ubuntu.com/mailman/listinfo/kernel-team