Lines Matching +full:i2c +full:- +full:command
3 * SPDX-License-Identifier: Apache-2.0
8 #include <zephyr/drivers/i2c.h>
9 #include <zephyr/drivers/i2c/stm32.h>
37 struct smbus_stm32_data *data = dev->data; in smbus_stm32_smbalert_isr()
39 k_work_submit(&data->smbalert_work); in smbus_stm32_smbalert_isr()
45 const struct device *dev = data->dev; in smbus_stm32_smbalert_work()
47 LOG_DBG("%s: got SMB alert", dev->name); in smbus_stm32_smbalert_work()
49 smbus_loop_alert_devices(dev, &data->smbalert_callbacks); in smbus_stm32_smbalert_work()
54 struct smbus_stm32_data *data = dev->data; in smbus_stm32_smbalert_set_cb()
56 return smbus_callback_set(&data->smbalert_callbacks, cb); in smbus_stm32_smbalert_set_cb()
61 struct smbus_stm32_data *data = dev->data; in smbus_stm32_smbalert_remove_cb()
63 return smbus_callback_remove(&data->smbalert_callbacks, cb); in smbus_stm32_smbalert_remove_cb()
69 const struct smbus_stm32_config *config = dev->config; in smbus_stm32_init()
70 struct smbus_stm32_data *data = dev->data; in smbus_stm32_init()
73 data->dev = dev; in smbus_stm32_init()
75 if (!device_is_ready(config->i2c_dev)) { in smbus_stm32_init()
76 LOG_ERR("%s: I2C device is not ready", dev->name); in smbus_stm32_init()
77 return -ENODEV; in smbus_stm32_init()
80 result = pinctrl_apply_state(config->pcfg, PINCTRL_STATE_DEFAULT); in smbus_stm32_init()
82 LOG_ERR("%s: pinctrl setup failed (%d)", dev->name, result); in smbus_stm32_init()
87 k_work_init(&data->smbalert_work, smbus_stm32_smbalert_work); in smbus_stm32_init()
89 i2c_stm32_smbalert_set_callback(config->i2c_dev, smbus_stm32_smbalert_isr, dev); in smbus_stm32_init()
97 const struct smbus_stm32_config *config = dev->config; in smbus_stm32_configure()
98 struct smbus_stm32_data *data = dev->data; in smbus_stm32_configure()
101 LOG_ERR("%s: not implemented", dev->name); in smbus_stm32_configure()
102 return -EINVAL; in smbus_stm32_configure()
106 LOG_ERR("%s: not available", dev->name); in smbus_stm32_configure()
107 return -EINVAL; in smbus_stm32_configure()
111 LOG_DBG("%s: configuring SMB in host mode", dev->name); in smbus_stm32_configure()
112 i2c_stm32_set_smbus_mode(config->i2c_dev, I2CSTM32MODE_SMBUSHOST); in smbus_stm32_configure()
114 LOG_DBG("%s: configuring SMB in device mode", dev->name); in smbus_stm32_configure()
115 i2c_stm32_set_smbus_mode(config->i2c_dev, I2CSTM32MODE_SMBUSDEVICE); in smbus_stm32_configure()
119 LOG_DBG("%s: activating SMB alert", dev->name); in smbus_stm32_configure()
120 i2c_stm32_smbalert_enable(config->i2c_dev); in smbus_stm32_configure()
122 LOG_DBG("%s: deactivating SMB alert", dev->name); in smbus_stm32_configure()
123 i2c_stm32_smbalert_disable(config->i2c_dev); in smbus_stm32_configure()
126 data->config = config_value; in smbus_stm32_configure()
132 struct smbus_stm32_data *data = dev->data; in smbus_stm32_get_config()
133 *config = data->config; in smbus_stm32_get_config()
140 const struct smbus_stm32_config *config = dev->config; in smbus_stm32_quick()
144 return i2c_write(config->i2c_dev, NULL, 0, periph_addr); in smbus_stm32_quick()
146 return i2c_read(config->i2c_dev, NULL, 0, periph_addr); in smbus_stm32_quick()
148 LOG_ERR("%s: invalid smbus direction %i", dev->name, rw); in smbus_stm32_quick()
149 return -EINVAL; in smbus_stm32_quick()
153 static int smbus_stm32_byte_write(const struct device *dev, uint16_t periph_addr, uint8_t command) in smbus_stm32_byte_write() argument
155 const struct smbus_stm32_config *config = dev->config; in smbus_stm32_byte_write()
157 return i2c_write(config->i2c_dev, &command, sizeof(command), periph_addr); in smbus_stm32_byte_write()
162 const struct smbus_stm32_config *config = dev->config; in smbus_stm32_byte_read()
164 return i2c_read(config->i2c_dev, byte, sizeof(*byte), periph_addr); in smbus_stm32_byte_read()
168 uint8_t command, uint8_t byte) in smbus_stm32_byte_data_write() argument
170 const struct smbus_stm32_config *config = dev->config; in smbus_stm32_byte_data_write()
172 command, in smbus_stm32_byte_data_write()
176 return i2c_write(config->i2c_dev, buffer, ARRAY_SIZE(buffer), periph_addr); in smbus_stm32_byte_data_write()
180 uint8_t command, uint8_t *byte) in smbus_stm32_byte_data_read() argument
182 const struct smbus_stm32_config *config = dev->config; in smbus_stm32_byte_data_read()
184 return i2c_write_read(config->i2c_dev, periph_addr, &command, sizeof(command), byte, in smbus_stm32_byte_data_read()
189 uint8_t command, uint16_t word) in smbus_stm32_word_data_write() argument
191 const struct smbus_stm32_config *config = dev->config; in smbus_stm32_word_data_write()
192 uint8_t buffer[sizeof(command) + sizeof(word)]; in smbus_stm32_word_data_write()
194 buffer[0] = command; in smbus_stm32_word_data_write()
197 return i2c_write(config->i2c_dev, buffer, ARRAY_SIZE(buffer), periph_addr); in smbus_stm32_word_data_write()
201 uint8_t command, uint16_t *word) in smbus_stm32_word_data_read() argument
203 const struct smbus_stm32_config *config = dev->config; in smbus_stm32_word_data_read()
206 result = i2c_write_read(config->i2c_dev, periph_addr, &command, sizeof(command), word, in smbus_stm32_word_data_read()
213 static int smbus_stm32_pcall(const struct device *dev, uint16_t periph_addr, uint8_t command, in smbus_stm32_pcall() argument
216 const struct smbus_stm32_config *config = dev->config; in smbus_stm32_pcall()
217 uint8_t buffer[sizeof(command) + sizeof(send_word)]; in smbus_stm32_pcall()
220 buffer[0] = command; in smbus_stm32_pcall()
223 result = i2c_write_read(config->i2c_dev, periph_addr, buffer, ARRAY_SIZE(buffer), recv_word, in smbus_stm32_pcall()
230 static int smbus_stm32_block_write(const struct device *dev, uint16_t periph_addr, uint8_t command, in smbus_stm32_block_write() argument
233 const struct smbus_stm32_config *config = dev->config; in smbus_stm32_block_write()
236 .buf = &command, in smbus_stm32_block_write()
237 .len = sizeof(command), in smbus_stm32_block_write()
247 return i2c_transfer(config->i2c_dev, messages, ARRAY_SIZE(messages), periph_addr); in smbus_stm32_block_write()
280 .i2c_dev = DEVICE_DT_GET(DT_INST_PROP(n, i2c)), \