@@ -133,16 +133,22 @@ static void pl011_disable_fifo(const struct device *dev)
133
133
134
134
static void pl011_set_flow_control (const struct device * dev , bool rts , bool cts )
135
135
{
136
+ volatile struct pl011_regs * uart = get_uart (dev );
137
+ uint32_t cr = uart -> cr ;
138
+
136
139
if (rts ) {
137
- get_uart ( dev ) -> cr |= PL011_CR_RTSEn ;
140
+ cr |= PL011_CR_RTSEn ;
138
141
} else {
139
- get_uart ( dev ) -> cr &= ~PL011_CR_RTSEn ;
142
+ cr &= ~PL011_CR_RTSEn ;
140
143
}
144
+
141
145
if (cts ) {
142
- get_uart ( dev ) -> cr |= PL011_CR_CTSEn ;
146
+ cr |= PL011_CR_CTSEn ;
143
147
} else {
144
- get_uart ( dev ) -> cr &= ~PL011_CR_CTSEn ;
148
+ cr &= ~PL011_CR_CTSEn ;
145
149
}
150
+
151
+ uart -> cr = cr ;
146
152
}
147
153
148
154
static int pl011_set_baudrate (const struct device * dev ,
@@ -151,6 +157,7 @@ static int pl011_set_baudrate(const struct device *dev,
151
157
/* Avoiding float calculations, bauddiv is left shifted by 6 */
152
158
uint64_t bauddiv = (((uint64_t )clk ) << PL011_FBRD_WIDTH )
153
159
/ (baudrate * 16U );
160
+ volatile struct pl011_regs * uart = get_uart (dev );
154
161
155
162
/* Valid bauddiv value
156
163
* uart_clk (min) >= 16 x baud_rate (max)
@@ -161,73 +168,80 @@ static int pl011_set_baudrate(const struct device *dev,
161
168
return - EINVAL ;
162
169
}
163
170
164
- get_uart ( dev ) -> ibrd = bauddiv >> PL011_FBRD_WIDTH ;
165
- get_uart ( dev ) -> fbrd = bauddiv & ((1u << PL011_FBRD_WIDTH ) - 1u );
171
+ uart -> ibrd = bauddiv >> PL011_FBRD_WIDTH ;
172
+ uart -> fbrd = bauddiv & ((1u << PL011_FBRD_WIDTH ) - 1u );
166
173
167
174
barrier_dmem_fence_full ();
168
175
169
176
/* In order to internally update the contents of ibrd or fbrd, a
170
177
* lcr_h write must always be performed at the end
171
178
* ARM DDI 0183F, Pg 3-13
172
179
*/
173
- get_uart ( dev ) -> lcr_h = get_uart ( dev ) -> lcr_h ;
180
+ uart -> lcr_h = uart -> lcr_h ;
174
181
175
182
return 0 ;
176
183
}
177
184
178
185
static bool pl011_is_readable (const struct device * dev )
179
186
{
180
187
struct pl011_data * data = dev -> data ;
188
+ volatile struct pl011_regs * uart = get_uart (dev );
189
+ uint32_t cr = uart -> cr ;
181
190
182
191
if (!data -> sbsa &&
183
- (!(get_uart ( dev ) -> cr & PL011_CR_UARTEN ) || !(get_uart ( dev ) -> cr & PL011_CR_RXE ))) {
192
+ (!(cr & PL011_CR_UARTEN ) || !(cr & PL011_CR_RXE ))) {
184
193
return false;
185
194
}
186
195
187
- return (get_uart ( dev ) -> fr & PL011_FR_RXFE ) == 0U ;
196
+ return (uart -> fr & PL011_FR_RXFE ) == 0U ;
188
197
}
189
198
190
199
static int pl011_poll_in (const struct device * dev , unsigned char * c )
191
200
{
201
+ volatile struct pl011_regs * uart = get_uart (dev );
202
+
192
203
if (!pl011_is_readable (dev )) {
193
204
return -1 ;
194
205
}
195
206
196
207
/* got a character */
197
- * c = (unsigned char )get_uart ( dev ) -> dr ;
208
+ * c = (unsigned char )uart -> dr ;
198
209
199
- return get_uart ( dev ) -> rsr & PL011_RSR_ERROR_MASK ;
210
+ return uart -> rsr & PL011_RSR_ERROR_MASK ;
200
211
}
201
212
202
213
static void pl011_poll_out (const struct device * dev ,
203
214
unsigned char c )
204
215
{
216
+ volatile struct pl011_regs * uart = get_uart (dev );
217
+
205
218
/* Wait for space in FIFO */
206
- while (get_uart ( dev ) -> fr & PL011_FR_TXFF ) {
219
+ while (uart -> fr & PL011_FR_TXFF ) {
207
220
; /* Wait */
208
221
}
209
222
210
223
/* Send a character */
211
- get_uart ( dev ) -> dr = (uint32_t )c ;
224
+ uart -> dr = (uint32_t )c ;
212
225
}
213
226
214
227
static int pl011_err_check (const struct device * dev )
215
228
{
229
+ uint32_t rsr = get_uart (dev )-> rsr ;
216
230
int errors = 0 ;
217
231
218
- if (get_uart ( dev ) -> rsr & PL011_RSR_ECR_OE ) {
232
+ if (rsr & PL011_RSR_ECR_OE ) {
219
233
errors |= UART_ERROR_OVERRUN ;
220
234
}
221
235
222
- if (get_uart ( dev ) -> rsr & PL011_RSR_ECR_BE ) {
236
+ if (rsr & PL011_RSR_ECR_BE ) {
223
237
errors |= UART_BREAK ;
224
238
}
225
239
226
- if (get_uart ( dev ) -> rsr & PL011_RSR_ECR_PE ) {
240
+ if (rsr & PL011_RSR_ECR_PE ) {
227
241
errors |= UART_ERROR_PARITY ;
228
242
}
229
243
230
- if (get_uart ( dev ) -> rsr & PL011_RSR_ECR_FE ) {
244
+ if (rsr & PL011_RSR_ECR_FE ) {
231
245
errors |= UART_ERROR_FRAMING ;
232
246
}
233
247
@@ -240,6 +254,7 @@ static int pl011_runtime_configure_internal(const struct device *dev,
240
254
{
241
255
const struct pl011_config * config = dev -> config ;
242
256
struct pl011_data * data = dev -> data ;
257
+ volatile struct pl011_regs * uart = get_uart (dev );
243
258
uint32_t lcrh ;
244
259
int ret = - ENOTSUP ;
245
260
@@ -252,7 +267,7 @@ static int pl011_runtime_configure_internal(const struct device *dev,
252
267
pl011_disable_fifo (dev );
253
268
}
254
269
255
- lcrh = get_uart ( dev ) -> lcr_h & ~(PL011_LCRH_FORMAT_MASK | PL011_LCRH_STP2 );
270
+ lcrh = uart -> lcr_h & ~(PL011_LCRH_FORMAT_MASK | PL011_LCRH_STP2 );
256
271
257
272
switch (cfg -> parity ) {
258
273
case UART_CFG_PARITY_NONE :
@@ -314,7 +329,7 @@ static int pl011_runtime_configure_internal(const struct device *dev,
314
329
}
315
330
316
331
/* Update settings */
317
- get_uart ( dev ) -> lcr_h = lcrh ;
332
+ uart -> lcr_h = lcrh ;
318
333
319
334
memcpy (& data -> uart_cfg , cfg , sizeof (data -> uart_cfg ));
320
335
@@ -353,21 +368,23 @@ static int pl011_runtime_config_get(const struct device *dev,
353
368
static int pl011_fifo_fill (const struct device * dev ,
354
369
const uint8_t * tx_data , int len )
355
370
{
371
+ volatile struct pl011_regs * uart = get_uart (dev );
356
372
int num_tx = 0U ;
357
373
358
- while (!(get_uart ( dev ) -> fr & PL011_FR_TXFF ) && (len - num_tx > 0 )) {
359
- get_uart ( dev ) -> dr = tx_data [num_tx ++ ];
374
+ while (!(uart -> fr & PL011_FR_TXFF ) && (len - num_tx > 0 )) {
375
+ uart -> dr = tx_data [num_tx ++ ];
360
376
}
361
377
return num_tx ;
362
378
}
363
379
364
380
static int pl011_fifo_read (const struct device * dev ,
365
381
uint8_t * rx_data , const int len )
366
382
{
383
+ volatile struct pl011_regs * uart = get_uart (dev );
367
384
int num_rx = 0U ;
368
385
369
- while ((len - num_rx > 0 ) && !(get_uart ( dev ) -> fr & PL011_FR_RXFE )) {
370
- rx_data [num_rx ++ ] = get_uart ( dev ) -> dr ;
386
+ while ((len - num_rx > 0 ) && !(uart -> fr & PL011_FR_RXFE )) {
387
+ rx_data [num_rx ++ ] = uart -> dr ;
371
388
}
372
389
373
390
return num_rx ;
@@ -376,8 +393,9 @@ static int pl011_fifo_read(const struct device *dev,
376
393
static void pl011_irq_tx_enable (const struct device * dev )
377
394
{
378
395
struct pl011_data * data = dev -> data ;
396
+ volatile struct pl011_regs * uart = get_uart (dev );
379
397
380
- get_uart ( dev ) -> imsc |= PL011_IMSC_TXIM ;
398
+ uart -> imsc |= PL011_IMSC_TXIM ;
381
399
if (!data -> sw_call_txdrdy ) {
382
400
return ;
383
401
}
@@ -405,7 +423,7 @@ static void pl011_irq_tx_enable(const struct device *dev)
405
423
* FIFO threshold may never be reached, and the hardware TX interrupt
406
424
* will never trigger.
407
425
*/
408
- while (get_uart ( dev ) -> imsc & PL011_IMSC_TXIM ) {
426
+ while (uart -> imsc & PL011_IMSC_TXIM ) {
409
427
K_SPINLOCK (& data -> irq_cb_lock ) {
410
428
data -> irq_cb (dev , data -> irq_cb_data );
411
429
}
@@ -429,14 +447,15 @@ static int pl011_irq_tx_complete(const struct device *dev)
429
447
static int pl011_irq_tx_ready (const struct device * dev )
430
448
{
431
449
struct pl011_data * data = dev -> data ;
450
+ volatile struct pl011_regs * uart = get_uart (dev );
432
451
433
- if (!data -> sbsa && !(get_uart ( dev ) -> cr & PL011_CR_TXE )) {
452
+ if (!data -> sbsa && !(uart -> cr & PL011_CR_TXE )) {
434
453
return false;
435
454
}
436
455
437
- return ((get_uart ( dev ) -> imsc & PL011_IMSC_TXIM ) &&
456
+ return ((uart -> imsc & PL011_IMSC_TXIM ) &&
438
457
/* Check for TX interrupt status is set or TX FIFO is empty. */
439
- (get_uart ( dev ) -> ris & PL011_RIS_TXRIS || get_uart ( dev ) -> fr & PL011_FR_TXFE ));
458
+ (uart -> ris & PL011_RIS_TXRIS || uart -> fr & PL011_FR_TXFE ));
440
459
}
441
460
442
461
static void pl011_irq_rx_enable (const struct device * dev )
@@ -451,14 +470,15 @@ static void pl011_irq_rx_disable(const struct device *dev)
451
470
452
471
static int pl011_irq_rx_ready (const struct device * dev )
453
472
{
473
+ volatile struct pl011_regs * uart = get_uart (dev );
454
474
struct pl011_data * data = dev -> data ;
455
475
456
- if (!data -> sbsa && !(get_uart ( dev ) -> cr & PL011_CR_RXE )) {
476
+ if (!data -> sbsa && !(uart -> cr & PL011_CR_RXE )) {
457
477
return false;
458
478
}
459
479
460
- return ((get_uart ( dev ) -> imsc & PL011_IMSC_RXIM ) &&
461
- (!(get_uart ( dev ) -> fr & PL011_FR_RXFE )));
480
+ return ((uart -> imsc & PL011_IMSC_RXIM ) &&
481
+ (!(uart -> fr & PL011_FR_RXFE )));
462
482
}
463
483
464
484
static void pl011_irq_err_enable (const struct device * dev )
@@ -523,10 +543,14 @@ static int pl011_init(const struct device *dev)
523
543
{
524
544
const struct pl011_config * config = dev -> config ;
525
545
struct pl011_data * data = dev -> data ;
546
+ volatile struct pl011_regs * uart ;
526
547
int ret ;
527
548
528
549
DEVICE_MMIO_MAP (dev , K_MEM_CACHE_NONE );
529
550
551
+ /* Must be placed after DEVICE_MMIO_MAP */
552
+ uart = get_uart (dev );
553
+
530
554
#if defined(CONFIG_RESET )
531
555
if (config -> reset .dev ) {
532
556
ret = reset_line_toggle_dt (& config -> reset );
@@ -575,7 +599,7 @@ static int pl011_init(const struct device *dev)
575
599
pl011_runtime_configure_internal (dev , & data -> uart_cfg , false);
576
600
577
601
/* Setting transmit and receive interrupt FIFO level */
578
- get_uart ( dev ) -> ifls = FIELD_PREP (PL011_IFLS_TXIFLSEL_M , TXIFLSEL_1_8_FULL )
602
+ uart -> ifls = FIELD_PREP (PL011_IFLS_TXIFLSEL_M , TXIFLSEL_1_8_FULL )
579
603
| FIELD_PREP (PL011_IFLS_RXIFLSEL_M , RXIFLSEL_1_2_FULL );
580
604
581
605
/* Enabling the FIFOs */
@@ -584,14 +608,14 @@ static int pl011_init(const struct device *dev)
584
608
}
585
609
}
586
610
/* initialize all IRQs as masked */
587
- get_uart ( dev ) -> imsc = 0U ;
588
- get_uart ( dev ) -> icr = PL011_IMSC_MASK_ALL ;
611
+ uart -> imsc = 0U ;
612
+ uart -> icr = PL011_IMSC_MASK_ALL ;
589
613
590
614
if (!data -> sbsa ) {
591
- get_uart ( dev ) -> dmacr = 0U ;
615
+ uart -> dmacr = 0U ;
592
616
barrier_isync_fence_full ();
593
- get_uart ( dev ) -> cr &= ~PL011_CR_SIREN ;
594
- get_uart ( dev ) -> cr |= PL011_CR_RXE | PL011_CR_TXE ;
617
+ uart -> cr &= ~PL011_CR_SIREN ;
618
+ uart -> cr |= PL011_CR_RXE | PL011_CR_TXE ;
595
619
barrier_isync_fence_full ();
596
620
}
597
621
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
0 commit comments