Lines Matching +full:bt1 +full:- +full:apb
1 // SPDX-License-Identifier: GPL-2.0-only
8 * Baikal-T1 APB-bus driver
37 * struct bt1_apb - Baikal-T1 APB EHB private data
39 * @regs: APB EHB registers map.
40 * @res: No-device error injection memory region.
42 * @rate: APB-bus reference clock rate.
43 * @pclk: APB-reference clock.
44 * @prst: APB domain reset line.
70 static inline unsigned long bt1_apb_n_to_timeout_us(struct bt1_apb *apb, u32 n) in bt1_apb_n_to_timeout_us() argument
74 do_div(timeout, apb->rate); in bt1_apb_n_to_timeout_us()
80 static inline unsigned long bt1_apb_timeout_to_n_us(struct bt1_apb *apb, in bt1_apb_timeout_to_n_us() argument
83 u64 n = (u64)timeout * apb->rate; in bt1_apb_timeout_to_n_us()
93 struct bt1_apb *apb = data; in bt1_apb_isr() local
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()
119 struct bt1_apb *apb = data; in bt1_apb_clear_data() local
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()
128 struct bt1_apb *apb; in bt1_apb_create_data() local
131 apb = devm_kzalloc(dev, sizeof(*apb), GFP_KERNEL); in bt1_apb_create_data()
132 if (!apb) in bt1_apb_create_data()
133 return ERR_PTR(-ENOMEM); in bt1_apb_create_data()
135 ret = devm_add_action(dev, bt1_apb_clear_data, apb); in bt1_apb_create_data()
137 dev_err(dev, "Can't add APB EHB data clear action\n"); 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()
143 platform_set_drvdata(pdev, apb); in bt1_apb_create_data()
145 return apb; in bt1_apb_create_data()
148 static int bt1_apb_request_regs(struct bt1_apb *apb) in bt1_apb_request_regs() argument
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()
172 static int bt1_apb_request_rst(struct bt1_apb *apb) in bt1_apb_request_rst() argument
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()
188 static int bt1_apb_request_clk(struct bt1_apb *apb) in bt1_apb_request_clk() argument
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()
193 "Couldn't get APB clock descriptor\n"); 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()
206 struct bt1_apb *apb = data; in bt1_apb_clear_irq() local
208 regmap_update_bits(apb->regs, APB_EHB_ISR, APB_EHB_ISR_MASK, 0); in bt1_apb_clear_irq()
211 static int bt1_apb_request_irq(struct bt1_apb *apb) in bt1_apb_request_irq() argument
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()
244 struct bt1_apb *apb = dev_get_drvdata(dev); in count_show() local
246 return scnprintf(buf, PAGE_SIZE, "%d\n", atomic_read(&apb->count)); in count_show()
253 struct bt1_apb *apb = dev_get_drvdata(dev); in timeout_show() local
258 ret = regmap_read(apb->regs, APB_EHB_TIMEOUT, &n); in timeout_show()
262 timeout = bt1_apb_n_to_timeout_us(apb, n); in timeout_show()
271 struct bt1_apb *apb = dev_get_drvdata(dev); in timeout_store() local
277 return -EINVAL; in timeout_store()
279 n = bt1_apb_timeout_to_n_us(apb, timeout); in timeout_store()
282 ret = regmap_write(apb->regs, APB_EHB_TIMEOUT, n); in timeout_store()
298 struct bt1_apb *apb = dev_get_drvdata(dev); in inject_error_store() local
301 * Either dummy read from the unmapped address in the APB IO area in inject_error_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()
326 struct bt1_apb *apb = data; in bt1_apb_remove_sysfs() local
328 device_remove_groups(apb->dev, bt1_apb_sysfs_groups); in bt1_apb_remove_sysfs()
331 static int bt1_apb_init_sysfs(struct bt1_apb *apb) in bt1_apb_init_sysfs() argument
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()
350 struct bt1_apb *apb; in bt1_apb_probe() local
353 apb = bt1_apb_create_data(pdev); in bt1_apb_probe()
354 if (IS_ERR(apb)) in bt1_apb_probe()
355 return PTR_ERR(apb); in bt1_apb_probe()
357 ret = bt1_apb_request_regs(apb); in bt1_apb_probe()
361 ret = bt1_apb_request_rst(apb); in bt1_apb_probe()
365 ret = bt1_apb_request_clk(apb); in bt1_apb_probe()
369 ret = bt1_apb_request_irq(apb); in bt1_apb_probe()
373 ret = bt1_apb_init_sysfs(apb); in bt1_apb_probe()
381 { .compatible = "baikal,bt1-apb" },
389 .name = "bt1-apb",
396 MODULE_DESCRIPTION("Baikal-T1 APB-bus driver");