2018-09-07 10:13:29 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2008-10-08 19:41:43 +08:00
|
|
|
/*
|
2016-03-01 04:48:40 +08:00
|
|
|
* Pin Control and GPIO driver for SuperH Pin Function Controller.
|
|
|
|
*
|
|
|
|
* Authors: Magnus Damm, Paul Mundt, Laurent Pinchart
|
2008-10-08 19:41:43 +08:00
|
|
|
*
|
|
|
|
* Copyright (C) 2008 Magnus Damm
|
2012-06-20 16:29:04 +08:00
|
|
|
* Copyright (C) 2009 - 2012 Paul Mundt
|
2008-10-08 19:41:43 +08:00
|
|
|
*/
|
2012-12-16 06:50:47 +08:00
|
|
|
|
|
|
|
#define DRV_NAME "sh-pfc"
|
2010-10-04 02:54:56 +08:00
|
|
|
|
2012-12-16 06:50:52 +08:00
|
|
|
#include <linux/bitops.h>
|
2008-10-08 19:41:43 +08:00
|
|
|
#include <linux/err.h>
|
2012-12-16 06:50:52 +08:00
|
|
|
#include <linux/errno.h>
|
2008-10-08 19:41:43 +08:00
|
|
|
#include <linux/io.h>
|
2011-12-09 11:14:27 +08:00
|
|
|
#include <linux/ioport.h>
|
2012-12-16 06:50:52 +08:00
|
|
|
#include <linux/kernel.h>
|
2016-03-01 04:48:40 +08:00
|
|
|
#include <linux/init.h>
|
2013-06-18 02:50:02 +08:00
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/of_device.h>
|
2012-07-10 11:08:14 +08:00
|
|
|
#include <linux/pinctrl/machine.h>
|
2012-12-16 06:50:47 +08:00
|
|
|
#include <linux/platform_device.h>
|
pinctrl: sh-pfc: Save/restore registers for PSCI system suspend
During PSCI system suspend, R-Car Gen3 SoCs are powered down, and their
pinctrl register state is lost. Note that as the boot loader skips most
initialization after system resume, pinctrl register state differs from
the state encountered during normal system boot, too.
To fix this, save all GPIO and peripheral function select, module
select, drive strength control, bias, and other I/O control registers
during system suspend, and restore them during system resume.
Note that to avoid overhead on platforms not needing it, the
suspend/resume code has a build time dependency on sleep and PSCI
support, and a runtime dependency on PSCI.
Inspired by a patch in the BSP by Hien Dang.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
2017-09-29 20:17:18 +08:00
|
|
|
#include <linux/psci.h>
|
2012-12-16 06:50:52 +08:00
|
|
|
#include <linux/slab.h>
|
2011-12-09 11:14:27 +08:00
|
|
|
|
2012-12-16 06:50:44 +08:00
|
|
|
#include "core.h"
|
|
|
|
|
2013-12-11 11:26:26 +08:00
|
|
|
static int sh_pfc_map_resources(struct sh_pfc *pfc,
|
|
|
|
struct platform_device *pdev)
|
2011-12-09 11:14:27 +08:00
|
|
|
{
|
2015-06-25 17:39:53 +08:00
|
|
|
unsigned int num_windows, num_irqs;
|
2013-12-11 11:26:26 +08:00
|
|
|
struct sh_pfc_window *windows;
|
|
|
|
unsigned int *irqs = NULL;
|
2011-12-09 11:14:27 +08:00
|
|
|
struct resource *res;
|
2013-12-11 11:26:26 +08:00
|
|
|
unsigned int i;
|
2015-06-25 17:39:53 +08:00
|
|
|
int irq;
|
2013-12-11 11:26:26 +08:00
|
|
|
|
|
|
|
/* Count the MEM and IRQ resources. */
|
2015-06-25 17:39:53 +08:00
|
|
|
for (num_windows = 0;; num_windows++) {
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, num_windows);
|
|
|
|
if (!res)
|
2013-12-11 11:26:26 +08:00
|
|
|
break;
|
2015-06-25 17:39:53 +08:00
|
|
|
}
|
|
|
|
for (num_irqs = 0;; num_irqs++) {
|
|
|
|
irq = platform_get_irq(pdev, num_irqs);
|
|
|
|
if (irq == -EPROBE_DEFER)
|
|
|
|
return irq;
|
|
|
|
if (irq < 0)
|
2013-12-11 11:26:26 +08:00
|
|
|
break;
|
|
|
|
}
|
2011-12-09 11:14:27 +08:00
|
|
|
|
2013-12-11 11:26:26 +08:00
|
|
|
if (num_windows == 0)
|
2013-02-17 06:39:07 +08:00
|
|
|
return -EINVAL;
|
2011-12-09 11:14:27 +08:00
|
|
|
|
2013-12-11 11:26:26 +08:00
|
|
|
/* Allocate memory windows and IRQs arrays. */
|
treewide: devm_kzalloc() -> devm_kcalloc()
The devm_kzalloc() function has a 2-factor argument form, devm_kcalloc().
This patch replaces cases of:
devm_kzalloc(handle, a * b, gfp)
with:
devm_kcalloc(handle, a * b, gfp)
as well as handling cases of:
devm_kzalloc(handle, a * b * c, gfp)
with:
devm_kzalloc(handle, array3_size(a, b, c), gfp)
as it's slightly less ugly than:
devm_kcalloc(handle, array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
devm_kzalloc(handle, 4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
Some manual whitespace fixes were needed in this patch, as Coccinelle
really liked to write "=devm_kcalloc..." instead of "= devm_kcalloc...".
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
expression HANDLE;
type TYPE;
expression THING, E;
@@
(
devm_kzalloc(HANDLE,
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
devm_kzalloc(HANDLE,
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression HANDLE;
expression COUNT;
typedef u8;
typedef __u8;
@@
(
devm_kzalloc(HANDLE,
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(char) * COUNT
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
expression HANDLE;
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
expression HANDLE;
identifier SIZE, COUNT;
@@
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression HANDLE;
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
devm_kzalloc(HANDLE,
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression HANDLE;
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
expression HANDLE;
identifier STRIDE, SIZE, COUNT;
@@
(
devm_kzalloc(HANDLE,
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression HANDLE;
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
devm_kzalloc(HANDLE, C1 * C2 * C3, ...)
|
devm_kzalloc(HANDLE,
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
devm_kzalloc(HANDLE,
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
devm_kzalloc(HANDLE,
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
devm_kzalloc(HANDLE,
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression HANDLE;
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
devm_kzalloc(HANDLE, sizeof(THING) * C2, ...)
|
devm_kzalloc(HANDLE, sizeof(TYPE) * C2, ...)
|
devm_kzalloc(HANDLE, C1 * C2 * C3, ...)
|
devm_kzalloc(HANDLE, C1 * C2, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- (E1) * E2
+ E1, E2
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- (E1) * (E2)
+ E1, E2
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-13 05:07:58 +08:00
|
|
|
windows = devm_kcalloc(pfc->dev, num_windows, sizeof(*windows),
|
2013-12-11 11:26:26 +08:00
|
|
|
GFP_KERNEL);
|
|
|
|
if (windows == NULL)
|
2012-12-16 06:50:48 +08:00
|
|
|
return -ENOMEM;
|
2011-12-09 11:14:27 +08:00
|
|
|
|
2013-12-11 11:26:26 +08:00
|
|
|
pfc->num_windows = num_windows;
|
|
|
|
pfc->windows = windows;
|
2012-12-16 06:50:55 +08:00
|
|
|
|
2013-12-11 11:26:26 +08:00
|
|
|
if (num_irqs) {
|
treewide: devm_kzalloc() -> devm_kcalloc()
The devm_kzalloc() function has a 2-factor argument form, devm_kcalloc().
This patch replaces cases of:
devm_kzalloc(handle, a * b, gfp)
with:
devm_kcalloc(handle, a * b, gfp)
as well as handling cases of:
devm_kzalloc(handle, a * b * c, gfp)
with:
devm_kzalloc(handle, array3_size(a, b, c), gfp)
as it's slightly less ugly than:
devm_kcalloc(handle, array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
devm_kzalloc(handle, 4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
Some manual whitespace fixes were needed in this patch, as Coccinelle
really liked to write "=devm_kcalloc..." instead of "= devm_kcalloc...".
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
expression HANDLE;
type TYPE;
expression THING, E;
@@
(
devm_kzalloc(HANDLE,
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
devm_kzalloc(HANDLE,
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression HANDLE;
expression COUNT;
typedef u8;
typedef __u8;
@@
(
devm_kzalloc(HANDLE,
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(char) * COUNT
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
expression HANDLE;
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
expression HANDLE;
identifier SIZE, COUNT;
@@
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression HANDLE;
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
devm_kzalloc(HANDLE,
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression HANDLE;
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
expression HANDLE;
identifier STRIDE, SIZE, COUNT;
@@
(
devm_kzalloc(HANDLE,
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression HANDLE;
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
devm_kzalloc(HANDLE, C1 * C2 * C3, ...)
|
devm_kzalloc(HANDLE,
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
devm_kzalloc(HANDLE,
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
devm_kzalloc(HANDLE,
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
devm_kzalloc(HANDLE,
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression HANDLE;
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
devm_kzalloc(HANDLE, sizeof(THING) * C2, ...)
|
devm_kzalloc(HANDLE, sizeof(TYPE) * C2, ...)
|
devm_kzalloc(HANDLE, C1 * C2 * C3, ...)
|
devm_kzalloc(HANDLE, C1 * C2, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- (E1) * E2
+ E1, E2
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- (E1) * (E2)
+ E1, E2
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-13 05:07:58 +08:00
|
|
|
irqs = devm_kcalloc(pfc->dev, num_irqs, sizeof(*irqs),
|
2013-12-11 11:26:26 +08:00
|
|
|
GFP_KERNEL);
|
|
|
|
if (irqs == NULL)
|
2012-12-16 06:50:48 +08:00
|
|
|
return -ENOMEM;
|
2013-12-11 11:26:26 +08:00
|
|
|
|
|
|
|
pfc->num_irqs = num_irqs;
|
|
|
|
pfc->irqs = irqs;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fill them. */
|
2015-06-25 17:39:53 +08:00
|
|
|
for (i = 0; i < num_windows; i++) {
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, i);
|
|
|
|
windows->phys = res->start;
|
|
|
|
windows->size = resource_size(res);
|
|
|
|
windows->virt = devm_ioremap_resource(pfc->dev, res);
|
|
|
|
if (IS_ERR(windows->virt))
|
|
|
|
return -ENOMEM;
|
|
|
|
windows++;
|
2011-12-09 11:14:27 +08:00
|
|
|
}
|
2015-06-25 17:39:53 +08:00
|
|
|
for (i = 0; i < num_irqs; i++)
|
|
|
|
*irqs++ = platform_get_irq(pdev, i);
|
2011-12-09 11:14:27 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-03-12 18:09:16 +08:00
|
|
|
static void __iomem *sh_pfc_phys_to_virt(struct sh_pfc *pfc, u32 reg)
|
2011-12-09 11:14:27 +08:00
|
|
|
{
|
2012-12-16 06:50:53 +08:00
|
|
|
struct sh_pfc_window *window;
|
2015-03-12 18:09:16 +08:00
|
|
|
phys_addr_t address = reg;
|
2013-02-17 06:39:07 +08:00
|
|
|
unsigned int i;
|
2011-12-09 11:14:27 +08:00
|
|
|
|
|
|
|
/* scan through physical windows and convert address */
|
2013-02-17 06:39:07 +08:00
|
|
|
for (i = 0; i < pfc->num_windows; i++) {
|
2013-12-11 11:26:25 +08:00
|
|
|
window = pfc->windows + i;
|
2011-12-09 11:14:27 +08:00
|
|
|
|
|
|
|
if (address < window->phys)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (address >= (window->phys + window->size))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
return window->virt + (address - window->phys);
|
|
|
|
}
|
|
|
|
|
2013-02-17 06:39:07 +08:00
|
|
|
BUG();
|
2013-03-26 08:44:52 +08:00
|
|
|
return NULL;
|
2011-12-09 11:14:27 +08:00
|
|
|
}
|
2008-10-08 19:41:43 +08:00
|
|
|
|
2013-03-09 00:43:54 +08:00
|
|
|
int sh_pfc_get_pin_index(struct sh_pfc *pfc, unsigned int pin)
|
2013-02-15 05:35:09 +08:00
|
|
|
{
|
2013-02-15 08:33:38 +08:00
|
|
|
unsigned int offset;
|
|
|
|
unsigned int i;
|
|
|
|
|
2013-07-16 00:38:30 +08:00
|
|
|
for (i = 0, offset = 0; i < pfc->nr_ranges; ++i) {
|
|
|
|
const struct sh_pfc_pin_range *range = &pfc->ranges[i];
|
2013-02-15 08:33:38 +08:00
|
|
|
|
|
|
|
if (pin <= range->end)
|
2013-07-16 00:38:30 +08:00
|
|
|
return pin >= range->start
|
|
|
|
? offset + pin - range->start : -1;
|
2013-02-15 08:33:38 +08:00
|
|
|
|
2013-07-16 00:38:30 +08:00
|
|
|
offset += range->end - range->start + 1;
|
2013-02-15 08:33:38 +08:00
|
|
|
}
|
|
|
|
|
2013-03-10 23:38:23 +08:00
|
|
|
return -EINVAL;
|
2013-02-15 05:35:09 +08:00
|
|
|
}
|
|
|
|
|
2013-07-15 19:03:20 +08:00
|
|
|
static int sh_pfc_enum_in_range(u16 enum_id, const struct pinmux_range *r)
|
2008-10-08 19:41:43 +08:00
|
|
|
{
|
|
|
|
if (enum_id < r->begin)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (enum_id > r->end)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-03-12 18:09:14 +08:00
|
|
|
u32 sh_pfc_read_raw_reg(void __iomem *mapped_reg, unsigned int reg_width)
|
2008-12-25 17:17:26 +08:00
|
|
|
{
|
|
|
|
switch (reg_width) {
|
|
|
|
case 8:
|
2011-12-09 11:14:27 +08:00
|
|
|
return ioread8(mapped_reg);
|
2008-12-25 17:17:26 +08:00
|
|
|
case 16:
|
2011-12-09 11:14:27 +08:00
|
|
|
return ioread16(mapped_reg);
|
2008-12-25 17:17:26 +08:00
|
|
|
case 32:
|
2011-12-09 11:14:27 +08:00
|
|
|
return ioread32(mapped_reg);
|
2008-12-25 17:17:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
BUG();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-03-12 18:09:14 +08:00
|
|
|
void sh_pfc_write_raw_reg(void __iomem *mapped_reg, unsigned int reg_width,
|
2015-02-28 01:38:04 +08:00
|
|
|
u32 data)
|
2008-12-25 17:17:26 +08:00
|
|
|
{
|
|
|
|
switch (reg_width) {
|
|
|
|
case 8:
|
2011-12-09 11:14:27 +08:00
|
|
|
iowrite8(data, mapped_reg);
|
2008-12-25 17:17:26 +08:00
|
|
|
return;
|
|
|
|
case 16:
|
2011-12-09 11:14:27 +08:00
|
|
|
iowrite16(data, mapped_reg);
|
2008-12-25 17:17:26 +08:00
|
|
|
return;
|
|
|
|
case 32:
|
2011-12-09 11:14:27 +08:00
|
|
|
iowrite32(data, mapped_reg);
|
2008-12-25 17:17:26 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
BUG();
|
|
|
|
}
|
|
|
|
|
2017-09-29 17:03:11 +08:00
|
|
|
u32 sh_pfc_read(struct sh_pfc *pfc, u32 reg)
|
2016-03-23 22:06:00 +08:00
|
|
|
{
|
2017-09-29 17:03:11 +08:00
|
|
|
return sh_pfc_read_raw_reg(sh_pfc_phys_to_virt(pfc, reg), 32);
|
2016-03-23 22:06:00 +08:00
|
|
|
}
|
|
|
|
|
2017-09-29 17:03:11 +08:00
|
|
|
void sh_pfc_write(struct sh_pfc *pfc, u32 reg, u32 data)
|
2016-03-23 22:06:00 +08:00
|
|
|
{
|
|
|
|
if (pfc->info->unlock_reg)
|
|
|
|
sh_pfc_write_raw_reg(
|
|
|
|
sh_pfc_phys_to_virt(pfc, pfc->info->unlock_reg), 32,
|
|
|
|
~data);
|
|
|
|
|
2017-09-29 17:03:11 +08:00
|
|
|
sh_pfc_write_raw_reg(sh_pfc_phys_to_virt(pfc, reg), 32, data);
|
2016-03-23 22:06:00 +08:00
|
|
|
}
|
|
|
|
|
2012-12-16 06:50:53 +08:00
|
|
|
static void sh_pfc_config_reg_helper(struct sh_pfc *pfc,
|
2013-02-17 01:47:05 +08:00
|
|
|
const struct pinmux_cfg_reg *crp,
|
2015-03-12 18:09:14 +08:00
|
|
|
unsigned int in_pos,
|
2015-02-28 01:38:04 +08:00
|
|
|
void __iomem **mapped_regp, u32 *maskp,
|
2015-03-12 18:09:14 +08:00
|
|
|
unsigned int *posp)
|
2008-10-08 19:41:43 +08:00
|
|
|
{
|
2013-12-11 11:26:21 +08:00
|
|
|
unsigned int k;
|
2011-12-14 00:01:05 +08:00
|
|
|
|
2012-12-16 06:50:53 +08:00
|
|
|
*mapped_regp = sh_pfc_phys_to_virt(pfc, crp->reg);
|
2008-10-08 19:41:43 +08:00
|
|
|
|
2011-12-14 00:01:05 +08:00
|
|
|
if (crp->field_width) {
|
|
|
|
*maskp = (1 << crp->field_width) - 1;
|
|
|
|
*posp = crp->reg_width - ((in_pos + 1) * crp->field_width);
|
|
|
|
} else {
|
|
|
|
*maskp = (1 << crp->var_field_width[in_pos]) - 1;
|
|
|
|
*posp = crp->reg_width;
|
|
|
|
for (k = 0; k <= in_pos; k++)
|
|
|
|
*posp -= crp->var_field_width[k];
|
|
|
|
}
|
2011-12-14 00:00:55 +08:00
|
|
|
}
|
|
|
|
|
2012-12-16 06:50:53 +08:00
|
|
|
static void sh_pfc_write_config_reg(struct sh_pfc *pfc,
|
2013-02-17 01:47:05 +08:00
|
|
|
const struct pinmux_cfg_reg *crp,
|
2015-03-12 18:09:14 +08:00
|
|
|
unsigned int field, u32 value)
|
2008-12-25 17:17:18 +08:00
|
|
|
{
|
2011-12-14 00:00:55 +08:00
|
|
|
void __iomem *mapped_reg;
|
2015-03-12 18:09:14 +08:00
|
|
|
unsigned int pos;
|
2015-02-28 01:38:04 +08:00
|
|
|
u32 mask, data;
|
2008-12-25 17:17:18 +08:00
|
|
|
|
2012-12-16 06:50:53 +08:00
|
|
|
sh_pfc_config_reg_helper(pfc, crp, field, &mapped_reg, &mask, &pos);
|
2008-10-08 19:41:43 +08:00
|
|
|
|
2015-03-12 18:09:16 +08:00
|
|
|
dev_dbg(pfc->dev, "write_reg addr = %x, value = 0x%x, field = %u, "
|
2015-03-12 18:09:13 +08:00
|
|
|
"r_width = %u, f_width = %u\n",
|
2013-03-11 01:00:02 +08:00
|
|
|
crp->reg, value, field, crp->reg_width, crp->field_width);
|
2008-12-25 17:17:18 +08:00
|
|
|
|
|
|
|
mask = ~(mask << pos);
|
|
|
|
value = value << pos;
|
2008-10-08 19:41:43 +08:00
|
|
|
|
2012-12-16 06:50:53 +08:00
|
|
|
data = sh_pfc_read_raw_reg(mapped_reg, crp->reg_width);
|
2011-12-14 00:01:14 +08:00
|
|
|
data &= mask;
|
|
|
|
data |= value;
|
|
|
|
|
2012-12-16 06:51:20 +08:00
|
|
|
if (pfc->info->unlock_reg)
|
2012-12-16 06:50:53 +08:00
|
|
|
sh_pfc_write_raw_reg(
|
2012-12-16 06:51:20 +08:00
|
|
|
sh_pfc_phys_to_virt(pfc, pfc->info->unlock_reg), 32,
|
2012-12-16 06:50:53 +08:00
|
|
|
~data);
|
2011-12-14 00:01:14 +08:00
|
|
|
|
2012-12-16 06:50:53 +08:00
|
|
|
sh_pfc_write_raw_reg(mapped_reg, crp->reg_width, data);
|
2008-10-08 19:41:43 +08:00
|
|
|
}
|
|
|
|
|
2013-07-15 19:03:20 +08:00
|
|
|
static int sh_pfc_get_config_reg(struct sh_pfc *pfc, u16 enum_id,
|
2015-03-12 18:09:14 +08:00
|
|
|
const struct pinmux_cfg_reg **crp,
|
|
|
|
unsigned int *fieldp, u32 *valuep)
|
2008-10-08 19:41:43 +08:00
|
|
|
{
|
2015-03-12 18:09:14 +08:00
|
|
|
unsigned int k = 0;
|
2008-10-08 19:41:43 +08:00
|
|
|
|
|
|
|
while (1) {
|
2015-03-12 18:09:14 +08:00
|
|
|
const struct pinmux_cfg_reg *config_reg =
|
|
|
|
pfc->info->cfg_regs + k;
|
|
|
|
unsigned int r_width = config_reg->reg_width;
|
|
|
|
unsigned int f_width = config_reg->field_width;
|
|
|
|
unsigned int curr_width;
|
|
|
|
unsigned int bit_pos;
|
|
|
|
unsigned int pos = 0;
|
|
|
|
unsigned int m = 0;
|
2008-10-08 19:41:43 +08:00
|
|
|
|
|
|
|
if (!r_width)
|
|
|
|
break;
|
2011-12-14 00:01:05 +08:00
|
|
|
|
|
|
|
for (bit_pos = 0; bit_pos < r_width; bit_pos += curr_width) {
|
2015-03-12 18:09:14 +08:00
|
|
|
u32 ncomb;
|
|
|
|
u32 n;
|
|
|
|
|
2011-12-14 00:01:05 +08:00
|
|
|
if (f_width)
|
|
|
|
curr_width = f_width;
|
|
|
|
else
|
|
|
|
curr_width = config_reg->var_field_width[m];
|
|
|
|
|
|
|
|
ncomb = 1 << curr_width;
|
|
|
|
for (n = 0; n < ncomb; n++) {
|
|
|
|
if (config_reg->enum_ids[pos + n] == enum_id) {
|
|
|
|
*crp = config_reg;
|
|
|
|
*fieldp = m;
|
|
|
|
*valuep = n;
|
|
|
|
return 0;
|
|
|
|
}
|
2008-10-08 19:41:43 +08:00
|
|
|
}
|
2011-12-14 00:01:05 +08:00
|
|
|
pos += ncomb;
|
|
|
|
m++;
|
2008-10-08 19:41:43 +08:00
|
|
|
}
|
|
|
|
k++;
|
|
|
|
}
|
|
|
|
|
2013-03-10 23:38:23 +08:00
|
|
|
return -EINVAL;
|
2008-10-08 19:41:43 +08:00
|
|
|
}
|
|
|
|
|
2013-07-15 19:03:20 +08:00
|
|
|
static int sh_pfc_mark_to_enum(struct sh_pfc *pfc, u16 mark, int pos,
|
|
|
|
u16 *enum_idp)
|
2008-10-08 19:41:43 +08:00
|
|
|
{
|
2015-09-21 22:27:23 +08:00
|
|
|
const u16 *data = pfc->info->pinmux_data;
|
2013-12-11 11:26:21 +08:00
|
|
|
unsigned int k;
|
2008-10-08 19:41:43 +08:00
|
|
|
|
|
|
|
if (pos) {
|
|
|
|
*enum_idp = data[pos + 1];
|
|
|
|
return pos + 1;
|
|
|
|
}
|
|
|
|
|
2015-09-21 22:27:23 +08:00
|
|
|
for (k = 0; k < pfc->info->pinmux_data_size; k++) {
|
2013-02-15 00:36:56 +08:00
|
|
|
if (data[k] == mark) {
|
2008-10-08 19:41:43 +08:00
|
|
|
*enum_idp = data[k + 1];
|
|
|
|
return k + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-11 01:00:02 +08:00
|
|
|
dev_err(pfc->dev, "cannot locate data/mark enum_id for mark %d\n",
|
|
|
|
mark);
|
2013-03-10 23:38:23 +08:00
|
|
|
return -EINVAL;
|
2008-10-08 19:41:43 +08:00
|
|
|
}
|
|
|
|
|
2013-03-10 22:29:14 +08:00
|
|
|
int sh_pfc_config_mux(struct sh_pfc *pfc, unsigned mark, int pinmux_type)
|
2008-10-08 19:41:43 +08:00
|
|
|
{
|
2013-02-17 01:47:05 +08:00
|
|
|
const struct pinmux_range *range;
|
2015-03-12 18:09:14 +08:00
|
|
|
int pos = 0;
|
2008-10-08 19:41:43 +08:00
|
|
|
|
|
|
|
switch (pinmux_type) {
|
2013-03-11 00:30:25 +08:00
|
|
|
case PINMUX_TYPE_GPIO:
|
2008-10-08 19:41:43 +08:00
|
|
|
case PINMUX_TYPE_FUNCTION:
|
|
|
|
range = NULL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PINMUX_TYPE_OUTPUT:
|
2012-12-16 06:51:20 +08:00
|
|
|
range = &pfc->info->output;
|
2008-10-08 19:41:43 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PINMUX_TYPE_INPUT:
|
2012-12-16 06:51:20 +08:00
|
|
|
range = &pfc->info->input;
|
2008-10-08 19:41:43 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2013-03-10 23:38:23 +08:00
|
|
|
return -EINVAL;
|
2008-10-08 19:41:43 +08:00
|
|
|
}
|
|
|
|
|
2013-03-11 00:30:25 +08:00
|
|
|
/* Iterate over all the configuration fields we need to update. */
|
2008-10-08 19:41:43 +08:00
|
|
|
while (1) {
|
2015-03-12 18:09:14 +08:00
|
|
|
const struct pinmux_cfg_reg *cr;
|
|
|
|
unsigned int field;
|
|
|
|
u16 enum_id;
|
|
|
|
u32 value;
|
|
|
|
int in_range;
|
|
|
|
int ret;
|
|
|
|
|
2013-02-15 00:36:56 +08:00
|
|
|
pos = sh_pfc_mark_to_enum(pfc, mark, pos, &enum_id);
|
2013-03-10 23:38:23 +08:00
|
|
|
if (pos < 0)
|
|
|
|
return pos;
|
2008-10-08 19:41:43 +08:00
|
|
|
|
|
|
|
if (!enum_id)
|
|
|
|
break;
|
|
|
|
|
2013-03-11 00:30:25 +08:00
|
|
|
/* Check if the configuration field selects a function. If it
|
|
|
|
* doesn't, skip the field if it's not applicable to the
|
|
|
|
* requested pinmux type.
|
|
|
|
*/
|
2012-12-16 06:51:20 +08:00
|
|
|
in_range = sh_pfc_enum_in_range(enum_id, &pfc->info->function);
|
2010-01-19 21:52:28 +08:00
|
|
|
if (!in_range) {
|
2013-03-11 00:30:25 +08:00
|
|
|
if (pinmux_type == PINMUX_TYPE_FUNCTION) {
|
|
|
|
/* Functions are allowed to modify all
|
|
|
|
* fields.
|
|
|
|
*/
|
|
|
|
in_range = 1;
|
|
|
|
} else if (pinmux_type != PINMUX_TYPE_GPIO) {
|
|
|
|
/* Input/output types can only modify fields
|
|
|
|
* that correspond to their respective ranges.
|
2010-01-19 21:52:28 +08:00
|
|
|
*/
|
2012-12-16 06:50:53 +08:00
|
|
|
in_range = sh_pfc_enum_in_range(enum_id, range);
|
2010-01-19 21:52:28 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* special case pass through for fixed
|
|
|
|
* input-only or output-only pins without
|
|
|
|
* function enum register association.
|
|
|
|
*/
|
|
|
|
if (in_range && enum_id == range->force)
|
|
|
|
continue;
|
|
|
|
}
|
2013-03-11 00:30:25 +08:00
|
|
|
/* GPIOs are only allowed to modify function fields. */
|
2008-10-22 17:29:17 +08:00
|
|
|
}
|
|
|
|
|
2008-10-08 19:41:43 +08:00
|
|
|
if (!in_range)
|
|
|
|
continue;
|
|
|
|
|
2013-03-10 23:38:23 +08:00
|
|
|
ret = sh_pfc_get_config_reg(pfc, enum_id, &cr, &field, &value);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2008-10-08 19:41:43 +08:00
|
|
|
|
2013-03-10 22:29:14 +08:00
|
|
|
sh_pfc_write_config_reg(pfc, cr, field, value);
|
2008-10-08 19:41:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-09-29 21:44:38 +08:00
|
|
|
const struct pinmux_bias_reg *
|
|
|
|
sh_pfc_pin_to_bias_reg(const struct sh_pfc *pfc, unsigned int pin,
|
|
|
|
unsigned int *bit)
|
|
|
|
{
|
|
|
|
unsigned int i, j;
|
|
|
|
|
|
|
|
for (i = 0; pfc->info->bias_regs[i].puen; i++) {
|
|
|
|
for (j = 0; j < ARRAY_SIZE(pfc->info->bias_regs[i].pins); j++) {
|
|
|
|
if (pfc->info->bias_regs[i].pins[j] == pin) {
|
|
|
|
*bit = j;
|
|
|
|
return &pfc->info->bias_regs[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN_ONCE(1, "Pin %u is not in bias info list\n", pin);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-07-16 00:38:30 +08:00
|
|
|
static int sh_pfc_init_ranges(struct sh_pfc *pfc)
|
|
|
|
{
|
|
|
|
struct sh_pfc_pin_range *range;
|
|
|
|
unsigned int nr_ranges;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
if (pfc->info->pins[0].pin == (u16)-1) {
|
|
|
|
/* Pin number -1 denotes that the SoC doesn't report pin numbers
|
|
|
|
* in its pin arrays yet. Consider the pin numbers range as
|
|
|
|
* continuous and allocate a single range.
|
|
|
|
*/
|
|
|
|
pfc->nr_ranges = 1;
|
|
|
|
pfc->ranges = devm_kzalloc(pfc->dev, sizeof(*pfc->ranges),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (pfc->ranges == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
pfc->ranges->start = 0;
|
|
|
|
pfc->ranges->end = pfc->info->nr_pins - 1;
|
|
|
|
pfc->nr_gpio_pins = pfc->info->nr_pins;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-07-16 03:10:54 +08:00
|
|
|
/* Count, allocate and fill the ranges. The PFC SoC data pins array must
|
|
|
|
* be sorted by pin numbers, and pins without a GPIO port must come
|
|
|
|
* last.
|
|
|
|
*/
|
2013-07-16 00:38:30 +08:00
|
|
|
for (i = 1, nr_ranges = 1; i < pfc->info->nr_pins; ++i) {
|
|
|
|
if (pfc->info->pins[i-1].pin != pfc->info->pins[i].pin - 1)
|
|
|
|
nr_ranges++;
|
|
|
|
}
|
|
|
|
|
|
|
|
pfc->nr_ranges = nr_ranges;
|
treewide: devm_kzalloc() -> devm_kcalloc()
The devm_kzalloc() function has a 2-factor argument form, devm_kcalloc().
This patch replaces cases of:
devm_kzalloc(handle, a * b, gfp)
with:
devm_kcalloc(handle, a * b, gfp)
as well as handling cases of:
devm_kzalloc(handle, a * b * c, gfp)
with:
devm_kzalloc(handle, array3_size(a, b, c), gfp)
as it's slightly less ugly than:
devm_kcalloc(handle, array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
devm_kzalloc(handle, 4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
Some manual whitespace fixes were needed in this patch, as Coccinelle
really liked to write "=devm_kcalloc..." instead of "= devm_kcalloc...".
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
expression HANDLE;
type TYPE;
expression THING, E;
@@
(
devm_kzalloc(HANDLE,
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
devm_kzalloc(HANDLE,
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression HANDLE;
expression COUNT;
typedef u8;
typedef __u8;
@@
(
devm_kzalloc(HANDLE,
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(char) * COUNT
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
expression HANDLE;
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
expression HANDLE;
identifier SIZE, COUNT;
@@
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression HANDLE;
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
devm_kzalloc(HANDLE,
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression HANDLE;
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
expression HANDLE;
identifier STRIDE, SIZE, COUNT;
@@
(
devm_kzalloc(HANDLE,
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression HANDLE;
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
devm_kzalloc(HANDLE, C1 * C2 * C3, ...)
|
devm_kzalloc(HANDLE,
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
devm_kzalloc(HANDLE,
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
devm_kzalloc(HANDLE,
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
devm_kzalloc(HANDLE,
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression HANDLE;
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
devm_kzalloc(HANDLE, sizeof(THING) * C2, ...)
|
devm_kzalloc(HANDLE, sizeof(TYPE) * C2, ...)
|
devm_kzalloc(HANDLE, C1 * C2 * C3, ...)
|
devm_kzalloc(HANDLE, C1 * C2, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- (E1) * E2
+ E1, E2
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- (E1) * (E2)
+ E1, E2
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-13 05:07:58 +08:00
|
|
|
pfc->ranges = devm_kcalloc(pfc->dev, nr_ranges, sizeof(*pfc->ranges),
|
2013-07-16 00:38:30 +08:00
|
|
|
GFP_KERNEL);
|
|
|
|
if (pfc->ranges == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
range = pfc->ranges;
|
|
|
|
range->start = pfc->info->pins[0].pin;
|
|
|
|
|
|
|
|
for (i = 1; i < pfc->info->nr_pins; ++i) {
|
2013-07-16 03:10:54 +08:00
|
|
|
if (pfc->info->pins[i-1].pin == pfc->info->pins[i].pin - 1)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
range->end = pfc->info->pins[i-1].pin;
|
|
|
|
if (!(pfc->info->pins[i-1].configs & SH_PFC_PIN_CFG_NO_GPIO))
|
|
|
|
pfc->nr_gpio_pins = range->end + 1;
|
|
|
|
|
|
|
|
range++;
|
|
|
|
range->start = pfc->info->pins[i].pin;
|
2013-07-16 00:38:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
range->end = pfc->info->pins[i-1].pin;
|
2013-07-16 03:10:54 +08:00
|
|
|
if (!(pfc->info->pins[i-1].configs & SH_PFC_PIN_CFG_NO_GPIO))
|
|
|
|
pfc->nr_gpio_pins = range->end + 1;
|
2013-07-16 00:38:30 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-06-18 02:50:02 +08:00
|
|
|
#ifdef CONFIG_OF
|
|
|
|
static const struct of_device_id sh_pfc_of_table[] = {
|
2015-01-25 21:49:52 +08:00
|
|
|
#ifdef CONFIG_PINCTRL_PFC_EMEV2
|
|
|
|
{
|
|
|
|
.compatible = "renesas,pfc-emev2",
|
|
|
|
.data = &emev2_pinmux_info,
|
|
|
|
},
|
|
|
|
#endif
|
2013-06-18 02:50:02 +08:00
|
|
|
#ifdef CONFIG_PINCTRL_PFC_R8A73A4
|
|
|
|
{
|
|
|
|
.compatible = "renesas,pfc-r8a73a4",
|
|
|
|
.data = &r8a73a4_pinmux_info,
|
|
|
|
},
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_PINCTRL_PFC_R8A7740
|
|
|
|
{
|
|
|
|
.compatible = "renesas,pfc-r8a7740",
|
|
|
|
.data = &r8a7740_pinmux_info,
|
|
|
|
},
|
|
|
|
#endif
|
2017-04-21 02:46:08 +08:00
|
|
|
#ifdef CONFIG_PINCTRL_PFC_R8A7743
|
|
|
|
{
|
|
|
|
.compatible = "renesas,pfc-r8a7743",
|
|
|
|
.data = &r8a7743_pinmux_info,
|
|
|
|
},
|
|
|
|
#endif
|
2017-04-29 02:52:35 +08:00
|
|
|
#ifdef CONFIG_PINCTRL_PFC_R8A7745
|
|
|
|
{
|
|
|
|
.compatible = "renesas,pfc-r8a7745",
|
|
|
|
.data = &r8a7745_pinmux_info,
|
|
|
|
},
|
|
|
|
#endif
|
2018-04-24 19:03:08 +08:00
|
|
|
#ifdef CONFIG_PINCTRL_PFC_R8A77470
|
|
|
|
{
|
|
|
|
.compatible = "renesas,pfc-r8a77470",
|
|
|
|
.data = &r8a77470_pinmux_info,
|
|
|
|
},
|
|
|
|
#endif
|
2018-08-13 21:52:32 +08:00
|
|
|
#ifdef CONFIG_PINCTRL_PFC_R8A774A1
|
|
|
|
{
|
|
|
|
.compatible = "renesas,pfc-r8a774a1",
|
|
|
|
.data = &r8a774a1_pinmux_info,
|
|
|
|
},
|
|
|
|
#endif
|
2013-06-18 02:50:02 +08:00
|
|
|
#ifdef CONFIG_PINCTRL_PFC_R8A7778
|
|
|
|
{
|
|
|
|
.compatible = "renesas,pfc-r8a7778",
|
|
|
|
.data = &r8a7778_pinmux_info,
|
|
|
|
},
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_PINCTRL_PFC_R8A7779
|
|
|
|
{
|
|
|
|
.compatible = "renesas,pfc-r8a7779",
|
|
|
|
.data = &r8a7779_pinmux_info,
|
|
|
|
},
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_PINCTRL_PFC_R8A7790
|
|
|
|
{
|
|
|
|
.compatible = "renesas,pfc-r8a7790",
|
|
|
|
.data = &r8a7790_pinmux_info,
|
|
|
|
},
|
|
|
|
#endif
|
2013-10-17 05:46:05 +08:00
|
|
|
#ifdef CONFIG_PINCTRL_PFC_R8A7791
|
|
|
|
{
|
|
|
|
.compatible = "renesas,pfc-r8a7791",
|
|
|
|
.data = &r8a7791_pinmux_info,
|
|
|
|
},
|
|
|
|
#endif
|
2016-06-30 05:21:08 +08:00
|
|
|
#ifdef CONFIG_PINCTRL_PFC_R8A7792
|
|
|
|
{
|
|
|
|
.compatible = "renesas,pfc-r8a7792",
|
|
|
|
.data = &r8a7792_pinmux_info,
|
|
|
|
},
|
|
|
|
#endif
|
2015-05-12 17:13:19 +08:00
|
|
|
#ifdef CONFIG_PINCTRL_PFC_R8A7793
|
|
|
|
{
|
|
|
|
.compatible = "renesas,pfc-r8a7793",
|
|
|
|
.data = &r8a7793_pinmux_info,
|
|
|
|
},
|
|
|
|
#endif
|
pinctrl: sh-pfc: add R8A7794 PFC support
Add PFC support for the R8A7794 SoC including pin groups for some
on-chip devices such as ETH, I2C, INTC, MSIOF, QSPI, [H]SCIF...
Sergei: squashed together several patches, fixed the MLB_CLK typo,
added IRQ4.. IRQ9 pin groups, fixed IRQn comments, added ETH B pin
group names, removed stray new line and fixed typos in the comments
in the pinmux_config_regs[] initializer, removed the platform device
ID, took into account limited number of signals in the GPIO1/5/6
controllers, added reasonable and removed unreasonable
copyrights, modified the bindings document, renamed, added changelog.
Changes in version 5:
- resolved rejects, refreshed the patch;
- added Laurent Pinchart's ACK.
Changes in version 4:
- reused the PORT_GP_26() macro to #define PORT_GP_28().
Changes in version 3:
- removed the platform device ID;
- added PORT_GP_26() and PORT_GP_28() macros, used them for GPIO1/5/6 in the
CPU_ALL_PORT() macro.
Changes in version 2:
- rebased the patch.
Signed-off-by: Hisashi Nakamura <hisashi.nakamura.ak@renesas.com>
Signed-off-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2015-06-06 06:34:48 +08:00
|
|
|
#ifdef CONFIG_PINCTRL_PFC_R8A7794
|
|
|
|
{
|
|
|
|
.compatible = "renesas,pfc-r8a7794",
|
|
|
|
.data = &r8a7794_pinmux_info,
|
|
|
|
},
|
|
|
|
#endif
|
2015-09-03 10:51:49 +08:00
|
|
|
#ifdef CONFIG_PINCTRL_PFC_R8A7795
|
|
|
|
{
|
|
|
|
.compatible = "renesas,pfc-r8a7795",
|
|
|
|
.data = &r8a7795_pinmux_info,
|
|
|
|
},
|
|
|
|
#endif
|
2016-08-18 21:12:32 +08:00
|
|
|
#ifdef CONFIG_PINCTRL_PFC_R8A7796
|
|
|
|
{
|
|
|
|
.compatible = "renesas,pfc-r8a7796",
|
|
|
|
.data = &r8a7796_pinmux_info,
|
|
|
|
},
|
|
|
|
#endif
|
2018-02-20 23:12:07 +08:00
|
|
|
#ifdef CONFIG_PINCTRL_PFC_R8A77965
|
|
|
|
{
|
|
|
|
.compatible = "renesas,pfc-r8a77965",
|
|
|
|
.data = &r8a77965_pinmux_info,
|
|
|
|
},
|
|
|
|
#endif
|
2017-11-11 01:59:01 +08:00
|
|
|
#ifdef CONFIG_PINCTRL_PFC_R8A77970
|
|
|
|
{
|
|
|
|
.compatible = "renesas,pfc-r8a77970",
|
|
|
|
.data = &r8a77970_pinmux_info,
|
|
|
|
},
|
|
|
|
#endif
|
2018-03-09 03:14:32 +08:00
|
|
|
#ifdef CONFIG_PINCTRL_PFC_R8A77980
|
|
|
|
{
|
|
|
|
.compatible = "renesas,pfc-r8a77980",
|
|
|
|
.data = &r8a77980_pinmux_info,
|
|
|
|
},
|
|
|
|
#endif
|
2018-05-11 11:22:23 +08:00
|
|
|
#ifdef CONFIG_PINCTRL_PFC_R8A77990
|
|
|
|
{
|
|
|
|
.compatible = "renesas,pfc-r8a77990",
|
|
|
|
.data = &r8a77990_pinmux_info,
|
|
|
|
},
|
|
|
|
#endif
|
2017-08-09 20:19:41 +08:00
|
|
|
#ifdef CONFIG_PINCTRL_PFC_R8A77995
|
|
|
|
{
|
|
|
|
.compatible = "renesas,pfc-r8a77995",
|
|
|
|
.data = &r8a77995_pinmux_info,
|
|
|
|
},
|
|
|
|
#endif
|
2013-06-18 02:50:02 +08:00
|
|
|
#ifdef CONFIG_PINCTRL_PFC_SH73A0
|
|
|
|
{
|
|
|
|
.compatible = "renesas,pfc-sh73a0",
|
|
|
|
.data = &sh73a0_pinmux_info,
|
|
|
|
},
|
|
|
|
#endif
|
|
|
|
{ },
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
pinctrl: sh-pfc: Save/restore registers for PSCI system suspend
During PSCI system suspend, R-Car Gen3 SoCs are powered down, and their
pinctrl register state is lost. Note that as the boot loader skips most
initialization after system resume, pinctrl register state differs from
the state encountered during normal system boot, too.
To fix this, save all GPIO and peripheral function select, module
select, drive strength control, bias, and other I/O control registers
during system suspend, and restore them during system resume.
Note that to avoid overhead on platforms not needing it, the
suspend/resume code has a build time dependency on sleep and PSCI
support, and a runtime dependency on PSCI.
Inspired by a patch in the BSP by Hien Dang.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
2017-09-29 20:17:18 +08:00
|
|
|
#if defined(CONFIG_PM_SLEEP) && defined(CONFIG_ARM_PSCI_FW)
|
|
|
|
static void sh_pfc_nop_reg(struct sh_pfc *pfc, u32 reg, unsigned int idx)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sh_pfc_save_reg(struct sh_pfc *pfc, u32 reg, unsigned int idx)
|
|
|
|
{
|
|
|
|
pfc->saved_regs[idx] = sh_pfc_read(pfc, reg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sh_pfc_restore_reg(struct sh_pfc *pfc, u32 reg, unsigned int idx)
|
|
|
|
{
|
|
|
|
sh_pfc_write(pfc, reg, pfc->saved_regs[idx]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int sh_pfc_walk_regs(struct sh_pfc *pfc,
|
|
|
|
void (*do_reg)(struct sh_pfc *pfc, u32 reg, unsigned int idx))
|
|
|
|
{
|
|
|
|
unsigned int i, n = 0;
|
|
|
|
|
|
|
|
if (pfc->info->cfg_regs)
|
|
|
|
for (i = 0; pfc->info->cfg_regs[i].reg; i++)
|
|
|
|
do_reg(pfc, pfc->info->cfg_regs[i].reg, n++);
|
|
|
|
|
|
|
|
if (pfc->info->drive_regs)
|
|
|
|
for (i = 0; pfc->info->drive_regs[i].reg; i++)
|
|
|
|
do_reg(pfc, pfc->info->drive_regs[i].reg, n++);
|
|
|
|
|
|
|
|
if (pfc->info->bias_regs)
|
|
|
|
for (i = 0; pfc->info->bias_regs[i].puen; i++) {
|
|
|
|
do_reg(pfc, pfc->info->bias_regs[i].puen, n++);
|
|
|
|
if (pfc->info->bias_regs[i].pud)
|
|
|
|
do_reg(pfc, pfc->info->bias_regs[i].pud, n++);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pfc->info->ioctrl_regs)
|
|
|
|
for (i = 0; pfc->info->ioctrl_regs[i].reg; i++)
|
|
|
|
do_reg(pfc, pfc->info->ioctrl_regs[i].reg, n++);
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sh_pfc_suspend_init(struct sh_pfc *pfc)
|
|
|
|
{
|
|
|
|
unsigned int n;
|
|
|
|
|
|
|
|
/* This is the best we can do to check for the presence of PSCI */
|
|
|
|
if (!psci_ops.cpu_suspend)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
n = sh_pfc_walk_regs(pfc, sh_pfc_nop_reg);
|
|
|
|
if (!n)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
pfc->saved_regs = devm_kmalloc_array(pfc->dev, n,
|
|
|
|
sizeof(*pfc->saved_regs),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!pfc->saved_regs)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
dev_dbg(pfc->dev, "Allocated space to save %u regs\n", n);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sh_pfc_suspend_noirq(struct device *dev)
|
|
|
|
{
|
|
|
|
struct sh_pfc *pfc = dev_get_drvdata(dev);
|
|
|
|
|
|
|
|
if (pfc->saved_regs)
|
|
|
|
sh_pfc_walk_regs(pfc, sh_pfc_save_reg);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sh_pfc_resume_noirq(struct device *dev)
|
|
|
|
{
|
|
|
|
struct sh_pfc *pfc = dev_get_drvdata(dev);
|
|
|
|
|
|
|
|
if (pfc->saved_regs)
|
|
|
|
sh_pfc_walk_regs(pfc, sh_pfc_restore_reg);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct dev_pm_ops sh_pfc_pm = {
|
|
|
|
SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(sh_pfc_suspend_noirq, sh_pfc_resume_noirq)
|
|
|
|
};
|
|
|
|
#define DEV_PM_OPS &sh_pfc_pm
|
|
|
|
#else
|
|
|
|
static int sh_pfc_suspend_init(struct sh_pfc *pfc) { return 0; }
|
|
|
|
#define DEV_PM_OPS NULL
|
|
|
|
#endif /* CONFIG_PM_SLEEP && CONFIG_ARM_PSCI_FW */
|
|
|
|
|
2012-12-16 06:50:47 +08:00
|
|
|
static int sh_pfc_probe(struct platform_device *pdev)
|
2008-10-08 19:41:43 +08:00
|
|
|
{
|
2013-06-18 02:50:02 +08:00
|
|
|
#ifdef CONFIG_OF
|
|
|
|
struct device_node *np = pdev->dev.of_node;
|
|
|
|
#endif
|
2013-02-17 01:47:05 +08:00
|
|
|
const struct sh_pfc_soc_info *info;
|
2012-12-16 06:50:47 +08:00
|
|
|
struct sh_pfc *pfc;
|
2008-12-25 17:17:18 +08:00
|
|
|
int ret;
|
2008-10-08 19:41:43 +08:00
|
|
|
|
2013-06-18 02:50:02 +08:00
|
|
|
#ifdef CONFIG_OF
|
|
|
|
if (np)
|
2016-03-02 00:38:46 +08:00
|
|
|
info = of_device_get_match_data(&pdev->dev);
|
2013-06-18 02:50:02 +08:00
|
|
|
else
|
|
|
|
#endif
|
2017-09-29 16:08:56 +08:00
|
|
|
info = (const void *)platform_get_device_id(pdev)->driver_data;
|
2008-10-08 19:41:43 +08:00
|
|
|
|
2013-02-14 20:23:47 +08:00
|
|
|
pfc = devm_kzalloc(&pdev->dev, sizeof(*pfc), GFP_KERNEL);
|
2012-12-16 06:50:47 +08:00
|
|
|
if (pfc == NULL)
|
|
|
|
return -ENOMEM;
|
2012-12-16 06:50:43 +08:00
|
|
|
|
2012-12-16 06:51:20 +08:00
|
|
|
pfc->info = info;
|
2012-12-16 06:50:47 +08:00
|
|
|
pfc->dev = &pdev->dev;
|
|
|
|
|
2013-12-11 11:26:26 +08:00
|
|
|
ret = sh_pfc_map_resources(pfc, pdev);
|
2012-12-16 06:50:47 +08:00
|
|
|
if (unlikely(ret < 0))
|
2011-12-09 11:14:27 +08:00
|
|
|
return ret;
|
|
|
|
|
2012-12-16 06:50:47 +08:00
|
|
|
spin_lock_init(&pfc->lock);
|
2008-12-25 17:17:34 +08:00
|
|
|
|
2013-04-22 02:21:57 +08:00
|
|
|
if (info->ops && info->ops->init) {
|
|
|
|
ret = info->ops->init(pfc);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2017-03-10 02:20:48 +08:00
|
|
|
|
|
|
|
/* .init() may have overridden pfc->info */
|
|
|
|
info = pfc->info;
|
2013-04-22 02:21:57 +08:00
|
|
|
}
|
|
|
|
|
pinctrl: sh-pfc: Save/restore registers for PSCI system suspend
During PSCI system suspend, R-Car Gen3 SoCs are powered down, and their
pinctrl register state is lost. Note that as the boot loader skips most
initialization after system resume, pinctrl register state differs from
the state encountered during normal system boot, too.
To fix this, save all GPIO and peripheral function select, module
select, drive strength control, bias, and other I/O control registers
during system suspend, and restore them during system resume.
Note that to avoid overhead on platforms not needing it, the
suspend/resume code has a build time dependency on sleep and PSCI
support, and a runtime dependency on PSCI.
Inspired by a patch in the BSP by Hien Dang.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
2017-09-29 20:17:18 +08:00
|
|
|
ret = sh_pfc_suspend_init(pfc);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2016-03-08 02:40:57 +08:00
|
|
|
/* Enable dummy states for those platforms without pinctrl support */
|
|
|
|
if (!of_have_populated_dt())
|
|
|
|
pinctrl_provide_dummies();
|
2011-12-09 11:14:27 +08:00
|
|
|
|
2013-07-16 00:38:30 +08:00
|
|
|
ret = sh_pfc_init_ranges(pfc);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
2012-07-10 11:08:14 +08:00
|
|
|
/*
|
|
|
|
* Initialize pinctrl bindings first
|
|
|
|
*/
|
2012-12-16 06:50:47 +08:00
|
|
|
ret = sh_pfc_register_pinctrl(pfc);
|
2012-12-16 06:50:45 +08:00
|
|
|
if (unlikely(ret != 0))
|
2014-09-11 05:55:55 +08:00
|
|
|
return ret;
|
2012-07-10 11:08:14 +08:00
|
|
|
|
2016-02-17 16:15:49 +08:00
|
|
|
#ifdef CONFIG_PINCTRL_SH_PFC_GPIO
|
2012-07-10 11:08:14 +08:00
|
|
|
/*
|
|
|
|
* Then the GPIO chip
|
|
|
|
*/
|
2012-12-16 06:50:47 +08:00
|
|
|
ret = sh_pfc_register_gpiochip(pfc);
|
2012-12-16 06:50:46 +08:00
|
|
|
if (unlikely(ret != 0)) {
|
2012-07-10 11:08:14 +08:00
|
|
|
/*
|
|
|
|
* If the GPIO chip fails to come up we still leave the
|
|
|
|
* PFC state as it is, given that there are already
|
|
|
|
* extant users of it that have succeeded by this point.
|
|
|
|
*/
|
2013-03-11 01:00:02 +08:00
|
|
|
dev_notice(pfc->dev, "failed to init GPIO chip, ignoring...\n");
|
2012-06-20 16:29:04 +08:00
|
|
|
}
|
2012-12-16 06:50:46 +08:00
|
|
|
#endif
|
2010-10-04 02:54:56 +08:00
|
|
|
|
2012-12-16 06:50:47 +08:00
|
|
|
platform_set_drvdata(pdev, pfc);
|
|
|
|
|
2013-03-11 01:00:02 +08:00
|
|
|
dev_info(pfc->dev, "%s support registered\n", info->name);
|
2012-07-10 11:08:14 +08:00
|
|
|
|
2012-06-20 16:29:04 +08:00
|
|
|
return 0;
|
2010-10-04 02:54:56 +08:00
|
|
|
}
|
2012-12-16 06:50:46 +08:00
|
|
|
|
2012-12-16 06:50:47 +08:00
|
|
|
static const struct platform_device_id sh_pfc_id_table[] = {
|
2012-12-16 06:51:29 +08:00
|
|
|
#ifdef CONFIG_PINCTRL_PFC_SH7203
|
|
|
|
{ "pfc-sh7203", (kernel_ulong_t)&sh7203_pinmux_info },
|
|
|
|
#endif
|
2012-12-16 06:51:30 +08:00
|
|
|
#ifdef CONFIG_PINCTRL_PFC_SH7264
|
|
|
|
{ "pfc-sh7264", (kernel_ulong_t)&sh7264_pinmux_info },
|
|
|
|
#endif
|
2012-12-16 06:51:31 +08:00
|
|
|
#ifdef CONFIG_PINCTRL_PFC_SH7269
|
|
|
|
{ "pfc-sh7269", (kernel_ulong_t)&sh7269_pinmux_info },
|
|
|
|
#endif
|
2012-12-16 06:51:32 +08:00
|
|
|
#ifdef CONFIG_PINCTRL_PFC_SH7720
|
|
|
|
{ "pfc-sh7720", (kernel_ulong_t)&sh7720_pinmux_info },
|
2012-12-16 06:51:33 +08:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_PINCTRL_PFC_SH7722
|
|
|
|
{ "pfc-sh7722", (kernel_ulong_t)&sh7722_pinmux_info },
|
2012-12-16 06:51:34 +08:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_PINCTRL_PFC_SH7723
|
|
|
|
{ "pfc-sh7723", (kernel_ulong_t)&sh7723_pinmux_info },
|
2012-12-16 06:51:35 +08:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_PINCTRL_PFC_SH7724
|
|
|
|
{ "pfc-sh7724", (kernel_ulong_t)&sh7724_pinmux_info },
|
2012-12-16 06:51:36 +08:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_PINCTRL_PFC_SH7734
|
|
|
|
{ "pfc-sh7734", (kernel_ulong_t)&sh7734_pinmux_info },
|
2012-12-16 06:51:37 +08:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_PINCTRL_PFC_SH7757
|
|
|
|
{ "pfc-sh7757", (kernel_ulong_t)&sh7757_pinmux_info },
|
2012-12-16 06:51:38 +08:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_PINCTRL_PFC_SH7785
|
|
|
|
{ "pfc-sh7785", (kernel_ulong_t)&sh7785_pinmux_info },
|
2012-12-16 06:51:39 +08:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_PINCTRL_PFC_SH7786
|
|
|
|
{ "pfc-sh7786", (kernel_ulong_t)&sh7786_pinmux_info },
|
2012-12-16 06:51:40 +08:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_PINCTRL_PFC_SHX3
|
|
|
|
{ "pfc-shx3", (kernel_ulong_t)&shx3_pinmux_info },
|
2012-12-16 06:51:21 +08:00
|
|
|
#endif
|
2012-12-16 06:50:47 +08:00
|
|
|
{ },
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct platform_driver sh_pfc_driver = {
|
|
|
|
.probe = sh_pfc_probe,
|
|
|
|
.id_table = sh_pfc_id_table,
|
|
|
|
.driver = {
|
|
|
|
.name = DRV_NAME,
|
2013-06-18 02:50:02 +08:00
|
|
|
.of_match_table = of_match_ptr(sh_pfc_of_table),
|
pinctrl: sh-pfc: Save/restore registers for PSCI system suspend
During PSCI system suspend, R-Car Gen3 SoCs are powered down, and their
pinctrl register state is lost. Note that as the boot loader skips most
initialization after system resume, pinctrl register state differs from
the state encountered during normal system boot, too.
To fix this, save all GPIO and peripheral function select, module
select, drive strength control, bias, and other I/O control registers
during system suspend, and restore them during system resume.
Note that to avoid overhead on platforms not needing it, the
suspend/resume code has a build time dependency on sleep and PSCI
support, and a runtime dependency on PSCI.
Inspired by a patch in the BSP by Hien Dang.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
2017-09-29 20:17:18 +08:00
|
|
|
.pm = DEV_PM_OPS,
|
2012-12-16 06:50:47 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2012-12-16 06:50:54 +08:00
|
|
|
static int __init sh_pfc_init(void)
|
|
|
|
{
|
|
|
|
return platform_driver_register(&sh_pfc_driver);
|
2012-12-16 06:50:47 +08:00
|
|
|
}
|
2012-12-16 06:50:54 +08:00
|
|
|
postcore_initcall(sh_pfc_init);
|