Skip to content

Commit ca83d29

Browse files
Tooraj TarazMingcongBai
authored andcommitted
BACKPORT: SURFACE: Add camera support for Surface Pro 9
Experimental camera support for the Surface Pro 9. Link: linux-surface/linux-surface#1867 Patchset: cameras [ Mingcong Bai: Since commit 2a7b765 ("platform/x86: int3472: Handle GPIO type 0x10 (DOVDD)") took the 0x10 entry used by the original patch for Surface Pro 9's secondary power rail, change the latter to 0x11 to adapt to this change. Link: linux-surface/linux-surface#2057 Link: linux-surface/linux-surface#2079 ] Link: https://github.com/linux-surface/linux-surface/tree/4c136ec928ce0b458562c7533852db67a8e0dc91 Signed-off-by: Mingcong Bai <[email protected]>
1 parent 53f9f3d commit ca83d29

4 files changed

Lines changed: 184 additions & 2 deletions

File tree

‎drivers/media/i2c/ov13858.c‎

Lines changed: 156 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Copyright (c) 2017 Intel Corporation.
33

44
#include <linux/acpi.h>
5+
#include <linux/delay.h>
56
#include <linux/clk.h>
67
#include <linux/i2c.h>
78
#include <linux/module.h>
@@ -119,6 +120,14 @@ struct ov13858_mode {
119120
struct ov13858_reg_list reg_list;
120121
};
121122

123+
// Or use standard names that might be more correct:
124+
static const char * const ov13858_supply_names[] = {
125+
"avdd", // Analog voltage
126+
"pwr1", // Digital core voltage
127+
};
128+
129+
#define OV13858_NUM_SUPPLIES ARRAY_SIZE(ov13858_supply_names)
130+
122131
/* 4224x3136 needs 1080Mbps/lane, 4 lanes */
123132
static const struct ov13858_reg mipi_data_rate_1080mbps[] = {
124133
/* PLL1 registers */
@@ -1046,12 +1055,126 @@ struct ov13858 {
10461055
/* Current mode */
10471056
const struct ov13858_mode *cur_mode;
10481057

1058+
struct regulator_bulk_data supplies[OV13858_NUM_SUPPLIES];
1059+
struct gpio_desc *reset;
1060+
struct clk *xvclk;
1061+
10491062
/* Mutex for serialized access */
10501063
struct mutex mutex;
10511064
};
10521065

10531066
#define to_ov13858(_sd) container_of(_sd, struct ov13858, sd)
10541067

1068+
1069+
static int ov13858_get_regulators(struct ov13858 *ov13858)
1070+
{
1071+
unsigned int i;
1072+
1073+
for (i = 0; i < OV13858_NUM_SUPPLIES; i++)
1074+
ov13858->supplies[i].supply = ov13858_supply_names[i];
1075+
1076+
return devm_regulator_bulk_get(ov13858->dev, OV13858_NUM_SUPPLIES,
1077+
ov13858->supplies);
1078+
}
1079+
1080+
static int ov13858_sensor_powerup(struct ov13858 *ov13858)
1081+
{
1082+
int ret;
1083+
1084+
dev_info(ov13858->dev, "Powering up sensor\n");
1085+
1086+
/* Assert reset */
1087+
gpiod_set_value_cansleep(ov13858->reset, 1);
1088+
1089+
/* Enable clock FIRST - sensor needs clock to communicate */
1090+
ret = clk_prepare_enable(ov13858->xvclk);
1091+
if (ret) {
1092+
dev_err(ov13858->dev, "Failed to enable clock: %d\n", ret);
1093+
return ret;
1094+
}
1095+
dev_info(ov13858->dev, "Clock enabled\n");
1096+
1097+
/* Enable regulators */
1098+
ret = regulator_bulk_enable(OV13858_NUM_SUPPLIES, ov13858->supplies);
1099+
if (ret) {
1100+
dev_err(ov13858->dev, "Failed to enable regulators: %d\n", ret);
1101+
clk_disable_unprepare(ov13858->xvclk);
1102+
return ret;
1103+
}
1104+
1105+
dev_info(ov13858->dev, "Regulators enabled\n");
1106+
1107+
/* Wait for power to stabilize */
1108+
usleep_range(5000, 10000);
1109+
1110+
/* De-assert reset */
1111+
gpiod_set_value_cansleep(ov13858->reset, 0);
1112+
1113+
/* Wait for sensor to boot */
1114+
msleep(20);
1115+
1116+
dev_info(ov13858->dev, "Reset de-asserted, sensor should be ready\n");
1117+
1118+
return 0;
1119+
}
1120+
1121+
static void ov13858_sensor_powerdown(struct ov13858 *ov13858)
1122+
{
1123+
dev_info(ov13858->dev, "Powering down sensor\n");
1124+
1125+
/* Assert reset to put sensor in reset state */
1126+
gpiod_set_value_cansleep(ov13858->reset, 1);
1127+
1128+
/* Disable regulators */
1129+
regulator_bulk_disable(OV13858_NUM_SUPPLIES, ov13858->supplies);
1130+
dev_info(ov13858->dev, "Regulators disabled\n");
1131+
1132+
/* Disable clock */
1133+
clk_disable_unprepare(ov13858->xvclk);
1134+
dev_info(ov13858->dev, "Clock disabled\n");
1135+
}
1136+
1137+
static int __maybe_unused ov13858_suspend(struct device *dev)
1138+
{
1139+
struct i2c_client *client = to_i2c_client(dev);
1140+
struct v4l2_subdev *sd = i2c_get_clientdata(client);
1141+
struct ov13858 *ov13858 = to_ov13858(sd);
1142+
1143+
ov13858_sensor_powerdown(ov13858);
1144+
1145+
return 0;
1146+
}
1147+
1148+
static int __maybe_unused ov13858_resume(struct device *dev)
1149+
{
1150+
struct i2c_client *client = to_i2c_client(dev);
1151+
struct v4l2_subdev *sd = i2c_get_clientdata(client);
1152+
struct ov13858 *ov13858 = to_ov13858(sd);
1153+
int ret;
1154+
1155+
ret = ov13858_sensor_powerup(ov13858);
1156+
if (ret)
1157+
return ret;
1158+
1159+
return 0;
1160+
}
1161+
1162+
static const struct dev_pm_ops ov13858_pm_ops = {
1163+
SET_RUNTIME_PM_OPS(ov13858_suspend, ov13858_resume, NULL)
1164+
};
1165+
1166+
static int ov13858_get_gpios(struct ov13858 *ov13858)
1167+
{
1168+
ov13858->reset = devm_gpiod_get_optional(ov13858->dev, "reset",
1169+
GPIOD_OUT_HIGH);
1170+
if (IS_ERR(ov13858->reset)) {
1171+
dev_err(ov13858->dev, "Error fetching reset GPIO\n");
1172+
return PTR_ERR(ov13858->reset);
1173+
}
1174+
1175+
return 0;
1176+
}
1177+
10551178
/* Read registers up to 4 at a time */
10561179
static int ov13858_read_reg(struct ov13858 *ov13858, u16 reg, u32 len,
10571180
u32 *val)
@@ -1498,8 +1621,11 @@ static int ov13858_identify_module(struct ov13858 *ov13858)
14981621
int ret;
14991622
u32 val;
15001623

1624+
dev_info(ov13858->dev, "Attempting to read chip ID from register 0x300a\n");
15011625
ret = ov13858_read_reg(ov13858, OV13858_REG_CHIP_ID,
15021626
OV13858_REG_VALUE_24BIT, &val);
1627+
dev_info(ov13858->dev, "Chip ID read result: ret=%d, val=0x%06x (expected 0x%06x)\n",
1628+
ret, val, OV13858_CHIP_ID);
15031629
if (ret)
15041630
return ret;
15051631

@@ -1509,6 +1635,7 @@ static int ov13858_identify_module(struct ov13858 *ov13858)
15091635
return -EIO;
15101636
}
15111637

