Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'tegra-for-4.10-bus' of git://git.kernel.org/pub/scm/linux/kernel/git/tegra/linux into next/drivers

bus: Add Tegra GMI support

This provides a driver to enable the use of the Generic Memory Interface
found on Tegra SoCs that can host various types of high-speed devices.

* tag 'tegra-for-4.10-bus' of git://git.kernel.org/pub/scm/linux/kernel/git/tegra/linux:
bus: Add support for Tegra Generic Memory Interface
dt/bindings: Add bindings for Tegra GMI controller

Signed-off-by: Olof Johansson <olof@lixom.net>

+424
+132
Documentation/devicetree/bindings/bus/nvidia,tegra20-gmi.txt
··· 1 + Device tree bindings for NVIDIA Tegra Generic Memory Interface bus 2 + 3 + The Generic Memory Interface bus enables memory transfers between internal and 4 + external memory. Can be used to attach various high speed devices such as 5 + synchronous/asynchronous NOR, FPGA, UARTS and more. 6 + 7 + The actual devices are instantiated from the child nodes of a GMI node. 8 + 9 + Required properties: 10 + - compatible : Should contain one of the following: 11 + For Tegra20 must contain "nvidia,tegra20-gmi". 12 + For Tegra30 must contain "nvidia,tegra30-gmi". 13 + - reg: Should contain GMI controller registers location and length. 14 + - clocks: Must contain an entry for each entry in clock-names. 15 + - clock-names: Must include the following entries: "gmi" 16 + - resets : Must contain an entry for each entry in reset-names. 17 + - reset-names : Must include the following entries: "gmi" 18 + - #address-cells: The number of cells used to represent physical base 19 + addresses in the GMI address space. Should be 2. 20 + - #size-cells: The number of cells used to represent the size of an address 21 + range in the GMI address space. Should be 1. 22 + - ranges: Must be set up to reflect the memory layout with three integer values 23 + for each chip-select line in use (only one entry is supported, see below 24 + comments): 25 + <cs-number> <offset> <physical address of mapping> <size> 26 + 27 + Note that the GMI controller does not have any internal chip-select address 28 + decoding, because of that chip-selects either need to be managed via software 29 + or by employing external chip-select decoding logic. 30 + 31 + If external chip-select logic is used to support multiple devices it is assumed 32 + that the devices use the same timing and so are probably the same type. It also 33 + assumes that they can fit in the 256MB address range. In this case only one 34 + child device is supported which represents the active chip-select line, see 35 + examples for more insight. 36 + 37 + The chip-select number is decoded from the child nodes second address cell of 38 + 'ranges' property, if 'ranges' property is not present or empty chip-select will 39 + then be decoded from the first cell of the 'reg' property. 40 + 41 + Optional child cs node properties: 42 + 43 + - nvidia,snor-data-width-32bit: Use 32bit data-bus, default is 16bit. 44 + - nvidia,snor-mux-mode: Enable address/data MUX mode. 45 + - nvidia,snor-rdy-active-before-data: Assert RDY signal one cycle before data. 46 + If omitted it will be asserted with data. 47 + - nvidia,snor-rdy-active-high: RDY signal is active high 48 + - nvidia,snor-adv-active-high: ADV signal is active high 49 + - nvidia,snor-oe-active-high: WE/OE signal is active high 50 + - nvidia,snor-cs-active-high: CS signal is active high 51 + 52 + Note that there is some special handling for the timing values. 53 + From Tegra TRM: 54 + Programming 0 means 1 clock cycle: actual cycle = programmed cycle + 1 55 + 56 + - nvidia,snor-muxed-width: Number of cycles MUX address/data asserted on the 57 + bus. Valid values are 0-15, default is 1 58 + - nvidia,snor-hold-width: Number of cycles CE stays asserted after the 59 + de-assertion of WR_N (in case of SLAVE/MASTER Request) or OE_N 60 + (in case of MASTER Request). Valid values are 0-15, default is 1 61 + - nvidia,snor-adv-width: Number of cycles during which ADV stays asserted. 62 + Valid values are 0-15, default is 1. 63 + - nvidia,snor-ce-width: Number of cycles before CE is asserted. 64 + Valid values are 0-15, default is 4 65 + - nvidia,snor-we-width: Number of cycles during which WE stays asserted. 66 + Valid values are 0-15, default is 1 67 + - nvidia,snor-oe-width: Number of cycles during which OE stays asserted. 68 + Valid values are 0-255, default is 1 69 + - nvidia,snor-wait-width: Number of cycles before READY is asserted. 70 + Valid values are 0-255, default is 3 71 + 72 + Example with two SJA1000 CAN controllers connected to the GMI bus. We wrap the 73 + controllers with a simple-bus node since they are all connected to the same 74 + chip-select (CS4), in this example external address decoding is provided: 75 + 76 + gmi@70090000 { 77 + compatible = "nvidia,tegra20-gmi"; 78 + reg = <0x70009000 0x1000>; 79 + #address-cells = <2>; 80 + #size-cells = <1>; 81 + clocks = <&tegra_car TEGRA20_CLK_NOR>; 82 + clock-names = "gmi"; 83 + resets = <&tegra_car 42>; 84 + reset-names = "gmi"; 85 + ranges = <4 0 0xd0000000 0xfffffff>; 86 + 87 + status = "okay"; 88 + 89 + bus@4,0 { 90 + compatible = "simple-bus"; 91 + #address-cells = <1>; 92 + #size-cells = <1>; 93 + ranges = <0 4 0 0x40100>; 94 + 95 + nvidia,snor-mux-mode; 96 + nvidia,snor-adv-active-high; 97 + 98 + can@0 { 99 + reg = <0 0x100>; 100 + ... 101 + }; 102 + 103 + can@40000 { 104 + reg = <0x40000 0x100>; 105 + ... 106 + }; 107 + }; 108 + }; 109 + 110 + Example with one SJA1000 CAN controller connected to the GMI bus 111 + on CS4: 112 + 113 + gmi@70090000 { 114 + compatible = "nvidia,tegra20-gmi"; 115 + reg = <0x70009000 0x1000>; 116 + #address-cells = <2>; 117 + #size-cells = <1>; 118 + clocks = <&tegra_car TEGRA20_CLK_NOR>; 119 + clock-names = "gmi"; 120 + resets = <&tegra_car 42>; 121 + reset-names = "gmi"; 122 + ranges = <4 0 0xd0000000 0xfffffff>; 123 + 124 + status = "okay"; 125 + 126 + can@4,0 { 127 + reg = <4 0 0x100>; 128 + nvidia,snor-mux-mode; 129 + nvidia,snor-adv-active-high; 130 + ... 131 + }; 132 + };
+7
drivers/bus/Kconfig
··· 149 149 Driver for the Tegra ACONNECT bus which is used to interface with 150 150 the devices inside the Audio Processing Engine (APE) for Tegra210. 151 151 152 + config TEGRA_GMI 153 + tristate "Tegra Generic Memory Interface bus driver" 154 + depends on ARCH_TEGRA 155 + help 156 + Driver for the Tegra Generic Memory Interface bus which can be used 157 + to attach devices such as NOR, UART, FPGA and more. 158 + 152 159 config UNIPHIER_SYSTEM_BUS 153 160 tristate "UniPhier System Bus driver" 154 161 depends on ARCH_UNIPHIER && OF
+1
drivers/bus/Makefile
··· 19 19 obj-$(CONFIG_SUNXI_RSB) += sunxi-rsb.o 20 20 obj-$(CONFIG_SIMPLE_PM_BUS) += simple-pm-bus.o 21 21 obj-$(CONFIG_TEGRA_ACONNECT) += tegra-aconnect.o 22 + obj-$(CONFIG_TEGRA_GMI) += tegra-gmi.o 22 23 obj-$(CONFIG_UNIPHIER_SYSTEM_BUS) += uniphier-system-bus.o 23 24 obj-$(CONFIG_VEXPRESS_CONFIG) += vexpress-config.o 24 25
+284
drivers/bus/tegra-gmi.c
··· 1 + /* 2 + * Driver for NVIDIA Generic Memory Interface 3 + * 4 + * Copyright (C) 2016 Host Mobility AB. All rights reserved. 5 + * 6 + * This file is licensed under the terms of the GNU General Public 7 + * License version 2. This program is licensed "as is" without any 8 + * warranty of any kind, whether express or implied. 9 + */ 10 + 11 + #include <linux/clk.h> 12 + #include <linux/delay.h> 13 + #include <linux/io.h> 14 + #include <linux/module.h> 15 + #include <linux/of_device.h> 16 + #include <linux/reset.h> 17 + 18 + #define TEGRA_GMI_CONFIG 0x00 19 + #define TEGRA_GMI_CONFIG_GO BIT(31) 20 + #define TEGRA_GMI_BUS_WIDTH_32BIT BIT(30) 21 + #define TEGRA_GMI_MUX_MODE BIT(28) 22 + #define TEGRA_GMI_RDY_BEFORE_DATA BIT(24) 23 + #define TEGRA_GMI_RDY_ACTIVE_HIGH BIT(23) 24 + #define TEGRA_GMI_ADV_ACTIVE_HIGH BIT(22) 25 + #define TEGRA_GMI_OE_ACTIVE_HIGH BIT(21) 26 + #define TEGRA_GMI_CS_ACTIVE_HIGH BIT(20) 27 + #define TEGRA_GMI_CS_SELECT(x) ((x & 0x7) << 4) 28 + 29 + #define TEGRA_GMI_TIMING0 0x10 30 + #define TEGRA_GMI_MUXED_WIDTH(x) ((x & 0xf) << 12) 31 + #define TEGRA_GMI_HOLD_WIDTH(x) ((x & 0xf) << 8) 32 + #define TEGRA_GMI_ADV_WIDTH(x) ((x & 0xf) << 4) 33 + #define TEGRA_GMI_CE_WIDTH(x) (x & 0xf) 34 + 35 + #define TEGRA_GMI_TIMING1 0x14 36 + #define TEGRA_GMI_WE_WIDTH(x) ((x & 0xff) << 16) 37 + #define TEGRA_GMI_OE_WIDTH(x) ((x & 0xff) << 8) 38 + #define TEGRA_GMI_WAIT_WIDTH(x) (x & 0xff) 39 + 40 + #define TEGRA_GMI_MAX_CHIP_SELECT 8 41 + 42 + struct tegra_gmi { 43 + struct device *dev; 44 + void __iomem *base; 45 + struct clk *clk; 46 + struct reset_control *rst; 47 + 48 + u32 snor_config; 49 + u32 snor_timing0; 50 + u32 snor_timing1; 51 + }; 52 + 53 + static int tegra_gmi_enable(struct tegra_gmi *gmi) 54 + { 55 + int err; 56 + 57 + err = clk_prepare_enable(gmi->clk); 58 + if (err < 0) { 59 + dev_err(gmi->dev, "failed to enable clock: %d\n", err); 60 + return err; 61 + } 62 + 63 + reset_control_assert(gmi->rst); 64 + usleep_range(2000, 4000); 65 + reset_control_deassert(gmi->rst); 66 + 67 + writel(gmi->snor_timing0, gmi->base + TEGRA_GMI_TIMING0); 68 + writel(gmi->snor_timing1, gmi->base + TEGRA_GMI_TIMING1); 69 + 70 + gmi->snor_config |= TEGRA_GMI_CONFIG_GO; 71 + writel(gmi->snor_config, gmi->base + TEGRA_GMI_CONFIG); 72 + 73 + return 0; 74 + } 75 + 76 + static void tegra_gmi_disable(struct tegra_gmi *gmi) 77 + { 78 + u32 config; 79 + 80 + /* stop GMI operation */ 81 + config = readl(gmi->base + TEGRA_GMI_CONFIG); 82 + config &= ~TEGRA_GMI_CONFIG_GO; 83 + writel(config, gmi->base + TEGRA_GMI_CONFIG); 84 + 85 + reset_control_assert(gmi->rst); 86 + clk_disable_unprepare(gmi->clk); 87 + } 88 + 89 + static int tegra_gmi_parse_dt(struct tegra_gmi *gmi) 90 + { 91 + struct device_node *child; 92 + u32 property, ranges[4]; 93 + int err; 94 + 95 + child = of_get_next_available_child(gmi->dev->of_node, NULL); 96 + if (!child) { 97 + dev_err(gmi->dev, "no child nodes found\n"); 98 + return -ENODEV; 99 + } 100 + 101 + /* 102 + * We currently only support one child device due to lack of 103 + * chip-select address decoding. Which means that we only have one 104 + * chip-select line from the GMI controller. 105 + */ 106 + if (of_get_child_count(gmi->dev->of_node) > 1) 107 + dev_warn(gmi->dev, "only one child device is supported."); 108 + 109 + if (of_property_read_bool(child, "nvidia,snor-data-width-32bit")) 110 + gmi->snor_config |= TEGRA_GMI_BUS_WIDTH_32BIT; 111 + 112 + if (of_property_read_bool(child, "nvidia,snor-mux-mode")) 113 + gmi->snor_config |= TEGRA_GMI_MUX_MODE; 114 + 115 + if (of_property_read_bool(child, "nvidia,snor-rdy-active-before-data")) 116 + gmi->snor_config |= TEGRA_GMI_RDY_BEFORE_DATA; 117 + 118 + if (of_property_read_bool(child, "nvidia,snor-rdy-active-high")) 119 + gmi->snor_config |= TEGRA_GMI_RDY_ACTIVE_HIGH; 120 + 121 + if (of_property_read_bool(child, "nvidia,snor-adv-active-high")) 122 + gmi->snor_config |= TEGRA_GMI_ADV_ACTIVE_HIGH; 123 + 124 + if (of_property_read_bool(child, "nvidia,snor-oe-active-high")) 125 + gmi->snor_config |= TEGRA_GMI_OE_ACTIVE_HIGH; 126 + 127 + if (of_property_read_bool(child, "nvidia,snor-cs-active-high")) 128 + gmi->snor_config |= TEGRA_GMI_CS_ACTIVE_HIGH; 129 + 130 + /* Decode the CS# */ 131 + err = of_property_read_u32_array(child, "ranges", ranges, 4); 132 + if (err < 0) { 133 + /* Invalid binding */ 134 + if (err == -EOVERFLOW) { 135 + dev_err(gmi->dev, 136 + "failed to decode CS: invalid ranges length\n"); 137 + goto error_cs; 138 + } 139 + 140 + /* 141 + * If we reach here it means that the child node has an empty 142 + * ranges or it does not exist at all. Attempt to decode the 143 + * CS# from the reg property instead. 144 + */ 145 + err = of_property_read_u32(child, "reg", &property); 146 + if (err < 0) { 147 + dev_err(gmi->dev, 148 + "failed to decode CS: no reg property found\n"); 149 + goto error_cs; 150 + } 151 + } else { 152 + property = ranges[1]; 153 + } 154 + 155 + /* Valid chip selects are CS0-CS7 */ 156 + if (property >= TEGRA_GMI_MAX_CHIP_SELECT) { 157 + dev_err(gmi->dev, "invalid chip select: %d", property); 158 + err = -EINVAL; 159 + goto error_cs; 160 + } 161 + 162 + gmi->snor_config |= TEGRA_GMI_CS_SELECT(property); 163 + 164 + /* The default values that are provided below are reset values */ 165 + if (!of_property_read_u32(child, "nvidia,snor-muxed-width", &property)) 166 + gmi->snor_timing0 |= TEGRA_GMI_MUXED_WIDTH(property); 167 + else 168 + gmi->snor_timing0 |= TEGRA_GMI_MUXED_WIDTH(1); 169 + 170 + if (!of_property_read_u32(child, "nvidia,snor-hold-width", &property)) 171 + gmi->snor_timing0 |= TEGRA_GMI_HOLD_WIDTH(property); 172 + else 173 + gmi->snor_timing0 |= TEGRA_GMI_HOLD_WIDTH(1); 174 + 175 + if (!of_property_read_u32(child, "nvidia,snor-adv-width", &property)) 176 + gmi->snor_timing0 |= TEGRA_GMI_ADV_WIDTH(property); 177 + else 178 + gmi->snor_timing0 |= TEGRA_GMI_ADV_WIDTH(1); 179 + 180 + if (!of_property_read_u32(child, "nvidia,snor-ce-width", &property)) 181 + gmi->snor_timing0 |= TEGRA_GMI_CE_WIDTH(property); 182 + else 183 + gmi->snor_timing0 |= TEGRA_GMI_CE_WIDTH(4); 184 + 185 + if (!of_property_read_u32(child, "nvidia,snor-we-width", &property)) 186 + gmi->snor_timing1 |= TEGRA_GMI_WE_WIDTH(property); 187 + else 188 + gmi->snor_timing1 |= TEGRA_GMI_WE_WIDTH(1); 189 + 190 + if (!of_property_read_u32(child, "nvidia,snor-oe-width", &property)) 191 + gmi->snor_timing1 |= TEGRA_GMI_OE_WIDTH(property); 192 + else 193 + gmi->snor_timing1 |= TEGRA_GMI_OE_WIDTH(1); 194 + 195 + if (!of_property_read_u32(child, "nvidia,snor-wait-width", &property)) 196 + gmi->snor_timing1 |= TEGRA_GMI_WAIT_WIDTH(property); 197 + else 198 + gmi->snor_timing1 |= TEGRA_GMI_WAIT_WIDTH(3); 199 + 200 + error_cs: 201 + of_node_put(child); 202 + return err; 203 + } 204 + 205 + static int tegra_gmi_probe(struct platform_device *pdev) 206 + { 207 + struct device *dev = &pdev->dev; 208 + struct tegra_gmi *gmi; 209 + struct resource *res; 210 + int err; 211 + 212 + gmi = devm_kzalloc(dev, sizeof(*gmi), GFP_KERNEL); 213 + if (!gmi) 214 + return -ENOMEM; 215 + 216 + gmi->dev = dev; 217 + 218 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 219 + gmi->base = devm_ioremap_resource(dev, res); 220 + if (IS_ERR(gmi->base)) 221 + return PTR_ERR(gmi->base); 222 + 223 + gmi->clk = devm_clk_get(dev, "gmi"); 224 + if (IS_ERR(gmi->clk)) { 225 + dev_err(dev, "can not get clock\n"); 226 + return PTR_ERR(gmi->clk); 227 + } 228 + 229 + gmi->rst = devm_reset_control_get(dev, "gmi"); 230 + if (IS_ERR(gmi->rst)) { 231 + dev_err(dev, "can not get reset\n"); 232 + return PTR_ERR(gmi->rst); 233 + } 234 + 235 + err = tegra_gmi_parse_dt(gmi); 236 + if (err) 237 + return err; 238 + 239 + err = tegra_gmi_enable(gmi); 240 + if (err < 0) 241 + return err; 242 + 243 + err = of_platform_default_populate(dev->of_node, NULL, dev); 244 + if (err < 0) { 245 + dev_err(dev, "fail to create devices.\n"); 246 + tegra_gmi_disable(gmi); 247 + return err; 248 + } 249 + 250 + platform_set_drvdata(pdev, gmi); 251 + 252 + return 0; 253 + } 254 + 255 + static int tegra_gmi_remove(struct platform_device *pdev) 256 + { 257 + struct tegra_gmi *gmi = platform_get_drvdata(pdev); 258 + 259 + of_platform_depopulate(gmi->dev); 260 + tegra_gmi_disable(gmi); 261 + 262 + return 0; 263 + } 264 + 265 + static const struct of_device_id tegra_gmi_id_table[] = { 266 + { .compatible = "nvidia,tegra20-gmi", }, 267 + { .compatible = "nvidia,tegra30-gmi", }, 268 + { } 269 + }; 270 + MODULE_DEVICE_TABLE(of, tegra_gmi_id_table); 271 + 272 + static struct platform_driver tegra_gmi_driver = { 273 + .probe = tegra_gmi_probe, 274 + .remove = tegra_gmi_remove, 275 + .driver = { 276 + .name = "tegra-gmi", 277 + .of_match_table = tegra_gmi_id_table, 278 + }, 279 + }; 280 + module_platform_driver(tegra_gmi_driver); 281 + 282 + MODULE_AUTHOR("Mirza Krak <mirza.krak@gmail.com"); 283 + MODULE_DESCRIPTION("NVIDIA Tegra GMI Bus Driver"); 284 + MODULE_LICENSE("GPL v2");