Skip to content

Commit

Permalink
platform/chrome: cros_usbpd_notify: Add driver data struct
Browse files Browse the repository at this point in the history
Introduce a device driver data structure, cros_usbpd_notify_data, in
which we can store the notifier block object and pointers to the struct
cros_ec_device and struct device objects.

This will make it more convenient to access these pointers when
executing both platform and ACPI callbacks.

Signed-off-by: Prashant Malani <pmalani@chromium.org>
Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Signed-off-by: Benson Leung <bleung@chromium.org>
  • Loading branch information
Prashant Malani authored and Benson Leung committed Mar 17, 2020
1 parent 92e399c commit f5d84a2
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions drivers/platform/chrome/cros_usbpd_notify.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@

static BLOCKING_NOTIFIER_HEAD(cros_usbpd_notifier_list);

struct cros_usbpd_notify_data {
struct device *dev;
struct cros_ec_device *ec;
struct notifier_block nb;
};

/**
* cros_usbpd_register_notify - Register a notifier callback for PD events.
* @nb: Notifier block pointer to register
Expand Down Expand Up @@ -98,18 +104,21 @@ static int cros_usbpd_notify_probe_plat(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct cros_ec_dev *ecdev = dev_get_drvdata(dev->parent);
struct notifier_block *nb;
struct cros_usbpd_notify_data *pdnotify;
int ret;

nb = devm_kzalloc(dev, sizeof(*nb), GFP_KERNEL);
if (!nb)
pdnotify = devm_kzalloc(dev, sizeof(*pdnotify), GFP_KERNEL);
if (!pdnotify)
return -ENOMEM;

nb->notifier_call = cros_usbpd_notify_plat;
dev_set_drvdata(dev, nb);
pdnotify->dev = dev;
pdnotify->ec = ecdev->ec_dev;
pdnotify->nb.notifier_call = cros_usbpd_notify_plat;

dev_set_drvdata(dev, pdnotify);

ret = blocking_notifier_chain_register(&ecdev->ec_dev->event_notifier,
nb);
&pdnotify->nb);
if (ret < 0) {
dev_err(dev, "Failed to register notifier\n");
return ret;
Expand All @@ -122,10 +131,11 @@ static int cros_usbpd_notify_remove_plat(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct cros_ec_dev *ecdev = dev_get_drvdata(dev->parent);
struct notifier_block *nb =
(struct notifier_block *)dev_get_drvdata(dev);
struct cros_usbpd_notify_data *pdnotify =
(struct cros_usbpd_notify_data *)dev_get_drvdata(dev);

blocking_notifier_chain_unregister(&ecdev->ec_dev->event_notifier, nb);
blocking_notifier_chain_unregister(&ecdev->ec_dev->event_notifier,
&pdnotify->nb);

return 0;
}
Expand Down

0 comments on commit f5d84a2

Please sign in to comment.