Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Documentation/devicetree/bindings/i2c/apple,i2c.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ properties:
power-domains:
maxItems: 1

resets:
maxItems: 1

required:
- compatible
- reg
Expand Down
5 changes: 5 additions & 0 deletions arch/arm64/boot/dts/apple/t8132.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,7 @@
#address-cells = <0x1>;
#size-cells = <0x0>;
power-domains = <&ps_i2c0>;
resets = <&ps_i2c0>;

status = "disabled";
};
Expand All @@ -754,6 +755,7 @@
#address-cells = <0x1>;
#size-cells = <0x0>;
power-domains = <&ps_i2c1>;
resets = <&ps_i2c1>;

status = "disabled";
};
Expand All @@ -769,6 +771,7 @@
#address-cells = <0x1>;
#size-cells = <0x0>;
power-domains = <&ps_i2c2>;
resets = <&ps_i2c2>;

status = "disabled";
};
Expand All @@ -784,6 +787,7 @@
#address-cells = <0x1>;
#size-cells = <0x0>;
power-domains = <&ps_i2c3>;
resets = <&ps_i2c3>;

status = "disabled";
};
Expand All @@ -799,6 +803,7 @@
#address-cells = <0x1>;
#size-cells = <0x0>;
power-domains = <&ps_i2c4>;
resets = <&ps_i2c4>;

status = "disabled";
};
Expand Down
52 changes: 48 additions & 4 deletions drivers/i2c/busses/i2c-pasemi-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <linux/module.h>
#include <linux/pci.h>
#include <linux/pm_runtime.h>
#include <linux/reset.h>
#include <linux/sched.h>
#include <linux/slab.h>
#include <linux/stddef.h>
Expand Down Expand Up @@ -89,16 +90,44 @@ static void pasemi_reset(struct pasemi_smbus *smbus)
reinit_completion(&smbus->irq_completion);
}

static int pasemi_smb_wait_idle(struct pasemi_smbus *smbus, unsigned int *status)
{
return readx_poll_timeout(ioread32, smbus->ioaddr + REG_SMSTA,
*status, !(*status & (SMSTA_XIP | SMSTA_JAM)),
USEC_PER_MSEC,
USEC_PER_MSEC * PASEMI_TRANSFER_TIMEOUT_MS);
}

/*
* A controller can stay in a transaction that no CTL reset ends, for example
* after a system sleep. Only resetting the controller gets it out of there;
* its CTL is then back at the reset value and is written again.
*/
static bool pasemi_smb_recover(struct pasemi_smbus *smbus, unsigned int status)
{
if (!smbus->reset)
return false;

dev_warn(smbus->dev, "Bus is stuck (status 0x%08x xfstatus 0x%08x), resetting the controller\n",
status, reg_read(smbus, REG_XFSTA));
if (reset_control_reset(smbus->reset))
return false;

reg_write(smbus, REG_IMASK, 0);
pasemi_reset(smbus);
return true;
}

static int pasemi_smb_clear(struct pasemi_smbus *smbus)
{
unsigned int status;
int ret;

/* First wait for the bus to go idle */
ret = readx_poll_timeout(ioread32, smbus->ioaddr + REG_SMSTA,
status, !(status & (SMSTA_XIP | SMSTA_JAM)),
USEC_PER_MSEC,
USEC_PER_MSEC * PASEMI_TRANSFER_TIMEOUT_MS);
ret = pasemi_smb_wait_idle(smbus, &status);

if (ret < 0 && pasemi_smb_recover(smbus, status))
ret = pasemi_smb_wait_idle(smbus, &status);

if (ret < 0) {
dev_err(smbus->dev, "Bus is still stuck (status 0x%08x xfstatus 0x%08x)\n",
Expand Down Expand Up @@ -258,6 +287,21 @@ static int pasemi_i2c_xfer(struct i2c_adapter *adapter,
for (i = 0; i < num && !ret; i++)
ret = pasemi_i2c_xfer_msg(adapter, &msgs[i], (i == (num - 1)));

/*
* A timed-out transfer can leave the controller in it. Reset it and let
* the core retry; the retry sends the whole transfer again, including
* what may already have reached the device. SMBus transfers have no
* retry and recover at the start of their next transfer. The reset
* needs the controller powered, so it comes before the runtime PM
* reference is dropped.
*/
if (ret == -ETIME) {
unsigned int status = reg_read(smbus, REG_SMSTA);

if (status & SMSTA_XIP && pasemi_smb_recover(smbus, status))
ret = -EAGAIN;
}

out:
if (smbus->runtime_pm)
pm_runtime_put_autosuspend(smbus->dev);
Expand Down
4 changes: 4 additions & 0 deletions drivers/i2c/busses/i2c-pasemi-core.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

#define PASEMI_HW_REV_PCI -1

struct reset_control;

struct pasemi_smbus {
struct device *dev;
struct i2c_adapter adapter;
Expand All @@ -20,6 +22,8 @@ struct pasemi_smbus {
int use_irq;
bool runtime_pm;
struct completion irq_completion;
/* Resets a controller stuck in a transaction (optional) */
struct reset_control *reset;
};

int pasemi_i2c_common_probe(struct pasemi_smbus *smbus);
Expand Down
9 changes: 9 additions & 0 deletions drivers/i2c/busses/i2c-pasemi-platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>
#include <linux/reset.h>
#include <linux/types.h>

#include "i2c-pasemi-core.h"
Expand Down Expand Up @@ -120,6 +121,14 @@ static int pasemi_platform_i2c_probe(struct platform_device *pdev)
if (error)
return error;

smbus->reset = devm_reset_control_get_optional_exclusive(dev, NULL);
if (IS_ERR(smbus->reset))
return dev_err_probe(dev, PTR_ERR(smbus->reset),
"failed to get the reset\n");
/* A transfer stuck in the controller is retried once after a reset */
if (smbus->reset)
smbus->adapter.retries = 1;

platform_set_drvdata(pdev, data);
error = clk_prepare_enable(data->clk_ref);
if (error)
Expand Down