Source
x
* mux_control_deselect() - Deselect the previously selected multiplexer state.
// SPDX-License-Identifier: GPL-2.0
/*
* Multiplexer subsystem
*
* Copyright (C) 2017 Axentia Technologies AB
*
* Author: Peter Rosin <peda@axentia.se>
*/
/*
* The idle-as-is "state" is not an actual state that may be selected, it
* only implies that the state should not be changed. So, use that state
* as indication that the cached state of the multiplexer is unknown.
*/
static struct class mux_class = {
.name = "mux",
.owner = THIS_MODULE,
};
static DEFINE_IDA(mux_ida);
static int __init mux_init(void)
{
ida_init(&mux_ida);
return class_register(&mux_class);
}
static void __exit mux_exit(void)
{
class_unregister(&mux_class);
ida_destroy(&mux_ida);
}
static void mux_chip_release(struct device *dev)
{
struct mux_chip *mux_chip = to_mux_chip(dev);
ida_simple_remove(&mux_ida, mux_chip->id);
kfree(mux_chip);
}
static const struct device_type mux_type = {
.name = "mux-chip",
.release = mux_chip_release,
};
/**
* mux_chip_alloc() - Allocate a mux-chip.
* @dev: The parent device implementing the mux interface.
* @controllers: The number of mux controllers to allocate for this chip.
* @sizeof_priv: Size of extra memory area for private use by the caller.
*
* After allocating the mux-chip with the desired number of mux controllers
* but before registering the chip, the mux driver is required to configure
* the number of valid mux states in the mux_chip->mux[N].states members and
* the desired idle state in the returned mux_chip->mux[N].idle_state members.
* The default idle state is MUX_IDLE_AS_IS. The mux driver also needs to
* provide a pointer to the operations struct in the mux_chip->ops member
* before registering the mux-chip with mux_chip_register.
*
* Return: A pointer to the new mux-chip, or an ERR_PTR with a negative errno.
*/
struct mux_chip *mux_chip_alloc(struct device *dev,
unsigned int controllers, size_t sizeof_priv)
{
struct mux_chip *mux_chip;
int i;
if (WARN_ON(!dev || !controllers))
return ERR_PTR(-EINVAL);
mux_chip = kzalloc(sizeof(*mux_chip) +
controllers * sizeof(*mux_chip->mux) +
sizeof_priv, GFP_KERNEL);
if (!mux_chip)
return ERR_PTR(-ENOMEM);