linux/drivers/platform/surface/aggregator/bus.c

// SPDX-License-Identifier: GPL-2.0+
/*
 * Surface System Aggregator Module bus and device integration.
 *
 * Copyright (C) 2019-2022 Maximilian Luz <[email protected]>
 */

#include <linux/device.h>
#include <linux/property.h>
#include <linux/slab.h>

#include <linux/surface_aggregator/controller.h>
#include <linux/surface_aggregator/device.h>

#include "bus.h"
#include "controller.h"


/* -- Device and bus functions. --------------------------------------------- */

static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
			     char *buf)
{}
static DEVICE_ATTR_RO(modalias);

static struct attribute *ssam_device_attrs[] =;
ATTRIBUTE_GROUPS();

static const struct bus_type ssam_bus_type;

static int ssam_device_uevent(const struct device *dev, struct kobj_uevent_env *env)
{}

static void ssam_device_release(struct device *dev)
{}

const struct device_type ssam_device_type =;
EXPORT_SYMBOL_GPL();

/**
 * ssam_device_alloc() - Allocate and initialize a SSAM client device.
 * @ctrl: The controller under which the device should be added.
 * @uid:  The UID of the device to be added.
 *
 * Allocates and initializes a new client device. The parent of the device
 * will be set to the controller device and the name will be set based on the
 * UID. Note that the device still has to be added via ssam_device_add().
 * Refer to that function for more details.
 *
 * Return: Returns the newly allocated and initialized SSAM client device, or
 * %NULL if it could not be allocated.
 */
struct ssam_device *ssam_device_alloc(struct ssam_controller *ctrl,
				      struct ssam_device_uid uid)
{}
EXPORT_SYMBOL_GPL();

/**
 * ssam_device_add() - Add a SSAM client device.
 * @sdev: The SSAM client device to be added.
 *
 * Added client devices must be guaranteed to always have a valid and active
 * controller. Thus, this function will fail with %-ENODEV if the controller
 * of the device has not been initialized yet, has been suspended, or has been
 * shut down.
 *
 * The caller of this function should ensure that the corresponding call to
 * ssam_device_remove() is issued before the controller is shut down. If the
 * added device is a direct child of the controller device (default), it will
 * be automatically removed when the controller is shut down.
 *
 * By default, the controller device will become the parent of the newly
 * created client device. The parent may be changed before ssam_device_add is
 * called, but care must be taken that a) the correct suspend/resume ordering
 * is guaranteed and b) the client device does not outlive the controller,
 * i.e. that the device is removed before the controller is being shut down.
 * In case these guarantees have to be manually enforced, please refer to the
 * ssam_client_link() and ssam_client_bind() functions, which are intended to
 * set up device-links for this purpose.
 *
 * Return: Returns zero on success, a negative error code on failure.
 */
int ssam_device_add(struct ssam_device *sdev)
{}
EXPORT_SYMBOL_GPL();

/**
 * ssam_device_remove() - Remove a SSAM client device.
 * @sdev: The device to remove.
 *
 * Removes and unregisters the provided SSAM client device.
 */
void ssam_device_remove(struct ssam_device *sdev)
{}
EXPORT_SYMBOL_GPL();

/**
 * ssam_device_id_compatible() - Check if a device ID matches a UID.
 * @id:  The device ID as potential match.
 * @uid: The device UID matching against.
 *
 * Check if the given ID is a match for the given UID, i.e. if a device with
 * the provided UID is compatible to the given ID following the match rules
 * described in its &ssam_device_id.match_flags member.
 *
 * Return: Returns %true if the given UID is compatible to the match rule
 * described by the given ID, %false otherwise.
 */
static bool ssam_device_id_compatible(const struct ssam_device_id *id,
				      struct ssam_device_uid uid)
{}

/**
 * ssam_device_id_is_null() - Check if a device ID is null.
 * @id: The device ID to check.
 *
 * Check if a given device ID is null, i.e. all zeros. Used to check for the
 * end of ``MODULE_DEVICE_TABLE(ssam, ...)`` or similar lists.
 *
 * Return: Returns %true if the given ID represents a null ID, %false
 * otherwise.
 */
static bool ssam_device_id_is_null(const struct ssam_device_id *id)
{}

/**
 * ssam_device_id_match() - Find the matching ID table entry for the given UID.
 * @table: The table to search in.
 * @uid:   The UID to matched against the individual table entries.
 *
 * Find the first match for the provided device UID in the provided ID table
 * and return it. Returns %NULL if no match could be found.
 */
const struct ssam_device_id *ssam_device_id_match(const struct ssam_device_id *table,
						  const struct ssam_device_uid uid)
{}
EXPORT_SYMBOL_GPL();

