.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * Abilis Systems TB10x pin control driver |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (C) Abilis Systems 2012 |
---|
5 | 6 | * |
---|
6 | 7 | * Author: Christian Ruppert <christian.ruppert@abilis.com> |
---|
7 | | - * |
---|
8 | | - * This program is free software; you can redistribute it and/or modify |
---|
9 | | - * it under the terms of the GNU General Public License version 2 as |
---|
10 | | - * published by the Free Software Foundation. |
---|
11 | | - * |
---|
12 | | - * This program is distributed in the hope that it will be useful, |
---|
13 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
15 | | - * GNU General Public License for more details. |
---|
16 | | - * |
---|
17 | | - * You should have received a copy of the GNU General Public License |
---|
18 | | - * along with this program; if not, write to the Free Software |
---|
19 | | - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
20 | 8 | */ |
---|
21 | 9 | |
---|
22 | 10 | #include <linux/stringify.h> |
---|
.. | .. |
---|
483 | 471 | * @base: register set base address. |
---|
484 | 472 | * @pingroups: pointer to an array of the pin groups this driver manages. |
---|
485 | 473 | * @pinfuncgrpcnt: number of pingroups in @pingroups. |
---|
486 | | - * @pinfuncs: pointer to an array of pin functions this driver manages. |
---|
487 | 474 | * @pinfuncnt: number of pin functions in @pinfuncs. |
---|
488 | 475 | * @mutex: mutex for exclusive access to a pin controller's state. |
---|
489 | 476 | * @ports: current state of each port. |
---|
490 | 477 | * @gpios: Indicates if a given pin is currently used as GPIO (1) or not (0). |
---|
| 478 | + * @pinfuncs: flexible array of pin functions this driver manages. |
---|
491 | 479 | */ |
---|
492 | 480 | struct tb10x_pinctrl { |
---|
493 | 481 | struct pinctrl_dev *pctl; |
---|
494 | 482 | void *base; |
---|
495 | 483 | const struct tb10x_pinfuncgrp *pingroups; |
---|
496 | 484 | unsigned int pinfuncgrpcnt; |
---|
497 | | - struct tb10x_of_pinfunc *pinfuncs; |
---|
498 | 485 | unsigned int pinfuncnt; |
---|
499 | 486 | struct mutex mutex; |
---|
500 | 487 | struct tb10x_port ports[TB10X_PORTS]; |
---|
501 | 488 | DECLARE_BITMAP(gpios, MAX_PIN + 1); |
---|
| 489 | + struct tb10x_of_pinfunc pinfuncs[]; |
---|
502 | 490 | }; |
---|
503 | 491 | |
---|
504 | 492 | static inline void tb10x_pinctrl_set_config(struct tb10x_pinctrl *state, |
---|
.. | .. |
---|
759 | 747 | static int tb10x_pinctrl_probe(struct platform_device *pdev) |
---|
760 | 748 | { |
---|
761 | 749 | int ret = -EINVAL; |
---|
762 | | - struct resource *mem; |
---|
763 | 750 | struct device *dev = &pdev->dev; |
---|
764 | 751 | struct device_node *of_node = dev->of_node; |
---|
765 | 752 | struct device_node *child; |
---|
.. | .. |
---|
771 | 758 | return -EINVAL; |
---|
772 | 759 | } |
---|
773 | 760 | |
---|
774 | | - state = devm_kzalloc(dev, sizeof(struct tb10x_pinctrl) + |
---|
775 | | - of_get_child_count(of_node) |
---|
776 | | - * sizeof(struct tb10x_of_pinfunc), |
---|
777 | | - GFP_KERNEL); |
---|
| 761 | + state = devm_kzalloc(dev, struct_size(state, pinfuncs, |
---|
| 762 | + of_get_child_count(of_node)), |
---|
| 763 | + GFP_KERNEL); |
---|
778 | 764 | if (!state) |
---|
779 | 765 | return -ENOMEM; |
---|
780 | 766 | |
---|
781 | 767 | platform_set_drvdata(pdev, state); |
---|
782 | | - state->pinfuncs = (struct tb10x_of_pinfunc *)(state + 1); |
---|
783 | 768 | mutex_init(&state->mutex); |
---|
784 | 769 | |
---|
785 | | - mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
---|
786 | | - state->base = devm_ioremap_resource(dev, mem); |
---|
| 770 | + state->base = devm_platform_ioremap_resource(pdev, 0); |
---|
787 | 771 | if (IS_ERR(state->base)) { |
---|
788 | 772 | ret = PTR_ERR(state->base); |
---|
789 | 773 | goto fail; |
---|