Skip to contentSkip to conversation

soundwire: Add a new SoundWire subsystem

PATCH Superseded Vinod Koul 5 participants 36 messages Nov 10, 2017 – Nov 27, 2017

Subsystems (5)

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Vinod Koul

author
#0 lore raw

v2 cover soundwire: Add a new SoundWire subsystem

This patch series adds a new SoundWire subsystem which implements a new MIPI bus protocol 'SoundWire'.

The SoundWire protocol is a robust, scalable, low complexity, low power, low latency, two-pin (clock and data) multi-drop bus that allows for the transfer of multiple audio streams and embedded control/commands. SoundWire provides synchronization capabilities and supports both PCM and PDM, multichannel data, isochronous and asynchronous modes.

This series adds SoundWire Bus, IO transfers, DisCo (Discovery and Configuration) sysfs interface, regmap and Documentation summary

This patch series is also available on
git://git.kernel.org/pub/scm/linux/kernel/git/vkoul/soundwire.git topic/patch_v2

v1: https://lkml.org/lkml/2017/10/18/1030
RFC: https://lkml.org/lkml/2016/10/21/395

Changes in v2:
- move documentation into driver-api and do rst conversion
- fix documentation comments
- add SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) to all source files
- rework the transfer logic and paging logic as commented on v1
- remove dummy sysfs fns
- registration checks and fixes
- remove slave check for regamp as that turned superfluous
- remove depends SoundWire symbol
- make modalias api arg const
- use bitmap for tracking assigned
- add counter for report present tracking
todo: add the dt-bindings

Sanyog Kale (4):
Documentation: Add SoundWire summary
soundwire: Add SoundWire MIPI defined registers
soundwire: Add Slave status handling helpers
soundwire: cdns: Add sdw_master_ops and IO transfer support

Vinod Koul (10):
soundwire: Add SoundWire bus type
soundwire: Add Master registration
soundwire: Add MIPI DisCo property helpers
soundwire: Add IO transfer
regmap: Add SoundWire bus support
soundwire: Add slave status handling
soundwire: Add sysfs for SoundWire DisCo properties
soundwire: cdns: Add cadence library
soundwire: intel: Add Intel Master driver
soundwire: intel: Add Intel init module

 Documentation/driver-api/index.rst             |    1 +
 Documentation/driver-api/soundwire/index.rst   |   15 +
 Documentation/driver-api/soundwire/summary.rst |  205 +++++
 drivers/Kconfig                                |    2 +
 drivers/Makefile                               |    1 +
 drivers/base/regmap/Kconfig                    |    4 +
 drivers/base/regmap/Makefile                   |    1 +
 drivers/base/regmap/regmap-sdw.c               |  140 ++++
 drivers/soundwire/Kconfig                      |   36 +
 drivers/soundwire/Makefile                     |   18 +
 drivers/soundwire/bus.c                        | 1013 ++++++++++++++++++++++++
 drivers/soundwire/bus.h                        |  126 +++
 drivers/soundwire/bus_type.c                   |  245 ++++++
 drivers/soundwire/cadence_master.c             |  791 ++++++++++++++++++
 drivers/soundwire/cadence_master.h             |   96 +++
 drivers/soundwire/intel.c                      |  391 +++++++++
 drivers/soundwire/intel.h                      |   72 ++
 drivers/soundwire/intel_init.c                 |  232 ++++++
 drivers/soundwire/mipi_disco.c                 |  422 ++++++++++
 drivers/soundwire/slave.c                      |  173 ++++
 drivers/soundwire/sysfs.c                      |  388 +++++++++
 include/linux/mod_devicetable.h                |    6 +
 include/linux/regmap.h                         |   37 +
 include/linux/soundwire/sdw.h                  |  563 +++++++++++++
 include/linux/soundwire/sdw_intel.h            |   74 ++
 include/linux/soundwire/sdw_registers.h        |  242 ++++++
 scripts/mod/devicetable-offsets.c              |    4 +
 scripts/mod/file2alias.c                       |   15 +
 28 files changed, 5313 insertions(+)
 create mode 100644 Documentation/driver-api/soundwire/index.rst
 create mode 100644 Documentation/driver-api/soundwire/summary.rst
 create mode 100644 drivers/base/regmap/regmap-sdw.c
 create mode 100644 drivers/soundwire/Kconfig
 create mode 100644 drivers/soundwire/Makefile
 create mode 100644 drivers/soundwire/bus.c
 create mode 100644 drivers/soundwire/bus.h
 create mode 100644 drivers/soundwire/bus_type.c
 create mode 100644 drivers/soundwire/cadence_master.c
 create mode 100644 drivers/soundwire/cadence_master.h
 create mode 100644 drivers/soundwire/intel.c
 create mode 100644 drivers/soundwire/intel.h
 create mode 100644 drivers/soundwire/intel_init.c
 create mode 100644 drivers/soundwire/mipi_disco.c
 create mode 100644 drivers/soundwire/slave.c
 create mode 100644 drivers/soundwire/sysfs.c
 create mode 100644 include/linux/soundwire/sdw.h
 create mode 100644 include/linux/soundwire/sdw_intel.h
 create mode 100644 include/linux/soundwire/sdw_registers.h
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH v2 1/14 Documentation: Add SoundWire summary

From: Sanyog Kale <[email protected]>

SoundWire is a new Linux bus which implements a new MIPI bus protocol 'SoundWire'. The summary of SoundWire bus and API is documented in the 'summary' file.

---
 Documentation/driver-api/index.rst             |   1 +
 Documentation/driver-api/soundwire/index.rst   |  15 ++
 Documentation/driver-api/soundwire/summary.rst | 205 +++++++++++++++++++++++++
 3 files changed, 221 insertions(+)
 create mode 100644 Documentation/driver-api/soundwire/index.rst
 create mode 100644 Documentation/driver-api/soundwire/summary.rst
Documentation/driver-api/index.rst +1 -0
index 9c20624842b7..bdd601cb38cb 100644
@@ -46,6 +46,7 @@ available subsections can be seen below.
    pinctl
    gpio
    misc_devices
+   soundwire/index
 
 .. only::  subproject and html
 
Documentation/driver-api/soundwire/index.rst new file +15 -0
new file mode 100644
index 000000000000..647e94654752
@@ -0,0 +1,15 @@
+=======================
+SoundWire Documentation
+=======================
+
+.. toctree::
+   :maxdepth: 1
+
+   summary
+
+.. only::  subproject
+
+   Indices
+   =======
+
+   * :ref:`genindex`
Documentation/driver-api/soundwire/summary.rst new file +205 -0

205 lines not on this page · raw message

Signature · 1 line
2.7.4
author
#2 lore raw

PATCH v2 2/14 soundwire: Add SoundWire bus type

In reply to Vinod Koul

This adds the base SoundWire bus type, bus and driver registration. along with changes to module device table for new SoundWire device type.

---
 drivers/Kconfig                   |   2 +
 drivers/Makefile                  |   1 +
 drivers/soundwire/Kconfig         |  21 ++++
 drivers/soundwire/Makefile        |   7 ++
 drivers/soundwire/bus.h           |  64 +++++++++++
 drivers/soundwire/bus_type.c      | 227 ++++++++++++++++++++++++++++++++++++++
 include/linux/mod_devicetable.h   |   6 +
 include/linux/soundwire/sdw.h     | 173 +++++++++++++++++++++++++++++
 scripts/mod/devicetable-offsets.c |   4 +
 scripts/mod/file2alias.c          |  15 +++
 10 files changed, 520 insertions(+)
 create mode 100644 drivers/soundwire/Kconfig
 create mode 100644 drivers/soundwire/Makefile
 create mode 100644 drivers/soundwire/bus.h
 create mode 100644 drivers/soundwire/bus_type.c
 create mode 100644 include/linux/soundwire/sdw.h
drivers/Kconfig +2 -0
index 505c676fa9c7..61b6e245c052 100644
@@ -152,6 +152,8 @@ source "drivers/remoteproc/Kconfig"
 
 source "drivers/rpmsg/Kconfig"
 
+source "drivers/soundwire/Kconfig"
+
 source "drivers/soc/Kconfig"
 
 source "drivers/devfreq/Kconfig"
drivers/Makefile +1 -0
index d90fdc413648..39c032f8abf3 100644
@@ -154,6 +154,7 @@ obj-$(CONFIG_MAILBOX)		+= mailbox/
 obj-$(CONFIG_HWSPINLOCK)	+= hwspinlock/
 obj-$(CONFIG_REMOTEPROC)	+= remoteproc/
 obj-$(CONFIG_RPMSG)		+= rpmsg/
+obj-$(CONFIG_SOUNDWIRE)		+= soundwire/
 
 # Virtualization drivers
 obj-$(CONFIG_VIRT_DRIVERS)	+= virt/
drivers/soundwire/Kconfig new file +21 -0
new file mode 100644
index 000000000000..71f19f45dc16
@@ -0,0 +1,21 @@
+#
+# SoundWire subsystem configuration
+#
+
+menuconfig SOUNDWIRE
+	bool "SoundWire support"
+	---help---
+	  SoundWire is a 2-Pin interface with data and clock line ratified
+	  by the MIPI Alliance. SoundWire is used for transporting data
+	  typically related to audio functions. SoundWire interface is
+	  optimized to integrate audio devices in mobile or mobile inspired
+	  systems
+
+if SOUNDWIRE
+
+comment "SoundWire Devices"
+
+config SOUNDWIRE_BUS
+	tristate
+
+endif
drivers/soundwire/Makefile new file +7 -0
new file mode 100644
index 000000000000..d1281def7662
@@ -0,0 +1,7 @@
+#
+# Makefile for soundwire core
+#
+
+#Bus Objs
+soundwire-bus-objs := bus_type.o
+obj-$(CONFIG_SOUNDWIRE_BUS) += soundwire-bus.o
drivers/soundwire/bus.h new file +64 -0

64 lines not on this page · raw message

drivers/soundwire/bus_type.c new file +227 -0

227 lines not on this page · raw message

include/linux/mod_devicetable.h +6 -0
index 694cebb50f72..316d11f2d264 100644
@@ -228,6 +228,12 @@ struct hda_device_id {
 	unsigned long driver_data;
 };
 
+struct sdw_device_id {
+	__u16 mfg_id;
+	__u16 part_id;
+	kernel_ulong_t driver_data;
+};
+
 /*
  * Struct used for matching a device
  */
include/linux/soundwire/sdw.h new file +173 -0

173 lines not on this page · raw message

scripts/mod/devicetable-offsets.c +4 -0
index e4d90e50f6fe..f23c08eb5c94 100644
@@ -202,6 +202,10 @@ int main(void)
 	DEVID_FIELD(hda_device_id, rev_id);
 	DEVID_FIELD(hda_device_id, api_version);
 
+	DEVID(sdw_device_id);
+	DEVID_FIELD(sdw_device_id, mfg_id);
+	DEVID_FIELD(sdw_device_id, part_id);
+
 	DEVID(fsl_mc_device_id);
 	DEVID_FIELD(fsl_mc_device_id, vendor);
 	DEVID_FIELD(fsl_mc_device_id, obj_type);
scripts/mod/file2alias.c +15 -0
index 29d6699d5a06..cad556fe22d3 100644
@@ -1289,6 +1289,21 @@ static int do_hda_entry(const char *filename, void *symval, char *alias)
 }
 ADD_TO_DEVTABLE("hdaudio", hda_device_id, do_hda_entry);
 
+/* Looks like: sdw:mNpN */
+static int do_sdw_entry(const char *filename, void *symval, char *alias)
+{
+	DEF_FIELD(symval, sdw_device_id, mfg_id);
+	DEF_FIELD(symval, sdw_device_id, part_id);
+
+	strcpy(alias, "sdw:");
+	ADD(alias, "m", mfg_id != 0, mfg_id);
+	ADD(alias, "p", part_id != 0, part_id);
+
+	add_wildcard(alias);
+	return 1;
+}
+ADD_TO_DEVTABLE("sdw", sdw_device_id, do_sdw_entry);
+
 /* Looks like: fsl-mc:vNdN */
 static int do_fsl_mc_entry(const char *filename, void *symval,
 			   char *alias)
Signature · 1 line
2.7.4
#3 lore raw

Re: [PATCH v2 02/14] soundwire: Add SoundWire bus type

drivers/soundwire/bus.h line 59

Quoted 12 lines · Vinod Koul

index 000000000000..9b3dca95a098

drivers/soundwire/bus.h new file +9 -0
+
+#ifndef __SDW_BUS_H
+#define __SDW_BUS_H
+
+#include <linux/init.h>
+#include <linux/device.h>
+#include <linux/module.h>
+#include <linux/mod_devicetable.h>
+#include <linux/acpi.h>

Do you need all these headers as part of this patch?

Quoted 11 lines
drivers/soundwire/bus.h new file +5 -0
+#include <linux/soundwire/sdw.h>
+
+int sdw_slave_modalias(const struct sdw_slave *slave, char *buf, size_t size);
+
+#endif /* __SDW_BUS_H */
drivers/soundwire/bus_type.c new file +0 -0
new file mode 100644
index 000000000000..3e97a8284871
@@ -0,0 +1,227 @@

...

drivers/soundwire/bus_type.c line 68

Quoted 2 lines
drivers/soundwire/bus_type.c new file +2 -0
+static const struct sdw_device_id *
+sdw_get_device_id(struct sdw_slave *slave, struct sdw_driver *drv)

Indentation looks Odd here,

Quoted 12 lines
drivers/soundwire/bus_type.c new file +12 -0
+{
+	const struct sdw_device_id *id = drv->id_table;
+
+	while (id && id->mfg_id) {
+		if (slave->id.mfg_id == id->mfg_id &&
+		    slave->id.part_id == id->part_id)
+			return id;
+		id++;
+	}
+
+	return NULL;
+}

...

Quoted 7 lines
drivers/soundwire/bus_type.c new file +7 -0
+
+static int sdw_drv_probe(struct device *dev)
+{
+	struct sdw_slave *slave = dev_to_sdw_dev(dev);
+	struct sdw_driver *drv = drv_to_sdw_driver(dev->driver);
+	const struct sdw_device_id *id;
+	int ret;

...

drivers/soundwire/bus_type.c line 133

Quoted 5 lines
drivers/soundwire/bus_type.c new file +5 -0
+	/*
+	 * attach to power domain but don't turn on (last arg)
+	 */
+	ret = dev_pm_domain_attach(dev, false);
+	if (ret) {

I think we discussed this in v1, but erring out here means that all the devices need to have pm domain attached, which might not be true all the time.

Quoted 16 lines
drivers/soundwire/bus_type.c new file +15 -0
+		dev_err(dev, "Failed to attach PM domain: %d\n", ret);
+		return ret;
+	}
+
+	ret = drv->probe(slave, id);
+	if (ret) {
+		dev_err(dev, "Probe of %s failed: %d\n", drv->name, ret);
+		dev_pm_domain_detach(dev, false);
+		return ret;
+	}
+
+	return 0;
+}
+
+

...

Quoted 24 lines
include/linux/soundwire/sdw.h +23 -0
+#ifndef __SOUNDWIRE_H
+#define __SOUNDWIRE_H
+
+#include <linux/device.h>
+#include <linux/mod_devicetable.h>
+
+struct sdw_bus;
+struct sdw_slave;
+
+#define SDW_MAX_DEVICES			11
+
+/**
+ * enum sdw_slave_status: Slave status
+ *
+ * @SDW_SLAVE_UNATTACHED: Slave is not attached with the bus.
+ * @SDW_SLAVE_ATTACHED: Slave is attached with bus.
+ * @SDW_SLAVE_ALERT: Some alert condition on the Slave
+ * @SDW_SLAVE_RESERVED: Reserved for future use
+ */
+enum sdw_slave_status {
+	SDW_SLAVE_UNATTACHED = 0,
+	SDW_SLAVE_ATTACHED = 1,
+	SDW_SLAVE_ALERT = 2,

include/linux/soundwire/sdw.h line 84

Quoted 10 lines
include/linux/soundwire/sdw.h +10 -0
+	SDW_SLAVE_RESERVED = 3,
+};
+
+/*
+ * SDW Slave Structures and APIs
+ */
+
+/**
+ * struct sdw_slave_id: Slave ID
+ *

Do we need an empty line Here?? same thing for all the kernel doc comments.

Also looking at examples in Documentation/doc-guide/kernel-doc.rst

struct should follow with - instead of :
same for functions..

author
#4 lore raw

Re: [PATCH v2 02/14] soundwire: Add SoundWire bus type

Quoted 17 lines · Srinivas Kandagatla

drivers/soundwire/bus.h line 59

Quoted 12 lines · Vinod Koul

index 000000000000..9b3dca95a098

drivers/soundwire/bus.h new file +9 -0
+
+#ifndef __SDW_BUS_H
+#define __SDW_BUS_H
+
+#include <linux/init.h>
+#include <linux/device.h>
+#include <linux/module.h>
+#include <linux/mod_devicetable.h>
+#include <linux/acpi.h>

Do you need all these headers as part of this patch?

I think so. One thing we need to keep in mind that bus is compiled on different archs where we may not have things availble explictly as they are on x86 or others. I think couple of them complained last time. I will check once more though..

Quoted 14 lines
Quoted 12 lines
drivers/soundwire/bus.h new file +5 -0
+#include <linux/soundwire/sdw.h>
+
+int sdw_slave_modalias(const struct sdw_slave *slave, char *buf, size_t size);
+
+#endif /* __SDW_BUS_H */
drivers/soundwire/bus_type.c new file +0 -0
new file mode 100644
index 000000000000..3e97a8284871
@@ -0,0 +1,227 @@

