Lines Matching refs:ac

67 static int spwr_ac_update_unlocked(struct spwr_ac_device *ac)
69 __le32 old = ac->state;
72 lockdep_assert_held(&ac->lock);
74 status = ssam_retry(ssam_bat_get_psrc, ac->sdev, &ac->state);
78 return old != ac->state;
81 static int spwr_ac_update(struct spwr_ac_device *ac)
85 mutex_lock(&ac->lock);
86 status = spwr_ac_update_unlocked(ac);
87 mutex_unlock(&ac->lock);
92 static int spwr_ac_recheck(struct spwr_ac_device *ac)
96 status = spwr_ac_update(ac);
98 power_supply_changed(ac->psy);
105 struct spwr_ac_device *ac;
108 ac = container_of(nf, struct spwr_ac_device, notif);
110 dev_dbg(&ac->sdev->dev, "power event (cid = %#04x, iid = %#04x, tid = %#04x)\n",
124 status = spwr_ac_recheck(ac);
142 struct spwr_ac_device *ac = power_supply_get_drvdata(psy);
145 mutex_lock(&ac->lock);
147 status = spwr_ac_update_unlocked(ac);
153 val->intval = !!le32_to_cpu(ac->state);
162 mutex_unlock(&ac->lock);
174 static void spwr_ac_init(struct spwr_ac_device *ac, struct ssam_device *sdev,
177 mutex_init(&ac->lock);
178 strscpy(ac->name, name, sizeof(ac->name));
180 ac->sdev = sdev;
182 ac->notif.base.priority = 1;
183 ac->notif.base.fn = spwr_notify_ac;
184 ac->notif.event.reg = registry;
185 ac->notif.event.id.target_category = sdev->uid.category;
186 ac->notif.event.id.instance = 0;
187 ac->notif.event.mask = SSAM_EVENT_MASK_NONE;
188 ac->notif.event.flags = SSAM_EVENT_SEQUENCED;
190 ac->psy_desc.name = ac->name;
191 ac->psy_desc.type = POWER_SUPPLY_TYPE_MAINS;
192 ac->psy_desc.properties = spwr_ac_props;
193 ac->psy_desc.num_properties = ARRAY_SIZE(spwr_ac_props);
194 ac->psy_desc.get_property = spwr_ac_get_property;
197 static int spwr_ac_register(struct spwr_ac_device *ac)
204 status = ssam_retry(ssam_bat_get_sta, ac->sdev, &sta);
211 psy_cfg.drv_data = ac;
215 ac->psy = devm_power_supply_register(&ac->sdev->dev, &ac->psy_desc, &psy_cfg);
216 if (IS_ERR(ac->psy))
217 return PTR_ERR(ac->psy);
219 return ssam_device_notifier_register(ac->sdev, &ac->notif);
234 struct spwr_ac_device *ac;
240 ac = devm_kzalloc(&sdev->dev, sizeof(*ac), GFP_KERNEL);
241 if (!ac)
244 spwr_ac_init(ac, sdev, p->registry, p->name);
245 ssam_device_set_drvdata(sdev, ac);
247 return spwr_ac_register(ac);
252 struct spwr_ac_device *ac = ssam_device_get_drvdata(sdev);
254 ssam_device_notifier_unregister(sdev, &ac->notif);