Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * GPIO driver for the TS-4800 board
0004  *
0005  * Copyright (c) 2016 - Savoir-faire Linux
0006  */
0007 
0008 #include <linux/gpio/driver.h>
0009 #include <linux/module.h>
0010 #include <linux/of_address.h>
0011 #include <linux/of_device.h>
0012 #include <linux/platform_device.h>
0013 
0014 #define DEFAULT_PIN_NUMBER      16
0015 #define INPUT_REG_OFFSET        0x00
0016 #define OUTPUT_REG_OFFSET       0x02
0017 #define DIRECTION_REG_OFFSET    0x04
0018 
0019 static int ts4800_gpio_probe(struct platform_device *pdev)
0020 {
0021     struct device_node *node;
0022     struct gpio_chip *chip;
0023     void __iomem *base_addr;
0024     int retval;
0025     u32 ngpios;
0026 
0027     chip = devm_kzalloc(&pdev->dev, sizeof(struct gpio_chip), GFP_KERNEL);
0028     if (!chip)
0029         return -ENOMEM;
0030 
0031     base_addr = devm_platform_ioremap_resource(pdev, 0);
0032     if (IS_ERR(base_addr))
0033         return PTR_ERR(base_addr);
0034 
0035     node = pdev->dev.of_node;
0036     if (!node)
0037         return -EINVAL;
0038 
0039     retval = of_property_read_u32(node, "ngpios", &ngpios);
0040     if (retval == -EINVAL)
0041         ngpios = DEFAULT_PIN_NUMBER;
0042     else if (retval)
0043         return retval;
0044 
0045     retval = bgpio_init(chip, &pdev->dev, 2, base_addr + INPUT_REG_OFFSET,
0046                 base_addr + OUTPUT_REG_OFFSET, NULL,
0047                 base_addr + DIRECTION_REG_OFFSET, NULL, 0);
0048     if (retval) {
0049         dev_err(&pdev->dev, "bgpio_init failed\n");
0050         return retval;
0051     }
0052 
0053     chip->ngpio = ngpios;
0054 
0055     platform_set_drvdata(pdev, chip);
0056 
0057     return devm_gpiochip_add_data(&pdev->dev, chip, NULL);
0058 }
0059 
0060 static const struct of_device_id ts4800_gpio_of_match[] = {
0061     { .compatible = "technologic,ts4800-gpio", },
0062     {},
0063 };
0064 MODULE_DEVICE_TABLE(of, ts4800_gpio_of_match);
0065 
0066 static struct platform_driver ts4800_gpio_driver = {
0067     .driver = {
0068            .name = "ts4800-gpio",
0069            .of_match_table = ts4800_gpio_of_match,
0070            },
0071     .probe = ts4800_gpio_probe,
0072 };
0073 
0074 module_platform_driver_probe(ts4800_gpio_driver, ts4800_gpio_probe);
0075 
0076 MODULE_AUTHOR("Julien Grossholtz <julien.grossholtz@savoirfairelinux.com>");
0077 MODULE_DESCRIPTION("TS4800 FPGA GPIO driver");
0078 MODULE_LICENSE("GPL v2");