Linux preempt-rt

Check our new training course

Real-Time Linux with PREEMPT_RT

Check our new training course
with Creative Commons CC-BY-SA
lecture and lab materials

Bootlin logo

Elixir Cross Referencer

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
/*
 * Copyright (c) 2021 IoT.bzh
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#define DT_DRV_COMPAT renesas_rcar_scif

#include <errno.h>
#include <device.h>
#include <devicetree.h>
#include <drivers/uart.h>
#include <drivers/clock_control.h>
#include <drivers/clock_control/rcar_clock_control.h>
#include <spinlock.h>

struct uart_rcar_cfg {
	uint32_t reg_addr;
	const struct device *clock_dev;
	struct rcar_cpg_clk mod_clk;
	struct rcar_cpg_clk bus_clk;
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
	void (*irq_config_func)(const struct device *dev);
#endif
};

struct uart_rcar_data {
	struct uart_config current_config;
	uint32_t clk_rate;
	struct k_spinlock lock;
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
	uart_irq_callback_user_data_t callback;
	void *cb_data;
#endif
};

/* Registers */
#define SCSMR           0x00    /* Serial Mode Register */
#define SCBRR           0x04    /* Bit Rate Register */
#define SCSCR           0x08    /* Serial Control Register */
#define SCFTDR          0x0c    /* Transmit FIFO Data Register */
#define SCFSR           0x10    /* Serial Status Register */
#define SCFRDR          0x14    /* Receive FIFO Data Register */
#define SCFCR           0x18    /* FIFO Control Register */
#define SCFDR           0x1c    /* FIFO Data Count Register */
#define SCSPTR          0x20    /* Serial Port Register */
#define SCLSR           0x24    /* Line Status Register */
#define DL              0x30    /* Frequency Division Register */
#define CKS             0x34    /* Clock Select Register */

/* SCSMR (Serial Mode Register) */
#define SCSMR_C_A       BIT(7)  /* Communication Mode */
#define SCSMR_CHR       BIT(6)  /* 7-bit Character Length */
#define SCSMR_PE        BIT(5)  /* Parity Enable */
#define SCSMR_O_E       BIT(4)  /* Odd Parity */
#define SCSMR_STOP      BIT(3)  /* Stop Bit Length */
#define SCSMR_CKS1      BIT(1)  /* Clock Select 1 */
#define SCSMR_CKS0      BIT(0)  /* Clock Select 0 */

/* SCSCR (Serial Control Register) */
#define SCSCR_TEIE      BIT(11) /* Transmit End Interrupt Enable */
#define SCSCR_TIE       BIT(7)  /* Transmit Interrupt Enable */
#define SCSCR_RIE       BIT(6)  /* Receive Interrupt Enable */
#define SCSCR_TE        BIT(5)  /* Transmit Enable */
#define SCSCR_RE        BIT(4)  /* Receive Enable */
#define SCSCR_REIE      BIT(3)  /* Receive Error Interrupt Enable */
#define SCSCR_TOIE      BIT(2)  /* Timeout Interrupt Enable */
#define SCSCR_CKE1      BIT(1)  /* Clock Enable 1 */
#define SCSCR_CKE0      BIT(0)  /* Clock Enable 0 */

/* SCFCR (FIFO Control Register) */
#define SCFCR_RTRG1     BIT(7)  /* Receive FIFO Data Count Trigger 1 */
#define SCFCR_RTRG0     BIT(6)  /* Receive FIFO Data Count Trigger 0 */
#define SCFCR_TTRG1     BIT(5)  /* Transmit FIFO Data Count Trigger 1 */
#define SCFCR_TTRG0     BIT(4)  /* Transmit FIFO Data Count Trigger 0 */
#define SCFCR_MCE       BIT(3)  /* Modem Control Enable */
#define SCFCR_TFRST     BIT(2)  /* Transmit FIFO Data Register Reset */
#define SCFCR_RFRST     BIT(1)  /* Receive FIFO Data Register Reset */
#define SCFCR_LOOP      BIT(0)  /* Loopback Test */