...

Quoted 3 lines

drivers/soundwire/bus_type.c line 68

Quoted 2 lines
drivers/soundwire/bus_type.c new file +2 -0
+static const struct sdw_device_id *
+sdw_get_device_id(struct sdw_slave *slave, struct sdw_driver *drv)

Indentation looks Odd here,

not really, the return type in preceding line is a perfect way to define things...

Quoted 7 lines
Quoted 6 lines
drivers/soundwire/bus_type.c new file +6 -0
+static int sdw_drv_probe(struct device *dev)
+{
+	struct sdw_slave *slave = dev_to_sdw_dev(dev);
+	struct sdw_driver *drv = drv_to_sdw_driver(dev->driver);
+	const struct sdw_device_id *id;
+	int ret;

...

Quoted 9 lines

drivers/soundwire/bus_type.c line 133

Quoted 5 lines
drivers/soundwire/bus_type.c new file +5 -0
+	/*
+	 * attach to power domain but don't turn on (last arg)
+	 */
+	ret = dev_pm_domain_attach(dev, false);
+	if (ret) {

I think we discussed this in v1, but erring out here means that all the devices need to have pm domain attached, which might not be true all the time.

oh yes, sorry i missed this one. will fix

Quoted 10 lines

drivers/soundwire/bus_type.c

Quoted 4 lines
drivers/soundwire/bus_type.c new file +4 -0
+
+/**
+ * struct sdw_slave_id: Slave ID
+ *

Do we need an empty line Here?? same thing for all the kernel doc comments.

Also looking at examples in Documentation/doc-guide/kernel-doc.rst

struct should follow with - instead of :
same for functions..

Kernel seems to have both. But yes - is more predominant by an order of magnitude and Documented so will fix it up.

Signature · 1 line
~Vinod
maintainer
#5 lore raw

Re: [PATCH v2 02/14] soundwire: Add SoundWire bus type

Quoted 8 lines · Vinod Koul
Quoted 3 lines · Srinivas Kandagatla

drivers/soundwire/bus_type.c line 68

Quoted 2 lines
drivers/soundwire/bus_type.c new file +2 -0
+static const struct sdw_device_id *
+sdw_get_device_id(struct sdw_slave *slave, struct sdw_driver *drv)

Indentation looks Odd here,

not really, the return type in preceding line is a perfect way to define things...

Yeah, that's fairly normal - just ugly long. You could also do it by splitting the arguments over two lines.

Quoted 8 lines
Quoted 6 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+	ret = dev_pm_domain_attach(dev, false);
+	if (ret) {

I think we discussed this in v1, but erring out here means that all the devices need to have pm domain attached, which might not be true all the time.

oh yes, sorry i missed this one. will fix

Looking at this pattern here I'm wondering if this should be folded into the domain code, everything attaching a domain is going to need to take care of this at the minute.

author
#6 lore raw

Re: [PATCH v2 02/14] soundwire: Add SoundWire bus type

Quoted 7 lines · Mark Brown
Quoted 5 lines · Vinod Koul
Quoted 3 lines · Srinivas Kandagatla

drivers/soundwire/bus_type.c line 68

Quoted 2 lines
drivers/soundwire/bus_type.c new file +2 -0
+static const struct sdw_device_id *
+sdw_get_device_id(struct sdw_slave *slave, struct sdw_driver *drv)

Indentation looks Odd here,

Quoted 5 lines
Quoted 2 lines

not really, the return type in preceding line is a perfect way to define things...

Yeah, that's fairly normal - just ugly long. You could also do it by splitting the arguments over two lines.

IMO that makes it look even worse :(

static const struct sdw_device_id *sdw_get_device_id(
struct sdw_slave *slave, struct sdw_driver *drv)

current one seemed lesser evil :)

Quoted 8 lines
Quoted 7 lines
Quoted 7 lines

Review

Quoted 3 lines
(quoted diff) +2 -0
+	ret = dev_pm_domain_attach(dev, false);
+	if (ret) {

I think we discussed this in v1, but erring out here means that all the devices need to have pm domain attached, which might not be true all the time.

Quoted 5 lines
Quoted 1 line

oh yes, sorry i missed this one. will fix

Looking at this pattern here I'm wondering if this should be folded into the domain code, everything attaching a domain is going to need to take care of this at the minute.

Yes, but then only busses call this, handful of users and some like platform core have bit different handling, so it may not work for them

Signature · 1 line
~Vinod
author
#7 lore raw

PATCH v2 3/14 soundwire: Add Master registration

In reply to Vinod Koul

A Master registers with SoundWire bus and scans the firmware provided for device description. In this patch we scan the ACPI namespaces and create the SoundWire Slave devices based on the ACPI description

---
 drivers/soundwire/Makefile    |   2 +-
 drivers/soundwire/bus.c       | 163 +++++++++++++++++++++++++++++++++++++++
 drivers/soundwire/bus.h       |  20 +++++
 drivers/soundwire/slave.c     | 172 ++++++++++++++++++++++++++++++++++++++++++
 include/linux/soundwire/sdw.h |  11 +++
 5 files changed, 367 insertions(+), 1 deletion(-)
 create mode 100644 drivers/soundwire/bus.c
 create mode 100644 drivers/soundwire/slave.c
drivers/soundwire/Makefile +1 -1
index d1281def7662..c875e434f8b3 100644
@@ -3,5 +3,5 @@
 #
 
 #Bus Objs
-soundwire-bus-objs := bus_type.o
+soundwire-bus-objs := bus_type.o bus.o slave.o
 obj-$(CONFIG_SOUNDWIRE_BUS) += soundwire-bus.o
drivers/soundwire/bus.c new file +163 -0

163 lines not on this page · raw message

drivers/soundwire/bus.h +20 -0
index 9b3dca95a098..7b764661c89d 100644
@@ -59,6 +59,26 @@
 #include <linux/acpi.h>
 #include <linux/soundwire/sdw.h>
 
+#if IS_ENABLED(CONFIG_ACPI)
+int sdw_acpi_find_slaves(struct sdw_bus *bus);
+#else
+static inline int sdw_acpi_find_slaves(struct sdw_bus *bus)
+{
+	return -ENOTSUPP;
+}
+#endif
+
+#if IS_ENABLED(CONFIG_OF)
+int sdw_of_find_slaves(struct sdw_bus *bus);
+#else
+static inline int sdw_of_find_slaves(struct sdw_bus *bus)
+{
+	return -ENOTSUPP;
+}
+#endif
+
 int sdw_slave_modalias(const struct sdw_slave *slave, char *buf, size_t size);
+void sdw_extract_slave_id(struct sdw_bus *bus,
+			unsigned long long addr, struct sdw_slave_id *id);
 
 #endif /* __SDW_BUS_H */
drivers/soundwire/slave.c new file +172 -0

172 lines not on this page · raw message

include/linux/soundwire/sdw.h +11 -0
index 1be63d5538fe..9070aec77576 100644
@@ -58,6 +58,14 @@
 struct sdw_bus;
 struct sdw_slave;
 
+/* SDW spec defines and enums, as defined by MIPI 1.1. Spec */
+
+/* SDW Broadcast Device Number */
+#define SDW_BROADCAST_DEV_NUM		15
+
+/* SDW Enumeration Device Number */
+#define SDW_ENUM_DEV_NUM		0
+
 #define SDW_MAX_DEVICES			11
 
 /**
@@ -170,4 +178,7 @@ struct sdw_bus {
 	struct mutex bus_lock;
 };
 
+int sdw_add_bus_master(struct sdw_bus *bus);
+void sdw_delete_bus_master(struct sdw_bus *bus);
+
 #endif /* __SOUNDWIRE_H */
Signature · 1 line
2.7.4
#8 lore raw

Re: [PATCH v2 03/14] soundwire: Add Master registration

Quoted 21 lines · Vinod Koul

A Master registers with SoundWire bus and scans the firmware provided for device description. In this patch we scan the ACPI namespaces and create the SoundWire Slave devices based on the ACPI description

---
  drivers/soundwire/Makefile    |   2 +-
  drivers/soundwire/bus.c       | 163 +++++++++++++++++++++++++++++++++++++++
  drivers/soundwire/bus.h       |  20 +++++
  drivers/soundwire/slave.c     | 172 ++++++++++++++++++++++++++++++++++++++++++
  include/linux/soundwire/sdw.h |  11 +++
  5 files changed, 367 insertions(+), 1 deletion(-)

create mode 100644 drivers/soundwire/bus.c
create mode 100644 drivers/soundwire/slave.c

drivers/soundwire/Makefile +0 -0
index d1281def7662..c875e434f8b3 100644

drivers/soundwire/Makefile

Quoted 10 lines
drivers/soundwire/Makefile +5 -1
@@ -3,5 +3,5 @@
  #
 
  #Bus Objs
-soundwire-bus-objs := bus_type.o
+soundwire-bus-objs := bus_type.o bus.o slave.o
 
+
+#include <linux/delay.h>
+#include <linux/device.h>
+#include <linux/pm_runtime.h>

Does this belong to this patch.

Quoted 20 lines
drivers/soundwire/Makefile +20 -0
+#include <linux/soundwire/sdw.h>
+#include "bus.h"
+
+/**
+ * sdw_add_bus_master: add a bus Master instance
+ *
+ * @bus: bus instance
+ *
+ * Initializes the bus instance, read properties and create child
+ * devices.
+ */
+int sdw_add_bus_master(struct sdw_bus *bus)
+{
+	int ret;
+
+	if (!bus->dev) {
+		pr_err("SoundWire bus has no device");
+		return -ENODEV;
+	}
+

drivers/soundwire/Makefile

Quoted 10 lines
drivers/soundwire/Makefile +10 -0
+	mutex_init(&bus->bus_lock);
+	INIT_LIST_HEAD(&bus->slaves);
+
+	/*
+	 * Enumeration device number and broadcast device number are
+	 * not used for assignment so mask these and other higher bits
+	 */
+
+	/* Set higher order bits */
+	*bus->assigned = ~GENMASK(SDW_BROADCAST_DEV_NUM, SDW_ENUM_DEV_NUM);

Can't we use ida for this.
This would also cut down code added for allocating dev_num.

Quoted 21 lines
drivers/soundwire/Makefile +20 -0
+
+	/* Set device number and broadcast device number */
+	set_bit(SDW_ENUM_DEV_NUM, bus->assigned);
+	set_bit(SDW_BROADCAST_DEV_NUM, bus->assigned);
 
+	return 0;
+}
+EXPORT_SYMBOL(sdw_add_bus_master);
+
+static int sdw_delete_slave(struct device *dev, void *data)
+{
+	struct sdw_slave *slave = dev_to_sdw_dev(dev);
+	struct sdw_bus *bus = slave->bus;
+
+	mutex_lock(&bus->bus_lock);
+
+	if (slave->dev_num) /* clear dev_num if assigned */
+		clear_bit(slave->dev_num, bus->assigned);
+
+	list_del_init(&slave->node);
+	mutex_unlock(&bus->bus_lock);

drivers/soundwire/Makefile

Quoted 10 lines
drivers/soundwire/Makefile +10 -0
+
+	device_unregister(dev);
+	return 0;
+}
+
+void sdw_delete_bus_master(struct sdw_bus *bus)
+{
+	device_for_each_child(bus->dev, NULL, sdw_delete_slave);
+}
+EXPORT_SYMBOL(sdw_delete_bus_master);

No kerneldoc..??

Quoted 1 line

+

drivers/soundwire/slave.c +0 -0
Quoted 46 lines

new file mode 100644
index 000000000000..4bf2a6cf732c

drivers/soundwire/slave.c new file +41 -0
 
+
+#include <linux/acpi.h>
+#include <linux/init.h>
+#include <linux/soundwire/sdw.h>
+#include "bus.h"
+
+}
+
+static int sdw_slave_add(struct sdw_bus *bus,
+		struct sdw_slave_id *id, struct fwnode_handle *fwnode)
+{
+	struct sdw_slave *slave;
+	int ret;
+
+	slave = kzalloc(sizeof(*slave), GFP_KERNEL);
+	if (!slave)
+		return -ENOMEM;
+
+	/* Initialize data structure */
+	memcpy(&slave->id, id, sizeof(*id));
+	slave->dev.parent = bus->dev;
+	slave->dev.fwnode = fwnode;
+
+	/* name shall be sdw:link:mfg:part:class:unique */
+	dev_set_name(&slave->dev, "sdw:%x:%x:%x:%x:%x",
+			bus->link_id, id->mfg_id, id->part_id,
+			id->class_id, id->unique_id);
+
+	slave->dev.release = sdw_slave_release;
+	slave->dev.bus = &sdw_bus_type;
+	slave->bus = bus;
+	slave->status = SDW_SLAVE_UNATTACHED;
+	slave->dev_num = 0;
+
+	mutex_lock(&bus->bus_lock);
+	list_add_tail(&slave->node, &bus->slaves);
+	mutex_unlock(&bus->bus_lock);
+
+	ret = device_register(&slave->dev);
+	if (ret) {
+		dev_err(bus->dev, "Failed to add slave: ret %d\n", ret);

drivers/soundwire/slave.c

Quoted 10 lines
drivers/soundwire/slave.c new file +10 -0
+
+		/*
+		 * On err, don't free but drop ref as this will be freed
+		 * when release method is invoked.
+		 */
+		mutex_lock(&bus->bus_lock);
+		list_del(&slave->node);
+		mutex_unlock(&bus->bus_lock);
+		put_device(&slave->dev);
+		return ret;

remove this line and ..

drivers/soundwire/slave.c

Quoted 3 lines
drivers/soundwire/slave.c new file +3 -0
+	}
+
+	return 0;
	return ret;

drivers/soundwire/slave.c

Quoted 11 lines
drivers/soundwire/slave.c new file +10 -0
+
 
+#endif
+
+#if IS_ENABLED(CONFIG_OF)
+int sdw_of_find_slaves(struct sdw_bus *bus)
+{
+	/* placeholder now, fill on OF support */
+	return -ENOTSUPP;
+}
+#endif

We should probably remove this dummy function, and add this functionality later.

author
#9 lore raw

Re: [PATCH v2 03/14] soundwire: Add Master registration

Quoted 29 lines · Srinivas Kandagatla
Quoted 25 lines · Vinod Koul

A Master registers with SoundWire bus and scans the firmware provided for device description. In this patch we scan the ACPI namespaces and create the SoundWire Slave devices based on the ACPI description

---
 drivers/soundwire/Makefile    |   2 +-
 drivers/soundwire/bus.c       | 163 +++++++++++++++++++++++++++++++++++++++
 drivers/soundwire/bus.h       |  20 +++++
 drivers/soundwire/slave.c     | 172 ++++++++++++++++++++++++++++++++++++++++++
 include/linux/soundwire/sdw.h |  11 +++
 5 files changed, 367 insertions(+), 1 deletion(-)
 create mode 100644 drivers/soundwire/bus.c
 create mode 100644 drivers/soundwire/slave.c
drivers/soundwire/Makefile +1 -1
index d1281def7662..c875e434f8b3 100644
@@ -3,5 +3,5 @@
 #
 #Bus Objs
-soundwire-bus-objs := bus_type.o
+soundwire-bus-objs := bus_type.o bus.o slave.o
Quoted 5 lines

drivers/soundwire/Makefile

Quoted 4 lines
drivers/soundwire/Makefile +4 -0
+
+#include <linux/delay.h>
+#include <linux/device.h>
+#include <linux/pm_runtime.h>

Does this belong to this patch.

Not really, tahnks for spotting

Quoted 25 lines
Quoted 25 lines
drivers/soundwire/Makefile +24 -0
+#include <linux/soundwire/sdw.h>
+#include "bus.h"
+
+/**
+ * sdw_add_bus_master: add a bus Master instance
+ *
+ * @bus: bus instance
+ *
+ * Initializes the bus instance, read properties and create child
+ * devices.
+ */
+int sdw_add_bus_master(struct sdw_bus *bus)
+{
+	int ret;
+
+	if (!bus->dev) {
+		pr_err("SoundWire bus has no device");
+		return -ENODEV;
+	}
+
+	mutex_init(&bus->bus_lock);
+	INIT_LIST_HEAD(&bus->slaves);
+
+	/*
Quoted 8 lines

drivers/soundwire/Makefile

Quoted 6 lines
drivers/soundwire/Makefile +6 -0
+	 * Enumeration device number and broadcast device number are
+	 * not used for assignment so mask these and other higher bits
+	 */
+
+	/* Set higher order bits */
+	*bus->assigned = ~GENMASK(SDW_BROADCAST_DEV_NUM, SDW_ENUM_DEV_NUM);

Can't we use ida for this.
This would also cut down code added for allocating dev_num.

Device numbers in SoundWire are 0 thru 15 with 0 and 15 having special meaning so can'r be allocated. Bitmaps give me a nice way to ensure we dont use those by masking these and above 15... IDR uses bitmap with stuff on top which maynot be helpful here as I need a number 1 to 14. For a generic, give me a number IDRs are very useful.

Quoted 25 lines
Quoted 25 lines
drivers/soundwire/Makefile +23 -0
+
+	/* Set device number and broadcast device number */
+	set_bit(SDW_ENUM_DEV_NUM, bus->assigned);
+	set_bit(SDW_BROADCAST_DEV_NUM, bus->assigned);
 
+	return 0;
+}
+EXPORT_SYMBOL(sdw_add_bus_master);
+
+static int sdw_delete_slave(struct device *dev, void *data)
+{
+	struct sdw_slave *slave = dev_to_sdw_dev(dev);
+	struct sdw_bus *bus = slave->bus;
+
+	mutex_lock(&bus->bus_lock);
+
+	if (slave->dev_num) /* clear dev_num if assigned */
+		clear_bit(slave->dev_num, bus->assigned);
+
+	list_del_init(&slave->node);
+	mutex_unlock(&bus->bus_lock);
+
+	device_unregister(dev);
+	return 0;
Quoted 8 lines

drivers/soundwire/Makefile

Quoted 7 lines
drivers/soundwire/Makefile +7 -0
+}
+
+void sdw_delete_bus_master(struct sdw_bus *bus)
+{
+	device_for_each_child(bus->dev, NULL, sdw_delete_slave);
+}
+EXPORT_SYMBOL(sdw_delete_bus_master);

No kerneldoc..??

will add.

Quoted 61 lines
Quoted 2 lines

+

drivers/soundwire/slave.c +0 -0
Quoted 46 lines

new file mode 100644
index 000000000000..4bf2a6cf732c

drivers/soundwire/slave.c new file +41 -0
 
+
+#include <linux/acpi.h>
+#include <linux/init.h>
+#include <linux/soundwire/sdw.h>
+#include "bus.h"
+
+}
+
+static int sdw_slave_add(struct sdw_bus *bus,
+		struct sdw_slave_id *id, struct fwnode_handle *fwnode)
+{
+	struct sdw_slave *slave;
+	int ret;
+
+	slave = kzalloc(sizeof(*slave), GFP_KERNEL);
+	if (!slave)
+		return -ENOMEM;
+
+	/* Initialize data structure */
+	memcpy(&slave->id, id, sizeof(*id));
+	slave->dev.parent = bus->dev;
+	slave->dev.fwnode = fwnode;
+
+	/* name shall be sdw:link:mfg:part:class:unique */
+	dev_set_name(&slave->dev, "sdw:%x:%x:%x:%x:%x",
+			bus->link_id, id->mfg_id, id->part_id,
+			id->class_id, id->unique_id);
+
+	slave->dev.release = sdw_slave_release;
+	slave->dev.bus = &sdw_bus_type;
+	slave->bus = bus;
+	slave->status = SDW_SLAVE_UNATTACHED;
+	slave->dev_num = 0;
+
+	mutex_lock(&bus->bus_lock);
+	list_add_tail(&slave->node, &bus->slaves);
+	mutex_unlock(&bus->bus_lock);
+
+	ret = device_register(&slave->dev);
+	if (ret) {
+		dev_err(bus->dev, "Failed to add slave: ret %d\n", ret);

drivers/soundwire/slave.c

Quoted 10 lines
drivers/soundwire/slave.c new file +10 -0
+
+		/*
+		 * On err, don't free but drop ref as this will be freed
+		 * when release method is invoked.
+		 */
+		mutex_lock(&bus->bus_lock);
+		list_del(&slave->node);
+		mutex_unlock(&bus->bus_lock);
+		put_device(&slave->dev);
+		return ret;

remove this line and ..

Quoted 5 lines

drivers/soundwire/slave.c

Quoted 3 lines
drivers/soundwire/slave.c new file +3 -0
+	}
+
+	return 0;
	return ret;

better :)

Quoted 10 lines

drivers/soundwire/slave.c

Quoted 7 lines
drivers/soundwire/slave.c new file +7 -0
+#if IS_ENABLED(CONFIG_OF)
+int sdw_of_find_slaves(struct sdw_bus *bus)
+{
+	/* placeholder now, fill on OF support */
+	return -ENOTSUPP;
+}
+#endif

We should probably remove this dummy function, and add this functionality later.

this was kept for people to know how they may add DT support, but yes its better to remove.

Signature · 1 line
~Vinod
maintainer
#10 lore raw

Re: [PATCH v2 03/14] soundwire: Add Master registration

Quoted 7 lines · Vinod Koul
Quoted 4 lines · Srinivas Kandagatla

Review

Quoted 1 line
(quoted diff) +1 -0
+	*bus->assigned = ~GENMASK(SDW_BROADCAST_DEV_NUM, SDW_ENUM_DEV_NUM);

Can't we use ida for this.
This would also cut down code added for allocating dev_num.

Quoted 5 lines

Device numbers in SoundWire are 0 thru 15 with 0 and 15 having special meaning so can'r be allocated. Bitmaps give me a nice way to ensure we dont use those by masking these and above 15... IDR uses bitmap with stuff on top which maynot be helpful here as I need a number 1 to 14. For a generic, give me a number IDRs are very useful.

Perhaps we need some comments or something explaining the constraints here to stop people doing misguided cleanups?

author
#11 lore raw

Re: [alsa-devel] [PATCH v2 03/14] soundwire: Add Master registration

Quoted 8 lines · Mark Brown
Quoted 6 lines · Vinod Koul
Quoted 4 lines · Srinivas Kandagatla

Review

Quoted 1 line
(quoted diff) +1 -0
+	*bus->assigned = ~GENMASK(SDW_BROADCAST_DEV_NUM, SDW_ENUM_DEV_NUM);

Can't we use ida for this.
This would also cut down code added for allocating dev_num.

Quoted 8 lines
Quoted 5 lines

Device numbers in SoundWire are 0 thru 15 with 0 and 15 having special meaning so can'r be allocated. Bitmaps give me a nice way to ensure we dont use those by masking these and above 15... IDR uses bitmap with stuff on top which maynot be helpful here as I need a number 1 to 14. For a generic, give me a number IDRs are very useful.

Perhaps we need some comments or something explaining the constraints here to stop people doing misguided cleanups?

Sure, it is already explained at scattered places, will add this comment here as well.

Signature · 1 line
~Vinod
author
#12 lore raw

PATCH v2 4/14 soundwire: Add MIPI DisCo property helpers

In reply to Vinod Koul

MIPI Discovery And Configuration (DisCo) Specification for SoundWire specifies properties to be implemented for SoundWire Masters and Slaves. The DisCo spec doesn't mandate these properties. However, SDW bus cannot work without knowing these values.

The helper functions read the Master and Slave properties. Implementers of Master or Slave drivers can use any of the below three mechanisms:
a) Use these APIs here as .read_prop() callback for Master and Slave
b) Implement own methods and set those as .read_prop(), but invoke APIs in this file for generic read and override the values with platform specific data
c) Implement ones own methods which do not use anything provided here

