@@ -218,6 +218,18 @@ static const char *wm8994_main_supplies[] = {
218218 "SPKVDD2" ,
219219};
220220
221+ static const char * wm8958_main_supplies [] = {
222+ "DBVDD1" ,
223+ "DBVDD2" ,
224+ "DBVDD3" ,
225+ "DCVDD" ,
226+ "AVDD1" ,
227+ "AVDD2" ,
228+ "CPVDD" ,
229+ "SPKVDD1" ,
230+ "SPKVDD2" ,
231+ };
232+
221233#ifdef CONFIG_PM
222234static int wm8994_device_suspend (struct device * dev )
223235{
@@ -239,7 +251,7 @@ static int wm8994_device_suspend(struct device *dev)
239251 if (ret < 0 )
240252 dev_err (dev , "Failed to save LDO registers: %d\n" , ret );
241253
242- ret = regulator_bulk_disable (ARRAY_SIZE ( wm8994_main_supplies ) ,
254+ ret = regulator_bulk_disable (wm8994 -> num_supplies ,
243255 wm8994 -> supplies );
244256 if (ret != 0 ) {
245257 dev_err (dev , "Failed to disable supplies: %d\n" , ret );
@@ -254,7 +266,7 @@ static int wm8994_device_resume(struct device *dev)
254266 struct wm8994 * wm8994 = dev_get_drvdata (dev );
255267 int ret ;
256268
257- ret = regulator_bulk_enable (ARRAY_SIZE ( wm8994_main_supplies ) ,
269+ ret = regulator_bulk_enable (wm8994 -> num_supplies ,
258270 wm8994 -> supplies );
259271 if (ret != 0 ) {
260272 dev_err (dev , "Failed to enable supplies: %d\n" , ret );
@@ -305,9 +317,10 @@ static int wm8994_ldo_in_use(struct wm8994_pdata *pdata, int ldo)
305317/*
306318 * Instantiate the generic non-control parts of the device.
307319 */
308- static int wm8994_device_init (struct wm8994 * wm8994 , unsigned long id , int irq )
320+ static int wm8994_device_init (struct wm8994 * wm8994 , int irq )
309321{
310322 struct wm8994_pdata * pdata = wm8994 -> dev -> platform_data ;
323+ const char * devname ;
311324 int ret , i ;
312325
313326 mutex_init (& wm8994 -> io_lock );
@@ -323,25 +336,48 @@ static int wm8994_device_init(struct wm8994 *wm8994, unsigned long id, int irq)
323336 goto err ;
324337 }
325338
339+ switch (wm8994 -> type ) {
340+ case WM8994 :
341+ wm8994 -> num_supplies = ARRAY_SIZE (wm8994_main_supplies );
342+ break ;
343+ case WM8958 :
344+ wm8994 -> num_supplies = ARRAY_SIZE (wm8958_main_supplies );
345+ break ;
346+ default :
347+ BUG ();
348+ return - EINVAL ;
349+ }
350+
326351 wm8994 -> supplies = kzalloc (sizeof (struct regulator_bulk_data ) *
327- ARRAY_SIZE ( wm8994_main_supplies ) ,
352+ wm8994 -> num_supplies ,
328353 GFP_KERNEL );
329354 if (!wm8994 -> supplies ) {
330355 ret = - ENOMEM ;
331356 goto err ;
332357 }
333358
334- for (i = 0 ; i < ARRAY_SIZE (wm8994_main_supplies ); i ++ )
335- wm8994 -> supplies [i ].supply = wm8994_main_supplies [i ];
336-
337- ret = regulator_bulk_get (wm8994 -> dev , ARRAY_SIZE (wm8994_main_supplies ),
359+ switch (wm8994 -> type ) {
360+ case WM8994 :
361+ for (i = 0 ; i < ARRAY_SIZE (wm8994_main_supplies ); i ++ )
362+ wm8994 -> supplies [i ].supply = wm8994_main_supplies [i ];
363+ break ;
364+ case WM8958 :
365+ for (i = 0 ; i < ARRAY_SIZE (wm8958_main_supplies ); i ++ )
366+ wm8994 -> supplies [i ].supply = wm8958_main_supplies [i ];
367+ break ;
368+ default :
369+ BUG ();
370+ return - EINVAL ;
371+ }
372+
373+ ret = regulator_bulk_get (wm8994 -> dev , wm8994 -> num_supplies ,
338374 wm8994 -> supplies );
339375 if (ret != 0 ) {
340376 dev_err (wm8994 -> dev , "Failed to get supplies: %d\n" , ret );
341377 goto err_supplies ;
342378 }
343379
344- ret = regulator_bulk_enable (ARRAY_SIZE ( wm8994_main_supplies ) ,
380+ ret = regulator_bulk_enable (wm8994 -> num_supplies ,
345381 wm8994 -> supplies );
346382 if (ret != 0 ) {
347383 dev_err (wm8994 -> dev , "Failed to enable supplies: %d\n" , ret );
@@ -353,7 +389,22 @@ static int wm8994_device_init(struct wm8994 *wm8994, unsigned long id, int irq)
353389 dev_err (wm8994 -> dev , "Failed to read ID register\n" );
354390 goto err_enable ;
355391 }
356- if (ret != 0x8994 ) {
392+ switch (ret ) {
393+ case 0x8994 :
394+ devname = "WM8994" ;
395+ if (wm8994 -> type != WM8994 )
396+ dev_warn (wm8994 -> dev , "Device registered as type %d\n" ,
397+ wm8994 -> type );
398+ wm8994 -> type = WM8994 ;
399+ break ;
400+ case 0x8958 :
401+ devname = "WM8958" ;
402+ if (wm8994 -> type != WM8958 )
403+ dev_warn (wm8994 -> dev , "Device registered as type %d\n" ,
404+ wm8994 -> type );
405+ wm8994 -> type = WM8958 ;
406+ break ;
407+ default :
357408 dev_err (wm8994 -> dev , "Device is not a WM8994, ID is %x\n" ,
358409 ret );
359410 ret = - EINVAL ;
@@ -370,14 +421,16 @@ static int wm8994_device_init(struct wm8994 *wm8994, unsigned long id, int irq)
370421 switch (ret ) {
371422 case 0 :
372423 case 1 :
373- dev_warn (wm8994 -> dev , "revision %c not fully supported\n" ,
374- 'A' + ret );
424+ if (wm8994 -> type == WM8994 )
425+ dev_warn (wm8994 -> dev ,
426+ "revision %c not fully supported\n" ,
427+ 'A' + ret );
375428 break ;
376429 default :
377- dev_info (wm8994 -> dev , "revision %c\n" , 'A' + ret );
378430 break ;
379431 }
380432
433+ dev_info (wm8994 -> dev , "%s revision %c\n" , devname , 'A' + ret );
381434
382435 if (pdata ) {
383436 wm8994 -> irq_base = pdata -> irq_base ;
@@ -423,10 +476,10 @@ static int wm8994_device_init(struct wm8994 *wm8994, unsigned long id, int irq)
423476err_irq :
424477 wm8994_irq_exit (wm8994 );
425478err_enable :
426- regulator_bulk_disable (ARRAY_SIZE ( wm8994_main_supplies ) ,
479+ regulator_bulk_disable (wm8994 -> num_supplies ,
427480 wm8994 -> supplies );
428481err_get :
429- regulator_bulk_free (ARRAY_SIZE ( wm8994_main_supplies ) , wm8994 -> supplies );
482+ regulator_bulk_free (wm8994 -> num_supplies , wm8994 -> supplies );
430483err_supplies :
431484 kfree (wm8994 -> supplies );
432485err :
@@ -439,9 +492,9 @@ static void wm8994_device_exit(struct wm8994 *wm8994)
439492{
440493 mfd_remove_devices (wm8994 -> dev );
441494 wm8994_irq_exit (wm8994 );
442- regulator_bulk_disable (ARRAY_SIZE ( wm8994_main_supplies ) ,
495+ regulator_bulk_disable (wm8994 -> num_supplies ,
443496 wm8994 -> supplies );
444- regulator_bulk_free (ARRAY_SIZE ( wm8994_main_supplies ) , wm8994 -> supplies );
497+ regulator_bulk_free (wm8994 -> num_supplies , wm8994 -> supplies );
445498 kfree (wm8994 -> supplies );
446499 kfree (wm8994 );
447500}
@@ -506,8 +559,9 @@ static int wm8994_i2c_probe(struct i2c_client *i2c,
506559 wm8994 -> read_dev = wm8994_i2c_read_device ;
507560 wm8994 -> write_dev = wm8994_i2c_write_device ;
508561 wm8994 -> irq = i2c -> irq ;
562+ wm8994 -> type = id -> driver_data ;
509563
510- return wm8994_device_init (wm8994 , id -> driver_data , i2c -> irq );
564+ return wm8994_device_init (wm8994 , i2c -> irq );
511565}
512566
513567static int wm8994_i2c_remove (struct i2c_client * i2c )
@@ -535,7 +589,8 @@ static int wm8994_i2c_resume(struct i2c_client *i2c)
535589#endif
536590
537591static const struct i2c_device_id wm8994_i2c_id [] = {
538- { "wm8994" , 0 },
592+ { "wm8994" , WM8994 },
593+ { "wm8958" , WM8958 },
539594 { }
540595};
541596MODULE_DEVICE_TABLE (i2c , wm8994_i2c_id );
0 commit comments