/* SCFSR (Serial Status Register) */
#define SCFSR_PER3      BIT(15) /* Parity Error Count 3 */
#define SCFSR_PER2      BIT(14) /* Parity Error Count 2 */
#define SCFSR_PER1      BIT(13) /* Parity Error Count 1 */
#define SCFSR_PER0      BIT(12) /* Parity Error Count 0 */
#define SCFSR_FER3      BIT(11) /* Framing Error Count 3 */
#define SCFSR_FER2      BIT(10) /* Framing Error Count 2 */
#define SCFSR_FER_1     BIT(9)  /* Framing Error Count 1 */
#define SCFSR_FER0      BIT(8)  /* Framing Error Count 0 */
#define SCFSR_ER        BIT(7)  /* Receive Error */
#define SCFSR_TEND      BIT(6)  /* Transmission ended */
#define SCFSR_TDFE      BIT(5)  /* Transmit FIFO Data Empty */
#define SCFSR_BRK       BIT(4)  /* Break Detect */
#define SCFSR_FER       BIT(3)  /* Framing Error */
#define SCFSR_PER       BIT(2)  /* Parity Error */
#define SCFSR_RDF       BIT(1)  /* Receive FIFO Data Full */
#define SCFSR_DR        BIT(0)  /* Receive Data Ready */

/* SCLSR (Line Status Register) on (H)SCIF */
#define SCLSR_TO        BIT(2)  /* Timeout */
#define SCLSR_ORER      BIT(0)  /* Overrun Error */

/* Helper macros for UART */
#define DEV_UART_CFG(dev) \
	((const struct uart_rcar_cfg *)(dev)->config)
#define DEV_UART_DATA(dev) \
	((struct uart_rcar_data *)(dev)->data)

static void uart_rcar_write_8(const struct uart_rcar_cfg *config,
			      uint32_t offs, uint8_t value)
{
	sys_write8(value, config->reg_addr + offs);
}

static uint16_t uart_rcar_read_16(const struct uart_rcar_cfg *config,
				  uint32_t offs)
{
	return sys_read16(config->reg_addr + offs);
}

static void uart_rcar_write_16(const struct uart_rcar_cfg *config,
			       uint32_t offs, uint16_t value)
{
	sys_write16(value, config->reg_addr + offs);
}

static void uart_rcar_set_baudrate(const struct device *dev,
				   uint32_t baud_rate)
{
	const struct uart_rcar_cfg *config = DEV_UART_CFG(dev);
	struct uart_rcar_data *data = DEV_UART_DATA(dev);
	uint8_t reg_val;

	reg_val = ((data->clk_rate + 16 * baud_rate) / (32 * baud_rate) - 1);
	uart_rcar_write_8(config, SCBRR, reg_val);
}

static int uart_rcar_poll_in(const struct device *dev, unsigned char *p_char)
{
	const struct uart_rcar_cfg *config = DEV_UART_CFG(dev);
	struct uart_rcar_data *data = DEV_UART_DATA(dev);
	uint16_t reg_val;
	int ret = 0;

	k_spinlock_key_t key = k_spin_lock(&data->lock);

	/* Receive FIFO empty */
	if (!((uart_rcar_read_16(config, SCFSR)) & SCFSR_RDF)) {
		ret = -1;
		goto unlock;
	}

	*p_char = uart_rcar_read_16(config, SCFRDR);

	reg_val = uart_rcar_read_16(config, SCFSR);
	reg_val &= ~SCFSR_RDF;
	uart_rcar_write_16(config, SCFSR, reg_val);

unlock:
	k_spin_unlock(&data->lock, key);

	return ret;
}

static void uart_rcar_poll_out(const struct device *dev, unsigned char out_char)
{
	const struct uart_rcar_cfg *config = DEV_UART_CFG(dev);
	struct uart_rcar_data *data = DEV_UART_DATA(dev);
	uint16_t reg_val;
	k_spinlock_key_t key = k_spin_lock(&data->lock);

	/* Wait for empty space in transmit FIFO */
	while (!(uart_rcar_read_16(config, SCFSR) & SCFSR_TDFE)) {
	}

	uart_rcar_write_8(config, SCFTDR, out_char);

	reg_val = uart_rcar_read_16(config, SCFSR);
	reg_val &= ~(SCFSR_TDFE | SCFSR_TEND);
	uart_rcar_write_16(config, SCFSR, reg_val);

	k_spin_unlock(&data->lock, key);
}

