^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * PRU-ICSS platform driver for various TI SoCs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2014-2020 Texas Instruments Incorporated - http://www.ti.com/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Author(s):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Suman Anna <s-anna@ti.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Andrew F. Davis <afd@ti.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/clk-provider.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/dma-mapping.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/mfd/syscon.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/of_address.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/of_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/pm_runtime.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/pruss_driver.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/regmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * struct pruss_private_data - PRUSS driver private data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * @has_no_sharedram: flag to indicate the absence of PRUSS Shared Data RAM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * @has_core_mux_clock: flag to indicate the presence of PRUSS core clock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) struct pruss_private_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) bool has_no_sharedram;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) bool has_core_mux_clock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) static void pruss_of_free_clk_provider(void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) struct device_node *clk_mux_np = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) of_clk_del_provider(clk_mux_np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) of_node_put(clk_mux_np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) static int pruss_clk_mux_setup(struct pruss *pruss, struct clk *clk_mux,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) char *mux_name, struct device_node *clks_np)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) struct device_node *clk_mux_np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) struct device *dev = pruss->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) char *clk_mux_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) unsigned int num_parents;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) const char **parent_names;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) void __iomem *reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) u32 reg_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) clk_mux_np = of_get_child_by_name(clks_np, mux_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) if (!clk_mux_np) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) dev_err(dev, "%pOF is missing its '%s' node\n", clks_np,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) mux_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) num_parents = of_clk_get_parent_count(clk_mux_np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) if (num_parents < 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) dev_err(dev, "mux-clock %pOF must have parents\n", clk_mux_np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) goto put_clk_mux_np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) parent_names = devm_kcalloc(dev, sizeof(*parent_names), num_parents,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) if (!parent_names) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) goto put_clk_mux_np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) of_clk_parent_fill(clk_mux_np, parent_names, num_parents);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) clk_mux_name = devm_kasprintf(dev, GFP_KERNEL, "%s.%pOFn",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) dev_name(dev), clk_mux_np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) if (!clk_mux_name) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) goto put_clk_mux_np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) ret = of_property_read_u32(clk_mux_np, "reg", ®_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) goto put_clk_mux_np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) reg = pruss->cfg_base + reg_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) clk_mux = clk_register_mux(NULL, clk_mux_name, parent_names,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) num_parents, 0, reg, 0, 1, 0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) if (IS_ERR(clk_mux)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) ret = PTR_ERR(clk_mux);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) goto put_clk_mux_np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) ret = devm_add_action_or_reset(dev, (void(*)(void *))clk_unregister_mux,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) clk_mux);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) dev_err(dev, "failed to add clkmux unregister action %d", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) goto put_clk_mux_np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) ret = of_clk_add_provider(clk_mux_np, of_clk_src_simple_get, clk_mux);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) goto put_clk_mux_np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) ret = devm_add_action_or_reset(dev, pruss_of_free_clk_provider,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) clk_mux_np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) dev_err(dev, "failed to add clkmux free action %d", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) goto put_clk_mux_np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) put_clk_mux_np:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) of_node_put(clk_mux_np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) static int pruss_clk_init(struct pruss *pruss, struct device_node *cfg_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) const struct pruss_private_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) struct device_node *clks_np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) struct device *dev = pruss->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) data = of_device_get_match_data(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) if (IS_ERR(data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) clks_np = of_get_child_by_name(cfg_node, "clocks");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) if (!clks_np) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) dev_err(dev, "%pOF is missing its 'clocks' node\n", cfg_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) if (data && data->has_core_mux_clock) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) ret = pruss_clk_mux_setup(pruss, pruss->core_clk_mux,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) "coreclk-mux", clks_np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) dev_err(dev, "failed to setup coreclk-mux\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) goto put_clks_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) ret = pruss_clk_mux_setup(pruss, pruss->iep_clk_mux, "iepclk-mux",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) clks_np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) dev_err(dev, "failed to setup iepclk-mux\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) goto put_clks_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) put_clks_node:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) of_node_put(clks_np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) static struct regmap_config regmap_conf = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) .reg_bits = 32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) .val_bits = 32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) .reg_stride = 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) static int pruss_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) struct device *dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) struct device_node *np = dev_of_node(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) struct device_node *child;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) struct pruss *pruss;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) struct resource res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) int ret, i, index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) const struct pruss_private_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) const char *mem_names[PRUSS_MEM_MAX] = { "dram0", "dram1", "shrdram2" };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) data = of_device_get_match_data(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) if (IS_ERR(data)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) dev_err(dev, "missing private data\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) ret = dma_set_coherent_mask(dev, DMA_BIT_MASK(32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) dev_err(dev, "failed to set the DMA coherent mask");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) pruss = devm_kzalloc(dev, sizeof(*pruss), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) if (!pruss)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) pruss->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) child = of_get_child_by_name(np, "memories");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) if (!child) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) dev_err(dev, "%pOF is missing its 'memories' node\n", child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) for (i = 0; i < PRUSS_MEM_MAX; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) * On AM437x one of two PRUSS units don't contain Shared RAM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) * skip it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) if (data && data->has_no_sharedram && i == PRUSS_MEM_SHRD_RAM2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) index = of_property_match_string(child, "reg-names",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) mem_names[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) if (index < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) of_node_put(child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) return index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) if (of_address_to_resource(child, index, &res)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) of_node_put(child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) pruss->mem_regions[i].va = devm_ioremap(dev, res.start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) resource_size(&res));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) if (!pruss->mem_regions[i].va) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) dev_err(dev, "failed to parse and map memory resource %d %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) i, mem_names[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) of_node_put(child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) pruss->mem_regions[i].pa = res.start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) pruss->mem_regions[i].size = resource_size(&res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) dev_dbg(dev, "memory %8s: pa %pa size 0x%zx va %pK\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) mem_names[i], &pruss->mem_regions[i].pa,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) pruss->mem_regions[i].size, pruss->mem_regions[i].va);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) of_node_put(child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) platform_set_drvdata(pdev, pruss);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) pm_runtime_enable(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) ret = pm_runtime_get_sync(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) dev_err(dev, "couldn't enable module\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) pm_runtime_put_noidle(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) goto rpm_disable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) child = of_get_child_by_name(np, "cfg");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) if (!child) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) dev_err(dev, "%pOF is missing its 'cfg' node\n", child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) goto rpm_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) if (of_address_to_resource(child, 0, &res)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) goto node_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) pruss->cfg_base = devm_ioremap(dev, res.start, resource_size(&res));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) if (!pruss->cfg_base) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) goto node_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) regmap_conf.name = kasprintf(GFP_KERNEL, "%pOFn@%llx", child,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) (u64)res.start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) regmap_conf.max_register = resource_size(&res) - 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) pruss->cfg_regmap = devm_regmap_init_mmio(dev, pruss->cfg_base,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) ®map_conf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) kfree(regmap_conf.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) if (IS_ERR(pruss->cfg_regmap)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) dev_err(dev, "regmap_init_mmio failed for cfg, ret = %ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) PTR_ERR(pruss->cfg_regmap));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) ret = PTR_ERR(pruss->cfg_regmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) goto node_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) ret = pruss_clk_init(pruss, child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) dev_err(dev, "failed to setup coreclk-mux\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) goto node_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) ret = devm_of_platform_populate(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) dev_err(dev, "failed to register child devices\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) goto node_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) of_node_put(child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) node_put:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) of_node_put(child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) rpm_put:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) pm_runtime_put_sync(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) rpm_disable:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) pm_runtime_disable(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) static int pruss_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) struct device *dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) devm_of_platform_depopulate(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) pm_runtime_put_sync(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) pm_runtime_disable(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) /* instance-specific driver private data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) static const struct pruss_private_data am437x_pruss1_data = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) .has_no_sharedram = false,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) static const struct pruss_private_data am437x_pruss0_data = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) .has_no_sharedram = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) static const struct pruss_private_data am65x_j721e_pruss_data = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) .has_core_mux_clock = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) static const struct of_device_id pruss_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) { .compatible = "ti,am3356-pruss" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) { .compatible = "ti,am4376-pruss0", .data = &am437x_pruss0_data, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) { .compatible = "ti,am4376-pruss1", .data = &am437x_pruss1_data, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) { .compatible = "ti,am5728-pruss" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) { .compatible = "ti,k2g-pruss" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) { .compatible = "ti,am654-icssg", .data = &am65x_j721e_pruss_data, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) { .compatible = "ti,j721e-icssg", .data = &am65x_j721e_pruss_data, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) MODULE_DEVICE_TABLE(of, pruss_of_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) static struct platform_driver pruss_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) .name = "pruss",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) .of_match_table = pruss_of_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) .probe = pruss_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) .remove = pruss_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) module_platform_driver(pruss_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) MODULE_AUTHOR("Suman Anna <s-anna@ti.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) MODULE_DESCRIPTION("PRU-ICSS Subsystem Driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) MODULE_LICENSE("GPL v2");