---
 drivers/soundwire/Makefile     |   2 +-
 drivers/soundwire/bus.c        |   8 +
 drivers/soundwire/bus_type.c   |  18 ++
 drivers/soundwire/mipi_disco.c | 422 +++++++++++++++++++++++++++++++++++++++++
 include/linux/soundwire/sdw.h  | 284 +++++++++++++++++++++++++++
 5 files changed, 733 insertions(+), 1 deletion(-)
 create mode 100644 drivers/soundwire/mipi_disco.c
drivers/soundwire/Makefile +1 -1
index c875e434f8b3..bcde0d26524c 100644
@@ -3,5 +3,5 @@
 #
 
 #Bus Objs
-soundwire-bus-objs := bus_type.o bus.o slave.o
+soundwire-bus-objs := bus_type.o bus.o slave.o mipi_disco.o
 obj-$(CONFIG_SOUNDWIRE_BUS) += soundwire-bus.o
drivers/soundwire/bus.c +8 -0
index 5bb9d930f86a..6cf4e5a7faea 100644
@@ -75,6 +75,14 @@ int sdw_add_bus_master(struct sdw_bus *bus)
 	mutex_init(&bus->bus_lock);
 	INIT_LIST_HEAD(&bus->slaves);
 
+	if (bus->ops->read_prop) {
+		ret = bus->ops->read_prop(bus);
+		if (ret < 0) {
+			dev_err(bus->dev, "Bus read properties failed:%d", ret);
+			return ret;
+		}
+	}
+
 	/*
 	 * Enumeration device number and broadcast device number are
 	 * not used for assignment so mask these and other higher bits
drivers/soundwire/bus_type.c +18 -0
index 3e97a8284871..520d31562544 100644
@@ -135,6 +135,8 @@ static int sdw_drv_probe(struct device *dev)
 		return ret;
 	}
 
+	slave->ops = drv->ops;
+
 	ret = drv->probe(slave, id);
 	if (ret) {
 		dev_err(dev, "Probe of %s failed: %d\n", drv->name, ret);
@@ -142,6 +144,22 @@ static int sdw_drv_probe(struct device *dev)
 		return ret;
 	}
 
+	/* device is probed so let's read the properties now */
+	if (slave->ops && slave->ops->read_prop)
+		slave->ops->read_prop(slave);
+
+	/*
+	 * Check for valid clk_stop_timeout, use DisCo worst case value of
+	 * 300ms
+	 *
+	 * TODO: check the timeouts and driver removal case
+	 */
+	if (slave->prop.clk_stop_timeout == 0)
+		slave->prop.clk_stop_timeout = 300;
+
+	slave->bus->clk_stop_timeout = max_t(u32, slave->bus->clk_stop_timeout,
+					slave->prop.clk_stop_timeout);
+
 	return 0;
 }
 
drivers/soundwire/mipi_disco.c new file +422 -0

422 lines not on this page · raw message

include/linux/soundwire/sdw.h +284 -0

328 lines not on this page · raw message

Signature · 1 line
2.7.4
#13 lore raw

Re: [PATCH v2 04/14] soundwire: Add MIPI DisCo property helpers

Few Minor comments!!

Quoted 18 lines · Vinod Koul
---
  drivers/soundwire/Makefile     |   2 +-
  drivers/soundwire/bus.c        |   8 +
  drivers/soundwire/bus_type.c   |  18 ++
  drivers/soundwire/mipi_disco.c | 422 +++++++++++++++++++++++++++++++++++++++++
  include/linux/soundwire/sdw.h  | 284 +++++++++++++++++++++++++++
  5 files changed, 733 insertions(+), 1 deletion(-)

create mode 100644 drivers/soundwire/mipi_disco.c

include/linux/soundwire/sdw.h +0 -0
index 9070aec77576..741b29d974fe 100644

include/linux/soundwire/sdw.h enum sdw_slave_status { · line 92

Quoted 9 lines
include/linux/soundwire/sdw.h +6 -0
@@ -84,6 +84,260 @@ enum sdw_slave_status {
  };
 
 
+/**
+ * enum sdw_clk_stop_mode: Clock Stop modes
+ *
+ * @SDW_CLK_STOP_MODE_0: Slave can continue operation seamlessly on clock
+ * restart
+ * @SDW_CLK_STOP_MODE_1: Slave may have entered a deeper power-saving mode,

Should be MODE0 and MODE1.. here

Quoted 6 lines
include/linux/soundwire/sdw.h +6 -0
+ * not capable of continuing operation seamlessly when the clock restarts
+ */
+enum sdw_clk_stop_mode {
+	SDW_CLK_STOP_MODE0 = 1,
+	SDW_CLK_STOP_MODE1 = 2,
+};

include/linux/soundwire/sdw.h enum sdw_slave_status { · line 169

Quoted 10 lines
include/linux/soundwire/sdw.h +9 -0
+
 
+/**
+ * struct sdw_dpn_audio_mode: Audio mode properties for DPn
+ *
+ * @bus_min_freq: Minimum bus frequency, in Hz
+ * @bus_max_freq: Maximum bus frequency, in Hz
+ * @bus_num_freq: Number of discrete frequencies supported
+ * @bus_freq: Discrete bus frequencies, in Hz
+ * @bus_min_freq: Minimum sampling frequency, in Hz

Should be min_freq

include/linux/soundwire/sdw.h enum sdw_slave_status { · line 170

Quoted 1 line
include/linux/soundwire/sdw.h +1 -0
+ * @bus_max_freq: Maximum sampling bus frequency, in Hz

Should be max_freq

include/linux/soundwire/sdw.h enum sdw_slave_status { · line 171

Quoted 1 line
include/linux/soundwire/sdw.h +1 -0
+ * @bus_num_freq: Number of discrete sampling frequency supported

Should be num_freq

include/linux/soundwire/sdw.h enum sdw_slave_status { · line 172

Quoted 1 line
include/linux/soundwire/sdw.h +1 -0
+ * @bus_freq: Discrete sampling frequencies, in Hz

Should be freq

Quoted 35 lines
include/linux/soundwire/sdw.h +34 -0
+ * @prep_ch_behave: Specifies the dependencies between Channel Prepare
+ * sequence and bus clock configuration
+ * If 0, Channel Prepare can happen at any Bus clock rate
+ * If 1, Channel Prepare sequence shall happen only after Bus clock is
+ * changed to a frequency supported by this mode or compatible modes
+ * described by the next field
+ * @glitchless: Bitmap describing possible glitchless transitions from this
+ * Audio Mode to other Audio Modes
+ */
+struct sdw_dpn_audio_mode {
+	u32 bus_min_freq;
+	u32 bus_max_freq;
+	u32 bus_num_freq;
+	u32 *bus_freq;
+	u32 max_freq;
+	u32 min_freq;
+	u32 num_freq;
+	u32 *freq;
+	u32 prep_ch_behave;
+	u32 glitchless;
+};
+
 
+/**
+ * struct sdw_slave_prop: SoundWire Slave properties
+ *
+ * @mipi_revision: Spec version of the implementation
+ * @wake_capable: Wake-up events are supported
+ * @test_mode_capable: If test mode is supported
+ * @clk_stop_mode1: Clock-Stop Mode 1 is supported
+ * @simple_clk_stop_capable: Simple clock mode is supported
+ * @clk_stop_timeout: Worst-case latency of the Clock Stop Prepare State
+ * Machine transitions, in milliseconds
+ * @ch_prep_timeout: Worst-case latency of the Channel Prepare State Machine
+ * transitions, in milliseconds

include/linux/soundwire/sdw.h enum sdw_slave_status { · line 271

Quoted 10 lines
include/linux/soundwire/sdw.h +10 -0
+ * @reset_behave: Slave keeps the status of the SlaveStopClockPrepare
+ * state machine (P=1 SCSP_SM) after exit from clock-stop mode1
+ * @high_PHY_capable: Slave is HighPHY capable
+ * @paging_support: Slave implements paging registers SCP_AddrPage1 and
+ * SCP_AddrPage2
+ * @bank_delay_support: Slave implements bank delay/bridge support registers
+ * SCP_BankDelay and SCP_NextFrame
+ * @p15_behave: Slave behavior when the Master attempts a read to the Port15
+ * alias
+ * @lane_control_support:

?? do description here..

Quoted 29 lines
include/linux/soundwire/sdw.h +29 -0
+ * @master_count: Number of Masters present on this Slave
+ * @source_ports: Bitmap identifying source ports
+ * @sink_ports: Bitmap identifying sink ports
+ * @dp0_prop: Data Port 0 properties
+ * @src_dpn_prop: Source Data Port N properties
+ * @sink_dpn_prop: Sink Data Port N properties
+ */
+struct sdw_slave_prop {
+	u32 mipi_revision;
+	bool wake_capable;
+	bool test_mode_capable;
+	bool clk_stop_mode1;
+	bool simple_clk_stop_capable;
+	u32 clk_stop_timeout;
+	u32 ch_prep_timeout;
+	enum sdw_clk_stop_reset_behave reset_behave;
+	bool high_PHY_capable;
+	bool paging_support;
+	bool bank_delay_support;
+	enum sdw_p15_behave p15_behave;
+	bool lane_control_support;
+	u32 master_count;
+	u32 source_ports;
+	u32 sink_ports;
+	struct sdw_dp0_prop *dp0_prop;
+	struct sdw_dpn_prop *src_dpn_prop;
+	struct sdw_dpn_prop *sink_dpn_prop;
+};
+
author
#14 lore raw

Re: [PATCH v2 04/14] soundwire: Add MIPI DisCo property helpers

Quoted 1 line · Srinivas Kandagatla

Few Minor comments!!

All are helpful :)

Quoted 7 lines
Quoted 6 lines

+/**
+ * enum sdw_clk_stop_mode: Clock Stop modes
+ *
+ * @SDW_CLK_STOP_MODE_0: Slave can continue operation seamlessly on clock
+ * restart
+ * @SDW_CLK_STOP_MODE_1: Slave may have entered a deeper power-saving mode,

Should be MODE0 and MODE1.. here

yes thanks for spotting

Quoted 8 lines
Quoted 8 lines

+/**
+ * struct sdw_dpn_audio_mode: Audio mode properties for DPn
+ *
+ * @bus_min_freq: Minimum bus frequency, in Hz
+ * @bus_max_freq: Maximum bus frequency, in Hz
+ * @bus_num_freq: Number of discrete frequencies supported
+ * @bus_freq: Discrete bus frequencies, in Hz
+ * @bus_min_freq: Minimum sampling frequency, in Hz

Quoted 8 lines

Should be min_freq

Quoted 1 line

+ * @bus_max_freq: Maximum sampling bus frequency, in Hz

Should be max_freq

Quoted 1 line

+ * @bus_num_freq: Number of discrete sampling frequency supported

Should be num_freq

Quoted 1 line

+ * @bus_freq: Discrete sampling frequencies, in Hz

Should be freq

yes, will fix

Quoted 5 lines
Quoted 3 lines

+ * @p15_behave: Slave behavior when the Master attempts a read to the Port15
+ * alias
+ * @lane_control_support:

?? do description here..

will add

Signature · 1 line
~Vinod
#15 lore raw

Re: [PATCH v2 04/14] soundwire: Add MIPI DisCo property helpers

In reply to Vinod Koul
Quoted 45 lines · Vinod Koul

MIPI Discovery And Configuration (DisCo) Specification for SoundWire specifies properties to be implemented for SoundWire Masters and Slaves. The DisCo spec doesn't mandate these properties. However, SDW bus cannot work without knowing these values.

The helper functions read the Master and Slave properties. Implementers of Master or Slave drivers can use any of the below three mechanisms:
a) Use these APIs here as .read_prop() callback for Master and Slave
b) Implement own methods and set those as .read_prop(), but invoke APIs in this file for generic read and override the values with platform specific data
c) Implement ones own methods which do not use anything provided here

---

 5 files changed, 733 insertions(+), 1 deletion(-)
 create mode 100644 drivers/soundwire/mipi_disco.c
drivers/soundwire/bus_type.c +11 -0
@@ -135,6 +135,8 @@ static int sdw_drv_probe(struct device *dev)
 		return ret;
 	}
 
+	slave->ops = drv->ops;
+
 	ret = drv->probe(slave, id);
 	if (ret) {
 		dev_err(dev, "Probe of %s failed: %d\n", drv->name, ret);
@@ -142,6 +144,22 @@ static int sdw_drv_probe(struct device *dev)
 		return ret;
 	}
 
+	/* device is probed so let's read the properties now */
+	if (slave->ops && slave->ops->read_prop)
+		slave->ops->read_prop(slave);
+
+	/*
+	 * Check for valid clk_stop_timeout, use DisCo worst case value of
+	 * 300ms
+	 *
+	 * TODO: check the timeouts and driver removal case

drivers/soundwire/bus_type.c static int sdw_drv_probe(struct device *dev) · line 165

Quoted 10 lines
drivers/soundwire/bus_type.c +7 -0
+	 */
+	if (slave->prop.clk_stop_timeout == 0)
+		slave->prop.clk_stop_timeout = 300;
+
+	slave->bus->clk_stop_timeout = max_t(u32, slave->bus->clk_stop_timeout,
+					slave->prop.clk_stop_timeout);
+
 	return 0;
 }
 