static int uart_rcar_configure(const struct device *dev,
			       const struct uart_config *cfg)
{
	const struct uart_rcar_cfg *config = DEV_UART_CFG(dev);
	struct uart_rcar_data *data = DEV_UART_DATA(dev);

	uint16_t reg_val;
	k_spinlock_key_t key;

	if (cfg->parity != UART_CFG_PARITY_NONE ||
	    cfg->stop_bits != UART_CFG_STOP_BITS_1 ||
	    cfg->data_bits != UART_CFG_DATA_BITS_8 ||
	    cfg->flow_ctrl != UART_CFG_FLOW_CTRL_NONE) {
		return -ENOTSUP;
	}

	key = k_spin_lock(&data->lock);

	/* Disable Transmit and Receive */
	reg_val = uart_rcar_read_16(config, SCSCR);
	reg_val &= ~(SCSCR_TE | SCSCR_RE);
	uart_rcar_write_16(config, SCSCR, reg_val);

	/* Emptying Transmit and Receive FIFO */
	reg_val = uart_rcar_read_16(config, SCFCR);
	reg_val |= (SCFCR_TFRST | SCFCR_RFRST);
	uart_rcar_write_16(config, SCFCR, reg_val);

	/* Resetting Errors Registers */
	reg_val = uart_rcar_read_16(config, SCFSR);
	reg_val &= ~(SCFSR_ER | SCFSR_DR | SCFSR_BRK | SCFSR_RDF);
	uart_rcar_write_16(config, SCFSR, reg_val);

	reg_val = uart_rcar_read_16(config, SCLSR);
	reg_val &= ~(SCLSR_TO | SCLSR_ORER);
	uart_rcar_write_16(config, SCLSR, reg_val);

	/* Select internal clock */
	reg_val = uart_rcar_read_16(config, SCSCR);
	reg_val &= ~(SCSCR_CKE1 | SCSCR_CKE0);
	uart_rcar_write_16(config, SCSCR, reg_val);

	/* Serial Configuration (8N1) & Clock divider selection */
	reg_val = uart_rcar_read_16(config, SCSMR);
	reg_val &= ~(SCSMR_C_A | SCSMR_CHR | SCSMR_PE | SCSMR_O_E | SCSMR_STOP |
		     SCSMR_CKS1 | SCSMR_CKS0);
	uart_rcar_write_16(config, SCSMR, reg_val);

	/* Set baudrate */
	uart_rcar_set_baudrate(dev, cfg->baudrate);

	/* FIFOs data count trigger configuration */
	reg_val = uart_rcar_read_16(config, SCFCR);
	reg_val &= ~(SCFCR_RTRG1 | SCFCR_RTRG0 | SCFCR_TTRG1 | SCFCR_TTRG0 |
		     SCFCR_MCE | SCFCR_TFRST | SCFCR_RFRST);
	uart_rcar_write_16(config, SCFCR, reg_val);

	/* Enable Transmit & Receive + disable Interrupts */
	reg_val = uart_rcar_read_16(config, SCSCR);
	reg_val |= (SCSCR_TE | SCSCR_RE);
	reg_val &= ~(SCSCR_TIE | SCSCR_RIE | SCSCR_TEIE | SCSCR_REIE |
		     SCSCR_TOIE);
	uart_rcar_write_16(config, SCSCR, reg_val);

	data->current_config = *cfg;

	k_spin_unlock(&data->lock, key);

	return 0;
}

#ifdef CONFIG_UART_USE_RUNTIME_CONFIGURE
static int uart_rcar_config_get(const struct device *dev,
				struct uart_config *cfg)
{
	struct uart_rcar_data *data = DEV_UART_DATA(dev);

	*cfg = data->current_config;

	return 0;
}
#endif /* CONFIG_UART_USE_RUNTIME_CONFIGURE */

