pinctrl-bcm2835.c (664b0bae0b87f69bc9deb098f5e0158b9cf18e04) pinctrl-bcm2835.c (0de704955ee44738e88b9cc08546ea10354037ed)
1/*
2 * Driver for Broadcom BCM2835 GPIO unit (pinctrl + GPIO)
3 *
4 * Copyright (C) 2012 Chris Boot, Simon Arlott, Stephen Warren
5 *
6 * This driver is inspired by:
7 * pinctrl-nomadik.c, please see original file for copyright information
8 * pinctrl-tegra.c, please see original file for copyright information

--- 22 unchanged lines hidden (view full) ---

31#include <linux/of_address.h>
32#include <linux/of.h>
33#include <linux/of_irq.h>
34#include <linux/pinctrl/consumer.h>
35#include <linux/pinctrl/machine.h>
36#include <linux/pinctrl/pinconf.h>
37#include <linux/pinctrl/pinctrl.h>
38#include <linux/pinctrl/pinmux.h>
1/*
2 * Driver for Broadcom BCM2835 GPIO unit (pinctrl + GPIO)
3 *
4 * Copyright (C) 2012 Chris Boot, Simon Arlott, Stephen Warren
5 *
6 * This driver is inspired by:
7 * pinctrl-nomadik.c, please see original file for copyright information
8 * pinctrl-tegra.c, please see original file for copyright information

--- 22 unchanged lines hidden (view full) ---

31#include <linux/of_address.h>
32#include <linux/of.h>
33#include <linux/of_irq.h>
34#include <linux/pinctrl/consumer.h>
35#include <linux/pinctrl/machine.h>
36#include <linux/pinctrl/pinconf.h>
37#include <linux/pinctrl/pinctrl.h>
38#include <linux/pinctrl/pinmux.h>
39#include <linux/pinctrl/pinconf-generic.h>
39#include <linux/platform_device.h>
40#include <linux/seq_file.h>
41#include <linux/slab.h>
42#include <linux/spinlock.h>
43#include <linux/types.h>
40#include <linux/platform_device.h>
41#include <linux/seq_file.h>
42#include <linux/slab.h>
43#include <linux/spinlock.h>
44#include <linux/types.h>
45#include <dt-bindings/pinctrl/bcm2835.h>
44
45#define MODULE_NAME "pinctrl-bcm2835"
46#define BCM2835_NUM_GPIOS 54
47#define BCM2835_NUM_BANKS 2
48#define BCM2835_NUM_IRQS 3
49
50#define BCM2835_PIN_BITMAP_SZ \
51 DIV_ROUND_UP(BCM2835_NUM_GPIOS, sizeof(unsigned long) * 8)

--- 15 unchanged lines hidden (view full) ---

67
68#define FSEL_REG(p) (GPFSEL0 + (((p) / 10) * 4))
69#define FSEL_SHIFT(p) (((p) % 10) * 3)
70#define GPIO_REG_OFFSET(p) ((p) / 32)
71#define GPIO_REG_SHIFT(p) ((p) % 32)
72
73enum bcm2835_pinconf_param {
74 /* argument: bcm2835_pinconf_pull */
46
47#define MODULE_NAME "pinctrl-bcm2835"
48#define BCM2835_NUM_GPIOS 54
49#define BCM2835_NUM_BANKS 2
50#define BCM2835_NUM_IRQS 3
51
52#define BCM2835_PIN_BITMAP_SZ \
53 DIV_ROUND_UP(BCM2835_NUM_GPIOS, sizeof(unsigned long) * 8)

--- 15 unchanged lines hidden (view full) ---

