From: Ye Xiang <xiang.ye@intel.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Arnd Bergmann <arnd@arndb.de>,
Matthias Kaehlcke <mka@chromium.org>, Lee Jones <lee@kernel.org>,
Wolfram Sang <wsa@kernel.org>, Tyrone Ting <kfting@nuvoton.com>,
Mark Brown <broonie@kernel.org>,
Linus Walleij <linus.walleij@linaro.org>,
Bartosz Golaszewski <brgl@bgdev.pl>,
linux-usb@vger.kernel.org, linux-i2c@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-spi@vger.kernel.org,
linux-gpio@vger.kernel.org
Cc: srinivas.pandruvada@intel.com, heikki.krogerus@linux.intel.com,
andriy.shevchenko@linux.intel.com, sakari.ailus@linux.intel.com,
zhifeng.wang@intel.com, wentong.wu@intel.com,
lixu.zhang@intel.com, Ye Xiang <xiang.ye@intel.com>
Subject: [PATCH v7 2/6] usb: ljca: Add transport interfaces for sub-module drivers
Date: Sat, 25 Mar 2023 23:47:07 +0800 [thread overview]
Message-ID: <20230325154711.2419569-3-xiang.ye@intel.com> (raw)
In-Reply-To: <20230325154711.2419569-1-xiang.ye@intel.com>
This patch adds the transport interfaces for various LJCA
sub-module drivers to communicate with LJCA hardware. The
sub-module of LJCA can use ljca_transfer() to issue a transfer
between host and hardware. And ljca_register_event_cb is exported
to LJCA sub-module drivers for hardware event subscription.
Signed-off-by: Ye Xiang <xiang.ye@intel.com>
---
drivers/usb/misc/usb-ljca.c | 61 +++++++++++++++++++++++++++++++++++++
include/linux/usb/ljca.h | 52 +++++++++++++++++++++++++++++++
2 files changed, 113 insertions(+)
diff --git a/drivers/usb/misc/usb-ljca.c b/drivers/usb/misc/usb-ljca.c
index 96e2b8c43c58..a5312869693a 100644
--- a/drivers/usb/misc/usb-ljca.c
+++ b/drivers/usb/misc/usb-ljca.c
@@ -365,6 +365,67 @@ static int ljca_stub_write(struct ljca_stub *stub, u8 cmd, const void *obuf, uns
return ret;
}
+static int ljca_transfer_internal(struct ljca *ljca, u8 cmd, const void *obuf,
+ unsigned int obuf_len, void *ibuf, unsigned int *ibuf_len,
+ bool wait_ack)
+{
+ struct ljca_stub *stub;
+
+ stub = ljca_stub_find(ljca->dev, ljca->type);
+ if (IS_ERR(stub))
+ return PTR_ERR(stub);
+
+ return ljca_stub_write(stub, cmd, obuf, obuf_len, ibuf, ibuf_len, wait_ack,
+ LJCA_USB_WRITE_ACK_TIMEOUT_MS);
+}
+
+int ljca_transfer(struct ljca *ljca, u8 cmd, const void *obuf, unsigned int obuf_len, void *ibuf,
+ unsigned int *ibuf_len)
+{
+ return ljca_transfer_internal(ljca, cmd, obuf, obuf_len, ibuf, ibuf_len, true);
+}
+EXPORT_SYMBOL_NS_GPL(ljca_transfer, LJCA);
+
+int ljca_transfer_noack(struct ljca *ljca, u8 cmd, const void *obuf, unsigned int obuf_len)
+{
+ return ljca_transfer_internal(ljca, cmd, obuf, obuf_len, NULL, NULL, false);
+}
+EXPORT_SYMBOL_NS_GPL(ljca_transfer_noack, LJCA);
+
+int ljca_register_event_cb(struct ljca *ljca, ljca_event_cb_t event_cb, void *context)
+{
+ struct ljca_stub *stub;
+ unsigned long flags;
+
+ stub = ljca_stub_find(ljca->dev, ljca->type);
+ if (IS_ERR(stub))
+ return PTR_ERR(stub);
+
+ spin_lock_irqsave(&stub->event_cb_lock, flags);
+ stub->event_entry.notify = event_cb;
+ stub->event_entry.context = context;
+ spin_unlock_irqrestore(&stub->event_cb_lock, flags);
+
+ return 0;
+}
+EXPORT_SYMBOL_NS_GPL(ljca_register_event_cb, LJCA);
+
+void ljca_unregister_event_cb(struct ljca *ljca)
+{
+ struct ljca_stub *stub;
+ unsigned long flags;
+
+ stub = ljca_stub_find(ljca->dev, ljca->type);
+ if (IS_ERR(stub))
+ return;
+
+ spin_lock_irqsave(&stub->event_cb_lock, flags);
+ stub->event_entry.notify = NULL;
+ stub->event_entry.context = NULL;
+ spin_unlock_irqrestore(&stub->event_cb_lock, flags);
+}
+EXPORT_SYMBOL_NS_GPL(ljca_unregister_event_cb, LJCA);
+
static void ljca_read_complete(struct urb *urb)
{
struct ljca_msg *header = urb->transfer_buffer;
diff --git a/include/linux/usb/ljca.h b/include/linux/usb/ljca.h
index 843d9f79865a..9ae3ea242294 100644
--- a/include/linux/usb/ljca.h
+++ b/include/linux/usb/ljca.h
@@ -40,4 +40,56 @@ struct ljca_spi_info {
*/
typedef void (*ljca_event_cb_t)(void *context, u8 cmd, const void *evt_data, int len);
+/**
+ * ljca_register_event_cb - register a callback function to receive events
+ *
+ * @ljca: ljca device handle
+ * @event_cb: callback function
+ * @context: execution context of event callback
+ *
+ * Return: 0 in case of success, negative value in case of error
+ */
+int ljca_register_event_cb(struct ljca *ljca, ljca_event_cb_t event_cb, void *context);
+
+/**
+ * ljca_unregister_event_cb - unregister the callback function for an event
+ *
+ * @ljca: ljca device handle
+ */
+void ljca_unregister_event_cb(struct ljca *ljca);
+
+/**
+ * ljca_transfer - issue a LJCA command and wait for a response and the
+ * associated data
+ *
+ * @ljca: ljca device handle
+ * @cmd: the command to be sent to the device
+ * @obuf: the buffer to be sent to the device; it can be NULL if the user
+ * doesn't need to transmit data with this command
+ * @obuf_len: the size of the buffer to be sent to the device; it should
+ * be 0 when obuf is NULL
+ * @ibuf: any data associated with the response will be copied here; it can be
+ * NULL if the user doesn't need the response data
+ * @ibuf_len: must be initialized to the input buffer size; it will be modified
+ * to indicate the actual data transferred; it shouldn't be NULL as well
+ * when ibuf isn't NULL
+ *
+ * Return: 0 for success, negative value for errors
+ */
+int ljca_transfer(struct ljca *ljca, u8 cmd, const void *obuf, unsigned int obuf_len,
+ void *ibuf, unsigned int *ibuf_len);
+
+/**
+ * ljca_transfer_noack - issue a LJCA command without a response
+ *
+ * @ljca: ljca device handle
+ * @cmd: the command to be sent to the device
+ * @obuf: the buffer to be sent to the device; it can be NULL if the user
+ * doesn't need to transmit data with this command
+ * @obuf_len: the size of the buffer to be sent to the device
+ *
+ * Return: 0 for success, negative value for errors
+ */
+int ljca_transfer_noack(struct ljca *ljca, u8 cmd, const void *obuf, unsigned int obuf_len);
+
#endif
--
2.34.1
next prev parent reply other threads:[~2023-03-25 15:48 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-25 15:47 [PATCH v7 0/6] Add Intel LJCA device driver Ye Xiang
2023-03-25 15:47 ` [PATCH v7 1/6] usb: Add support for Intel LJCA device Ye Xiang
2023-03-25 16:20 ` Greg Kroah-Hartman
2023-03-25 17:26 ` Ye, Xiang
2023-03-25 17:35 ` Greg Kroah-Hartman
2023-03-25 18:05 ` Mark Brown
2023-03-25 22:27 ` Greg Kroah-Hartman
2023-03-26 9:04 ` Ye, Xiang
2023-03-27 11:08 ` Oliver Neukum
2023-03-25 15:47 ` Ye Xiang [this message]
2023-03-25 15:47 ` [PATCH v7 3/6] Documentation: Add ABI doc for attributes of " Ye Xiang
2023-04-04 8:53 ` Oliver Neukum
2023-04-10 10:44 ` Ye, Xiang
2023-04-12 11:10 ` Oliver Neukum
2023-03-25 15:47 ` [PATCH v7 4/6] gpio: Add support for Intel LJCA USB GPIO driver Ye Xiang
2023-03-29 8:37 ` Linus Walleij
2023-03-25 15:47 ` [PATCH v7 5/6] i2c: Add support for Intel LJCA USB I2C driver Ye Xiang
2023-03-25 15:47 ` [PATCH v7 6/6] spi: Add support for Intel LJCA USB SPI driver Ye Xiang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230325154711.2419569-3-xiang.ye@intel.com \
--to=xiang.ye@intel.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=arnd@arndb.de \
--cc=brgl@bgdev.pl \
--cc=broonie@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=heikki.krogerus@linux.intel.com \
--cc=kfting@nuvoton.com \
--cc=lee@kernel.org \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-spi@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=lixu.zhang@intel.com \
--cc=mka@chromium.org \
--cc=sakari.ailus@linux.intel.com \
--cc=srinivas.pandruvada@intel.com \
--cc=wentong.wu@intel.com \
--cc=wsa@kernel.org \
--cc=zhifeng.wang@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).