void __init of_at91sam9260_clk_slow_setup(struct device_node *np, struct at91_pmc *pmc) { struct clk *clk; const char *parent_names[2]; int num_parents; const char *name = np->name; int i; num_parents = of_count_phandle_with_args(np, "clocks", "#clock-cells"); if (num_parents != 2) return; for (i = 0; i < num_parents; ++i) { parent_names[i] = of_clk_get_parent_name(np, i); if (!parent_names[i]) return; } of_property_read_string(np, "clock-output-names", &name); clk = at91_clk_register_sam9260_slow(pmc, name, parent_names, num_parents); if (IS_ERR(clk)) return; of_clk_add_provider(np, of_clk_src_simple_get, clk); }
void __init of_at91sam9x5_clk_main_setup(struct device_node *np, struct at91_pmc *pmc) { struct clk *clk; const char *parent_names[2]; int num_parents; unsigned int irq; const char *name = np->name; int i; num_parents = of_count_phandle_with_args(np, "clocks", "#clock-cells"); if (num_parents <= 0 || num_parents > 2) return; for (i = 0; i < num_parents; ++i) { parent_names[i] = of_clk_get_parent_name(np, i); if (!parent_names[i]) return; } of_property_read_string(np, "clock-output-names", &name); irq = irq_of_parse_and_map(np, 0); if (!irq) return; clk = at91_clk_register_sam9x5_main(pmc, irq, name, parent_names, num_parents); if (IS_ERR(clk)) return; of_clk_add_provider(np, of_clk_src_simple_get, clk); }
static int __init ar79_cpu_intc_of_init( struct device_node *node, struct device_node *parent) { int err, i, count; /* Fill the irq_wb_chan table */ count = of_count_phandle_with_args( node, "qca,ddr-wb-channels", "#qca,ddr-wb-channel-cells"); for (i = 0; i < count; i++) { struct of_phandle_args args; u32 irq = i; of_property_read_u32_index( node, "qca,ddr-wb-channel-interrupts", i, &irq); if (irq >= ARRAY_SIZE(irq_wb_chan)) continue; err = of_parse_phandle_with_args( node, "qca,ddr-wb-channels", "#qca,ddr-wb-channel-cells", i, &args); if (err) return err; irq_wb_chan[irq] = args.args[0]; pr_info("IRQ: Set flush channel of IRQ%d to %d\n", irq, args.args[0]); } return mips_cpu_irq_of_init(node, parent); }
static void __init of_ti_clockdomain_setup(struct device_node *node) { struct clk *clk; struct clk_hw *clk_hw; const char *clkdm_name = node->name; int i; int num_clks; num_clks = of_count_phandle_with_args(node, "clocks", "#clock-cells"); for (i = 0; i < num_clks; i++) { clk = of_clk_get(node, i); if (IS_ERR(clk)) { pr_err("%s: Failed get %s' clock nr %d (%ld)\n", __func__, node->full_name, i, PTR_ERR(clk)); continue; } if (__clk_get_flags(clk) & CLK_IS_BASIC) { pr_warn("can't setup clkdm for basic clk %s\n", __clk_get_name(clk)); continue; } clk_hw = __clk_get_hw(clk); to_clk_hw_omap(clk_hw)->clkdm_name = clkdm_name; omap2_init_clk_clkdm(clk_hw); } }
static void __init sp804_of_init(struct device_node *np) { static bool initialized = false; void __iomem *base; int irq; u32 irq_num = 0; struct clk *clk1, *clk2; const char *name = of_get_property(np, "compatible", NULL); base = of_iomap(np, 0); if (WARN_ON(!base)) return; /* Ensure timers are disabled */ writel(0, base + TIMER_CTRL); writel(0, base + TIMER_2_BASE + TIMER_CTRL); if (initialized || !of_device_is_available(np)) goto err; clk1 = of_clk_get(np, 0); if (IS_ERR(clk1)) clk1 = NULL; /* Get the 2nd clock if the timer has 3 timer clocks */ if (of_count_phandle_with_args(np, "clocks", "#clock-cells") == 3) { clk2 = of_clk_get(np, 1); if (IS_ERR(clk2)) { pr_err("sp804: %s clock not found: %d\n", np->name, (int)PTR_ERR(clk2)); clk2 = NULL; } } else clk2 = clk1; irq = irq_of_parse_and_map(np, 0); if (irq <= 0) goto err; of_property_read_u32(np, "arm,sp804-has-irq", &irq_num); if (irq_num == 2) { __sp804_clockevents_init(base + TIMER_2_BASE, irq, clk2, name); __sp804_clocksource_and_sched_clock_init(base, name, clk1, 1); } else { __sp804_clockevents_init(base, irq, clk1 , name); __sp804_clocksource_and_sched_clock_init(base + TIMER_2_BASE, name, clk2, 1); } initialized = true; return; err: iounmap(base); }
static void __init of_at91_clk_prog_setup(struct device_node *np, struct at91_pmc *pmc, const struct clk_programmable_layout *layout) { int num; u32 id; int i; unsigned int irq; struct clk *clk; int num_parents; const char *parent_names[PROG_SOURCE_MAX]; const char *name; struct device_node *progclknp; num_parents = of_count_phandle_with_args(np, "clocks", "#clock-cells"); if (num_parents <= 0 || num_parents > PROG_SOURCE_MAX) return; for (i = 0; i < num_parents; ++i) { parent_names[i] = of_clk_get_parent_name(np, i); if (!parent_names[i]) return; } num = of_get_child_count(np); if (!num || num > (PROG_ID_MAX + 1)) return; for_each_child_of_node(np, progclknp) { if (of_property_read_u32(progclknp, "reg", &id)) continue; if (of_property_read_string(np, "clock-output-names", &name)) name = progclknp->name; irq = irq_of_parse_and_map(progclknp, 0); if (!irq) continue; clk = at91_clk_register_programmable(pmc, irq, name, parent_names, num_parents, id, layout); if (IS_ERR(clk)) continue; of_clk_add_provider(progclknp, of_clk_src_simple_get, clk); } }
int axidma_of_num_channels(struct platform_device *pdev) { int num_dmas, num_dma_names; struct device_node *driver_node; // Get the device tree node for the driver driver_node = pdev->dev.of_node; // Check that the device tree node has the 'dmas' and 'dma-names' properties if (of_find_property(driver_node, "dma-names", NULL) == NULL) { axidma_node_err(driver_node, "Property 'dma-names' is missing.\n"); return -EINVAL; } else if (of_find_property(driver_node, "dmas", NULL) == NULL) { axidma_node_err(driver_node, "Property 'dmas' is missing.\n"); return -EINVAL; } // Get the length of the properties, and make sure they are not empty num_dma_names = of_property_count_strings(driver_node, "dma-names"); if (num_dma_names < 0) { axidma_node_err(driver_node, "Unable to get the 'dma-names' property " "length.\n"); return -EINVAL; } else if (num_dma_names == 0) { axidma_node_err(driver_node, "'dma-names' property is empty.\n"); return -EINVAL; } num_dmas = of_count_phandle_with_args(driver_node, "dmas", "#dma-cells"); if (num_dmas < 0) { axidma_node_err(driver_node, "Unable to get the 'dmas' property " "length.\n"); return -EINVAL; } else if (num_dmas == 0) { axidma_node_err(driver_node, "'dmas' property is empty.\n"); return -EINVAL; } // Check that the number of entries in each property matches if (num_dma_names != num_dmas) { axidma_node_err(driver_node, "Length of 'dma-names' and 'dmas' " "properties differ.\n"); return -EINVAL; } return num_dma_names; }
static const char ** __init flexgen_get_parents(struct device_node *np, int *num_parents) { const char **parents; int nparents, i; nparents = of_count_phandle_with_args(np, "clocks", "#clock-cells"); if (WARN_ON(nparents <= 0)) return NULL; parents = kcalloc(nparents, sizeof(const char *), GFP_KERNEL); if (!parents) return NULL; for (i = 0; i < nparents; i++) parents[i] = of_clk_get_parent_name(np, i); *num_parents = nparents; return parents; }
static const char ** __init clkgen_mux_get_parents(struct device_node *np, int *num_parents) { const char **parents; int nparents, i; nparents = of_count_phandle_with_args(np, "clocks", "#clock-cells"); if (WARN_ON(nparents <= 0)) return ERR_PTR(-EINVAL); parents = kzalloc(nparents * sizeof(const char *), GFP_KERNEL); if (!parents) return ERR_PTR(-ENOMEM); for (i = 0; i < nparents; i++) parents[i] = of_clk_get_parent_name(np, i); *num_parents = nparents; return parents; }
static int xhci_mtk_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct device_node *node = dev->of_node; struct xhci_hcd_mtk *mtk; const struct hc_driver *driver; struct xhci_hcd *xhci; struct resource *res; struct usb_hcd *hcd; struct phy *phy; int phy_num; int ret = -ENODEV; int irq; if (usb_disabled()) return -ENODEV; driver = &xhci_mtk_hc_driver; mtk = devm_kzalloc(dev, sizeof(*mtk), GFP_KERNEL); if (!mtk) return -ENOMEM; mtk->dev = dev; mtk->vbus = devm_regulator_get(dev, "vbus"); if (IS_ERR(mtk->vbus)) { dev_err(dev, "fail to get vbus\n"); return PTR_ERR(mtk->vbus); } mtk->vusb33 = devm_regulator_get(dev, "vusb33"); if (IS_ERR(mtk->vusb33)) { dev_err(dev, "fail to get vusb33\n"); return PTR_ERR(mtk->vusb33); } mtk->sys_clk = devm_clk_get(dev, "sys_ck"); if (IS_ERR(mtk->sys_clk)) { dev_err(dev, "fail to get sys_ck\n"); return PTR_ERR(mtk->sys_clk); } /* * reference clock is usually a "fixed-clock", make it optional * for backward compatibility and ignore the error if it does * not exist. */ mtk->ref_clk = devm_clk_get(dev, "ref_ck"); if (IS_ERR(mtk->ref_clk)) { if (PTR_ERR(mtk->ref_clk) == -EPROBE_DEFER) return -EPROBE_DEFER; mtk->ref_clk = NULL; } mtk->lpm_support = of_property_read_bool(node, "usb3-lpm-capable"); ret = usb_wakeup_of_property_parse(mtk, node); if (ret) return ret; mtk->num_phys = of_count_phandle_with_args(node, "phys", "#phy-cells"); if (mtk->num_phys > 0) { mtk->phys = devm_kcalloc(dev, mtk->num_phys, sizeof(*mtk->phys), GFP_KERNEL); if (!mtk->phys) return -ENOMEM; } else { mtk->num_phys = 0; } pm_runtime_enable(dev); pm_runtime_get_sync(dev); device_enable_async_suspend(dev); ret = xhci_mtk_ldos_enable(mtk); if (ret) goto disable_pm; ret = xhci_mtk_clks_enable(mtk); if (ret) goto disable_ldos; irq = platform_get_irq(pdev, 0); if (irq < 0) { ret = irq; goto disable_clk; } /* Initialize dma_mask and coherent_dma_mask to 32-bits */ ret = dma_set_coherent_mask(dev, DMA_BIT_MASK(32)); if (ret) goto disable_clk; if (!dev->dma_mask) dev->dma_mask = &dev->coherent_dma_mask; else dma_set_mask(dev, DMA_BIT_MASK(32)); hcd = usb_create_hcd(driver, dev, dev_name(dev)); if (!hcd) { ret = -ENOMEM; goto disable_clk; } /* * USB 2.0 roothub is stored in the platform_device. * Swap it with mtk HCD. */ mtk->hcd = platform_get_drvdata(pdev); platform_set_drvdata(pdev, mtk); res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mac"); hcd->regs = devm_ioremap_resource(dev, res); if (IS_ERR(hcd->regs)) { ret = PTR_ERR(hcd->regs); goto put_usb2_hcd; } hcd->rsrc_start = res->start; hcd->rsrc_len = resource_size(res); res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ippc"); if (res) { /* ippc register is optional */ mtk->ippc_regs = devm_ioremap_resource(dev, res); if (IS_ERR(mtk->ippc_regs)) { ret = PTR_ERR(mtk->ippc_regs); goto put_usb2_hcd; } mtk->has_ippc = true; } else { mtk->has_ippc = false; } for (phy_num = 0; phy_num < mtk->num_phys; phy_num++) { phy = devm_of_phy_get_by_index(dev, node, phy_num); if (IS_ERR(phy)) { ret = PTR_ERR(phy); goto put_usb2_hcd; } mtk->phys[phy_num] = phy; } ret = xhci_mtk_phy_init(mtk); if (ret) goto put_usb2_hcd; ret = xhci_mtk_phy_power_on(mtk); if (ret) goto exit_phys; device_init_wakeup(dev, true); xhci = hcd_to_xhci(hcd); xhci->main_hcd = hcd; xhci->shared_hcd = usb_create_shared_hcd(driver, dev, dev_name(dev), hcd); if (!xhci->shared_hcd) { ret = -ENOMEM; goto power_off_phys; } ret = usb_add_hcd(hcd, irq, IRQF_SHARED); if (ret) goto put_usb3_hcd; if (HCC_MAX_PSA(xhci->hcc_params) >= 4) xhci->shared_hcd->can_do_streams = 1; ret = usb_add_hcd(xhci->shared_hcd, irq, IRQF_SHARED); if (ret) goto dealloc_usb2_hcd; return 0; dealloc_usb2_hcd: usb_remove_hcd(hcd); put_usb3_hcd: xhci_mtk_sch_exit(mtk); usb_put_hcd(xhci->shared_hcd); power_off_phys: xhci_mtk_phy_power_off(mtk); device_init_wakeup(dev, false); exit_phys: xhci_mtk_phy_exit(mtk); put_usb2_hcd: usb_put_hcd(hcd); disable_clk: xhci_mtk_clks_disable(mtk); disable_ldos: xhci_mtk_ldos_disable(mtk); disable_pm: pm_runtime_put_sync(dev); pm_runtime_disable(dev); return ret; }
static int dwc3_of_simple_probe(struct platform_device *pdev) { struct dwc3_of_simple *simple; struct device *dev = &pdev->dev; struct device_node *np = dev->of_node; int ret; int i; bool shared_resets = false; simple = devm_kzalloc(dev, sizeof(*simple), GFP_KERNEL); if (!simple) return -ENOMEM; platform_set_drvdata(pdev, simple); simple->dev = dev; /* * Some controllers need to toggle the usb3-otg reset before trying to * initialize the PHY, otherwise the PHY times out. */ if (of_device_is_compatible(np, "rockchip,rk3399-dwc3")) simple->need_reset = true; if (of_device_is_compatible(np, "amlogic,meson-axg-dwc3") || of_device_is_compatible(np, "amlogic,meson-gxl-dwc3")) { shared_resets = true; simple->pulse_resets = true; } simple->resets = of_reset_control_array_get(np, shared_resets, true); if (IS_ERR(simple->resets)) { ret = PTR_ERR(simple->resets); dev_err(dev, "failed to get device resets, err=%d\n", ret); return ret; } if (simple->pulse_resets) { ret = reset_control_reset(simple->resets); if (ret) goto err_resetc_put; } else { ret = reset_control_deassert(simple->resets); if (ret) goto err_resetc_put; } ret = dwc3_of_simple_clk_init(simple, of_count_phandle_with_args(np, "clocks", "#clock-cells")); if (ret) goto err_resetc_assert; ret = of_platform_populate(np, NULL, NULL, dev); if (ret) { for (i = 0; i < simple->num_clocks; i++) { clk_disable_unprepare(simple->clks[i]); clk_put(simple->clks[i]); } goto err_resetc_assert; } pm_runtime_set_active(dev); pm_runtime_enable(dev); pm_runtime_get_sync(dev); return 0; err_resetc_assert: if (!simple->pulse_resets) reset_control_assert(simple->resets); err_resetc_put: reset_control_put(simple->resets); return ret; }
static int rockchip_pm_add_one_domain(struct rockchip_pmu *pmu, struct device_node *node) { const struct rockchip_domain_info *pd_info; struct rockchip_pm_domain *pd; struct device_node *qos_node; int i, j; u32 id; int error; error = of_property_read_u32(node, "reg", &id); if (error) { dev_err(pmu->dev, "%s: failed to retrieve domain id (reg): %d\n", node->name, error); return -EINVAL; } if (id >= pmu->info->num_domains) { dev_err(pmu->dev, "%s: invalid domain id %d\n", node->name, id); return -EINVAL; } pd_info = &pmu->info->domain_info[id]; if (!pd_info) { dev_err(pmu->dev, "%s: undefined domain id %d\n", node->name, id); return -EINVAL; } pd = devm_kzalloc(pmu->dev, sizeof(*pd), GFP_KERNEL); if (!pd) return -ENOMEM; pd->info = pd_info; pd->pmu = pmu; pd->num_clks = of_clk_get_parent_count(node); if (pd->num_clks > 0) { pd->clks = devm_kcalloc(pmu->dev, pd->num_clks, sizeof(*pd->clks), GFP_KERNEL); if (!pd->clks) return -ENOMEM; } else { dev_dbg(pmu->dev, "%s: doesn't have clocks: %d\n", node->name, pd->num_clks); pd->num_clks = 0; } for (i = 0; i < pd->num_clks; i++) { pd->clks[i].clk = of_clk_get(node, i); if (IS_ERR(pd->clks[i].clk)) { error = PTR_ERR(pd->clks[i].clk); dev_err(pmu->dev, "%s: failed to get clk at index %d: %d\n", node->name, i, error); return error; } } error = clk_bulk_prepare(pd->num_clks, pd->clks); if (error) goto err_put_clocks; pd->num_qos = of_count_phandle_with_args(node, "pm_qos", NULL); if (pd->num_qos > 0) { pd->qos_regmap = devm_kcalloc(pmu->dev, pd->num_qos, sizeof(*pd->qos_regmap), GFP_KERNEL); if (!pd->qos_regmap) { error = -ENOMEM; goto err_unprepare_clocks; } for (j = 0; j < MAX_QOS_REGS_NUM; j++) { pd->qos_save_regs[j] = devm_kcalloc(pmu->dev, pd->num_qos, sizeof(u32), GFP_KERNEL); if (!pd->qos_save_regs[j]) { error = -ENOMEM; goto err_unprepare_clocks; } } for (j = 0; j < pd->num_qos; j++) { qos_node = of_parse_phandle(node, "pm_qos", j); if (!qos_node) { error = -ENODEV; goto err_unprepare_clocks; } pd->qos_regmap[j] = syscon_node_to_regmap(qos_node); if (IS_ERR(pd->qos_regmap[j])) { error = -ENODEV; of_node_put(qos_node); goto err_unprepare_clocks; } of_node_put(qos_node); } } error = rockchip_pd_power(pd, true); if (error) { dev_err(pmu->dev, "failed to power on domain '%s': %d\n", node->name, error); goto err_unprepare_clocks; } pd->genpd.name = node->name; pd->genpd.power_off = rockchip_pd_power_off; pd->genpd.power_on = rockchip_pd_power_on; pd->genpd.attach_dev = rockchip_pd_attach_dev; pd->genpd.detach_dev = rockchip_pd_detach_dev; pd->genpd.flags = GENPD_FLAG_PM_CLK; if (pd_info->active_wakeup) pd->genpd.flags |= GENPD_FLAG_ACTIVE_WAKEUP; pm_genpd_init(&pd->genpd, NULL, false); pmu->genpd_data.domains[id] = &pd->genpd; return 0; err_unprepare_clocks: clk_bulk_unprepare(pd->num_clks, pd->clks); err_put_clocks: clk_bulk_put(pd->num_clks, pd->clks); return error; }
static int ohci_platform_probe(struct platform_device *dev) { struct usb_hcd *hcd; struct resource *res_mem; struct usb_ohci_pdata *pdata = dev_get_platdata(&dev->dev); struct ohci_platform_priv *priv; struct ohci_hcd *ohci; int err, irq, phy_num, clk = 0, rst = 0; if (usb_disabled()) return -ENODEV; /* * Use reasonable defaults so platforms don't have to provide these * with DT probing on ARM. */ if (!pdata) pdata = &ohci_platform_defaults; err = dma_coerce_mask_and_coherent(&dev->dev, DMA_BIT_MASK(32)); if (err) return err; irq = platform_get_irq(dev, 0); if (irq < 0) { dev_err(&dev->dev, "no irq provided"); return irq; } hcd = usb_create_hcd(&ohci_platform_hc_driver, &dev->dev, dev_name(&dev->dev)); if (!hcd) return -ENOMEM; platform_set_drvdata(dev, hcd); dev->dev.platform_data = pdata; priv = hcd_to_ohci_priv(hcd); ohci = hcd_to_ohci(hcd); if (pdata == &ohci_platform_defaults && dev->dev.of_node) { if (of_property_read_bool(dev->dev.of_node, "big-endian-regs")) ohci->flags |= OHCI_QUIRK_BE_MMIO; if (of_property_read_bool(dev->dev.of_node, "big-endian-desc")) ohci->flags |= OHCI_QUIRK_BE_DESC; if (of_property_read_bool(dev->dev.of_node, "big-endian")) ohci->flags |= OHCI_QUIRK_BE_MMIO | OHCI_QUIRK_BE_DESC; if (of_property_read_bool(dev->dev.of_node, "no-big-frame-no")) ohci->flags |= OHCI_QUIRK_FRAME_NO; of_property_read_u32(dev->dev.of_node, "num-ports", &ohci->num_ports); priv->num_phys = of_count_phandle_with_args(dev->dev.of_node, "phys", "#phy-cells"); if (priv->num_phys > 0) { priv->phys = devm_kcalloc(&dev->dev, priv->num_phys, sizeof(struct phy *), GFP_KERNEL); if (!priv->phys) return -ENOMEM; } else priv->num_phys = 0; for (phy_num = 0; phy_num < priv->num_phys; phy_num++) { priv->phys[phy_num] = devm_of_phy_get_by_index( &dev->dev, dev->dev.of_node, phy_num); if (IS_ERR(priv->phys[phy_num])) { err = PTR_ERR(priv->phys[phy_num]); goto err_put_hcd; } } for (clk = 0; clk < OHCI_MAX_CLKS; clk++) { priv->clks[clk] = of_clk_get(dev->dev.of_node, clk); if (IS_ERR(priv->clks[clk])) { err = PTR_ERR(priv->clks[clk]); if (err == -EPROBE_DEFER) goto err_put_clks; priv->clks[clk] = NULL; break; } } for (rst = 0; rst < OHCI_MAX_RESETS; rst++) { priv->resets[rst] = devm_reset_control_get_shared_by_index( &dev->dev, rst); if (IS_ERR(priv->resets[rst])) { err = PTR_ERR(priv->resets[rst]); if (err == -EPROBE_DEFER) goto err_reset; priv->resets[rst] = NULL; break; } err = reset_control_deassert(priv->resets[rst]); if (err) goto err_reset; } } if (pdata->big_endian_desc) ohci->flags |= OHCI_QUIRK_BE_DESC; if (pdata->big_endian_mmio) ohci->flags |= OHCI_QUIRK_BE_MMIO; if (pdata->no_big_frame_no) ohci->flags |= OHCI_QUIRK_FRAME_NO; if (pdata->num_ports) ohci->num_ports = pdata->num_ports; #ifndef CONFIG_USB_OHCI_BIG_ENDIAN_MMIO if (ohci->flags & OHCI_QUIRK_BE_MMIO) { dev_err(&dev->dev, "Error: CONFIG_USB_OHCI_BIG_ENDIAN_MMIO not set\n"); err = -EINVAL; goto err_reset; } #endif #ifndef CONFIG_USB_OHCI_BIG_ENDIAN_DESC if (ohci->flags & OHCI_QUIRK_BE_DESC) { dev_err(&dev->dev, "Error: CONFIG_USB_OHCI_BIG_ENDIAN_DESC not set\n"); err = -EINVAL; goto err_reset; } #endif if (pdata->power_on) { err = pdata->power_on(dev); if (err < 0) goto err_reset; } res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0); hcd->regs = devm_ioremap_resource(&dev->dev, res_mem); if (IS_ERR(hcd->regs)) { err = PTR_ERR(hcd->regs); goto err_power; } hcd->rsrc_start = res_mem->start; hcd->rsrc_len = resource_size(res_mem); err = usb_add_hcd(hcd, irq, IRQF_SHARED); if (err) goto err_power; device_wakeup_enable(hcd->self.controller); platform_set_drvdata(dev, hcd); return err; err_power: if (pdata->power_off) pdata->power_off(dev); err_reset: while (--rst >= 0) reset_control_assert(priv->resets[rst]); err_put_clks: while (--clk >= 0) clk_put(priv->clks[clk]); err_put_hcd: if (pdata == &ohci_platform_defaults) dev->dev.platform_data = NULL; usb_put_hcd(hcd); return err; }
static int tm2_probe(struct platform_device *pdev) { struct device_node *cpu_dai_node[2] = {}; struct device_node *codec_dai_node[2] = {}; const char *cells_name = NULL; struct device *dev = &pdev->dev; struct snd_soc_card *card = &tm2_card; struct tm2_machine_priv *priv; struct of_phandle_args args; struct snd_soc_dai_link *dai_link; int num_codecs, ret, i; priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); if (!priv) return -ENOMEM; snd_soc_card_set_drvdata(card, priv); card->dev = dev; priv->gpio_mic_bias = devm_gpiod_get(dev, "mic-bias", GPIOD_OUT_HIGH); if (IS_ERR(priv->gpio_mic_bias)) { dev_err(dev, "Failed to get mic bias gpio\n"); return PTR_ERR(priv->gpio_mic_bias); } ret = snd_soc_of_parse_card_name(card, "model"); if (ret < 0) { dev_err(dev, "Card name is not specified\n"); return ret; } ret = snd_soc_of_parse_audio_routing(card, "samsung,audio-routing"); if (ret < 0) { dev_err(dev, "Audio routing is not specified or invalid\n"); return ret; } card->aux_dev[0].codec_of_node = of_parse_phandle(dev->of_node, "audio-amplifier", 0); if (!card->aux_dev[0].codec_of_node) { dev_err(dev, "audio-amplifier property invalid or missing\n"); return -EINVAL; } num_codecs = of_count_phandle_with_args(dev->of_node, "audio-codec", NULL); /* Skip the HDMI link if not specified in DT */ if (num_codecs > 1) { card->num_links = ARRAY_SIZE(tm2_dai_links); cells_name = "#sound-dai-cells"; } else { card->num_links = ARRAY_SIZE(tm2_dai_links) - 1; } for (i = 0; i < num_codecs; i++) { struct of_phandle_args args; ret = of_parse_phandle_with_args(dev->of_node, "i2s-controller", cells_name, i, &args); if (!args.np) { dev_err(dev, "i2s-controller property parse error: %d\n", i); ret = -EINVAL; goto dai_node_put; } cpu_dai_node[i] = args.np; codec_dai_node[i] = of_parse_phandle(dev->of_node, "audio-codec", i); if (!codec_dai_node[i]) { dev_err(dev, "audio-codec property parse error\n"); ret = -EINVAL; goto dai_node_put; } } /* Initialize WM5110 - I2S and HDMI - I2S1 DAI links */ for_each_card_prelinks(card, i, dai_link) { unsigned int dai_index = 0; /* WM5110 */ dai_link->cpu_name = NULL; dai_link->platform_name = NULL; if (num_codecs > 1 && i == card->num_links - 1) dai_index = 1; /* HDMI */ dai_link->codec_of_node = codec_dai_node[dai_index]; dai_link->cpu_of_node = cpu_dai_node[dai_index]; dai_link->platform_of_node = cpu_dai_node[dai_index]; }
static int get_ssusb_rscs(struct platform_device *pdev, struct ssusb_mtk *ssusb) { struct device_node *node = pdev->dev.of_node; struct otg_switch_mtk *otg_sx = &ssusb->otg_switch; struct device *dev = &pdev->dev; struct regulator *vbus; struct resource *res; int i; int ret; ssusb->vusb33 = devm_regulator_get(&pdev->dev, "vusb33"); if (IS_ERR(ssusb->vusb33)) { dev_err(dev, "failed to get vusb33\n"); return PTR_ERR(ssusb->vusb33); } ssusb->sys_clk = devm_clk_get(dev, "sys_ck"); if (IS_ERR(ssusb->sys_clk)) { dev_err(dev, "failed to get sys clock\n"); return PTR_ERR(ssusb->sys_clk); } ssusb->ref_clk = get_optional_clk(dev, "ref_ck"); if (IS_ERR(ssusb->ref_clk)) return PTR_ERR(ssusb->ref_clk); ssusb->mcu_clk = get_optional_clk(dev, "mcu_ck"); if (IS_ERR(ssusb->mcu_clk)) return PTR_ERR(ssusb->mcu_clk); ssusb->dma_clk = get_optional_clk(dev, "dma_ck"); if (IS_ERR(ssusb->dma_clk)) return PTR_ERR(ssusb->dma_clk); ssusb->num_phys = of_count_phandle_with_args(node, "phys", "#phy-cells"); if (ssusb->num_phys > 0) { ssusb->phys = devm_kcalloc(dev, ssusb->num_phys, sizeof(*ssusb->phys), GFP_KERNEL); if (!ssusb->phys) return -ENOMEM; } else { ssusb->num_phys = 0; } for (i = 0; i < ssusb->num_phys; i++) { ssusb->phys[i] = devm_of_phy_get_by_index(dev, node, i); if (IS_ERR(ssusb->phys[i])) { dev_err(dev, "failed to get phy-%d\n", i); return PTR_ERR(ssusb->phys[i]); } } res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ippc"); ssusb->ippc_base = devm_ioremap_resource(dev, res); if (IS_ERR(ssusb->ippc_base)) return PTR_ERR(ssusb->ippc_base); ssusb->dr_mode = usb_get_dr_mode(dev); if (ssusb->dr_mode == USB_DR_MODE_UNKNOWN) ssusb->dr_mode = USB_DR_MODE_OTG; if (ssusb->dr_mode == USB_DR_MODE_PERIPHERAL) return 0; /* if host role is supported */ ret = ssusb_wakeup_of_property_parse(ssusb, node); if (ret) { dev_err(dev, "failed to parse uwk property\n"); return ret; } /* optional property, ignore the error if it does not exist */ of_property_read_u32(node, "mediatek,u3p-dis-msk", &ssusb->u3p_dis_msk); vbus = devm_regulator_get(&pdev->dev, "vbus"); if (IS_ERR(vbus)) { dev_err(dev, "failed to get vbus\n"); return PTR_ERR(vbus); } otg_sx->vbus = vbus; if (ssusb->dr_mode == USB_DR_MODE_HOST) return 0; /* if dual-role mode is supported */ otg_sx->is_u3_drd = of_property_read_bool(node, "mediatek,usb3-drd"); otg_sx->manual_drd_enabled = of_property_read_bool(node, "enable-manual-drd"); if (of_property_read_bool(node, "extcon")) { otg_sx->edev = extcon_get_edev_by_phandle(ssusb->dev, 0); if (IS_ERR(otg_sx->edev)) { dev_err(ssusb->dev, "couldn't get extcon device\n"); return PTR_ERR(otg_sx->edev); } } dev_info(dev, "dr_mode: %d, is_u3_dr: %d, u3p_dis_msk: %x, drd: %s\n", ssusb->dr_mode, otg_sx->is_u3_drd, ssusb->u3p_dis_msk, otg_sx->manual_drd_enabled ? "manual" : "auto"); return 0; }
static int rockchip_pm_add_one_domain(struct rockchip_pmu *pmu, struct device_node *node) { const struct rockchip_domain_info *pd_info; struct rockchip_pm_domain *pd; struct device_node *qos_node; struct clk *clk; int clk_cnt; int i, j; u32 id; int error; error = of_property_read_u32(node, "reg", &id); if (error) { dev_err(pmu->dev, "%s: failed to retrieve domain id (reg): %d\n", node->name, error); return -EINVAL; } if (id >= pmu->info->num_domains) { dev_err(pmu->dev, "%s: invalid domain id %d\n", node->name, id); return -EINVAL; } pd_info = &pmu->info->domain_info[id]; if (!pd_info) { dev_err(pmu->dev, "%s: undefined domain id %d\n", node->name, id); return -EINVAL; } clk_cnt = of_count_phandle_with_args(node, "clocks", "#clock-cells"); pd = devm_kzalloc(pmu->dev, sizeof(*pd) + clk_cnt * sizeof(pd->clks[0]), GFP_KERNEL); if (!pd) return -ENOMEM; pd->info = pd_info; pd->pmu = pmu; for (i = 0; i < clk_cnt; i++) { clk = of_clk_get(node, i); if (IS_ERR(clk)) { error = PTR_ERR(clk); dev_err(pmu->dev, "%s: failed to get clk at index %d: %d\n", node->name, i, error); goto err_out; } error = clk_prepare(clk); if (error) { dev_err(pmu->dev, "%s: failed to prepare clk %pC (index %d): %d\n", node->name, clk, i, error); clk_put(clk); goto err_out; } pd->clks[pd->num_clks++] = clk; dev_dbg(pmu->dev, "added clock '%pC' to domain '%s'\n", clk, node->name); } pd->num_qos = of_count_phandle_with_args(node, "pm_qos", NULL); if (pd->num_qos > 0) { pd->qos_regmap = devm_kcalloc(pmu->dev, pd->num_qos, sizeof(*pd->qos_regmap), GFP_KERNEL); if (!pd->qos_regmap) { error = -ENOMEM; goto err_out; } for (j = 0; j < MAX_QOS_REGS_NUM; j++) { pd->qos_save_regs[j] = devm_kcalloc(pmu->dev, pd->num_qos, sizeof(u32), GFP_KERNEL); if (!pd->qos_save_regs[j]) { error = -ENOMEM; goto err_out; } } for (j = 0; j < pd->num_qos; j++) { qos_node = of_parse_phandle(node, "pm_qos", j); if (!qos_node) { error = -ENODEV; goto err_out; } pd->qos_regmap[j] = syscon_node_to_regmap(qos_node); if (IS_ERR(pd->qos_regmap[j])) { error = -ENODEV; of_node_put(qos_node); goto err_out; } of_node_put(qos_node); } } error = rockchip_pd_power(pd, true); if (error) { dev_err(pmu->dev, "failed to power on domain '%s': %d\n", node->name, error); goto err_out; } pd->genpd.name = node->name; pd->genpd.power_off = rockchip_pd_power_off; pd->genpd.power_on = rockchip_pd_power_on; pd->genpd.attach_dev = rockchip_pd_attach_dev; pd->genpd.detach_dev = rockchip_pd_detach_dev; pd->genpd.flags = GENPD_FLAG_PM_CLK; pm_genpd_init(&pd->genpd, NULL, false); pmu->genpd_data.domains[id] = &pd->genpd; return 0; err_out: while (--i >= 0) { clk_unprepare(pd->clks[i]); clk_put(pd->clks[i]); } return error; }
static void __init of_selftest_parse_phandle_with_args(void) { struct device_node *np; struct of_phandle_args args; int i, rc; np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a"); if (!np) { pr_err("missing testcase data\n"); return; } rc = of_count_phandle_with_args(np, "phandle-list", "#phandle-cells"); selftest(rc == 7, "of_count_phandle_with_args() returned %i, expected 7\n", rc); for (i = 0; i < 8; i++) { bool passed = true; rc = of_parse_phandle_with_args(np, "phandle-list", "#phandle-cells", i, &args); /* Test the values from tests-phandle.dtsi */ switch (i) { case 0: passed &= !rc; passed &= (args.args_count == 1); passed &= (args.args[0] == (i + 1)); break; case 1: passed &= !rc; passed &= (args.args_count == 2); passed &= (args.args[0] == (i + 1)); passed &= (args.args[1] == 0); break; case 2: passed &= (rc == -ENOENT); break; case 3: passed &= !rc; passed &= (args.args_count == 3); passed &= (args.args[0] == (i + 1)); passed &= (args.args[1] == 4); passed &= (args.args[2] == 3); break; case 4: passed &= !rc; passed &= (args.args_count == 2); passed &= (args.args[0] == (i + 1)); passed &= (args.args[1] == 100); break; case 5: passed &= !rc; passed &= (args.args_count == 0); break; case 6: passed &= !rc; passed &= (args.args_count == 1); passed &= (args.args[0] == (i + 1)); break; case 7: passed &= (rc == -ENOENT); break; default: passed = false; } selftest(passed, "index %i - data error on node %s rc=%i\n", i, args.np->full_name, rc); } /* Check for missing list property */ rc = of_parse_phandle_with_args(np, "phandle-list-missing", "#phandle-cells", 0, &args); selftest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc); rc = of_count_phandle_with_args(np, "phandle-list-missing", "#phandle-cells"); selftest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc); /* Check for missing cells property */ rc = of_parse_phandle_with_args(np, "phandle-list", "#phandle-cells-missing", 0, &args); selftest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); rc = of_count_phandle_with_args(np, "phandle-list", "#phandle-cells-missing"); selftest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); /* Check for bad phandle in list */ rc = of_parse_phandle_with_args(np, "phandle-list-bad-phandle", "#phandle-cells", 0, &args); selftest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); rc = of_count_phandle_with_args(np, "phandle-list-bad-phandle", "#phandle-cells"); selftest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); /* Check for incorrectly formed argument list */ rc = of_parse_phandle_with_args(np, "phandle-list-bad-args", "#phandle-cells", 1, &args); selftest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); rc = of_count_phandle_with_args(np, "phandle-list-bad-args", "#phandle-cells"); selftest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); }
static int ehci_platform_probe(struct platform_device *dev) { struct usb_hcd *hcd; struct resource *res_mem; struct usb_ehci_pdata *pdata = dev_get_platdata(&dev->dev); struct ehci_platform_priv *priv; struct ehci_hcd *ehci; int err, irq, phy_num, clk = 0; if (usb_disabled()) return -ENODEV; /* * Use reasonable defaults so platforms don't have to provide these * with DT probing on ARM. */ if (!pdata) pdata = &ehci_platform_defaults; err = dma_coerce_mask_and_coherent(&dev->dev, pdata->dma_mask_64 ? DMA_BIT_MASK(64) : DMA_BIT_MASK(32)); if (err) return err; irq = platform_get_irq(dev, 0); if (irq < 0) { dev_err(&dev->dev, "no irq provided"); return irq; } hcd = usb_create_hcd(&ehci_platform_hc_driver, &dev->dev, dev_name(&dev->dev)); if (!hcd) return -ENOMEM; platform_set_drvdata(dev, hcd); dev->dev.platform_data = pdata; priv = hcd_to_ehci_priv(hcd); ehci = hcd_to_ehci(hcd); if (pdata == &ehci_platform_defaults && dev->dev.of_node) { if (of_property_read_bool(dev->dev.of_node, "big-endian-regs")) ehci->big_endian_mmio = 1; if (of_property_read_bool(dev->dev.of_node, "big-endian-desc")) ehci->big_endian_desc = 1; if (of_property_read_bool(dev->dev.of_node, "big-endian")) ehci->big_endian_mmio = ehci->big_endian_desc = 1; if (of_property_read_bool(dev->dev.of_node, "needs-reset-on-resume")) priv->reset_on_resume = true; if (of_property_read_bool(dev->dev.of_node, "has-transaction-translator")) hcd->has_tt = 1; priv->num_phys = of_count_phandle_with_args(dev->dev.of_node, "phys", "#phy-cells"); if (priv->num_phys > 0) { priv->phys = devm_kcalloc(&dev->dev, priv->num_phys, sizeof(struct phy *), GFP_KERNEL); if (!priv->phys) return -ENOMEM; } else priv->num_phys = 0; for (phy_num = 0; phy_num < priv->num_phys; phy_num++) { priv->phys[phy_num] = devm_of_phy_get_by_index( &dev->dev, dev->dev.of_node, phy_num); if (IS_ERR(priv->phys[phy_num])) { err = PTR_ERR(priv->phys[phy_num]); goto err_put_hcd; } } for (clk = 0; clk < EHCI_MAX_CLKS; clk++) { priv->clks[clk] = of_clk_get(dev->dev.of_node, clk); if (IS_ERR(priv->clks[clk])) { err = PTR_ERR(priv->clks[clk]); if (err == -EPROBE_DEFER) goto err_put_clks; priv->clks[clk] = NULL; break; } } } priv->rst = devm_reset_control_get_optional(&dev->dev, NULL); if (IS_ERR(priv->rst)) { err = PTR_ERR(priv->rst); if (err == -EPROBE_DEFER) goto err_put_clks; priv->rst = NULL; } else { err = reset_control_deassert(priv->rst); if (err) goto err_put_clks; } if (pdata->big_endian_desc) ehci->big_endian_desc = 1; if (pdata->big_endian_mmio) ehci->big_endian_mmio = 1; if (pdata->has_tt) hcd->has_tt = 1; if (pdata->reset_on_resume) priv->reset_on_resume = true; #ifndef CONFIG_USB_EHCI_BIG_ENDIAN_MMIO if (ehci->big_endian_mmio) { dev_err(&dev->dev, "Error: CONFIG_USB_EHCI_BIG_ENDIAN_MMIO not set\n"); err = -EINVAL; goto err_reset; } #endif #ifndef CONFIG_USB_EHCI_BIG_ENDIAN_DESC if (ehci->big_endian_desc) { dev_err(&dev->dev, "Error: CONFIG_USB_EHCI_BIG_ENDIAN_DESC not set\n"); err = -EINVAL; goto err_reset; } #endif if (pdata->power_on) { err = pdata->power_on(dev); if (err < 0) goto err_reset; } res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0); hcd->regs = devm_ioremap_resource(&dev->dev, res_mem); if (IS_ERR(hcd->regs)) { err = PTR_ERR(hcd->regs); goto err_power; } hcd->rsrc_start = res_mem->start; hcd->rsrc_len = resource_size(res_mem); err = usb_add_hcd(hcd, irq, IRQF_SHARED); if (err) goto err_power; device_wakeup_enable(hcd->self.controller); platform_set_drvdata(dev, hcd); return err; err_power: if (pdata->power_off) pdata->power_off(dev); err_reset: if (priv->rst) reset_control_assert(priv->rst); err_put_clks: while (--clk >= 0) clk_put(priv->clks[clk]); err_put_hcd: if (pdata == &ehci_platform_defaults) dev->dev.platform_data = NULL; usb_put_hcd(hcd); return err; }
static int scpi_probe(struct platform_device *pdev) { int count, idx, ret; struct resource res; struct scpi_chan *scpi_chan; struct device *dev = &pdev->dev; struct device_node *np = dev->of_node; scpi_info = devm_kzalloc(dev, sizeof(*scpi_info), GFP_KERNEL); if (!scpi_info) { dev_err(dev, "failed to allocate memory for scpi drvinfo\n"); return -ENOMEM; } count = of_count_phandle_with_args(np, "mboxes", "#mbox-cells"); if (count < 0) { dev_err(dev, "no mboxes property in '%s'\n", np->full_name); return -ENODEV; } scpi_chan = devm_kcalloc(dev, count, sizeof(*scpi_chan), GFP_KERNEL); if (!scpi_chan) { dev_err(dev, "failed to allocate memory scpi chaninfo\n"); return -ENOMEM; } for (idx = 0; idx < count; idx++) { resource_size_t size; struct scpi_chan *pchan = scpi_chan + idx; struct mbox_client *cl = &pchan->cl; struct device_node *shmem = of_parse_phandle(np, "shmem", idx); if (of_address_to_resource(shmem, 0, &res)) { dev_err(dev, "failed to get SCPI payload mem resource\n"); ret = -EINVAL; goto err; } size = resource_size(&res); pchan->rx_payload = devm_ioremap(dev, res.start, size); if (!pchan->rx_payload) { dev_err(dev, "failed to ioremap SCPI payload\n"); ret = -EADDRNOTAVAIL; goto err; } pchan->tx_payload = pchan->rx_payload + (size >> 1); cl->dev = dev; cl->rx_callback = scpi_handle_remote_msg; cl->tx_prepare = scpi_tx_prepare; cl->tx_block = true; cl->tx_tout = 50; cl->knows_txdone = false; /* controller can ack */ INIT_LIST_HEAD(&pchan->rx_pending); INIT_LIST_HEAD(&pchan->xfers_list); spin_lock_init(&pchan->rx_lock); mutex_init(&pchan->xfers_lock); ret = scpi_alloc_xfer_list(dev, pchan); if (!ret) { pchan->chan = mbox_request_channel(cl, idx); if (!IS_ERR(pchan->chan)) continue; ret = -EPROBE_DEFER; dev_err(dev, "failed to acquire channel#%d\n", idx); } err: scpi_free_channels(dev, scpi_chan, idx); scpi_info = NULL; return ret; } scpi_info->channels = scpi_chan; scpi_info->num_chans = count; platform_set_drvdata(pdev, scpi_info); ret = scpi_init_versions(scpi_info); if (ret) { dev_err(dev, "incorrect or no SCP firmware found\n"); scpi_remove(pdev); return ret; } _dev_info(dev, "SCP Protocol %d.%d Firmware %d.%d.%d version\n", PROTOCOL_REV_MAJOR(scpi_info->protocol_version), PROTOCOL_REV_MINOR(scpi_info->protocol_version), FW_REV_MAJOR(scpi_info->firmware_version), FW_REV_MINOR(scpi_info->firmware_version), FW_REV_PATCH(scpi_info->firmware_version)); scpi_info->scpi_ops = &scpi_ops; ret = sysfs_create_groups(&dev->kobj, versions_groups); if (ret) dev_err(dev, "unable to create sysfs version group\n"); return of_platform_populate(dev->of_node, NULL, NULL, dev); }