Lines Matching +full:npcm750 +full:- +full:gcr
1 // SPDX-License-Identifier: GPL-2.0
12 #include <linux/reset-controller.h>
18 /* NPCM7xx GCR registers */
104 writel(NPCM_SWRST << rc->sw_reset_number, rc->base + NPCM_SWRSTR); in npcm_rc_restart()
121 spin_lock_irqsave(&rc->lock, flags); in npcm_rc_setclear_reset()
122 stat = readl(rc->base + ctrl_offset); in npcm_rc_setclear_reset()
124 writel(stat | rst_bit, rc->base + ctrl_offset); in npcm_rc_setclear_reset()
126 writel(stat & ~rst_bit, rc->base + ctrl_offset); in npcm_rc_setclear_reset()
127 spin_unlock_irqrestore(&rc->lock, flags); in npcm_rc_setclear_reset()
150 return (readl(rc->base + ctrl_offset) & rst_bit); in npcm_rc_status()
161 offset = reset_spec->args[0]; in npcm_reset_xlate()
162 for (off_num = 0 ; off_num < rc->info->num_ipsrst ; off_num++) { in npcm_reset_xlate()
163 if (offset == rc->info->ipsrst[off_num]) { in npcm_reset_xlate()
170 dev_err(rcdev->dev, "Error reset register (0x%x)\n", offset); in npcm_reset_xlate()
171 return -EINVAL; in npcm_reset_xlate()
174 bit = reset_spec->args[1]; in npcm_reset_xlate()
176 dev_err(rcdev->dev, "Error reset number (%d)\n", bit); in npcm_reset_xlate()
177 return -EINVAL; in npcm_reset_xlate()
184 { .compatible = "nuvoton,npcm750-reset", .data = &npxm7xx_reset_info},
185 { .compatible = "nuvoton,npcm845-reset", .data = &npxm8xx_reset_info},
197 regmap_read(rc->gcr_regmap, NPCM_MDLR_OFFSET, &mdlr); in npcm_usb_reset_npcm7xx()
215 iprst1 = readl(rc->base + NPCM_IPSRST1); in npcm_usb_reset_npcm7xx()
216 iprst2 = readl(rc->base + NPCM_IPSRST2); in npcm_usb_reset_npcm7xx()
217 iprst3 = readl(rc->base + NPCM_IPSRST3); in npcm_usb_reset_npcm7xx()
224 writel(iprst1, rc->base + NPCM_IPSRST1); in npcm_usb_reset_npcm7xx()
225 writel(iprst2, rc->base + NPCM_IPSRST2); in npcm_usb_reset_npcm7xx()
226 writel(iprst3, rc->base + NPCM_IPSRST3); in npcm_usb_reset_npcm7xx()
229 regmap_update_bits(rc->gcr_regmap, NPCM_USB1PHYCTL_OFFSET, in npcm_usb_reset_npcm7xx()
231 regmap_update_bits(rc->gcr_regmap, NPCM_USB2PHYCTL_OFFSET, in npcm_usb_reset_npcm7xx()
236 writel(iprst3, rc->base + NPCM_IPSRST3); in npcm_usb_reset_npcm7xx()
241 regmap_update_bits(rc->gcr_regmap, NPCM_USB1PHYCTL_OFFSET, in npcm_usb_reset_npcm7xx()
243 regmap_update_bits(rc->gcr_regmap, NPCM_USB2PHYCTL_OFFSET, in npcm_usb_reset_npcm7xx()
251 writel(iprst1, rc->base + NPCM_IPSRST1); in npcm_usb_reset_npcm7xx()
252 writel(iprst2, rc->base + NPCM_IPSRST2); in npcm_usb_reset_npcm7xx()
253 writel(iprst3, rc->base + NPCM_IPSRST3); in npcm_usb_reset_npcm7xx()
265 regmap_read(rc->gcr_regmap, NPCM_MDLR_OFFSET, &mdlr); in npcm_usb_reset_npcm8xx()
285 iprst1 = readl(rc->base + NPCM_IPSRST1); in npcm_usb_reset_npcm8xx()
286 iprst2 = readl(rc->base + NPCM_IPSRST2); in npcm_usb_reset_npcm8xx()
287 iprst3 = readl(rc->base + NPCM_IPSRST3); in npcm_usb_reset_npcm8xx()
288 iprst4 = readl(rc->base + NPCM_IPSRST4); in npcm_usb_reset_npcm8xx()
296 writel(iprst1, rc->base + NPCM_IPSRST1); in npcm_usb_reset_npcm8xx()
297 writel(iprst2, rc->base + NPCM_IPSRST2); in npcm_usb_reset_npcm8xx()
298 writel(iprst3, rc->base + NPCM_IPSRST3); in npcm_usb_reset_npcm8xx()
299 writel(iprst4, rc->base + NPCM_IPSRST4); in npcm_usb_reset_npcm8xx()
302 regmap_update_bits(rc->gcr_regmap, NPCM_USB1PHYCTL_OFFSET, in npcm_usb_reset_npcm8xx()
304 regmap_update_bits(rc->gcr_regmap, NPCM_USB2PHYCTL_OFFSET, in npcm_usb_reset_npcm8xx()
306 regmap_update_bits(rc->gcr_regmap, NPCM_USB3PHYCTL_OFFSET, in npcm_usb_reset_npcm8xx()
311 writel(iprst3, rc->base + NPCM_IPSRST3); in npcm_usb_reset_npcm8xx()
313 writel(iprst4, rc->base + NPCM_IPSRST4); in npcm_usb_reset_npcm8xx()
316 regmap_update_bits(rc->gcr_regmap, NPCM_USB1PHYCTL_OFFSET, in npcm_usb_reset_npcm8xx()
318 regmap_update_bits(rc->gcr_regmap, NPCM_USB2PHYCTL_OFFSET, in npcm_usb_reset_npcm8xx()
320 regmap_update_bits(rc->gcr_regmap, NPCM_USB3PHYCTL_OFFSET, in npcm_usb_reset_npcm8xx()
329 writel(iprst1, rc->base + NPCM_IPSRST1); in npcm_usb_reset_npcm8xx()
330 writel(iprst2, rc->base + NPCM_IPSRST2); in npcm_usb_reset_npcm8xx()
331 writel(iprst3, rc->base + NPCM_IPSRST3); in npcm_usb_reset_npcm8xx()
332 writel(iprst4, rc->base + NPCM_IPSRST4); in npcm_usb_reset_npcm8xx()
341 struct device *dev = &pdev->dev; in npcm_usb_reset()
343 rc->gcr_regmap = syscon_regmap_lookup_by_phandle(dev->of_node, "nuvoton,sysgcr"); in npcm_usb_reset()
344 if (IS_ERR(rc->gcr_regmap)) { in npcm_usb_reset()
345 dev_warn(&pdev->dev, "Failed to find nuvoton,sysgcr property, please update the device tree\n"); in npcm_usb_reset()
346 dev_info(&pdev->dev, "Using nuvoton,npcm750-gcr for Poleg backward compatibility\n"); in npcm_usb_reset()
347 rc->gcr_regmap = syscon_regmap_lookup_by_compatible("nuvoton,npcm750-gcr"); in npcm_usb_reset()
348 if (IS_ERR(rc->gcr_regmap)) { in npcm_usb_reset()
349 dev_err(&pdev->dev, "Failed to find nuvoton,npcm750-gcr"); in npcm_usb_reset()
350 return PTR_ERR(rc->gcr_regmap); in npcm_usb_reset()
354 rc->info = device_get_match_data(dev); in npcm_usb_reset()
355 switch (rc->info->bmc_id) { in npcm_usb_reset()
363 return -ENODEV; in npcm_usb_reset()
380 rc = devm_kzalloc(&pdev->dev, sizeof(*rc), GFP_KERNEL); in npcm_rc_probe()
382 return -ENOMEM; in npcm_rc_probe()
384 rc->base = devm_platform_ioremap_resource(pdev, 0); in npcm_rc_probe()
385 if (IS_ERR(rc->base)) in npcm_rc_probe()
386 return PTR_ERR(rc->base); in npcm_rc_probe()
388 spin_lock_init(&rc->lock); in npcm_rc_probe()
390 rc->rcdev.owner = THIS_MODULE; in npcm_rc_probe()
391 rc->rcdev.ops = &npcm_rc_ops; in npcm_rc_probe()
392 rc->rcdev.of_node = pdev->dev.of_node; in npcm_rc_probe()
393 rc->rcdev.of_reset_n_cells = 2; in npcm_rc_probe()
394 rc->rcdev.of_xlate = npcm_reset_xlate; in npcm_rc_probe()
396 ret = devm_reset_controller_register(&pdev->dev, &rc->rcdev); in npcm_rc_probe()
398 dev_err(&pdev->dev, "unable to register device\n"); in npcm_rc_probe()
403 dev_warn(&pdev->dev, "NPCM USB reset failed, can cause issues with UDC and USB host\n"); in npcm_rc_probe()
405 if (!of_property_read_u32(pdev->dev.of_node, "nuvoton,sw-reset-number", in npcm_rc_probe()
406 &rc->sw_reset_number)) { in npcm_rc_probe()
407 if (rc->sw_reset_number && rc->sw_reset_number < 5) { in npcm_rc_probe()
408 rc->restart_nb.priority = 192; in npcm_rc_probe()
409 rc->restart_nb.notifier_call = npcm_rc_restart; in npcm_rc_probe()
410 ret = register_restart_handler(&rc->restart_nb); in npcm_rc_probe()
412 dev_warn(&pdev->dev, "failed to register restart handler\n"); in npcm_rc_probe()
422 .name = "npcm-reset",