From: Sascha Hauer <s.hauer@pengutronix.de>
To: Michael Grzeschik <m.grzeschik@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 2/3] mxs_spi: initial commit
Date: Tue, 5 Feb 2013 10:22:33 +0100 [thread overview]
Message-ID: <20130205092233.GR1906@pengutronix.de> (raw)
In-Reply-To: <1359998781-31956-3-git-send-email-m.grzeschik@pengutronix.de>
s/$subject/SPI: Add i.MX 23/28 SPI driver support/
On Mon, Feb 04, 2013 at 06:26:20PM +0100, Michael Grzeschik wrote:
> +
> +/*
> + * Set SSP/MMC bus frequency, in kHz
> + */
> +static void imx_set_ssp_busclock(struct spi_master *master, uint32_t freq)
> +{
> + struct mxs_spi *mxs = to_mxs(master);
> + const uint32_t sspclk = imx_get_sspclk(master->bus_num);
> + uint32_t val;
> + uint32_t divide, rate, tgtclk;
> +
> + /*
> + * SSP bit rate = SSPCLK / (CLOCK_DIVIDE * (1 + CLOCK_RATE)),
> + * CLOCK_DIVIDE has to be an even value from 2 to 254, and
> + * CLOCK_RATE could be any integer from 0 to 255.
> + */
> + for (divide = 2; divide < 254; divide += 2) {
> + rate = sspclk / freq / divide;
> + if (rate <= 256)
> + break;
> + }
> +
> + tgtclk = sspclk / divide / rate;
> + while (tgtclk > freq) {
> + rate++;
> + tgtclk = sspclk / divide / rate;
> + }
> + if (rate > 256)
> + rate = 256;
> +
> + /* Always set timeout the maximum */
> + val = SSP_TIMING_TIMEOUT_MASK |
> + SSP_TIMING_CLOCK_DIVIDE(divide) |
> + SSP_TIMING_CLOCK_RATE(rate - 1);
> + writel(val, mxs->regs + HW_SSP_TIMING);
> +
> + debug("SPI%d: Set freq rate to %d KHz (requested %d KHz)\n",
> + bus, tgtclk, freq);
Use dev_dbg, dev_info, dev_err throughout the driver please.
> +
> +static int mxs_spi_probe(struct device_d *dev)
> +{
> + struct spi_master *master;
> + struct mxs_spi *mxs;
> +
> + mxs = xzalloc(sizeof(*mxs));
> + if (!mxs)
> + return -ENOMEM;
xzalloc always returns memory.
> +
> + master = &mxs->master;
> + master->dev = dev;
> +
> + master->bus_num = dev->id;
> + master->setup = mxs_spi_setup;
> + master->transfer = mxs_spi_transfer;
> + master->num_chipselect = 3;
> + mxs->mode = SPI_CPOL | SPI_CPHA;
> +
> + mxs->regs = dev_request_mem_region(dev, 0);
> +
> + spi_register_master(master);
> +
> + return 0;
> +}
> +
> +static struct driver_d mxs_spi_driver = {
> + .name = "mxs_spi",
> + .probe = mxs_spi_probe,
> +};
> +
> +static int __init mxs_spi_init(void)
> +{
> + platform_driver_register(&mxs_spi_driver);
> + return 0;
return platform_driver_register(&mxs_spi_driver);
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2013-02-05 9:22 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-04 17:26 [PATCH 0/3] Add mxs spi driver and mx28evk as its first user Michael Grzeschik
2013-02-04 17:26 ` [PATCH 1/3] mxs: ssp move to common register layout Michael Grzeschik
2013-02-05 9:10 ` Sascha Hauer
2013-02-04 17:26 ` [PATCH 2/3] mxs_spi: initial commit Michael Grzeschik
2013-02-04 17:57 ` Alexander Aring
2013-02-04 18:15 ` Alexander Aring
2013-02-04 18:18 ` Alexander Aring
2013-02-05 9:22 ` Sascha Hauer [this message]
2013-02-04 17:26 ` [PATCH 3/3] mx28evk: add m25p80 flash via ssp2 Michael Grzeschik
2013-02-05 9:24 ` Sascha Hauer
-- strict thread matches above, loose matches on Subject: below --
2013-02-04 16:26 [PATCH 0/3] Add mxs spi driver and mx28evk as its first user Michael Grzeschik
2013-02-04 16:26 ` [PATCH 2/3] mxs_spi: initial commit Michael Grzeschik
2013-02-04 16:26 ` Michael Grzeschik
2013-02-04 17:10 ` Michael Grzeschik
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=20130205092233.GR1906@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=m.grzeschik@pengutronix.de \
/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