Lines Matching +full:cec +full:- +full:clk

1 // SPDX-License-Identifier: GPL-2.0-only
3 * adv7511_cec.c - Analog Devices ADV7511/33 cec driver
11 #include <linux/clk.h>
13 #include <media/cec.h>
36 unsigned int offset = adv7511->reg_cec_offset; in adv_cec_tx_raw_status()
39 if (regmap_read(adv7511->regmap_cec, in adv_cec_tx_raw_status()
47 cec_transmit_attempt_done(adv7511->cec_adap, in adv_cec_tx_raw_status()
63 if (regmap_read(adv7511->regmap_cec, in adv_cec_tx_raw_status()
75 cec_transmit_done(adv7511->cec_adap, status, in adv_cec_tx_raw_status()
80 cec_transmit_attempt_done(adv7511->cec_adap, CEC_TX_STATUS_OK); in adv_cec_tx_raw_status()
87 unsigned int offset = adv7511->reg_cec_offset; in adv7511_cec_rx()
93 if (regmap_read(adv7511->regmap_cec, in adv7511_cec_rx()
106 regmap_read(adv7511->regmap_cec, in adv7511_cec_rx()
112 /* Toggle RX Ready Clear bit to re-enable this RX buffer */ in adv7511_cec_rx()
113 regmap_update_bits(adv7511->regmap_cec, in adv7511_cec_rx()
116 regmap_update_bits(adv7511->regmap_cec, in adv7511_cec_rx()
119 cec_received_msg(adv7511->cec_adap, &msg); in adv7511_cec_rx()
124 unsigned int offset = adv7511->reg_cec_offset; in adv7511_cec_irq_process()
132 int rx_order[3] = { -1, -1, -1 }; in adv7511_cec_irq_process()
141 if (regmap_read(adv7511->regmap_cec, in adv7511_cec_irq_process()
156 * read from in order, where -1 indicates that there are no in adv7511_cec_irq_process()
163 rx_order[timestamp - 1] = i; in adv7511_cec_irq_process()
166 /* Read CEC RX buffers in the appropriate order as prescribed above */ in adv7511_cec_irq_process()
180 unsigned int offset = adv7511->reg_cec_offset; in adv7511_cec_adap_enable()
182 if (adv7511->i2c_cec == NULL) in adv7511_cec_adap_enable()
183 return -EIO; in adv7511_cec_adap_enable()
185 if (!adv7511->cec_enabled_adap && enable) { in adv7511_cec_adap_enable()
186 /* power up cec section */ in adv7511_cec_adap_enable()
187 regmap_update_bits(adv7511->regmap_cec, in adv7511_cec_adap_enable()
190 /* non-legacy mode and clear all rx buffers */ in adv7511_cec_adap_enable()
191 regmap_write(adv7511->regmap_cec, in adv7511_cec_adap_enable()
193 regmap_write(adv7511->regmap_cec, in adv7511_cec_adap_enable()
196 regmap_update_bits(adv7511->regmap_cec, in adv7511_cec_adap_enable()
202 /* rx: ready 1-3 */ in adv7511_cec_adap_enable()
203 regmap_update_bits(adv7511->regmap, in adv7511_cec_adap_enable()
206 } else if (adv7511->cec_enabled_adap && !enable) { in adv7511_cec_adap_enable()
207 regmap_update_bits(adv7511->regmap, in adv7511_cec_adap_enable()
209 /* disable address mask 1-3 */ in adv7511_cec_adap_enable()
210 regmap_update_bits(adv7511->regmap_cec, in adv7511_cec_adap_enable()
213 /* power down cec section */ in adv7511_cec_adap_enable()
214 regmap_update_bits(adv7511->regmap_cec, in adv7511_cec_adap_enable()
217 adv7511->cec_valid_addrs = 0; in adv7511_cec_adap_enable()
219 adv7511->cec_enabled_adap = enable; in adv7511_cec_adap_enable()
226 unsigned int offset = adv7511->reg_cec_offset; in adv7511_cec_adap_log_addr()
229 if (!adv7511->cec_enabled_adap) in adv7511_cec_adap_log_addr()
230 return addr == CEC_LOG_ADDR_INVALID ? 0 : -EIO; in adv7511_cec_adap_log_addr()
233 regmap_update_bits(adv7511->regmap_cec, in adv7511_cec_adap_log_addr()
236 adv7511->cec_valid_addrs = 0; in adv7511_cec_adap_log_addr()
241 bool is_valid = adv7511->cec_valid_addrs & (1 << i); in adv7511_cec_adap_log_addr()
245 if (is_valid && adv7511->cec_addr[i] == addr) in adv7511_cec_adap_log_addr()
251 return -ENXIO; in adv7511_cec_adap_log_addr()
253 adv7511->cec_addr[i] = addr; in adv7511_cec_adap_log_addr()
254 adv7511->cec_valid_addrs |= 1 << i; in adv7511_cec_adap_log_addr()
259 regmap_update_bits(adv7511->regmap_cec, in adv7511_cec_adap_log_addr()
263 regmap_update_bits(adv7511->regmap_cec, in adv7511_cec_adap_log_addr()
269 regmap_update_bits(adv7511->regmap_cec, in adv7511_cec_adap_log_addr()
273 regmap_update_bits(adv7511->regmap_cec, in adv7511_cec_adap_log_addr()
279 regmap_update_bits(adv7511->regmap_cec, in adv7511_cec_adap_log_addr()
283 regmap_update_bits(adv7511->regmap_cec, in adv7511_cec_adap_log_addr()
295 unsigned int offset = adv7511->reg_cec_offset; in adv7511_cec_adap_transmit()
296 u8 len = msg->len; in adv7511_cec_adap_transmit()
300 * The number of retries is the number of attempts - 1, but retry in adv7511_cec_adap_transmit()
304 regmap_update_bits(adv7511->regmap_cec, in adv7511_cec_adap_transmit()
306 0x70, max(1, attempts - 1) << 4); in adv7511_cec_adap_transmit()
308 /* blocking, clear cec tx irq status */ in adv7511_cec_adap_transmit()
309 regmap_update_bits(adv7511->regmap, ADV7511_REG_INT(1), 0x38, 0x38); in adv7511_cec_adap_transmit()
313 regmap_write(adv7511->regmap_cec, in adv7511_cec_adap_transmit()
315 msg->msg[i]); in adv7511_cec_adap_transmit()
318 regmap_write(adv7511->regmap_cec, in adv7511_cec_adap_transmit()
321 regmap_write(adv7511->regmap_cec, in adv7511_cec_adap_transmit()
334 adv7511->cec_clk = devm_clk_get(dev, "cec"); in adv7511_cec_parse_dt()
335 if (IS_ERR(adv7511->cec_clk)) { in adv7511_cec_parse_dt()
336 int ret = PTR_ERR(adv7511->cec_clk); in adv7511_cec_parse_dt()
338 adv7511->cec_clk = NULL; in adv7511_cec_parse_dt()
341 clk_prepare_enable(adv7511->cec_clk); in adv7511_cec_parse_dt()
342 adv7511->cec_clk_freq = clk_get_rate(adv7511->cec_clk); in adv7511_cec_parse_dt()
348 unsigned int offset = adv7511->reg_cec_offset; in adv7511_cec_init()
354 adv7511->cec_adap = cec_allocate_adapter(&adv7511_cec_adap_ops, in adv7511_cec_init()
356 if (IS_ERR(adv7511->cec_adap)) { in adv7511_cec_init()
357 ret = PTR_ERR(adv7511->cec_adap); in adv7511_cec_init()
361 regmap_write(adv7511->regmap, ADV7511_REG_CEC_CTRL, 0); in adv7511_cec_init()
362 /* cec soft reset */ in adv7511_cec_init()
363 regmap_write(adv7511->regmap_cec, in adv7511_cec_init()
365 regmap_write(adv7511->regmap_cec, in adv7511_cec_init()
368 /* non-legacy mode - use all three RX buffers */ in adv7511_cec_init()
369 regmap_write(adv7511->regmap_cec, in adv7511_cec_init()
372 regmap_write(adv7511->regmap_cec, in adv7511_cec_init()
374 ((adv7511->cec_clk_freq / 750000) - 1) << 2); in adv7511_cec_init()
376 ret = cec_register_adapter(adv7511->cec_adap, dev); in adv7511_cec_init()
382 cec_delete_adapter(adv7511->cec_adap); in adv7511_cec_init()
383 adv7511->cec_adap = NULL; in adv7511_cec_init()
385 dev_info(dev, "Initializing CEC failed with error %d, disabling CEC\n", in adv7511_cec_init()
388 regmap_write(adv7511->regmap, ADV7511_REG_CEC_CTRL, in adv7511_cec_init()
390 return ret == -EPROBE_DEFER ? ret : 0; in adv7511_cec_init()