Skip to content

Commit d2d0086

Browse files
author
Roger Quadros
committed
memory: omap-gpmc: Support general purpose input for WAITPINs
OMAPs can have 2 to 4 WAITPINs that can be used as general purpose input if not used for memory wait state insertion. The first user will be the OMAP NAND chip to get the NAND read/busy status using gpiolib. Signed-off-by: Roger Quadros <rogerq@ti.com> Acked-by: Rob Herring <robh@kernel.org> Acked-by: Tony Lindgren <tony@atomide.com>
1 parent 3c76f61 commit d2d0086

3 files changed

Lines changed: 112 additions & 12 deletions

File tree

‎Documentation/devicetree/bindings/memory-controllers/omap-gpmc.txt‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ Required properties:
3838
0 - NAND_fifoevent
3939
1 - NAND_termcount
4040
- interrupt-cells: Must be set to 2
41+
- gpio-controller: The GPMC driver implements a GPIO controller for the
42+
GPMC WAIT pins that can be used as general purpose inputs.
43+
0 maps to GPMC_WAIT0 pin.
44+
- gpio-cells: Must be set to 2
4145

4246
Timing properties for child nodes. All are optional and default to 0.
4347

@@ -138,6 +142,8 @@ Example for an AM33xx board:
138142
ranges = <0 0 0x08000000 0x10000000>; /* CS0 @addr 0x8000000, size 0x10000000 */
139143
interrupt-controller;
140144
#interrupt-cells = <2>;
145+
gpio-controller;
146+
#gpio-cells = <2>;
141147

142148
/* child nodes go here */
143149
};

‎drivers/memory/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ config TI_EMIF
5151

5252
config OMAP_GPMC
5353
bool
54+
select GPIOLIB
5455
help
5556
This driver is for the General Purpose Memory Controller (GPMC)
5657
present on Texas Instruments SoCs (e.g. OMAP2+). GPMC allows

‎drivers/memory/omap-gpmc.c‎

Lines changed: 105 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <linux/spinlock.h>
2222
#include <linux/io.h>
2323
#include <linux/module.h>
24+
#include <linux/gpio/driver.h>
2425
#include <linux/interrupt.h>
2526
#include <linux/irqdomain.h>
2627
#include <linux/platform_device.h>
@@ -237,6 +238,7 @@ struct gpmc_device {
237238
struct device *dev;
238239
int irq;
239240
struct irq_chip irq_chip;
241+
struct gpio_chip gpio_chip;
240242
};
241243

242244
static struct irq_domain *gpmc_irq_domain;
@@ -2064,10 +2066,71 @@ static int gpmc_probe_generic_child(struct platform_device *pdev,
20642066
return ret;
20652067
}
20662068

2069+
static int gpmc_gpio_get_direction(struct gpio_chip *chip, unsigned int offset)
2070+
{
2071+
return 1; /* we're input only */
2072+
}
2073+
2074+
static int gpmc_gpio_direction_input(struct gpio_chip *chip,
2075+
unsigned int offset)
2076+
{
2077+
return 0; /* we're input only */
2078+
}
2079+
2080+
static int gpmc_gpio_direction_output(struct gpio_chip *chip,
2081+
unsigned int offset, int value)
2082+
{
2083+
return -EINVAL; /* we're input only */
2084+
}
2085+
2086+
static void gpmc_gpio_set(struct gpio_chip *chip, unsigned int offset,
2087+
int value)
2088+
{
2089+
}
2090+
2091+
static int gpmc_gpio_get(struct gpio_chip *chip, unsigned int offset)
2092+
{
2093+
u32 reg;
2094+
2095+
offset += 8;
2096+
2097+
reg = gpmc_read_reg(GPMC_STATUS) & BIT(offset);
2098+
2099+
return !!reg;
2100+
}
2101+
2102+
static int gpmc_gpio_init(struct gpmc_device *gpmc)
2103+
{
2104+
int ret;
2105+
2106+
gpmc->gpio_chip.parent = gpmc->dev;
2107+
gpmc->gpio_chip.owner = THIS_MODULE;
2108+
gpmc->gpio_chip.label = DEVICE_NAME;
2109+
gpmc->gpio_chip.ngpio = gpmc_nr_waitpins;
2110+
gpmc->gpio_chip.get_direction = gpmc_gpio_get_direction;
2111+
gpmc->gpio_chip.direction_input = gpmc_gpio_direction_input;
2112+
gpmc->gpio_chip.direction_output = gpmc_gpio_direction_output;
2113+
gpmc->gpio_chip.set = gpmc_gpio_set;
2114+
gpmc->gpio_chip.get = gpmc_gpio_get;
2115+
gpmc->gpio_chip.base = -1;
2116+
2117+
ret = gpiochip_add(&gpmc->gpio_chip);
2118+
if (ret < 0) {
2119+
dev_err(gpmc->dev, "could not register gpio chip: %d\n", ret);
2120+
return ret;
2121+
}
2122+
2123+
return 0;
2124+
}
2125+
2126+
static void gpmc_gpio_exit(struct gpmc_device *gpmc)
2127+
{
2128+
gpiochip_remove(&gpmc->gpio_chip);
2129+
}
2130+
20672131
static int gpmc_probe_dt(struct platform_device *pdev)
20682132
{
20692133
int ret;
2070-
struct device_node *child;
20712134
const struct of_device_id *of_id =
20722135
of_match_device(gpmc_dt_ids, &pdev->dev);
20732136

@@ -2095,6 +2158,14 @@ static int gpmc_probe_dt(struct platform_device *pdev)
20952158
return ret;
20962159
}
20972160