/**
 * ssam_device_get_match() - Find and return the ID matching the device in the
 * ID table of the bound driver.
 * @dev: The device for which to get the matching ID table entry.
 *
 * Find the fist match for the UID of the device in the ID table of the
 * currently bound driver and return it. Returns %NULL if the device does not
 * have a driver bound to it, the driver does not have match_table (i.e. it is
 * %NULL), or there is no match in the driver's match_table.
 *
 * This function essentially calls ssam_device_id_match() with the ID table of
 * the bound device driver and the UID of the device.
 *
 * Return: Returns the first match for the UID of the device in the device
 * driver's match table, or %NULL if no such match could be found.
 */
const struct ssam_device_id *ssam_device_get_match(const struct ssam_device *dev)
{}
EXPORT_SYMBOL_GPL();

/**
 * ssam_device_get_match_data() - Find the ID matching the device in the
 * ID table of the bound driver and return its ``driver_data`` member.
 * @dev: The device for which to get the match data.
 *
 * Find the fist match for the UID of the device in the ID table of the
 * corresponding driver and return its driver_data. Returns %NULL if the
 * device does not have a driver bound to it, the driver does not have
 * match_table (i.e. it is %NULL), there is no match in the driver's
 * match_table, or the match does not have any driver_data.
 *
 * This function essentially calls ssam_device_get_match() and, if any match
 * could be found, returns its ``struct ssam_device_id.driver_data`` member.
 *
 * Return: Returns the driver data associated with the first match for the UID
 * of the device in the device driver's match table, or %NULL if no such match
 * could be found.
 */
const void *ssam_device_get_match_data(const struct ssam_device *dev)
{}
EXPORT_SYMBOL_GPL();

static int ssam_bus_match(struct device *dev, const struct device_driver *drv)
{}

static int ssam_bus_probe(struct device *dev)
{}

static void ssam_bus_remove(struct device *dev)
{}

static const struct bus_type ssam_bus_type =;

/**
 * __ssam_device_driver_register() - Register a SSAM client device driver.
 * @sdrv:  The driver to register.
 * @owner: The module owning the provided driver.
 *
 * Please refer to the ssam_device_driver_register() macro for the normal way
 * to register a driver from inside its owning module.
 */
int __ssam_device_driver_register(struct ssam_device_driver *sdrv,
				  struct module *owner)
{}
EXPORT_SYMBOL_GPL();

/**
 * ssam_device_driver_unregister - Unregister a SSAM device driver.
 * @sdrv: The driver to unregister.
 */
void ssam_device_driver_unregister(struct ssam_device_driver *sdrv)
{}
EXPORT_SYMBOL_GPL();


/* -- Bus registration. ----------------------------------------------------- */

/**
 * ssam_bus_register() - Register and set-up the SSAM client device bus.
 */
int ssam_bus_register(void)
{}

/**
 * ssam_bus_unregister() - Unregister the SSAM client device bus.
 */
void ssam_bus_unregister(void)
{}


/* -- Helpers for controller and hub devices. ------------------------------- */

static int ssam_device_uid_from_string(const char *str, struct ssam_device_uid *uid)
{}

static int ssam_get_uid_for_node(struct fwnode_handle *node, struct ssam_device_uid *uid)
{}

static int ssam_add_client_device(struct device *parent, struct ssam_controller *ctrl,
				  struct fwnode_handle *node)
{}

/**
 * __ssam_register_clients() - Register client devices defined under the
 * given firmware node as children of the given device.
 * @parent: The parent device under which clients should be registered.
 * @ctrl: The controller with which client should be registered.
 * @node: The firmware node holding definitions of the devices to be added.
 *
 * Register all clients that have been defined as children of the given root
 * firmware node as children of the given parent device. The respective child
 * firmware nodes will be associated with the correspondingly created child
 * devices.
 *
 * The given controller will be used to instantiate the new devices. See
 * ssam_device_add() for details.
 *
 * Note that, generally, the use of either ssam_device_register_clients() or
 * ssam_register_clients() should be preferred as they directly use the
 * firmware node and/or controller associated with the given device. This
 * function is only intended for use when different device specifications (e.g.
 * ACPI and firmware nodes) need to be combined (as is done in the platform hub
 * of the device registry).
 *
 * Return: Returns zero on success, nonzero on failure.
 */
int __ssam_register_clients(struct device *parent, struct ssam_controller *ctrl,
			    struct fwnode_handle *node)
{}
EXPORT_SYMBOL_GPL();

static int ssam_remove_device(struct device *dev, void *_data)
{}

/**
 * ssam_remove_clients() - Remove SSAM client devices registered as direct
 * children under the given parent device.
 * @dev: The (parent) device to remove all direct clients for.
 *
 * Remove all SSAM client devices registered as direct children under the given
 * device. Note that this only accounts for direct children of the device.
 * Refer to ssam_device_add()/ssam_device_remove() for more details.
 */
void ssam_remove_clients(struct device *dev)
{}
EXPORT_SYMBOL_GPL();