blob: 19735012ffb4135a22040ba9e982bf8f339e0ac5 [file] [log] [blame]
Magnus Damm2967dab2008-10-08 20:41:43 +09001/*
Paul Mundtb3c185a2012-06-20 17:29:04 +09002 * SuperH Pin Function Controller support.
Magnus Damm2967dab2008-10-08 20:41:43 +09003 *
4 * Copyright (C) 2008 Magnus Damm
Paul Mundtb3c185a2012-06-20 17:29:04 +09005 * Copyright (C) 2009 - 2012 Paul Mundt
Magnus Damm2967dab2008-10-08 20:41:43 +09006 *
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file "COPYING" in the main directory of this archive
9 * for more details.
10 */
Laurent Pinchartc6193ea2012-12-15 23:50:47 +010011
12#define DRV_NAME "sh-pfc"
Laurent Pinchartf9492fd2012-12-15 23:50:45 +010013#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
Paul Mundtb72421d2010-10-04 03:54:56 +090014
Magnus Damm2967dab2008-10-08 20:41:43 +090015#include <linux/bitops.h>
Laurent Pinchart90efde22012-12-15 23:50:52 +010016#include <linux/err.h>
17#include <linux/errno.h>
18#include <linux/io.h>
Magnus Dammb0e10212011-12-09 12:14:27 +090019#include <linux/ioport.h>
Laurent Pinchart90efde22012-12-15 23:50:52 +010020#include <linux/kernel.h>
21#include <linux/module.h>
Paul Mundtca5481c62012-07-10 12:08:14 +090022#include <linux/pinctrl/machine.h>
Laurent Pinchartc6193ea2012-12-15 23:50:47 +010023#include <linux/platform_device.h>
Laurent Pinchart90efde22012-12-15 23:50:52 +010024#include <linux/slab.h>
Magnus Dammb0e10212011-12-09 12:14:27 +090025
Laurent Pinchartf9165132012-12-15 23:50:44 +010026#include "core.h"
27
Laurent Pinchart973931a2012-12-15 23:50:55 +010028static int sh_pfc_ioremap(struct sh_pfc *pfc, struct platform_device *pdev)
Magnus Dammb0e10212011-12-09 12:14:27 +090029{
30 struct resource *res;
31 int k;
32
Laurent Pinchartbee9f222013-02-16 23:39:07 +010033 if (pdev->num_resources == 0)
34 return -EINVAL;
Laurent Pinchart973931a2012-12-15 23:50:55 +010035
Laurent Pinchart56dc04a2012-12-15 23:51:18 +010036 pfc->window = devm_kzalloc(pfc->dev, pdev->num_resources *
Laurent Pinchart1724acf2012-12-15 23:50:48 +010037 sizeof(*pfc->window), GFP_NOWAIT);
Paul Mundtb3c185a2012-06-20 17:29:04 +090038 if (!pfc->window)
Laurent Pinchart1724acf2012-12-15 23:50:48 +010039 return -ENOMEM;
Magnus Dammb0e10212011-12-09 12:14:27 +090040
Laurent Pinchart56dc04a2012-12-15 23:51:18 +010041 pfc->num_windows = pdev->num_resources;
Laurent Pinchart973931a2012-12-15 23:50:55 +010042
Laurent Pinchart56dc04a2012-12-15 23:51:18 +010043 for (k = 0, res = pdev->resource; k < pdev->num_resources; k++, res++) {
Magnus Dammb0e10212011-12-09 12:14:27 +090044 WARN_ON(resource_type(res) != IORESOURCE_MEM);
Paul Mundtb3c185a2012-06-20 17:29:04 +090045 pfc->window[k].phys = res->start;
46 pfc->window[k].size = resource_size(res);
Laurent Pinchartc9fa88e2012-12-15 23:50:49 +010047 pfc->window[k].virt = devm_ioremap_nocache(pfc->dev, res->start,
48 resource_size(res));
49 if (!pfc->window[k].virt)
Laurent Pinchart1724acf2012-12-15 23:50:48 +010050 return -ENOMEM;
Magnus Dammb0e10212011-12-09 12:14:27 +090051 }
52
53 return 0;
Magnus Dammb0e10212011-12-09 12:14:27 +090054}
55
Laurent Pincharte51d5342013-02-17 00:26:33 +010056static void __iomem *sh_pfc_phys_to_virt(struct sh_pfc *pfc,
57 unsigned long address)
Magnus Dammb0e10212011-12-09 12:14:27 +090058{
Laurent Pinchart4aeacd52012-12-15 23:50:53 +010059 struct sh_pfc_window *window;
Laurent Pinchartbee9f222013-02-16 23:39:07 +010060 unsigned int i;
Magnus Dammb0e10212011-12-09 12:14:27 +090061
62 /* scan through physical windows and convert address */
Laurent Pinchartbee9f222013-02-16 23:39:07 +010063 for (i = 0; i < pfc->num_windows; i++) {
64 window = pfc->window + i;
Magnus Dammb0e10212011-12-09 12:14:27 +090065
66 if (address < window->phys)
67 continue;
68
69 if (address >= (window->phys + window->size))
70 continue;
71
72 return window->virt + (address - window->phys);
73 }
74
Laurent Pinchartbee9f222013-02-16 23:39:07 +010075 BUG();
Magnus Dammb0e10212011-12-09 12:14:27 +090076}
Magnus Damm2967dab2008-10-08 20:41:43 +090077
Laurent Pinchart1a0039d2013-03-08 17:43:54 +010078int sh_pfc_get_pin_index(struct sh_pfc *pfc, unsigned int pin)
Laurent Pinchart934cb022013-02-14 22:35:09 +010079{
Laurent Pinchart63d57382013-02-15 01:33:38 +010080 unsigned int offset;
81 unsigned int i;
82
83 if (pfc->info->ranges == NULL)
Laurent Pinchart1a0039d2013-03-08 17:43:54 +010084 return pin;
Laurent Pinchart63d57382013-02-15 01:33:38 +010085
86 for (i = 0, offset = 0; i < pfc->info->nr_ranges; ++i) {
87 const struct pinmux_range *range = &pfc->info->ranges[i];
88
89 if (pin <= range->end)
90 return pin >= range->begin
Laurent Pinchart1a0039d2013-03-08 17:43:54 +010091 ? offset + pin - range->begin : -1;
Laurent Pinchart63d57382013-02-15 01:33:38 +010092
93 offset += range->end - range->begin + 1;
94 }
95
Laurent Pinchart1a0039d2013-03-08 17:43:54 +010096 return -1;
Laurent Pinchart934cb022013-02-14 22:35:09 +010097}
98
Laurent Pinchart4aeacd52012-12-15 23:50:53 +010099static int sh_pfc_enum_in_range(pinmux_enum_t enum_id, struct pinmux_range *r)
Magnus Damm2967dab2008-10-08 20:41:43 +0900100{
101 if (enum_id < r->begin)
102 return 0;
103
104 if (enum_id > r->end)
105 return 0;
106
107 return 1;
108}
109
Laurent Pinchart41f12192013-02-15 02:04:55 +0100110unsigned long sh_pfc_read_raw_reg(void __iomem *mapped_reg,
111 unsigned long reg_width)
Magnus Damm32920942008-12-25 18:17:26 +0900112{
113 switch (reg_width) {
114 case 8:
Magnus Dammb0e10212011-12-09 12:14:27 +0900115 return ioread8(mapped_reg);
Magnus Damm32920942008-12-25 18:17:26 +0900116 case 16:
Magnus Dammb0e10212011-12-09 12:14:27 +0900117 return ioread16(mapped_reg);
Magnus Damm32920942008-12-25 18:17:26 +0900118 case 32:
Magnus Dammb0e10212011-12-09 12:14:27 +0900119 return ioread32(mapped_reg);
Magnus Damm32920942008-12-25 18:17:26 +0900120 }
121
122 BUG();
123 return 0;
124}
125
Laurent Pinchart41f12192013-02-15 02:04:55 +0100126void sh_pfc_write_raw_reg(void __iomem *mapped_reg, unsigned long reg_width,
127 unsigned long data)
Magnus Damm32920942008-12-25 18:17:26 +0900128{
129 switch (reg_width) {
130 case 8:
Magnus Dammb0e10212011-12-09 12:14:27 +0900131 iowrite8(data, mapped_reg);
Magnus Damm32920942008-12-25 18:17:26 +0900132 return;
133 case 16:
Magnus Dammb0e10212011-12-09 12:14:27 +0900134 iowrite16(data, mapped_reg);
Magnus Damm32920942008-12-25 18:17:26 +0900135 return;
136 case 32:
Magnus Dammb0e10212011-12-09 12:14:27 +0900137 iowrite32(data, mapped_reg);
Magnus Damm32920942008-12-25 18:17:26 +0900138 return;
139 }
140
141 BUG();
142}
143
Laurent Pinchart4aeacd52012-12-15 23:50:53 +0100144static void sh_pfc_config_reg_helper(struct sh_pfc *pfc,
145 struct pinmux_cfg_reg *crp,
146 unsigned long in_pos,
147 void __iomem **mapped_regp,
148 unsigned long *maskp,
149 unsigned long *posp)
Magnus Damm2967dab2008-10-08 20:41:43 +0900150{
Magnus Dammf78a26f2011-12-14 01:01:05 +0900151 int k;
152
Laurent Pinchart4aeacd52012-12-15 23:50:53 +0100153 *mapped_regp = sh_pfc_phys_to_virt(pfc, crp->reg);
Magnus Damm2967dab2008-10-08 20:41:43 +0900154
Magnus Dammf78a26f2011-12-14 01:01:05 +0900155 if (crp->field_width) {
156 *maskp = (1 << crp->field_width) - 1;
157 *posp = crp->reg_width - ((in_pos + 1) * crp->field_width);
158 } else {
159 *maskp = (1 << crp->var_field_width[in_pos]) - 1;
160 *posp = crp->reg_width;
161 for (k = 0; k <= in_pos; k++)
162 *posp -= crp->var_field_width[k];
163 }
Magnus Damm0fc64cc2008-12-25 18:17:18 +0900164}
Magnus Damm2967dab2008-10-08 20:41:43 +0900165
Laurent Pinchart4aeacd52012-12-15 23:50:53 +0100166static int sh_pfc_read_config_reg(struct sh_pfc *pfc,
167 struct pinmux_cfg_reg *crp,
168 unsigned long field)
Magnus Damm0fc64cc2008-12-25 18:17:18 +0900169{
Magnus Damm18925e12011-12-14 01:00:55 +0900170 void __iomem *mapped_reg;
Magnus Damm0fc64cc2008-12-25 18:17:18 +0900171 unsigned long mask, pos;
172
Laurent Pinchart4aeacd52012-12-15 23:50:53 +0100173 sh_pfc_config_reg_helper(pfc, crp, field, &mapped_reg, &mask, &pos);
Magnus Damm0fc64cc2008-12-25 18:17:18 +0900174
Magnus Damm18925e12011-12-14 01:00:55 +0900175 pr_debug("read_reg: addr = %lx, field = %ld, "
Paul Mundtfd2cb0c2009-11-30 12:15:04 +0900176 "r_width = %ld, f_width = %ld\n",
Magnus Damm18925e12011-12-14 01:00:55 +0900177 crp->reg, field, crp->reg_width, crp->field_width);
178
Laurent Pinchart4aeacd52012-12-15 23:50:53 +0100179 return (sh_pfc_read_raw_reg(mapped_reg, crp->reg_width) >> pos) & mask;
Magnus Damm18925e12011-12-14 01:00:55 +0900180}
181
Laurent Pinchart4aeacd52012-12-15 23:50:53 +0100182static void sh_pfc_write_config_reg(struct sh_pfc *pfc,
183 struct pinmux_cfg_reg *crp,
184 unsigned long field, unsigned long value)
Magnus Damm18925e12011-12-14 01:00:55 +0900185{
186 void __iomem *mapped_reg;
Magnus Damme499ada2011-12-14 01:01:14 +0900187 unsigned long mask, pos, data;
Magnus Damm18925e12011-12-14 01:00:55 +0900188
Laurent Pinchart4aeacd52012-12-15 23:50:53 +0100189 sh_pfc_config_reg_helper(pfc, crp, field, &mapped_reg, &mask, &pos);
Magnus Damm18925e12011-12-14 01:00:55 +0900190
191 pr_debug("write_reg addr = %lx, value = %ld, field = %ld, "
192 "r_width = %ld, f_width = %ld\n",
193 crp->reg, value, field, crp->reg_width, crp->field_width);
Magnus Damm0fc64cc2008-12-25 18:17:18 +0900194
195 mask = ~(mask << pos);
196 value = value << pos;
Magnus Damm2967dab2008-10-08 20:41:43 +0900197
Laurent Pinchart4aeacd52012-12-15 23:50:53 +0100198 data = sh_pfc_read_raw_reg(mapped_reg, crp->reg_width);
Magnus Damme499ada2011-12-14 01:01:14 +0900199 data &= mask;
200 data |= value;
201
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100202 if (pfc->info->unlock_reg)
Laurent Pinchart4aeacd52012-12-15 23:50:53 +0100203 sh_pfc_write_raw_reg(
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100204 sh_pfc_phys_to_virt(pfc, pfc->info->unlock_reg), 32,
Laurent Pinchart4aeacd52012-12-15 23:50:53 +0100205 ~data);
Magnus Damme499ada2011-12-14 01:01:14 +0900206
Laurent Pinchart4aeacd52012-12-15 23:50:53 +0100207 sh_pfc_write_raw_reg(mapped_reg, crp->reg_width, data);
Magnus Damm2967dab2008-10-08 20:41:43 +0900208}
209
Laurent Pinchart4aeacd52012-12-15 23:50:53 +0100210static int sh_pfc_get_config_reg(struct sh_pfc *pfc, pinmux_enum_t enum_id,
211 struct pinmux_cfg_reg **crp, int *fieldp,
212 int *valuep, unsigned long **cntp)
Magnus Damm2967dab2008-10-08 20:41:43 +0900213{
214 struct pinmux_cfg_reg *config_reg;
Magnus Dammf78a26f2011-12-14 01:01:05 +0900215 unsigned long r_width, f_width, curr_width, ncomb;
216 int k, m, n, pos, bit_pos;
Magnus Damm2967dab2008-10-08 20:41:43 +0900217
218 k = 0;
219 while (1) {
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100220 config_reg = pfc->info->cfg_regs + k;
Magnus Damm2967dab2008-10-08 20:41:43 +0900221
222 r_width = config_reg->reg_width;
223 f_width = config_reg->field_width;
224
225 if (!r_width)
226 break;
Magnus Dammf78a26f2011-12-14 01:01:05 +0900227
228 pos = 0;
229 m = 0;
230 for (bit_pos = 0; bit_pos < r_width; bit_pos += curr_width) {
231 if (f_width)
232 curr_width = f_width;
233 else
234 curr_width = config_reg->var_field_width[m];
235
236 ncomb = 1 << curr_width;
237 for (n = 0; n < ncomb; n++) {
238 if (config_reg->enum_ids[pos + n] == enum_id) {
239 *crp = config_reg;
240 *fieldp = m;
241 *valuep = n;
242 *cntp = &config_reg->cnt[m];
243 return 0;
244 }
Magnus Damm2967dab2008-10-08 20:41:43 +0900245 }
Magnus Dammf78a26f2011-12-14 01:01:05 +0900246 pos += ncomb;
247 m++;
Magnus Damm2967dab2008-10-08 20:41:43 +0900248 }
249 k++;
250 }
251
252 return -1;
253}
254
Laurent Pincharta68fdca92013-02-14 17:36:56 +0100255static int sh_pfc_mark_to_enum(struct sh_pfc *pfc, pinmux_enum_t mark, int pos,
256 pinmux_enum_t *enum_idp)
Magnus Damm2967dab2008-10-08 20:41:43 +0900257{
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100258 pinmux_enum_t *data = pfc->info->gpio_data;
Magnus Damm2967dab2008-10-08 20:41:43 +0900259 int k;
260
Magnus Damm2967dab2008-10-08 20:41:43 +0900261 if (pos) {
262 *enum_idp = data[pos + 1];
263 return pos + 1;
264 }
265
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100266 for (k = 0; k < pfc->info->gpio_data_size; k++) {
Laurent Pincharta68fdca92013-02-14 17:36:56 +0100267 if (data[k] == mark) {
Magnus Damm2967dab2008-10-08 20:41:43 +0900268 *enum_idp = data[k + 1];
269 return k + 1;
270 }
271 }
272
Laurent Pincharta68fdca92013-02-14 17:36:56 +0100273 pr_err("cannot locate data/mark enum_id for mark %d\n", mark);
Magnus Damm2967dab2008-10-08 20:41:43 +0900274 return -1;
275}
276
Laurent Pincharta68fdca92013-02-14 17:36:56 +0100277int sh_pfc_config_mux(struct sh_pfc *pfc, unsigned mark, int pinmux_type,
278 int cfg_mode)
Magnus Damm2967dab2008-10-08 20:41:43 +0900279{
280 struct pinmux_cfg_reg *cr = NULL;
281 pinmux_enum_t enum_id;
282 struct pinmux_range *range;
Magnus Dammad4a07f2011-12-14 01:00:46 +0900283 int in_range, pos, field, value;
Magnus Damm2967dab2008-10-08 20:41:43 +0900284 unsigned long *cntp;
285
286 switch (pinmux_type) {
287
288 case PINMUX_TYPE_FUNCTION:
289 range = NULL;
290 break;
291
292 case PINMUX_TYPE_OUTPUT:
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100293 range = &pfc->info->output;
Magnus Damm2967dab2008-10-08 20:41:43 +0900294 break;
295
296 case PINMUX_TYPE_INPUT:
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100297 range = &pfc->info->input;
Magnus Damm2967dab2008-10-08 20:41:43 +0900298 break;
299
300 case PINMUX_TYPE_INPUT_PULLUP:
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100301 range = &pfc->info->input_pu;
Magnus Damm2967dab2008-10-08 20:41:43 +0900302 break;
303
304 case PINMUX_TYPE_INPUT_PULLDOWN:
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100305 range = &pfc->info->input_pd;
Magnus Damm2967dab2008-10-08 20:41:43 +0900306 break;
307
308 default:
309 goto out_err;
310 }
311
312 pos = 0;
313 enum_id = 0;
Magnus Dammad4a07f2011-12-14 01:00:46 +0900314 field = 0;
315 value = 0;
Magnus Damm2967dab2008-10-08 20:41:43 +0900316 while (1) {
Laurent Pincharta68fdca92013-02-14 17:36:56 +0100317 pos = sh_pfc_mark_to_enum(pfc, mark, pos, &enum_id);
Magnus Damm2967dab2008-10-08 20:41:43 +0900318 if (pos <= 0)
319 goto out_err;
320
321 if (!enum_id)
322 break;
323
Magnus Damm50dd3142010-01-19 13:52:28 +0000324 /* first check if this is a function enum */
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100325 in_range = sh_pfc_enum_in_range(enum_id, &pfc->info->function);
Magnus Damm50dd3142010-01-19 13:52:28 +0000326 if (!in_range) {
327 /* not a function enum */
328 if (range) {
329 /*
330 * other range exists, so this pin is
331 * a regular GPIO pin that now is being
332 * bound to a specific direction.
333 *
334 * for this case we only allow function enums
335 * and the enums that match the other range.
336 */
Laurent Pinchart4aeacd52012-12-15 23:50:53 +0100337 in_range = sh_pfc_enum_in_range(enum_id, range);
Magnus Damm2967dab2008-10-08 20:41:43 +0900338
Magnus Damm50dd3142010-01-19 13:52:28 +0000339 /*
340 * special case pass through for fixed
341 * input-only or output-only pins without
342 * function enum register association.
343 */
344 if (in_range && enum_id == range->force)
345 continue;
346 } else {
347 /*
348 * no other range exists, so this pin
349 * must then be of the function type.
350 *
351 * allow function type pins to select
352 * any combination of function/in/out
353 * in their MARK lists.
354 */
355 in_range = 1;
356 }
Magnus Damm42eed422008-10-22 18:29:17 +0900357 }
358
Magnus Damm2967dab2008-10-08 20:41:43 +0900359 if (!in_range)
360 continue;
361
Laurent Pinchart4aeacd52012-12-15 23:50:53 +0100362 if (sh_pfc_get_config_reg(pfc, enum_id, &cr,
363 &field, &value, &cntp) != 0)
Magnus Damm2967dab2008-10-08 20:41:43 +0900364 goto out_err;
365
366 switch (cfg_mode) {
367 case GPIO_CFG_DRYRUN:
Magnus Damm18925e12011-12-14 01:00:55 +0900368 if (!*cntp ||
Laurent Pinchart4aeacd52012-12-15 23:50:53 +0100369 (sh_pfc_read_config_reg(pfc, cr, field) != value))
Magnus Damm2967dab2008-10-08 20:41:43 +0900370 continue;
371 break;
372
373 case GPIO_CFG_REQ:
Laurent Pinchart4aeacd52012-12-15 23:50:53 +0100374 sh_pfc_write_config_reg(pfc, cr, field, value);
Magnus Damm2967dab2008-10-08 20:41:43 +0900375 *cntp = *cntp + 1;
376 break;
377
378 case GPIO_CFG_FREE:
379 *cntp = *cntp - 1;
380 break;
381 }
382 }
383
384 return 0;
385 out_err:
386 return -1;
387}
388
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100389static int sh_pfc_probe(struct platform_device *pdev)
Magnus Damm2967dab2008-10-08 20:41:43 +0900390{
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100391 struct sh_pfc_soc_info *info;
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100392 struct sh_pfc *pfc;
Magnus Damm0fc64cc2008-12-25 18:17:18 +0900393 int ret;
Magnus Damm2967dab2008-10-08 20:41:43 +0900394
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100395 info = pdev->id_entry->driver_data
396 ? (void *)pdev->id_entry->driver_data : pdev->dev.platform_data;
397 if (info == NULL)
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100398 return -ENODEV;
Magnus Damm0fc64cc2008-12-25 18:17:18 +0900399
Magnus Damm8c43fcc2013-02-14 21:23:47 +0900400 pfc = devm_kzalloc(&pdev->dev, sizeof(*pfc), GFP_KERNEL);
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100401 if (pfc == NULL)
402 return -ENOMEM;
Magnus Dammb0e10212011-12-09 12:14:27 +0900403
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100404 pfc->info = info;
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100405 pfc->dev = &pdev->dev;
406
Laurent Pinchart973931a2012-12-15 23:50:55 +0100407 ret = sh_pfc_ioremap(pfc, pdev);
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100408 if (unlikely(ret < 0))
Laurent Pinchartd4e62d02012-12-15 23:50:43 +0100409 return ret;
Laurent Pinchartd4e62d02012-12-15 23:50:43 +0100410
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100411 spin_lock_init(&pfc->lock);
Magnus Damm69edbba2008-12-25 18:17:34 +0900412
Paul Mundtca5481c62012-07-10 12:08:14 +0900413 pinctrl_provide_dummies();
Magnus Damm69edbba2008-12-25 18:17:34 +0900414
Paul Mundtca5481c62012-07-10 12:08:14 +0900415 /*
416 * Initialize pinctrl bindings first
417 */
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100418 ret = sh_pfc_register_pinctrl(pfc);
Laurent Pinchartf9492fd2012-12-15 23:50:45 +0100419 if (unlikely(ret != 0))
Laurent Pinchartc9fa88e2012-12-15 23:50:49 +0100420 return ret;
Magnus Damm69edbba2008-12-25 18:17:34 +0900421
Laurent Pinchart6f6a4a62012-12-15 23:50:46 +0100422#ifdef CONFIG_GPIO_SH_PFC
Paul Mundtca5481c62012-07-10 12:08:14 +0900423 /*
424 * Then the GPIO chip
425 */
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100426 ret = sh_pfc_register_gpiochip(pfc);
Laurent Pinchart6f6a4a62012-12-15 23:50:46 +0100427 if (unlikely(ret != 0)) {
Paul Mundtca5481c62012-07-10 12:08:14 +0900428 /*
429 * If the GPIO chip fails to come up we still leave the
430 * PFC state as it is, given that there are already
431 * extant users of it that have succeeded by this point.
432 */
Laurent Pinchart6f6a4a62012-12-15 23:50:46 +0100433 pr_notice("failed to init GPIO chip, ignoring...\n");
Paul Mundtca5481c62012-07-10 12:08:14 +0900434 }
Laurent Pinchart6f6a4a62012-12-15 23:50:46 +0100435#endif
Paul Mundtca5481c62012-07-10 12:08:14 +0900436
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100437 platform_set_drvdata(pdev, pfc);
438
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100439 pr_info("%s support registered\n", info->name);
Paul Mundtca5481c62012-07-10 12:08:14 +0900440
Paul Mundtb3c185a2012-06-20 17:29:04 +0900441 return 0;
Paul Mundtb72421d2010-10-04 03:54:56 +0900442}
Laurent Pinchart6f6a4a62012-12-15 23:50:46 +0100443
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100444static int sh_pfc_remove(struct platform_device *pdev)
445{
446 struct sh_pfc *pfc = platform_get_drvdata(pdev);
447
448#ifdef CONFIG_GPIO_SH_PFC
449 sh_pfc_unregister_gpiochip(pfc);
450#endif
451 sh_pfc_unregister_pinctrl(pfc);
452
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100453 platform_set_drvdata(pdev, NULL);
454
455 return 0;
456}
457
458static const struct platform_device_id sh_pfc_id_table[] = {
Laurent Pinchartd5b15212012-12-15 23:51:21 +0100459#ifdef CONFIG_PINCTRL_PFC_R8A7740
460 { "pfc-r8a7740", (kernel_ulong_t)&r8a7740_pinmux_info },
461#endif
Laurent Pinchart881023d2012-12-15 23:51:22 +0100462#ifdef CONFIG_PINCTRL_PFC_R8A7779
463 { "pfc-r8a7779", (kernel_ulong_t)&r8a7779_pinmux_info },
464#endif
Laurent Pinchartccda5522012-12-15 23:51:29 +0100465#ifdef CONFIG_PINCTRL_PFC_SH7203
466 { "pfc-sh7203", (kernel_ulong_t)&sh7203_pinmux_info },
467#endif
Laurent Pincharta8d42fc2012-12-15 23:51:30 +0100468#ifdef CONFIG_PINCTRL_PFC_SH7264
469 { "pfc-sh7264", (kernel_ulong_t)&sh7264_pinmux_info },
470#endif
Laurent Pinchartf5e811f2012-12-15 23:51:31 +0100471#ifdef CONFIG_PINCTRL_PFC_SH7269
472 { "pfc-sh7269", (kernel_ulong_t)&sh7269_pinmux_info },
473#endif
Laurent Pinchart6e5469a2012-12-15 23:51:23 +0100474#ifdef CONFIG_PINCTRL_PFC_SH7372
475 { "pfc-sh7372", (kernel_ulong_t)&sh7372_pinmux_info },
476#endif
Laurent Pinchart5d5166d2012-12-15 23:51:24 +0100477#ifdef CONFIG_PINCTRL_PFC_SH73A0
478 { "pfc-sh73a0", (kernel_ulong_t)&sh73a0_pinmux_info },
479#endif
Laurent Pinchart74cad602012-12-15 23:51:32 +0100480#ifdef CONFIG_PINCTRL_PFC_SH7720
481 { "pfc-sh7720", (kernel_ulong_t)&sh7720_pinmux_info },
482#endif
Laurent Pinchartf5e25ae2012-12-15 23:51:33 +0100483#ifdef CONFIG_PINCTRL_PFC_SH7722
484 { "pfc-sh7722", (kernel_ulong_t)&sh7722_pinmux_info },
485#endif
Laurent Pinchartd05afa02012-12-15 23:51:34 +0100486#ifdef CONFIG_PINCTRL_PFC_SH7723
487 { "pfc-sh7723", (kernel_ulong_t)&sh7723_pinmux_info },
488#endif
Laurent Pinchart0ff25ba2012-12-15 23:51:35 +0100489#ifdef CONFIG_PINCTRL_PFC_SH7724
490 { "pfc-sh7724", (kernel_ulong_t)&sh7724_pinmux_info },
491#endif
Laurent Pinchartac1ebc22012-12-15 23:51:36 +0100492#ifdef CONFIG_PINCTRL_PFC_SH7734
493 { "pfc-sh7734", (kernel_ulong_t)&sh7734_pinmux_info },
494#endif
Laurent Pinchart0bb92672012-12-15 23:51:37 +0100495#ifdef CONFIG_PINCTRL_PFC_SH7757
496 { "pfc-sh7757", (kernel_ulong_t)&sh7757_pinmux_info },
497#endif
Laurent Pincharta56398e2012-12-15 23:51:38 +0100498#ifdef CONFIG_PINCTRL_PFC_SH7785
499 { "pfc-sh7785", (kernel_ulong_t)&sh7785_pinmux_info },
500#endif
Laurent Pinchartd2a31bd2012-12-15 23:51:39 +0100501#ifdef CONFIG_PINCTRL_PFC_SH7786
502 { "pfc-sh7786", (kernel_ulong_t)&sh7786_pinmux_info },
503#endif
Laurent Pinchartd5d9a812012-12-15 23:51:40 +0100504#ifdef CONFIG_PINCTRL_PFC_SHX3
505 { "pfc-shx3", (kernel_ulong_t)&shx3_pinmux_info },
506#endif
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100507 { "sh-pfc", 0 },
508 { },
509};
510MODULE_DEVICE_TABLE(platform, sh_pfc_id_table);
511
512static struct platform_driver sh_pfc_driver = {
513 .probe = sh_pfc_probe,
514 .remove = sh_pfc_remove,
515 .id_table = sh_pfc_id_table,
516 .driver = {
517 .name = DRV_NAME,
518 .owner = THIS_MODULE,
519 },
520};
521
Laurent Pinchart40ee6fc2012-12-15 23:50:54 +0100522static int __init sh_pfc_init(void)
523{
524 return platform_driver_register(&sh_pfc_driver);
525}
526postcore_initcall(sh_pfc_init);
527
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100528static void __exit sh_pfc_exit(void)
529{
530 platform_driver_unregister(&sh_pfc_driver);
531}
532module_exit(sh_pfc_exit);
533
Laurent Pinchart6f6a4a62012-12-15 23:50:46 +0100534MODULE_AUTHOR("Magnus Damm, Paul Mundt, Laurent Pinchart");
535MODULE_DESCRIPTION("Pin Control and GPIO driver for SuperH pin function controller");
536MODULE_LICENSE("GPL v2");