@@ -1306,7 +1306,7 @@ static int dualshock4_set_operational_bt(struct hid_device *hdev)
1306
1306
return ret ;
1307
1307
}
1308
1308
1309
- static void sixaxis_set_leds_from_id (int id , __u8 values [ MAX_LEDS ] )
1309
+ static void sixaxis_set_leds_from_id (struct sony_sc * sc )
1310
1310
{
1311
1311
static const __u8 sixaxis_leds [10 ][4 ] = {
1312
1312
{ 0x01 , 0x00 , 0x00 , 0x00 },
@@ -1321,16 +1321,18 @@ static void sixaxis_set_leds_from_id(int id, __u8 values[MAX_LEDS])
1321
1321
{ 0x01 , 0x01 , 0x01 , 0x01 }
1322
1322
};
1323
1323
1324
- BUG_ON (MAX_LEDS < ARRAY_SIZE (sixaxis_leds [0 ]));
1324
+ int id = sc -> device_id ;
1325
+
1326
+ BUILD_BUG_ON (MAX_LEDS < ARRAY_SIZE (sixaxis_leds [0 ]));
1325
1327
1326
1328
if (id < 0 )
1327
1329
return ;
1328
1330
1329
1331
id %= 10 ;
1330
- memcpy (values , sixaxis_leds [id ], sizeof (sixaxis_leds [id ]));
1332
+ memcpy (sc -> led_state , sixaxis_leds [id ], sizeof (sixaxis_leds [id ]));
1331
1333
}
1332
1334
1333
- static void dualshock4_set_leds_from_id (int id , __u8 values [ MAX_LEDS ] )
1335
+ static void dualshock4_set_leds_from_id (struct sony_sc * sc )
1334
1336
{
1335
1337
/* The first 4 color/index entries match what the PS4 assigns */
1336
1338
static const __u8 color_code [7 ][3 ] = {
@@ -1343,46 +1345,44 @@ static void dualshock4_set_leds_from_id(int id, __u8 values[MAX_LEDS])
1343
1345
/* White */ { 0x01 , 0x01 , 0x01 }
1344
1346
};
1345
1347
1346
- BUG_ON (MAX_LEDS < ARRAY_SIZE (color_code [0 ]));
1348
+ int id = sc -> device_id ;
1349
+
1350
+ BUILD_BUG_ON (MAX_LEDS < ARRAY_SIZE (color_code [0 ]));
1347
1351
1348
1352
if (id < 0 )
1349
1353
return ;
1350
1354
1351
1355
id %= 7 ;
1352
- memcpy (values , color_code [id ], sizeof (color_code [id ]));
1356
+ memcpy (sc -> led_state , color_code [id ], sizeof (color_code [id ]));
1353
1357
}
1354
1358
1355
- static void buzz_set_leds (struct hid_device * hdev , const __u8 * leds )
1359
+ static void buzz_set_leds (struct sony_sc * sc )
1356
1360
{
1361
+ struct hid_device * hdev = sc -> hdev ;
1357
1362
struct list_head * report_list =
1358
1363
& hdev -> report_enum [HID_OUTPUT_REPORT ].report_list ;
1359
1364
struct hid_report * report = list_entry (report_list -> next ,
1360
1365
struct hid_report , list );
1361
1366
__s32 * value = report -> field [0 ]-> value ;
1362
1367
1368
+ BUILD_BUG_ON (MAX_LEDS < 4 );
1369
+
1363
1370
value [0 ] = 0x00 ;
1364
- value [1 ] = leds [0 ] ? 0xff : 0x00 ;
1365
- value [2 ] = leds [1 ] ? 0xff : 0x00 ;
1366
- value [3 ] = leds [2 ] ? 0xff : 0x00 ;
1367
- value [4 ] = leds [3 ] ? 0xff : 0x00 ;
1371
+ value [1 ] = sc -> led_state [0 ] ? 0xff : 0x00 ;
1372
+ value [2 ] = sc -> led_state [1 ] ? 0xff : 0x00 ;
1373
+ value [3 ] = sc -> led_state [2 ] ? 0xff : 0x00 ;
1374
+ value [4 ] = sc -> led_state [3 ] ? 0xff : 0x00 ;
1368
1375
value [5 ] = 0x00 ;
1369
1376
value [6 ] = 0x00 ;
1370
1377
hid_hw_request (hdev , report , HID_REQ_SET_REPORT );
1371
1378
}
1372
1379
1373
- static void sony_set_leds (struct sony_sc * sc , const __u8 * leds , int count )
1380
+ static void sony_set_leds (struct sony_sc * sc )
1374
1381
{
1375
- int n ;
1376
-
1377
- BUG_ON (count > MAX_LEDS );
1378
-
1379
- if (sc -> quirks & BUZZ_CONTROLLER && count == 4 ) {
1380
- buzz_set_leds (sc -> hdev , leds );
1381
- } else {
1382
- for (n = 0 ; n < count ; n ++ )
1383
- sc -> led_state [n ] = leds [n ];
1382
+ if (!(sc -> quirks & BUZZ_CONTROLLER ))
1384
1383
schedule_work (& sc -> state_worker );
1385
- }
1384
+ else
1385
+ buzz_set_leds (sc );
1386
1386
}
1387
1387
1388
1388
static void sony_led_set_brightness (struct led_classdev * led ,
@@ -1422,8 +1422,7 @@ static void sony_led_set_brightness(struct led_classdev *led,
1422
1422
drv_data -> led_delay_on [n ] = 0 ;
1423
1423
drv_data -> led_delay_off [n ] = 0 ;
1424
1424
1425
- sony_set_leds (drv_data , drv_data -> led_state ,
1426
- drv_data -> led_count );
1425
+ sony_set_leds (drv_data );
1427
1426
break ;
1428
1427
}
1429
1428
}
@@ -1529,7 +1528,6 @@ static int sony_leds_init(struct sony_sc *sc)
1529
1528
const char * name_fmt ;
1530
1529
static const char * const ds4_name_str [] = { "red" , "green" , "blue" ,
1531
1530
"global" };
1532
- __u8 initial_values [MAX_LEDS ] = { 0 };
1533
1531
__u8 max_brightness [MAX_LEDS ] = { [0 ... (MAX_LEDS - 1 )] = 1 };
1534
1532
__u8 use_hw_blink [MAX_LEDS ] = { 0 };
1535
1533
@@ -1544,8 +1542,8 @@ static int sony_leds_init(struct sony_sc *sc)
1544
1542
if (!hid_validate_values (hdev , HID_OUTPUT_REPORT , 0 , 0 , 7 ))
1545
1543
return - ENODEV ;
1546
1544
} else if (sc -> quirks & DUALSHOCK4_CONTROLLER ) {
1547
- dualshock4_set_leds_from_id (sc -> device_id , initial_values );
1548
- initial_values [3 ] = 1 ;
1545
+ dualshock4_set_leds_from_id (sc );
1546
+ sc -> led_state [3 ] = 1 ;
1549
1547
sc -> led_count = 4 ;
1550
1548
memset (max_brightness , 255 , 3 );
1551
1549
use_hw_blink [3 ] = 1 ;
@@ -1559,7 +1557,7 @@ static int sony_leds_init(struct sony_sc *sc)
1559
1557
name_len = 0 ;
1560
1558
name_fmt = "%s:%s" ;
1561
1559
} else {
1562
- sixaxis_set_leds_from_id (sc -> device_id , initial_values );
1560
+ sixaxis_set_leds_from_id (sc );
1563
1561
sc -> led_count = 4 ;
1564
1562
memset (use_hw_blink , 1 , 4 );
1565
1563
use_ds4_names = 0 ;
@@ -1572,7 +1570,7 @@ static int sony_leds_init(struct sony_sc *sc)
1572
1570
* only relevant if the driver is loaded after somebody actively set the
1573
1571
* LEDs to on
1574
1572
*/
1575
- sony_set_leds (sc , initial_values , sc -> led_count );
1573
+ sony_set_leds (sc );
1576
1574
1577
1575
name_sz = strlen (dev_name (& hdev -> dev )) + name_len + 1 ;
1578
1576
@@ -1595,7 +1593,7 @@ static int sony_leds_init(struct sony_sc *sc)
1595
1593
else
1596
1594
snprintf (name , name_sz , name_fmt , dev_name (& hdev -> dev ), n + 1 );
1597
1595
led -> name = name ;
1598
- led -> brightness = initial_values [n ];
1596
+ led -> brightness = sc -> led_state [n ];
1599
1597
led -> max_brightness = max_brightness [n ];
1600
1598
led -> brightness_get = sony_led_get_brightness ;
1601
1599
led -> brightness_set = sony_led_set_brightness ;
0 commit comments