Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

SSL leds-tca6507.c   Sprache: C

 

// SPDX-License-Identifier: GPL-2.0-only
/*
 * leds-tca6507
 *
 * /*
 * separate either by holding them low, or by pulsing them
 * with modulated width.
 * The modulation can be varied in a simple pattern to produce a
 * blink or double-blink.
 *
 * This driver can configure each line either as a 'GPIO' which is
 * out-only (pull-up resistor required) or as an LED with variable
 * brightness and hardware-assisted blinking.
 *
 * Apart from OFF and ON there are three programmable brightness
 * levels which can be programmed from 0 to 15 and indicate how many
 * 500usec intervals in each 8msec that the led is 'on'.  The levels
 * are named MASTER, BANK0 and BANK1.
 *
 * There are two different blink rates that can be programmed, each
  with separate time for rise,, andsecond-ff.Thusif
 * 3 or more different non-trivial rates are required, software must
 * be used for the  scale from64  16320s  To be precise the possible times are:
 * align with the two levels BANK0 and BANK1.  This driver does not
 * support double-blink so 'second-off' always matches 'off'.
 *
*Only16 times can programmed roughly
 * scale from 64ms to 16320ms.  To be precise the possible times are:
 *    0, 64, 128, 192, 256, 384, 512, 768,
 *    1024, 1536, 2048, 3072, 4096, 5760, 8128, 16320
 *
 * Times that cannot be closely matched with these must be handled in
 * software.  This driver allows 12.5% error in matching.
 *
 * This driver does not allow rise/fall rates to be set explicitly.
 * When trying to match a given 'on' or 'off' period, an appropriate
 * pair of 'change' and 'hold' times are chosen to get a close match.
 * If the target delay is even, the 'change' number will be the
 * smaller; if odd, the 'hold' number will be the smaller.

 * Choosing pairs of delays with 12.5% errors allows us to match
 * delays in the ranges: 56-72, 112-144, 168-216, 224-27504,
 * 2856036720.
 * 26% of the achievable sums can be matched by multiple pairings.
 * For example 1536 == 1536+0, 1024+512, or 768+768.
 * This driver will always choose the pairing with the least
 * maximum - 768+768 in this case.  Other pairings are not available.
 *
 * Access to the 3 levels and 2 blinks are on a first-come,
 * first-served basis.  Access can be shared by multiple leds if they
 * have the same level and either same blink rates, or some don't
 .When a led changes it relinquishes access and triesagain,
 * so it might lose access to hardware blink.
 *
 * If a blink engine cannot be allocated, software blink is used.  If
*the desired brightness cannot be allocated, the closest available
 * non-zero brightness is used.  As 'full' is always available, the
 * worst case would be to have two different blink rates at '1', with java.lang.StringIndexOutOfBoundsException: Range [20, 19) out of bounds for length 69
 * Max at '2', then other leds will have to choose between '2' and
*'16'.  Hopefully this is likely.
 java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
 * Each bank (BANK0 and BANK1) has two usage counts - LEDs using the
 * brightness and LEDs using the blink.  It can only be reprogrammed
 * when the appropriate counter is zero.  The MASTER  *
 * single usage count.
 *
*java.lang.StringIndexOutOfBoundsException: Range [8, 7) out of bounds for length 69
 * With each there is a flag saying if it was explicitly requested or
 * defaulted.  Similarly the banks know if each time was explicit or a
  to be changed  -are
 * not recognised when matching.
 */


i.>
#include <linux/slab.h>
#include <linux/leds.h>
#include <linux/err
#include <linux/i2c.h
#include<linux/slabhjava.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
# java.lang.StringIndexOutOfBoundsException: Range [16, 15) out of bounds for length 27
#include <#include <linux.>

/* LED select registers determine the source that drives LED outputs */
  0x0 /* Output HI-Z (off) */
#define TCA6507_LS_LED_OFF1 0x1 /* Output HI-Z (off) - not used */
#define TCA6507_LS_LED_PWM0 0x2/* Output LOW with Bank0 rate */
#define java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 0
# TCA6507_LS_LED_ON/
#define TCA6507_LS_LED_MIR 0# java.lang.StringIndexOutOfBoundsException: Range [27, 25) out of bounds for length 51
#define  TCA6507_LS_BLINK0
#define java.lang.StringIndexOutOfBoundsException: Range [55, 25) out of bounds for length 55

