iio: core: pass parent device as parameter during allocation
The change passes the parent device to the iio_device_alloc() call. This also updates the devm_iio_device_alloc() call to consider the device object as the parent device by default. Having it passed like this, should ensure that any IIO device object already has a device object as parent, allowing for neater control, like passing the 'indio_dev' object for other stuff [like buffers/triggers/etc], and potentially creating iiom_xxx(indio_dev) functions. With this patch, only the 'drivers/platform/x86/toshiba_acpi.c' needs an update to pass the parent object as a parameter. In the next patch all devm_iio_device_alloc() calls will be handled. Acked-by: Andy Shevchenko <andy.shevchenko@gmail.com> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This commit is contained in:
parent
9ca39411f9
commit
78289b4a58
@ -566,6 +566,13 @@ static struct iio_sw_device *iio_dummy_probe(const char *name)
|
|||||||
struct iio_dev *indio_dev;
|
struct iio_dev *indio_dev;
|
||||||
struct iio_dummy_state *st;
|
struct iio_dummy_state *st;
|
||||||
struct iio_sw_device *swd;
|
struct iio_sw_device *swd;
|
||||||
|
struct device *parent = NULL;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* With hardware: Set the parent device.
|
||||||
|
* parent = &spi->dev;
|
||||||
|
* parent = &client->dev;
|
||||||
|
*/
|
||||||
|
|
||||||
swd = kzalloc(sizeof(*swd), GFP_KERNEL);
|
swd = kzalloc(sizeof(*swd), GFP_KERNEL);
|
||||||
if (!swd) {
|
if (!swd) {
|
||||||
@ -580,7 +587,7 @@ static struct iio_sw_device *iio_dummy_probe(const char *name)
|
|||||||
* It also has a region (accessed by iio_priv()
|
* It also has a region (accessed by iio_priv()
|
||||||
* for chip specific state information.
|
* for chip specific state information.
|
||||||
*/
|
*/
|
||||||
indio_dev = iio_device_alloc(sizeof(*st));
|
indio_dev = iio_device_alloc(parent, sizeof(*st));
|
||||||
if (!indio_dev) {
|
if (!indio_dev) {
|
||||||
ret = -ENOMEM;
|
ret = -ENOMEM;
|
||||||
goto error_ret;
|
goto error_ret;
|
||||||
@ -590,11 +597,6 @@ static struct iio_sw_device *iio_dummy_probe(const char *name)
|
|||||||
mutex_init(&st->lock);
|
mutex_init(&st->lock);
|
||||||
|
|
||||||
iio_dummy_init_device(indio_dev);
|
iio_dummy_init_device(indio_dev);
|
||||||
/*
|
|
||||||
* With hardware: Set the parent device.
|
|
||||||
* indio_dev->dev.parent = &spi->dev;
|
|
||||||
* indio_dev->dev.parent = &client->dev;
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Make the iio_dev struct available to remove function.
|
* Make the iio_dev struct available to remove function.
|
||||||
|
@ -1493,7 +1493,7 @@ struct device_type iio_device_type = {
|
|||||||
* iio_device_alloc() - allocate an iio_dev from a driver
|
* iio_device_alloc() - allocate an iio_dev from a driver
|
||||||
* @sizeof_priv: Space to allocate for private structure.
|
* @sizeof_priv: Space to allocate for private structure.
|
||||||
**/
|
**/
|
||||||
struct iio_dev *iio_device_alloc(int sizeof_priv)
|
struct iio_dev *iio_device_alloc(struct device *parent, int sizeof_priv)
|
||||||
{
|
{
|
||||||
struct iio_dev *dev;
|
struct iio_dev *dev;
|
||||||
size_t alloc_size;
|
size_t alloc_size;
|
||||||
@ -1510,6 +1510,7 @@ struct iio_dev *iio_device_alloc(int sizeof_priv)
|
|||||||
if (!dev)
|
if (!dev)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
dev->dev.parent = parent;
|
||||||
dev->dev.groups = dev->groups;
|
dev->dev.groups = dev->groups;
|
||||||
dev->dev.type = &iio_device_type;
|
dev->dev.type = &iio_device_type;
|
||||||
dev->dev.bus = &iio_bus_type;
|
dev->dev.bus = &iio_bus_type;
|
||||||
@ -1551,7 +1552,7 @@ static void devm_iio_device_release(struct device *dev, void *res)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* devm_iio_device_alloc - Resource-managed iio_device_alloc()
|
* devm_iio_device_alloc - Resource-managed iio_device_alloc()
|
||||||
* @dev: Device to allocate iio_dev for
|
* @parent: Device to allocate iio_dev for, and parent for this IIO device
|
||||||
* @sizeof_priv: Space to allocate for private structure.
|
* @sizeof_priv: Space to allocate for private structure.
|
||||||
*
|
*
|
||||||
* Managed iio_device_alloc. iio_dev allocated with this function is
|
* Managed iio_device_alloc. iio_dev allocated with this function is
|
||||||
@ -1560,7 +1561,7 @@ static void devm_iio_device_release(struct device *dev, void *res)
|
|||||||
* RETURNS:
|
* RETURNS:
|
||||||
* Pointer to allocated iio_dev on success, NULL on failure.
|
* Pointer to allocated iio_dev on success, NULL on failure.
|
||||||
*/
|
*/
|
||||||
struct iio_dev *devm_iio_device_alloc(struct device *dev, int sizeof_priv)
|
struct iio_dev *devm_iio_device_alloc(struct device *parent, int sizeof_priv)
|
||||||
{
|
{
|
||||||
struct iio_dev **ptr, *iio_dev;
|
struct iio_dev **ptr, *iio_dev;
|
||||||
|
|
||||||
@ -1569,10 +1570,10 @@ struct iio_dev *devm_iio_device_alloc(struct device *dev, int sizeof_priv)
|
|||||||
if (!ptr)
|
if (!ptr)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
iio_dev = iio_device_alloc(sizeof_priv);
|
iio_dev = iio_device_alloc(parent, sizeof_priv);
|
||||||
if (iio_dev) {
|
if (iio_dev) {
|
||||||
*ptr = iio_dev;
|
*ptr = iio_dev;
|
||||||
devres_add(dev, ptr);
|
devres_add(parent, ptr);
|
||||||
} else {
|
} else {
|
||||||
devres_free(ptr);
|
devres_free(ptr);
|
||||||
}
|
}
|
||||||
|
@ -3114,7 +3114,7 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev)
|
|||||||
|
|
||||||
toshiba_accelerometer_available(dev);
|
toshiba_accelerometer_available(dev);
|
||||||
if (dev->accelerometer_supported) {
|
if (dev->accelerometer_supported) {
|
||||||
dev->indio_dev = iio_device_alloc(sizeof(*dev));
|
dev->indio_dev = iio_device_alloc(&acpi_dev->dev, sizeof(*dev));
|
||||||
if (!dev->indio_dev) {
|
if (!dev->indio_dev) {
|
||||||
pr_err("Unable to allocate iio device\n");
|
pr_err("Unable to allocate iio device\n");
|
||||||
goto iio_error;
|
goto iio_error;
|
||||||
@ -3124,7 +3124,6 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev)
|
|||||||
|
|
||||||
dev->indio_dev->info = &toshiba_iio_accel_info;
|
dev->indio_dev->info = &toshiba_iio_accel_info;
|
||||||
dev->indio_dev->name = "Toshiba accelerometer";
|
dev->indio_dev->name = "Toshiba accelerometer";
|
||||||
dev->indio_dev->dev.parent = &acpi_dev->dev;
|
|
||||||
dev->indio_dev->modes = INDIO_DIRECT_MODE;
|
dev->indio_dev->modes = INDIO_DIRECT_MODE;
|
||||||
dev->indio_dev->channels = toshiba_iio_accel_channels;
|
dev->indio_dev->channels = toshiba_iio_accel_channels;
|
||||||
dev->indio_dev->num_channels =
|
dev->indio_dev->num_channels =
|
||||||
|
@ -8,7 +8,7 @@ The crucial structure for device drivers in iio is iio_dev.
|
|||||||
|
|
||||||
First allocate one using:
|
First allocate one using:
|
||||||
|
|
||||||
struct iio_dev *indio_dev = iio_device_alloc(sizeof(struct chip_state));
|
struct iio_dev *indio_dev = iio_device_alloc(parent, sizeof(struct chip_state));
|
||||||
where chip_state is a structure of local state data for this instance of
|
where chip_state is a structure of local state data for this instance of
|
||||||
the chip.
|
the chip.
|
||||||
|
|
||||||
@ -16,8 +16,6 @@ That data can be accessed using iio_priv(struct iio_dev *).
|
|||||||
|
|
||||||
Then fill in the following:
|
Then fill in the following:
|
||||||
|
|
||||||
- indio_dev->dev.parent
|
|
||||||
Struct device associated with the underlying hardware.
|
|
||||||
- indio_dev->name
|
- indio_dev->name
|
||||||
Name of the device being driven - made available as the name
|
Name of the device being driven - made available as the name
|
||||||
attribute in sysfs.
|
attribute in sysfs.
|
||||||
|
@ -676,7 +676,7 @@ static inline void *iio_device_get_drvdata(const struct iio_dev *indio_dev)
|
|||||||
|
|
||||||
/* Can we make this smaller? */
|
/* Can we make this smaller? */
|
||||||
#define IIO_ALIGN L1_CACHE_BYTES
|
#define IIO_ALIGN L1_CACHE_BYTES
|
||||||
struct iio_dev *iio_device_alloc(int sizeof_priv);
|
struct iio_dev *iio_device_alloc(struct device *parent, int sizeof_priv);
|
||||||
|
|
||||||
static inline void *iio_priv(const struct iio_dev *indio_dev)
|
static inline void *iio_priv(const struct iio_dev *indio_dev)
|
||||||
{
|
{
|
||||||
@ -690,7 +690,7 @@ static inline struct iio_dev *iio_priv_to_dev(void *priv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void iio_device_free(struct iio_dev *indio_dev);
|
void iio_device_free(struct iio_dev *indio_dev);
|
||||||
struct iio_dev *devm_iio_device_alloc(struct device *dev, int sizeof_priv);
|
struct iio_dev *devm_iio_device_alloc(struct device *parent, int sizeof_priv);
|
||||||
struct iio_trigger *devm_iio_trigger_alloc(struct device *dev,
|
struct iio_trigger *devm_iio_trigger_alloc(struct device *dev,
|
||||||
const char *fmt, ...);
|
const char *fmt, ...);
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user