2161+
return 0;
2162+
}
2163+
2164+
static int gpmc_probe_dt_children(struct platform_device *pdev)
2165+
{
2166+
int ret;
2167+
struct device_node *child;
2168+
20982169
for_each_available_child_of_node(pdev->dev.of_node, child) {
20992170

21002171
if (!child->name)
@@ -2104,6 +2175,9 @@ static int gpmc_probe_dt(struct platform_device *pdev)
21042175
ret = gpmc_probe_onenand_child(pdev, child);
21052176
else
21062177
ret = gpmc_probe_generic_child(pdev, child);
2178+
2179+
if (ret)
2180+
return ret;
21072181
}
21082182

21092183
return 0;
@@ -2113,6 +2187,11 @@ static int gpmc_probe_dt(struct platform_device *pdev)
21132187
{
21142188
return 0;
21152189
}
2190+
2191+
static int gpmc_probe_dt_children(struct platform_device *pdev)
2192+
{
2193+
return 0;
2194+
}
21162195
#endif
21172196

21182197
static int gpmc_probe(struct platform_device *pdev)
@@ -2159,6 +2238,15 @@ static int gpmc_probe(struct platform_device *pdev)
21592238
return -EINVAL;
21602239
}
21612240

2241+
if (pdev->dev.of_node) {
2242+
rc = gpmc_probe_dt(pdev);
2243+
if (rc)
2244+
return rc;
2245+
} else {
2246+
gpmc_cs_num = GPMC_CS_NUM;
2247+
gpmc_nr_waitpins = GPMC_NR_WAITPINS;
2248+
}
2249+
21622250
pm_runtime_enable(&pdev->dev);
21632251
pm_runtime_get_sync(&pdev->dev);
21642252

@@ -2184,29 +2272,33 @@ static int gpmc_probe(struct platform_device *pdev)
21842272
GPMC_REVISION_MINOR(l));
21852273

21862274
gpmc_mem_init();
2275+
rc = gpmc_gpio_init(gpmc);
2276+
if (rc)
2277+
goto gpio_init_failed;
21872278

21882279
rc = gpmc_setup_irq(gpmc);
21892280
if (rc) {
21902281
dev_err(gpmc->dev, "gpmc_setup_irq failed\n");
2191-
goto fail;
2282+
goto setup_irq_failed;
21922283
}
21932284

2194-
if (!pdev->dev.of_node) {
2195-
gpmc_cs_num = GPMC_CS_NUM;
2196-
gpmc_nr_waitpins = GPMC_NR_WAITPINS;
2197-
}
2198-
2199-
rc = gpmc_probe_dt(pdev);
2285+
rc = gpmc_probe_dt_children(pdev);
22002286
if (rc < 0) {
2201-
dev_err(gpmc->dev, "failed to probe DT parameters\n");
2202-
gpmc_free_irq(gpmc);
2203-
goto fail;
2287+
dev_err(gpmc->dev, "failed to probe DT children\n");
2288+
goto dt_children_failed;
22042289
}
22052290

22062291
return 0;
22072292

2208-
fail:
2293+
dt_children_failed:
2294+
gpmc_free_irq(gpmc);
2295+
setup_irq_failed:
2296+
gpmc_gpio_exit(gpmc);
2297+
gpio_init_failed:
2298+
gpmc_mem_exit();
22092299
pm_runtime_put_sync(&pdev->dev);
2300+
pm_runtime_disable(&pdev->dev);
2301+
22102302
return rc;
22112303
}
22122304

@@ -2215,6 +2307,7 @@ static int gpmc_remove(struct platform_device *pdev)
22152307
struct gpmc_device *gpmc = platform_get_drvdata(pdev);
22162308

22172309
gpmc_free_irq(gpmc);
2310+
gpmc_gpio_exit(gpmc);
22182311
gpmc_mem_exit();
22192312
pm_runtime_put_sync(&pdev->dev);
22202313
pm_runtime_disable(&pdev->dev);

0 commit comments

Comments
 (0)