Lines Matching +full:ast2600 +full:- +full:lpc +full:- +full:snoop
1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Provides a simple driver to control the ASPEED LPC snoop interface which
7 * the host to an arbitrary LPC I/O port.
26 #define DEVICE_NAME "aspeed-lpc-snoop"
75 return container_of(file->private_data, in snoop_file_to_chan()
87 if (kfifo_is_empty(&chan->fifo)) { in snoop_file_read()
88 if (file->f_flags & O_NONBLOCK) in snoop_file_read()
89 return -EAGAIN; in snoop_file_read()
90 ret = wait_event_interruptible(chan->wq, in snoop_file_read()
91 !kfifo_is_empty(&chan->fifo)); in snoop_file_read()
92 if (ret == -ERESTARTSYS) in snoop_file_read()
93 return -EINTR; in snoop_file_read()
95 ret = kfifo_to_user(&chan->fifo, buffer, count, &copied); in snoop_file_read()
107 poll_wait(file, &chan->wq, pt); in snoop_file_poll()
108 return !kfifo_is_empty(&chan->fifo) ? EPOLLIN : 0; in snoop_file_poll()
121 if (!kfifo_initialized(&chan->fifo)) in put_fifo_with_discard()
123 if (kfifo_is_full(&chan->fifo)) in put_fifo_with_discard()
124 kfifo_skip(&chan->fifo); in put_fifo_with_discard()
125 kfifo_put(&chan->fifo, val); in put_fifo_with_discard()
126 wake_up_interruptible(&chan->wq); in put_fifo_with_discard()
134 if (regmap_read(lpc_snoop->regmap, HICR6, ®)) in aspeed_lpc_snoop_irq()
137 /* Check if one of the snoop channels is interrupting */ in aspeed_lpc_snoop_irq()
143 regmap_write(lpc_snoop->regmap, HICR6, reg); in aspeed_lpc_snoop_irq()
145 /* Read and save most recent snoop'ed data byte to FIFO */ in aspeed_lpc_snoop_irq()
146 regmap_read(lpc_snoop->regmap, SNPWDR, &data); in aspeed_lpc_snoop_irq()
151 put_fifo_with_discard(&lpc_snoop->chan[0], val); in aspeed_lpc_snoop_irq()
156 put_fifo_with_discard(&lpc_snoop->chan[1], val); in aspeed_lpc_snoop_irq()
165 struct device *dev = &pdev->dev; in aspeed_lpc_snoop_config_irq()
168 lpc_snoop->irq = platform_get_irq(pdev, 0); in aspeed_lpc_snoop_config_irq()
169 if (!lpc_snoop->irq) in aspeed_lpc_snoop_config_irq()
170 return -ENODEV; in aspeed_lpc_snoop_config_irq()
172 rc = devm_request_irq(dev, lpc_snoop->irq, in aspeed_lpc_snoop_config_irq()
176 dev_warn(dev, "Unable to request IRQ %d\n", lpc_snoop->irq); in aspeed_lpc_snoop_config_irq()
177 lpc_snoop->irq = 0; in aspeed_lpc_snoop_config_irq()
193 init_waitqueue_head(&lpc_snoop->chan[channel].wq); in aspeed_lpc_enable_snoop()
195 rc = kfifo_alloc(&lpc_snoop->chan[channel].fifo, in aspeed_lpc_enable_snoop()
200 lpc_snoop->chan[channel].miscdev.minor = MISC_DYNAMIC_MINOR; in aspeed_lpc_enable_snoop()
201 lpc_snoop->chan[channel].miscdev.name = in aspeed_lpc_enable_snoop()
203 lpc_snoop->chan[channel].miscdev.fops = &snoop_fops; in aspeed_lpc_enable_snoop()
204 lpc_snoop->chan[channel].miscdev.parent = dev; in aspeed_lpc_enable_snoop()
205 rc = misc_register(&lpc_snoop->chan[channel].miscdev); in aspeed_lpc_enable_snoop()
209 /* Enable LPC snoop channel at requested port */ in aspeed_lpc_enable_snoop()
224 return -EINVAL; in aspeed_lpc_enable_snoop()
227 regmap_update_bits(lpc_snoop->regmap, HICR5, hicr5_en, hicr5_en); in aspeed_lpc_enable_snoop()
228 regmap_update_bits(lpc_snoop->regmap, SNPWADR, snpwadr_mask, in aspeed_lpc_enable_snoop()
230 if (model_data->has_hicrb_ensnp) in aspeed_lpc_enable_snoop()
231 regmap_update_bits(lpc_snoop->regmap, HICRB, in aspeed_lpc_enable_snoop()
242 regmap_update_bits(lpc_snoop->regmap, HICR5, in aspeed_lpc_disable_snoop()
247 regmap_update_bits(lpc_snoop->regmap, HICR5, in aspeed_lpc_disable_snoop()
255 kfifo_free(&lpc_snoop->chan[channel].fifo); in aspeed_lpc_disable_snoop()
256 misc_deregister(&lpc_snoop->chan[channel].miscdev); in aspeed_lpc_disable_snoop()
267 dev = &pdev->dev; in aspeed_lpc_snoop_probe()
271 return -ENOMEM; in aspeed_lpc_snoop_probe()
273 np = pdev->dev.parent->of_node; in aspeed_lpc_snoop_probe()
274 if (!of_device_is_compatible(np, "aspeed,ast2400-lpc-v2") && in aspeed_lpc_snoop_probe()
275 !of_device_is_compatible(np, "aspeed,ast2500-lpc-v2") && in aspeed_lpc_snoop_probe()
276 !of_device_is_compatible(np, "aspeed,ast2600-lpc-v2")) { in aspeed_lpc_snoop_probe()
277 dev_err(dev, "unsupported LPC device binding\n"); in aspeed_lpc_snoop_probe()
278 return -ENODEV; in aspeed_lpc_snoop_probe()
281 lpc_snoop->regmap = syscon_node_to_regmap(np); in aspeed_lpc_snoop_probe()
282 if (IS_ERR(lpc_snoop->regmap)) { in aspeed_lpc_snoop_probe()
284 return -ENODEV; in aspeed_lpc_snoop_probe()
287 dev_set_drvdata(&pdev->dev, lpc_snoop); in aspeed_lpc_snoop_probe()
289 rc = of_property_read_u32_index(dev->of_node, "snoop-ports", 0, &port); in aspeed_lpc_snoop_probe()
291 dev_err(dev, "no snoop ports configured\n"); in aspeed_lpc_snoop_probe()
292 return -ENODEV; in aspeed_lpc_snoop_probe()
295 lpc_snoop->clk = devm_clk_get(dev, NULL); in aspeed_lpc_snoop_probe()
296 if (IS_ERR(lpc_snoop->clk)) { in aspeed_lpc_snoop_probe()
297 rc = PTR_ERR(lpc_snoop->clk); in aspeed_lpc_snoop_probe()
298 if (rc != -EPROBE_DEFER) in aspeed_lpc_snoop_probe()
302 rc = clk_prepare_enable(lpc_snoop->clk); in aspeed_lpc_snoop_probe()
316 /* Configuration of 2nd snoop channel port is optional */ in aspeed_lpc_snoop_probe()
317 if (of_property_read_u32_index(dev->of_node, "snoop-ports", in aspeed_lpc_snoop_probe()
329 clk_disable_unprepare(lpc_snoop->clk); in aspeed_lpc_snoop_probe()
336 struct aspeed_lpc_snoop *lpc_snoop = dev_get_drvdata(&pdev->dev); in aspeed_lpc_snoop_remove()
338 /* Disable both snoop channels */ in aspeed_lpc_snoop_remove()
342 clk_disable_unprepare(lpc_snoop->clk); in aspeed_lpc_snoop_remove()
354 { .compatible = "aspeed,ast2400-lpc-snoop",
356 { .compatible = "aspeed,ast2500-lpc-snoop",
358 { .compatible = "aspeed,ast2600-lpc-snoop",
377 MODULE_DESCRIPTION("Linux driver to control Aspeed LPC snoop functionality");