static int uart_rcar_init(const struct device *dev)
{
	const struct uart_rcar_cfg *config = DEV_UART_CFG(dev);
	struct uart_rcar_data *data = DEV_UART_DATA(dev);
	int ret;

	ret = clock_control_on(config->clock_dev,
			       (clock_control_subsys_t *)&config->mod_clk);
	if (ret < 0) {
		return ret;
	}

	ret = clock_control_get_rate(config->clock_dev,
				     (clock_control_subsys_t *)&config->bus_clk,
				     &data->clk_rate);
	if (ret < 0) {
		return ret;
	}

	ret = uart_rcar_configure(dev, &data->current_config);
	if (ret != 0) {
		return ret;
	}

#ifdef CONFIG_UART_INTERRUPT_DRIVEN
	config->irq_config_func(dev);
#endif

	return 0;
}

#ifdef CONFIG_UART_INTERRUPT_DRIVEN

static bool uart_rcar_irq_is_enabled(const struct device *dev,
				     uint32_t irq)
{
	const struct uart_rcar_cfg *config = DEV_UART_CFG(dev);

	return !!(uart_rcar_read_16(config, SCSCR) & irq);
}

static int uart_rcar_fifo_fill(const struct device *dev,
			       const uint8_t *tx_data,
			       int len)
{
	const struct uart_rcar_cfg *config = DEV_UART_CFG(dev);
	struct uart_rcar_data *data = DEV_UART_DATA(dev);
	int num_tx = 0;
	uint16_t reg_val;
	k_spinlock_key_t key = k_spin_lock(&data->lock);

	while (((len - num_tx) > 0) &&
	       (uart_rcar_read_16(config, SCFSR) & SCFSR_TDFE)) {
		/* Send current byte */
		uart_rcar_write_8(config, SCFTDR, tx_data[num_tx]);

		reg_val = uart_rcar_read_16(config, SCFSR);
		reg_val &= ~(SCFSR_TDFE | SCFSR_TEND);
		uart_rcar_write_16(config, SCFSR, reg_val);

		num_tx++;
	}

	k_spin_unlock(&data->lock, key);

	return num_tx;
}

static int uart_rcar_fifo_read(const struct device *dev, uint8_t *rx_data,
			       const int size)
{
	const struct uart_rcar_cfg *config = DEV_UART_CFG(dev);
	struct uart_rcar_data *data = DEV_UART_DATA(dev);
	int num_rx = 0;
	uint16_t reg_val;
	k_spinlock_key_t key = k_spin_lock(&data->lock);

	while (((size - num_rx) > 0) &&
	       (uart_rcar_read_16(config, SCFSR) & SCFSR_RDF)) {
		/* Receive current byte */
		rx_data[num_rx++] = uart_rcar_read_16(config, SCFRDR);

		reg_val = uart_rcar_read_16(config, SCFSR);
		reg_val &= ~(SCFSR_RDF);
		uart_rcar_write_16(config, SCFSR, reg_val);

	}

	k_spin_unlock(&data->lock, key);

	return num_rx;
}

static void uart_rcar_irq_tx_enable(const struct device *dev)
{
	const struct uart_rcar_cfg *config = DEV_UART_CFG(dev);
	struct uart_rcar_data *data = DEV_UART_DATA(dev);

	uint16_t reg_val;
	k_spinlock_key_t key = k_spin_lock(&data->lock);

	reg_val = uart_rcar_read_16(config, SCSCR);
	reg_val |= (SCSCR_TIE);
	uart_rcar_write_16(config, SCSCR, reg_val);

	k_spin_unlock(&data->lock, key);
}

static void uart_rcar_irq_tx_disable(const struct device *dev)
{
	const struct uart_rcar_cfg *config = DEV_UART_CFG(dev);
	struct uart_rcar_data *data = DEV_UART_DATA(dev);

	uint16_t reg_val;
	k_spinlock_key_t key = k_spin_lock(&data->lock);

	reg_val = uart_rcar_read_16(config, SCSCR);
	reg_val &= ~(SCSCR_TIE);
	uart_rcar_write_16(config, SCSCR, reg_val);

	k_spin_unlock(&data->lock, key);
}

