|
| 1 | +From 4987202965423fafd5c704d4e68a51a4167a4414 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Oleksandr Shulzhenko < [email protected]> |
| 3 | +Date: Thu, 30 Sep 2021 16:28:26 +0200 |
| 4 | +Subject: [PATCH] Add sample i3c slave driver |
| 5 | + |
| 6 | +The aim of the driver is to debug various i3c solutions implemented |
| 7 | +for DesignWare master I3C driver. |
| 8 | +The driver is bound to the I3C device that corresponds to I3C slave |
| 9 | +emulated by Prodigy with manufacturer ID 0xAC and part ID 0x55AA. |
| 10 | +It is enough to fill the I3C_DEVICE macro with the corresponding data |
| 11 | +to adjust the driver with another I3C slave device |
| 12 | + |
| 13 | +Signed-off-by: Oleksandr Shulzhenko < [email protected]> |
| 14 | +--- |
| 15 | + drivers/i3c/Kconfig | 2 + |
| 16 | + drivers/i3c/Makefile | 1 + |
| 17 | + drivers/i3c/sample/Kconfig | 7 +++ |
| 18 | + drivers/i3c/sample/Makefile | 2 + |
| 19 | + drivers/i3c/sample/dw-i3c-sample.c | 75 ++++++++++++++++++++++++++++++ |
| 20 | + 5 files changed, 87 insertions(+) |
| 21 | + create mode 100644 drivers/i3c/sample/Kconfig |
| 22 | + create mode 100644 drivers/i3c/sample/Makefile |
| 23 | + create mode 100644 drivers/i3c/sample/dw-i3c-sample.c |
| 24 | + |
| 25 | +diff --git a/drivers/i3c/Kconfig b/drivers/i3c/Kconfig |
| 26 | +index 01642768ab5f..202b0d091631 100644 |
| 27 | +--- a/drivers/i3c/Kconfig |
| 28 | ++++ b/drivers/i3c/Kconfig |
| 29 | +@@ -36,4 +36,6 @@ config I3CDEV |
| 30 | + and hence SUBJECT TO CHANGE WITHOUT NOTICE while it stabilizes. |
| 31 | + |
| 32 | + source "drivers/i3c/master/Kconfig" |
| 33 | ++ |
| 34 | ++source "drivers/i3c/sample/Kconfig" |
| 35 | + endif # I3C |
| 36 | +diff --git a/drivers/i3c/Makefile b/drivers/i3c/Makefile |
| 37 | +index 606d422841b2..8048a9a793c6 100644 |
| 38 | +--- a/drivers/i3c/Makefile |
| 39 | ++++ b/drivers/i3c/Makefile |
| 40 | +@@ -3,3 +3,4 @@ i3c-y := device.o master.o |
| 41 | + obj-$(CONFIG_I3C) += i3c.o |
| 42 | + obj-$(CONFIG_I3CDEV) += i3cdev.o |
| 43 | + obj-$(CONFIG_I3C) += master/ |
| 44 | ++obj-$(CONFIG_I3C) += sample/ |
| 45 | +diff --git a/drivers/i3c/sample/Kconfig b/drivers/i3c/sample/Kconfig |
| 46 | +new file mode 100644 |
| 47 | +index 000000000000..6376c9891795 |
| 48 | +--- /dev/null |
| 49 | ++++ b/drivers/i3c/sample/Kconfig |
| 50 | +@@ -0,0 +1,7 @@ |
| 51 | ++# SPDX-License-Identifier: GPL-2.0-only |
| 52 | ++config DW_I3C_SAMPLE |
| 53 | ++ tristate "Synopsys DesignWare I3C sample driver" |
| 54 | ++ depends on I3C |
| 55 | ++help |
| 56 | ++ Say yes here to enable the driver for DesignWare |
| 57 | ++ I3C Sample driver. |
| 58 | +diff --git a/drivers/i3c/sample/Makefile b/drivers/i3c/sample/Makefile |
| 59 | +new file mode 100644 |
| 60 | +index 000000000000..c73bb34fce0e |
| 61 | +--- /dev/null |
| 62 | ++++ b/drivers/i3c/sample/Makefile |
| 63 | +@@ -0,0 +1,2 @@ |
| 64 | ++# SPDX-License-Identifier: GPL-2.0-only |
| 65 | ++obj-$(CONFIG_DW_I3C_SAMPLE) += dw-i3c-sample.o |
| 66 | +\ No newline at end of file |
| 67 | +diff --git a/drivers/i3c/sample/dw-i3c-sample.c b/drivers/i3c/sample/dw-i3c-sample.c |
| 68 | +new file mode 100644 |
| 69 | +index 000000000000..1993b9fdb32b |
| 70 | +--- /dev/null |
| 71 | ++++ b/drivers/i3c/sample/dw-i3c-sample.c |
| 72 | +@@ -0,0 +1,75 @@ |
| 73 | ++// SPDX-License-Identifier: GPL-2.0 |
| 74 | ++/* Copyright (C) 2021 Intel Corporation.*/ |
| 75 | ++ |
| 76 | ++#include <linux/i3c/device.h> |
| 77 | ++#include <linux/module.h> |
| 78 | ++ |
| 79 | ++#define IBI_QUEUE_STATUS_IBI_ID(x) (((x) & GENMASK(15, 8)) >> 8) |
| 80 | ++#define IBI_QUEUE_IBI_ADDR(x) (IBI_QUEUE_STATUS_IBI_ID(x) >> 1) |
| 81 | ++#define IBI_QUEUE_STATUS_DATA_LEN(x) ((x) & GENMASK(7, 0)) |
| 82 | ++ |
| 83 | ++static void ibi_handler(struct i3c_device *dev, |
| 84 | ++ const struct i3c_ibi_payload *payload) |
| 85 | ++{ |
| 86 | ++ unsigned int i = 0; |
| 87 | ++ u32 ibi_status; |
| 88 | ++ u8 addr; |
| 89 | ++ const u8 *buf; |
| 90 | ++ |
| 91 | ++ dev_info(i3cdev_to_dev(dev), "%s:%d\n", __func__, __LINE__); |
| 92 | ++ if (payload) { |
| 93 | ++ ibi_status = *((u32 *)payload->data); |
| 94 | ++ addr = IBI_QUEUE_IBI_ADDR(ibi_status); |
| 95 | ++ dev_info(i3cdev_to_dev(dev), "%s, dynamic address = 0x%02x\n", |
| 96 | ++ __func__, addr); |
| 97 | ++ /* We need to read only IBI Paylod data - so shift for IBI_QUEUE_STATUS |
| 98 | ++ * length which is 32 bits |
| 99 | ++ */ |
| 100 | ++ buf = payload->data + sizeof(u32); |
| 101 | ++ for (i = 0; i < IBI_QUEUE_STATUS_DATA_LEN(ibi_status); i++) |
| 102 | ++ dev_info(i3cdev_to_dev(dev), "%s payload[%d] = 0x%02x\n", |
| 103 | ++ __func__, i, *(buf + sizeof(u8) * i)); |
| 104 | ++ } |
| 105 | ++} |
| 106 | ++ |
| 107 | ++static int dw_i3c_sample_probe(struct i3c_device *i3cdev) |
| 108 | ++{ |
| 109 | ++ int ret; |
| 110 | ++ struct i3c_ibi_setup ibireq = { |
| 111 | ++ .handler = ibi_handler, |
| 112 | ++ .max_payload_len = 2, |
| 113 | ++ .num_slots = 10, |
| 114 | ++ }; |
| 115 | ++ |
| 116 | ++ ret = i3c_device_request_ibi(i3cdev, &ibireq); |
| 117 | ++ if (ret) |
| 118 | ++ return ret; |
| 119 | ++ ret = i3c_device_enable_ibi(i3cdev); |
| 120 | ++ if (ret) |
| 121 | ++ i3c_device_free_ibi(i3cdev); |
| 122 | ++ |
| 123 | ++ return ret; |
| 124 | ++} |
| 125 | ++ |
| 126 | ++static void dw_i3c_sample_remove(struct i3c_device *i3cdev) |
| 127 | ++{ |
| 128 | ++ i3c_device_disable_ibi(i3cdev); |
| 129 | ++ i3c_device_free_ibi(i3cdev); |
| 130 | ++} |
| 131 | ++ |
| 132 | ++static const struct i3c_device_id dw_i3c_sample_ids[] = { |
| 133 | ++ I3C_DEVICE(0x2AC /*manufid*/, 0x55AA /*partid*/, NULL /*driver-data*/), |
| 134 | ++ { /* sentinel */ }, |
| 135 | ++}; |
| 136 | ++ |
| 137 | ++static struct i3c_driver dw_i3c_sample = { |
| 138 | ++ .driver.name = "dw-i3c-sample", |
| 139 | ++ .id_table = dw_i3c_sample_ids, |
| 140 | ++ .probe = dw_i3c_sample_probe, |
| 141 | ++ .remove = dw_i3c_sample_remove, |
| 142 | ++}; |
| 143 | ++ |
| 144 | ++module_i3c_driver(dw_i3c_sample); |
| 145 | ++MODULE_AUTHOR("Oleksandr Shulzhenko <[email protected]>"); |
| 146 | ++MODULE_DESCRIPTION("DesignWare I3C sample driver"); |
| 147 | ++MODULE_LICENSE("GPL"); |
| 148 | +-- |
| 149 | +2.25.1 |
| 150 | + |
0 commit comments