1638+
dev_info(ov13858->dev, "Chip ID verified successfully!\n");
15121639
return 0;
15131640
}
15141641

@@ -1678,22 +1805,41 @@ static int ov13858_probe(struct i2c_client *client)
16781805
"external clock %lu is not supported\n",
16791806
freq);
16801807

1808+
/* Get the external clock */
1809+
ov13858->xvclk = devm_clk_get_optional(ov13858->dev, "xvclk");
1810+
if (IS_ERR(ov13858->xvclk))
1811+
return dev_err_probe(ov13858->dev, PTR_ERR(ov13858->xvclk),
1812+
"failed to get xvclk\n");
1813+
16811814
/* Initialize subdev */
16821815
v4l2_i2c_subdev_init(&ov13858->sd, client, &ov13858_subdev_ops);
16831816

1817+
ret = ov13858_get_regulators(ov13858);
1818+
if (ret)
1819+
return dev_err_probe(ov13858->dev, ret,
1820+
"Error fetching regulators\n");
1821+
1822+
ret = ov13858_get_gpios(ov13858);
1823+
if (ret)
1824+
return ret;
1825+
1826+
ret = ov13858_sensor_powerup(ov13858);
1827+
if (ret)
1828+
return ret; // No cleanup needed yet, devm handles GPIOs/regulators
1829+
16841830
/* Check module identity */
16851831
ret = ov13858_identify_module(ov13858);
16861832
if (ret) {
16871833
dev_err(ov13858->dev, "failed to find sensor: %d\n", ret);
1688-
return ret;
1834+
goto error_power_off; // Now we need to power down
16891835
}
16901836

16911837
/* Set default mode to max resolution */
16921838
ov13858->cur_mode = &supported_modes[0];
16931839

16941840
ret = ov13858_init_controls(ov13858);
16951841
if (ret)
1696-
return ret;
1842+
goto error_power_off;
16971843

16981844
/* Initialize subdev */
16991845
ov13858->sd.internal_ops = &ov13858_internal_ops;
@@ -1729,6 +1875,10 @@ static int ov13858_probe(struct i2c_client *client)
17291875

