diff options
Diffstat (limited to 'drivers/led/led-pca955x.c')
-rw-r--r-- | drivers/led/led-pca955x.c | 107 |
1 files changed, 45 insertions, 62 deletions
diff --git a/drivers/led/led-pca955x.c b/drivers/led/led-pca955x.c index 9c4f7967fb..cad4db3799 100644 --- a/drivers/led/led-pca955x.c +++ b/drivers/led/led-pca955x.c @@ -1,3 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright 2007-2008 Extreme Engineering Solutions, Inc. * Author: Nate Case <ncase@xes-inc.com> @@ -5,16 +6,6 @@ * Copyright (C) 2018 WAGO Kontakttechnik GmbH & Co. KG <http://global.wago.com> * Author: Oleg Karfich <oleg.karfich@wago.com> * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * * This code was ported from linux-4.18 kernel driver. * Orginal code with it's copyright info can be found in * drivers/leds/leds-pca955x.c @@ -72,53 +63,47 @@ enum led_brightness { LED_FULL = 255, }; -enum pca955x_type { - pca9550, - pca9551, - pca9552, - pca9553, -}; - struct pca955x_chipdef { int bits; u8 slv_addr; /* 7-bit slave address mask */ int slv_addr_shift; /* Number of bits to ignore */ }; -static struct pca955x_chipdef pca955x_chipdefs[] = { - [pca9550] = { - .bits = 2, - .slv_addr = /* 110000x */ 0x60, - .slv_addr_shift = 1, - }, - [pca9551] = { - .bits = 8, - .slv_addr = /* 1100xxx */ 0x60, - .slv_addr_shift = 3, - }, - [pca9552] = { - .bits = 16, - .slv_addr = /* 1100xxx */ 0x60, - .slv_addr_shift = 3, - }, - [pca9553] = { - .bits = 4, - .slv_addr = /* 110001x */ 0x62, - .slv_addr_shift = 1, - }, +static const struct pca955x_chipdef pca9550_chipdef = { + .bits = 2, + .slv_addr = /* 110000x */ 0x60, + .slv_addr_shift = 1, +}; + +static const struct pca955x_chipdef pca9551_chipdef = { + .bits = 8, + .slv_addr = /* 1100xxx */ 0x60, + .slv_addr_shift = 3, +}; + +static const struct pca955x_chipdef pca9552_chipdef = { + .bits = 16, + .slv_addr = /* 1100xxx */ 0x60, + .slv_addr_shift = 3, +}; + +static const struct pca955x_chipdef pca9553_chipdef = { + .bits = 4, + .slv_addr = /* 110001x */ 0x62, + .slv_addr_shift = 1, }; static const struct platform_device_id led_pca955x_id[] = { - { "pca9550", pca9550 }, - { "pca9551", pca9551 }, - { "pca9552", pca9552 }, - { "pca9553", pca9553 }, + { "pca9550", (unsigned long) &pca9550_chipdef }, + { "pca9551", (unsigned long) &pca9551_chipdef }, + { "pca9552", (unsigned long) &pca9552_chipdef }, + { "pca9553", (unsigned long) &pca9553_chipdef }, { } }; struct pca955x { struct pca955x_led *leds; - struct pca955x_chipdef *chipdef; + const struct pca955x_chipdef *chipdef; struct i2c_client *client; }; @@ -278,7 +263,7 @@ static struct pca955x_platform_data * led_pca955x_pdata_of_init(struct device_node *np, struct pca955x *pca955x) { struct device_node *child; - struct pca955x_chipdef *chip = pca955x->chipdef; + const struct pca955x_chipdef *chip = pca955x->chipdef; struct pca955x_platform_data *pdata; int count, err; @@ -316,7 +301,6 @@ led_pca955x_pdata_of_init(struct device_node *np, struct pca955x *pca955x) pca955x_led->led_cdev.name = pca955x_led->name; pca955x_led->led_cdev.set = pca955x_led_set; - pca955x_led->led_cdev.num = pca955x_led->led_num; pca955x_led->led_cdev.max_value = 255; err = led_register(&pca955x_led->led_cdev); @@ -335,23 +319,27 @@ led_pca955x_pdata_of_init(struct device_node *np, struct pca955x *pca955x) } static const struct of_device_id of_pca955x_match[] = { - { .compatible = "nxp,pca9550", .data = (void *)pca9550 }, - { .compatible = "nxp,pca9551", .data = (void *)pca9551 }, - { .compatible = "nxp,pca9552", .data = (void *)pca9552 }, - { .compatible = "nxp,pca9553", .data = (void *)pca9553 }, + { .compatible = "nxp,pca9550", .data = &pca9550_chipdef }, + { .compatible = "nxp,pca9551", .data = &pca9551_chipdef }, + { .compatible = "nxp,pca9552", .data = &pca9552_chipdef }, + { .compatible = "nxp,pca9553", .data = &pca9553_chipdef }, {}, }; +MODULE_DEVICE_TABLE(of, of_pca955x_match); -static int led_pca955x_probe(struct device_d *dev) +static int led_pca955x_probe(struct device *dev) { struct pca955x *pca955x; struct pca955x_led *pca955x_led; - struct pca955x_chipdef *chip; + const struct pca955x_chipdef *chip; struct i2c_client *client; int err; struct pca955x_platform_data *pdata; - chip = &pca955x_chipdefs[dev->id_entry->driver_data]; + chip = device_get_match_data(dev); + if (!chip) + return -ENODEV; + client = to_i2c_client(dev); /* Make sure the slave address / chip type combo given is possible */ @@ -378,7 +366,7 @@ static int led_pca955x_probe(struct device_d *dev) pca955x->client = client; pca955x->chipdef = chip; - pdata = led_pca955x_pdata_of_init(dev->device_node, pca955x); + pdata = led_pca955x_pdata_of_init(dev->of_node, pca955x); if (IS_ERR(pdata)) return PTR_ERR(pdata); @@ -400,22 +388,17 @@ static int led_pca955x_probe(struct device_d *dev) err = pca955x_write_psc(client, 0, 0); if (err) return err; + err = pca955x_write_psc(client, 1, 0); - if (err) - return err; - return 0; + return err; } -static struct driver_d led_pca955x_driver = { +static struct driver led_pca955x_driver = { .name = "led-pca955x", .probe = led_pca955x_probe, .id_table = led_pca955x_id, .of_compatible = DRV_OF_COMPAT(of_pca955x_match), }; -static int __init led_pca955x_init(void) -{ - return i2c_driver_register(&led_pca955x_driver); -} -device_initcall(led_pca955x_init); +device_i2c_driver(led_pca955x_driver); |