gpio.c (552c69b36ebd966186573b9c7a286b390935cce1) | gpio.c (b9762bebc6332b40c33e03dea03e30fa12d9e3ed) |
---|---|
1// SPDX-License-Identifier: GPL-2.0 2/* 3 * GPIO-controlled multiplexer driver 4 * 5 * Copyright (C) 2017 Axentia Technologies AB 6 * 7 * Author: Peter Rosin <peda@axentia.se> 8 */ 9 10#include <linux/err.h> 11#include <linux/gpio/consumer.h> 12#include <linux/module.h> 13#include <linux/mux/driver.h> 14#include <linux/of_platform.h> 15#include <linux/platform_device.h> 16#include <linux/property.h> 17 18struct mux_gpio { 19 struct gpio_descs *gpios; | 1// SPDX-License-Identifier: GPL-2.0 2/* 3 * GPIO-controlled multiplexer driver 4 * 5 * Copyright (C) 2017 Axentia Technologies AB 6 * 7 * Author: Peter Rosin <peda@axentia.se> 8 */ 9 10#include <linux/err.h> 11#include <linux/gpio/consumer.h> 12#include <linux/module.h> 13#include <linux/mux/driver.h> 14#include <linux/of_platform.h> 15#include <linux/platform_device.h> 16#include <linux/property.h> 17 18struct mux_gpio { 19 struct gpio_descs *gpios; |
20 int *val; | |
21}; 22 23static int mux_gpio_set(struct mux_control *mux, int state) 24{ 25 struct mux_gpio *mux_gpio = mux_chip_priv(mux->chip); | 20}; 21 22static int mux_gpio_set(struct mux_control *mux, int state) 23{ 24 struct mux_gpio *mux_gpio = mux_chip_priv(mux->chip); |
26 int i; | 25 DECLARE_BITMAP(values, BITS_PER_TYPE(state)); |
27 | 26 |
28 for (i = 0; i < mux_gpio->gpios->ndescs; i++) 29 mux_gpio->val[i] = (state >> i) & 1; | 27 values[0] = state; |
30 31 gpiod_set_array_value_cansleep(mux_gpio->gpios->ndescs, | 28 29 gpiod_set_array_value_cansleep(mux_gpio->gpios->ndescs, |
32 mux_gpio->gpios->desc, 33 mux_gpio->val); | 30 mux_gpio->gpios->desc, values); |
34 35 return 0; 36} 37 38static const struct mux_control_ops mux_gpio_ops = { 39 .set = mux_gpio_set, 40}; 41 --- 11 unchanged lines hidden (view full) --- 53 int pins; 54 s32 idle_state; 55 int ret; 56 57 pins = gpiod_count(dev, "mux"); 58 if (pins < 0) 59 return pins; 60 | 31 32 return 0; 33} 34 35static const struct mux_control_ops mux_gpio_ops = { 36 .set = mux_gpio_set, 37}; 38 --- 11 unchanged lines hidden (view full) --- 50 int pins; 51 s32 idle_state; 52 int ret; 53 54 pins = gpiod_count(dev, "mux"); 55 if (pins < 0) 56 return pins; 57 |
61 mux_chip = devm_mux_chip_alloc(dev, 1, sizeof(*mux_gpio) + 62 pins * sizeof(*mux_gpio->val)); | 58 mux_chip = devm_mux_chip_alloc(dev, 1, sizeof(*mux_gpio)); |
63 if (IS_ERR(mux_chip)) 64 return PTR_ERR(mux_chip); 65 66 mux_gpio = mux_chip_priv(mux_chip); | 59 if (IS_ERR(mux_chip)) 60 return PTR_ERR(mux_chip); 61 62 mux_gpio = mux_chip_priv(mux_chip); |
67 mux_gpio->val = (int *)(mux_gpio + 1); | |
68 mux_chip->ops = &mux_gpio_ops; 69 70 mux_gpio->gpios = devm_gpiod_get_array(dev, "mux", GPIOD_OUT_LOW); 71 if (IS_ERR(mux_gpio->gpios)) { 72 ret = PTR_ERR(mux_gpio->gpios); 73 if (ret != -EPROBE_DEFER) 74 dev_err(dev, "failed to get gpios\n"); 75 return ret; --- 36 unchanged lines hidden --- | 63 mux_chip->ops = &mux_gpio_ops; 64 65 mux_gpio->gpios = devm_gpiod_get_array(dev, "mux", GPIOD_OUT_LOW); 66 if (IS_ERR(mux_gpio->gpios)) { 67 ret = PTR_ERR(mux_gpio->gpios); 68 if (ret != -EPROBE_DEFER) 69 dev_err(dev, "failed to get gpios\n"); 70 return ret; --- 36 unchanged lines hidden --- |