This brings up something I have been struggling with a little on both the soundwire and slimbus chains at the moment.

This happens after probe but if I am understanding right these properties might be required to communicate with the device. Which directly implies that probe shouldn't attempt to talk to the device? This is also implied in both series by the fact that probe will usually setup the things necessary for enumeration (power, clocks, etc). But it is fairly common in probe to at least do something like read some ID registers to check we are probing the right device.

On the slimbus side I guess you can get round this using the fact they have device_status callbacks to the driver so the driver can tell when the device is actually available, and could perform some actions when the device first becomes available on the bus. But this SoundWire chain doesn't have an equivalent.

Apologies for the long and slightly vague comment, but I guess my question is do you have a thought on how drivers should know when it is safe to communicate with a SoundWire device?

Thanks,
Charles

#16 lore raw

Re: [PATCH v2 04/14] soundwire: Add MIPI DisCo property helpers

Quoted 70 lines · Charles Keepax
Quoted 45 lines · Vinod Koul

MIPI Discovery And Configuration (DisCo) Specification for SoundWire specifies properties to be implemented for SoundWire Masters and Slaves. The DisCo spec doesn't mandate these properties. However, SDW bus cannot work without knowing these values.

The helper functions read the Master and Slave properties. Implementers of Master or Slave drivers can use any of the below three mechanisms:
a) Use these APIs here as .read_prop() callback for Master and Slave
b) Implement own methods and set those as .read_prop(), but invoke APIs in this file for generic read and override the values with platform specific data
c) Implement ones own methods which do not use anything provided here

---

 5 files changed, 733 insertions(+), 1 deletion(-)
 create mode 100644 drivers/soundwire/mipi_disco.c
drivers/soundwire/bus_type.c +11 -0
@@ -135,6 +135,8 @@ static int sdw_drv_probe(struct device *dev)
 		return ret;
 	}
 
+	slave->ops = drv->ops;
+
 	ret = drv->probe(slave, id);
 	if (ret) {
 		dev_err(dev, "Probe of %s failed: %d\n", drv->name, ret);
@@ -142,6 +144,22 @@ static int sdw_drv_probe(struct device *dev)
 		return ret;
 	}
 
+	/* device is probed so let's read the properties now */
+	if (slave->ops && slave->ops->read_prop)
+		slave->ops->read_prop(slave);
+
+	/*
+	 * Check for valid clk_stop_timeout, use DisCo worst case value of
+	 * 300ms
+	 *
+	 * TODO: check the timeouts and driver removal case

drivers/soundwire/bus_type.c static int sdw_drv_probe(struct device *dev) · line 165

Quoted 10 lines
drivers/soundwire/bus_type.c +7 -0
+	 */
+	if (slave->prop.clk_stop_timeout == 0)
+		slave->prop.clk_stop_timeout = 300;
+
+	slave->bus->clk_stop_timeout = max_t(u32, slave->bus->clk_stop_timeout,
+					slave->prop.clk_stop_timeout);
+
 	return 0;
 }
 

This brings up something I have been struggling with a little on both the soundwire and slimbus chains at the moment.

This happens after probe but if I am understanding right these properties might be required to communicate with the device. Which directly implies that probe shouldn't attempt to talk to the device? This is also implied in both series by the fact that probe will usually setup the things necessary for enumeration (power, clocks, etc). But it is fairly common in probe to at least do something like read some ID registers to check we are probing the right device.

Quoted 5 lines

On the slimbus side I guess you can get round this using the fact they have device_status callbacks to the driver so the driver can tell when the device is actually available, and could perform some actions when the device first becomes available on the bus. But this SoundWire chain doesn't have an equivalent.

We have similar device status callback (update_status) to report driver about Slave status change. Bus calls update_status when Slave reports status change (please check patch 09/14).

Quoted 3 lines

Apologies for the long and slightly vague comment, but I guess my question is do you have a thought on how drivers should know when it is safe to communicate with a SoundWire device?

IMO it is safe to communicate with SoundWire device when the Slave status is ATTACHED. In any case bus will report error if it is not able to communicate with SoundWire device.

Quoted 2 lines

Thanks,
Charles

#17 lore raw

Re: [PATCH v2 04/14] soundwire: Add MIPI DisCo property helpers

Quoted 22 lines · Sanyog Kale
Quoted 21 lines · Charles Keepax
Quoted 19 lines · Vinod Koul

MIPI Discovery And Configuration (DisCo) Specification for SoundWire specifies properties to be implemented for SoundWire Masters and Slaves. The DisCo spec doesn't mandate these properties. However, SDW bus cannot work without knowing these values.

The helper functions read the Master and Slave properties. Implementers of Master or Slave drivers can use any of the below three mechanisms:
a) Use these APIs here as .read_prop() callback for Master and Slave
b) Implement own methods and set those as .read_prop(), but invoke APIs in this file for generic read and override the values with platform specific data
c) Implement ones own methods which do not use anything provided here

---

Quoted 8 lines
Quoted 3 lines

Apologies for the long and slightly vague comment, but I guess my question is do you have a thought on how drivers should know when it is safe to communicate with a SoundWire device?

IMO it is safe to communicate with SoundWire device when the Slave status is ATTACHED. In any case bus will report error if it is not able to communicate with SoundWire device.

Yeah I guess my point here is that there is currently no way in this SoundWire framework for the slave driver to know if the device is attached or not, unless I am missing something? There are calls by which the master can inform the framework, but nothing to pass that on to the slave driver.

I would indeed imagine the comms would fail if the slave isn't attached but that doesn't seem like a particularly robust way of determining that.

Thanks,
Charles

author
#18 lore raw

Re: [PATCH v2 04/14] soundwire: Add MIPI DisCo property helpers

Quoted 8 lines · Charles Keepax
Quoted 7 lines
Quoted 3 lines

Apologies for the long and slightly vague comment, but I guess my question is do you have a thought on how drivers should know when it is safe to communicate with a SoundWire device?

IMO it is safe to communicate with SoundWire device when the Slave status is ATTACHED. In any case bus will report error if it is not able to communicate with SoundWire device.

Quoted 5 lines

Yeah I guess my point here is that there is currently no way in this SoundWire framework for the slave driver to know if the device is attached or not, unless I am missing something? There are calls by which the master can inform the framework, but nothing to pass that on to the slave driver.

Nope, as Sanyog pointed out there are deterministic ways for Slave driver to find out. We can do that by:
a) check the slave->status and communicate only if status is SDW_SLAVE_ATTACHED
b) Implement sdw_slave_ops->update_status() which is invoked by Bus on any status changes.

So to summarize, for a Slave driver during the probe, if the status is not SDW_SLAVE_ATTACHED it should not communicate and should implement sdw_slave_ops->update_status and attempt IO when this callback gets invoked with SDW_SLAVE_ATTACHED status.

Does that clarify and solve the problem.

Signature · 1 line
~Vinod
#19 lore raw

Re: [PATCH v2 04/14] soundwire: Add MIPI DisCo property helpers

Quoted 22 lines · Vinod Koul
Quoted 8 lines · Charles Keepax
Quoted 7 lines
Quoted 3 lines

Apologies for the long and slightly vague comment, but I guess my question is do you have a thought on how drivers should know when it is safe to communicate with a SoundWire device?

IMO it is safe to communicate with SoundWire device when the Slave status is ATTACHED. In any case bus will report error if it is not able to communicate with SoundWire device.

Quoted 5 lines

Yeah I guess my point here is that there is currently no way in this SoundWire framework for the slave driver to know if the device is attached or not, unless I am missing something? There are calls by which the master can inform the framework, but nothing to pass that on to the slave driver.

Nope, as Sanyog pointed out there are deterministic ways for Slave driver to find out. We can do that by:
a) check the slave->status and communicate only if status is SDW_SLAVE_ATTACHED
b) Implement sdw_slave_ops->update_status() which is invoked by Bus on any status changes.

Quoted 7 lines

So to summarize, for a Slave driver during the probe, if the status is not SDW_SLAVE_ATTACHED it should not communicate and should implement sdw_slave_ops->update_status and attempt IO when this callback gets invoked with SDW_SLAVE_ATTACHED status.

Does that clarify and solve the problem.

Ok apologies looks like this was my bad sorry for missing those. That does indeed seem fine.

Thanks,
Charles

author
#20 lore raw

Re: [alsa-devel] [PATCH v2 04/14] soundwire: Add MIPI DisCo property helpers

Quoted 23 lines · Charles Keepax
Quoted 22 lines · Vinod Koul
Quoted 8 lines · Charles Keepax
Quoted 7 lines
Quoted 3 lines

Apologies for the long and slightly vague comment, but I guess my question is do you have a thought on how drivers should know when it is safe to communicate with a SoundWire device?

IMO it is safe to communicate with SoundWire device when the Slave status is ATTACHED. In any case bus will report error if it is not able to communicate with SoundWire device.

Quoted 5 lines

Yeah I guess my point here is that there is currently no way in this SoundWire framework for the slave driver to know if the device is attached or not, unless I am missing something? There are calls by which the master can inform the framework, but nothing to pass that on to the slave driver.

Nope, as Sanyog pointed out there are deterministic ways for Slave driver to find out. We can do that by:
a) check the slave->status and communicate only if status is SDW_SLAVE_ATTACHED
b) Implement sdw_slave_ops->update_status() which is invoked by Bus on any status changes.

Quoted 8 lines
Quoted 6 lines

So to summarize, for a Slave driver during the probe, if the status is not SDW_SLAVE_ATTACHED it should not communicate and should implement sdw_slave_ops->update_status and attempt IO when this callback gets invoked with SDW_SLAVE_ATTACHED status.

Does that clarify and solve the problem.

Ok apologies looks like this was my bad sorry for missing those.

Ah no need for apologies Charles. The whole point of the patch review is to make sure everyone is on same page wrt understanding and that is the beauty of review over email where we can discuss and clarfiy :)

Quoted 1 line

That does indeed seem fine.

Great !!!

Signature · 1 line
~Vinod
author
#21 lore raw

PATCH v2 5/14 soundwire: Add SoundWire MIPI defined registers

In reply to Vinod Koul

From: Sanyog Kale <[email protected]>

MIPI SoundWire spec defines standard SoundWire registers mandatory for SoundWire Slave devices, so add them.

---
 include/linux/soundwire/sdw.h           |   1 +
 include/linux/soundwire/sdw_registers.h | 242 ++++++++++++++++++++++++++++++++
 2 files changed, 243 insertions(+)
 create mode 100644 include/linux/soundwire/sdw_registers.h
include/linux/soundwire/sdw.h +1 -0
index 741b29d974fe..7e6edb26ce4b 100644
@@ -54,6 +54,7 @@
 
 #include <linux/device.h>
 #include <linux/mod_devicetable.h>
+#include <linux/soundwire/sdw_registers.h>
 
 struct sdw_bus;
 struct sdw_slave;
include/linux/soundwire/sdw_registers.h new file +242 -0

242 lines not on this page · raw message

Signature · 1 line
2.7.4
author
#22 lore raw

PATCH v2 6/14 soundwire: Add IO transfer

In reply to Vinod Koul

SoundWire bus supports read or write register(s) for SoundWire Slave device. sdw_read() and sdw_write() APIs are provided for single register read/write. sdw_nread() and sdw_nwrite() for operations on contiguous registers.

---
 drivers/soundwire/bus.c       | 278 ++++++++++++++++++++++++++++++++++++++++++
 drivers/soundwire/bus.h       |  38 ++++++
 include/linux/soundwire/sdw.h |  59 +++++++++
 3 files changed, 375 insertions(+)
drivers/soundwire/bus.c +278 -0
index 6cf4e5a7faea..70b60ba84592 100644
@@ -72,6 +72,12 @@ int sdw_add_bus_master(struct sdw_bus *bus)
 		return -ENODEV;
 	}
 
+	if (!bus->ops) {
+		dev_err(bus->dev, "SoundWire Bus ops are not set");
+		return -EINVAL;
+	}
+
+	mutex_init(&bus->msg_lock);
 	mutex_init(&bus->bus_lock);
 	INIT_LIST_HEAD(&bus->slaves);
 
@@ -141,6 +147,278 @@ void sdw_delete_bus_master(struct sdw_bus *bus)
 }
 EXPORT_SYMBOL(sdw_delete_bus_master);
 
