From: Stefan Bosch <stefan_b@posteo.net>
To: u-boot@lists.denx.de
Subject: [PATCH v3 04/14] i2c: add nexell driver
Date: Mon, 6 Jul 2020 09:04:47 +0200 [thread overview]
Message-ID: <65fae6fc-b60f-eafe-2742-3d047cfde367@posteo.net> (raw)
In-Reply-To: <627bc0e4-ee39-f622-b0f0-a76c87c1af70@denx.de>
Hello Heiko,
thank you for your proposals. I'll make the appropriate changes.
Regards
Stefan
Am 03.07.20 um 08:03 schrieb Heiko Schocher:
> Hello Stefan,
>
> Am 29.06.2020 um 19:46 schrieb Stefan Bosch:
>> Changes in relation to FriendlyARM's U-Boot nanopi2-v2016.01:
>> - i2c/nx_i2c.c: Some adaptions mainly because of changes in
>> ?? "struct udevice".
>> - several Bugfixes in nx_i2c.c.
>> - the driver has been for s5p6818 only. Code extended appropriately
>> ?? in order s5p4418 is also working.
>> - "probe_chip" added.
>> - pinctrl-driver/dt is used instead of configuring the i2c I/O-pins
>> ?? in the i2c-driver.
>> - '#ifdef CONFIG...' changed to 'if (IS_ENABLED(CONFIG...))' where
>> ?? possible (and similar).
>> - livetree API (dev_read_...) is used instead of fdt one (fdt...).
>>
>> Signed-off-by: Stefan Bosch <stefan_b@posteo.net>
>
> Reviewed-by: Heiko Schocher <hs@denx.de>
>
> Nitpick only ...
>
> [...]
>> diff --git a/drivers/i2c/nx_i2c.c b/drivers/i2c/nx_i2c.c
>> new file mode 100644
>> index 0000000..cefc774
>> --- /dev/null
>> +++ b/drivers/i2c/nx_i2c.c
>> @@ -0,0 +1,624 @@
> [...]
>> +static uint i2c_set_clk(struct nx_i2c_bus *bus, uint enb)
>> +{
>> +??? struct clk *clk;
>> +??? char name[50];
>> +
>> +??? sprintf(name, "%s.%d", DEV_NAME_I2C, bus->bus_num);
>> +??? clk = clk_get((const char *)name);
>> +??? if (!clk) {
>> +??????? debug("%s(): clk_get(%s) error!\n",
>> +????????????? __func__, (const char *)name);
>> +??????? return -EINVAL;
>> +??? }
>> +
>> +??? if (enb) {
>> +??????? clk_disable(clk);
>> +??????? clk_enable(clk);
>> +??? } else {
>> +??????? clk_disable(clk);
>> +??? }
>
> You can do here:
>
> ????clk_disable(clk);
> ????if (enb)
> ??????? clk_enable(clk);
>
>> +
>> +??? return 0;
>> +}
>> +
>> +#ifdef CONFIG_ARCH_S5P6818
>> +/* Set SDA line delay, not available at S5P4418 */
>> +static int nx_i2c_set_sda_delay(struct nx_i2c_bus *bus)
>> +{
>> +??? struct nx_i2c_regs *i2c = bus->regs;
>> +??? uint pclk = 0;
>> +??? uint t_pclk = 0;
>> +??? uint delay = 0;
>> +
>> +??? /* get input clock of the I2C-controller */
>> +??? pclk = i2c_get_clkrate(bus);
>> +
>> +??? if (bus->sda_delay) {
>> +??????? /* t_pclk = period time of one pclk [ns] */
>> +??????? t_pclk = DIV_ROUND_UP(1000, pclk / 1000000);
>> +??????? /* delay = number of pclks required for sda_delay [ns] */
>> +??????? delay = DIV_ROUND_UP(bus->sda_delay, t_pclk);
>> +??????? /* delay = register value (step of 5 clocks) */
>> +??????? delay = DIV_ROUND_UP(delay, 5);
>> +??????? /* max. possible register value = 3 */
>> +??????? if (delay > 3) {
>
> May you use defines here?
>
>> +??????????? delay = 3;
>> +??????????? debug("%s(): sda-delay des.: %dns, sat. to max.: %dns
>> (granularity: %dns)\n",
>> +????????????????? __func__, bus->sda_delay, t_pclk * delay * 5,
>> +????????????????? t_pclk * 5);
>> +??????? } else {
>> +??????????? debug("%s(): sda-delay des.: %dns, act.: %dns
>> (granularity: %dns)\n",
>> +????????????????? __func__, bus->sda_delay, t_pclk * delay * 5,
>> +????????????????? t_pclk * 5);
>> +??????? }
>> +
>> +??????? delay |= I2CLC_FILTER;
>> +??? } else {
>> +??????? delay = 0;
>> +??????? debug("%s(): sda-delay = 0\n", __func__);
>> +??? }
>> +
>> +??? delay &= 0x7;
>> +??? writel(delay, &i2c->iiclc);
>> +
>> +??? return 0;
>> +}
>> +#endif
>> +
>> +static int nx_i2c_set_bus_speed(struct udevice *dev, uint speed)
>> +{
>> +??? struct nx_i2c_bus *bus = dev_get_priv(dev);
>> +??? struct nx_i2c_regs *i2c = bus->regs;
>> +??? unsigned long pclk, pres = 16, div;
>> +
>> +??? if (i2c_set_clk(bus, 1))
>> +??????? return -EINVAL;
>> +
>> +??? /* get input clock of the I2C-controller */
>> +??? pclk = i2c_get_clkrate(bus);
>> +
>> +??? /* calculate prescaler and divisor values */
>> +??? if ((pclk / pres / (16 + 1)) > speed)
>> +??????? /* set prescaler to 256 */
>> +??????? pres = 256;
>> +
>> +??? div = 0;
>> +??? /* actual divider = div + 1 */
>> +??? while ((pclk / pres / (div + 1)) > speed)
>> +??????? div++;
>> +
>> +??? if (div > 0xF) {
>> +??????? debug("%s(): pres==%ld, div==0x%lx is saturated to 0xF !)\n",
>> +????????????? __func__, pres, div);
>> +??????? div = 0xF;
>> +??? } else {
>> +??????? debug("%s(): pres==%ld, div==0x%lx)\n", __func__, pres, div);
>> +??? }
>> +
>> +??? /* set prescaler, divisor according to pclk, also set ACKGEN, IRQ */
>> +??? writel((div & 0x0F) | ((pres == 256) ? 0x40 : 0), &i2c->iiccon);
>
> Ok, I am really nitpicking now ... can you use defines here instead
> this magic values?
>
> [...]
>
> Thanks!
>
> bye,
> Heiko
next prev parent reply other threads:[~2020-07-06 7:04 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-29 17:46 [PATCH v3 00/14] arm: add support for SoC S5P4418 Stefan Bosch
2020-06-29 17:46 ` [PATCH v3 01/14] arm: add mach-nexell (header files) Stefan Bosch
2020-06-29 17:46 ` [PATCH v3 02/14] arm: add mach-nexell (all files except header files) Stefan Bosch
2020-06-29 17:46 ` [PATCH v3 03/14] gpio: add nexell driver Stefan Bosch
2020-06-29 17:46 ` [PATCH v3 04/14] i2c: " Stefan Bosch
2020-07-03 6:03 ` Heiko Schocher
2020-07-06 7:04 ` Stefan Bosch [this message]
2020-06-29 17:46 ` [PATCH v3 05/14] mmc: " Stefan Bosch
2020-06-29 17:46 ` [PATCH v3 06/14] pinctrl: " Stefan Bosch
2020-06-29 17:46 ` [PATCH v3 07/14] pwm: add driver for nexell Stefan Bosch
2020-06-29 17:46 ` [PATCH v3 08/14] video: add nexell video driver (soc: displaytop) Stefan Bosch
2020-06-29 17:46 ` [PATCH v3 09/14] video: add nexell video driver (soc: mlc, mipi) Stefan Bosch
2020-06-29 17:46 ` [PATCH v3 10/14] video: add nexell video driver (soc: lvds, hdmi) Stefan Bosch
2020-06-29 17:46 ` [PATCH v3 11/14] video: add nexell video driver (soc: dpc, makefile) Stefan Bosch
2020-06-29 17:46 ` [PATCH v3 12/14] video: add nexell video driver (display/video driver) Stefan Bosch
2020-06-29 17:46 ` [PATCH v3 13/14] arm: add support for SoC s5p4418 (cpu) / nanopi2 board Stefan Bosch
2020-06-29 17:46 ` [PATCH v3 14/14] arm: add (default) config for " Stefan Bosch
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=65fae6fc-b60f-eafe-2742-3d047cfde367@posteo.net \
--to=stefan_b@posteo.net \
--cc=u-boot@lists.denx.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