Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /* Copyright (C) 2021 Rafał Miłecki <rafal@milecki.pl> */
0003 
0004 #include <linux/err.h>
0005 #include <linux/io.h>
0006 #include <linux/mod_devicetable.h>
0007 #include <linux/module.h>
0008 #include <linux/pinctrl/pinconf-generic.h>
0009 #include <linux/pinctrl/pinctrl.h>
0010 #include <linux/pinctrl/pinmux.h>
0011 #include <linux/platform_device.h>
0012 #include <linux/slab.h>
0013 #include <linux/string_helpers.h>
0014 
0015 #include "../core.h"
0016 #include "../pinmux.h"
0017 
0018 #define BCM4908_NUM_PINS            86
0019 
0020 #define BCM4908_TEST_PORT_BLOCK_EN_LSB          0x00
0021 #define BCM4908_TEST_PORT_BLOCK_DATA_MSB        0x04
0022 #define BCM4908_TEST_PORT_BLOCK_DATA_LSB        0x08
0023 #define  BCM4908_TEST_PORT_LSB_PINMUX_DATA_SHIFT    12
0024 #define BCM4908_TEST_PORT_COMMAND           0x0c
0025 #define  BCM4908_TEST_PORT_CMD_LOAD_MUX_REG     0x00000021
0026 
0027 struct bcm4908_pinctrl {
0028     struct device *dev;
0029     void __iomem *base;
0030     struct mutex mutex;
0031     struct pinctrl_dev *pctldev;
0032     struct pinctrl_desc pctldesc;
0033 };
0034 
0035 /*
0036  * Groups
0037  */
0038 
0039 struct bcm4908_pinctrl_pin_setup {
0040     unsigned int number;
0041     unsigned int function;
0042 };
0043 
0044 static const struct bcm4908_pinctrl_pin_setup led_0_pins_a[] = {
0045     { 0, 3 },
0046 };
0047 
0048 static const struct bcm4908_pinctrl_pin_setup led_1_pins_a[] = {
0049     { 1, 3 },
0050 };
0051 
0052 static const struct bcm4908_pinctrl_pin_setup led_2_pins_a[] = {
0053     { 2, 3 },
0054 };
0055 
0056 static const struct bcm4908_pinctrl_pin_setup led_3_pins_a[] = {
0057     { 3, 3 },
0058 };
0059 
0060 static const struct bcm4908_pinctrl_pin_setup led_4_pins_a[] = {
0061     { 4, 3 },
0062 };
0063 
0064 static const struct bcm4908_pinctrl_pin_setup led_5_pins_a[] = {
0065     { 5, 3 },
0066 };
0067 
0068 static const struct bcm4908_pinctrl_pin_setup led_6_pins_a[] = {
0069     { 6, 3 },
0070 };
0071 
0072 static const struct bcm4908_pinctrl_pin_setup led_7_pins_a[] = {
0073     { 7, 3 },
0074 };
0075 
0076 static const struct bcm4908_pinctrl_pin_setup led_8_pins_a[] = {
0077     { 8, 3 },
0078 };
0079 
0080 static const struct bcm4908_pinctrl_pin_setup led_9_pins_a[] = {
0081     { 9, 3 },
0082 };
0083 
0084 static const struct bcm4908_pinctrl_pin_setup led_10_pins_a[] = {
0085     { 10, 3 },
0086 };
0087 
0088 static const struct bcm4908_pinctrl_pin_setup led_11_pins_a[] = {
0089     { 11, 3 },
0090 };
0091 
0092 static const struct bcm4908_pinctrl_pin_setup led_12_pins_a[] = {
0093     { 12, 3 },
0094 };
0095 
0096 static const struct bcm4908_pinctrl_pin_setup led_13_pins_a[] = {
0097     { 13, 3 },
0098 };
0099 
0100 static const struct bcm4908_pinctrl_pin_setup led_14_pins_a[] = {
0101     { 14, 3 },
0102 };
0103 
0104 static const struct bcm4908_pinctrl_pin_setup led_15_pins_a[] = {
0105     { 15, 3 },
0106 };
0107 
0108 static const struct bcm4908_pinctrl_pin_setup led_16_pins_a[] = {
0109     { 16, 3 },
0110 };
0111 
0112 static const struct bcm4908_pinctrl_pin_setup led_17_pins_a[] = {
0113     { 17, 3 },
0114 };
0115 
0116 static const struct bcm4908_pinctrl_pin_setup led_18_pins_a[] = {
0117     { 18, 3 },
0118 };
0119 
0120 static const struct bcm4908_pinctrl_pin_setup led_19_pins_a[] = {
0121     { 19, 3 },
0122 };
0123 
0124 static const struct bcm4908_pinctrl_pin_setup led_20_pins_a[] = {
0125     { 20, 3 },
0126 };
0127 
0128 static const struct bcm4908_pinctrl_pin_setup led_21_pins_a[] = {
0129     { 21, 3 },
0130 };
0131 
0132 static const struct bcm4908_pinctrl_pin_setup led_22_pins_a[] = {
0133     { 22, 3 },
0134 };
0135 
0136 static const struct bcm4908_pinctrl_pin_setup led_23_pins_a[] = {
0137     { 23, 3 },
0138 };
0139 
0140 static const struct bcm4908_pinctrl_pin_setup led_24_pins_a[] = {
0141     { 24, 3 },
0142 };
0143 
0144 static const struct bcm4908_pinctrl_pin_setup led_25_pins_a[] = {
0145     { 25, 3 },
0146 };
0147 
0148 static const struct bcm4908_pinctrl_pin_setup led_26_pins_a[] = {
0149     { 26, 3 },
0150 };
0151 
0152 static const struct bcm4908_pinctrl_pin_setup led_27_pins_a[] = {
0153     { 27, 3 },
0154 };
0155 
0156 static const struct bcm4908_pinctrl_pin_setup led_28_pins_a[] = {
0157     { 28, 3 },
0158 };
0159 
0160 static const struct bcm4908_pinctrl_pin_setup led_29_pins_a[] = {
0161     { 29, 3 },
0162 };
0163 
0164 static const struct bcm4908_pinctrl_pin_setup led_30_pins_a[] = {
0165     { 30, 3 },
0166 };
0167 
0168 static const struct bcm4908_pinctrl_pin_setup led_31_pins_a[] = {
0169     { 31, 3 },
0170 };
0171 
0172 static const struct bcm4908_pinctrl_pin_setup led_10_pins_b[] = {
0173     { 8, 2 },
0174 };
0175 
0176 static const struct bcm4908_pinctrl_pin_setup led_11_pins_b[] = {
0177     { 9, 2 },
0178 };
0179 
0180 static const struct bcm4908_pinctrl_pin_setup led_12_pins_b[] = {
0181     { 0, 2 },
0182 };
0183 
0184 static const struct bcm4908_pinctrl_pin_setup led_13_pins_b[] = {
0185     { 1, 2 },
0186 };
0187 
0188 static const struct bcm4908_pinctrl_pin_setup led_31_pins_b[] = {
0189     { 30, 2 },
0190 };
0191 
0192 static const struct bcm4908_pinctrl_pin_setup hs_uart_pins[] = {
0193     { 10, 0 },  /* CTS */
0194     { 11, 0 },  /* RTS */
0195     { 12, 0 },  /* RXD */
0196     { 13, 0 },  /* TXD */
0197 };
0198 
0199 static const struct bcm4908_pinctrl_pin_setup i2c_pins_a[] = {
0200     { 18, 0 },  /* SDA */
0201     { 19, 0 },  /* SCL */
0202 };
0203 
0204 static const struct bcm4908_pinctrl_pin_setup i2c_pins_b[] = {
0205     { 22, 0 },  /* SDA */
0206     { 23, 0 },  /* SCL */
0207 };
0208 
0209 static const struct bcm4908_pinctrl_pin_setup i2s_pins[] = {
0210     { 27, 0 },  /* MCLK */
0211     { 28, 0 },  /* LRCK */
0212     { 29, 0 },  /* SDATA */
0213     { 30, 0 },  /* SCLK */
0214 };
0215 
0216 static const struct bcm4908_pinctrl_pin_setup nand_ctrl_pins[] = {
0217     { 32, 0 },
0218     { 33, 0 },
0219     { 34, 0 },
0220     { 43, 0 },
0221     { 44, 0 },
0222     { 45, 0 },
0223     { 56, 1 },
0224 };
0225 
0226 static const struct bcm4908_pinctrl_pin_setup nand_data_pins[] = {
0227     { 35, 0 },
0228     { 36, 0 },
0229     { 37, 0 },
0230     { 38, 0 },
0231     { 39, 0 },
0232     { 40, 0 },
0233     { 41, 0 },
0234     { 42, 0 },
0235 };
0236 
0237 static const struct bcm4908_pinctrl_pin_setup emmc_ctrl_pins[] = {
0238     { 46, 0 },
0239     { 47, 0 },
0240 };
0241 
0242 static const struct bcm4908_pinctrl_pin_setup usb0_pwr_pins[] = {
0243     { 63, 0 },
0244     { 64, 0 },
0245 };
0246 
0247 static const struct bcm4908_pinctrl_pin_setup usb1_pwr_pins[] = {
0248     { 66, 0 },
0249     { 67, 0 },
0250 };
0251 
0252 struct bcm4908_pinctrl_grp {
0253     const char *name;
0254     const struct bcm4908_pinctrl_pin_setup *pins;
0255     const unsigned int num_pins;
0256 };
0257 
0258 static const struct bcm4908_pinctrl_grp bcm4908_pinctrl_grps[] = {
0259     { "led_0_grp_a", led_0_pins_a, ARRAY_SIZE(led_0_pins_a) },
0260     { "led_1_grp_a", led_1_pins_a, ARRAY_SIZE(led_1_pins_a) },
0261     { "led_2_grp_a", led_2_pins_a, ARRAY_SIZE(led_2_pins_a) },
0262     { "led_3_grp_a", led_3_pins_a, ARRAY_SIZE(led_3_pins_a) },
0263     { "led_4_grp_a", led_4_pins_a, ARRAY_SIZE(led_4_pins_a) },
0264     { "led_5_grp_a", led_5_pins_a, ARRAY_SIZE(led_5_pins_a) },
0265     { "led_6_grp_a", led_6_pins_a, ARRAY_SIZE(led_6_pins_a) },
0266     { "led_7_grp_a", led_7_pins_a, ARRAY_SIZE(led_7_pins_a) },
0267     { "led_8_grp_a", led_8_pins_a, ARRAY_SIZE(led_8_pins_a) },
0268     { "led_9_grp_a", led_9_pins_a, ARRAY_SIZE(led_9_pins_a) },
0269     { "led_10_grp_a", led_10_pins_a, ARRAY_SIZE(led_10_pins_a) },
0270     { "led_11_grp_a", led_11_pins_a, ARRAY_SIZE(led_11_pins_a) },
0271     { "led_12_grp_a", led_12_pins_a, ARRAY_SIZE(led_12_pins_a) },
0272     { "led_13_grp_a", led_13_pins_a, ARRAY_SIZE(led_13_pins_a) },
0273     { "led_14_grp_a", led_14_pins_a, ARRAY_SIZE(led_14_pins_a) },
0274     { "led_15_grp_a", led_15_pins_a, ARRAY_SIZE(led_15_pins_a) },
0275     { "led_16_grp_a", led_16_pins_a, ARRAY_SIZE(led_16_pins_a) },
0276     { "led_17_grp_a", led_17_pins_a, ARRAY_SIZE(led_17_pins_a) },
0277     { "led_18_grp_a", led_18_pins_a, ARRAY_SIZE(led_18_pins_a) },
0278     { "led_19_grp_a", led_19_pins_a, ARRAY_SIZE(led_19_pins_a) },
0279     { "led_20_grp_a", led_20_pins_a, ARRAY_SIZE(led_20_pins_a) },
0280     { "led_21_grp_a", led_21_pins_a, ARRAY_SIZE(led_21_pins_a) },
0281     { "led_22_grp_a", led_22_pins_a, ARRAY_SIZE(led_22_pins_a) },
0282     { "led_23_grp_a", led_23_pins_a, ARRAY_SIZE(led_23_pins_a) },
0283     { "led_24_grp_a", led_24_pins_a, ARRAY_SIZE(led_24_pins_a) },
0284     { "led_25_grp_a", led_25_pins_a, ARRAY_SIZE(led_25_pins_a) },
0285     { "led_26_grp_a", led_26_pins_a, ARRAY_SIZE(led_26_pins_a) },
0286     { "led_27_grp_a", led_27_pins_a, ARRAY_SIZE(led_27_pins_a) },
0287     { "led_28_grp_a", led_28_pins_a, ARRAY_SIZE(led_28_pins_a) },
0288     { "led_29_grp_a", led_29_pins_a, ARRAY_SIZE(led_29_pins_a) },
0289     { "led_30_grp_a", led_30_pins_a, ARRAY_SIZE(led_30_pins_a) },
0290     { "led_31_grp_a", led_31_pins_a, ARRAY_SIZE(led_31_pins_a) },
0291     { "led_10_grp_b", led_10_pins_b, ARRAY_SIZE(led_10_pins_b) },
0292     { "led_11_grp_b", led_11_pins_b, ARRAY_SIZE(led_11_pins_b) },
0293     { "led_12_grp_b", led_12_pins_b, ARRAY_SIZE(led_12_pins_b) },
0294     { "led_13_grp_b", led_13_pins_b, ARRAY_SIZE(led_13_pins_b) },
0295     { "led_31_grp_b", led_31_pins_b, ARRAY_SIZE(led_31_pins_b) },
0296     { "hs_uart_grp", hs_uart_pins, ARRAY_SIZE(hs_uart_pins) },
0297     { "i2c_grp_a", i2c_pins_a, ARRAY_SIZE(i2c_pins_a) },
0298     { "i2c_grp_b", i2c_pins_b, ARRAY_SIZE(i2c_pins_b) },
0299     { "i2s_grp", i2s_pins, ARRAY_SIZE(i2s_pins) },
0300     { "nand_ctrl_grp", nand_ctrl_pins, ARRAY_SIZE(nand_ctrl_pins) },
0301     { "nand_data_grp", nand_data_pins, ARRAY_SIZE(nand_data_pins) },
0302     { "emmc_ctrl_grp", emmc_ctrl_pins, ARRAY_SIZE(emmc_ctrl_pins) },
0303     { "usb0_pwr_grp", usb0_pwr_pins, ARRAY_SIZE(usb0_pwr_pins) },
0304     { "usb1_pwr_grp", usb1_pwr_pins, ARRAY_SIZE(usb1_pwr_pins) },
0305 };
0306 
0307 /*
0308  * Functions
0309  */
0310 
0311 struct bcm4908_pinctrl_function {
0312     const char *name;
0313     const char * const *groups;
0314     const unsigned int num_groups;
0315 };
0316 
0317 static const char * const led_0_groups[] = { "led_0_grp_a" };
0318 static const char * const led_1_groups[] = { "led_1_grp_a" };
0319 static const char * const led_2_groups[] = { "led_2_grp_a" };
0320 static const char * const led_3_groups[] = { "led_3_grp_a" };
0321 static const char * const led_4_groups[] = { "led_4_grp_a" };
0322 static const char * const led_5_groups[] = { "led_5_grp_a" };
0323 static const char * const led_6_groups[] = { "led_6_grp_a" };
0324 static const char * const led_7_groups[] = { "led_7_grp_a" };
0325 static const char * const led_8_groups[] = { "led_8_grp_a" };
0326 static const char * const led_9_groups[] = { "led_9_grp_a" };
0327 static const char * const led_10_groups[] = { "led_10_grp_a", "led_10_grp_b" };
0328 static const char * const led_11_groups[] = { "led_11_grp_a", "led_11_grp_b" };
0329 static const char * const led_12_groups[] = { "led_12_grp_a", "led_12_grp_b" };
0330 static const char * const led_13_groups[] = { "led_13_grp_a", "led_13_grp_b" };
0331 static const char * const led_14_groups[] = { "led_14_grp_a" };
0332 static const char * const led_15_groups[] = { "led_15_grp_a" };
0333 static const char * const led_16_groups[] = { "led_16_grp_a" };
0334 static const char * const led_17_groups[] = { "led_17_grp_a" };
0335 static const char * const led_18_groups[] = { "led_18_grp_a" };
0336 static const char * const led_19_groups[] = { "led_19_grp_a" };
0337 static const char * const led_20_groups[] = { "led_20_grp_a" };
0338 static const char * const led_21_groups[] = { "led_21_grp_a" };
0339 static const char * const led_22_groups[] = { "led_22_grp_a" };
0340 static const char * const led_23_groups[] = { "led_23_grp_a" };
0341 static const char * const led_24_groups[] = { "led_24_grp_a" };
0342 static const char * const led_25_groups[] = { "led_25_grp_a" };
0343 static const char * const led_26_groups[] = { "led_26_grp_a" };
0344 static const char * const led_27_groups[] = { "led_27_grp_a" };
0345 static const char * const led_28_groups[] = { "led_28_grp_a" };
0346 static const char * const led_29_groups[] = { "led_29_grp_a" };
0347 static const char * const led_30_groups[] = { "led_30_grp_a" };
0348 static const char * const led_31_groups[] = { "led_31_grp_a", "led_31_grp_b" };
0349 static const char * const hs_uart_groups[] = { "hs_uart_grp" };
0350 static const char * const i2c_groups[] = { "i2c_grp_a", "i2c_grp_b" };
0351 static const char * const i2s_groups[] = { "i2s_grp" };
0352 static const char * const nand_ctrl_groups[] = { "nand_ctrl_grp" };
0353 static const char * const nand_data_groups[] = { "nand_data_grp" };
0354 static const char * const emmc_ctrl_groups[] = { "emmc_ctrl_grp" };
0355 static const char * const usb0_pwr_groups[] = { "usb0_pwr_grp" };
0356 static const char * const usb1_pwr_groups[] = { "usb1_pwr_grp" };
0357 
0358 static const struct bcm4908_pinctrl_function bcm4908_pinctrl_functions[] = {
0359     { "led_0", led_0_groups, ARRAY_SIZE(led_0_groups) },
0360     { "led_1", led_1_groups, ARRAY_SIZE(led_1_groups) },
0361     { "led_2", led_2_groups, ARRAY_SIZE(led_2_groups) },
0362     { "led_3", led_3_groups, ARRAY_SIZE(led_3_groups) },
0363     { "led_4", led_4_groups, ARRAY_SIZE(led_4_groups) },
0364     { "led_5", led_5_groups, ARRAY_SIZE(led_5_groups) },
0365     { "led_6", led_6_groups, ARRAY_SIZE(led_6_groups) },
0366     { "led_7", led_7_groups, ARRAY_SIZE(led_7_groups) },
0367     { "led_8", led_8_groups, ARRAY_SIZE(led_8_groups) },
0368     { "led_9", led_9_groups, ARRAY_SIZE(led_9_groups) },
0369     { "led_10", led_10_groups, ARRAY_SIZE(led_10_groups) },
0370     { "led_11", led_11_groups, ARRAY_SIZE(led_11_groups) },
0371     { "led_12", led_12_groups, ARRAY_SIZE(led_12_groups) },
0372     { "led_13", led_13_groups, ARRAY_SIZE(led_13_groups) },
0373     { "led_14", led_14_groups, ARRAY_SIZE(led_14_groups) },
0374     { "led_15", led_15_groups, ARRAY_SIZE(led_15_groups) },
0375     { "led_16", led_16_groups, ARRAY_SIZE(led_16_groups) },
0376     { "led_17", led_17_groups, ARRAY_SIZE(led_17_groups) },
0377     { "led_18", led_18_groups, ARRAY_SIZE(led_18_groups) },
0378     { "led_19", led_19_groups, ARRAY_SIZE(led_19_groups) },
0379     { "led_20", led_20_groups, ARRAY_SIZE(led_20_groups) },
0380     { "led_21", led_21_groups, ARRAY_SIZE(led_21_groups) },
0381     { "led_22", led_22_groups, ARRAY_SIZE(led_22_groups) },
0382     { "led_23", led_23_groups, ARRAY_SIZE(led_23_groups) },
0383     { "led_24", led_24_groups, ARRAY_SIZE(led_24_groups) },
0384     { "led_25", led_25_groups, ARRAY_SIZE(led_25_groups) },
0385     { "led_26", led_26_groups, ARRAY_SIZE(led_26_groups) },
0386     { "led_27", led_27_groups, ARRAY_SIZE(led_27_groups) },
0387     { "led_28", led_28_groups, ARRAY_SIZE(led_28_groups) },
0388     { "led_29", led_29_groups, ARRAY_SIZE(led_29_groups) },
0389     { "led_30", led_30_groups, ARRAY_SIZE(led_30_groups) },
0390     { "led_31", led_31_groups, ARRAY_SIZE(led_31_groups) },
0391     { "hs_uart", hs_uart_groups, ARRAY_SIZE(hs_uart_groups) },
0392     { "i2c", i2c_groups, ARRAY_SIZE(i2c_groups) },
0393     { "i2s", i2s_groups, ARRAY_SIZE(i2s_groups) },
0394     { "nand_ctrl", nand_ctrl_groups, ARRAY_SIZE(nand_ctrl_groups) },
0395     { "nand_data", nand_data_groups, ARRAY_SIZE(nand_data_groups) },
0396     { "emmc_ctrl", emmc_ctrl_groups, ARRAY_SIZE(emmc_ctrl_groups) },
0397     { "usb0_pwr", usb0_pwr_groups, ARRAY_SIZE(usb0_pwr_groups) },
0398     { "usb1_pwr", usb1_pwr_groups, ARRAY_SIZE(usb1_pwr_groups) },
0399 };
0400 
0401 /*
0402  * Groups code
0403  */
0404 
0405 static const struct pinctrl_ops bcm4908_pinctrl_ops = {
0406     .get_groups_count = pinctrl_generic_get_group_count,
0407     .get_group_name = pinctrl_generic_get_group_name,
0408     .get_group_pins = pinctrl_generic_get_group_pins,
0409     .dt_node_to_map = pinconf_generic_dt_node_to_map_group,
0410     .dt_free_map = pinconf_generic_dt_free_map,
0411 };
0412 
0413 /*
0414  * Functions code
0415  */
0416 
0417 static int bcm4908_pinctrl_set_mux(struct pinctrl_dev *pctrl_dev,
0418                   unsigned int func_selector,
0419                   unsigned int group_selector)
0420 {
0421     struct bcm4908_pinctrl *bcm4908_pinctrl = pinctrl_dev_get_drvdata(pctrl_dev);
0422     const struct bcm4908_pinctrl_grp *group;
0423     struct group_desc *group_desc;
0424     int i;
0425 
0426     group_desc = pinctrl_generic_get_group(pctrl_dev, group_selector);
0427     if (!group_desc)
0428         return -EINVAL;
0429     group = group_desc->data;
0430 
0431     mutex_lock(&bcm4908_pinctrl->mutex);
0432     for (i = 0; i < group->num_pins; i++) {
0433         u32 lsb = 0;
0434 
0435         lsb |= group->pins[i].number;
0436         lsb |= group->pins[i].function << BCM4908_TEST_PORT_LSB_PINMUX_DATA_SHIFT;
0437 
0438         writel(0x0, bcm4908_pinctrl->base + BCM4908_TEST_PORT_BLOCK_DATA_MSB);
0439         writel(lsb, bcm4908_pinctrl->base + BCM4908_TEST_PORT_BLOCK_DATA_LSB);
0440         writel(BCM4908_TEST_PORT_CMD_LOAD_MUX_REG,
0441                bcm4908_pinctrl->base + BCM4908_TEST_PORT_COMMAND);
0442     }
0443     mutex_unlock(&bcm4908_pinctrl->mutex);
0444 
0445     return 0;
0446 }
0447 
0448 static const struct pinmux_ops bcm4908_pinctrl_pmxops = {
0449     .get_functions_count = pinmux_generic_get_function_count,
0450     .get_function_name = pinmux_generic_get_function_name,
0451     .get_function_groups = pinmux_generic_get_function_groups,
0452     .set_mux = bcm4908_pinctrl_set_mux,
0453 };
0454 
0455 /*
0456  * Controller code
0457  */
0458 
0459 static struct pinctrl_desc bcm4908_pinctrl_desc = {
0460     .name = "bcm4908-pinctrl",
0461     .pctlops = &bcm4908_pinctrl_ops,
0462     .pmxops = &bcm4908_pinctrl_pmxops,
0463 };
0464 
0465 static const struct of_device_id bcm4908_pinctrl_of_match_table[] = {
0466     { .compatible = "brcm,bcm4908-pinctrl", },
0467     { }
0468 };
0469 
0470 static int bcm4908_pinctrl_probe(struct platform_device *pdev)
0471 {
0472     struct device *dev = &pdev->dev;
0473     struct bcm4908_pinctrl *bcm4908_pinctrl;
0474     struct pinctrl_desc *pctldesc;
0475     struct pinctrl_pin_desc *pins;
0476     char **pin_names;
0477     int i;
0478 
0479     bcm4908_pinctrl = devm_kzalloc(dev, sizeof(*bcm4908_pinctrl), GFP_KERNEL);
0480     if (!bcm4908_pinctrl)
0481         return -ENOMEM;
0482     pctldesc = &bcm4908_pinctrl->pctldesc;
0483     platform_set_drvdata(pdev, bcm4908_pinctrl);
0484 
0485     /* Set basic properties */
0486 
0487     bcm4908_pinctrl->dev = dev;
0488 
0489     bcm4908_pinctrl->base = devm_platform_ioremap_resource(pdev, 0);
0490     if (IS_ERR(bcm4908_pinctrl->base))
0491         return PTR_ERR(bcm4908_pinctrl->base);
0492 
0493     mutex_init(&bcm4908_pinctrl->mutex);
0494 
0495     memcpy(pctldesc, &bcm4908_pinctrl_desc, sizeof(*pctldesc));
0496 
0497     /* Set pinctrl properties */
0498 
0499     pin_names = devm_kasprintf_strarray(dev, "pin", BCM4908_NUM_PINS);
0500     if (IS_ERR(pin_names))
0501         return PTR_ERR(pin_names);
0502 
0503     pins = devm_kcalloc(dev, BCM4908_NUM_PINS, sizeof(*pins), GFP_KERNEL);
0504     if (!pins)
0505         return -ENOMEM;
0506     for (i = 0; i < BCM4908_NUM_PINS; i++) {
0507         pins[i].number = i;
0508         pins[i].name = pin_names[i];
0509     }
0510     pctldesc->pins = pins;
0511     pctldesc->npins = BCM4908_NUM_PINS;
0512 
0513     /* Register */
0514 
0515     bcm4908_pinctrl->pctldev = devm_pinctrl_register(dev, pctldesc, bcm4908_pinctrl);
0516     if (IS_ERR(bcm4908_pinctrl->pctldev))
0517         return dev_err_probe(dev, PTR_ERR(bcm4908_pinctrl->pctldev),
0518                      "Failed to register pinctrl\n");
0519 
0520     /* Groups */
0521 
0522     for (i = 0; i < ARRAY_SIZE(bcm4908_pinctrl_grps); i++) {
0523         const struct bcm4908_pinctrl_grp *group = &bcm4908_pinctrl_grps[i];
0524         int *pins;
0525         int j;
0526 
0527         pins = devm_kcalloc(dev, group->num_pins, sizeof(*pins), GFP_KERNEL);
0528         if (!pins)
0529             return -ENOMEM;
0530         for (j = 0; j < group->num_pins; j++)
0531             pins[j] = group->pins[j].number;
0532 
0533         pinctrl_generic_add_group(bcm4908_pinctrl->pctldev, group->name,
0534                       pins, group->num_pins, (void *)group);
0535     }
0536 
0537     /* Functions */
0538 
0539     for (i = 0; i < ARRAY_SIZE(bcm4908_pinctrl_functions); i++) {
0540         const struct bcm4908_pinctrl_function *function = &bcm4908_pinctrl_functions[i];
0541 
0542         pinmux_generic_add_function(bcm4908_pinctrl->pctldev,
0543                         function->name,
0544                         function->groups,
0545                         function->num_groups, NULL);
0546     }
0547 
0548     return 0;
0549 }
0550 
0551 static struct platform_driver bcm4908_pinctrl_driver = {
0552     .probe = bcm4908_pinctrl_probe,
0553     .driver = {
0554         .name = "bcm4908-pinctrl",
0555         .of_match_table = bcm4908_pinctrl_of_match_table,
0556     },
0557 };
0558 
0559 module_platform_driver(bcm4908_pinctrl_driver);
0560 
0561 MODULE_AUTHOR("Rafał Miłecki");
0562 MODULE_LICENSE("GPL v2");
0563 MODULE_DEVICE_TABLE(of, bcm4908_pinctrl_of_match_table);