0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include <linux/gpio/machine.h>
0012 #include <linux/gpio/consumer.h>
0013 #include <linux/leds.h>
0014 #include <linux/module.h>
0015 #include <linux/platform_device.h>
0016
0017 static struct gpiod_lookup_table simatic_ipc_led_gpio_table = {
0018 .dev_id = "leds-gpio",
0019 .table = {
0020 GPIO_LOOKUP_IDX("apollolake-pinctrl.0", 51, NULL, 0, GPIO_ACTIVE_LOW),
0021 GPIO_LOOKUP_IDX("apollolake-pinctrl.0", 52, NULL, 1, GPIO_ACTIVE_LOW),
0022 GPIO_LOOKUP_IDX("apollolake-pinctrl.0", 53, NULL, 2, GPIO_ACTIVE_LOW),
0023 GPIO_LOOKUP_IDX("apollolake-pinctrl.0", 57, NULL, 3, GPIO_ACTIVE_LOW),
0024 GPIO_LOOKUP_IDX("apollolake-pinctrl.0", 58, NULL, 4, GPIO_ACTIVE_LOW),
0025 GPIO_LOOKUP_IDX("apollolake-pinctrl.0", 60, NULL, 5, GPIO_ACTIVE_LOW),
0026 GPIO_LOOKUP_IDX("apollolake-pinctrl.0", 56, NULL, 6, GPIO_ACTIVE_LOW),
0027 GPIO_LOOKUP_IDX("apollolake-pinctrl.0", 59, NULL, 7, GPIO_ACTIVE_HIGH),
0028 },
0029 };
0030
0031 static const struct gpio_led simatic_ipc_gpio_leds[] = {
0032 { .name = "green:" LED_FUNCTION_STATUS "-3" },
0033 { .name = "red:" LED_FUNCTION_STATUS "-1" },
0034 { .name = "green:" LED_FUNCTION_STATUS "-1" },
0035 { .name = "red:" LED_FUNCTION_STATUS "-2" },
0036 { .name = "green:" LED_FUNCTION_STATUS "-2" },
0037 { .name = "red:" LED_FUNCTION_STATUS "-3" },
0038 };
0039
0040 static const struct gpio_led_platform_data simatic_ipc_gpio_leds_pdata = {
0041 .num_leds = ARRAY_SIZE(simatic_ipc_gpio_leds),
0042 .leds = simatic_ipc_gpio_leds,
0043 };
0044
0045 static struct platform_device *simatic_leds_pdev;
0046
0047 static int simatic_ipc_leds_gpio_remove(struct platform_device *pdev)
0048 {
0049 gpiod_remove_lookup_table(&simatic_ipc_led_gpio_table);
0050 platform_device_unregister(simatic_leds_pdev);
0051
0052 return 0;
0053 }
0054
0055 static int simatic_ipc_leds_gpio_probe(struct platform_device *pdev)
0056 {
0057 struct gpio_desc *gpiod;
0058 int err;
0059
0060 gpiod_add_lookup_table(&simatic_ipc_led_gpio_table);
0061 simatic_leds_pdev = platform_device_register_resndata(NULL,
0062 "leds-gpio", PLATFORM_DEVID_NONE, NULL, 0,
0063 &simatic_ipc_gpio_leds_pdata,
0064 sizeof(simatic_ipc_gpio_leds_pdata));
0065 if (IS_ERR(simatic_leds_pdev)) {
0066 err = PTR_ERR(simatic_leds_pdev);
0067 goto out;
0068 }
0069
0070
0071 gpiod = gpiod_get_index(&simatic_leds_pdev->dev, NULL, 6, GPIOD_OUT_LOW);
0072 if (IS_ERR(gpiod)) {
0073 err = PTR_ERR(gpiod);
0074 goto out;
0075 }
0076 gpiod_put(gpiod);
0077
0078
0079 gpiod = gpiod_get_index(&simatic_leds_pdev->dev, NULL, 7, GPIOD_OUT_LOW);
0080 if (IS_ERR(gpiod)) {
0081 err = PTR_ERR(gpiod);
0082 goto out;
0083 }
0084 gpiod_put(gpiod);
0085
0086 return 0;
0087 out:
0088 simatic_ipc_leds_gpio_remove(pdev);
0089
0090 return err;
0091 }
0092
0093 static struct platform_driver simatic_ipc_led_gpio_driver = {
0094 .probe = simatic_ipc_leds_gpio_probe,
0095 .remove = simatic_ipc_leds_gpio_remove,
0096 .driver = {
0097 .name = KBUILD_MODNAME,
0098 }
0099 };
0100 module_platform_driver(simatic_ipc_led_gpio_driver);
0101
0102 MODULE_LICENSE("GPL v2");
0103 MODULE_ALIAS("platform:" KBUILD_MODNAME);
0104 MODULE_SOFTDEP("pre: platform:leds-gpio");
0105 MODULE_AUTHOR("Henning Schild <henning.schild@siemens.com>");