if (drv->name) return strncmp(dev_name(dev), drv->name,
SPMI_NAME_SIZE) == 0;
return 0;
}
/** * spmi_device_add() - add a device previously constructed via spmi_device_alloc() * @sdev: spmi_device to be added
*/ int spmi_device_add(struct spmi_device *sdev)
{ struct spmi_controller *ctrl = sdev->ctrl; int err;
/** * spmi_ext_register_read() - extended register read * @sdev: SPMI device. * @addr: slave register address (8-bit address). * @buf: buffer to be populated with data from the Slave. * @len: the request number of bytes to read (up to 16 bytes). * * Reads up to 16 bytes of data from the extended register space on a * Slave device.
*/ int spmi_ext_register_read(struct spmi_device *sdev, u8 addr, u8 *buf,
size_t len)
{ /* 8-bit register address, up to 16 bytes */ if (len == 0 || len > 16) return -EINVAL;
/** * spmi_ext_register_readl() - extended register read long * @sdev: SPMI device. * @addr: slave register address (16-bit address). * @buf: buffer to be populated with data from the Slave. * @len: the request number of bytes to read (up to 8 bytes). * * Reads up to 8 bytes of data from the extended register space on a * Slave device using 16-bit address.
*/ int spmi_ext_register_readl(struct spmi_device *sdev, u16 addr, u8 *buf,
size_t len)
{ /* 16-bit register address, up to 8 bytes */ if (len == 0 || len > 8) return -EINVAL;
/** * spmi_register_zero_write() - register zero write * @sdev: SPMI device. * @data: the data to be written to register 0 (7-bits). * * Writes data to register 0 of the Slave device.
*/ int spmi_register_zero_write(struct spmi_device *sdev, u8 data)
{ return spmi_write_cmd(sdev->ctrl, SPMI_CMD_ZERO_WRITE, sdev->usid, 0,
&data, 1);
}
EXPORT_SYMBOL_GPL(spmi_register_zero_write);
/** * spmi_ext_register_write() - extended register write * @sdev: SPMI device. * @addr: slave register address (8-bit address). * @buf: buffer containing the data to be transferred to the Slave. * @len: the request number of bytes to read (up to 16 bytes). * * Writes up to 16 bytes of data to the extended register space of a * Slave device.
*/ int spmi_ext_register_write(struct spmi_device *sdev, u8 addr, const u8 *buf,
size_t len)
{ /* 8-bit register address, up to 16 bytes */ if (len == 0 || len > 16) return -EINVAL;
/** * spmi_ext_register_writel() - extended register write long * @sdev: SPMI device. * @addr: slave register address (16-bit address). * @buf: buffer containing the data to be transferred to the Slave. * @len: the request number of bytes to read (up to 8 bytes). * * Writes up to 8 bytes of data to the extended register space of a * Slave device using 16-bit address.
*/ int spmi_ext_register_writel(struct spmi_device *sdev, u16 addr, const u8 *buf,
size_t len)
{ /* 4-bit Slave Identifier, 16-bit register address, up to 8 bytes */ if (len == 0 || len > 8) return -EINVAL;
/** * spmi_command_reset() - sends RESET command to the specified slave * @sdev: SPMI device. * * The Reset command initializes the Slave and forces all registers to * their reset values. The Slave shall enter the STARTUP state after * receiving a Reset command.
*/ int spmi_command_reset(struct spmi_device *sdev)
{ return spmi_cmd(sdev->ctrl, SPMI_CMD_RESET, sdev->usid);
}
EXPORT_SYMBOL_GPL(spmi_command_reset);
/** * spmi_command_sleep() - sends SLEEP command to the specified SPMI device * @sdev: SPMI device. * * The Sleep command causes the Slave to enter the user defined SLEEP state.
*/ int spmi_command_sleep(struct spmi_device *sdev)
{ return spmi_cmd(sdev->ctrl, SPMI_CMD_SLEEP, sdev->usid);
}
EXPORT_SYMBOL_GPL(spmi_command_sleep);
/** * spmi_command_wakeup() - sends WAKEUP command to the specified SPMI device * @sdev: SPMI device. * * The Wakeup command causes the Slave to move from the SLEEP state to * the ACTIVE state.
*/ int spmi_command_wakeup(struct spmi_device *sdev)
{ return spmi_cmd(sdev->ctrl, SPMI_CMD_WAKEUP, sdev->usid);
}
EXPORT_SYMBOL_GPL(spmi_command_wakeup);
/** * spmi_command_shutdown() - sends SHUTDOWN command to the specified SPMI device * @sdev: SPMI device. * * The Shutdown command causes the Slave to enter the SHUTDOWN state.
*/ int spmi_command_shutdown(struct spmi_device *sdev)
{ return spmi_cmd(sdev->ctrl, SPMI_CMD_SHUTDOWN, sdev->usid);
}
EXPORT_SYMBOL_GPL(spmi_command_shutdown);
/** * spmi_find_device_by_of_node() - look up an SPMI device from a device node * * @np: device node * * Takes a reference to the embedded struct device which needs to be dropped * after use. * * Returns the struct spmi_device associated with a device node or NULL.
*/ struct spmi_device *spmi_find_device_by_of_node(struct device_node *np)
{ struct device *dev = bus_find_device_by_of_node(&spmi_bus_type, np);
if (dev) return to_spmi_device(dev); return NULL;
}
EXPORT_SYMBOL_GPL(spmi_find_device_by_of_node);
/** * spmi_device_alloc() - Allocate a new SPMI device * @ctrl: associated controller * * Caller is responsible for either calling spmi_device_add() to add the * newly allocated controller, or calling spmi_device_put() to discard it.
*/ struct spmi_device *spmi_device_alloc(struct spmi_controller *ctrl)
{ struct spmi_device *sdev;
sdev = kzalloc(sizeof(*sdev), GFP_KERNEL); if (!sdev) return NULL;
/** * spmi_controller_alloc() - Allocate a new SPMI controller * @parent: parent device * @size: size of private data * * Caller is responsible for either calling spmi_controller_add() to add the * newly allocated controller, or calling spmi_controller_put() to discard it. * The allocated private data region may be accessed via * spmi_controller_get_drvdata()
*/ struct spmi_controller *spmi_controller_alloc(struct device *parent,
size_t size)
{ struct spmi_controller *ctrl; int id;
if (WARN_ON(!parent)) return ERR_PTR(-EINVAL);
ctrl = kzalloc(sizeof(*ctrl) + size, GFP_KERNEL); if (!ctrl) return ERR_PTR(-ENOMEM);
id = ida_alloc(&ctrl_ida, GFP_KERNEL); if (id < 0) {
dev_err(parent, "unable to allocate SPMI controller identifier.\n");
spmi_controller_put(ctrl); return ERR_PTR(id);
}
err = spmi_device_add(sdev); if (err) {
dev_err(&sdev->dev, "failure adding device. status %d\n", err);
spmi_device_put(sdev);
}
}
}
/** * spmi_controller_add() - Add an SPMI controller * @ctrl: controller to be registered. * * Register a controller previously allocated via spmi_controller_alloc() with * the SPMI core.
*/ int spmi_controller_add(struct spmi_controller *ctrl)
{ int ret;
/* Can't register until after driver model init */ if (WARN_ON(!is_registered)) return -EAGAIN;
ret = device_add(&ctrl->dev); if (ret) return ret;
if (IS_ENABLED(CONFIG_OF))
of_spmi_register_devices(ctrl);
/* Remove a device associated with a controller */ staticint spmi_ctrl_remove_device(struct device *dev, void *data)
{ struct spmi_device *spmidev = to_spmi_device(dev);
if (dev->type == &spmi_dev_type)
spmi_device_remove(spmidev); return 0;
}
/** * spmi_controller_remove(): remove an SPMI controller * @ctrl: controller to remove * * Remove a SPMI controller. Caller is responsible for calling * spmi_controller_put() to discard the allocated controller.
*/ void spmi_controller_remove(struct spmi_controller *ctrl)
{ if (!ctrl) return;
/** * __spmi_driver_register() - Register client driver with SPMI core * @sdrv: client driver to be associated with client-device. * @owner: module owner * * This API will register the client driver with the SPMI framework. * It is typically called from the driver's module-init function.
*/ int __spmi_driver_register(struct spmi_driver *sdrv, struct module *owner)
{
sdrv->driver.bus = &spmi_bus_type;
sdrv->driver.owner = owner; return driver_register(&sdrv->driver);
}
EXPORT_SYMBOL_GPL(__spmi_driver_register);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.