Skip to contentSkip to conversation

soc: imx-sc: add i.MX system controller soc driver support

PATCH In review Anson Huang 5 participants 11 messages Apr 11, 2019 – May 10, 2019 Arm i.MX and Layerscape

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 soc: imx-sc: add i.MX system controller soc driver support

i.MX8QXP is an ARMv8 SoC which has a Cortex-M4 system controller inside, the system controller is in charge of controlling power, clock and fuse etc..

This patch adds i.MX system controller soc driver support, Linux kernel has to communicate with system controller via MU (message unit) IPC to get soc revision, uid etc..

With this patch, soc info can be read from sysfs:

i.mx8qxp-mek# cat /sys/devices/soc0/family
Freescale i.MX

i.mx8qxp-mek# cat /sys/devices/soc0/soc_id
i.MX8QXP

i.mx8qxp-mek# cat /sys/devices/soc0/machine
Freescale i.MX8QXP MEK

i.mx8qxp-mek# cat /sys/devices/soc0/revision
1.1

i.mx8qxp-mek# cat /sys/devices/soc0/soc_uid
7B64280B57AC1898

---
 drivers/soc/imx/Kconfig      |   7 ++
 drivers/soc/imx/Makefile     |   1 +
 drivers/soc/imx/soc-imx-sc.c | 220 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 228 insertions(+)
 create mode 100644 drivers/soc/imx/soc-imx-sc.c
drivers/soc/imx/Kconfig +7 -0
index d80f899..c902b89 100644
@@ -7,4 +7,11 @@ config IMX_GPCV2_PM_DOMAINS
 	select PM_GENERIC_DOMAINS
 	default y if SOC_IMX7D
 
+config IMX_SC_SOC
+	depends on IMX_SCU || COMPILE_TEST
+	tristate "i.MX System Controller SoC support"
+	help
+	   If you say yes here you get support for the i.MX System
+	   Controller SoC module.
+
 endmenu
drivers/soc/imx/Makefile +1 -0
index 506a6f3..d00606d 100644
@@ -1,2 +1,3 @@
 obj-$(CONFIG_HAVE_IMX_GPC) += gpc.o
 obj-$(CONFIG_IMX_GPCV2_PM_DOMAINS) += gpcv2.o
+obj-$(CONFIG_IMX_SC_SOC) += soc-imx-sc.o
drivers/soc/imx/soc-imx-sc.c new file +220 -0

220 lines not on this page · raw message

Signature · 1 line
2.7.4
#1 lore raw

PATCH 2/2 defconfig: arm64: add i.MX system controller SoC support

This patch enables CONFIG_IMX_SC_SOC as module.

---
 arch/arm64/configs/defconfig | 1 +
 1 file changed, 1 insertion(+)
arch/arm64/configs/defconfig +1 -0
index d4c404a..b61cc53 100644
@@ -683,6 +683,7 @@ CONFIG_RPMSG_QCOM_GLINK_SMEM=m
 CONFIG_RPMSG_QCOM_SMD=y
 CONFIG_RASPBERRYPI_POWER=y
 CONFIG_IMX_GPCV2_PM_DOMAINS=y
+CONFIG_IMX_SC_SOC=m
 CONFIG_QCOM_COMMAND_DB=y
 CONFIG_QCOM_GENI_SE=y
 CONFIG_QCOM_GLINK_SSR=m
Signature · 1 line
2.7.4
#2 lore raw
In reply to Anson Huang
Quoted 25 lines · Anson Huang

i.MX8QXP is an ARMv8 SoC which has a Cortex-M4 system controller inside, the system controller is in charge of controlling power, clock and fuse etc..

This patch adds i.MX system controller soc driver support, Linux kernel has to communicate with system controller via MU (message unit) IPC to get soc revision, uid etc..

With this patch, soc info can be read from sysfs:

i.mx8qxp-mek# cat /sys/devices/soc0/family
Freescale i.MX

i.mx8qxp-mek# cat /sys/devices/soc0/soc_id
i.MX8QXP

i.mx8qxp-mek# cat /sys/devices/soc0/machine
Freescale i.MX8QXP MEK

i.mx8qxp-mek# cat /sys/devices/soc0/revision
1.1

i.mx8qxp-mek# cat /sys/devices/soc0/soc_uid
7B64280B57AC1898

Quoted 7 lines
---
 drivers/soc/imx/Kconfig      |   7 ++
 drivers/soc/imx/Makefile     |   1 +
 drivers/soc/imx/soc-imx-sc.c | 220 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 228 insertions(+)
 create mode 100644 drivers/soc/imx/soc-imx-sc.c

Rather than creating a new driver, please take a look at Abel's generic i.MX8 SoC driver, and see if it can be extended to cover i.MX8QXP.

Shawn

#3 lore raw
Quoted 34 lines · Shawn Guo
Quoted 25 lines · Anson Huang

i.MX8QXP is an ARMv8 SoC which has a Cortex-M4 system controller inside, the system controller is in charge of controlling power, clock and fuse etc..

This patch adds i.MX system controller soc driver support, Linux kernel has to communicate with system controller via MU (message unit) IPC to get soc revision, uid etc..

With this patch, soc info can be read from sysfs:

i.mx8qxp-mek# cat /sys/devices/soc0/family
Freescale i.MX

i.mx8qxp-mek# cat /sys/devices/soc0/soc_id
i.MX8QXP

i.mx8qxp-mek# cat /sys/devices/soc0/machine
Freescale i.MX8QXP MEK

i.mx8qxp-mek# cat /sys/devices/soc0/revision
1.1

i.mx8qxp-mek# cat /sys/devices/soc0/soc_uid
7B64280B57AC1898

Quoted 7 lines
---
 drivers/soc/imx/Kconfig      |   7 ++
 drivers/soc/imx/Makefile     |   1 +
 drivers/soc/imx/soc-imx-sc.c | 220 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 228 insertions(+)
 create mode 100644 drivers/soc/imx/soc-imx-sc.c
Quoted 2 lines

Rather than creating a new driver, please take a look at Abel's generic i.MX8 SoC driver, and see if it can be extended to cover i.MX8QXP.

Forgot to give pointer to Abel's driver.

https://git.kernel.org/pub/scm/linux/kernel/git/shawnguo/linux.git/commit/?h=imx/drivers&id=a7e26f356ca12906a164d83c9e9f8527ee7da022

Shawn

#4 lore raw

Hi, Shawn

Best Regards!
Anson Huang

