diff mbox series

[3/5] powerpc/zImage: Check compatible at driver init

Message ID 20180319051403.23275-3-oohall@gmail.com
State New
Headers show
Series [1/5] powerpc/zImage: Remove #ifdef in opal.c | expand

Commit Message

Oliver O'Halloran March 19, 2018, 5:14 a.m. UTC
Have each driver's init function check the compatible string
of the node given by the stdout path. This gives the drivers
a more traditional probe-also-inits structure.

Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
---
 arch/powerpc/boot/cpm-serial.c  | 2 ++
 arch/powerpc/boot/mpc52xx-psc.c | 3 +++
 arch/powerpc/boot/mpsc.c        | 3 +++
 arch/powerpc/boot/ns16550.c     | 4 ++++
 arch/powerpc/boot/opal.c        | 3 +++
 arch/powerpc/boot/uartlite.c    | 5 +++++
 6 files changed, 20 insertions(+)

Comments

Michael Ellerman March 20, 2018, 9:19 a.m. UTC | #1
Oliver O'Halloran <oohall@gmail.com> writes:
> diff --git a/arch/powerpc/boot/mpc52xx-psc.c b/arch/powerpc/boot/mpc52xx-psc.c
> index c2c08633ee35..75470936e661 100644
> --- a/arch/powerpc/boot/mpc52xx-psc.c
> +++ b/arch/powerpc/boot/mpc52xx-psc.c
> @@ -52,6 +52,9 @@ static unsigned char psc_getc(void)
>  
>  int mpc5200_psc_console_init(void *devp, struct serial_console_data *scdp)
>  {
> +	if (!dt_is_compatible(devp, "fsl,mpc5200-psc-uart"))
> +		return 1;

Returning 1 raises the question of whether this is a bool-style function
that returns 1 on success and 0 on failure - or a UNIX style function
that returns 0 for sucesss and 1 on failure.

Can we return ENODEV, or just -1 instead to make it clearer?

cheers
Oliver O'Halloran March 20, 2018, 12:56 p.m. UTC | #2
On Tue, Mar 20, 2018 at 8:19 PM, Michael Ellerman <mpe@ellerman.id.au> wrote:
> Oliver O'Halloran <oohall@gmail.com> writes:
>> diff --git a/arch/powerpc/boot/mpc52xx-psc.c b/arch/powerpc/boot/mpc52xx-psc.c
>> index c2c08633ee35..75470936e661 100644
>> --- a/arch/powerpc/boot/mpc52xx-psc.c
>> +++ b/arch/powerpc/boot/mpc52xx-psc.c
>> @@ -52,6 +52,9 @@ static unsigned char psc_getc(void)
>>
>>  int mpc5200_psc_console_init(void *devp, struct serial_console_data *scdp)
>>  {
>> +     if (!dt_is_compatible(devp, "fsl,mpc5200-psc-uart"))
>> +             return 1;
>
> Returning 1 raises the question of whether this is a bool-style function
> that returns 1 on success and 0 on failure - or a UNIX style function
> that returns 0 for sucesss and 1 on failure.
>
> Can we return ENODEV, or just -1 instead to make it clearer?

I figured we would want to differentiate between a mis-matched driver
and any other error type. There's no existing definition of ENODEV and
friends in the wrapper so I just used positive 1 as a half-assed
workaround. I don't have particularly strong feelings about it so
adding an explicit ENODEV would make things a bit cleaner. I'll fix it
on the respin.

>
> cheers
diff mbox series

Patch

diff --git a/arch/powerpc/boot/cpm-serial.c b/arch/powerpc/boot/cpm-serial.c
index dfb56829cace..f6b1cf23946e 100644
--- a/arch/powerpc/boot/cpm-serial.c
+++ b/arch/powerpc/boot/cpm-serial.c
@@ -212,6 +212,8 @@  int cpm_console_init(void *devp, struct serial_console_data *scdp)
 	} else if (dt_is_compatible(devp, "fsl,cpm2-smc-uart")) {
 		is_cpm2 = 1;
 		is_smc = 1;
+	} else if (!dt_is_compatible(devp, "fsl,cpm1-scc-uart")) {
+		return 1; /* not compatible */
 	}
 
 	if (is_smc) {
diff --git a/arch/powerpc/boot/mpc52xx-psc.c b/arch/powerpc/boot/mpc52xx-psc.c
index c2c08633ee35..75470936e661 100644
--- a/arch/powerpc/boot/mpc52xx-psc.c
+++ b/arch/powerpc/boot/mpc52xx-psc.c
@@ -52,6 +52,9 @@  static unsigned char psc_getc(void)
 
 int mpc5200_psc_console_init(void *devp, struct serial_console_data *scdp)
 {
+	if (!dt_is_compatible(devp, "fsl,mpc5200-psc-uart"))
+		return 1;
+
 	/* Get the base address of the psc registers */
 	if (dt_get_virtual_reg(devp, &psc, 1) < 1)
 		return -1;
diff --git a/arch/powerpc/boot/mpsc.c b/arch/powerpc/boot/mpsc.c
index 425ad88cce8d..59e23e886440 100644
--- a/arch/powerpc/boot/mpsc.c
+++ b/arch/powerpc/boot/mpsc.c
@@ -128,6 +128,9 @@  int mpsc_console_init(void *devp, struct serial_console_data *scdp)
 	int n, reg_set;
 	volatile char *sdma_base;
 
+	if (!dt_is_compatible(devp, "marvell,mv64360-mpsc"))
+		return 1;
+
 	n = getprop(devp, "virtual-reg", &v, sizeof(v));
 	if (n != sizeof(v))
 		goto err_out;
diff --git a/arch/powerpc/boot/ns16550.c b/arch/powerpc/boot/ns16550.c
index b0da4466d419..0e7bd5284255 100644
--- a/arch/powerpc/boot/ns16550.c
+++ b/arch/powerpc/boot/ns16550.c
@@ -58,6 +58,10 @@  int ns16550_console_init(void *devp, struct serial_console_data *scdp)
 	int n;
 	u32 reg_offset;
 
+	if (!dt_is_compatible(devp, "ns16550") &&
+	    !dt_is_compatible(devp, "pnpPNP,501"))
+		return 1;
+
 	if (dt_get_virtual_reg(devp, (void **)&reg_base, 1) < 1)
 		return -1;
 
diff --git a/arch/powerpc/boot/opal.c b/arch/powerpc/boot/opal.c
index dfb199ef5b94..0e92537536b9 100644
--- a/arch/powerpc/boot/opal.c
+++ b/arch/powerpc/boot/opal.c
@@ -83,6 +83,9 @@  static void opal_init(void)
 
 int opal_console_init(void *devp, struct serial_console_data *scdp)
 {
+	if (!dt_is_compatible(devp, "ibm,opal-console-raw"))
+		return 1;
+
 	opal_init();
 
 	if (devp) {
diff --git a/arch/powerpc/boot/uartlite.c b/arch/powerpc/boot/uartlite.c
index 46bed69b4169..fc66a5fcea66 100644
--- a/arch/powerpc/boot/uartlite.c
+++ b/arch/powerpc/boot/uartlite.c
@@ -62,6 +62,11 @@  int uartlite_console_init(void *devp, struct serial_console_data *scdp)
 	int n;
 	unsigned long reg_phys;
 
+
+	if (!dt_is_compatible(devp, "xlnx,opb-uartlite-1.00.b") &&
+	    !dt_is_compatible(devp, "xlnx,xps-uartlite-1.00.a"))
+		return 1;
+
 	n = getprop(devp, "virtual-reg", &reg_base, sizeof(reg_base));
 	if (n != sizeof(reg_base)) {
 		if (!dt_xlate_reg(devp, 0, &reg_phys, NULL))