17301876
error_handler_free:
17311877
ov13858_free_controls(ov13858);
1878+
1879+
error_power_off:
1880+
ov13858_sensor_powerdown(ov13858);
1881+
17321882
dev_err(ov13858->dev, "%s failed:%d\n", __func__, ret);
17331883

17341884
return ret;
@@ -1744,6 +1894,9 @@ static void ov13858_remove(struct i2c_client *client)
17441894
ov13858_free_controls(ov13858);
17451895

17461896
pm_runtime_disable(ov13858->dev);
1897+
if (!pm_runtime_status_suspended(ov13858->dev))
1898+
ov13858_sensor_powerdown(ov13858);
1899+
pm_runtime_set_suspended(ov13858->dev);
17471900
}
17481901

17491902
static const struct i2c_device_id ov13858_id_table[] = {
@@ -1765,6 +1918,7 @@ MODULE_DEVICE_TABLE(acpi, ov13858_acpi_ids);
17651918
static struct i2c_driver ov13858_i2c_driver = {
17661919
.driver = {
17671920
.name = "ov13858",
1921+
.pm = &ov13858_pm_ops,
17681922
.acpi_match_table = ACPI_PTR(ov13858_acpi_ids),
17691923
},
17701924
.probe = ov13858_probe,

‎drivers/media/i2c/ov5693.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,6 +1396,7 @@ static const struct dev_pm_ops ov5693_pm_ops = {
13961396

13971397
static const struct acpi_device_id ov5693_acpi_match[] = {
13981398
{"INT33BE"},
1399+
{"OVTI5693"},
13991400
{},
14001401
};
14011402
MODULE_DEVICE_TABLE(acpi, ov5693_acpi_match);

‎drivers/media/pci/intel/ipu-bridge.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ static const struct ipu_sensor_config ipu_supported_sensors[] = {
6161
IPU_SENSOR_CONFIG("INT33BE", 1, 419200000),
6262
/* Onsemi MT9M114 */
6363
IPU_SENSOR_CONFIG("INT33F0", 1, 384000000),
64+
/* Omnivision OV5693 - Surface Pro 9 */
65+
IPU_SENSOR_CONFIG("OVTI5693", 1, 419200000),
66+
/* Omnivision OV13858 - Surface Pro 9 */
67+
IPU_SENSOR_CONFIG("OVTID858", 4, 540000000),
6468
/* Omnivision OV2740 */
6569
IPU_SENSOR_CONFIG("INT3474", 1, 180000000),
6670
/* Omnivision OV5670 */

‎drivers/platform/x86/intel/int3472/discrete.c‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,14 @@ static void int3472_get_con_id_and_polarity(struct int3472_discrete_device *int3
233233
/* Setups using a handshake pin need 25 ms enable delay */
234234
*enable_time_us = 25 * USEC_PER_MSEC;
235235
break;
236+
case 0x08: /* Surface Pro 9 - additional power rail */
237+
*con_id = "pwr1";
238+
*gpio_flags = GPIO_ACTIVE_HIGH;
239+
break;
240+
case 0x11: /* Surface Pro 9 - secondary power rail */
241+
*con_id = "pwr2";
242+
*gpio_flags = GPIO_ACTIVE_HIGH;
243+
break;
236244
default:
237245
*con_id = "unknown";
238246
*gpio_flags = GPIO_ACTIVE_HIGH;
@@ -339,6 +347,8 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,
339347
case INT3472_GPIO_TYPE_POWER_ENABLE:
340348
case INT3472_GPIO_TYPE_DOVDD:
341349
case INT3472_GPIO_TYPE_HANDSHAKE:
350+
case 0x08: /* Surface Pro 9 power rails */
351+
case 0x11:
342352
gpio = skl_int3472_gpiod_get_from_temp_lookup(int3472, agpio, con_id, gpio_flags);
343353
if (IS_ERR(gpio)) {
344354
ret = PTR_ERR(gpio);
@@ -370,6 +380,19 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,
370380
err_msg = "Failed to register regulator\n";
371381

372382
break;
383+
case 0x08: /* Surface Pro 9 - treat as power*/
384+
dev_info(int3472->dev, "GPIO type 0x%02x detected on pin 0x%02x\n", type, agpio->pin_table[0]);
385+
dev_info(int3472->dev, " con_id=%s, flags=0x%x\n", con_id, gpio_flags);
386+
ret = skl_int3472_register_regulator(int3472, gpio,
387+
GPIO_REGULATOR_ENABLE_TIME,
388+
con_id, NULL);
389+
dev_info(int3472->dev, " register_regulator returned: %d\n", ret);
390+
if (ret) {
391+
dev_err(int3472->dev, "Failed to register type 0x02x: %d\n", type, ret);
392+
}
393+
break;
394+
case 0x11:
395+
break;
373396
default: /* Never reached */
374397
ret = -EINVAL;
375398
break;

0 commit comments

Comments
 (0)