Quoted 55 lines

-----Original Message-----
From: Shawn Guo [mailto:[email protected]]
Sent: Sunday, April 21, 2019 3:42 PM
To: Anson Huang <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Abel Vesa <[email protected]>; [email protected]; Andy Gross <[email protected]>; [email protected]; [email protected]; dl-linux-imx <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 1/2] soc: imx-sc: add i.MX system controller soc driver support

Quoted 32 lines · Shawn Guo
Quoted 22 lines · Anson Huang

i.MX8QXP is an ARMv8 SoC which has a Cortex-M4 system controller inside, the system controller is in charge of controlling power, clock and fuse etc..

This patch adds i.MX system controller soc driver support, Linux kernel has to communicate with system controller via MU (message unit) IPC to get soc revision, uid etc..

With this patch, soc info can be read from sysfs:

i.mx8qxp-mek# cat /sys/devices/soc0/family Freescale i.MX

i.mx8qxp-mek# cat /sys/devices/soc0/soc_id i.MX8QXP

i.mx8qxp-mek# cat /sys/devices/soc0/machine Freescale i.MX8QXP MEK

i.mx8qxp-mek# cat /sys/devices/soc0/revision
1.1

i.mx8qxp-mek# cat /sys/devices/soc0/soc_uid
7B64280B57AC1898

Quoted 8 lines
---
 drivers/soc/imx/Kconfig      |   7 ++
 drivers/soc/imx/Makefile     |   1 +
 drivers/soc/imx/soc-imx-sc.c | 220
+++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 228 insertions(+)
 create mode 100644 drivers/soc/imx/soc-imx-sc.c
Quoted 3 lines

Rather than creating a new driver, please take a look at Abel's generic
i.MX8 SoC driver, and see if it can be extended to cover i.MX8QXP.

Forgot to give pointer to Abel's driver.

Quoted 8 lines

https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.ker
nel.org%2Fpub%2Fscm%2Flinux%2Fkernel%2Fgit%2Fshawnguo%2Flinux.git% 2Fcommit%2F%3Fh%3Dimx%2Fdrivers%26id%3Da7e26f356ca12906a164d83c 9e9f8527ee7da022&amp;data=02%7C01%7Canson.huang%40nxp.com%7C9 e2705d7449b4c2e23ed08d6c62ce0bb%7C686ea1d3bc2b4c6fa92cd99c5c3016 35%7C0%7C0%7C636914293400307709&amp;sdata=6ySEs%2B4SE8bvcBCkfoi VBafseAYthTED9%2F5qcf25xds%3D&amp;reserved=0

Got it, I didn't notice that this patch bas been accepted, I will redo the patch based on it, thanks.

Anson.

Quoted 1 line

Shawn

#5 lore raw

Hi, Shawn

Best Regards!
Anson Huang

Quoted 86 lines

-----Original Message-----
From: Anson Huang
Sent: Monday, April 22, 2019 8:52 AM
To: Shawn Guo <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Abel Vesa <[email protected]>; [email protected]; Andy Gross <[email protected]>; [email protected]; [email protected]; dl-linux-imx <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: RE: [PATCH 1/2] soc: imx-sc: add i.MX system controller soc driver support

Hi, Shawn

Best Regards!
Anson Huang

Quoted 17 lines

-----Original Message-----
From: Shawn Guo [mailto:[email protected]]
Sent: Sunday, April 21, 2019 3:42 PM
To: Anson Huang <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Abel Vesa <[email protected]>; [email protected]; Andy Gross <[email protected]>; [email protected]; [email protected]; dl-linux-imx <[email protected]>; [email protected];
[email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 1/2] soc: imx-sc: add i.MX system controller soc driver support

Quoted 17 lines
Quoted 16 lines · Shawn Guo
Quoted 15 lines · Anson Huang

i.MX8QXP is an ARMv8 SoC which has a Cortex-M4 system controller inside, the system controller is in charge of controlling power, clock and fuse etc..

This patch adds i.MX system controller soc driver support, Linux kernel has to communicate with system controller via MU (message unit) IPC to get soc revision, uid etc..

With this patch, soc info can be read from sysfs:

i.mx8qxp-mek# cat /sys/devices/soc0/family Freescale i.MX

i.mx8qxp-mek# cat /sys/devices/soc0/soc_id i.MX8QXP

i.mx8qxp-mek# cat /sys/devices/soc0/machine Freescale i.MX8QXP

MEK

Quoted 16 lines
Quoted 16 lines
Quoted 15 lines

i.mx8qxp-mek# cat /sys/devices/soc0/revision
1.1

i.mx8qxp-mek# cat /sys/devices/soc0/soc_uid
7B64280B57AC1898

---
 drivers/soc/imx/Kconfig      |   7 ++
 drivers/soc/imx/Makefile     |   1 +
 drivers/soc/imx/soc-imx-sc.c | 220
+++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 228 insertions(+)  create mode 100644

drivers/soc/imx/soc-imx-sc.c

Quoted 8 lines
Quoted 3 lines

Rather than creating a new driver, please take a look at Abel's generic
i.MX8 SoC driver, and see if it can be extended to cover i.MX8QXP.

Forgot to give pointer to Abel's driver.

https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.
ker

nel.org%2Fpub%2Fscm%2Flinux%2Fkernel%2Fgit%2Fshawnguo%2Flinux.git%

Quoted 1 line

2Fcommit%2F%3Fh%3Dimx%2Fdrivers%26id%3Da7e26f356ca12906a164d83c

Quoted 1 line

9e9f8527ee7da022&amp;data=02%7C01%7Canson.huang%40nxp.com%7C9

Quoted 1 line
Quoted 8 lines

e2705d7449b4c2e23ed08d6c62ce0bb%7C686ea1d3bc2b4c6fa92cd99c5c3016

Quoted 1 line

35%7C0%7C0%7C636914293400307709&amp;sdata=6ySEs%2B4SE8bvcBCkfoi

Quoted 2 lines

VBafseAYthTED9%2F5qcf25xds%3D&amp;reserved=0

Got it, I didn't notice that this patch bas been accepted, I will redo the patch based on it, thanks.

I have sent the new patch set to support i.MX8QXP SoC revision based on generic i.MX8 SoC driver, however, the Kconfig modification is NOT good, it may break i.MX8MQ if IMX_SCU is NOT enabled, although we can add some warp function for SCU firmware API call to fix it, but after further thought and discussion with Dong Aisheng, I think we may need to roll back to use this patch series to create a new SoC driver dedicated for i.MX8 SoCs
with system controller inside, such as i.MX8QXP, i.MX8QM etc., the reason are as below:

