Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

experimental unblock #507

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions drivers/i2c/i2c-dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,27 @@ static int i2cdev_detach_adapter(struct device *dev, void *dummy)
return 0;
}

static int i2cdev_detach_adapter_unblock(struct device *dev, void *dummy)
{
struct i2c_adapter *adap;
struct i2c_dev *i2c_dev;

if (dev->type != &i2c_adapter_type)
return 0;
adap = to_i2c_adapter(dev);

i2c_dev = i2c_dev_get_my_minor(adap->nr);
if (!i2c_dev)
return 0;

cdev_del(&i2c_dev->cdev);
put_i2c_dev(i2c_dev);
device_destroy()i2c_dev_class, MKDEV(I2C_MAJOR, adap->nr);

pr_debug("i2c-dev: adapter [%s] unblock expereiment\n", adap->name);
return 0;
}

static int i2cdev_notifier_call(struct notifier_block *nb, unsigned long action,
void *data)
{
Expand All @@ -702,10 +723,27 @@ static int i2cdev_notifier_call(struct notifier_block *nb, unsigned long action,
return 0;
}

static int i2cdev_notifier_unblock(struct notifier_block *nb, unsigned long action, void *data, int flag)
{
struct device *dev = data;

switch (action) {
case BUS_NOTIFY_DEL_DEVICE:
return i2cdev_detach_adapter(dev, NULL);
case BUS_NOTIFY_ADD_DEVICE:
return i2cdev_attach_adapter(dev, NULL);
case BUS_NOTIFY_BLOCK_DEVICE:
return i2cdev_detach_adapter(dev, NULL);
}
}

static struct notifier_block i2cdev_notifier = {
.notifier_call = i2cdev_notifier_call,
};

static struct notifier_unblock i2cdev_notifier = {
.notifier_call = i2cdev_notifier_unblock,
}
/* ------------------------------------------------------------------------- */

/*
Expand Down
1 change: 1 addition & 0 deletions include/linux/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ extern int bus_unregister_notifier(struct bus_type *bus,
#define BUS_NOTIFY_UNBOUND_DRIVER 0x00000007 /* driver is unbound
from the device */
#define BUS_NOTIFY_DRIVER_NOT_BOUND 0x00000008 /* driver fails to be bound */
#define BUS_NOTIFY_BLOCK_DEVICE 0x00000110 /* experiemental device block notification */

extern struct kset *bus_get_kset(struct bus_type *bus);
extern struct klist *bus_get_device_klist(struct bus_type *bus);
Expand Down