[alsa-devel] [PATCH v3 0/8] slimbus: fixes and some helpers

Hi Greg,
Here is set of patches for slimbus, there are 6 fixes and two helper functions. Most of these issues were found while testing QCOM NGD SLIMBus controller with WCD9335 codec.
Changes since v2 (https://lkml.org/lkml/2018/5/17/251) - removed unnecessary changes in slim_prepare_txn patch
thanks, Srini
Srinivas Kandagatla (8): slimbus: core: rearrange slim_eaddr structure slimbus: core: add need_tid flag to slim_msg_txn slimbus: messaging: pass correct wbuf slimbus: messaging: remove multiple calls to pm_runtime_mark_last_busy slimbus: messaging: initialize completion correctly slimbus: qcom: remove redundant depends in Kconfig slimbus: messaging: add slim_prepare_txn() helper function slimbus: core: add of_slim_device_get() helper
drivers/slimbus/Kconfig | 1 - drivers/slimbus/core.c | 39 ++++++++++++++++++++ drivers/slimbus/messaging.c | 89 ++++++++++++++++++++++++++++++--------------- drivers/slimbus/slimbus.h | 4 ++ include/linux/slimbus.h | 14 ++++--- 5 files changed, 110 insertions(+), 37 deletions(-)

Rearrange struct slim_eaddr so that the structure is packed correctly to be able to send in SLIMBus messages.
Signed-off-by: Srinivas Kandagatla srinivas.kandagatla@linaro.org --- include/linux/slimbus.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/include/linux/slimbus.h b/include/linux/slimbus.h index c36cf121d2cd..90af9eb26615 100644 --- a/include/linux/slimbus.h +++ b/include/linux/slimbus.h @@ -14,16 +14,16 @@ extern struct bus_type slimbus_bus;
/** * struct slim_eaddr - Enumeration address for a SLIMbus device - * @manf_id: Manufacturer Id for the device - * @prod_code: Product code - * @dev_index: Device index * @instance: Instance value + * @dev_index: Device index + * @prod_code: Product code + * @manf_id: Manufacturer Id for the device */ struct slim_eaddr { - u16 manf_id; - u16 prod_code; - u8 dev_index; u8 instance; + u8 dev_index; + u16 prod_code; + u16 manf_id; } __packed;
/**

Add need_tid flag to txn, this flag can be set before start of transcation. Having this flag would avoid calling slim_tid_txn() multiple times on the same txn. Also it is handy for controller drivers too.
Signed-off-by: Srinivas Kandagatla srinivas.kandagatla@linaro.org --- drivers/slimbus/slimbus.h | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/drivers/slimbus/slimbus.h b/drivers/slimbus/slimbus.h index 79f8e05d92dd..3ec5a85fba8e 100644 --- a/drivers/slimbus/slimbus.h +++ b/drivers/slimbus/slimbus.h @@ -102,6 +102,7 @@ struct slim_framer { * @msg: Elemental access message to be read/written * @comp: completion if read/write is synchronous, used internally * for tid based transactions. + * @need_tid: flag indicating if a tid is required for this txn */ struct slim_msg_txn { u8 rl; @@ -113,6 +114,7 @@ struct slim_msg_txn { u8 la; struct slim_val_inf *msg; struct completion *comp; + bool need_tid; };
/* Frequently used message transaction structures */

There seems to be a typo while filling msg for slim_write, wbuf is set to NULL instead of rbuf.
Signed-off-by: Srinivas Kandagatla srinivas.kandagatla@linaro.org --- drivers/slimbus/messaging.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/slimbus/messaging.c b/drivers/slimbus/messaging.c index 457ea1f8db30..5a2ff01b394c 100644 --- a/drivers/slimbus/messaging.c +++ b/drivers/slimbus/messaging.c @@ -307,7 +307,7 @@ int slim_write(struct slim_device *sdev, u32 addr, size_t count, u8 *val) { struct slim_val_inf msg;
- slim_fill_msg(&msg, addr, count, val, NULL); + slim_fill_msg(&msg, addr, count, NULL, val);
return slim_xfer_msg(sdev, &msg, SLIM_MSG_MC_CHANGE_VALUE); }

There seems to be a multiple calls to pm_runtime_mark_last_busy(), which looks like a typo. Fix this by properly adding pm_runtime_put_autosuspend to put controller in auto suspend state.
Signed-off-by: Srinivas Kandagatla srinivas.kandagatla@linaro.org --- drivers/slimbus/messaging.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/slimbus/messaging.c b/drivers/slimbus/messaging.c index 5a2ff01b394c..1c57b631031a 100644 --- a/drivers/slimbus/messaging.c +++ b/drivers/slimbus/messaging.c @@ -139,7 +139,7 @@ int slim_do_transfer(struct slim_controller *ctrl, struct slim_msg_txn *txn) * if there was error during this transaction */ pm_runtime_mark_last_busy(ctrl->dev); - pm_runtime_mark_last_busy(ctrl->dev); + pm_runtime_put_autosuspend(ctrl->dev); } return ret; }

