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

Configure Feed

Select the types of activity you want to include in your feed.

ALSA: hda/cirrus_scodec_test: Use faux_device instead of platform_device

The dummy GPIO driver doesn't need to be a platform device. So make it a
faux_device driver.

Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
Link: https://patch.msgid.link/20260115143920.1553783-1-rf@opensource.cirrus.com
Signed-off-by: Takashi Iwai <tiwai@suse.de>

authored by

Richard Fitzgerald and committed by
Takashi Iwai
b799d165 a654de9d

+29 -32
+29 -32
sound/hda/codecs/side-codecs/cirrus_scodec_test.c
··· 5 5 // Copyright (C) 2023 Cirrus Logic, Inc. and 6 6 // Cirrus Logic International Semiconductor Ltd. 7 7 8 - #include <kunit/platform_device.h> 9 8 #include <kunit/resource.h> 10 9 #include <kunit/test.h> 11 10 #include <linux/device.h> 11 + #include <linux/device/devres.h> 12 12 #include <linux/device/faux.h> 13 13 #include <linux/gpio/driver.h> 14 14 #include <linux/module.h> 15 - #include <linux/platform_device.h> 16 15 17 16 #include "cirrus_scodec.h" 18 17 ··· 28 29 29 30 struct cirrus_scodec_test_priv { 30 31 struct faux_device *amp_dev; 31 - struct platform_device *gpio_pdev; 32 + struct faux_device *gpio_dev; 32 33 struct cirrus_scodec_test_gpio *gpio_priv; 33 34 }; 34 35 ··· 91 92 .ngpio = 32, 92 93 }; 93 94 94 - static int cirrus_scodec_test_gpio_probe(struct platform_device *pdev) 95 + /* software_node referencing the gpio driver */ 96 + static const struct software_node cirrus_scodec_test_gpio_swnode = { 97 + .name = "cirrus_scodec_test_gpio", 98 + }; 99 + 100 + static int cirrus_scodec_test_gpio_probe(struct faux_device *fdev) 95 101 { 96 102 struct cirrus_scodec_test_gpio *gpio_priv; 97 103 int ret; 98 104 99 - gpio_priv = devm_kzalloc(&pdev->dev, sizeof(*gpio_priv), GFP_KERNEL); 105 + gpio_priv = devm_kzalloc(&fdev->dev, sizeof(*gpio_priv), GFP_KERNEL); 100 106 if (!gpio_priv) 101 107 return -ENOMEM; 102 108 109 + ret = device_add_software_node(&fdev->dev, &cirrus_scodec_test_gpio_swnode); 110 + if (ret) 111 + return ret; 112 + 113 + ret = devm_add_action_or_reset(&fdev->dev, device_remove_software_node_wrapper, 114 + &fdev->dev); 115 + if (ret) 116 + return ret; 117 + 103 118 /* GPIO core modifies our struct gpio_chip so use a copy */ 104 119 gpio_priv->chip = cirrus_scodec_test_gpio_chip; 105 - gpio_priv->chip.parent = &pdev->dev; 106 - ret = devm_gpiochip_add_data(&pdev->dev, &gpio_priv->chip, gpio_priv); 120 + gpio_priv->chip.parent = &fdev->dev; 121 + ret = devm_gpiochip_add_data(&fdev->dev, &gpio_priv->chip, gpio_priv); 107 122 if (ret) 108 - return dev_err_probe(&pdev->dev, ret, "Failed to add gpiochip\n"); 123 + return dev_err_probe(&fdev->dev, ret, "Failed to add gpiochip\n"); 109 124 110 - dev_set_drvdata(&pdev->dev, gpio_priv); 125 + dev_set_drvdata(&fdev->dev, gpio_priv); 111 126 112 127 return 0; 113 128 } 114 129 115 - static struct platform_driver cirrus_scodec_test_gpio_driver = { 116 - .driver.name = "cirrus_scodec_test_gpio_drv", 117 - .driver.owner = THIS_MODULE, 130 + static const struct faux_device_ops cirrus_scodec_test_gpio_driver_ops = { 118 131 .probe = cirrus_scodec_test_gpio_probe, 119 - }; 120 - 121 - /* software_node referencing the gpio driver */ 122 - static const struct software_node cirrus_scodec_test_gpio_swnode = { 123 - .name = "cirrus_scodec_test_gpio", 124 132 }; 125 133 126 134 static void cirrus_scodec_test_create_gpio(struct kunit *test) 127 135 { 128 136 struct cirrus_scodec_test_priv *priv = test->priv; 129 137 130 - KUNIT_ASSERT_EQ(test, 0, 131 - kunit_platform_driver_register(test, &cirrus_scodec_test_gpio_driver)); 132 - 133 - priv->gpio_pdev = kunit_platform_device_alloc(test, 134 - cirrus_scodec_test_gpio_driver.driver.name, 135 - PLATFORM_DEVID_NONE); 136 - KUNIT_ASSERT_NOT_NULL(test, priv->gpio_pdev); 137 - 138 - KUNIT_ASSERT_EQ(test, 0, device_add_software_node(&priv->gpio_pdev->dev, 139 - &cirrus_scodec_test_gpio_swnode)); 138 + priv->gpio_dev = faux_device_create("cirrus_scodec_test_gpio_drv", NULL, 139 + &cirrus_scodec_test_gpio_driver_ops); 140 + KUNIT_ASSERT_NOT_NULL(test, priv->gpio_dev); 140 141 KUNIT_ASSERT_EQ(test, 0, kunit_add_action_or_reset(test, 141 - device_remove_software_node_wrapper, 142 - &priv->gpio_pdev->dev)); 142 + faux_device_destroy_wrapper, 143 + priv->gpio_dev)); 143 144 144 - KUNIT_ASSERT_EQ(test, 0, kunit_platform_device_add(test, priv->gpio_pdev)); 145 - 146 - priv->gpio_priv = dev_get_drvdata(&priv->gpio_pdev->dev); 145 + priv->gpio_priv = dev_get_drvdata(&priv->gpio_dev->dev); 147 146 KUNIT_ASSERT_NOT_NULL(test, priv->gpio_priv); 148 147 } 149 148