mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-08-05 16:54:27 +00:00
gpio: viperboard: use new GPIO line value setter callbacks
struct gpio_chip now has callbacks for setting line values that return an integer, allowing to indicate failures. Convert the driver to using them. Link: https://lore.kernel.org/r/20250707-gpiochip-set-rv-gpio-round4-v1-11-35668aaaf6d2@linaro.org Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
This commit is contained in:
parent
42fbbe3163
commit
55e2d1eec1
1 changed files with 63 additions and 53 deletions
|
@ -128,45 +128,50 @@ static int vprbrd_gpioa_get(struct gpio_chip *chip,
|
||||||
return answer;
|
return answer;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void vprbrd_gpioa_set(struct gpio_chip *chip,
|
static int vprbrd_gpioa_set(struct gpio_chip *chip, unsigned int offset,
|
||||||
unsigned int offset, int value)
|
int value)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret = 0;
|
||||||
struct vprbrd_gpio *gpio = gpiochip_get_data(chip);
|
struct vprbrd_gpio *gpio = gpiochip_get_data(chip);
|
||||||
struct vprbrd *vb = gpio->vb;
|
struct vprbrd *vb = gpio->vb;
|
||||||
struct vprbrd_gpioa_msg *gamsg = (struct vprbrd_gpioa_msg *)vb->buf;
|
struct vprbrd_gpioa_msg *gamsg = (struct vprbrd_gpioa_msg *)vb->buf;
|
||||||
|
|
||||||
if (gpio->gpioa_out & (1 << offset)) {
|
if (!(gpio->gpioa_out & (1 << offset)))
|
||||||
if (value)
|
return 0;
|
||||||
gpio->gpioa_val |= (1 << offset);
|
|
||||||
else
|
|
||||||
gpio->gpioa_val &= ~(1 << offset);
|
|
||||||
|
|
||||||
mutex_lock(&vb->lock);
|
if (value)
|
||||||
|
gpio->gpioa_val |= (1 << offset);
|
||||||
|
else
|
||||||
|
gpio->gpioa_val &= ~(1 << offset);
|
||||||
|
|
||||||
gamsg->cmd = VPRBRD_GPIOA_CMD_SETOUT;
|
mutex_lock(&vb->lock);
|
||||||
gamsg->clk = 0x00;
|
|
||||||
gamsg->offset = offset;
|
|
||||||
gamsg->t1 = 0x00;
|
|
||||||
gamsg->t2 = 0x00;
|
|
||||||
gamsg->invert = 0x00;
|
|
||||||
gamsg->pwmlevel = 0x00;
|
|
||||||
gamsg->outval = value;
|
|
||||||
gamsg->risefall = 0x00;
|
|
||||||
gamsg->answer = 0x00;
|
|
||||||
gamsg->__fill = 0x00;
|
|
||||||
|
|
||||||
ret = usb_control_msg(vb->usb_dev,
|
gamsg->cmd = VPRBRD_GPIOA_CMD_SETOUT;
|
||||||
usb_sndctrlpipe(vb->usb_dev, 0),
|
gamsg->clk = 0x00;
|
||||||
VPRBRD_USB_REQUEST_GPIOA, VPRBRD_USB_TYPE_OUT,
|
gamsg->offset = offset;
|
||||||
0x0000, 0x0000, gamsg,
|
gamsg->t1 = 0x00;
|
||||||
sizeof(struct vprbrd_gpioa_msg), VPRBRD_USB_TIMEOUT_MS);
|
gamsg->t2 = 0x00;
|
||||||
|
gamsg->invert = 0x00;
|
||||||
|
gamsg->pwmlevel = 0x00;
|
||||||
|
gamsg->outval = value;
|
||||||
|
gamsg->risefall = 0x00;
|
||||||
|
gamsg->answer = 0x00;
|
||||||
|
gamsg->__fill = 0x00;
|
||||||
|
|
||||||
mutex_unlock(&vb->lock);
|
ret = usb_control_msg(vb->usb_dev, usb_sndctrlpipe(vb->usb_dev, 0),
|
||||||
|
VPRBRD_USB_REQUEST_GPIOA, VPRBRD_USB_TYPE_OUT,
|
||||||
|
0x0000, 0x0000, gamsg,
|
||||||
|
sizeof(struct vprbrd_gpioa_msg),
|
||||||
|
VPRBRD_USB_TIMEOUT_MS);
|
||||||
|
|
||||||
if (ret != sizeof(struct vprbrd_gpioa_msg))
|
mutex_unlock(&vb->lock);
|
||||||
dev_err(chip->parent, "usb error setting pin value\n");
|
|
||||||
|
if (ret != sizeof(struct vprbrd_gpioa_msg)) {
|
||||||
|
dev_err(chip->parent, "usb error setting pin value\n");
|
||||||
|
return -EREMOTEIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int vprbrd_gpioa_direction_input(struct gpio_chip *chip,
|
static int vprbrd_gpioa_direction_input(struct gpio_chip *chip,
|
||||||
|
@ -304,37 +309,42 @@ static int vprbrd_gpiob_get(struct gpio_chip *chip,
|
||||||
return (gpio->gpiob_val >> offset) & 0x1;
|
return (gpio->gpiob_val >> offset) & 0x1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void vprbrd_gpiob_set(struct gpio_chip *chip,
|
static int vprbrd_gpiob_set(struct gpio_chip *chip, unsigned int offset,
|
||||||
unsigned int offset, int value)
|
int value)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
struct vprbrd_gpio *gpio = gpiochip_get_data(chip);
|
struct vprbrd_gpio *gpio = gpiochip_get_data(chip);
|
||||||
struct vprbrd *vb = gpio->vb;
|
struct vprbrd *vb = gpio->vb;
|
||||||
struct vprbrd_gpiob_msg *gbmsg = (struct vprbrd_gpiob_msg *)vb->buf;
|
struct vprbrd_gpiob_msg *gbmsg = (struct vprbrd_gpiob_msg *)vb->buf;
|
||||||
|
|
||||||
if (gpio->gpiob_out & (1 << offset)) {
|
if (!(gpio->gpiob_out & (1 << offset)))
|
||||||
if (value)
|
return 0;
|
||||||
gpio->gpiob_val |= (1 << offset);
|
|
||||||
else
|
|
||||||
gpio->gpiob_val &= ~(1 << offset);
|
|
||||||
|
|
||||||
mutex_lock(&vb->lock);
|
if (value)
|
||||||
|
gpio->gpiob_val |= (1 << offset);
|
||||||
|
else
|
||||||
|
gpio->gpiob_val &= ~(1 << offset);
|
||||||
|
|
||||||
gbmsg->cmd = VPRBRD_GPIOB_CMD_SETVAL;
|
mutex_lock(&vb->lock);
|
||||||
gbmsg->val = cpu_to_be16(value << offset);
|
|
||||||
gbmsg->mask = cpu_to_be16(0x0001 << offset);
|
|
||||||
|
|
||||||
ret = usb_control_msg(vb->usb_dev,
|
gbmsg->cmd = VPRBRD_GPIOB_CMD_SETVAL;
|
||||||
usb_sndctrlpipe(vb->usb_dev, 0),
|
gbmsg->val = cpu_to_be16(value << offset);
|
||||||
VPRBRD_USB_REQUEST_GPIOB, VPRBRD_USB_TYPE_OUT,
|
gbmsg->mask = cpu_to_be16(0x0001 << offset);
|
||||||
0x0000, 0x0000, gbmsg,
|
|
||||||
sizeof(struct vprbrd_gpiob_msg), VPRBRD_USB_TIMEOUT_MS);
|
|
||||||
|
|
||||||
mutex_unlock(&vb->lock);
|
ret = usb_control_msg(vb->usb_dev, usb_sndctrlpipe(vb->usb_dev, 0),
|
||||||
|
VPRBRD_USB_REQUEST_GPIOB, VPRBRD_USB_TYPE_OUT,
|
||||||
|
0x0000, 0x0000, gbmsg,
|
||||||
|
sizeof(struct vprbrd_gpiob_msg),
|
||||||
|
VPRBRD_USB_TIMEOUT_MS);
|
||||||
|
|
||||||
if (ret != sizeof(struct vprbrd_gpiob_msg))
|
mutex_unlock(&vb->lock);
|
||||||
dev_err(chip->parent, "usb error setting pin value\n");
|
|
||||||
|
if (ret != sizeof(struct vprbrd_gpiob_msg)) {
|
||||||
|
dev_err(chip->parent, "usb error setting pin value\n");
|
||||||
|
return -EREMOTEIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int vprbrd_gpiob_direction_input(struct gpio_chip *chip,
|
static int vprbrd_gpiob_direction_input(struct gpio_chip *chip,
|
||||||
|
@ -370,14 +380,14 @@ static int vprbrd_gpiob_direction_output(struct gpio_chip *chip,
|
||||||
mutex_lock(&vb->lock);
|
mutex_lock(&vb->lock);
|
||||||
|
|
||||||
ret = vprbrd_gpiob_setdir(vb, offset, 1);
|
ret = vprbrd_gpiob_setdir(vb, offset, 1);
|
||||||
if (ret)
|
if (ret) {
|
||||||
dev_err(chip->parent, "usb error setting pin to output\n");
|
dev_err(chip->parent, "usb error setting pin to output\n");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
mutex_unlock(&vb->lock);
|
mutex_unlock(&vb->lock);
|
||||||
|
|
||||||
vprbrd_gpiob_set(chip, offset, value);
|
return vprbrd_gpiob_set(chip, offset, value);
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----- end of gpio b chip ---------------------------------------------- */
|
/* ----- end of gpio b chip ---------------------------------------------- */
|
||||||
|
@ -400,7 +410,7 @@ static int vprbrd_gpio_probe(struct platform_device *pdev)
|
||||||
vb_gpio->gpioa.base = -1;
|
vb_gpio->gpioa.base = -1;
|
||||||
vb_gpio->gpioa.ngpio = 16;
|
vb_gpio->gpioa.ngpio = 16;
|
||||||
vb_gpio->gpioa.can_sleep = true;
|
vb_gpio->gpioa.can_sleep = true;
|
||||||
vb_gpio->gpioa.set = vprbrd_gpioa_set;
|
vb_gpio->gpioa.set_rv = vprbrd_gpioa_set;
|
||||||
vb_gpio->gpioa.get = vprbrd_gpioa_get;
|
vb_gpio->gpioa.get = vprbrd_gpioa_get;
|
||||||
vb_gpio->gpioa.direction_input = vprbrd_gpioa_direction_input;
|
vb_gpio->gpioa.direction_input = vprbrd_gpioa_direction_input;
|
||||||
vb_gpio->gpioa.direction_output = vprbrd_gpioa_direction_output;
|
vb_gpio->gpioa.direction_output = vprbrd_gpioa_direction_output;
|
||||||
|
@ -416,7 +426,7 @@ static int vprbrd_gpio_probe(struct platform_device *pdev)
|
||||||
vb_gpio->gpiob.base = -1;
|
vb_gpio->gpiob.base = -1;
|
||||||
vb_gpio->gpiob.ngpio = 16;
|
vb_gpio->gpiob.ngpio = 16;
|
||||||
vb_gpio->gpiob.can_sleep = true;
|
vb_gpio->gpiob.can_sleep = true;
|
||||||
vb_gpio->gpiob.set = vprbrd_gpiob_set;
|
vb_gpio->gpiob.set_rv = vprbrd_gpiob_set;
|
||||||
vb_gpio->gpiob.get = vprbrd_gpiob_get;
|
vb_gpio->gpiob.get = vprbrd_gpiob_get;
|
||||||
vb_gpio->gpiob.direction_input = vprbrd_gpiob_direction_input;
|
vb_gpio->gpiob.direction_input = vprbrd_gpiob_direction_input;
|
||||||
vb_gpio->gpiob.direction_output = vprbrd_gpiob_direction_output;
|
vb_gpio->gpiob.direction_output = vprbrd_gpiob_direction_output;
|
||||||
|
|
Loading…
Add table
Reference in a new issue