/* * drivers/power/axp/axp80x/axp80x-gpio.c * (C) Copyright 2010-2016 * Allwinner Technology Co., Ltd. * Pannan * * gpio driver of axp80x * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "../../../../pinctrl/core.h" #include "../axp-core.h" #include "../axp-gpio.h" #include "axp80x-gpio.h" static int axp80x_gpio_get_data(struct axp_dev *axp_dev, int gpio) { if (gpio == 0) { pr_err("This IO is not an input\n"); return -ENXIO; } else { return -ENXIO; } } static int axp80x_gpio_set_data(struct axp_dev *axp_dev, int gpio, int value) { struct axp_regmap *map; if (gpio == 0) { map = axp_dev->regmap; if (map == NULL) { pr_err("%s: %d axp regmap is null\n", __func__, __LINE__); return -ENXIO; } } else { return -ENXIO; } /* high */ if (value) return axp_regmap_update_sync(map, AXP_GPIO0_CFG, 0x03, 0x07); else return axp_regmap_update_sync(map, AXP_GPIO0_CFG, 0x02, 0x07); } static int axp80x_pmx_set(struct axp_dev *axp_dev, int gpio, int mux) { struct axp_regmap *map; if (gpio == 0) { map = axp_dev->regmap; if (map == NULL) { pr_err("%s: %d axp regmap is null\n", __func__, __LINE__); return -ENXIO; } } else { return -ENXIO; } /* output */ if (mux == 1) return axp_regmap_update_sync(map, AXP_GPIO0_CFG, 0x02, 0x07); else return -ENXIO; } static int axp80x_pmx_get(struct axp_dev *axp_dev, int gpio) { u8 ret; struct axp_regmap *map; if (gpio == 0) { map = axp_dev->regmap; if (map == NULL) { pr_err("%s: %d axp regmap is null\n", __func__, __LINE__); return -ENXIO; } } else { return -ENXIO; } axp_regmap_read(map, AXP_GPIO0_CFG, &ret); if ((ret & 0x06) == 0x2) return 1; else return -ENXIO; } static const struct axp_desc_pin axp80x_pins[] = { AXP_PIN_DESC(AXP_PINCTRL_GPIO(0), AXP_FUNCTION(0x0, "gpio_in"), AXP_FUNCTION(0x1, "gpio_out")), }; static struct axp_pinctrl_desc axp80x_pinctrl_pins_desc = { .pins = axp80x_pins, .npins = ARRAY_SIZE(axp80x_pins), }; static struct axp_gpio_ops axp80x_gpio_ops = { .gpio_get_data = axp80x_gpio_get_data, .gpio_set_data = axp80x_gpio_set_data, .pmx_set = axp80x_pmx_set, .pmx_get = axp80x_pmx_get, }; static int axp80x_gpio_probe(struct platform_device *pdev) { struct axp_dev *axp_dev = dev_get_drvdata(pdev->dev.parent); struct axp_pinctrl *axp80x_pin; axp80x_pin = axp_pinctrl_register(&pdev->dev, axp_dev, &axp80x_pinctrl_pins_desc, &axp80x_gpio_ops); if (IS_ERR_OR_NULL(axp80x_pin)) return -1; platform_set_drvdata(pdev, axp80x_pin); return 0; } static int axp80x_gpio_remove(struct platform_device *pdev) { struct axp_pinctrl *axp80x_pin = platform_get_drvdata(pdev); return axp_pinctrl_unregister(axp80x_pin); } static const struct of_device_id axp80x_gpio_dt_ids[] = { { .compatible = "axp806-gpio", }, { .compatible = "axp808-gpio", }, {}, }; MODULE_DEVICE_TABLE(of, axp80x_gpio_dt_ids); static struct platform_driver axp80x_gpio_driver = { .driver = { .name = "axp80x-gpio", .of_match_table = axp80x_gpio_dt_ids, }, .probe = axp80x_gpio_probe, .remove = axp80x_gpio_remove, }; static int __init axp80x_gpio_initcall(void) { int ret; ret = platform_driver_register(&axp80x_gpio_driver); if (ret != 0) { pr_err("%s: failed, errno %d\n", __func__, ret); return -EINVAL; } return 0; } fs_initcall(axp80x_gpio_initcall); MODULE_DESCRIPTION("Gpio driver of axp22x"); MODULE_AUTHOR("pannan"); MODULE_LICENSE("GPL");