Magnus Damm | fae4339 | 2009-11-27 07:38:01 +0000 | [diff] [blame] | 1 | /* |
| 2 | * SuperH Pin Function Controller Support |
| 3 | * |
| 4 | * Copyright (c) 2008 Magnus Damm |
| 5 | * |
| 6 | * This file is subject to the terms and conditions of the GNU General Public |
| 7 | * License. See the file "COPYING" in the main directory of this archive |
| 8 | * for more details. |
| 9 | */ |
| 10 | |
| 11 | #ifndef __SH_PFC_H |
| 12 | #define __SH_PFC_H |
| 13 | |
Paul Mundt | 72c7afa | 2012-07-10 11:59:29 +0900 | [diff] [blame] | 14 | #include <linux/stringify.h> |
Magnus Damm | fae4339 | 2009-11-27 07:38:01 +0000 | [diff] [blame] | 15 | #include <asm-generic/gpio.h> |
| 16 | |
| 17 | typedef unsigned short pinmux_enum_t; |
Magnus Damm | fae4339 | 2009-11-27 07:38:01 +0000 | [diff] [blame] | 18 | |
Laurent Pinchart | 3d8d9f1 | 2013-01-03 14:33:13 +0100 | [diff] [blame] | 19 | #define SH_PFC_MARK_INVALID ((pinmux_enum_t)-1) |
| 20 | |
Paul Mundt | 06d5631 | 2012-06-21 00:03:41 +0900 | [diff] [blame] | 21 | enum { |
| 22 | PINMUX_TYPE_NONE, |
Magnus Damm | fae4339 | 2009-11-27 07:38:01 +0000 | [diff] [blame] | 23 | |
Paul Mundt | 06d5631 | 2012-06-21 00:03:41 +0900 | [diff] [blame] | 24 | PINMUX_TYPE_FUNCTION, |
| 25 | PINMUX_TYPE_GPIO, |
| 26 | PINMUX_TYPE_OUTPUT, |
| 27 | PINMUX_TYPE_INPUT, |
| 28 | PINMUX_TYPE_INPUT_PULLUP, |
| 29 | PINMUX_TYPE_INPUT_PULLDOWN, |
| 30 | |
| 31 | PINMUX_FLAG_TYPE, /* must be last */ |
| 32 | }; |
Magnus Damm | fae4339 | 2009-11-27 07:38:01 +0000 | [diff] [blame] | 33 | |
| 34 | #define PINMUX_FLAG_DBIT_SHIFT 5 |
| 35 | #define PINMUX_FLAG_DBIT (0x1f << PINMUX_FLAG_DBIT_SHIFT) |
| 36 | #define PINMUX_FLAG_DREG_SHIFT 10 |
| 37 | #define PINMUX_FLAG_DREG (0x3f << PINMUX_FLAG_DREG_SHIFT) |
| 38 | |
Laurent Pinchart | a3db40a | 2013-01-02 14:53:37 +0100 | [diff] [blame] | 39 | struct sh_pfc_pin { |
Laurent Pinchart | 051fae4 | 2012-11-28 19:22:18 +0100 | [diff] [blame] | 40 | const pinmux_enum_t enum_id; |
Laurent Pinchart | a3db40a | 2013-01-02 14:53:37 +0100 | [diff] [blame] | 41 | unsigned short flags; |
Paul Mundt | 72c7afa | 2012-07-10 11:59:29 +0900 | [diff] [blame] | 42 | const char *name; |
Magnus Damm | fae4339 | 2009-11-27 07:38:01 +0000 | [diff] [blame] | 43 | }; |
| 44 | |
Laurent Pinchart | 3d8d9f1 | 2013-01-03 14:33:13 +0100 | [diff] [blame] | 45 | #define SH_PFC_PIN_GROUP(n) \ |
| 46 | { \ |
| 47 | .name = #n, \ |
| 48 | .pins = n##_pins, \ |
| 49 | .mux = n##_mux, \ |
| 50 | .nr_pins = ARRAY_SIZE(n##_pins), \ |
| 51 | } |
| 52 | |
| 53 | struct sh_pfc_pin_group { |
| 54 | const char *name; |
| 55 | const unsigned int *pins; |
| 56 | const unsigned int *mux; |
| 57 | unsigned int nr_pins; |
| 58 | }; |
| 59 | |
| 60 | #define SH_PFC_FUNCTION(n) \ |
| 61 | { \ |
| 62 | .name = #n, \ |
| 63 | .groups = n##_groups, \ |
| 64 | .nr_groups = ARRAY_SIZE(n##_groups), \ |
| 65 | } |
| 66 | |
| 67 | struct sh_pfc_function { |
| 68 | const char *name; |
| 69 | const char * const *groups; |
| 70 | unsigned int nr_groups; |
| 71 | }; |
| 72 | |
Laurent Pinchart | a373ed0 | 2012-11-29 13:24:07 +0100 | [diff] [blame] | 73 | struct pinmux_func { |
| 74 | const pinmux_enum_t enum_id; |
| 75 | const char *name; |
| 76 | }; |
| 77 | |
Laurent Pinchart | 380c2ed | 2012-11-29 02:23:26 +0100 | [diff] [blame] | 78 | #define PINMUX_GPIO(gpio, data_or_mark) \ |
| 79 | [gpio] = { \ |
| 80 | .name = __stringify(gpio), \ |
| 81 | .enum_id = data_or_mark, \ |
| 82 | .flags = PINMUX_TYPE_GPIO \ |
| 83 | } |
Laurent Pinchart | a373ed0 | 2012-11-29 13:24:07 +0100 | [diff] [blame] | 84 | #define PINMUX_GPIO_FN(gpio, base, data_or_mark) \ |
| 85 | [gpio - (base)] = { \ |
Laurent Pinchart | 380c2ed | 2012-11-29 02:23:26 +0100 | [diff] [blame] | 86 | .name = __stringify(gpio), \ |
| 87 | .enum_id = data_or_mark, \ |
Laurent Pinchart | 380c2ed | 2012-11-29 02:23:26 +0100 | [diff] [blame] | 88 | } |
Paul Mundt | 06d5631 | 2012-06-21 00:03:41 +0900 | [diff] [blame] | 89 | |
Magnus Damm | fae4339 | 2009-11-27 07:38:01 +0000 | [diff] [blame] | 90 | #define PINMUX_DATA(data_or_mark, ids...) data_or_mark, ids, 0 |
| 91 | |
| 92 | struct pinmux_cfg_reg { |
| 93 | unsigned long reg, reg_width, field_width; |
| 94 | unsigned long *cnt; |
| 95 | pinmux_enum_t *enum_ids; |
Magnus Damm | f78a26f | 2011-12-14 01:01:05 +0900 | [diff] [blame] | 96 | unsigned long *var_field_width; |
Magnus Damm | fae4339 | 2009-11-27 07:38:01 +0000 | [diff] [blame] | 97 | }; |
| 98 | |
| 99 | #define PINMUX_CFG_REG(name, r, r_width, f_width) \ |
| 100 | .reg = r, .reg_width = r_width, .field_width = f_width, \ |
| 101 | .cnt = (unsigned long [r_width / f_width]) {}, \ |
Magnus Damm | f78a26f | 2011-12-14 01:01:05 +0900 | [diff] [blame] | 102 | .enum_ids = (pinmux_enum_t [(r_width / f_width) * (1 << f_width)]) |
| 103 | |
| 104 | #define PINMUX_CFG_REG_VAR(name, r, r_width, var_fw0, var_fwn...) \ |
| 105 | .reg = r, .reg_width = r_width, \ |
| 106 | .cnt = (unsigned long [r_width]) {}, \ |
| 107 | .var_field_width = (unsigned long [r_width]) { var_fw0, var_fwn, 0 }, \ |
| 108 | .enum_ids = (pinmux_enum_t []) |
Magnus Damm | fae4339 | 2009-11-27 07:38:01 +0000 | [diff] [blame] | 109 | |
| 110 | struct pinmux_data_reg { |
Laurent Pinchart | 51cb226 | 2013-02-16 18:34:32 +0100 | [diff] [blame^] | 111 | unsigned long reg, reg_width; |
Magnus Damm | fae4339 | 2009-11-27 07:38:01 +0000 | [diff] [blame] | 112 | pinmux_enum_t *enum_ids; |
| 113 | }; |
| 114 | |
| 115 | #define PINMUX_DATA_REG(name, r, r_width) \ |
| 116 | .reg = r, .reg_width = r_width, \ |
| 117 | .enum_ids = (pinmux_enum_t [r_width]) \ |
| 118 | |
Magnus Damm | ad2a8e7 | 2011-09-28 16:50:58 +0900 | [diff] [blame] | 119 | struct pinmux_irq { |
| 120 | int irq; |
Laurent Pinchart | c07f54f | 2013-01-03 14:12:14 +0100 | [diff] [blame] | 121 | unsigned short *gpios; |
Magnus Damm | ad2a8e7 | 2011-09-28 16:50:58 +0900 | [diff] [blame] | 122 | }; |
| 123 | |
| 124 | #define PINMUX_IRQ(irq_nr, ids...) \ |
Laurent Pinchart | c07f54f | 2013-01-03 14:12:14 +0100 | [diff] [blame] | 125 | { .irq = irq_nr, .gpios = (unsigned short []) { ids, 0 } } \ |
Magnus Damm | ad2a8e7 | 2011-09-28 16:50:58 +0900 | [diff] [blame] | 126 | |
Magnus Damm | fae4339 | 2009-11-27 07:38:01 +0000 | [diff] [blame] | 127 | struct pinmux_range { |
| 128 | pinmux_enum_t begin; |
| 129 | pinmux_enum_t end; |
| 130 | pinmux_enum_t force; |
| 131 | }; |
| 132 | |
Laurent Pinchart | 19bb7fe3 | 2012-12-15 23:51:20 +0100 | [diff] [blame] | 133 | struct sh_pfc_soc_info { |
Magnus Damm | fae4339 | 2009-11-27 07:38:01 +0000 | [diff] [blame] | 134 | char *name; |
Magnus Damm | fae4339 | 2009-11-27 07:38:01 +0000 | [diff] [blame] | 135 | struct pinmux_range input; |
| 136 | struct pinmux_range input_pd; |
| 137 | struct pinmux_range input_pu; |
| 138 | struct pinmux_range output; |
Magnus Damm | fae4339 | 2009-11-27 07:38:01 +0000 | [diff] [blame] | 139 | struct pinmux_range function; |
| 140 | |
Laurent Pinchart | a3db40a | 2013-01-02 14:53:37 +0100 | [diff] [blame] | 141 | struct sh_pfc_pin *pins; |
Laurent Pinchart | caa5bac | 2012-11-29 12:24:51 +0100 | [diff] [blame] | 142 | unsigned int nr_pins; |
Laurent Pinchart | 63d5738 | 2013-02-15 01:33:38 +0100 | [diff] [blame] | 143 | const struct pinmux_range *ranges; |
| 144 | unsigned int nr_ranges; |
Laurent Pinchart | 3d8d9f1 | 2013-01-03 14:33:13 +0100 | [diff] [blame] | 145 | const struct sh_pfc_pin_group *groups; |
| 146 | unsigned int nr_groups; |
| 147 | const struct sh_pfc_function *functions; |
| 148 | unsigned int nr_functions; |
| 149 | |
Laurent Pinchart | a373ed0 | 2012-11-29 13:24:07 +0100 | [diff] [blame] | 150 | struct pinmux_func *func_gpios; |
| 151 | unsigned int nr_func_gpios; |
Laurent Pinchart | d7a7ca5 | 2012-11-28 17:51:00 +0100 | [diff] [blame] | 152 | |
Magnus Damm | fae4339 | 2009-11-27 07:38:01 +0000 | [diff] [blame] | 153 | struct pinmux_cfg_reg *cfg_regs; |
| 154 | struct pinmux_data_reg *data_regs; |
| 155 | |
| 156 | pinmux_enum_t *gpio_data; |
| 157 | unsigned int gpio_data_size; |
| 158 | |
Magnus Damm | ad2a8e7 | 2011-09-28 16:50:58 +0900 | [diff] [blame] | 159 | struct pinmux_irq *gpio_irq; |
| 160 | unsigned int gpio_irq_size; |
| 161 | |
Magnus Damm | e499ada | 2011-12-14 01:01:14 +0900 | [diff] [blame] | 162 | unsigned long unlock_reg; |
Magnus Damm | fae4339 | 2009-11-27 07:38:01 +0000 | [diff] [blame] | 163 | }; |
| 164 | |
Paul Mundt | b3c185a | 2012-06-20 17:29:04 +0900 | [diff] [blame] | 165 | enum { GPIO_CFG_DRYRUN, GPIO_CFG_REQ, GPIO_CFG_FREE }; |
Magnus Damm | fae4339 | 2009-11-27 07:38:01 +0000 | [diff] [blame] | 166 | |
Kuninori Morimoto | 972c3fb | 2011-11-10 18:45:33 -0800 | [diff] [blame] | 167 | /* helper macro for port */ |
| 168 | #define PORT_1(fn, pfx, sfx) fn(pfx, sfx) |
| 169 | |
| 170 | #define PORT_10(fn, pfx, sfx) \ |
| 171 | PORT_1(fn, pfx##0, sfx), PORT_1(fn, pfx##1, sfx), \ |
| 172 | PORT_1(fn, pfx##2, sfx), PORT_1(fn, pfx##3, sfx), \ |
| 173 | PORT_1(fn, pfx##4, sfx), PORT_1(fn, pfx##5, sfx), \ |
| 174 | PORT_1(fn, pfx##6, sfx), PORT_1(fn, pfx##7, sfx), \ |
| 175 | PORT_1(fn, pfx##8, sfx), PORT_1(fn, pfx##9, sfx) |
| 176 | |
Laurent Pinchart | 17dffe4 | 2013-02-13 22:09:27 +0100 | [diff] [blame] | 177 | #define PORT_10_REV(fn, pfx, sfx) \ |
| 178 | PORT_1(fn, pfx##9, sfx), PORT_1(fn, pfx##8, sfx), \ |
| 179 | PORT_1(fn, pfx##7, sfx), PORT_1(fn, pfx##6, sfx), \ |
| 180 | PORT_1(fn, pfx##5, sfx), PORT_1(fn, pfx##4, sfx), \ |
| 181 | PORT_1(fn, pfx##3, sfx), PORT_1(fn, pfx##2, sfx), \ |
| 182 | PORT_1(fn, pfx##1, sfx), PORT_1(fn, pfx##0, sfx) |
| 183 | |
| 184 | #define PORT_32(fn, pfx, sfx) \ |
| 185 | PORT_10(fn, pfx, sfx), PORT_10(fn, pfx##1, sfx), \ |
| 186 | PORT_10(fn, pfx##2, sfx), PORT_1(fn, pfx##30, sfx), \ |
| 187 | PORT_1(fn, pfx##31, sfx) |
| 188 | |
| 189 | #define PORT_32_REV(fn, pfx, sfx) \ |
| 190 | PORT_1(fn, pfx##31, sfx), PORT_1(fn, pfx##30, sfx), \ |
| 191 | PORT_10_REV(fn, pfx##2, sfx), PORT_10_REV(fn, pfx##1, sfx), \ |
| 192 | PORT_10_REV(fn, pfx, sfx) |
| 193 | |
Kuninori Morimoto | 972c3fb | 2011-11-10 18:45:33 -0800 | [diff] [blame] | 194 | #define PORT_90(fn, pfx, sfx) \ |
| 195 | PORT_10(fn, pfx##1, sfx), PORT_10(fn, pfx##2, sfx), \ |
| 196 | PORT_10(fn, pfx##3, sfx), PORT_10(fn, pfx##4, sfx), \ |
| 197 | PORT_10(fn, pfx##5, sfx), PORT_10(fn, pfx##6, sfx), \ |
| 198 | PORT_10(fn, pfx##7, sfx), PORT_10(fn, pfx##8, sfx), \ |
| 199 | PORT_10(fn, pfx##9, sfx) |
| 200 | |
| 201 | #define _PORT_ALL(pfx, sfx) pfx##_##sfx |
| 202 | #define _GPIO_PORT(pfx, sfx) PINMUX_GPIO(GPIO_PORT##pfx, PORT##pfx##_DATA) |
| 203 | #define PORT_ALL(str) CPU_ALL_PORT(_PORT_ALL, PORT, str) |
| 204 | #define GPIO_PORT_ALL() CPU_ALL_PORT(_GPIO_PORT, , unused) |
Laurent Pinchart | a373ed0 | 2012-11-29 13:24:07 +0100 | [diff] [blame] | 205 | #define GPIO_FN(str) PINMUX_GPIO_FN(GPIO_FN_##str, PINMUX_FN_BASE, str##_MARK) |
Kuninori Morimoto | 972c3fb | 2011-11-10 18:45:33 -0800 | [diff] [blame] | 206 | |
Kuninori Morimoto | bd8d0cba | 2011-11-10 18:45:23 -0800 | [diff] [blame] | 207 | /* helper macro for pinmux_enum_t */ |
| 208 | #define PORT_DATA_I(nr) \ |
| 209 | PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_IN) |
| 210 | |
| 211 | #define PORT_DATA_I_PD(nr) \ |
| 212 | PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, \ |
| 213 | PORT##nr##_IN, PORT##nr##_IN_PD) |
| 214 | |
| 215 | #define PORT_DATA_I_PU(nr) \ |
| 216 | PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, \ |
| 217 | PORT##nr##_IN, PORT##nr##_IN_PU) |
| 218 | |
| 219 | #define PORT_DATA_I_PU_PD(nr) \ |
| 220 | PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, \ |
| 221 | PORT##nr##_IN, PORT##nr##_IN_PD, PORT##nr##_IN_PU) |
| 222 | |
| 223 | #define PORT_DATA_O(nr) \ |
| 224 | PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT) |
| 225 | |
| 226 | #define PORT_DATA_IO(nr) \ |
| 227 | PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT, \ |
| 228 | PORT##nr##_IN) |
| 229 | |
| 230 | #define PORT_DATA_IO_PD(nr) \ |
| 231 | PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT, \ |
| 232 | PORT##nr##_IN, PORT##nr##_IN_PD) |
| 233 | |
| 234 | #define PORT_DATA_IO_PU(nr) \ |
| 235 | PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT, \ |
| 236 | PORT##nr##_IN, PORT##nr##_IN_PU) |
| 237 | |
| 238 | #define PORT_DATA_IO_PU_PD(nr) \ |
| 239 | PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT, \ |
| 240 | PORT##nr##_IN, PORT##nr##_IN_PD, PORT##nr##_IN_PU) |
| 241 | |
Kuninori Morimoto | 9b49139 | 2011-11-10 18:45:43 -0800 | [diff] [blame] | 242 | /* helper macro for top 4 bits in PORTnCR */ |
| 243 | #define _PCRH(in, in_pd, in_pu, out) \ |
| 244 | 0, (out), (in), 0, \ |
| 245 | 0, 0, 0, 0, \ |
| 246 | 0, 0, (in_pd), 0, \ |
| 247 | 0, 0, (in_pu), 0 |
| 248 | |
| 249 | #define PORTCR(nr, reg) \ |
| 250 | { \ |
| 251 | PINMUX_CFG_REG("PORT" nr "CR", reg, 8, 4) { \ |
| 252 | _PCRH(PORT##nr##_IN, PORT##nr##_IN_PD, \ |
| 253 | PORT##nr##_IN_PU, PORT##nr##_OUT), \ |
| 254 | PORT##nr##_FN0, PORT##nr##_FN1, \ |
| 255 | PORT##nr##_FN2, PORT##nr##_FN3, \ |
| 256 | PORT##nr##_FN4, PORT##nr##_FN5, \ |
| 257 | PORT##nr##_FN6, PORT##nr##_FN7 } \ |
| 258 | } |
Kuninori Morimoto | bd8d0cba | 2011-11-10 18:45:23 -0800 | [diff] [blame] | 259 | |
Magnus Damm | fae4339 | 2009-11-27 07:38:01 +0000 | [diff] [blame] | 260 | #endif /* __SH_PFC_H */ |