For i.MX8MQ/i.MX8MM:
1. SoC driver does NOT depends on i.MX SCU firmware, so no need to use platform driver probe model, just device_init phase call is good enough;
2. The SoC driver no need to depends on IMX_SCU, so it can be always built in, no need to check IMX_SCU config;
3. The fuse check for CPU speed grading, HDCP status, NoC settings etc. could be added to this driver, but they are ONLY for i.MX8MQ/i.MX8MM etc..
For i.MX8QXP/i.MX8QM:
1. SoC driver MUST depends on IMX_SCU;
2. MUST use platform model to support defer probe;
3. No fuse check for CPU speed grading.

So, I guess the reused code for i.MX8MQ and i.MX8QXP is ONLY those part of creating SoC id device node (less than 30% I think), all other functions are implemented in total different ways, that is why I created the imx_sc_soc driver in this patch series, so do you think we can add new SoC driver for i.MX8 SoC with SCU inside? Putting 2 different architecture SoCs' driver into 1 file looks like NOT making enough sense.

Anson.

Quoted 4 lines

Anson.

Quoted 1 line

Shawn

#6 lore raw
Quoted 48 lines · Anson Huang
Quoted 22 lines

-----Original Message-----
From: Anson Huang

Quoted 20 lines

From: Shawn Guo [mailto:[email protected]]

Quoted 18 lines · Shawn Guo
Quoted 16 lines · Anson Huang

i.MX8QXP is an ARMv8 SoC which has a Cortex-M4 system controller inside, the system controller is in charge of controlling power, clock and fuse etc..

This patch adds i.MX system controller soc driver support, Linux kernel has to communicate with system controller via MU (message unit) IPC to get soc revision, uid etc..

With this patch, soc info can be read from sysfs:

  drivers/soc/imx/Kconfig      |   7 ++
  drivers/soc/imx/Makefile     |   1 +
  drivers/soc/imx/soc-imx-sc.c | 220
+++++++++++++++++++++++++++++++++++++++++++
  3 files changed, 228 insertions(+)  create mode 100644

drivers/soc/imx/soc-imx-sc.c

Quoted 6 lines
Quoted 3 lines
Quoted 3 lines

Rather than creating a new driver, please take a look at Abel's generic
i.MX8 SoC driver, and see if it can be extended to cover i.MX8QXP.

Got it, I didn't notice that this patch bas been accepted, I will redo the patch based on it, thanks.

I have sent the new patch set to support i.MX8QXP SoC revision based on generic i.MX8 SoC driver, however, the Kconfig modification is NOT good, it may break i.MX8MQ if IMX_SCU is NOT enabled, although we can add some warp function for SCU firmware API call to fix it, but after further thought and discussion with Dong Aisheng, I think we may need to roll back to use this patch series to create a new SoC driver dedicated for i.MX8 SoCs
with system controller inside, such as i.MX8QXP, i.MX8QM etc., the reason are as below:

For i.MX8MQ/i.MX8MM:
1. SoC driver does NOT depends on i.MX SCU firmware, so no need to use platform driver probe model, just device_init phase call is good enough;
2. The SoC driver no need to depends on IMX_SCU, so it can be always built in, no need to check IMX_SCU config;
3. The fuse check for CPU speed grading, HDCP status, NoC settings etc. could be added to this driver, but they are ONLY for i.MX8MQ/i.MX8MM etc..
For i.MX8QXP/i.MX8QM:
1. SoC driver MUST depends on IMX_SCU;
2. MUST use platform model to support defer probe;
3. No fuse check for CPU speed grading.

Quoted 4 lines

So, I guess the reused code for i.MX8MQ and i.MX8QXP is ONLY those part of creating SoC id device node (less than 30% I think), all other functions are implemented in total different ways, that is why I created the imx_sc_soc driver in this patch series, so do you think we can add new SoC driver for i.MX8 SoC with SCU inside? Putting 2 different architecture SoCs' driver into 1 file looks like NOT making enough sense.

+1 for separate SOC driver. The 8mq/8mm and 8qm/8qxp families are very different, they just happen to share the imx8 prefix.

It makes sense to allow people to compile one without the other and this is easier with distinct SOC drivers.

--
Regards,
Leonard

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#7 lore raw
Quoted 54 lines · Leonard Crestez
Quoted 48 lines · Anson Huang
Quoted 22 lines

-----Original Message-----
From: Anson Huang

Quoted 20 lines

From: Shawn Guo [mailto:[email protected]]

Quoted 18 lines · Shawn Guo
Quoted 16 lines · Anson Huang

i.MX8QXP is an ARMv8 SoC which has a Cortex-M4 system controller inside, the system controller is in charge of controlling power, clock and fuse etc..

This patch adds i.MX system controller soc driver support, Linux kernel has to communicate with system controller via MU (message unit) IPC to get soc revision, uid etc..

With this patch, soc info can be read from sysfs:

  drivers/soc/imx/Kconfig      |   7 ++
  drivers/soc/imx/Makefile     |   1 +
  drivers/soc/imx/soc-imx-sc.c | 220
+++++++++++++++++++++++++++++++++++++++++++
  3 files changed, 228 insertions(+)  create mode 100644

drivers/soc/imx/soc-imx-sc.c

Quoted 6 lines
Quoted 3 lines
Quoted 3 lines

Rather than creating a new driver, please take a look at Abel's generic
i.MX8 SoC driver, and see if it can be extended to cover i.MX8QXP.

Got it, I didn't notice that this patch bas been accepted, I will redo the patch based on it, thanks.

I have sent the new patch set to support i.MX8QXP SoC revision based on generic i.MX8 SoC driver, however, the Kconfig modification is NOT good, it may break i.MX8MQ if IMX_SCU is NOT enabled, although we can add some warp function for SCU firmware API call to fix it, but after further thought and discussion with Dong Aisheng, I think we may need to roll back to use this patch series to create a new SoC driver dedicated for i.MX8 SoCs
with system controller inside, such as i.MX8QXP, i.MX8QM etc., the reason are as below:

