0001
0002
0003
0004
0005
0006
0007
0008 #ifndef __SH_PFC_H
0009 #define __SH_PFC_H
0010
0011 #include <linux/bug.h>
0012 #include <linux/pinctrl/pinconf-generic.h>
0013 #include <linux/spinlock.h>
0014 #include <linux/stringify.h>
0015
0016 enum {
0017 PINMUX_TYPE_NONE,
0018 PINMUX_TYPE_FUNCTION,
0019 PINMUX_TYPE_GPIO,
0020 PINMUX_TYPE_OUTPUT,
0021 PINMUX_TYPE_INPUT,
0022 };
0023
0024 #define SH_PFC_PIN_NONE U16_MAX
0025
0026 #define SH_PFC_PIN_CFG_INPUT (1 << 0)
0027 #define SH_PFC_PIN_CFG_OUTPUT (1 << 1)
0028 #define SH_PFC_PIN_CFG_PULL_UP (1 << 2)
0029 #define SH_PFC_PIN_CFG_PULL_DOWN (1 << 3)
0030 #define SH_PFC_PIN_CFG_PULL_UP_DOWN (SH_PFC_PIN_CFG_PULL_UP | \
0031 SH_PFC_PIN_CFG_PULL_DOWN)
0032 #define SH_PFC_PIN_CFG_IO_VOLTAGE (1 << 4)
0033 #define SH_PFC_PIN_CFG_DRIVE_STRENGTH (1 << 5)
0034
0035 #define SH_PFC_PIN_VOLTAGE_18_33 (0 << 6)
0036 #define SH_PFC_PIN_VOLTAGE_25_33 (1 << 6)
0037
0038 #define SH_PFC_PIN_CFG_IO_VOLTAGE_18_33 (SH_PFC_PIN_CFG_IO_VOLTAGE | \
0039 SH_PFC_PIN_VOLTAGE_18_33)
0040 #define SH_PFC_PIN_CFG_IO_VOLTAGE_25_33 (SH_PFC_PIN_CFG_IO_VOLTAGE | \
0041 SH_PFC_PIN_VOLTAGE_25_33)
0042
0043 #define SH_PFC_PIN_CFG_NO_GPIO (1 << 31)
0044
0045 struct sh_pfc_pin {
0046 const char *name;
0047 unsigned int configs;
0048 u16 pin;
0049 u16 enum_id;
0050 };
0051
0052 #define SH_PFC_PIN_GROUP_ALIAS(alias, _name) { \
0053 .name = #alias, \
0054 .pins = _name##_pins, \
0055 .mux = _name##_mux, \
0056 .nr_pins = ARRAY_SIZE(_name##_pins) + \
0057 BUILD_BUG_ON_ZERO(sizeof(_name##_pins) != sizeof(_name##_mux)), \
0058 }
0059 #define SH_PFC_PIN_GROUP(name) SH_PFC_PIN_GROUP_ALIAS(name, name)
0060
0061
0062
0063
0064 #define SH_PFC_PIN_GROUP_SUBSET(_name, data, first, n) { \
0065 .name = #_name, \
0066 .pins = data##_pins + first, \
0067 .mux = data##_mux + first, \
0068 .nr_pins = n + \
0069 BUILD_BUG_ON_ZERO(first + n > ARRAY_SIZE(data##_pins)) + \
0070 BUILD_BUG_ON_ZERO(first + n > ARRAY_SIZE(data##_mux)), \
0071 }
0072
0073
0074
0075
0076
0077
0078 #define BUS_DATA_PIN_GROUP(base, n, ...) \
0079 SH_PFC_PIN_GROUP_SUBSET(base##n##__VA_ARGS__, base##__VA_ARGS__, 0, n)
0080
0081 struct sh_pfc_pin_group {
0082 const char *name;
0083 const unsigned int *pins;
0084 const unsigned int *mux;
0085 unsigned int nr_pins;
0086 };
0087
0088 #define SH_PFC_FUNCTION(n) { \
0089 .name = #n, \
0090 .groups = n##_groups, \
0091 .nr_groups = ARRAY_SIZE(n##_groups), \
0092 }
0093
0094 struct sh_pfc_function {
0095 const char *name;
0096 const char * const *groups;
0097 unsigned int nr_groups;
0098 };
0099
0100 struct pinmux_func {
0101 u16 enum_id;
0102 const char *name;
0103 };
0104
0105 struct pinmux_cfg_reg {
0106 u32 reg;
0107 u8 reg_width, field_width;
0108 #ifdef DEBUG
0109 u16 nr_enum_ids;
0110 #define SET_NR_ENUM_IDS(n) .nr_enum_ids = n,
0111 #else
0112 #define SET_NR_ENUM_IDS(n)
0113 #endif
0114 const u16 *enum_ids;
0115 const s8 *var_field_width;
0116 };
0117
0118 #define GROUP(...) __VA_ARGS__
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131 #define PINMUX_CFG_REG(name, r, r_width, f_width, ids) \
0132 .reg = r, .reg_width = r_width, \
0133 .field_width = f_width + BUILD_BUG_ON_ZERO(r_width % f_width) + \
0134 BUILD_BUG_ON_ZERO(sizeof((const u16 []) { ids }) / sizeof(u16) != \
0135 (r_width / f_width) << f_width), \
0136 .enum_ids = (const u16 [(r_width / f_width) << f_width]) { ids }
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151 #define PINMUX_CFG_REG_VAR(name, r, r_width, f_widths, ids) \
0152 .reg = r, .reg_width = r_width, \
0153 .var_field_width = (const s8 []) { f_widths, 0 }, \
0154 SET_NR_ENUM_IDS(sizeof((const u16 []) { ids }) / sizeof(u16)) \
0155 .enum_ids = (const u16 []) { ids }
0156
0157 struct pinmux_drive_reg_field {
0158 u16 pin;
0159 u8 offset;
0160 u8 size;
0161 };
0162
0163 struct pinmux_drive_reg {
0164 u32 reg;
0165 const struct pinmux_drive_reg_field fields[10];
0166 };
0167
0168 #define PINMUX_DRIVE_REG(name, r) \
0169 .reg = r, \
0170 .fields =
0171
0172 struct pinmux_bias_reg {
0173 u32 puen;
0174 u32 pud;
0175 const u16 pins[32];
0176 };
0177
0178 #define PINMUX_BIAS_REG(name1, r1, name2, r2) \
0179 .puen = r1, \
0180 .pud = r2, \
0181 .pins =
0182
0183 struct pinmux_ioctrl_reg {
0184 u32 reg;
0185 };
0186
0187 struct pinmux_data_reg {
0188 u32 reg;
0189 u8 reg_width;
0190 const u16 *enum_ids;
0191 };
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201 #define PINMUX_DATA_REG(name, r, r_width, ids) \
0202 .reg = r, .reg_width = r_width + \
0203 BUILD_BUG_ON_ZERO(sizeof((const u16 []) { ids }) / sizeof(u16) != \
0204 r_width), \
0205 .enum_ids = (const u16 [r_width]) { ids }
0206
0207 struct pinmux_irq {
0208 const short *gpios;
0209 };
0210
0211
0212
0213
0214
0215 #define PINMUX_IRQ(ids...) { \
0216 .gpios = (const short []) { ids, -1 } \
0217 }
0218
0219 struct pinmux_range {
0220 u16 begin;
0221 u16 end;
0222 u16 force;
0223 };
0224
0225 struct sh_pfc_window {
0226 phys_addr_t phys;
0227 void __iomem *virt;
0228 unsigned long size;
0229 };
0230
0231 struct sh_pfc_pin_range;
0232
0233 struct sh_pfc {
0234 struct device *dev;
0235 const struct sh_pfc_soc_info *info;
0236 spinlock_t lock;
0237
0238 unsigned int num_windows;
0239 struct sh_pfc_window *windows;
0240 unsigned int num_irqs;
0241 unsigned int *irqs;
0242
0243 struct sh_pfc_pin_range *ranges;
0244 unsigned int nr_ranges;
0245
0246 unsigned int nr_gpio_pins;
0247
0248 struct sh_pfc_chip *gpio;
0249 u32 *saved_regs;
0250 };
0251
0252 struct sh_pfc_soc_operations {
0253 int (*init)(struct sh_pfc *pfc);
0254 unsigned int (*get_bias)(struct sh_pfc *pfc, unsigned int pin);
0255 void (*set_bias)(struct sh_pfc *pfc, unsigned int pin,
0256 unsigned int bias);
0257 int (*pin_to_pocctrl)(unsigned int pin, u32 *pocctrl);
0258 int (*pin_to_portcr)(unsigned int pin);
0259 };
0260
0261 struct sh_pfc_soc_info {
0262 const char *name;
0263 const struct sh_pfc_soc_operations *ops;
0264
0265 #ifdef CONFIG_PINCTRL_SH_PFC_GPIO
0266 struct pinmux_range input;
0267 struct pinmux_range output;
0268 const struct pinmux_irq *gpio_irq;
0269 unsigned int gpio_irq_size;
0270 #endif
0271
0272 struct pinmux_range function;
0273
0274 const struct sh_pfc_pin *pins;
0275 unsigned int nr_pins;
0276 const struct sh_pfc_pin_group *groups;
0277 unsigned int nr_groups;
0278 const struct sh_pfc_function *functions;
0279 unsigned int nr_functions;
0280
0281 #ifdef CONFIG_PINCTRL_SH_FUNC_GPIO
0282 const struct pinmux_func *func_gpios;
0283 unsigned int nr_func_gpios;
0284 #endif
0285
0286 const struct pinmux_cfg_reg *cfg_regs;
0287 const struct pinmux_drive_reg *drive_regs;
0288 const struct pinmux_bias_reg *bias_regs;
0289 const struct pinmux_ioctrl_reg *ioctrl_regs;
0290 const struct pinmux_data_reg *data_regs;
0291
0292 const u16 *pinmux_data;
0293 unsigned int pinmux_data_size;
0294
0295 u32 unlock_reg;
0296 };
0297
0298 extern const struct sh_pfc_soc_info emev2_pinmux_info;
0299 extern const struct sh_pfc_soc_info r8a73a4_pinmux_info;
0300 extern const struct sh_pfc_soc_info r8a7740_pinmux_info;
0301 extern const struct sh_pfc_soc_info r8a7742_pinmux_info;
0302 extern const struct sh_pfc_soc_info r8a7743_pinmux_info;
0303 extern const struct sh_pfc_soc_info r8a7744_pinmux_info;
0304 extern const struct sh_pfc_soc_info r8a7745_pinmux_info;
0305 extern const struct sh_pfc_soc_info r8a77470_pinmux_info;
0306 extern const struct sh_pfc_soc_info r8a774a1_pinmux_info;
0307 extern const struct sh_pfc_soc_info r8a774b1_pinmux_info;
0308 extern const struct sh_pfc_soc_info r8a774c0_pinmux_info;
0309 extern const struct sh_pfc_soc_info r8a774e1_pinmux_info;
0310 extern const struct sh_pfc_soc_info r8a7778_pinmux_info;
0311 extern const struct sh_pfc_soc_info r8a7779_pinmux_info;
0312 extern const struct sh_pfc_soc_info r8a7790_pinmux_info;
0313 extern const struct sh_pfc_soc_info r8a7791_pinmux_info;
0314 extern const struct sh_pfc_soc_info r8a7792_pinmux_info;
0315 extern const struct sh_pfc_soc_info r8a7793_pinmux_info;
0316 extern const struct sh_pfc_soc_info r8a7794_pinmux_info;
0317 extern const struct sh_pfc_soc_info r8a77950_pinmux_info;
0318 extern const struct sh_pfc_soc_info r8a77951_pinmux_info;
0319 extern const struct sh_pfc_soc_info r8a77960_pinmux_info;
0320 extern const struct sh_pfc_soc_info r8a77961_pinmux_info;
0321 extern const struct sh_pfc_soc_info r8a77965_pinmux_info;
0322 extern const struct sh_pfc_soc_info r8a77970_pinmux_info;
0323 extern const struct sh_pfc_soc_info r8a77980_pinmux_info;
0324 extern const struct sh_pfc_soc_info r8a77990_pinmux_info;
0325 extern const struct sh_pfc_soc_info r8a77995_pinmux_info;
0326 extern const struct sh_pfc_soc_info r8a779a0_pinmux_info;
0327 extern const struct sh_pfc_soc_info r8a779f0_pinmux_info;
0328 extern const struct sh_pfc_soc_info r8a779g0_pinmux_info;
0329 extern const struct sh_pfc_soc_info sh7203_pinmux_info;
0330 extern const struct sh_pfc_soc_info sh7264_pinmux_info;
0331 extern const struct sh_pfc_soc_info sh7269_pinmux_info;
0332 extern const struct sh_pfc_soc_info sh73a0_pinmux_info;
0333 extern const struct sh_pfc_soc_info sh7720_pinmux_info;
0334 extern const struct sh_pfc_soc_info sh7722_pinmux_info;
0335 extern const struct sh_pfc_soc_info sh7723_pinmux_info;
0336 extern const struct sh_pfc_soc_info sh7724_pinmux_info;
0337 extern const struct sh_pfc_soc_info sh7734_pinmux_info;
0338 extern const struct sh_pfc_soc_info sh7757_pinmux_info;
0339 extern const struct sh_pfc_soc_info sh7785_pinmux_info;
0340 extern const struct sh_pfc_soc_info sh7786_pinmux_info;
0341 extern const struct sh_pfc_soc_info shx3_pinmux_info;
0342
0343
0344
0345
0346
0347
0348
0349
0350
0351
0352
0353
0354
0355
0356 #define PINMUX_DATA(data_or_mark, ids...) data_or_mark, ids, 0
0357
0358
0359
0360
0361
0362
0363
0364 #define PINMUX_IPSR_NOGP(ipsr, fn) \
0365 PINMUX_DATA(fn##_MARK, FN_##fn)
0366
0367
0368
0369
0370
0371
0372
0373
0374 #define PINMUX_IPSR_GPSR(ipsr, fn) \
0375 PINMUX_DATA(fn##_MARK, FN_##fn, FN_##ipsr)
0376
0377
0378
0379
0380
0381
0382
0383
0384
0385 #define PINMUX_IPSR_NOGM(ipsr, fn, msel) \
0386 PINMUX_DATA(fn##_MARK, FN_##fn, FN_##msel)
0387
0388
0389
0390
0391
0392
0393
0394
0395
0396 #define PINMUX_IPSR_NOFN(gpsr, fn, gsel) \
0397 PINMUX_DATA(fn##_MARK, FN_##gpsr, FN_##gsel)
0398
0399
0400
0401
0402
0403
0404
0405
0406
0407
0408 #define PINMUX_IPSR_MSEL(ipsr, fn, msel) \
0409 PINMUX_DATA(fn##_MARK, FN_##msel, FN_##fn, FN_##ipsr)
0410
0411
0412
0413
0414
0415
0416
0417
0418
0419
0420 #define PINMUX_IPSR_PHYS_MSEL(ipsr, fn, psel, msel) \
0421 PINMUX_DATA(fn##_MARK, FN_##psel, FN_##msel, FN_##fn, FN_##ipsr)
0422
0423
0424
0425
0426
0427
0428
0429
0430 #define PINMUX_IPSR_PHYS(ipsr, fn, psel) \
0431 PINMUX_DATA(fn##_MARK, FN_##psel, FN_##ipsr)
0432
0433
0434
0435
0436
0437
0438 #define PINMUX_SINGLE(fn) \
0439 PINMUX_DATA(fn##_MARK, FN_##fn)
0440
0441
0442
0443
0444
0445 #define PORT_GP_CFG_1(bank, pin, fn, sfx, cfg) \
0446 fn(bank, pin, GP_##bank##_##pin, sfx, cfg)
0447 #define PORT_GP_1(bank, pin, fn, sfx) PORT_GP_CFG_1(bank, pin, fn, sfx, 0)
0448
0449 #define PORT_GP_CFG_2(bank, fn, sfx, cfg) \
0450 PORT_GP_CFG_1(bank, 0, fn, sfx, cfg), \
0451 PORT_GP_CFG_1(bank, 1, fn, sfx, cfg)
0452 #define PORT_GP_2(bank, fn, sfx) PORT_GP_CFG_2(bank, fn, sfx, 0)
0453
0454 #define PORT_GP_CFG_4(bank, fn, sfx, cfg) \
0455 PORT_GP_CFG_2(bank, fn, sfx, cfg), \
0456 PORT_GP_CFG_1(bank, 2, fn, sfx, cfg), \
0457 PORT_GP_CFG_1(bank, 3, fn, sfx, cfg)
0458 #define PORT_GP_4(bank, fn, sfx) PORT_GP_CFG_4(bank, fn, sfx, 0)
0459
0460 #define PORT_GP_CFG_6(bank, fn, sfx, cfg) \
0461 PORT_GP_CFG_4(bank, fn, sfx, cfg), \
0462 PORT_GP_CFG_1(bank, 4, fn, sfx, cfg), \
0463 PORT_GP_CFG_1(bank, 5, fn, sfx, cfg)
0464 #define PORT_GP_6(bank, fn, sfx) PORT_GP_CFG_6(bank, fn, sfx, 0)
0465
0466 #define PORT_GP_CFG_7(bank, fn, sfx, cfg) \
0467 PORT_GP_CFG_6(bank, fn, sfx, cfg), \
0468 PORT_GP_CFG_1(bank, 6, fn, sfx, cfg)
0469 #define PORT_GP_7(bank, fn, sfx) PORT_GP_CFG_7(bank, fn, sfx, 0)
0470
0471 #define PORT_GP_CFG_8(bank, fn, sfx, cfg) \
0472 PORT_GP_CFG_7(bank, fn, sfx, cfg), \
0473 PORT_GP_CFG_1(bank, 7, fn, sfx, cfg)
0474 #define PORT_GP_8(bank, fn, sfx) PORT_GP_CFG_8(bank, fn, sfx, 0)
0475
0476 #define PORT_GP_CFG_9(bank, fn, sfx, cfg) \
0477 PORT_GP_CFG_8(bank, fn, sfx, cfg), \
0478 PORT_GP_CFG_1(bank, 8, fn, sfx, cfg)
0479 #define PORT_GP_9(bank, fn, sfx) PORT_GP_CFG_9(bank, fn, sfx, 0)
0480
0481 #define PORT_GP_CFG_10(bank, fn, sfx, cfg) \
0482 PORT_GP_CFG_9(bank, fn, sfx, cfg), \
0483 PORT_GP_CFG_1(bank, 9, fn, sfx, cfg)
0484 #define PORT_GP_10(bank, fn, sfx) PORT_GP_CFG_10(bank, fn, sfx, 0)
0485
0486 #define PORT_GP_CFG_11(bank, fn, sfx, cfg) \
0487 PORT_GP_CFG_10(bank, fn, sfx, cfg), \
0488 PORT_GP_CFG_1(bank, 10, fn, sfx, cfg)
0489 #define PORT_GP_11(bank, fn, sfx) PORT_GP_CFG_11(bank, fn, sfx, 0)
0490
0491 #define PORT_GP_CFG_12(bank, fn, sfx, cfg) \
0492 PORT_GP_CFG_11(bank, fn, sfx, cfg), \
0493 PORT_GP_CFG_1(bank, 11, fn, sfx, cfg)
0494 #define PORT_GP_12(bank, fn, sfx) PORT_GP_CFG_12(bank, fn, sfx, 0)
0495
0496 #define PORT_GP_CFG_13(bank, fn, sfx, cfg) \
0497 PORT_GP_CFG_12(bank, fn, sfx, cfg), \
0498 PORT_GP_CFG_1(bank, 12, fn, sfx, cfg)
0499 #define PORT_GP_13(bank, fn, sfx) PORT_GP_CFG_13(bank, fn, sfx, 0)
0500
0501 #define PORT_GP_CFG_14(bank, fn, sfx, cfg) \
0502 PORT_GP_CFG_13(bank, fn, sfx, cfg), \
0503 PORT_GP_CFG_1(bank, 13, fn, sfx, cfg)
0504 #define PORT_GP_14(bank, fn, sfx) PORT_GP_CFG_14(bank, fn, sfx, 0)
0505
0506 #define PORT_GP_CFG_15(bank, fn, sfx, cfg) \
0507 PORT_GP_CFG_14(bank, fn, sfx, cfg), \
0508 PORT_GP_CFG_1(bank, 14, fn, sfx, cfg)
0509 #define PORT_GP_15(bank, fn, sfx) PORT_GP_CFG_15(bank, fn, sfx, 0)
0510
0511 #define PORT_GP_CFG_16(bank, fn, sfx, cfg) \
0512 PORT_GP_CFG_15(bank, fn, sfx, cfg), \
0513 PORT_GP_CFG_1(bank, 15, fn, sfx, cfg)
0514 #define PORT_GP_16(bank, fn, sfx) PORT_GP_CFG_16(bank, fn, sfx, 0)
0515
0516 #define PORT_GP_CFG_17(bank, fn, sfx, cfg) \
0517 PORT_GP_CFG_16(bank, fn, sfx, cfg), \
0518 PORT_GP_CFG_1(bank, 16, fn, sfx, cfg)
0519 #define PORT_GP_17(bank, fn, sfx) PORT_GP_CFG_17(bank, fn, sfx, 0)
0520
0521 #define PORT_GP_CFG_18(bank, fn, sfx, cfg) \
0522 PORT_GP_CFG_17(bank, fn, sfx, cfg), \
0523 PORT_GP_CFG_1(bank, 17, fn, sfx, cfg)
0524 #define PORT_GP_18(bank, fn, sfx) PORT_GP_CFG_18(bank, fn, sfx, 0)
0525
0526 #define PORT_GP_CFG_19(bank, fn, sfx, cfg) \
0527 PORT_GP_CFG_18(bank, fn, sfx, cfg), \
0528 PORT_GP_CFG_1(bank, 18, fn, sfx, cfg)
0529 #define PORT_GP_19(bank, fn, sfx) PORT_GP_CFG_19(bank, fn, sfx, 0)
0530
0531 #define PORT_GP_CFG_20(bank, fn, sfx, cfg) \
0532 PORT_GP_CFG_19(bank, fn, sfx, cfg), \
0533 PORT_GP_CFG_1(bank, 19, fn, sfx, cfg)
0534 #define PORT_GP_20(bank, fn, sfx) PORT_GP_CFG_20(bank, fn, sfx, 0)
0535
0536 #define PORT_GP_CFG_21(bank, fn, sfx, cfg) \
0537 PORT_GP_CFG_20(bank, fn, sfx, cfg), \
0538 PORT_GP_CFG_1(bank, 20, fn, sfx, cfg)
0539 #define PORT_GP_21(bank, fn, sfx) PORT_GP_CFG_21(bank, fn, sfx, 0)
0540
0541 #define PORT_GP_CFG_22(bank, fn, sfx, cfg) \
0542 PORT_GP_CFG_21(bank, fn, sfx, cfg), \
0543 PORT_GP_CFG_1(bank, 21, fn, sfx, cfg)
0544 #define PORT_GP_22(bank, fn, sfx) PORT_GP_CFG_22(bank, fn, sfx, 0)
0545
0546 #define PORT_GP_CFG_23(bank, fn, sfx, cfg) \
0547 PORT_GP_CFG_22(bank, fn, sfx, cfg), \
0548 PORT_GP_CFG_1(bank, 22, fn, sfx, cfg)
0549 #define PORT_GP_23(bank, fn, sfx) PORT_GP_CFG_23(bank, fn, sfx, 0)
0550
0551 #define PORT_GP_CFG_24(bank, fn, sfx, cfg) \
0552 PORT_GP_CFG_23(bank, fn, sfx, cfg), \
0553 PORT_GP_CFG_1(bank, 23, fn, sfx, cfg)
0554 #define PORT_GP_24(bank, fn, sfx) PORT_GP_CFG_24(bank, fn, sfx, 0)
0555
0556 #define PORT_GP_CFG_25(bank, fn, sfx, cfg) \
0557 PORT_GP_CFG_24(bank, fn, sfx, cfg), \
0558 PORT_GP_CFG_1(bank, 24, fn, sfx, cfg)
0559 #define PORT_GP_25(bank, fn, sfx) PORT_GP_CFG_25(bank, fn, sfx, 0)
0560
0561 #define PORT_GP_CFG_26(bank, fn, sfx, cfg) \
0562 PORT_GP_CFG_25(bank, fn, sfx, cfg), \
0563 PORT_GP_CFG_1(bank, 25, fn, sfx, cfg)
0564 #define PORT_GP_26(bank, fn, sfx) PORT_GP_CFG_26(bank, fn, sfx, 0)
0565
0566 #define PORT_GP_CFG_27(bank, fn, sfx, cfg) \
0567 PORT_GP_CFG_26(bank, fn, sfx, cfg), \
0568 PORT_GP_CFG_1(bank, 26, fn, sfx, cfg)
0569 #define PORT_GP_27(bank, fn, sfx) PORT_GP_CFG_27(bank, fn, sfx, 0)
0570
0571 #define PORT_GP_CFG_28(bank, fn, sfx, cfg) \
0572 PORT_GP_CFG_27(bank, fn, sfx, cfg), \
0573 PORT_GP_CFG_1(bank, 27, fn, sfx, cfg)
0574 #define PORT_GP_28(bank, fn, sfx) PORT_GP_CFG_28(bank, fn, sfx, 0)
0575
0576 #define PORT_GP_CFG_29(bank, fn, sfx, cfg) \
0577 PORT_GP_CFG_28(bank, fn, sfx, cfg), \
0578 PORT_GP_CFG_1(bank, 28, fn, sfx, cfg)
0579 #define PORT_GP_29(bank, fn, sfx) PORT_GP_CFG_29(bank, fn, sfx, 0)
0580
0581 #define PORT_GP_CFG_30(bank, fn, sfx, cfg) \
0582 PORT_GP_CFG_29(bank, fn, sfx, cfg), \
0583 PORT_GP_CFG_1(bank, 29, fn, sfx, cfg)
0584 #define PORT_GP_30(bank, fn, sfx) PORT_GP_CFG_30(bank, fn, sfx, 0)
0585
0586 #define PORT_GP_CFG_31(bank, fn, sfx, cfg) \
0587 PORT_GP_CFG_30(bank, fn, sfx, cfg), \
0588 PORT_GP_CFG_1(bank, 30, fn, sfx, cfg)
0589 #define PORT_GP_31(bank, fn, sfx) PORT_GP_CFG_31(bank, fn, sfx, 0)
0590
0591 #define PORT_GP_CFG_32(bank, fn, sfx, cfg) \
0592 PORT_GP_CFG_31(bank, fn, sfx, cfg), \
0593 PORT_GP_CFG_1(bank, 31, fn, sfx, cfg)
0594 #define PORT_GP_32(bank, fn, sfx) PORT_GP_CFG_32(bank, fn, sfx, 0)
0595
0596 #define PORT_GP_32_REV(bank, fn, sfx) \
0597 PORT_GP_1(bank, 31, fn, sfx), PORT_GP_1(bank, 30, fn, sfx), \
0598 PORT_GP_1(bank, 29, fn, sfx), PORT_GP_1(bank, 28, fn, sfx), \
0599 PORT_GP_1(bank, 27, fn, sfx), PORT_GP_1(bank, 26, fn, sfx), \
0600 PORT_GP_1(bank, 25, fn, sfx), PORT_GP_1(bank, 24, fn, sfx), \
0601 PORT_GP_1(bank, 23, fn, sfx), PORT_GP_1(bank, 22, fn, sfx), \
0602 PORT_GP_1(bank, 21, fn, sfx), PORT_GP_1(bank, 20, fn, sfx), \
0603 PORT_GP_1(bank, 19, fn, sfx), PORT_GP_1(bank, 18, fn, sfx), \
0604 PORT_GP_1(bank, 17, fn, sfx), PORT_GP_1(bank, 16, fn, sfx), \
0605 PORT_GP_1(bank, 15, fn, sfx), PORT_GP_1(bank, 14, fn, sfx), \
0606 PORT_GP_1(bank, 13, fn, sfx), PORT_GP_1(bank, 12, fn, sfx), \
0607 PORT_GP_1(bank, 11, fn, sfx), PORT_GP_1(bank, 10, fn, sfx), \
0608 PORT_GP_1(bank, 9, fn, sfx), PORT_GP_1(bank, 8, fn, sfx), \
0609 PORT_GP_1(bank, 7, fn, sfx), PORT_GP_1(bank, 6, fn, sfx), \
0610 PORT_GP_1(bank, 5, fn, sfx), PORT_GP_1(bank, 4, fn, sfx), \
0611 PORT_GP_1(bank, 3, fn, sfx), PORT_GP_1(bank, 2, fn, sfx), \
0612 PORT_GP_1(bank, 1, fn, sfx), PORT_GP_1(bank, 0, fn, sfx)
0613
0614
0615 #define _GP_ALL(bank, pin, name, sfx, cfg) name##_##sfx
0616 #define GP_ALL(str) CPU_ALL_GP(_GP_ALL, str)
0617
0618
0619 #define _GP_GPIO(bank, _pin, _name, sfx, cfg) { \
0620 .pin = (bank * 32) + _pin, \
0621 .name = __stringify(_name), \
0622 .enum_id = _name##_DATA, \
0623 .configs = cfg, \
0624 }
0625 #define PINMUX_GPIO_GP_ALL() CPU_ALL_GP(_GP_GPIO, unused)
0626
0627
0628 #define _GP_DATA(bank, pin, name, sfx, cfg) PINMUX_DATA(name##_DATA, name##_FN)
0629 #define PINMUX_DATA_GP_ALL() CPU_ALL_GP(_GP_DATA, unused)
0630
0631
0632
0633
0634
0635
0636
0637
0638
0639
0640 #define _GP_ENTRY(bank, pin, name, sfx, cfg) \
0641 deprecated)); char name[(bank * 32) + pin] __attribute__((deprecated
0642 #define GP_ASSIGN_LAST() \
0643 GP_LAST = sizeof(union { \
0644 char dummy[0] __attribute__((deprecated, \
0645 CPU_ALL_GP(_GP_ENTRY, unused), \
0646 deprecated)); \
0647 })
0648
0649
0650
0651
0652
0653 #define PORT_1(pn, fn, pfx, sfx) fn(pn, pfx, sfx)
0654
0655 #define PORT_10(pn, fn, pfx, sfx) \
0656 PORT_1(pn, fn, pfx##0, sfx), PORT_1(pn+1, fn, pfx##1, sfx), \
0657 PORT_1(pn+2, fn, pfx##2, sfx), PORT_1(pn+3, fn, pfx##3, sfx), \
0658 PORT_1(pn+4, fn, pfx##4, sfx), PORT_1(pn+5, fn, pfx##5, sfx), \
0659 PORT_1(pn+6, fn, pfx##6, sfx), PORT_1(pn+7, fn, pfx##7, sfx), \
0660 PORT_1(pn+8, fn, pfx##8, sfx), PORT_1(pn+9, fn, pfx##9, sfx)
0661
0662 #define PORT_90(pn, fn, pfx, sfx) \
0663 PORT_10(pn+10, fn, pfx##1, sfx), PORT_10(pn+20, fn, pfx##2, sfx), \
0664 PORT_10(pn+30, fn, pfx##3, sfx), PORT_10(pn+40, fn, pfx##4, sfx), \
0665 PORT_10(pn+50, fn, pfx##5, sfx), PORT_10(pn+60, fn, pfx##6, sfx), \
0666 PORT_10(pn+70, fn, pfx##7, sfx), PORT_10(pn+80, fn, pfx##8, sfx), \
0667 PORT_10(pn+90, fn, pfx##9, sfx)
0668
0669
0670 #define _PORT_ALL(pn, pfx, sfx) pfx##_##sfx
0671 #define PORT_ALL(str) CPU_ALL_PORT(_PORT_ALL, PORT, str)
0672
0673
0674 #define PINMUX_GPIO(_pin) \
0675 [GPIO_##_pin] = { \
0676 .pin = (u16)-1, \
0677 .name = __stringify(GPIO_##_pin), \
0678 .enum_id = _pin##_DATA, \
0679 }
0680
0681
0682 #define SH_PFC_PIN_CFG(_pin, cfgs) { \
0683 .pin = _pin, \
0684 .name = __stringify(PORT##_pin), \
0685 .enum_id = PORT##_pin##_DATA, \
0686 .configs = cfgs, \
0687 }
0688
0689
0690
0691
0692 #define _PORT_DATA(pn, pfx, sfx) \
0693 PINMUX_DATA(PORT##pfx##_DATA, PORT##pfx##_FN0, \
0694 PORT##pfx##_OUT, PORT##pfx##_IN)
0695 #define PINMUX_DATA_ALL() CPU_ALL_PORT(_PORT_DATA, , unused)
0696
0697
0698
0699
0700
0701
0702
0703
0704
0705
0706 #define _PORT_ENTRY(pn, pfx, sfx) \
0707 deprecated)); char pfx[pn] __attribute__((deprecated
0708 #define PORT_ASSIGN_LAST() \
0709 PORT_LAST = sizeof(union { \
0710 char dummy[0] __attribute__((deprecated, \
0711 CPU_ALL_PORT(_PORT_ENTRY, PORT, unused), \
0712 deprecated)); \
0713 })
0714
0715
0716 #define PINMUX_GPIO_FN(gpio, base, data_or_mark) \
0717 [gpio - (base)] = { \
0718 .name = __stringify(gpio), \
0719 .enum_id = data_or_mark, \
0720 }
0721 #define GPIO_FN(str) \
0722 PINMUX_GPIO_FN(GPIO_FN_##str, PINMUX_FN_BASE, str##_MARK)
0723
0724
0725
0726
0727
0728 #define PIN_NOGP_CFG(pin, name, fn, cfg) fn(pin, name, cfg)
0729 #define PIN_NOGP(pin, name, fn) fn(pin, name, 0)
0730
0731
0732 #define _NOGP_ALL(pin, name, cfg) PIN_##pin
0733 #define NOGP_ALL() CPU_ALL_NOGP(_NOGP_ALL)
0734
0735
0736 #define _NOGP_PINMUX(_pin, _name, cfg) { \
0737 .pin = PIN_##_pin, \
0738 .name = "PIN_" _name, \
0739 .configs = SH_PFC_PIN_CFG_NO_GPIO | cfg, \
0740 }
0741 #define PINMUX_NOGP_ALL() CPU_ALL_NOGP(_NOGP_PINMUX)
0742
0743
0744
0745
0746 #define PORTCR(nr, reg) { \
0747 PINMUX_CFG_REG_VAR("PORT" nr "CR", reg, 8, GROUP(-2, 2, -1, 3), \
0748 GROUP( \
0749 \
0750 \
0751 0, PORT##nr##_OUT, PORT##nr##_IN, 0, \
0752 \
0753 \
0754 PORT##nr##_FN0, PORT##nr##_FN1, \
0755 PORT##nr##_FN2, PORT##nr##_FN3, \
0756 PORT##nr##_FN4, PORT##nr##_FN5, \
0757 PORT##nr##_FN6, PORT##nr##_FN7 \
0758 )) \
0759 }
0760
0761
0762
0763
0764 #define RCAR_GP_PIN(bank, pin) (((bank) * 32) + (pin))
0765
0766
0767
0768
0769 const struct pinmux_bias_reg *
0770 rcar_pin_to_bias_reg(const struct sh_pfc_soc_info *info, unsigned int pin,
0771 unsigned int *bit);
0772 unsigned int rcar_pinmux_get_bias(struct sh_pfc *pfc, unsigned int pin);
0773 void rcar_pinmux_set_bias(struct sh_pfc *pfc, unsigned int pin,
0774 unsigned int bias);
0775
0776 unsigned int rmobile_pinmux_get_bias(struct sh_pfc *pfc, unsigned int pin);
0777 void rmobile_pinmux_set_bias(struct sh_pfc *pfc, unsigned int pin,
0778 unsigned int bias);
0779
0780 #endif