Lines Matching +full:baikal +full:- +full:t1
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2020 BAIKAL ELECTRONICS, JSC
8 * Baikal-T1 APB-bus driver
38 * struct bt1_apb - Baikal-T1 APB EHB private data
41 * @res: No-device error injection memory region.
43 * @rate: APB-bus reference clock rate.
44 * @pclk: APB-reference clock.
75 do_div(timeout, apb->rate); in bt1_apb_n_to_timeout_us()
84 u64 n = (u64)timeout * apb->rate; in bt1_apb_timeout_to_n_us()
97 regmap_read(apb->regs, APB_EHB_ADDR, &addr); in bt1_apb_isr()
99 dev_crit_ratelimited(apb->dev, in bt1_apb_isr()
100 "APB-bus fault %d: Slave access timeout at 0x%08x\n", in bt1_apb_isr()
101 atomic_inc_return(&apb->count), in bt1_apb_isr()
113 regmap_update_bits(apb->regs, APB_EHB_ISR, APB_EHB_ISR_PENDING, 0); in bt1_apb_isr()
121 struct platform_device *pdev = to_platform_device(apb->dev); in bt1_apb_clear_data()
128 struct device *dev = &pdev->dev; in bt1_apb_create_data()
134 return ERR_PTR(-ENOMEM); in bt1_apb_create_data()
142 apb->dev = dev; in bt1_apb_create_data()
143 atomic_set(&apb->count, 0); in bt1_apb_create_data()
151 struct platform_device *pdev = to_platform_device(apb->dev); in bt1_apb_request_regs()
156 dev_err(apb->dev, "Couldn't map APB EHB registers\n"); in bt1_apb_request_regs()
160 apb->regs = devm_regmap_init_mmio(apb->dev, regs, &bt1_apb_regmap_cfg); in bt1_apb_request_regs()
161 if (IS_ERR(apb->regs)) { in bt1_apb_request_regs()
162 dev_err(apb->dev, "Couldn't create APB EHB regmap\n"); in bt1_apb_request_regs()
163 return PTR_ERR(apb->regs); in bt1_apb_request_regs()
166 apb->res = devm_platform_ioremap_resource_byname(pdev, "nodev"); in bt1_apb_request_regs()
167 if (IS_ERR(apb->res)) in bt1_apb_request_regs()
168 dev_err(apb->dev, "Couldn't map reserved region\n"); in bt1_apb_request_regs()
170 return PTR_ERR_OR_ZERO(apb->res); in bt1_apb_request_regs()
177 apb->prst = devm_reset_control_get_optional_exclusive(apb->dev, "prst"); in bt1_apb_request_rst()
178 if (IS_ERR(apb->prst)) { in bt1_apb_request_rst()
179 dev_warn(apb->dev, "Couldn't get reset control line\n"); in bt1_apb_request_rst()
180 return PTR_ERR(apb->prst); in bt1_apb_request_rst()
183 ret = reset_control_deassert(apb->prst); in bt1_apb_request_rst()
185 dev_err(apb->dev, "Failed to deassert the reset line\n"); in bt1_apb_request_rst()
194 clk_disable_unprepare(apb->pclk); in bt1_apb_disable_clk()
201 apb->pclk = devm_clk_get(apb->dev, "pclk"); in bt1_apb_request_clk()
202 if (IS_ERR(apb->pclk)) { in bt1_apb_request_clk()
203 dev_err(apb->dev, "Couldn't get APB clock descriptor\n"); in bt1_apb_request_clk()
204 return PTR_ERR(apb->pclk); in bt1_apb_request_clk()
207 ret = clk_prepare_enable(apb->pclk); in bt1_apb_request_clk()
209 dev_err(apb->dev, "Couldn't enable the APB clock\n"); in bt1_apb_request_clk()
213 ret = devm_add_action_or_reset(apb->dev, bt1_apb_disable_clk, apb); in bt1_apb_request_clk()
215 dev_err(apb->dev, "Can't add APB EHB clocks disable action\n"); in bt1_apb_request_clk()
219 apb->rate = clk_get_rate(apb->pclk); in bt1_apb_request_clk()
220 if (!apb->rate) { in bt1_apb_request_clk()
221 dev_err(apb->dev, "Invalid clock rate\n"); in bt1_apb_request_clk()
222 return -EINVAL; in bt1_apb_request_clk()
232 regmap_update_bits(apb->regs, APB_EHB_ISR, APB_EHB_ISR_MASK, 0); in bt1_apb_clear_irq()
237 struct platform_device *pdev = to_platform_device(apb->dev); in bt1_apb_request_irq()
240 apb->irq = platform_get_irq(pdev, 0); in bt1_apb_request_irq()
241 if (apb->irq < 0) in bt1_apb_request_irq()
242 return apb->irq; in bt1_apb_request_irq()
244 ret = devm_request_irq(apb->dev, apb->irq, bt1_apb_isr, IRQF_SHARED, in bt1_apb_request_irq()
245 "bt1-apb", apb); in bt1_apb_request_irq()
247 dev_err(apb->dev, "Couldn't request APB EHB IRQ\n"); in bt1_apb_request_irq()
251 ret = devm_add_action(apb->dev, bt1_apb_clear_irq, apb); in bt1_apb_request_irq()
253 dev_err(apb->dev, "Can't add APB EHB IRQs clear action\n"); in bt1_apb_request_irq()
258 regmap_update_bits(apb->regs, APB_EHB_ISR, in bt1_apb_request_irq()
270 return scnprintf(buf, PAGE_SIZE, "%d\n", atomic_read(&apb->count)); in count_show()
282 ret = regmap_read(apb->regs, APB_EHB_TIMEOUT, &n); in timeout_show()
301 return -EINVAL; in timeout_store()
306 ret = regmap_write(apb->regs, APB_EHB_TIMEOUT, n); in timeout_store()
329 readl(apb->res); in inject_error_store()
331 regmap_update_bits(apb->regs, APB_EHB_ISR, APB_EHB_ISR_PENDING, in inject_error_store()
334 return -EINVAL; in inject_error_store()
352 device_remove_groups(apb->dev, bt1_apb_sysfs_groups); in bt1_apb_remove_sysfs()
359 ret = device_add_groups(apb->dev, bt1_apb_sysfs_groups); in bt1_apb_init_sysfs()
361 dev_err(apb->dev, "Failed to create EHB APB sysfs nodes\n"); in bt1_apb_init_sysfs()
365 ret = devm_add_action_or_reset(apb->dev, bt1_apb_remove_sysfs, apb); in bt1_apb_init_sysfs()
367 dev_err(apb->dev, "Can't add APB EHB sysfs remove action\n"); in bt1_apb_init_sysfs()
405 { .compatible = "baikal,bt1-apb" },
413 .name = "bt1-apb",
420 MODULE_DESCRIPTION("Baikal-T1 APB-bus driver");