static int uart_rcar_irq_tx_ready(const struct device *dev)
{
	const struct uart_rcar_cfg *config = DEV_UART_CFG(dev);

	return !!(uart_rcar_read_16(config, SCFSR) & SCFSR_TDFE);
}

static void uart_rcar_irq_rx_enable(const struct device *dev)
{
	const struct uart_rcar_cfg *config = DEV_UART_CFG(dev);
	struct uart_rcar_data *data = DEV_UART_DATA(dev);

	uint16_t reg_val;
	k_spinlock_key_t key = k_spin_lock(&data->lock);

	reg_val = uart_rcar_read_16(config, SCSCR);
	reg_val |= (SCSCR_RIE);
	uart_rcar_write_16(config, SCSCR, reg_val);

	k_spin_unlock(&data->lock, key);
}

static void uart_rcar_irq_rx_disable(const struct device *dev)
{
	const struct uart_rcar_cfg *config = DEV_UART_CFG(dev);
	struct uart_rcar_data *data = DEV_UART_DATA(dev);

	uint16_t reg_val;
	k_spinlock_key_t key = k_spin_lock(&data->lock);

	reg_val = uart_rcar_read_16(config, SCSCR);
	reg_val &= ~(SCSCR_RIE);
	uart_rcar_write_16(config, SCSCR, reg_val);

	k_spin_unlock(&data->lock, key);
}

static int uart_rcar_irq_rx_ready(const struct device *dev)
{
	const struct uart_rcar_cfg *config = DEV_UART_CFG(dev);

	return !!(uart_rcar_read_16(config, SCFSR) & SCFSR_RDF);
}

static void uart_rcar_irq_err_enable(const struct device *dev)
{
	const struct uart_rcar_cfg *config = DEV_UART_CFG(dev);
	struct uart_rcar_data *data = DEV_UART_DATA(dev);

	uint16_t reg_val;
	k_spinlock_key_t key = k_spin_lock(&data->lock);

	reg_val = uart_rcar_read_16(config, SCSCR);
	reg_val |= (SCSCR_REIE);
	uart_rcar_write_16(config, SCSCR, reg_val);

	k_spin_unlock(&data->lock, key);
}

static void uart_rcar_irq_err_disable(const struct device *dev)
{
	const struct uart_rcar_cfg *config = DEV_UART_CFG(dev);
	struct uart_rcar_data *data = DEV_UART_DATA(dev);

	uint16_t reg_val;
	k_spinlock_key_t key = k_spin_lock(&data->lock);

	reg_val = uart_rcar_read_16(config, SCSCR);
	reg_val &= ~(SCSCR_REIE);
	uart_rcar_write_16(config, SCSCR, reg_val);

	k_spin_unlock(&data->lock, key);
}

static int uart_rcar_irq_is_pending(const struct device *dev)
{
	return (uart_rcar_irq_rx_ready(dev) && uart_rcar_irq_is_enabled(dev, SCSCR_RIE)) ||
	       (uart_rcar_irq_tx_ready(dev) && uart_rcar_irq_is_enabled(dev, SCSCR_TIE));
}

static int uart_rcar_irq_update(const struct device *dev)
{
	return 1;
}

static void uart_rcar_irq_callback_set(const struct device *dev,
				       uart_irq_callback_user_data_t cb,
				       void *cb_data)
{
	struct uart_rcar_data *data = DEV_UART_DATA(dev);

	data->callback = cb;
	data->cb_data = cb_data;
}

/**
 * @brief Interrupt service routine.
 *
 * This simply calls the callback function, if one exists.
 *
 * @param arg Argument to ISR.
 *
 * @return N/A
 */
void uart_rcar_isr(const struct device *dev)
{
	struct uart_rcar_data *data = DEV_UART_DATA(dev);

	if (data->callback) {
		data->callback(dev, data->cb_data);
	}
}

#endif /* CONFIG_UART_INTERRUPT_DRIVEN */

