dm: Use access methods for dev/uclass private data

Most drivers use these access methods but a few do not. Update them.

In some cases the access is not permitted, so mark those with a FIXME tag
for the maintainer to check.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Pratyush Yadav <p.yadav@ti.com>
diff --git a/drivers/serial/altera_jtag_uart.c b/drivers/serial/altera_jtag_uart.c
index 0d3ccd8..4435fcf 100644
--- a/drivers/serial/altera_jtag_uart.c
+++ b/drivers/serial/altera_jtag_uart.c
@@ -37,7 +37,7 @@
 
 static int altera_jtaguart_putc(struct udevice *dev, const char ch)
 {
-	struct altera_jtaguart_plat *plat = dev->plat;
+	struct altera_jtaguart_plat *plat = dev_get_plat(dev);
 	struct altera_jtaguart_regs *const regs = plat->regs;
 	u32 st = readl(&regs->control);
 
@@ -56,7 +56,7 @@
 
 static int altera_jtaguart_pending(struct udevice *dev, bool input)
 {
-	struct altera_jtaguart_plat *plat = dev->plat;
+	struct altera_jtaguart_plat *plat = dev_get_plat(dev);
 	struct altera_jtaguart_regs *const regs = plat->regs;
 	u32 st = readl(&regs->control);
 
@@ -68,7 +68,7 @@
 
 static int altera_jtaguart_getc(struct udevice *dev)
 {
-	struct altera_jtaguart_plat *plat = dev->plat;
+	struct altera_jtaguart_plat *plat = dev_get_plat(dev);
 	struct altera_jtaguart_regs *const regs = plat->regs;
 	u32 val;
 
@@ -83,7 +83,7 @@
 static int altera_jtaguart_probe(struct udevice *dev)
 {
 #ifdef CONFIG_ALTERA_JTAG_UART_BYPASS
-	struct altera_jtaguart_plat *plat = dev->plat;
+	struct altera_jtaguart_plat *plat = dev_get_plat(dev);
 	struct altera_jtaguart_regs *const regs = plat->regs;
 
 	writel(ALTERA_JTAG_AC, &regs->control); /* clear AC flag */
diff --git a/drivers/serial/altera_uart.c b/drivers/serial/altera_uart.c
index a3efa1e..b18be6e 100644
--- a/drivers/serial/altera_uart.c
+++ b/drivers/serial/altera_uart.c
@@ -32,7 +32,7 @@
 
 static int altera_uart_setbrg(struct udevice *dev, int baudrate)
 {
-	struct altera_uart_plat *plat = dev->plat;
+	struct altera_uart_plat *plat = dev_get_plat(dev);
 	struct altera_uart_regs *const regs = plat->regs;
 	u32 div;
 
@@ -44,7 +44,7 @@
 
 static int altera_uart_putc(struct udevice *dev, const char ch)
 {
-	struct altera_uart_plat *plat = dev->plat;
+	struct altera_uart_plat *plat = dev_get_plat(dev);
 	struct altera_uart_regs *const regs = plat->regs;
 
 	if (!(readl(&regs->status) & ALTERA_UART_TRDY))
@@ -57,7 +57,7 @@
 
 static int altera_uart_pending(struct udevice *dev, bool input)
 {
-	struct altera_uart_plat *plat = dev->plat;
+	struct altera_uart_plat *plat = dev_get_plat(dev);
 	struct altera_uart_regs *const regs = plat->regs;
 	u32 st = readl(&regs->status);
 
@@ -69,7 +69,7 @@
 
 static int altera_uart_getc(struct udevice *dev)
 {
-	struct altera_uart_plat *plat = dev->plat;
+	struct altera_uart_plat *plat = dev_get_plat(dev);
 	struct altera_uart_regs *const regs = plat->regs;
 
 	if (!(readl(&regs->status) & ALTERA_UART_RRDY))
diff --git a/drivers/serial/atmel_usart.c b/drivers/serial/atmel_usart.c
index 7eabf76..7edec23 100644
--- a/drivers/serial/atmel_usart.c
+++ b/drivers/serial/atmel_usart.c
@@ -262,7 +262,7 @@
 
 static int atmel_serial_probe(struct udevice *dev)
 {
-	struct atmel_serial_plat *plat = dev->plat;
+	struct atmel_serial_plat *plat = dev_get_plat(dev);
 	struct atmel_serial_priv *priv = dev_get_priv(dev);
 	int ret;
 #if CONFIG_IS_ENABLED(OF_CONTROL)
diff --git a/drivers/serial/ns16550.c b/drivers/serial/ns16550.c
index 17808fb..508c134 100644
--- a/drivers/serial/ns16550.c
+++ b/drivers/serial/ns16550.c
@@ -498,7 +498,7 @@
 
 int ns16550_serial_probe(struct udevice *dev)
 {
-	struct ns16550_plat *plat = dev->plat;
+	struct ns16550_plat *plat = dev_get_plat(dev);
 	struct ns16550 *const com_port = dev_get_priv(dev);
 	struct reset_ctl_bulk reset_bulk;
 	fdt_addr_t addr;
@@ -535,7 +535,7 @@
 #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
 int ns16550_serial_of_to_plat(struct udevice *dev)
 {
-	struct ns16550_plat *plat = dev->plat;
+	struct ns16550_plat *plat = dev_get_plat(dev);
 	const u32 port_type = dev_get_driver_data(dev);
 	fdt_addr_t addr;
 	struct clk clk;
diff --git a/drivers/serial/sandbox.c b/drivers/serial/sandbox.c
index c7d5390..a05c564 100644
--- a/drivers/serial/sandbox.c
+++ b/drivers/serial/sandbox.c
@@ -72,7 +72,7 @@
 
 static int sandbox_serial_remove(struct udevice *dev)
 {
-	struct sandbox_serial_plat *plat = dev->plat;
+	struct sandbox_serial_plat *plat = dev_get_plat(dev);
 
 	if (plat->colour != -1)
 		output_ansi_reset();
@@ -83,7 +83,7 @@
 static int sandbox_serial_putc(struct udevice *dev, const char ch)
 {
 	struct sandbox_serial_priv *priv = dev_get_priv(dev);
-	struct sandbox_serial_plat *plat = dev->plat;
+	struct sandbox_serial_plat *plat = dev_get_plat(dev);
 
 	/* With of-platdata we don't real the colour correctly, so disable it */
 	if (!CONFIG_IS_ENABLED(OF_PLATDATA) && priv->start_of_line &&
@@ -203,7 +203,7 @@
 
 static int sandbox_serial_of_to_plat(struct udevice *dev)
 {
-	struct sandbox_serial_plat *plat = dev->plat;
+	struct sandbox_serial_plat *plat = dev_get_plat(dev);
 	const char *colour;
 	int i;
 
diff --git a/drivers/serial/serial_arc.c b/drivers/serial/serial_arc.c
index 022e377..445eacc 100644
--- a/drivers/serial/serial_arc.c
+++ b/drivers/serial/serial_arc.c
@@ -37,7 +37,7 @@
 
 static int arc_serial_setbrg(struct udevice *dev, int baudrate)
 {
-	struct arc_serial_plat *plat = dev->plat;
+	struct arc_serial_plat *plat = dev_get_plat(dev);
 	struct arc_serial_regs *const regs = plat->reg;
 	int arc_console_baud = gd->cpu_clk / (baudrate * 4) - 1;
 
@@ -49,7 +49,7 @@
 
 static int arc_serial_putc(struct udevice *dev, const char c)
 {
-	struct arc_serial_plat *plat = dev->plat;
+	struct arc_serial_plat *plat = dev_get_plat(dev);
 	struct arc_serial_regs *const regs = plat->reg;
 
 	while (!(readb(&regs->status) & UART_TXEMPTY))
@@ -67,7 +67,7 @@
 
 static int arc_serial_pending(struct udevice *dev, bool input)
 {
-	struct arc_serial_plat *plat = dev->plat;
+	struct arc_serial_plat *plat = dev_get_plat(dev);
 	struct arc_serial_regs *const regs = plat->reg;
 	uint32_t status = readb(&regs->status);
 
@@ -79,7 +79,7 @@
 
 static int arc_serial_getc(struct udevice *dev)
 {
-	struct arc_serial_plat *plat = dev->plat;
+	struct arc_serial_plat *plat = dev_get_plat(dev);
 	struct arc_serial_regs *const regs = plat->reg;
 
 	while (!arc_serial_tstc(regs))
diff --git a/drivers/serial/serial_linflexuart.c b/drivers/serial/serial_linflexuart.c
index ced0057..c3714e1 100644
--- a/drivers/serial/serial_linflexuart.c
+++ b/drivers/serial/serial_linflexuart.c
@@ -168,7 +168,7 @@
 
 static int linflex_serial_probe(struct udevice *dev)
 {
-	struct linflex_serial_plat *plat = dev->plat;
+	struct linflex_serial_plat *plat = dev_get_plat(dev);
 	struct linflex_serial_priv *priv = dev_get_priv(dev);
 
 	priv->lfuart = (struct linflex_fsl *)plat->base_addr;
diff --git a/drivers/serial/serial_lpuart.c b/drivers/serial/serial_lpuart.c
index 5beb5f2..a35e5be 100644
--- a/drivers/serial/serial_lpuart.c
+++ b/drivers/serial/serial_lpuart.c
@@ -138,7 +138,7 @@
 
 static bool is_lpuart32(struct udevice *dev)
 {
-	struct lpuart_serial_plat *plat = dev->plat;
+	struct lpuart_serial_plat *plat = dev_get_plat(dev);
 
 	return plat->flags & LPUART_FLAG_REGMAP_32BIT_REG;
 }
@@ -445,7 +445,7 @@
 
 static int lpuart_serial_getc(struct udevice *dev)
 {
-	struct lpuart_serial_plat *plat = dev->plat;
+	struct lpuart_serial_plat *plat = dev_get_plat(dev);
 
 	if (is_lpuart32(dev))
 		return _lpuart32_serial_getc(plat);
@@ -455,7 +455,7 @@
 
 static int lpuart_serial_putc(struct udevice *dev, const char c)
 {
-	struct lpuart_serial_plat *plat = dev->plat;
+	struct lpuart_serial_plat *plat = dev_get_plat(dev);
 
 	if (is_lpuart32(dev))
 		_lpuart32_serial_putc(plat, c);
@@ -467,7 +467,7 @@
 
 static int lpuart_serial_pending(struct udevice *dev, bool input)
 {
-	struct lpuart_serial_plat *plat = dev->plat;
+	struct lpuart_serial_plat *plat = dev_get_plat(dev);
 	struct lpuart_fsl *reg = plat->reg;
 	struct lpuart_fsl_reg32 *reg32 = plat->reg;
 	u32 stat;
@@ -513,7 +513,7 @@
 
 static int lpuart_serial_of_to_plat(struct udevice *dev)
 {
-	struct lpuart_serial_plat *plat = dev->plat;
+	struct lpuart_serial_plat *plat = dev_get_plat(dev);
 	const void *blob = gd->fdt_blob;
 	int node = dev_of_offset(dev);
 	fdt_addr_t addr;
diff --git a/drivers/serial/serial_mcf.c b/drivers/serial/serial_mcf.c
index 4ba6dc3..e6e21b2 100644
--- a/drivers/serial/serial_mcf.c
+++ b/drivers/serial/serial_mcf.c
@@ -83,7 +83,7 @@
 
 static int coldfire_serial_probe(struct udevice *dev)
 {
-	struct coldfire_serial_plat *plat = dev->plat;
+	struct coldfire_serial_plat *plat = dev_get_plat(dev);
 
 	plat->port = dev_seq(dev);
 
@@ -93,7 +93,7 @@
 
 static int coldfire_serial_putc(struct udevice *dev, const char ch)
 {
-	struct coldfire_serial_plat *plat = dev->plat;
+	struct coldfire_serial_plat *plat = dev_get_plat(dev);
 	uart_t *uart = (uart_t *)plat->base;
 
 	/* Wait for last character to go. */
@@ -107,7 +107,7 @@
 
 static int coldfire_serial_getc(struct udevice *dev)
 {
-	struct coldfire_serial_plat *plat = dev->plat;
+	struct coldfire_serial_plat *plat = dev_get_plat(dev);
 	uart_t *uart = (uart_t *)(plat->base);
 
 	/* Wait for a character to arrive. */
@@ -119,7 +119,7 @@
 
 int coldfire_serial_setbrg(struct udevice *dev, int baudrate)
 {
-	struct coldfire_serial_plat *plat = dev->plat;
+	struct coldfire_serial_plat *plat = dev_get_plat(dev);
 	uart_t *uart = (uart_t *)(plat->base);
 
 	mcf_serial_setbrg_common(uart, baudrate);
@@ -129,7 +129,7 @@
 
 static int coldfire_serial_pending(struct udevice *dev, bool input)
 {
-	struct coldfire_serial_plat *plat = dev->plat;
+	struct coldfire_serial_plat *plat = dev_get_plat(dev);
 	uart_t *uart = (uart_t *)(plat->base);
 
 	if (input)
diff --git a/drivers/serial/serial_meson.c b/drivers/serial/serial_meson.c
index 40d9bfe..d69ec22 100644
--- a/drivers/serial/serial_meson.c
+++ b/drivers/serial/serial_meson.c
@@ -57,7 +57,7 @@
 
 static int meson_serial_probe(struct udevice *dev)
 {
-	struct meson_serial_plat *plat = dev->plat;
+	struct meson_serial_plat *plat = dev_get_plat(dev);
 	struct meson_uart *const uart = plat->reg;
 
 	meson_serial_init(uart);
@@ -67,7 +67,7 @@
 
 static void meson_serial_rx_error(struct udevice *dev)
 {
-	struct meson_serial_plat *plat = dev->plat;
+	struct meson_serial_plat *plat = dev_get_plat(dev);
 	struct meson_uart *const uart = plat->reg;
 	u32 val = readl(&uart->control);
 
@@ -83,7 +83,7 @@
 
 static int meson_serial_getc(struct udevice *dev)
 {
-	struct meson_serial_plat *plat = dev->plat;
+	struct meson_serial_plat *plat = dev_get_plat(dev);
 	struct meson_uart *const uart = plat->reg;
 	uint32_t status = readl(&uart->status);
 
@@ -100,7 +100,7 @@
 
 static int meson_serial_putc(struct udevice *dev, const char ch)
 {
-	struct meson_serial_plat *plat = dev->plat;
+	struct meson_serial_plat *plat = dev_get_plat(dev);
 	struct meson_uart *const uart = plat->reg;
 
 	if (readl(&uart->status) & AML_UART_TX_FULL)
@@ -113,7 +113,7 @@
 
 static int meson_serial_pending(struct udevice *dev, bool input)
 {
-	struct meson_serial_plat *plat = dev->plat;
+	struct meson_serial_plat *plat = dev_get_plat(dev);
 	struct meson_uart *const uart = plat->reg;
 	uint32_t status = readl(&uart->status);
 
@@ -138,7 +138,7 @@
 
 static int meson_serial_of_to_plat(struct udevice *dev)
 {
-	struct meson_serial_plat *plat = dev->plat;
+	struct meson_serial_plat *plat = dev_get_plat(dev);
 	fdt_addr_t addr;
 
 	addr = dev_read_addr(dev);
diff --git a/drivers/serial/serial_mxc.c b/drivers/serial/serial_mxc.c
index 2603fa8..e5795da 100644
--- a/drivers/serial/serial_mxc.c
+++ b/drivers/serial/serial_mxc.c
@@ -264,7 +264,7 @@
 
 int mxc_serial_setbrg(struct udevice *dev, int baudrate)
 {
-	struct mxc_serial_plat *plat = dev->plat;
+	struct mxc_serial_plat *plat = dev_get_plat(dev);
 	u32 clk = imx_get_uartclk();
 
 	_mxc_serial_setbrg(plat->reg, clk, baudrate, plat->use_dte);
@@ -274,7 +274,7 @@
 
 static int mxc_serial_probe(struct udevice *dev)
 {
-	struct mxc_serial_plat *plat = dev->plat;
+	struct mxc_serial_plat *plat = dev_get_plat(dev);
 
 	_mxc_serial_init(plat->reg, plat->use_dte);
 
@@ -283,7 +283,7 @@
 
 static int mxc_serial_getc(struct udevice *dev)
 {
-	struct mxc_serial_plat *plat = dev->plat;
+	struct mxc_serial_plat *plat = dev_get_plat(dev);
 	struct mxc_uart *const uart = plat->reg;
 
 	if (readl(&uart->ts) & UTS_RXEMPTY)
@@ -294,7 +294,7 @@
 
 static int mxc_serial_putc(struct udevice *dev, const char ch)
 {
-	struct mxc_serial_plat *plat = dev->plat;
+	struct mxc_serial_plat *plat = dev_get_plat(dev);
 	struct mxc_uart *const uart = plat->reg;
 
 	if (!(readl(&uart->ts) & UTS_TXEMPTY))
@@ -307,7 +307,7 @@
 
 static int mxc_serial_pending(struct udevice *dev, bool input)
 {
-	struct mxc_serial_plat *plat = dev->plat;
+	struct mxc_serial_plat *plat = dev_get_plat(dev);
 	struct mxc_uart *const uart = plat->reg;
 	uint32_t sr2 = readl(&uart->sr2);
 
@@ -327,7 +327,7 @@
 #if CONFIG_IS_ENABLED(OF_CONTROL)
 static int mxc_serial_of_to_plat(struct udevice *dev)
 {
-	struct mxc_serial_plat *plat = dev->plat;
+	struct mxc_serial_plat *plat = dev_get_plat(dev);
 	fdt_addr_t addr;
 
 	addr = dev_read_addr(dev);
diff --git a/drivers/serial/serial_omap.c b/drivers/serial/serial_omap.c
index c235215..2b23ece 100644
--- a/drivers/serial/serial_omap.c
+++ b/drivers/serial/serial_omap.c
@@ -101,7 +101,7 @@
 #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
 static int omap_serial_of_to_plat(struct udevice *dev)
 {
-	struct ns16550_plat *plat = dev->plat;
+	struct ns16550_plat *plat = dev_get_plat(dev);
 	fdt_addr_t addr;
 	struct clk clk;
 	int err;
diff --git a/drivers/serial/serial_pxa.c b/drivers/serial/serial_pxa.c
index d82f3b9..669841e 100644
--- a/drivers/serial/serial_pxa.c
+++ b/drivers/serial/serial_pxa.c
@@ -268,7 +268,7 @@
 #ifdef CONFIG_DM_SERIAL
 static int pxa_serial_probe(struct udevice *dev)
 {
-	struct pxa_serial_plat *plat = dev->plat;
+	struct pxa_serial_plat *plat = dev_get_plat(dev);
 
 	pxa_setbrg_common((struct pxa_uart_regs *)plat->base, plat->port,
 			  plat->baudrate);
@@ -277,7 +277,7 @@
 
 static int pxa_serial_putc(struct udevice *dev, const char ch)
 {
-	struct pxa_serial_plat *plat = dev->plat;
+	struct pxa_serial_plat *plat = dev_get_plat(dev);
 	struct pxa_uart_regs *uart_regs = (struct pxa_uart_regs *)plat->base;
 
 	/* Wait for last character to go. */
@@ -291,7 +291,7 @@
 
 static int pxa_serial_getc(struct udevice *dev)
 {
-	struct pxa_serial_plat *plat = dev->plat;
+	struct pxa_serial_plat *plat = dev_get_plat(dev);
 	struct pxa_uart_regs *uart_regs = (struct pxa_uart_regs *)plat->base;
 
 	/* Wait for a character to arrive. */
@@ -303,7 +303,7 @@
 
 int pxa_serial_setbrg(struct udevice *dev, int baudrate)
 {
-	struct pxa_serial_plat *plat = dev->plat;
+	struct pxa_serial_plat *plat = dev_get_plat(dev);
 	struct pxa_uart_regs *uart_regs = (struct pxa_uart_regs *)plat->base;
 	int port = plat->port;
 
@@ -314,7 +314,7 @@
 
 static int pxa_serial_pending(struct udevice *dev, bool input)
 {
-	struct pxa_serial_plat *plat = dev->plat;
+	struct pxa_serial_plat *plat = dev_get_plat(dev);
 	struct pxa_uart_regs *uart_regs = (struct pxa_uart_regs *)plat->base;
 
 	if (input)
diff --git a/drivers/serial/serial_rockchip.c b/drivers/serial/serial_rockchip.c
index 036c072..97d4086 100644
--- a/drivers/serial/serial_rockchip.c
+++ b/drivers/serial/serial_rockchip.c
@@ -10,6 +10,7 @@
 #include <ns16550.h>
 #include <serial.h>
 #include <asm/arch-rockchip/clock.h>
+#include <dm/device-internal.h>
 
 #if defined(CONFIG_ROCKCHIP_RK3188)
 struct rockchip_uart_plat {
@@ -34,7 +35,7 @@
 	plat->plat.reg_shift = plat->dtplat.reg_shift;
 	plat->plat.clock = plat->dtplat.clock_frequency;
 	plat->plat.fcr = UART_FCR_DEFVAL;
-	dev->plat = &plat->plat;
+	dev_set_plat(dev, &plat->plat);
 
 	return ns16550_serial_probe(dev);
 }
diff --git a/drivers/serial/serial_s5p.c b/drivers/serial/serial_s5p.c
index 120df83..0eac0d5 100644
--- a/drivers/serial/serial_s5p.c
+++ b/drivers/serial/serial_s5p.c
@@ -88,7 +88,7 @@
 #ifndef CONFIG_SPL_BUILD
 int s5p_serial_setbrg(struct udevice *dev, int baudrate)
 {
-	struct s5p_serial_plat *plat = dev->plat;
+	struct s5p_serial_plat *plat = dev_get_plat(dev);
 	struct s5p_uart *const uart = plat->reg;
 	u32 uclk;
 
@@ -111,7 +111,7 @@
 
 static int s5p_serial_probe(struct udevice *dev)
 {
-	struct s5p_serial_plat *plat = dev->plat;
+	struct s5p_serial_plat *plat = dev_get_plat(dev);
 	struct s5p_uart *const uart = plat->reg;
 
 	s5p_serial_init(uart);
@@ -140,7 +140,7 @@
 
 static int s5p_serial_getc(struct udevice *dev)
 {
-	struct s5p_serial_plat *plat = dev->plat;
+	struct s5p_serial_plat *plat = dev_get_plat(dev);
 	struct s5p_uart *const uart = plat->reg;
 
 	if (!(readl(&uart->ufstat) & RX_FIFO_COUNT_MASK))
@@ -152,7 +152,7 @@
 
 static int s5p_serial_putc(struct udevice *dev, const char ch)
 {
-	struct s5p_serial_plat *plat = dev->plat;
+	struct s5p_serial_plat *plat = dev_get_plat(dev);
 	struct s5p_uart *const uart = plat->reg;
 
 	if (readl(&uart->ufstat) & TX_FIFO_FULL)
@@ -166,7 +166,7 @@
 
 static int s5p_serial_pending(struct udevice *dev, bool input)
 {
-	struct s5p_serial_plat *plat = dev->plat;
+	struct s5p_serial_plat *plat = dev_get_plat(dev);
 	struct s5p_uart *const uart = plat->reg;
 	uint32_t ufstat = readl(&uart->ufstat);
 
@@ -178,7 +178,7 @@
 
 static int s5p_serial_of_to_plat(struct udevice *dev)
 {
-	struct s5p_serial_plat *plat = dev->plat;
+	struct s5p_serial_plat *plat = dev_get_plat(dev);
 	fdt_addr_t addr;
 
 	addr = dev_read_addr(dev);