+/*
+ * SDW IO Calls
+ */
+
+static inline int find_response_code(enum sdw_command_response resp)
+{
+	switch (resp) {
+	case SDW_CMD_OK:
+		return 0;
+
+	case SDW_CMD_IGNORED:
+		return -ENODATA;
+
+	case SDW_CMD_TIMEOUT:
+		return -ETIMEDOUT;
+
+	default:
+		return -EIO;
+	}
+}
+
+static inline int do_transfer(struct sdw_bus *bus, struct sdw_msg *msg)
+{
+	int retry = bus->prop.err_threshold;
+	enum sdw_command_response resp;
+	int ret = 0, i;
+
+	for (i = 0; i <= retry; i++) {
+		resp = bus->ops->xfer_msg(bus, msg);
+		ret = find_response_code(resp);
+
+		/* if cmd is ok or ignored return */
+		if (ret == 0 || ret == -ENODATA)
+			return ret;
+	}
+
+	return ret;
+}
+
+static inline int do_transfer_defer(struct sdw_bus *bus,
+			struct sdw_msg *msg, struct sdw_defer *defer)
+{
+	int retry = bus->prop.err_threshold;
+	enum sdw_command_response resp;
+	int ret = 0, i;
+
+	defer->msg = msg;
+	defer->length = msg->len;
+
+	for (i = 0; i <= retry; i++) {
+		resp = bus->ops->xfer_msg_defer(bus, msg, defer);
+		ret = find_response_code(resp);
+		/* if cmd is ok or ignored return */
+		if (ret == 0 || ret == -ENODATA)
+			return ret;
+	}
+
+	return ret;
+}
+
+static int sdw_reset_page(struct sdw_bus *bus, u16 dev_num)
+{
+	int retry = bus->prop.err_threshold;
+	enum sdw_command_response resp;
+	int ret = 0, i;
+
+	for (i = 0; i <= retry; i++) {
+		resp = bus->ops->reset_page_addr(bus, dev_num);
+		ret = find_response_code(resp);
+		/* if cmd is ok or ignored return */
+		if (ret == 0 || ret == -ENODATA)
+			return ret;
+	}
+
+	return ret;
+}
+
+/**
+ * sdw_transfer: Synchronous transfer message to a SDW Slave device
+ *
+ * @bus: SDW bus
+ * @slave: SDW Slave
+ * @msg: SDW message to be xfered
+ */
+int sdw_transfer(struct sdw_bus *bus,
+		struct sdw_slave *slave, struct sdw_msg *msg)
+{
+	int ret;
+
+	mutex_lock(&bus->msg_lock);
+
+	ret = do_transfer(bus, msg);
+	if (ret != 0 && ret != -ENODATA)
+		dev_err(bus->dev, "trf on Slave %d failed:%d\n",
+				msg->dev_num, ret);
+
+	if (msg->page)
+		sdw_reset_page(bus, msg->dev_num);
+
+	mutex_unlock(&bus->msg_lock);
+
+	return ret;
+}
+
+/**
+ * sdw_transfer_defer: Asynchronously transfer message to a SDW Slave device
+ *
+ * @bus: SDW bus
+ * @slave: SDW Slave
+ * @msg: SDW message to be xfered
+ * @defer: Defer block for signal completion
+ *
+ * Caller needs to hold the msg_lock lock while calling this
+ */
+int sdw_transfer_defer(struct sdw_bus *bus, struct sdw_slave *slave,
+			struct sdw_msg *msg, struct sdw_defer *defer)
+{
+	int ret;
+
+	if (!bus->ops->xfer_msg_defer)
+		return -ENOTSUPP;
+
+	ret = do_transfer_defer(bus, msg, defer);
+	if (ret != 0 && ret != -ENODATA)
+		dev_err(bus->dev, "Defer trf on Slave %d failed:%d\n",
+				msg->dev_num, ret);
+
+	if (msg->page)
+		sdw_reset_page(bus, msg->dev_num);
+
+	return ret;
+}
+
+
+int sdw_fill_msg(struct sdw_msg *msg, struct sdw_slave *slave,
+		u32 addr, size_t count, u16 dev_num, u8 flags, u8 *buf)
+{
+	msg->addr = addr;
+	msg->len = count;
+	msg->dev_num = dev_num;
+	msg->flags = flags;
+	msg->buf = buf;
+	msg->ssp_sync = false;
+	msg->page = false;
+
+	if (addr < SDW_REG_NO_PAGE) { /* no paging area */
+		return 0;
+	} else if (addr >= SDW_REG_MAX) { /* illegal addr */
+		pr_err("SDW: Invalid address %x passed\n", addr);
+		return -EINVAL;
+	}
+
+	if (addr < SDW_REG_OPTIONAL_PAGE) { /* 32k but no page */
+		if (slave && !slave->prop.paging_support)
+			return 0;
+		/* no need for else as that will fall thru to paging */
+	}
+
+	/* paging madatory */
+	if (dev_num == SDW_ENUM_DEV_NUM || dev_num == SDW_BROADCAST_DEV_NUM) {
+		pr_err("SDW: Invalid device for paging :%d\n", dev_num);
+		return -EINVAL;
+	}
+
+	if (!slave) {
+		pr_err("SDW: No slave for paging addr\n");
+		return -EINVAL;
+	} else if (!slave->prop.paging_support) {
+		dev_err(&slave->dev,
+			"address %x needs paging but no support", addr);
+		return -EINVAL;
+	}
+
+	msg->addr_page1 = (addr >> SDW_REG_SHIFT(SDW_SCP_ADDRPAGE1_MASK));
+	msg->addr_page2 = (addr >> SDW_REG_SHIFT(SDW_SCP_ADDRPAGE2_MASK));
+	msg->addr |= BIT(15);
+	msg->page = true;
+
+	return 0;
+}
+
+/**
+ * sdw_nread: Read "n" contiguous SDW Slave registers
+ *
+ * @slave: SDW Slave
+ * @addr: Register address
+ * @count: length
+ * @val: Buffer for values to be read
+ */
+int sdw_nread(struct sdw_slave *slave, u32 addr, size_t count, u8 *val)
+{
+	struct sdw_msg msg;
+	int ret;
+
+	ret = sdw_fill_msg(&msg, slave, addr, count,
+			slave->dev_num, SDW_MSG_FLAG_READ, val);
+	if (ret < 0)
+		return ret;
+
+	ret = pm_runtime_get_sync(slave->bus->dev);
+	if (!ret)
+		return ret;
+
+	ret = sdw_transfer(slave->bus, slave, &msg);
+	pm_runtime_put(slave->bus->dev);
+
+	return ret;
+}
+EXPORT_SYMBOL(sdw_nread);
+
+/**
+ * sdw_nwrite: Write "n" contiguous SDW Slave registers
+ *
+ * @slave: SDW Slave
+ * @addr: Register address
+ * @count: length
+ * @val: Buffer for values to be read
+ */
+int sdw_nwrite(struct sdw_slave *slave, u32 addr, size_t count, u8 *val)
+{
+	struct sdw_msg msg;
+	int ret;
+
+	ret = sdw_fill_msg(&msg, slave, addr, count,
+			slave->dev_num, SDW_MSG_FLAG_WRITE, val);
+	if (ret < 0)
+		return ret;
+
+	ret = pm_runtime_get_sync(slave->bus->dev);
+	if (!ret)
+		return ret;
+
+	ret = sdw_transfer(slave->bus, slave, &msg);
+	pm_runtime_put(slave->bus->dev);
+
+	return ret;
+}
+EXPORT_SYMBOL(sdw_nwrite);
+
+/**
+ * sdw_read: Read a SDW Slave register
+ *
+ * @slave: SDW Slave
+ * @addr: Register address
+ */
+int sdw_read(struct sdw_slave *slave, u32 addr)
+{
+	u8 buf;
+	int ret;
+
+	ret = sdw_nread(slave, addr, 1, &buf);
+	if (ret < 0)
+		return ret;
+	else
+		return buf;
+}
+EXPORT_SYMBOL(sdw_read);
+
+/**
+ * sdw_write: Write a SDW Slave register
+ *
+ * @slave: SDW Slave
+ * @addr: Register address
+ * @value: Register value
+ */
+int sdw_write(struct sdw_slave *slave, u32 addr, u8 value)
+{
+	return sdw_nwrite(slave, addr, 1, &value);
+
+}
+EXPORT_SYMBOL(sdw_write);
+
 void sdw_extract_slave_id(struct sdw_bus *bus,
 			u64 addr, struct sdw_slave_id *id)
 {
drivers/soundwire/bus.h +38 -0
index 7b764661c89d..d6943b6ceeb6 100644
@@ -81,4 +81,42 @@ int sdw_slave_modalias(const struct sdw_slave *slave, char *buf, size_t size);
 void sdw_extract_slave_id(struct sdw_bus *bus,
 			unsigned long long addr, struct sdw_slave_id *id);
 
+enum {
+	SDW_MSG_FLAG_READ = 0,
+	SDW_MSG_FLAG_WRITE,
+};
+
+/**
+ * struct sdw_msg: Message structure
+ *
+ * @addr: Register address accessed in the Slave
+ * @len: number of messages
+ * @dev_num: Slave device number
+ * @addr_page1: SCP address page 1 Slave register
+ * @addr_page2: SCP address page 2 Slave register
+ * @flags: transfer flags, indicate if xfer is read or write
+ * @buf: message data buffer
+ * @ssp_sync: Send message at SSP (Stream Synchronization Point)
+ * @page: address requires paging
+ */
+struct sdw_msg {
+	u16 addr;
+	u16 len;
+	u16 dev_num;
+	u8 addr_page1;
+	u8 addr_page2;
+	u8 flags;
+	u8 *buf;
+	bool ssp_sync;
+	bool page;
+};
+
+int sdw_transfer(struct sdw_bus *bus, struct sdw_slave *slave,
+			struct sdw_msg *msg);
+int sdw_transfer_defer(struct sdw_bus *bus, struct sdw_slave *slave,
+			struct sdw_msg *msg, struct sdw_defer *defer);
+
+int sdw_fill_msg(struct sdw_msg *msg, struct sdw_slave *slave,
+		u32 addr, size_t count, u16 dev_num, u8 flags, u8 *buf);
+
 #endif /* __SDW_BUS_H */
include/linux/soundwire/sdw.h +59 -0

98 lines not on this page · raw message

Signature · 1 line
2.7.4
author
#23 lore raw

PATCH v2 7/14 regmap: Add SoundWire bus support

In reply to Vinod Koul

SoundWire bus provides sdw_read() and sdw_write() APIs for Slave devices to program the registers. Provide support in regmap for SoundWire bus.

---
 drivers/base/regmap/Kconfig      |   4 ++
 drivers/base/regmap/Makefile     |   1 +
 drivers/base/regmap/regmap-sdw.c | 140 +++++++++++++++++++++++++++++++++++++++
 drivers/soundwire/Kconfig        |   1 +
 include/linux/regmap.h           |  37 +++++++++++
 5 files changed, 183 insertions(+)
 create mode 100644 drivers/base/regmap/regmap-sdw.c
drivers/base/regmap/Kconfig +4 -0
index 073c0b77e5b3..d0310fbaa8e7 100644
@@ -36,3 +36,7 @@ config REGMAP_MMIO
 
 config REGMAP_IRQ
 	bool
+
+config REGMAP_SOUNDWIRE
+	tristate
+	depends on SOUNDWIRE_BUS
drivers/base/regmap/Makefile +1 -0
index 0cf4abc8fbf1..13004c979881 100644
@@ -12,3 +12,4 @@ obj-$(CONFIG_REGMAP_SPMI) += regmap-spmi.o
 obj-$(CONFIG_REGMAP_MMIO) += regmap-mmio.o
 obj-$(CONFIG_REGMAP_IRQ) += regmap-irq.o
 obj-$(CONFIG_REGMAP_W1) += regmap-w1.o
+obj-$(CONFIG_REGMAP_SOUNDWIRE) += regmap-sdw.o
drivers/base/regmap/regmap-sdw.c new file +140 -0

140 lines not on this page · raw message

drivers/soundwire/Kconfig +1 -0
index 71f19f45dc16..57bf769d9be7 100644
@@ -17,5 +17,6 @@ comment "SoundWire Devices"
 
 config SOUNDWIRE_BUS
 	tristate
+	select REGMAP_SOUNDWIRE
 
 endif
include/linux/regmap.h +37 -0
index 978abfbac617..d5eecf2e9697 100644
@@ -30,6 +30,7 @@ struct regmap;
 struct regmap_range_cfg;
 struct regmap_field;
 struct snd_ac97;
+struct sdw_slave;
 
 /* An enum of all the supported cache types */
 enum regcache_type {
@@ -474,6 +475,10 @@ struct regmap *__regmap_init_ac97(struct snd_ac97 *ac97,
 				  const struct regmap_config *config,
 				  struct lock_class_key *lock_key,
 				  const char *lock_name);
+struct regmap *__regmap_init_sdw(struct sdw_slave *sdw,
+				 const struct regmap_config *config,
+				 struct lock_class_key *lock_key,
+				 const char *lock_name);
 
 struct regmap *__devm_regmap_init(struct device *dev,
 				  const struct regmap_bus *bus,
@@ -511,6 +516,10 @@ struct regmap *__devm_regmap_init_ac97(struct snd_ac97 *ac97,
 				       const struct regmap_config *config,
 				       struct lock_class_key *lock_key,
 				       const char *lock_name);
+struct regmap *__devm_regmap_init_sdw(struct sdw_slave *sdw,
+				 const struct regmap_config *config,
+				 struct lock_class_key *lock_key,
+				 const char *lock_name);
 
 /*
  * Wrapper for regmap_init macros to include a unique lockdep key and name
@@ -660,6 +669,20 @@ int regmap_attach_dev(struct device *dev, struct regmap *map,
 bool regmap_ac97_default_volatile(struct device *dev, unsigned int reg);
 
 /**
+ * regmap_init_sdw(): Initialise register map
+ *
+ * @sdw: Device that will be interacted with
+ * @config: Configuration for register map
+ *
+ * The return value will be an ERR_PTR() on error or a valid pointer to
+ * a struct regmap.
+ */
+#define regmap_init_sdw(sdw, config)					\
+	__regmap_lockdep_wrapper(__regmap_init_sdw, #config,		\
+				sdw, config)
+
+
+/**
  * devm_regmap_init() - Initialise managed register map
  *
  * @dev: Device that will be interacted with
@@ -789,6 +812,20 @@ bool regmap_ac97_default_volatile(struct device *dev, unsigned int reg);
 	__regmap_lockdep_wrapper(__devm_regmap_init_ac97, #config,	\
 				ac97, config)
 
+/**
+ * devm_regmap_init_sdw(): Initialise managed register map
+ *
+ * @sdw: Device that will be interacted with
+ * @config: Configuration for register map
+ *
+ * The return value will be an ERR_PTR() on error or a valid pointer
+ * to a struct regmap.  The regmap will be automatically freed by the
+ * device management code.
+ */
+#define devm_regmap_init_sdw(sdw, config)				\
+	__regmap_lockdep_wrapper(__devm_regmap_init_sdw, #config,	\
+				sdw, config)
+
 void regmap_exit(struct regmap *map);
 int regmap_reinit_cache(struct regmap *map,
 			const struct regmap_config *config);
Signature · 1 line
2.7.4
maintainer
#24 lore raw

Re: [PATCH v2 07/14] regmap: Add SoundWire bus support

Quoted 1 line · Vinod Koul

+EXPORT_SYMBOL(__regmap_init_sdw);

We still have plain EXPORT_SYMBOL() on the regmap exports...

author
#25 lore raw

Re: [PATCH v2 07/14] regmap: Add SoundWire bus support

Quoted 5 lines · Mark Brown
Quoted 1 line · Vinod Koul

+EXPORT_SYMBOL(__regmap_init_sdw);

We still have plain EXPORT_SYMBOL() on the regmap exports...

Hi Mark,

I assumed after Alan's clarification that it is okay to do so. Let me know if you feel otherwise

Thanks

Signature · 1 line
~Vinod
maintainer
#26 lore raw

Re: [PATCH v2 07/14] regmap: Add SoundWire bus support

Quoted 9 lines · Vinod Koul
Quoted 5 lines · Mark Brown
Quoted 1 line · Vinod Koul

+EXPORT_SYMBOL(__regmap_init_sdw);

We still have plain EXPORT_SYMBOL() on the regmap exports...

I assumed after Alan's clarification that it is okay to do so. Let me know if you feel otherwise

No, I'm not which is why I replied to Alan's most recent mail explaining that I felt he was missing my point. For the bus code itself I don't really care either way, this is just about this one file.

To repeat this is a pretty thin layer of code tying regmap and Soundwire together, it's not as substantial as the bus code itself. The exports have no meaning outside of a kernel context and within that context it's hard to see a natural use case for doing this. It's much easier to see cases where someone causes themselves problems by reading too much into the use of plain EXPORT_SYMBOL(), perhaps not considering things as carefully as they might otherwise have done.

author
#27 lore raw

PATCH v2 8/14 soundwire: Add Slave status handling helpers

In reply to Vinod Koul

From: Sanyog Kale <[email protected]>

SoundWire Slaves report status to bus. Add helpers to handle the status changes.

---
 drivers/soundwire/bus.c       | 213 ++++++++++++++++++++++++++++++++++++++++++
 include/linux/soundwire/sdw.h |   1 +
 2 files changed, 214 insertions(+)
drivers/soundwire/bus.c +213 -0
index 70b60ba84592..16bc295634de 100644
@@ -419,6 +419,93 @@ int sdw_write(struct sdw_slave *slave, u32 addr, u8 value)
 }
 EXPORT_SYMBOL(sdw_write);
 
+/*
+ * SDW alert handling
+ */
+
+/* called with bus_lock held */
+static struct sdw_slave *sdw_get_slave(struct sdw_bus *bus, int i)
+{
+	struct sdw_slave *slave = NULL;
+
+	list_for_each_entry(slave, &bus->slaves, node) {
+		if (slave->dev_num == i)
+			break;
+	}
+
+	return slave;
+}
+
+static int sdw_compare_devid(struct sdw_slave *slave, struct sdw_slave_id id)
+{
+
+	if ((slave->id.unique_id != id.unique_id) ||
+	    (slave->id.mfg_id != id.mfg_id) ||
+	    (slave->id.part_id != id.part_id) ||
+	    (slave->id.class_id != id.class_id))
+		return -ENODEV;
+
+	return 0;
+}
+
+/* called with bus_lock held */
+static int sdw_get_device_num(struct sdw_slave *slave)
+{
+	int bit;
+
+	bit = find_first_zero_bit(slave->bus->assigned, SDW_MAX_DEVICES);
+	if (bit == SDW_MAX_DEVICES) {
+		bit = -ENODEV;
+		goto err;
+	}
+
+	/*
+	 * Do not update dev_num in Slave data structure here,
+	 * Update once program dev_num is successful
+	 */
+	set_bit(bit, slave->bus->assigned);
+
+err:
+	return bit;
+}
+
+static int sdw_assign_device_num(struct sdw_slave *slave)
+{
+	int ret, dev_num;
+
+	/* check first if device number is assigned, if so reuse that */
+	if (!slave->dev_num) {
+		mutex_lock(&slave->bus->bus_lock);
+		dev_num = sdw_get_device_num(slave);
+		mutex_unlock(&slave->bus->bus_lock);
+		if (dev_num < 0) {
+			dev_err(slave->bus->dev, "Get dev_num failed: %d",
+								dev_num);
+			return dev_num;
+		}
+	} else {
+		dev_info(slave->bus->dev,
+				"Slave already registered dev_num:%d",
+				slave->dev_num);
+
+		/* Clear the slave->dev_num to transfer message on device 0 */
+		dev_num = slave->dev_num;
+		slave->dev_num = 0;
+
+	}
+
+	ret = sdw_write(slave, SDW_SCP_DEVNUMBER, dev_num);
+	if (ret < 0) {
+		dev_err(&slave->dev, "Program device_num failed: %d", ret);
+		return ret;
+	}
+
+	/* After xfer of msg, restore dev_num */
+	slave->dev_num = dev_num;
+
+	return 0;
+}
+
 void sdw_extract_slave_id(struct sdw_bus *bus,
 			u64 addr, struct sdw_slave_id *id)
 {
@@ -447,3 +534,129 @@ void sdw_extract_slave_id(struct sdw_bus *bus,
 				id->unique_id, id->sdw_version);
 
 }
+
+static int sdw_program_device_num(struct sdw_bus *bus)
+{
+	u8 buf[SDW_NUM_DEV_ID_REGISTERS] = {0};
+	struct sdw_slave *slave, *_s;
+	struct sdw_slave_id id;
+	struct sdw_msg msg;
+	bool found = false;
+	int count = 0, ret;
+	u64 addr;
+
+	/* No Slave, so use raw xfer api */
+	ret = sdw_fill_msg(&msg, NULL, SDW_SCP_DEVID_0, SDW_NUM_DEV_ID_REGISTERS,
+					0, SDW_MSG_FLAG_READ, buf);
+	if (ret < 0)
+		return ret;
+
+	do {
+		ret = sdw_transfer(bus, NULL, &msg);
+		if (ret == -ENODATA)
+			break;
+		if (ret < 0) {
+			dev_err(bus->dev, "DEVID read fail:%d\n", ret);
+			break;
+		}
+
+		/*
+		 * Construct the addr and extract. Cast the higher shift
+		 * bits to avoid truncation due to size limit.
+		 */
+		addr = buf[5] | (buf[4] << 8) | (buf[3] << 16) |
+			(buf[2] << 24) | ((unsigned long long)buf[1] << 32) |
+			((unsigned long long)buf[0] << 40);
+
+		sdw_extract_slave_id(bus, addr, &id);
+
+		/* Now compare with entries */
+		list_for_each_entry_safe(slave, _s, &bus->slaves, node) {
+			if (sdw_compare_devid(slave, id) == 0) {
+				found = true;
+
+				/*
+				 * Assign a new dev_num to this Slave and
+				 * not mark it present. It will be marked
+				 * present after it reports ATTACHED on new
+				 * dev_num
+				 */
+				ret = sdw_assign_device_num(slave);
+				if (ret) {
+					dev_err(slave->bus->dev,
+						"Assign dev_num failed:%d",
+						ret);
+					return ret;
+				}
+
+				break;
+			}
+		}
+
+		if (found == false) {
+			/* TODO: Park this device in Group 13 */
+			dev_err(bus->dev, "Slave Entry not found");
+		}
+
+		count++;
+
+	} while (ret == 0 && count < (SDW_MAX_DEVICES * 2));
+
+	return ret;
+}
+
+static void sdw_modify_slave_status(struct sdw_slave *slave,
+				enum sdw_slave_status status)
+{
+	mutex_lock(&slave->bus->bus_lock);
+	slave->status = status;
+	mutex_unlock(&slave->bus->bus_lock);
+}
+
+static int sdw_initialize_slave(struct sdw_slave *slave)
+{
+	struct sdw_slave_prop *prop = &slave->prop;
+	int val, ret;
+
+	val = sdw_read(slave, SDW_SCP_INTMASK1);
+	if (val < 0) {
+		dev_err(slave->bus->dev,
+				"SDW_SCP_INTMASK1 read failed:%d", val);
+		return val;
+	}
+
+	/* Set bus clash and parity interrupt mask */
+	val |= SDW_SCP_INT1_BUS_CLASH | SDW_SCP_INT1_PARITY;
+
+	/* Enable SCP interrupts */
+	ret = sdw_write(slave, SDW_SCP_INTMASK1, val);
+	if (ret < 0) {
+		dev_err(slave->bus->dev,
+				"SDW_SCP_INTMASK1 write failed:%d", val);
+		return ret;
+	}
+
+	/* No need to continue if DP0 is not present */
+	if (!slave->prop.dp0_prop)
+		return 0;
+
+	/* Enable DP0 interrupts */
+	val = sdw_read(slave, SDW_DP0_INTMASK);
+	if (val < 0) {
+		dev_err(slave->bus->dev,
+				"SDW_DP0_INTMASK read failed:%d", val);
+		return val;
+	}
+
+	val |= prop->dp0_prop->device_interrupts;
+	val |= SDW_DP0_INT_PORT_READY | SDW_DP0_INT_BRA_FAILURE;
+
+	ret = sdw_write(slave, SDW_DP0_INTMASK, val);
+	if (ret < 0) {
+		dev_err(slave->bus->dev,
+				"SDW_DP0_INTMASK write failed:%d", val);
+		return ret;
+	}
+
+	return 0;
+}
include/linux/soundwire/sdw.h +1 -0
index f9a3e397afa6..71b69c17cc1b 100644
@@ -67,6 +67,7 @@ struct sdw_slave;
 /* SDW Enumeration Device Number */
 #define SDW_ENUM_DEV_NUM		0
 
+#define SDW_NUM_DEV_ID_REGISTERS	6
 #define SDW_MAX_DEVICES			11
 
 /**
Signature · 1 line
2.7.4
#28 lore raw

Re: [PATCH v2 08/14] soundwire: Add Slave status handling helpers

Minor Comment!

Quoted 15 lines · Vinod Koul

From: Sanyog Kale <[email protected]>

SoundWire Slaves report status to bus. Add helpers to handle the status changes.

---

drivers/soundwire/bus.c +5 -0
+static int sdw_compare_devid(struct sdw_slave *slave, struct sdw_slave_id id)
+{
+
+	if ((slave->id.unique_id != id.unique_id) ||
+	    (slave->id.mfg_id != id.mfg_id) ||

drivers/soundwire/bus.c int sdw_write(struct sdw_slave *slave, u32 addr, u8 value) · line 453

Quoted 10 lines
drivers/soundwire/bus.c +10 -0
+	    (slave->id.part_id != id.part_id) ||
+	    (slave->id.class_id != id.class_id))
+		return -ENODEV;
+
+	return 0;
+}
+
+/* called with bus_lock held */
+static int sdw_get_device_num(struct sdw_slave *slave)
+{

If we use ida we would not need this function.

Quoted 64 lines
drivers/soundwire/bus.c +56 -0
+	int bit;
+
+	bit = find_first_zero_bit(slave->bus->assigned, SDW_MAX_DEVICES);
+	if (bit == SDW_MAX_DEVICES) {
+		bit = -ENODEV;
+		goto err;
+	}
+
+	/*
+	 * Do not update dev_num in Slave data structure here,
+	 * Update once program dev_num is successful
+	 */
+	set_bit(bit, slave->bus->assigned);
+
+err:
+	return bit;
+}
+
+static int sdw_assign_device_num(struct sdw_slave *slave)
+{
+	int ret, dev_num;
+
+	/* check first if device number is assigned, if so reuse that */
+	if (!slave->dev_num) {
+		mutex_lock(&slave->bus->bus_lock);
+		dev_num = sdw_get_device_num(slave);
+		mutex_unlock(&slave->bus->bus_lock);
+		if (dev_num < 0) {
+			dev_err(slave->bus->dev, "Get dev_num failed: %d",
+								dev_num);
+			return dev_num;
+		}
+	} else {
+		dev_info(slave->bus->dev,
+				"Slave already registered dev_num:%d",
+				slave->dev_num);
+
+		/* Clear the slave->dev_num to transfer message on device 0 */
+		dev_num = slave->dev_num;
+		slave->dev_num = 0;
+
+	}
+
+	ret = sdw_write(slave, SDW_SCP_DEVNUMBER, dev_num);
+	if (ret < 0) {
+		dev_err(&slave->dev, "Program device_num failed: %d", ret);
+		return ret;
+	}
+
+	/* After xfer of msg, restore dev_num */
+	slave->dev_num = dev_num;
+
+	return 0;
+}
+
  void sdw_extract_slave_id(struct sdw_bus *bus,
  			u64 addr, struct sdw_slave_id *id)
  {
@@ -447,3 +534,129 @@ void sdw_extract_slave_id(struct sdw_bus *bus,
  				id->unique_id, id->sdw_version);
 
  }
+
author
#29 lore raw

Re: [PATCH v2 08/14] soundwire: Add Slave status handling helpers

Quoted 14 lines · Srinivas Kandagatla

Minor Comment!

Quoted 9 lines · Vinod Koul

From: Sanyog Kale <[email protected]>

SoundWire Slaves report status to bus. Add helpers to handle the status changes.

---

Quoted 16 lines
Quoted 5 lines
drivers/soundwire/bus.c +5 -0
+static int sdw_compare_devid(struct sdw_slave *slave, struct sdw_slave_id id)
+{
+
+	if ((slave->id.unique_id != id.unique_id) ||
+	    (slave->id.mfg_id != id.mfg_id) ||

drivers/soundwire/bus.c int sdw_write(struct sdw_slave *slave, u32 addr, u8 value) · line 453

Quoted 10 lines
drivers/soundwire/bus.c +10 -0
+	    (slave->id.part_id != id.part_id) ||
+	    (slave->id.class_id != id.class_id))
+		return -ENODEV;
+
+	return 0;
+}
+
+/* called with bus_lock held */
+static int sdw_get_device_num(struct sdw_slave *slave)
+{

If we use ida we would not need this function.

Not really, find_first_zero_bit and set_bit will be replaced by get_ida()

the bound check will still be required as we have finite set of ids to work with. Nevertheless I will check if it helps in this case and move if helpful.

Quoted 17 lines
Quoted 17 lines
drivers/soundwire/bus.c +17 -0
+	int bit;
+
+	bit = find_first_zero_bit(slave->bus->assigned, SDW_MAX_DEVICES);
+	if (bit == SDW_MAX_DEVICES) {
+		bit = -ENODEV;
+		goto err;
+	}
+
+	/*
+	 * Do not update dev_num in Slave data structure here,
+	 * Update once program dev_num is successful
+	 */
+	set_bit(bit, slave->bus->assigned);
+
+err:
+	return bit;
+}
Signature · 1 line
~Vinod
author
#30 lore raw

PATCH v2 9/14 soundwire: Add slave status handling

In reply to Vinod Koul

Add status handling API sdw_handle_slave_status() to handle Slave status changes.

---
 drivers/soundwire/bus.c       | 348 ++++++++++++++++++++++++++++++++++++++++++
 drivers/soundwire/bus.h       |   2 +
 include/linux/soundwire/sdw.h |  21 +++
 3 files changed, 371 insertions(+)
drivers/soundwire/bus.c +348 -0
index 16bc295634de..9199daafeffc 100644
@@ -660,3 +660,351 @@ static int sdw_initialize_slave(struct sdw_slave *slave)
 
 	return 0;
 }
+
+static int sdw_handle_dp0_interrupt(struct sdw_slave *slave, u8 *slave_status)
+{
+	u8 clear = 0, impl_int_mask;
+	int status, ret, count = 0;
+
+	status = sdw_read(slave, SDW_DP0_INT);
+	if (status < 0) {
+		dev_err(slave->bus->dev,
+				"SDW_DP0_INT read failed:%d", status);
+		return status;
+	}
+
+	do {
+
+		if (status & SDW_DP0_INT_TEST_FAIL) {
+			dev_err(&slave->dev, "Test fail for port 0");
+			clear |= SDW_DP0_INT_TEST_FAIL;
+		}
+
+		/*
+		 * Assumption: PORT_READY interrupt will be received only for
+		 * ports implementing Channel Prepare state machine (CP_SM)
+		 */
+
+		if (status & SDW_DP0_INT_PORT_READY) {
+			complete(&slave->port_ready[0]);
+			clear |= SDW_DP0_INT_PORT_READY;
+		}
+
+		if (status & SDW_DP0_INT_BRA_FAILURE) {
+			dev_err(&slave->dev, "BRA failed");
+			clear |= SDW_DP0_INT_BRA_FAILURE;
+		}
+
+		impl_int_mask = SDW_DP0_INT_IMPDEF1 |
+			SDW_DP0_INT_IMPDEF2 | SDW_DP0_INT_IMPDEF3;
+
+		if (status & impl_int_mask) {
+			clear |= impl_int_mask;
+			*slave_status = clear;
+		}
+
+		/* clear the interrupt */
+		ret = sdw_write(slave, SDW_DP0_INT, clear);
+		if (ret < 0) {
+			dev_err(slave->bus->dev,
+				"SDW_DP0_INT write failed:%d", ret);
+			return ret;
+		}
+
+		/* Read DP0 interrupt again */
+		status = sdw_read(slave, SDW_DP0_INT);
+		if (status < 0) {
+			dev_err(slave->bus->dev,
+				"SDW_DP0_INT read failed:%d", status);
+			return status;
+		}
+
+		count++;
+
+		/* we can get alerts while processing so keep retrying */
+	} while (status != 0 && count < SDW_READ_INTR_CLEAR_RETRY);
+
+	if (count == SDW_READ_INTR_CLEAR_RETRY)
+		dev_warn(slave->bus->dev, "Reached MAX_RETRY on DP0 read");
+
+	return ret;
+}
+
+static int sdw_handle_port_interrupt(struct sdw_slave *slave,
+		int port, u8 *slave_status)
+{
+	u8 clear = 0, impl_int_mask;
+	int status, ret, count = 0;
+	u32 addr;
+
+	if (port == 0)
+		return sdw_handle_dp0_interrupt(slave, slave_status);
+
+	addr = SDW_DPN_INT(port);
+	status = sdw_read(slave, addr);
+	if (status < 0) {
+		dev_err(slave->bus->dev,
+				"SDW_DPN_INT read failed:%d", status);
+
+		return status;
+	}
+
+	do {
+
+		if (status & SDW_DPN_INT_TEST_FAIL) {
+			dev_err(&slave->dev, "Test fail for port:%d", port);
+			clear |= SDW_DPN_INT_TEST_FAIL;
+		}
+
+		/*
+		 * Assumption: PORT_READY interrupt will be received only
+		 * for ports implementing CP_SM.
+		 */
+		if (status & SDW_DPN_INT_PORT_READY) {
+			complete(&slave->port_ready[port]);
+			clear |= SDW_DPN_INT_PORT_READY;
+		}
+
+		impl_int_mask = SDW_DPN_INT_IMPDEF1 |
+			SDW_DPN_INT_IMPDEF2 | SDW_DPN_INT_IMPDEF3;
+
+
+		if (status & impl_int_mask) {
+			clear |= impl_int_mask;
+			*slave_status = clear;
+		}
+
+		/* clear the interrupt */
+		ret = sdw_write(slave, addr, clear);
+		if (ret < 0) {
+			dev_err(slave->bus->dev,
+					"SDW_DPN_INT write failed:%d", ret);
+			return ret;
+		}
+
+		/* Read DPN interrupt again */
+		status = sdw_read(slave, addr);
+		if (status < 0) {
+			dev_err(slave->bus->dev,
+					"SDW_DPN_INT read failed:%d", status);
+			return status;
+		}
+
+		count++;
+
+		/* we can get alerts while processing so keep retrying */
+	} while (status != 0 && count < SDW_READ_INTR_CLEAR_RETRY);
+
+	if (count == SDW_READ_INTR_CLEAR_RETRY)
+		dev_warn(slave->bus->dev, "Reached MAX_RETRY on port read");
+
+	return ret;
+}
+
+static int sdw_handle_slave_alerts(struct sdw_slave *slave)
+{
+	u8 clear = 0, bit, port_status[15];
+	int port_num, stat, ret, count = 0;
+	unsigned long port;
+	bool slave_notify = false;
+	u8 buf[3];
+
+	sdw_modify_slave_status(slave, SDW_SLAVE_ALERT);
+
+	/* Read Instat 1, Instat 2 and Instat 3 registers */
+	ret = sdw_nread(slave, SDW_SCP_INT1, 3, buf);
+	if (ret < 0) {
+		dev_err(slave->bus->dev,
+					"SDW_SCP_INT1 read failed:%d", ret);
+		return ret;
+	}
+
+	do {
+		/*
+		 * Check parity, bus clash and Slave (impl defined)
+		 * interrupt
+		 */
+		if (buf[0] & SDW_SCP_INT1_PARITY) {
+			dev_err(&slave->dev, "Parity error detected");
+			clear |= SDW_SCP_INT1_PARITY;
+		}
+
+		if (buf[0] & SDW_SCP_INT1_BUS_CLASH) {
+			dev_err(&slave->dev, "Bus clash error detected");
+			clear |= SDW_SCP_INT1_BUS_CLASH;
+		}
+
+		/*
+		 * When bus clash or parity errors are detected, such errors
+		 * are unlikely to be recoverable errors.
+		 * TODO: In such scenario, reset bus. Make this configurable
+		 * via sysfs property with bus reset being the default.
+		 */
+
+		if (buf[0] & SDW_SCP_INT1_IMPL_DEF) {
+			dev_dbg(&slave->dev, "Slave impl defined interrupt\n");
+			clear |= SDW_SCP_INT1_IMPL_DEF;
+			slave_notify = true;
+		}
+
+		/* Check port 0 - 4 interrupts */
+		port = buf[0] & SDW_SCP_INT1_PORT0_3;
+
+		/* To get port number corresponding to bits, shift it */
+		port = port >> SDW_REG_SHIFT(SDW_SCP_INT1_PORT0_3);
+		for_each_set_bit(bit, &port, 8) {
+			sdw_handle_port_interrupt(slave, bit,
+						&port_status[bit]);
+
+		}
+
+		/* Check if cascade 2 interrupt is present */
+		if (buf[0] & SDW_SCP_INT1_SCP2_CASCADE) {
+			port = buf[1] & SDW_SCP_INTSTAT2_PORT4_10;
+			for_each_set_bit(bit, &port, 8) {
+				/* scp2 ports start from 4 */
+				port_num = bit + 3;
+				sdw_handle_port_interrupt(slave,
+						port_num,
+						&port_status[port_num]);
+			}
+		}
+
+		/* now check last cascade */
+		if (buf[1] & SDW_SCP_INTSTAT2_SCP3_CASCADE) {
+			port = buf[2] & SDW_SCP_INTSTAT3_PORT11_14;
+			for_each_set_bit(bit, &port, 8) {
+				/* scp3 ports start from 11 */
+				port_num = bit + 10;
+				sdw_handle_port_interrupt(slave,
+						port_num,
+						&port_status[port_num]);
+			}
+		}
+
+		/* Update the Slave driver */
+		if (slave_notify && (slave->ops) &&
+					(slave->ops->interrupt_callback)) {
+			struct sdw_slave_intr_status slave_intr;
+
+			slave_intr.control_port = clear;
+			memcpy(slave_intr.port, &port_status,
+						sizeof(slave_intr.port));
+
+			slave->ops->interrupt_callback(slave, &slave_intr);
+		}
+
+		/* Ack interrupt */
+		ret = sdw_write(slave, SDW_SCP_INT1, clear);
+		if (ret < 0) {
+			dev_err(slave->bus->dev,
+					"SDW_SCP_INT1 write failed:%d", ret);
+			return ret;
+		}
+
+		/*
+		 * Read status again to ensure no new interrupts arrived
+		 * while servicing interrupts
+		 */
+		ret = sdw_nread(slave, SDW_SCP_INT1, 3, buf);
+		if (ret < 0) {
+			dev_err(slave->bus->dev,
+					"SDW_SCP_INT1 read failed:%d", ret);
+			return ret;
+		}
+
+		/* Make sure no interrupts are pending */
+		stat = buf[0] || buf[1] || buf[2];
+
+		/*
+		 * Exit loop if Slave is continuously in ALERT state even
+		 * after servicing the interrupt multiple times.
+		 */
+		count++;
+
+		/* we can get alerts while processing so keep retrying */
+	} while (stat != 0 && count < SDW_READ_INTR_CLEAR_RETRY);
+
+	if (count == SDW_READ_INTR_CLEAR_RETRY)
+		dev_warn(slave->bus->dev, "Reached MAX_RETRY on alert read");
+
+	return ret;
+}
+
+static int sdw_update_slave_status(struct sdw_slave *slave,
+				enum sdw_slave_status status)
+{
+	if ((slave->ops) && (slave->ops->update_status))
+		return slave->ops->update_status(slave, status);
+
+	return 0;
+}
+
+/**
+ * sdw_handle_slave_status: Handle Slave status
+ *
+ * @bus: SDW bus instance
+ * @status: Status for all Slave(s)
+ */
+int sdw_handle_slave_status(struct sdw_bus *bus,
+			enum sdw_slave_status status[])
+{
+	struct sdw_slave *slave;
+	int i, ret = 0;
+
+	if (status[0] == SDW_SLAVE_ATTACHED) {
+		ret = sdw_program_device_num(bus);
+		if (ret)
+			dev_err(bus->dev, "Slave attach failed: %d", ret);
+	}
+
+	/* Continue to check other slave statuses */
+	for (i = 1; i <= SDW_MAX_DEVICES; i++) {
+		if (test_bit(i, bus->assigned) == true)
+			continue;
+
+		slave = sdw_get_slave(bus, i);
+		if (!slave)
+			continue;
+
+		switch (status[i]) {
+		case SDW_SLAVE_UNATTACHED:
+			if (slave->status == SDW_SLAVE_UNATTACHED)
+				break;
+
+			sdw_modify_slave_status(slave, SDW_SLAVE_UNATTACHED);
+			break;
+
+		case SDW_SLAVE_ALERT:
+			ret = sdw_handle_slave_alerts(slave);
+			if (ret)
+				dev_err(bus->dev,
+					"Slave %d alert handling failed: %d",
+					i, ret);
+			break;
+
+		case SDW_SLAVE_ATTACHED:
+			if (slave->status == SDW_SLAVE_ATTACHED)
+				break;
+
+			sdw_initialize_slave(slave);
+			sdw_modify_slave_status(slave, SDW_SLAVE_ATTACHED);
+
+			break;
+
+		default:
+			dev_err(bus->dev, "Invalid slave %d status:%d",
+							i, status[i]);
+			break;
+		}
+
+		ret = sdw_update_slave_status(slave, status[i]);
+		if (ret)
+			dev_err(slave->bus->dev,
+				"Update Slave status failed:%d", ret);
+
+	}
+
+	return ret;
+}
+EXPORT_SYMBOL(sdw_handle_slave_status);
drivers/soundwire/bus.h +2 -0
index d6943b6ceeb6..0b670ac3aae4 100644
@@ -111,6 +111,8 @@ struct sdw_msg {
 	bool page;
 };
 
+#define SDW_READ_INTR_CLEAR_RETRY	10
+
 int sdw_transfer(struct sdw_bus *bus, struct sdw_slave *slave,
 			struct sdw_msg *msg);
 int sdw_transfer_defer(struct sdw_bus *bus, struct sdw_slave *slave,
include/linux/soundwire/sdw.h +21 -0
index 71b69c17cc1b..9a42fa336184 100644
@@ -386,12 +386,30 @@ struct sdw_slave_id {
 };
 
 /**
+ * struct sdw_slave_intr_status: Slave interrupt status
+ *
+ * @control_port: control port status
+ * @port: data port status
+ */
+struct sdw_slave_intr_status {
+	u8 control_port;
+	u8 port[14];
+};
+
+/**
  * struct sdw_slave_ops: Slave driver callback ops
  *
  * @read_prop: Read Slave properties
+ * @interrupt_callback: Device interrupt notification (invoked in thread
+ * context)
+ * @update_status: Update Slave status
  */
 struct sdw_slave_ops {
 	int (*read_prop)(struct sdw_slave *sdw);
+	int (*interrupt_callback)(struct sdw_slave *slave,
+			struct sdw_slave_intr_status *status);
+	int (*update_status)(struct sdw_slave *slave,
+			enum sdw_slave_status status);
 };
 
 /**
@@ -449,6 +467,9 @@ struct sdw_driver {
 int __sdw_register_driver(struct sdw_driver *drv, struct module *);
 void sdw_unregister_driver(struct sdw_driver *drv);
 
+int sdw_handle_slave_status(struct sdw_bus *bus,
+			enum sdw_slave_status status[]);
+
 /*
  * SDW master structures and APIs
  */
Signature · 1 line
2.7.4
author
#31 lore raw

PATCH v2 10/14 soundwire: Add sysfs for SoundWire DisCo properties

In reply to Vinod Koul

It helps to read the properties for understanding and debugging systems, so add sysfs files for SoundWire DisCo properties.

TODO: Add ABI files for sysfs

---
 drivers/soundwire/Makefile    |   2 +-
 drivers/soundwire/bus.c       |   3 +
 drivers/soundwire/bus.h       |   2 +
 drivers/soundwire/slave.c     |   1 +
 drivers/soundwire/sysfs.c     | 388 ++++++++++++++++++++++++++++++++++++++++++
 include/linux/soundwire/sdw.h |  13 ++
 6 files changed, 408 insertions(+), 1 deletion(-)
 create mode 100644 drivers/soundwire/sysfs.c
drivers/soundwire/Makefile +1 -1
index bcde0d26524c..67dc7b546258 100644
@@ -3,5 +3,5 @@
 #
 
 #Bus Objs
-soundwire-bus-objs := bus_type.o bus.o slave.o mipi_disco.o
+soundwire-bus-objs := bus_type.o bus.o slave.o mipi_disco.o sysfs.o
 obj-$(CONFIG_SOUNDWIRE_BUS) += soundwire-bus.o
drivers/soundwire/bus.c +3 -0
index 9199daafeffc..3cc0bba85057 100644
@@ -89,6 +89,8 @@ int sdw_add_bus_master(struct sdw_bus *bus)
 		}
 	}
 
