1 /* 2 * Driver header file for the ST Microelectronics SPEAr pinmux 3 * 4 * Copyright (C) 2012 ST Microelectronics 5 * Viresh Kumar <viresh.linux@gmail.com> 6 * 7 * This file is licensed under the terms of the GNU General Public 8 * License version 2. This program is licensed "as is" without any 9 * warranty of any kind, whether express or implied. 10 */ 11 12 #ifndef __PINMUX_SPEAR_H__ 13 #define __PINMUX_SPEAR_H__ 14 15 #include <linux/gpio.h> 16 #include <linux/io.h> 17 #include <linux/pinctrl/pinctrl.h> 18 #include <linux/types.h> 19 20 struct platform_device; 21 struct device; 22 struct spear_pmx; 23 24 /** 25 * struct spear_pmx_mode - SPEAr pmx mode 26 * @name: name of pmx mode 27 * @mode: mode id 28 * @reg: register for configuring this mode 29 * @mask: mask of this mode in reg 30 * @val: val to be configured at reg after doing (val & mask) 31 */ 32 struct spear_pmx_mode { 33 const char *const name; 34 u16 mode; 35 u16 reg; 36 u16 mask; 37 u32 val; 38 }; 39 40 /** 41 * struct spear_muxreg - SPEAr mux reg configuration 42 * @reg: register offset 43 * @mask: mask bits 44 * @val: val to be written on mask bits 45 */ 46 struct spear_muxreg { 47 u16 reg; 48 u32 mask; 49 u32 val; 50 }; 51 52 struct spear_gpio_pingroup { 53 const unsigned *pins; 54 unsigned npins; 55 struct spear_muxreg *muxregs; 56 u8 nmuxregs; 57 }; 58 59 /* ste: set to enable */ 60 #define DEFINE_MUXREG(__pins, __muxreg, __mask, __ste) \ 61 static struct spear_muxreg __pins##_muxregs[] = { \ 62 { \ 63 .reg = __muxreg, \ 64 .mask = __mask, \ 65 .val = __ste ? __mask : 0, \ 66 }, \ 67 } 68 69 #define DEFINE_2_MUXREG(__pins, __muxreg1, __muxreg2, __mask, __ste1, __ste2) \ 70 static struct spear_muxreg __pins##_muxregs[] = { \ 71 { \ 72 .reg = __muxreg1, \ 73 .mask = __mask, \ 74 .val = __ste1 ? __mask : 0, \ 75 }, { \ 76 .reg = __muxreg2, \ 77 .mask = __mask, \ 78 .val = __ste2 ? __mask : 0, \ 79 }, \ 80 } 81 82 #define GPIO_PINGROUP(__pins) \ 83 { \ 84 .pins = __pins, \ 85 .npins = ARRAY_SIZE(__pins), \ 86 .muxregs = __pins##_muxregs, \ 87 .nmuxregs = ARRAY_SIZE(__pins##_muxregs), \ 88 } 89 90 /** 91 * struct spear_modemux - SPEAr mode mux configuration 92 * @modes: mode ids supported by this group of muxregs 93 * @nmuxregs: number of muxreg configurations to be done for modes 94 * @muxregs: array of muxreg configurations to be done for modes 95 */ 96 struct spear_modemux { 97 u16 modes; 98 u8 nmuxregs; 99 struct spear_muxreg *muxregs; 100 }; 101 102 /** 103 * struct spear_pingroup - SPEAr pin group configurations 104 * @name: name of pin group 105 * @pins: array containing pin numbers 106 * @npins: size of pins array 107 * @modemuxs: array of modemux configurations for this pin group 108 * @nmodemuxs: size of array modemuxs 109 * 110 * A representation of a group of pins in the SPEAr pin controller. Each group 111 * allows some parameter or parameters to be configured. 112 */ 113 struct spear_pingroup { 114 const char *name; 115 const unsigned *pins; 116 unsigned npins; 117 struct spear_modemux *modemuxs; 118 unsigned nmodemuxs; 119 }; 120 121 /** 122 * struct spear_function - SPEAr pinctrl mux function 123 * @name: The name of the function, exported to pinctrl core. 124 * @groups: An array of pin groups that may select this function. 125 * @ngroups: The number of entries in @groups. 126 */ 127 struct spear_function { 128 const char *name; 129 const char *const *groups; 130 unsigned ngroups; 131 }; 132 133 /** 134 * struct spear_pinctrl_machdata - SPEAr pin controller machine driver 135 * configuration 136 * @pins: An array describing all pins the pin controller affects. 137 * All pins which are also GPIOs must be listed first within the *array, 138 * and be numbered identically to the GPIO controller's *numbering. 139 * @npins: The numbmer of entries in @pins. 140 * @functions: An array describing all mux functions the SoC supports. 141 * @nfunctions: The numbmer of entries in @functions. 142 * @groups: An array describing all pin groups the pin SoC supports. 143 * @ngroups: The numbmer of entries in @groups. 144 * @gpio_pingroups: gpio pingroups 145 * @ngpio_pingroups: gpio pingroups count 146 * 147 * @modes_supported: Does SoC support modes 148 * @mode: mode configured from probe 149 * @pmx_modes: array of modes supported by SoC 150 * @npmx_modes: number of entries in pmx_modes. 151 */ 152 struct spear_pinctrl_machdata { 153 const struct pinctrl_pin_desc *pins; 154 unsigned npins; 155 struct spear_function **functions; 156 unsigned nfunctions; 157 struct spear_pingroup **groups; 158 unsigned ngroups; 159 struct spear_gpio_pingroup *gpio_pingroups; 160 void (*gpio_request_endisable)(struct spear_pmx *pmx, int offset, 161 bool enable); 162 unsigned ngpio_pingroups; 163 164 bool modes_supported; 165 u16 mode; 166 struct spear_pmx_mode **pmx_modes; 167 unsigned npmx_modes; 168 }; 169 170 /** 171 * struct spear_pmx - SPEAr pinctrl mux 172 * @dev: pointer to struct dev of platform_device registered 173 * @pctl: pointer to struct pinctrl_dev 174 * @machdata: pointer to SoC or machine specific structure 175 * @vbase: virtual base address of pinmux controller 176 */ 177 struct spear_pmx { 178 struct device *dev; 179 struct pinctrl_dev *pctl; 180 struct spear_pinctrl_machdata *machdata; 181 void __iomem *vbase; 182 }; 183 184 /* exported routines */ 185 static inline u32 pmx_readl(struct spear_pmx *pmx, u32 reg) 186 { 187 return readl_relaxed(pmx->vbase + reg); 188 } 189 190 static inline void pmx_writel(struct spear_pmx *pmx, u32 val, u32 reg) 191 { 192 writel_relaxed(val, pmx->vbase + reg); 193 } 194 195 void __devinit pmx_init_addr(struct spear_pinctrl_machdata *machdata, u16 reg); 196 void __devinit 197 pmx_init_gpio_pingroup_addr(struct spear_gpio_pingroup *gpio_pingroup, 198 unsigned count, u16 reg); 199 int __devinit spear_pinctrl_probe(struct platform_device *pdev, 200 struct spear_pinctrl_machdata *machdata); 201 int spear_pinctrl_remove(struct platform_device *pdev); 202 203 #define SPEAR_PIN_0_TO_101 \ 204 PINCTRL_PIN(0, "PLGPIO0"), \ 205 PINCTRL_PIN(1, "PLGPIO1"), \ 206 PINCTRL_PIN(2, "PLGPIO2"), \ 207 PINCTRL_PIN(3, "PLGPIO3"), \ 208 PINCTRL_PIN(4, "PLGPIO4"), \ 209 PINCTRL_PIN(5, "PLGPIO5"), \ 210 PINCTRL_PIN(6, "PLGPIO6"), \ 211 PINCTRL_PIN(7, "PLGPIO7"), \ 212 PINCTRL_PIN(8, "PLGPIO8"), \ 213 PINCTRL_PIN(9, "PLGPIO9"), \ 214 PINCTRL_PIN(10, "PLGPIO10"), \ 215 PINCTRL_PIN(11, "PLGPIO11"), \ 216 PINCTRL_PIN(12, "PLGPIO12"), \ 217 PINCTRL_PIN(13, "PLGPIO13"), \ 218 PINCTRL_PIN(14, "PLGPIO14"), \ 219 PINCTRL_PIN(15, "PLGPIO15"), \ 220 PINCTRL_PIN(16, "PLGPIO16"), \ 221 PINCTRL_PIN(17, "PLGPIO17"), \ 222 PINCTRL_PIN(18, "PLGPIO18"), \ 223 PINCTRL_PIN(19, "PLGPIO19"), \ 224 PINCTRL_PIN(20, "PLGPIO20"), \ 225 PINCTRL_PIN(21, "PLGPIO21"), \ 226 PINCTRL_PIN(22, "PLGPIO22"), \ 227 PINCTRL_PIN(23, "PLGPIO23"), \ 228 PINCTRL_PIN(24, "PLGPIO24"), \ 229 PINCTRL_PIN(25, "PLGPIO25"), \ 230 PINCTRL_PIN(26, "PLGPIO26"), \ 231 PINCTRL_PIN(27, "PLGPIO27"), \ 232 PINCTRL_PIN(28, "PLGPIO28"), \ 233 PINCTRL_PIN(29, "PLGPIO29"), \ 234 PINCTRL_PIN(30, "PLGPIO30"), \ 235 PINCTRL_PIN(31, "PLGPIO31"), \ 236 PINCTRL_PIN(32, "PLGPIO32"), \ 237 PINCTRL_PIN(33, "PLGPIO33"), \ 238 PINCTRL_PIN(34, "PLGPIO34"), \ 239 PINCTRL_PIN(35, "PLGPIO35"), \ 240 PINCTRL_PIN(36, "PLGPIO36"), \ 241 PINCTRL_PIN(37, "PLGPIO37"), \ 242 PINCTRL_PIN(38, "PLGPIO38"), \ 243 PINCTRL_PIN(39, "PLGPIO39"), \ 244 PINCTRL_PIN(40, "PLGPIO40"), \ 245 PINCTRL_PIN(41, "PLGPIO41"), \ 246 PINCTRL_PIN(42, "PLGPIO42"), \ 247 PINCTRL_PIN(43, "PLGPIO43"), \ 248 PINCTRL_PIN(44, "PLGPIO44"), \ 249 PINCTRL_PIN(45, "PLGPIO45"), \ 250 PINCTRL_PIN(46, "PLGPIO46"), \ 251 PINCTRL_PIN(47, "PLGPIO47"), \ 252 PINCTRL_PIN(48, "PLGPIO48"), \ 253 PINCTRL_PIN(49, "PLGPIO49"), \ 254 PINCTRL_PIN(50, "PLGPIO50"), \ 255 PINCTRL_PIN(51, "PLGPIO51"), \ 256 PINCTRL_PIN(52, "PLGPIO52"), \ 257 PINCTRL_PIN(53, "PLGPIO53"), \ 258 PINCTRL_PIN(54, "PLGPIO54"), \ 259 PINCTRL_PIN(55, "PLGPIO55"), \ 260 PINCTRL_PIN(56, "PLGPIO56"), \ 261 PINCTRL_PIN(57, "PLGPIO57"), \ 262 PINCTRL_PIN(58, "PLGPIO58"), \ 263 PINCTRL_PIN(59, "PLGPIO59"), \ 264 PINCTRL_PIN(60, "PLGPIO60"), \ 265 PINCTRL_PIN(61, "PLGPIO61"), \ 266 PINCTRL_PIN(62, "PLGPIO62"), \ 267 PINCTRL_PIN(63, "PLGPIO63"), \ 268 PINCTRL_PIN(64, "PLGPIO64"), \ 269 PINCTRL_PIN(65, "PLGPIO65"), \ 270 PINCTRL_PIN(66, "PLGPIO66"), \ 271 PINCTRL_PIN(67, "PLGPIO67"), \ 272 PINCTRL_PIN(68, "PLGPIO68"), \ 273 PINCTRL_PIN(69, "PLGPIO69"), \ 274 PINCTRL_PIN(70, "PLGPIO70"), \ 275 PINCTRL_PIN(71, "PLGPIO71"), \ 276 PINCTRL_PIN(72, "PLGPIO72"), \ 277 PINCTRL_PIN(73, "PLGPIO73"), \ 278 PINCTRL_PIN(74, "PLGPIO74"), \ 279 PINCTRL_PIN(75, "PLGPIO75"), \ 280 PINCTRL_PIN(76, "PLGPIO76"), \ 281 PINCTRL_PIN(77, "PLGPIO77"), \ 282 PINCTRL_PIN(78, "PLGPIO78"), \ 283 PINCTRL_PIN(79, "PLGPIO79"), \ 284 PINCTRL_PIN(80, "PLGPIO80"), \ 285 PINCTRL_PIN(81, "PLGPIO81"), \ 286 PINCTRL_PIN(82, "PLGPIO82"), \ 287 PINCTRL_PIN(83, "PLGPIO83"), \ 288 PINCTRL_PIN(84, "PLGPIO84"), \ 289 PINCTRL_PIN(85, "PLGPIO85"), \ 290 PINCTRL_PIN(86, "PLGPIO86"), \ 291 PINCTRL_PIN(87, "PLGPIO87"), \ 292 PINCTRL_PIN(88, "PLGPIO88"), \ 293 PINCTRL_PIN(89, "PLGPIO89"), \ 294 PINCTRL_PIN(90, "PLGPIO90"), \ 295 PINCTRL_PIN(91, "PLGPIO91"), \ 296 PINCTRL_PIN(92, "PLGPIO92"), \ 297 PINCTRL_PIN(93, "PLGPIO93"), \ 298 PINCTRL_PIN(94, "PLGPIO94"), \ 299 PINCTRL_PIN(95, "PLGPIO95"), \ 300 PINCTRL_PIN(96, "PLGPIO96"), \ 301 PINCTRL_PIN(97, "PLGPIO97"), \ 302 PINCTRL_PIN(98, "PLGPIO98"), \ 303 PINCTRL_PIN(99, "PLGPIO99"), \ 304 PINCTRL_PIN(100, "PLGPIO100"), \ 305 PINCTRL_PIN(101, "PLGPIO101") 306 307 #define SPEAR_PIN_102_TO_245 \ 308 PINCTRL_PIN(102, "PLGPIO102"), \ 309 PINCTRL_PIN(103, "PLGPIO103"), \ 310 PINCTRL_PIN(104, "PLGPIO104"), \ 311 PINCTRL_PIN(105, "PLGPIO105"), \ 312 PINCTRL_PIN(106, "PLGPIO106"), \ 313 PINCTRL_PIN(107, "PLGPIO107"), \ 314 PINCTRL_PIN(108, "PLGPIO108"), \ 315 PINCTRL_PIN(109, "PLGPIO109"), \ 316 PINCTRL_PIN(110, "PLGPIO110"), \ 317 PINCTRL_PIN(111, "PLGPIO111"), \ 318 PINCTRL_PIN(112, "PLGPIO112"), \ 319 PINCTRL_PIN(113, "PLGPIO113"), \ 320 PINCTRL_PIN(114, "PLGPIO114"), \ 321 PINCTRL_PIN(115, "PLGPIO115"), \ 322 PINCTRL_PIN(116, "PLGPIO116"), \ 323 PINCTRL_PIN(117, "PLGPIO117"), \ 324 PINCTRL_PIN(118, "PLGPIO118"), \ 325 PINCTRL_PIN(119, "PLGPIO119"), \ 326 PINCTRL_PIN(120, "PLGPIO120"), \ 327 PINCTRL_PIN(121, "PLGPIO121"), \ 328 PINCTRL_PIN(122, "PLGPIO122"), \ 329 PINCTRL_PIN(123, "PLGPIO123"), \ 330 PINCTRL_PIN(124, "PLGPIO124"), \ 331 PINCTRL_PIN(125, "PLGPIO125"), \ 332 PINCTRL_PIN(126, "PLGPIO126"), \ 333 PINCTRL_PIN(127, "PLGPIO127"), \ 334 PINCTRL_PIN(128, "PLGPIO128"), \ 335 PINCTRL_PIN(129, "PLGPIO129"), \ 336 PINCTRL_PIN(130, "PLGPIO130"), \ 337 PINCTRL_PIN(131, "PLGPIO131"), \ 338 PINCTRL_PIN(132, "PLGPIO132"), \ 339 PINCTRL_PIN(133, "PLGPIO133"), \ 340 PINCTRL_PIN(134, "PLGPIO134"), \ 341 PINCTRL_PIN(135, "PLGPIO135"), \ 342 PINCTRL_PIN(136, "PLGPIO136"), \ 343 PINCTRL_PIN(137, "PLGPIO137"), \ 344 PINCTRL_PIN(138, "PLGPIO138"), \ 345 PINCTRL_PIN(139, "PLGPIO139"), \ 346 PINCTRL_PIN(140, "PLGPIO140"), \ 347 PINCTRL_PIN(141, "PLGPIO141"), \ 348 PINCTRL_PIN(142, "PLGPIO142"), \ 349 PINCTRL_PIN(143, "PLGPIO143"), \ 350 PINCTRL_PIN(144, "PLGPIO144"), \ 351 PINCTRL_PIN(145, "PLGPIO145"), \ 352 PINCTRL_PIN(146, "PLGPIO146"), \ 353 PINCTRL_PIN(147, "PLGPIO147"), \ 354 PINCTRL_PIN(148, "PLGPIO148"), \ 355 PINCTRL_PIN(149, "PLGPIO149"), \ 356 PINCTRL_PIN(150, "PLGPIO150"), \ 357 PINCTRL_PIN(151, "PLGPIO151"), \ 358 PINCTRL_PIN(152, "PLGPIO152"), \ 359 PINCTRL_PIN(153, "PLGPIO153"), \ 360 PINCTRL_PIN(154, "PLGPIO154"), \ 361 PINCTRL_PIN(155, "PLGPIO155"), \ 362 PINCTRL_PIN(156, "PLGPIO156"), \ 363 PINCTRL_PIN(157, "PLGPIO157"), \ 364 PINCTRL_PIN(158, "PLGPIO158"), \ 365 PINCTRL_PIN(159, "PLGPIO159"), \ 366 PINCTRL_PIN(160, "PLGPIO160"), \ 367 PINCTRL_PIN(161, "PLGPIO161"), \ 368 PINCTRL_PIN(162, "PLGPIO162"), \ 369 PINCTRL_PIN(163, "PLGPIO163"), \ 370 PINCTRL_PIN(164, "PLGPIO164"), \ 371 PINCTRL_PIN(165, "PLGPIO165"), \ 372 PINCTRL_PIN(166, "PLGPIO166"), \ 373 PINCTRL_PIN(167, "PLGPIO167"), \ 374 PINCTRL_PIN(168, "PLGPIO168"), \ 375 PINCTRL_PIN(169, "PLGPIO169"), \ 376 PINCTRL_PIN(170, "PLGPIO170"), \ 377 PINCTRL_PIN(171, "PLGPIO171"), \ 378 PINCTRL_PIN(172, "PLGPIO172"), \ 379 PINCTRL_PIN(173, "PLGPIO173"), \ 380 PINCTRL_PIN(174, "PLGPIO174"), \ 381 PINCTRL_PIN(175, "PLGPIO175"), \ 382 PINCTRL_PIN(176, "PLGPIO176"), \ 383 PINCTRL_PIN(177, "PLGPIO177"), \ 384 PINCTRL_PIN(178, "PLGPIO178"), \ 385 PINCTRL_PIN(179, "PLGPIO179"), \ 386 PINCTRL_PIN(180, "PLGPIO180"), \ 387 PINCTRL_PIN(181, "PLGPIO181"), \ 388 PINCTRL_PIN(182, "PLGPIO182"), \ 389 PINCTRL_PIN(183, "PLGPIO183"), \ 390 PINCTRL_PIN(184, "PLGPIO184"), \ 391 PINCTRL_PIN(185, "PLGPIO185"), \ 392 PINCTRL_PIN(186, "PLGPIO186"), \ 393 PINCTRL_PIN(187, "PLGPIO187"), \ 394 PINCTRL_PIN(188, "PLGPIO188"), \ 395 PINCTRL_PIN(189, "PLGPIO189"), \ 396 PINCTRL_PIN(190, "PLGPIO190"), \ 397 PINCTRL_PIN(191, "PLGPIO191"), \ 398 PINCTRL_PIN(192, "PLGPIO192"), \ 399 PINCTRL_PIN(193, "PLGPIO193"), \ 400 PINCTRL_PIN(194, "PLGPIO194"), \ 401 PINCTRL_PIN(195, "PLGPIO195"), \ 402 PINCTRL_PIN(196, "PLGPIO196"), \ 403 PINCTRL_PIN(197, "PLGPIO197"), \ 404 PINCTRL_PIN(198, "PLGPIO198"), \ 405 PINCTRL_PIN(199, "PLGPIO199"), \ 406 PINCTRL_PIN(200, "PLGPIO200"), \ 407 PINCTRL_PIN(201, "PLGPIO201"), \ 408 PINCTRL_PIN(202, "PLGPIO202"), \ 409 PINCTRL_PIN(203, "PLGPIO203"), \ 410 PINCTRL_PIN(204, "PLGPIO204"), \ 411 PINCTRL_PIN(205, "PLGPIO205"), \ 412 PINCTRL_PIN(206, "PLGPIO206"), \ 413 PINCTRL_PIN(207, "PLGPIO207"), \ 414 PINCTRL_PIN(208, "PLGPIO208"), \ 415 PINCTRL_PIN(209, "PLGPIO209"), \ 416 PINCTRL_PIN(210, "PLGPIO210"), \ 417 PINCTRL_PIN(211, "PLGPIO211"), \ 418 PINCTRL_PIN(212, "PLGPIO212"), \ 419 PINCTRL_PIN(213, "PLGPIO213"), \ 420 PINCTRL_PIN(214, "PLGPIO214"), \ 421 PINCTRL_PIN(215, "PLGPIO215"), \ 422 PINCTRL_PIN(216, "PLGPIO216"), \ 423 PINCTRL_PIN(217, "PLGPIO217"), \ 424 PINCTRL_PIN(218, "PLGPIO218"), \ 425 PINCTRL_PIN(219, "PLGPIO219"), \ 426 PINCTRL_PIN(220, "PLGPIO220"), \ 427 PINCTRL_PIN(221, "PLGPIO221"), \ 428 PINCTRL_PIN(222, "PLGPIO222"), \ 429 PINCTRL_PIN(223, "PLGPIO223"), \ 430 PINCTRL_PIN(224, "PLGPIO224"), \ 431 PINCTRL_PIN(225, "PLGPIO225"), \ 432 PINCTRL_PIN(226, "PLGPIO226"), \ 433 PINCTRL_PIN(227, "PLGPIO227"), \ 434 PINCTRL_PIN(228, "PLGPIO228"), \ 435 PINCTRL_PIN(229, "PLGPIO229"), \ 436 PINCTRL_PIN(230, "PLGPIO230"), \ 437 PINCTRL_PIN(231, "PLGPIO231"), \ 438 PINCTRL_PIN(232, "PLGPIO232"), \ 439 PINCTRL_PIN(233, "PLGPIO233"), \ 440 PINCTRL_PIN(234, "PLGPIO234"), \ 441 PINCTRL_PIN(235, "PLGPIO235"), \ 442 PINCTRL_PIN(236, "PLGPIO236"), \ 443 PINCTRL_PIN(237, "PLGPIO237"), \ 444 PINCTRL_PIN(238, "PLGPIO238"), \ 445 PINCTRL_PIN(239, "PLGPIO239"), \ 446 PINCTRL_PIN(240, "PLGPIO240"), \ 447 PINCTRL_PIN(241, "PLGPIO241"), \ 448 PINCTRL_PIN(242, "PLGPIO242"), \ 449 PINCTRL_PIN(243, "PLGPIO243"), \ 450 PINCTRL_PIN(244, "PLGPIO244"), \ 451 PINCTRL_PIN(245, "PLGPIO245") 452 453 #endif /* __PINMUX_SPEAR_H__ */ 454