static const struct uart_driver_api uart_rcar_driver_api = {
	.poll_in = uart_rcar_poll_in,
	.poll_out = uart_rcar_poll_out,
#ifdef CONFIG_UART_USE_RUNTIME_CONFIGURE
	.configure = uart_rcar_configure,
	.config_get = uart_rcar_config_get,
#endif
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
	.fifo_fill = uart_rcar_fifo_fill,
	.fifo_read = uart_rcar_fifo_read,
	.irq_tx_enable = uart_rcar_irq_tx_enable,
	.irq_tx_disable = uart_rcar_irq_tx_disable,
	.irq_tx_ready = uart_rcar_irq_tx_ready,
	.irq_rx_enable = uart_rcar_irq_rx_enable,
	.irq_rx_disable = uart_rcar_irq_rx_disable,
	.irq_rx_ready = uart_rcar_irq_rx_ready,
	.irq_err_enable = uart_rcar_irq_err_enable,
	.irq_err_disable = uart_rcar_irq_err_disable,
	.irq_is_pending = uart_rcar_irq_is_pending,
	.irq_update = uart_rcar_irq_update,
	.irq_callback_set = uart_rcar_irq_callback_set,
#endif  /* CONFIG_UART_INTERRUPT_DRIVEN */
};

/* Device Instantiation */
#define UART_RCAR_DECLARE_CFG(n, IRQ_FUNC_INIT)			    \
	static const struct uart_rcar_cfg uart_rcar_cfg_##n = {	    \
		.reg_addr = DT_INST_REG_ADDR(n),		    \
		.clock_dev = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(n)), \
		.mod_clk.module =				    \
			DT_INST_CLOCKS_CELL_BY_IDX(n, 0, module),   \
		.mod_clk.domain =				    \
			DT_INST_CLOCKS_CELL_BY_IDX(n, 0, domain),   \
		.bus_clk.module =				    \
			DT_INST_CLOCKS_CELL_BY_IDX(n, 1, module),   \
		.bus_clk.domain =				    \
			DT_INST_CLOCKS_CELL_BY_IDX(n, 1, domain),   \
		IRQ_FUNC_INIT					    \
	}

#ifdef CONFIG_UART_INTERRUPT_DRIVEN
#define UART_RCAR_CONFIG_FUNC(n)				  \
	static void irq_config_func_##n(const struct device *dev) \
	{							  \
		IRQ_CONNECT(DT_INST_IRQN(n),			  \
			    DT_INST_IRQ(n, priority),		  \
			    uart_rcar_isr,			  \
			    DEVICE_DT_INST_GET(n), 0);		  \
								  \
		irq_enable(DT_INST_IRQN(n));			  \
	}
#define UART_RCAR_IRQ_CFG_FUNC_INIT(n) \
	.irq_config_func = irq_config_func_##n
#define UART_RCAR_INIT_CFG(n) \
	UART_RCAR_DECLARE_CFG(n, UART_RCAR_IRQ_CFG_FUNC_INIT(n))
#else
#define UART_RCAR_CONFIG_FUNC(n)
#define UART_RCAR_IRQ_CFG_FUNC_INIT
#define UART_RCAR_INIT_CFG(n) \
	UART_RCAR_DECLARE_CFG(n, UART_RCAR_IRQ_CFG_FUNC_INIT)
#endif

#define UART_RCAR_INIT(n)							\
	static struct uart_rcar_data uart_rcar_data_##n = {			\
		.current_config = {						\
			.baudrate = DT_INST_PROP(n, current_speed),		\
			.parity = UART_CFG_PARITY_NONE,				\
			.stop_bits = UART_CFG_STOP_BITS_1,			\
			.data_bits = UART_CFG_DATA_BITS_8,			\
			.flow_ctrl = UART_CFG_FLOW_CTRL_NONE,			\
		},								\
	};									\
										\
	static const struct uart_rcar_cfg uart_rcar_cfg_##n;			\
										\
	DEVICE_DT_INST_DEFINE(n,						\
			      uart_rcar_init,					\
			      NULL,						\
			      &uart_rcar_data_##n,				\
			      &uart_rcar_cfg_##n,				\
			      PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEVICE,	\
			      &uart_rcar_driver_api);				\
										\
	UART_RCAR_CONFIG_FUNC(n)						\
										\
	UART_RCAR_INIT_CFG(n);

DT_INST_FOREACH_STATUS_OKAY(UART_RCAR_INIT)