From patchwork Thu Jul 12 16:38:40 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [1/2] mtd: maps: physmap: Add GPIO VPP control Date: Thu, 12 Jul 2012 06:38:40 -0000 From: Pawel Moll X-Patchwork-Id: 170725 Message-Id: <1342111121-23161-2-git-send-email-pawel.moll@arm.com> To: linux-mtd@lists.infradead.org Cc: Artem Bityutskiy , David Woodhouse , Pawel Moll Add GPIO control of the VPP signal: * platform data fields to specify GPIO number and polarity * set_vpp implementation setting the GPIO value Signed-off-by: Pawel Moll --- drivers/mtd/maps/physmap.c | 22 ++++++++++++++++++++++ include/linux/mtd/physmap.h | 2 ++ 2 files changed, 24 insertions(+) diff --git a/drivers/mtd/maps/physmap.c b/drivers/mtd/maps/physmap.c index 21b0b71..3ef4e1e 100644 --- a/drivers/mtd/maps/physmap.c +++ b/drivers/mtd/maps/physmap.c @@ -20,6 +20,7 @@ #include #include #include +#include #define MAX_RESOURCES 4 @@ -87,6 +88,14 @@ static void physmap_set_vpp(struct map_info *map, int state) spin_unlock_irqrestore(&info->vpp_lock, flags); } +static void physmap_set_gpio_vpp(struct platform_device *pdev, int state) +{ + struct physmap_flash_data *physmap_data = pdev->dev.platform_data; + + gpio_set_value(physmap_data->gpio_vpp, + !!state ^ !!physmap_data->gpio_vpp_active_low); +} + static const char *rom_probe_types[] = { "cfi_probe", "jedec_probe", @@ -123,6 +132,19 @@ static int physmap_flash_probe(struct platform_device *dev) goto err_out; } + if (!physmap_data->set_vpp && gpio_is_valid(physmap_data->gpio_vpp)) { + unsigned long flags = GPIOF_DIR_OUT; + if (physmap_data->gpio_vpp_active_low) + flags |= GPIOF_INIT_HIGH; + else + flags |= GPIOF_INIT_LOW; + err = devm_gpio_request_one(&dev->dev, physmap_data->gpio_vpp, + flags, dev_name(&dev->dev)); + if (err) + goto err_out; + physmap_data->set_vpp = physmap_set_gpio_vpp; + } + platform_set_drvdata(dev, info); for (i = 0; i < dev->num_resources; i++) { diff --git a/include/linux/mtd/physmap.h b/include/linux/mtd/physmap.h index d2887e7..b5c85b6 100644 --- a/include/linux/mtd/physmap.h +++ b/include/linux/mtd/physmap.h @@ -26,6 +26,8 @@ struct physmap_flash_data { int (*init)(struct platform_device *); void (*exit)(struct platform_device *); void (*set_vpp)(struct platform_device *, int); + int gpio_vpp; + bool gpio_vpp_active_low; unsigned int nr_parts; unsigned int pfow_base; char *probe_type;