+	sdw_sysfs_bus_init(bus);
+
 	/*
 	 * Enumeration device number and broadcast device number are
 	 * not used for assignment so mask these and other higher bits
@@ -143,6 +145,7 @@ static int sdw_delete_slave(struct device *dev, void *data)
 
 void sdw_delete_bus_master(struct sdw_bus *bus)
 {
+	sdw_sysfs_bus_exit(bus);
 	device_for_each_child(bus->dev, NULL, sdw_delete_slave);
 }
 EXPORT_SYMBOL(sdw_delete_bus_master);
drivers/soundwire/bus.h +2 -0
index 0b670ac3aae4..a9a9bd2940ef 100644
@@ -81,6 +81,8 @@ int sdw_slave_modalias(const struct sdw_slave *slave, char *buf, size_t size);
 void sdw_extract_slave_id(struct sdw_bus *bus,
 			unsigned long long addr, struct sdw_slave_id *id);
 
+extern const struct attribute_group *sdw_slave_dev_attr_groups[];
+
 enum {
 	SDW_MSG_FLAG_READ = 0,
 	SDW_MSG_FLAG_WRITE,
drivers/soundwire/slave.c +1 -0
index 4bf2a6cf732c..63e234b5253e 100644
@@ -82,6 +82,7 @@ static int sdw_slave_add(struct sdw_bus *bus,
 			id->class_id, id->unique_id);
 
 	slave->dev.release = sdw_slave_release;
+	slave->dev.groups = sdw_slave_dev_attr_groups;
 	slave->dev.bus = &sdw_bus_type;
 	slave->bus = bus;
 	slave->status = SDW_SLAVE_UNATTACHED;
drivers/soundwire/sysfs.c new file +388 -0

388 lines not on this page · raw message

include/linux/soundwire/sdw.h +13 -0
index 9a42fa336184..f9058e604581 100644
@@ -362,6 +362,15 @@ int sdw_master_read_prop(struct sdw_bus *bus);
 int sdw_slave_read_prop(struct sdw_slave *slave);
 
 /*
+ * SDW sysfs APIs
+ */
+struct sdw_slave_sysfs;
+struct sdw_master_sysfs;
+
+int sdw_sysfs_bus_init(struct sdw_bus *bus);
+void sdw_sysfs_bus_exit(struct sdw_bus *bus);
+
+/*
  * SDW Slave Structures and APIs
  */
 