For i.MX8MQ/i.MX8MM:
1. SoC driver does NOT depends on i.MX SCU firmware, so no need to use platform driver probe model, just device_init phase call is good enough;
2. The SoC driver no need to depends on IMX_SCU, so it can be always built in, no need to check IMX_SCU config;
3. The fuse check for CPU speed grading, HDCP status, NoC settings etc. could be added to this driver, but they are ONLY for i.MX8MQ/i.MX8MM etc..
For i.MX8QXP/i.MX8QM:
1. SoC driver MUST depends on IMX_SCU;
2. MUST use platform model to support defer probe;
3. No fuse check for CPU speed grading.

Quoted 4 lines

So, I guess the reused code for i.MX8MQ and i.MX8QXP is ONLY those part of creating SoC id device node (less than 30% I think), all other functions are implemented in total different ways, that is why I created the imx_sc_soc driver in this patch series, so do you think we can add new SoC driver for i.MX8 SoC with SCU inside? Putting 2 different architecture SoCs' driver into 1 file looks like NOT making enough sense.

Quoted 5 lines

+1 for separate SOC driver. The 8mq/8mm and 8qm/8qxp families are very different, they just happen to share the imx8 prefix.

It makes sense to allow people to compile one without the other and this is easier with distinct SOC drivers.

Leonard, Abel,

Can you guys help review the patch? Thanks.

Shawn

Reviewed-by
#8 lore raw
Quoted 55 lines · Shawn Guo
Quoted 54 lines · Leonard Crestez
Quoted 52 lines · Anson Huang
Quoted 22 lines

-----Original Message-----
From: Anson Huang

Quoted 20 lines

From: Shawn Guo [mailto:[email protected]]

Quoted 18 lines · Shawn Guo
Quoted 16 lines · Anson Huang

i.MX8QXP is an ARMv8 SoC which has a Cortex-M4 system controller inside, the system controller is in charge of controlling power, clock and fuse etc..

This patch adds i.MX system controller soc driver support, Linux kernel has to communicate with system controller via MU (message unit) IPC to get soc revision, uid etc..

With this patch, soc info can be read from sysfs:

  drivers/soc/imx/Kconfig      |   7 ++
  drivers/soc/imx/Makefile     |   1 +
  drivers/soc/imx/soc-imx-sc.c | 220
+++++++++++++++++++++++++++++++++++++++++++
  3 files changed, 228 insertions(+)  create mode 100644

drivers/soc/imx/soc-imx-sc.c

Quoted 6 lines
Quoted 3 lines
Quoted 3 lines

Rather than creating a new driver, please take a look at Abel's generic
i.MX8 SoC driver, and see if it can be extended to cover i.MX8QXP.

Got it, I didn't notice that this patch bas been accepted, I will redo the patch based on it, thanks.

I have sent the new patch set to support i.MX8QXP SoC revision based on generic i.MX8 SoC driver, however, the Kconfig modification is NOT good, it may break i.MX8MQ if IMX_SCU is NOT enabled, although we can add some warp function for SCU firmware API call to fix it, but after further thought and discussion with Dong Aisheng, I think we may need to roll back to use this patch series to create a new SoC driver dedicated for i.MX8 SoCs
with system controller inside, such as i.MX8QXP, i.MX8QM etc., the reason are as below:

For i.MX8MQ/i.MX8MM:
1. SoC driver does NOT depends on i.MX SCU firmware, so no need to use platform driver probe model, just device_init phase call is good enough;
2. The SoC driver no need to depends on IMX_SCU, so it can be always built in, no need to check IMX_SCU config;
3. The fuse check for CPU speed grading, HDCP status, NoC settings etc. could be added to this driver, but they are ONLY for i.MX8MQ/i.MX8MM etc..
For i.MX8QXP/i.MX8QM:
1. SoC driver MUST depends on IMX_SCU;
2. MUST use platform model to support defer probe;
3. No fuse check for CPU speed grading.

So, I guess the reused code for i.MX8MQ and i.MX8QXP is ONLY those part of creating SoC id device node (less than 30% I think), all other functions are implemented in total different ways, that is why I created the imx_sc_soc driver in this patch series, so do you think we can add new SoC driver for i.MX8 SoC with SCU inside? Putting 2 different architecture SoCs' driver into 1 file looks like NOT making enough sense.

Quoted 5 lines
Quoted 5 lines

+1 for separate SOC driver. The 8mq/8mm and 8qm/8qxp families are very different, they just happen to share the imx8 prefix.

It makes sense to allow people to compile one without the other and this is easier with distinct SOC drivers.

Totally agree.

Quoted 6 lines

Leonard, Abel,

Can you guys help review the patch? Thanks.

Shawn

Looks good to me.

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#9 lore raw
In reply to Anson Huang
Quoted 38 lines

From: Anson Huang
Sent: Thursday, April 11, 2019 2:49 PM

i.MX8QXP is an ARMv8 SoC which has a Cortex-M4 system controller inside, the system controller is in charge of controlling power, clock and fuse etc..

This patch adds i.MX system controller soc driver support, Linux kernel has to communicate with system controller via MU (message unit) IPC to get soc revision, uid etc..

With this patch, soc info can be read from sysfs:

i.mx8qxp-mek# cat /sys/devices/soc0/family Freescale i.MX

i.mx8qxp-mek# cat /sys/devices/soc0/soc_id i.MX8QXP

i.mx8qxp-mek# cat /sys/devices/soc0/machine Freescale i.MX8QXP MEK

i.mx8qxp-mek# cat /sys/devices/soc0/revision
1.1

i.mx8qxp-mek# cat /sys/devices/soc0/soc_uid
7B64280B57AC1898

---
 drivers/soc/imx/Kconfig      |   7 ++
 drivers/soc/imx/Makefile     |   1 +
 drivers/soc/imx/soc-imx-sc.c | 220
+++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 228 insertions(+)
 create mode 100644 drivers/soc/imx/soc-imx-sc.c
drivers/soc/imx/Kconfig index renamed from drivers/soc/imx/Kconfig +0 -0

d80f899..c902b89 100644

drivers/soc/imx/Kconfig config IMX_GPCV2_PM_DOMAINS · line 11

Quoted 5 lines
drivers/soc/imx/Kconfig +2 -0
@@ -7,4 +7,11 @@ config IMX_GPCV2_PM_DOMAINS
 	select PM_GENERIC_DOMAINS
 	default y if SOC_IMX7D
 
+config IMX_SC_SOC
+	depends on IMX_SCU || COMPILE_TEST

COMPILE_TEST may not work due to dependency

drivers/soc/imx/Kconfig config IMX_GPCV2_PM_DOMAINS · line 12

