Lines Matching +full:bus +full:- +full:id
1 // SPDX-License-Identifier: GPL-2.0-or-later
7 #include <dt-bindings/soc/bcm-pmb.h>
79 int id; member
80 u8 bus; member
90 static int bcm_pmb_bpcm_read(struct bcm_pmb *pmb, int bus, u8 device, in bcm_pmb_bpcm_read() argument
93 void __iomem *base = pmb->base + bus * 0x20; in bcm_pmb_bpcm_read()
97 spin_lock_irqsave(&pmb->lock, flags); in bcm_pmb_bpcm_read()
99 spin_unlock_irqrestore(&pmb->lock, flags); in bcm_pmb_bpcm_read()
102 *val = pmb->little_endian ? le32_to_cpu(*val) : be32_to_cpu(*val); in bcm_pmb_bpcm_read()
107 static int bcm_pmb_bpcm_write(struct bcm_pmb *pmb, int bus, u8 device, in bcm_pmb_bpcm_write() argument
110 void __iomem *base = pmb->base + bus * 0x20; in bcm_pmb_bpcm_write()
114 val = pmb->little_endian ? cpu_to_le32(val) : cpu_to_be32(val); in bcm_pmb_bpcm_write()
116 spin_lock_irqsave(&pmb->lock, flags); in bcm_pmb_bpcm_write()
118 spin_unlock_irqrestore(&pmb->lock, flags); in bcm_pmb_bpcm_write()
123 static int bcm_pmb_power_off_zone(struct bcm_pmb *pmb, int bus, u8 device, in bcm_pmb_power_off_zone() argument
132 err = bcm_pmb_bpcm_read(pmb, bus, device, offset, &val); in bcm_pmb_power_off_zone()
139 err = bcm_pmb_bpcm_write(pmb, bus, device, offset, val); in bcm_pmb_power_off_zone()
144 static int bcm_pmb_power_on_zone(struct bcm_pmb *pmb, int bus, u8 device, in bcm_pmb_power_on_zone() argument
153 err = bcm_pmb_bpcm_read(pmb, bus, device, offset, &val); in bcm_pmb_power_on_zone()
164 err = bcm_pmb_bpcm_write(pmb, bus, device, offset, val); in bcm_pmb_power_on_zone()
170 static int bcm_pmb_power_off_device(struct bcm_pmb *pmb, int bus, u8 device) in bcm_pmb_power_off_device() argument
179 err = bcm_pmb_bpcm_read(pmb, bus, device, offset, &val); in bcm_pmb_power_off_device()
186 err = bcm_pmb_bpcm_write(pmb, bus, device, offset, val); in bcm_pmb_power_off_device()
192 static int bcm_pmb_power_on_device(struct bcm_pmb *pmb, int bus, u8 device) in bcm_pmb_power_on_device() argument
198 err = bcm_pmb_bpcm_read(pmb, bus, device, BPCM_CAPABILITIES, &val); in bcm_pmb_power_on_device()
203 err = bcm_pmb_power_on_zone(pmb, bus, device, i); in bcm_pmb_power_on_device()
211 static int bcm_pmb_power_on_sata(struct bcm_pmb *pmb, int bus, u8 device) in bcm_pmb_power_on_sata() argument
215 err = bcm_pmb_power_on_zone(pmb, bus, device, 0); in bcm_pmb_power_on_sata()
220 err = bcm_pmb_bpcm_write(pmb, bus, device, BPCM_MISC_CONTROL, 0); in bcm_pmb_power_on_sata()
224 err = bcm_pmb_bpcm_write(pmb, bus, device, BPCM_SR_CONTROL, 0xffffffff); in bcm_pmb_power_on_sata()
228 err = bcm_pmb_bpcm_write(pmb, bus, device, BPCM_SR_CONTROL, 0); in bcm_pmb_power_on_sata()
236 const struct bcm_pmb_pd_data *data = pd->data; in bcm_pmb_power_on()
237 struct bcm_pmb *pmb = pd->pmb; in bcm_pmb_power_on()
239 switch (data->id) { in bcm_pmb_power_on()
243 return bcm_pmb_power_on_zone(pmb, data->bus, data->device, 0); in bcm_pmb_power_on()
245 return bcm_pmb_power_on_device(pmb, data->bus, data->device); in bcm_pmb_power_on()
247 return bcm_pmb_power_on_sata(pmb, data->bus, data->device); in bcm_pmb_power_on()
249 dev_err(pmb->dev, "unsupported device id: %d\n", data->id); in bcm_pmb_power_on()
250 return -EINVAL; in bcm_pmb_power_on()
257 const struct bcm_pmb_pd_data *data = pd->data; in bcm_pmb_power_off()
258 struct bcm_pmb *pmb = pd->pmb; in bcm_pmb_power_off()
260 switch (data->id) { in bcm_pmb_power_off()
264 return bcm_pmb_power_off_zone(pmb, data->bus, data->device, 0); in bcm_pmb_power_off()
266 return bcm_pmb_power_off_device(pmb, data->bus, data->device); in bcm_pmb_power_off()
268 dev_err(pmb->dev, "unsupported device id: %d\n", data->id); in bcm_pmb_power_off()
269 return -EINVAL; in bcm_pmb_power_off()
275 struct device *dev = &pdev->dev; in bcm_pmb_probe()
284 return -ENOMEM; in bcm_pmb_probe()
286 pmb->dev = dev; in bcm_pmb_probe()
288 pmb->base = devm_platform_ioremap_resource(pdev, 0); in bcm_pmb_probe()
289 if (IS_ERR(pmb->base)) in bcm_pmb_probe()
290 return PTR_ERR(pmb->base); in bcm_pmb_probe()
292 spin_lock_init(&pmb->lock); in bcm_pmb_probe()
294 pmb->little_endian = !of_device_is_big_endian(dev->of_node); in bcm_pmb_probe()
298 return -EINVAL; in bcm_pmb_probe()
301 for (e = table; e->name; e++) in bcm_pmb_probe()
302 max_id = max(max_id, e->id); in bcm_pmb_probe()
304 pmb->genpd_onecell_data.num_domains = max_id + 1; in bcm_pmb_probe()
305 pmb->genpd_onecell_data.domains = in bcm_pmb_probe()
306 devm_kcalloc(dev, pmb->genpd_onecell_data.num_domains, in bcm_pmb_probe()
308 if (!pmb->genpd_onecell_data.domains) in bcm_pmb_probe()
309 return -ENOMEM; in bcm_pmb_probe()
311 for (e = table; e->name; e++) { in bcm_pmb_probe()
315 return -ENOMEM; in bcm_pmb_probe()
317 pd->pmb = pmb; in bcm_pmb_probe()
318 pd->data = e; in bcm_pmb_probe()
319 pd->genpd.name = e->name; in bcm_pmb_probe()
320 pd->genpd.power_on = bcm_pmb_power_on; in bcm_pmb_probe()
321 pd->genpd.power_off = bcm_pmb_power_off; in bcm_pmb_probe()
323 pm_genpd_init(&pd->genpd, NULL, true); in bcm_pmb_probe()
324 pmb->genpd_onecell_data.domains[e->id] = &pd->genpd; in bcm_pmb_probe()
327 err = of_genpd_add_provider_onecell(dev->of_node, &pmb->genpd_onecell_data); in bcm_pmb_probe()
337 { .name = "pcie2", .id = BCM_PMB_PCIE2, .bus = 0, .device = 2, },
338 { .name = "pcie0", .id = BCM_PMB_PCIE0, .bus = 1, .device = 14, },
339 { .name = "pcie1", .id = BCM_PMB_PCIE1, .bus = 1, .device = 15, },
340 { .name = "usb", .id = BCM_PMB_HOST_USB, .bus = 1, .device = 17, },
345 { .name = "sata", .id = BCM_PMB_SATA, .bus = 0, .device = 3, },
350 { .compatible = "brcm,bcm4908-pmb", .data = &bcm_pmb_bcm4908_data, },
351 { .compatible = "brcm,bcm63138-pmb", .data = &bcm_pmb_bcm63138_data, },
357 .name = "bcm-pmb",