Created
October 25, 2022 10:37
-
-
Save Demon000/d55ab249656a6f14a798159b5bd12de7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 5.10 compatibility */ | |
#include <linux/regulator/driver.h> | |
#include "../../../drivers/regulator/internal.h" | |
struct regulator_bulk_devres { | |
struct regulator_bulk_data *consumers; | |
int num_consumers; | |
}; | |
static int devm_regulator_bulk_match(struct device *dev, void *res, | |
void *data) | |
{ | |
struct regulator_bulk_devres *match = res; | |
struct regulator_bulk_data *target = data; | |
/* | |
* We check the put uses same consumer list as the get did. | |
* We _could_ scan all entries in consumer array and check the | |
* regulators match but ATM I don't see the need. We can change this | |
* later if needed. | |
*/ | |
return match->consumers == target; | |
} | |
static void devm_regulator_bulk_release(struct device *dev, void *res) | |
{ | |
struct regulator_bulk_devres *devres = res; | |
regulator_bulk_free(devres->num_consumers, devres->consumers); | |
} | |
static void devm_regulator_bulk_disable(void *res) | |
{ | |
struct regulator_bulk_devres *devres = res; | |
int i; | |
for (i = 0; i < devres->num_consumers; i++) | |
regulator_disable(devres->consumers[i].consumer); | |
} | |
/** | |
* devm_regulator_bulk_put - Resource managed regulator_bulk_put() | |
* @consumers: consumers to free | |
* | |
* Deallocate regulators allocated with devm_regulator_bulk_get(). Normally | |
* this function will not need to be called and the resource management | |
* code will ensure that the resource is freed. | |
*/ | |
static | |
void devm_regulator_bulk_put(struct regulator_bulk_data *consumers) | |
{ | |
int rc; | |
struct regulator *regulator = consumers[0].consumer; | |
rc = devres_release(regulator->dev, devm_regulator_bulk_release, | |
devm_regulator_bulk_match, consumers); | |
if (rc != 0) | |
WARN_ON(rc); | |
} | |
/** | |
* devm_regulator_bulk_get_enable - managed get'n enable multiple regulators | |
* | |
* @dev: device to supply | |
* @num_consumers: number of consumers to register | |
* @id: list of supply names or regulator IDs | |
* | |
* @return 0 on success, an errno on failure. | |
* | |
* This helper function allows drivers to get several regulator | |
* consumers in one operation with management, the regulators will | |
* automatically be freed when the device is unbound. If any of the | |
* regulators cannot be acquired then any regulators that were | |
* allocated will be freed before returning to the caller. | |
*/ | |
static | |
int devm_regulator_bulk_get_enable(struct device *dev, int num_consumers, | |
const char * const *id) | |
{ | |
struct regulator_bulk_devres *devres; | |
struct regulator_bulk_data *consumers; | |
int i, ret; | |
devres = devm_kmalloc(dev, sizeof(*devres), GFP_KERNEL); | |
if (!devres) | |
return -ENOMEM; | |
devres->consumers = devm_kcalloc(dev, num_consumers, sizeof(*consumers), | |
GFP_KERNEL); | |
consumers = devres->consumers; | |
if (!consumers) | |
return -ENOMEM; | |
devres->num_consumers = num_consumers; | |
for (i = 0; i < num_consumers; i++) | |
consumers[i].supply = id[i]; | |
ret = devm_regulator_bulk_get(dev, num_consumers, consumers); | |
if (ret) | |
return ret; | |
for (i = 0; i < num_consumers; i++) { | |
ret = regulator_enable(consumers[i].consumer); | |
if (ret) | |
goto unwind; | |
} | |
ret = devm_add_action(dev, devm_regulator_bulk_disable, devres); | |
if (!ret) | |
return 0; | |
unwind: | |
while (--i >= 0) | |
regulator_disable(consumers[i].consumer); | |
devm_regulator_bulk_put(consumers); | |
return ret; | |
} | |
static int iio_device_id(struct iio_dev *indio_dev) | |
{ | |
return indio_dev->id; | |
} | |
#include <linux/slab.h> | |
#define IIO_DMA_MINALIGN ARCH_KMALLOC_MINALIGN | |
/* end 5.10 compatibility */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment