Linux Audio

Check our new training course

Loading...
v5.9
 
 1/*
 2 * GPIO driver for the TS-4800 board
 3 *
 4 * Copyright (c) 2016 - Savoir-faire Linux
 5 *
 6 * This file is licensed under the terms of the GNU General Public
 7 * License version 2. This program is licensed "as is" without any
 8 * warranty of any kind, whether express or implied.
 9 */
10
11#include <linux/gpio/driver.h>
12#include <linux/module.h>
13#include <linux/of_address.h>
14#include <linux/of_device.h>
15#include <linux/platform_device.h>
16
17#define DEFAULT_PIN_NUMBER      16
18#define INPUT_REG_OFFSET        0x00
19#define OUTPUT_REG_OFFSET       0x02
20#define DIRECTION_REG_OFFSET    0x04
21
22static int ts4800_gpio_probe(struct platform_device *pdev)
23{
24	struct device_node *node;
25	struct gpio_chip *chip;
26	void __iomem *base_addr;
27	int retval;
28	u32 ngpios;
29
30	chip = devm_kzalloc(&pdev->dev, sizeof(struct gpio_chip), GFP_KERNEL);
31	if (!chip)
32		return -ENOMEM;
33
34	base_addr = devm_platform_ioremap_resource(pdev, 0);
35	if (IS_ERR(base_addr))
36		return PTR_ERR(base_addr);
37
38	node = pdev->dev.of_node;
39	if (!node)
40		return -EINVAL;
41
42	retval = of_property_read_u32(node, "ngpios", &ngpios);
43	if (retval == -EINVAL)
44		ngpios = DEFAULT_PIN_NUMBER;
45	else if (retval)
46		return retval;
47
48	retval = bgpio_init(chip, &pdev->dev, 2, base_addr + INPUT_REG_OFFSET,
49			    base_addr + OUTPUT_REG_OFFSET, NULL,
50			    base_addr + DIRECTION_REG_OFFSET, NULL, 0);
51	if (retval) {
52		dev_err(&pdev->dev, "bgpio_init failed\n");
53		return retval;
54	}
55
56	chip->ngpio = ngpios;
57
58	platform_set_drvdata(pdev, chip);
59
60	return devm_gpiochip_add_data(&pdev->dev, chip, NULL);
61}
62
63static const struct of_device_id ts4800_gpio_of_match[] = {
64	{ .compatible = "technologic,ts4800-gpio", },
65	{},
66};
67MODULE_DEVICE_TABLE(of, ts4800_gpio_of_match);
68
69static struct platform_driver ts4800_gpio_driver = {
70	.driver = {
71		   .name = "ts4800-gpio",
72		   .of_match_table = ts4800_gpio_of_match,
73		   },
74	.probe = ts4800_gpio_probe,
75};
76
77module_platform_driver_probe(ts4800_gpio_driver, ts4800_gpio_probe);
78
79MODULE_AUTHOR("Julien Grossholtz <julien.grossholtz@savoirfairelinux.com>");
80MODULE_DESCRIPTION("TS4800 FPGA GPIO driver");
81MODULE_LICENSE("GPL v2");
v6.2
 1// SPDX-License-Identifier: GPL-2.0-only
 2/*
 3 * GPIO driver for the TS-4800 board
 4 *
 5 * Copyright (c) 2016 - Savoir-faire Linux
 
 
 
 
 6 */
 7
 8#include <linux/gpio/driver.h>
 9#include <linux/module.h>
10#include <linux/of_address.h>
11#include <linux/of_device.h>
12#include <linux/platform_device.h>
13
14#define DEFAULT_PIN_NUMBER      16
15#define INPUT_REG_OFFSET        0x00
16#define OUTPUT_REG_OFFSET       0x02
17#define DIRECTION_REG_OFFSET    0x04
18
19static int ts4800_gpio_probe(struct platform_device *pdev)
20{
21	struct device_node *node;
22	struct gpio_chip *chip;
23	void __iomem *base_addr;
24	int retval;
25	u32 ngpios;
26
27	chip = devm_kzalloc(&pdev->dev, sizeof(struct gpio_chip), GFP_KERNEL);
28	if (!chip)
29		return -ENOMEM;
30
31	base_addr = devm_platform_ioremap_resource(pdev, 0);
32	if (IS_ERR(base_addr))
33		return PTR_ERR(base_addr);
34
35	node = pdev->dev.of_node;
36	if (!node)
37		return -EINVAL;
38
39	retval = of_property_read_u32(node, "ngpios", &ngpios);
40	if (retval == -EINVAL)
41		ngpios = DEFAULT_PIN_NUMBER;
42	else if (retval)
43		return retval;
44
45	retval = bgpio_init(chip, &pdev->dev, 2, base_addr + INPUT_REG_OFFSET,
46			    base_addr + OUTPUT_REG_OFFSET, NULL,
47			    base_addr + DIRECTION_REG_OFFSET, NULL, 0);
48	if (retval) {
49		dev_err(&pdev->dev, "bgpio_init failed\n");
50		return retval;
51	}
52
53	chip->ngpio = ngpios;
54
55	platform_set_drvdata(pdev, chip);
56
57	return devm_gpiochip_add_data(&pdev->dev, chip, NULL);
58}
59
60static const struct of_device_id ts4800_gpio_of_match[] = {
61	{ .compatible = "technologic,ts4800-gpio", },
62	{},
63};
64MODULE_DEVICE_TABLE(of, ts4800_gpio_of_match);
65
66static struct platform_driver ts4800_gpio_driver = {
67	.driver = {
68		   .name = "ts4800-gpio",
69		   .of_match_table = ts4800_gpio_of_match,
70		   },
71	.probe = ts4800_gpio_probe,
72};
73
74module_platform_driver_probe(ts4800_gpio_driver, ts4800_gpio_probe);
75
76MODULE_AUTHOR("Julien Grossholtz <julien.grossholtz@savoirfairelinux.com>");
77MODULE_DESCRIPTION("TS4800 FPGA GPIO driver");
78MODULE_LICENSE("GPL v2");