Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

media: i2c: ov7670: Extend match support for OF tables

The driver has an OF match table, still, it uses an ID lookup table for
retrieving match data. Currently, the driver is working on the
assumption that an I2C device registered via OF will always match a
legacy I2C device ID. The correct approach is to have an OF device ID
table using i2c_get_match_data() if the devices are registered via OF/ID.

Unify the OF/ID table by using struct ov7670_devtype as match data for
both these tables and replace the ID lookup table for the match data by
i2c_get_match_data().

Split the array ov7670_devdata[] as individual variables, and
make lines shorter by referring to e.g. &ov7670_devdata instead of
&ov7670_devdata[MODEL_OV7670].

Drop enum ov7670_model as there is no user.

While at it, remove the trailing comma in the terminator entry for the OF
table making code robust against (theoretical) misrebases or other similar
things where the new entry goes _after_ the termination without the
compiler noticing.

Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
Reviewed-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi+renesas@ideasonboard.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>

authored by

Biju Das and committed by
Hans Verkuil
dd2dbf3c 57829517

+20 -27
+20 -27
drivers/media/i2c/ov7670.c
··· 186 186 #define REG_HAECC7 0xaa /* Hist AEC/AGC control 7 */ 187 187 #define REG_BD60MAX 0xab /* 60hz banding step limit */ 188 188 189 - enum ov7670_model { 190 - MODEL_OV7670 = 0, 191 - MODEL_OV7675, 192 - }; 193 - 194 189 struct ov7670_win_size { 195 190 int width; 196 191 int height; ··· 1753 1758 1754 1759 /* ----------------------------------------------------------------------- */ 1755 1760 1756 - static const struct ov7670_devtype ov7670_devdata[] = { 1757 - [MODEL_OV7670] = { 1758 - .win_sizes = ov7670_win_sizes, 1759 - .n_win_sizes = ARRAY_SIZE(ov7670_win_sizes), 1760 - .set_framerate = ov7670_set_framerate_legacy, 1761 - .get_framerate = ov7670_get_framerate_legacy, 1762 - }, 1763 - [MODEL_OV7675] = { 1764 - .win_sizes = ov7675_win_sizes, 1765 - .n_win_sizes = ARRAY_SIZE(ov7675_win_sizes), 1766 - .set_framerate = ov7675_set_framerate, 1767 - .get_framerate = ov7675_get_framerate, 1768 - }, 1769 - }; 1770 - 1771 1761 static int ov7670_init_gpio(struct i2c_client *client, struct ov7670_info *info) 1772 1762 { 1773 1763 info->pwdn_gpio = devm_gpiod_get_optional(&client->dev, "powerdown", ··· 1813 1833 1814 1834 static int ov7670_probe(struct i2c_client *client) 1815 1835 { 1816 - const struct i2c_device_id *id = i2c_client_get_device_id(client); 1817 1836 struct v4l2_fract tpf; 1818 1837 struct v4l2_subdev *sd; 1819 1838 struct ov7670_info *info; ··· 1884 1905 v4l_info(client, "chip found @ 0x%02x (%s)\n", 1885 1906 client->addr << 1, client->adapter->name); 1886 1907 1887 - info->devtype = &ov7670_devdata[id->driver_data]; 1908 + info->devtype = i2c_get_match_data(client); 1888 1909 info->fmt = &ov7670_formats[0]; 1889 1910 info->wsize = &info->devtype->win_sizes[0]; 1890 1911 ··· 1972 1993 media_entity_cleanup(&info->sd.entity); 1973 1994 } 1974 1995 1996 + static const struct ov7670_devtype ov7670_devdata = { 1997 + .win_sizes = ov7670_win_sizes, 1998 + .n_win_sizes = ARRAY_SIZE(ov7670_win_sizes), 1999 + .set_framerate = ov7670_set_framerate_legacy, 2000 + .get_framerate = ov7670_get_framerate_legacy, 2001 + }; 2002 + 2003 + static const struct ov7670_devtype ov7675_devdata = { 2004 + .win_sizes = ov7675_win_sizes, 2005 + .n_win_sizes = ARRAY_SIZE(ov7675_win_sizes), 2006 + .set_framerate = ov7675_set_framerate, 2007 + .get_framerate = ov7675_get_framerate, 2008 + }; 2009 + 1975 2010 static const struct i2c_device_id ov7670_id[] = { 1976 - { "ov7670", MODEL_OV7670 }, 1977 - { "ov7675", MODEL_OV7675 }, 1978 - { } 2011 + { "ov7670", (kernel_ulong_t)&ov7670_devdata }, 2012 + { "ov7675", (kernel_ulong_t)&ov7675_devdata }, 2013 + { /* sentinel */ } 1979 2014 }; 1980 2015 MODULE_DEVICE_TABLE(i2c, ov7670_id); 1981 2016 1982 2017 #if IS_ENABLED(CONFIG_OF) 1983 2018 static const struct of_device_id ov7670_of_match[] = { 1984 - { .compatible = "ovti,ov7670", }, 1985 - { /* sentinel */ }, 2019 + { .compatible = "ovti,ov7670", &ov7670_devdata }, 2020 + { /* sentinel */ } 1986 2021 }; 1987 2022 MODULE_DEVICE_TABLE(of, ov7670_of_match); 1988 2023 #endif