api/gpio: Controller may not support GPIO_INT at all

It's not an error if a driver does not implement callback related
function. Let's return -ENOTSUP relevantly.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
This commit is contained in:
Tomasz Bursztyka 2018-11-15 09:52:01 +01:00 committed by Anas Nashif
commit 04d9d57a63
2 changed files with 20 additions and 7 deletions

View file

@ -29,20 +29,17 @@ Z_SYSCALL_HANDLER(gpio_read, port, access_op, pin, value)
Z_SYSCALL_HANDLER(gpio_enable_callback, port, access_op, pin)
{
Z_OOPS(Z_SYSCALL_DRIVER_GPIO(port, enable_callback));
return _impl_gpio_enable_callback((struct device *)port, access_op,
pin);
}
Z_SYSCALL_HANDLER(gpio_disable_callback, port, access_op, pin)
{
Z_OOPS(Z_SYSCALL_DRIVER_GPIO(port, disable_callback));
return _impl_gpio_disable_callback((struct device *)port, access_op,
pin);
}
Z_SYSCALL_HANDLER(gpio_get_pending_int, port)
{
Z_OOPS(Z_SYSCALL_DRIVER_GPIO(port, get_pending_int));
return _impl_gpio_get_pending_int((struct device *)port);
}

View file

@ -169,6 +169,10 @@ static inline int _impl_gpio_enable_callback(struct device *port,
const struct gpio_driver_api *api =
(const struct gpio_driver_api *)port->driver_api;
if (!api->enable_callback) {
return -ENOTSUP;
}
return api->enable_callback(port, access_op, pin);
}
@ -181,6 +185,10 @@ static inline int _impl_gpio_disable_callback(struct device *port,
const struct gpio_driver_api *api =
(const struct gpio_driver_api *)port->driver_api;
if (!api->disable_callback) {
return -ENOTSUP;
}
return api->disable_callback(port, access_op, pin);
}
/**
@ -260,7 +268,9 @@ static inline int gpio_add_callback(struct device *port,
const struct gpio_driver_api *api =
(const struct gpio_driver_api *)port->driver_api;
__ASSERT(callback, "Callback pointer should not be NULL");
if (!api->manage_callback) {
return -ENOTSUP;
}
return api->manage_callback(port, callback, true);
}
@ -280,7 +290,9 @@ static inline int gpio_remove_callback(struct device *port,
const struct gpio_driver_api *api =
(const struct gpio_driver_api *)port->driver_api;
__ASSERT(callback, "Callback pointer should not be NULL");
if (!api->manage_callback) {
return -ENOTSUP;
}
return api->manage_callback(port, callback, false);
}
@ -405,9 +417,13 @@ __syscall int gpio_get_pending_int(struct device *dev);
*/
static inline int _impl_gpio_get_pending_int(struct device *dev)
{
struct gpio_driver_api *api;
const struct gpio_driver_api *api =
(const struct gpio_driver_api *)dev->driver_api;
if (!api->get_pending_int) {
return -ENOTSUP;
}
api = (struct gpio_driver_api *)dev->driver_api;
return api->get_pending_int(dev);
}