2019-05-27 09:55:01 +03:00
// SPDX-License-Identifier: GPL-2.0-or-later
2015-05-05 13:55:10 +03:00
/*
* Driver for Conexant Digicolor General Purpose Pin Mapping
*
* Author : Baruch Siach < baruch @ tkos . co . il >
*
* Copyright ( C ) 2015 Paradox Innovation Ltd .
*
* TODO :
* - GPIO interrupt support
* - Pin pad configuration ( pull up / down , strength )
*/
2023-01-13 17:36:40 +03:00
# include <linux/gpio/driver.h>
2016-06-07 05:43:07 +03:00
# include <linux/init.h>
2015-05-05 13:55:10 +03:00
# include <linux/io.h>
2023-01-13 17:36:40 +03:00
# include <linux/mod_devicetable.h>
# include <linux/platform_device.h>
2015-05-05 13:55:10 +03:00
# include <linux/spinlock.h>
2023-01-13 17:36:40 +03:00
2015-05-05 13:55:10 +03:00
# include <linux/pinctrl/machine.h>
# include <linux/pinctrl/pinconf.h>
# include <linux/pinctrl/pinconf-generic.h>
# include <linux/pinctrl/pinctrl.h>
# include <linux/pinctrl/pinmux.h>
2023-01-13 17:36:40 +03:00
2015-05-05 13:55:10 +03:00
# include "pinctrl-utils.h"
# define DRIVER_NAME "pinctrl-digicolor"
# define GP_CLIENTSEL(clct) ((clct)*8 + 0x20)
# define GP_DRIVE0(clct) (GP_CLIENTSEL(clct) + 2)
# define GP_OUTPUT0(clct) (GP_CLIENTSEL(clct) + 3)
# define GP_INPUT(clct) (GP_CLIENTSEL(clct) + 6)
# define PIN_COLLECTIONS ('R' - 'A' + 1)
# define PINS_PER_COLLECTION 8
# define PINS_COUNT (PIN_COLLECTIONS * PINS_PER_COLLECTION)
struct dc_pinmap {
void __iomem * regs ;
struct device * dev ;
struct pinctrl_dev * pctl ;
struct pinctrl_desc * desc ;
const char * pin_names [ PINS_COUNT ] ;
struct gpio_chip chip ;
spinlock_t lock ;
} ;
static int dc_get_groups_count ( struct pinctrl_dev * pctldev )
{
return PINS_COUNT ;
}
static const char * dc_get_group_name ( struct pinctrl_dev * pctldev ,
unsigned selector )
{
struct dc_pinmap * pmap = pinctrl_dev_get_drvdata ( pctldev ) ;
/* Exactly one group per pin */
return pmap - > desc - > pins [ selector ] . name ;
}
static int dc_get_group_pins ( struct pinctrl_dev * pctldev , unsigned selector ,
const unsigned * * pins ,
unsigned * num_pins )
{
struct dc_pinmap * pmap = pinctrl_dev_get_drvdata ( pctldev ) ;
* pins = & pmap - > desc - > pins [ selector ] . number ;
* num_pins = 1 ;
return 0 ;
}
2017-08-10 13:06:19 +03:00
static const struct pinctrl_ops dc_pinctrl_ops = {
2015-05-05 13:55:10 +03:00
. get_groups_count = dc_get_groups_count ,
. get_group_name = dc_get_group_name ,
. get_group_pins = dc_get_group_pins ,
. dt_node_to_map = pinconf_generic_dt_node_to_map_pin ,
2016-03-31 14:44:42 +03:00
. dt_free_map = pinctrl_utils_free_map ,
2015-05-05 13:55:10 +03:00
} ;
static const char * const dc_functions [ ] = {
" gpio " ,
" client_a " ,
" client_b " ,
" client_c " ,
} ;
static int dc_get_functions_count ( struct pinctrl_dev * pctldev )
{
return ARRAY_SIZE ( dc_functions ) ;
}
static const char * dc_get_fname ( struct pinctrl_dev * pctldev , unsigned selector )
{
return dc_functions [ selector ] ;
}
static int dc_get_groups ( struct pinctrl_dev * pctldev , unsigned selector ,
const char * const * * groups ,
unsigned * const num_groups )
{
struct dc_pinmap * pmap = pinctrl_dev_get_drvdata ( pctldev ) ;
* groups = pmap - > pin_names ;
* num_groups = PINS_COUNT ;
return 0 ;
}
static void dc_client_sel ( int pin_num , int * reg , int * bit )
{
* bit = ( pin_num % PINS_PER_COLLECTION ) * 2 ;
* reg = GP_CLIENTSEL ( pin_num / PINS_PER_COLLECTION ) ;
if ( * bit > = PINS_PER_COLLECTION ) {
* bit - = PINS_PER_COLLECTION ;
* reg + = 1 ;
}
}
static int dc_set_mux ( struct pinctrl_dev * pctldev , unsigned selector ,
unsigned group )
{
struct dc_pinmap * pmap = pinctrl_dev_get_drvdata ( pctldev ) ;
int bit_off , reg_off ;
u8 reg ;
dc_client_sel ( group , & reg_off , & bit_off ) ;
reg = readb_relaxed ( pmap - > regs + reg_off ) ;
reg & = ~ ( 3 < < bit_off ) ;
reg | = ( selector < < bit_off ) ;
writeb_relaxed ( reg , pmap - > regs + reg_off ) ;
return 0 ;
}
static int dc_pmx_request_gpio ( struct pinctrl_dev * pcdev ,
struct pinctrl_gpio_range * range ,
unsigned offset )
{
struct dc_pinmap * pmap = pinctrl_dev_get_drvdata ( pcdev ) ;
int bit_off , reg_off ;
u8 reg ;
dc_client_sel ( offset , & reg_off , & bit_off ) ;
reg = readb_relaxed ( pmap - > regs + reg_off ) ;
if ( ( reg & ( 3 < < bit_off ) ) ! = 0 )
return - EBUSY ;
return 0 ;
}
2017-08-10 13:06:19 +03:00
static const struct pinmux_ops dc_pmxops = {
2015-05-05 13:55:10 +03:00
. get_functions_count = dc_get_functions_count ,
. get_function_name = dc_get_fname ,
. get_function_groups = dc_get_groups ,
. set_mux = dc_set_mux ,
. gpio_request_enable = dc_pmx_request_gpio ,
} ;
static int dc_gpio_direction_input ( struct gpio_chip * chip , unsigned gpio )
{
2015-12-08 11:35:14 +03:00
struct dc_pinmap * pmap = gpiochip_get_data ( chip ) ;
2015-05-05 13:55:10 +03:00
int reg_off = GP_DRIVE0 ( gpio / PINS_PER_COLLECTION ) ;
int bit_off = gpio % PINS_PER_COLLECTION ;
u8 drive ;
unsigned long flags ;
spin_lock_irqsave ( & pmap - > lock , flags ) ;
drive = readb_relaxed ( pmap - > regs + reg_off ) ;
drive & = ~ BIT ( bit_off ) ;
writeb_relaxed ( drive , pmap - > regs + reg_off ) ;
spin_unlock_irqrestore ( & pmap - > lock , flags ) ;
return 0 ;
}
static void dc_gpio_set ( struct gpio_chip * chip , unsigned gpio , int value ) ;
static int dc_gpio_direction_output ( struct gpio_chip * chip , unsigned gpio ,
int value )
{
2015-12-08 11:35:14 +03:00
struct dc_pinmap * pmap = gpiochip_get_data ( chip ) ;
2015-05-05 13:55:10 +03:00
int reg_off = GP_DRIVE0 ( gpio / PINS_PER_COLLECTION ) ;
int bit_off = gpio % PINS_PER_COLLECTION ;
u8 drive ;
unsigned long flags ;
dc_gpio_set ( chip , gpio , value ) ;
spin_lock_irqsave ( & pmap - > lock , flags ) ;
drive = readb_relaxed ( pmap - > regs + reg_off ) ;
drive | = BIT ( bit_off ) ;
writeb_relaxed ( drive , pmap - > regs + reg_off ) ;
spin_unlock_irqrestore ( & pmap - > lock , flags ) ;
return 0 ;
}
static int dc_gpio_get ( struct gpio_chip * chip , unsigned gpio )
{
2015-12-08 11:35:14 +03:00
struct dc_pinmap * pmap = gpiochip_get_data ( chip ) ;
2015-05-05 13:55:10 +03:00
int reg_off = GP_INPUT ( gpio / PINS_PER_COLLECTION ) ;
int bit_off = gpio % PINS_PER_COLLECTION ;
u8 input ;
input = readb_relaxed ( pmap - > regs + reg_off ) ;
return ! ! ( input & BIT ( bit_off ) ) ;
}
static void dc_gpio_set ( struct gpio_chip * chip , unsigned gpio , int value )
{
2015-12-08 11:35:14 +03:00
struct dc_pinmap * pmap = gpiochip_get_data ( chip ) ;
2015-05-05 13:55:10 +03:00
int reg_off = GP_OUTPUT0 ( gpio / PINS_PER_COLLECTION ) ;
int bit_off = gpio % PINS_PER_COLLECTION ;
u8 output ;
unsigned long flags ;
spin_lock_irqsave ( & pmap - > lock , flags ) ;
output = readb_relaxed ( pmap - > regs + reg_off ) ;
if ( value )
output | = BIT ( bit_off ) ;
else
output & = ~ BIT ( bit_off ) ;
writeb_relaxed ( output , pmap - > regs + reg_off ) ;
spin_unlock_irqrestore ( & pmap - > lock , flags ) ;
}
2021-12-14 15:58:54 +03:00
static int dc_gpiochip_add ( struct dc_pinmap * pmap )
2015-05-05 13:55:10 +03:00
{
struct gpio_chip * chip = & pmap - > chip ;
int ret ;
chip - > label = DRIVER_NAME ;
2015-11-04 11:56:26 +03:00
chip - > parent = pmap - > dev ;
2015-10-11 18:34:19 +03:00
chip - > request = gpiochip_generic_request ;
chip - > free = gpiochip_generic_free ;
2015-05-05 13:55:10 +03:00
chip - > direction_input = dc_gpio_direction_input ;
chip - > direction_output = dc_gpio_direction_output ;
chip - > get = dc_gpio_get ;
chip - > set = dc_gpio_set ;
chip - > base = - 1 ;
chip - > ngpio = PINS_COUNT ;
spin_lock_init ( & pmap - > lock ) ;
2015-12-08 11:35:14 +03:00
ret = gpiochip_add_data ( chip , pmap ) ;
2015-05-05 13:55:10 +03:00
if ( ret < 0 )
return ret ;
ret = gpiochip_add_pin_range ( chip , dev_name ( pmap - > dev ) , 0 , 0 ,
PINS_COUNT ) ;
if ( ret < 0 ) {
gpiochip_remove ( chip ) ;
return ret ;
}
return 0 ;
}
static int dc_pinctrl_probe ( struct platform_device * pdev )
{
struct dc_pinmap * pmap ;
struct pinctrl_pin_desc * pins ;
struct pinctrl_desc * pctl_desc ;
char * pin_names ;
int name_len = strlen ( " GP_xx " ) + 1 ;
2016-02-28 12:03:21 +03:00
int i , j ;
2015-05-05 13:55:10 +03:00
pmap = devm_kzalloc ( & pdev - > dev , sizeof ( * pmap ) , GFP_KERNEL ) ;
if ( ! pmap )
return - ENOMEM ;
2019-11-04 17:26:54 +03:00
pmap - > regs = devm_platform_ioremap_resource ( pdev , 0 ) ;
2015-05-05 13:55:10 +03:00
if ( IS_ERR ( pmap - > regs ) )
return PTR_ERR ( pmap - > regs ) ;
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 00:07:58 +03:00
pins = devm_kcalloc ( & pdev - > dev , PINS_COUNT , sizeof ( * pins ) ,
GFP_KERNEL ) ;
2015-05-05 13:55:10 +03:00
if ( ! pins )
return - ENOMEM ;
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 00:07:58 +03:00
pin_names = devm_kcalloc ( & pdev - > dev , PINS_COUNT , name_len ,
2015-05-05 13:55:10 +03:00
GFP_KERNEL ) ;
if ( ! pin_names )
return - ENOMEM ;
for ( i = 0 ; i < PIN_COLLECTIONS ; i + + ) {
for ( j = 0 ; j < PINS_PER_COLLECTION ; j + + ) {
int pin_id = i * PINS_PER_COLLECTION + j ;
char * name = & pin_names [ pin_id * name_len ] ;
snprintf ( name , name_len , " GP_%c%c " , ' A ' + i , ' 0 ' + j ) ;
pins [ pin_id ] . number = pin_id ;
pins [ pin_id ] . name = name ;
pmap - > pin_names [ pin_id ] = name ;
}
}
pctl_desc = devm_kzalloc ( & pdev - > dev , sizeof ( * pctl_desc ) , GFP_KERNEL ) ;
if ( ! pctl_desc )
return - ENOMEM ;
pctl_desc - > name = DRIVER_NAME ,
pctl_desc - > owner = THIS_MODULE ,
pctl_desc - > pctlops = & dc_pinctrl_ops ,
pctl_desc - > pmxops = & dc_pmxops ,
pctl_desc - > npins = PINS_COUNT ;
pctl_desc - > pins = pins ;
pmap - > desc = pctl_desc ;
pmap - > dev = & pdev - > dev ;
2016-02-28 12:03:21 +03:00
pmap - > pctl = devm_pinctrl_register ( & pdev - > dev , pctl_desc , pmap ) ;
2015-08-25 00:12:27 +03:00
if ( IS_ERR ( pmap - > pctl ) ) {
2015-05-05 13:55:10 +03:00
dev_err ( & pdev - > dev , " pinctrl driver registration failed \n " ) ;
2015-08-25 00:12:27 +03:00
return PTR_ERR ( pmap - > pctl ) ;
2015-05-05 13:55:10 +03:00
}
2021-12-14 15:58:54 +03:00
return dc_gpiochip_add ( pmap ) ;
2015-05-05 13:55:10 +03:00
}
static const struct of_device_id dc_pinctrl_ids [ ] = {
{ . compatible = " cnxt,cx92755-pinctrl " } ,
{ /* sentinel */ }
} ;
static struct platform_driver dc_pinctrl_driver = {
. driver = {
. name = DRIVER_NAME ,
. of_match_table = dc_pinctrl_ids ,
2016-06-07 05:43:07 +03:00
. suppress_bind_attrs = true ,
2015-05-05 13:55:10 +03:00
} ,
. probe = dc_pinctrl_probe ,
} ;
2016-06-07 05:43:07 +03:00
builtin_platform_driver ( dc_pinctrl_driver ) ;