69
70#define FSEL_REG(p) (GPFSEL0 + (((p) / 10) * 4))
71#define FSEL_SHIFT(p) (((p) % 10) * 3)
72#define GPIO_REG_OFFSET(p) ((p) / 32)
73#define GPIO_REG_SHIFT(p) ((p) % 32)
74
75enum bcm2835_pinconf_param {
76 /* argument: bcm2835_pinconf_pull */
75 BCM2835_PINCONF_PARAM_PULL,
77 BCM2835_PINCONF_PARAM_PULL = (PIN_CONFIG_END + 1),
76};
77
78};
79
78#define BCM2835_PINCONF_PACK(_param_, _arg_) ((_param_) << 16 | (_arg_))
79#define BCM2835_PINCONF_UNPACK_PARAM(_conf_) ((_conf_) >> 16)
80#define BCM2835_PINCONF_UNPACK_ARG(_conf_) ((_conf_) & 0xffff)
81
82struct bcm2835_pinctrl {
83 struct device *dev;
84 void __iomem *base;
85 int irq[BCM2835_NUM_IRQS];
86
87 /* note: locking assumes each bank will have its own unsigned long */
88 unsigned long enabled_irq_map[BCM2835_NUM_BANKS];
89 unsigned int irq_type[BCM2835_NUM_GPIOS];

--- 118 unchanged lines hidden (view full) ---

208 "gpio49",
209 "gpio50",
210 "gpio51",
211 "gpio52",
212 "gpio53",
213};
214
215enum bcm2835_fsel {
80struct bcm2835_pinctrl {
81 struct device *dev;
82 void __iomem *base;
83 int irq[BCM2835_NUM_IRQS];
84
85 /* note: locking assumes each bank will have its own unsigned long */
86 unsigned long enabled_irq_map[BCM2835_NUM_BANKS];
87 unsigned int irq_type[BCM2835_NUM_GPIOS];

--- 118 unchanged lines hidden (view full) ---

206 "gpio49",
207 "gpio50",
208 "gpio51",
209 "gpio52",
210 "gpio53",
211};
212
213enum bcm2835_fsel {
216 BCM2835_FSEL_GPIO_IN = 0,
217 BCM2835_FSEL_GPIO_OUT = 1,
218 BCM2835_FSEL_ALT0 = 4,
219 BCM2835_FSEL_ALT1 = 5,
220 BCM2835_FSEL_ALT2 = 6,
221 BCM2835_FSEL_ALT3 = 7,
222 BCM2835_FSEL_ALT4 = 3,
223 BCM2835_FSEL_ALT5 = 2,
224 BCM2835_FSEL_COUNT = 8,
225 BCM2835_FSEL_MASK = 0x7,
226};
227
228static const char * const bcm2835_functions[BCM2835_FSEL_COUNT] = {
229 [BCM2835_FSEL_GPIO_IN] = "gpio_in",
230 [BCM2835_FSEL_GPIO_OUT] = "gpio_out",
231 [BCM2835_FSEL_ALT0] = "alt0",

--- 477 unchanged lines hidden (view full) ---

709 if (pull > 2) {
710 dev_err(pc->dev, "%pOF: invalid brcm,pull %d\n", np, pull);
711 return -EINVAL;
712 }
713
714 configs = kzalloc(sizeof(*configs), GFP_KERNEL);
715 if (!configs)
716 return -ENOMEM;
214 BCM2835_FSEL_COUNT = 8,
215 BCM2835_FSEL_MASK = 0x7,
216};
217
218static const char * const bcm2835_functions[BCM2835_FSEL_COUNT] = {
219 [BCM2835_FSEL_GPIO_IN] = "gpio_in",
220 [BCM2835_FSEL_GPIO_OUT] = "gpio_out",
221 [BCM2835_FSEL_ALT0] = "alt0",

--- 477 unchanged lines hidden (view full) ---

699 if (pull > 2) {
700 dev_err(pc->dev, "%pOF: invalid brcm,pull %d\n", np, pull);
701 return -EINVAL;
702 }
703
704 configs = kzalloc(sizeof(*configs), GFP_KERNEL);
705 if (!configs)
706 return -ENOMEM;
717 configs[0] = BCM2835_PINCONF_PACK(BCM2835_PINCONF_PARAM_PULL, pull);
707 configs[0] = pinconf_to_config_packed(BCM2835_PINCONF_PARAM_PULL, pull);
718
719 map->type = PIN_MAP_TYPE_CONFIGS_PIN;
720 map->data.configs.group_or_pin = bcm2835_gpio_pins[pin].name;
721 map->data.configs.configs = configs;
722 map->data.configs.num_configs = 1;
723 (*maps)++;
724
725 return 0;
726}
727
728static int bcm2835_pctl_dt_node_to_map(struct pinctrl_dev *pctldev,
729 struct device_node *np,
708
709 map->type = PIN_MAP_TYPE_CONFIGS_PIN;
710 map->data.configs.group_or_pin = bcm2835_gpio_pins[pin].name;
711 map->data.configs.configs = configs;
712 map->data.configs.num_configs = 1;
713 (*maps)++;
714
715 return 0;
716}
717
718static int bcm2835_pctl_dt_node_to_map(struct pinctrl_dev *pctldev,
719 struct device_node *np,
730 struct pinctrl_map **map, unsigned *num_maps)
720 struct pinctrl_map **map, unsigned int *num_maps)
731{
732 struct bcm2835_pinctrl *pc = pinctrl_dev_get_drvdata(pctldev);
733 struct property *pins, *funcs, *pulls;
734 int num_pins, num_funcs, num_pulls, maps_per_pin;
735 struct pinctrl_map *maps, *cur_map;
736 int i, err;
737 u32 pin, func, pull;
738
721{
722 struct bcm2835_pinctrl *pc = pinctrl_dev_get_drvdata(pctldev);
723 struct property *pins, *funcs, *pulls;
724 int num_pins, num_funcs, num_pulls, maps_per_pin;
725 struct pinctrl_map *maps, *cur_map;
726 int i, err;
727 u32 pin, func, pull;
728
729 /* Check for generic binding in this node */
730 err = pinconf_generic_dt_node_to_map_all(pctldev, np, map, num_maps);
731 if (err || *num_maps)
732 return err;
733
734 /* Generic binding did not find anything continue with legacy parse */
739 pins = of_find_property(np, "brcm,pins", NULL);
740 if (!pins) {
741 dev_err(pc->dev, "%pOF: missing brcm,pins property\n", np);
742 return -EINVAL;
743 }
744
745 funcs = of_find_property(np, "brcm,function", NULL);
746 pulls = of_find_property(np, "brcm,pull", NULL);

--- 165 unchanged lines hidden (view full) ---

912
913static int bcm2835_pinconf_get(struct pinctrl_dev *pctldev,
914 unsigned pin, unsigned long *config)
915{
916 /* No way to read back config in HW */
917 return -ENOTSUPP;
918}
919
735 pins = of_find_property(np, "brcm,pins", NULL);
736 if (!pins) {
737 dev_err(pc->dev, "%pOF: missing brcm,pins property\n", np);
738 return -EINVAL;
739 }
740
741 funcs = of_find_property(np, "brcm,function", NULL);
742 pulls = of_find_property(np, "brcm,pull", NULL);

--- 165 unchanged lines hidden (view full) ---

908
909static int bcm2835_pinconf_get(struct pinctrl_dev *pctldev,
910 unsigned pin, unsigned long *config)
911{
912 /* No way to read back config in HW */
913 return -ENOTSUPP;
914}
915
916static void bcm2835_pull_config_set(struct bcm2835_pinctrl *pc,
917 unsigned int pin, unsigned int arg)
918{
919 u32 off, bit;
920
921 off = GPIO_REG_OFFSET(pin);
922 bit = GPIO_REG_SHIFT(pin);
923
924 bcm2835_gpio_wr(pc, GPPUD, arg & 3);
925 /*
926 * BCM2835 datasheet say to wait 150 cycles, but not of what.
927 * But the VideoCore firmware delay for this operation
928 * based nearly on the same amount of VPU cycles and this clock
929 * runs at 250 MHz.
930 */
931 udelay(1);
932 bcm2835_gpio_wr(pc, GPPUDCLK0 + (off * 4), BIT(bit));
933 udelay(1);
934 bcm2835_gpio_wr(pc, GPPUDCLK0 + (off * 4), 0);
935}
936
920static int bcm2835_pinconf_set(struct pinctrl_dev *pctldev,
937static int bcm2835_pinconf_set(struct pinctrl_dev *pctldev,
921 unsigned pin, unsigned long *configs,
922 unsigned num_configs)
938 unsigned int pin, unsigned long *configs,
939 unsigned int num_configs)
923{
924 struct bcm2835_pinctrl *pc = pinctrl_dev_get_drvdata(pctldev);
940{
941 struct bcm2835_pinctrl *pc = pinctrl_dev_get_drvdata(pctldev);
925 enum bcm2835_pinconf_param param;
926 u16 arg;
927 u32 off, bit;
942 u32 param, arg;
928 int i;
929
930 for (i = 0; i < num_configs; i++) {
943 int i;
944
945 for (i = 0; i < num_configs; i++) {
931 param = BCM2835_PINCONF_UNPACK_PARAM(configs[i]);
932 arg = BCM2835_PINCONF_UNPACK_ARG(configs[i]);
946 param = pinconf_to_config_param(configs[i]);
947 arg = pinconf_to_config_argument(configs[i]);
933
948
934 if (param != BCM2835_PINCONF_PARAM_PULL)
935 return -EINVAL;
949 switch (param) {
950 /* Set legacy brcm,pull */
951 case BCM2835_PINCONF_PARAM_PULL:
952 bcm2835_pull_config_set(pc, pin, arg);
953 break;
936
954
937 off = GPIO_REG_OFFSET(pin);
938 bit = GPIO_REG_SHIFT(pin);
955 /* Set pull generic bindings */
956 case PIN_CONFIG_BIAS_DISABLE:
957 bcm2835_pull_config_set(pc, pin, BCM2835_PUD_OFF);
958 break;
939
959
940 bcm2835_gpio_wr(pc, GPPUD, arg & 3);
941 /*
942 * BCM2835 datasheet say to wait 150 cycles, but not of what.
943 * But the VideoCore firmware delay for this operation
944 * based nearly on the same amount of VPU cycles and this clock
945 * runs at 250 MHz.
946 */
947 udelay(1);
948 bcm2835_gpio_wr(pc, GPPUDCLK0 + (off * 4), BIT(bit));
949 udelay(1);
950 bcm2835_gpio_wr(pc, GPPUDCLK0 + (off * 4), 0);
960 case PIN_CONFIG_BIAS_PULL_DOWN:
961 bcm2835_pull_config_set(pc, pin, BCM2835_PUD_DOWN);
962 break;
963
964 case PIN_CONFIG_BIAS_PULL_UP:
965 bcm2835_pull_config_set(pc, pin, BCM2835_PUD_UP);
966 break;
967
968 default:
969 return -EINVAL;
970
971 } /* switch param type */
951 } /* for each config */
952
953 return 0;
954}
955
956static const struct pinconf_ops bcm2835_pinconf_ops = {
957 .pin_config_get = bcm2835_pinconf_get,
958 .pin_config_set = bcm2835_pinconf_set,

--- 128 unchanged lines hidden ---
972 } /* for each config */
973
974 return 0;
975}
976
977static const struct pinconf_ops bcm2835_pinconf_ops = {
978 .pin_config_get = bcm2835_pinconf_get,
979 .pin_config_set = bcm2835_pinconf_set,

--- 128 unchanged lines hidden ---