blob: 49fde283decd34b7a005af44fdb0a495b6acf390 [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 Pinchart56dc04a2012-12-15 23:51:18 +010033 if (pdev->num_resources == 0) {
Laurent Pinchart973931a2012-12-15 23:50:55 +010034 pfc->num_windows = 0;
35 return 0;
36 }
37
Laurent Pinchart56dc04a2012-12-15 23:51:18 +010038 pfc->window = devm_kzalloc(pfc->dev, pdev->num_resources *
Laurent Pinchart1724acf2012-12-15 23:50:48 +010039 sizeof(*pfc->window), GFP_NOWAIT);
Paul Mundtb3c185a2012-06-20 17:29:04 +090040 if (!pfc->window)
Laurent Pinchart1724acf2012-12-15 23:50:48 +010041 return -ENOMEM;
Magnus Dammb0e10212011-12-09 12:14:27 +090042
Laurent Pinchart56dc04a2012-12-15 23:51:18 +010043 pfc->num_windows = pdev->num_resources;
Laurent Pinchart973931a2012-12-15 23:50:55 +010044
Laurent Pinchart56dc04a2012-12-15 23:51:18 +010045 for (k = 0, res = pdev->resource; k < pdev->num_resources; k++, res++) {
Magnus Dammb0e10212011-12-09 12:14:27 +090046 WARN_ON(resource_type(res) != IORESOURCE_MEM);
Paul Mundtb3c185a2012-06-20 17:29:04 +090047 pfc->window[k].phys = res->start;
48 pfc->window[k].size = resource_size(res);
Laurent Pinchartc9fa88e2012-12-15 23:50:49 +010049 pfc->window[k].virt = devm_ioremap_nocache(pfc->dev, res->start,
50 resource_size(res));
51 if (!pfc->window[k].virt)
Laurent Pinchart1724acf2012-12-15 23:50:48 +010052 return -ENOMEM;
Magnus Dammb0e10212011-12-09 12:14:27 +090053 }
54
55 return 0;
Magnus Dammb0e10212011-12-09 12:14:27 +090056}
57
Laurent Pinchart41f12192013-02-15 02:04:55 +010058void __iomem *sh_pfc_phys_to_virt(struct sh_pfc *pfc, unsigned long address)
Magnus Dammb0e10212011-12-09 12:14:27 +090059{
Laurent Pinchart4aeacd52012-12-15 23:50:53 +010060 struct sh_pfc_window *window;
Magnus Dammb0e10212011-12-09 12:14:27 +090061 int k;
62
63 /* scan through physical windows and convert address */
Laurent Pinchart973931a2012-12-15 23:50:55 +010064 for (k = 0; k < pfc->num_windows; k++) {
Paul Mundtb3c185a2012-06-20 17:29:04 +090065 window = pfc->window + k;
Magnus Dammb0e10212011-12-09 12:14:27 +090066
67 if (address < window->phys)
68 continue;
69
70 if (address >= (window->phys + window->size))
71 continue;
72
73 return window->virt + (address - window->phys);
74 }
75
76 /* no windows defined, register must be 1:1 mapped virt:phys */
77 return (void __iomem *)address;
78}
Magnus Damm2967dab2008-10-08 20:41:43 +090079
Laurent Pinchart934cb022013-02-14 22:35:09 +010080struct sh_pfc_pin *sh_pfc_get_pin(struct sh_pfc *pfc, unsigned int pin)
81{
Laurent Pinchart63d57382013-02-15 01:33:38 +010082 unsigned int offset;
83 unsigned int i;
84
85 if (pfc->info->ranges == NULL)
86 return &pfc->info->pins[pin];
87
88 for (i = 0, offset = 0; i < pfc->info->nr_ranges; ++i) {
89 const struct pinmux_range *range = &pfc->info->ranges[i];
90
91 if (pin <= range->end)
92 return pin >= range->begin
93 ? &pfc->info->pins[offset + pin - range->begin]
94 : NULL;
95
96 offset += range->end - range->begin + 1;
97 }
98
99 return NULL;
Laurent Pinchart934cb022013-02-14 22:35:09 +0100100}
101
Laurent Pinchart4aeacd52012-12-15 23:50:53 +0100102static int sh_pfc_enum_in_range(pinmux_enum_t enum_id, struct pinmux_range *r)
Magnus Damm2967dab2008-10-08 20:41:43 +0900103{
104 if (enum_id < r->begin)
105 return 0;
106
107 if (enum_id > r->end)
108 return 0;
109
110 return 1;
111}
112
Laurent Pinchart41f12192013-02-15 02:04:55 +0100113unsigned long sh_pfc_read_raw_reg(void __iomem *mapped_reg,
114 unsigned long reg_width)
Magnus Damm32920942008-12-25 18:17:26 +0900115{
116 switch (reg_width) {
117 case 8:
Magnus Dammb0e10212011-12-09 12:14:27 +0900118 return ioread8(mapped_reg);
Magnus Damm32920942008-12-25 18:17:26 +0900119 case 16:
Magnus Dammb0e10212011-12-09 12:14:27 +0900120 return ioread16(mapped_reg);
Magnus Damm32920942008-12-25 18:17:26 +0900121 case 32:
Magnus Dammb0e10212011-12-09 12:14:27 +0900122 return ioread32(mapped_reg);
Magnus Damm32920942008-12-25 18:17:26 +0900123 }
124
125 BUG();
126 return 0;
127}
128
Laurent Pinchart41f12192013-02-15 02:04:55 +0100129void sh_pfc_write_raw_reg(void __iomem *mapped_reg, unsigned long reg_width,
130 unsigned long data)
Magnus Damm32920942008-12-25 18:17:26 +0900131{
132 switch (reg_width) {
133 case 8:
Magnus Dammb0e10212011-12-09 12:14:27 +0900134 iowrite8(data, mapped_reg);
Magnus Damm32920942008-12-25 18:17:26 +0900135 return;
136 case 16:
Magnus Dammb0e10212011-12-09 12:14:27 +0900137 iowrite16(data, mapped_reg);
Magnus Damm32920942008-12-25 18:17:26 +0900138 return;
139 case 32:
Magnus Dammb0e10212011-12-09 12:14:27 +0900140 iowrite32(data, mapped_reg);
Magnus Damm32920942008-12-25 18:17:26 +0900141 return;
142 }
143
144 BUG();
145}
146
Laurent Pinchart4aeacd52012-12-15 23:50:53 +0100147static void sh_pfc_config_reg_helper(struct sh_pfc *pfc,
148 struct pinmux_cfg_reg *crp,
149 unsigned long in_pos,
150 void __iomem **mapped_regp,
151 unsigned long *maskp,
152 unsigned long *posp)
Magnus Damm2967dab2008-10-08 20:41:43 +0900153{
Magnus Dammf78a26f2011-12-14 01:01:05 +0900154 int k;
155
Laurent Pinchart4aeacd52012-12-15 23:50:53 +0100156 *mapped_regp = sh_pfc_phys_to_virt(pfc, crp->reg);
Magnus Damm2967dab2008-10-08 20:41:43 +0900157
Magnus Dammf78a26f2011-12-14 01:01:05 +0900158 if (crp->field_width) {
159 *maskp = (1 << crp->field_width) - 1;
160 *posp = crp->reg_width - ((in_pos + 1) * crp->field_width);
161 } else {
162 *maskp = (1 << crp->var_field_width[in_pos]) - 1;
163 *posp = crp->reg_width;
164 for (k = 0; k <= in_pos; k++)
165 *posp -= crp->var_field_width[k];
166 }
Magnus Damm0fc64cc2008-12-25 18:17:18 +0900167}
Magnus Damm2967dab2008-10-08 20:41:43 +0900168
Laurent Pinchart4aeacd52012-12-15 23:50:53 +0100169static int sh_pfc_read_config_reg(struct sh_pfc *pfc,
170 struct pinmux_cfg_reg *crp,
171 unsigned long field)
Magnus Damm0fc64cc2008-12-25 18:17:18 +0900172{
Magnus Damm18925e12011-12-14 01:00:55 +0900173 void __iomem *mapped_reg;
Magnus Damm0fc64cc2008-12-25 18:17:18 +0900174 unsigned long mask, pos;
175
Laurent Pinchart4aeacd52012-12-15 23:50:53 +0100176 sh_pfc_config_reg_helper(pfc, crp, field, &mapped_reg, &mask, &pos);
Magnus Damm0fc64cc2008-12-25 18:17:18 +0900177
Magnus Damm18925e12011-12-14 01:00:55 +0900178 pr_debug("read_reg: addr = %lx, field = %ld, "
Paul Mundtfd2cb0c2009-11-30 12:15:04 +0900179 "r_width = %ld, f_width = %ld\n",
Magnus Damm18925e12011-12-14 01:00:55 +0900180 crp->reg, field, crp->reg_width, crp->field_width);
181
Laurent Pinchart4aeacd52012-12-15 23:50:53 +0100182 return (sh_pfc_read_raw_reg(mapped_reg, crp->reg_width) >> pos) & mask;
Magnus Damm18925e12011-12-14 01:00:55 +0900183}
184
Laurent Pinchart4aeacd52012-12-15 23:50:53 +0100185static void sh_pfc_write_config_reg(struct sh_pfc *pfc,
186 struct pinmux_cfg_reg *crp,
187 unsigned long field, unsigned long value)
Magnus Damm18925e12011-12-14 01:00:55 +0900188{
189 void __iomem *mapped_reg;
Magnus Damme499ada2011-12-14 01:01:14 +0900190 unsigned long mask, pos, data;
Magnus Damm18925e12011-12-14 01:00:55 +0900191
Laurent Pinchart4aeacd52012-12-15 23:50:53 +0100192 sh_pfc_config_reg_helper(pfc, crp, field, &mapped_reg, &mask, &pos);
Magnus Damm18925e12011-12-14 01:00:55 +0900193
194 pr_debug("write_reg addr = %lx, value = %ld, field = %ld, "
195 "r_width = %ld, f_width = %ld\n",
196 crp->reg, value, field, crp->reg_width, crp->field_width);
Magnus Damm0fc64cc2008-12-25 18:17:18 +0900197
198 mask = ~(mask << pos);
199 value = value << pos;
Magnus Damm2967dab2008-10-08 20:41:43 +0900200
Laurent Pinchart4aeacd52012-12-15 23:50:53 +0100201 data = sh_pfc_read_raw_reg(mapped_reg, crp->reg_width);
Magnus Damme499ada2011-12-14 01:01:14 +0900202 data &= mask;
203 data |= value;
204
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100205 if (pfc->info->unlock_reg)
Laurent Pinchart4aeacd52012-12-15 23:50:53 +0100206 sh_pfc_write_raw_reg(
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100207 sh_pfc_phys_to_virt(pfc, pfc->info->unlock_reg), 32,
Laurent Pinchart4aeacd52012-12-15 23:50:53 +0100208 ~data);
Magnus Damme499ada2011-12-14 01:01:14 +0900209
Laurent Pinchart4aeacd52012-12-15 23:50:53 +0100210 sh_pfc_write_raw_reg(mapped_reg, crp->reg_width, data);
Magnus Damm2967dab2008-10-08 20:41:43 +0900211}
212
Laurent Pinchart4aeacd52012-12-15 23:50:53 +0100213static int sh_pfc_get_config_reg(struct sh_pfc *pfc, pinmux_enum_t enum_id,
214 struct pinmux_cfg_reg **crp, int *fieldp,
215 int *valuep, unsigned long **cntp)
Magnus Damm2967dab2008-10-08 20:41:43 +0900216{
217 struct pinmux_cfg_reg *config_reg;
Magnus Dammf78a26f2011-12-14 01:01:05 +0900218 unsigned long r_width, f_width, curr_width, ncomb;
219 int k, m, n, pos, bit_pos;
Magnus Damm2967dab2008-10-08 20:41:43 +0900220
221 k = 0;
222 while (1) {
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100223 config_reg = pfc->info->cfg_regs + k;
Magnus Damm2967dab2008-10-08 20:41:43 +0900224
225 r_width = config_reg->reg_width;
226 f_width = config_reg->field_width;
227
228 if (!r_width)
229 break;
Magnus Dammf78a26f2011-12-14 01:01:05 +0900230
231 pos = 0;
232 m = 0;
233 for (bit_pos = 0; bit_pos < r_width; bit_pos += curr_width) {
234 if (f_width)
235 curr_width = f_width;
236 else
237 curr_width = config_reg->var_field_width[m];
238
239 ncomb = 1 << curr_width;
240 for (n = 0; n < ncomb; n++) {
241 if (config_reg->enum_ids[pos + n] == enum_id) {
242 *crp = config_reg;
243 *fieldp = m;
244 *valuep = n;
245 *cntp = &config_reg->cnt[m];
246 return 0;
247 }
Magnus Damm2967dab2008-10-08 20:41:43 +0900248 }
Magnus Dammf78a26f2011-12-14 01:01:05 +0900249 pos += ncomb;
250 m++;
Magnus Damm2967dab2008-10-08 20:41:43 +0900251 }
252 k++;
253 }
254
255 return -1;
256}
257
Laurent Pincharta68fdca92013-02-14 17:36:56 +0100258static int sh_pfc_mark_to_enum(struct sh_pfc *pfc, pinmux_enum_t mark, int pos,
259 pinmux_enum_t *enum_idp)
Magnus Damm2967dab2008-10-08 20:41:43 +0900260{
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100261 pinmux_enum_t *data = pfc->info->gpio_data;
Magnus Damm2967dab2008-10-08 20:41:43 +0900262 int k;
263
Magnus Damm2967dab2008-10-08 20:41:43 +0900264 if (pos) {
265 *enum_idp = data[pos + 1];
266 return pos + 1;
267 }
268
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100269 for (k = 0; k < pfc->info->gpio_data_size; k++) {
Laurent Pincharta68fdca92013-02-14 17:36:56 +0100270 if (data[k] == mark) {
Magnus Damm2967dab2008-10-08 20:41:43 +0900271 *enum_idp = data[k + 1];
272 return k + 1;
273 }
274 }
275
Laurent Pincharta68fdca92013-02-14 17:36:56 +0100276 pr_err("cannot locate data/mark enum_id for mark %d\n", mark);
Magnus Damm2967dab2008-10-08 20:41:43 +0900277 return -1;
278}
279
Laurent Pincharta68fdca92013-02-14 17:36:56 +0100280int sh_pfc_config_mux(struct sh_pfc *pfc, unsigned mark, int pinmux_type,
281 int cfg_mode)
Magnus Damm2967dab2008-10-08 20:41:43 +0900282{
283 struct pinmux_cfg_reg *cr = NULL;
284 pinmux_enum_t enum_id;
285 struct pinmux_range *range;
Magnus Dammad4a07f2011-12-14 01:00:46 +0900286 int in_range, pos, field, value;
Magnus Damm2967dab2008-10-08 20:41:43 +0900287 unsigned long *cntp;
288
289 switch (pinmux_type) {
290
291 case PINMUX_TYPE_FUNCTION:
292 range = NULL;
293 break;
294
295 case PINMUX_TYPE_OUTPUT:
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100296 range = &pfc->info->output;
Magnus Damm2967dab2008-10-08 20:41:43 +0900297 break;
298
299 case PINMUX_TYPE_INPUT:
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100300 range = &pfc->info->input;
Magnus Damm2967dab2008-10-08 20:41:43 +0900301 break;
302
303 case PINMUX_TYPE_INPUT_PULLUP:
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100304 range = &pfc->info->input_pu;
Magnus Damm2967dab2008-10-08 20:41:43 +0900305 break;
306
307 case PINMUX_TYPE_INPUT_PULLDOWN:
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100308 range = &pfc->info->input_pd;
Magnus Damm2967dab2008-10-08 20:41:43 +0900309 break;
310
311 default:
312 goto out_err;
313 }
314
315 pos = 0;
316 enum_id = 0;
Magnus Dammad4a07f2011-12-14 01:00:46 +0900317 field = 0;
318 value = 0;
Magnus Damm2967dab2008-10-08 20:41:43 +0900319 while (1) {
Laurent Pincharta68fdca92013-02-14 17:36:56 +0100320 pos = sh_pfc_mark_to_enum(pfc, mark, pos, &enum_id);
Magnus Damm2967dab2008-10-08 20:41:43 +0900321 if (pos <= 0)
322 goto out_err;
323
324 if (!enum_id)
325 break;
326
Magnus Damm50dd3142010-01-19 13:52:28 +0000327 /* first check if this is a function enum */
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100328 in_range = sh_pfc_enum_in_range(enum_id, &pfc->info->function);
Magnus Damm50dd3142010-01-19 13:52:28 +0000329 if (!in_range) {
330 /* not a function enum */
331 if (range) {
332 /*
333 * other range exists, so this pin is
334 * a regular GPIO pin that now is being
335 * bound to a specific direction.
336 *
337 * for this case we only allow function enums
338 * and the enums that match the other range.
339 */
Laurent Pinchart4aeacd52012-12-15 23:50:53 +0100340 in_range = sh_pfc_enum_in_range(enum_id, range);
Magnus Damm2967dab2008-10-08 20:41:43 +0900341
Magnus Damm50dd3142010-01-19 13:52:28 +0000342 /*
343 * special case pass through for fixed
344 * input-only or output-only pins without
345 * function enum register association.
346 */
347 if (in_range && enum_id == range->force)
348 continue;
349 } else {
350 /*
351 * no other range exists, so this pin
352 * must then be of the function type.
353 *
354 * allow function type pins to select
355 * any combination of function/in/out
356 * in their MARK lists.
357 */
358 in_range = 1;
359 }
Magnus Damm42eed422008-10-22 18:29:17 +0900360 }
361
Magnus Damm2967dab2008-10-08 20:41:43 +0900362 if (!in_range)
363 continue;
364
Laurent Pinchart4aeacd52012-12-15 23:50:53 +0100365 if (sh_pfc_get_config_reg(pfc, enum_id, &cr,
366 &field, &value, &cntp) != 0)
Magnus Damm2967dab2008-10-08 20:41:43 +0900367 goto out_err;
368
369 switch (cfg_mode) {
370 case GPIO_CFG_DRYRUN:
Magnus Damm18925e12011-12-14 01:00:55 +0900371 if (!*cntp ||
Laurent Pinchart4aeacd52012-12-15 23:50:53 +0100372 (sh_pfc_read_config_reg(pfc, cr, field) != value))
Magnus Damm2967dab2008-10-08 20:41:43 +0900373 continue;
374 break;
375
376 case GPIO_CFG_REQ:
Laurent Pinchart4aeacd52012-12-15 23:50:53 +0100377 sh_pfc_write_config_reg(pfc, cr, field, value);
Magnus Damm2967dab2008-10-08 20:41:43 +0900378 *cntp = *cntp + 1;
379 break;
380
381 case GPIO_CFG_FREE:
382 *cntp = *cntp - 1;
383 break;
384 }
385 }
386
387 return 0;
388 out_err:
389 return -1;
390}
391
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100392static int sh_pfc_probe(struct platform_device *pdev)
Magnus Damm2967dab2008-10-08 20:41:43 +0900393{
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100394 struct sh_pfc_soc_info *info;
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100395 struct sh_pfc *pfc;
Magnus Damm0fc64cc2008-12-25 18:17:18 +0900396 int ret;
Magnus Damm2967dab2008-10-08 20:41:43 +0900397
Paul Mundt06d56312012-06-21 00:03:41 +0900398 /*
399 * Ensure that the type encoding fits
400 */
401 BUILD_BUG_ON(PINMUX_FLAG_TYPE > ((1 << PINMUX_FLAG_DBIT_SHIFT) - 1));
402
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100403 info = pdev->id_entry->driver_data
404 ? (void *)pdev->id_entry->driver_data : pdev->dev.platform_data;
405 if (info == NULL)
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100406 return -ENODEV;
Magnus Damm0fc64cc2008-12-25 18:17:18 +0900407
Magnus Damm8c43fcc2013-02-14 21:23:47 +0900408 pfc = devm_kzalloc(&pdev->dev, sizeof(*pfc), GFP_KERNEL);
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100409 if (pfc == NULL)
410 return -ENOMEM;
Magnus Dammb0e10212011-12-09 12:14:27 +0900411
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100412 pfc->info = info;
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100413 pfc->dev = &pdev->dev;
414
Laurent Pinchart973931a2012-12-15 23:50:55 +0100415 ret = sh_pfc_ioremap(pfc, pdev);
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100416 if (unlikely(ret < 0))
Laurent Pinchartd4e62d02012-12-15 23:50:43 +0100417 return ret;
Laurent Pinchartd4e62d02012-12-15 23:50:43 +0100418
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100419 spin_lock_init(&pfc->lock);
Magnus Damm69edbba2008-12-25 18:17:34 +0900420
Paul Mundtca5481c62012-07-10 12:08:14 +0900421 pinctrl_provide_dummies();
Magnus Damm69edbba2008-12-25 18:17:34 +0900422
Paul Mundtca5481c62012-07-10 12:08:14 +0900423 /*
424 * Initialize pinctrl bindings first
425 */
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100426 ret = sh_pfc_register_pinctrl(pfc);
Laurent Pinchartf9492fd2012-12-15 23:50:45 +0100427 if (unlikely(ret != 0))
Laurent Pinchartc9fa88e2012-12-15 23:50:49 +0100428 return ret;
Magnus Damm69edbba2008-12-25 18:17:34 +0900429
Laurent Pinchart6f6a4a62012-12-15 23:50:46 +0100430#ifdef CONFIG_GPIO_SH_PFC
Paul Mundtca5481c62012-07-10 12:08:14 +0900431 /*
432 * Then the GPIO chip
433 */
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100434 ret = sh_pfc_register_gpiochip(pfc);
Laurent Pinchart6f6a4a62012-12-15 23:50:46 +0100435 if (unlikely(ret != 0)) {
Paul Mundtca5481c62012-07-10 12:08:14 +0900436 /*
437 * If the GPIO chip fails to come up we still leave the
438 * PFC state as it is, given that there are already
439 * extant users of it that have succeeded by this point.
440 */
Laurent Pinchart6f6a4a62012-12-15 23:50:46 +0100441 pr_notice("failed to init GPIO chip, ignoring...\n");
Paul Mundtca5481c62012-07-10 12:08:14 +0900442 }
Laurent Pinchart6f6a4a62012-12-15 23:50:46 +0100443#endif
Paul Mundtca5481c62012-07-10 12:08:14 +0900444
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100445 platform_set_drvdata(pdev, pfc);
446
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100447 pr_info("%s support registered\n", info->name);
Paul Mundtca5481c62012-07-10 12:08:14 +0900448
Paul Mundtb3c185a2012-06-20 17:29:04 +0900449 return 0;
Paul Mundtb72421d2010-10-04 03:54:56 +0900450}
Laurent Pinchart6f6a4a62012-12-15 23:50:46 +0100451
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100452static int sh_pfc_remove(struct platform_device *pdev)
453{
454 struct sh_pfc *pfc = platform_get_drvdata(pdev);
455
456#ifdef CONFIG_GPIO_SH_PFC
457 sh_pfc_unregister_gpiochip(pfc);
458#endif
459 sh_pfc_unregister_pinctrl(pfc);
460
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100461 platform_set_drvdata(pdev, NULL);
462
463 return 0;
464}
465
466static const struct platform_device_id sh_pfc_id_table[] = {
Laurent Pinchartd5b15212012-12-15 23:51:21 +0100467#ifdef CONFIG_PINCTRL_PFC_R8A7740
468 { "pfc-r8a7740", (kernel_ulong_t)&r8a7740_pinmux_info },
469#endif
Laurent Pinchart881023d2012-12-15 23:51:22 +0100470#ifdef CONFIG_PINCTRL_PFC_R8A7779
471 { "pfc-r8a7779", (kernel_ulong_t)&r8a7779_pinmux_info },
472#endif
Laurent Pinchartccda5522012-12-15 23:51:29 +0100473#ifdef CONFIG_PINCTRL_PFC_SH7203
474 { "pfc-sh7203", (kernel_ulong_t)&sh7203_pinmux_info },
475#endif
Laurent Pincharta8d42fc2012-12-15 23:51:30 +0100476#ifdef CONFIG_PINCTRL_PFC_SH7264
477 { "pfc-sh7264", (kernel_ulong_t)&sh7264_pinmux_info },
478#endif
Laurent Pinchartf5e811f2012-12-15 23:51:31 +0100479#ifdef CONFIG_PINCTRL_PFC_SH7269
480 { "pfc-sh7269", (kernel_ulong_t)&sh7269_pinmux_info },
481#endif
Laurent Pinchart6e5469a2012-12-15 23:51:23 +0100482#ifdef CONFIG_PINCTRL_PFC_SH7372
483 { "pfc-sh7372", (kernel_ulong_t)&sh7372_pinmux_info },
484#endif
Laurent Pinchart5d5166d2012-12-15 23:51:24 +0100485#ifdef CONFIG_PINCTRL_PFC_SH73A0
486 { "pfc-sh73a0", (kernel_ulong_t)&sh73a0_pinmux_info },
487#endif
Laurent Pinchart74cad602012-12-15 23:51:32 +0100488#ifdef CONFIG_PINCTRL_PFC_SH7720
489 { "pfc-sh7720", (kernel_ulong_t)&sh7720_pinmux_info },
490#endif
Laurent Pinchartf5e25ae2012-12-15 23:51:33 +0100491#ifdef CONFIG_PINCTRL_PFC_SH7722
492 { "pfc-sh7722", (kernel_ulong_t)&sh7722_pinmux_info },
493#endif
Laurent Pinchartd05afa02012-12-15 23:51:34 +0100494#ifdef CONFIG_PINCTRL_PFC_SH7723
495 { "pfc-sh7723", (kernel_ulong_t)&sh7723_pinmux_info },
496#endif
Laurent Pinchart0ff25ba2012-12-15 23:51:35 +0100497#ifdef CONFIG_PINCTRL_PFC_SH7724
498 { "pfc-sh7724", (kernel_ulong_t)&sh7724_pinmux_info },
499#endif
Laurent Pinchartac1ebc22012-12-15 23:51:36 +0100500#ifdef CONFIG_PINCTRL_PFC_SH7734
501 { "pfc-sh7734", (kernel_ulong_t)&sh7734_pinmux_info },
502#endif
Laurent Pinchart0bb92672012-12-15 23:51:37 +0100503#ifdef CONFIG_PINCTRL_PFC_SH7757
504 { "pfc-sh7757", (kernel_ulong_t)&sh7757_pinmux_info },
505#endif
Laurent Pincharta56398e2012-12-15 23:51:38 +0100506#ifdef CONFIG_PINCTRL_PFC_SH7785
507 { "pfc-sh7785", (kernel_ulong_t)&sh7785_pinmux_info },
508#endif
Laurent Pinchartd2a31bd2012-12-15 23:51:39 +0100509#ifdef CONFIG_PINCTRL_PFC_SH7786
510 { "pfc-sh7786", (kernel_ulong_t)&sh7786_pinmux_info },
511#endif
Laurent Pinchartd5d9a812012-12-15 23:51:40 +0100512#ifdef CONFIG_PINCTRL_PFC_SHX3
513 { "pfc-shx3", (kernel_ulong_t)&shx3_pinmux_info },
514#endif
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100515 { "sh-pfc", 0 },
516 { },
517};
518MODULE_DEVICE_TABLE(platform, sh_pfc_id_table);
519
520static struct platform_driver sh_pfc_driver = {
521 .probe = sh_pfc_probe,
522 .remove = sh_pfc_remove,
523 .id_table = sh_pfc_id_table,
524 .driver = {
525 .name = DRV_NAME,
526 .owner = THIS_MODULE,
527 },
528};
529
Laurent Pinchart40ee6fc2012-12-15 23:50:54 +0100530static int __init sh_pfc_init(void)
531{
532 return platform_driver_register(&sh_pfc_driver);
533}
534postcore_initcall(sh_pfc_init);
535
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100536static void __exit sh_pfc_exit(void)
537{
538 platform_driver_unregister(&sh_pfc_driver);
539}
540module_exit(sh_pfc_exit);
541
Laurent Pinchart6f6a4a62012-12-15 23:50:46 +0100542MODULE_AUTHOR("Magnus Damm, Paul Mundt, Laurent Pinchart");
543MODULE_DESCRIPTION("Pin Control and GPIO driver for SuperH pin function controller");
544MODULE_LICENSE("GPL v2");