Commit e0906f1f authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'i3c/for-6.4' of git://git.kernel.org/pub/scm/linux/kernel/git/i3c/linux

Pull i3c updates from Alexandre Belloni:
 "Subsystem:
   - OF alias bus numbering
   - convert to platform remove callback returning void

  New driver:
   - AST2600 controller, based on Synopsys DesignWare IP

  Driver update:
   - dw: add infrastructure to support different platform integrations"

* tag 'i3c/for-6.4' of git://git.kernel.org/pub/scm/linux/kernel/git/i3c/linux:
  i3c: ast2600: set variable ast2600_i3c_ops storage-class-specifier to static
  i3c: ast2600: fix register setting for 545 ohm pullups
  i3c: ast2600: enable IBI support
  i3c: dw: Add a platform facility for IBI PEC workarounds
  i3c: dw: Add support for in-band interrupts
  i3c: dw: Turn DAT array entry into a struct
  i3c: dw: Create a generic fifo read function
  i3c: Allow OF-alias-based persistent bus numbering
  i3c: ast2600: Add AST2600 platform-specific driver
  dt-bindings: i3c: Add AST2600 i3c controller
  i3c: dw: Add infrastructure for platform-specific implementations
  i3c: dw: use bus mode rather than device reg for conditional tCAS setting
  i3c: dw: Return the length from a read priv_xfer
  i3c: svc: Convert to platform remove callback returning void
  i3c: mipi-i3c-hci: Convert to platform remove callback returning void
  i3c: cdns: Convert to platform remove callback returning void
  i3c: dw: Convert to platform remove callback returning void
  i3c: Make i3c_master_unregister() return void
  i3c: dw: drop of_match_ptr for ID table
  i3c: Correct reference to the I²C device data type
