Commit 9251345d authored by Vinod Koul's avatar Vinod Koul Committed by Greg Kroah-Hartman

soundwire: Add SoundWire bus type

This adds the base SoundWire bus type, bus and driver registration.
along with changes to module device table for new SoundWire
device type.
Signed-off-by: default avatarSanyog Kale <sanyog.r.kale@intel.com>
Reviewed-by: default avatarPhilippe Ombredanne <pombredanne@nexb.com>
Acked-By: default avatarPierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Reviewed-by: default avatarTakashi Iwai <tiwai@suse.de>
Acked-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarVinod Koul <vinod.koul@intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 8ecf4264
......@@ -153,6 +153,8 @@ source "drivers/remoteproc/Kconfig"
source "drivers/rpmsg/Kconfig"
source "drivers/soundwire/Kconfig"
source "drivers/soc/Kconfig"
source "drivers/devfreq/Kconfig"
......
......@@ -158,6 +158,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/
......
#
# 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. Say Y to enable this subsystem, N if you do not have such
a device
if SOUNDWIRE
comment "SoundWire Devices"
config SOUNDWIRE_BUS
tristate
endif
#
# Makefile for soundwire core
#
#Bus Objs
soundwire-bus-objs := bus_type.o
obj-$(CONFIG_SOUNDWIRE_BUS) += soundwire-bus.o
// SPDX-License-Identifier: GPL-2.0
// Copyright(c) 2015-17 Intel Corporation.
#include <linux/module.h>
#include <linux/mod_devicetable.h>
#include <linux/pm_domain.h>
#include <linux/soundwire/sdw.h>
#include <linux/soundwire/sdw_type.h>
/**
* sdw_get_device_id - find the matching SoundWire device id
* @slave: SoundWire Slave Device
* @drv: SoundWire Slave Driver
*
* The match is done by comparing the mfg_id and part_id from the
* struct sdw_device_id.
*/
static const struct sdw_device_id *
sdw_get_device_id(struct sdw_slave *slave, struct sdw_driver *drv)
{
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;
}
static int sdw_bus_match(struct device *dev, struct device_driver *ddrv)
{
struct sdw_slave *slave = dev_to_sdw_dev(dev);
struct sdw_driver *drv = drv_to_sdw_driver(ddrv);
return !!sdw_get_device_id(slave, drv);
}
int sdw_slave_modalias(const struct sdw_slave *slave, char *buf, size_t size)
{
/* modalias is sdw:m<mfg_id>p<part_id> */
return snprintf(buf, size, "sdw:m%04Xp%04X\n",
slave->id.mfg_id, slave->id.part_id);
}
static int sdw_uevent(struct device *dev, struct kobj_uevent_env *env)
{
struct sdw_slave *slave = dev_to_sdw_dev(dev);
char modalias[32];
sdw_slave_modalias(slave, modalias, sizeof(modalias));
if (add_uevent_var(env, "MODALIAS=%s", modalias))
return -ENOMEM;
return 0;
}
struct bus_type sdw_bus_type = {
.name = "soundwire",
.match = sdw_bus_match,
.uevent = sdw_uevent,
};
EXPORT_SYMBOL_GPL(sdw_bus_type);
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;
id = sdw_get_device_id(slave, drv);
if (!id)
return -ENODEV;
/*
* attach to power domain but don't turn on (last arg)
*/
ret = dev_pm_domain_attach(dev, false);
if (ret != -EPROBE_DEFER) {
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;
}
static int sdw_drv_remove(struct device *dev)
{
struct sdw_slave *slave = dev_to_sdw_dev(dev);
struct sdw_driver *drv = drv_to_sdw_driver(dev->driver);
int ret = 0;
if (drv->remove)
ret = drv->remove(slave);
dev_pm_domain_detach(dev, false);
return ret;
}
static void sdw_drv_shutdown(struct device *dev)
{
struct sdw_slave *slave = dev_to_sdw_dev(dev);
struct sdw_driver *drv = drv_to_sdw_driver(dev->driver);
if (drv->shutdown)
drv->shutdown(slave);
}
/**
* __sdw_register_driver() - register a SoundWire Slave driver
* @drv: driver to register
* @owner: owning module/driver
*
* Return: zero on success, else a negative error code.
*/
int __sdw_register_driver(struct sdw_driver *drv, struct module *owner)
{
drv->driver.bus = &sdw_bus_type;
if (!drv->probe) {
pr_err("driver %s didn't provide SDW probe routine\n",
drv->name);
return -EINVAL;
}
drv->driver.owner = owner;
drv->driver.probe = sdw_drv_probe;
if (drv->remove)
drv->driver.remove = sdw_drv_remove;
if (drv->shutdown)
drv->driver.shutdown = sdw_drv_shutdown;
return driver_register(&drv->driver);
}
EXPORT_SYMBOL_GPL(__sdw_register_driver);
/**
* sdw_unregister_driver() - unregisters the SoundWire Slave driver
* @drv: driver to unregister
*/
void sdw_unregister_driver(struct sdw_driver *drv)
{
driver_unregister(&drv->driver);
}
EXPORT_SYMBOL_GPL(sdw_unregister_driver);
static int __init sdw_bus_init(void)
{
return bus_register(&sdw_bus_type);
}
static void __exit sdw_bus_exit(void)
{
bus_unregister(&sdw_bus_type);
}
postcore_initcall(sdw_bus_init);
module_exit(sdw_bus_exit);
MODULE_DESCRIPTION("SoundWire bus");
MODULE_LICENSE("GPL v2");
......@@ -229,6 +229,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
*/
......
// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
// Copyright(c) 2015-17 Intel Corporation.
#ifndef __SOUNDWIRE_H
#define __SOUNDWIRE_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,
SDW_SLAVE_RESERVED = 3,
};
/*
* SDW Slave Structures and APIs
*/
/**
* struct sdw_slave_id - Slave ID
* @mfg_id: MIPI Manufacturer ID
* @part_id: Device Part ID
* @class_id: MIPI Class ID, unused now.
* Currently a placeholder in MIPI SoundWire Spec
* @unique_id: Device unique ID
* @sdw_version: SDW version implemented
*
* The order of the IDs here does not follow the DisCo spec definitions
*/
struct sdw_slave_id {
__u16 mfg_id;
__u16 part_id;
__u8 class_id;
__u8 unique_id:4;
__u8 sdw_version:4;
};
/**
* struct sdw_slave - SoundWire Slave
* @id: MIPI device ID
* @dev: Linux device
* @status: Status reported by the Slave
* @bus: Bus handle
* @node: node for bus list
* @dev_num: Device Number assigned by Bus
*/
struct sdw_slave {
struct sdw_slave_id id;
struct device dev;
enum sdw_slave_status status;
struct sdw_bus *bus;
struct list_head node;
u16 dev_num;
};
#define dev_to_sdw_dev(_dev) container_of(_dev, struct sdw_slave, dev)
struct sdw_driver {
const char *name;
int (*probe)(struct sdw_slave *sdw,
const struct sdw_device_id *id);
int (*remove)(struct sdw_slave *sdw);
void (*shutdown)(struct sdw_slave *sdw);
const struct sdw_device_id *id_table;
const struct sdw_slave_ops *ops;
struct device_driver driver;
};
#define SDW_SLAVE_ENTRY(_mfg_id, _part_id, _drv_data) \
{ .mfg_id = (_mfg_id), .part_id = (_part_id), \
.driver_data = (unsigned long)(_drv_data) }
/*
* SDW master structures and APIs
*/
/**
* struct sdw_bus - SoundWire bus
* @dev: Master linux device
* @link_id: Link id number, can be 0 to N, unique for each Master
* @slaves: list of Slaves on this bus
* @assigned: Bitmap for Slave device numbers.
* Bit set implies used number, bit clear implies unused number.
* @bus_lock: bus lock
*/
struct sdw_bus {
struct device *dev;
unsigned int link_id;
struct list_head slaves;
DECLARE_BITMAP(assigned, SDW_MAX_DEVICES);
struct mutex bus_lock;
};
#endif /* __SOUNDWIRE_H */
// SPDX-License-Identifier: GPL-2.0
// Copyright(c) 2015-17 Intel Corporation.
#ifndef __SOUNDWIRE_TYPES_H
#define __SOUNDWIRE_TYPES_H
extern struct bus_type sdw_bus_type;
#define drv_to_sdw_driver(_drv) container_of(_drv, struct sdw_driver, driver)
#define sdw_register_driver(drv) \
__sdw_register_driver(drv, THIS_MODULE)
int __sdw_register_driver(struct sdw_driver *drv, struct module *);
void sdw_unregister_driver(struct sdw_driver *drv);
int sdw_slave_modalias(const struct sdw_slave *slave, char *buf, size_t size);
#endif /* __SOUNDWIRE_TYPES_H */
......@@ -203,6 +203,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);
......
......@@ -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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment