Skip to content

Commit 696e9ba

Browse files
author
Bartosz Golaszewski
committed
gpio: sim: allow to define the active-low setting of a simulated hog
Add a new configfs attribute to the hog group allowing to configure the active-low lookup flag for hogged lines. This will allow us to extend tests to also cover the line config of hogs set up using software nodes. Reviewed-by: Linus Walleij <linusw@kernel.org> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Link: https://patch.msgid.link/20260309-gpio-hog-fwnode-v2-6-4e61f3dbf06a@oss.qualcomm.com Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
1 parent dea046e commit 696e9ba

1 file changed

Lines changed: 39 additions & 1 deletion

File tree

drivers/gpio/gpio-sim.c

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,7 @@ struct gpio_sim_hog {
654654

655655
char *name;
656656
int dir;
657+
bool active_low;
657658
};
658659

659660
static struct gpio_sim_hog *to_gpio_sim_hog(struct config_item *item)
@@ -836,7 +837,7 @@ static int gpio_sim_bank_add_hogs(struct gpio_sim_bank *bank)
836837
hog = line->hog;
837838

838839
gpios[0] = line->offset;
839-
gpios[1] = 0;
840+
gpios[1] = hog->active_low ? 1 : 0;
840841

841842
memset(properties, 0, sizeof(properties));
842843

@@ -1315,9 +1316,46 @@ gpio_sim_hog_config_direction_store(struct config_item *item,
13151316

13161317
CONFIGFS_ATTR(gpio_sim_hog_config_, direction);
13171318

1319+
static ssize_t gpio_sim_hog_config_active_low_show(struct config_item *item,
1320+
char *page)
1321+
{
1322+
struct gpio_sim_hog *hog = to_gpio_sim_hog(item);
1323+
struct gpio_sim_device *dev = gpio_sim_hog_get_device(hog);
1324+
1325+
guard(mutex)(&dev->lock);
1326+
1327+
return sprintf(page, "%c\n", hog->active_low ? '1' : '0');
1328+
}
1329+
1330+
static ssize_t
1331+
gpio_sim_hog_config_active_low_store(struct config_item *item,
1332+
const char *page, size_t count)
1333+
{
1334+
struct gpio_sim_hog *hog = to_gpio_sim_hog(item);
1335+
struct gpio_sim_device *dev = gpio_sim_hog_get_device(hog);
1336+
bool active_low;
1337+
int ret;
1338+
1339+
guard(mutex)(&dev->lock);
1340+
1341+
if (gpio_sim_device_is_live(dev))
1342+
return -EBUSY;
1343+
1344+
ret = kstrtobool(page, &active_low);
1345+
if (ret)
1346+
return ret;
1347+
1348+
hog->active_low = active_low;
1349+
1350+
return count;
1351+
}
1352+
1353+
CONFIGFS_ATTR(gpio_sim_hog_config_, active_low);
1354+
13181355
static struct configfs_attribute *gpio_sim_hog_config_attrs[] = {
13191356
&gpio_sim_hog_config_attr_name,
13201357
&gpio_sim_hog_config_attr_direction,
1358+
&gpio_sim_hog_config_attr_active_low,
13211359
NULL
13221360
};
13231361

0 commit comments

Comments
 (0)