Quoted 1 line
drivers/soc/imx/Kconfig +1 -0
+	tristate "i.MX System Controller SoC support"

Can it build as module?
I did not see soc_device_register() is exported.

Quoted 50 lines
drivers/soc/imx/Kconfig +4 -0
+	help
+	   If you say yes here you get support for the i.MX System
+	   Controller SoC module.
+
 endmenu
drivers/soc/imx/Makefile index renamed from drivers/soc/imx/Makefile +0 -0

506a6f3..d00606d 100644

drivers/soc/imx/Makefile +1 -0
@@ -1,2 +1,3 @@
 obj-$(CONFIG_HAVE_IMX_GPC) += gpc.o
 obj-$(CONFIG_IMX_GPCV2_PM_DOMAINS) += gpcv2.o
+obj-$(CONFIG_IMX_SC_SOC) += soc-imx-sc.o
drivers/soc/imx/soc-imx-sc.c new file renamed from drivers/soc/imx/soc-imx-sc.c +0 -0

mode 100644 index 0000000..029d754

drivers/soc/imx/soc-imx-sc.c new file +32 -0
@@ -0,0 +1,220 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2019 NXP.
+ */
+
+#include <dt-bindings/firmware/imx/rsrc.h> #include
+<linux/firmware/imx/sci.h> #include <linux/module.h> #include
+<linux/slab.h> #include <linux/sys_soc.h> #include
+<linux/platform_device.h> #include <linux/of.h>
+
+#include <soc/imx/revision.h>
+
+#define IMX_SC_SOC_DRIVER_NAME	"imx-sc-soc"
+
+#define SOC_REV_MAJOR_OFFSET	0x4
+#define SOC_REV_MAJOR_MASK	0xf
+#define SOC_REV_MINOR_OFFSET	0x4
+#define SOC_REV_MINOR_MASK	0xf
+
+#define get_soc_rev_major(rev) ((rev >> SOC_REV_MAJOR_OFFSET) &
+SOC_REV_MAJOR_MASK) #define get_soc_rev_minor(rev) ((rev >>
+SOC_REV_MINOR_OFFSET) & SOC_REV_MINOR_MASK)
+
+static u32 imx_sc_soc_rev = IMX_CHIP_REVISION_UNKNOWN; static u64
+imx_sc_soc_uid;
+
+static struct imx_sc_ipc *soc_ipc_handle; static struct platform_device
+*imx_sc_soc_pdev;
+
+struct imx_sc_msg_misc_get_soc_id {
+	struct imx_sc_rpc_msg hdr;
+	union {

drivers/soc/imx/soc-imx-sc.c line 42

Quoted 10 lines
drivers/soc/imx/soc-imx-sc.c new file +10 -0
+		struct {
+			u32 control;
+			u16 resource;
+		} __packed send;
+		struct {
+			u32 id;
+			u16 reserved;
+		} __packed resp;
+	} data;
+};

By learned more, I think probably a more safe reference is to have one more __packed outside. Then we can unified in this way.

Quoted 25 lines
drivers/soc/imx/soc-imx-sc.c new file +25 -0
+
+struct imx_sc_msg_misc_get_soc_uid {
+	struct imx_sc_rpc_msg hdr;
+	u32 id_l;
+	u32 id_h;
+};
+
+static inline void imx_sc_set_soc_revision(u32 rev) {
+	imx_sc_soc_rev = rev;
+}
+
+unsigned int imx_get_soc_revision(void) {
+	return imx_sc_soc_rev;
+}
+EXPORT_SYMBOL(imx_get_soc_revision);
+
+static u32 imx_init_revision_from_scu(void) {
+	struct imx_sc_msg_misc_get_soc_id msg;
+	struct imx_sc_msg_misc_get_soc_uid msg1;
+	struct imx_sc_rpc_msg *hdr = &msg.hdr;
+	struct imx_sc_rpc_msg *hdr1 = &msg1.hdr;
+	u32 id, rev;
+	int ret;
+
+	hdr->ver = IMX_SC_RPC_VERSION;

drivers/soc/imx/soc-imx-sc.c line 82

Quoted 10 lines
drivers/soc/imx/soc-imx-sc.c new file +10 -0
+	hdr->svc = IMX_SC_RPC_SVC_MISC;
+	hdr->func = IMX_SC_MISC_FUNC_GET_CONTROL;
+	hdr->size = 3;
+
+	msg.data.send.control = IMX_SC_C_ID;
+	msg.data.send.resource = IMX_SC_R_SYSTEM;
+
+	ret = imx_scu_call_rpc(soc_ipc_handle, &msg, true);
+	if (ret) {
+		pr_err("misc get control failed, ret %d\n", ret);

Pls improve the message

Quoted 4 lines
drivers/soc/imx/soc-imx-sc.c new file +4 -0
+		return ret;
+	}
+
+	id = msg.data.resp.id;

drivers/soc/imx/soc-imx-sc.c line 96

Quoted 10 lines
drivers/soc/imx/soc-imx-sc.c new file +10 -0
+
+	rev = (id >> 5) & 0xf;
+	rev = (((rev >> 2) + 1) << 4) | (rev & 0x3);
+
+	imx_sc_set_soc_revision(rev);
+
+	hdr1->ver = IMX_SC_RPC_VERSION;
+	hdr1->svc = IMX_SC_RPC_SVC_MISC;
+	hdr1->func = IMX_SC_MISC_FUNC_UNIQUE_ID;
+	hdr1->size = 1;

Can't we reuse the first one?

drivers/soc/imx/soc-imx-sc.c line 99

Quoted 3 lines
drivers/soc/imx/soc-imx-sc.c new file +3 -0
+
+	/* the return value of SCU FW is in correct, can NOT check the ret */
+	ret = imx_scu_call_rpc(soc_ipc_handle, &msg1, true);

If can't check ret, then do not assign?

But how do we make sure the function call is successfully? How about check other returns? E.g. -ETIMEOUT?

Quoted 28 lines
drivers/soc/imx/soc-imx-sc.c new file +28 -0
+
+	imx_sc_soc_uid = msg1.id_h;
+	imx_sc_soc_uid <<= 32;
+	imx_sc_soc_uid |= msg1.id_l;
+
+	return rev;
+}
+
+static ssize_t imx_sc_get_soc_uid(struct device *dev,
+				  struct device_attribute *attr,
+				  char *buf)
+{
+	return sprintf(buf, "%016llX\n", imx_sc_soc_uid); }
+
+static struct device_attribute imx_sc_uid =
+	__ATTR(soc_uid, 0444, imx_sc_get_soc_uid, NULL);
+
+static int imx_sc_soc_probe(struct platform_device *pdev) {
+	struct soc_device_attribute *soc_dev_attr;
+	u32 rev = IMX_CHIP_REVISION_UNKNOWN;
+	struct soc_device *soc_dev;
+	u32 soc_rev;
+	int ret;
+
+	ret = imx_scu_get_handle(&soc_ipc_handle);
+	if (ret)
+		return ret;
+

drivers/soc/imx/soc-imx-sc.c line 139

Quoted 10 lines
drivers/soc/imx/soc-imx-sc.c new file +10 -0
+	soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
+	if (!soc_dev_attr)
+		return -ENOMEM;
+
+	soc_dev_attr->family = "Freescale i.MX";
+
+	if (of_machine_is_compatible("fsl,imx8qxp"))
+		soc_dev_attr->soc_id = "i.MX8QXP";
+	else
+		soc_dev_attr->soc_id = "unknown";

Why not just return directly? Then we can remove the unknow chip support. Or we must have to support an unkown chip?

Quoted 21 lines
drivers/soc/imx/soc-imx-sc.c new file +21 -0
+
+	rev = imx_init_revision_from_scu();
+	if (rev == IMX_CHIP_REVISION_UNKNOWN)
+		dev_info(&pdev->dev, "CPU identified as %s, unknown revision\n",
+			 soc_dev_attr->soc_id);
+	else
+		dev_info(&pdev->dev, "CPU identified as %s, silicon rev %d.%d\n",
+			 soc_dev_attr->soc_id,
+			 get_soc_rev_major(rev),
+			 get_soc_rev_minor(rev));
+
+	soc_rev = imx_get_soc_revision();
+	soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%d.%d",
+					   get_soc_rev_major(rev),
+					   get_soc_rev_minor(rev));
+	if (!soc_dev_attr->revision) {
+		ret = -ENOMEM;
+		goto free_soc;
+	}
+
+	of_property_read_string(of_root, "model", &soc_dev_attr->machine);

