Maxime Ripard | 0e37f88 | 2013-01-18 22:30:34 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Allwinner A1X SoCs pinctrl driver. |
| 3 | * |
| 4 | * Copyright (C) 2012 Maxime Ripard |
| 5 | * |
| 6 | * Maxime Ripard <maxime.ripard@free-electrons.com> |
| 7 | * |
| 8 | * This file is licensed under the terms of the GNU General Public |
| 9 | * License version 2. This program is licensed "as is" without any |
| 10 | * warranty of any kind, whether express or implied. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/io.h> |
Maxime Ripard | 08e9e61 | 2013-01-28 21:33:12 +0100 | [diff] [blame^] | 14 | #include <linux/gpio.h> |
Maxime Ripard | 0e37f88 | 2013-01-18 22:30:34 +0100 | [diff] [blame] | 15 | #include <linux/module.h> |
| 16 | #include <linux/of.h> |
| 17 | #include <linux/of_address.h> |
| 18 | #include <linux/of_device.h> |
| 19 | #include <linux/pinctrl/consumer.h> |
| 20 | #include <linux/pinctrl/machine.h> |
| 21 | #include <linux/pinctrl/pinctrl.h> |
| 22 | #include <linux/pinctrl/pinconf-generic.h> |
| 23 | #include <linux/pinctrl/pinmux.h> |
| 24 | #include <linux/platform_device.h> |
| 25 | #include <linux/slab.h> |
| 26 | |
| 27 | #include "core.h" |
| 28 | #include "pinctrl-sunxi.h" |
| 29 | |
Maxime Ripard | eaa3d84 | 2013-01-18 22:30:35 +0100 | [diff] [blame] | 30 | static const struct sunxi_desc_pin sun5i_a13_pins[] = { |
| 31 | /* Hole */ |
| 32 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PB0, |
| 33 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 34 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 35 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PB1, |
| 36 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 37 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 38 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PB2, |
| 39 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 40 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 41 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PB3, |
| 42 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 43 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 44 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PB4, |
| 45 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 46 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 47 | /* Hole */ |
| 48 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PB10, |
| 49 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 50 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 51 | /* Hole */ |
| 52 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PB15, |
| 53 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 54 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 55 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PB16, |
| 56 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 57 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 58 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PB17, |
| 59 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 60 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 61 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PB18, |
| 62 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 63 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 64 | /* Hole */ |
| 65 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PC0, |
| 66 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 67 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 68 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PC1, |
| 69 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 70 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 71 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PC2, |
| 72 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 73 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 74 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PC3, |
| 75 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 76 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 77 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PC4, |
| 78 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 79 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 80 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PC5, |
| 81 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 82 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 83 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PC6, |
| 84 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 85 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 86 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PC7, |
| 87 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 88 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 89 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PC8, |
| 90 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 91 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 92 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PC9, |
| 93 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 94 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 95 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PC10, |
| 96 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 97 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 98 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PC11, |
| 99 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 100 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 101 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PC12, |
| 102 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 103 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 104 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PC13, |
| 105 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 106 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 107 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PC14, |
| 108 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 109 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 110 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PC15, |
| 111 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 112 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 113 | /* Hole */ |
| 114 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PC19, |
| 115 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 116 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 117 | /* Hole */ |
| 118 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PD2, |
| 119 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 120 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 121 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PD3, |
| 122 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 123 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 124 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PD4, |
| 125 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 126 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 127 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PD5, |
| 128 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 129 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 130 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PD6, |
| 131 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 132 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 133 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PD7, |
| 134 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 135 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 136 | /* Hole */ |
| 137 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PD10, |
| 138 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 139 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 140 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PD11, |
| 141 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 142 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 143 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PD12, |
| 144 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 145 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 146 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PD13, |
| 147 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 148 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 149 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PD14, |
| 150 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 151 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 152 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PD15, |
| 153 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 154 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 155 | /* Hole */ |
| 156 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PD18, |
| 157 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 158 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 159 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PD19, |
| 160 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 161 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 162 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PD20, |
| 163 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 164 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 165 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PD21, |
| 166 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 167 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 168 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PD22, |
| 169 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 170 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 171 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PD23, |
| 172 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 173 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 174 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PD24, |
| 175 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 176 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 177 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PD25, |
| 178 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 179 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 180 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PD26, |
| 181 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 182 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 183 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PD27, |
| 184 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 185 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 186 | /* Hole */ |
| 187 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PE0, |
| 188 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 189 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 190 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PE1, |
| 191 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 192 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 193 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PE2, |
| 194 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 195 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 196 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PE3, |
| 197 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 198 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 199 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PE4, |
| 200 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 201 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 202 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PE5, |
| 203 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 204 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 205 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PE6, |
| 206 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 207 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 208 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PE7, |
| 209 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 210 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 211 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PE8, |
| 212 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 213 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 214 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PE9, |
| 215 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 216 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 217 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PE10, |
| 218 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 219 | SUNXI_FUNCTION(0x1, "gpio_out"), |
| 220 | SUNXI_FUNCTION(0x4, "uart1")), |
| 221 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PE11, |
| 222 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 223 | SUNXI_FUNCTION(0x1, "gpio_out"), |
| 224 | SUNXI_FUNCTION(0x4, "uart1")), |
| 225 | /* Hole */ |
| 226 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PF0, |
| 227 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 228 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 229 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PF1, |
| 230 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 231 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 232 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PF2, |
| 233 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 234 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 235 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PF3, |
| 236 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 237 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 238 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PF4, |
| 239 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 240 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 241 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PF5, |
| 242 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 243 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 244 | /* Hole */ |
| 245 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PG0, |
| 246 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 247 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 248 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PG1, |
| 249 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 250 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 251 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PG2, |
| 252 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 253 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 254 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PG3, |
| 255 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 256 | SUNXI_FUNCTION(0x1, "gpio_out"), |
| 257 | SUNXI_FUNCTION(0x4, "uart1")), |
| 258 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PG4, |
| 259 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 260 | SUNXI_FUNCTION(0x1, "gpio_out"), |
| 261 | SUNXI_FUNCTION(0x4, "uart1")), |
| 262 | /* Hole */ |
| 263 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PG9, |
| 264 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 265 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 266 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PG10, |
| 267 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 268 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 269 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PG11, |
| 270 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 271 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 272 | SUNXI_PIN(SUNXI_PINCTRL_PIN_PG12, |
| 273 | SUNXI_FUNCTION(0x0, "gpio_in"), |
| 274 | SUNXI_FUNCTION(0x1, "gpio_out")), |
| 275 | }; |
| 276 | |
| 277 | static const struct sunxi_pinctrl_desc sun5i_a13_pinctrl_data = { |
| 278 | .pins = sun5i_a13_pins, |
| 279 | .npins = ARRAY_SIZE(sun5i_a13_pins), |
| 280 | }; |
| 281 | |
Maxime Ripard | 0e37f88 | 2013-01-18 22:30:34 +0100 | [diff] [blame] | 282 | static struct sunxi_pinctrl_group * |
| 283 | sunxi_pinctrl_find_group_by_name(struct sunxi_pinctrl *pctl, const char *group) |
| 284 | { |
| 285 | int i; |
| 286 | |
| 287 | for (i = 0; i < pctl->ngroups; i++) { |
| 288 | struct sunxi_pinctrl_group *grp = pctl->groups + i; |
| 289 | |
| 290 | if (!strcmp(grp->name, group)) |
| 291 | return grp; |
| 292 | } |
| 293 | |
| 294 | return NULL; |
| 295 | } |
| 296 | |
| 297 | static struct sunxi_pinctrl_function * |
| 298 | sunxi_pinctrl_find_function_by_name(struct sunxi_pinctrl *pctl, |
| 299 | const char *name) |
| 300 | { |
| 301 | struct sunxi_pinctrl_function *func = pctl->functions; |
| 302 | int i; |
| 303 | |
| 304 | for (i = 0; i < pctl->nfunctions; i++) { |
| 305 | if (!func[i].name) |
| 306 | break; |
| 307 | |
| 308 | if (!strcmp(func[i].name, name)) |
| 309 | return func + i; |
| 310 | } |
| 311 | |
| 312 | return NULL; |
| 313 | } |
| 314 | |
| 315 | static struct sunxi_desc_function * |
| 316 | sunxi_pinctrl_desc_find_function_by_name(struct sunxi_pinctrl *pctl, |
| 317 | const char *pin_name, |
| 318 | const char *func_name) |
| 319 | { |
| 320 | int i; |
| 321 | |
| 322 | for (i = 0; i < pctl->desc->npins; i++) { |
| 323 | const struct sunxi_desc_pin *pin = pctl->desc->pins + i; |
| 324 | |
| 325 | if (!strcmp(pin->pin.name, pin_name)) { |
| 326 | struct sunxi_desc_function *func = pin->functions; |
| 327 | |
| 328 | while (func->name) { |
| 329 | if (!strcmp(func->name, func_name)) |
| 330 | return func; |
| 331 | |
| 332 | func++; |
| 333 | } |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | return NULL; |
| 338 | } |
| 339 | |
| 340 | static int sunxi_pctrl_get_groups_count(struct pinctrl_dev *pctldev) |
| 341 | { |
| 342 | struct sunxi_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); |
| 343 | |
| 344 | return pctl->ngroups; |
| 345 | } |
| 346 | |
| 347 | static const char *sunxi_pctrl_get_group_name(struct pinctrl_dev *pctldev, |
| 348 | unsigned group) |
| 349 | { |
| 350 | struct sunxi_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); |
| 351 | |
| 352 | return pctl->groups[group].name; |
| 353 | } |
| 354 | |
| 355 | static int sunxi_pctrl_get_group_pins(struct pinctrl_dev *pctldev, |
| 356 | unsigned group, |
| 357 | const unsigned **pins, |
| 358 | unsigned *num_pins) |
| 359 | { |
| 360 | struct sunxi_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); |
| 361 | |
| 362 | *pins = (unsigned *)&pctl->groups[group].pin; |
| 363 | *num_pins = 1; |
| 364 | |
| 365 | return 0; |
| 366 | } |
| 367 | |
| 368 | static int sunxi_pctrl_dt_node_to_map(struct pinctrl_dev *pctldev, |
| 369 | struct device_node *node, |
| 370 | struct pinctrl_map **map, |
| 371 | unsigned *num_maps) |
| 372 | { |
| 373 | struct sunxi_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); |
| 374 | unsigned long *pinconfig; |
| 375 | struct property *prop; |
| 376 | const char *function; |
| 377 | const char *group; |
| 378 | int ret, nmaps, i = 0; |
| 379 | u32 val; |
| 380 | |
| 381 | *map = NULL; |
| 382 | *num_maps = 0; |
| 383 | |
| 384 | ret = of_property_read_string(node, "allwinner,function", &function); |
| 385 | if (ret) { |
| 386 | dev_err(pctl->dev, |
| 387 | "missing allwinner,function property in node %s\n", |
| 388 | node->name); |
| 389 | return -EINVAL; |
| 390 | } |
| 391 | |
| 392 | nmaps = of_property_count_strings(node, "allwinner,pins") * 2; |
| 393 | if (nmaps < 0) { |
| 394 | dev_err(pctl->dev, |
| 395 | "missing allwinner,pins property in node %s\n", |
| 396 | node->name); |
| 397 | return -EINVAL; |
| 398 | } |
| 399 | |
| 400 | *map = kmalloc(nmaps * sizeof(struct pinctrl_map), GFP_KERNEL); |
| 401 | if (!map) |
| 402 | return -ENOMEM; |
| 403 | |
| 404 | of_property_for_each_string(node, "allwinner,pins", prop, group) { |
| 405 | struct sunxi_pinctrl_group *grp = |
| 406 | sunxi_pinctrl_find_group_by_name(pctl, group); |
| 407 | int j = 0, configlen = 0; |
| 408 | |
| 409 | if (!grp) { |
| 410 | dev_err(pctl->dev, "unknown pin %s", group); |
| 411 | continue; |
| 412 | } |
| 413 | |
| 414 | if (!sunxi_pinctrl_desc_find_function_by_name(pctl, |
| 415 | grp->name, |
| 416 | function)) { |
| 417 | dev_err(pctl->dev, "unsupported function %s on pin %s", |
| 418 | function, group); |
| 419 | continue; |
| 420 | } |
| 421 | |
| 422 | (*map)[i].type = PIN_MAP_TYPE_MUX_GROUP; |
| 423 | (*map)[i].data.mux.group = group; |
| 424 | (*map)[i].data.mux.function = function; |
| 425 | |
| 426 | i++; |
| 427 | |
| 428 | (*map)[i].type = PIN_MAP_TYPE_CONFIGS_GROUP; |
| 429 | (*map)[i].data.configs.group_or_pin = group; |
| 430 | |
| 431 | if (of_find_property(node, "allwinner,drive", NULL)) |
| 432 | configlen++; |
| 433 | if (of_find_property(node, "allwinner,pull", NULL)) |
| 434 | configlen++; |
| 435 | |
| 436 | pinconfig = kzalloc(configlen * sizeof(*pinconfig), GFP_KERNEL); |
| 437 | |
| 438 | if (!of_property_read_u32(node, "allwinner,drive", &val)) { |
| 439 | u16 strength = (val + 1) * 10; |
| 440 | pinconfig[j++] = |
| 441 | pinconf_to_config_packed(PIN_CONFIG_DRIVE_STRENGTH, |
| 442 | strength); |
| 443 | } |
| 444 | |
| 445 | if (!of_property_read_u32(node, "allwinner,pull", &val)) { |
| 446 | enum pin_config_param pull = PIN_CONFIG_END; |
| 447 | if (val == 1) |
| 448 | pull = PIN_CONFIG_BIAS_PULL_UP; |
| 449 | else if (val == 2) |
| 450 | pull = PIN_CONFIG_BIAS_PULL_DOWN; |
| 451 | pinconfig[j++] = pinconf_to_config_packed(pull, 0); |
| 452 | } |
| 453 | |
| 454 | (*map)[i].data.configs.configs = pinconfig; |
| 455 | (*map)[i].data.configs.num_configs = configlen; |
| 456 | |
| 457 | i++; |
| 458 | } |
| 459 | |
| 460 | *num_maps = nmaps; |
| 461 | |
| 462 | return 0; |
| 463 | } |
| 464 | |
| 465 | static void sunxi_pctrl_dt_free_map(struct pinctrl_dev *pctldev, |
| 466 | struct pinctrl_map *map, |
| 467 | unsigned num_maps) |
| 468 | { |
| 469 | int i; |
| 470 | |
| 471 | for (i = 0; i < num_maps; i++) { |
| 472 | if (map[i].type == PIN_MAP_TYPE_CONFIGS_GROUP) |
| 473 | kfree(map[i].data.configs.configs); |
| 474 | } |
| 475 | |
| 476 | kfree(map); |
| 477 | } |
| 478 | |
| 479 | static struct pinctrl_ops sunxi_pctrl_ops = { |
| 480 | .dt_node_to_map = sunxi_pctrl_dt_node_to_map, |
| 481 | .dt_free_map = sunxi_pctrl_dt_free_map, |
| 482 | .get_groups_count = sunxi_pctrl_get_groups_count, |
| 483 | .get_group_name = sunxi_pctrl_get_group_name, |
| 484 | .get_group_pins = sunxi_pctrl_get_group_pins, |
| 485 | }; |
| 486 | |
| 487 | static int sunxi_pconf_group_get(struct pinctrl_dev *pctldev, |
| 488 | unsigned group, |
| 489 | unsigned long *config) |
| 490 | { |
| 491 | struct sunxi_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); |
| 492 | |
| 493 | *config = pctl->groups[group].config; |
| 494 | |
| 495 | return 0; |
| 496 | } |
| 497 | |
| 498 | static int sunxi_pconf_group_set(struct pinctrl_dev *pctldev, |
| 499 | unsigned group, |
| 500 | unsigned long config) |
| 501 | { |
| 502 | struct sunxi_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); |
| 503 | struct sunxi_pinctrl_group *g = &pctl->groups[group]; |
| 504 | u32 val, mask; |
| 505 | u16 strength; |
| 506 | u8 dlevel; |
| 507 | |
| 508 | switch (pinconf_to_config_param(config)) { |
| 509 | case PIN_CONFIG_DRIVE_STRENGTH: |
| 510 | strength = pinconf_to_config_argument(config); |
| 511 | if (strength > 40) |
| 512 | return -EINVAL; |
| 513 | /* |
| 514 | * We convert from mA to what the register expects: |
| 515 | * 0: 10mA |
| 516 | * 1: 20mA |
| 517 | * 2: 30mA |
| 518 | * 3: 40mA |
| 519 | */ |
| 520 | dlevel = strength / 10 - 1; |
| 521 | val = readl(pctl->membase + sunxi_dlevel_reg(g->pin)); |
| 522 | mask = DLEVEL_PINS_MASK << sunxi_dlevel_offset(g->pin); |
| 523 | writel((val & ~mask) | dlevel << sunxi_dlevel_offset(g->pin), |
| 524 | pctl->membase + sunxi_dlevel_reg(g->pin)); |
| 525 | break; |
| 526 | case PIN_CONFIG_BIAS_PULL_UP: |
| 527 | val = readl(pctl->membase + sunxi_pull_reg(g->pin)); |
| 528 | mask = PULL_PINS_MASK << sunxi_pull_offset(g->pin); |
| 529 | writel((val & ~mask) | 1 << sunxi_pull_offset(g->pin), |
| 530 | pctl->membase + sunxi_pull_reg(g->pin)); |
| 531 | break; |
| 532 | case PIN_CONFIG_BIAS_PULL_DOWN: |
| 533 | val = readl(pctl->membase + sunxi_pull_reg(g->pin)); |
| 534 | mask = PULL_PINS_MASK << sunxi_pull_offset(g->pin); |
| 535 | writel((val & ~mask) | 2 << sunxi_pull_offset(g->pin), |
| 536 | pctl->membase + sunxi_pull_reg(g->pin)); |
| 537 | break; |
| 538 | default: |
| 539 | break; |
| 540 | } |
| 541 | |
| 542 | /* cache the config value */ |
| 543 | g->config = config; |
| 544 | |
| 545 | return 0; |
| 546 | } |
| 547 | |
| 548 | static struct pinconf_ops sunxi_pconf_ops = { |
| 549 | .pin_config_group_get = sunxi_pconf_group_get, |
| 550 | .pin_config_group_set = sunxi_pconf_group_set, |
| 551 | }; |
| 552 | |
| 553 | static int sunxi_pmx_get_funcs_cnt(struct pinctrl_dev *pctldev) |
| 554 | { |
| 555 | struct sunxi_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); |
| 556 | |
| 557 | return pctl->nfunctions; |
| 558 | } |
| 559 | |
| 560 | static const char *sunxi_pmx_get_func_name(struct pinctrl_dev *pctldev, |
| 561 | unsigned function) |
| 562 | { |
| 563 | struct sunxi_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); |
| 564 | |
| 565 | return pctl->functions[function].name; |
| 566 | } |
| 567 | |
| 568 | static int sunxi_pmx_get_func_groups(struct pinctrl_dev *pctldev, |
| 569 | unsigned function, |
| 570 | const char * const **groups, |
| 571 | unsigned * const num_groups) |
| 572 | { |
| 573 | struct sunxi_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); |
| 574 | |
| 575 | *groups = pctl->functions[function].groups; |
| 576 | *num_groups = pctl->functions[function].ngroups; |
| 577 | |
| 578 | return 0; |
| 579 | } |
| 580 | |
| 581 | static void sunxi_pmx_set(struct pinctrl_dev *pctldev, |
| 582 | unsigned pin, |
| 583 | u8 config) |
| 584 | { |
| 585 | struct sunxi_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); |
| 586 | |
| 587 | u32 val = readl(pctl->membase + sunxi_mux_reg(pin)); |
| 588 | u32 mask = MUX_PINS_MASK << sunxi_mux_offset(pin); |
| 589 | writel((val & ~mask) | config << sunxi_mux_offset(pin), |
| 590 | pctl->membase + sunxi_mux_reg(pin)); |
| 591 | } |
| 592 | |
| 593 | static int sunxi_pmx_enable(struct pinctrl_dev *pctldev, |
| 594 | unsigned function, |
| 595 | unsigned group) |
| 596 | { |
| 597 | struct sunxi_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); |
| 598 | struct sunxi_pinctrl_group *g = pctl->groups + group; |
| 599 | struct sunxi_pinctrl_function *func = pctl->functions + function; |
| 600 | struct sunxi_desc_function *desc = |
| 601 | sunxi_pinctrl_desc_find_function_by_name(pctl, |
| 602 | g->name, |
| 603 | func->name); |
| 604 | |
| 605 | if (!desc) |
| 606 | return -EINVAL; |
| 607 | |
| 608 | sunxi_pmx_set(pctldev, g->pin, desc->muxval); |
| 609 | |
| 610 | return 0; |
| 611 | } |
| 612 | |
Maxime Ripard | 08e9e61 | 2013-01-28 21:33:12 +0100 | [diff] [blame^] | 613 | static int |
| 614 | sunxi_pmx_gpio_set_direction(struct pinctrl_dev *pctldev, |
| 615 | struct pinctrl_gpio_range *range, |
| 616 | unsigned offset, |
| 617 | bool input) |
| 618 | { |
| 619 | struct sunxi_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); |
| 620 | struct sunxi_desc_function *desc; |
| 621 | char pin_name[SUNXI_PIN_NAME_MAX_LEN]; |
| 622 | const char *func; |
| 623 | u8 bank, pin; |
| 624 | int ret; |
| 625 | |
| 626 | bank = (offset) / PINS_PER_BANK; |
| 627 | pin = (offset) % PINS_PER_BANK; |
| 628 | |
| 629 | ret = sprintf(pin_name, "P%c%d", 'A' + bank, pin); |
| 630 | if (!ret) |
| 631 | goto error; |
| 632 | |
| 633 | if (input) |
| 634 | func = "gpio_in"; |
| 635 | else |
| 636 | func = "gpio_out"; |
| 637 | |
| 638 | desc = sunxi_pinctrl_desc_find_function_by_name(pctl, |
| 639 | pin_name, |
| 640 | func); |
| 641 | if (!desc) { |
| 642 | ret = -EINVAL; |
| 643 | goto error; |
| 644 | } |
| 645 | |
| 646 | sunxi_pmx_set(pctldev, offset, desc->muxval); |
| 647 | |
| 648 | ret = 0; |
| 649 | |
| 650 | error: |
| 651 | return ret; |
| 652 | } |
| 653 | |
Maxime Ripard | 0e37f88 | 2013-01-18 22:30:34 +0100 | [diff] [blame] | 654 | static struct pinmux_ops sunxi_pmx_ops = { |
| 655 | .get_functions_count = sunxi_pmx_get_funcs_cnt, |
| 656 | .get_function_name = sunxi_pmx_get_func_name, |
| 657 | .get_function_groups = sunxi_pmx_get_func_groups, |
| 658 | .enable = sunxi_pmx_enable, |
Maxime Ripard | 08e9e61 | 2013-01-28 21:33:12 +0100 | [diff] [blame^] | 659 | .gpio_set_direction = sunxi_pmx_gpio_set_direction, |
Maxime Ripard | 0e37f88 | 2013-01-18 22:30:34 +0100 | [diff] [blame] | 660 | }; |
| 661 | |
| 662 | static struct pinctrl_desc sunxi_pctrl_desc = { |
| 663 | .confops = &sunxi_pconf_ops, |
| 664 | .pctlops = &sunxi_pctrl_ops, |
| 665 | .pmxops = &sunxi_pmx_ops, |
| 666 | }; |
| 667 | |
Maxime Ripard | 08e9e61 | 2013-01-28 21:33:12 +0100 | [diff] [blame^] | 668 | static int sunxi_pinctrl_gpio_request(struct gpio_chip *chip, unsigned offset) |
| 669 | { |
| 670 | return pinctrl_request_gpio(chip->base + offset); |
| 671 | } |
| 672 | |
| 673 | static void sunxi_pinctrl_gpio_free(struct gpio_chip *chip, unsigned offset) |
| 674 | { |
| 675 | pinctrl_free_gpio(chip->base + offset); |
| 676 | } |
| 677 | |
| 678 | static int sunxi_pinctrl_gpio_direction_input(struct gpio_chip *chip, |
| 679 | unsigned offset) |
| 680 | { |
| 681 | return pinctrl_gpio_direction_input(chip->base + offset); |
| 682 | } |
| 683 | |
| 684 | static int sunxi_pinctrl_gpio_get(struct gpio_chip *chip, unsigned offset) |
| 685 | { |
| 686 | struct sunxi_pinctrl *pctl = dev_get_drvdata(chip->dev); |
| 687 | |
| 688 | u32 reg = sunxi_data_reg(offset); |
| 689 | u8 index = sunxi_data_offset(offset); |
| 690 | u32 val = (readl(pctl->membase + reg) >> index) & DATA_PINS_MASK; |
| 691 | |
| 692 | return val; |
| 693 | } |
| 694 | |
| 695 | static int sunxi_pinctrl_gpio_direction_output(struct gpio_chip *chip, |
| 696 | unsigned offset, int value) |
| 697 | { |
| 698 | return pinctrl_gpio_direction_output(chip->base + offset); |
| 699 | } |
| 700 | |
| 701 | static void sunxi_pinctrl_gpio_set(struct gpio_chip *chip, |
| 702 | unsigned offset, int value) |
| 703 | { |
| 704 | struct sunxi_pinctrl *pctl = dev_get_drvdata(chip->dev); |
| 705 | u32 reg = sunxi_data_reg(offset); |
| 706 | u8 index = sunxi_data_offset(offset); |
| 707 | |
| 708 | writel((value & DATA_PINS_MASK) << index, pctl->membase + reg); |
| 709 | } |
| 710 | |
| 711 | static struct gpio_chip sunxi_pinctrl_gpio_chip = { |
| 712 | .owner = THIS_MODULE, |
| 713 | .request = sunxi_pinctrl_gpio_request, |
| 714 | .free = sunxi_pinctrl_gpio_free, |
| 715 | .direction_input = sunxi_pinctrl_gpio_direction_input, |
| 716 | .direction_output = sunxi_pinctrl_gpio_direction_output, |
| 717 | .get = sunxi_pinctrl_gpio_get, |
| 718 | .set = sunxi_pinctrl_gpio_set, |
| 719 | .can_sleep = 0, |
| 720 | }; |
| 721 | |
Maxime Ripard | 0e37f88 | 2013-01-18 22:30:34 +0100 | [diff] [blame] | 722 | static struct of_device_id sunxi_pinctrl_match[] = { |
Maxime Ripard | eaa3d84 | 2013-01-18 22:30:35 +0100 | [diff] [blame] | 723 | { .compatible = "allwinner,sun5i-a13-pinctrl", .data = (void *)&sun5i_a13_pinctrl_data }, |
Maxime Ripard | 0e37f88 | 2013-01-18 22:30:34 +0100 | [diff] [blame] | 724 | {} |
| 725 | }; |
| 726 | MODULE_DEVICE_TABLE(of, sunxi_pinctrl_match); |
| 727 | |
| 728 | static int sunxi_pinctrl_add_function(struct sunxi_pinctrl *pctl, |
| 729 | const char *name) |
| 730 | { |
| 731 | struct sunxi_pinctrl_function *func = pctl->functions; |
| 732 | |
| 733 | while (func->name) { |
| 734 | /* function already there */ |
| 735 | if (strcmp(func->name, name) == 0) { |
| 736 | func->ngroups++; |
| 737 | return -EEXIST; |
| 738 | } |
| 739 | func++; |
| 740 | } |
| 741 | |
| 742 | func->name = name; |
| 743 | func->ngroups = 1; |
| 744 | |
| 745 | pctl->nfunctions++; |
| 746 | |
| 747 | return 0; |
| 748 | } |
| 749 | |
| 750 | static int sunxi_pinctrl_build_state(struct platform_device *pdev) |
| 751 | { |
| 752 | struct sunxi_pinctrl *pctl = platform_get_drvdata(pdev); |
| 753 | int i; |
| 754 | |
| 755 | pctl->ngroups = pctl->desc->npins; |
| 756 | |
| 757 | /* Allocate groups */ |
| 758 | pctl->groups = devm_kzalloc(&pdev->dev, |
| 759 | pctl->ngroups * sizeof(*pctl->groups), |
| 760 | GFP_KERNEL); |
| 761 | if (!pctl->groups) |
| 762 | return -ENOMEM; |
| 763 | |
| 764 | for (i = 0; i < pctl->desc->npins; i++) { |
| 765 | const struct sunxi_desc_pin *pin = pctl->desc->pins + i; |
| 766 | struct sunxi_pinctrl_group *group = pctl->groups + i; |
| 767 | |
| 768 | group->name = pin->pin.name; |
| 769 | group->pin = pin->pin.number; |
| 770 | } |
| 771 | |
| 772 | /* |
| 773 | * We suppose that we won't have any more functions than pins, |
| 774 | * we'll reallocate that later anyway |
| 775 | */ |
| 776 | pctl->functions = devm_kzalloc(&pdev->dev, |
| 777 | pctl->desc->npins * sizeof(*pctl->functions), |
| 778 | GFP_KERNEL); |
| 779 | if (!pctl->functions) |
| 780 | return -ENOMEM; |
| 781 | |
| 782 | /* Count functions and their associated groups */ |
| 783 | for (i = 0; i < pctl->desc->npins; i++) { |
| 784 | const struct sunxi_desc_pin *pin = pctl->desc->pins + i; |
| 785 | struct sunxi_desc_function *func = pin->functions; |
| 786 | |
| 787 | while (func->name) { |
| 788 | sunxi_pinctrl_add_function(pctl, func->name); |
| 789 | func++; |
| 790 | } |
| 791 | } |
| 792 | |
| 793 | pctl->functions = krealloc(pctl->functions, |
| 794 | pctl->nfunctions * sizeof(*pctl->functions), |
| 795 | GFP_KERNEL); |
| 796 | |
| 797 | for (i = 0; i < pctl->desc->npins; i++) { |
| 798 | const struct sunxi_desc_pin *pin = pctl->desc->pins + i; |
| 799 | struct sunxi_desc_function *func = pin->functions; |
| 800 | |
| 801 | while (func->name) { |
| 802 | struct sunxi_pinctrl_function *func_item; |
| 803 | const char **func_grp; |
| 804 | |
| 805 | func_item = sunxi_pinctrl_find_function_by_name(pctl, |
| 806 | func->name); |
| 807 | if (!func_item) |
| 808 | return -EINVAL; |
| 809 | |
| 810 | if (!func_item->groups) { |
| 811 | func_item->groups = |
| 812 | devm_kzalloc(&pdev->dev, |
| 813 | func_item->ngroups * sizeof(*func_item->groups), |
| 814 | GFP_KERNEL); |
| 815 | if (!func_item->groups) |
| 816 | return -ENOMEM; |
| 817 | } |
| 818 | |
| 819 | func_grp = func_item->groups; |
| 820 | while (*func_grp) |
| 821 | func_grp++; |
| 822 | |
| 823 | *func_grp = pin->pin.name; |
| 824 | func++; |
| 825 | } |
| 826 | } |
| 827 | |
| 828 | return 0; |
| 829 | } |
| 830 | |
| 831 | static int sunxi_pinctrl_probe(struct platform_device *pdev) |
| 832 | { |
| 833 | struct device_node *node = pdev->dev.of_node; |
| 834 | const struct of_device_id *device; |
| 835 | struct pinctrl_pin_desc *pins; |
| 836 | struct sunxi_pinctrl *pctl; |
Maxime Ripard | 08e9e61 | 2013-01-28 21:33:12 +0100 | [diff] [blame^] | 837 | int i, ret, last_pin; |
Maxime Ripard | 0e37f88 | 2013-01-18 22:30:34 +0100 | [diff] [blame] | 838 | |
| 839 | pctl = devm_kzalloc(&pdev->dev, sizeof(*pctl), GFP_KERNEL); |
| 840 | if (!pctl) |
| 841 | return -ENOMEM; |
| 842 | platform_set_drvdata(pdev, pctl); |
| 843 | |
| 844 | pctl->membase = of_iomap(node, 0); |
| 845 | if (!pctl->membase) |
| 846 | return -ENOMEM; |
| 847 | |
| 848 | device = of_match_device(sunxi_pinctrl_match, &pdev->dev); |
| 849 | if (!device) |
| 850 | return -ENODEV; |
| 851 | |
| 852 | pctl->desc = (struct sunxi_pinctrl_desc *)device->data; |
| 853 | |
| 854 | ret = sunxi_pinctrl_build_state(pdev); |
| 855 | if (ret) { |
| 856 | dev_err(&pdev->dev, "dt probe failed: %d\n", ret); |
| 857 | return ret; |
| 858 | } |
| 859 | |
| 860 | pins = devm_kzalloc(&pdev->dev, |
| 861 | pctl->desc->npins * sizeof(*pins), |
| 862 | GFP_KERNEL); |
| 863 | if (!pins) |
| 864 | return -ENOMEM; |
| 865 | |
| 866 | for (i = 0; i < pctl->desc->npins; i++) |
| 867 | pins[i] = pctl->desc->pins[i].pin; |
| 868 | |
| 869 | sunxi_pctrl_desc.name = dev_name(&pdev->dev); |
| 870 | sunxi_pctrl_desc.owner = THIS_MODULE; |
| 871 | sunxi_pctrl_desc.pins = pins; |
| 872 | sunxi_pctrl_desc.npins = pctl->desc->npins; |
| 873 | pctl->dev = &pdev->dev; |
| 874 | pctl->pctl_dev = pinctrl_register(&sunxi_pctrl_desc, |
| 875 | &pdev->dev, pctl); |
| 876 | if (!pctl->pctl_dev) { |
| 877 | dev_err(&pdev->dev, "couldn't register pinctrl driver\n"); |
| 878 | return -EINVAL; |
| 879 | } |
| 880 | |
Maxime Ripard | 08e9e61 | 2013-01-28 21:33:12 +0100 | [diff] [blame^] | 881 | pctl->chip = devm_kzalloc(&pdev->dev, sizeof(*pctl->chip), GFP_KERNEL); |
| 882 | if (!pctl->chip) { |
| 883 | ret = -ENOMEM; |
| 884 | goto pinctrl_error; |
| 885 | } |
| 886 | |
| 887 | last_pin = pctl->desc->pins[pctl->desc->npins - 1].pin.number; |
| 888 | pctl->chip = &sunxi_pinctrl_gpio_chip; |
| 889 | pctl->chip->ngpio = round_up(last_pin, PINS_PER_BANK); |
| 890 | pctl->chip->label = dev_name(&pdev->dev); |
| 891 | pctl->chip->dev = &pdev->dev; |
| 892 | pctl->chip->base = 0; |
| 893 | |
| 894 | ret = gpiochip_add(pctl->chip); |
| 895 | if (ret) |
| 896 | goto pinctrl_error; |
| 897 | |
| 898 | for (i = 0; i < pctl->desc->npins; i++) { |
| 899 | const struct sunxi_desc_pin *pin = pctl->desc->pins + i; |
| 900 | |
| 901 | ret = gpiochip_add_pin_range(pctl->chip, dev_name(&pdev->dev), |
| 902 | pin->pin.number, |
| 903 | pin->pin.number, 1); |
| 904 | if (ret) |
| 905 | goto gpiochip_error; |
| 906 | } |
| 907 | |
| 908 | dev_info(&pdev->dev, "initialized sunXi PIO driver\n"); |
Maxime Ripard | 0e37f88 | 2013-01-18 22:30:34 +0100 | [diff] [blame] | 909 | |
| 910 | return 0; |
Maxime Ripard | 08e9e61 | 2013-01-28 21:33:12 +0100 | [diff] [blame^] | 911 | |
| 912 | gpiochip_error: |
| 913 | ret = gpiochip_remove(pctl->chip); |
| 914 | pinctrl_error: |
| 915 | pinctrl_unregister(pctl->pctl_dev); |
| 916 | return ret; |
Maxime Ripard | 0e37f88 | 2013-01-18 22:30:34 +0100 | [diff] [blame] | 917 | } |
| 918 | |
| 919 | static struct platform_driver sunxi_pinctrl_driver = { |
| 920 | .probe = sunxi_pinctrl_probe, |
| 921 | .driver = { |
| 922 | .name = "sunxi-pinctrl", |
| 923 | .owner = THIS_MODULE, |
| 924 | .of_match_table = sunxi_pinctrl_match, |
| 925 | }, |
| 926 | }; |
| 927 | module_platform_driver(sunxi_pinctrl_driver); |
| 928 | |
| 929 | MODULE_AUTHOR("Maxime Ripard <maxime.ripard@free-electrons.com"); |
| 930 | MODULE_DESCRIPTION("Allwinner A1X pinctrl driver"); |
| 931 | MODULE_LICENSE("GPL"); |