2019-05-27 09:55:21 +03:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2012-09-18 15:24:57 +04:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 ARM Limited
|
|
|
|
*/
|
|
|
|
|
2015-12-04 16:02:58 +03:00
|
|
|
#include <linux/gpio/driver.h>
|
2012-09-18 15:24:57 +04:00
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/io.h>
|
2014-04-23 13:49:31 +04:00
|
|
|
#include <linux/mfd/core.h>
|
2020-04-29 23:58:20 +03:00
|
|
|
#include <linux/module.h>
|
mfd: vexpress: Convert custom func API to regmap
Components of the Versatile Express platform (configuration
microcontrollers on motherboard and daughterboards in particular)
talk to each other over a custom configuration bus. They
provide miscellaneous functions (from clock generator control
to energy sensors) which are represented as platform devices
(and Device Tree nodes). The transactions on the bus can
be generated by different "bridges" in the system, some
of which are universal for the whole platform (for the price
of high transfer latencies), others restricted to a subsystem
(but much faster).
Until now drivers for such functions were using custom "func"
API, which is being replaced in this patch by regmap calls.
This required:
* a rework (and move to drivers/bus directory, as suggested
by Samuel and Arnd) of the config bus core, which is much
simpler now and uses device model infrastructure (class)
to keep track of the bridges; non-DT case (soon to be
retired anyway) is simply covered by a special device
registration function
* the new config-bus driver also takes over device population,
so there is no need for special matching table for
of_platform_populate nor "simple-bus" hack in the arm64
model dtsi file (relevant bindings documentation has
been updated); this allows all the vexpress devices
fit into normal device model, making it possible
to remove plenty of early inits and other hacks in
the near future
* adaptation of the syscfg bridge implementation in the
sysreg driver, again making it much simpler; there is
a special case of the "energy" function spanning two
registers, where they should be both defined in the tree
now, but backward compatibility is maintained in the code
* modification of the relevant drivers:
* hwmon - just a straight-forward API change
* power/reset driver - API change
* regulator - API change plus error handling
simplification
* osc clock driver - this one required larger rework
in order to turn in into a standard platform driver
Signed-off-by: Pawel Moll <pawel.moll@arm.com>
Acked-by: Mark Brown <broonie@linaro.org>
Acked-by: Lee Jones <lee.jones@linaro.org>
Acked-by: Guenter Roeck <linux@roeck-us.net>
Acked-by: Mike Turquette <mturquette@linaro.org>
2014-04-30 19:46:29 +04:00
|
|
|
#include <linux/of_platform.h>
|
2014-04-23 13:49:31 +04:00
|
|
|
#include <linux/platform_data/syscon.h>
|
2012-09-18 15:24:57 +04:00
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/stat.h>
|
|
|
|
#include <linux/vexpress.h>
|
|
|
|
|
|
|
|
#define SYS_ID 0x000
|
|
|
|
#define SYS_SW 0x004
|
|
|
|
#define SYS_LED 0x008
|
|
|
|
#define SYS_100HZ 0x024
|
|
|
|
#define SYS_FLAGSSET 0x030
|
|
|
|
#define SYS_FLAGSCLR 0x034
|
|
|
|
#define SYS_NVFLAGS 0x038
|
|
|
|
#define SYS_NVFLAGSSET 0x038
|
|
|
|
#define SYS_NVFLAGSCLR 0x03c
|
|
|
|
#define SYS_MCI 0x048
|
|
|
|
#define SYS_FLASH 0x04c
|
|
|
|
#define SYS_CFGSW 0x058
|
|
|
|
#define SYS_24MHZ 0x05c
|
|
|
|
#define SYS_MISC 0x060
|
|
|
|
#define SYS_DMA 0x064
|
|
|
|
#define SYS_PROCID0 0x084
|
|
|
|
#define SYS_PROCID1 0x088
|
|
|
|
#define SYS_CFGDATA 0x0a0
|
|
|
|
#define SYS_CFGCTRL 0x0a4
|
|
|
|
#define SYS_CFGSTAT 0x0a8
|
|
|
|
|
|
|
|
#define SYS_HBI_MASK 0xfff
|
|
|
|
#define SYS_PROCIDx_HBI_SHIFT 0
|
|
|
|
|
|
|
|
#define SYS_MISC_MASTERSITE (1 << 14)
|
|
|
|
|
2014-04-23 13:49:31 +04:00
|
|
|
/* The sysreg block is just a random collection of various functions... */
|
2013-01-30 14:33:16 +04:00
|
|
|
|
2014-04-23 13:49:31 +04:00
|
|
|
static struct bgpio_pdata vexpress_sysreg_sys_led_pdata = {
|
|
|
|
.label = "sys_led",
|
|
|
|
.base = -1,
|
|
|
|
.ngpio = 8,
|
2012-09-18 15:24:57 +04:00
|
|
|
};
|
|
|
|
|
2014-04-23 13:49:31 +04:00
|
|
|
static struct bgpio_pdata vexpress_sysreg_sys_mci_pdata = {
|
|
|
|
.label = "sys_mci",
|
|
|
|
.base = -1,
|
|
|
|
.ngpio = 2,
|
2013-01-30 14:33:16 +04:00
|
|
|
};
|
|
|
|
|
2014-04-23 13:49:31 +04:00
|
|
|
static struct bgpio_pdata vexpress_sysreg_sys_flash_pdata = {
|
|
|
|
.label = "sys_flash",
|
|
|
|
.base = -1,
|
|
|
|
.ngpio = 1,
|
2013-01-30 14:33:16 +04:00
|
|
|
};
|
|
|
|
|
2014-04-23 13:49:31 +04:00
|
|
|
static struct mfd_cell vexpress_sysreg_cells[] = {
|
|
|
|
{
|
|
|
|
.name = "basic-mmio-gpio",
|
|
|
|
.of_compatible = "arm,vexpress-sysreg,sys_led",
|
|
|
|
.num_resources = 1,
|
|
|
|
.resources = (struct resource []) {
|
|
|
|
DEFINE_RES_MEM_NAMED(SYS_LED, 0x4, "dat"),
|
|
|
|
},
|
|
|
|
.platform_data = &vexpress_sysreg_sys_led_pdata,
|
|
|
|
.pdata_size = sizeof(vexpress_sysreg_sys_led_pdata),
|
|
|
|
}, {
|
|
|
|
.name = "basic-mmio-gpio",
|
|
|
|
.of_compatible = "arm,vexpress-sysreg,sys_mci",
|
|
|
|
.num_resources = 1,
|
|
|
|
.resources = (struct resource []) {
|
|
|
|
DEFINE_RES_MEM_NAMED(SYS_MCI, 0x4, "dat"),
|
|
|
|
},
|
|
|
|
.platform_data = &vexpress_sysreg_sys_mci_pdata,
|
|
|
|
.pdata_size = sizeof(vexpress_sysreg_sys_mci_pdata),
|
|
|
|
}, {
|
|
|
|
.name = "basic-mmio-gpio",
|
|
|
|
.of_compatible = "arm,vexpress-sysreg,sys_flash",
|
|
|
|
.num_resources = 1,
|
|
|
|
.resources = (struct resource []) {
|
|
|
|
DEFINE_RES_MEM_NAMED(SYS_FLASH, 0x4, "dat"),
|
|
|
|
},
|
|
|
|
.platform_data = &vexpress_sysreg_sys_flash_pdata,
|
|
|
|
.pdata_size = sizeof(vexpress_sysreg_sys_flash_pdata),
|
|
|
|
}, {
|
|
|
|
.name = "vexpress-syscfg",
|
|
|
|
.num_resources = 1,
|
|
|
|
.resources = (struct resource []) {
|
|
|
|
DEFINE_RES_MEM(SYS_CFGDATA, 0xc),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
};
|
2012-09-18 15:24:57 +04:00
|
|
|
|
2012-12-22 03:03:15 +04:00
|
|
|
static int vexpress_sysreg_probe(struct platform_device *pdev)
|
2012-09-18 15:24:57 +04:00
|
|
|
{
|
2014-04-23 13:49:31 +04:00
|
|
|
struct resource *mem;
|
|
|
|
void __iomem *base;
|
2015-12-04 16:02:58 +03:00
|
|
|
struct gpio_chip *mmc_gpio_chip;
|
2015-01-20 20:25:15 +03:00
|
|
|
int master;
|
2014-02-06 18:33:44 +04:00
|
|
|
u32 dt_hbi;
|
2012-09-18 15:24:57 +04:00
|
|
|
|
2014-04-23 13:49:31 +04:00
|
|
|
mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
|
|
if (!mem)
|
|
|
|
return -EINVAL;
|
2012-09-18 15:24:57 +04:00
|
|
|
|
2014-04-23 13:49:31 +04:00
|
|
|
base = devm_ioremap(&pdev->dev, mem->start, resource_size(mem));
|
|
|
|
if (!base)
|
|
|
|
return -ENOMEM;
|
2012-09-18 15:24:57 +04:00
|
|
|
|
2015-01-20 20:25:15 +03:00
|
|
|
master = readl(base + SYS_MISC) & SYS_MISC_MASTERSITE ?
|
|
|
|
VEXPRESS_SITE_DB2 : VEXPRESS_SITE_DB1;
|
|
|
|
vexpress_config_set_master(master);
|
2012-09-18 15:24:57 +04:00
|
|
|
|
2014-02-06 18:33:44 +04:00
|
|
|
/* Confirm board type against DT property, if available */
|
2014-10-03 19:28:27 +04:00
|
|
|
if (of_property_read_u32(of_root, "arm,hbi", &dt_hbi) == 0) {
|
2015-01-20 20:25:15 +03:00
|
|
|
u32 id = readl(base + (master == VEXPRESS_SITE_DB1 ?
|
|
|
|
SYS_PROCID0 : SYS_PROCID1));
|
2014-02-06 18:33:44 +04:00
|
|
|
u32 hbi = (id >> SYS_PROCIDx_HBI_SHIFT) & SYS_HBI_MASK;
|
|
|
|
|
|
|
|
if (WARN_ON(dt_hbi != hbi))
|
|
|
|
dev_warn(&pdev->dev, "DT HBI (%x) is not matching hardware (%x)!\n",
|
|
|
|
dt_hbi, hbi);
|
|
|
|
}
|
|
|
|
|
2014-04-23 13:49:31 +04:00
|
|
|
/*
|
|
|
|
* Duplicated SYS_MCI pseudo-GPIO controller for compatibility with
|
|
|
|
* older trees using sysreg node for MMC control lines.
|
|
|
|
*/
|
|
|
|
mmc_gpio_chip = devm_kzalloc(&pdev->dev, sizeof(*mmc_gpio_chip),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!mmc_gpio_chip)
|
|
|
|
return -ENOMEM;
|
|
|
|
bgpio_init(mmc_gpio_chip, &pdev->dev, 0x4, base + SYS_MCI,
|
|
|
|
NULL, NULL, NULL, NULL, 0);
|
2015-12-04 16:02:58 +03:00
|
|
|
mmc_gpio_chip->ngpio = 2;
|
2020-04-29 23:58:19 +03:00
|
|
|
devm_gpiochip_add_data(&pdev->dev, mmc_gpio_chip, NULL);
|
2014-04-23 13:49:31 +04:00
|
|
|
|
2020-04-29 23:58:19 +03:00
|
|
|
return devm_mfd_add_devices(&pdev->dev, PLATFORM_DEVID_AUTO,
|
2014-04-23 13:49:31 +04:00
|
|
|
vexpress_sysreg_cells,
|
|
|
|
ARRAY_SIZE(vexpress_sysreg_cells), mem, 0, NULL);
|
2012-09-18 15:24:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct of_device_id vexpress_sysreg_match[] = {
|
|
|
|
{ .compatible = "arm,vexpress-sysreg", },
|
|
|
|
{},
|
|
|
|
};
|
2020-04-29 23:58:20 +03:00
|
|
|
MODULE_DEVICE_TABLE(of, vexpress_sysreg_match);
|
2012-09-18 15:24:57 +04:00
|
|
|
|
|
|
|
static struct platform_driver vexpress_sysreg_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "vexpress-sysreg",
|
|
|
|
.of_match_table = vexpress_sysreg_match,
|
|
|
|
},
|
|
|
|
.probe = vexpress_sysreg_probe,
|
|
|
|
};
|
|
|
|
|
2020-04-29 23:58:20 +03:00
|
|
|
module_platform_driver(vexpress_sysreg_driver);
|
|
|
|
MODULE_LICENSE("GPL v2");
|