drivers/soc/imx/soc-imx-sc.c line 170

Quoted 10 lines
drivers/soc/imx/soc-imx-sc.c new file +10 -0
+
+	soc_dev = soc_device_register(soc_dev_attr);
+	if (IS_ERR(soc_dev)) {
+		ret = PTR_ERR(soc_dev);
+		goto free_rev;
+	}
+
+	ret = device_create_file(soc_device_to_device(soc_dev), &imx_sc_uid);
+	if (ret)
+		dev_err(&pdev->dev, "could not register sysfs entry\n");

Improve the message

drivers/soc/imx/soc-imx-sc.c line 177

Quoted 7 lines
drivers/soc/imx/soc-imx-sc.c new file +7 -0
+
+	return ret;
+
+free_rev:
+	kfree(soc_dev_attr->revision);
+free_soc:
+	kfree(soc_dev_attr);

If using platform device model, we may use devm_x API as well.

However, I'm a bit wondering whether it's really necessary to model It as platform device?

Quoted 12 lines
drivers/soc/imx/soc-imx-sc.c new file +12 -0
+	return ret;
+}
+
+static struct platform_driver imx_sc_soc_driver = {
+	.driver = {
+		.name = IMX_SC_SOC_DRIVER_NAME,
+	},
+	.probe = imx_sc_soc_probe,
+};
+
+static int __init imx_sc_soc_init(void) {
+	int ret;

drivers/soc/imx/soc-imx-sc.c line 200

Quoted 10 lines
drivers/soc/imx/soc-imx-sc.c new file +10 -0
+
+	ret = platform_driver_register(&imx_sc_soc_driver);
+	if (ret)
+		return ret;
+
+	imx_sc_soc_pdev =
+		platform_device_register_simple(IMX_SC_SOC_DRIVER_NAME,
+						-1,
+						NULL,
+						0);

Is it really necessary?

Regards
Dong Aisheng

Quoted 21 lines
drivers/soc/imx/soc-imx-sc.c new file +19 -1
+	if (IS_ERR(imx_sc_soc_pdev)) {
+		ret = PTR_ERR(imx_sc_soc_pdev);
+		goto unreg_platform_driver;
+	}
+
+	return 0;
+
+unreg_platform_driver:
+	platform_driver_unregister(&imx_sc_soc_driver);
+	return ret;
+}
+
+static void __exit imx_sc_soc_exit(void) {
+	platform_device_unregister(imx_sc_soc_pdev);
+	platform_driver_unregister(&imx_sc_soc_driver);
+}
+
+module_init(imx_sc_soc_init);
+module_exit(imx_sc_soc_exit);
--

2.7.4

#10 lore raw

Hi, Aisheng
Thanks for comments, I plan to resend this patch to make it align with current drivers/soc/imx/soc-imx8.c implementation about the soc id/revision generation, the ONLY difference would be the system controller SoC driver needs to use platform driver model as it needs to use defer probe to make sure SCU driver is ready, and need to use SCU API for getting soc id, will resend a patch soon, sorry for wasting your time on this patch.

Anson.

Quoted 341 lines

-----Original Message-----
From: Aisheng Dong
Sent: Friday, May 10, 2019 5:17 PM
To: Anson Huang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Andy Gross <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Abel Vesa <[email protected]>; [email protected]; linux- [email protected]
Cc: dl-linux-imx <[email protected]>
Subject: RE: [PATCH 1/2] soc: imx-sc: add i.MX system controller soc driver support

Quoted 5 lines

From: Anson Huang
Sent: Thursday, April 11, 2019 2:49 PM

i.MX8QXP is an ARMv8 SoC which has a Cortex-M4 system controller inside, the system controller is in charge of controlling power, clock and

fuse etc..

Quoted 33 lines

This patch adds i.MX system controller soc driver support, Linux kernel has to communicate with system controller via MU (message unit) IPC to get soc revision, uid etc..

With this patch, soc info can be read from sysfs:

i.mx8qxp-mek# cat /sys/devices/soc0/family Freescale i.MX

i.mx8qxp-mek# cat /sys/devices/soc0/soc_id i.MX8QXP

i.mx8qxp-mek# cat /sys/devices/soc0/machine Freescale i.MX8QXP MEK

i.mx8qxp-mek# cat /sys/devices/soc0/revision
1.1

