mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-13 05:54:23 +08:00
ef035628c3
regarding unneeded 'driver_data' and more sanity checks in the char device. For the host drivers, this release includes significant updates, with the primary change being the renaming from "master/slave" to "controller/target" to adhere to I2C v7 and SMBus 3.2 standards. New Support: - Added support for Intel Arrow Lake-H. - Added I2C support in the Arioha SoC by linking the Mediatek I2C controller. Cleanups: - Added the MODULE_DESCRIPTION() macro, resolving a modpost warning in the ALi 1563 Southbridge driver. - Constified the regmap_config declaration in the i2c-designware driver. - Improved the coding style in the Renesas R-Car driver by removing unnecessary semicolons after brackets. General improvements: - In the OMAP device, replaced NOIRQ_SYSTEM_SLEEP_PM_OPS with RUNTIME_PM_OPS to enable waking up the controller during suspend() before suspend_noirq() kicks in. - Improved logging in the Xilinx driver. - Added a warning (WARN()) in the Renesas R-Car driver for spurious interrupts. DTS Changes: - Removed address-cell and size-cell from the Atmel at91sam, nVidia Tegra 20, and Samsung S3c2410 devices. - Fixed Texas Instruments OMAP4 I2C controller to comply with the i2c-controller.yaml schema. - Improved indentation in DTS examples for several I2C devices. - Converted the NXP LPC1788 binding to the dt-schema. - Added documentation for the compatible string thead,th1520-i2c. - Added the "power-domains" property for the Meson I2C driver. AT24 EEPROM driver changes: - add support for two new Microchip models - document even more new models in DT bindings (those use fallback compatibles so no code changes) -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEOZGx6rniZ1Gk92RdFA3kzBSgKbYFAmaagXUACgkQFA3kzBSg KbYbXg/+Kox1Qg5LDsW9IM0YVKMbeGVCxwzNKIoL55TwW2kUOml2JZsrcTE0Ap9J SvcpcGs6kzoU8PMzQlmmPYgIU+5NZbd50CohM1TvHE7VPcduB+ydHfo61aF48obU K3biAxALkcNYG4ab5i83D04Fcfwwgmt5wU/nXvcySTRteeBOtcB+MniZ0fJWG4q1 3czYndwLgWwKa+xOaI0Y1tf5Fc8LEtyGCDQuvDtbA0/cr4RjAYVo9t8cPsKi0Ywk WEsgk7e2u74UwepmR/SQcKJ25Z70hf9k0vsyGVCPqqGNZPeCOWhiFgphU57Dm2Gm IX5CncwMT/5jYa1AoZmWmc2SkDIkk+RXq6zaOgncuDtFy78A+DHSzRSnOk5cjXX+ cNu5Er5UEzVxnJGM46C+1/60LnqIpQYyEW5goPhr91So8UPMC+PaK2eNJ+nknSxS jc2832KlWcKj0Hun7X6fbVHNGX/AKpNzwrYjOy7Rxd0G/ViaspzKSD+eukAFQuKX PX5pGcO/syzGIzXMP7aRoQ+I0TIIpTaIB9UeuCTzTSzYYmtI/yKgDp9Cbi5yPGD8 EXEVPfL3jmjxMmoYUXVPeE7qHMLm/wlrhrMvhhBKHsvzQ3MfSw9J/lcEnuKGiWYu PEKRsIdlp2qJL0tseoB/dlwWIMgW7XHT5pg4I9FoX1H1UWC89cs= =perV -----END PGP SIGNATURE----- Merge tag 'i2c-for-6.11-rc1-try2' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux Pull i2c fixes from Wolfram Sang: "The I2C core gains documentation updates for the testunit, a cleanup regarding unneeded 'driver_data' and more sanity checks in the char device. For the host drivers, this release includes significant updates, with the primary change being the renaming from "master/slave" to "controller/target" to adhere to I2C v7 and SMBus 3.2 standards. New Support: - Added support for Intel Arrow Lake-H - Added I2C support in the Arioha SoC by linking the Mediatek I2C controller Cleanups: - Added the MODULE_DESCRIPTION() macro, resolving a modpost warning in the ALi 1563 Southbridge driver. - Constified the regmap_config declaration in the i2c-designware driver. - Improved the coding style in the Renesas R-Car driver by removing unnecessary semicolons after brackets. General improvements: - In the OMAP device, replaced NOIRQ_SYSTEM_SLEEP_PM_OPS with RUNTIME_PM_OPS to enable waking up the controller during suspend() before suspend_noirq() kicks in. - Improved logging in the Xilinx driver. - Added a warning (WARN()) in the Renesas R-Car driver for spurious interrupts. DTS Changes: - Removed address-cell and size-cell from the Atmel at91sam, nVidia Tegra 20, and Samsung S3c2410 devices. - Fixed Texas Instruments OMAP4 I2C controller to comply with the i2c-controller.yaml schema. - Improved indentation in DTS examples for several I2C devices. - Converted the NXP LPC1788 binding to the dt-schema. - Added documentation for the compatible string thead,th1520-i2c. - Added the "power-domains" property for the Meson I2C driver. AT24 EEPROM driver changes: - add support for two new Microchip models - document even more new models in DT bindings (those use fallback compatibles so no code changes)" * tag 'i2c-for-6.11-rc1-try2' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux: (87 commits) i2c: document new callbacks in i2c_algorithm dt-bindings: i2c: amlogic,meson6-i2c: add optional power-domains dt-bindings: i2c: at91: Add sama7d65 compatible string i2c: st: reword according to newest specification i2c: cpm: reword according to newest specification i2c: virtio: reword according to newest specification i2c: nvidia-gpu: reword according to newest specification i2c: viai2c: reword according to newest specification i2c: viperboard: reword according to newest specification i2c: uniphier: reword according to newest specification i2c: uniphier-f: reword according to newest specification i2c: tiny-usb: reword according to newest specification i2c: thunderx-pcidrv: reword according to newest specification i2c: tegra-bpmp: reword according to newest specification i2c: taos-evm: reword according to newest specification i2c: sun6i-p2wi: reword according to newest specification i2c: stm32f4: reword according to newest specification i2c: sprd: reword according to newest specification i2c: sis5595: reword according to newest specification i2c: rzv2m: reword according to newest specification ...
193 lines
4.4 KiB
C
193 lines
4.4 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* I2C slave mode testunit
|
|
*
|
|
* Copyright (C) 2020 by Wolfram Sang, Sang Engineering <wsa@sang-engineering.com>
|
|
* Copyright (C) 2020 by Renesas Electronics Corporation
|
|
*/
|
|
|
|
#include <linux/bitops.h>
|
|
#include <linux/i2c.h>
|
|
#include <linux/init.h>
|
|
#include <linux/module.h>
|
|
#include <linux/of.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/workqueue.h> /* FIXME: is system_long_wq the best choice? */
|
|
|
|
#define TU_CUR_VERSION 0x01
|
|
|
|
enum testunit_cmds {
|
|
TU_CMD_READ_BYTES = 1, /* save 0 for ABORT, RESET or similar */
|
|
TU_CMD_HOST_NOTIFY,
|
|
TU_CMD_SMBUS_BLOCK_PROC_CALL,
|
|
TU_NUM_CMDS
|
|
};
|
|
|
|
enum testunit_regs {
|
|
TU_REG_CMD,
|
|
TU_REG_DATAL,
|
|
TU_REG_DATAH,
|
|
TU_REG_DELAY,
|
|
TU_NUM_REGS
|
|
};
|
|
|
|
enum testunit_flags {
|
|
TU_FLAG_IN_PROCESS,
|
|
};
|
|
|
|
struct testunit_data {
|
|
unsigned long flags;
|
|
u8 regs[TU_NUM_REGS];
|
|
u8 reg_idx;
|
|
struct i2c_client *client;
|
|
struct delayed_work worker;
|
|
};
|
|
|
|
static void i2c_slave_testunit_work(struct work_struct *work)
|
|
{
|
|
struct testunit_data *tu = container_of(work, struct testunit_data, worker.work);
|
|
struct i2c_msg msg;
|
|
u8 msgbuf[256];
|
|
int ret = 0;
|
|
|
|
msg.addr = I2C_CLIENT_END;
|
|
msg.buf = msgbuf;
|
|
|
|
switch (tu->regs[TU_REG_CMD]) {
|
|
case TU_CMD_READ_BYTES:
|
|
msg.addr = tu->regs[TU_REG_DATAL];
|
|
msg.flags = I2C_M_RD;
|
|
msg.len = tu->regs[TU_REG_DATAH];
|
|
break;
|
|
|
|
case TU_CMD_HOST_NOTIFY:
|
|
msg.addr = 0x08;
|
|
msg.flags = 0;
|
|
msg.len = 3;
|
|
msgbuf[0] = tu->client->addr;
|
|
msgbuf[1] = tu->regs[TU_REG_DATAL];
|
|
msgbuf[2] = tu->regs[TU_REG_DATAH];
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
|
|
if (msg.addr != I2C_CLIENT_END) {
|
|
ret = i2c_transfer(tu->client->adapter, &msg, 1);
|
|
/* convert '0 msgs transferred' to errno */
|
|
ret = (ret == 0) ? -EIO : ret;
|
|
}
|
|
|
|
if (ret < 0)
|
|
dev_err(&tu->client->dev, "CMD%02X failed (%d)\n", tu->regs[TU_REG_CMD], ret);
|
|
|
|
clear_bit(TU_FLAG_IN_PROCESS, &tu->flags);
|
|
}
|
|
|
|
static int i2c_slave_testunit_slave_cb(struct i2c_client *client,
|
|
enum i2c_slave_event event, u8 *val)
|
|
{
|
|
struct testunit_data *tu = i2c_get_clientdata(client);
|
|
bool is_proc_call = tu->reg_idx == 3 && tu->regs[TU_REG_DATAL] == 1 &&
|
|
tu->regs[TU_REG_CMD] == TU_CMD_SMBUS_BLOCK_PROC_CALL;
|
|
int ret = 0;
|
|
|
|
switch (event) {
|
|
case I2C_SLAVE_WRITE_RECEIVED:
|
|
if (test_bit(TU_FLAG_IN_PROCESS, &tu->flags))
|
|
return -EBUSY;
|
|
|
|
if (tu->reg_idx < TU_NUM_REGS)
|
|
tu->regs[tu->reg_idx] = *val;
|
|
else
|
|
ret = -EMSGSIZE;
|
|
|
|
if (tu->reg_idx <= TU_NUM_REGS)
|
|
tu->reg_idx++;
|
|
|
|
/* TU_REG_CMD always written at this point */
|
|
if (tu->regs[TU_REG_CMD] >= TU_NUM_CMDS)
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
case I2C_SLAVE_STOP:
|
|
if (tu->reg_idx == TU_NUM_REGS) {
|
|
set_bit(TU_FLAG_IN_PROCESS, &tu->flags);
|
|
queue_delayed_work(system_long_wq, &tu->worker,
|
|
msecs_to_jiffies(10 * tu->regs[TU_REG_DELAY]));
|
|
}
|
|
|
|
/*
|
|
* Reset reg_idx to avoid that work gets queued again in case of
|
|
* STOP after a following read message. But do not clear TU regs
|
|
* here because we still need them in the workqueue!
|
|
*/
|
|
tu->reg_idx = 0;
|
|
break;
|
|
|
|
case I2C_SLAVE_WRITE_REQUESTED:
|
|
if (test_bit(TU_FLAG_IN_PROCESS, &tu->flags))
|
|
return -EBUSY;
|
|
|
|
memset(tu->regs, 0, TU_NUM_REGS);
|
|
tu->reg_idx = 0;
|
|
break;
|
|
|
|
case I2C_SLAVE_READ_PROCESSED:
|
|
if (is_proc_call && tu->regs[TU_REG_DATAH])
|
|
tu->regs[TU_REG_DATAH]--;
|
|
fallthrough;
|
|
|
|
case I2C_SLAVE_READ_REQUESTED:
|
|
*val = is_proc_call ? tu->regs[TU_REG_DATAH] : TU_CUR_VERSION;
|
|
break;
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
static int i2c_slave_testunit_probe(struct i2c_client *client)
|
|
{
|
|
struct testunit_data *tu;
|
|
|
|
tu = devm_kzalloc(&client->dev, sizeof(struct testunit_data), GFP_KERNEL);
|
|
if (!tu)
|
|
return -ENOMEM;
|
|
|
|
tu->client = client;
|
|
i2c_set_clientdata(client, tu);
|
|
INIT_DELAYED_WORK(&tu->worker, i2c_slave_testunit_work);
|
|
|
|
return i2c_slave_register(client, i2c_slave_testunit_slave_cb);
|
|
};
|
|
|
|
static void i2c_slave_testunit_remove(struct i2c_client *client)
|
|
{
|
|
struct testunit_data *tu = i2c_get_clientdata(client);
|
|
|
|
cancel_delayed_work_sync(&tu->worker);
|
|
i2c_slave_unregister(client);
|
|
}
|
|
|
|
static const struct i2c_device_id i2c_slave_testunit_id[] = {
|
|
{ "slave-testunit" },
|
|
{ }
|
|
};
|
|
MODULE_DEVICE_TABLE(i2c, i2c_slave_testunit_id);
|
|
|
|
static struct i2c_driver i2c_slave_testunit_driver = {
|
|
.driver = {
|
|
.name = "i2c-slave-testunit",
|
|
},
|
|
.probe = i2c_slave_testunit_probe,
|
|
.remove = i2c_slave_testunit_remove,
|
|
.id_table = i2c_slave_testunit_id,
|
|
};
|
|
module_i2c_driver(i2c_slave_testunit_driver);
|
|
|
|
MODULE_AUTHOR("Wolfram Sang <wsa@sang-engineering.com>");
|
|
MODULE_DESCRIPTION("I2C slave mode test unit");
|
|
MODULE_LICENSE("GPL v2");
|