Lines Matching +full:read +full:- +full:command
7 * PCH provides SMBus 2.0 - compliant Host Controller.
9 * SPDX-License-Identifier: Apache-2.0
29 * * periph_addr - Peripheral address (Slave address mentioned in the Specs)
30 * * command - First byte to send in the SMBus protocol operations except for
31 * Quick and Byte Read. Also known as register.
92 struct pch_data *data = dev->data; in pch_reg_read()
94 return sys_in8(data->sba + reg); in pch_reg_read()
99 struct pch_data *data = dev->data; in pch_reg_write()
101 sys_out8(val, data->sba + reg); in pch_reg_write()
112 const struct device *dev = data->dev; in host_notify_work()
113 uint8_t addr = data->notify_addr; in host_notify_work()
115 smbus_fire_callbacks(&data->host_notify_cbs, dev, addr); in host_notify_work()
121 struct pch_data *data = dev->data; in pch_smbus_host_notify_set_cb()
125 return smbus_callback_set(&data->host_notify_cbs, cb); in pch_smbus_host_notify_set_cb()
131 struct pch_data *data = dev->data; in pch_smbus_host_notify_remove_cb()
135 return smbus_callback_remove(&data->host_notify_cbs, cb); in pch_smbus_host_notify_remove_cb()
144 const struct device *dev = data->dev; in smbalert_work()
146 smbus_loop_alert_devices(dev, &data->smbalert_cbs); in smbalert_work()
152 struct pch_data *data = dev->data; in pch_smbus_smbalert_set_sb()
156 return smbus_callback_set(&data->smbalert_cbs, cb); in pch_smbus_smbalert_set_sb()
162 struct pch_data *data = dev->data; in pch_smbus_smbalert_remove_sb()
166 return smbus_callback_remove(&data->smbalert_cbs, cb); in pch_smbus_smbalert_remove_sb()
172 struct pch_data *data = dev->data; in pch_configure()
181 return -EINVAL; in pch_configure()
195 return -EINVAL; in pch_configure()
205 data->config = config; in pch_configure()
212 struct pch_data *data = dev->data; in pch_get_config()
214 *config = data->config; in pch_get_config()
222 const struct pch_config * const config = dev->config; in pch_smbus_init()
223 struct pch_data *data = dev->data; in pch_smbus_init()
227 if (config->pcie->bdf == PCIE_BDF_NONE) { in pch_smbus_init()
229 return -ENODEV; in pch_smbus_init()
232 val = pcie_conf_read(config->pcie->bdf, PCIE_CONF_CMDSTAT); in pch_smbus_init()
238 pcie_probe_mbar(config->pcie->bdf, 0, &mbar); in pch_smbus_init()
239 pcie_set_cmd(config->pcie->bdf, PCIE_CONF_CMDSTAT_MEM, true); in pch_smbus_init()
247 pcie_set_cmd(config->pcie->bdf, PCIE_CONF_CMDSTAT_IO, true); in pch_smbus_init()
248 val = pcie_conf_read(config->pcie->bdf, PCIE_CONF_BAR4); in pch_smbus_init()
250 LOG_ERR("Cannot read IO BAR"); in pch_smbus_init()
251 return -EINVAL; in pch_smbus_init()
254 data->sba = PCIE_CONF_BAR_ADDR(val); in pch_smbus_init()
256 LOG_DBG("Using I/O address 0x%x", data->sba); in pch_smbus_init()
259 val = pcie_conf_read(config->pcie->bdf, PCH_SMBUS_HCFG); in pch_smbus_init()
262 return -EINVAL; in pch_smbus_init()
266 k_mutex_init(&data->mutex); in pch_smbus_init()
267 k_sem_init(&data->completion_sync, 0, 1); in pch_smbus_init()
269 data->dev = dev; in pch_smbus_init()
274 k_work_init(&data->smb_alert_work, smbalert_work); in pch_smbus_init()
278 k_work_init(&data->host_notify_work, host_notify_work); in pch_smbus_init()
281 config->config_func(dev); in pch_smbus_init()
285 return -EIO; in pch_smbus_init()
301 return -EBUSY; in pch_prepare_transfer()
318 struct pch_data *data = dev->data; in pch_check_status()
319 uint8_t status = data->status; in pch_check_status()
323 * - unsupported Command Field Unclaimed Cycle in pch_check_status()
324 * - Host Device timeout in pch_check_status()
325 * - CRC Error in pch_check_status()
339 return -EIO; in pch_check_status()
349 return -EAGAIN; in pch_check_status()
359 return -EIO; in pch_check_status()
366 uint8_t rw, uint8_t command, uint8_t count, in pch_smbus_block_start() argument
372 LOG_DBG("addr %x rw %d command %x", periph_addr, rw, command); in pch_smbus_block_start()
380 pch_reg_write(dev, PCH_SMBUS_HCMD, command); in pch_smbus_block_start()
382 /* Enable 32-byte buffer mode (E32b) to send block of data */ in pch_smbus_block_start()
387 /* In E32B mode read and write to PCH_SMBUS_HBD translates to in pch_smbus_block_start()
388 * read and write to 32 byte storage array, index needs to be in pch_smbus_block_start()
420 enum smbus_direction rw, uint8_t command, in pch_smbus_start() argument
426 LOG_DBG("addr 0x%02x rw %d command %x", periph_addr, rw, command); in pch_smbus_start()
433 /* Write command for every but QUICK op */ in pch_smbus_start()
436 pch_reg_write(dev, PCH_SMBUS_HCMD, command); in pch_smbus_start()
470 struct pch_data *data = dev->data; in pch_smbus_quick()
475 k_mutex_lock(&data->mutex, K_FOREVER); in pch_smbus_quick()
483 ret = k_sem_take(&data->completion_sync, K_MSEC(30)); in pch_smbus_quick()
486 ret = -ETIMEDOUT; in pch_smbus_quick()
493 k_mutex_unlock(&data->mutex); in pch_smbus_quick()
500 uint8_t command) in pch_smbus_byte_write() argument
502 struct pch_data *data = dev->data; in pch_smbus_byte_write()
505 LOG_DBG("dev %p addr 0x%02x command 0x%02x", dev, periph_addr, command); in pch_smbus_byte_write()
507 k_mutex_lock(&data->mutex, K_FOREVER); in pch_smbus_byte_write()
509 ret = pch_smbus_start(dev, periph_addr, SMBUS_MSG_WRITE, command, NULL, in pch_smbus_byte_write()
516 ret = k_sem_take(&data->completion_sync, K_MSEC(30)); in pch_smbus_byte_write()
519 ret = -ETIMEDOUT; in pch_smbus_byte_write()
526 k_mutex_unlock(&data->mutex); in pch_smbus_byte_write()
531 /* Implementation of SMBus Byte Read */
535 struct pch_data *data = dev->data; in pch_smbus_byte_read()
540 k_mutex_lock(&data->mutex, K_FOREVER); in pch_smbus_byte_read()
549 ret = k_sem_take(&data->completion_sync, K_MSEC(30)); in pch_smbus_byte_read()
551 LOG_ERR("SMBus Byte Read timed out"); in pch_smbus_byte_read()
552 ret = -ETIMEDOUT; in pch_smbus_byte_read()
564 k_mutex_unlock(&data->mutex); in pch_smbus_byte_read()
572 uint8_t command, uint8_t byte) in pch_smbus_byte_data_write() argument
574 struct pch_data *data = dev->data; in pch_smbus_byte_data_write()
577 LOG_DBG("dev %p addr 0x%02x command 0x%02x", dev, periph_addr, command); in pch_smbus_byte_data_write()
579 k_mutex_lock(&data->mutex, K_FOREVER); in pch_smbus_byte_data_write()
581 ret = pch_smbus_start(dev, periph_addr, SMBUS_MSG_WRITE, command, in pch_smbus_byte_data_write()
588 ret = k_sem_take(&data->completion_sync, K_MSEC(30)); in pch_smbus_byte_data_write()
591 ret = -ETIMEDOUT; in pch_smbus_byte_data_write()
598 k_mutex_unlock(&data->mutex); in pch_smbus_byte_data_write()
603 /* Implementation of SMBus Byte Data Read */
606 uint8_t command, uint8_t *byte) in pch_smbus_byte_data_read() argument
608 struct pch_data *data = dev->data; in pch_smbus_byte_data_read()
611 LOG_DBG("dev %p addr 0x%02x command 0x%02x", dev, periph_addr, command); in pch_smbus_byte_data_read()
613 k_mutex_lock(&data->mutex, K_FOREVER); in pch_smbus_byte_data_read()
615 ret = pch_smbus_start(dev, periph_addr, SMBUS_MSG_READ, command, in pch_smbus_byte_data_read()
622 ret = k_sem_take(&data->completion_sync, K_MSEC(30)); in pch_smbus_byte_data_read()
624 LOG_ERR("SMBus Byte Data Read timed out"); in pch_smbus_byte_data_read()
625 ret = -ETIMEDOUT; in pch_smbus_byte_data_read()
637 k_mutex_unlock(&data->mutex); in pch_smbus_byte_data_read()
645 uint8_t command, uint16_t word) in pch_smbus_word_data_write() argument
647 struct pch_data *data = dev->data; in pch_smbus_word_data_write()
650 LOG_DBG("dev %p addr 0x%02x command 0x%02x", dev, periph_addr, command); in pch_smbus_word_data_write()
652 k_mutex_lock(&data->mutex, K_FOREVER); in pch_smbus_word_data_write()
654 ret = pch_smbus_start(dev, periph_addr, SMBUS_MSG_WRITE, command, in pch_smbus_word_data_write()
661 ret = k_sem_take(&data->completion_sync, K_MSEC(30)); in pch_smbus_word_data_write()
664 ret = -ETIMEDOUT; in pch_smbus_word_data_write()
671 k_mutex_unlock(&data->mutex); in pch_smbus_word_data_write()
676 /* Implementation of SMBus Word Data Read */
679 uint8_t command, uint16_t *word) in pch_smbus_word_data_read() argument
681 struct pch_data *data = dev->data; in pch_smbus_word_data_read()
685 LOG_DBG("dev %p addr 0x%02x command 0x%02x", dev, periph_addr, command); in pch_smbus_word_data_read()
687 k_mutex_lock(&data->mutex, K_FOREVER); in pch_smbus_word_data_read()
689 ret = pch_smbus_start(dev, periph_addr, SMBUS_MSG_READ, command, in pch_smbus_word_data_read()
696 ret = k_sem_take(&data->completion_sync, K_MSEC(30)); in pch_smbus_word_data_read()
698 LOG_ERR("SMBus Word Data Read timed out"); in pch_smbus_word_data_read()
699 ret = -ETIMEDOUT; in pch_smbus_word_data_read()
712 k_mutex_unlock(&data->mutex); in pch_smbus_word_data_read()
719 uint16_t periph_addr, uint8_t command, in pch_smbus_pcall() argument
722 struct pch_data *data = dev->data; in pch_smbus_pcall()
726 LOG_DBG("dev %p addr 0x%02x command 0x%02x", dev, periph_addr, command); in pch_smbus_pcall()
728 k_mutex_lock(&data->mutex, K_FOREVER); in pch_smbus_pcall()
730 ret = pch_smbus_start(dev, periph_addr, SMBUS_MSG_WRITE, command, in pch_smbus_pcall()
737 ret = k_sem_take(&data->completion_sync, K_MSEC(30)); in pch_smbus_pcall()
740 ret = -ETIMEDOUT; in pch_smbus_pcall()
753 k_mutex_unlock(&data->mutex); in pch_smbus_pcall()
760 uint8_t command, uint8_t count, uint8_t *buf) in pch_smbus_block_write() argument
762 struct pch_data *data = dev->data; in pch_smbus_block_write()
765 LOG_DBG("dev %p addr 0x%02x command 0x%02x count %u", in pch_smbus_block_write()
766 dev, periph_addr, command, count); in pch_smbus_block_write()
768 k_mutex_lock(&data->mutex, K_FOREVER); in pch_smbus_block_write()
770 ret = pch_smbus_block_start(dev, periph_addr, SMBUS_MSG_WRITE, command, in pch_smbus_block_write()
777 ret = k_sem_take(&data->completion_sync, K_MSEC(30)); in pch_smbus_block_write()
780 ret = -ETIMEDOUT; in pch_smbus_block_write()
787 k_mutex_unlock(&data->mutex); in pch_smbus_block_write()
792 /* Implementation of SMBus Block Read */
794 uint8_t command, uint8_t *count, uint8_t *buf) in pch_smbus_block_read() argument
796 struct pch_data *data = dev->data; in pch_smbus_block_read()
799 LOG_DBG("dev %p addr 0x%02x command 0x%02x", in pch_smbus_block_read()
800 dev, periph_addr, command); in pch_smbus_block_read()
802 k_mutex_lock(&data->mutex, K_FOREVER); in pch_smbus_block_read()
804 ret = pch_smbus_block_start(dev, periph_addr, SMBUS_MSG_READ, command, in pch_smbus_block_read()
811 ret = k_sem_take(&data->completion_sync, K_MSEC(30)); in pch_smbus_block_read()
813 LOG_ERR("SMBus Block Read timed out"); in pch_smbus_block_read()
814 ret = -ETIMEDOUT; in pch_smbus_block_read()
825 ret = -ENODATA; in pch_smbus_block_read()
834 k_mutex_unlock(&data->mutex); in pch_smbus_block_read()
841 uint16_t periph_addr, uint8_t command, in pch_smbus_block_pcall() argument
845 struct pch_data *data = dev->data; in pch_smbus_block_pcall()
848 LOG_DBG("dev %p addr 0x%02x command 0x%02x", in pch_smbus_block_pcall()
849 dev, periph_addr, command); in pch_smbus_block_pcall()
851 k_mutex_lock(&data->mutex, K_FOREVER); in pch_smbus_block_pcall()
853 ret = pch_smbus_block_start(dev, periph_addr, SMBUS_MSG_WRITE, command, in pch_smbus_block_pcall()
860 ret = k_sem_take(&data->completion_sync, K_MSEC(30)); in pch_smbus_block_pcall()
863 ret = -ETIMEDOUT; in pch_smbus_block_pcall()
875 ret = -ENODATA; in pch_smbus_block_pcall()
884 k_mutex_unlock(&data->mutex); in pch_smbus_block_pcall()
915 const struct pch_config * const config = dev->config; in smbus_isr()
916 struct pch_data *data = dev->data; in smbus_isr()
920 sts = pcie_conf_read(config->pcie->bdf, PCIE_CONF_CMDSTAT); in smbus_isr()
927 * Handle first Host Notify since for that we need to read SSTS in smbus_isr()
933 if (data->config & SMBUS_MODE_HOST_NOTIFY) { in smbus_isr()
937 data->notify_addr = in smbus_isr()
941 data->notify_data = pch_reg_read(dev, PCH_SMBUS_NDLB); in smbus_isr()
942 data->notify_data |= in smbus_isr()
945 k_work_submit(&data->host_notify_work); in smbus_isr()
966 if (data->config & SMBUS_MODE_SMBALERT && in smbus_isr()
968 k_work_submit(&data->smb_alert_work); in smbus_isr()
975 data->status = status; in smbus_isr()
977 k_sem_give(&data->completion_sync); in smbus_isr()
992 const struct pch_config * const config = dev->config; \
995 irq = pcie_alloc_irq(config->pcie->bdf); \
1001 pcie_conf_write(config->pcie->bdf, \
1004 pcie_connect_dynamic_irq(config->pcie->bdf, irq, \
1009 pcie_irq_enable(config->pcie->bdf, irq); \