i.mx8qxp-mek# cat /sys/devices/soc0/soc_uid
7B64280B57AC1898

---
 drivers/soc/imx/Kconfig      |   7 ++
 drivers/soc/imx/Makefile     |   1 +
 drivers/soc/imx/soc-imx-sc.c | 220
+++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 228 insertions(+)
 create mode 100644 drivers/soc/imx/soc-imx-sc.c
drivers/soc/imx/Kconfig index renamed from drivers/soc/imx/Kconfig +0 -0

d80f899..c902b89 100644

drivers/soc/imx/Kconfig config IMX_GPCV2_PM_DOMAINS · line 11

Quoted 5 lines
drivers/soc/imx/Kconfig +2 -0
@@ -7,4 +7,11 @@ config IMX_GPCV2_PM_DOMAINS
 	select PM_GENERIC_DOMAINS
 	default y if SOC_IMX7D
 
+config IMX_SC_SOC
+	depends on IMX_SCU || COMPILE_TEST

COMPILE_TEST may not work due to dependency

drivers/soc/imx/Kconfig config IMX_GPCV2_PM_DOMAINS · line 12

Quoted 1 line
drivers/soc/imx/Kconfig +1 -0
+	tristate "i.MX System Controller SoC support"

Can it build as module?
I did not see soc_device_register() is exported.

Quoted 51 lines
drivers/soc/imx/Kconfig +4 -0
+	help
+	   If you say yes here you get support for the i.MX System
+	   Controller SoC module.
+
 endmenu
drivers/soc/imx/Makefile index renamed from drivers/soc/imx/Makefile +0 -0

506a6f3..d00606d 100644

drivers/soc/imx/Makefile +1 -0
@@ -1,2 +1,3 @@
 obj-$(CONFIG_HAVE_IMX_GPC) += gpc.o
 obj-$(CONFIG_IMX_GPCV2_PM_DOMAINS) += gpcv2.o
+obj-$(CONFIG_IMX_SC_SOC) += soc-imx-sc.o
(quoted diff) +0 -0

b/drivers/soc/imx/soc-imx-sc.c new file mode 100644 index 0000000..029d754

drivers/soc/imx/soc-imx-sc.c new file +32 -0
@@ -0,0 +1,220 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2019 NXP.
+ */
+
+#include <dt-bindings/firmware/imx/rsrc.h> #include
+<linux/firmware/imx/sci.h> #include <linux/module.h> #include
+<linux/slab.h> #include <linux/sys_soc.h> #include
+<linux/platform_device.h> #include <linux/of.h>
+
+#include <soc/imx/revision.h>
+
+#define IMX_SC_SOC_DRIVER_NAME	"imx-sc-soc"
+
+#define SOC_REV_MAJOR_OFFSET	0x4
+#define SOC_REV_MAJOR_MASK	0xf
+#define SOC_REV_MINOR_OFFSET	0x4
+#define SOC_REV_MINOR_MASK	0xf
+
+#define get_soc_rev_major(rev) ((rev >> SOC_REV_MAJOR_OFFSET) &
+SOC_REV_MAJOR_MASK) #define get_soc_rev_minor(rev) ((rev >>
+SOC_REV_MINOR_OFFSET) & SOC_REV_MINOR_MASK)
+
+static u32 imx_sc_soc_rev = IMX_CHIP_REVISION_UNKNOWN; static u64
+imx_sc_soc_uid;
+
+static struct imx_sc_ipc *soc_ipc_handle; static struct
+platform_device *imx_sc_soc_pdev;
+
+struct imx_sc_msg_misc_get_soc_id {
+	struct imx_sc_rpc_msg hdr;
+	union {

drivers/soc/imx/soc-imx-sc.c line 42

Quoted 10 lines
drivers/soc/imx/soc-imx-sc.c new file +10 -0
+		struct {
+			u32 control;
+			u16 resource;
+		} __packed send;
+		struct {
+			u32 id;
+			u16 reserved;
+		} __packed resp;
+	} data;
+};

By learned more, I think probably a more safe reference is to have one more __packed outside. Then we can unified in this way.

