Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 1 | /* |
Paul Gortmaker | a43647b | 2016-02-29 15:48:40 -0500 | [diff] [blame] | 2 | * Pin Control and GPIO driver for SuperH Pin Function Controller. |
| 3 | * |
| 4 | * Authors: Magnus Damm, Paul Mundt, Laurent Pinchart |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 5 | * |
| 6 | * Copyright (C) 2008 Magnus Damm |
Paul Mundt | b3c185a | 2012-06-20 17:29:04 +0900 | [diff] [blame] | 7 | * Copyright (C) 2009 - 2012 Paul Mundt |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 8 | * |
| 9 | * This file is subject to the terms and conditions of the GNU General Public |
| 10 | * License. See the file "COPYING" in the main directory of this archive |
| 11 | * for more details. |
| 12 | */ |
Laurent Pinchart | c6193ea | 2012-12-15 23:50:47 +0100 | [diff] [blame] | 13 | |
| 14 | #define DRV_NAME "sh-pfc" |
Paul Mundt | b72421d | 2010-10-04 03:54:56 +0900 | [diff] [blame] | 15 | |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 16 | #include <linux/bitops.h> |
Laurent Pinchart | 90efde2 | 2012-12-15 23:50:52 +0100 | [diff] [blame] | 17 | #include <linux/err.h> |
| 18 | #include <linux/errno.h> |
| 19 | #include <linux/io.h> |
Magnus Damm | b0e1021 | 2011-12-09 12:14:27 +0900 | [diff] [blame] | 20 | #include <linux/ioport.h> |
Laurent Pinchart | 90efde2 | 2012-12-15 23:50:52 +0100 | [diff] [blame] | 21 | #include <linux/kernel.h> |
Paul Gortmaker | a43647b | 2016-02-29 15:48:40 -0500 | [diff] [blame] | 22 | #include <linux/init.h> |
Laurent Pinchart | fe1c9a8 | 2013-06-17 20:50:02 +0200 | [diff] [blame] | 23 | #include <linux/of.h> |
| 24 | #include <linux/of_device.h> |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 25 | #include <linux/pinctrl/machine.h> |
Laurent Pinchart | c6193ea | 2012-12-15 23:50:47 +0100 | [diff] [blame] | 26 | #include <linux/platform_device.h> |
Laurent Pinchart | 90efde2 | 2012-12-15 23:50:52 +0100 | [diff] [blame] | 27 | #include <linux/slab.h> |
Magnus Damm | b0e1021 | 2011-12-09 12:14:27 +0900 | [diff] [blame] | 28 | |
Laurent Pinchart | f916513 | 2012-12-15 23:50:44 +0100 | [diff] [blame] | 29 | #include "core.h" |
| 30 | |
Laurent Pinchart | 70c8f01 | 2013-12-11 04:26:26 +0100 | [diff] [blame] | 31 | static int sh_pfc_map_resources(struct sh_pfc *pfc, |
| 32 | struct platform_device *pdev) |
Magnus Damm | b0e1021 | 2011-12-09 12:14:27 +0900 | [diff] [blame] | 33 | { |
Geert Uytterhoeven | c7977ec | 2015-06-25 11:39:53 +0200 | [diff] [blame] | 34 | unsigned int num_windows, num_irqs; |
Laurent Pinchart | 70c8f01 | 2013-12-11 04:26:26 +0100 | [diff] [blame] | 35 | struct sh_pfc_window *windows; |
| 36 | unsigned int *irqs = NULL; |
Magnus Damm | b0e1021 | 2011-12-09 12:14:27 +0900 | [diff] [blame] | 37 | struct resource *res; |
Laurent Pinchart | 70c8f01 | 2013-12-11 04:26:26 +0100 | [diff] [blame] | 38 | unsigned int i; |
Geert Uytterhoeven | c7977ec | 2015-06-25 11:39:53 +0200 | [diff] [blame] | 39 | int irq; |
Magnus Damm | b0e1021 | 2011-12-09 12:14:27 +0900 | [diff] [blame] | 40 | |
Laurent Pinchart | 70c8f01 | 2013-12-11 04:26:26 +0100 | [diff] [blame] | 41 | /* Count the MEM and IRQ resources. */ |
Geert Uytterhoeven | c7977ec | 2015-06-25 11:39:53 +0200 | [diff] [blame] | 42 | for (num_windows = 0;; num_windows++) { |
| 43 | res = platform_get_resource(pdev, IORESOURCE_MEM, num_windows); |
| 44 | if (!res) |
Laurent Pinchart | 70c8f01 | 2013-12-11 04:26:26 +0100 | [diff] [blame] | 45 | break; |
Geert Uytterhoeven | c7977ec | 2015-06-25 11:39:53 +0200 | [diff] [blame] | 46 | } |
| 47 | for (num_irqs = 0;; num_irqs++) { |
| 48 | irq = platform_get_irq(pdev, num_irqs); |
| 49 | if (irq == -EPROBE_DEFER) |
| 50 | return irq; |
| 51 | if (irq < 0) |
Laurent Pinchart | 70c8f01 | 2013-12-11 04:26:26 +0100 | [diff] [blame] | 52 | break; |
Laurent Pinchart | 70c8f01 | 2013-12-11 04:26:26 +0100 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | if (num_windows == 0) |
Laurent Pinchart | bee9f22 | 2013-02-16 23:39:07 +0100 | [diff] [blame] | 56 | return -EINVAL; |
Laurent Pinchart | 973931a | 2012-12-15 23:50:55 +0100 | [diff] [blame] | 57 | |
Laurent Pinchart | 70c8f01 | 2013-12-11 04:26:26 +0100 | [diff] [blame] | 58 | /* Allocate memory windows and IRQs arrays. */ |
| 59 | windows = devm_kzalloc(pfc->dev, num_windows * sizeof(*windows), |
| 60 | GFP_KERNEL); |
| 61 | if (windows == NULL) |
Laurent Pinchart | 1724acf | 2012-12-15 23:50:48 +0100 | [diff] [blame] | 62 | return -ENOMEM; |
Magnus Damm | b0e1021 | 2011-12-09 12:14:27 +0900 | [diff] [blame] | 63 | |
Laurent Pinchart | 70c8f01 | 2013-12-11 04:26:26 +0100 | [diff] [blame] | 64 | pfc->num_windows = num_windows; |
| 65 | pfc->windows = windows; |
Laurent Pinchart | 973931a | 2012-12-15 23:50:55 +0100 | [diff] [blame] | 66 | |
Laurent Pinchart | 70c8f01 | 2013-12-11 04:26:26 +0100 | [diff] [blame] | 67 | if (num_irqs) { |
| 68 | irqs = devm_kzalloc(pfc->dev, num_irqs * sizeof(*irqs), |
| 69 | GFP_KERNEL); |
| 70 | if (irqs == NULL) |
Laurent Pinchart | 1724acf | 2012-12-15 23:50:48 +0100 | [diff] [blame] | 71 | return -ENOMEM; |
Laurent Pinchart | 70c8f01 | 2013-12-11 04:26:26 +0100 | [diff] [blame] | 72 | |
| 73 | pfc->num_irqs = num_irqs; |
| 74 | pfc->irqs = irqs; |
| 75 | } |
| 76 | |
| 77 | /* Fill them. */ |
Geert Uytterhoeven | c7977ec | 2015-06-25 11:39:53 +0200 | [diff] [blame] | 78 | for (i = 0; i < num_windows; i++) { |
| 79 | res = platform_get_resource(pdev, IORESOURCE_MEM, i); |
| 80 | windows->phys = res->start; |
| 81 | windows->size = resource_size(res); |
| 82 | windows->virt = devm_ioremap_resource(pfc->dev, res); |
| 83 | if (IS_ERR(windows->virt)) |
| 84 | return -ENOMEM; |
| 85 | windows++; |
Magnus Damm | b0e1021 | 2011-12-09 12:14:27 +0900 | [diff] [blame] | 86 | } |
Geert Uytterhoeven | c7977ec | 2015-06-25 11:39:53 +0200 | [diff] [blame] | 87 | for (i = 0; i < num_irqs; i++) |
| 88 | *irqs++ = platform_get_irq(pdev, i); |
Magnus Damm | b0e1021 | 2011-12-09 12:14:27 +0900 | [diff] [blame] | 89 | |
| 90 | return 0; |
Magnus Damm | b0e1021 | 2011-12-09 12:14:27 +0900 | [diff] [blame] | 91 | } |
| 92 | |
Geert Uytterhoeven | 1f34de0 | 2015-03-12 11:09:16 +0100 | [diff] [blame] | 93 | static void __iomem *sh_pfc_phys_to_virt(struct sh_pfc *pfc, u32 reg) |
Magnus Damm | b0e1021 | 2011-12-09 12:14:27 +0900 | [diff] [blame] | 94 | { |
Laurent Pinchart | 4aeacd5 | 2012-12-15 23:50:53 +0100 | [diff] [blame] | 95 | struct sh_pfc_window *window; |
Geert Uytterhoeven | 1f34de0 | 2015-03-12 11:09:16 +0100 | [diff] [blame] | 96 | phys_addr_t address = reg; |
Laurent Pinchart | bee9f22 | 2013-02-16 23:39:07 +0100 | [diff] [blame] | 97 | unsigned int i; |
Magnus Damm | b0e1021 | 2011-12-09 12:14:27 +0900 | [diff] [blame] | 98 | |
| 99 | /* scan through physical windows and convert address */ |
Laurent Pinchart | bee9f22 | 2013-02-16 23:39:07 +0100 | [diff] [blame] | 100 | for (i = 0; i < pfc->num_windows; i++) { |
Laurent Pinchart | 5b46ac3 | 2013-12-11 04:26:25 +0100 | [diff] [blame] | 101 | window = pfc->windows + i; |
Magnus Damm | b0e1021 | 2011-12-09 12:14:27 +0900 | [diff] [blame] | 102 | |
| 103 | if (address < window->phys) |
| 104 | continue; |
| 105 | |
| 106 | if (address >= (window->phys + window->size)) |
| 107 | continue; |
| 108 | |
| 109 | return window->virt + (address - window->phys); |
| 110 | } |
| 111 | |
Laurent Pinchart | bee9f22 | 2013-02-16 23:39:07 +0100 | [diff] [blame] | 112 | BUG(); |
Laurent Pinchart | 1960d58 | 2013-03-26 01:44:52 +0100 | [diff] [blame] | 113 | return NULL; |
Magnus Damm | b0e1021 | 2011-12-09 12:14:27 +0900 | [diff] [blame] | 114 | } |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 115 | |
Laurent Pinchart | 1a0039d | 2013-03-08 17:43:54 +0100 | [diff] [blame] | 116 | int sh_pfc_get_pin_index(struct sh_pfc *pfc, unsigned int pin) |
Laurent Pinchart | 934cb02 | 2013-02-14 22:35:09 +0100 | [diff] [blame] | 117 | { |
Laurent Pinchart | 63d5738 | 2013-02-15 01:33:38 +0100 | [diff] [blame] | 118 | unsigned int offset; |
| 119 | unsigned int i; |
| 120 | |
Laurent Pinchart | acac8ed | 2013-07-15 18:38:30 +0200 | [diff] [blame] | 121 | for (i = 0, offset = 0; i < pfc->nr_ranges; ++i) { |
| 122 | const struct sh_pfc_pin_range *range = &pfc->ranges[i]; |
Laurent Pinchart | 63d5738 | 2013-02-15 01:33:38 +0100 | [diff] [blame] | 123 | |
| 124 | if (pin <= range->end) |
Laurent Pinchart | acac8ed | 2013-07-15 18:38:30 +0200 | [diff] [blame] | 125 | return pin >= range->start |
| 126 | ? offset + pin - range->start : -1; |
Laurent Pinchart | 63d5738 | 2013-02-15 01:33:38 +0100 | [diff] [blame] | 127 | |
Laurent Pinchart | acac8ed | 2013-07-15 18:38:30 +0200 | [diff] [blame] | 128 | offset += range->end - range->start + 1; |
Laurent Pinchart | 63d5738 | 2013-02-15 01:33:38 +0100 | [diff] [blame] | 129 | } |
| 130 | |
Laurent Pinchart | b705c05 | 2013-03-10 16:38:23 +0100 | [diff] [blame] | 131 | return -EINVAL; |
Laurent Pinchart | 934cb02 | 2013-02-14 22:35:09 +0100 | [diff] [blame] | 132 | } |
| 133 | |
Laurent Pinchart | 533743d | 2013-07-15 13:03:20 +0200 | [diff] [blame] | 134 | static int sh_pfc_enum_in_range(u16 enum_id, const struct pinmux_range *r) |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 135 | { |
| 136 | if (enum_id < r->begin) |
| 137 | return 0; |
| 138 | |
| 139 | if (enum_id > r->end) |
| 140 | return 0; |
| 141 | |
| 142 | return 1; |
| 143 | } |
| 144 | |
Geert Uytterhoeven | cef28a2 | 2015-03-12 11:09:14 +0100 | [diff] [blame] | 145 | u32 sh_pfc_read_raw_reg(void __iomem *mapped_reg, unsigned int reg_width) |
Magnus Damm | 3292094 | 2008-12-25 18:17:26 +0900 | [diff] [blame] | 146 | { |
| 147 | switch (reg_width) { |
| 148 | case 8: |
Magnus Damm | b0e1021 | 2011-12-09 12:14:27 +0900 | [diff] [blame] | 149 | return ioread8(mapped_reg); |
Magnus Damm | 3292094 | 2008-12-25 18:17:26 +0900 | [diff] [blame] | 150 | case 16: |
Magnus Damm | b0e1021 | 2011-12-09 12:14:27 +0900 | [diff] [blame] | 151 | return ioread16(mapped_reg); |
Magnus Damm | 3292094 | 2008-12-25 18:17:26 +0900 | [diff] [blame] | 152 | case 32: |
Magnus Damm | b0e1021 | 2011-12-09 12:14:27 +0900 | [diff] [blame] | 153 | return ioread32(mapped_reg); |
Magnus Damm | 3292094 | 2008-12-25 18:17:26 +0900 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | BUG(); |
| 157 | return 0; |
| 158 | } |
| 159 | |
Geert Uytterhoeven | cef28a2 | 2015-03-12 11:09:14 +0100 | [diff] [blame] | 160 | void sh_pfc_write_raw_reg(void __iomem *mapped_reg, unsigned int reg_width, |
Geert Uytterhoeven | fc88936 | 2015-02-27 18:38:04 +0100 | [diff] [blame] | 161 | u32 data) |
Magnus Damm | 3292094 | 2008-12-25 18:17:26 +0900 | [diff] [blame] | 162 | { |
| 163 | switch (reg_width) { |
| 164 | case 8: |
Magnus Damm | b0e1021 | 2011-12-09 12:14:27 +0900 | [diff] [blame] | 165 | iowrite8(data, mapped_reg); |
Magnus Damm | 3292094 | 2008-12-25 18:17:26 +0900 | [diff] [blame] | 166 | return; |
| 167 | case 16: |
Magnus Damm | b0e1021 | 2011-12-09 12:14:27 +0900 | [diff] [blame] | 168 | iowrite16(data, mapped_reg); |
Magnus Damm | 3292094 | 2008-12-25 18:17:26 +0900 | [diff] [blame] | 169 | return; |
| 170 | case 32: |
Magnus Damm | b0e1021 | 2011-12-09 12:14:27 +0900 | [diff] [blame] | 171 | iowrite32(data, mapped_reg); |
Magnus Damm | 3292094 | 2008-12-25 18:17:26 +0900 | [diff] [blame] | 172 | return; |
| 173 | } |
| 174 | |
| 175 | BUG(); |
| 176 | } |
| 177 | |
Laurent Pinchart | 3caa7d8 | 2016-03-23 16:06:00 +0200 | [diff] [blame] | 178 | u32 sh_pfc_read_reg(struct sh_pfc *pfc, u32 reg, unsigned int width) |
| 179 | { |
| 180 | return sh_pfc_read_raw_reg(sh_pfc_phys_to_virt(pfc, reg), width); |
| 181 | } |
| 182 | |
| 183 | void sh_pfc_write_reg(struct sh_pfc *pfc, u32 reg, unsigned int width, u32 data) |
| 184 | { |
| 185 | if (pfc->info->unlock_reg) |
| 186 | sh_pfc_write_raw_reg( |
| 187 | sh_pfc_phys_to_virt(pfc, pfc->info->unlock_reg), 32, |
| 188 | ~data); |
| 189 | |
| 190 | sh_pfc_write_raw_reg(sh_pfc_phys_to_virt(pfc, reg), width, data); |
| 191 | } |
| 192 | |
Laurent Pinchart | 4aeacd5 | 2012-12-15 23:50:53 +0100 | [diff] [blame] | 193 | static void sh_pfc_config_reg_helper(struct sh_pfc *pfc, |
Laurent Pinchart | cd3c1be | 2013-02-16 18:47:05 +0100 | [diff] [blame] | 194 | const struct pinmux_cfg_reg *crp, |
Geert Uytterhoeven | cef28a2 | 2015-03-12 11:09:14 +0100 | [diff] [blame] | 195 | unsigned int in_pos, |
Geert Uytterhoeven | fc88936 | 2015-02-27 18:38:04 +0100 | [diff] [blame] | 196 | void __iomem **mapped_regp, u32 *maskp, |
Geert Uytterhoeven | cef28a2 | 2015-03-12 11:09:14 +0100 | [diff] [blame] | 197 | unsigned int *posp) |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 198 | { |
Laurent Pinchart | 8d72a7f | 2013-12-11 04:26:21 +0100 | [diff] [blame] | 199 | unsigned int k; |
Magnus Damm | f78a26f | 2011-12-14 01:01:05 +0900 | [diff] [blame] | 200 | |
Laurent Pinchart | 4aeacd5 | 2012-12-15 23:50:53 +0100 | [diff] [blame] | 201 | *mapped_regp = sh_pfc_phys_to_virt(pfc, crp->reg); |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 202 | |
Magnus Damm | f78a26f | 2011-12-14 01:01:05 +0900 | [diff] [blame] | 203 | if (crp->field_width) { |
| 204 | *maskp = (1 << crp->field_width) - 1; |
| 205 | *posp = crp->reg_width - ((in_pos + 1) * crp->field_width); |
| 206 | } else { |
| 207 | *maskp = (1 << crp->var_field_width[in_pos]) - 1; |
| 208 | *posp = crp->reg_width; |
| 209 | for (k = 0; k <= in_pos; k++) |
| 210 | *posp -= crp->var_field_width[k]; |
| 211 | } |
Magnus Damm | 0fc64cc | 2008-12-25 18:17:18 +0900 | [diff] [blame] | 212 | } |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 213 | |
Laurent Pinchart | 4aeacd5 | 2012-12-15 23:50:53 +0100 | [diff] [blame] | 214 | static void sh_pfc_write_config_reg(struct sh_pfc *pfc, |
Laurent Pinchart | cd3c1be | 2013-02-16 18:47:05 +0100 | [diff] [blame] | 215 | const struct pinmux_cfg_reg *crp, |
Geert Uytterhoeven | cef28a2 | 2015-03-12 11:09:14 +0100 | [diff] [blame] | 216 | unsigned int field, u32 value) |
Magnus Damm | 18925e1 | 2011-12-14 01:00:55 +0900 | [diff] [blame] | 217 | { |
| 218 | void __iomem *mapped_reg; |
Geert Uytterhoeven | cef28a2 | 2015-03-12 11:09:14 +0100 | [diff] [blame] | 219 | unsigned int pos; |
Geert Uytterhoeven | fc88936 | 2015-02-27 18:38:04 +0100 | [diff] [blame] | 220 | u32 mask, data; |
Magnus Damm | 18925e1 | 2011-12-14 01:00:55 +0900 | [diff] [blame] | 221 | |
Laurent Pinchart | 4aeacd5 | 2012-12-15 23:50:53 +0100 | [diff] [blame] | 222 | sh_pfc_config_reg_helper(pfc, crp, field, &mapped_reg, &mask, &pos); |
Magnus Damm | 18925e1 | 2011-12-14 01:00:55 +0900 | [diff] [blame] | 223 | |
Geert Uytterhoeven | 1f34de0 | 2015-03-12 11:09:16 +0100 | [diff] [blame] | 224 | dev_dbg(pfc->dev, "write_reg addr = %x, value = 0x%x, field = %u, " |
Geert Uytterhoeven | dc70071 | 2015-03-12 11:09:13 +0100 | [diff] [blame] | 225 | "r_width = %u, f_width = %u\n", |
Laurent Pinchart | 9a643c9 | 2013-03-10 18:00:02 +0100 | [diff] [blame] | 226 | crp->reg, value, field, crp->reg_width, crp->field_width); |
Magnus Damm | 0fc64cc | 2008-12-25 18:17:18 +0900 | [diff] [blame] | 227 | |
| 228 | mask = ~(mask << pos); |
| 229 | value = value << pos; |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 230 | |
Laurent Pinchart | 4aeacd5 | 2012-12-15 23:50:53 +0100 | [diff] [blame] | 231 | data = sh_pfc_read_raw_reg(mapped_reg, crp->reg_width); |
Magnus Damm | e499ada | 2011-12-14 01:01:14 +0900 | [diff] [blame] | 232 | data &= mask; |
| 233 | data |= value; |
| 234 | |
Laurent Pinchart | 19bb7fe3 | 2012-12-15 23:51:20 +0100 | [diff] [blame] | 235 | if (pfc->info->unlock_reg) |
Laurent Pinchart | 4aeacd5 | 2012-12-15 23:50:53 +0100 | [diff] [blame] | 236 | sh_pfc_write_raw_reg( |
Laurent Pinchart | 19bb7fe3 | 2012-12-15 23:51:20 +0100 | [diff] [blame] | 237 | sh_pfc_phys_to_virt(pfc, pfc->info->unlock_reg), 32, |
Laurent Pinchart | 4aeacd5 | 2012-12-15 23:50:53 +0100 | [diff] [blame] | 238 | ~data); |
Magnus Damm | e499ada | 2011-12-14 01:01:14 +0900 | [diff] [blame] | 239 | |
Laurent Pinchart | 4aeacd5 | 2012-12-15 23:50:53 +0100 | [diff] [blame] | 240 | sh_pfc_write_raw_reg(mapped_reg, crp->reg_width, data); |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 241 | } |
| 242 | |
Laurent Pinchart | 533743d | 2013-07-15 13:03:20 +0200 | [diff] [blame] | 243 | static int sh_pfc_get_config_reg(struct sh_pfc *pfc, u16 enum_id, |
Geert Uytterhoeven | cef28a2 | 2015-03-12 11:09:14 +0100 | [diff] [blame] | 244 | const struct pinmux_cfg_reg **crp, |
| 245 | unsigned int *fieldp, u32 *valuep) |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 246 | { |
Geert Uytterhoeven | cef28a2 | 2015-03-12 11:09:14 +0100 | [diff] [blame] | 247 | unsigned int k = 0; |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 248 | |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 249 | while (1) { |
Geert Uytterhoeven | cef28a2 | 2015-03-12 11:09:14 +0100 | [diff] [blame] | 250 | const struct pinmux_cfg_reg *config_reg = |
| 251 | pfc->info->cfg_regs + k; |
| 252 | unsigned int r_width = config_reg->reg_width; |
| 253 | unsigned int f_width = config_reg->field_width; |
| 254 | unsigned int curr_width; |
| 255 | unsigned int bit_pos; |
| 256 | unsigned int pos = 0; |
| 257 | unsigned int m = 0; |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 258 | |
| 259 | if (!r_width) |
| 260 | break; |
Magnus Damm | f78a26f | 2011-12-14 01:01:05 +0900 | [diff] [blame] | 261 | |
Magnus Damm | f78a26f | 2011-12-14 01:01:05 +0900 | [diff] [blame] | 262 | for (bit_pos = 0; bit_pos < r_width; bit_pos += curr_width) { |
Geert Uytterhoeven | cef28a2 | 2015-03-12 11:09:14 +0100 | [diff] [blame] | 263 | u32 ncomb; |
| 264 | u32 n; |
| 265 | |
Magnus Damm | f78a26f | 2011-12-14 01:01:05 +0900 | [diff] [blame] | 266 | if (f_width) |
| 267 | curr_width = f_width; |
| 268 | else |
| 269 | curr_width = config_reg->var_field_width[m]; |
| 270 | |
| 271 | ncomb = 1 << curr_width; |
| 272 | for (n = 0; n < ncomb; n++) { |
| 273 | if (config_reg->enum_ids[pos + n] == enum_id) { |
| 274 | *crp = config_reg; |
| 275 | *fieldp = m; |
| 276 | *valuep = n; |
Magnus Damm | f78a26f | 2011-12-14 01:01:05 +0900 | [diff] [blame] | 277 | return 0; |
| 278 | } |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 279 | } |
Magnus Damm | f78a26f | 2011-12-14 01:01:05 +0900 | [diff] [blame] | 280 | pos += ncomb; |
| 281 | m++; |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 282 | } |
| 283 | k++; |
| 284 | } |
| 285 | |
Laurent Pinchart | b705c05 | 2013-03-10 16:38:23 +0100 | [diff] [blame] | 286 | return -EINVAL; |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 287 | } |
| 288 | |
Laurent Pinchart | 533743d | 2013-07-15 13:03:20 +0200 | [diff] [blame] | 289 | static int sh_pfc_mark_to_enum(struct sh_pfc *pfc, u16 mark, int pos, |
| 290 | u16 *enum_idp) |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 291 | { |
Geert Uytterhoeven | b8b47d6 | 2015-09-21 16:27:23 +0200 | [diff] [blame] | 292 | const u16 *data = pfc->info->pinmux_data; |
Laurent Pinchart | 8d72a7f | 2013-12-11 04:26:21 +0100 | [diff] [blame] | 293 | unsigned int k; |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 294 | |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 295 | if (pos) { |
| 296 | *enum_idp = data[pos + 1]; |
| 297 | return pos + 1; |
| 298 | } |
| 299 | |
Geert Uytterhoeven | b8b47d6 | 2015-09-21 16:27:23 +0200 | [diff] [blame] | 300 | for (k = 0; k < pfc->info->pinmux_data_size; k++) { |
Laurent Pinchart | a68fdca9 | 2013-02-14 17:36:56 +0100 | [diff] [blame] | 301 | if (data[k] == mark) { |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 302 | *enum_idp = data[k + 1]; |
| 303 | return k + 1; |
| 304 | } |
| 305 | } |
| 306 | |
Laurent Pinchart | 9a643c9 | 2013-03-10 18:00:02 +0100 | [diff] [blame] | 307 | dev_err(pfc->dev, "cannot locate data/mark enum_id for mark %d\n", |
| 308 | mark); |
Laurent Pinchart | b705c05 | 2013-03-10 16:38:23 +0100 | [diff] [blame] | 309 | return -EINVAL; |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 310 | } |
| 311 | |
Laurent Pinchart | 861601d | 2013-03-10 15:29:14 +0100 | [diff] [blame] | 312 | int sh_pfc_config_mux(struct sh_pfc *pfc, unsigned mark, int pinmux_type) |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 313 | { |
Laurent Pinchart | cd3c1be | 2013-02-16 18:47:05 +0100 | [diff] [blame] | 314 | const struct pinmux_range *range; |
Geert Uytterhoeven | cef28a2 | 2015-03-12 11:09:14 +0100 | [diff] [blame] | 315 | int pos = 0; |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 316 | |
| 317 | switch (pinmux_type) { |
Laurent Pinchart | e3c4705 | 2013-03-10 17:30:25 +0100 | [diff] [blame] | 318 | case PINMUX_TYPE_GPIO: |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 319 | case PINMUX_TYPE_FUNCTION: |
| 320 | range = NULL; |
| 321 | break; |
| 322 | |
| 323 | case PINMUX_TYPE_OUTPUT: |
Laurent Pinchart | 19bb7fe3 | 2012-12-15 23:51:20 +0100 | [diff] [blame] | 324 | range = &pfc->info->output; |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 325 | break; |
| 326 | |
| 327 | case PINMUX_TYPE_INPUT: |
Laurent Pinchart | 19bb7fe3 | 2012-12-15 23:51:20 +0100 | [diff] [blame] | 328 | range = &pfc->info->input; |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 329 | break; |
| 330 | |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 331 | default: |
Laurent Pinchart | b705c05 | 2013-03-10 16:38:23 +0100 | [diff] [blame] | 332 | return -EINVAL; |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 333 | } |
| 334 | |
Laurent Pinchart | e3c4705 | 2013-03-10 17:30:25 +0100 | [diff] [blame] | 335 | /* Iterate over all the configuration fields we need to update. */ |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 336 | while (1) { |
Geert Uytterhoeven | cef28a2 | 2015-03-12 11:09:14 +0100 | [diff] [blame] | 337 | const struct pinmux_cfg_reg *cr; |
| 338 | unsigned int field; |
| 339 | u16 enum_id; |
| 340 | u32 value; |
| 341 | int in_range; |
| 342 | int ret; |
| 343 | |
Laurent Pinchart | a68fdca9 | 2013-02-14 17:36:56 +0100 | [diff] [blame] | 344 | pos = sh_pfc_mark_to_enum(pfc, mark, pos, &enum_id); |
Laurent Pinchart | b705c05 | 2013-03-10 16:38:23 +0100 | [diff] [blame] | 345 | if (pos < 0) |
| 346 | return pos; |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 347 | |
| 348 | if (!enum_id) |
| 349 | break; |
| 350 | |
Laurent Pinchart | e3c4705 | 2013-03-10 17:30:25 +0100 | [diff] [blame] | 351 | /* Check if the configuration field selects a function. If it |
| 352 | * doesn't, skip the field if it's not applicable to the |
| 353 | * requested pinmux type. |
| 354 | */ |
Laurent Pinchart | 19bb7fe3 | 2012-12-15 23:51:20 +0100 | [diff] [blame] | 355 | in_range = sh_pfc_enum_in_range(enum_id, &pfc->info->function); |
Magnus Damm | 50dd314 | 2010-01-19 13:52:28 +0000 | [diff] [blame] | 356 | if (!in_range) { |
Laurent Pinchart | e3c4705 | 2013-03-10 17:30:25 +0100 | [diff] [blame] | 357 | if (pinmux_type == PINMUX_TYPE_FUNCTION) { |
| 358 | /* Functions are allowed to modify all |
| 359 | * fields. |
| 360 | */ |
| 361 | in_range = 1; |
| 362 | } else if (pinmux_type != PINMUX_TYPE_GPIO) { |
| 363 | /* Input/output types can only modify fields |
| 364 | * that correspond to their respective ranges. |
Magnus Damm | 50dd314 | 2010-01-19 13:52:28 +0000 | [diff] [blame] | 365 | */ |
Laurent Pinchart | 4aeacd5 | 2012-12-15 23:50:53 +0100 | [diff] [blame] | 366 | in_range = sh_pfc_enum_in_range(enum_id, range); |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 367 | |
Magnus Damm | 50dd314 | 2010-01-19 13:52:28 +0000 | [diff] [blame] | 368 | /* |
| 369 | * special case pass through for fixed |
| 370 | * input-only or output-only pins without |
| 371 | * function enum register association. |
| 372 | */ |
| 373 | if (in_range && enum_id == range->force) |
| 374 | continue; |
Magnus Damm | 50dd314 | 2010-01-19 13:52:28 +0000 | [diff] [blame] | 375 | } |
Laurent Pinchart | e3c4705 | 2013-03-10 17:30:25 +0100 | [diff] [blame] | 376 | /* GPIOs are only allowed to modify function fields. */ |
Magnus Damm | 42eed42 | 2008-10-22 18:29:17 +0900 | [diff] [blame] | 377 | } |
| 378 | |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 379 | if (!in_range) |
| 380 | continue; |
| 381 | |
Laurent Pinchart | b705c05 | 2013-03-10 16:38:23 +0100 | [diff] [blame] | 382 | ret = sh_pfc_get_config_reg(pfc, enum_id, &cr, &field, &value); |
| 383 | if (ret < 0) |
| 384 | return ret; |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 385 | |
Laurent Pinchart | 861601d | 2013-03-10 15:29:14 +0100 | [diff] [blame] | 386 | sh_pfc_write_config_reg(pfc, cr, field, value); |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | return 0; |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 390 | } |
| 391 | |
Laurent Pinchart | acac8ed | 2013-07-15 18:38:30 +0200 | [diff] [blame] | 392 | static int sh_pfc_init_ranges(struct sh_pfc *pfc) |
| 393 | { |
| 394 | struct sh_pfc_pin_range *range; |
| 395 | unsigned int nr_ranges; |
| 396 | unsigned int i; |
| 397 | |
| 398 | if (pfc->info->pins[0].pin == (u16)-1) { |
| 399 | /* Pin number -1 denotes that the SoC doesn't report pin numbers |
| 400 | * in its pin arrays yet. Consider the pin numbers range as |
| 401 | * continuous and allocate a single range. |
| 402 | */ |
| 403 | pfc->nr_ranges = 1; |
| 404 | pfc->ranges = devm_kzalloc(pfc->dev, sizeof(*pfc->ranges), |
| 405 | GFP_KERNEL); |
| 406 | if (pfc->ranges == NULL) |
| 407 | return -ENOMEM; |
| 408 | |
| 409 | pfc->ranges->start = 0; |
| 410 | pfc->ranges->end = pfc->info->nr_pins - 1; |
| 411 | pfc->nr_gpio_pins = pfc->info->nr_pins; |
| 412 | |
| 413 | return 0; |
| 414 | } |
| 415 | |
Laurent Pinchart | 4f82e3e | 2013-07-15 21:10:54 +0200 | [diff] [blame] | 416 | /* Count, allocate and fill the ranges. The PFC SoC data pins array must |
| 417 | * be sorted by pin numbers, and pins without a GPIO port must come |
| 418 | * last. |
| 419 | */ |
Laurent Pinchart | acac8ed | 2013-07-15 18:38:30 +0200 | [diff] [blame] | 420 | for (i = 1, nr_ranges = 1; i < pfc->info->nr_pins; ++i) { |
| 421 | if (pfc->info->pins[i-1].pin != pfc->info->pins[i].pin - 1) |
| 422 | nr_ranges++; |
| 423 | } |
| 424 | |
| 425 | pfc->nr_ranges = nr_ranges; |
| 426 | pfc->ranges = devm_kzalloc(pfc->dev, sizeof(*pfc->ranges) * nr_ranges, |
| 427 | GFP_KERNEL); |
| 428 | if (pfc->ranges == NULL) |
| 429 | return -ENOMEM; |
| 430 | |
| 431 | range = pfc->ranges; |
| 432 | range->start = pfc->info->pins[0].pin; |
| 433 | |
| 434 | for (i = 1; i < pfc->info->nr_pins; ++i) { |
Laurent Pinchart | 4f82e3e | 2013-07-15 21:10:54 +0200 | [diff] [blame] | 435 | if (pfc->info->pins[i-1].pin == pfc->info->pins[i].pin - 1) |
| 436 | continue; |
| 437 | |
| 438 | range->end = pfc->info->pins[i-1].pin; |
| 439 | if (!(pfc->info->pins[i-1].configs & SH_PFC_PIN_CFG_NO_GPIO)) |
| 440 | pfc->nr_gpio_pins = range->end + 1; |
| 441 | |
| 442 | range++; |
| 443 | range->start = pfc->info->pins[i].pin; |
Laurent Pinchart | acac8ed | 2013-07-15 18:38:30 +0200 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | range->end = pfc->info->pins[i-1].pin; |
Laurent Pinchart | 4f82e3e | 2013-07-15 21:10:54 +0200 | [diff] [blame] | 447 | if (!(pfc->info->pins[i-1].configs & SH_PFC_PIN_CFG_NO_GPIO)) |
| 448 | pfc->nr_gpio_pins = range->end + 1; |
Laurent Pinchart | acac8ed | 2013-07-15 18:38:30 +0200 | [diff] [blame] | 449 | |
| 450 | return 0; |
| 451 | } |
| 452 | |
Laurent Pinchart | fe1c9a8 | 2013-06-17 20:50:02 +0200 | [diff] [blame] | 453 | #ifdef CONFIG_OF |
| 454 | static const struct of_device_id sh_pfc_of_table[] = { |
Niklas Söderlund | 1e7d5d8 | 2015-01-25 14:49:52 +0100 | [diff] [blame] | 455 | #ifdef CONFIG_PINCTRL_PFC_EMEV2 |
| 456 | { |
| 457 | .compatible = "renesas,pfc-emev2", |
| 458 | .data = &emev2_pinmux_info, |
| 459 | }, |
| 460 | #endif |
Laurent Pinchart | fe1c9a8 | 2013-06-17 20:50:02 +0200 | [diff] [blame] | 461 | #ifdef CONFIG_PINCTRL_PFC_R8A73A4 |
| 462 | { |
| 463 | .compatible = "renesas,pfc-r8a73a4", |
| 464 | .data = &r8a73a4_pinmux_info, |
| 465 | }, |
| 466 | #endif |
| 467 | #ifdef CONFIG_PINCTRL_PFC_R8A7740 |
| 468 | { |
| 469 | .compatible = "renesas,pfc-r8a7740", |
| 470 | .data = &r8a7740_pinmux_info, |
| 471 | }, |
| 472 | #endif |
| 473 | #ifdef CONFIG_PINCTRL_PFC_R8A7778 |
| 474 | { |
| 475 | .compatible = "renesas,pfc-r8a7778", |
| 476 | .data = &r8a7778_pinmux_info, |
| 477 | }, |
| 478 | #endif |
| 479 | #ifdef CONFIG_PINCTRL_PFC_R8A7779 |
| 480 | { |
| 481 | .compatible = "renesas,pfc-r8a7779", |
| 482 | .data = &r8a7779_pinmux_info, |
| 483 | }, |
| 484 | #endif |
| 485 | #ifdef CONFIG_PINCTRL_PFC_R8A7790 |
| 486 | { |
| 487 | .compatible = "renesas,pfc-r8a7790", |
| 488 | .data = &r8a7790_pinmux_info, |
| 489 | }, |
| 490 | #endif |
Hisashi Nakamura | 5088451 | 2013-10-17 06:46:05 +0900 | [diff] [blame] | 491 | #ifdef CONFIG_PINCTRL_PFC_R8A7791 |
| 492 | { |
| 493 | .compatible = "renesas,pfc-r8a7791", |
| 494 | .data = &r8a7791_pinmux_info, |
| 495 | }, |
| 496 | #endif |
Sergei Shtylyov | 2cf59e0 | 2016-06-30 00:21:08 +0300 | [diff] [blame] | 497 | #ifdef CONFIG_PINCTRL_PFC_R8A7792 |
| 498 | { |
| 499 | .compatible = "renesas,pfc-r8a7792", |
| 500 | .data = &r8a7792_pinmux_info, |
| 501 | }, |
| 502 | #endif |
Ulrich Hecht | 19e1e98 | 2015-05-12 11:13:19 +0200 | [diff] [blame] | 503 | #ifdef CONFIG_PINCTRL_PFC_R8A7793 |
| 504 | { |
| 505 | .compatible = "renesas,pfc-r8a7793", |
| 506 | .data = &r8a7793_pinmux_info, |
| 507 | }, |
| 508 | #endif |
Hisashi Nakamura | 43c4436 | 2015-06-06 01:34:48 +0300 | [diff] [blame] | 509 | #ifdef CONFIG_PINCTRL_PFC_R8A7794 |
| 510 | { |
| 511 | .compatible = "renesas,pfc-r8a7794", |
| 512 | .data = &r8a7794_pinmux_info, |
| 513 | }, |
| 514 | #endif |
Takeshi Kihara | 0b0ffc9 | 2015-09-03 02:51:49 +0000 | [diff] [blame] | 515 | #ifdef CONFIG_PINCTRL_PFC_R8A7795 |
| 516 | { |
| 517 | .compatible = "renesas,pfc-r8a7795", |
| 518 | .data = &r8a7795_pinmux_info, |
| 519 | }, |
| 520 | #endif |
Takeshi Kihara | f9aece7 | 2016-08-18 15:12:32 +0200 | [diff] [blame] | 521 | #ifdef CONFIG_PINCTRL_PFC_R8A7796 |
| 522 | { |
| 523 | .compatible = "renesas,pfc-r8a7796", |
| 524 | .data = &r8a7796_pinmux_info, |
| 525 | }, |
| 526 | #endif |
Laurent Pinchart | fe1c9a8 | 2013-06-17 20:50:02 +0200 | [diff] [blame] | 527 | #ifdef CONFIG_PINCTRL_PFC_SH73A0 |
| 528 | { |
| 529 | .compatible = "renesas,pfc-sh73a0", |
| 530 | .data = &sh73a0_pinmux_info, |
| 531 | }, |
| 532 | #endif |
| 533 | { }, |
| 534 | }; |
Laurent Pinchart | fe1c9a8 | 2013-06-17 20:50:02 +0200 | [diff] [blame] | 535 | #endif |
| 536 | |
Laurent Pinchart | c6193ea | 2012-12-15 23:50:47 +0100 | [diff] [blame] | 537 | static int sh_pfc_probe(struct platform_device *pdev) |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 538 | { |
Laurent Pinchart | fe1c9a8 | 2013-06-17 20:50:02 +0200 | [diff] [blame] | 539 | const struct platform_device_id *platid = platform_get_device_id(pdev); |
| 540 | #ifdef CONFIG_OF |
| 541 | struct device_node *np = pdev->dev.of_node; |
| 542 | #endif |
Laurent Pinchart | cd3c1be | 2013-02-16 18:47:05 +0100 | [diff] [blame] | 543 | const struct sh_pfc_soc_info *info; |
Laurent Pinchart | c6193ea | 2012-12-15 23:50:47 +0100 | [diff] [blame] | 544 | struct sh_pfc *pfc; |
Magnus Damm | 0fc64cc | 2008-12-25 18:17:18 +0900 | [diff] [blame] | 545 | int ret; |
Magnus Damm | 2967dab | 2008-10-08 20:41:43 +0900 | [diff] [blame] | 546 | |
Laurent Pinchart | fe1c9a8 | 2013-06-17 20:50:02 +0200 | [diff] [blame] | 547 | #ifdef CONFIG_OF |
| 548 | if (np) |
Wolfram Sang | 331207a | 2016-03-01 17:38:46 +0100 | [diff] [blame] | 549 | info = of_device_get_match_data(&pdev->dev); |
Laurent Pinchart | fe1c9a8 | 2013-06-17 20:50:02 +0200 | [diff] [blame] | 550 | else |
| 551 | #endif |
| 552 | info = platid ? (const void *)platid->driver_data : NULL; |
| 553 | |
Laurent Pinchart | 19bb7fe3 | 2012-12-15 23:51:20 +0100 | [diff] [blame] | 554 | if (info == NULL) |
Laurent Pinchart | c6193ea | 2012-12-15 23:50:47 +0100 | [diff] [blame] | 555 | return -ENODEV; |
Magnus Damm | 0fc64cc | 2008-12-25 18:17:18 +0900 | [diff] [blame] | 556 | |
Magnus Damm | 8c43fcc | 2013-02-14 21:23:47 +0900 | [diff] [blame] | 557 | pfc = devm_kzalloc(&pdev->dev, sizeof(*pfc), GFP_KERNEL); |
Laurent Pinchart | c6193ea | 2012-12-15 23:50:47 +0100 | [diff] [blame] | 558 | if (pfc == NULL) |
| 559 | return -ENOMEM; |
Magnus Damm | b0e1021 | 2011-12-09 12:14:27 +0900 | [diff] [blame] | 560 | |
Laurent Pinchart | 19bb7fe3 | 2012-12-15 23:51:20 +0100 | [diff] [blame] | 561 | pfc->info = info; |
Laurent Pinchart | c6193ea | 2012-12-15 23:50:47 +0100 | [diff] [blame] | 562 | pfc->dev = &pdev->dev; |
| 563 | |
Laurent Pinchart | 70c8f01 | 2013-12-11 04:26:26 +0100 | [diff] [blame] | 564 | ret = sh_pfc_map_resources(pfc, pdev); |
Laurent Pinchart | c6193ea | 2012-12-15 23:50:47 +0100 | [diff] [blame] | 565 | if (unlikely(ret < 0)) |
Laurent Pinchart | d4e62d0 | 2012-12-15 23:50:43 +0100 | [diff] [blame] | 566 | return ret; |
Laurent Pinchart | d4e62d0 | 2012-12-15 23:50:43 +0100 | [diff] [blame] | 567 | |
Laurent Pinchart | c6193ea | 2012-12-15 23:50:47 +0100 | [diff] [blame] | 568 | spin_lock_init(&pfc->lock); |
Magnus Damm | 69edbba | 2008-12-25 18:17:34 +0900 | [diff] [blame] | 569 | |
Laurent Pinchart | 0c15106 | 2013-04-21 20:21:57 +0200 | [diff] [blame] | 570 | if (info->ops && info->ops->init) { |
| 571 | ret = info->ops->init(pfc); |
| 572 | if (ret < 0) |
| 573 | return ret; |
| 574 | } |
| 575 | |
Wolfram Sang | 0129801 | 2016-03-07 19:40:57 +0100 | [diff] [blame] | 576 | /* Enable dummy states for those platforms without pinctrl support */ |
| 577 | if (!of_have_populated_dt()) |
| 578 | pinctrl_provide_dummies(); |
Magnus Damm | 69edbba | 2008-12-25 18:17:34 +0900 | [diff] [blame] | 579 | |
Laurent Pinchart | acac8ed | 2013-07-15 18:38:30 +0200 | [diff] [blame] | 580 | ret = sh_pfc_init_ranges(pfc); |
| 581 | if (ret < 0) |
| 582 | return ret; |
| 583 | |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 584 | /* |
| 585 | * Initialize pinctrl bindings first |
| 586 | */ |
Laurent Pinchart | c6193ea | 2012-12-15 23:50:47 +0100 | [diff] [blame] | 587 | ret = sh_pfc_register_pinctrl(pfc); |
Laurent Pinchart | f9492fd | 2012-12-15 23:50:45 +0100 | [diff] [blame] | 588 | if (unlikely(ret != 0)) |
Laurent Pinchart | 0a332c9 | 2014-09-11 00:55:55 +0300 | [diff] [blame] | 589 | return ret; |
Magnus Damm | 69edbba | 2008-12-25 18:17:34 +0900 | [diff] [blame] | 590 | |
Magnus Damm | abc60d4 | 2016-02-17 17:15:49 +0900 | [diff] [blame] | 591 | #ifdef CONFIG_PINCTRL_SH_PFC_GPIO |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 592 | /* |
| 593 | * Then the GPIO chip |
| 594 | */ |
Laurent Pinchart | c6193ea | 2012-12-15 23:50:47 +0100 | [diff] [blame] | 595 | ret = sh_pfc_register_gpiochip(pfc); |
Laurent Pinchart | 6f6a4a6 | 2012-12-15 23:50:46 +0100 | [diff] [blame] | 596 | if (unlikely(ret != 0)) { |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 597 | /* |
| 598 | * If the GPIO chip fails to come up we still leave the |
| 599 | * PFC state as it is, given that there are already |
| 600 | * extant users of it that have succeeded by this point. |
| 601 | */ |
Laurent Pinchart | 9a643c9 | 2013-03-10 18:00:02 +0100 | [diff] [blame] | 602 | dev_notice(pfc->dev, "failed to init GPIO chip, ignoring...\n"); |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 603 | } |
Laurent Pinchart | 6f6a4a6 | 2012-12-15 23:50:46 +0100 | [diff] [blame] | 604 | #endif |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 605 | |
Laurent Pinchart | c6193ea | 2012-12-15 23:50:47 +0100 | [diff] [blame] | 606 | platform_set_drvdata(pdev, pfc); |
| 607 | |
Laurent Pinchart | 9a643c9 | 2013-03-10 18:00:02 +0100 | [diff] [blame] | 608 | dev_info(pfc->dev, "%s support registered\n", info->name); |
Paul Mundt | ca5481c6 | 2012-07-10 12:08:14 +0900 | [diff] [blame] | 609 | |
Paul Mundt | b3c185a | 2012-06-20 17:29:04 +0900 | [diff] [blame] | 610 | return 0; |
Paul Mundt | b72421d | 2010-10-04 03:54:56 +0900 | [diff] [blame] | 611 | } |
Laurent Pinchart | 6f6a4a6 | 2012-12-15 23:50:46 +0100 | [diff] [blame] | 612 | |
Laurent Pinchart | c6193ea | 2012-12-15 23:50:47 +0100 | [diff] [blame] | 613 | static const struct platform_device_id sh_pfc_id_table[] = { |
Laurent Pinchart | ccda552 | 2012-12-15 23:51:29 +0100 | [diff] [blame] | 614 | #ifdef CONFIG_PINCTRL_PFC_SH7203 |
| 615 | { "pfc-sh7203", (kernel_ulong_t)&sh7203_pinmux_info }, |
| 616 | #endif |
Laurent Pinchart | a8d42fc | 2012-12-15 23:51:30 +0100 | [diff] [blame] | 617 | #ifdef CONFIG_PINCTRL_PFC_SH7264 |
| 618 | { "pfc-sh7264", (kernel_ulong_t)&sh7264_pinmux_info }, |
| 619 | #endif |
Laurent Pinchart | f5e811f | 2012-12-15 23:51:31 +0100 | [diff] [blame] | 620 | #ifdef CONFIG_PINCTRL_PFC_SH7269 |
| 621 | { "pfc-sh7269", (kernel_ulong_t)&sh7269_pinmux_info }, |
| 622 | #endif |
Laurent Pinchart | 74cad60 | 2012-12-15 23:51:32 +0100 | [diff] [blame] | 623 | #ifdef CONFIG_PINCTRL_PFC_SH7720 |
| 624 | { "pfc-sh7720", (kernel_ulong_t)&sh7720_pinmux_info }, |
| 625 | #endif |
Laurent Pinchart | f5e25ae | 2012-12-15 23:51:33 +0100 | [diff] [blame] | 626 | #ifdef CONFIG_PINCTRL_PFC_SH7722 |
| 627 | { "pfc-sh7722", (kernel_ulong_t)&sh7722_pinmux_info }, |
| 628 | #endif |
Laurent Pinchart | d05afa0 | 2012-12-15 23:51:34 +0100 | [diff] [blame] | 629 | #ifdef CONFIG_PINCTRL_PFC_SH7723 |
| 630 | { "pfc-sh7723", (kernel_ulong_t)&sh7723_pinmux_info }, |
| 631 | #endif |
Laurent Pinchart | 0ff25ba | 2012-12-15 23:51:35 +0100 | [diff] [blame] | 632 | #ifdef CONFIG_PINCTRL_PFC_SH7724 |
| 633 | { "pfc-sh7724", (kernel_ulong_t)&sh7724_pinmux_info }, |
| 634 | #endif |
Laurent Pinchart | ac1ebc2 | 2012-12-15 23:51:36 +0100 | [diff] [blame] | 635 | #ifdef CONFIG_PINCTRL_PFC_SH7734 |
| 636 | { "pfc-sh7734", (kernel_ulong_t)&sh7734_pinmux_info }, |
| 637 | #endif |
Laurent Pinchart | 0bb9267 | 2012-12-15 23:51:37 +0100 | [diff] [blame] | 638 | #ifdef CONFIG_PINCTRL_PFC_SH7757 |
| 639 | { "pfc-sh7757", (kernel_ulong_t)&sh7757_pinmux_info }, |
| 640 | #endif |
Laurent Pinchart | a56398e | 2012-12-15 23:51:38 +0100 | [diff] [blame] | 641 | #ifdef CONFIG_PINCTRL_PFC_SH7785 |
| 642 | { "pfc-sh7785", (kernel_ulong_t)&sh7785_pinmux_info }, |
| 643 | #endif |
Laurent Pinchart | d2a31bd | 2012-12-15 23:51:39 +0100 | [diff] [blame] | 644 | #ifdef CONFIG_PINCTRL_PFC_SH7786 |
| 645 | { "pfc-sh7786", (kernel_ulong_t)&sh7786_pinmux_info }, |
| 646 | #endif |
Laurent Pinchart | d5d9a81 | 2012-12-15 23:51:40 +0100 | [diff] [blame] | 647 | #ifdef CONFIG_PINCTRL_PFC_SHX3 |
| 648 | { "pfc-shx3", (kernel_ulong_t)&shx3_pinmux_info }, |
| 649 | #endif |
Laurent Pinchart | c6193ea | 2012-12-15 23:50:47 +0100 | [diff] [blame] | 650 | { "sh-pfc", 0 }, |
| 651 | { }, |
| 652 | }; |
Laurent Pinchart | c6193ea | 2012-12-15 23:50:47 +0100 | [diff] [blame] | 653 | |
| 654 | static struct platform_driver sh_pfc_driver = { |
| 655 | .probe = sh_pfc_probe, |
Laurent Pinchart | c6193ea | 2012-12-15 23:50:47 +0100 | [diff] [blame] | 656 | .id_table = sh_pfc_id_table, |
| 657 | .driver = { |
| 658 | .name = DRV_NAME, |
Laurent Pinchart | fe1c9a8 | 2013-06-17 20:50:02 +0200 | [diff] [blame] | 659 | .of_match_table = of_match_ptr(sh_pfc_of_table), |
Laurent Pinchart | c6193ea | 2012-12-15 23:50:47 +0100 | [diff] [blame] | 660 | }, |
| 661 | }; |
| 662 | |
Laurent Pinchart | 40ee6fc | 2012-12-15 23:50:54 +0100 | [diff] [blame] | 663 | static int __init sh_pfc_init(void) |
| 664 | { |
| 665 | return platform_driver_register(&sh_pfc_driver); |
| 666 | } |
| 667 | postcore_initcall(sh_pfc_init); |