parents 06936aaf 6b496a94
# SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause
%YAML 1.2
---
$id: http://devicetree.org/schemas/i3c/aspeed,ast2600-i3c.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#
title: ASPEED AST2600 i3c controller
maintainers:
- Jeremy Kerr <jk@codeconstruct.com.au>
allOf:
- $ref: i3c.yaml#
properties:
compatible:
const: aspeed,ast2600-i3c
reg:
maxItems: 1
clocks:
maxItems: 1
resets:
maxItems: 1
interrupts:
maxItems: 1
sda-pullup-ohms:
enum: [545, 750, 2000]
default: 2000
description: |
Value to configure SDA pullup resistor, in Ohms.
aspeed,global-regs:
$ref: /schemas/types.yaml#/definitions/phandle-array
items:
- items:
- description: phandle to i3c global register syscon node
- description: index of this i3c controller in the global register set
description: |
A (phandle, controller index) reference to the i3c global register set
used for this device.
required:
- compatible
- reg
- clocks
- interrupts
- aspeed,global-regs
unevaluatedProperties: false
examples:
- |
#include <dt-bindings/interrupt-controller/arm-gic.h>
i3c-master@2000 {
compatible = "aspeed,ast2600-i3c";
reg = <0x2000 0x1000>;
#address-cells = <3>;
#size-cells = <0>;
clocks = <&syscon 0>;
resets = <&syscon 0>;
aspeed,global-regs = <&i3c_global 0>;
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_i3c1_default>;
interrupts = <GIC_SPI 102 IRQ_TYPE_LEVEL_HIGH>;
};
...
......@@ -9778,6 +9778,12 @@ S: Orphan
F: Documentation/devicetree/bindings/i3c/snps,dw-i3c-master.yaml
F: drivers/i3c/master/dw*
I3C DRIVER FOR ASPEED AST2600
M: Jeremy Kerr <jk@codeconstruct.com.au>
S: Maintained
F: Documentation/devicetree/bindings/i3c/aspeed,ast2600-i3c.yaml
F: drivers/i3c/master/ast2600-i3c-master.c
I3C SUBSYSTEM
M: Alexandre Belloni <alexandre.belloni@bootlin.com>
L: linux-i3c@lists.infradead.org (moderated for non-subscribers)
......
......@@ -21,6 +21,7 @@
static DEFINE_IDR(i3c_bus_idr);
static DEFINE_MUTEX(i3c_core_lock);
static int __i3c_first_dynamic_bus_num;
/**
* i3c_bus_maintenance_lock - Lock the bus for a maintenance operation
......@@ -419,9 +420,9 @@ static void i3c_bus_cleanup(struct i3c_bus *i3cbus)
mutex_unlock(&i3c_core_lock);
}
static int i3c_bus_init(struct i3c_bus *i3cbus)
static int i3c_bus_init(struct i3c_bus *i3cbus, struct device_node *np)
{
int ret;
int ret, start, end, id = -1;
init_rwsem(&i3cbus->lock);
INIT_LIST_HEAD(&i3cbus->devs.i2c);
......@@ -429,8 +430,19 @@ static int i3c_bus_init(struct i3c_bus *i3cbus)
i3c_bus_init_addrslots(i3cbus);
i3cbus->mode = I3C_BUS_MODE_PURE;
if (np)
id = of_alias_get_id(np, "i3c");
mutex_lock(&i3c_core_lock);
ret = idr_alloc(&i3c_bus_idr, i3cbus, 0, 0, GFP_KERNEL);
if (id >= 0) {
start = id;
end = start + 1;
} else {
start = __i3c_first_dynamic_bus_num;
end = 0;
}
ret = idr_alloc(&i3c_bus_idr, i3cbus, start, end, GFP_KERNEL);
mutex_unlock(&i3c_core_lock);
if (ret < 0)
......@@ -2606,7 +2618,7 @@ int i3c_master_register(struct i3c_master_controller *master,
INIT_LIST_HEAD(&master->boardinfo.i2c);
INIT_LIST_HEAD(&master->boardinfo.i3c);
ret = i3c_bus_init(i3cbus);
ret = i3c_bus_init(i3cbus, master->dev.of_node);
if (ret)
return ret;
......@@ -2695,17 +2707,13 @@ EXPORT_SYMBOL_GPL(i3c_master_register);
* @master: master used to send frames on the bus
*
* Basically undo everything done in i3c_master_register().
*
* Return: 0 in case of success, a negative error code otherwise.
*/
int i3c_master_unregister(struct i3c_master_controller *master)
void i3c_master_unregister(struct i3c_master_controller *master)
{
i3c_master_i2c_adapter_cleanup(master);
i3c_master_unregister_i3c_devs(master);
i3c_master_bus_cleanup(master);
device_unregister(&master->dev);
return 0;
}
EXPORT_SYMBOL_GPL(i3c_master_unregister);
......@@ -2834,8 +2842,16 @@ void i3c_dev_free_ibi_locked(struct i3c_dev_desc *dev)
static int __init i3c_init(void)
{
int res = bus_register_notifier(&i2c_bus_type, &i2cdev_notifier);
int res;
res = of_alias_get_highest_id("i3c");
if (res >= 0) {
mutex_lock(&i3c_core_lock);
__i3c_first_dynamic_bus_num = res + 1;
mutex_unlock(&i3c_core_lock);
}
res = bus_register_notifier(&i2c_bus_type, &i2cdev_notifier);
if (res)
return res;
......
......@@ -22,6 +22,20 @@ config DW_I3C_MASTER
This driver can also be built as a module. If so, the module
will be called dw-i3c-master.
config AST2600_I3C_MASTER
tristate "ASPEED AST2600 I3C master driver"
depends on DW_I3C_MASTER
depends on ARCH_ASPEED || COMPILE_TEST
select MFD_SYSCON
help
Support for ASPEED AST2600 I3C Controller.
This hardware is an instance of the DW I3C controller; this
driver adds platform- specific support for AST2600 hardware.
This driver can also be built as a module. If so, the module
will be called ast2600-i3c-master.
config SVC_I3C_MASTER
tristate "Silvaco I3C Dual-Role Master driver"
depends on I3C
......
# SPDX-License-Identifier: GPL-2.0-only
obj-$(CONFIG_CDNS_I3C_MASTER) += i3c-master-cdns.o
obj-$(CONFIG_DW_I3C_MASTER) += dw-i3c-master.o
obj-$(CONFIG_AST2600_I3C_MASTER) += ast2600-i3c-master.o
obj-$(CONFIG_SVC_I3C_MASTER) += svc-i3c-master.o
obj-$(CONFIG_MIPI_I3C_HCI) += mipi-i3c-hci/
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2023 Code Construct
*
* Author: Jeremy Kerr <jk@codeconstruct.com.au>
*/
#include <linux/mfd/syscon.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_device.h>
#include <linux/platform_device.h>
#include <linux/regmap.h>
#include "dw-i3c-master.h"
/* AST2600-specific global register set */
#define AST2600_I3CG_REG0(idx) (((idx) * 4 * 4) + 0x10)
#define AST2600_I3CG_REG1(idx) (((idx) * 4 * 4) + 0x14)
#define AST2600_I3CG_REG0_SDA_PULLUP_EN_MASK GENMASK(29, 28)
#define AST2600_I3CG_REG0_SDA_PULLUP_EN_2K (0x0 << 28)
#define AST2600_I3CG_REG0_SDA_PULLUP_EN_750 (0x2 << 28)
#define AST2600_I3CG_REG0_SDA_PULLUP_EN_545 (0x3 << 28)
#define AST2600_I3CG_REG1_I2C_MODE BIT(0)
#define AST2600_I3CG_REG1_TEST_MODE BIT(1)
#define AST2600_I3CG_REG1_ACT_MODE_MASK GENMASK(3, 2)
#define AST2600_I3CG_REG1_ACT_MODE(x) (((x) << 2) & AST2600_I3CG_REG1_ACT_MODE_MASK)
#define AST2600_I3CG_REG1_PENDING_INT_MASK GENMASK(7, 4)
#define AST2600_I3CG_REG1_PENDING_INT(x) (((x) << 4) & AST2600_I3CG_REG1_PENDING_INT_MASK)
#define AST2600_I3CG_REG1_SA_MASK GENMASK(14, 8)
#define AST2600_I3CG_REG1_SA(x) (((x) << 8) & AST2600_I3CG_REG1_SA_MASK)
#define AST2600_I3CG_REG1_SA_EN BIT(15)
#define AST2600_I3CG_REG1_INST_ID_MASK GENMASK(19, 16)
#define AST2600_I3CG_REG1_INST_ID(x) (((x) << 16) & AST2600_I3CG_REG1_INST_ID_MASK)
#define AST2600_DEFAULT_SDA_PULLUP_OHMS 2000
#define DEV_ADDR_TABLE_IBI_PEC BIT(11)
struct ast2600_i3c {
struct dw_i3c_master dw;
struct regmap *global_regs;
unsigned int global_idx;
unsigned int sda_pullup;
};
static struct ast2600_i3c *to_ast2600_i3c(struct dw_i3c_master *dw)
{
return container_of(dw, struct ast2600_i3c, dw);
}
static int ast2600_i3c_pullup_to_reg(unsigned int ohms, u32 *regp)
{
u32 reg;
switch (ohms) {
case 2000:
reg = AST2600_I3CG_REG0_SDA_PULLUP_EN_2K;
break;
case 750:
reg = AST2600_I3CG_REG0_SDA_PULLUP_EN_750;
break;
case 545:
reg = AST2600_I3CG_REG0_SDA_PULLUP_EN_545;
break;
default:
return -EINVAL;
}
if (regp)
*regp = reg;
return 0;
}
static int ast2600_i3c_init(struct dw_i3c_master *dw)
{
struct ast2600_i3c *i3c = to_ast2600_i3c(dw);
u32 reg = 0;
int rc;
/* reg0: set SDA pullup values */
rc = ast2600_i3c_pullup_to_reg(i3c->sda_pullup, &reg);
if (rc)
return rc;
rc = regmap_write(i3c->global_regs,
AST2600_I3CG_REG0(i3c->global_idx), reg);
if (rc)
return rc;
/* reg1: set up the instance id, but leave everything else disabled,
* as it's all for client mode
*/
reg = AST2600_I3CG_REG1_INST_ID(i3c->global_idx);
rc = regmap_write(i3c->global_regs,
AST2600_I3CG_REG1(i3c->global_idx), reg);
return rc;
}
static void ast2600_i3c_set_dat_ibi(struct dw_i3c_master *i3c,
struct i3c_dev_desc *dev,
bool enable, u32 *dat)
{
/*
* The ast2600 i3c controller will lock up on receiving 4n+1-byte IBIs
* if the PEC is disabled. We have no way to restrict the length of
* IBIs sent to the controller, so we need to unconditionally enable
* PEC checking, which means we drop a byte of payload data
*/
if (enable && dev->info.bcr & I3C_BCR_IBI_PAYLOAD) {
dev_warn_once(&i3c->base.dev,
"Enabling PEC workaround. IBI payloads will be truncated\n");
*dat |= DEV_ADDR_TABLE_IBI_PEC;
}
}
static const struct dw_i3c_platform_ops ast2600_i3c_ops = {
.init = ast2600_i3c_init,
.set_dat_ibi = ast2600_i3c_set_dat_ibi,
};
static int ast2600_i3c_probe(struct platform_device *pdev)
{
struct device_node *np = pdev->dev.of_node;
struct of_phandle_args gspec;
struct ast2600_i3c *i3c;
int rc;
i3c = devm_kzalloc(&pdev->dev, sizeof(*i3c), GFP_KERNEL);
if (!i3c)
return -ENOMEM;
rc = of_parse_phandle_with_fixed_args(np, "aspeed,global-regs", 1, 0,
&gspec);
if (rc)
return -ENODEV;
i3c->global_regs = syscon_node_to_regmap(gspec.np);
of_node_put(gspec.np);
if (IS_ERR(i3c->global_regs))
return PTR_ERR(i3c->global_regs);
i3c->global_idx = gspec.args[0];
rc = of_property_read_u32(np, "sda-pullup-ohms", &i3c->sda_pullup);
if (rc)
i3c->sda_pullup = AST2600_DEFAULT_SDA_PULLUP_OHMS;
rc = ast2600_i3c_pullup_to_reg(i3c->sda_pullup, NULL);
if (rc)
dev_err(&pdev->dev, "invalid sda-pullup value %d\n",
i3c->sda_pullup);
i3c->dw.platform_ops = &ast2600_i3c_ops;
i3c->dw.ibi_capable = true;
return dw_i3c_common_probe(&i3c->dw, pdev);
}
static void ast2600_i3c_remove(struct platform_device *pdev)
{
struct dw_i3c_master *dw_i3c = platform_get_drvdata(pdev);
dw_i3c_common_remove(dw_i3c);
}
static const struct of_device_id ast2600_i3c_master_of_match[] = {
{ .compatible = "aspeed,ast2600-i3c", },
{},
};
MODULE_DEVICE_TABLE(of, ast2600_i3c_master_of_match);
static struct platform_driver ast2600_i3c_driver = {
.probe = ast2600_i3c_probe,
.remove_new = ast2600_i3c_remove,
.driver = {
.name = "ast2600-i3c-master",
.of_match_table = ast2600_i3c_master_of_match,
},
};
module_platform_driver(ast2600_i3c_driver);
MODULE_AUTHOR("Jeremy Kerr <jk@codeconstruct.com.au>");
MODULE_DESCRIPTION("ASPEED AST2600 I3C driver");
MODULE_LICENSE("GPL");
This diff is collapsed.
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2023 Code Construct
*
* Author: Jeremy Kerr <jk@codeconstruct.com.au>
*/
#include <linux/clk.h>
#include <linux/i3c/master.h>
#include <linux/reset.h>
#include <linux/types.h>
#define DW_I3C_MAX_DEVS 32
struct dw_i3c_master_caps {
u8 cmdfifodepth;
u8 datafifodepth;
};
struct dw_i3c_dat_entry {
u8 addr;
struct i3c_dev_desc *ibi_dev;
};
struct dw_i3c_master {
struct i3c_master_controller base;
u16 maxdevs;
u16 datstartaddr;
u32 free_pos;
struct {
struct list_head list;
struct dw_i3c_xfer *cur;
spinlock_t lock;
} xferqueue;
struct dw_i3c_master_caps caps;
void __iomem *regs;
struct reset_control *core_rst;
struct clk *core_clk;
char version[5];
char type[5];
bool ibi_capable;
/*
* Per-device hardware data, used to manage the device address table
* (DAT)
*
* Locking: the devs array may be referenced in IRQ context while
* processing an IBI. However, IBIs (for a specific device, which
* implies a specific DAT entry) can only happen while interrupts are
* requested for that device, which is serialised against other
* insertions/removals from the array by the global i3c infrastructure.
* So, devs_lock protects against concurrent updates to devs->ibi_dev
* between request_ibi/free_ibi and the IBI irq event.
*/
struct dw_i3c_dat_entry devs[DW_I3C_MAX_DEVS];
spinlock_t devs_lock;
/* platform-specific data */
const struct dw_i3c_platform_ops *platform_ops;
};
struct dw_i3c_platform_ops {
/*
* Called on early bus init: the i3c has been set up, but before any
* transactions have taken place. Platform implementations may use to
* perform actual device enabling with the i3c core ready.
*/
int (*init)(struct dw_i3c_master *i3c);
/*
* Initialise a DAT entry to enable/disable IBIs. Allows the platform
* to perform any device workarounds on the DAT entry before
* inserting into the hardware table.
*
* Called with the DAT lock held; must not sleep.
*/
void (*set_dat_ibi)(struct dw_i3c_master *i3c,
struct i3c_dev_desc *dev, bool enable, u32 *reg);
};
extern int dw_i3c_common_probe(struct dw_i3c_master *master,
struct platform_device *pdev);
extern void dw_i3c_common_remove(struct dw_i3c_master *master);
......@@ -1662,24 +1662,19 @@ static int cdns_i3c_master_probe(struct platform_device *pdev)
return ret;
}
static int cdns_i3c_master_remove(struct platform_device *pdev)
static void cdns_i3c_master_remove(struct platform_device *pdev)
{
struct cdns_i3c_master *master = platform_get_drvdata(pdev);
int ret;
ret = i3c_master_unregister(&master->base);
if (ret)
return ret;
i3c_master_unregister(&master->base);
clk_disable_unprepare(master->sysclk);
clk_disable_unprepare(master->pclk);
return 0;
}
static struct platform_driver cdns_i3c_master = {
.probe = cdns_i3c_master_probe,
.remove = cdns_i3c_master_remove,
.remove_new = cdns_i3c_master_remove,
.driver = {
.name = "cdns-i3c-master",
.of_match_table = cdns_i3c_master_of_ids,
......
......@@ -765,11 +765,11 @@ static int i3c_hci_probe(struct platform_device *pdev)
return 0;
}
static int i3c_hci_remove(struct platform_device *pdev)
static void i3c_hci_remove(struct platform_device *pdev)
{
struct i3c_hci *hci = platform_get_drvdata(pdev);
return i3c_master_unregister(&hci->master);
i3c_master_unregister(&hci->master);
}
static const __maybe_unused struct of_device_id i3c_hci_of_match[] = {
......@@ -780,7 +780,7 @@ MODULE_DEVICE_TABLE(of, i3c_hci_of_match);
static struct platform_driver i3c_hci_driver = {
.probe = i3c_hci_probe,
.remove = i3c_hci_remove,
.remove_new = i3c_hci_remove,
.driver = {
.name = "mipi-i3c-hci",
.of_match_table = of_match_ptr(i3c_hci_of_match),
......
......@@ -1569,19 +1569,14 @@ static int svc_i3c_master_probe(struct platform_device *pdev)
return ret;
}
static int svc_i3c_master_remove(struct platform_device *pdev)
static void svc_i3c_master_remove(struct platform_device *pdev)
{
struct svc_i3c_master *master = platform_get_drvdata(pdev);
int ret;
ret = i3c_master_unregister(&master->base);
if (ret)
return ret;
i3c_master_unregister(&master->base);
pm_runtime_dont_use_autosuspend(&pdev->dev);
pm_runtime_disable(&pdev->dev);
return 0;
}
static int __maybe_unused svc_i3c_runtime_suspend(struct device *dev)
......@@ -1619,7 +1614,7 @@ MODULE_DEVICE_TABLE(of, svc_i3c_master_of_match_tbl);
static struct platform_driver svc_i3c_master = {
.probe = svc_i3c_master_probe,
.remove = svc_i3c_master_remove,
.remove_new = svc_i3c_master_remove,
.driver = {
.name = "silvaco-i3c-master",
.of_match_table = svc_i3c_master_of_match_tbl,
......
......@@ -22,9 +22,10 @@
#define I3C_BROADCAST_ADDR 0x7e
#define I3C_MAX_ADDR GENMASK(6, 0)
struct i2c_client;
struct i3c_master_controller;
struct i3c_bus;
struct i2c_device;
struct i3c_device;
/**
......@@ -541,7 +542,7 @@ int i3c_master_register(struct i3c_master_controller *master,
struct device *parent,
const struct i3c_master_controller_ops *ops,
bool secondary);
int i3c_master_unregister(struct i3c_master_controller *master);
void i3c_master_unregister(struct i3c_master_controller *master);
/**
* i3c_dev_get_master_data() - get master private data attached to an I3C
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment