blob: 3b2fd43ff2944ced1e8af02f1c8da50728816d0b [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"
Paul Mundtb72421d2010-10-04 03:54:56 +090013
Magnus Damm2967dab2008-10-08 20:41:43 +090014#include <linux/bitops.h>
Laurent Pinchart90efde22012-12-15 23:50:52 +010015#include <linux/err.h>
16#include <linux/errno.h>
17#include <linux/io.h>
Magnus Dammb0e10212011-12-09 12:14:27 +090018#include <linux/ioport.h>
Laurent Pinchart90efde22012-12-15 23:50:52 +010019#include <linux/kernel.h>
20#include <linux/module.h>
Paul Mundtca5481c62012-07-10 12:08:14 +090021#include <linux/pinctrl/machine.h>
Laurent Pinchartc6193ea2012-12-15 23:50:47 +010022#include <linux/platform_device.h>
Laurent Pinchart90efde22012-12-15 23:50:52 +010023#include <linux/slab.h>
Magnus Dammb0e10212011-12-09 12:14:27 +090024
Laurent Pinchartf9165132012-12-15 23:50:44 +010025#include "core.h"
26
Laurent Pinchart973931a2012-12-15 23:50:55 +010027static int sh_pfc_ioremap(struct sh_pfc *pfc, struct platform_device *pdev)
Magnus Dammb0e10212011-12-09 12:14:27 +090028{
29 struct resource *res;
30 int k;
31
Laurent Pinchartbee9f222013-02-16 23:39:07 +010032 if (pdev->num_resources == 0)
33 return -EINVAL;
Laurent Pinchart973931a2012-12-15 23:50:55 +010034
Laurent Pinchart56dc04a2012-12-15 23:51:18 +010035 pfc->window = devm_kzalloc(pfc->dev, pdev->num_resources *
Laurent Pinchart1724acf2012-12-15 23:50:48 +010036 sizeof(*pfc->window), GFP_NOWAIT);
Paul Mundtb3c185a2012-06-20 17:29:04 +090037 if (!pfc->window)
Laurent Pinchart1724acf2012-12-15 23:50:48 +010038 return -ENOMEM;
Magnus Dammb0e10212011-12-09 12:14:27 +090039
Laurent Pinchart56dc04a2012-12-15 23:51:18 +010040 pfc->num_windows = pdev->num_resources;
Laurent Pinchart973931a2012-12-15 23:50:55 +010041
Laurent Pinchart56dc04a2012-12-15 23:51:18 +010042 for (k = 0, res = pdev->resource; k < pdev->num_resources; k++, res++) {
Magnus Dammb0e10212011-12-09 12:14:27 +090043 WARN_ON(resource_type(res) != IORESOURCE_MEM);
Paul Mundtb3c185a2012-06-20 17:29:04 +090044 pfc->window[k].phys = res->start;
45 pfc->window[k].size = resource_size(res);
Laurent Pinchartc9fa88e2012-12-15 23:50:49 +010046 pfc->window[k].virt = devm_ioremap_nocache(pfc->dev, res->start,
47 resource_size(res));
48 if (!pfc->window[k].virt)
Laurent Pinchart1724acf2012-12-15 23:50:48 +010049 return -ENOMEM;
Magnus Dammb0e10212011-12-09 12:14:27 +090050 }
51
52 return 0;
Magnus Dammb0e10212011-12-09 12:14:27 +090053}
54
Laurent Pincharte51d5342013-02-17 00:26:33 +010055static void __iomem *sh_pfc_phys_to_virt(struct sh_pfc *pfc,
56 unsigned long address)
Magnus Dammb0e10212011-12-09 12:14:27 +090057{
Laurent Pinchart4aeacd52012-12-15 23:50:53 +010058 struct sh_pfc_window *window;
Laurent Pinchartbee9f222013-02-16 23:39:07 +010059 unsigned int i;
Magnus Dammb0e10212011-12-09 12:14:27 +090060
61 /* scan through physical windows and convert address */
Laurent Pinchartbee9f222013-02-16 23:39:07 +010062 for (i = 0; i < pfc->num_windows; i++) {
63 window = pfc->window + i;
Magnus Dammb0e10212011-12-09 12:14:27 +090064
65 if (address < window->phys)
66 continue;
67
68 if (address >= (window->phys + window->size))
69 continue;
70
71 return window->virt + (address - window->phys);
72 }
73
Laurent Pinchartbee9f222013-02-16 23:39:07 +010074 BUG();
Laurent Pinchart1960d582013-03-26 01:44:52 +010075 return NULL;
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 Pinchartb705c052013-03-10 16:38:23 +010096 return -EINVAL;
Laurent Pinchart934cb022013-02-14 22:35:09 +010097}
98
Laurent Pinchartcd3c1be2013-02-16 18:47:05 +010099static int sh_pfc_enum_in_range(pinmux_enum_t enum_id,
100 const struct pinmux_range *r)
Magnus Damm2967dab2008-10-08 20:41:43 +0900101{
102 if (enum_id < r->begin)
103 return 0;
104
105 if (enum_id > r->end)
106 return 0;
107
108 return 1;
109}
110
Laurent Pinchart41f12192013-02-15 02:04:55 +0100111unsigned long sh_pfc_read_raw_reg(void __iomem *mapped_reg,
112 unsigned long reg_width)
Magnus Damm32920942008-12-25 18:17:26 +0900113{
114 switch (reg_width) {
115 case 8:
Magnus Dammb0e10212011-12-09 12:14:27 +0900116 return ioread8(mapped_reg);
Magnus Damm32920942008-12-25 18:17:26 +0900117 case 16:
Magnus Dammb0e10212011-12-09 12:14:27 +0900118 return ioread16(mapped_reg);
Magnus Damm32920942008-12-25 18:17:26 +0900119 case 32:
Magnus Dammb0e10212011-12-09 12:14:27 +0900120 return ioread32(mapped_reg);
Magnus Damm32920942008-12-25 18:17:26 +0900121 }
122
123 BUG();
124 return 0;
125}
126
Laurent Pinchart41f12192013-02-15 02:04:55 +0100127void sh_pfc_write_raw_reg(void __iomem *mapped_reg, unsigned long reg_width,
128 unsigned long data)
Magnus Damm32920942008-12-25 18:17:26 +0900129{
130 switch (reg_width) {
131 case 8:
Magnus Dammb0e10212011-12-09 12:14:27 +0900132 iowrite8(data, mapped_reg);
Magnus Damm32920942008-12-25 18:17:26 +0900133 return;
134 case 16:
Magnus Dammb0e10212011-12-09 12:14:27 +0900135 iowrite16(data, mapped_reg);
Magnus Damm32920942008-12-25 18:17:26 +0900136 return;
137 case 32:
Magnus Dammb0e10212011-12-09 12:14:27 +0900138 iowrite32(data, mapped_reg);
Magnus Damm32920942008-12-25 18:17:26 +0900139 return;
140 }
141
142 BUG();
143}
144
Laurent Pinchart4aeacd52012-12-15 23:50:53 +0100145static void sh_pfc_config_reg_helper(struct sh_pfc *pfc,
Laurent Pinchartcd3c1be2013-02-16 18:47:05 +0100146 const struct pinmux_cfg_reg *crp,
Laurent Pinchart4aeacd52012-12-15 23:50:53 +0100147 unsigned long in_pos,
148 void __iomem **mapped_regp,
149 unsigned long *maskp,
150 unsigned long *posp)
Magnus Damm2967dab2008-10-08 20:41:43 +0900151{
Magnus Dammf78a26f2011-12-14 01:01:05 +0900152 int k;
153
Laurent Pinchart4aeacd52012-12-15 23:50:53 +0100154 *mapped_regp = sh_pfc_phys_to_virt(pfc, crp->reg);
Magnus Damm2967dab2008-10-08 20:41:43 +0900155
Magnus Dammf78a26f2011-12-14 01:01:05 +0900156 if (crp->field_width) {
157 *maskp = (1 << crp->field_width) - 1;
158 *posp = crp->reg_width - ((in_pos + 1) * crp->field_width);
159 } else {
160 *maskp = (1 << crp->var_field_width[in_pos]) - 1;
161 *posp = crp->reg_width;
162 for (k = 0; k <= in_pos; k++)
163 *posp -= crp->var_field_width[k];
164 }
Magnus Damm0fc64cc2008-12-25 18:17:18 +0900165}
Magnus Damm2967dab2008-10-08 20:41:43 +0900166
Laurent Pinchart4aeacd52012-12-15 23:50:53 +0100167static void sh_pfc_write_config_reg(struct sh_pfc *pfc,
Laurent Pinchartcd3c1be2013-02-16 18:47:05 +0100168 const struct pinmux_cfg_reg *crp,
Laurent Pinchart4aeacd52012-12-15 23:50:53 +0100169 unsigned long field, unsigned long value)
Magnus Damm18925e12011-12-14 01:00:55 +0900170{
171 void __iomem *mapped_reg;
Magnus Damme499ada2011-12-14 01:01:14 +0900172 unsigned long mask, pos, data;
Magnus Damm18925e12011-12-14 01:00:55 +0900173
Laurent Pinchart4aeacd52012-12-15 23:50:53 +0100174 sh_pfc_config_reg_helper(pfc, crp, field, &mapped_reg, &mask, &pos);
Magnus Damm18925e12011-12-14 01:00:55 +0900175
Laurent Pinchart9a643c92013-03-10 18:00:02 +0100176 dev_dbg(pfc->dev, "write_reg addr = %lx, value = %ld, field = %ld, "
177 "r_width = %ld, f_width = %ld\n",
178 crp->reg, value, field, crp->reg_width, crp->field_width);
Magnus Damm0fc64cc2008-12-25 18:17:18 +0900179
180 mask = ~(mask << pos);
181 value = value << pos;
Magnus Damm2967dab2008-10-08 20:41:43 +0900182
Laurent Pinchart4aeacd52012-12-15 23:50:53 +0100183 data = sh_pfc_read_raw_reg(mapped_reg, crp->reg_width);
Magnus Damme499ada2011-12-14 01:01:14 +0900184 data &= mask;
185 data |= value;
186
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100187 if (pfc->info->unlock_reg)
Laurent Pinchart4aeacd52012-12-15 23:50:53 +0100188 sh_pfc_write_raw_reg(
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100189 sh_pfc_phys_to_virt(pfc, pfc->info->unlock_reg), 32,
Laurent Pinchart4aeacd52012-12-15 23:50:53 +0100190 ~data);
Magnus Damme499ada2011-12-14 01:01:14 +0900191
Laurent Pinchart4aeacd52012-12-15 23:50:53 +0100192 sh_pfc_write_raw_reg(mapped_reg, crp->reg_width, data);
Magnus Damm2967dab2008-10-08 20:41:43 +0900193}
194
Laurent Pinchart4aeacd52012-12-15 23:50:53 +0100195static int sh_pfc_get_config_reg(struct sh_pfc *pfc, pinmux_enum_t enum_id,
Laurent Pinchartcd3c1be2013-02-16 18:47:05 +0100196 const struct pinmux_cfg_reg **crp, int *fieldp,
Laurent Pinchart861601d2013-03-10 15:29:14 +0100197 int *valuep)
Magnus Damm2967dab2008-10-08 20:41:43 +0900198{
Laurent Pinchartcd3c1be2013-02-16 18:47:05 +0100199 const struct pinmux_cfg_reg *config_reg;
Magnus Dammf78a26f2011-12-14 01:01:05 +0900200 unsigned long r_width, f_width, curr_width, ncomb;
201 int k, m, n, pos, bit_pos;
Magnus Damm2967dab2008-10-08 20:41:43 +0900202
203 k = 0;
204 while (1) {
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100205 config_reg = pfc->info->cfg_regs + k;
Magnus Damm2967dab2008-10-08 20:41:43 +0900206
207 r_width = config_reg->reg_width;
208 f_width = config_reg->field_width;
209
210 if (!r_width)
211 break;
Magnus Dammf78a26f2011-12-14 01:01:05 +0900212
213 pos = 0;
214 m = 0;
215 for (bit_pos = 0; bit_pos < r_width; bit_pos += curr_width) {
216 if (f_width)
217 curr_width = f_width;
218 else
219 curr_width = config_reg->var_field_width[m];
220
221 ncomb = 1 << curr_width;
222 for (n = 0; n < ncomb; n++) {
223 if (config_reg->enum_ids[pos + n] == enum_id) {
224 *crp = config_reg;
225 *fieldp = m;
226 *valuep = n;
Magnus Dammf78a26f2011-12-14 01:01:05 +0900227 return 0;
228 }
Magnus Damm2967dab2008-10-08 20:41:43 +0900229 }
Magnus Dammf78a26f2011-12-14 01:01:05 +0900230 pos += ncomb;
231 m++;
Magnus Damm2967dab2008-10-08 20:41:43 +0900232 }
233 k++;
234 }
235
Laurent Pinchartb705c052013-03-10 16:38:23 +0100236 return -EINVAL;
Magnus Damm2967dab2008-10-08 20:41:43 +0900237}
238
Laurent Pincharta68fdca92013-02-14 17:36:56 +0100239static int sh_pfc_mark_to_enum(struct sh_pfc *pfc, pinmux_enum_t mark, int pos,
240 pinmux_enum_t *enum_idp)
Magnus Damm2967dab2008-10-08 20:41:43 +0900241{
Laurent Pinchartcd3c1be2013-02-16 18:47:05 +0100242 const pinmux_enum_t *data = pfc->info->gpio_data;
Magnus Damm2967dab2008-10-08 20:41:43 +0900243 int k;
244
Magnus Damm2967dab2008-10-08 20:41:43 +0900245 if (pos) {
246 *enum_idp = data[pos + 1];
247 return pos + 1;
248 }
249
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100250 for (k = 0; k < pfc->info->gpio_data_size; k++) {
Laurent Pincharta68fdca92013-02-14 17:36:56 +0100251 if (data[k] == mark) {
Magnus Damm2967dab2008-10-08 20:41:43 +0900252 *enum_idp = data[k + 1];
253 return k + 1;
254 }
255 }
256
Laurent Pinchart9a643c92013-03-10 18:00:02 +0100257 dev_err(pfc->dev, "cannot locate data/mark enum_id for mark %d\n",
258 mark);
Laurent Pinchartb705c052013-03-10 16:38:23 +0100259 return -EINVAL;
Magnus Damm2967dab2008-10-08 20:41:43 +0900260}
261
Laurent Pinchart861601d2013-03-10 15:29:14 +0100262int sh_pfc_config_mux(struct sh_pfc *pfc, unsigned mark, int pinmux_type)
Magnus Damm2967dab2008-10-08 20:41:43 +0900263{
Laurent Pinchartcd3c1be2013-02-16 18:47:05 +0100264 const struct pinmux_cfg_reg *cr = NULL;
Magnus Damm2967dab2008-10-08 20:41:43 +0900265 pinmux_enum_t enum_id;
Laurent Pinchartcd3c1be2013-02-16 18:47:05 +0100266 const struct pinmux_range *range;
Magnus Dammad4a07f2011-12-14 01:00:46 +0900267 int in_range, pos, field, value;
Laurent Pinchartb705c052013-03-10 16:38:23 +0100268 int ret;
Magnus Damm2967dab2008-10-08 20:41:43 +0900269
270 switch (pinmux_type) {
Laurent Pincharte3c470512013-03-10 17:30:25 +0100271 case PINMUX_TYPE_GPIO:
Magnus Damm2967dab2008-10-08 20:41:43 +0900272 case PINMUX_TYPE_FUNCTION:
273 range = NULL;
274 break;
275
276 case PINMUX_TYPE_OUTPUT:
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100277 range = &pfc->info->output;
Magnus Damm2967dab2008-10-08 20:41:43 +0900278 break;
279
280 case PINMUX_TYPE_INPUT:
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100281 range = &pfc->info->input;
Magnus Damm2967dab2008-10-08 20:41:43 +0900282 break;
283
284 case PINMUX_TYPE_INPUT_PULLUP:
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100285 range = &pfc->info->input_pu;
Magnus Damm2967dab2008-10-08 20:41:43 +0900286 break;
287
288 case PINMUX_TYPE_INPUT_PULLDOWN:
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100289 range = &pfc->info->input_pd;
Magnus Damm2967dab2008-10-08 20:41:43 +0900290 break;
291
292 default:
Laurent Pinchartb705c052013-03-10 16:38:23 +0100293 return -EINVAL;
Magnus Damm2967dab2008-10-08 20:41:43 +0900294 }
295
296 pos = 0;
297 enum_id = 0;
Magnus Dammad4a07f2011-12-14 01:00:46 +0900298 field = 0;
299 value = 0;
Laurent Pincharte3c470512013-03-10 17:30:25 +0100300
301 /* Iterate over all the configuration fields we need to update. */
Magnus Damm2967dab2008-10-08 20:41:43 +0900302 while (1) {
Laurent Pincharta68fdca92013-02-14 17:36:56 +0100303 pos = sh_pfc_mark_to_enum(pfc, mark, pos, &enum_id);
Laurent Pinchartb705c052013-03-10 16:38:23 +0100304 if (pos < 0)
305 return pos;
Magnus Damm2967dab2008-10-08 20:41:43 +0900306
307 if (!enum_id)
308 break;
309
Laurent Pincharte3c470512013-03-10 17:30:25 +0100310 /* Check if the configuration field selects a function. If it
311 * doesn't, skip the field if it's not applicable to the
312 * requested pinmux type.
313 */
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100314 in_range = sh_pfc_enum_in_range(enum_id, &pfc->info->function);
Magnus Damm50dd3142010-01-19 13:52:28 +0000315 if (!in_range) {
Laurent Pincharte3c470512013-03-10 17:30:25 +0100316 if (pinmux_type == PINMUX_TYPE_FUNCTION) {
317 /* Functions are allowed to modify all
318 * fields.
319 */
320 in_range = 1;
321 } else if (pinmux_type != PINMUX_TYPE_GPIO) {
322 /* Input/output types can only modify fields
323 * that correspond to their respective ranges.
Magnus Damm50dd3142010-01-19 13:52:28 +0000324 */
Laurent Pinchart4aeacd52012-12-15 23:50:53 +0100325 in_range = sh_pfc_enum_in_range(enum_id, range);
Magnus Damm2967dab2008-10-08 20:41:43 +0900326
Magnus Damm50dd3142010-01-19 13:52:28 +0000327 /*
328 * special case pass through for fixed
329 * input-only or output-only pins without
330 * function enum register association.
331 */
332 if (in_range && enum_id == range->force)
333 continue;
Magnus Damm50dd3142010-01-19 13:52:28 +0000334 }
Laurent Pincharte3c470512013-03-10 17:30:25 +0100335 /* GPIOs are only allowed to modify function fields. */
Magnus Damm42eed422008-10-22 18:29:17 +0900336 }
337
Magnus Damm2967dab2008-10-08 20:41:43 +0900338 if (!in_range)
339 continue;
340
Laurent Pinchartb705c052013-03-10 16:38:23 +0100341 ret = sh_pfc_get_config_reg(pfc, enum_id, &cr, &field, &value);
342 if (ret < 0)
343 return ret;
Magnus Damm2967dab2008-10-08 20:41:43 +0900344
Laurent Pinchart861601d2013-03-10 15:29:14 +0100345 sh_pfc_write_config_reg(pfc, cr, field, value);
Magnus Damm2967dab2008-10-08 20:41:43 +0900346 }
347
348 return 0;
Magnus Damm2967dab2008-10-08 20:41:43 +0900349}
350
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100351static int sh_pfc_probe(struct platform_device *pdev)
Magnus Damm2967dab2008-10-08 20:41:43 +0900352{
Laurent Pinchartcd3c1be2013-02-16 18:47:05 +0100353 const struct sh_pfc_soc_info *info;
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100354 struct sh_pfc *pfc;
Magnus Damm0fc64cc2008-12-25 18:17:18 +0900355 int ret;
Magnus Damm2967dab2008-10-08 20:41:43 +0900356
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100357 info = pdev->id_entry->driver_data
358 ? (void *)pdev->id_entry->driver_data : pdev->dev.platform_data;
359 if (info == NULL)
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100360 return -ENODEV;
Magnus Damm0fc64cc2008-12-25 18:17:18 +0900361
Magnus Damm8c43fcc2013-02-14 21:23:47 +0900362 pfc = devm_kzalloc(&pdev->dev, sizeof(*pfc), GFP_KERNEL);
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100363 if (pfc == NULL)
364 return -ENOMEM;
Magnus Dammb0e10212011-12-09 12:14:27 +0900365
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100366 pfc->info = info;
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100367 pfc->dev = &pdev->dev;
368
Laurent Pinchart973931a2012-12-15 23:50:55 +0100369 ret = sh_pfc_ioremap(pfc, pdev);
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100370 if (unlikely(ret < 0))
Laurent Pinchartd4e62d02012-12-15 23:50:43 +0100371 return ret;
Laurent Pinchartd4e62d02012-12-15 23:50:43 +0100372
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100373 spin_lock_init(&pfc->lock);
Magnus Damm69edbba2008-12-25 18:17:34 +0900374
Laurent Pinchart0c151062013-04-21 20:21:57 +0200375 if (info->ops && info->ops->init) {
376 ret = info->ops->init(pfc);
377 if (ret < 0)
378 return ret;
379 }
380
Paul Mundtca5481c62012-07-10 12:08:14 +0900381 pinctrl_provide_dummies();
Magnus Damm69edbba2008-12-25 18:17:34 +0900382
Paul Mundtca5481c62012-07-10 12:08:14 +0900383 /*
384 * Initialize pinctrl bindings first
385 */
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100386 ret = sh_pfc_register_pinctrl(pfc);
Laurent Pinchartf9492fd2012-12-15 23:50:45 +0100387 if (unlikely(ret != 0))
Laurent Pinchart0c151062013-04-21 20:21:57 +0200388 goto error;
Magnus Damm69edbba2008-12-25 18:17:34 +0900389
Laurent Pinchart6f6a4a62012-12-15 23:50:46 +0100390#ifdef CONFIG_GPIO_SH_PFC
Paul Mundtca5481c62012-07-10 12:08:14 +0900391 /*
392 * Then the GPIO chip
393 */
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100394 ret = sh_pfc_register_gpiochip(pfc);
Laurent Pinchart6f6a4a62012-12-15 23:50:46 +0100395 if (unlikely(ret != 0)) {
Paul Mundtca5481c62012-07-10 12:08:14 +0900396 /*
397 * If the GPIO chip fails to come up we still leave the
398 * PFC state as it is, given that there are already
399 * extant users of it that have succeeded by this point.
400 */
Laurent Pinchart9a643c92013-03-10 18:00:02 +0100401 dev_notice(pfc->dev, "failed to init GPIO chip, ignoring...\n");
Paul Mundtca5481c62012-07-10 12:08:14 +0900402 }
Laurent Pinchart6f6a4a62012-12-15 23:50:46 +0100403#endif
Paul Mundtca5481c62012-07-10 12:08:14 +0900404
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100405 platform_set_drvdata(pdev, pfc);
406
Laurent Pinchart9a643c92013-03-10 18:00:02 +0100407 dev_info(pfc->dev, "%s support registered\n", info->name);
Paul Mundtca5481c62012-07-10 12:08:14 +0900408
Paul Mundtb3c185a2012-06-20 17:29:04 +0900409 return 0;
Laurent Pinchart0c151062013-04-21 20:21:57 +0200410
411error:
412 if (info->ops && info->ops->exit)
413 info->ops->exit(pfc);
414 return ret;
Paul Mundtb72421d2010-10-04 03:54:56 +0900415}
Laurent Pinchart6f6a4a62012-12-15 23:50:46 +0100416
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100417static int sh_pfc_remove(struct platform_device *pdev)
418{
419 struct sh_pfc *pfc = platform_get_drvdata(pdev);
420
421#ifdef CONFIG_GPIO_SH_PFC
422 sh_pfc_unregister_gpiochip(pfc);
423#endif
424 sh_pfc_unregister_pinctrl(pfc);
425
Laurent Pinchart0c151062013-04-21 20:21:57 +0200426 if (pfc->info->ops && pfc->info->ops->exit)
427 pfc->info->ops->exit(pfc);
428
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100429 platform_set_drvdata(pdev, NULL);
430
431 return 0;
432}
433
434static const struct platform_device_id sh_pfc_id_table[] = {
Magnus Dammc98f6c22013-03-26 22:49:49 +0900435#ifdef CONFIG_PINCTRL_PFC_R8A73A4
436 { "pfc-r8a73a4", (kernel_ulong_t)&r8a73a4_pinmux_info },
437#endif
Laurent Pinchartd5b15212012-12-15 23:51:21 +0100438#ifdef CONFIG_PINCTRL_PFC_R8A7740
439 { "pfc-r8a7740", (kernel_ulong_t)&r8a7740_pinmux_info },
440#endif
Kuninori Morimoto87f8c982013-04-12 05:37:20 +0000441#ifdef CONFIG_PINCTRL_PFC_R8A7778
442 { "pfc-r8a7778", (kernel_ulong_t)&r8a7778_pinmux_info },
443#endif
Laurent Pinchart881023d2012-12-15 23:51:22 +0100444#ifdef CONFIG_PINCTRL_PFC_R8A7779
445 { "pfc-r8a7779", (kernel_ulong_t)&r8a7779_pinmux_info },
446#endif
Koji Matsuoka58c229e2013-04-08 11:08:53 +0900447#ifdef CONFIG_PINCTRL_PFC_R8A7790
448 { "pfc-r8a7790", (kernel_ulong_t)&r8a7790_pinmux_info },
449#endif
Laurent Pinchartccda5522012-12-15 23:51:29 +0100450#ifdef CONFIG_PINCTRL_PFC_SH7203
451 { "pfc-sh7203", (kernel_ulong_t)&sh7203_pinmux_info },
452#endif
Laurent Pincharta8d42fc2012-12-15 23:51:30 +0100453#ifdef CONFIG_PINCTRL_PFC_SH7264
454 { "pfc-sh7264", (kernel_ulong_t)&sh7264_pinmux_info },
455#endif
Laurent Pinchartf5e811f2012-12-15 23:51:31 +0100456#ifdef CONFIG_PINCTRL_PFC_SH7269
457 { "pfc-sh7269", (kernel_ulong_t)&sh7269_pinmux_info },
458#endif
Laurent Pinchart6e5469a2012-12-15 23:51:23 +0100459#ifdef CONFIG_PINCTRL_PFC_SH7372
460 { "pfc-sh7372", (kernel_ulong_t)&sh7372_pinmux_info },
461#endif
Laurent Pinchart5d5166d2012-12-15 23:51:24 +0100462#ifdef CONFIG_PINCTRL_PFC_SH73A0
463 { "pfc-sh73a0", (kernel_ulong_t)&sh73a0_pinmux_info },
464#endif
Laurent Pinchart74cad602012-12-15 23:51:32 +0100465#ifdef CONFIG_PINCTRL_PFC_SH7720
466 { "pfc-sh7720", (kernel_ulong_t)&sh7720_pinmux_info },
467#endif
Laurent Pinchartf5e25ae2012-12-15 23:51:33 +0100468#ifdef CONFIG_PINCTRL_PFC_SH7722
469 { "pfc-sh7722", (kernel_ulong_t)&sh7722_pinmux_info },
470#endif
Laurent Pinchartd05afa02012-12-15 23:51:34 +0100471#ifdef CONFIG_PINCTRL_PFC_SH7723
472 { "pfc-sh7723", (kernel_ulong_t)&sh7723_pinmux_info },
473#endif
Laurent Pinchart0ff25ba2012-12-15 23:51:35 +0100474#ifdef CONFIG_PINCTRL_PFC_SH7724
475 { "pfc-sh7724", (kernel_ulong_t)&sh7724_pinmux_info },
476#endif
Laurent Pinchartac1ebc22012-12-15 23:51:36 +0100477#ifdef CONFIG_PINCTRL_PFC_SH7734
478 { "pfc-sh7734", (kernel_ulong_t)&sh7734_pinmux_info },
479#endif
Laurent Pinchart0bb92672012-12-15 23:51:37 +0100480#ifdef CONFIG_PINCTRL_PFC_SH7757
481 { "pfc-sh7757", (kernel_ulong_t)&sh7757_pinmux_info },
482#endif
Laurent Pincharta56398e2012-12-15 23:51:38 +0100483#ifdef CONFIG_PINCTRL_PFC_SH7785
484 { "pfc-sh7785", (kernel_ulong_t)&sh7785_pinmux_info },
485#endif
Laurent Pinchartd2a31bd2012-12-15 23:51:39 +0100486#ifdef CONFIG_PINCTRL_PFC_SH7786
487 { "pfc-sh7786", (kernel_ulong_t)&sh7786_pinmux_info },
488#endif
Laurent Pinchartd5d9a812012-12-15 23:51:40 +0100489#ifdef CONFIG_PINCTRL_PFC_SHX3
490 { "pfc-shx3", (kernel_ulong_t)&shx3_pinmux_info },
491#endif
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100492 { "sh-pfc", 0 },
493 { },
494};
495MODULE_DEVICE_TABLE(platform, sh_pfc_id_table);
496
497static struct platform_driver sh_pfc_driver = {
498 .probe = sh_pfc_probe,
499 .remove = sh_pfc_remove,
500 .id_table = sh_pfc_id_table,
501 .driver = {
502 .name = DRV_NAME,
503 .owner = THIS_MODULE,
504 },
505};
506
Laurent Pinchart40ee6fc2012-12-15 23:50:54 +0100507static int __init sh_pfc_init(void)
508{
509 return platform_driver_register(&sh_pfc_driver);
510}
511postcore_initcall(sh_pfc_init);
512
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100513static void __exit sh_pfc_exit(void)
514{
515 platform_driver_unregister(&sh_pfc_driver);
516}
517module_exit(sh_pfc_exit);
518
Laurent Pinchart6f6a4a62012-12-15 23:50:46 +0100519MODULE_AUTHOR("Magnus Damm, Paul Mundt, Laurent Pinchart");
520MODULE_DESCRIPTION("Pin Control and GPIO driver for SuperH pin function controller");
521MODULE_LICENSE("GPL v2");