Skip to contentSkip to conversation

arm: add support for SoC S5P4418

RFC PATCH New Stefan Bosch 4 participants 19 messages Feb 3, 2020 – Feb 25, 2020

Subsystems (7)
lore
Share & tools
lore
#0 lore raw

cover arm: add support for SoC S5P4418

This patch adds support for SAMSUNG's/NEXELL's ARM Cortex-A9 based S5P4418 SoC, especially FriendlyARM's NanoPi2 and NanoPC-T2 boards. It is based on the following FriendlyARM's U-Boot version:
https://github.com/friendlyarm/u-boot/tree/nanopi2-v2016.01.

The added mach-nexell also supports the S5P6818 SoC which is a follow-up of the S5P4418.

Main changes in relation to nanopi2-v2016.01:
- Cosmetic changes due to patman warnings/errors.
- MMC and Video drivers changed to DM.
- Configs reworked (e.g. "CONFIG_..." moved from s5p4418_nanopi2.h to s5p4418_nanopi2_defconfig)
- SPL related files are not included.
- MACH_TYPE_S5P4418 is not defined/used anymore.
- arch/arm/mach-nexell/include/mach/boot0.h added to generate the NSIH (Nexell System Information Header), substitudes tools/nexell.
- board/s5p4418/ renamed to board/friendlyarm/
- Only the NanoPi2 and NanoPC-T2 boards are supported yet because I do only have the NanoPC-T2 board to test the code (this board uses the NanoPi2 code).

Stefan Bosch (10):
arm: add mach-nexell (header files)
arm: add mach-nexell (all files except header files)
i2c: mmc: add nexell driver (gpio, i2c, mmc, pwm)
video: add nexell video driver (soc: displaytop)
video: add nexell video driver (soc: mlc, mipi)
video: add nexell video driver (soc: lvds, hdmi)
video: add nexell video driver (soc: dpc, makefile)
video: add nexell video driver (display/video driver)
arm: add support for SoC s5p4418 (cpu) / nanopi2 board
arm: add (default) config for nanopi2 board

 MAINTAINERS                                        |   19 +
 arch/arm/Kconfig                                   |    7 +
 arch/arm/Makefile                                  |    1 +
 arch/arm/cpu/armv7/Makefile                        |    1 +
 arch/arm/cpu/armv7/s5p4418/Makefile                |    6 +
 arch/arm/cpu/armv7/s5p4418/cpu.c                   |  120 ++
 arch/arm/dts/Makefile                              |    3 +
 arch/arm/dts/s5p4418-nanopi2.dts                   |  109 ++
 arch/arm/dts/s5p4418-pinctrl.dtsi                  |   66 +
 arch/arm/dts/s5p4418.dtsi                          |  157 ++
 arch/arm/mach-nexell/Kconfig                       |   67 +
 arch/arm/mach-nexell/Makefile                      |   15 +
 arch/arm/mach-nexell/clock.c                       |  869 +++++++++
 arch/arm/mach-nexell/cmd_boot_linux.c              |  145 ++
 arch/arm/mach-nexell/config.mk                     |   11 +
 arch/arm/mach-nexell/include/mach/boot0.h          |   40 +
 arch/arm/mach-nexell/include/mach/clk.h            |   24 +
 arch/arm/mach-nexell/include/mach/display.h        |  273 +++
 arch/arm/mach-nexell/include/mach/display_dev.h    |   37 +
 arch/arm/mach-nexell/include/mach/ehci.h           |  106 ++
 arch/arm/mach-nexell/include/mach/gpio.h           |   17 +
 arch/arm/mach-nexell/include/mach/mipi_display.h   |  219 +++
 arch/arm/mach-nexell/include/mach/nexell.h         |  352 ++++
 arch/arm/mach-nexell/include/mach/nx_gpio.h        |  103 ++
 arch/arm/mach-nexell/include/mach/reset.h          |   19 +
 arch/arm/mach-nexell/include/mach/sec_reg.h        |   15 +
 arch/arm/mach-nexell/include/mach/tieoff.h         |  423 +++++
 arch/arm/mach-nexell/nx_gpio.c                     |  352 ++++
 arch/arm/mach-nexell/nx_sec_reg.c                  |   82 +
 arch/arm/mach-nexell/reg-call.S                    |   23 +
 arch/arm/mach-nexell/reset.c                       |   33 +
 arch/arm/mach-nexell/serial.c                      |  262 +++
 arch/arm/mach-nexell/tieoff.c                      |  109 ++
 arch/arm/mach-nexell/timer.c                       |  297 ++++
 board/friendlyarm/Kconfig                          |   39 +
 board/friendlyarm/nanopi2/Kconfig                  |   12 +
 board/friendlyarm/nanopi2/MAINTAINERS              |    7 +
 board/friendlyarm/nanopi2/Makefile                 |    6 +
 board/friendlyarm/nanopi2/board.c                  |  581 ++++++
 board/friendlyarm/nanopi2/hwrev.c                  |  122 ++
 board/friendlyarm/nanopi2/hwrev.h                  |   29 +
 board/friendlyarm/nanopi2/lcds.c                   |  703 ++++++++
 board/friendlyarm/nanopi2/nxp-fb.h                 |   99 ++
 board/friendlyarm/nanopi2/onewire.c                |  323 ++++
 board/friendlyarm/nanopi2/onewire.h                |   29 +
 configs/s5p4418_nanopi2_defconfig                  |  177 ++
 doc/README.s5p4418                                 |   63 +
 drivers/gpio/Kconfig                               |    9 +
 drivers/gpio/Makefile                              |    1 +
 drivers/gpio/nx_gpio.c                             |  252 +++
 drivers/i2c/Kconfig                                |    9 +
 drivers/i2c/Makefile                               |    1 +
 drivers/i2c/nx_i2c.c                               |  537 ++++++
 drivers/mmc/Kconfig                                |    6 +
 drivers/mmc/Makefile                               |    1 +
 drivers/mmc/nexell_dw_mmc_dm.c                     |  350 ++++
 drivers/pwm/Makefile                               |    1 +
 drivers/pwm/pwm-nexell.c                           |  252 +++
 drivers/pwm/pwm-nexell.h                           |   54 +
 drivers/video/Kconfig                              |   10 +
 drivers/video/Makefile                             |    1 +
 drivers/video/nexell/Kconfig                       |   27 +
 drivers/video/nexell/Makefile                      |   12 +
 drivers/video/nexell/s5pxx18_dp.c                  |  338 ++++
 drivers/video/nexell/s5pxx18_dp_hdmi.c             |  543 ++++++
 drivers/video/nexell/s5pxx18_dp_lvds.c             |  274 +++
 drivers/video/nexell/s5pxx18_dp_mipi.c             |  677 +++++++
 drivers/video/nexell/s5pxx18_dp_rgb.c              |   69 +
 drivers/video/nexell/soc/Makefile                  |   11 +
 drivers/video/nexell/soc/s5pxx18_soc_disptop.c     |  185 ++
 drivers/video/nexell/soc/s5pxx18_soc_disptop.h     |  385 ++++
 drivers/video/nexell/soc/s5pxx18_soc_disptop_clk.c |  309 ++++
 drivers/video/nexell/soc/s5pxx18_soc_disptop_clk.h |   59 +
 drivers/video/nexell/soc/s5pxx18_soc_disptype.h    |   23 +
 drivers/video/nexell/soc/s5pxx18_soc_dpc.c         | 1569 +++++++++++++++++
 drivers/video/nexell/soc/s5pxx18_soc_dpc.h         |  444 +++++
 drivers/video/nexell/soc/s5pxx18_soc_hdmi.c        |   50 +
 drivers/video/nexell/soc/s5pxx18_soc_hdmi.h        |  488 +++++
 drivers/video/nexell/soc/s5pxx18_soc_lvds.c        |  278 +++
 drivers/video/nexell/soc/s5pxx18_soc_lvds.h        |   83 +
 drivers/video/nexell/soc/s5pxx18_soc_mipi.c        |  580 ++++++
 drivers/video/nexell/soc/s5pxx18_soc_mipi.h        |  291 +++
 drivers/video/nexell/soc/s5pxx18_soc_mlc.c         | 1861 ++++++++++++++++++++
 drivers/video/nexell/soc/s5pxx18_soc_mlc.h         |  429 +++++
 drivers/video/nexell_display.c                     |  658 +++++++
 include/configs/s5p4418_nanopi2.h                  |  270 +++
 86 files changed, 17969 insertions(+)
 create mode 100644 arch/arm/cpu/armv7/s5p4418/Makefile
 create mode 100644 arch/arm/cpu/armv7/s5p4418/cpu.c
 create mode 100644 arch/arm/dts/s5p4418-nanopi2.dts
 create mode 100644 arch/arm/dts/s5p4418-pinctrl.dtsi
 create mode 100644 arch/arm/dts/s5p4418.dtsi
 create mode 100644 arch/arm/mach-nexell/Kconfig
 create mode 100644 arch/arm/mach-nexell/Makefile
 create mode 100644 arch/arm/mach-nexell/clock.c
 create mode 100644 arch/arm/mach-nexell/cmd_boot_linux.c
 create mode 100644 arch/arm/mach-nexell/config.mk
 create mode 100644 arch/arm/mach-nexell/include/mach/boot0.h
 create mode 100644 arch/arm/mach-nexell/include/mach/clk.h
 create mode 100644 arch/arm/mach-nexell/include/mach/display.h
 create mode 100644 arch/arm/mach-nexell/include/mach/display_dev.h
 create mode 100644 arch/arm/mach-nexell/include/mach/ehci.h
 create mode 100644 arch/arm/mach-nexell/include/mach/gpio.h
 create mode 100644 arch/arm/mach-nexell/include/mach/mipi_display.h
 create mode 100644 arch/arm/mach-nexell/include/mach/nexell.h
 create mode 100644 arch/arm/mach-nexell/include/mach/nx_gpio.h
 create mode 100644 arch/arm/mach-nexell/include/mach/reset.h
 create mode 100644 arch/arm/mach-nexell/include/mach/sec_reg.h
 create mode 100644 arch/arm/mach-nexell/include/mach/tieoff.h
 create mode 100644 arch/arm/mach-nexell/nx_gpio.c
 create mode 100644 arch/arm/mach-nexell/nx_sec_reg.c
 create mode 100644 arch/arm/mach-nexell/reg-call.S
 create mode 100644 arch/arm/mach-nexell/reset.c
 create mode 100644 arch/arm/mach-nexell/serial.c
 create mode 100644 arch/arm/mach-nexell/tieoff.c
 create mode 100644 arch/arm/mach-nexell/timer.c
 create mode 100644 board/friendlyarm/Kconfig
 create mode 100644 board/friendlyarm/nanopi2/Kconfig
 create mode 100644 board/friendlyarm/nanopi2/MAINTAINERS
 create mode 100644 board/friendlyarm/nanopi2/Makefile
 create mode 100644 board/friendlyarm/nanopi2/board.c
 create mode 100644 board/friendlyarm/nanopi2/hwrev.c
 create mode 100644 board/friendlyarm/nanopi2/hwrev.h
 create mode 100644 board/friendlyarm/nanopi2/lcds.c
 create mode 100644 board/friendlyarm/nanopi2/nxp-fb.h
 create mode 100644 board/friendlyarm/nanopi2/onewire.c
 create mode 100644 board/friendlyarm/nanopi2/onewire.h
 create mode 100644 configs/s5p4418_nanopi2_defconfig
 create mode 100644 doc/README.s5p4418
 create mode 100644 drivers/gpio/nx_gpio.c
 create mode 100644 drivers/i2c/nx_i2c.c
 create mode 100644 drivers/mmc/nexell_dw_mmc_dm.c
 create mode 100644 drivers/pwm/pwm-nexell.c
 create mode 100644 drivers/pwm/pwm-nexell.h
 create mode 100644 drivers/video/nexell/Kconfig
 create mode 100644 drivers/video/nexell/Makefile
 create mode 100644 drivers/video/nexell/s5pxx18_dp.c
 create mode 100644 drivers/video/nexell/s5pxx18_dp_hdmi.c
 create mode 100644 drivers/video/nexell/s5pxx18_dp_lvds.c
 create mode 100644 drivers/video/nexell/s5pxx18_dp_mipi.c
 create mode 100644 drivers/video/nexell/s5pxx18_dp_rgb.c
 create mode 100644 drivers/video/nexell/soc/Makefile
 create mode 100644 drivers/video/nexell/soc/s5pxx18_soc_disptop.c
 create mode 100644 drivers/video/nexell/soc/s5pxx18_soc_disptop.h
 create mode 100644 drivers/video/nexell/soc/s5pxx18_soc_disptop_clk.c
 create mode 100644 drivers/video/nexell/soc/s5pxx18_soc_disptop_clk.h
 create mode 100644 drivers/video/nexell/soc/s5pxx18_soc_disptype.h
 create mode 100644 drivers/video/nexell/soc/s5pxx18_soc_dpc.c
 create mode 100644 drivers/video/nexell/soc/s5pxx18_soc_dpc.h
 create mode 100644 drivers/video/nexell/soc/s5pxx18_soc_hdmi.c
 create mode 100644 drivers/video/nexell/soc/s5pxx18_soc_hdmi.h
 create mode 100644 drivers/video/nexell/soc/s5pxx18_soc_lvds.c
 create mode 100644 drivers/video/nexell/soc/s5pxx18_soc_lvds.h
 create mode 100644 drivers/video/nexell/soc/s5pxx18_soc_mipi.c
 create mode 100644 drivers/video/nexell/soc/s5pxx18_soc_mipi.h
 create mode 100644 drivers/video/nexell/soc/s5pxx18_soc_mlc.c
 create mode 100644 drivers/video/nexell/soc/s5pxx18_soc_mlc.h
 create mode 100644 drivers/video/nexell_display.c
 create mode 100644 include/configs/s5p4418_nanopi2.h
Signature · 1 line
1.9.1
#1 lore raw

RFC PATCH 1/10 arm: add mach-nexell (header files)

Changes in relation to FriendlyARM's U-Boot nanopi2-v2016.01:
- DM_VIDEO support (display_dev.h).
- boot0.h added, handles NSIH --> tools/nexell obsolete.
- gpio.h: Include-path to errno.h changed.

---

 arch/arm/mach-nexell/include/mach/boot0.h        |  40 +++
 arch/arm/mach-nexell/include/mach/clk.h          |  24 ++
 arch/arm/mach-nexell/include/mach/display.h      | 273 +++++++++++++++
 arch/arm/mach-nexell/include/mach/display_dev.h  |  37 ++
 arch/arm/mach-nexell/include/mach/ehci.h         | 106 ++++++
 arch/arm/mach-nexell/include/mach/gpio.h         |  17 +
 arch/arm/mach-nexell/include/mach/mipi_display.h | 219 ++++++++++++
 arch/arm/mach-nexell/include/mach/nexell.h       | 352 +++++++++++++++++++
 arch/arm/mach-nexell/include/mach/nx_gpio.h      | 103 ++++++
 arch/arm/mach-nexell/include/mach/reset.h        |  19 +
 arch/arm/mach-nexell/include/mach/sec_reg.h      |  15 +
 arch/arm/mach-nexell/include/mach/tieoff.h       | 423 +++++++++++++++++++++++
 12 files changed, 1628 insertions(+)
 create mode 100644 arch/arm/mach-nexell/include/mach/boot0.h
 create mode 100644 arch/arm/mach-nexell/include/mach/clk.h
 create mode 100644 arch/arm/mach-nexell/include/mach/display.h
 create mode 100644 arch/arm/mach-nexell/include/mach/display_dev.h
 create mode 100644 arch/arm/mach-nexell/include/mach/ehci.h
 create mode 100644 arch/arm/mach-nexell/include/mach/gpio.h
 create mode 100644 arch/arm/mach-nexell/include/mach/mipi_display.h
 create mode 100644 arch/arm/mach-nexell/include/mach/nexell.h
 create mode 100644 arch/arm/mach-nexell/include/mach/nx_gpio.h
 create mode 100644 arch/arm/mach-nexell/include/mach/reset.h
 create mode 100644 arch/arm/mach-nexell/include/mach/sec_reg.h
 create mode 100644 arch/arm/mach-nexell/include/mach/tieoff.h
arch/arm/mach-nexell/include/mach/boot0.h new file +40 -0
new file mode 100644
index 0000000..e05c07e
@@ -0,0 +1,40 @@
+/* SPDX-License-Identifier: GPL-2.0+
+ *
+ * NSIH (Nexell System Information Header) for FriendlyArm nanopi2 board
+ *
+ * The NSIH (first 512 Bytes of u-boot.bin) is necessary for the
+ * 2nd-Bootloader to get information like load address of U-Boot.
+ *
+ * 0x400 must be added to CONFIG_SYS_TEXT_BASE to have the actual load and
+ * start address because 2nd-Bootloader loads with an offset of 0x400
+ * (NSIH + 0x200 bytes are not loaded into RAM).
+ *
+ * It has been tested / is working with the following 2nd-Bootloader:
+ * "BL1 by Nexell V1.0.0-gd551e13 [Built on 2018-01-25 16:58:29]"
+ *
+ * (C) Copyright 2020 Stefan Bosch <[email protected]>
+ */
+
+#ifndef __BOOT0_H
+#define __BOOT0_H
+
+	ARM_VECTORS
+	.space	0x30
+	.word	(_end - _start) + 20 * 1024	/* 0x50: load size
+						 *       (bin + 20k for DTB) */
+	.space	0x4
+	.word	CONFIG_SYS_TEXT_BASE + 0x400	/* 0x58: load address */
+	.word	0x00000000
+	.word	CONFIG_SYS_TEXT_BASE + 0x400	/* 0x60: start address */
+	.space	0x198
+	.byte	'N'				/* 0x1FC: "NSIH" signature */
+	.byte	'S'
+	.byte	'I'
+	.byte	'H'
+
+	/* The NSIH + 0x200 bytes are omitted by the 2nd-Bootloader */
+	.space	0x200
+_start:
+	ARM_VECTORS
+
+#endif /* __BOOT0_H */
arch/arm/mach-nexell/include/mach/clk.h new file +24 -0
new file mode 100644
index 0000000..cc5589a
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: GPL-2.0+
+ *
+ * (C) Copyright 2016 Nexell
+ * Hyunseok, Jung <[email protected]>
+ */
+
+#ifndef __ASM_ARM_ARCH_CLK_H_
+#define __ASM_ARM_ARCH_CLK_H_
+
+struct clk {
+	unsigned long rate;
+};
+
+void clk_init(void);
+
+struct clk *clk_get(const char *id);
+void clk_put(struct clk *clk);
+unsigned long clk_get_rate(struct clk *clk);
+long clk_round_rate(struct clk *clk, unsigned long rate);
+int clk_set_rate(struct clk *clk, unsigned long rate);
+int clk_enable(struct clk *clk);
+void clk_disable(struct clk *clk);
+
+#endif
arch/arm/mach-nexell/include/mach/display.h new file +273 -0

273 lines not on this page · raw message

arch/arm/mach-nexell/include/mach/display_dev.h new file +37 -0
new file mode 100644
index 0000000..77eb614
@@ -0,0 +1,37 @@
+/* SPDX-License-Identifier: GPL-2.0+
+ *
+ * Copyright (C) 2016  Nexell Co., Ltd.
+ *
+ * Author: junghyun, kim <[email protected]>
+ */
+
+#ifndef _NX__DISPLAY_DEV_H_
+#define _NX__DISPLAY_DEV_H_
+
+#if defined CONFIG_VIDEO || defined CONFIG_DM_VIDEO
+#include <video_fb.h>
+#elif defined CONFIG_LCD
+#include <lcd.h>
+#endif
+
+struct nx_display_dev {
+#if defined CONFIG_VIDEO || defined CONFIG_DM_VIDEO
+	GraphicDevice graphic_device;
+#elif defined CONFIG_LCD
+	vidinfo_t *panel_info;
+#endif
+	unsigned long base;
+	int module;
+	struct dp_sync_info sync;
+	struct dp_ctrl_info ctrl;
+	struct dp_plane_top top;
+	struct dp_plane_info planes[DP_PLANS_NUM];
+	int dev_type;
+	void *device;
+	struct dp_plane_info *fb_plane;
+	unsigned int depth;	/* byte per pixel */
+	unsigned int fb_addr;
+	unsigned int fb_size;
+};
+
+#endif
arch/arm/mach-nexell/include/mach/ehci.h new file +106 -0

106 lines not on this page · raw message

arch/arm/mach-nexell/include/mach/gpio.h new file +17 -0
new file mode 100644
index 0000000..7167d3c
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0+
+ *
+ * (C) Copyright 2016 Nexell
+ * DeokJin, Lee <[email protected]>
+ */
+
+#ifndef __ASM_ARCH_NEXELL_GPIO_H
+#define __ASM_ARCH_NEXELL_GPIO_H
+
+#include <asm/io.h>
+#include <linux/errno.h>
+
+#define PIN_BASE		0
+
+#define MAX_GPIO_BANKS		5
+
+#endif /* __ASM_ARCH_NEXELL_GPIO_H */
arch/arm/mach-nexell/include/mach/mipi_display.h new file +219 -0

219 lines not on this page · raw message

arch/arm/mach-nexell/include/mach/nexell.h new file +352 -0

352 lines not on this page · raw message

arch/arm/mach-nexell/include/mach/nx_gpio.h new file +103 -0

103 lines not on this page · raw message

arch/arm/mach-nexell/include/mach/reset.h new file +19 -0
new file mode 100644
index 0000000..e1301d4
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: GPL-2.0+
+ *
+ * (C) Copyright 2016 Nexell
+ * Youngbok, Park <[email protected]>
+ */
+
+#ifndef __NEXELL_RESET__
+#define __NEXELL_RESET__
+
+#define NUMBER_OF_RESET_MODULE_PIN      69
+
+enum rstcon {
+	RSTCON_ASSERT	= 0UL,
+	RSTCON_NEGATE	= 1UL
+};
+
+void nx_rstcon_setrst(u32 rstindex, enum rstcon status);
+
+#endif /* __NEXELL_RESET__ */
arch/arm/mach-nexell/include/mach/sec_reg.h new file +15 -0
new file mode 100644
index 0000000..e3ae5ac
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0+
+ *
+ * (C) Copyright 2016 Nexell
+ * Youngbok, Park <[email protected]>
+ */
+
+#define NEXELL_L2C_SEC_ID	0
+#define NEXELL_MALI_SEC_ID	2
+#define NEXELL_MIPI_SEC_ID	4
+#define NEXELL_TOFF_SEC_ID	6
+
+int write_sec_reg_by_id(void __iomem *reg, int val, int id);
+int read_sec_reg_by_id(void __iomem *reg, int id);
+int read_sec_reg(void __iomem *reg);
+int write_sec_reg(void __iomem *reg, int val);
arch/arm/mach-nexell/include/mach/tieoff.h new file +423 -0

423 lines not on this page · raw message

Signature · 1 line
1.9.1
#2 lore raw

RFC PATCH 2/10 arm: add mach-nexell (all files except header files)

In reply to Stefan Bosch

Changes in relation to FriendlyARM's U-Boot nanopi2-v2016.01:
- SPL not supported yet --> no spl-directory in arch/arm/mach-nexell. Appropriate line in Makefile removed.
- clock.c: 'section(".data")' added to declaration of clk_periphs[] and core_hz.
- Kconfig: Changes to have a structure like in mach-bcm283x/Kconfig, e.g. "config ..." entries moved from other Kconfig.
- timer.c: 'section(".data")' added to declaration of timestamp and lastdec.

---

 arch/arm/Kconfig                      |   7 +
 arch/arm/Makefile                     |   1 +
 arch/arm/mach-nexell/Kconfig          |  67 +++
 arch/arm/mach-nexell/Makefile         |  15 +
 arch/arm/mach-nexell/clock.c          | 869 ++++++++++++++++++++++++++++++++++
 arch/arm/mach-nexell/cmd_boot_linux.c | 145 ++++++
 arch/arm/mach-nexell/config.mk        |  11 +
 arch/arm/mach-nexell/nx_gpio.c        | 352 ++++++++++++++
 arch/arm/mach-nexell/nx_sec_reg.c     |  82 ++++
 arch/arm/mach-nexell/reg-call.S       |  23 +
 arch/arm/mach-nexell/reset.c          |  33 ++
 arch/arm/mach-nexell/serial.c         | 262 ++++++++++
 arch/arm/mach-nexell/tieoff.c         | 109 +++++
 arch/arm/mach-nexell/timer.c          | 297 ++++++++++++
 14 files changed, 2273 insertions(+)
 create mode 100644 arch/arm/mach-nexell/Kconfig
 create mode 100644 arch/arm/mach-nexell/Makefile
 create mode 100644 arch/arm/mach-nexell/clock.c
 create mode 100644 arch/arm/mach-nexell/cmd_boot_linux.c
 create mode 100644 arch/arm/mach-nexell/config.mk
 create mode 100644 arch/arm/mach-nexell/nx_gpio.c
 create mode 100644 arch/arm/mach-nexell/nx_sec_reg.c
 create mode 100644 arch/arm/mach-nexell/reg-call.S
 create mode 100644 arch/arm/mach-nexell/reset.c
 create mode 100644 arch/arm/mach-nexell/serial.c
 create mode 100644 arch/arm/mach-nexell/tieoff.c
 create mode 100644 arch/arm/mach-nexell/timer.c
arch/arm/Kconfig +7 -0
index a623ef5..469aa65 100644
@@ -875,6 +875,11 @@ config ARCH_MX5
 	select CPU_V7A
 	imply MXC_GPIO
 
+config ARCH_NEXELL
+	bool "Nexell S5P4418/S5P6818 SoC"
+	select ENABLE_ARM_SOC_BOOT0_HOOK
+	select DM
+
 config ARCH_OWL
 	bool "Actions Semi OWL SoCs"
 	select ARM64
@@ -1797,6 +1802,8 @@ source "arch/arm/cpu/armv8/Kconfig"
 
 source "arch/arm/mach-imx/Kconfig"
 
+source "arch/arm/mach-nexell/Kconfig"
+
 source "board/bosch/shc/Kconfig"
 source "board/bosch/guardian/Kconfig"
 source "board/CarMediaLab/flea3/Kconfig"
arch/arm/Makefile +1 -0
index 1e60a9f..5a390b8 100644
@@ -67,6 +67,7 @@ machine-$(CONFIG_ARCH_MESON)		+= meson
 machine-$(CONFIG_ARCH_MVEBU)		+= mvebu
 # TODO: rename CONFIG_TEGRA -> CONFIG_ARCH_TEGRA
 # TODO: rename CONFIG_ORION5X -> CONFIG_ARCH_ORION5X
+machine-$(CONFIG_ARCH_NEXELL)		+= nexell
 machine-$(CONFIG_ORION5X)		+= orion5x
 machine-$(CONFIG_ARCH_OMAP2PLUS)	+= omap2
 machine-$(CONFIG_ARCH_OWL)		+= owl
arch/arm/mach-nexell/Kconfig new file +67 -0

67 lines not on this page · raw message

arch/arm/mach-nexell/Makefile new file +15 -0
new file mode 100644
index 0000000..e144196
@@ -0,0 +1,15 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# (C) Copyright 2016 Nexell
+# Hyunseok, Jung <[email protected]>
+
+obj-y				+= clock.o
+obj-y				+= timer.o
+obj-y				+= reset.o
+obj-y				+= nx_gpio.o
+obj-y				+= tieoff.o
+obj-$(CONFIG_ARCH_S5P4418)	+= reg-call.o
+obj-$(CONFIG_ARCH_S5P4418)	+= nx_sec_reg.o
+obj-$(CONFIG_CMD_BOOTL)		+= cmd_boot_linux.o
+obj-$(CONFIG_S5P_SERIAL)	+= serial.o
+obj-$(CONFIG_SPL_BUILD)		+= spl/
arch/arm/mach-nexell/clock.c new file +869 -0

869 lines not on this page · raw message

arch/arm/mach-nexell/cmd_boot_linux.c new file +145 -0

145 lines not on this page · raw message

arch/arm/mach-nexell/config.mk new file +11 -0
new file mode 100644
index 0000000..7b06626
@@ -0,0 +1,11 @@
+#
+# (C) Copyright 2016 Nexell
+# junghyun kim<[email protected]>
+#
+# SPDX-License-Identifier:      GPL-2.0+
+#
+
+SOCDIR=CPUDIR/$(VENDOR)
+MACHDIR=$(patsubst %,arch/arm/mach-%,$(machine-y))
+
+LDPPFLAGS += -DMACHDIR=$(MACHDIR) -DSOCDIR=$(SOCDIR)
arch/arm/mach-nexell/nx_gpio.c new file +352 -0

352 lines not on this page · raw message

arch/arm/mach-nexell/nx_sec_reg.c new file +82 -0

82 lines not on this page · raw message

arch/arm/mach-nexell/reg-call.S new file +23 -0
new file mode 100644
index 0000000..5fdf515
@@ -0,0 +1,23 @@
+#include <asm-offsets.h>
+#include <config.h>
+#include <linux/linkage.h>
+
+#define ___asm_opcode_identity32(x) ((x) & 0xFFFFFFFF)
+#define __opcode_to_mem_arm(x) ___opcode_identity32(x)
+#define ___asm_opcode_to_mem_arm(x) ___asm_opcode_identity32(x)
+
+#define ___opcode_identity32(x) ((u32)(x))
+#define ___inst_arm(x) .long x
+#define __inst_arm(x) ___inst_arm(___asm_opcode_to_mem_arm(x))
+
+#define __inst_arm_thumb32(arm_opcode, thumb_opcode) __inst_arm(arm_opcode)
+
+#define __SMC(imm4) __inst_arm_thumb32(                                 \
+        0xE1600070 | (((imm4) & 0xF) << 0),                             \
+        0xF7F08000 | (((imm4) & 0xF) << 16)                             \
+)
+
+ENTRY(__invoke_nexell_fn_smc)
+	__SMC(0)
+	bx      lr
+ENDPROC(__invoke_nexell_fn_smc)
arch/arm/mach-nexell/reset.c new file +33 -0
new file mode 100644
index 0000000..1f732a3
@@ -0,0 +1,33 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2016 Nexell
+ * Youngbok, Park <[email protected]>
+ */
+
+/*
+ *FIXME : Not support device tree & reset control driver.
+ *        will remove after support device tree & reset control driver.
+ */
+#include <common.h>
+#include <asm/io.h>
+#include <asm/arch/nexell.h>
+#include <asm/arch/reset.h>
+
+struct	nx_rstcon_registerset {
+	u32	regrst[(NUMBER_OF_RESET_MODULE_PIN + 31) >> 5];
+};
+
+static struct nx_rstcon_registerset *nx_rstcon =
+			(struct nx_rstcon_registerset *)PHY_BASEADDR_RSTCON;
+
+void nx_rstcon_setrst(u32 rstindex, enum rstcon status)
+{
+	u32 regnum, bitpos, curstat;
+
+	regnum		= rstindex >> 5;
+	curstat		= (u32)readl(&nx_rstcon->regrst[regnum]);
+	bitpos		= rstindex & 0x1f;
+	curstat		&= ~(1UL << bitpos);
+	curstat		|= (status & 0x01) << bitpos;
+	writel(curstat, &nx_rstcon->regrst[regnum]);
+}
arch/arm/mach-nexell/serial.c new file +262 -0

262 lines not on this page · raw message

arch/arm/mach-nexell/tieoff.c new file +109 -0

109 lines not on this page · raw message

arch/arm/mach-nexell/timer.c new file +297 -0

297 lines not on this page · raw message

Signature · 1 line
1.9.1
#3 lore raw

RFC PATCH 3/10 i2c: mmc: add nexell driver (gpio, i2c, mmc, pwm)

In reply to 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".
- mmc: nexell_dw_mmc.c changed to nexell_dw_mmc_dm.c (switched to DM).

---

 drivers/gpio/Kconfig           |   9 +
 drivers/gpio/Makefile          |   1 +
 drivers/gpio/nx_gpio.c         | 252 +++++++++++++++++++
 drivers/i2c/Kconfig            |   9 +
 drivers/i2c/Makefile           |   1 +
 drivers/i2c/nx_i2c.c           | 537 +++++++++++++++++++++++++++++++++++++++++
 drivers/mmc/Kconfig            |   6 +
 drivers/mmc/Makefile           |   1 +
 drivers/mmc/nexell_dw_mmc_dm.c | 350 +++++++++++++++++++++++++++
 drivers/pwm/Makefile           |   1 +
 drivers/pwm/pwm-nexell.c       | 252 +++++++++++++++++++
 drivers/pwm/pwm-nexell.h       |  54 +++++
 12 files changed, 1473 insertions(+)
 create mode 100644 drivers/gpio/nx_gpio.c
 create mode 100644 drivers/i2c/nx_i2c.c
 create mode 100644 drivers/mmc/nexell_dw_mmc_dm.c
 create mode 100644 drivers/pwm/pwm-nexell.c
 create mode 100644 drivers/pwm/pwm-nexell.h
drivers/gpio/Kconfig +9 -0
index 1de6f52..febda89 100644
@@ -421,4 +421,13 @@ config MT7621_GPIO
 	help
 	  Say yes here to support MediaTek MT7621 compatible GPIOs.
 
+config NX_GPIO
+	bool "Nexell GPIO driver"
+	depends on DM_GPIO
+	help
+	  Support GPIO access on Nexell SoCs. The GPIOs are arranged into
+	  a number of banks (different for each SoC type) each with 32 GPIOs.
+	  The GPIOs for a device are defined in the device tree with one node
+	  for each bank.
+
 endmenu
drivers/gpio/Makefile +1 -0
index 449046b..e3340de 100644
@@ -65,3 +65,4 @@ obj-$(CONFIG_PM8916_GPIO)	+= pm8916_gpio.o
 obj-$(CONFIG_MT7621_GPIO)	+= mt7621_gpio.o
 obj-$(CONFIG_MSCC_SGPIO)	+= mscc_sgpio.o
 obj-$(CONFIG_SIFIVE_GPIO)	+= sifive-gpio.o
+obj-$(CONFIG_NX_GPIO)		+= nx_gpio.o
drivers/gpio/nx_gpio.c new file +252 -0

252 lines not on this page · raw message

drivers/i2c/Kconfig +9 -0
index 03d2fed..2cd0ed3 100644
@@ -317,6 +317,15 @@ config SYS_MXC_I2C8_SLAVE
 	 MXC I2C8 Slave
 endif
 
+config SYS_I2C_NEXELL
+	bool "Nexell I2C driver"
+	depends on DM_I2C
+	help
+	  Add support for the Nexell I2C driver. This is used with various
+	  Nexell parts such as S5Pxx18 series SoCs. All chips
+	  have several I2C ports and all are provided, controlled by the
+	  device tree.
+
 config SYS_I2C_OMAP24XX
 	bool "TI OMAP2+ I2C driver"
 	depends on ARCH_OMAP2PLUS || ARCH_K3
drivers/i2c/Makefile +1 -0
index f5a471f..64b8ead 100644
@@ -26,6 +26,7 @@ obj-$(CONFIG_SYS_I2C_LPC32XX) += lpc32xx_i2c.o
 obj-$(CONFIG_SYS_I2C_MESON) += meson_i2c.o
 obj-$(CONFIG_SYS_I2C_MVTWSI) += mvtwsi.o
 obj-$(CONFIG_SYS_I2C_MXC) += mxc_i2c.o
+obj-$(CONFIG_SYS_I2C_NEXELL) += nx_i2c.o
 obj-$(CONFIG_SYS_I2C_OMAP24XX) += omap24xx_i2c.o
 obj-$(CONFIG_SYS_I2C_RCAR_I2C) += rcar_i2c.o
 obj-$(CONFIG_SYS_I2C_RCAR_IIC) += rcar_iic.o
drivers/i2c/nx_i2c.c new file +537 -0

537 lines not on this page · raw message

drivers/mmc/Kconfig +6 -0
index 2f0eedc..bb8e7c0 100644
@@ -253,6 +253,12 @@ config MMC_DW_SNPS
 	  This selects support for Synopsys DesignWare Memory Card Interface driver
 	  extensions used in various Synopsys ARC devboards.
 
+config NEXELL_DWMMC
+	bool "Nexell SD/MMC controller support"
+	depends on ARCH_NEXELL
+	depends on MMC_DW
+	default y
+
 config MMC_MESON_GX
 	bool "Meson GX EMMC controller support"
 	depends on DM_MMC && BLK && ARCH_MESON
drivers/mmc/Makefile +1 -0
index 9c1f8e5..a7b5a7b 100644
@@ -43,6 +43,7 @@ obj-$(CONFIG_SH_MMCIF) += sh_mmcif.o
 obj-$(CONFIG_SH_SDHI) += sh_sdhi.o
 obj-$(CONFIG_STM32_SDMMC2) += stm32_sdmmc2.o
 obj-$(CONFIG_JZ47XX_MMC) += jz_mmc.o
+obj-$(CONFIG_NEXELL_DWMMC) += nexell_dw_mmc_dm.o
 
 # SDHCI
 obj-$(CONFIG_MMC_SDHCI)			+= sdhci.o
drivers/mmc/nexell_dw_mmc_dm.c new file +350 -0

350 lines not on this page · raw message

drivers/pwm/Makefile +1 -0
index a837c35..b45aada 100644
@@ -16,3 +16,4 @@ obj-$(CONFIG_PWM_ROCKCHIP)	+= rk_pwm.o
 obj-$(CONFIG_PWM_SANDBOX)	+= sandbox_pwm.o
 obj-$(CONFIG_PWM_TEGRA)		+= tegra_pwm.o
 obj-$(CONFIG_PWM_SUNXI)		+= sunxi_pwm.o
+obj-$(CONFIG_PWM_NX)		+= pwm-nexell.o
drivers/pwm/pwm-nexell.c new file +252 -0

252 lines not on this page · raw message

drivers/pwm/pwm-nexell.h new file +54 -0

54 lines not on this page · raw message

Signature · 1 line
1.9.1
#4 lore raw

RFC PATCH 3/10 i2c: mmc: add nexell driver (gpio, i2c, mmc, pwm)

Hello Stefan,

Am 03.02.2020 um 21:40 schrieb Stefan Bosch:

Quoted 8 lines

Changes in relation to FriendlyARM's U-Boot nanopi2-v2016.01:
- i2c/nx_i2c.c: Some adaptions mainly because of changes in "struct udevice".
- mmc: nexell_dw_mmc.c changed to nexell_dw_mmc_dm.c (switched to DM).

---

Quoted 12 lines
  drivers/gpio/Kconfig           |   9 +
  drivers/gpio/Makefile          |   1 +
  drivers/gpio/nx_gpio.c         | 252 +++++++++++++++++++
  drivers/i2c/Kconfig            |   9 +
  drivers/i2c/Makefile           |   1 +
  drivers/i2c/nx_i2c.c           | 537 +++++++++++++++++++++++++++++++++++++++++
  drivers/mmc/Kconfig            |   6 +
  drivers/mmc/Makefile           |   1 +
  drivers/mmc/nexell_dw_mmc_dm.c | 350 +++++++++++++++++++++++++++
  drivers/pwm/Makefile           |   1 +
  drivers/pwm/pwm-nexell.c       | 252 +++++++++++++++++++
  drivers/pwm/pwm-nexell.h       |  54 +++++

Could you please split this patch into 4 parts (i2c, gpio, mmc and pwm) ?

Thanks!

Quoted 7 lines
  12 files changed, 1473 insertions(+)

create mode 100644 drivers/gpio/nx_gpio.c create mode 100644 drivers/i2c/nx_i2c.c create mode 100644 drivers/mmc/nexell_dw_mmc_dm.c create mode 100644 drivers/pwm/pwm-nexell.c create mode 100644 drivers/pwm/pwm-nexell.h

[...]

drivers/gpio/Makefile obj-$(CONFIG_PM8916_GPIO) += pm8916_gpio.o · line 68

Quoted 9 lines
drivers/gpio/Makefile +1 -0
index 449046b..e3340de 100644
@@ -65,3 +65,4 @@ obj-$(CONFIG_PM8916_GPIO)	+= pm8916_gpio.o
  obj-$(CONFIG_MT7621_GPIO)	+= mt7621_gpio.o
  obj-$(CONFIG_MSCC_SGPIO)	+= mscc_sgpio.o
  obj-$(CONFIG_SIFIVE_GPIO)	+= sifive-gpio.o
+obj-$(CONFIG_NX_GPIO)		+= nx_gpio.o

Please keep lists sorted.

Quoted 323 lines
drivers/gpio/nx_gpio.c new file +252 -0
new file mode 100644
index 0000000..86472f6
@@ -0,0 +1,252 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2016 Nexell
+ * DeokJin, Lee <[email protected]>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <errno.h>
+#include <malloc.h>
+#include <fdtdec.h>
+#include <asm/io.h>
+#include <asm/gpio.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+struct nx_gpio_regs {
+	u32	data;		/* Data register */
+	u32	outputenb;	/* Output Enable register */
+	u32	detmode[2];	/* Detect Mode Register */
+	u32	intenb;		/* Interrupt Enable Register */
+	u32	det;		/* Event Detect Register */
+	u32	pad;		/* Pad Status Register */
+};
+
+struct nx_alive_gpio_regs {
+	u32	pwrgate;	/* Power Gating Register */
+	u32	reserved0[28];	/* Reserved0 */
+	u32	outputenb_reset;/* Alive GPIO Output Enable Reset Register */
+	u32	outputenb;	/* Alive GPIO Output Enable Register */
+	u32	outputenb_read; /* Alive GPIO Output Read Register */
+	u32	reserved1[3];	/* Reserved1 */
+	u32	pad_reset;	/* Alive GPIO Output Reset Register */
+	u32	data;		/* Alive GPIO Output Register */
+	u32	pad_read;	/* Alive GPIO Pad Read Register */
+	u32	reserved2[33];	/* Reserved2 */
+	u32	pad;		/* Alive GPIO Input Value Register */
+};
+
+struct nx_gpio_platdata {
+	void *regs;
+	int gpio_count;
+	const char *bank_name;
+};
+
+static int nx_alive_gpio_is_check(struct udevice *dev)
+{
+	struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+	const char *bank_name = plat->bank_name;
+
+	if (!strcmp(bank_name, "gpio_alv"))
+		return 1;
+
+	return 0;
+}
+
+static int nx_alive_gpio_direction_input(struct udevice *dev, unsigned int pin)
+{
+	struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+	struct nx_alive_gpio_regs *const regs = plat->regs;
+
+	setbits_le32(&regs->outputenb_reset, 1 << pin);
+
+	return 0;
+}
+
+static int nx_alive_gpio_direction_output(struct udevice *dev, unsigned int pin,
+					  int val)
+{
+	struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+	struct nx_alive_gpio_regs *const regs = plat->regs;
+
+	if (val)
+		setbits_le32(&regs->data, 1 << pin);
+	else
+		setbits_le32(&regs->pad_reset, 1 << pin);
+
+	setbits_le32(&regs->outputenb, 1 << pin);
+
+	return 0;
+}
+
+static int nx_alive_gpio_get_value(struct udevice *dev, unsigned int pin)
+{
+	struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+	struct nx_alive_gpio_regs *const regs = plat->regs;
+	unsigned int mask = 1UL << pin;
+	unsigned int value;
+
+	value = (readl(&regs->pad_read) & mask) >> pin;
+
+	return value;
+}
+
+static int nx_alive_gpio_set_value(struct udevice *dev, unsigned int pin,
+				   int val)
+{
+	struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+	struct nx_alive_gpio_regs *const regs = plat->regs;
+
+	if (val)
+		setbits_le32(&regs->data, 1 << pin);
+	else
+		clrbits_le32(&regs->pad_reset, 1 << pin);
+
+	return 0;
+}
+
+static int nx_alive_gpio_get_function(struct udevice *dev, unsigned int pin)
+{
+	struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+	struct nx_alive_gpio_regs *const regs = plat->regs;
+	unsigned int mask = (1UL << pin);
+	unsigned int output;
+
+	output = readl(&regs->outputenb_read) & mask;
+
+	if (output)
+		return GPIOF_OUTPUT;
+	else
+		return GPIOF_INPUT;
+}
+
+static int nx_gpio_direction_input(struct udevice *dev, unsigned int pin)
+{
+	struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+	struct nx_gpio_regs *const regs = plat->regs;
+
+	if (nx_alive_gpio_is_check(dev))
+		return nx_alive_gpio_direction_input(dev, pin);
+
+	clrbits_le32(&regs->outputenb, 1 << pin);
+
+	return 0;
+}
+
+static int nx_gpio_direction_output(struct udevice *dev, unsigned int pin,
+				    int val)
+{
+	struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+	struct nx_gpio_regs *const regs = plat->regs;
+
+	if (nx_alive_gpio_is_check(dev))
+		return nx_alive_gpio_direction_output(dev, pin, val);
+
+	if (val)
+		setbits_le32(&regs->data, 1 << pin);
+	else
+		clrbits_le32(&regs->data, 1 << pin);
+
+	setbits_le32(&regs->outputenb, 1 << pin);
+
+	return 0;
+}
+
+static int nx_gpio_get_value(struct udevice *dev, unsigned int pin)
+{
+	struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+	struct nx_gpio_regs *const regs = plat->regs;
+	unsigned int mask = 1UL << pin;
+	unsigned int value;
+
+	if (nx_alive_gpio_is_check(dev))
+		return nx_alive_gpio_get_value(dev, pin);
+
+	value = (readl(&regs->pad) & mask) >> pin;
+
+	return value;
+}
+
+static int nx_gpio_set_value(struct udevice *dev, unsigned int pin, int val)
+{
+	struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+	struct nx_gpio_regs *const regs = plat->regs;
+
+	if (nx_alive_gpio_is_check(dev))
+		return nx_alive_gpio_set_value(dev, pin, val);
+
+	if (val)
+		setbits_le32(&regs->data, 1 << pin);
+	else
+		clrbits_le32(&regs->data, 1 << pin);
+
+	return 0;
+}
+
+static int nx_gpio_get_function(struct udevice *dev, unsigned int pin)
+{
+	struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+	struct nx_gpio_regs *const regs = plat->regs;
+	unsigned int mask = (1UL << pin);
+	unsigned int output;
+
+	if (nx_alive_gpio_is_check(dev))
+		return nx_alive_gpio_get_function(dev, pin);
+
+	output = readl(&regs->outputenb) & mask;
+
+	if (output)
+		return GPIOF_OUTPUT;
+	else
+		return GPIOF_INPUT;
+}
+
+static int nx_gpio_probe(struct udevice *dev)
+{
+	struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
+	struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+
+	uc_priv->gpio_count = plat->gpio_count;
+	uc_priv->bank_name = plat->bank_name;
+
+	return 0;
+}
+
+static int nx_gpio_ofdata_to_platdata(struct udevice *dev)
+{
+	struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+
+	plat->regs = map_physmem(devfdt_get_addr(dev),
+				 sizeof(struct nx_gpio_regs),
+				 MAP_NOCACHE);
+	plat->gpio_count = fdtdec_get_int(gd->fdt_blob, dev->node.of_offset,
+					  "nexell,gpio-bank-width", 32);
+	plat->bank_name = fdt_getprop(gd->fdt_blob, dev->node.of_offset,
+				      "gpio-bank-name", NULL);
+
+	return 0;
+}
+
+static const struct dm_gpio_ops nx_gpio_ops = {
+	.direction_input	= nx_gpio_direction_input,
+	.direction_output	= nx_gpio_direction_output,
+	.get_value		= nx_gpio_get_value,
+	.set_value		= nx_gpio_set_value,
+	.get_function		= nx_gpio_get_function,
+};
+
+static const struct udevice_id nx_gpio_ids[] = {
+	{ .compatible = "nexell,nexell-gpio" },
+	{ }
+};
+
+U_BOOT_DRIVER(nx_gpio) = {
+	.name		= "nx_gpio",
+	.id		= UCLASS_GPIO,
+	.of_match	= nx_gpio_ids,
+	.ops		= &nx_gpio_ops,
+	.ofdata_to_platdata = nx_gpio_ofdata_to_platdata,
+	.platdata_auto_alloc_size = sizeof(struct nx_gpio_platdata),
+	.probe		= nx_gpio_probe,
+};
drivers/i2c/Kconfig +9 -0
index 03d2fed..2cd0ed3 100644
@@ -317,6 +317,15 @@ config SYS_MXC_I2C8_SLAVE
  	 MXC I2C8 Slave
  endif
 
+config SYS_I2C_NEXELL
+	bool "Nexell I2C driver"
+	depends on DM_I2C
+	help
+	  Add support for the Nexell I2C driver. This is used with various
+	  Nexell parts such as S5Pxx18 series SoCs. All chips
+	  have several I2C ports and all are provided, controlled by the
+	  device tree.
+
  config SYS_I2C_OMAP24XX
  	bool "TI OMAP2+ I2C driver"
  	depends on ARCH_OMAP2PLUS || ARCH_K3
drivers/i2c/Makefile +1 -0
index f5a471f..64b8ead 100644
@@ -26,6 +26,7 @@ obj-$(CONFIG_SYS_I2C_LPC32XX) += lpc32xx_i2c.o
  obj-$(CONFIG_SYS_I2C_MESON) += meson_i2c.o
  obj-$(CONFIG_SYS_I2C_MVTWSI) += mvtwsi.o
  obj-$(CONFIG_SYS_I2C_MXC) += mxc_i2c.o
+obj-$(CONFIG_SYS_I2C_NEXELL) += nx_i2c.o
  obj-$(CONFIG_SYS_I2C_OMAP24XX) += omap24xx_i2c.o
  obj-$(CONFIG_SYS_I2C_RCAR_I2C) += rcar_i2c.o
  obj-$(CONFIG_SYS_I2C_RCAR_IIC) += rcar_iic.o
drivers/i2c/nx_i2c.c new file +27 -0
new file mode 100644
index 0000000..a3eec6c
@@ -0,0 +1,537 @@
+#include <common.h>
+#include <errno.h>
+#include <dm.h>
+#include <i2c.h>
+#include <asm/arch/nexell.h>
+#include <asm/arch/reset.h>
+#include <asm/arch/clk.h>
+#include <asm/arch/nx_gpio.h>
+
+#define I2C_WRITE       0
+#define I2C_READ        1
+
+#define I2C_OK          0
+#define I2C_NOK         1
+#define I2C_NACK        2
+#define I2C_NOK_LA      3       /* Lost arbitration */
+#define I2C_NOK_TOUT    4       /* time out */
+
+#define I2CLC_FILTER	0x04	/* SDA filter on*/
+#define I2CSTAT_BSY     0x20    /* Busy bit */
+#define I2CSTAT_NACK    0x01    /* Nack bit */
+#define I2CSTAT_ABT	0x08	/* Arbitration bit */
+#define I2CCON_ACKGEN   0x80    /* Acknowledge generation */
+#define I2CCON_IRENB	0x20	/* Interrupt Enable bit  */
+#define I2CCON_IRPND    0x10    /* Interrupt pending bit */
+#define I2C_MODE_MT     0xC0    /* Master Transmit Mode */
+#define I2C_MODE_MR     0x80    /* Master Receive Mode */

drivers/i2c/nx_i2c.c line 37

Quoted 10 lines
drivers/i2c/nx_i2c.c new file +10 -0
+#define I2C_START_STOP  0x20    /* START / STOP */
+#define I2C_TXRX_ENA    0x10    /* I2C Tx/Rx enable */
+
+#define I2C_TIMEOUT_MS	10      /* 10 ms */
+
+#define I2C_M_NOSTOP	0x100
+
+#ifndef CONFIG_MAX_I2C_NUM
+#define CONFIG_MAX_I2C_NUM 3
+#endif

Is this really configurable? If so, I do not find the Kconfig description.

Quoted 38 lines
drivers/i2c/nx_i2c.c new file +38 -0
+
+DECLARE_GLOBAL_DATA_PTR;
+
+struct nx_i2c_regs {
+	uint     iiccon;
+	uint     iicstat;
+	uint     iicadd;
+	uint     iicds;
+	uint     iiclc;
+};
+
+struct nx_i2c_bus {
+	uint bus_num;
+	struct nx_i2c_regs *regs;
+	uint speed;
+	uint target_speed;
+	uint sda_delay;
+};
+
+/* s5pxx18 i2c must be reset before enabled */
+static void i2c_reset(int ch)
+{
+	int rst_id = RESET_ID_I2C0 + ch;
+
+	nx_rstcon_setrst(rst_id, 0);
+	nx_rstcon_setrst(rst_id, 1);
+}
+
+/* FIXME : this func will be removed after reset dm driver ported.
+ * set mmc pad alternative func.
+ */
+static void set_i2c_pad_func(struct nx_i2c_bus *i2c)
+{
+	switch (i2c->bus_num) {
+	case 0:
+		nx_gpio_set_pad_function(3, 2, 1);
+		nx_gpio_set_pad_function(3, 3, 1);
+		break;

drivers/i2c/nx_i2c.c line 85

Quoted 10 lines
drivers/i2c/nx_i2c.c new file +10 -0
+	case 1:
+		nx_gpio_set_pad_function(3, 4, 1);
+		nx_gpio_set_pad_function(3, 5, 1);
+		break;
+	case 2:
+		nx_gpio_set_pad_function(3, 6, 1);
+		nx_gpio_set_pad_function(3, 7, 1);
+		break;
+	}
+}

Hmm... may this should be moved into a seperate pincontrol driver?

drivers/i2c/nx_i2c.c line 91

Quoted 6 lines
drivers/i2c/nx_i2c.c new file +6 -0
+
+static uint i2c_get_clkrate(struct nx_i2c_bus *bus)
+{
+	struct clk *clk;
+	int index = bus->bus_num;
+	char name[50] = {0, };

?

drivers/i2c/nx_i2c.c line 93

Quoted 2 lines
drivers/i2c/nx_i2c.c new file +2 -0
+
+	sprintf(name, "%s.%d", DEV_NAME_I2C, index);

Where is DEV_NAME_I2C defined ?

Quoted 32 lines
drivers/i2c/nx_i2c.c new file +32 -0
+	clk = clk_get((const char *)name);
+	if (!clk)
+		return -1;
+
+	return clk_get_rate(clk);
+}
+
+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)
+		return -1;
+
+	if (enb) {
+		clk_disable(clk);
+		clk_enable(clk);
+	} else {
+		clk_disable(clk);
+	}
+
+	return 0;
+}
+
+/* get i2c module number from base address */
+static uint i2c_get_busnum(struct nx_i2c_bus *bus)
+{
+	void *base_addr = (void *)PHY_BASEADDR_I2C0;
+	int i;

drivers/i2c/nx_i2c.c line 135

Quoted 10 lines
drivers/i2c/nx_i2c.c new file +10 -0
+
+	for (i = 0; i < CONFIG_MAX_I2C_NUM; i++) {
+		if (base_addr == ((void *)bus->regs)) {
+			bus->bus_num = i;
+			return i;
+		}
+		base_addr += 0x1000;
+	}
+
+	return -1;

return -ENODEV;

Hmm... is there no chance to use seq from struct udevice

https://gitlab.denx.de/u-boot/u-boot/blob/master/include/dm/device.h#L152

?

For example like:
https://gitlab.denx.de/u-boot/u-boot/blob/master/drivers/i2c/mxc_i2c.c#L895

Quoted 42 lines
drivers/i2c/nx_i2c.c new file +42 -0
+}
+
+/* Set SDA line delay */
+static int nx_i2c_set_sda_delay(struct nx_i2c_bus *bus, ulong clkin)
+{
+	struct nx_i2c_regs *i2c = bus->regs;
+	uint sda_delay = 0;
+
+	if (bus->sda_delay) {
+		sda_delay = clkin * bus->sda_delay;
+		sda_delay = DIV_ROUND_UP(sda_delay, 1000000);
+		sda_delay = DIV_ROUND_UP(sda_delay, 5);
+		if (sda_delay > 3)
+			sda_delay = 3;
+		sda_delay |= I2CLC_FILTER;
+	} else {
+		sda_delay = 0;
+	}
+
+	sda_delay &= 0x7;
+	writel(sda_delay, &i2c->iiclc);
+
+	return 0;
+}
+
+/* Calculate the value of the divider and prescaler, set the bus speed. */
+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 freq, pres = 16, div;
+
+	freq = i2c_get_clkrate(bus);
+	/* calculate prescaler and divisor values */
+	if ((freq / pres / (16 + 1)) > speed)
+		/* set prescaler to 512 */
+		pres = 512;
+
+	div = 0;
+	while ((freq / pres / (div + 1)) > speed)
+		div++;
+

drivers/i2c/nx_i2c.c line 187

Quoted 10 lines
drivers/i2c/nx_i2c.c new file +10 -0
+	/* set prescaler, divisor according to freq, also set ACKGEN, IRQ */
+	writel((div & 0x0F) | ((pres == 512) ? 0x40 : 0), &i2c->iiccon);
+
+	/* init to SLAVE REVEIVE and set slaveaddr */
+	writel(0, &i2c->iicstat);
+	writel(0x00, &i2c->iicadd);
+	/* program Master Transmit (and implicit STOP) */
+	writel(I2C_MODE_MT | I2C_TXRX_ENA, &i2c->iicstat);
+
+	bus->speed = bus->target_speed / (div * pres);

Do you want to allow all values of speeds or may you want to use standard speeds, see:

https://gitlab.denx.de/u-boot/u-boot/blob/master/include/i2c.h#L33

Quoted 18 lines
drivers/i2c/nx_i2c.c new file +18 -0
+
+	return 0;
+}
+
+static void nx_i2c_set_clockrate(struct udevice *dev, uint speed)
+{
+	struct nx_i2c_bus *bus = dev_get_priv(dev);
+	ulong clkin;
+
+	nx_i2c_set_bus_speed(dev, speed);
+	clkin = bus->speed;			/* the actual i2c speed */
+	clkin /= 1000;				/* clkin now in Khz */
+	nx_i2c_set_sda_delay(bus, clkin);
+}
+
+static void i2c_process_node(struct udevice *dev)
+{
+	struct nx_i2c_bus *bus = dev_get_priv(dev);

drivers/i2c/nx_i2c.c line 215

Quoted 10 lines
drivers/i2c/nx_i2c.c new file +10 -0
+	const void *blob = gd->fdt_blob;
+
+	int node;
+
+	node = dev->node.of_offset;
+
+	bus->target_speed = fdtdec_get_int(blob, node,
+					   "nexell,i2c-max-bus-freq", 0);
+	bus->sda_delay = fdtdec_get_int(blob, node,
+					"nexell,i2c-sda-delay", 0);

You introdue here new properties, please document them in u-boot:/doc/device-tree-bindings/i2c

Please without "nexell,"

Do you plan to post also a linux i2c driver?

If so, the devicetree bindings should be discussed there to avoid different properties between U-Boot and linux!

drivers/i2c/nx_i2c.c line 227

Quoted 12 lines
drivers/i2c/nx_i2c.c new file +12 -0
+}
+
+static int nx_i2c_probe(struct udevice *dev)
+{
+	struct nx_i2c_bus *bus = dev_get_priv(dev);
+
+	/* get regs */
+	bus->regs = (struct nx_i2c_regs *)devfdt_get_addr(dev);
+	/* calc index */
+	if (!i2c_get_busnum(bus)) {
+		debug("not found i2c number!\n");
+		return -1;

please return -ENODEV

drivers/i2c/nx_i2c.c line 233

Quoted 6 lines
drivers/i2c/nx_i2c.c new file +6 -0
+	}
+
+	/* i2c optional node parsing */
+	i2c_process_node(dev);
+	if (!bus->target_speed)
+		return -1;

please return here also an errorcode from include/linux/errno.h

Hmm.. if you return here if target_speed is not set, it is not optional!

Quoted 283 lines
drivers/i2c/nx_i2c.c new file +283 -0
+
+	/* reset */
+	i2c_reset(bus->bus_num);
+	/* gpio pad */
+	set_i2c_pad_func(bus);
+
+	/* clock rate */
+	i2c_set_clk(bus, 1);
+	nx_i2c_set_clockrate(dev, bus->target_speed);
+	i2c_set_clk(bus, 0);
+
+	return 0;
+}
+
+/* i2c bus busy check */
+static int i2c_is_busy(struct nx_i2c_regs *i2c)
+{
+	ulong start_time;
+
+	start_time = get_timer(0);
+	while (readl(&i2c->iicstat) & I2CSTAT_BSY) {
+		if (get_timer(start_time) > I2C_TIMEOUT_MS) {
+			debug("Timeout\n");
+			return -I2C_NOK_TOUT;
+		}
+	}
+	return 0;
+}
+
+/* irq enable/disable functions */
+static void i2c_enable_irq(struct nx_i2c_regs *i2c)
+{
+	unsigned int reg;
+
+	reg = readl(&i2c->iiccon);
+	reg |= I2CCON_IRENB;
+	writel(reg, &i2c->iiccon);
+}
+
+/* irq clear function */
+static void i2c_clear_irq(struct nx_i2c_regs *i2c)
+{
+	clrbits_le32(&i2c->iiccon, I2CCON_IRPND);
+}
+
+/* ack enable functions */
+static void i2c_enable_ack(struct nx_i2c_regs *i2c)
+{
+	unsigned int reg;
+
+	reg = readl(&i2c->iiccon);
+	reg |= I2CCON_ACKGEN;
+	writel(reg, &i2c->iiccon);
+}
+
+static void i2c_send_stop(struct nx_i2c_regs *i2c)
+{
+	unsigned int reg;
+
+	/* Send STOP. */
+	reg = readl(&i2c->iicstat);
+	reg |= I2C_MODE_MR | I2C_TXRX_ENA;
+	reg &= (~I2C_START_STOP);
+	writel(reg, &i2c->iicstat);
+	i2c_clear_irq(i2c);
+}
+
+static int wait_for_xfer(struct nx_i2c_regs *i2c)
+{
+	unsigned long start_time = get_timer(0);
+
+	do {
+		if (readl(&i2c->iiccon) & I2CCON_IRPND)
+			return (readl(&i2c->iicstat) & I2CSTAT_NACK) ?
+				I2C_NACK : I2C_OK;
+	} while (get_timer(start_time) < I2C_TIMEOUT_MS);
+
+	return I2C_NOK_TOUT;
+}
+
+static int i2c_transfer(struct nx_i2c_regs *i2c,
+			uchar cmd_type,
+			uchar chip,
+			uchar addr[],
+			uchar addr_len,
+			uchar data[],
+			unsigned short data_len,
+			uint seq)
+{
+	uint status;
+	int i = 0, result;
+
+	if (data == 0 || data_len == 0) {
+		/*Don't support data transfer of no length or to address 0 */
+		debug("%s: bad call\n", __func__);
+		return I2C_NOK;
+	}
+
+	i2c_enable_irq(i2c);
+	i2c_enable_ack(i2c);
+
+	/* Get the slave chip address going */
+	writel(chip, &i2c->iicds);
+	status = I2C_TXRX_ENA | I2C_START_STOP;
+	if (cmd_type == I2C_WRITE || (addr && addr_len))
+		status |= I2C_MODE_MT;
+	else
+		status |= I2C_MODE_MR;
+	writel(status, &i2c->iicstat);
+	if (seq)
+		i2c_clear_irq(i2c);
+
+	/* Wait for chip address to transmit. */
+	result = wait_for_xfer(i2c);
+	if (result != I2C_OK)
+		goto bailout;
+
+	/* If register address needs to be transmitted - do it now. */
+	if (addr && addr_len) {  /* register addr */
+		while ((i < addr_len) && (result == I2C_OK)) {
+			writel(addr[i++], &i2c->iicds);
+			i2c_clear_irq(i2c);
+			result = wait_for_xfer(i2c);
+		}
+
+		i = 0;
+		if (result != I2C_OK)
+			goto bailout;
+	}
+
+	switch (cmd_type) {
+	case I2C_WRITE:
+		while ((i < data_len) && (result == I2C_OK)) {
+			writel(data[i++], &i2c->iicds);
+			i2c_clear_irq(i2c);
+			result = wait_for_xfer(i2c);
+		}
+		break;
+	case I2C_READ:
+		if (addr && addr_len) {
+			/*
+			 * Register address has been sent, now send slave chip
+			 * address again to start the actual read transaction.
+			 */
+			writel(chip, &i2c->iicds);
+
+			/* Generate a re-START. */
+			writel(I2C_MODE_MR | I2C_TXRX_ENA
+					| I2C_START_STOP, &i2c->iicstat);
+			i2c_clear_irq(i2c);
+			result = wait_for_xfer(i2c);
+			if (result != I2C_OK)
+				goto bailout;
+		}
+
+		while ((i < data_len) && (result == I2C_OK)) {
+			/* disable ACK for final READ */
+			if (i == data_len - 1)
+				clrbits_le32(&i2c->iiccon
+						, I2CCON_ACKGEN);
+
+			i2c_clear_irq(i2c);
+			result = wait_for_xfer(i2c);
+			data[i++] = readb(&i2c->iicds);
+		}
+
+		if (result == I2C_NACK)
+			result = I2C_OK; /* Normal terminated read. */
+		break;
+
+	default:
+		debug("%s: bad call\n", __func__);
+		result = I2C_NOK;
+		break;
+	}
+
+bailout:
+	return result;
+}
+
+static int nx_i2c_read(struct udevice *dev, uchar chip, uint addr,
+		       uint alen, uchar *buffer, uint len, uint seq)
+{
+	struct nx_i2c_bus *i2c;
+	uchar xaddr[4];
+	int ret;
+
+	i2c = dev_get_priv(dev);
+	if (!i2c)
+		return -EFAULT;
+
+	if (alen > 4) {
+		debug("I2C read: addr len %d not supported\n", alen);
+		return -EADDRNOTAVAIL;
+	}
+
+	if (alen > 0)
+		xaddr[0] = (addr >> 24) & 0xFF;
+
+	if (alen > 0) {
+		xaddr[0] = (addr >> 24) & 0xFF;
+		xaddr[1] = (addr >> 16) & 0xFF;
+		xaddr[2] = (addr >> 8) & 0xFF;
+		xaddr[3] = addr & 0xFF;
+	}
+
+	ret = i2c_transfer(i2c->regs, I2C_READ, chip << 1,
+			   &xaddr[4 - alen], alen, buffer, len, seq);
+
+	if (ret) {
+		debug("I2C read failed %d\n", ret);
+		return -EIO;
+	}
+
+	return 0;
+}
+
+static int nx_i2c_write(struct udevice *dev, uchar chip, uint addr,
+			uint alen, uchar *buffer, uint len, uint seq)
+{
+	struct nx_i2c_bus *i2c;
+	uchar xaddr[4];
+	int ret;
+
+	i2c = dev_get_priv(dev);
+	if (!i2c)
+		return -EFAULT;
+
+	if (alen > 4) {
+		debug("I2C write: addr len %d not supported\n", alen);
+		return -EINVAL;
+	}
+
+	if (alen > 0) {
+		xaddr[0] = (addr >> 24) & 0xFF;
+		xaddr[1] = (addr >> 16) & 0xFF;
+		xaddr[2] = (addr >> 8) & 0xFF;
+		xaddr[3] = addr & 0xFF;
+	}
+
+	ret = i2c_transfer(i2c->regs, I2C_WRITE, chip << 1,
+			   &xaddr[4 - alen], alen, buffer, len, seq);
+	if (ret) {
+		debug("I2C write failed %d\n", ret);
+		return -EIO;
+	}
+
+	return 0;
+}
+
+static int nx_i2c_xfer(struct udevice *dev, struct i2c_msg *msg, int nmsgs)
+{
+	struct nx_i2c_bus *bus = dev_get_priv(dev);
+	struct nx_i2c_regs *i2c = bus->regs;
+	int ret;
+	int i;
+
+	/* The power loss by the clock, only during on/off. */
+	i2c_set_clk(bus, 1);
+
+	/* Bus State(Busy) check  */
+	ret = i2c_is_busy(i2c);
+	if (ret < 0)
+		return ret;
+
+	for (i = 0; i < nmsgs; msg++, i++) {
+		if (msg->flags & I2C_M_RD) {
+			ret = nx_i2c_read(dev, msg->addr, 0, 0, msg->buf,
+					  msg->len, i);
+		} else {
+			ret = nx_i2c_write(dev, msg->addr, 0, 0, msg->buf,
+					   msg->len, i);
+		}
+
+		if (ret) {
+			debug("i2c_xfer: error sending\n");
+			return -EREMOTEIO;
+		}
+	}
+	/* Send Stop */
+	i2c_send_stop(i2c);
+	i2c_set_clk(bus, 0);
+

drivers/i2c/nx_i2c.c line 526

Quoted 10 lines
drivers/i2c/nx_i2c.c new file +10 -0
+	return ret ? -EREMOTEIO : 0;
+};
+
+static const struct dm_i2c_ops nx_i2c_ops = {
+	.xfer		= nx_i2c_xfer,
+	.set_bus_speed	= nx_i2c_set_bus_speed,
+};
+
+static const struct udevice_id nx_i2c_ids[] = {
+	{ .compatible = "nexell,s5pxx18-i2c" },

Same here as for the new properties. Please discuss the names on

devicetree at vger.kernel.org <[email protected]>

first!

drivers/i2c/nx_i2c.c line 537

Quoted 11 lines
drivers/i2c/nx_i2c.c new file +11 -0
+	{ }
+};
+
+U_BOOT_DRIVER(i2c_nexell) = {
+	.name		= "i2c_nexell",
+	.id		= UCLASS_I2C,
+	.of_match	= nx_i2c_ids,
+	.probe		= nx_i2c_probe,
+	.priv_auto_alloc_size	= sizeof(struct nx_i2c_bus),
+	.ops		= &nx_i2c_ops,
+};

bye,
Heiko

Quoted 713 lines
drivers/mmc/Kconfig +6 -0
index 2f0eedc..bb8e7c0 100644
@@ -253,6 +253,12 @@ config MMC_DW_SNPS
  	  This selects support for Synopsys DesignWare Memory Card Interface driver
  	  extensions used in various Synopsys ARC devboards.
 
+config NEXELL_DWMMC
+	bool "Nexell SD/MMC controller support"
+	depends on ARCH_NEXELL
+	depends on MMC_DW
+	default y
+
  config MMC_MESON_GX
  	bool "Meson GX EMMC controller support"
  	depends on DM_MMC && BLK && ARCH_MESON
drivers/mmc/Makefile +1 -0
index 9c1f8e5..a7b5a7b 100644
@@ -43,6 +43,7 @@ obj-$(CONFIG_SH_MMCIF) += sh_mmcif.o
  obj-$(CONFIG_SH_SDHI) += sh_sdhi.o
  obj-$(CONFIG_STM32_SDMMC2) += stm32_sdmmc2.o
  obj-$(CONFIG_JZ47XX_MMC) += jz_mmc.o
+obj-$(CONFIG_NEXELL_DWMMC) += nexell_dw_mmc_dm.o
 
  # SDHCI
  obj-$(CONFIG_MMC_SDHCI)			+= sdhci.o
drivers/mmc/nexell_dw_mmc_dm.c new file +350 -0
new file mode 100644
index 0000000..b06b60d
@@ -0,0 +1,350 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2016 Nexell
+ * Youngbok, Park <[email protected]>
+ *
+ * (C) Copyright 2019 Stefan Bosch <[email protected]>
+ */
+
+#include <common.h>
+#include <clk.h>
+#include <dm.h>
+#include <dt-structs.h>
+#include <dwmmc.h>
+#include <syscon.h>
+#include <asm/gpio.h>
+#include <asm/arch/nx_gpio.h>
+#include <asm/arch/reset.h>
+
+#define DWMCI_CLKSEL			0x09C
+#define DWMCI_SHIFT_0			0x0
+#define DWMCI_SHIFT_1			0x1
+#define DWMCI_SHIFT_2			0x2
+#define DWMCI_SHIFT_3			0x3
+#define DWMCI_SET_SAMPLE_CLK(x)	(x)
+#define DWMCI_SET_DRV_CLK(x)	((x) << 16)
+#define DWMCI_SET_DIV_RATIO(x)	((x) << 24)
+#define DWMCI_CLKCTRL			0x114
+#define NX_MMC_CLK_DELAY(x, y, a, b)	((((x) & 0xFF) << 0) |\
+					(((y) & 0x03) << 16) |\
+					(((a) & 0xFF) << 8)  |\
+					(((b) & 0x03) << 24))
+
+struct nexell_mmc_plat {
+	struct mmc_config cfg;
+	struct mmc mmc;
+};
+
+struct nexell_dwmmc_priv {
+	struct clk *clk;
+	struct dwmci_host host;
+	int fifo_size;
+	bool fifo_mode;
+	int frequency;
+	u32 min_freq;
+	u32 max_freq;
+	int d_delay;
+	int d_shift;
+	int s_delay;
+	int s_shift;
+
+};
+
+struct clk *clk_get(const char *id);
+
+static void set_pin_stat(int index, int bit, int value)
+{
+#if !defined(CONFIG_SPL_BUILD)
+	nx_gpio_set_pad_function(index, bit, value);
+#else
+#if defined(CONFIG_ARCH_S5P4418) ||	\
+	defined(CONFIG_ARCH_S5P6818)
+
+	unsigned long base[5] = {
+		PHY_BASEADDR_GPIOA, PHY_BASEADDR_GPIOB,
+		PHY_BASEADDR_GPIOC, PHY_BASEADDR_GPIOD,
+		PHY_BASEADDR_GPIOE,
+	};
+
+	dw_mmc_set_pin(base[index], bit, value);
+#endif
+#endif
+}
+
+static void nx_dw_mmc_set_pin(struct dwmci_host *host)
+{
+	debug("  %s(): dev_index == %d", __func__, host->dev_index);
+
+	switch (host->dev_index) {
+	case 0:
+		set_pin_stat(0, 29, 1);
+		set_pin_stat(0, 31, 1);
+		set_pin_stat(1, 1, 1);
+		set_pin_stat(1, 3, 1);
+		set_pin_stat(1, 5, 1);
+		set_pin_stat(1, 7, 1);
+		break;
+	case 1:
+		set_pin_stat(3, 22, 1);
+		set_pin_stat(3, 23, 1);
+		set_pin_stat(3, 24, 1);
+		set_pin_stat(3, 25, 1);
+		set_pin_stat(3, 26, 1);
+		set_pin_stat(3, 27, 1);
+		break;
+	case 2:
+		set_pin_stat(2, 18, 2);
+		set_pin_stat(2, 19, 2);
+		set_pin_stat(2, 20, 2);
+		set_pin_stat(2, 21, 2);
+		set_pin_stat(2, 22, 2);
+		set_pin_stat(2, 23, 2);
+		if (host->buswidth == 8) {
+			set_pin_stat(4, 21, 2);
+			set_pin_stat(4, 22, 2);
+			set_pin_stat(4, 23, 2);
+			set_pin_stat(4, 24, 2);
+		}
+		break;
+	default:
+		debug(" is invalid!");
+	}
+	debug("\n");
+}
+
+static void nx_dw_mmc_clksel(struct dwmci_host *host)
+{
+	u32 val;
+
+#ifdef CONFIG_BOOST_MMC
+	val = DWMCI_SET_SAMPLE_CLK(DWMCI_SHIFT_0) |
+	    DWMCI_SET_DRV_CLK(DWMCI_SHIFT_0) | DWMCI_SET_DIV_RATIO(1);
+#else
+	val = DWMCI_SET_SAMPLE_CLK(DWMCI_SHIFT_0) |
+	    DWMCI_SET_DRV_CLK(DWMCI_SHIFT_0) | DWMCI_SET_DIV_RATIO(3);
+#endif
+
+	dwmci_writel(host, DWMCI_CLKSEL, val);
+}
+
+static void nx_dw_mmc_reset(int ch)
+{
+	int rst_id = RESET_ID_SDMMC0 + ch;
+
+	nx_rstcon_setrst(rst_id, 0);
+	nx_rstcon_setrst(rst_id, 1);
+}
+
+static void nx_dw_mmc_clk_delay(struct udevice *dev)
+{
+	unsigned int delay;
+	struct nexell_dwmmc_priv *priv = dev_get_priv(dev);
+	struct dwmci_host *host = &priv->host;
+
+	delay = NX_MMC_CLK_DELAY(priv->d_delay,
+				 priv->d_shift, priv->s_delay, priv->s_shift);
+
+	writel(delay, (host->ioaddr + DWMCI_CLKCTRL));
+	debug("%s(): Values set: d_delay==%d, d_shift==%d, s_delay==%d, "
+	      "s_shift==%d\n", __func__, priv->d_delay, priv->d_shift,
+	      priv->s_delay, priv->s_shift);
+}
+
+static unsigned int nx_dw_mmc_get_clk(struct dwmci_host *host, uint freq)
+{
+	struct clk *clk;
+	struct udevice *dev = host->priv;
+	struct nexell_dwmmc_priv *priv = dev_get_priv(dev);
+
+	int index = host->dev_index;
+	char name[50] = { 0, };
+
+	clk = priv->clk;
+	if (!clk) {
+		sprintf(name, "%s.%d", DEV_NAME_SDHC, index);
+		clk = clk_get((const char *)name);
+		if (!clk)
+			return 0;
+		priv->clk = clk;
+	}
+
+	return clk_get_rate(clk) / 2;
+}
+
+static unsigned long nx_dw_mmc_set_clk(struct dwmci_host *host,
+				       unsigned int rate)
+{
+	struct clk *clk;
+	char name[50] = { 0, };
+	struct udevice *dev = host->priv;
+	struct nexell_dwmmc_priv *priv = dev_get_priv(dev);
+
+	int index = host->dev_index;
+
+	clk = priv->clk;
+	if (!clk) {
+		sprintf(name, "%s.%d", DEV_NAME_SDHC, index);
+		clk = clk_get((const char *)name);
+		if (!clk)
+			return 0;
+		priv->clk = clk;
+	}
+
+	clk_disable(clk);
+	rate = clk_set_rate(clk, rate);
+	clk_enable(clk);
+
+	return rate;
+}
+
+static int nexell_dwmmc_ofdata_to_platdata(struct udevice *dev)
+{
+	/* if (dev): *priv = dev->priv, else: *priv = NULL */
+	struct nexell_dwmmc_priv *priv = dev_get_priv(dev);
+	struct dwmci_host *host = &priv->host;
+	int val = -1;
+
+	debug("%s()\n", __func__);
+
+	host->name = dev->name;
+	host->ioaddr = dev_read_addr_ptr(dev);
+
+	val = dev_read_u32_default(dev, "nexell,bus-width", -1);
+	if (val < 0) {
+		debug("  'nexell,bus-width' missing/invalid!\n");
+		return -EINVAL;
+	}
+	host->buswidth = val;
+	host->get_mmc_clk = nx_dw_mmc_get_clk;
+	host->clksel = nx_dw_mmc_clksel;
+	host->priv = dev;
+
+	val = dev_read_u32_default(dev, "index", -1);
+	if (val < 0) {
+		debug("  'index' missing/invalid!\n");
+		return -EINVAL;
+	}
+	host->dev_index = val;
+
+	val = dev_read_u32_default(dev, "fifo-size", 0x20);
+	if (val <= 0) {
+		debug("  'fifo-size' missing/invalid!\n");
+		return -EINVAL;
+	}
+	priv->fifo_size = val;
+
+	priv->fifo_mode = dev_read_bool(dev, "fifo-mode");
+
+	val = dev_read_u32_default(dev, "frequency", -1);
+	if (val < 0) {
+		debug("  'frequency' missing/invalid!\n");
+		return -EINVAL;
+	}
+	priv->frequency = val;
+
+	val = dev_read_u32_default(dev, "max-frequency", -1);
+	if (val < 0) {
+		debug("  'max-frequency' missing/invalid!\n");
+		return -EINVAL;
+	}
+	priv->max_freq = val;
+	priv->min_freq = 400000;  /* 400 kHz */
+
+	val = dev_read_u32_default(dev, "nexell,drive_dly", -1);
+	if (val < 0) {
+		debug("  'nexell,drive_dly' missing/invalid!\n");
+		return -EINVAL;
+	}
+	priv->d_delay = val;
+
+	val = dev_read_u32_default(dev, "nexell,drive_shift", -1);
+	if (val < 0) {
+		debug("  'nexell,drive_shift' missing/invalid!\n");
+		return -EINVAL;
+	}
+	priv->d_shift = val;
+
+	val = dev_read_u32_default(dev, "nexell,sample_dly", -1);
+	if (val < 0) {
+		debug("  'nexell,sample_dly' missing/invalid!\n");
+		return -EINVAL;
+	}
+	priv->s_delay = val;
+
+	val = dev_read_u32_default(dev, "nexell,sample_shift", -1);
+	if (val < 0) {
+		debug("  'nexell,sample_shift' missing/invalid!\n");
+		return -EINVAL;
+	}
+	priv->s_shift = val;
+
+	debug("  index==%d, name==%s, ioaddr==0x%08x, buswidth==%d, "
+		  "fifo_size==%d, fifo_mode==%d, frequency==%d\n",
+		  host->dev_index, host->name, (u32)host->ioaddr,
+		  host->buswidth, priv->fifo_size, priv->fifo_mode,
+		  priv->frequency);
+	debug("  min_freq==%d, max_freq==%d, delay: "
+		  "0x%02x:0x%02x:0x%02x:0x%02x\n",
+		  priv->min_freq, priv->max_freq, priv->d_delay,
+		  priv->d_shift, priv->s_delay, priv->s_shift);
+
+	return 0;
+}
+
+static int nexell_dwmmc_probe(struct udevice *dev)
+{
+	struct nexell_mmc_plat *plat = dev_get_platdata(dev);
+	struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
+	struct nexell_dwmmc_priv *priv = dev_get_priv(dev);
+	struct dwmci_host *host = &priv->host;
+	struct udevice *pwr_dev __maybe_unused;
+
+	debug("%s():\n", __func__);
+
+	host->fifoth_val = MSIZE(0x2) |
+		RX_WMARK(priv->fifo_size / 2 - 1) |
+		TX_WMARK(priv->fifo_size / 2);
+
+	host->fifo_mode = priv->fifo_mode;
+
+	dwmci_setup_cfg(&plat->cfg, host, priv->max_freq, priv->min_freq);
+	host->mmc = &plat->mmc;
+	host->mmc->priv = &priv->host;
+	host->mmc->dev = dev;
+	upriv->mmc = host->mmc;
+
+	nx_dw_mmc_set_pin(host);
+
+	debug("  nx_dw_mmc_set_clk(host, frequency * 4 == %d)\n",
+	      priv->frequency * 4);
+	nx_dw_mmc_set_clk(host, priv->frequency * 4);
+
+	nx_dw_mmc_reset(host->dev_index);
+	nx_dw_mmc_clk_delay(dev);
+
+	return dwmci_probe(dev);
+}
+
+static int nexell_dwmmc_bind(struct udevice *dev)
+{
+	struct nexell_mmc_plat *plat = dev_get_platdata(dev);
+
+	return dwmci_bind(dev, &plat->mmc, &plat->cfg);
+}
+
+static const struct udevice_id nexell_dwmmc_ids[] = {
+	{ .compatible = "nexell,nexell-dwmmc" },
+	{ }
+};
+
+U_BOOT_DRIVER(nexell_dwmmc_drv) = {
+	.name		= "nexell_dwmmc",
+	.id		= UCLASS_MMC,
+	.of_match	= nexell_dwmmc_ids,
+	.ofdata_to_platdata = nexell_dwmmc_ofdata_to_platdata,
+	.ops		= &dm_dwmci_ops,
+	.bind		= nexell_dwmmc_bind,
+	.probe		= nexell_dwmmc_probe,
+	.priv_auto_alloc_size = sizeof(struct nexell_dwmmc_priv),
+	.platdata_auto_alloc_size = sizeof(struct nexell_mmc_plat),
+};
drivers/pwm/Makefile +1 -0
index a837c35..b45aada 100644
@@ -16,3 +16,4 @@ obj-$(CONFIG_PWM_ROCKCHIP)	+= rk_pwm.o
  obj-$(CONFIG_PWM_SANDBOX)	+= sandbox_pwm.o
  obj-$(CONFIG_PWM_TEGRA)		+= tegra_pwm.o
  obj-$(CONFIG_PWM_SUNXI)		+= sunxi_pwm.o
+obj-$(CONFIG_PWM_NX)		+= pwm-nexell.o
drivers/pwm/pwm-nexell.c new file +252 -0
new file mode 100644
index 0000000..6c0f8f4
@@ -0,0 +1,252 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2011 Samsung Electronics
+ *
+ * Donghwa Lee <[email protected]>
+ */
+
+/* This codes are copied from arch/arm/cpu/armv7/s5p-common/pwm.c */
+
+#include <common.h>
+#include <errno.h>
+#include <pwm.h>
+#include <asm/io.h>
+#include <asm/arch/clk.h>
+#include "pwm-nexell.h"
+
+#if defined(CONFIG_ARCH_NEXELL)
+#include <asm/arch/nexell.h>
+#include <asm/arch/reset.h>
+#include <asm/arch/nx_gpio.h>
+#include <asm/arch/tieoff.h>
+
+struct pwm_device {
+	int ch;
+	int grp;
+	int bit;
+	int pwm_fn;
+};
+
+static struct pwm_device pwm_dev[] = {
+	[0] = { .ch = 0, .grp = 3, .bit = 1,  .pwm_fn = 1 },
+	[1] = { .ch = 1, .grp = 2, .bit = 13, .pwm_fn = 2 },
+	[2] = { .ch = 2, .grp = 2, .bit = 14, .pwm_fn =	2 },
+	[3] = { .ch = 3, .grp = 3, .bit = 0,  .pwm_fn = 2 },
+};
+#endif
+
+int pwm_enable(int pwm_id)
+{
+	const struct s5p_timer *pwm =
+#if defined(CONFIG_ARCH_NEXELL)
+			(struct s5p_timer *)PHY_BASEADDR_PWM;
+#else
+			(struct s5p_timer *)samsung_get_base_timer();
+#endif
+	unsigned long tcon;
+
+	tcon = readl(&pwm->tcon);
+	tcon |= TCON_START(pwm_id);
+
+	writel(tcon, &pwm->tcon);
+
+	return 0;
+}
+
+void pwm_disable(int pwm_id)
+{
+	const struct s5p_timer *pwm =
+#if defined(CONFIG_ARCH_NEXELL)
+			(struct s5p_timer *)PHY_BASEADDR_PWM;
+#else
+			(struct s5p_timer *)samsung_get_base_timer();
+#endif
+	unsigned long tcon;
+
+	tcon = readl(&pwm->tcon);
+	tcon &= ~TCON_START(pwm_id);
+
+	writel(tcon, &pwm->tcon);
+}
+
+static unsigned long pwm_calc_tin(int pwm_id, unsigned long freq)
+{
+	unsigned long tin_parent_rate;
+	unsigned int div;
+#if defined(CONFIG_ARCH_NEXELL)
+	unsigned int pre_div;
+	const struct s5p_timer *pwm =
+		(struct s5p_timer *)PHY_BASEADDR_PWM;
+	unsigned int val;
+#endif
+
+#if defined(CONFIG_ARCH_NEXELL)
+	struct clk *clk = clk_get(CORECLK_NAME_PCLK);
+
+	tin_parent_rate = clk_get_rate(clk);
+#else
+	tin_parent_rate = get_pwm_clk();
+#endif
+
+#if defined(CONFIG_ARCH_NEXELL)
+	writel(0, &pwm->tcfg0);
+	val = readl(&pwm->tcfg0);
+
+	if (pwm_id < 2)
+		div = ((val >> 0) & 0xff) + 1;
+	else
+		div = ((val >> 8) & 0xff) + 1;
+
+	writel(0, &pwm->tcfg1);
+	val = readl(&pwm->tcfg1);
+	val = (val >> MUX_DIV_SHIFT(pwm_id)) & 0xF;
+	pre_div = (1UL << val);
+
+	freq = tin_parent_rate / div / pre_div;
+
+	return freq;
+#else
+	for (div = 2; div <= 16; div *= 2) {
+		if ((tin_parent_rate / (div << 16)) < freq)
+			return tin_parent_rate / div;
+	}
+
+	return tin_parent_rate / 16;
+#endif
+}
+
+#define NS_IN_SEC 1000000000UL
+
+int pwm_config(int pwm_id, int duty_ns, int period_ns)
+{
+	const struct s5p_timer *pwm =
+#if defined(CONFIG_ARCH_NEXELL)
+		(struct s5p_timer *)PHY_BASEADDR_PWM;
+#else
+		(struct s5p_timer *)samsung_get_base_timer();
+#endif
+	unsigned int offset;
+	unsigned long tin_rate;
+	unsigned long tin_ns;
+	unsigned long frequency;
+	unsigned long tcon;
+	unsigned long tcnt;
+	unsigned long tcmp;
+
+	/*
+	 * We currently avoid using 64bit arithmetic by using the
+	 * fact that anything faster than 1GHz is easily representable
+	 * by 32bits.
+	 */
+	if (period_ns > NS_IN_SEC || duty_ns > NS_IN_SEC || period_ns == 0)
+		return -ERANGE;
+
+	if (duty_ns > period_ns)
+		return -EINVAL;
+
+	frequency = NS_IN_SEC / period_ns;
+
+	/* Check to see if we are changing the clock rate of the PWM */
+	tin_rate = pwm_calc_tin(pwm_id, frequency);
+
+	tin_ns = NS_IN_SEC / tin_rate;
+#if defined(CONFIG_ARCH_NEXELL)
+	/* The counter starts at zero. */
+	tcnt = (period_ns / tin_ns) - 1;
+#else
+	tcnt = period_ns / tin_ns;
+#endif
+
+	/* Note, counters count down */
+	tcmp = duty_ns / tin_ns;
+	tcmp = tcnt - tcmp;
+
+	/* Update the PWM register block. */
+	offset = pwm_id * 3;
+	if (pwm_id < 4) {
+		writel(tcnt, &pwm->tcntb0 + offset);
+		writel(tcmp, &pwm->tcmpb0 + offset);
+	}
+
+	tcon = readl(&pwm->tcon);
+	tcon |= TCON_UPDATE(pwm_id);
+	if (pwm_id < 4)
+		tcon |= TCON_AUTO_RELOAD(pwm_id);
+	else
+		tcon |= TCON4_AUTO_RELOAD;
+	writel(tcon, &pwm->tcon);
+
+	tcon &= ~TCON_UPDATE(pwm_id);
+	writel(tcon, &pwm->tcon);
+
+	return 0;
+}
+
+int pwm_init(int pwm_id, int div, int invert)
+{
+	u32 val;
+	const struct s5p_timer *pwm =
+#if defined(CONFIG_ARCH_NEXELL)
+			(struct s5p_timer *)PHY_BASEADDR_PWM;
+#else
+			(struct s5p_timer *)samsung_get_base_timer();
+#endif
+	unsigned long ticks_per_period;
+	unsigned int offset, prescaler;
+
+	/*
+	 * Timer Freq(HZ) =
+	 *	PWM_CLK / { (prescaler_value + 1) * (divider_value) }
+	 */
+
+	val = readl(&pwm->tcfg0);
+	if (pwm_id < 2) {
+		prescaler = PRESCALER_0;
+		val &= ~0xff;
+		val |= (prescaler & 0xff);
+	} else {
+		prescaler = PRESCALER_1;
+		val &= ~(0xff << 8);
+		val |= (prescaler & 0xff) << 8;
+	}
+	writel(val, &pwm->tcfg0);
+	val = readl(&pwm->tcfg1);
+	val &= ~(0xf << MUX_DIV_SHIFT(pwm_id));
+	val |= (div & 0xf) << MUX_DIV_SHIFT(pwm_id);
+	writel(val, &pwm->tcfg1);
+
+	if (pwm_id == 4) {
+		/*
+		 * TODO(sjg): Use this as a countdown timer for now. We count
+		 * down from the maximum value to 0, then reset.
+		 */
+		ticks_per_period = -1UL;
+	} else {
+		const unsigned long pwm_hz = 1000;
+#if defined(CONFIG_ARCH_NEXELL)
+		struct clk *clk = clk_get(CORECLK_NAME_PCLK);
+		unsigned long timer_rate_hz = clk_get_rate(clk) /
+#else
+		unsigned long timer_rate_hz = get_pwm_clk() /
+#endif
+			((prescaler + 1) * (1 << div));
+
+		ticks_per_period = timer_rate_hz / pwm_hz;
+	}
+
+	/* set count value */
+	offset = pwm_id * 3;
+
+	writel(ticks_per_period, &pwm->tcntb0 + offset);
+
+	val = readl(&pwm->tcon) & ~(0xf << TCON_OFFSET(pwm_id));
+	if (invert && pwm_id < 4)
+		val |= TCON_INVERTER(pwm_id);
+	writel(val, &pwm->tcon);
+
+	nx_gpio_set_pad_function(pwm_dev[pwm_id].grp, pwm_dev[pwm_id].bit,
+				 pwm_dev[pwm_id].pwm_fn);
+	pwm_enable(pwm_id);
+
+	return 0;
+}
drivers/pwm/pwm-nexell.h new file +54 -0
new file mode 100644
index 0000000..92dc707
@@ -0,0 +1,54 @@
+/* SPDX-License-Identifier: GPL-2.0+
+ *
+ * Copyright (C) 2009 Samsung Electronics
+ * Kyungmin Park <[email protected]>
+ * Minkyu Kang <[email protected]>
+ */
+
+#ifndef __ASM_ARM_ARCH_PWM_H_
+#define __ASM_ARM_ARCH_PWM_H_
+
+#define PRESCALER_0		(8 - 1)		/* prescaler of timer 0, 1 */
+#define PRESCALER_1		(16 - 1)	/* prescaler of timer 2, 3, 4 */
+
+/* Divider MUX */
+#define MUX_DIV_1		0		/* 1/1 period */
+#define MUX_DIV_2		1		/* 1/2 period */
+#define MUX_DIV_4		2		/* 1/4 period */
+#define MUX_DIV_8		3		/* 1/8 period */
+#define MUX_DIV_16		4		/* 1/16 period */
+
+#define MUX_DIV_SHIFT(x)	((x) * 4)
+
+#define TCON_OFFSET(x)		(((x) + 1) * (!!x) << 2)
+
+#define TCON_START(x)		(1 << TCON_OFFSET(x))
+#define TCON_UPDATE(x)		(1 << (TCON_OFFSET(x) + 1))
+#define TCON_INVERTER(x)	(1 << (TCON_OFFSET(x) + 2))
+#define TCON_AUTO_RELOAD(x)	(1 << (TCON_OFFSET(x) + 3))
+#define TCON4_AUTO_RELOAD	(1 << 22)
+
+#ifndef __ASSEMBLY__
+struct s5p_timer {
+	unsigned int	tcfg0;
+	unsigned int	tcfg1;
+	unsigned int	tcon;
+	unsigned int	tcntb0;
+	unsigned int	tcmpb0;
+	unsigned int	tcnto0;
+	unsigned int	tcntb1;
+	unsigned int	tcmpb1;
+	unsigned int	tcnto1;
+	unsigned int	tcntb2;
+	unsigned int	tcmpb2;
+	unsigned int	tcnto2;
+	unsigned int	tcntb3;
+	unsigned int	res1;
+	unsigned int	tcnto3;
+	unsigned int	tcntb4;
+	unsigned int	tcnto4;
+	unsigned int	tintcstat;
+};
+#endif	/* __ASSEMBLY__ */
+
+#endif
Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: hs at denx.de
author
#5 lore raw

RFC PATCH 3/10 i2c: mmc: add nexell driver (gpio, i2c, mmc, pwm)

Hello Heiko,

thanks a lot for your annotations and suggestions. I will have a look at them and give you feedback ASAP.

Regards
Stefan

Am 04.02.20 um 07:58 schrieb Heiko Schocher:

Quoted 1,668 lines

Hello Stefan,

Am 03.02.2020 um 21:40 schrieb Stefan Bosch:

Quoted 8 lines

Changes in relation to FriendlyARM's U-Boot nanopi2-v2016.01:
- i2c/nx_i2c.c: Some adaptions mainly because of changes in "struct udevice".
- mmc: nexell_dw_mmc.c changed to nexell_dw_mmc_dm.c (switched to DM).

---

Quoted 13 lines

  drivers/gpio/Kconfig           |   9 + drivers/gpio/Makefile          |   1 + drivers/gpio/nx_gpio.c         | 252 +++++++++++++++++++ drivers/i2c/Kconfig            |   9 + drivers/i2c/Makefile           |   1 + drivers/i2c/nx_i2c.c           | 537
+++++++++++++++++++++++++++++++++++++++++
  drivers/mmc/Kconfig            |   6 + drivers/mmc/Makefile           |   1 + drivers/mmc/nexell_dw_mmc_dm.c | 350 +++++++++++++++++++++++++++ drivers/pwm/Makefile           |   1 + drivers/pwm/pwm-nexell.c       | 252 +++++++++++++++++++ drivers/pwm/pwm-nexell.h       |  54 +++++

Could you please split this patch into 4 parts (i2c, gpio, mmc and pwm) ?

Thanks!

Quoted 7 lines
  12 files changed, 1473 insertions(+)

  create mode 100644 drivers/gpio/nx_gpio.c create mode 100644 drivers/i2c/nx_i2c.c create mode 100644 drivers/mmc/nexell_dw_mmc_dm.c create mode 100644 drivers/pwm/pwm-nexell.c create mode 100644 drivers/pwm/pwm-nexell.h

[...]

Quoted 9 lines
drivers/gpio/Makefile +0 -0
index 449046b..e3340de 100644
@@ -65,3 +65,4 @@ obj-$(CONFIG_PM8916_GPIO)    += pm8916_gpio.o

  obj-$(CONFIG_MT7621_GPIO)    += mt7621_gpio.o
  obj-$(CONFIG_MSCC_SGPIO)    += mscc_sgpio.o
  obj-$(CONFIG_SIFIVE_GPIO)    += sifive-gpio.o
+obj-$(CONFIG_NX_GPIO)        += nx_gpio.o

Please keep lists sorted.

Quoted 330 lines
drivers/gpio/nx_gpio.c new file +57 -0
new file mode 100644
index 0000000..86472f6
@@ -0,0 +1,252 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2016 Nexell
+ * DeokJin, Lee <[email protected]>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <errno.h>
+#include <malloc.h>
+#include <fdtdec.h>
+#include <asm/io.h>
+#include <asm/gpio.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+struct nx_gpio_regs {
+    u32    data;        /* Data register */
+    u32    outputenb;    /* Output Enable register */
+    u32    detmode[2];    /* Detect Mode Register */
+    u32    intenb;        /* Interrupt Enable Register */
+    u32    det;        /* Event Detect Register */
+    u32    pad;        /* Pad Status Register */
+};
+
+struct nx_alive_gpio_regs {
+    u32    pwrgate;    /* Power Gating Register */
+    u32    reserved0[28];    /* Reserved0 */
+    u32    outputenb_reset;/* Alive GPIO Output Enable Reset Register */
+    u32    outputenb;    /* Alive GPIO Output Enable Register */
+    u32    outputenb_read; /* Alive GPIO Output Read Register */
+    u32    reserved1[3];    /* Reserved1 */
+    u32    pad_reset;    /* Alive GPIO Output Reset Register */
+    u32    data;        /* Alive GPIO Output Register */
+    u32    pad_read;    /* Alive GPIO Pad Read Register */
+    u32    reserved2[33];    /* Reserved2 */
+    u32    pad;        /* Alive GPIO Input Value Register */
+};
+
+struct nx_gpio_platdata {
+    void *regs;
+    int gpio_count;
+    const char *bank_name;
+};
+
+static int nx_alive_gpio_is_check(struct udevice *dev)
+{
+    struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+    const char *bank_name = plat->bank_name;
+
+    if (!strcmp(bank_name, "gpio_alv"))
+        return 1;
+
+    return 0;
+}
+
+static int nx_alive_gpio_direction_input(struct udevice *dev, 

unsigned int pin)

drivers/gpio/nx_gpio.c new file +10 -0
+{
+    struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+    struct nx_alive_gpio_regs *const regs = plat->regs;
+
+    setbits_le32(&regs->outputenb_reset, 1 << pin);
+
+    return 0;
+}
+
+static int nx_alive_gpio_direction_output(struct udevice *dev, 

unsigned int pin,
+                      int val)

drivers/gpio/nx_gpio.c new file +15 -0
+{
+    struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+    struct nx_alive_gpio_regs *const regs = plat->regs;
+
+    if (val)
+        setbits_le32(&regs->data, 1 << pin);
+    else
+        setbits_le32(&regs->pad_reset, 1 << pin);
+
+    setbits_le32(&regs->outputenb, 1 << pin);
+
+    return 0;
+}
+
+static int nx_alive_gpio_get_value(struct udevice *dev, unsigned int 

pin)

drivers/gpio/nx_gpio.c new file +12 -0
+{
+    struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+    struct nx_alive_gpio_regs *const regs = plat->regs;
+    unsigned int mask = 1UL << pin;
+    unsigned int value;
+
+    value = (readl(&regs->pad_read) & mask) >> pin;
+
+    return value;
+}
+
+static int nx_alive_gpio_set_value(struct udevice *dev, unsigned int 

pin,
+                   int val)

drivers/gpio/nx_gpio.c new file +13 -0
+{
+    struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+    struct nx_alive_gpio_regs *const regs = plat->regs;
+
+    if (val)
+        setbits_le32(&regs->data, 1 << pin);
+    else
+        clrbits_le32(&regs->pad_reset, 1 << pin);
+
+    return 0;
+}
+
+static int nx_alive_gpio_get_function(struct udevice *dev, unsigned 

int pin)

drivers/gpio/nx_gpio.c new file +15 -0
+{
+    struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+    struct nx_alive_gpio_regs *const regs = plat->regs;
+    unsigned int mask = (1UL << pin);
+    unsigned int output;
+
+    output = readl(&regs->outputenb_read) & mask;
+
+    if (output)
+        return GPIOF_OUTPUT;
+    else
+        return GPIOF_INPUT;
+}
+
+static int nx_gpio_direction_input(struct udevice *dev, unsigned int 

pin)

drivers/gpio/nx_gpio.c new file +13 -0
+{
+    struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+    struct nx_gpio_regs *const regs = plat->regs;
+
+    if (nx_alive_gpio_is_check(dev))
+        return nx_alive_gpio_direction_input(dev, pin);
+
+    clrbits_le32(&regs->outputenb, 1 << pin);
+
+    return 0;
+}
+
+static int nx_gpio_direction_output(struct udevice *dev, unsigned 

int pin,
+                    int val)

drivers/gpio/nx_gpio.c new file +33 -0
+{
+    struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+    struct nx_gpio_regs *const regs = plat->regs;
+
+    if (nx_alive_gpio_is_check(dev))
+        return nx_alive_gpio_direction_output(dev, pin, val);
+
+    if (val)
+        setbits_le32(&regs->data, 1 << pin);
+    else
+        clrbits_le32(&regs->data, 1 << pin);
+
+    setbits_le32(&regs->outputenb, 1 << pin);
+
+    return 0;
+}
+
+static int nx_gpio_get_value(struct udevice *dev, unsigned int pin)
+{
+    struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+    struct nx_gpio_regs *const regs = plat->regs;
+    unsigned int mask = 1UL << pin;
+    unsigned int value;
+
+    if (nx_alive_gpio_is_check(dev))
+        return nx_alive_gpio_get_value(dev, pin);
+
+    value = (readl(&regs->pad) & mask) >> pin;
+
+    return value;
+}
+
+static int nx_gpio_set_value(struct udevice *dev, unsigned int pin, 

int val)

drivers/gpio/nx_gpio.c new file +81 -0
+{
+    struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+    struct nx_gpio_regs *const regs = plat->regs;
+
+    if (nx_alive_gpio_is_check(dev))
+        return nx_alive_gpio_set_value(dev, pin, val);
+
+    if (val)
+        setbits_le32(&regs->data, 1 << pin);
+    else
+        clrbits_le32(&regs->data, 1 << pin);
+
+    return 0;
+}
+
+static int nx_gpio_get_function(struct udevice *dev, unsigned int pin)
+{
+    struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+    struct nx_gpio_regs *const regs = plat->regs;
+    unsigned int mask = (1UL << pin);
+    unsigned int output;
+
+    if (nx_alive_gpio_is_check(dev))
+        return nx_alive_gpio_get_function(dev, pin);
+
+    output = readl(&regs->outputenb) & mask;
+
+    if (output)
+        return GPIOF_OUTPUT;
+    else
+        return GPIOF_INPUT;
+}
+
+static int nx_gpio_probe(struct udevice *dev)
+{
+    struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
+    struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+
+    uc_priv->gpio_count = plat->gpio_count;
+    uc_priv->bank_name = plat->bank_name;
+
+    return 0;
+}
+
+static int nx_gpio_ofdata_to_platdata(struct udevice *dev)
+{
+    struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+
+    plat->regs = map_physmem(devfdt_get_addr(dev),
+                 sizeof(struct nx_gpio_regs),
+                 MAP_NOCACHE);
+    plat->gpio_count = fdtdec_get_int(gd->fdt_blob, dev->node.of_offset,
+                      "nexell,gpio-bank-width", 32);
+    plat->bank_name = fdt_getprop(gd->fdt_blob, dev->node.of_offset,
+                      "gpio-bank-name", NULL);
+
+    return 0;
+}
+
+static const struct dm_gpio_ops nx_gpio_ops = {
+    .direction_input    = nx_gpio_direction_input,
+    .direction_output    = nx_gpio_direction_output,
+    .get_value        = nx_gpio_get_value,
+    .set_value        = nx_gpio_set_value,
+    .get_function        = nx_gpio_get_function,
+};
+
+static const struct udevice_id nx_gpio_ids[] = {
+    { .compatible = "nexell,nexell-gpio" },
+    { }
+};
+
+U_BOOT_DRIVER(nx_gpio) = {
+    .name        = "nx_gpio",
+    .id        = UCLASS_GPIO,
+    .of_match    = nx_gpio_ids,
+    .ops        = &nx_gpio_ops,
+    .ofdata_to_platdata = nx_gpio_ofdata_to_platdata,
+    .platdata_auto_alloc_size = sizeof(struct nx_gpio_platdata),
+    .probe        = nx_gpio_probe,
+};
drivers/i2c/Kconfig +0 -0
index 03d2fed..2cd0ed3 100644
@@ -317,6 +317,15 @@ config SYS_MXC_I2C8_SLAVE

       MXC I2C8 Slave
  endif
  +config SYS_I2C_NEXELL
+    bool "Nexell I2C driver"
+    depends on DM_I2C
+    help
+      Add support for the Nexell I2C driver. This is used with various +      Nexell parts such as S5Pxx18 series SoCs. All chips
+      have several I2C ports and all are provided, controlled by the +      device tree.
+
  config SYS_I2C_OMAP24XX
      bool "TI OMAP2+ I2C driver"
      depends on ARCH_OMAP2PLUS || ARCH_K3

drivers/i2c/Makefile +0 -0
index f5a471f..64b8ead 100644
@@ -26,6 +26,7 @@ obj-$(CONFIG_SYS_I2C_LPC32XX) += lpc32xx_i2c.o

  obj-$(CONFIG_SYS_I2C_MESON) += meson_i2c.o obj-$(CONFIG_SYS_I2C_MVTWSI) += mvtwsi.o obj-$(CONFIG_SYS_I2C_MXC) += mxc_i2c.o +obj-$(CONFIG_SYS_I2C_NEXELL) += nx_i2c.o obj-$(CONFIG_SYS_I2C_OMAP24XX) += omap24xx_i2c.o obj-$(CONFIG_SYS_I2C_RCAR_I2C) += rcar_i2c.o obj-$(CONFIG_SYS_I2C_RCAR_IIC) += rcar_iic.o

drivers/i2c/nx_i2c.c new file +27 -0
new file mode 100644
index 0000000..a3eec6c
@@ -0,0 +1,537 @@
+#include <common.h>
+#include <errno.h>
+#include <dm.h>
+#include <i2c.h>
+#include <asm/arch/nexell.h>
+#include <asm/arch/reset.h>
+#include <asm/arch/clk.h>
+#include <asm/arch/nx_gpio.h>
+
+#define I2C_WRITE       0
+#define I2C_READ        1
+
+#define I2C_OK          0
+#define I2C_NOK         1
+#define I2C_NACK        2
+#define I2C_NOK_LA      3       /* Lost arbitration */
+#define I2C_NOK_TOUT    4       /* time out */
+
+#define I2CLC_FILTER    0x04    /* SDA filter on*/
+#define I2CSTAT_BSY     0x20    /* Busy bit */
+#define I2CSTAT_NACK    0x01    /* Nack bit */
+#define I2CSTAT_ABT    0x08    /* Arbitration bit */
+#define I2CCON_ACKGEN   0x80    /* Acknowledge generation */
+#define I2CCON_IRENB    0x20    /* Interrupt Enable bit  */
+#define I2CCON_IRPND    0x10    /* Interrupt pending bit */
+#define I2C_MODE_MT     0xC0    /* Master Transmit Mode */
+#define I2C_MODE_MR     0x80    /* Master Receive Mode */

drivers/i2c/nx_i2c.c line 37

Quoted 10 lines
drivers/i2c/nx_i2c.c new file +10 -0
+#define I2C_START_STOP  0x20    /* START / STOP */
+#define I2C_TXRX_ENA    0x10    /* I2C Tx/Rx enable */
+
+#define I2C_TIMEOUT_MS    10      /* 10 ms */
+
+#define I2C_M_NOSTOP    0x100
+
+#ifndef CONFIG_MAX_I2C_NUM
+#define CONFIG_MAX_I2C_NUM 3
+#endif

Is this really configurable? If so, I do not find the Kconfig description.

Quoted 38 lines
drivers/i2c/nx_i2c.c new file +38 -0
+
+DECLARE_GLOBAL_DATA_PTR;
+
+struct nx_i2c_regs {
+    uint     iiccon;
+    uint     iicstat;
+    uint     iicadd;
+    uint     iicds;
+    uint     iiclc;
+};
+
+struct nx_i2c_bus {
+    uint bus_num;
+    struct nx_i2c_regs *regs;
+    uint speed;
+    uint target_speed;
+    uint sda_delay;
+};
+
+/* s5pxx18 i2c must be reset before enabled */
+static void i2c_reset(int ch)
+{
+    int rst_id = RESET_ID_I2C0 + ch;
+
+    nx_rstcon_setrst(rst_id, 0);
+    nx_rstcon_setrst(rst_id, 1);
+}
+
+/* FIXME : this func will be removed after reset dm driver ported.
+ * set mmc pad alternative func.
+ */
+static void set_i2c_pad_func(struct nx_i2c_bus *i2c)
+{
+    switch (i2c->bus_num) {
+    case 0:
+        nx_gpio_set_pad_function(3, 2, 1);
+        nx_gpio_set_pad_function(3, 3, 1);
+        break;

drivers/i2c/nx_i2c.c line 85

Quoted 10 lines
drivers/i2c/nx_i2c.c new file +10 -0
+    case 1:
+        nx_gpio_set_pad_function(3, 4, 1);
+        nx_gpio_set_pad_function(3, 5, 1);
+        break;
+    case 2:
+        nx_gpio_set_pad_function(3, 6, 1);
+        nx_gpio_set_pad_function(3, 7, 1);
+        break;
+    }
+}

Hmm... may this should be moved into a seperate pincontrol driver?

drivers/i2c/nx_i2c.c line 91

Quoted 6 lines
drivers/i2c/nx_i2c.c new file +6 -0
+
+static uint i2c_get_clkrate(struct nx_i2c_bus *bus)
+{
+    struct clk *clk;
+    int index = bus->bus_num;
+    char name[50] = {0, };

?

drivers/i2c/nx_i2c.c line 93

Quoted 2 lines
drivers/i2c/nx_i2c.c new file +2 -0
+
+    sprintf(name, "%s.%d", DEV_NAME_I2C, index);

Where is DEV_NAME_I2C defined ?

Quoted 32 lines
drivers/i2c/nx_i2c.c new file +32 -0
+    clk = clk_get((const char *)name);
+    if (!clk)
+        return -1;
+
+    return clk_get_rate(clk);
+}
+
+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)
+        return -1;
+
+    if (enb) {
+        clk_disable(clk);
+        clk_enable(clk);
+    } else {
+        clk_disable(clk);
+    }
+
+    return 0;
+}
+
+/* get i2c module number from base address */
+static uint i2c_get_busnum(struct nx_i2c_bus *bus)
+{
+    void *base_addr = (void *)PHY_BASEADDR_I2C0;
+    int i;

drivers/i2c/nx_i2c.c line 135

Quoted 10 lines
drivers/i2c/nx_i2c.c new file +10 -0
+
+    for (i = 0; i < CONFIG_MAX_I2C_NUM; i++) {
+        if (base_addr == ((void *)bus->regs)) {
+            bus->bus_num = i;
+            return i;
+        }
+        base_addr += 0x1000;
+    }
+
+    return -1;

return -ENODEV;

Hmm... is there no chance to use seq from struct udevice

https://gitlab.denx.de/u-boot/u-boot/blob/master/include/dm/device.h#L152

?

For example like:
https://gitlab.denx.de/u-boot/u-boot/blob/master/drivers/i2c/mxc_i2c.c#L895

Quoted 43 lines
drivers/i2c/nx_i2c.c new file +26 -0
+}
+
+/* Set SDA line delay */
+static int nx_i2c_set_sda_delay(struct nx_i2c_bus *bus, ulong clkin)
+{
+    struct nx_i2c_regs *i2c = bus->regs;
+    uint sda_delay = 0;
+
+    if (bus->sda_delay) {
+        sda_delay = clkin * bus->sda_delay;
+        sda_delay = DIV_ROUND_UP(sda_delay, 1000000);
+        sda_delay = DIV_ROUND_UP(sda_delay, 5);
+        if (sda_delay > 3)
+            sda_delay = 3;
+        sda_delay |= I2CLC_FILTER;
+    } else {
+        sda_delay = 0;
+    }
+
+    sda_delay &= 0x7;
+    writel(sda_delay, &i2c->iiclc);
+
+    return 0;
+}
+
+/* Calculate the value of the divider and prescaler, set the bus 

speed. */

drivers/i2c/nx_i2c.c new file +16 -0
+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 freq, pres = 16, div;
+
+    freq = i2c_get_clkrate(bus);
+    /* calculate prescaler and divisor values */
+    if ((freq / pres / (16 + 1)) > speed)
+        /* set prescaler to 512 */
+        pres = 512;
+
+    div = 0;
+    while ((freq / pres / (div + 1)) > speed)
+        div++;
+

drivers/i2c/nx_i2c.c line 187

Quoted 10 lines
drivers/i2c/nx_i2c.c new file +10 -0
+    /* set prescaler, divisor according to freq, also set ACKGEN, IRQ */
+    writel((div & 0x0F) | ((pres == 512) ? 0x40 : 0), &i2c->iiccon);
+
+    /* init to SLAVE REVEIVE and set slaveaddr */
+    writel(0, &i2c->iicstat);
+    writel(0x00, &i2c->iicadd);
+    /* program Master Transmit (and implicit STOP) */
+    writel(I2C_MODE_MT | I2C_TXRX_ENA, &i2c->iicstat);
+
+    bus->speed = bus->target_speed / (div * pres);

Do you want to allow all values of speeds or may you want to use standard speeds, see:

https://gitlab.denx.de/u-boot/u-boot/blob/master/include/i2c.h#L33

Quoted 18 lines
drivers/i2c/nx_i2c.c new file +18 -0
+
+    return 0;
+}
+
+static void nx_i2c_set_clockrate(struct udevice *dev, uint speed)
+{
+    struct nx_i2c_bus *bus = dev_get_priv(dev);
+    ulong clkin;
+
+    nx_i2c_set_bus_speed(dev, speed);
+    clkin = bus->speed;            /* the actual i2c speed */
+    clkin /= 1000;                /* clkin now in Khz */
+    nx_i2c_set_sda_delay(bus, clkin);
+}
+
+static void i2c_process_node(struct udevice *dev)
+{
+    struct nx_i2c_bus *bus = dev_get_priv(dev);

drivers/i2c/nx_i2c.c line 215

Quoted 10 lines
drivers/i2c/nx_i2c.c new file +10 -0
+    const void *blob = gd->fdt_blob;
+
+    int node;
+
+    node = dev->node.of_offset;
+
+    bus->target_speed = fdtdec_get_int(blob, node,
+                       "nexell,i2c-max-bus-freq", 0);
+    bus->sda_delay = fdtdec_get_int(blob, node,
+                    "nexell,i2c-sda-delay", 0);

You introdue here new properties, please document them in u-boot:/doc/device-tree-bindings/i2c

Please without "nexell,"

Do you plan to post also a linux i2c driver?

If so, the devicetree bindings should be discussed there to avoid different properties between U-Boot and linux!

drivers/i2c/nx_i2c.c line 227

Quoted 12 lines
drivers/i2c/nx_i2c.c new file +12 -0
+}
+
+static int nx_i2c_probe(struct udevice *dev)
+{
+    struct nx_i2c_bus *bus = dev_get_priv(dev);
+
+    /* get regs */
+    bus->regs = (struct nx_i2c_regs *)devfdt_get_addr(dev);
+    /* calc index */
+    if (!i2c_get_busnum(bus)) {
+        debug("not found i2c number!\n");
+        return -1;

please return -ENODEV

Quoted 6 lines

+    }
+
+    /* i2c optional node parsing */
+    i2c_process_node(dev);
+    if (!bus->target_speed)
+        return -1;

please return here also an errorcode from include/linux/errno.h

Hmm.. if you return here if target_speed is not set, it is not optional!

Quoted 284 lines
drivers/i2c/nx_i2c.c new file +251 -0
+
+    /* reset */
+    i2c_reset(bus->bus_num);
+    /* gpio pad */
+    set_i2c_pad_func(bus);
+
+    /* clock rate */
+    i2c_set_clk(bus, 1);
+    nx_i2c_set_clockrate(dev, bus->target_speed);
+    i2c_set_clk(bus, 0);
+
+    return 0;
+}
+
+/* i2c bus busy check */
+static int i2c_is_busy(struct nx_i2c_regs *i2c)
+{
+    ulong start_time;
+
+    start_time = get_timer(0);
+    while (readl(&i2c->iicstat) & I2CSTAT_BSY) {
+        if (get_timer(start_time) > I2C_TIMEOUT_MS) {
+            debug("Timeout\n");
+            return -I2C_NOK_TOUT;
+        }
+    }
+    return 0;
+}
+
+/* irq enable/disable functions */
+static void i2c_enable_irq(struct nx_i2c_regs *i2c)
+{
+    unsigned int reg;
+
+    reg = readl(&i2c->iiccon);
+    reg |= I2CCON_IRENB;
+    writel(reg, &i2c->iiccon);
+}
+
+/* irq clear function */
+static void i2c_clear_irq(struct nx_i2c_regs *i2c)
+{
+    clrbits_le32(&i2c->iiccon, I2CCON_IRPND);
+}
+
+/* ack enable functions */
+static void i2c_enable_ack(struct nx_i2c_regs *i2c)
+{
+    unsigned int reg;
+
+    reg = readl(&i2c->iiccon);
+    reg |= I2CCON_ACKGEN;
+    writel(reg, &i2c->iiccon);
+}
+
+static void i2c_send_stop(struct nx_i2c_regs *i2c)
+{
+    unsigned int reg;
+
+    /* Send STOP. */
+    reg = readl(&i2c->iicstat);
+    reg |= I2C_MODE_MR | I2C_TXRX_ENA;
+    reg &= (~I2C_START_STOP);
+    writel(reg, &i2c->iicstat);
+    i2c_clear_irq(i2c);
+}
+
+static int wait_for_xfer(struct nx_i2c_regs *i2c)
+{
+    unsigned long start_time = get_timer(0);
+
+    do {
+        if (readl(&i2c->iiccon) & I2CCON_IRPND)
+            return (readl(&i2c->iicstat) & I2CSTAT_NACK) ?
+                I2C_NACK : I2C_OK;
+    } while (get_timer(start_time) < I2C_TIMEOUT_MS);
+
+    return I2C_NOK_TOUT;
+}
+
+static int i2c_transfer(struct nx_i2c_regs *i2c,
+            uchar cmd_type,
+            uchar chip,
+            uchar addr[],
+            uchar addr_len,
+            uchar data[],
+            unsigned short data_len,
+            uint seq)
+{
+    uint status;
+    int i = 0, result;
+
+    if (data == 0 || data_len == 0) {
+        /*Don't support data transfer of no length or to address 0 */
+        debug("%s: bad call\n", __func__);
+        return I2C_NOK;
+    }
+
+    i2c_enable_irq(i2c);
+    i2c_enable_ack(i2c);
+
+    /* Get the slave chip address going */
+    writel(chip, &i2c->iicds);
+    status = I2C_TXRX_ENA | I2C_START_STOP;
+    if (cmd_type == I2C_WRITE || (addr && addr_len))
+        status |= I2C_MODE_MT;
+    else
+        status |= I2C_MODE_MR;
+    writel(status, &i2c->iicstat);
+    if (seq)
+        i2c_clear_irq(i2c);
+
+    /* Wait for chip address to transmit. */
+    result = wait_for_xfer(i2c);
+    if (result != I2C_OK)
+        goto bailout;
+
+    /* If register address needs to be transmitted - do it now. */
+    if (addr && addr_len) {  /* register addr */
+        while ((i < addr_len) && (result == I2C_OK)) {
+            writel(addr[i++], &i2c->iicds);
+            i2c_clear_irq(i2c);
+            result = wait_for_xfer(i2c);
+        }
+
+        i = 0;
+        if (result != I2C_OK)
+            goto bailout;
+    }
+
+    switch (cmd_type) {
+    case I2C_WRITE:
+        while ((i < data_len) && (result == I2C_OK)) {
+            writel(data[i++], &i2c->iicds);
+            i2c_clear_irq(i2c);
+            result = wait_for_xfer(i2c);
+        }
+        break;
+    case I2C_READ:
+        if (addr && addr_len) {
+            /*
+             * Register address has been sent, now send slave chip
+             * address again to start the actual read transaction.
+             */
+            writel(chip, &i2c->iicds);
+
+            /* Generate a re-START. */
+            writel(I2C_MODE_MR | I2C_TXRX_ENA
+                    | I2C_START_STOP, &i2c->iicstat);
+            i2c_clear_irq(i2c);
+            result = wait_for_xfer(i2c);
+            if (result != I2C_OK)
+                goto bailout;
+        }
+
+        while ((i < data_len) && (result == I2C_OK)) {
+            /* disable ACK for final READ */
+            if (i == data_len - 1)
+                clrbits_le32(&i2c->iiccon
+                        , I2CCON_ACKGEN);
+
+            i2c_clear_irq(i2c);
+            result = wait_for_xfer(i2c);
+            data[i++] = readb(&i2c->iicds);
+        }
+
+        if (result == I2C_NACK)
+            result = I2C_OK; /* Normal terminated read. */
+        break;
+
+    default:
+        debug("%s: bad call\n", __func__);
+        result = I2C_NOK;
+        break;
+    }
+
+bailout:
+    return result;
+}
+
+static int nx_i2c_read(struct udevice *dev, uchar chip, uint addr,
+               uint alen, uchar *buffer, uint len, uint seq)
+{
+    struct nx_i2c_bus *i2c;
+    uchar xaddr[4];
+    int ret;
+
+    i2c = dev_get_priv(dev);
+    if (!i2c)
+        return -EFAULT;
+
+    if (alen > 4) {
+        debug("I2C read: addr len %d not supported\n", alen);
+        return -EADDRNOTAVAIL;
+    }
+
+    if (alen > 0)
+        xaddr[0] = (addr >> 24) & 0xFF;
+
+    if (alen > 0) {
+        xaddr[0] = (addr >> 24) & 0xFF;
+        xaddr[1] = (addr >> 16) & 0xFF;
+        xaddr[2] = (addr >> 8) & 0xFF;
+        xaddr[3] = addr & 0xFF;
+    }
+
+    ret = i2c_transfer(i2c->regs, I2C_READ, chip << 1,
+               &xaddr[4 - alen], alen, buffer, len, seq);
+
+    if (ret) {
+        debug("I2C read failed %d\n", ret);
+        return -EIO;
+    }
+
+    return 0;
+}
+
+static int nx_i2c_write(struct udevice *dev, uchar chip, uint addr,
+            uint alen, uchar *buffer, uint len, uint seq)
+{
+    struct nx_i2c_bus *i2c;
+    uchar xaddr[4];
+    int ret;
+
+    i2c = dev_get_priv(dev);
+    if (!i2c)
+        return -EFAULT;
+
+    if (alen > 4) {
+        debug("I2C write: addr len %d not supported\n", alen);
+        return -EINVAL;
+    }
+
+    if (alen > 0) {
+        xaddr[0] = (addr >> 24) & 0xFF;
+        xaddr[1] = (addr >> 16) & 0xFF;
+        xaddr[2] = (addr >> 8) & 0xFF;
+        xaddr[3] = addr & 0xFF;
+    }
+
+    ret = i2c_transfer(i2c->regs, I2C_WRITE, chip << 1,
+               &xaddr[4 - alen], alen, buffer, len, seq);
+    if (ret) {
+        debug("I2C write failed %d\n", ret);
+        return -EIO;
+    }
+
+    return 0;
+}
+
+static int nx_i2c_xfer(struct udevice *dev, struct i2c_msg *msg, int 

nmsgs)

drivers/i2c/nx_i2c.c new file +32 -0
+{
+    struct nx_i2c_bus *bus = dev_get_priv(dev);
+    struct nx_i2c_regs *i2c = bus->regs;
+    int ret;
+    int i;
+
+    /* The power loss by the clock, only during on/off. */
+    i2c_set_clk(bus, 1);
+
+    /* Bus State(Busy) check  */
+    ret = i2c_is_busy(i2c);
+    if (ret < 0)
+        return ret;
+
+    for (i = 0; i < nmsgs; msg++, i++) {
+        if (msg->flags & I2C_M_RD) {
+            ret = nx_i2c_read(dev, msg->addr, 0, 0, msg->buf,
+                      msg->len, i);
+        } else {
+            ret = nx_i2c_write(dev, msg->addr, 0, 0, msg->buf,
+                       msg->len, i);
+        }
+
+        if (ret) {
+            debug("i2c_xfer: error sending\n");
+            return -EREMOTEIO;
+        }
+    }
+    /* Send Stop */
+    i2c_send_stop(i2c);
+    i2c_set_clk(bus, 0);
+

drivers/i2c/nx_i2c.c line 526

Quoted 10 lines
drivers/i2c/nx_i2c.c new file +10 -0
+    return ret ? -EREMOTEIO : 0;
+};
+
+static const struct dm_i2c_ops nx_i2c_ops = {
+    .xfer        = nx_i2c_xfer,
+    .set_bus_speed    = nx_i2c_set_bus_speed,
+};
+
+static const struct udevice_id nx_i2c_ids[] = {
+    { .compatible = "nexell,s5pxx18-i2c" },

Same here as for the new properties. Please discuss the names on

devicetree at vger.kernel.org <[email protected]>

first!

drivers/i2c/nx_i2c.c line 537

Quoted 11 lines

+    { }

drivers/i2c/nx_i2c.c new file +10 -0
+};
+
+U_BOOT_DRIVER(i2c_nexell) = {
+    .name        = "i2c_nexell",
+    .id        = UCLASS_I2C,
+    .of_match    = nx_i2c_ids,
+    .probe        = nx_i2c_probe,
+    .priv_auto_alloc_size    = sizeof(struct nx_i2c_bus),
+    .ops        = &nx_i2c_ops,
+};

bye,
Heiko

Quoted 714 lines
drivers/mmc/Kconfig +0 -0
index 2f0eedc..bb8e7c0 100644
@@ -253,6 +253,12 @@ config MMC_DW_SNPS

        This selects support for Synopsys DesignWare Memory Card Interface driver
        extensions used in various Synopsys ARC devboards. +config NEXELL_DWMMC
+    bool "Nexell SD/MMC controller support"
+    depends on ARCH_NEXELL
+    depends on MMC_DW
+    default y
+
  config MMC_MESON_GX
      bool "Meson GX EMMC controller support"
      depends on DM_MMC && BLK && ARCH_MESON

drivers/mmc/Makefile +0 -0
index 9c1f8e5..a7b5a7b 100644
@@ -43,6 +43,7 @@ obj-$(CONFIG_SH_MMCIF) += sh_mmcif.o

  obj-$(CONFIG_SH_SDHI) += sh_sdhi.o
  obj-$(CONFIG_STM32_SDMMC2) += stm32_sdmmc2.o
  obj-$(CONFIG_JZ47XX_MMC) += jz_mmc.o
+obj-$(CONFIG_NEXELL_DWMMC) += nexell_dw_mmc_dm.o
    # SDHCI
  obj-$(CONFIG_MMC_SDHCI)            += sdhci.o

drivers/mmc/nexell_dw_mmc_dm.c new file +153 -0
new file mode 100644
index 0000000..b06b60d
@@ -0,0 +1,350 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2016 Nexell
+ * Youngbok, Park <[email protected]>
+ *
+ * (C) Copyright 2019 Stefan Bosch <[email protected]>
+ */
+
+#include <common.h>
+#include <clk.h>
+#include <dm.h>
+#include <dt-structs.h>
+#include <dwmmc.h>
+#include <syscon.h>
+#include <asm/gpio.h>
+#include <asm/arch/nx_gpio.h>
+#include <asm/arch/reset.h>
+
+#define DWMCI_CLKSEL            0x09C
+#define DWMCI_SHIFT_0            0x0
+#define DWMCI_SHIFT_1            0x1
+#define DWMCI_SHIFT_2            0x2
+#define DWMCI_SHIFT_3            0x3
+#define DWMCI_SET_SAMPLE_CLK(x)    (x)
+#define DWMCI_SET_DRV_CLK(x)    ((x) << 16)
+#define DWMCI_SET_DIV_RATIO(x)    ((x) << 24)
+#define DWMCI_CLKCTRL            0x114
+#define NX_MMC_CLK_DELAY(x, y, a, b)    ((((x) & 0xFF) << 0) |\
+                    (((y) & 0x03) << 16) |\
+                    (((a) & 0xFF) << 8)  |\
+                    (((b) & 0x03) << 24))
+
+struct nexell_mmc_plat {
+    struct mmc_config cfg;
+    struct mmc mmc;
+};
+
+struct nexell_dwmmc_priv {
+    struct clk *clk;
+    struct dwmci_host host;
+    int fifo_size;
+    bool fifo_mode;
+    int frequency;
+    u32 min_freq;
+    u32 max_freq;
+    int d_delay;
+    int d_shift;
+    int s_delay;
+    int s_shift;
+
+};
+
+struct clk *clk_get(const char *id);
+
+static void set_pin_stat(int index, int bit, int value)
+{
+#if !defined(CONFIG_SPL_BUILD)
+    nx_gpio_set_pad_function(index, bit, value);
+#else
+#if defined(CONFIG_ARCH_S5P4418) ||    \
+    defined(CONFIG_ARCH_S5P6818)
+
+    unsigned long base[5] = {
+        PHY_BASEADDR_GPIOA, PHY_BASEADDR_GPIOB,
+        PHY_BASEADDR_GPIOC, PHY_BASEADDR_GPIOD,
+        PHY_BASEADDR_GPIOE,
+    };
+
+    dw_mmc_set_pin(base[index], bit, value);
+#endif
+#endif
+}
+
+static void nx_dw_mmc_set_pin(struct dwmci_host *host)
+{
+    debug("  %s(): dev_index == %d", __func__, host->dev_index);
+
+    switch (host->dev_index) {
+    case 0:
+        set_pin_stat(0, 29, 1);
+        set_pin_stat(0, 31, 1);
+        set_pin_stat(1, 1, 1);
+        set_pin_stat(1, 3, 1);
+        set_pin_stat(1, 5, 1);
+        set_pin_stat(1, 7, 1);
+        break;
+    case 1:
+        set_pin_stat(3, 22, 1);
+        set_pin_stat(3, 23, 1);
+        set_pin_stat(3, 24, 1);
+        set_pin_stat(3, 25, 1);
+        set_pin_stat(3, 26, 1);
+        set_pin_stat(3, 27, 1);
+        break;
+    case 2:
+        set_pin_stat(2, 18, 2);
+        set_pin_stat(2, 19, 2);
+        set_pin_stat(2, 20, 2);
+        set_pin_stat(2, 21, 2);
+        set_pin_stat(2, 22, 2);
+        set_pin_stat(2, 23, 2);
+        if (host->buswidth == 8) {
+            set_pin_stat(4, 21, 2);
+            set_pin_stat(4, 22, 2);
+            set_pin_stat(4, 23, 2);
+            set_pin_stat(4, 24, 2);
+        }
+        break;
+    default:
+        debug(" is invalid!");
+    }
+    debug("\n");
+}
+
+static void nx_dw_mmc_clksel(struct dwmci_host *host)
+{
+    u32 val;
+
+#ifdef CONFIG_BOOST_MMC
+    val = DWMCI_SET_SAMPLE_CLK(DWMCI_SHIFT_0) |
+        DWMCI_SET_DRV_CLK(DWMCI_SHIFT_0) | DWMCI_SET_DIV_RATIO(1);
+#else
+    val = DWMCI_SET_SAMPLE_CLK(DWMCI_SHIFT_0) |
+        DWMCI_SET_DRV_CLK(DWMCI_SHIFT_0) | DWMCI_SET_DIV_RATIO(3);
+#endif
+
+    dwmci_writel(host, DWMCI_CLKSEL, val);
+}
+
+static void nx_dw_mmc_reset(int ch)
+{
+    int rst_id = RESET_ID_SDMMC0 + ch;
+
+    nx_rstcon_setrst(rst_id, 0);
+    nx_rstcon_setrst(rst_id, 1);
+}
+
+static void nx_dw_mmc_clk_delay(struct udevice *dev)
+{
+    unsigned int delay;
+    struct nexell_dwmmc_priv *priv = dev_get_priv(dev);
+    struct dwmci_host *host = &priv->host;
+
+    delay = NX_MMC_CLK_DELAY(priv->d_delay,
+                 priv->d_shift, priv->s_delay, priv->s_shift);
+
+    writel(delay, (host->ioaddr + DWMCI_CLKCTRL));
+    debug("%s(): Values set: d_delay==%d, d_shift==%d, s_delay==%d, "
+          "s_shift==%d\n", __func__, priv->d_delay, priv->d_shift,
+          priv->s_delay, priv->s_shift);
+}
+
+static unsigned int nx_dw_mmc_get_clk(struct dwmci_host *host, uint 

freq)

drivers/mmc/nexell_dw_mmc_dm.c new file +197 -0
+{
+    struct clk *clk;
+    struct udevice *dev = host->priv;
+    struct nexell_dwmmc_priv *priv = dev_get_priv(dev);
+
+    int index = host->dev_index;
+    char name[50] = { 0, };
+
+    clk = priv->clk;
+    if (!clk) {
+        sprintf(name, "%s.%d", DEV_NAME_SDHC, index);
+        clk = clk_get((const char *)name);
+        if (!clk)
+            return 0;
+        priv->clk = clk;
+    }
+
+    return clk_get_rate(clk) / 2;
+}
+
+static unsigned long nx_dw_mmc_set_clk(struct dwmci_host *host,
+                       unsigned int rate)
+{
+    struct clk *clk;
+    char name[50] = { 0, };
+    struct udevice *dev = host->priv;
+    struct nexell_dwmmc_priv *priv = dev_get_priv(dev);
+
+    int index = host->dev_index;
+
+    clk = priv->clk;
+    if (!clk) {
+        sprintf(name, "%s.%d", DEV_NAME_SDHC, index);
+        clk = clk_get((const char *)name);
+        if (!clk)
+            return 0;
+        priv->clk = clk;
+    }
+
+    clk_disable(clk);
+    rate = clk_set_rate(clk, rate);
+    clk_enable(clk);
+
+    return rate;
+}
+
+static int nexell_dwmmc_ofdata_to_platdata(struct udevice *dev)
+{
+    /* if (dev): *priv = dev->priv, else: *priv = NULL */
+    struct nexell_dwmmc_priv *priv = dev_get_priv(dev);
+    struct dwmci_host *host = &priv->host;
+    int val = -1;
+
+    debug("%s()\n", __func__);
+
+    host->name = dev->name;
+    host->ioaddr = dev_read_addr_ptr(dev);
+
+    val = dev_read_u32_default(dev, "nexell,bus-width", -1);
+    if (val < 0) {
+        debug("  'nexell,bus-width' missing/invalid!\n");
+        return -EINVAL;
+    }
+    host->buswidth = val;
+    host->get_mmc_clk = nx_dw_mmc_get_clk;
+    host->clksel = nx_dw_mmc_clksel;
+    host->priv = dev;
+
+    val = dev_read_u32_default(dev, "index", -1);
+    if (val < 0) {
+        debug("  'index' missing/invalid!\n");
+        return -EINVAL;
+    }
+    host->dev_index = val;
+
+    val = dev_read_u32_default(dev, "fifo-size", 0x20);
+    if (val <= 0) {
+        debug("  'fifo-size' missing/invalid!\n");
+        return -EINVAL;
+    }
+    priv->fifo_size = val;
+
+    priv->fifo_mode = dev_read_bool(dev, "fifo-mode");
+
+    val = dev_read_u32_default(dev, "frequency", -1);
+    if (val < 0) {
+        debug("  'frequency' missing/invalid!\n");
+        return -EINVAL;
+    }
+    priv->frequency = val;
+
+    val = dev_read_u32_default(dev, "max-frequency", -1);
+    if (val < 0) {
+        debug("  'max-frequency' missing/invalid!\n");
+        return -EINVAL;
+    }
+    priv->max_freq = val;
+    priv->min_freq = 400000;  /* 400 kHz */
+
+    val = dev_read_u32_default(dev, "nexell,drive_dly", -1);
+    if (val < 0) {
+        debug("  'nexell,drive_dly' missing/invalid!\n");
+        return -EINVAL;
+    }
+    priv->d_delay = val;
+
+    val = dev_read_u32_default(dev, "nexell,drive_shift", -1);
+    if (val < 0) {
+        debug("  'nexell,drive_shift' missing/invalid!\n");
+        return -EINVAL;
+    }
+    priv->d_shift = val;
+
+    val = dev_read_u32_default(dev, "nexell,sample_dly", -1);
+    if (val < 0) {
+        debug("  'nexell,sample_dly' missing/invalid!\n");
+        return -EINVAL;
+    }
+    priv->s_delay = val;
+
+    val = dev_read_u32_default(dev, "nexell,sample_shift", -1);
+    if (val < 0) {
+        debug("  'nexell,sample_shift' missing/invalid!\n");
+        return -EINVAL;
+    }
+    priv->s_shift = val;
+
+    debug("  index==%d, name==%s, ioaddr==0x%08x, buswidth==%d, "
+          "fifo_size==%d, fifo_mode==%d, frequency==%d\n",
+          host->dev_index, host->name, (u32)host->ioaddr,
+          host->buswidth, priv->fifo_size, priv->fifo_mode,
+          priv->frequency);
+    debug("  min_freq==%d, max_freq==%d, delay: "
+          "0x%02x:0x%02x:0x%02x:0x%02x\n",
+          priv->min_freq, priv->max_freq, priv->d_delay,
+          priv->d_shift, priv->s_delay, priv->s_shift);
+
+    return 0;
+}
+
+static int nexell_dwmmc_probe(struct udevice *dev)
+{
+    struct nexell_mmc_plat *plat = dev_get_platdata(dev);
+    struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
+    struct nexell_dwmmc_priv *priv = dev_get_priv(dev);
+    struct dwmci_host *host = &priv->host;
+    struct udevice *pwr_dev __maybe_unused;
+
+    debug("%s():\n", __func__);
+
+    host->fifoth_val = MSIZE(0x2) |
+        RX_WMARK(priv->fifo_size / 2 - 1) |
+        TX_WMARK(priv->fifo_size / 2);
+
+    host->fifo_mode = priv->fifo_mode;
+
+    dwmci_setup_cfg(&plat->cfg, host, priv->max_freq, priv->min_freq);
+    host->mmc = &plat->mmc;
+    host->mmc->priv = &priv->host;
+    host->mmc->dev = dev;
+    upriv->mmc = host->mmc;
+
+    nx_dw_mmc_set_pin(host);
+
+    debug("  nx_dw_mmc_set_clk(host, frequency * 4 == %d)\n",
+          priv->frequency * 4);
+    nx_dw_mmc_set_clk(host, priv->frequency * 4);
+
+    nx_dw_mmc_reset(host->dev_index);
+    nx_dw_mmc_clk_delay(dev);
+
+    return dwmci_probe(dev);
+}
+
+static int nexell_dwmmc_bind(struct udevice *dev)
+{
+    struct nexell_mmc_plat *plat = dev_get_platdata(dev);
+
+    return dwmci_bind(dev, &plat->mmc, &plat->cfg);
+}
+
+static const struct udevice_id nexell_dwmmc_ids[] = {
+    { .compatible = "nexell,nexell-dwmmc" },
+    { }
+};
+
+U_BOOT_DRIVER(nexell_dwmmc_drv) = {
+    .name        = "nexell_dwmmc",
+    .id        = UCLASS_MMC,
+    .of_match    = nexell_dwmmc_ids,
+    .ofdata_to_platdata = nexell_dwmmc_ofdata_to_platdata,
+    .ops        = &dm_dwmci_ops,
+    .bind        = nexell_dwmmc_bind,
+    .probe        = nexell_dwmmc_probe,
+    .priv_auto_alloc_size = sizeof(struct nexell_dwmmc_priv),
+    .platdata_auto_alloc_size = sizeof(struct nexell_mmc_plat),
+};
drivers/pwm/Makefile +0 -0
index a837c35..b45aada 100644
@@ -16,3 +16,4 @@ obj-$(CONFIG_PWM_ROCKCHIP)    += rk_pwm.o

  obj-$(CONFIG_PWM_SANDBOX)    += sandbox_pwm.o
  obj-$(CONFIG_PWM_TEGRA)        += tegra_pwm.o
  obj-$(CONFIG_PWM_SUNXI)        += sunxi_pwm.o

drivers/pwm/Makefile +1 -0
+obj-$(CONFIG_PWM_NX)        += pwm-nexell.o
drivers/pwm/pwm-nexell.c new file +252 -0
new file mode 100644
index 0000000..6c0f8f4
@@ -0,0 +1,252 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2011 Samsung Electronics
+ *
+ * Donghwa Lee <[email protected]>
+ */
+
+/* This codes are copied from arch/arm/cpu/armv7/s5p-common/pwm.c */
+
+#include <common.h>
+#include <errno.h>
+#include <pwm.h>
+#include <asm/io.h>
+#include <asm/arch/clk.h>
+#include "pwm-nexell.h"
+
+#if defined(CONFIG_ARCH_NEXELL)
+#include <asm/arch/nexell.h>
+#include <asm/arch/reset.h>
+#include <asm/arch/nx_gpio.h>
+#include <asm/arch/tieoff.h>
+
+struct pwm_device {
+    int ch;
+    int grp;
+    int bit;
+    int pwm_fn;
+};
+
+static struct pwm_device pwm_dev[] = {
+    [0] = { .ch = 0, .grp = 3, .bit = 1,  .pwm_fn = 1 },
+    [1] = { .ch = 1, .grp = 2, .bit = 13, .pwm_fn = 2 },
+    [2] = { .ch = 2, .grp = 2, .bit = 14, .pwm_fn =    2 },
+    [3] = { .ch = 3, .grp = 3, .bit = 0,  .pwm_fn = 2 },
+};
+#endif
+
+int pwm_enable(int pwm_id)
+{
+    const struct s5p_timer *pwm =
+#if defined(CONFIG_ARCH_NEXELL)
+            (struct s5p_timer *)PHY_BASEADDR_PWM;
+#else
+            (struct s5p_timer *)samsung_get_base_timer();
+#endif
+    unsigned long tcon;
+
+    tcon = readl(&pwm->tcon);
+    tcon |= TCON_START(pwm_id);
+
+    writel(tcon, &pwm->tcon);
+
+    return 0;
+}
+
+void pwm_disable(int pwm_id)
+{
+    const struct s5p_timer *pwm =
+#if defined(CONFIG_ARCH_NEXELL)
+            (struct s5p_timer *)PHY_BASEADDR_PWM;
+#else
+            (struct s5p_timer *)samsung_get_base_timer();
+#endif
+    unsigned long tcon;
+
+    tcon = readl(&pwm->tcon);
+    tcon &= ~TCON_START(pwm_id);
+
+    writel(tcon, &pwm->tcon);
+}
+
+static unsigned long pwm_calc_tin(int pwm_id, unsigned long freq)
+{
+    unsigned long tin_parent_rate;
+    unsigned int div;
+#if defined(CONFIG_ARCH_NEXELL)
+    unsigned int pre_div;
+    const struct s5p_timer *pwm =
+        (struct s5p_timer *)PHY_BASEADDR_PWM;
+    unsigned int val;
+#endif
+
+#if defined(CONFIG_ARCH_NEXELL)
+    struct clk *clk = clk_get(CORECLK_NAME_PCLK);
+
+    tin_parent_rate = clk_get_rate(clk);
+#else
+    tin_parent_rate = get_pwm_clk();
+#endif
+
+#if defined(CONFIG_ARCH_NEXELL)
+    writel(0, &pwm->tcfg0);
+    val = readl(&pwm->tcfg0);
+
+    if (pwm_id < 2)
+        div = ((val >> 0) & 0xff) + 1;
+    else
+        div = ((val >> 8) & 0xff) + 1;
+
+    writel(0, &pwm->tcfg1);
+    val = readl(&pwm->tcfg1);
+    val = (val >> MUX_DIV_SHIFT(pwm_id)) & 0xF;
+    pre_div = (1UL << val);
+
+    freq = tin_parent_rate / div / pre_div;
+
+    return freq;
+#else
+    for (div = 2; div <= 16; div *= 2) {
+        if ((tin_parent_rate / (div << 16)) < freq)
+            return tin_parent_rate / div;
+    }
+
+    return tin_parent_rate / 16;
+#endif
+}
+
+#define NS_IN_SEC 1000000000UL
+
+int pwm_config(int pwm_id, int duty_ns, int period_ns)
+{
+    const struct s5p_timer *pwm =
+#if defined(CONFIG_ARCH_NEXELL)
+        (struct s5p_timer *)PHY_BASEADDR_PWM;
+#else
+        (struct s5p_timer *)samsung_get_base_timer();
+#endif
+    unsigned int offset;
+    unsigned long tin_rate;
+    unsigned long tin_ns;
+    unsigned long frequency;
+    unsigned long tcon;
+    unsigned long tcnt;
+    unsigned long tcmp;
+
+    /*
+     * We currently avoid using 64bit arithmetic by using the
+     * fact that anything faster than 1GHz is easily representable
+     * by 32bits.
+     */
+    if (period_ns > NS_IN_SEC || duty_ns > NS_IN_SEC || period_ns == 0)
+        return -ERANGE;
+
+    if (duty_ns > period_ns)
+        return -EINVAL;
+
+    frequency = NS_IN_SEC / period_ns;
+
+    /* Check to see if we are changing the clock rate of the PWM */
+    tin_rate = pwm_calc_tin(pwm_id, frequency);
+
+    tin_ns = NS_IN_SEC / tin_rate;
+#if defined(CONFIG_ARCH_NEXELL)
+    /* The counter starts at zero. */
+    tcnt = (period_ns / tin_ns) - 1;
+#else
+    tcnt = period_ns / tin_ns;
+#endif
+
+    /* Note, counters count down */
+    tcmp = duty_ns / tin_ns;
+    tcmp = tcnt - tcmp;
+
+    /* Update the PWM register block. */
+    offset = pwm_id * 3;
+    if (pwm_id < 4) {
+        writel(tcnt, &pwm->tcntb0 + offset);
+        writel(tcmp, &pwm->tcmpb0 + offset);
+    }
+
+    tcon = readl(&pwm->tcon);
+    tcon |= TCON_UPDATE(pwm_id);
+    if (pwm_id < 4)
+        tcon |= TCON_AUTO_RELOAD(pwm_id);
+    else
+        tcon |= TCON4_AUTO_RELOAD;
+    writel(tcon, &pwm->tcon);
+
+    tcon &= ~TCON_UPDATE(pwm_id);
+    writel(tcon, &pwm->tcon);
+
+    return 0;
+}
+
+int pwm_init(int pwm_id, int div, int invert)
+{
+    u32 val;
+    const struct s5p_timer *pwm =
+#if defined(CONFIG_ARCH_NEXELL)
+            (struct s5p_timer *)PHY_BASEADDR_PWM;
+#else
+            (struct s5p_timer *)samsung_get_base_timer();
+#endif
+    unsigned long ticks_per_period;
+    unsigned int offset, prescaler;
+
+    /*
+     * Timer Freq(HZ) =
+     *    PWM_CLK / { (prescaler_value + 1) * (divider_value) }
+     */
+
+    val = readl(&pwm->tcfg0);
+    if (pwm_id < 2) {
+        prescaler = PRESCALER_0;
+        val &= ~0xff;
+        val |= (prescaler & 0xff);
+    } else {
+        prescaler = PRESCALER_1;
+        val &= ~(0xff << 8);
+        val |= (prescaler & 0xff) << 8;
+    }
+    writel(val, &pwm->tcfg0);
+    val = readl(&pwm->tcfg1);
+    val &= ~(0xf << MUX_DIV_SHIFT(pwm_id));
+    val |= (div & 0xf) << MUX_DIV_SHIFT(pwm_id);
+    writel(val, &pwm->tcfg1);
+
+    if (pwm_id == 4) {
+        /*
+         * TODO(sjg): Use this as a countdown timer for now. We count
+         * down from the maximum value to 0, then reset.
+         */
+        ticks_per_period = -1UL;
+    } else {
+        const unsigned long pwm_hz = 1000;
+#if defined(CONFIG_ARCH_NEXELL)
+        struct clk *clk = clk_get(CORECLK_NAME_PCLK);
+        unsigned long timer_rate_hz = clk_get_rate(clk) /
+#else
+        unsigned long timer_rate_hz = get_pwm_clk() /
+#endif
+            ((prescaler + 1) * (1 << div));
+
+        ticks_per_period = timer_rate_hz / pwm_hz;
+    }
+
+    /* set count value */
+    offset = pwm_id * 3;
+
+    writel(ticks_per_period, &pwm->tcntb0 + offset);
+
+    val = readl(&pwm->tcon) & ~(0xf << TCON_OFFSET(pwm_id));
+    if (invert && pwm_id < 4)
+        val |= TCON_INVERTER(pwm_id);
+    writel(val, &pwm->tcon);
+
+    nx_gpio_set_pad_function(pwm_dev[pwm_id].grp, pwm_dev[pwm_id].bit,
+                 pwm_dev[pwm_id].pwm_fn);
+    pwm_enable(pwm_id);
+
+    return 0;
+}
drivers/pwm/pwm-nexell.h new file +54 -0
new file mode 100644
index 0000000..92dc707
@@ -0,0 +1,54 @@
+/* SPDX-License-Identifier: GPL-2.0+
+ *
+ * Copyright (C) 2009 Samsung Electronics
+ * Kyungmin Park <[email protected]>
+ * Minkyu Kang <[email protected]>
+ */
+
+#ifndef __ASM_ARM_ARCH_PWM_H_
+#define __ASM_ARM_ARCH_PWM_H_
+
+#define PRESCALER_0        (8 - 1)        /* prescaler of timer 0, 1 */
+#define PRESCALER_1        (16 - 1)    /* prescaler of timer 2, 3, 4 */
+
+/* Divider MUX */
+#define MUX_DIV_1        0        /* 1/1 period */
+#define MUX_DIV_2        1        /* 1/2 period */
+#define MUX_DIV_4        2        /* 1/4 period */
+#define MUX_DIV_8        3        /* 1/8 period */
+#define MUX_DIV_16        4        /* 1/16 period */
+
+#define MUX_DIV_SHIFT(x)    ((x) * 4)
+
+#define TCON_OFFSET(x)        (((x) + 1) * (!!x) << 2)
+
+#define TCON_START(x)        (1 << TCON_OFFSET(x))
+#define TCON_UPDATE(x)        (1 << (TCON_OFFSET(x) + 1))
+#define TCON_INVERTER(x)    (1 << (TCON_OFFSET(x) + 2))
+#define TCON_AUTO_RELOAD(x)    (1 << (TCON_OFFSET(x) + 3))
+#define TCON4_AUTO_RELOAD    (1 << 22)
+
+#ifndef __ASSEMBLY__
+struct s5p_timer {
+    unsigned int    tcfg0;
+    unsigned int    tcfg1;
+    unsigned int    tcon;
+    unsigned int    tcntb0;
+    unsigned int    tcmpb0;
+    unsigned int    tcnto0;
+    unsigned int    tcntb1;
+    unsigned int    tcmpb1;
+    unsigned int    tcnto1;
+    unsigned int    tcntb2;
+    unsigned int    tcmpb2;
+    unsigned int    tcnto2;
+    unsigned int    tcntb3;
+    unsigned int    res1;
+    unsigned int    tcnto3;
+    unsigned int    tcntb4;
+    unsigned int    tcnto4;
+    unsigned int    tintcstat;
+};
+#endif    /* __ASSEMBLY__ */
+
+#endif
author
#6 lore raw

RFC PATCH 3/10 i2c: mmc: add nexell driver (gpio, i2c, mmc, pwm)

In reply to Heiko Schocher

Hello Heiko,

see below my feedback, please give me further advise where indicated.

Unfortunately there have been some Bugs in the i2c-driver and I learned that this driver has not been used at all ("i2c-gpio" has been used instead). So I have done several Bugfixes and improvements appart from your proposals.

Regards
Stefan

Am 04.02.20 um 07:58 schrieb Heiko Schocher:

Quoted 25 lines

Hello Stefan,

Am 03.02.2020 um 21:40 schrieb Stefan Bosch:

Quoted 8 lines

Changes in relation to FriendlyARM's U-Boot nanopi2-v2016.01:
- i2c/nx_i2c.c: Some adaptions mainly because of changes in ?? "struct udevice".
- mmc: nexell_dw_mmc.c changed to nexell_dw_mmc_dm.c (switched to DM).

---

Quoted 13 lines
? drivers/gpio/Kconfig?????????? |?? 9 +
? drivers/gpio/Makefile????????? |?? 1 +
? drivers/gpio/nx_gpio.c???????? | 252 +++++++++++++++++++
? drivers/i2c/Kconfig??????????? |?? 9 +
? drivers/i2c/Makefile?????????? |?? 1 +
? drivers/i2c/nx_i2c.c?????????? | 537 
+++++++++++++++++++++++++++++++++++++++++
? drivers/mmc/Kconfig??????????? |?? 6 +
? drivers/mmc/Makefile?????????? |?? 1 +
? drivers/mmc/nexell_dw_mmc_dm.c | 350 +++++++++++++++++++++++++++
? drivers/pwm/Makefile?????????? |?? 1 +
? drivers/pwm/pwm-nexell.c?????? | 252 +++++++++++++++++++
? drivers/pwm/pwm-nexell.h?????? |? 54 +++++
Quoted 5 lines

Could you please split this patch into 4 parts (i2c, gpio, mmc and pwm) ?

Thanks!

Ok, I will split this patch.

Quoted 8 lines
Quoted 7 lines

? 12 files changed, 1473 insertions(+)
? create mode 100644 drivers/gpio/nx_gpio.c ? create mode 100644 drivers/i2c/nx_i2c.c
? create mode 100644 drivers/mmc/nexell_dw_mmc_dm.c ? create mode 100644 drivers/pwm/pwm-nexell.c ? create mode 100644 drivers/pwm/pwm-nexell.h

[...]

Quoted 11 lines
Quoted 9 lines
drivers/gpio/Makefile +0 -0
index 449046b..e3340de 100644
@@ -65,3 +65,4 @@ obj-$(CONFIG_PM8916_GPIO)??? += pm8916_gpio.o

? obj-$(CONFIG_MT7621_GPIO)??? += mt7621_gpio.o
? obj-$(CONFIG_MSCC_SGPIO)??? += mscc_sgpio.o
? obj-$(CONFIG_SIFIVE_GPIO)??? += sifive-gpio.o
+obj-$(CONFIG_NX_GPIO)??????? += nx_gpio.o

Please keep lists sorted.

The list is not sorted (at least in no alphabetical order), but I can e.g. move "... += nx_gpio.o" one line up?

Quoted 336 lines
Quoted 336 lines
drivers/gpio/nx_gpio.c new file +57 -0
new file mode 100644
index 0000000..86472f6
@@ -0,0 +1,252 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2016 Nexell
+ * DeokJin, Lee <[email protected]>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <errno.h>
+#include <malloc.h>
+#include <fdtdec.h>
+#include <asm/io.h>
+#include <asm/gpio.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+struct nx_gpio_regs {
+??? u32??? data;??????? /* Data register */
+??? u32??? outputenb;??? /* Output Enable register */
+??? u32??? detmode[2];??? /* Detect Mode Register */
+??? u32??? intenb;??????? /* Interrupt Enable Register */
+??? u32??? det;??????? /* Event Detect Register */
+??? u32??? pad;??????? /* Pad Status Register */
+};
+
+struct nx_alive_gpio_regs {
+??? u32??? pwrgate;??? /* Power Gating Register */
+??? u32??? reserved0[28];??? /* Reserved0 */
+??? u32??? outputenb_reset;/* Alive GPIO Output Enable Reset Register */
+??? u32??? outputenb;??? /* Alive GPIO Output Enable Register */
+??? u32??? outputenb_read; /* Alive GPIO Output Read Register */
+??? u32??? reserved1[3];??? /* Reserved1 */
+??? u32??? pad_reset;??? /* Alive GPIO Output Reset Register */
+??? u32??? data;??????? /* Alive GPIO Output Register */
+??? u32??? pad_read;??? /* Alive GPIO Pad Read Register */
+??? u32??? reserved2[33];??? /* Reserved2 */
+??? u32??? pad;??????? /* Alive GPIO Input Value Register */
+};
+
+struct nx_gpio_platdata {
+??? void *regs;
+??? int gpio_count;
+??? const char *bank_name;
+};
+
+static int nx_alive_gpio_is_check(struct udevice *dev)
+{
+??? struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+??? const char *bank_name = plat->bank_name;
+
+??? if (!strcmp(bank_name, "gpio_alv"))
+??????? return 1;
+
+??? return 0;
+}
+
+static int nx_alive_gpio_direction_input(struct udevice *dev, 

unsigned int pin)

drivers/gpio/nx_gpio.c new file +10 -0
+{
+??? struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+??? struct nx_alive_gpio_regs *const regs = plat->regs;
+
+??? setbits_le32(&regs->outputenb_reset, 1 << pin);
+
+??? return 0;
+}
+
+static int nx_alive_gpio_direction_output(struct udevice *dev, 

unsigned int pin,
+????????????????????? int val)

drivers/gpio/nx_gpio.c new file +15 -0
+{
+??? struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+??? struct nx_alive_gpio_regs *const regs = plat->regs;
+
+??? if (val)
+??????? setbits_le32(&regs->data, 1 << pin);
+??? else
+??????? setbits_le32(&regs->pad_reset, 1 << pin);
+
+??? setbits_le32(&regs->outputenb, 1 << pin);
+
+??? return 0;
+}
+
+static int nx_alive_gpio_get_value(struct udevice *dev, unsigned int 

pin)

drivers/gpio/nx_gpio.c new file +12 -0
+{
+??? struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+??? struct nx_alive_gpio_regs *const regs = plat->regs;
+??? unsigned int mask = 1UL << pin;
+??? unsigned int value;
+
+??? value = (readl(&regs->pad_read) & mask) >> pin;
+
+??? return value;
+}
+
+static int nx_alive_gpio_set_value(struct udevice *dev, unsigned int 

pin,
+?????????????????? int val)

drivers/gpio/nx_gpio.c new file +13 -0
+{
+??? struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+??? struct nx_alive_gpio_regs *const regs = plat->regs;
+
+??? if (val)
+??????? setbits_le32(&regs->data, 1 << pin);
+??? else
+??????? clrbits_le32(&regs->pad_reset, 1 << pin);
+
+??? return 0;
+}
+
+static int nx_alive_gpio_get_function(struct udevice *dev, unsigned 

int pin)

drivers/gpio/nx_gpio.c new file +15 -0
+{
+??? struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+??? struct nx_alive_gpio_regs *const regs = plat->regs;
+??? unsigned int mask = (1UL << pin);
+??? unsigned int output;
+
+??? output = readl(&regs->outputenb_read) & mask;
+
+??? if (output)
+??????? return GPIOF_OUTPUT;
+??? else
+??????? return GPIOF_INPUT;
+}
+
+static int nx_gpio_direction_input(struct udevice *dev, unsigned int 

pin)

drivers/gpio/nx_gpio.c new file +13 -0
+{
+??? struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+??? struct nx_gpio_regs *const regs = plat->regs;
+
+??? if (nx_alive_gpio_is_check(dev))
+??????? return nx_alive_gpio_direction_input(dev, pin);
+
+??? clrbits_le32(&regs->outputenb, 1 << pin);
+
+??? return 0;
+}
+
+static int nx_gpio_direction_output(struct udevice *dev, unsigned int 

pin,
+??????????????????? int val)

drivers/gpio/nx_gpio.c new file +33 -0
+{
+??? struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+??? struct nx_gpio_regs *const regs = plat->regs;
+
+??? if (nx_alive_gpio_is_check(dev))
+??????? return nx_alive_gpio_direction_output(dev, pin, val);
+
+??? if (val)
+??????? setbits_le32(&regs->data, 1 << pin);
+??? else
+??????? clrbits_le32(&regs->data, 1 << pin);
+
+??? setbits_le32(&regs->outputenb, 1 << pin);
+
+??? return 0;
+}
+
+static int nx_gpio_get_value(struct udevice *dev, unsigned int pin)
+{
+??? struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+??? struct nx_gpio_regs *const regs = plat->regs;
+??? unsigned int mask = 1UL << pin;
+??? unsigned int value;
+
+??? if (nx_alive_gpio_is_check(dev))
+??????? return nx_alive_gpio_get_value(dev, pin);
+
+??? value = (readl(&regs->pad) & mask) >> pin;
+
+??? return value;
+}
+
+static int nx_gpio_set_value(struct udevice *dev, unsigned int pin, 

int val)

drivers/gpio/nx_gpio.c new file +81 -0
+{
+??? struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+??? struct nx_gpio_regs *const regs = plat->regs;
+
+??? if (nx_alive_gpio_is_check(dev))
+??????? return nx_alive_gpio_set_value(dev, pin, val);
+
+??? if (val)
+??????? setbits_le32(&regs->data, 1 << pin);
+??? else
+??????? clrbits_le32(&regs->data, 1 << pin);
+
+??? return 0;
+}
+
+static int nx_gpio_get_function(struct udevice *dev, unsigned int pin)
+{
+??? struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+??? struct nx_gpio_regs *const regs = plat->regs;
+??? unsigned int mask = (1UL << pin);
+??? unsigned int output;
+
+??? if (nx_alive_gpio_is_check(dev))
+??????? return nx_alive_gpio_get_function(dev, pin);
+
+??? output = readl(&regs->outputenb) & mask;
+
+??? if (output)
+??????? return GPIOF_OUTPUT;
+??? else
+??????? return GPIOF_INPUT;
+}
+
+static int nx_gpio_probe(struct udevice *dev)
+{
+??? struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
+??? struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+
+??? uc_priv->gpio_count = plat->gpio_count;
+??? uc_priv->bank_name = plat->bank_name;
+
+??? return 0;
+}
+
+static int nx_gpio_ofdata_to_platdata(struct udevice *dev)
+{
+??? struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+
+??? plat->regs = map_physmem(devfdt_get_addr(dev),
+???????????????? sizeof(struct nx_gpio_regs),
+???????????????? MAP_NOCACHE);
+??? plat->gpio_count = fdtdec_get_int(gd->fdt_blob, dev->node.of_offset,
+????????????????????? "nexell,gpio-bank-width", 32);
+??? plat->bank_name = fdt_getprop(gd->fdt_blob, dev->node.of_offset,
+????????????????????? "gpio-bank-name", NULL);
+
+??? return 0;
+}
+
+static const struct dm_gpio_ops nx_gpio_ops = {
+??? .direction_input??? = nx_gpio_direction_input,
+??? .direction_output??? = nx_gpio_direction_output,
+??? .get_value??????? = nx_gpio_get_value,
+??? .set_value??????? = nx_gpio_set_value,
+??? .get_function??????? = nx_gpio_get_function,
+};
+
+static const struct udevice_id nx_gpio_ids[] = {
+??? { .compatible = "nexell,nexell-gpio" },
+??? { }
+};
+
+U_BOOT_DRIVER(nx_gpio) = {
+??? .name??????? = "nx_gpio",
+??? .id??????? = UCLASS_GPIO,
+??? .of_match??? = nx_gpio_ids,
+??? .ops??????? = &nx_gpio_ops,
+??? .ofdata_to_platdata = nx_gpio_ofdata_to_platdata,
+??? .platdata_auto_alloc_size = sizeof(struct nx_gpio_platdata),
+??? .probe??????? = nx_gpio_probe,
+};
drivers/i2c/Kconfig +0 -0
index 03d2fed..2cd0ed3 100644
@@ -317,6 +317,15 @@ config SYS_MXC_I2C8_SLAVE

?????? MXC I2C8 Slave
? endif

drivers/i2c/Kconfig +9 -0
+config SYS_I2C_NEXELL
+??? bool "Nexell I2C driver"
+??? depends on DM_I2C
+??? help
+????? Add support for the Nexell I2C driver. This is used with various
+????? Nexell parts such as S5Pxx18 series SoCs. All chips
+????? have several I2C ports and all are provided, controlled by the
+????? device tree.
+

? config SYS_I2C_OMAP24XX
????? bool "TI OMAP2+ I2C driver"
????? depends on ARCH_OMAP2PLUS || ARCH_K3

drivers/i2c/Makefile +0 -0
index f5a471f..64b8ead 100644
@@ -26,6 +26,7 @@ obj-$(CONFIG_SYS_I2C_LPC32XX) += lpc32xx_i2c.o

? obj-$(CONFIG_SYS_I2C_MESON) += meson_i2c.o ? obj-$(CONFIG_SYS_I2C_MVTWSI) += mvtwsi.o ? obj-$(CONFIG_SYS_I2C_MXC) += mxc_i2c.o +obj-$(CONFIG_SYS_I2C_NEXELL) += nx_i2c.o ? obj-$(CONFIG_SYS_I2C_OMAP24XX) += omap24xx_i2c.o ? obj-$(CONFIG_SYS_I2C_RCAR_I2C) += rcar_i2c.o ? obj-$(CONFIG_SYS_I2C_RCAR_IIC) += rcar_iic.o

drivers/i2c/nx_i2c.c new file +32 -0
new file mode 100644
index 0000000..a3eec6c
@@ -0,0 +1,537 @@
+#include <common.h>
+#include <errno.h>
+#include <dm.h>
+#include <i2c.h>
+#include <asm/arch/nexell.h>
+#include <asm/arch/reset.h>
+#include <asm/arch/clk.h>
+#include <asm/arch/nx_gpio.h>
+
+#define I2C_WRITE?????? 0
+#define I2C_READ??????? 1
+
+#define I2C_OK????????? 0
+#define I2C_NOK???????? 1
+#define I2C_NACK??????? 2
+#define I2C_NOK_LA????? 3?????? /* Lost arbitration */
+#define I2C_NOK_TOUT??? 4?????? /* time out */
+
+#define I2CLC_FILTER??? 0x04??? /* SDA filter on*/
+#define I2CSTAT_BSY???? 0x20??? /* Busy bit */
+#define I2CSTAT_NACK??? 0x01??? /* Nack bit */
+#define I2CSTAT_ABT??? 0x08??? /* Arbitration bit */
+#define I2CCON_ACKGEN?? 0x80??? /* Acknowledge generation */
+#define I2CCON_IRENB??? 0x20??? /* Interrupt Enable bit? */
+#define I2CCON_IRPND??? 0x10??? /* Interrupt pending bit */
+#define I2C_MODE_MT???? 0xC0??? /* Master Transmit Mode */
+#define I2C_MODE_MR???? 0x80??? /* Master Receive Mode */
+#define I2C_START_STOP? 0x20??? /* START / STOP */
+#define I2C_TXRX_ENA??? 0x10??? /* I2C Tx/Rx enable */
+
+#define I2C_TIMEOUT_MS??? 10????? /* 10 ms */
+
Quoted 8 lines

drivers/i2c/nx_i2c.c line 37

Quoted 5 lines
drivers/i2c/nx_i2c.c new file +5 -0
+#define I2C_M_NOSTOP??? 0x100
+
+#ifndef CONFIG_MAX_I2C_NUM
+#define CONFIG_MAX_I2C_NUM 3
+#endif

Is this really configurable? If so, I do not find the Kconfig description.

No, it is not configurable. I have changed it to MAX_I2C_NUM.

Quoted 43 lines
Quoted 43 lines
drivers/i2c/nx_i2c.c new file +42 -0
+
+DECLARE_GLOBAL_DATA_PTR;
+
+struct nx_i2c_regs {
+??? uint???? iiccon;
+??? uint???? iicstat;
+??? uint???? iicadd;
+??? uint???? iicds;
+??? uint???? iiclc;
+};
+
+struct nx_i2c_bus {
+??? uint bus_num;
+??? struct nx_i2c_regs *regs;
+??? uint speed;
+??? uint target_speed;
+??? uint sda_delay;
+};
+
+/* s5pxx18 i2c must be reset before enabled */
+static void i2c_reset(int ch)
+{
+??? int rst_id = RESET_ID_I2C0 + ch;
+
+??? nx_rstcon_setrst(rst_id, 0);
+??? nx_rstcon_setrst(rst_id, 1);
+}
+
+/* FIXME : this func will be removed after reset dm driver ported.
+ * set mmc pad alternative func.
+ */
+static void set_i2c_pad_func(struct nx_i2c_bus *i2c)
+{
+??? switch (i2c->bus_num) {
+??? case 0:
+??????? nx_gpio_set_pad_function(3, 2, 1);
+??????? nx_gpio_set_pad_function(3, 3, 1);
+??????? break;
+??? case 1:
+??????? nx_gpio_set_pad_function(3, 4, 1);
+??????? nx_gpio_set_pad_function(3, 5, 1);
+??????? break;
Quoted 8 lines

drivers/i2c/nx_i2c.c line 85

Quoted 6 lines
drivers/i2c/nx_i2c.c new file +6 -0
+??? case 2:
+??????? nx_gpio_set_pad_function(3, 6, 1);
+??????? nx_gpio_set_pad_function(3, 7, 1);
+??????? break;
+??? }
+}

Hmm... may this should be moved into a seperate pincontrol driver?

According to the above FIXME comment from Nexell it probably should. But there is no pincontrol driver implemented. But is the change to a driver necessary for now?

Quoted 10 lines

drivers/i2c/nx_i2c.c

Quoted 7 lines
drivers/i2c/nx_i2c.c new file +6 -0
+
+static uint i2c_get_clkrate(struct nx_i2c_bus *bus)
+{
+??? struct clk *clk;
+??? int index = bus->bus_num;
+??? char name[50] = {0, };

?

Quoted 4 lines

drivers/i2c/nx_i2c.c line 93

Quoted 2 lines
drivers/i2c/nx_i2c.c new file +2 -0
+
+??? sprintf(name, "%s.%d", DEV_NAME_I2C, index);

Where is DEV_NAME_I2C defined ?

DEV_NAME_I2C is defined in arch/arm/mach-nexell/include/mach/nexell.h

Quoted 46 lines
Quoted 33 lines
drivers/i2c/nx_i2c.c new file +32 -0
+??? clk = clk_get((const char *)name);
+??? if (!clk)
+??????? return -1;
+
+??? return clk_get_rate(clk);
+}
+
+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)
+??????? return -1;
+
+??? if (enb) {
+??????? clk_disable(clk);
+??????? clk_enable(clk);
+??? } else {
+??????? clk_disable(clk);
+??? }
+
+??? return 0;
+}
+
+/* get i2c module number from base address */
+static uint i2c_get_busnum(struct nx_i2c_bus *bus)
+{
+??? void *base_addr = (void *)PHY_BASEADDR_I2C0;
+??? int i;

drivers/i2c/nx_i2c.c line 135

Quoted 10 lines
drivers/i2c/nx_i2c.c new file +10 -0
+
+??? for (i = 0; i < CONFIG_MAX_I2C_NUM; i++) {
+??????? if (base_addr == ((void *)bus->regs)) {
+??????????? bus->bus_num = i;
+??????????? return i;
+??????? }
+??????? base_addr += 0x1000;
+??? }
+
+??? return -1;

return -ENODEV;

Quoted 9 lines

Hmm... is there no chance to use seq from struct udevice

https://gitlab.denx.de/u-boot/u-boot/blob/master/include/dm/device.h#L152

?

For example like:
https://gitlab.denx.de/u-boot/u-boot/blob/master/drivers/i2c/mxc_i2c.c#L895

Ok, I have changed this as proposed.

Quoted 57 lines
Quoted 43 lines
drivers/i2c/nx_i2c.c new file +26 -0
+}
+
+/* Set SDA line delay */
+static int nx_i2c_set_sda_delay(struct nx_i2c_bus *bus, ulong clkin)
+{
+??? struct nx_i2c_regs *i2c = bus->regs;
+??? uint sda_delay = 0;
+
+??? if (bus->sda_delay) {
+??????? sda_delay = clkin * bus->sda_delay;
+??????? sda_delay = DIV_ROUND_UP(sda_delay, 1000000);
+??????? sda_delay = DIV_ROUND_UP(sda_delay, 5);
+??????? if (sda_delay > 3)
+??????????? sda_delay = 3;
+??????? sda_delay |= I2CLC_FILTER;
+??? } else {
+??????? sda_delay = 0;
+??? }
+
+??? sda_delay &= 0x7;
+??? writel(sda_delay, &i2c->iiclc);
+
+??? return 0;
+}
+
+/* Calculate the value of the divider and prescaler, set the bus 

speed. */

drivers/i2c/nx_i2c.c new file +16 -0
+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 freq, pres = 16, div;
+
+??? freq = i2c_get_clkrate(bus);
+??? /* calculate prescaler and divisor values */
+??? if ((freq / pres / (16 + 1)) > speed)
+??????? /* set prescaler to 512 */
+??????? pres = 512;
+
+??? div = 0;
+??? while ((freq / pres / (div + 1)) > speed)
+??????? div++;
+

drivers/i2c/nx_i2c.c

Quoted 10 lines
drivers/i2c/nx_i2c.c new file +10 -0
+??? /* set prescaler, divisor according to freq, also set ACKGEN, IRQ */
+??? writel((div & 0x0F) | ((pres == 512) ? 0x40 : 0), &i2c->iiccon);
+
+??? /* init to SLAVE REVEIVE and set slaveaddr */
+??? writel(0, &i2c->iicstat);
+??? writel(0x00, &i2c->iicadd);
+??? /* program Master Transmit (and implicit STOP) */
+??? writel(I2C_MODE_MT | I2C_TXRX_ENA, &i2c->iicstat);
+
+??? bus->speed = bus->target_speed / (div * pres);

Do you want to allow all values of speeds or may you want to use standard speeds, see:

Quoted 2 lines

https://gitlab.denx.de/u-boot/u-boot/blob/master/include/i2c.h#L33

I'd like to allow all values of speed. In my opinion allowing only standard speeds does complicate things (e.g. how to do error handling?). Furthermore I think sometimes it could be handy to be able to set speed to an arbitrary value (e.g. to a lower value than 100000) when trying a new i2c-device on the bus.

Quoted 32 lines
Quoted 18 lines
drivers/i2c/nx_i2c.c new file +18 -0
+
+??? return 0;
+}
+
+static void nx_i2c_set_clockrate(struct udevice *dev, uint speed)
+{
+??? struct nx_i2c_bus *bus = dev_get_priv(dev);
+??? ulong clkin;
+
+??? nx_i2c_set_bus_speed(dev, speed);
+??? clkin = bus->speed;??????????? /* the actual i2c speed */
+??? clkin /= 1000;??????????????? /* clkin now in Khz */
+??? nx_i2c_set_sda_delay(bus, clkin);
+}
+
+static void i2c_process_node(struct udevice *dev)
+{
+??? struct nx_i2c_bus *bus = dev_get_priv(dev);

drivers/i2c/nx_i2c.c

Quoted 10 lines
drivers/i2c/nx_i2c.c new file +10 -0
+??? const void *blob = gd->fdt_blob;
+
+??? int node;
+
+??? node = dev->node.of_offset;
+
+??? bus->target_speed = fdtdec_get_int(blob, node,
+?????????????????????? "nexell,i2c-max-bus-freq", 0);
+??? bus->sda_delay = fdtdec_get_int(blob, node,
+??????????????????? "nexell,i2c-sda-delay", 0);

You introdue here new properties, please document them in u-boot:/doc/device-tree-bindings/i2c

Quoted 2 lines

Please without "nexell,"

I have changed "nexell,i2c-max-bus-freq" to the already defined "clock-frequency". Furthermore I have changed "nexell,i2c-sda-delay" to "i2c-sda-delay-ns".
Furthermore, I have added "nx_i2c.txt" in doc/device-tree-bindings/i2c.

Quoted 5 lines

Do you plan to post also a linux i2c driver?

If so, the devicetree bindings should be discussed there to avoid different properties between U-Boot and linux!

No, I do not plan to post a linux driver.

Quoted 6 lines
Quoted 6 lines
drivers/i2c/nx_i2c.c new file +6 -0
+}
+
+static int nx_i2c_probe(struct udevice *dev)
+{
+??? struct nx_i2c_bus *bus = dev_get_priv(dev);
+
Quoted 9 lines
Quoted 6 lines

+??? /* get regs */
+??? bus->regs = (struct nx_i2c_regs *)devfdt_get_addr(dev); +??? /* calc index */
+??? if (!i2c_get_busnum(bus)) {
+??????? debug("not found i2c number!\n"); +??????? return -1;

please return -ENODEV

Ok

Quoted 9 lines
Quoted 6 lines

+??? }
+
+??? /* i2c optional node parsing */
+??? i2c_process_node(dev);
+??? if (!bus->target_speed)
+??????? return -1;

please return here also an errorcode from include/linux/errno.h

Ok

Quoted 2 lines

Hmm.. if you return here if target_speed is not set, it is not optional!

You are right, I have removed 'optional' in the comment.

Quoted 1,030 lines
Quoted 284 lines
drivers/i2c/nx_i2c.c new file +251 -0
+
+??? /* reset */
+??? i2c_reset(bus->bus_num);
+??? /* gpio pad */
+??? set_i2c_pad_func(bus);
+
+??? /* clock rate */
+??? i2c_set_clk(bus, 1);
+??? nx_i2c_set_clockrate(dev, bus->target_speed);
+??? i2c_set_clk(bus, 0);
+
+??? return 0;
+}
+
+/* i2c bus busy check */
+static int i2c_is_busy(struct nx_i2c_regs *i2c)
+{
+??? ulong start_time;
+
+??? start_time = get_timer(0);
+??? while (readl(&i2c->iicstat) & I2CSTAT_BSY) {
+??????? if (get_timer(start_time) > I2C_TIMEOUT_MS) {
+??????????? debug("Timeout\n");
+??????????? return -I2C_NOK_TOUT;
+??????? }
+??? }
+??? return 0;
+}
+
+/* irq enable/disable functions */
+static void i2c_enable_irq(struct nx_i2c_regs *i2c)
+{
+??? unsigned int reg;
+
+??? reg = readl(&i2c->iiccon);
+??? reg |= I2CCON_IRENB;
+??? writel(reg, &i2c->iiccon);
+}
+
+/* irq clear function */
+static void i2c_clear_irq(struct nx_i2c_regs *i2c)
+{
+??? clrbits_le32(&i2c->iiccon, I2CCON_IRPND);
+}
+
+/* ack enable functions */
+static void i2c_enable_ack(struct nx_i2c_regs *i2c)
+{
+??? unsigned int reg;
+
+??? reg = readl(&i2c->iiccon);
+??? reg |= I2CCON_ACKGEN;
+??? writel(reg, &i2c->iiccon);
+}
+
+static void i2c_send_stop(struct nx_i2c_regs *i2c)
+{
+??? unsigned int reg;
+
+??? /* Send STOP. */
+??? reg = readl(&i2c->iicstat);
+??? reg |= I2C_MODE_MR | I2C_TXRX_ENA;
+??? reg &= (~I2C_START_STOP);
+??? writel(reg, &i2c->iicstat);
+??? i2c_clear_irq(i2c);
+}
+
+static int wait_for_xfer(struct nx_i2c_regs *i2c)
+{
+??? unsigned long start_time = get_timer(0);
+
+??? do {
+??????? if (readl(&i2c->iiccon) & I2CCON_IRPND)
+??????????? return (readl(&i2c->iicstat) & I2CSTAT_NACK) ?
+??????????????? I2C_NACK : I2C_OK;
+??? } while (get_timer(start_time) < I2C_TIMEOUT_MS);
+
+??? return I2C_NOK_TOUT;
+}
+
+static int i2c_transfer(struct nx_i2c_regs *i2c,
+??????????? uchar cmd_type,
+??????????? uchar chip,
+??????????? uchar addr[],
+??????????? uchar addr_len,
+??????????? uchar data[],
+??????????? unsigned short data_len,
+??????????? uint seq)
+{
+??? uint status;
+??? int i = 0, result;
+
+??? if (data == 0 || data_len == 0) {
+??????? /*Don't support data transfer of no length or to address 0 */
+??????? debug("%s: bad call\n", __func__);
+??????? return I2C_NOK;
+??? }
+
+??? i2c_enable_irq(i2c);
+??? i2c_enable_ack(i2c);
+
+??? /* Get the slave chip address going */
+??? writel(chip, &i2c->iicds);
+??? status = I2C_TXRX_ENA | I2C_START_STOP;
+??? if (cmd_type == I2C_WRITE || (addr && addr_len))
+??????? status |= I2C_MODE_MT;
+??? else
+??????? status |= I2C_MODE_MR;
+??? writel(status, &i2c->iicstat);
+??? if (seq)
+??????? i2c_clear_irq(i2c);
+
+??? /* Wait for chip address to transmit. */
+??? result = wait_for_xfer(i2c);
+??? if (result != I2C_OK)
+??????? goto bailout;
+
+??? /* If register address needs to be transmitted - do it now. */
+??? if (addr && addr_len) {? /* register addr */
+??????? while ((i < addr_len) && (result == I2C_OK)) {
+??????????? writel(addr[i++], &i2c->iicds);
+??????????? i2c_clear_irq(i2c);
+??????????? result = wait_for_xfer(i2c);
+??????? }
+
+??????? i = 0;
+??????? if (result != I2C_OK)
+??????????? goto bailout;
+??? }
+
+??? switch (cmd_type) {
+??? case I2C_WRITE:
+??????? while ((i < data_len) && (result == I2C_OK)) {
+??????????? writel(data[i++], &i2c->iicds);
+??????????? i2c_clear_irq(i2c);
+??????????? result = wait_for_xfer(i2c);
+??????? }
+??????? break;
+??? case I2C_READ:
+??????? if (addr && addr_len) {
+??????????? /*
+???????????? * Register address has been sent, now send slave chip
+???????????? * address again to start the actual read transaction.
+???????????? */
+??????????? writel(chip, &i2c->iicds);
+
+??????????? /* Generate a re-START. */
+??????????? writel(I2C_MODE_MR | I2C_TXRX_ENA
+??????????????????? | I2C_START_STOP, &i2c->iicstat);
+??????????? i2c_clear_irq(i2c);
+??????????? result = wait_for_xfer(i2c);
+??????????? if (result != I2C_OK)
+??????????????? goto bailout;
+??????? }
+
+??????? while ((i < data_len) && (result == I2C_OK)) {
+??????????? /* disable ACK for final READ */
+??????????? if (i == data_len - 1)
+??????????????? clrbits_le32(&i2c->iiccon
+??????????????????????? , I2CCON_ACKGEN);
+
+??????????? i2c_clear_irq(i2c);
+??????????? result = wait_for_xfer(i2c);
+??????????? data[i++] = readb(&i2c->iicds);
+??????? }
+
+??????? if (result == I2C_NACK)
+??????????? result = I2C_OK; /* Normal terminated read. */
+??????? break;
+
+??? default:
+??????? debug("%s: bad call\n", __func__);
+??????? result = I2C_NOK;
+??????? break;
+??? }
+
+bailout:
+??? return result;
+}
+
+static int nx_i2c_read(struct udevice *dev, uchar chip, uint addr,
+?????????????? uint alen, uchar *buffer, uint len, uint seq)
+{
+??? struct nx_i2c_bus *i2c;
+??? uchar xaddr[4];
+??? int ret;
+
+??? i2c = dev_get_priv(dev);
+??? if (!i2c)
+??????? return -EFAULT;
+
+??? if (alen > 4) {
+??????? debug("I2C read: addr len %d not supported\n", alen);
+??????? return -EADDRNOTAVAIL;
+??? }
+
+??? if (alen > 0)
+??????? xaddr[0] = (addr >> 24) & 0xFF;
+
+??? if (alen > 0) {
+??????? xaddr[0] = (addr >> 24) & 0xFF;
+??????? xaddr[1] = (addr >> 16) & 0xFF;
+??????? xaddr[2] = (addr >> 8) & 0xFF;
+??????? xaddr[3] = addr & 0xFF;
+??? }
+
+??? ret = i2c_transfer(i2c->regs, I2C_READ, chip << 1,
+?????????????? &xaddr[4 - alen], alen, buffer, len, seq);
+
+??? if (ret) {
+??????? debug("I2C read failed %d\n", ret);
+??????? return -EIO;
+??? }
+
+??? return 0;
+}
+
+static int nx_i2c_write(struct udevice *dev, uchar chip, uint addr,
+??????????? uint alen, uchar *buffer, uint len, uint seq)
+{
+??? struct nx_i2c_bus *i2c;
+??? uchar xaddr[4];
+??? int ret;
+
+??? i2c = dev_get_priv(dev);
+??? if (!i2c)
+??????? return -EFAULT;
+
+??? if (alen > 4) {
+??????? debug("I2C write: addr len %d not supported\n", alen);
+??????? return -EINVAL;
+??? }
+
+??? if (alen > 0) {
+??????? xaddr[0] = (addr >> 24) & 0xFF;
+??????? xaddr[1] = (addr >> 16) & 0xFF;
+??????? xaddr[2] = (addr >> 8) & 0xFF;
+??????? xaddr[3] = addr & 0xFF;
+??? }
+
+??? ret = i2c_transfer(i2c->regs, I2C_WRITE, chip << 1,
+?????????????? &xaddr[4 - alen], alen, buffer, len, seq);
+??? if (ret) {
+??????? debug("I2C write failed %d\n", ret);
+??????? return -EIO;
+??? }
+
+??? return 0;
+}
+
+static int nx_i2c_xfer(struct udevice *dev, struct i2c_msg *msg, int 

nmsgs)

drivers/i2c/nx_i2c.c new file +32 -0
+{
+??? struct nx_i2c_bus *bus = dev_get_priv(dev);
+??? struct nx_i2c_regs *i2c = bus->regs;
+??? int ret;
+??? int i;
+
+??? /* The power loss by the clock, only during on/off. */
+??? i2c_set_clk(bus, 1);
+
+??? /* Bus State(Busy) check? */
+??? ret = i2c_is_busy(i2c);
+??? if (ret < 0)
+??????? return ret;
+
+??? for (i = 0; i < nmsgs; msg++, i++) {
+??????? if (msg->flags & I2C_M_RD) {
+??????????? ret = nx_i2c_read(dev, msg->addr, 0, 0, msg->buf,
+????????????????????? msg->len, i);
+??????? } else {
+??????????? ret = nx_i2c_write(dev, msg->addr, 0, 0, msg->buf,
+?????????????????????? msg->len, i);
+??????? }
+
+??????? if (ret) {
+??????????? debug("i2c_xfer: error sending\n");
+??????????? return -EREMOTEIO;
+??????? }
+??? }
+??? /* Send Stop */
+??? i2c_send_stop(i2c);
+??? i2c_set_clk(bus, 0);
+

drivers/i2c/nx_i2c.c

Quoted 10 lines
drivers/i2c/nx_i2c.c new file +10 -0
+??? return ret ? -EREMOTEIO : 0;
+};
+
+static const struct dm_i2c_ops nx_i2c_ops = {
+??? .xfer??????? = nx_i2c_xfer,
+??? .set_bus_speed??? = nx_i2c_set_bus_speed,
+};
+
+static const struct udevice_id nx_i2c_ids[] = {
+??? { .compatible = "nexell,s5pxx18-i2c" },

Same here as for the new properties. Please discuss the names on

devicetree at vger.kernel.org <[email protected]>

first!

drivers/i2c/nx_i2c.c

Quoted 11 lines

+??? { }

drivers/i2c/nx_i2c.c new file +10 -0
+};
+
+U_BOOT_DRIVER(i2c_nexell) = {
+??? .name??????? = "i2c_nexell",
+??? .id??????? = UCLASS_I2C,
+??? .of_match??? = nx_i2c_ids,
+??? .probe??????? = nx_i2c_probe,
+??? .priv_auto_alloc_size??? = sizeof(struct nx_i2c_bus),
+??? .ops??????? = &nx_i2c_ops,
+};

bye,
Heiko

Quoted 714 lines
drivers/mmc/Kconfig +0 -0
index 2f0eedc..bb8e7c0 100644
@@ -253,6 +253,12 @@ config MMC_DW_SNPS

??????? This selects support for Synopsys DesignWare Memory Card Interface driver
??????? extensions used in various Synopsys ARC devboards.

drivers/mmc/Kconfig +6 -0
+config NEXELL_DWMMC
+??? bool "Nexell SD/MMC controller support"
+??? depends on ARCH_NEXELL
+??? depends on MMC_DW
+??? default y
+

? config MMC_MESON_GX
????? bool "Meson GX EMMC controller support"
????? depends on DM_MMC && BLK && ARCH_MESON

drivers/mmc/Makefile +0 -0
index 9c1f8e5..a7b5a7b 100644
@@ -43,6 +43,7 @@ obj-$(CONFIG_SH_MMCIF) += sh_mmcif.o

? obj-$(CONFIG_SH_SDHI) += sh_sdhi.o
? obj-$(CONFIG_STM32_SDMMC2) += stm32_sdmmc2.o
? obj-$(CONFIG_JZ47XX_MMC) += jz_mmc.o
+obj-$(CONFIG_NEXELL_DWMMC) += nexell_dw_mmc_dm.o
? # SDHCI
? obj-$(CONFIG_MMC_SDHCI)??????????? += sdhci.o

drivers/mmc/nexell_dw_mmc_dm.c new file +153 -0
new file mode 100644
index 0000000..b06b60d
@@ -0,0 +1,350 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2016 Nexell
+ * Youngbok, Park <[email protected]>
+ *
+ * (C) Copyright 2019 Stefan Bosch <[email protected]>
+ */
+
+#include <common.h>
+#include <clk.h>
+#include <dm.h>
+#include <dt-structs.h>
+#include <dwmmc.h>
+#include <syscon.h>
+#include <asm/gpio.h>
+#include <asm/arch/nx_gpio.h>
+#include <asm/arch/reset.h>
+
+#define DWMCI_CLKSEL??????????? 0x09C
+#define DWMCI_SHIFT_0??????????? 0x0
+#define DWMCI_SHIFT_1??????????? 0x1
+#define DWMCI_SHIFT_2??????????? 0x2
+#define DWMCI_SHIFT_3??????????? 0x3
+#define DWMCI_SET_SAMPLE_CLK(x)??? (x)
+#define DWMCI_SET_DRV_CLK(x)??? ((x) << 16)
+#define DWMCI_SET_DIV_RATIO(x)??? ((x) << 24)
+#define DWMCI_CLKCTRL??????????? 0x114
+#define NX_MMC_CLK_DELAY(x, y, a, b)??? ((((x) & 0xFF) << 0) |\
+??????????????????? (((y) & 0x03) << 16) |\
+??????????????????? (((a) & 0xFF) << 8)? |\
+??????????????????? (((b) & 0x03) << 24))
+
+struct nexell_mmc_plat {
+??? struct mmc_config cfg;
+??? struct mmc mmc;
+};
+
+struct nexell_dwmmc_priv {
+??? struct clk *clk;
+??? struct dwmci_host host;
+??? int fifo_size;
+??? bool fifo_mode;
+??? int frequency;
+??? u32 min_freq;
+??? u32 max_freq;
+??? int d_delay;
+??? int d_shift;
+??? int s_delay;
+??? int s_shift;
+
+};
+
+struct clk *clk_get(const char *id);
+
+static void set_pin_stat(int index, int bit, int value)
+{
+#if !defined(CONFIG_SPL_BUILD)
+??? nx_gpio_set_pad_function(index, bit, value);
+#else
+#if defined(CONFIG_ARCH_S5P4418) ||??? \
+??? defined(CONFIG_ARCH_S5P6818)
+
+??? unsigned long base[5] = {
+??????? PHY_BASEADDR_GPIOA, PHY_BASEADDR_GPIOB,
+??????? PHY_BASEADDR_GPIOC, PHY_BASEADDR_GPIOD,
+??????? PHY_BASEADDR_GPIOE,
+??? };
+
+??? dw_mmc_set_pin(base[index], bit, value);
+#endif
+#endif
+}
+
+static void nx_dw_mmc_set_pin(struct dwmci_host *host)
+{
+??? debug("? %s(): dev_index == %d", __func__, host->dev_index);
+
+??? switch (host->dev_index) {
+??? case 0:
+??????? set_pin_stat(0, 29, 1);
+??????? set_pin_stat(0, 31, 1);
+??????? set_pin_stat(1, 1, 1);
+??????? set_pin_stat(1, 3, 1);
+??????? set_pin_stat(1, 5, 1);
+??????? set_pin_stat(1, 7, 1);
+??????? break;
+??? case 1:
+??????? set_pin_stat(3, 22, 1);
+??????? set_pin_stat(3, 23, 1);
+??????? set_pin_stat(3, 24, 1);
+??????? set_pin_stat(3, 25, 1);
+??????? set_pin_stat(3, 26, 1);
+??????? set_pin_stat(3, 27, 1);
+??????? break;
+??? case 2:
+??????? set_pin_stat(2, 18, 2);
+??????? set_pin_stat(2, 19, 2);
+??????? set_pin_stat(2, 20, 2);
+??????? set_pin_stat(2, 21, 2);
+??????? set_pin_stat(2, 22, 2);
+??????? set_pin_stat(2, 23, 2);
+??????? if (host->buswidth == 8) {
+??????????? set_pin_stat(4, 21, 2);
+??????????? set_pin_stat(4, 22, 2);
+??????????? set_pin_stat(4, 23, 2);
+??????????? set_pin_stat(4, 24, 2);
+??????? }
+??????? break;
+??? default:
+??????? debug(" is invalid!");
+??? }
+??? debug("\n");
+}
+
+static void nx_dw_mmc_clksel(struct dwmci_host *host)
+{
+??? u32 val;
+
+#ifdef CONFIG_BOOST_MMC
+??? val = DWMCI_SET_SAMPLE_CLK(DWMCI_SHIFT_0) |
+??????? DWMCI_SET_DRV_CLK(DWMCI_SHIFT_0) | DWMCI_SET_DIV_RATIO(1);
+#else
+??? val = DWMCI_SET_SAMPLE_CLK(DWMCI_SHIFT_0) |
+??????? DWMCI_SET_DRV_CLK(DWMCI_SHIFT_0) | DWMCI_SET_DIV_RATIO(3);
+#endif
+
+??? dwmci_writel(host, DWMCI_CLKSEL, val);
+}
+
+static void nx_dw_mmc_reset(int ch)
+{
+??? int rst_id = RESET_ID_SDMMC0 + ch;
+
+??? nx_rstcon_setrst(rst_id, 0);
+??? nx_rstcon_setrst(rst_id, 1);
+}
+
+static void nx_dw_mmc_clk_delay(struct udevice *dev)
+{
+??? unsigned int delay;
+??? struct nexell_dwmmc_priv *priv = dev_get_priv(dev);
+??? struct dwmci_host *host = &priv->host;
+
+??? delay = NX_MMC_CLK_DELAY(priv->d_delay,
+???????????????? priv->d_shift, priv->s_delay, priv->s_shift);
+
+??? writel(delay, (host->ioaddr + DWMCI_CLKCTRL));
+??? debug("%s(): Values set: d_delay==%d, d_shift==%d, s_delay==%d, "
+????????? "s_shift==%d\n", __func__, priv->d_delay, priv->d_shift,
+????????? priv->s_delay, priv->s_shift);
+}
+
+static unsigned int nx_dw_mmc_get_clk(struct dwmci_host *host, uint 

freq)

drivers/mmc/nexell_dw_mmc_dm.c new file +197 -0
+{
+??? struct clk *clk;
+??? struct udevice *dev = host->priv;
+??? struct nexell_dwmmc_priv *priv = dev_get_priv(dev);
+
+??? int index = host->dev_index;
+??? char name[50] = { 0, };
+
+??? clk = priv->clk;
+??? if (!clk) {
+??????? sprintf(name, "%s.%d", DEV_NAME_SDHC, index);
+??????? clk = clk_get((const char *)name);
+??????? if (!clk)
+??????????? return 0;
+??????? priv->clk = clk;
+??? }
+
+??? return clk_get_rate(clk) / 2;
+}
+
+static unsigned long nx_dw_mmc_set_clk(struct dwmci_host *host,
+?????????????????????? unsigned int rate)
+{
+??? struct clk *clk;
+??? char name[50] = { 0, };
+??? struct udevice *dev = host->priv;
+??? struct nexell_dwmmc_priv *priv = dev_get_priv(dev);
+
+??? int index = host->dev_index;
+
+??? clk = priv->clk;
+??? if (!clk) {
+??????? sprintf(name, "%s.%d", DEV_NAME_SDHC, index);
+??????? clk = clk_get((const char *)name);
+??????? if (!clk)
+??????????? return 0;
+??????? priv->clk = clk;
+??? }
+
+??? clk_disable(clk);
+??? rate = clk_set_rate(clk, rate);
+??? clk_enable(clk);
+
+??? return rate;
+}
+
+static int nexell_dwmmc_ofdata_to_platdata(struct udevice *dev)
+{
+??? /* if (dev): *priv = dev->priv, else: *priv = NULL */
+??? struct nexell_dwmmc_priv *priv = dev_get_priv(dev);
+??? struct dwmci_host *host = &priv->host;
+??? int val = -1;
+
+??? debug("%s()\n", __func__);
+
+??? host->name = dev->name;
+??? host->ioaddr = dev_read_addr_ptr(dev);
+
+??? val = dev_read_u32_default(dev, "nexell,bus-width", -1);
+??? if (val < 0) {
+??????? debug("? 'nexell,bus-width' missing/invalid!\n");
+??????? return -EINVAL;
+??? }
+??? host->buswidth = val;
+??? host->get_mmc_clk = nx_dw_mmc_get_clk;
+??? host->clksel = nx_dw_mmc_clksel;
+??? host->priv = dev;
+
+??? val = dev_read_u32_default(dev, "index", -1);
+??? if (val < 0) {
+??????? debug("? 'index' missing/invalid!\n");
+??????? return -EINVAL;
+??? }
+??? host->dev_index = val;
+
+??? val = dev_read_u32_default(dev, "fifo-size", 0x20);
+??? if (val <= 0) {
+??????? debug("? 'fifo-size' missing/invalid!\n");
+??????? return -EINVAL;
+??? }
+??? priv->fifo_size = val;
+
+??? priv->fifo_mode = dev_read_bool(dev, "fifo-mode");
+
+??? val = dev_read_u32_default(dev, "frequency", -1);
+??? if (val < 0) {
+??????? debug("? 'frequency' missing/invalid!\n");
+??????? return -EINVAL;
+??? }
+??? priv->frequency = val;
+
+??? val = dev_read_u32_default(dev, "max-frequency", -1);
+??? if (val < 0) {
+??????? debug("? 'max-frequency' missing/invalid!\n");
+??????? return -EINVAL;
+??? }
+??? priv->max_freq = val;
+??? priv->min_freq = 400000;? /* 400 kHz */
+
+??? val = dev_read_u32_default(dev, "nexell,drive_dly", -1);
+??? if (val < 0) {
+??????? debug("? 'nexell,drive_dly' missing/invalid!\n");
+??????? return -EINVAL;
+??? }
+??? priv->d_delay = val;
+
+??? val = dev_read_u32_default(dev, "nexell,drive_shift", -1);
+??? if (val < 0) {
+??????? debug("? 'nexell,drive_shift' missing/invalid!\n");
+??????? return -EINVAL;
+??? }
+??? priv->d_shift = val;
+
+??? val = dev_read_u32_default(dev, "nexell,sample_dly", -1);
+??? if (val < 0) {
+??????? debug("? 'nexell,sample_dly' missing/invalid!\n");
+??????? return -EINVAL;
+??? }
+??? priv->s_delay = val;
+
+??? val = dev_read_u32_default(dev, "nexell,sample_shift", -1);
+??? if (val < 0) {
+??????? debug("? 'nexell,sample_shift' missing/invalid!\n");
+??????? return -EINVAL;
+??? }
+??? priv->s_shift = val;
+
+??? debug("? index==%d, name==%s, ioaddr==0x%08x, buswidth==%d, "
+????????? "fifo_size==%d, fifo_mode==%d, frequency==%d\n",
+????????? host->dev_index, host->name, (u32)host->ioaddr,
+????????? host->buswidth, priv->fifo_size, priv->fifo_mode,
+????????? priv->frequency);
+??? debug("? min_freq==%d, max_freq==%d, delay: "
+????????? "0x%02x:0x%02x:0x%02x:0x%02x\n",
+????????? priv->min_freq, priv->max_freq, priv->d_delay,
+????????? priv->d_shift, priv->s_delay, priv->s_shift);
+
+??? return 0;
+}
+
+static int nexell_dwmmc_probe(struct udevice *dev)
+{
+??? struct nexell_mmc_plat *plat = dev_get_platdata(dev);
+??? struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
+??? struct nexell_dwmmc_priv *priv = dev_get_priv(dev);
+??? struct dwmci_host *host = &priv->host;
+??? struct udevice *pwr_dev __maybe_unused;
+
+??? debug("%s():\n", __func__);
+
+??? host->fifoth_val = MSIZE(0x2) |
+??????? RX_WMARK(priv->fifo_size / 2 - 1) |
+??????? TX_WMARK(priv->fifo_size / 2);
+
+??? host->fifo_mode = priv->fifo_mode;
+
+??? dwmci_setup_cfg(&plat->cfg, host, priv->max_freq, priv->min_freq);
+??? host->mmc = &plat->mmc;
+??? host->mmc->priv = &priv->host;
+??? host->mmc->dev = dev;
+??? upriv->mmc = host->mmc;
+
+??? nx_dw_mmc_set_pin(host);
+
+??? debug("? nx_dw_mmc_set_clk(host, frequency * 4 == %d)\n",
+????????? priv->frequency * 4);
+??? nx_dw_mmc_set_clk(host, priv->frequency * 4);
+
+??? nx_dw_mmc_reset(host->dev_index);
+??? nx_dw_mmc_clk_delay(dev);
+
+??? return dwmci_probe(dev);
+}
+
+static int nexell_dwmmc_bind(struct udevice *dev)
+{
+??? struct nexell_mmc_plat *plat = dev_get_platdata(dev);
+
+??? return dwmci_bind(dev, &plat->mmc, &plat->cfg);
+}
+
+static const struct udevice_id nexell_dwmmc_ids[] = {
+??? { .compatible = "nexell,nexell-dwmmc" },
+??? { }
+};
+
+U_BOOT_DRIVER(nexell_dwmmc_drv) = {
+??? .name??????? = "nexell_dwmmc",
+??? .id??????? = UCLASS_MMC,
+??? .of_match??? = nexell_dwmmc_ids,
+??? .ofdata_to_platdata = nexell_dwmmc_ofdata_to_platdata,
+??? .ops??????? = &dm_dwmci_ops,
+??? .bind??????? = nexell_dwmmc_bind,
+??? .probe??????? = nexell_dwmmc_probe,
+??? .priv_auto_alloc_size = sizeof(struct nexell_dwmmc_priv),
+??? .platdata_auto_alloc_size = sizeof(struct nexell_mmc_plat),
+};
drivers/pwm/Makefile +0 -0
index a837c35..b45aada 100644
@@ -16,3 +16,4 @@ obj-$(CONFIG_PWM_ROCKCHIP)??? += rk_pwm.o

? obj-$(CONFIG_PWM_SANDBOX)??? += sandbox_pwm.o
? obj-$(CONFIG_PWM_TEGRA)??????? += tegra_pwm.o
? obj-$(CONFIG_PWM_SUNXI)??????? += sunxi_pwm.o

drivers/pwm/Makefile +1 -0
+obj-$(CONFIG_PWM_NX)??????? += pwm-nexell.o
drivers/pwm/pwm-nexell.c new file +252 -0
new file mode 100644
index 0000000..6c0f8f4
@@ -0,0 +1,252 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2011 Samsung Electronics
+ *
+ * Donghwa Lee <[email protected]>
+ */
+
+/* This codes are copied from arch/arm/cpu/armv7/s5p-common/pwm.c */
+
+#include <common.h>
+#include <errno.h>
+#include <pwm.h>
+#include <asm/io.h>
+#include <asm/arch/clk.h>
+#include "pwm-nexell.h"
+
+#if defined(CONFIG_ARCH_NEXELL)
+#include <asm/arch/nexell.h>
+#include <asm/arch/reset.h>
+#include <asm/arch/nx_gpio.h>
+#include <asm/arch/tieoff.h>
+
+struct pwm_device {
+??? int ch;
+??? int grp;
+??? int bit;
+??? int pwm_fn;
+};
+
+static struct pwm_device pwm_dev[] = {
+??? [0] = { .ch = 0, .grp = 3, .bit = 1,? .pwm_fn = 1 },
+??? [1] = { .ch = 1, .grp = 2, .bit = 13, .pwm_fn = 2 },
+??? [2] = { .ch = 2, .grp = 2, .bit = 14, .pwm_fn =??? 2 },
+??? [3] = { .ch = 3, .grp = 3, .bit = 0,? .pwm_fn = 2 },
+};
+#endif
+
+int pwm_enable(int pwm_id)
+{
+??? const struct s5p_timer *pwm =
+#if defined(CONFIG_ARCH_NEXELL)
+??????????? (struct s5p_timer *)PHY_BASEADDR_PWM;
+#else
+??????????? (struct s5p_timer *)samsung_get_base_timer();
+#endif
+??? unsigned long tcon;
+
+??? tcon = readl(&pwm->tcon);
+??? tcon |= TCON_START(pwm_id);
+
+??? writel(tcon, &pwm->tcon);
+
+??? return 0;
+}
+
+void pwm_disable(int pwm_id)
+{
+??? const struct s5p_timer *pwm =
+#if defined(CONFIG_ARCH_NEXELL)
+??????????? (struct s5p_timer *)PHY_BASEADDR_PWM;
+#else
+??????????? (struct s5p_timer *)samsung_get_base_timer();
+#endif
+??? unsigned long tcon;
+
+??? tcon = readl(&pwm->tcon);
+??? tcon &= ~TCON_START(pwm_id);
+
+??? writel(tcon, &pwm->tcon);
+}
+
+static unsigned long pwm_calc_tin(int pwm_id, unsigned long freq)
+{
+??? unsigned long tin_parent_rate;
+??? unsigned int div;
+#if defined(CONFIG_ARCH_NEXELL)
+??? unsigned int pre_div;
+??? const struct s5p_timer *pwm =
+??????? (struct s5p_timer *)PHY_BASEADDR_PWM;
+??? unsigned int val;
+#endif
+
+#if defined(CONFIG_ARCH_NEXELL)
+??? struct clk *clk = clk_get(CORECLK_NAME_PCLK);
+
+??? tin_parent_rate = clk_get_rate(clk);
+#else
+??? tin_parent_rate = get_pwm_clk();
+#endif
+
+#if defined(CONFIG_ARCH_NEXELL)
+??? writel(0, &pwm->tcfg0);
+??? val = readl(&pwm->tcfg0);
+
+??? if (pwm_id < 2)
+??????? div = ((val >> 0) & 0xff) + 1;
+??? else
+??????? div = ((val >> 8) & 0xff) + 1;
+
+??? writel(0, &pwm->tcfg1);
+??? val = readl(&pwm->tcfg1);
+??? val = (val >> MUX_DIV_SHIFT(pwm_id)) & 0xF;
+??? pre_div = (1UL << val);
+
+??? freq = tin_parent_rate / div / pre_div;
+
+??? return freq;
+#else
+??? for (div = 2; div <= 16; div *= 2) {
+??????? if ((tin_parent_rate / (div << 16)) < freq)
+??????????? return tin_parent_rate / div;
+??? }
+
+??? return tin_parent_rate / 16;
+#endif
+}
+
+#define NS_IN_SEC 1000000000UL
+
+int pwm_config(int pwm_id, int duty_ns, int period_ns)
+{
+??? const struct s5p_timer *pwm =
+#if defined(CONFIG_ARCH_NEXELL)
+??????? (struct s5p_timer *)PHY_BASEADDR_PWM;
+#else
+??????? (struct s5p_timer *)samsung_get_base_timer();
+#endif
+??? unsigned int offset;
+??? unsigned long tin_rate;
+??? unsigned long tin_ns;
+??? unsigned long frequency;
+??? unsigned long tcon;
+??? unsigned long tcnt;
+??? unsigned long tcmp;
+
+??? /*
+???? * We currently avoid using 64bit arithmetic by using the
+???? * fact that anything faster than 1GHz is easily representable
+???? * by 32bits.
+???? */
+??? if (period_ns > NS_IN_SEC || duty_ns > NS_IN_SEC || period_ns == 0)
+??????? return -ERANGE;
+
+??? if (duty_ns > period_ns)
+??????? return -EINVAL;
+
+??? frequency = NS_IN_SEC / period_ns;
+
+??? /* Check to see if we are changing the clock rate of the PWM */
+??? tin_rate = pwm_calc_tin(pwm_id, frequency);
+
+??? tin_ns = NS_IN_SEC / tin_rate;
+#if defined(CONFIG_ARCH_NEXELL)
+??? /* The counter starts at zero. */
+??? tcnt = (period_ns / tin_ns) - 1;
+#else
+??? tcnt = period_ns / tin_ns;
+#endif
+
+??? /* Note, counters count down */
+??? tcmp = duty_ns / tin_ns;
+??? tcmp = tcnt - tcmp;
+
+??? /* Update the PWM register block. */
+??? offset = pwm_id * 3;
+??? if (pwm_id < 4) {
+??????? writel(tcnt, &pwm->tcntb0 + offset);
+??????? writel(tcmp, &pwm->tcmpb0 + offset);
+??? }
+
+??? tcon = readl(&pwm->tcon);
+??? tcon |= TCON_UPDATE(pwm_id);
+??? if (pwm_id < 4)
+??????? tcon |= TCON_AUTO_RELOAD(pwm_id);
+??? else
+??????? tcon |= TCON4_AUTO_RELOAD;
+??? writel(tcon, &pwm->tcon);
+
+??? tcon &= ~TCON_UPDATE(pwm_id);
+??? writel(tcon, &pwm->tcon);
+
+??? return 0;
+}
+
+int pwm_init(int pwm_id, int div, int invert)
+{
+??? u32 val;
+??? const struct s5p_timer *pwm =
+#if defined(CONFIG_ARCH_NEXELL)
+??????????? (struct s5p_timer *)PHY_BASEADDR_PWM;
+#else
+??????????? (struct s5p_timer *)samsung_get_base_timer();
+#endif
+??? unsigned long ticks_per_period;
+??? unsigned int offset, prescaler;
+
+??? /*
+???? * Timer Freq(HZ) =
+???? *??? PWM_CLK / { (prescaler_value + 1) * (divider_value) }
+???? */
+
+??? val = readl(&pwm->tcfg0);
+??? if (pwm_id < 2) {
+??????? prescaler = PRESCALER_0;
+??????? val &= ~0xff;
+??????? val |= (prescaler & 0xff);
+??? } else {
+??????? prescaler = PRESCALER_1;
+??????? val &= ~(0xff << 8);
+??????? val |= (prescaler & 0xff) << 8;
+??? }
+??? writel(val, &pwm->tcfg0);
+??? val = readl(&pwm->tcfg1);
+??? val &= ~(0xf << MUX_DIV_SHIFT(pwm_id));
+??? val |= (div & 0xf) << MUX_DIV_SHIFT(pwm_id);
+??? writel(val, &pwm->tcfg1);
+
+??? if (pwm_id == 4) {
+??????? /*
+???????? * TODO(sjg): Use this as a countdown timer for now. We count
+???????? * down from the maximum value to 0, then reset.
+???????? */
+??????? ticks_per_period = -1UL;
+??? } else {
+??????? const unsigned long pwm_hz = 1000;
+#if defined(CONFIG_ARCH_NEXELL)
+??????? struct clk *clk = clk_get(CORECLK_NAME_PCLK);
+??????? unsigned long timer_rate_hz = clk_get_rate(clk) /
+#else
+??????? unsigned long timer_rate_hz = get_pwm_clk() /
+#endif
+??????????? ((prescaler + 1) * (1 << div));
+
+??????? ticks_per_period = timer_rate_hz / pwm_hz;
+??? }
+
+??? /* set count value */
+??? offset = pwm_id * 3;
+
+??? writel(ticks_per_period, &pwm->tcntb0 + offset);
+
+??? val = readl(&pwm->tcon) & ~(0xf << TCON_OFFSET(pwm_id));
+??? if (invert && pwm_id < 4)
+??????? val |= TCON_INVERTER(pwm_id);
+??? writel(val, &pwm->tcon);
+
+??? nx_gpio_set_pad_function(pwm_dev[pwm_id].grp, pwm_dev[pwm_id].bit,
+???????????????? pwm_dev[pwm_id].pwm_fn);
+??? pwm_enable(pwm_id);
+
+??? return 0;
+}
drivers/pwm/pwm-nexell.h new file +54 -0
new file mode 100644
index 0000000..92dc707
@@ -0,0 +1,54 @@
+/* SPDX-License-Identifier: GPL-2.0+
+ *
+ * Copyright (C) 2009 Samsung Electronics
+ * Kyungmin Park <[email protected]>
+ * Minkyu Kang <[email protected]>
+ */
+
+#ifndef __ASM_ARM_ARCH_PWM_H_
+#define __ASM_ARM_ARCH_PWM_H_
+
+#define PRESCALER_0??????? (8 - 1)??????? /* prescaler of timer 0, 1 */
+#define PRESCALER_1??????? (16 - 1)??? /* prescaler of timer 2, 3, 4 */
+
+/* Divider MUX */
+#define MUX_DIV_1??????? 0??????? /* 1/1 period */
+#define MUX_DIV_2??????? 1??????? /* 1/2 period */
+#define MUX_DIV_4??????? 2??????? /* 1/4 period */
+#define MUX_DIV_8??????? 3??????? /* 1/8 period */
+#define MUX_DIV_16??????? 4??????? /* 1/16 period */
+
+#define MUX_DIV_SHIFT(x)??? ((x) * 4)
+
+#define TCON_OFFSET(x)??????? (((x) + 1) * (!!x) << 2)
+
+#define TCON_START(x)??????? (1 << TCON_OFFSET(x))
+#define TCON_UPDATE(x)??????? (1 << (TCON_OFFSET(x) + 1))
+#define TCON_INVERTER(x)??? (1 << (TCON_OFFSET(x) + 2))
+#define TCON_AUTO_RELOAD(x)??? (1 << (TCON_OFFSET(x) + 3))
+#define TCON4_AUTO_RELOAD??? (1 << 22)
+
+#ifndef __ASSEMBLY__
+struct s5p_timer {
+??? unsigned int??? tcfg0;
+??? unsigned int??? tcfg1;
+??? unsigned int??? tcon;
+??? unsigned int??? tcntb0;
+??? unsigned int??? tcmpb0;
+??? unsigned int??? tcnto0;
+??? unsigned int??? tcntb1;
+??? unsigned int??? tcmpb1;
+??? unsigned int??? tcnto1;
+??? unsigned int??? tcntb2;
+??? unsigned int??? tcmpb2;
+??? unsigned int??? tcnto2;
+??? unsigned int??? tcntb3;
+??? unsigned int??? res1;
+??? unsigned int??? tcnto3;
+??? unsigned int??? tcntb4;
+??? unsigned int??? tcnto4;
+??? unsigned int??? tintcstat;
+};
+#endif??? /* __ASSEMBLY__ */
+
+#endif
#7 lore raw

RFC PATCH 3/10 i2c: mmc: add nexell driver (gpio, i2c, mmc, pwm)

Hello Stefan,

Am 20.02.2020 um 18:49 schrieb Stefan B.:

Quoted 38 lines

Hello Heiko,

see below my feedback, please give me further advise where indicated.

Unfortunately there have been some Bugs in the i2c-driver and I learned that this driver has not been used at all ("i2c-gpio" has been used instead). So I have done several Bugfixes and improvements appart from your proposals.

Regards
Stefan

Am 04.02.20 um 07:58 schrieb Heiko Schocher:

Quoted 24 lines

Hello Stefan,

Am 03.02.2020 um 21:40 schrieb Stefan Bosch:

Quoted 20 lines

Changes in relation to FriendlyARM's U-Boot nanopi2-v2016.01:
- i2c/nx_i2c.c: Some adaptions mainly because of changes in ?? "struct udevice".
- mmc: nexell_dw_mmc.c changed to nexell_dw_mmc_dm.c (switched to DM).

---

? drivers/gpio/Kconfig?????????? |?? 9 +
? drivers/gpio/Makefile????????? |?? 1 +
? drivers/gpio/nx_gpio.c???????? | 252 +++++++++++++++++++
? drivers/i2c/Kconfig??????????? |?? 9 +
? drivers/i2c/Makefile?????????? |?? 1 +
? drivers/i2c/nx_i2c.c?????????? | 537 +++++++++++++++++++++++++++++++++++++++++
? drivers/mmc/Kconfig??????????? |?? 6 +
? drivers/mmc/Makefile?????????? |?? 1 +
? drivers/mmc/nexell_dw_mmc_dm.c | 350 +++++++++++++++++++++++++++
? drivers/pwm/Makefile?????????? |?? 1 +
? drivers/pwm/pwm-nexell.c?????? | 252 +++++++++++++++++++
? drivers/pwm/pwm-nexell.h?????? |? 54 +++++
Quoted 6 lines
Quoted 5 lines

Could you please split this patch into 4 parts (i2c, gpio, mmc and pwm) ?

Thanks!

Ok, I will split this patch.

Thanks!

Quoted 20 lines
Quoted 8 lines
Quoted 7 lines

? 12 files changed, 1473 insertions(+)
? create mode 100644 drivers/gpio/nx_gpio.c ? create mode 100644 drivers/i2c/nx_i2c.c
? create mode 100644 drivers/mmc/nexell_dw_mmc_dm.c ? create mode 100644 drivers/pwm/pwm-nexell.c ? create mode 100644 drivers/pwm/pwm-nexell.h

[...]

Quoted 11 lines
Quoted 9 lines
drivers/gpio/Makefile +0 -0
index 449046b..e3340de 100644
@@ -65,3 +65,4 @@ obj-$(CONFIG_PM8916_GPIO)??? += pm8916_gpio.o

? obj-$(CONFIG_MT7621_GPIO)??? += mt7621_gpio.o
? obj-$(CONFIG_MSCC_SGPIO)??? += mscc_sgpio.o
? obj-$(CONFIG_SIFIVE_GPIO)??? += sifive-gpio.o
+obj-$(CONFIG_NX_GPIO)??????? += nx_gpio.o

Please keep lists sorted.

Quoted 2 lines

The list is not sorted (at least in no alphabetical order), but I can e.g. move "... += nx_gpio.o" one line up?

Find for me.

Quoted 336 lines
Quoted 327 lines
Quoted 327 lines
drivers/gpio/nx_gpio.c new file +252 -0
new file mode 100644
index 0000000..86472f6
@@ -0,0 +1,252 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2016 Nexell
+ * DeokJin, Lee <[email protected]>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <errno.h>
+#include <malloc.h>
+#include <fdtdec.h>
+#include <asm/io.h>
+#include <asm/gpio.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+struct nx_gpio_regs {
+??? u32??? data;??????? /* Data register */
+??? u32??? outputenb;??? /* Output Enable register */
+??? u32??? detmode[2];??? /* Detect Mode Register */
+??? u32??? intenb;??????? /* Interrupt Enable Register */
+??? u32??? det;??????? /* Event Detect Register */
+??? u32??? pad;??????? /* Pad Status Register */
+};
+
+struct nx_alive_gpio_regs {
+??? u32??? pwrgate;??? /* Power Gating Register */
+??? u32??? reserved0[28];??? /* Reserved0 */
+??? u32??? outputenb_reset;/* Alive GPIO Output Enable Reset Register */
+??? u32??? outputenb;??? /* Alive GPIO Output Enable Register */
+??? u32??? outputenb_read; /* Alive GPIO Output Read Register */
+??? u32??? reserved1[3];??? /* Reserved1 */
+??? u32??? pad_reset;??? /* Alive GPIO Output Reset Register */
+??? u32??? data;??????? /* Alive GPIO Output Register */
+??? u32??? pad_read;??? /* Alive GPIO Pad Read Register */
+??? u32??? reserved2[33];??? /* Reserved2 */
+??? u32??? pad;??????? /* Alive GPIO Input Value Register */
+};
+
+struct nx_gpio_platdata {
+??? void *regs;
+??? int gpio_count;
+??? const char *bank_name;
+};
+
+static int nx_alive_gpio_is_check(struct udevice *dev)
+{
+??? struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+??? const char *bank_name = plat->bank_name;
+
+??? if (!strcmp(bank_name, "gpio_alv"))
+??????? return 1;
+
+??? return 0;
+}
+
+static int nx_alive_gpio_direction_input(struct udevice *dev, unsigned int pin)
+{
+??? struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+??? struct nx_alive_gpio_regs *const regs = plat->regs;
+
+??? setbits_le32(&regs->outputenb_reset, 1 << pin);
+
+??? return 0;
+}
+
+static int nx_alive_gpio_direction_output(struct udevice *dev, unsigned int pin,
+????????????????????? int val)
+{
+??? struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+??? struct nx_alive_gpio_regs *const regs = plat->regs;
+
+??? if (val)
+??????? setbits_le32(&regs->data, 1 << pin);
+??? else
+??????? setbits_le32(&regs->pad_reset, 1 << pin);
+
+??? setbits_le32(&regs->outputenb, 1 << pin);
+
+??? return 0;
+}
+
+static int nx_alive_gpio_get_value(struct udevice *dev, unsigned int pin)
+{
+??? struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+??? struct nx_alive_gpio_regs *const regs = plat->regs;
+??? unsigned int mask = 1UL << pin;
+??? unsigned int value;
+
+??? value = (readl(&regs->pad_read) & mask) >> pin;
+
+??? return value;
+}
+
+static int nx_alive_gpio_set_value(struct udevice *dev, unsigned int pin,
+?????????????????? int val)
+{
+??? struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+??? struct nx_alive_gpio_regs *const regs = plat->regs;
+
+??? if (val)
+??????? setbits_le32(&regs->data, 1 << pin);
+??? else
+??????? clrbits_le32(&regs->pad_reset, 1 << pin);
+
+??? return 0;
+}
+
+static int nx_alive_gpio_get_function(struct udevice *dev, unsigned int pin)
+{
+??? struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+??? struct nx_alive_gpio_regs *const regs = plat->regs;
+??? unsigned int mask = (1UL << pin);
+??? unsigned int output;
+
+??? output = readl(&regs->outputenb_read) & mask;
+
+??? if (output)
+??????? return GPIOF_OUTPUT;
+??? else
+??????? return GPIOF_INPUT;
+}
+
+static int nx_gpio_direction_input(struct udevice *dev, unsigned int pin)
+{
+??? struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+??? struct nx_gpio_regs *const regs = plat->regs;
+
+??? if (nx_alive_gpio_is_check(dev))
+??????? return nx_alive_gpio_direction_input(dev, pin);
+
+??? clrbits_le32(&regs->outputenb, 1 << pin);
+
+??? return 0;
+}
+
+static int nx_gpio_direction_output(struct udevice *dev, unsigned int pin,
+??????????????????? int val)
+{
+??? struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+??? struct nx_gpio_regs *const regs = plat->regs;
+
+??? if (nx_alive_gpio_is_check(dev))
+??????? return nx_alive_gpio_direction_output(dev, pin, val);
+
+??? if (val)
+??????? setbits_le32(&regs->data, 1 << pin);
+??? else
+??????? clrbits_le32(&regs->data, 1 << pin);
+
+??? setbits_le32(&regs->outputenb, 1 << pin);
+
+??? return 0;
+}
+
+static int nx_gpio_get_value(struct udevice *dev, unsigned int pin)
+{
+??? struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+??? struct nx_gpio_regs *const regs = plat->regs;
+??? unsigned int mask = 1UL << pin;
+??? unsigned int value;
+
+??? if (nx_alive_gpio_is_check(dev))
+??????? return nx_alive_gpio_get_value(dev, pin);
+
+??? value = (readl(&regs->pad) & mask) >> pin;
+
+??? return value;
+}
+
+static int nx_gpio_set_value(struct udevice *dev, unsigned int pin, int val)
+{
+??? struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+??? struct nx_gpio_regs *const regs = plat->regs;
+
+??? if (nx_alive_gpio_is_check(dev))
+??????? return nx_alive_gpio_set_value(dev, pin, val);
+
+??? if (val)
+??????? setbits_le32(&regs->data, 1 << pin);
+??? else
+??????? clrbits_le32(&regs->data, 1 << pin);
+
+??? return 0;
+}
+
+static int nx_gpio_get_function(struct udevice *dev, unsigned int pin)
+{
+??? struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+??? struct nx_gpio_regs *const regs = plat->regs;
+??? unsigned int mask = (1UL << pin);
+??? unsigned int output;
+
+??? if (nx_alive_gpio_is_check(dev))
+??????? return nx_alive_gpio_get_function(dev, pin);
+
+??? output = readl(&regs->outputenb) & mask;
+
+??? if (output)
+??????? return GPIOF_OUTPUT;
+??? else
+??????? return GPIOF_INPUT;
+}
+
+static int nx_gpio_probe(struct udevice *dev)
+{
+??? struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
+??? struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+
+??? uc_priv->gpio_count = plat->gpio_count;
+??? uc_priv->bank_name = plat->bank_name;
+
+??? return 0;
+}
+
+static int nx_gpio_ofdata_to_platdata(struct udevice *dev)
+{
+??? struct nx_gpio_platdata *plat = dev_get_platdata(dev);
+
+??? plat->regs = map_physmem(devfdt_get_addr(dev),
+???????????????? sizeof(struct nx_gpio_regs),
+???????????????? MAP_NOCACHE);
+??? plat->gpio_count = fdtdec_get_int(gd->fdt_blob, dev->node.of_offset,
+????????????????????? "nexell,gpio-bank-width", 32);
+??? plat->bank_name = fdt_getprop(gd->fdt_blob, dev->node.of_offset,
+????????????????????? "gpio-bank-name", NULL);
+
+??? return 0;
+}
+
+static const struct dm_gpio_ops nx_gpio_ops = {
+??? .direction_input??? = nx_gpio_direction_input,
+??? .direction_output??? = nx_gpio_direction_output,
+??? .get_value??????? = nx_gpio_get_value,
+??? .set_value??????? = nx_gpio_set_value,
+??? .get_function??????? = nx_gpio_get_function,
+};
+
+static const struct udevice_id nx_gpio_ids[] = {
+??? { .compatible = "nexell,nexell-gpio" },
+??? { }
+};
+
+U_BOOT_DRIVER(nx_gpio) = {
+??? .name??????? = "nx_gpio",
+??? .id??????? = UCLASS_GPIO,
+??? .of_match??? = nx_gpio_ids,
+??? .ops??????? = &nx_gpio_ops,
+??? .ofdata_to_platdata = nx_gpio_ofdata_to_platdata,
+??? .platdata_auto_alloc_size = sizeof(struct nx_gpio_platdata),
+??? .probe??????? = nx_gpio_probe,
+};
drivers/i2c/Kconfig +0 -0
index 03d2fed..2cd0ed3 100644
@@ -317,6 +317,15 @@ config SYS_MXC_I2C8_SLAVE

?????? MXC I2C8 Slave
? endif

drivers/i2c/Kconfig +9 -0
+config SYS_I2C_NEXELL
+??? bool "Nexell I2C driver"
+??? depends on DM_I2C
+??? help
+????? Add support for the Nexell I2C driver. This is used with various
+????? Nexell parts such as S5Pxx18 series SoCs. All chips
+????? have several I2C ports and all are provided, controlled by the
+????? device tree.
+

? config SYS_I2C_OMAP24XX
????? bool "TI OMAP2+ I2C driver"
????? depends on ARCH_OMAP2PLUS || ARCH_K3

drivers/i2c/Makefile +0 -0
index f5a471f..64b8ead 100644
@@ -26,6 +26,7 @@ obj-$(CONFIG_SYS_I2C_LPC32XX) += lpc32xx_i2c.o

? obj-$(CONFIG_SYS_I2C_MESON) += meson_i2c.o ? obj-$(CONFIG_SYS_I2C_MVTWSI) += mvtwsi.o ? obj-$(CONFIG_SYS_I2C_MXC) += mxc_i2c.o +obj-$(CONFIG_SYS_I2C_NEXELL) += nx_i2c.o ? obj-$(CONFIG_SYS_I2C_OMAP24XX) += omap24xx_i2c.o ? obj-$(CONFIG_SYS_I2C_RCAR_I2C) += rcar_i2c.o ? obj-$(CONFIG_SYS_I2C_RCAR_IIC) += rcar_iic.o

drivers/i2c/nx_i2c.c new file +32 -0
new file mode 100644
index 0000000..a3eec6c
@@ -0,0 +1,537 @@
+#include <common.h>
+#include <errno.h>
+#include <dm.h>
+#include <i2c.h>
+#include <asm/arch/nexell.h>
+#include <asm/arch/reset.h>
+#include <asm/arch/clk.h>
+#include <asm/arch/nx_gpio.h>
+
+#define I2C_WRITE?????? 0
+#define I2C_READ??????? 1
+
+#define I2C_OK????????? 0
+#define I2C_NOK???????? 1
+#define I2C_NACK??????? 2
+#define I2C_NOK_LA????? 3?????? /* Lost arbitration */
+#define I2C_NOK_TOUT??? 4?????? /* time out */
+
+#define I2CLC_FILTER??? 0x04??? /* SDA filter on*/
+#define I2CSTAT_BSY???? 0x20??? /* Busy bit */
+#define I2CSTAT_NACK??? 0x01??? /* Nack bit */
+#define I2CSTAT_ABT??? 0x08??? /* Arbitration bit */
+#define I2CCON_ACKGEN?? 0x80??? /* Acknowledge generation */
+#define I2CCON_IRENB??? 0x20??? /* Interrupt Enable bit? */
+#define I2CCON_IRPND??? 0x10??? /* Interrupt pending bit */
+#define I2C_MODE_MT???? 0xC0??? /* Master Transmit Mode */
+#define I2C_MODE_MR???? 0x80??? /* Master Receive Mode */
+#define I2C_START_STOP? 0x20??? /* START / STOP */
+#define I2C_TXRX_ENA??? 0x10??? /* I2C Tx/Rx enable */
+
+#define I2C_TIMEOUT_MS??? 10????? /* 10 ms */
+
Quoted 8 lines

drivers/i2c/nx_i2c.c line 37

Quoted 5 lines
drivers/i2c/nx_i2c.c new file +5 -0
+#define I2C_M_NOSTOP??? 0x100
+
+#ifndef CONFIG_MAX_I2C_NUM
+#define CONFIG_MAX_I2C_NUM 3
+#endif

Is this really configurable? If so, I do not find the Kconfig description.

Quoted 1 line

No, it is not configurable. I have changed it to MAX_I2C_NUM.

Ok.

Quoted 51 lines
Quoted 42 lines
Quoted 42 lines
drivers/i2c/nx_i2c.c new file +42 -0
+
+DECLARE_GLOBAL_DATA_PTR;
+
+struct nx_i2c_regs {
+??? uint???? iiccon;
+??? uint???? iicstat;
+??? uint???? iicadd;
+??? uint???? iicds;
+??? uint???? iiclc;
+};
+
+struct nx_i2c_bus {
+??? uint bus_num;
+??? struct nx_i2c_regs *regs;
+??? uint speed;
+??? uint target_speed;
+??? uint sda_delay;
+};
+
+/* s5pxx18 i2c must be reset before enabled */
+static void i2c_reset(int ch)
+{
+??? int rst_id = RESET_ID_I2C0 + ch;
+
+??? nx_rstcon_setrst(rst_id, 0);
+??? nx_rstcon_setrst(rst_id, 1);
+}
+
+/* FIXME : this func will be removed after reset dm driver ported.
+ * set mmc pad alternative func.
+ */
+static void set_i2c_pad_func(struct nx_i2c_bus *i2c)
+{
+??? switch (i2c->bus_num) {
+??? case 0:
+??????? nx_gpio_set_pad_function(3, 2, 1);
+??????? nx_gpio_set_pad_function(3, 3, 1);
+??????? break;
+??? case 1:
+??????? nx_gpio_set_pad_function(3, 4, 1);
+??????? nx_gpio_set_pad_function(3, 5, 1);
+??????? break;
Quoted 8 lines

drivers/i2c/nx_i2c.c line 85

Quoted 6 lines
drivers/i2c/nx_i2c.c new file +6 -0
+??? case 2:
+??????? nx_gpio_set_pad_function(3, 6, 1);
+??????? nx_gpio_set_pad_function(3, 7, 1);
+??????? break;
+??? }
+}

Hmm... may this should be moved into a seperate pincontrol driver?

Quoted 2 lines

According to the above FIXME comment from Nexell it probably should. But there is no pincontrol driver implemented. But is the change to a driver necessary for now?

Hmm.. it would be better to have a pinctrl driver, but I can accept it for now.

Quoted 9 lines
Quoted 9 lines

drivers/i2c/nx_i2c.c

Quoted 6 lines
drivers/i2c/nx_i2c.c new file +6 -0
+
+static uint i2c_get_clkrate(struct nx_i2c_bus *bus)
+{
+??? struct clk *clk;
+??? int index = bus->bus_num;
+??? char name[50] = {0, };

?

Quoted 6 lines
Quoted 4 lines

drivers/i2c/nx_i2c.c line 93

Quoted 2 lines
drivers/i2c/nx_i2c.c new file +2 -0
+
+??? sprintf(name, "%s.%d", DEV_NAME_I2C, index);

Where is DEV_NAME_I2C defined ?

DEV_NAME_I2C is defined in arch/arm/mach-nexell/include/mach/nexell.h

Ah, ok.

Quoted 51 lines
Quoted 51 lines
Quoted 34 lines
drivers/i2c/nx_i2c.c new file +32 -0
+??? clk = clk_get((const char *)name);
+??? if (!clk)
+??????? return -1;
+
+??? return clk_get_rate(clk);
+}
+
+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)
+??????? return -1;
+
+??? if (enb) {
+??????? clk_disable(clk);
+??????? clk_enable(clk);
+??? } else {
+??????? clk_disable(clk);
+??? }
+
+??? return 0;
+}
+
+/* get i2c module number from base address */
+static uint i2c_get_busnum(struct nx_i2c_bus *bus)
+{
+??? void *base_addr = (void *)PHY_BASEADDR_I2C0;
+??? int i;

drivers/i2c/nx_i2c.c line 135

Quoted 10 lines
drivers/i2c/nx_i2c.c new file +10 -0
+
+??? for (i = 0; i < CONFIG_MAX_I2C_NUM; i++) {
+??????? if (base_addr == ((void *)bus->regs)) {
+??????????? bus->bus_num = i;
+??????????? return i;
+??????? }
+??????? base_addr += 0x1000;
+??? }
+
+??? return -1;

return -ENODEV;

Hmm... is there no chance to use seq from struct udevice

https://gitlab.denx.de/u-boot/u-boot/blob/master/include/dm/device.h#L152

Quoted 7 lines
Quoted 5 lines

?

For example like:
https://gitlab.denx.de/u-boot/u-boot/blob/master/drivers/i2c/mxc_i2c.c#L895

Ok, I have changed this as proposed.

Thanks!

Quoted 56 lines
Quoted 56 lines
Quoted 42 lines
drivers/i2c/nx_i2c.c new file +42 -0
+}
+
+/* Set SDA line delay */
+static int nx_i2c_set_sda_delay(struct nx_i2c_bus *bus, ulong clkin)
+{
+??? struct nx_i2c_regs *i2c = bus->regs;
+??? uint sda_delay = 0;
+
+??? if (bus->sda_delay) {
+??????? sda_delay = clkin * bus->sda_delay;
+??????? sda_delay = DIV_ROUND_UP(sda_delay, 1000000);
+??????? sda_delay = DIV_ROUND_UP(sda_delay, 5);
+??????? if (sda_delay > 3)
+??????????? sda_delay = 3;
+??????? sda_delay |= I2CLC_FILTER;
+??? } else {
+??????? sda_delay = 0;
+??? }
+
+??? sda_delay &= 0x7;
+??? writel(sda_delay, &i2c->iiclc);
+
+??? return 0;
+}
+
+/* Calculate the value of the divider and prescaler, set the bus speed. */
+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 freq, pres = 16, div;
+
+??? freq = i2c_get_clkrate(bus);
+??? /* calculate prescaler and divisor values */
+??? if ((freq / pres / (16 + 1)) > speed)
+??????? /* set prescaler to 512 */
+??????? pres = 512;
+
+??? div = 0;
+??? while ((freq / pres / (div + 1)) > speed)
+??????? div++;
+

drivers/i2c/nx_i2c.c line 187

Quoted 10 lines
drivers/i2c/nx_i2c.c new file +10 -0
+??? /* set prescaler, divisor according to freq, also set ACKGEN, IRQ */
+??? writel((div & 0x0F) | ((pres == 512) ? 0x40 : 0), &i2c->iiccon);
+
+??? /* init to SLAVE REVEIVE and set slaveaddr */
+??? writel(0, &i2c->iicstat);
+??? writel(0x00, &i2c->iicadd);
+??? /* program Master Transmit (and implicit STOP) */
+??? writel(I2C_MODE_MT | I2C_TXRX_ENA, &i2c->iicstat);
+
+??? bus->speed = bus->target_speed / (div * pres);

Do you want to allow all values of speeds or may you want to use standard speeds, see:

Quoted 7 lines
Quoted 2 lines

https://gitlab.denx.de/u-boot/u-boot/blob/master/include/i2c.h#L33

I'd like to allow all values of speed. In my opinion allowing only standard speeds does complicate things (e.g. how to do error handling?). Furthermore I think sometimes it could be handy to be able to set speed to an arbitrary value (e.g. to a lower value than 100000) when trying a new i2c-device on the bus.

ok.

Quoted 33 lines
Quoted 33 lines
Quoted 19 lines
drivers/i2c/nx_i2c.c new file +18 -0
+
+??? return 0;
+}
+
+static void nx_i2c_set_clockrate(struct udevice *dev, uint speed)
+{
+??? struct nx_i2c_bus *bus = dev_get_priv(dev);
+??? ulong clkin;
+
+??? nx_i2c_set_bus_speed(dev, speed);
+??? clkin = bus->speed;??????????? /* the actual i2c speed */
+??? clkin /= 1000;??????????????? /* clkin now in Khz */
+??? nx_i2c_set_sda_delay(bus, clkin);
+}
+
+static void i2c_process_node(struct udevice *dev)
+{
+??? struct nx_i2c_bus *bus = dev_get_priv(dev);

drivers/i2c/nx_i2c.c line 215

Quoted 10 lines
drivers/i2c/nx_i2c.c new file +10 -0
+??? const void *blob = gd->fdt_blob;
+
+??? int node;
+
+??? node = dev->node.of_offset;
+
+??? bus->target_speed = fdtdec_get_int(blob, node,
+?????????????????????? "nexell,i2c-max-bus-freq", 0);
+??? bus->sda_delay = fdtdec_get_int(blob, node,
+??????????????????? "nexell,i2c-sda-delay", 0);

You introdue here new properties, please document them in u-boot:/doc/device-tree-bindings/i2c

Quoted 6 lines
Quoted 2 lines

Please without "nexell,"

I have changed "nexell,i2c-max-bus-freq" to the already defined "clock-frequency". Furthermore I have changed "nexell,i2c-sda-delay" to "i2c-sda-delay-ns".
Furthermore, I have added "nx_i2c.txt" in doc/device-tree-bindings/i2c.

Thanks!

Quoted 8 lines
Quoted 6 lines

Do you plan to post also a linux i2c driver?

If so, the devicetree bindings should be discussed there to avoid different properties between U-Boot and linux!

No, I do not plan to post a linux driver.

Ok.

Quoted 29 lines
Quoted 16 lines

drivers/i2c/nx_i2c.c line 227

Quoted 13 lines
drivers/i2c/nx_i2c.c new file +12 -0
+}
+
+static int nx_i2c_probe(struct udevice *dev)
+{
+??? struct nx_i2c_bus *bus = dev_get_priv(dev);
+
+??? /* get regs */
+??? bus->regs = (struct nx_i2c_regs *)devfdt_get_addr(dev);
+??? /* calc index */
+??? if (!i2c_get_busnum(bus)) {
+??????? debug("not found i2c number!\n");
+??????? return -1;

please return -ENODEV

Ok

Quoted 9 lines

drivers/i2c/nx_i2c.c line 233

Quoted 6 lines
drivers/i2c/nx_i2c.c new file +6 -0
+??? }
+
+??? /* i2c optional node parsing */
+??? i2c_process_node(dev);
+??? if (!bus->target_speed)
+??????? return -1;

please return here also an errorcode from include/linux/errno.h

Quoted 6 lines

Ok

Quoted 2 lines

Hmm.. if you return here if target_speed is not set, it is not optional!

You are right, I have removed 'optional' in the comment.

Thanks.

Quoted 1,019 lines
Quoted 1,019 lines
Quoted 284 lines
drivers/i2c/nx_i2c.c new file +283 -0
+
+??? /* reset */
+??? i2c_reset(bus->bus_num);
+??? /* gpio pad */
+??? set_i2c_pad_func(bus);
+
+??? /* clock rate */
+??? i2c_set_clk(bus, 1);
+??? nx_i2c_set_clockrate(dev, bus->target_speed);
+??? i2c_set_clk(bus, 0);
+
+??? return 0;
+}
+
+/* i2c bus busy check */
+static int i2c_is_busy(struct nx_i2c_regs *i2c)
+{
+??? ulong start_time;
+
+??? start_time = get_timer(0);
+??? while (readl(&i2c->iicstat) & I2CSTAT_BSY) {
+??????? if (get_timer(start_time) > I2C_TIMEOUT_MS) {
+??????????? debug("Timeout\n");
+??????????? return -I2C_NOK_TOUT;
+??????? }
+??? }
+??? return 0;
+}
+
+/* irq enable/disable functions */
+static void i2c_enable_irq(struct nx_i2c_regs *i2c)
+{
+??? unsigned int reg;
+
+??? reg = readl(&i2c->iiccon);
+??? reg |= I2CCON_IRENB;
+??? writel(reg, &i2c->iiccon);
+}
+
+/* irq clear function */
+static void i2c_clear_irq(struct nx_i2c_regs *i2c)
+{
+??? clrbits_le32(&i2c->iiccon, I2CCON_IRPND);
+}
+
+/* ack enable functions */
+static void i2c_enable_ack(struct nx_i2c_regs *i2c)
+{
+??? unsigned int reg;
+
+??? reg = readl(&i2c->iiccon);
+??? reg |= I2CCON_ACKGEN;
+??? writel(reg, &i2c->iiccon);
+}
+
+static void i2c_send_stop(struct nx_i2c_regs *i2c)
+{
+??? unsigned int reg;
+
+??? /* Send STOP. */
+??? reg = readl(&i2c->iicstat);
+??? reg |= I2C_MODE_MR | I2C_TXRX_ENA;
+??? reg &= (~I2C_START_STOP);
+??? writel(reg, &i2c->iicstat);
+??? i2c_clear_irq(i2c);
+}
+
+static int wait_for_xfer(struct nx_i2c_regs *i2c)
+{
+??? unsigned long start_time = get_timer(0);
+
+??? do {
+??????? if (readl(&i2c->iiccon) & I2CCON_IRPND)
+??????????? return (readl(&i2c->iicstat) & I2CSTAT_NACK) ?
+??????????????? I2C_NACK : I2C_OK;
+??? } while (get_timer(start_time) < I2C_TIMEOUT_MS);
+
+??? return I2C_NOK_TOUT;
+}
+
+static int i2c_transfer(struct nx_i2c_regs *i2c,
+??????????? uchar cmd_type,
+??????????? uchar chip,
+??????????? uchar addr[],
+??????????? uchar addr_len,
+??????????? uchar data[],
+??????????? unsigned short data_len,
+??????????? uint seq)
+{
+??? uint status;
+??? int i = 0, result;
+
+??? if (data == 0 || data_len == 0) {
+??????? /*Don't support data transfer of no length or to address 0 */
+??????? debug("%s: bad call\n", __func__);
+??????? return I2C_NOK;
+??? }
+
+??? i2c_enable_irq(i2c);
+??? i2c_enable_ack(i2c);
+
+??? /* Get the slave chip address going */
+??? writel(chip, &i2c->iicds);
+??? status = I2C_TXRX_ENA | I2C_START_STOP;
+??? if (cmd_type == I2C_WRITE || (addr && addr_len))
+??????? status |= I2C_MODE_MT;
+??? else
+??????? status |= I2C_MODE_MR;
+??? writel(status, &i2c->iicstat);
+??? if (seq)
+??????? i2c_clear_irq(i2c);
+
+??? /* Wait for chip address to transmit. */
+??? result = wait_for_xfer(i2c);
+??? if (result != I2C_OK)
+??????? goto bailout;
+
+??? /* If register address needs to be transmitted - do it now. */
+??? if (addr && addr_len) {? /* register addr */
+??????? while ((i < addr_len) && (result == I2C_OK)) {
+??????????? writel(addr[i++], &i2c->iicds);
+??????????? i2c_clear_irq(i2c);
+??????????? result = wait_for_xfer(i2c);
+??????? }
+
+??????? i = 0;
+??????? if (result != I2C_OK)
+??????????? goto bailout;
+??? }
+
+??? switch (cmd_type) {
+??? case I2C_WRITE:
+??????? while ((i < data_len) && (result == I2C_OK)) {
+??????????? writel(data[i++], &i2c->iicds);
+??????????? i2c_clear_irq(i2c);
+??????????? result = wait_for_xfer(i2c);
+??????? }
+??????? break;
+??? case I2C_READ:
+??????? if (addr && addr_len) {
+??????????? /*
+???????????? * Register address has been sent, now send slave chip
+???????????? * address again to start the actual read transaction.
+???????????? */
+??????????? writel(chip, &i2c->iicds);
+
+??????????? /* Generate a re-START. */
+??????????? writel(I2C_MODE_MR | I2C_TXRX_ENA
+??????????????????? | I2C_START_STOP, &i2c->iicstat);
+??????????? i2c_clear_irq(i2c);
+??????????? result = wait_for_xfer(i2c);
+??????????? if (result != I2C_OK)
+??????????????? goto bailout;
+??????? }
+
+??????? while ((i < data_len) && (result == I2C_OK)) {
+??????????? /* disable ACK for final READ */
+??????????? if (i == data_len - 1)
+??????????????? clrbits_le32(&i2c->iiccon
+??????????????????????? , I2CCON_ACKGEN);
+
+??????????? i2c_clear_irq(i2c);
+??????????? result = wait_for_xfer(i2c);
+??????????? data[i++] = readb(&i2c->iicds);
+??????? }
+
+??????? if (result == I2C_NACK)
+??????????? result = I2C_OK; /* Normal terminated read. */
+??????? break;
+
+??? default:
+??????? debug("%s: bad call\n", __func__);
+??????? result = I2C_NOK;
+??????? break;
+??? }
+
+bailout:
+??? return result;
+}
+
+static int nx_i2c_read(struct udevice *dev, uchar chip, uint addr,
+?????????????? uint alen, uchar *buffer, uint len, uint seq)
+{
+??? struct nx_i2c_bus *i2c;
+??? uchar xaddr[4];
+??? int ret;
+
+??? i2c = dev_get_priv(dev);
+??? if (!i2c)
+??????? return -EFAULT;
+
+??? if (alen > 4) {
+??????? debug("I2C read: addr len %d not supported\n", alen);
+??????? return -EADDRNOTAVAIL;
+??? }
+
+??? if (alen > 0)
+??????? xaddr[0] = (addr >> 24) & 0xFF;
+
+??? if (alen > 0) {
+??????? xaddr[0] = (addr >> 24) & 0xFF;
+??????? xaddr[1] = (addr >> 16) & 0xFF;
+??????? xaddr[2] = (addr >> 8) & 0xFF;
+??????? xaddr[3] = addr & 0xFF;
+??? }
+
+??? ret = i2c_transfer(i2c->regs, I2C_READ, chip << 1,
+?????????????? &xaddr[4 - alen], alen, buffer, len, seq);
+
+??? if (ret) {
+??????? debug("I2C read failed %d\n", ret);
+??????? return -EIO;
+??? }
+
+??? return 0;
+}
+
+static int nx_i2c_write(struct udevice *dev, uchar chip, uint addr,
+??????????? uint alen, uchar *buffer, uint len, uint seq)
+{
+??? struct nx_i2c_bus *i2c;
+??? uchar xaddr[4];
+??? int ret;
+
+??? i2c = dev_get_priv(dev);
+??? if (!i2c)
+??????? return -EFAULT;
+
+??? if (alen > 4) {
+??????? debug("I2C write: addr len %d not supported\n", alen);
+??????? return -EINVAL;
+??? }
+
+??? if (alen > 0) {
+??????? xaddr[0] = (addr >> 24) & 0xFF;
+??????? xaddr[1] = (addr >> 16) & 0xFF;
+??????? xaddr[2] = (addr >> 8) & 0xFF;
+??????? xaddr[3] = addr & 0xFF;
+??? }
+
+??? ret = i2c_transfer(i2c->regs, I2C_WRITE, chip << 1,
+?????????????? &xaddr[4 - alen], alen, buffer, len, seq);
+??? if (ret) {
+??????? debug("I2C write failed %d\n", ret);
+??????? return -EIO;
+??? }
+
+??? return 0;
+}
+
+static int nx_i2c_xfer(struct udevice *dev, struct i2c_msg *msg, int nmsgs)
+{
+??? struct nx_i2c_bus *bus = dev_get_priv(dev);
+??? struct nx_i2c_regs *i2c = bus->regs;
+??? int ret;
+??? int i;
+
+??? /* The power loss by the clock, only during on/off. */
+??? i2c_set_clk(bus, 1);
+
+??? /* Bus State(Busy) check? */
+??? ret = i2c_is_busy(i2c);
+??? if (ret < 0)
+??????? return ret;
+
+??? for (i = 0; i < nmsgs; msg++, i++) {
+??????? if (msg->flags & I2C_M_RD) {
+??????????? ret = nx_i2c_read(dev, msg->addr, 0, 0, msg->buf,
+????????????????????? msg->len, i);
+??????? } else {
+??????????? ret = nx_i2c_write(dev, msg->addr, 0, 0, msg->buf,
+?????????????????????? msg->len, i);
+??????? }
+
+??????? if (ret) {
+??????????? debug("i2c_xfer: error sending\n");
+??????????? return -EREMOTEIO;
+??????? }
+??? }
+??? /* Send Stop */
+??? i2c_send_stop(i2c);
+??? i2c_set_clk(bus, 0);
+

drivers/i2c/nx_i2c.c line 526

Quoted 10 lines
drivers/i2c/nx_i2c.c new file +10 -0
+??? return ret ? -EREMOTEIO : 0;
+};
+
+static const struct dm_i2c_ops nx_i2c_ops = {
+??? .xfer??????? = nx_i2c_xfer,
+??? .set_bus_speed??? = nx_i2c_set_bus_speed,
+};
+
+static const struct udevice_id nx_i2c_ids[] = {
+??? { .compatible = "nexell,s5pxx18-i2c" },

Same here as for the new properties. Please discuss the names on

devicetree at vger.kernel.org <[email protected]>

first!

drivers/i2c/nx_i2c.c line 537

Quoted 11 lines
drivers/i2c/nx_i2c.c new file +11 -0
+??? { }
+};
+
+U_BOOT_DRIVER(i2c_nexell) = {
+??? .name??????? = "i2c_nexell",
+??? .id??????? = UCLASS_I2C,
+??? .of_match??? = nx_i2c_ids,
+??? .probe??????? = nx_i2c_probe,
+??? .priv_auto_alloc_size??? = sizeof(struct nx_i2c_bus),
+??? .ops??????? = &nx_i2c_ops,
+};

bye,
Heiko

Quoted 704 lines
drivers/mmc/Kconfig +0 -0
index 2f0eedc..bb8e7c0 100644
@@ -253,6 +253,12 @@ config MMC_DW_SNPS

??????? This selects support for Synopsys DesignWare Memory Card Interface driver ??????? extensions used in various Synopsys ARC devboards.

drivers/mmc/Kconfig +6 -0
+config NEXELL_DWMMC
+??? bool "Nexell SD/MMC controller support"
+??? depends on ARCH_NEXELL
+??? depends on MMC_DW
+??? default y
+

? config MMC_MESON_GX
????? bool "Meson GX EMMC controller support"
????? depends on DM_MMC && BLK && ARCH_MESON

drivers/mmc/Makefile +0 -0
index 9c1f8e5..a7b5a7b 100644
@@ -43,6 +43,7 @@ obj-$(CONFIG_SH_MMCIF) += sh_mmcif.o

? obj-$(CONFIG_SH_SDHI) += sh_sdhi.o
? obj-$(CONFIG_STM32_SDMMC2) += stm32_sdmmc2.o
? obj-$(CONFIG_JZ47XX_MMC) += jz_mmc.o
+obj-$(CONFIG_NEXELL_DWMMC) += nexell_dw_mmc_dm.o
? # SDHCI
? obj-$(CONFIG_MMC_SDHCI)??????????? += sdhci.o

drivers/mmc/nexell_dw_mmc_dm.c new file +350 -0
new file mode 100644
index 0000000..b06b60d
@@ -0,0 +1,350 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2016 Nexell
+ * Youngbok, Park <[email protected]>
+ *
+ * (C) Copyright 2019 Stefan Bosch <[email protected]>
+ */
+
+#include <common.h>
+#include <clk.h>
+#include <dm.h>
+#include <dt-structs.h>
+#include <dwmmc.h>
+#include <syscon.h>
+#include <asm/gpio.h>
+#include <asm/arch/nx_gpio.h>
+#include <asm/arch/reset.h>
+
+#define DWMCI_CLKSEL??????????? 0x09C
+#define DWMCI_SHIFT_0??????????? 0x0
+#define DWMCI_SHIFT_1??????????? 0x1
+#define DWMCI_SHIFT_2??????????? 0x2
+#define DWMCI_SHIFT_3??????????? 0x3
+#define DWMCI_SET_SAMPLE_CLK(x)??? (x)
+#define DWMCI_SET_DRV_CLK(x)??? ((x) << 16)
+#define DWMCI_SET_DIV_RATIO(x)??? ((x) << 24)
+#define DWMCI_CLKCTRL??????????? 0x114
+#define NX_MMC_CLK_DELAY(x, y, a, b)??? ((((x) & 0xFF) << 0) |\
+??????????????????? (((y) & 0x03) << 16) |\
+??????????????????? (((a) & 0xFF) << 8)? |\
+??????????????????? (((b) & 0x03) << 24))
+
+struct nexell_mmc_plat {
+??? struct mmc_config cfg;
+??? struct mmc mmc;
+};
+
+struct nexell_dwmmc_priv {
+??? struct clk *clk;
+??? struct dwmci_host host;
+??? int fifo_size;
+??? bool fifo_mode;
+??? int frequency;
+??? u32 min_freq;
+??? u32 max_freq;
+??? int d_delay;
+??? int d_shift;
+??? int s_delay;
+??? int s_shift;
+
+};
+
+struct clk *clk_get(const char *id);
+
+static void set_pin_stat(int index, int bit, int value)
+{
+#if !defined(CONFIG_SPL_BUILD)
+??? nx_gpio_set_pad_function(index, bit, value);
+#else
+#if defined(CONFIG_ARCH_S5P4418) ||??? \
+??? defined(CONFIG_ARCH_S5P6818)
+
+??? unsigned long base[5] = {
+??????? PHY_BASEADDR_GPIOA, PHY_BASEADDR_GPIOB,
+??????? PHY_BASEADDR_GPIOC, PHY_BASEADDR_GPIOD,
+??????? PHY_BASEADDR_GPIOE,
+??? };
+
+??? dw_mmc_set_pin(base[index], bit, value);
+#endif
+#endif
+}
+
+static void nx_dw_mmc_set_pin(struct dwmci_host *host)
+{
+??? debug("? %s(): dev_index == %d", __func__, host->dev_index);
+
+??? switch (host->dev_index) {
+??? case 0:
+??????? set_pin_stat(0, 29, 1);
+??????? set_pin_stat(0, 31, 1);
+??????? set_pin_stat(1, 1, 1);
+??????? set_pin_stat(1, 3, 1);
+??????? set_pin_stat(1, 5, 1);
+??????? set_pin_stat(1, 7, 1);
+??????? break;
+??? case 1:
+??????? set_pin_stat(3, 22, 1);
+??????? set_pin_stat(3, 23, 1);
+??????? set_pin_stat(3, 24, 1);
+??????? set_pin_stat(3, 25, 1);
+??????? set_pin_stat(3, 26, 1);
+??????? set_pin_stat(3, 27, 1);
+??????? break;
+??? case 2:
+??????? set_pin_stat(2, 18, 2);
+??????? set_pin_stat(2, 19, 2);
+??????? set_pin_stat(2, 20, 2);
+??????? set_pin_stat(2, 21, 2);
+??????? set_pin_stat(2, 22, 2);
+??????? set_pin_stat(2, 23, 2);
+??????? if (host->buswidth == 8) {
+??????????? set_pin_stat(4, 21, 2);
+??????????? set_pin_stat(4, 22, 2);
+??????????? set_pin_stat(4, 23, 2);
+??????????? set_pin_stat(4, 24, 2);
+??????? }
+??????? break;
+??? default:
+??????? debug(" is invalid!");
+??? }
+??? debug("\n");
+}
+
+static void nx_dw_mmc_clksel(struct dwmci_host *host)
+{
+??? u32 val;
+
+#ifdef CONFIG_BOOST_MMC
+??? val = DWMCI_SET_SAMPLE_CLK(DWMCI_SHIFT_0) |
+??????? DWMCI_SET_DRV_CLK(DWMCI_SHIFT_0) | DWMCI_SET_DIV_RATIO(1);
+#else
+??? val = DWMCI_SET_SAMPLE_CLK(DWMCI_SHIFT_0) |
+??????? DWMCI_SET_DRV_CLK(DWMCI_SHIFT_0) | DWMCI_SET_DIV_RATIO(3);
+#endif
+
+??? dwmci_writel(host, DWMCI_CLKSEL, val);
+}
+
+static void nx_dw_mmc_reset(int ch)
+{
+??? int rst_id = RESET_ID_SDMMC0 + ch;
+
+??? nx_rstcon_setrst(rst_id, 0);
+??? nx_rstcon_setrst(rst_id, 1);
+}
+
+static void nx_dw_mmc_clk_delay(struct udevice *dev)
+{
+??? unsigned int delay;
+??? struct nexell_dwmmc_priv *priv = dev_get_priv(dev);
+??? struct dwmci_host *host = &priv->host;
+
+??? delay = NX_MMC_CLK_DELAY(priv->d_delay,
+???????????????? priv->d_shift, priv->s_delay, priv->s_shift);
+
+??? writel(delay, (host->ioaddr + DWMCI_CLKCTRL));
+??? debug("%s(): Values set: d_delay==%d, d_shift==%d, s_delay==%d, "
+????????? "s_shift==%d\n", __func__, priv->d_delay, priv->d_shift,
+????????? priv->s_delay, priv->s_shift);
+}
+
+static unsigned int nx_dw_mmc_get_clk(struct dwmci_host *host, uint freq)
+{
+??? struct clk *clk;
+??? struct udevice *dev = host->priv;
+??? struct nexell_dwmmc_priv *priv = dev_get_priv(dev);
+
+??? int index = host->dev_index;
+??? char name[50] = { 0, };
+
+??? clk = priv->clk;
+??? if (!clk) {
+??????? sprintf(name, "%s.%d", DEV_NAME_SDHC, index);
+??????? clk = clk_get((const char *)name);
+??????? if (!clk)
+??????????? return 0;
+??????? priv->clk = clk;
+??? }
+
+??? return clk_get_rate(clk) / 2;
+}
+
+static unsigned long nx_dw_mmc_set_clk(struct dwmci_host *host,
+?????????????????????? unsigned int rate)
+{
+??? struct clk *clk;
+??? char name[50] = { 0, };
+??? struct udevice *dev = host->priv;
+??? struct nexell_dwmmc_priv *priv = dev_get_priv(dev);
+
+??? int index = host->dev_index;
+
+??? clk = priv->clk;
+??? if (!clk) {
+??????? sprintf(name, "%s.%d", DEV_NAME_SDHC, index);
+??????? clk = clk_get((const char *)name);
+??????? if (!clk)
+??????????? return 0;
+??????? priv->clk = clk;
+??? }
+
+??? clk_disable(clk);
+??? rate = clk_set_rate(clk, rate);
+??? clk_enable(clk);
+
+??? return rate;
+}
+
+static int nexell_dwmmc_ofdata_to_platdata(struct udevice *dev)
+{
+??? /* if (dev): *priv = dev->priv, else: *priv = NULL */
+??? struct nexell_dwmmc_priv *priv = dev_get_priv(dev);
+??? struct dwmci_host *host = &priv->host;
+??? int val = -1;
+
+??? debug("%s()\n", __func__);
+
+??? host->name = dev->name;
+??? host->ioaddr = dev_read_addr_ptr(dev);
+
+??? val = dev_read_u32_default(dev, "nexell,bus-width", -1);
+??? if (val < 0) {
+??????? debug("? 'nexell,bus-width' missing/invalid!\n");
+??????? return -EINVAL;
+??? }
+??? host->buswidth = val;
+??? host->get_mmc_clk = nx_dw_mmc_get_clk;
+??? host->clksel = nx_dw_mmc_clksel;
+??? host->priv = dev;
+
+??? val = dev_read_u32_default(dev, "index", -1);
+??? if (val < 0) {
+??????? debug("? 'index' missing/invalid!\n");
+??????? return -EINVAL;
+??? }
+??? host->dev_index = val;
+
+??? val = dev_read_u32_default(dev, "fifo-size", 0x20);
+??? if (val <= 0) {
+??????? debug("? 'fifo-size' missing/invalid!\n");
+??????? return -EINVAL;
+??? }
+??? priv->fifo_size = val;
+
+??? priv->fifo_mode = dev_read_bool(dev, "fifo-mode");
+
+??? val = dev_read_u32_default(dev, "frequency", -1);
+??? if (val < 0) {
+??????? debug("? 'frequency' missing/invalid!\n");
+??????? return -EINVAL;
+??? }
+??? priv->frequency = val;
+
+??? val = dev_read_u32_default(dev, "max-frequency", -1);
+??? if (val < 0) {
+??????? debug("? 'max-frequency' missing/invalid!\n");
+??????? return -EINVAL;
+??? }
+??? priv->max_freq = val;
+??? priv->min_freq = 400000;? /* 400 kHz */
+
+??? val = dev_read_u32_default(dev, "nexell,drive_dly", -1);
+??? if (val < 0) {
+??????? debug("? 'nexell,drive_dly' missing/invalid!\n");
+??????? return -EINVAL;
+??? }
+??? priv->d_delay = val;
+
+??? val = dev_read_u32_default(dev, "nexell,drive_shift", -1);
+??? if (val < 0) {
+??????? debug("? 'nexell,drive_shift' missing/invalid!\n");
+??????? return -EINVAL;
+??? }
+??? priv->d_shift = val;
+
+??? val = dev_read_u32_default(dev, "nexell,sample_dly", -1);
+??? if (val < 0) {
+??????? debug("? 'nexell,sample_dly' missing/invalid!\n");
+??????? return -EINVAL;
+??? }
+??? priv->s_delay = val;
+
+??? val = dev_read_u32_default(dev, "nexell,sample_shift", -1);
+??? if (val < 0) {
+??????? debug("? 'nexell,sample_shift' missing/invalid!\n");
+??????? return -EINVAL;
+??? }
+??? priv->s_shift = val;
+
+??? debug("? index==%d, name==%s, ioaddr==0x%08x, buswidth==%d, "
+????????? "fifo_size==%d, fifo_mode==%d, frequency==%d\n",
+????????? host->dev_index, host->name, (u32)host->ioaddr,
+????????? host->buswidth, priv->fifo_size, priv->fifo_mode,
+????????? priv->frequency);
+??? debug("? min_freq==%d, max_freq==%d, delay: "
+????????? "0x%02x:0x%02x:0x%02x:0x%02x\n",
+????????? priv->min_freq, priv->max_freq, priv->d_delay,
+????????? priv->d_shift, priv->s_delay, priv->s_shift);
+
+??? return 0;
+}
+
+static int nexell_dwmmc_probe(struct udevice *dev)
+{
+??? struct nexell_mmc_plat *plat = dev_get_platdata(dev);
+??? struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
+??? struct nexell_dwmmc_priv *priv = dev_get_priv(dev);
+??? struct dwmci_host *host = &priv->host;
+??? struct udevice *pwr_dev __maybe_unused;
+
+??? debug("%s():\n", __func__);
+
+??? host->fifoth_val = MSIZE(0x2) |
+??????? RX_WMARK(priv->fifo_size / 2 - 1) |
+??????? TX_WMARK(priv->fifo_size / 2);
+
+??? host->fifo_mode = priv->fifo_mode;
+
+??? dwmci_setup_cfg(&plat->cfg, host, priv->max_freq, priv->min_freq);
+??? host->mmc = &plat->mmc;
+??? host->mmc->priv = &priv->host;
+??? host->mmc->dev = dev;
+??? upriv->mmc = host->mmc;
+
+??? nx_dw_mmc_set_pin(host);
+
+??? debug("? nx_dw_mmc_set_clk(host, frequency * 4 == %d)\n",
+????????? priv->frequency * 4);
+??? nx_dw_mmc_set_clk(host, priv->frequency * 4);
+
+??? nx_dw_mmc_reset(host->dev_index);
+??? nx_dw_mmc_clk_delay(dev);
+
+??? return dwmci_probe(dev);
+}
+
+static int nexell_dwmmc_bind(struct udevice *dev)
+{
+??? struct nexell_mmc_plat *plat = dev_get_platdata(dev);
+
+??? return dwmci_bind(dev, &plat->mmc, &plat->cfg);
+}
+
+static const struct udevice_id nexell_dwmmc_ids[] = {
+??? { .compatible = "nexell,nexell-dwmmc" },
+??? { }
+};
+
+U_BOOT_DRIVER(nexell_dwmmc_drv) = {
+??? .name??????? = "nexell_dwmmc",
+??? .id??????? = UCLASS_MMC,
+??? .of_match??? = nexell_dwmmc_ids,
+??? .ofdata_to_platdata = nexell_dwmmc_ofdata_to_platdata,
+??? .ops??????? = &dm_dwmci_ops,
+??? .bind??????? = nexell_dwmmc_bind,
+??? .probe??????? = nexell_dwmmc_probe,
+??? .priv_auto_alloc_size = sizeof(struct nexell_dwmmc_priv),
+??? .platdata_auto_alloc_size = sizeof(struct nexell_mmc_plat),
+};
drivers/pwm/Makefile +0 -0
index a837c35..b45aada 100644
@@ -16,3 +16,4 @@ obj-$(CONFIG_PWM_ROCKCHIP)??? += rk_pwm.o

? obj-$(CONFIG_PWM_SANDBOX)??? += sandbox_pwm.o
? obj-$(CONFIG_PWM_TEGRA)??????? += tegra_pwm.o
? obj-$(CONFIG_PWM_SUNXI)??????? += sunxi_pwm.o

drivers/pwm/Makefile +1 -0
+obj-$(CONFIG_PWM_NX)??????? += pwm-nexell.o
drivers/pwm/pwm-nexell.c new file +252 -0
new file mode 100644
index 0000000..6c0f8f4
@@ -0,0 +1,252 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2011 Samsung Electronics
+ *
+ * Donghwa Lee <[email protected]>
+ */
+
+/* This codes are copied from arch/arm/cpu/armv7/s5p-common/pwm.c */
+
+#include <common.h>
+#include <errno.h>
+#include <pwm.h>
+#include <asm/io.h>
+#include <asm/arch/clk.h>
+#include "pwm-nexell.h"
+
+#if defined(CONFIG_ARCH_NEXELL)
+#include <asm/arch/nexell.h>
+#include <asm/arch/reset.h>
+#include <asm/arch/nx_gpio.h>
+#include <asm/arch/tieoff.h>
+
+struct pwm_device {
+??? int ch;
+??? int grp;
+??? int bit;
+??? int pwm_fn;
+};
+
+static struct pwm_device pwm_dev[] = {
+??? [0] = { .ch = 0, .grp = 3, .bit = 1,? .pwm_fn = 1 },
+??? [1] = { .ch = 1, .grp = 2, .bit = 13, .pwm_fn = 2 },
+??? [2] = { .ch = 2, .grp = 2, .bit = 14, .pwm_fn =??? 2 },
+??? [3] = { .ch = 3, .grp = 3, .bit = 0,? .pwm_fn = 2 },
+};
+#endif
+
+int pwm_enable(int pwm_id)
+{
+??? const struct s5p_timer *pwm =
+#if defined(CONFIG_ARCH_NEXELL)
+??????????? (struct s5p_timer *)PHY_BASEADDR_PWM;
+#else
+??????????? (struct s5p_timer *)samsung_get_base_timer();
+#endif
+??? unsigned long tcon;
+
+??? tcon = readl(&pwm->tcon);
+??? tcon |= TCON_START(pwm_id);
+
+??? writel(tcon, &pwm->tcon);
+
+??? return 0;
+}
+
+void pwm_disable(int pwm_id)
+{
+??? const struct s5p_timer *pwm =
+#if defined(CONFIG_ARCH_NEXELL)
+??????????? (struct s5p_timer *)PHY_BASEADDR_PWM;
+#else
+??????????? (struct s5p_timer *)samsung_get_base_timer();
+#endif
+??? unsigned long tcon;
+
+??? tcon = readl(&pwm->tcon);
+??? tcon &= ~TCON_START(pwm_id);
+
+??? writel(tcon, &pwm->tcon);
+}
+
+static unsigned long pwm_calc_tin(int pwm_id, unsigned long freq)
+{
+??? unsigned long tin_parent_rate;
+??? unsigned int div;
+#if defined(CONFIG_ARCH_NEXELL)
+??? unsigned int pre_div;
+??? const struct s5p_timer *pwm =
+??????? (struct s5p_timer *)PHY_BASEADDR_PWM;
+??? unsigned int val;
+#endif
+
+#if defined(CONFIG_ARCH_NEXELL)
+??? struct clk *clk = clk_get(CORECLK_NAME_PCLK);
+
+??? tin_parent_rate = clk_get_rate(clk);
+#else
+??? tin_parent_rate = get_pwm_clk();
+#endif
+
+#if defined(CONFIG_ARCH_NEXELL)
+??? writel(0, &pwm->tcfg0);
+??? val = readl(&pwm->tcfg0);
+
+??? if (pwm_id < 2)
+??????? div = ((val >> 0) & 0xff) + 1;
+??? else
+??????? div = ((val >> 8) & 0xff) + 1;
+
+??? writel(0, &pwm->tcfg1);
+??? val = readl(&pwm->tcfg1);
+??? val = (val >> MUX_DIV_SHIFT(pwm_id)) & 0xF;
+??? pre_div = (1UL << val);
+
+??? freq = tin_parent_rate / div / pre_div;
+
+??? return freq;
+#else
+??? for (div = 2; div <= 16; div *= 2) {
+??????? if ((tin_parent_rate / (div << 16)) < freq)
+??????????? return tin_parent_rate / div;
+??? }
+
+??? return tin_parent_rate / 16;
+#endif
+}
+
+#define NS_IN_SEC 1000000000UL
+
+int pwm_config(int pwm_id, int duty_ns, int period_ns)
+{
+??? const struct s5p_timer *pwm =
+#if defined(CONFIG_ARCH_NEXELL)
+??????? (struct s5p_timer *)PHY_BASEADDR_PWM;
+#else
+??????? (struct s5p_timer *)samsung_get_base_timer();
+#endif
+??? unsigned int offset;
+??? unsigned long tin_rate;
+??? unsigned long tin_ns;
+??? unsigned long frequency;
+??? unsigned long tcon;
+??? unsigned long tcnt;
+??? unsigned long tcmp;
+
+??? /*
+???? * We currently avoid using 64bit arithmetic by using the
+???? * fact that anything faster than 1GHz is easily representable
+???? * by 32bits.
+???? */
+??? if (period_ns > NS_IN_SEC || duty_ns > NS_IN_SEC || period_ns == 0)
+??????? return -ERANGE;
+
+??? if (duty_ns > period_ns)
+??????? return -EINVAL;
+
+??? frequency = NS_IN_SEC / period_ns;
+
+??? /* Check to see if we are changing the clock rate of the PWM */
+??? tin_rate = pwm_calc_tin(pwm_id, frequency);
+
+??? tin_ns = NS_IN_SEC / tin_rate;
+#if defined(CONFIG_ARCH_NEXELL)
+??? /* The counter starts at zero. */
+??? tcnt = (period_ns / tin_ns) - 1;
+#else
+??? tcnt = period_ns / tin_ns;
+#endif
+
+??? /* Note, counters count down */
+??? tcmp = duty_ns / tin_ns;
+??? tcmp = tcnt - tcmp;
+
+??? /* Update the PWM register block. */
+??? offset = pwm_id * 3;
+??? if (pwm_id < 4) {
+??????? writel(tcnt, &pwm->tcntb0 + offset);
+??????? writel(tcmp, &pwm->tcmpb0 + offset);
+??? }
+
+??? tcon = readl(&pwm->tcon);
+??? tcon |= TCON_UPDATE(pwm_id);
+??? if (pwm_id < 4)
+??????? tcon |= TCON_AUTO_RELOAD(pwm_id);
+??? else
+??????? tcon |= TCON4_AUTO_RELOAD;
+??? writel(tcon, &pwm->tcon);
+
+??? tcon &= ~TCON_UPDATE(pwm_id);
+??? writel(tcon, &pwm->tcon);
+
+??? return 0;
+}
+
+int pwm_init(int pwm_id, int div, int invert)
+{
+??? u32 val;
+??? const struct s5p_timer *pwm =
+#if defined(CONFIG_ARCH_NEXELL)
+??????????? (struct s5p_timer *)PHY_BASEADDR_PWM;
+#else
+??????????? (struct s5p_timer *)samsung_get_base_timer();
+#endif
+??? unsigned long ticks_per_period;
+??? unsigned int offset, prescaler;
+
+??? /*
+???? * Timer Freq(HZ) =
+???? *??? PWM_CLK / { (prescaler_value + 1) * (divider_value) }
+???? */
+
+??? val = readl(&pwm->tcfg0);
+??? if (pwm_id < 2) {
+??????? prescaler = PRESCALER_0;
+??????? val &= ~0xff;
+??????? val |= (prescaler & 0xff);
+??? } else {
+??????? prescaler = PRESCALER_1;
+??????? val &= ~(0xff << 8);
+??????? val |= (prescaler & 0xff) << 8;
+??? }
+??? writel(val, &pwm->tcfg0);
+??? val = readl(&pwm->tcfg1);
+??? val &= ~(0xf << MUX_DIV_SHIFT(pwm_id));
+??? val |= (div & 0xf) << MUX_DIV_SHIFT(pwm_id);
+??? writel(val, &pwm->tcfg1);
+
+??? if (pwm_id == 4) {
+??????? /*
+???????? * TODO(sjg): Use this as a countdown timer for now. We count
+???????? * down from the maximum value to 0, then reset.
+???????? */
+??????? ticks_per_period = -1UL;
+??? } else {
+??????? const unsigned long pwm_hz = 1000;
+#if defined(CONFIG_ARCH_NEXELL)
+??????? struct clk *clk = clk_get(CORECLK_NAME_PCLK);
+??????? unsigned long timer_rate_hz = clk_get_rate(clk) /
+#else
+??????? unsigned long timer_rate_hz = get_pwm_clk() /
+#endif
+??????????? ((prescaler + 1) * (1 << div));
+
+??????? ticks_per_period = timer_rate_hz / pwm_hz;
+??? }
+
+??? /* set count value */
+??? offset = pwm_id * 3;
+
+??? writel(ticks_per_period, &pwm->tcntb0 + offset);
+
+??? val = readl(&pwm->tcon) & ~(0xf << TCON_OFFSET(pwm_id));
+??? if (invert && pwm_id < 4)
+??????? val |= TCON_INVERTER(pwm_id);
+??? writel(val, &pwm->tcon);
+
+??? nx_gpio_set_pad_function(pwm_dev[pwm_id].grp, pwm_dev[pwm_id].bit,
+???????????????? pwm_dev[pwm_id].pwm_fn);
+??? pwm_enable(pwm_id);
+
+??? return 0;
+}
drivers/pwm/pwm-nexell.h new file +48 -0
new file mode 100644
index 0000000..92dc707
@@ -0,0 +1,54 @@
+/* SPDX-License-Identifier: GPL-2.0+
+ *
+ * Copyright (C) 2009 Samsung Electronics
+ * Kyungmin Park <[email protected]>
+ * Minkyu Kang <[email protected]>
+ */
+
+#ifndef __ASM_ARM_ARCH_PWM_H_
+#define __ASM_ARM_ARCH_PWM_H_
+
+#define PRESCALER_0??????? (8 - 1)??????? /* prescaler of timer 0, 1 */
+#define PRESCALER_1??????? (16 - 1)??? /* prescaler of timer 2, 3, 4 */
+
+/* Divider MUX */
+#define MUX_DIV_1??????? 0??????? /* 1/1 period */
+#define MUX_DIV_2??????? 1??????? /* 1/2 period */
+#define MUX_DIV_4??????? 2??????? /* 1/4 period */
+#define MUX_DIV_8??????? 3??????? /* 1/8 period */
+#define MUX_DIV_16??????? 4??????? /* 1/16 period */
+
+#define MUX_DIV_SHIFT(x)??? ((x) * 4)
+
+#define TCON_OFFSET(x)??????? (((x) + 1) * (!!x) << 2)
+
+#define TCON_START(x)??????? (1 << TCON_OFFSET(x))
+#define TCON_UPDATE(x)??????? (1 << (TCON_OFFSET(x) + 1))
+#define TCON_INVERTER(x)??? (1 << (TCON_OFFSET(x) + 2))
+#define TCON_AUTO_RELOAD(x)??? (1 << (TCON_OFFSET(x) + 3))
+#define TCON4_AUTO_RELOAD??? (1 << 22)
+
+#ifndef __ASSEMBLY__
+struct s5p_timer {
+??? unsigned int??? tcfg0;
+??? unsigned int??? tcfg1;
+??? unsigned int??? tcon;
+??? unsigned int??? tcntb0;
+??? unsigned int??? tcmpb0;
+??? unsigned int??? tcnto0;
+??? unsigned int??? tcntb1;
+??? unsigned int??? tcmpb1;
+??? unsigned int??? tcnto1;
+??? unsigned int??? tcntb2;
+??? unsigned int??? tcmpb2;
+??? unsigned int??? tcnto2;
+??? unsigned int??? tcntb3;
+??? unsigned int??? res1;
+??? unsigned int??? tcnto3;
+??? unsigned int??? tcntb4;
Quoted 9 lines
Quoted 8 lines

drivers/pwm/pwm-nexell.h line 54

Quoted 7 lines
drivers/pwm/pwm-nexell.h new file +6 -0
+??? unsigned int??? tcnto4;
+??? unsigned int??? tintcstat;
+};
+#endif??? /* __ASSEMBLY__ */
+
+#endif

bye,
Heiko

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: hs at denx.de
#8 lore raw

RFC PATCH 4/10 video: add nexell video driver (soc: displaytop)

In reply to Stefan Bosch

Low level functions for DisplayTop (Display Topology).

---

 drivers/video/nexell/soc/s5pxx18_soc_disptop.c     | 185 ++++++++++
 drivers/video/nexell/soc/s5pxx18_soc_disptop.h     | 385 +++++++++++++++++++++
 drivers/video/nexell/soc/s5pxx18_soc_disptop_clk.c | 309 +++++++++++++++++
 drivers/video/nexell/soc/s5pxx18_soc_disptop_clk.h |  59 ++++
 drivers/video/nexell/soc/s5pxx18_soc_disptype.h    |  23 ++
 5 files changed, 961 insertions(+)
 create mode 100644 drivers/video/nexell/soc/s5pxx18_soc_disptop.c
 create mode 100644 drivers/video/nexell/soc/s5pxx18_soc_disptop.h
 create mode 100644 drivers/video/nexell/soc/s5pxx18_soc_disptop_clk.c
 create mode 100644 drivers/video/nexell/soc/s5pxx18_soc_disptop_clk.h
 create mode 100644 drivers/video/nexell/soc/s5pxx18_soc_disptype.h
drivers/video/nexell/soc/s5pxx18_soc_disptop.c new file +185 -0
new file mode 100644
index 0000000..626e53a
@@ -0,0 +1,185 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2016  Nexell Co., Ltd.
+ *
+ * Author: junghyun, kim <[email protected]>
+ */
+
+#include <linux/types.h>
+#include <linux/io.h>
+
+#include "s5pxx18_soc_disptop.h"
+
+static struct {
+	struct nx_disp_top_register_set *pregister;
+} __g_module_variables = { NULL, };
+
+int nx_disp_top_initialize(void)
+{
+	static int binit;
+	u32 i;
+
+	if (binit == 0) {
+		for (i = 0; i < NUMBER_OF_DISPTOP_MODULE; i++)
+			__g_module_variables.pregister = NULL;
+		binit = 1;
+	}
+	return 1;
+}
+
+u32 nx_disp_top_get_number_of_module(void)
+{
+	return NUMBER_OF_DISPTOP_MODULE;
+}
+
+u32 nx_disp_top_get_physical_address(void)
+{
+	static const u32 physical_addr[] = PHY_BASEADDR_DISPTOP_LIST;
+
+	return (u32)(physical_addr[0] + PHY_BASEADDR_DISPLAYTOP_MODULE_OFFSET);
+}
+
+u32 nx_disp_top_get_size_of_register_set(void)
+{
+	return sizeof(struct nx_disp_top_register_set);
+}
+
+void nx_disp_top_set_base_address(void *base_address)
+{
+	__g_module_variables.pregister =
+	    (struct nx_disp_top_register_set *)base_address;
+}
+
+void *nx_disp_top_get_base_address(void)
+{
+	return (void *)__g_module_variables.pregister;
+}
+
+void nx_disp_top_set_resconvmux(int benb, u32 sel)
+{
+	register struct nx_disp_top_register_set *pregister;
+	u32 regvalue;
+
+	pregister = __g_module_variables.pregister;
+	regvalue = (benb << 31) | (sel << 0);
+	writel((u32)regvalue, &pregister->resconv_mux_ctrl);
+}
+
+void nx_disp_top_set_hdmimux(int benb, u32 sel)
+{
+	register struct nx_disp_top_register_set *pregister;
+	u32 regvalue;
+
+	pregister = __g_module_variables.pregister;
+	regvalue = (benb << 31) | (sel << 0);
+	writel((u32)regvalue, &pregister->interconv_mux_ctrl);
+}
+
+void nx_disp_top_set_mipimux(int benb, u32 sel)
+{
+	register struct nx_disp_top_register_set *pregister;
+	u32 regvalue;
+
+	pregister = __g_module_variables.pregister;
+	regvalue = (benb << 31) | (sel << 0);
+	writel((u32)regvalue, &pregister->mipi_mux_ctrl);
+}
+
+void nx_disp_top_set_lvdsmux(int benb, u32 sel)
+{
+	register struct nx_disp_top_register_set *pregister;
+	u32 regvalue;
+
+	pregister = __g_module_variables.pregister;
+	regvalue = (benb << 31) | (sel << 0);
+	writel((u32)regvalue, &pregister->lvds_mux_ctrl);
+}
+
+void nx_disp_top_set_primary_mux(u32 sel)
+{
+	register struct nx_disp_top_register_set *pregister;
+
+	pregister = __g_module_variables.pregister;
+	writel((u32)sel, &pregister->tftmpu_mux);
+}
+
+void nx_disp_top_hdmi_set_vsync_start(u32 sel)
+{
+	register struct nx_disp_top_register_set *pregister;
+
+	pregister = __g_module_variables.pregister;
+	writel((u32)sel, &pregister->hdmisyncctrl0);
+}
+
+void nx_disp_top_hdmi_set_vsync_hsstart_end(u32 start, u32 end)
+{
+	register struct nx_disp_top_register_set *pregister;
+
+	pregister = __g_module_variables.pregister;
+	writel((u32)(end << 16) | (start << 0), &pregister->hdmisyncctrl3);
+}
+
+void nx_disp_top_hdmi_set_hactive_start(u32 sel)
+{
+	register struct nx_disp_top_register_set *pregister;
+
+	pregister = __g_module_variables.pregister;
+	writel((u32)sel, &pregister->hdmisyncctrl1);
+}
+
+void nx_disp_top_hdmi_set_hactive_end(u32 sel)
+{
+	register struct nx_disp_top_register_set *pregister;
+
+	pregister = __g_module_variables.pregister;
+	writel((u32)sel, &pregister->hdmisyncctrl2);
+}
+
+void nx_disp_top_set_hdmifield(u32 enable, u32 init_val, u32 vsynctoggle,
+			       u32 hsynctoggle, u32 vsyncclr, u32 hsyncclr,
+			       u32 field_use, u32 muxsel)
+{
+	register struct nx_disp_top_register_set *pregister;
+	u32 regvalue;
+
+	pregister = __g_module_variables.pregister;
+	regvalue = ((enable & 0x01) << 0) | ((init_val & 0x01) << 1) |
+		   ((vsynctoggle & 0x3fff) << 2) |
+		   ((hsynctoggle & 0x3fff) << 17);
+	writel(regvalue, &pregister->hdmifieldctrl);
+	regvalue = ((field_use & 0x01) << 31) | ((muxsel & 0x01) << 30) |
+		   ((hsyncclr) << 15) | ((vsyncclr) << 0);
+	writel(regvalue, &pregister->greg0);
+}
+
+void nx_disp_top_set_padclock(u32 mux_index, u32 padclk_cfg)
+{
+	register struct nx_disp_top_register_set *pregister;
+	u32 regvalue;
+
+	pregister = __g_module_variables.pregister;
+	regvalue = readl(&pregister->greg1);
+	if (padmux_secondary_mlc == mux_index) {
+		regvalue = regvalue & (~(0x7 << 3));
+		regvalue = regvalue | (padclk_cfg << 3);
+	} else if (padmux_resolution_conv == mux_index) {
+		regvalue = regvalue & (~(0x7 << 6));
+		regvalue = regvalue | (padclk_cfg << 6);
+	} else {
+		regvalue = regvalue & (~(0x7 << 0));
+		regvalue = regvalue | (padclk_cfg << 0);
+	}
+	writel(regvalue, &pregister->greg1);
+}
+
+void nx_disp_top_set_lcdif_enb(int enb)
+{
+	register struct nx_disp_top_register_set *pregister;
+	u32 regvalue;
+
+	pregister = __g_module_variables.pregister;
+	regvalue = readl(&pregister->greg1);
+	regvalue = regvalue & (~(0x1 << 9));
+	regvalue = regvalue | ((enb & 0x1) << 9);
+	writel(regvalue, &pregister->greg1);
+}
drivers/video/nexell/soc/s5pxx18_soc_disptop.h new file +385 -0

385 lines not on this page · raw message

drivers/video/nexell/soc/s5pxx18_soc_disptop_clk.c new file +309 -0

309 lines not on this page · raw message

drivers/video/nexell/soc/s5pxx18_soc_disptop_clk.h new file +59 -0

59 lines not on this page · raw message

drivers/video/nexell/soc/s5pxx18_soc_disptype.h new file +23 -0
new file mode 100644
index 0000000..b5df7a7
@@ -0,0 +1,23 @@
+/* SPDX-License-Identifier: GPL-2.0+
+ *
+ * Copyright (C) 2016  Nexell Co., Ltd.
+ *
+ * Author: junghyun, kim <[email protected]>
+ */
+
+#ifndef _S5PXX18_SOC_DISP_TYPE_H_
+#define _S5PXX18_SOC_DISP_TYPE_H_
+
+/* clock control types */
+enum nx_pclkmode {
+	nx_pclkmode_dynamic = 0UL,
+	nx_pclkmode_always	= 1UL
+};
+
+enum nx_bclkmode {
+	nx_bclkmode_disable	= 0UL,
+	nx_bclkmode_dynamic	= 2UL,
+	nx_bclkmode_always	= 3UL
+};
+
+#endif
Signature · 1 line
1.9.1
#9 lore raw

RFC PATCH 5/10 video: add nexell video driver (soc: mlc, mipi)

In reply to Stefan Bosch

Low level functions for MLC (Multi Layer Control) and MIPI (Mobile Industry Processor Interface).

---

 drivers/video/nexell/soc/s5pxx18_soc_mipi.c |  580 +++++++++
 drivers/video/nexell/soc/s5pxx18_soc_mipi.h |  291 +++++
 drivers/video/nexell/soc/s5pxx18_soc_mlc.c  | 1861 +++++++++++++++++++++++++++
 drivers/video/nexell/soc/s5pxx18_soc_mlc.h  |  429 ++++++
 4 files changed, 3161 insertions(+)
 create mode 100644 drivers/video/nexell/soc/s5pxx18_soc_mipi.c
 create mode 100644 drivers/video/nexell/soc/s5pxx18_soc_mipi.h
 create mode 100644 drivers/video/nexell/soc/s5pxx18_soc_mlc.c
 create mode 100644 drivers/video/nexell/soc/s5pxx18_soc_mlc.h
drivers/video/nexell/soc/s5pxx18_soc_mipi.c new file +580 -0
new file mode 100644
index 0000000..1000ddb
@@ -0,0 +1,580 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2016  Nexell Co., Ltd.
+ *
+ * Author: junghyun, kim <[email protected]>
+ */
+
+#include <linux/types.h>
+#include <linux/io.h>
+
+#include "s5pxx18_soc_disptop.h"
+#include "s5pxx18_soc_mipi.h"
+
+static struct nx_mipi_register_set *__g_pregister[NUMBER_OF_MIPI_MODULE];
+
+int nx_mipi_smoke_test(u32 module_index)
+{
+	register struct nx_mipi_register_set *pregister;
+
+	pregister = __g_pregister[module_index];
+
+	if (pregister->csis_config_ch0 != 0x000000FC)
+		return false;
+
+	if (pregister->dsim_intmsk != 0xB337FFFF)
+		return false;
+
+	writel(0xDEADC0DE, &pregister->csis_dphyctrl);
+	writel(0xFFFFFFFF, &pregister->csis_ctrl2);
+	writel(0xDEADC0DE, &pregister->dsim_msync);
+
+	if (pregister->csis_dphyctrl != 0xDE80001E)
+		return false;
+
+	if ((pregister->csis_ctrl2 & (~1)) != 0xEEE00010)
+		return false;
+
+	if (pregister->dsim_msync != 0xDE80C0DE)
+		return false;
+
+	return true;
+}
+
+void nx_mipi_set_base_address(u32 module_index, void *base_address)
+{
+	__g_pregister[module_index] =
+	    (struct nx_mipi_register_set *)base_address;
+}
+
+void *nx_mipi_get_base_address(u32 module_index)
+{
+	return (void *)__g_pregister[module_index];
+}
+
+u32 nx_mipi_get_physical_address(u32 module_index)
+{
+	const u32 physical_addr[] = PHY_BASEADDR_MIPI_LIST;
+
+	return physical_addr[module_index];
+}
+
+#define __nx_mipi_valid_dsi_intmask__	\
+	(~((1 << 26) | (1 << 23) | (1 << 22) | (1 << 19)))
+
+void nx_mipi_set_interrupt_enable(u32 module_index, u32 int_num, int enable)
+{
+	register struct nx_mipi_register_set *pregister;
+	register u32 regvalue;
+
+	pregister = __g_pregister[module_index];
+	if (int_num < 32) {
+		regvalue = pregister->csis_intmsk;
+		regvalue &= ~(1ul << int_num);
+		regvalue |= (u32)enable << int_num;
+		writel(regvalue, &pregister->csis_intmsk);
+	} else {
+		regvalue = pregister->dsim_intmsk;
+		regvalue &= ~(1ul << (int_num - 32));
+		regvalue |= (u32)enable << (int_num - 32);
+		writel(regvalue, &pregister->dsim_intmsk);
+	}
+}
+
+int nx_mipi_get_interrupt_enable(u32 module_index, u32 int_num)
+{
+	if (int_num < 32)
+		return (int)((__g_pregister[module_index]->csis_intmsk >>
+			      int_num) & 0x01);
+	else
+		return (int)((__g_pregister[module_index]->dsim_intmsk >>
+			      (int_num - 32)) & 0x01);
+}
+
+int nx_mipi_get_interrupt_pending(u32 module_index, u32 int_num)
+{
+	register struct nx_mipi_register_set *pregister;
+	register u32 regvalue;
+	int ret;
+
+	pregister = __g_pregister[module_index];
+	if (int_num < 32) {
+		regvalue = pregister->csis_intmsk;
+		regvalue &= pregister->csis_intsrc;
+		ret = (int)((regvalue >> int_num) & 0x01);
+	} else {
+		regvalue = pregister->dsim_intmsk;
+		regvalue &= pregister->dsim_intsrc;
+		ret = (int)((regvalue >> (int_num - 32)) & 0x01);
+	}
+
+	return ret;
+}
+
+void nx_mipi_clear_interrupt_pending(u32 module_index, u32 int_num)
+{
+	register struct nx_mipi_register_set *pregister;
+
+	pregister = __g_pregister[module_index];
+	if (int_num < 32)
+		writel(1ul << int_num, &pregister->csis_intsrc);
+	else
+		writel(1ul << (int_num - 32), &pregister->dsim_intsrc);
+}
+
+void nx_mipi_set_interrupt_enable_all(u32 module_index, int enable)
+{
+	register struct nx_mipi_register_set *pregister;
+
+	pregister = __g_pregister[module_index];
+	if (enable)
+		writel(__nx_mipi_valid_dsi_intmask__, &pregister->dsim_intmsk);
+	else
+		writel(0, &pregister->dsim_intmsk);
+}
+
+int nx_mipi_get_interrupt_enable_all(u32 module_index)
+{
+	if (__g_pregister[module_index]->csis_intmsk)
+		return true;
+
+	if (__g_pregister[module_index]->dsim_intmsk)
+		return true;
+
+	return false;
+}
+
+int nx_mipi_get_interrupt_pending_all(u32 module_index)
+{
+	register struct nx_mipi_register_set *pregister;
+	register u32 regvalue;
+
+	pregister = __g_pregister[module_index];
+	regvalue = pregister->csis_intmsk;
+	regvalue &= pregister->csis_intsrc;
+
+	if (regvalue)
+		return true;
+
+	regvalue = pregister->dsim_intmsk;
+	regvalue &= pregister->dsim_intsrc;
+
+	if (regvalue)
+		return true;
+
+	return false;
+}
+
+void nx_mipi_clear_interrupt_pending_all(u32 module_index)
+{
+	register struct nx_mipi_register_set *pregister;
+
+	pregister = __g_pregister[module_index];
+	writel(__nx_mipi_valid_dsi_intmask__, &pregister->dsim_intsrc);
+}
+
+int32_t nx_mipi_get_interrupt_pending_number(u32 module_index)
+{
+	register struct nx_mipi_register_set *pregister;
+	register u32 regvalue;
+	int i;
+
+	pregister = __g_pregister[module_index];
+	regvalue = pregister->csis_intmsk;
+	regvalue &= pregister->csis_intsrc;
+	if (regvalue != 0) {
+		for (i = 0; i < 32; i++) {
+			if (regvalue & 1ul)
+				return i;
+			regvalue >>= 1;
+		}
+	}
+
+	regvalue = pregister->dsim_intmsk;
+	regvalue &= pregister->dsim_intsrc;
+	if (regvalue != 0) {
+		for (i = 0; i < 32; i++) {
+			if (regvalue & 1ul)
+				return i + 32;
+			regvalue >>= 1;
+		}
+	}
+	return -1;
+}
+
+#define writereg(regname, mask, value) \
+	regvalue = pregister->(regname);	\
+	regvalue = (regvalue & (~(mask))) | (value); \
+	writel(regvalue, &pregister->(regname))
+
+void nx_mipi_dsi_get_status(u32 module_index, u32 *pulps, u32 *pstop,
+			    u32 *pispllstable, u32 *pisinreset,
+			    u32 *pisbackward, u32 *pishsclockready)
+{
+	register struct nx_mipi_register_set *pregister;
+	register u32 regvalue;
+
+	pregister = __g_pregister[module_index];
+	regvalue = pregister->dsim_status;
+	if (pulps) {
+		*pulps = 0;
+		if (regvalue & (1 << 4))
+			*pulps |= (1 << 0);
+		if (regvalue & (1 << 5))
+			*pulps |= (1 << 1);
+		if (regvalue & (1 << 6))
+			*pulps |= (1 << 2);
+		if (regvalue & (1 << 7))
+			*pulps |= (1 << 3);
+		if (regvalue & (1 << 9))
+			*pulps |= (1 << 4);
+	}
+
+	if (pstop) {
+		*pstop = 0;
+		if (regvalue & (1 << 0))
+			*pstop |= (1 << 0);
+		if (regvalue & (1 << 1))
+			*pstop |= (1 << 1);
+		if (regvalue & (1 << 2))
+			*pstop |= (1 << 2);
+		if (regvalue & (1 << 3))
+			*pstop |= (1 << 3);
+		if (regvalue & (1 << 8))
+			*pstop |= (1 << 4);
+	}
+
+	if (pispllstable)
+		*pispllstable = (regvalue >> 31) & 1;
+
+	if (pisinreset)
+		*pisinreset = ((regvalue >> 20) & 1) ? 0 : 1;
+
+	if (pisbackward)
+		*pisbackward = (regvalue >> 16) & 1;
+
+	if (pishsclockready)
+		*pishsclockready = (regvalue >> 10) & 1;
+}
+
+void nx_mipi_dsi_software_reset(u32 module_index)
+{
+	register struct nx_mipi_register_set *pregister;
+
+	pregister = __g_pregister[module_index];
+
+	writel(0x00010001, &pregister->dsim_swrst);
+
+	while (0 != (readl(&pregister->dsim_status) & (1 << 20)))
+		;
+
+	writel(0x00000000, &pregister->dsim_swrst);
+}
+
+void nx_mipi_dsi_set_clock(u32 module_index, int enable_txhsclock,
+			   int use_external_clock, int enable_byte_clock,
+			   int enable_escclock_clock_lane,
+			   int enable_escclock_data_lane0,
+			   int enable_escclock_data_lane1,
+			   int enable_escclock_data_lane2,
+			   int enable_escclock_data_lane3,
+			   int enable_escprescaler, u32 escprescalervalue)
+{
+	register struct nx_mipi_register_set *pregister;
+	register u32 regvalue;
+
+	pregister = __g_pregister[module_index];
+	regvalue = 0;
+	regvalue |= (enable_txhsclock << 31);
+	regvalue |= (use_external_clock << 27);
+	regvalue |= (enable_byte_clock << 24);
+	regvalue |= (enable_escclock_clock_lane << 19);
+	regvalue |= (enable_escclock_data_lane0 << 20);
+	regvalue |= (enable_escclock_data_lane1 << 21);
+	regvalue |= (enable_escclock_data_lane2 << 22);
+	regvalue |= (enable_escclock_data_lane3 << 23);
+	regvalue |= (enable_escprescaler << 28);
+	regvalue |= escprescalervalue;
+
+	writel(regvalue, &pregister->dsim_clkctrl);
+}
+
+void nx_mipi_dsi_set_timeout(u32 module_index, u32 bta_tout, u32 lpdrtout)
+{
+	register struct nx_mipi_register_set *pregister;
+	register u32 regvalue;
+
+	pregister = __g_pregister[module_index];
+	regvalue = 0;
+	regvalue |= (bta_tout << 16);
+	regvalue |= (lpdrtout << 0);
+
+	writel(regvalue, &pregister->dsim_timeout);
+}
+
+void nx_mipi_dsi_set_config_video_mode(u32 module_index,
+				       int enable_auto_flush_main_display_fifo,
+				       int enable_auto_vertical_count,
+				       int enable_burst,
+				       enum nx_mipi_dsi_syncmode sync_mode,
+				       int enable_eo_tpacket,
+				       int enable_hsync_end_packet,
+				       int enable_hfp, int enable_hbp,
+				       int enable_hsa,
+				       u32 number_of_virtual_channel,
+				       enum nx_mipi_dsi_format format,
+				       u32 number_of_words_in_hfp,
+				       u32 number_of_words_in_hbp,
+				       u32 number_of_words_in_hsync,
+				       u32 number_of_lines_in_vfp,
+				       u32 number_of_lines_in_vbp,
+				       u32 number_of_lines_in_vsync,
+				       u32 number_of_lines_in_command_allow)
+{
+	register struct nx_mipi_register_set *pregister;
+	register u32 regvalue;
+	u32 newvalue;
+
+	pregister = __g_pregister[module_index];
+	newvalue = (1 << 25);
+	newvalue |= ((1 - enable_auto_flush_main_display_fifo) << 29);
+	newvalue |= (enable_auto_vertical_count << 24);
+	newvalue |= (enable_burst << 26);
+	newvalue |= (sync_mode << 27);
+	newvalue |= ((1 - enable_eo_tpacket) << 28);
+	newvalue |= (enable_hsync_end_packet << 23);
+	newvalue |= ((1 - enable_hfp) << 22);
+	newvalue |= ((1 - enable_hbp) << 21);
+	newvalue |= ((1 - enable_hsa) << 20);
+	newvalue |= (number_of_virtual_channel << 18);
+	newvalue |= (format << 12);
+
+	writereg(dsim_config, 0xFFFFFF00, newvalue);
+
+	newvalue = (number_of_lines_in_command_allow << 28);
+	newvalue |= (number_of_lines_in_vfp << 16);
+	newvalue |= (number_of_lines_in_vbp << 0);
+
+	writel(newvalue, &pregister->dsim_mvporch);
+
+	newvalue = (number_of_words_in_hfp << 16);
+	newvalue |= (number_of_words_in_hbp << 0);
+
+	writel(newvalue, &pregister->dsim_mhporch);
+
+	newvalue = (number_of_words_in_hsync << 0);
+	newvalue |= (number_of_lines_in_vsync << 22);
+
+	writel(newvalue, &pregister->dsim_msync);
+}
+
+void nx_mipi_dsi_set_config_command_mode(u32 module_index,
+					 int
+					 enable_auto_flush_main_display_fifo,
+					 int enable_eo_tpacket,
+					 u32 number_of_virtual_channel,
+					 enum nx_mipi_dsi_format format)
+{
+	register struct nx_mipi_register_set *pregister;
+	register u32 regvalue;
+	u32 newvalue;
+
+	pregister = __g_pregister[module_index];
+	newvalue = (0 << 25);
+	newvalue |= (enable_auto_flush_main_display_fifo << 29);
+	newvalue |= (enable_eo_tpacket << 28);
+	newvalue |= (number_of_virtual_channel << 18);
+	newvalue |= (format << 12);
+	writereg(dsim_config, 0xFFFFFF00, newvalue);
+}
+
+void nx_mipi_dsi_set_escape_mode(u32 module_index, u32 stop_state_count,
+				 int force_stop_state, int force_bta,
+				 enum nx_mipi_dsi_lpmode cmdin_lp,
+				 enum nx_mipi_dsi_lpmode txinlp)
+{
+	register struct nx_mipi_register_set *pregister;
+	register u32 regvalue;
+	u32 newvalue;
+
+	pregister = __g_pregister[module_index];
+	newvalue = (stop_state_count << 21);
+	newvalue |= (force_stop_state << 20);
+	newvalue |= (force_bta << 16);
+	newvalue |= (cmdin_lp << 7);
+	newvalue |= (txinlp << 6);
+	writereg(dsim_escmode, 0xFFFFFFC0, newvalue);
+}
+
+void nx_mipi_dsi_set_escape_lp(u32 module_index,
+			       enum nx_mipi_dsi_lpmode cmdin_lp,
+			       enum nx_mipi_dsi_lpmode txinlp)
+{
+	register struct nx_mipi_register_set *pregister;
+	register u32 regvalue;
+	u32 newvalue = 0;
+
+	pregister = __g_pregister[module_index];
+	newvalue |= (cmdin_lp << 7);
+	newvalue |= (txinlp << 6);
+	writereg(dsim_escmode, 0xC0, newvalue);
+}
+
+void nx_mipi_dsi_remote_reset_trigger(u32 module_index)
+{
+	register struct nx_mipi_register_set *pregister;
+	register u32 regvalue;
+	u32 newvalue;
+
+	pregister = __g_pregister[module_index];
+	newvalue = (1 << 4);
+	writereg(dsim_escmode, (1 << 4), newvalue);
+
+	while (readl(&pregister->dsim_escmode) & (1 << 4))
+		;
+}
+
+void nx_mipi_dsi_set_ulps(u32 module_index, int ulpsclocklane, int ulpsdatalane)
+{
+	register struct nx_mipi_register_set *pregister;
+	register u32 regvalue;
+
+	pregister = __g_pregister[module_index];
+	regvalue = pregister->dsim_escmode;
+
+	if (ulpsclocklane) {
+		regvalue &= ~(1 << 0);
+		regvalue |= (1 << 1);
+	} else {
+		regvalue |= (1 << 0);
+	}
+
+	if (ulpsdatalane) {
+		regvalue &= ~(1 << 2);
+		regvalue |= (1 << 3);
+	} else {
+		regvalue |= (1 << 2);
+	}
+
+	writel(regvalue, &pregister->dsim_escmode);
+
+	if (ulpsclocklane)
+		while ((1 << 9) ==
+		       (readl(&pregister->dsim_status) & (1 << 9)))
+			;
+	else
+		while (0 != (readl(&pregister->dsim_status) & (1 << 9)))
+			;
+
+	if (ulpsdatalane)
+		while ((15 << 4) ==
+		       (readl(&pregister->dsim_status) & (15 << 4)))
+			;
+	else
+		while (0 != (readl(&pregister->dsim_status) & (15 << 4)))
+			;
+
+	if (!ulpsclocklane)
+		regvalue &= (3 << 0);
+
+	if (!ulpsdatalane)
+		regvalue |= (3 << 2);
+
+	writel(regvalue, &pregister->dsim_escmode);
+}
+
+void nx_mipi_dsi_set_size(u32 module_index, u32 width, u32 height)
+{
+	register struct nx_mipi_register_set *pregister;
+	register u32 regvalue;
+	u32 newvalue;
+
+	pregister = __g_pregister[module_index];
+	newvalue = (height << 16);
+	newvalue |= (width << 0);
+	writereg(dsim_mdresol, 0x0FFFFFFF, newvalue);
+}
+
+void nx_mipi_dsi_set_enable(u32 module_index, int enable)
+{
+	register struct nx_mipi_register_set *pregister;
+	register u32 regvalue;
+
+	pregister = __g_pregister[module_index];
+	writereg(dsim_mdresol, (1 << 31), (enable << 31));
+}
+
+void nx_mipi_dsi_set_phy(u32 module_index, u32 number_of_data_lanes,
+			 int enable_clock_lane, int enable_data_lane0,
+			 int enable_data_lane1, int enable_data_lane2,
+			 int enable_data_lane3, int swap_clock_lane,
+			 int swap_data_lane)
+{
+	register struct nx_mipi_register_set *pregister;
+	register u32 regvalue;
+	u32 newvalue;
+
+	pregister = __g_pregister[module_index];
+	newvalue = (number_of_data_lanes << 5);
+	newvalue |= (enable_clock_lane << 0);
+	newvalue |= (enable_data_lane0 << 1);
+	newvalue |= (enable_data_lane1 << 2);
+	newvalue |= (enable_data_lane2 << 3);
+	newvalue |= (enable_data_lane3 << 4);
+	writereg(dsim_config, 0xFF, newvalue);
+	newvalue = (swap_clock_lane << 1);
+	newvalue |= (swap_data_lane << 0);
+	writereg(dsim_phyacchr1, 0x3, newvalue);
+}
+
+void nx_mipi_dsi_set_pll(u32 module_index, int enable, u32 pllstabletimer,
+			 u32 m_pllpms, u32 m_bandctl, u32 m_dphyctl,
+			 u32 b_dphyctl)
+{
+	register struct nx_mipi_register_set *pregister;
+	register u32 regvalue;
+	u32 newvalue;
+
+	pregister = __g_pregister[module_index];
+	if (!enable) {
+		newvalue = (enable << 23);
+		newvalue |= (m_pllpms << 1);
+		newvalue |= (m_bandctl << 24);
+		writereg(dsim_pllctrl, 0x0FFFFFFF, newvalue);
+	}
+
+	writel(m_dphyctl, &pregister->dsim_phyacchr);
+	writel(pllstabletimer, &pregister->dsim_plltmr);
+	writel((b_dphyctl << 9), &pregister->dsim_phyacchr1);
+
+	if (enable) {
+		newvalue = (enable << 23);
+		newvalue |= (m_pllpms << 1);
+		newvalue |= (m_bandctl << 24);
+		writereg(dsim_pllctrl, 0x0FFFFFFF, newvalue);
+	}
+}
+
+void nx_mipi_dsi_write_pkheader(u32 module_index, u32 data)
+{
+	register struct nx_mipi_register_set *pregister;
+
+	pregister = __g_pregister[module_index];
+	writel(data, &pregister->dsim_pkthdr);
+}
+
+void nx_mipi_dsi_write_payload(u32 module_index, u32 data)
+{
+	register struct nx_mipi_register_set *pregister;
+
+	pregister = __g_pregister[module_index];
+	writel(data, &pregister->dsim_payload);
+}
+
+u32 nx_mipi_dsi_read_fifo_status(u32 module_index)
+{
+	register struct nx_mipi_register_set *pregister;
+
+	pregister = __g_pregister[module_index];
+	return readl(&pregister->dsim_fifoctrl);
+}
drivers/video/nexell/soc/s5pxx18_soc_mipi.h new file +291 -0

291 lines not on this page · raw message

drivers/video/nexell/soc/s5pxx18_soc_mlc.c new file +1861 -0

1,861 lines not on this page · raw message

drivers/video/nexell/soc/s5pxx18_soc_mlc.h new file +429 -0

268 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
1.9.1

Part of the diff is not shown here. View the raw message.

#10 lore raw

RFC PATCH 6/10 video: add nexell video driver (soc: lvds, hdmi)

In reply to Stefan Bosch

Low level functions for LVDS and HDMI display interfaces.

---

 drivers/video/nexell/soc/s5pxx18_soc_hdmi.c |  50 +++
 drivers/video/nexell/soc/s5pxx18_soc_hdmi.h | 488 ++++++++++++++++++++++++++++
 drivers/video/nexell/soc/s5pxx18_soc_lvds.c | 278 ++++++++++++++++
 drivers/video/nexell/soc/s5pxx18_soc_lvds.h |  83 +++++
 4 files changed, 899 insertions(+)
 create mode 100644 drivers/video/nexell/soc/s5pxx18_soc_hdmi.c
 create mode 100644 drivers/video/nexell/soc/s5pxx18_soc_hdmi.h
 create mode 100644 drivers/video/nexell/soc/s5pxx18_soc_lvds.c
 create mode 100644 drivers/video/nexell/soc/s5pxx18_soc_lvds.h
drivers/video/nexell/soc/s5pxx18_soc_hdmi.c new file +50 -0
new file mode 100644
index 0000000..7b8be7e
@@ -0,0 +1,50 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2016  Nexell Co., Ltd.
+ *
+ * Author: junghyun, kim <[email protected]>
+ */
+
+#include <linux/types.h>
+#include <linux/io.h>
+
+#include "s5pxx18_soc_hdmi.h"
+
+static u32 *hdmi_base_addr;
+
+u32 nx_hdmi_get_reg(u32 module_index, u32 offset)
+{
+	u32 *reg_addr;
+	u32 regvalue;
+
+	reg_addr = hdmi_base_addr + (offset / sizeof(u32));
+	regvalue = readl((u32 *)reg_addr);
+
+	return regvalue;
+}
+
+void nx_hdmi_set_reg(u32 module_index, u32 offset, u32 regvalue)
+{
+	s64 offset_new = (s64)((int32_t)offset);
+	u32 *reg_addr;
+
+	reg_addr = hdmi_base_addr + (offset_new / sizeof(u32));
+	writel(regvalue, (u32 *)reg_addr);
+}
+
+void nx_hdmi_set_base_address(u32 module_index, void *base_address)
+{
+	hdmi_base_addr = (u32 *)base_address;
+}
+
+void *nx_hdmi_get_base_address(u32 module_index)
+{
+	return (u32 *)hdmi_base_addr;
+}
+
+u32 nx_hdmi_get_physical_address(u32 module_index)
+{
+	const u32 physical_addr[] = PHY_BASEADDR_HDMI_LIST;
+
+	return physical_addr[module_index];
+}
drivers/video/nexell/soc/s5pxx18_soc_hdmi.h new file +488 -0

488 lines not on this page · raw message

drivers/video/nexell/soc/s5pxx18_soc_lvds.c new file +278 -0

278 lines not on this page · raw message

drivers/video/nexell/soc/s5pxx18_soc_lvds.h new file +83 -0

83 lines not on this page · raw message

Signature · 1 line
1.9.1
#11 lore raw

RFC PATCH 7/10 video: add nexell video driver (soc: dpc, makefile)

In reply to Stefan Bosch

Low level functions for DPC (Display Controller) and Makefile for all nexell video low level functions.

---

 drivers/video/nexell/soc/Makefile          |   11 +
 drivers/video/nexell/soc/s5pxx18_soc_dpc.c | 1569 ++++++++++++++++++++++++++++
 drivers/video/nexell/soc/s5pxx18_soc_dpc.h |  444 ++++++++
 3 files changed, 2024 insertions(+)
 create mode 100644 drivers/video/nexell/soc/Makefile
 create mode 100644 drivers/video/nexell/soc/s5pxx18_soc_dpc.c
 create mode 100644 drivers/video/nexell/soc/s5pxx18_soc_dpc.h
drivers/video/nexell/soc/Makefile new file +11 -0
new file mode 100644
index 0000000..a3036e5
@@ -0,0 +1,11 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# (C) Copyright 2016 Nexell
+# Junghyun, kim<[email protected]>
+
+obj-$(CONFIG_VIDEO_NX) += s5pxx18_soc_dpc.o s5pxx18_soc_mlc.o \
+			  s5pxx18_soc_disptop.o s5pxx18_soc_disptop_clk.o
+
+obj-$(CONFIG_VIDEO_NX_LVDS) += s5pxx18_soc_lvds.o
+obj-$(CONFIG_VIDEO_NX_MIPI) += s5pxx18_soc_mipi.o
+obj-$(CONFIG_VIDEO_NX_HDMI) += s5pxx18_soc_hdmi.o
drivers/video/nexell/soc/s5pxx18_soc_dpc.c new file +1569 -0

1,569 lines not on this page · raw message

drivers/video/nexell/soc/s5pxx18_soc_dpc.h new file +444 -0

444 lines not on this page · raw message

Signature · 1 line
1.9.1
#12 lore raw

RFC PATCH 8/10 video: add nexell video driver (display/video driver)

In reply to Stefan Bosch

Changes in relation to FriendlyARM's U-Boot nanopi2-v2016.01:
- nexell_display.c: Changed to DM, CONFIG_FB_ADDR can not be used anymore because framebuffer is allocated by video_reserve() in video-uclass.c. Therefore code changed appropriately.

---

 drivers/video/Kconfig                  |  10 +
 drivers/video/Makefile                 |   1 +
 drivers/video/nexell/Kconfig           |  27 ++
 drivers/video/nexell/Makefile          |  12 +
 drivers/video/nexell/s5pxx18_dp.c      | 338 ++++++++++++++++
 drivers/video/nexell/s5pxx18_dp_hdmi.c | 543 ++++++++++++++++++++++++++
 drivers/video/nexell/s5pxx18_dp_lvds.c | 274 +++++++++++++
 drivers/video/nexell/s5pxx18_dp_mipi.c | 677 +++++++++++++++++++++++++++++++++
 drivers/video/nexell/s5pxx18_dp_rgb.c  |  69 ++++
 drivers/video/nexell_display.c         | 658 ++++++++++++++++++++++++++++++++
 10 files changed, 2609 insertions(+)
 create mode 100644 drivers/video/nexell/Kconfig
 create mode 100644 drivers/video/nexell/Makefile
 create mode 100644 drivers/video/nexell/s5pxx18_dp.c
 create mode 100644 drivers/video/nexell/s5pxx18_dp_hdmi.c
 create mode 100644 drivers/video/nexell/s5pxx18_dp_lvds.c
 create mode 100644 drivers/video/nexell/s5pxx18_dp_mipi.c
 create mode 100644 drivers/video/nexell/s5pxx18_dp_rgb.c
 create mode 100644 drivers/video/nexell_display.c
drivers/video/Kconfig +10 -0
index 50ab365..dd224ab 100644
@@ -563,6 +563,16 @@ source "drivers/video/bridge/Kconfig"
 
 source "drivers/video/imx/Kconfig"
 
+config VIDEO_NX
+	bool "Enable video support on Nexell SoC"
+	depends on ARCH_S5P6818 || ARCH_S5P4418
+	help
+	   Nexell SoC supports many video output options including eDP and
+	   HDMI. This option enables this support which can be used on devices
+	   which have an eDP display connected.
+
+source "drivers/video/nexell/Kconfig"
+
 config VIDEO
 	bool "Enable legacy video support"
 	depends on !DM_VIDEO
drivers/video/Makefile +1 -0
index df7119d..3bacc64 100644
@@ -61,6 +61,7 @@ obj-${CONFIG_VIDEO_MIPI_DSI} += mipi_dsi.o
 obj-$(CONFIG_VIDEO_MVEBU) += mvebu_lcd.o
 obj-$(CONFIG_VIDEO_MX3) += mx3fb.o videomodes.o
 obj-$(CONFIG_VIDEO_MXS) += mxsfb.o videomodes.o
+obj-$(CONFIG_VIDEO_NX) += nexell_display.o videomodes.o nexell/
 obj-$(CONFIG_VIDEO_OMAP3) += omap3_dss.o
 obj-$(CONFIG_VIDEO_DSI_HOST_SANDBOX) += sandbox_dsi_host.o
 obj-$(CONFIG_VIDEO_SANDBOX_SDL) += sandbox_sdl.o
drivers/video/nexell/Kconfig new file +27 -0
new file mode 100644
index 0000000..54b8ccb
@@ -0,0 +1,27 @@
+if VIDEO_NX
+
+menu "LCD select"
+
+config VIDEO_NX_RGB
+	bool "RGB LCD"
+	help
+	  Support for RGB lcd output.
+
+config VIDEO_NX_LVDS
+	bool "LVDS LCD"
+	help
+	  Support for LVDS lcd output.
+
+config VIDEO_NX_MIPI
+	bool "MiPi"
+	help
+	  Support for MiPi lcd output.
+
+config VIDEO_NX_HDMI
+	bool "HDMI"
+	help
+	  Support for hdmi output.
+
+endmenu
+
+endif
drivers/video/nexell/Makefile new file +12 -0
new file mode 100644
index 0000000..111ab45
@@ -0,0 +1,12 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# (C) Copyright 2016 Nexell
+# Junghyun, kim<[email protected]>
+
+obj-$(CONFIG_VIDEO_NX) += s5pxx18_dp.o
+obj-$(CONFIG_VIDEO_NX) += soc/
+
+obj-$(CONFIG_VIDEO_NX_RGB)  += s5pxx18_dp_rgb.o
+obj-$(CONFIG_VIDEO_NX_LVDS) += s5pxx18_dp_lvds.o
+obj-$(CONFIG_VIDEO_NX_MIPI) += s5pxx18_dp_mipi.o
+obj-$(CONFIG_VIDEO_NX_HDMI) += s5pxx18_dp_hdmi.o
drivers/video/nexell/s5pxx18_dp.c new file +338 -0

338 lines not on this page · raw message

drivers/video/nexell/s5pxx18_dp_hdmi.c new file +543 -0

543 lines not on this page · raw message

drivers/video/nexell/s5pxx18_dp_lvds.c new file +274 -0

274 lines not on this page · raw message

drivers/video/nexell/s5pxx18_dp_mipi.c new file +677 -0

677 lines not on this page · raw message

drivers/video/nexell/s5pxx18_dp_rgb.c new file +69 -0

69 lines not on this page · raw message

drivers/video/nexell_display.c new file +658 -0

658 lines not on this page · raw message

Signature · 1 line
1.9.1
#13 lore raw

RFC PATCH 9/10 arm: add support for SoC s5p4418 (cpu) / nanopi2 board

In reply to Stefan Bosch

Changes in relation to FriendlyARM's U-Boot nanopi2-v2016.01:
- SPL not supported yet --> no spl-dir in arch/arm/cpu/armv7/s5p4418/. Appropriate line in Makefile removed.
- cpu.c: '#include <cpu_func.h>' added.
- arch/arm/cpu/armv7/s5p4418/u-boot.lds removed, is not required anylonger.
- s5p4418.dtsi: '#include "../../../include/generated/autoconf.h"' removed, is not necessary, error at out-of-tree building. '#ifdef CONFIG_CPU_NXP4330'-blocks (2x) removed. Some minor changes regarding mmc. 'u-boot,dm-pre-reloc' added to dp0 because of added DM_VIDEO support.
- board/s5p4418/ renamed to board/friendlyarm/
- All s5p4418-boards except nanopi2 removed because there is no possibility to test the other boards.
- Kconfig: Changes to have a structure like mach-bcm283x (RaspberryPi), e.g. "config ..." entries moved from/to other Kconfig.
- "CONFIG_" removed from several s5p4418/nanopi2 specific defines because the appropriate values do not need to be configurable.
- nanopi2/board.c: All getenv(), getenv_ulong(), setenv() and saveenv() renamed to env_get(), env_get_ulong(), env_set() and env_save(), respectively. MACH_TYPE_S5P4418 is not defined anymore, therefore appropriate code removed (not necessary for DT-kernels).
- nanopi2/onewire.c: All crc8() renamed to crc8_ow() because crc8() is already defined in lib/crc8.c (with different parameters).

---

 arch/arm/cpu/armv7/Makefile           |   1 +
 arch/arm/cpu/armv7/s5p4418/Makefile   |   6 +
 arch/arm/cpu/armv7/s5p4418/cpu.c      | 120 ++++++
 arch/arm/dts/Makefile                 |   3 +
 arch/arm/dts/s5p4418-nanopi2.dts      | 109 ++++++
 arch/arm/dts/s5p4418-pinctrl.dtsi     |  66 ++++
 arch/arm/dts/s5p4418.dtsi             | 157 ++++++++
 board/friendlyarm/Kconfig             |  39 ++
 board/friendlyarm/nanopi2/Kconfig     |  12 +
 board/friendlyarm/nanopi2/MAINTAINERS |   7 +
 board/friendlyarm/nanopi2/Makefile    |   6 +
 board/friendlyarm/nanopi2/board.c     | 581 ++++++++++++++++++++++++++++
 board/friendlyarm/nanopi2/hwrev.c     | 122 ++++++
 board/friendlyarm/nanopi2/hwrev.h     |  29 ++
 board/friendlyarm/nanopi2/lcds.c      | 703 ++++++++++++++++++++++++++++++++++
 board/friendlyarm/nanopi2/nxp-fb.h    |  99 +++++
 board/friendlyarm/nanopi2/onewire.c   | 323 ++++++++++++++++
 board/friendlyarm/nanopi2/onewire.h   |  29 ++
 18 files changed, 2412 insertions(+)
 create mode 100644 arch/arm/cpu/armv7/s5p4418/Makefile
 create mode 100644 arch/arm/cpu/armv7/s5p4418/cpu.c
 create mode 100644 arch/arm/dts/s5p4418-nanopi2.dts
 create mode 100644 arch/arm/dts/s5p4418-pinctrl.dtsi
 create mode 100644 arch/arm/dts/s5p4418.dtsi
 create mode 100644 board/friendlyarm/Kconfig
 create mode 100644 board/friendlyarm/nanopi2/Kconfig
 create mode 100644 board/friendlyarm/nanopi2/MAINTAINERS
 create mode 100644 board/friendlyarm/nanopi2/Makefile
 create mode 100644 board/friendlyarm/nanopi2/board.c
 create mode 100644 board/friendlyarm/nanopi2/hwrev.c
 create mode 100644 board/friendlyarm/nanopi2/hwrev.h
 create mode 100644 board/friendlyarm/nanopi2/lcds.c
 create mode 100644 board/friendlyarm/nanopi2/nxp-fb.h
 create mode 100644 board/friendlyarm/nanopi2/onewire.c
 create mode 100644 board/friendlyarm/nanopi2/onewire.h
arch/arm/cpu/armv7/Makefile +1 -0
index 8c955d0..ee87417 100644
@@ -42,3 +42,4 @@ obj-$(CONFIG_RMOBILE) += rmobile/
 obj-$(if $(filter stv0991,$(SOC)),y) += stv0991/
 obj-$(CONFIG_ARCH_SUNXI) += sunxi/
 obj-$(CONFIG_VF610) += vf610/
+obj-$(CONFIG_ARCH_S5P4418) += s5p4418/
arch/arm/cpu/armv7/s5p4418/Makefile new file +6 -0
new file mode 100644
index 0000000..321b257
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# (C) Copyright 2016 Nexell
+# Hyunseok, Jung <[email protected]>
+
+obj-y += cpu.o
arch/arm/cpu/armv7/s5p4418/cpu.c new file +120 -0

120 lines not on this page · raw message

arch/arm/dts/Makefile +3 -0
index 04a8ccc..065b2d2 100644
@@ -137,6 +137,9 @@ dtb-$(CONFIG_ROCKCHIP_RV1108) += \
 	rv1108-elgin-r1.dtb \
 	rv1108-evb.dtb
 
+dtb-$(CONFIG_ARCH_S5P4418) += \
+	s5p4418-nanopi2.dtb
+
 dtb-$(CONFIG_ARCH_MESON) += \
 	meson-gxbb-nanopi-k2.dtb \
 	meson-gxbb-odroidc2.dtb \
arch/arm/dts/s5p4418-nanopi2.dts new file +109 -0

109 lines not on this page · raw message

arch/arm/dts/s5p4418-pinctrl.dtsi new file +66 -0

66 lines not on this page · raw message

arch/arm/dts/s5p4418.dtsi new file +157 -0

157 lines not on this page · raw message

board/friendlyarm/Kconfig new file +39 -0
new file mode 100644
index 0000000..8f79640
@@ -0,0 +1,39 @@
+
+#config SYS_CONFIG_NAME
+#	string "Board header file"
+#	help
+#	  This option should contain the base name of board header file.
+#	  The header file include/configs/<CONFIG_SYS_CONFIG_NAME>.h
+#	  should be included from include/config.h.
+
+config S5P4418_ONEWIRE
+	bool "S5P4418_ONEWIRE"
+	#default y
+
+config PWM_NX
+	bool "PWM_NX"
+	#default y
+
+config SYS_RESERVE_MEM_SIZE
+	hex "SYS_RESERVE_MEM_SIZE"
+
+config ROOT_DEV
+	int "ROOT_DEV"
+	help
+	  Environment variable rootdev is set to this value if env. var. firstboot
+	  does not exist. Otherwise rootdev is set to the MMC boot device. rootdev
+	  determines (together with env. var. bootpart) where the OS (linux) is
+	  booted from.
+
+config BOOT_PART
+	int "BOOT_PART"
+	help
+	  Environment variable bootpart is set to this value. bootpart determines
+	  (together with env. var. rootdev) where the OS (linux) is booted from.
+
+config ROOT_PART
+	int "ROOT_PART"
+	help
+	  Environment variable rootpart is set to this value.
+
+source "board/friendlyarm/nanopi2/Kconfig"
board/friendlyarm/nanopi2/Kconfig new file +12 -0
new file mode 100644
index 0000000..0f68422
@@ -0,0 +1,12 @@
+if TARGET_NANOPI2
+
+config SYS_BOARD
+	default "nanopi2"
+
+config SYS_VENDOR
+	default "friendlyarm"
+
+config SYS_CONFIG_NAME
+	default "s5p4418_nanopi2"
+
+endif
board/friendlyarm/nanopi2/MAINTAINERS new file +7 -0
new file mode 100644
index 0000000..c8e2ce7
@@ -0,0 +1,7 @@
+NANOPI2 BOARD
+NANOPC-T2 BOARD
+M:  Stefan Bosch <[email protected]>
+S:  Maintained
+F:  board/s5p4418/nanopi2/
+F:  include/configs/s5p4418_nanopi2.h
+F:  configs/s5p4418_nanopi2_defconfig
board/friendlyarm/nanopi2/Makefile new file +6 -0
new file mode 100644
index 0000000..cd459f2
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# (C) Copyright 2016 Nexell
+# Hyunseok, Jung <[email protected]>
+
+obj-y	:= board.o hwrev.o onewire.o lcds.o
board/friendlyarm/nanopi2/board.c new file +581 -0

581 lines not on this page · raw message

board/friendlyarm/nanopi2/hwrev.c new file +122 -0

122 lines not on this page · raw message

board/friendlyarm/nanopi2/hwrev.h new file +29 -0
new file mode 100644
index 0000000..7bd1b67
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: GPL-2.0+
+ *
+ * Copyright (C) Guangzhou FriendlyARM Computer Tech. Co., Ltd.
+ * (http://www.friendlyarm.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, you can access it online at
+ * http://www.gnu.org/licenses/gpl-2.0.html.
+ */
+
+#ifndef __BD_HW_REV_H__
+#define __BD_HW_REV_H__
+
+extern void bd_hwrev_init(void);
+extern void bd_base_rev_init(void);
+extern u32 get_board_rev(void);
+extern const char *get_board_name(void);
+
+#endif /* __BD_HW_REV_H__ */
board/friendlyarm/nanopi2/lcds.c new file +703 -0

703 lines not on this page · raw message

board/friendlyarm/nanopi2/nxp-fb.h new file +99 -0

99 lines not on this page · raw message

board/friendlyarm/nanopi2/onewire.c new file +323 -0

323 lines not on this page · raw message

board/friendlyarm/nanopi2/onewire.h new file +29 -0
new file mode 100644
index 0000000..23a93c0
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: GPL-2.0+
+ *
+ * Copyright (C) Guangzhou FriendlyARM Computer Tech. Co., Ltd.
+ * (http://www.friendlyarm.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, you can access it online at
+ * http://www.gnu.org/licenses/gpl-2.0.html.
+ */
+
+#ifndef __ONE_WIRE_H__
+#define __ONE_WIRE_H__
+
+extern void onewire_init(void);
+extern int  onewire_get_info(unsigned char *lcd, unsigned short *fw_ver);
+extern int  onewire_get_lcd_id(void);
+extern int  onewire_set_backlight(int brightness);
+
+#endif /* __ONE_WIRE_H__ */
Signature · 1 line
1.9.1
#14 lore raw

RFC PATCH 9/10 arm: add support for SoC s5p4418 (cpu) / nanopi2 board

Quoted 28 lines · Stefan Bosch

Changes in relation to FriendlyARM's U-Boot nanopi2-v2016.01:
- SPL not supported yet --> no spl-dir in arch/arm/cpu/armv7/s5p4418/. Appropriate line in Makefile removed.
- cpu.c: '#include <cpu_func.h>' added.
- arch/arm/cpu/armv7/s5p4418/u-boot.lds removed, is not required anylonger.
- s5p4418.dtsi: '#include "../../../include/generated/autoconf.h"' removed, is not necessary, error at out-of-tree building. '#ifdef CONFIG_CPU_NXP4330'-blocks (2x) removed. Some minor changes regarding mmc. 'u-boot,dm-pre-reloc' added to dp0 because of added DM_VIDEO support.
- board/s5p4418/ renamed to board/friendlyarm/
- All s5p4418-boards except nanopi2 removed because there is no possibility to test the other boards.
- Kconfig: Changes to have a structure like mach-bcm283x (RaspberryPi), e.g. "config ..." entries moved from/to other Kconfig.
- "CONFIG_" removed from several s5p4418/nanopi2 specific defines because the appropriate values do not need to be configurable.
- nanopi2/board.c: All getenv(), getenv_ulong(), setenv() and saveenv() renamed to env_get(), env_get_ulong(), env_set() and env_save(), respectively. MACH_TYPE_S5P4418 is not defined anymore, therefore appropriate code removed (not necessary for DT-kernels).
- nanopi2/onewire.c: All crc8() renamed to crc8_ow() because crc8() is already defined in lib/crc8.c (with different parameters).

---

Quoted 7 lines
 arch/arm/cpu/armv7/Makefile           |   1 +
 arch/arm/cpu/armv7/s5p4418/Makefile   |   6 +
 arch/arm/cpu/armv7/s5p4418/cpu.c      | 120 ++++++
 arch/arm/dts/Makefile                 |   3 +
 arch/arm/dts/s5p4418-nanopi2.dts      | 109 ++++++
 arch/arm/dts/s5p4418-pinctrl.dtsi     |  66 ++++
 arch/arm/dts/s5p4418.dtsi             | 157 ++++++++

Please do the DTS files in their own commit and note what kernel release they're from. Thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200207/d4574cc9/attachment.sig>
#15 lore raw

RFC PATCH 10/10 arm: add (default) config for nanopi2 board

In reply to Stefan Bosch

Changes in relation to FriendlyARM's U-Boot nanopi2-v2016.01:
- Configuration changed, mainly several "CONFIG_..." moved from s5p4418_nanopi2.h to s5p4418_nanopi2_defconfig.
- s5p4418_nanopi2.h: "CONFIG_" removed from several s5p4418/nanopi2 specific defines because the appropriate values do not need to be configurable.

---

 MAINTAINERS                       |  19 +++
 configs/s5p4418_nanopi2_defconfig | 177 +++++++++++++++++++++++++
 doc/README.s5p4418                |  63 +++++++++
 include/configs/s5p4418_nanopi2.h | 270 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 529 insertions(+)
 create mode 100644 configs/s5p4418_nanopi2_defconfig
 create mode 100644 doc/README.s5p4418
 create mode 100644 include/configs/s5p4418_nanopi2.h
MAINTAINERS +19 -0
index 7d2729d..9e5de66 100644
@@ -258,6 +258,25 @@ F:	arch/arm/mach-at91/
 F:	board/atmel/
 F:	drivers/misc/microchip_flexcom.c
 
+ARM NEXELL S5P4418
+M:	Stefan Bosch <[email protected]>
+S:	Maintained
+F:	arch/arm/cpu/armv7/s5p4418/
+F:	arch/arm/dts/s5p4418*
+F:	arch/arm/mach-nexell/
+F:	board/friendlyarm/
+F:	configs/s5p4418_nanopi2_defconfig
+F:	doc/README.s5p4418
+F:	drivers/gpio/nx_gpio.c
+F:	drivers/i2c/nx_i2c.c
+F:	drivers/mmc/nexell_dw_mmc_dm.c
+F:	drivers/pwm/pwm-nexell*
+F:	drivers/video/nexell/
+F:	drivers/pwm/pwm-nexell*
+F:	drivers/video/nexell/
+F:	drivers/video/nexell_display.c
+F:	include/configs/s5p4418_nanopi2.h
+
 ARM OWL
 M:	Manivannan Sadhasivam <[email protected]>
 S:	Maintained
configs/s5p4418_nanopi2_defconfig new file +177 -0

177 lines not on this page · raw message

doc/README.s5p4418 new file +63 -0

63 lines not on this page · raw message

include/configs/s5p4418_nanopi2.h new file +270 -0

270 lines not on this page · raw message

Signature · 1 line
1.9.1
#16 lore raw

cover arm: add support for SoC S5P4418

In reply to Stefan Bosch
Quoted 23 lines · Stefan Bosch

This patch adds support for SAMSUNG's/NEXELL's ARM Cortex-A9 based S5P4418 SoC, especially FriendlyARM's NanoPi2 and NanoPC-T2 boards. It is based on the following FriendlyARM's U-Boot version:
https://github.com/friendlyarm/u-boot/tree/nanopi2-v2016.01.

The added mach-nexell also supports the S5P6818 SoC which is a follow-up of the S5P4418.

Main changes in relation to nanopi2-v2016.01:
- Cosmetic changes due to patman warnings/errors.
- MMC and Video drivers changed to DM.
- Configs reworked (e.g. "CONFIG_..." moved from s5p4418_nanopi2.h to s5p4418_nanopi2_defconfig)
- SPL related files are not included.
- MACH_TYPE_S5P4418 is not defined/used anymore.
- arch/arm/mach-nexell/include/mach/boot0.h added to generate the NSIH (Nexell System Information Header), substitudes tools/nexell.
- board/s5p4418/ renamed to board/friendlyarm/
- Only the NanoPi2 and NanoPC-T2 boards are supported yet because I do only have the NanoPC-T2 board to test the code (this board uses the NanoPi2 code).

Quoted 11 lines

Stefan Bosch (10):
arm: add mach-nexell (header files)
arm: add mach-nexell (all files except header files)
i2c: mmc: add nexell driver (gpio, i2c, mmc, pwm)
video: add nexell video driver (soc: displaytop)
video: add nexell video driver (soc: mlc, mipi)
video: add nexell video driver (soc: lvds, hdmi)
video: add nexell video driver (soc: dpc, makefile)
video: add nexell video driver (display/video driver)
arm: add support for SoC s5p4418 (cpu) / nanopi2 board
arm: add (default) config for nanopi2 board

In general:
- Make sure everything is checkpatch clean (or when not, explainable).
- Don't include unused (by the end of the series at least) code.
- Don't include both SPDX tags and then the whole license boilerplate.
- Do make sure that there's nothing in the config.h file that should be in a _defconfig file at this point.

Thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200207/1da83665/attachment.sig>
#17 lore raw

cover arm: add support for SoC S5P4418

In reply to Stefan Bosch

Hi,

Quoted 7 lines · Stefan Bosch

This patch adds support for SAMSUNG's/NEXELL's ARM Cortex-A9 based S5P4418 SoC, especially FriendlyARM's NanoPi2 and NanoPC-T2 boards. It is based on the following FriendlyARM's U-Boot version:
https://github.com/friendlyarm/u-boot/tree/nanopi2-v2016.01.

I don't think this is the right approach, i.e. to take everything from BSP source as it is and put
it into mainline U-BOOT. AFAIR, Some of the peripherals present on these NEXELL SoC's are
compatible with SAMSUNG IP (for instance the UART).
So, are we sure that some of the already existing code in U-BOOT can't be re-used to drive those
compatible peripherals at-least ?

Thanks
-Amit

author
#18 lore raw

cover arm: add support for SoC S5P4418

Hi Amit,

Am 22.02.20 um 14:06 schrieb Amit Tomer:

Quoted 19 lines

Hi,

Quoted 7 lines · Stefan Bosch

This patch adds support for SAMSUNG's/NEXELL's ARM Cortex-A9 based S5P4418 SoC, especially FriendlyARM's NanoPi2 and NanoPC-T2 boards. It is based on the following FriendlyARM's U-Boot version:
https://github.com/friendlyarm/u-boot/tree/nanopi2-v2016.01.

I don't think this is the right approach, i.e. to take everything from BSP source as it is and put
it into mainline U-BOOT. AFAIR, Some of the peripherals present on these NEXELL SoC's are
compatible with SAMSUNG IP (for instance the UART).
So, are we sure that some of the already existing code in U-BOOT can't be re-used to drive those
compatible peripherals at-least ?

Quoted 3 lines

Thanks
-Amit

You are right, already existing code in U-BOOT should be used where possible. So I have reviewed the code (and will review it further). Up to now, I have the following proposals for the peripherials indicated:

UART:
Actually the UARTs of the S5P4418 are Amba PrimeCell PL011 compatible, therefore the appropriate code is used. S5P6818 does have different UARTs which apparently arch/arm/mach-nexell/serial.c is for. Since S5P6818 is not supported (yet) I will remove this file.

TIMER:
Currently arch/arm/mach-nexell/timer.c is used. I will try to use arch/arm/cpu/armv7/s5p-common/timer.c instead. The timer-registers used seem to be the same, but the functions in timer.c are not which is a possible pitfall.

PWM:
Currently drivers/pwm/pwm-nexell.c is used. This is a extended version of arch/arm/cpu/armv7/s5p-common/pwm.c. I.e. pwm.c is adapted with "#if defined(CONFIG_ARCH_NEXELL) ... #else" at some places. So my proposal is to change s5p-common/pwm.c appropriately to get rid of pwm-nexell.c.

Regards
Stefan