Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Generic device tree based pinctrl driver for one register per pin |
| 3 | * type pinmux controllers |
| 4 | * |
| 5 | * Copyright (C) 2012 Texas Instruments, Inc. |
| 6 | * |
| 7 | * This file is licensed under the terms of the GNU General Public |
| 8 | * License version 2. This program is licensed "as is" without any |
| 9 | * warranty of any kind, whether express or implied. |
| 10 | */ |
| 11 | |
| 12 | #include <linux/init.h> |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/io.h> |
| 15 | #include <linux/slab.h> |
| 16 | #include <linux/err.h> |
| 17 | #include <linux/list.h> |
Tony Lindgren | 3e6cee1 | 2013-10-02 21:39:40 -0700 | [diff] [blame] | 18 | #include <linux/interrupt.h> |
| 19 | |
| 20 | #include <linux/irqchip/chained_irq.h> |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 21 | |
| 22 | #include <linux/of.h> |
| 23 | #include <linux/of_device.h> |
| 24 | #include <linux/of_address.h> |
Tony Lindgren | 3e6cee1 | 2013-10-02 21:39:40 -0700 | [diff] [blame] | 25 | #include <linux/of_irq.h> |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 26 | |
| 27 | #include <linux/pinctrl/pinctrl.h> |
| 28 | #include <linux/pinctrl/pinmux.h> |
Haojian Zhuang | 9dddb4d | 2013-02-17 19:42:55 +0800 | [diff] [blame] | 29 | #include <linux/pinctrl/pinconf-generic.h> |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 30 | |
Tony Lindgren | dc7743a | 2013-10-02 21:39:40 -0700 | [diff] [blame] | 31 | #include <linux/platform_data/pinctrl-single.h> |
| 32 | |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 33 | #include "core.h" |
Tony Lindgren | 4622215 | 2016-11-03 09:35:48 -0700 | [diff] [blame] | 34 | #include "devicetree.h" |
Haojian Zhuang | 9dddb4d | 2013-02-17 19:42:55 +0800 | [diff] [blame] | 35 | #include "pinconf.h" |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 36 | |
| 37 | #define DRIVER_NAME "pinctrl-single" |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 38 | #define PCS_OFF_DISABLED ~0U |
| 39 | |
| 40 | /** |
| 41 | * struct pcs_pingroup - pingroups for a function |
| 42 | * @np: pingroup device node pointer |
| 43 | * @name: pingroup name |
| 44 | * @gpins: array of the pins in the group |
| 45 | * @ngpins: number of pins in the group |
| 46 | * @node: list node |
| 47 | */ |
| 48 | struct pcs_pingroup { |
| 49 | struct device_node *np; |
| 50 | const char *name; |
| 51 | int *gpins; |
| 52 | int ngpins; |
| 53 | struct list_head node; |
| 54 | }; |
| 55 | |
| 56 | /** |
| 57 | * struct pcs_func_vals - mux function register offset and value pair |
| 58 | * @reg: register virtual address |
| 59 | * @val: register value |
| 60 | */ |
| 61 | struct pcs_func_vals { |
| 62 | void __iomem *reg; |
| 63 | unsigned val; |
Peter Ujfalusi | 9e605cb | 2012-09-11 11:54:24 +0300 | [diff] [blame] | 64 | unsigned mask; |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | /** |
Haojian Zhuang | 9dddb4d | 2013-02-17 19:42:55 +0800 | [diff] [blame] | 68 | * struct pcs_conf_vals - pinconf parameter, pinconf register offset |
| 69 | * and value, enable, disable, mask |
| 70 | * @param: config parameter |
| 71 | * @val: user input bits in the pinconf register |
| 72 | * @enable: enable bits in the pinconf register |
| 73 | * @disable: disable bits in the pinconf register |
| 74 | * @mask: mask bits in the register value |
| 75 | */ |
| 76 | struct pcs_conf_vals { |
| 77 | enum pin_config_param param; |
| 78 | unsigned val; |
| 79 | unsigned enable; |
| 80 | unsigned disable; |
| 81 | unsigned mask; |
| 82 | }; |
| 83 | |
| 84 | /** |
| 85 | * struct pcs_conf_type - pinconf property name, pinconf param pair |
| 86 | * @name: property name in DTS file |
| 87 | * @param: config parameter |
| 88 | */ |
| 89 | struct pcs_conf_type { |
| 90 | const char *name; |
| 91 | enum pin_config_param param; |
| 92 | }; |
| 93 | |
| 94 | /** |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 95 | * struct pcs_function - pinctrl function |
| 96 | * @name: pinctrl function name |
| 97 | * @vals: register and vals array |
| 98 | * @nvals: number of entries in vals array |
| 99 | * @pgnames: array of pingroup names the function uses |
| 100 | * @npgnames: number of pingroup names the function uses |
| 101 | * @node: list node |
| 102 | */ |
| 103 | struct pcs_function { |
| 104 | const char *name; |
| 105 | struct pcs_func_vals *vals; |
| 106 | unsigned nvals; |
| 107 | const char **pgnames; |
| 108 | int npgnames; |
Haojian Zhuang | 9dddb4d | 2013-02-17 19:42:55 +0800 | [diff] [blame] | 109 | struct pcs_conf_vals *conf; |
| 110 | int nconfs; |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 111 | struct list_head node; |
| 112 | }; |
| 113 | |
| 114 | /** |
Haojian Zhuang | a1a277e | 2013-02-17 19:42:52 +0800 | [diff] [blame] | 115 | * struct pcs_gpiofunc_range - pin ranges with same mux value of gpio function |
| 116 | * @offset: offset base of pins |
| 117 | * @npins: number pins with the same mux value of gpio function |
| 118 | * @gpiofunc: mux value of gpio function |
| 119 | * @node: list node |
| 120 | */ |
| 121 | struct pcs_gpiofunc_range { |
| 122 | unsigned offset; |
| 123 | unsigned npins; |
| 124 | unsigned gpiofunc; |
| 125 | struct list_head node; |
| 126 | }; |
| 127 | |
| 128 | /** |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 129 | * struct pcs_data - wrapper for data needed by pinctrl framework |
| 130 | * @pa: pindesc array |
| 131 | * @cur: index to current element |
| 132 | * |
| 133 | * REVISIT: We should be able to drop this eventually by adding |
| 134 | * support for registering pins individually in the pinctrl |
| 135 | * framework for those drivers that don't need a static array. |
| 136 | */ |
| 137 | struct pcs_data { |
| 138 | struct pinctrl_pin_desc *pa; |
| 139 | int cur; |
| 140 | }; |
| 141 | |
| 142 | /** |
Tony Lindgren | 02e483f | 2013-10-02 21:39:39 -0700 | [diff] [blame] | 143 | * struct pcs_soc_data - SoC specific settings |
| 144 | * @flags: initial SoC specific PCS_FEAT_xxx values |
Tony Lindgren | 3e6cee1 | 2013-10-02 21:39:40 -0700 | [diff] [blame] | 145 | * @irq: optional interrupt for the controller |
| 146 | * @irq_enable_mask: optional SoC specific interrupt enable mask |
| 147 | * @irq_status_mask: optional SoC specific interrupt status mask |
Tony Lindgren | dc7743a | 2013-10-02 21:39:40 -0700 | [diff] [blame] | 148 | * @rearm: optional SoC specific wake-up rearm function |
Tony Lindgren | 02e483f | 2013-10-02 21:39:39 -0700 | [diff] [blame] | 149 | */ |
| 150 | struct pcs_soc_data { |
| 151 | unsigned flags; |
Tony Lindgren | 3e6cee1 | 2013-10-02 21:39:40 -0700 | [diff] [blame] | 152 | int irq; |
| 153 | unsigned irq_enable_mask; |
| 154 | unsigned irq_status_mask; |
Tony Lindgren | dc7743a | 2013-10-02 21:39:40 -0700 | [diff] [blame] | 155 | void (*rearm)(void); |
Tony Lindgren | 02e483f | 2013-10-02 21:39:39 -0700 | [diff] [blame] | 156 | }; |
| 157 | |
| 158 | /** |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 159 | * struct pcs_device - pinctrl device instance |
| 160 | * @res: resources |
| 161 | * @base: virtual address of the controller |
| 162 | * @size: size of the ioremapped area |
| 163 | * @dev: device entry |
Tony Lindgren | 4622215 | 2016-11-03 09:35:48 -0700 | [diff] [blame] | 164 | * @np: device tree node |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 165 | * @pctl: pin controller device |
Tony Lindgren | 02e483f | 2013-10-02 21:39:39 -0700 | [diff] [blame] | 166 | * @flags: mask of PCS_FEAT_xxx values |
Tony Lindgren | 4622215 | 2016-11-03 09:35:48 -0700 | [diff] [blame] | 167 | * @missing_nr_pinctrl_cells: for legacy binding, may go away |
| 168 | * @socdata: soc specific data |
Tony Lindgren | 3e6cee1 | 2013-10-02 21:39:40 -0700 | [diff] [blame] | 169 | * @lock: spinlock for register access |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 170 | * @mutex: mutex protecting the lists |
| 171 | * @width: bits per mux register |
| 172 | * @fmask: function register mask |
| 173 | * @fshift: function register shift |
| 174 | * @foff: value to turn mux off |
| 175 | * @fmax: max number of functions in fmask |
Tony Lindgren | 4622215 | 2016-11-03 09:35:48 -0700 | [diff] [blame] | 176 | * @bits_per_mux: number of bits per mux |
| 177 | * @bits_per_pin: number of bits per pin |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 178 | * @pins: physical pins on the SoC |
| 179 | * @pgtree: pingroup index radix tree |
| 180 | * @ftree: function index radix tree |
| 181 | * @pingroups: list of pingroups |
| 182 | * @functions: list of functions |
Haojian Zhuang | a1a277e | 2013-02-17 19:42:52 +0800 | [diff] [blame] | 183 | * @gpiofuncs: list of gpio functions |
Tony Lindgren | 3e6cee1 | 2013-10-02 21:39:40 -0700 | [diff] [blame] | 184 | * @irqs: list of interrupt registers |
| 185 | * @chip: chip container for this instance |
| 186 | * @domain: IRQ domain for this instance |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 187 | * @ngroups: number of pingroups |
| 188 | * @nfuncs: number of functions |
| 189 | * @desc: pin controller descriptor |
| 190 | * @read: register read function to use |
| 191 | * @write: register write function to use |
| 192 | */ |
| 193 | struct pcs_device { |
| 194 | struct resource *res; |
| 195 | void __iomem *base; |
| 196 | unsigned size; |
| 197 | struct device *dev; |
Tony Lindgren | 4622215 | 2016-11-03 09:35:48 -0700 | [diff] [blame] | 198 | struct device_node *np; |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 199 | struct pinctrl_dev *pctl; |
Tony Lindgren | 02e483f | 2013-10-02 21:39:39 -0700 | [diff] [blame] | 200 | unsigned flags; |
Tony Lindgren | 3e6cee1 | 2013-10-02 21:39:40 -0700 | [diff] [blame] | 201 | #define PCS_QUIRK_SHARED_IRQ (1 << 2) |
| 202 | #define PCS_FEAT_IRQ (1 << 1) |
Tony Lindgren | 02e483f | 2013-10-02 21:39:39 -0700 | [diff] [blame] | 203 | #define PCS_FEAT_PINCONF (1 << 0) |
Tony Lindgren | 4622215 | 2016-11-03 09:35:48 -0700 | [diff] [blame] | 204 | struct property *missing_nr_pinctrl_cells; |
Tony Lindgren | 3e6cee1 | 2013-10-02 21:39:40 -0700 | [diff] [blame] | 205 | struct pcs_soc_data socdata; |
| 206 | raw_spinlock_t lock; |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 207 | struct mutex mutex; |
| 208 | unsigned width; |
| 209 | unsigned fmask; |
| 210 | unsigned fshift; |
| 211 | unsigned foff; |
| 212 | unsigned fmax; |
Peter Ujfalusi | 9e605cb | 2012-09-11 11:54:24 +0300 | [diff] [blame] | 213 | bool bits_per_mux; |
Manjunathappa, Prakash | 4e7e801 | 2013-05-21 19:38:00 +0530 | [diff] [blame] | 214 | unsigned bits_per_pin; |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 215 | struct pcs_data pins; |
| 216 | struct radix_tree_root pgtree; |
| 217 | struct radix_tree_root ftree; |
| 218 | struct list_head pingroups; |
| 219 | struct list_head functions; |
Haojian Zhuang | a1a277e | 2013-02-17 19:42:52 +0800 | [diff] [blame] | 220 | struct list_head gpiofuncs; |
Tony Lindgren | 3e6cee1 | 2013-10-02 21:39:40 -0700 | [diff] [blame] | 221 | struct list_head irqs; |
| 222 | struct irq_chip chip; |
| 223 | struct irq_domain *domain; |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 224 | unsigned ngroups; |
| 225 | unsigned nfuncs; |
| 226 | struct pinctrl_desc desc; |
| 227 | unsigned (*read)(void __iomem *reg); |
| 228 | void (*write)(unsigned val, void __iomem *reg); |
| 229 | }; |
| 230 | |
Tony Lindgren | 3e6cee1 | 2013-10-02 21:39:40 -0700 | [diff] [blame] | 231 | #define PCS_QUIRK_HAS_SHARED_IRQ (pcs->flags & PCS_QUIRK_SHARED_IRQ) |
| 232 | #define PCS_HAS_IRQ (pcs->flags & PCS_FEAT_IRQ) |
Tony Lindgren | 02e483f | 2013-10-02 21:39:39 -0700 | [diff] [blame] | 233 | #define PCS_HAS_PINCONF (pcs->flags & PCS_FEAT_PINCONF) |
| 234 | |
Haojian Zhuang | 9dddb4d | 2013-02-17 19:42:55 +0800 | [diff] [blame] | 235 | static int pcs_pinconf_get(struct pinctrl_dev *pctldev, unsigned pin, |
| 236 | unsigned long *config); |
| 237 | static int pcs_pinconf_set(struct pinctrl_dev *pctldev, unsigned pin, |
Sherman Yin | 03b054e | 2013-08-27 11:32:12 -0700 | [diff] [blame] | 238 | unsigned long *configs, unsigned num_configs); |
Haojian Zhuang | 9dddb4d | 2013-02-17 19:42:55 +0800 | [diff] [blame] | 239 | |
| 240 | static enum pin_config_param pcs_bias[] = { |
| 241 | PIN_CONFIG_BIAS_PULL_DOWN, |
| 242 | PIN_CONFIG_BIAS_PULL_UP, |
| 243 | }; |
| 244 | |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 245 | /* |
Sudeep Holla | 3c177a1 | 2016-02-01 18:28:17 +0000 | [diff] [blame] | 246 | * This lock class tells lockdep that irqchip core that this single |
| 247 | * pinctrl can be in a different category than its parents, so it won't |
| 248 | * report false recursion. |
| 249 | */ |
| 250 | static struct lock_class_key pcs_lock_class; |
| 251 | |
| 252 | /* |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 253 | * REVISIT: Reads and writes could eventually use regmap or something |
| 254 | * generic. But at least on omaps, some mux registers are performance |
| 255 | * critical as they may need to be remuxed every time before and after |
| 256 | * idle. Adding tests for register access width for every read and |
| 257 | * write like regmap is doing is not desired, and caching the registers |
| 258 | * does not help in this case. |
| 259 | */ |
| 260 | |
| 261 | static unsigned __maybe_unused pcs_readb(void __iomem *reg) |
| 262 | { |
| 263 | return readb(reg); |
| 264 | } |
| 265 | |
| 266 | static unsigned __maybe_unused pcs_readw(void __iomem *reg) |
| 267 | { |
| 268 | return readw(reg); |
| 269 | } |
| 270 | |
| 271 | static unsigned __maybe_unused pcs_readl(void __iomem *reg) |
| 272 | { |
| 273 | return readl(reg); |
| 274 | } |
| 275 | |
| 276 | static void __maybe_unused pcs_writeb(unsigned val, void __iomem *reg) |
| 277 | { |
| 278 | writeb(val, reg); |
| 279 | } |
| 280 | |
| 281 | static void __maybe_unused pcs_writew(unsigned val, void __iomem *reg) |
| 282 | { |
| 283 | writew(val, reg); |
| 284 | } |
| 285 | |
| 286 | static void __maybe_unused pcs_writel(unsigned val, void __iomem *reg) |
| 287 | { |
| 288 | writel(val, reg); |
| 289 | } |
| 290 | |
| 291 | static int pcs_get_groups_count(struct pinctrl_dev *pctldev) |
| 292 | { |
| 293 | struct pcs_device *pcs; |
| 294 | |
| 295 | pcs = pinctrl_dev_get_drvdata(pctldev); |
| 296 | |
| 297 | return pcs->ngroups; |
| 298 | } |
| 299 | |
| 300 | static const char *pcs_get_group_name(struct pinctrl_dev *pctldev, |
| 301 | unsigned gselector) |
| 302 | { |
| 303 | struct pcs_device *pcs; |
| 304 | struct pcs_pingroup *group; |
| 305 | |
| 306 | pcs = pinctrl_dev_get_drvdata(pctldev); |
| 307 | group = radix_tree_lookup(&pcs->pgtree, gselector); |
| 308 | if (!group) { |
| 309 | dev_err(pcs->dev, "%s could not find pingroup%i\n", |
| 310 | __func__, gselector); |
| 311 | return NULL; |
| 312 | } |
| 313 | |
| 314 | return group->name; |
| 315 | } |
| 316 | |
| 317 | static int pcs_get_group_pins(struct pinctrl_dev *pctldev, |
| 318 | unsigned gselector, |
| 319 | const unsigned **pins, |
| 320 | unsigned *npins) |
| 321 | { |
| 322 | struct pcs_device *pcs; |
| 323 | struct pcs_pingroup *group; |
| 324 | |
| 325 | pcs = pinctrl_dev_get_drvdata(pctldev); |
| 326 | group = radix_tree_lookup(&pcs->pgtree, gselector); |
| 327 | if (!group) { |
| 328 | dev_err(pcs->dev, "%s could not find pingroup%i\n", |
| 329 | __func__, gselector); |
| 330 | return -EINVAL; |
| 331 | } |
| 332 | |
| 333 | *pins = group->gpins; |
| 334 | *npins = group->ngpins; |
| 335 | |
| 336 | return 0; |
| 337 | } |
| 338 | |
| 339 | static void pcs_pin_dbg_show(struct pinctrl_dev *pctldev, |
| 340 | struct seq_file *s, |
Haojian Zhuang | e7ed671 | 2012-11-07 23:19:42 +0800 | [diff] [blame] | 341 | unsigned pin) |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 342 | { |
Matt Porter | 7d66ce7 | 2012-09-26 15:07:43 -0400 | [diff] [blame] | 343 | struct pcs_device *pcs; |
Haojian Zhuang | e7ed671 | 2012-11-07 23:19:42 +0800 | [diff] [blame] | 344 | unsigned val, mux_bytes; |
Tony Lindgren | 223decc | 2016-10-27 07:59:52 -0700 | [diff] [blame] | 345 | unsigned long offset; |
| 346 | size_t pa; |
Matt Porter | 7d66ce7 | 2012-09-26 15:07:43 -0400 | [diff] [blame] | 347 | |
| 348 | pcs = pinctrl_dev_get_drvdata(pctldev); |
| 349 | |
Haojian Zhuang | e7ed671 | 2012-11-07 23:19:42 +0800 | [diff] [blame] | 350 | mux_bytes = pcs->width / BITS_PER_BYTE; |
Tony Lindgren | 223decc | 2016-10-27 07:59:52 -0700 | [diff] [blame] | 351 | offset = pin * mux_bytes; |
| 352 | val = pcs->read(pcs->base + offset); |
| 353 | pa = pcs->res->start + offset; |
Matt Porter | 7d66ce7 | 2012-09-26 15:07:43 -0400 | [diff] [blame] | 354 | |
Tony Lindgren | 223decc | 2016-10-27 07:59:52 -0700 | [diff] [blame] | 355 | seq_printf(s, "%zx %08x %s ", pa, val, DRIVER_NAME); |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | static void pcs_dt_free_map(struct pinctrl_dev *pctldev, |
| 359 | struct pinctrl_map *map, unsigned num_maps) |
| 360 | { |
| 361 | struct pcs_device *pcs; |
| 362 | |
| 363 | pcs = pinctrl_dev_get_drvdata(pctldev); |
| 364 | devm_kfree(pcs->dev, map); |
| 365 | } |
| 366 | |
| 367 | static int pcs_dt_node_to_map(struct pinctrl_dev *pctldev, |
| 368 | struct device_node *np_config, |
| 369 | struct pinctrl_map **map, unsigned *num_maps); |
| 370 | |
Laurent Pinchart | 022ab14 | 2013-02-16 10:25:07 +0100 | [diff] [blame] | 371 | static const struct pinctrl_ops pcs_pinctrl_ops = { |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 372 | .get_groups_count = pcs_get_groups_count, |
| 373 | .get_group_name = pcs_get_group_name, |
| 374 | .get_group_pins = pcs_get_group_pins, |
| 375 | .pin_dbg_show = pcs_pin_dbg_show, |
| 376 | .dt_node_to_map = pcs_dt_node_to_map, |
| 377 | .dt_free_map = pcs_dt_free_map, |
| 378 | }; |
| 379 | |
| 380 | static int pcs_get_functions_count(struct pinctrl_dev *pctldev) |
| 381 | { |
| 382 | struct pcs_device *pcs; |
| 383 | |
| 384 | pcs = pinctrl_dev_get_drvdata(pctldev); |
| 385 | |
| 386 | return pcs->nfuncs; |
| 387 | } |
| 388 | |
| 389 | static const char *pcs_get_function_name(struct pinctrl_dev *pctldev, |
| 390 | unsigned fselector) |
| 391 | { |
| 392 | struct pcs_device *pcs; |
| 393 | struct pcs_function *func; |
| 394 | |
| 395 | pcs = pinctrl_dev_get_drvdata(pctldev); |
| 396 | func = radix_tree_lookup(&pcs->ftree, fselector); |
| 397 | if (!func) { |
| 398 | dev_err(pcs->dev, "%s could not find function%i\n", |
| 399 | __func__, fselector); |
| 400 | return NULL; |
| 401 | } |
| 402 | |
| 403 | return func->name; |
| 404 | } |
| 405 | |
| 406 | static int pcs_get_function_groups(struct pinctrl_dev *pctldev, |
| 407 | unsigned fselector, |
| 408 | const char * const **groups, |
| 409 | unsigned * const ngroups) |
| 410 | { |
| 411 | struct pcs_device *pcs; |
| 412 | struct pcs_function *func; |
| 413 | |
| 414 | pcs = pinctrl_dev_get_drvdata(pctldev); |
| 415 | func = radix_tree_lookup(&pcs->ftree, fselector); |
| 416 | if (!func) { |
| 417 | dev_err(pcs->dev, "%s could not find function%i\n", |
| 418 | __func__, fselector); |
| 419 | return -EINVAL; |
| 420 | } |
| 421 | *groups = func->pgnames; |
| 422 | *ngroups = func->npgnames; |
| 423 | |
| 424 | return 0; |
| 425 | } |
| 426 | |
Haojian Zhuang | 9dddb4d | 2013-02-17 19:42:55 +0800 | [diff] [blame] | 427 | static int pcs_get_function(struct pinctrl_dev *pctldev, unsigned pin, |
| 428 | struct pcs_function **func) |
| 429 | { |
| 430 | struct pcs_device *pcs = pinctrl_dev_get_drvdata(pctldev); |
| 431 | struct pin_desc *pdesc = pin_desc_get(pctldev, pin); |
| 432 | const struct pinctrl_setting_mux *setting; |
| 433 | unsigned fselector; |
| 434 | |
| 435 | /* If pin is not described in DTS & enabled, mux_setting is NULL. */ |
| 436 | setting = pdesc->mux_setting; |
| 437 | if (!setting) |
| 438 | return -ENOTSUPP; |
| 439 | fselector = setting->func; |
| 440 | *func = radix_tree_lookup(&pcs->ftree, fselector); |
| 441 | if (!(*func)) { |
| 442 | dev_err(pcs->dev, "%s could not find function%i\n", |
| 443 | __func__, fselector); |
| 444 | return -ENOTSUPP; |
| 445 | } |
| 446 | return 0; |
| 447 | } |
| 448 | |
Linus Walleij | 03e9f0c | 2014-09-03 13:02:56 +0200 | [diff] [blame] | 449 | static int pcs_set_mux(struct pinctrl_dev *pctldev, unsigned fselector, |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 450 | unsigned group) |
| 451 | { |
| 452 | struct pcs_device *pcs; |
| 453 | struct pcs_function *func; |
| 454 | int i; |
| 455 | |
| 456 | pcs = pinctrl_dev_get_drvdata(pctldev); |
Haojian Zhuang | 477ac77 | 2013-02-17 19:42:54 +0800 | [diff] [blame] | 457 | /* If function mask is null, needn't enable it. */ |
| 458 | if (!pcs->fmask) |
| 459 | return 0; |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 460 | func = radix_tree_lookup(&pcs->ftree, fselector); |
| 461 | if (!func) |
| 462 | return -EINVAL; |
| 463 | |
| 464 | dev_dbg(pcs->dev, "enabling %s function%i\n", |
| 465 | func->name, fselector); |
| 466 | |
| 467 | for (i = 0; i < func->nvals; i++) { |
| 468 | struct pcs_func_vals *vals; |
Tony Lindgren | 3e6cee1 | 2013-10-02 21:39:40 -0700 | [diff] [blame] | 469 | unsigned long flags; |
Peter Ujfalusi | 9e605cb | 2012-09-11 11:54:24 +0300 | [diff] [blame] | 470 | unsigned val, mask; |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 471 | |
| 472 | vals = &func->vals[i]; |
Tony Lindgren | 3e6cee1 | 2013-10-02 21:39:40 -0700 | [diff] [blame] | 473 | raw_spin_lock_irqsave(&pcs->lock, flags); |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 474 | val = pcs->read(vals->reg); |
Manjunathappa, Prakash | 4e7e801 | 2013-05-21 19:38:00 +0530 | [diff] [blame] | 475 | |
| 476 | if (pcs->bits_per_mux) |
| 477 | mask = vals->mask; |
Peter Ujfalusi | 9e605cb | 2012-09-11 11:54:24 +0300 | [diff] [blame] | 478 | else |
Manjunathappa, Prakash | 4e7e801 | 2013-05-21 19:38:00 +0530 | [diff] [blame] | 479 | mask = pcs->fmask; |
Peter Ujfalusi | 9e605cb | 2012-09-11 11:54:24 +0300 | [diff] [blame] | 480 | |
| 481 | val &= ~mask; |
| 482 | val |= (vals->val & mask); |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 483 | pcs->write(val, vals->reg); |
Tony Lindgren | 3e6cee1 | 2013-10-02 21:39:40 -0700 | [diff] [blame] | 484 | raw_spin_unlock_irqrestore(&pcs->lock, flags); |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | return 0; |
| 488 | } |
| 489 | |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 490 | static int pcs_request_gpio(struct pinctrl_dev *pctldev, |
Haojian Zhuang | a1a277e | 2013-02-17 19:42:52 +0800 | [diff] [blame] | 491 | struct pinctrl_gpio_range *range, unsigned pin) |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 492 | { |
Haojian Zhuang | a1a277e | 2013-02-17 19:42:52 +0800 | [diff] [blame] | 493 | struct pcs_device *pcs = pinctrl_dev_get_drvdata(pctldev); |
| 494 | struct pcs_gpiofunc_range *frange = NULL; |
| 495 | struct list_head *pos, *tmp; |
| 496 | int mux_bytes = 0; |
| 497 | unsigned data; |
| 498 | |
Haojian Zhuang | 477ac77 | 2013-02-17 19:42:54 +0800 | [diff] [blame] | 499 | /* If function mask is null, return directly. */ |
| 500 | if (!pcs->fmask) |
| 501 | return -ENOTSUPP; |
| 502 | |
Haojian Zhuang | a1a277e | 2013-02-17 19:42:52 +0800 | [diff] [blame] | 503 | list_for_each_safe(pos, tmp, &pcs->gpiofuncs) { |
| 504 | frange = list_entry(pos, struct pcs_gpiofunc_range, node); |
| 505 | if (pin >= frange->offset + frange->npins |
| 506 | || pin < frange->offset) |
| 507 | continue; |
| 508 | mux_bytes = pcs->width / BITS_PER_BYTE; |
| 509 | data = pcs->read(pcs->base + pin * mux_bytes) & ~pcs->fmask; |
| 510 | data |= frange->gpiofunc; |
| 511 | pcs->write(data, pcs->base + pin * mux_bytes); |
| 512 | break; |
| 513 | } |
| 514 | return 0; |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 515 | } |
| 516 | |
Laurent Pinchart | 022ab14 | 2013-02-16 10:25:07 +0100 | [diff] [blame] | 517 | static const struct pinmux_ops pcs_pinmux_ops = { |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 518 | .get_functions_count = pcs_get_functions_count, |
| 519 | .get_function_name = pcs_get_function_name, |
| 520 | .get_function_groups = pcs_get_function_groups, |
Linus Walleij | 9e3a979 | 2014-09-05 09:53:23 +0200 | [diff] [blame] | 521 | .set_mux = pcs_set_mux, |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 522 | .gpio_request_enable = pcs_request_gpio, |
| 523 | }; |
| 524 | |
Haojian Zhuang | 9dddb4d | 2013-02-17 19:42:55 +0800 | [diff] [blame] | 525 | /* Clear BIAS value */ |
| 526 | static void pcs_pinconf_clear_bias(struct pinctrl_dev *pctldev, unsigned pin) |
| 527 | { |
| 528 | unsigned long config; |
| 529 | int i; |
| 530 | for (i = 0; i < ARRAY_SIZE(pcs_bias); i++) { |
| 531 | config = pinconf_to_config_packed(pcs_bias[i], 0); |
Sherman Yin | 03b054e | 2013-08-27 11:32:12 -0700 | [diff] [blame] | 532 | pcs_pinconf_set(pctldev, pin, &config, 1); |
Haojian Zhuang | 9dddb4d | 2013-02-17 19:42:55 +0800 | [diff] [blame] | 533 | } |
| 534 | } |
| 535 | |
| 536 | /* |
| 537 | * Check whether PIN_CONFIG_BIAS_DISABLE is valid. |
| 538 | * It's depend on that PULL_DOWN & PULL_UP configs are all invalid. |
| 539 | */ |
| 540 | static bool pcs_pinconf_bias_disable(struct pinctrl_dev *pctldev, unsigned pin) |
| 541 | { |
| 542 | unsigned long config; |
| 543 | int i; |
| 544 | |
| 545 | for (i = 0; i < ARRAY_SIZE(pcs_bias); i++) { |
| 546 | config = pinconf_to_config_packed(pcs_bias[i], 0); |
| 547 | if (!pcs_pinconf_get(pctldev, pin, &config)) |
| 548 | goto out; |
| 549 | } |
| 550 | return true; |
| 551 | out: |
| 552 | return false; |
| 553 | } |
| 554 | |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 555 | static int pcs_pinconf_get(struct pinctrl_dev *pctldev, |
| 556 | unsigned pin, unsigned long *config) |
| 557 | { |
Haojian Zhuang | 9dddb4d | 2013-02-17 19:42:55 +0800 | [diff] [blame] | 558 | struct pcs_device *pcs = pinctrl_dev_get_drvdata(pctldev); |
| 559 | struct pcs_function *func; |
| 560 | enum pin_config_param param; |
| 561 | unsigned offset = 0, data = 0, i, j, ret; |
| 562 | |
| 563 | ret = pcs_get_function(pctldev, pin, &func); |
| 564 | if (ret) |
| 565 | return ret; |
| 566 | |
| 567 | for (i = 0; i < func->nconfs; i++) { |
| 568 | param = pinconf_to_config_param(*config); |
| 569 | if (param == PIN_CONFIG_BIAS_DISABLE) { |
| 570 | if (pcs_pinconf_bias_disable(pctldev, pin)) { |
| 571 | *config = 0; |
| 572 | return 0; |
| 573 | } else { |
| 574 | return -ENOTSUPP; |
| 575 | } |
| 576 | } else if (param != func->conf[i].param) { |
| 577 | continue; |
| 578 | } |
| 579 | |
| 580 | offset = pin * (pcs->width / BITS_PER_BYTE); |
| 581 | data = pcs->read(pcs->base + offset) & func->conf[i].mask; |
| 582 | switch (func->conf[i].param) { |
| 583 | /* 4 parameters */ |
| 584 | case PIN_CONFIG_BIAS_PULL_DOWN: |
| 585 | case PIN_CONFIG_BIAS_PULL_UP: |
| 586 | case PIN_CONFIG_INPUT_SCHMITT_ENABLE: |
| 587 | if ((data != func->conf[i].enable) || |
| 588 | (data == func->conf[i].disable)) |
| 589 | return -ENOTSUPP; |
| 590 | *config = 0; |
| 591 | break; |
| 592 | /* 2 parameters */ |
| 593 | case PIN_CONFIG_INPUT_SCHMITT: |
| 594 | for (j = 0; j < func->nconfs; j++) { |
| 595 | switch (func->conf[j].param) { |
| 596 | case PIN_CONFIG_INPUT_SCHMITT_ENABLE: |
| 597 | if (data != func->conf[j].enable) |
| 598 | return -ENOTSUPP; |
| 599 | break; |
| 600 | default: |
| 601 | break; |
| 602 | } |
| 603 | } |
| 604 | *config = data; |
| 605 | break; |
| 606 | case PIN_CONFIG_DRIVE_STRENGTH: |
| 607 | case PIN_CONFIG_SLEW_RATE: |
Chao Xie | 4bd7547 | 2014-01-28 15:20:44 +0800 | [diff] [blame] | 608 | case PIN_CONFIG_LOW_POWER_MODE: |
Haojian Zhuang | 9dddb4d | 2013-02-17 19:42:55 +0800 | [diff] [blame] | 609 | default: |
| 610 | *config = data; |
| 611 | break; |
| 612 | } |
| 613 | return 0; |
| 614 | } |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 615 | return -ENOTSUPP; |
| 616 | } |
| 617 | |
| 618 | static int pcs_pinconf_set(struct pinctrl_dev *pctldev, |
Sherman Yin | 03b054e | 2013-08-27 11:32:12 -0700 | [diff] [blame] | 619 | unsigned pin, unsigned long *configs, |
| 620 | unsigned num_configs) |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 621 | { |
Haojian Zhuang | 9dddb4d | 2013-02-17 19:42:55 +0800 | [diff] [blame] | 622 | struct pcs_device *pcs = pinctrl_dev_get_drvdata(pctldev); |
| 623 | struct pcs_function *func; |
Haojian Zhuang | 7cba5b3 | 2013-03-13 16:01:26 +0800 | [diff] [blame] | 624 | unsigned offset = 0, shift = 0, i, data, ret; |
| 625 | u16 arg; |
Sherman Yin | 03b054e | 2013-08-27 11:32:12 -0700 | [diff] [blame] | 626 | int j; |
Haojian Zhuang | 9dddb4d | 2013-02-17 19:42:55 +0800 | [diff] [blame] | 627 | |
| 628 | ret = pcs_get_function(pctldev, pin, &func); |
| 629 | if (ret) |
| 630 | return ret; |
| 631 | |
Sherman Yin | 03b054e | 2013-08-27 11:32:12 -0700 | [diff] [blame] | 632 | for (j = 0; j < num_configs; j++) { |
| 633 | for (i = 0; i < func->nconfs; i++) { |
| 634 | if (pinconf_to_config_param(configs[j]) |
| 635 | != func->conf[i].param) |
| 636 | continue; |
| 637 | |
Haojian Zhuang | 9dddb4d | 2013-02-17 19:42:55 +0800 | [diff] [blame] | 638 | offset = pin * (pcs->width / BITS_PER_BYTE); |
| 639 | data = pcs->read(pcs->base + offset); |
Sherman Yin | 03b054e | 2013-08-27 11:32:12 -0700 | [diff] [blame] | 640 | arg = pinconf_to_config_argument(configs[j]); |
Haojian Zhuang | 9dddb4d | 2013-02-17 19:42:55 +0800 | [diff] [blame] | 641 | switch (func->conf[i].param) { |
| 642 | /* 2 parameters */ |
| 643 | case PIN_CONFIG_INPUT_SCHMITT: |
| 644 | case PIN_CONFIG_DRIVE_STRENGTH: |
| 645 | case PIN_CONFIG_SLEW_RATE: |
Chao Xie | 4bd7547 | 2014-01-28 15:20:44 +0800 | [diff] [blame] | 646 | case PIN_CONFIG_LOW_POWER_MODE: |
Haojian Zhuang | 9dddb4d | 2013-02-17 19:42:55 +0800 | [diff] [blame] | 647 | shift = ffs(func->conf[i].mask) - 1; |
Haojian Zhuang | 9dddb4d | 2013-02-17 19:42:55 +0800 | [diff] [blame] | 648 | data &= ~func->conf[i].mask; |
| 649 | data |= (arg << shift) & func->conf[i].mask; |
| 650 | break; |
| 651 | /* 4 parameters */ |
| 652 | case PIN_CONFIG_BIAS_DISABLE: |
| 653 | pcs_pinconf_clear_bias(pctldev, pin); |
| 654 | break; |
| 655 | case PIN_CONFIG_BIAS_PULL_DOWN: |
| 656 | case PIN_CONFIG_BIAS_PULL_UP: |
Haojian Zhuang | 7cba5b3 | 2013-03-13 16:01:26 +0800 | [diff] [blame] | 657 | if (arg) |
Haojian Zhuang | 9dddb4d | 2013-02-17 19:42:55 +0800 | [diff] [blame] | 658 | pcs_pinconf_clear_bias(pctldev, pin); |
| 659 | /* fall through */ |
| 660 | case PIN_CONFIG_INPUT_SCHMITT_ENABLE: |
| 661 | data &= ~func->conf[i].mask; |
Haojian Zhuang | 7cba5b3 | 2013-03-13 16:01:26 +0800 | [diff] [blame] | 662 | if (arg) |
Haojian Zhuang | 9dddb4d | 2013-02-17 19:42:55 +0800 | [diff] [blame] | 663 | data |= func->conf[i].enable; |
| 664 | else |
| 665 | data |= func->conf[i].disable; |
| 666 | break; |
| 667 | default: |
| 668 | return -ENOTSUPP; |
| 669 | } |
| 670 | pcs->write(data, pcs->base + offset); |
Sherman Yin | 03b054e | 2013-08-27 11:32:12 -0700 | [diff] [blame] | 671 | |
| 672 | break; |
Haojian Zhuang | 9dddb4d | 2013-02-17 19:42:55 +0800 | [diff] [blame] | 673 | } |
Sherman Yin | 03b054e | 2013-08-27 11:32:12 -0700 | [diff] [blame] | 674 | if (i >= func->nconfs) |
| 675 | return -ENOTSUPP; |
| 676 | } /* for each config */ |
| 677 | |
| 678 | return 0; |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 679 | } |
| 680 | |
| 681 | static int pcs_pinconf_group_get(struct pinctrl_dev *pctldev, |
| 682 | unsigned group, unsigned long *config) |
| 683 | { |
Haojian Zhuang | 9dddb4d | 2013-02-17 19:42:55 +0800 | [diff] [blame] | 684 | const unsigned *pins; |
| 685 | unsigned npins, old = 0; |
| 686 | int i, ret; |
| 687 | |
| 688 | ret = pcs_get_group_pins(pctldev, group, &pins, &npins); |
| 689 | if (ret) |
| 690 | return ret; |
| 691 | for (i = 0; i < npins; i++) { |
| 692 | if (pcs_pinconf_get(pctldev, pins[i], config)) |
| 693 | return -ENOTSUPP; |
| 694 | /* configs do not match between two pins */ |
| 695 | if (i && (old != *config)) |
| 696 | return -ENOTSUPP; |
| 697 | old = *config; |
| 698 | } |
| 699 | return 0; |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | static int pcs_pinconf_group_set(struct pinctrl_dev *pctldev, |
Sherman Yin | 03b054e | 2013-08-27 11:32:12 -0700 | [diff] [blame] | 703 | unsigned group, unsigned long *configs, |
| 704 | unsigned num_configs) |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 705 | { |
Haojian Zhuang | 9dddb4d | 2013-02-17 19:42:55 +0800 | [diff] [blame] | 706 | const unsigned *pins; |
| 707 | unsigned npins; |
| 708 | int i, ret; |
| 709 | |
| 710 | ret = pcs_get_group_pins(pctldev, group, &pins, &npins); |
| 711 | if (ret) |
| 712 | return ret; |
| 713 | for (i = 0; i < npins; i++) { |
Sherman Yin | 03b054e | 2013-08-27 11:32:12 -0700 | [diff] [blame] | 714 | if (pcs_pinconf_set(pctldev, pins[i], configs, num_configs)) |
Haojian Zhuang | 9dddb4d | 2013-02-17 19:42:55 +0800 | [diff] [blame] | 715 | return -ENOTSUPP; |
| 716 | } |
| 717 | return 0; |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | static void pcs_pinconf_dbg_show(struct pinctrl_dev *pctldev, |
Haojian Zhuang | 9dddb4d | 2013-02-17 19:42:55 +0800 | [diff] [blame] | 721 | struct seq_file *s, unsigned pin) |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 722 | { |
| 723 | } |
| 724 | |
| 725 | static void pcs_pinconf_group_dbg_show(struct pinctrl_dev *pctldev, |
| 726 | struct seq_file *s, unsigned selector) |
| 727 | { |
| 728 | } |
| 729 | |
Haojian Zhuang | 9dddb4d | 2013-02-17 19:42:55 +0800 | [diff] [blame] | 730 | static void pcs_pinconf_config_dbg_show(struct pinctrl_dev *pctldev, |
| 731 | struct seq_file *s, |
| 732 | unsigned long config) |
| 733 | { |
| 734 | pinconf_generic_dump_config(pctldev, s, config); |
| 735 | } |
| 736 | |
Laurent Pinchart | 022ab14 | 2013-02-16 10:25:07 +0100 | [diff] [blame] | 737 | static const struct pinconf_ops pcs_pinconf_ops = { |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 738 | .pin_config_get = pcs_pinconf_get, |
| 739 | .pin_config_set = pcs_pinconf_set, |
| 740 | .pin_config_group_get = pcs_pinconf_group_get, |
| 741 | .pin_config_group_set = pcs_pinconf_group_set, |
| 742 | .pin_config_dbg_show = pcs_pinconf_dbg_show, |
| 743 | .pin_config_group_dbg_show = pcs_pinconf_group_dbg_show, |
Haojian Zhuang | 9dddb4d | 2013-02-17 19:42:55 +0800 | [diff] [blame] | 744 | .pin_config_config_dbg_show = pcs_pinconf_config_dbg_show, |
Axel Lin | a7bbdd7 | 2013-03-04 13:47:39 +0800 | [diff] [blame] | 745 | .is_generic = true, |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 746 | }; |
| 747 | |
| 748 | /** |
| 749 | * pcs_add_pin() - add a pin to the static per controller pin array |
| 750 | * @pcs: pcs driver instance |
| 751 | * @offset: register offset from base |
| 752 | */ |
Manjunathappa, Prakash | 6f924b0 | 2013-05-21 19:38:01 +0530 | [diff] [blame] | 753 | static int pcs_add_pin(struct pcs_device *pcs, unsigned offset, |
| 754 | unsigned pin_pos) |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 755 | { |
Tony Lindgren | 5896862 | 2014-04-10 16:47:19 -0700 | [diff] [blame] | 756 | struct pcs_soc_data *pcs_soc = &pcs->socdata; |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 757 | struct pinctrl_pin_desc *pin; |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 758 | int i; |
| 759 | |
| 760 | i = pcs->pins.cur; |
| 761 | if (i >= pcs->desc.npins) { |
| 762 | dev_err(pcs->dev, "too many pins, max %i\n", |
| 763 | pcs->desc.npins); |
| 764 | return -ENOMEM; |
| 765 | } |
| 766 | |
Tony Lindgren | 5896862 | 2014-04-10 16:47:19 -0700 | [diff] [blame] | 767 | if (pcs_soc->irq_enable_mask) { |
| 768 | unsigned val; |
| 769 | |
| 770 | val = pcs->read(pcs->base + offset); |
| 771 | if (val & pcs_soc->irq_enable_mask) { |
| 772 | dev_dbg(pcs->dev, "irq enabled at boot for pin at %lx (%x), clearing\n", |
| 773 | (unsigned long)pcs->res->start + offset, val); |
| 774 | val &= ~pcs_soc->irq_enable_mask; |
| 775 | pcs->write(val, pcs->base + offset); |
| 776 | } |
| 777 | } |
| 778 | |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 779 | pin = &pcs->pins.pa[i]; |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 780 | pin->number = i; |
| 781 | pcs->pins.cur++; |
| 782 | |
| 783 | return i; |
| 784 | } |
| 785 | |
| 786 | /** |
| 787 | * pcs_allocate_pin_table() - adds all the pins for the pinctrl driver |
| 788 | * @pcs: pcs driver instance |
| 789 | * |
| 790 | * In case of errors, resources are freed in pcs_free_resources. |
| 791 | * |
| 792 | * If your hardware needs holes in the address space, then just set |
| 793 | * up multiple driver instances. |
| 794 | */ |
Greg Kroah-Hartman | 150632b | 2012-12-21 13:10:23 -0800 | [diff] [blame] | 795 | static int pcs_allocate_pin_table(struct pcs_device *pcs) |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 796 | { |
| 797 | int mux_bytes, nr_pins, i; |
Manjunathappa, Prakash | 6f924b0 | 2013-05-21 19:38:01 +0530 | [diff] [blame] | 798 | int num_pins_in_register = 0; |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 799 | |
| 800 | mux_bytes = pcs->width / BITS_PER_BYTE; |
Manjunathappa, Prakash | 4e7e801 | 2013-05-21 19:38:00 +0530 | [diff] [blame] | 801 | |
| 802 | if (pcs->bits_per_mux) { |
| 803 | pcs->bits_per_pin = fls(pcs->fmask); |
| 804 | nr_pins = (pcs->size * BITS_PER_BYTE) / pcs->bits_per_pin; |
Manjunathappa, Prakash | 6f924b0 | 2013-05-21 19:38:01 +0530 | [diff] [blame] | 805 | num_pins_in_register = pcs->width / pcs->bits_per_pin; |
Manjunathappa, Prakash | 4e7e801 | 2013-05-21 19:38:00 +0530 | [diff] [blame] | 806 | } else { |
| 807 | nr_pins = pcs->size / mux_bytes; |
| 808 | } |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 809 | |
| 810 | dev_dbg(pcs->dev, "allocating %i pins\n", nr_pins); |
| 811 | pcs->pins.pa = devm_kzalloc(pcs->dev, |
| 812 | sizeof(*pcs->pins.pa) * nr_pins, |
| 813 | GFP_KERNEL); |
| 814 | if (!pcs->pins.pa) |
| 815 | return -ENOMEM; |
| 816 | |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 817 | pcs->desc.pins = pcs->pins.pa; |
| 818 | pcs->desc.npins = nr_pins; |
| 819 | |
| 820 | for (i = 0; i < pcs->desc.npins; i++) { |
| 821 | unsigned offset; |
| 822 | int res; |
Manjunathappa, Prakash | 4e7e801 | 2013-05-21 19:38:00 +0530 | [diff] [blame] | 823 | int byte_num; |
Manjunathappa, Prakash | 6f924b0 | 2013-05-21 19:38:01 +0530 | [diff] [blame] | 824 | int pin_pos = 0; |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 825 | |
Manjunathappa, Prakash | 4e7e801 | 2013-05-21 19:38:00 +0530 | [diff] [blame] | 826 | if (pcs->bits_per_mux) { |
| 827 | byte_num = (pcs->bits_per_pin * i) / BITS_PER_BYTE; |
| 828 | offset = (byte_num / mux_bytes) * mux_bytes; |
Manjunathappa, Prakash | 6f924b0 | 2013-05-21 19:38:01 +0530 | [diff] [blame] | 829 | pin_pos = i % num_pins_in_register; |
Manjunathappa, Prakash | 4e7e801 | 2013-05-21 19:38:00 +0530 | [diff] [blame] | 830 | } else { |
| 831 | offset = i * mux_bytes; |
| 832 | } |
Manjunathappa, Prakash | 6f924b0 | 2013-05-21 19:38:01 +0530 | [diff] [blame] | 833 | res = pcs_add_pin(pcs, offset, pin_pos); |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 834 | if (res < 0) { |
| 835 | dev_err(pcs->dev, "error adding pins: %i\n", res); |
| 836 | return res; |
| 837 | } |
| 838 | } |
| 839 | |
| 840 | return 0; |
| 841 | } |
| 842 | |
| 843 | /** |
| 844 | * pcs_add_function() - adds a new function to the function list |
| 845 | * @pcs: pcs driver instance |
| 846 | * @np: device node of the mux entry |
| 847 | * @name: name of the function |
| 848 | * @vals: array of mux register value pairs used by the function |
| 849 | * @nvals: number of mux register value pairs |
| 850 | * @pgnames: array of pingroup names for the function |
| 851 | * @npgnames: number of pingroup names |
| 852 | */ |
| 853 | static struct pcs_function *pcs_add_function(struct pcs_device *pcs, |
| 854 | struct device_node *np, |
| 855 | const char *name, |
| 856 | struct pcs_func_vals *vals, |
| 857 | unsigned nvals, |
| 858 | const char **pgnames, |
| 859 | unsigned npgnames) |
| 860 | { |
| 861 | struct pcs_function *function; |
| 862 | |
| 863 | function = devm_kzalloc(pcs->dev, sizeof(*function), GFP_KERNEL); |
| 864 | if (!function) |
| 865 | return NULL; |
| 866 | |
| 867 | function->name = name; |
| 868 | function->vals = vals; |
| 869 | function->nvals = nvals; |
| 870 | function->pgnames = pgnames; |
| 871 | function->npgnames = npgnames; |
| 872 | |
| 873 | mutex_lock(&pcs->mutex); |
| 874 | list_add_tail(&function->node, &pcs->functions); |
| 875 | radix_tree_insert(&pcs->ftree, pcs->nfuncs, function); |
| 876 | pcs->nfuncs++; |
| 877 | mutex_unlock(&pcs->mutex); |
| 878 | |
| 879 | return function; |
| 880 | } |
| 881 | |
| 882 | static void pcs_remove_function(struct pcs_device *pcs, |
| 883 | struct pcs_function *function) |
| 884 | { |
| 885 | int i; |
| 886 | |
| 887 | mutex_lock(&pcs->mutex); |
| 888 | for (i = 0; i < pcs->nfuncs; i++) { |
| 889 | struct pcs_function *found; |
| 890 | |
| 891 | found = radix_tree_lookup(&pcs->ftree, i); |
| 892 | if (found == function) |
| 893 | radix_tree_delete(&pcs->ftree, i); |
| 894 | } |
| 895 | list_del(&function->node); |
| 896 | mutex_unlock(&pcs->mutex); |
| 897 | } |
| 898 | |
| 899 | /** |
| 900 | * pcs_add_pingroup() - add a pingroup to the pingroup list |
| 901 | * @pcs: pcs driver instance |
| 902 | * @np: device node of the mux entry |
| 903 | * @name: name of the pingroup |
| 904 | * @gpins: array of the pins that belong to the group |
| 905 | * @ngpins: number of pins in the group |
| 906 | */ |
| 907 | static int pcs_add_pingroup(struct pcs_device *pcs, |
| 908 | struct device_node *np, |
| 909 | const char *name, |
| 910 | int *gpins, |
| 911 | int ngpins) |
| 912 | { |
| 913 | struct pcs_pingroup *pingroup; |
| 914 | |
| 915 | pingroup = devm_kzalloc(pcs->dev, sizeof(*pingroup), GFP_KERNEL); |
| 916 | if (!pingroup) |
| 917 | return -ENOMEM; |
| 918 | |
| 919 | pingroup->name = name; |
| 920 | pingroup->np = np; |
| 921 | pingroup->gpins = gpins; |
| 922 | pingroup->ngpins = ngpins; |
| 923 | |
| 924 | mutex_lock(&pcs->mutex); |
| 925 | list_add_tail(&pingroup->node, &pcs->pingroups); |
| 926 | radix_tree_insert(&pcs->pgtree, pcs->ngroups, pingroup); |
| 927 | pcs->ngroups++; |
| 928 | mutex_unlock(&pcs->mutex); |
| 929 | |
| 930 | return 0; |
| 931 | } |
| 932 | |
| 933 | /** |
| 934 | * pcs_get_pin_by_offset() - get a pin index based on the register offset |
| 935 | * @pcs: pcs driver instance |
| 936 | * @offset: register offset from the base |
| 937 | * |
| 938 | * Note that this is OK as long as the pins are in a static array. |
| 939 | */ |
| 940 | static int pcs_get_pin_by_offset(struct pcs_device *pcs, unsigned offset) |
| 941 | { |
| 942 | unsigned index; |
| 943 | |
| 944 | if (offset >= pcs->size) { |
| 945 | dev_err(pcs->dev, "mux offset out of range: 0x%x (0x%x)\n", |
| 946 | offset, pcs->size); |
| 947 | return -EINVAL; |
| 948 | } |
| 949 | |
Manjunathappa, Prakash | 4e7e801 | 2013-05-21 19:38:00 +0530 | [diff] [blame] | 950 | if (pcs->bits_per_mux) |
| 951 | index = (offset * BITS_PER_BYTE) / pcs->bits_per_pin; |
| 952 | else |
| 953 | index = offset / (pcs->width / BITS_PER_BYTE); |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 954 | |
| 955 | return index; |
| 956 | } |
| 957 | |
Haojian Zhuang | 9dddb4d | 2013-02-17 19:42:55 +0800 | [diff] [blame] | 958 | /* |
| 959 | * check whether data matches enable bits or disable bits |
| 960 | * Return value: 1 for matching enable bits, 0 for matching disable bits, |
| 961 | * and negative value for matching failure. |
| 962 | */ |
| 963 | static int pcs_config_match(unsigned data, unsigned enable, unsigned disable) |
| 964 | { |
| 965 | int ret = -EINVAL; |
| 966 | |
| 967 | if (data == enable) |
| 968 | ret = 1; |
| 969 | else if (data == disable) |
| 970 | ret = 0; |
| 971 | return ret; |
| 972 | } |
| 973 | |
| 974 | static void add_config(struct pcs_conf_vals **conf, enum pin_config_param param, |
| 975 | unsigned value, unsigned enable, unsigned disable, |
| 976 | unsigned mask) |
| 977 | { |
| 978 | (*conf)->param = param; |
| 979 | (*conf)->val = value; |
| 980 | (*conf)->enable = enable; |
| 981 | (*conf)->disable = disable; |
| 982 | (*conf)->mask = mask; |
| 983 | (*conf)++; |
| 984 | } |
| 985 | |
| 986 | static void add_setting(unsigned long **setting, enum pin_config_param param, |
| 987 | unsigned arg) |
| 988 | { |
| 989 | **setting = pinconf_to_config_packed(param, arg); |
| 990 | (*setting)++; |
| 991 | } |
| 992 | |
| 993 | /* add pinconf setting with 2 parameters */ |
| 994 | static void pcs_add_conf2(struct pcs_device *pcs, struct device_node *np, |
| 995 | const char *name, enum pin_config_param param, |
| 996 | struct pcs_conf_vals **conf, unsigned long **settings) |
| 997 | { |
Haojian Zhuang | 7cba5b3 | 2013-03-13 16:01:26 +0800 | [diff] [blame] | 998 | unsigned value[2], shift; |
Haojian Zhuang | 9dddb4d | 2013-02-17 19:42:55 +0800 | [diff] [blame] | 999 | int ret; |
| 1000 | |
| 1001 | ret = of_property_read_u32_array(np, name, value, 2); |
| 1002 | if (ret) |
| 1003 | return; |
| 1004 | /* set value & mask */ |
| 1005 | value[0] &= value[1]; |
Haojian Zhuang | 7cba5b3 | 2013-03-13 16:01:26 +0800 | [diff] [blame] | 1006 | shift = ffs(value[1]) - 1; |
Haojian Zhuang | 9dddb4d | 2013-02-17 19:42:55 +0800 | [diff] [blame] | 1007 | /* skip enable & disable */ |
| 1008 | add_config(conf, param, value[0], 0, 0, value[1]); |
Haojian Zhuang | 7cba5b3 | 2013-03-13 16:01:26 +0800 | [diff] [blame] | 1009 | add_setting(settings, param, value[0] >> shift); |
Haojian Zhuang | 9dddb4d | 2013-02-17 19:42:55 +0800 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | /* add pinconf setting with 4 parameters */ |
| 1013 | static void pcs_add_conf4(struct pcs_device *pcs, struct device_node *np, |
| 1014 | const char *name, enum pin_config_param param, |
| 1015 | struct pcs_conf_vals **conf, unsigned long **settings) |
| 1016 | { |
| 1017 | unsigned value[4]; |
| 1018 | int ret; |
| 1019 | |
| 1020 | /* value to set, enable, disable, mask */ |
| 1021 | ret = of_property_read_u32_array(np, name, value, 4); |
| 1022 | if (ret) |
| 1023 | return; |
| 1024 | if (!value[3]) { |
| 1025 | dev_err(pcs->dev, "mask field of the property can't be 0\n"); |
| 1026 | return; |
| 1027 | } |
| 1028 | value[0] &= value[3]; |
| 1029 | value[1] &= value[3]; |
| 1030 | value[2] &= value[3]; |
| 1031 | ret = pcs_config_match(value[0], value[1], value[2]); |
| 1032 | if (ret < 0) |
| 1033 | dev_dbg(pcs->dev, "failed to match enable or disable bits\n"); |
| 1034 | add_config(conf, param, value[0], value[1], value[2], value[3]); |
| 1035 | add_setting(settings, param, ret); |
| 1036 | } |
| 1037 | |
| 1038 | static int pcs_parse_pinconf(struct pcs_device *pcs, struct device_node *np, |
| 1039 | struct pcs_function *func, |
| 1040 | struct pinctrl_map **map) |
| 1041 | |
| 1042 | { |
| 1043 | struct pinctrl_map *m = *map; |
| 1044 | int i = 0, nconfs = 0; |
| 1045 | unsigned long *settings = NULL, *s = NULL; |
| 1046 | struct pcs_conf_vals *conf = NULL; |
| 1047 | struct pcs_conf_type prop2[] = { |
| 1048 | { "pinctrl-single,drive-strength", PIN_CONFIG_DRIVE_STRENGTH, }, |
| 1049 | { "pinctrl-single,slew-rate", PIN_CONFIG_SLEW_RATE, }, |
| 1050 | { "pinctrl-single,input-schmitt", PIN_CONFIG_INPUT_SCHMITT, }, |
Chao Xie | 4bd7547 | 2014-01-28 15:20:44 +0800 | [diff] [blame] | 1051 | { "pinctrl-single,low-power-mode", PIN_CONFIG_LOW_POWER_MODE, }, |
Haojian Zhuang | 9dddb4d | 2013-02-17 19:42:55 +0800 | [diff] [blame] | 1052 | }; |
| 1053 | struct pcs_conf_type prop4[] = { |
| 1054 | { "pinctrl-single,bias-pullup", PIN_CONFIG_BIAS_PULL_UP, }, |
| 1055 | { "pinctrl-single,bias-pulldown", PIN_CONFIG_BIAS_PULL_DOWN, }, |
| 1056 | { "pinctrl-single,input-schmitt-enable", |
| 1057 | PIN_CONFIG_INPUT_SCHMITT_ENABLE, }, |
| 1058 | }; |
| 1059 | |
| 1060 | /* If pinconf isn't supported, don't parse properties in below. */ |
Tony Lindgren | 02e483f | 2013-10-02 21:39:39 -0700 | [diff] [blame] | 1061 | if (!PCS_HAS_PINCONF) |
Haojian Zhuang | 9dddb4d | 2013-02-17 19:42:55 +0800 | [diff] [blame] | 1062 | return 0; |
| 1063 | |
| 1064 | /* cacluate how much properties are supported in current node */ |
| 1065 | for (i = 0; i < ARRAY_SIZE(prop2); i++) { |
| 1066 | if (of_find_property(np, prop2[i].name, NULL)) |
| 1067 | nconfs++; |
| 1068 | } |
| 1069 | for (i = 0; i < ARRAY_SIZE(prop4); i++) { |
| 1070 | if (of_find_property(np, prop4[i].name, NULL)) |
| 1071 | nconfs++; |
| 1072 | } |
| 1073 | if (!nconfs) |
| 1074 | return 0; |
| 1075 | |
| 1076 | func->conf = devm_kzalloc(pcs->dev, |
| 1077 | sizeof(struct pcs_conf_vals) * nconfs, |
| 1078 | GFP_KERNEL); |
| 1079 | if (!func->conf) |
| 1080 | return -ENOMEM; |
| 1081 | func->nconfs = nconfs; |
| 1082 | conf = &(func->conf[0]); |
| 1083 | m++; |
| 1084 | settings = devm_kzalloc(pcs->dev, sizeof(unsigned long) * nconfs, |
| 1085 | GFP_KERNEL); |
| 1086 | if (!settings) |
| 1087 | return -ENOMEM; |
| 1088 | s = &settings[0]; |
| 1089 | |
| 1090 | for (i = 0; i < ARRAY_SIZE(prop2); i++) |
| 1091 | pcs_add_conf2(pcs, np, prop2[i].name, prop2[i].param, |
| 1092 | &conf, &s); |
| 1093 | for (i = 0; i < ARRAY_SIZE(prop4); i++) |
| 1094 | pcs_add_conf4(pcs, np, prop4[i].name, prop4[i].param, |
| 1095 | &conf, &s); |
| 1096 | m->type = PIN_MAP_TYPE_CONFIGS_GROUP; |
| 1097 | m->data.configs.group_or_pin = np->name; |
| 1098 | m->data.configs.configs = settings; |
| 1099 | m->data.configs.num_configs = nconfs; |
| 1100 | return 0; |
| 1101 | } |
| 1102 | |
| 1103 | static void pcs_free_pingroups(struct pcs_device *pcs); |
| 1104 | |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 1105 | /** |
| 1106 | * smux_parse_one_pinctrl_entry() - parses a device tree mux entry |
| 1107 | * @pcs: pinctrl driver instance |
| 1108 | * @np: device node of the mux entry |
| 1109 | * @map: map entry |
Haojian Zhuang | 9dddb4d | 2013-02-17 19:42:55 +0800 | [diff] [blame] | 1110 | * @num_maps: number of map |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 1111 | * @pgnames: pingroup names |
| 1112 | * |
| 1113 | * Note that this binding currently supports only sets of one register + value. |
| 1114 | * |
| 1115 | * Also note that this driver tries to avoid understanding pin and function |
| 1116 | * names because of the extra bloat they would cause especially in the case of |
| 1117 | * a large number of pins. This driver just sets what is specified for the board |
| 1118 | * in the .dts file. Further user space debugging tools can be developed to |
| 1119 | * decipher the pin and function names using debugfs. |
| 1120 | * |
| 1121 | * If you are concerned about the boot time, set up the static pins in |
| 1122 | * the bootloader, and only set up selected pins as device tree entries. |
| 1123 | */ |
| 1124 | static int pcs_parse_one_pinctrl_entry(struct pcs_device *pcs, |
| 1125 | struct device_node *np, |
| 1126 | struct pinctrl_map **map, |
Haojian Zhuang | 9dddb4d | 2013-02-17 19:42:55 +0800 | [diff] [blame] | 1127 | unsigned *num_maps, |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 1128 | const char **pgnames) |
| 1129 | { |
Tony Lindgren | 4622215 | 2016-11-03 09:35:48 -0700 | [diff] [blame] | 1130 | const char *name = "pinctrl-single,pins"; |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 1131 | struct pcs_func_vals *vals; |
Tony Lindgren | 4622215 | 2016-11-03 09:35:48 -0700 | [diff] [blame] | 1132 | int rows, *pins, found = 0, res = -ENOMEM, i; |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 1133 | struct pcs_function *function; |
| 1134 | |
Tony Lindgren | 4622215 | 2016-11-03 09:35:48 -0700 | [diff] [blame] | 1135 | rows = pinctrl_count_index_with_args(np, name); |
Axel Haslam | de7416b | 2016-11-09 15:54:00 +0100 | [diff] [blame^] | 1136 | if (rows <= 0) { |
| 1137 | dev_err(pcs->dev, "Ivalid number of rows: %d\n", rows); |
| 1138 | return -EINVAL; |
| 1139 | } |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 1140 | |
| 1141 | vals = devm_kzalloc(pcs->dev, sizeof(*vals) * rows, GFP_KERNEL); |
| 1142 | if (!vals) |
| 1143 | return -ENOMEM; |
| 1144 | |
| 1145 | pins = devm_kzalloc(pcs->dev, sizeof(*pins) * rows, GFP_KERNEL); |
| 1146 | if (!pins) |
| 1147 | goto free_vals; |
| 1148 | |
Tony Lindgren | 4622215 | 2016-11-03 09:35:48 -0700 | [diff] [blame] | 1149 | for (i = 0; i < rows; i++) { |
| 1150 | struct of_phandle_args pinctrl_spec; |
| 1151 | unsigned int offset; |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 1152 | int pin; |
| 1153 | |
Tony Lindgren | 4622215 | 2016-11-03 09:35:48 -0700 | [diff] [blame] | 1154 | res = pinctrl_parse_index_with_args(np, name, i, &pinctrl_spec); |
| 1155 | if (res) |
| 1156 | return res; |
| 1157 | |
| 1158 | if (pinctrl_spec.args_count < 2) { |
| 1159 | dev_err(pcs->dev, "invalid args_count for spec: %i\n", |
| 1160 | pinctrl_spec.args_count); |
| 1161 | break; |
| 1162 | } |
| 1163 | |
| 1164 | /* Index plus one value cell */ |
| 1165 | offset = pinctrl_spec.args[0]; |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 1166 | vals[found].reg = pcs->base + offset; |
Tony Lindgren | 4622215 | 2016-11-03 09:35:48 -0700 | [diff] [blame] | 1167 | vals[found].val = pinctrl_spec.args[1]; |
| 1168 | |
| 1169 | dev_dbg(pcs->dev, "%s index: 0x%x value: 0x%x\n", |
| 1170 | pinctrl_spec.np->name, offset, pinctrl_spec.args[1]); |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 1171 | |
| 1172 | pin = pcs_get_pin_by_offset(pcs, offset); |
| 1173 | if (pin < 0) { |
| 1174 | dev_err(pcs->dev, |
| 1175 | "could not add functions for %s %ux\n", |
| 1176 | np->name, offset); |
| 1177 | break; |
| 1178 | } |
| 1179 | pins[found++] = pin; |
| 1180 | } |
| 1181 | |
| 1182 | pgnames[0] = np->name; |
| 1183 | function = pcs_add_function(pcs, np, np->name, vals, found, pgnames, 1); |
| 1184 | if (!function) |
| 1185 | goto free_pins; |
| 1186 | |
| 1187 | res = pcs_add_pingroup(pcs, np, np->name, pins, found); |
| 1188 | if (res < 0) |
| 1189 | goto free_function; |
| 1190 | |
| 1191 | (*map)->type = PIN_MAP_TYPE_MUX_GROUP; |
| 1192 | (*map)->data.mux.group = np->name; |
| 1193 | (*map)->data.mux.function = np->name; |
| 1194 | |
Tony Lindgren | 02e483f | 2013-10-02 21:39:39 -0700 | [diff] [blame] | 1195 | if (PCS_HAS_PINCONF) { |
Wei Yongjun | 18442e6 | 2013-05-07 20:06:19 +0800 | [diff] [blame] | 1196 | res = pcs_parse_pinconf(pcs, np, function, map); |
| 1197 | if (res) |
Haojian Zhuang | 9dddb4d | 2013-02-17 19:42:55 +0800 | [diff] [blame] | 1198 | goto free_pingroups; |
| 1199 | *num_maps = 2; |
| 1200 | } else { |
| 1201 | *num_maps = 1; |
| 1202 | } |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 1203 | return 0; |
| 1204 | |
Haojian Zhuang | 9dddb4d | 2013-02-17 19:42:55 +0800 | [diff] [blame] | 1205 | free_pingroups: |
| 1206 | pcs_free_pingroups(pcs); |
| 1207 | *num_maps = 1; |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 1208 | free_function: |
| 1209 | pcs_remove_function(pcs, function); |
| 1210 | |
| 1211 | free_pins: |
| 1212 | devm_kfree(pcs->dev, pins); |
| 1213 | |
| 1214 | free_vals: |
| 1215 | devm_kfree(pcs->dev, vals); |
| 1216 | |
| 1217 | return res; |
| 1218 | } |
Manjunathappa, Prakash | 4e7e801 | 2013-05-21 19:38:00 +0530 | [diff] [blame] | 1219 | |
Manjunathappa, Prakash | 4e7e801 | 2013-05-21 19:38:00 +0530 | [diff] [blame] | 1220 | static int pcs_parse_bits_in_pinctrl_entry(struct pcs_device *pcs, |
| 1221 | struct device_node *np, |
| 1222 | struct pinctrl_map **map, |
| 1223 | unsigned *num_maps, |
| 1224 | const char **pgnames) |
| 1225 | { |
Tony Lindgren | 22d5127 | 2016-11-03 09:35:49 -0700 | [diff] [blame] | 1226 | const char *name = "pinctrl-single,pins"; |
Manjunathappa, Prakash | 4e7e801 | 2013-05-21 19:38:00 +0530 | [diff] [blame] | 1227 | struct pcs_func_vals *vals; |
Tony Lindgren | 22d5127 | 2016-11-03 09:35:49 -0700 | [diff] [blame] | 1228 | int rows, *pins, found = 0, res = -ENOMEM, i; |
Manjunathappa, Prakash | 4e7e801 | 2013-05-21 19:38:00 +0530 | [diff] [blame] | 1229 | int npins_in_row; |
| 1230 | struct pcs_function *function; |
| 1231 | |
Tony Lindgren | 22d5127 | 2016-11-03 09:35:49 -0700 | [diff] [blame] | 1232 | rows = pinctrl_count_index_with_args(np, name); |
Axel Haslam | de7416b | 2016-11-09 15:54:00 +0100 | [diff] [blame^] | 1233 | if (rows <= 0) { |
| 1234 | dev_err(pcs->dev, "Invalid number of rows: %d\n", rows); |
| 1235 | return -EINVAL; |
| 1236 | } |
Manjunathappa, Prakash | 4e7e801 | 2013-05-21 19:38:00 +0530 | [diff] [blame] | 1237 | |
Manjunathappa, Prakash | 4e7e801 | 2013-05-21 19:38:00 +0530 | [diff] [blame] | 1238 | npins_in_row = pcs->width / pcs->bits_per_pin; |
| 1239 | |
| 1240 | vals = devm_kzalloc(pcs->dev, sizeof(*vals) * rows * npins_in_row, |
| 1241 | GFP_KERNEL); |
| 1242 | if (!vals) |
| 1243 | return -ENOMEM; |
| 1244 | |
| 1245 | pins = devm_kzalloc(pcs->dev, sizeof(*pins) * rows * npins_in_row, |
| 1246 | GFP_KERNEL); |
| 1247 | if (!pins) |
| 1248 | goto free_vals; |
| 1249 | |
Tony Lindgren | 22d5127 | 2016-11-03 09:35:49 -0700 | [diff] [blame] | 1250 | for (i = 0; i < rows; i++) { |
| 1251 | struct of_phandle_args pinctrl_spec; |
Manjunathappa, Prakash | 4e7e801 | 2013-05-21 19:38:00 +0530 | [diff] [blame] | 1252 | unsigned offset, val; |
| 1253 | unsigned mask, bit_pos, val_pos, mask_pos, submask; |
| 1254 | unsigned pin_num_from_lsb; |
| 1255 | int pin; |
| 1256 | |
Tony Lindgren | 22d5127 | 2016-11-03 09:35:49 -0700 | [diff] [blame] | 1257 | res = pinctrl_parse_index_with_args(np, name, i, &pinctrl_spec); |
| 1258 | if (res) |
| 1259 | return res; |
| 1260 | |
| 1261 | if (pinctrl_spec.args_count < 3) { |
| 1262 | dev_err(pcs->dev, "invalid args_count for spec: %i\n", |
| 1263 | pinctrl_spec.args_count); |
| 1264 | break; |
| 1265 | } |
| 1266 | |
| 1267 | /* Index plus two value cells */ |
| 1268 | offset = pinctrl_spec.args[0]; |
| 1269 | val = pinctrl_spec.args[1]; |
| 1270 | mask = pinctrl_spec.args[2]; |
| 1271 | |
| 1272 | dev_dbg(pcs->dev, "%s index: 0x%x value: 0x%x mask: 0x%x\n", |
| 1273 | pinctrl_spec.np->name, offset, val, mask); |
Manjunathappa, Prakash | 4e7e801 | 2013-05-21 19:38:00 +0530 | [diff] [blame] | 1274 | |
| 1275 | /* Parse pins in each row from LSB */ |
| 1276 | while (mask) { |
Keerthy | 56b367c | 2016-04-14 10:29:16 +0530 | [diff] [blame] | 1277 | bit_pos = __ffs(mask); |
Manjunathappa, Prakash | 4e7e801 | 2013-05-21 19:38:00 +0530 | [diff] [blame] | 1278 | pin_num_from_lsb = bit_pos / pcs->bits_per_pin; |
Keerthy | 56b367c | 2016-04-14 10:29:16 +0530 | [diff] [blame] | 1279 | mask_pos = ((pcs->fmask) << bit_pos); |
Manjunathappa, Prakash | 4e7e801 | 2013-05-21 19:38:00 +0530 | [diff] [blame] | 1280 | val_pos = val & mask_pos; |
| 1281 | submask = mask & mask_pos; |
Tomi Valkeinen | ad5d25f | 2014-01-09 14:50:29 +0200 | [diff] [blame] | 1282 | |
| 1283 | if ((mask & mask_pos) == 0) { |
| 1284 | dev_err(pcs->dev, |
| 1285 | "Invalid mask for %s at 0x%x\n", |
| 1286 | np->name, offset); |
| 1287 | break; |
| 1288 | } |
| 1289 | |
Manjunathappa, Prakash | 4e7e801 | 2013-05-21 19:38:00 +0530 | [diff] [blame] | 1290 | mask &= ~mask_pos; |
| 1291 | |
| 1292 | if (submask != mask_pos) { |
| 1293 | dev_warn(pcs->dev, |
| 1294 | "Invalid submask 0x%x for %s at 0x%x\n", |
| 1295 | submask, np->name, offset); |
| 1296 | continue; |
| 1297 | } |
| 1298 | |
| 1299 | vals[found].mask = submask; |
| 1300 | vals[found].reg = pcs->base + offset; |
| 1301 | vals[found].val = val_pos; |
| 1302 | |
| 1303 | pin = pcs_get_pin_by_offset(pcs, offset); |
| 1304 | if (pin < 0) { |
| 1305 | dev_err(pcs->dev, |
| 1306 | "could not add functions for %s %ux\n", |
| 1307 | np->name, offset); |
| 1308 | break; |
| 1309 | } |
| 1310 | pins[found++] = pin + pin_num_from_lsb; |
| 1311 | } |
| 1312 | } |
| 1313 | |
| 1314 | pgnames[0] = np->name; |
| 1315 | function = pcs_add_function(pcs, np, np->name, vals, found, pgnames, 1); |
| 1316 | if (!function) |
| 1317 | goto free_pins; |
| 1318 | |
| 1319 | res = pcs_add_pingroup(pcs, np, np->name, pins, found); |
| 1320 | if (res < 0) |
| 1321 | goto free_function; |
| 1322 | |
| 1323 | (*map)->type = PIN_MAP_TYPE_MUX_GROUP; |
| 1324 | (*map)->data.mux.group = np->name; |
| 1325 | (*map)->data.mux.function = np->name; |
| 1326 | |
Tony Lindgren | 02e483f | 2013-10-02 21:39:39 -0700 | [diff] [blame] | 1327 | if (PCS_HAS_PINCONF) { |
Manjunathappa, Prakash | 4e7e801 | 2013-05-21 19:38:00 +0530 | [diff] [blame] | 1328 | dev_err(pcs->dev, "pinconf not supported\n"); |
| 1329 | goto free_pingroups; |
| 1330 | } |
| 1331 | |
| 1332 | *num_maps = 1; |
| 1333 | return 0; |
| 1334 | |
| 1335 | free_pingroups: |
| 1336 | pcs_free_pingroups(pcs); |
| 1337 | *num_maps = 1; |
| 1338 | free_function: |
| 1339 | pcs_remove_function(pcs, function); |
| 1340 | |
| 1341 | free_pins: |
| 1342 | devm_kfree(pcs->dev, pins); |
| 1343 | |
| 1344 | free_vals: |
| 1345 | devm_kfree(pcs->dev, vals); |
| 1346 | |
| 1347 | return res; |
| 1348 | } |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 1349 | /** |
| 1350 | * pcs_dt_node_to_map() - allocates and parses pinctrl maps |
| 1351 | * @pctldev: pinctrl instance |
| 1352 | * @np_config: device tree pinmux entry |
| 1353 | * @map: array of map entries |
| 1354 | * @num_maps: number of maps |
| 1355 | */ |
| 1356 | static int pcs_dt_node_to_map(struct pinctrl_dev *pctldev, |
| 1357 | struct device_node *np_config, |
| 1358 | struct pinctrl_map **map, unsigned *num_maps) |
| 1359 | { |
| 1360 | struct pcs_device *pcs; |
| 1361 | const char **pgnames; |
| 1362 | int ret; |
| 1363 | |
| 1364 | pcs = pinctrl_dev_get_drvdata(pctldev); |
| 1365 | |
Haojian Zhuang | 9dddb4d | 2013-02-17 19:42:55 +0800 | [diff] [blame] | 1366 | /* create 2 maps. One is for pinmux, and the other is for pinconf. */ |
| 1367 | *map = devm_kzalloc(pcs->dev, sizeof(**map) * 2, GFP_KERNEL); |
Sachin Kamat | 00e79d1 | 2012-11-20 16:34:39 +0530 | [diff] [blame] | 1368 | if (!*map) |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 1369 | return -ENOMEM; |
| 1370 | |
| 1371 | *num_maps = 0; |
| 1372 | |
| 1373 | pgnames = devm_kzalloc(pcs->dev, sizeof(*pgnames), GFP_KERNEL); |
| 1374 | if (!pgnames) { |
| 1375 | ret = -ENOMEM; |
| 1376 | goto free_map; |
| 1377 | } |
| 1378 | |
Manjunathappa, Prakash | 4e7e801 | 2013-05-21 19:38:00 +0530 | [diff] [blame] | 1379 | if (pcs->bits_per_mux) { |
| 1380 | ret = pcs_parse_bits_in_pinctrl_entry(pcs, np_config, map, |
| 1381 | num_maps, pgnames); |
| 1382 | if (ret < 0) { |
| 1383 | dev_err(pcs->dev, "no pins entries for %s\n", |
| 1384 | np_config->name); |
| 1385 | goto free_pgnames; |
| 1386 | } |
| 1387 | } else { |
| 1388 | ret = pcs_parse_one_pinctrl_entry(pcs, np_config, map, |
| 1389 | num_maps, pgnames); |
| 1390 | if (ret < 0) { |
| 1391 | dev_err(pcs->dev, "no pins entries for %s\n", |
| 1392 | np_config->name); |
| 1393 | goto free_pgnames; |
| 1394 | } |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 1395 | } |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 1396 | |
| 1397 | return 0; |
| 1398 | |
| 1399 | free_pgnames: |
| 1400 | devm_kfree(pcs->dev, pgnames); |
| 1401 | free_map: |
| 1402 | devm_kfree(pcs->dev, *map); |
| 1403 | |
| 1404 | return ret; |
| 1405 | } |
| 1406 | |
| 1407 | /** |
| 1408 | * pcs_free_funcs() - free memory used by functions |
| 1409 | * @pcs: pcs driver instance |
| 1410 | */ |
| 1411 | static void pcs_free_funcs(struct pcs_device *pcs) |
| 1412 | { |
| 1413 | struct list_head *pos, *tmp; |
| 1414 | int i; |
| 1415 | |
| 1416 | mutex_lock(&pcs->mutex); |
| 1417 | for (i = 0; i < pcs->nfuncs; i++) { |
| 1418 | struct pcs_function *func; |
| 1419 | |
| 1420 | func = radix_tree_lookup(&pcs->ftree, i); |
| 1421 | if (!func) |
| 1422 | continue; |
| 1423 | radix_tree_delete(&pcs->ftree, i); |
| 1424 | } |
| 1425 | list_for_each_safe(pos, tmp, &pcs->functions) { |
| 1426 | struct pcs_function *function; |
| 1427 | |
| 1428 | function = list_entry(pos, struct pcs_function, node); |
| 1429 | list_del(&function->node); |
| 1430 | } |
| 1431 | mutex_unlock(&pcs->mutex); |
| 1432 | } |
| 1433 | |
| 1434 | /** |
| 1435 | * pcs_free_pingroups() - free memory used by pingroups |
| 1436 | * @pcs: pcs driver instance |
| 1437 | */ |
| 1438 | static void pcs_free_pingroups(struct pcs_device *pcs) |
| 1439 | { |
| 1440 | struct list_head *pos, *tmp; |
| 1441 | int i; |
| 1442 | |
| 1443 | mutex_lock(&pcs->mutex); |
| 1444 | for (i = 0; i < pcs->ngroups; i++) { |
| 1445 | struct pcs_pingroup *pingroup; |
| 1446 | |
| 1447 | pingroup = radix_tree_lookup(&pcs->pgtree, i); |
| 1448 | if (!pingroup) |
| 1449 | continue; |
| 1450 | radix_tree_delete(&pcs->pgtree, i); |
| 1451 | } |
| 1452 | list_for_each_safe(pos, tmp, &pcs->pingroups) { |
| 1453 | struct pcs_pingroup *pingroup; |
| 1454 | |
| 1455 | pingroup = list_entry(pos, struct pcs_pingroup, node); |
| 1456 | list_del(&pingroup->node); |
| 1457 | } |
| 1458 | mutex_unlock(&pcs->mutex); |
| 1459 | } |
| 1460 | |
| 1461 | /** |
Tony Lindgren | 3e6cee1 | 2013-10-02 21:39:40 -0700 | [diff] [blame] | 1462 | * pcs_irq_free() - free interrupt |
| 1463 | * @pcs: pcs driver instance |
| 1464 | */ |
| 1465 | static void pcs_irq_free(struct pcs_device *pcs) |
| 1466 | { |
| 1467 | struct pcs_soc_data *pcs_soc = &pcs->socdata; |
| 1468 | |
| 1469 | if (pcs_soc->irq < 0) |
| 1470 | return; |
| 1471 | |
| 1472 | if (pcs->domain) |
| 1473 | irq_domain_remove(pcs->domain); |
| 1474 | |
| 1475 | if (PCS_QUIRK_HAS_SHARED_IRQ) |
| 1476 | free_irq(pcs_soc->irq, pcs_soc); |
| 1477 | else |
| 1478 | irq_set_chained_handler(pcs_soc->irq, NULL); |
| 1479 | } |
| 1480 | |
| 1481 | /** |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 1482 | * pcs_free_resources() - free memory used by this driver |
| 1483 | * @pcs: pcs driver instance |
| 1484 | */ |
| 1485 | static void pcs_free_resources(struct pcs_device *pcs) |
| 1486 | { |
Tony Lindgren | 3e6cee1 | 2013-10-02 21:39:40 -0700 | [diff] [blame] | 1487 | pcs_irq_free(pcs); |
Markus Elfring | f10a258 | 2015-11-05 17:10:22 +0100 | [diff] [blame] | 1488 | pinctrl_unregister(pcs->pctl); |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 1489 | pcs_free_funcs(pcs); |
| 1490 | pcs_free_pingroups(pcs); |
Tony Lindgren | 4622215 | 2016-11-03 09:35:48 -0700 | [diff] [blame] | 1491 | #if IS_BUILTIN(CONFIG_PINCTRL_SINGLE) |
| 1492 | if (pcs->missing_nr_pinctrl_cells) |
| 1493 | of_remove_property(pcs->np, pcs->missing_nr_pinctrl_cells); |
| 1494 | #endif |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 1495 | } |
| 1496 | |
Fabian Frederick | baa9946e | 2015-03-16 20:59:09 +0100 | [diff] [blame] | 1497 | static const struct of_device_id pcs_of_match[]; |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 1498 | |
Haojian Zhuang | a1a277e | 2013-02-17 19:42:52 +0800 | [diff] [blame] | 1499 | static int pcs_add_gpio_func(struct device_node *node, struct pcs_device *pcs) |
| 1500 | { |
| 1501 | const char *propname = "pinctrl-single,gpio-range"; |
| 1502 | const char *cellname = "#pinctrl-single,gpio-range-cells"; |
| 1503 | struct of_phandle_args gpiospec; |
| 1504 | struct pcs_gpiofunc_range *range; |
| 1505 | int ret, i; |
| 1506 | |
| 1507 | for (i = 0; ; i++) { |
| 1508 | ret = of_parse_phandle_with_args(node, propname, cellname, |
| 1509 | i, &gpiospec); |
| 1510 | /* Do not treat it as error. Only treat it as end condition. */ |
| 1511 | if (ret) { |
| 1512 | ret = 0; |
| 1513 | break; |
| 1514 | } |
| 1515 | range = devm_kzalloc(pcs->dev, sizeof(*range), GFP_KERNEL); |
| 1516 | if (!range) { |
| 1517 | ret = -ENOMEM; |
| 1518 | break; |
| 1519 | } |
| 1520 | range->offset = gpiospec.args[0]; |
| 1521 | range->npins = gpiospec.args[1]; |
| 1522 | range->gpiofunc = gpiospec.args[2]; |
| 1523 | mutex_lock(&pcs->mutex); |
| 1524 | list_add_tail(&range->node, &pcs->gpiofuncs); |
| 1525 | mutex_unlock(&pcs->mutex); |
| 1526 | } |
| 1527 | return ret; |
| 1528 | } |
Tony Lindgren | 3e6cee1 | 2013-10-02 21:39:40 -0700 | [diff] [blame] | 1529 | /** |
| 1530 | * @reg: virtual address of interrupt register |
| 1531 | * @hwirq: hardware irq number |
| 1532 | * @irq: virtual irq number |
| 1533 | * @node: list node |
| 1534 | */ |
| 1535 | struct pcs_interrupt { |
| 1536 | void __iomem *reg; |
| 1537 | irq_hw_number_t hwirq; |
| 1538 | unsigned int irq; |
| 1539 | struct list_head node; |
| 1540 | }; |
| 1541 | |
| 1542 | /** |
| 1543 | * pcs_irq_set() - enables or disables an interrupt |
| 1544 | * |
| 1545 | * Note that this currently assumes one interrupt per pinctrl |
| 1546 | * register that is typically used for wake-up events. |
| 1547 | */ |
| 1548 | static inline void pcs_irq_set(struct pcs_soc_data *pcs_soc, |
| 1549 | int irq, const bool enable) |
| 1550 | { |
| 1551 | struct pcs_device *pcs; |
| 1552 | struct list_head *pos; |
| 1553 | unsigned mask; |
| 1554 | |
| 1555 | pcs = container_of(pcs_soc, struct pcs_device, socdata); |
| 1556 | list_for_each(pos, &pcs->irqs) { |
| 1557 | struct pcs_interrupt *pcswi; |
| 1558 | unsigned soc_mask; |
| 1559 | |
| 1560 | pcswi = list_entry(pos, struct pcs_interrupt, node); |
| 1561 | if (irq != pcswi->irq) |
| 1562 | continue; |
| 1563 | |
| 1564 | soc_mask = pcs_soc->irq_enable_mask; |
| 1565 | raw_spin_lock(&pcs->lock); |
| 1566 | mask = pcs->read(pcswi->reg); |
| 1567 | if (enable) |
| 1568 | mask |= soc_mask; |
| 1569 | else |
| 1570 | mask &= ~soc_mask; |
| 1571 | pcs->write(mask, pcswi->reg); |
Tony Lindgren | 0ac3c0a4 | 2016-05-31 14:17:06 -0700 | [diff] [blame] | 1572 | |
| 1573 | /* flush posted write */ |
| 1574 | mask = pcs->read(pcswi->reg); |
Tony Lindgren | 3e6cee1 | 2013-10-02 21:39:40 -0700 | [diff] [blame] | 1575 | raw_spin_unlock(&pcs->lock); |
| 1576 | } |
Roger Quadros | c9b3a7d | 2013-10-11 19:13:16 +0300 | [diff] [blame] | 1577 | |
| 1578 | if (pcs_soc->rearm) |
| 1579 | pcs_soc->rearm(); |
Tony Lindgren | 3e6cee1 | 2013-10-02 21:39:40 -0700 | [diff] [blame] | 1580 | } |
| 1581 | |
| 1582 | /** |
| 1583 | * pcs_irq_mask() - mask pinctrl interrupt |
| 1584 | * @d: interrupt data |
| 1585 | */ |
| 1586 | static void pcs_irq_mask(struct irq_data *d) |
| 1587 | { |
| 1588 | struct pcs_soc_data *pcs_soc = irq_data_get_irq_chip_data(d); |
| 1589 | |
| 1590 | pcs_irq_set(pcs_soc, d->irq, false); |
| 1591 | } |
| 1592 | |
| 1593 | /** |
| 1594 | * pcs_irq_unmask() - unmask pinctrl interrupt |
| 1595 | * @d: interrupt data |
| 1596 | */ |
| 1597 | static void pcs_irq_unmask(struct irq_data *d) |
| 1598 | { |
| 1599 | struct pcs_soc_data *pcs_soc = irq_data_get_irq_chip_data(d); |
| 1600 | |
| 1601 | pcs_irq_set(pcs_soc, d->irq, true); |
| 1602 | } |
| 1603 | |
| 1604 | /** |
| 1605 | * pcs_irq_set_wake() - toggle the suspend and resume wake up |
| 1606 | * @d: interrupt data |
| 1607 | * @state: wake-up state |
| 1608 | * |
| 1609 | * Note that this should be called only for suspend and resume. |
| 1610 | * For runtime PM, the wake-up events should be enabled by default. |
| 1611 | */ |
| 1612 | static int pcs_irq_set_wake(struct irq_data *d, unsigned int state) |
| 1613 | { |
| 1614 | if (state) |
| 1615 | pcs_irq_unmask(d); |
| 1616 | else |
| 1617 | pcs_irq_mask(d); |
| 1618 | |
| 1619 | return 0; |
| 1620 | } |
| 1621 | |
| 1622 | /** |
| 1623 | * pcs_irq_handle() - common interrupt handler |
| 1624 | * @pcs_irq: interrupt data |
| 1625 | * |
| 1626 | * Note that this currently assumes we have one interrupt bit per |
| 1627 | * mux register. This interrupt is typically used for wake-up events. |
| 1628 | * For more complex interrupts different handlers can be specified. |
| 1629 | */ |
| 1630 | static int pcs_irq_handle(struct pcs_soc_data *pcs_soc) |
| 1631 | { |
| 1632 | struct pcs_device *pcs; |
| 1633 | struct list_head *pos; |
| 1634 | int count = 0; |
| 1635 | |
| 1636 | pcs = container_of(pcs_soc, struct pcs_device, socdata); |
| 1637 | list_for_each(pos, &pcs->irqs) { |
| 1638 | struct pcs_interrupt *pcswi; |
| 1639 | unsigned mask; |
| 1640 | |
| 1641 | pcswi = list_entry(pos, struct pcs_interrupt, node); |
| 1642 | raw_spin_lock(&pcs->lock); |
| 1643 | mask = pcs->read(pcswi->reg); |
| 1644 | raw_spin_unlock(&pcs->lock); |
| 1645 | if (mask & pcs_soc->irq_status_mask) { |
| 1646 | generic_handle_irq(irq_find_mapping(pcs->domain, |
| 1647 | pcswi->hwirq)); |
| 1648 | count++; |
| 1649 | } |
| 1650 | } |
| 1651 | |
| 1652 | return count; |
| 1653 | } |
| 1654 | |
| 1655 | /** |
| 1656 | * pcs_irq_handler() - handler for the shared interrupt case |
| 1657 | * @irq: interrupt |
| 1658 | * @d: data |
| 1659 | * |
| 1660 | * Use this for cases where multiple instances of |
| 1661 | * pinctrl-single share a single interrupt like on omaps. |
| 1662 | */ |
| 1663 | static irqreturn_t pcs_irq_handler(int irq, void *d) |
| 1664 | { |
| 1665 | struct pcs_soc_data *pcs_soc = d; |
| 1666 | |
| 1667 | return pcs_irq_handle(pcs_soc) ? IRQ_HANDLED : IRQ_NONE; |
| 1668 | } |
| 1669 | |
| 1670 | /** |
| 1671 | * pcs_irq_handle() - handler for the dedicated chained interrupt case |
| 1672 | * @irq: interrupt |
| 1673 | * @desc: interrupt descriptor |
| 1674 | * |
| 1675 | * Use this if you have a separate interrupt for each |
| 1676 | * pinctrl-single instance. |
| 1677 | */ |
Thomas Gleixner | bd0b9ac | 2015-09-14 10:42:37 +0200 | [diff] [blame] | 1678 | static void pcs_irq_chain_handler(struct irq_desc *desc) |
Tony Lindgren | 3e6cee1 | 2013-10-02 21:39:40 -0700 | [diff] [blame] | 1679 | { |
| 1680 | struct pcs_soc_data *pcs_soc = irq_desc_get_handler_data(desc); |
| 1681 | struct irq_chip *chip; |
Tony Lindgren | 3e6cee1 | 2013-10-02 21:39:40 -0700 | [diff] [blame] | 1682 | |
Jiang Liu | 5663bb2 | 2015-06-04 12:13:16 +0800 | [diff] [blame] | 1683 | chip = irq_desc_get_chip(desc); |
Tony Lindgren | 3e6cee1 | 2013-10-02 21:39:40 -0700 | [diff] [blame] | 1684 | chained_irq_enter(chip, desc); |
Rickard Strandqvist | 849bfe0 | 2014-06-26 15:43:01 +0200 | [diff] [blame] | 1685 | pcs_irq_handle(pcs_soc); |
Tony Lindgren | 3e6cee1 | 2013-10-02 21:39:40 -0700 | [diff] [blame] | 1686 | /* REVISIT: export and add handle_bad_irq(irq, desc)? */ |
| 1687 | chained_irq_exit(chip, desc); |
| 1688 | |
| 1689 | return; |
| 1690 | } |
| 1691 | |
| 1692 | static int pcs_irqdomain_map(struct irq_domain *d, unsigned int irq, |
| 1693 | irq_hw_number_t hwirq) |
| 1694 | { |
| 1695 | struct pcs_soc_data *pcs_soc = d->host_data; |
| 1696 | struct pcs_device *pcs; |
| 1697 | struct pcs_interrupt *pcswi; |
| 1698 | |
| 1699 | pcs = container_of(pcs_soc, struct pcs_device, socdata); |
| 1700 | pcswi = devm_kzalloc(pcs->dev, sizeof(*pcswi), GFP_KERNEL); |
| 1701 | if (!pcswi) |
| 1702 | return -ENOMEM; |
| 1703 | |
| 1704 | pcswi->reg = pcs->base + hwirq; |
| 1705 | pcswi->hwirq = hwirq; |
| 1706 | pcswi->irq = irq; |
| 1707 | |
| 1708 | mutex_lock(&pcs->mutex); |
| 1709 | list_add_tail(&pcswi->node, &pcs->irqs); |
| 1710 | mutex_unlock(&pcs->mutex); |
| 1711 | |
| 1712 | irq_set_chip_data(irq, pcs_soc); |
| 1713 | irq_set_chip_and_handler(irq, &pcs->chip, |
| 1714 | handle_level_irq); |
Sudeep Holla | 3c177a1 | 2016-02-01 18:28:17 +0000 | [diff] [blame] | 1715 | irq_set_lockdep_class(irq, &pcs_lock_class); |
Tony Lindgren | 1b9c0fb | 2013-10-18 16:20:05 -0700 | [diff] [blame] | 1716 | irq_set_noprobe(irq); |
Tony Lindgren | 3e6cee1 | 2013-10-02 21:39:40 -0700 | [diff] [blame] | 1717 | |
| 1718 | return 0; |
| 1719 | } |
| 1720 | |
Krzysztof Kozlowski | e5b6095 | 2015-04-27 21:54:06 +0900 | [diff] [blame] | 1721 | static const struct irq_domain_ops pcs_irqdomain_ops = { |
Tony Lindgren | 3e6cee1 | 2013-10-02 21:39:40 -0700 | [diff] [blame] | 1722 | .map = pcs_irqdomain_map, |
| 1723 | .xlate = irq_domain_xlate_onecell, |
| 1724 | }; |
| 1725 | |
| 1726 | /** |
| 1727 | * pcs_irq_init_chained_handler() - set up a chained interrupt handler |
| 1728 | * @pcs: pcs driver instance |
| 1729 | * @np: device node pointer |
| 1730 | */ |
| 1731 | static int pcs_irq_init_chained_handler(struct pcs_device *pcs, |
| 1732 | struct device_node *np) |
| 1733 | { |
| 1734 | struct pcs_soc_data *pcs_soc = &pcs->socdata; |
| 1735 | const char *name = "pinctrl"; |
| 1736 | int num_irqs; |
| 1737 | |
| 1738 | if (!pcs_soc->irq_enable_mask || |
| 1739 | !pcs_soc->irq_status_mask) { |
| 1740 | pcs_soc->irq = -1; |
| 1741 | return -EINVAL; |
| 1742 | } |
| 1743 | |
| 1744 | INIT_LIST_HEAD(&pcs->irqs); |
| 1745 | pcs->chip.name = name; |
| 1746 | pcs->chip.irq_ack = pcs_irq_mask; |
| 1747 | pcs->chip.irq_mask = pcs_irq_mask; |
| 1748 | pcs->chip.irq_unmask = pcs_irq_unmask; |
| 1749 | pcs->chip.irq_set_wake = pcs_irq_set_wake; |
| 1750 | |
| 1751 | if (PCS_QUIRK_HAS_SHARED_IRQ) { |
| 1752 | int res; |
| 1753 | |
| 1754 | res = request_irq(pcs_soc->irq, pcs_irq_handler, |
Grygorii Strashko | c10372e | 2015-07-06 18:13:37 +0300 | [diff] [blame] | 1755 | IRQF_SHARED | IRQF_NO_SUSPEND | |
| 1756 | IRQF_NO_THREAD, |
Tony Lindgren | 3e6cee1 | 2013-10-02 21:39:40 -0700 | [diff] [blame] | 1757 | name, pcs_soc); |
| 1758 | if (res) { |
| 1759 | pcs_soc->irq = -1; |
| 1760 | return res; |
| 1761 | } |
| 1762 | } else { |
Thomas Gleixner | 20d5d14 | 2015-06-21 21:11:06 +0200 | [diff] [blame] | 1763 | irq_set_chained_handler_and_data(pcs_soc->irq, |
| 1764 | pcs_irq_chain_handler, |
| 1765 | pcs_soc); |
Tony Lindgren | 3e6cee1 | 2013-10-02 21:39:40 -0700 | [diff] [blame] | 1766 | } |
| 1767 | |
| 1768 | /* |
| 1769 | * We can use the register offset as the hardirq |
| 1770 | * number as irq_domain_add_simple maps them lazily. |
| 1771 | * This way we can easily support more than one |
| 1772 | * interrupt per function if needed. |
| 1773 | */ |
| 1774 | num_irqs = pcs->size; |
| 1775 | |
| 1776 | pcs->domain = irq_domain_add_simple(np, num_irqs, 0, |
| 1777 | &pcs_irqdomain_ops, |
| 1778 | pcs_soc); |
| 1779 | if (!pcs->domain) { |
| 1780 | irq_set_chained_handler(pcs_soc->irq, NULL); |
| 1781 | return -EINVAL; |
| 1782 | } |
| 1783 | |
| 1784 | return 0; |
| 1785 | } |
Haojian Zhuang | a1a277e | 2013-02-17 19:42:52 +0800 | [diff] [blame] | 1786 | |
Jean-Francois Moine | 8cb440a | 2013-07-15 10:14:26 +0200 | [diff] [blame] | 1787 | #ifdef CONFIG_PM |
Hebbar Gururaja | 0f9bc4b | 2013-05-31 15:43:01 +0530 | [diff] [blame] | 1788 | static int pinctrl_single_suspend(struct platform_device *pdev, |
| 1789 | pm_message_t state) |
| 1790 | { |
| 1791 | struct pcs_device *pcs; |
| 1792 | |
| 1793 | pcs = platform_get_drvdata(pdev); |
| 1794 | if (!pcs) |
| 1795 | return -EINVAL; |
| 1796 | |
| 1797 | return pinctrl_force_sleep(pcs->pctl); |
| 1798 | } |
| 1799 | |
| 1800 | static int pinctrl_single_resume(struct platform_device *pdev) |
| 1801 | { |
| 1802 | struct pcs_device *pcs; |
| 1803 | |
| 1804 | pcs = platform_get_drvdata(pdev); |
| 1805 | if (!pcs) |
| 1806 | return -EINVAL; |
| 1807 | |
| 1808 | return pinctrl_force_default(pcs->pctl); |
| 1809 | } |
Jean-Francois Moine | 8cb440a | 2013-07-15 10:14:26 +0200 | [diff] [blame] | 1810 | #endif |
Hebbar Gururaja | 0f9bc4b | 2013-05-31 15:43:01 +0530 | [diff] [blame] | 1811 | |
Tony Lindgren | 4622215 | 2016-11-03 09:35:48 -0700 | [diff] [blame] | 1812 | /** |
| 1813 | * pcs_quirk_missing_pinctrl_cells - handle legacy binding |
| 1814 | * @pcs: pinctrl driver instance |
| 1815 | * @np: device tree node |
| 1816 | * @cells: number of cells |
| 1817 | * |
| 1818 | * Handle legacy binding with no #pinctrl-cells. This should be |
| 1819 | * always two pinctrl-single,bit-per-mux and one for others. |
| 1820 | * At some point we may want to consider removing this. |
| 1821 | */ |
| 1822 | static int pcs_quirk_missing_pinctrl_cells(struct pcs_device *pcs, |
| 1823 | struct device_node *np, |
| 1824 | int cells) |
| 1825 | { |
| 1826 | struct property *p; |
| 1827 | const char *name = "#pinctrl-cells"; |
| 1828 | int error; |
| 1829 | u32 val; |
| 1830 | |
| 1831 | error = of_property_read_u32(np, name, &val); |
| 1832 | if (!error) |
| 1833 | return 0; |
| 1834 | |
| 1835 | dev_warn(pcs->dev, "please update dts to use %s = <%i>\n", |
| 1836 | name, cells); |
| 1837 | |
| 1838 | p = devm_kzalloc(pcs->dev, sizeof(*p), GFP_KERNEL); |
| 1839 | if (!p) |
| 1840 | return -ENOMEM; |
| 1841 | |
| 1842 | p->length = sizeof(__be32); |
| 1843 | p->value = devm_kzalloc(pcs->dev, sizeof(__be32), GFP_KERNEL); |
| 1844 | if (!p->value) |
| 1845 | return -ENOMEM; |
| 1846 | *(__be32 *)p->value = cpu_to_be32(cells); |
| 1847 | |
| 1848 | p->name = devm_kstrdup(pcs->dev, name, GFP_KERNEL); |
| 1849 | if (!p->name) |
| 1850 | return -ENOMEM; |
| 1851 | |
| 1852 | pcs->missing_nr_pinctrl_cells = p; |
| 1853 | |
| 1854 | #if IS_BUILTIN(CONFIG_PINCTRL_SINGLE) |
| 1855 | error = of_add_property(np, pcs->missing_nr_pinctrl_cells); |
| 1856 | #endif |
| 1857 | |
| 1858 | return error; |
| 1859 | } |
| 1860 | |
Greg Kroah-Hartman | 150632b | 2012-12-21 13:10:23 -0800 | [diff] [blame] | 1861 | static int pcs_probe(struct platform_device *pdev) |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 1862 | { |
| 1863 | struct device_node *np = pdev->dev.of_node; |
| 1864 | const struct of_device_id *match; |
Tony Lindgren | dc7743a | 2013-10-02 21:39:40 -0700 | [diff] [blame] | 1865 | struct pcs_pdata *pdata; |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 1866 | struct resource *res; |
| 1867 | struct pcs_device *pcs; |
Tony Lindgren | 02e483f | 2013-10-02 21:39:39 -0700 | [diff] [blame] | 1868 | const struct pcs_soc_data *soc; |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 1869 | int ret; |
| 1870 | |
| 1871 | match = of_match_device(pcs_of_match, &pdev->dev); |
| 1872 | if (!match) |
| 1873 | return -EINVAL; |
| 1874 | |
| 1875 | pcs = devm_kzalloc(&pdev->dev, sizeof(*pcs), GFP_KERNEL); |
| 1876 | if (!pcs) { |
| 1877 | dev_err(&pdev->dev, "could not allocate\n"); |
| 1878 | return -ENOMEM; |
| 1879 | } |
| 1880 | pcs->dev = &pdev->dev; |
Tony Lindgren | 4622215 | 2016-11-03 09:35:48 -0700 | [diff] [blame] | 1881 | pcs->np = np; |
Tony Lindgren | 3e6cee1 | 2013-10-02 21:39:40 -0700 | [diff] [blame] | 1882 | raw_spin_lock_init(&pcs->lock); |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 1883 | mutex_init(&pcs->mutex); |
| 1884 | INIT_LIST_HEAD(&pcs->pingroups); |
| 1885 | INIT_LIST_HEAD(&pcs->functions); |
Haojian Zhuang | a1a277e | 2013-02-17 19:42:52 +0800 | [diff] [blame] | 1886 | INIT_LIST_HEAD(&pcs->gpiofuncs); |
Tony Lindgren | 02e483f | 2013-10-02 21:39:39 -0700 | [diff] [blame] | 1887 | soc = match->data; |
| 1888 | pcs->flags = soc->flags; |
Tony Lindgren | 3e6cee1 | 2013-10-02 21:39:40 -0700 | [diff] [blame] | 1889 | memcpy(&pcs->socdata, soc, sizeof(*soc)); |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 1890 | |
Tony Lindgren | cd23604 | 2016-10-25 09:09:00 -0700 | [diff] [blame] | 1891 | ret = of_property_read_u32(np, "pinctrl-single,register-width", |
| 1892 | &pcs->width); |
| 1893 | if (ret) { |
| 1894 | dev_err(pcs->dev, "register width not specified\n"); |
| 1895 | |
| 1896 | return ret; |
| 1897 | } |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 1898 | |
Haojian Zhuang | 477ac77 | 2013-02-17 19:42:54 +0800 | [diff] [blame] | 1899 | ret = of_property_read_u32(np, "pinctrl-single,function-mask", |
| 1900 | &pcs->fmask); |
| 1901 | if (!ret) { |
Keerthy | 56b367c | 2016-04-14 10:29:16 +0530 | [diff] [blame] | 1902 | pcs->fshift = __ffs(pcs->fmask); |
Haojian Zhuang | 477ac77 | 2013-02-17 19:42:54 +0800 | [diff] [blame] | 1903 | pcs->fmax = pcs->fmask >> pcs->fshift; |
| 1904 | } else { |
| 1905 | /* If mask property doesn't exist, function mux is invalid. */ |
| 1906 | pcs->fmask = 0; |
| 1907 | pcs->fshift = 0; |
| 1908 | pcs->fmax = 0; |
| 1909 | } |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 1910 | |
| 1911 | ret = of_property_read_u32(np, "pinctrl-single,function-off", |
| 1912 | &pcs->foff); |
| 1913 | if (ret) |
| 1914 | pcs->foff = PCS_OFF_DISABLED; |
| 1915 | |
Peter Ujfalusi | 9e605cb | 2012-09-11 11:54:24 +0300 | [diff] [blame] | 1916 | pcs->bits_per_mux = of_property_read_bool(np, |
| 1917 | "pinctrl-single,bit-per-mux"); |
Tony Lindgren | 4622215 | 2016-11-03 09:35:48 -0700 | [diff] [blame] | 1918 | ret = pcs_quirk_missing_pinctrl_cells(pcs, np, |
| 1919 | pcs->bits_per_mux ? 2 : 1); |
| 1920 | if (ret) { |
| 1921 | dev_err(&pdev->dev, "unable to patch #pinctrl-cells\n"); |
| 1922 | |
| 1923 | return ret; |
| 1924 | } |
Peter Ujfalusi | 9e605cb | 2012-09-11 11:54:24 +0300 | [diff] [blame] | 1925 | |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 1926 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1927 | if (!res) { |
| 1928 | dev_err(pcs->dev, "could not get resource\n"); |
| 1929 | return -ENODEV; |
| 1930 | } |
| 1931 | |
| 1932 | pcs->res = devm_request_mem_region(pcs->dev, res->start, |
| 1933 | resource_size(res), DRIVER_NAME); |
| 1934 | if (!pcs->res) { |
| 1935 | dev_err(pcs->dev, "could not get mem_region\n"); |
| 1936 | return -EBUSY; |
| 1937 | } |
| 1938 | |
| 1939 | pcs->size = resource_size(pcs->res); |
| 1940 | pcs->base = devm_ioremap(pcs->dev, pcs->res->start, pcs->size); |
| 1941 | if (!pcs->base) { |
| 1942 | dev_err(pcs->dev, "could not ioremap\n"); |
| 1943 | return -ENODEV; |
| 1944 | } |
| 1945 | |
| 1946 | INIT_RADIX_TREE(&pcs->pgtree, GFP_KERNEL); |
| 1947 | INIT_RADIX_TREE(&pcs->ftree, GFP_KERNEL); |
| 1948 | platform_set_drvdata(pdev, pcs); |
| 1949 | |
| 1950 | switch (pcs->width) { |
| 1951 | case 8: |
| 1952 | pcs->read = pcs_readb; |
| 1953 | pcs->write = pcs_writeb; |
| 1954 | break; |
| 1955 | case 16: |
| 1956 | pcs->read = pcs_readw; |
| 1957 | pcs->write = pcs_writew; |
| 1958 | break; |
| 1959 | case 32: |
| 1960 | pcs->read = pcs_readl; |
| 1961 | pcs->write = pcs_writel; |
| 1962 | break; |
| 1963 | default: |
| 1964 | break; |
| 1965 | } |
| 1966 | |
| 1967 | pcs->desc.name = DRIVER_NAME; |
| 1968 | pcs->desc.pctlops = &pcs_pinctrl_ops; |
| 1969 | pcs->desc.pmxops = &pcs_pinmux_ops; |
Tony Lindgren | 02e483f | 2013-10-02 21:39:39 -0700 | [diff] [blame] | 1970 | if (PCS_HAS_PINCONF) |
Axel Lin | a7bbdd7 | 2013-03-04 13:47:39 +0800 | [diff] [blame] | 1971 | pcs->desc.confops = &pcs_pinconf_ops; |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 1972 | pcs->desc.owner = THIS_MODULE; |
| 1973 | |
| 1974 | ret = pcs_allocate_pin_table(pcs); |
| 1975 | if (ret < 0) |
| 1976 | goto free; |
| 1977 | |
| 1978 | pcs->pctl = pinctrl_register(&pcs->desc, pcs->dev, pcs); |
Masahiro Yamada | 323de9e | 2015-06-09 13:01:16 +0900 | [diff] [blame] | 1979 | if (IS_ERR(pcs->pctl)) { |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 1980 | dev_err(pcs->dev, "could not register single pinctrl driver\n"); |
Masahiro Yamada | 323de9e | 2015-06-09 13:01:16 +0900 | [diff] [blame] | 1981 | ret = PTR_ERR(pcs->pctl); |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 1982 | goto free; |
| 1983 | } |
| 1984 | |
Haojian Zhuang | a1a277e | 2013-02-17 19:42:52 +0800 | [diff] [blame] | 1985 | ret = pcs_add_gpio_func(np, pcs); |
| 1986 | if (ret < 0) |
| 1987 | goto free; |
| 1988 | |
Tony Lindgren | 3e6cee1 | 2013-10-02 21:39:40 -0700 | [diff] [blame] | 1989 | pcs->socdata.irq = irq_of_parse_and_map(np, 0); |
| 1990 | if (pcs->socdata.irq) |
| 1991 | pcs->flags |= PCS_FEAT_IRQ; |
| 1992 | |
Tony Lindgren | dc7743a | 2013-10-02 21:39:40 -0700 | [diff] [blame] | 1993 | /* We still need auxdata for some omaps for PRM interrupts */ |
| 1994 | pdata = dev_get_platdata(&pdev->dev); |
| 1995 | if (pdata) { |
| 1996 | if (pdata->rearm) |
| 1997 | pcs->socdata.rearm = pdata->rearm; |
| 1998 | if (pdata->irq) { |
| 1999 | pcs->socdata.irq = pdata->irq; |
| 2000 | pcs->flags |= PCS_FEAT_IRQ; |
| 2001 | } |
| 2002 | } |
| 2003 | |
Tony Lindgren | 3e6cee1 | 2013-10-02 21:39:40 -0700 | [diff] [blame] | 2004 | if (PCS_HAS_IRQ) { |
| 2005 | ret = pcs_irq_init_chained_handler(pcs, np); |
| 2006 | if (ret < 0) |
| 2007 | dev_warn(pcs->dev, "initialized with no interrupts\n"); |
| 2008 | } |
| 2009 | |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 2010 | dev_info(pcs->dev, "%i pins at pa %p size %u\n", |
| 2011 | pcs->desc.npins, pcs->base, pcs->size); |
| 2012 | |
| 2013 | return 0; |
| 2014 | |
| 2015 | free: |
| 2016 | pcs_free_resources(pcs); |
| 2017 | |
| 2018 | return ret; |
| 2019 | } |
| 2020 | |
Bill Pemberton | f90f54b | 2012-11-19 13:26:06 -0500 | [diff] [blame] | 2021 | static int pcs_remove(struct platform_device *pdev) |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 2022 | { |
| 2023 | struct pcs_device *pcs = platform_get_drvdata(pdev); |
| 2024 | |
| 2025 | if (!pcs) |
| 2026 | return 0; |
| 2027 | |
| 2028 | pcs_free_resources(pcs); |
| 2029 | |
| 2030 | return 0; |
| 2031 | } |
| 2032 | |
Tony Lindgren | 3e6cee1 | 2013-10-02 21:39:40 -0700 | [diff] [blame] | 2033 | static const struct pcs_soc_data pinctrl_single_omap_wkup = { |
| 2034 | .flags = PCS_QUIRK_SHARED_IRQ, |
| 2035 | .irq_enable_mask = (1 << 14), /* OMAP_WAKEUP_EN */ |
| 2036 | .irq_status_mask = (1 << 15), /* OMAP_WAKEUP_EVENT */ |
| 2037 | }; |
| 2038 | |
Nishanth Menon | 31320be | 2014-08-22 09:01:01 -0500 | [diff] [blame] | 2039 | static const struct pcs_soc_data pinctrl_single_dra7 = { |
Nishanth Menon | 31320be | 2014-08-22 09:01:01 -0500 | [diff] [blame] | 2040 | .irq_enable_mask = (1 << 24), /* WAKEUPENABLE */ |
| 2041 | .irq_status_mask = (1 << 25), /* WAKEUPEVENT */ |
| 2042 | }; |
| 2043 | |
Keerthy | aa2293d | 2014-08-22 09:01:02 -0500 | [diff] [blame] | 2044 | static const struct pcs_soc_data pinctrl_single_am437x = { |
| 2045 | .flags = PCS_QUIRK_SHARED_IRQ, |
| 2046 | .irq_enable_mask = (1 << 29), /* OMAP_WAKEUP_EN */ |
| 2047 | .irq_status_mask = (1 << 30), /* OMAP_WAKEUP_EVENT */ |
| 2048 | }; |
| 2049 | |
Tony Lindgren | 02e483f | 2013-10-02 21:39:39 -0700 | [diff] [blame] | 2050 | static const struct pcs_soc_data pinctrl_single = { |
| 2051 | }; |
| 2052 | |
| 2053 | static const struct pcs_soc_data pinconf_single = { |
| 2054 | .flags = PCS_FEAT_PINCONF, |
| 2055 | }; |
| 2056 | |
Fabian Frederick | baa9946e | 2015-03-16 20:59:09 +0100 | [diff] [blame] | 2057 | static const struct of_device_id pcs_of_match[] = { |
Tony Lindgren | 3e6cee1 | 2013-10-02 21:39:40 -0700 | [diff] [blame] | 2058 | { .compatible = "ti,omap3-padconf", .data = &pinctrl_single_omap_wkup }, |
| 2059 | { .compatible = "ti,omap4-padconf", .data = &pinctrl_single_omap_wkup }, |
| 2060 | { .compatible = "ti,omap5-padconf", .data = &pinctrl_single_omap_wkup }, |
Nishanth Menon | 31320be | 2014-08-22 09:01:01 -0500 | [diff] [blame] | 2061 | { .compatible = "ti,dra7-padconf", .data = &pinctrl_single_dra7 }, |
Keerthy | aa2293d | 2014-08-22 09:01:02 -0500 | [diff] [blame] | 2062 | { .compatible = "ti,am437-padconf", .data = &pinctrl_single_am437x }, |
Tony Lindgren | 02e483f | 2013-10-02 21:39:39 -0700 | [diff] [blame] | 2063 | { .compatible = "pinctrl-single", .data = &pinctrl_single }, |
| 2064 | { .compatible = "pinconf-single", .data = &pinconf_single }, |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 2065 | { }, |
| 2066 | }; |
| 2067 | MODULE_DEVICE_TABLE(of, pcs_of_match); |
| 2068 | |
| 2069 | static struct platform_driver pcs_driver = { |
| 2070 | .probe = pcs_probe, |
Bill Pemberton | 2a36f08 | 2012-11-19 13:21:27 -0500 | [diff] [blame] | 2071 | .remove = pcs_remove, |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 2072 | .driver = { |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 2073 | .name = DRIVER_NAME, |
| 2074 | .of_match_table = pcs_of_match, |
| 2075 | }, |
Hebbar Gururaja | 0f9bc4b | 2013-05-31 15:43:01 +0530 | [diff] [blame] | 2076 | #ifdef CONFIG_PM |
| 2077 | .suspend = pinctrl_single_suspend, |
| 2078 | .resume = pinctrl_single_resume, |
| 2079 | #endif |
Tony Lindgren | 8b8b091 | 2012-07-10 02:05:46 -0700 | [diff] [blame] | 2080 | }; |
| 2081 | |
| 2082 | module_platform_driver(pcs_driver); |
| 2083 | |
| 2084 | MODULE_AUTHOR("Tony Lindgren <tony@atomide.com>"); |
| 2085 | MODULE_DESCRIPTION("One-register-per-pin type device tree based pinctrl driver"); |
| 2086 | MODULE_LICENSE("GPL v2"); |