| 1 |
// SPDX-License-Identifier: GPL-2.0-only |
| 2 |
/* |
| 3 |
* |
| 4 |
* Copyright (C) 2012 ARM Limited |
| 5 |
*/ |
| 6 |
|
| 7 |
#include <linux/gpio/driver.h> |
| 8 |
#include <linux/gpio/generic.h> |
| 9 |
#include <linux/err.h> |
| 10 |
#include <linux/io.h> |
| 11 |
#include <linux/mfd/core.h> |
| 12 |
#include <linux/module.h> |
| 13 |
#include <linux/of_platform.h> |
| 14 |
#include <linux/platform_device.h> |
| 15 |
#include <linux/property.h> |
| 16 |
#include <linux/slab.h> |
| 17 |
#include <linux/stat.h> |
| 18 |
|
| 19 |
#define SYS_ID 0x000 |
| 20 |
#define SYS_SW 0x004 |
| 21 |
#define SYS_LED 0x008 |
| 22 |
#define SYS_100HZ 0x024 |
| 23 |
#define SYS_FLAGSSET 0x030 |
| 24 |
#define SYS_FLAGSCLR 0x034 |
| 25 |
#define SYS_NVFLAGS 0x038 |
| 26 |
#define SYS_NVFLAGSSET 0x038 |
| 27 |
#define SYS_NVFLAGSCLR 0x03c |
| 28 |
#define SYS_MCI 0x048 |
| 29 |
#define SYS_FLASH 0x04c |
| 30 |
#define SYS_CFGSW 0x058 |
| 31 |
#define SYS_24MHZ 0x05c |
| 32 |
#define SYS_MISC 0x060 |
| 33 |
#define SYS_DMA 0x064 |
| 34 |
#define SYS_PROCID0 0x084 |
| 35 |
#define SYS_PROCID1 0x088 |
| 36 |
#define SYS_CFGDATA 0x0a0 |
| 37 |
#define SYS_CFGCTRL 0x0a4 |
| 38 |
#define SYS_CFGSTAT 0x0a8 |
| 39 |
|
| 40 |
/* The sysreg block is just a random collection of various functions... */ |
| 41 |
|
| 42 |
static const struct property_entry vexpress_sysreg_sys_led_props[] = { |
| 43 |
PROPERTY_ENTRY_STRING("label", "sys_led"), |
| 44 |
PROPERTY_ENTRY_U32("ngpios", 8), |
| 45 |
{ } |
| 46 |
}; |
| 47 |
|
| 48 |
static const struct software_node vexpress_sysreg_sys_led_swnode = { |
| 49 |
.properties = vexpress_sysreg_sys_led_props, |
| 50 |
}; |
| 51 |
|
| 52 |
static const struct property_entry vexpress_sysreg_sys_mci_props[] = { |
| 53 |
PROPERTY_ENTRY_STRING("label", "sys_mci"), |
| 54 |
PROPERTY_ENTRY_U32("ngpios", 2), |
| 55 |
{ } |
| 56 |
}; |
| 57 |
|
| 58 |
static const struct software_node vexpress_sysreg_sys_mci_swnode = { |
| 59 |
.properties = vexpress_sysreg_sys_mci_props, |
| 60 |
}; |
| 61 |
|
| 62 |
static const struct property_entry vexpress_sysreg_sys_flash_props[] = { |
| 63 |
PROPERTY_ENTRY_STRING("label", "sys_flash"), |
| 64 |
PROPERTY_ENTRY_U32("ngpios", 1), |
| 65 |
{ } |
| 66 |
}; |
| 67 |
|
| 68 |
static const struct software_node vexpress_sysreg_sys_flash_swnode = { |
| 69 |
.properties = vexpress_sysreg_sys_flash_props, |
| 70 |
}; |
| 71 |
|
| 72 |
static struct mfd_cell vexpress_sysreg_cells[] = { |
| 73 |
{ |
| 74 |
.name = "basic-mmio-gpio", |
| 75 |
.of_compatible = "arm,vexpress-sysreg,sys_led", |
| 76 |
.num_resources = 1, |
| 77 |
.resources = &DEFINE_RES_MEM_NAMED(SYS_LED, 0x4, "dat"), |
| 78 |
.swnode = &vexpress_sysreg_sys_led_swnode, |
| 79 |
}, { |
| 80 |
.name = "basic-mmio-gpio", |
| 81 |
.of_compatible = "arm,vexpress-sysreg,sys_mci", |
| 82 |
.num_resources = 1, |
| 83 |
.resources = &DEFINE_RES_MEM_NAMED(SYS_MCI, 0x4, "dat"), |
| 84 |
.swnode = &vexpress_sysreg_sys_mci_swnode, |
| 85 |
}, { |
| 86 |
.name = "basic-mmio-gpio", |
| 87 |
.of_compatible = "arm,vexpress-sysreg,sys_flash", |
| 88 |
.num_resources = 1, |
| 89 |
.resources = &DEFINE_RES_MEM_NAMED(SYS_FLASH, 0x4, "dat"), |
| 90 |
.swnode = &vexpress_sysreg_sys_flash_swnode, |
| 91 |
}, { |
| 92 |
.name = "vexpress-syscfg", |
| 93 |
.num_resources = 1, |
| 94 |
.resources = &DEFINE_RES_MEM(SYS_MISC, 0x4c), |
| 95 |
} |
| 96 |
}; |
| 97 |
|
| 98 |
static int vexpress_sysreg_probe(struct platform_device *pdev) |
| 99 |
{ |
| 100 |
struct gpio_generic_chip *mmc_gpio_chip; |
| 101 |
struct gpio_generic_chip_config config; |
| 102 |
struct resource *mem; |
| 103 |
void __iomem *base; |
| 104 |
int ret; |
| 105 |
|
| 106 |
mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 107 |
if (!mem) |
| 108 |
return -EINVAL; |
| 109 |
|
| 110 |
base = devm_ioremap(&pdev->dev, mem->start, resource_size(mem)); |
| 111 |
if (!base) |
| 112 |
return -ENOMEM; |
| 113 |
|
| 114 |
/* |
| 115 |
* Duplicated SYS_MCI pseudo-GPIO controller for compatibility with |
| 116 |
* older trees using sysreg node for MMC control lines. |
| 117 |
*/ |
| 118 |
mmc_gpio_chip = devm_kzalloc(&pdev->dev, sizeof(*mmc_gpio_chip), |
| 119 |
GFP_KERNEL); |
| 120 |
if (!mmc_gpio_chip) |
| 121 |
return -ENOMEM; |
| 122 |
|
| 123 |
config = (struct gpio_generic_chip_config) { |
| 124 |
.dev = &pdev->dev, |
| 125 |
.sz = 4, |
| 126 |
.dat = base + SYS_MCI, |
| 127 |
}; |
| 128 |
|
| 129 |
ret = gpio_generic_chip_init(mmc_gpio_chip, &config); |
| 130 |
if (ret) |
| 131 |
return ret; |
| 132 |
|
| 133 |
mmc_gpio_chip->gc.ngpio = 2; |
| 134 |
|
| 135 |
ret = devm_gpiochip_add_data(&pdev->dev, &mmc_gpio_chip->gc, NULL); |
| 136 |
if (ret) |
| 137 |
return ret; |
| 138 |
|
| 139 |
return devm_mfd_add_devices(&pdev->dev, PLATFORM_DEVID_AUTO, |
| 140 |
vexpress_sysreg_cells, |
| 141 |
ARRAY_SIZE(vexpress_sysreg_cells), mem, 0, NULL); |
| 142 |
} |
| 143 |
|
| 144 |
static const struct of_device_id vexpress_sysreg_match[] = { |
| 145 |
{ .compatible = "arm,vexpress-sysreg", }, |
| 146 |
{}, |
| 147 |
}; |
| 148 |
MODULE_DEVICE_TABLE(of, vexpress_sysreg_match); |
| 149 |
|
| 150 |
static struct platform_driver vexpress_sysreg_driver = { |
| 151 |
.driver = { |
| 152 |
.name = "vexpress-sysreg", |
| 153 |
.of_match_table = vexpress_sysreg_match, |
| 154 |
}, |
| 155 |
.probe = vexpress_sysreg_probe, |
| 156 |
}; |
| 157 |
|
| 158 |
module_platform_driver(vexpress_sysreg_driver); |
| 159 |
MODULE_DESCRIPTION("Versatile Express system registers driver"); |
| 160 |
MODULE_LICENSE("GPL v2"); |