static int __init amigaone_add_bridge(struct device_node *dev) { const u32 *cfg_addr, *cfg_data; int len; const int *bus_range; struct pci_controller *hose; printk(KERN_INFO "Adding PCI host bridge %s\n", dev->full_name); cfg_addr = of_get_address(dev, 0, NULL, NULL); cfg_data = of_get_address(dev, 1, NULL, NULL); if ((cfg_addr == NULL) || (cfg_data == NULL)) return -ENODEV; bus_range = of_get_property(dev, "bus-range", &len); if ((bus_range == NULL) || (len < 2 * sizeof(int))) printk(KERN_WARNING "Can't get bus-range for %s, assume" " bus 0\n", dev->full_name); hose = pcibios_alloc_controller(dev); if (hose == NULL) return -ENOMEM; hose->first_busno = bus_range ? bus_range[0] : 0; hose->last_busno = bus_range ? bus_range[1] : 0xff; setup_indirect_pci(hose, cfg_addr[0], cfg_data[0], 0); /* Interpret the "ranges" property */ /* This also maps the I/O region and sets isa_io/mem_base */ pci_process_bridge_OF_ranges(hose, dev, 1); return 0; }
static void qe_muram_init(void) { struct device_node *np; const u32 *address; u64 size; unsigned int flags; /* initialize the info header */ rh_init(&qe_muram_info, 1, sizeof(qe_boot_muram_rh_block) / sizeof(qe_boot_muram_rh_block[0]), qe_boot_muram_rh_block); /* Attach the usable muram area */ /* XXX: This is a subset of the available muram. It * varies with the processor and the microcode patches activated. */ np = of_find_compatible_node(NULL, NULL, "fsl,qe-muram-data"); if (!np) { np = of_find_node_by_name(NULL, "data-only"); if (!np) { WARN_ON(1); return; } } address = of_get_address(np, 0, &size, &flags); WARN_ON(!address); of_node_put(np); if (address) rh_attach_region(&qe_muram_info, *address, (int)size); }
void __init exynos_firmware_init(void) { struct device_node *nd; const __be32 *addr; nd = of_find_compatible_node(NULL, NULL, "samsung,secure-firmware"); if (!nd) return; addr = of_get_address(nd, 0, NULL, NULL); if (!addr) { pr_err("%s: No address specified.\n", __func__); return; } pr_info("Running under secure firmware.\n"); register_firmware_ops(&exynos_firmware_ops); /* * Exynos 4 SoCs (based on Cortex A9 and equipped with L2C-310), * running under secure firmware, require certain registers of L2 * cache controller to be written in secure mode. Here .write_sec * callback is provided to perform necessary SMC calls. */ if (IS_ENABLED(CONFIG_CACHE_L2X0) && read_cpuid_part() == ARM_CPU_PART_CORTEX_A9) { outer_cache.write_sec = exynos_l2_write_sec; outer_cache.configure = exynos_l2_configure; } }
int bman_init_ccsr(const struct device_node *node) { static int ccsr_map_fd; uint64_t phys_addr; const uint32_t *bman_addr; uint64_t regs_size; bman_addr = of_get_address(node, 0, ®s_size, NULL); if (!bman_addr) { pr_err("of_get_address cannot return BMan address"); return -EINVAL; } phys_addr = of_translate_address(node, bman_addr); if (!phys_addr) { pr_err("of_translate_address failed"); return -EINVAL; } ccsr_map_fd = open(BMAN_CCSR_MAP, O_RDWR); if (unlikely(ccsr_map_fd < 0)) { pr_err("Can not open /dev/mem for BMan CCSR map"); return ccsr_map_fd; } bman_ccsr_map = mmap(NULL, regs_size, PROT_READ | PROT_WRITE, MAP_SHARED, ccsr_map_fd, phys_addr); if (bman_ccsr_map == MAP_FAILED) { pr_err("Can not map BMan CCSR base Bman: " "0x%x Phys: 0x%lx size 0x%lx", *bman_addr, phys_addr, regs_size); return -EINVAL; } return 0; }
static int mpm_parse_dt(void) { struct device_node *np; u32 freq; np = of_find_matching_node(NULL, mpm_counter_of_match); if (!np) { pr_err("mpm_counter: can't find DT node\n"); return -ENODEV; } if (!of_property_read_u32(np, "clock-frequency", &freq)) mpm_counter_freq = freq; else return -ENODEV; if (of_get_address(np, 0, NULL, NULL)) { mpm_counter_base = of_iomap(np, 0); if (!mpm_counter_base) { pr_err("mpm_counter: cant map counter base\n"); return -ENODEV; } } return 0; }
static int __init add_legacy_soc_port(struct device_node *np, struct device_node *soc_dev) { u64 addr; const u32 *addrp; upf_t flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST | UPF_SHARE_IRQ; struct device_node *tsi = of_get_parent(np); /* We only support ports that have a clock frequency properly * encoded in the device-tree. */ if (get_property(np, "clock-frequency", NULL) == NULL) return -1; /* if rtas uses this device, don't try to use it as well */ if (get_property(np, "used-by-rtas", NULL) != NULL) return -1; /* Get the address */ addrp = of_get_address(soc_dev, 0, NULL, NULL); if (addrp == NULL) return -1; addr = of_translate_address(soc_dev, addrp); if (addr == OF_BAD_ADDR) return -1; /* Add port, irq will be dealt with later. We passed a translated * IO port value. It will be fixed up later along with the irq */ if (tsi && !strcmp(tsi->type, "tsi-bridge")) return add_legacy_port(np, -1, UPIO_TSI, addr, addr, NO_IRQ, flags, 0); else return add_legacy_port(np, -1, UPIO_MEM, addr, addr, NO_IRQ, flags, 0); }
static void bcm2835_dma_init(struct spi_master *master, struct device *dev) { struct dma_slave_config slave_config; const __be32 *addr; dma_addr_t dma_reg_base; int ret; /* base address in dma-space */ addr = of_get_address(master->dev.of_node, 0, NULL, NULL); if (!addr) { dev_err(dev, "could not get DMA-register address - not using dma mode\n"); goto err; } dma_reg_base = be32_to_cpup(addr); /* get tx/rx dma */ master->dma_tx = dma_request_slave_channel(dev, "tx"); if (!master->dma_tx) { dev_err(dev, "no tx-dma configuration found - not using dma mode\n"); goto err; } master->dma_rx = dma_request_slave_channel(dev, "rx"); if (!master->dma_rx) { dev_err(dev, "no rx-dma configuration found - not using dma mode\n"); goto err_release; } /* configure DMAs */ slave_config.direction = DMA_MEM_TO_DEV; slave_config.dst_addr = (u32)(dma_reg_base + BCM2835_SPI_FIFO); slave_config.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; ret = dmaengine_slave_config(master->dma_tx, &slave_config); if (ret) goto err_config; slave_config.direction = DMA_DEV_TO_MEM; slave_config.src_addr = (u32)(dma_reg_base + BCM2835_SPI_FIFO); slave_config.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; ret = dmaengine_slave_config(master->dma_rx, &slave_config); if (ret) goto err_config; /* all went well, so set can_dma */ master->can_dma = bcm2835_spi_can_dma; master->max_dma_len = 65535; /* limitation by BCM2835_SPI_DLEN */ /* need to do TX AND RX DMA, so we need dummy buffers */ master->flags = SPI_MASTER_MUST_RX | SPI_MASTER_MUST_TX; return; err_config: dev_err(dev, "issue configuring dma: %d - not using DMA mode\n", ret); err_release: bcm2835_dma_release(master); err: return; }
/*Add Device tree for ramoops, linux patch 2fddba4..1d43305 ++ */ static int __init of_ramoops_platform_data(struct device_node *node, struct ramoops_platform_data *pdata) { const __be32 *addrp; const __be32 *prop; u64 size; memset(pdata, 0, sizeof(*pdata)); addrp = of_get_address(node, 0, &size, NULL); if (addrp == NULL) return -EINVAL; pdata->mem_address = of_translate_address(node, addrp); pdata->mem_size = size; prop = of_get_property(node, "record-size", NULL); if (!prop) return -EINVAL; pdata->record_size = be32_to_cpup(prop); prop = of_get_property(node, "console-size", NULL); if (!prop) return -EINVAL; pdata->console_size = be32_to_cpup(prop); prop = of_get_property(node, "ftrace-size", NULL); if (!prop) return -EINVAL; pdata->ftrace_size = be32_to_cpup(prop); prop = of_get_property(node, "dump-oops", NULL); if (!prop) return -EINVAL; pdata->dump_oops = be32_to_cpup(prop); return 0; }
/** * of_device_make_bus_id - Use the device node data to assign a unique name * @dev: pointer to device structure that is linked to a device tree node * * This routine will first try using either the dcr-reg or the reg property * value to derive a unique name. As a last resort it will use the node * name followed by a unique number. */ void of_device_make_bus_id(struct device *dev) { static atomic_t bus_no_reg_magic; struct device_node *node = dev->of_node; const __be32 *reg; u64 addr; const __be32 *addrp; int magic; #ifdef CONFIG_PPC_DCR /* * If it's a DCR based device, use 'd' for native DCRs * and 'D' for MMIO DCRs. */ reg = of_get_property(node, "dcr-reg", NULL); if (reg) { #ifdef CONFIG_PPC_DCR_NATIVE dev_set_name(dev, "d%x.%s", *reg, node->name); #else /* CONFIG_PPC_DCR_NATIVE */ u64 addr = of_translate_dcr_address(node, *reg, NULL); if (addr != OF_BAD_ADDR) { dev_set_name(dev, "D%llx.%s", (unsigned long long)addr, node->name); return; } #endif /* !CONFIG_PPC_DCR_NATIVE */ } #endif /* CONFIG_PPC_DCR */ /* * For MMIO, get the physical address */ reg = of_get_property(node, "reg", NULL); if (reg) { if (of_can_translate_address(node)) { addr = of_translate_address(node, reg); } else { addrp = of_get_address(node, 0, NULL, NULL); if (addrp) addr = of_read_number(addrp, 1); else addr = OF_BAD_ADDR; } if (addr != OF_BAD_ADDR) { dev_set_name(dev, "%llx.%s", (unsigned long long)addr, node->name); return; } } /* * No BusID, use the node name and add a globally incremented * counter (and pray...) */ magic = atomic_add_return(1, &bus_no_reg_magic); dev_set_name(dev, "%s.%d", node->name, magic - 1); }
int of_address_to_resource(struct device_node *dev, int index, struct resource *r) { const u32 *addrp; u64 size; unsigned int flags; addrp = of_get_address(dev, index, &size, &flags); if (addrp == NULL) return -EINVAL; return __of_address_to_resource(dev, addrp, size, flags, r); }
static int bcm2835_smi_probe(struct platform_device *pdev) { int err; struct device *dev = &pdev->dev; struct device_node *node = dev->of_node; struct resource *ioresource; struct bcm2835_smi_instance *inst; /* Allocate buffers and instance data */ inst = devm_kzalloc(dev, sizeof(struct bcm2835_smi_instance), GFP_KERNEL); if (!inst) return -ENOMEM; inst->dev = dev; spin_lock_init(&inst->transaction_lock); /* We require device tree support */ if (!node) return -EINVAL; ioresource = platform_get_resource(pdev, IORESOURCE_MEM, 0); inst->smi_regs_ptr = devm_ioremap_resource(dev, ioresource); ioresource = platform_get_resource(pdev, IORESOURCE_MEM, 1); inst->cm_smi_regs_ptr = devm_ioremap_resource(dev, ioresource); inst->smi_regs_busaddr = be32_to_cpu( *of_get_address(node, 0, NULL, NULL)); of_property_read_u32(node, "brcm,smi-clock-source", &inst->clock_source); of_property_read_u32(node, "brcm,smi-clock-divisor", &inst->clock_divisor); err = bcm2835_smi_dma_setup(inst); if (err) return err; /* Finally, do peripheral setup */ smi_setup_clock(inst); smi_setup_regs(inst); platform_set_drvdata(pdev, inst); dev_info(inst->dev, "initialised"); return 0; }
static int read_handle(struct device_node *np, u64 *handle) { const __be32 *prop; u64 size; /* Get address and size of the node */ prop = of_get_address(np, 0, &size, NULL); if (size) return -EINVAL; /* Helper to read a big number; size is in cells (not bytes) */ *handle = of_read_number(prop, of_n_addr_cells(np)); return 0; }
void of_device_make_bus_id(struct device *dev) { static atomic_t bus_no_reg_magic; struct device_node *node = dev->of_node; const u32 *reg; u64 addr; const __be32 *addrp; int magic; #ifdef CONFIG_PPC_DCR reg = of_get_property(node, "dcr-reg", NULL); if (reg) { #ifdef CONFIG_PPC_DCR_NATIVE dev_set_name(dev, "d%x.%s", *reg, node->name); #else u64 addr = of_translate_dcr_address(node, *reg, NULL); if (addr != OF_BAD_ADDR) { dev_set_name(dev, "D%llx.%s", (unsigned long long)addr, node->name); return; } #endif } #endif reg = of_get_property(node, "reg", NULL); if (reg) { if (of_can_translate_address(node)) { addr = of_translate_address(node, reg); } else { addrp = of_get_address(node, 0, NULL, NULL); if (addrp) addr = of_read_number(addrp, 1); else addr = OF_BAD_ADDR; } if (addr != OF_BAD_ADDR) { dev_set_name(dev, "%llx.%s", (unsigned long long)addr, node->name); return; } } magic = atomic_add_return(1, &bus_no_reg_magic); dev_set_name(dev, "%s.%d", node->name, magic - 1); }
/** * of_address_to_resource - Translate device tree address and return as resource * * Note that if your address is a PIO address, the conversion will fail if * the physical address can't be internally converted to an IO token with * pci_address_to_pio(), that is because it's either called too early or it * can't be matched to any host bridge IO space */ int of_address_to_resource(struct device_node *dev, int index, struct resource *r) { const __be32 *addrp; u64 size; unsigned int flags; const char *name = NULL; addrp = of_get_address(dev, index, &size, &flags); if (addrp == NULL) return -EINVAL; /* Get optional "reg-names" property to add a name to a resource */ of_property_read_string_index(dev, "reg-names", index, &name); return __of_address_to_resource(dev, addrp, size, flags, name, r); }
int miphy365x_get_addr(struct device *dev, struct miphy365x_phy *miphy_phy, int index) { struct device_node *phynode = miphy_phy->phy->dev.of_node; const char *name; const __be32 *taddr; int type = miphy_phy->type; int ret; ret = of_property_read_string_index(phynode, "reg-names", index, &name); if (ret) { dev_err(dev, "no reg-names property not found\n"); return ret; } if (!strncmp(name, "syscfg", 6)) { taddr = of_get_address(phynode, index, NULL, NULL); if (!taddr) { dev_err(dev, "failed to fetch syscfg address\n"); return -EINVAL; } miphy_phy->ctrlreg = of_translate_address(phynode, taddr); if (miphy_phy->ctrlreg == OF_BAD_ADDR) { dev_err(dev, "failed to translate syscfg address\n"); return -EINVAL; } return 0; } if (!((!strncmp(name, "sata", 4) && type == MIPHY_TYPE_SATA) || (!strncmp(name, "pcie", 4) && type == MIPHY_TYPE_PCIE))) return 0; miphy_phy->base = of_iomap(phynode, index); if (!miphy_phy->base) { dev_err(dev, "Failed to map %s\n", phynode->full_name); return -EINVAL; } return 0; }
void __init exynos_firmware_init(void) { struct device_node *nd; const __be32 *addr; nd = of_find_compatible_node(NULL, NULL, "samsung,secure-firmware"); if (!nd) return; addr = of_get_address(nd, 0, NULL, NULL); if (!addr) { pr_err("%s: No address specified.\n", __func__); return; } pr_info("Running under secure firmware.\n"); register_firmware_ops(&exynos_firmware_ops); }
static int mnemosyne_parse_dt(struct device_node *node) { phys_addr_t phys = 0, size = 0; struct device_node *pnode = NULL; int ret; pr_info("%s: init from device tree.\n", MNEMOSYNE_MODULE_NAME); if (node == NULL) { pr_err("%s: Can't find device_node", MNEMOSYNE_MODULE_NAME); ret = -ENODEV; goto PARSE_DT_ERR_OUT; } pnode = of_parse_phandle(node, "linux,contiguous-region", 0); if (!pnode) { pr_err("%s: mnemosyne memory is not reserved.\n", MNEMOSYNE_MODULE_NAME); } else { const __be32 *prop; int addr_cells, size_cells; prop = of_get_address(pnode, 0, NULL, NULL); if (!prop) { pr_err("%s: Can't find register property", MNEMOSYNE_MODULE_NAME); ret = -ENODEV; of_node_put(pnode); goto PARSE_DT_ERR_OUT; } of_node_put(pnode); addr_cells = of_n_addr_cells(pnode); size_cells = of_n_size_cells(pnode); phys = of_read_number(prop, addr_cells); size = of_read_number(prop + addr_cells, size_cells); } ret = mnemosyne_setup(phys, size); PARSE_DT_ERR_OUT: return ret; }
static void __iomem *offb_map_reg(struct device_node *np, int index, unsigned long offset, unsigned long size) { const u32 *addrp; u64 asize, taddr; unsigned int flags; addrp = of_get_pci_address(np, index, &asize, &flags); if (addrp == NULL) addrp = of_get_address(np, index, &asize, &flags); if (addrp == NULL) return NULL; if ((flags & (IORESOURCE_IO | IORESOURCE_MEM)) == 0) return NULL; if ((offset + size) > asize) return NULL; taddr = of_translate_address(np, addrp); if (taddr == OF_BAD_ADDR) return NULL; return ioremap(taddr + offset, size); }
static void qe_muram_init(void) { struct device_node *np; u32 address; u64 size; unsigned int flags; /* initialize the info header */ rh_init(&qe_muram_info, 1, sizeof(qe_boot_muram_rh_block) / sizeof(qe_boot_muram_rh_block[0]), qe_boot_muram_rh_block); /* Attach the usable muram area */ /* XXX: This is a subset of the available muram. It * varies with the processor and the microcode patches activated. */ if ((np = of_find_node_by_name(NULL, "data-only")) != NULL) { address = *of_get_address(np, 0, &size, &flags); of_node_put(np); rh_attach_region(&qe_muram_info, address, (int) size); } }
void __iomem * mpc52xx_find_and_map(const char *compatible) { struct device_node *ofn; const u32 *regaddr_p; u64 regaddr64, size64; ofn = of_find_compatible_node(NULL, NULL, compatible); if (!ofn) return NULL; regaddr_p = of_get_address(ofn, 0, &size64, NULL); if (!regaddr_p) { of_node_put(ofn); return NULL; } regaddr64 = of_translate_address(ofn, regaddr_p); of_node_put(ofn); return ioremap((u32)regaddr64, (u32)size64); }
static void __init offb_init_nodriver(struct device_node *dp, int no_real_node) { unsigned int len; int i, width = 640, height = 480, depth = 8, pitch = 640; unsigned int flags, rsize, addr_prop = 0; unsigned long max_size = 0; u64 rstart, address = OF_BAD_ADDR; const u32 *pp, *addrp, *up; u64 asize; int foreign_endian = 0; #ifdef __BIG_ENDIAN if (of_get_property(dp, "little-endian", NULL)) foreign_endian = FBINFO_FOREIGN_ENDIAN; #else if (of_get_property(dp, "big-endian", NULL)) foreign_endian = FBINFO_FOREIGN_ENDIAN; #endif pp = of_get_property(dp, "linux,bootx-depth", &len); if (pp == NULL) pp = of_get_property(dp, "depth", &len); if (pp && len == sizeof(u32)) depth = *pp; pp = of_get_property(dp, "linux,bootx-width", &len); if (pp == NULL) pp = of_get_property(dp, "width", &len); if (pp && len == sizeof(u32)) width = *pp; pp = of_get_property(dp, "linux,bootx-height", &len); if (pp == NULL) pp = of_get_property(dp, "height", &len); if (pp && len == sizeof(u32)) height = *pp; pp = of_get_property(dp, "linux,bootx-linebytes", &len); if (pp == NULL) pp = of_get_property(dp, "linebytes", &len); if (pp && len == sizeof(u32) && (*pp != 0xffffffffu)) pitch = *pp; else pitch = width * ((depth + 7) / 8); rsize = (unsigned long)pitch * (unsigned long)height; /* Ok, now we try to figure out the address of the framebuffer. * * Unfortunately, Open Firmware doesn't provide a standard way to do * so. All we can do is a dodgy heuristic that happens to work in * practice. On most machines, the "address" property contains what * we need, though not on Matrox cards found in IBM machines. What I've * found that appears to give good results is to go through the PCI * ranges and pick one that is both big enough and if possible encloses * the "address" property. If none match, we pick the biggest */ up = of_get_property(dp, "linux,bootx-addr", &len); if (up == NULL) up = of_get_property(dp, "address", &len); if (up && len == sizeof(u32)) addr_prop = *up; /* Hack for when BootX is passing us */ if (no_real_node) goto skip_addr; for (i = 0; (addrp = of_get_address(dp, i, &asize, &flags)) != NULL; i++) { int match_addrp = 0; if (!(flags & IORESOURCE_MEM)) continue; if (asize < rsize) continue; rstart = of_translate_address(dp, addrp); if (rstart == OF_BAD_ADDR) continue; if (addr_prop && (rstart <= addr_prop) && ((rstart + asize) >= (addr_prop + rsize))) match_addrp = 1; if (match_addrp) { address = addr_prop; break; } if (rsize > max_size) { max_size = rsize; address = OF_BAD_ADDR; } if (address == OF_BAD_ADDR) address = rstart; } skip_addr: if (address == OF_BAD_ADDR && addr_prop) address = (u64)addr_prop; if (address != OF_BAD_ADDR) { /* kludge for valkyrie */ if (strcmp(dp->name, "valkyrie") == 0) address += 0x1000; offb_init_fb(no_real_node ? "bootx" : dp->name, no_real_node ? "display" : dp->full_name, width, height, depth, pitch, address, foreign_endian, no_real_node ? NULL : dp); } }
int bcom_sram_init(struct device_node *sram_node, char *owner) { int rv; const u32 *regaddr_p; u64 regaddr64, size64; unsigned int psize; if (bcom_sram) { printk(KERN_ERR "%s: bcom_sram_init: " "Already initialized !\n", owner); return -EBUSY; } bcom_sram = kmalloc(sizeof(struct bcom_sram), GFP_KERNEL); if (!bcom_sram) { printk(KERN_ERR "%s: bcom_sram_init: " "Couldn't allocate internal state !\n", owner); return -ENOMEM; } regaddr_p = of_get_address(sram_node, 0, &size64, NULL); if (!regaddr_p) { printk(KERN_ERR "%s: bcom_sram_init: " "Invalid device node !\n", owner); rv = -EINVAL; goto error_free; } regaddr64 = of_translate_address(sram_node, regaddr_p); bcom_sram->base_phys = (phys_addr_t) regaddr64; bcom_sram->size = (unsigned int) size64; if (!request_mem_region(bcom_sram->base_phys, bcom_sram->size, owner)) { printk(KERN_ERR "%s: bcom_sram_init: " "Couldn't request region !\n", owner); rv = -EBUSY; goto error_free; } bcom_sram->base_virt = (void*) ioremap(bcom_sram->base_phys, bcom_sram->size); if (!bcom_sram->base_virt) { printk(KERN_ERR "%s: bcom_sram_init: " "Map error SRAM zone 0x%08lx (0x%0x)!\n", owner, (long)bcom_sram->base_phys, bcom_sram->size ); rv = -ENOMEM; goto error_release; } bcom_sram->rh = rh_create(4); #if 0 reg_addr_p = of_get_property(sram_node, "available", &psize); #else regaddr_p = NULL; psize = 0; #endif if (!regaddr_p || !psize) { rh_attach_region(bcom_sram->rh, 0, bcom_sram->size); } else { while (psize >= 2 * sizeof(u32)) { phys_addr_t zbase = of_translate_address(sram_node, regaddr_p); rh_attach_region(bcom_sram->rh, zbase - bcom_sram->base_phys, regaddr_p[1]); regaddr_p += 2; psize -= 2 * sizeof(u32); } } spin_lock_init(&bcom_sram->lock); return 0; error_release: release_mem_region(bcom_sram->base_phys, bcom_sram->size); error_free: kfree(bcom_sram); bcom_sram = NULL; return rv; }
static int wkup_m3_rproc_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct wkup_m3_platform_data *pdata = dev->platform_data; /* umem always needs to be processed first */ const char *mem_names[WKUPM3_MEM_MAX] = { "umem", "dmem" }; struct wkup_m3_rproc *wkupm3; const char *fw_name; struct rproc *rproc; struct resource *res; const __be32 *addrp; u32 l4_offset = 0; u64 size; int ret; int i; if (!(pdata && pdata->deassert_reset && pdata->assert_reset && pdata->reset_name)) { dev_err(dev, "Platform data missing!\n"); return -ENODEV; } ret = of_property_read_string(dev->of_node, "ti,pm-firmware", &fw_name); if (ret) { dev_err(dev, "No firmware filename given\n"); return -ENODEV; } pm_runtime_enable(&pdev->dev); ret = pm_runtime_get_sync(&pdev->dev); if (ret < 0) { dev_err(&pdev->dev, "pm_runtime_get_sync() failed\n"); goto err; } rproc = rproc_alloc(dev, "wkup_m3", &wkup_m3_rproc_ops, fw_name, sizeof(*wkupm3)); if (!rproc) { ret = -ENOMEM; goto err; } rproc->auto_boot = false; wkupm3 = rproc->priv; wkupm3->rproc = rproc; wkupm3->pdev = pdev; for (i = 0; i < ARRAY_SIZE(mem_names); i++) { res = platform_get_resource_byname(pdev, IORESOURCE_MEM, mem_names[i]); wkupm3->mem[i].cpu_addr = devm_ioremap_resource(dev, res); if (IS_ERR(wkupm3->mem[i].cpu_addr)) { dev_err(&pdev->dev, "devm_ioremap_resource failed for resource %d\n", i); ret = PTR_ERR(wkupm3->mem[i].cpu_addr); goto err; } wkupm3->mem[i].bus_addr = res->start; wkupm3->mem[i].size = resource_size(res); addrp = of_get_address(dev->of_node, i, &size, NULL); /* * The wkupm3 has umem at address 0 in its view, so the device * addresses for each memory region is computed as a relative * offset of the bus address for umem, and therefore needs to be * processed first. */ if (!strcmp(mem_names[i], "umem")) l4_offset = be32_to_cpu(*addrp); wkupm3->mem[i].dev_addr = be32_to_cpu(*addrp) - l4_offset; } dev_set_drvdata(dev, rproc); ret = rproc_add(rproc); if (ret) { dev_err(dev, "rproc_add failed\n"); goto err_put_rproc; } return 0; err_put_rproc: rproc_free(rproc); err: pm_runtime_put_noidle(dev); pm_runtime_disable(dev); return ret; }
/** * of_device_make_bus_id - Use the device node data to assign a unique name * @dev: pointer to device structure that is linked to a device tree node * * This routine will first try using either the dcr-reg or the reg property * value to derive a unique name. As a last resort it will use the node * name followed by a unique number. */ static void of_device_make_bus_id(struct device_d *dev) { static int bus_no_reg_magic; struct device_node *np = dev->device_node; const __be32 *reg, *addrp; u64 addr; char *name, *at; name = xstrdup(np->name); at = strchr(name, '@'); if (at) *at = '\0'; #ifdef CONFIG_PPC_DCR /* * If it's a DCR based device, use 'd' for native DCRs * and 'D' for MMIO DCRs. */ reg = of_get_property(np, "dcr-reg", NULL); if (reg) { #ifdef CONFIG_PPC_DCR_NATIVE snprintf(dev->name, MAX_DRIVER_NAME, "d%x.%s", *reg, name); #else /* CONFIG_PPC_DCR_NATIVE */ u64 addr = of_translate_dcr_address(np, *reg, NULL); if (addr != OF_BAD_ADDR) { snprintf(dev->name, MAX_DRIVER_NAME, "D%llx.%s", (unsigned long long)addr, name); free(name); return; } #endif /* !CONFIG_PPC_DCR_NATIVE */ } #endif /* CONFIG_PPC_DCR */ /* * For MMIO, get the physical address */ reg = of_get_property(np, "reg", NULL); if (reg) { if (of_can_translate_address(np)) { addr = of_translate_address(np, reg); } else { addrp = of_get_address(np, 0, NULL, NULL); if (addrp) addr = of_read_number(addrp, 1); else addr = OF_BAD_ADDR; } if (addr != OF_BAD_ADDR) { snprintf(dev->name, MAX_DRIVER_NAME, "%llx.%s", (unsigned long long)addr, name); free(name); return; } } /* * No BusID, use the node name and add a globally incremented counter */ snprintf(dev->name, MAX_DRIVER_NAME, "%s.%d", name, bus_no_reg_magic++); free(name); }
static int bcm2835_i2s_probe(struct platform_device *pdev) { struct bcm2835_i2s_dev *dev; int ret; struct resource *mem; void __iomem *base; const __be32 *addr; dma_addr_t dma_base; dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); if (!dev) return -ENOMEM; /* get the clock */ dev->clk_prepared = false; dev->clk = devm_clk_get(&pdev->dev, NULL); if (IS_ERR(dev->clk)) { dev_err(&pdev->dev, "could not get clk: %ld\n", PTR_ERR(dev->clk)); return PTR_ERR(dev->clk); } /* Request ioarea */ mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); base = devm_ioremap_resource(&pdev->dev, mem); if (IS_ERR(base)) return PTR_ERR(base); dev->i2s_regmap = devm_regmap_init_mmio(&pdev->dev, base, &bcm2835_regmap_config); if (IS_ERR(dev->i2s_regmap)) return PTR_ERR(dev->i2s_regmap); /* Set the DMA address - we have to parse DT ourselves */ addr = of_get_address(pdev->dev.of_node, 0, NULL, NULL); if (!addr) { dev_err(&pdev->dev, "could not get DMA-register address\n"); return -EINVAL; } dma_base = be32_to_cpup(addr); dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].addr = dma_base + BCM2835_I2S_FIFO_A_REG; dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].addr = dma_base + BCM2835_I2S_FIFO_A_REG; /* Set the bus width */ dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; /* Set burst */ dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].maxburst = 2; dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].maxburst = 2; /* * Set the PACK flag to enable S16_LE support (2 S16_LE values * packed into 32-bit transfers). */ dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].flags = SND_DMAENGINE_PCM_DAI_FLAG_PACK; dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].flags = SND_DMAENGINE_PCM_DAI_FLAG_PACK; /* BCLK ratio - use default */ dev->bclk_ratio = 0; /* Store the pdev */ dev->dev = &pdev->dev; dev_set_drvdata(&pdev->dev, dev); ret = devm_snd_soc_register_component(&pdev->dev, &bcm2835_i2s_component, &bcm2835_i2s_dai, 1); if (ret) { dev_err(&pdev->dev, "Could not register DAI: %d\n", ret); return ret; } ret = devm_snd_dmaengine_pcm_register(&pdev->dev, NULL, 0); if (ret) { dev_err(&pdev->dev, "Could not register PCM: %d\n", ret); return ret; } return 0; }
static void __init offb_init_nodriver(struct device_node *dp, int no_real_node) { unsigned int len; int i, width = 640, height = 480, depth = 8, pitch = 640; unsigned int flags, rsize, addr_prop = 0; unsigned long max_size = 0; u64 rstart, address = OF_BAD_ADDR; const u32 *pp, *addrp, *up; u64 asize; int foreign_endian = 0; #ifdef __BIG_ENDIAN if (of_get_property(dp, "little-endian", NULL)) foreign_endian = FBINFO_FOREIGN_ENDIAN; #else if (of_get_property(dp, "big-endian", NULL)) foreign_endian = FBINFO_FOREIGN_ENDIAN; #endif pp = of_get_property(dp, "linux,bootx-depth", &len); if (pp == NULL) pp = of_get_property(dp, "depth", &len); if (pp && len == sizeof(u32)) depth = *pp; pp = of_get_property(dp, "linux,bootx-width", &len); if (pp == NULL) pp = of_get_property(dp, "width", &len); if (pp && len == sizeof(u32)) width = *pp; pp = of_get_property(dp, "linux,bootx-height", &len); if (pp == NULL) pp = of_get_property(dp, "height", &len); if (pp && len == sizeof(u32)) height = *pp; pp = of_get_property(dp, "linux,bootx-linebytes", &len); if (pp == NULL) pp = of_get_property(dp, "linebytes", &len); if (pp && len == sizeof(u32) && (*pp != 0xffffffffu)) pitch = *pp; else pitch = width * ((depth + 7) / 8); rsize = (unsigned long)pitch * (unsigned long)height; up = of_get_property(dp, "linux,bootx-addr", &len); if (up == NULL) up = of_get_property(dp, "address", &len); if (up && len == sizeof(u32)) addr_prop = *up; if (no_real_node) goto skip_addr; for (i = 0; (addrp = of_get_address(dp, i, &asize, &flags)) != NULL; i++) { int match_addrp = 0; if (!(flags & IORESOURCE_MEM)) continue; if (asize < rsize) continue; rstart = of_translate_address(dp, addrp); if (rstart == OF_BAD_ADDR) continue; if (addr_prop && (rstart <= addr_prop) && ((rstart + asize) >= (addr_prop + rsize))) match_addrp = 1; if (match_addrp) { address = addr_prop; break; } if (rsize > max_size) { max_size = rsize; address = OF_BAD_ADDR; } if (address == OF_BAD_ADDR) address = rstart; } skip_addr: if (address == OF_BAD_ADDR && addr_prop) address = (u64)addr_prop; if (address != OF_BAD_ADDR) { if (strcmp(dp->name, "valkyrie") == 0) address += 0x1000; offb_init_fb(no_real_node ? "bootx" : dp->name, no_real_node ? "display" : dp->full_name, width, height, depth, pitch, address, foreign_endian, no_real_node ? NULL : dp); } }
int bcom_sram_init(struct device_node *sram_node, char *owner) { int rv; const u32 *regaddr_p; u64 regaddr64, size64; unsigned int psize; /* Create our state struct */ if (bcom_sram) { printk(KERN_ERR "%s: bcom_sram_init: " "Already initialized !\n", owner); return -EBUSY; } bcom_sram = kmalloc(sizeof(struct bcom_sram), GFP_KERNEL); if (!bcom_sram) { printk(KERN_ERR "%s: bcom_sram_init: " "Couldn't allocate internal state !\n", owner); return -ENOMEM; } /* Get address and size of the sram */ regaddr_p = of_get_address(sram_node, 0, &size64, NULL); if (!regaddr_p) { printk(KERN_ERR "%s: bcom_sram_init: " "Invalid device node !\n", owner); rv = -EINVAL; goto error_free; } regaddr64 = of_translate_address(sram_node, regaddr_p); bcom_sram->base_phys = (phys_addr_t) regaddr64; bcom_sram->size = (unsigned int) size64; /* Request region */ if (!request_mem_region(bcom_sram->base_phys, bcom_sram->size, owner)) { printk(KERN_ERR "%s: bcom_sram_init: " "Couldn't request region !\n", owner); rv = -EBUSY; goto error_free; } /* Map SRAM */ /* sram is not really __iomem */ bcom_sram->base_virt = (void*) ioremap(bcom_sram->base_phys, bcom_sram->size); if (!bcom_sram->base_virt) { printk(KERN_ERR "%s: bcom_sram_init: " "Map error SRAM zone 0x%08lx (0x%0x)!\n", owner, (long)bcom_sram->base_phys, bcom_sram->size ); rv = -ENOMEM; goto error_release; } /* Create an rheap (defaults to 32 bits word alignment) */ bcom_sram->rh = rh_create(4); /* Attach the free zones */ #if 0 /* Currently disabled ... for future use only */ reg_addr_p = of_get_property(sram_node, "available", &psize); #else regaddr_p = NULL; psize = 0; #endif if (!regaddr_p || !psize) { /* Attach the whole zone */ rh_attach_region(bcom_sram->rh, 0, bcom_sram->size); } else { /* Attach each zone independently */ while (psize >= 2 * sizeof(u32)) { phys_addr_t zbase = of_translate_address(sram_node, regaddr_p); rh_attach_region(bcom_sram->rh, zbase - bcom_sram->base_phys, regaddr_p[1]); regaddr_p += 2; psize -= 2 * sizeof(u32); } } /* Init our spinlock */ spin_lock_init(&bcom_sram->lock); return 0; error_release: release_mem_region(bcom_sram->base_phys, bcom_sram->size); error_free: kfree(bcom_sram); bcom_sram = NULL; return rv; }