Commit 90acca1d authored by Pierre-Louis Bossart's avatar Pierre-Louis Bossart Committed by Vinod Koul

soundwire: bus_type: introduce sdw_slave_type and sdw_master_type

this is a preparatory patch before the introduction of the
sdw_master_type. The SoundWire slave support is slightly modified with
the use of a sdw_slave_type, and the uevent handling move to
slave.c (since it's not necessary for the master).

No functionality change other than moving code around.
Signed-off-by: default avatarPierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Signed-off-by: default avatarBard Liao <yung-chuan.liao@linux.intel.com>
Acked-by: default avatarJaroslav Kysela <perex@perex.cz>
Link: https://lore.kernel.org/r/20200518174322.31561-3-yung-chuan.liao@linux.intel.comSigned-off-by: default avatarVinod Koul <vkoul@kernel.org>
parent 5cab3ff2
...@@ -33,13 +33,21 @@ sdw_get_device_id(struct sdw_slave *slave, struct sdw_driver *drv) ...@@ -33,13 +33,21 @@ sdw_get_device_id(struct sdw_slave *slave, struct sdw_driver *drv)
static int sdw_bus_match(struct device *dev, struct device_driver *ddrv) static int sdw_bus_match(struct device *dev, struct device_driver *ddrv)
{ {
struct sdw_slave *slave = dev_to_sdw_dev(dev); struct sdw_slave *slave;
struct sdw_driver *drv = drv_to_sdw_driver(ddrv); struct sdw_driver *drv;
int ret = 0;
if (is_sdw_slave(dev)) {
slave = dev_to_sdw_dev(dev);
drv = drv_to_sdw_driver(ddrv);
return !!sdw_get_device_id(slave, drv); ret = !!sdw_get_device_id(slave, drv);
}
return ret;
} }
int sdw_slave_modalias(const struct sdw_slave *slave, char *buf, size_t size) static int sdw_slave_modalias(const struct sdw_slave *slave, char *buf,
size_t size)
{ {
/* modalias is sdw:m<mfg_id>p<part_id> */ /* modalias is sdw:m<mfg_id>p<part_id> */
...@@ -47,7 +55,7 @@ int sdw_slave_modalias(const struct sdw_slave *slave, char *buf, size_t size) ...@@ -47,7 +55,7 @@ int sdw_slave_modalias(const struct sdw_slave *slave, char *buf, size_t size)
slave->id.mfg_id, slave->id.part_id); slave->id.mfg_id, slave->id.part_id);
} }
static int sdw_uevent(struct device *dev, struct kobj_uevent_env *env) int sdw_slave_uevent(struct device *dev, struct kobj_uevent_env *env)
{ {
struct sdw_slave *slave = dev_to_sdw_dev(dev); struct sdw_slave *slave = dev_to_sdw_dev(dev);
char modalias[32]; char modalias[32];
...@@ -63,7 +71,6 @@ static int sdw_uevent(struct device *dev, struct kobj_uevent_env *env) ...@@ -63,7 +71,6 @@ static int sdw_uevent(struct device *dev, struct kobj_uevent_env *env)
struct bus_type sdw_bus_type = { struct bus_type sdw_bus_type = {
.name = "soundwire", .name = "soundwire",
.match = sdw_bus_match, .match = sdw_bus_match,
.uevent = sdw_uevent,
}; };
EXPORT_SYMBOL_GPL(sdw_bus_type); EXPORT_SYMBOL_GPL(sdw_bus_type);
......
...@@ -14,6 +14,12 @@ static void sdw_slave_release(struct device *dev) ...@@ -14,6 +14,12 @@ static void sdw_slave_release(struct device *dev)
kfree(slave); kfree(slave);
} }
struct device_type sdw_slave_type = {
.name = "sdw_slave",
.release = sdw_slave_release,
.uevent = sdw_slave_uevent,
};
static int sdw_slave_add(struct sdw_bus *bus, static int sdw_slave_add(struct sdw_bus *bus,
struct sdw_slave_id *id, struct fwnode_handle *fwnode) struct sdw_slave_id *id, struct fwnode_handle *fwnode)
{ {
...@@ -41,9 +47,9 @@ static int sdw_slave_add(struct sdw_bus *bus, ...@@ -41,9 +47,9 @@ static int sdw_slave_add(struct sdw_bus *bus,
id->class_id, id->unique_id); id->class_id, id->unique_id);
} }
slave->dev.release = sdw_slave_release;
slave->dev.bus = &sdw_bus_type; slave->dev.bus = &sdw_bus_type;
slave->dev.of_node = of_node_get(to_of_node(fwnode)); slave->dev.of_node = of_node_get(to_of_node(fwnode));
slave->dev.type = &sdw_slave_type;
slave->bus = bus; slave->bus = bus;
slave->status = SDW_SLAVE_UNATTACHED; slave->status = SDW_SLAVE_UNATTACHED;
init_completion(&slave->enumeration_complete); init_completion(&slave->enumeration_complete);
......
...@@ -5,6 +5,13 @@ ...@@ -5,6 +5,13 @@
#define __SOUNDWIRE_TYPES_H #define __SOUNDWIRE_TYPES_H
extern struct bus_type sdw_bus_type; extern struct bus_type sdw_bus_type;
extern struct device_type sdw_slave_type;
extern struct device_type sdw_master_type;
static inline int is_sdw_slave(const struct device *dev)
{
return dev->type == &sdw_slave_type;
}
#define drv_to_sdw_driver(_drv) container_of(_drv, struct sdw_driver, driver) #define drv_to_sdw_driver(_drv) container_of(_drv, struct sdw_driver, driver)
...@@ -14,7 +21,7 @@ extern struct bus_type sdw_bus_type; ...@@ -14,7 +21,7 @@ extern struct bus_type sdw_bus_type;
int __sdw_register_driver(struct sdw_driver *drv, struct module *owner); int __sdw_register_driver(struct sdw_driver *drv, struct module *owner);
void sdw_unregister_driver(struct sdw_driver *drv); void sdw_unregister_driver(struct sdw_driver *drv);
int sdw_slave_modalias(const struct sdw_slave *slave, char *buf, size_t size); int sdw_slave_uevent(struct device *dev, struct kobj_uevent_env *env);
/** /**
* module_sdw_driver() - Helper macro for registering a Soundwire driver * module_sdw_driver() - Helper macro for registering a Soundwire driver
......
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