// SPDX-License-Identifier: GPL-2.0-only /* * devfreq-event: a framework to provide raw data and events of devfreq devices * * Copyright (C) 2015 Samsung Electronics * Author: Chanwoo Choi <cw00.choi@samsung.com> * * This driver is based on drivers/devfreq/devfreq.c.
*/
/** * devfreq_event_enable_edev() - Enable the devfreq-event dev and increase * the enable_count of devfreq-event dev. * @edev : the devfreq-event device * * Note that this function increase the enable_count and enable the * devfreq-event device. The devfreq-event device should be enabled before * using it by devfreq device.
*/ int devfreq_event_enable_edev(struct devfreq_event_dev *edev)
{ int ret = 0;
if (!edev || !edev->desc) return -EINVAL;
mutex_lock(&edev->lock); if (edev->desc->ops && edev->desc->ops->enable
&& edev->enable_count == 0) {
ret = edev->desc->ops->enable(edev); if (ret < 0) goto err;
}
edev->enable_count++;
err:
mutex_unlock(&edev->lock);
/** * devfreq_event_disable_edev() - Disable the devfreq-event dev and decrease * the enable_count of the devfreq-event dev. * @edev : the devfreq-event device * * Note that this function decrease the enable_count and disable the * devfreq-event device. After the devfreq-event device is disabled, * devfreq device can't use the devfreq-event device for get/set/reset * operations.
*/ int devfreq_event_disable_edev(struct devfreq_event_dev *edev)
{ int ret = 0;
if (!edev || !edev->desc) return -EINVAL;
mutex_lock(&edev->lock); if (edev->enable_count <= 0) {
dev_warn(&edev->dev, "unbalanced enable_count\n");
ret = -EIO; goto err;
}
if (edev->desc->ops && edev->desc->ops->disable
&& edev->enable_count == 1) {
ret = edev->desc->ops->disable(edev); if (ret < 0) goto err;
}
edev->enable_count--;
err:
mutex_unlock(&edev->lock);
/** * devfreq_event_is_enabled() - Check whether devfreq-event dev is enabled or * not. * @edev : the devfreq-event device * * Note that this function check whether devfreq-event dev is enabled or not. * If return true, the devfreq-event dev is enabeld. If return false, the * devfreq-event dev is disabled.
*/ bool devfreq_event_is_enabled(struct devfreq_event_dev *edev)
{ bool enabled = false;
/** * devfreq_event_set_event() - Set event to devfreq-event dev to start. * @edev : the devfreq-event device * * Note that this function set the event to the devfreq-event device to start * for getting the event data which could be various event type.
*/ int devfreq_event_set_event(struct devfreq_event_dev *edev)
{ int ret;
if (!edev || !edev->desc) return -EINVAL;
if (!edev->desc->ops || !edev->desc->ops->set_event) return -EINVAL;
if (!devfreq_event_is_enabled(edev)) return -EPERM;
mutex_lock(&edev->lock);
ret = edev->desc->ops->set_event(edev);
mutex_unlock(&edev->lock);
/** * devfreq_event_get_event() - Get {load|total}_count from devfreq-event dev. * @edev : the devfreq-event device * @edata : the calculated data of devfreq-event device * * Note that this function get the calculated event data from devfreq-event dev * after stoping the progress of whole sequence of devfreq-event dev.
*/ int devfreq_event_get_event(struct devfreq_event_dev *edev, struct devfreq_event_data *edata)
{ int ret;
if (!edev || !edev->desc) return -EINVAL;
if (!edev->desc->ops || !edev->desc->ops->get_event) return -EINVAL;
if (!devfreq_event_is_enabled(edev)) return -EINVAL;
edata->total_count = edata->load_count = 0;
mutex_lock(&edev->lock);
ret = edev->desc->ops->get_event(edev, edata); if (ret < 0)
edata->total_count = edata->load_count = 0;
mutex_unlock(&edev->lock);
/** * devfreq_event_reset_event() - Reset all opeations of devfreq-event dev. * @edev : the devfreq-event device * * Note that this function stop all operations of devfreq-event dev and reset * the current event data to make the devfreq-event device into initial state.
*/ int devfreq_event_reset_event(struct devfreq_event_dev *edev)
{ int ret = 0;
if (!edev || !edev->desc) return -EINVAL;
if (!devfreq_event_is_enabled(edev)) return -EPERM;
mutex_lock(&edev->lock); if (edev->desc->ops && edev->desc->ops->reset)
ret = edev->desc->ops->reset(edev);
mutex_unlock(&edev->lock);
/** * devfreq_event_get_edev_by_phandle() - Get the devfreq-event dev from * devicetree. * @dev : the pointer to the given device * @phandle_name: name of property holding a phandle value * @index : the index into list of devfreq-event device * * Note that this function return the pointer of devfreq-event device.
*/ struct devfreq_event_dev *devfreq_event_get_edev_by_phandle(struct device *dev, constchar *phandle_name, int index)
{ struct device_node *node; struct devfreq_event_dev *edev;
if (!dev->of_node || !phandle_name) return ERR_PTR(-EINVAL);
node = of_parse_phandle(dev->of_node, phandle_name, index); if (!node) return ERR_PTR(-ENODEV);
/** * devfreq_event_get_edev_count() - Get the count of devfreq-event dev * @dev : the pointer to the given device * @phandle_name: name of property holding a phandle value * * Note that this function return the count of devfreq-event devices.
*/ int devfreq_event_get_edev_count(struct device *dev, constchar *phandle_name)
{ int count;
if (!dev->of_node || !phandle_name) {
dev_err(dev, "device does not have a device node entry\n"); return -EINVAL;
}
count = of_property_count_elems_of_size(dev->of_node, phandle_name, sizeof(u32)); if (count < 0) {
dev_err(dev, "failed to get the count of devfreq-event in %pOF node\n",
dev->of_node); return count;
}
/** * devfreq_event_add_edev() - Add new devfreq-event device. * @dev : the device owning the devfreq-event device being created * @desc : the devfreq-event device's descriptor which include essential * data for devfreq-event device. * * Note that this function add new devfreq-event device to devfreq-event class * list and register the device of the devfreq-event device.
*/ struct devfreq_event_dev *devfreq_event_add_edev(struct device *dev, struct devfreq_event_desc *desc)
{ struct devfreq_event_dev *edev; static atomic_t event_no = ATOMIC_INIT(-1); int ret;
if (!dev || !desc) return ERR_PTR(-EINVAL);
if (!desc->name || !desc->ops) return ERR_PTR(-EINVAL);
if (!desc->ops->set_event || !desc->ops->get_event) return ERR_PTR(-EINVAL);
edev = kzalloc(sizeof(struct devfreq_event_dev), GFP_KERNEL); if (!edev) return ERR_PTR(-ENOMEM);
/** * devfreq_event_remove_edev() - Remove the devfreq-event device registered. * @edev : the devfreq-event device * * Note that this function removes the registered devfreq-event device.
*/ int devfreq_event_remove_edev(struct devfreq_event_dev *edev)
{ if (!edev) return -EINVAL;
/** * devm_devfreq_event_add_edev() - Resource-managed devfreq_event_add_edev() * @dev : the device owning the devfreq-event device being created * @desc : the devfreq-event device's descriptor which include essential * data for devfreq-event device. * * Note that this function manages automatically the memory of devfreq-event * device using device resource management and simplify the free operation * for memory of devfreq-event device.
*/ struct devfreq_event_dev *devm_devfreq_event_add_edev(struct device *dev, struct devfreq_event_desc *desc)
{ struct devfreq_event_dev **ptr, *edev;
ptr = devres_alloc(devm_devfreq_event_release, sizeof(*ptr),
GFP_KERNEL); if (!ptr) return ERR_PTR(-ENOMEM);
/** * devm_devfreq_event_remove_edev()- Resource-managed devfreq_event_remove_edev() * @dev : the device owning the devfreq-event device being created * @edev : the devfreq-event device * * Note that this function manages automatically the memory of devfreq-event * device using device resource management.
*/ void devm_devfreq_event_remove_edev(struct device *dev, struct devfreq_event_dev *edev)
{
WARN_ON(devres_release(dev, devm_devfreq_event_release,
devm_devfreq_event_match, edev));
}
EXPORT_SYMBOL_GPL(devm_devfreq_event_remove_edev);
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.