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

[media] ov7670: add devicetree support

Add DT support. Use it to get the reset and pwdn pins (if there are any).
Tested with one sensor requiring reset/pwdn and one sensor that doesn't
have reset/pwdn pins.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>

authored by

Hans Verkuil and committed by
Mauro Carvalho Chehab
a0c4164e 0a024d63

+38 -2
+38 -2
drivers/media/i2c/ov7670.c
··· 17 17 #include <linux/i2c.h> 18 18 #include <linux/delay.h> 19 19 #include <linux/videodev2.h> 20 + #include <linux/gpio.h> 21 + #include <linux/gpio/consumer.h> 20 22 #include <media/v4l2-device.h> 21 23 #include <media/v4l2-ctrls.h> 22 24 #include <media/v4l2-mediabus.h> ··· 231 229 }; 232 230 struct ov7670_format_struct *fmt; /* Current format */ 233 231 struct clk *clk; 232 + struct gpio_desc *resetb_gpio; 233 + struct gpio_desc *pwdn_gpio; 234 234 int min_width; /* Filter out smaller sizes */ 235 235 int min_height; /* Filter out smaller sizes */ 236 236 int clock_speed; /* External clock speed (MHz) */ ··· 594 590 { 595 591 return ov7670_write_array(sd, ov7670_default_regs); 596 592 } 597 - 598 - 599 593 600 594 static int ov7670_detect(struct v4l2_subdev *sd) 601 595 { ··· 1551 1549 }, 1552 1550 }; 1553 1551 1552 + static int ov7670_init_gpio(struct i2c_client *client, struct ov7670_info *info) 1553 + { 1554 + info->pwdn_gpio = devm_gpiod_get_optional(&client->dev, "powerdown", 1555 + GPIOD_OUT_LOW); 1556 + if (IS_ERR(info->pwdn_gpio)) { 1557 + dev_info(&client->dev, "can't get %s GPIO\n", "powerdown"); 1558 + return PTR_ERR(info->pwdn_gpio); 1559 + } 1560 + 1561 + info->resetb_gpio = devm_gpiod_get_optional(&client->dev, "reset", 1562 + GPIOD_OUT_LOW); 1563 + if (IS_ERR(info->resetb_gpio)) { 1564 + dev_info(&client->dev, "can't get %s GPIO\n", "reset"); 1565 + return PTR_ERR(info->resetb_gpio); 1566 + } 1567 + 1568 + usleep_range(3000, 5000); 1569 + 1570 + return 0; 1571 + } 1572 + 1554 1573 static int ov7670_probe(struct i2c_client *client, 1555 1574 const struct i2c_device_id *id) 1556 1575 { ··· 1616 1593 if (IS_ERR(info->clk)) 1617 1594 return -EPROBE_DEFER; 1618 1595 clk_prepare_enable(info->clk); 1596 + 1597 + ret = ov7670_init_gpio(client, info); 1598 + if (ret) 1599 + goto clk_disable; 1619 1600 1620 1601 info->clock_speed = clk_get_rate(info->clk) / 1000000; 1621 1602 if (info->clock_speed < 10 || info->clock_speed > 48) { ··· 1720 1693 }; 1721 1694 MODULE_DEVICE_TABLE(i2c, ov7670_id); 1722 1695 1696 + #if IS_ENABLED(CONFIG_OF) 1697 + static const struct of_device_id ov7670_of_match[] = { 1698 + { .compatible = "ovti,ov7670", }, 1699 + { /* sentinel */ }, 1700 + }; 1701 + MODULE_DEVICE_TABLE(of, ov7670_of_match); 1702 + #endif 1703 + 1723 1704 static struct i2c_driver ov7670_driver = { 1724 1705 .driver = { 1725 1706 .name = "ov7670", 1707 + .of_match_table = of_match_ptr(ov7670_of_match), 1726 1708 }, 1727 1709 .probe = ov7670_probe, 1728 1710 .remove = ov7670_remove,