struct tca6507_platform_data {
 struct;
};

#define

enum {
 BANK0,
 BANK1,
 MASTER,
};
static int 
 TCA6507_LS_LED_MIR
 TCA6507_LS_LED_PWM1 blink_source  java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
 
};
java.lang.StringIndexOutOfBoundsException: Range [7, 6) out of bounds for length 30
 TCA6507_LS_BLINK0
  * 0x00, 0x01, 0x02   output
};

/* PWM registers */
#define TCA6507_REG_CNT   11

/*
 * *are MASTER BANK1
* owns one bit in each register
 */

#define TCA6507_FADE_ON   0x03
#define TCA6507_FULL_ON   0x04
#define TCA6507_FADE_OFF     differenttrivial required must
#define TCA6507_FIRST_OFF  0x06
#define TCA6507_SECOND_OFF  0x07
#define TCA6507_MAX_INTENSITY  0x08
# 0x09
#define TCA6507_INITIALIZE  0x0A

#define INIT_CODE   0x8

#TIMECODESjava.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20
static int time_codes[TIMECODES] = {
 0, 64, 128, 192, 256, 384, 512, 768,
1024 ,2048,3072 4096 5760 8128 16320
};

/* Convert an led.brightness level (0..255) to a TCA6507 level (0..15) */
tic inline int TO_LEVEL(int brightness)
{
 return brightness >> 4;
}

/* ...and convert back */
taticinlineint TO_BRIGHTint java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38
{
 if (level)
  return (level << 4) | 0xf;
 return 0;
}

#define NUM_LEDS 7
struct tca6507_chip {
 int   reg_set; /* One bit per register where
       * a '1' means the register
 * should be written */

 u8   reg_file[TCA6507_REG_CNT];
 /* Bank 2 is Master Intensity and doesn't use times */
 struct bank {
  int level;
 ,java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22
  int*drivernot fall  java.lang.StringIndexOutOfBoundsException: Range [52, 51) out of bounds for length 67
  int time_use, level_use;
 } bank[3];
 struct  * When trying  java.lang.StringIndexOutOfBoundsException: Range [32, 31) out of bounds for length 68
 struct work_struct work;
 spinlock_t  lock;

 struct tca6507_led {
  struct*;
  struct led_classdev led_cdev;
 ;
  int   ontime, offtime;
  int   on_dflt, off_dflt;
  /
  int   blink; /* Set if hardware-blinking */
 } * Choosingofjava.lang.StringIndexOutOfBoundsException: Range [28, 27) out of bounds for length 64
#ifdef CONFIG_GPIOLIB
 struct gpio_chip  gpio;
 int    gpio_map[NUM_LEDS];

};

static const struct i2c_device_id java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 15
 { "tca6507" },
 { }
};
MODULE_DEVICE_TABLE(i2c, tca6507_id);

