Skip to content

Commit 941e1d3

Browse files
Sakari Ailusmchehab
authored andcommitted
media: smiapp: Support probing NVM size
The interface supports probing for the NVM size but this was not implemented in the driver. Do that now. This will also make nokia,nvm-size property redundant. Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
1 parent 23fc92f commit 941e1d3

3 files changed

Lines changed: 50 additions & 57 deletions

File tree

‎drivers/media/i2c/smiapp/smiapp-core.c‎

Lines changed: 50 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -971,10 +971,14 @@ static int smiapp_update_mode(struct smiapp_sensor *sensor)
971971
*
972972
*/
973973

974-
static int smiapp_read_nvm_page(struct smiapp_sensor *sensor, u32 p, u8 *nvm)
974+
static int smiapp_read_nvm_page(struct smiapp_sensor *sensor, u32 p, u8 *nvm,
975+
u8 *status)
975976
{
976977
unsigned int i;
977978
int rval;
979+
u32 s;
980+
981+
*status = 0;
978982

979983
rval = smiapp_write(sensor,
980984
SMIAPP_REG_U8_DATA_TRANSFER_IF_1_PAGE_SELECT, p);
@@ -986,10 +990,21 @@ static int smiapp_read_nvm_page(struct smiapp_sensor *sensor, u32 p, u8 *nvm)
986990
if (rval)
987991
return rval;
988992

993+
rval = smiapp_read(sensor, SMIAPP_REG_U8_DATA_TRANSFER_IF_1_STATUS,
994+
&s);
995+
if (rval)
996+
return rval;
997+
998+
if (s & SMIAPP_DATA_TRANSFER_IF_1_STATUS_EUSAGE) {
999+
*status = s;
1000+
return -ENODATA;
1001+
}
1002+
9891003
if (sensor->limits[SMIAPP_LIMIT_DATA_TRANSFER_IF_CAPABILITY] &
9901004
SMIAPP_DATA_TRANSFER_IF_CAPABILITY_POLL) {
9911005
for (i = 1000; i > 0; i--) {
992-
u32 s;
1006+
if (s & SMIAPP_DATA_TRANSFER_IF_1_STATUS_RD_READY)
1007+
break;
9931008

9941009
rval = smiapp_read(
9951010
sensor,
@@ -998,10 +1013,6 @@ static int smiapp_read_nvm_page(struct smiapp_sensor *sensor, u32 p, u8 *nvm)
9981013

9991014
if (rval)
10001015
return rval;
1001-
1002-
if (s & SMIAPP_DATA_TRANSFER_IF_1_STATUS_RD_READY)
1003-
break;
1004-
10051016
}
10061017

10071018
if (!i)
@@ -1023,23 +1034,27 @@ static int smiapp_read_nvm_page(struct smiapp_sensor *sensor, u32 p, u8 *nvm)
10231034
return 0;
10241035
}
10251036

1026-
static int smiapp_read_nvm(struct smiapp_sensor *sensor,
1027-
unsigned char *nvm)
1037+
static int smiapp_read_nvm(struct smiapp_sensor *sensor, unsigned char *nvm,
1038+
size_t nvm_size)
10281039
{
1029-
u32 p, np;
1040+
u8 status = 0;
1041+
u32 p;
10301042
int rval = 0, rval2;
10311043

1032-
np = sensor->nvm_size / SMIAPP_NVM_PAGE_SIZE;
1033-
for (p = 0; p < np && !rval; p++) {
1034-
rval = smiapp_read_nvm_page(sensor, p, nvm);
1044+
for (p = 0; p < nvm_size / SMIAPP_NVM_PAGE_SIZE && !rval; p++) {
1045+
rval = smiapp_read_nvm_page(sensor, p, nvm, &status);
10351046
nvm += SMIAPP_NVM_PAGE_SIZE;
10361047
}
10371048

1049+
if (rval == -ENODATA &&
1050+
status & SMIAPP_DATA_TRANSFER_IF_1_STATUS_EUSAGE)
1051+
rval = 0;
1052+
10381053
rval2 = smiapp_write(sensor, SMIAPP_REG_U8_DATA_TRANSFER_IF_1_CTRL, 0);
10391054
if (rval < 0)
10401055
return rval;
10411056
else
1042-
return rval2;
1057+
return rval2 ?: p * SMIAPP_NVM_PAGE_SIZE;
10431058
}
10441059

10451060
/*
@@ -2326,42 +2341,34 @@ smiapp_sysfs_nvm_read(struct device *dev, struct device_attribute *attr,
23262341
struct v4l2_subdev *subdev = i2c_get_clientdata(to_i2c_client(dev));
23272342
struct i2c_client *client = v4l2_get_subdevdata(subdev);
23282343
struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
2329-
unsigned int nbytes;
2344+
int rval;
23302345

23312346
if (!sensor->dev_init_done)
23322347
return -EBUSY;
23332348

2334-
if (!sensor->nvm_size) {
2335-
int rval;
2336-
2337-
/* NVM not read yet - read it now */
2338-
sensor->nvm_size = sensor->hwcfg->nvm_size;
2349+
rval = pm_runtime_get_sync(&client->dev);
2350+
if (rval < 0) {
2351+
if (rval != -EBUSY && rval != -EAGAIN)
2352+
pm_runtime_set_active(&client->dev);
2353+
pm_runtime_put_noidle(&client->dev);
2354+
return -ENODEV;
2355+
}
23392356

2340-
rval = pm_runtime_get_sync(&client->dev);
2341-
if (rval < 0) {
2342-
if (rval != -EBUSY && rval != -EAGAIN)
2343-
pm_runtime_set_active(&client->dev);
2344-
pm_runtime_put_noidle(&client->dev);
2345-
return -ENODEV;
2346-
}
2357+
rval = smiapp_read_nvm(sensor, buf, PAGE_SIZE);
2358+
if (rval < 0) {
2359+
pm_runtime_put(&client->dev);
2360+
dev_err(&client->dev, "nvm read failed\n");
2361+
return -ENODEV;
2362+
}
23472363

2348-
if (smiapp_read_nvm(sensor, sensor->nvm)) {
2349-
pm_runtime_put(&client->dev);
2350-
dev_err(&client->dev, "nvm read failed\n");
2351-
return -ENODEV;
2352-
}
2364+
pm_runtime_mark_last_busy(&client->dev);
2365+
pm_runtime_put_autosuspend(&client->dev);
23532366

2354-
pm_runtime_mark_last_busy(&client->dev);
2355-
pm_runtime_put_autosuspend(&client->dev);
2356-
}
23572367
/*
23582368
* NVM is still way below a PAGE_SIZE, so we can safely
23592369
* assume this for now.
23602370
*/
2361-
nbytes = min_t(unsigned int, sensor->nvm_size, PAGE_SIZE);
2362-
memcpy(buf, sensor->nvm, nbytes);
2363-
2364-
return nbytes;
2371+
return rval;
23652372
}
23662373
static DEVICE_ATTR(nvm, S_IRUGO, smiapp_sysfs_nvm_read, NULL);
23672374

@@ -2825,16 +2832,13 @@ static struct smiapp_hwconfig *smiapp_get_hwconfig(struct device *dev)
28252832
}
28262833
}
28272834

