Commit | Line | Data |
---|---|---|
2967dab1 | 1 | /* |
b3c185a7 | 2 | * SuperH Pin Function Controller support. |
2967dab1 MD |
3 | * |
4 | * Copyright (C) 2008 Magnus Damm | |
b3c185a7 | 5 | * Copyright (C) 2009 - 2012 Paul Mundt |
2967dab1 MD |
6 | * |
7 | * This file is subject to the terms and conditions of the GNU General Public | |
8 | * License. See the file "COPYING" in the main directory of this archive | |
9 | * for more details. | |
10 | */ | |
c6193eac LP |
11 | |
12 | #define DRV_NAME "sh-pfc" | |
f9492fda | 13 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
b72421d8 | 14 | |
90efde22 | 15 | #include <linux/bitops.h> |
2967dab1 | 16 | #include <linux/err.h> |
90efde22 | 17 | #include <linux/errno.h> |
2967dab1 | 18 | #include <linux/io.h> |
b0e10211 | 19 | #include <linux/ioport.h> |
90efde22 LP |
20 | #include <linux/kernel.h> |
21 | #include <linux/module.h> | |
ca5481c6 | 22 | #include <linux/pinctrl/machine.h> |
c6193eac | 23 | #include <linux/platform_device.h> |
90efde22 | 24 | #include <linux/slab.h> |
b0e10211 | 25 | |
f9165132 LP |
26 | #include "core.h" |
27 | ||
973931ae | 28 | static int sh_pfc_ioremap(struct sh_pfc *pfc, struct platform_device *pdev) |
b0e10211 MD |
29 | { |
30 | struct resource *res; | |
31 | int k; | |
32 | ||
56dc04af | 33 | if (pdev->num_resources == 0) { |
973931ae | 34 | pfc->num_windows = 0; |
b0e10211 | 35 | return 0; |
973931ae | 36 | } |
b0e10211 | 37 | |
56dc04af | 38 | pfc->window = devm_kzalloc(pfc->dev, pdev->num_resources * |
1724acfd | 39 | sizeof(*pfc->window), GFP_NOWAIT); |
b3c185a7 | 40 | if (!pfc->window) |
1724acfd | 41 | return -ENOMEM; |
b0e10211 | 42 | |
56dc04af | 43 | pfc->num_windows = pdev->num_resources; |
973931ae | 44 | |
56dc04af | 45 | for (k = 0, res = pdev->resource; k < pdev->num_resources; k++, res++) { |
b0e10211 | 46 | WARN_ON(resource_type(res) != IORESOURCE_MEM); |
b3c185a7 PM |
47 | pfc->window[k].phys = res->start; |
48 | pfc->window[k].size = resource_size(res); | |
c9fa88e2 LP |
49 | pfc->window[k].virt = devm_ioremap_nocache(pfc->dev, res->start, |
50 | resource_size(res)); | |
51 | if (!pfc->window[k].virt) | |
1724acfd | 52 | return -ENOMEM; |
b0e10211 MD |
53 | } |
54 | ||
55 | return 0; | |
b0e10211 MD |
56 | } |
57 | ||
4aeacd5b LP |
58 | static void __iomem *sh_pfc_phys_to_virt(struct sh_pfc *pfc, |
59 | unsigned long address) | |
b0e10211 | 60 | { |
4aeacd5b | 61 | struct sh_pfc_window *window; |
b0e10211 MD |
62 | int k; |
63 | ||
64 | /* scan through physical windows and convert address */ | |
973931ae | 65 | for (k = 0; k < pfc->num_windows; k++) { |
b3c185a7 | 66 | window = pfc->window + k; |
b0e10211 MD |
67 | |
68 | if (address < window->phys) | |
69 | continue; | |
70 | ||
71 | if (address >= (window->phys + window->size)) | |
72 | continue; | |
73 | ||
74 | return window->virt + (address - window->phys); | |
75 | } | |
76 | ||
77 | /* no windows defined, register must be 1:1 mapped virt:phys */ | |
78 | return (void __iomem *)address; | |
79 | } | |
2967dab1 | 80 | |
4aeacd5b | 81 | static int sh_pfc_enum_in_range(pinmux_enum_t enum_id, struct pinmux_range *r) |
2967dab1 MD |
82 | { |
83 | if (enum_id < r->begin) | |
84 | return 0; | |
85 | ||
86 | if (enum_id > r->end) | |
87 | return 0; | |
88 | ||
89 | return 1; | |
90 | } | |
91 | ||
caa5bac3 LP |
92 | static bool sh_pfc_gpio_is_pin(struct sh_pfc *pfc, unsigned int gpio) |
93 | { | |
94 | return (gpio < pfc->info->nr_pins) && | |
a373ed0a | 95 | (pfc->info->pins[gpio].enum_id != 0); |
caa5bac3 LP |
96 | } |
97 | ||
2119f7c9 | 98 | bool sh_pfc_gpio_is_function(struct sh_pfc *pfc, unsigned int gpio) |
caa5bac3 | 99 | { |
a373ed0a LP |
100 | return (gpio >= pfc->info->nr_pins) && |
101 | (gpio < pfc->info->nr_pins + pfc->info->nr_func_gpios) && | |
102 | (pfc->info->func_gpios[gpio - pfc->info->nr_pins].enum_id != 0); | |
caa5bac3 LP |
103 | } |
104 | ||
4aeacd5b LP |
105 | static unsigned long sh_pfc_read_raw_reg(void __iomem *mapped_reg, |
106 | unsigned long reg_width) | |
3292094e MD |
107 | { |
108 | switch (reg_width) { | |
109 | case 8: | |
b0e10211 | 110 | return ioread8(mapped_reg); |
3292094e | 111 | case 16: |
b0e10211 | 112 | return ioread16(mapped_reg); |
3292094e | 113 | case 32: |
b0e10211 | 114 | return ioread32(mapped_reg); |
3292094e MD |
115 | } |
116 | ||
117 | BUG(); | |
118 | return 0; | |
119 | } | |
120 | ||
4aeacd5b LP |
121 | static void sh_pfc_write_raw_reg(void __iomem *mapped_reg, |
122 | unsigned long reg_width, unsigned long data) | |
3292094e MD |
123 | { |
124 | switch (reg_width) { | |
125 | case 8: | |
b0e10211 | 126 | iowrite8(data, mapped_reg); |
3292094e MD |
127 | return; |
128 | case 16: | |
b0e10211 | 129 | iowrite16(data, mapped_reg); |
3292094e MD |
130 | return; |
131 | case 32: | |
b0e10211 | 132 | iowrite32(data, mapped_reg); |
3292094e MD |
133 | return; |
134 | } | |
135 | ||
136 | BUG(); | |
137 | } | |
138 | ||
b3c185a7 | 139 | int sh_pfc_read_bit(struct pinmux_data_reg *dr, unsigned long in_pos) |
92554d97 MD |
140 | { |
141 | unsigned long pos; | |
142 | ||
143 | pos = dr->reg_width - (in_pos + 1); | |
144 | ||
145 | pr_debug("read_bit: addr = %lx, pos = %ld, " | |
146 | "r_width = %ld\n", dr->reg, pos, dr->reg_width); | |
147 | ||
4aeacd5b | 148 | return (sh_pfc_read_raw_reg(dr->mapped_reg, dr->reg_width) >> pos) & 1; |
92554d97 MD |
149 | } |
150 | ||
b3c185a7 PM |
151 | void sh_pfc_write_bit(struct pinmux_data_reg *dr, unsigned long in_pos, |
152 | unsigned long value) | |
3292094e MD |
153 | { |
154 | unsigned long pos; | |
155 | ||
156 | pos = dr->reg_width - (in_pos + 1); | |
157 | ||
ca6f2d7f | 158 | pr_debug("write_bit addr = %lx, value = %d, pos = %ld, " |
fd2cb0ce PM |
159 | "r_width = %ld\n", |
160 | dr->reg, !!value, pos, dr->reg_width); | |
3292094e MD |
161 | |
162 | if (value) | |
163 | set_bit(pos, &dr->reg_shadow); | |
164 | else | |
165 | clear_bit(pos, &dr->reg_shadow); | |
166 | ||
4aeacd5b | 167 | sh_pfc_write_raw_reg(dr->mapped_reg, dr->reg_width, dr->reg_shadow); |
3292094e MD |
168 | } |
169 | ||
4aeacd5b LP |
170 | static void sh_pfc_config_reg_helper(struct sh_pfc *pfc, |
171 | struct pinmux_cfg_reg *crp, | |
172 | unsigned long in_pos, | |
173 | void __iomem **mapped_regp, | |
174 | unsigned long *maskp, | |
175 | unsigned long *posp) | |
2967dab1 | 176 | { |
f78a26f5 MD |
177 | int k; |
178 | ||
4aeacd5b | 179 | *mapped_regp = sh_pfc_phys_to_virt(pfc, crp->reg); |
2967dab1 | 180 | |
f78a26f5 MD |
181 | if (crp->field_width) { |
182 | *maskp = (1 << crp->field_width) - 1; | |
183 | *posp = crp->reg_width - ((in_pos + 1) * crp->field_width); | |
184 | } else { | |
185 | *maskp = (1 << crp->var_field_width[in_pos]) - 1; | |
186 | *posp = crp->reg_width; | |
187 | for (k = 0; k <= in_pos; k++) | |
188 | *posp -= crp->var_field_width[k]; | |
189 | } | |
18925e11 MD |
190 | } |
191 | ||
4aeacd5b LP |
192 | static int sh_pfc_read_config_reg(struct sh_pfc *pfc, |
193 | struct pinmux_cfg_reg *crp, | |
194 | unsigned long field) | |
18925e11 MD |
195 | { |
196 | void __iomem *mapped_reg; | |
197 | unsigned long mask, pos; | |
198 | ||
4aeacd5b | 199 | sh_pfc_config_reg_helper(pfc, crp, field, &mapped_reg, &mask, &pos); |
2967dab1 | 200 | |
18925e11 | 201 | pr_debug("read_reg: addr = %lx, field = %ld, " |
fd2cb0ce | 202 | "r_width = %ld, f_width = %ld\n", |
18925e11 | 203 | crp->reg, field, crp->reg_width, crp->field_width); |
2967dab1 | 204 | |
4aeacd5b | 205 | return (sh_pfc_read_raw_reg(mapped_reg, crp->reg_width) >> pos) & mask; |
0fc64cc0 MD |
206 | } |
207 | ||
4aeacd5b LP |
208 | static void sh_pfc_write_config_reg(struct sh_pfc *pfc, |
209 | struct pinmux_cfg_reg *crp, | |
210 | unsigned long field, unsigned long value) | |
0fc64cc0 | 211 | { |
18925e11 | 212 | void __iomem *mapped_reg; |
e499ada8 | 213 | unsigned long mask, pos, data; |
0fc64cc0 | 214 | |
4aeacd5b | 215 | sh_pfc_config_reg_helper(pfc, crp, field, &mapped_reg, &mask, &pos); |
2967dab1 | 216 | |
18925e11 | 217 | pr_debug("write_reg addr = %lx, value = %ld, field = %ld, " |
fd2cb0ce | 218 | "r_width = %ld, f_width = %ld\n", |
18925e11 | 219 | crp->reg, value, field, crp->reg_width, crp->field_width); |
0fc64cc0 MD |
220 | |
221 | mask = ~(mask << pos); | |
222 | value = value << pos; | |
2967dab1 | 223 | |
4aeacd5b | 224 | data = sh_pfc_read_raw_reg(mapped_reg, crp->reg_width); |
e499ada8 MD |
225 | data &= mask; |
226 | data |= value; | |
227 | ||
19bb7fe3 | 228 | if (pfc->info->unlock_reg) |
4aeacd5b | 229 | sh_pfc_write_raw_reg( |
19bb7fe3 | 230 | sh_pfc_phys_to_virt(pfc, pfc->info->unlock_reg), 32, |
4aeacd5b | 231 | ~data); |
e499ada8 | 232 | |
4aeacd5b | 233 | sh_pfc_write_raw_reg(mapped_reg, crp->reg_width, data); |
2967dab1 MD |
234 | } |
235 | ||
4aeacd5b | 236 | static int sh_pfc_setup_data_reg(struct sh_pfc *pfc, unsigned gpio) |
2967dab1 | 237 | { |
a373ed0a | 238 | struct pinmux_pin *gpiop = &pfc->info->pins[gpio]; |
2967dab1 MD |
239 | struct pinmux_data_reg *data_reg; |
240 | int k, n; | |
241 | ||
caa5bac3 | 242 | if (!sh_pfc_gpio_is_pin(pfc, gpio)) |
2967dab1 MD |
243 | return -1; |
244 | ||
245 | k = 0; | |
246 | while (1) { | |
19bb7fe3 | 247 | data_reg = pfc->info->data_regs + k; |
2967dab1 MD |
248 | |
249 | if (!data_reg->reg_width) | |
250 | break; | |
251 | ||
4aeacd5b | 252 | data_reg->mapped_reg = sh_pfc_phys_to_virt(pfc, data_reg->reg); |
b0e10211 | 253 | |
2967dab1 | 254 | for (n = 0; n < data_reg->reg_width; n++) { |
18801be7 MD |
255 | if (data_reg->enum_ids[n] == gpiop->enum_id) { |
256 | gpiop->flags &= ~PINMUX_FLAG_DREG; | |
257 | gpiop->flags |= (k << PINMUX_FLAG_DREG_SHIFT); | |
258 | gpiop->flags &= ~PINMUX_FLAG_DBIT; | |
259 | gpiop->flags |= (n << PINMUX_FLAG_DBIT_SHIFT); | |
2967dab1 | 260 | return 0; |
2967dab1 MD |
261 | } |
262 | } | |
263 | k++; | |
264 | } | |
265 | ||
18801be7 MD |
266 | BUG(); |
267 | ||
2967dab1 MD |
268 | return -1; |
269 | } | |
270 | ||
4aeacd5b | 271 | static void sh_pfc_setup_data_regs(struct sh_pfc *pfc) |
3292094e MD |
272 | { |
273 | struct pinmux_data_reg *drp; | |
274 | int k; | |
275 | ||
caa5bac3 | 276 | for (k = 0; k < pfc->info->nr_pins; k++) |
4aeacd5b | 277 | sh_pfc_setup_data_reg(pfc, k); |
3292094e MD |
278 | |
279 | k = 0; | |
280 | while (1) { | |
19bb7fe3 | 281 | drp = pfc->info->data_regs + k; |
3292094e MD |
282 | |
283 | if (!drp->reg_width) | |
284 | break; | |
285 | ||
4aeacd5b LP |
286 | drp->reg_shadow = sh_pfc_read_raw_reg(drp->mapped_reg, |
287 | drp->reg_width); | |
3292094e MD |
288 | k++; |
289 | } | |
290 | } | |
291 | ||
b3c185a7 | 292 | int sh_pfc_get_data_reg(struct sh_pfc *pfc, unsigned gpio, |
18801be7 MD |
293 | struct pinmux_data_reg **drp, int *bitp) |
294 | { | |
a373ed0a | 295 | struct pinmux_pin *gpiop = &pfc->info->pins[gpio]; |
18801be7 MD |
296 | int k, n; |
297 | ||
caa5bac3 | 298 | if (!sh_pfc_gpio_is_pin(pfc, gpio)) |
18801be7 MD |
299 | return -1; |
300 | ||
301 | k = (gpiop->flags & PINMUX_FLAG_DREG) >> PINMUX_FLAG_DREG_SHIFT; | |
302 | n = (gpiop->flags & PINMUX_FLAG_DBIT) >> PINMUX_FLAG_DBIT_SHIFT; | |
19bb7fe3 | 303 | *drp = pfc->info->data_regs + k; |
18801be7 MD |
304 | *bitp = n; |
305 | return 0; | |
306 | } | |
307 | ||
4aeacd5b LP |
308 | static int sh_pfc_get_config_reg(struct sh_pfc *pfc, pinmux_enum_t enum_id, |
309 | struct pinmux_cfg_reg **crp, int *fieldp, | |
310 | int *valuep, unsigned long **cntp) | |
2967dab1 MD |
311 | { |
312 | struct pinmux_cfg_reg *config_reg; | |
f78a26f5 MD |
313 | unsigned long r_width, f_width, curr_width, ncomb; |
314 | int k, m, n, pos, bit_pos; | |
2967dab1 MD |
315 | |
316 | k = 0; | |
317 | while (1) { | |
19bb7fe3 | 318 | config_reg = pfc->info->cfg_regs + k; |
2967dab1 MD |
319 | |
320 | r_width = config_reg->reg_width; | |
321 | f_width = config_reg->field_width; | |
322 | ||
323 | if (!r_width) | |
324 | break; | |
f78a26f5 MD |
325 | |
326 | pos = 0; | |
327 | m = 0; | |
328 | for (bit_pos = 0; bit_pos < r_width; bit_pos += curr_width) { | |
329 | if (f_width) | |
330 | curr_width = f_width; | |
331 | else | |
332 | curr_width = config_reg->var_field_width[m]; | |
333 | ||
334 | ncomb = 1 << curr_width; | |
335 | for (n = 0; n < ncomb; n++) { | |
336 | if (config_reg->enum_ids[pos + n] == enum_id) { | |
337 | *crp = config_reg; | |
338 | *fieldp = m; | |
339 | *valuep = n; | |
340 | *cntp = &config_reg->cnt[m]; | |
341 | return 0; | |
342 | } | |
2967dab1 | 343 | } |
f78a26f5 MD |
344 | pos += ncomb; |
345 | m++; | |
2967dab1 MD |
346 | } |
347 | k++; | |
348 | } | |
349 | ||
350 | return -1; | |
351 | } | |
352 | ||
b3c185a7 PM |
353 | int sh_pfc_gpio_to_enum(struct sh_pfc *pfc, unsigned gpio, int pos, |
354 | pinmux_enum_t *enum_idp) | |
2967dab1 | 355 | { |
19bb7fe3 | 356 | pinmux_enum_t *data = pfc->info->gpio_data; |
a373ed0a | 357 | pinmux_enum_t enum_id; |
2967dab1 MD |
358 | int k; |
359 | ||
a373ed0a LP |
360 | if (sh_pfc_gpio_is_pin(pfc, gpio)) { |
361 | enum_id = pfc->info->pins[gpio].enum_id; | |
362 | } else if (sh_pfc_gpio_is_function(pfc, gpio)) { | |
363 | unsigned int offset = gpio - pfc->info->nr_pins; | |
364 | enum_id = pfc->info->func_gpios[offset].enum_id; | |
365 | } else { | |
caa5bac3 LP |
366 | pr_err("non data/mark enum_id for gpio %d\n", gpio); |
367 | return -1; | |
2967dab1 MD |
368 | } |
369 | ||
370 | if (pos) { | |
371 | *enum_idp = data[pos + 1]; | |
372 | return pos + 1; | |
373 | } | |
374 | ||
19bb7fe3 | 375 | for (k = 0; k < pfc->info->gpio_data_size; k++) { |
2967dab1 MD |
376 | if (data[k] == enum_id) { |
377 | *enum_idp = data[k + 1]; | |
378 | return k + 1; | |
379 | } | |
380 | } | |
381 | ||
382 | pr_err("cannot locate data/mark enum_id for gpio %d\n", gpio); | |
383 | return -1; | |
384 | } | |
385 | ||
b3c185a7 PM |
386 | int sh_pfc_config_gpio(struct sh_pfc *pfc, unsigned gpio, int pinmux_type, |
387 | int cfg_mode) | |
2967dab1 MD |
388 | { |
389 | struct pinmux_cfg_reg *cr = NULL; | |
390 | pinmux_enum_t enum_id; | |
391 | struct pinmux_range *range; | |
ad4a07ff | 392 | int in_range, pos, field, value; |
2967dab1 MD |
393 | unsigned long *cntp; |
394 | ||
395 | switch (pinmux_type) { | |
396 | ||
397 | case PINMUX_TYPE_FUNCTION: | |
398 | range = NULL; | |
399 | break; | |
400 | ||
401 | case PINMUX_TYPE_OUTPUT: | |
19bb7fe3 | 402 | range = &pfc->info->output; |
2967dab1 MD |
403 | break; |
404 | ||
405 | case PINMUX_TYPE_INPUT: | |
19bb7fe3 | 406 | range = &pfc->info->input; |
2967dab1 MD |
407 | break; |
408 | ||
409 | case PINMUX_TYPE_INPUT_PULLUP: | |
19bb7fe3 | 410 | range = &pfc->info->input_pu; |
2967dab1 MD |
411 | break; |
412 | ||
413 | case PINMUX_TYPE_INPUT_PULLDOWN: | |
19bb7fe3 | 414 | range = &pfc->info->input_pd; |
2967dab1 MD |
415 | break; |
416 | ||
417 | default: | |
418 | goto out_err; | |
419 | } | |
420 | ||
421 | pos = 0; | |
422 | enum_id = 0; | |
ad4a07ff MD |
423 | field = 0; |
424 | value = 0; | |
2967dab1 | 425 | while (1) { |
b3c185a7 | 426 | pos = sh_pfc_gpio_to_enum(pfc, gpio, pos, &enum_id); |
2967dab1 MD |
427 | if (pos <= 0) |
428 | goto out_err; | |
429 | ||
430 | if (!enum_id) | |
431 | break; | |
432 | ||
50dd3145 | 433 | /* first check if this is a function enum */ |
19bb7fe3 | 434 | in_range = sh_pfc_enum_in_range(enum_id, &pfc->info->function); |
50dd3145 MD |
435 | if (!in_range) { |
436 | /* not a function enum */ | |
437 | if (range) { | |
438 | /* | |
439 | * other range exists, so this pin is | |
440 | * a regular GPIO pin that now is being | |
441 | * bound to a specific direction. | |
442 | * | |
443 | * for this case we only allow function enums | |
444 | * and the enums that match the other range. | |
445 | */ | |
4aeacd5b | 446 | in_range = sh_pfc_enum_in_range(enum_id, range); |
50dd3145 MD |
447 | |
448 | /* | |
449 | * special case pass through for fixed | |
450 | * input-only or output-only pins without | |
451 | * function enum register association. | |
452 | */ | |
453 | if (in_range && enum_id == range->force) | |
454 | continue; | |
455 | } else { | |
456 | /* | |
457 | * no other range exists, so this pin | |
458 | * must then be of the function type. | |
459 | * | |
460 | * allow function type pins to select | |
461 | * any combination of function/in/out | |
462 | * in their MARK lists. | |
463 | */ | |
464 | in_range = 1; | |
465 | } | |
42eed42b MD |
466 | } |
467 | ||
2967dab1 MD |
468 | if (!in_range) |
469 | continue; | |
470 | ||
4aeacd5b LP |
471 | if (sh_pfc_get_config_reg(pfc, enum_id, &cr, |
472 | &field, &value, &cntp) != 0) | |
2967dab1 MD |
473 | goto out_err; |
474 | ||
475 | switch (cfg_mode) { | |
476 | case GPIO_CFG_DRYRUN: | |
18925e11 | 477 | if (!*cntp || |
4aeacd5b | 478 | (sh_pfc_read_config_reg(pfc, cr, field) != value)) |
2967dab1 MD |
479 | continue; |
480 | break; | |
481 | ||
482 | case GPIO_CFG_REQ: | |
4aeacd5b | 483 | sh_pfc_write_config_reg(pfc, cr, field, value); |
2967dab1 MD |
484 | *cntp = *cntp + 1; |
485 | break; | |
486 | ||
487 | case GPIO_CFG_FREE: | |
488 | *cntp = *cntp - 1; | |
489 | break; | |
490 | } | |
491 | } | |
492 | ||
493 | return 0; | |
494 | out_err: | |
495 | return -1; | |
496 | } | |
497 | ||
c6193eac | 498 | static int sh_pfc_probe(struct platform_device *pdev) |
2967dab1 | 499 | { |
19bb7fe3 | 500 | struct sh_pfc_soc_info *info; |
c6193eac | 501 | struct sh_pfc *pfc; |
0fc64cc0 | 502 | int ret; |
2967dab1 | 503 | |
06d5631f PM |
504 | /* |
505 | * Ensure that the type encoding fits | |
506 | */ | |
507 | BUILD_BUG_ON(PINMUX_FLAG_TYPE > ((1 << PINMUX_FLAG_DBIT_SHIFT) - 1)); | |
508 | ||
19bb7fe3 LP |
509 | info = pdev->id_entry->driver_data |
510 | ? (void *)pdev->id_entry->driver_data : pdev->dev.platform_data; | |
511 | if (info == NULL) | |
c6193eac | 512 | return -ENODEV; |
2967dab1 | 513 | |
8c43fcc7 | 514 | pfc = devm_kzalloc(&pdev->dev, sizeof(*pfc), GFP_KERNEL); |
c6193eac LP |
515 | if (pfc == NULL) |
516 | return -ENOMEM; | |
d4e62d00 | 517 | |
19bb7fe3 | 518 | pfc->info = info; |
c6193eac LP |
519 | pfc->dev = &pdev->dev; |
520 | ||
973931ae | 521 | ret = sh_pfc_ioremap(pfc, pdev); |
c6193eac | 522 | if (unlikely(ret < 0)) |
b0e10211 MD |
523 | return ret; |
524 | ||
c6193eac | 525 | spin_lock_init(&pfc->lock); |
69edbba0 | 526 | |
ca5481c6 | 527 | pinctrl_provide_dummies(); |
4aeacd5b | 528 | sh_pfc_setup_data_regs(pfc); |
b0e10211 | 529 | |
ca5481c6 PM |
530 | /* |
531 | * Initialize pinctrl bindings first | |
532 | */ | |
c6193eac | 533 | ret = sh_pfc_register_pinctrl(pfc); |
f9492fda | 534 | if (unlikely(ret != 0)) |
c9fa88e2 | 535 | return ret; |
ca5481c6 | 536 | |
6f6a4a68 | 537 | #ifdef CONFIG_GPIO_SH_PFC |
ca5481c6 PM |
538 | /* |
539 | * Then the GPIO chip | |
540 | */ | |
c6193eac | 541 | ret = sh_pfc_register_gpiochip(pfc); |
6f6a4a68 | 542 | if (unlikely(ret != 0)) { |
ca5481c6 PM |
543 | /* |
544 | * If the GPIO chip fails to come up we still leave the | |
545 | * PFC state as it is, given that there are already | |
546 | * extant users of it that have succeeded by this point. | |
547 | */ | |
6f6a4a68 | 548 | pr_notice("failed to init GPIO chip, ignoring...\n"); |
b3c185a7 | 549 | } |
6f6a4a68 | 550 | #endif |
b72421d8 | 551 | |
c6193eac LP |
552 | platform_set_drvdata(pdev, pfc); |
553 | ||
19bb7fe3 | 554 | pr_info("%s support registered\n", info->name); |
ca5481c6 | 555 | |
b3c185a7 | 556 | return 0; |
b72421d8 | 557 | } |
6f6a4a68 | 558 | |
c6193eac LP |
559 | static int sh_pfc_remove(struct platform_device *pdev) |
560 | { | |
561 | struct sh_pfc *pfc = platform_get_drvdata(pdev); | |
562 | ||
563 | #ifdef CONFIG_GPIO_SH_PFC | |
564 | sh_pfc_unregister_gpiochip(pfc); | |
565 | #endif | |
566 | sh_pfc_unregister_pinctrl(pfc); | |
567 | ||
c6193eac LP |
568 | platform_set_drvdata(pdev, NULL); |
569 | ||
570 | return 0; | |
571 | } | |
572 | ||
573 | static const struct platform_device_id sh_pfc_id_table[] = { | |
d5b1521a LP |
574 | #ifdef CONFIG_PINCTRL_PFC_R8A7740 |
575 | { "pfc-r8a7740", (kernel_ulong_t)&r8a7740_pinmux_info }, | |
881023d2 LP |
576 | #endif |
577 | #ifdef CONFIG_PINCTRL_PFC_R8A7779 | |
578 | { "pfc-r8a7779", (kernel_ulong_t)&r8a7779_pinmux_info }, | |
6e5469a6 | 579 | #endif |
ccda552e LP |
580 | #ifdef CONFIG_PINCTRL_PFC_SH7203 |
581 | { "pfc-sh7203", (kernel_ulong_t)&sh7203_pinmux_info }, | |
582 | #endif | |
a8d42fc4 LP |
583 | #ifdef CONFIG_PINCTRL_PFC_SH7264 |
584 | { "pfc-sh7264", (kernel_ulong_t)&sh7264_pinmux_info }, | |
585 | #endif | |
f5e811f2 LP |
586 | #ifdef CONFIG_PINCTRL_PFC_SH7269 |
587 | { "pfc-sh7269", (kernel_ulong_t)&sh7269_pinmux_info }, | |
588 | #endif | |
6e5469a6 LP |
589 | #ifdef CONFIG_PINCTRL_PFC_SH7372 |
590 | { "pfc-sh7372", (kernel_ulong_t)&sh7372_pinmux_info }, | |
5d5166dc LP |
591 | #endif |
592 | #ifdef CONFIG_PINCTRL_PFC_SH73A0 | |
593 | { "pfc-sh73a0", (kernel_ulong_t)&sh73a0_pinmux_info }, | |
74cad605 LP |
594 | #endif |
595 | #ifdef CONFIG_PINCTRL_PFC_SH7720 | |
596 | { "pfc-sh7720", (kernel_ulong_t)&sh7720_pinmux_info }, | |
f5e25ae5 LP |
597 | #endif |
598 | #ifdef CONFIG_PINCTRL_PFC_SH7722 | |
599 | { "pfc-sh7722", (kernel_ulong_t)&sh7722_pinmux_info }, | |
d05afa0a LP |
600 | #endif |
601 | #ifdef CONFIG_PINCTRL_PFC_SH7723 | |
602 | { "pfc-sh7723", (kernel_ulong_t)&sh7723_pinmux_info }, | |
0ff25bab LP |
603 | #endif |
604 | #ifdef CONFIG_PINCTRL_PFC_SH7724 | |
605 | { "pfc-sh7724", (kernel_ulong_t)&sh7724_pinmux_info }, | |
ac1ebc21 LP |
606 | #endif |
607 | #ifdef CONFIG_PINCTRL_PFC_SH7734 | |
608 | { "pfc-sh7734", (kernel_ulong_t)&sh7734_pinmux_info }, | |
0bb92677 LP |
609 | #endif |
610 | #ifdef CONFIG_PINCTRL_PFC_SH7757 | |
611 | { "pfc-sh7757", (kernel_ulong_t)&sh7757_pinmux_info }, | |
a56398e9 LP |
612 | #endif |
613 | #ifdef CONFIG_PINCTRL_PFC_SH7785 | |
614 | { "pfc-sh7785", (kernel_ulong_t)&sh7785_pinmux_info }, | |
d2a31bdd LP |
615 | #endif |
616 | #ifdef CONFIG_PINCTRL_PFC_SH7786 | |
617 | { "pfc-sh7786", (kernel_ulong_t)&sh7786_pinmux_info }, | |
d5d9a818 LP |
618 | #endif |
619 | #ifdef CONFIG_PINCTRL_PFC_SHX3 | |
620 | { "pfc-shx3", (kernel_ulong_t)&shx3_pinmux_info }, | |
d5b1521a | 621 | #endif |
c6193eac LP |
622 | { "sh-pfc", 0 }, |
623 | { }, | |
624 | }; | |
625 | MODULE_DEVICE_TABLE(platform, sh_pfc_id_table); | |
626 | ||
627 | static struct platform_driver sh_pfc_driver = { | |
628 | .probe = sh_pfc_probe, | |
629 | .remove = sh_pfc_remove, | |
630 | .id_table = sh_pfc_id_table, | |
631 | .driver = { | |
632 | .name = DRV_NAME, | |
633 | .owner = THIS_MODULE, | |
634 | }, | |
635 | }; | |
636 | ||
40ee6fce LP |
637 | static int __init sh_pfc_init(void) |
638 | { | |
639 | return platform_driver_register(&sh_pfc_driver); | |
c6193eac | 640 | } |
40ee6fce | 641 | postcore_initcall(sh_pfc_init); |
c6193eac LP |
642 | |
643 | static void __exit sh_pfc_exit(void) | |
644 | { | |
645 | platform_driver_unregister(&sh_pfc_driver); | |
646 | } | |
647 | module_exit(sh_pfc_exit); | |
648 | ||
6f6a4a68 LP |
649 | MODULE_AUTHOR("Magnus Damm, Paul Mundt, Laurent Pinchart"); |
650 | MODULE_DESCRIPTION("Pin Control and GPIO driver for SuperH pin function controller"); | |
651 | MODULE_LICENSE("GPL v2"); |