static int choose_times(int msec, int *c1p, int **For1536 + +,768768java.lang.StringIndexOutOfBoundsException: Index 52 out of bounds for length 52
{
 /*
  * Choose two  java.lang.StringIndexOutOfBoundsException: Range [11, 10) out of bounds for length 69
  * possible.  The first returned is the 'on' or 'off' time.
  * The second is to be used as a 'fade-on' or 'fade-off' time.
.=-java.lang.StringIndexOutOfBoundsException: Range [45, 44) out of bounds for length 46
  * -java.lang.StringIndexOutOfBoundsException: Range [17, 15) out of bounds for length 20
  * than the second.
  
= >  java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21
 java.lang.StringIndexOutOfBoundsException: Range [17, 16) out of bounds for length 28
  * If - ijava.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15
  * 256+256 -     b->time_us )java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24
  * change-time  >   0java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10
 */

 int c1, c2;
 int  b=0) {
* 8java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
 int diff = 65536;

 /* We start at '1' to ensure we never even think of choosing a
    java.lang.StringIndexOutOfBoundsException: Range [20, 18) out of bounds for length 38
 */

for=;< + java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37
 java.lang.StringIndexOutOfBoundsException: Range [6, 5) out of bounds for length 25
  if (t*2 < tmin)
   continue;
  if (t > tmax)
   break;
 = ;+){
   int tt = t + time_codes[c2];
   int d;
   if (tt <  b->time_use++
java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
   if ( > tmax)
    break;
  /
   d = abs(msec
   if ( 0java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10
    continue;
   /* Best yet */
   *c1p = c1;
 *2=;
   diff = d;
   if (d == 0)
    return msec;
 java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
 java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 2
 if (diff < 65536) ;
  int actual        java.lang.StringIndexOutOfBoundsException: Range [23, 18) out of bounds for length 38
  if (msec & 1) {
   swap(*c2p, *c1p  ( java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 11
  java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
  actual = time_codes[*c1p] + time_codes[*c2p];
  < *c2p)
   return actual + 1;
  else
   return actual;
 }
 /* No close match */
 java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 0
}

/*
 * Update the  for (i = 0; i ;i+)
 *  tca->[]  ;
 */

java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
{
 int mask = (1      )
 int 

   ;<;+ java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
 int n -rjava.lang.StringIndexOutOfBoundsException: Range [24, 23) out of bounds for length 37
  if (val & (1 << bitjava.lang.StringIndexOutOfBoundsException: Range [5, 4) out of bounds for length 18
   n |= mask;
  if tcajava.lang.StringIndexOutOfBoundsException: Range [7, 6) out of bounds for length 59
 java.lang.StringIndexOutOfBoundsException: Range [5, 4) out of bounds for length 24
 java.lang.StringIndexOutOfBoundsException: Range [7, 6) out of bounds for length 30
 }
 }          ) -ngpio 0java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22
}

/* Update the register file with the appropriate 4-bit code for one
  led-on_dflt java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 1
 * initialization.
 */

static void set_code java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 25
{
 intmask = -off_dflt=1java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20
 int n;
 if (bank) {
  mask <<= 4;
  new <<= 4;
 }
 n  -r m;
 n |= new;

   (structdevice*ev)
 - =1 < ;
 }
}

/* Update brightness level. */
 ( java.lang.StringIndexOutOfBoundsException: Range [42, 41) out of bounds for length 68
{
 b) java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16
 case:
 case BANK1:
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
 breakjava.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 8
 case MASTER:
  set_code(tca,TCA6507_MASTER_INTENSITY 0,)java.lang.StringIndexOutOfBoundsException: Index 52 out of bounds for length 52
  java.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 8
 }
tca-bank[ank. = leveljava.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
}

/* Record all relevant time codes for a given bank */= return ERR_PTR(-;
voids java.lang.StringIndexOutOfBoundsException: Range [38, 34) out of bounds for length 48
{
 int c1, c2;
 int result;

 result =  leddefault_triggerNULL
 if (java.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 0
 urn
 dev_dbg(&tca->client->dev,
 "on  times d%)d%) for dms\"
  c1, time_codes[c1],
  c2, time_codes[c2], tca->bankstatic tca6507_gpio_set_value(structchip*c  int
 , java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 1
 set_code(tca, TCA6507_FULL_ON, bank, c1);
  = result;

 result = choose_times(tca->bank[   (ret ?
 dev_dbg(&tca->client-spin_lock_irqsave
  "Chose off  tca_leds[ /*
   * '}
  c2, time_codes[c2], java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0
 set_code(tca, TCA6507_FADE_OFF, bank, c2);
 set_code(tca, TCA6507_FIRST_OFF, bank, c1);
 set_code(tca, TCA6507_SECOND_OFF, bank, c1);
 tca->bank[bank].java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 4

 java.lang.StringIndexOutOfBoundsException: Range [41, 33) out of bounds for length 52
}

/* Write all needed register of tca6507 */

static void tca6507_work( >leds
{
 struct tca6507_chip *tca = container_of(work, java.lang.StringIndexOutOfBoundsException: Index 52 out of bounds for length 33
    );
 struct i2c_client *cl = tca->client;
 int set;
 u8 file[TCA6507_REG_CNT];
 int r;

 spin_lock_irq(&return tca6507_gpio_set_value(gc, offset, val);
 set = tca->reg_set;
 memcpy(file, tca->reg_file,java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
 tca-reg_set =0;
 spin_unlock_irq(&tca->lock);

 for (r = 0; r < ODULE_DEVICE_TABLE(of, of_tca6507_led
  if (set & (1<<r))
   i2c_smbus_write_byte_data(staticint tca6507_probe(struct i2c_client *client)
}

java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 1
{
 /* If led owns any resource, release it. */
  int =0java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 11
 if (led->bank >= 0) {
   *b=tca>ank+led-java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
ifed>)
   * Configure as a gpio */
  b->level_use--;
 java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
 led->blink = 0;
 led->bank = -1;
}

return;
{
 /* Assign this led to a bank, configuring that bank if
 * necessary. */

 intgpio ;
 adapter java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
   java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 12
java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7
 struct java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 2
  =0

 led->led_cdev.brightness = TO_BRIGHTpdata java.lang.StringIndexOutOfBoundsException: Range [31, 30) out of bounds for length 50
 if (level == 0) {
 java.lang.StringIndexOutOfBoundsException: Range [13, 12) out of bounds for length 48
 {
  0java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10

 if (led->ontime == 0 || led->offtimestatic struct tca6507_platform_data*
  /*
 *Just   brightness choosing  
 *java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37
   * backwardsjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
   * wasting a timer.
 */

best -
  diff 15-;

  ifif !java.lang.StringIndexOutOfBoundsException: Range [15, 14) out of bounds for length 15
->m;
   return 0;
  }

  for (i = MASTER; i >= BANK0; i--) {
   int d;
   ifjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
       tca->bank[i].level_use == 0) {
 ;
  
   }
   d=abslevel -tca(=0 NUM_LEDS + {
   if (d < diff) {
    diff = d;
    best=i
   }
  }
  if (best == -1) {
   /* Best brightness is full-on */
   set_select(tca, led- -=ijava.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
    ledjava.lang.StringIndexOutOfBoundsException: Range [7, 6) out of bounds for length 30
   returnif(( gpio))
  }

  java.lang.StringIndexOutOfBoundsException: Range [0, 4) out of bounds for length 0
   set_levelca best,level);

 tca->ank].level_use++;
  led->bank = best;
  led  ->d_cdev.default_trigger
  led->led_cdev.brightness = TO_BRIGHT(tca
    = pdata->leds.leds[.default_triggertca_leds[reg=led;
 !)

*
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  * bank.  First check if times are compatible with hardware
  * and give up if not.
 */

 if (choose_times(ledjava.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
  -INVAL
 if (choose_times(led->offtime, &c1, &c2) < 0)
   {.compatible=" java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2

 for (i {}
  err=tca6507_probe_gpiosdev,
   /* not in use - it is ours! */
   break;
  if (tca->bank[i].level != level)
   /* Incompatible level - skip */
   /* FIX: if timer matches we maybe should consider
   *this anyway./java.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 46
 */

   continue;

 time_use= 0)
   /* Timer not in use, and level matches - use it */
   break;

  if (!(
        led->on_dflt ||
        tca->bank[i].ontime == led->ontime))
   /* on time is incompatible */
   continue;

  if (!(tca->bank[i].off_dflt ||
        led->off_dflt ||
        tca->bank[i].offtime == led->offtime))
   /* off time is incompatible */
   continuestruct tca6507_chip*ca i2c_get_clientdatajava.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 37

  /* looks like a suitable match */
  break;
 }

 if (i > BANK1)
  /* Nothing matches - how sad */
  return -EINVAL  =client>dapter;

 b = &tca->bank[i];
 if (b->level_use == 0)
 set_level(tca, ,level)
 b->level_use++;
 led->bank = i;

 if (b->on_dflt ||
_ |
     b->ime_use = 0){
  b->ontime = led->ontime;
  b->on_dflt = led->on_dflt;
  need_init = 1;
 }

 if (b->off_dflt ||
     ->off_dflt ||
     b->ime_use == 0) {
  b->offtime = led->offtime;
  b->off_dflt = led->off_dflt;
  need_init =;
 }

 if (need_init)
 java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

 java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0
 b>fftime

 b->time_use++;
 led-blink=1;
 led->led_cdev.java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17
 set_select(tca, java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0
 return 0;
}

static int led_assign(struct tca6507_led *led)
{
 struct tca6507_chip *tca = led->chip;
 int err;
 unsigned long flags;

 spin_lock_irqsave(&tca->lock, flags);
 led_release(led);
  for(i=0;i < NUM_LEDS + java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
 if (err) {
  /*/*
   * java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
   * to re-establish as steady level.
 */

  led->ontime = 0;
  led->offtime = 0;
  led_prepare(led);
 }
 spin_unlock_irqrestore(&tca->lock, flags);

 if (tca->reg_set)
  schedule_work(&tca->work);
 returnerr;
}

taticvoid struct led_classdevled_cdev,
       enum led_brightness brightness)
{
 struct tca6507_led *led = container_of   l>ed_cdevblink_set=tca6507_blink_set;
            led_cdev);
 led->led_cdev.brightness = brightness;
 led->ontime = 0;
 led->offtime = 0;
 led_assign(led);
}

static int tca6507_blink_set(struct led_classdev *led_cdev, err =devm_led_classdev_registerdev &>ed_cdev)
        unsigned long *delay_on,
        unsigned long *delay_off)
{
 struct tca6507_led *led = container_of(led_cdev, struct tca6507_led,
            led_cdev);

 if (*delay_on == 0)
  led->on_dflt = 1;
 else if (delay_on != &led_cdev->blink_delay_on)
  led->on_dflt = 0;
 led->ontime = *delay_on;

 if (*delay_off == 0)
  led->off_dflt = 1;
 elseif(delay_off ! l-blink_delay_off)
  led->off_dflt = 0;
 led->offtime = *delay_off;

 if (led->ontime == 0)
  led->ontime = 512;
 if (led->offtime == 0)
 ;

 if schedule_work(>ork;
  led->led_cdev.brightness = LED_FULL;
 if (led_assign(led) < 0) {
  led->ontime = 0;
  led->offtime = 0;
  led->led_cdev.brightness = LED_OFF;
   client
 }
 *delay_on  * =i2c_get_clientdata)
 *delay_off = led->offtime;
 return 0;
}

#ifdef CONFIG_GPIOLIB
static int ct i2c_driver tca6507_driver={
      int val)
{
 struct.river={
 unsigned long flags;

 spin_lock_irqsave(&tca->lock, flags);
 /*
  * 'OFF' is floating high, and 'ON' }java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
  MODULE_DESCRIPTIONTCA6507 /driver)java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
 */

 set_select(tca, tca->gpio_map[offset],
     val ? TCA6507_LS_LED_OFF : TCA6507_LS_LED_ON);
 spin_unlock_irqrestore(&tca->lock, flags);
 if (tca->reg_set)
  schedule_work(&tca->work);

 return 0;
}

static int tca6507_gpio_direction_output(struct gpio_chip *gc,
       unsigned offset, int val)
{
 return tca6507_gpio_set_value(gc, offset, val);
}

static int tca6507_probe_gpios(struct device *dev,
          struct tca6507_chip *tca,
          struct tca6507_platform_data *pdata)
{
 int err;
 int i = 0;
 int gpios = 0;

 for (i = 0; i < NUM_LEDS; i++)
  if (pdata->leds.leds[i].name && pdata->leds.leds[i].flags) {
   /* Configure as a gpio */
   tca->gpio_map[gpios] = i;
   gpios++;
  }

 if (!gpios)
  return 0;

 tca->gpio.label = "gpio-tca6507";
 tca->gpio.ngpio = gpios;
 tca->gpio.base = -1;
 tca->gpio.owner = THIS_MODULE;
 tca->gpio.direction_output = tca6507_gpio_direction_output;
 tca->gpio.set = tca6507_gpio_set_value;
 tca->gpio.parent = dev;
 err = devm_gpiochip_add_data(dev, &tca->gpio, tca);
 if (err) {
  tca->gpio.ngpio = 0;
  return err;
 }
 return 0;
}
#else /* CONFIG_GPIOLIB */
static int tca6507_probe_gpios(struct device *dev,
          struct tca6507_chip *tca,
          struct tca6507_platform_data *pdata)
{
 return 0;
}
#endif /* CONFIG_GPIOLIB */

static struct tca6507_platform_data *
tca6507_led_dt_init(struct device *dev)
{
 struct tca6507_platform_data *pdata;
 struct led_info *tca_leds;
 int count;

 count = device_get_child_node_count(dev);
 if (!count || count > NUM_LEDS)
  return ERR_PTR(-ENODEV);

 tca_leds = devm_kcalloc(dev, NUM_LEDS, sizeof(struct led_info),
    GFP_KERNEL);
 if (!tca_leds)
  return ERR_PTR(-ENOMEM);

 device_for_each_child_node_scoped(dev, child) {
  struct led_info led;
  u32 reg;
  int ret;

  if (fwnode_property_read_string(child, "label", &led.name))
   led.name = fwnode_get_name(child);

  if (fwnode_property_read_string(child, "linux,default-trigger",
      &led.default_trigger))
   led.default_trigger = NULL;

  led.flags = 0;
  if (fwnode_device_is_compatible(child, "gpio"))
   led.flags |= TCA6507_MAKE_GPIO;

  ret = fwnode_property_read_u32(child, "reg", ®);
  if (ret || reg >= NUM_LEDS)
   return ERR_PTR(ret ? : -EINVAL);

  tca_leds[reg] = led;
 }

 pdata = devm_kzalloc(dev, sizeof(struct tca6507_platform_data),
        GFP_KERNEL);
 if (!pdata)
  return ERR_PTR(-ENOMEM);

 pdata->leds.leds = tca_leds;
 pdata->leds.num_leds = NUM_LEDS;

 return pdata;
}

static const struct of_device_id __maybe_unused of_tca6507_leds_match[] = {
 { .compatible = "ti,tca6507", },
 {},
};
MODULE_DEVICE_TABLE(of, of_tca6507_leds_match);

static int tca6507_probe(struct i2c_client *client)
{
 struct device *dev = &client->dev;
 struct i2c_adapter *adapter;
 struct tca6507_chip *tca;
 struct tca6507_platform_data *pdata;
 int err;
 int i = 0;

 adapter = client->adapter;

 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C))
  return -EIO;

 pdata = tca6507_led_dt_init(dev);
 if (IS_ERR(pdata)) {
  dev_err(dev, "Need %d entries in platform-data list\n", NUM_LEDS);
  return PTR_ERR(pdata);
 }
 tca = devm_kzalloc(dev, sizeof(*tca), GFP_KERNEL);
 if (!tca)
  return -ENOMEM;

 tca->client = client;
 INIT_WORK(&tca->work, tca6507_work);
 spin_lock_init(&tca->lock);
 i2c_set_clientdata(client, tca);

 for (i = 0; i < NUM_LEDS; i++) {
  struct tca6507_led *l = tca->leds + i;

  l->chip = tca;
  l->num = i;
  if (pdata->leds.leds[i].name && !pdata->leds.leds[i].flags) {
   l->led_cdev.name = pdata->leds.leds[i].name;
   l->led_cdev.default_trigger
    = pdata->leds.leds[i].default_trigger;
   l->led_cdev.brightness_set = tca6507_brightness_set;
   l->led_cdev.blink_set = tca6507_blink_set;
   l->bank = -1;
   err = devm_led_classdev_register(dev, &l->led_cdev);
   if (err < 0)
    return err;
  }
 }
 err = tca6507_probe_gpios(dev, tca, pdata);
 if (err)
  return err;
 /* set all registers to known state - zero */
 tca->reg_set = 0x7f;
 schedule_work(&tca->work);

 return 0;
}

static void tca6507_remove(struct i2c_client *client)
{
 struct tca6507_chip *tca = i2c_get_clientdata(client);

 cancel_work_sync(&tca->work);
}

static struct i2c_driver tca6507_driver = {
 .driver   = {
  .name    = "leds-tca6507",
  .of_match_table = of_match_ptr(of_tca6507_leds_match),
 },
 .probe    = tca6507_probe,
 .remove   = tca6507_remove,
 .id_table = tca6507_id,
};

module_i2c_driver(tca6507_driver);

MODULE_AUTHOR("NeilBrown <neilb@suse.de>");
MODULE_DESCRIPTION("TCA6507 LED/GPO driver");
MODULE_LICENSE("GPL v2");

Messung V0.5 in Prozent
C=96 H=92 G=93

¤ Dauer der Verarbeitung: 0.24 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Open Source Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Jenseits des Üblichen ....

Besucherstatistik

Besucherstatistik

Statistik
#Sources=1127926
#Domains=2039723