Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

i3c: mipi-i3c-hci: Extract ring initialization from hci_dma_init()

Split the ring setup logic out of hci_dma_init() into a new helper
hci_dma_init_rings(). This refactoring prepares for Runtime PM support
by allowing DMA rings to be reinitialized independently after resume.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Reviewed-by: Frank Li <Frank.Li@nxp.com>
Link: https://patch.msgid.link/20260113072702.16268-11-adrian.hunter@intel.com
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>

authored by

Adrian Hunter and committed by
Alexandre Belloni
f5401c97 f180524a

+68 -50
+68 -50
drivers/i3c/master/mipi-i3c-hci/dma.c
··· 210 210 hci->io_data = NULL; 211 211 } 212 212 213 + static void hci_dma_init_rh(struct i3c_hci *hci, struct hci_rh_data *rh, int i) 214 + { 215 + u32 regval; 216 + 217 + rh_reg_write(CMD_RING_BASE_LO, lower_32_bits(rh->xfer_dma)); 218 + rh_reg_write(CMD_RING_BASE_HI, upper_32_bits(rh->xfer_dma)); 219 + rh_reg_write(RESP_RING_BASE_LO, lower_32_bits(rh->resp_dma)); 220 + rh_reg_write(RESP_RING_BASE_HI, upper_32_bits(rh->resp_dma)); 221 + 222 + regval = FIELD_PREP(CR_RING_SIZE, rh->xfer_entries); 223 + rh_reg_write(CR_SETUP, regval); 224 + 225 + rh_reg_write(INTR_STATUS_ENABLE, 0xffffffff); 226 + rh_reg_write(INTR_SIGNAL_ENABLE, INTR_IBI_READY | 227 + INTR_TRANSFER_COMPLETION | 228 + INTR_RING_OP | 229 + INTR_TRANSFER_ERR | 230 + INTR_IBI_RING_FULL | 231 + INTR_TRANSFER_ABORT); 232 + 233 + if (i >= IBI_RINGS) 234 + goto ring_ready; 235 + 236 + rh_reg_write(IBI_STATUS_RING_BASE_LO, lower_32_bits(rh->ibi_status_dma)); 237 + rh_reg_write(IBI_STATUS_RING_BASE_HI, upper_32_bits(rh->ibi_status_dma)); 238 + rh_reg_write(IBI_DATA_RING_BASE_LO, lower_32_bits(rh->ibi_data_dma)); 239 + rh_reg_write(IBI_DATA_RING_BASE_HI, upper_32_bits(rh->ibi_data_dma)); 240 + 241 + regval = FIELD_PREP(IBI_STATUS_RING_SIZE, rh->ibi_status_entries) | 242 + FIELD_PREP(IBI_DATA_CHUNK_SIZE, ilog2(rh->ibi_chunk_sz) - 2) | 243 + FIELD_PREP(IBI_DATA_CHUNK_COUNT, rh->ibi_chunks_total); 244 + rh_reg_write(IBI_SETUP, regval); 245 + 246 + regval = rh_reg_read(INTR_SIGNAL_ENABLE); 247 + regval |= INTR_IBI_READY; 248 + rh_reg_write(INTR_SIGNAL_ENABLE, regval); 249 + 250 + ring_ready: 251 + /* 252 + * The MIPI I3C HCI specification does not document reset values for 253 + * RING_OPERATION1 fields and some controllers (e.g. Intel controllers) 254 + * do not reset the values, so ensure the ring pointers are set to zero 255 + * here. 256 + */ 257 + rh_reg_write(RING_OPERATION1, 0); 258 + 259 + rh_reg_write(RING_CONTROL, RING_CTRL_ENABLE); 260 + rh_reg_write(RING_CONTROL, RING_CTRL_ENABLE | RING_CTRL_RUN_STOP); 261 + 262 + rh->done_ptr = 0; 263 + rh->ibi_chunk_ptr = 0; 264 + } 265 + 266 + static void hci_dma_init_rings(struct i3c_hci *hci) 267 + { 268 + struct hci_rings_data *rings = hci->io_data; 269 + u32 regval; 270 + 271 + regval = FIELD_PREP(MAX_HEADER_COUNT, rings->total); 272 + rhs_reg_write(CONTROL, regval); 273 + 274 + for (int i = 0; i < rings->total; i++) 275 + hci_dma_init_rh(hci, &rings->headers[i], i); 276 + } 277 + 213 278 static int hci_dma_init(struct i3c_hci *hci) 214 279 { 215 280 struct hci_rings_data *rings; ··· 312 247 rings->total = nr_rings; 313 248 rings->sysdev = sysdev; 314 249 315 - regval = FIELD_PREP(MAX_HEADER_COUNT, rings->total); 316 - rhs_reg_write(CONTROL, regval); 317 - 318 250 for (i = 0; i < rings->total; i++) { 319 251 u32 offset = rhs_reg_read(RHn_OFFSET(i)); 320 252 ··· 346 284 if (!rh->xfer || !rh->resp || !rh->src_xfers) 347 285 goto err_out; 348 286 349 - rh_reg_write(CMD_RING_BASE_LO, lower_32_bits(rh->xfer_dma)); 350 - rh_reg_write(CMD_RING_BASE_HI, upper_32_bits(rh->xfer_dma)); 351 - rh_reg_write(RESP_RING_BASE_LO, lower_32_bits(rh->resp_dma)); 352 - rh_reg_write(RESP_RING_BASE_HI, upper_32_bits(rh->resp_dma)); 353 - 354 - regval = FIELD_PREP(CR_RING_SIZE, rh->xfer_entries); 355 - rh_reg_write(CR_SETUP, regval); 356 - 357 - rh_reg_write(INTR_STATUS_ENABLE, 0xffffffff); 358 - rh_reg_write(INTR_SIGNAL_ENABLE, INTR_IBI_READY | 359 - INTR_TRANSFER_COMPLETION | 360 - INTR_RING_OP | 361 - INTR_TRANSFER_ERR | 362 - INTR_IBI_RING_FULL | 363 - INTR_TRANSFER_ABORT); 364 - 365 287 /* IBIs */ 366 288 367 289 if (i >= IBI_RINGS) 368 - goto ring_ready; 290 + continue; 369 291 370 292 regval = rh_reg_read(IBI_SETUP); 371 293 rh->ibi_status_sz = FIELD_GET(IBI_STATUS_STRUCT_SIZE, regval); ··· 388 342 ret = -ENOMEM; 389 343 goto err_out; 390 344 } 391 - 392 - rh_reg_write(IBI_STATUS_RING_BASE_LO, lower_32_bits(rh->ibi_status_dma)); 393 - rh_reg_write(IBI_STATUS_RING_BASE_HI, upper_32_bits(rh->ibi_status_dma)); 394 - rh_reg_write(IBI_DATA_RING_BASE_LO, lower_32_bits(rh->ibi_data_dma)); 395 - rh_reg_write(IBI_DATA_RING_BASE_HI, upper_32_bits(rh->ibi_data_dma)); 396 - 397 - regval = FIELD_PREP(IBI_STATUS_RING_SIZE, 398 - rh->ibi_status_entries) | 399 - FIELD_PREP(IBI_DATA_CHUNK_SIZE, 400 - ilog2(rh->ibi_chunk_sz) - 2) | 401 - FIELD_PREP(IBI_DATA_CHUNK_COUNT, 402 - rh->ibi_chunks_total); 403 - rh_reg_write(IBI_SETUP, regval); 404 - 405 - regval = rh_reg_read(INTR_SIGNAL_ENABLE); 406 - regval |= INTR_IBI_READY; 407 - rh_reg_write(INTR_SIGNAL_ENABLE, regval); 408 - 409 - ring_ready: 410 - /* 411 - * The MIPI I3C HCI specification does not document reset values for 412 - * RING_OPERATION1 fields and some controllers (e.g. Intel controllers) 413 - * do not reset the values, so ensure the ring pointers are set to zero 414 - * here. 415 - */ 416 - rh_reg_write(RING_OPERATION1, 0); 417 - 418 - rh_reg_write(RING_CONTROL, RING_CTRL_ENABLE | 419 - RING_CTRL_RUN_STOP); 420 345 } 421 346 422 347 ret = devm_add_action(hci->master.dev.parent, hci_dma_free, hci); 423 348 if (ret) 424 349 goto err_out; 425 350 351 + hci_dma_init_rings(hci); 352 + 426 353 return 0; 427 354 428 355 err_out: 429 - hci_dma_cleanup(hci); 430 356 hci_dma_free(hci); 431 357 return ret; 432 358 }