[PATCH 2/7] led: pca955x: fix probing from device tree

Ahmad Fatoum a.fatoum at pengutronix.de
Wed Sep 30 03:28:42 EDT 2020


Hi,

On 9/29/20 9:19 AM, Sascha Hauer wrote:
> On Mon, Sep 28, 2020 at 05:42:42PM +0200, Ahmad Fatoum wrote:
>> dev->id_entry is not populated for devices probed from the device
>> tree. It was used unconditionally however. Use device_get_match_data
>> instead to support device tree probing.
>>
>> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
>> ---
>>  drivers/led/led-pca955x.c | 5 ++++-
>>  1 file changed, 4 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/led/led-pca955x.c b/drivers/led/led-pca955x.c
>> index 27fefce8d524..f89fcbfba5ac 100644
>> --- a/drivers/led/led-pca955x.c
>> +++ b/drivers/led/led-pca955x.c
>> @@ -349,8 +349,11 @@ static int led_pca955x_probe(struct device_d *dev)
>>  	struct i2c_client *client;
>>  	int err;
>>  	struct pca955x_platform_data *pdata;
>> +	enum pca955x_type type;
>>  
>> -	chip = &pca955x_chipdefs[dev->id_entry->driver_data];
>> +	type = (enum pca955x_type)device_get_match_data(dev);
> 
> In this driver we have this:
> 
> 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,
> 	},
> };
> 
> So instead of putting the enum casted to void pointer into the matchdata
> we could put pointers to struct pca955x_chipdef directly into the
> matchdata.

platform id match data will have a cast as well, but casting pointer
to long is probably better than pointer to enum. Will send out along
with v2 when we reach agreement on the new function's signature.

> 
> Sascha
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



More information about the barebox mailing list