blob: e2864ec900f4aebbd6f60728452d20ddd45e4e06 [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 void sh_pfc_write_config_reg(struct sh_pfc *pfc,
167 struct pinmux_cfg_reg *crp,
168 unsigned long field, unsigned long value)
Magnus Damm18925e12011-12-14 01:00:55 +0900169{
170 void __iomem *mapped_reg;
Magnus Damme499ada2011-12-14 01:01:14 +0900171 unsigned long mask, pos, data;
Magnus Damm18925e12011-12-14 01:00:55 +0900172
Laurent Pinchart4aeacd52012-12-15 23:50:53 +0100173 sh_pfc_config_reg_helper(pfc, crp, field, &mapped_reg, &mask, &pos);
Magnus Damm18925e12011-12-14 01:00:55 +0900174
175 pr_debug("write_reg addr = %lx, value = %ld, field = %ld, "
176 "r_width = %ld, f_width = %ld\n",
177 crp->reg, value, field, crp->reg_width, crp->field_width);
Magnus Damm0fc64cc2008-12-25 18:17:18 +0900178
179 mask = ~(mask << pos);
180 value = value << pos;
Magnus Damm2967dab2008-10-08 20:41:43 +0900181
Laurent Pinchart4aeacd52012-12-15 23:50:53 +0100182 data = sh_pfc_read_raw_reg(mapped_reg, crp->reg_width);
Magnus Damme499ada2011-12-14 01:01:14 +0900183 data &= mask;
184 data |= value;
185
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100186 if (pfc->info->unlock_reg)
Laurent Pinchart4aeacd52012-12-15 23:50:53 +0100187 sh_pfc_write_raw_reg(
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100188 sh_pfc_phys_to_virt(pfc, pfc->info->unlock_reg), 32,
Laurent Pinchart4aeacd52012-12-15 23:50:53 +0100189 ~data);
Magnus Damme499ada2011-12-14 01:01:14 +0900190
Laurent Pinchart4aeacd52012-12-15 23:50:53 +0100191 sh_pfc_write_raw_reg(mapped_reg, crp->reg_width, data);
Magnus Damm2967dab2008-10-08 20:41:43 +0900192}
193
Laurent Pinchart4aeacd52012-12-15 23:50:53 +0100194static int sh_pfc_get_config_reg(struct sh_pfc *pfc, pinmux_enum_t enum_id,
195 struct pinmux_cfg_reg **crp, int *fieldp,
Laurent Pinchart861601d2013-03-10 15:29:14 +0100196 int *valuep)
Magnus Damm2967dab2008-10-08 20:41:43 +0900197{
198 struct pinmux_cfg_reg *config_reg;
Magnus Dammf78a26f2011-12-14 01:01:05 +0900199 unsigned long r_width, f_width, curr_width, ncomb;
200 int k, m, n, pos, bit_pos;
Magnus Damm2967dab2008-10-08 20:41:43 +0900201
202 k = 0;
203 while (1) {
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100204 config_reg = pfc->info->cfg_regs + k;
Magnus Damm2967dab2008-10-08 20:41:43 +0900205
206 r_width = config_reg->reg_width;
207 f_width = config_reg->field_width;
208
209 if (!r_width)
210 break;
Magnus Dammf78a26f2011-12-14 01:01:05 +0900211
212 pos = 0;
213 m = 0;
214 for (bit_pos = 0; bit_pos < r_width; bit_pos += curr_width) {
215 if (f_width)
216 curr_width = f_width;
217 else
218 curr_width = config_reg->var_field_width[m];
219
220 ncomb = 1 << curr_width;
221 for (n = 0; n < ncomb; n++) {
222 if (config_reg->enum_ids[pos + n] == enum_id) {
223 *crp = config_reg;
224 *fieldp = m;
225 *valuep = n;
Magnus Dammf78a26f2011-12-14 01:01:05 +0900226 return 0;
227 }
Magnus Damm2967dab2008-10-08 20:41:43 +0900228 }
Magnus Dammf78a26f2011-12-14 01:01:05 +0900229 pos += ncomb;
230 m++;
Magnus Damm2967dab2008-10-08 20:41:43 +0900231 }
232 k++;
233 }
234
235 return -1;
236}
237
Laurent Pincharta68fdca92013-02-14 17:36:56 +0100238static int sh_pfc_mark_to_enum(struct sh_pfc *pfc, pinmux_enum_t mark, int pos,
239 pinmux_enum_t *enum_idp)
Magnus Damm2967dab2008-10-08 20:41:43 +0900240{
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100241 pinmux_enum_t *data = pfc->info->gpio_data;
Magnus Damm2967dab2008-10-08 20:41:43 +0900242 int k;
243
Magnus Damm2967dab2008-10-08 20:41:43 +0900244 if (pos) {
245 *enum_idp = data[pos + 1];
246 return pos + 1;
247 }
248
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100249 for (k = 0; k < pfc->info->gpio_data_size; k++) {
Laurent Pincharta68fdca92013-02-14 17:36:56 +0100250 if (data[k] == mark) {
Magnus Damm2967dab2008-10-08 20:41:43 +0900251 *enum_idp = data[k + 1];
252 return k + 1;
253 }
254 }
255
Laurent Pincharta68fdca92013-02-14 17:36:56 +0100256 pr_err("cannot locate data/mark enum_id for mark %d\n", mark);
Magnus Damm2967dab2008-10-08 20:41:43 +0900257 return -1;
258}
259
Laurent Pinchart861601d2013-03-10 15:29:14 +0100260int sh_pfc_config_mux(struct sh_pfc *pfc, unsigned mark, int pinmux_type)
Magnus Damm2967dab2008-10-08 20:41:43 +0900261{
262 struct pinmux_cfg_reg *cr = NULL;
263 pinmux_enum_t enum_id;
264 struct pinmux_range *range;
Magnus Dammad4a07f2011-12-14 01:00:46 +0900265 int in_range, pos, field, value;
Magnus Damm2967dab2008-10-08 20:41:43 +0900266
267 switch (pinmux_type) {
268
269 case PINMUX_TYPE_FUNCTION:
270 range = NULL;
271 break;
272
273 case PINMUX_TYPE_OUTPUT:
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100274 range = &pfc->info->output;
Magnus Damm2967dab2008-10-08 20:41:43 +0900275 break;
276
277 case PINMUX_TYPE_INPUT:
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100278 range = &pfc->info->input;
Magnus Damm2967dab2008-10-08 20:41:43 +0900279 break;
280
281 case PINMUX_TYPE_INPUT_PULLUP:
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100282 range = &pfc->info->input_pu;
Magnus Damm2967dab2008-10-08 20:41:43 +0900283 break;
284
285 case PINMUX_TYPE_INPUT_PULLDOWN:
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100286 range = &pfc->info->input_pd;
Magnus Damm2967dab2008-10-08 20:41:43 +0900287 break;
288
289 default:
Laurent Pinchart861601d2013-03-10 15:29:14 +0100290 return -1;
Magnus Damm2967dab2008-10-08 20:41:43 +0900291 }
292
293 pos = 0;
294 enum_id = 0;
Magnus Dammad4a07f2011-12-14 01:00:46 +0900295 field = 0;
296 value = 0;
Magnus Damm2967dab2008-10-08 20:41:43 +0900297 while (1) {
Laurent Pincharta68fdca92013-02-14 17:36:56 +0100298 pos = sh_pfc_mark_to_enum(pfc, mark, pos, &enum_id);
Magnus Damm2967dab2008-10-08 20:41:43 +0900299 if (pos <= 0)
Laurent Pinchart861601d2013-03-10 15:29:14 +0100300 return -1;
Magnus Damm2967dab2008-10-08 20:41:43 +0900301
302 if (!enum_id)
303 break;
304
Magnus Damm50dd3142010-01-19 13:52:28 +0000305 /* first check if this is a function enum */
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100306 in_range = sh_pfc_enum_in_range(enum_id, &pfc->info->function);
Magnus Damm50dd3142010-01-19 13:52:28 +0000307 if (!in_range) {
308 /* not a function enum */
309 if (range) {
310 /*
311 * other range exists, so this pin is
312 * a regular GPIO pin that now is being
313 * bound to a specific direction.
314 *
315 * for this case we only allow function enums
316 * and the enums that match the other range.
317 */
Laurent Pinchart4aeacd52012-12-15 23:50:53 +0100318 in_range = sh_pfc_enum_in_range(enum_id, range);
Magnus Damm2967dab2008-10-08 20:41:43 +0900319
Magnus Damm50dd3142010-01-19 13:52:28 +0000320 /*
321 * special case pass through for fixed
322 * input-only or output-only pins without
323 * function enum register association.
324 */
325 if (in_range && enum_id == range->force)
326 continue;
327 } else {
328 /*
329 * no other range exists, so this pin
330 * must then be of the function type.
331 *
332 * allow function type pins to select
333 * any combination of function/in/out
334 * in their MARK lists.
335 */
336 in_range = 1;
337 }
Magnus Damm42eed422008-10-22 18:29:17 +0900338 }
339
Magnus Damm2967dab2008-10-08 20:41:43 +0900340 if (!in_range)
341 continue;
342
Laurent Pinchart4aeacd52012-12-15 23:50:53 +0100343 if (sh_pfc_get_config_reg(pfc, enum_id, &cr,
Laurent Pinchart861601d2013-03-10 15:29:14 +0100344 &field, &value) != 0)
345 return -1;
Magnus Damm2967dab2008-10-08 20:41:43 +0900346
Laurent Pinchart861601d2013-03-10 15:29:14 +0100347 sh_pfc_write_config_reg(pfc, cr, field, value);
Magnus Damm2967dab2008-10-08 20:41:43 +0900348 }
349
350 return 0;
Magnus Damm2967dab2008-10-08 20:41:43 +0900351}
352
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100353static int sh_pfc_probe(struct platform_device *pdev)
Magnus Damm2967dab2008-10-08 20:41:43 +0900354{
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100355 struct sh_pfc_soc_info *info;
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100356 struct sh_pfc *pfc;
Magnus Damm0fc64cc2008-12-25 18:17:18 +0900357 int ret;
Magnus Damm2967dab2008-10-08 20:41:43 +0900358
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100359 info = pdev->id_entry->driver_data
360 ? (void *)pdev->id_entry->driver_data : pdev->dev.platform_data;
361 if (info == NULL)
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100362 return -ENODEV;
Magnus Damm0fc64cc2008-12-25 18:17:18 +0900363
Magnus Damm8c43fcc2013-02-14 21:23:47 +0900364 pfc = devm_kzalloc(&pdev->dev, sizeof(*pfc), GFP_KERNEL);
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100365 if (pfc == NULL)
366 return -ENOMEM;
Magnus Dammb0e10212011-12-09 12:14:27 +0900367
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100368 pfc->info = info;
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100369 pfc->dev = &pdev->dev;
370
Laurent Pinchart973931a2012-12-15 23:50:55 +0100371 ret = sh_pfc_ioremap(pfc, pdev);
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100372 if (unlikely(ret < 0))
Laurent Pinchartd4e62d02012-12-15 23:50:43 +0100373 return ret;
Laurent Pinchartd4e62d02012-12-15 23:50:43 +0100374
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100375 spin_lock_init(&pfc->lock);
Magnus Damm69edbba2008-12-25 18:17:34 +0900376
Paul Mundtca5481c62012-07-10 12:08:14 +0900377 pinctrl_provide_dummies();
Magnus Damm69edbba2008-12-25 18:17:34 +0900378
Paul Mundtca5481c62012-07-10 12:08:14 +0900379 /*
380 * Initialize pinctrl bindings first
381 */
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100382 ret = sh_pfc_register_pinctrl(pfc);
Laurent Pinchartf9492fd2012-12-15 23:50:45 +0100383 if (unlikely(ret != 0))
Laurent Pinchartc9fa88e2012-12-15 23:50:49 +0100384 return ret;
Magnus Damm69edbba2008-12-25 18:17:34 +0900385
Laurent Pinchart6f6a4a62012-12-15 23:50:46 +0100386#ifdef CONFIG_GPIO_SH_PFC
Paul Mundtca5481c62012-07-10 12:08:14 +0900387 /*
388 * Then the GPIO chip
389 */
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100390 ret = sh_pfc_register_gpiochip(pfc);
Laurent Pinchart6f6a4a62012-12-15 23:50:46 +0100391 if (unlikely(ret != 0)) {
Paul Mundtca5481c62012-07-10 12:08:14 +0900392 /*
393 * If the GPIO chip fails to come up we still leave the
394 * PFC state as it is, given that there are already
395 * extant users of it that have succeeded by this point.
396 */
Laurent Pinchart6f6a4a62012-12-15 23:50:46 +0100397 pr_notice("failed to init GPIO chip, ignoring...\n");
Paul Mundtca5481c62012-07-10 12:08:14 +0900398 }
Laurent Pinchart6f6a4a62012-12-15 23:50:46 +0100399#endif
Paul Mundtca5481c62012-07-10 12:08:14 +0900400
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100401 platform_set_drvdata(pdev, pfc);
402
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100403 pr_info("%s support registered\n", info->name);
Paul Mundtca5481c62012-07-10 12:08:14 +0900404
Paul Mundtb3c185a2012-06-20 17:29:04 +0900405 return 0;
Paul Mundtb72421d2010-10-04 03:54:56 +0900406}
Laurent Pinchart6f6a4a62012-12-15 23:50:46 +0100407
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100408static int sh_pfc_remove(struct platform_device *pdev)
409{
410 struct sh_pfc *pfc = platform_get_drvdata(pdev);
411
412#ifdef CONFIG_GPIO_SH_PFC
413 sh_pfc_unregister_gpiochip(pfc);
414#endif
415 sh_pfc_unregister_pinctrl(pfc);
416
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100417 platform_set_drvdata(pdev, NULL);
418
419 return 0;
420}
421
422static const struct platform_device_id sh_pfc_id_table[] = {
Laurent Pinchartd5b15212012-12-15 23:51:21 +0100423#ifdef CONFIG_PINCTRL_PFC_R8A7740
424 { "pfc-r8a7740", (kernel_ulong_t)&r8a7740_pinmux_info },
425#endif
Laurent Pinchart881023d2012-12-15 23:51:22 +0100426#ifdef CONFIG_PINCTRL_PFC_R8A7779
427 { "pfc-r8a7779", (kernel_ulong_t)&r8a7779_pinmux_info },
428#endif
Laurent Pinchartccda5522012-12-15 23:51:29 +0100429#ifdef CONFIG_PINCTRL_PFC_SH7203
430 { "pfc-sh7203", (kernel_ulong_t)&sh7203_pinmux_info },
431#endif
Laurent Pincharta8d42fc2012-12-15 23:51:30 +0100432#ifdef CONFIG_PINCTRL_PFC_SH7264
433 { "pfc-sh7264", (kernel_ulong_t)&sh7264_pinmux_info },
434#endif
Laurent Pinchartf5e811f2012-12-15 23:51:31 +0100435#ifdef CONFIG_PINCTRL_PFC_SH7269
436 { "pfc-sh7269", (kernel_ulong_t)&sh7269_pinmux_info },
437#endif
Laurent Pinchart6e5469a2012-12-15 23:51:23 +0100438#ifdef CONFIG_PINCTRL_PFC_SH7372
439 { "pfc-sh7372", (kernel_ulong_t)&sh7372_pinmux_info },
440#endif
Laurent Pinchart5d5166d2012-12-15 23:51:24 +0100441#ifdef CONFIG_PINCTRL_PFC_SH73A0
442 { "pfc-sh73a0", (kernel_ulong_t)&sh73a0_pinmux_info },
443#endif
Laurent Pinchart74cad602012-12-15 23:51:32 +0100444#ifdef CONFIG_PINCTRL_PFC_SH7720
445 { "pfc-sh7720", (kernel_ulong_t)&sh7720_pinmux_info },
446#endif
Laurent Pinchartf5e25ae2012-12-15 23:51:33 +0100447#ifdef CONFIG_PINCTRL_PFC_SH7722
448 { "pfc-sh7722", (kernel_ulong_t)&sh7722_pinmux_info },
449#endif
Laurent Pinchartd05afa02012-12-15 23:51:34 +0100450#ifdef CONFIG_PINCTRL_PFC_SH7723
451 { "pfc-sh7723", (kernel_ulong_t)&sh7723_pinmux_info },
452#endif
Laurent Pinchart0ff25ba2012-12-15 23:51:35 +0100453#ifdef CONFIG_PINCTRL_PFC_SH7724
454 { "pfc-sh7724", (kernel_ulong_t)&sh7724_pinmux_info },
455#endif
Laurent Pinchartac1ebc22012-12-15 23:51:36 +0100456#ifdef CONFIG_PINCTRL_PFC_SH7734
457 { "pfc-sh7734", (kernel_ulong_t)&sh7734_pinmux_info },
458#endif
Laurent Pinchart0bb92672012-12-15 23:51:37 +0100459#ifdef CONFIG_PINCTRL_PFC_SH7757
460 { "pfc-sh7757", (kernel_ulong_t)&sh7757_pinmux_info },
461#endif
Laurent Pincharta56398e2012-12-15 23:51:38 +0100462#ifdef CONFIG_PINCTRL_PFC_SH7785
463 { "pfc-sh7785", (kernel_ulong_t)&sh7785_pinmux_info },
464#endif
Laurent Pinchartd2a31bd2012-12-15 23:51:39 +0100465#ifdef CONFIG_PINCTRL_PFC_SH7786
466 { "pfc-sh7786", (kernel_ulong_t)&sh7786_pinmux_info },
467#endif
Laurent Pinchartd5d9a812012-12-15 23:51:40 +0100468#ifdef CONFIG_PINCTRL_PFC_SHX3
469 { "pfc-shx3", (kernel_ulong_t)&shx3_pinmux_info },
470#endif
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100471 { "sh-pfc", 0 },
472 { },
473};
474MODULE_DEVICE_TABLE(platform, sh_pfc_id_table);
475
476static struct platform_driver sh_pfc_driver = {
477 .probe = sh_pfc_probe,
478 .remove = sh_pfc_remove,
479 .id_table = sh_pfc_id_table,
480 .driver = {
481 .name = DRV_NAME,
482 .owner = THIS_MODULE,
483 },
484};
485
Laurent Pinchart40ee6fc2012-12-15 23:50:54 +0100486static int __init sh_pfc_init(void)
487{
488 return platform_driver_register(&sh_pfc_driver);
489}
490postcore_initcall(sh_pfc_init);
491
Laurent Pinchartc6193ea2012-12-15 23:50:47 +0100492static void __exit sh_pfc_exit(void)
493{
494 platform_driver_unregister(&sh_pfc_driver);
495}
496module_exit(sh_pfc_exit);
497
Laurent Pinchart6f6a4a62012-12-15 23:50:46 +0100498MODULE_AUTHOR("Magnus Damm, Paul Mundt, Laurent Pinchart");
499MODULE_DESCRIPTION("Pin Control and GPIO driver for SuperH pin function controller");
500MODULE_LICENSE("GPL v2");