ioexpander/gpio:Add gpio_pin_register_byname

This commit is contained in:
David Sidrane 2022-10-04 04:54:23 -07:00 committed by Xiang Xiao
parent bc605962b8
commit ac50b3a473
2 changed files with 160 additions and 3 deletions

View File

@ -546,14 +546,57 @@ static int gpio_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
* Register GPIO pin device driver at /dev/gpioN, where N is the provided * Register GPIO pin device driver at /dev/gpioN, where N is the provided
* minor number. * minor number.
* *
* Input Parameters:
* dev - A pointer to a gpio_dev_s
* minor - An integer value to be concatenated with '/dev/gpio'
* to form the device name.
*
* Returned Value:
* Zero on success; A negated errno value is returned on a failure
* all error values returned by inode_reserve:
*
* EINVAL - 'path' is invalid for this operation
* EEXIST - An inode already exists at 'path'
* ENOMEM - Failed to allocate in-memory resources for the operation
*
****************************************************************************/ ****************************************************************************/
int gpio_pin_register(FAR struct gpio_dev_s *dev, int minor) int gpio_pin_register(FAR struct gpio_dev_s *dev, int minor)
{
char devname[32];
snprintf(devname, sizeof(devname), "gpio%u", (unsigned int)minor);
return gpio_pin_register_byname(dev, devname);
}
/****************************************************************************
* Name: gpio_pin_register_byname
*
* Description:
* Register GPIO pin device driver with it's pin name.
*
* Input Parameters:
* dev - A pointer to a gpio_dev_s
* pinname - A pointer to the name to be concatenated with '/dev/'
* to form the device name.
*
* Returned Value:
* Zero on success; A negated errno value is returned on a failure
* all error values returned by inode_reserve:
*
* EINVAL - 'path' is invalid for this operation
* EEXIST - An inode already exists at 'path'
* ENOMEM - Failed to allocate in-memory resources for the operation
*
****************************************************************************/
int gpio_pin_register_byname(FAR struct gpio_dev_s *dev,
FAR const char *pinname)
{ {
char devname[32]; char devname[32];
int ret; int ret;
DEBUGASSERT(dev != NULL && dev->gp_ops != NULL); DEBUGASSERT(dev != NULL && dev->gp_ops != NULL && pinname != NULL);
switch (dev->gp_pintype) switch (dev->gp_pintype)
{ {
@ -590,7 +633,8 @@ int gpio_pin_register(FAR struct gpio_dev_s *dev, int minor)
break; break;
} }
snprintf(devname, sizeof(devname), "/dev/gpio%u", (unsigned int)minor); snprintf(devname, sizeof(devname), "/dev/%s", pinname);
gpioinfo("Registering %s\n", devname); gpioinfo("Registering %s\n", devname);
return register_driver(devname, &g_gpio_drvrops, 0666, dev); return register_driver(devname, &g_gpio_drvrops, 0666, dev);
@ -603,13 +647,54 @@ int gpio_pin_register(FAR struct gpio_dev_s *dev, int minor)
* Unregister GPIO pin device driver at /dev/gpioN, where N is the provided * Unregister GPIO pin device driver at /dev/gpioN, where N is the provided
* minor number. * minor number.
* *
* Input Parameters:
* dev - A pointer to a gpio_dev_s
* minor - An integer value to be concatenated with '/dev/gpio'
* to form the device name.
*
* Returned Value:
* Zero on success; A negated value is returned on a failure
* (all error values returned by inode_remove):
*
* ENOENT - path does not exist.
* EBUSY - Ref count is not 0;
*
****************************************************************************/ ****************************************************************************/
int gpio_pin_unregister(FAR struct gpio_dev_s *dev, int minor) int gpio_pin_unregister(FAR struct gpio_dev_s *dev, int minor)
{ {
char devname[32]; char devname[32];
snprintf(devname, sizeof(devname), "gpio%u", (unsigned int)minor);
return gpio_pin_unregister_byname(dev, devname);
}
/****************************************************************************
* Name: gpio_pin_unregister_byname
*
* Description:
* Unregister GPIO pin device driver at /dev/pinname.
*
* Input Parameters:
* dev - A pointer to a gpio_dev_s
* pinname - A pointer to the name to be concatenated with '/dev/'
* to form the device name.
*
*
* Returned Value:
* Zero on success; A negated value is returned on a failure
* (all error values returned by inode_remove):
*
* ENOENT - path does not exist.
* EBUSY - Ref count is not 0;
****************************************************************************/
int gpio_pin_unregister_byname(FAR struct gpio_dev_s *dev,
FAR const char *pinname)
{
char devname[32];
snprintf(devname, sizeof(devname), "/dev/%s", pinname);
snprintf(devname, sizeof(devname), "/dev/gpio%u", (unsigned int)minor);
gpioinfo("Unregistering %s\n", devname); gpioinfo("Unregistering %s\n", devname);
return unregister_driver(devname); return unregister_driver(devname);

View File

@ -184,10 +184,47 @@ extern "C"
* Register GPIO pin device driver at /dev/gpioN, where N is the provided * Register GPIO pin device driver at /dev/gpioN, where N is the provided
* minor number. * minor number.
* *
* Input Parameters:
* dev - A pointer to a gpio_dev_s
* minor - An integer value to be concatenated with '/dev/gpio'
* to form the device name.
*
* Returned Value:
* Zero on success; A negated errno value is returned on a failure
* all error values returned by inode_reserve:
*
* EINVAL - 'path' is invalid for this operation
* EEXIST - An inode already exists at 'path'
* ENOMEM - Failed to allocate in-memory resources for the operation
*
****************************************************************************/ ****************************************************************************/
int gpio_pin_register(FAR struct gpio_dev_s *dev, int minor); int gpio_pin_register(FAR struct gpio_dev_s *dev, int minor);
/****************************************************************************
* Name: gpio_pin_register_byname
*
* Description:
* Register GPIO pin device driver with it's pin name.
*
* Input Parameters:
* dev - A pointer to a gpio_dev_s
* pinname - A pointer to the name to be concatenated with '/dev/'
* to form the device name.
*
* Returned Value:
* Zero on success; A negated errno value is returned on a failure
* all error values returned by inode_reserve:
*
* EINVAL - 'path' is invalid for this operation
* EEXIST - An inode already exists at 'path'
* ENOMEM - Failed to allocate in-memory resources for the operation
*
****************************************************************************/
int gpio_pin_register_byname(FAR struct gpio_dev_s *dev,
FAR const char *pinname);
/**************************************************************************** /****************************************************************************
* Name: gpio_pin_unregister * Name: gpio_pin_unregister
* *
@ -195,10 +232,45 @@ int gpio_pin_register(FAR struct gpio_dev_s *dev, int minor);
* Unregister GPIO pin device driver at /dev/gpioN, where N is the provided * Unregister GPIO pin device driver at /dev/gpioN, where N is the provided
* minor number. * minor number.
* *
* Input Parameters:
* dev - A pointer to a gpio_dev_s
* minor - An integer value to be concatenated with '/dev/gpio'
* to form the device name.
*
* Returned Value:
* Zero on success; A negated value is returned on a failure
* (all error values returned by inode_remove):
*
* ENOENT - path does not exist.
* EBUSY - Ref count is not 0;
*
****************************************************************************/ ****************************************************************************/
int gpio_pin_unregister(FAR struct gpio_dev_s *dev, int minor); int gpio_pin_unregister(FAR struct gpio_dev_s *dev, int minor);
/****************************************************************************
* Name: gpio_pin_unregister_byname
*
* Description:
* Unregister GPIO pin device driver at /dev/pinname.
*
* Input Parameters:
* dev - A pointer to a gpio_dev_s
* pinname - A pointer to the name to be concatenated with '/dev/'
* to form the device name.
*
*
* Returned Value:
* Zero on success; A negated value is returned on a failure
* (all error values returned by inode_remove):
*
* ENOENT - path does not exist.
* EBUSY - Ref count is not 0;
****************************************************************************/
int gpio_pin_unregister_byname(FAR struct gpio_dev_s *dev,
FAR const char *pinname);
/**************************************************************************** /****************************************************************************
* Name: gpio_lower_half * Name: gpio_lower_half
* *