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
37 * struct bt1_apb - Baikal-T1 APB EHB private data
40 * @res: No-device error injection memory region.
42 * @rate: APB-bus reference clock rate.
43 * @pclk: APB-reference clock.
74 do_div(timeout, apb->rate); in bt1_apb_n_to_timeout_us()
83 u64 n = (u64)timeout * apb->rate; in bt1_apb_timeout_to_n_us()
96 regmap_read(apb->regs, APB_EHB_ADDR, &addr); in bt1_apb_isr()
98 dev_crit_ratelimited(apb->dev, in bt1_apb_isr()
99 "APB-bus fault %d: Slave access timeout at 0x%08x\n", in bt1_apb_isr()
100 atomic_inc_return(&apb->count), in bt1_apb_isr()
112 regmap_update_bits(apb->regs, APB_EHB_ISR, APB_EHB_ISR_PENDING, 0); in bt1_apb_isr()
120 struct platform_device *pdev = to_platform_device(apb->dev); in bt1_apb_clear_data()
127 struct device *dev = &pdev->dev; in bt1_apb_create_data()
133 return ERR_PTR(-ENOMEM); in bt1_apb_create_data()
141 apb->dev = dev; in bt1_apb_create_data()
142 atomic_set(&apb->count, 0); in bt1_apb_create_data()
150 struct platform_device *pdev = to_platform_device(apb->dev); in bt1_apb_request_regs()
155 dev_err(apb->dev, "Couldn't map APB EHB registers\n"); in bt1_apb_request_regs()
159 apb->regs = devm_regmap_init_mmio(apb->dev, regs, &bt1_apb_regmap_cfg); in bt1_apb_request_regs()
160 if (IS_ERR(apb->regs)) { in bt1_apb_request_regs()
161 dev_err(apb->dev, "Couldn't create APB EHB regmap\n"); in bt1_apb_request_regs()
162 return PTR_ERR(apb->regs); in bt1_apb_request_regs()
165 apb->res = devm_platform_ioremap_resource_byname(pdev, "nodev"); in bt1_apb_request_regs()
166 if (IS_ERR(apb->res)) in bt1_apb_request_regs()
167 dev_err(apb->dev, "Couldn't map reserved region\n"); in bt1_apb_request_regs()
169 return PTR_ERR_OR_ZERO(apb->res); in bt1_apb_request_regs()
176 apb->prst = devm_reset_control_get_optional_exclusive(apb->dev, "prst"); in bt1_apb_request_rst()
177 if (IS_ERR(apb->prst)) in bt1_apb_request_rst()
178 return dev_err_probe(apb->dev, PTR_ERR(apb->prst), in bt1_apb_request_rst()
181 ret = reset_control_deassert(apb->prst); in bt1_apb_request_rst()
183 dev_err(apb->dev, "Failed to deassert the reset line\n"); in bt1_apb_request_rst()
190 apb->pclk = devm_clk_get_enabled(apb->dev, "pclk"); in bt1_apb_request_clk()
191 if (IS_ERR(apb->pclk)) in bt1_apb_request_clk()
192 return dev_err_probe(apb->dev, PTR_ERR(apb->pclk), in bt1_apb_request_clk()
195 apb->rate = clk_get_rate(apb->pclk); in bt1_apb_request_clk()
196 if (!apb->rate) { in bt1_apb_request_clk()
197 dev_err(apb->dev, "Invalid clock rate\n"); in bt1_apb_request_clk()
198 return -EINVAL; in bt1_apb_request_clk()
208 regmap_update_bits(apb->regs, APB_EHB_ISR, APB_EHB_ISR_MASK, 0); in bt1_apb_clear_irq()
213 struct platform_device *pdev = to_platform_device(apb->dev); in bt1_apb_request_irq()
216 apb->irq = platform_get_irq(pdev, 0); in bt1_apb_request_irq()
217 if (apb->irq < 0) in bt1_apb_request_irq()
218 return apb->irq; in bt1_apb_request_irq()
220 ret = devm_request_irq(apb->dev, apb->irq, bt1_apb_isr, IRQF_SHARED, in bt1_apb_request_irq()
221 "bt1-apb", apb); in bt1_apb_request_irq()
223 dev_err(apb->dev, "Couldn't request APB EHB IRQ\n"); in bt1_apb_request_irq()
227 ret = devm_add_action(apb->dev, bt1_apb_clear_irq, apb); in bt1_apb_request_irq()
229 dev_err(apb->dev, "Can't add APB EHB IRQs clear action\n"); in bt1_apb_request_irq()
234 regmap_update_bits(apb->regs, APB_EHB_ISR, in bt1_apb_request_irq()
246 return scnprintf(buf, PAGE_SIZE, "%d\n", atomic_read(&apb->count)); in count_show()
258 ret = regmap_read(apb->regs, APB_EHB_TIMEOUT, &n); in timeout_show()
277 return -EINVAL; in timeout_store()
282 ret = regmap_write(apb->regs, APB_EHB_TIMEOUT, n); in timeout_store()
305 readl(apb->res); in inject_error_store()
307 regmap_update_bits(apb->regs, APB_EHB_ISR, APB_EHB_ISR_PENDING, in inject_error_store()
310 return -EINVAL; in inject_error_store()
328 device_remove_groups(apb->dev, bt1_apb_sysfs_groups); in bt1_apb_remove_sysfs()
335 ret = device_add_groups(apb->dev, bt1_apb_sysfs_groups); in bt1_apb_init_sysfs()
337 dev_err(apb->dev, "Failed to create EHB APB sysfs nodes\n"); in bt1_apb_init_sysfs()
341 ret = devm_add_action_or_reset(apb->dev, bt1_apb_remove_sysfs, apb); in bt1_apb_init_sysfs()
343 dev_err(apb->dev, "Can't add APB EHB sysfs remove action\n"); in bt1_apb_init_sysfs()
381 { .compatible = "baikal,bt1-apb" },
389 .name = "bt1-apb",
396 MODULE_DESCRIPTION("Baikal-T1 APB-bus driver");