Path: blob/master/arch/mips/lantiq/xway/gpio_ebu.c
10818 views
/*1* This program is free software; you can redistribute it and/or modify it2* under the terms of the GNU General Public License version 2 as published3* by the Free Software Foundation.4*5* Copyright (C) 2010 John Crispin <[email protected]>6*/78#include <linux/init.h>9#include <linux/module.h>10#include <linux/types.h>11#include <linux/platform_device.h>12#include <linux/mutex.h>13#include <linux/gpio.h>14#include <linux/io.h>1516#include <lantiq_soc.h>1718/*19* By attaching hardware latches to the EBU it is possible to create output20* only gpios. This driver configures a special memory address, which when21* written to outputs 16 bit to the latches.22*/2324#define LTQ_EBU_BUSCON 0x1e7ff /* 16 bit access, slowest timing */25#define LTQ_EBU_WP 0x80000000 /* write protect bit */2627/* we keep a shadow value of the last value written to the ebu */28static int ltq_ebu_gpio_shadow = 0x0;29static void __iomem *ltq_ebu_gpio_membase;3031static void ltq_ebu_apply(void)32{33unsigned long flags;3435spin_lock_irqsave(&ebu_lock, flags);36ltq_ebu_w32(LTQ_EBU_BUSCON, LTQ_EBU_BUSCON1);37*((__u16 *)ltq_ebu_gpio_membase) = ltq_ebu_gpio_shadow;38ltq_ebu_w32(LTQ_EBU_BUSCON | LTQ_EBU_WP, LTQ_EBU_BUSCON1);39spin_unlock_irqrestore(&ebu_lock, flags);40}4142static void ltq_ebu_set(struct gpio_chip *chip, unsigned offset, int value)43{44if (value)45ltq_ebu_gpio_shadow |= (1 << offset);46else47ltq_ebu_gpio_shadow &= ~(1 << offset);48ltq_ebu_apply();49}5051static int ltq_ebu_direction_output(struct gpio_chip *chip, unsigned offset,52int value)53{54ltq_ebu_set(chip, offset, value);5556return 0;57}5859static struct gpio_chip ltq_ebu_chip = {60.label = "ltq_ebu",61.direction_output = ltq_ebu_direction_output,62.set = ltq_ebu_set,63.base = 72,64.ngpio = 16,65.can_sleep = 1,66.owner = THIS_MODULE,67};6869static int ltq_ebu_probe(struct platform_device *pdev)70{71int ret = 0;72struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);7374if (!res) {75dev_err(&pdev->dev, "failed to get memory resource\n");76return -ENOENT;77}7879res = devm_request_mem_region(&pdev->dev, res->start,80resource_size(res), dev_name(&pdev->dev));81if (!res) {82dev_err(&pdev->dev, "failed to request memory resource\n");83return -EBUSY;84}8586ltq_ebu_gpio_membase = devm_ioremap_nocache(&pdev->dev, res->start,87resource_size(res));88if (!ltq_ebu_gpio_membase) {89dev_err(&pdev->dev, "Failed to ioremap mem region\n");90return -ENOMEM;91}9293/* grab the default shadow value passed form the platform code */94ltq_ebu_gpio_shadow = (unsigned int) pdev->dev.platform_data;9596/* tell the ebu controller which memory address we will be using */97ltq_ebu_w32(pdev->resource->start | 0x1, LTQ_EBU_ADDRSEL1);9899/* write protect the region */100ltq_ebu_w32(LTQ_EBU_BUSCON | LTQ_EBU_WP, LTQ_EBU_BUSCON1);101102ret = gpiochip_add(<q_ebu_chip);103if (!ret)104ltq_ebu_apply();105return ret;106}107108static struct platform_driver ltq_ebu_driver = {109.probe = ltq_ebu_probe,110.driver = {111.name = "ltq_ebu",112.owner = THIS_MODULE,113},114};115116static int __init ltq_ebu_init(void)117{118int ret = platform_driver_register(<q_ebu_driver);119120if (ret)121pr_info("ltq_ebu : Error registering platfom driver!");122return ret;123}124125postcore_initcall(ltq_ebu_init);126127128