@@ -421,6 +430,7 @@ struct sdw_slave_ops {
  * @bus: Bus handle
  * @ops: Slave callback ops
  * @prop: Slave properties
+ * @sysfs: Sysfs interface
  * @node: node for bus list
  * @port_ready: Port ready completion flag for each Slave port
  * @dev_num: Device Number assigned by Bus
@@ -432,6 +442,7 @@ struct sdw_slave {
 	struct sdw_bus *bus;
 	const struct sdw_slave_ops *ops;
 	struct sdw_slave_prop prop;
+	struct sdw_slave_sysfs *sysfs;
 	struct list_head node;
 	struct completion *port_ready;
 	u16 dev_num;
@@ -521,6 +532,7 @@ struct sdw_master_ops {
  * @msg_lock: message lock
  * @ops: Master callback ops
  * @prop: Master properties
+ * @sysfs: Bus sysfs
  * @defer_msg: Defer message
  * @clk_stop_timeout: Clock stop timeout computed
  */
@@ -533,6 +545,7 @@ struct sdw_bus {
 	struct mutex msg_lock;
 	const struct sdw_master_ops *ops;
 	struct sdw_master_prop prop;
+	struct sdw_master_sysfs *sysfs;
 	struct sdw_defer defer_msg;
 	unsigned int clk_stop_timeout;
 };
Signature · 1 line
2.7.4
author
#32 lore raw

PATCH v2 11/14 soundwire: cdns: Add cadence library

In reply to Vinod Koul

Cadence IP implements SoundWire Master. Add base cadence library initialization and interrupt handling

---
 drivers/soundwire/Kconfig          |   3 +
 drivers/soundwire/Makefile         |   4 +
 drivers/soundwire/cadence_master.c | 469 +++++++++++++++++++++++++++++++++++++
 drivers/soundwire/cadence_master.h |  82 +++++++
 4 files changed, 558 insertions(+)
 create mode 100644 drivers/soundwire/cadence_master.c
 create mode 100644 drivers/soundwire/cadence_master.h
drivers/soundwire/Kconfig +3 -0
index 57bf769d9be7..65d97ef59fbb 100644
@@ -19,4 +19,7 @@ config SOUNDWIRE_BUS
 	tristate
 	select REGMAP_SOUNDWIRE
 
+config SOUNDWIRE_CADENCE
+	tristate
+
 endif
drivers/soundwire/Makefile +4 -0
index 67dc7b546258..f9a1ce3a860e 100644
@@ -5,3 +5,7 @@
 #Bus Objs
 soundwire-bus-objs := bus_type.o bus.o slave.o mipi_disco.o sysfs.o
 obj-$(CONFIG_SOUNDWIRE_BUS) += soundwire-bus.o
+
+#Cadence Objs
+soundwire-cadence-objs := cadence_master.o
+obj-$(CONFIG_SOUNDWIRE_CADENCE) += soundwire-cadence.o
drivers/soundwire/cadence_master.c new file +469 -0

469 lines not on this page · raw message

drivers/soundwire/cadence_master.h new file +82 -0

82 lines not on this page · raw message

Signature · 1 line
2.7.4
author
#33 lore raw

PATCH v2 12/14 soundwire: cdns: Add sdw_master_ops and IO transfer support

In reply to Vinod Koul

From: Sanyog Kale <[email protected]>

Implement sdw_master_ops with support for xfer_msg, xfer_msg_defer and reset_page_addr. Since Cadence module doesn't know the systems it will be used, set the read_prop to the bus helper.

---
 drivers/soundwire/cadence_master.c | 322 +++++++++++++++++++++++++++++++++++++
 drivers/soundwire/cadence_master.h |  14 ++
 2 files changed, 336 insertions(+)
drivers/soundwire/cadence_master.c +322 -0
index 7a9dc2fbf695..cf612b573b3e 100644
@@ -269,9 +269,261 @@ static int cdns_clear_bit(struct sdw_cdns *cdns, int offset, u32 value)
 }
 
 /*
+ * IO Calls
+ */
+static enum sdw_command_response cdns_fill_msg_resp(
+			struct sdw_cdns *cdns,
+			struct sdw_msg *msg, int count, int offset)
+{
+	int nack = 0, no_ack = 0;
+	int i;
+
+	/* check message response */
+	for (i = 0; i < count; i++) {
+		if (!(cdns->response_buf[i] & CDNS_MCP_RESP_ACK)) {
+			no_ack = 1;
+			dev_dbg(cdns->dev, "Msg Ack not received\n");
+			if (cdns->response_buf[i] & CDNS_MCP_RESP_NACK) {
+				nack = 1;
+				dev_err(cdns->dev, "Msg NACK received\n");
+			}
+		}
+	}
+
+	if (nack) {
+		dev_err(cdns->dev, "Msg NACKed for Slave %d\n", msg->dev_num);
+		return SDW_CMD_FAIL;
+	} else if (no_ack) {
+		dev_dbg(cdns->dev, "Msg ignored for Slave %d\n", msg->dev_num);
+		return SDW_CMD_IGNORED;
+	}
+
+	/* fill response */
+	for (i = 0; i < count; i++)
+		msg->buf[i + offset] = cdns->response_buf[i] >>
+				SDW_REG_SHIFT(CDNS_MCP_RESP_RDATA);
+
+	return SDW_CMD_OK;
+}
+
+static enum sdw_command_response
+_cdns_xfer_msg(struct sdw_cdns *cdns, struct sdw_msg *msg, int cmd,
+				int offset, int count, bool defer)
+{
+	unsigned long time;
+	u32 base, i, data;
+	u16 addr;
+
+	/* Program the watermark level for RX FIFO */
+	if (cdns->msg_count != count) {
+		cdns_writel(cdns, CDNS_MCP_FIFOLEVEL, count);
+		cdns->msg_count = count;
+	}
+
+	base = CDNS_MCP_CMD_BASE;
+	addr = msg->addr;
+
+	for (i = 0; i < count; i++) {
+		data = msg->dev_num << SDW_REG_SHIFT(CDNS_MCP_CMD_DEV_ADDR);
+		data |= cmd << SDW_REG_SHIFT(CDNS_MCP_CMD_COMMAND);
+		data |= addr++  << SDW_REG_SHIFT(CDNS_MCP_CMD_REG_ADDR_L);
+
+		if (msg->flags == SDW_MSG_FLAG_WRITE)
+			data |= msg->buf[i + offset];
+
+		data |= msg->ssp_sync << SDW_REG_SHIFT(CDNS_MCP_CMD_SSP_TAG);
+		cdns_writel(cdns, base, data);
+		base += CDNS_MCP_CMD_WORD_LEN;
+	}
+
+	if (defer)
+		return SDW_CMD_OK;
+
+	/* wait for timeout or response */
+	time = wait_for_completion_timeout(&cdns->tx_complete,
+				msecs_to_jiffies(CDNS_TX_TIMEOUT));
+	if (!time) {
+		dev_err(cdns->dev, "IO transfer timed out\n");
+		msg->len = 0;
+		return SDW_CMD_TIMEOUT;
+	}
+
+	return cdns_fill_msg_resp(cdns, msg, count, offset);
+}
+
+static enum sdw_command_response cdns_program_scp_addr(
+			struct sdw_cdns *cdns, struct sdw_msg *msg)
+{
+	int nack = 0, no_ack = 0;
+	unsigned long time;
+	u32 data[2], base;
+	int i;
+
+	/* Program the watermark level for RX FIFO */
+	if (cdns->msg_count != CDNS_SCP_RX_FIFOLEVEL) {
+		cdns_writel(cdns, CDNS_MCP_FIFOLEVEL, CDNS_SCP_RX_FIFOLEVEL);
+		cdns->msg_count = CDNS_SCP_RX_FIFOLEVEL;
+	}
+
+	data[0] = msg->dev_num << SDW_REG_SHIFT(CDNS_MCP_CMD_DEV_ADDR);
+	data[0] |= 0x3 << SDW_REG_SHIFT(CDNS_MCP_CMD_COMMAND);
+	data[1] = data[0];
+
+	data[0] |= SDW_SCP_ADDRPAGE1 << SDW_REG_SHIFT(CDNS_MCP_CMD_REG_ADDR_L);
+	data[1] |= SDW_SCP_ADDRPAGE2 << SDW_REG_SHIFT(CDNS_MCP_CMD_REG_ADDR_L);
+
+	data[0] |= msg->addr_page1;
+	data[1] |= msg->addr_page2;
+
+	base = CDNS_MCP_CMD_BASE;
+	cdns_writel(cdns, base, data[0]);
+	base += CDNS_MCP_CMD_WORD_LEN;
+	cdns_writel(cdns, base, data[1]);
+
+	time = wait_for_completion_timeout(&cdns->tx_complete,
+				msecs_to_jiffies(CDNS_TX_TIMEOUT));
+	if (!time) {
+		dev_err(cdns->dev, "SCP Msg trf timed out\n");
+		msg->len = 0;
+		return SDW_CMD_TIMEOUT;
+	}
+
+	/* check response the writes */
+	for (i = 0; i < 2; i++) {
+		if (!(cdns->response_buf[i] & CDNS_MCP_RESP_ACK)) {
+			no_ack = 1;
+			dev_err(cdns->dev, "Program SCP Ack not received");
+			if (cdns->response_buf[i] & CDNS_MCP_RESP_NACK) {
+				nack = 1;
+				dev_err(cdns->dev, "Program SCP NACK received");
+			}
+		}
+	}
+
+	/* For NACK, NO ack, don't return err if we are in Broadcast mode */
+	if (nack) {
+		dev_err(cdns->dev,
+			"SCP_addrpage NACKed for Slave %d", msg->dev_num);
+		return SDW_CMD_FAIL;
+	} else if (no_ack) {
+		dev_dbg(cdns->dev,
+			"SCP_addrpage ignored for Slave %d", msg->dev_num);
+		return SDW_CMD_IGNORED;
+	}
+
+	return SDW_CMD_OK;
+}
+
+static int cdns_prep_msg(struct sdw_cdns *cdns, struct sdw_msg *msg, int *cmd)
+{
+	int ret;
+
+	if (msg->page) {
+		ret = cdns_program_scp_addr(cdns, msg);
+		if (ret) {
+			msg->len = 0;
+			return ret;
+		}
+	}
+
+	switch (msg->flags) {
+	case SDW_MSG_FLAG_READ:
+		*cmd = CDNS_MCP_CMD_READ;
+		break;
+
+	case SDW_MSG_FLAG_WRITE:
+		*cmd = CDNS_MCP_CMD_WRITE;
+		break;
+
+	default:
+		dev_err(cdns->dev, "Invalid msg cmd: %d\n", msg->flags);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static enum sdw_command_response
+cdns_xfer_msg(struct sdw_bus *bus, struct sdw_msg *msg)
+{
+	struct sdw_cdns *cdns = bus_to_cdns(bus);
+	int cmd = 0, ret, i;
+
+	ret = cdns_prep_msg(cdns, msg, &cmd);
+	if (ret)
+		return SDW_CMD_FAIL_OTHER;
+
+	for (i = 0; i < msg->len / CDNS_MCP_CMD_LEN; i++) {
+		ret = _cdns_xfer_msg(cdns, msg, cmd, i * CDNS_MCP_CMD_LEN,
+				CDNS_MCP_CMD_LEN, false);
+		if (ret < 0)
+			goto exit;
+	}
+
+	if (!(msg->len % CDNS_MCP_CMD_LEN))
+		goto exit;
+
+	ret = _cdns_xfer_msg(cdns, msg, cmd, i * CDNS_MCP_CMD_LEN,
+			msg->len % CDNS_MCP_CMD_LEN, false);
+
+exit:
+	return ret;
+}
+
+static enum sdw_command_response
+cdns_xfer_msg_defer(struct sdw_bus *bus,
+		struct sdw_msg *msg, struct sdw_defer *defer)
+{
+	struct sdw_cdns *cdns = bus_to_cdns(bus);
+	int cmd = 0, ret;
+
+	/* for defer only 1 message is supported */
+	if (msg->len > 1)
+		return -ENOTSUPP;
+
+	ret = cdns_prep_msg(cdns, msg, &cmd);
+	if (ret)
+		return SDW_CMD_FAIL_OTHER;
+
+	cdns->defer = defer;
+	cdns->defer->length = msg->len;
+
+	return _cdns_xfer_msg(cdns, msg, cmd, 0, msg->len, true);
+}
+
+static enum sdw_command_response
+cdns_reset_page_addr(struct sdw_bus *bus, unsigned int dev_num)
+{
+	struct sdw_cdns *cdns = bus_to_cdns(bus);
+	struct sdw_msg msg;
+
+	/* Create dummy message with valid device number */
+	memset(&msg, 0, sizeof(msg));
+	msg.dev_num = dev_num;
+
+	return cdns_program_scp_addr(cdns, &msg);
+}
+
+/*
  * IRQ handling
  */
 
+static void cdns_read_response(struct sdw_cdns *cdns)
+{
+	u32 num_resp, cmd_base;
+	int i;
+
+	num_resp = cdns_readl(cdns, CDNS_MCP_FIFOSTAT);
+	num_resp &= CDNS_MCP_RX_FIFO_AVAIL;
+
+	cmd_base = CDNS_MCP_CMD_BASE;
+
+	for (i = 0; i < num_resp; i++) {
+		cdns->response_buf[i] = cdns_readl(cdns, cmd_base);
+		cmd_base += CDNS_MCP_CMD_WORD_LEN;
+	}
+}
+
 static int cdns_update_slave_status(struct sdw_cdns *cdns,
 					u32 slave0, u32 slave1)
 {
@@ -346,6 +598,18 @@ irqreturn_t sdw_cdns_irq(int irq, void *dev_id)
 	if (!(int_status & CDNS_MCP_INT_IRQ))
 		return IRQ_NONE;
 
+	if (int_status & CDNS_MCP_INT_RX_WL) {
+		cdns_read_response(cdns);
+
+		if (cdns->defer) {
+			cdns_fill_msg_resp(cdns, cdns->defer->msg,
+					cdns->defer->length, 0);
+			complete(&cdns->defer->complete);
+			cdns->defer = NULL;
+		} else
+			complete(&cdns->tx_complete);
+	}
+
 	if (int_status & CDNS_MCP_INT_CTRL_CLASH) {
 
 		/* Slave is driving bit slot during control word */
@@ -402,6 +666,43 @@ EXPORT_SYMBOL(sdw_cdns_thread);
 /*
  * init routines
  */
+static int _cdns_enable_interrupt(struct sdw_cdns *cdns)
+{
+	u32 mask;
+
+	cdns_writel(cdns, CDNS_MCP_SLAVE_INTMASK0,
+				CDNS_MCP_SLAVE_INTMASK0_MASK);
+	cdns_writel(cdns, CDNS_MCP_SLAVE_INTMASK1,
+				CDNS_MCP_SLAVE_INTMASK1_MASK);
+
+	mask = CDNS_MCP_INT_SLAVE_RSVD | CDNS_MCP_INT_SLAVE_ALERT |
+		CDNS_MCP_INT_SLAVE_ATTACH | CDNS_MCP_INT_SLAVE_NATTACH |
+		CDNS_MCP_INT_CTRL_CLASH | CDNS_MCP_INT_DATA_CLASH |
+		CDNS_MCP_INT_RX_WL | CDNS_MCP_INT_IRQ | CDNS_MCP_INT_DPINT;
+
+	cdns_writel(cdns, CDNS_MCP_INTMASK, mask);
+
+	return 0;
+}
+
+/**
+ * sdw_cdns_enable_interrupt: Enable SDW interrupts and update config
+ *
+ * @cdns: Cadence instance
+ */
+int sdw_cdns_enable_interrupt(struct sdw_cdns *cdns)
+{
+	int ret;
+
+	_cdns_enable_interrupt(cdns);
+	ret = cdns_clear_bit(cdns, CDNS_MCP_CONFIG_UPDATE,
+			CDNS_MCP_CONFIG_UPDATE_BIT);
+	if (ret < 0)
+		dev_err(cdns->dev, "Config update timedout");
+
+	return ret;
+}
+EXPORT_SYMBOL(sdw_cdns_enable_interrupt);
 
 /**
  * sdw_cdns_init: Cadence initialization
@@ -465,5 +766,26 @@ int sdw_cdns_init(struct sdw_cdns *cdns)
 }
 EXPORT_SYMBOL(sdw_cdns_init);
 
+struct sdw_master_ops sdw_cdns_master_ops = {
+	.read_prop = sdw_master_read_prop,
+	.xfer_msg = cdns_xfer_msg,
+	.xfer_msg_defer = cdns_xfer_msg_defer,
+	.reset_page_addr = cdns_reset_page_addr,
+};
+EXPORT_SYMBOL(sdw_cdns_master_ops);
+
+/**
+ * sdw_cdns_probe: Cadence probe routine
+ *
+ * @cdns: Cadence instance
+ */
+int sdw_cdns_probe(struct sdw_cdns *cdns)
+{
+	init_completion(&cdns->tx_complete);
+
+	return 0;
+}
+EXPORT_SYMBOL(sdw_cdns_probe);
+
 MODULE_LICENSE("Dual BSD/GPL");
 MODULE_DESCRIPTION("Cadence Soundwire Library");
drivers/soundwire/cadence_master.h +14 -0
index a8cb82a15126..5ea7b9ec74e6 100644
@@ -57,26 +57,40 @@
  * @dev: Linux device
  * @bus: Bus handle
  * @instance: instance number
+ * @response_buf: SoundWire response buffer
+ * @tx_complete: Tx completion
+ * @defer: Defer pointer
  * @registers: Cadence registers
  * @link_up: Link status
+ * @msg_count: Messages sent on bus
  */
 struct sdw_cdns {
 	struct device *dev;
 	struct sdw_bus bus;
 	unsigned int instance;
 
+	u32 response_buf[0x80];
+	struct completion tx_complete;
+	struct sdw_defer *defer;
+
 	void __iomem *registers;
 
 	bool link_up;
+	unsigned int msg_count;
 };
 
 #define bus_to_cdns(_bus) container_of(_bus, struct sdw_cdns, bus)
 
 /* Exported symbols */
 
+int sdw_cdns_probe(struct sdw_cdns *cdns);
+extern struct sdw_master_ops sdw_cdns_master_ops;
+
 irqreturn_t sdw_cdns_irq(int irq, void *dev_id);
 irqreturn_t sdw_cdns_thread(int irq, void *dev_id);
 
 int sdw_cdns_init(struct sdw_cdns *cdns);
+int sdw_cdns_enable_interrupt(struct sdw_cdns *cdns);
+
 
 #endif /* __SDW_CADENCE_H */
Signature · 1 line
2.7.4
author
#34 lore raw

PATCH v2 13/14 soundwire: intel: Add Intel Master driver

In reply to Vinod Koul

Some Intel platforms have SoundWire Master, so add Intel SoundWire Master driver which uses Cadence module. This patch adds probe and initialization routines for Intel Master driver.

---
 drivers/soundwire/Kconfig           |  11 +
 drivers/soundwire/Makefile          |   4 +
 drivers/soundwire/intel.c           | 391 ++++++++++++++++++++++++++++++++++++
 drivers/soundwire/intel.h           |  72 +++++++
 include/linux/soundwire/sdw_intel.h |  71 +++++++
 5 files changed, 549 insertions(+)
 create mode 100644 drivers/soundwire/intel.c
 create mode 100644 drivers/soundwire/intel.h
 create mode 100644 include/linux/soundwire/sdw_intel.h
drivers/soundwire/Kconfig +11 -0
index 65d97ef59fbb..0b8e4b9cef99 100644
@@ -22,4 +22,15 @@ config SOUNDWIRE_BUS
 config SOUNDWIRE_CADENCE
 	tristate
 
+config SOUNDWIRE_INTEL
+	tristate "Intel SoundWire Master driver"
+	select SOUNDWIRE_CADENCE
+	select SOUNDWIRE_BUS
+	depends on X86 && ACPI
+	---help---
+	  SoundWire Intel Master driver.
+	  If you have an Intel platform which has a SoundWire Master then
+	  enable this config option to get the SoundWire support for that
+	  device.
+
 endif
drivers/soundwire/Makefile +4 -0
index f9a1ce3a860e..0813b2c74426 100644
@@ -9,3 +9,7 @@ obj-$(CONFIG_SOUNDWIRE_BUS) += soundwire-bus.o
 #Cadence Objs
 soundwire-cadence-objs := cadence_master.o
 obj-$(CONFIG_SOUNDWIRE_CADENCE) += soundwire-cadence.o
+
+#Intel driver
+soundwire-intel-objs :=	intel.o
+obj-$(CONFIG_SOUNDWIRE_INTEL) += soundwire-intel.o
drivers/soundwire/intel.c new file +391 -0

391 lines not on this page · raw message

drivers/soundwire/intel.h new file +72 -0

72 lines not on this page · raw message

include/linux/soundwire/sdw_intel.h new file +71 -0

71 lines not on this page · raw message

Signature · 1 line
2.7.4
author
#35 lore raw

PATCH v2 14/14 soundwire: intel: Add Intel init module

In reply to Vinod Koul

The SoundWire Master is implemented as part of Audio controller in Intel platforms. Add a init module which creates SoundWire Master platform devices based on the links supported in the hardware.

---
 drivers/soundwire/Makefile          |   3 +
 drivers/soundwire/intel_init.c      | 232 ++++++++++++++++++++++++++++++++++++
 include/linux/soundwire/sdw_intel.h |   3 +
 3 files changed, 238 insertions(+)
 create mode 100644 drivers/soundwire/intel_init.c
drivers/soundwire/Makefile +3 -0
index 0813b2c74426..94272c965d6c 100644
@@ -13,3 +13,6 @@ obj-$(CONFIG_SOUNDWIRE_CADENCE) += soundwire-cadence.o
 #Intel driver
 soundwire-intel-objs :=	intel.o
 obj-$(CONFIG_SOUNDWIRE_INTEL) += soundwire-intel.o
+
+soundwire-intel-init-objs := intel_init.o
+obj-$(CONFIG_SOUNDWIRE_INTEL) += soundwire-intel-init.o
drivers/soundwire/intel_init.c new file +232 -0

232 lines not on this page · raw message

include/linux/soundwire/sdw_intel.h +3 -0
index 27a5c4f76576..3a47e3b544b6 100644
@@ -68,4 +68,7 @@ struct sdw_intel_res {
 	struct device *parent;
 };
 
+void *sdw_intel_init(acpi_handle *parent_handle, struct sdw_intel_res *res);
+void sdw_intel_exit(void *arg);
+
 #endif
Signature · 1 line
2.7.4