slim_val_inf can contain random value from stack, make sure the completion is initialized to NULL while filling the msg.
Signed-off-by: Srinivas Kandagatla srinivas.kandagatla@linaro.org --- drivers/slimbus/messaging.c | 1 + 1 file changed, 1 insertion(+)
diff --git a/drivers/slimbus/messaging.c b/drivers/slimbus/messaging.c index 1c57b631031a..e3605ed1c459 100644 --- a/drivers/slimbus/messaging.c +++ b/drivers/slimbus/messaging.c @@ -246,6 +246,7 @@ static void slim_fill_msg(struct slim_val_inf *msg, u32 addr, msg->num_bytes = count; msg->rbuf = rbuf; msg->wbuf = wbuf; + msg->comp = NULL; }
/**

QCOM SLIMBus controller is already under a 'if SLIMBUS' in Kconfig, having depends on SLIMBUS is totally redundant. Just remove it.
Signed-off-by: Srinivas Kandagatla srinivas.kandagatla@linaro.org --- drivers/slimbus/Kconfig | 1 - 1 file changed, 1 deletion(-)
diff --git a/drivers/slimbus/Kconfig b/drivers/slimbus/Kconfig index 1a632fad597e..bfb78d9a6583 100644 --- a/drivers/slimbus/Kconfig +++ b/drivers/slimbus/Kconfig @@ -15,7 +15,6 @@ if SLIMBUS # SLIMbus controllers config SLIM_QCOM_CTRL tristate "Qualcomm SLIMbus Manager Component" - depends on SLIMBUS depends on HAS_IOMEM help Select driver if Qualcomm's SLIMbus Manager Component is

This patch adds slim_prepare_txn() to allow controllers to prepare controller specific transaction. If not each controllers will duplicate the same code from core.
Signed-off-by: Srinivas Kandagatla srinivas.kandagatla@linaro.org --- drivers/slimbus/messaging.c | 84 ++++++++++++++++++++++++++++++--------------- drivers/slimbus/slimbus.h | 2 ++ 2 files changed, 58 insertions(+), 28 deletions(-)
diff --git a/drivers/slimbus/messaging.c b/drivers/slimbus/messaging.c index e3605ed1c459..cfffa1dece61 100644 --- a/drivers/slimbus/messaging.c +++ b/drivers/slimbus/messaging.c @@ -55,6 +55,46 @@ void slim_msg_response(struct slim_controller *ctrl, u8 *reply, u8 tid, u8 len) } EXPORT_SYMBOL_GPL(slim_msg_response);
+/** + * slim_prepare_txn() - Prepare a transaction + * + * @ctrl: Controller handle + * @txn: transaction to be prepared + * @done: completion for transaction if msg does not have completion + * @need_tid: flag to indicate if tid is required for this txn + * note, user defined commands would need tid. + * + * Called by controller to prepare a transaction + * + * Return: zero on success and error code on failures. + */ +int slim_prepare_txn(struct slim_controller *ctrl, struct slim_msg_txn *txn, + struct completion *done, bool need_tid) +{ + unsigned long flags; + int ret = 0; + + txn->need_tid = need_tid; + if (!need_tid) + return 0; + + spin_lock_irqsave(&ctrl->txn_lock, flags); + ret = idr_alloc(&ctrl->tid_idr, txn, 0, SLIM_MAX_TIDS, GFP_ATOMIC); + if (ret < 0) + goto err; + + txn->tid = ret; + if (!txn->msg->comp) + txn->comp = done; + else + txn->comp = txn->msg->comp; + +err: + spin_unlock_irqrestore(&ctrl->txn_lock, flags); + return ret; +} +EXPORT_SYMBOL_GPL(slim_prepare_txn); + /** * slim_do_transfer() - Process a SLIMbus-messaging transaction * @@ -70,10 +110,9 @@ EXPORT_SYMBOL_GPL(slim_msg_response); */ int slim_do_transfer(struct slim_controller *ctrl, struct slim_msg_txn *txn) { - DECLARE_COMPLETION_ONSTACK(done); - bool need_tid = false, clk_pause_msg = false; + bool clk_pause_msg = false; unsigned long flags; - int ret, tid, timeout; + int ret, timeout;
/* * do not vote for runtime-PM if the transactions are part of clock @@ -94,28 +133,8 @@ int slim_do_transfer(struct slim_controller *ctrl, struct slim_msg_txn *txn) } }
- need_tid = slim_tid_txn(txn->mt, txn->mc); - - if (need_tid) { - spin_lock_irqsave(&ctrl->txn_lock, flags); - tid = idr_alloc(&ctrl->tid_idr, txn, 0, - SLIM_MAX_TIDS, GFP_ATOMIC); - txn->tid = tid; - - if (!txn->msg->comp) - txn->comp = &done; - else - txn->comp = txn->comp; - - spin_unlock_irqrestore(&ctrl->txn_lock, flags); - - if (tid < 0) - return tid; - } - ret = ctrl->xfer_msg(ctrl, txn); - - if (ret && need_tid && !txn->msg->comp) { + if (!ret && txn->need_tid && !txn->msg->comp) { unsigned long ms = txn->rl + HZ;
timeout = wait_for_completion_timeout(txn->comp, @@ -123,7 +142,7 @@ int slim_do_transfer(struct slim_controller *ctrl, struct slim_msg_txn *txn) if (!timeout) { ret = -ETIMEDOUT; spin_lock_irqsave(&ctrl->txn_lock, flags); - idr_remove(&ctrl->tid_idr, tid); + idr_remove(&ctrl->tid_idr, txn->tid); spin_unlock_irqrestore(&ctrl->txn_lock, flags); } } @@ -133,13 +152,14 @@ int slim_do_transfer(struct slim_controller *ctrl, struct slim_msg_txn *txn) txn->mt, txn->mc, txn->la, ret);
slim_xfer_err: - if (!clk_pause_msg && (!need_tid || ret == -ETIMEDOUT)) { + if (!clk_pause_msg && (!txn->need_tid || ret == -ETIMEDOUT)) { /* * remove runtime-pm vote if this was TX only, or * if there was error during this transaction */ pm_runtime_mark_last_busy(ctrl->dev); pm_runtime_put_autosuspend(ctrl->dev); + } return ret; } @@ -205,6 +225,8 @@ int slim_xfer_msg(struct slim_device *sbdev, struct slim_val_inf *msg, DEFINE_SLIM_LDEST_TXN(txn_stack, mc, 6, sbdev->laddr, msg); struct slim_msg_txn *txn = &txn_stack; struct slim_controller *ctrl = sbdev->ctrl; + DECLARE_COMPLETION_ONSTACK(done); + bool need_tid = false; int ret; u16 sl;
@@ -232,10 +254,16 @@ int slim_xfer_msg(struct slim_device *sbdev, struct slim_val_inf *msg, break; }
- if (slim_tid_txn(txn->mt, txn->mc)) + if (slim_tid_txn(txn->mt, txn->mc)) { txn->rl++; + need_tid = true; + }
- return slim_do_transfer(ctrl, txn); + ret = slim_prepare_txn(ctrl, txn, &done, need_tid); + if (!ret) + return slim_do_transfer(ctrl, txn); + + return ret; } EXPORT_SYMBOL_GPL(slim_xfer_msg);
diff --git a/drivers/slimbus/slimbus.h b/drivers/slimbus/slimbus.h index 3ec5a85fba8e..8266e53535cb 100644 --- a/drivers/slimbus/slimbus.h +++ b/drivers/slimbus/slimbus.h @@ -242,6 +242,8 @@ int slim_unregister_controller(struct slim_controller *ctrl); void slim_msg_response(struct slim_controller *ctrl, u8 *reply, u8 tid, u8 l); int slim_do_transfer(struct slim_controller *ctrl, struct slim_msg_txn *txn); int slim_ctrl_clk_pause(struct slim_controller *ctrl, bool wakeup, u8 restart); +int slim_prepare_txn(struct slim_controller *ctrl, struct slim_msg_txn *txn, + struct completion *done, bool need_tid);
static inline bool slim_tid_txn(u8 mt, u8 mc) {

On SLIMBus controllers like Qcom NGD(non ported device), controller can request logical address once the remote side is powered, having a helper function like this to explicitly enumerate the bus is helpful. Also codec drivers which are taking to interface device would need such a helper too.
Signed-off-by: Srinivas Kandagatla srinivas.kandagatla@linaro.org --- drivers/slimbus/core.c | 39 +++++++++++++++++++++++++++++++++++++++ include/linux/slimbus.h | 2 ++ 2 files changed, 41 insertions(+)
diff --git a/drivers/slimbus/core.c b/drivers/slimbus/core.c index 7ddfc675b131..88248a4ecad9 100644 --- a/drivers/slimbus/core.c +++ b/drivers/slimbus/core.c @@ -356,6 +356,45 @@ struct slim_device *slim_get_device(struct slim_controller *ctrl, } EXPORT_SYMBOL_GPL(slim_get_device);
+static int of_slim_match_dev(struct device *dev, void *data) +{ + struct device_node *np = data; + struct slim_device *sbdev = to_slim_device(dev); + + return (sbdev->dev.of_node == np); +} + +static struct slim_device *of_find_slim_device(struct slim_controller *ctrl, + struct device_node *np) +{ + struct slim_device *sbdev; + struct device *dev; + + dev = device_find_child(ctrl->dev, np, of_slim_match_dev); + if (dev) { + sbdev = to_slim_device(dev); + return sbdev; + } + + return NULL; +} + +/** + * of_slim_get_device() - get handle to a device using dt node. + * + * @ctrl: Controller on which this device will be added/queried + * @np: node pointer to device + * + * Return: pointer to a device if it has already reported. Creates a new + * device and returns pointer to it if the device has not yet enumerated. + */ +struct slim_device *of_slim_get_device(struct slim_controller *ctrl, + struct device_node *np) +{ + return of_find_slim_device(ctrl, np); +} +EXPORT_SYMBOL_GPL(of_slim_get_device); + static int slim_device_alloc_laddr(struct slim_device *sbdev, bool report_present) { diff --git a/include/linux/slimbus.h b/include/linux/slimbus.h index 90af9eb26615..63801bcc5e60 100644 --- a/include/linux/slimbus.h +++ b/include/linux/slimbus.h @@ -138,6 +138,8 @@ static inline void slim_set_devicedata(struct slim_device *dev, void *data) dev_set_drvdata(&dev->dev, data); }
+struct slim_device *of_slim_get_device(struct slim_controller *ctrl, + struct device_node *np); struct slim_device *slim_get_device(struct slim_controller *ctrl, struct slim_eaddr *e_addr); int slim_get_logical_addr(struct slim_device *sbdev);
participants (1)
-
Srinivas Kandagatla