Merge git://git.denx.de/u-boot-marvell
authorTom Rini <trini@konsulko.com>
Tue, 20 Nov 2018 17:36:47 +0000 (12:36 -0500)
committerTom Rini <trini@konsulko.com>
Tue, 20 Nov 2018 17:39:16 +0000 (12:39 -0500)
- Clearfog GT-8K support added by Baruch / Raheeb
- const and sizes cleanup (also in MIPS) from Baruch
- Minor cleanup to db-88f6820 from Chris

board/solidrun/clearfog/MAINTAINERS
cmd/adc.c
drivers/adc/adc-uclass.c
drivers/clk/clk_meson.c
fs/fat/fat.c
include/adc.h
test/dm/adc.c

index 298e501..6646d96 100644 (file)
@@ -4,3 +4,4 @@ S:      Maintained
 F:     board/soldrun/clearfog/
 F:     include/configs/clearfog.h
 F:     configs/clearfog_defconfig
+F:     configs/clearfog_gt_8k_defconfig
index c8857ed..2d635ac 100644 (file)
--- a/cmd/adc.c
+++ b/cmd/adc.c
@@ -35,7 +35,7 @@ static int do_adc_info(cmd_tbl_t *cmdtp, int flag, int argc,
                       char *const argv[])
 {
        struct udevice *dev;
-       unsigned int data_mask;
+       unsigned int data_mask, ch_mask;
        int ret, vss, vdd;
 
        if (argc < 2)
@@ -49,6 +49,10 @@ static int do_adc_info(cmd_tbl_t *cmdtp, int flag, int argc,
 
        printf("ADC Device '%s' :\n", argv[1]);
 
+       ret = adc_channel_mask(dev, &ch_mask);
+       if (!ret)
+               printf("channel mask: %x\n", ch_mask);
+
        ret = adc_data_mask(dev, &data_mask);
        if (!ret)
                printf("data mask: %x\n", data_mask);
@@ -67,8 +71,9 @@ static int do_adc_info(cmd_tbl_t *cmdtp, int flag, int argc,
 static int do_adc_single(cmd_tbl_t *cmdtp, int flag, int argc,
                         char *const argv[])
 {
+       struct udevice *dev;
        unsigned int data;
-       int ret;
+       int ret, uV;
 
        if (argc < 3)
                return CMD_RET_USAGE;
@@ -81,7 +86,62 @@ static int do_adc_single(cmd_tbl_t *cmdtp, int flag, int argc,
                return CMD_RET_FAILURE;
        }
 
-       printf("%u\n", data);
+       ret = uclass_get_device_by_name(UCLASS_ADC, argv[1], &dev);
+       if (!ret && !adc_raw_to_uV(dev, data, &uV))
+               printf("%u, %d uV\n", data, uV);
+       else
+               printf("%u\n", data);
+
+       return CMD_RET_SUCCESS;
+}
+
+static int do_adc_scan(cmd_tbl_t *cmdtp, int flag, int argc,
+                      char *const argv[])
+{
+       struct adc_channel ch[ADC_MAX_CHANNEL];
+       struct udevice *dev;
+       unsigned int ch_mask;
+       int i, chan, ret, uV;
+
+       if (argc < 2)
+               return CMD_RET_USAGE;
+
+       ret = uclass_get_device_by_name(UCLASS_ADC, argv[1], &dev);
+       if (ret) {
+               pr_err("Can't get the ADC %s: %d\n", argv[1], ret);
+               return CMD_RET_FAILURE;
+       }
+
+       switch (argc) {
+       case 3:
+               ch_mask = simple_strtoul(argv[2], NULL, 0);
+               if (ch_mask)
+                       break;
+       case 2:
+               ret = adc_channel_mask(dev, &ch_mask);
+               if (ret) {
+                       pr_err("Can't get mask for %s: %d\n", dev->name, ret);
+                       return CMD_RET_FAILURE;
+               }
+               break;
+       }
+
+       ret = adc_channels_single_shot(dev->name, ch_mask, ch);
+       if (ret) {
+               pr_err("Can't get single shot for %s (chans mask: 0x%x): %d\n",
+                      dev->name, ch_mask, ret);
+               return CMD_RET_FAILURE;
+       }
+
+       for (chan = 0, i = 0; chan < ADC_MAX_CHANNEL; chan++) {
+               if (!(ch_mask & ADC_CHANNEL(chan)))
+                       continue;
+               if (!adc_raw_to_uV(dev, ch[i].data, &uV))
+                       printf("[%02d]: %u, %d uV\n", ch[i].id, ch[i].data, uV);
+               else
+                       printf("[%02d]: %u\n", ch[i].id, ch[i].data);
+               i++;
+       }
 
        return CMD_RET_SUCCESS;
 }
@@ -90,6 +150,7 @@ static cmd_tbl_t cmd_adc_sub[] = {
        U_BOOT_CMD_MKENT(list, 1, 1, do_adc_list, "", ""),
        U_BOOT_CMD_MKENT(info, 2, 1, do_adc_info, "", ""),
        U_BOOT_CMD_MKENT(single, 3, 1, do_adc_single, "", ""),
+       U_BOOT_CMD_MKENT(scan, 3, 1, do_adc_scan, "", ""),
 };
 
 static int do_adc(cmd_tbl_t *cmdtp, int flag, int argc,
@@ -115,6 +176,7 @@ static int do_adc(cmd_tbl_t *cmdtp, int flag, int argc,
 static char adc_help_text[] =
        "list - list ADC devices\n"
        "adc info <name> - Get ADC device info\n"
-       "adc single <name> <channel> - Get Single data of ADC device channel";
+       "adc single <name> <channel> - Get Single data of ADC device channel\n"
+       "adc scan <name> [channel mask] - Scan all [or masked] ADC channels";
 
 U_BOOT_CMD(adc, 4, 1, do_adc, "ADC sub-system", adc_help_text);
index 738c1ea..0a492eb 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <common.h>
 #include <errno.h>
+#include <div64.h>
 #include <dm.h>
 #include <dm/lists.h>
 #include <dm/device-internal.h>
@@ -77,6 +78,18 @@ int adc_data_mask(struct udevice *dev, unsigned int *data_mask)
        return 0;
 }
 
+int adc_channel_mask(struct udevice *dev, unsigned int *channel_mask)
+{
+       struct adc_uclass_platdata *uc_pdata = dev_get_uclass_platdata(dev);
+
+       if (!uc_pdata)
+               return -ENOSYS;
+
+       *channel_mask = uc_pdata->channel_mask;
+
+       return 0;
+}
+
 int adc_stop(struct udevice *dev)
 {
        const struct adc_ops *ops = dev_get_driver_ops(dev);
@@ -329,6 +342,30 @@ int adc_vss_value(struct udevice *dev, int *uV)
        return 0;
 }
 
+int adc_raw_to_uV(struct udevice *dev, unsigned int raw, int *uV)
+{
+       unsigned int data_mask;
+       int ret, val, vref;
+       u64 raw64 = raw;
+
+       ret = adc_vdd_value(dev, &vref);
+       if (ret)
+               return ret;
+
+       if (!adc_vss_value(dev, &val))
+               vref -= val;
+
+       ret = adc_data_mask(dev, &data_mask);
+       if (ret)
+               return ret;
+
+       raw64 *= vref;
+       do_div(raw64, data_mask);
+       *uV = raw64;
+
+       return 0;
+}
+
 static int adc_vdd_platdata_set(struct udevice *dev)
 {
        struct adc_uclass_platdata *uc_pdata = dev_get_uclass_platdata(dev);
index 236d734..c448588 100644 (file)
@@ -600,7 +600,8 @@ static unsigned long meson_clk81_get_rate(struct clk *clk)
        reg = readl(priv->addr + HHI_MPEG_CLK_CNTL);
        reg = reg & ((1 << 7) - 1);
 
-       return parent_rate / reg;
+       /* clk81 divider is zero based */
+       return parent_rate / (reg + 1);
 }
 
 static long mpll_rate_from_params(unsigned long parent_rate,
index b08949d..4bc3030 100644 (file)
@@ -725,7 +725,10 @@ static void *next_cluster(fat_itr *itr)
        if (itr->last_cluster)
                return NULL;
 
-       sect = clust_to_sect(itr->fsdata, itr->next_clust);
+       if (itr->fsdata->fatsize != 32 && itr->is_root)
+               sect = mydata->rootdir_sect;
+       else
+               sect = clust_to_sect(itr->fsdata, itr->next_clust);
 
        debug("FAT read(sect=%d), clust_size=%d, DIRENTSPERBLOCK=%zd\n",
              sect, itr->fsdata->clust_size, DIRENTSPERBLOCK);
index d04c9c4..5841dfb 100644 (file)
@@ -219,6 +219,17 @@ int adc_channels_data(struct udevice *dev, unsigned int channel_mask,
 int adc_data_mask(struct udevice *dev, unsigned int *data_mask);
 
 /**
+ * adc_channel_mask() - get channel mask for given ADC device
+ *
+ * This can be used if adc uclass platform data is filled.
+ *
+ * @dev:       ADC device to check
+ * @channel_mask: pointer to the returned channel bitmask
+ * @return: 0 if OK, -ve on error
+ */
+int adc_channel_mask(struct udevice *dev, unsigned int *channel_mask);
+
+/**
  * adc_channel_single_shot() - get output data of conversion for the ADC
  * device's channel. This function searches for the device with the given name,
  * starts the given channel conversion and returns the output data.
@@ -284,4 +295,14 @@ int adc_vss_value(struct udevice *dev, int *uV);
  */
 int adc_stop(struct udevice *dev);
 
+/**
+ * adc_raw_to_uV() - converts raw value to microvolts for given ADC device.
+ *
+ * @dev:     ADC device used from conversion
+ * @raw:     raw value to convert
+ * @uV:             converted value in microvolts
+ * @return:  0 on success or -ve on error
+ */
+int adc_raw_to_uV(struct udevice *dev, unsigned int raw, int *uV);
+
 #endif
index 13eda3b..1f82304 100644 (file)
 static int dm_test_adc_bind(struct unit_test_state *uts)
 {
        struct udevice *dev;
+       unsigned int channel_mask;
 
        ut_assertok(uclass_get_device_by_name(UCLASS_ADC, "adc", &dev));
        ut_asserteq_str(SANDBOX_ADC_DEVNAME, dev->name);
 
+       ut_assertok(adc_channel_mask(dev, &channel_mask));
+       ut_asserteq((1 << SANDBOX_ADC_CHANNELS) - 1, channel_mask);
+
        return 0;
 }
 DM_TEST(dm_test_adc_bind, DM_TESTF_SCAN_FDT);
@@ -160,3 +164,34 @@ static int dm_test_adc_multi_channel_shot(struct unit_test_state *uts)
        return 0;
 }
 DM_TEST(dm_test_adc_multi_channel_shot, DM_TESTF_SCAN_FDT);
+
+static const int dm_test_adc_uV_data[SANDBOX_ADC_CHANNELS] = {
+       ((u64)SANDBOX_ADC_CHANNEL0_DATA * SANDBOX_BUCK2_INITIAL_EXPECTED_UV) /
+               SANDBOX_ADC_DATA_MASK,
+       ((u64)SANDBOX_ADC_CHANNEL1_DATA * SANDBOX_BUCK2_INITIAL_EXPECTED_UV) /
+               SANDBOX_ADC_DATA_MASK,
+       ((u64)SANDBOX_ADC_CHANNEL2_DATA * SANDBOX_BUCK2_INITIAL_EXPECTED_UV) /
+               SANDBOX_ADC_DATA_MASK,
+       ((u64)SANDBOX_ADC_CHANNEL3_DATA * SANDBOX_BUCK2_INITIAL_EXPECTED_UV) /
+               SANDBOX_ADC_DATA_MASK,
+};
+
+static int dm_test_adc_raw_to_uV(struct unit_test_state *uts)
+{
+       struct adc_channel *tdata = adc_channel_test_data;
+       unsigned int i, data;
+       struct udevice *dev;
+       int uV;
+
+       ut_assertok(uclass_get_device_by_name(UCLASS_ADC, "adc", &dev));
+       /* Test each ADC channel's value in microvolts */
+       for (i = 0; i < SANDBOX_ADC_CHANNELS; i++, tdata++) {
+               ut_assertok(adc_start_channel(dev, tdata->id));
+               ut_assertok(adc_channel_data(dev, tdata->id, &data));
+               ut_assertok(adc_raw_to_uV(dev, data, &uV));
+               ut_asserteq(dm_test_adc_uV_data[i], uV);
+       }
+
+       return 0;
+}
+DM_TEST(dm_test_adc_raw_to_uV, DM_TESTF_SCAN_FDT);