2828-
/* NVM size is not mandatory */
2829-
fwnode_property_read_u32(fwnode, "nokia,nvm-size", &hwcfg->nvm_size);
2830-
28312835
rval = fwnode_property_read_u32(dev_fwnode(dev), "clock-frequency",
28322836
&hwcfg->ext_clk);
28332837
if (rval)
28342838
dev_info(dev, "can't get clock-frequency\n");
28352839

2836-
dev_dbg(dev, "nvm %d, clk %d, mode %d\n",
2837-
hwcfg->nvm_size, hwcfg->ext_clk, hwcfg->csi_signalling_mode);
2840+
dev_dbg(dev, "clk %d, mode %d\n", hwcfg->ext_clk,
2841+
hwcfg->csi_signalling_mode);
28382842

28392843
if (!bus_cfg.nr_of_link_frequencies) {
28402844
dev_warn(dev, "no link frequencies defined\n");
@@ -3018,17 +3022,10 @@ static int smiapp_probe(struct i2c_client *client)
30183022
rval = -ENOENT;
30193023
goto out_power_off;
30203024
}
3021-
/* SMIA++ NVM initialization - it will be read from the sensor
3022-
* when it is first requested by userspace.
3023-
*/
3024-
if (sensor->minfo.smiapp_version && sensor->hwcfg->nvm_size) {
3025-
sensor->nvm = devm_kzalloc(&client->dev,
3026-
sensor->hwcfg->nvm_size, GFP_KERNEL);
3027-
if (sensor->nvm == NULL) {
3028-
rval = -ENOMEM;
3029-
goto out_cleanup;
3030-
}
30313025

3026+
if (sensor->minfo.smiapp_version &&
3027+
sensor->limits[SMIAPP_LIMIT_DATA_TRANSFER_IF_CAPABILITY] &
3028+
SMIAPP_DATA_TRANSFER_IF_CAPABILITY_SUPPORTED) {
30323029
if (device_create_file(&client->dev, &dev_attr_nvm) != 0) {
30333030
dev_err(&client->dev, "sysfs nvm entry failed\n");
30343031
rval = -EBUSY;

‎drivers/media/i2c/smiapp/smiapp.h‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,6 @@ struct smiapp_sensor {
208208
bool dev_init_done;
209209
u8 compressed_min_bpp;
210210

211-
u8 *nvm; /* nvm memory buffer */
212-
unsigned int nvm_size; /* bytes */
213-
214211
struct smiapp_module_info minfo;
215212

216213
struct smiapp_pll pll;

‎include/media/i2c/smiapp.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ struct smiapp_hwconfig {
4949
unsigned short i2c_addr_dfl; /* Default i2c addr */
5050
unsigned short i2c_addr_alt; /* Alternate i2c addr */
5151

52-
uint32_t nvm_size; /* bytes */
5352
uint32_t ext_clk; /* sensor external clk */
5453

5554
unsigned int lanes; /* Number of CSI-2 lanes */

0 commit comments

Comments
 (0)