[media] smiapp: Get clock rate if it's not available through DT
authorSakari Ailus <sakari.ailus@linux.intel.com>
Tue, 29 Aug 2017 12:41:24 +0000 (09:41 -0300)
committerMauro Carvalho Chehab <mchehab@osg.samsung.com>
Wed, 4 Oct 2017 20:24:55 +0000 (17:24 -0300)
Obtain the clock rate from the clock framework if it's not available
through DT. The assumption is that the parent device (camera module)
defines the rate as clock control is a part of the power on and power off
sequences --- which are camera module specific.

Also use the clock rate from DT if no clock is provided.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
drivers/media/i2c/smiapp/smiapp-core.c

index 55771826b446e418bc77f232eef33ace522337d9..009b5e26204b542a18730f3445351cbeccb21187 100644 (file)
@@ -2829,12 +2829,10 @@ static struct smiapp_hwconfig *smiapp_get_hwconfig(struct device *dev)
        /* NVM size is not mandatory */
        fwnode_property_read_u32(fwnode, "nokia,nvm-size", &hwcfg->nvm_size);
 
-       rval = fwnode_property_read_u32(fwnode, "clock-frequency",
+       rval = fwnode_property_read_u32(dev_fwnode(dev), "clock-frequency",
                                        &hwcfg->ext_clk);
-       if (rval) {
-               dev_warn(dev, "can't get clock-frequency\n");
-               goto out_err;
-       }
+       if (rval)
+               dev_info(dev, "can't get clock-frequency\n");
 
        dev_dbg(dev, "nvm %d, clk %d, mode %d\n",
                hwcfg->nvm_size, hwcfg->ext_clk, hwcfg->csi_signalling_mode);
@@ -2870,7 +2868,6 @@ static int smiapp_probe(struct i2c_client *client,
 {
        struct smiapp_sensor *sensor;
        struct smiapp_hwconfig *hwcfg = smiapp_get_hwconfig(&client->dev);
-       unsigned long rate;
        unsigned int i;
        int rval;
 
@@ -2901,20 +2898,37 @@ static int smiapp_probe(struct i2c_client *client,
                return -EPROBE_DEFER;
        }
 
-       rval = clk_set_rate(sensor->ext_clk, sensor->hwcfg->ext_clk);
-       if (rval < 0) {
-               dev_err(&client->dev,
-                       "unable to set clock freq to %u\n",
-                       sensor->hwcfg->ext_clk);
-               return rval;
-       }
+       if (sensor->ext_clk) {
+               if (sensor->hwcfg->ext_clk) {
+                       unsigned long rate;
 
-       rate = clk_get_rate(sensor->ext_clk);
-       if (rate != sensor->hwcfg->ext_clk) {
-               dev_err(&client->dev,
-                       "can't set clock freq, asked for %u but got %lu\n",
-                       sensor->hwcfg->ext_clk, rate);
-               return rval;
+                       rval = clk_set_rate(sensor->ext_clk,
+                                           sensor->hwcfg->ext_clk);
+                       if (rval < 0) {
+                               dev_err(&client->dev,
+                                       "unable to set clock freq to %u\n",
+                                       sensor->hwcfg->ext_clk);
+                               return rval;
+                       }
+
+                       rate = clk_get_rate(sensor->ext_clk);
+                       if (rate != sensor->hwcfg->ext_clk) {
+                               dev_err(&client->dev,
+                                       "can't set clock freq, asked for %u but got %lu\n",
+                                       sensor->hwcfg->ext_clk, rate);
+                               return rval;
+                       }
+               } else {
+                       sensor->hwcfg->ext_clk = clk_get_rate(sensor->ext_clk);
+                       dev_dbg(&client->dev, "obtained clock freq %u\n",
+                               sensor->hwcfg->ext_clk);
+               }
+       } else if (sensor->hwcfg->ext_clk) {
+               dev_dbg(&client->dev, "assuming clock freq %u\n",
+                       sensor->hwcfg->ext_clk);
+       } else {
+               dev_err(&client->dev, "unable to obtain clock freq\n");
+               return -EINVAL;
        }
 
        sensor->xshutdown = devm_gpiod_get_optional(&client->dev, "xshutdown",