Quoted 25 lines
drivers/soc/imx/soc-imx-sc.c new file +25 -0
+
+struct imx_sc_msg_misc_get_soc_uid {
+	struct imx_sc_rpc_msg hdr;
+	u32 id_l;
+	u32 id_h;
+};
+
+static inline void imx_sc_set_soc_revision(u32 rev) {
+	imx_sc_soc_rev = rev;
+}
+
+unsigned int imx_get_soc_revision(void) {
+	return imx_sc_soc_rev;
+}
+EXPORT_SYMBOL(imx_get_soc_revision);
+
+static u32 imx_init_revision_from_scu(void) {
+	struct imx_sc_msg_misc_get_soc_id msg;
+	struct imx_sc_msg_misc_get_soc_uid msg1;
+	struct imx_sc_rpc_msg *hdr = &msg.hdr;
+	struct imx_sc_rpc_msg *hdr1 = &msg1.hdr;
+	u32 id, rev;
+	int ret;
+
+	hdr->ver = IMX_SC_RPC_VERSION;

drivers/soc/imx/soc-imx-sc.c line 82

Quoted 10 lines
drivers/soc/imx/soc-imx-sc.c new file +10 -0
+	hdr->svc = IMX_SC_RPC_SVC_MISC;
+	hdr->func = IMX_SC_MISC_FUNC_GET_CONTROL;
+	hdr->size = 3;
+
+	msg.data.send.control = IMX_SC_C_ID;
+	msg.data.send.resource = IMX_SC_R_SYSTEM;
+
+	ret = imx_scu_call_rpc(soc_ipc_handle, &msg, true);
+	if (ret) {
+		pr_err("misc get control failed, ret %d\n", ret);

Pls improve the message

Quoted 4 lines
drivers/soc/imx/soc-imx-sc.c new file +4 -0
+		return ret;
+	}
+
+	id = msg.data.resp.id;

drivers/soc/imx/soc-imx-sc.c line 96

Quoted 10 lines
drivers/soc/imx/soc-imx-sc.c new file +10 -0
+
+	rev = (id >> 5) & 0xf;
+	rev = (((rev >> 2) + 1) << 4) | (rev & 0x3);
+
+	imx_sc_set_soc_revision(rev);
+
+	hdr1->ver = IMX_SC_RPC_VERSION;
+	hdr1->svc = IMX_SC_RPC_SVC_MISC;
+	hdr1->func = IMX_SC_MISC_FUNC_UNIQUE_ID;
+	hdr1->size = 1;

Can't we reuse the first one?

drivers/soc/imx/soc-imx-sc.c line 99

Quoted 3 lines
drivers/soc/imx/soc-imx-sc.c new file +3 -0
+
+	/* the return value of SCU FW is in correct, can NOT check the ret */
+	ret = imx_scu_call_rpc(soc_ipc_handle, &msg1, true);

If can't check ret, then do not assign?

But how do we make sure the function call is successfully? How about check other returns? E.g. -ETIMEOUT?

Quoted 28 lines
drivers/soc/imx/soc-imx-sc.c new file +28 -0
+
+	imx_sc_soc_uid = msg1.id_h;
+	imx_sc_soc_uid <<= 32;
+	imx_sc_soc_uid |= msg1.id_l;
+
+	return rev;
+}
+
+static ssize_t imx_sc_get_soc_uid(struct device *dev,
+				  struct device_attribute *attr,
+				  char *buf)
+{
+	return sprintf(buf, "%016llX\n", imx_sc_soc_uid); }
+
+static struct device_attribute imx_sc_uid =
+	__ATTR(soc_uid, 0444, imx_sc_get_soc_uid, NULL);
+
+static int imx_sc_soc_probe(struct platform_device *pdev) {
+	struct soc_device_attribute *soc_dev_attr;
+	u32 rev = IMX_CHIP_REVISION_UNKNOWN;
+	struct soc_device *soc_dev;
+	u32 soc_rev;
+	int ret;
+
+	ret = imx_scu_get_handle(&soc_ipc_handle);
+	if (ret)
+		return ret;
+

drivers/soc/imx/soc-imx-sc.c line 139

Quoted 10 lines
drivers/soc/imx/soc-imx-sc.c new file +10 -0
+	soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
+	if (!soc_dev_attr)
+		return -ENOMEM;
+
+	soc_dev_attr->family = "Freescale i.MX";
+
+	if (of_machine_is_compatible("fsl,imx8qxp"))
+		soc_dev_attr->soc_id = "i.MX8QXP";
+	else
+		soc_dev_attr->soc_id = "unknown";

Why not just return directly? Then we can remove the unknow chip support. Or we must have to support an unkown chip?

drivers/soc/imx/soc-imx-sc.c

Quoted 4 lines
drivers/soc/imx/soc-imx-sc.c new file +4 -0
+
+	rev = imx_init_revision_from_scu();
+	if (rev == IMX_CHIP_REVISION_UNKNOWN)
+		dev_info(&pdev->dev, "CPU identified as %s, unknown

revision\n",

drivers/soc/imx/soc-imx-sc.c

Quoted 3 lines
drivers/soc/imx/soc-imx-sc.c new file +3 -0
+			 soc_dev_attr->soc_id);
+	else
+		dev_info(&pdev->dev, "CPU identified as %s, silicon

rev %d.%d\n",

Quoted 15 lines
drivers/soc/imx/soc-imx-sc.c new file +14 -0
+			 soc_dev_attr->soc_id,
+			 get_soc_rev_major(rev),
+			 get_soc_rev_minor(rev));
+
+	soc_rev = imx_get_soc_revision();
+	soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%d.%d",
+					   get_soc_rev_major(rev),
+					   get_soc_rev_minor(rev));
+	if (!soc_dev_attr->revision) {
+		ret = -ENOMEM;
+		goto free_soc;
+	}
+
+	of_property_read_string(of_root, "model", &soc_dev_attr-

machine);

drivers/soc/imx/soc-imx-sc.c

Quoted 8 lines
drivers/soc/imx/soc-imx-sc.c new file +8 -0
+
+	soc_dev = soc_device_register(soc_dev_attr);
+	if (IS_ERR(soc_dev)) {
+		ret = PTR_ERR(soc_dev);
+		goto free_rev;
+	}
+
+	ret = device_create_file(soc_device_to_device(soc_dev),

&imx_sc_uid);

drivers/soc/imx/soc-imx-sc.c

Quoted 2 lines
drivers/soc/imx/soc-imx-sc.c new file +2 -0
+	if (ret)
+		dev_err(&pdev->dev, "could not register sysfs entry\n");

Improve the message

drivers/soc/imx/soc-imx-sc.c line 177

Quoted 7 lines
drivers/soc/imx/soc-imx-sc.c new file +7 -0
+
+	return ret;
+
+free_rev:
+	kfree(soc_dev_attr->revision);
+free_soc:
+	kfree(soc_dev_attr);

If using platform device model, we may use devm_x API as well.

However, I'm a bit wondering whether it's really necessary to model It as platform device?

Quoted 9 lines
drivers/soc/imx/soc-imx-sc.c new file +9 -0
+	return ret;
+}
+
+static struct platform_driver imx_sc_soc_driver = {
+	.driver = {
+		.name = IMX_SC_SOC_DRIVER_NAME,
+	},
+	.probe = imx_sc_soc_probe,
+};

drivers/soc/imx/soc-imx-sc.c line 205

Quoted 10 lines
drivers/soc/imx/soc-imx-sc.c new file +10 -0
+
+static int __init imx_sc_soc_init(void) {
+	int ret;
+
+	ret = platform_driver_register(&imx_sc_soc_driver);
+	if (ret)
+		return ret;
+
+	imx_sc_soc_pdev =
+

platform_device_register_simple(IMX_SC_SOC_DRIVER_NAME,

drivers/soc/imx/soc-imx-sc.c line 200

Quoted 3 lines
drivers/soc/imx/soc-imx-sc.c new file +3 -0
+						-1,
+						NULL,
+						0);

Is it really necessary?

Regards
Dong Aisheng

Quoted 21 lines
drivers/soc/imx/soc-imx-sc.c new file +19 -1
+	if (IS_ERR(imx_sc_soc_pdev)) {
+		ret = PTR_ERR(imx_sc_soc_pdev);
+		goto unreg_platform_driver;
+	}
+
+	return 0;
+
+unreg_platform_driver:
+	platform_driver_unregister(&imx_sc_soc_driver);
+	return ret;
+}
+
+static void __exit imx_sc_soc_exit(void) {
+	platform_device_unregister(imx_sc_soc_pdev);
+	platform_driver_unregister(&imx_sc_soc_driver);
+}
+
+module_init(imx_sc_soc_init);
+module_exit(imx_sc_soc_exit);
--

2.7.4