From: Marc Kleine-Budde <mkl@pengutronix.de>
To: Gerhard Bertelsmann <info@gerhard-bertelsmann.de>,
linux-can@vger.kernel.org
Subject: Re: [PATCH v3 2/2] Allwinner A10/A20 CAN Controller support
Date: Tue, 8 Sep 2015 13:00:52 +0200 [thread overview]
Message-ID: <55EEBFE4.8@pengutronix.de> (raw)
In-Reply-To: <1441376988-2384-3-git-send-email-info@gerhard-bertelsmann.de>
[-- Attachment #1: Type: text/plain, Size: 5241 bytes --]
On 09/04/2015 04:29 PM, Gerhard Bertelsmann wrote:
> This patch adds the Allwinner A10/A20 Kernel module
>
> Signed-off-by: Gerhard Bertelsmann < info@gerhard-bertelsmann.de >
^ ^
Please remove the space.
> Tested-by: Gerhard Bertelsmann < info@gerhard-bertelsmann.de >
Submitting a patch includes testing it :) You can remove that tag.
> +static int sunxican_probe(struct platform_device *pdev)
> +{
> + struct resource *res;
> + struct clk *clk;
> + void __iomem *addr;
> + int err, irq;
> + u32 temp_irqen;
> + struct net_device *dev;
> + struct sunxican_priv *priv;
> +
> + clk = clk_get(&pdev->dev, "apb1_can");
> + if (IS_ERR(clk)) {
> + dev_err(&pdev->dev, "no clock defined\n");
> + err = -ENODEV;
> + goto exit;
> + }
> + /* turn on clocking for CAN peripheral block */
> + err = clk_prepare_enable(clk);
> + if (err) {
> + dev_err(&pdev->dev, "could not enable clocking (apb1_can)\n");
> + goto exit;
> + }
> + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> + irq = platform_get_irq(pdev, 0);
> +
> + if (!res || irq <= 0) {
> + dev_err(&pdev->dev, "could not get a valid irq\n");
> + err = -ENODEV;
> + goto exit_put;
> + }
> + if (!request_mem_region(res->start, resource_size(res), pdev->name)) {
> + dev_err(&pdev->dev, "could not get io memory resource\n");
> + err = -EBUSY;
> + goto exit_put;
> + }
> + addr = ioremap_nocache(res->start, resource_size(res));
> + if (!addr) {
> + dev_err(&pdev->dev, "could not map io memory\n");
> + err = -ENOMEM;
> + goto exit_release;
> + }
> + dev = alloc_candev(sizeof(struct sunxican_priv), 1);
> +
> + if (!dev) {
> + dev_err(&pdev->dev,
> + "could not allocate memory for CAN device\n");
> + err = -ENOMEM;
> + goto exit_iounmap;
> + }
> +
> + dev->netdev_ops = &sunxican_netdev_ops;
> + dev->irq = irq;
> + dev->flags |= IFF_ECHO;
> +
> + priv = netdev_priv(dev);
> + priv->can.clock.freq = clk_get_rate(clk);
> + priv->can.bittiming_const = &sunxican_bittiming_const;
> + priv->can.do_set_bittiming = sunxican_set_bittiming;
Please don't do this, call set_bittiming during open();
> + priv->can.do_set_mode = sunxican_set_mode;
> + priv->can.do_get_berr_counter = sunxican_get_berr_counter;
> + priv->can.ctrlmode_supported = CAN_CTRLMODE_BERR_REPORTING |
> + CAN_CTRLMODE_LISTENONLY |
> + CAN_CTRLMODE_LOOPBACK |
> + CAN_CTRLMODE_3_SAMPLES;
> + priv->base = addr;
> + priv->clk = clk;
> + spin_lock_init(&priv->cmdreg_lock);
> +
> + /* enable CAN specific interrupts */
> + set_reset_mode(dev);
> + temp_irqen = BERR_IRQ_EN | ERR_PASSIVE_IRQ_EN | OR_IRQ_EN | RX_IRQ_EN;
> + writel(readl(priv->base + CAN_INTEN_ADDR) | temp_irqen,
> + priv->base + CAN_INTEN_ADDR);
> +
> + platform_set_drvdata(pdev, dev);
> + SET_NETDEV_DEV(dev, &pdev->dev);
> +
> + err = register_candev(dev);
> + if (err) {
> + dev_err(&pdev->dev, "registering %s failed (err=%d)\n",
> + DRV_NAME, err);
> + goto exit_free;
> + }
> + devm_can_led_init(dev);
> +
> + dev_info(&pdev->dev, "device registered (base=%p, irq=%d)\n",
> + priv->base, dev->irq);
> +
> + return 0;
> +
> +exit_free:
> + free_candev(dev);
> +exit_iounmap:
> + iounmap(addr);
> +exit_release:
> + release_mem_region(res->start, resource_size(res));
> +exit_put:
> + clk_put(clk);
> +exit:
> + return err;
> +}
> +
> +static int __maybe_unused sunxi_can_suspend(struct device *device)
> +{
> + struct net_device *dev = dev_get_drvdata(device);
> + struct sunxican_priv *priv = netdev_priv(dev);
> +
> + if (netif_running(dev)) {
> + netif_stop_queue(dev);
> + netif_device_detach(dev);
> + }
> + priv->can.state = CAN_STATE_SLEEPING;
> +
> + return 0;
> +}
> +
> +static int __maybe_unused sunxi_can_resume(struct device *device)
> +{
> + struct net_device *dev = dev_get_drvdata(device);
> + struct sunxican_priv *priv = netdev_priv(dev);
> +
> + priv->can.state = CAN_STATE_ERROR_ACTIVE;
> + if (netif_running(dev)) {
> + netif_device_attach(dev);
> + netif_start_queue(dev);
> + }
> + return 0;
> +}
> +
> +static SIMPLE_DEV_PM_OPS(sunxi_can_pm_ops, sunxi_can_suspend, sunxi_can_resume);
> +
> +static struct platform_driver sunxi_can_driver = {
> + .driver = {
> + .name = DRV_NAME,
> + .owner = THIS_MODULE,
> + .pm = &sunxi_can_pm_ops,
> + .of_match_table = sunxican_of_match,
> + },
> + .probe = sunxican_probe,
> + .remove = sunxican_remove,
> + .id_table = sunxican_id_table,
> +};
> +
> +module_platform_driver(sunxi_can_driver);
> +
> +MODULE_AUTHOR("Peter Chen <xingkongcp@gmail.com>");
> +MODULE_AUTHOR("Gerhard Bertelsmann <info@gerhard-bertelsmann.de>");
> +MODULE_LICENSE("Dual BSD/GPL");
> +MODULE_DESCRIPTION(DRV_NAME "CAN driver for Allwinner SoCs (A10/A20)");
> +MODULE_VERSION(DRV_MODULE_VERSION);
> +
Marc
--
Pengutronix e.K. | Marc Kleine-Budde |
Industrial Linux Solutions | Phone: +49-231-2826-924 |
Vertretung West/Dortmund | Fax: +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de |
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 455 bytes --]
prev parent reply other threads:[~2015-09-08 11:00 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-04 14:29 [PATCH v3 0/2] Allwinner A10/A20 CAN Controller support Gerhard Bertelsmann
2015-09-04 14:29 ` [PATCH v3 1/2] " Gerhard Bertelsmann
2015-09-04 14:29 ` [PATCH v3 2/2] " Gerhard Bertelsmann
2015-09-05 18:37 ` Mirza Krak
2015-09-07 16:25 ` Gerhard Bertelsmann
2015-09-07 17:18 ` Mirza Krak
2015-09-08 11:00 ` Marc Kleine-Budde [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=55EEBFE4.8@pengutronix.de \
--to=mkl@pengutronix.de \
--cc=info@gerhard-bertelsmann.de \
--cc=linux-can@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).