hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/media/i2c/adv7604.c
....@@ -27,6 +27,7 @@
2727 #include <linux/videodev2.h>
2828 #include <linux/workqueue.h>
2929 #include <linux/regmap.h>
30
+#include <linux/interrupt.h>
3031
3132 #include <media/i2c/adv7604.h>
3233 #include <media/cec.h>
....@@ -113,6 +114,11 @@
113114 unsigned int tdms_lock_mask;
114115 unsigned int fmt_change_digital_mask;
115116 unsigned int cp_csc;
117
+
118
+ unsigned int cec_irq_status;
119
+ unsigned int cec_rx_enable;
120
+ unsigned int cec_rx_enable_mask;
121
+ bool cec_irq_swap;
116122
117123 const struct adv76xx_format_info *formats;
118124 unsigned int nformats;
....@@ -1497,23 +1503,14 @@
14971503
14981504 static unsigned int adv7604_read_hdmi_pixelclock(struct v4l2_subdev *sd)
14991505 {
1500
- unsigned int freq;
15011506 int a, b;
15021507
15031508 a = hdmi_read(sd, 0x06);
15041509 b = hdmi_read(sd, 0x3b);
15051510 if (a < 0 || b < 0)
15061511 return 0;
1507
- freq = a * 1000000 + ((b & 0x30) >> 4) * 250000;
15081512
1509
- if (is_hdmi(sd)) {
1510
- /* adjust for deep color mode */
1511
- unsigned bits_per_channel = ((hdmi_read(sd, 0x0b) & 0x60) >> 4) + 8;
1512
-
1513
- freq = freq * 8 / bits_per_channel;
1514
- }
1515
-
1516
- return freq;
1513
+ return a * 1000000 + ((b & 0x30) >> 4) * 250000;
15171514 }
15181515
15191516 static unsigned int adv7611_read_hdmi_pixelclock(struct v4l2_subdev *sd)
....@@ -1524,7 +1521,26 @@
15241521 b = hdmi_read(sd, 0x52);
15251522 if (a < 0 || b < 0)
15261523 return 0;
1524
+
15271525 return ((a << 1) | (b >> 7)) * 1000000 + (b & 0x7f) * 1000000 / 128;
1526
+}
1527
+
1528
+static unsigned int adv76xx_read_hdmi_pixelclock(struct v4l2_subdev *sd)
1529
+{
1530
+ struct adv76xx_state *state = to_state(sd);
1531
+ const struct adv76xx_chip_info *info = state->info;
1532
+ unsigned int freq, bits_per_channel, pixelrepetition;
1533
+
1534
+ freq = info->read_hdmi_pixelclock(sd);
1535
+ if (is_hdmi(sd)) {
1536
+ /* adjust for deep color mode and pixel repetition */
1537
+ bits_per_channel = ((hdmi_read(sd, 0x0b) & 0x60) >> 4) + 8;
1538
+ pixelrepetition = (hdmi_read(sd, 0x05) & 0x0f) + 1;
1539
+
1540
+ freq = freq * 8 / bits_per_channel / pixelrepetition;
1541
+ }
1542
+
1543
+ return freq;
15281544 }
15291545
15301546 static int adv76xx_query_dv_timings(struct v4l2_subdev *sd,
....@@ -1573,7 +1589,7 @@
15731589
15741590 bt->width = w;
15751591 bt->height = h;
1576
- bt->pixelclock = info->read_hdmi_pixelclock(sd);
1592
+ bt->pixelclock = adv76xx_read_hdmi_pixelclock(sd);
15771593 bt->hfrontporch = hdmi_read16(sd, 0x20, info->hfrontporch_mask);
15781594 bt->hsync = hdmi_read16(sd, 0x22, info->hsync_mask);
15791595 bt->hbackporch = hdmi_read16(sd, 0x24, info->hbackporch_mask);
....@@ -2003,10 +2019,11 @@
20032019 static void adv76xx_cec_isr(struct v4l2_subdev *sd, bool *handled)
20042020 {
20052021 struct adv76xx_state *state = to_state(sd);
2022
+ const struct adv76xx_chip_info *info = state->info;
20062023 u8 cec_irq;
20072024
20082025 /* cec controller */
2009
- cec_irq = io_read(sd, 0x4d) & 0x0f;
2026
+ cec_irq = io_read(sd, info->cec_irq_status) & 0x0f;
20102027 if (!cec_irq)
20112028 return;
20122029
....@@ -2024,15 +2041,21 @@
20242041
20252042 for (i = 0; i < msg.len; i++)
20262043 msg.msg[i] = cec_read(sd, i + 0x15);
2027
- cec_write(sd, 0x26, 0x01); /* re-enable rx */
2044
+ cec_write(sd, info->cec_rx_enable,
2045
+ info->cec_rx_enable_mask); /* re-enable rx */
20282046 cec_received_msg(state->cec_adap, &msg);
20292047 }
20302048 }
20312049
2032
- /* note: the bit order is swapped between 0x4d and 0x4e */
2033
- cec_irq = ((cec_irq & 0x08) >> 3) | ((cec_irq & 0x04) >> 1) |
2034
- ((cec_irq & 0x02) << 1) | ((cec_irq & 0x01) << 3);
2035
- io_write(sd, 0x4e, cec_irq);
2050
+ if (info->cec_irq_swap) {
2051
+ /*
2052
+ * Note: the bit order is swapped between 0x4d and 0x4e
2053
+ * on adv7604
2054
+ */
2055
+ cec_irq = ((cec_irq & 0x08) >> 3) | ((cec_irq & 0x04) >> 1) |
2056
+ ((cec_irq & 0x02) << 1) | ((cec_irq & 0x01) << 3);
2057
+ }
2058
+ io_write(sd, info->cec_irq_status + 1, cec_irq);
20362059
20372060 if (handled)
20382061 *handled = true;
....@@ -2041,6 +2064,7 @@
20412064 static int adv76xx_cec_adap_enable(struct cec_adapter *adap, bool enable)
20422065 {
20432066 struct adv76xx_state *state = cec_get_drvdata(adap);
2067
+ const struct adv76xx_chip_info *info = state->info;
20442068 struct v4l2_subdev *sd = &state->sd;
20452069
20462070 if (!state->cec_enabled_adap && enable) {
....@@ -2052,11 +2076,11 @@
20522076 /* tx: arbitration lost */
20532077 /* tx: retry timeout */
20542078 /* rx: ready */
2055
- io_write_clr_set(sd, 0x50, 0x0f, 0x0f);
2056
- cec_write(sd, 0x26, 0x01); /* enable rx */
2079
+ io_write_clr_set(sd, info->cec_irq_status + 3, 0x0f, 0x0f);
2080
+ cec_write(sd, info->cec_rx_enable, info->cec_rx_enable_mask);
20572081 } else if (state->cec_enabled_adap && !enable) {
20582082 /* disable cec interrupts */
2059
- io_write_clr_set(sd, 0x50, 0x0f, 0x00);
2083
+ io_write_clr_set(sd, info->cec_irq_status + 3, 0x0f, 0x00);
20602084 /* disable address mask 1-3 */
20612085 cec_write_clr_set(sd, 0x27, 0x70, 0x00);
20622086 /* power down cec section */
....@@ -2219,6 +2243,16 @@
22192243 *handled = true;
22202244 }
22212245 return 0;
2246
+}
2247
+
2248
+static irqreturn_t adv76xx_irq_handler(int irq, void *dev_id)
2249
+{
2250
+ struct adv76xx_state *state = dev_id;
2251
+ bool handled = false;
2252
+
2253
+ adv76xx_isr(&state->sd, 0, &handled);
2254
+
2255
+ return handled ? IRQ_HANDLED : IRQ_NONE;
22222256 }
22232257
22242258 static int adv76xx_get_edid(struct v4l2_subdev *sd, struct v4l2_edid *edid)
....@@ -2420,7 +2454,7 @@
24202454 buffer[i + 3] = infoframe_read(sd,
24212455 adv76xx_cri[index].payload_addr + i);
24222456
2423
- if (hdmi_infoframe_unpack(frame, buffer, sizeof(buffer)) < 0) {
2457
+ if (hdmi_infoframe_unpack(frame, buffer, len + 3) < 0) {
24242458 v4l2_err(sd, "%s: unpack of %s infoframe failed\n", __func__,
24252459 adv76xx_cri[index].desc);
24262460 return -ENOENT;
....@@ -2838,10 +2872,8 @@
28382872 {
28392873 unsigned int i;
28402874
2841
- for (i = 1; i < ARRAY_SIZE(state->i2c_clients); ++i) {
2842
- if (state->i2c_clients[i])
2843
- i2c_unregister_device(state->i2c_clients[i]);
2844
- }
2875
+ for (i = 1; i < ARRAY_SIZE(state->i2c_clients); ++i)
2876
+ i2c_unregister_device(state->i2c_clients[i]);
28452877 }
28462878
28472879 static struct i2c_client *adv76xx_dummy_client(struct v4l2_subdev *sd,
....@@ -2854,14 +2886,14 @@
28542886 struct i2c_client *new_client;
28552887
28562888 if (pdata && pdata->i2c_addresses[page])
2857
- new_client = i2c_new_dummy(client->adapter,
2889
+ new_client = i2c_new_dummy_device(client->adapter,
28582890 pdata->i2c_addresses[page]);
28592891 else
2860
- new_client = i2c_new_secondary_device(client,
2892
+ new_client = i2c_new_ancillary_device(client,
28612893 adv76xx_default_addresses[page].name,
28622894 adv76xx_default_addresses[page].default_addr);
28632895
2864
- if (new_client)
2896
+ if (!IS_ERR(new_client))
28652897 io_write(sd, io_reg, new_client->addr << 1);
28662898
28672899 return new_client;
....@@ -2960,6 +2992,10 @@
29602992 .cable_det_mask = 0x1e,
29612993 .fmt_change_digital_mask = 0xc1,
29622994 .cp_csc = 0xfc,
2995
+ .cec_irq_status = 0x4d,
2996
+ .cec_rx_enable = 0x26,
2997
+ .cec_rx_enable_mask = 0x01,
2998
+ .cec_irq_swap = true,
29632999 .formats = adv7604_formats,
29643000 .nformats = ARRAY_SIZE(adv7604_formats),
29653001 .set_termination = adv7604_set_termination,
....@@ -3006,6 +3042,9 @@
30063042 .cable_det_mask = 0x01,
30073043 .fmt_change_digital_mask = 0x03,
30083044 .cp_csc = 0xf4,
3045
+ .cec_irq_status = 0x93,
3046
+ .cec_rx_enable = 0x2c,
3047
+ .cec_rx_enable_mask = 0x02,
30093048 .formats = adv7611_formats,
30103049 .nformats = ARRAY_SIZE(adv7611_formats),
30113050 .set_termination = adv7611_set_termination,
....@@ -3047,6 +3086,9 @@
30473086 .cable_det_mask = 0x01,
30483087 .fmt_change_digital_mask = 0x03,
30493088 .cp_csc = 0xf4,
3089
+ .cec_irq_status = 0x93,
3090
+ .cec_rx_enable = 0x2c,
3091
+ .cec_rx_enable_mask = 0x02,
30503092 .formats = adv7612_formats,
30513093 .nformats = ARRAY_SIZE(adv7612_formats),
30523094 .set_termination = adv7611_set_termination,
....@@ -3095,7 +3137,7 @@
30953137
30963138 static int adv76xx_parse_dt(struct adv76xx_state *state)
30973139 {
3098
- struct v4l2_fwnode_endpoint bus_cfg;
3140
+ struct v4l2_fwnode_endpoint bus_cfg = { .bus_type = 0 };
30993141 struct device_node *endpoint;
31003142 struct device_node *np;
31013143 unsigned int flags;
....@@ -3134,7 +3176,7 @@
31343176 state->pdata.insert_av_codes = 1;
31353177
31363178 /* Disable the interrupt for now as no DT-based board uses it. */
3137
- state->pdata.int1_config = ADV76XX_INT1_CONFIG_DISABLED;
3179
+ state->pdata.int1_config = ADV76XX_INT1_CONFIG_ACTIVE_HIGH;
31383180
31393181 /* Hardcode the remaining platform data fields. */
31403182 state->pdata.disable_pwrdnb = 0;
....@@ -3482,15 +3524,19 @@
34823524 }
34833525
34843526 for (i = 1; i < ADV76XX_PAGE_MAX; ++i) {
3527
+ struct i2c_client *dummy_client;
3528
+
34853529 if (!(BIT(i) & state->info->page_mask))
34863530 continue;
34873531
3488
- state->i2c_clients[i] = adv76xx_dummy_client(sd, i);
3489
- if (!state->i2c_clients[i]) {
3490
- err = -EINVAL;
3532
+ dummy_client = adv76xx_dummy_client(sd, i);
3533
+ if (IS_ERR(dummy_client)) {
3534
+ err = PTR_ERR(dummy_client);
34913535 v4l2_err(sd, "failed to create i2c client %u\n", i);
34923536 goto err_i2c;
34933537 }
3538
+
3539
+ state->i2c_clients[i] = dummy_client;
34943540 }
34953541
34963542 INIT_DELAYED_WORK(&state->delayed_work_enable_hotplug,
....@@ -3517,6 +3563,16 @@
35173563 if (err)
35183564 goto err_entity;
35193565
3566
+ if (client->irq) {
3567
+ err = devm_request_threaded_irq(&client->dev,
3568
+ client->irq,
3569
+ NULL, adv76xx_irq_handler,
3570
+ IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
3571
+ client->name, state);
3572
+ if (err)
3573
+ goto err_entity;
3574
+ }
3575
+
35203576 #if IS_ENABLED(CONFIG_VIDEO_ADV7604_CEC)
35213577 state->cec_adap = cec_allocate_adapter(&adv76xx_cec_adap_ops,
35223578 state, dev_name(&client->dev),